]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
readelf: Print CU, base address and unresolved .debug_loc entries.
authorMark Wielaard <mark@klomp.org>
Wed, 29 Nov 2017 15:37:50 +0000 (16:37 +0100)
committerMark Wielaard <mark@klomp.org>
Wed, 29 Nov 2017 15:47:26 +0000 (16:47 +0100)
Also adjust the formatting for the resolved addresses to print them
on separate lines so they nicely line up even when the addresses are
resolved to symbol+offset names. And print the operands starting on
a new line.

Signed-off-by: Mark Wielaard <mark@klomp.org>
src/ChangeLog
src/readelf.c
tests/ChangeLog
tests/run-readelf-loc.sh
tests/run-readelf-zdebug-rel.sh
tests/run-readelf-zdebug.sh

index 3dd80fb0a75edee7b834985f7f41baec4776ed13..612b3655848c7a18d21876f99f6ed149133fd1de 100644 (file)
@@ -1,3 +1,8 @@
+2017-11-29  Mark Wielaard  <mark@klomp.org>
+
+       * readelf.c (print_debug_loc_section): Print CU base and unresolved
+       addresses. Adjust formatting.
+
 2017-11-29  Mark Wielaard  <mark@klomp.org>
 
        * readelf.c (print_debug_ranges_section): Print CU base and unresolved
