From 76a7c996474268ce475ff58b847332052a2f51a2 Mon Sep 17 00:00:00 2001 From: Seva Alekseyev Date: Tue, 16 Aug 2022 09:40:14 -0400 Subject: [PATCH] Support for DW_FORM_data16, unit test (#437) Fixes #436 --- elftools/dwarf/structs.py | 1 + test/test_dwarf_formdata16.py | 34 ++++++++++++++++++ .../dwarf_lineprog_data16.elf | Bin 0 -> 6200 bytes 3 files changed, 35 insertions(+) create mode 100644 test/test_dwarf_formdata16.py create mode 100644 test/testfiles_for_unittests/dwarf_lineprog_data16.elf 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 0000000000000000000000000000000000000000..16d4d38455b59d4d1538872e346f84e83ffb4f68 GIT binary patch literal 6200 zcmbtYYit}>6}~fDCr;zX=Fz;2$g0h%F4SYM>x4XNSjTp~R^8wxZ50S*81Ig~1G_uc z?l{_10xY?&s6;X#AtNE0Kb0bcgnv|!e^^Q=0R>S6LP-3epjJvG3Pma}Me1_S%=uR1 z+g%ZKZ6rl=v+fi;L7I72q+Zt_6F+G5kTvt#Nx&Td(%xlh4|-kNgGN42zY`QV zFaNKfi$ahvYF2pPgg~7k1uH=wA~>0oG^)L%m-!n>(#!epqbr2`&~nuPKMd;Oc=p;Vh{DHezO&G~12Ack|1al9LO ztzjb}ewKfn9dI3Ly(+zaofDX4PHrYJpp|=c`WHwY|!`PiVgG z*z;b+DS6MiWER|3ZXBCm*by}~GktR09=3+9!_D#|BVl(izc8-XWgS|Rc>w$^!Ix!T z0f#;NQ1o=jQDiA~HipN?$CqMwm|7-2d!RS*^`6ejp5#~$a?dbxzd+Xw@(afx`Mqe4cW)V^ z4zYtKnRllz{^pChi+{{JV13zhu-M; z4?T~OTNz#B`5Wva*1!MOXyh&(zC{(cR|vc|zdE}-x-TS*ywTB11t$0*p)2>w=-0^e zmPek1Iw9IkVb&?k+1qmjpS|{U?&3SoUb}fSxAND{+$$Yva>~815txlPb1T<7uMv^( zute@8jl;(&W+VM5-Fpvasl;}Xt8Ty5AW09i%~SFAo1y&)woSG-$Y#g5upTWFrD{_0mb8vWmN_la=sCwN^KLpPxOB!UPA1>qGx3=a>rP5k!p_Vmu1{y9HC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