[PATCH v3 13/28] Add is_optimized_out to dwarf_location class

Zoran Zaric zoran.zaric@amd.com
Thu Oct 14 09:32:20 GMT 2021


Similarly to the is_implicit_ptr_at method, the existing function
callback interface of the computed struct value, requiers a way to
check if the underlying location description describes any part as
optimized out.

gdb/ChangeLog:

        * dwarf2/expr.c (dwarf_location::is_optimized_out):
        New method.
        (dwarf_implicit::is_optimized_out): New method.
        (dwarf_register::is_optimized_out): New method.
        (dwarf_composite::is_optimized_out): New method.
---
 gdb/dwarf2/expr.c | 97 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 97 insertions(+)

diff --git a/gdb/dwarf2/expr.c b/gdb/dwarf2/expr.c
index af84710b054..1b6622d5f59 100644
--- a/gdb/dwarf2/expr.c
+++ b/gdb/dwarf2/expr.c
@@ -492,6 +492,21 @@ class dwarf_location : public dwarf_entry
     return nullptr;
   }
 
+  /* Check if location description resolves into optimized out.
+
+     The check operation is performed in the context of a FRAME.
+     BIG_ENDIAN defines the endianness of the target, BIT_SIZE is the
+     number of bits to read and BITS_TO_SKIP is a bit offset into the
+     location.  LOCATION_BIT_LIMIT is a maximum number of bits that
+     location can hold, where value zero signifies that there is
+     no such restriction.  */
+  virtual bool is_optimized_out (frame_info *frame, bool big_endian,
+				 LONGEST bits_to_skip, size_t bit_size,
+				 size_t location_bit_limit) const
+  {
+    return false;
+  }
+
 protected:
   /* Architecture of the location.  */
   gdbarch *m_arch;
@@ -666,6 +681,13 @@ class dwarf_undefined final : public dwarf_location
     *unavailable = 0;
     *optimized = 1;
   }
+
+  bool is_optimized_out (frame_info *frame, bool big_endian,
+			 LONGEST bits_to_skip, size_t bit_size,
+			 size_t location_bit_limit) const override
+  {
+    return true;
+  }
 };
 
 class dwarf_memory final : public dwarf_location
@@ -904,6 +926,10 @@ class dwarf_register final : public dwarf_location
 	      size_t location_bit_limit, bool big_endian,
 	      int *optimized, int *unavailable) const override;
 
+  bool is_optimized_out (frame_info *frame, bool big_endian,
+			 LONGEST bits_to_skip, size_t bit_size,
+			 size_t location_bit_limit) const override;
+
 private:
   /* DWARF register number.  */
   unsigned int m_regnum;
@@ -997,6 +1023,24 @@ dwarf_register::write (frame_info *frame, const gdb_byte *buf,
 		     temp_buf, optimized, unavailable);
 }
 
+bool
+dwarf_register::is_optimized_out (frame_info *frame, bool big_endian,
+				  LONGEST bits_to_skip, size_t bit_size,
+				  size_t location_bit_limit) const
+{
+  int optimized, unavailable;
+  gdb::byte_vector temp_buf (bit_size);
+
+  this->read (frame, temp_buf.data (), 0, bit_size,
+	      bits_to_skip, location_bit_limit,
+	      big_endian, &optimized, &unavailable);
+
+  if (optimized)
+    return true;
+
+  return false;
+}
+
 /* Implicit location description entry.  Describes a location
    description not found on the target but instead saved in a
    gdb-allocated buffer.  */
@@ -1025,6 +1069,13 @@ class dwarf_implicit final : public dwarf_location
     *unavailable = 0;
   }
 
+  bool is_optimized_out (frame_info *frame, bool big_endian,
+			 LONGEST bits_to_skip, size_t bit_size,
+			 size_t location_bit_limit) const override
+  {
+    return true;
+  }
+
 private:
   /* Implicit location contents as a stream of bytes in target byte-order.  */
   gdb::byte_vector m_contents;
@@ -1230,6 +1281,10 @@ class dwarf_composite final : public dwarf_location
 				LONGEST bit_offset = 0,
 				int bit_length = 0) const override;
 
+  bool is_optimized_out (frame_info *frame, bool big_endian,
+			 LONGEST bits_to_skip, size_t bit_size,
+			 size_t location_bit_limit) const override;
+
 private:
   /* Composite piece that contains a piece location
      description and it's size.  */
@@ -1497,6 +1552,48 @@ dwarf_composite::indirect_implicit_ptr (frame_info *frame, struct type *type,
   return nullptr;
 }
 
+bool
+dwarf_composite::is_optimized_out (frame_info *frame, bool big_endian,
+				   LONGEST bits_to_skip, size_t bit_size,
+				   size_t location_bit_limit) const
+{
+  ULONGEST total_bits_to_skip
+    = bits_to_skip + HOST_CHAR_BIT * m_offset + m_bit_suboffset;
+  ULONGEST remaining_bit_size = bit_size;
+  unsigned int pieces_num = m_pieces.size ();
+  unsigned int i;
+
+  /* Advance to the first non-skipped piece.  */
+  for (i = 0; i < pieces_num; i++)
+    {
+      ULONGEST piece_bit_size = m_pieces[i].size;
+
+      if (total_bits_to_skip < piece_bit_size)
+	break;
+
+      total_bits_to_skip -= piece_bit_size;
+    }
+
+  for (; i < pieces_num; i++)
+    {
+      const dwarf_location &location = *m_pieces[i].location;
+      ULONGEST piece_bit_size = m_pieces[i].size;
+      size_t this_bit_size = piece_bit_size - total_bits_to_skip;
+
+      if (this_bit_size > remaining_bit_size)
+	this_bit_size = remaining_bit_size;
+
+      if (location.is_optimized_out (frame, big_endian, total_bits_to_skip,
+				     this_bit_size, piece_bit_size))
+	return true;
+
+      remaining_bit_size -= this_bit_size;
+      total_bits_to_skip = 0;
+    }
+
+  return false;
+}
+
 struct piece_closure
 {
   /* Reference count.  */
-- 
2.17.1



More information about the Gdb-patches mailing list