From 9bf1b2d54bf74707674c07c9c060f20962d8a4e0 Mon Sep 17 00:00:00 2001 From: Eli Bendersky Date: Sat, 25 May 2013 09:28:12 -0700 Subject: [PATCH] More tweaks to succesfully parse an object file generated by gcc 4.8 with DWARFv4 --- CHANGES | 4 ++-- elftools/dwarf/descriptions.py | 9 +++++---- elftools/dwarf/enums.py | 9 +++++++++ elftools/dwarf/structs.py | 9 ++++----- test/testfiles_for_readelf/clang33-simple.o | Bin 0 -> 3160 bytes test/testfiles_for_readelf/gcc48-simple.o | Bin 0 -> 2968 bytes 6 files changed, 20 insertions(+), 11 deletions(-) create mode 100644 test/testfiles_for_readelf/clang33-simple.o create mode 100644 test/testfiles_for_readelf/gcc48-simple.o diff --git a/CHANGES b/CHANGES index fe39abb..8a8bd2a 100644 --- a/CHANGES +++ b/CHANGES @@ -5,8 +5,8 @@ Changelog - Added some initial support for parsing Solaris OpenCSW ELF files (contributed by Yann Rouillard). - - Added some initial support for DWARF4 and DWARF generated by recent - versions of Clang. + - Added some initial support for DWARF4 (as generated by gcc 4.8) + and DWARF generated by recent versions of Clang (3.3). + Version 0.21 (17.04.2013) diff --git a/elftools/dwarf/descriptions.py b/elftools/dwarf/descriptions.py index 3a950a0..f46ef81 100644 --- a/elftools/dwarf/descriptions.py +++ b/elftools/dwarf/descriptions.py @@ -198,6 +198,9 @@ def _describe_attr_debool(attr, die, section_offset): return '1' if attr.value else '0' def _describe_attr_present(attr, die, section_offset): + """ Some forms may simply mean that an attribute is present, + without providing any value. + """ return '1' def _describe_attr_block(attr, die, section_offset): @@ -231,10 +234,8 @@ _ATTR_DESCRIPTION_MAP = defaultdict( DW_FORM_block4=_describe_attr_block, DW_FORM_block=_describe_attr_block, DW_FORM_flag_present=_describe_attr_present, - # Not sure how to print them - # DW_FORM_exprloc=_describe_attr_value_passthrough, - # DW_FORM_ref_sig8=_describe_attr_ref, - + DW_FORM_exprloc=_describe_attr_block, + DW_FORM_ref_sig8=_describe_attr_ref, ) diff --git a/elftools/dwarf/enums.py b/elftools/dwarf/enums.py index 2b00b2a..ee1ff7e 100644 --- a/elftools/dwarf/enums.py +++ b/elftools/dwarf/enums.py @@ -215,6 +215,15 @@ ENUM_DW_AT = dict( DW_AT_GNU_vector = 0x2107, DW_AT_GNU_template_name = 0x2110, + DW_AT_GNU_call_site_value = 0x2111, + DW_AT_GNU_call_site_data_value = 0x2112, + DW_AT_GNU_call_site_target = 0x2113, + DW_AT_GNU_call_site_target_clobbered = 0x2114, + DW_AT_GNU_tail_call = 0x2115, + DW_AT_GNU_all_tail_call_sites = 0x2116, + DW_AT_GNU_all_call_sites = 0x2117, + DW_AT_GNU_all_source_call_sites = 0x2118, + DW_AT_APPLE_optimized = 0x3fe1, DW_AT_APPLE_flags = 0x3fe2, DW_AT_APPLE_isa = 0x3fe3, diff --git a/elftools/dwarf/structs.py b/elftools/dwarf/structs.py index ffd662e..fb4074a 100644 --- a/elftools/dwarf/structs.py +++ b/elftools/dwarf/structs.py @@ -194,12 +194,11 @@ class DWARFStructs(object): DW_FORM_indirect=self.Dwarf_uleb128(''), + # New forms in DWARFv4 DW_FORM_flag_present = StaticField('', 0), - # Needs checkings - #DW_FORM_sec_offset = self.Dwarf_offset(''), - #DW_FORM_exprloc = self.Dwarf_uleb128(''), - #DW_FORM_ref_sig8 = self.Dwarf_offset(''), - + DW_FORM_sec_offset = self.Dwarf_offset(''), + DW_FORM_exprloc = self._make_block_struct(self.Dwarf_uleb128), + DW_FORM_ref_sig8 = self.Dwarf_offset(''), ) def _create_lineprog_header(self): diff --git a/test/testfiles_for_readelf/clang33-simple.o b/test/testfiles_for_readelf/clang33-simple.o new file mode 100644 index 0000000000000000000000000000000000000000..d64d2ef3c1b62a9cc21fc1ea81367e8af461c25f GIT binary patch literal 3160 zcmbtW&2JM|5TEC@gM*0^C#7miKdg$6fRr`V9NHoUM|5eZq8@?(aX?}1tP=~{8|^M3 zAgmsc+FAw)ZoTx}UfN1+k3Cc>Dja&^e?V%b96<8H5|P5p?mYASyb=ON+BY-5nRzpB z-g~?IwY7LUA%p=;0_H$SMd78s2S6#rOYk;K!MTO@xt-fT0QZg-9n|CqDtCU_y6B_c6K^e zZ{gPc{H4FaLo|U8KsqdSPblj{=pm9#9Y1 zNf0@4AUl;ZvNpNI?XjnM$CVJU*bN_M==%M)`O3Lm20+FJ-+PM8tZk(tRRdu8m$_oy}N(@C0$4y%XJf@ z7+0y=&DH#d&dvIPUAZ#gP_H!|2As9!s%JM)jbiI=1x$YpGX!=SCCRThLVd*!>}XYQ zJW@Yt)BAnm8B5H=Ub0MVLXk-v$0t0n8vYX=J)+Cu80{P7NwfYA^M8>Ou3YcX@(0^> zrssMW9ca$ijlY7ilwT*Ae?v3qzE!mAHBm^KE*Mgt1E|k*llAqJS)UUjIKto(DGKSn z1+?iHx!;TfV|*{fV6PH?`z7&T(qszhWqpgbxc<%XOI4l|>K`2`y?;L;*E4Ke-h(%fsD{}Cw)$-YVGJ_>s6Wc!N~J>-DBh|#-C&;KW4 zarwXF_t*PqS4q#W+EkhRlJIm##iVTXPk}@tZp2nX^~H6V@bKSYa1zuE*foR^VDwi% zXf|MU5Ma#+Z``oS0Nz~9WWbn)M5+P!w-Q4}`1Kez7(-u~$j1OWL4!odq|#6My^{Mq z=nXK9fc^~&ee@q5`tvB;9zHk7PTx5qI%|}38~+H2W(h>nad~fa{8Z!~`cI-P=aJuE zI(AYfSJ`R8rA#=*5=nd}QsD#UgsZ#yk%H4avc5waev$QK%;_A{8YF$ng2ZLNKWALl gW3#@b;T6^|Yq-O@tKpYeFEW>TS%o|cRHItwbI1A#egFUf literal 0 HcmV?d00001 diff --git a/test/testfiles_for_readelf/gcc48-simple.o b/test/testfiles_for_readelf/gcc48-simple.o new file mode 100644 index 0000000000000000000000000000000000000000..5eb04fa7328742143c35beaaceab2b68ac4a12ad GIT binary patch literal 2968 zcmbVO-D@LN6hC(+Nn5kcCasHGsxadEv9g(FZ75}zuE~bjt`rsB!itqTNhVFOnJkmZ zwyvudDnh6a?Ta9Y&wUX5Bet;OKcEkN6$19fXNC2g`_atYq%V6Q_nz}R-)HWf$v5TI zcMQfr5rbPWkQ54VU=H{KXAAH=WMFNj_gC@mM=N`$R`08m{qjlgNuSica{o#Bl(@fh z`{h%GJ|0*Ud&dJs@#3$?>`zwi@0Cv(!Z*t&kAB-P_gD6gtxt;UpFZBkNHGcrq z6JDdF_`{y~suoqNlGT0}83SI!m9c+QleqE+hofLn+jjhVexuWD-QRNUs&JVQ(NVbc z$M0aoj6+(CYZ=^F;@!lzOU497nQOFL?wq^TthgR+lFe4zHG=Cy!I$4#vr1OpUbJ&o zwiR?ecWKl0T)$aG(ebN|rJcov>_XnkZd%#*(Wc%Boa*P<`+hrct3lfbST2=rSZ}OV zx?a$oTWxxd-xdM0^IZ24&n5CtjgXG`3vf$=P|I!4;ubHe5`vB4DXlt)e%@T7C%rxUr*>w@D)LOrzV zx#&(%%xCpqKwqj$Czbz8O`+RfN4;JXxg5y;RUGO+jz6lENcDdkc|9iSUyb4&sHmd%`q;ORJR6o_O*WW};k4c`tNbnvBA<}JYs2i2PA@i#_ zQGOb!p1+G2#Z+}7%PA&bW%P0mlgh95T~vcbkvkfGw0w#-+KBhRdIa$ zJtRl<9i}rvRsZ)?(3_-0(s6np6X|$Kz#OM8RUGx*qT`}?GF6i!oX(iK$J95G!e165 xP~Suf7ZL#VO+@D@e9o_OH2O{=Xi?(2y{e7khfj@~wQfIuP8>_(R7<#?{{do%2DShI literal 0 HcmV?d00001 -- 2.30.2