mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
[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 bb9604b62a
)
Co-authored-by: Tian Gao <gaogaotiantian@hotmail.com>
This commit is contained in:
parent
cc66dfc86c
commit
6c79baea4d
3 changed files with 12 additions and 2 deletions
|
@ -429,8 +429,7 @@ class Pdb(bdb.Bdb, cmd.Cmd):
|
|||
def user_line(self, frame):
|
||||
"""This function is called when we stop or break at this line."""
|
||||
if self._wait_for_mainpyfile:
|
||||
if (self.mainpyfile != self.canonic(frame.f_code.co_filename)
|
||||
or frame.f_lineno <= 0):
|
||||
if (self.mainpyfile != self.canonic(frame.f_code.co_filename)):
|
||||
return
|
||||
self._wait_for_mainpyfile = False
|
||||
if self.bp_commands(frame):
|
||||
|
|
|
@ -3781,6 +3781,16 @@ def bœr():
|
|||
# verify that pdb found the source of the "frozen" function
|
||||
self.assertIn('x = "Sentinel string for gh-93696"', stdout, "Sentinel statement not found")
|
||||
|
||||
def test_empty_file(self):
|
||||
script = ''
|
||||
commands = 'q\n'
|
||||
# We check that pdb stopped at line 0, but anything reasonable
|
||||
# is acceptable here, as long as it does not halt
|
||||
stdout, _ = self.run_pdb_script(script, commands)
|
||||
self.assertIn('main.py(0)', stdout)
|
||||
stdout, _ = self.run_pdb_module(script, commands)
|
||||
self.assertIn('__main__.py(0)', stdout)
|
||||
|
||||
def test_non_utf8_encoding(self):
|
||||
script_dir = os.path.join(os.path.dirname(__file__), 'encoded_modules')
|
||||
for filename in os.listdir(script_dir):
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Fixed the bug where :mod:`pdb` will be stuck in an infinite loop when debugging an empty file.
|
Loading…
Add table
Add a link
Reference in a new issue