gh-84583: Make pdb enter post-mortem mode even for SyntaxError (#110883)

This commit is contained in:
Tian Gao 2023-10-15 03:55:00 -07:00 committed by GitHub
parent 84b7e9e3fa
commit fa18b0afe4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 7 deletions

View file

@ -2151,9 +2151,6 @@ def main():
while True: while True:
try: try:
pdb._run(target) pdb._run(target)
if pdb._user_requested_quit:
break
print("The program finished and will be restarted")
except Restart: except Restart:
print("Restarting", target, "with arguments:") print("Restarting", target, "with arguments:")
print("\t" + " ".join(sys.argv[1:])) print("\t" + " ".join(sys.argv[1:]))
@ -2161,9 +2158,6 @@ def main():
# In most cases SystemExit does not warrant a post-mortem session. # In most cases SystemExit does not warrant a post-mortem session.
print("The program exited via sys.exit(). Exit status:", end=' ') print("The program exited via sys.exit(). Exit status:", end=' ')
print(e) print(e)
except SyntaxError:
traceback.print_exc()
sys.exit(1)
except BaseException as e: except BaseException as e:
traceback.print_exc() traceback.print_exc()
print("Uncaught exception. Entering post mortem debugging") print("Uncaught exception. Entering post mortem debugging")
@ -2171,6 +2165,9 @@ def main():
pdb.interaction(None, e) pdb.interaction(None, e)
print("Post mortem debugger finished. The " + target + print("Post mortem debugger finished. The " + target +
" will be restarted") " 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 # When invoked as main program, invoke the debugger on a script

View file

@ -2638,13 +2638,28 @@ def bœr():
commands = '' commands = ''
expected = "SyntaxError:" expected = "SyntaxError:"
stdout, stderr = self.run_pdb_script( stdout, stderr = self.run_pdb_script(
script, commands, expected_returncode=1 script, commands
) )
self.assertIn(expected, stdout, self.assertIn(expected, stdout,
'\n\nExpected:\n{}\nGot:\n{}\n' '\n\nExpected:\n{}\nGot:\n{}\n'
'Fail to handle a syntax error in the debuggee.' 'Fail to handle a syntax error in the debuggee.'
.format(expected, stdout)) .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): def test_issue26053(self):
# run command of pdb prompt echoes the correct args # run command of pdb prompt echoes the correct args
script = "print('hello')" script = "print('hello')"

View file

@ -0,0 +1 @@
Make :mod:`pdb` enter post-mortem mode even for :exc:`SyntaxError`