From: William Woodruff Date: Fri, 18 Oct 2019 16:17:27 +0000 (-0400) Subject: dwarf/die: Handle DW_FORM_flag_present in value translation (#246) X-Git-Tag: v0.26~5 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=1d1a49883a50a06634af0b304236f09eeea56711;p=pyelftools.git 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 --- 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 0000000..d232a05 Binary files /dev/null and b/test/testfiles_for_unittests/lambda.elf differ