1 #-------------------------------------------------------------------------------
4 # Eli Bendersky (eliben@gmail.com)
5 # This code is in the public domain
6 #-------------------------------------------------------------------------------
10 from elftools
.elf
.elffile
import ELFFile
11 from elftools
.elf
.sections
import StabSection
14 class TestStab(unittest
.TestCase
):
17 ("obj_stabs.S", 0, 0, 0x2, 33), # generated by compiler
18 ("label", 0x95, 0xc8, 0x4072, 0xdeadbeef),
19 ("another label", 0x41, 0x66, 0xf9b1, 0xcafebabe)]
20 with
open(os
.path
.join('test', 'testfiles_for_unittests',
21 'obj_stabs.elf'), 'rb') as f
:
25 for s
in elf
.iter_sections():
27 self
.assertIsInstance(s
, StabSection
)
29 # check section contents
30 stab
= elf
.get_section_by_name('.stab')
31 stabstr
= elf
.get_section_by_name('.stabstr')
32 for entry
, golden
in zip(stab
.iter_stabs(), expected
):
33 self
.assertEqual(stabstr
.get_string(entry
.n_strx
), golden
[0])
34 self
.assertEqual(entry
.n_type
, golden
[1])
35 self
.assertEqual(entry
.n_other
, golden
[2])
36 self
.assertEqual(entry
.n_desc
, golden
[3])
37 self
.assertEqual(entry
.n_value
, golden
[4])
40 if __name__
== '__main__':