Skip to content

Commit 3e1227e

Browse files
Fixed the breakpoint display error for frozen modules
1 parent a94c752 commit 3e1227e

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

Lib/pdb.py

-6
Original file line numberDiff line numberDiff line change
@@ -1971,12 +1971,6 @@ def do_list(self, arg):
19711971
if last is None:
19721972
last = first + 10
19731973
filename = self.curframe.f_code.co_filename
1974-
# gh-93696: stdlib frozen modules provide a useful __file__
1975-
# this workaround can be removed with the closure of gh-89815
1976-
if filename.startswith("<frozen"):
1977-
tmp = self.curframe.f_globals.get("__file__")
1978-
if isinstance(tmp, str):
1979-
filename = tmp
19801974
breaklist = self.get_file_breaks(filename)
19811975
try:
19821976
lines = linecache.getlines(filename, self.curframe.f_globals)

Lib/test/test_pdb.py

+21-3
Original file line numberDiff line numberDiff line change
@@ -4260,13 +4260,22 @@ def _create_fake_frozen_module():
42604260
mod = _create_fake_frozen_module()
42614261
mod.func()
42624262
"""
4263-
commands = """
4263+
commands_list = """
42644264
break 20
42654265
continue
42664266
step
4267+
break 4
42674268
list
42684269
quit
42694270
"""
4271+
commands_longlist = """
4272+
break 20
4273+
continue
4274+
step
4275+
break 4
4276+
longlist
4277+
quit
4278+
"""
42704279
with open('gh93696.py', 'w') as f:
42714280
f.write(textwrap.dedent(frozen_src))
42724281

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

42764285
self.addCleanup(os_helper.unlink, 'gh93696.py')
42774286
self.addCleanup(os_helper.unlink, 'gh93696_host.py')
4278-
stdout, stderr = self._run_pdb(["gh93696_host.py"], commands)
4279-
# verify that pdb found the source of the "frozen" function
4287+
4288+
# verify that pdb found the source of the "frozen" function and it
4289+
# shows the breakpoint at the correct line for both list and longlist
4290+
stdout, _ = self._run_pdb(["gh93696_host.py"], commands_list)
4291+
self.assertIn('x = "Sentinel string for gh-93696"', stdout, "Sentinel statement not found")
4292+
self.assertIn('4 B', stdout, "breakpoint not found")
4293+
self.assertIn('-> def func():', stdout, "stack entry not found")
4294+
4295+
stdout, _ = self._run_pdb(["gh93696_host.py"], commands_longlist)
42804296
self.assertIn('x = "Sentinel string for gh-93696"', stdout, "Sentinel statement not found")
4297+
self.assertIn('4 B', stdout, "breakpoint not found")
4298+
self.assertIn('-> def func():', stdout, "stack entry not found")
42814299

42824300
def test_empty_file(self):
42834301
script = ''

0 commit comments

Comments
 (0)