annotate Lib/pdb.doc @ 4566:6403c94de50d legacy-trunk

Added safeguard against failure in __del__.
author Guido van Rossum <guido@python.org>
date Wed, 27 Nov 1996 19:39:58 +0000
parents 1940892d2fe3
children 35e1a140fe4e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
653
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1 The Python Debugger
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2 ===================
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
4 To use the debugger in its simplest form:
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
5
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
6 >>> import pdb
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
7 >>> pdb.run('<a statement>')
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
8
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
9 The debugger's prompt is '(Pdb) '. This will stop in the first
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
10 function call in <a statement>.
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
11
1041
3dac204b74fa Added post_mortem() and pm() interfaces to pdb and wdb.
Guido van Rossum <guido@python.org>
parents: 719
diff changeset
12 Alternatively, if a statement terminated with an unhandled exception,
3dac204b74fa Added post_mortem() and pm() interfaces to pdb and wdb.
Guido van Rossum <guido@python.org>
parents: 719
diff changeset
13 you can use pdb's post-mortem facility to inspect the contents of the
3dac204b74fa Added post_mortem() and pm() interfaces to pdb and wdb.
Guido van Rossum <guido@python.org>
parents: 719
diff changeset
14 traceback:
3dac204b74fa Added post_mortem() and pm() interfaces to pdb and wdb.
Guido van Rossum <guido@python.org>
parents: 719
diff changeset
15
3dac204b74fa Added post_mortem() and pm() interfaces to pdb and wdb.
Guido van Rossum <guido@python.org>
parents: 719
diff changeset
16 >>> <a statement>
3dac204b74fa Added post_mortem() and pm() interfaces to pdb and wdb.
Guido van Rossum <guido@python.org>
parents: 719
diff changeset
17 <exception traceback>
3dac204b74fa Added post_mortem() and pm() interfaces to pdb and wdb.
Guido van Rossum <guido@python.org>
parents: 719
diff changeset
18 >>> import pdb
3dac204b74fa Added post_mortem() and pm() interfaces to pdb and wdb.
Guido van Rossum <guido@python.org>
parents: 719
diff changeset
19 >>> pdb.pm()
3dac204b74fa Added post_mortem() and pm() interfaces to pdb and wdb.
Guido van Rossum <guido@python.org>
parents: 719
diff changeset
20
653
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
21 The commands recognized by the debugger are listed in the next
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
22 section. Most can be abbreviated as indicated; e.g., h(elp) means
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
23 that 'help' can be typed as 'h' or 'help' (but not as 'he' or 'hel',
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
24 nor as 'H' or 'Help' or 'HELP'). Optional arguments are enclosed in
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
25 square brackets.
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
26
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
27 A blank line repeats the previous command literally. (Except for
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
28 'list', where it lists the next 11 lines.)
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
29
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
30 Commands that the debugger doesn't recognize are assumed to be Python
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
31 statements and are executed in the context of the program being
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
32 debugged. Python statements can also be prefixed with an exclamation
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
33 point ('!'). This is a powerful way to inspect the program being
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
34 debugged; it is even possible to change variables. When an exception
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
35 occurs in such a statement, the exception name is printed but the
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
36 debugger's state is not changed.
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
37
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
38 The debugger is not directly programmable; but it is implemented as a
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
39 class from which you can derive your own debugger class, so you can
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
40 make as fancy as you like.
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
41
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
42
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
43 Debugger commands
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
44 =================
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
45
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
46 h(elp)
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
47 Without argument, print the list of available commands.
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
48 With a command name as argument, print help about that command
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
49 (this is currently not implemented).
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
50
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
51 w(here)
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
52 Print a stack trace, with the most recent frame at the bottom.
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
53 An arrow indicates the "current frame", which determines the
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
54 context of most commands.
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
55
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
56 d(own)
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
57 Move the current frame one level down in the stack trace
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
58 (to an older frame).
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
59
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
60 u(p)
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
61 Move the current frame one level up in the stack trace
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
62 (to a newer frame).
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
63
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1041
diff changeset
64 b(reak) [lineno | function]
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1041
diff changeset
65 With a line number argument, set a break there in the current
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1041
diff changeset
66 file. With a function name, set a break at the entry of that
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1041
diff changeset
67 function. Without argument, list all breaks.
653
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
68
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
69 cl(ear) [lineno]
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
70 With a line number argument, clear that break in the current file.
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
71 Without argument, clear all breaks (but first ask confirmation).
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
72
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
73 s(tep)
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
74 Execute the current line, stop at the first possible occasion
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
75 (either in a function that is called or in the current function).
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
76
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
77 n(ext)
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
78 Continue execution until the next line in the current function
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
79 is reached or it returns.
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
80
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
81 r(eturn)
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
82 Continue execution until the current function returns.
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
83
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
84 c(ont(inue))
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
85 Continue execution, only stop when a breakpoint is encountered.
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
86
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
87 l(ist) [first [,last]]
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
88 List source code for the current file.
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
89 Without arguments, list 11 lines around the current line
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
90 or continue the previous listing.
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
91 With one argument, list 11 lines starting at that line.
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
92 With two arguments, list the given range;
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
93 if the second argument is less than the first, it is a count.
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
94
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
95 a(rgs)
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
96 Print the argument list of the current function.
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
97
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
98 p expression
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
99 Print the value of the expression.
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
100
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
101 (!) statement
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
102 Execute the (one-line) statement in the context of
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
103 the current stack frame.
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
104 The exclamation point can be omitted unless the first word
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
105 of the statement resembles a debugger command.
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
106 To assign to a global variable you must always prefix the
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
107 command with a 'global' command, e.g.:
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
108 (Pdb) global list_options; list_options = ['-l']
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
109 (Pdb)
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
110
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
111 q(uit)
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
112 Quit from the debugger.
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
113 The program being executed is aborted.
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
114
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
115
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
116 How it works
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
117 ============
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
118
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
119 Some changes were made to the interpreter:
719
cce05a476e04 Document sys.settrace().
Guido van Rossum <guido@python.org>
parents: 653
diff changeset
120 - sys.settrace(func) sets the global trace function
653
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
121 - there can also a local trace function (see later)
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
122
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
123 Trace functions have three arguments: (frame, event, arg)
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
124 - frame is the current stack frame
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
125 - event is a string: 'call', 'line', 'return' or 'exception'
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
126 - arg is dependent on the event type
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
127 A trace function should return a new trace function or None.
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
128 Class methods are accepted (and most useful!) as trace methods.
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
129
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
130 The events have the following meaning:
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
131
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
132 'call': A function is called (or some other code block entered).
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
133 The global trace function is called;
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
134 arg is the argument list to the function;
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
135 the return value specifies the local trace function.
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
136
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
137 'line': The interpreter is about to execute a new line of code
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
138 (sometimes multiple line events on one line exist).
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
139 The local trace function is called; arg in None;
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
140 the return value specifies the new local trace function.
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
141
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
142 'return': A function (or other code block) is about to return.
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
143 The local trace function is called;
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
144 arg is the value that will be returned.
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
145 The trace function's return value is ignored.
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
146
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
147 'exception': An exception has occurred.
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
148 The local trace function is called;
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
149 arg is a triple (exception, value, traceback);
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
150 the return value specifies the new local trace function
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
151
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
152 Note that as an exception is propagated down the chain of callers, an
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
153 'exception' event is generated at each level.
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
154
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
155 Stack frame objects have the following read-only attributes:
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
156 f_code: the code object being executed
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
157 f_lineno: the current line number (-1 for 'call' events)
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
158 f_back: the stack frame of the caller, or None
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
159 f_locals: dictionary containing local name bindings
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
160 f_globals: dictionary containing global name bindings
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
161
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
162 Code objects have the following read-only attributes:
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
163 co_code: the code string
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
164 co_names: the list of names used by the code
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
165 co_consts: the list of (literal) constants used by the code
74942ec70430 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
166 co_filename: the filename from which the code was compiled