Skip to content

Commit 90b1406

Browse files
[3.12] gh-100141: Allow pdb to deal with empty file (GH-125425) (#125537)
gh-100141: Allow pdb to deal with empty file (GH-125425) (cherry picked from commit bb9604b) Co-authored-by: Tian Gao <[email protected]>
1 parent 1cab726 commit 90b1406

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

Lib/pdb.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,7 @@ def user_call(self, frame, argument_list):
321321
def user_line(self, frame):
322322
"""This function is called when we stop or break at this line."""
323323
if self._wait_for_mainpyfile:
324-
if (self.mainpyfile != self.canonic(frame.f_code.co_filename)
325-
or frame.f_lineno <= 0):
324+
if (self.mainpyfile != self.canonic(frame.f_code.co_filename)):
326325
return
327326
self._wait_for_mainpyfile = False
328327
if self.bp_commands(frame):

Lib/test/test_pdb.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2754,6 +2754,16 @@ def _create_fake_frozen_module():
27542754
# verify that pdb found the source of the "frozen" function
27552755
self.assertIn('x = "Sentinel string for gh-93696"', stdout, "Sentinel statement not found")
27562756

2757+
def test_empty_file(self):
2758+
script = ''
2759+
commands = 'q\n'
2760+
# We check that pdb stopped at line 0, but anything reasonable
2761+
# is acceptable here, as long as it does not halt
2762+
stdout, _ = self.run_pdb_script(script, commands)
2763+
self.assertIn('main.py(0)', stdout)
2764+
stdout, _ = self.run_pdb_module(script, commands)
2765+
self.assertIn('__main__.py(0)', stdout)
2766+
27572767
def test_non_utf8_encoding(self):
27582768
script_dir = os.path.join(os.path.dirname(__file__), 'encoded_modules')
27592769
for filename in os.listdir(script_dir):
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed the bug where :mod:`pdb` will be stuck in an infinite loop when debugging an empty file.

0 commit comments

Comments
 (0)