catcher.py (1184B)
1 # This Source Code Form is subject to the terms of the Mozilla Public 2 # License, v. 2.0. If a copy of the MPL was not distributed with this file, 3 # You can obtain one at http://mozilla.org/MPL/2.0/. 4 5 # Apparently, there's simply no way to ask GDB to exit with a non-zero 6 # status when the script run with the --eval-command option fails. Thus, if 7 # we have --eval-command run prologue.py directly, syntax errors there will 8 # lead GDB to exit with no indication anything went wrong. 9 # 10 # To avert that, we use this very small launcher script to run prologue.py 11 # and catch errors. 12 # 13 # Remember, errors in this file will cause spurious passes, so keep this as 14 # simple as possible! 15 # flake8: noqa: F821 16 17 import os 18 import sys 19 import traceback 20 21 22 def execfile(filename, globs, locs): 23 with open(filename) as f: 24 code = compile(f.read(), filename, "exec") 25 exec(code, globs, locs) 26 27 28 try: 29 # testlibdir is set on the GDB command line, via: 30 # --eval-command python testlibdir=... 31 execfile(os.path.join(testlibdir, "prologue.py"), globals(), locals()) 32 except Exception: 33 sys.stderr.write("Error running GDB prologue:\n") 34 traceback.print_exc() 35 sys.exit(1)