Exemple #1
0
 def getStack(self):
     """
     Public method to get the stack.
     
     @return list of lists with file name (string), line number (integer)
         and function name (string)
     """
     fr = self.cFrame
     stack = []
     while fr is not None:
         fname = self._dbgClient.absPath(self.fix_frame_filename(fr))
         if not fname.startswith("<"):
             fline = fr.f_lineno
             ffunc = fr.f_code.co_name
             
             if ffunc == '?':
                 ffunc = ''
             
             if ffunc and not ffunc.startswith("<"):
                 argInfo = getargvalues(fr)
                 try:
                     fargs = formatargvalues(
                         argInfo.args, argInfo.varargs,
                         argInfo.keywords, argInfo.locals)
                 except Exception:
                     fargs = ""
             else:
                 fargs = ""
             
             stack.append([fname, fline, ffunc, fargs])
         
         if fr == self._dbgClient.mainFrame:
             fr = None
         else:
             fr = fr.f_back
     
     return stack
Exemple #2
0
    def getStack(self):
        """
        Public method to get the stack.
        
        @return list of lists with file name (string), line number (integer)
            and function name (string)
        """
        fr = self.cFrame
        stack = []
        while fr is not None:
            fname = self._dbgClient.absPath(self.fix_frame_filename(fr))
            if not fname.startswith("<"):
                fline = fr.f_lineno
                ffunc = fr.f_code.co_name

                if ffunc == '?':
                    ffunc = ''

                if ffunc and not ffunc.startswith("<"):
                    argInfo = getargvalues(fr)
                    try:
                        fargs = formatargvalues(argInfo.args, argInfo.varargs,
                                                argInfo.keywords,
                                                argInfo.locals)
                    except Exception:
                        fargs = ""
                else:
                    fargs = ""

                stack.append([fname, fline, ffunc, fargs])

            if fr == self._dbgClient.mainFrame:
                fr = None
            else:
                fr = fr.f_back

        return stack
Exemple #3
0
 def user_exception(self, frame, excinfo, unhandled=False):
     """
     Public method reimplemented to report an exception to the debug server.
     
     @param frame the frame object
     @param excinfo information about the exception
     @param unhandled flag indicating an uncaught exception
     """
     exctype, excval, exctb = excinfo
     
     if exctype in [GeneratorExit, StopIteration]:
         # ignore these
         return
     
     if exctype in [SystemExit, bdb.BdbQuit]:
         atexit._run_exitfuncs()
         if excval is None:
             excval = 0
         elif isinstance(excval, str):
             self._dbgClient.write(excval)
             excval = 1
         elif isinstance(excval, bytes):
             self._dbgClient.write(excval.decode())
             excval = 1
         if isinstance(excval, int):
             self._dbgClient.progTerminated(excval)
         else:
             self._dbgClient.progTerminated(excval.code)
         return
     
     if exctype in [SyntaxError, IndentationError]:
         try:
             message = str(excval)
             filename = excval.filename
             linenr = excval.lineno
             charnr = excval.offset
         except (AttributeError, ValueError):
             exclist = []
             realSyntaxError = True
         else:
             exclist = [message, [filename, linenr, charnr]]
             realSyntaxError = os.path.exists(filename)
         
         if realSyntaxError:
             self._dbgClient.write("{0}{1}\n".format(
                 ResponseSyntax, str(exclist)))
             self._dbgClient.eventLoop()
             return
     
     exctype = self.__extractExceptionName(exctype)
     
     if excval is None:
         excval = ''
     
     if unhandled:
         exctypetxt = "unhandled {0!s}".format(str(exctype))
     else:
         exctypetxt = str(exctype)
     try:
         exclist = [exctypetxt, str(excval)]
     except TypeError:
         exclist = [exctypetxt, str(excval)]
     
     if exctb:
         frlist = self.__extract_stack(exctb)
         frlist.reverse()
         
         self.currentFrame = frlist[0]
         self.currentFrameLocals = frlist[0].f_locals
         # remember the locals because it is reinitialized when accessed
         
         for fr in frlist:
             filename = self._dbgClient.absPath(self.fix_frame_filename(fr))
             
             if os.path.basename(filename).startswith("DebugClient") or \
                os.path.basename(filename) == "bdb.py":
                 break
             
             linenr = fr.f_lineno
             ffunc = fr.f_code.co_name
             
             if ffunc == '?':
                 ffunc = ''
             
             if ffunc and not ffunc.startswith("<"):
                 argInfo = getargvalues(fr)
                 try:
                     fargs = formatargvalues(
                         argInfo.args, argInfo.varargs,
                         argInfo.keywords, argInfo.locals)
                 except Exception:
                     fargs = ""
             else:
                 fargs = ""
             
             exclist.append([filename, linenr, ffunc, fargs])
     
     self._dbgClient.write("{0}{1}\n".format(
         ResponseException, str(exclist)))
     
     if exctb is None:
         return
     
     self._dbgClient.eventLoop()
