DebugClients/Python/DebugBase.py

branch
debugger speed
changeset 5084
25115adf9758
parent 5083
4affedf129c5
child 5085
85dfb7886fb9
--- a/DebugClients/Python/DebugBase.py	Mon Aug 08 22:02:45 2016 +0200
+++ b/DebugClients/Python/DebugBase.py	Mon Aug 08 22:30:48 2016 +0200
@@ -276,7 +276,7 @@
         @type depends on the previous event parameter
         @return local trace function
         @rtype trace function or None
-        @exception bdb.BdbQuit
+        @exception SystemExit
         """
         # give the client a chance to push through new break points.
         if self.eventPollFlag:
@@ -284,7 +284,7 @@
             self.eventPollFlag = False
             
             if self.quitting:
-                raise bdb.BdbQuit
+                raise SystemExit
         
         if event == 'line':
             if self.stop_here(frame) or self.break_here(frame):
@@ -317,7 +317,7 @@
                     self.user_line(frame)
                     
                 if self.quitting and not self._dbgClient.passive:
-                    raise bdb.BdbQuit
+                    raise SystemExit
             return
         
         if event == 'exception':
@@ -359,6 +359,36 @@
         sys.settrace(self.trace_dispatch)
         sys.setprofile(self._dbgClient.callTraceEnabled)
     
+    def run(self, cmd, globals=None, locals=None):
+        """
+        Public method to start a given command under debugger control.
+        
+        @param cmd command / code to execute under debugger control
+        @type str or CodeType
+        @keyparam globals dictionary of global variables for cmd
+        @type dict
+        @keyparam locals  dictionary of local variables for cmd
+        @type dict
+        """
+        if globals is None:
+            import __main__
+            globals = __main__.__dict__
+        
+        if locals is None:
+            locals = globals
+        
+        sys.settrace(self.trace_dispatch)
+        if not isinstance(cmd, types.CodeType):
+            cmd += '\n'
+        
+        try:
+            exec cmd in globals, locals
+        except SystemExit:
+            pass
+        finally:
+            self.quitting = 1
+            sys.settrace(None)
+
     def set_continue(self, special):
         """
         Public method reimplemented from bdb.py to always get informed of
@@ -629,16 +659,21 @@
         Public method reimplemented to report an exception to the debug server.
         
         @param frame the frame object
+        @type frame object
         @param exctype the type of the exception
+        @type Exception
         @param excval data about the exception
+        @type excval object
         @param exctb traceback for the exception
+        @type traceback frame object
         @param unhandled flag indicating an uncaught exception
+        @type int
         """
         if exctype in [GeneratorExit, StopIteration]:
             # ignore these
             return
         
-        if exctype in [SystemExit, bdb.BdbQuit]:
+        if exctype == SystemExit:
             atexit._run_exitfuncs()
             if excval is None:
                 excval = 0

eric ide

mercurial