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