Skip to content

Instantly share code, notes, and snippets.

@zahaar
Last active June 13, 2021 16:14
Show Gist options
  • Save zahaar/86da3129a71517fb3462bdc56c4ea1e3 to your computer and use it in GitHub Desktop.
Save zahaar/86da3129a71517fb3462bdc56c4ea1e3 to your computer and use it in GitHub Desktop.

Getting started

start pdb from within a script: import pdb;pdb.set_trace()

start pdb from the commandline: python -m pdb <file.py>

Basics

h(elp) print available commands.
h(elp) command print help about command.
q(quit) quit debugger.

Examine

p(rint) expr print the value of expr.
pp expr pretty-print the value of expr.
w(here) print current position (including stack trace).
l(ist) list 11 lines of code around the current line.
l(ist) first, last list from first to last line number.
a(rgs) print the args of the current function.

Movement

<ENTER> repeat the last command.
n(ext) execute the current statement (step over).
s(tep) execute and step into function.
r(eturn) continue execution until the current function returns.
c(ontinue) continue execution until a breakpoint is encountered.
u(p) move one level up in the stack trace.

credits : https://github.com/nblock/pdb-cheatsheet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment