Skip to content

Switching frame will erase the local variable changes in pdb #102864

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

Closed
gaogaotiantian opened this issue Mar 21, 2023 · 4 comments
Closed

Switching frame will erase the local variable changes in pdb #102864

gaogaotiantian opened this issue Mar 21, 2023 · 4 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@gaogaotiantian
Copy link
Member

gaogaotiantian commented Mar 21, 2023

This issue is related to #101673 , where f_locals being accessed during the debugging clears the changes of local variables. We need to only do one access of f_locals before giving back control.

def f():
    a = 1
    breakpoint()
    print(a)

f()
> /home/gaogaotiantian/programs/mycpython/example.py(4)f()
-> print(a)
(Pdb) p a
1
(Pdb) !a = 2
(Pdb) p a
2
(Pdb) u
> /home/gaogaotiantian/programs/mycpython/example.py(6)<module>()
-> f()
(Pdb) d
> /home/gaogaotiantian/programs/mycpython/example.py(4)f()
-> print(a)
(Pdb) p a
1

The worst part is, print_stack_entry calls format_stack_entry which is a bdb function, and it accesses f_locals. To keep the maximum compatibility of bdb, I decided to leave it alone and only fix pdb.

Linked PRs

@gaogaotiantian gaogaotiantian added the type-bug An unexpected behavior, bug, or error label Mar 21, 2023
@gaogaotiantian
Copy link
Member Author

@iritkatriel could you take a look at the issue when you have some time as you reviewed the related one so you might already know the fundamental problem.

@gaogaotiantian gaogaotiantian changed the title Switching frame will erase the local variable changes Switching frame will erase the local variable changes in pdb Mar 21, 2023
@iritkatriel
Copy link
Member

When was this issue introduced? Is it part of the 3.10/3.11 changes to frames?

@gaogaotiantian
Copy link
Member Author

Unfortunately no. This issue has been there for a long time. As far as I can tell, you can repro it on 3.8. If I had to guess, it's probably when Python started using FAST instead of local variable dict.

@gaogaotiantian
Copy link
Member Author

This is fixed by PEP 667.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants