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