You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Legacy tracing & PY_UNWIND: arg of legacy tracer call should be NULL #110892
When using a legacy tracer with PyEval_SetTrace and a function exits with an exception, the arg of the tracer event PyTrace_RETURN should be NULL docs. Currently in 3.12 (& 3.13), the arg is set to the exception value because the PY_UNWIND handler is forwarding its arg to the legacy tracer function.
I'm confused. Why do you think the exception is passed to the legacy tracer? Could you share an example code?
In _PyEval_SetTrace, the callback of PY_MONITORING_EVENT_PY_UNWIND is sys_trace_func3 which unconditionally passes Py_None as the arg to the trace function. That is the case for both 3.12 and 3.13.
The arg needs to be NULL and not Py_None when there's an exception. For the legacy tracer 'r' event, the arg is the value returned so arg=Py_None indicates None is returned without an exception.
I found this while debugging Wing's debugger which uses a C implemented trace function and I saw the arg was not NULL and didn't look at what the value was or look closely up the stack; sorry. It may be that the trampoline that called a Python implemented trace function passed Py_None when arg was NULL, but it's been years since I worked with a Python implemented trace function.
Activity
gaogaotiantian commentedon Oct 15, 2023
I'm confused. Why do you think the exception is passed to the legacy tracer? Could you share an example code?
In
_PyEval_SetTrace, the callback ofPY_MONITORING_EVENT_PY_UNWINDissys_trace_func3which unconditionally passesPy_Noneas the arg to the trace function. That is the case for both 3.12 and 3.13.jpe commentedon Oct 15, 2023
The arg needs to be NULL and not Py_None when there's an exception. For the legacy tracer 'r' event, the arg is the value returned so arg=Py_None indicates None is returned without an exception.
I found this while debugging Wing's debugger which uses a C implemented trace function and I saw the arg was not NULL and didn't look at what the value was or look closely up the stack; sorry. It may be that the trampoline that called a Python implemented trace function passed Py_None when arg was NULL, but it's been years since I worked with a Python implemented trace function.
gaogaotiantian commentedon Oct 15, 2023
Okay I think I understood what you were talking about.
gaogaotiantian commentedon Oct 15, 2023
PR is made to fix this.
jpe commentedon Oct 16, 2023
I've verified that the trace function gets a NULL on an UNWIND event with the PR. Thanks!
Shouldn't the profile function also get a NULL on an UNWIND event?
gaogaotiantian commentedon Oct 16, 2023
Yes,
sys_profile_unwindis changed to return NULL in the same PR.jpe commentedon Oct 17, 2023
I see the profile change now; LGTM.
gh-110892: Return NULL for `PyTrace_RETURN` events caused by an excep…
pythongh-110892: Return NULL for `PyTrace_RETURN` events caused by an…
pythongh-110892: Return NULL for `PyTrace_RETURN` events caused by an…
pythongh-110892: Return NULL for `PyTrace_RETURN` events caused by an…