From 5db298d75abbd76d1f3bd0101660af6d8960fa6e Mon Sep 17 00:00:00 2001 From: Seth LaForge Date: Wed, 2 Dec 2015 20:43:36 -0800 Subject: [PATCH] Improved DWARFv4 support. Handle DW_AT_data_member_location attributes with type DW_FORM_data*, which store a simple integer offset rather than dwarf expression. This seems to come up with struct members, at least on ARM. Handle DW_AT_location attributes with type DW_FORM_sec_offset as not having dwarf expressions, as allowed by the DWARFv4 standard. This seems to come up with some local variables, at least on ARM. Test DW_FORM_sec_offset support in location lists and DW_AT_data_member_location formatting support. Test code, compiled with gcc (Ubuntu 4.8.4-2ubuntu1~14.04) 4.8.4 on x86-64: struct Foo { char bim : 8; char bar : 3; char baz : 5; }; int get_bar(struct Foo foo) { return foo.bar; } int f1(int a, char b) { return a+b; } --- elftools/dwarf/descriptions.py | 17 ++++++++++++++--- .../improved-dwarfv4.o.elf | Bin 0 -> 3568 bytes 2 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 test/testfiles_for_readelf/improved-dwarfv4.o.elf diff --git a/elftools/dwarf/descriptions.py b/elftools/dwarf/descriptions.py index abe9252..a894ceb 100644 --- a/elftools/dwarf/descriptions.py +++ b/elftools/dwarf/descriptions.py @@ -420,13 +420,24 @@ _DWARF_EXPR_DUMPER_CACHE = {} def _location_list_extra(attr, die, section_offset): # According to section 2.6 of the DWARF spec v3, class loclistptr means # a location list, and class block means a location expression. - # - if attr.form in ('DW_FORM_data4', 'DW_FORM_data8'): + # DW_FORM_sec_offset is new in DWARFv4 as a section offset. + if attr.form in ('DW_FORM_data4', 'DW_FORM_data8', 'DW_FORM_sec_offset'): return '(location list)' else: return describe_DWARF_expr(attr.value, die.cu.structs) +def _data_member_location_extra(attr, die, section_offset): + # According to section 5.5.6 of the DWARF spec v4, a data member location + # can be an integer offset, or a location description. + # + if attr.form in ('DW_FORM_data1', 'DW_FORM_data2', + 'DW_FORM_data4', 'DW_FORM_data8'): + return '' # No extra description needed + else: + return describe_DWARF_expr(attr.value, die.cu.structs) + + def _import_extra(attr, die, section_offset): # For DW_AT_import the value points to a DIE (that can be either in the # current DIE's CU or in another CU, depending on the FORM). The extra @@ -479,7 +490,7 @@ _EXTRA_INFO_DESCRIPTION_MAP = defaultdict( DW_AT_location=_location_list_extra, DW_AT_string_length=_location_list_extra, DW_AT_return_addr=_location_list_extra, - DW_AT_data_member_location=_location_list_extra, + DW_AT_data_member_location=_data_member_location_extra, DW_AT_vtable_elem_location=_location_list_extra, DW_AT_segment=_location_list_extra, DW_AT_static_link=_location_list_extra, diff --git a/test/testfiles_for_readelf/improved-dwarfv4.o.elf b/test/testfiles_for_readelf/improved-dwarfv4.o.elf new file mode 100644 index 0000000000000000000000000000000000000000..f8fda6620c62281604d2bf617a5014fd059ae480 GIT binary patch literal 3568 zcmbtWO>7%g5T3Vd$4=I9{wQ@6ek^`d!0S4SqNvc4pOUsvQAA^eRH3kT)<4wtM)o=+ zIRI)Tq=1k>LZSx{7Y=ZM3rD1?Rk?EH!Ub+{s45{YMMWwzZ{IlU=RLtlyKm-u^Ub_@ zKfCYU7tXI4LI8_^Q*dZ83NRZ#)R&~X1V>;J4({CeEnc~CXLRh^^_#_uXZLR<5AH6F zUAuj7`ww#a==6hdcK^rZr8jO`7&j)VNtt0F&C{|oco}P+2RN`Qnr5lq1YwXWl4Lq< z5T-QExIl9cL`<4-9D7U*Q3yF+k@$jiC8MeppA$M%!3-jiLsb+Z5sTMbJ|rsz5UDWf zp&sdP)P|i<_izaf%1bg5GyvpgiK5ZL_qwr-R;n@w!lIy~@)c0Tgm^qXWtr)j^n{p9 zj2{Isri7WatP|F=mYBjqN5M>zac;`8My-^!XyFV#29|XSX;`8yo}V_;4zt;@LTIX0#^y(S`I^^s^Bvc(H5>V@UAIy3J+ILL zIJ3HXB0F0wbz6QnNST}KN~`crVctGIe=I<;g!_V;KM){C3dRSZlit$M)SFAM8!X zcfc-nI$%q5(=BzY8}(Mj!#=4yrBd77W(&*j^K{xytLpZ%8}*jU{+JT%ve#_7c&<6RsW(QQ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