Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 1 | :mod:`bdb` --- Debugger framework |
| 2 | ================================= |
| 3 | |
| 4 | .. module:: bdb |
| 5 | :synopsis: Debugger framework. |
| 6 | |
Éric Araujo | 29a0b57 | 2011-08-19 02:14:03 +0200 | [diff] [blame] | 7 | **Source code:** :source:`Lib/bdb.py` |
| 8 | |
| 9 | -------------- |
| 10 | |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 11 | The :mod:`bdb` module handles basic debugger functions, like setting breakpoints |
| 12 | or managing execution via the debugger. |
| 13 | |
| 14 | The following exception is defined: |
| 15 | |
| 16 | .. exception:: BdbQuit |
| 17 | |
| 18 | Exception raised by the :class:`Bdb` class for quitting the debugger. |
| 19 | |
| 20 | |
| 21 | The :mod:`bdb` module also defines two classes: |
| 22 | |
Serhiy Storchaka | 610f84a | 2013-12-23 18:19:34 +0200 | [diff] [blame] | 23 | .. class:: Breakpoint(self, file, line, temporary=0, cond=None, funcname=None) |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 24 | |
| 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 Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 38 | :class:`Breakpoint` instances have the following methods: |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 39 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 40 | .. method:: deleteMe() |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 41 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 42 | 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. |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 45 | |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 46 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 47 | .. method:: enable() |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 48 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 49 | Mark the breakpoint as enabled. |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 50 | |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 51 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 52 | .. method:: disable() |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 53 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 54 | Mark the breakpoint as disabled. |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 55 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 56 | |
| 57 | .. method:: pprint([out]) |
| 58 | |
| 59 | Print all the information about the breakpoint: |
| 60 | |
| 61 | * The breakpoint number. |
| 62 | * If it is temporary or not. |
| 63 | * Its file,line position. |
| 64 | * The condition that causes a break. |
| 65 | * If it must be ignored the next N times. |
| 66 | * The breakpoint hit count. |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 67 | |
| 68 | |
Andrew M. Kuchling | f6e3d7d | 2009-10-05 21:25:03 +0000 | [diff] [blame] | 69 | .. class:: Bdb(skip=None) |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 70 | |
Andrew M. Kuchling | f6e3d7d | 2009-10-05 21:25:03 +0000 | [diff] [blame] | 71 | The :class:`Bdb` class acts as a generic Python debugger base class. |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 72 | |
| 73 | This class takes care of the details of the trace facility; a derived class |
| 74 | should implement user interaction. The standard debugger class |
| 75 | (:class:`pdb.Pdb`) is an example. |
| 76 | |
Andrew M. Kuchling | f6e3d7d | 2009-10-05 21:25:03 +0000 | [diff] [blame] | 77 | The *skip* argument, if given, must be an iterable of glob-style |
| 78 | module name patterns. The debugger will not step into frames that |
| 79 | originate in a module that matches one of these patterns. Whether a |
| 80 | frame is considered to originate in a certain module is determined |
| 81 | by the ``__name__`` in the frame globals. |
| 82 | |
| 83 | .. versionadded:: 2.7 |
| 84 | The *skip* argument. |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 85 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 86 | The following methods of :class:`Bdb` normally don't need to be overridden. |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 87 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 88 | .. method:: canonic(filename) |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 89 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 90 | Auxiliary method for getting a filename in a canonical form, that is, as a |
| 91 | case-normalized (on case-insensitive filesystems) absolute path, stripped |
| 92 | of surrounding angle brackets. |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 93 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 94 | .. method:: reset() |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 95 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 96 | Set the :attr:`botframe`, :attr:`stopframe`, :attr:`returnframe` and |
| 97 | :attr:`quitting` attributes with values ready to start debugging. |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 98 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 99 | .. method:: trace_dispatch(frame, event, arg) |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 100 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 101 | This function is installed as the trace function of debugged frames. Its |
| 102 | return value is the new trace function (in most cases, that is, itself). |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 103 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 104 | The default implementation decides how to dispatch a frame, depending on |
| 105 | the type of event (passed as a string) that is about to be executed. |
| 106 | *event* can be one of the following: |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 107 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 108 | * ``"line"``: A new line of code is going to be executed. |
| 109 | * ``"call"``: A function is about to be called, or another code block |
| 110 | entered. |
| 111 | * ``"return"``: A function or other code block is about to return. |
| 112 | * ``"exception"``: An exception has occurred. |
| 113 | * ``"c_call"``: A C function is about to be called. |
| 114 | * ``"c_return"``: A C function has returned. |
Georg Brandl | 21946af | 2010-10-06 09:28:45 +0000 | [diff] [blame] | 115 | * ``"c_exception"``: A C function has raised an exception. |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 116 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 117 | For the Python events, specialized functions (see below) are called. For |
| 118 | the C events, no action is taken. |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 119 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 120 | The *arg* parameter depends on the previous event. |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 121 | |
Benjamin Peterson | 39ff59e | 2008-11-24 01:16:29 +0000 | [diff] [blame] | 122 | See the documentation for :func:`sys.settrace` for more information on the |
| 123 | trace function. For more information on code and frame objects, refer to |
| 124 | :ref:`types`. |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 125 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 126 | .. method:: dispatch_line(frame) |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 127 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 128 | If the debugger should stop on the current line, invoke the |
| 129 | :meth:`user_line` method (which should be overridden in subclasses). |
| 130 | Raise a :exc:`BdbQuit` exception if the :attr:`Bdb.quitting` flag is set |
| 131 | (which can be set from :meth:`user_line`). Return a reference to the |
| 132 | :meth:`trace_dispatch` method for further tracing in that scope. |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 133 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 134 | .. method:: dispatch_call(frame, arg) |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 135 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 136 | If the debugger should stop on this function call, invoke the |
| 137 | :meth:`user_call` 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_call`). Return a reference to the |
| 140 | :meth:`trace_dispatch` method for further tracing in that scope. |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 141 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 142 | .. method:: dispatch_return(frame, arg) |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 143 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 144 | If the debugger should stop on this function return, invoke the |
| 145 | :meth:`user_return` 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_return`). Return a reference to the |
| 148 | :meth:`trace_dispatch` method for further tracing in that scope. |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 149 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 150 | .. method:: dispatch_exception(frame, arg) |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 151 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 152 | If the debugger should stop at this exception, invokes the |
| 153 | :meth:`user_exception` 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_exception`). Return a reference to the |
| 156 | :meth:`trace_dispatch` method for further tracing in that scope. |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 157 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 158 | Normally derived classes don't override the following methods, but they may |
| 159 | if they want to redefine the definition of stopping and breakpoints. |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 160 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 161 | .. method:: stop_here(frame) |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 162 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 163 | This method checks if the *frame* is somewhere below :attr:`botframe` in |
| 164 | the call stack. :attr:`botframe` is the frame in which debugging started. |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 165 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 166 | .. method:: break_here(frame) |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 167 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 168 | This method checks if there is a breakpoint in the filename and line |
| 169 | belonging to *frame* or, at least, in the current function. If the |
| 170 | breakpoint is a temporary one, this method deletes it. |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 171 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 172 | .. method:: break_anywhere(frame) |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 173 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 174 | This method checks if there is a breakpoint in the filename of the current |
| 175 | frame. |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 176 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 177 | Derived classes should override these methods to gain control over debugger |
| 178 | operation. |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 179 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 180 | .. method:: user_call(frame, argument_list) |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 181 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 182 | This method is called from :meth:`dispatch_call` when there is the |
| 183 | possibility that a break might be necessary anywhere inside the called |
| 184 | function. |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 185 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 186 | .. method:: user_line(frame) |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 187 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 188 | This method is called from :meth:`dispatch_line` when either |
Serhiy Storchaka | 26d936a | 2013-11-29 12:16:53 +0200 | [diff] [blame] | 189 | :meth:`stop_here` or :meth:`break_here` yields ``True``. |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 190 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 191 | .. method:: user_return(frame, return_value) |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 192 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 193 | This method is called from :meth:`dispatch_return` when :meth:`stop_here` |
Serhiy Storchaka | 26d936a | 2013-11-29 12:16:53 +0200 | [diff] [blame] | 194 | yields ``True``. |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 195 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 196 | .. method:: user_exception(frame, exc_info) |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 197 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 198 | This method is called from :meth:`dispatch_exception` when |
Serhiy Storchaka | 26d936a | 2013-11-29 12:16:53 +0200 | [diff] [blame] | 199 | :meth:`stop_here` yields ``True``. |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 200 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 201 | .. method:: do_clear(arg) |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 202 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 203 | Handle how a breakpoint must be removed when it is a temporary one. |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 204 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 205 | This method must be implemented by derived classes. |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 206 | |
| 207 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 208 | Derived classes and clients can call the following methods to affect the |
| 209 | stepping state. |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 210 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 211 | .. method:: set_step() |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 212 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 213 | Stop after one line of code. |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 214 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 215 | .. method:: set_next(frame) |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 216 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 217 | Stop on the next line in or below the given frame. |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 218 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 219 | .. method:: set_return(frame) |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 220 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 221 | Stop when returning from the given frame. |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 222 | |
Benjamin Peterson | 9835394 | 2008-05-11 14:13:25 +0000 | [diff] [blame] | 223 | .. method:: set_until(frame) |
| 224 | |
| 225 | Stop when the line with the line no greater than the current one is |
Martin Panter | 4ed35fc | 2015-10-10 10:52:35 +0000 | [diff] [blame] | 226 | reached or when returning from current frame. |
Benjamin Peterson | 9835394 | 2008-05-11 14:13:25 +0000 | [diff] [blame] | 227 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 228 | .. method:: set_trace([frame]) |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 229 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 230 | Start debugging from *frame*. If *frame* is not specified, debugging |
| 231 | starts from caller's frame. |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 232 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 233 | .. method:: set_continue() |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 234 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 235 | Stop only at breakpoints or when finished. If there are no breakpoints, |
| 236 | set the system trace function to None. |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 237 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 238 | .. method:: set_quit() |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 239 | |
Serhiy Storchaka | 26d936a | 2013-11-29 12:16:53 +0200 | [diff] [blame] | 240 | Set the :attr:`quitting` attribute to ``True``. This raises :exc:`BdbQuit` in |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 241 | the next call to one of the :meth:`dispatch_\*` methods. |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 242 | |
| 243 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 244 | Derived classes and clients can call the following methods to manipulate |
| 245 | breakpoints. These methods return a string containing an error message if |
| 246 | something went wrong, or ``None`` if all is well. |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 247 | |
Hynek Schlawack | e58ce01 | 2012-05-22 10:27:40 +0200 | [diff] [blame] | 248 | .. method:: set_break(filename, lineno, temporary=0, cond=None, funcname=None) |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 249 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 250 | Set a new breakpoint. If the *lineno* line doesn't exist for the |
| 251 | *filename* passed as argument, return an error message. The *filename* |
| 252 | should be in canonical form, as described in the :meth:`canonic` method. |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 253 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 254 | .. method:: clear_break(filename, lineno) |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 255 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 256 | Delete the breakpoints in *filename* and *lineno*. If none were set, an |
| 257 | error message is returned. |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 258 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 259 | .. method:: clear_bpbynumber(arg) |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 260 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 261 | Delete the breakpoint which has the index *arg* in the |
| 262 | :attr:`Breakpoint.bpbynumber`. If *arg* is not numeric or out of range, |
| 263 | return an error message. |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 264 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 265 | .. method:: clear_all_file_breaks(filename) |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 266 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 267 | Delete all breakpoints in *filename*. If none were set, an error message |
| 268 | is returned. |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 269 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 270 | .. method:: clear_all_breaks() |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 271 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 272 | Delete all existing breakpoints. |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 273 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 274 | .. method:: get_break(filename, lineno) |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 275 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 276 | Check if there is a breakpoint for *lineno* of *filename*. |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 277 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 278 | .. method:: get_breaks(filename, lineno) |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 279 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 280 | Return all breakpoints for *lineno* in *filename*, or an empty list if |
| 281 | none are set. |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 282 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 283 | .. method:: get_file_breaks(filename) |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 284 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 285 | Return all breakpoints in *filename*, or an empty list if none are set. |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 286 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 287 | .. method:: get_all_breaks() |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 288 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 289 | Return all breakpoints that are set. |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 290 | |
| 291 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 292 | Derived classes and clients can call the following methods to get a data |
| 293 | structure representing a stack trace. |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 294 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 295 | .. method:: get_stack(f, t) |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 296 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 297 | Get a list of records for a frame and all higher (calling) and lower |
| 298 | frames, and the size of the higher part. |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 299 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 300 | .. method:: format_stack_entry(frame_lineno, [lprefix=': ']) |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 301 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 302 | Return a string with information about a stack entry, identified by a |
| 303 | ``(frame, lineno)`` tuple: |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 304 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 305 | * The canonical form of the filename which contains the frame. |
| 306 | * The function name, or ``"<lambda>"``. |
| 307 | * The input arguments. |
| 308 | * The return value. |
| 309 | * The line of code (if it exists). |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 310 | |
| 311 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 312 | The following two methods can be called by clients to use a debugger to debug |
| 313 | a :term:`statement`, given as a string. |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 314 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 315 | .. method:: run(cmd, [globals, [locals]]) |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 316 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 317 | Debug a statement executed via the :keyword:`exec` statement. *globals* |
| 318 | defaults to :attr:`__main__.__dict__`, *locals* defaults to *globals*. |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 319 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 320 | .. method:: runeval(expr, [globals, [locals]]) |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 321 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 322 | Debug an expression executed via the :func:`eval` function. *globals* and |
| 323 | *locals* have the same meaning as in :meth:`run`. |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 324 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 325 | .. method:: runctx(cmd, globals, locals) |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 326 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 327 | For backwards compatibility. Calls the :meth:`run` method. |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 328 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 329 | .. method:: runcall(func, *args, **kwds) |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 330 | |
Benjamin Peterson | c7b0592 | 2008-04-25 01:29:10 +0000 | [diff] [blame] | 331 | Debug a single function call, and return its result. |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 332 | |
| 333 | |
| 334 | Finally, the module defines the following functions: |
| 335 | |
| 336 | .. function:: checkfuncname(b, frame) |
| 337 | |
| 338 | Check whether we should break here, depending on the way the breakpoint *b* |
| 339 | was set. |
Georg Brandl | c62ef8b | 2009-01-03 20:55:06 +0000 | [diff] [blame] | 340 | |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 341 | If it was set via line number, it checks if ``b.line`` is the same as the one |
| 342 | in the frame also passed as argument. If the breakpoint was set via function |
| 343 | name, we have to check we are in the right frame (the right function) and if |
| 344 | we are in its first executable line. |
| 345 | |
| 346 | .. function:: effective(file, line, frame) |
| 347 | |
| 348 | Determine if there is an effective (active) breakpoint at this line of code. |
Georg Brandl | 86fed7d | 2010-11-26 18:26:04 +0000 | [diff] [blame] | 349 | Return a tuple of the breakpoint and a boolean that indicates if it is ok |
| 350 | to delete a temporary breakpoint. Return ``(None, None)`` if there is no |
| 351 | matching breakpoint. |
Georg Brandl | b15a8df | 2007-12-02 14:37:29 +0000 | [diff] [blame] | 352 | |
| 353 | .. function:: set_trace() |
| 354 | |
Georg Brandl | 86fed7d | 2010-11-26 18:26:04 +0000 | [diff] [blame] | 355 | Start debugging with a :class:`Bdb` instance from caller's frame. |