From 9ef167e488a17760e48c1d0ee2105b0a7f6167c3 Mon Sep 17 00:00:00 2001 From: Eli Bendersky Date: Thu, 16 Jun 2022 06:47:35 -0700 Subject: [PATCH] Add previously untested output file to test set * By renaming it to have a .elf suffix This also fixes descriptions for DW_FORM_sdata to comply with the recent output format of readelf --- elftools/dwarf/descriptions.py | 5 +-- test/testfiles_for_readelf/hello.c | 40 ------------------ .../struct-bitfield-packed.c | 32 ++++++++++++++ .../{hello.out => struct-bitfield-packed.elf} | Bin 4 files changed, 34 insertions(+), 43 deletions(-) delete mode 100644 test/testfiles_for_readelf/hello.c create mode 100644 test/testfiles_for_readelf/struct-bitfield-packed.c rename test/testfiles_for_readelf/{hello.out => struct-bitfield-packed.elf} (100%) diff --git a/elftools/dwarf/descriptions.py b/elftools/dwarf/descriptions.py index 1934a2e..7861180 100644 --- a/elftools/dwarf/descriptions.py +++ b/elftools/dwarf/descriptions.py @@ -454,10 +454,9 @@ def _data_member_location_extra(attr, die, section_offset): # 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'): + 'DW_FORM_data4', 'DW_FORM_data8', + 'DW_FORM_sdata'): 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, die.cu.cu_offset) diff --git a/test/testfiles_for_readelf/hello.c b/test/testfiles_for_readelf/hello.c deleted file mode 100644 index b008b11..0000000 --- a/test/testfiles_for_readelf/hello.c +++ /dev/null @@ -1,40 +0,0 @@ -/* 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/struct-bitfield-packed.c b/test/testfiles_for_readelf/struct-bitfield-packed.c new file mode 100644 index 0000000..40d7076 --- /dev/null +++ b/test/testfiles_for_readelf/struct-bitfield-packed.c @@ -0,0 +1,32 @@ +/* Generated by compiling with gcc 4.4 (or higher?) as follows: +** +** gcc -g -o file.out file.c +*/ + +#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/struct-bitfield-packed.elf similarity index 100% rename from test/testfiles_for_readelf/hello.out rename to test/testfiles_for_readelf/struct-bitfield-packed.elf -- 2.30.2