[Python-checkins] r71006 - python/trunk/Lib/pdb.py

georg.brandl python-checkins at python.org
Thu Apr 2 01:32:18 CEST 2009


Author: georg.brandl
Date: Thu Apr 2 01:32:17 2009
New Revision: 71006
Log:
Cache the f_locals dict of the current frame, since every access to frame.f_locals overrides its contents with the real locals which undoes modifications made by the debugging user.
Modified:
 python/trunk/Lib/pdb.py
Modified: python/trunk/Lib/pdb.py
==============================================================================
--- python/trunk/Lib/pdb.py	(original)
+++ python/trunk/Lib/pdb.py	Thu Apr 2 01:32:17 2009
@@ -95,10 +95,14 @@
 rcFile.close()
 
 self.commands = {} # associates a command list to breakpoint numbers
- self.commands_doprompt = {} # for each bp num, tells if the prompt must be disp. after execing the cmd list
- self.commands_silent = {} # for each bp num, tells if the stack trace must be disp. after execing the cmd list
- self.commands_defining = False # True while in the process of defining a command list
- self.commands_bnum = None # The breakpoint number for which we are defining a list
+ self.commands_doprompt = {} # for each bp num, tells if the prompt
+ # must be disp. after execing the cmd list
+ self.commands_silent = {} # for each bp num, tells if the stack trace
+ # must be disp. after execing the cmd list
+ self.commands_defining = False # True while in the process of defining
+ # a command list
+ self.commands_bnum = None # The breakpoint number for which we are
+ # defining a list
 
 def reset(self):
 bdb.Bdb.reset(self)
@@ -114,6 +118,10 @@
 self.forget()
 self.stack, self.curindex = self.get_stack(f, t)
 self.curframe = self.stack[self.curindex][0]
+ # The f_locals dictionary is updated from the actual frame
+ # locals whenever the .f_locals accessor is called, so we
+ # cache it here to ensure that modifications are not overwritten.
+ self.curframe_locals = self.curframe.f_locals
 self.execRcLines()
 
 # Can be executed earlier than 'setup' if desired
@@ -202,7 +210,7 @@
 
 def default(self, line):
 if line[:1] == '!': line = line[1:]
- locals = self.curframe.f_locals
+ locals = self.curframe_locals
 globals = self.curframe.f_globals
 try:
 code = compile(line + '\n', '<stdin>', 'single')
@@ -360,7 +368,7 @@
 try:
 func = eval(arg,
 self.curframe.f_globals,
- self.curframe.f_locals)
+ self.curframe_locals)
 except:
 func = arg
 try:
@@ -681,7 +689,7 @@
 def do_debug(self, arg):
 sys.settrace(None)
 globals = self.curframe.f_globals
- locals = self.curframe.f_locals
+ locals = self.curframe_locals
 p = Pdb(self.completekey, self.stdin, self.stdout)
 p.prompt = "(%s) " % self.prompt.strip()
 print >>self.stdout, "ENTERING RECURSIVE DEBUGGER"
@@ -705,9 +713,8 @@
 return 1
 
 def do_args(self, arg):
- f = self.curframe
- co = f.f_code
- dict = f.f_locals
+ co = self.curframe.f_code
+ dict = self.curframe_locals
 n = co.co_argcount
 if co.co_flags & 4: n = n+1
 if co.co_flags & 8: n = n+1
@@ -719,8 +726,8 @@
 do_a = do_args
 
 def do_retval(self, arg):
- if '__return__' in self.curframe.f_locals:
- print >>self.stdout, self.curframe.f_locals['__return__']
+ if '__return__' in self.curframe_locals:
+ print >>self.stdout, self.curframe_locals['__return__']
 else:
 print >>self.stdout, '*** Not yet returned!'
 do_rv = do_retval
@@ -728,7 +735,7 @@
 def _getval(self, arg):
 try:
 return eval(arg, self.curframe.f_globals,
- self.curframe.f_locals)
+ self.curframe_locals)
 except:
 t, v = sys.exc_info()[:2]
 if isinstance(t, str):
@@ -797,7 +804,7 @@
 def do_whatis(self, arg):
 try:
 value = eval(arg, self.curframe.f_globals,
- self.curframe.f_locals)
+ self.curframe_locals)
 except:
 t, v = sys.exc_info()[:2]
 if type(t) == type(''):


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /