@@ -165,6 +165,11 @@ def dispatch_return(self, frame, arg):
165165 # The user issued a 'next' or 'until' command.
166166 if self .stopframe is frame and self .stoplineno != - 1 :
167167 self ._set_stopinfo (None , None )
168+ # The previous frame might not have f_trace set, unless we are
169+ # issuing a command that does not expect to stop, we should set
170+ # f_trace
171+ if self .stoplineno != - 1 :
172+ self ._set_caller_tracefunc (frame )
168173 return self .trace_dispatch
169174
170175 def dispatch_exception (self , frame , arg ):
@@ -320,15 +325,14 @@ def _set_stopinfo(self, stopframe, returnframe, stoplineno=0, opcode=False):
320325 self .stoplineno = stoplineno
321326 self ._set_trace_opcodes (opcode )
322327
323- def _set_caller_tracefunc (self ):
328+ def _set_caller_tracefunc (self , current_frame ):
324329 # Issue #13183: pdb skips frames after hitting a breakpoint and running
325330 # step commands.
326331 # Restore the trace function in the caller (that may not have been set
327332 # for performance reasons) when returning from the current frame.
328- if self .frame_returning :
329- caller_frame = self .frame_returning .f_back
330- if caller_frame and not caller_frame .f_trace :
331- caller_frame .f_trace = self .trace_dispatch
333+ caller_frame = current_frame .f_back
334+ if caller_frame and not caller_frame .f_trace :
335+ caller_frame .f_trace = self .trace_dispatch
332336
333337 # Derived classes and clients can call the following methods
334338 # to affect the stepping state.
@@ -343,12 +347,10 @@ def set_until(self, frame, lineno=None):
343347
344348 def set_step (self ):
345349 """Stop after one line of code."""
346- self ._set_caller_tracefunc ()
347350 self ._set_stopinfo (None , None )
348351
349352 def set_stepinstr (self ):
350353 """Stop before the next instruction."""
351- self ._set_caller_tracefunc ()
352354 self ._set_stopinfo (None , None , opcode = True )
353355
354356 def set_next (self , frame ):
0 commit comments