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