-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
gh-136057: Allow step and next to step over for loops #136160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -306,7 +306,12 @@ def dispatch_line(self, frame): | |
self.user_line(). Raise BdbQuit if self.quitting is set. | ||
Return self.trace_dispatch to continue tracing in this scope. | ||
""" | ||
if self.stop_here(frame) or self.break_here(frame): | ||
# GH-136057 | ||
# For line events, besides whether we should stop at the frame, we | ||
# also need to check if it's the same line as we issue the command. | ||
if (self.stop_here(frame) or self.break_here(frame)) and not ( | ||
self.startframe == frame and self.startlineno == frame.f_lineno | ||
): | ||
self.user_line(frame) | ||
self.restart_events() | ||
if self.quitting: raise BdbQuit | ||
|
@@ -535,7 +540,8 @@ def _set_trace_opcodes(self, trace_opcodes): | |
if self.monitoring_tracer: | ||
self.monitoring_tracer.update_local_events() | ||
|
||
def _set_stopinfo(self, stopframe, returnframe, stoplineno=0, opcode=False): | ||
def _set_stopinfo(self, stopframe, returnframe, stoplineno=0, opcode=False, | ||
startframe=None, startlineno=None): | ||
"""Set the attributes for stopping. | ||
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): | |
# stoplineno >= 0 means: stop at line >= the stoplineno | ||
# stoplineno -1 means: don't stop at all | ||
self.stoplineno = stoplineno | ||
# startframe/startlineno is the frame/line number when the user does | ||
# step or next. We don't want to stop at the same line for those commands. | ||
self.startframe = startframe | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we could pick a more informative name, something like "command frame", because it's ambiguous here what exactly started at that frame. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah we can change it, but there's actually a caveat here - it's not really the command frame. You can do So it's more like a "do not stop here again if it's a line event" frame/lineno. Do you think there's better name to describe it? |
||
self.startlineno = startlineno | ||
self._set_trace_opcodes(opcode) | ||
|
||
def _set_caller_tracefunc(self, current_frame): | ||
|
@@ -573,15 +583,17 @@ def set_until(self, frame, lineno=None): | |
|
||
def set_step(self): | ||
"""Stop after one line of code.""" | ||
self._set_stopinfo(None, None) | ||
# set_step() could be called from signal handler so enterframe might be None | ||
self._set_stopinfo(None, None, startframe=self.enterframe, | ||
startlineno=getattr(self.enterframe, 'f_lineno', None)) | ||
|
||
def set_stepinstr(self): | ||
"""Stop before the next instruction.""" | ||
self._set_stopinfo(None, None, opcode=True) | ||
|
||
def set_next(self, frame): | ||
"""Stop on the next line in or below the given frame.""" | ||
self._set_stopinfo(frame, None) | ||
self._set_stopinfo(frame, None, startframe=frame, startlineno=frame.f_lineno) | ||
|
||
def set_return(self, frame): | ||
"""Stop when returning from the given frame.""" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fixed the bug in :mod:`pdb` and :mod:`bdb` where ``next`` and ``step`` can't go over the line if a loop exists in the line. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is very clear: "it's the same line as we issue the command". I think you mean "the same frame and line at which the break command was issued by the user".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not the break command, it's either next or step. But yes I'm open to all suggestions to make this clearer.