From 321ba8296a8695fae8f600e79d63e9fc6a34ebbd Mon Sep 17 00:00:00 2001 From: Tian Gao Date: Tue, 7 May 2024 10:32:34 -0700 Subject: [PATCH 1/3] Make the pdb post-mortem restart/quit behavior more reasonable --- Lib/pdb.py | 9 ++++++--- Lib/test/test_pdb.py | 17 +++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/Lib/pdb.py b/Lib/pdb.py index e507a9bb896611..c6d8a019370849 100755 --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -2441,9 +2441,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 f47466410082ef..f69dae482b87b5 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -3409,6 +3409,23 @@ def change_file(content, filename): # 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) From 50bcd52f0c51befac07b78aa58fd252f4a1bc46b Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Tue, 7 May 2024 17:38:56 +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-05-07-17-38-53.gh-issue-118714.XXKpVZ.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2024-05-07-17-38-53.gh-issue-118714.XXKpVZ.rst 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 00000000000000..638d550ed644a3 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2024-05-07-17-38-53.gh-issue-118714.XXKpVZ.rst @@ -0,0 +1 @@ +Make the :mod:`pdb` post-mortem restart/quit message match the behavior From 8d9644282a6e3d2e8e102105c85a41069db33d1c Mon Sep 17 00:00:00 2001 From: Tian Gao Date: Tue, 2 Jul 2024 18:53:30 -0700 Subject: [PATCH 3/3] Update 2024-05-07-17-38-53.gh-issue-118714.XXKpVZ.rst --- .../Library/2024-05-07-17-38-53.gh-issue-118714.XXKpVZ.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 index 638d550ed644a3..f41baee303482a 100644 --- 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 @@ -1 +1,2 @@ -Make the :mod:`pdb` post-mortem restart/quit message match the behavior +Allow ``restart`` in post-mortem debugging of :mod:`pdb`. Removed restart message +when the user quits pdb from post-mortem mode.