From: Seva Alekseyev Date: Tue, 16 Aug 2022 13:40:14 +0000 (-0400) Subject: Support for DW_FORM_data16, unit test (#437) X-Git-Tag: v0.30~24^2 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=76a7c996474268ce475ff58b847332052a2f51a2;p=pyelftools.git Support for DW_FORM_data16, unit test (#437) Fixes #436 --- diff --git a/elftools/dwarf/structs.py b/elftools/dwarf/structs.py index 1a5ae45..a74d5de 100644 --- a/elftools/dwarf/structs.py +++ b/elftools/dwarf/structs.py @@ -225,6 +225,7 @@ class DWARFStructs(object): DW_FORM_data2=self.Dwarf_uint16(''), DW_FORM_data4=self.Dwarf_uint32(''), DW_FORM_data8=self.Dwarf_uint64(''), + DW_FORM_data16=Array(16, self.Dwarf_uint8('')), # Used for hashes and such, not for integers DW_FORM_sdata=self.Dwarf_sleb128(''), DW_FORM_udata=self.Dwarf_uleb128(''), diff --git a/test/test_dwarf_formdata16.py b/test/test_dwarf_formdata16.py new file mode 100644 index 0000000..898ca9b --- /dev/null +++ b/test/test_dwarf_formdata16.py @@ -0,0 +1,34 @@ +#------------------------------------------------------------------------------- +# elftools tests +# +# Seva Alekseyev (sevaa@sprynet.com) +# This code is in the public domain +#------------------------------------------------------------------------------- +import unittest +import os + +from elftools.elf.elffile import ELFFile + +class TestFormData16(unittest.TestCase): + def test_formdata16(self): + path = os.path.join('test', 'testfiles_for_unittests', + 'dwarf_lineprog_data16.elf') + with open(path, 'rb') as f: + elffile = ELFFile(f) + dwarfinfo = elffile.get_dwarf_info(follow_links=False) + cu = next(dwarfinfo.iter_CUs()) + # Without DW_FORM_data16, the following line errors out: + lp = dwarfinfo.line_program_for_CU(cu) + # Make sure the hashes come out right + self.assertEqual(lp.header.version, 5) + # The following interrogates the DWARFv5 specific header structures + self.assertEqual(lp.header.file_name_entry_format[2].content_type, 'DW_LNCT_MD5') + # The correct hash value was taken from llvm-dwarfdump output + hash = lp.header.file_names[0]['DW_LNCT_MD5'] + hash = ''.join("%02x" % b for b in hash) + self.assertEqual(hash, '00dbc7f4edc56417c80f1aa512c4c051') + + + +if __name__ == '__main__': + unittest.main() diff --git a/test/testfiles_for_unittests/dwarf_lineprog_data16.elf b/test/testfiles_for_unittests/dwarf_lineprog_data16.elf new file mode 100644 index 0000000..16d4d38 Binary files /dev/null and b/test/testfiles_for_unittests/dwarf_lineprog_data16.elf differ