DebugClients/Python/DebugBase.py

branch
debugger speed
changeset 5206
997064ba25d6
parent 5205
df1709f0e49f
child 5207
7283629b02c0
equal deleted inserted replaced
5205:df1709f0e49f 5206:997064ba25d6
71 Constructor 71 Constructor
72 72
73 @param dbgClient the owning client 73 @param dbgClient the owning client
74 """ 74 """
75 self._dbgClient = dbgClient 75 self._dbgClient = dbgClient
76 if sys.version_info[0] == 2:
77 self.stopOnHandleLine = self._dbgClient.handleLine.func_code
78 else:
79 self.stopOnHandleLine = self._dbgClient.handleLine.__code__
80 76
81 self._mainThread = True 77 self._mainThread = True
82 self.quitting = 0 78 self.quitting = False
83 79
84 self.tracePythonLibs(0) 80 self.tracePythonLibs(0)
85 81
86 # Special handling of a recursion error 82 # Special handling of a recursion error
87 self.skipFrames = 0 83 self.skipFrames = 0
88 84
89 self.__isBroken = False 85 self.isBroken = False
90 self.cFrame = None 86 self.cFrame = None
91 87
92 # current frame we are at 88 # current frame we are at
93 self.currentFrame = None 89 self.currentFrame = None
94 90
95 # frame that we are stepping in, can be different than currentFrame 91 # frames, where we want to stop or release debugger
96 self.stepFrame = None
97
98 self.botframe = None 92 self.botframe = None
99 self.stopframe = None 93 self.stopframe = None
100 self.returnframe = None 94 self.returnframe = None
101 self.stop_everywhere = False 95 self.stop_everywhere = False
102 96
173 Public method to perform a step operation in this thread. 167 Public method to perform a step operation in this thread.
174 168
175 @param traceMode If it is True, then the step is a step into, 169 @param traceMode If it is True, then the step is a step into,
176 otherwise it is a step over. 170 otherwise it is a step over.
177 """ 171 """
178 self.stepFrame = self.currentFrame
179
180 if traceMode: 172 if traceMode:
181 self.currentFrame = None
182 self.set_step() 173 self.set_step()
183 else: 174 else:
184 self.set_next(self.currentFrame) 175 self.set_next(self.currentFrame)
185 176
186 def stepOut(self): 177 def stepOut(self):
187 """ 178 """
188 Public method to perform a step out of the current call. 179 Public method to perform a step out of the current call.
189 """ 180 """
190 self.stepFrame = self.currentFrame
191 self.set_return(self.currentFrame) 181 self.set_return(self.currentFrame)
192 182
193 def go(self, special): 183 def go(self, special):
194 """ 184 """
195 Public method to resume the thread. 185 Public method to resume the thread.
196 186
197 It resumes the thread stopping only at breakpoints or exceptions. 187 It resumes the thread stopping only at breakpoints or exceptions.
198 188
199 @param special flag indicating a special continue operation 189 @param special flag indicating a special continue operation
200 """ 190 """
201 self.currentFrame = None
202 self.set_continue(special) 191 self.set_continue(special)
203 192
204 def setRecursionDepth(self, frame): 193 def setRecursionDepth(self, frame):
205 """ 194 """
206 Public method to determine the current recursion depth. 195 Public method to determine the current recursion depth.
387 @type frame object 376 @type frame object
388 """ 377 """
389 if frame is None: 378 if frame is None:
390 frame = sys._getframe().f_back # Skip set_trace method 379 frame = sys._getframe().f_back # Skip set_trace method
391 380
381 if sys.version_info[0] == 2:
382 stopOnHandleLine = self._dbgClient.handleLine.func_code
383 bootstrap = '__bootstrap'
384 else:
385 stopOnHandleLine = self._dbgClient.handleLine.__code__
386 bootstrap = 'bootstrap'
387
392 frame.f_trace = self.trace_dispatch 388 frame.f_trace = self.trace_dispatch
393 while frame is not None: 389 while frame is not None:
394 # stop at erics debugger frame 390 # stop at erics debugger frame
395 if frame.f_back.f_code == self.stopOnHandleLine: 391 if frame.f_back.f_code == stopOnHandleLine:
396 frame.f_trace = self.trace_dispatch 392 frame.f_trace = self.trace_dispatch
397 self.botframe = frame 393 self.botframe = frame
398 break 394 break
399 395
400 frame = frame.f_back 396 frame = frame.f_back
428 try: 424 try:
429 exec(cmd, globals, locals) 425 exec(cmd, globals, locals)
430 except SystemExit: 426 except SystemExit:
431 pass 427 pass
432 finally: 428 finally:
433 self.quitting = 1 429 self.quitting = True
434 sys.settrace(None) 430 sys.settrace(None)
435 431
436 def _set_stopinfo(self, stopframe, returnframe): 432 def _set_stopinfo(self, stopframe, returnframe):
437 """ 433 """
438 Protected method to update the frame pointers. 434 Protected method to update the frame pointers.
493 """ 489 """
494 Public method to quit. 490 Public method to quit.
495 491
496 Disables the trace functions and resets all frame pointer. 492 Disables the trace functions and resets all frame pointer.
497 """ 493 """
498 self.currentFrame = None
499 sys.setprofile(None) 494 sys.setprofile(None)
500 sys.settrace(None) 495 sys.settrace(None)
501 self.stopframe = None 496 self.stopframe = None
502 self.returnframe = None 497 self.returnframe = None
503 self.quitting = 1 498 self.quitting = True
504 499
505 def fix_frame_filename(self, frame): 500 def fix_frame_filename(self, frame):
506 """ 501 """
507 Public method used to fixup the filename for a given frame. 502 Public method used to fixup the filename for a given frame.
508 503
718 return 713 return
719 714
720 self.currentFrame = frame 715 self.currentFrame = frame
721 stack = self.getStack(frame, applyTrace=True) 716 stack = self.getStack(frame, applyTrace=True)
722 717
723 self.__isBroken = True 718 self.isBroken = True
724 719
725 self._dbgClient.sendResponseLine(stack) 720 self._dbgClient.sendResponseLine(stack)
726 self._dbgClient.eventLoop() 721 self._dbgClient.eventLoop()
727 722
728 self.__isBroken = False 723 self.isBroken = False
729 724
730 def user_exception(self, frame, excinfo, unhandled=False): 725 def user_exception(self, frame, excinfo, unhandled=False):
731 """ 726 """
732 Public method reimplemented to report an exception to the debug server. 727 Public method reimplemented to report an exception to the debug server.
733 728
734 @param frame the frame object 729 @param frame the frame object
806 return 801 return
807 802
808 self.skipFrames = 0 803 self.skipFrames = 0
809 if (exctype == RuntimeError and 804 if (exctype == RuntimeError and
810 str(excval).startswith('maximum recursion depth exceeded') or 805 str(excval).startswith('maximum recursion depth exceeded') or
811 sys.version_info >= (3, 5) and exctype == RecursionError): 806 sys.version_info >= (3, 5) and
807 exctype == RecursionError): # __IGNORE_WARNING__
812 excval = 'maximum recursion depth exceeded' 808 excval = 'maximum recursion depth exceeded'
813 depth = 0 809 depth = 0
814 tb = exctb 810 tb = exctb
815 while tb: 811 while tb:
816 tb = tb.tb_next 812 tb = tb.tb_next
949 return ret 945 return ret
950 except AttributeError: 946 except AttributeError:
951 # if frame is None 947 # if frame is None
952 return True 948 return True
953 949
954 def isBroken(self):
955 """
956 Public method to return the broken state of the debugger.
957
958 @return flag indicating the broken state
959 @rtype bool
960 """
961 return self.__isBroken
962
963 # 950 #
964 # eflag: noqa = M702 951 # eflag: noqa = M702

eric ide

mercurial