1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
|
<span id="bdb-debugger-framework"></span><h1>bdb — Debugger framework</h1> <p><strong>Source code:</strong> <a class="reference external" href="https://github.com/python/cpython/tree/3.12/Lib/bdb.py">Lib/bdb.py</a></p> <p>The <a class="reference internal" href="#module-bdb" title="bdb: Debugger framework."><code>bdb</code></a> module handles basic debugger functions, like setting breakpoints or managing execution via the debugger.</p> <p>The following exception is defined:</p> <dl class="py exception"> <dt class="sig sig-object py" id="bdb.BdbQuit">
<code>exception bdb.BdbQuit</code> </dt> <dd>
<p>Exception raised by the <a class="reference internal" href="#bdb.Bdb" title="bdb.Bdb"><code>Bdb</code></a> class for quitting the debugger.</p> </dd>
</dl> <p>The <a class="reference internal" href="#module-bdb" title="bdb: Debugger framework."><code>bdb</code></a> module also defines two classes:</p> <dl class="py class"> <dt class="sig sig-object py" id="bdb.Breakpoint">
<code>class bdb.Breakpoint(self, file, line, temporary=False, cond=None, funcname=None)</code> </dt> <dd>
<p>This class implements temporary breakpoints, ignore counts, disabling and (re-)enabling, and conditionals.</p> <p>Breakpoints are indexed by number through a list called <a class="reference internal" href="#bdb.Breakpoint.bpbynumber" title="bdb.Breakpoint.bpbynumber"><code>bpbynumber</code></a> and by <code>(file, line)</code> pairs through <a class="reference internal" href="#bdb.Breakpoint.bplist" title="bdb.Breakpoint.bplist"><code>bplist</code></a>. The former points to a single instance of class <a class="reference internal" href="#bdb.Breakpoint" title="bdb.Breakpoint"><code>Breakpoint</code></a>. The latter points to a list of such instances since there may be more than one breakpoint per line.</p> <p>When creating a breakpoint, its associated <a class="reference internal" href="#bdb.Breakpoint.file" title="bdb.Breakpoint.file"><code>file name</code></a> should be in canonical form. If a <a class="reference internal" href="#bdb.Breakpoint.funcname" title="bdb.Breakpoint.funcname"><code>funcname</code></a> is defined, a breakpoint <a class="reference internal" href="#bdb.Breakpoint.hits" title="bdb.Breakpoint.hits"><code>hit</code></a> will be counted when the first line of that function is executed. A <a class="reference internal" href="#bdb.Breakpoint.cond" title="bdb.Breakpoint.cond"><code>conditional</code></a> breakpoint always counts a <a class="reference internal" href="#bdb.Breakpoint.hits" title="bdb.Breakpoint.hits"><code>hit</code></a>.</p> <p><a class="reference internal" href="#bdb.Breakpoint" title="bdb.Breakpoint"><code>Breakpoint</code></a> instances have the following methods:</p> <dl class="py method"> <dt class="sig sig-object py" id="bdb.Breakpoint.deleteMe">
<code>deleteMe()</code> </dt> <dd>
<p>Delete the breakpoint from the list associated to a file/line. If it is the last breakpoint in that position, it also deletes the entry for the file/line.</p> </dd>
</dl> <dl class="py method"> <dt class="sig sig-object py" id="bdb.Breakpoint.enable">
<code>enable()</code> </dt> <dd>
<p>Mark the breakpoint as enabled.</p> </dd>
</dl> <dl class="py method"> <dt class="sig sig-object py" id="bdb.Breakpoint.disable">
<code>disable()</code> </dt> <dd>
<p>Mark the breakpoint as disabled.</p> </dd>
</dl> <dl class="py method"> <dt class="sig sig-object py" id="bdb.Breakpoint.bpformat">
<code>bpformat()</code> </dt> <dd>
<p>Return a string with all the information about the breakpoint, nicely formatted:</p> <ul class="simple"> <li>Breakpoint number.</li> <li>Temporary status (del or keep).</li> <li>File/line position.</li> <li>Break condition.</li> <li>Number of times to ignore.</li> <li>Number of times hit.</li> </ul> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.2.</span></p> </div> </dd>
</dl> <dl class="py method"> <dt class="sig sig-object py" id="bdb.Breakpoint.bpprint">
<code>bpprint(out=None)</code> </dt> <dd>
<p>Print the output of <a class="reference internal" href="#bdb.Breakpoint.bpformat" title="bdb.Breakpoint.bpformat"><code>bpformat()</code></a> to the file <em>out</em>, or if it is <code>None</code>, to standard output.</p> </dd>
</dl> <p><a class="reference internal" href="#bdb.Breakpoint" title="bdb.Breakpoint"><code>Breakpoint</code></a> instances have the following attributes:</p> <dl class="py attribute"> <dt class="sig sig-object py" id="bdb.Breakpoint.file">
<code>file</code> </dt> <dd>
<p>File name of the <a class="reference internal" href="#bdb.Breakpoint" title="bdb.Breakpoint"><code>Breakpoint</code></a>.</p> </dd>
</dl> <dl class="py attribute"> <dt class="sig sig-object py" id="bdb.Breakpoint.line">
<code>line</code> </dt> <dd>
<p>Line number of the <a class="reference internal" href="#bdb.Breakpoint" title="bdb.Breakpoint"><code>Breakpoint</code></a> within <a class="reference internal" href="#bdb.Breakpoint.file" title="bdb.Breakpoint.file"><code>file</code></a>.</p> </dd>
</dl> <dl class="py attribute"> <dt class="sig sig-object py" id="bdb.Breakpoint.temporary">
<code>temporary</code> </dt> <dd>
<p>True if a <a class="reference internal" href="#bdb.Breakpoint" title="bdb.Breakpoint"><code>Breakpoint</code></a> at (file, line) is temporary.</p> </dd>
</dl> <dl class="py attribute"> <dt class="sig sig-object py" id="bdb.Breakpoint.cond">
<code>cond</code> </dt> <dd>
<p>Condition for evaluating a <a class="reference internal" href="#bdb.Breakpoint" title="bdb.Breakpoint"><code>Breakpoint</code></a> at (file, line).</p> </dd>
</dl> <dl class="py attribute"> <dt class="sig sig-object py" id="bdb.Breakpoint.funcname">
<code>funcname</code> </dt> <dd>
<p>Function name that defines whether a <a class="reference internal" href="#bdb.Breakpoint" title="bdb.Breakpoint"><code>Breakpoint</code></a> is hit upon entering the function.</p> </dd>
</dl> <dl class="py attribute"> <dt class="sig sig-object py" id="bdb.Breakpoint.enabled">
<code>enabled</code> </dt> <dd>
<p>True if <a class="reference internal" href="#bdb.Breakpoint" title="bdb.Breakpoint"><code>Breakpoint</code></a> is enabled.</p> </dd>
</dl> <dl class="py attribute"> <dt class="sig sig-object py" id="bdb.Breakpoint.bpbynumber">
<code>bpbynumber</code> </dt> <dd>
<p>Numeric index for a single instance of a <a class="reference internal" href="#bdb.Breakpoint" title="bdb.Breakpoint"><code>Breakpoint</code></a>.</p> </dd>
</dl> <dl class="py attribute"> <dt class="sig sig-object py" id="bdb.Breakpoint.bplist">
<code>bplist</code> </dt> <dd>
<p>Dictionary of <a class="reference internal" href="#bdb.Breakpoint" title="bdb.Breakpoint"><code>Breakpoint</code></a> instances indexed by (<a class="reference internal" href="#bdb.Breakpoint.file" title="bdb.Breakpoint.file"><code>file</code></a>, <a class="reference internal" href="#bdb.Breakpoint.line" title="bdb.Breakpoint.line"><code>line</code></a>) tuples.</p> </dd>
</dl> <dl class="py attribute"> <dt class="sig sig-object py" id="bdb.Breakpoint.ignore">
<code>ignore</code> </dt> <dd>
<p>Number of times to ignore a <a class="reference internal" href="#bdb.Breakpoint" title="bdb.Breakpoint"><code>Breakpoint</code></a>.</p> </dd>
</dl> <dl class="py attribute"> <dt class="sig sig-object py" id="bdb.Breakpoint.hits">
<code>hits</code> </dt> <dd>
<p>Count of the number of times a <a class="reference internal" href="#bdb.Breakpoint" title="bdb.Breakpoint"><code>Breakpoint</code></a> has been hit.</p> </dd>
</dl> </dd>
</dl> <dl class="py class"> <dt class="sig sig-object py" id="bdb.Bdb">
<code>class bdb.Bdb(skip=None)</code> </dt> <dd>
<p>The <a class="reference internal" href="#bdb.Bdb" title="bdb.Bdb"><code>Bdb</code></a> class acts as a generic Python debugger base class.</p> <p>This class takes care of the details of the trace facility; a derived class should implement user interaction. The standard debugger class (<a class="reference internal" href="pdb#pdb.Pdb" title="pdb.Pdb"><code>pdb.Pdb</code></a>) is an example.</p> <p>The <em>skip</em> argument, if given, must be an iterable of glob-style module name patterns. The debugger will not step into frames that originate in a module that matches one of these patterns. Whether a frame is considered to originate in a certain module is determined by the <code>__name__</code> in the frame globals.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.1: </span>The <em>skip</em> argument.</p> </div> <p>The following methods of <a class="reference internal" href="#bdb.Bdb" title="bdb.Bdb"><code>Bdb</code></a> normally don’t need to be overridden.</p> <dl class="py method"> <dt class="sig sig-object py" id="bdb.Bdb.canonic">
<code>canonic(filename)</code> </dt> <dd>
<p>Return canonical form of <em>filename</em>.</p> <p>For real file names, the canonical form is an operating-system-dependent, <a class="reference internal" href="os.path#os.path.normcase" title="os.path.normcase"><code>case-normalized</code></a> <a class="reference internal" href="os.path#os.path.abspath" title="os.path.abspath"><code>absolute path</code></a>. A <em>filename</em> with angle brackets, such as <code>"<stdin>"</code> generated in interactive mode, is returned unchanged.</p> </dd>
</dl> <dl class="py method"> <dt class="sig sig-object py" id="bdb.Bdb.reset">
<code>reset()</code> </dt> <dd>
<p>Set the <code>botframe</code>, <code>stopframe</code>, <code>returnframe</code> and <code>quitting</code> attributes with values ready to start debugging.</p> </dd>
</dl> <dl class="py method"> <dt class="sig sig-object py" id="bdb.Bdb.trace_dispatch">
<code>trace_dispatch(frame, event, arg)</code> </dt> <dd>
<p>This function is installed as the trace function of debugged frames. Its return value is the new trace function (in most cases, that is, itself).</p> <p>The default implementation decides how to dispatch a frame, depending on the type of event (passed as a string) that is about to be executed. <em>event</em> can be one of the following:</p> <ul class="simple"> <li>
<code>"line"</code>: A new line of code is going to be executed.</li> <li>
<code>"call"</code>: A function is about to be called, or another code block entered.</li> <li>
<code>"return"</code>: A function or other code block is about to return.</li> <li>
<code>"exception"</code>: An exception has occurred.</li> <li>
<code>"c_call"</code>: A C function is about to be called.</li> <li>
<code>"c_return"</code>: A C function has returned.</li> <li>
<code>"c_exception"</code>: A C function has raised an exception.</li> </ul> <p>For the Python events, specialized functions (see below) are called. For the C events, no action is taken.</p> <p>The <em>arg</em> parameter depends on the previous event.</p> <p>See the documentation for <a class="reference internal" href="sys#sys.settrace" title="sys.settrace"><code>sys.settrace()</code></a> for more information on the trace function. For more information on code and frame objects, refer to <a class="reference internal" href="../reference/datamodel#types"><span class="std std-ref">The standard type hierarchy</span></a>.</p> </dd>
</dl> <dl class="py method"> <dt class="sig sig-object py" id="bdb.Bdb.dispatch_line">
<code>dispatch_line(frame)</code> </dt> <dd>
<p>If the debugger should stop on the current line, invoke the <a class="reference internal" href="#bdb.Bdb.user_line" title="bdb.Bdb.user_line"><code>user_line()</code></a> method (which should be overridden in subclasses). Raise a <a class="reference internal" href="#bdb.BdbQuit" title="bdb.BdbQuit"><code>BdbQuit</code></a> exception if the <code>Bdb.quitting</code> flag is set (which can be set from <a class="reference internal" href="#bdb.Bdb.user_line" title="bdb.Bdb.user_line"><code>user_line()</code></a>). Return a reference to the <a class="reference internal" href="#bdb.Bdb.trace_dispatch" title="bdb.Bdb.trace_dispatch"><code>trace_dispatch()</code></a> method for further tracing in that scope.</p> </dd>
</dl> <dl class="py method"> <dt class="sig sig-object py" id="bdb.Bdb.dispatch_call">
<code>dispatch_call(frame, arg)</code> </dt> <dd>
<p>If the debugger should stop on this function call, invoke the <a class="reference internal" href="#bdb.Bdb.user_call" title="bdb.Bdb.user_call"><code>user_call()</code></a> method (which should be overridden in subclasses). Raise a <a class="reference internal" href="#bdb.BdbQuit" title="bdb.BdbQuit"><code>BdbQuit</code></a> exception if the <code>Bdb.quitting</code> flag is set (which can be set from <a class="reference internal" href="#bdb.Bdb.user_call" title="bdb.Bdb.user_call"><code>user_call()</code></a>). Return a reference to the <a class="reference internal" href="#bdb.Bdb.trace_dispatch" title="bdb.Bdb.trace_dispatch"><code>trace_dispatch()</code></a> method for further tracing in that scope.</p> </dd>
</dl> <dl class="py method"> <dt class="sig sig-object py" id="bdb.Bdb.dispatch_return">
<code>dispatch_return(frame, arg)</code> </dt> <dd>
<p>If the debugger should stop on this function return, invoke the <a class="reference internal" href="#bdb.Bdb.user_return" title="bdb.Bdb.user_return"><code>user_return()</code></a> method (which should be overridden in subclasses). Raise a <a class="reference internal" href="#bdb.BdbQuit" title="bdb.BdbQuit"><code>BdbQuit</code></a> exception if the <code>Bdb.quitting</code> flag is set (which can be set from <a class="reference internal" href="#bdb.Bdb.user_return" title="bdb.Bdb.user_return"><code>user_return()</code></a>). Return a reference to the <a class="reference internal" href="#bdb.Bdb.trace_dispatch" title="bdb.Bdb.trace_dispatch"><code>trace_dispatch()</code></a> method for further tracing in that scope.</p> </dd>
</dl> <dl class="py method"> <dt class="sig sig-object py" id="bdb.Bdb.dispatch_exception">
<code>dispatch_exception(frame, arg)</code> </dt> <dd>
<p>If the debugger should stop at this exception, invokes the <a class="reference internal" href="#bdb.Bdb.user_exception" title="bdb.Bdb.user_exception"><code>user_exception()</code></a> method (which should be overridden in subclasses). Raise a <a class="reference internal" href="#bdb.BdbQuit" title="bdb.BdbQuit"><code>BdbQuit</code></a> exception if the <code>Bdb.quitting</code> flag is set (which can be set from <a class="reference internal" href="#bdb.Bdb.user_exception" title="bdb.Bdb.user_exception"><code>user_exception()</code></a>). Return a reference to the <a class="reference internal" href="#bdb.Bdb.trace_dispatch" title="bdb.Bdb.trace_dispatch"><code>trace_dispatch()</code></a> method for further tracing in that scope.</p> </dd>
</dl> <p>Normally derived classes don’t override the following methods, but they may if they want to redefine the definition of stopping and breakpoints.</p> <dl class="py method"> <dt class="sig sig-object py" id="bdb.Bdb.is_skipped_line">
<code>is_skipped_line(module_name)</code> </dt> <dd>
<p>Return True if <em>module_name</em> matches any skip pattern.</p> </dd>
</dl> <dl class="py method"> <dt class="sig sig-object py" id="bdb.Bdb.stop_here">
<code>stop_here(frame)</code> </dt> <dd>
<p>Return True if <em>frame</em> is below the starting frame in the stack.</p> </dd>
</dl> <dl class="py method"> <dt class="sig sig-object py" id="bdb.Bdb.break_here">
<code>break_here(frame)</code> </dt> <dd>
<p>Return True if there is an effective breakpoint for this line.</p> <p>Check whether a line or function breakpoint exists and is in effect. Delete temporary breakpoints based on information from <a class="reference internal" href="#bdb.effective" title="bdb.effective"><code>effective()</code></a>.</p> </dd>
</dl> <dl class="py method"> <dt class="sig sig-object py" id="bdb.Bdb.break_anywhere">
<code>break_anywhere(frame)</code> </dt> <dd>
<p>Return True if any breakpoint exists for <em>frame</em>’s filename.</p> </dd>
</dl> <p>Derived classes should override these methods to gain control over debugger operation.</p> <dl class="py method"> <dt class="sig sig-object py" id="bdb.Bdb.user_call">
<code>user_call(frame, argument_list)</code> </dt> <dd>
<p>Called from <a class="reference internal" href="#bdb.Bdb.dispatch_call" title="bdb.Bdb.dispatch_call"><code>dispatch_call()</code></a> if a break might stop inside the called function.</p> </dd>
</dl> <dl class="py method"> <dt class="sig sig-object py" id="bdb.Bdb.user_line">
<code>user_line(frame)</code> </dt> <dd>
<p>Called from <a class="reference internal" href="#bdb.Bdb.dispatch_line" title="bdb.Bdb.dispatch_line"><code>dispatch_line()</code></a> when either <a class="reference internal" href="#bdb.Bdb.stop_here" title="bdb.Bdb.stop_here"><code>stop_here()</code></a> or <a class="reference internal" href="#bdb.Bdb.break_here" title="bdb.Bdb.break_here"><code>break_here()</code></a> returns <code>True</code>.</p> </dd>
</dl> <dl class="py method"> <dt class="sig sig-object py" id="bdb.Bdb.user_return">
<code>user_return(frame, return_value)</code> </dt> <dd>
<p>Called from <a class="reference internal" href="#bdb.Bdb.dispatch_return" title="bdb.Bdb.dispatch_return"><code>dispatch_return()</code></a> when <a class="reference internal" href="#bdb.Bdb.stop_here" title="bdb.Bdb.stop_here"><code>stop_here()</code></a> returns <code>True</code>.</p> </dd>
</dl> <dl class="py method"> <dt class="sig sig-object py" id="bdb.Bdb.user_exception">
<code>user_exception(frame, exc_info)</code> </dt> <dd>
<p>Called from <a class="reference internal" href="#bdb.Bdb.dispatch_exception" title="bdb.Bdb.dispatch_exception"><code>dispatch_exception()</code></a> when <a class="reference internal" href="#bdb.Bdb.stop_here" title="bdb.Bdb.stop_here"><code>stop_here()</code></a> returns <code>True</code>.</p> </dd>
</dl> <dl class="py method"> <dt class="sig sig-object py" id="bdb.Bdb.do_clear">
<code>do_clear(arg)</code> </dt> <dd>
<p>Handle how a breakpoint must be removed when it is a temporary one.</p> <p>This method must be implemented by derived classes.</p> </dd>
</dl> <p>Derived classes and clients can call the following methods to affect the stepping state.</p> <dl class="py method"> <dt class="sig sig-object py" id="bdb.Bdb.set_step">
<code>set_step()</code> </dt> <dd>
<p>Stop after one line of code.</p> </dd>
</dl> <dl class="py method"> <dt class="sig sig-object py" id="bdb.Bdb.set_next">
<code>set_next(frame)</code> </dt> <dd>
<p>Stop on the next line in or below the given frame.</p> </dd>
</dl> <dl class="py method"> <dt class="sig sig-object py" id="bdb.Bdb.set_return">
<code>set_return(frame)</code> </dt> <dd>
<p>Stop when returning from the given frame.</p> </dd>
</dl> <dl class="py method"> <dt class="sig sig-object py" id="bdb.Bdb.set_until">
<code>set_until(frame, lineno=None)</code> </dt> <dd>
<p>Stop when the line with the <em>lineno</em> greater than the current one is reached or when returning from current frame.</p> </dd>
</dl> <dl class="py method"> <dt class="sig sig-object py" id="bdb.Bdb.set_trace">
<code>set_trace([frame])</code> </dt> <dd>
<p>Start debugging from <em>frame</em>. If <em>frame</em> is not specified, debugging starts from caller’s frame.</p> </dd>
</dl> <dl class="py method"> <dt class="sig sig-object py" id="bdb.Bdb.set_continue">
<code>set_continue()</code> </dt> <dd>
<p>Stop only at breakpoints or when finished. If there are no breakpoints, set the system trace function to <code>None</code>.</p> </dd>
</dl> <dl class="py method"> <dt class="sig sig-object py" id="bdb.Bdb.set_quit">
<code>set_quit()</code> </dt> <dd>
<p>Set the <code>quitting</code> attribute to <code>True</code>. This raises <a class="reference internal" href="#bdb.BdbQuit" title="bdb.BdbQuit"><code>BdbQuit</code></a> in the next call to one of the <code>dispatch_*()</code> methods.</p> </dd>
</dl> <p>Derived classes and clients can call the following methods to manipulate breakpoints. These methods return a string containing an error message if something went wrong, or <code>None</code> if all is well.</p> <dl class="py method"> <dt class="sig sig-object py" id="bdb.Bdb.set_break">
<code>set_break(filename, lineno, temporary=False, cond=None, funcname=None)</code> </dt> <dd>
<p>Set a new breakpoint. If the <em>lineno</em> line doesn’t exist for the <em>filename</em> passed as argument, return an error message. The <em>filename</em> should be in canonical form, as described in the <a class="reference internal" href="#bdb.Bdb.canonic" title="bdb.Bdb.canonic"><code>canonic()</code></a> method.</p> </dd>
</dl> <dl class="py method"> <dt class="sig sig-object py" id="bdb.Bdb.clear_break">
<code>clear_break(filename, lineno)</code> </dt> <dd>
<p>Delete the breakpoints in <em>filename</em> and <em>lineno</em>. If none were set, return an error message.</p> </dd>
</dl> <dl class="py method"> <dt class="sig sig-object py" id="bdb.Bdb.clear_bpbynumber">
<code>clear_bpbynumber(arg)</code> </dt> <dd>
<p>Delete the breakpoint which has the index <em>arg</em> in the <a class="reference internal" href="#bdb.Breakpoint.bpbynumber" title="bdb.Breakpoint.bpbynumber"><code>Breakpoint.bpbynumber</code></a>. If <em>arg</em> is not numeric or out of range, return an error message.</p> </dd>
</dl> <dl class="py method"> <dt class="sig sig-object py" id="bdb.Bdb.clear_all_file_breaks">
<code>clear_all_file_breaks(filename)</code> </dt> <dd>
<p>Delete all breakpoints in <em>filename</em>. If none were set, return an error message.</p> </dd>
</dl> <dl class="py method"> <dt class="sig sig-object py" id="bdb.Bdb.clear_all_breaks">
<code>clear_all_breaks()</code> </dt> <dd>
<p>Delete all existing breakpoints. If none were set, return an error message.</p> </dd>
</dl> <dl class="py method"> <dt class="sig sig-object py" id="bdb.Bdb.get_bpbynumber">
<code>get_bpbynumber(arg)</code> </dt> <dd>
<p>Return a breakpoint specified by the given number. If <em>arg</em> is a string, it will be converted to a number. If <em>arg</em> is a non-numeric string, if the given breakpoint never existed or has been deleted, a <a class="reference internal" href="exceptions#ValueError" title="ValueError"><code>ValueError</code></a> is raised.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.2.</span></p> </div> </dd>
</dl> <dl class="py method"> <dt class="sig sig-object py" id="bdb.Bdb.get_break">
<code>get_break(filename, lineno)</code> </dt> <dd>
<p>Return True if there is a breakpoint for <em>lineno</em> in <em>filename</em>.</p> </dd>
</dl> <dl class="py method"> <dt class="sig sig-object py" id="bdb.Bdb.get_breaks">
<code>get_breaks(filename, lineno)</code> </dt> <dd>
<p>Return all breakpoints for <em>lineno</em> in <em>filename</em>, or an empty list if none are set.</p> </dd>
</dl> <dl class="py method"> <dt class="sig sig-object py" id="bdb.Bdb.get_file_breaks">
<code>get_file_breaks(filename)</code> </dt> <dd>
<p>Return all breakpoints in <em>filename</em>, or an empty list if none are set.</p> </dd>
</dl> <dl class="py method"> <dt class="sig sig-object py" id="bdb.Bdb.get_all_breaks">
<code>get_all_breaks()</code> </dt> <dd>
<p>Return all breakpoints that are set.</p> </dd>
</dl> <p>Derived classes and clients can call the following methods to get a data structure representing a stack trace.</p> <dl class="py method"> <dt class="sig sig-object py" id="bdb.Bdb.get_stack">
<code>get_stack(f, t)</code> </dt> <dd>
<p>Return a list of (frame, lineno) tuples in a stack trace, and a size.</p> <p>The most recently called frame is last in the list. The size is the number of frames below the frame where the debugger was invoked.</p> </dd>
</dl> <dl class="py method"> <dt class="sig sig-object py" id="bdb.Bdb.format_stack_entry">
<code>format_stack_entry(frame_lineno, lprefix=': ')</code> </dt> <dd>
<p>Return a string with information about a stack entry, which is a <code>(frame, lineno)</code> tuple. The return string contains:</p> <ul class="simple"> <li>The canonical filename which contains the frame.</li> <li>The function name or <code>"<lambda>"</code>.</li> <li>The input arguments.</li> <li>The return value.</li> <li>The line of code (if it exists).</li> </ul> </dd>
</dl> <p>The following two methods can be called by clients to use a debugger to debug a <a class="reference internal" href="../glossary#term-statement"><span class="xref std std-term">statement</span></a>, given as a string.</p> <dl class="py method"> <dt class="sig sig-object py" id="bdb.Bdb.run">
<code>run(cmd, globals=None, locals=None)</code> </dt> <dd>
<p>Debug a statement executed via the <a class="reference internal" href="functions#exec" title="exec"><code>exec()</code></a> function. <em>globals</em> defaults to <code>__main__.__dict__</code>, <em>locals</em> defaults to <em>globals</em>.</p> </dd>
</dl> <dl class="py method"> <dt class="sig sig-object py" id="bdb.Bdb.runeval">
<code>runeval(expr, globals=None, locals=None)</code> </dt> <dd>
<p>Debug an expression executed via the <a class="reference internal" href="functions#eval" title="eval"><code>eval()</code></a> function. <em>globals</em> and <em>locals</em> have the same meaning as in <a class="reference internal" href="#bdb.Bdb.run" title="bdb.Bdb.run"><code>run()</code></a>.</p> </dd>
</dl> <dl class="py method"> <dt class="sig sig-object py" id="bdb.Bdb.runctx">
<code>runctx(cmd, globals, locals)</code> </dt> <dd>
<p>For backwards compatibility. Calls the <a class="reference internal" href="#bdb.Bdb.run" title="bdb.Bdb.run"><code>run()</code></a> method.</p> </dd>
</dl> <dl class="py method"> <dt class="sig sig-object py" id="bdb.Bdb.runcall">
<code>runcall(func, /, *args, **kwds)</code> </dt> <dd>
<p>Debug a single function call, and return its result.</p> </dd>
</dl> </dd>
</dl> <p>Finally, the module defines the following functions:</p> <dl class="py function"> <dt class="sig sig-object py" id="bdb.checkfuncname">
<code>bdb.checkfuncname(b, frame)</code> </dt> <dd>
<p>Return True if we should break here, depending on the way the <a class="reference internal" href="#bdb.Breakpoint" title="bdb.Breakpoint"><code>Breakpoint</code></a> <em>b</em> was set.</p> <p>If it was set via line number, it checks if <a class="reference internal" href="#bdb.Breakpoint.line" title="bdb.Breakpoint.line"><code>b.line</code></a> is the same as the one in <em>frame</em>. If the breakpoint was set via <a class="reference internal" href="#bdb.Breakpoint.funcname" title="bdb.Breakpoint.funcname"><code>function name</code></a>, we have to check we are in the right <em>frame</em> (the right function) and if we are on its first executable line.</p> </dd>
</dl> <dl class="py function"> <dt class="sig sig-object py" id="bdb.effective">
<code>bdb.effective(file, line, frame)</code> </dt> <dd>
<p>Return <code>(active breakpoint, delete temporary flag)</code> or <code>(None, None)</code> as the breakpoint to act upon.</p> <p>The <em>active breakpoint</em> is the first entry in <a class="reference internal" href="#bdb.Breakpoint.bplist" title="bdb.Breakpoint.bplist"><code>bplist</code></a> for the (<a class="reference internal" href="#bdb.Breakpoint.file" title="bdb.Breakpoint.file"><code>file</code></a>, <a class="reference internal" href="#bdb.Breakpoint.line" title="bdb.Breakpoint.line"><code>line</code></a>) (which must exist) that is <a class="reference internal" href="#bdb.Breakpoint.enabled" title="bdb.Breakpoint.enabled"><code>enabled</code></a>, for which <a class="reference internal" href="#bdb.checkfuncname" title="bdb.checkfuncname"><code>checkfuncname()</code></a> is True, and that has neither a False <a class="reference internal" href="#bdb.Breakpoint.cond" title="bdb.Breakpoint.cond"><code>condition</code></a> nor positive <a class="reference internal" href="#bdb.Breakpoint.ignore" title="bdb.Breakpoint.ignore"><code>ignore</code></a> count. The <em>flag</em>, meaning that a temporary breakpoint should be deleted, is False only when the <a class="reference internal" href="#bdb.Breakpoint.cond" title="bdb.Breakpoint.cond"><code>cond</code></a> cannot be evaluated (in which case, <a class="reference internal" href="#bdb.Breakpoint.ignore" title="bdb.Breakpoint.ignore"><code>ignore</code></a> count is ignored).</p> <p>If no such entry exists, then (None, None) is returned.</p> </dd>
</dl> <dl class="py function"> <dt class="sig sig-object py" id="bdb.set_trace">
<code>bdb.set_trace()</code> </dt> <dd>
<p>Start debugging with a <a class="reference internal" href="#bdb.Bdb" title="bdb.Bdb"><code>Bdb</code></a> instance from caller’s frame.</p> </dd>
</dl> <div class="_attribution">
<p class="_attribution-p">
© 2001–2023 Python Software Foundation<br>Licensed under the PSF License.<br>
<a href="https://docs.python.org/3.12/library/bdb.html" class="_attribution-link">https://docs.python.org/3.12/library/bdb.html</a>
</p>
</div>
|