How to use the drgn.internal.dwarf.Die 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_dwarftypeindex.py View on Github external
def test_union(self):
        self.dies[:] = [
            # int
            Die(self.cu, DW_TAG.base_type, [
                DieAttrib(DW_AT.byte_size, DW_FORM.data1, b'\x04'),
                DieAttrib(DW_AT.encoding, DW_FORM.data1, b'\x05'),
                DieAttrib(DW_AT.name, DW_FORM.string, b'int'),
            ]),
            # float
            Die(None, DW_TAG.base_type, [
                DieAttrib(DW_AT.byte_size, DW_FORM.data1, b'\x04'),
                DieAttrib(DW_AT.encoding, DW_FORM.data1, b'\x04'),
                DieAttrib(DW_AT.name, DW_FORM.string, b'float'),
            ]),
            # union value {
            #    int i;
            #    float f;
            # };
            Die(self.cu, DW_TAG.union_type, [
                DieAttrib(DW_AT.name, DW_FORM.string, b'value'),
                DieAttrib(DW_AT.byte_size, DW_FORM.data1, b'\x04'),
            ], lambda: [
                Die(self.cu, DW_TAG.member, [
                    DieAttrib(DW_AT.name, DW_FORM.string, b'i'),
                    DieAttrib(DW_AT.type, DW_FORM.ref4, 0),
                    DieAttrib(DW_AT.data_member_location, DW_FORM.data1, b'\x00'),
github osandov / drgn / tests / test_dwarftypeindex.py View on Github external
DieAttrib(DW_AT.name, DW_FORM.string, b'float'),
            ]),
            # double
            Die(None, DW_TAG.base_type, [
                DieAttrib(DW_AT.byte_size, DW_FORM.data1, b'\x08'),
                DieAttrib(DW_AT.encoding, DW_FORM.data1, b'\x04'),
                DieAttrib(DW_AT.name, DW_FORM.string, b'double'),
            ]),
            # long double
            Die(None, DW_TAG.base_type, [
                DieAttrib(DW_AT.byte_size, DW_FORM.data1, b'\x10'),
                DieAttrib(DW_AT.encoding, DW_FORM.data1, b'\x04'),
                DieAttrib(DW_AT.name, DW_FORM.string, b'long double'),
            ]),
            # double long
            Die(None, DW_TAG.base_type, [
                DieAttrib(DW_AT.byte_size, DW_FORM.data1, b'\x10'),
                DieAttrib(DW_AT.encoding, DW_FORM.data1, b'\x04'),
                DieAttrib(DW_AT.name, DW_FORM.string, b'double long'),
            ]),
        ]

        self.assertFromDwarfType(0, FloatType('float', 4))
        self.assertFromDwarfType(1, FloatType('double', 8))
        self.assertFromDwarfType(2, FloatType('long double', 16))
        self.assertFromDwarfType(3, FloatType('long double', 16))
github osandov / drgn / tests / test_dwarftypeindex.py View on Github external
def test_struct(self):
        self.dies[:] = [
            # int
            Die(self.cu, DW_TAG.base_type, [
                DieAttrib(DW_AT.byte_size, DW_FORM.data1, b'\x04'),
                DieAttrib(DW_AT.encoding, DW_FORM.data1, b'\x05'),
                DieAttrib(DW_AT.name, DW_FORM.string, b'int'),
            ]),
            # struct point {
            #     int x, y;
            # };
            Die(self.cu, DW_TAG.structure_type, [
                DieAttrib(DW_AT.name, DW_FORM.string, b'point'),
                DieAttrib(DW_AT.byte_size, DW_FORM.data1, b'\x08'),
            ], lambda: [
                Die(self.cu, DW_TAG.member, [
                    DieAttrib(DW_AT.name, DW_FORM.string, b'x'),
                    DieAttrib(DW_AT.type, DW_FORM.ref4, 0),
                    DieAttrib(DW_AT.data_member_location, DW_FORM.data1, b'\x00'),
                ]),
github osandov / drgn / tests / test_dwarftypeindex.py View on Github external
Die(self.cu, DW_TAG.base_type, [
                DieAttrib(DW_AT.byte_size, DW_FORM.data1, b'\x04'),
                DieAttrib(DW_AT.encoding, DW_FORM.data1, b'\x05'),
                DieAttrib(DW_AT.name, DW_FORM.string, b'int'),
            ]),
            # const int
            Die(self.cu, DW_TAG.const_type, [
                DieAttrib(DW_AT.type, DW_FORM.ref4, 0),
            ]),
            # int *
            Die(self.cu, DW_TAG.pointer_type, [
                DieAttrib(DW_AT.byte_size, DW_FORM.data1, b'\x08'),
                DieAttrib(DW_AT.type, DW_FORM.ref4, 0),
            ]),
            # int * const
            Die(self.cu, DW_TAG.const_type, [
                DieAttrib(DW_AT.type, DW_FORM.ref4, 2),
            ]),
            # void *
            Die(self.cu, DW_TAG.pointer_type, [
                DieAttrib(DW_AT.byte_size, DW_FORM.data1, b'\x08'),
            ]),
        ]

        self.assertFromDwarfType(2, PointerType(8, IntType('int', 4, True)))
        self.assertFromDwarfType(3, PointerType(8, IntType('int', 4, True), {'const'}))
        self.assertFromDwarfType(4, PointerType(8, VoidType()))

        self.assertEqual(self.type_index.find('void *'), PointerType(8, VoidType()))
github osandov / drgn / tests / test_dwarftypeindex.py View on Github external
DieAttrib(DW_AT.byte_size, DW_FORM.data1, b'\x04'),
                DieAttrib(DW_AT.encoding, DW_FORM.data1, b'\x05'),
                DieAttrib(DW_AT.name, DW_FORM.string, b'int'),
            ]),
            # unsigned int
            Die(self.cu, DW_TAG.base_type, [
                DieAttrib(DW_AT.byte_size, DW_FORM.data1, b'\x04'),
                DieAttrib(DW_AT.encoding, DW_FORM.data1, b'\x07'),
                DieAttrib(DW_AT.name, DW_FORM.string, b'unsigned int'),
            ]),
            # enum color {
            #     RED,
            #     GREEN,
            #     BLUE,
            # };
            Die(self.cu, DW_TAG.enumeration_type, [
                DieAttrib(DW_AT.name, DW_FORM.string, b'color'),
                DieAttrib(DW_AT.type, DW_FORM.ref4, 1),
            ], lambda: [
                Die(self.cu, DW_TAG.enumerator, [
                    DieAttrib(DW_AT.name, DW_FORM.string, b'RED'),
                    DieAttrib(DW_AT.const_value, DW_FORM.data1, b'\x00'),
                ]),
                Die(self.cu, DW_TAG.enumerator, [
                    DieAttrib(DW_AT.name, DW_FORM.string, b'GREEN'),
                    DieAttrib(DW_AT.const_value, DW_FORM.data1, b'\x01'),
                ]),
                Die(self.cu, DW_TAG.enumerator, [
                    DieAttrib(DW_AT.name, DW_FORM.string, b'BLUE'),
                    DieAttrib(DW_AT.const_value, DW_FORM.data1, b'\x02'),
                ]),
            ]),
github osandov / drgn / tests / test_dwarftypeindex.py View on Github external
def test_bit_field(self):
        self.dies[:] = [
            # int
            Die(self.cu, DW_TAG.base_type, [
                DieAttrib(DW_AT.byte_size, DW_FORM.data1, b'\x04'),
                DieAttrib(DW_AT.encoding, DW_FORM.data1, b'\x05'),
                DieAttrib(DW_AT.name, DW_FORM.string, b'int'),
            ]),
            # const int
            Die(self.cu, DW_TAG.const_type, [
                DieAttrib(DW_AT.type, DW_FORM.ref4, 0),
            ]),
            # struct {
            #     int x : 4;
            #     const int y : 28;
            #     int z : 5;
            # };
            Die(self.cu, DW_TAG.structure_type, [
                DieAttrib(DW_AT.byte_size, DW_FORM.data1, b'\x08'),
            ], lambda: [
github osandov / drgn / tests / test_dwarftypeindex.py View on Github external
def test_array(self):
        self.dies[:] = [
            # int
            Die(self.cu, DW_TAG.base_type, [
                DieAttrib(DW_AT.byte_size, DW_FORM.data1, b'\x04'),
                DieAttrib(DW_AT.encoding, DW_FORM.data1, b'\x05'),
                DieAttrib(DW_AT.name, DW_FORM.string, b'int'),
            ]),
            # int [2]
            Die(self.cu, DW_TAG.array_type, [
                DieAttrib(DW_AT.type, DW_FORM.ref4, 0),
            ], lambda: [
                Die(self.cu, DW_TAG.subrange_type, [
                    DieAttrib(DW_AT.upper_bound, DW_FORM.data1, b'\x01'),
                ]),
            ]),
            # int [2][3]
            Die(self.cu, DW_TAG.array_type, [
                DieAttrib(DW_AT.type, DW_FORM.ref4, 0),
            ], lambda: [
                Die(self.cu, DW_TAG.subrange_type, [
                    DieAttrib(DW_AT.upper_bound, DW_FORM.data1, b'\x01'),
                ]),
                Die(self.cu, DW_TAG.subrange_type, [
                    DieAttrib(DW_AT.upper_bound, DW_FORM.data1, b'\x02'),
                ]),
github osandov / drgn / tests / test_dwarftypeindex.py View on Github external
def test_union(self):
        self.dies[:] = [
            # int
            Die(self.cu, DW_TAG.base_type, [
                DieAttrib(DW_AT.byte_size, DW_FORM.data1, b'\x04'),
                DieAttrib(DW_AT.encoding, DW_FORM.data1, b'\x05'),
                DieAttrib(DW_AT.name, DW_FORM.string, b'int'),
            ]),
            # float
            Die(None, DW_TAG.base_type, [
                DieAttrib(DW_AT.byte_size, DW_FORM.data1, b'\x04'),
                DieAttrib(DW_AT.encoding, DW_FORM.data1, b'\x04'),
                DieAttrib(DW_AT.name, DW_FORM.string, b'float'),
            ]),
            # union value {
            #    int i;
            #    float f;
            # };
            Die(self.cu, DW_TAG.union_type, [
                DieAttrib(DW_AT.name, DW_FORM.string, b'value'),
github osandov / drgn / tests / test_dwarftypeindex.py View on Github external
DieAttrib(DW_AT.name, DW_FORM.string, b'int'),
            ]),
            # const int
            Die(self.cu, DW_TAG.const_type, [
                DieAttrib(DW_AT.type, DW_FORM.ref4, 0),
            ]),
            # volatile int
            Die(self.cu, DW_TAG.volatile_type, [
                DieAttrib(DW_AT.type, DW_FORM.ref4, 0),
            ]),
            # volatile const int
            Die(self.cu, DW_TAG.volatile_type, [
                DieAttrib(DW_AT.type, DW_FORM.ref4, 1),
            ]),
            # _Atomic volatile const int
            Die(self.cu, DW_TAG.atomic_type, [
                DieAttrib(DW_AT.type, DW_FORM.ref4, 3),
            ]),
            # restrict int
            Die(self.cu, DW_TAG.restrict_type, [
                DieAttrib(DW_AT.type, DW_FORM.ref4, 0),
            ]),
            # const void
            Die(self.cu, DW_TAG.const_type, []),
        ]

        self.assertFromDwarfType(1, IntType('int', 4, True, {'const'}))
        self.assertFromDwarfType(2, IntType('int', 4, True, {'volatile'}))
        self.assertFromDwarfType(3, IntType('int', 4, True, {'const', 'volatile'}))
        self.assertFromDwarfType(4, IntType('int', 4, True, {'_Atomic', 'const', 'volatile'}))
        self.assertFromDwarfType(5, IntType('int', 4, True, {'restrict'}))
        self.assertFromDwarfType(6, VoidType({'const'}))
github osandov / drgn / tests / test_dwarftypeindex.py View on Github external
def test_pointer(self):
        self.dies[:] = [
            # int
            Die(self.cu, DW_TAG.base_type, [
                DieAttrib(DW_AT.byte_size, DW_FORM.data1, b'\x04'),
                DieAttrib(DW_AT.encoding, DW_FORM.data1, b'\x05'),
                DieAttrib(DW_AT.name, DW_FORM.string, b'int'),
            ]),
            # const int
            Die(self.cu, DW_TAG.const_type, [
                DieAttrib(DW_AT.type, DW_FORM.ref4, 0),
            ]),
            # int *
            Die(self.cu, DW_TAG.pointer_type, [
                DieAttrib(DW_AT.byte_size, DW_FORM.data1, b'\x08'),
                DieAttrib(DW_AT.type, DW_FORM.ref4, 0),
            ]),
            # int * const
            Die(self.cu, DW_TAG.const_type, [
                DieAttrib(DW_AT.type, DW_FORM.ref4, 2),