Author xdegaye
Recipients akaptur, xdegaye
Date 2012-11-19.21:00:49
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
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/ b/Lib/
--- a/Lib/
+++ b/Lib/
@@ -64,6 +64,10 @@
         if self.stop_here(frame) or self.break_here(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
             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):
        if sys.gettrace():
            return self.trace_dispatch

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

    def set_continue(self):
        del self.botframe.f_trace

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

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