static struct type * gnuv2_value_rtti_type (struct value *v, int *full, int *top, int *using_enc) { struct type *known_type; struct type *rtti_type; CORE_ADDR vtbl; struct minimal_symbol *minsym; char *demangled_name; struct type *btype; if (full) *full = 0; if (top) *top = -1; if (using_enc) *using_enc = 0; /* Get declared type */ known_type = value_type (v); CHECK_TYPEDEF (known_type); /* RTTI works only or class objects */ if (TYPE_CODE (known_type) != TYPE_CODE_CLASS) return NULL; /* Plan on this changing in the future as i get around to setting the vtables properly for G++ compiled stuff. Also, I'll be using the type info functions, which are always right. Deal with it until then. JCI - This pretty much useless. This gets the "true" type correctly when there is single inheritance - but in all such cases that I could find gdb already knows that. In cases where this points INTO the object (like non-virtual diamond graphs) the demangled name is something like OUTER::INNER and this is not a symbol gdb can resolve, so we fail & return NULL anyway. Seems like this really isn't going to work till we actually call the RTTI function & parse it. */ /* If the type has no vptr fieldno, try to get it filled in */ if (TYPE_VPTR_FIELDNO(known_type) < 0) fill_in_vptr_fieldno(known_type); /* If we still can't find one, give up */ if (TYPE_VPTR_FIELDNO(known_type) < 0) return NULL; /* Make sure our basetype and known type match, otherwise, cast so we can get at the vtable properly. */ btype = TYPE_VPTR_BASETYPE (known_type); CHECK_TYPEDEF (btype); if (btype != known_type ) { v = value_cast (btype, v); if (using_enc) *using_enc=1; } /* We can't use value_ind here, because it would want to use RTTI, and we'd waste a bunch of time figuring out we already know the type. Besides, we don't care about the type, just the actual pointer */ if (VALUE_ADDRESS (value_field (v, TYPE_VPTR_FIELDNO (known_type))) == 0) return NULL; vtbl=value_as_address(value_field(v,TYPE_VPTR_FIELDNO(known_type))); /* Try to find a symbol that is the vtable */ minsym=lookup_minimal_symbol_by_pc(vtbl); if (minsym==NULL || (demangled_name=DEPRECATED_SYMBOL_NAME (minsym))==NULL || !is_vtable_name (demangled_name)) return NULL; /* If we just skip the prefix, we get screwed by namespaces */ demangled_name=cplus_demangle(demangled_name,DMGL_PARAMS|DMGL_ANSI); *(strchr(demangled_name,' '))=0; /* Lookup the type for the name */ /* FIXME: chastain/2003-11-26: block=NULL is bogus. See pr gdb/1465. */ rtti_type = cp_lookup_rtti_type (demangled_name, NULL); if (rtti_type == NULL) return NULL; if (TYPE_N_BASECLASSES(rtti_type) > 1 && full && (*full) != 1) { if (top) *top=TYPE_BASECLASS_BITPOS(rtti_type,TYPE_VPTR_FIELDNO(rtti_type))/8; if (top && ((*top) >0)) { if (TYPE_LENGTH(rtti_type) > TYPE_LENGTH(known_type)) { if (full) *full=0; } else { if (full) *full=1; } } } else { if (full) *full=1; } return rtti_type; }
static struct type * gnuv2_value_rtti_type (struct value *v, int *full, int *top, int *using_enc) { struct type *known_type; struct type *rtti_type; CORE_ADDR vtbl; struct bound_minimal_symbol minsym; char *demangled_name, *p; const char *linkage_name; struct type *btype; struct type *known_type_vptr_basetype; int known_type_vptr_fieldno; if (full) *full = 0; if (top) *top = -1; if (using_enc) *using_enc = 0; /* Get declared type. */ known_type = value_type (v); CHECK_TYPEDEF (known_type); /* RTTI works only or class objects. */ if (TYPE_CODE (known_type) != TYPE_CODE_STRUCT) return NULL; /* Plan on this changing in the future as i get around to setting the vtables properly for G++ compiled stuff. Also, I'll be using the type info functions, which are always right. Deal with it until then. */ /* Try to get the vptr basetype, fieldno. */ known_type_vptr_fieldno = get_vptr_fieldno (known_type, &known_type_vptr_basetype); /* If we can't find it, give up. */ if (known_type_vptr_fieldno < 0) return NULL; /* Make sure our basetype and known type match, otherwise, cast so we can get at the vtable properly. */ btype = known_type_vptr_basetype; CHECK_TYPEDEF (btype); if (btype != known_type ) { v = value_cast (btype, v); if (using_enc) *using_enc=1; } /* We can't use value_ind here, because it would want to use RTTI, and we'd waste a bunch of time figuring out we already know the type. Besides, we don't care about the type, just the actual pointer. */ if (value_address (value_field (v, known_type_vptr_fieldno)) == 0) return NULL; vtbl = value_as_address (value_field (v, known_type_vptr_fieldno)); /* Try to find a symbol that is the vtable. */ minsym=lookup_minimal_symbol_by_pc(vtbl); if (minsym.minsym==NULL || (linkage_name=MSYMBOL_LINKAGE_NAME (minsym.minsym))==NULL || !is_vtable_name (linkage_name)) return NULL; /* If we just skip the prefix, we get screwed by namespaces. */ demangled_name=gdb_demangle(linkage_name,DMGL_PARAMS|DMGL_ANSI); p = strchr (demangled_name, ' '); if (p) *p = '\0'; /* Lookup the type for the name. */ /* FIXME: chastain/2003-11-26: block=NULL is bogus. See pr gdb/1465. */ rtti_type = cp_lookup_rtti_type (demangled_name, NULL); if (rtti_type == NULL) return NULL; if (TYPE_N_BASECLASSES(rtti_type) > 1 && full && (*full) != 1) { if (top) *top = TYPE_BASECLASS_BITPOS (rtti_type, TYPE_VPTR_FIELDNO(rtti_type)) / 8; if (top && ((*top) >0)) { if (TYPE_LENGTH(rtti_type) > TYPE_LENGTH(known_type)) { if (full) *full=0; } else { if (full) *full=1; } } } else { if (full) *full=1; } return rtti_type; }