DebugClients/Python3/DebugBase.py

changeset 4642
f18d5fb9a53b
parent 4631
5c1a96925da4
child 4683
1ba6ba86b383
equal deleted inserted replaced
4640:0b502e1bc0b9 4642:f18d5fb9a53b
10 import sys 10 import sys
11 import bdb 11 import bdb
12 import os 12 import os
13 import atexit 13 import atexit
14 import inspect 14 import inspect
15 import ctypes
15 from inspect import CO_GENERATOR 16 from inspect import CO_GENERATOR
16 17
17 from DebugProtocol import ResponseClearWatch, ResponseClearBreak, \ 18 from DebugProtocol import ResponseClearWatch, ResponseClearBreak, \
18 ResponseLine, ResponseSyntax, ResponseException, CallTrace 19 ResponseLine, ResponseSyntax, ResponseException, CallTrace
19 from DebugUtilities import getargvalues, formatargvalues 20 from DebugUtilities import getargvalues, formatargvalues
65 self.__isBroken = "" 66 self.__isBroken = ""
66 self.cFrame = None 67 self.cFrame = None
67 68
68 # current frame we are at 69 # current frame we are at
69 self.currentFrame = None 70 self.currentFrame = None
70 self.currentFrameLocals = None
71 71
72 # frame that we are stepping in, can be different than currentFrame 72 # frame that we are stepping in, can be different than currentFrame
73 self.stepFrame = None 73 self.stepFrame = None
74 74
75 # provide a hook to perform a hard breakpoint 75 # provide a hook to perform a hard breakpoint
98 98
99 @keyparam frmnr distance of frame to get locals dictionary of. 0 is 99 @keyparam frmnr distance of frame to get locals dictionary of. 0 is
100 the current frame (int) 100 the current frame (int)
101 @return locals dictionary of the frame 101 @return locals dictionary of the frame
102 """ 102 """
103 if frmnr: 103 f = self.currentFrame
104 f = self.currentFrame 104 while f is not None and frmnr > 0:
105 while f is not None and frmnr > 0: 105 f = f.f_back
106 f = f.f_back 106 frmnr -= 1
107 frmnr -= 1 107 return f.f_locals
108 return f.f_locals 108
109 else: 109 def storeFrameLocals(self, frmnr=0):
110 return self.currentFrameLocals 110 """
111 Public method to store the locals into the frame, so an access to
112 frame.f_locals returns the last data.
113
114 @keyparam frmnr distance of frame to store locals dictionary to. 0 is
115 the current frame (int)
116 """
117 cf = self.currentFrame
118 while cf is not None and frmnr > 0:
119 cf = cf.f_back
120 frmnr -= 1
121 ctypes.pythonapi.PyFrame_LocalsToFast(
122 ctypes.py_object(cf),
123 ctypes.c_int(0))
111 124
112 def step(self, traceMode): 125 def step(self, traceMode):
113 """ 126 """
114 Public method to perform a step operation in this thread. 127 Public method to perform a step operation in this thread.
115 128
630 if fn != self._dbgClient.getRunning(): 643 if fn != self._dbgClient.getRunning():
631 return 644 return
632 self._dbgClient.mainFrame = frame 645 self._dbgClient.mainFrame = frame
633 646
634 self.currentFrame = frame 647 self.currentFrame = frame
635 self.currentFrameLocals = frame.f_locals
636 # remember the locals because it is reinitialized when accessed
637 648
638 fr = frame 649 fr = frame
639 stack = [] 650 stack = []
640 while fr is not None: 651 while fr is not None:
641 # Reset the trace function so we can be sure 652 # Reset the trace function so we can be sure
741 if exctb: 752 if exctb:
742 frlist = self.__extract_stack(exctb) 753 frlist = self.__extract_stack(exctb)
743 frlist.reverse() 754 frlist.reverse()
744 755
745 self.currentFrame = frlist[0] 756 self.currentFrame = frlist[0]
746 self.currentFrameLocals = frlist[0].f_locals
747 # remember the locals because it is reinitialized when accessed
748 757
749 for fr in frlist: 758 for fr in frlist:
750 filename = self._dbgClient.absPath(self.fix_frame_filename(fr)) 759 filename = self._dbgClient.absPath(self.fix_frame_filename(fr))
751 760
752 if os.path.basename(filename).startswith("DebugClient") or \ 761 if os.path.basename(filename).startswith("DebugClient") or \

eric ide

mercurial