You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: app/templates/22_debugger.md
+19-15Lines changed: 19 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,8 @@ However, a better tool exists, and it comes with Python.
12
12
On a new line in your code, write `breakpoint()`{: .smolcode} and run your code.
13
13
When execution hits a line with a breakpoint, the code will pause and drop you into pdb.
14
14
From here, you can explore the state of the program, set new breakpoints, jump forwards or backwards in code, step through the program, and more.
15
-
If you ever forget what commands are available to you, type `help`{: .smolcode}. For a detailed help explaining all available commands at once and a summary of how to use pdb, type `help pdb`{: .smolcode}.
15
+
If you ever forget what commands are available to you, type `help`{: .smolcode}.
16
+
For a detailed help explaining all available commands at once and a summary of how to use pdb, type `help pdb`{: .smolcode}.
16
17
17
18
## Where am I?
18
19
There are several commands that can help orient you.
@@ -42,22 +43,12 @@ Inside the debugger, you can type any python expression and it will attempt to e
42
43
If you type "p" followed by a variable name and hit enter, you can see the current value.
43
44
You may omit the "p" if the variable name does not collide with a pdb command.
44
45
"pp" will pretty print the value, which sometimes makes reading collections and nested data structures easier on the eyes.
45
-
If you wish to run a function or inspect a variable with a name collision, you can start your command with an exclamation point "!".
46
+
If you wish to interact with a function or variable with a name collision, you can start your command with an exclamation point "!".
46
47
This allows us to access the Python interpreter's help, rather than pdb's help, by typing `!help()`{: .smolcode}.
47
48
48
-
We also might want to monitor the state of a variable over time.
49
-
Use the "display" command followed by an expression or the variable name, and it will print out the result of the expression with each step through the code.
50
-
Unfortunately, display does not work with the "continue" command when you are using `breakpoint()`{: .smolcode} inside your source code.
51
-
To get around this, you can put your breakpoint in a different location or start your program with pdb and no initial breakpoints.
52
-
Then, use "break" followed by a line number to set your breakpoint.
53
-
Now, display will work as we expect and will update us on changes that occur after we "continue".
54
-
55
-
You may wish to have the full capabilities of the Python interpreter.
56
-
Type "interact" to invoke an interpreter.
57
-
Note that any state you create inside of the interpreter will be lost when you return to the debugger.
58
-
One way around this is to create any variables you wish to save between both sessions inside the debugger before invoking the interpreter.
59
-
60
49
## Where to next?
50
+
To continue until the next breakpoint, run "cont(inue)".
51
+
61
52
To execute the current line and step into the next function or line, run the "step" command, or "s" for short.
62
53
63
54
To continue execution until the next line, run "n(ext)". This will NOT go in to a function.
@@ -67,8 +58,21 @@ If not given a line number n, it will continue execution until a line with a num
67
58
68
59
To continue until the return of a frame, run "r(eturn)".
69
60
70
-
To continue until the next breakpoint, run "cont(inue)".
61
+
To traverse up and down stack frames, run "up" and "down" respectively
71
62
72
63
To quit out of the debugger, run "quit".
64
+
On Unix systems, you may also press <Ctrl+D\>
65
+
66
+
## Miscellaneous
67
+
Use the "display" command followed by an expression or variable name to watch its state over time.
68
+
Unfortunately, display does not work with the "continue" command when you are using `breakpoint()`{: .smolcode} inside your source code.
69
+
To get around this, you can put your breakpoint in a different location or start your program with pdb and no initial breakpoints.
70
+
Then, use "break" followed by a line number to set your breakpoint.
71
+
Now, display will work as we expect and will update us on changes that occur after we "continue".
72
+
73
+
You may notice that inside pdb, you cannot make use of multiline statements such as for loops.
74
+
Type "interact" to invoke the full Python interpreter.
75
+
Note that any state you create inside of the interpreter will be lost when you return to the debugger.
76
+
You may create mutable variables (such as a list or dictionary) inside of pdb before entering the interpreter to get around this limitation.
0 commit comments