1e93f7393Sniklas /* Support for printing C values for GDB, the GNU debugger.
2*b725ae77Skettenis
3*b725ae77Skettenis Copyright 1986, 1988, 1989, 1991, 1992, 1993, 1994, 1995, 1996,
4*b725ae77Skettenis 1997, 1998, 1999, 2000, 2001, 2003 Free Software Foundation, Inc.
5e93f7393Sniklas
6e93f7393Sniklas This file is part of GDB.
7e93f7393Sniklas
8e93f7393Sniklas This program is free software; you can redistribute it and/or modify
9e93f7393Sniklas it under the terms of the GNU General Public License as published by
10e93f7393Sniklas the Free Software Foundation; either version 2 of the License, or
11e93f7393Sniklas (at your option) any later version.
12e93f7393Sniklas
13e93f7393Sniklas This program is distributed in the hope that it will be useful,
14e93f7393Sniklas but WITHOUT ANY WARRANTY; without even the implied warranty of
15e93f7393Sniklas MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16e93f7393Sniklas GNU General Public License for more details.
17e93f7393Sniklas
18e93f7393Sniklas You should have received a copy of the GNU General Public License
19e93f7393Sniklas along with this program; if not, write to the Free Software
20*b725ae77Skettenis Foundation, Inc., 59 Temple Place - Suite 330,
21*b725ae77Skettenis Boston, MA 02111-1307, USA. */
22e93f7393Sniklas
23e93f7393Sniklas #include "defs.h"
24*b725ae77Skettenis #include "gdb_string.h"
25e93f7393Sniklas #include "symtab.h"
26e93f7393Sniklas #include "gdbtypes.h"
27e93f7393Sniklas #include "expression.h"
28e93f7393Sniklas #include "value.h"
29e93f7393Sniklas #include "valprint.h"
30e93f7393Sniklas #include "language.h"
31e93f7393Sniklas #include "c-lang.h"
32*b725ae77Skettenis #include "cp-abi.h"
33*b725ae77Skettenis #include "target.h"
34e93f7393Sniklas
35*b725ae77Skettenis
36*b725ae77Skettenis /* Print function pointer with inferior address ADDRESS onto stdio
37*b725ae77Skettenis stream STREAM. */
38*b725ae77Skettenis
39*b725ae77Skettenis static void
print_function_pointer_address(CORE_ADDR address,struct ui_file * stream)40*b725ae77Skettenis print_function_pointer_address (CORE_ADDR address, struct ui_file *stream)
41*b725ae77Skettenis {
42*b725ae77Skettenis CORE_ADDR func_addr = gdbarch_convert_from_func_ptr_addr (current_gdbarch,
43*b725ae77Skettenis address,
44*b725ae77Skettenis ¤t_target);
45*b725ae77Skettenis
46*b725ae77Skettenis /* If the function pointer is represented by a description, print the
47*b725ae77Skettenis address of the description. */
48*b725ae77Skettenis if (addressprint && func_addr != address)
49*b725ae77Skettenis {
50*b725ae77Skettenis fputs_filtered ("@", stream);
51*b725ae77Skettenis print_address_numeric (address, 1, stream);
52*b725ae77Skettenis fputs_filtered (": ", stream);
53*b725ae77Skettenis }
54*b725ae77Skettenis print_address_demangle (func_addr, stream, demangle);
55*b725ae77Skettenis }
56*b725ae77Skettenis
57*b725ae77Skettenis
58e93f7393Sniklas /* Print data of type TYPE located at VALADDR (within GDB), which came from
59e93f7393Sniklas the inferior at address ADDRESS, onto stdio stream STREAM according to
60e93f7393Sniklas FORMAT (a letter or 0 for natural format). The data at VALADDR is in
61e93f7393Sniklas target byte order.
62e93f7393Sniklas
63e93f7393Sniklas If the data are a string pointer, returns the number of string characters
64e93f7393Sniklas printed.
65e93f7393Sniklas
66e93f7393Sniklas If DEREF_REF is nonzero, then dereference references, otherwise just print
67e93f7393Sniklas them like pointers.
68e93f7393Sniklas
69e93f7393Sniklas The PRETTY parameter controls prettyprinting. */
70e93f7393Sniklas
71e93f7393Sniklas int
c_val_print(struct type * type,char * valaddr,int embedded_offset,CORE_ADDR address,struct ui_file * stream,int format,int deref_ref,int recurse,enum val_prettyprint pretty)72*b725ae77Skettenis c_val_print (struct type *type, char *valaddr, int embedded_offset,
73*b725ae77Skettenis CORE_ADDR address, struct ui_file *stream, int format,
74*b725ae77Skettenis int deref_ref, int recurse, enum val_prettyprint pretty)
75e93f7393Sniklas {
76*b725ae77Skettenis unsigned int i = 0; /* Number of characters printed */
77e93f7393Sniklas unsigned len;
78e93f7393Sniklas struct type *elttype;
79e93f7393Sniklas unsigned eltlen;
80e93f7393Sniklas LONGEST val;
81e93f7393Sniklas CORE_ADDR addr;
82e93f7393Sniklas
83e93f7393Sniklas CHECK_TYPEDEF (type);
84e93f7393Sniklas switch (TYPE_CODE (type))
85e93f7393Sniklas {
86e93f7393Sniklas case TYPE_CODE_ARRAY:
87*b725ae77Skettenis elttype = check_typedef (TYPE_TARGET_TYPE (type));
88e93f7393Sniklas if (TYPE_LENGTH (type) > 0 && TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0)
89e93f7393Sniklas {
90e93f7393Sniklas eltlen = TYPE_LENGTH (elttype);
91e93f7393Sniklas len = TYPE_LENGTH (type) / eltlen;
92e93f7393Sniklas if (prettyprint_arrays)
93e93f7393Sniklas {
94e93f7393Sniklas print_spaces_filtered (2 + 2 * recurse, stream);
95e93f7393Sniklas }
96e93f7393Sniklas /* For an array of chars, print with string syntax. */
97e93f7393Sniklas if (eltlen == 1 &&
98e93f7393Sniklas ((TYPE_CODE (elttype) == TYPE_CODE_INT)
99e93f7393Sniklas || ((current_language->la_language == language_m2)
100e93f7393Sniklas && (TYPE_CODE (elttype) == TYPE_CODE_CHAR)))
101e93f7393Sniklas && (format == 0 || format == 's'))
102e93f7393Sniklas {
103e93f7393Sniklas /* If requested, look for the first null char and only print
104e93f7393Sniklas elements up to it. */
105e93f7393Sniklas if (stop_print_at_null)
106e93f7393Sniklas {
107*b725ae77Skettenis unsigned int temp_len;
108e93f7393Sniklas
109e93f7393Sniklas /* Look for a NULL char. */
110e93f7393Sniklas for (temp_len = 0;
111*b725ae77Skettenis (valaddr + embedded_offset)[temp_len]
112e93f7393Sniklas && temp_len < len && temp_len < print_max;
113e93f7393Sniklas temp_len++);
114e93f7393Sniklas len = temp_len;
115e93f7393Sniklas }
116e93f7393Sniklas
117*b725ae77Skettenis LA_PRINT_STRING (stream, valaddr + embedded_offset, len, eltlen, 0);
118e93f7393Sniklas i = len;
119e93f7393Sniklas }
120e93f7393Sniklas else
121e93f7393Sniklas {
122e93f7393Sniklas fprintf_filtered (stream, "{");
123e93f7393Sniklas /* If this is a virtual function table, print the 0th
124e93f7393Sniklas entry specially, and the rest of the members normally. */
125e93f7393Sniklas if (cp_is_vtbl_ptr_type (elttype))
126e93f7393Sniklas {
127e93f7393Sniklas i = 1;
128e93f7393Sniklas fprintf_filtered (stream, "%d vtable entries", len - 1);
129e93f7393Sniklas }
130e93f7393Sniklas else
131e93f7393Sniklas {
132e93f7393Sniklas i = 0;
133e93f7393Sniklas }
134*b725ae77Skettenis val_print_array_elements (type, valaddr + embedded_offset, address, stream,
135e93f7393Sniklas format, deref_ref, recurse, pretty, i);
136e93f7393Sniklas fprintf_filtered (stream, "}");
137e93f7393Sniklas }
138e93f7393Sniklas break;
139e93f7393Sniklas }
140e93f7393Sniklas /* Array of unspecified length: treat like pointer to first elt. */
141e93f7393Sniklas addr = address;
142e93f7393Sniklas goto print_unpacked_pointer;
143e93f7393Sniklas
144e93f7393Sniklas case TYPE_CODE_PTR:
145e93f7393Sniklas if (format && format != 's')
146e93f7393Sniklas {
147*b725ae77Skettenis print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream);
148e93f7393Sniklas break;
149e93f7393Sniklas }
150e93f7393Sniklas if (vtblprint && cp_is_vtbl_ptr_type (type))
151e93f7393Sniklas {
152e93f7393Sniklas /* Print the unmangled name if desired. */
153e93f7393Sniklas /* Print vtable entry - we only get here if we ARE using
154e93f7393Sniklas -fvtable_thunks. (Otherwise, look under TYPE_CODE_STRUCT.) */
155*b725ae77Skettenis CORE_ADDR addr
156*b725ae77Skettenis = extract_typed_address (valaddr + embedded_offset, type);
157*b725ae77Skettenis print_function_pointer_address (addr, stream);
158e93f7393Sniklas break;
159e93f7393Sniklas }
160e93f7393Sniklas elttype = check_typedef (TYPE_TARGET_TYPE (type));
161e93f7393Sniklas if (TYPE_CODE (elttype) == TYPE_CODE_METHOD)
162e93f7393Sniklas {
163*b725ae77Skettenis cp_print_class_method (valaddr + embedded_offset, type, stream);
164e93f7393Sniklas }
165e93f7393Sniklas else if (TYPE_CODE (elttype) == TYPE_CODE_MEMBER)
166e93f7393Sniklas {
167*b725ae77Skettenis cp_print_class_member (valaddr + embedded_offset,
168e93f7393Sniklas TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (type)),
169e93f7393Sniklas stream, "&");
170e93f7393Sniklas }
171e93f7393Sniklas else
172e93f7393Sniklas {
173*b725ae77Skettenis addr = unpack_pointer (type, valaddr + embedded_offset);
174e93f7393Sniklas print_unpacked_pointer:
175e93f7393Sniklas
176e93f7393Sniklas if (TYPE_CODE (elttype) == TYPE_CODE_FUNC)
177e93f7393Sniklas {
178e93f7393Sniklas /* Try to print what function it points to. */
179*b725ae77Skettenis print_function_pointer_address (addr, stream);
180e93f7393Sniklas /* Return value is irrelevant except for string pointers. */
181e93f7393Sniklas return (0);
182e93f7393Sniklas }
183e93f7393Sniklas
184e93f7393Sniklas if (addressprint && format != 's')
185e93f7393Sniklas {
186e93f7393Sniklas print_address_numeric (addr, 1, stream);
187e93f7393Sniklas }
188e93f7393Sniklas
189e93f7393Sniklas /* For a pointer to char or unsigned char, also print the string
190e93f7393Sniklas pointed to, unless pointer is null. */
191*b725ae77Skettenis /* FIXME: need to handle wchar_t here... */
192*b725ae77Skettenis
193e93f7393Sniklas if (TYPE_LENGTH (elttype) == 1
194e93f7393Sniklas && TYPE_CODE (elttype) == TYPE_CODE_INT
195e93f7393Sniklas && (format == 0 || format == 's')
196e93f7393Sniklas && addr != 0)
197e93f7393Sniklas {
198*b725ae77Skettenis i = val_print_string (addr, -1, TYPE_LENGTH (elttype), stream);
199e93f7393Sniklas }
200e93f7393Sniklas else if (cp_is_vtbl_member (type))
201e93f7393Sniklas {
202e93f7393Sniklas /* print vtbl's nicely */
203*b725ae77Skettenis CORE_ADDR vt_address = unpack_pointer (type, valaddr + embedded_offset);
204e93f7393Sniklas
205e93f7393Sniklas struct minimal_symbol *msymbol =
206e93f7393Sniklas lookup_minimal_symbol_by_pc (vt_address);
207e93f7393Sniklas if ((msymbol != NULL) &&
208e93f7393Sniklas (vt_address == SYMBOL_VALUE_ADDRESS (msymbol)))
209e93f7393Sniklas {
210e93f7393Sniklas fputs_filtered (" <", stream);
211*b725ae77Skettenis fputs_filtered (SYMBOL_PRINT_NAME (msymbol), stream);
212e93f7393Sniklas fputs_filtered (">", stream);
213e93f7393Sniklas }
214e93f7393Sniklas if (vt_address && vtblprint)
215e93f7393Sniklas {
216*b725ae77Skettenis struct value *vt_val;
217e93f7393Sniklas struct symbol *wsym = (struct symbol *) NULL;
218e93f7393Sniklas struct type *wtype;
219e93f7393Sniklas struct block *block = (struct block *) NULL;
220e93f7393Sniklas int is_this_fld;
221e93f7393Sniklas
222e93f7393Sniklas if (msymbol != NULL)
223*b725ae77Skettenis wsym = lookup_symbol (DEPRECATED_SYMBOL_NAME (msymbol), block,
224*b725ae77Skettenis VAR_DOMAIN, &is_this_fld, NULL);
225e93f7393Sniklas
226e93f7393Sniklas if (wsym)
227e93f7393Sniklas {
228e93f7393Sniklas wtype = SYMBOL_TYPE (wsym);
229e93f7393Sniklas }
230e93f7393Sniklas else
231e93f7393Sniklas {
232e93f7393Sniklas wtype = TYPE_TARGET_TYPE (type);
233e93f7393Sniklas }
234*b725ae77Skettenis vt_val = value_at (wtype, vt_address, NULL);
235*b725ae77Skettenis val_print (VALUE_TYPE (vt_val), VALUE_CONTENTS (vt_val), 0,
236e93f7393Sniklas VALUE_ADDRESS (vt_val), stream, format,
237e93f7393Sniklas deref_ref, recurse + 1, pretty);
238e93f7393Sniklas if (pretty)
239e93f7393Sniklas {
240e93f7393Sniklas fprintf_filtered (stream, "\n");
241e93f7393Sniklas print_spaces_filtered (2 + 2 * recurse, stream);
242e93f7393Sniklas }
243e93f7393Sniklas }
244e93f7393Sniklas }
245e93f7393Sniklas
246e93f7393Sniklas /* Return number of characters printed, including the terminating
247e93f7393Sniklas '\0' if we reached the end. val_print_string takes care including
248e93f7393Sniklas the terminating '\0' if necessary. */
249e93f7393Sniklas return i;
250e93f7393Sniklas }
251e93f7393Sniklas break;
252e93f7393Sniklas
253e93f7393Sniklas case TYPE_CODE_MEMBER:
254e93f7393Sniklas error ("not implemented: member type in c_val_print");
255e93f7393Sniklas break;
256e93f7393Sniklas
257e93f7393Sniklas case TYPE_CODE_REF:
258e93f7393Sniklas elttype = check_typedef (TYPE_TARGET_TYPE (type));
259e93f7393Sniklas if (TYPE_CODE (elttype) == TYPE_CODE_MEMBER)
260e93f7393Sniklas {
261*b725ae77Skettenis cp_print_class_member (valaddr + embedded_offset,
262e93f7393Sniklas TYPE_DOMAIN_TYPE (elttype),
263e93f7393Sniklas stream, "");
264e93f7393Sniklas break;
265e93f7393Sniklas }
266e93f7393Sniklas if (addressprint)
267e93f7393Sniklas {
268*b725ae77Skettenis CORE_ADDR addr
269*b725ae77Skettenis = extract_typed_address (valaddr + embedded_offset, type);
270e93f7393Sniklas fprintf_filtered (stream, "@");
271*b725ae77Skettenis print_address_numeric (addr, 1, stream);
272e93f7393Sniklas if (deref_ref)
273e93f7393Sniklas fputs_filtered (": ", stream);
274e93f7393Sniklas }
275e93f7393Sniklas /* De-reference the reference. */
276e93f7393Sniklas if (deref_ref)
277e93f7393Sniklas {
278e93f7393Sniklas if (TYPE_CODE (elttype) != TYPE_CODE_UNDEF)
279e93f7393Sniklas {
280*b725ae77Skettenis struct value *deref_val =
281e93f7393Sniklas value_at
282e93f7393Sniklas (TYPE_TARGET_TYPE (type),
283e93f7393Sniklas unpack_pointer (lookup_pointer_type (builtin_type_void),
284*b725ae77Skettenis valaddr + embedded_offset),
285*b725ae77Skettenis NULL);
286e93f7393Sniklas val_print (VALUE_TYPE (deref_val),
287e93f7393Sniklas VALUE_CONTENTS (deref_val),
288*b725ae77Skettenis 0,
289*b725ae77Skettenis VALUE_ADDRESS (deref_val),
290*b725ae77Skettenis stream,
291*b725ae77Skettenis format,
292*b725ae77Skettenis deref_ref,
293*b725ae77Skettenis recurse,
294*b725ae77Skettenis pretty);
295e93f7393Sniklas }
296e93f7393Sniklas else
297e93f7393Sniklas fputs_filtered ("???", stream);
298e93f7393Sniklas }
299e93f7393Sniklas break;
300e93f7393Sniklas
301e93f7393Sniklas case TYPE_CODE_UNION:
302e93f7393Sniklas if (recurse && !unionprint)
303e93f7393Sniklas {
304e93f7393Sniklas fprintf_filtered (stream, "{...}");
305e93f7393Sniklas break;
306e93f7393Sniklas }
307e93f7393Sniklas /* Fall through. */
308e93f7393Sniklas case TYPE_CODE_STRUCT:
309*b725ae77Skettenis /*FIXME: Abstract this away */
310e93f7393Sniklas if (vtblprint && cp_is_vtbl_ptr_type (type))
311e93f7393Sniklas {
312e93f7393Sniklas /* Print the unmangled name if desired. */
313e93f7393Sniklas /* Print vtable entry - we only get here if NOT using
314e93f7393Sniklas -fvtable_thunks. (Otherwise, look under TYPE_CODE_PTR.) */
315*b725ae77Skettenis int offset = (embedded_offset +
316*b725ae77Skettenis TYPE_FIELD_BITPOS (type, VTBL_FNADDR_OFFSET) / 8);
317*b725ae77Skettenis struct type *field_type = TYPE_FIELD_TYPE (type, VTBL_FNADDR_OFFSET);
318*b725ae77Skettenis CORE_ADDR addr
319*b725ae77Skettenis = extract_typed_address (valaddr + offset, field_type);
320*b725ae77Skettenis
321*b725ae77Skettenis print_function_pointer_address (addr, stream);
322e93f7393Sniklas }
323e93f7393Sniklas else
324*b725ae77Skettenis cp_print_value_fields (type, type, valaddr, embedded_offset, address, stream, format,
325e93f7393Sniklas recurse, pretty, NULL, 0);
326e93f7393Sniklas break;
327e93f7393Sniklas
328e93f7393Sniklas case TYPE_CODE_ENUM:
329e93f7393Sniklas if (format)
330e93f7393Sniklas {
331*b725ae77Skettenis print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream);
332e93f7393Sniklas break;
333e93f7393Sniklas }
334e93f7393Sniklas len = TYPE_NFIELDS (type);
335*b725ae77Skettenis val = unpack_long (type, valaddr + embedded_offset);
336e93f7393Sniklas for (i = 0; i < len; i++)
337e93f7393Sniklas {
338e93f7393Sniklas QUIT;
339e93f7393Sniklas if (val == TYPE_FIELD_BITPOS (type, i))
340e93f7393Sniklas {
341e93f7393Sniklas break;
342e93f7393Sniklas }
343e93f7393Sniklas }
344e93f7393Sniklas if (i < len)
345e93f7393Sniklas {
346e93f7393Sniklas fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
347e93f7393Sniklas }
348e93f7393Sniklas else
349e93f7393Sniklas {
350e93f7393Sniklas print_longest (stream, 'd', 0, val);
351e93f7393Sniklas }
352e93f7393Sniklas break;
353e93f7393Sniklas
354e93f7393Sniklas case TYPE_CODE_FUNC:
355e93f7393Sniklas if (format)
356e93f7393Sniklas {
357*b725ae77Skettenis print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream);
358e93f7393Sniklas break;
359e93f7393Sniklas }
360e93f7393Sniklas /* FIXME, we should consider, at least for ANSI C language, eliminating
361e93f7393Sniklas the distinction made between FUNCs and POINTERs to FUNCs. */
362e93f7393Sniklas fprintf_filtered (stream, "{");
363e93f7393Sniklas type_print (type, "", stream, -1);
364e93f7393Sniklas fprintf_filtered (stream, "} ");
365e93f7393Sniklas /* Try to print what function it points to, and its address. */
366e93f7393Sniklas print_address_demangle (address, stream, demangle);
367e93f7393Sniklas break;
368e93f7393Sniklas
369e93f7393Sniklas case TYPE_CODE_BOOL:
370e93f7393Sniklas format = format ? format : output_format;
371e93f7393Sniklas if (format)
372*b725ae77Skettenis print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream);
373e93f7393Sniklas else
374e93f7393Sniklas {
375*b725ae77Skettenis val = unpack_long (type, valaddr + embedded_offset);
376e93f7393Sniklas if (val == 0)
377e93f7393Sniklas fputs_filtered ("false", stream);
378e93f7393Sniklas else if (val == 1)
379e93f7393Sniklas fputs_filtered ("true", stream);
380e93f7393Sniklas else
381e93f7393Sniklas print_longest (stream, 'd', 0, val);
382e93f7393Sniklas }
383e93f7393Sniklas break;
384e93f7393Sniklas
385e93f7393Sniklas case TYPE_CODE_RANGE:
386e93f7393Sniklas /* FIXME: create_range_type does not set the unsigned bit in a
387e93f7393Sniklas range type (I think it probably should copy it from the target
388e93f7393Sniklas type), so we won't print values which are too large to
389e93f7393Sniklas fit in a signed integer correctly. */
390e93f7393Sniklas /* FIXME: Doesn't handle ranges of enums correctly. (Can't just
391e93f7393Sniklas print with the target type, though, because the size of our type
392e93f7393Sniklas and the target type might differ). */
393e93f7393Sniklas /* FALLTHROUGH */
394e93f7393Sniklas
395e93f7393Sniklas case TYPE_CODE_INT:
396e93f7393Sniklas format = format ? format : output_format;
397e93f7393Sniklas if (format)
398e93f7393Sniklas {
399*b725ae77Skettenis print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream);
400e93f7393Sniklas }
401e93f7393Sniklas else
402e93f7393Sniklas {
403*b725ae77Skettenis val_print_type_code_int (type, valaddr + embedded_offset, stream);
404e93f7393Sniklas /* C and C++ has no single byte int type, char is used instead.
405e93f7393Sniklas Since we don't know whether the value is really intended to
406e93f7393Sniklas be used as an integer or a character, print the character
407e93f7393Sniklas equivalent as well. */
408e93f7393Sniklas if (TYPE_LENGTH (type) == 1)
409e93f7393Sniklas {
410e93f7393Sniklas fputs_filtered (" ", stream);
411*b725ae77Skettenis LA_PRINT_CHAR ((unsigned char) unpack_long (type, valaddr + embedded_offset),
412e93f7393Sniklas stream);
413e93f7393Sniklas }
414e93f7393Sniklas }
415e93f7393Sniklas break;
416e93f7393Sniklas
417e93f7393Sniklas case TYPE_CODE_CHAR:
418e93f7393Sniklas format = format ? format : output_format;
419e93f7393Sniklas if (format)
420e93f7393Sniklas {
421*b725ae77Skettenis print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream);
422e93f7393Sniklas }
423e93f7393Sniklas else
424e93f7393Sniklas {
425*b725ae77Skettenis val = unpack_long (type, valaddr + embedded_offset);
426*b725ae77Skettenis if (TYPE_UNSIGNED (type))
427*b725ae77Skettenis fprintf_filtered (stream, "%u", (unsigned int) val);
428*b725ae77Skettenis else
429*b725ae77Skettenis fprintf_filtered (stream, "%d", (int) val);
430e93f7393Sniklas fputs_filtered (" ", stream);
431*b725ae77Skettenis LA_PRINT_CHAR ((unsigned char) val, stream);
432e93f7393Sniklas }
433e93f7393Sniklas break;
434e93f7393Sniklas
435e93f7393Sniklas case TYPE_CODE_FLT:
436e93f7393Sniklas if (format)
437e93f7393Sniklas {
438*b725ae77Skettenis print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream);
439e93f7393Sniklas }
440e93f7393Sniklas else
441e93f7393Sniklas {
442*b725ae77Skettenis print_floating (valaddr + embedded_offset, type, stream);
443e93f7393Sniklas }
444e93f7393Sniklas break;
445e93f7393Sniklas
446*b725ae77Skettenis case TYPE_CODE_METHOD:
447*b725ae77Skettenis {
448*b725ae77Skettenis struct value *v = value_at (type, address, NULL);
449*b725ae77Skettenis cp_print_class_method (VALUE_CONTENTS (value_addr (v)),
450*b725ae77Skettenis lookup_pointer_type (type), stream);
451*b725ae77Skettenis break;
452*b725ae77Skettenis }
453*b725ae77Skettenis
454e93f7393Sniklas case TYPE_CODE_VOID:
455e93f7393Sniklas fprintf_filtered (stream, "void");
456e93f7393Sniklas break;
457e93f7393Sniklas
458e93f7393Sniklas case TYPE_CODE_ERROR:
459e93f7393Sniklas fprintf_filtered (stream, "<error type>");
460e93f7393Sniklas break;
461e93f7393Sniklas
462e93f7393Sniklas case TYPE_CODE_UNDEF:
463e93f7393Sniklas /* This happens (without TYPE_FLAG_STUB set) on systems which don't use
464e93f7393Sniklas dbx xrefs (NO_DBX_XREFS in gcc) if a file has a "struct foo *bar"
465e93f7393Sniklas and no complete type for struct foo in that file. */
466e93f7393Sniklas fprintf_filtered (stream, "<incomplete type>");
467e93f7393Sniklas break;
468e93f7393Sniklas
469*b725ae77Skettenis case TYPE_CODE_COMPLEX:
470*b725ae77Skettenis if (format)
471*b725ae77Skettenis print_scalar_formatted (valaddr + embedded_offset,
472*b725ae77Skettenis TYPE_TARGET_TYPE (type),
473*b725ae77Skettenis format, 0, stream);
474*b725ae77Skettenis else
475*b725ae77Skettenis print_floating (valaddr + embedded_offset, TYPE_TARGET_TYPE (type),
476*b725ae77Skettenis stream);
477*b725ae77Skettenis fprintf_filtered (stream, " + ");
478*b725ae77Skettenis if (format)
479*b725ae77Skettenis print_scalar_formatted (valaddr + embedded_offset
480*b725ae77Skettenis + TYPE_LENGTH (TYPE_TARGET_TYPE (type)),
481*b725ae77Skettenis TYPE_TARGET_TYPE (type),
482*b725ae77Skettenis format, 0, stream);
483*b725ae77Skettenis else
484*b725ae77Skettenis print_floating (valaddr + embedded_offset
485*b725ae77Skettenis + TYPE_LENGTH (TYPE_TARGET_TYPE (type)),
486*b725ae77Skettenis TYPE_TARGET_TYPE (type),
487*b725ae77Skettenis stream);
488*b725ae77Skettenis fprintf_filtered (stream, " * I");
489*b725ae77Skettenis break;
490*b725ae77Skettenis
491e93f7393Sniklas default:
492e93f7393Sniklas error ("Invalid C/C++ type code %d in symbol table.", TYPE_CODE (type));
493e93f7393Sniklas }
494e93f7393Sniklas gdb_flush (stream);
495e93f7393Sniklas return (0);
496e93f7393Sniklas }
497e93f7393Sniklas
498e93f7393Sniklas int
c_value_print(struct value * val,struct ui_file * stream,int format,enum val_prettyprint pretty)499*b725ae77Skettenis c_value_print (struct value *val, struct ui_file *stream, int format,
500*b725ae77Skettenis enum val_prettyprint pretty)
501e93f7393Sniklas {
502e93f7393Sniklas struct type *type = VALUE_TYPE (val);
503*b725ae77Skettenis struct type *real_type;
504*b725ae77Skettenis int full, top, using_enc;
505e93f7393Sniklas
506e93f7393Sniklas /* If it is a pointer, indicate what it points to.
507e93f7393Sniklas
508e93f7393Sniklas Print type also if it is a reference.
509e93f7393Sniklas
510e93f7393Sniklas C++: if it is a member pointer, we will take care
511e93f7393Sniklas of that when we print it. */
512e93f7393Sniklas if (TYPE_CODE (type) == TYPE_CODE_PTR ||
513e93f7393Sniklas TYPE_CODE (type) == TYPE_CODE_REF)
514e93f7393Sniklas {
515e93f7393Sniklas /* Hack: remove (char *) for char strings. Their
516e93f7393Sniklas type is indicated by the quoted string anyway. */
517e93f7393Sniklas if (TYPE_CODE (type) == TYPE_CODE_PTR &&
518e93f7393Sniklas TYPE_NAME (type) == NULL &&
519e93f7393Sniklas TYPE_NAME (TYPE_TARGET_TYPE (type)) != NULL &&
520*b725ae77Skettenis strcmp (TYPE_NAME (TYPE_TARGET_TYPE (type)), "char") == 0)
521e93f7393Sniklas {
522e93f7393Sniklas /* Print nothing */
523e93f7393Sniklas }
524*b725ae77Skettenis else if (objectprint && (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_CLASS))
525*b725ae77Skettenis {
526*b725ae77Skettenis
527*b725ae77Skettenis if (TYPE_CODE(type) == TYPE_CODE_REF)
528*b725ae77Skettenis {
529*b725ae77Skettenis /* Copy value, change to pointer, so we don't get an
530*b725ae77Skettenis * error about a non-pointer type in value_rtti_target_type
531*b725ae77Skettenis */
532*b725ae77Skettenis struct value *temparg;
533*b725ae77Skettenis temparg=value_copy(val);
534*b725ae77Skettenis VALUE_TYPE (temparg) = lookup_pointer_type(TYPE_TARGET_TYPE(type));
535*b725ae77Skettenis val=temparg;
536*b725ae77Skettenis }
537*b725ae77Skettenis /* Pointer to class, check real type of object */
538*b725ae77Skettenis fprintf_filtered (stream, "(");
539*b725ae77Skettenis real_type = value_rtti_target_type (val, &full, &top, &using_enc);
540*b725ae77Skettenis if (real_type)
541*b725ae77Skettenis {
542*b725ae77Skettenis /* RTTI entry found */
543*b725ae77Skettenis if (TYPE_CODE (type) == TYPE_CODE_PTR)
544*b725ae77Skettenis {
545*b725ae77Skettenis /* create a pointer type pointing to the real type */
546*b725ae77Skettenis type = lookup_pointer_type (real_type);
547*b725ae77Skettenis }
548e93f7393Sniklas else
549e93f7393Sniklas {
550*b725ae77Skettenis /* create a reference type referencing the real type */
551*b725ae77Skettenis type = lookup_reference_type (real_type);
552*b725ae77Skettenis }
553*b725ae77Skettenis /* JYG: Need to adjust pointer value. */
554*b725ae77Skettenis val->aligner.contents[0] -= top;
555*b725ae77Skettenis
556*b725ae77Skettenis /* Note: When we look up RTTI entries, we don't get any
557*b725ae77Skettenis information on const or volatile attributes */
558*b725ae77Skettenis }
559*b725ae77Skettenis type_print (type, "", stream, -1);
560*b725ae77Skettenis fprintf_filtered (stream, ") ");
561*b725ae77Skettenis }
562*b725ae77Skettenis else
563*b725ae77Skettenis {
564*b725ae77Skettenis /* normal case */
565e93f7393Sniklas fprintf_filtered (stream, "(");
566e93f7393Sniklas type_print (type, "", stream, -1);
567e93f7393Sniklas fprintf_filtered (stream, ") ");
568e93f7393Sniklas }
569e93f7393Sniklas }
570*b725ae77Skettenis if (objectprint && (TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_CLASS))
571*b725ae77Skettenis {
572*b725ae77Skettenis /* Attempt to determine real type of object */
573*b725ae77Skettenis real_type = value_rtti_type (val, &full, &top, &using_enc);
574*b725ae77Skettenis if (real_type)
575*b725ae77Skettenis {
576*b725ae77Skettenis /* We have RTTI information, so use it */
577*b725ae77Skettenis val = value_full_object (val, real_type, full, top, using_enc);
578*b725ae77Skettenis fprintf_filtered (stream, "(%s%s) ",
579*b725ae77Skettenis TYPE_NAME (real_type),
580*b725ae77Skettenis full ? "" : " [incomplete object]");
581*b725ae77Skettenis /* Print out object: enclosing type is same as real_type if full */
582*b725ae77Skettenis return val_print (VALUE_ENCLOSING_TYPE (val), VALUE_CONTENTS_ALL (val), 0,
583*b725ae77Skettenis VALUE_ADDRESS (val), stream, format, 1, 0, pretty);
584*b725ae77Skettenis /* Note: When we look up RTTI entries, we don't get any information on
585*b725ae77Skettenis const or volatile attributes */
586*b725ae77Skettenis }
587*b725ae77Skettenis else if (type != VALUE_ENCLOSING_TYPE (val))
588*b725ae77Skettenis {
589*b725ae77Skettenis /* No RTTI information, so let's do our best */
590*b725ae77Skettenis fprintf_filtered (stream, "(%s ?) ",
591*b725ae77Skettenis TYPE_NAME (VALUE_ENCLOSING_TYPE (val)));
592*b725ae77Skettenis return val_print (VALUE_ENCLOSING_TYPE (val), VALUE_CONTENTS_ALL (val), 0,
593*b725ae77Skettenis VALUE_ADDRESS (val), stream, format, 1, 0, pretty);
594*b725ae77Skettenis }
595*b725ae77Skettenis /* Otherwise, we end up at the return outside this "if" */
596*b725ae77Skettenis }
597*b725ae77Skettenis
598*b725ae77Skettenis return val_print (type, VALUE_CONTENTS_ALL (val),
599*b725ae77Skettenis VALUE_EMBEDDED_OFFSET (val),
600e93f7393Sniklas VALUE_ADDRESS (val) + VALUE_OFFSET (val),
601e93f7393Sniklas stream, format, 1, 0, pretty);
602e93f7393Sniklas }
603