@staticmethod
def _attribute_has_loc_expr(attr, dwarf_version):
- return (dwarf_version < 4 and attr.form == 'DW_FORM_block1' or
- attr.form == 'DW_FORM_exprloc')
+ return ((dwarf_version < 4 and attr.form == 'DW_FORM_block1' and
+ not attr.name == 'DW_AT_const_value') or
+ attr.form == 'DW_FORM_exprloc')
@staticmethod
def _attribute_has_loc_list(attr, dwarf_version):
return ((dwarf_version < 4 and
- attr.form in ('DW_FORM_data4', 'DW_FORM_data8')) or
+ attr.form in ('DW_FORM_data4', 'DW_FORM_data8') and
+ not attr.name == 'DW_AT_const_value') or
attr.form == 'DW_FORM_sec_offset')
@staticmethod
'DW_AT_data_member_location',
'DW_AT_frame_base', 'DW_AT_segment',
'DW_AT_static_link', 'DW_AT_use_location',
- 'DW_AT_vtable_elem_location'))
+ 'DW_AT_vtable_elem_location',
+ 'DW_AT_GNU_call_site_value',
+ 'DW_AT_GNU_call_site_target',
+ 'DW_AT_GNU_call_site_data_value'))
--- /dev/null
+#------------------------------------------------------------------------------
+# elftools tests
+#
+# Seva Alekseyev (sevaa@sprynet.com)
+# This code is in the public domain
+#------------------------------------------------------------------------------
+
+import unittest
+import os, sys, io
+
+sys.path.insert(1, os.getcwd())
+
+from elftools.elf.elffile import ELFFile
+from elftools.dwarf.dwarfinfo import DWARFInfo, DebugSectionDescriptor, DwarfConfig
+from elftools.dwarf.locationlists import LocationParser
+
+class TestConstWithData4IsntLocation(unittest.TestCase):
+ def _test_file(self, filename):
+ filepath = os.path.join('test', 'testfiles_for_unittests', filename)
+ print('Reading %s...' % (filename))
+ with open(filepath, 'rb') as f:
+ elffile = ELFFile(f)
+ dwarfinfo = elffile.get_dwarf_info()
+ locparser = LocationParser(dwarfinfo.location_lists())
+ for CU in dwarfinfo.iter_CUs():
+ print("Compile unit %s..." % CU.get_top_DIE().attributes['DW_AT_name'].value.decode('utf-8'))
+ ver = CU['version']
+ for DIE in CU.iter_DIEs():
+ for key in DIE.attributes:
+ attr = DIE.attributes[key]
+ if LocationParser.attribute_has_location(attr, ver):
+ # This will crash on unpatched library on DIE at 0x9f
+ locparser.parse_from_attribute(attr, ver)
+
+ def test_main(self):
+ self._test_file('pascalenum.o')
+
+if __name__ == '__main__':
+ unittest.main()
--- /dev/null
+#------------------------------------------------------------------------------
+# elftools tests
+#
+# Seva Alekseyev (sevaa@sprynet.com)
+# This code is in the public domain
+#------------------------------------------------------------------------------
+
+import unittest
+import os, sys, io
+
+# sys.path.insert(1, os.getcwd())
+
+from elftools.elf.elffile import ELFFile
+from elftools.dwarf.dwarfinfo import DWARFInfo, DebugSectionDescriptor, DwarfConfig
+from elftools.dwarf.locationlists import LocationParser
+
+class TestGNUCallAttributesHaveLocation(unittest.TestCase):
+ def _test_file(self, filename):
+ filepath = os.path.join('test', 'testfiles_for_unittests', filename)
+ print('Reading %s...' % (filename))
+ with open(filepath, 'rb') as f:
+ elffile = ELFFile(f)
+ dwarfinfo = elffile.get_dwarf_info()
+ for CU in dwarfinfo.iter_CUs():
+ ver = CU['version']
+ print("Compile unit %s..." % CU.get_top_DIE().attributes['DW_AT_name'].value.decode('utf-8'))
+
+ for DIE in CU.iter_DIEs():
+ for key in DIE.attributes:
+ attr = DIE.attributes[key]
+ if attr.form == 'DW_FORM_exprloc':
+ self.assertTrue(LocationParser.attribute_has_location(attr, CU['version']), "Attribute %s not recognized as a location" % key)
+
+
+ def test_main(self):
+ self._test_file('dwarf_gnuops1.o')
+
+if __name__ == '__main__':
+ unittest.main()
\ No newline at end of file