Skip to content

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

Closed

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

Activity

  1. gaogaotiantian commented on Mar 21, 2023

    @gaogaotiantian
    MemberAuthor

    @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.

  2. changed the title [-]Switching frame will erase the local variable changes[/-] [+]Switching frame will erase the local variable changes in pdb[/+] on Mar 21, 2023
  3. iritkatriel commented on Mar 21, 2023

    @iritkatriel
    Member

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

  4. gaogaotiantian commented on Mar 21, 2023

    @gaogaotiantian
    MemberAuthor

    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.

  5. added
    stdlibStandard Library Python modules in the Lib/ directory
    on Mar 22, 2023
  6. gaogaotiantian commented on May 5, 2024

    @gaogaotiantian
    MemberAuthor

    This is fixed by PEP 667.

  7. added a commit that references this issue on May 26, 2024
  8. added a commit that references this issue on Jul 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions