DebugClients/Python/DebugBase.py

branch
debugger speed
changeset 5085
85dfb7886fb9
parent 5084
25115adf9758
child 5086
6cb8be573090
--- a/DebugClients/Python/DebugBase.py	Mon Aug 08 22:30:48 2016 +0200
+++ b/DebugClients/Python/DebugBase.py	Mon Aug 08 22:38:07 2016 +0200
@@ -71,6 +71,7 @@
 
         self._dbgClient = dbgClient
         self._mainThread = 1
+        self.quitting = 0
         
         self.tracePythonLibs(0)
         
@@ -86,6 +87,11 @@
         # frame that we are stepping in, can be different than currentFrame
         self.stepFrame = None
         
+        self.botframe = None
+        self.stopframe = None
+        self.returnframe = None
+        self.stop_everywhere = False
+        
         # provide a hook to perform a hard breakpoint
         # Use it like this:
         # if hasattr(sys, 'breakpoint): sys.breakpoint()
@@ -292,10 +298,12 @@
             return
         
         if event == 'call':
-            if self.botframe is None:
-                # First call of dispatch since reset()
-                # (CT) Note that this may also be None!
+            if self.botframe is None and frame.f_lineno > 1:
                 self.botframe = frame.f_back
+                frame.f_trace = self.trace_dispatch
+                self._dbgClient.mainFrame = frame
+                
+                self.user_line(frame)
                 return self.trace_dispatch
             
             if not (self.stop_here(frame) or
@@ -306,18 +314,15 @@
             return self.trace_dispatch
         
         if event == 'return':
-            if self.stop_here(frame) or frame == self.returnframe:
-                # 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 SystemExit
+            # The program has finished if we have just left the first frame
+            if (self.stop_here(frame) and
+                    frame == self._dbgClient.mainFrame and
+                    self._mainThread):
+                atexit._run_exitfuncs()
+                self._dbgClient.progTerminated(arg)
+            
+            if self.quitting and not self._dbgClient.passive:
+                raise SystemExit
             return
         
         if event == 'exception':
@@ -389,14 +394,26 @@
             self.quitting = 1
             sys.settrace(None)
 
+    def _set_stopinfo(self, stopframe, returnframe):
+        """
+        Protected method to update the frame pointers.
+        
+        @param stopframe the frame object where to stop
+        @type frame object
+        @param returnframe the frame object where to stop on a function return
+        @type frame object
+        """
+        self.stopframe = stopframe
+        self.returnframe = returnframe
+        self.stop_everywhere = False
+
     def set_continue(self, special):
         """
-        Public method reimplemented from bdb.py to always get informed of
-        exceptions.
+        Public method to stop only on next breakpoint.
         
         @param special flag indicating a special continue operation
+        @type bool
         """
-        # Modified version of the one found in bdb.py
         # Here we only set a new stop frame if it is a normal continue.
         if not special:
             self._set_stopinfo(self.botframe, None)
@@ -405,6 +422,13 @@
             sys.settrace(None)
             sys.setprofile(None)
 
+    def set_step(self):
+        """
+        Public method to stop after one line of code.
+        """
+        self._set_stopinfo(None, None)
+        self.stop_everywhere = True
+
     def set_quit(self):
         """
         Public method to quit.
@@ -796,11 +820,17 @@
         debugger that are called from the application being debugged.
         
         @param frame the frame object
+        @type frame object
         @return flag indicating whether the debugger should stop here
+        @rtype bool
         """
         if self.__skipFrame(frame):
-            return 0
-        return bdb.Bdb.stop_here(self, frame)
+            return False
+        
+        return (self.stop_everywhere or
+                frame is self.stopframe or
+                frame is self.returnframe or
+                frame is self.botframe)
 
     def tracePythonLibs(self, enable):
         """

eric ide

mercurial