diff options
author | Christian Tismer <tismer@stackless.com> | 2024-04-21 13:50:33 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2024-04-23 09:30:33 +0200 |
commit | 0e107b7ec39efe4f03b0c2ed586e2e04cdfea0fe (patch) | |
tree | 802e93e92453fb68c4517c54f4faaf3a1248d60a | |
parent | 0ad3b1fd87257ec286ecb8950f13bae19aa9ac22 (diff) |
shiboken: improve the display of disassembleFrame
Some more info is displayed, especially the current file
name which is sometimes not obvious (frozen modules).
Task-number: PYSIDE-2675
Change-Id: Iceb97fb1a28da2cf0ef9e28ff6bd158a3bfb2e88
Pick-to: 6.7
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
-rw-r--r-- | sources/shiboken6/libshiboken/sbkfeature_base.cpp | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/sources/shiboken6/libshiboken/sbkfeature_base.cpp b/sources/shiboken6/libshiboken/sbkfeature_base.cpp index caf3517e5..f31b8f4f7 100644 --- a/sources/shiboken6/libshiboken/sbkfeature_base.cpp +++ b/sources/shiboken6/libshiboken/sbkfeature_base.cpp @@ -65,14 +65,24 @@ void disassembleFrame(const char *marker) static PyObject *dismodule = PyImport_ImportModule("dis"); static PyObject *disco = PyObject_GetAttrString(dismodule, "disco"); static PyObject *const _f_lasti = Shiboken::String::createStaticString("f_lasti"); + static PyObject *const _f_lineno = Shiboken::String::createStaticString("f_lineno"); static PyObject *const _f_code = Shiboken::String::createStaticString("f_code"); - auto *frame = reinterpret_cast<PyObject *>(PyEval_GetFrame()); - AutoDecRef f_lasti(PyObject_GetAttr(frame, _f_lasti)); - AutoDecRef f_code(PyObject_GetAttr(frame, _f_code)); + static PyObject *const _co_filename = Shiboken::String::createStaticString("co_filename"); AutoDecRef ignore{}; - fprintf(stdout, "\n%s BEGIN\n", marker); - ignore.reset(PyObject_CallFunctionObjArgs(disco, f_code.object(), f_lasti.object(), nullptr)); - fprintf(stdout, "%s END\n\n", marker); + auto *frame = reinterpret_cast<PyObject *>(PyEval_GetFrame()); + if (frame == nullptr) { + fprintf(stdout, "\n%s BEGIN no frame END\n\n", marker); + } else { + AutoDecRef f_lasti(PyObject_GetAttr(frame, _f_lasti)); + AutoDecRef f_lineno(PyObject_GetAttr(frame, _f_lineno)); + AutoDecRef f_code(PyObject_GetAttr(frame, _f_code)); + AutoDecRef co_filename(PyObject_GetAttr(f_code, _co_filename)); + long line = PyLong_AsLong(f_lineno); + const char *fname = String::toCString(co_filename); + fprintf(stdout, "\n%s BEGIN line=%ld %s\n", marker, line, fname); + ignore.reset(PyObject_CallFunctionObjArgs(disco, f_code.object(), f_lasti.object(), nullptr)); + fprintf(stdout, "%s END line=%ld %s\n\n", marker, line, fname); + } #if PY_VERSION_HEX >= 0x030C0000 && !Py_LIMITED_API if (error_type) PyErr_DisplayException(error_value); |