From: Zoran Zaric Date: Wed, 24 Feb 2021 12:13:04 +0000 (+0000) Subject: Add to_value method to dwarf_location class X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b650f7fd861718e7b7feda4341d00469778a7c29;p=thirdparty%2Fbinutils-gdb.git 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. --- diff --git a/gdb/dwarf2/expr.c b/gdb/dwarf2/expr.c index 2cb93706ac4..e9e5e55ca61 100644 --- a/gdb/dwarf2/expr.c +++ b/gdb/dwarf2/expr.c @@ -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 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; + /* 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 (arch, offset); } +dwarf_value_up +dwarf_memory::to_value (struct type *type) const +{ + return make_unique (m_offset, type); +} + /* Register location description entry. */ class dwarf_register final : public dwarf_location