From 1d1a49883a50a06634af0b304236f09eeea56711 Mon Sep 17 00:00:00 2001 From: William Woodruff Date: Fri, 18 Oct 2019 12:17:27 -0400 Subject: [PATCH] dwarf/die: Handle DW_FORM_flag_present in value translation (#246) * dwarf/die: Handle DW_FORM_flag_present in value translation When an attribute has form DW_FORM_flag_present it is implicitly indicated as present, with no actual value. Ref. DWARFv4, section 7. * test: Add DW_FORM_flag_present value test * test: Fix iteration * test: Remove old assert --- elftools/dwarf/die.py | 2 ++ test/test_dwarf_attr_form_flag_present.py | 25 ++++++++++++++++++++++ test/testfiles_for_unittests/lambda.elf | Bin 0 -> 23456 bytes 3 files changed, 27 insertions(+) create mode 100644 test/test_dwarf_attr_form_flag_present.py create mode 100755 test/testfiles_for_unittests/lambda.elf diff --git a/elftools/dwarf/die.py b/elftools/dwarf/die.py index 5d3ad99..ec50fb1 100755 --- a/elftools/dwarf/die.py +++ b/elftools/dwarf/die.py @@ -199,6 +199,8 @@ class DIE(object): value = self.dwarfinfo.get_string_from_table(raw_value) elif form == 'DW_FORM_flag': value = not raw_value == 0 + elif form == 'DW_FORM_flag_present': + value = True elif form == 'DW_FORM_indirect': try: form = DW_FORM_raw2name[raw_value] diff --git a/test/test_dwarf_attr_form_flag_present.py b/test/test_dwarf_attr_form_flag_present.py new file mode 100644 index 0000000..9ec9ce5 --- /dev/null +++ b/test/test_dwarf_attr_form_flag_present.py @@ -0,0 +1,25 @@ +#------------------------------------------------------------------------------- +# elftools tests +# +# Eli Bendersky (eliben@gmail.com), Santhosh Kumar Mani (santhoshmani@gmail.com) +# This code is in the public domain +#------------------------------------------------------------------------------- +import os +import unittest + +from elftools.elf.elffile import ELFFile + + +class TestAttrFormFlagPresent(unittest.TestCase): + def test_form_flag_present_value_is_true(self): + with open(os.path.join('test', 'testfiles_for_unittests', + 'lambda.elf'), 'rb') as f: + elffile = ELFFile(f) + self.assertTrue(elffile.has_dwarf_info()) + + dwarf = elffile.get_dwarf_info() + for cu in dwarf.iter_CUs(): + for die in cu.iter_DIEs(): + for _, attr in die.attributes.items(): + if attr.form == "DW_FORM_flag_present": + self.assertTrue(attr.value) diff --git a/test/testfiles_for_unittests/lambda.elf b/test/testfiles_for_unittests/lambda.elf new file mode 100755 index 0000000000000000000000000000000000000000..d232a0510ee7c70959cd29d9d846f1d490fd7df7 GIT binary patch literal 23456 zcmeHvdwiTlz5eWOF1y_}NiTsWOX-&0Qn0zSCA~mP(l%`Z>AmHqWxLtzCV|av$Zjr0 zDV2K!wA=+nsv@EXwJ0EnK)GlEMUkU|2js^=)K>7E3MzMcp65F=@4nfjpTjxF^ZV<( zZQf_*neX>I_jzY#=Y20|YF*{^c$B@oYMG)hT-+d(zALqRqj(LsNCi}bnxUqvA}|H` zYmgA4c3FJen6~IQay}sS7I`(X$lD+ei$`f%S+pr67Md^(4aTQ&FsQv2krN@P$Fx2_ zPQ1Wv;;?wRNyly`Os=rpNmK8j(K~4LEGnaC(dLhNskld2q2me=~< zXWQxC8xSwBK^zu0Yg$>fdK;j}bbi#U%m{8Y@g1&Qs!aMVvK)EUB)i(`7t|!%=O(*S zeS>oc7uC`TauiZj%#bUKZML*rlqOBLD$`qTS$+nvG`LQeJH2tcT zvZG#*oiIwko8U&{FF6dq?lAnq!|?kK!xtVVJuHVX{_?K}L5x>Ns%>T4B&ZDfyr$xh z>EBb-fV=BLd1tcivEz#EwRm!rcK93 zVzBmK*IIvy)>{xu_hltL>13v#A1;QeRbqxHjA;rXe64A4|Zi$Z#318 zOf%GEx;xsHQmb2AmajPd^vL|`1=<~%S3R%#c$S+N|9s{jTN~YMZ~VvBrt2j;=Nfcb zpE}Z%KSK|gaDeKo>_U_Ds_7>DVCgo}GA0y@OW)ph@pcSgh^=3aS+;GHpKR)#HjHV~ zD(vFj{iVvqJ3|!YYhAn@3utGNi+7Kg4KCh2UNpP-F*IPV=8InUH(ycsbRevnFWH;* z9(tzvqR0J@*i*m^^oz5a zhhAyE=+%SkH@EEDyBi~N^S(!F1@@Ksk>~Q;{bBW2k$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