blob: 116ffcf88e3b69dee35d4e6ba77bc3dbf8fb16cd [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
Georg Brandlb868a662009-04-02 02:56:10 +000023.. class:: Breakpoint(self, file, line, temporary=0, 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`
29 and by ``(file, line)`` pairs through :attr:`bplist`. The former points to a
30 single instance of class :class:`Breakpoint`. The latter points to a list of
31 such instances since there may be more than one breakpoint per line.
32
33 When creating a breakpoint, its associated filename should be in canonical
34 form. If a *funcname* is defined, a breakpoint hit will be counted when the
35 first line of that function is executed. A conditional breakpoint always
36 counts a hit.
37
Benjamin Petersone41251e2008-04-25 01:59:09 +000038 :class:`Breakpoint` instances have the following methods:
Christian Heimesd8654cf2007-12-02 15:22:16 +000039
Benjamin Petersone41251e2008-04-25 01:59:09 +000040 .. method:: deleteMe()
Christian Heimesd8654cf2007-12-02 15:22:16 +000041
Benjamin Petersone41251e2008-04-25 01:59:09 +000042 Delete the breakpoint from the list associated to a file/line. If it is
43 the last breakpoint in that position, it also deletes the entry for the
44 file/line.
Christian Heimesd8654cf2007-12-02 15:22:16 +000045
Christian Heimesd8654cf2007-12-02 15:22:16 +000046
Benjamin Petersone41251e2008-04-25 01:59:09 +000047 .. method:: enable()
Christian Heimesd8654cf2007-12-02 15:22:16 +000048
Benjamin Petersone41251e2008-04-25 01:59:09 +000049 Mark the breakpoint as enabled.
Christian Heimesd8654cf2007-12-02 15:22:16 +000050
Christian Heimesd8654cf2007-12-02 15:22:16 +000051
Benjamin Petersone41251e2008-04-25 01:59:09 +000052 .. method:: disable()
Christian Heimesd8654cf2007-12-02 15:22:16 +000053
Benjamin Petersone41251e2008-04-25 01:59:09 +000054 Mark the breakpoint as disabled.
Christian Heimesd8654cf2007-12-02 15:22:16 +000055
Benjamin Petersone41251e2008-04-25 01:59:09 +000056
Georg Brandld2fd4ca2010-07-30 15:01:23 +000057 .. method:: bpformat()
Benjamin Petersone41251e2008-04-25 01:59:09 +000058
Georg Brandld2fd4ca2010-07-30 15:01:23 +000059 Return a string with all the information about the breakpoint, nicely
60 formatted:
Benjamin Petersone41251e2008-04-25 01:59:09 +000061
62 * The breakpoint number.
63 * If it is temporary or not.
64 * Its file,line position.
65 * The condition that causes a break.
66 * If it must be ignored the next N times.
67 * The breakpoint hit count.
Christian Heimesd8654cf2007-12-02 15:22:16 +000068
Georg Brandld2fd4ca2010-07-30 15:01:23 +000069 .. versionadded:: 3.2
70
71 .. method:: bpprint(out=None)
72
73 Print the output of :meth:`bpformat` to the file *out*, or if it is
74 ``None``, to standard output.
75
Christian Heimesd8654cf2007-12-02 15:22:16 +000076
Benjamin Petersona0dfa822009-11-13 02:25:08 +000077.. class:: Bdb(skip=None)
Christian Heimesd8654cf2007-12-02 15:22:16 +000078
Benjamin Petersona0dfa822009-11-13 02:25:08 +000079 The :class:`Bdb` class acts as a generic Python debugger base class.
Christian Heimesd8654cf2007-12-02 15:22:16 +000080
81 This class takes care of the details of the trace facility; a derived class
82 should implement user interaction. The standard debugger class
83 (:class:`pdb.Pdb`) is an example.
84
Benjamin Petersona0dfa822009-11-13 02:25:08 +000085 The *skip* argument, if given, must be an iterable of glob-style
86 module name patterns. The debugger will not step into frames that
87 originate in a module that matches one of these patterns. Whether a
88 frame is considered to originate in a certain module is determined
89 by the ``__name__`` in the frame globals.
90
Ezio Melotti83fc6dd2010-01-27 22:44:03 +000091 .. versionadded:: 3.1
Benjamin Petersona0dfa822009-11-13 02:25:08 +000092 The *skip* argument.
Christian Heimesd8654cf2007-12-02 15:22:16 +000093
Benjamin Petersone41251e2008-04-25 01:59:09 +000094 The following methods of :class:`Bdb` normally don't need to be overridden.
Christian Heimesd8654cf2007-12-02 15:22:16 +000095
Benjamin Petersone41251e2008-04-25 01:59:09 +000096 .. method:: canonic(filename)
Christian Heimesd8654cf2007-12-02 15:22:16 +000097
Benjamin Petersone41251e2008-04-25 01:59:09 +000098 Auxiliary method for getting a filename in a canonical form, that is, as a
99 case-normalized (on case-insensitive filesystems) absolute path, stripped
100 of surrounding angle brackets.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000101
Benjamin Petersone41251e2008-04-25 01:59:09 +0000102 .. method:: reset()
Christian Heimesd8654cf2007-12-02 15:22:16 +0000103
Benjamin Petersone41251e2008-04-25 01:59:09 +0000104 Set the :attr:`botframe`, :attr:`stopframe`, :attr:`returnframe` and
105 :attr:`quitting` attributes with values ready to start debugging.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000106
Benjamin Petersone41251e2008-04-25 01:59:09 +0000107 .. method:: trace_dispatch(frame, event, arg)
Christian Heimesd8654cf2007-12-02 15:22:16 +0000108
Benjamin Petersone41251e2008-04-25 01:59:09 +0000109 This function is installed as the trace function of debugged frames. Its
110 return value is the new trace function (in most cases, that is, itself).
Christian Heimesd8654cf2007-12-02 15:22:16 +0000111
Benjamin Petersone41251e2008-04-25 01:59:09 +0000112 The default implementation decides how to dispatch a frame, depending on
113 the type of event (passed as a string) that is about to be executed.
114 *event* can be one of the following:
Christian Heimesd8654cf2007-12-02 15:22:16 +0000115
Benjamin Petersone41251e2008-04-25 01:59:09 +0000116 * ``"line"``: A new line of code is going to be executed.
117 * ``"call"``: A function is about to be called, or another code block
118 entered.
119 * ``"return"``: A function or other code block is about to return.
120 * ``"exception"``: An exception has occurred.
121 * ``"c_call"``: A C function is about to be called.
122 * ``"c_return"``: A C function has returned.
Georg Brandl7cb13192010-08-03 12:06:29 +0000123 * ``"c_exception"``: A C function has raised an exception.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000124
Benjamin Petersone41251e2008-04-25 01:59:09 +0000125 For the Python events, specialized functions (see below) are called. For
126 the C events, no action is taken.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000127
Benjamin Petersone41251e2008-04-25 01:59:09 +0000128 The *arg* parameter depends on the previous event.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000129
Benjamin Peterson4469d0c2008-11-30 22:46:23 +0000130 See the documentation for :func:`sys.settrace` for more information on the
131 trace function. For more information on code and frame objects, refer to
132 :ref:`types`.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000133
Benjamin Petersone41251e2008-04-25 01:59:09 +0000134 .. method:: dispatch_line(frame)
Christian Heimesd8654cf2007-12-02 15:22:16 +0000135
Benjamin Petersone41251e2008-04-25 01:59:09 +0000136 If the debugger should stop on the current line, invoke the
137 :meth:`user_line` method (which should be overridden in subclasses).
138 Raise a :exc:`BdbQuit` exception if the :attr:`Bdb.quitting` flag is set
139 (which can be set from :meth:`user_line`). Return a reference to the
140 :meth:`trace_dispatch` method for further tracing in that scope.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000141
Benjamin Petersone41251e2008-04-25 01:59:09 +0000142 .. method:: dispatch_call(frame, arg)
Christian Heimesd8654cf2007-12-02 15:22:16 +0000143
Benjamin Petersone41251e2008-04-25 01:59:09 +0000144 If the debugger should stop on this function call, invoke the
145 :meth:`user_call` method (which should be overridden in subclasses).
146 Raise a :exc:`BdbQuit` exception if the :attr:`Bdb.quitting` flag is set
147 (which can be set from :meth:`user_call`). Return a reference to the
148 :meth:`trace_dispatch` method for further tracing in that scope.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000149
Benjamin Petersone41251e2008-04-25 01:59:09 +0000150 .. method:: dispatch_return(frame, arg)
Christian Heimesd8654cf2007-12-02 15:22:16 +0000151
Benjamin Petersone41251e2008-04-25 01:59:09 +0000152 If the debugger should stop on this function return, invoke the
153 :meth:`user_return` method (which should be overridden in subclasses).
154 Raise a :exc:`BdbQuit` exception if the :attr:`Bdb.quitting` flag is set
155 (which can be set from :meth:`user_return`). Return a reference to the
156 :meth:`trace_dispatch` method for further tracing in that scope.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000157
Benjamin Petersone41251e2008-04-25 01:59:09 +0000158 .. method:: dispatch_exception(frame, arg)
Christian Heimesd8654cf2007-12-02 15:22:16 +0000159
Benjamin Petersone41251e2008-04-25 01:59:09 +0000160 If the debugger should stop at this exception, invokes the
161 :meth:`user_exception` method (which should be overridden in subclasses).
162 Raise a :exc:`BdbQuit` exception if the :attr:`Bdb.quitting` flag is set
163 (which can be set from :meth:`user_exception`). Return a reference to the
164 :meth:`trace_dispatch` method for further tracing in that scope.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000165
Benjamin Petersone41251e2008-04-25 01:59:09 +0000166 Normally derived classes don't override the following methods, but they may
167 if they want to redefine the definition of stopping and breakpoints.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000168
Benjamin Petersone41251e2008-04-25 01:59:09 +0000169 .. method:: stop_here(frame)
Christian Heimesd8654cf2007-12-02 15:22:16 +0000170
Benjamin Petersone41251e2008-04-25 01:59:09 +0000171 This method checks if the *frame* is somewhere below :attr:`botframe` in
172 the call stack. :attr:`botframe` is the frame in which debugging started.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000173
Benjamin Petersone41251e2008-04-25 01:59:09 +0000174 .. method:: break_here(frame)
Christian Heimesd8654cf2007-12-02 15:22:16 +0000175
Benjamin Petersone41251e2008-04-25 01:59:09 +0000176 This method checks if there is a breakpoint in the filename and line
177 belonging to *frame* or, at least, in the current function. If the
178 breakpoint is a temporary one, this method deletes it.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000179
Benjamin Petersone41251e2008-04-25 01:59:09 +0000180 .. method:: break_anywhere(frame)
Christian Heimesd8654cf2007-12-02 15:22:16 +0000181
Benjamin Petersone41251e2008-04-25 01:59:09 +0000182 This method checks if there is a breakpoint in the filename of the current
183 frame.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000184
Benjamin Petersone41251e2008-04-25 01:59:09 +0000185 Derived classes should override these methods to gain control over debugger
186 operation.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000187
Benjamin Petersone41251e2008-04-25 01:59:09 +0000188 .. method:: user_call(frame, argument_list)
Christian Heimesd8654cf2007-12-02 15:22:16 +0000189
Benjamin Petersone41251e2008-04-25 01:59:09 +0000190 This method is called from :meth:`dispatch_call` when there is the
191 possibility that a break might be necessary anywhere inside the called
192 function.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000193
Benjamin Petersone41251e2008-04-25 01:59:09 +0000194 .. method:: user_line(frame)
Christian Heimesd8654cf2007-12-02 15:22:16 +0000195
Benjamin Petersone41251e2008-04-25 01:59:09 +0000196 This method is called from :meth:`dispatch_line` when either
Serhiy Storchakafbc1c262013-11-29 12:17:13 +0200197 :meth:`stop_here` or :meth:`break_here` yields ``True``.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000198
Benjamin Petersone41251e2008-04-25 01:59:09 +0000199 .. method:: user_return(frame, return_value)
Christian Heimesd8654cf2007-12-02 15:22:16 +0000200
Benjamin Petersone41251e2008-04-25 01:59:09 +0000201 This method is called from :meth:`dispatch_return` when :meth:`stop_here`
Serhiy Storchakafbc1c262013-11-29 12:17:13 +0200202 yields ``True``.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000203
Benjamin Petersone41251e2008-04-25 01:59:09 +0000204 .. method:: user_exception(frame, exc_info)
Christian Heimesd8654cf2007-12-02 15:22:16 +0000205
Benjamin Petersone41251e2008-04-25 01:59:09 +0000206 This method is called from :meth:`dispatch_exception` when
Serhiy Storchakafbc1c262013-11-29 12:17:13 +0200207 :meth:`stop_here` yields ``True``.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000208
Benjamin Petersone41251e2008-04-25 01:59:09 +0000209 .. method:: do_clear(arg)
Christian Heimesd8654cf2007-12-02 15:22:16 +0000210
Benjamin Petersone41251e2008-04-25 01:59:09 +0000211 Handle how a breakpoint must be removed when it is a temporary one.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000212
Benjamin Petersone41251e2008-04-25 01:59:09 +0000213 This method must be implemented by derived classes.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000214
215
Benjamin Petersone41251e2008-04-25 01:59:09 +0000216 Derived classes and clients can call the following methods to affect the
217 stepping state.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000218
Benjamin Petersone41251e2008-04-25 01:59:09 +0000219 .. method:: set_step()
Christian Heimesd8654cf2007-12-02 15:22:16 +0000220
Benjamin Petersone41251e2008-04-25 01:59:09 +0000221 Stop after one line of code.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000222
Benjamin Petersone41251e2008-04-25 01:59:09 +0000223 .. method:: set_next(frame)
Christian Heimesd8654cf2007-12-02 15:22:16 +0000224
Benjamin Petersone41251e2008-04-25 01:59:09 +0000225 Stop on the next line in or below the given frame.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000226
Benjamin Petersone41251e2008-04-25 01:59:09 +0000227 .. method:: set_return(frame)
Christian Heimesd8654cf2007-12-02 15:22:16 +0000228
Benjamin Petersone41251e2008-04-25 01:59:09 +0000229 Stop when returning from the given frame.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000230
Alexandre Vassalotti5f8ced22008-05-16 00:03:33 +0000231 .. method:: set_until(frame)
232
233 Stop when the line with the line no greater than the current one is
Martin Panterd21e0b52015-10-10 10:36:22 +0000234 reached or when returning from current frame.
Alexandre Vassalotti5f8ced22008-05-16 00:03:33 +0000235
Benjamin Petersone41251e2008-04-25 01:59:09 +0000236 .. method:: set_trace([frame])
Christian Heimesd8654cf2007-12-02 15:22:16 +0000237
Benjamin Petersone41251e2008-04-25 01:59:09 +0000238 Start debugging from *frame*. If *frame* is not specified, debugging
239 starts from caller's frame.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000240
Benjamin Petersone41251e2008-04-25 01:59:09 +0000241 .. method:: set_continue()
Christian Heimesd8654cf2007-12-02 15:22:16 +0000242
Benjamin Petersone41251e2008-04-25 01:59:09 +0000243 Stop only at breakpoints or when finished. If there are no breakpoints,
Serhiy Storchakaecf41da2016-10-19 16:29:26 +0300244 set the system trace function to ``None``.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000245
Benjamin Petersone41251e2008-04-25 01:59:09 +0000246 .. method:: set_quit()
Christian Heimesd8654cf2007-12-02 15:22:16 +0000247
Serhiy Storchakafbc1c262013-11-29 12:17:13 +0200248 Set the :attr:`quitting` attribute to ``True``. This raises :exc:`BdbQuit` in
Benjamin Petersone41251e2008-04-25 01:59:09 +0000249 the next call to one of the :meth:`dispatch_\*` methods.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000250
251
Benjamin Petersone41251e2008-04-25 01:59:09 +0000252 Derived classes and clients can call the following methods to manipulate
253 breakpoints. These methods return a string containing an error message if
254 something went wrong, or ``None`` if all is well.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000255
Georg Brandlb868a662009-04-02 02:56:10 +0000256 .. method:: set_break(filename, lineno, temporary=0, cond, funcname)
Christian Heimesd8654cf2007-12-02 15:22:16 +0000257
Benjamin Petersone41251e2008-04-25 01:59:09 +0000258 Set a new breakpoint. If the *lineno* line doesn't exist for the
259 *filename* passed as argument, return an error message. The *filename*
260 should be in canonical form, as described in the :meth:`canonic` method.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000261
Benjamin Petersone41251e2008-04-25 01:59:09 +0000262 .. method:: clear_break(filename, lineno)
Christian Heimesd8654cf2007-12-02 15:22:16 +0000263
Benjamin Petersone41251e2008-04-25 01:59:09 +0000264 Delete the breakpoints in *filename* and *lineno*. If none were set, an
265 error message is returned.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000266
Benjamin Petersone41251e2008-04-25 01:59:09 +0000267 .. method:: clear_bpbynumber(arg)
Christian Heimesd8654cf2007-12-02 15:22:16 +0000268
Benjamin Petersone41251e2008-04-25 01:59:09 +0000269 Delete the breakpoint which has the index *arg* in the
270 :attr:`Breakpoint.bpbynumber`. If *arg* is not numeric or out of range,
271 return an error message.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000272
Benjamin Petersone41251e2008-04-25 01:59:09 +0000273 .. method:: clear_all_file_breaks(filename)
Christian Heimesd8654cf2007-12-02 15:22:16 +0000274
Benjamin Petersone41251e2008-04-25 01:59:09 +0000275 Delete all breakpoints in *filename*. If none were set, an error message
276 is returned.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000277
Benjamin Petersone41251e2008-04-25 01:59:09 +0000278 .. method:: clear_all_breaks()
Christian Heimesd8654cf2007-12-02 15:22:16 +0000279
Benjamin Petersone41251e2008-04-25 01:59:09 +0000280 Delete all existing breakpoints.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000281
Georg Brandl7410dd12010-07-30 12:01:20 +0000282 .. method:: get_bpbynumber(arg)
283
284 Return a breakpoint specified by the given number. If *arg* is a string,
285 it will be converted to a number. If *arg* is a non-numeric string, if
286 the given breakpoint never existed or has been deleted, a
287 :exc:`ValueError` is raised.
288
289 .. versionadded:: 3.2
290
Benjamin Petersone41251e2008-04-25 01:59:09 +0000291 .. method:: get_break(filename, lineno)
Christian Heimesd8654cf2007-12-02 15:22:16 +0000292
Benjamin Petersone41251e2008-04-25 01:59:09 +0000293 Check if there is a breakpoint for *lineno* of *filename*.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000294
Benjamin Petersone41251e2008-04-25 01:59:09 +0000295 .. method:: get_breaks(filename, lineno)
Christian Heimesd8654cf2007-12-02 15:22:16 +0000296
Benjamin Petersone41251e2008-04-25 01:59:09 +0000297 Return all breakpoints for *lineno* in *filename*, or an empty list if
298 none are set.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000299
Benjamin Petersone41251e2008-04-25 01:59:09 +0000300 .. method:: get_file_breaks(filename)
Christian Heimesd8654cf2007-12-02 15:22:16 +0000301
Benjamin Petersone41251e2008-04-25 01:59:09 +0000302 Return all breakpoints in *filename*, or an empty list if none are set.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000303
Benjamin Petersone41251e2008-04-25 01:59:09 +0000304 .. method:: get_all_breaks()
Christian Heimesd8654cf2007-12-02 15:22:16 +0000305
Benjamin Petersone41251e2008-04-25 01:59:09 +0000306 Return all breakpoints that are set.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000307
308
Benjamin Petersone41251e2008-04-25 01:59:09 +0000309 Derived classes and clients can call the following methods to get a data
310 structure representing a stack trace.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000311
Benjamin Petersone41251e2008-04-25 01:59:09 +0000312 .. method:: get_stack(f, t)
Christian Heimesd8654cf2007-12-02 15:22:16 +0000313
Benjamin Petersone41251e2008-04-25 01:59:09 +0000314 Get a list of records for a frame and all higher (calling) and lower
315 frames, and the size of the higher part.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000316
Georg Brandlb868a662009-04-02 02:56:10 +0000317 .. method:: format_stack_entry(frame_lineno, lprefix=': ')
Christian Heimesd8654cf2007-12-02 15:22:16 +0000318
Benjamin Petersone41251e2008-04-25 01:59:09 +0000319 Return a string with information about a stack entry, identified by a
320 ``(frame, lineno)`` tuple:
Christian Heimesd8654cf2007-12-02 15:22:16 +0000321
Benjamin Petersone41251e2008-04-25 01:59:09 +0000322 * The canonical form of the filename which contains the frame.
323 * The function name, or ``"<lambda>"``.
324 * The input arguments.
325 * The return value.
326 * The line of code (if it exists).
Christian Heimesd8654cf2007-12-02 15:22:16 +0000327
328
Benjamin Petersone41251e2008-04-25 01:59:09 +0000329 The following two methods can be called by clients to use a debugger to debug
330 a :term:`statement`, given as a string.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000331
Georg Brandlb868a662009-04-02 02:56:10 +0000332 .. method:: run(cmd, globals=None, locals=None)
Christian Heimesd8654cf2007-12-02 15:22:16 +0000333
Benjamin Petersone41251e2008-04-25 01:59:09 +0000334 Debug a statement executed via the :func:`exec` function. *globals*
335 defaults to :attr:`__main__.__dict__`, *locals* defaults to *globals*.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000336
Georg Brandlb868a662009-04-02 02:56:10 +0000337 .. method:: runeval(expr, globals=None, locals=None)
Christian Heimesd8654cf2007-12-02 15:22:16 +0000338
Benjamin Petersone41251e2008-04-25 01:59:09 +0000339 Debug an expression executed via the :func:`eval` function. *globals* and
340 *locals* have the same meaning as in :meth:`run`.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000341
Benjamin Petersone41251e2008-04-25 01:59:09 +0000342 .. method:: runctx(cmd, globals, locals)
Christian Heimesd8654cf2007-12-02 15:22:16 +0000343
Benjamin Petersone41251e2008-04-25 01:59:09 +0000344 For backwards compatibility. Calls the :meth:`run` method.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000345
Benjamin Petersone41251e2008-04-25 01:59:09 +0000346 .. method:: runcall(func, *args, **kwds)
Christian Heimesd8654cf2007-12-02 15:22:16 +0000347
Benjamin Petersone41251e2008-04-25 01:59:09 +0000348 Debug a single function call, and return its result.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000349
350
351Finally, the module defines the following functions:
352
353.. function:: checkfuncname(b, frame)
354
355 Check whether we should break here, depending on the way the breakpoint *b*
356 was set.
Georg Brandl48310cd2009-01-03 21:18:54 +0000357
Christian Heimesd8654cf2007-12-02 15:22:16 +0000358 If it was set via line number, it checks if ``b.line`` is the same as the one
359 in the frame also passed as argument. If the breakpoint was set via function
360 name, we have to check we are in the right frame (the right function) and if
361 we are in its first executable line.
362
363.. function:: effective(file, line, frame)
364
365 Determine if there is an effective (active) breakpoint at this line of code.
Georg Brandlf51a6c72010-11-26 12:05:48 +0000366 Return a tuple of the breakpoint and a boolean that indicates if it is ok
367 to delete a temporary breakpoint. Return ``(None, None)`` if there is no
368 matching breakpoint.
Christian Heimesd8654cf2007-12-02 15:22:16 +0000369
370.. function:: set_trace()
371
Georg Brandlf51a6c72010-11-26 12:05:48 +0000372 Start debugging with a :class:`Bdb` instance from caller's frame.