On this page
  1. pdb
  2. Import
  3. Overview
  4. Quick Start
  5. Implementation Walkthrough
  6. 1. Essential pdb Interactive Commands
  7. 2. Post-Mortem Debugging on Failure (pdb.post_mortem)
  8. Gotchas & Boundaries
  9. Common Functions
  10. Classes & Objects

pdb

Prev: pathlib | Up: stdlib_module | Next: pickle
Rel: typing, annotationlib, pydoc, pydoc_data, doctest
Ref: docs.python.org — pdb
Tags: #public #python3 #stdlib


Import

import pdb

Overview

Python's built-in interactive source debugger (breakpoint(), pdb.set_trace(), pdb.post_mortem(), python -m pdb script.py). Use built-in breakpoint() in code (which delegates to pdb by default and honors PYTHONBREAKPOINT=0 to disable breakpoints in CI/production).

Quick Start

# Run a script under pdb from line 1, or drop into post-mortem on uncaught error:
python3 -m pdb my_script.py
python3 -m pdb -c continue my_script.py

Implementation Walkthrough

1. Essential pdb Interactive Commands

2. Post-Mortem Debugging on Failure (pdb.post_mortem)

import pdb

def debug_on_crash(fn):
    try:
        return fn()
    except Exception:
        pdb.post_mortem()
        raise

Gotchas & Boundaries

Common Functions

Classes & Objects

Linked from

Related notes