]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Add is_optimized_out to dwarf_location class
authorZoran Zaric <zoran.zaric@amd.com>
Mon, 11 Oct 2021 12:26:04 +0000 (13:26 +0100)
committerZoran Zaric <zoran.zaric@amd.com>
Fri, 5 Nov 2021 11:46:38 +0000 (11:46 +0000)
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

index 185324f1d2dc7fac454ae33015d7bd307249dd10..a16c53377b705cdc636c867c36d98f6e750ab3b2 100644 (file)
@@ -483,6 +483,21 @@ public:
     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;
@@ -662,6 +677,13 @@ public:
     *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
@@ -902,6 +924,10 @@ public:
              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;
@@ -995,6 +1021,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.  */
@@ -1023,6 +1067,13 @@ public:
     *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;
@@ -1228,6 +1279,10 @@ public:
                                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.  */
@@ -1495,6 +1550,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.  */