Skip to content

Commit 6c79bae

Browse files
[3.13] gh-100141: Allow pdb to deal with empty file (GH-125425) (#125536)
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 cc66dfc commit 6c79bae

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
@@ -429,8 +429,7 @@ def user_call(self, frame, argument_list):
429429
def user_line(self, frame):
430430
"""This function is called when we stop or break at this line."""
431431
if self._wait_for_mainpyfile:
432-
if (self.mainpyfile != self.canonic(frame.f_code.co_filename)
433-
or frame.f_lineno <= 0):
432+
if (self.mainpyfile != self.canonic(frame.f_code.co_filename)):
434433
return
435434
self._wait_for_mainpyfile = False
436435
if self.bp_commands(frame):

Lib/test/test_pdb.py

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

3784+
def test_empty_file(self):
3785+
script = ''
3786+
commands = 'q\n'
3787+
# We check that pdb stopped at line 0, but anything reasonable
3788+
# is acceptable here, as long as it does not halt
3789+
stdout, _ = self.run_pdb_script(script, commands)
3790+
self.assertIn('main.py(0)', stdout)
3791+
stdout, _ = self.run_pdb_module(script, commands)
3792+
self.assertIn('__main__.py(0)', stdout)
3793+
37843794
def test_non_utf8_encoding(self):
37853795
script_dir = os.path.join(os.path.dirname(__file__), 'encoded_modules')
37863796
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)