Commit | Line | Data |
---|---|---|
7a9eb4c4 PB |
1 | /* Java language support routines for GDB, the GNU debugger. |
2 | Copyright 1997 Free Software Foundation, Inc. | |
3 | ||
4 | This file is part of GDB. | |
5 | ||
6 | This program is free software; you can redistribute it and/or modify | |
7 | it under the terms of the GNU General Public License as published by | |
8 | the Free Software Foundation; either version 2 of the License, or | |
9 | (at your option) any later version. | |
10 | ||
11 | This program is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
17 | along with this program; if not, write to the Free Software | |
18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | |
19 | ||
20 | #include "defs.h" | |
21 | #include "symtab.h" | |
22 | #include "gdbtypes.h" | |
23 | #include "expression.h" | |
24 | #include "parser-defs.h" | |
25 | #include "language.h" | |
26 | #include "gdbtypes.h" | |
27 | #include "symtab.h" | |
28 | #include "symfile.h" | |
29 | #include "objfiles.h" | |
30 | #include "gdb_string.h" | |
31 | #include "value.h" | |
32 | #include "c-lang.h" | |
33 | #include "java-lang.h" | |
40b647e9 | 34 | #include "gdbcore.h" |
7a9eb4c4 PB |
35 | |
36 | struct type *java_int_type; | |
37 | struct type *java_byte_type; | |
38 | struct type *java_short_type; | |
39 | struct type *java_long_type; | |
40 | struct type *java_boolean_type; | |
41 | struct type *java_char_type; | |
42 | struct type *java_float_type; | |
43 | struct type *java_double_type; | |
44 | struct type *java_void_type; | |
45 | ||
46 | struct type *java_object_type; | |
47 | ||
48 | /* This objfile contains symtabs that have been dynamically created | |
49 | to record dynamically loaded Java classes and dynamically | |
50 | compiled java methods. */ | |
51 | struct objfile *dynamics_objfile = NULL; | |
52 | ||
53 | struct objfile * | |
54 | get_dynamics_objfile () | |
55 | { | |
56 | if (dynamics_objfile == NULL) | |
57 | { | |
58 | dynamics_objfile = allocate_objfile (NULL, 0); | |
59 | } | |
60 | return dynamics_objfile; | |
61 | } | |
62 | ||
63 | #if 1 | |
64 | /* symtab contains classes read from the inferior. */ | |
65 | ||
66 | static struct symtab *class_symtab = NULL; | |
67 | ||
68 | /* Maximum number of class in class_symtab before relocation is needed. */ | |
69 | ||
70 | static int class_symtab_space; | |
71 | ||
72 | struct symtab * | |
73 | get_java_class_symtab () | |
74 | { | |
75 | if (class_symtab == NULL) | |
76 | { | |
77 | struct objfile *objfile = get_dynamics_objfile(); | |
78 | struct blockvector *bv; | |
79 | struct block *bl; | |
80 | class_symtab = allocate_symtab ("<java-classes>", objfile); | |
81 | class_symtab->language = language_java; | |
82 | bv = (struct blockvector *) | |
83 | obstack_alloc (&objfile->symbol_obstack, sizeof (struct blockvector)); | |
84 | BLOCKVECTOR_NBLOCKS (bv) = 1; | |
85 | BLOCKVECTOR (class_symtab) = bv; | |
86 | ||
87 | /* Allocate dummy STATIC_BLOCK. */ | |
88 | bl = (struct block *) | |
89 | obstack_alloc (&objfile->symbol_obstack, sizeof (struct block)); | |
90 | BLOCK_NSYMS (bl) = 0; | |
91 | BLOCK_START (bl) = 0; | |
92 | BLOCK_END (bl) = 0; | |
93 | BLOCK_FUNCTION (bl) = NULL; | |
94 | BLOCK_SUPERBLOCK (bl) = NULL; | |
95 | BLOCK_GCC_COMPILED (bl) = 0; | |
96 | BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK) = bl; | |
97 | ||
98 | /* Allocate GLOBAL_BLOCK. This has to be relocatable. */ | |
99 | class_symtab_space = 128; | |
100 | bl = (struct block *) | |
101 | mmalloc (objfile->md, | |
102 | sizeof (struct block) | |
103 | + ((class_symtab_space - 1) * sizeof (struct symbol *))); | |
104 | *bl = *BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK); | |
105 | BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK) = bl; | |
106 | class_symtab->free_ptr = (char *) bl; | |
107 | } | |
108 | return class_symtab; | |
109 | } | |
110 | ||
111 | static void | |
112 | add_class_symtab_symbol (sym) | |
113 | struct symbol *sym; | |
114 | { | |
115 | struct symtab *symtab = get_java_class_symtab (); | |
116 | struct blockvector *bv = BLOCKVECTOR (symtab); | |
117 | struct block *bl = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK); | |
118 | if (BLOCK_NSYMS (bl) >= class_symtab_space) | |
119 | { | |
120 | /* Need to re-allocate. */ | |
121 | class_symtab_space *= 2; | |
122 | bl = (struct block *) | |
123 | mrealloc (symtab->objfile->md, bl, | |
124 | sizeof (struct block) | |
125 | + ((class_symtab_space - 1) * sizeof (struct symbol *))); | |
126 | class_symtab->free_ptr = (char *) bl; | |
127 | BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK) = bl; | |
128 | } | |
129 | ||
130 | BLOCK_SYM (bl, BLOCK_NSYMS (bl)) = sym; | |
131 | BLOCK_NSYMS (bl) = BLOCK_NSYMS (bl) + 1; | |
132 | } | |
133 | ||
134 | struct symbol * | |
135 | add_class_symbol (type, addr) | |
136 | struct type *type; | |
137 | CORE_ADDR addr; | |
138 | { | |
139 | struct symbol *sym; | |
140 | sym = (struct symbol *) | |
141 | obstack_alloc (&dynamics_objfile->symbol_obstack, sizeof (struct symbol)); | |
142 | memset (sym, 0, sizeof (struct symbol)); | |
143 | SYMBOL_LANGUAGE (sym) = language_java; | |
144 | SYMBOL_NAME (sym) = TYPE_NAME (type); | |
145 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
146 | /* SYMBOL_VALUE (sym) = valu;*/ | |
147 | SYMBOL_TYPE (sym) = type; | |
148 | SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE; | |
149 | SYMBOL_VALUE_ADDRESS (sym) = addr; | |
150 | return sym; | |
151 | } | |
152 | #endif | |
153 | ||
154 | struct type * | |
155 | java_lookup_class (name) | |
156 | char *name; | |
157 | { | |
158 | struct symbol *sym; | |
159 | sym = lookup_symbol (name, expression_context_block, STRUCT_NAMESPACE, | |
160 | (int *) 0, (struct symtab **) NULL); | |
161 | if (sym == NULL) | |
162 | { | |
163 | /* FIXME - should search inferior's symbol table. */ | |
164 | return NULL; | |
165 | } | |
166 | return SYMBOL_TYPE (sym); | |
167 | } | |
168 | ||
169 | /* Return a nul-terminated string (allocated on OBSTACK) for | |
170 | a name given by NAME (which has type Utf8Const*). */ | |
171 | ||
172 | char * | |
173 | get_java_utf8_name (obstack, name) | |
174 | struct obstack *obstack; | |
175 | value_ptr name; | |
176 | { | |
177 | char *chrs; | |
178 | value_ptr temp = name; | |
179 | int name_length = (int) value_as_long | |
180 | (value_struct_elt (&temp, NULL, "length", NULL, "structure")); | |
181 | temp = name; | |
182 | temp = value_struct_elt (&temp, NULL, "data", NULL, "structure"); | |
183 | chrs = obstack_alloc (obstack, name_length+1); | |
184 | chrs [name_length] = '\0'; | |
185 | read_memory_section (VALUE_ADDRESS (temp) + VALUE_OFFSET (temp), | |
186 | chrs, name_length, NULL); | |
187 | return chrs; | |
188 | } | |
189 | ||
190 | value_ptr | |
191 | java_class_from_object (obj_val) | |
192 | value_ptr obj_val; | |
193 | { | |
194 | value_ptr dtable_val = value_struct_elt (&obj_val, NULL, "dtable", NULL, "structure"); | |
195 | return value_struct_elt (&dtable_val, NULL, "class", NULL, "structure"); | |
196 | } | |
197 | ||
198 | /* Check if CLASS_IS_PRIMITIVE(value of clas): */ | |
199 | int | |
200 | java_class_is_primitive (clas) | |
201 | value_ptr clas; | |
202 | { | |
203 | value_ptr dtable = value_struct_elt (&clas, NULL, "dtable", NULL, "struct"); | |
204 | CORE_ADDR i = value_as_pointer (dtable); | |
205 | return (int) (i & 0x7fffffff) == (int) 0x7fffffff; | |
206 | } | |
207 | ||
208 | /* Read a Kaffe Class object, and generated a gdb (TYPE_CODE_STRUCT) type. */ | |
209 | ||
210 | struct type * | |
211 | type_from_class (clas) | |
212 | value_ptr clas; | |
213 | { | |
214 | struct type *type; | |
215 | struct type *tsuper; | |
216 | int ninterfaces, nfields; | |
217 | char *name; | |
218 | value_ptr temp; | |
219 | struct objfile *objfile = get_dynamics_objfile(); | |
220 | value_ptr utf8_name, fields, field, method, methods; | |
7a9eb4c4 PB |
221 | char *nptr; |
222 | CORE_ADDR addr; | |
223 | struct block *bl; | |
224 | int i, j; | |
225 | int type_is_object = 0; | |
226 | int is_array = 0; | |
227 | int nmethods; | |
228 | struct fn_field *fn_fields; | |
229 | struct fn_fieldlist *fn_fieldlists; | |
230 | char *unqualified_name; | |
231 | ||
232 | type = check_typedef (VALUE_TYPE (clas)); | |
233 | if (TYPE_CODE (type) == TYPE_CODE_PTR) | |
234 | { | |
235 | if (value_logical_not (clas)) | |
236 | return NULL; | |
237 | clas = value_ind (clas); | |
238 | } | |
239 | addr = VALUE_ADDRESS (clas) + VALUE_OFFSET (clas); | |
240 | ||
241 | get_java_class_symtab (); | |
242 | bl = BLOCKVECTOR_BLOCK (BLOCKVECTOR (class_symtab), GLOBAL_BLOCK); | |
243 | for (i = BLOCK_NSYMS (bl); --i >= 0; ) | |
244 | { | |
245 | struct symbol *sym = BLOCK_SYM (bl, i); | |
246 | if (SYMBOL_VALUE_ADDRESS (sym) == addr) | |
247 | return SYMBOL_TYPE (sym); | |
248 | } | |
249 | ||
250 | if (java_class_is_primitive (clas)) | |
251 | { | |
252 | value_ptr sig; | |
253 | temp = clas; | |
254 | sig = value_struct_elt (&temp, NULL, "msize", NULL, "structure"); | |
255 | return java_primitive_type (value_as_long (sig)); | |
256 | } | |
257 | ||
258 | /* Get Class name. */ | |
259 | /* if clasloader non-null, prepend loader address. FIXME */ | |
260 | temp = clas; | |
261 | utf8_name = value_struct_elt (&temp, NULL, "name", NULL, "structure"); | |
262 | name = get_java_utf8_name (&objfile->type_obstack, utf8_name); | |
263 | ||
264 | type = alloc_type (objfile); | |
265 | TYPE_CODE (type) = TYPE_CODE_STRUCT; | |
266 | INIT_CPLUS_SPECIFIC (type); | |
267 | ||
268 | if (name[0] == '[') | |
269 | { | |
270 | is_array = 1; | |
271 | temp = clas; | |
272 | /* Set array element type. */ | |
273 | temp = value_struct_elt (&temp, NULL, "methods", NULL, "structure"); | |
274 | VALUE_TYPE (temp) = lookup_pointer_type (VALUE_TYPE (clas)); | |
275 | TYPE_TARGET_TYPE (type) = type_from_class (temp); | |
276 | } | |
277 | unqualified_name = name; | |
278 | for (nptr = name; *nptr != 0; nptr++) | |
279 | { | |
280 | if (*nptr == '/') | |
281 | { | |
282 | *nptr = '.'; | |
283 | unqualified_name = nptr+1; | |
284 | } | |
285 | } | |
286 | ||
287 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
288 | TYPE_NAME (type) = name; | |
289 | ||
290 | add_class_symtab_symbol (add_class_symbol (type, addr)); | |
291 | ||
292 | temp = clas; | |
293 | temp = value_struct_elt (&temp, NULL, "superclass", NULL, "structure"); | |
294 | if (name != NULL && strcmp (name, "java.lang.Object") == 0) | |
295 | { | |
296 | tsuper = get_java_object_type (); | |
297 | if (tsuper && TYPE_CODE (tsuper) == TYPE_CODE_PTR) | |
298 | tsuper = TYPE_TARGET_TYPE (tsuper); | |
299 | type_is_object = 1; | |
300 | } | |
301 | else | |
302 | tsuper = type_from_class (temp); | |
303 | ||
304 | #if 1 | |
305 | ninterfaces = 0; | |
306 | #else | |
307 | temp = clas; | |
308 | ninterfaces = value_as_long (value_struct_elt (&temp, NULL, "interface_len", NULL, "structure")); | |
309 | #endif | |
310 | TYPE_N_BASECLASSES (type) = (tsuper == NULL ? 0 : 1) + ninterfaces; | |
311 | temp = clas; | |
312 | nfields = value_as_long (value_struct_elt (&temp, NULL, "nfields", NULL, "structure")); | |
313 | nfields += TYPE_N_BASECLASSES (type); | |
314 | TYPE_NFIELDS (type) = nfields; | |
315 | TYPE_FIELDS (type) = (struct field *) | |
316 | TYPE_ALLOC (type, sizeof (struct field) * nfields); | |
317 | ||
318 | memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields); | |
319 | ||
320 | TYPE_FIELD_PRIVATE_BITS (type) = | |
321 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
322 | B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields); | |
323 | ||
324 | TYPE_FIELD_PROTECTED_BITS (type) = | |
325 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
326 | B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields); | |
327 | ||
328 | TYPE_FIELD_IGNORE_BITS (type) = | |
329 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
330 | B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields); | |
331 | ||
332 | TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *) | |
333 | TYPE_ALLOC (type, B_BYTES (TYPE_N_BASECLASSES (type))); | |
334 | B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), TYPE_N_BASECLASSES (type)); | |
335 | ||
336 | if (tsuper != NULL) | |
337 | { | |
338 | TYPE_BASECLASS (type, 0) = tsuper; | |
339 | if (type_is_object) | |
340 | SET_TYPE_FIELD_PRIVATE (type, 0); | |
341 | } | |
342 | ||
343 | ||
344 | temp = clas; | |
345 | temp = value_struct_elt (&temp, NULL, "bfsize", NULL, "structure"); | |
346 | TYPE_LENGTH (type) = JAVA_OBJECT_SIZE + value_as_long (temp); | |
347 | ||
348 | fields = NULL; | |
349 | for (i = TYPE_N_BASECLASSES (type); i < nfields; i++) | |
350 | { | |
351 | int accflags; | |
352 | int boffset; | |
7a9eb4c4 PB |
353 | if (fields == NULL) |
354 | { | |
355 | temp = clas; | |
356 | fields = value_struct_elt (&temp, NULL, "fields", NULL, "structure"); | |
357 | field = value_ind (fields); | |
358 | } | |
359 | else | |
360 | { /* Re-use field value for next field. */ | |
361 | VALUE_ADDRESS (field) += TYPE_LENGTH (VALUE_TYPE (field)); | |
362 | VALUE_LAZY (field) = 1; | |
363 | } | |
364 | temp = field; | |
365 | temp = value_struct_elt (&temp, NULL, "name", NULL, "structure"); | |
366 | TYPE_FIELD_NAME (type, i) = | |
367 | get_java_utf8_name (&objfile->type_obstack, temp); | |
368 | temp = field; | |
369 | accflags = value_as_long (value_struct_elt (&temp, NULL, "accflags", | |
370 | NULL, "structure")); | |
371 | boffset = value_as_long (value_struct_elt (&temp, NULL, "boffset", | |
372 | NULL, "structure")); | |
373 | if (accflags & 0x0001) /* public access */ | |
374 | { | |
375 | /* ??? */ | |
376 | } | |
377 | if (accflags & 0x0002) /* private access */ | |
378 | { | |
379 | SET_TYPE_FIELD_PRIVATE (type, i); | |
380 | } | |
381 | if (accflags & 0x0004) /* protected access */ | |
382 | { | |
383 | SET_TYPE_FIELD_PROTECTED (type, i); | |
384 | } | |
385 | if (accflags & 0x0008) /* ACC_STATIC */ | |
386 | { | |
387 | TYPE_FIELD_BITPOS (type, i) = -1; | |
388 | /* Hack for TYPE_FIELD_STATIC_PHYSNAME to prevent a crash. FIXME. */ | |
389 | type->fields[i].bitsize = (long) "???"; | |
390 | } | |
391 | else | |
392 | TYPE_FIELD_BITPOS (type, i) = 8 * (JAVA_OBJECT_SIZE + boffset); | |
393 | if (accflags & 0x8000) /* FIELD_UNRESOLVED_FLAG */ | |
394 | { | |
395 | TYPE_FIELD_TYPE (type, i) = get_java_object_type (); /* FIXME */ | |
396 | } | |
397 | else | |
398 | { | |
399 | struct type *ftype; | |
400 | temp = field; | |
401 | temp = value_struct_elt (&temp, NULL, "type", NULL, "structure"); | |
402 | ftype = type_from_class (temp); | |
403 | if (TYPE_CODE (ftype) == TYPE_CODE_STRUCT) | |
404 | ftype = lookup_pointer_type (ftype); | |
405 | TYPE_FIELD_TYPE (type, i) = ftype; | |
406 | } | |
407 | } | |
408 | ||
409 | temp = clas; | |
410 | nmethods = value_as_long (value_struct_elt (&temp, NULL, "nmethods", | |
411 | NULL, "structure")); | |
412 | TYPE_NFN_FIELDS_TOTAL (type) = nmethods; | |
413 | j = nmethods * sizeof (struct fn_field); | |
414 | fn_fields = (struct fn_field*) | |
415 | obstack_alloc (&dynamics_objfile->symbol_obstack, j); | |
416 | memset (fn_fields, 0, j); | |
417 | fn_fieldlists = (struct fn_fieldlist*) | |
418 | alloca (nmethods * sizeof (struct fn_fieldlist)); | |
419 | ||
420 | methods = NULL; | |
421 | for (i = 0; i < nmethods; i++) | |
422 | { | |
423 | char *mname; | |
424 | int k; | |
425 | if (methods == NULL) | |
426 | { | |
427 | temp = clas; | |
428 | methods = value_struct_elt (&temp, NULL, "methods", NULL, "structure"); | |
429 | method = value_ind (methods); | |
430 | } | |
431 | else | |
432 | { /* Re-use method value for next method. */ | |
433 | VALUE_ADDRESS (method) += TYPE_LENGTH (VALUE_TYPE (method)); | |
434 | VALUE_LAZY (method) = 1; | |
435 | } | |
436 | ||
437 | /* Get method name. */ | |
438 | temp = method; | |
439 | temp = value_struct_elt (&temp, NULL, "name", NULL, "structure"); | |
440 | mname = get_java_utf8_name (&objfile->type_obstack, temp); | |
441 | if (strcmp (mname, "<init>") == 0) | |
442 | mname = unqualified_name; | |
443 | ||
444 | /* Check for an existing method with the same name. | |
445 | * This makes building the fn_fieldslists an O(nmethods**2) | |
446 | * operation. That could be using hashing, but I doubt it | |
447 | * is worth it. Note that we do maintain the order of methods | |
448 | * in the inferior's Method table (as long as that is grouped | |
449 | * by method name), which I think is desirable. --PB */ | |
450 | for (k = 0, j = TYPE_NFN_FIELDS (type); ; ) | |
451 | { | |
452 | if (--j < 0) | |
453 | { /* No match - new method name. */ | |
454 | j = TYPE_NFN_FIELDS(type)++; | |
455 | fn_fieldlists[j].name = mname; | |
456 | fn_fieldlists[j].length = 1; | |
457 | fn_fieldlists[j].fn_fields = &fn_fields[i]; | |
458 | k = i; | |
459 | break; | |
460 | } | |
461 | if (strcmp (mname, fn_fieldlists[j].name) == 0) | |
462 | { /* Found an existing method with the same name. */ | |
463 | int l; | |
464 | if (mname != unqualified_name) | |
465 | obstack_free (&objfile->type_obstack, mname); | |
466 | mname = fn_fieldlists[j].name; | |
467 | fn_fieldlists[j].length++; | |
468 | k = i - k; /* Index of new slot. */ | |
469 | /* Shift intervening fn_fields (between k and i) down. */ | |
470 | for (l = i; l > k; l--) fn_fields[l] = fn_fields[l-1]; | |
471 | for (l = TYPE_NFN_FIELDS (type); --l > j; ) | |
472 | fn_fieldlists[l].fn_fields++; | |
473 | break; | |
474 | } | |
475 | k += fn_fieldlists[j].length; | |
476 | } | |
477 | fn_fields[k].physname = ""; | |
478 | fn_fields[k].is_stub = 1; | |
479 | fn_fields[k].type = make_function_type (java_void_type, NULL); /* FIXME*/ | |
480 | TYPE_CODE (fn_fields[k].type) = TYPE_CODE_METHOD; | |
481 | } | |
482 | ||
483 | j = TYPE_NFN_FIELDS(type) * sizeof (struct fn_fieldlist); | |
484 | TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist*) | |
485 | obstack_alloc (&dynamics_objfile->symbol_obstack, j); | |
486 | memcpy (TYPE_FN_FIELDLISTS (type), fn_fieldlists, j); | |
487 | ||
488 | return type; | |
489 | } | |
490 | ||
491 | struct type* | |
492 | get_java_object_type () | |
493 | { | |
494 | return java_object_type; | |
495 | } | |
496 | ||
497 | int | |
498 | is_object_type (type) | |
499 | struct type *type; | |
500 | { | |
501 | CHECK_TYPEDEF (type); | |
502 | if (TYPE_CODE (type) == TYPE_CODE_PTR) | |
503 | { | |
504 | struct type *ttype = check_typedef (TYPE_TARGET_TYPE (type)); | |
505 | char *name; | |
506 | if (TYPE_CODE (ttype) != TYPE_CODE_STRUCT) | |
507 | return 0; | |
508 | while (TYPE_N_BASECLASSES (ttype) > 0) | |
509 | ttype = TYPE_BASECLASS (ttype, 0); | |
510 | name = TYPE_NAME (ttype); | |
511 | if (name != NULL && strcmp (name, "java.lang.Object") == 0) | |
512 | return 1; | |
513 | name = TYPE_NFIELDS (ttype) > 0 ? TYPE_FIELD_NAME (ttype, 0) : (char*)0; | |
514 | if (name != NULL && strcmp (name, "dtable") == 0) | |
515 | { | |
516 | if (java_object_type == NULL) | |
517 | java_object_type = type; | |
518 | return 1; | |
519 | } | |
520 | } | |
521 | return 0; | |
522 | } | |
523 | ||
524 | struct type* | |
525 | java_primitive_type (signature) | |
526 | int signature; | |
527 | { | |
528 | switch (signature) | |
529 | { | |
530 | case 'B': return java_byte_type; | |
531 | case 'S': return java_short_type; | |
532 | case 'I': return java_int_type; | |
533 | case 'J': return java_long_type; | |
534 | case 'Z': return java_boolean_type; | |
535 | case 'C': return java_char_type; | |
536 | case 'F': return java_float_type; | |
537 | case 'D': return java_double_type; | |
538 | case 'V': return java_void_type; | |
539 | } | |
540 | error ("unknown signature '%c' for primitive type", (char) signature); | |
541 | } | |
542 | ||
543 | /* Return the type of TYPE followed by DIMS pairs of [ ]. | |
544 | If DIMS == 0, TYPE is returned. */ | |
545 | ||
546 | struct type * | |
547 | java_array_type (type, dims) | |
548 | struct type *type; | |
549 | int dims; | |
550 | { | |
551 | if (dims == 0) | |
552 | return type; | |
553 | error ("array types not implemented"); | |
554 | } | |
555 | ||
556 | /* Create a Java string in the inferior from a (Utf8) literal. */ | |
557 | ||
558 | value_ptr | |
559 | java_value_string (ptr, len) | |
560 | char *ptr; | |
561 | int len; | |
562 | { | |
563 | error ("not implemented - java_value_string"); /* FIXME */ | |
564 | } | |
565 | ||
566 | static value_ptr | |
567 | evaluate_subexp_java (expect_type, exp, pos, noside) | |
568 | struct type *expect_type; | |
569 | register struct expression *exp; | |
570 | register int *pos; | |
571 | enum noside noside; | |
572 | { | |
573 | int pc = *pos; | |
574 | int i; | |
575 | enum exp_opcode op = exp->elts[*pos].opcode; | |
576 | value_ptr arg1; | |
577 | switch (op) | |
578 | { | |
579 | case UNOP_IND: | |
580 | if (noside == EVAL_SKIP) | |
581 | goto standard; | |
582 | (*pos)++; | |
583 | arg1 = evaluate_subexp_standard (expect_type, exp, pos, EVAL_NORMAL); | |
584 | if (is_object_type (VALUE_TYPE (arg1))) | |
585 | { | |
586 | struct type *type = type_from_class (java_class_from_object (arg1)); | |
587 | arg1 = value_cast (lookup_pointer_type (type), arg1); | |
588 | } | |
589 | if (noside == EVAL_SKIP) | |
590 | goto nosideret; | |
591 | return value_ind (arg1); | |
592 | case OP_STRING: | |
593 | (*pos)++; | |
594 | i = longest_to_int (exp->elts[pc + 1].longconst); | |
595 | (*pos) += 3 + BYTES_TO_EXP_ELEM (i + 1); | |
596 | if (noside == EVAL_SKIP) | |
597 | goto nosideret; | |
598 | return java_value_string (&exp->elts[pc + 2].string, i); | |
40b647e9 FF |
599 | default: |
600 | break; | |
7a9eb4c4 PB |
601 | } |
602 | standard: | |
603 | return evaluate_subexp_standard (expect_type, exp, pos, noside); | |
604 | nosideret: | |
605 | return value_from_longest (builtin_type_long, (LONGEST) 1); | |
606 | } | |
607 | ||
608 | static struct type * | |
609 | java_create_fundamental_type (objfile, typeid) | |
610 | struct objfile *objfile; | |
611 | int typeid; | |
612 | { | |
613 | switch (typeid) | |
614 | { | |
615 | case FT_VOID: return java_void_type; | |
616 | case FT_BOOLEAN: return java_boolean_type; | |
617 | case FT_CHAR: return java_char_type; | |
618 | case FT_FLOAT: return java_float_type; | |
619 | case FT_DBL_PREC_FLOAT: return java_double_type; | |
620 | case FT_BYTE: case FT_SIGNED_CHAR: return java_byte_type; | |
621 | case FT_SHORT: case FT_SIGNED_SHORT: return java_short_type; | |
622 | case FT_INTEGER: case FT_SIGNED_INTEGER: return java_int_type; | |
623 | case FT_LONG: case FT_SIGNED_LONG: return java_long_type; | |
624 | } | |
625 | return c_create_fundamental_type (objfile, typeid); | |
626 | } | |
627 | ||
628 | /* Table mapping opcodes into strings for printing operators | |
629 | and precedences of the operators. */ | |
630 | ||
631 | const struct op_print java_op_print_tab[] = | |
632 | { | |
633 | {",", BINOP_COMMA, PREC_COMMA, 0}, | |
634 | {"=", BINOP_ASSIGN, PREC_ASSIGN, 1}, | |
635 | {"||", BINOP_LOGICAL_OR, PREC_LOGICAL_OR, 0}, | |
636 | {"&&", BINOP_LOGICAL_AND, PREC_LOGICAL_AND, 0}, | |
637 | {"|", BINOP_BITWISE_IOR, PREC_BITWISE_IOR, 0}, | |
638 | {"^", BINOP_BITWISE_XOR, PREC_BITWISE_XOR, 0}, | |
639 | {"&", BINOP_BITWISE_AND, PREC_BITWISE_AND, 0}, | |
640 | {"==", BINOP_EQUAL, PREC_EQUAL, 0}, | |
641 | {"!=", BINOP_NOTEQUAL, PREC_EQUAL, 0}, | |
642 | {"<=", BINOP_LEQ, PREC_ORDER, 0}, | |
643 | {">=", BINOP_GEQ, PREC_ORDER, 0}, | |
644 | {">", BINOP_GTR, PREC_ORDER, 0}, | |
645 | {"<", BINOP_LESS, PREC_ORDER, 0}, | |
646 | {">>", BINOP_RSH, PREC_SHIFT, 0}, | |
647 | {"<<", BINOP_LSH, PREC_SHIFT, 0}, | |
648 | #if 0 | |
649 | {">>>", BINOP_???, PREC_SHIFT, 0}, | |
650 | #endif | |
651 | {"+", BINOP_ADD, PREC_ADD, 0}, | |
652 | {"-", BINOP_SUB, PREC_ADD, 0}, | |
653 | {"*", BINOP_MUL, PREC_MUL, 0}, | |
654 | {"/", BINOP_DIV, PREC_MUL, 0}, | |
655 | {"%", BINOP_REM, PREC_MUL, 0}, | |
656 | {"-", UNOP_NEG, PREC_PREFIX, 0}, | |
657 | {"!", UNOP_LOGICAL_NOT, PREC_PREFIX, 0}, | |
658 | {"~", UNOP_COMPLEMENT, PREC_PREFIX, 0}, | |
659 | {"*", UNOP_IND, PREC_PREFIX, 0}, | |
660 | #if 0 | |
661 | {"instanceof", ???, ???, 0}, | |
662 | #endif | |
663 | {"++", UNOP_PREINCREMENT, PREC_PREFIX, 0}, | |
664 | {"--", UNOP_PREDECREMENT, PREC_PREFIX, 0}, | |
665 | {NULL, 0, 0, 0} | |
666 | }; | |
667 | ||
668 | const struct language_defn java_language_defn = { | |
669 | "java", /* Language name */ | |
670 | language_java, | |
671 | c_builtin_types, | |
672 | range_check_off, | |
673 | type_check_off, | |
674 | java_parse, | |
675 | java_error, | |
676 | evaluate_subexp_java, | |
677 | c_printchar, /* Print a character constant */ | |
678 | c_printstr, /* Function to print string constant */ | |
679 | java_create_fundamental_type, /* Create fundamental type in this language */ | |
680 | c_print_type, /* Print a type using appropriate syntax */ | |
681 | java_val_print, /* Print a value using appropriate syntax */ | |
682 | java_value_print, /* Print a top-level value */ | |
683 | {"", "", "", ""}, /* Binary format info */ | |
684 | {"0%lo", "0", "o", ""}, /* Octal format info */ | |
685 | {"%ld", "", "d", ""}, /* Decimal format info */ | |
686 | {"0x%lx", "0x", "x", ""}, /* Hex format info */ | |
687 | java_op_print_tab, /* expression operators for printing */ | |
688 | 1, /* c-style arrays */ | |
689 | 0, /* String lower bound */ | |
690 | &builtin_type_char, /* Type of string elements */ | |
691 | LANG_MAGIC | |
692 | }; | |
693 | ||
694 | void | |
695 | _initialize_jave_language () | |
696 | { | |
697 | ||
698 | java_int_type = init_type (TYPE_CODE_INT, 4, 0, "int", NULL); | |
699 | java_short_type = init_type (TYPE_CODE_INT, 2, 0, "short", NULL); | |
700 | java_long_type = init_type (TYPE_CODE_INT, 8, 0, "long", NULL); | |
701 | java_byte_type = init_type (TYPE_CODE_INT, 1, 0, "byte", NULL); | |
702 | java_boolean_type= init_type (TYPE_CODE_BOOL, 1, 0, "boolean", NULL); | |
703 | java_char_type = init_type (TYPE_CODE_CHAR, 2, 0, "char", NULL); | |
704 | java_float_type = init_type (TYPE_CODE_FLT, 4, 0, "float", NULL); | |
705 | java_double_type = init_type (TYPE_CODE_FLT, 8, 0, "double", NULL); | |
706 | java_void_type = init_type (TYPE_CODE_VOID, 1, 0, "void", NULL); | |
707 | ||
708 | add_language (&java_language_defn); | |
709 | } | |
710 | ||
711 | /* Cleanup code that should be urn on every "run". | |
712 | We need some hook to have this actually be called ... FIXME */ | |
713 | ||
714 | void java_rerun_cleanup () | |
715 | { | |
716 | if (class_symtab != NULL) | |
717 | { | |
718 | free_symtab (class_symtab); /* ??? */ | |
719 | class_symtab = NULL; | |
720 | } | |
721 | if (dynamics_objfile != NULL) | |
722 | { | |
723 | free_objfile (dynamics_objfile); | |
724 | dynamics_objfile = NULL; | |
725 | } | |
726 | ||
727 | java_object_type = NULL; | |
728 | } |