*** empty log message ***
[deliverable/binutils-gdb.git] / gdb / jv-lang.c
CommitLineData
c906108c 1/* Java language support routines for GDB, the GNU debugger.
dfa52d88 2
4c38e0a4
JB
3 Copyright (C) 1997, 1998, 1999, 2000, 2003, 2004, 2005, 2007, 2008, 2009,
4 2010 Free Software 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"
c906108c 41
392a587b
JM
42/* Local functions */
43
a14ed312 44extern void _initialize_java_language (void);
392a587b 45
a14ed312
KB
46static int java_demangled_signature_length (char *);
47static void java_demangled_signature_copy (char *, char *);
c906108c 48
20781792 49static struct symtab *get_java_class_symtab (struct gdbarch *gdbarch);
75c9979e
AC
50static char *get_java_utf8_name (struct obstack *obstack, struct value *name);
51static int java_class_is_primitive (struct value *clas);
75c9979e 52static struct value *java_value_string (char *ptr, int len);
392a587b 53
6c7a06a3
TT
54static void java_emit_char (int c, struct type *type,
55 struct ui_file * stream, int quoter);
c906108c 56
31c27f77
JJ
57static char *java_class_name_from_physname (const char *physname);
58
20781792
TT
59static const struct objfile_data *jv_dynamics_objfile_data_key;
60static const struct objfile_data *jv_type_objfile_data_key;
61
c906108c
SS
62/* This objfile contains symtabs that have been dynamically created
63 to record dynamically loaded Java classes and dynamically
64 compiled java methods. */
65
66static struct objfile *dynamics_objfile = NULL;
67
20781792
TT
68/* symtab contains classes read from the inferior. */
69
70static struct symtab *class_symtab = NULL;
71
0daa2b63
UW
72static struct type *java_link_class_type (struct gdbarch *,
73 struct type *, struct value *);
c906108c 74
20781792
TT
75/* A function called when the dynamics_objfile is freed. We use this
76 to clean up some internal state. */
77static void
78jv_per_objfile_free (struct objfile *objfile, void *ignore)
79{
80 gdb_assert (objfile == dynamics_objfile);
81 /* Clean up all our cached state. These objects are all allocated
82 in the dynamics_objfile, so we don't need to actually free
83 anything. */
84 dynamics_objfile = NULL;
85 class_symtab = NULL;
86}
87
eb9a305d
DC
88/* FIXME: carlton/2003-02-04: This is the main or only caller of
89 allocate_objfile with first argument NULL; as a result, this code
90 breaks every so often. Somebody should write a test case that
91 exercises GDB in various ways (e.g. something involving loading a
92 dynamic library) after this code has been called. */
93
c906108c 94static struct objfile *
20781792 95get_dynamics_objfile (struct gdbarch *gdbarch)
c906108c
SS
96{
97 if (dynamics_objfile == NULL)
98 {
20781792
TT
99 /* Mark it as shared so that it is cleared when the inferior is
100 re-run. */
101 dynamics_objfile = allocate_objfile (NULL, OBJF_SHARED);
102 dynamics_objfile->gdbarch = gdbarch;
103 /* We don't have any data to store, but this lets us get a
104 notification when the objfile is destroyed. Since we have to
105 store a non-NULL value, we just pick something arbitrary and
106 safe. */
107 set_objfile_data (dynamics_objfile, jv_dynamics_objfile_data_key,
108 &dynamics_objfile);
c906108c
SS
109 }
110 return dynamics_objfile;
111}
112
de4f826b 113static void free_class_block (struct symtab *symtab);
c906108c 114
392a587b 115static struct symtab *
20781792 116get_java_class_symtab (struct gdbarch *gdbarch)
c906108c
SS
117{
118 if (class_symtab == NULL)
119 {
20781792 120 struct objfile *objfile = get_dynamics_objfile (gdbarch);
c906108c
SS
121 struct blockvector *bv;
122 struct block *bl;
123 class_symtab = allocate_symtab ("<java-classes>", objfile);
124 class_symtab->language = language_java;
125 bv = (struct blockvector *)
4a146b47 126 obstack_alloc (&objfile->objfile_obstack,
de4f826b 127 sizeof (struct blockvector) + sizeof (struct block *));
c906108c
SS
128 BLOCKVECTOR_NBLOCKS (bv) = 1;
129 BLOCKVECTOR (class_symtab) = bv;
130
131 /* Allocate dummy STATIC_BLOCK. */
4a146b47
EZ
132 bl = allocate_block (&objfile->objfile_obstack);
133 BLOCK_DICT (bl) = dict_create_linear (&objfile->objfile_obstack,
de4f826b 134 NULL);
c906108c
SS
135 BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK) = bl;
136
5c4e30ca 137 /* Allocate GLOBAL_BLOCK. */
4a146b47 138 bl = allocate_block (&objfile->objfile_obstack);
de4f826b 139 BLOCK_DICT (bl) = dict_create_hashed_expandable ();
c906108c 140 BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK) = bl;
de4f826b 141 class_symtab->free_func = free_class_block;
c906108c
SS
142 }
143 return class_symtab;
144}
145
146static void
fba45db2 147add_class_symtab_symbol (struct symbol *sym)
c906108c 148{
20781792
TT
149 struct symtab *symtab
150 = get_java_class_symtab (get_objfile_arch (SYMBOL_SYMTAB (sym)->objfile));
c906108c 151 struct blockvector *bv = BLOCKVECTOR (symtab);
de4f826b 152 dict_add_symbol (BLOCK_DICT (BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK)), sym);
c906108c
SS
153}
154
c906108c 155static struct symbol *
fba45db2 156add_class_symbol (struct type *type, CORE_ADDR addr)
c906108c
SS
157{
158 struct symbol *sym;
159 sym = (struct symbol *)
4a146b47 160 obstack_alloc (&dynamics_objfile->objfile_obstack, sizeof (struct symbol));
c906108c
SS
161 memset (sym, 0, sizeof (struct symbol));
162 SYMBOL_LANGUAGE (sym) = language_java;
3567439c 163 SYMBOL_SET_LINKAGE_NAME (sym, TYPE_TAG_NAME (type));
c906108c 164 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
c5aa993b 165 /* SYMBOL_VALUE (sym) = valu; */
c906108c 166 SYMBOL_TYPE (sym) = type;
176620f1 167 SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN;
c906108c
SS
168 SYMBOL_VALUE_ADDRESS (sym) = addr;
169 return sym;
170}
de4f826b
DC
171
172/* Free the dynamic symbols block. */
173static void
174free_class_block (struct symtab *symtab)
175{
176 struct blockvector *bv = BLOCKVECTOR (symtab);
177 struct block *bl = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
178
179 dict_free (BLOCK_DICT (bl));
180}
c906108c
SS
181
182struct type *
fba45db2 183java_lookup_class (char *name)
c906108c
SS
184{
185 struct symbol *sym;
2570f2b7 186 sym = lookup_symbol (name, expression_context_block, STRUCT_DOMAIN, NULL);
c906108c
SS
187 if (sym != NULL)
188 return SYMBOL_TYPE (sym);
189#if 0
190 CORE_ADDR addr;
191 if (called from parser)
192 {
193 call lookup_class (or similar) in inferior;
c5aa993b
JM
194 if not
195 found:
c906108c
SS
196 return NULL;
197 addr = found in inferior;
198 }
199 else
200 addr = 0;
201 struct type *type;
202 type = alloc_type (objfile);
203 TYPE_CODE (type) = TYPE_CODE_STRUCT;
204 INIT_CPLUS_SPECIFIC (type);
b99607ea 205 TYPE_TAG_NAME (type) = obsavestring (name, strlen (name), &objfile->objfile_obstack);
876cecd0 206 TYPE_STUB (type) = 1;
c906108c
SS
207 TYPE ? = addr;
208 return type;
209#else
210 /* FIXME - should search inferior's symbol table. */
211 return NULL;
212#endif
213}
214
215/* Return a nul-terminated string (allocated on OBSTACK) for
216 a name given by NAME (which has type Utf8Const*). */
217
218char *
75c9979e 219get_java_utf8_name (struct obstack *obstack, struct value *name)
c906108c
SS
220{
221 char *chrs;
75c9979e 222 struct value *temp = name;
c906108c
SS
223 int name_length;
224 CORE_ADDR data_addr;
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{
75c9979e 254 struct value *vtable = value_struct_elt (&clas, NULL, "vtable", NULL, "struct");
1aa20aa8 255 CORE_ADDR i = value_as_address (vtable);
c906108c
SS
256 return (int) (i & 0x7fffffff) == (int) 0x7fffffff;
257}
258
259/* Read a GCJ Class object, and generated a gdb (TYPE_CODE_STRUCT) type. */
260
261struct type *
0daa2b63 262type_from_class (struct gdbarch *gdbarch, struct value *clas)
c906108c
SS
263{
264 struct type *type;
265 char *name;
75c9979e 266 struct value *temp;
c906108c 267 struct objfile *objfile;
75c9979e 268 struct value *utf8_name;
c906108c
SS
269 char *nptr;
270 CORE_ADDR addr;
271 struct block *bl;
de4f826b 272 struct dict_iterator iter;
c906108c
SS
273 int is_array = 0;
274
df407dfe 275 type = check_typedef (value_type (clas));
c906108c
SS
276 if (TYPE_CODE (type) == TYPE_CODE_PTR)
277 {
278 if (value_logical_not (clas))
279 return NULL;
280 clas = value_ind (clas);
281 }
42ae5230 282 addr = value_address (clas);
c906108c
SS
283
284#if 0
285 get_java_class_symtab ();
286 bl = BLOCKVECTOR_BLOCK (BLOCKVECTOR (class_symtab), GLOBAL_BLOCK);
de4f826b 287 ALL_BLOCK_SYMBOLS (block, iter, sym)
c906108c 288 {
c906108c
SS
289 if (SYMBOL_VALUE_ADDRESS (sym) == addr)
290 return SYMBOL_TYPE (sym);
291 }
292#endif
293
20781792 294 objfile = get_dynamics_objfile (gdbarch);
c906108c
SS
295 if (java_class_is_primitive (clas))
296 {
75c9979e 297 struct value *sig;
c906108c
SS
298 temp = clas;
299 sig = value_struct_elt (&temp, NULL, "method_count", NULL, "structure");
0daa2b63 300 return java_primitive_type (gdbarch, value_as_long (sig));
c906108c
SS
301 }
302
303 /* Get Class name. */
304 /* if clasloader non-null, prepend loader address. FIXME */
305 temp = clas;
306 utf8_name = value_struct_elt (&temp, NULL, "name", NULL, "structure");
b99607ea 307 name = get_java_utf8_name (&objfile->objfile_obstack, utf8_name);
c5aa993b 308 for (nptr = name; *nptr != 0; nptr++)
c906108c
SS
309 {
310 if (*nptr == '/')
311 *nptr = '.';
312 }
313
314 type = java_lookup_class (name);
315 if (type != NULL)
316 return type;
317
20781792 318 type = alloc_type (objfile);
c906108c
SS
319 TYPE_CODE (type) = TYPE_CODE_STRUCT;
320 INIT_CPLUS_SPECIFIC (type);
321
322 if (name[0] == '[')
323 {
324 char *signature = name;
325 int namelen = java_demangled_signature_length (signature);
326 if (namelen > strlen (name))
b99607ea 327 name = obstack_alloc (&objfile->objfile_obstack, namelen + 1);
c906108c
SS
328 java_demangled_signature_copy (name, signature);
329 name[namelen] = '\0';
330 is_array = 1;
331 temp = clas;
332 /* Set array element type. */
333 temp = value_struct_elt (&temp, NULL, "methods", NULL, "structure");
04624583 334 deprecated_set_value_type (temp, lookup_pointer_type (value_type (clas)));
0daa2b63 335 TYPE_TARGET_TYPE (type) = type_from_class (gdbarch, temp);
c906108c
SS
336 }
337
338 ALLOCATE_CPLUS_STRUCT_TYPE (type);
339 TYPE_TAG_NAME (type) = name;
340
341 add_class_symtab_symbol (add_class_symbol (type, addr));
0daa2b63 342 return java_link_class_type (gdbarch, type, clas);
c906108c
SS
343}
344
c5aa993b 345/* Fill in class TYPE with data from the CLAS value. */
c906108c 346
20781792 347static struct type *
0daa2b63
UW
348java_link_class_type (struct gdbarch *gdbarch,
349 struct type *type, struct value *clas)
c906108c 350{
75c9979e 351 struct value *temp;
c906108c
SS
352 char *unqualified_name;
353 char *name = TYPE_TAG_NAME (type);
354 int ninterfaces, nfields, nmethods;
355 int type_is_object = 0;
356 struct fn_field *fn_fields;
357 struct fn_fieldlist *fn_fieldlists;
75c9979e
AC
358 struct value *fields;
359 struct value *methods;
c65ecaf3
AC
360 struct value *method = NULL;
361 struct value *field = NULL;
c906108c 362 int i, j;
20781792 363 struct objfile *objfile = get_dynamics_objfile (gdbarch);
c906108c
SS
364 struct type *tsuper;
365
03b4bca2 366 gdb_assert (name != NULL);
c906108c
SS
367 unqualified_name = strrchr (name, '.');
368 if (unqualified_name == NULL)
369 unqualified_name = name;
370
371 temp = clas;
372 temp = value_struct_elt (&temp, NULL, "superclass", NULL, "structure");
03b4bca2 373 if (strcmp (name, "java.lang.Object") == 0)
c906108c
SS
374 {
375 tsuper = get_java_object_type ();
376 if (tsuper && TYPE_CODE (tsuper) == TYPE_CODE_PTR)
377 tsuper = TYPE_TARGET_TYPE (tsuper);
378 type_is_object = 1;
379 }
380 else
0daa2b63 381 tsuper = type_from_class (gdbarch, temp);
c906108c
SS
382
383#if 1
384 ninterfaces = 0;
385#else
386 temp = clas;
387 ninterfaces = value_as_long (value_struct_elt (&temp, NULL, "interface_len", NULL, "structure"));
388#endif
389 TYPE_N_BASECLASSES (type) = (tsuper == NULL ? 0 : 1) + ninterfaces;
390 temp = clas;
391 nfields = value_as_long (value_struct_elt (&temp, NULL, "field_count", NULL, "structure"));
392 nfields += TYPE_N_BASECLASSES (type);
c5aa993b 393 nfields++; /* Add one for dummy "class" field. */
c906108c
SS
394 TYPE_NFIELDS (type) = nfields;
395 TYPE_FIELDS (type) = (struct field *)
396 TYPE_ALLOC (type, sizeof (struct field) * nfields);
397
398 memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields);
399
400 TYPE_FIELD_PRIVATE_BITS (type) =
401 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
402 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields);
403
404 TYPE_FIELD_PROTECTED_BITS (type) =
405 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
406 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields);
407
408 TYPE_FIELD_IGNORE_BITS (type) =
409 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
410 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields);
411
412 TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *)
413 TYPE_ALLOC (type, B_BYTES (TYPE_N_BASECLASSES (type)));
414 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), TYPE_N_BASECLASSES (type));
415
416 if (tsuper != NULL)
417 {
418 TYPE_BASECLASS (type, 0) = tsuper;
419 if (type_is_object)
420 SET_TYPE_FIELD_PRIVATE (type, 0);
421 }
422
423 i = strlen (name);
c5aa993b 424 if (i > 2 && name[i - 1] == ']' && tsuper != NULL)
c906108c
SS
425 {
426 /* FIXME */
c5aa993b 427 TYPE_LENGTH (type) = TYPE_LENGTH (tsuper) + 4; /* size with "length" */
c906108c
SS
428 }
429 else
430 {
431 temp = clas;
432 temp = value_struct_elt (&temp, NULL, "size_in_bytes", NULL, "structure");
433 TYPE_LENGTH (type) = value_as_long (temp);
434 }
435
436 fields = NULL;
c5aa993b 437 nfields--; /* First set up dummy "class" field. */
42ae5230 438 SET_FIELD_PHYSADDR (TYPE_FIELD (type, nfields), value_address (clas));
c906108c 439 TYPE_FIELD_NAME (type, nfields) = "class";
df407dfe 440 TYPE_FIELD_TYPE (type, nfields) = value_type (clas);
c906108c 441 SET_TYPE_FIELD_PRIVATE (type, nfields);
c5aa993b
JM
442
443 for (i = TYPE_N_BASECLASSES (type); i < nfields; i++)
c906108c
SS
444 {
445 int accflags;
446 int boffset;
447 if (fields == NULL)
448 {
449 temp = clas;
450 fields = value_struct_elt (&temp, NULL, "fields", NULL, "structure");
451 field = value_ind (fields);
452 }
453 else
c5aa993b 454 { /* Re-use field value for next field. */
42ae5230
TT
455 CORE_ADDR addr
456 = value_address (field) + TYPE_LENGTH (value_type (field));
457 set_value_address (field, addr);
dfa52d88 458 set_value_lazy (field, 1);
c906108c
SS
459 }
460 temp = field;
461 temp = value_struct_elt (&temp, NULL, "name", NULL, "structure");
462 TYPE_FIELD_NAME (type, i) =
b99607ea 463 get_java_utf8_name (&objfile->objfile_obstack, temp);
c906108c
SS
464 temp = field;
465 accflags = value_as_long (value_struct_elt (&temp, NULL, "accflags",
466 NULL, "structure"));
467 temp = field;
468 temp = value_struct_elt (&temp, NULL, "info", NULL, "structure");
469 boffset = value_as_long (value_struct_elt (&temp, NULL, "boffset",
c5aa993b
JM
470 NULL, "structure"));
471 if (accflags & 0x0001) /* public access */
c906108c
SS
472 {
473 /* ??? */
474 }
c5aa993b 475 if (accflags & 0x0002) /* private access */
c906108c
SS
476 {
477 SET_TYPE_FIELD_PRIVATE (type, i);
478 }
c5aa993b 479 if (accflags & 0x0004) /* protected access */
c906108c
SS
480 {
481 SET_TYPE_FIELD_PROTECTED (type, i);
482 }
c5aa993b
JM
483 if (accflags & 0x0008) /* ACC_STATIC */
484 SET_FIELD_PHYSADDR (TYPE_FIELD (type, i), boffset);
c906108c
SS
485 else
486 TYPE_FIELD_BITPOS (type, i) = 8 * boffset;
c5aa993b 487 if (accflags & 0x8000) /* FIELD_UNRESOLVED_FLAG */
c906108c 488 {
c5aa993b 489 TYPE_FIELD_TYPE (type, i) = get_java_object_type (); /* FIXME */
c906108c
SS
490 }
491 else
492 {
493 struct type *ftype;
494 temp = field;
495 temp = value_struct_elt (&temp, NULL, "type", NULL, "structure");
0daa2b63 496 ftype = type_from_class (gdbarch, temp);
c906108c
SS
497 if (TYPE_CODE (ftype) == TYPE_CODE_STRUCT)
498 ftype = lookup_pointer_type (ftype);
499 TYPE_FIELD_TYPE (type, i) = ftype;
500 }
501 }
502
503 temp = clas;
504 nmethods = value_as_long (value_struct_elt (&temp, NULL, "method_count",
505 NULL, "structure"));
506 TYPE_NFN_FIELDS_TOTAL (type) = nmethods;
507 j = nmethods * sizeof (struct fn_field);
c5aa993b 508 fn_fields = (struct fn_field *)
4a146b47 509 obstack_alloc (&dynamics_objfile->objfile_obstack, j);
c906108c 510 memset (fn_fields, 0, j);
c5aa993b 511 fn_fieldlists = (struct fn_fieldlist *)
c906108c
SS
512 alloca (nmethods * sizeof (struct fn_fieldlist));
513
514 methods = NULL;
c5aa993b 515 for (i = 0; i < nmethods; i++)
c906108c
SS
516 {
517 char *mname;
518 int k;
519 if (methods == NULL)
520 {
521 temp = clas;
522 methods = value_struct_elt (&temp, NULL, "methods", NULL, "structure");
523 method = value_ind (methods);
524 }
525 else
c5aa993b 526 { /* Re-use method value for next method. */
42ae5230
TT
527 CORE_ADDR addr
528 = value_address (method) + TYPE_LENGTH (value_type (method));
529 set_value_address (method, addr);
dfa52d88 530 set_value_lazy (method, 1);
c906108c
SS
531 }
532
533 /* Get method name. */
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)
c5aa993b
JM
549 { /* No match - new method name. */
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)
c5aa993b 558 { /* Found an existing method with the same name. */
c906108c
SS
559 int l;
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++;
c5aa993b 564 k = i - k; /* Index of new slot. */
c906108c 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 *)
4a146b47 584 obstack_alloc (&dynamics_objfile->objfile_obstack, j);
c906108c 585 memcpy (TYPE_FN_FIELDLISTS (type), fn_fieldlists, j);
c5aa993b 586
c906108c
SS
587 return type;
588}
589
590static struct type *java_object_type;
591
20781792
TT
592/* A free function that is attached to the objfile defining
593 java_object_type. This is used to clear the cached type whenever
594 its owning objfile is destroyed. */
595static void
596jv_clear_object_type (struct objfile *objfile, void *ignore)
597{
598 java_object_type = NULL;
599}
600
601static void
602set_java_object_type (struct type *type)
603{
604 struct objfile *owner;
605
606 gdb_assert (java_object_type == NULL);
607
608 owner = TYPE_OBJFILE (type);
609 if (owner)
610 set_objfile_data (owner, jv_type_objfile_data_key, &java_object_type);
611 java_object_type = type;
612}
613
c906108c 614struct type *
fba45db2 615get_java_object_type (void)
c906108c
SS
616{
617 if (java_object_type == NULL)
618 {
619 struct symbol *sym;
2570f2b7 620 sym = lookup_symbol ("java.lang.Object", NULL, STRUCT_DOMAIN, NULL);
c906108c 621 if (sym == NULL)
8a3fe4f8 622 error (_("cannot find java.lang.Object"));
20781792 623 set_java_object_type (SYMBOL_TYPE (sym));
c906108c
SS
624 }
625 return java_object_type;
626}
627
628int
45d5d5ca 629get_java_object_header_size (struct gdbarch *gdbarch)
c906108c
SS
630{
631 struct type *objtype = get_java_object_type ();
632 if (objtype == NULL)
45d5d5ca 633 return (2 * gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT);
c906108c
SS
634 else
635 return TYPE_LENGTH (objtype);
636}
637
638int
fba45db2 639is_object_type (struct type *type)
c906108c
SS
640{
641 CHECK_TYPEDEF (type);
642 if (TYPE_CODE (type) == TYPE_CODE_PTR)
643 {
644 struct type *ttype = check_typedef (TYPE_TARGET_TYPE (type));
645 char *name;
646 if (TYPE_CODE (ttype) != TYPE_CODE_STRUCT)
647 return 0;
648 while (TYPE_N_BASECLASSES (ttype) > 0)
649 ttype = TYPE_BASECLASS (ttype, 0);
650 name = TYPE_TAG_NAME (ttype);
651 if (name != NULL && strcmp (name, "java.lang.Object") == 0)
652 return 1;
c5aa993b 653 name = TYPE_NFIELDS (ttype) > 0 ? TYPE_FIELD_NAME (ttype, 0) : (char *) 0;
c906108c
SS
654 if (name != NULL && strcmp (name, "vtable") == 0)
655 {
656 if (java_object_type == NULL)
20781792 657 set_java_object_type (type);
c906108c
SS
658 return 1;
659 }
660 }
661 return 0;
662}
663
664struct type *
0daa2b63 665java_primitive_type (struct gdbarch *gdbarch, int signature)
c906108c 666{
0daa2b63
UW
667 const struct builtin_java_type *builtin = builtin_java_type (gdbarch);
668
c906108c
SS
669 switch (signature)
670 {
c5aa993b 671 case 'B':
0daa2b63 672 return builtin->builtin_byte;
c5aa993b 673 case 'S':
0daa2b63 674 return builtin->builtin_short;
c5aa993b 675 case 'I':
0daa2b63 676 return builtin->builtin_int;
c5aa993b 677 case 'J':
0daa2b63 678 return builtin->builtin_long;
c5aa993b 679 case 'Z':
0daa2b63 680 return builtin->builtin_boolean;
c5aa993b 681 case 'C':
0daa2b63 682 return builtin->builtin_char;
c5aa993b 683 case 'F':
0daa2b63 684 return builtin->builtin_float;
c5aa993b 685 case 'D':
0daa2b63 686 return builtin->builtin_double;
c5aa993b 687 case 'V':
0daa2b63 688 return builtin->builtin_void;
c906108c 689 }
8a3fe4f8 690 error (_("unknown signature '%c' for primitive type"), (char) signature);
c906108c
SS
691}
692
693/* If name[0 .. namelen-1] is the name of a primitive Java type,
694 return that type. Otherwise, return NULL. */
695
696struct type *
0daa2b63
UW
697java_primitive_type_from_name (struct gdbarch *gdbarch,
698 char *name, int namelen)
c906108c 699{
0daa2b63
UW
700 const struct builtin_java_type *builtin = builtin_java_type (gdbarch);
701
c906108c
SS
702 switch (name[0])
703 {
704 case 'b':
705 if (namelen == 4 && memcmp (name, "byte", 4) == 0)
0daa2b63 706 return builtin->builtin_byte;
c906108c 707 if (namelen == 7 && memcmp (name, "boolean", 7) == 0)
0daa2b63 708 return builtin->builtin_boolean;
c906108c
SS
709 break;
710 case 'c':
711 if (namelen == 4 && memcmp (name, "char", 4) == 0)
0daa2b63 712 return builtin->builtin_char;
c906108c
SS
713 case 'd':
714 if (namelen == 6 && memcmp (name, "double", 6) == 0)
0daa2b63 715 return builtin->builtin_double;
c906108c
SS
716 break;
717 case 'f':
718 if (namelen == 5 && memcmp (name, "float", 5) == 0)
0daa2b63 719 return builtin->builtin_float;
c906108c
SS
720 break;
721 case 'i':
722 if (namelen == 3 && memcmp (name, "int", 3) == 0)
0daa2b63 723 return builtin->builtin_int;
c906108c
SS
724 break;
725 case 'l':
726 if (namelen == 4 && memcmp (name, "long", 4) == 0)
0daa2b63 727 return builtin->builtin_long;
c906108c
SS
728 break;
729 case 's':
730 if (namelen == 5 && memcmp (name, "short", 5) == 0)
0daa2b63 731 return builtin->builtin_short;
c906108c
SS
732 break;
733 case 'v':
734 if (namelen == 4 && memcmp (name, "void", 4) == 0)
0daa2b63 735 return builtin->builtin_void;
c906108c
SS
736 break;
737 }
738 return NULL;
739}
740
0daa2b63
UW
741static char *
742java_primitive_type_name (int signature)
743{
744 switch (signature)
745 {
746 case 'B':
747 return "byte";
748 case 'S':
749 return "short";
750 case 'I':
751 return "int";
752 case 'J':
753 return "long";
754 case 'Z':
755 return "boolean";
756 case 'C':
757 return "char";
758 case 'F':
759 return "float";
760 case 'D':
761 return "double";
762 case 'V':
763 return "void";
764 }
765 error (_("unknown signature '%c' for primitive type"), (char) signature);
766}
767
c906108c
SS
768/* Return the length (in bytes) of demangled name of the Java type
769 signature string SIGNATURE. */
770
771static int
fba45db2 772java_demangled_signature_length (char *signature)
c906108c
SS
773{
774 int array = 0;
c5aa993b
JM
775 for (; *signature == '['; signature++)
776 array += 2; /* Two chars for "[]". */
c906108c
SS
777 switch (signature[0])
778 {
779 case 'L':
780 /* Subtract 2 for 'L' and ';'. */
781 return strlen (signature) - 2 + array;
782 default:
0daa2b63 783 return strlen (java_primitive_type_name (signature[0])) + array;
c906108c
SS
784 }
785}
786
787/* Demangle the Java type signature SIGNATURE, leaving the result in RESULT. */
788
789static void
fba45db2 790java_demangled_signature_copy (char *result, char *signature)
c906108c
SS
791{
792 int array = 0;
793 char *ptr;
794 int i;
795 while (*signature == '[')
796 {
797 array++;
798 signature++;
799 }
800 switch (signature[0])
801 {
802 case 'L':
803 /* Subtract 2 for 'L' and ';', but add 1 for final nul. */
804 signature++;
805 ptr = result;
c5aa993b 806 for (; *signature != ';' && *signature != '\0'; signature++)
c906108c
SS
807 {
808 if (*signature == '/')
809 *ptr++ = '.';
810 else
811 *ptr++ = *signature;
812 }
813 break;
814 default:
0daa2b63 815 ptr = java_primitive_type_name (signature[0]);
c906108c
SS
816 i = strlen (ptr);
817 strcpy (result, ptr);
818 ptr = result + i;
819 break;
820 }
821 while (--array >= 0)
822 {
823 *ptr++ = '[';
824 *ptr++ = ']';
825 }
826}
827
828/* Return the demangled name of the Java type signature string SIGNATURE,
829 as a freshly allocated copy. */
830
831char *
fba45db2 832java_demangle_type_signature (char *signature)
c906108c
SS
833{
834 int length = java_demangled_signature_length (signature);
835 char *result = xmalloc (length + 1);
836 java_demangled_signature_copy (result, signature);
837 result[length] = '\0';
838 return result;
839}
840
c906108c
SS
841/* Return the type of TYPE followed by DIMS pairs of [ ].
842 If DIMS == 0, TYPE is returned. */
843
844struct type *
fba45db2 845java_array_type (struct type *type, int dims)
c906108c 846{
c906108c
SS
847 while (dims-- > 0)
848 {
c906108c 849 /* FIXME This is bogus! Java arrays are not gdb arrays! */
e3506a9f 850 type = lookup_array_range_type (type, 0, 0);
c906108c
SS
851 }
852
853 return type;
854}
855
856/* Create a Java string in the inferior from a (Utf8) literal. */
857
75c9979e 858static struct value *
fba45db2 859java_value_string (char *ptr, int len)
c906108c 860{
8a3fe4f8 861 error (_("not implemented - java_value_string")); /* FIXME */
c906108c
SS
862}
863
864/* Print the character C on STREAM as part of the contents of a literal
865 string whose delimiter is QUOTER. Note that that format for printing
866 characters and strings is language specific. */
867
868static void
6c7a06a3 869java_emit_char (int c, struct type *type, struct ui_file *stream, int quoter)
c906108c
SS
870{
871 switch (c)
872 {
873 case '\\':
874 case '\'':
875 fprintf_filtered (stream, "\\%c", c);
876 break;
877 case '\b':
878 fputs_filtered ("\\b", stream);
879 break;
880 case '\t':
881 fputs_filtered ("\\t", stream);
882 break;
883 case '\n':
884 fputs_filtered ("\\n", stream);
885 break;
886 case '\f':
887 fputs_filtered ("\\f", stream);
888 break;
889 case '\r':
890 fputs_filtered ("\\r", stream);
891 break;
892 default:
893 if (isprint (c))
894 fputc_filtered (c, stream);
895 else
896 fprintf_filtered (stream, "\\u%.4x", (unsigned int) c);
897 break;
898 }
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;
907 char *name;
908 enum exp_opcode op = exp->elts[*pos].opcode;
75c9979e
AC
909 struct value *arg1;
910 struct value *arg2;
c906108c
SS
911 struct type *type;
912 switch (op)
913 {
914 case UNOP_IND:
915 if (noside == EVAL_SKIP)
916 goto standard;
917 (*pos)++;
918 arg1 = evaluate_subexp_java (NULL_TYPE, exp, pos, EVAL_NORMAL);
df407dfe 919 if (is_object_type (value_type (arg1)))
c906108c
SS
920 {
921 struct type *type;
922
0daa2b63 923 type = type_from_class (exp->gdbarch, java_class_from_object (arg1));
c906108c
SS
924 arg1 = value_cast (lookup_pointer_type (type), arg1);
925 }
926 if (noside == EVAL_SKIP)
927 goto nosideret;
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
JM
937 array or pointer type (like a plain int variable for example),
938 then report this as an error. */
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;
c906108c
SS
959 /* Get CLASS_ELEMENT_TYPE of the array type. */
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
SS
1001 arg1 = evaluate_subexp_standard (expect_type, exp, pos, noside);
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;
1056 int depth = 0;
1057 char *demangled_name = java_demangle (physname, DMGL_PARAMS | DMGL_ANSI);
1058
1059 if (demangled_name == NULL)
1060 return NULL;
1061
1062 end = java_find_last_component (demangled_name);
1063 if (end != NULL)
1064 {
1065 ret = xmalloc (end - demangled_name + 1);
1066 memcpy (ret, demangled_name, end - demangled_name);
1067 ret[end - demangled_name] = '\0';
1068 }
1069
1070 xfree (demangled_name);
1071 return ret;
1072}
9a3d7dfd 1073
c906108c
SS
1074/* Table mapping opcodes into strings for printing operators
1075 and precedences of the operators. */
1076
1077const struct op_print java_op_print_tab[] =
c5aa993b
JM
1078{
1079 {",", BINOP_COMMA, PREC_COMMA, 0},
1080 {"=", BINOP_ASSIGN, PREC_ASSIGN, 1},
1081 {"||", BINOP_LOGICAL_OR, PREC_LOGICAL_OR, 0},
1082 {"&&", BINOP_LOGICAL_AND, PREC_LOGICAL_AND, 0},
1083 {"|", BINOP_BITWISE_IOR, PREC_BITWISE_IOR, 0},
1084 {"^", BINOP_BITWISE_XOR, PREC_BITWISE_XOR, 0},
1085 {"&", BINOP_BITWISE_AND, PREC_BITWISE_AND, 0},
1086 {"==", BINOP_EQUAL, PREC_EQUAL, 0},
1087 {"!=", BINOP_NOTEQUAL, PREC_EQUAL, 0},
1088 {"<=", BINOP_LEQ, PREC_ORDER, 0},
1089 {">=", BINOP_GEQ, PREC_ORDER, 0},
1090 {">", BINOP_GTR, PREC_ORDER, 0},
1091 {"<", BINOP_LESS, PREC_ORDER, 0},
1092 {">>", BINOP_RSH, PREC_SHIFT, 0},
1093 {"<<", BINOP_LSH, PREC_SHIFT, 0},
c906108c 1094#if 0
c5aa993b 1095 {">>>", BINOP_ ? ? ?, PREC_SHIFT, 0},
c906108c 1096#endif
c5aa993b
JM
1097 {"+", BINOP_ADD, PREC_ADD, 0},
1098 {"-", BINOP_SUB, PREC_ADD, 0},
1099 {"*", BINOP_MUL, PREC_MUL, 0},
1100 {"/", BINOP_DIV, PREC_MUL, 0},
1101 {"%", BINOP_REM, PREC_MUL, 0},
1102 {"-", UNOP_NEG, PREC_PREFIX, 0},
1103 {"!", UNOP_LOGICAL_NOT, PREC_PREFIX, 0},
1104 {"~", UNOP_COMPLEMENT, PREC_PREFIX, 0},
1105 {"*", UNOP_IND, PREC_PREFIX, 0},
c906108c 1106#if 0
c5aa993b 1107 {"instanceof", ? ? ?, ? ? ?, 0},
c906108c 1108#endif
c5aa993b
JM
1109 {"++", UNOP_PREINCREMENT, PREC_PREFIX, 0},
1110 {"--", UNOP_PREDECREMENT, PREC_PREFIX, 0},
1111 {NULL, 0, 0, 0}
c906108c
SS
1112};
1113
de7b6b47
UW
1114enum java_primitive_types
1115{
1116 java_primitive_type_int,
1117 java_primitive_type_short,
1118 java_primitive_type_long,
1119 java_primitive_type_byte,
1120 java_primitive_type_boolean,
1121 java_primitive_type_char,
1122 java_primitive_type_float,
1123 java_primitive_type_double,
1124 java_primitive_type_void,
1125 nr_java_primitive_types
1126};
1127
2c0b251b 1128static void
de7b6b47
UW
1129java_language_arch_info (struct gdbarch *gdbarch,
1130 struct language_arch_info *lai)
1131{
0daa2b63
UW
1132 const struct builtin_java_type *builtin = builtin_java_type (gdbarch);
1133
1134 lai->string_char_type = builtin->builtin_char;
de7b6b47
UW
1135 lai->primitive_type_vector
1136 = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_java_primitive_types + 1,
1137 struct type *);
1138 lai->primitive_type_vector [java_primitive_type_int]
0daa2b63 1139 = builtin->builtin_int;
de7b6b47 1140 lai->primitive_type_vector [java_primitive_type_short]
0daa2b63 1141 = builtin->builtin_short;
de7b6b47 1142 lai->primitive_type_vector [java_primitive_type_long]
0daa2b63 1143 = builtin->builtin_long;
de7b6b47 1144 lai->primitive_type_vector [java_primitive_type_byte]
0daa2b63 1145 = builtin->builtin_byte;
de7b6b47 1146 lai->primitive_type_vector [java_primitive_type_boolean]
0daa2b63 1147 = builtin->builtin_boolean;
de7b6b47 1148 lai->primitive_type_vector [java_primitive_type_char]
0daa2b63 1149 = builtin->builtin_char;
de7b6b47 1150 lai->primitive_type_vector [java_primitive_type_float]
0daa2b63 1151 = builtin->builtin_float;
de7b6b47 1152 lai->primitive_type_vector [java_primitive_type_double]
0daa2b63 1153 = builtin->builtin_double;
de7b6b47 1154 lai->primitive_type_vector [java_primitive_type_void]
0daa2b63 1155 = builtin->builtin_void;
fbb06eb1
UW
1156
1157 lai->bool_type_symbol = "boolean";
0daa2b63 1158 lai->bool_type_default = builtin->builtin_boolean;
de7b6b47
UW
1159}
1160
5f9769d1
PH
1161const struct exp_descriptor exp_descriptor_java =
1162{
1163 print_subexp_standard,
1164 operator_length_standard,
c0201579 1165 operator_check_standard,
5f9769d1
PH
1166 op_name_standard,
1167 dump_subexp_body_standard,
1168 evaluate_subexp_java
1169};
1170
c5aa993b
JM
1171const struct language_defn java_language_defn =
1172{
1173 "java", /* Language name */
c906108c 1174 language_java,
c906108c
SS
1175 range_check_off,
1176 type_check_off,
63872f9d 1177 case_sensitive_on,
7ca2d3a3 1178 array_row_major,
9a044a89 1179 macro_expansion_no,
5f9769d1 1180 &exp_descriptor_java,
c906108c
SS
1181 java_parse,
1182 java_error,
e85c3284 1183 null_post_parser,
c906108c
SS
1184 c_printchar, /* Print a character constant */
1185 c_printstr, /* Function to print string constant */
1186 java_emit_char, /* Function to print a single character */
c906108c 1187 java_print_type, /* Print a type using appropriate syntax */
5c6ce71d 1188 default_print_typedef, /* Print a typedef using appropriate syntax */
c906108c
SS
1189 java_val_print, /* Print a value using appropriate syntax */
1190 java_value_print, /* Print a top-level value */
f636b87d 1191 NULL, /* Language specific skip_trampoline */
2b2d9e11 1192 "this", /* name_of_this */
5f9a71c3 1193 basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
b368761e 1194 basic_lookup_transparent_type,/* lookup_transparent_type */
9a3d7dfd 1195 java_demangle, /* Language specific symbol demangler */
31c27f77 1196 java_class_name_from_physname,/* Language specific class name */
c906108c
SS
1197 java_op_print_tab, /* expression operators for printing */
1198 0, /* not c-style arrays */
1199 0, /* String lower bound */
6084f43a 1200 default_word_break_characters,
41d27058 1201 default_make_symbol_completion_list,
de7b6b47 1202 java_language_arch_info,
e79af960 1203 default_print_array_index,
41f1b697 1204 default_pass_by_reference,
ae6a3a4c 1205 default_get_string,
c906108c
SS
1206 LANG_MAGIC
1207};
1208
0daa2b63
UW
1209static void *
1210build_java_types (struct gdbarch *gdbarch)
1211{
1212 struct builtin_java_type *builtin_java_type
1213 = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct builtin_java_type);
1214
1215 builtin_java_type->builtin_int
e9bb382b 1216 = arch_integer_type (gdbarch, 32, 0, "int");
0daa2b63 1217 builtin_java_type->builtin_short
e9bb382b 1218 = arch_integer_type (gdbarch, 16, 0, "short");
0daa2b63 1219 builtin_java_type->builtin_long
e9bb382b 1220 = arch_integer_type (gdbarch, 64, 0, "long");
0daa2b63 1221 builtin_java_type->builtin_byte
e9bb382b 1222 = arch_integer_type (gdbarch, 8, 0, "byte");
0daa2b63 1223 builtin_java_type->builtin_boolean
e9bb382b 1224 = arch_boolean_type (gdbarch, 8, 0, "boolean");
0daa2b63 1225 builtin_java_type->builtin_char
e9bb382b 1226 = arch_character_type (gdbarch, 16, 1, "char");
0daa2b63 1227 builtin_java_type->builtin_float
e9bb382b 1228 = arch_float_type (gdbarch, 32, "float", NULL);
0daa2b63 1229 builtin_java_type->builtin_double
e9bb382b 1230 = arch_float_type (gdbarch, 64, "double", NULL);
0daa2b63 1231 builtin_java_type->builtin_void
e9bb382b 1232 = arch_type (gdbarch, TYPE_CODE_VOID, 1, "void");
0daa2b63
UW
1233
1234 return builtin_java_type;
1235}
1236
1237static struct gdbarch_data *java_type_data;
1238
1239const struct builtin_java_type *
1240builtin_java_type (struct gdbarch *gdbarch)
1241{
1242 return gdbarch_data (gdbarch, java_type_data);
1243}
1244
c906108c 1245void
fba45db2 1246_initialize_java_language (void)
c906108c 1247{
20781792
TT
1248 jv_dynamics_objfile_data_key
1249 = register_objfile_data_with_cleanup (NULL, jv_per_objfile_free);
1250 jv_type_objfile_data_key
1251 = register_objfile_data_with_cleanup (NULL, jv_clear_object_type);
1252
0daa2b63 1253 java_type_data = gdbarch_data_register_post_init (build_java_types);
c906108c
SS
1254
1255 add_language (&java_language_defn);
1256}
This page took 0.887299 seconds and 4 git commands to generate.