diff -r e2fa12bb0f53 -r be693f11da53 DebugClients/Python3/DebugBase.py --- a/DebugClients/Python3/DebugBase.py Fri Jul 01 21:54:07 2016 +0200 +++ b/DebugClients/Python3/DebugBase.py Sat Jul 02 21:58:09 2016 +0200 @@ -73,8 +73,7 @@ self.breaks = self._dbgClient.breakpoints self.tracePythonLibs(0) - self.__event = "" - self.__isBroken = "" + self.__isBroken = False self.cFrame = None # current frame we are at @@ -233,10 +232,15 @@ for new events (i.e. new breakpoints) while we are going through the code. - @param frame The current stack frame. - @param event The trace event (string) + @param frame The current stack frame + @type frame object + @param event The trace event + @type str @param arg The arguments + @type depends on the previous event parameter @return local trace function + @rtype trace function or None + @exception bdb.BdbQuit """ if self.quitting: return # None @@ -244,92 +248,75 @@ # give the client a chance to push through new break points. self._dbgClient.eventPoll() - self.__event == event - self.__isBroken = False + if event == 'line': + if self.stop_here(frame) or self.break_here(frame): + self.user_line(frame) + if self.quitting: + raise bdb.BdbQuit + return - if event == 'line': - return self.dispatch_line(frame) if event == 'call': - return self.dispatch_call(frame, arg) - if event == 'return': - return self.dispatch_return(frame, arg) - if event == 'exception': - return self.dispatch_exception(frame, arg) - if event == 'c_call': - return self.trace_dispatch - if event == 'c_exception': - return self.trace_dispatch - if event == 'c_return': - return self.trace_dispatch - print('bdb.Bdb.dispatch: unknown debugging event: ', repr(event)) # __IGNORE_WARNING__ - return self.trace_dispatch - - def dispatch_line(self, frame): - """ - Public method reimplemented from bdb.py to do some special things. - - This speciality is to check the connection to the debug server - for new events (i.e. new breakpoints) while we are going through - the code. - - @param frame The current stack frame. - @return local trace function - @exception bdb.BdbQuit raised to indicate the end of the debug session - """ - if self.stop_here(frame) or self.break_here(frame): - self.user_line(frame) + if self.botframe is None: + # First call of dispatch since reset() + # (CT) Note that this may also be None! + self.botframe = frame.f_back + return self.trace_dispatch + + if not (self.stop_here(frame) or self.break_anywhere(frame)): + # No need to trace this function + return if self.quitting: raise bdb.BdbQuit - return self.trace_dispatch - - def dispatch_return(self, frame, arg): - """ - Public method reimplemented from bdb.py to handle passive mode cleanly. + return self.trace_dispatch - @param frame The current stack frame. - @param arg The arguments - @return local trace function - @exception bdb.BdbQuit raised to indicate the end of the debug session - """ - if self.stop_here(frame) or frame == self.returnframe: - # Ignore return events in generator except when stepping. - if self.stopframe and frame.f_code.co_flags & CO_GENERATOR: - return self.trace_dispatch - self.user_return(frame, arg) - if self.quitting and not self._dbgClient.passive: - raise bdb.BdbQuit - return self.trace_dispatch - - def dispatch_exception(self, frame, arg): - """ - Public method reimplemented from bdb.py to always call user_exception. + if event == 'return': + if self.stop_here(frame) or frame == self.returnframe: + # Ignore return events in generator except when stepping. + if self.stopframe and frame.f_code.co_flags & CO_GENERATOR: + return + # The program has finished if we have just left the first frame + if frame == self._dbgClient.mainFrame and \ + self._mainThread: + atexit._run_exitfuncs() + self._dbgClient.progTerminated(arg) + elif frame is not self.stepFrame: + self.stepFrame = None + self.user_line(frame) + + if self.quitting and not self._dbgClient.passive: + raise bdb.BdbQuit + return - @param frame The current stack frame. - @param arg The arguments - @return local trace function - @exception bdb.BdbQuit raised to indicate the end of the debug session - """ - if not self.__skipFrame(frame): - # When stepping with next/until/return in a generator frame, - # skip the internal StopIteration exception (with no traceback) - # triggered by a subiterator run with the 'yield from' - # statement. - if not (frame.f_code.co_flags & CO_GENERATOR and - arg[0] is StopIteration and arg[2] is None): + if event == 'exception': + if not self.__skipFrame(frame): + # When stepping with next/until/return in a generator frame, + # skip the internal StopIteration exception (with no traceback) + # triggered by a subiterator run with the 'yield from' + # statement. + if not (frame.f_code.co_flags & CO_GENERATOR and + arg[0] is StopIteration and arg[2] is None): + self.user_exception(frame, arg) + if self.quitting: + raise bdb.BdbQuit + # Stop at the StopIteration or GeneratorExit exception when the user + # has set stopframe in a generator by issuing a return command, or a + # next/until command at the last statement in the generator before the + # exception. + elif (self.stopframe and frame is not self.stopframe and + self.stopframe.f_code.co_flags & CO_GENERATOR and + arg[0] in (StopIteration, GeneratorExit)): self.user_exception(frame, arg) if self.quitting: raise bdb.BdbQuit - # Stop at the StopIteration or GeneratorExit exception when the user - # has set stopframe in a generator by issuing a return command, or a - # next/until command at the last statement in the generator before the - # exception. - elif (self.stopframe and frame is not self.stopframe and - self.stopframe.f_code.co_flags & CO_GENERATOR and - arg[0] in (StopIteration, GeneratorExit)): - self.user_exception(frame, arg) - if self.quitting: - raise bdb.BdbQuit - + return + + if event == 'c_call': + return + if event == 'c_exception': + return + if event == 'c_return': + return + print('bdb.Bdb.dispatch: unknown debugging event: ', repr(event)) # __IGNORE_WARNING__ return self.trace_dispatch def set_trace(self, frame=None): @@ -747,6 +734,8 @@ self._dbgClient.write('{0}{1}\n'.format(ResponseLine, str(stack))) self._dbgClient.eventLoop() + + self.__isBroken = False def user_exception(self, frame, excinfo, unhandled=False): """ @@ -876,23 +865,6 @@ tb = None return stack - def user_return(self, frame, retval): - """ - Public method reimplemented to report program termination to the debug - server. - - @param frame the frame object - @param retval the return value of the program - """ - # The program has finished if we have just left the first frame. - if frame == self._dbgClient.mainFrame and \ - self._mainThread: - atexit._run_exitfuncs() - self._dbgClient.progTerminated(retval) - elif frame is not self.stepFrame: - self.stepFrame = None - self.user_line(frame) - def stop_here(self, frame): """ Public method reimplemented to filter out debugger files. @@ -954,17 +926,10 @@ """ Public method to return the broken state of the debugger. - @return flag indicating the broken state (boolean) + @return flag indicating the broken state + @rtype bool """ return self.__isBroken - - def getEvent(self): - """ - Protected method to return the last debugger event. - - @return last debugger event (string) - """ - return self.__event # # eflag: noqa = M702