How to use the drgn.internal.dwarf.DieAttrib 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
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'),
                ]),
            ]),
            # enum {
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'),
            ]),
            # 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
], 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
], lambda: [
                Die(self.cu, DW_TAG.member, [
                    DieAttrib(DW_AT.name, DW_FORM.string, b'n'),
                    DieAttrib(DW_AT.type, DW_FORM.ref4, 0),
                    DieAttrib(DW_AT.data_member_location, DW_FORM.data1, b'\x00'),
                ]),
                Die(self.cu, DW_TAG.member, [
                    DieAttrib(DW_AT.name, DW_FORM.string, b'foo'),
                    # Note that this is the ambiguous int [] or int [0] DIE.
                    DieAttrib(DW_AT.type, DW_FORM.ref4, 1),
                    DieAttrib(DW_AT.data_member_location, DW_FORM.data1, b'\x00'),
                ]),
github osandov / drgn / tests / test_dwarftypeindex.py View on Github external
def test_float(self):
        self.dies[:] = [
            # 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'),
            ]),
            # 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'),
            ]),
        ]
github osandov / drgn / tests / test_dwarftypeindex.py View on Github external
def test_short(self):
        self.dies[:] = [
            # short
            Die(self.cu, DW_TAG.base_type, [
                DieAttrib(DW_AT.byte_size, DW_FORM.data1, b'\x02'),
                DieAttrib(DW_AT.encoding, DW_FORM.data1, b'\x05'),
                DieAttrib(DW_AT.name, DW_FORM.string, b'short'),
            ]),
            # signed short
            Die(self.cu, DW_TAG.base_type, [
                DieAttrib(DW_AT.byte_size, DW_FORM.data1, b'\x02'),
                DieAttrib(DW_AT.encoding, DW_FORM.data1, b'\x05'),
                DieAttrib(DW_AT.name, DW_FORM.string, b'signed short'),
            ]),
            # unsigned short
            Die(self.cu, DW_TAG.base_type, [
                DieAttrib(DW_AT.byte_size, DW_FORM.data1, b'\x02'),
                DieAttrib(DW_AT.encoding, DW_FORM.data1, b'\x07'),
                DieAttrib(DW_AT.name, DW_FORM.string, b'unsigned short'),
            ]),
        ]

        self.assertFromDwarfType(0, IntType('short', 2, True))
github osandov / drgn / tests / test_dwarftypeindex.py View on Github external
], lambda: [
                Die(self.cu, DW_TAG.member, [
                    DieAttrib(DW_AT.name, DW_FORM.string, b'a'),
                    DieAttrib(DW_AT.type, DW_FORM.ref4, 1),
                    DieAttrib(DW_AT.data_member_location, DW_FORM.data1, b'\x00'),
                ]),
                Die(self.cu, DW_TAG.member, [
                    DieAttrib(DW_AT.name, DW_FORM.string, b'b'),
                    DieAttrib(DW_AT.type, DW_FORM.ref4, 1),
                    DieAttrib(DW_AT.data_member_location, DW_FORM.data1, b'\x08'),
                ]),
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'),
                ]),
                Die(self.cu, DW_TAG.member, [
                    DieAttrib(DW_AT.name, DW_FORM.string, b'y'),
                    DieAttrib(DW_AT.type, DW_FORM.ref4, 0),
                    DieAttrib(DW_AT.data_member_location, DW_FORM.data1, b'\x04'),
                ]),
            ]),
            # struct line_segment {
            #     struct point a, b;
            # };
github osandov / drgn / tests / test_dwarftypeindex.py View on Github external
], lambda: [
                Die(self.cu, DW_TAG.member, [
                    DieAttrib(DW_AT.name, DW_FORM.string, b'n'),
                    DieAttrib(DW_AT.type, DW_FORM.ref4, 0),
                    DieAttrib(DW_AT.data_member_location, DW_FORM.data1, b'\x00'),
                ]),
                Die(self.cu, DW_TAG.member, [
                    DieAttrib(DW_AT.name, DW_FORM.string, b'foo'),
                    # Note that this is the ambiguous int [] or int [0] DIE.
                    DieAttrib(DW_AT.type, DW_FORM.ref4, 1),
                    DieAttrib(DW_AT.data_member_location, DW_FORM.data1, b'\x04'),
                ]),
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'),
            ]),
            # 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'),
                ]),
                Die(self.cu, DW_TAG.member, [
                    DieAttrib(DW_AT.name, DW_FORM.string, b'f'),
                    DieAttrib(DW_AT.type, DW_FORM.ref4, 1),
                    DieAttrib(DW_AT.data_member_location, DW_FORM.data1, b'\x00'),
                ]),
            ]),
            # union foo;
            Die(self.cu, DW_TAG.union_type, [
                DieAttrib(DW_AT.name, DW_FORM.string, b'foo'),