DebugClients/Python/DebugBase.py

branch
debugger speed
changeset 5012
be693f11da53
parent 5007
e2fa12bb0f53
child 5041
f00a4c8bcbbd
equal deleted inserted replaced
5007:e2fa12bb0f53 5012:be693f11da53
70 self._mainThread = 1 70 self._mainThread = 1
71 71
72 self.breaks = self._dbgClient.breakpoints 72 self.breaks = self._dbgClient.breakpoints
73 self.tracePythonLibs(0) 73 self.tracePythonLibs(0)
74 74
75 self.__event = "" 75 self.__isBroken = False
76 self.__isBroken = ""
77 self.cFrame = None 76 self.cFrame = None
78 77
79 # current frame we are at 78 # current frame we are at
80 self.currentFrame = None 79 self.currentFrame = None
81 80
230 229
231 This specialty is to check the connection to the debug server 230 This specialty is to check the connection to the debug server
232 for new events (i.e. new breakpoints) while we are going through 231 for new events (i.e. new breakpoints) while we are going through
233 the code. 232 the code.
234 233
235 @param frame The current stack frame. 234 @param frame The current stack frame
236 @param event The trace event (string) 235 @type frame object
236 @param event The trace event
237 @type str
237 @param arg The arguments 238 @param arg The arguments
239 @type depends on the previous event parameter
238 @return local trace function 240 @return local trace function
241 @rtype trace function or None
242 @exception bdb.BdbQuit
239 """ 243 """
240 if self.quitting: 244 if self.quitting:
241 return # None 245 return # None
242 246
243 # give the client a chance to push through new break points. 247 # give the client a chance to push through new break points.
244 self._dbgClient.eventPoll() 248 self._dbgClient.eventPoll()
245 249
246 self.__event == event
247 self.__isBroken = False
248
249 if event == 'line': 250 if event == 'line':
250 return self.dispatch_line(frame) 251 if self.stop_here(frame) or self.break_here(frame):
252 self.user_line(frame)
253 if self.quitting:
254 raise bdb.BdbQuit
255 return
256
251 if event == 'call': 257 if event == 'call':
252 return self.dispatch_call(frame, arg) 258 if self.botframe is None:
253 if event == 'return': 259 # First call of dispatch since reset()
254 return self.dispatch_return(frame, arg) 260 # (CT) Note that this may also be None!
255 if event == 'exception': 261 self.botframe = frame.f_back
256 return self.dispatch_exception(frame, arg) 262 return self.trace_dispatch
257 if event == 'c_call': 263
258 return self.trace_dispatch 264 if not (self.stop_here(frame) or self.break_anywhere(frame)):
259 if event == 'c_exception': 265 # No need to trace this function
260 return self.trace_dispatch 266 return
261 if event == 'c_return':
262 return self.trace_dispatch
263 print 'DebugBase.trace_dispatch: unknown debugging event:', repr(event) # __IGNORE_WARNING__
264 return self.trace_dispatch
265
266 def dispatch_line(self, frame):
267 """
268 Public method reimplemented from bdb.py to do some special things.
269
270 This speciality is to check the connection to the debug server
271 for new events (i.e. new breakpoints) while we are going through
272 the code.
273
274 @param frame The current stack frame.
275 @return local trace function
276 @exception bdb.BdbQuit raised to indicate the end of the debug session
277 """
278 if self.stop_here(frame) or self.break_here(frame):
279 self.user_line(frame)
280 if self.quitting: 267 if self.quitting:
281 raise bdb.BdbQuit 268 raise bdb.BdbQuit
282 return self.trace_dispatch 269 return self.trace_dispatch
283 270
284 def dispatch_return(self, frame, arg): 271 if event == 'return':
285 """ 272 if self.stop_here(frame) or frame == self.returnframe:
286 Public method reimplemented from bdb.py to handle passive mode cleanly. 273 # The program has finished if we have just left the first frame
287 274 if frame == self._dbgClient.mainFrame and \
288 @param frame The current stack frame. 275 self._mainThread:
289 @param arg The arguments 276 atexit._run_exitfuncs()
290 @return local trace function 277 self._dbgClient.progTerminated(arg)
291 @exception bdb.BdbQuit raised to indicate the end of the debug session 278 elif frame is not self.stepFrame:
292 """ 279 self.stepFrame = None
293 if self.stop_here(frame) or frame == self.returnframe: 280 self.user_line(frame)
294 self.user_return(frame, arg) 281
295 if self.quitting and not self._dbgClient.passive: 282 if self.quitting and not self._dbgClient.passive:
296 raise bdb.BdbQuit 283 raise bdb.BdbQuit
297 return self.trace_dispatch 284 return
298 285
299 def dispatch_exception(self, frame, arg): 286 if event == 'exception':
300 """ 287 if not self.__skipFrame(frame):
301 Public method reimplemented from bdb.py to always call user_exception. 288 self.user_exception(frame, arg)
302 289 if self.quitting:
303 @param frame The current stack frame. 290 raise bdb.BdbQuit
304 @param arg The arguments 291 return
305 @return local trace function 292
306 @exception bdb.BdbQuit raised to indicate the end of the debug session 293 if event == 'c_call':
307 """ 294 return
308 if not self.__skipFrame(frame): 295 if event == 'c_exception':
309 self.user_exception(frame, arg) 296 return
310 if self.quitting: 297 if event == 'c_return':
311 raise bdb.BdbQuit 298 return
299 print 'DebugBase.trace_dispatch: unknown debugging event:', repr(event) # __IGNORE_WARNING__
312 return self.trace_dispatch 300 return self.trace_dispatch
313 301
314 def set_trace(self, frame=None): 302 def set_trace(self, frame=None):
315 """ 303 """
316 Public method reimplemented from bdb.py to do some special setup. 304 Public method reimplemented from bdb.py to do some special setup.
716 704
717 self.__isBroken = True 705 self.__isBroken = True
718 706
719 self._dbgClient.write('%s%s\n' % (ResponseLine, unicode(stack))) 707 self._dbgClient.write('%s%s\n' % (ResponseLine, unicode(stack)))
720 self._dbgClient.eventLoop() 708 self._dbgClient.eventLoop()
709
710 self.__isBroken = False
721 711
722 def user_exception(self, frame, (exctype, excval, exctb), unhandled=0): 712 def user_exception(self, frame, (exctype, excval, exctb), unhandled=0):
723 """ 713 """
724 Public method reimplemented to report an exception to the debug server. 714 Public method reimplemented to report an exception to the debug server.
725 715
830 stack.append(tb.tb_frame) 820 stack.append(tb.tb_frame)
831 tb = tb.tb_next 821 tb = tb.tb_next
832 tb = None 822 tb = None
833 return stack 823 return stack
834 824
835 def user_return(self, frame, retval):
836 """
837 Public method reimplemented to report program termination to the debug
838 server.
839
840 @param frame the frame object
841 @param retval the return value of the program
842 """
843 # The program has finished if we have just left the first frame.
844 if frame == self._dbgClient.mainFrame and \
845 self._mainThread:
846 atexit._run_exitfuncs()
847 self._dbgClient.progTerminated(retval)
848 elif frame is not self.stepFrame:
849 self.stepFrame = None
850 self.user_line(frame)
851
852 def stop_here(self, frame): 825 def stop_here(self, frame):
853 """ 826 """
854 Public method reimplemented to filter out debugger files. 827 Public method reimplemented to filter out debugger files.
855 828
856 Tracing is turned off for files that are part of the 829 Tracing is turned off for files that are part of the
907 880
908 def isBroken(self): 881 def isBroken(self):
909 """ 882 """
910 Public method to return the broken state of the debugger. 883 Public method to return the broken state of the debugger.
911 884
912 @return flag indicating the broken state (boolean) 885 @return flag indicating the broken state
886 @rtype bool
913 """ 887 """
914 return self.__isBroken 888 return self.__isBroken
915
916 def getEvent(self):
917 """
918 Protected method to return the last debugger event.
919
920 @return last debugger event (string)
921 """
922 return self.__event
923 889
924 # 890 #
925 # eflag: FileType = Python2 891 # eflag: FileType = Python2
926 # eflag: noqa = M601, M702 892 # eflag: noqa = M601, M702

eric ide

mercurial