Commandline debugging python
From: https://docs.python.org/3/library/pdb.html
Source code: Lib/pdb.py
The module pdb defines an interactive source code debugger for Python programs. It supports setting breakpoints and single stepping at the source line level, inspection of stack frames, source code listing, and evaluation of arbitrary Python code in the context of any stack frame.
pdb.py can also be invoked as a script to debug other scripts. For example:
python3 -m pdb myscript.py
Following commands can be used in the pdb:
- h(elp) [command] Without argument, print the list of available commands
- w(here) Print a stack trace
- d(own) [count] Move to a lower(newer) frame
- u(p) [count] Move to an upper(older) frame
- b(reak) [([filename:]lineno | function) [, condition]] Without argument, list all breaks.
- cl(ear) [filename:lineno | bpnumber [bpnumber …]] Without argument, clear all breaks
- disable [bpnumber [bpnumber …]] Disable the breakpoints
- enable [bpnumber [bpnumber …]] Enable the breakpoints
- s(tep) Step in the current line
- n(ext) Continue execution until the next line
- unt(il) [lineno] With a line number, continue execution until a line with a number greater or equal to that is reached. Without argument, continue execution until the line with a number greater than the current one is reached. In both cases, also stop when the current frame returns.
- r(eturn) Continue execution until the current function returns
- c(ont(inue)) Continue execution, only stop when a breakpoint is encountered.
- j(ump) Set the next line that will be executed. Only available in the bottom-most frame.
- l(ist) [first[, last]] List source code for the current file. Without arguments, list 11 lines around the current line or continue the previous listing. With . as argument, list 11 lines around the current line. With one argument, list 11 lines around at that line. With two arguments, list the given range; if the second argument is less than the first, it is interpreted as a count.
- ll | longlist List all source code for the current function or frame.
- a(rgs) Print the argument list of the current function
- p expression Evaluate the expression in the current context and print its value
- pp expression Like the p command, except the value of the expression is pretty-printed using pprint module
- whatis expression Print the type of the expression
- source expression Try to get source code for the given object and display it
- (run | restart) [args] Restart the debugged Python program
- q(uit) Quit from the debugger