index 8e134627ae8975c75ecd153b4ce76414811a6b64..bb48af9bf0a5a8f8e4fdf5c35adc43c3c2eb1f93 100644 (file)
@@ -7130,19 +7130,36 @@ print_debug_loc_section (Dwfl_Module *dwflmod,
   uint_fast8_t offset_size = 4;
 
   bool first = true;
-  struct Dwarf_CU *cu = NULL;
   Dwarf_Addr base = 0;
   unsigned char *readp = data->d_buf;
   unsigned char *const endp = (unsigned char *) data->d_buf + data->d_size;
+  Dwarf_CU *last_cu = NULL;
   while (readp < endp)
     {
       ptrdiff_t offset = readp - (unsigned char *) data->d_buf;
+      Dwarf_CU *cu;
 
       if (first && skip_listptr_hole (&known_loclistptr, &listptr_idx,
                                      &address_size, &offset_size, &base,
                                      &cu, offset, &readp, endp))
        continue;
 
+      if (last_cu != cu)
+       {
+       char *basestr = format_dwarf_addr (dwflmod, address_size,
+                                          base, base);
+       Dwarf_Die cudie;
+       if (dwarf_cu_die (cu, &cudie,
+                         NULL, NULL, NULL, NULL,
+                         NULL, NULL) == NULL)
+         printf (gettext ("\n Unknown CU base: %s\n"), basestr);
+       else
+         printf (gettext ("\n CU [%6" PRIx64 "] base: %s\n"),
+                 dwarf_dieoffset (&cudie), basestr);
+       free (basestr);
+       }
+      last_cu = cu;
+
       if (unlikely (data->d_size - offset < (size_t) address_size * 2))
        {
          printf (gettext (" [%6tx]  <INVALID DATA>\n"), offset);
@@ -7167,14 +7184,14 @@ print_debug_loc_section (Dwfl_Module *dwflmod,
       if (begin == (Dwarf_Addr) -1l) /* Base address entry.  */
        {
          char *b = format_dwarf_addr (dwflmod, address_size, end, end);
-         printf (gettext (" [%6tx]  base address %s\n"), offset, b);
+         printf (gettext (" [%6tx] base address\n          %s\n"), offset, b);
          free (b);
          base = end;
        }
       else if (begin == 0 && end == 0) /* End of list entry.  */
        {
          if (first)
-           printf (gettext (" [%6tx]  empty list\n"), offset);
+           printf (gettext (" [%6tx] empty list\n"), offset);
          first = true;
        }
       else
@@ -7182,18 +7199,23 @@ print_debug_loc_section (Dwfl_Module *dwflmod,
          /* We have a location expression entry.  */
          uint_fast16_t len = read_2ubyte_unaligned_inc (dbg, readp);
 
-         char *b = format_dwarf_addr (dwflmod, address_size, base + begin,
-                                      begin);
-         char *e = format_dwarf_addr (dwflmod, address_size, base + end,
-                                      end);
-
          if (first)            /* First entry in a list.  */
-           printf (gettext (" [%6tx]  %s..%s"), offset, b, e);
+           printf (" [%6tx] ", offset);
          else
-           printf (gettext ("           %s..%s"), b, e);
+           printf ("          ");
 
-         free (b);
-         free (e);
+         printf ("range %" PRIx64 ", %" PRIx64 "\n", begin, end);
+         if (! print_unresolved_addresses)
+           {
+             char *b = format_dwarf_addr (dwflmod, address_size, base + begin,
+                                          base + begin);
+             char *e = format_dwarf_addr (dwflmod, address_size,
+                                          base + end - 1, base + end);
+             printf ("          %s..\n", b);
+             printf ("          %s\n", e);
+             free (b);
+             free (e);
+           }
 
          if (endp - readp <= (ptrdiff_t) len)
            {
@@ -7201,8 +7223,9 @@ print_debug_loc_section (Dwfl_Module *dwflmod,
              break;
            }
 
-         print_ops (dwflmod, dbg, 1, 18 + (address_size * 4),
-                    3 /*XXX*/, address_size, offset_size, cu, len, readp);
+         print_ops (dwflmod, dbg, 11, 11,
+                    cu != NULL ? cu->version : 3,
+                    address_size, offset_size, cu, len, readp);
 
          first = false;
          readp += len;
index 4666dcc210d522ac3d3303c6ae64e4d0396e4257..cb0c977fff223d374312919d837ed2534ed8999a 100644 (file)
@@ -1,3 +1,9 @@
+2017-11-29  Mark Wielaard  <mark@klomp.org>
+
+       * run-readelf-loc.sh: Adjust expected loc list output.
+       * run-readelf-zdebug-rel.sh: Likewise.
+       * run-readelf-zdebug.sh: Likewise.
+
 2017-11-29  Mark Wielaard  <mark@klomp.org>
 
        * run-readelf-loc.sh: Adjust expected range list output.
index 4b666cfeaebeb67ac60aed9f73cf8050d373d5f0..e5152df85d6c3c32fc935cf7cfd5785da9bfd430 100755 (executable)
@@ -63,9 +63,22 @@ testrun_compare ${abs_top_builddir}/src/readelf --debug-dump=loc --debug-dump=ra
   testfileloc<<\EOF
 
 DWARF section [33] '.debug_loc' at offset 0xd2a:
- [     0]  0x0000000000400480 <main>..0x000000000040048d <main+0xd> [ 0] reg5
- [    23]  0x0000000000400485 <main+0x5>..0x000000000040048d <main+0xd> [ 0] reg5
- [    46]  0x00000000004004b2 <say+0x12>..0x00000000004004ba <say+0x1a> [ 0] breg5 0
+
+ CU [     b] base: 0x0000000000400480 <main>
+ [     0] range 0, d
+          0x0000000000400480 <main>..
+          0x000000000040048c <main+0xc>
+           [ 0] reg5
+ [    23] range 5, d
+          0x0000000000400485 <main+0x5>..
+          0x000000000040048c <main+0xc>
+           [ 0] reg5
+
+ CU [    e0] base: 0x00000000004004a0 <say>
+ [    46] range 12, 1a
+          0x00000000004004b2 <say+0x12>..
+          0x00000000004004b9 <say+0x19>
+           [ 0] breg5 0
 
 DWARF section [34] '.debug_ranges' at offset 0xd94:
 
@@ -91,9 +104,22 @@ testrun_compare ${abs_top_builddir}/src/readelf -N --debug-dump=loc --debug-dump
   testfileloc<<\EOF
 
 DWARF section [33] '.debug_loc' at offset 0xd2a:
- [     0]  0x0000000000400480..0x000000000040048d [ 0] reg5
- [    23]  0x0000000000400485..0x000000000040048d [ 0] reg5
- [    46]  0x00000000004004b2..0x00000000004004ba [ 0] breg5 0
+
+ CU [     b] base: 0x0000000000400480
+ [     0] range 0, d
+          0x0000000000400480..
+          0x000000000040048c
+           [ 0] reg5
+ [    23] range 5, d
+          0x0000000000400485..
+          0x000000000040048c
+           [ 0] reg5
+
+ CU [    e0] base: 0x00000000004004a0
+ [    46] range 12, 1a
+          0x00000000004004b2..
+          0x00000000004004b9
+           [ 0] breg5 0
 
 DWARF section [34] '.debug_ranges' at offset 0xd94:
 
@@ -119,9 +145,16 @@ testrun_compare ${abs_top_builddir}/src/readelf -U --debug-dump=loc --debug-dump
   testfileloc<<\EOF
 
 DWARF section [33] '.debug_loc' at offset 0xd2a:
- [     0]  000000000000000000..0x000000000000000d [ 0] reg5
- [    23]  0x0000000000000005..0x000000000000000d [ 0] reg5
- [    46]  0x0000000000000012..0x000000000000001a [ 0] breg5 0
+
+ CU [     b] base: 0x0000000000400480
+ [     0] range 0, d
+           [ 0] reg5
+ [    23] range 5, d
+           [ 0] reg5
+
+ CU [    e0] base: 0x00000000004004a0
+ [    46] range 12, 1a
+           [ 0] breg5 0
 
 DWARF section [34] '.debug_ranges' at offset 0xd94:
 
index 2b57d05817bdb484b558d4475122e91d79952b0a..ccccd82dbdc1cadfae4fc289a95c8ba68ff8b9d7 100755 (executable)
@@ -127,12 +127,17 @@ cat info.out | testrun_compare ${abs_top_builddir}/src/readelf -U --debug-dump=i
 cat > loc.out << \EOF
 
 DWARF section [ 7] '.debug_loc' at offset 0x185:
- [     0]  000000000000000000..0x0000000000000003 [ 0] reg5
-           0x0000000000000003..0x0000000000000010 [ 0] breg5 -42
-                                                  [ 2] stack_value
-           0x0000000000000010..0x0000000000000018 [ 0] GNU_entry_value:
-      [ 0] reg5
-                                                  [ 3] stack_value
+
+ CU [     b] base: 000000000000000000
+ [     0] range 0, 3
+           [ 0] reg5
+          range 3, 10
+           [ 0] breg5 -42
+           [ 2] stack_value
+          range 10, 18
+           [ 0] GNU_entry_value:
+                [ 0] reg5
+           [ 3] stack_value
 EOF
 
 cat loc.out | testrun_compare ${abs_top_builddir}/src/readelf -U --debug-dump=loc testfile-debug-rel.o
index 7be9beeee7d5e27f63b241954db1c5aba1a4a062..28128ad90773f0ac8bf7c0fb2176b866c975dbbc 100755 (executable)
@@ -46,12 +46,17 @@ tempfiles loc.out aranges.out ranges.out macro.out line.out frame.out
 cat > loc.out << \EOF
 
 DWARF section [30] '.debug_loc' at offset 0xa17:
- [     0]  0x00000000004003c0..0x00000000004003c3 [ 0] reg5
-           0x00000000004003c3..0x00000000004003d6 [ 0] breg5 -42
-                                                  [ 2] stack_value
-           0x00000000004003d6..0x00000000004003d9 [ 0] GNU_entry_value:
-      [ 0] reg5
-                                                  [ 3] stack_value
+
+ CU [     b] base: 000000000000000000
+ [     0] range 4003c0, 4003c3
+           [ 0] reg5
+          range 4003c3, 4003d6
+           [ 0] breg5 -42
+           [ 2] stack_value
+          range 4003d6, 4003d9
+           [ 0] GNU_entry_value:
+                [ 0] reg5
+           [ 3] stack_value
 EOF
 
 cat loc.out | testrun_compare ${abs_top_builddir}/src/readelf -U --debug-dump=loc testfile-debug