How to use the drgn.array_type function in drgn

To help you get started, we’ve selected a few drgn examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github osandov / drgn / tests / test_program.py View on Github external
def test_array(self):
        prog = mock_program()
        self.assertEqual(prog.type('int []'),
                         array_type(None, int_type('int', 4, True)))
        self.assertEqual(prog.type('int [20]'),
                         array_type(20, int_type('int', 4, True)))
        self.assertEqual(prog.type('int [0x20]'),
                         array_type(32, int_type('int', 4, True)))
        self.assertEqual(prog.type('int [020]'),
                         array_type(16, int_type('int', 4, True)))
        self.assertEqual(prog.type('int [2][3]'),
                         array_type(2, array_type(3, int_type('int', 4, True))))
        self.assertEqual(prog.type('int [2][3][4]'),
                         array_type(2, array_type(3, array_type(4, int_type('int', 4, True)))))
github osandov / drgn / tests / test_dwarf.py View on Github external
),
            DwarfDie(
                DW_TAG.array_type,
                [DwarfAttrib(DW_AT.type, DW_FORM.ref4, 3)],
            ),
            int_die,
        ]

        type_ = struct_type('foo', 4, (
            (typedef_type('ZARRAY', array_type(0, int_type('int', 4, True))),
             'a'),
        ))
        self.assertFromDwarf(dies, type_)

        farray_zarray = typedef_type('ZARRAY',
                                     array_type(None, int_type('int', 4, True)))

        # GCC < 9.0.
        del dies[1].children[0]
        prog = dwarf_program(dies)
        self.assertEqual(prog.type('struct foo'), type_)
        # Although the ZARRAY type must be a zero-length array in the context
        # of the structure, it could still be an incomplete array if used
        # elsewhere.
        self.assertEqual(prog.type('ZARRAY'), farray_zarray)

        # Make sure it still works if we parse the array type first.
        prog = dwarf_program(dies)
        self.assertEqual(prog.type('ZARRAY'), farray_zarray)
        self.assertEqual(prog.type('struct foo'), type_)
github osandov / drgn / tests / test_type_index.py View on Github external
def test_pointer_to_array(self):
        tindex = TypeIndex(8)
        self.assertEqual(tindex.find('int (*)[2]'),
                         pointer_type(8, array_type(2, int_type('int', 4, True))))
        self.assertEqual(tindex.find('int (*)[2][3]'),
                         pointer_type(8, array_type(2, array_type(3, int_type('int', 4, True)))))
github osandov / drgn / tests / test_type_index.py View on Github external
def test_array(self):
        tindex = TypeIndex(8)
        self.assertEqual(tindex.find('int []'),
                         array_type(None, int_type('int', 4, True)))
        self.assertEqual(tindex.find('int [20]'),
                         array_type(20, int_type('int', 4, True)))
        self.assertEqual(tindex.find('int [0x20]'),
                         array_type(32, int_type('int', 4, True)))
        self.assertEqual(tindex.find('int [020]'),
                         array_type(16, int_type('int', 4, True)))
        self.assertEqual(tindex.find('int [2][3]'),
                         array_type(2, array_type(3, int_type('int', 4, True))))
        self.assertEqual(tindex.find('int [2][3][4]'),
                         array_type(2, array_type(3, array_type(4, int_type('int', 4, True)))))
github osandov / drgn / tests / test_language_c.py View on Github external
def test_array_of_pointers_to_functions(self):
        i = int_type('int', 4, True)
        self.assertTypeName(array_type(4, pointer_type(8, function_type(i, ((i,),), False))),
                            'int (*[4])(int)', True)
github osandov / drgn / tests / test_type_index.py View on Github external
def test_array(self):
        tindex = TypeIndex(8)
        self.assertEqual(tindex.find('int []'),
                         array_type(None, int_type('int', 4, True)))
        self.assertEqual(tindex.find('int [20]'),
                         array_type(20, int_type('int', 4, True)))
        self.assertEqual(tindex.find('int [0x20]'),
                         array_type(32, int_type('int', 4, True)))
        self.assertEqual(tindex.find('int [020]'),
                         array_type(16, int_type('int', 4, True)))
        self.assertEqual(tindex.find('int [2][3]'),
                         array_type(2, array_type(3, int_type('int', 4, True))))
        self.assertEqual(tindex.find('int [2][3][4]'),
                         array_type(2, array_type(3, array_type(4, int_type('int', 4, True)))))
github osandov / drgn / tests / test_program.py View on Github external
def test_pointer_to_array_of_pointers(self):
        prog = mock_program()
        self.assertEqual(prog.type('int *(*)[2]'),
                         pointer_type(8, array_type(2, pointer_type(8, int_type('int', 4, True)))))
        self.assertEqual(prog.type('int *((*)[2])'),
                         pointer_type(8, array_type(2, pointer_type(8, int_type('int', 4, True)))))
github osandov / drgn / tests / test_object.py View on Github external
self.assertRaisesRegex(TypeError,
                               'cannot create object with incomplete structure type',
                               Object, self.prog, struct_type('foo'), value={})

        self.assertRaisesRegex(TypeError,
                               'cannot create object with incomplete union type',
                               Object, self.prog, union_type('foo'), value={})

        self.assertRaisesRegex(TypeError,
                               'cannot create object with incomplete enumerated type',
                               Object, self.prog, enum_type('foo'), value=0)

        self.assertRaisesRegex(TypeError,
                               'cannot create object with incomplete array type',
                               Object, self.prog,
                               array_type(None, int_type('int', 4, True)),
                               value=[])
github osandov / drgn / tests / test_language_c.py View on Github external
def test_array_of_pointers_to_array(self):
        self.assertTypeName(array_type(2, pointer_type(8, array_type(3, int_type('int', 4, True)))),
                            'int (*[2])[3]', True)
github osandov / drgn / tests / test_language_c.py View on Github external
def test_array(self):
        i = int_type('int', 4, True)
        self.assertTypeName(array_type(None, i), 'int []', True)
        self.assertTypeName(array_type(2, i), 'int [2]', True)
        self.assertTypeName(array_type(2, array_type(3, i)), 'int [2][3]', True)
        self.assertTypeName(array_type(2, array_type(3, array_type(4, i))),
                            'int [2][3][4]', True)