From 09e84e0520d3eb9d9ff5726ec7dc869e27ea9c54 Mon Sep 17 00:00:00 2001 From: Eli Bendersky Date: Wed, 2 Mar 2016 04:15:33 -0800 Subject: [PATCH] Fix descriptions._data_member_location_extra to handle DW_FORM_sdata Taken from #98 - contributed by @bseifers --- elftools/dwarf/descriptions.py | 2 ++ test/testfiles_for_readelf/deleteme.out | 1 + test/testfiles_for_readelf/hello.c | 40 ++++++++++++++++++++++++ test/testfiles_for_readelf/hello.out | Bin 0 -> 8181 bytes 4 files changed, 43 insertions(+) create mode 100644 test/testfiles_for_readelf/deleteme.out create mode 100644 test/testfiles_for_readelf/hello.c create mode 100644 test/testfiles_for_readelf/hello.out 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 0000000000000000000000000000000000000000..74a8e247d1b38d1c8a4ed7d8adfdb36108a9f66d GIT binary patch literal 8181 zcmcIpZ)_aJ6`$R`^PPRRV<&+SV#q-+ty9$(J2AnK1lDo>oavE3VhRYF_1Sl}FP!h( zyFHYkv`yszIk`|HRVqbDq=*kz`-Ms^iiFf83N)l2P-s6iQbBboNQMN}h!RERkNbPG z^X~T6=avuclXl*`-+OP~?AzIy+1VfNjPKGlO)%-=4nfkaVM@p;g*e$HMTPZTr54RNQ&{IqJCc~IFI;6AGB3eZibqIjDl3Fh2G;uNn!rm8yp7Kgy3pa(P+#y{!D0Pb)v>e1CLrbhWAW+H?~V$tE$eLzWdT za{=t0_w6Lr-%~gFp5K&~%p+0~f;s!$3qRFGW$~XG_j5xgJ+!%dLnhggNoR|PIu7-0 z?%3QNE##sbW&c~y4Bg`HJ@?55IUma*QS6nt=vk8fk2ie&dII9Gr)r=yv?=d~g1qf&O!+XMLuKojWrx*}2!i=1#%kpVQM6J2vHCkA`B8 zpSJad3o`Vyo9>I1-rrA#N4J@<6UA@8dZKPn!0mQ&`_ZLmNjmeH5u3cE#csP;h>R>- zyF=h6PHVA}{~8!AtbAP>P5A@la@)oHyTA8;VuXc8;T}4Fc4TBEx@_$++5gz&HlZU9 z#kH58B#inNJT-$j=ND$rpPim29lF$V>LOm2xp%)@Sdez4n*M}ZbGKK@L@vfl$;fQ% zsg6l4EaFeCJ3_~fj z>PVy$x7kB|BP!<;8N4cxj>)SF_Ucz@T2gtt6vT6wLO!o96hBrOa-P*(j`~8QgT|bD zbRkKpOePn;KbOxWg|^1n5=P=^oXx^zEBNQ&4}&-2(c9qk9usMg?GxIe7Hv&qA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