Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Support changing return value of a function in sys.monitoring #135799

Open
@gaogaotiantian

Description

@gaogaotiantian

Feature or enhancement

Proposal:

gdb has a command return for users to immediately return from the function. It basically does two things:

  1. stop the execution of the function
  2. return an arbitrary value

In Python, 1. might not be that simple as we have all the references to the stack value (it should be doable, but may or may not worth it), but 2. should be pretty straightforward. We can allow the callback for PY_RETURN function to return something specific (like sys.monitoring.RETURN, retval) to replace the value we are about to return. It should only need to swap the value on the stack and the impact should be contained. Some of the instrumentation structure needs to be refactored a bit but I don't think it's too much work.

With this feature, we can "mock" the return value in the debugger. We can even expand our existing return command - we may not able to return immediately, but we can run until it returns and secretly swap the return value, so we can call this command from anywhere.

Does this sound like a reasonable feature or I'm missing something? @markshannon

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions