From 9951ad78c80e144c166a7d476cad7ffdf84332a9 Mon Sep 17 00:00:00 2001 From: Ben Longbons Date: Wed, 13 Aug 2014 14:55:49 -0700 Subject: Debug debugging --- tools/debug-debug-scripts | 99 +++++++++++++++++++++++++++++++++++++++++++++++ tools/debug-debug.gdb | 35 +++++++++++++++++ 2 files changed, 134 insertions(+) create mode 100755 tools/debug-debug-scripts create mode 100644 tools/debug-debug.gdb (limited to 'tools') diff --git a/tools/debug-debug-scripts b/tools/debug-debug-scripts new file mode 100755 index 0000000..79520e9 --- /dev/null +++ b/tools/debug-debug-scripts @@ -0,0 +1,99 @@ +#!/usr/bin/env python + +from __future__ import print_function + +import itertools +import os +import subprocess +import sys +import tempfile + +error = False + +def eprint(s): + print('Error:', s, file=sys.stderr) + +def get_classes_from_file(a): + global error + d = {} + execfile(a, d) + for (k, v) in sorted(d.items()): + try: + name = v.name + except AttributeError: + if hasattr(v, 'enabled') and hasattr(v, 'tests'): + name = 'None::' + k + else: + continue + else: + if name.split('::')[-1] != k: + eprint('Mismatch: class %s is for %s' % (k, name)) + error = True + if not v.enabled: + eprint('Disabled: %s' % name) + continue + + try: + tests = v.tests + except AttributeError: + eprint('Unimplemented tests for %s' % name) + error = True + continue + extra = getattr(v, 'test_extra', '').rstrip(' ') + yield (k, tests, extra) + +def c_quote(s): + s = s.replace('\\', '\\\\') + s = s.replace('"', '\\"') + return '"' + s + '"' + +def gen_test(name, expr, expected): + print('static') + print('void %s()' % name) + print('{') + print(' auto value = %s;' % expr) + print(' const char *expected = %s;' % c_quote(expected)) + print(' do_breakpoint(value, expected);') + print('}') + +def main(args): + print('// Generated by', __file__) + print('#include ') + print() + print('template') + print('__attribute__((noinline))') + print('void do_breakpoint(const T& value, const char *expected)') + print('{') + print(' (void)value;') + print(' (void)expected;') + print(' if (!expected) printf("printer test: %p = %s\\n", &value, expected);') + print('}') + + names = [] + for a in args: + basename, ext = os.path.splitext(a) + assert ext == '.py' + print() + print('// Tests from', a) + header = basename + '.hpp' + print('#include "%s"' % header) + + for (k, tests, extra) in get_classes_from_file(a): + print() + print('// Tests for', k) + print(extra) + for (i, (expr, expected)) in enumerate(tests): + name = 'testset_%s_subtest_%d' % (k, i) + gen_test(name, expr, expected) + names.append(name) + print('int main()') + print('{') + for n in names: + print(' %s();' % n) + print('}') + if error and not os.getenv('TMWA_FORCE_GENERATE'): + sys.exit(1) + + +if __name__ == '__main__': + main(sys.argv[1:]) diff --git a/tools/debug-debug.gdb b/tools/debug-debug.gdb new file mode 100644 index 0000000..0389341 --- /dev/null +++ b/tools/debug-debug.gdb @@ -0,0 +1,35 @@ +# vim: ft=python +set logging file /dev/null +set logging redirect on +set logging off + +python +import sys + +def hit_breakpoint(): + sys.stdout.write('.') + value = str(gdb.parse_and_eval('*&value')) + expected = gdb.parse_and_eval('expected').string() + if value != expected: + print 'Error: mismatch, aborting ...' + print 'actual: %r' % value + print 'expect: %r' % str(expected) + gdb.execute('bt') + sys.exit(1) +end + +# register a pretty-printer for 'char *' instead +#set print address off +set print static-members off +set print elements unlimited +set print frame-arguments none + +set logging on +rbreak do_breakpoint +set logging off +commands +silent +python hit_breakpoint() +continue +end +run -- cgit v1.2.3-60-g2f50