]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Add is_implicit_ptr_at method to dwarf_location
authorZoran Zaric <Zoran.Zaric@amd.com>
Wed, 24 Feb 2021 17:11:56 +0000 (17:11 +0000)
committerZoran Zaric <zoran.zaric@amd.com>
Fri, 5 Nov 2021 11:46:38 +0000 (11:46 +0000)
Another expectation of the existing function callback interface of the
computed struct value is to check if a specific part (on a given offset
of a given length) of an underlying location description is an implicit
pointer location description.

To satisfy this expectation a new is_implicit_ptr_at has been added.

gdb/ChangeLog:

        * dwarf2/expr.c (dwarf_location::is_implicit_ptr_at):
        New method.
        (dwarf_implicit_pointer::is_implicit_ptr_at): New method.
        (dwarf_composite::is_implicit_ptr_at): New method.

gdb/dwarf2/expr.c

index b2fb0099b0e78fd460d5c1a758261ef7c26f8b84..a933ca2797de89b339c49bc30217c8ac87fa77d3 100644 (file)
@@ -457,6 +457,14 @@ public:
                                   LONGEST bits_to_skip, size_t bit_size,
                                   size_t location_bit_limit) const;
 
+  /* Check if a given DWARF location description contains an implicit
+     pointer location description of a BIT_LENGTH size on a given
+     BIT_OFFSET offset.  */
+  virtual bool is_implicit_ptr_at (LONGEST bit_offset, int bit_length) const
+  {
+     return false;
+  }
+
 protected:
   /* Architecture of the location.  */
   gdbarch *m_arch;
@@ -1088,6 +1096,11 @@ public:
                           size_t location_bit_limit) const override
   {}
 
+  bool is_implicit_ptr_at (LONGEST bit_offset, int bit_length) const override
+  {
+     return true;
+  }
+
 private:
   /* Per object file data of the implicit pointer.  */
   dwarf2_per_objfile *m_per_objfile;
@@ -1174,6 +1187,8 @@ public:
                           LONGEST bits_to_skip, size_t bit_size,
                           size_t location_bit_limit) const override;
 
+  bool is_implicit_ptr_at (LONGEST bit_offset, int bit_length) const override;
+
 private:
   /* Composite piece that contains a piece location
      description and it's size.  */
@@ -1370,6 +1385,43 @@ dwarf_composite::write_to_gdb_value (frame_info *frame, struct value *value,
     }
 }
 
+bool
+dwarf_composite::is_implicit_ptr_at (LONGEST bit_offset, int bit_length) const
+{
+  /* Advance to the first non-skipped piece.  */
+  unsigned int pieces_num = m_pieces.size ();
+  LONGEST total_bit_offset = bit_offset;
+  LONGEST total_bit_length = bit_length;
+
+  total_bit_offset += HOST_CHAR_BIT * m_offset + m_bit_suboffset;
+
+  for (unsigned int i = 0; i < pieces_num && total_bit_length != 0; i++)
+    {
+      const piece &piece = m_pieces[i];
+      ULONGEST read_bit_length = piece.size;
+
+      if (total_bit_offset >= read_bit_length)
+       {
+         total_bit_offset -= read_bit_length;
+         continue;
+       }
+
+      read_bit_length -= total_bit_offset;
+
+      if (total_bit_length < read_bit_length)
+       read_bit_length = total_bit_length;
+
+      if (piece.location->is_implicit_ptr_at (total_bit_offset,
+                                             read_bit_length))
+       return true;
+
+      total_bit_offset = 0;
+      total_bit_length -= read_bit_length;
+    }
+
+    return false;
+}
+
 struct piece_closure
 {
   /* Reference count.  */