15796c8dcSSimon Schubert /* Abstraction of GNU v2 abi.
25796c8dcSSimon Schubert
3*ef5ccd6cSJohn Marino Copyright (C) 2001-2013 Free Software Foundation, Inc.
45796c8dcSSimon Schubert
55796c8dcSSimon Schubert Contributed by Daniel Berlin <dberlin@redhat.com>
65796c8dcSSimon Schubert
75796c8dcSSimon Schubert This file is part of GDB.
85796c8dcSSimon Schubert
95796c8dcSSimon Schubert This program is free software; you can redistribute it and/or modify
105796c8dcSSimon Schubert it under the terms of the GNU General Public License as published by
115796c8dcSSimon Schubert the Free Software Foundation; either version 3 of the License, or
125796c8dcSSimon Schubert (at your option) any later version.
135796c8dcSSimon Schubert
145796c8dcSSimon Schubert This program is distributed in the hope that it will be useful,
155796c8dcSSimon Schubert but WITHOUT ANY WARRANTY; without even the implied warranty of
165796c8dcSSimon Schubert MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
175796c8dcSSimon Schubert GNU General Public License for more details.
185796c8dcSSimon Schubert
195796c8dcSSimon Schubert You should have received a copy of the GNU General Public License
205796c8dcSSimon Schubert along with this program. If not, see <http://www.gnu.org/licenses/>. */
215796c8dcSSimon Schubert
225796c8dcSSimon Schubert #include "defs.h"
235796c8dcSSimon Schubert #include "gdb_string.h"
245796c8dcSSimon Schubert #include "symtab.h"
255796c8dcSSimon Schubert #include "gdbtypes.h"
265796c8dcSSimon Schubert #include "value.h"
275796c8dcSSimon Schubert #include "demangle.h"
28a45ae5f8SJohn Marino #include "gdb-demangle.h"
295796c8dcSSimon Schubert #include "cp-abi.h"
305796c8dcSSimon Schubert #include "cp-support.h"
31c50c785cSJohn Marino #include "exceptions.h"
325796c8dcSSimon Schubert
335796c8dcSSimon Schubert #include <ctype.h>
345796c8dcSSimon Schubert
355796c8dcSSimon Schubert struct cp_abi_ops gnu_v2_abi_ops;
365796c8dcSSimon Schubert
375796c8dcSSimon Schubert static int vb_match (struct type *, int, struct type *);
385796c8dcSSimon Schubert
395796c8dcSSimon Schubert static enum dtor_kinds
gnuv2_is_destructor_name(const char * name)405796c8dcSSimon Schubert gnuv2_is_destructor_name (const char *name)
415796c8dcSSimon Schubert {
425796c8dcSSimon Schubert if ((name[0] == '_' && is_cplus_marker (name[1]) && name[2] == '_')
435796c8dcSSimon Schubert || strncmp (name, "__dt__", 6) == 0)
445796c8dcSSimon Schubert return complete_object_dtor;
455796c8dcSSimon Schubert else
465796c8dcSSimon Schubert return 0;
475796c8dcSSimon Schubert }
485796c8dcSSimon Schubert
495796c8dcSSimon Schubert static enum ctor_kinds
gnuv2_is_constructor_name(const char * name)505796c8dcSSimon Schubert gnuv2_is_constructor_name (const char *name)
515796c8dcSSimon Schubert {
525796c8dcSSimon Schubert if ((name[0] == '_' && name[1] == '_'
535796c8dcSSimon Schubert && (isdigit (name[2]) || strchr ("Qt", name[2])))
545796c8dcSSimon Schubert || strncmp (name, "__ct__", 6) == 0)
555796c8dcSSimon Schubert return complete_object_ctor;
565796c8dcSSimon Schubert else
575796c8dcSSimon Schubert return 0;
585796c8dcSSimon Schubert }
595796c8dcSSimon Schubert
605796c8dcSSimon Schubert static int
gnuv2_is_vtable_name(const char * name)615796c8dcSSimon Schubert gnuv2_is_vtable_name (const char *name)
625796c8dcSSimon Schubert {
635796c8dcSSimon Schubert return (((name)[0] == '_'
645796c8dcSSimon Schubert && (((name)[1] == 'V' && (name)[2] == 'T')
655796c8dcSSimon Schubert || ((name)[1] == 'v' && (name)[2] == 't'))
665796c8dcSSimon Schubert && is_cplus_marker ((name)[3])) ||
675796c8dcSSimon Schubert ((name)[0] == '_' && (name)[1] == '_'
685796c8dcSSimon Schubert && (name)[2] == 'v' && (name)[3] == 't' && (name)[4] == '_'));
695796c8dcSSimon Schubert }
705796c8dcSSimon Schubert
715796c8dcSSimon Schubert static int
gnuv2_is_operator_name(const char * name)725796c8dcSSimon Schubert gnuv2_is_operator_name (const char *name)
735796c8dcSSimon Schubert {
745796c8dcSSimon Schubert return strncmp (name, "operator", 8) == 0;
755796c8dcSSimon Schubert }
765796c8dcSSimon Schubert
775796c8dcSSimon Schubert
785796c8dcSSimon Schubert /* Return a virtual function as a value.
795796c8dcSSimon Schubert ARG1 is the object which provides the virtual function
805796c8dcSSimon Schubert table pointer. *ARG1P is side-effected in calling this function.
815796c8dcSSimon Schubert F is the list of member functions which contains the desired virtual
825796c8dcSSimon Schubert function.
835796c8dcSSimon Schubert J is an index into F which provides the desired virtual function.
845796c8dcSSimon Schubert
855796c8dcSSimon Schubert TYPE is the type in which F is located. */
865796c8dcSSimon Schubert static struct value *
gnuv2_virtual_fn_field(struct value ** arg1p,struct fn_field * f,int j,struct type * type,int offset)875796c8dcSSimon Schubert gnuv2_virtual_fn_field (struct value **arg1p, struct fn_field * f, int j,
885796c8dcSSimon Schubert struct type * type, int offset)
895796c8dcSSimon Schubert {
905796c8dcSSimon Schubert struct value *arg1 = *arg1p;
915796c8dcSSimon Schubert struct type *type1 = check_typedef (value_type (arg1));
925796c8dcSSimon Schubert struct type *entry_type;
935796c8dcSSimon Schubert /* First, get the virtual function table pointer. That comes
945796c8dcSSimon Schubert with a strange type, so cast it to type `pointer to long' (which
955796c8dcSSimon Schubert should serve just fine as a function type). Then, index into
965796c8dcSSimon Schubert the table, and convert final value to appropriate function type. */
975796c8dcSSimon Schubert struct value *entry;
985796c8dcSSimon Schubert struct value *vfn;
995796c8dcSSimon Schubert struct value *vtbl;
1005796c8dcSSimon Schubert LONGEST vi = (LONGEST) TYPE_FN_FIELD_VOFFSET (f, j);
1015796c8dcSSimon Schubert struct type *fcontext = TYPE_FN_FIELD_FCONTEXT (f, j);
1025796c8dcSSimon Schubert struct type *context;
1035796c8dcSSimon Schubert struct type *context_vptr_basetype;
1045796c8dcSSimon Schubert int context_vptr_fieldno;
1055796c8dcSSimon Schubert
1065796c8dcSSimon Schubert if (fcontext == NULL)
1075796c8dcSSimon Schubert /* We don't have an fcontext (e.g. the program was compiled with
1085796c8dcSSimon Schubert g++ version 1). Try to get the vtbl from the TYPE_VPTR_BASETYPE.
1095796c8dcSSimon Schubert This won't work right for multiple inheritance, but at least we
1105796c8dcSSimon Schubert should do as well as GDB 3.x did. */
1115796c8dcSSimon Schubert fcontext = TYPE_VPTR_BASETYPE (type);
1125796c8dcSSimon Schubert context = lookup_pointer_type (fcontext);
1135796c8dcSSimon Schubert /* Now context is a pointer to the basetype containing the vtbl. */
1145796c8dcSSimon Schubert if (TYPE_TARGET_TYPE (context) != type1)
1155796c8dcSSimon Schubert {
1165796c8dcSSimon Schubert struct value *tmp = value_cast (context, value_addr (arg1));
117cf7f2e2dSJohn Marino
1185796c8dcSSimon Schubert arg1 = value_ind (tmp);
1195796c8dcSSimon Schubert type1 = check_typedef (value_type (arg1));
1205796c8dcSSimon Schubert }
1215796c8dcSSimon Schubert
1225796c8dcSSimon Schubert context = type1;
1235796c8dcSSimon Schubert /* Now context is the basetype containing the vtbl. */
1245796c8dcSSimon Schubert
1255796c8dcSSimon Schubert /* This type may have been defined before its virtual function table
1265796c8dcSSimon Schubert was. If so, fill in the virtual function table entry for the
1275796c8dcSSimon Schubert type now. */
1285796c8dcSSimon Schubert context_vptr_fieldno = get_vptr_fieldno (context, &context_vptr_basetype);
1295796c8dcSSimon Schubert /* FIXME: What to do if vptr_fieldno is still -1? */
1305796c8dcSSimon Schubert
1315796c8dcSSimon Schubert /* The virtual function table is now an array of structures
1325796c8dcSSimon Schubert which have the form { int16 offset, delta; void *pfn; }. */
1335796c8dcSSimon Schubert vtbl = value_primitive_field (arg1, 0, context_vptr_fieldno,
1345796c8dcSSimon Schubert context_vptr_basetype);
1355796c8dcSSimon Schubert
1365796c8dcSSimon Schubert /* With older versions of g++, the vtbl field pointed to an array
1375796c8dcSSimon Schubert of structures. Nowadays it points directly to the structure. */
1385796c8dcSSimon Schubert if (TYPE_CODE (value_type (vtbl)) == TYPE_CODE_PTR
1395796c8dcSSimon Schubert && TYPE_CODE (TYPE_TARGET_TYPE (value_type (vtbl))) == TYPE_CODE_ARRAY)
1405796c8dcSSimon Schubert {
1415796c8dcSSimon Schubert /* Handle the case where the vtbl field points to an
1425796c8dcSSimon Schubert array of structures. */
1435796c8dcSSimon Schubert vtbl = value_ind (vtbl);
1445796c8dcSSimon Schubert
1455796c8dcSSimon Schubert /* Index into the virtual function table. This is hard-coded because
1465796c8dcSSimon Schubert looking up a field is not cheap, and it may be important to save
1475796c8dcSSimon Schubert time, e.g. if the user has set a conditional breakpoint calling
1485796c8dcSSimon Schubert a virtual function. */
1495796c8dcSSimon Schubert entry = value_subscript (vtbl, vi);
1505796c8dcSSimon Schubert }
1515796c8dcSSimon Schubert else
1525796c8dcSSimon Schubert {
153c50c785cSJohn Marino /* Handle the case where the vtbl field points directly to a
154c50c785cSJohn Marino structure. */
1555796c8dcSSimon Schubert vtbl = value_ptradd (vtbl, vi);
1565796c8dcSSimon Schubert entry = value_ind (vtbl);
1575796c8dcSSimon Schubert }
1585796c8dcSSimon Schubert
1595796c8dcSSimon Schubert entry_type = check_typedef (value_type (entry));
1605796c8dcSSimon Schubert
1615796c8dcSSimon Schubert if (TYPE_CODE (entry_type) == TYPE_CODE_STRUCT)
1625796c8dcSSimon Schubert {
1635796c8dcSSimon Schubert /* Move the `this' pointer according to the virtual function table. */
164c50c785cSJohn Marino set_value_offset (arg1, value_offset (arg1)
165c50c785cSJohn Marino + value_as_long (value_field (entry, 0)));
1665796c8dcSSimon Schubert
1675796c8dcSSimon Schubert if (!value_lazy (arg1))
1685796c8dcSSimon Schubert {
1695796c8dcSSimon Schubert set_value_lazy (arg1, 1);
1705796c8dcSSimon Schubert value_fetch_lazy (arg1);
1715796c8dcSSimon Schubert }
1725796c8dcSSimon Schubert
1735796c8dcSSimon Schubert vfn = value_field (entry, 2);
1745796c8dcSSimon Schubert }
1755796c8dcSSimon Schubert else if (TYPE_CODE (entry_type) == TYPE_CODE_PTR)
1765796c8dcSSimon Schubert vfn = entry;
1775796c8dcSSimon Schubert else
1785796c8dcSSimon Schubert error (_("I'm confused: virtual function table has bad type"));
1795796c8dcSSimon Schubert /* Reinstantiate the function pointer with the correct type. */
180c50c785cSJohn Marino deprecated_set_value_type (vfn,
181c50c785cSJohn Marino lookup_pointer_type (TYPE_FN_FIELD_TYPE (f, j)));
1825796c8dcSSimon Schubert
1835796c8dcSSimon Schubert *arg1p = arg1;
1845796c8dcSSimon Schubert return vfn;
1855796c8dcSSimon Schubert }
1865796c8dcSSimon Schubert
1875796c8dcSSimon Schubert
1885796c8dcSSimon Schubert static struct type *
gnuv2_value_rtti_type(struct value * v,int * full,int * top,int * using_enc)1895796c8dcSSimon Schubert gnuv2_value_rtti_type (struct value *v, int *full, int *top, int *using_enc)
1905796c8dcSSimon Schubert {
1915796c8dcSSimon Schubert struct type *known_type;
1925796c8dcSSimon Schubert struct type *rtti_type;
1935796c8dcSSimon Schubert CORE_ADDR vtbl;
1945796c8dcSSimon Schubert struct minimal_symbol *minsym;
1955796c8dcSSimon Schubert char *demangled_name, *p;
196*ef5ccd6cSJohn Marino const char *linkage_name;
1975796c8dcSSimon Schubert struct type *btype;
1985796c8dcSSimon Schubert struct type *known_type_vptr_basetype;
1995796c8dcSSimon Schubert int known_type_vptr_fieldno;
2005796c8dcSSimon Schubert
2015796c8dcSSimon Schubert if (full)
2025796c8dcSSimon Schubert *full = 0;
2035796c8dcSSimon Schubert if (top)
2045796c8dcSSimon Schubert *top = -1;
2055796c8dcSSimon Schubert if (using_enc)
2065796c8dcSSimon Schubert *using_enc = 0;
2075796c8dcSSimon Schubert
208c50c785cSJohn Marino /* Get declared type. */
2095796c8dcSSimon Schubert known_type = value_type (v);
2105796c8dcSSimon Schubert CHECK_TYPEDEF (known_type);
211c50c785cSJohn Marino /* RTTI works only or class objects. */
2125796c8dcSSimon Schubert if (TYPE_CODE (known_type) != TYPE_CODE_CLASS)
2135796c8dcSSimon Schubert return NULL;
2145796c8dcSSimon Schubert
2155796c8dcSSimon Schubert /* Plan on this changing in the future as i get around to setting
2165796c8dcSSimon Schubert the vtables properly for G++ compiled stuff. Also, I'll be using
2175796c8dcSSimon Schubert the type info functions, which are always right. Deal with it
2185796c8dcSSimon Schubert until then. */
2195796c8dcSSimon Schubert
2205796c8dcSSimon Schubert /* Try to get the vptr basetype, fieldno. */
2215796c8dcSSimon Schubert known_type_vptr_fieldno = get_vptr_fieldno (known_type,
2225796c8dcSSimon Schubert &known_type_vptr_basetype);
2235796c8dcSSimon Schubert
2245796c8dcSSimon Schubert /* If we can't find it, give up. */
2255796c8dcSSimon Schubert if (known_type_vptr_fieldno < 0)
2265796c8dcSSimon Schubert return NULL;
2275796c8dcSSimon Schubert
2285796c8dcSSimon Schubert /* Make sure our basetype and known type match, otherwise, cast
229c50c785cSJohn Marino so we can get at the vtable properly. */
2305796c8dcSSimon Schubert btype = known_type_vptr_basetype;
2315796c8dcSSimon Schubert CHECK_TYPEDEF (btype);
2325796c8dcSSimon Schubert if (btype != known_type )
2335796c8dcSSimon Schubert {
2345796c8dcSSimon Schubert v = value_cast (btype, v);
2355796c8dcSSimon Schubert if (using_enc)
2365796c8dcSSimon Schubert *using_enc=1;
2375796c8dcSSimon Schubert }
238c50c785cSJohn Marino /* We can't use value_ind here, because it would want to use RTTI, and
2395796c8dcSSimon Schubert we'd waste a bunch of time figuring out we already know the type.
240c50c785cSJohn Marino Besides, we don't care about the type, just the actual pointer. */
2415796c8dcSSimon Schubert if (value_address (value_field (v, known_type_vptr_fieldno)) == 0)
2425796c8dcSSimon Schubert return NULL;
2435796c8dcSSimon Schubert
2445796c8dcSSimon Schubert vtbl = value_as_address (value_field (v, known_type_vptr_fieldno));
2455796c8dcSSimon Schubert
246c50c785cSJohn Marino /* Try to find a symbol that is the vtable. */
2475796c8dcSSimon Schubert minsym=lookup_minimal_symbol_by_pc(vtbl);
2485796c8dcSSimon Schubert if (minsym==NULL
249*ef5ccd6cSJohn Marino || (linkage_name=SYMBOL_LINKAGE_NAME (minsym))==NULL
250*ef5ccd6cSJohn Marino || !is_vtable_name (linkage_name))
2515796c8dcSSimon Schubert return NULL;
2525796c8dcSSimon Schubert
253c50c785cSJohn Marino /* If we just skip the prefix, we get screwed by namespaces. */
254*ef5ccd6cSJohn Marino demangled_name=cplus_demangle(linkage_name,DMGL_PARAMS|DMGL_ANSI);
2555796c8dcSSimon Schubert p = strchr (demangled_name, ' ');
2565796c8dcSSimon Schubert if (p)
2575796c8dcSSimon Schubert *p = '\0';
2585796c8dcSSimon Schubert
259c50c785cSJohn Marino /* Lookup the type for the name. */
2605796c8dcSSimon Schubert /* FIXME: chastain/2003-11-26: block=NULL is bogus. See pr gdb/1465. */
2615796c8dcSSimon Schubert rtti_type = cp_lookup_rtti_type (demangled_name, NULL);
2625796c8dcSSimon Schubert if (rtti_type == NULL)
2635796c8dcSSimon Schubert return NULL;
2645796c8dcSSimon Schubert
2655796c8dcSSimon Schubert if (TYPE_N_BASECLASSES(rtti_type) > 1 && full && (*full) != 1)
2665796c8dcSSimon Schubert {
2675796c8dcSSimon Schubert if (top)
268c50c785cSJohn Marino *top = TYPE_BASECLASS_BITPOS (rtti_type,
269c50c785cSJohn Marino TYPE_VPTR_FIELDNO(rtti_type)) / 8;
2705796c8dcSSimon Schubert if (top && ((*top) >0))
2715796c8dcSSimon Schubert {
2725796c8dcSSimon Schubert if (TYPE_LENGTH(rtti_type) > TYPE_LENGTH(known_type))
2735796c8dcSSimon Schubert {
2745796c8dcSSimon Schubert if (full)
2755796c8dcSSimon Schubert *full=0;
2765796c8dcSSimon Schubert }
2775796c8dcSSimon Schubert else
2785796c8dcSSimon Schubert {
2795796c8dcSSimon Schubert if (full)
2805796c8dcSSimon Schubert *full=1;
2815796c8dcSSimon Schubert }
2825796c8dcSSimon Schubert }
2835796c8dcSSimon Schubert }
2845796c8dcSSimon Schubert else
2855796c8dcSSimon Schubert {
2865796c8dcSSimon Schubert if (full)
2875796c8dcSSimon Schubert *full=1;
2885796c8dcSSimon Schubert }
2895796c8dcSSimon Schubert
2905796c8dcSSimon Schubert return rtti_type;
2915796c8dcSSimon Schubert }
2925796c8dcSSimon Schubert
2935796c8dcSSimon Schubert /* Return true if the INDEXth field of TYPE is a virtual baseclass
2945796c8dcSSimon Schubert pointer which is for the base class whose type is BASECLASS. */
2955796c8dcSSimon Schubert
2965796c8dcSSimon Schubert static int
vb_match(struct type * type,int index,struct type * basetype)2975796c8dcSSimon Schubert vb_match (struct type *type, int index, struct type *basetype)
2985796c8dcSSimon Schubert {
2995796c8dcSSimon Schubert struct type *fieldtype;
300*ef5ccd6cSJohn Marino const char *name = TYPE_FIELD_NAME (type, index);
301*ef5ccd6cSJohn Marino const char *field_class_name = NULL;
3025796c8dcSSimon Schubert
3035796c8dcSSimon Schubert if (*name != '_')
3045796c8dcSSimon Schubert return 0;
3055796c8dcSSimon Schubert /* gcc 2.4 uses _vb$. */
3065796c8dcSSimon Schubert if (name[1] == 'v' && name[2] == 'b' && is_cplus_marker (name[3]))
3075796c8dcSSimon Schubert field_class_name = name + 4;
3085796c8dcSSimon Schubert /* gcc 2.5 will use __vb_. */
3095796c8dcSSimon Schubert if (name[1] == '_' && name[2] == 'v' && name[3] == 'b' && name[4] == '_')
3105796c8dcSSimon Schubert field_class_name = name + 5;
3115796c8dcSSimon Schubert
3125796c8dcSSimon Schubert if (field_class_name == NULL)
3135796c8dcSSimon Schubert /* This field is not a virtual base class pointer. */
3145796c8dcSSimon Schubert return 0;
3155796c8dcSSimon Schubert
3165796c8dcSSimon Schubert /* It's a virtual baseclass pointer, now we just need to find out whether
3175796c8dcSSimon Schubert it is for this baseclass. */
3185796c8dcSSimon Schubert fieldtype = TYPE_FIELD_TYPE (type, index);
3195796c8dcSSimon Schubert if (fieldtype == NULL
3205796c8dcSSimon Schubert || TYPE_CODE (fieldtype) != TYPE_CODE_PTR)
3215796c8dcSSimon Schubert /* "Can't happen". */
3225796c8dcSSimon Schubert return 0;
3235796c8dcSSimon Schubert
3245796c8dcSSimon Schubert /* What we check for is that either the types are equal (needed for
3255796c8dcSSimon Schubert nameless types) or have the same name. This is ugly, and a more
3265796c8dcSSimon Schubert elegant solution should be devised (which would probably just push
3275796c8dcSSimon Schubert the ugliness into symbol reading unless we change the stabs format). */
3285796c8dcSSimon Schubert if (TYPE_TARGET_TYPE (fieldtype) == basetype)
3295796c8dcSSimon Schubert return 1;
3305796c8dcSSimon Schubert
3315796c8dcSSimon Schubert if (TYPE_NAME (basetype) != NULL
3325796c8dcSSimon Schubert && TYPE_NAME (TYPE_TARGET_TYPE (fieldtype)) != NULL
3335796c8dcSSimon Schubert && strcmp (TYPE_NAME (basetype),
3345796c8dcSSimon Schubert TYPE_NAME (TYPE_TARGET_TYPE (fieldtype))) == 0)
3355796c8dcSSimon Schubert return 1;
3365796c8dcSSimon Schubert return 0;
3375796c8dcSSimon Schubert }
3385796c8dcSSimon Schubert
339c50c785cSJohn Marino /* Compute the offset of the baseclass which is the INDEXth baseclass
340c50c785cSJohn Marino of class TYPE, for value at VALADDR (in host) at ADDRESS (in
341c50c785cSJohn Marino target). The result is the offset of the baseclass value relative
342c50c785cSJohn Marino to (the address of)(ARG) + OFFSET. */
3435796c8dcSSimon Schubert
344cf7f2e2dSJohn Marino static int
gnuv2_baseclass_offset(struct type * type,int index,const bfd_byte * valaddr,int embedded_offset,CORE_ADDR address,const struct value * val)3455796c8dcSSimon Schubert gnuv2_baseclass_offset (struct type *type, int index,
346c50c785cSJohn Marino const bfd_byte *valaddr, int embedded_offset,
347c50c785cSJohn Marino CORE_ADDR address, const struct value *val)
3485796c8dcSSimon Schubert {
3495796c8dcSSimon Schubert struct type *basetype = TYPE_BASECLASS (type, index);
3505796c8dcSSimon Schubert
3515796c8dcSSimon Schubert if (BASETYPE_VIA_VIRTUAL (type, index))
3525796c8dcSSimon Schubert {
3535796c8dcSSimon Schubert /* Must hunt for the pointer to this virtual baseclass. */
3545796c8dcSSimon Schubert int i, len = TYPE_NFIELDS (type);
3555796c8dcSSimon Schubert int n_baseclasses = TYPE_N_BASECLASSES (type);
3565796c8dcSSimon Schubert
3575796c8dcSSimon Schubert /* First look for the virtual baseclass pointer
3585796c8dcSSimon Schubert in the fields. */
3595796c8dcSSimon Schubert for (i = n_baseclasses; i < len; i++)
3605796c8dcSSimon Schubert {
3615796c8dcSSimon Schubert if (vb_match (type, i, basetype))
3625796c8dcSSimon Schubert {
363c50c785cSJohn Marino struct type *field_type;
364c50c785cSJohn Marino int field_offset;
365c50c785cSJohn Marino int field_length;
366c50c785cSJohn Marino CORE_ADDR addr;
3675796c8dcSSimon Schubert
368c50c785cSJohn Marino field_type = check_typedef (TYPE_FIELD_TYPE (type, i));
369c50c785cSJohn Marino field_offset = TYPE_FIELD_BITPOS (type, i) / 8;
370c50c785cSJohn Marino field_length = TYPE_LENGTH (field_type);
371c50c785cSJohn Marino
372c50c785cSJohn Marino if (!value_bytes_available (val, embedded_offset + field_offset,
373c50c785cSJohn Marino field_length))
374c50c785cSJohn Marino throw_error (NOT_AVAILABLE_ERROR,
375c50c785cSJohn Marino _("Virtual baseclass pointer is not available"));
376c50c785cSJohn Marino
377c50c785cSJohn Marino addr = unpack_pointer (field_type,
378c50c785cSJohn Marino valaddr + embedded_offset + field_offset);
379c50c785cSJohn Marino
380c50c785cSJohn Marino return addr - (LONGEST) address + embedded_offset;
3815796c8dcSSimon Schubert }
3825796c8dcSSimon Schubert }
3835796c8dcSSimon Schubert /* Not in the fields, so try looking through the baseclasses. */
3845796c8dcSSimon Schubert for (i = index + 1; i < n_baseclasses; i++)
3855796c8dcSSimon Schubert {
386c50c785cSJohn Marino /* Don't go through baseclass_offset, as that wraps
387c50c785cSJohn Marino exceptions, thus, inner exceptions would be wrapped more
388c50c785cSJohn Marino than once. */
3895796c8dcSSimon Schubert int boffset =
390c50c785cSJohn Marino gnuv2_baseclass_offset (type, i, valaddr,
391c50c785cSJohn Marino embedded_offset, address, val);
392cf7f2e2dSJohn Marino
3935796c8dcSSimon Schubert if (boffset)
3945796c8dcSSimon Schubert return boffset;
3955796c8dcSSimon Schubert }
396c50c785cSJohn Marino
397c50c785cSJohn Marino error (_("Baseclass offset not found"));
3985796c8dcSSimon Schubert }
3995796c8dcSSimon Schubert
4005796c8dcSSimon Schubert /* Baseclass is easily computed. */
4015796c8dcSSimon Schubert return TYPE_BASECLASS_BITPOS (type, index) / 8;
4025796c8dcSSimon Schubert }
4035796c8dcSSimon Schubert
4045796c8dcSSimon Schubert static void
init_gnuv2_ops(void)4055796c8dcSSimon Schubert init_gnuv2_ops (void)
4065796c8dcSSimon Schubert {
4075796c8dcSSimon Schubert gnu_v2_abi_ops.shortname = "gnu-v2";
4085796c8dcSSimon Schubert gnu_v2_abi_ops.longname = "GNU G++ Version 2 ABI";
4095796c8dcSSimon Schubert gnu_v2_abi_ops.doc = "G++ Version 2 ABI";
4105796c8dcSSimon Schubert gnu_v2_abi_ops.is_destructor_name = gnuv2_is_destructor_name;
4115796c8dcSSimon Schubert gnu_v2_abi_ops.is_constructor_name = gnuv2_is_constructor_name;
4125796c8dcSSimon Schubert gnu_v2_abi_ops.is_vtable_name = gnuv2_is_vtable_name;
4135796c8dcSSimon Schubert gnu_v2_abi_ops.is_operator_name = gnuv2_is_operator_name;
4145796c8dcSSimon Schubert gnu_v2_abi_ops.virtual_fn_field = gnuv2_virtual_fn_field;
4155796c8dcSSimon Schubert gnu_v2_abi_ops.rtti_type = gnuv2_value_rtti_type;
4165796c8dcSSimon Schubert gnu_v2_abi_ops.baseclass_offset = gnuv2_baseclass_offset;
4175796c8dcSSimon Schubert }
4185796c8dcSSimon Schubert
4195796c8dcSSimon Schubert extern initialize_file_ftype _initialize_gnu_v2_abi; /* -Wmissing-prototypes */
4205796c8dcSSimon Schubert
4215796c8dcSSimon Schubert void
_initialize_gnu_v2_abi(void)4225796c8dcSSimon Schubert _initialize_gnu_v2_abi (void)
4235796c8dcSSimon Schubert {
4245796c8dcSSimon Schubert init_gnuv2_ops ();
4255796c8dcSSimon Schubert register_cp_abi (&gnu_v2_abi_ops);
4265796c8dcSSimon Schubert }
427