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