Ejemplo n.º 1
0
    def tear_down(self):
        if self.coverage_enabled:
            # Process coverage data with the same Python interpreter and
            # "coverage" package that was used to produce them. To achieve
            # this, spawn GDB just like testcases.
            gdb = GDBSession(log_file=os.path.join(self.coverage_dir,
                                                   'gdb.log'),
                             load_gnatdbg=False)
            gdb.import_coverage()
            gdb.execute('python import glob')

            # Consolidate coverage data for each testcase and generate both a
            # sumary textual report on the standard output and a detailed HTML
            # report.
            gdb.execute('''python
c = coverage.Coverage(data_file={data_file!r}, config_file={config_file!r})
c.combine(glob.glob({data_files_glob!r}))
c.html_report(directory={coverage_dir!r}, title='gnatdbg coverage report')
end'''.format(data_file=os.path.join(self.coverage_dir, '.coverage'),
              data_files_glob=os.path.join(self.coverage_dir, '*.coverage'),
              config_file=self.coverage_rcfile,
              coverage_dir=self.coverage_dir))

            html_index = os.path.join(self.coverage_dir, 'index.html')
            assert os.path.exists(html_index)
            print('Detailed HTML coverage report available at:'
                  ' {}'.format(html_index))

        super(Testsuite, self).tear_down()
Ejemplo n.º 2
0
    def tear_down(self) -> None:
        ts_config: TestsuiteConfig = self.env.ts_config
        if ts_config.coverage:
            # Process coverage data with the same Python interpreter and
            # "coverage" package that was used to produce them. To achieve
            # this, spawn GDB just like testcases.
            gdb = GDBSession(log_file=os.path.join(ts_config.coverage_dir,
                                                   "gdb.log"),
                             load_gnatdbg=False)
            gdb.import_coverage()

            # Consolidate coverage data for each testcase and generate both a
            # sumary textual report on the standard output and a detailed HTML
            # report.
            script = os.path.join(self.working_dir, "coverage_script.py")
            with open(script, "w") as f:
                f.write("""
import glob

c = coverage.Coverage(data_file={data_file!r}, config_file={config_file!r})
c.combine(glob.glob({data_files_glob!r}))
c.html_report(directory={coverage_dir!r}, title="gnatdbg coverage report")
end""".format(data_file=os.path.join(ts_config.coverage_dir, ".coverage"),
                data_files_glob=os.path.join(ts_config.coverage_dir,
                                           "*.coverage"),
                config_file=ts_config.coverage_rcfile,
                coverage_dir=ts_config.coverage_dir))
            gdb.execute(f"source {script}")

            html_index = os.path.join(ts_config.coverage_dir, "index.html")
            assert os.path.exists(html_index)
            print("Detailed HTML coverage report available at:"
                  " {}".format(html_index))

        super().tear_down()
Ejemplo n.º 3
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('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@...')
Ejemplo n.º 4
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 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__@/.*/)""")
Ejemplo n.º 5
0
from support.build import gnatmake
from support.gdb import GDBSession


gdb = GDBSession()


def dm(label):
    return 'DiscriminantMatcher({})'.format(label)


def error(field_name):
    return ("ValueError(Invalid GNAT encoding for discriminant matcher: {})"
            .format(repr(field_name)))


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),
Ejemplo n.º 6
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 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')
Ejemplo n.º 7
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.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)')
Ejemplo n.º 8
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.execute('set corrupted_string.reference := 0x1')

gdb.print_expr('empty_string', '""')
gdb.print_expr('some_string', '"Hello, world!"')
gdb.print_expr('binary_string', '"b["00"]""["ff"]"')
gdb.print_expr(
    'corrupted_string',
    '<error reading variable: Cannot access memory at address 0x1>')
Ejemplo n.º 9
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.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"]"""')
Ejemplo n.º 10
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('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'
Ejemplo n.º 11
0
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})')
Ejemplo n.º 12
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.print_expr('us1', 'Unbounded_String ("Hello world!")')
gdb.print_expr('us2', 'Unbounded_String ("")')

gdb.print_expr('v1', 'foo.str_vectors.vector of length 3 ='
                     ' {Unbounded_String ("one"),'
                     '  Unbounded_String ("two"),'
                     '  Unbounded_String ("three")}')
gdb.print_expr('v2', 'foo.str_vectors.vector of length 0')
gdb.print_expr('cur_v', 'Cursor (2 => Unbounded_String ("two"))')
gdb.print_expr('no_cur_v', 'Cursor (No_Element)')

