Fix for mixed version loclists, tests (#521)
[pyelftools.git] / test / test_dwarf_constisntloc.py
1 #------------------------------------------------------------------------------
2 # elftools tests
3 #
4 # Seva Alekseyev (sevaa@sprynet.com)
5 # This code is in the public domain
6 #------------------------------------------------------------------------------
7
8 import unittest
9 import os, sys, io
10
11 sys.path.insert(1, os.getcwd())
12
13 from elftools.elf.elffile import ELFFile
14 from elftools.dwarf.dwarfinfo import DWARFInfo, DebugSectionDescriptor, DwarfConfig
15 from elftools.dwarf.locationlists import LocationParser
16
17 class TestConstWithData4IsntLocation(unittest.TestCase):
18 def _test_file(self, filename):
19 filepath = os.path.join('test', 'testfiles_for_unittests', filename)
20 with open(filepath, 'rb') as f:
21 elffile = ELFFile(f)
22 dwarfinfo = elffile.get_dwarf_info()
23 locparser = LocationParser(dwarfinfo.location_lists())
24 for CU in dwarfinfo.iter_CUs():
25 ver = CU['version']
26 for DIE in CU.iter_DIEs():
27 for key in DIE.attributes:
28 attr = DIE.attributes[key]
29 if LocationParser.attribute_has_location(attr, ver):
30 # This will crash on unpatched library on DIE at 0x9f
31 locparser.parse_from_attribute(attr, ver)
32
33 def test_main(self):
34 self._test_file('pascalenum.o')
35
36 if __name__ == '__main__':
37 unittest.main()