Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fixed the breakpoint display error for frozen modules
  • Loading branch information
gaogaotiantian committed Apr 24, 2025
commit 3e1227e2af3a693f888087e4b883715923c1a563
6 changes: 0 additions & 6 deletions Lib/pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -1971,12 +1971,6 @@ def do_list(self, arg):
if last is None:
last = first + 10
filename = self.curframe.f_code.co_filename
# gh-93696: stdlib frozen modules provide a useful __file__
# this workaround can be removed with the closure of gh-89815
if filename.startswith("<frozen"):
tmp = self.curframe.f_globals.get("__file__")
if isinstance(tmp, str):
filename = tmp
breaklist = self.get_file_breaks(filename)
try:
lines = linecache.getlines(filename, self.curframe.f_globals)
Expand Down
24 changes: 21 additions & 3 deletions Lib/test/test_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -4260,13 +4260,22 @@ def _create_fake_frozen_module():
mod = _create_fake_frozen_module()
mod.func()
"""
commands = """
commands_list = """
break 20
continue
step
break 4
list
quit
"""
commands_longlist = """
break 20
continue
step
break 4
longlist
quit
"""
with open('gh93696.py', 'w') as f:
f.write(textwrap.dedent(frozen_src))

Expand All @@ -4275,9 +4284,18 @@ def _create_fake_frozen_module():

self.addCleanup(os_helper.unlink, 'gh93696.py')
self.addCleanup(os_helper.unlink, 'gh93696_host.py')
stdout, stderr = self._run_pdb(["gh93696_host.py"], commands)
# verify that pdb found the source of the "frozen" function

# verify that pdb found the source of the "frozen" function and it
# shows the breakpoint at the correct line for both list and longlist
stdout, _ = self._run_pdb(["gh93696_host.py"], commands_list)
self.assertIn('x = "Sentinel string for gh-93696"', stdout, "Sentinel statement not found")
self.assertIn('4 B', stdout, "breakpoint not found")
self.assertIn('-> def func():', stdout, "stack entry not found")

stdout, _ = self._run_pdb(["gh93696_host.py"], commands_longlist)
self.assertIn('x = "Sentinel string for gh-93696"', stdout, "Sentinel statement not found")
self.assertIn('4 B', stdout, "breakpoint not found")
self.assertIn('-> def func():', stdout, "stack entry not found")
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.

These two tests look identical as l. Make a loop?

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.

Good point! I used loop for it.


def test_empty_file(self):
script = ''
Expand Down
Loading