Exemple #4
0
    def user_line(self, frame):
        """
        Public method reimplemented to handle the program about to execute a
        particular line.
        
        @param frame the frame object
        """
        line = frame.f_lineno

        # We never stop on line 0.
        if line == 0:
            return

        fn = self._dbgClient.absPath(self.fix_frame_filename(frame))

        # See if we are skipping at the start of a newly loaded program.
        if self._dbgClient.mainFrame is None:
            if fn != self._dbgClient.getRunning():
                return
            self._dbgClient.mainFrame = frame

        self.currentFrame = frame
        self.currentFrameLocals = frame.f_locals
        # remember the locals because it is reinitialized when accessed
        
        fr = frame
        stack = []
        while fr is not None:
            # Reset the trace function so we can be sure
            # to trace all functions up the stack... This gets around
            # problems where an exception/breakpoint has occurred
            # but we had disabled tracing along the way via a None
            # return from dispatch_call
            fr.f_trace = self.trace_dispatch
            fname = self._dbgClient.absPath(self.fix_frame_filename(fr))
            if not fname.startswith("<"):
                fline = fr.f_lineno
                ffunc = fr.f_code.co_name
                
                if ffunc == '?':
                    ffunc = ''
                
                if ffunc and not ffunc.startswith("<"):
                    argInfo = getargvalues(fr)
                    try:
                        fargs = formatargvalues(
                            argInfo.args, argInfo.varargs,
                            argInfo.keywords, argInfo.locals)
                    except Exception:
                        fargs = ""
                else:
                    fargs = ""
                
                stack.append([fname, fline, ffunc, fargs])
            
            if fr == self._dbgClient.mainFrame:
                fr = None
            else:
                fr = fr.f_back
        
        self.__isBroken = True
        
        self._dbgClient.write('{0}{1}\n'.format(ResponseLine, str(stack)))
        self._dbgClient.eventLoop()
Exemple #5
0
    def user_exception(self, frame, excinfo, unhandled=False):
        """
        Public method reimplemented to report an exception to the debug server.
        
        @param frame the frame object
        @param excinfo information about the exception
        @param unhandled flag indicating an uncaught exception
        """
        exctype, excval, exctb = excinfo

        if exctype in [GeneratorExit, StopIteration]:
            # ignore these
            return

        if exctype in [SystemExit, bdb.BdbQuit]:
            atexit._run_exitfuncs()
            if excval is None:
                excval = 0
            elif isinstance(excval, str):
                self._dbgClient.write(excval)
                excval = 1
            elif isinstance(excval, bytes):
                self._dbgClient.write(excval.decode())
                excval = 1
            if isinstance(excval, int):
                self._dbgClient.progTerminated(excval)
            else:
                self._dbgClient.progTerminated(excval.code)
            return

        if exctype in [SyntaxError, IndentationError]:
            try:
                message = str(excval)
                filename = excval.filename
                linenr = excval.lineno
                charnr = excval.offset
            except (AttributeError, ValueError):
                exclist = []
                realSyntaxError = True
            else:
                exclist = [message, [filename, linenr, charnr]]
                realSyntaxError = os.path.exists(filename)

            if realSyntaxError:
                self._dbgClient.write("{0}{1}\n".format(
                    ResponseSyntax, str(exclist)))
                self._dbgClient.eventLoop()
                return

        exctype = self.__extractExceptionName(exctype)

        if excval is None:
            excval = ''

        if unhandled:
            exctypetxt = "unhandled {0!s}".format(str(exctype))
        else:
            exctypetxt = str(exctype)
        try:
            exclist = [exctypetxt, str(excval)]
        except TypeError:
            exclist = [exctypetxt, str(excval)]

        if exctb:
            frlist = self.__extract_stack(exctb)
            frlist.reverse()

            self.currentFrame = frlist[0]

            for fr in frlist:
                filename = self._dbgClient.absPath(self.fix_frame_filename(fr))

                if os.path.basename(filename).startswith("DebugClient") or \
                   os.path.basename(filename) == "bdb.py":
                    break

                linenr = fr.f_lineno
                ffunc = fr.f_code.co_name

                if ffunc == '?':
                    ffunc = ''

                if ffunc and not ffunc.startswith("<"):
                    argInfo = getargvalues(fr)
                    try:
                        fargs = formatargvalues(argInfo.args, argInfo.varargs,
                                                argInfo.keywords,
                                                argInfo.locals)
                    except Exception:
                        fargs = ""
                else:
                    fargs = ""

                exclist.append([filename, linenr, ffunc, fargs])

        self._dbgClient.write("{0}{1}\n".format(ResponseException,
                                                str(exclist)))

        if exctb is None:
            return

        self._dbgClient.eventLoop()
Exemple #6
0
    def user_line(self, frame):
        """
        Public method reimplemented to handle the program about to execute a
        particular line.
        
        @param frame the frame object
        """
        line = frame.f_lineno

        # We never stop on line 0.
        if line == 0:
            return

        fn = self._dbgClient.absPath(self.fix_frame_filename(frame))

        # See if we are skipping at the start of a newly loaded program.
        if self._dbgClient.mainFrame is None:
            if fn != self._dbgClient.getRunning():
                return
            fr = frame
            while (fr is not None
                   and fr.f_code != self._dbgClient.handleLine.__code__):
                self._dbgClient.mainFrame = fr
                fr = fr.f_back

        self.currentFrame = frame

        fr = frame
        stack = []
        while fr is not None:
            # Reset the trace function so we can be sure
            # to trace all functions up the stack... This gets around
            # problems where an exception/breakpoint has occurred
            # but we had disabled tracing along the way via a None
            # return from dispatch_call
            fr.f_trace = self.trace_dispatch
            fname = self._dbgClient.absPath(self.fix_frame_filename(fr))
            if not fname.startswith("<"):
                fline = fr.f_lineno
                ffunc = fr.f_code.co_name

                if ffunc == '?':
                    ffunc = ''

                if ffunc and not ffunc.startswith("<"):
                    argInfo = getargvalues(fr)
                    try:
                        fargs = formatargvalues(argInfo.args, argInfo.varargs,
                                                argInfo.keywords,
                                                argInfo.locals)
                    except Exception:
                        fargs = ""
                else:
                    fargs = ""

                stack.append([fname, fline, ffunc, fargs])

            if fr == self._dbgClient.mainFrame:
                fr = None
            else:
                fr = fr.f_back

        self.__isBroken = True

        self._dbgClient.write('{0}{1}\n'.format(ResponseLine, str(stack)))
        self._dbgClient.eventLoop()