How to use the drgn.pointer_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_language_c.py View on Github external
def test_pointer_to_array_of_pointers(self):
        self.assertTypeName(pointer_type(8, array_type(2, pointer_type(8, int_type('int', 4, True)))),
                            'int *(*)[2]', True)
github osandov / drgn / tests / test_program.py View on Github external
def test_pointer(self):
        prog = mock_program()
        self.assertEqual(prog.type('int *'),
                         pointer_type(8, int_type('int', 4, True)))
        self.assertEqual(prog.type('const int *'),
                         pointer_type(8, int_type('int', 4, True, Qualifiers.CONST)))
        self.assertEqual(prog.type('int * const'),
                         pointer_type(8, int_type('int', 4, True), Qualifiers.CONST))
        self.assertEqual(prog.type('int **'),
                         pointer_type(8, pointer_type(8, int_type('int', 4, True))))
        self.assertEqual(prog.type('int *((*))'),
                         pointer_type(8, pointer_type(8, int_type('int', 4, True))))
        self.assertEqual(prog.type('int * const *'),
                         pointer_type(8, pointer_type(8, int_type('int', 4, True), Qualifiers.CONST)))
github osandov / drgn / tests / test_type.py View on Github external
def test_pointer(self):
        t = pointer_type(8, int_type('int', 4, True))
        self.assertEqual(t.kind, TypeKind.POINTER)
        self.assertIsNone(t.primitive)
        self.assertEqual(t.size, 8)
        self.assertEqual(t.type, int_type('int', 4, True))
        self.assertTrue(t.is_complete())

        self.assertEqual(t, pointer_type(8, int_type('int', 4, True)))
        # Qualified type argument.
        self.assertEqual(t, pointer_type(8, int_type('int', 4, True)))
        # Different size.
        self.assertNotEqual(t, pointer_type(4, int_type('int', 4, True)))
        # Different type.
        self.assertNotEqual(t, pointer_type(8, void_type()))
        self.assertNotEqual(t, pointer_type(8, void_type(Qualifiers.CONST)))

        self.assertEqual(repr(t), "pointer_type(size=8, type=int_type(name='int', size=4, is_signed=True))")
        self.assertEqual(sizeof(t), 8)

        self.assertRaises(TypeError, pointer_type, None,
                          int_type('int', 4, True))
        self.assertRaises(TypeError, pointer_type, 8, 4)
github osandov / drgn / tests / test_language_c.py View on Github external
def test_pointer_to_function_returning_const_pointer(self):
        i = int_type('int', 4, True)
        self.assertTypeName(pointer_type(8, function_type(pointer_type(8, i, Qualifiers.CONST), ((i,),), False)),
                            'int * const (*)(int)', True)
github osandov / drgn / tests / test_language_c.py View on Github external
def test_pointer(self):
        self.assertTypeName(pointer_type(8, void_type()), 'void *', True)
        t = pointer_type(8, void_type(Qualifiers.VOLATILE))
        self.assertTypeName(t, 'volatile void *', True)
        t = pointer_type(8, void_type(Qualifiers.VOLATILE), Qualifiers.CONST)
        self.assertTypeName(t, 'volatile void * const', True)
        t = pointer_type(8, t)
        self.assertTypeName(t, 'volatile void * const *', True)
github osandov / drgn / tests / test_dwarf.py View on Github external
DwarfAttrib(DW_AT.type, DW_FORM.ref4, 3),
                        ],
                    ),
                    DwarfDie(
                        DW_TAG.member,
                        [
                            DwarfAttrib(DW_AT.name, DW_FORM.string, 'y'),
                            DwarfAttrib(DW_AT.data_member_location, DW_FORM.data1, 4),
                            DwarfAttrib(DW_AT.type, DW_FORM.ref4, 3),
                        ],
                    ),
                ],
            ),
            int_die,
        ]
        self.assertFromDwarf(dies, pointer_type(8, point_type))

        # Ambiguous incomplete type.
        dies.append(
            DwarfDie(
                DW_TAG.structure_type,
                [
                    DwarfAttrib(DW_AT.name, DW_FORM.string, 'point'),
                    DwarfAttrib(DW_AT.byte_size, DW_FORM.data1, 8),
                    DwarfAttrib(DW_AT.decl_file, DW_FORM.udata, 'bar.c'),
                ],
                [
                    DwarfDie(
                        DW_TAG.member,
                        [
                            DwarfAttrib(DW_AT.name, DW_FORM.string, 'a'),
                            DwarfAttrib(DW_AT.data_member_location, DW_FORM.data1, 0),
github osandov / drgn / tests / test_type_index.py View on Github external
def test_array_of_pointers(self):
        tindex = TypeIndex(8)
        self.assertEqual(tindex.find('int *[2][3]'),
                         array_type(2, array_type(3, pointer_type(8, int_type('int', 4, True)))))
github osandov / drgn / tests / test_language_c.py View on Github external
def test_pointer_to_pointer_to_array(self):
        self.assertTypeName(pointer_type(8, pointer_type(8, array_type(2, int_type('int', 4, True)))),
                            'int (**)[2]', True)
github delphix / sdb / sdb / target.py View on Github external
def type_canonicalize(t: drgn.Type) -> drgn.Type:
    """
    Return the "canonical" version of this type.  This means removing
    qualifiers (const, volatile, etc) and typedef's.

    For example the type `foo_t*` will be canonicalized to `struct foo *`.

    Note: function type's arguments and return types are not canonicalized.
    """
    if t.kind == drgn.TypeKind.TYPEDEF:
        return type_canonicalize(t.type)
    if t.kind == drgn.TypeKind.POINTER:
        return drgn.pointer_type(t.size, type_canonicalize(t.type))
    if t.kind == drgn.TypeKind.ARRAY:
        return drgn.array_type(t.length, type_canonicalize(t.type))
    return t.unqualified()