Skip to content

Instantly share code, notes, and snippets.

@timsonner
Last active March 9, 2026 01:46
Show Gist options
  • Select an option

  • Save timsonner/4e80754591a0e47d9a1ff1d9c59fda5e to your computer and use it in GitHub Desktop.

Select an option

Save timsonner/4e80754591a0e47d9a1ff1d9c59fda5e to your computer and use it in GitHub Desktop.
PDB - Python Debugger Reference

PDB - Python Debugger Reference

Import statement

import pdb; pdb.set_trace()
Command Action Brief Explanation
l (list) Show Code Shows 11 lines of code around your current position.
ll (long list) Show Function Shows the entire source code for the current function.
n (next) Step Over Executes current line; stops at the next line in the same function.
s (step) Step Into Follows execution inside a called function.
c (continue) Play Resumes program execution until the next breakpoint.
r (return) Step Out Runs until the current function returns to its caller.
p <var> Print Evaluates and prints a variable (e.g., p user_id).
pp <var> Pretty Print Formats dicts/lists/JSON into a readable tree structure.
w (where) Stack Trace Shows the call stack (how you got to this specific line).
u (up) / d (down) Move Stack Move Up to the caller or Down toward the current line.
b <line> Set Breakpoint Create a stop point at a line number (e.g., b 42).
b <line>, <cond> Conditional Break Only stop if condition is true (e.g., b 42, i > 10).
cl (clear) Clear Break Deletes a breakpoint (e.g., cl 1 to remove breakpoint #1).
j <line> Jump Time Travel: Skips ahead or goes back to re-run a line.
unt <line> Until Runs until the execution reaches a line number higher than current.
sticky Sticky Mode (Python 3.13+) Keeps code visible at the top while you step.
q (quit) Exit Immediately kills the debugger and the script.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment