diff --git a/Lib/pdb.py b/Lib/pdb.py index 9025be1af12..8b747e714a0 100755 --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -95,10 +95,14 @@ class Pdb(bdb.Bdb, cmd.Cmd): 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 @@ class Pdb(bdb.Bdb, cmd.Cmd): 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 @@ class Pdb(bdb.Bdb, cmd.Cmd): 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', '', 'single') @@ -360,7 +368,7 @@ class Pdb(bdb.Bdb, cmd.Cmd): try: func = eval(arg, self.curframe.f_globals, - self.curframe.f_locals) + self.curframe_locals) except: func = arg try: @@ -681,7 +689,7 @@ class Pdb(bdb.Bdb, cmd.Cmd): 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 @@ class Pdb(bdb.Bdb, cmd.Cmd): 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 @@ class Pdb(bdb.Bdb, cmd.Cmd): 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 @@ class Pdb(bdb.Bdb, cmd.Cmd): 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 @@ class Pdb(bdb.Bdb, cmd.Cmd): 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(''):