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