]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-100141: Allow pdb to deal with empty file (#125425)
authorTian Gao <gaogaotiantian@hotmail.com>
Tue, 15 Oct 2024 15:45:23 +0000 (08:45 -0700)
committerGitHub <noreply@github.com>
Tue, 15 Oct 2024 15:45:23 +0000 (11:45 -0400)
Lib/pdb.py
Lib/test/test_pdb.py
Misc/NEWS.d/next/Library/2024-10-14-02-27-03.gh-issue-100141.NuAcwa.rst [new file with mode: 0644]

index d9aed24bfcd8e79d696a4f190b3132f92e9bd17c..2b36b1e3fa7cbe2fec3bed6b443d75948302afc1 100644 (file)
@@ -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
         self.bp_commands(frame)
index 3dc65fdfc0340950b0f26cea08f9d29e8e25b0c6..474d31f1ae03d9a66015773f2207eaefd414eeb6 100644 (file)
@@ -3999,6 +3999,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):
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 (file)
index 0000000..c366b0a
--- /dev/null
@@ -0,0 +1 @@
+Fixed the bug where :mod:`pdb` will be stuck in an infinite loop when debugging an empty file.