1 # The test_gnudebugaltlink* and test_debugsup* files have been generated as
4 # int main(int argc, char** argv)
9 # $ gcc test_sup.c -o test_debugsup1
10 # $ gcc test_sup.c -o test_debugsup2
11 # $ dwz test_debugsup1 test_debugsup2 -m test_debugsup.common --dwarf-5
13 # $ gcc test_sup.c -o test_gnudebugaltlink1
14 # $ gcc test_sup.c -o test_gnudebugaltlink2
15 # $ dwz test_gnudebugaltlink1 test_gnudebugaltlink2 -m test_gnudebugaltlink.common
20 from elftools
.elf
.elffile
import ELFFile
22 class TestDWARFSupplementaryObjects(unittest
.TestCase
):
24 def test_gnudebugaltlink_no_followlinks(self
):
25 path
= os
.path
.join('test', 'testfiles_for_unittests',
26 'test_gnudebugaltlink1')
27 with
open(path
, 'rb') as f
:
29 # Check that we don't have a supplementary_dwarfinfo
30 dwarfinfo
= elffile
.get_dwarf_info(follow_links
=False)
31 self
.assertIsNone(dwarfinfo
.supplementary_dwarfinfo
)
32 # Check that imported units are present
33 self
.assertTrue(any(die
.tag
== 'DW_TAG_imported_unit'
34 for cu
in dwarfinfo
.iter_CUs()
35 for die
in cu
.iter_DIEs()))
36 # Check that DW_FORM_GNU_strp_alt keep their raw_value.
37 for cu
in dwarfinfo
.iter_CUs():
38 for die
in cu
.iter_DIEs():
39 attrs
= die
.attributes
40 if ('DW_AT_name' in attrs
and
41 attrs
['DW_AT_name'].form
== 'DW_FORM_GNU_strp_alt'):
42 self
.assertEqual(attrs
['DW_AT_name'].value
,
43 attrs
['DW_AT_name'].raw_value
)
45 def test_gnudebugaltlink_followlinks(self
):
46 base_dir
= os
.path
.join(b
'test', b
'testfiles_for_unittests')
47 path
= os
.path
.join(base_dir
, b
'test_gnudebugaltlink1')
48 with ELFFile
.load_from_path(path
) as elffile
:
49 # Check that we do have a supplementary_dwarfinfo
50 dwarfinfo
= elffile
.get_dwarf_info()
51 self
.assertIsNotNone(dwarfinfo
.supplementary_dwarfinfo
)
52 # Check that imported units are replaced by what they refer to.
53 self
.assertTrue(all(die
.tag
!= 'DW_TAG_imported_unit'
54 for cu
in dwarfinfo
.iter_CUs()
55 for die
in cu
.iter_DIEs()))
56 # Check that DW_FORM_GNU_strp_alt get a proper reference
57 for cu
in dwarfinfo
.iter_CUs():
58 for die
in cu
.iter_DIEs():
59 attrs
= die
.attributes
60 if ('DW_AT_name' in attrs
and attrs
['DW_AT_name'].form
==
61 'DW_FORM_GNU_strp_alt'):
62 self
.assertIsInstance(attrs
['DW_AT_name'].value
, bytes
)
64 def test_debugsup_no_followlinks(self
):
65 path
= os
.path
.join('test', 'testfiles_for_unittests',
67 with ELFFile
.load_from_path(path
) as elffile
:
68 # Check that we don't have a supplementary_dwarfinfo
69 dwarfinfo
= elffile
.get_dwarf_info(follow_links
=False)
70 self
.assertIsNone(dwarfinfo
.supplementary_dwarfinfo
)
71 # Check that imported units are present
72 self
.assertTrue(any(die
.tag
== 'DW_TAG_imported_unit'
73 for cu
in dwarfinfo
.iter_CUs()
74 for die
in cu
.iter_DIEs()))
75 # Check that DW_FORM_GNU_strp_alt keep their raw_value.
76 for cu
in dwarfinfo
.iter_CUs():
77 for die
in cu
.iter_DIEs():
78 attrs
= die
.attributes
79 if ('DW_AT_name' in attrs
and
80 attrs
['DW_AT_name'].form
== 'DW_FORM_strp_sup'):
81 self
.assertEqual(attrs
['DW_AT_name'].value
,
82 attrs
['DW_AT_name'].raw_value
)
84 def test_debugsup_followlinks(self
):
85 base_dir
= os
.path
.join(b
'test', b
'testfiles_for_unittests')
86 path
= os
.path
.join(base_dir
, b
'test_debugsup1')
87 with ELFFile
.load_from_path(path
) as elffile
:
88 # Check that we do have a supplementary_dwarfinfo
89 dwarfinfo
= elffile
.get_dwarf_info()
90 self
.assertIsNotNone(dwarfinfo
.supplementary_dwarfinfo
)
91 # Check that imported units are replaced by what they refer to.
92 self
.assertTrue(all(die
.tag
!= 'DW_TAG_imported_unit'
93 for cu
in dwarfinfo
.iter_CUs()
94 for die
in cu
.iter_DIEs()))
95 # Check that DW_FORM_GNU_strp_alt get a proper reference
96 for cu
in dwarfinfo
.iter_CUs():
97 for die
in cu
.iter_DIEs():
98 attrs
= die
.attributes
99 if ('DW_AT_name' in attrs
and attrs
['DW_AT_name'].form
==
101 self
.assertIsInstance(attrs
['DW_AT_name'].value
, bytes
)