]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-84583: Make pdb enter post-mortem mode even for SyntaxError (#110883)
authorTian Gao <gaogaotiantian@hotmail.com>
Sun, 15 Oct 2023 10:55:00 +0000 (03:55 -0700)
committerGitHub <noreply@github.com>
Sun, 15 Oct 2023 10:55:00 +0000 (11:55 +0100)
Lib/pdb.py
Lib/test/test_pdb.py
Misc/NEWS.d/next/Library/2023-10-14-21-33-57.gh-issue-84583.-Cmn4_.rst [new file with mode: 0644]

index 930cb91b8696a314f9b181726e3487366583cab9..129dd65bf592b378f90d94e8995768b7a3878e93 100755 (executable)
@@ -2151,9 +2151,6 @@ def main():
     while True:
         try:
             pdb._run(target)
-            if pdb._user_requested_quit:
-                break
-            print("The program finished and will be restarted")
         except Restart:
             print("Restarting", target, "with arguments:")
             print("\t" + " ".join(sys.argv[1:]))
@@ -2161,9 +2158,6 @@ def main():
             # In most cases SystemExit does not warrant a post-mortem session.
             print("The program exited via sys.exit(). Exit status:", end=' ')
             print(e)
-        except SyntaxError:
-            traceback.print_exc()
-            sys.exit(1)
         except BaseException as e:
             traceback.print_exc()
             print("Uncaught exception. Entering post mortem debugging")
@@ -2171,6 +2165,9 @@ def main():
             pdb.interaction(None, e)
             print("Post mortem debugger finished. The " + target +
                   " will be restarted")
+        if pdb._user_requested_quit:
+            break
+        print("The program finished and will be restarted")
 
 
 # When invoked as main program, invoke the debugger on a script
index ff677aeb795442502308c08cd76ada20fc992fd7..a668b6cf2a84f83c6cc0e6b4fa77271910913cc7 100644 (file)
@@ -2638,13 +2638,28 @@ def bœr():
         commands = ''
         expected = "SyntaxError:"
         stdout, stderr = self.run_pdb_script(
-            script, commands, expected_returncode=1
+            script, commands
         )
         self.assertIn(expected, stdout,
             '\n\nExpected:\n{}\nGot:\n{}\n'
             'Fail to handle a syntax error in the debuggee.'
             .format(expected, stdout))
 
+    def test_issue84583(self):
+        # A syntax error from ast.literal_eval should not make pdb exit.
+        script = "import ast; ast.literal_eval('')\n"
+        commands = """
+            continue
+            where
+            quit
+        """
+        stdout, stderr = self.run_pdb_script(script, commands)
+        # The code should appear 3 times in the stdout:
+        # 1. when pdb starts
+        # 2. when the exception is raised, in trackback
+        # 3. in where command
+        self.assertEqual(stdout.count("ast.literal_eval('')"), 3)
+
     def test_issue26053(self):
         # run command of pdb prompt echoes the correct args
         script = "print('hello')"
diff --git a/Misc/NEWS.d/next/Library/2023-10-14-21-33-57.gh-issue-84583.-Cmn4_.rst b/Misc/NEWS.d/next/Library/2023-10-14-21-33-57.gh-issue-84583.-Cmn4_.rst
new file mode 100644 (file)
index 0000000..aa86da4
--- /dev/null
@@ -0,0 +1 @@
+Make :mod:`pdb` enter post-mortem mode even for :exc:`SyntaxError`