[PATCH 28/43] Add is_implicit_ptr_at method to dwarf_location

Zoran Zaric via Gdb-patches
2021-03-01T14:47:29Z

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 | 51 +++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 51 insertions(+)

diff --git a/gdb/dwarf2/expr.c b/gdb/dwarf2/expr.c
index 7e5ba5d636b..5de75f570aa 100644
--- a/gdb/dwarf2/expr.c
+++ b/gdb/dwarf2/expr.c
@@ -489,6 +489,14 @@ class dwarf_location : public dwarf_entry
LONGEST bits_to_skip, size_t bit_size,
size_t location_bit_limit);

+ /* 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. */
struct gdbarch *m_arch;
@@ -1137,6 +1145,11 @@ class dwarf_implicit_pointer : public dwarf_location
size_t location_bit_limit) 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;
@@ -1224,6 +1237,8 @@ class dwarf_composite : public dwarf_location
LONGEST bits_to_skip, size_t bit_size,
size_t location_bit_limit) 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. */
@@ -1422,6 +1437,42 @@ dwarf_composite::write_to_gdb_value (struct frame_info *frame,
}
}

+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++)
+ {
+ ULONGEST read_bit_length = m_pieces[i].m_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 (!m_pieces[i].m_location->is_implicit_ptr_at (total_bit_offset,
+ read_bit_length))
+ return false;
+
+ total_bit_offset = 0;
+ total_bit_length -= read_bit_length;
+ }
+
+ return true;
+}
+
struct piece_closure
{
/* Reference count. */
--
2.17.1