GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Cannot define global variables in .pdbrc · Issue #119580 · python/cpython

Cannot define global variables in .pdbrc #119580

New issue
Copy link
New issue
Copy link
Closed as not planned
Closed as not planned
Cannot define global variables in .pdbrc#119580
Copy link
Assignees
gaogaotiantian
Labels
type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@Delengowski
Delengowski
opened on May 26, 2024
Issue body actions

Bug report

Bug description:

#116660 closed gh-90095 to properly handle commands issued through -c or .pdbrc. The pdb documentation also speaks of convenience variables which is a debugging global variable. I was expecting to be able to define a variable starting with $ as defined in the documentation below, and make manipulations to that variable through commands in a .pdbrc, but doing the following $_capture_list = [] in .pdbrc issues a syntax error

To set a temporary global variable, use a convenience variable. A convenience variable is a variable whose name starts with $. For example, $foo = 1 sets a global variable $foo which you can use in the debugger session. The convenience variables are cleared when the program resumes execution so it’s less likely to interfere with your program compared to using normal variables like foo = 1.

CPython versions tested on:

3.11

Operating systems tested on:

Linux

Linked PRs

  • gh-119580: Improve version added section for convenience variable #119583
  • [3.13] gh-119580: Improve version added section for convenience variable (GH-119583) #119624
  • [3.12] gh-119580: Improve version added section for convenience variable (GH-119583) #119625

Activity

  1. Delengowski
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on May 26, 2024
  2. AlexWaygood
    assigned
    gaogaotiantian
    on May 26, 2024
  3. Delengowski commented on May 26, 2024

    @Delengowski
    Delengowski
    on May 26, 2024
    ContributorAuthor
    More actions

    I may be misunderstanding the paragraph. Perhaps the convenience variable is restricted to the scope of the command and should not be persistent throughout the entire debugging session.

    Example program

    from itertools import product
    
    x_axis = range(6)
    y_axis = range(6)
    
    for x,y in product(x_axis, y_axis):
        ...

    In the same directory .pdbrc

    $equal_components = []
    b 7, (x ==y)
    commands
    $equal_components.append((x,y))
    print($equal_components)
    continue
    

    Displays *** SyntaxError: invalid syntax

    Instead I attempt

    b 7, (x ==y)
    commands
    $equal_components.append((x,y))
    print($equal_components)
    continue
    

    Then invoke with python -m pdb example.py and manually type

    (Pdb) commands
    (com) $equal_components = []
    (com) end
    (Pdb) continue
    

    Which does not work either, I'm presuming because there is no breakpoint to associate that command with.

    What does work is

    b 7, (x ==y)
    commands
    print((x,y))
    continue
    
    Breakpoint 1 at /tmp/example_pdbrc.py:7
    (Pdb) c
    (0, 0)
    > /tmp/example_pdbrc.py(7)<module>()
    -> ...
    (1, 1)
    > /tmp/example_pdbrc.py(7)<module>()
    -> ...
    (2, 2)
    > /tmp/example_pdbrc.py(7)<module>()
    -> ...
    (3, 3)
    > /tmp/example_pdbrc.py(7)<module>()
    -> ...
    (4, 4)
    > /tmp/example_pdbrc.py(7)<module>()
    -> ...
    (5, 5)
    > /tmp/example_pdbrc.py(7)<module>()
    -> ...
    The program finished and will be restarted
    
  4. gaogaotiantian commented on May 26, 2024

    @gaogaotiantian
    gaogaotiantian
    on May 26, 2024
    Member
    More actions

    First of all, you listed that you were using Python 3.11, is that the case? Convenience variable is a feature added in Python 3.12 so it won't work with 3.11.

  5. Delengowski commented on May 26, 2024

    @Delengowski
    Delengowski
    on May 26, 2024
    ContributorAuthor
    More actions

    First of all, you listed that you were using Python 3.11, is that the case? Convenience variable is a feature added in Python 3.12 so it won't work with 3.11.

    Ah, let me try 3.12 with your backport

  6. Delengowski commented on May 26, 2024

    @Delengowski
    Delengowski
    on May 26, 2024
    ContributorAuthor
    More actions

    Defining a convenience variable through .pdbrc does indeed work correctly when using 3.12 with your backport. Although from the paragraph I believe I was misunderstanding how it persists between breakpoints (it doesn't appear to).

    With that being said I do find it unclear that convenience variables were added in 3.12 or specific convenience variables ($_frame, etc.) were added in 3.12, or really what of the previous 6 paragraphs was added 3.12.

  7. gaogaotiantian commented on May 26, 2024

    @gaogaotiantian
    gaogaotiantian
    on May 26, 2024
    Member
    More actions

    I agree that the added version is not super clear and I can try to improve it. However, about the persistence:

    The convenience variables are cleared when the program resumes execution

    Your program resumes execution between breakpoints so the convenience variables will be cleared. I think this behavior is well-described.

  8. Delengowski commented on May 26, 2024

    @Delengowski
    Delengowski
    on May 26, 2024
    ContributorAuthor
    More actions

    Yes I misunderstood the behavior of the convenience variables. As such I will close this.

  9. Delengowski
    closed this as completedon May 26, 2024
  10. gaogaotiantian
    closed this as not plannedon May 26, 2024
  11. AlexWaygood
    added a commit that references this issue on May 27, 2024

    gh-119580: Improve version added section for convenience variable (#1…

    3dfa364
  12. miss-islington
    added 2 commits that reference this issue on May 27, 2024

    pythongh-119580: Improve version added section for convenience variab…

    0ee7326

    pythongh-119580: Improve version added section for convenience variab…

    7dfbce5
  13. AlexWaygood
    added 2 commits that reference this issue on May 27, 2024

    [3.12] gh-119580: Improve version added section for convenience varia…

    823c66a

    [3.13] gh-119580: Improve version added section for convenience varia…

    9edf010
  14. estyxx
    added a commit that references this issue on Jul 17, 2024

    pythongh-119580: Improve version added section for convenience variab…

    5e86c5e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @gaogaotiantian
    gaogaotiantian

Labels

type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.