1 # The dwarf_v5_forms.debug file was generated as follows, using gcc 11.2.0 on
3 # $ cat dwarf_v5_forms.c
9 # $ gcc -O0 -gdwarf-5 dwarf_v5_forms.c -o dwarf_v5_forms.debug
10 # $ strip --only-keep-debug dwarf_v5_forms.debug
15 from elftools
.elf
.elffile
import ELFFile
17 class TestDWARFV5_forms(unittest
.TestCase
):
19 def test_DW_FORM_implicit_const(self
):
20 path
= os
.path
.join('test', 'testfiles_for_unittests',
21 'dwarf_v5_forms.debug')
22 with
open(path
, 'rb') as f
:
24 dwarfinfo
= elffile
.get_dwarf_info()
25 # File is very small, so load all DIEs.
27 for cu
in dwarfinfo
.iter_CUs():
28 dies
.extend(cu
.iter_DIEs())
29 # Locate the "var" DIE.
31 # There should be only one
32 if (die
.tag
== "DW_TAG_variable" and
33 die
.attributes
["DW_AT_name"].value
== b
'val'):
34 # In the dwarfinfo, it's type is sized using a
35 # DW_FORM_implicit_const: check it is parsed correctly
37 dietype
= cu
.get_DIE_from_refaddr(die
.attributes
["DW_AT_type"].value
)
38 byte_size_attr
= dietype
.attributes
["DW_AT_byte_size"]
39 self
.assertEqual(byte_size_attr
.form
, "DW_FORM_implicit_const")
40 self
.assertEqual(byte_size_attr
.value
, 8)
42 def test_DW_FORM_linestrp(self
):
43 path
= os
.path
.join('test', 'testfiles_for_unittests',
44 'dwarf_v5_forms.debug')
45 with
open(path
, 'rb') as f
:
47 dwarfinfo
= elffile
.get_dwarf_info()
48 cu
= next(dwarfinfo
.iter_CUs())
49 top_die
= cu
.get_top_DIE()
50 name_attr
= top_die
.attributes
["DW_AT_name"]
51 self
.assertEqual(name_attr
.form
, "DW_FORM_line_strp")
52 self
.assertEqual(name_attr
.value
, b
"dwarf_v5_forms.c")