mirror of https://github.com/python/cpython.git
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.
This commit is contained in:
parent
71095ae5ab
commit
e361bcb43f
35
Lib/pdb.py
35
Lib/pdb.py
|
@ -95,10 +95,14 @@ def __init__(self, completekey='tab', stdin=None, stdout=None):
|
||||||
rcFile.close()
|
rcFile.close()
|
||||||
|
|
||||||
self.commands = {} # associates a command list to breakpoint numbers
|
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_doprompt = {} # for each bp num, tells if the prompt
|
||||||
self.commands_silent = {} # for each bp num, tells if the stack trace must be disp. after execing the cmd list
|
# must be disp. after execing the cmd list
|
||||||
self.commands_defining = False # True while in the process of defining a command list
|
self.commands_silent = {} # for each bp num, tells if the stack trace
|
||||||
self.commands_bnum = None # The breakpoint number for which we are defining a list
|
# 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):
|
def reset(self):
|
||||||
bdb.Bdb.reset(self)
|
bdb.Bdb.reset(self)
|
||||||
|
@ -114,6 +118,10 @@ def setup(self, f, t):
|
||||||
self.forget()
|
self.forget()
|
||||||
self.stack, self.curindex = self.get_stack(f, t)
|
self.stack, self.curindex = self.get_stack(f, t)
|
||||||
self.curframe = self.stack[self.curindex][0]
|
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()
|
self.execRcLines()
|
||||||
|
|
||||||
# Can be executed earlier than 'setup' if desired
|
# Can be executed earlier than 'setup' if desired
|
||||||
|
@ -202,7 +210,7 @@ def displayhook(self, obj):
|
||||||
|
|
||||||
def default(self, line):
|
def default(self, line):
|
||||||
if line[:1] == '!': line = line[1:]
|
if line[:1] == '!': line = line[1:]
|
||||||
locals = self.curframe.f_locals
|
locals = self.curframe_locals
|
||||||
globals = self.curframe.f_globals
|
globals = self.curframe.f_globals
|
||||||
try:
|
try:
|
||||||
code = compile(line + '\n', '<stdin>', 'single')
|
code = compile(line + '\n', '<stdin>', 'single')
|
||||||
|
@ -360,7 +368,7 @@ def do_break(self, arg, temporary = 0):
|
||||||
try:
|
try:
|
||||||
func = eval(arg,
|
func = eval(arg,
|
||||||
self.curframe.f_globals,
|
self.curframe.f_globals,
|
||||||
self.curframe.f_locals)
|
self.curframe_locals)
|
||||||
except:
|
except:
|
||||||
func = arg
|
func = arg
|
||||||
try:
|
try:
|
||||||
|
@ -681,7 +689,7 @@ def do_jump(self, arg):
|
||||||
def do_debug(self, arg):
|
def do_debug(self, arg):
|
||||||
sys.settrace(None)
|
sys.settrace(None)
|
||||||
globals = self.curframe.f_globals
|
globals = self.curframe.f_globals
|
||||||
locals = self.curframe.f_locals
|
locals = self.curframe_locals
|
||||||
p = Pdb(self.completekey, self.stdin, self.stdout)
|
p = Pdb(self.completekey, self.stdin, self.stdout)
|
||||||
p.prompt = "(%s) " % self.prompt.strip()
|
p.prompt = "(%s) " % self.prompt.strip()
|
||||||
print >>self.stdout, "ENTERING RECURSIVE DEBUGGER"
|
print >>self.stdout, "ENTERING RECURSIVE DEBUGGER"
|
||||||
|
@ -705,9 +713,8 @@ def do_EOF(self, arg):
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
def do_args(self, arg):
|
def do_args(self, arg):
|
||||||
f = self.curframe
|
co = self.curframe.f_code
|
||||||
co = f.f_code
|
dict = self.curframe_locals
|
||||||
dict = f.f_locals
|
|
||||||
n = co.co_argcount
|
n = co.co_argcount
|
||||||
if co.co_flags & 4: n = n+1
|
if co.co_flags & 4: n = n+1
|
||||||
if co.co_flags & 8: n = n+1
|
if co.co_flags & 8: n = n+1
|
||||||
|
@ -719,8 +726,8 @@ def do_args(self, arg):
|
||||||
do_a = do_args
|
do_a = do_args
|
||||||
|
|
||||||
def do_retval(self, arg):
|
def do_retval(self, arg):
|
||||||
if '__return__' in self.curframe.f_locals:
|
if '__return__' in self.curframe_locals:
|
||||||
print >>self.stdout, self.curframe.f_locals['__return__']
|
print >>self.stdout, self.curframe_locals['__return__']
|
||||||
else:
|
else:
|
||||||
print >>self.stdout, '*** Not yet returned!'
|
print >>self.stdout, '*** Not yet returned!'
|
||||||
do_rv = do_retval
|
do_rv = do_retval
|
||||||
|
@ -728,7 +735,7 @@ def do_retval(self, arg):
|
||||||
def _getval(self, arg):
|
def _getval(self, arg):
|
||||||
try:
|
try:
|
||||||
return eval(arg, self.curframe.f_globals,
|
return eval(arg, self.curframe.f_globals,
|
||||||
self.curframe.f_locals)
|
self.curframe_locals)
|
||||||
except:
|
except:
|
||||||
t, v = sys.exc_info()[:2]
|
t, v = sys.exc_info()[:2]
|
||||||
if isinstance(t, str):
|
if isinstance(t, str):
|
||||||
|
@ -797,7 +804,7 @@ def do_list(self, arg):
|
||||||
def do_whatis(self, arg):
|
def do_whatis(self, arg):
|
||||||
try:
|
try:
|
||||||
value = eval(arg, self.curframe.f_globals,
|
value = eval(arg, self.curframe.f_globals,
|
||||||
self.curframe.f_locals)
|
self.curframe_locals)
|
||||||
except:
|
except:
|
||||||
t, v = sys.exc_info()[:2]
|
t, v = sys.exc_info()[:2]
|
||||||
if type(t) == type(''):
|
if type(t) == type(''):
|
||||||
|
|
Loading…
Reference in New Issue