summaryrefslogtreecommitdiffstats
path: root/Lib/pdb.py
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2009-04-01 23:32:17 (GMT)
committerGeorg Brandl <georg@python.org>2009-04-01 23:32:17 (GMT)
commite361bcb43f93a6e42c4ccdb9ad19a24543f9938b (patch)
tree96895f7a25da71a2be312c68ad2e54875d4dd3f4 /Lib/pdb.py
parent71095ae5abf60fa73ebf95320b3f1e1508d9c308 (diff)
downloadcpython-e361bcb43f93a6e42c4ccdb9ad19a24543f9938b.zip
cpython-e361bcb43f93a6e42c4ccdb9ad19a24543f9938b.tar.gz
cpython-e361bcb43f93a6e42c4ccdb9ad19a24543f9938b.tar.bz2
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.
Diffstat (limited to 'Lib/pdb.py')
-rwxr-xr-xLib/pdb.py35
1 files changed, 21 insertions, 14 deletions
diff --git a/Lib/pdb.py b/Lib/pdb.py
index 9025be1..8b747e7 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', '<stdin>', '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(''):