DebugClients/Python3/DebugBase.py

branch
debugger speed
changeset 5174
8c48f5e0cd92
parent 5088
5b992bcb3c86
parent 5169
74e000797a93
diff -r fb9168c2e069 -r 8c48f5e0cd92 DebugClients/Python3/DebugBase.py
--- a/DebugClients/Python3/DebugBase.py	Thu Sep 15 21:49:13 2016 +0200
+++ b/DebugClients/Python3/DebugBase.py	Sun Sep 18 21:35:53 2016 +0200
@@ -16,8 +16,6 @@
 import time
 from inspect import CO_GENERATOR
 
-from DebugProtocol import ResponseClearWatch, ResponseClearBreak, \
-    ResponseLine, ResponseSyntax, ResponseException, CallTrace
 from DebugUtilities import getargvalues, formatargvalues
 from BreakpointWatch import Breakpoint, Watch
 
@@ -144,6 +142,15 @@
         while cf is not None and frmnr > 0:
             cf = cf.f_back
             frmnr -= 1
+        
+        try:
+            if "__pypy__" in sys.builtin_module_names:
+                import __pypy__
+                __pypy__.locals_to_fast(cf)
+                return
+        except Exception:
+            pass
+        
         ctypes.pythonapi.PyFrame_LocalsToFast(
             ctypes.py_object(cf),
             ctypes.c_int(0))
@@ -249,16 +256,19 @@
         @type frame object
         """
         if not self.__skipFrame(fromFrame) and not self.__skipFrame(toFrame):
-            fromStr = "{0}:{1}:{2}".format(
-                self._dbgClient.absPath(self.fix_frame_filename(fromFrame)),
-                fromFrame.f_lineno,
-                fromFrame.f_code.co_name)
-            toStr = "{0}:{1}:{2}".format(
-                self._dbgClient.absPath(self.fix_frame_filename(toFrame)),
-                toFrame.f_lineno,
-                toFrame.f_code.co_name)
-            self._dbgClient.write("{0}{1}@@{2}@@{3}\n".format(
-                CallTrace, event[0], fromStr, toStr))
+            fromInfo = {
+                "filename": self._dbgClient.absPath(
+                    self.fix_frame_filename(fromFrame)),
+                "linenumber": fromFrame.f_lineno,
+                "codename": fromFrame.f_code.co_name,
+            }
+            toInfo = {
+                "filename": self._dbgClient.absPath(
+                    self.fix_frame_filename(toFrame)),
+                "linenumber": toFrame.f_lineno,
+                "codename": toFrame.f_code.co_name,
+            }
+            self._dbgClient.sendCallTrace(event, fromInfo, toInfo)
     
     def trace_dispatch(self, frame, event, arg):
         """
@@ -313,8 +323,8 @@
                 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:
+                if (frame == self._dbgClient.mainFrame and
+                        self._mainThread):
                     atexit._run_exitfuncs()
                     self._dbgClient.progTerminated(arg)
                 
@@ -347,7 +357,10 @@
             return
         if event == 'c_return':
             return
-        print('bdb.Bdb.dispatch: unknown debugging event: ', repr(event))   # __IGNORE_WARNING__
+        
+        print('DebugBase.trace_dispatch:'       # __IGNORE_WARNING__
+              ' unknown debugging event: ',
+              repr(event))
         return self.trace_dispatch
 
     def set_trace(self, frame=None):
@@ -599,8 +612,7 @@
         @type int
         """
         Breakpoint.clear_break(filename, lineno)
-        self._dbgClient.write('{0}{1},{2:d}\n'.format(
-                              ResponseClearBreak, filename, lineno))
+        self._dbgClient.sendClearTemporaryBreakpoint(filename, lineno)
 
     def __do_clearWatch(self, cond):
         """
@@ -610,7 +622,7 @@
         @type str
         """
         Watch.clear_watch(cond)
-        self._dbgClient.write('{0}{1}\n'.format(ResponseClearWatch, cond))
+        self._dbgClient.sendClearTemporaryWatch(cond)
 
     def getStack(self):
         """
@@ -700,7 +712,7 @@
         
         self.__isBroken = True
         
-        self._dbgClient.write('{0}{1}\n'.format(ResponseLine, str(stack)))
+        self._dbgClient.sendResponseLine(stack)
         self._dbgClient.eventLoop()
         
         self.__isBroken = False
@@ -725,35 +737,54 @@
         if exctype == SystemExit:
             atexit._run_exitfuncs()
             if excval is None:
-                excval = 0
+                exitcode = 0
+                message = ""
             elif isinstance(excval, str):
-                self._dbgClient.write(excval)
-                excval = 1
+                exitcode = 1
+                message = excval
             elif isinstance(excval, bytes):
-                self._dbgClient.write(excval.decode())
-                excval = 1
-            if isinstance(excval, int):
-                self._dbgClient.progTerminated(excval)
+                exitcode = 1
+                message = excval.decode()
+            elif isinstance(excval, int):
+                exitcode = excval
+                message = ""
+            elif isinstance(excval, SystemExit):
+                code = excval.code
+                if isinstance(code, str):
+                    exitcode = 1
+                    message = code
+                elif isinstance(code, bytes):
+                    exitcode = 1
+                    message = code.decode()
+                elif isinstance(code, int):
+                    exitcode = code
+                    message = ""
+                else:
+                    exitcode = 1
+                    message = str(code)
             else:
-                self._dbgClient.progTerminated(excval.code)
+                exitcode = 1
+                message = str(excval)
+            self._dbgClient.progTerminated(exitcode, message)
             return
         
         if exctype in [SyntaxError, IndentationError]:
             try:
                 message = str(excval)
                 filename = excval.filename
-                linenr = excval.lineno
-                charnr = excval.offset
+                lineno = excval.lineno
+                charno = excval.offset
+                realSyntaxError = os.path.exists(filename)
             except (AttributeError, ValueError):
-                exclist = []
+                message = ""
+                filename = ""
+                lineno = 0
+                charno = 0
                 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.sendSyntaxError(
+                    message, filename, lineno, charno)
                 self._dbgClient.eventLoop()
                 return
         
@@ -784,11 +815,8 @@
             exctypetxt = "unhandled {0!s}".format(str(exctype))
         else:
             exctypetxt = str(exctype)
-        try:
-            exclist = [exctypetxt, str(excval)]
-        except TypeError:
-            exclist = [exctypetxt, str(excval)]
         
+        stack = []
         if exctb:
             frlist = self.__extract_stack(exctb)
             frlist.reverse()
@@ -818,10 +846,9 @@
                 else:
                     fargs = ""
                 
-                exclist.append([filename, linenr, ffunc, fargs])
+                stack.append([filename, linenr, ffunc, fargs])
         
-        self._dbgClient.write("{0}{1}\n".format(
-            ResponseException, str(exclist)))
+        self._dbgClient.sendException(exctypetxt, str(excval), stack)
         
         if exctb is None:
             return
@@ -879,7 +906,7 @@
         Public method to update the settings to trace into Python libraries.
         
         @param enable flag to debug into Python libraries
-        @type int
+        @type bool
         """
         pathsToSkip = list(self.pathsToSkip)
         # don't trace into Python library?

eric ide

mercurial