From 4ebf23e7788022df378c502a822a09c9c457254d Mon Sep 17 00:00:00 2001 From: Tian Gao Date: Fri, 6 Oct 2023 17:14:00 -0700 Subject: [PATCH 1/3] Set convenience variable for post mortem debugging --- Lib/pdb.py | 8 ++++++++ Lib/test/test_pdb.py | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/Lib/pdb.py b/Lib/pdb.py index fd62d246f124ab..2cbd6f6746773f 100755 --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -304,6 +304,14 @@ def setup(self, f, tb): # cache it here to ensure that modifications are not overwritten. self.curframe_locals = self.curframe.f_locals self.set_convenience_variable(self.curframe, '_frame', self.curframe) + + if self._chained_exceptions: + self.set_convenience_variable( + self.curframe, + '_exception', + self._chained_exceptions[self._chained_exception_index], + ) + return self.execRcLines() # Can be executed earlier than 'setup' if desired diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py index 8fed1d0f7162fd..b1652e993b8a01 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -859,9 +859,11 @@ def test_post_mortem_chained(): >>> with PdbTestInput([ # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE ... 'exceptions', ... 'exceptions 0', + ... '$_exception', ... 'up', ... 'down', ... 'exceptions 1', + ... '$_exception', ... 'up', ... 'down', ... 'exceptions -1', @@ -882,6 +884,8 @@ def test_post_mortem_chained(): (Pdb) exceptions 0 > (3)test_function_2() -> 1/0 + (Pdb) $_exception + ZeroDivisionError('division by zero') (Pdb) up > (3)test_function_reraise() -> test_function_2() @@ -891,6 +895,8 @@ def test_post_mortem_chained(): (Pdb) exceptions 1 > (5)test_function_reraise() -> raise ZeroDivisionError('reraised') from e + (Pdb) $_exception + ZeroDivisionError('reraised') (Pdb) up > (5)test_function() -> test_function_reraise() From 16f1c1872949d0f8ac2856281f1945a11822b606 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Sat, 7 Oct 2023 00:18:41 +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/2023-10-07-00-18-40.gh-issue-106670.kCGyRc.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2023-10-07-00-18-40.gh-issue-106670.kCGyRc.rst diff --git a/Misc/NEWS.d/next/Library/2023-10-07-00-18-40.gh-issue-106670.kCGyRc.rst b/Misc/NEWS.d/next/Library/2023-10-07-00-18-40.gh-issue-106670.kCGyRc.rst new file mode 100644 index 00000000000000..f2c348370534f7 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-10-07-00-18-40.gh-issue-106670.kCGyRc.rst @@ -0,0 +1 @@ +Set convenience variable ``$_exception`` for post mortem debugging From 0c9d9d2b669467d3d6ad1f350c15e76b6f88b61c Mon Sep 17 00:00:00 2001 From: Irit Katriel <1055913+iritkatriel@users.noreply.github.com> Date: Mon, 9 Oct 2023 09:48:34 +0200 Subject: [PATCH 3/3] tweak news --- .../next/Library/2023-10-07-00-18-40.gh-issue-106670.kCGyRc.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2023-10-07-00-18-40.gh-issue-106670.kCGyRc.rst b/Misc/NEWS.d/next/Library/2023-10-07-00-18-40.gh-issue-106670.kCGyRc.rst index f2c348370534f7..3a066162b3dfdf 100644 --- a/Misc/NEWS.d/next/Library/2023-10-07-00-18-40.gh-issue-106670.kCGyRc.rst +++ b/Misc/NEWS.d/next/Library/2023-10-07-00-18-40.gh-issue-106670.kCGyRc.rst @@ -1 +1 @@ -Set convenience variable ``$_exception`` for post mortem debugging +In :mod:`pdb`, set convenience variable ``$_exception`` for post mortem debugging.