[PATCH] readelf: Support showing view pairs in loclists as GNU extension.
Mark Wielaard
mark@klomp.org
Mon Sep 28 07:43:44 GMT 2020
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 | 9 ++++++
src/readelf.c | 78 +++++++++++++++++++++++++++++++++++++++++++++------
2 files changed, 79 insertions(+), 8 deletions(-)
diff --git a/src/ChangeLog b/src/ChangeLog
index 0313d2a2..112b2242 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -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
diff --git a/src/readelf.c b/src/readelf.c
index 64067a57..f6d13afa 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -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
--
2.18.4
More information about the Elfutils-devel
mailing list