DebugClients/Python/DebugBase.py

changeset 2171
c7dd548d67d8
parent 2166
15b4e58d61d7
child 2302
f29e9405c851
diff -r f4e0f6133ace -r c7dd548d67d8 DebugClients/Python/DebugBase.py
--- a/DebugClients/Python/DebugBase.py	Thu Nov 01 15:31:06 2012 +0100
+++ b/DebugClients/Python/DebugBase.py	Thu Nov 01 18:29:58 2012 +0100
@@ -15,7 +15,7 @@
 import inspect
 
 from DebugProtocol import ResponseClearWatch, ResponseClearBreak, ResponseLine, \
-    ResponseSyntax, ResponseException
+    ResponseSyntax, ResponseException, CallTrace
 
 gRecursionLimit = 64
 
@@ -154,13 +154,39 @@
         if event == 'return':
             self.cFrame = frame.f_back
             self.__recursionDepth -= 1
+            self.__sendCallTrace(event, frame, self.cFrame)
         elif event == 'call':
+            self.__sendCallTrace(event, self.cFrame, frame)
             self.cFrame = frame
             self.__recursionDepth += 1
             if self.__recursionDepth > gRecursionLimit:
                 raise RuntimeError('maximum recursion depth exceeded\n'
                     '(offending frame is two down the stack)')
     
+    def __sendCallTrace(self, event, fromFrame, toFrame):
+        """
+        Private method to send a call/return trace.
+        
+        @param event trace event (string)
+        @param fromFrame originating frame (frame)
+        @param toFrame destination frame (frame)
+        """
+        if self._dbgClient.callTraceEnabled:
+            if not self.__skip_it(fromFrame) and not self.__skip_it(toFrame):
+                if event in ["call", "return"]:
+                    fr = fromFrame
+                    fromStr = "%s:%s:%s" % (
+                        self._dbgClient.absPath(self.fix_frame_filename(fr)),
+                        fr.f_lineno,
+                        fr.f_code.co_name)
+                    fr = toFrame
+                    toStr = "%s:%s:%s" % (
+                        self._dbgClient.absPath(self.fix_frame_filename(fr)),
+                        fr.f_lineno,
+                        fr.f_code.co_name)
+                    self._dbgClient.write("%s%s@@%s@@%s\n" % (
+                        CallTrace, event[0], fromStr, toStr))
+    
     def trace_dispatch(self, frame, event, arg):
         """
         Reimplemented from bdb.py to do some special things.
@@ -700,6 +726,9 @@
         @param frame the frame object
         @return flag indicating whether the debugger should skip this frame
         """
+        if frame is None:
+            return 1
+        
         fn = self.fix_frame_filename(frame)
 
         # Eliminate things like <string> and <stdin>.

eric ide

mercurial