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 <dominik.b.czarnota@gmail.com>
This commit is contained in:
Gulshan Singh 2024-06-24 16:46:01 -07:00 committed by GitHub
parent b4d6d5cbb8
commit dc9c87254a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 12 additions and 4 deletions

View File

@ -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)