$ 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.pyRun pdb.pm() after an error raised
whereorw: shows the current line and treelistorl: shows more context around the current locationlonglistorll: shows the entire function or frame which contains the current locationsource OBJ: shows the source ofOBJupanddown: moves between frames towards older and newer stack, respectively
- Just type existing variables to check it out.
print(VAR)orp VAR: print a variableVARprettyprintorpp: pretty print!{expression}: runexpressionwithin 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 thereturnline of a function
break #LINENO: set a breakpoint to#LINENOlinecontinueorc: execute until the next breakpointbreak FILENAME:LINENO: set a breakpoint toLINENOof anotherFILENAMEbreak: list current breakpoints set
break OBJNAME: set a breakpoint toOBJNAMEdisable #BREAKPOINT: disable the breakpoint#BREAKPOINTenable #BREAKPOINT: enable the breakpoint#BREAKPOINTclear #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#HITNUMBERtimes 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 VARdisplay: list current variables to be displayedundisplay VAR
jump #LINENO: skip to#LINENOline if#CURRENT < #LINENO, otherwise jump back
$ python3 -m pdb myscript.py
# works are done
(pdb)run ARGS: restartmyscript.pywith argumentsARGS(space-separated text)
alias ALIAS COMMAND:ALIAS <- COMMANDalias: list all aliasesalias ALIAS: show information ofALIASCOMMANDcan take numbered arguments as format%n,%*consumes all argumentsunalias ALIAS: delete the alias
Write your .pdbrc