Guido van Rossum | babe2bf | 1992-01-22 22:21:31 +0000 | [diff] [blame] | 1 | # A generic Python debugger base class. |
| 2 | # This class takes care of details of the trace facility; |
| 3 | # a derived class should implement user interaction. |
| 4 | # There are two debuggers based upon this: |
| 5 | # 'pdb', a text-oriented debugger not unlike dbx or gdb; |
| 6 | # and 'wdb', a window-oriented debugger. |
| 7 | # And of course... you can roll your own! |
| 8 | |
| 9 | import sys |
Guido van Rossum | 4808dcb | 1996-10-15 14:40:21 +0000 | [diff] [blame] | 10 | import types |
Guido van Rossum | babe2bf | 1992-01-22 22:21:31 +0000 | [diff] [blame] | 11 | |
| 12 | BdbQuit = 'bdb.BdbQuit' # Exception to give up completely |
| 13 | |
| 14 | |
| 15 | class Bdb: # Basic Debugger |
| 16 | |
Guido van Rossum | 5ef74b8 | 1993-06-23 11:55:24 +0000 | [diff] [blame] | 17 | def __init__(self): |
Guido van Rossum | babe2bf | 1992-01-22 22:21:31 +0000 | [diff] [blame] | 18 | self.breaks = {} |
Guido van Rossum | ff02e1d | 1997-07-11 13:42:50 +0000 | [diff] [blame^] | 19 | self.cbreaks = {} |
Guido van Rossum | babe2bf | 1992-01-22 22:21:31 +0000 | [diff] [blame] | 20 | |
| 21 | def reset(self): |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 22 | import linecache |
| 23 | linecache.checkcache() |
Guido van Rossum | babe2bf | 1992-01-22 22:21:31 +0000 | [diff] [blame] | 24 | self.botframe = None |
| 25 | self.stopframe = None |
| 26 | self.returnframe = None |
| 27 | self.quitting = 0 |
| 28 | |
| 29 | def trace_dispatch(self, frame, event, arg): |
| 30 | if self.quitting: |
| 31 | return # None |
| 32 | if event == 'line': |
| 33 | return self.dispatch_line(frame) |
| 34 | if event == 'call': |
| 35 | return self.dispatch_call(frame, arg) |
| 36 | if event == 'return': |
| 37 | return self.dispatch_return(frame, arg) |
| 38 | if event == 'exception': |
| 39 | return self.dispatch_exception(frame, arg) |
| 40 | print 'bdb.Bdb.dispatch: unknown debugging event:', `event` |
| 41 | return self.trace_dispatch |
| 42 | |
| 43 | def dispatch_line(self, frame): |
| 44 | if self.stop_here(frame) or self.break_here(frame): |
| 45 | self.user_line(frame) |
| 46 | if self.quitting: raise BdbQuit |
| 47 | return self.trace_dispatch |
| 48 | |
| 49 | def dispatch_call(self, frame, arg): |
| 50 | frame.f_locals['__args__'] = arg |
| 51 | if self.botframe is None: |
| 52 | # First call of dispatch since reset() |
| 53 | self.botframe = frame |
| 54 | return self.trace_dispatch |
| 55 | if not (self.stop_here(frame) or self.break_anywhere(frame)): |
| 56 | # No need to trace this function |
| 57 | return # None |
| 58 | self.user_call(frame, arg) |
| 59 | if self.quitting: raise BdbQuit |
| 60 | return self.trace_dispatch |
| 61 | |
| 62 | def dispatch_return(self, frame, arg): |
| 63 | if self.stop_here(frame) or frame == self.returnframe: |
| 64 | self.user_return(frame, arg) |
| 65 | if self.quitting: raise BdbQuit |
| 66 | |
| 67 | def dispatch_exception(self, frame, arg): |
| 68 | if self.stop_here(frame): |
| 69 | self.user_exception(frame, arg) |
| 70 | if self.quitting: raise BdbQuit |
| 71 | return self.trace_dispatch |
| 72 | |
| 73 | # Normally derived classes don't override the following |
Guido van Rossum | 4e16098 | 1992-09-02 20:43:20 +0000 | [diff] [blame] | 74 | # methods, but they may if they want to redefine the |
Guido van Rossum | babe2bf | 1992-01-22 22:21:31 +0000 | [diff] [blame] | 75 | # definition of stopping and breakpoints. |
| 76 | |
| 77 | def stop_here(self, frame): |
| 78 | if self.stopframe is None: |
| 79 | return 1 |
| 80 | if frame is self.stopframe: |
| 81 | return 1 |
| 82 | while frame is not None and frame is not self.stopframe: |
| 83 | if frame is self.botframe: |
| 84 | return 1 |
| 85 | frame = frame.f_back |
| 86 | return 0 |
| 87 | |
| 88 | def break_here(self, frame): |
Guido van Rossum | ff02e1d | 1997-07-11 13:42:50 +0000 | [diff] [blame^] | 89 | filename=frame.f_code.co_filename |
| 90 | if not self.breaks.has_key(filename): |
Guido van Rossum | babe2bf | 1992-01-22 22:21:31 +0000 | [diff] [blame] | 91 | return 0 |
Guido van Rossum | ff02e1d | 1997-07-11 13:42:50 +0000 | [diff] [blame^] | 92 | lineno=frame.f_lineno |
| 93 | if not lineno in self.breaks[filename]: |
Guido van Rossum | babe2bf | 1992-01-22 22:21:31 +0000 | [diff] [blame] | 94 | return 0 |
Guido van Rossum | ff02e1d | 1997-07-11 13:42:50 +0000 | [diff] [blame^] | 95 | if self.cbreaks.has_key((filename, lineno)): |
| 96 | cond=self.cbreaks[filename, lineno] |
| 97 | return eval(cond, frame.f_globals, |
| 98 | frame.f_locals) |
Guido van Rossum | babe2bf | 1992-01-22 22:21:31 +0000 | [diff] [blame] | 99 | return 1 |
| 100 | |
| 101 | def break_anywhere(self, frame): |
| 102 | return self.breaks.has_key(frame.f_code.co_filename) |
| 103 | |
Guido van Rossum | 4e16098 | 1992-09-02 20:43:20 +0000 | [diff] [blame] | 104 | # Derived classes should override the user_* methods |
Guido van Rossum | babe2bf | 1992-01-22 22:21:31 +0000 | [diff] [blame] | 105 | # to gain control. |
| 106 | |
| 107 | def user_call(self, frame, argument_list): |
Guido van Rossum | 4e16098 | 1992-09-02 20:43:20 +0000 | [diff] [blame] | 108 | # This method is called when there is the remote possibility |
Guido van Rossum | babe2bf | 1992-01-22 22:21:31 +0000 | [diff] [blame] | 109 | # that we ever need to stop in this function |
| 110 | pass |
| 111 | |
| 112 | def user_line(self, frame): |
Guido van Rossum | 4e16098 | 1992-09-02 20:43:20 +0000 | [diff] [blame] | 113 | # This method is called when we stop or break at this line |
Guido van Rossum | babe2bf | 1992-01-22 22:21:31 +0000 | [diff] [blame] | 114 | pass |
| 115 | |
| 116 | def user_return(self, frame, return_value): |
Guido van Rossum | 4e16098 | 1992-09-02 20:43:20 +0000 | [diff] [blame] | 117 | # This method is called when a return trap is set here |
Guido van Rossum | babe2bf | 1992-01-22 22:21:31 +0000 | [diff] [blame] | 118 | pass |
| 119 | |
| 120 | def user_exception(self, frame, (exc_type, exc_value, exc_traceback)): |
Guido van Rossum | 4e16098 | 1992-09-02 20:43:20 +0000 | [diff] [blame] | 121 | # This method is called if an exception occurs, |
Guido van Rossum | babe2bf | 1992-01-22 22:21:31 +0000 | [diff] [blame] | 122 | # but only if we are to stop at or just below this level |
| 123 | pass |
| 124 | |
Guido van Rossum | 4e16098 | 1992-09-02 20:43:20 +0000 | [diff] [blame] | 125 | # Derived classes and clients can call the following methods |
Guido van Rossum | babe2bf | 1992-01-22 22:21:31 +0000 | [diff] [blame] | 126 | # to affect the stepping state. |
| 127 | |
| 128 | def set_step(self): |
| 129 | # Stop after one line of code |
| 130 | self.stopframe = None |
| 131 | self.returnframe = None |
| 132 | self.quitting = 0 |
| 133 | |
| 134 | def set_next(self, frame): |
| 135 | # Stop on the next line in or below the given frame |
| 136 | self.stopframe = frame |
| 137 | self.returnframe = None |
| 138 | self.quitting = 0 |
| 139 | |
| 140 | def set_return(self, frame): |
| 141 | # Stop when returning from the given frame |
| 142 | self.stopframe = frame.f_back |
| 143 | self.returnframe = frame |
| 144 | self.quitting = 0 |
| 145 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 146 | def set_trace(self): |
| 147 | # Start debugging from here |
| 148 | try: |
| 149 | 1 + '' |
| 150 | except: |
| 151 | frame = sys.exc_traceback.tb_frame.f_back |
| 152 | self.reset() |
| 153 | while frame: |
| 154 | frame.f_trace = self.trace_dispatch |
| 155 | self.botframe = frame |
| 156 | frame = frame.f_back |
| 157 | self.set_step() |
| 158 | sys.settrace(self.trace_dispatch) |
| 159 | |
Guido van Rossum | babe2bf | 1992-01-22 22:21:31 +0000 | [diff] [blame] | 160 | def set_continue(self): |
| 161 | # Don't stop except at breakpoints or when finished |
| 162 | self.stopframe = self.botframe |
| 163 | self.returnframe = None |
| 164 | self.quitting = 0 |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 165 | if not self.breaks: |
| 166 | # no breakpoints; run without debugger overhead |
| 167 | sys.settrace(None) |
| 168 | try: |
| 169 | 1 + '' # raise an exception |
| 170 | except: |
| 171 | frame = sys.exc_traceback.tb_frame.f_back |
| 172 | while frame and frame is not self.botframe: |
| 173 | del frame.f_trace |
| 174 | frame = frame.f_back |
Guido van Rossum | babe2bf | 1992-01-22 22:21:31 +0000 | [diff] [blame] | 175 | |
| 176 | def set_quit(self): |
| 177 | self.stopframe = self.botframe |
| 178 | self.returnframe = None |
| 179 | self.quitting = 1 |
Guido van Rossum | edbfcbd | 1992-03-27 15:09:46 +0000 | [diff] [blame] | 180 | sys.settrace(None) |
Guido van Rossum | babe2bf | 1992-01-22 22:21:31 +0000 | [diff] [blame] | 181 | |
Guido van Rossum | 4e16098 | 1992-09-02 20:43:20 +0000 | [diff] [blame] | 182 | # Derived classes and clients can call the following methods |
| 183 | # to manipulate breakpoints. These methods return an |
Guido van Rossum | babe2bf | 1992-01-22 22:21:31 +0000 | [diff] [blame] | 184 | # error message is something went wrong, None if all is well. |
| 185 | # Call self.get_*break*() to see the breakpoints. |
| 186 | |
Guido van Rossum | ff02e1d | 1997-07-11 13:42:50 +0000 | [diff] [blame^] | 187 | def set_break(self, filename, lineno, cond=None): |
Guido van Rossum | babe2bf | 1992-01-22 22:21:31 +0000 | [diff] [blame] | 188 | import linecache # Import as late as possible |
| 189 | line = linecache.getline(filename, lineno) |
| 190 | if not line: |
| 191 | return 'That line does not exist!' |
| 192 | if not self.breaks.has_key(filename): |
| 193 | self.breaks[filename] = [] |
| 194 | list = self.breaks[filename] |
| 195 | if lineno in list: |
| 196 | return 'There is already a breakpoint there!' |
| 197 | list.append(lineno) |
Guido van Rossum | ff02e1d | 1997-07-11 13:42:50 +0000 | [diff] [blame^] | 198 | if cond is not None: self.cbreaks[filename, lineno]=cond |
Guido van Rossum | babe2bf | 1992-01-22 22:21:31 +0000 | [diff] [blame] | 199 | |
| 200 | def clear_break(self, filename, lineno): |
| 201 | if not self.breaks.has_key(filename): |
| 202 | return 'There are no breakpoints in that file!' |
| 203 | if lineno not in self.breaks[filename]: |
| 204 | return 'There is no breakpoint there!' |
| 205 | self.breaks[filename].remove(lineno) |
| 206 | if not self.breaks[filename]: |
| 207 | del self.breaks[filename] |
Guido van Rossum | ff02e1d | 1997-07-11 13:42:50 +0000 | [diff] [blame^] | 208 | try: del self.cbreaks[filename, lineno] |
| 209 | except: pass |
Guido van Rossum | babe2bf | 1992-01-22 22:21:31 +0000 | [diff] [blame] | 210 | |
| 211 | def clear_all_file_breaks(self, filename): |
| 212 | if not self.breaks.has_key(filename): |
| 213 | return 'There are no breakpoints in that file!' |
| 214 | del self.breaks[filename] |
Guido van Rossum | ff02e1d | 1997-07-11 13:42:50 +0000 | [diff] [blame^] | 215 | for f,l in self.cbreaks.keys(): |
| 216 | if f==filename: del self.cbreaks[f,l] |
Guido van Rossum | babe2bf | 1992-01-22 22:21:31 +0000 | [diff] [blame] | 217 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 218 | def clear_all_breaks(self): |
Guido van Rossum | babe2bf | 1992-01-22 22:21:31 +0000 | [diff] [blame] | 219 | if not self.breaks: |
| 220 | return 'There are no breakpoints!' |
| 221 | self.breaks = {} |
Guido van Rossum | ff02e1d | 1997-07-11 13:42:50 +0000 | [diff] [blame^] | 222 | self.cbreaks = {} |
Guido van Rossum | babe2bf | 1992-01-22 22:21:31 +0000 | [diff] [blame] | 223 | |
| 224 | def get_break(self, filename, lineno): |
| 225 | return self.breaks.has_key(filename) and \ |
| 226 | lineno in self.breaks[filename] |
| 227 | |
| 228 | def get_file_breaks(self, filename): |
| 229 | if self.breaks.has_key(filename): |
| 230 | return self.breaks[filename] |
| 231 | else: |
| 232 | return [] |
| 233 | |
| 234 | def get_all_breaks(self): |
| 235 | return self.breaks |
| 236 | |
Guido van Rossum | 4e16098 | 1992-09-02 20:43:20 +0000 | [diff] [blame] | 237 | # Derived classes and clients can call the following method |
Guido van Rossum | babe2bf | 1992-01-22 22:21:31 +0000 | [diff] [blame] | 238 | # to get a data structure representing a stack trace. |
| 239 | |
| 240 | def get_stack(self, f, t): |
| 241 | stack = [] |
| 242 | if t and t.tb_frame is f: |
| 243 | t = t.tb_next |
| 244 | while f is not None: |
| 245 | stack.append((f, f.f_lineno)) |
| 246 | if f is self.botframe: |
| 247 | break |
| 248 | f = f.f_back |
| 249 | stack.reverse() |
| 250 | i = max(0, len(stack) - 1) |
| 251 | while t is not None: |
| 252 | stack.append((t.tb_frame, t.tb_lineno)) |
| 253 | t = t.tb_next |
| 254 | return stack, i |
| 255 | |
Guido van Rossum | fac6da2 | 1992-01-27 16:59:34 +0000 | [diff] [blame] | 256 | # |
| 257 | |
Guido van Rossum | a558e37 | 1994-11-10 22:27:35 +0000 | [diff] [blame] | 258 | def format_stack_entry(self, frame_lineno, lprefix=': '): |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 259 | import linecache, repr, string |
Guido van Rossum | 89a7869 | 1992-12-14 12:57:56 +0000 | [diff] [blame] | 260 | frame, lineno = frame_lineno |
Guido van Rossum | fac6da2 | 1992-01-27 16:59:34 +0000 | [diff] [blame] | 261 | filename = frame.f_code.co_filename |
| 262 | s = filename + '(' + `lineno` + ')' |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 263 | if frame.f_code.co_name: |
| 264 | s = s + frame.f_code.co_name |
| 265 | else: |
| 266 | s = s + "<lambda>" |
Guido van Rossum | fac6da2 | 1992-01-27 16:59:34 +0000 | [diff] [blame] | 267 | if frame.f_locals.has_key('__args__'): |
| 268 | args = frame.f_locals['__args__'] |
Guido van Rossum | b6aa92e | 1995-02-03 12:50:04 +0000 | [diff] [blame] | 269 | else: |
| 270 | args = None |
| 271 | if args: |
| 272 | s = s + repr.repr(args) |
| 273 | else: |
| 274 | s = s + '()' |
Guido van Rossum | fac6da2 | 1992-01-27 16:59:34 +0000 | [diff] [blame] | 275 | if frame.f_locals.has_key('__return__'): |
| 276 | rv = frame.f_locals['__return__'] |
| 277 | s = s + '->' |
| 278 | s = s + repr.repr(rv) |
| 279 | line = linecache.getline(filename, lineno) |
Guido van Rossum | a558e37 | 1994-11-10 22:27:35 +0000 | [diff] [blame] | 280 | if line: s = s + lprefix + string.strip(line) |
Guido van Rossum | fac6da2 | 1992-01-27 16:59:34 +0000 | [diff] [blame] | 281 | return s |
| 282 | |
Guido van Rossum | 4e16098 | 1992-09-02 20:43:20 +0000 | [diff] [blame] | 283 | # The following two methods can be called by clients to use |
Guido van Rossum | babe2bf | 1992-01-22 22:21:31 +0000 | [diff] [blame] | 284 | # a debugger to debug a statement, given as a string. |
| 285 | |
Guido van Rossum | 5e38b6f | 1995-02-27 13:13:40 +0000 | [diff] [blame] | 286 | def run(self, cmd, globals=None, locals=None): |
| 287 | if globals is None: |
| 288 | import __main__ |
| 289 | globals = __main__.__dict__ |
| 290 | if locals is None: |
| 291 | locals = globals |
Guido van Rossum | babe2bf | 1992-01-22 22:21:31 +0000 | [diff] [blame] | 292 | self.reset() |
Guido van Rossum | edbfcbd | 1992-03-27 15:09:46 +0000 | [diff] [blame] | 293 | sys.settrace(self.trace_dispatch) |
Guido van Rossum | 4808dcb | 1996-10-15 14:40:21 +0000 | [diff] [blame] | 294 | if type(cmd) <> types.CodeType: |
| 295 | cmd = cmd+'\n' |
Guido van Rossum | babe2bf | 1992-01-22 22:21:31 +0000 | [diff] [blame] | 296 | try: |
Guido van Rossum | ceb3ba2 | 1992-04-03 16:32:37 +0000 | [diff] [blame] | 297 | try: |
Guido van Rossum | 4808dcb | 1996-10-15 14:40:21 +0000 | [diff] [blame] | 298 | exec cmd in globals, locals |
Guido van Rossum | ceb3ba2 | 1992-04-03 16:32:37 +0000 | [diff] [blame] | 299 | except BdbQuit: |
| 300 | pass |
Guido van Rossum | babe2bf | 1992-01-22 22:21:31 +0000 | [diff] [blame] | 301 | finally: |
| 302 | self.quitting = 1 |
Guido van Rossum | edbfcbd | 1992-03-27 15:09:46 +0000 | [diff] [blame] | 303 | sys.settrace(None) |
Guido van Rossum | 5e38b6f | 1995-02-27 13:13:40 +0000 | [diff] [blame] | 304 | |
| 305 | def runeval(self, expr, globals=None, locals=None): |
| 306 | if globals is None: |
| 307 | import __main__ |
| 308 | globals = __main__.__dict__ |
| 309 | if locals is None: |
| 310 | locals = globals |
| 311 | self.reset() |
| 312 | sys.settrace(self.trace_dispatch) |
Guido van Rossum | 4808dcb | 1996-10-15 14:40:21 +0000 | [diff] [blame] | 313 | if type(expr) <> types.CodeType: |
| 314 | expr = expr+'\n' |
Guido van Rossum | 5e38b6f | 1995-02-27 13:13:40 +0000 | [diff] [blame] | 315 | try: |
| 316 | try: |
Guido van Rossum | 4808dcb | 1996-10-15 14:40:21 +0000 | [diff] [blame] | 317 | return eval(expr, globals, locals) |
Guido van Rossum | 5e38b6f | 1995-02-27 13:13:40 +0000 | [diff] [blame] | 318 | except BdbQuit: |
| 319 | pass |
| 320 | finally: |
| 321 | self.quitting = 1 |
| 322 | sys.settrace(None) |
| 323 | |
| 324 | def runctx(self, cmd, globals, locals): |
| 325 | # B/W compatibility |
| 326 | self.run(cmd, globals, locals) |
Guido van Rossum | 4e16098 | 1992-09-02 20:43:20 +0000 | [diff] [blame] | 327 | |
| 328 | # This method is more useful to debug a single function call. |
| 329 | |
| 330 | def runcall(self, func, *args): |
| 331 | self.reset() |
| 332 | sys.settrace(self.trace_dispatch) |
Guido van Rossum | 5e38b6f | 1995-02-27 13:13:40 +0000 | [diff] [blame] | 333 | res = None |
Guido van Rossum | 4e16098 | 1992-09-02 20:43:20 +0000 | [diff] [blame] | 334 | try: |
| 335 | try: |
Guido van Rossum | 5e38b6f | 1995-02-27 13:13:40 +0000 | [diff] [blame] | 336 | res = apply(func, args) |
Guido van Rossum | 4e16098 | 1992-09-02 20:43:20 +0000 | [diff] [blame] | 337 | except BdbQuit: |
| 338 | pass |
| 339 | finally: |
| 340 | self.quitting = 1 |
| 341 | sys.settrace(None) |
Guido van Rossum | 5e38b6f | 1995-02-27 13:13:40 +0000 | [diff] [blame] | 342 | return res |
Guido van Rossum | babe2bf | 1992-01-22 22:21:31 +0000 | [diff] [blame] | 343 | |
Guido van Rossum | babe2bf | 1992-01-22 22:21:31 +0000 | [diff] [blame] | 344 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 345 | def set_trace(): |
| 346 | Bdb().set_trace() |
| 347 | |
Guido van Rossum | babe2bf | 1992-01-22 22:21:31 +0000 | [diff] [blame] | 348 | # -------------------- testing -------------------- |
| 349 | |
| 350 | class Tdb(Bdb): |
| 351 | def user_call(self, frame, args): |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 352 | name = frame.f_code.co_name |
Guido van Rossum | babe2bf | 1992-01-22 22:21:31 +0000 | [diff] [blame] | 353 | if not name: name = '???' |
| 354 | print '+++ call', name, args |
| 355 | def user_line(self, frame): |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 356 | import linecache, string |
| 357 | name = frame.f_code.co_name |
Guido van Rossum | babe2bf | 1992-01-22 22:21:31 +0000 | [diff] [blame] | 358 | if not name: name = '???' |
| 359 | fn = frame.f_code.co_filename |
| 360 | line = linecache.getline(fn, frame.f_lineno) |
| 361 | print '+++', fn, frame.f_lineno, name, ':', string.strip(line) |
| 362 | def user_return(self, frame, retval): |
| 363 | print '+++ return', retval |
| 364 | def user_exception(self, frame, exc_stuff): |
| 365 | print '+++ exception', exc_stuff |
| 366 | self.set_continue() |
| 367 | |
| 368 | def foo(n): |
| 369 | print 'foo(', n, ')' |
| 370 | x = bar(n*10) |
| 371 | print 'bar returned', x |
| 372 | |
| 373 | def bar(a): |
| 374 | print 'bar(', a, ')' |
| 375 | return a/2 |
| 376 | |
| 377 | def test(): |
Guido van Rossum | 5ef74b8 | 1993-06-23 11:55:24 +0000 | [diff] [blame] | 378 | t = Tdb() |
Guido van Rossum | babe2bf | 1992-01-22 22:21:31 +0000 | [diff] [blame] | 379 | t.run('import bdb; bdb.foo(10)') |