15796c8dcSSimon Schubert /* Abstraction of GNU v2 abi. 25796c8dcSSimon Schubert 3*a45ae5f8SJohn Marino Copyright (C) 2001-2003, 2005, 2007-2012 Free Software Foundation, 4*a45ae5f8SJohn Marino Inc. 55796c8dcSSimon Schubert 65796c8dcSSimon Schubert Contributed by Daniel Berlin <dberlin@redhat.com> 75796c8dcSSimon Schubert 85796c8dcSSimon Schubert This file is part of GDB. 95796c8dcSSimon Schubert 105796c8dcSSimon Schubert This program is free software; you can redistribute it and/or modify 115796c8dcSSimon Schubert it under the terms of the GNU General Public License as published by 125796c8dcSSimon Schubert the Free Software Foundation; either version 3 of the License, or 135796c8dcSSimon Schubert (at your option) any later version. 145796c8dcSSimon Schubert 155796c8dcSSimon Schubert This program is distributed in the hope that it will be useful, 165796c8dcSSimon Schubert but WITHOUT ANY WARRANTY; without even the implied warranty of 175796c8dcSSimon Schubert MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 185796c8dcSSimon Schubert GNU General Public License for more details. 195796c8dcSSimon Schubert 205796c8dcSSimon Schubert You should have received a copy of the GNU General Public License 215796c8dcSSimon Schubert along with this program. If not, see <http://www.gnu.org/licenses/>. */ 225796c8dcSSimon Schubert 235796c8dcSSimon Schubert #include "defs.h" 245796c8dcSSimon Schubert #include "gdb_string.h" 255796c8dcSSimon Schubert #include "symtab.h" 265796c8dcSSimon Schubert #include "gdbtypes.h" 275796c8dcSSimon Schubert #include "value.h" 285796c8dcSSimon Schubert #include "demangle.h" 29*a45ae5f8SJohn Marino #include "gdb-demangle.h" 305796c8dcSSimon Schubert #include "cp-abi.h" 315796c8dcSSimon Schubert #include "cp-support.h" 32c50c785cSJohn Marino #include "exceptions.h" 335796c8dcSSimon Schubert 345796c8dcSSimon Schubert #include <ctype.h> 355796c8dcSSimon Schubert 365796c8dcSSimon Schubert struct cp_abi_ops gnu_v2_abi_ops; 375796c8dcSSimon Schubert 385796c8dcSSimon Schubert static int vb_match (struct type *, int, struct type *); 395796c8dcSSimon Schubert 405796c8dcSSimon Schubert static enum dtor_kinds 415796c8dcSSimon Schubert gnuv2_is_destructor_name (const char *name) 425796c8dcSSimon Schubert { 435796c8dcSSimon Schubert if ((name[0] == '_' && is_cplus_marker (name[1]) && name[2] == '_') 445796c8dcSSimon Schubert || strncmp (name, "__dt__", 6) == 0) 455796c8dcSSimon Schubert return complete_object_dtor; 465796c8dcSSimon Schubert else 475796c8dcSSimon Schubert return 0; 485796c8dcSSimon Schubert } 495796c8dcSSimon Schubert 505796c8dcSSimon Schubert static enum ctor_kinds 515796c8dcSSimon Schubert gnuv2_is_constructor_name (const char *name) 525796c8dcSSimon Schubert { 535796c8dcSSimon Schubert if ((name[0] == '_' && name[1] == '_' 545796c8dcSSimon Schubert && (isdigit (name[2]) || strchr ("Qt", name[2]))) 555796c8dcSSimon Schubert || strncmp (name, "__ct__", 6) == 0) 565796c8dcSSimon Schubert return complete_object_ctor; 575796c8dcSSimon Schubert else 585796c8dcSSimon Schubert return 0; 595796c8dcSSimon Schubert } 605796c8dcSSimon Schubert 615796c8dcSSimon Schubert static int 625796c8dcSSimon Schubert gnuv2_is_vtable_name (const char *name) 635796c8dcSSimon Schubert { 645796c8dcSSimon Schubert return (((name)[0] == '_' 655796c8dcSSimon Schubert && (((name)[1] == 'V' && (name)[2] == 'T') 665796c8dcSSimon Schubert || ((name)[1] == 'v' && (name)[2] == 't')) 675796c8dcSSimon Schubert && is_cplus_marker ((name)[3])) || 685796c8dcSSimon Schubert ((name)[0] == '_' && (name)[1] == '_' 695796c8dcSSimon Schubert && (name)[2] == 'v' && (name)[3] == 't' && (name)[4] == '_')); 705796c8dcSSimon Schubert } 715796c8dcSSimon Schubert 725796c8dcSSimon Schubert static int 735796c8dcSSimon Schubert gnuv2_is_operator_name (const char *name) 745796c8dcSSimon Schubert { 755796c8dcSSimon Schubert return strncmp (name, "operator", 8) == 0; 765796c8dcSSimon Schubert } 775796c8dcSSimon Schubert 785796c8dcSSimon Schubert 795796c8dcSSimon Schubert /* Return a virtual function as a value. 805796c8dcSSimon Schubert ARG1 is the object which provides the virtual function 815796c8dcSSimon Schubert table pointer. *ARG1P is side-effected in calling this function. 825796c8dcSSimon Schubert F is the list of member functions which contains the desired virtual 835796c8dcSSimon Schubert function. 845796c8dcSSimon Schubert J is an index into F which provides the desired virtual function. 855796c8dcSSimon Schubert 865796c8dcSSimon Schubert TYPE is the type in which F is located. */ 875796c8dcSSimon Schubert static struct value * 885796c8dcSSimon Schubert gnuv2_virtual_fn_field (struct value **arg1p, struct fn_field * f, int j, 895796c8dcSSimon Schubert struct type * type, int offset) 905796c8dcSSimon Schubert { 915796c8dcSSimon Schubert struct value *arg1 = *arg1p; 925796c8dcSSimon Schubert struct type *type1 = check_typedef (value_type (arg1)); 935796c8dcSSimon Schubert struct type *entry_type; 945796c8dcSSimon Schubert /* First, get the virtual function table pointer. That comes 955796c8dcSSimon Schubert with a strange type, so cast it to type `pointer to long' (which 965796c8dcSSimon Schubert should serve just fine as a function type). Then, index into 975796c8dcSSimon Schubert the table, and convert final value to appropriate function type. */ 985796c8dcSSimon Schubert struct value *entry; 995796c8dcSSimon Schubert struct value *vfn; 1005796c8dcSSimon Schubert struct value *vtbl; 1015796c8dcSSimon Schubert LONGEST vi = (LONGEST) TYPE_FN_FIELD_VOFFSET (f, j); 1025796c8dcSSimon Schubert struct type *fcontext = TYPE_FN_FIELD_FCONTEXT (f, j); 1035796c8dcSSimon Schubert struct type *context; 1045796c8dcSSimon Schubert struct type *context_vptr_basetype; 1055796c8dcSSimon Schubert int context_vptr_fieldno; 1065796c8dcSSimon Schubert 1075796c8dcSSimon Schubert if (fcontext == NULL) 1085796c8dcSSimon Schubert /* We don't have an fcontext (e.g. the program was compiled with 1095796c8dcSSimon Schubert g++ version 1). Try to get the vtbl from the TYPE_VPTR_BASETYPE. 1105796c8dcSSimon Schubert This won't work right for multiple inheritance, but at least we 1115796c8dcSSimon Schubert should do as well as GDB 3.x did. */ 1125796c8dcSSimon Schubert fcontext = TYPE_VPTR_BASETYPE (type); 1135796c8dcSSimon Schubert context = lookup_pointer_type (fcontext); 1145796c8dcSSimon Schubert /* Now context is a pointer to the basetype containing the vtbl. */ 1155796c8dcSSimon Schubert if (TYPE_TARGET_TYPE (context) != type1) 1165796c8dcSSimon Schubert { 1175796c8dcSSimon Schubert struct value *tmp = value_cast (context, value_addr (arg1)); 118cf7f2e2dSJohn Marino 1195796c8dcSSimon Schubert arg1 = value_ind (tmp); 1205796c8dcSSimon Schubert type1 = check_typedef (value_type (arg1)); 1215796c8dcSSimon Schubert } 1225796c8dcSSimon Schubert 1235796c8dcSSimon Schubert context = type1; 1245796c8dcSSimon Schubert /* Now context is the basetype containing the vtbl. */ 1255796c8dcSSimon Schubert 1265796c8dcSSimon Schubert /* This type may have been defined before its virtual function table 1275796c8dcSSimon Schubert was. If so, fill in the virtual function table entry for the 1285796c8dcSSimon Schubert type now. */ 1295796c8dcSSimon Schubert context_vptr_fieldno = get_vptr_fieldno (context, &context_vptr_basetype); 1305796c8dcSSimon Schubert /* FIXME: What to do if vptr_fieldno is still -1? */ 1315796c8dcSSimon Schubert 1325796c8dcSSimon Schubert /* The virtual function table is now an array of structures 1335796c8dcSSimon Schubert which have the form { int16 offset, delta; void *pfn; }. */ 1345796c8dcSSimon Schubert vtbl = value_primitive_field (arg1, 0, context_vptr_fieldno, 1355796c8dcSSimon Schubert context_vptr_basetype); 1365796c8dcSSimon Schubert 1375796c8dcSSimon Schubert /* With older versions of g++, the vtbl field pointed to an array 1385796c8dcSSimon Schubert of structures. Nowadays it points directly to the structure. */ 1395796c8dcSSimon Schubert if (TYPE_CODE (value_type (vtbl)) == TYPE_CODE_PTR 1405796c8dcSSimon Schubert && TYPE_CODE (TYPE_TARGET_TYPE (value_type (vtbl))) == TYPE_CODE_ARRAY) 1415796c8dcSSimon Schubert { 1425796c8dcSSimon Schubert /* Handle the case where the vtbl field points to an 1435796c8dcSSimon Schubert array of structures. */ 1445796c8dcSSimon Schubert vtbl = value_ind (vtbl); 1455796c8dcSSimon Schubert 1465796c8dcSSimon Schubert /* Index into the virtual function table. This is hard-coded because 1475796c8dcSSimon Schubert looking up a field is not cheap, and it may be important to save 1485796c8dcSSimon Schubert time, e.g. if the user has set a conditional breakpoint calling 1495796c8dcSSimon Schubert a virtual function. */ 1505796c8dcSSimon Schubert entry = value_subscript (vtbl, vi); 1515796c8dcSSimon Schubert } 1525796c8dcSSimon Schubert else 1535796c8dcSSimon Schubert { 154c50c785cSJohn Marino /* Handle the case where the vtbl field points directly to a 155c50c785cSJohn Marino structure. */ 1565796c8dcSSimon Schubert vtbl = value_ptradd (vtbl, vi); 1575796c8dcSSimon Schubert entry = value_ind (vtbl); 1585796c8dcSSimon Schubert } 1595796c8dcSSimon Schubert 1605796c8dcSSimon Schubert entry_type = check_typedef (value_type (entry)); 1615796c8dcSSimon Schubert 1625796c8dcSSimon Schubert if (TYPE_CODE (entry_type) == TYPE_CODE_STRUCT) 1635796c8dcSSimon Schubert { 1645796c8dcSSimon Schubert /* Move the `this' pointer according to the virtual function table. */ 165c50c785cSJohn Marino set_value_offset (arg1, value_offset (arg1) 166c50c785cSJohn Marino + value_as_long (value_field (entry, 0))); 1675796c8dcSSimon Schubert 1685796c8dcSSimon Schubert if (!value_lazy (arg1)) 1695796c8dcSSimon Schubert { 1705796c8dcSSimon Schubert set_value_lazy (arg1, 1); 1715796c8dcSSimon Schubert value_fetch_lazy (arg1); 1725796c8dcSSimon Schubert } 1735796c8dcSSimon Schubert 1745796c8dcSSimon Schubert vfn = value_field (entry, 2); 1755796c8dcSSimon Schubert } 1765796c8dcSSimon Schubert else if (TYPE_CODE (entry_type) == TYPE_CODE_PTR) 1775796c8dcSSimon Schubert vfn = entry; 1785796c8dcSSimon Schubert else 1795796c8dcSSimon Schubert error (_("I'm confused: virtual function table has bad type")); 1805796c8dcSSimon Schubert /* Reinstantiate the function pointer with the correct type. */ 181c50c785cSJohn Marino deprecated_set_value_type (vfn, 182c50c785cSJohn Marino lookup_pointer_type (TYPE_FN_FIELD_TYPE (f, j))); 1835796c8dcSSimon Schubert 1845796c8dcSSimon Schubert *arg1p = arg1; 1855796c8dcSSimon Schubert return vfn; 1865796c8dcSSimon Schubert } 1875796c8dcSSimon Schubert 1885796c8dcSSimon Schubert 1895796c8dcSSimon Schubert static struct type * 1905796c8dcSSimon Schubert gnuv2_value_rtti_type (struct value *v, int *full, int *top, int *using_enc) 1915796c8dcSSimon Schubert { 1925796c8dcSSimon Schubert struct type *known_type; 1935796c8dcSSimon Schubert struct type *rtti_type; 1945796c8dcSSimon Schubert CORE_ADDR vtbl; 1955796c8dcSSimon Schubert struct minimal_symbol *minsym; 1965796c8dcSSimon Schubert char *demangled_name, *p; 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 2495796c8dcSSimon Schubert || (demangled_name=SYMBOL_LINKAGE_NAME (minsym))==NULL 2505796c8dcSSimon Schubert || !is_vtable_name (demangled_name)) 2515796c8dcSSimon Schubert return NULL; 2525796c8dcSSimon Schubert 253c50c785cSJohn Marino /* If we just skip the prefix, we get screwed by namespaces. */ 2545796c8dcSSimon Schubert demangled_name=cplus_demangle(demangled_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 2975796c8dcSSimon Schubert vb_match (struct type *type, int index, struct type *basetype) 2985796c8dcSSimon Schubert { 2995796c8dcSSimon Schubert struct type *fieldtype; 3005796c8dcSSimon Schubert char *name = TYPE_FIELD_NAME (type, index); 3015796c8dcSSimon Schubert 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 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 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 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 set_cp_abi_as_auto_default (gnu_v2_abi_ops.shortname); 4275796c8dcSSimon Schubert } 428