from support.build import gnatmake from support.gdb import GDBSession gnatmake('foo') # Run gnatdbg.setup twice, check that the pretty-printers still work gdb = GDBSession('foo', log_file='gdb-double-setup.log', load_gnatdbg=True) gdb.run_to(gdb.find_loc('foo.adb', 'BREAK')) gdb.test('python gnatdbg.setup()', '') gdb.print_expr('empty_string', 'Unbounded_String ("")') gdb.stop() # Run gnatdbg.setup without registering pretty-printers globally gdb = GDBSession('foo', log_file='gdb-local.log', load_gnatdbg=False) gdb.run_to(gdb.find_loc('foo.adb', 'BREAK')) gdb.test('python import gnatdbg; gnatdbg.setup(globally=False)', '') gdb.print_expr('empty_string', 'Unbounded_String ("")') # Re-load and re-run foo, just to make sure the new_objfile event is run. gdb.kill() gdb.run_to(gdb.find_loc('foo.adb', 'BREAK')) gdb.print_expr('empty_string', 'Unbounded_String ("")')
from support.build import gnatmake from support.gdb import GDBSession gnatmake('foo') gdb = GDBSession('foo') gdb.run_to(gdb.find_loc('foo.adb', 'BREAK')) # Corrupt the linked list and the cursor gdb.test('set variable l.length := 2', '') gdb.test('set variable cur.container := 1', '') gdb.test('set variable cur.node := 2', '') gdb.print_expr( 'l', 'foo.str_lists.list of length 2 =' ' {"one",' ' "two"' '<error reading variable: The linked list seems invalid>...}') gdb.print_expr('cur', 'Cursor ([Invalid])')
from support.build import gnatmake from support.gdb import GDBSession gnatmake('foo') gdb = GDBSession('foo') gdb.run_to(gdb.find_loc('foo.adb', 'BREAK')) gdb.execute('python import gnatdbg.debug') gdb.execute('python gnatdbg.debug.PrintGDBTypeTreeCommand()') gdb.test('dbgtype i', '%0 (integer : TYPE_CODE_INT) (4 bytes)') gdb.test('dbgtype l', '%0 (foo.linked_list : TYPE_CODE_TYPEDEF):' ' %1 (None : TYPE_CODE_PTR):' ' %2 (foo.linked_list_record : TYPE_CODE_STRUCT):' ' value: %3 (integer : TYPE_CODE_INT) (4 bytes)' ' next: %0 (foo.linked_list : TYPE_CODE_TYPEDEF)') gdb.test('dbgtype s', '%0 (foo__TsS : TYPE_CODE_ARRAY)[1 .. 13]:' ' %1 (character : TYPE_CODE_CHAR)')
from support.build import gnatmake from support.gdb import GDBSession gnatmake('foo') gdb = GDBSession('foo') gdb.run_to(gdb.find_loc('foo.adb', 'BREAK')) gdb.test('set lang c', 'Warning: the current language does not match this frame.') gdb.test('set corrupted_string.P_ARRAY = 0x1', '') gdb.test('set lang auto', '') gdb.print_expr('null_string', '0x0 <null string access>') gdb.print_expr('empty_string', '""') gdb.print_expr('some_string', '"Hello, world!"') gdb.print_expr('binary_string', '"b["00"]""["ff"]"') gdb.print_expr('wstring', '"wide string"') gdb.print_expr('wwstring', '"wide wide string"') gdb.print_expr('corrupted_string', '<error: Cannot access memory at address 0x1>') gdb.test( 'python' ' i = gdb.parse_and_eval("i");' ' v = gnatdbg.strings.StringAccess(i)', '@...TypeError: Input is not an access to string@...')
from support.build import gnatmake from support.gdb import GDBSession gnatmake('foo') gdb = GDBSession('foo') gdb.run_to(gdb.find_loc('foo.adb', 'BREAK')) gdb.test( 'source script.py', """\ Trying to access element 4 of "V"... gdb.MemoryError: Out of bound vector access (4 not in 1 .. 3) Trying to print vector at address 0... gdb.MemoryError: Cannot access memory at address 0x0 Trying to print corrupted cursor... Cursor ([Invalid])""")
tests = [ # Regular cases ('O', dm('others')), ('S1', dm('1')), ('S1R2T3', dm('1 | 2 .. 3')), ('S1S2S3', dm('1 | 2 | 3')), ('R1T100', dm('1 .. 100')), # Erroneous cases ('', error), ('a', error), ('S', error), ('Sa', error), ('R', error), ('Ra', error), ('R1a', error), ('R1T', error), ('R1Ta', error), ('R1T10a', error), ] gdb.test('source helpers.py', '') for field_name, baseline in tests: if baseline == error: baseline = error(field_name) gdb.test('python evaluate({})'.format(repr(field_name)), baseline)
from support.build import gnatmake from support.gdb import GDBSession gnatmake('foo') gdb = GDBSession('foo') gdb.run_to(gdb.find_loc('foo.adb', 'BREAK')) gdb.test( 'source script.py', """\ Debug: mismatch: Struct(2 fields) <-> TYPE_CODE_STRUCT (name=foo__my_record, 2 fields) Field(name=n) <-> n TypeName(name=natural) <-> TYPE_CODE_RANGE\ (name=positive___XDLU_1__@/.*/)""")
from support.build import gnatmake from support.gdb import GDBSession gnatmake('foo') gdb = GDBSession('foo') gdb.run_to(gdb.find_loc('foo.adb', 'BREAK')) gdb.execute('set corrupted_string.reference := 0x1') gdb.print_expr('empty_string', 'Unbounded_String ("")') gdb.print_expr('some_string', 'Unbounded_String ("Hello, world!")') gdb.print_expr('binary_string', 'Unbounded_String ("b["00"]""["ff"]")') gdb.print_expr('corrupted_string', 'Unbounded_String ([Invalid])') gdb.test( 'python' ' s = gdb.parse_and_eval("binary_string");' ' v = gnatdbg.strings.UnboundedString(s);' ' string = v.get_string("ascii", errors="ignore");' ' print(gnatdbg.utils.ada_string_repr(string))', '"b["00"]"""')
from support.build import gnatmake from support.gdb import GDBSession gnatmake('foo') gdb = GDBSession('foo') gdb.run_to(gdb.find_loc('foo.adb', 'BREAK')) gdb.test('source helpers.py', '') gdb.test('pi print_record("R", gdb.parse_and_eval("R"))', '== R ==\n' ' i: 1\n' ' c: 65 \'A\'')
from support.build import gnatmake from support.gdb import GDBSession gnatmake('main') gdb = GDBSession('main') gdb.run_to(gdb.find_loc('main.adb', 'break here')) gdb.test('source custom.py', '') gdb.print_expr( 'v', '(t => time, vec => main.time_vectors.vector of length 1 = {time})')
from support.build import gnatmake from support.gdb import GDBSession gnatmake('foo') gdb = GDBSession('foo') gdb.run_to(gdb.find_loc('foo.adb', 'BREAK')) gdb.test('python from gnatdbg.tagged import *', '') gdb.test( 'python' ' c = gdb.parse_and_eval("c");' ' r = gdb.parse_and_eval("r");' ' i = gdb.parse_and_eval("i");', '') gdb.test( 'python' ' rc = reinterpret_tagged(c);' ' rr = reinterpret_tagged(r);' ' ri = reinterpret_tagged(i);', '') gdb.test('python print("c: {} -> {} {}".format(c.type, rc.type, rc))', 'c: access p.child_type' ' -> p.child_type (i => 1, j => 2, k => 3)') gdb.test('python print("r: {} -> {} {}".format(r.type, rr.type, rr))', 'r: access p.root_type' ' -> p.child_type (i => 1, j => 2, k => 3)') gdb.test( 'python print("i: {} -> {} {}".format(i.type, ri.type, ri))', 'i: access p.interface_type'
from support.build import gnatmake from support.gdb import GDBSession gnatmake('foo') gdb = GDBSession('foo') gdb.run_to(gdb.find_loc('foo.adb', 'BREAK')) gdb.test('source script.py', '') tests = [ ('unc_param', '== unc_param ==\n' '%0 (None : TYPE_CODE_ARRAY)[1 .. 5]:\n' ' %1 (character : TYPE_CODE_CHAR)\n' '"Hello"'), ('unc', '== unc ==\n' '%0 (foo__run__T@/\\d+/b : TYPE_CODE_ARRAY)[1 .. 10]:\n' ' %1 (character : TYPE_CODE_CHAR)\n' '"HelloHello"'), ('acc', '== acc ==\n' '%0 (None : TYPE_CODE_ARRAY)[1 .. 5]:\n' ' %1 (character : TYPE_CODE_CHAR)\n' '"Hello"'), ('empty', '== empty ==\n' '%0 (None : TYPE_CODE_ARRAY)[1 .. 0]:\n' ' %1 (character : TYPE_CODE_CHAR)\n' '""'), ('null_str', '== null_str ==\n' 'None'), ('i', '== i ==\n' '<ValueError: Invalid array value: 0 (TYPE_CODE_INT)>'), ]
from support.build import gnatmake from support.gdb import GDBSession gnatmake('foo') gdb = GDBSession('foo') gdb.run_to(gdb.find_loc('foo.adb', 'BREAK')) gdb.test('source pp.py', '') gdb.print_expr('i1', 'My_Int (10)') gdb.print_expr('i2', 'My_Int (20)') gdb.print_expr('n', 'My_Nat (30)') gdb.print_expr('i', '0')
from support.build import gnatmake from support.gdb import GDBSession gnatmake('foo') gdb = GDBSession('foo') gdb.run_to(gdb.find_loc('foo.adb', 'BREAK')) gdb.test('source helpers.py', '') tests = [ (0, ' n: 0\n' ' index: 100'), (1, ' n: 1\n' ' index: 101\n' ' b: true'), (2, ' n: 2\n' ' index: 102\n' ' c: 65 \'A\''), (11, ' n: 11\n' ' index: 111\n' ' i: 42'), (20, ' n: 20\n' ' index: 120'), ('Error', ' present: 65'), ] for num, expected_content in tests: simple_var = 'R{}'.format(num) gdb.test( 'pi print_record({0}, gdb.parse_and_eval({0}))'.format( repr(simple_var)), '== {} ==\n' '{}'.format(simple_var, expected_content))