Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Lib/pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions Lib/test/test_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -882,6 +884,8 @@ def test_post_mortem_chained():
(Pdb) exceptions 0
> <doctest test.test_pdb.test_post_mortem_chained[0]>(3)test_function_2()
-> 1/0
(Pdb) $_exception
ZeroDivisionError('division by zero')
(Pdb) up
> <doctest test.test_pdb.test_post_mortem_chained[1]>(3)test_function_reraise()
-> test_function_2()
Expand All @@ -891,6 +895,8 @@ def test_post_mortem_chained():
(Pdb) exceptions 1
> <doctest test.test_pdb.test_post_mortem_chained[1]>(5)test_function_reraise()
-> raise ZeroDivisionError('reraised') from e
(Pdb) $_exception
ZeroDivisionError('reraised')
(Pdb) up
> <doctest test.test_pdb.test_post_mortem_chained[2]>(5)test_function()
-> test_function_reraise()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
In :mod:`pdb`, set convenience variable ``$_exception`` for post mortem debugging.