static struct type * java_link_class_type (struct gdbarch *gdbarch, struct type *type, struct value *clas) { struct value *temp; const char *unqualified_name; const char *name = TYPE_TAG_NAME (type); int ninterfaces, nfields, nmethods; int type_is_object = 0; struct fn_field *fn_fields; struct fn_fieldlist *fn_fieldlists; struct value *fields; struct value *methods; struct value *method = NULL; struct value *field = NULL; int i, j; struct objfile *objfile = get_dynamics_objfile (gdbarch); struct type *tsuper; gdb_assert (name != NULL); unqualified_name = strrchr (name, '.'); if (unqualified_name == NULL) unqualified_name = name; temp = clas; temp = value_struct_elt (&temp, NULL, "superclass", NULL, "structure"); if (strcmp (name, "java.lang.Object") == 0) { tsuper = get_java_object_type (); if (tsuper && TYPE_CODE (tsuper) == TYPE_CODE_PTR) tsuper = TYPE_TARGET_TYPE (tsuper); type_is_object = 1; } else tsuper = type_from_class (gdbarch, temp); #if 1 ninterfaces = 0; #else temp = clas; ninterfaces = value_as_long (value_struct_elt (&temp, NULL, "interface_len", NULL, "structure")); #endif TYPE_N_BASECLASSES (type) = (tsuper == NULL ? 0 : 1) + ninterfaces; temp = clas; nfields = value_as_long (value_struct_elt (&temp, NULL, "field_count", NULL, "structure")); nfields += TYPE_N_BASECLASSES (type); nfields++; /* Add one for dummy "class" field. */ TYPE_NFIELDS (type) = nfields; TYPE_FIELDS (type) = (struct field *) TYPE_ALLOC (type, sizeof (struct field) * nfields); memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields); TYPE_FIELD_PRIVATE_BITS (type) = (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields); TYPE_FIELD_PROTECTED_BITS (type) = (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields); TYPE_FIELD_IGNORE_BITS (type) = (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields); TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *) TYPE_ALLOC (type, B_BYTES (TYPE_N_BASECLASSES (type))); B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), TYPE_N_BASECLASSES (type)); if (tsuper != NULL) { TYPE_BASECLASS (type, 0) = tsuper; if (type_is_object) SET_TYPE_FIELD_PRIVATE (type, 0); } i = strlen (name); if (i > 2 && name[i - 1] == ']' && tsuper != NULL) { /* FIXME */ TYPE_LENGTH (type) = TYPE_LENGTH (tsuper) + 4; /* size with "length" */ } else { temp = clas; temp = value_struct_elt (&temp, NULL, "size_in_bytes", NULL, "structure"); TYPE_LENGTH (type) = value_as_long (temp); } fields = NULL; nfields--; /* First set up dummy "class" field. */ SET_FIELD_PHYSADDR (TYPE_FIELD (type, nfields), value_address (clas)); TYPE_FIELD_NAME (type, nfields) = "class"; TYPE_FIELD_TYPE (type, nfields) = value_type (clas); SET_TYPE_FIELD_PRIVATE (type, nfields); for (i = TYPE_N_BASECLASSES (type); i < nfields; i++) { int accflags; int boffset; if (fields == NULL) { temp = clas; fields = value_struct_elt (&temp, NULL, "fields", NULL, "structure"); field = value_ind (fields); } else { /* Re-use field value for next field. */ CORE_ADDR addr = value_address (field) + TYPE_LENGTH (value_type (field)); set_value_address (field, addr); set_value_lazy (field, 1); } temp = field; temp = value_struct_elt (&temp, NULL, "name", NULL, "structure"); TYPE_FIELD_NAME (type, i) = get_java_utf8_name (&objfile->objfile_obstack, temp); temp = field; accflags = value_as_long (value_struct_elt (&temp, NULL, "accflags", NULL, "structure")); temp = field; temp = value_struct_elt (&temp, NULL, "info", NULL, "structure"); boffset = value_as_long (value_struct_elt (&temp, NULL, "boffset", NULL, "structure")); if (accflags & 0x0001) /* public access */ { /* ??? */ } if (accflags & 0x0002) /* private access */ { SET_TYPE_FIELD_PRIVATE (type, i); } if (accflags & 0x0004) /* protected access */ { SET_TYPE_FIELD_PROTECTED (type, i); } if (accflags & 0x0008) /* ACC_STATIC */ SET_FIELD_PHYSADDR (TYPE_FIELD (type, i), boffset); else SET_FIELD_BITPOS (TYPE_FIELD (type, i), 8 * boffset); if (accflags & 0x8000) /* FIELD_UNRESOLVED_FLAG */ { TYPE_FIELD_TYPE (type, i) = get_java_object_type (); /* FIXME */ } else { struct type *ftype; temp = field; temp = value_struct_elt (&temp, NULL, "type", NULL, "structure"); ftype = type_from_class (gdbarch, temp); if (TYPE_CODE (ftype) == TYPE_CODE_STRUCT) ftype = lookup_pointer_type (ftype); TYPE_FIELD_TYPE (type, i) = ftype; } } temp = clas; nmethods = value_as_long (value_struct_elt (&temp, NULL, "method_count", NULL, "structure")); j = nmethods * sizeof (struct fn_field); fn_fields = (struct fn_field *) obstack_alloc (&objfile->objfile_obstack, j); memset (fn_fields, 0, j); fn_fieldlists = (struct fn_fieldlist *) alloca (nmethods * sizeof (struct fn_fieldlist)); methods = NULL; for (i = 0; i < nmethods; i++) { const char *mname; int k; if (methods == NULL) { temp = clas; methods = value_struct_elt (&temp, NULL, "methods", NULL, "structure"); method = value_ind (methods); } else { /* Re-use method value for next method. */ CORE_ADDR addr = value_address (method) + TYPE_LENGTH (value_type (method)); set_value_address (method, addr); set_value_lazy (method, 1); } /* Get method name. */ temp = method; temp = value_struct_elt (&temp, NULL, "name", NULL, "structure"); mname = get_java_utf8_name (&objfile->objfile_obstack, temp); if (strcmp (mname, "<init>") == 0) mname = unqualified_name; /* Check for an existing method with the same name. * This makes building the fn_fieldslists an O(nmethods**2) * operation. That could be using hashing, but I doubt it * is worth it. Note that we do maintain the order of methods * in the inferior's Method table (as long as that is grouped * by method name), which I think is desirable. --PB */ for (k = 0, j = TYPE_NFN_FIELDS (type);;) { if (--j < 0) { /* No match - new method name. */ j = TYPE_NFN_FIELDS (type)++; fn_fieldlists[j].name = mname; fn_fieldlists[j].length = 1; fn_fieldlists[j].fn_fields = &fn_fields[i]; k = i; break; } if (strcmp (mname, fn_fieldlists[j].name) == 0) { /* Found an existing method with the same name. */ int l; if (mname != unqualified_name) obstack_free (&objfile->objfile_obstack, mname); mname = fn_fieldlists[j].name; fn_fieldlists[j].length++; k = i - k; /* Index of new slot. */ /* Shift intervening fn_fields (between k and i) down. */ for (l = i; l > k; l--) fn_fields[l] = fn_fields[l - 1]; for (l = TYPE_NFN_FIELDS (type); --l > j;) fn_fieldlists[l].fn_fields++; break; } k += fn_fieldlists[j].length; } fn_fields[k].physname = ""; fn_fields[k].is_stub = 1; /* FIXME */ fn_fields[k].type = lookup_function_type (builtin_java_type (gdbarch)->builtin_void); TYPE_CODE (fn_fields[k].type) = TYPE_CODE_METHOD; } j = TYPE_NFN_FIELDS (type) * sizeof (struct fn_fieldlist); TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *) obstack_alloc (&objfile->objfile_obstack, j); memcpy (TYPE_FN_FIELDLISTS (type), fn_fieldlists, j); return type; }
/* Return a GDB type representing `struct gdb_gnu_v3_abi_vtable', described above, laid out appropriately for ARCH. We use this function as the gdbarch per-architecture data initialization function. */ static void * build_gdb_vtable_type (struct gdbarch *arch) { struct type *t; struct field *field_list, *field; int offset; struct type *void_ptr_type = builtin_type (arch)->builtin_data_ptr; struct type *ptr_to_void_fn_type = builtin_type (arch)->builtin_func_ptr; /* ARCH can't give us the true ptrdiff_t type, so we guess. */ struct type *ptrdiff_type = arch_integer_type (arch, gdbarch_ptr_bit (arch), 0, "ptrdiff_t"); /* We assume no padding is necessary, since GDB doesn't know anything about alignment at the moment. If this assumption bites us, we should add a gdbarch method which, given a type, returns 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 = &field_list[0]; offset = 0; /* ptrdiff_t vcall_and_vbase_offsets[0]; */ FIELD_NAME (*field) = "vcall_and_vbase_offsets"; FIELD_TYPE (*field) = lookup_array_range_type (ptrdiff_type, 0, -1); SET_FIELD_BITPOS (*field, offset * TARGET_CHAR_BIT); offset += TYPE_LENGTH (FIELD_TYPE (*field)); field++; /* ptrdiff_t offset_to_top; */ FIELD_NAME (*field) = "offset_to_top"; FIELD_TYPE (*field) = ptrdiff_type; SET_FIELD_BITPOS (*field, offset * TARGET_CHAR_BIT); offset += TYPE_LENGTH (FIELD_TYPE (*field)); field++; /* void *type_info; */ FIELD_NAME (*field) = "type_info"; FIELD_TYPE (*field) = void_ptr_type; SET_FIELD_BITPOS (*field, offset * TARGET_CHAR_BIT); offset += TYPE_LENGTH (FIELD_TYPE (*field)); field++; /* void (*virtual_functions[0]) (); */ FIELD_NAME (*field) = "virtual_functions"; FIELD_TYPE (*field) = lookup_array_range_type (ptr_to_void_fn_type, 0, -1); SET_FIELD_BITPOS (*field, offset * TARGET_CHAR_BIT); offset += TYPE_LENGTH (FIELD_TYPE (*field)); field++; /* We assumed in the allocation above that there were four fields. */ gdb_assert (field == (field_list + 4)); t = arch_type (arch, TYPE_CODE_STRUCT, offset, NULL); TYPE_NFIELDS (t) = field - field_list; TYPE_FIELDS (t) = field_list; TYPE_TAG_NAME (t) = "gdb_gnu_v3_abi_vtable"; INIT_CPLUS_SPECIFIC (t); return t; }