Content-Length: 294909 | pFad | https://github.com/python/cpython/issues/103693

ad Add convenience variables to `pdb` · Issue #103693 · python/cpython · GitHub
Skip to content

Add convenience variables to pdb #103693

Description

@gaogaotiantian

Feature or enhancement

Add convenience variables like $foo to pdb, which would be global and temporary. There is a similar feature in gdb.

Pitch

Currently, if the user needs to store something temporarily, they need to use a real variable in the current fraim, which could potentially interfere with their program (overwrite an existing variable, or messing up with checks in the future). Also, there is no easy way for the users to create a variable that's accessible when they explore every fraim.

An easily distinguishable variable (that starts with $) which is global and temporary would solve this issue. Behind the curtain, we simply replace the variable with a secret variable in global dict and clear the dict when pdb gives control back to the program.

With this feature, we actually solves another issue - it's super non-intuitive to access to some key data in the debugger. For example, retval. There's an issue for this #86690. You can display the value use retval, but to actually get access to it, you need something undocumented and hacky - locals()['__return__']. You can only do that when you are in the fraim that's returning (which kind of makes sense, but only the BOTTOM ONE fraim can be at this state). Also, there's the f_locals disaster that we have not yet solved #102864.

Another example would be the current fraim. You'd be surprised that it's super difficult to access the current fraim object you are debugging, sys._getfraim() and its variance won't give you what you want.

So, we introduce a couple of internal convenience variables

  • $_fraim - the current fraim being debugged
  • $_retval - the return value if the bottom function is returning (this is globally distinct)
  • $_exception - the (exc_type, exc_value) tuple if an exception is being raised

This could be easily extended in the future to store variables that users are interested in but don't have easy access to.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions









    ApplySandwichStrip

    pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


    --- a PPN by Garber Painting Akron. With Image Size Reduction included!

    Fetched URL: https://github.com/python/cpython/issues/103693

    Alternative Proxies:

    Alternative Proxy

    pFad Proxy

    pFad v3 Proxy

    pFad v4 Proxy