Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot define global variables in .pdbrc #119580

Closed
Delengowski opened this issue May 26, 2024 · 6 comments
Closed

Cannot define global variables in .pdbrc #119580

Delengowski opened this issue May 26, 2024 · 6 comments
Assignees
Labels
type-bug An unexpected behavior, bug, or error

Comments

@Delengowski
Copy link
Contributor

Delengowski commented May 26, 2024

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

@Delengowski Delengowski added the type-bug An unexpected behavior, bug, or error label May 26, 2024
@Delengowski
Copy link
Contributor Author

Delengowski commented 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)
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

@gaogaotiantian
Copy link
Member

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.

@Delengowski
Copy link
Contributor Author

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

@Delengowski
Copy link
Contributor Author

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.

@gaogaotiantian
Copy link
Member

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.

@Delengowski
Copy link
Contributor Author

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

@gaogaotiantian gaogaotiantian closed this as not planned Won't fix, can't repro, duplicate, stale May 26, 2024
miss-islington pushed a commit to miss-islington/cpython that referenced this issue May 27, 2024
…le (pythonGH-119583)

(cherry picked from commit 3dfa364)

Co-authored-by: Tian Gao <gaogaotiantian@hotmail.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue May 27, 2024
…le (pythonGH-119583)

(cherry picked from commit 3dfa364)

Co-authored-by: Tian Gao <gaogaotiantian@hotmail.com>
AlexWaygood pushed a commit that referenced this issue May 27, 2024
…ble (GH-119583) (#119625)

Co-authored-by: Tian Gao <gaogaotiantian@hotmail.com>
AlexWaygood pushed a commit that referenced this issue May 27, 2024
…ble (GH-119583) (#119624)

Co-authored-by: Tian Gao <gaogaotiantian@hotmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants