Skip to content

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

Closed
@gaogaotiantian

Description

@gaogaotiantian

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions