1*5796c8dcSSimon Schubert /* Java language support routines for GDB, the GNU debugger. 2*5796c8dcSSimon Schubert 3*5796c8dcSSimon Schubert Copyright (C) 1997, 1998, 1999, 2000, 2003, 2004, 2005, 2007, 2008, 2009 4*5796c8dcSSimon Schubert Free Software Foundation, Inc. 5*5796c8dcSSimon Schubert 6*5796c8dcSSimon Schubert This file is part of GDB. 7*5796c8dcSSimon Schubert 8*5796c8dcSSimon Schubert This program is free software; you can redistribute it and/or modify 9*5796c8dcSSimon Schubert it under the terms of the GNU General Public License as published by 10*5796c8dcSSimon Schubert the Free Software Foundation; either version 3 of the License, or 11*5796c8dcSSimon Schubert (at your option) any later version. 12*5796c8dcSSimon Schubert 13*5796c8dcSSimon Schubert This program is distributed in the hope that it will be useful, 14*5796c8dcSSimon Schubert but WITHOUT ANY WARRANTY; without even the implied warranty of 15*5796c8dcSSimon Schubert MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16*5796c8dcSSimon Schubert GNU General Public License for more details. 17*5796c8dcSSimon Schubert 18*5796c8dcSSimon Schubert You should have received a copy of the GNU General Public License 19*5796c8dcSSimon Schubert along with this program. If not, see <http://www.gnu.org/licenses/>. */ 20*5796c8dcSSimon Schubert 21*5796c8dcSSimon Schubert #include "defs.h" 22*5796c8dcSSimon Schubert #include "symtab.h" 23*5796c8dcSSimon Schubert #include "gdbtypes.h" 24*5796c8dcSSimon Schubert #include "expression.h" 25*5796c8dcSSimon Schubert #include "parser-defs.h" 26*5796c8dcSSimon Schubert #include "language.h" 27*5796c8dcSSimon Schubert #include "gdbtypes.h" 28*5796c8dcSSimon Schubert #include "symtab.h" 29*5796c8dcSSimon Schubert #include "symfile.h" 30*5796c8dcSSimon Schubert #include "objfiles.h" 31*5796c8dcSSimon Schubert #include "gdb_string.h" 32*5796c8dcSSimon Schubert #include "value.h" 33*5796c8dcSSimon Schubert #include "c-lang.h" 34*5796c8dcSSimon Schubert #include "jv-lang.h" 35*5796c8dcSSimon Schubert #include "gdbcore.h" 36*5796c8dcSSimon Schubert #include "block.h" 37*5796c8dcSSimon Schubert #include "demangle.h" 38*5796c8dcSSimon Schubert #include "dictionary.h" 39*5796c8dcSSimon Schubert #include <ctype.h> 40*5796c8dcSSimon Schubert #include "gdb_assert.h" 41*5796c8dcSSimon Schubert 42*5796c8dcSSimon Schubert /* Local functions */ 43*5796c8dcSSimon Schubert 44*5796c8dcSSimon Schubert extern void _initialize_java_language (void); 45*5796c8dcSSimon Schubert 46*5796c8dcSSimon Schubert static int java_demangled_signature_length (char *); 47*5796c8dcSSimon Schubert static void java_demangled_signature_copy (char *, char *); 48*5796c8dcSSimon Schubert 49*5796c8dcSSimon Schubert static struct symtab *get_java_class_symtab (void); 50*5796c8dcSSimon Schubert static char *get_java_utf8_name (struct obstack *obstack, struct value *name); 51*5796c8dcSSimon Schubert static int java_class_is_primitive (struct value *clas); 52*5796c8dcSSimon Schubert static struct value *java_value_string (char *ptr, int len); 53*5796c8dcSSimon Schubert 54*5796c8dcSSimon Schubert static void java_emit_char (int c, struct type *type, 55*5796c8dcSSimon Schubert struct ui_file * stream, int quoter); 56*5796c8dcSSimon Schubert 57*5796c8dcSSimon Schubert static char *java_class_name_from_physname (const char *physname); 58*5796c8dcSSimon Schubert 59*5796c8dcSSimon Schubert /* This objfile contains symtabs that have been dynamically created 60*5796c8dcSSimon Schubert to record dynamically loaded Java classes and dynamically 61*5796c8dcSSimon Schubert compiled java methods. */ 62*5796c8dcSSimon Schubert 63*5796c8dcSSimon Schubert static struct objfile *dynamics_objfile = NULL; 64*5796c8dcSSimon Schubert 65*5796c8dcSSimon Schubert static struct type *java_link_class_type (struct gdbarch *, 66*5796c8dcSSimon Schubert struct type *, struct value *); 67*5796c8dcSSimon Schubert 68*5796c8dcSSimon Schubert /* FIXME: carlton/2003-02-04: This is the main or only caller of 69*5796c8dcSSimon Schubert allocate_objfile with first argument NULL; as a result, this code 70*5796c8dcSSimon Schubert breaks every so often. Somebody should write a test case that 71*5796c8dcSSimon Schubert exercises GDB in various ways (e.g. something involving loading a 72*5796c8dcSSimon Schubert dynamic library) after this code has been called. */ 73*5796c8dcSSimon Schubert 74*5796c8dcSSimon Schubert static struct objfile * 75*5796c8dcSSimon Schubert get_dynamics_objfile (void) 76*5796c8dcSSimon Schubert { 77*5796c8dcSSimon Schubert if (dynamics_objfile == NULL) 78*5796c8dcSSimon Schubert { 79*5796c8dcSSimon Schubert dynamics_objfile = allocate_objfile (NULL, 0); 80*5796c8dcSSimon Schubert } 81*5796c8dcSSimon Schubert return dynamics_objfile; 82*5796c8dcSSimon Schubert } 83*5796c8dcSSimon Schubert 84*5796c8dcSSimon Schubert #if 1 85*5796c8dcSSimon Schubert /* symtab contains classes read from the inferior. */ 86*5796c8dcSSimon Schubert 87*5796c8dcSSimon Schubert static struct symtab *class_symtab = NULL; 88*5796c8dcSSimon Schubert 89*5796c8dcSSimon Schubert static void free_class_block (struct symtab *symtab); 90*5796c8dcSSimon Schubert 91*5796c8dcSSimon Schubert static struct symtab * 92*5796c8dcSSimon Schubert get_java_class_symtab (void) 93*5796c8dcSSimon Schubert { 94*5796c8dcSSimon Schubert if (class_symtab == NULL) 95*5796c8dcSSimon Schubert { 96*5796c8dcSSimon Schubert struct objfile *objfile = get_dynamics_objfile (); 97*5796c8dcSSimon Schubert struct blockvector *bv; 98*5796c8dcSSimon Schubert struct block *bl; 99*5796c8dcSSimon Schubert class_symtab = allocate_symtab ("<java-classes>", objfile); 100*5796c8dcSSimon Schubert class_symtab->language = language_java; 101*5796c8dcSSimon Schubert bv = (struct blockvector *) 102*5796c8dcSSimon Schubert obstack_alloc (&objfile->objfile_obstack, 103*5796c8dcSSimon Schubert sizeof (struct blockvector) + sizeof (struct block *)); 104*5796c8dcSSimon Schubert BLOCKVECTOR_NBLOCKS (bv) = 1; 105*5796c8dcSSimon Schubert BLOCKVECTOR (class_symtab) = bv; 106*5796c8dcSSimon Schubert 107*5796c8dcSSimon Schubert /* Allocate dummy STATIC_BLOCK. */ 108*5796c8dcSSimon Schubert bl = allocate_block (&objfile->objfile_obstack); 109*5796c8dcSSimon Schubert BLOCK_DICT (bl) = dict_create_linear (&objfile->objfile_obstack, 110*5796c8dcSSimon Schubert NULL); 111*5796c8dcSSimon Schubert BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK) = bl; 112*5796c8dcSSimon Schubert 113*5796c8dcSSimon Schubert /* Allocate GLOBAL_BLOCK. */ 114*5796c8dcSSimon Schubert bl = allocate_block (&objfile->objfile_obstack); 115*5796c8dcSSimon Schubert BLOCK_DICT (bl) = dict_create_hashed_expandable (); 116*5796c8dcSSimon Schubert BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK) = bl; 117*5796c8dcSSimon Schubert class_symtab->free_func = free_class_block; 118*5796c8dcSSimon Schubert } 119*5796c8dcSSimon Schubert return class_symtab; 120*5796c8dcSSimon Schubert } 121*5796c8dcSSimon Schubert 122*5796c8dcSSimon Schubert static void 123*5796c8dcSSimon Schubert add_class_symtab_symbol (struct symbol *sym) 124*5796c8dcSSimon Schubert { 125*5796c8dcSSimon Schubert struct symtab *symtab = get_java_class_symtab (); 126*5796c8dcSSimon Schubert struct blockvector *bv = BLOCKVECTOR (symtab); 127*5796c8dcSSimon Schubert dict_add_symbol (BLOCK_DICT (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)), sym); 128*5796c8dcSSimon Schubert } 129*5796c8dcSSimon Schubert 130*5796c8dcSSimon Schubert static struct symbol *add_class_symbol (struct type *type, CORE_ADDR addr); 131*5796c8dcSSimon Schubert 132*5796c8dcSSimon Schubert static struct symbol * 133*5796c8dcSSimon Schubert add_class_symbol (struct type *type, CORE_ADDR addr) 134*5796c8dcSSimon Schubert { 135*5796c8dcSSimon Schubert struct symbol *sym; 136*5796c8dcSSimon Schubert sym = (struct symbol *) 137*5796c8dcSSimon Schubert obstack_alloc (&dynamics_objfile->objfile_obstack, sizeof (struct symbol)); 138*5796c8dcSSimon Schubert memset (sym, 0, sizeof (struct symbol)); 139*5796c8dcSSimon Schubert SYMBOL_LANGUAGE (sym) = language_java; 140*5796c8dcSSimon Schubert SYMBOL_SET_LINKAGE_NAME (sym, TYPE_TAG_NAME (type)); 141*5796c8dcSSimon Schubert SYMBOL_CLASS (sym) = LOC_TYPEDEF; 142*5796c8dcSSimon Schubert /* SYMBOL_VALUE (sym) = valu; */ 143*5796c8dcSSimon Schubert SYMBOL_TYPE (sym) = type; 144*5796c8dcSSimon Schubert SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN; 145*5796c8dcSSimon Schubert SYMBOL_VALUE_ADDRESS (sym) = addr; 146*5796c8dcSSimon Schubert return sym; 147*5796c8dcSSimon Schubert } 148*5796c8dcSSimon Schubert 149*5796c8dcSSimon Schubert /* Free the dynamic symbols block. */ 150*5796c8dcSSimon Schubert static void 151*5796c8dcSSimon Schubert free_class_block (struct symtab *symtab) 152*5796c8dcSSimon Schubert { 153*5796c8dcSSimon Schubert struct blockvector *bv = BLOCKVECTOR (symtab); 154*5796c8dcSSimon Schubert struct block *bl = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK); 155*5796c8dcSSimon Schubert 156*5796c8dcSSimon Schubert dict_free (BLOCK_DICT (bl)); 157*5796c8dcSSimon Schubert } 158*5796c8dcSSimon Schubert #endif 159*5796c8dcSSimon Schubert 160*5796c8dcSSimon Schubert struct type * 161*5796c8dcSSimon Schubert java_lookup_class (char *name) 162*5796c8dcSSimon Schubert { 163*5796c8dcSSimon Schubert struct symbol *sym; 164*5796c8dcSSimon Schubert sym = lookup_symbol (name, expression_context_block, STRUCT_DOMAIN, NULL); 165*5796c8dcSSimon Schubert if (sym != NULL) 166*5796c8dcSSimon Schubert return SYMBOL_TYPE (sym); 167*5796c8dcSSimon Schubert #if 0 168*5796c8dcSSimon Schubert CORE_ADDR addr; 169*5796c8dcSSimon Schubert if (called from parser) 170*5796c8dcSSimon Schubert { 171*5796c8dcSSimon Schubert call lookup_class (or similar) in inferior; 172*5796c8dcSSimon Schubert if not 173*5796c8dcSSimon Schubert found: 174*5796c8dcSSimon Schubert return NULL; 175*5796c8dcSSimon Schubert addr = found in inferior; 176*5796c8dcSSimon Schubert } 177*5796c8dcSSimon Schubert else 178*5796c8dcSSimon Schubert addr = 0; 179*5796c8dcSSimon Schubert struct type *type; 180*5796c8dcSSimon Schubert type = alloc_type (objfile); 181*5796c8dcSSimon Schubert TYPE_CODE (type) = TYPE_CODE_STRUCT; 182*5796c8dcSSimon Schubert INIT_CPLUS_SPECIFIC (type); 183*5796c8dcSSimon Schubert TYPE_TAG_NAME (type) = obsavestring (name, strlen (name), &objfile->objfile_obstack); 184*5796c8dcSSimon Schubert TYPE_STUB (type) = 1; 185*5796c8dcSSimon Schubert TYPE ? = addr; 186*5796c8dcSSimon Schubert return type; 187*5796c8dcSSimon Schubert #else 188*5796c8dcSSimon Schubert /* FIXME - should search inferior's symbol table. */ 189*5796c8dcSSimon Schubert return NULL; 190*5796c8dcSSimon Schubert #endif 191*5796c8dcSSimon Schubert } 192*5796c8dcSSimon Schubert 193*5796c8dcSSimon Schubert /* Return a nul-terminated string (allocated on OBSTACK) for 194*5796c8dcSSimon Schubert a name given by NAME (which has type Utf8Const*). */ 195*5796c8dcSSimon Schubert 196*5796c8dcSSimon Schubert char * 197*5796c8dcSSimon Schubert get_java_utf8_name (struct obstack *obstack, struct value *name) 198*5796c8dcSSimon Schubert { 199*5796c8dcSSimon Schubert char *chrs; 200*5796c8dcSSimon Schubert struct value *temp = name; 201*5796c8dcSSimon Schubert int name_length; 202*5796c8dcSSimon Schubert CORE_ADDR data_addr; 203*5796c8dcSSimon Schubert temp = value_struct_elt (&temp, NULL, "length", NULL, "structure"); 204*5796c8dcSSimon Schubert name_length = (int) value_as_long (temp); 205*5796c8dcSSimon Schubert data_addr = value_address (temp) + TYPE_LENGTH (value_type (temp)); 206*5796c8dcSSimon Schubert chrs = obstack_alloc (obstack, name_length + 1); 207*5796c8dcSSimon Schubert chrs[name_length] = '\0'; 208*5796c8dcSSimon Schubert read_memory (data_addr, (gdb_byte *) chrs, name_length); 209*5796c8dcSSimon Schubert return chrs; 210*5796c8dcSSimon Schubert } 211*5796c8dcSSimon Schubert 212*5796c8dcSSimon Schubert struct value * 213*5796c8dcSSimon Schubert java_class_from_object (struct value *obj_val) 214*5796c8dcSSimon Schubert { 215*5796c8dcSSimon Schubert /* This is all rather inefficient, since the offsets of vtable and 216*5796c8dcSSimon Schubert class are fixed. FIXME */ 217*5796c8dcSSimon Schubert struct value *vtable_val; 218*5796c8dcSSimon Schubert 219*5796c8dcSSimon Schubert if (TYPE_CODE (value_type (obj_val)) == TYPE_CODE_PTR 220*5796c8dcSSimon Schubert && TYPE_LENGTH (TYPE_TARGET_TYPE (value_type (obj_val))) == 0) 221*5796c8dcSSimon Schubert obj_val = value_at (get_java_object_type (), 222*5796c8dcSSimon Schubert value_as_address (obj_val)); 223*5796c8dcSSimon Schubert 224*5796c8dcSSimon Schubert vtable_val = value_struct_elt (&obj_val, NULL, "vtable", NULL, "structure"); 225*5796c8dcSSimon Schubert return value_struct_elt (&vtable_val, NULL, "class", NULL, "structure"); 226*5796c8dcSSimon Schubert } 227*5796c8dcSSimon Schubert 228*5796c8dcSSimon Schubert /* Check if CLASS_IS_PRIMITIVE(value of clas): */ 229*5796c8dcSSimon Schubert static int 230*5796c8dcSSimon Schubert java_class_is_primitive (struct value *clas) 231*5796c8dcSSimon Schubert { 232*5796c8dcSSimon Schubert struct value *vtable = value_struct_elt (&clas, NULL, "vtable", NULL, "struct"); 233*5796c8dcSSimon Schubert CORE_ADDR i = value_as_address (vtable); 234*5796c8dcSSimon Schubert return (int) (i & 0x7fffffff) == (int) 0x7fffffff; 235*5796c8dcSSimon Schubert } 236*5796c8dcSSimon Schubert 237*5796c8dcSSimon Schubert /* Read a GCJ Class object, and generated a gdb (TYPE_CODE_STRUCT) type. */ 238*5796c8dcSSimon Schubert 239*5796c8dcSSimon Schubert struct type * 240*5796c8dcSSimon Schubert type_from_class (struct gdbarch *gdbarch, struct value *clas) 241*5796c8dcSSimon Schubert { 242*5796c8dcSSimon Schubert struct type *type; 243*5796c8dcSSimon Schubert char *name; 244*5796c8dcSSimon Schubert struct value *temp; 245*5796c8dcSSimon Schubert struct objfile *objfile; 246*5796c8dcSSimon Schubert struct value *utf8_name; 247*5796c8dcSSimon Schubert char *nptr; 248*5796c8dcSSimon Schubert CORE_ADDR addr; 249*5796c8dcSSimon Schubert struct block *bl; 250*5796c8dcSSimon Schubert struct dict_iterator iter; 251*5796c8dcSSimon Schubert int is_array = 0; 252*5796c8dcSSimon Schubert 253*5796c8dcSSimon Schubert type = check_typedef (value_type (clas)); 254*5796c8dcSSimon Schubert if (TYPE_CODE (type) == TYPE_CODE_PTR) 255*5796c8dcSSimon Schubert { 256*5796c8dcSSimon Schubert if (value_logical_not (clas)) 257*5796c8dcSSimon Schubert return NULL; 258*5796c8dcSSimon Schubert clas = value_ind (clas); 259*5796c8dcSSimon Schubert } 260*5796c8dcSSimon Schubert addr = value_address (clas); 261*5796c8dcSSimon Schubert 262*5796c8dcSSimon Schubert #if 0 263*5796c8dcSSimon Schubert get_java_class_symtab (); 264*5796c8dcSSimon Schubert bl = BLOCKVECTOR_BLOCK (BLOCKVECTOR (class_symtab), GLOBAL_BLOCK); 265*5796c8dcSSimon Schubert ALL_BLOCK_SYMBOLS (block, iter, sym) 266*5796c8dcSSimon Schubert { 267*5796c8dcSSimon Schubert if (SYMBOL_VALUE_ADDRESS (sym) == addr) 268*5796c8dcSSimon Schubert return SYMBOL_TYPE (sym); 269*5796c8dcSSimon Schubert } 270*5796c8dcSSimon Schubert #endif 271*5796c8dcSSimon Schubert 272*5796c8dcSSimon Schubert objfile = get_dynamics_objfile (); 273*5796c8dcSSimon Schubert if (java_class_is_primitive (clas)) 274*5796c8dcSSimon Schubert { 275*5796c8dcSSimon Schubert struct value *sig; 276*5796c8dcSSimon Schubert temp = clas; 277*5796c8dcSSimon Schubert sig = value_struct_elt (&temp, NULL, "method_count", NULL, "structure"); 278*5796c8dcSSimon Schubert return java_primitive_type (gdbarch, value_as_long (sig)); 279*5796c8dcSSimon Schubert } 280*5796c8dcSSimon Schubert 281*5796c8dcSSimon Schubert /* Get Class name. */ 282*5796c8dcSSimon Schubert /* if clasloader non-null, prepend loader address. FIXME */ 283*5796c8dcSSimon Schubert temp = clas; 284*5796c8dcSSimon Schubert utf8_name = value_struct_elt (&temp, NULL, "name", NULL, "structure"); 285*5796c8dcSSimon Schubert name = get_java_utf8_name (&objfile->objfile_obstack, utf8_name); 286*5796c8dcSSimon Schubert for (nptr = name; *nptr != 0; nptr++) 287*5796c8dcSSimon Schubert { 288*5796c8dcSSimon Schubert if (*nptr == '/') 289*5796c8dcSSimon Schubert *nptr = '.'; 290*5796c8dcSSimon Schubert } 291*5796c8dcSSimon Schubert 292*5796c8dcSSimon Schubert type = java_lookup_class (name); 293*5796c8dcSSimon Schubert if (type != NULL) 294*5796c8dcSSimon Schubert return type; 295*5796c8dcSSimon Schubert 296*5796c8dcSSimon Schubert /* Do not use the "fake" dynamics objfile to own dynamically generated 297*5796c8dcSSimon Schubert types, as it does not provide an architecture, and it would not help 298*5796c8dcSSimon Schubert manage the lifetime of these types anyway. */ 299*5796c8dcSSimon Schubert type = alloc_type_arch (gdbarch); 300*5796c8dcSSimon Schubert TYPE_CODE (type) = TYPE_CODE_STRUCT; 301*5796c8dcSSimon Schubert INIT_CPLUS_SPECIFIC (type); 302*5796c8dcSSimon Schubert 303*5796c8dcSSimon Schubert if (name[0] == '[') 304*5796c8dcSSimon Schubert { 305*5796c8dcSSimon Schubert char *signature = name; 306*5796c8dcSSimon Schubert int namelen = java_demangled_signature_length (signature); 307*5796c8dcSSimon Schubert if (namelen > strlen (name)) 308*5796c8dcSSimon Schubert name = obstack_alloc (&objfile->objfile_obstack, namelen + 1); 309*5796c8dcSSimon Schubert java_demangled_signature_copy (name, signature); 310*5796c8dcSSimon Schubert name[namelen] = '\0'; 311*5796c8dcSSimon Schubert is_array = 1; 312*5796c8dcSSimon Schubert temp = clas; 313*5796c8dcSSimon Schubert /* Set array element type. */ 314*5796c8dcSSimon Schubert temp = value_struct_elt (&temp, NULL, "methods", NULL, "structure"); 315*5796c8dcSSimon Schubert deprecated_set_value_type (temp, lookup_pointer_type (value_type (clas))); 316*5796c8dcSSimon Schubert TYPE_TARGET_TYPE (type) = type_from_class (gdbarch, temp); 317*5796c8dcSSimon Schubert } 318*5796c8dcSSimon Schubert 319*5796c8dcSSimon Schubert ALLOCATE_CPLUS_STRUCT_TYPE (type); 320*5796c8dcSSimon Schubert TYPE_TAG_NAME (type) = name; 321*5796c8dcSSimon Schubert 322*5796c8dcSSimon Schubert add_class_symtab_symbol (add_class_symbol (type, addr)); 323*5796c8dcSSimon Schubert return java_link_class_type (gdbarch, type, clas); 324*5796c8dcSSimon Schubert } 325*5796c8dcSSimon Schubert 326*5796c8dcSSimon Schubert /* Fill in class TYPE with data from the CLAS value. */ 327*5796c8dcSSimon Schubert 328*5796c8dcSSimon Schubert struct type * 329*5796c8dcSSimon Schubert java_link_class_type (struct gdbarch *gdbarch, 330*5796c8dcSSimon Schubert struct type *type, struct value *clas) 331*5796c8dcSSimon Schubert { 332*5796c8dcSSimon Schubert struct value *temp; 333*5796c8dcSSimon Schubert char *unqualified_name; 334*5796c8dcSSimon Schubert char *name = TYPE_TAG_NAME (type); 335*5796c8dcSSimon Schubert int ninterfaces, nfields, nmethods; 336*5796c8dcSSimon Schubert int type_is_object = 0; 337*5796c8dcSSimon Schubert struct fn_field *fn_fields; 338*5796c8dcSSimon Schubert struct fn_fieldlist *fn_fieldlists; 339*5796c8dcSSimon Schubert struct value *fields; 340*5796c8dcSSimon Schubert struct value *methods; 341*5796c8dcSSimon Schubert struct value *method = NULL; 342*5796c8dcSSimon Schubert struct value *field = NULL; 343*5796c8dcSSimon Schubert int i, j; 344*5796c8dcSSimon Schubert struct objfile *objfile = get_dynamics_objfile (); 345*5796c8dcSSimon Schubert struct type *tsuper; 346*5796c8dcSSimon Schubert 347*5796c8dcSSimon Schubert gdb_assert (name != NULL); 348*5796c8dcSSimon Schubert unqualified_name = strrchr (name, '.'); 349*5796c8dcSSimon Schubert if (unqualified_name == NULL) 350*5796c8dcSSimon Schubert unqualified_name = name; 351*5796c8dcSSimon Schubert 352*5796c8dcSSimon Schubert temp = clas; 353*5796c8dcSSimon Schubert temp = value_struct_elt (&temp, NULL, "superclass", NULL, "structure"); 354*5796c8dcSSimon Schubert if (strcmp (name, "java.lang.Object") == 0) 355*5796c8dcSSimon Schubert { 356*5796c8dcSSimon Schubert tsuper = get_java_object_type (); 357*5796c8dcSSimon Schubert if (tsuper && TYPE_CODE (tsuper) == TYPE_CODE_PTR) 358*5796c8dcSSimon Schubert tsuper = TYPE_TARGET_TYPE (tsuper); 359*5796c8dcSSimon Schubert type_is_object = 1; 360*5796c8dcSSimon Schubert } 361*5796c8dcSSimon Schubert else 362*5796c8dcSSimon Schubert tsuper = type_from_class (gdbarch, temp); 363*5796c8dcSSimon Schubert 364*5796c8dcSSimon Schubert #if 1 365*5796c8dcSSimon Schubert ninterfaces = 0; 366*5796c8dcSSimon Schubert #else 367*5796c8dcSSimon Schubert temp = clas; 368*5796c8dcSSimon Schubert ninterfaces = value_as_long (value_struct_elt (&temp, NULL, "interface_len", NULL, "structure")); 369*5796c8dcSSimon Schubert #endif 370*5796c8dcSSimon Schubert TYPE_N_BASECLASSES (type) = (tsuper == NULL ? 0 : 1) + ninterfaces; 371*5796c8dcSSimon Schubert temp = clas; 372*5796c8dcSSimon Schubert nfields = value_as_long (value_struct_elt (&temp, NULL, "field_count", NULL, "structure")); 373*5796c8dcSSimon Schubert nfields += TYPE_N_BASECLASSES (type); 374*5796c8dcSSimon Schubert nfields++; /* Add one for dummy "class" field. */ 375*5796c8dcSSimon Schubert TYPE_NFIELDS (type) = nfields; 376*5796c8dcSSimon Schubert TYPE_FIELDS (type) = (struct field *) 377*5796c8dcSSimon Schubert TYPE_ALLOC (type, sizeof (struct field) * nfields); 378*5796c8dcSSimon Schubert 379*5796c8dcSSimon Schubert memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields); 380*5796c8dcSSimon Schubert 381*5796c8dcSSimon Schubert TYPE_FIELD_PRIVATE_BITS (type) = 382*5796c8dcSSimon Schubert (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); 383*5796c8dcSSimon Schubert B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields); 384*5796c8dcSSimon Schubert 385*5796c8dcSSimon Schubert TYPE_FIELD_PROTECTED_BITS (type) = 386*5796c8dcSSimon Schubert (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); 387*5796c8dcSSimon Schubert B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields); 388*5796c8dcSSimon Schubert 389*5796c8dcSSimon Schubert TYPE_FIELD_IGNORE_BITS (type) = 390*5796c8dcSSimon Schubert (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); 391*5796c8dcSSimon Schubert B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields); 392*5796c8dcSSimon Schubert 393*5796c8dcSSimon Schubert TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *) 394*5796c8dcSSimon Schubert TYPE_ALLOC (type, B_BYTES (TYPE_N_BASECLASSES (type))); 395*5796c8dcSSimon Schubert B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), TYPE_N_BASECLASSES (type)); 396*5796c8dcSSimon Schubert 397*5796c8dcSSimon Schubert if (tsuper != NULL) 398*5796c8dcSSimon Schubert { 399*5796c8dcSSimon Schubert TYPE_BASECLASS (type, 0) = tsuper; 400*5796c8dcSSimon Schubert if (type_is_object) 401*5796c8dcSSimon Schubert SET_TYPE_FIELD_PRIVATE (type, 0); 402*5796c8dcSSimon Schubert } 403*5796c8dcSSimon Schubert 404*5796c8dcSSimon Schubert i = strlen (name); 405*5796c8dcSSimon Schubert if (i > 2 && name[i - 1] == ']' && tsuper != NULL) 406*5796c8dcSSimon Schubert { 407*5796c8dcSSimon Schubert /* FIXME */ 408*5796c8dcSSimon Schubert TYPE_LENGTH (type) = TYPE_LENGTH (tsuper) + 4; /* size with "length" */ 409*5796c8dcSSimon Schubert } 410*5796c8dcSSimon Schubert else 411*5796c8dcSSimon Schubert { 412*5796c8dcSSimon Schubert temp = clas; 413*5796c8dcSSimon Schubert temp = value_struct_elt (&temp, NULL, "size_in_bytes", NULL, "structure"); 414*5796c8dcSSimon Schubert TYPE_LENGTH (type) = value_as_long (temp); 415*5796c8dcSSimon Schubert } 416*5796c8dcSSimon Schubert 417*5796c8dcSSimon Schubert fields = NULL; 418*5796c8dcSSimon Schubert nfields--; /* First set up dummy "class" field. */ 419*5796c8dcSSimon Schubert SET_FIELD_PHYSADDR (TYPE_FIELD (type, nfields), value_address (clas)); 420*5796c8dcSSimon Schubert TYPE_FIELD_NAME (type, nfields) = "class"; 421*5796c8dcSSimon Schubert TYPE_FIELD_TYPE (type, nfields) = value_type (clas); 422*5796c8dcSSimon Schubert SET_TYPE_FIELD_PRIVATE (type, nfields); 423*5796c8dcSSimon Schubert 424*5796c8dcSSimon Schubert for (i = TYPE_N_BASECLASSES (type); i < nfields; i++) 425*5796c8dcSSimon Schubert { 426*5796c8dcSSimon Schubert int accflags; 427*5796c8dcSSimon Schubert int boffset; 428*5796c8dcSSimon Schubert if (fields == NULL) 429*5796c8dcSSimon Schubert { 430*5796c8dcSSimon Schubert temp = clas; 431*5796c8dcSSimon Schubert fields = value_struct_elt (&temp, NULL, "fields", NULL, "structure"); 432*5796c8dcSSimon Schubert field = value_ind (fields); 433*5796c8dcSSimon Schubert } 434*5796c8dcSSimon Schubert else 435*5796c8dcSSimon Schubert { /* Re-use field value for next field. */ 436*5796c8dcSSimon Schubert CORE_ADDR addr 437*5796c8dcSSimon Schubert = value_address (field) + TYPE_LENGTH (value_type (field)); 438*5796c8dcSSimon Schubert set_value_address (field, addr); 439*5796c8dcSSimon Schubert set_value_lazy (field, 1); 440*5796c8dcSSimon Schubert } 441*5796c8dcSSimon Schubert temp = field; 442*5796c8dcSSimon Schubert temp = value_struct_elt (&temp, NULL, "name", NULL, "structure"); 443*5796c8dcSSimon Schubert TYPE_FIELD_NAME (type, i) = 444*5796c8dcSSimon Schubert get_java_utf8_name (&objfile->objfile_obstack, temp); 445*5796c8dcSSimon Schubert temp = field; 446*5796c8dcSSimon Schubert accflags = value_as_long (value_struct_elt (&temp, NULL, "accflags", 447*5796c8dcSSimon Schubert NULL, "structure")); 448*5796c8dcSSimon Schubert temp = field; 449*5796c8dcSSimon Schubert temp = value_struct_elt (&temp, NULL, "info", NULL, "structure"); 450*5796c8dcSSimon Schubert boffset = value_as_long (value_struct_elt (&temp, NULL, "boffset", 451*5796c8dcSSimon Schubert NULL, "structure")); 452*5796c8dcSSimon Schubert if (accflags & 0x0001) /* public access */ 453*5796c8dcSSimon Schubert { 454*5796c8dcSSimon Schubert /* ??? */ 455*5796c8dcSSimon Schubert } 456*5796c8dcSSimon Schubert if (accflags & 0x0002) /* private access */ 457*5796c8dcSSimon Schubert { 458*5796c8dcSSimon Schubert SET_TYPE_FIELD_PRIVATE (type, i); 459*5796c8dcSSimon Schubert } 460*5796c8dcSSimon Schubert if (accflags & 0x0004) /* protected access */ 461*5796c8dcSSimon Schubert { 462*5796c8dcSSimon Schubert SET_TYPE_FIELD_PROTECTED (type, i); 463*5796c8dcSSimon Schubert } 464*5796c8dcSSimon Schubert if (accflags & 0x0008) /* ACC_STATIC */ 465*5796c8dcSSimon Schubert SET_FIELD_PHYSADDR (TYPE_FIELD (type, i), boffset); 466*5796c8dcSSimon Schubert else 467*5796c8dcSSimon Schubert TYPE_FIELD_BITPOS (type, i) = 8 * boffset; 468*5796c8dcSSimon Schubert if (accflags & 0x8000) /* FIELD_UNRESOLVED_FLAG */ 469*5796c8dcSSimon Schubert { 470*5796c8dcSSimon Schubert TYPE_FIELD_TYPE (type, i) = get_java_object_type (); /* FIXME */ 471*5796c8dcSSimon Schubert } 472*5796c8dcSSimon Schubert else 473*5796c8dcSSimon Schubert { 474*5796c8dcSSimon Schubert struct type *ftype; 475*5796c8dcSSimon Schubert temp = field; 476*5796c8dcSSimon Schubert temp = value_struct_elt (&temp, NULL, "type", NULL, "structure"); 477*5796c8dcSSimon Schubert ftype = type_from_class (gdbarch, temp); 478*5796c8dcSSimon Schubert if (TYPE_CODE (ftype) == TYPE_CODE_STRUCT) 479*5796c8dcSSimon Schubert ftype = lookup_pointer_type (ftype); 480*5796c8dcSSimon Schubert TYPE_FIELD_TYPE (type, i) = ftype; 481*5796c8dcSSimon Schubert } 482*5796c8dcSSimon Schubert } 483*5796c8dcSSimon Schubert 484*5796c8dcSSimon Schubert temp = clas; 485*5796c8dcSSimon Schubert nmethods = value_as_long (value_struct_elt (&temp, NULL, "method_count", 486*5796c8dcSSimon Schubert NULL, "structure")); 487*5796c8dcSSimon Schubert TYPE_NFN_FIELDS_TOTAL (type) = nmethods; 488*5796c8dcSSimon Schubert j = nmethods * sizeof (struct fn_field); 489*5796c8dcSSimon Schubert fn_fields = (struct fn_field *) 490*5796c8dcSSimon Schubert obstack_alloc (&dynamics_objfile->objfile_obstack, j); 491*5796c8dcSSimon Schubert memset (fn_fields, 0, j); 492*5796c8dcSSimon Schubert fn_fieldlists = (struct fn_fieldlist *) 493*5796c8dcSSimon Schubert alloca (nmethods * sizeof (struct fn_fieldlist)); 494*5796c8dcSSimon Schubert 495*5796c8dcSSimon Schubert methods = NULL; 496*5796c8dcSSimon Schubert for (i = 0; i < nmethods; i++) 497*5796c8dcSSimon Schubert { 498*5796c8dcSSimon Schubert char *mname; 499*5796c8dcSSimon Schubert int k; 500*5796c8dcSSimon Schubert if (methods == NULL) 501*5796c8dcSSimon Schubert { 502*5796c8dcSSimon Schubert temp = clas; 503*5796c8dcSSimon Schubert methods = value_struct_elt (&temp, NULL, "methods", NULL, "structure"); 504*5796c8dcSSimon Schubert method = value_ind (methods); 505*5796c8dcSSimon Schubert } 506*5796c8dcSSimon Schubert else 507*5796c8dcSSimon Schubert { /* Re-use method value for next method. */ 508*5796c8dcSSimon Schubert CORE_ADDR addr 509*5796c8dcSSimon Schubert = value_address (method) + TYPE_LENGTH (value_type (method)); 510*5796c8dcSSimon Schubert set_value_address (method, addr); 511*5796c8dcSSimon Schubert set_value_lazy (method, 1); 512*5796c8dcSSimon Schubert } 513*5796c8dcSSimon Schubert 514*5796c8dcSSimon Schubert /* Get method name. */ 515*5796c8dcSSimon Schubert temp = method; 516*5796c8dcSSimon Schubert temp = value_struct_elt (&temp, NULL, "name", NULL, "structure"); 517*5796c8dcSSimon Schubert mname = get_java_utf8_name (&objfile->objfile_obstack, temp); 518*5796c8dcSSimon Schubert if (strcmp (mname, "<init>") == 0) 519*5796c8dcSSimon Schubert mname = unqualified_name; 520*5796c8dcSSimon Schubert 521*5796c8dcSSimon Schubert /* Check for an existing method with the same name. 522*5796c8dcSSimon Schubert * This makes building the fn_fieldslists an O(nmethods**2) 523*5796c8dcSSimon Schubert * operation. That could be using hashing, but I doubt it 524*5796c8dcSSimon Schubert * is worth it. Note that we do maintain the order of methods 525*5796c8dcSSimon Schubert * in the inferior's Method table (as long as that is grouped 526*5796c8dcSSimon Schubert * by method name), which I think is desirable. --PB */ 527*5796c8dcSSimon Schubert for (k = 0, j = TYPE_NFN_FIELDS (type);;) 528*5796c8dcSSimon Schubert { 529*5796c8dcSSimon Schubert if (--j < 0) 530*5796c8dcSSimon Schubert { /* No match - new method name. */ 531*5796c8dcSSimon Schubert j = TYPE_NFN_FIELDS (type)++; 532*5796c8dcSSimon Schubert fn_fieldlists[j].name = mname; 533*5796c8dcSSimon Schubert fn_fieldlists[j].length = 1; 534*5796c8dcSSimon Schubert fn_fieldlists[j].fn_fields = &fn_fields[i]; 535*5796c8dcSSimon Schubert k = i; 536*5796c8dcSSimon Schubert break; 537*5796c8dcSSimon Schubert } 538*5796c8dcSSimon Schubert if (strcmp (mname, fn_fieldlists[j].name) == 0) 539*5796c8dcSSimon Schubert { /* Found an existing method with the same name. */ 540*5796c8dcSSimon Schubert int l; 541*5796c8dcSSimon Schubert if (mname != unqualified_name) 542*5796c8dcSSimon Schubert obstack_free (&objfile->objfile_obstack, mname); 543*5796c8dcSSimon Schubert mname = fn_fieldlists[j].name; 544*5796c8dcSSimon Schubert fn_fieldlists[j].length++; 545*5796c8dcSSimon Schubert k = i - k; /* Index of new slot. */ 546*5796c8dcSSimon Schubert /* Shift intervening fn_fields (between k and i) down. */ 547*5796c8dcSSimon Schubert for (l = i; l > k; l--) 548*5796c8dcSSimon Schubert fn_fields[l] = fn_fields[l - 1]; 549*5796c8dcSSimon Schubert for (l = TYPE_NFN_FIELDS (type); --l > j;) 550*5796c8dcSSimon Schubert fn_fieldlists[l].fn_fields++; 551*5796c8dcSSimon Schubert break; 552*5796c8dcSSimon Schubert } 553*5796c8dcSSimon Schubert k += fn_fieldlists[j].length; 554*5796c8dcSSimon Schubert } 555*5796c8dcSSimon Schubert fn_fields[k].physname = ""; 556*5796c8dcSSimon Schubert fn_fields[k].is_stub = 1; 557*5796c8dcSSimon Schubert /* FIXME */ 558*5796c8dcSSimon Schubert fn_fields[k].type = lookup_function_type 559*5796c8dcSSimon Schubert (builtin_java_type (gdbarch)->builtin_void); 560*5796c8dcSSimon Schubert TYPE_CODE (fn_fields[k].type) = TYPE_CODE_METHOD; 561*5796c8dcSSimon Schubert } 562*5796c8dcSSimon Schubert 563*5796c8dcSSimon Schubert j = TYPE_NFN_FIELDS (type) * sizeof (struct fn_fieldlist); 564*5796c8dcSSimon Schubert TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *) 565*5796c8dcSSimon Schubert obstack_alloc (&dynamics_objfile->objfile_obstack, j); 566*5796c8dcSSimon Schubert memcpy (TYPE_FN_FIELDLISTS (type), fn_fieldlists, j); 567*5796c8dcSSimon Schubert 568*5796c8dcSSimon Schubert return type; 569*5796c8dcSSimon Schubert } 570*5796c8dcSSimon Schubert 571*5796c8dcSSimon Schubert static struct type *java_object_type; 572*5796c8dcSSimon Schubert 573*5796c8dcSSimon Schubert struct type * 574*5796c8dcSSimon Schubert get_java_object_type (void) 575*5796c8dcSSimon Schubert { 576*5796c8dcSSimon Schubert if (java_object_type == NULL) 577*5796c8dcSSimon Schubert { 578*5796c8dcSSimon Schubert struct symbol *sym; 579*5796c8dcSSimon Schubert sym = lookup_symbol ("java.lang.Object", NULL, STRUCT_DOMAIN, NULL); 580*5796c8dcSSimon Schubert if (sym == NULL) 581*5796c8dcSSimon Schubert error (_("cannot find java.lang.Object")); 582*5796c8dcSSimon Schubert java_object_type = SYMBOL_TYPE (sym); 583*5796c8dcSSimon Schubert } 584*5796c8dcSSimon Schubert return java_object_type; 585*5796c8dcSSimon Schubert } 586*5796c8dcSSimon Schubert 587*5796c8dcSSimon Schubert int 588*5796c8dcSSimon Schubert get_java_object_header_size (struct gdbarch *gdbarch) 589*5796c8dcSSimon Schubert { 590*5796c8dcSSimon Schubert struct type *objtype = get_java_object_type (); 591*5796c8dcSSimon Schubert if (objtype == NULL) 592*5796c8dcSSimon Schubert return (2 * gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT); 593*5796c8dcSSimon Schubert else 594*5796c8dcSSimon Schubert return TYPE_LENGTH (objtype); 595*5796c8dcSSimon Schubert } 596*5796c8dcSSimon Schubert 597*5796c8dcSSimon Schubert int 598*5796c8dcSSimon Schubert is_object_type (struct type *type) 599*5796c8dcSSimon Schubert { 600*5796c8dcSSimon Schubert CHECK_TYPEDEF (type); 601*5796c8dcSSimon Schubert if (TYPE_CODE (type) == TYPE_CODE_PTR) 602*5796c8dcSSimon Schubert { 603*5796c8dcSSimon Schubert struct type *ttype = check_typedef (TYPE_TARGET_TYPE (type)); 604*5796c8dcSSimon Schubert char *name; 605*5796c8dcSSimon Schubert if (TYPE_CODE (ttype) != TYPE_CODE_STRUCT) 606*5796c8dcSSimon Schubert return 0; 607*5796c8dcSSimon Schubert while (TYPE_N_BASECLASSES (ttype) > 0) 608*5796c8dcSSimon Schubert ttype = TYPE_BASECLASS (ttype, 0); 609*5796c8dcSSimon Schubert name = TYPE_TAG_NAME (ttype); 610*5796c8dcSSimon Schubert if (name != NULL && strcmp (name, "java.lang.Object") == 0) 611*5796c8dcSSimon Schubert return 1; 612*5796c8dcSSimon Schubert name = TYPE_NFIELDS (ttype) > 0 ? TYPE_FIELD_NAME (ttype, 0) : (char *) 0; 613*5796c8dcSSimon Schubert if (name != NULL && strcmp (name, "vtable") == 0) 614*5796c8dcSSimon Schubert { 615*5796c8dcSSimon Schubert if (java_object_type == NULL) 616*5796c8dcSSimon Schubert java_object_type = type; 617*5796c8dcSSimon Schubert return 1; 618*5796c8dcSSimon Schubert } 619*5796c8dcSSimon Schubert } 620*5796c8dcSSimon Schubert return 0; 621*5796c8dcSSimon Schubert } 622*5796c8dcSSimon Schubert 623*5796c8dcSSimon Schubert struct type * 624*5796c8dcSSimon Schubert java_primitive_type (struct gdbarch *gdbarch, int signature) 625*5796c8dcSSimon Schubert { 626*5796c8dcSSimon Schubert const struct builtin_java_type *builtin = builtin_java_type (gdbarch); 627*5796c8dcSSimon Schubert 628*5796c8dcSSimon Schubert switch (signature) 629*5796c8dcSSimon Schubert { 630*5796c8dcSSimon Schubert case 'B': 631*5796c8dcSSimon Schubert return builtin->builtin_byte; 632*5796c8dcSSimon Schubert case 'S': 633*5796c8dcSSimon Schubert return builtin->builtin_short; 634*5796c8dcSSimon Schubert case 'I': 635*5796c8dcSSimon Schubert return builtin->builtin_int; 636*5796c8dcSSimon Schubert case 'J': 637*5796c8dcSSimon Schubert return builtin->builtin_long; 638*5796c8dcSSimon Schubert case 'Z': 639*5796c8dcSSimon Schubert return builtin->builtin_boolean; 640*5796c8dcSSimon Schubert case 'C': 641*5796c8dcSSimon Schubert return builtin->builtin_char; 642*5796c8dcSSimon Schubert case 'F': 643*5796c8dcSSimon Schubert return builtin->builtin_float; 644*5796c8dcSSimon Schubert case 'D': 645*5796c8dcSSimon Schubert return builtin->builtin_double; 646*5796c8dcSSimon Schubert case 'V': 647*5796c8dcSSimon Schubert return builtin->builtin_void; 648*5796c8dcSSimon Schubert } 649*5796c8dcSSimon Schubert error (_("unknown signature '%c' for primitive type"), (char) signature); 650*5796c8dcSSimon Schubert } 651*5796c8dcSSimon Schubert 652*5796c8dcSSimon Schubert /* If name[0 .. namelen-1] is the name of a primitive Java type, 653*5796c8dcSSimon Schubert return that type. Otherwise, return NULL. */ 654*5796c8dcSSimon Schubert 655*5796c8dcSSimon Schubert struct type * 656*5796c8dcSSimon Schubert java_primitive_type_from_name (struct gdbarch *gdbarch, 657*5796c8dcSSimon Schubert char *name, int namelen) 658*5796c8dcSSimon Schubert { 659*5796c8dcSSimon Schubert const struct builtin_java_type *builtin = builtin_java_type (gdbarch); 660*5796c8dcSSimon Schubert 661*5796c8dcSSimon Schubert switch (name[0]) 662*5796c8dcSSimon Schubert { 663*5796c8dcSSimon Schubert case 'b': 664*5796c8dcSSimon Schubert if (namelen == 4 && memcmp (name, "byte", 4) == 0) 665*5796c8dcSSimon Schubert return builtin->builtin_byte; 666*5796c8dcSSimon Schubert if (namelen == 7 && memcmp (name, "boolean", 7) == 0) 667*5796c8dcSSimon Schubert return builtin->builtin_boolean; 668*5796c8dcSSimon Schubert break; 669*5796c8dcSSimon Schubert case 'c': 670*5796c8dcSSimon Schubert if (namelen == 4 && memcmp (name, "char", 4) == 0) 671*5796c8dcSSimon Schubert return builtin->builtin_char; 672*5796c8dcSSimon Schubert case 'd': 673*5796c8dcSSimon Schubert if (namelen == 6 && memcmp (name, "double", 6) == 0) 674*5796c8dcSSimon Schubert return builtin->builtin_double; 675*5796c8dcSSimon Schubert break; 676*5796c8dcSSimon Schubert case 'f': 677*5796c8dcSSimon Schubert if (namelen == 5 && memcmp (name, "float", 5) == 0) 678*5796c8dcSSimon Schubert return builtin->builtin_float; 679*5796c8dcSSimon Schubert break; 680*5796c8dcSSimon Schubert case 'i': 681*5796c8dcSSimon Schubert if (namelen == 3 && memcmp (name, "int", 3) == 0) 682*5796c8dcSSimon Schubert return builtin->builtin_int; 683*5796c8dcSSimon Schubert break; 684*5796c8dcSSimon Schubert case 'l': 685*5796c8dcSSimon Schubert if (namelen == 4 && memcmp (name, "long", 4) == 0) 686*5796c8dcSSimon Schubert return builtin->builtin_long; 687*5796c8dcSSimon Schubert break; 688*5796c8dcSSimon Schubert case 's': 689*5796c8dcSSimon Schubert if (namelen == 5 && memcmp (name, "short", 5) == 0) 690*5796c8dcSSimon Schubert return builtin->builtin_short; 691*5796c8dcSSimon Schubert break; 692*5796c8dcSSimon Schubert case 'v': 693*5796c8dcSSimon Schubert if (namelen == 4 && memcmp (name, "void", 4) == 0) 694*5796c8dcSSimon Schubert return builtin->builtin_void; 695*5796c8dcSSimon Schubert break; 696*5796c8dcSSimon Schubert } 697*5796c8dcSSimon Schubert return NULL; 698*5796c8dcSSimon Schubert } 699*5796c8dcSSimon Schubert 700*5796c8dcSSimon Schubert static char * 701*5796c8dcSSimon Schubert java_primitive_type_name (int signature) 702*5796c8dcSSimon Schubert { 703*5796c8dcSSimon Schubert switch (signature) 704*5796c8dcSSimon Schubert { 705*5796c8dcSSimon Schubert case 'B': 706*5796c8dcSSimon Schubert return "byte"; 707*5796c8dcSSimon Schubert case 'S': 708*5796c8dcSSimon Schubert return "short"; 709*5796c8dcSSimon Schubert case 'I': 710*5796c8dcSSimon Schubert return "int"; 711*5796c8dcSSimon Schubert case 'J': 712*5796c8dcSSimon Schubert return "long"; 713*5796c8dcSSimon Schubert case 'Z': 714*5796c8dcSSimon Schubert return "boolean"; 715*5796c8dcSSimon Schubert case 'C': 716*5796c8dcSSimon Schubert return "char"; 717*5796c8dcSSimon Schubert case 'F': 718*5796c8dcSSimon Schubert return "float"; 719*5796c8dcSSimon Schubert case 'D': 720*5796c8dcSSimon Schubert return "double"; 721*5796c8dcSSimon Schubert case 'V': 722*5796c8dcSSimon Schubert return "void"; 723*5796c8dcSSimon Schubert } 724*5796c8dcSSimon Schubert error (_("unknown signature '%c' for primitive type"), (char) signature); 725*5796c8dcSSimon Schubert } 726*5796c8dcSSimon Schubert 727*5796c8dcSSimon Schubert /* Return the length (in bytes) of demangled name of the Java type 728*5796c8dcSSimon Schubert signature string SIGNATURE. */ 729*5796c8dcSSimon Schubert 730*5796c8dcSSimon Schubert static int 731*5796c8dcSSimon Schubert java_demangled_signature_length (char *signature) 732*5796c8dcSSimon Schubert { 733*5796c8dcSSimon Schubert int array = 0; 734*5796c8dcSSimon Schubert for (; *signature == '['; signature++) 735*5796c8dcSSimon Schubert array += 2; /* Two chars for "[]". */ 736*5796c8dcSSimon Schubert switch (signature[0]) 737*5796c8dcSSimon Schubert { 738*5796c8dcSSimon Schubert case 'L': 739*5796c8dcSSimon Schubert /* Subtract 2 for 'L' and ';'. */ 740*5796c8dcSSimon Schubert return strlen (signature) - 2 + array; 741*5796c8dcSSimon Schubert default: 742*5796c8dcSSimon Schubert return strlen (java_primitive_type_name (signature[0])) + array; 743*5796c8dcSSimon Schubert } 744*5796c8dcSSimon Schubert } 745*5796c8dcSSimon Schubert 746*5796c8dcSSimon Schubert /* Demangle the Java type signature SIGNATURE, leaving the result in RESULT. */ 747*5796c8dcSSimon Schubert 748*5796c8dcSSimon Schubert static void 749*5796c8dcSSimon Schubert java_demangled_signature_copy (char *result, char *signature) 750*5796c8dcSSimon Schubert { 751*5796c8dcSSimon Schubert int array = 0; 752*5796c8dcSSimon Schubert char *ptr; 753*5796c8dcSSimon Schubert int i; 754*5796c8dcSSimon Schubert while (*signature == '[') 755*5796c8dcSSimon Schubert { 756*5796c8dcSSimon Schubert array++; 757*5796c8dcSSimon Schubert signature++; 758*5796c8dcSSimon Schubert } 759*5796c8dcSSimon Schubert switch (signature[0]) 760*5796c8dcSSimon Schubert { 761*5796c8dcSSimon Schubert case 'L': 762*5796c8dcSSimon Schubert /* Subtract 2 for 'L' and ';', but add 1 for final nul. */ 763*5796c8dcSSimon Schubert signature++; 764*5796c8dcSSimon Schubert ptr = result; 765*5796c8dcSSimon Schubert for (; *signature != ';' && *signature != '\0'; signature++) 766*5796c8dcSSimon Schubert { 767*5796c8dcSSimon Schubert if (*signature == '/') 768*5796c8dcSSimon Schubert *ptr++ = '.'; 769*5796c8dcSSimon Schubert else 770*5796c8dcSSimon Schubert *ptr++ = *signature; 771*5796c8dcSSimon Schubert } 772*5796c8dcSSimon Schubert break; 773*5796c8dcSSimon Schubert default: 774*5796c8dcSSimon Schubert ptr = java_primitive_type_name (signature[0]); 775*5796c8dcSSimon Schubert i = strlen (ptr); 776*5796c8dcSSimon Schubert strcpy (result, ptr); 777*5796c8dcSSimon Schubert ptr = result + i; 778*5796c8dcSSimon Schubert break; 779*5796c8dcSSimon Schubert } 780*5796c8dcSSimon Schubert while (--array >= 0) 781*5796c8dcSSimon Schubert { 782*5796c8dcSSimon Schubert *ptr++ = '['; 783*5796c8dcSSimon Schubert *ptr++ = ']'; 784*5796c8dcSSimon Schubert } 785*5796c8dcSSimon Schubert } 786*5796c8dcSSimon Schubert 787*5796c8dcSSimon Schubert /* Return the demangled name of the Java type signature string SIGNATURE, 788*5796c8dcSSimon Schubert as a freshly allocated copy. */ 789*5796c8dcSSimon Schubert 790*5796c8dcSSimon Schubert char * 791*5796c8dcSSimon Schubert java_demangle_type_signature (char *signature) 792*5796c8dcSSimon Schubert { 793*5796c8dcSSimon Schubert int length = java_demangled_signature_length (signature); 794*5796c8dcSSimon Schubert char *result = xmalloc (length + 1); 795*5796c8dcSSimon Schubert java_demangled_signature_copy (result, signature); 796*5796c8dcSSimon Schubert result[length] = '\0'; 797*5796c8dcSSimon Schubert return result; 798*5796c8dcSSimon Schubert } 799*5796c8dcSSimon Schubert 800*5796c8dcSSimon Schubert /* Return the type of TYPE followed by DIMS pairs of [ ]. 801*5796c8dcSSimon Schubert If DIMS == 0, TYPE is returned. */ 802*5796c8dcSSimon Schubert 803*5796c8dcSSimon Schubert struct type * 804*5796c8dcSSimon Schubert java_array_type (struct type *type, int dims) 805*5796c8dcSSimon Schubert { 806*5796c8dcSSimon Schubert while (dims-- > 0) 807*5796c8dcSSimon Schubert { 808*5796c8dcSSimon Schubert /* FIXME This is bogus! Java arrays are not gdb arrays! */ 809*5796c8dcSSimon Schubert type = lookup_array_range_type (type, 0, 0); 810*5796c8dcSSimon Schubert } 811*5796c8dcSSimon Schubert 812*5796c8dcSSimon Schubert return type; 813*5796c8dcSSimon Schubert } 814*5796c8dcSSimon Schubert 815*5796c8dcSSimon Schubert /* Create a Java string in the inferior from a (Utf8) literal. */ 816*5796c8dcSSimon Schubert 817*5796c8dcSSimon Schubert static struct value * 818*5796c8dcSSimon Schubert java_value_string (char *ptr, int len) 819*5796c8dcSSimon Schubert { 820*5796c8dcSSimon Schubert error (_("not implemented - java_value_string")); /* FIXME */ 821*5796c8dcSSimon Schubert } 822*5796c8dcSSimon Schubert 823*5796c8dcSSimon Schubert /* Print the character C on STREAM as part of the contents of a literal 824*5796c8dcSSimon Schubert string whose delimiter is QUOTER. Note that that format for printing 825*5796c8dcSSimon Schubert characters and strings is language specific. */ 826*5796c8dcSSimon Schubert 827*5796c8dcSSimon Schubert static void 828*5796c8dcSSimon Schubert java_emit_char (int c, struct type *type, struct ui_file *stream, int quoter) 829*5796c8dcSSimon Schubert { 830*5796c8dcSSimon Schubert switch (c) 831*5796c8dcSSimon Schubert { 832*5796c8dcSSimon Schubert case '\\': 833*5796c8dcSSimon Schubert case '\'': 834*5796c8dcSSimon Schubert fprintf_filtered (stream, "\\%c", c); 835*5796c8dcSSimon Schubert break; 836*5796c8dcSSimon Schubert case '\b': 837*5796c8dcSSimon Schubert fputs_filtered ("\\b", stream); 838*5796c8dcSSimon Schubert break; 839*5796c8dcSSimon Schubert case '\t': 840*5796c8dcSSimon Schubert fputs_filtered ("\\t", stream); 841*5796c8dcSSimon Schubert break; 842*5796c8dcSSimon Schubert case '\n': 843*5796c8dcSSimon Schubert fputs_filtered ("\\n", stream); 844*5796c8dcSSimon Schubert break; 845*5796c8dcSSimon Schubert case '\f': 846*5796c8dcSSimon Schubert fputs_filtered ("\\f", stream); 847*5796c8dcSSimon Schubert break; 848*5796c8dcSSimon Schubert case '\r': 849*5796c8dcSSimon Schubert fputs_filtered ("\\r", stream); 850*5796c8dcSSimon Schubert break; 851*5796c8dcSSimon Schubert default: 852*5796c8dcSSimon Schubert if (isprint (c)) 853*5796c8dcSSimon Schubert fputc_filtered (c, stream); 854*5796c8dcSSimon Schubert else 855*5796c8dcSSimon Schubert fprintf_filtered (stream, "\\u%.4x", (unsigned int) c); 856*5796c8dcSSimon Schubert break; 857*5796c8dcSSimon Schubert } 858*5796c8dcSSimon Schubert } 859*5796c8dcSSimon Schubert 860*5796c8dcSSimon Schubert static struct value * 861*5796c8dcSSimon Schubert evaluate_subexp_java (struct type *expect_type, struct expression *exp, 862*5796c8dcSSimon Schubert int *pos, enum noside noside) 863*5796c8dcSSimon Schubert { 864*5796c8dcSSimon Schubert int pc = *pos; 865*5796c8dcSSimon Schubert int i; 866*5796c8dcSSimon Schubert char *name; 867*5796c8dcSSimon Schubert enum exp_opcode op = exp->elts[*pos].opcode; 868*5796c8dcSSimon Schubert struct value *arg1; 869*5796c8dcSSimon Schubert struct value *arg2; 870*5796c8dcSSimon Schubert struct type *type; 871*5796c8dcSSimon Schubert switch (op) 872*5796c8dcSSimon Schubert { 873*5796c8dcSSimon Schubert case UNOP_IND: 874*5796c8dcSSimon Schubert if (noside == EVAL_SKIP) 875*5796c8dcSSimon Schubert goto standard; 876*5796c8dcSSimon Schubert (*pos)++; 877*5796c8dcSSimon Schubert arg1 = evaluate_subexp_java (NULL_TYPE, exp, pos, EVAL_NORMAL); 878*5796c8dcSSimon Schubert if (is_object_type (value_type (arg1))) 879*5796c8dcSSimon Schubert { 880*5796c8dcSSimon Schubert struct type *type; 881*5796c8dcSSimon Schubert 882*5796c8dcSSimon Schubert type = type_from_class (exp->gdbarch, java_class_from_object (arg1)); 883*5796c8dcSSimon Schubert arg1 = value_cast (lookup_pointer_type (type), arg1); 884*5796c8dcSSimon Schubert } 885*5796c8dcSSimon Schubert if (noside == EVAL_SKIP) 886*5796c8dcSSimon Schubert goto nosideret; 887*5796c8dcSSimon Schubert return value_ind (arg1); 888*5796c8dcSSimon Schubert 889*5796c8dcSSimon Schubert case BINOP_SUBSCRIPT: 890*5796c8dcSSimon Schubert (*pos)++; 891*5796c8dcSSimon Schubert arg1 = evaluate_subexp_with_coercion (exp, pos, noside); 892*5796c8dcSSimon Schubert arg2 = evaluate_subexp_with_coercion (exp, pos, noside); 893*5796c8dcSSimon Schubert if (noside == EVAL_SKIP) 894*5796c8dcSSimon Schubert goto nosideret; 895*5796c8dcSSimon Schubert /* If the user attempts to subscript something that is not an 896*5796c8dcSSimon Schubert array or pointer type (like a plain int variable for example), 897*5796c8dcSSimon Schubert then report this as an error. */ 898*5796c8dcSSimon Schubert 899*5796c8dcSSimon Schubert arg1 = coerce_ref (arg1); 900*5796c8dcSSimon Schubert type = check_typedef (value_type (arg1)); 901*5796c8dcSSimon Schubert if (TYPE_CODE (type) == TYPE_CODE_PTR) 902*5796c8dcSSimon Schubert type = check_typedef (TYPE_TARGET_TYPE (type)); 903*5796c8dcSSimon Schubert name = TYPE_NAME (type); 904*5796c8dcSSimon Schubert if (name == NULL) 905*5796c8dcSSimon Schubert name = TYPE_TAG_NAME (type); 906*5796c8dcSSimon Schubert i = name == NULL ? 0 : strlen (name); 907*5796c8dcSSimon Schubert if (TYPE_CODE (type) == TYPE_CODE_STRUCT 908*5796c8dcSSimon Schubert && i > 2 && name[i - 1] == ']') 909*5796c8dcSSimon Schubert { 910*5796c8dcSSimon Schubert enum bfd_endian byte_order = gdbarch_byte_order (exp->gdbarch); 911*5796c8dcSSimon Schubert CORE_ADDR address; 912*5796c8dcSSimon Schubert long length, index; 913*5796c8dcSSimon Schubert struct type *el_type; 914*5796c8dcSSimon Schubert gdb_byte buf4[4]; 915*5796c8dcSSimon Schubert 916*5796c8dcSSimon Schubert struct value *clas = java_class_from_object (arg1); 917*5796c8dcSSimon Schubert struct value *temp = clas; 918*5796c8dcSSimon Schubert /* Get CLASS_ELEMENT_TYPE of the array type. */ 919*5796c8dcSSimon Schubert temp = value_struct_elt (&temp, NULL, "methods", 920*5796c8dcSSimon Schubert NULL, "structure"); 921*5796c8dcSSimon Schubert deprecated_set_value_type (temp, value_type (clas)); 922*5796c8dcSSimon Schubert el_type = type_from_class (exp->gdbarch, temp); 923*5796c8dcSSimon Schubert if (TYPE_CODE (el_type) == TYPE_CODE_STRUCT) 924*5796c8dcSSimon Schubert el_type = lookup_pointer_type (el_type); 925*5796c8dcSSimon Schubert 926*5796c8dcSSimon Schubert if (noside == EVAL_AVOID_SIDE_EFFECTS) 927*5796c8dcSSimon Schubert return value_zero (el_type, VALUE_LVAL (arg1)); 928*5796c8dcSSimon Schubert address = value_as_address (arg1); 929*5796c8dcSSimon Schubert address += get_java_object_header_size (exp->gdbarch); 930*5796c8dcSSimon Schubert read_memory (address, buf4, 4); 931*5796c8dcSSimon Schubert length = (long) extract_signed_integer (buf4, 4, byte_order); 932*5796c8dcSSimon Schubert index = (long) value_as_long (arg2); 933*5796c8dcSSimon Schubert if (index >= length || index < 0) 934*5796c8dcSSimon Schubert error (_("array index (%ld) out of bounds (length: %ld)"), 935*5796c8dcSSimon Schubert index, length); 936*5796c8dcSSimon Schubert address = (address + 4) + index * TYPE_LENGTH (el_type); 937*5796c8dcSSimon Schubert return value_at (el_type, address); 938*5796c8dcSSimon Schubert } 939*5796c8dcSSimon Schubert else if (TYPE_CODE (type) == TYPE_CODE_ARRAY) 940*5796c8dcSSimon Schubert { 941*5796c8dcSSimon Schubert if (noside == EVAL_AVOID_SIDE_EFFECTS) 942*5796c8dcSSimon Schubert return value_zero (TYPE_TARGET_TYPE (type), VALUE_LVAL (arg1)); 943*5796c8dcSSimon Schubert else 944*5796c8dcSSimon Schubert return value_subscript (arg1, value_as_long (arg2)); 945*5796c8dcSSimon Schubert } 946*5796c8dcSSimon Schubert if (name) 947*5796c8dcSSimon Schubert error (_("cannot subscript something of type `%s'"), name); 948*5796c8dcSSimon Schubert else 949*5796c8dcSSimon Schubert error (_("cannot subscript requested type")); 950*5796c8dcSSimon Schubert 951*5796c8dcSSimon Schubert case OP_STRING: 952*5796c8dcSSimon Schubert (*pos)++; 953*5796c8dcSSimon Schubert i = longest_to_int (exp->elts[pc + 1].longconst); 954*5796c8dcSSimon Schubert (*pos) += 3 + BYTES_TO_EXP_ELEM (i + 1); 955*5796c8dcSSimon Schubert if (noside == EVAL_SKIP) 956*5796c8dcSSimon Schubert goto nosideret; 957*5796c8dcSSimon Schubert return java_value_string (&exp->elts[pc + 2].string, i); 958*5796c8dcSSimon Schubert 959*5796c8dcSSimon Schubert case STRUCTOP_PTR: 960*5796c8dcSSimon Schubert arg1 = evaluate_subexp_standard (expect_type, exp, pos, noside); 961*5796c8dcSSimon Schubert /* Convert object field (such as TYPE.class) to reference. */ 962*5796c8dcSSimon Schubert if (TYPE_CODE (value_type (arg1)) == TYPE_CODE_STRUCT) 963*5796c8dcSSimon Schubert arg1 = value_addr (arg1); 964*5796c8dcSSimon Schubert return arg1; 965*5796c8dcSSimon Schubert default: 966*5796c8dcSSimon Schubert break; 967*5796c8dcSSimon Schubert } 968*5796c8dcSSimon Schubert standard: 969*5796c8dcSSimon Schubert return evaluate_subexp_standard (expect_type, exp, pos, noside); 970*5796c8dcSSimon Schubert nosideret: 971*5796c8dcSSimon Schubert return value_from_longest (builtin_type (exp->gdbarch)->builtin_int, 1); 972*5796c8dcSSimon Schubert } 973*5796c8dcSSimon Schubert 974*5796c8dcSSimon Schubert static char *java_demangle (const char *mangled, int options) 975*5796c8dcSSimon Schubert { 976*5796c8dcSSimon Schubert return cplus_demangle (mangled, options | DMGL_JAVA); 977*5796c8dcSSimon Schubert } 978*5796c8dcSSimon Schubert 979*5796c8dcSSimon Schubert /* Find the member function name of the demangled name NAME. NAME 980*5796c8dcSSimon Schubert must be a method name including arguments, in order to correctly 981*5796c8dcSSimon Schubert locate the last component. 982*5796c8dcSSimon Schubert 983*5796c8dcSSimon Schubert This function return a pointer to the first dot before the 984*5796c8dcSSimon Schubert member function name, or NULL if the name was not of the 985*5796c8dcSSimon Schubert expected form. */ 986*5796c8dcSSimon Schubert 987*5796c8dcSSimon Schubert static const char * 988*5796c8dcSSimon Schubert java_find_last_component (const char *name) 989*5796c8dcSSimon Schubert { 990*5796c8dcSSimon Schubert const char *p; 991*5796c8dcSSimon Schubert 992*5796c8dcSSimon Schubert /* Find argument list. */ 993*5796c8dcSSimon Schubert p = strchr (name, '('); 994*5796c8dcSSimon Schubert 995*5796c8dcSSimon Schubert if (p == NULL) 996*5796c8dcSSimon Schubert return NULL; 997*5796c8dcSSimon Schubert 998*5796c8dcSSimon Schubert /* Back up and find first dot prior to argument list. */ 999*5796c8dcSSimon Schubert while (p > name && *p != '.') 1000*5796c8dcSSimon Schubert p--; 1001*5796c8dcSSimon Schubert 1002*5796c8dcSSimon Schubert if (p == name) 1003*5796c8dcSSimon Schubert return NULL; 1004*5796c8dcSSimon Schubert 1005*5796c8dcSSimon Schubert return p; 1006*5796c8dcSSimon Schubert } 1007*5796c8dcSSimon Schubert 1008*5796c8dcSSimon Schubert /* Return the name of the class containing method PHYSNAME. */ 1009*5796c8dcSSimon Schubert 1010*5796c8dcSSimon Schubert static char * 1011*5796c8dcSSimon Schubert java_class_name_from_physname (const char *physname) 1012*5796c8dcSSimon Schubert { 1013*5796c8dcSSimon Schubert char *ret = NULL; 1014*5796c8dcSSimon Schubert const char *end; 1015*5796c8dcSSimon Schubert int depth = 0; 1016*5796c8dcSSimon Schubert char *demangled_name = java_demangle (physname, DMGL_PARAMS | DMGL_ANSI); 1017*5796c8dcSSimon Schubert 1018*5796c8dcSSimon Schubert if (demangled_name == NULL) 1019*5796c8dcSSimon Schubert return NULL; 1020*5796c8dcSSimon Schubert 1021*5796c8dcSSimon Schubert end = java_find_last_component (demangled_name); 1022*5796c8dcSSimon Schubert if (end != NULL) 1023*5796c8dcSSimon Schubert { 1024*5796c8dcSSimon Schubert ret = xmalloc (end - demangled_name + 1); 1025*5796c8dcSSimon Schubert memcpy (ret, demangled_name, end - demangled_name); 1026*5796c8dcSSimon Schubert ret[end - demangled_name] = '\0'; 1027*5796c8dcSSimon Schubert } 1028*5796c8dcSSimon Schubert 1029*5796c8dcSSimon Schubert xfree (demangled_name); 1030*5796c8dcSSimon Schubert return ret; 1031*5796c8dcSSimon Schubert } 1032*5796c8dcSSimon Schubert 1033*5796c8dcSSimon Schubert /* Table mapping opcodes into strings for printing operators 1034*5796c8dcSSimon Schubert and precedences of the operators. */ 1035*5796c8dcSSimon Schubert 1036*5796c8dcSSimon Schubert const struct op_print java_op_print_tab[] = 1037*5796c8dcSSimon Schubert { 1038*5796c8dcSSimon Schubert {",", BINOP_COMMA, PREC_COMMA, 0}, 1039*5796c8dcSSimon Schubert {"=", BINOP_ASSIGN, PREC_ASSIGN, 1}, 1040*5796c8dcSSimon Schubert {"||", BINOP_LOGICAL_OR, PREC_LOGICAL_OR, 0}, 1041*5796c8dcSSimon Schubert {"&&", BINOP_LOGICAL_AND, PREC_LOGICAL_AND, 0}, 1042*5796c8dcSSimon Schubert {"|", BINOP_BITWISE_IOR, PREC_BITWISE_IOR, 0}, 1043*5796c8dcSSimon Schubert {"^", BINOP_BITWISE_XOR, PREC_BITWISE_XOR, 0}, 1044*5796c8dcSSimon Schubert {"&", BINOP_BITWISE_AND, PREC_BITWISE_AND, 0}, 1045*5796c8dcSSimon Schubert {"==", BINOP_EQUAL, PREC_EQUAL, 0}, 1046*5796c8dcSSimon Schubert {"!=", BINOP_NOTEQUAL, PREC_EQUAL, 0}, 1047*5796c8dcSSimon Schubert {"<=", BINOP_LEQ, PREC_ORDER, 0}, 1048*5796c8dcSSimon Schubert {">=", BINOP_GEQ, PREC_ORDER, 0}, 1049*5796c8dcSSimon Schubert {">", BINOP_GTR, PREC_ORDER, 0}, 1050*5796c8dcSSimon Schubert {"<", BINOP_LESS, PREC_ORDER, 0}, 1051*5796c8dcSSimon Schubert {">>", BINOP_RSH, PREC_SHIFT, 0}, 1052*5796c8dcSSimon Schubert {"<<", BINOP_LSH, PREC_SHIFT, 0}, 1053*5796c8dcSSimon Schubert #if 0 1054*5796c8dcSSimon Schubert {">>>", BINOP_ ? ? ?, PREC_SHIFT, 0}, 1055*5796c8dcSSimon Schubert #endif 1056*5796c8dcSSimon Schubert {"+", BINOP_ADD, PREC_ADD, 0}, 1057*5796c8dcSSimon Schubert {"-", BINOP_SUB, PREC_ADD, 0}, 1058*5796c8dcSSimon Schubert {"*", BINOP_MUL, PREC_MUL, 0}, 1059*5796c8dcSSimon Schubert {"/", BINOP_DIV, PREC_MUL, 0}, 1060*5796c8dcSSimon Schubert {"%", BINOP_REM, PREC_MUL, 0}, 1061*5796c8dcSSimon Schubert {"-", UNOP_NEG, PREC_PREFIX, 0}, 1062*5796c8dcSSimon Schubert {"!", UNOP_LOGICAL_NOT, PREC_PREFIX, 0}, 1063*5796c8dcSSimon Schubert {"~", UNOP_COMPLEMENT, PREC_PREFIX, 0}, 1064*5796c8dcSSimon Schubert {"*", UNOP_IND, PREC_PREFIX, 0}, 1065*5796c8dcSSimon Schubert #if 0 1066*5796c8dcSSimon Schubert {"instanceof", ? ? ?, ? ? ?, 0}, 1067*5796c8dcSSimon Schubert #endif 1068*5796c8dcSSimon Schubert {"++", UNOP_PREINCREMENT, PREC_PREFIX, 0}, 1069*5796c8dcSSimon Schubert {"--", UNOP_PREDECREMENT, PREC_PREFIX, 0}, 1070*5796c8dcSSimon Schubert {NULL, 0, 0, 0} 1071*5796c8dcSSimon Schubert }; 1072*5796c8dcSSimon Schubert 1073*5796c8dcSSimon Schubert enum java_primitive_types 1074*5796c8dcSSimon Schubert { 1075*5796c8dcSSimon Schubert java_primitive_type_int, 1076*5796c8dcSSimon Schubert java_primitive_type_short, 1077*5796c8dcSSimon Schubert java_primitive_type_long, 1078*5796c8dcSSimon Schubert java_primitive_type_byte, 1079*5796c8dcSSimon Schubert java_primitive_type_boolean, 1080*5796c8dcSSimon Schubert java_primitive_type_char, 1081*5796c8dcSSimon Schubert java_primitive_type_float, 1082*5796c8dcSSimon Schubert java_primitive_type_double, 1083*5796c8dcSSimon Schubert java_primitive_type_void, 1084*5796c8dcSSimon Schubert nr_java_primitive_types 1085*5796c8dcSSimon Schubert }; 1086*5796c8dcSSimon Schubert 1087*5796c8dcSSimon Schubert static void 1088*5796c8dcSSimon Schubert java_language_arch_info (struct gdbarch *gdbarch, 1089*5796c8dcSSimon Schubert struct language_arch_info *lai) 1090*5796c8dcSSimon Schubert { 1091*5796c8dcSSimon Schubert const struct builtin_java_type *builtin = builtin_java_type (gdbarch); 1092*5796c8dcSSimon Schubert 1093*5796c8dcSSimon Schubert lai->string_char_type = builtin->builtin_char; 1094*5796c8dcSSimon Schubert lai->primitive_type_vector 1095*5796c8dcSSimon Schubert = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_java_primitive_types + 1, 1096*5796c8dcSSimon Schubert struct type *); 1097*5796c8dcSSimon Schubert lai->primitive_type_vector [java_primitive_type_int] 1098*5796c8dcSSimon Schubert = builtin->builtin_int; 1099*5796c8dcSSimon Schubert lai->primitive_type_vector [java_primitive_type_short] 1100*5796c8dcSSimon Schubert = builtin->builtin_short; 1101*5796c8dcSSimon Schubert lai->primitive_type_vector [java_primitive_type_long] 1102*5796c8dcSSimon Schubert = builtin->builtin_long; 1103*5796c8dcSSimon Schubert lai->primitive_type_vector [java_primitive_type_byte] 1104*5796c8dcSSimon Schubert = builtin->builtin_byte; 1105*5796c8dcSSimon Schubert lai->primitive_type_vector [java_primitive_type_boolean] 1106*5796c8dcSSimon Schubert = builtin->builtin_boolean; 1107*5796c8dcSSimon Schubert lai->primitive_type_vector [java_primitive_type_char] 1108*5796c8dcSSimon Schubert = builtin->builtin_char; 1109*5796c8dcSSimon Schubert lai->primitive_type_vector [java_primitive_type_float] 1110*5796c8dcSSimon Schubert = builtin->builtin_float; 1111*5796c8dcSSimon Schubert lai->primitive_type_vector [java_primitive_type_double] 1112*5796c8dcSSimon Schubert = builtin->builtin_double; 1113*5796c8dcSSimon Schubert lai->primitive_type_vector [java_primitive_type_void] 1114*5796c8dcSSimon Schubert = builtin->builtin_void; 1115*5796c8dcSSimon Schubert 1116*5796c8dcSSimon Schubert lai->bool_type_symbol = "boolean"; 1117*5796c8dcSSimon Schubert lai->bool_type_default = builtin->builtin_boolean; 1118*5796c8dcSSimon Schubert } 1119*5796c8dcSSimon Schubert 1120*5796c8dcSSimon Schubert const struct exp_descriptor exp_descriptor_java = 1121*5796c8dcSSimon Schubert { 1122*5796c8dcSSimon Schubert print_subexp_standard, 1123*5796c8dcSSimon Schubert operator_length_standard, 1124*5796c8dcSSimon Schubert op_name_standard, 1125*5796c8dcSSimon Schubert dump_subexp_body_standard, 1126*5796c8dcSSimon Schubert evaluate_subexp_java 1127*5796c8dcSSimon Schubert }; 1128*5796c8dcSSimon Schubert 1129*5796c8dcSSimon Schubert const struct language_defn java_language_defn = 1130*5796c8dcSSimon Schubert { 1131*5796c8dcSSimon Schubert "java", /* Language name */ 1132*5796c8dcSSimon Schubert language_java, 1133*5796c8dcSSimon Schubert range_check_off, 1134*5796c8dcSSimon Schubert type_check_off, 1135*5796c8dcSSimon Schubert case_sensitive_on, 1136*5796c8dcSSimon Schubert array_row_major, 1137*5796c8dcSSimon Schubert macro_expansion_no, 1138*5796c8dcSSimon Schubert &exp_descriptor_java, 1139*5796c8dcSSimon Schubert java_parse, 1140*5796c8dcSSimon Schubert java_error, 1141*5796c8dcSSimon Schubert null_post_parser, 1142*5796c8dcSSimon Schubert c_printchar, /* Print a character constant */ 1143*5796c8dcSSimon Schubert c_printstr, /* Function to print string constant */ 1144*5796c8dcSSimon Schubert java_emit_char, /* Function to print a single character */ 1145*5796c8dcSSimon Schubert java_print_type, /* Print a type using appropriate syntax */ 1146*5796c8dcSSimon Schubert default_print_typedef, /* Print a typedef using appropriate syntax */ 1147*5796c8dcSSimon Schubert java_val_print, /* Print a value using appropriate syntax */ 1148*5796c8dcSSimon Schubert java_value_print, /* Print a top-level value */ 1149*5796c8dcSSimon Schubert NULL, /* Language specific skip_trampoline */ 1150*5796c8dcSSimon Schubert "this", /* name_of_this */ 1151*5796c8dcSSimon Schubert basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */ 1152*5796c8dcSSimon Schubert basic_lookup_transparent_type,/* lookup_transparent_type */ 1153*5796c8dcSSimon Schubert java_demangle, /* Language specific symbol demangler */ 1154*5796c8dcSSimon Schubert java_class_name_from_physname,/* Language specific class name */ 1155*5796c8dcSSimon Schubert java_op_print_tab, /* expression operators for printing */ 1156*5796c8dcSSimon Schubert 0, /* not c-style arrays */ 1157*5796c8dcSSimon Schubert 0, /* String lower bound */ 1158*5796c8dcSSimon Schubert default_word_break_characters, 1159*5796c8dcSSimon Schubert default_make_symbol_completion_list, 1160*5796c8dcSSimon Schubert java_language_arch_info, 1161*5796c8dcSSimon Schubert default_print_array_index, 1162*5796c8dcSSimon Schubert default_pass_by_reference, 1163*5796c8dcSSimon Schubert default_get_string, 1164*5796c8dcSSimon Schubert LANG_MAGIC 1165*5796c8dcSSimon Schubert }; 1166*5796c8dcSSimon Schubert 1167*5796c8dcSSimon Schubert static void * 1168*5796c8dcSSimon Schubert build_java_types (struct gdbarch *gdbarch) 1169*5796c8dcSSimon Schubert { 1170*5796c8dcSSimon Schubert struct builtin_java_type *builtin_java_type 1171*5796c8dcSSimon Schubert = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct builtin_java_type); 1172*5796c8dcSSimon Schubert 1173*5796c8dcSSimon Schubert builtin_java_type->builtin_int 1174*5796c8dcSSimon Schubert = arch_integer_type (gdbarch, 32, 0, "int"); 1175*5796c8dcSSimon Schubert builtin_java_type->builtin_short 1176*5796c8dcSSimon Schubert = arch_integer_type (gdbarch, 16, 0, "short"); 1177*5796c8dcSSimon Schubert builtin_java_type->builtin_long 1178*5796c8dcSSimon Schubert = arch_integer_type (gdbarch, 64, 0, "long"); 1179*5796c8dcSSimon Schubert builtin_java_type->builtin_byte 1180*5796c8dcSSimon Schubert = arch_integer_type (gdbarch, 8, 0, "byte"); 1181*5796c8dcSSimon Schubert builtin_java_type->builtin_boolean 1182*5796c8dcSSimon Schubert = arch_boolean_type (gdbarch, 8, 0, "boolean"); 1183*5796c8dcSSimon Schubert builtin_java_type->builtin_char 1184*5796c8dcSSimon Schubert = arch_character_type (gdbarch, 16, 1, "char"); 1185*5796c8dcSSimon Schubert builtin_java_type->builtin_float 1186*5796c8dcSSimon Schubert = arch_float_type (gdbarch, 32, "float", NULL); 1187*5796c8dcSSimon Schubert builtin_java_type->builtin_double 1188*5796c8dcSSimon Schubert = arch_float_type (gdbarch, 64, "double", NULL); 1189*5796c8dcSSimon Schubert builtin_java_type->builtin_void 1190*5796c8dcSSimon Schubert = arch_type (gdbarch, TYPE_CODE_VOID, 1, "void"); 1191*5796c8dcSSimon Schubert 1192*5796c8dcSSimon Schubert return builtin_java_type; 1193*5796c8dcSSimon Schubert } 1194*5796c8dcSSimon Schubert 1195*5796c8dcSSimon Schubert static struct gdbarch_data *java_type_data; 1196*5796c8dcSSimon Schubert 1197*5796c8dcSSimon Schubert const struct builtin_java_type * 1198*5796c8dcSSimon Schubert builtin_java_type (struct gdbarch *gdbarch) 1199*5796c8dcSSimon Schubert { 1200*5796c8dcSSimon Schubert return gdbarch_data (gdbarch, java_type_data); 1201*5796c8dcSSimon Schubert } 1202*5796c8dcSSimon Schubert 1203*5796c8dcSSimon Schubert void 1204*5796c8dcSSimon Schubert _initialize_java_language (void) 1205*5796c8dcSSimon Schubert { 1206*5796c8dcSSimon Schubert java_type_data = gdbarch_data_register_post_init (build_java_types); 1207*5796c8dcSSimon Schubert 1208*5796c8dcSSimon Schubert add_language (&java_language_defn); 1209*5796c8dcSSimon Schubert } 1210