On this page
  1. bdb
  2. Import
  3. Overview
  4. Quick Start
  5. Implementation Walkthrough
  6. 1. Implementing user_line() for Line-by-Line Stepping
  7. Gotchas & Boundaries
  8. Classes & Objects

bdb

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


Import

import bdb

Overview

Base debugger framework (Bdb, Breakpoint, BdbQuit) that powers Python's interactive pdb debugger and IDE debuggers. Subclass bdb.Bdb when building a custom debugger, step tracer, or programmatic breakpoint runner without re-implementing sys.settrace() frame management from scratch.

Quick Start

import bdb

class CallLogger(bdb.Bdb):
    def __init__(self) -> None:
        super().__init__()
        self.calls: list[str] = []

    def user_call(self, frame, argument_list) -> None:
        self.calls.append(frame.f_code.co_name)

def greet() -> str:
    return "hi"

tracer = CallLogger()
result = tracer.runcall(greet)
assert result == "hi" and "greet" in tracer.calls

Implementation Walkthrough

1. Implementing user_line() for Line-by-Line Stepping

Override user_line(frame) to inspect locals or stop at breakpoints while calling self.set_step() / self.set_next(frame) / self.set_continue() to control execution flow.

Gotchas & Boundaries

Classes & Objects

Linked from

Related notes