blob: d201dc963b599506b26dc5bb9ba078c82f208eec [file] [log] [blame]
Christian Heimesd8654cf2007-12-02 15:22:16 +00001:mod:`bdb` --- Debugger framework
2=================================
3
4.. module:: bdb
5 :synopsis: Debugger framework.
6
Raymond Hettingera1993682011-01-27 01:20:32 +00007**Source code:** :source:`Lib/bdb.py`
8
9--------------
10
Christian Heimesd8654cf2007-12-02 15:22:16 +000011The :mod:`bdb` module handles basic debugger functions, like setting breakpoints
12or managing execution via the debugger.
13
14The following exception is defined:
15
16.. exception:: BdbQuit
17
18 Exception raised by the :class:`Bdb` class for quitting the debugger.
19
20
21The :mod:`bdb` module also defines two classes:
22
Miss Islington (bot)02c59be2022-09-02 10:48:26 -070023.. class:: Breakpoint(self, file, line, temporary=False, cond=None, funcname=None)
Christian Heimesd8654cf2007-12-02 15:22:16 +000024
25 This class implements temporary breakpoints, ignore counts, disabling and
26 (re-)enabling, and conditionals.
27
28 Breakpoints are indexed by number through a list called :attr:`bpbynumber`
Miss Islington (bot)02c59be2022-09-02 10:48:26 -070029 and by ``(file, line)`` pairs through :attr:`bplist`. The former points to
30 a single instance of class :class:`Breakpoint`. The latter points to a list
31 of such instances since there may be more than one breakpoint per line.
Christian Heimesd8654cf2007-12-02 15:22:16 +000032
Miss Islington (bot)02c59be2022-09-02 10:48:26 -070033 When creating a breakpoint, its associated :attr:`file name <file>` should
34 be in canonical form. If a :attr:`funcname` is defined, a breakpoint
35 :attr:`hit <hits>` will be counted when the first line of that function is
36 executed. A :attr:`conditional <cond>` breakpoint always counts a
37 :attr:`hit <hits>`.
Christian Heimesd8654cf2007-12-02 15:22:16 +000038
Benjamin Petersone41251e2008-04-25 01:59:09 +000039 :class:`Breakpoint` instances have the following methods:
Christian Heimesd8654cf2007-12-02 15:22:16 +000040
Benjamin Petersone41251e2008-04-25 01:59:09 +000041 .. method:: deleteMe()
Christian Heimesd8654cf2007-12-02 15:22:16 +000042
Benjamin Petersone41251e2008-04-25 01:59:09 +000043 Delete the breakpoint from the list associated to a file/line. If it is
44 the last breakpoint in that position, it also deletes the entry for the
45 file/line.
Christian Heimesd8654cf2007-12-02 15:22:16 +000046
Christian Heimesd8654cf2007-12-02 15:22:16 +000047
Benjamin Petersone41251e2008-04-25 01:59:09 +000048 .. method:: enable()
Christian Heimesd8654cf2007-12-02 15:22:16 +000049
Benjamin Petersone41251e2008-04-25 01:59:09 +000050 Mark the breakpoint as enabled.
Christian Heimesd8654cf2007-12-02 15:22:16 +000051
Christian Heimesd8654cf2007-12-02 15:22:16 +000052
Benjamin Petersone41251e2008-04-25 01:59:09 +000053 .. method:: disable()
Christian Heimesd8654cf2007-12-02 15:22:16 +000054
Benjamin Petersone41251e2008-04-25 01:59:09 +000055 Mark the breakpoint as disabled.
Christian Heimesd8654cf2007-12-02 15:22:16 +000056
Benjamin Petersone41251e2008-04-25 01:59:09 +000057
Georg Brandld2fd4ca2010-07-30 15:01:23 +000058 .. method:: bpformat()
Benjamin Petersone41251e2008-04-25 01:59:09 +000059
Georg Brandld2fd4ca2010-07-30 15:01:23 +000060 Return a string with all the information about the breakpoint, nicely
61 formatted:
Benjamin Petersone41251e2008-04-25 01:59:09 +000062
Miss Islington (bot)02c59be2022-09-02 10:48:26 -070063 * Breakpoint number.
64 * Temporary status (del or keep).
65 * File/line position.
66 * Break condition.
67 * Number of times to ignore.
68 * Number of times hit.
Christian Heimesd8654cf2007-12-02 15:22:16 +000069
Georg Brandld2fd4ca2010-07-30 15:01:23 +000070 .. versionadded:: 3.2
71
72 .. method:: bpprint(out=None)
73
74 Print the output of :meth:`bpformat` to the file *out*, or if it is
75 ``None``, to standard output.
76
Miss Islington (bot)02c59be2022-09-02 10:48:26 -070077 :class:`Breakpoint` instances have the following attributes:
78
79 .. attribute:: file
80
81 File name of the :class:`Breakpoint`.
82
83 .. attribute:: line
84
85 Line number of the :class:`Breakpoint` within :attr:`file`.
86
87 .. attribute:: temporary
88
89 True if a :class:`Breakpoint` at (file, line) is temporary.
90
91 .. attribute:: cond
92
93 Condition for evaluating a :class:`Breakpoint` at (file, line).
94
95 .. attribute:: funcname
96
97 Function name that defines whether a :class:`Breakpoint` is hit upon
98 entering the function.
99
100 .. attribute:: enabled
101
102 True if :class:`Breakpoint` is enabled.
103
104 .. attribute:: bpbynumber
105
106 Numeric index for a single instance of a :class:`Breakpoint`.
107
108 .. attribute:: bplist
109
110 Dictionary of :class:`Breakpoint` instances indexed by
111 (:attr:`file`, :attr:`line`) tuples.
112
113 .. attribute:: ignore
114
115 Number of times to ignore a :class:`Breakpoint`.
116
117 .. attribute:: hits
118
119 Count of the number of times a :class:`Breakpoint` has been hit.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000120
Benjamin Petersona0dfa822009-11-13 02:25:08 +0000121.. class:: Bdb(skip=None)
Christian Heimesd8654cf2007-12-02 15:22:16 +0000122
Benjamin Petersona0dfa822009-11-13 02:25:08 +0000123 The :class:`Bdb` class acts as a generic Python debugger base class.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000124
125 This class takes care of the details of the trace facility; a derived class
126 should implement user interaction. The standard debugger class
127 (:class:`pdb.Pdb`) is an example.
128
Benjamin Petersona0dfa822009-11-13 02:25:08 +0000129 The *skip* argument, if given, must be an iterable of glob-style
130 module name patterns. The debugger will not step into frames that
131 originate in a module that matches one of these patterns. Whether a
132 frame is considered to originate in a certain module is determined
133 by the ``__name__`` in the frame globals.
134
Ezio Melotti83fc6dd2010-01-27 22:44:03 +0000135 .. versionadded:: 3.1
Benjamin Petersona0dfa822009-11-13 02:25:08 +0000136 The *skip* argument.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000137
Benjamin Petersone41251e2008-04-25 01:59:09 +0000138 The following methods of :class:`Bdb` normally don't need to be overridden.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000139
Benjamin Petersone41251e2008-04-25 01:59:09 +0000140 .. method:: canonic(filename)
Christian Heimesd8654cf2007-12-02 15:22:16 +0000141
Miss Islington (bot)02c59be2022-09-02 10:48:26 -0700142 Return canonical form of *filename*.
143
144 For real file names, the canonical form is an operating-system-dependent,
145 :func:`case-normalized <os.path.normcase>` :func:`absolute path
C.A.M. Gerlachea19c282022-10-17 18:49:38 -0500146 <os.path.abspath>`. A *filename* with angle brackets, such as ``"<stdin>"``
Miss Islington (bot)02c59be2022-09-02 10:48:26 -0700147 generated in interactive mode, is returned unchanged.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000148
Benjamin Petersone41251e2008-04-25 01:59:09 +0000149 .. method:: reset()
Christian Heimesd8654cf2007-12-02 15:22:16 +0000150
Benjamin Petersone41251e2008-04-25 01:59:09 +0000151 Set the :attr:`botframe`, :attr:`stopframe`, :attr:`returnframe` and
152 :attr:`quitting` attributes with values ready to start debugging.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000153
Benjamin Petersone41251e2008-04-25 01:59:09 +0000154 .. method:: trace_dispatch(frame, event, arg)
Christian Heimesd8654cf2007-12-02 15:22:16 +0000155
Benjamin Petersone41251e2008-04-25 01:59:09 +0000156 This function is installed as the trace function of debugged frames. Its
157 return value is the new trace function (in most cases, that is, itself).
Christian Heimesd8654cf2007-12-02 15:22:16 +0000158
Benjamin Petersone41251e2008-04-25 01:59:09 +0000159 The default implementation decides how to dispatch a frame, depending on
160 the type of event (passed as a string) that is about to be executed.
161 *event* can be one of the following:
Christian Heimesd8654cf2007-12-02 15:22:16 +0000162
Benjamin Petersone41251e2008-04-25 01:59:09 +0000163 * ``"line"``: A new line of code is going to be executed.
164 * ``"call"``: A function is about to be called, or another code block
165 entered.
166 * ``"return"``: A function or other code block is about to return.
167 * ``"exception"``: An exception has occurred.
168 * ``"c_call"``: A C function is about to be called.
169 * ``"c_return"``: A C function has returned.
Georg Brandl7cb13192010-08-03 12:06:29 +0000170 * ``"c_exception"``: A C function has raised an exception.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000171
Benjamin Petersone41251e2008-04-25 01:59:09 +0000172 For the Python events, specialized functions (see below) are called. For
173 the C events, no action is taken.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000174
Benjamin Petersone41251e2008-04-25 01:59:09 +0000175 The *arg* parameter depends on the previous event.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000176
Benjamin Peterson4469d0c2008-11-30 22:46:23 +0000177 See the documentation for :func:`sys.settrace` for more information on the
178 trace function. For more information on code and frame objects, refer to
179 :ref:`types`.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000180
Benjamin Petersone41251e2008-04-25 01:59:09 +0000181 .. method:: dispatch_line(frame)
Christian Heimesd8654cf2007-12-02 15:22:16 +0000182
Benjamin Petersone41251e2008-04-25 01:59:09 +0000183 If the debugger should stop on the current line, invoke the
184 :meth:`user_line` method (which should be overridden in subclasses).
185 Raise a :exc:`BdbQuit` exception if the :attr:`Bdb.quitting` flag is set
186 (which can be set from :meth:`user_line`). Return a reference to the
187 :meth:`trace_dispatch` method for further tracing in that scope.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000188
Benjamin Petersone41251e2008-04-25 01:59:09 +0000189 .. method:: dispatch_call(frame, arg)
Christian Heimesd8654cf2007-12-02 15:22:16 +0000190
Benjamin Petersone41251e2008-04-25 01:59:09 +0000191 If the debugger should stop on this function call, invoke the
192 :meth:`user_call` method (which should be overridden in subclasses).
193 Raise a :exc:`BdbQuit` exception if the :attr:`Bdb.quitting` flag is set
194 (which can be set from :meth:`user_call`). Return a reference to the
195 :meth:`trace_dispatch` method for further tracing in that scope.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000196
Benjamin Petersone41251e2008-04-25 01:59:09 +0000197 .. method:: dispatch_return(frame, arg)
Christian Heimesd8654cf2007-12-02 15:22:16 +0000198
Benjamin Petersone41251e2008-04-25 01:59:09 +0000199 If the debugger should stop on this function return, invoke the
200 :meth:`user_return` method (which should be overridden in subclasses).
201 Raise a :exc:`BdbQuit` exception if the :attr:`Bdb.quitting` flag is set
202 (which can be set from :meth:`user_return`). Return a reference to the
203 :meth:`trace_dispatch` method for further tracing in that scope.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000204
Benjamin Petersone41251e2008-04-25 01:59:09 +0000205 .. method:: dispatch_exception(frame, arg)
Christian Heimesd8654cf2007-12-02 15:22:16 +0000206
Benjamin Petersone41251e2008-04-25 01:59:09 +0000207 If the debugger should stop at this exception, invokes the
208 :meth:`user_exception` method (which should be overridden in subclasses).
209 Raise a :exc:`BdbQuit` exception if the :attr:`Bdb.quitting` flag is set
210 (which can be set from :meth:`user_exception`). Return a reference to the
211 :meth:`trace_dispatch` method for further tracing in that scope.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000212
Benjamin Petersone41251e2008-04-25 01:59:09 +0000213 Normally derived classes don't override the following methods, but they may
214 if they want to redefine the definition of stopping and breakpoints.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000215
Miss Islington (bot)02c59be2022-09-02 10:48:26 -0700216 .. method:: is_skipped_line(module_name)
217
218 Return True if *module_name* matches any skip pattern.
219
Benjamin Petersone41251e2008-04-25 01:59:09 +0000220 .. method:: stop_here(frame)
Christian Heimesd8654cf2007-12-02 15:22:16 +0000221
Miss Islington (bot)02c59be2022-09-02 10:48:26 -0700222 Return True if *frame* is below the starting frame in the stack.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000223
Benjamin Petersone41251e2008-04-25 01:59:09 +0000224 .. method:: break_here(frame)
Christian Heimesd8654cf2007-12-02 15:22:16 +0000225
Miss Islington (bot)02c59be2022-09-02 10:48:26 -0700226 Return True if there is an effective breakpoint for this line.
227
228 Check whether a line or function breakpoint exists and is in effect. Delete temporary
229 breakpoints based on information from :func:`effective`.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000230
Benjamin Petersone41251e2008-04-25 01:59:09 +0000231 .. method:: break_anywhere(frame)
Christian Heimesd8654cf2007-12-02 15:22:16 +0000232
Miss Islington (bot)02c59be2022-09-02 10:48:26 -0700233 Return True if any breakpoint exists for *frame*'s filename.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000234
Benjamin Petersone41251e2008-04-25 01:59:09 +0000235 Derived classes should override these methods to gain control over debugger
236 operation.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000237
Benjamin Petersone41251e2008-04-25 01:59:09 +0000238 .. method:: user_call(frame, argument_list)
Christian Heimesd8654cf2007-12-02 15:22:16 +0000239
Miss Islington (bot)02c59be2022-09-02 10:48:26 -0700240 Called from :meth:`dispatch_call` if a break might stop inside the
241 called function.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000242
Benjamin Petersone41251e2008-04-25 01:59:09 +0000243 .. method:: user_line(frame)
Christian Heimesd8654cf2007-12-02 15:22:16 +0000244
Miss Islington (bot)02c59be2022-09-02 10:48:26 -0700245 Called from :meth:`dispatch_line` when either :meth:`stop_here` or
246 :meth:`break_here` returns ``True``.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000247
Benjamin Petersone41251e2008-04-25 01:59:09 +0000248 .. method:: user_return(frame, return_value)
Christian Heimesd8654cf2007-12-02 15:22:16 +0000249
Miss Islington (bot)02c59be2022-09-02 10:48:26 -0700250 Called from :meth:`dispatch_return` when :meth:`stop_here` returns ``True``.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000251
Benjamin Petersone41251e2008-04-25 01:59:09 +0000252 .. method:: user_exception(frame, exc_info)
Christian Heimesd8654cf2007-12-02 15:22:16 +0000253
Miss Islington (bot)02c59be2022-09-02 10:48:26 -0700254 Called from :meth:`dispatch_exception` when :meth:`stop_here`
255 returns ``True``.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000256
Benjamin Petersone41251e2008-04-25 01:59:09 +0000257 .. method:: do_clear(arg)
Christian Heimesd8654cf2007-12-02 15:22:16 +0000258
Benjamin Petersone41251e2008-04-25 01:59:09 +0000259 Handle how a breakpoint must be removed when it is a temporary one.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000260
Benjamin Petersone41251e2008-04-25 01:59:09 +0000261 This method must be implemented by derived classes.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000262
263
Benjamin Petersone41251e2008-04-25 01:59:09 +0000264 Derived classes and clients can call the following methods to affect the
265 stepping state.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000266
Benjamin Petersone41251e2008-04-25 01:59:09 +0000267 .. method:: set_step()
Christian Heimesd8654cf2007-12-02 15:22:16 +0000268
Benjamin Petersone41251e2008-04-25 01:59:09 +0000269 Stop after one line of code.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000270
Benjamin Petersone41251e2008-04-25 01:59:09 +0000271 .. method:: set_next(frame)
Christian Heimesd8654cf2007-12-02 15:22:16 +0000272
Benjamin Petersone41251e2008-04-25 01:59:09 +0000273 Stop on the next line in or below the given frame.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000274
Benjamin Petersone41251e2008-04-25 01:59:09 +0000275 .. method:: set_return(frame)
Christian Heimesd8654cf2007-12-02 15:22:16 +0000276
Benjamin Petersone41251e2008-04-25 01:59:09 +0000277 Stop when returning from the given frame.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000278
Miss Islington (bot)02c59be2022-09-02 10:48:26 -0700279 .. method:: set_until(frame, lineno=None)
Alexandre Vassalotti5f8ced22008-05-16 00:03:33 +0000280
Miss Islington (bot)02c59be2022-09-02 10:48:26 -0700281 Stop when the line with the *lineno* greater than the current one is
Martin Panterd21e0b52015-10-10 10:36:22 +0000282 reached or when returning from current frame.
Alexandre Vassalotti5f8ced22008-05-16 00:03:33 +0000283
Benjamin Petersone41251e2008-04-25 01:59:09 +0000284 .. method:: set_trace([frame])
Christian Heimesd8654cf2007-12-02 15:22:16 +0000285
Benjamin Petersone41251e2008-04-25 01:59:09 +0000286 Start debugging from *frame*. If *frame* is not specified, debugging
287 starts from caller's frame.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000288
Benjamin Petersone41251e2008-04-25 01:59:09 +0000289 .. method:: set_continue()
Christian Heimesd8654cf2007-12-02 15:22:16 +0000290
Benjamin Petersone41251e2008-04-25 01:59:09 +0000291 Stop only at breakpoints or when finished. If there are no breakpoints,
Serhiy Storchakaecf41da2016-10-19 16:29:26 +0300292 set the system trace function to ``None``.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000293
Benjamin Petersone41251e2008-04-25 01:59:09 +0000294 .. method:: set_quit()
Christian Heimesd8654cf2007-12-02 15:22:16 +0000295
Serhiy Storchakafbc1c262013-11-29 12:17:13 +0200296 Set the :attr:`quitting` attribute to ``True``. This raises :exc:`BdbQuit` in
Benjamin Petersone41251e2008-04-25 01:59:09 +0000297 the next call to one of the :meth:`dispatch_\*` methods.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000298
299
Benjamin Petersone41251e2008-04-25 01:59:09 +0000300 Derived classes and clients can call the following methods to manipulate
301 breakpoints. These methods return a string containing an error message if
302 something went wrong, or ``None`` if all is well.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000303
Miss Islington (bot)02c59be2022-09-02 10:48:26 -0700304 .. method:: set_break(filename, lineno, temporary=False, cond=None, funcname=None)
Christian Heimesd8654cf2007-12-02 15:22:16 +0000305
Benjamin Petersone41251e2008-04-25 01:59:09 +0000306 Set a new breakpoint. If the *lineno* line doesn't exist for the
307 *filename* passed as argument, return an error message. The *filename*
308 should be in canonical form, as described in the :meth:`canonic` method.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000309
Benjamin Petersone41251e2008-04-25 01:59:09 +0000310 .. method:: clear_break(filename, lineno)
Christian Heimesd8654cf2007-12-02 15:22:16 +0000311
Miss Islington (bot)02c59be2022-09-02 10:48:26 -0700312 Delete the breakpoints in *filename* and *lineno*. If none were set,
313 return an error message.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000314
Benjamin Petersone41251e2008-04-25 01:59:09 +0000315 .. method:: clear_bpbynumber(arg)
Christian Heimesd8654cf2007-12-02 15:22:16 +0000316
Benjamin Petersone41251e2008-04-25 01:59:09 +0000317 Delete the breakpoint which has the index *arg* in the
318 :attr:`Breakpoint.bpbynumber`. If *arg* is not numeric or out of range,
319 return an error message.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000320
Benjamin Petersone41251e2008-04-25 01:59:09 +0000321 .. method:: clear_all_file_breaks(filename)
Christian Heimesd8654cf2007-12-02 15:22:16 +0000322
Miss Islington (bot)02c59be2022-09-02 10:48:26 -0700323 Delete all breakpoints in *filename*. If none were set, return an error
324 message.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000325
Benjamin Petersone41251e2008-04-25 01:59:09 +0000326 .. method:: clear_all_breaks()
Christian Heimesd8654cf2007-12-02 15:22:16 +0000327
Miss Islington (bot)02c59be2022-09-02 10:48:26 -0700328 Delete all existing breakpoints. If none were set, return an error
329 message.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000330
Georg Brandl7410dd12010-07-30 12:01:20 +0000331 .. method:: get_bpbynumber(arg)
332
333 Return a breakpoint specified by the given number. If *arg* is a string,
334 it will be converted to a number. If *arg* is a non-numeric string, if
335 the given breakpoint never existed or has been deleted, a
336 :exc:`ValueError` is raised.
337
338 .. versionadded:: 3.2
339
Benjamin Petersone41251e2008-04-25 01:59:09 +0000340 .. method:: get_break(filename, lineno)
Christian Heimesd8654cf2007-12-02 15:22:16 +0000341
Miss Islington (bot)02c59be2022-09-02 10:48:26 -0700342 Return True if there is a breakpoint for *lineno* in *filename*.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000343
Benjamin Petersone41251e2008-04-25 01:59:09 +0000344 .. method:: get_breaks(filename, lineno)
Christian Heimesd8654cf2007-12-02 15:22:16 +0000345
Benjamin Petersone41251e2008-04-25 01:59:09 +0000346 Return all breakpoints for *lineno* in *filename*, or an empty list if
347 none are set.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000348
Benjamin Petersone41251e2008-04-25 01:59:09 +0000349 .. method:: get_file_breaks(filename)
Christian Heimesd8654cf2007-12-02 15:22:16 +0000350
Benjamin Petersone41251e2008-04-25 01:59:09 +0000351 Return all breakpoints in *filename*, or an empty list if none are set.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000352
Benjamin Petersone41251e2008-04-25 01:59:09 +0000353 .. method:: get_all_breaks()
Christian Heimesd8654cf2007-12-02 15:22:16 +0000354
Benjamin Petersone41251e2008-04-25 01:59:09 +0000355 Return all breakpoints that are set.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000356
357
Benjamin Petersone41251e2008-04-25 01:59:09 +0000358 Derived classes and clients can call the following methods to get a data
359 structure representing a stack trace.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000360
Benjamin Petersone41251e2008-04-25 01:59:09 +0000361 .. method:: get_stack(f, t)
Christian Heimesd8654cf2007-12-02 15:22:16 +0000362
Miss Islington (bot)02c59be2022-09-02 10:48:26 -0700363 Return a list of (frame, lineno) tuples in a stack trace, and a size.
364
365 The most recently called frame is last in the list. The size is the number
366 of frames below the frame where the debugger was invoked.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000367
Georg Brandlb868a662009-04-02 02:56:10 +0000368 .. method:: format_stack_entry(frame_lineno, lprefix=': ')
Christian Heimesd8654cf2007-12-02 15:22:16 +0000369
Miss Islington (bot)02c59be2022-09-02 10:48:26 -0700370 Return a string with information about a stack entry, which is a
371 ``(frame, lineno)`` tuple. The return string contains:
Christian Heimesd8654cf2007-12-02 15:22:16 +0000372
Miss Islington (bot)02c59be2022-09-02 10:48:26 -0700373 * The canonical filename which contains the frame.
374 * The function name or ``"<lambda>"``.
Benjamin Petersone41251e2008-04-25 01:59:09 +0000375 * The input arguments.
376 * The return value.
377 * The line of code (if it exists).
Christian Heimesd8654cf2007-12-02 15:22:16 +0000378
379
Benjamin Petersone41251e2008-04-25 01:59:09 +0000380 The following two methods can be called by clients to use a debugger to debug
381 a :term:`statement`, given as a string.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000382
Georg Brandlb868a662009-04-02 02:56:10 +0000383 .. method:: run(cmd, globals=None, locals=None)
Christian Heimesd8654cf2007-12-02 15:22:16 +0000384
Benjamin Petersone41251e2008-04-25 01:59:09 +0000385 Debug a statement executed via the :func:`exec` function. *globals*
386 defaults to :attr:`__main__.__dict__`, *locals* defaults to *globals*.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000387
Georg Brandlb868a662009-04-02 02:56:10 +0000388 .. method:: runeval(expr, globals=None, locals=None)
Christian Heimesd8654cf2007-12-02 15:22:16 +0000389
Benjamin Petersone41251e2008-04-25 01:59:09 +0000390 Debug an expression executed via the :func:`eval` function. *globals* and
391 *locals* have the same meaning as in :meth:`run`.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000392
Benjamin Petersone41251e2008-04-25 01:59:09 +0000393 .. method:: runctx(cmd, globals, locals)
Christian Heimesd8654cf2007-12-02 15:22:16 +0000394
Benjamin Petersone41251e2008-04-25 01:59:09 +0000395 For backwards compatibility. Calls the :meth:`run` method.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000396
Serhiy Storchaka142566c2019-06-05 18:22:31 +0300397 .. method:: runcall(func, /, *args, **kwds)
Christian Heimesd8654cf2007-12-02 15:22:16 +0000398
Benjamin Petersone41251e2008-04-25 01:59:09 +0000399 Debug a single function call, and return its result.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000400
401
402Finally, the module defines the following functions:
403
404.. function:: checkfuncname(b, frame)
405
Miss Islington (bot)02c59be2022-09-02 10:48:26 -0700406 Return True if we should break here, depending on the way the
407 :class:`Breakpoint` *b* was set.
Georg Brandl48310cd2009-01-03 21:18:54 +0000408
Miss Islington (bot)02c59be2022-09-02 10:48:26 -0700409 If it was set via line number, it checks if
410 :attr:`b.line <bdb.Breakpoint.line>` is the same as the one in *frame*.
411 If the breakpoint was set via
412 :attr:`function name <bdb.Breakpoint.funcname>`, we have to check we are in
413 the right *frame* (the right function) and if we are on its first executable
414 line.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000415
416.. function:: effective(file, line, frame)
417
Miss Islington (bot)02c59be2022-09-02 10:48:26 -0700418 Return ``(active breakpoint, delete temporary flag)`` or ``(None, None)`` as the
419 breakpoint to act upon.
420
421 The *active breakpoint* is the first entry in
422 :attr:`bplist <bdb.Breakpoint.bplist>` for the
423 (:attr:`file <bdb.Breakpoint.file>`, :attr:`line <bdb.Breakpoint.line>`)
424 (which must exist) that is :attr:`enabled <bdb.Breakpoint.enabled>`, for
425 which :func:`checkfuncname` is True, and that has neither a False
426 :attr:`condition <bdb.Breakpoint.cond>` nor positive
427 :attr:`ignore <bdb.Breakpoint.ignore>` count. The *flag*, meaning that a
428 temporary breakpoint should be deleted, is False only when the
429 :attr:`cond <bdb.Breakpoint.cond>` cannot be evaluated (in which case,
430 :attr:`ignore <bdb.Breakpoint.ignore>` count is ignored).
431
432 If no such entry exists, then (None, None) is returned.
433
Christian Heimesd8654cf2007-12-02 15:22:16 +0000434
435.. function:: set_trace()
436
Georg Brandlf51a6c72010-11-26 12:05:48 +0000437 Start debugging with a :class:`Bdb` instance from caller's frame.