@@ -306,7 +306,12 @@ def dispatch_line(self, frame):
306306        self.user_line(). Raise BdbQuit if self.quitting is set. 
307307        Return self.trace_dispatch to continue tracing in this scope. 
308308        """ 
309-         if  self .stop_here (frame ) or  self .break_here (frame ):
309+         # GH-136057 
310+         # For line events, besides whether we should stop at the frame, we 
311+         # also need to check if it's the same line as we issue the command. 
312+         if  (self .stop_here (frame ) or  self .break_here (frame )) and  not  (
313+             self .startframe  ==  frame  and  self .startlineno  ==  frame .f_lineno 
314+         ):
310315            self .user_line (frame )
311316            self .restart_events ()
312317            if  self .quitting : raise  BdbQuit 
@@ -535,7 +540,8 @@ def _set_trace_opcodes(self, trace_opcodes):
535540            if  self .monitoring_tracer :
536541                self .monitoring_tracer .update_local_events ()
537542
538-     def  _set_stopinfo (self , stopframe , returnframe , stoplineno = 0 , opcode = False ):
543+     def  _set_stopinfo (self , stopframe , returnframe , stoplineno = 0 , opcode = False ,
544+                       startframe = None , startlineno = None ):
539545        """Set the attributes for stopping. 
540546
541547        If stoplineno is greater than or equal to 0, then stop at line 
@@ -548,6 +554,10 @@ def _set_stopinfo(self, stopframe, returnframe, stoplineno=0, opcode=False):
548554        # stoplineno >= 0 means: stop at line >= the stoplineno 
549555        # stoplineno -1 means: don't stop at all 
550556        self .stoplineno  =  stoplineno 
557+         # startframe/startlineno is the frame/line number when the user does 
558+         # step or next. We don't want to stop at the same line for those commands. 
559+         self .startframe  =  startframe 
560+         self .startlineno  =  startlineno 
551561        self ._set_trace_opcodes (opcode )
552562
553563    def  _set_caller_tracefunc (self , current_frame ):
@@ -573,15 +583,16 @@ def set_until(self, frame, lineno=None):
573583
574584    def  set_step (self ):
575585        """Stop after one line of code.""" 
576-         self ._set_stopinfo (None , None )
586+         self ._set_stopinfo (None , None , startframe = self .enterframe ,
587+                            startlineno = self .enterframe .f_lineno )
577588
578589    def  set_stepinstr (self ):
579590        """Stop before the next instruction.""" 
580591        self ._set_stopinfo (None , None , opcode = True )
581592
582593    def  set_next (self , frame ):
583594        """Stop on the next line in or below the given frame.""" 
584-         self ._set_stopinfo (frame , None )
595+         self ._set_stopinfo (frame , None ,  startframe = frame ,  startlineno = frame . f_lineno )
585596
586597    def  set_return (self , frame ):
587598        """Stop when returning from the given frame.""" 
0 commit comments