Add to_value method to dwarf_location class

Following the idea from the last patch this patch is adding a
conversion method from any dwarf_location derived object into
a dwarf_value object.

Currently, we only know how to convert from a memory location
description into a value, but it is resonable to expect a set
of target hooks that would let the target decide on how to do
other conversions in the future.

gdb/ChangeLog:

        * dwarf2/expr.c (dwarf_location::to_value): New method.
        (dwarf_memory::to_value): New method.
        (ill_formed_expression): New function.
This commit is contained in:
Zoran Zaric
2021-02-24 12:13:04 +00:00
committed by Zoran Zaric
parent 851fa76da8
commit b650f7fd86

View File

@@ -90,6 +90,14 @@ bits_to_bytes (ULONGEST start, ULONGEST n_bits)
return (start % HOST_CHAR_BIT + n_bits + HOST_CHAR_BIT - 1) / HOST_CHAR_BIT;
}
/* Throw an exception about the invalid DWARF expression. */
static void ATTRIBUTE_NORETURN
ill_formed_expression ()
{
error (_("Ill-formed DWARF expression"));
}
/* See expr.h. */
CORE_ADDR
@@ -272,6 +280,7 @@ write_to_memory (CORE_ADDR address, const gdb_byte *buffer,
}
class dwarf_location;
class dwarf_value;
/* Base class that describes entries found on a DWARF expression
evaluation stack. */
@@ -321,6 +330,16 @@ public:
m_initialised = initialised;
};
/* Convert DWARF entry into a DWARF value. TYPE defines a desired type of
the returned DWARF value if it doesn't already have one.
If the conversion from that location description kind to a value is not
supported, throw an error. */
virtual std::unique_ptr<dwarf_value> to_value (struct type *type) const
{
ill_formed_expression ();
}
protected:
/* Architecture of the location. */
gdbarch *m_arch;
@@ -391,6 +410,8 @@ private:
struct type *m_type;
};
using dwarf_value_up = std::unique_ptr<dwarf_value>;
/* Undefined location description entry. This is a special location
description type that describes the location description that is
not known. */
@@ -415,6 +436,8 @@ public:
m_stack = stack;
};
dwarf_value_up to_value (struct type *type) const override;
private:
/* True if the location belongs to a stack memory region. */
bool m_stack;
@@ -435,6 +458,12 @@ dwarf_value::to_location (struct gdbarch *arch) const
return make_unique<dwarf_memory> (arch, offset);
}
dwarf_value_up
dwarf_memory::to_value (struct type *type) const
{
return make_unique<dwarf_value> (m_offset, type);
}
/* Register location description entry. */
class dwarf_register final : public dwarf_location