$ python3 -m pdb myscript.py
$ python3
>>> import pdb
>>> import myscript
>>> pdb.run('myscript.MyObj(5).mymethod()')
Add pdb.set_trace()
anywhere you want to start debugging and then run it.
$ python3 myscript.py
Run pdb.pm()
after an error raised
where
orw
: shows the current line and treelist
orl
: shows more context around the current locationlonglist
orll
: shows the entire function or frame which contains the current locationsource OBJ
: shows the source ofOBJ
up
anddown
: moves between frames towards older and newer stack, respectively
- Just type existing variables to check it out.
print(VAR)
orp VAR
: print a variableVAR
prettyprint
orpp
: pretty print!{expression}
: runexpression
within the interpreter (it can change the value of a variable)interact
: dive into "interactive mode" and<CTRL-D>
for exiting the interactive prompt
step
: execute the line and step into if there is, otherwise move nextnext
: execute the line and move nextuntil
: execute until it progresses to the next line (e.g. run through a loop)return
: execute until thereturn
line of a function
break #LINENO
: set a breakpoint to#LINENO
linecontinue
orc
: execute until the next breakpointbreak FILENAME:LINENO
: set a breakpoint toLINENO
of anotherFILENAME
break
: list current breakpoints set
break OBJNAME
: set a breakpoint toOBJNAME
disable #BREAKPOINT
: disable the breakpoint#BREAKPOINT
enable #BREAKPOINT
: enable the breakpoint#BREAKPOINT
clear #BREAKPOINT
: delete the breakpoint#BREAKPOINT
tbreak
: it hits only once
break #LINENO, {conditional expression}
- `condition #BREAKPOINT {conditional expression}': gives the condition to the specified breakpoint
ignore #BREAKPOINT #HITNUMBER
: the specified breakpoint will only hit#HITNUMBER
times and then be ignoredignore #BREAKPOINT 0
: re-activate
command #BREAKPOINT
: register a custom command for the specified breakpoint (debugger prompt changes from(Pdb)
to(com)
display VAR
display
: list current variables to be displayedundisplay VAR
jump #LINENO
: skip to#LINENO
line if#CURRENT < #LINENO
, otherwise jump back
$ python3 -m pdb myscript.py
# works are done
(pdb)
run ARGS
: restartmyscript.py
with argumentsARGS
(space-separated text)
alias ALIAS COMMAND
:ALIAS <- COMMAND
alias
: list all aliasesalias ALIAS
: show information ofALIAS
COMMAND
can take numbered arguments as format%n
,%*
consumes all argumentsunalias ALIAS
: delete the alias
Write your .pdbrc