]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
readelf: Support showing view pairs in loclists as GNU extension.
authorMark Wielaard <mark@klomp.org>
Sun, 27 Sep 2020 19:07:12 +0000 (21:07 +0200)
committerMark Wielaard <mark@klomp.org>
Fri, 2 Oct 2020 21:32:49 +0000 (23:32 +0200)
View pairs are encoded in .debug_loclists as they are encoded in
.debug_locs sections by the GCC compiler. Scan for DW_AT_GNU_locviews
attributes that point to the view pairs just in front of the actual
location lists.

Signed-off-by: Mark Wielaard <mark@klomp.org>
src/ChangeLog
src/readelf.c

index 0313d2a28bbda20574f5ec8564604533012494d9..112b2242a7172d25d5bc8d807b1dafc3b72c3c3b 100644 (file)
@@ -1,3 +1,12 @@
+2020-09-28  Mark Wielaard  <mark@klomp.org>
+
+       * readelf.c (next_listptr_offset): Take idx as pointer, to be updated
+       and use new Dwarf_Off as offset to match.
+       (listptr_attr): New function.
+       (print_debug_loclists_section): Check for DW_AT_GNU_locviews to show
+       view pairs.
+       (print_debug_loc_section): Adjust next_listptr_offset call.
+
 2020-09-03  Mark Wielaard  <mark@klomp.org>
 
        * readelf.c (print_cfa_program): Take ehdr as argument. Use it to
index 64067a57bb68a13f399ff25605205ef44cf2a3c6..f6d13afaababd033981abd94667f1c7087ee75e8 100644 (file)
@@ -4993,17 +4993,19 @@ skip_listptr_hole (struct listptr_table *table, size_t *idxp,
 }
 
 static Dwarf_Off
-next_listptr_offset (struct listptr_table *table, size_t idx)
+next_listptr_offset (struct listptr_table *table, size_t *idxp, Dwarf_Off off)
 {
   /* Note that multiple attributes could in theory point to the same loclist
      offset, so make sure we pick one that is bigger than the current one.
      The table is sorted on offset.  */
-  Dwarf_Off offset = table->table[idx].offset;
-  while (++idx < table->n)
+  if (*idxp < table->n)
     {
-      Dwarf_Off next = table->table[idx].offset;
-      if (next > offset)
-       return next;
+      while (++*idxp < table->n)
+       {
+         Dwarf_Off next = table->table[*idxp].offset;
+         if (next > off)
+           return next;
+       }
     }
   return 0;
 }
@@ -5036,13 +5038,36 @@ listptr_cu (struct listptr_table *table, size_t *idxp,
       struct listptr *p = &table->table[*idxp];
       *base = listptr_base (p);
       *cu = p->cu;
-      ++*idxp;
       return true;
     }
 
   return false;
 }
 
+/* Returns the next index with the current CU for the given attribute.
+   If there is none false is returned, otherwise true.  Assumes the
+   table has been sorted.  */
+static bool
+listptr_attr (struct listptr_table *table, size_t idxp,
+             Dwarf_Off offset, unsigned int attr)
+{
+  struct listptr *listptr;
+  do
+    {
+      listptr = get_listptr (table, idxp);
+      if (listptr == NULL)
+       return false;
+
+      if (listptr->offset == offset && listptr->attr == attr)
+       return true;
+
+      idxp++;
+    }
+  while (listptr->offset <= offset);
+
+  return false;
+}
+
 static void
 print_debug_abbrev_section (Dwfl_Module *dwflmod __attribute__ ((unused)),
                            Ebl *ebl, GElf_Ehdr *ehdr __attribute__ ((unused)),
@@ -9171,6 +9196,43 @@ print_debug_loclists_section (Dwfl_Module *dwflmod,
       bool start_of_list = true;
       while (readp < nexthdr)
        {
+         Dwarf_Off off = (Dwarf_Off) (readp - (unsigned char *) data->d_buf);
+         if (listptr_attr (&known_loclistsptr, listptr_idx, off,
+                           DW_AT_GNU_locviews))
+           {
+             Dwarf_Off next_off = next_listptr_offset (&known_loclistsptr,
+                                                       &listptr_idx, off);
+             const unsigned char *locp = readp;
+             const unsigned char *locendp;
+             if (next_off == 0
+                 || next_off > (size_t) (nexthdr - ((const unsigned char *)
+                                                    data->d_buf)))
+               locendp = nexthdr;
+             else
+               locendp = (const unsigned char *) data->d_buf + next_off;
+
+             printf ("  Offset: %" PRIx64 ", Index: %" PRIx64 "\n",
+                     (uint64_t) (readp - (unsigned char *) data->d_buf),
+                     (uint64_t) (readp - offset_array_start));
+
+             while (locp < locendp)
+               {
+                 uint64_t v1, v2;
+                 get_uleb128 (v1, locp, locendp);
+                 if (locp >= locendp)
+                   {
+                     printf (gettext ("    <INVALID DATA>\n"));
+                     break;
+                   }
+                 get_uleb128 (v2, locp, locendp);
+                 printf ("    view pair %" PRId64 ", %" PRId64 "\n", v1, v2);
+               }
+
+             printf ("\n");
+             readp = (unsigned char *) locendp;
+             continue;
+           }
+
          uint8_t kind = *readp++;
          uint64_t op1, op2, len;
 
@@ -9502,7 +9564,7 @@ print_debug_loc_section (Dwfl_Module *dwflmod,
       if (attr == DW_AT_GNU_locviews)
        {
          Dwarf_Off next_off = next_listptr_offset (&known_locsptr,
-                                                   listptr_idx);
+                                                   &listptr_idx, offset);
          const unsigned char *locp = readp;
          const unsigned char *locendp;
          if (next_off == 0