1 /* Support for printing Java values for GDB, the GNU debugger.
2 Copyright 1997, 1998, 1999 Free Software Foundation, Inc.
4 This file is part of GDB.
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.
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.
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. */
23 #include "expression.h"
32 java_value_print (val
, stream
, format
, pretty
)
36 enum val_prettyprint pretty
;
43 type
= VALUE_TYPE (val
);
44 address
= VALUE_ADDRESS (val
) + VALUE_OFFSET (val
);
46 if (is_object_type (type
))
50 /* Get the run-time type, and cast the object into that */
52 obj_addr
= unpack_pointer (type
, VALUE_CONTENTS (val
));
56 type
= type_from_class (java_class_from_object (val
));
57 type
= lookup_pointer_type (type
);
59 val
= value_at (type
, address
, NULL
);
63 if (TYPE_CODE (type
) == TYPE_CODE_PTR
&& ! value_logical_not (val
))
64 type_print (TYPE_TARGET_TYPE (type
), "", stream
, -1);
66 name
= TYPE_TAG_NAME (type
);
67 if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
&& name
!= NULL
68 && (i
= strlen (name
), name
[i
-1] == ']'))
72 unsigned int things_printed
= 0;
74 struct type
*el_type
= java_primitive_type_from_name (name
, i
- 2);
77 read_memory (address
+ JAVA_OBJECT_SIZE
, buf4
, 4);
79 length
= (long) extract_signed_integer (buf4
, 4);
80 fprintf_filtered (stream
, "{length: %ld", length
);
84 CORE_ADDR element
, next_element
;
86 address
+= JAVA_OBJECT_SIZE
+ 4; /* Skip object header and length. */
88 while (i
< length
&& things_printed
< print_max
)
90 char buf
[TARGET_PTR_BIT
/ HOST_CHAR_BIT
];
92 fputs_filtered (", ", stream
);
93 wrap_here (n_spaces (2));
96 element
= next_element
;
99 read_memory (address
, buf
, sizeof(buf
));
100 address
+= TARGET_PTR_BIT
/ HOST_CHAR_BIT
;
101 element
= extract_address (buf
, sizeof(buf
));
104 for (reps
= 1; i
+ reps
< length
; reps
++)
106 read_memory (address
, buf
, sizeof(buf
));
107 address
+= TARGET_PTR_BIT
/ HOST_CHAR_BIT
;
108 next_element
= extract_address (buf
, sizeof(buf
));
109 if (next_element
!= element
)
114 fprintf_filtered (stream
, "%d: ", i
);
116 fprintf_filtered (stream
, "%d..%d: ", i
, i
+ reps
- 1);
119 fprintf_filtered (stream
, "null");
121 fprintf_filtered (stream
, "@%x", element
);
129 value_ptr v
= allocate_value (el_type
);
130 value_ptr next_v
= allocate_value (el_type
);
132 VALUE_ADDRESS (v
) = address
+ JAVA_OBJECT_SIZE
+ 4;
133 VALUE_ADDRESS (next_v
) = VALUE_ADDRESS (v
);
135 while (i
< length
&& things_printed
< print_max
)
137 fputs_filtered (", ", stream
);
138 wrap_here (n_spaces (2));
151 VALUE_OFFSET (v
) = 0;
154 VALUE_OFFSET (next_v
) = VALUE_OFFSET (v
);
156 for (reps
= 1; i
+ reps
< length
; reps
++)
158 VALUE_LAZY (next_v
) = 1;
159 VALUE_OFFSET (next_v
) += TYPE_LENGTH (el_type
);
160 if (memcmp (VALUE_CONTENTS (v
), VALUE_CONTENTS (next_v
),
161 TYPE_LENGTH (el_type
)) != 0)
166 fprintf_filtered (stream
, "%d: ", i
);
168 fprintf_filtered (stream
, "%d..%d: ", i
, i
+ reps
- 1);
170 val_print (VALUE_TYPE (v
), VALUE_CONTENTS (v
), 0, 0,
171 stream
, format
, 2, 1, pretty
);
179 fprintf_filtered (stream
, "...");
181 fprintf_filtered (stream
, "}");
186 /* If it's type String, print it */
188 if (TYPE_CODE (type
) == TYPE_CODE_PTR
189 && TYPE_TARGET_TYPE (type
)
190 && TYPE_NAME (TYPE_TARGET_TYPE (type
))
191 && strcmp (TYPE_NAME (TYPE_TARGET_TYPE (type
)), "java.lang.String") == 0
192 && (format
== 0 || format
== 's')
197 value_ptr boffset_val
;
198 unsigned long boffset
;
203 mark
= value_mark (); /* Remember start of new values */
205 data_val
= value_struct_elt (&val
, NULL
, "data", NULL
, NULL
);
206 data
= value_as_pointer (data_val
);
208 boffset_val
= value_struct_elt (&val
, NULL
, "boffset", NULL
, NULL
);
209 boffset
= value_as_pointer (boffset_val
);
211 count_val
= value_struct_elt (&val
, NULL
, "count", NULL
, NULL
);
212 count
= value_as_pointer (count_val
);
214 value_free_to_mark (mark
); /* Release unnecessary values */
216 val_print_string (data
+ boffset
, count
, 2, stream
);
221 return (val_print (type
, VALUE_CONTENTS (val
), 0, address
,
222 stream
, format
, 1, 0, pretty
));
225 /* TYPE, VALADDR, ADDRESS, STREAM, RECURSE, and PRETTY have the
226 same meanings as in cp_print_value and c_val_print.
228 DONT_PRINT is an array of baseclass types that we
229 should not print, or zero if called from top level. */
232 java_print_value_fields (type
, valaddr
, address
, stream
,
233 format
, recurse
, pretty
)
240 enum val_prettyprint pretty
;
242 int i
, len
, n_baseclasses
;
244 CHECK_TYPEDEF (type
);
246 fprintf_filtered (stream
, "{");
247 len
= TYPE_NFIELDS (type
);
248 n_baseclasses
= TYPE_N_BASECLASSES (type
);
250 if (n_baseclasses
> 0)
252 int i
, n_baseclasses
= TYPE_N_BASECLASSES (type
);
254 for (i
= 0; i
< n_baseclasses
; i
++)
257 struct type
*baseclass
= check_typedef (TYPE_BASECLASS (type
, i
));
258 char *basename
= TYPE_NAME (baseclass
);
261 if (BASETYPE_VIA_VIRTUAL (type
, i
))
264 if (basename
!= NULL
&& strcmp (basename
, "java.lang.Object") == 0)
271 fprintf_filtered (stream
, "\n");
272 print_spaces_filtered (2 * (recurse
+1), stream
);
274 fputs_filtered ("<", stream
);
275 /* Not sure what the best notation is in the case where there is no
277 fputs_filtered (basename
? basename
: "", stream
);
278 fputs_filtered ("> = ", stream
);
280 base_valaddr
= valaddr
;
282 java_print_value_fields (baseclass
, base_valaddr
, address
+ boffset
,
283 stream
, format
, recurse
+1, pretty
);
284 fputs_filtered (", ", stream
);
292 if (!len
&& n_baseclasses
== 1)
293 fprintf_filtered (stream
, "<No data fields>");
296 extern int inspect_it
;
299 for (i
= n_baseclasses
; i
< len
; i
++)
301 /* If requested, skip printing of static fields. */
302 if (TYPE_FIELD_STATIC (type
, i
))
304 char *name
= TYPE_FIELD_NAME (type
, i
);
305 if (!static_field_print
)
307 if (name
!= NULL
&& strcmp (name
, "class") == 0)
311 fprintf_filtered (stream
, ", ");
312 else if (n_baseclasses
> 0)
316 fprintf_filtered (stream
, "\n");
317 print_spaces_filtered (2 + 2 * recurse
, stream
);
318 fputs_filtered ("members of ", stream
);
319 fputs_filtered (type_name_no_tag (type
), stream
);
320 fputs_filtered (": ", stream
);
327 fprintf_filtered (stream
, "\n");
328 print_spaces_filtered (2 + 2 * recurse
, stream
);
332 wrap_here (n_spaces (2 + 2 * recurse
));
336 if (TYPE_CODE (TYPE_FIELD_TYPE (type
, i
)) == TYPE_CODE_PTR
)
337 fputs_filtered ("\"( ptr \"", stream
);
339 fputs_filtered ("\"( nodef \"", stream
);
340 if (TYPE_FIELD_STATIC (type
, i
))
341 fputs_filtered ("static ", stream
);
342 fprintf_symbol_filtered (stream
, TYPE_FIELD_NAME (type
, i
),
344 DMGL_PARAMS
| DMGL_ANSI
);
345 fputs_filtered ("\" \"", stream
);
346 fprintf_symbol_filtered (stream
, TYPE_FIELD_NAME (type
, i
),
348 DMGL_PARAMS
| DMGL_ANSI
);
349 fputs_filtered ("\") \"", stream
);
353 annotate_field_begin (TYPE_FIELD_TYPE (type
, i
));
355 if (TYPE_FIELD_STATIC (type
, i
))
356 fputs_filtered ("static ", stream
);
357 fprintf_symbol_filtered (stream
, TYPE_FIELD_NAME (type
, i
),
359 DMGL_PARAMS
| DMGL_ANSI
);
360 annotate_field_name_end ();
361 fputs_filtered (": ", stream
);
362 annotate_field_value ();
365 if (!TYPE_FIELD_STATIC (type
, i
) && TYPE_FIELD_PACKED (type
, i
))
369 /* Bitfields require special handling, especially due to byte
371 if (TYPE_FIELD_IGNORE (type
, i
))
373 fputs_filtered ("<optimized out or zero length>", stream
);
377 v
= value_from_longest (TYPE_FIELD_TYPE (type
, i
),
378 unpack_field_as_long (type
, valaddr
, i
));
380 val_print (TYPE_FIELD_TYPE(type
, i
), VALUE_CONTENTS (v
), 0,
381 0, stream
, format
, 0, recurse
+ 1, pretty
);
386 if (TYPE_FIELD_IGNORE (type
, i
))
388 fputs_filtered ("<optimized out or zero length>", stream
);
390 else if (TYPE_FIELD_STATIC (type
, i
))
392 value_ptr v
= value_static_field (type
, i
);
394 fputs_filtered ("<optimized out>", stream
);
397 struct type
*t
= check_typedef (VALUE_TYPE (v
));
398 if (TYPE_CODE (t
) == TYPE_CODE_STRUCT
)
400 val_print (VALUE_TYPE (v
),
401 VALUE_CONTENTS (v
), 0, VALUE_ADDRESS (v
),
402 stream
, format
, 0, recurse
+1, pretty
);
407 val_print (TYPE_FIELD_TYPE (type
, i
),
408 valaddr
+ TYPE_FIELD_BITPOS (type
, i
) / 8, 0,
409 address
+ TYPE_FIELD_BITPOS (type
, i
) / 8,
410 stream
, format
, 0, recurse
+ 1, pretty
);
413 annotate_field_end ();
418 fprintf_filtered (stream
, "\n");
419 print_spaces_filtered (2 * recurse
, stream
);
422 fprintf_filtered (stream
, "}");
425 /* Print data of type TYPE located at VALADDR (within GDB), which came from
426 the inferior at address ADDRESS, onto stdio stream STREAM according to
427 FORMAT (a letter or 0 for natural format). The data at VALADDR is in
430 If the data are a string pointer, returns the number of string characters
433 If DEREF_REF is nonzero, then dereference references, otherwise just print
436 The PRETTY parameter controls prettyprinting. */
439 java_val_print (type
, valaddr
, embedded_offset
, address
, stream
, format
,
440 deref_ref
, recurse
, pretty
)
448 enum val_prettyprint pretty
;
450 register unsigned int i
= 0; /* Number of characters printed */
451 struct type
*target_type
;
454 CHECK_TYPEDEF (type
);
455 switch (TYPE_CODE (type
))
458 if (format
&& format
!= 's')
460 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
464 if (vtblprint
&& cp_is_vtbl_ptr_type(type
))
466 /* Print the unmangled name if desired. */
467 /* Print vtable entry - we only get here if we ARE using
468 -fvtable_thunks. (Otherwise, look under TYPE_CODE_STRUCT.) */
469 print_address_demangle(extract_address (valaddr
, TYPE_LENGTH (type
)),
474 addr
= unpack_pointer (type
, valaddr
);
477 fputs_filtered ("null", stream
);
480 target_type
= check_typedef (TYPE_TARGET_TYPE (type
));
482 if (TYPE_CODE (target_type
) == TYPE_CODE_FUNC
)
484 /* Try to print what function it points to. */
485 print_address_demangle (addr
, stream
, demangle
);
486 /* Return value is irrelevant except for string pointers. */
490 if (addressprint
&& format
!= 's')
492 fputs_filtered ("@", stream
);
493 print_longest (stream
, 'x', 0, (ULONGEST
) addr
);
499 format
= format
? format
: output_format
;
501 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
503 LA_PRINT_CHAR ((int) unpack_long (type
, valaddr
), stream
);
507 /* Can't just call c_val_print because that print bytes as C chars. */
508 format
= format
? format
: output_format
;
510 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
512 val_print_type_code_int (type
, valaddr
, stream
);
515 case TYPE_CODE_STRUCT
:
516 java_print_value_fields (type
, valaddr
, address
, stream
, format
,
521 return c_val_print (type
, valaddr
, embedded_offset
, address
, stream
,
522 format
, deref_ref
, recurse
, pretty
);
This page took 0.048311 seconds and 5 git commands to generate.