/* Abstraction of GNU v3 abi.
Contributed by Jim Blandy <jimb@redhat.com>
- Copyright (C) 2001-2015 Free Software Foundation, Inc.
+ Copyright (C) 2001-2017 Free Software Foundation, Inc.
This file is part of GDB.
the alignment that type requires, and then use that here. */
/* Build the field list. */
- field_list = xmalloc (sizeof (struct field [4]));
- memset (field_list, 0, sizeof (struct field [4]));
+ field_list = XCNEWVEC (struct field, 4);
field = &field_list[0];
offset = 0;
static struct type *
vtable_ptrdiff_type (struct gdbarch *gdbarch)
{
- struct type *vtable_type = gdbarch_data (gdbarch, vtable_type_gdbarch_data);
+ struct type *vtable_type
+ = (struct type *) gdbarch_data (gdbarch, vtable_type_gdbarch_data);
/* The "offset_to_top" field has the appropriate (ptrdiff_t) type. */
return TYPE_FIELD_TYPE (vtable_type, vtable_field_offset_to_top);
static int
vtable_address_point_offset (struct gdbarch *gdbarch)
{
- struct type *vtable_type = gdbarch_data (gdbarch, vtable_type_gdbarch_data);
+ struct type *vtable_type
+ = (struct type *) gdbarch_data (gdbarch, vtable_type_gdbarch_data);
return (TYPE_FIELD_BITPOS (vtable_type, vtable_field_virtual_functions)
/ TARGET_CHAR_BIT);
gnuv3_get_vtable (struct gdbarch *gdbarch,
struct type *container_type, CORE_ADDR container_addr)
{
- struct type *vtable_type = gdbarch_data (gdbarch,
- vtable_type_gdbarch_data);
+ struct type *vtable_type
+ = (struct type *) gdbarch_data (gdbarch, vtable_type_gdbarch_data);
struct type *vtable_pointer_type;
struct value *vtable_pointer;
CORE_ADDR vtable_address;
static struct type *
gnuv3_rtti_type (struct value *value,
- int *full_p, int *top_p, int *using_enc_p)
+ int *full_p, LONGEST *top_p, int *using_enc_p)
{
struct gdbarch *gdbarch;
struct type *values_type = check_typedef (value_type (value));
const char *class_name;
struct type *run_time_type;
LONGEST offset_to_top;
- char *atsign;
+ const char *atsign;
/* We only have RTTI for class objects. */
if (TYPE_CODE (values_type) != TYPE_CODE_STRUCT)
return NULL;
- /* Java doesn't have RTTI following the C++ ABI. */
- if (TYPE_CPLUS_REALLY_JAVA (values_type))
- return NULL;
-
/* Determine architecture. */
gdbarch = get_type_arch (values_type);
{
char *copy;
- copy = alloca (atsign - class_name + 1);
+ copy = (char *) alloca (atsign - class_name + 1);
memcpy (copy, class_name, atsign - class_name);
copy[atsign - class_name] = '\0';
class_name = copy;
static int
gnuv3_baseclass_offset (struct type *type, int index,
- const bfd_byte *valaddr, int embedded_offset,
+ const bfd_byte *valaddr, LONGEST embedded_offset,
CORE_ADDR address, const struct value *val)
{
struct gdbarch *gdbarch;
ptr_type = builtin_type (gdbarch)->builtin_data_ptr;
/* If it isn't a virtual base, this is easy. The offset is in the
- type definition. Likewise for Java, which doesn't really have
- virtual inheritance in the C++ sense. */
- if (!BASETYPE_VIA_VIRTUAL (type, index) || TYPE_CPLUS_REALLY_JAVA (type))
+ type definition. */
+ if (!BASETYPE_VIA_VIRTUAL (type, index))
return TYPE_BASECLASS_BITPOS (type, index) / 8;
/* To access a virtual base, we need to use the vbase offset stored in
static hashval_t
hash_value_and_voffset (const void *p)
{
- const struct value_and_voffset *o = p;
+ const struct value_and_voffset *o = (const struct value_and_voffset *) p;
return value_address (o->value) + value_embedded_offset (o->value);
}
static int
eq_value_and_voffset (const void *a, const void *b)
{
- const struct value_and_voffset *ova = a;
- const struct value_and_voffset *ovb = b;
+ const struct value_and_voffset *ova = (const struct value_and_voffset *) a;
+ const struct value_and_voffset *ovb = (const struct value_and_voffset *) b;
return (value_address (ova->value) + value_embedded_offset (ova->value)
== value_address (ovb->value) + value_embedded_offset (ovb->value));
static int
compare_value_and_voffset (const void *a, const void *b)
{
- const struct value_and_voffset * const *ova = a;
+ const struct value_and_voffset * const *ova
+ = (const struct value_and_voffset * const *) a;
CORE_ADDR addra = (value_address ((*ova)->value)
+ value_embedded_offset ((*ova)->value));
- const struct value_and_voffset * const *ovb = b;
+ const struct value_and_voffset * const *ovb
+ = (const struct value_and_voffset * const *) b;
CORE_ADDR addrb = (value_address ((*ovb)->value)
+ value_embedded_offset ((*ovb)->value));
search_vo.value = value;
slot = htab_find_slot (offset_hash, &search_vo, INSERT);
if (*slot)
- current_vo = *slot;
+ current_vo = (struct value_and_voffset *) *slot;
else
{
current_vo = XNEW (struct value_and_voffset);
struct type *type;
struct value *vtable;
struct value_print_options opts;
- htab_t offset_hash;
struct cleanup *cleanup;
VEC (value_and_voffset_p) *result_vec = NULL;
struct value_and_voffset *iter;
return;
}
- offset_hash = htab_create_alloc (1, hash_value_and_voffset,
- eq_value_and_voffset,
- xfree, xcalloc, xfree);
- cleanup = make_cleanup_htab_delete (offset_hash);
- make_cleanup (VEC_cleanup (value_and_voffset_p), &result_vec);
+ htab_up offset_hash (htab_create_alloc (1, hash_value_and_voffset,
+ eq_value_and_voffset,
+ xfree, xcalloc, xfree));
+ cleanup = make_cleanup (VEC_cleanup (value_and_voffset_p), &result_vec);
- compute_vtable_size (offset_hash, &result_vec, value);
+ compute_vtable_size (offset_hash.get (), &result_vec, value);
qsort (VEC_address (value_and_voffset_p, result_vec),
VEC_length (value_and_voffset_p, result_vec),
struct type *char_ptr_type
= make_pointer_type (make_cv_type (1, 0, char_type, NULL), NULL);
- field_list = xmalloc (sizeof (struct field [2]));
- memset (field_list, 0, sizeof (struct field [2]));
+ field_list = XCNEWVEC (struct field, 2);
field = &field_list[0];
offset = 0;
struct symbol *typeinfo;
struct type *typeinfo_type;
- typeinfo = lookup_symbol ("std::type_info", NULL, STRUCT_DOMAIN, NULL);
+ typeinfo = lookup_symbol ("std::type_info", NULL, STRUCT_DOMAIN,
+ NULL).symbol;
if (typeinfo == NULL)
- typeinfo_type = gdbarch_data (gdbarch, std_type_info_gdbarch_data);
+ typeinfo_type
+ = (struct type *) gdbarch_data (gdbarch, std_type_info_gdbarch_data);
else
typeinfo_type = SYMBOL_TYPE (typeinfo);
struct gdbarch *gdbarch;
struct cleanup *cleanup;
struct value *result;
- char *type_name, *canonical;
+ std::string type_name, 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
gdbarch = get_type_arch (type);
type_name = type_to_string (type);
- if (type_name == NULL)
+ if (type_name.empty ())
error (_("cannot find typeinfo for unnamed type"));
- cleanup = make_cleanup (xfree, type_name);
/* We need to canonicalize the type name here, because we do lookups
using the demangled name, and so we must match the format it
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);
- if (canonical != NULL)
- {
- make_cleanup (xfree, canonical);
- type_name = canonical;
- }
+ canonical = cp_canonicalize_string (type_name.c_str ());
+ if (!canonical.empty ())
+ type_name = canonical;
typeinfo_type = gnuv3_get_typeid_type (gdbarch);
vtable = gnuv3_get_vtable (gdbarch, type, address);
if (vtable == NULL)
- error (_("cannot find typeinfo for object of type '%s'"), type_name);
+ error (_("cannot find typeinfo for object of type '%s'"),
+ type_name.c_str ());
typeinfo_value = value_field (vtable, vtable_field_type_info);
result = value_ind (value_cast (make_pointer_type (typeinfo_type, NULL),
typeinfo_value));
}
else
{
- char *sym_name;
- struct bound_minimal_symbol minsym;
-
- sym_name = concat ("typeinfo for ", type_name, (char *) NULL);
- make_cleanup (xfree, sym_name);
- minsym = lookup_minimal_symbol (sym_name, NULL, NULL);
+ std::string sym_name = std::string ("typeinfo for ") + type_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);
+ error (_("could not find typeinfo symbol for '%s'"), type_name.c_str ());
result = value_at_lazy (typeinfo_type, BMSYMBOL_VALUE_ADDRESS (minsym));
}
- do_cleanups (cleanup);
return result;
}
/* Implement the 'get_typename_from_type_info' method. */
-static char *
+static std::string
gnuv3_get_typename_from_type_info (struct value *type_info_ptr)
{
struct gdbarch *gdbarch = get_type_arch (value_type (type_info_ptr));
/* Strip off @plt and version suffixes. */
atsign = strchr (class_name, '@');
if (atsign != NULL)
- return savestring (class_name, atsign - class_name);
- return xstrdup (class_name);
+ return std::string (class_name, atsign - class_name);
+ return class_name;
}
/* Implement the 'get_type_from_type_info' method. */
static struct type *
gnuv3_get_type_from_type_info (struct value *type_info_ptr)
{
- char *type_name;
- struct cleanup *cleanup;
- struct value *type_val;
- struct expression *expr;
- struct type *result;
-
- type_name = gnuv3_get_typename_from_type_info (type_info_ptr);
- cleanup = make_cleanup (xfree, type_name);
-
/* We have to parse the type name, since in general there is not a
symbol for a type. This is somewhat bogus since there may be a
mis-parse. Another approach might be to re-use the demangler's
internal form to reconstruct the type somehow. */
-
- expr = parse_expression (type_name);
- make_cleanup (xfree, expr);
-
- type_val = evaluate_type (expr);
- result = value_type (type_val);
-
- do_cleanups (cleanup);
- return result;
+ std::string type_name = gnuv3_get_typename_from_type_info (type_info_ptr);
+ expression_up expr (parse_expression (type_name.c_str ()));
+ struct value *type_val = evaluate_type (expr.get ());
+ return value_type (type_val);
}
/* Determine if we are currently in a C++ thunk. If so, get the address