The debugger prompts with a line like this:
(pdb)
At this prompt, you can type any of the
pdb commands discussed below. You
can abbreviate any command by omitting the characters in
square brackets. For example, the
where command can be abbreviated
as simply w.
h[elp] [cmd]Without an argument, prints a list of valid
commands. Use the argument to get help
on command cmd.cmd
!stmtExecute a Python statement
.
The “stmt!” may be omitted if the
statement does not resemble a
pdb command.
w[here]Shows your current location in the program as a
stack traceback, with an arrow (->)
pointing to the current stack frame.
q[uit]Exit pdb.
l[ist] [begin[,end]]Shows you Python source code. With no
arguments, it shows 11 lines centered around the
current point of execution. The line about to be
executed is marked with an arrow
(->), and the letter
B appears at the beginning
of lines with breakpoints set.
To look at a given range of source lines, use
the
argument to list 11 lines around that line number,
or provide the ending line number as an
beginend
argument. For example, the
command list 50,65 would
list lines 50-65.
If you press Enter at the
(pdb) prompt, the previous
command is repeated. The
list command is an
exception: an empty line entered after a
list command shows you the
next 11 lines after the ones previously
listed.
b[reak] [[filename:]lineno[,condition]], b[reak] [function[,condition]]The break command sets a
breakpoint at some location in your
program. If execution reaches a breakpoint, execution will be
suspended and you will get back to the
(pdb) prompt.
The first form sets a breakpoint at a specific
line in a source file. Specify the line number
within your source file as
;
add the
lineno
if you are working with multiple source files, or
if your source file hasn't been loaded yet.filename:
The second form sets a breakpoint on the first
executable statement of the given
.function
You can also specify a conditional breakpoint,
that is, one that interrupts execution only if a
given evaluates as
true. For example, the command conditionbreak
92,i>5 would break at line 92 only
when i is greater than 5.
When you set a breakpoint,
pdb prints a “breakpoint
number.” You will need to know this number to
clear the breakpoint.
tbreakSame options and behavior as
break, but the breakpoint is
temporary, that is, it is removed after the first
time it is hit.
cl[ear]
[lineno]If used without an argument, clears all
breakpoints. To clear one breakpoint, give its
breakpoint number (see break
above).
s[tep]Single step: execute the current line. If any
functions are called in the current line,
pdb will break upon entering
the function.
n[ext]Like step, but does not
stop on entering a called function.
c[ont[inue]]Resume execution until the next breakpoint (if any).
r[eturn]Resume execution until the current function returns.
a[rgs]Display the argument names and values to the currently executing function.
p
exprEvaluate an expression
expr and print its
value.