93 self.isException = False |
93 self.isException = False |
94 self.cFrame = None |
94 self.cFrame = None |
95 |
95 |
96 # current frame we are at |
96 # current frame we are at |
97 self.currentFrame = None |
97 self.currentFrame = None |
|
98 self.frameList = [] |
|
99 self.getStack() |
98 |
100 |
99 # frames, where we want to stop or release debugger |
101 # frames, where we want to stop or release debugger |
100 self.stopframe = None |
102 self.stopframe = None |
101 self.returnframe = None |
103 self.returnframe = None |
102 self.stop_everywhere = False |
104 self.stop_everywhere = False |
123 time.sleep(0.5) |
125 time.sleep(0.5) |
124 self.eventPollFlag = True |
126 self.eventPollFlag = True |
125 |
127 |
126 self.eventPollFlag = False |
128 self.eventPollFlag = False |
127 |
129 |
128 def getCurrentFrame(self): |
130 def getFrame(self, frmnr=0): |
129 """ |
131 """ |
130 Public method to return the current frame. |
132 Public method to return the frame "frmnr" down the stack. |
131 |
133 |
|
134 @param frmnr distance of frames down the stack. 0 is |
|
135 the current frame |
|
136 @rtype int |
132 @return the current frame |
137 @return the current frame |
133 @rtype frame object |
138 @rtype frame object |
134 """ |
139 """ |
135 # Don't show any local frames after the program was stopped |
140 # Don't show any local frames after the program was stopped |
136 if self.quitting: |
141 if self.quitting: |
137 return None |
142 return None |
138 |
143 |
139 return self.currentFrame |
144 try: |
|
145 return self.frameList[frmnr] |
|
146 except IndexError: |
|
147 return None |
140 |
148 |
141 def getFrameLocals(self, frmnr=0): |
149 def getFrameLocals(self, frmnr=0): |
142 """ |
150 """ |
143 Public method to return the locals dictionary of the current frame |
151 Public method to return the locals dictionary of the current frame |
144 or a frame below. |
152 or a frame below. |
145 |
153 |
146 @param frmnr distance of frame to get locals dictionary of. 0 is |
154 @param frmnr distance of frame to get locals dictionary of. 0 is |
147 the current frame (int) |
155 the current frame (int) |
148 @return locals dictionary of the frame |
156 @return locals dictionary of the frame |
149 """ |
157 """ |
150 f = self.currentFrame |
158 try: |
151 while f is not None and frmnr > 0: |
159 f = self.frameList[frmnr] |
152 f = f.f_back |
160 return f.f_locals |
153 frmnr -= 1 |
161 except IndexError: |
154 return f.f_locals |
162 return {} |
155 |
163 |
156 def storeFrameLocals(self, frmnr=0): |
164 def storeFrameLocals(self, frmnr=0): |
157 """ |
165 """ |
158 Public method to store the locals into the frame, so an access to |
166 Public method to store the locals into the frame, so an access to |
159 frame.f_locals returns the last data. |
167 frame.f_locals returns the last data. |
160 |
168 |
161 @param frmnr distance of frame to store locals dictionary to. 0 is |
169 @param frmnr distance of frame to store locals dictionary to. 0 is |
162 the current frame (int) |
170 the current frame (int) |
163 """ |
171 """ |
164 cf = self.currentFrame |
172 cf = self.frameList[frmnr] |
165 while cf is not None and frmnr > 0: |
|
166 cf = cf.f_back |
|
167 frmnr -= 1 |
|
168 |
173 |
169 with contextlib.suppress(ImportError, AttributeError): |
174 with contextlib.suppress(ImportError, AttributeError): |
170 if "__pypy__" in sys.builtin_module_names: |
175 if "__pypy__" in sys.builtin_module_names: |
171 import __pypy__ # __IGNORE_WARNING_I10__ |
176 import __pypy__ # __IGNORE_WARNING_I10__ |
172 |
177 |
761 @return list of lists with file name (string), line number (integer) |
766 @return list of lists with file name (string), line number (integer) |
762 and function name (string) |
767 and function name (string) |
763 """ |
768 """ |
764 tb_lineno = None |
769 tb_lineno = None |
765 if frame is None: |
770 if frame is None: |
766 fr = self.getCurrentFrame() |
771 fr = self.getFrame() |
767 elif type(frame) == list: |
772 elif type(frame) == list: |
768 fr, tb_lineno = frame.pop(0) |
773 fr, tb_lineno = frame.pop(0) |
769 else: |
774 else: |
770 fr = frame |
775 fr = frame |
771 |
776 |
|
777 self.frameList.clear() |
772 stack = [] |
778 stack = [] |
773 while fr is not None: |
779 while fr is not None: |
|
780 self.frameList.append(fr) |
774 if applyTrace: |
781 if applyTrace: |
775 # Reset the trace function so we can be sure |
782 # Reset the trace function so we can be sure |
776 # to trace all functions up the stack... This gets around |
783 # to trace all functions up the stack... This gets around |
777 # problems where an exception/breakpoint has occurred |
784 # problems where an exception/breakpoint has occurred |
778 # but we had disabled tracing along the way via a None |
785 # but we had disabled tracing along the way via a None |
841 self._dbgClient.currentThreadExec = self |
848 self._dbgClient.currentThreadExec = self |
842 |
849 |
843 self._dbgClient.sendResponseLine(stack, self.name) |
850 self._dbgClient.sendResponseLine(stack, self.name) |
844 self._dbgClient.eventLoop() |
851 self._dbgClient.eventLoop() |
845 |
852 |
|
853 self.frameList.clear() |
|
854 |
846 self.isBroken = False |
855 self.isBroken = False |
847 self._dbgClient.unlockClient() |
856 self._dbgClient.unlockClient() |
848 |
857 |
849 self._dbgClient.dumpThreadList() |
858 self._dbgClient.dumpThreadList() |
850 |
859 |
895 if realSyntaxError: |
904 if realSyntaxError: |
896 self._dbgClient.sendSyntaxError( |
905 self._dbgClient.sendSyntaxError( |
897 message, filename, lineno, charno, self.name |
906 message, filename, lineno, charno, self.name |
898 ) |
907 ) |
899 self._dbgClient.eventLoop() |
908 self._dbgClient.eventLoop() |
|
909 self.frameList.clear() |
900 return |
910 return |
901 |
911 |
902 self.skipFrames = 0 |
912 self.skipFrames = 0 |
903 if ( |
913 if ( |
904 exctype == RuntimeError |
914 exctype == RuntimeError |
959 if exctb is not None: |
969 if exctb is not None: |
960 # When polling kept enabled, it isn't possible to resume after an |
970 # When polling kept enabled, it isn't possible to resume after an |
961 # unhandled exception without further user interaction. |
971 # unhandled exception without further user interaction. |
962 self._dbgClient.eventLoop(True) |
972 self._dbgClient.eventLoop(True) |
963 |
973 |
|
974 self.frameList.clear() |
964 self.skipFrames = 0 |
975 self.skipFrames = 0 |
965 |
976 |
966 self.isBroken = False |
977 self.isBroken = False |
967 self.isException = False |
978 self.isException = False |
968 stop_everywhere = self.stop_everywhere |
979 stop_everywhere = self.stop_everywhere |
993 tb = exctb |
1004 tb = exctb |
994 stack = [] |
1005 stack = [] |
995 while tb is not None: |
1006 while tb is not None: |
996 stack.append((tb.tb_frame, tb.tb_lineno)) |
1007 stack.append((tb.tb_frame, tb.tb_lineno)) |
997 tb = tb.tb_next |
1008 tb = tb.tb_next |
998 tb = None |
1009 |
|
1010 # Follow first frame to bottom to catch special case if an exception |
|
1011 # is thrown in a function with breakpoint in it. |
|
1012 # eric's frames are filtered out later by self.getStack |
|
1013 frame = stack[0][0].f_back |
|
1014 while frame is not None: |
|
1015 stack.insert(0, (frame, frame.f_lineno)) |
|
1016 frame = frame.f_back |
|
1017 |
999 return stack |
1018 return stack |
1000 |
1019 |
1001 def __disassemble(self, frame): |
1020 def __disassemble(self, frame): |
1002 """ |
1021 """ |
1003 Private method to generate a disassembly of the given code object. |
1022 Private method to generate a disassembly of the given code object. |