gh-50571: Check bytecode before accepting a breakpoint in pdb#145121
gh-50571: Check bytecode before accepting a breakpoint in pdb#145121aisk wants to merge 11 commits intopython:mainfrom
Conversation
gaogaotiantian
left a comment
There was a problem hiding this comment.
Overall I think it's a good fix. Also relatively safe. I have a few commonts.
Lib/bdb.py
Outdated
| line = linecache.getline(filename, lineno) | ||
| if not line: | ||
| return 'Line %s:%d does not exist' % (filename, lineno) | ||
| source = ''.join(linecache.getlines(filename)) |
There was a problem hiding this comment.
Let's cache this internally. Build a {filename: lineno} cache. Having some overhead for setting breakpoint is fine, but compile + co_lines() is pretty expensive. Let's avoid wasting extra time on it.
There was a problem hiding this comment.
Added the cache to the Bdb instance instead of using a global variable because some tests register different code objects using the same filename.
Updating the tests would introduce a lot of changes, but since they use different Bdb instances, moving the cache here is very straightforward. In real scenarios, we always set breakpoints on the same instance, so I think there is no difference between using a global variable and an instance variable.
However, if you think this is not the right solution, I can change it.
Misc/NEWS.d/next/Library/2026-02-23-00-58-24.gh-issue-50571.jZIR3T.rst
Outdated
Show resolved
Hide resolved
…IR3T.rst Co-authored-by: Tian Gao <gaogaotiantian@hotmail.com>
Collect all linenos in a code object recursively, and check if the target breakpoint is in them. If not, report an error, just like set break point on blank lines.