Benjamin Peterson | 90f5ba5 | 2010-03-11 22:53:45 +0000 | [diff] [blame] | 1 | #! /usr/bin/env python3 |
Guido van Rossum | f17361d | 1996-07-30 16:28:13 +0000 | [diff] [blame] | 2 | |
Georg Brandl | 02053ee | 2010-07-18 10:11:03 +0000 | [diff] [blame] | 3 | """ |
| 4 | The Python Debugger Pdb |
| 5 | ======================= |
Guido van Rossum | 92df0c6 | 1992-01-14 18:30:15 +0000 | [diff] [blame] | 6 | |
Georg Brandl | 02053ee | 2010-07-18 10:11:03 +0000 | [diff] [blame] | 7 | To use the debugger in its simplest form: |
| 8 | |
| 9 | >>> import pdb |
| 10 | >>> pdb.run('<a statement>') |
| 11 | |
| 12 | The debugger's prompt is '(Pdb) '. This will stop in the first |
| 13 | function call in <a statement>. |
| 14 | |
| 15 | Alternatively, if a statement terminated with an unhandled exception, |
| 16 | you can use pdb's post-mortem facility to inspect the contents of the |
| 17 | traceback: |
| 18 | |
| 19 | >>> <a statement> |
| 20 | <exception traceback> |
| 21 | >>> import pdb |
| 22 | >>> pdb.pm() |
| 23 | |
| 24 | The commands recognized by the debugger are listed in the next |
| 25 | section. Most can be abbreviated as indicated; e.g., h(elp) means |
| 26 | that 'help' can be typed as 'h' or 'help' (but not as 'he' or 'hel', |
| 27 | nor as 'H' or 'Help' or 'HELP'). Optional arguments are enclosed in |
| 28 | square brackets. Alternatives in the command syntax are separated |
| 29 | by a vertical bar (|). |
| 30 | |
| 31 | A blank line repeats the previous command literally, except for |
| 32 | 'list', where it lists the next 11 lines. |
| 33 | |
| 34 | Commands that the debugger doesn't recognize are assumed to be Python |
| 35 | statements and are executed in the context of the program being |
| 36 | debugged. Python statements can also be prefixed with an exclamation |
| 37 | point ('!'). This is a powerful way to inspect the program being |
| 38 | debugged; it is even possible to change variables or call functions. |
| 39 | When an exception occurs in such a statement, the exception name is |
| 40 | printed but the debugger's state is not changed. |
| 41 | |
| 42 | The debugger supports aliases, which can save typing. And aliases can |
| 43 | have parameters (see the alias help entry) which allows one a certain |
| 44 | level of adaptability to the context under examination. |
| 45 | |
| 46 | Multiple commands may be entered on a single line, separated by the |
| 47 | pair ';;'. No intelligence is applied to separating the commands; the |
| 48 | input is split at the first ';;', even if it is in the middle of a |
| 49 | quoted string. |
| 50 | |
| 51 | If a file ".pdbrc" exists in your home directory or in the current |
| 52 | directory, it is read in and executed as if it had been typed at the |
| 53 | debugger prompt. This is particularly useful for aliases. If both |
| 54 | files exist, the one in the home directory is read first and aliases |
| 55 | defined there can be overriden by the local file. |
| 56 | |
| 57 | Aside from aliases, the debugger is not directly programmable; but it |
| 58 | is implemented as a class from which you can derive your own debugger |
| 59 | class, which you can make as fancy as you like. |
| 60 | |
| 61 | |
| 62 | Debugger commands |
| 63 | ================= |
| 64 | |
Georg Brandl | 02053ee | 2010-07-18 10:11:03 +0000 | [diff] [blame] | 65 | """ |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 66 | # NOTE: the actual command documentation is collected from docstrings of the |
| 67 | # commands and is appended to __doc__ after the class has been defined. |
Guido van Rossum | 921c824 | 1992-01-10 14:54:42 +0000 | [diff] [blame] | 68 | |
Guido van Rossum | 921c824 | 1992-01-10 14:54:42 +0000 | [diff] [blame] | 69 | import sys |
| 70 | import linecache |
Guido van Rossum | 23efba4 | 1992-01-27 16:58:47 +0000 | [diff] [blame] | 71 | import cmd |
| 72 | import bdb |
Georg Brandl | 0a9c3e9 | 2010-07-30 18:46:38 +0000 | [diff] [blame] | 73 | import dis |
Guido van Rossum | b5699c7 | 1998-07-20 23:13:54 +0000 | [diff] [blame] | 74 | import os |
Barry Warsaw | 2bee8fe | 1999-09-09 16:32:41 +0000 | [diff] [blame] | 75 | import re |
Georg Brandl | 0a9c3e9 | 2010-07-30 18:46:38 +0000 | [diff] [blame] | 76 | import code |
Barry Warsaw | 210bd20 | 2002-11-05 22:40:20 +0000 | [diff] [blame] | 77 | import pprint |
Johannes Gijsbers | 25b38c8 | 2004-10-12 18:12:09 +0000 | [diff] [blame] | 78 | import traceback |
Georg Brandl | e59ca2a | 2010-07-30 17:04:28 +0000 | [diff] [blame] | 79 | import inspect |
| 80 | import types |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 81 | |
| 82 | |
| 83 | class Restart(Exception): |
| 84 | """Causes a debugger to be restarted for the debugged python program.""" |
| 85 | pass |
| 86 | |
Skip Montanaro | 352674d | 2001-02-07 23:14:30 +0000 | [diff] [blame] | 87 | __all__ = ["run", "pm", "Pdb", "runeval", "runctx", "runcall", "set_trace", |
| 88 | "post_mortem", "help"] |
| 89 | |
Barry Warsaw | 2bee8fe | 1999-09-09 16:32:41 +0000 | [diff] [blame] | 90 | def find_function(funcname, filename): |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 91 | cre = re.compile(r'def\s+%s\s*[(]' % re.escape(funcname)) |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 92 | try: |
| 93 | fp = open(filename) |
| 94 | except IOError: |
| 95 | return None |
| 96 | # consumer of this info expects the first line to be 1 |
| 97 | lineno = 1 |
| 98 | answer = None |
| 99 | while 1: |
| 100 | line = fp.readline() |
| 101 | if line == '': |
| 102 | break |
| 103 | if cre.match(line): |
| 104 | answer = funcname, filename, lineno |
| 105 | break |
| 106 | lineno = lineno + 1 |
| 107 | fp.close() |
| 108 | return answer |
Guido van Rossum | 921c824 | 1992-01-10 14:54:42 +0000 | [diff] [blame] | 109 | |
Georg Brandl | 5ed2b5a | 2010-07-30 18:08:12 +0000 | [diff] [blame] | 110 | def getsourcelines(obj): |
| 111 | lines, lineno = inspect.findsource(obj) |
Georg Brandl | 0a9c3e9 | 2010-07-30 18:46:38 +0000 | [diff] [blame] | 112 | if inspect.isframe(obj) and obj.f_globals is obj.f_locals: |
Georg Brandl | 5ed2b5a | 2010-07-30 18:08:12 +0000 | [diff] [blame] | 113 | # must be a module frame: do not try to cut a block out of it |
Georg Brandl | 0a9c3e9 | 2010-07-30 18:46:38 +0000 | [diff] [blame] | 114 | return lines, 1 |
Georg Brandl | 5ed2b5a | 2010-07-30 18:08:12 +0000 | [diff] [blame] | 115 | elif inspect.ismodule(obj): |
Georg Brandl | 0a9c3e9 | 2010-07-30 18:46:38 +0000 | [diff] [blame] | 116 | return lines, 1 |
Georg Brandl | 5ed2b5a | 2010-07-30 18:08:12 +0000 | [diff] [blame] | 117 | return inspect.getblock(lines[lineno:]), lineno+1 |
Guido van Rossum | 921c824 | 1992-01-10 14:54:42 +0000 | [diff] [blame] | 118 | |
Georg Brandl | 0a9c3e9 | 2010-07-30 18:46:38 +0000 | [diff] [blame] | 119 | def lasti2lineno(code, lasti): |
| 120 | linestarts = list(dis.findlinestarts(code)) |
| 121 | linestarts.reverse() |
| 122 | for i, lineno in linestarts: |
| 123 | if lasti >= i: |
| 124 | return lineno |
| 125 | return 0 |
| 126 | |
| 127 | |
Guido van Rossum | a558e37 | 1994-11-10 22:27:35 +0000 | [diff] [blame] | 128 | # Interaction prompt line will separate file and call info from code |
| 129 | # text using value of line_prefix string. A newline and arrow may |
| 130 | # be to your liking. You can set it once pdb is imported using the |
| 131 | # command "pdb.line_prefix = '\n% '". |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 132 | # line_prefix = ': ' # Use this to get the old situation back |
| 133 | line_prefix = '\n-> ' # Probably a better default |
Guido van Rossum | a558e37 | 1994-11-10 22:27:35 +0000 | [diff] [blame] | 134 | |
Guido van Rossum | 23efba4 | 1992-01-27 16:58:47 +0000 | [diff] [blame] | 135 | class Pdb(bdb.Bdb, cmd.Cmd): |
Guido van Rossum | 2424f85 | 1998-09-11 22:50:09 +0000 | [diff] [blame] | 136 | |
Georg Brandl | 243ad66 | 2009-05-05 09:00:19 +0000 | [diff] [blame] | 137 | def __init__(self, completekey='tab', stdin=None, stdout=None, skip=None): |
| 138 | bdb.Bdb.__init__(self, skip=skip) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 139 | cmd.Cmd.__init__(self, completekey, stdin, stdout) |
| 140 | if stdout: |
| 141 | self.use_rawinput = 0 |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 142 | self.prompt = '(Pdb) ' |
| 143 | self.aliases = {} |
Johannes Gijsbers | 25b38c8 | 2004-10-12 18:12:09 +0000 | [diff] [blame] | 144 | self.mainpyfile = '' |
| 145 | self._wait_for_mainpyfile = 0 |
Georg Brandl | 0a9c3e9 | 2010-07-30 18:46:38 +0000 | [diff] [blame] | 146 | self.tb_lineno = {} |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 147 | # Try to load readline if it exists |
| 148 | try: |
| 149 | import readline |
| 150 | except ImportError: |
| 151 | pass |
Guido van Rossum | 2424f85 | 1998-09-11 22:50:09 +0000 | [diff] [blame] | 152 | |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 153 | # Read $HOME/.pdbrc and ./.pdbrc |
| 154 | self.rcLines = [] |
Raymond Hettinger | 54f0222 | 2002-06-01 14:18:47 +0000 | [diff] [blame] | 155 | if 'HOME' in os.environ: |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 156 | envHome = os.environ['HOME'] |
| 157 | try: |
| 158 | rcFile = open(os.path.join(envHome, ".pdbrc")) |
| 159 | except IOError: |
| 160 | pass |
| 161 | else: |
| 162 | for line in rcFile.readlines(): |
| 163 | self.rcLines.append(line) |
| 164 | rcFile.close() |
| 165 | try: |
| 166 | rcFile = open(".pdbrc") |
| 167 | except IOError: |
| 168 | pass |
| 169 | else: |
| 170 | for line in rcFile.readlines(): |
| 171 | self.rcLines.append(line) |
| 172 | rcFile.close() |
Guido van Rossum | 23efba4 | 1992-01-27 16:58:47 +0000 | [diff] [blame] | 173 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 174 | self.commands = {} # associates a command list to breakpoint numbers |
Benjamin Peterson | d23f822 | 2009-04-05 19:13:16 +0000 | [diff] [blame] | 175 | self.commands_doprompt = {} # for each bp num, tells if the prompt |
| 176 | # must be disp. after execing the cmd list |
| 177 | self.commands_silent = {} # for each bp num, tells if the stack trace |
| 178 | # must be disp. after execing the cmd list |
| 179 | self.commands_defining = False # True while in the process of defining |
| 180 | # a command list |
| 181 | self.commands_bnum = None # The breakpoint number for which we are |
| 182 | # defining a list |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 183 | |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 184 | def reset(self): |
| 185 | bdb.Bdb.reset(self) |
| 186 | self.forget() |
Guido van Rossum | 23efba4 | 1992-01-27 16:58:47 +0000 | [diff] [blame] | 187 | |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 188 | def forget(self): |
| 189 | self.lineno = None |
| 190 | self.stack = [] |
| 191 | self.curindex = 0 |
| 192 | self.curframe = None |
Georg Brandl | 0a9c3e9 | 2010-07-30 18:46:38 +0000 | [diff] [blame] | 193 | self.tb_lineno.clear() |
Guido van Rossum | 2424f85 | 1998-09-11 22:50:09 +0000 | [diff] [blame] | 194 | |
Georg Brandl | 0a9c3e9 | 2010-07-30 18:46:38 +0000 | [diff] [blame] | 195 | def setup(self, f, tb): |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 196 | self.forget() |
Georg Brandl | 0a9c3e9 | 2010-07-30 18:46:38 +0000 | [diff] [blame] | 197 | self.stack, self.curindex = self.get_stack(f, tb) |
| 198 | while tb: |
| 199 | # when setting up post-mortem debugging with a traceback, save all |
| 200 | # the original line numbers to be displayed along the current line |
| 201 | # numbers (which can be different, e.g. due to finally clauses) |
| 202 | lineno = lasti2lineno(tb.tb_frame.f_code, tb.tb_lasti) |
| 203 | self.tb_lineno[tb.tb_frame] = lineno |
| 204 | tb = tb.tb_next |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 205 | self.curframe = self.stack[self.curindex][0] |
Benjamin Peterson | d23f822 | 2009-04-05 19:13:16 +0000 | [diff] [blame] | 206 | # The f_locals dictionary is updated from the actual frame |
| 207 | # locals whenever the .f_locals accessor is called, so we |
| 208 | # cache it here to ensure that modifications are not overwritten. |
| 209 | self.curframe_locals = self.curframe.f_locals |
Georg Brandl | e023091 | 2010-07-30 08:29:39 +0000 | [diff] [blame] | 210 | return self.execRcLines() |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 211 | |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 212 | # Can be executed earlier than 'setup' if desired |
| 213 | def execRcLines(self): |
Georg Brandl | e023091 | 2010-07-30 08:29:39 +0000 | [diff] [blame] | 214 | if not self.rcLines: |
| 215 | return |
| 216 | # local copy because of recursion |
| 217 | rcLines = self.rcLines |
| 218 | rcLines.reverse() |
| 219 | # execute every line only once |
| 220 | self.rcLines = [] |
| 221 | while rcLines: |
| 222 | line = rcLines.pop().strip() |
| 223 | if line and line[0] != '#': |
| 224 | if self.onecmd(line): |
| 225 | # if onecmd returns True, the command wants to exit |
| 226 | # from the interaction, save leftover rc lines |
| 227 | # to execute before next interaction |
| 228 | self.rcLines += reversed(rcLines) |
| 229 | return True |
Guido van Rossum | 2424f85 | 1998-09-11 22:50:09 +0000 | [diff] [blame] | 230 | |
Tim Peters | 280488b | 2002-08-23 18:19:30 +0000 | [diff] [blame] | 231 | # Override Bdb methods |
Michael W. Hudson | dd32a91 | 2002-08-15 14:59:02 +0000 | [diff] [blame] | 232 | |
| 233 | def user_call(self, frame, argument_list): |
| 234 | """This method is called when there is the remote possibility |
| 235 | that we ever need to stop in this function.""" |
Johannes Gijsbers | 25b38c8 | 2004-10-12 18:12:09 +0000 | [diff] [blame] | 236 | if self._wait_for_mainpyfile: |
| 237 | return |
Michael W. Hudson | 01eb85c | 2003-01-31 17:48:29 +0000 | [diff] [blame] | 238 | if self.stop_here(frame): |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 239 | self.message('--Call--') |
Michael W. Hudson | 01eb85c | 2003-01-31 17:48:29 +0000 | [diff] [blame] | 240 | self.interaction(frame, None) |
Guido van Rossum | 2424f85 | 1998-09-11 22:50:09 +0000 | [diff] [blame] | 241 | |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 242 | def user_line(self, frame): |
| 243 | """This function is called when we stop or break at this line.""" |
Johannes Gijsbers | 25b38c8 | 2004-10-12 18:12:09 +0000 | [diff] [blame] | 244 | if self._wait_for_mainpyfile: |
| 245 | if (self.mainpyfile != self.canonic(frame.f_code.co_filename) |
| 246 | or frame.f_lineno<= 0): |
| 247 | return |
| 248 | self._wait_for_mainpyfile = 0 |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 249 | if self.bp_commands(frame): |
| 250 | self.interaction(frame, None) |
| 251 | |
Georg Brandl | e023091 | 2010-07-30 08:29:39 +0000 | [diff] [blame] | 252 | def bp_commands(self, frame): |
Georg Brandl | 3078df0 | 2009-05-05 09:11:31 +0000 | [diff] [blame] | 253 | """Call every command that was set for the current active breakpoint |
| 254 | (if there is one). |
| 255 | |
| 256 | Returns True if the normal interaction function must be called, |
| 257 | False otherwise.""" |
| 258 | # self.currentbp is set in bdb in Bdb.break_here if a breakpoint was hit |
| 259 | if getattr(self, "currentbp", False) and \ |
| 260 | self.currentbp in self.commands: |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 261 | currentbp = self.currentbp |
| 262 | self.currentbp = 0 |
| 263 | lastcmd_back = self.lastcmd |
| 264 | self.setup(frame, None) |
| 265 | for line in self.commands[currentbp]: |
| 266 | self.onecmd(line) |
| 267 | self.lastcmd = lastcmd_back |
| 268 | if not self.commands_silent[currentbp]: |
| 269 | self.print_stack_entry(self.stack[self.curindex]) |
| 270 | if self.commands_doprompt[currentbp]: |
| 271 | self.cmdloop() |
| 272 | self.forget() |
| 273 | return |
| 274 | return 1 |
Guido van Rossum | 9e1ee97 | 1997-07-11 13:43:53 +0000 | [diff] [blame] | 275 | |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 276 | def user_return(self, frame, return_value): |
| 277 | """This function is called when a return trap is set here.""" |
Georg Brandl | 34cc0f5 | 2010-07-30 09:43:00 +0000 | [diff] [blame] | 278 | if self._wait_for_mainpyfile: |
| 279 | return |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 280 | frame.f_locals['__return__'] = return_value |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 281 | self.message('--Return--') |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 282 | self.interaction(frame, None) |
Guido van Rossum | 2424f85 | 1998-09-11 22:50:09 +0000 | [diff] [blame] | 283 | |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 284 | def user_exception(self, frame, exc_info): |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 285 | """This function is called if an exception occurs, |
| 286 | but only if we are to stop at or just below this level.""" |
Georg Brandl | 34cc0f5 | 2010-07-30 09:43:00 +0000 | [diff] [blame] | 287 | if self._wait_for_mainpyfile: |
| 288 | return |
Guido van Rossum | 1bc535d | 2007-05-15 18:46:22 +0000 | [diff] [blame] | 289 | exc_type, exc_value, exc_traceback = exc_info |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 290 | frame.f_locals['__exception__'] = exc_type, exc_value |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 291 | self.message(traceback.format_exception_only(exc_type, |
| 292 | exc_value)[-1].strip()) |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 293 | self.interaction(frame, exc_traceback) |
Guido van Rossum | 2424f85 | 1998-09-11 22:50:09 +0000 | [diff] [blame] | 294 | |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 295 | # General interaction function |
| 296 | |
| 297 | def interaction(self, frame, traceback): |
Georg Brandl | e023091 | 2010-07-30 08:29:39 +0000 | [diff] [blame] | 298 | if self.setup(frame, traceback): |
| 299 | # no interaction desired at this time (happens if .pdbrc contains |
| 300 | # a command like "continue") |
| 301 | self.forget() |
| 302 | return |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 303 | self.print_stack_entry(self.stack[self.curindex]) |
| 304 | self.cmdloop() |
| 305 | self.forget() |
| 306 | |
Benjamin Peterson | d23f822 | 2009-04-05 19:13:16 +0000 | [diff] [blame] | 307 | def displayhook(self, obj): |
| 308 | """Custom displayhook for the exec in default(), which prevents |
| 309 | assignment of the _ variable in the builtins. |
| 310 | """ |
Georg Brandl | 9fa2e02 | 2009-09-16 16:40:45 +0000 | [diff] [blame] | 311 | # reproduce the behavior of the standard displayhook, not printing None |
| 312 | if obj is not None: |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 313 | self.message(repr(obj)) |
Benjamin Peterson | d23f822 | 2009-04-05 19:13:16 +0000 | [diff] [blame] | 314 | |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 315 | def default(self, line): |
| 316 | if line[:1] == '!': line = line[1:] |
Benjamin Peterson | d23f822 | 2009-04-05 19:13:16 +0000 | [diff] [blame] | 317 | locals = self.curframe_locals |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 318 | globals = self.curframe.f_globals |
| 319 | try: |
| 320 | code = compile(line + '\n', '<stdin>', 'single') |
Christian Heimes | 679db4a | 2008-01-18 09:56:22 +0000 | [diff] [blame] | 321 | save_stdout = sys.stdout |
| 322 | save_stdin = sys.stdin |
Benjamin Peterson | d23f822 | 2009-04-05 19:13:16 +0000 | [diff] [blame] | 323 | save_displayhook = sys.displayhook |
Guido van Rossum | 7736b5b | 2008-01-15 21:44:53 +0000 | [diff] [blame] | 324 | try: |
| 325 | sys.stdin = self.stdin |
| 326 | sys.stdout = self.stdout |
Benjamin Peterson | d23f822 | 2009-04-05 19:13:16 +0000 | [diff] [blame] | 327 | sys.displayhook = self.displayhook |
Guido van Rossum | 7736b5b | 2008-01-15 21:44:53 +0000 | [diff] [blame] | 328 | exec(code, globals, locals) |
| 329 | finally: |
| 330 | sys.stdout = save_stdout |
| 331 | sys.stdin = save_stdin |
Benjamin Peterson | d23f822 | 2009-04-05 19:13:16 +0000 | [diff] [blame] | 332 | sys.displayhook = save_displayhook |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 333 | except: |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 334 | exc_info = sys.exc_info()[:2] |
| 335 | self.error(traceback.format_exception_only(*exc_info)[-1].strip()) |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 336 | |
| 337 | def precmd(self, line): |
| 338 | """Handle alias expansion and ';;' separator.""" |
Guido van Rossum | 0845459 | 2002-07-12 13:10:53 +0000 | [diff] [blame] | 339 | if not line.strip(): |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 340 | return line |
Eric S. Raymond | 9b93c5f | 2001-02-09 07:58:53 +0000 | [diff] [blame] | 341 | args = line.split() |
Raymond Hettinger | 54f0222 | 2002-06-01 14:18:47 +0000 | [diff] [blame] | 342 | while args[0] in self.aliases: |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 343 | line = self.aliases[args[0]] |
| 344 | ii = 1 |
| 345 | for tmpArg in args[1:]: |
Eric S. Raymond | 9b93c5f | 2001-02-09 07:58:53 +0000 | [diff] [blame] | 346 | line = line.replace("%" + str(ii), |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 347 | tmpArg) |
| 348 | ii = ii + 1 |
Eric S. Raymond | 9b93c5f | 2001-02-09 07:58:53 +0000 | [diff] [blame] | 349 | line = line.replace("%*", ' '.join(args[1:])) |
| 350 | args = line.split() |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 351 | # split into ';;' separated commands |
| 352 | # unless it's an alias command |
| 353 | if args[0] != 'alias': |
Eric S. Raymond | 9b93c5f | 2001-02-09 07:58:53 +0000 | [diff] [blame] | 354 | marker = line.find(';;') |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 355 | if marker >= 0: |
| 356 | # queue up everything after marker |
Eric S. Raymond | 9b93c5f | 2001-02-09 07:58:53 +0000 | [diff] [blame] | 357 | next = line[marker+2:].lstrip() |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 358 | self.cmdqueue.append(next) |
Eric S. Raymond | 9b93c5f | 2001-02-09 07:58:53 +0000 | [diff] [blame] | 359 | line = line[:marker].rstrip() |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 360 | return line |
| 361 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 362 | def onecmd(self, line): |
| 363 | """Interpret the argument as though it had been typed in response |
| 364 | to the prompt. |
| 365 | |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 366 | Checks whether this line is typed at the normal prompt or in |
| 367 | a breakpoint command list definition. |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 368 | """ |
| 369 | if not self.commands_defining: |
| 370 | return cmd.Cmd.onecmd(self, line) |
| 371 | else: |
| 372 | return self.handle_command_def(line) |
| 373 | |
Georg Brandl | b90ffd8 | 2010-07-30 22:20:16 +0000 | [diff] [blame] | 374 | def handle_command_def(self, line): |
Georg Brandl | 44f8bf9 | 2010-07-30 08:54:49 +0000 | [diff] [blame] | 375 | """Handles one command line during command list definition.""" |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 376 | cmd, arg, line = self.parseline(line) |
Georg Brandl | 44f8bf9 | 2010-07-30 08:54:49 +0000 | [diff] [blame] | 377 | if not cmd: |
| 378 | return |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 379 | if cmd == 'silent': |
| 380 | self.commands_silent[self.commands_bnum] = True |
| 381 | return # continue to handle other cmd def in the cmd list |
| 382 | elif cmd == 'end': |
| 383 | self.cmdqueue = [] |
| 384 | return 1 # end of cmd list |
| 385 | cmdlist = self.commands[self.commands_bnum] |
Georg Brandl | 44f8bf9 | 2010-07-30 08:54:49 +0000 | [diff] [blame] | 386 | if arg: |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 387 | cmdlist.append(cmd+' '+arg) |
| 388 | else: |
| 389 | cmdlist.append(cmd) |
| 390 | # Determine if we must stop |
| 391 | try: |
| 392 | func = getattr(self, 'do_' + cmd) |
| 393 | except AttributeError: |
| 394 | func = self.default |
Georg Brandl | 3078df0 | 2009-05-05 09:11:31 +0000 | [diff] [blame] | 395 | # one of the resuming commands |
| 396 | if func.__name__ in self.commands_resuming: |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 397 | self.commands_doprompt[self.commands_bnum] = False |
| 398 | self.cmdqueue = [] |
| 399 | return 1 |
| 400 | return |
| 401 | |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 402 | # interface abstraction functions |
| 403 | |
| 404 | def message(self, msg): |
| 405 | print(msg, file=self.stdout) |
| 406 | |
| 407 | def error(self, msg): |
| 408 | print('***', msg, file=self.stdout) |
| 409 | |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 410 | # Command definitions, called by cmdloop() |
| 411 | # The argument is the remaining string on the command line |
| 412 | # Return true to exit from the command loop |
| 413 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 414 | def do_commands(self, arg): |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 415 | """commands [bpnumber] |
| 416 | (com) ... |
| 417 | (com) end |
| 418 | (Pdb) |
Georg Brandl | 3078df0 | 2009-05-05 09:11:31 +0000 | [diff] [blame] | 419 | |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 420 | Specify a list of commands for breakpoint number bpnumber. |
| 421 | The commands themselves are entered on the following lines. |
| 422 | Type a line containing just 'end' to terminate the commands. |
| 423 | The commands are executed when the breakpoint is hit. |
| 424 | |
| 425 | To remove all commands from a breakpoint, type commands and |
| 426 | follow it immediately with end; that is, give no commands. |
| 427 | |
| 428 | With no bpnumber argument, commands refers to the last |
| 429 | breakpoint set. |
| 430 | |
| 431 | You can use breakpoint commands to start your program up |
| 432 | again. Simply use the continue command, or step, or any other |
| 433 | command that resumes execution. |
| 434 | |
| 435 | Specifying any command resuming execution (currently continue, |
| 436 | step, next, return, jump, quit and their abbreviations) |
| 437 | terminates the command list (as if that command was |
| 438 | immediately followed by end). This is because any time you |
| 439 | resume execution (even with a simple next or step), you may |
| 440 | encounter another breakpoint -- which could have its own |
| 441 | command list, leading to ambiguities about which list to |
| 442 | execute. |
| 443 | |
| 444 | If you use the 'silent' command in the command list, the usual |
| 445 | message about stopping at a breakpoint is not printed. This |
| 446 | may be desirable for breakpoints that are to print a specific |
| 447 | message and then continue. If none of the other commands |
| 448 | print anything, you will see no sign that the breakpoint was |
| 449 | reached. |
| 450 | """ |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 451 | if not arg: |
Georg Brandl | 7410dd1 | 2010-07-30 12:01:20 +0000 | [diff] [blame] | 452 | bnum = len(bdb.Breakpoint.bpbynumber) - 1 |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 453 | else: |
| 454 | try: |
| 455 | bnum = int(arg) |
| 456 | except: |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 457 | self.error("Usage: commands [bnum]\n ...\n end") |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 458 | return |
| 459 | self.commands_bnum = bnum |
Georg Brandl | b90ffd8 | 2010-07-30 22:20:16 +0000 | [diff] [blame] | 460 | # Save old definitions for the case of a keyboard interrupt. |
| 461 | if bnum in self.commands: |
| 462 | old_command_defs = (self.commands[bnum], |
| 463 | self.commands_doprompt[bnum], |
| 464 | self.commands_silent[bnum]) |
| 465 | else: |
| 466 | old_command_defs = None |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 467 | self.commands[bnum] = [] |
| 468 | self.commands_doprompt[bnum] = True |
| 469 | self.commands_silent[bnum] = False |
Georg Brandl | b90ffd8 | 2010-07-30 22:20:16 +0000 | [diff] [blame] | 470 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 471 | prompt_back = self.prompt |
| 472 | self.prompt = '(com) ' |
| 473 | self.commands_defining = True |
Georg Brandl | 44f8bf9 | 2010-07-30 08:54:49 +0000 | [diff] [blame] | 474 | try: |
| 475 | self.cmdloop() |
Georg Brandl | b90ffd8 | 2010-07-30 22:20:16 +0000 | [diff] [blame] | 476 | except KeyboardInterrupt: |
| 477 | # Restore old definitions. |
| 478 | if old_command_defs: |
| 479 | self.commands[bnum] = old_command_defs[0] |
| 480 | self.commands_doprompt[bnum] = old_command_defs[1] |
| 481 | self.commands_silent[bnum] = old_command_defs[2] |
| 482 | else: |
| 483 | del self.commands[bnum] |
| 484 | del self.commands_doprompt[bnum] |
| 485 | del self.commands_silent[bnum] |
| 486 | self.error('command definition aborted, old commands restored') |
Georg Brandl | 44f8bf9 | 2010-07-30 08:54:49 +0000 | [diff] [blame] | 487 | finally: |
| 488 | self.commands_defining = False |
| 489 | self.prompt = prompt_back |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 490 | |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 491 | def do_break(self, arg, temporary = 0): |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 492 | """b(reak) [ ([filename:]lineno | function) [, condition] ] |
| 493 | Without argument, list all breaks. |
| 494 | |
| 495 | With a line number argument, set a break at this line in the |
| 496 | current file. With a function name, set a break at the first |
| 497 | executable line of that function. If a second argument is |
| 498 | present, it is a string specifying an expression which must |
| 499 | evaluate to true before the breakpoint is honored. |
| 500 | |
| 501 | The line number may be prefixed with a filename and a colon, |
| 502 | to specify a breakpoint in another file (probably one that |
| 503 | hasn't been loaded yet). The file is searched for on |
| 504 | sys.path; the .py suffix may be omitted. |
| 505 | """ |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 506 | if not arg: |
| 507 | if self.breaks: # There's at least one |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 508 | self.message("Num Type Disp Enb Where") |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 509 | for bp in bdb.Breakpoint.bpbynumber: |
| 510 | if bp: |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 511 | self.message(bp.bpformat()) |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 512 | return |
| 513 | # parse arguments; comma has lowest precedence |
| 514 | # and cannot occur in filename |
| 515 | filename = None |
| 516 | lineno = None |
| 517 | cond = None |
Eric S. Raymond | 9b93c5f | 2001-02-09 07:58:53 +0000 | [diff] [blame] | 518 | comma = arg.find(',') |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 519 | if comma > 0: |
| 520 | # parse stuff after comma: "condition" |
Eric S. Raymond | 9b93c5f | 2001-02-09 07:58:53 +0000 | [diff] [blame] | 521 | cond = arg[comma+1:].lstrip() |
| 522 | arg = arg[:comma].rstrip() |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 523 | # parse stuff before comma: [filename:]lineno | function |
Eric S. Raymond | 9b93c5f | 2001-02-09 07:58:53 +0000 | [diff] [blame] | 524 | colon = arg.rfind(':') |
Johannes Gijsbers | 4a9faa1 | 2004-08-30 13:29:44 +0000 | [diff] [blame] | 525 | funcname = None |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 526 | if colon >= 0: |
Eric S. Raymond | 9b93c5f | 2001-02-09 07:58:53 +0000 | [diff] [blame] | 527 | filename = arg[:colon].rstrip() |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 528 | f = self.lookupmodule(filename) |
| 529 | if not f: |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 530 | self.error('%r not found from sys.path' % filename) |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 531 | return |
| 532 | else: |
| 533 | filename = f |
Eric S. Raymond | 9b93c5f | 2001-02-09 07:58:53 +0000 | [diff] [blame] | 534 | arg = arg[colon+1:].lstrip() |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 535 | try: |
| 536 | lineno = int(arg) |
Guido van Rossum | b940e11 | 2007-01-10 16:19:56 +0000 | [diff] [blame] | 537 | except ValueError as msg: |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 538 | self.error('Bad lineno: %s' % arg) |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 539 | return |
| 540 | else: |
| 541 | # no colon; can be lineno or function |
| 542 | try: |
| 543 | lineno = int(arg) |
| 544 | except ValueError: |
| 545 | try: |
| 546 | func = eval(arg, |
| 547 | self.curframe.f_globals, |
Benjamin Peterson | d23f822 | 2009-04-05 19:13:16 +0000 | [diff] [blame] | 548 | self.curframe_locals) |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 549 | except: |
| 550 | func = arg |
| 551 | try: |
Christian Heimes | ff73795 | 2007-11-27 10:40:20 +0000 | [diff] [blame] | 552 | if hasattr(func, '__func__'): |
| 553 | func = func.__func__ |
Neal Norwitz | 221085d | 2007-02-25 20:55:47 +0000 | [diff] [blame] | 554 | code = func.__code__ |
Johannes Gijsbers | 4a9faa1 | 2004-08-30 13:29:44 +0000 | [diff] [blame] | 555 | #use co_name to identify the bkpt (function names |
| 556 | #could be aliased, but co_name is invariant) |
| 557 | funcname = code.co_name |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 558 | lineno = code.co_firstlineno |
| 559 | filename = code.co_filename |
| 560 | except: |
| 561 | # last thing to try |
| 562 | (ok, filename, ln) = self.lineinfo(arg) |
| 563 | if not ok: |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 564 | self.error('The specified object %r is not a function ' |
| 565 | 'or was not found along sys.path.' % arg) |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 566 | return |
Johannes Gijsbers | 4a9faa1 | 2004-08-30 13:29:44 +0000 | [diff] [blame] | 567 | funcname = ok # ok contains a function name |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 568 | lineno = int(ln) |
| 569 | if not filename: |
| 570 | filename = self.defaultFile() |
| 571 | # Check for reasonable breakpoint |
| 572 | line = self.checkline(filename, lineno) |
| 573 | if line: |
| 574 | # now set the break point |
Johannes Gijsbers | 4a9faa1 | 2004-08-30 13:29:44 +0000 | [diff] [blame] | 575 | err = self.set_break(filename, line, temporary, cond, funcname) |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 576 | if err: |
| 577 | self.error(err, file=self.stdout) |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 578 | else: |
| 579 | bp = self.get_breaks(filename, line)[-1] |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 580 | self.message("Breakpoint %d at %s:%d" % |
| 581 | (bp.number, bp.file, bp.line)) |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 582 | |
| 583 | # To be overridden in derived debuggers |
| 584 | def defaultFile(self): |
| 585 | """Produce a reasonable default.""" |
| 586 | filename = self.curframe.f_code.co_filename |
Johannes Gijsbers | 25b38c8 | 2004-10-12 18:12:09 +0000 | [diff] [blame] | 587 | if filename == '<string>' and self.mainpyfile: |
| 588 | filename = self.mainpyfile |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 589 | return filename |
| 590 | |
| 591 | do_b = do_break |
| 592 | |
| 593 | def do_tbreak(self, arg): |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 594 | """tbreak [ ([filename:]lineno | function) [, condition] ] |
| 595 | Same arguments as break, but sets a temporary breakpoint: it |
| 596 | is automatically deleted when first hit. |
| 597 | """ |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 598 | self.do_break(arg, 1) |
| 599 | |
| 600 | def lineinfo(self, identifier): |
| 601 | failed = (None, None, None) |
| 602 | # Input is identifier, may be in single quotes |
Eric S. Raymond | 9b93c5f | 2001-02-09 07:58:53 +0000 | [diff] [blame] | 603 | idstring = identifier.split("'") |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 604 | if len(idstring) == 1: |
| 605 | # not in single quotes |
Eric S. Raymond | 9b93c5f | 2001-02-09 07:58:53 +0000 | [diff] [blame] | 606 | id = idstring[0].strip() |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 607 | elif len(idstring) == 3: |
| 608 | # quoted |
Eric S. Raymond | 9b93c5f | 2001-02-09 07:58:53 +0000 | [diff] [blame] | 609 | id = idstring[1].strip() |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 610 | else: |
| 611 | return failed |
| 612 | if id == '': return failed |
Eric S. Raymond | 9b93c5f | 2001-02-09 07:58:53 +0000 | [diff] [blame] | 613 | parts = id.split('.') |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 614 | # Protection for derived debuggers |
| 615 | if parts[0] == 'self': |
| 616 | del parts[0] |
| 617 | if len(parts) == 0: |
| 618 | return failed |
| 619 | # Best first guess at file to look at |
| 620 | fname = self.defaultFile() |
| 621 | if len(parts) == 1: |
| 622 | item = parts[0] |
| 623 | else: |
| 624 | # More than one part. |
| 625 | # First is module, second is method/class |
| 626 | f = self.lookupmodule(parts[0]) |
| 627 | if f: |
| 628 | fname = f |
| 629 | item = parts[1] |
| 630 | answer = find_function(item, fname) |
| 631 | return answer or failed |
| 632 | |
| 633 | def checkline(self, filename, lineno): |
Johannes Gijsbers | 4a9faa1 | 2004-08-30 13:29:44 +0000 | [diff] [blame] | 634 | """Check whether specified line seems to be executable. |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 635 | |
Johannes Gijsbers | 4a9faa1 | 2004-08-30 13:29:44 +0000 | [diff] [blame] | 636 | Return `lineno` if it is, 0 if not (e.g. a docstring, comment, blank |
| 637 | line or EOF). Warning: testing is not comprehensive. |
| 638 | """ |
Georg Brandl | 1e30bd3 | 2010-07-30 07:21:26 +0000 | [diff] [blame] | 639 | # this method should be callable before starting debugging, so default |
| 640 | # to "no globals" if there is no current frame |
| 641 | globs = self.curframe.f_globals if hasattr(self, 'curframe') else None |
| 642 | line = linecache.getline(filename, lineno, globs) |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 643 | if not line: |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 644 | self.message('End of file') |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 645 | return 0 |
Eric S. Raymond | 9b93c5f | 2001-02-09 07:58:53 +0000 | [diff] [blame] | 646 | line = line.strip() |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 647 | # Don't allow setting breakpoint at a blank line |
Guido van Rossum | 0845459 | 2002-07-12 13:10:53 +0000 | [diff] [blame] | 648 | if (not line or (line[0] == '#') or |
| 649 | (line[:3] == '"""') or line[:3] == "'''"): |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 650 | self.error('Blank or comment') |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 651 | return 0 |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 652 | return lineno |
| 653 | |
| 654 | def do_enable(self, arg): |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 655 | """enable bpnumber [bpnumber ...] |
| 656 | Enables the breakpoints given as a space separated list of |
| 657 | breakpoint numbers. |
| 658 | """ |
Eric S. Raymond | 9b93c5f | 2001-02-09 07:58:53 +0000 | [diff] [blame] | 659 | args = arg.split() |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 660 | for i in args: |
Andrew M. Kuchling | b1f8bab | 2003-05-22 14:46:12 +0000 | [diff] [blame] | 661 | try: |
Georg Brandl | 7410dd1 | 2010-07-30 12:01:20 +0000 | [diff] [blame] | 662 | bp = self.get_bpbynumber(i) |
| 663 | except ValueError as err: |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 664 | self.error(err) |
Georg Brandl | 7410dd1 | 2010-07-30 12:01:20 +0000 | [diff] [blame] | 665 | else: |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 666 | bp.enable() |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 667 | self.message('Enabled %s' % bp) |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 668 | |
| 669 | def do_disable(self, arg): |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 670 | """disable bpnumber [bpnumber ...] |
| 671 | Disables the breakpoints given as a space separated list of |
| 672 | breakpoint numbers. Disabling a breakpoint means it cannot |
| 673 | cause the program to stop execution, but unlike clearing a |
| 674 | breakpoint, it remains in the list of breakpoints and can be |
| 675 | (re-)enabled. |
| 676 | """ |
Eric S. Raymond | 9b93c5f | 2001-02-09 07:58:53 +0000 | [diff] [blame] | 677 | args = arg.split() |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 678 | for i in args: |
Andrew M. Kuchling | b1f8bab | 2003-05-22 14:46:12 +0000 | [diff] [blame] | 679 | try: |
Georg Brandl | 7410dd1 | 2010-07-30 12:01:20 +0000 | [diff] [blame] | 680 | bp = self.get_bpbynumber(i) |
| 681 | except ValueError as err: |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 682 | self.error(err) |
Georg Brandl | 7410dd1 | 2010-07-30 12:01:20 +0000 | [diff] [blame] | 683 | else: |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 684 | bp.disable() |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 685 | self.message('Disabled %s' % bp) |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 686 | |
| 687 | def do_condition(self, arg): |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 688 | """condition bpnumber [condition] |
| 689 | Set a new condition for the breakpoint, an expression which |
| 690 | must evaluate to true before the breakpoint is honored. If |
| 691 | condition is absent, any existing condition is removed; i.e., |
| 692 | the breakpoint is made unconditional. |
| 693 | """ |
Eric S. Raymond | 9b93c5f | 2001-02-09 07:58:53 +0000 | [diff] [blame] | 694 | args = arg.split(' ', 1) |
Thomas Wouters | b213704 | 2007-02-01 18:02:27 +0000 | [diff] [blame] | 695 | try: |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 696 | cond = args[1] |
Georg Brandl | 7410dd1 | 2010-07-30 12:01:20 +0000 | [diff] [blame] | 697 | except IndexError: |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 698 | cond = None |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 699 | try: |
Georg Brandl | 7410dd1 | 2010-07-30 12:01:20 +0000 | [diff] [blame] | 700 | bp = self.get_bpbynumber(args[0].strip()) |
| 701 | except ValueError as err: |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 702 | self.error(err) |
Georg Brandl | 7410dd1 | 2010-07-30 12:01:20 +0000 | [diff] [blame] | 703 | else: |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 704 | bp.cond = cond |
| 705 | if not cond: |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 706 | self.message('Breakpoint %d is now unconditional.' % bp.number) |
Georg Brandl | 7410dd1 | 2010-07-30 12:01:20 +0000 | [diff] [blame] | 707 | else: |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 708 | self.message('New condition set for breakpoint %d.' % bp.number) |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 709 | |
Georg Brandl | 7410dd1 | 2010-07-30 12:01:20 +0000 | [diff] [blame] | 710 | def do_ignore(self, arg): |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 711 | """ignore bpnumber [count] |
| 712 | Set the ignore count for the given breakpoint number. If |
| 713 | count is omitted, the ignore count is set to 0. A breakpoint |
| 714 | becomes active when the ignore count is zero. When non-zero, |
| 715 | the count is decremented each time the breakpoint is reached |
| 716 | and the breakpoint is not disabled and any associated |
| 717 | condition evaluates to true. |
| 718 | """ |
Eric S. Raymond | 9b93c5f | 2001-02-09 07:58:53 +0000 | [diff] [blame] | 719 | args = arg.split() |
Thomas Wouters | b213704 | 2007-02-01 18:02:27 +0000 | [diff] [blame] | 720 | try: |
Eric S. Raymond | 9b93c5f | 2001-02-09 07:58:53 +0000 | [diff] [blame] | 721 | count = int(args[1].strip()) |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 722 | except: |
| 723 | count = 0 |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 724 | try: |
Georg Brandl | 7410dd1 | 2010-07-30 12:01:20 +0000 | [diff] [blame] | 725 | bp = self.get_bpbynumber(args[0].strip()) |
| 726 | except ValueError as err: |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 727 | self.error(err) |
Georg Brandl | 7410dd1 | 2010-07-30 12:01:20 +0000 | [diff] [blame] | 728 | else: |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 729 | bp.ignore = count |
Guido van Rossum | 0845459 | 2002-07-12 13:10:53 +0000 | [diff] [blame] | 730 | if count > 0: |
Guido van Rossum | 0845459 | 2002-07-12 13:10:53 +0000 | [diff] [blame] | 731 | if count > 1: |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 732 | countstr = '%d crossings' % count |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 733 | else: |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 734 | countstr = '1 crossing' |
| 735 | self.message('Will ignore next %s of breakpoint %d.' % |
| 736 | (countstr, bp.number)) |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 737 | else: |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 738 | self.message('Will stop next time breakpoint %d is reached.' |
| 739 | % bp.number) |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 740 | |
| 741 | def do_clear(self, arg): |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 742 | """cl(ear) filename:lineno\ncl(ear) [bpnumber [bpnumber...]] |
| 743 | With a space separated list of breakpoint numbers, clear |
| 744 | those breakpoints. Without argument, clear all breaks (but |
| 745 | first ask confirmation). With a filename:lineno argument, |
| 746 | clear all breaks at that line in that file. |
| 747 | """ |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 748 | if not arg: |
| 749 | try: |
Guido van Rossum | c5b6ab0 | 2007-05-27 09:19:52 +0000 | [diff] [blame] | 750 | reply = input('Clear all breaks? ') |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 751 | except EOFError: |
| 752 | reply = 'no' |
Eric S. Raymond | 9b93c5f | 2001-02-09 07:58:53 +0000 | [diff] [blame] | 753 | reply = reply.strip().lower() |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 754 | if reply in ('y', 'yes'): |
Georg Brandl | 7410dd1 | 2010-07-30 12:01:20 +0000 | [diff] [blame] | 755 | bplist = [bp for bp in bdb.Breakpoint.bpbynumber if bp] |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 756 | self.clear_all_breaks() |
Georg Brandl | 7410dd1 | 2010-07-30 12:01:20 +0000 | [diff] [blame] | 757 | for bp in bplist: |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 758 | self.message('Deleted %s' % bp) |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 759 | return |
| 760 | if ':' in arg: |
| 761 | # Make sure it works for "clear C:\foo\bar.py:12" |
Eric S. Raymond | 9b93c5f | 2001-02-09 07:58:53 +0000 | [diff] [blame] | 762 | i = arg.rfind(':') |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 763 | filename = arg[:i] |
| 764 | arg = arg[i+1:] |
| 765 | try: |
| 766 | lineno = int(arg) |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 767 | except ValueError: |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 768 | err = "Invalid line number (%s)" % arg |
| 769 | else: |
Georg Brandl | 7410dd1 | 2010-07-30 12:01:20 +0000 | [diff] [blame] | 770 | bplist = self.get_breaks(filename, lineno) |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 771 | err = self.clear_break(filename, lineno) |
Georg Brandl | 7410dd1 | 2010-07-30 12:01:20 +0000 | [diff] [blame] | 772 | if err: |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 773 | self.error(err) |
Georg Brandl | 7410dd1 | 2010-07-30 12:01:20 +0000 | [diff] [blame] | 774 | else: |
| 775 | for bp in bplist: |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 776 | self.message('Deleted %s' % bp) |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 777 | return |
Eric S. Raymond | 9b93c5f | 2001-02-09 07:58:53 +0000 | [diff] [blame] | 778 | numberlist = arg.split() |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 779 | for i in numberlist: |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 780 | try: |
Georg Brandl | 7410dd1 | 2010-07-30 12:01:20 +0000 | [diff] [blame] | 781 | bp = self.get_bpbynumber(i) |
| 782 | except ValueError as err: |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 783 | self.error(err) |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 784 | else: |
Georg Brandl | 7410dd1 | 2010-07-30 12:01:20 +0000 | [diff] [blame] | 785 | self.clear_break(bp.file, bp.line) |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 786 | self.message('Deleted %s' % bp) |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 787 | do_cl = do_clear # 'c' is already an abbreviation for 'continue' |
| 788 | |
| 789 | def do_where(self, arg): |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 790 | """w(here) |
| 791 | Print a stack trace, with the most recent frame at the bottom. |
| 792 | An arrow indicates the "current frame", which determines the |
| 793 | context of most commands. 'bt' is an alias for this command. |
| 794 | """ |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 795 | self.print_stack_trace() |
| 796 | do_w = do_where |
Guido van Rossum | 6bd6835 | 2001-01-20 17:57:37 +0000 | [diff] [blame] | 797 | do_bt = do_where |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 798 | |
Georg Brandl | eb1f4aa | 2010-06-27 10:37:48 +0000 | [diff] [blame] | 799 | def _select_frame(self, number): |
| 800 | assert 0 <= number < len(self.stack) |
| 801 | self.curindex = number |
| 802 | self.curframe = self.stack[self.curindex][0] |
| 803 | self.curframe_locals = self.curframe.f_locals |
| 804 | self.print_stack_entry(self.stack[self.curindex]) |
| 805 | self.lineno = None |
| 806 | |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 807 | def do_up(self, arg): |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 808 | """u(p) [count] |
| 809 | Move the current frame count (default one) levels up in the |
| 810 | stack trace (to an older frame). |
| 811 | """ |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 812 | if self.curindex == 0: |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 813 | self.error('Oldest frame') |
Georg Brandl | eb1f4aa | 2010-06-27 10:37:48 +0000 | [diff] [blame] | 814 | return |
| 815 | try: |
| 816 | count = int(arg or 1) |
| 817 | except ValueError: |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 818 | self.error('Invalid frame count (%s)' % arg) |
Georg Brandl | eb1f4aa | 2010-06-27 10:37:48 +0000 | [diff] [blame] | 819 | return |
| 820 | if count < 0: |
| 821 | newframe = 0 |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 822 | else: |
Georg Brandl | eb1f4aa | 2010-06-27 10:37:48 +0000 | [diff] [blame] | 823 | newframe = max(0, self.curindex - count) |
| 824 | self._select_frame(newframe) |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 825 | do_u = do_up |
| 826 | |
| 827 | def do_down(self, arg): |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 828 | """d(own) [count] |
| 829 | Move the current frame count (default one) levels down in the |
| 830 | stack trace (to a newer frame). |
| 831 | """ |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 832 | if self.curindex + 1 == len(self.stack): |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 833 | self.error('Newest frame') |
Georg Brandl | eb1f4aa | 2010-06-27 10:37:48 +0000 | [diff] [blame] | 834 | return |
| 835 | try: |
| 836 | count = int(arg or 1) |
| 837 | except ValueError: |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 838 | self.error('Invalid frame count (%s)' % arg) |
Georg Brandl | eb1f4aa | 2010-06-27 10:37:48 +0000 | [diff] [blame] | 839 | return |
| 840 | if count < 0: |
| 841 | newframe = len(self.stack) - 1 |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 842 | else: |
Georg Brandl | eb1f4aa | 2010-06-27 10:37:48 +0000 | [diff] [blame] | 843 | newframe = min(len(self.stack) - 1, self.curindex + count) |
| 844 | self._select_frame(newframe) |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 845 | do_d = do_down |
| 846 | |
Alexandre Vassalotti | 5f8ced2 | 2008-05-16 00:03:33 +0000 | [diff] [blame] | 847 | def do_until(self, arg): |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 848 | """unt(il) [lineno] |
| 849 | Without argument, continue execution until the line with a |
| 850 | number greater than the current one is reached. With a line |
| 851 | number, continue execution until a line with a number greater |
| 852 | or equal to that is reached. In both cases, also stop when |
| 853 | the current frame returns. |
| 854 | """ |
Georg Brandl | 2dfec55 | 2010-07-30 08:43:32 +0000 | [diff] [blame] | 855 | if arg: |
| 856 | try: |
| 857 | lineno = int(arg) |
| 858 | except ValueError: |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 859 | self.error('Error in argument: %r' % arg) |
Georg Brandl | 2dfec55 | 2010-07-30 08:43:32 +0000 | [diff] [blame] | 860 | return |
| 861 | if lineno <= self.curframe.f_lineno: |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 862 | self.error('"until" line number is smaller than current ' |
| 863 | 'line number') |
Georg Brandl | 2dfec55 | 2010-07-30 08:43:32 +0000 | [diff] [blame] | 864 | return |
| 865 | else: |
| 866 | lineno = None |
| 867 | self.set_until(self.curframe, lineno) |
Alexandre Vassalotti | 5f8ced2 | 2008-05-16 00:03:33 +0000 | [diff] [blame] | 868 | return 1 |
| 869 | do_unt = do_until |
| 870 | |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 871 | def do_step(self, arg): |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 872 | """s(tep) |
| 873 | Execute the current line, stop at the first possible occasion |
| 874 | (either in a function that is called or in the current |
| 875 | function). |
| 876 | """ |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 877 | self.set_step() |
| 878 | return 1 |
| 879 | do_s = do_step |
| 880 | |
| 881 | def do_next(self, arg): |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 882 | """n(ext) |
| 883 | Continue execution until the next line in the current function |
| 884 | is reached or it returns. |
| 885 | """ |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 886 | self.set_next(self.curframe) |
| 887 | return 1 |
| 888 | do_n = do_next |
| 889 | |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 890 | def do_run(self, arg): |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 891 | """run [args...] |
| 892 | Restart the debugged python program. If a string is supplied |
| 893 | it is splitted with "shlex", and the result is used as the new |
| 894 | sys.argv. History, breakpoints, actions and debugger options |
| 895 | are preserved. "restart" is an alias for "run". |
| 896 | """ |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 897 | if arg: |
| 898 | import shlex |
| 899 | argv0 = sys.argv[0:1] |
| 900 | sys.argv = shlex.split(arg) |
| 901 | sys.argv[:0] = argv0 |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 902 | # this is caught in the main debugger loop |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 903 | raise Restart |
| 904 | |
| 905 | do_restart = do_run |
| 906 | |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 907 | def do_return(self, arg): |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 908 | """r(eturn) |
| 909 | Continue execution until the current function returns. |
| 910 | """ |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 911 | self.set_return(self.curframe) |
| 912 | return 1 |
| 913 | do_r = do_return |
| 914 | |
| 915 | def do_continue(self, arg): |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 916 | """c(ont(inue)) |
| 917 | Continue execution, only stop when a breakpoint is encountered. |
| 918 | """ |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 919 | self.set_continue() |
| 920 | return 1 |
| 921 | do_c = do_cont = do_continue |
| 922 | |
Michael W. Hudson | cfd3884 | 2002-12-17 16:15:34 +0000 | [diff] [blame] | 923 | def do_jump(self, arg): |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 924 | """j(ump) lineno |
| 925 | Set the next line that will be executed. Only available in |
| 926 | the bottom-most frame. This lets you jump back and execute |
| 927 | code again, or jump forward to skip code that you don't want |
| 928 | to run. |
| 929 | |
| 930 | It should be noted that not all jumps are allowed -- for |
| 931 | instance it is not possible to jump into the middle of a |
| 932 | for loop or out of a finally clause. |
| 933 | """ |
Michael W. Hudson | cfd3884 | 2002-12-17 16:15:34 +0000 | [diff] [blame] | 934 | if self.curindex + 1 != len(self.stack): |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 935 | self.error('You can only jump within the bottom frame') |
Michael W. Hudson | cfd3884 | 2002-12-17 16:15:34 +0000 | [diff] [blame] | 936 | return |
| 937 | try: |
| 938 | arg = int(arg) |
| 939 | except ValueError: |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 940 | self.error("The 'jump' command requires a line number") |
Michael W. Hudson | cfd3884 | 2002-12-17 16:15:34 +0000 | [diff] [blame] | 941 | else: |
| 942 | try: |
| 943 | # Do the jump, fix up our copy of the stack, and display the |
| 944 | # new position |
| 945 | self.curframe.f_lineno = arg |
| 946 | self.stack[self.curindex] = self.stack[self.curindex][0], arg |
| 947 | self.print_stack_entry(self.stack[self.curindex]) |
Guido van Rossum | b940e11 | 2007-01-10 16:19:56 +0000 | [diff] [blame] | 948 | except ValueError as e: |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 949 | self.error('Jump failed: %s' % e) |
Michael W. Hudson | cfd3884 | 2002-12-17 16:15:34 +0000 | [diff] [blame] | 950 | do_j = do_jump |
| 951 | |
Guido van Rossum | a12fe4e | 2003-04-09 19:06:21 +0000 | [diff] [blame] | 952 | def do_debug(self, arg): |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 953 | """debug code |
| 954 | Enter a recursive debugger that steps through the code |
| 955 | argument (which is an arbitrary expression or statement to be |
| 956 | executed in the current environment). |
| 957 | """ |
Guido van Rossum | a12fe4e | 2003-04-09 19:06:21 +0000 | [diff] [blame] | 958 | sys.settrace(None) |
| 959 | globals = self.curframe.f_globals |
Benjamin Peterson | d23f822 | 2009-04-05 19:13:16 +0000 | [diff] [blame] | 960 | locals = self.curframe_locals |
Guido van Rossum | 7736b5b | 2008-01-15 21:44:53 +0000 | [diff] [blame] | 961 | p = Pdb(self.completekey, self.stdin, self.stdout) |
Guido van Rossum | ed538d8 | 2003-04-09 19:36:34 +0000 | [diff] [blame] | 962 | p.prompt = "(%s) " % self.prompt.strip() |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 963 | self.message("ENTERING RECURSIVE DEBUGGER") |
Guido van Rossum | ed538d8 | 2003-04-09 19:36:34 +0000 | [diff] [blame] | 964 | sys.call_tracing(p.run, (arg, globals, locals)) |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 965 | self.message("LEAVING RECURSIVE DEBUGGER") |
Guido van Rossum | a12fe4e | 2003-04-09 19:06:21 +0000 | [diff] [blame] | 966 | sys.settrace(self.trace_dispatch) |
| 967 | self.lastcmd = p.lastcmd |
| 968 | |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 969 | def do_quit(self, arg): |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 970 | """q(uit)\nexit |
| 971 | Quit from the debugger. The program being executed is aborted. |
| 972 | """ |
Johannes Gijsbers | 25b38c8 | 2004-10-12 18:12:09 +0000 | [diff] [blame] | 973 | self._user_requested_quit = 1 |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 974 | self.set_quit() |
| 975 | return 1 |
Johannes Gijsbers | 25b38c8 | 2004-10-12 18:12:09 +0000 | [diff] [blame] | 976 | |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 977 | do_q = do_quit |
Guido van Rossum | d1c08f3 | 2002-04-15 00:48:24 +0000 | [diff] [blame] | 978 | do_exit = do_quit |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 979 | |
Guido van Rossum | eef2607 | 2003-01-13 21:13:55 +0000 | [diff] [blame] | 980 | def do_EOF(self, arg): |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 981 | """EOF |
| 982 | Handles the receipt of EOF as a command. |
| 983 | """ |
| 984 | self.message('') |
Johannes Gijsbers | 25b38c8 | 2004-10-12 18:12:09 +0000 | [diff] [blame] | 985 | self._user_requested_quit = 1 |
Guido van Rossum | eef2607 | 2003-01-13 21:13:55 +0000 | [diff] [blame] | 986 | self.set_quit() |
| 987 | return 1 |
| 988 | |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 989 | def do_args(self, arg): |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 990 | """a(rgs) |
| 991 | Print the argument list of the current function. |
| 992 | """ |
Benjamin Peterson | d23f822 | 2009-04-05 19:13:16 +0000 | [diff] [blame] | 993 | co = self.curframe.f_code |
| 994 | dict = self.curframe_locals |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 995 | n = co.co_argcount |
| 996 | if co.co_flags & 4: n = n+1 |
| 997 | if co.co_flags & 8: n = n+1 |
| 998 | for i in range(n): |
| 999 | name = co.co_varnames[i] |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 1000 | if name in dict: |
| 1001 | self.message('%s = %r' % (name, dict[name])) |
| 1002 | else: |
| 1003 | self.message('%s = *** undefined ***' % (name,)) |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 1004 | do_a = do_args |
Guido van Rossum | 2424f85 | 1998-09-11 22:50:09 +0000 | [diff] [blame] | 1005 | |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 1006 | def do_retval(self, arg): |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 1007 | """retval |
| 1008 | Print the return value for the last return of a function. |
| 1009 | """ |
Benjamin Peterson | d23f822 | 2009-04-05 19:13:16 +0000 | [diff] [blame] | 1010 | if '__return__' in self.curframe_locals: |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 1011 | self.message(repr(self.curframe_locals['__return__'])) |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 1012 | else: |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 1013 | self.error('Not yet returned!') |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 1014 | do_rv = do_retval |
Guido van Rossum | 2424f85 | 1998-09-11 22:50:09 +0000 | [diff] [blame] | 1015 | |
Barry Warsaw | 210bd20 | 2002-11-05 22:40:20 +0000 | [diff] [blame] | 1016 | def _getval(self, arg): |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 1017 | try: |
Benjamin Peterson | d23f822 | 2009-04-05 19:13:16 +0000 | [diff] [blame] | 1018 | return eval(arg, self.curframe.f_globals, self.curframe_locals) |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 1019 | except: |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 1020 | exc_info = sys.exc_info()[:2] |
| 1021 | self.error(traceback.format_exception_only(*exc_info)[-1].strip()) |
Barry Warsaw | 210bd20 | 2002-11-05 22:40:20 +0000 | [diff] [blame] | 1022 | raise |
Guido van Rossum | 2424f85 | 1998-09-11 22:50:09 +0000 | [diff] [blame] | 1023 | |
Barry Warsaw | 210bd20 | 2002-11-05 22:40:20 +0000 | [diff] [blame] | 1024 | def do_p(self, arg): |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 1025 | """p(rint) expression |
| 1026 | Print the value of the expression. |
| 1027 | """ |
Barry Warsaw | 210bd20 | 2002-11-05 22:40:20 +0000 | [diff] [blame] | 1028 | try: |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 1029 | self.message(repr(self._getval(arg))) |
Barry Warsaw | 210bd20 | 2002-11-05 22:40:20 +0000 | [diff] [blame] | 1030 | except: |
| 1031 | pass |
Georg Brandl | c987924 | 2007-09-04 07:07:56 +0000 | [diff] [blame] | 1032 | # make "print" an alias of "p" since print isn't a Python statement anymore |
| 1033 | do_print = do_p |
Barry Warsaw | 210bd20 | 2002-11-05 22:40:20 +0000 | [diff] [blame] | 1034 | |
| 1035 | def do_pp(self, arg): |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 1036 | """pp expression |
| 1037 | Pretty-print the value of the expression. |
| 1038 | """ |
Barry Warsaw | 210bd20 | 2002-11-05 22:40:20 +0000 | [diff] [blame] | 1039 | try: |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 1040 | self.message(pprint.pformat(self._getval(arg))) |
Barry Warsaw | 210bd20 | 2002-11-05 22:40:20 +0000 | [diff] [blame] | 1041 | except: |
| 1042 | pass |
Guido van Rossum | 2424f85 | 1998-09-11 22:50:09 +0000 | [diff] [blame] | 1043 | |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 1044 | def do_list(self, arg): |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 1045 | """l(ist) [first [,last] | .] |
Georg Brandl | 0a9c3e9 | 2010-07-30 18:46:38 +0000 | [diff] [blame] | 1046 | |
| 1047 | List source code for the current file. Without arguments, |
| 1048 | list 11 lines around the current line or continue the previous |
| 1049 | listing. With . as argument, list 11 lines around the current |
| 1050 | line. With one argument, list 11 lines starting at that line. |
| 1051 | With two arguments, list the given range; if the second |
| 1052 | argument is less than the first, it is a count. |
| 1053 | |
| 1054 | The current line in the current frame is indicated by "->". |
| 1055 | If an exception is being debugged, the line where the |
| 1056 | exception was originally raised or propagated is indicated by |
| 1057 | ">>", if it differs from the current line. |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 1058 | """ |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 1059 | self.lastcmd = 'list' |
| 1060 | last = None |
Georg Brandl | a91a94b | 2010-07-30 07:14:01 +0000 | [diff] [blame] | 1061 | if arg and arg != '.': |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 1062 | try: |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 1063 | if ',' in arg: |
| 1064 | first, last = arg.split(',') |
| 1065 | first = int(first.strip()) |
| 1066 | last = int(last.strip()) |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 1067 | if last < first: |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 1068 | # assume it's a count |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 1069 | last = first + last |
| 1070 | else: |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 1071 | first = int(arg.strip()) |
| 1072 | first = max(1, first - 5) |
| 1073 | except ValueError: |
| 1074 | self.error('Error in argument: %r' % arg) |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 1075 | return |
Georg Brandl | a91a94b | 2010-07-30 07:14:01 +0000 | [diff] [blame] | 1076 | elif self.lineno is None or arg == '.': |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 1077 | first = max(1, self.curframe.f_lineno - 5) |
| 1078 | else: |
| 1079 | first = self.lineno + 1 |
| 1080 | if last is None: |
| 1081 | last = first + 10 |
| 1082 | filename = self.curframe.f_code.co_filename |
| 1083 | breaklist = self.get_file_breaks(filename) |
| 1084 | try: |
Georg Brandl | e59ca2a | 2010-07-30 17:04:28 +0000 | [diff] [blame] | 1085 | lines = linecache.getlines(filename, self.curframe.f_globals) |
| 1086 | self._print_lines(lines[first-1:last], first, breaklist, |
Georg Brandl | 0a9c3e9 | 2010-07-30 18:46:38 +0000 | [diff] [blame] | 1087 | self.curframe) |
Georg Brandl | e59ca2a | 2010-07-30 17:04:28 +0000 | [diff] [blame] | 1088 | self.lineno = min(last, len(lines)) |
| 1089 | if len(lines) < last: |
| 1090 | self.message('[EOF]') |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 1091 | except KeyboardInterrupt: |
| 1092 | pass |
| 1093 | do_l = do_list |
Guido van Rossum | 2424f85 | 1998-09-11 22:50:09 +0000 | [diff] [blame] | 1094 | |
Georg Brandl | e59ca2a | 2010-07-30 17:04:28 +0000 | [diff] [blame] | 1095 | def do_longlist(self, arg): |
| 1096 | """longlist | ll |
| 1097 | List the whole source code for the current function or frame. |
| 1098 | """ |
| 1099 | filename = self.curframe.f_code.co_filename |
| 1100 | breaklist = self.get_file_breaks(filename) |
| 1101 | try: |
Georg Brandl | 5ed2b5a | 2010-07-30 18:08:12 +0000 | [diff] [blame] | 1102 | lines, lineno = getsourcelines(self.curframe) |
Georg Brandl | e59ca2a | 2010-07-30 17:04:28 +0000 | [diff] [blame] | 1103 | except IOError as err: |
| 1104 | self.error(err) |
| 1105 | return |
Georg Brandl | 0a9c3e9 | 2010-07-30 18:46:38 +0000 | [diff] [blame] | 1106 | self._print_lines(lines, lineno, breaklist, self.curframe) |
Georg Brandl | e59ca2a | 2010-07-30 17:04:28 +0000 | [diff] [blame] | 1107 | do_ll = do_longlist |
| 1108 | |
| 1109 | def do_source(self, arg): |
| 1110 | """source expression |
| 1111 | Try to get source code for the given object and display it. |
| 1112 | """ |
| 1113 | try: |
| 1114 | obj = self._getval(arg) |
| 1115 | except: |
| 1116 | return |
| 1117 | try: |
Georg Brandl | 5ed2b5a | 2010-07-30 18:08:12 +0000 | [diff] [blame] | 1118 | lines, lineno = getsourcelines(obj) |
Georg Brandl | e59ca2a | 2010-07-30 17:04:28 +0000 | [diff] [blame] | 1119 | except (IOError, TypeError) as err: |
| 1120 | self.error(err) |
| 1121 | return |
Georg Brandl | 0a9c3e9 | 2010-07-30 18:46:38 +0000 | [diff] [blame] | 1122 | self._print_lines(lines, lineno) |
Georg Brandl | e59ca2a | 2010-07-30 17:04:28 +0000 | [diff] [blame] | 1123 | |
Georg Brandl | 0a9c3e9 | 2010-07-30 18:46:38 +0000 | [diff] [blame] | 1124 | def _print_lines(self, lines, start, breaks=(), frame=None): |
Georg Brandl | e59ca2a | 2010-07-30 17:04:28 +0000 | [diff] [blame] | 1125 | """Print a range of lines.""" |
Georg Brandl | 0a9c3e9 | 2010-07-30 18:46:38 +0000 | [diff] [blame] | 1126 | if frame: |
| 1127 | current_lineno = frame.f_lineno |
| 1128 | exc_lineno = self.tb_lineno.get(frame, -1) |
| 1129 | else: |
| 1130 | current_lineno = exc_lineno = -1 |
Georg Brandl | e59ca2a | 2010-07-30 17:04:28 +0000 | [diff] [blame] | 1131 | for lineno, line in enumerate(lines, start): |
| 1132 | s = str(lineno).rjust(3) |
| 1133 | if len(s) < 4: |
| 1134 | s += ' ' |
| 1135 | if lineno in breaks: |
| 1136 | s += 'B' |
| 1137 | else: |
| 1138 | s += ' ' |
Georg Brandl | 0a9c3e9 | 2010-07-30 18:46:38 +0000 | [diff] [blame] | 1139 | if lineno == current_lineno: |
Georg Brandl | e59ca2a | 2010-07-30 17:04:28 +0000 | [diff] [blame] | 1140 | s += '->' |
Georg Brandl | 0a9c3e9 | 2010-07-30 18:46:38 +0000 | [diff] [blame] | 1141 | elif lineno == exc_lineno: |
Georg Brandl | e59ca2a | 2010-07-30 17:04:28 +0000 | [diff] [blame] | 1142 | s += '>>' |
| 1143 | self.message(s + '\t' + line.rstrip()) |
| 1144 | |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 1145 | def do_whatis(self, arg): |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 1146 | """whatis arg |
| 1147 | Print the type of the argument. |
| 1148 | """ |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 1149 | try: |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 1150 | value = self._getval(arg) |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 1151 | except: |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 1152 | # _getval() already printed the error |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 1153 | return |
| 1154 | code = None |
| 1155 | # Is it a function? |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 1156 | try: |
| 1157 | code = value.__code__ |
| 1158 | except Exception: |
| 1159 | pass |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 1160 | if code: |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 1161 | self.message('Function %s' % code.co_name) |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 1162 | return |
| 1163 | # Is it an instance method? |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 1164 | try: |
| 1165 | code = value.__func__.__code__ |
| 1166 | except Exception: |
| 1167 | pass |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 1168 | if code: |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 1169 | self.message('Method %s' % code.co_name) |
| 1170 | return |
| 1171 | # Is it a class? |
| 1172 | if value.__class__ is type: |
| 1173 | self.message('Class %s.%s' % (value.__module__, value.__name__)) |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 1174 | return |
| 1175 | # None of the above... |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 1176 | self.message(type(value)) |
Guido van Rossum | 8e2ec56 | 1993-07-29 09:37:38 +0000 | [diff] [blame] | 1177 | |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 1178 | def do_alias(self, arg): |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 1179 | """alias [name [command [parameter parameter ...] ]] |
| 1180 | Create an alias called 'name' that executes 'command'. The |
| 1181 | command must *not* be enclosed in quotes. Replaceable |
| 1182 | parameters can be indicated by %1, %2, and so on, while %* is |
| 1183 | replaced by all the parameters. If no command is given, the |
| 1184 | current alias for name is shown. If no name is given, all |
| 1185 | aliases are listed. |
| 1186 | |
| 1187 | Aliases may be nested and can contain anything that can be |
| 1188 | legally typed at the pdb prompt. Note! You *can* override |
| 1189 | internal pdb commands with aliases! Those internal commands |
| 1190 | are then hidden until the alias is removed. Aliasing is |
| 1191 | recursively applied to the first word of the command line; all |
| 1192 | other words in the line are left alone. |
| 1193 | |
| 1194 | As an example, here are two useful aliases (especially when |
| 1195 | placed in the .pdbrc file): |
| 1196 | |
| 1197 | # Print instance variables (usage "pi classInst") |
| 1198 | alias pi for k in %1.__dict__.keys(): print "%1.",k,"=",%1.__dict__[k] |
| 1199 | # Print instance variables in self |
| 1200 | alias ps pi self |
| 1201 | """ |
Eric S. Raymond | 9b93c5f | 2001-02-09 07:58:53 +0000 | [diff] [blame] | 1202 | args = arg.split() |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 1203 | if len(args) == 0: |
Benjamin Peterson | be74a37 | 2009-09-11 21:17:13 +0000 | [diff] [blame] | 1204 | keys = sorted(self.aliases.keys()) |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 1205 | for alias in keys: |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 1206 | self.message("%s = %s" % (alias, self.aliases[alias])) |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 1207 | return |
Guido van Rossum | 0845459 | 2002-07-12 13:10:53 +0000 | [diff] [blame] | 1208 | if args[0] in self.aliases and len(args) == 1: |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 1209 | self.message("%s = %s" % (args[0], self.aliases[args[0]])) |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 1210 | else: |
Eric S. Raymond | 9b93c5f | 2001-02-09 07:58:53 +0000 | [diff] [blame] | 1211 | self.aliases[args[0]] = ' '.join(args[1:]) |
Guido van Rossum | 23efba4 | 1992-01-27 16:58:47 +0000 | [diff] [blame] | 1212 | |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 1213 | def do_unalias(self, arg): |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 1214 | """unalias name |
| 1215 | Delete the specified alias. |
| 1216 | """ |
Eric S. Raymond | 9b93c5f | 2001-02-09 07:58:53 +0000 | [diff] [blame] | 1217 | args = arg.split() |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 1218 | if len(args) == 0: return |
Raymond Hettinger | 54f0222 | 2002-06-01 14:18:47 +0000 | [diff] [blame] | 1219 | if args[0] in self.aliases: |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 1220 | del self.aliases[args[0]] |
Guido van Rossum | 0023078 | 1993-03-29 11:39:45 +0000 | [diff] [blame] | 1221 | |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 1222 | # List of all the commands making the program resume execution. |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 1223 | commands_resuming = ['do_continue', 'do_step', 'do_next', 'do_return', |
| 1224 | 'do_quit', 'do_jump'] |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 1225 | |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 1226 | # Print a traceback starting at the top stack frame. |
| 1227 | # The most recently entered frame is printed last; |
| 1228 | # this is different from dbx and gdb, but consistent with |
| 1229 | # the Python interpreter's stack trace. |
| 1230 | # It is also consistent with the up/down commands (which are |
| 1231 | # compatible with dbx and gdb: up moves towards 'main()' |
| 1232 | # and down moves towards the most recent stack frame). |
Guido van Rossum | 2424f85 | 1998-09-11 22:50:09 +0000 | [diff] [blame] | 1233 | |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 1234 | def print_stack_trace(self): |
| 1235 | try: |
| 1236 | for frame_lineno in self.stack: |
| 1237 | self.print_stack_entry(frame_lineno) |
| 1238 | except KeyboardInterrupt: |
| 1239 | pass |
Guido van Rossum | 2424f85 | 1998-09-11 22:50:09 +0000 | [diff] [blame] | 1240 | |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 1241 | def print_stack_entry(self, frame_lineno, prompt_prefix=line_prefix): |
| 1242 | frame, lineno = frame_lineno |
| 1243 | if frame is self.curframe: |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 1244 | prefix = '> ' |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 1245 | else: |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 1246 | prefix = ' ' |
| 1247 | self.message(prefix + |
| 1248 | self.format_stack_entry(frame_lineno, prompt_prefix)) |
Guido van Rossum | 2424f85 | 1998-09-11 22:50:09 +0000 | [diff] [blame] | 1249 | |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 1250 | # Provide help |
Guido van Rossum | 921c824 | 1992-01-10 14:54:42 +0000 | [diff] [blame] | 1251 | |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 1252 | def do_help(self, arg): |
| 1253 | """h(elp) |
| 1254 | Without argument, print the list of available commands. |
| 1255 | With a command name as argument, print help about that command. |
| 1256 | "help pdb" shows the full pdb documentation. |
| 1257 | "help exec" gives help on the ! command. |
| 1258 | """ |
| 1259 | if not arg: |
| 1260 | return cmd.Cmd.do_help(self, arg) |
| 1261 | try: |
| 1262 | try: |
| 1263 | topic = getattr(self, 'help_' + arg) |
| 1264 | return topic() |
| 1265 | except AttributeError: |
| 1266 | command = getattr(self, 'do_' + arg) |
| 1267 | except AttributeError: |
| 1268 | self.error('No help for %r' % arg) |
| 1269 | else: |
| 1270 | self.message(command.__doc__.rstrip()) |
Guido van Rossum | 921c824 | 1992-01-10 14:54:42 +0000 | [diff] [blame] | 1271 | |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 1272 | do_h = do_help |
Barry Warsaw | 210bd20 | 2002-11-05 22:40:20 +0000 | [diff] [blame] | 1273 | |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 1274 | def help_exec(self): |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 1275 | """(!) statement |
| 1276 | Execute the (one-line) statement in the context of the current |
| 1277 | stack frame. The exclamation point can be omitted unless the |
| 1278 | first word of the statement resembles a debugger command. To |
| 1279 | assign to a global variable you must always prefix the command |
| 1280 | with a 'global' command, e.g.: |
| 1281 | (Pdb) global list_options; list_options = ['-l'] |
| 1282 | (Pdb) |
| 1283 | """ |
| 1284 | self.message(self.help_exec.__doc__.strip()) |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 1285 | |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 1286 | def help_pdb(self): |
| 1287 | help() |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 1288 | |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 1289 | # other helper functions |
| 1290 | |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 1291 | def lookupmodule(self, filename): |
Johannes Gijsbers | 25b38c8 | 2004-10-12 18:12:09 +0000 | [diff] [blame] | 1292 | """Helper function for break/clear parsing -- may be overridden. |
| 1293 | |
| 1294 | lookupmodule() translates (possibly incomplete) file or module name |
| 1295 | into an absolute file name. |
| 1296 | """ |
| 1297 | if os.path.isabs(filename) and os.path.exists(filename): |
Tim Peters | e718f61 | 2004-10-12 21:51:32 +0000 | [diff] [blame] | 1298 | return filename |
Johannes Gijsbers | 25b38c8 | 2004-10-12 18:12:09 +0000 | [diff] [blame] | 1299 | f = os.path.join(sys.path[0], filename) |
| 1300 | if os.path.exists(f) and self.canonic(f) == self.mainpyfile: |
| 1301 | return f |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 1302 | root, ext = os.path.splitext(filename) |
| 1303 | if ext == '': |
| 1304 | filename = filename + '.py' |
| 1305 | if os.path.isabs(filename): |
| 1306 | return filename |
| 1307 | for dirname in sys.path: |
| 1308 | while os.path.islink(dirname): |
| 1309 | dirname = os.readlink(dirname) |
| 1310 | fullname = os.path.join(dirname, filename) |
| 1311 | if os.path.exists(fullname): |
| 1312 | return fullname |
| 1313 | return None |
Guido van Rossum | b5699c7 | 1998-07-20 23:13:54 +0000 | [diff] [blame] | 1314 | |
Johannes Gijsbers | 25b38c8 | 2004-10-12 18:12:09 +0000 | [diff] [blame] | 1315 | def _runscript(self, filename): |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 1316 | # The script has to run in __main__ namespace (or imports from |
| 1317 | # __main__ will break). |
| 1318 | # |
| 1319 | # So we clear up the __main__ and set several special variables |
| 1320 | # (this gets rid of pdb's globals and cleans old variables on restarts). |
| 1321 | import __main__ |
| 1322 | __main__.__dict__.clear() |
| 1323 | __main__.__dict__.update({"__name__" : "__main__", |
| 1324 | "__file__" : filename, |
| 1325 | "__builtins__": __builtins__, |
| 1326 | }) |
Johannes Gijsbers | 25b38c8 | 2004-10-12 18:12:09 +0000 | [diff] [blame] | 1327 | |
| 1328 | # When bdb sets tracing, a number of call and line events happens |
| 1329 | # BEFORE debugger even reaches user's code (and the exact sequence of |
| 1330 | # events depends on python version). So we take special measures to |
| 1331 | # avoid stopping before we reach the main script (see user_line and |
| 1332 | # user_call for details). |
| 1333 | self._wait_for_mainpyfile = 1 |
| 1334 | self.mainpyfile = self.canonic(filename) |
| 1335 | self._user_requested_quit = 0 |
Georg Brandl | d07ac64 | 2009-08-13 07:50:57 +0000 | [diff] [blame] | 1336 | with open(filename, "rb") as fp: |
| 1337 | statement = "exec(compile(%r, %r, 'exec'))" % \ |
| 1338 | (fp.read(), self.mainpyfile) |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 1339 | self.run(statement) |
Johannes Gijsbers | 25b38c8 | 2004-10-12 18:12:09 +0000 | [diff] [blame] | 1340 | |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 1341 | # Collect all command help into docstring |
| 1342 | |
| 1343 | # unfortunately we can't guess this order from the class definition |
| 1344 | _help_order = [ |
| 1345 | 'help', 'where', 'down', 'up', 'break', 'tbreak', 'clear', 'disable', |
| 1346 | 'enable', 'ignore', 'condition', 'commands', 'step', 'next', 'until', |
Georg Brandl | e59ca2a | 2010-07-30 17:04:28 +0000 | [diff] [blame] | 1347 | 'jump', 'return', 'retval', 'run', 'continue', 'list', 'longlist', |
| 1348 | 'args', 'print', 'pp', 'whatis', 'source', 'alias', 'unalias', |
| 1349 | 'debug', 'quit', |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 1350 | ] |
| 1351 | |
Georg Brandl | e59ca2a | 2010-07-30 17:04:28 +0000 | [diff] [blame] | 1352 | docs = set() |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 1353 | for _command in _help_order: |
| 1354 | __doc__ += getattr(Pdb, 'do_' + _command).__doc__.strip() + '\n\n' |
| 1355 | __doc__ += Pdb.help_exec.__doc__ |
| 1356 | |
| 1357 | del _help_order, _command |
| 1358 | |
Guido van Rossum | 3577113 | 1992-09-08 11:59:04 +0000 | [diff] [blame] | 1359 | # Simplified interface |
| 1360 | |
Guido van Rossum | 5e38b6f | 1995-02-27 13:13:40 +0000 | [diff] [blame] | 1361 | def run(statement, globals=None, locals=None): |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 1362 | Pdb().run(statement, globals, locals) |
Guido van Rossum | 5e38b6f | 1995-02-27 13:13:40 +0000 | [diff] [blame] | 1363 | |
| 1364 | def runeval(expression, globals=None, locals=None): |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 1365 | return Pdb().runeval(expression, globals, locals) |
Guido van Rossum | 6fe08b0 | 1992-01-16 13:50:21 +0000 | [diff] [blame] | 1366 | |
| 1367 | def runctx(statement, globals, locals): |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 1368 | # B/W compatibility |
| 1369 | run(statement, globals, locals) |
Guido van Rossum | 6fe08b0 | 1992-01-16 13:50:21 +0000 | [diff] [blame] | 1370 | |
Raymond Hettinger | 2ef7e6c | 2004-10-24 00:32:24 +0000 | [diff] [blame] | 1371 | def runcall(*args, **kwds): |
| 1372 | return Pdb().runcall(*args, **kwds) |
Guido van Rossum | 4e16098 | 1992-09-02 20:43:20 +0000 | [diff] [blame] | 1373 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 1374 | def set_trace(): |
Johannes Gijsbers | 84a6c20 | 2004-11-07 11:35:30 +0000 | [diff] [blame] | 1375 | Pdb().set_trace(sys._getframe().f_back) |
Guido van Rossum | 3577113 | 1992-09-08 11:59:04 +0000 | [diff] [blame] | 1376 | |
| 1377 | # Post-Mortem interface |
| 1378 | |
Christian Heimes | dd15f6c | 2008-03-16 00:07:10 +0000 | [diff] [blame] | 1379 | def post_mortem(t=None): |
| 1380 | # handling the default |
| 1381 | if t is None: |
| 1382 | # sys.exc_info() returns (type, value, traceback) if an exception is |
| 1383 | # being handled, otherwise it returns None |
| 1384 | t = sys.exc_info()[2] |
Georg Brandl | 0d08962 | 2010-07-30 16:00:46 +0000 | [diff] [blame] | 1385 | if t is None: |
| 1386 | raise ValueError("A valid traceback must be passed if no " |
| 1387 | "exception is being handled") |
Christian Heimes | dd15f6c | 2008-03-16 00:07:10 +0000 | [diff] [blame] | 1388 | |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 1389 | p = Pdb() |
| 1390 | p.reset() |
Benjamin Peterson | 1a6e0d0 | 2008-10-25 15:49:17 +0000 | [diff] [blame] | 1391 | p.interaction(None, t) |
Guido van Rossum | 3577113 | 1992-09-08 11:59:04 +0000 | [diff] [blame] | 1392 | |
| 1393 | def pm(): |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 1394 | post_mortem(sys.last_traceback) |
Guido van Rossum | 3577113 | 1992-09-08 11:59:04 +0000 | [diff] [blame] | 1395 | |
| 1396 | |
| 1397 | # Main program for testing |
| 1398 | |
Guido van Rossum | 23efba4 | 1992-01-27 16:58:47 +0000 | [diff] [blame] | 1399 | TESTCMD = 'import x; x.main()' |
Guido van Rossum | 6fe08b0 | 1992-01-16 13:50:21 +0000 | [diff] [blame] | 1400 | |
Guido van Rossum | 921c824 | 1992-01-10 14:54:42 +0000 | [diff] [blame] | 1401 | def test(): |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 1402 | run(TESTCMD) |
Guido van Rossum | e61fa0a | 1993-10-22 13:56:35 +0000 | [diff] [blame] | 1403 | |
| 1404 | # print help |
| 1405 | def help(): |
Georg Brandl | 02053ee | 2010-07-18 10:11:03 +0000 | [diff] [blame] | 1406 | import pydoc |
| 1407 | pydoc.pager(__doc__) |
Guido van Rossum | f17361d | 1996-07-30 16:28:13 +0000 | [diff] [blame] | 1408 | |
Georg Brandl | e023091 | 2010-07-30 08:29:39 +0000 | [diff] [blame] | 1409 | _usage = """\ |
| 1410 | usage: pdb.py [-c command] ... pyfile [arg] ... |
| 1411 | |
| 1412 | Debug the Python program given by pyfile. |
| 1413 | |
| 1414 | Initial commands are read from .pdbrc files in your home directory |
| 1415 | and in the current directory, if they exist. Commands supplied with |
| 1416 | -c are executed after commands from .pdbrc files. |
| 1417 | |
| 1418 | To let the script run until an exception occurs, use "-c continue". |
Georg Brandl | 2dfec55 | 2010-07-30 08:43:32 +0000 | [diff] [blame] | 1419 | To let the script run up to a given line X in the debugged file, use |
| 1420 | "-c 'until X'".""" |
Georg Brandl | e023091 | 2010-07-30 08:29:39 +0000 | [diff] [blame] | 1421 | |
Johannes Gijsbers | 25b38c8 | 2004-10-12 18:12:09 +0000 | [diff] [blame] | 1422 | def main(): |
Georg Brandl | e023091 | 2010-07-30 08:29:39 +0000 | [diff] [blame] | 1423 | import getopt |
| 1424 | |
| 1425 | opts, args = getopt.getopt(sys.argv[1:], 'hc:', ['--help', '--command=']) |
| 1426 | |
| 1427 | if not args: |
| 1428 | print(_usage) |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 1429 | sys.exit(2) |
Guido van Rossum | f17361d | 1996-07-30 16:28:13 +0000 | [diff] [blame] | 1430 | |
Georg Brandl | e023091 | 2010-07-30 08:29:39 +0000 | [diff] [blame] | 1431 | commands = [] |
| 1432 | for opt, optarg in opts: |
| 1433 | if opt in ['-h', '--help']: |
| 1434 | print(_usage) |
| 1435 | sys.exit() |
| 1436 | elif opt in ['-c', '--command']: |
| 1437 | commands.append(optarg) |
| 1438 | |
| 1439 | mainpyfile = args[0] # Get script filename |
Johannes Gijsbers | 25b38c8 | 2004-10-12 18:12:09 +0000 | [diff] [blame] | 1440 | if not os.path.exists(mainpyfile): |
Guido van Rossum | be19ed7 | 2007-02-09 05:37:30 +0000 | [diff] [blame] | 1441 | print('Error:', mainpyfile, 'does not exist') |
Tim Peters | 2344fae | 2001-01-15 00:50:52 +0000 | [diff] [blame] | 1442 | sys.exit(1) |
Johannes Gijsbers | 25b38c8 | 2004-10-12 18:12:09 +0000 | [diff] [blame] | 1443 | |
Georg Brandl | e023091 | 2010-07-30 08:29:39 +0000 | [diff] [blame] | 1444 | sys.argv[:] = args # Hide "pdb.py" and pdb options from argument list |
Guido van Rossum | ec577d5 | 1996-09-10 17:39:34 +0000 | [diff] [blame] | 1445 | |
Johannes Gijsbers | 25b38c8 | 2004-10-12 18:12:09 +0000 | [diff] [blame] | 1446 | # Replace pdb's dir with script's dir in front of module search path. |
| 1447 | sys.path[0] = os.path.dirname(mainpyfile) |
Guido van Rossum | f17361d | 1996-07-30 16:28:13 +0000 | [diff] [blame] | 1448 | |
Johannes Gijsbers | 25b38c8 | 2004-10-12 18:12:09 +0000 | [diff] [blame] | 1449 | # Note on saving/restoring sys.argv: it's a good idea when sys.argv was |
| 1450 | # modified by the script being debugged. It's a bad idea when it was |
Georg Brandl | 3078df0 | 2009-05-05 09:11:31 +0000 | [diff] [blame] | 1451 | # changed by the user from the command line. There is a "restart" command |
| 1452 | # which allows explicit specification of command line arguments. |
Johannes Gijsbers | 25b38c8 | 2004-10-12 18:12:09 +0000 | [diff] [blame] | 1453 | pdb = Pdb() |
Georg Brandl | e023091 | 2010-07-30 08:29:39 +0000 | [diff] [blame] | 1454 | pdb.rcLines.extend(commands) |
Georg Brandl | 1e30bd3 | 2010-07-30 07:21:26 +0000 | [diff] [blame] | 1455 | while True: |
Johannes Gijsbers | 25b38c8 | 2004-10-12 18:12:09 +0000 | [diff] [blame] | 1456 | try: |
| 1457 | pdb._runscript(mainpyfile) |
| 1458 | if pdb._user_requested_quit: |
| 1459 | break |
Guido van Rossum | be19ed7 | 2007-02-09 05:37:30 +0000 | [diff] [blame] | 1460 | print("The program finished and will be restarted") |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 1461 | except Restart: |
| 1462 | print("Restarting", mainpyfile, "with arguments:") |
Georg Brandl | e023091 | 2010-07-30 08:29:39 +0000 | [diff] [blame] | 1463 | print("\t" + " ".join(args)) |
Johannes Gijsbers | 25b38c8 | 2004-10-12 18:12:09 +0000 | [diff] [blame] | 1464 | except SystemExit: |
| 1465 | # In most cases SystemExit does not warrant a post-mortem session. |
Georg Brandl | e023091 | 2010-07-30 08:29:39 +0000 | [diff] [blame] | 1466 | print("The program exited via sys.exit(). Exit status:", end=' ') |
Guido van Rossum | be19ed7 | 2007-02-09 05:37:30 +0000 | [diff] [blame] | 1467 | print(sys.exc_info()[1]) |
Johannes Gijsbers | 25b38c8 | 2004-10-12 18:12:09 +0000 | [diff] [blame] | 1468 | except: |
| 1469 | traceback.print_exc() |
Guido van Rossum | be19ed7 | 2007-02-09 05:37:30 +0000 | [diff] [blame] | 1470 | print("Uncaught exception. Entering post mortem debugging") |
| 1471 | print("Running 'cont' or 'step' will restart the program") |
Johannes Gijsbers | 25b38c8 | 2004-10-12 18:12:09 +0000 | [diff] [blame] | 1472 | t = sys.exc_info()[2] |
Benjamin Peterson | 1a6e0d0 | 2008-10-25 15:49:17 +0000 | [diff] [blame] | 1473 | pdb.interaction(None, t) |
Georg Brandl | 3078df0 | 2009-05-05 09:11:31 +0000 | [diff] [blame] | 1474 | print("Post mortem debugger finished. The " + mainpyfile + |
| 1475 | " will be restarted") |
Johannes Gijsbers | 25b38c8 | 2004-10-12 18:12:09 +0000 | [diff] [blame] | 1476 | |
| 1477 | |
| 1478 | # When invoked as main program, invoke the debugger on a script |
Guido van Rossum | d8faa36 | 2007-04-27 19:54:29 +0000 | [diff] [blame] | 1479 | if __name__ == '__main__': |
| 1480 | import pdb |
| 1481 | pdb.main() |