cpython/Lib/pdb.doc

125 lines
4.4 KiB
Plaintext
Raw Normal View History

1992-01-27 13:00:37 -04:00
The Python Debugger
===================
To use the debugger in its simplest form:
1998-07-20 20:22:51 -03:00
>>> import pdb
>>> pdb.run('<a statement>')
1992-01-27 13:00:37 -04:00
The debugger's prompt is '(Pdb) '. This will stop in the first
function call in <a statement>.
Alternatively, if a statement terminated with an unhandled exception,
you can use pdb's post-mortem facility to inspect the contents of the
traceback:
1998-07-20 20:22:51 -03:00
>>> <a statement>
<exception traceback>
>>> import pdb
>>> pdb.pm()
1992-01-27 13:00:37 -04:00
The commands recognized by the debugger are listed in the next
section. Most can be abbreviated as indicated; e.g., h(elp) means
that 'help' can be typed as 'h' or 'help' (but not as 'he' or 'hel',
nor as 'H' or 'Help' or 'HELP'). Optional arguments are enclosed in
square brackets.
A blank line repeats the previous command literally. (Except for
'list', where it lists the next 11 lines.)
Commands that the debugger doesn't recognize are assumed to be Python
statements and are executed in the context of the program being
debugged. Python statements can also be prefixed with an exclamation
point ('!'). This is a powerful way to inspect the program being
debugged; it is even possible to change variables. When an exception
occurs in such a statement, the exception name is printed but the
debugger's state is not changed.
The debugger is not directly programmable; but it is implemented as a
class from which you can derive your own debugger class, so you can
make as fancy as you like.
Debugger commands
=================
h(elp)
Without argument, print the list of available commands.
With a command name as argument, print help about that command
"help pdb" pipes the full documentation file to the $PAGER
"help exec" gives help on the ! command
1992-01-27 13:00:37 -04:00
w(here)
1998-07-20 20:22:51 -03:00
Print a stack trace, with the most recent frame at the bottom.
An arrow indicates the "current frame", which determines the
context of most commands.
1992-01-27 13:00:37 -04:00
d(own)
1998-07-20 20:22:51 -03:00
Move the current frame one level down in the stack trace
(to an older frame).
1992-01-27 13:00:37 -04:00
u(p)
1998-07-20 20:22:51 -03:00
Move the current frame one level up in the stack trace
(to a newer frame).
1992-01-27 13:00:37 -04:00
b(reak) ([file:]lineno | function) [, "condition"]
With a line number argument, set a break there in the current
file. With a function name, set a break at the entry of that
function. Without argument, list all breaks. If a second
argument is present, it is a string specifying an expression
which must evaluate to true before the breakpoint is honored.
The line number may be prefixed with a filename and a colon,
to specify a breakpoint in another file (probably one that
hasn't been loaded yet). The file is searched on sys.path.
1992-01-27 13:00:37 -04:00
cl(ear) [lineno]
1998-07-20 20:22:51 -03:00
With a line number argument, clear that break in the current file.
Without argument, clear all breaks (but first ask confirmation).
1992-01-27 13:00:37 -04:00
The line number may be prefixed with a filename and a colon,
to specify a breakpoint in another file (probably one that
hasn't been loaded yet). The file is searched on sys.path.
1992-01-27 13:00:37 -04:00
s(tep)
1998-07-20 20:22:51 -03:00
Execute the current line, stop at the first possible occasion
(either in a function that is called or in the current function).
1992-01-27 13:00:37 -04:00
n(ext)
1998-07-20 20:22:51 -03:00
Continue execution until the next line in the current function
is reached or it returns.
1992-01-27 13:00:37 -04:00
r(eturn)
1998-07-20 20:22:51 -03:00
Continue execution until the current function returns.
1992-01-27 13:00:37 -04:00
c(ont(inue))
1998-07-20 20:22:51 -03:00
Continue execution, only stop when a breakpoint is encountered.
1992-01-27 13:00:37 -04:00
l(ist) [first [,last]]
1998-07-20 20:22:51 -03:00
List source code for the current file.
Without arguments, list 11 lines around the current line
or continue the previous listing.
With one argument, list 11 lines starting at that line.
With two arguments, list the given range;
if the second argument is less than the first, it is a count.
1992-01-27 13:00:37 -04:00
a(rgs)
1998-07-20 20:22:51 -03:00
Print the argument list of the current function.
1992-01-27 13:00:37 -04:00
p expression
1998-07-20 20:22:51 -03:00
Print the value of the expression.
1992-01-27 13:00:37 -04:00
(!) statement
1998-07-20 20:22:51 -03:00
Execute the (one-line) statement in the context of
the current stack frame.
The exclamation point can be omitted unless the first word
of the statement resembles a debugger command.
To assign to a global variable you must always prefix the
command with a 'global' command, e.g.:
(Pdb) global list_options; list_options = ['-l']
(Pdb)
1992-01-27 13:00:37 -04:00
q(uit)
1998-07-20 20:22:51 -03:00
Quit from the debugger.
The program being executed is aborted.