Author xdegaye
Recipients akaptur, xdegaye
Date 2012-11-19.21:00:49
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1353358849.96.0.3507751882.issue16482@psf.upfronthosting.co.za>
In-reply-to
Content
The top level frame line number is not updated because it has a local
trace function while the global trace function is None. This is
related to issue 7238.

The following patch fixes the issue. The patch removes the local trace
at the top level frame and makes sure it is not reinstalled when
returning from the current trace function.

diff --git a/Lib/bdb.py b/Lib/bdb.py
--- a/Lib/bdb.py
+++ b/Lib/bdb.py
@@ -64,6 +64,10 @@
         if self.stop_here(frame) or self.break_here(frame):
             self.user_line(frame)
             if self.quitting: raise BdbQuit
+            # Do not re-install the local trace when we are finished debugging,
+            # see issues 16482 and 7238.
+            if not sys.gettrace():
+                return None
         return self.trace_dispatch
 
     def dispatch_call(self, frame, arg):
@@ -231,8 +235,10 @@
             # no breakpoints; run without debugger overhead
             sys.settrace(None)
             frame = sys._getframe().f_back
-            while frame and frame is not self.botframe:
+            while frame:
                 del frame.f_trace
+                if frame is self.botframe:
+                    break
                 frame = frame.f_back
 
     def set_quit(self):


The following code is a minimum implementation of pdb with the patch
applied and the associated code to test it.

class Bdb:

    def trace_dispatch(self, frame, event, arg):
        self.set_continue()
        if sys.gettrace():
            return self.trace_dispatch

    def set_trace(self, frame):
        self.botframe = frame
        frame.f_trace = self.trace_dispatch
        sys.settrace(self.trace_dispatch)

    def set_continue(self):
        sys.settrace(None)
        del self.botframe.f_trace

frame = sys._getframe()
d = Bdb()
d.set_trace(frame)

y = "line of code not triggering an error"
x = 1
assert x != 1
History
Date User Action Args
2012-11-19 21:00:50xdegayesetrecipients: + xdegaye, akaptur
2012-11-19 21:00:49xdegayesetmessageid: <1353358849.96.0.3507751882.issue16482@psf.upfronthosting.co.za>
2012-11-19 21:00:49xdegayelinkissue16482 messages
2012-11-19 21:00:49xdegayecreate