Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Legacy tracing & PY_UNWIND: arg of legacy tracer call should be NULL #110892

Closed
jpe opened this issue Oct 15, 2023 · 7 comments
Closed

Legacy tracing & PY_UNWIND: arg of legacy tracer call should be NULL #110892

jpe opened this issue Oct 15, 2023 · 7 comments
Assignees
Labels
3.12 bugs and security fixes 3.13 bugs and security fixes type-bug An unexpected behavior, bug, or error

Comments

@jpe
Copy link

jpe commented Oct 15, 2023

Bug report

Bug description:

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.

CPython versions tested on:

3.12

Operating systems tested on:

No response

Linked PRs

@jpe jpe added the type-bug An unexpected behavior, bug, or error label Oct 15, 2023
@AlexWaygood AlexWaygood added 3.12 bugs and security fixes 3.13 bugs and security fixes labels Oct 15, 2023
@gaogaotiantian
Copy link
Member

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.

@jpe
Copy link
Author

jpe commented 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
Copy link
Member

Okay I think I understood what you were talking about.

@gaogaotiantian
Copy link
Member

PR is made to fix this.

@jpe
Copy link
Author

jpe commented 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
Copy link
Member

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?

Yes, sys_profile_unwind is changed to return NULL in the same PR.

@jpe
Copy link
Author

jpe commented Oct 17, 2023

I see the profile change now; LGTM.

FullteaR pushed a commit to FullteaR/cpython that referenced this issue Nov 3, 2023
aisk pushed a commit to aisk/cpython that referenced this issue Feb 11, 2024
Glyphack pushed a commit to Glyphack/cpython that referenced this issue Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.12 bugs and security fixes 3.13 bugs and security fixes type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

4 participants