Fri, 08 Jan 2016 22:14:39 +0100
Store values entered into the shell in selected frame.
--- a/DebugClients/Python/DebugBase.py Mon Jan 04 17:49:31 2016 +0100 +++ b/DebugClients/Python/DebugBase.py Fri Jan 08 22:14:39 2016 +0100 @@ -13,6 +13,7 @@ import types import atexit import inspect +import ctypes from DebugProtocol import ResponseClearWatch, ResponseClearBreak, \ ResponseLine, ResponseSyntax, ResponseException, CallTrace @@ -66,7 +67,6 @@ # current frame we are at self.currentFrame = None - self.currentFrameLocals = None # frame that we are stepping in, can be different than currentFrame self.stepFrame = None @@ -99,14 +99,27 @@ the current frame (int) @return locals dictionary of the frame """ - if frmnr: - f = self.currentFrame - while f is not None and frmnr > 0: - f = f.f_back - frmnr -= 1 - return f.f_locals - else: - return self.currentFrameLocals + f = self.currentFrame + while f is not None and frmnr > 0: + f = f.f_back + frmnr -= 1 + return f.f_locals + + def storeFrameLocals(self, frmnr=0): + """ + Public method to store the locals into the frame, so an access to + frame.f_locals returns the last data. + + @keyparam frmnr distance of frame to store locals dictionary to. 0 is + the current frame (int) + """ + cf = self.currentFrame + while cf is not None and frmnr > 0: + cf = cf.f_back + frmnr -= 1 + ctypes.pythonapi.PyFrame_LocalsToFast( + ctypes.py_object(cf), + ctypes.c_int(0)) def step(self, traceMode): """ @@ -600,8 +613,6 @@ self._dbgClient.mainFrame = frame self.currentFrame = frame - self.currentFrameLocals = frame.f_locals - # remember the locals because it is reinitialized when accessed fr = frame stack = [] @@ -707,8 +718,6 @@ frlist.reverse() self.currentFrame = frlist[0] - self.currentFrameLocals = frlist[0].f_locals - # remember the locals because it is reinitialized when accessed for fr in frlist: filename = self._dbgClient.absPath(self.fix_frame_filename(fr))
--- a/DebugClients/Python/DebugClientBase.py Mon Jan 04 17:49:31 2016 +0100 +++ b/DebugClients/Python/DebugClientBase.py Fri Jan 08 22:14:39 2016 +0100 @@ -771,7 +771,8 @@ try: value = eval( arg, self.currentThread.getCurrentFrame().f_globals, - self.currentThread.getFrameLocals(0)) + self.currentThread.getFrameLocals(self.framenr)) + self.currentThread.storeFrameLocals(self.framenr) except Exception: # Report the exception and the traceback try: @@ -801,10 +802,11 @@ if cmd == DebugProtocol.RequestExec: _globals = self.currentThread.getCurrentFrame().f_globals - _locals = self.currentThread.getFrameLocals(0) + _locals = self.currentThread.getFrameLocals(self.framenr) try: code = compile(arg + '\n', '<stdin>', 'single') exec code in _globals, _locals + self.currentThread.storeFrameLocals(self.framenr) except Exception: # Report the exception and the traceback try: @@ -994,6 +996,8 @@ _locals["sys"].stdout = __stdout else: exec code in _globals, _locals + + self.currentThread.storeFrameLocals(self.framenr) except SystemExit, exc: self.progTerminated(exc.code) except Exception: @@ -1356,12 +1360,11 @@ scope = -1 elif scope: dict = f.f_globals + elif f.f_globals is f.f_locals: + scope = -1 else: dict = f.f_locals - if f.f_globals is f.f_locals: - scope = -1 - varlist = [scope] if scope != -1: @@ -1401,12 +1404,11 @@ scope = -1 elif scope: dict = f.f_globals + elif f.f_globals is f.f_locals: + scope = -1 else: dict = f.f_locals - - if f.f_globals is f.f_locals: - scope = -1 - + varlist = [scope, var] if scope != -1:
--- a/DebugClients/Python3/DebugBase.py Mon Jan 04 17:49:31 2016 +0100 +++ b/DebugClients/Python3/DebugBase.py Fri Jan 08 22:14:39 2016 +0100 @@ -12,6 +12,7 @@ import os import atexit import inspect +import ctypes from inspect import CO_GENERATOR from DebugProtocol import ResponseClearWatch, ResponseClearBreak, \ @@ -67,7 +68,6 @@ # current frame we are at self.currentFrame = None - self.currentFrameLocals = None # frame that we are stepping in, can be different than currentFrame self.stepFrame = None @@ -100,14 +100,27 @@ the current frame (int) @return locals dictionary of the frame """ - if frmnr: - f = self.currentFrame - while f is not None and frmnr > 0: - f = f.f_back - frmnr -= 1 - return f.f_locals - else: - return self.currentFrameLocals + f = self.currentFrame + while f is not None and frmnr > 0: + f = f.f_back + frmnr -= 1 + return f.f_locals + + def storeFrameLocals(self, frmnr=0): + """ + Public method to store the locals into the frame, so an access to + frame.f_locals returns the last data. + + @keyparam frmnr distance of frame to store locals dictionary to. 0 is + the current frame (int) + """ + cf = self.currentFrame + while cf is not None and frmnr > 0: + cf = cf.f_back + frmnr -= 1 + ctypes.pythonapi.PyFrame_LocalsToFast( + ctypes.py_object(cf), + ctypes.c_int(0)) def step(self, traceMode): """ @@ -632,8 +645,6 @@ self._dbgClient.mainFrame = frame self.currentFrame = frame - self.currentFrameLocals = frame.f_locals - # remember the locals because it is reinitialized when accessed fr = frame stack = [] @@ -743,8 +754,6 @@ frlist.reverse() self.currentFrame = frlist[0] - self.currentFrameLocals = frlist[0].f_locals - # remember the locals because it is reinitialized when accessed for fr in frlist: filename = self._dbgClient.absPath(self.fix_frame_filename(fr))
--- a/DebugClients/Python3/DebugClientBase.py Mon Jan 04 17:49:31 2016 +0100 +++ b/DebugClients/Python3/DebugClientBase.py Fri Jan 08 22:14:39 2016 +0100 @@ -775,7 +775,8 @@ value = eval( arg, self.currentThread.getCurrentFrame().f_globals, - self.currentThread.getFrameLocals(0)) + self.currentThread.getFrameLocals(self.framenr)) + self.currentThread.storeFrameLocals(self.framenr) except Exception: # Report the exception and the traceback try: @@ -806,10 +807,11 @@ if cmd == DebugProtocol.RequestExec: _globals = self.currentThread.getCurrentFrame().f_globals - _locals = self.currentThread.getFrameLocals(0) + _locals = self.currentThread.getFrameLocals(self.framenr) try: code = compile(arg + '\n', '<stdin>', 'single') exec(code, _globals, _locals) + self.currentThread.storeFrameLocals(self.framenr) except Exception: # Report the exception and the traceback try: @@ -996,6 +998,8 @@ _locals["sys"].stdout = __stdout else: exec(code, _globals, _locals) + + self.currentThread.storeFrameLocals(self.framenr) except SystemExit as exc: self.progTerminated(exc.code) except Exception: @@ -1359,12 +1363,11 @@ scope = -1 elif scope: dict = f.f_globals + elif f.f_globals is f.f_locals: + scope = -1 else: dict = f.f_locals - if f.f_globals is f.f_locals: - scope = -1 - varlist = [scope] if scope != -1: @@ -1404,11 +1407,10 @@ scope = -1 elif scope: dict = f.f_globals + elif f.f_globals is f.f_locals: + scope = -1 else: dict = f.f_locals - - if f.f_globals is f.f_locals: - scope = -1 varlist = [scope, var]