Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Bailey <danieljabailey>2020-08-06 08:34:55 +0300
committerCampbell Barton <ideasman42@gmail.com>2020-08-06 08:44:00 +0300
commite9c4325515aed9cb3a35183d4093cda2b6bffd9f (patch)
treef68c4d89f16257731ff7457371978b973da3f8a3 /source/blender/python/generic
parentc5b6b3d82f56b6da1fce19b961fa444745dbc269 (diff)
Python: include Python stack trace in the crash log
This helps Python developers troubleshoot errors when Python causes a crash.
Diffstat (limited to 'source/blender/python/generic')
-rw-r--r--source/blender/python/generic/py_capi_utils.c14
-rw-r--r--source/blender/python/generic/py_capi_utils.h1
2 files changed, 15 insertions, 0 deletions
diff --git a/source/blender/python/generic/py_capi_utils.c b/source/blender/python/generic/py_capi_utils.c
index 9c84a4bb824..0a4f3b5bebd 100644
--- a/source/blender/python/generic/py_capi_utils.c
+++ b/source/blender/python/generic/py_capi_utils.c
@@ -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;
diff --git a/source/blender/python/generic/py_capi_utils.h b/source/blender/python/generic/py_capi_utils.h
index e8b2e8ff502..7950ee2c968 100644
--- a/source/blender/python/generic/py_capi_utils.h
+++ b/source/blender/python/generic/py_capi_utils.h
@@ -28,6 +28,7 @@ void PyC_ObSpit(const char *name, PyObject *var);
void PyC_ObSpitStr(char *result, size_t result_len, PyObject *var);
void PyC_LineSpit(void);
void PyC_StackSpit(void);
+void PyC_StackPrint(FILE *fp);
PyObject *PyC_ExceptionBuffer(void);
PyObject *PyC_ExceptionBuffer_Simple(void);
PyObject *PyC_Object_GetAttrStringArgs(PyObject *o, Py_ssize_t n, ...);