python pdb
abstract
pdb is Python's built-in debugger.
basics
-
pdb
is a Python module. -
python -m pdb
runs pdb like a script. python -m pdb myscript.py
runsmyscript.py
and starts pdb.- Python's breakpoint() function interrupts a script (or module) to start pdb.
commands
c |
continue until breakpoint |
h |
show help menu |
interact |
start interpreter |
n |
run until next line |
q |
quit debugger |
r |
run until function returns |
run |
run script again |
s |
step inside function |
unt 13 |
run until line 13 |
!statement |
execute statement |
args |
arguments for current function |
d 5 |
down 5 levels in stack trace |
l |
list lines near current line |
ll |
list lines in current frame |
l 13 |
list lines near line 13 |
l 13 20 |
list lines from 13 through 20 |
p x |
print value of x |
pp x |
pretty-print value of x |
source x |
source code of x |
w |
where are we in stack trace? |
u 5 |
up 5 levels in stack trace |
b |
show breakpoints |
b 13 |
set breakpoint at line 13 |
b func |
set breakpoint inside func() |
cl |
clear all breakpoints |
cl 3 |
clear 3rd breakpoint |
dependencies
pdb is included with Python.
examples
Run pdb like a script:
python -m pdb
Run path/to/myscript.py
and start pdb:
python -m pdb path/to/myscript.py
Start pdb from inside a Python interpreter:
python3 Python 3.7.0 (default, Aug 17 2018, 21:14:48) [Clang 9.1.0 (clang-902.0.39.2)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> breakpoint() --Return-- > <stdin>(1)<module>()->None
faq
- Where are the official docs?
- pdb module docs
- Where can I find other tutorials?
- DigitalOcean pdb tutorial
- Djangostars pdb tutorial