-
-
Notifications
You must be signed in to change notification settings - Fork 30.8k
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
gh-124552 : Improve the accuracy of possible breakpoint check in bdb #124553
gh-124552 : Improve the accuracy of possible breakpoint check in bdb #124553
Conversation
This needs a test. |
Lib/bdb.py
Outdated
self.code_lineno[code] = set() | ||
for _, _, lineno in code.co_lines(): | ||
self.code_lineno[code].add(lineno) |
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.
self.code_lineno[code] = set() | |
for _, _, lineno in code.co_lines(): | |
self.code_lineno[code].add(lineno) | |
self.code_lineno[code] = set([lno for _, _, lno in code.co_lines()]) |
Do you think a test that directly tests |
I added a test for |
I am testing this with IDLE's bdb-based debugger now. |
No (new) problems found. Breakpoints at top level and in def still work. |
Thanks @terryjreedy for confirming this. #124533 might be another interesting one to test. |
Lib/bdb.py
Outdated
return False | ||
if code not in self.code_lineno: | ||
self.code_lineno[code] = set(lineno for _, _, lineno in code.co_lines()) | ||
return lineno in self.code_lineno[frame.f_code] |
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.
return lineno in self.code_lineno[frame.f_code] | |
return lineno in self.code_lineno[code] |
Lib/bdb.py
Outdated
@@ -36,6 +37,7 @@ def __init__(self, skip=None): | |||
self.frame_returning = None | |||
self.trace_opcodes = False | |||
self.enterframe = None | |||
self.code_lineno = weakref.WeakKeyDictionary() |
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.
self.code_lineno = weakref.WeakKeyDictionary() | |
self.code_linenos = weakref.WeakKeyDictionary() |
Misc/NEWS.d/next/Library/2024-09-25-22-06-52.gh-issue-124552.1nQKNM.rst
Outdated
Show resolved
Hide resolved
Lib/bdb.py
Outdated
@@ -275,7 +280,23 @@ def do_clear(self, arg): | |||
def break_anywhere(self, frame): | |||
"""Return True if there is any breakpoint for frame's filename. |
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.
this comment needs updating (it's not just filename now).
…nQKNM.rst Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
@@ -155,6 +157,9 @@ def dispatch_return(self, frame, arg): | |||
if self.stop_here(frame) or frame == self.returnframe: | |||
# Ignore return events in generator except when stepping. | |||
if self.stopframe and frame.f_code.co_flags & GENERATOR_AND_COROUTINE_FLAGS: | |||
# It's possible to trigger a StopIteration exception in | |||
# the caller so we must set the trace function in the caller | |||
self._set_caller_tracefunc(frame) |
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.
how is this related to this PR?
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.
There is a hidden bug which was exposed by the change of break_anywhere
. There's a test case of bdb
testing raising StopIteration
in a generator. It passed because break_anywhere
always return True
when the function was defined in the same file, which always sets the trace function on the caller because it is in the same file. That coincidence hide the bug where returning from a generator should stop in the caller. There's a similar call in line 177 - that's for the normal return case from #118979 - it's also my fix to a similar case.
Now we check whether the line number is in the code object with
co_lines()
so we can have an accurate answer.A bug needs to be fixed for generators. This is not caused by the new feature, but exposed. I put those together because the changes are very small. I can separate those if that's desired.