2 Test that elftools does not fail to load debug symbol ELF files
7 from elftools
.elf
.elffile
import ELFFile
, DynamicSection
8 from elftools
.dwarf
.callframe
import ZERO
10 class TestDBGFile(unittest
.TestCase
):
11 def test_dynamic_segment(self
):
12 """ Test that the degenerate case for the dynamic segment does not crash
14 with
open(os
.path
.join('test', 'testfiles_for_unittests',
15 'debug_info.elf'), 'rb') as f
:
18 seen_dynamic_segment
= False
19 for segment
in elf
.iter_segments():
20 if segment
.header
.p_type
== 'PT_DYNAMIC':
21 self
.assertEqual(segment
.num_tags(), 0, "The dynamic segment in this file should be empty")
22 seen_dynamic_segment
= True
25 self
.assertTrue(seen_dynamic_segment
, "There should be a dynamic segment in this file")
27 def test_dynamic_section(self
):
28 """ Test that the degenerate case for the dynamic section does not crash
30 with
open(os
.path
.join('test', 'testfiles_for_unittests',
31 'debug_info.elf'), 'rb') as f
:
33 section
= DynamicSection(elf
.get_section_by_name('.dynamic').header
, '.dynamic', elf
)
35 self
.assertEqual(section
.num_tags(), 0, "The dynamic section in this file should be empty")
37 def test_eh_frame(self
):
38 """ Test that parsing .eh_frame with SHT_NOBITS does not crash
40 with
open(os
.path
.join('test', 'testfiles_for_unittests',
41 'debug_info.elf'), 'rb') as f
:
43 dwarf
= elf
.get_dwarf_info()
44 eh_frame
= list(dwarf
.EH_CFI_entries())
45 self
.assertEqual(len(eh_frame
), 1, "There should only be the ZERO entry in eh_frame")
46 self
.assertIs(type(eh_frame
[0]), ZERO
, "The only eh_frame entry should be the terminator")
48 if __name__
== '__main__':