1 /* Support for printing Java values for GDB, the GNU debugger.
2 Copyright 1997 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
;
38 struct type
*type
= VALUE_TYPE (val
);
39 CORE_ADDR address
= VALUE_ADDRESS (val
) + VALUE_OFFSET (val
);
40 if (is_object_type (type
))
42 CORE_ADDR obj_addr
= unpack_pointer (type
, VALUE_CONTENTS (val
));
46 = value_at (TYPE_TARGET_TYPE (type
), obj_addr
, NULL
);
47 type
= type_from_class (java_class_from_object (obj_val
));
48 type
= lookup_pointer_type (type
);
51 if (TYPE_CODE (type
) == TYPE_CODE_PTR
&& ! value_logical_not (val
))
53 type_print (TYPE_TARGET_TYPE (type
), "", stream
, -1);
56 if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
&& TYPE_TAG_NAME (type
) != NULL
57 && TYPE_TAG_NAME (type
)[0] == '[')
61 unsigned int things_printed
= 0;
64 read_memory (address
+ JAVA_OBJECT_SIZE
, buf4
, 4);
65 length
= (long) extract_signed_integer (buf4
, 4);
66 fprintf_filtered (stream
, "{length: %ld", length
);
67 if (TYPE_TAG_NAME (type
)[1] == 'L'
68 || TYPE_TAG_NAME (type
)[1] == '[')
70 CORE_ADDR element
, next_element
;
71 address
+= JAVA_OBJECT_SIZE
+ 4; /* Skip object header and length. */
72 while (i
< length
&& things_printed
< print_max
)
74 char buf
[TARGET_PTR_BIT
/ HOST_CHAR_BIT
];
75 fputs_filtered (", ", stream
);
76 wrap_here (n_spaces (2));
78 element
= next_element
;
81 read_memory (address
, buf
, sizeof(buf
));
82 address
+= TARGET_PTR_BIT
/ HOST_CHAR_BIT
;
83 element
= extract_address (buf
, sizeof(buf
));
85 for (reps
= 1; i
+ reps
< length
; reps
++)
87 read_memory (address
, buf
, sizeof(buf
));
88 address
+= TARGET_PTR_BIT
/ HOST_CHAR_BIT
;
89 next_element
= extract_address (buf
, sizeof(buf
));
90 if (next_element
!= element
)
94 fprintf_filtered (stream
, "%d: ", i
);
96 fprintf_filtered (stream
, "%d..%d: ", i
, i
+ reps
- 1);
98 fprintf_filtered (stream
, "null");
100 fprintf_filtered (stream
, "@%x", element
);
107 struct type
*el_type
= java_primitive_type (TYPE_TAG_NAME (type
)[1]);
108 value_ptr v
= allocate_value (el_type
);
109 value_ptr next_v
= allocate_value (el_type
);
110 VALUE_ADDRESS (v
) = address
+ JAVA_OBJECT_SIZE
+ 4;
111 VALUE_ADDRESS (next_v
) = VALUE_ADDRESS (v
);
113 while (i
< length
&& things_printed
< print_max
)
115 fputs_filtered (", ", stream
);
116 wrap_here (n_spaces (2));
119 value_ptr tmp
= next_v
; next_v
= v
; v
= tmp
;
124 VALUE_OFFSET (v
) = 0;
126 VALUE_OFFSET (next_v
) = VALUE_OFFSET (v
);
127 for (reps
= 1; i
+ reps
< length
; reps
++)
129 VALUE_LAZY (next_v
) = 1;
130 VALUE_OFFSET (next_v
) += TYPE_LENGTH (el_type
);
131 if (memcmp (VALUE_CONTENTS (v
), VALUE_CONTENTS (next_v
),
132 TYPE_LENGTH (el_type
)) != 0)
136 fprintf_filtered (stream
, "%d: ", i
);
138 fprintf_filtered (stream
, "%d..%d: ", i
, i
+ reps
- 1);
139 val_print (VALUE_TYPE (v
), VALUE_CONTENTS (v
), 0, 0,
140 stream
, format
, 2, 1, pretty
);
147 fprintf_filtered (stream
, "...");
148 fprintf_filtered (stream
, "}");
152 /* If it's type String, print it */
154 if (TYPE_CODE (type
) == TYPE_CODE_PTR
155 && TYPE_TARGET_TYPE (type
)
156 && TYPE_NAME (TYPE_TARGET_TYPE (type
))
157 && strcmp (TYPE_NAME (TYPE_TARGET_TYPE (type
)), "java.lang.String") == 0
158 && (format
== 0 || format
== 's')
163 value_ptr boffset_val
;
164 unsigned long boffset
;
169 mark
= value_mark (); /* Remember start of new values */
171 data_val
= value_struct_elt (&val
, NULL
, "data", NULL
, NULL
);
172 data
= value_as_pointer (data_val
);
174 boffset_val
= value_struct_elt (&val
, NULL
, "boffset", NULL
, NULL
);
175 boffset
= value_as_pointer (boffset_val
);
177 count_val
= value_struct_elt (&val
, NULL
, "count", NULL
, NULL
);
178 count
= value_as_pointer (count_val
);
180 value_free_to_mark (mark
); /* Release unnecessary values */
182 val_print_string (data
+ boffset
, count
, 2, stream
);
187 return (val_print (type
, VALUE_CONTENTS (val
), 0, address
,
188 stream
, format
, 1, 0, pretty
));
191 /* TYPE, VALADDR, ADDRESS, STREAM, RECURSE, and PRETTY have the
192 same meanings as in cp_print_value and c_val_print.
194 DONT_PRINT is an array of baseclass types that we
195 should not print, or zero if called from top level. */
198 java_print_value_fields (type
, valaddr
, address
, stream
,
199 format
, recurse
, pretty
)
206 enum val_prettyprint pretty
;
208 int i
, len
, n_baseclasses
;
210 CHECK_TYPEDEF (type
);
212 fprintf_filtered (stream
, "{");
213 len
= TYPE_NFIELDS (type
);
214 n_baseclasses
= TYPE_N_BASECLASSES (type
);
216 if (n_baseclasses
> 0)
218 int i
, n_baseclasses
= TYPE_N_BASECLASSES (type
);
220 for (i
= 0; i
< n_baseclasses
; i
++)
223 struct type
*baseclass
= check_typedef (TYPE_BASECLASS (type
, i
));
224 char *basename
= TYPE_NAME (baseclass
);
227 if (BASETYPE_VIA_VIRTUAL (type
, i
))
230 if (basename
!= NULL
&& strcmp (basename
, "java.lang.Object") == 0)
237 fprintf_filtered (stream
, "\n");
238 print_spaces_filtered (2 * (recurse
+1), stream
);
240 fputs_filtered ("<", stream
);
241 /* Not sure what the best notation is in the case where there is no
243 fputs_filtered (basename
? basename
: "", stream
);
244 fputs_filtered ("> = ", stream
);
246 base_valaddr
= valaddr
;
248 java_print_value_fields (baseclass
, base_valaddr
, address
+ boffset
,
249 stream
, format
, recurse
+1, pretty
);
250 fputs_filtered (", ", stream
);
258 if (!len
&& n_baseclasses
== 1)
259 fprintf_filtered (stream
, "<No data fields>");
262 extern int inspect_it
;
265 for (i
= n_baseclasses
; i
< len
; i
++)
267 /* If requested, skip printing of static fields. */
268 if (TYPE_FIELD_STATIC (type
, i
))
270 char *name
= TYPE_FIELD_NAME (type
, i
);
271 if (!static_field_print
)
273 if (name
!= NULL
&& strcmp (name
, "class") == 0)
277 fprintf_filtered (stream
, ", ");
278 else if (n_baseclasses
> 0)
282 fprintf_filtered (stream
, "\n");
283 print_spaces_filtered (2 + 2 * recurse
, stream
);
284 fputs_filtered ("members of ", stream
);
285 fputs_filtered (type_name_no_tag (type
), stream
);
286 fputs_filtered (": ", stream
);
293 fprintf_filtered (stream
, "\n");
294 print_spaces_filtered (2 + 2 * recurse
, stream
);
298 wrap_here (n_spaces (2 + 2 * recurse
));
302 if (TYPE_CODE (TYPE_FIELD_TYPE (type
, i
)) == TYPE_CODE_PTR
)
303 fputs_filtered ("\"( ptr \"", stream
);
305 fputs_filtered ("\"( nodef \"", stream
);
306 if (TYPE_FIELD_STATIC (type
, i
))
307 fputs_filtered ("static ", stream
);
308 fprintf_symbol_filtered (stream
, TYPE_FIELD_NAME (type
, i
),
310 DMGL_PARAMS
| DMGL_ANSI
);
311 fputs_filtered ("\" \"", stream
);
312 fprintf_symbol_filtered (stream
, TYPE_FIELD_NAME (type
, i
),
314 DMGL_PARAMS
| DMGL_ANSI
);
315 fputs_filtered ("\") \"", stream
);
319 annotate_field_begin (TYPE_FIELD_TYPE (type
, i
));
321 if (TYPE_FIELD_STATIC (type
, i
))
322 fputs_filtered ("static ", stream
);
323 fprintf_symbol_filtered (stream
, TYPE_FIELD_NAME (type
, i
),
325 DMGL_PARAMS
| DMGL_ANSI
);
326 annotate_field_name_end ();
327 fputs_filtered (": ", stream
);
328 annotate_field_value ();
331 if (!TYPE_FIELD_STATIC (type
, i
) && TYPE_FIELD_PACKED (type
, i
))
335 /* Bitfields require special handling, especially due to byte
337 if (TYPE_FIELD_IGNORE (type
, i
))
339 fputs_filtered ("<optimized out or zero length>", stream
);
343 v
= value_from_longest (TYPE_FIELD_TYPE (type
, i
),
344 unpack_field_as_long (type
, valaddr
, i
));
346 val_print (TYPE_FIELD_TYPE(type
, i
), VALUE_CONTENTS (v
),
348 stream
, format
, 0, recurse
+ 1, pretty
);
353 if (TYPE_FIELD_IGNORE (type
, i
))
355 fputs_filtered ("<optimized out or zero length>", stream
);
357 else if (TYPE_FIELD_STATIC (type
, i
))
359 value_ptr v
= value_static_field (type
, i
);
361 fputs_filtered ("<optimized out>", stream
);
364 struct type
*t
= check_typedef (VALUE_TYPE (v
));
365 if (TYPE_CODE (t
) == TYPE_CODE_STRUCT
)
367 val_print (VALUE_TYPE (v
),
368 VALUE_CONTENTS (v
), 0, VALUE_ADDRESS (v
),
369 stream
, format
, 0, recurse
+1, pretty
);
374 val_print (TYPE_FIELD_TYPE (type
, i
),
375 valaddr
+ TYPE_FIELD_BITPOS (type
, i
) / 8,
377 address
+ TYPE_FIELD_BITPOS (type
, i
) / 8,
378 stream
, format
, 0, recurse
+ 1, pretty
);
381 annotate_field_end ();
386 fprintf_filtered (stream
, "\n");
387 print_spaces_filtered (2 * recurse
, stream
);
390 fprintf_filtered (stream
, "}");
393 /* Print data of type TYPE located at VALADDR (within GDB), which came from
394 the inferior at address ADDRESS, onto stdio stream STREAM according to
395 FORMAT (a letter or 0 for natural format). The data at VALADDR is in
398 If the data are a string pointer, returns the number of string characters
401 If DEREF_REF is nonzero, then dereference references, otherwise just print
404 The PRETTY parameter controls prettyprinting. */
407 java_val_print (type
, valaddr
, embedded_offset
, address
, stream
, format
,
408 deref_ref
, recurse
, pretty
)
417 enum val_prettyprint pretty
;
419 register unsigned int i
= 0; /* Number of characters printed */
420 struct type
*target_type
;
423 CHECK_TYPEDEF (type
);
424 switch (TYPE_CODE (type
))
427 if (format
&& format
!= 's')
429 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
433 if (vtblprint
&& cp_is_vtbl_ptr_type(type
))
435 /* Print the unmangled name if desired. */
436 /* Print vtable entry - we only get here if we ARE using
437 -fvtable_thunks. (Otherwise, look under TYPE_CODE_STRUCT.) */
438 print_address_demangle(extract_address (valaddr
, TYPE_LENGTH (type
)),
443 addr
= unpack_pointer (type
, valaddr
);
446 fputs_filtered ("null", stream
);
449 target_type
= check_typedef (TYPE_TARGET_TYPE (type
));
451 if (TYPE_CODE (target_type
) == TYPE_CODE_FUNC
)
453 /* Try to print what function it points to. */
454 print_address_demangle (addr
, stream
, demangle
);
455 /* Return value is irrelevant except for string pointers. */
459 if (addressprint
&& format
!= 's')
461 fputs_filtered ("@", stream
);
462 print_longest (stream
, 'x', 0, (ULONGEST
) addr
);
467 format
= format
? format
: output_format
;
470 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
474 LA_PRINT_CHAR ((int) unpack_long (type
, valaddr
), stream
);
477 case TYPE_CODE_STRUCT
:
478 java_print_value_fields (type
, valaddr
, address
, stream
, format
,
482 return c_val_print (type
, valaddr
, 0, address
, stream
, format
,
483 deref_ref
, recurse
, pretty
);
This page took 0.039259 seconds and 4 git commands to generate.