-
Notifications
You must be signed in to change notification settings - Fork 8
Pdb tutorial
Help me (Chris) create a resource for new users to learn PDB effectively. I'll use the result of our efforts as a PyCon talk, to be recorded, so we can point new users at the result. Here's the beginnings of an outline for such a talk:
PDB is an interactive debugging environment for Python programs. It allows you to pause your program, look at the values of variables, and watch program execution step-by-step, so you can understand what your program is actually doing, as opposed to what you think it's doing.
Effectively using PDB is arguably the most important skill a new Python developer can learn. This talk will show novice and intermediate Python users how to use PDB to troubleshoot existing code.
-
When is it reasonable to use PDB?
-
"I don't use a debugger"
-
When is it really not reasonable?
-
-
Modes of pdb usage
-
set_trace mode, e.g. pdb.set_trace()
-
postmortem mode, e.g.
python -m pdb buggy.pyorpdb.pm() -
run mode, .e.g.
pdb.run('some.expression()').
-
-
Getting help
-
Shortcut aliases (
cvs.continue) -
The workhorse commands (list, print, pretty-print, next, continue, step, return, until, where, up, down):
-
list: displaying code in your current execution context -
pandpp: displaying objects -
continue,step,return,next,return,until: execution control -
where: showing the current location in the frame stack -
up,down: navigating the frame stack
-
-
Managing breakpoints (break, tbreak, ignore, enable, disable, clear):
-
break,tbreak,ignore,enable,disable, andclear: Managing breakpoints
-
-
Lesser-used commands (args, !-prefixing, debug)
-
debug: recursive debugging -
!-prefixing: modifying variables -
args: printing args to the current function -
commands: scripting pdb
-
-
~/.pdbrc and PDB aliases
-
Debugging in the face of threads (ie. web apps).
-
"Purple bags"
-
Enhanced shells: ipdb, pudb, winpdb
-
In-editor debugger integration (Wing, Eclipse PyDev, PyCharm, etc)
-