length, buffer);
}
+class dwarf_location;
+
/* Base class that describes entries found on a DWARF expression
evaluation stack. */
virtual ~dwarf_entry () = default;
};
+using dwarf_entry_up = std::unique_ptr<dwarf_entry>;
+
/* Location description entry found on a DWARF expression evaluation
stack.
bool m_initialised = true;
};
+using dwarf_location_up = std::unique_ptr<dwarf_location>;
+
/* Value entry found on a DWARF expression evaluation stack. */
class dwarf_value final : public dwarf_entry
return unpack_long (m_type, m_contents.data ());
}
+ /* Convert DWARF value into a DWARF memory location description.
+ ARCH defines an architecture of the location described. */
+ dwarf_location_up to_location (struct gdbarch *arch) const;
+
private:
/* Value contents as a stream of bytes in target byte order. */
gdb::byte_vector m_contents;
bool m_stack;
};
+dwarf_location_up
+dwarf_value::to_location (struct gdbarch *arch) const
+{
+ LONGEST offset;
+
+ if (gdbarch_integer_to_address_p (arch))
+ offset = gdbarch_integer_to_address (arch, m_type, m_contents.data ());
+ else
+ offset = extract_unsigned_integer (m_contents.data (),
+ TYPE_LENGTH (m_type),
+ type_byte_order (m_type));
+
+ return make_unique<dwarf_memory> (arch, offset);
+}
+
/* Register location description entry. */
class dwarf_register final : public dwarf_location
/* Like the above, but return a gdb::byte_vector. */
gdb::byte_vector hex2bin (const char *hex);
+#if __cplusplus >= 201402L
+#include <memory>
+
+using std::make_unique;
+#else
+namespace gdb {
+
+/* Stolen from libstdc++ and adjusted, so probably fine license-wise. */
+template<typename _Tp, typename ... _Args>
+std::unique_ptr<_Tp>
+make_unique (_Args &&... __args)
+{
+ return std::unique_ptr<_Tp> (new _Tp (std::forward<_Args>(__args)...));
+}
+
+}
+#endif /* __cplusplus >= 201402L */
+
#endif /* COMMON_COMMON_UTILS_H */