[PATCH 12/13] gdb/dwarf: make read_{loc, rng}list_index return sect_offset

Simon Marchi via Gdb-patches
2021-01-20T05:41:33Z

From: Simon Marchi <simon.marchi@efficios.com>

I think it's wrong that read_loclist_index and read_rnglist_index return
a CORE_ADDR. A CORE_ADDR is an address in the program. These functions
return offset in sections (.debug_loclists and .debug_rnglists). I
think sect_offset is more appropriate.

I'm wondering if struct attribute should have a "set_sect_offset"
method, that takes a sect_offset parameter, or if it's better to be
left as a simple "unsigned".

gdb/ChangeLog:

* dwarf2/read.c (read_loclist_index, read_rnglist_index): Return
a sect_offset.
(read_attribute_reprocess): Adjust.

Change-Id: I0e22e0864130fb490072b41ae099762918b8ad4d
---
gdb/dwarf2/read.c | 22 ++++++++++++----------
1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 86a69efe8ecc..b4ac290ca319 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -20195,7 +20195,8 @@ lookup_loclist_base (struct dwarf2_cu *cu)

/* Given a DW_FORM_loclistx value LOCLIST_INDEX, fetch the offset from the
array of offsets in the .debug_loclists section. */
-static CORE_ADDR
+
+static sect_offset
read_loclist_index (struct dwarf2_cu *cu, ULONGEST loclist_index)
{
dwarf2_per_objfile *per_objfile = cu->per_objfile;
@@ -20245,14 +20246,15 @@ read_loclist_index (struct dwarf2_cu *cu, ULONGEST loclist_index)
const gdb_byte *info_ptr = section->buffer + start_offset;

if (cu->header.offset_size == 4)
- return bfd_get_32 (abfd, info_ptr) + loclist_base;
+ return (sect_offset) (bfd_get_32 (abfd, info_ptr) + loclist_base);
else
- return bfd_get_64 (abfd, info_ptr) + loclist_base;
+ return (sect_offset) (bfd_get_64 (abfd, info_ptr) + loclist_base);
}

/* Given a DW_FORM_rnglistx value RNGLIST_INDEX, fetch the offset from the
array of offsets in the .debug_rnglists section. */
-static CORE_ADDR
+
+static sect_offset
read_rnglist_index (struct dwarf2_cu *cu, ULONGEST rnglist_index,
dwarf_tag tag)
{
@@ -20309,9 +20311,9 @@ read_rnglist_index (struct dwarf2_cu *cu, ULONGEST rnglist_index,
const gdb_byte *info_ptr = section->buffer + start_offset;

if (cu->header.offset_size == 4)
- return read_4_bytes (abfd, info_ptr) + rnglist_base;
+ return (sect_offset) (read_4_bytes (abfd, info_ptr) + rnglist_base);
else
- return read_8_bytes (abfd, info_ptr) + rnglist_base;
+ return (sect_offset) (read_8_bytes (abfd, info_ptr) + rnglist_base);
}

/* Process the attributes that had to be skipped in the first round. These
@@ -20332,18 +20334,18 @@ read_attribute_reprocess (const struct die_reader_specs *reader,
break;
case DW_FORM_loclistx:
{
- CORE_ADDR loclists_sect_off
+ sect_offset loclists_sect_off
= read_loclist_index (cu, attr->as_unsigned_reprocess ());

- attr->set_unsigned (loclists_sect_off);
+ attr->set_unsigned (to_underlying (loclists_sect_off));
}
break;
case DW_FORM_rnglistx:
{
- CORE_ADDR rnglists_sect_off
+ sect_offset rnglists_sect_off
= read_rnglist_index (cu, attr->as_unsigned_reprocess (), tag);

- attr->set_unsigned (rnglists_sect_off);
+ attr->set_unsigned (to_underlying (rnglists_sect_off));
}
break;
case DW_FORM_strx:
--
2.30.0