From dc9c87254aae436147a577290007b0a0b3a8210a Mon Sep 17 00:00:00 2001 From: Gulshan Singh Date: Mon, 24 Jun 2024 16:46:01 -0700 Subject: [PATCH] Exit with non-zero code from gdbinit.py if an exception occurs (#2242) * Exit with non-zero code from gdbinit.py if an exception occurs * Update gdbinit.py --------- Co-authored-by: Disconnect3d --- gdbinit.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/gdbinit.py b/gdbinit.py index 32ec99b0b..61e8f3896 100644 --- a/gdbinit.py +++ b/gdbinit.py @@ -8,6 +8,7 @@ import site import subprocess import sys import time +import traceback from glob import glob from pathlib import Path from typing import List @@ -163,8 +164,15 @@ def main() -> None: pwndbg.profiling.profiler.start() -main() +# We wrap everything in try/except so that we can exit GDB with an error code +# This is used by tests to check if gdbinit.py failed +try: + main() -# We've already imported this in `main`, but we reimport it here so that it's available -# at the global scope when some starts a Python interpreter in GDB -import pwndbg # noqa: F401 + # We've already imported this in `main`, but we reimport it here so that it's + # available at the global scope when some starts a Python interpreter in GDB + import pwndbg # noqa: F401 + +except Exception: + print(traceback.format_exc(), file=sys.stderr) + sys.exit(1)