Changeset 391 for python/trunk/Lib/pdb.py
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Lib/pdb.py
r2 r391 59 59 class Pdb(bdb.Bdb, cmd.Cmd): 60 60 61 def __init__(self, completekey='tab', stdin=None, stdout=None ):62 bdb.Bdb.__init__(self )61 def __init__(self, completekey='tab', stdin=None, stdout=None, skip=None): 62 bdb.Bdb.__init__(self, skip=skip) 63 63 cmd.Cmd.__init__(self, completekey, stdin, stdout) 64 64 if stdout: … … 96 96 97 97 self.commands = {} # associates a command list to breakpoint numbers 98 self.commands_doprompt = {} # for each bp num, tells if the prompt must be disp. after execing the cmd list 99 self.commands_silent = {} # for each bp num, tells if the stack trace must be disp. after execing the cmd list 100 self.commands_defining = False # True while in the process of defining a command list 101 self.commands_bnum = None # The breakpoint number for which we are defining a list 98 self.commands_doprompt = {} # for each bp num, tells if the prompt 99 # must be disp. after execing the cmd list 100 self.commands_silent = {} # for each bp num, tells if the stack trace 101 # must be disp. after execing the cmd list 102 self.commands_defining = False # True while in the process of defining 103 # a command list 104 self.commands_bnum = None # The breakpoint number for which we are 105 # defining a list 102 106 103 107 def reset(self): … … 115 119 self.stack, self.curindex = self.get_stack(f, t) 116 120 self.curframe = self.stack[self.curindex][0] 121 # The f_locals dictionary is updated from the actual frame 122 # locals whenever the .f_locals accessor is called, so we 123 # cache it here to ensure that modifications are not overwritten. 124 self.curframe_locals = self.curframe.f_locals 117 125 self.execRcLines() 118 126 … … 151 159 152 160 def bp_commands(self,frame): 153 """ Call every command that was set for the current active breakpoint (if there is one) 154 Returns True if the normal interaction function must be called, False otherwise """ 155 #self.currentbp is set in bdb.py in bdb.break_here if a breakpoint was hit 156 if getattr(self,"currentbp",False) and self.currentbp in self.commands: 161 """Call every command that was set for the current active breakpoint 162 (if there is one). 163 164 Returns True if the normal interaction function must be called, 165 False otherwise.""" 166 # self.currentbp is set in bdb in Bdb.break_here if a breakpoint was hit 167 if getattr(self, "currentbp", False) and \ 168 self.currentbp in self.commands: 157 169 currentbp = self.currentbp 158 170 self.currentbp = 0 … … 172 184 def user_return(self, frame, return_value): 173 185 """This function is called when a return trap is set here.""" 186 if self._wait_for_mainpyfile: 187 return 174 188 frame.f_locals['__return__'] = return_value 175 189 print >>self.stdout, '--Return--' … … 177 191 178 192 def user_exception(self, frame, exc_info): 179 exc_type, exc_value, exc_traceback = exc_info180 193 """This function is called if an exception occurs, 181 194 but only if we are to stop at or just below this level.""" 195 if self._wait_for_mainpyfile: 196 return 197 exc_type, exc_value, exc_traceback = exc_info 182 198 frame.f_locals['__exception__'] = exc_type, exc_value 183 199 if type(exc_type) == type(''): … … 205 221 def default(self, line): 206 222 if line[:1] == '!': line = line[1:] 207 locals = self.curframe .f_locals223 locals = self.curframe_locals 208 224 globals = self.curframe.f_globals 209 225 try: … … 266 282 267 283 def handle_command_def(self,line): 268 """ Handles one command line during command list definition."""284 """Handles one command line during command list definition.""" 269 285 cmd, arg, line = self.parseline(line) 286 if not cmd: 287 return 270 288 if cmd == 'silent': 271 289 self.commands_silent[self.commands_bnum] = True … … 275 293 return 1 # end of cmd list 276 294 cmdlist = self.commands[self.commands_bnum] 277 if (arg):295 if arg: 278 296 cmdlist.append(cmd+' '+arg) 279 297 else: … … 284 302 except AttributeError: 285 303 func = self.default 286 if func.func_name in self.commands_resuming : # one of the resuming commands. 304 # one of the resuming commands 305 if func.func_name in self.commands_resuming: 287 306 self.commands_doprompt[self.commands_bnum] = False 288 307 self.cmdqueue = [] … … 297 316 298 317 def do_commands(self, arg): 299 """Defines a list of commands associated to a breakpoint 300 Those commands will be executed whenever the breakpoint causes the program to stop execution.""" 318 """Defines a list of commands associated to a breakpoint. 319 320 Those commands will be executed whenever the breakpoint causes 321 the program to stop execution.""" 301 322 if not arg: 302 323 bnum = len(bdb.Breakpoint.bpbynumber)-1 … … 305 326 bnum = int(arg) 306 327 except: 307 print >>self.stdout, "Usage : commands [bnum]\n ...\n end" 328 print >>self.stdout, "Usage : commands [bnum]\n ..." \ 329 "\n end" 308 330 return 309 331 self.commands_bnum = bnum … … 314 336 self.prompt = '(com) ' 315 337 self.commands_defining = True 316 self.cmdloop() 317 self.commands_defining = False 318 self.prompt = prompt_back 338 try: 339 self.cmdloop() 340 finally: 341 self.commands_defining = False 342 self.prompt = prompt_back 319 343 320 344 def do_break(self, arg, temporary = 0): … … 363 387 func = eval(arg, 364 388 self.curframe.f_globals, 365 self.curframe .f_locals)389 self.curframe_locals) 366 390 except: 367 391 func = arg … … 452 476 line or EOF). Warning: testing is not comprehensive. 453 477 """ 454 line = linecache.getline(filename, lineno, self.curframe.f_globals) 478 # this method should be callable before starting debugging, so default 479 # to "no globals" if there is no current frame 480 globs = self.curframe.f_globals if hasattr(self, 'curframe') else None 481 line = linecache.getline(filename, lineno, globs) 455 482 if not line: 456 483 print >>self.stdout, 'End of file' … … 611 638 self.curindex = self.curindex - 1 612 639 self.curframe = self.stack[self.curindex][0] 640 self.curframe_locals = self.curframe.f_locals 613 641 self.print_stack_entry(self.stack[self.curindex]) 614 642 self.lineno = None … … 621 649 self.curindex = self.curindex + 1 622 650 self.curframe = self.stack[self.curindex][0] 651 self.curframe_locals = self.curframe.f_locals 623 652 self.print_stack_entry(self.stack[self.curindex]) 624 653 self.lineno = None … … 641 670 642 671 def do_run(self, arg): 643 """Restart program by raising an exception to be caught in the main debugger644 loop.If arguments were given, set them in sys.argv."""672 """Restart program by raising an exception to be caught in the main 673 debugger loop. If arguments were given, set them in sys.argv.""" 645 674 if arg: 646 675 import shlex … … 684 713 sys.settrace(None) 685 714 globals = self.curframe.f_globals 686 locals = self.curframe .f_locals715 locals = self.curframe_locals 687 716 p = Pdb(self.completekey, self.stdin, self.stdout) 688 717 p.prompt = "(%s) " % self.prompt.strip() … … 708 737 709 738 def do_args(self, arg): 710 f = self.curframe 711 co = f.f_code 712 dict = f.f_locals 739 co = self.curframe.f_code 740 dict = self.curframe_locals 713 741 n = co.co_argcount 714 742 if co.co_flags & 4: n = n+1 … … 722 750 723 751 def do_retval(self, arg): 724 if '__return__' in self.curframe .f_locals:725 print >>self.stdout, self.curframe .f_locals['__return__']752 if '__return__' in self.curframe_locals: 753 print >>self.stdout, self.curframe_locals['__return__'] 726 754 else: 727 755 print >>self.stdout, '*** Not yet returned!' … … 731 759 try: 732 760 return eval(arg, self.curframe.f_globals, 733 self.curframe .f_locals)761 self.curframe_locals) 734 762 except: 735 763 t, v = sys.exc_info()[:2] … … 780 808 try: 781 809 for lineno in range(first, last+1): 782 line = linecache.getline(filename, lineno, self.curframe.f_globals) 810 line = linecache.getline(filename, lineno, 811 self.curframe.f_globals) 783 812 if not line: 784 813 print >>self.stdout, '[EOF]' … … 800 829 try: 801 830 value = eval(arg, self.curframe.f_globals, 802 self.curframe .f_locals)831 self.curframe_locals) 803 832 except: 804 833 t, v = sys.exc_info()[:2] … … 944 973 945 974 def help_tbreak(self): 946 print >>self.stdout, """tbreak same arguments as break, but breakpoint is947 removed when first hit."""975 print >>self.stdout, """tbreak same arguments as break, but breakpoint 976 is removed when first hit.""" 948 977 949 978 def help_enable(self): … … 1067 1096 print """run [args...] 1068 1097 Restart the debugged python program. If a string is supplied, it is 1069 split tedwith "shlex" and the result is used as the new sys.argv.1098 split with "shlex" and the result is used as the new sys.argv. 1070 1099 History, breakpoints, actions and debugger options are preserved. 1071 1100 "restart" is an alias for "run".""" … … 1091 1120 1092 1121 def help_alias(self): 1093 print >>self.stdout, """alias [name [command [parameter parameter ...] 1122 print >>self.stdout, """alias [name [command [parameter parameter ...]]] 1094 1123 Creates an alias called 'name' the executes 'command'. The command 1095 1124 must *not* be enclosed in quotes. Replaceable parameters are … … 1201 1230 self.mainpyfile = self.canonic(filename) 1202 1231 self._user_requested_quit = 0 1203 statement = 'execfile( "%s")' % filename1232 statement = 'execfile(%r)' % filename 1204 1233 self.run(statement) 1205 1234 … … 1278 1307 # Note on saving/restoring sys.argv: it's a good idea when sys.argv was 1279 1308 # modified by the script being debugged. It's a bad idea when it was 1280 # changed by the user from the command line. There is a "restart" command which1281 # allows explicit specification of command line arguments.1309 # changed by the user from the command line. There is a "restart" command 1310 # which allows explicit specification of command line arguments. 1282 1311 pdb = Pdb() 1283 while 1:1312 while True: 1284 1313 try: 1285 1314 pdb._runscript(mainpyfile) … … 1300 1329 t = sys.exc_info()[2] 1301 1330 pdb.interaction(None, t) 1302 print "Post mortem debugger finished. The "+mainpyfile+" will be restarted" 1331 print "Post mortem debugger finished. The " + mainpyfile + \ 1332 " will be restarted" 1303 1333 1304 1334
Note:
See TracChangeset
for help on using the changeset viewer.