gdb/dwarf: few fixes for handling DW_FORM_{rng,loc}listx
authorSimon Marchi <simon.marchi@efficios.com>
Tue, 2 Feb 2021 15:40:51 +0000 (10:40 -0500)
committerSimon Marchi <simon.marchi@polymtl.ca>
Tue, 2 Feb 2021 15:40:51 +0000 (10:40 -0500)
We hit an assertion when loading the binary from PR 26813.  When fixing
it, execution goes a up bit further but then hits another assert, and
another, and another.  With these fours fixes, I am able to load the
binary and get to the prompt.  An error is shown (index pointing outside
of the section), because the DW_FORM_rnglistx attribute is not read
correctly, but that one is taken care of by the next patch.

The four fixes are:

- attribute::form_requires_reprocessing needs to handle forms
  DW_FORM_rnglistx and DW_FORM_loclistx, because set_unsigned_reprocess
  is called for them in read_attribute_value.

- read_attribute_reprocess must call set_unsigned for them, not
  set_address.  The parameter of set_address is a CORE_ADDR, meaning
  it's for program addresses.  Post-reprocess, DW_FORM_rnglistx and
  DW_FORM_loclistx are offsets into their respective sections
  (.debug_rnglists and .debug_loclists).  set_unsigned is the current
  attribute value setter that fits the best.  But perhaps we should have
  a setter that takes a sect_offset?

- read_attribute_process must call as_unsigned_reprocess instead of
  as_unsigned to get the pre-reprocess value, otherwise we hit the
  assert inside as_unsigned that makes sure the attribute doesn't need
  reprocessing.

- attribute::set_unsigned needs to clear the requires_reprocessing flag,
  otherwise it stays set when reprocessing DW_FORM_rnglistx and
  DW_FORM_loclistx attributes.

There's another assert that we hit once the next patch is applied, but
since it's in the same vein as the changes in this patch, I included it
in this patch:

- attribute::form_is_unsigned must handle form DW_FORM_loclistx,
  otherwise we hit the assert when trying to call set_unsigned for an
  attribute of this form.  DW_FORM_rnglistx is already handled.

gdb/ChangeLog:

PR gdb/26813
* dwarf2/attribute.h (struct attribute) <set_unsigned>: Clear
requires_reprocessing flag.
* dwarf2/attribute.c (attribute::form_is_unsigned): Handle
DW_FORM_loclistx.
(attribute::form_requires_reprocessing): Handle DW_FORM_rnglistx
and DW_FORM_loclistx.
* dwarf2/read.c (read_attribute_reprocess): Use set_unsigned
instead of set_address for DW_FORM_loclistx and
DW_FORM_rnglistx.

Change-Id: I06c156fa3913ca98e4e39085f4ef171645b4bc1e

gdb/ChangeLog
gdb/dwarf2/attribute.c
gdb/dwarf2/attribute.h
gdb/dwarf2/read.c

index b420a941184daf9d3a9fc19d65f6ffe1d123818b..4f9944aa0b6755a4caa3783074fe0b3e6de6b7a1 100644 (file)
@@ -1,3 +1,16 @@
+2021-02-02  Simon Marchi  <simon.marchi@efficios.com>
+
+       PR gdb/26813
+       * dwarf2/attribute.h (struct attribute) <set_unsigned>: Clear
+       requires_reprocessing flag.
+       * dwarf2/attribute.c (attribute::form_is_unsigned): Handle
+       DW_FORM_loclistx.
+       (attribute::form_requires_reprocessing): Handle DW_FORM_rnglistx
+       and DW_FORM_loclistx.
+       * dwarf2/read.c (read_attribute_reprocess): Use set_unsigned
+       instead of set_address for DW_FORM_loclistx and
+       DW_FORM_rnglistx.
+
 2021-02-02  Simon Marchi  <simon.marchi@efficios.com>
 
        * dwarf2/read.c (read_loclist_index): Remove bound check for
index 479261030c5df335950b69c761e16b59e644a38a..b4f188a096e1c991e161eeb44e127c7d3ed154e5 100644 (file)
@@ -179,6 +179,7 @@ attribute::form_is_unsigned () const
          || form == DW_FORM_flag_present
          || form == DW_FORM_udata
          || form == DW_FORM_rnglistx
+         || form == DW_FORM_loclistx
          || form == DW_FORM_ref1
          || form == DW_FORM_ref2
          || form == DW_FORM_ref4
@@ -197,7 +198,9 @@ attribute::form_requires_reprocessing () const
          || form == DW_FORM_strx4
          || form == DW_FORM_GNU_str_index
          || form == DW_FORM_addrx
-         || form == DW_FORM_GNU_addr_index);
+         || form == DW_FORM_GNU_addr_index
+         || form == DW_FORM_rnglistx
+         || form == DW_FORM_loclistx);
 }
 
 /* See attribute.h.  */
index a3ff9b0eb9c6b0041cf531b36562b9e448b3afe1..56776d64ed345d2cb2d5aa44071a176a12f6881f 100644 (file)
@@ -223,6 +223,7 @@ struct attribute
   {
     gdb_assert (form_is_unsigned ());
     u.unsnd = unsnd;
+    requires_reprocessing = 0;
   }
 
   /* Temporarily set this attribute to an unsigned integer.  This is
index ee0f8bec4465ce1b87994447c4ac73b5afc502ab..4fe4f94a6eef46fa0f2587b21d2b08992f953ffd 100644 (file)
@@ -20315,10 +20315,20 @@ read_attribute_reprocess (const struct die_reader_specs *reader,
                                            attr->as_unsigned_reprocess ()));
        break;
       case DW_FORM_loclistx:
-       attr->set_address (read_loclist_index (cu, attr->as_unsigned ()));
-        break;
+       {
+         CORE_ADDR loclists_sect_off
+           = read_loclist_index (cu, attr->as_unsigned_reprocess ());
+
+         attr->set_unsigned (loclists_sect_off);
+       }
+       break;
       case DW_FORM_rnglistx:
-       attr->set_address (read_rnglist_index (cu, attr->as_unsigned (), tag));
+       {
+         CORE_ADDR rnglists_sect_off
+           = read_rnglist_index (cu, attr->as_unsigned_reprocess (), tag);
+
+         attr->set_unsigned (rnglists_sect_off);
+       }
        break;
       case DW_FORM_strx:
       case DW_FORM_strx1:
This page took 0.037226 seconds and 4 git commands to generate.