Repository navigation
Cannot define global variables in .pdbrc #119580
Description
Activity
- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on May 26, 2024 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) continueDisplays
*** SyntaxError: invalid syntaxInstead I attempt
b 7, (x ==y) commands $equal_components.append((x,y)) print($equal_components) continueThen invoke with
python -m pdb example.pyand manually type(Pdb) commands (com) $equal_components = [] (com) end (Pdb) continueWhich 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)) continueBreakpoint 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 restartedFirst 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.
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
Defining a convenience variable through
.pdbrcdoes 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.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.
Yes I misunderstood the behavior of the convenience variables. As such I will close this.
- added a commit that references this issue
on May 27, 2024
Bug report
Bug description:
#116660 closed gh-90095 to properly handle
commandsissued through-cor.pdbrc. Thepdbdocumentation 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 throughcommandsin a.pdbrc, but doing the following$_capture_list = []in.pdbrcissues a syntax errorCPython versions tested on:
3.11
Operating systems tested on:
Linux
Linked PRs