#include "typeprint.h"
#include <algorithm>
#include "cli/cli-style.h"
+#include "dwarf2/loc.h"
static struct cp_abi_ops gnu_v3_abi_ops;
gdb_assert (field == (field_list + 4));
t = arch_type (arch, TYPE_CODE_STRUCT, offset * TARGET_CHAR_BIT, NULL);
- TYPE_NFIELDS (t) = field - field_list;
- TYPE_FIELDS (t) = field_list;
- TYPE_NAME (t) = "gdb_gnu_v3_abi_vtable";
+ t->set_num_fields (field - field_list);
+ t->set_fields (field_list);
+ t->set_name ("gdb_gnu_v3_abi_vtable");
INIT_CPLUS_SPECIFIC (t);
return make_type_with_address_space (t, TYPE_INSTANCE_FLAG_CODE_SPACE);
int fieldnum, fieldelem;
type = check_typedef (type);
- gdb_assert (TYPE_CODE (type) == TYPE_CODE_STRUCT
- || TYPE_CODE (type) == TYPE_CODE_UNION);
+ gdb_assert (type->code () == TYPE_CODE_STRUCT
+ || type->code () == TYPE_CODE_UNION);
- if (TYPE_CODE (type) == TYPE_CODE_UNION)
+ if (type->code () == TYPE_CODE_UNION)
return 0;
if (TYPE_CPLUS_DYNAMIC (type))
CORE_ADDR vtable_address;
container_type = check_typedef (container_type);
- gdb_assert (TYPE_CODE (container_type) == TYPE_CODE_STRUCT);
+ gdb_assert (container_type->code () == TYPE_CODE_STRUCT);
/* If this type does not have a virtual table, don't read the first
field. */
const char *atsign;
/* We only have RTTI for dynamic class objects. */
- if (TYPE_CODE (values_type) != TYPE_CODE_STRUCT
+ if (values_type->code () != TYPE_CODE_STRUCT
|| !gnuv3_dynamic_class (values_type))
return NULL;
struct gdbarch *gdbarch;
/* Some simple sanity checks. */
- if (TYPE_CODE (values_type) != TYPE_CODE_STRUCT)
+ if (values_type->code () != TYPE_CODE_STRUCT)
error (_("Only classes can have virtual functions."));
/* Determine architecture. */
if (!BASETYPE_VIA_VIRTUAL (type, index))
return TYPE_BASECLASS_BITPOS (type, index) / 8;
+ /* If we have a DWARF expression for the offset, evaluate it. */
+ if (TYPE_FIELD_LOC_KIND (type, index) == FIELD_LOC_KIND_DWARF_BLOCK)
+ {
+ struct dwarf2_property_baton baton;
+ baton.property_type
+ = lookup_pointer_type (TYPE_FIELD_TYPE (type, index));
+ baton.locexpr = *TYPE_FIELD_DWARF_BLOCK (type, index);
+
+ struct dynamic_prop prop;
+ prop.kind = PROP_LOCEXPR;
+ prop.data.baton = &baton;
+
+ struct property_addr_info addr_stack;
+ addr_stack.type = type;
+ /* Note that we don't set "valaddr" here. Doing so causes
+ regressions. FIXME. */
+ addr_stack.addr = address + embedded_offset;
+ addr_stack.next = nullptr;
+
+ CORE_ADDR result;
+ if (dwarf2_evaluate_property (&prop, nullptr, &addr_stack, &result,
+ true))
+ return (int) (result - addr_stack.addr);
+ }
+
/* To access a virtual base, we need to use the vbase offset stored in
our vtable. Recent GCC versions provide this information. If it isn't
available, we could get what we needed from RTTI, or from drawing the
void **slot;
struct value_and_voffset search_vo, *current_vo;
- gdb_assert (TYPE_CODE (type) == TYPE_CODE_STRUCT);
+ gdb_assert (type->code () == TYPE_CODE_STRUCT);
/* If the object is not dynamic, then we are done; as it cannot have
dynamic base types either. */
value = coerce_ref (value);
type = check_typedef (value_type (value));
- if (TYPE_CODE (type) == TYPE_CODE_PTR)
+ if (type->code () == TYPE_CODE_PTR)
{
value = value_ind (value);
type = check_typedef (value_type (value));
gdbarch = get_type_arch (type);
vtable = NULL;
- if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
+ if (type->code () == TYPE_CODE_STRUCT)
vtable = gnuv3_get_vtable (gdbarch, type,
value_as_address (value_addr (value)));
gdb_assert (field == (field_list + 2));
t = arch_type (arch, TYPE_CODE_STRUCT, offset * TARGET_CHAR_BIT, NULL);
- TYPE_NFIELDS (t) = field - field_list;
- TYPE_FIELDS (t) = field_list;
- TYPE_NAME (t) = "gdb_gnu_v3_type_info";
+ t->set_num_fields (field - field_list);
+ t->set_fields (field_list);
+ t->set_name ("gdb_gnu_v3_type_info");
INIT_CPLUS_SPECIFIC (t);
return t;
struct type *type;
struct gdbarch *gdbarch;
struct value *result;
- std::string type_name, canonical;
+ std::string type_name;
+ gdb::unique_xmalloc_ptr<char> canonical;
/* We have to handle values a bit trickily here, to allow this code
to work properly with non_lvalue values that are really just
/* In the non_lvalue case, a reference might have slipped through
here. */
- if (TYPE_CODE (type) == TYPE_CODE_REF)
+ if (type->code () == TYPE_CODE_REF)
type = check_typedef (TYPE_TARGET_TYPE (type));
/* Ignore top-level cv-qualifiers. */
uses. E.g., GDB tends to use "const char *" as a type name, but
the demangler uses "char const *". */
canonical = cp_canonicalize_string (type_name.c_str ());
- if (!canonical.empty ())
- type_name = canonical;
+ const char *name = (canonical == nullptr
+ ? type_name.c_str ()
+ : canonical.get ());
typeinfo_type = gnuv3_get_typeid_type (gdbarch);
/* We check for lval_memory because in the "typeid (type-id)" case,
the type is passed via a not_lval value object. */
- if (TYPE_CODE (type) == TYPE_CODE_STRUCT
+ if (type->code () == TYPE_CODE_STRUCT
&& value_lval_const (value) == lval_memory
&& gnuv3_dynamic_class (type))
{
vtable = gnuv3_get_vtable (gdbarch, type, address);
if (vtable == NULL)
error (_("cannot find typeinfo for object of type '%s'"),
- type_name.c_str ());
+ name);
typeinfo_value = value_field (vtable, vtable_field_type_info);
result = value_ind (value_cast (make_pointer_type (typeinfo_type, NULL),
typeinfo_value));
}
else
{
- std::string sym_name = std::string ("typeinfo for ") + type_name;
+ std::string sym_name = std::string ("typeinfo for ") + name;
bound_minimal_symbol minsym
= lookup_minimal_symbol (sym_name.c_str (), NULL, NULL);
if (minsym.minsym == NULL)
- error (_("could not find typeinfo symbol for '%s'"), type_name.c_str ());
+ error (_("could not find typeinfo symbol for '%s'"), name);
result = value_at_lazy (typeinfo_type, BMSYMBOL_VALUE_ADDRESS (minsym));
}
type_code expected)
{
/* The method should take at least two arguments... */
- if (TYPE_NFIELDS (method_type) < 2)
+ if (method_type->num_fields () < 2)
return false;
/* ...and the second argument should be the same as the class
type, with the expected type code... */
struct type *arg_type = TYPE_FIELD_TYPE (method_type, 1);
- if (TYPE_CODE (arg_type) != expected)
+ if (arg_type->code () != expected)
return false;
struct type *target = check_typedef (TYPE_TARGET_TYPE (arg_type));
/* ...and if any of the remaining arguments don't have a default value
then this is not a copy or move constructor, but just a
constructor. */
- for (int i = 2; i < TYPE_NFIELDS (method_type); i++)
+ for (int i = 2; i < method_type->num_fields (); i++)
{
arg_type = TYPE_FIELD_TYPE (method_type, i);
/* FIXME aktemur/2019-10-31: As of this date, neither
type = check_typedef (type);
/* Start with the default values. */
- struct language_pass_by_ref_info info
- = default_pass_by_reference (type);
+ struct language_pass_by_ref_info info;
bool has_cc_attr = false;
bool is_pass_by_value = false;
definition_style mctor_def = DOES_NOT_EXIST_IN_SOURCE;
/* We're only interested in things that can have methods. */
- if (TYPE_CODE (type) != TYPE_CODE_STRUCT
- && TYPE_CODE (type) != TYPE_CODE_UNION)
+ if (type->code () != TYPE_CODE_STRUCT
+ && type->code () != TYPE_CODE_UNION)
return info;
/* The compiler may have emitted the calling convention attribute.
are constructed whenever this class is. We do not need to worry
about recursive loops here, since we are only looking at members
of complete class type. Also ignore any static members. */
- for (fieldnum = 0; fieldnum < TYPE_NFIELDS (type); fieldnum++)
- if (!field_is_static (&TYPE_FIELD (type, fieldnum)))
+ for (fieldnum = 0; fieldnum < type->num_fields (); fieldnum++)
+ if (!field_is_static (&type->field (fieldnum)))
{
struct type *field_type = TYPE_FIELD_TYPE (type, fieldnum);
/* For arrays, make the decision based on the element type. */
- if (TYPE_CODE (field_type) == TYPE_CODE_ARRAY)
+ if (field_type->code () == TYPE_CODE_ARRAY)
field_type = check_typedef (TYPE_TARGET_TYPE (field_type));
struct language_pass_by_ref_info field_info