Fix descriptions._data_member_location_extra to handle DW_FORM_sdata
authorEli Bendersky <eliben@gmail.com>
Wed, 2 Mar 2016 12:15:33 +0000 (04:15 -0800)
committerEli Bendersky <eliben@gmail.com>
Wed, 2 Mar 2016 12:15:33 +0000 (04:15 -0800)
Taken from #98 - contributed by @bseifers

elftools/dwarf/descriptions.py
test/testfiles_for_readelf/deleteme.out [new file with mode: 0644]
test/testfiles_for_readelf/hello.c [new file with mode: 0644]
test/testfiles_for_readelf/hello.out [new file with mode: 0644]

index a894ceb09fe3917a2589464229b390d19cec12af..2dbd69925a90033a5cf91534d13652dc47980f47 100644 (file)
@@ -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 (file)
index 0000000..524acff
--- /dev/null
@@ -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 (file)
index 0000000..b008b11
--- /dev/null
@@ -0,0 +1,40 @@
+/* Generated by compiling with gcc 4.4 (or higher?) as follows:\r
+**\r
+** gcc -g -o hello.out hello.c\r
+**\r
+** To run the test that shows the error, do a readelf dump:\r
+** readelf.py --debug-dump=info hello.out\r
+** \r
+** When using an unmodified descriptions.py, you will get a \r
+** python exception when it tries to read the 'ijk' element \r
+** from the elf file. My new version of descriptions.py fixes \r
+** this problem.\r
+*/\r
+\r
+#include <stdio.h>\r
+\r
+struct def\r
+{\r
+       int ijk;\r
+       char c;\r
+       long long lint;\r
+       float mno;\r
+       int bit1 : 1;\r
+       int bit3 : 3;\r
+       int bit2 : 2;\r
+       int bit4 : 4;\r
+//};\r
+}__attribute__((__packed__));\r
+\r
+const int GLOBAL_CONST;\r
+\r
+int tryGlobal;\r
+struct def hiLo;\r
+\r
+int main()\r
+{\r
+       int abc;\r
+       printf("Hello World\n");\r
+       return 0;\r
+}\r
+\r
diff --git a/test/testfiles_for_readelf/hello.out b/test/testfiles_for_readelf/hello.out
new file mode 100644 (file)
index 0000000..74a8e24
Binary files /dev/null and b/test/testfiles_for_readelf/hello.out differ