Debugger and Profiler
The Debugger
Pdb is an interactive Python source-code debugger available as a standard library module.
Top-Level Interface
import pdbLoads debugger interface (a module written in Python).
pdb.run(string [,globals [,locals]])Runs code string string in the debugger. The string is assumed to contain a Python statement and runs in module __main__ by default unless globals and/or locals namespace dictionaries are passed.
pdb.runeval(string [,globals [,locals]])Like
pbd.run,but assumes string contains an expression (not a statement) and returns its result.pdb.runcall(func, arg1, arg2, . . . )Runs a call to function object func with the listed arguments (in the debugger). Returns func result.
pdb.pm( )Runs postmortem session on the last exception that occurred (much like debugging a core file).
pdb.post_mortem(tb)Runs a postmortem session on traceback object tb.
pdb.PdbA customizable debugger class which retains state between operations (e.g., break points).
Note
The debugger runs program until breakpoint reached, exception raised, or end of program, but it also stops initially so you can set break points and continue.
In run, string can be any Python statement, in the form of a Python string: pdb.run(“x = main(‘spam’)”).
To debug script files, import them, optionally setting sys.argv first: pdb.run(“import file”). Can also run scripts under debugger with a command line like: “python libpath/pdb.py myscript.py.”
Interactive Commands
Each command name has a short (h) and long (help) ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access