1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/gdb/lib-for-tests/prolog.py Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,75 @@ 1.4 +import gdb 1.5 +import os 1.6 +import re 1.7 +import sys 1.8 +import traceback 1.9 + 1.10 +# testlibdir is set on the GDB command line, via --eval-command python testlibdir=... 1.11 +sys.path[0:0] = [testlibdir] 1.12 + 1.13 +# Run the C++ fragment named |fragment|, stopping on entry to |function| 1.14 +# ('breakpoint', by default) and then select the calling frame. 1.15 +def run_fragment(fragment, function='breakpoint'): 1.16 + # Arrange to stop at a reasonable place in the test program. 1.17 + bp = gdb.Breakpoint(function); 1.18 + try: 1.19 + gdb.execute("run %s" % (fragment,)) 1.20 + # Check that we did indeed stop by hitting the breakpoint we set. 1.21 + assert bp.hit_count == 1 1.22 + finally: 1.23 + bp.delete() 1.24 + gdb.execute('frame 1') 1.25 + 1.26 +# Assert that |actual| is equal to |expected|; if not, complain in a helpful way. 1.27 +def assert_eq(actual, expected): 1.28 + if actual != expected: 1.29 + raise AssertionError, """Unexpected result: 1.30 +expected: %r 1.31 +actual: %r""" % (expected, actual) 1.32 + 1.33 +# Assert that |value|'s pretty-printed form is |form|. If |value| is a 1.34 +# string, then evaluate it with gdb.parse_and_eval to produce a value. 1.35 +def assert_pretty(value, form): 1.36 + if isinstance(value, str): 1.37 + value = gdb.parse_and_eval(value) 1.38 + assert_eq(str(value), form) 1.39 + 1.40 +# Check that the list of registered pretty-printers includes one named 1.41 +# |printer|, with a subprinter named |subprinter|. 1.42 +def assert_subprinter_registered(printer, subprinter): 1.43 + # Match a line containing |printer| followed by a colon, and then a 1.44 + # series of more-indented lines containing |subprinter|. 1.45 + 1.46 + names = { 'printer': re.escape(printer), 'subprinter': re.escape(subprinter) } 1.47 + pat = r'^( +)%(printer)s *\n(\1 +.*\n)*\1 +%(subprinter)s *\n' % names 1.48 + output = gdb.execute('info pretty-printer', to_string=True) 1.49 + if not re.search(pat, output, re.MULTILINE): 1.50 + raise AssertionError, ("assert_subprinter_registered failed to find pretty-printer:\n" 1.51 + " %s:%s\n" 1.52 + "'info pretty-printer' says:\n" 1.53 + "%s" % (printer, subprinter, output)) 1.54 + 1.55 +# Request full stack traces for Python errors. 1.56 +gdb.execute('set python print-stack full') 1.57 + 1.58 +# Tell GDB not to ask the user about the things we tell it to do. 1.59 +gdb.execute('set confirm off', False) 1.60 + 1.61 +# Some print settings that make testing easier. 1.62 +gdb.execute('set print static-members off') 1.63 +gdb.execute('set print address off') 1.64 +gdb.execute('set print pretty off') 1.65 +gdb.execute('set width 0') 1.66 + 1.67 +try: 1.68 + # testscript is set on the GDB command line, via: 1.69 + # --eval-command python testscript=... 1.70 + execfile(testscript) 1.71 +except AssertionError as err: 1.72 + sys.stderr.write('\nAssertion traceback:\n') 1.73 + (t, v, tb) = sys.exc_info() 1.74 + traceback.print_tb(tb) 1.75 + sys.stderr.write('\nTest assertion failed:\n') 1.76 + sys.stderr.write(str(err)) 1.77 + sys.exit(1) 1.78 +