From 348024b242a6ef68007160bbcf69197e1548de9e Mon Sep 17 00:00:00 2001 From: Tian Gao Date: Sun, 13 Oct 2024 22:21:41 -0400 Subject: [PATCH 1/3] Allow pdb to deal with empty file --- Lib/pdb.py | 3 +-- Lib/test/test_pdb.py | 7 +++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Lib/pdb.py b/Lib/pdb.py index aea6fb70ae3106..8eb4619c02b71c 100644 --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -429,8 +429,7 @@ def user_call(self, frame, argument_list): 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 self.bp_commands(frame) diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py index 4c64a800cb32d2..b7c36c817f7927 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -3948,6 +3948,13 @@ def _create_fake_frozen_module(): # 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' + # Anything reasonable is acceptable here, as long as it does not halt + _, _ = self.run_pdb_script(script, commands) + _, _ = self.run_pdb_module(script, commands) + def test_non_utf8_encoding(self): script_dir = os.path.join(os.path.dirname(__file__), 'encoded_modules') for filename in os.listdir(script_dir): From 7528b89e2e9543c5d11ebbfc758807489dfe4783 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Mon, 14 Oct 2024 02:27:05 +0000 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Library/2024-10-14-02-27-03.gh-issue-100141.NuAcwa.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2024-10-14-02-27-03.gh-issue-100141.NuAcwa.rst diff --git a/Misc/NEWS.d/next/Library/2024-10-14-02-27-03.gh-issue-100141.NuAcwa.rst b/Misc/NEWS.d/next/Library/2024-10-14-02-27-03.gh-issue-100141.NuAcwa.rst new file mode 100644 index 00000000000000..c366b0ad4040d3 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2024-10-14-02-27-03.gh-issue-100141.NuAcwa.rst @@ -0,0 +1 @@ +Fixed the bug where :mod:`pdb` will be stuck in an infinite loop when debugging an empty file. From 2af97046f5d1fef79af513c75f84145f2c4eb464 Mon Sep 17 00:00:00 2001 From: Tian Gao Date: Sun, 13 Oct 2024 23:58:16 -0400 Subject: [PATCH 3/3] Update test --- Lib/test/test_pdb.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py index b7c36c817f7927..8cf5155ae482c4 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -3951,9 +3951,12 @@ def _create_fake_frozen_module(): def test_empty_file(self): script = '' commands = 'q\n' - # Anything reasonable is acceptable here, as long as it does not halt - _, _ = self.run_pdb_script(script, commands) - _, _ = self.run_pdb_module(script, commands) + # 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')