FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-124552 : Improve the accuracy of possible breakpoint check in bdb by gaogaotiantian · Pull Request #124553 · python/cpython · GitHub

/ cpython Public

gh-124552 : Improve the accuracy of possible breakpoint check in bdb - #124553

Merged
gaogaotiantian merged 6 commits into
python:mainfrom
gaogaotiantian:pdb-breakpoint-check
Oct 5, 2024
Merged

gh-124552 : Improve the accuracy of possible breakpoint check in bdb#124553
gaogaotiantian merged 6 commits into
python:mainfrom
gaogaotiantian:pdb-breakpoint-check

Conversation

gaogaotiantian commented Sep 25, 2024
edited by bedevere-app Bot
Loading

Copy link
Copy Markdown
Member

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.

gaogaotiantian changed the title Improve the accuracy of possible breakpoint check in bdb gh-124552 : Improve the accuracy of possible breakpoint check in bdb Sep 25, 2024

Copy link
Copy Markdown
Member

This needs a test.

Comment thread Lib/bdb.py Outdated
Comment on lines +298 to +300
self.code_lineno[code] = set()
for _, _, lineno in code.co_lines():
self.code_lineno[code].add(lineno)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality
Suggested change
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()])

Copy link
Copy Markdown
Member Author

Do you think a test that directly tests break_anywhere in test_bdb would work? It's a public documented API. Checking whether the dispatch function stopped would be a bit more complicated.

Copy link
Copy Markdown
Member Author

I added a test for break_anywhere. Also I used the generator for set() instead of a list.

Copy link
Copy Markdown
Member

I am testing this with IDLE's bdb-based debugger now.

Copy link
Copy Markdown
Member

No (new) problems found. Breakpoints at top level and in def still work.

Copy link
Copy Markdown
Member Author

Thanks @terryjreedy for confirming this. #124533 might be another interesting one to test.

Comment thread 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]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality
Suggested change
return lineno in self.code_lineno[frame.f_code]
return lineno in self.code_lineno[code]

Comment thread Lib/bdb.py Outdated
self.frame_returning = None
self.trace_opcodes = False
self.enterframe = None
self.code_lineno = weakref.WeakKeyDictionary()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality
Suggested change
self.code_lineno = weakref.WeakKeyDictionary()
self.code_linenos = weakref.WeakKeyDictionary()

Comment thread 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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

this comment needs updating (it's not just filename now).

gaogaotiantian and others added 2 commits October 4, 2024 19:04
Comment thread Lib/bdb.py
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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

how is this related to this PR?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants


Back | FazBrowse Home | New Git URL