gdb.print_expr('l1', 'foo.str_lists.list of length 3 ='
                     ' {Unbounded_String ("one"),'
                     '  Unbounded_String ("two"),'
                     '  Unbounded_String ("three")}')
gdb.print_expr('l2', 'foo.str_lists.list of length 0')
gdb.print_expr('cur_l', 'Cursor (Unbounded_String ("one"))')
gdb.print_expr('no_cur_l', 'Cursor (No_Element)')

gdb.print_expr('om1', 'foo.int_to_str.map of length 3 ='
                      ' {[1] = Unbounded_String ("one"),'
                      '  [2] = Unbounded_String ("two"),'
                      '  [3] = Unbounded_String ("three")}')
Ejemplo n.º 13
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 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)>'),
]
Ejemplo n.º 14
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.execute('set corrupted.num.value.c := 0x1')

gdb.print_expr('uninit', 'Big_Real ([Uninitialized])')
gdb.print_expr('zero', 'Big_Real (0 / 1)')
gdb.print_expr('neg_one', 'Big_Real (-1 / 1)')
gdb.print_expr('neg_small', 'Big_Real (-10 / 9)')
gdb.print_expr('pos_one', 'Big_Real (1 / 1)')
gdb.print_expr('pos_small', 'Big_Real (1000 / 3)')
gdb.print_expr('corrupted', 'Big_Real ([Invalid])')
Ejemplo n.º 15
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.print_expr('us1', '"Hello world!"')
gdb.print_expr('us2', '""')

gdb.print_expr(
    'v1', 'foo.str_vectors.vector of length 3 ='
    ' {"one",'
    '  "two",'
    '  "three"}')
gdb.print_expr('v2', 'foo.str_vectors.vector of length 0')
gdb.print_expr('cur_v', 'Cursor (2 => "two")')
gdb.print_expr('no_cur_v', 'Cursor (No_Element)')

gdb.print_expr(
    'l1', 'foo.str_lists.list of length 3 ='
    ' {"one",'
    '  "two",'
    '  "three"}')
gdb.print_expr('l2', 'foo.str_lists.list of length 0')
gdb.print_expr('cur_l', 'Cursor ("one")')
gdb.print_expr('no_cur_l', 'Cursor (No_Element)')

gdb.print_expr(
    'om1', 'foo.int_to_str.map of length 3 ='
    ' {[1] = "one",'
Ejemplo n.º 16
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.execute('set corrupted.value.c := 0x1')

gdb.print_expr('uninit', 'Big_Integer ([Uninitialized])')
gdb.print_expr('zero', 'Big_Integer (0)')
gdb.print_expr('neg_one', 'Big_Integer (-1)')
gdb.print_expr('neg_small', 'Big_Integer (-1000)')
gdb.print_expr('neg_big',
               'Big_Integer (-1234567890098765432112345678900987654321)')
gdb.print_expr('pos_one', 'Big_Integer (1)')
gdb.print_expr('pos_small', 'Big_Integer (1000)')
gdb.print_expr('pos_big',
               'Big_Integer (1234567890098765432112345678900987654321)')
gdb.print_expr('corrupted', 'Big_Integer ([Invalid])')
Ejemplo n.º 17
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 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])""")
Ejemplo n.º 18
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', '')
gdb.test('pi print_record("R", gdb.parse_and_eval("R"))', '== R ==\n'
         '  i: 1\n'
         '  c: 65 \'A\'')
Ejemplo n.º 19
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'))

# 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])')
Ejemplo n.º 20
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('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', '(foo__string_access) 0x0 [Invalid]')
gdb.print_expr('empty_string', '(foo__string_access) @ADDRESS ""')
gdb.print_expr('some_string', '(foo__string_access) @ADDRESS "Hello, world!"')
gdb.print_expr('binary_string',
               '(foo__string_access) @ADDRESS "b["00"]""["ff"]"')
gdb.print_expr('wstring', '(foo__wstring_access) @ADDRESS "wide string"')
gdb.print_expr('wwstring',
               '(foo__wwstring_access) @ADDRESS "wide wide string"')
gdb.print_expr('corrupted_string', '(foo__string_access) 0x1 [Invalid]')

gdb.test(
    'python'
    ' i = gdb.parse_and_eval("i");'
    ' v = gnatdbg.strings.StringAccess(i)',
    '@...TypeError: Input is not an access to string@...')
Ejemplo n.º 21
0
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 ("")')
Ejemplo n.º 22
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))