Skip to content

Commit c3ee193

Browse files
committed
Update debugger.md
1 parent b88b4b5 commit c3ee193

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

app/templates/22_debugger.md

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ However, a better tool exists, and it comes with Python.
1212
On a new line in your code, write `breakpoint()`{: .smolcode} and run your code.
1313
When execution hits a line with a breakpoint, the code will pause and drop you into pdb.
1414
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}.
1617

1718
## Where am I?
1819
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
4243
If you type "p" followed by a variable name and hit enter, you can see the current value.
4344
You may omit the "p" if the variable name does not collide with a pdb command.
4445
"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 "!".
4647
This allows us to access the Python interpreter's help, rather than pdb's help, by typing `!help()`{: .smolcode}.
4748

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-
6049
## Where to next?
50+
To continue until the next breakpoint, run "cont(inue)".
51+
6152
To execute the current line and step into the next function or line, run the "step" command, or "s" for short.
6253

6354
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
6758

6859
To continue until the return of a frame, run "r(eturn)".
6960

70-
To continue until the next breakpoint, run "cont(inue)".
61+
To traverse up and down stack frames, run "up" and "down" respectively
7162

7263
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.
7377

7478
<<[prev]({{int_operators}}) [index]({{int_index}}) [next]({{int_classes}})>>

0 commit comments

Comments
 (0)