How to use the drgn.void_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_type.py View on Github external
def test_cmp(self):
        self.assertEqual(void_type(), void_type())
        self.assertEqual(void_type(Qualifiers.CONST),
                         void_type(Qualifiers.CONST))
        self.assertNotEqual(void_type(), void_type(Qualifiers.CONST))
        self.assertNotEqual(void_type(), int_type('int', 4, True))
        self.assertNotEqual(void_type(), 1)
        self.assertNotEqual(1, void_type())
github osandov / drgn / tests / test_dwarf.py View on Github external
def test_qualifiers(self):
        dies = [
            DwarfDie(
                DW_TAG.const_type,
                [DwarfAttrib(DW_AT.type, DW_FORM.ref4, 1)],
            ),
            int_die,
        ]
        self.assertFromDwarf(dies, int_type('int', 4, True, Qualifiers.CONST))

        del dies[0].attribs[0]
        self.assertFromDwarf(dies, void_type(Qualifiers.CONST))

        dies = [
            DwarfDie(
                DW_TAG.const_type,
                [DwarfAttrib(DW_AT.type, DW_FORM.ref4, 1)],
            ),
            DwarfDie(
                DW_TAG.restrict_type,
                [DwarfAttrib(DW_AT.type, DW_FORM.ref4, 2)],
            ),
            DwarfDie(
                DW_TAG.volatile_type,
                [DwarfAttrib(DW_AT.type, DW_FORM.ref4, 3)],
            ),
            DwarfDie(
                DW_TAG.atomic_type,
github osandov / drgn / tests / test_object.py View on Github external
self.assertTrue(ptr0 != ptr1)
        self.assertTrue(ptr0 != fptr1)
        self.assertFalse(ptr1 != fptr1)

        self.assertFalse(ptr0 > ptr1)
        self.assertFalse(ptr0 > fptr1)
        self.assertFalse(ptr1 > fptr1)

        self.assertFalse(ptr0 >= ptr1)
        self.assertFalse(ptr0 >= fptr1)
        self.assertTrue(ptr1 >= fptr1)

        self.assertRaises(TypeError, operator.lt, ptr0, self.int(1))

        func = Object(self.prog,
                      function_type(void_type(), (), False), address=0xffff0000)
        self.assertTrue(func == func)
        self.assertTrue(func == ptr0)

        array = Object(self.prog, 'int [8]', address=0xffff0000)
        self.assertTrue(array == array)
        self.assertTrue(array != ptr1)

        incomplete = Object(self.prog, 'int []', address=0xffff0000)
        self.assertTrue(incomplete == incomplete)
        self.assertTrue(incomplete == ptr0)

        self.assertRaises(TypeError, operator.eq,
                          Object(self.prog, struct_type('foo', None, None),
                                 address=0xffff0000),
                          ptr0)
github osandov / drgn / tests / test_type.py View on Github external
def test_qualifiers(self):
        self.assertEqual(void_type().qualifiers, Qualifiers(0))

        t = void_type(Qualifiers.CONST | Qualifiers.VOLATILE)
        self.assertEqual(t.qualifiers, Qualifiers.CONST | Qualifiers.VOLATILE)
        self.assertEqual(repr(t), 'void_type(qualifiers=)')

        self.assertEqual(t.qualified(Qualifiers.ATOMIC),
                         void_type(Qualifiers.ATOMIC))
        self.assertEqual(t.unqualified(), void_type())
        self.assertEqual(t.qualified(Qualifiers(0)), t.unqualified())

        self.assertRaisesRegex(TypeError, 'expected Qualifiers or None',
                               void_type, 1.5)
github osandov / drgn / tests / test_dwarf.py View on Github external
def test_pointer(self):
        dies = [
            DwarfDie(
                DW_TAG.pointer_type,
                [
                    DwarfAttrib(DW_AT.type, DW_FORM.ref4, 1),
                ],
            ),
            int_die,
        ]
        self.assertFromDwarf(dies, pointer_type(8, int_type('int', 4, True)))

        del dies[0].attribs[0]
        self.assertFromDwarf(dies, pointer_type(8, void_type()))
github osandov / drgn / tests / test_type.py View on Github external
self.assertEqual(repr(t), "function_type(type=void_type(), parameters=((int_type(name='int', size=4, is_signed=True), 'n'),), is_variadic=False)")
        self.assertRaises(TypeError, sizeof, t)

        self.assertFalse(function_type(void_type(), (), False).is_variadic)
        self.assertTrue(function_type(void_type(), (), True).is_variadic)

        self.assertRaisesRegex(TypeError, 'must be Type', function_type, None,
                               ())
        self.assertRaisesRegex(TypeError, 'must be sequence', function_type,
                               void_type(), None)
        self.assertRaisesRegex(TypeError, 'must be.*sequence', function_type,
                               void_type(), (4,))
        self.assertRaisesRegex(ValueError, 'must be.*sequence', function_type,
                               void_type, ((),))
        self.assertRaisesRegex(TypeError, 'must be string or None',
                               function_type, void_type(),
                               ((int_type('int', 4, True), 4),))
        self.assertRaisesRegex(TypeError, 'must be Type', function_type,
                               void_type(), ((None, 'n'),))
github osandov / drgn / tests / test_type.py View on Github external
def test_cmp(self):
        self.assertEqual(void_type(), void_type())
        self.assertEqual(void_type(Qualifiers.CONST),
                         void_type(Qualifiers.CONST))
        self.assertNotEqual(void_type(), void_type(Qualifiers.CONST))
        self.assertNotEqual(void_type(), int_type('int', 4, True))
        self.assertNotEqual(void_type(), 1)
        self.assertNotEqual(1, void_type())
github osandov / drgn / tests / test_type.py View on Github external
def test_qualifiers(self):
        self.assertEqual(void_type().qualifiers, Qualifiers(0))

        t = void_type(Qualifiers.CONST | Qualifiers.VOLATILE)
        self.assertEqual(t.qualifiers, Qualifiers.CONST | Qualifiers.VOLATILE)
        self.assertEqual(repr(t), 'void_type(qualifiers=)')

        self.assertEqual(t.qualified(Qualifiers.ATOMIC),
                         void_type(Qualifiers.ATOMIC))
        self.assertEqual(t.unqualified(), void_type())
        self.assertEqual(t.qualified(Qualifiers(0)), t.unqualified())

        self.assertRaisesRegex(TypeError, 'expected Qualifiers or None',
                               void_type, 1.5)
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_object.py View on Github external
def test_void(self):
        obj = Object(self.prog, void_type(), address=0)
        self.assertIs(obj.prog_, self.prog)
        self.assertEqual(obj.type_, void_type())
        self.assertEqual(obj.address_, 0)
        self.assertEqual(obj.byteorder_, 'little')
        self.assertEqual(obj.bit_offset_, 0)
        self.assertIsNone(obj.bit_field_size_)
        self.assertRaisesRegex(TypeError, 'cannot read object with void type',
                               obj.value_)
        self.assertRaisesRegex(TypeError, 'cannot read object with void type',
                               obj.read_)
        self.assertRaises(TypeError, sizeof, obj)