Skip to content

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

Closed

Description

@jpe

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

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    on Oct 15, 2023
  2. gaogaotiantian commented on Oct 15, 2023

    @gaogaotiantian
    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.

  3. jpe commented on Oct 15, 2023

    @jpe
    Author

    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.

  4. gaogaotiantian commented on Oct 15, 2023

    @gaogaotiantian
    Member

    Okay I think I understood what you were talking about.

  5. gaogaotiantian commented on Oct 15, 2023

    @gaogaotiantian
    Member

    PR is made to fix this.

  6. jpe commented on Oct 16, 2023

    @jpe
    Author

    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?

  7. gaogaotiantian commented on Oct 16, 2023

    @gaogaotiantian
    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.

  8. jpe commented on Oct 17, 2023

    @jpe
    Author

    I see the profile change now; LGTM.

  9. added a commit that references this issue on Nov 2, 2023
  10. added a commit that references this issue on Nov 3, 2023
  11. added a commit that references this issue on Feb 11, 2024
  12. added a commit that references this issue on Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

3.12only security fixes3.13only security fixestype-bugAn unexpected behavior, bug, or error

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions