]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
readelf: Deal with combined normal and split dwarf DebugFission .debug_loc.
authorMark Wielaard <mark@klomp.org>
Fri, 1 Jun 2018 00:23:37 +0000 (02:23 +0200)
committerMark Wielaard <mark@klomp.org>
Fri, 1 Jun 2018 13:16:33 +0000 (15:16 +0200)
Normal and split dwarf from GNU DebugFission look the same, but should
be treated competely separtely. When having a file with both skeletons
and real compile units only note the secoffsets into the real .debug_loc
in readelf. Otherwise or known_locslistptr will get confused.

Add a testfile that combines an normal -gdwarf-4 object with a
-gsplit-dwarf object. libdw already got this right, but add a
run-varlocs.sh test to make sure.

Signed-off-by: Mark Wielaard <mark@klomp.org>
src/ChangeLog
src/readelf.c
tests/ChangeLog
tests/Makefile.am
tests/run-readelf-loc.sh
tests/run-varlocs.sh
tests/splitdwarf4-not-split4.dwo.bz2 [new file with mode: 0644]
tests/testfile-splitdwarf4-not-split4.debug.bz2 [new file with mode: 0755]

index 0e6f1f272b999f910b07f84b8c5001b8d44ce9a3..3cd7ae7bb0f93758fadcb079308e7b351b994eb9 100644 (file)
@@ -1,3 +1,8 @@
+2018-05-31  Mark Wielaard  <mark@klomp.org>
+
+       * readelf.c (attr_callback): Only register section_loc when not
+       looking at a split dwarf from a skeleton.
+
 2018-05-30  Mark Wielaard  <mark@klomp.org>
 
        * readelf.c (print_debug_loc_section): Use correct listptr for
index db7723d370bdd9ec80e536ba0bcefbcc90f4d601..45401b307c5da6f95a113d9b03c5cbb8b548bc6b 100644 (file)
@@ -7077,9 +7077,17 @@ attr_callback (Dwarf_Attribute *attrp, void *arg)
          {
            bool nlpt;
            if (cbargs->cu->version < 5)
-             nlpt = notice_listptr (section_loc, &known_locsptr,
-                                    cbargs->addrsize, cbargs->offset_size,
-                                    cbargs->cu, num, attr);
+             {
+               if (! cbargs->is_split)
+                 {
+                   nlpt = notice_listptr (section_loc, &known_locsptr,
+                                          cbargs->addrsize,
+                                          cbargs->offset_size,
+                                          cbargs->cu, num, attr);
+                 }
+               else
+                 nlpt = true;
+             }
            else
              {
                /* Only register for a real section offset.  Otherwise
index 1c1ef4ede62c920bf8426aff1ed583da16fed638..04b6e75315a31d8da234641b37fd626fe5858109 100644 (file)
@@ -1,3 +1,13 @@
+2018-05-31  Mark Wielaard  <mark@klomp.org>
+
+       * splitdwarf4-not-split4.dwo.bz2: New test file.
+       * testfile-splitdwarf4-not-split4.debug.bz2: Likewise.
+       * run-readelf-loc.sh: Add test for splitdwarf4-not-split4.dwo
+       and testfile-splitdwarf4-not-split4.debug.
+       * run-varlocs.sh: Test testfile-splitdwarf4-not-split4.debug.
+       * Makefile.am (EXTRA_DIST): Add splitdwarf4-not-split4.dwo.bz2
+       and testfile-splitdwarf4-not-split4.debug.bz2.
+
 2018-05-31  Mark Wielaard  <mark@klomp.org>
 
        * test-subr.sh (self_test_files): Split into self_test_files_exe,
index e935410aed11968a5c26e60b00cc195525861797..28ba9f79ba3c515125e0d36667a6be17652b6431 100644 (file)
@@ -238,6 +238,8 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh run-ar.sh \
             testfile-macros-0xff.bz2 \
             run-readelf-macro.sh testfilemacro.bz2 \
             run-readelf-loc.sh testfileloc.bz2 \
+            splitdwarf4-not-split4.dwo.bz2 \
+            testfile-splitdwarf4-not-split4.debug.bz2 \
             run-readelf-ranges.sh \
             run-readelf-aranges.sh run-readelf-line.sh testfilefoobarbaz.bz2 \
             testfile-ppc64-min-instr.bz2 \
index 484db4668f2b8c328bf16c795f5a830acebc3524..bf676f2b2eea4b161c760dda4cf07d753459b3a4 100755 (executable)
@@ -868,4 +868,293 @@ DWARF section [ 3] '.debug_loc.dwo' at offset 0x225:
            [ 0] reg5
 EOF
 
+# Partial dwarf-4 and partial GNU DebugFission split-dwarf.
+#
+# = popcount.c =
+#
+# int popcount (unsigned char u)
+# {
+#   int c = 0;
+#   while (u != 0)
+#     {
+#       if ((u & 1) == 1)
+#         c++;
+#       u >>= 1;
+#     }
+#   return c;
+# }
+#
+# = splitdwarf4-not-split4.c =
+#
+# extern int popcount (unsigned char);
+#
+# int main (int argc, char **argv)
+# {
+#   int i;
+#   int p = argc;
+#   for (i = 0; i < argc;  ++i)
+#     p += popcount (argv[i][0]);
+#   i += p;
+#   return i;
+# }
+#
+# gcc -gdwarf-4 -O2 -c popcount.c
+# gcc -gdwarf-4 -gsplit-dwarf -O2 -c splitdwarf4-not-split4.c
+# gcc -o testfile-splitdwarf4-not-split4 splitdwarf4-not-split4.o popcount.o
+# eu-strip -f testfile-splitdwarf4-not-split4.debug \
+#   testfile-splitdwarf4-not-split4
+
+testfiles testfile-splitdwarf4-not-split4.debug
+testfiles splitdwarf4-not-split4.dwo
+
+testrun_compare ${abs_top_builddir}/src/readelf --debug-dump=info+ --debug-dump=loc testfile-splitdwarf4-not-split4.debug <<\EOF
+
+DWARF section [28] '.debug_info' at offset 0x330:
+ [Offset]
+ Compilation unit at offset 0:
+ Version: 4, Abbreviation section offset: 0, Address size: 8, Offset size: 4
+ Unit type: skeleton (4), Unit id: 0x3d909d7bd0e69c0b
+ [     b]  compile_unit         abbrev: 1
+           ranges               (sec_offset) range list [     0]
+           low_pc               (addr) 000000000000000000
+           stmt_list            (sec_offset) 0
+           GNU_dwo_name         (strp) "splitdwarf4-not-split4.dwo"
+           comp_dir             (strp) "/tmp"
+           GNU_pubnames         (flag_present) yes
+           GNU_addr_base        (sec_offset) address base [     0]
+           GNU_dwo_id           (data8) 0x3d909d7bd0e69c0b
+           GNU_ranges_base      (sec_offset) 0
+ Split compilation unit at offset 0:
+ Version: 4, Abbreviation section offset: 0, Address size: 8, Offset size: 4
+ Unit type: skeleton (4), Unit id: 0x3d909d7bd0e69c0b
+ {     b}  compile_unit         abbrev: 1
+           producer             (GNU_str_index) "GNU C17 9.0.0 20180528 (experimental) -mtune=generic -march=x86-64 -gdwarf-4 -gsplit-dwarf -O2"
+           language             (data1) C99 (12)
+           name                 (GNU_str_index) "splitdwarf4-not-split4.c"
+           comp_dir             (GNU_str_index) "/tmp"
+           GNU_dwo_id           (data8) 0x3d909d7bd0e69c0b
+ {    18}    subprogram           abbrev: 2
+             external             (flag_present) yes
+             name                 (GNU_str_index) "main"
+             decl_file            (data1) splitdwarf4-not-split4.c (1)
+             decl_line            (data1) 3
+             decl_column          (data1) 5
+             prototyped           (flag_present) yes
+             type                 (ref4) {    6d}
+             low_pc               (GNU_addr_index) [4] 0x0000000000401050 <main>
+             high_pc              (data8) 76 (0x000000000040109c <_start>)
+             frame_base           (exprloc) 
+              [ 0] call_frame_cfa
+             GNU_all_call_sites   (flag_present) yes
+             sibling              (ref4) {    6d}
+ {    30}      formal_parameter     abbrev: 3
+               name                 (GNU_str_index) "argc"
+               decl_file            (data1) splitdwarf4-not-split4.c (1)
+               decl_line            (data1) 3
+               decl_column          (data1) 15
+               type                 (ref4) {    6d}
+               location             (sec_offset) location list [     0]
+ {    3d}      formal_parameter     abbrev: 3
+               name                 (GNU_str_index) "argv"
+               decl_file            (data1) splitdwarf4-not-split4.c (1)
+               decl_line            (data1) 3
+               decl_column          (data1) 28
+               type                 (ref4) {    74}
+               location             (sec_offset) location list [    28]
+ {    4a}      variable             abbrev: 4
+               name                 (string) "i"
+               decl_file            (data1) splitdwarf4-not-split4.c (1)
+               decl_line            (data1) 5
+               decl_column          (data1) 7
+               type                 (ref4) {    6d}
+               location             (sec_offset) location list [    47]
+ {    58}      variable             abbrev: 4
+               name                 (string) "p"
+               decl_file            (data1) splitdwarf4-not-split4.c (1)
+               decl_line            (data1) 6
+               decl_column          (data1) 7
+               type                 (ref4) {    6d}
+               location             (sec_offset) location list [    73]
+ {    66}      GNU_call_site        abbrev: 5
+               low_pc               (GNU_addr_index) [1] 0x000000000040107f <main+0x2f>
+               abstract_origin      (ref4) {    84}
+ {    6d}    base_type            abbrev: 6
+             byte_size            (data1) 4
+             encoding             (data1) signed (5)
+             name                 (string) "int"
+ {    74}    pointer_type         abbrev: 7
+             byte_size            (data1) 8
+             type                 (ref4) {    7a}
+ {    7a}    pointer_type         abbrev: 7
+             byte_size            (data1) 8
+             type                 (ref4) {    80}
+ {    80}    base_type            abbrev: 8
+             byte_size            (data1) 1
+             encoding             (data1) signed_char (6)
+             name                 (GNU_str_index) "char"
+ {    84}    subprogram           abbrev: 9
+             external             (flag_present) yes
+             declaration          (flag_present) yes
+             linkage_name         (GNU_str_index) "popcount"
+             name                 (GNU_str_index) "popcount"
+             decl_file            (data1) splitdwarf4-not-split4.c (1)
+             decl_line            (data1) 1
+             decl_column          (data1) 12
+ Compilation unit at offset 52:
+ Version: 4, Abbreviation section offset: 29, Address size: 8, Offset size: 4
+ [    3f]  compile_unit         abbrev: 1
+           producer             (strp) "GNU C17 9.0.0 20180528 (experimental) -mtune=generic -march=x86-64 -gdwarf-4 -O2"
+           language             (data1) C99 (12)
+           name                 (strp) "popcount.c"
+           comp_dir             (strp) "/tmp"
+           low_pc               (addr) 0x0000000000401180 <popcount>
+           high_pc              (data8) 33 (0x00000000004011a1)
+           stmt_list            (sec_offset) 145
+ [    61]    subprogram           abbrev: 2
+             external             (flag_present) yes
+             name                 (strp) "popcount"
+             decl_file            (data1) popcount.c (1)
+             decl_line            (data1) 1
+             decl_column          (data1) 5
+             prototyped           (flag_present) yes
+             type                 (ref4) [    a0]
+             low_pc               (addr) 0x0000000000401180 <popcount>
+             high_pc              (data8) 33 (0x00000000004011a1)
+             frame_base           (exprloc) 
+              [ 0] call_frame_cfa
+             GNU_all_call_sites   (flag_present) yes
+             sibling              (ref4) [    a0]
+ [    83]      formal_parameter     abbrev: 3
+               name                 (string) "u"
+               decl_file            (data1) popcount.c (1)
+               decl_line            (data1) 1
+               decl_column          (data1) 29
+               type                 (ref4) [    a7]
+               location             (sec_offset) location list [     0]
+ [    91]      variable             abbrev: 4
+               name                 (string) "c"
+               decl_file            (data1) popcount.c (1)
+               decl_line            (data1) 3
+               decl_column          (data1) 7
+               type                 (ref4) [    a0]
+               location             (sec_offset) location list [    60]
+ [    a0]    base_type            abbrev: 5
+             byte_size            (data1) 4
+             encoding             (data1) signed (5)
+             name                 (string) "int"
+ [    a7]    base_type            abbrev: 6
+             byte_size            (data1) 1
+             encoding             (data1) unsigned_char (8)
+             name                 (strp) "unsigned char"
+
+DWARF section [32] '.debug_loc' at offset 0x5ef:
+
+ CU [    3f] base: 0x0000000000401180 <popcount>
+ [     0] range 0, 9
+          0x0000000000401180 <popcount>..
+          0x0000000000401188 <popcount+0x8>
+           [ 0] reg5
+          range 9, 1b
+          0x0000000000401189 <popcount+0x9>..
+          0x000000000040119a <popcount+0x1a>
+           [ 0] reg1
+          range 1b, 1d
+          0x000000000040119b <popcount+0x1b>..
+          0x000000000040119c <popcount+0x1c>
+           [ 0] breg1 0
+           [ 2] lit1
+           [ 3] shr
+           [ 4] stack_value
+          range 1d, 21
+          0x000000000040119d <popcount+0x1d>..
+          0x00000000004011a0 <popcount+0x20>
+           [ 0] reg1
+ [    60] range 0, 9
+          0x0000000000401180 <popcount>..
+          0x0000000000401188 <popcount+0x8>
+           [ 0] lit0
+           [ 1] stack_value
+          range 9, 20
+          0x0000000000401189 <popcount+0x9>..
+          0x000000000040119f <popcount+0x1f>
+           [ 0] reg0
+          range 20, 21
+          0x00000000004011a0 <popcount+0x20>..
+          0x00000000004011a0 <popcount+0x20>
+           [ 0] lit0
+           [ 1] stack_value
+EOF
+
+testrun_compare ${abs_top_builddir}/src/readelf --dwarf-skeleton=testfile-splitdwarf4-not-split4.debug --debug-dump=loc splitdwarf4-not-split4.dwo <<\EOF
+
+DWARF section [ 3] '.debug_loc.dwo' at offset 0x15b:
+
+ CU [     b] base: 000000000000000000
+ [     0] range 401050, 40106e
+          0x0000000000401050 <main>..
+          0x000000000040106d <main+0x1d>
+           [ 0] reg5
+          range 40106e, 401086
+          0x000000000040106e <main+0x1e>..
+          0x0000000000401085 <main+0x35>
+           [ 0] reg12
+          range 401086, 401095
+          0x0000000000401086 <main+0x36>..
+          0x0000000000401094 <main+0x44>
+           [ 0] GNU_entry_value:
+                [ 0] reg5
+           [ 3] stack_value
+          range 401095, 40109c
+          0x0000000000401095 <main+0x45>..
+          0x000000000040109b <main+0x4b>
+           [ 0] reg5
+ [    28] range 401050, 40106e
+          0x0000000000401050 <main>..
+          0x000000000040106d <main+0x1d>
+           [ 0] reg4
+          range 40106e, 401095
+          0x000000000040106e <main+0x1e>..
+          0x0000000000401094 <main+0x44>
+           [ 0] GNU_entry_value:
+                [ 0] reg4
+           [ 3] stack_value
+          range 401095, 40109c
+          0x0000000000401095 <main+0x45>..
+          0x000000000040109b <main+0x4b>
+           [ 0] reg4
+ [    47] range 401050, 40106e
+          0x0000000000401050 <main>..
+          0x000000000040106d <main+0x1d>
+           [ 0] lit0
+           [ 1] stack_value
+          range 401086, 40108e
+          0x0000000000401086 <main+0x36>..
+          0x000000000040108d <main+0x3d>
+           [ 0] breg12 0
+           [ 2] breg6 0
+           [ 4] plus
+           [ 5] stack_value
+          range 40108e, 401095
+          0x000000000040108e <main+0x3e>..
+          0x0000000000401094 <main+0x44>
+           [ 0] reg0
+          range 401095, 40109c
+          0x0000000000401095 <main+0x45>..
+          0x000000000040109b <main+0x4b>
+           [ 0] lit0
+           [ 1] stack_value
+ [    73] range 401050, 40106e
+          0x0000000000401050 <main>..
+          0x000000000040106d <main+0x1d>
+           [ 0] reg5
+          range 40106e, 401090
+          0x000000000040106e <main+0x1e>..
+          0x000000000040108f <main+0x3f>
+           [ 0] reg6
+          range 401095, 40109c
+          0x0000000000401095 <main+0x45>..
+          0x000000000040109b <main+0x4b>
+           [ 0] reg5
+EOF
+
 exit 0
index e98d8e94b7358e680c8d2a68f2c20a6fae702b2d..b26217760b376bcaa0a70d3232fe2cd8d25e119a 100755 (executable)
@@ -559,4 +559,46 @@ module 'testfile-addrx_constx-4'
       location (exprloc) {addr: 0x404038, deref_size(4), GNU_push_tls_address, const: 0x403e08, deref_size(4), plus, GNU_push_tls_address, const: 0x403e0c, deref_size(4), plus, GNU_push_tls_address, const: 0x403e10, deref_size(4), plus, addr: 0x404034, deref_size(4), plus, addr: 0x40403c, deref_size(4), plus, stack_value}
 EOF
 
+# See run-readelf-loc.sh
+testfiles testfile-splitdwarf4-not-split4.debug
+testfiles splitdwarf4-not-split4.dwo
+
+testrun_compare ${abs_top_builddir}/tests/varlocs --debug -e testfile-splitdwarf4-not-split4.debug <<\EOF
+module 'testfile-splitdwarf4-not-split4.debug'
+[b] CU 'splitdwarf4-not-split4.c'
+  [18] function 'main'@401050
+    frame_base: {call_frame_cfa {...}}
+    [30] parameter 'argc'
+      [401050,40106e) {reg5}
+      [40106e,401086) {reg12}
+      [401086,401095) {GNU_entry_value(1) {reg5}, stack_value}
+      [401095,40109c) {reg5}
+    [3d] parameter 'argv'
+      [401050,40106e) {reg4}
+      [40106e,401095) {GNU_entry_value(1) {reg4}, stack_value}
+      [401095,40109c) {reg4}
+    [4a] variable 'i'
+      [401050,40106e) {lit0, stack_value}
+      [401086,40108e) {breg12(0), breg6(0), plus, stack_value}
+      [40108e,401095) {reg0}
+      [401095,40109c) {lit0, stack_value}
+    [58] variable 'p'
+      [401050,40106e) {reg5}
+      [40106e,401090) {reg6}
+      [401095,40109c) {reg5}
+module 'testfile-splitdwarf4-not-split4.debug'
+[3f] CU 'popcount.c'@401180
+  [61] function 'popcount'@401180
+    frame_base: {call_frame_cfa {...}}
+    [83] parameter 'u'
+      [401180,401189) {reg5}
+      [401189,40119b) {reg1}
+      [40119b,40119d) {breg1(0), lit1, shr, stack_value}
+      [40119d,4011a1) {reg1}
+    [91] variable 'c'
+      [401180,401189) {lit0, stack_value}
+      [401189,4011a0) {reg0}
+      [4011a0,4011a1) {lit0, stack_value}
+EOF
+
 exit 0
diff --git a/tests/splitdwarf4-not-split4.dwo.bz2 b/tests/splitdwarf4-not-split4.dwo.bz2
new file mode 100644 (file)
index 0000000..4346b2e
Binary files /dev/null and b/tests/splitdwarf4-not-split4.dwo.bz2 differ
diff --git a/tests/testfile-splitdwarf4-not-split4.debug.bz2 b/tests/testfile-splitdwarf4-not-split4.debug.bz2
new file mode 100755 (executable)
index 0000000..6f4d701
Binary files /dev/null and b/tests/testfile-splitdwarf4-not-split4.debug.bz2 differ