Reporting the real attribute form for DW_FORM_indirect (#475)
[pyelftools.git] / test / test_dwarf_formindirect.py
1 #-------------------------------------------------------------------------------
2 # elftools tests
3 #
4 # Seva Alekseyev (sevaa@sprynet.com)
5 # This code is in the public domain
6 #-------------------------------------------------------------------------------
7 import unittest
8 import os
9
10 from elftools.elf.elffile import ELFFile
11
12 class TestFormIndirect(unittest.TestCase):
13 def test_formindirect(self):
14 path = os.path.join('test', 'testfiles_for_unittests',
15 'gmtime_r.o.elf')
16 with open(path, 'rb') as f:
17 elffile = ELFFile(f)
18 dwarfinfo = elffile.get_dwarf_info(follow_links=False)
19 cu = next(dwarfinfo.iter_CUs())
20 # That DIE in that binary has an attribute with form DW_FORM_indirect
21 die = next(die for die in cu.iter_DIEs() if die.tag == 'DW_TAG_pointer_type')
22 attr = die.attributes["DW_AT_type"]
23 self.assertEqual(attr.form, "DW_FORM_ref2") # That's the real form
24 self.assertEqual(attr.indirection_length, 1) # But the fact of indirection is captured
25
26 if __name__ == '__main__':
27 unittest.main()