Switching frame will erase the local variable changes in pdb · Issue #102864 · python/cpython (original) (raw)
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
.