So You Think You Can PDB?
Clayton Parker
So You Think You Can PDB? - Clayton Parker - PyCon 2015
Slide 2
Slide 2 text
Who am I?
Director of Engineering at Six Feet Up
claytron on the internets
Slide 3
Slide 3 text
What is PDB?
Interactive debugging tool
Pure awesome
Slide 4
Slide 4 text
How to invoke it?
Set a trace directly in the code:
import pdb; pdb.set_trace()
Or start a script with pdb directly:
$ python -m pdb example.py
It is that easy!
Slide 5
Slide 5 text
Now what?
Common commands
Navigating the stack
Slide 6
Slide 6 text
Help
Type help or ? for short to know what commands are available
Further help on commands help help or help list
Slide 7
Slide 7 text
Show the current context
Type list or l to see the current position in the code
Slide 8
Slide 8 text
Repeating the last command
Just type return
Slide 9
Slide 9 text
Examine variables
Type print or p to see what a variable is set to
Use pp to pretty print the result for easier reading
Slide 10
Slide 10 text
Go to the next line
Type next or n to go to the next line
Slide 11
Slide 11 text
Step into a function
Type step or s to step into a function for further inspection
Slide 12
Slide 12 text
Skip over a loop
Type until to skip over the end of a loop
Slide 13
Slide 13 text
Skip to the end of a function
Type return or r to go to the end of a function
Slide 14
Slide 14 text
Breakpoints
Type break or b to see a list of breakpoints
Then b and a line number to set one
To clear out a breakpoint clear or cl and a breakpoint number
Slide 15
Slide 15 text
Continue execution
Type continue or c to go to the next breakpoint or finish
execution
Slide 16
Slide 16 text
Conditional breakpoints
Breakpoints can take an expression to know when to break:
b 11, this_year == 2015
Slide 17
Slide 17 text
See where you are in the
stack
Type where or w to see the current stack
You can debug at any point in the stack
Slide 18
Slide 18 text
Traverse the stack
Type up or u to go up the stack
Type down or d to go back down the stack
Slide 19
Slide 19 text
New features in Python 3:
Interact
Type interact to open an interpreter in the current scope
Slide 20
Slide 20 text
New features in Python 3:
Long list
Type longlist or ll to show the complete current function
Slide 21
Slide 21 text
All done
Type quit or q to exit pdb and stop execution