Python: include Python stack trace in the crash log

This helps Python developers troubleshoot errors when
Python causes a crash.
This commit is contained in:
Daniel Bailey
2020-08-06 15:34:55 +10:00
committed by Campbell Barton
parent c5b6b3d82f
commit e9c4325515
5 changed files with 31 additions and 0 deletions

View File

@@ -360,6 +360,20 @@ void PyC_StackSpit(void)
}
}
void PyC_StackPrint(FILE *fp)
{
PyThreadState *tstate = PyGILState_GetThisThreadState();
if (tstate != NULL && tstate->frame != NULL) {
PyFrameObject *frame = tstate->frame;
do {
const int line = PyCode_Addr2Line(frame->f_code, frame->f_lasti);
const char *filename = _PyUnicode_AsString(frame->f_code->co_filename);
const char *funcname = _PyUnicode_AsString(frame->f_code->co_name);
fprintf(fp, " File \"%s\", line %d in %s\n", filename, line, funcname);
} while ((frame = frame->f_back));
}
}
void PyC_FileAndNum(const char **r_filename, int *r_lineno)
{
PyFrameObject *frame;