From e7008d78f37dd80392f9e8c3b734c707ae10049a Mon Sep 17 00:00:00 2001 From: "Miss Islington (bot)" <31488909+miss-islington@users.noreply.github.com> Date: Wed, 3 Jul 2024 21:15:53 +0200 Subject: [PATCH] [3.13] gh-118714: Make the pdb post-mortem restart/quit behavior more reasonable (GH-118725) (#121346) gh-118714: Make the pdb post-mortem restart/quit behavior more reasonable (GH-118725) (cherry picked from commit e245ed7d1e23b5c8bc0d568bd1a2f06ae92d631a) Co-authored-by: Tian Gao --- Lib/pdb.py | 9 ++++++--- Lib/test/test_pdb.py | 17 +++++++++++++++++ ...24-05-07-17-38-53.gh-issue-118714.XXKpVZ.rst | 2 ++ 3 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2024-05-07-17-38-53.gh-issue-118714.XXKpVZ.rst diff --git a/Lib/pdb.py b/Lib/pdb.py index 87837737dcd..a42b8881f03 100755 --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -2460,9 +2460,12 @@ def main(): traceback.print_exception(e, colorize=_colorize.can_colorize()) print("Uncaught exception. Entering post mortem debugging") print("Running 'cont' or 'step' will restart the program") - pdb.interaction(None, e) - print(f"Post mortem debugger finished. The {target} will " - "be restarted") + try: + pdb.interaction(None, e) + except Restart: + print("Restarting", target, "with arguments:") + print("\t" + " ".join(sys.argv[1:])) + continue if pdb._user_requested_quit: break print("The program finished and will be restarted") diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py index 4b3557f9b0d..8654d8e66f7 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -3492,6 +3492,23 @@ def bœr(): # the file as up to date self.assertNotIn("WARNING:", stdout) + def test_post_mortem_restart(self): + script = """ + def foo(): + raise ValueError("foo") + foo() + """ + + commands = """ + continue + restart + continue + quit + """ + + stdout, stderr = self.run_pdb_script(script, commands) + self.assertIn("Restarting", stdout) + def test_relative_imports(self): self.module_name = 't_main' os_helper.rmtree(self.module_name) diff --git a/Misc/NEWS.d/next/Library/2024-05-07-17-38-53.gh-issue-118714.XXKpVZ.rst b/Misc/NEWS.d/next/Library/2024-05-07-17-38-53.gh-issue-118714.XXKpVZ.rst new file mode 100644 index 00000000000..f41baee3034 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2024-05-07-17-38-53.gh-issue-118714.XXKpVZ.rst @@ -0,0 +1,2 @@ +Allow ``restart`` in post-mortem debugging of :mod:`pdb`. Removed restart message +when the user quits pdb from post-mortem mode.