From: Eli Bendersky Date: Wed, 2 Mar 2016 12:15:33 +0000 (-0800) Subject: Fix descriptions._data_member_location_extra to handle DW_FORM_sdata X-Git-Tag: v0.24~10 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=09e84e0520d3eb9d9ff5726ec7dc869e27ea9c54;p=pyelftools.git Fix descriptions._data_member_location_extra to handle DW_FORM_sdata Taken from #98 - contributed by @bseifers --- diff --git a/elftools/dwarf/descriptions.py b/elftools/dwarf/descriptions.py index a894ceb..2dbd699 100644 --- a/elftools/dwarf/descriptions.py +++ b/elftools/dwarf/descriptions.py @@ -434,6 +434,8 @@ def _data_member_location_extra(attr, die, section_offset): if attr.form in ('DW_FORM_data1', 'DW_FORM_data2', 'DW_FORM_data4', 'DW_FORM_data8'): return '' # No extra description needed + elif attr.form == 'DW_FORM_sdata': + return str(attr.value) else: return describe_DWARF_expr(attr.value, die.cu.structs) diff --git a/test/testfiles_for_readelf/deleteme.out b/test/testfiles_for_readelf/deleteme.out new file mode 100644 index 0000000..524acff --- /dev/null +++ b/test/testfiles_for_readelf/deleteme.out @@ -0,0 +1 @@ +Test file diff --git a/test/testfiles_for_readelf/hello.c b/test/testfiles_for_readelf/hello.c new file mode 100644 index 0000000..b008b11 --- /dev/null +++ b/test/testfiles_for_readelf/hello.c @@ -0,0 +1,40 @@ +/* Generated by compiling with gcc 4.4 (or higher?) as follows: +** +** gcc -g -o hello.out hello.c +** +** To run the test that shows the error, do a readelf dump: +** readelf.py --debug-dump=info hello.out +** +** When using an unmodified descriptions.py, you will get a +** python exception when it tries to read the 'ijk' element +** from the elf file. My new version of descriptions.py fixes +** this problem. +*/ + +#include + +struct def +{ + int ijk; + char c; + long long lint; + float mno; + int bit1 : 1; + int bit3 : 3; + int bit2 : 2; + int bit4 : 4; +//}; +}__attribute__((__packed__)); + +const int GLOBAL_CONST; + +int tryGlobal; +struct def hiLo; + +int main() +{ + int abc; + printf("Hello World\n"); + return 0; +} + diff --git a/test/testfiles_for_readelf/hello.out b/test/testfiles_for_readelf/hello.out new file mode 100644 index 0000000..74a8e24 Binary files /dev/null and b/test/testfiles_for_readelf/hello.out differ