static struct value * gnuv3_get_virtual_fn (struct gdbarch *gdbarch, struct value *container, struct type *fntype, int vtable_index) { struct value *vtable, *vfn; /* Every class with virtual functions must have a vtable. */ vtable = gnuv3_get_vtable (gdbarch, value_type (container), value_as_address (value_addr (container))); gdb_assert (vtable != NULL); /* Fetch the appropriate function pointer from the vtable. */ vfn = value_subscript (value_field (vtable, vtable_field_virtual_functions), vtable_index); /* If this architecture uses function descriptors directly in the vtable, then the address of the vtable entry is actually a "function pointer" (i.e. points to the descriptor). We don't need to scale the index by the size of a function descriptor; GCC does that before outputing debug information. */ if (gdbarch_vtable_function_descriptors (gdbarch)) vfn = value_addr (vfn); /* Cast the function pointer to the appropriate type. */ vfn = value_cast (lookup_pointer_type (fntype), vfn); return vfn; }
/** * garrow_list_data_type_get_value_field: * @list_data_type: A #GArrowListDataType. * * Returns: (transfer full): The field of value. */ GArrowField * garrow_list_data_type_get_value_field(GArrowListDataType *list_data_type) { auto arrow_data_type = garrow_data_type_get_raw(GARROW_DATA_TYPE(list_data_type)); auto arrow_list_data_type = static_cast<arrow::ListType *>(arrow_data_type.get()); auto arrow_field = arrow_list_data_type->value_field(); auto field = garrow_field_new_raw(&arrow_field); return field; }
static int gnuv3_baseclass_offset (struct type *type, int index, const bfd_byte *valaddr, int embedded_offset, CORE_ADDR address, const struct value *val) { struct gdbarch *gdbarch; struct type *ptr_type; struct value *vtable; struct value *vbase_array; long int cur_base_offset, base_offset; /* Determine architecture. */ gdbarch = get_type_arch (type); 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)) return TYPE_BASECLASS_BITPOS (type, index) / 8; /* 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 complete inheritance graph based on the debug info. Neither is worthwhile. */ cur_base_offset = TYPE_BASECLASS_BITPOS (type, index) / 8; if (cur_base_offset >= - vtable_address_point_offset (gdbarch)) error (_("Expected a negative vbase offset (old compiler?)")); cur_base_offset = cur_base_offset + vtable_address_point_offset (gdbarch); if ((- cur_base_offset) % TYPE_LENGTH (ptr_type) != 0) error (_("Misaligned vbase offset.")); cur_base_offset = cur_base_offset / ((int) TYPE_LENGTH (ptr_type)); vtable = gnuv3_get_vtable (gdbarch, type, address + embedded_offset); gdb_assert (vtable != NULL); vbase_array = value_field (vtable, vtable_field_vcall_and_vbase_offsets); base_offset = value_as_long (value_subscript (vbase_array, cur_base_offset)); return base_offset; }
static void ada_varobj_struct_elt (struct value *parent_value, struct type *parent_type, int fieldno, struct value **child_value, struct type **child_type) { struct value *value = NULL; struct type *type = NULL; if (parent_value) { value = value_field (parent_value, fieldno); type = value_type (value); } else type = TYPE_FIELD_TYPE (parent_type, fieldno); if (child_value) *child_value = value; if (child_type) *child_type = type; }
/* Return a virtual function as a value. ARG1 is the object which provides the virtual function table pointer. *ARG1P is side-effected in calling this function. F is the list of member functions which contains the desired virtual function. J is an index into F which provides the desired virtual function. TYPE is the type in which F is located. */ static struct value * gnuv2_virtual_fn_field (struct value **arg1p, struct fn_field * f, int j, struct type * type, int offset) { struct value *arg1 = *arg1p; struct type *type1 = check_typedef (value_type (arg1)); struct type *entry_type; /* First, get the virtual function table pointer. That comes with a strange type, so cast it to type `pointer to long' (which should serve just fine as a function type). Then, index into the table, and convert final value to appropriate function type. */ struct value *entry; struct value *vfn; struct value *vtbl; struct value *vi = value_from_longest (builtin_type_int, (LONGEST) TYPE_FN_FIELD_VOFFSET (f, j)); struct type *fcontext = TYPE_FN_FIELD_FCONTEXT (f, j); struct type *context; if (fcontext == NULL) /* We don't have an fcontext (e.g. the program was compiled with g++ version 1). Try to get the vtbl from the TYPE_VPTR_BASETYPE. This won't work right for multiple inheritance, but at least we should do as well as GDB 3.x did. */ fcontext = TYPE_VPTR_BASETYPE (type); context = lookup_pointer_type (fcontext); /* Now context is a pointer to the basetype containing the vtbl. */ if (TYPE_TARGET_TYPE (context) != type1) { struct value *tmp = value_cast (context, value_addr (arg1)); arg1 = value_ind (tmp); type1 = check_typedef (value_type (arg1)); } context = type1; /* Now context is the basetype containing the vtbl. */ /* This type may have been defined before its virtual function table was. If so, fill in the virtual function table entry for the type now. */ if (TYPE_VPTR_FIELDNO (context) < 0) fill_in_vptr_fieldno (context); /* The virtual function table is now an array of structures which have the form { int16 offset, delta; void *pfn; }. */ vtbl = value_primitive_field (arg1, 0, TYPE_VPTR_FIELDNO (context), TYPE_VPTR_BASETYPE (context)); /* With older versions of g++, the vtbl field pointed to an array of structures. Nowadays it points directly to the structure. */ if (TYPE_CODE (value_type (vtbl)) == TYPE_CODE_PTR && TYPE_CODE (TYPE_TARGET_TYPE (value_type (vtbl))) == TYPE_CODE_ARRAY) { /* Handle the case where the vtbl field points to an array of structures. */ vtbl = value_ind (vtbl); /* Index into the virtual function table. This is hard-coded because looking up a field is not cheap, and it may be important to save time, e.g. if the user has set a conditional breakpoint calling a virtual function. */ entry = value_subscript (vtbl, vi); } else { /* Handle the case where the vtbl field points directly to a structure. */ vtbl = value_add (vtbl, vi); entry = value_ind (vtbl); } entry_type = check_typedef (value_type (entry)); if (TYPE_CODE (entry_type) == TYPE_CODE_STRUCT) { /* Move the `this' pointer according to the virtual function table. */ set_value_offset (arg1, value_offset (arg1) + value_as_long (value_field (entry, 0))); if (!value_lazy (arg1)) { set_value_lazy (arg1, 1); value_fetch_lazy (arg1); } vfn = value_field (entry, 2); } else if (TYPE_CODE (entry_type) == TYPE_CODE_PTR) vfn = entry; else error (_("I'm confused: virtual function table has bad type")); /* Reinstantiate the function pointer with the correct type. */ deprecated_set_value_type (vfn, lookup_pointer_type (TYPE_FN_FIELD_TYPE (f, j))); *arg1p = arg1; return vfn; }
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 * gnuv3_rtti_type (struct value *value, int *full_p, int *top_p, int *using_enc_p) { struct gdbarch *gdbarch; struct type *values_type = check_typedef (value_type (value)); struct value *vtable; struct minimal_symbol *vtable_symbol; const char *vtable_symbol_name; const char *class_name; struct type *run_time_type; LONGEST offset_to_top; char *atsign; /* We only have RTTI for class objects. */ if (TYPE_CODE (values_type) != TYPE_CODE_CLASS) 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); if (using_enc_p) *using_enc_p = 0; vtable = gnuv3_get_vtable (gdbarch, value_type (value), value_as_address (value_addr (value))); if (vtable == NULL) return NULL; /* Find the linker symbol for this vtable. */ vtable_symbol = lookup_minimal_symbol_by_pc (value_address (vtable) + value_embedded_offset (vtable)).minsym; if (! vtable_symbol) return NULL; /* The symbol's demangled name should be something like "vtable for CLASS", where CLASS is the name of the run-time type of VALUE. If we didn't like this approach, we could instead look in the type_info object itself to get the class name. But this way should work just as well, and doesn't read target memory. */ vtable_symbol_name = SYMBOL_DEMANGLED_NAME (vtable_symbol); if (vtable_symbol_name == NULL || strncmp (vtable_symbol_name, "vtable for ", 11)) { warning (_("can't find linker symbol for virtual table for `%s' value"), TYPE_SAFE_NAME (values_type)); if (vtable_symbol_name) warning (_(" found `%s' instead"), vtable_symbol_name); return NULL; } class_name = vtable_symbol_name + 11; /* Strip off @plt and version suffixes. */ atsign = strchr (class_name, '@'); if (atsign != NULL) { char *copy; copy = alloca (atsign - class_name + 1); memcpy (copy, class_name, atsign - class_name); copy[atsign - class_name] = '\0'; class_name = copy; } /* Try to look up the class name as a type name. */ /* FIXME: chastain/2003-11-26: block=NULL is bogus. See pr gdb/1465. */ run_time_type = cp_lookup_rtti_type (class_name, NULL); if (run_time_type == NULL) return NULL; /* Get the offset from VALUE to the top of the complete object. NOTE: this is the reverse of the meaning of *TOP_P. */ offset_to_top = value_as_long (value_field (vtable, vtable_field_offset_to_top)); if (full_p) *full_p = (- offset_to_top == value_embedded_offset (value) && (TYPE_LENGTH (value_enclosing_type (value)) >= TYPE_LENGTH (run_time_type))); if (top_p) *top_p = - offset_to_top; return run_time_type; }
static void ppc_push_argument (struct ppc_stack_abi *abi, struct ppc_stack_context *c, struct value *arg, int argno, int do_copy, int floatonly) { struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch); struct type *type = check_typedef (value_type (arg)); int len = TYPE_LENGTH (type); gdb_byte buf[16]; c->argoffset = ROUND_UP (c->argoffset, 4); switch (TYPE_CODE (type)) { case TYPE_CODE_FLT: { if (c->freg <= abi->last_freg) { struct value *rval; struct type *rtype; int rlen; /* APPLE LOCAL: If the thing is already a long double type, don't cast it to a builtin type double, since there are two long double types, and we will pass an 16 byte long double wrong if we assume it is an 8 byte double. */ if (strcmp (TYPE_NAME (type), "long double") != 0) { rval = value_cast (builtin_type_double, arg); rtype = check_typedef (value_type (rval)); rlen = TYPE_LENGTH (rtype); } else { rval = arg; rtype = type; rlen = len; } /* APPLE LOCAL: GCC 4.0 has 16 byte long doubles */ if ((len != 4) && (len != 8) && (len != 16)) error ("floating point parameter had unexpected size"); if (rlen != 8 && rlen != 16) error ("floating point parameter had unexpected size"); if (do_copy) regcache_raw_write (current_regcache, FP0_REGNUM + c->freg, value_contents (rval)); if (do_copy && ! floatonly && abi->fregs_shadow_gregs) ppc_copy_into_greg (current_regcache, c->greg, tdep->wordsize, len, value_contents (arg)); if (do_copy && ! floatonly && abi->regs_shadow_stack) write_memory (c->sp + c->argoffset, value_contents (arg), len); c->freg++; /* APPLE LOCAL: We took up two registers... */ if (rlen == 16) c->freg++; if (! floatonly && (abi->fregs_shadow_gregs) && (c->greg <= abi->last_greg)) c->greg += len / 4; if (! floatonly && abi->regs_shadow_stack) c->argoffset += len; } else if (! floatonly) { if ((len != 4) && (len != 8) && (len != 16)) error ("floating point parameter had unexpected size"); c->argoffset = ROUND_UP (c->argoffset, len); if (do_copy) write_memory (c->sp + c->argoffset, value_contents (arg), len); c->argoffset += len; } break; } case TYPE_CODE_INT: case TYPE_CODE_ENUM: case TYPE_CODE_PTR: case TYPE_CODE_REF: { int nregs; gdb_byte *val_contents; if (floatonly) break; /* APPLE LOCAL: Huge Hack... The problem is that if we are a 32 bit app on Mac OS X, the registers are really 64 bits, but we don't want to pass all 64 bits. So if we get passed a value that came from a register, and it's length is > the wordsize, cast it to the wordsize first before passing it in. */ if (VALUE_REGNUM (arg) != -1 && len == 8 && tdep->wordsize == 4) { len = 4; val_contents = value_contents (arg) + 4; } else val_contents = value_contents (arg); /* END APPLE LOCAL */ nregs = (len <= 4) ? 1 : 2; if ((len != 1) && (len != 2) && (len != 4) && (len != 8)) error ("integer parameter had unexpected size"); if (c->greg <= abi->last_greg) { /* If the parameter fits in the remaining argument registers, write it to the registers, and to the stack if the abi requires it. */ if (do_copy) { /* Split the argument between registers & the stack if it doesn't fit in the remaining registers. */ int regs_avaliable = abi->last_greg - c->greg + 1; if (regs_avaliable >= nregs) regs_avaliable = nregs; ppc_copy_into_greg (current_regcache, c->greg, tdep->wordsize, regs_avaliable * 4, val_contents); } if (do_copy && abi->regs_shadow_stack) write_memory (c->sp + c->argoffset, val_contents, len); c->greg += nregs; if (abi->regs_shadow_stack) c->argoffset += (nregs * 4); } else { /* If we've filled up the registers, then just write it on the stack. */ if (do_copy) write_memory (c->sp + c->argoffset, val_contents, len); c->argoffset += (nregs * 4); } break; } case TYPE_CODE_STRUCT: case TYPE_CODE_UNION: { if (! abi->structs_with_args) { if (floatonly) break; if (len > 4) { /* Rounding to the nearest multiple of 8 may not be necessary, but it is safe. Particularly since we don't know the field types of the structure */ c->structoffset = ROUND_UP (c->structoffset, 8); if (do_copy) { write_memory (c->sp + c->structoffset, value_contents (arg), len); store_unsigned_integer (buf, 4, c->sp + c->structoffset); } c->structoffset += ROUND_UP (len, 8); } else if (do_copy) { memset (buf, 0, 4); memcpy (buf, value_contents (arg), len); } if (c->greg <= abi->last_greg) { if (do_copy) ppc_copy_into_greg (current_regcache, c->greg, tdep->wordsize, 4, buf); c->greg++; } else { if (do_copy) write_memory (c->sp + c->argoffset, buf, 4); c->argoffset += 4; } break; } else { int i; int regspace = (abi->last_greg - c->greg + 1) * 4; int stackspace = (len <= regspace) ? 0 : (len - regspace); int writereg = (regspace > len) ? len : regspace; int writestack = abi->regs_shadow_stack ? len : stackspace; for (i = 0; i < TYPE_NFIELDS (type); i++) { struct value *subarg = value_field (arg, i); ppc_push_argument (abi, c, subarg, argno, do_copy, 1); } if (floatonly) break; if (do_copy) { gdb_byte *ptr = value_contents (arg); if (len < 4) { memset (buf, 0, 4); if ((len == 1) || (len == 2)) memcpy (buf + 4 - len, ptr, len); else memcpy (buf, ptr, len); ptr = buf; } ppc_copy_into_greg (current_regcache, c->greg, tdep->wordsize, (writereg < 4) ? 4 : writereg, ptr); write_memory (c->sp + c->argoffset, ptr, (writestack < 4) ? 4 : writestack); } c->greg += ROUND_UP (writereg, 4) / 4; c->argoffset += writestack; } break; } case TYPE_CODE_ARRAY: { if (floatonly) break; if (! TYPE_VECTOR (type)) error ("non-vector array type"); if (len != 16) error ("unexpected vector length"); if (c->vreg <= abi->last_vreg) { if (do_copy) regcache_raw_write (current_regcache, tdep->ppc_vr0_regnum + c->vreg, value_contents (arg)); c->vreg++; } else { /* Vector arguments must be aligned to 16 bytes on the stack. */ c->argoffset = ROUND_UP (c->argoffset, 16); if (do_copy) write_memory (c->sp + c->argoffset, value_contents (arg), len); c->argoffset += len; } break; } default: error ("argument %d has unknown type code 0x%x (%s)", argno, TYPE_CODE (type), type_code_name (TYPE_CODE (type))); } return; }
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; }
/* Compute the offset of the baseclass which is the INDEXth baseclass of class TYPE, for value at VALADDR (in host) at ADDRESS (in target). The result is the offset of the baseclass value relative to (the address of)(ARG) + OFFSET. -1 is returned on error. */ static int gnuv3_baseclass_offset (struct type *type, int index, const bfd_byte *valaddr, CORE_ADDR address) { struct gdbarch *gdbarch; struct type *vtable_type; struct type *ptr_type; struct value *vtable; struct type *vbasetype; struct value *offset_val, *vbase_array; CORE_ADDR vtable_address; long int cur_base_offset, base_offset; int vbasetype_vptr_fieldno; /* Determine architecture. */ gdbarch = get_class_arch (type); vtable_type = gdbarch_data (gdbarch, vtable_type_gdbarch_data); 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. */ 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 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 complete inheritance graph based on the debug info. Neither is worthwhile. */ cur_base_offset = TYPE_BASECLASS_BITPOS (type, index) / 8; if (cur_base_offset >= - vtable_address_point_offset (gdbarch)) error (_("Expected a negative vbase offset (old compiler?)")); cur_base_offset = cur_base_offset + vtable_address_point_offset (gdbarch); if ((- cur_base_offset) % TYPE_LENGTH (ptr_type) != 0) error (_("Misaligned vbase offset.")); cur_base_offset = cur_base_offset / ((int) TYPE_LENGTH (ptr_type)); /* We're now looking for the cur_base_offset'th entry (negative index) in the vcall_and_vbase_offsets array. We used to cast the object to its TYPE_VPTR_BASETYPE, and reference the vtable as TYPE_VPTR_FIELDNO; however, that cast can not be done without calling baseclass_offset again if the TYPE_VPTR_BASETYPE is a virtual base class, as described in the v3 C++ ABI Section 2.4.I.2.b. Fortunately the ABI guarantees that the vtable pointer will be located at the beginning of the object, so we can bypass the casting. Verify that the TYPE_VPTR_FIELDNO is in fact at the start of whichever baseclass it resides in, as a sanity measure - iff we have debugging information for that baseclass. */ vbasetype = check_typedef (TYPE_VPTR_BASETYPE (type)); vbasetype_vptr_fieldno = get_vptr_fieldno (vbasetype, NULL); if (vbasetype_vptr_fieldno >= 0 && TYPE_FIELD_BITPOS (vbasetype, vbasetype_vptr_fieldno) != 0) error (_("Illegal vptr offset in class %s"), TYPE_NAME (vbasetype) ? TYPE_NAME (vbasetype) : "<unknown>"); vtable_address = value_as_address (value_at_lazy (ptr_type, address)); vtable = value_at_lazy (vtable_type, vtable_address - vtable_address_point_offset (gdbarch)); offset_val = value_from_longest (builtin_type_int32, cur_base_offset); vbase_array = value_field (vtable, vtable_field_vcall_and_vbase_offsets); base_offset = value_as_long (value_subscript (vbase_array, offset_val)); return base_offset; }
static struct type * gnuv3_rtti_type (struct value *value, int *full_p, int *top_p, int *using_enc_p) { struct gdbarch *gdbarch; struct type *vtable_type; struct type *values_type = check_typedef (value_type (value)); CORE_ADDR vtable_address; struct value *vtable; struct minimal_symbol *vtable_symbol; const char *vtable_symbol_name; const char *class_name; struct type *run_time_type; struct type *base_type; LONGEST offset_to_top; struct type *values_type_vptr_basetype; int values_type_vptr_fieldno; /* We only have RTTI for class objects. */ if (TYPE_CODE (values_type) != TYPE_CODE_CLASS) return NULL; /* This routine may be called for Java types that do not have a proper objfile. Just return NULL for those. */ if (!TYPE_OBJFILE (values_type) || !TYPE_OBJFILE (values_type)->obfd) return NULL; /* Determine architecture. */ gdbarch = get_class_arch (values_type); vtable_type = gdbarch_data (gdbarch, vtable_type_gdbarch_data); /* If we can't find the virtual table pointer for values_type, we can't find the RTTI. */ values_type_vptr_fieldno = get_vptr_fieldno (values_type, &values_type_vptr_basetype); if (values_type_vptr_fieldno == -1) return NULL; if (using_enc_p) *using_enc_p = 0; /* Fetch VALUE's virtual table pointer, and tweak it to point at an instance of our imaginary gdb_gnu_v3_abi_vtable structure. */ base_type = check_typedef (values_type_vptr_basetype); if (values_type != base_type) { value = value_cast (base_type, value); if (using_enc_p) *using_enc_p = 1; } vtable_address = value_as_address (value_field (value, values_type_vptr_fieldno)); vtable = value_at_lazy (vtable_type, vtable_address - vtable_address_point_offset (gdbarch)); /* Find the linker symbol for this vtable. */ vtable_symbol = lookup_minimal_symbol_by_pc (value_address (vtable) + value_embedded_offset (vtable)); if (! vtable_symbol) return NULL; /* The symbol's demangled name should be something like "vtable for CLASS", where CLASS is the name of the run-time type of VALUE. If we didn't like this approach, we could instead look in the type_info object itself to get the class name. But this way should work just as well, and doesn't read target memory. */ vtable_symbol_name = SYMBOL_DEMANGLED_NAME (vtable_symbol); if (vtable_symbol_name == NULL || strncmp (vtable_symbol_name, "vtable for ", 11)) { warning (_("can't find linker symbol for virtual table for `%s' value"), TYPE_NAME (values_type)); if (vtable_symbol_name) warning (_(" found `%s' instead"), vtable_symbol_name); return NULL; } class_name = vtable_symbol_name + 11; /* Try to look up the class name as a type name. */ /* FIXME: chastain/2003-11-26: block=NULL is bogus. See pr gdb/1465. */ run_time_type = cp_lookup_rtti_type (class_name, NULL); if (run_time_type == NULL) return NULL; /* Get the offset from VALUE to the top of the complete object. NOTE: this is the reverse of the meaning of *TOP_P. */ offset_to_top = value_as_long (value_field (vtable, vtable_field_offset_to_top)); if (full_p) *full_p = (- offset_to_top == value_embedded_offset (value) && (TYPE_LENGTH (value_enclosing_type (value)) >= TYPE_LENGTH (run_time_type))); if (top_p) *top_p = - offset_to_top; return run_time_type; }