LANGUAGE » PYTHON

Debug

Debug mode

This will run the script in loop.

shell
python -m pdb -c continue path/to/script.py

Add breakpoints

python
## ...
breakpoint()  # Python 3.7+
import pdb; pdb.set_trace()
## ...

Basic usage

CommandMeaningExplanation
hhelpPrint the list of available commands
wwherePrint a stack trace
sstepExecute the current line, stop at the first possible occasion
nnextContinue execution until the next line in the current function is reached or it returns
unt NuntilContinue execution until a line with a number greater or equal to N (default next) is reached
rreturnContinue execution until the current function returns
ccontinueContinue execution, only stop when a breakpoint is encountered
llistList 11 lines around the current line
lllonglistList all source code for the current function or frame
uupMove the current frame count (default one) levels up in the stack trace
ddownMove the current frame count (default one) levels down in the stack trace
p EXPprintPrint the value of EXPression
pp EXPpretty-printPretty-print the value of EXPression
whatis EXPwhatisPrint the type of the EXPression
qquitQuit from the debugger. The program being executed is aborted

Enter post-mortem debugging

python
import pdb; pdb.pm()