mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-05-13 05:20:45 +00:00
Add support for aborting python execution at the next traceback call
This commit is contained in:
@@ -442,6 +442,8 @@ void PythonContext::executeString(const QString &filename, const QString &source
|
||||
|
||||
PyEval_SetTrace(&PythonContext::traceEvent, traceContext);
|
||||
|
||||
m_Abort = false;
|
||||
|
||||
m_State = PyGILState_GetThisThreadState();
|
||||
|
||||
ret = PyEval_EvalCode(compiled, context_namespace, context_namespace);
|
||||
@@ -674,18 +676,26 @@ PyObject *PythonContext::outstream_flush(PyObject *self, PyObject *args)
|
||||
|
||||
int PythonContext::traceEvent(PyObject *obj, PyFrameObject *frame, int what, PyObject *arg)
|
||||
{
|
||||
PyObject *thisobj = PyDict_GetItemString(obj, "thisobj");
|
||||
|
||||
uint64_t thisuint64 = PyLong_AsUnsignedLongLong(thisobj);
|
||||
uintptr_t thisint = (uintptr_t)thisuint64;
|
||||
PythonContext *context = (PythonContext *)thisint;
|
||||
|
||||
PyObject *compiled = PyDict_GetItemString(obj, "compiled");
|
||||
if(compiled == (PyObject *)frame->f_code && what == PyTrace_LINE)
|
||||
{
|
||||
PyObject *thisobj = PyDict_GetItemString(obj, "thisobj");
|
||||
|
||||
uint64_t thisuint64 = PyLong_AsUnsignedLongLong(thisobj);
|
||||
uintptr_t thisint = (uintptr_t)thisuint64;
|
||||
PythonContext *context = (PythonContext *)thisint;
|
||||
context->location.line = PyFrame_GetLineNumber(frame);
|
||||
|
||||
emit context->traceLine(context->location.file, context->location.line);
|
||||
}
|
||||
|
||||
if(context->shouldAbort())
|
||||
{
|
||||
PyErr_SetString(PyExc_SystemExit, "Execution aborted.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -80,6 +80,8 @@ public:
|
||||
static PyObject *QWidgetToPy(QWidget *widget) { return QtObjectToPython("QWidget", widget); }
|
||||
static QWidget *QWidgetFromPy(PyObject *widget);
|
||||
|
||||
void abort() { m_Abort = true; }
|
||||
bool shouldAbort() { return m_Abort; }
|
||||
QString currentFile() { return location.file; }
|
||||
int currentLine() { return location.line; }
|
||||
signals:
|
||||
@@ -115,6 +117,8 @@ private:
|
||||
int line = 0;
|
||||
} location;
|
||||
|
||||
bool m_Abort = false;
|
||||
|
||||
static PyObject *QtObjectToPython(const char *typeName, QObject *object);
|
||||
|
||||
// Python callbacks
|
||||
|
||||
Reference in New Issue
Block a user