Restore `sys.excepthook` after leaved IPython

This commit is contained in:
lebr0nli 2022-09-27 22:31:40 +08:00 committed by Disconnect3d
parent 33d9e35b0f
commit c7a72e226f
1 changed files with 3 additions and 1 deletions

View File

@ -15,6 +15,7 @@ def switch_to_ipython_env():
# Save GDB's stdout and stderr
saved_stdout = sys.stdout
saved_stderr = sys.stderr
saved_excepthook = sys.excepthook
# Use Python's default stdout and stderr
sys.stdout = sys.__stdout__
sys.stderr = sys.__stderr__
@ -22,9 +23,10 @@ def switch_to_ipython_env():
# Restore GDB's stdout and stderr
sys.stdout = saved_stdout
sys.stderr = saved_stderr
# Restore Python's default ps1 and ps2 for GDB's `pi` command
# Restore Python's default ps1, ps2, and excepthook for GDB's `pi` command
sys.ps1 = ">>> "
sys.ps2 = "... "
sys.excepthook = saved_excepthook
@pwndbg.commands.ArgparsedCommand("Start an interactive IPython prompt.")