pdb
pdb is the Python debugger included in Python’s standard library. It provides an interactive, text-based debugging environment for Python programs that allows stepping through code execution, inspecting variables, and analyzing program state.
Core Features
Post-mortem Debugging
- Launches debugger when unhandled exceptions occur
- Allows inspection of program state at point of failure
Interactive Debugging
- Steps through code line by line
- Sets breakpoints at specific lines
- Evaluates expressions in current context
- Modifies variables during execution
Integration Methods
- Command line with
python -m pdb script.py
- Hard-coded breakpoints via
breakpoint()
function - Post-mortem analysis after exceptions
- Remote debugging capabilities
Key Commands
Program Flow
n
(next): Execute next lines
(step): Step into function callc
(continue): Continue executionr
(return): Continue until current function returnsq
(quit): Exit debugger
Breakpoints
b [filename:]lineno
: Set breakpointclear [filename:]lineno
: Remove breakpointtbreak
: Set temporary breakpointdisable
: Disable breakpointenable
: Enable breakpoint
Inspection
p expression
: Print value of expressionpp expression
: Pretty-print valuewhatis expression
: Print type of expressionl
: List source code around current linea
: Print current function’s arguments
Limitations
- Basic text-based interface
- Limited IDE integration
- Cannot modify frozen code objects
Learn More
Last updated on