1 /* Support for printing C values for GDB, the GNU debugger.
2 Copyright 1986, 1988, 1989, 1991, 1992, 1993, 1994, 1995
3 Free Software Foundation, Inc.
5 This file is part of GDB.
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
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
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.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
24 #include "expression.h"
32 /* Print data of type TYPE located at VALADDR (within GDB), which came from
33 the inferior at address ADDRESS, onto stdio stream STREAM according to
34 FORMAT (a letter or 0 for natural format). The data at VALADDR is in
37 If the data are a string pointer, returns the number of string characters
40 If DEREF_REF is nonzero, then dereference references, otherwise just print
43 The PRETTY parameter controls prettyprinting. */
46 c_val_print (type
, valaddr
, address
, stream
, format
, deref_ref
, recurse
,
55 enum val_prettyprint pretty
;
57 register unsigned int i
= 0; /* Number of characters printed */
65 switch (TYPE_CODE (type
))
68 if (TYPE_LENGTH (type
) > 0 && TYPE_LENGTH (TYPE_TARGET_TYPE (type
)) > 0)
70 elttype
= check_typedef (TYPE_TARGET_TYPE (type
));
71 eltlen
= TYPE_LENGTH (elttype
);
72 len
= TYPE_LENGTH (type
) / eltlen
;
73 if (prettyprint_arrays
)
75 print_spaces_filtered (2 + 2 * recurse
, stream
);
77 /* For an array of chars, print with string syntax. */
79 ((TYPE_CODE (elttype
) == TYPE_CODE_INT
)
80 || ((current_language
->la_language
== language_m2
)
81 && (TYPE_CODE (elttype
) == TYPE_CODE_CHAR
)))
82 && (format
== 0 || format
== 's'))
84 /* If requested, look for the first null char and only print
86 if (stop_print_at_null
)
90 /* Look for a NULL char. */
93 && temp_len
< len
&& temp_len
< print_max
;
98 LA_PRINT_STRING (stream
, valaddr
, len
, 0);
103 fprintf_filtered (stream
, "{");
104 /* If this is a virtual function table, print the 0th
105 entry specially, and the rest of the members normally. */
106 if (cp_is_vtbl_ptr_type (elttype
))
109 fprintf_filtered (stream
, "%d vtable entries", len
- 1);
115 val_print_array_elements (type
, valaddr
, address
, stream
,
116 format
, deref_ref
, recurse
, pretty
, i
);
117 fprintf_filtered (stream
, "}");
121 /* Array of unspecified length: treat like pointer to first elt. */
123 goto print_unpacked_pointer
;
126 if (format
&& format
!= 's')
128 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
131 if (vtblprint
&& cp_is_vtbl_ptr_type(type
))
133 /* Print the unmangled name if desired. */
134 /* Print vtable entry - we only get here if we ARE using
135 -fvtable_thunks. (Otherwise, look under TYPE_CODE_STRUCT.) */
136 print_address_demangle(extract_address (valaddr
, TYPE_LENGTH (type
)),
140 elttype
= check_typedef (TYPE_TARGET_TYPE (type
));
141 if (TYPE_CODE (elttype
) == TYPE_CODE_METHOD
)
143 cp_print_class_method (valaddr
, type
, stream
);
145 else if (TYPE_CODE (elttype
) == TYPE_CODE_MEMBER
)
147 cp_print_class_member (valaddr
,
148 TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (type
)),
153 addr
= unpack_pointer (type
, valaddr
);
154 print_unpacked_pointer
:
156 if (TYPE_CODE (elttype
) == TYPE_CODE_FUNC
)
158 /* Try to print what function it points to. */
159 print_address_demangle (addr
, stream
, demangle
);
160 /* Return value is irrelevant except for string pointers. */
164 if (addressprint
&& format
!= 's')
166 print_address_numeric (addr
, 1, stream
);
169 /* For a pointer to char or unsigned char, also print the string
170 pointed to, unless pointer is null. */
171 if (TYPE_LENGTH (elttype
) == 1
172 && TYPE_CODE (elttype
) == TYPE_CODE_INT
173 && (format
== 0 || format
== 's')
176 i
= val_print_string (addr
, 0, stream
);
178 else if (cp_is_vtbl_member(type
))
180 /* print vtbl's nicely */
181 CORE_ADDR vt_address
= unpack_pointer (type
, valaddr
);
183 struct minimal_symbol
*msymbol
=
184 lookup_minimal_symbol_by_pc (vt_address
);
185 if ((msymbol
!= NULL
) &&
186 (vt_address
== SYMBOL_VALUE_ADDRESS (msymbol
)))
188 fputs_filtered (" <", stream
);
189 fputs_filtered (SYMBOL_SOURCE_NAME (msymbol
), stream
);
190 fputs_filtered (">", stream
);
192 if (vt_address
&& vtblprint
)
195 struct symbol
*wsym
= (struct symbol
*)NULL
;
198 struct block
*block
= (struct block
*)NULL
;
202 wsym
= lookup_symbol (SYMBOL_NAME(msymbol
), block
,
203 VAR_NAMESPACE
, &is_this_fld
, &s
);
207 wtype
= SYMBOL_TYPE(wsym
);
211 wtype
= TYPE_TARGET_TYPE(type
);
213 vt_val
= value_at (wtype
, vt_address
);
214 val_print (VALUE_TYPE (vt_val
), VALUE_CONTENTS (vt_val
),
215 VALUE_ADDRESS (vt_val
), stream
, format
,
216 deref_ref
, recurse
+ 1, pretty
);
219 fprintf_filtered (stream
, "\n");
220 print_spaces_filtered (2 + 2 * recurse
, stream
);
225 /* Return number of characters printed, including the terminating
226 '\0' if we reached the end. val_print_string takes care including
227 the terminating '\0' if necessary. */
232 case TYPE_CODE_MEMBER
:
233 error ("not implemented: member type in c_val_print");
237 elttype
= check_typedef (TYPE_TARGET_TYPE (type
));
238 if (TYPE_CODE (elttype
) == TYPE_CODE_MEMBER
)
240 cp_print_class_member (valaddr
,
241 TYPE_DOMAIN_TYPE (elttype
),
247 fprintf_filtered (stream
, "@");
248 print_address_numeric
249 (extract_address (valaddr
,
250 TARGET_PTR_BIT
/ HOST_CHAR_BIT
), 1, stream
);
252 fputs_filtered (": ", stream
);
254 /* De-reference the reference. */
257 if (TYPE_CODE (elttype
) != TYPE_CODE_UNDEF
)
259 value_ptr deref_val
=
261 (TYPE_TARGET_TYPE (type
),
262 unpack_pointer (lookup_pointer_type (builtin_type_void
),
264 val_print (VALUE_TYPE (deref_val
),
265 VALUE_CONTENTS (deref_val
),
266 VALUE_ADDRESS (deref_val
), stream
, format
,
267 deref_ref
, recurse
+ 1, pretty
);
270 fputs_filtered ("???", stream
);
274 case TYPE_CODE_UNION
:
275 if (recurse
&& !unionprint
)
277 fprintf_filtered (stream
, "{...}");
281 case TYPE_CODE_STRUCT
:
282 if (vtblprint
&& cp_is_vtbl_ptr_type(type
))
284 /* Print the unmangled name if desired. */
285 /* Print vtable entry - we only get here if NOT using
286 -fvtable_thunks. (Otherwise, look under TYPE_CODE_PTR.) */
287 print_address_demangle(*((int *) (valaddr
+ /* FIXME bytesex */
288 TYPE_FIELD_BITPOS (type
, VTBL_FNADDR_OFFSET
) / 8)),
292 cp_print_value_fields (type
, valaddr
, address
, stream
, format
,
293 recurse
, pretty
, NULL
, 0);
299 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
302 len
= TYPE_NFIELDS (type
);
303 val
= unpack_long (type
, valaddr
);
304 for (i
= 0; i
< len
; i
++)
307 if (val
== TYPE_FIELD_BITPOS (type
, i
))
314 fputs_filtered (TYPE_FIELD_NAME (type
, i
), stream
);
318 print_longest (stream
, 'd', 0, val
);
325 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
328 /* FIXME, we should consider, at least for ANSI C language, eliminating
329 the distinction made between FUNCs and POINTERs to FUNCs. */
330 fprintf_filtered (stream
, "{");
331 type_print (type
, "", stream
, -1);
332 fprintf_filtered (stream
, "} ");
333 /* Try to print what function it points to, and its address. */
334 print_address_demangle (address
, stream
, demangle
);
338 format
= format
? format
: output_format
;
340 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
343 val
= unpack_long (type
, valaddr
);
345 fputs_filtered ("false", stream
);
347 fputs_filtered ("true", stream
);
349 print_longest (stream
, 'd', 0, val
);
353 case TYPE_CODE_RANGE
:
354 /* FIXME: create_range_type does not set the unsigned bit in a
355 range type (I think it probably should copy it from the target
356 type), so we won't print values which are too large to
357 fit in a signed integer correctly. */
358 /* FIXME: Doesn't handle ranges of enums correctly. (Can't just
359 print with the target type, though, because the size of our type
360 and the target type might differ). */
364 format
= format
? format
: output_format
;
367 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
371 val_print_type_code_int (type
, valaddr
, stream
);
372 /* C and C++ has no single byte int type, char is used instead.
373 Since we don't know whether the value is really intended to
374 be used as an integer or a character, print the character
375 equivalent as well. */
376 if (TYPE_LENGTH (type
) == 1)
378 fputs_filtered (" ", stream
);
379 LA_PRINT_CHAR ((unsigned char) unpack_long (type
, valaddr
),
386 format
= format
? format
: output_format
;
389 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
393 fprintf_filtered (stream
, TYPE_UNSIGNED (type
) ? "%u" : "%d",
394 unpack_long (type
, valaddr
));
395 fputs_filtered (" ", stream
);
396 LA_PRINT_CHAR ((unsigned char) unpack_long (type
, valaddr
), stream
);
403 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
407 print_floating (valaddr
, type
, stream
);
412 fprintf_filtered (stream
, "void");
415 case TYPE_CODE_ERROR
:
416 fprintf_filtered (stream
, "<error type>");
419 case TYPE_CODE_UNDEF
:
420 /* This happens (without TYPE_FLAG_STUB set) on systems which don't use
421 dbx xrefs (NO_DBX_XREFS in gcc) if a file has a "struct foo *bar"
422 and no complete type for struct foo in that file. */
423 fprintf_filtered (stream
, "<incomplete type>");
427 error ("Invalid C/C++ type code %d in symbol table.", TYPE_CODE (type
));
434 c_value_print (val
, stream
, format
, pretty
)
438 enum val_prettyprint pretty
;
440 struct type
*type
= VALUE_TYPE (val
);
442 /* If it is a pointer, indicate what it points to.
444 Print type also if it is a reference.
446 C++: if it is a member pointer, we will take care
447 of that when we print it. */
448 if (TYPE_CODE (type
) == TYPE_CODE_PTR
||
449 TYPE_CODE (type
) == TYPE_CODE_REF
)
451 /* Hack: remove (char *) for char strings. Their
452 type is indicated by the quoted string anyway. */
453 if (TYPE_CODE (type
) == TYPE_CODE_PTR
&&
454 TYPE_NAME (type
) == NULL
&&
455 TYPE_NAME (TYPE_TARGET_TYPE (type
)) != NULL
&&
456 STREQ (TYPE_NAME (TYPE_TARGET_TYPE (type
)), "char"))
462 fprintf_filtered (stream
, "(");
463 type_print (type
, "", stream
, -1);
464 fprintf_filtered (stream
, ") ");
467 return (val_print (type
, VALUE_CONTENTS (val
),
468 VALUE_ADDRESS (val
), stream
, format
, 1, 0, pretty
));
This page took 0.040763 seconds and 4 git commands to generate.