SEGV traceback?

Well, some progress, here is my current code:

#include <python2.4/Python.h>

#include <python2.4/frameobject.h>

extern "C" void wxFatalSignalHandler(wxTYPE_SA_HANDLER)

{

if ( wxTheApp ) {

PyInterpreterState *interp = PyInterpreterState_Head();

PyThreadState *st;

int threadNum = 0;

for (st = interp->tstate_head; st; st = st->next) {

PyTracebackObject *tb;

PyFrameObject *frm;

fprintf(stderr, "Thread %u:\n", ++threadNum);

st->curexc_traceback = NULL;

for (frm = st->frame; frm; frm = frm->f_back)

if (PyTraceBack_Here(frm) < 0) { fprintf(stderr, "PyTraceBack_Here failed\n"); break; }

tb = (PyTracebackObject *) st->curexc_traceback;

if (tb == NULL) { fprintf(stderr, "traceback is NULL in wxFatalSignalHandler\n"); continue; }

while (tb) {

fprintf(stderr, " %s line %u: %s\n", PyString_AsString(tb->tb_frame->f_code->co_filename),

tb->tb_lineno, PyString_AsString(tb->tb_frame->f_code->co_name));

tb = tb->tb_next;

}

}

}

}

This assumes just one interpreter is running, for now, which could be made into a loop, and this prints only a rudimentary stack trace, which is fine, if a SEGV occurred, I would say…

Lee

···

“There is nothing remarkable about it. All one has to do is press the right keys at the right time and the computer programs itself.” (ala J.S. Bach)

Unless otherwise stated, any views presented in this e-mail are solely those of the author and do not necessarily represent those of the company.