15796c8dcSSimon Schubert /* Support for printing C values for GDB, the GNU debugger.
25796c8dcSSimon Schubert
3*ef5ccd6cSJohn Marino Copyright (C) 1986-2013 Free Software Foundation, Inc.
45796c8dcSSimon Schubert
55796c8dcSSimon Schubert This file is part of GDB.
65796c8dcSSimon Schubert
75796c8dcSSimon Schubert This program is free software; you can redistribute it and/or modify
85796c8dcSSimon Schubert it under the terms of the GNU General Public License as published by
95796c8dcSSimon Schubert the Free Software Foundation; either version 3 of the License, or
105796c8dcSSimon Schubert (at your option) any later version.
115796c8dcSSimon Schubert
125796c8dcSSimon Schubert This program is distributed in the hope that it will be useful,
135796c8dcSSimon Schubert but WITHOUT ANY WARRANTY; without even the implied warranty of
145796c8dcSSimon Schubert MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
155796c8dcSSimon Schubert GNU General Public License for more details.
165796c8dcSSimon Schubert
175796c8dcSSimon Schubert You should have received a copy of the GNU General Public License
185796c8dcSSimon Schubert along with this program. If not, see <http://www.gnu.org/licenses/>. */
195796c8dcSSimon Schubert
205796c8dcSSimon Schubert #include "defs.h"
215796c8dcSSimon Schubert #include "gdb_string.h"
225796c8dcSSimon Schubert #include "symtab.h"
235796c8dcSSimon Schubert #include "gdbtypes.h"
245796c8dcSSimon Schubert #include "expression.h"
255796c8dcSSimon Schubert #include "value.h"
265796c8dcSSimon Schubert #include "valprint.h"
275796c8dcSSimon Schubert #include "language.h"
285796c8dcSSimon Schubert #include "c-lang.h"
295796c8dcSSimon Schubert #include "cp-abi.h"
305796c8dcSSimon Schubert #include "target.h"
315796c8dcSSimon Schubert
325796c8dcSSimon Schubert
33cf7f2e2dSJohn Marino /* A helper for c_textual_element_type. This checks the name of the
345796c8dcSSimon Schubert typedef. This is bogus but it isn't apparent that the compiler
355796c8dcSSimon Schubert provides us the help we may need. */
365796c8dcSSimon Schubert
375796c8dcSSimon Schubert static int
textual_name(const char * name)385796c8dcSSimon Schubert textual_name (const char *name)
395796c8dcSSimon Schubert {
405796c8dcSSimon Schubert return (!strcmp (name, "wchar_t")
415796c8dcSSimon Schubert || !strcmp (name, "char16_t")
425796c8dcSSimon Schubert || !strcmp (name, "char32_t"));
435796c8dcSSimon Schubert }
445796c8dcSSimon Schubert
455796c8dcSSimon Schubert /* Apply a heuristic to decide whether an array of TYPE or a pointer
465796c8dcSSimon Schubert to TYPE should be printed as a textual string. Return non-zero if
475796c8dcSSimon Schubert it should, or zero if it should be treated as an array of integers
48c50c785cSJohn Marino or pointer to integers. FORMAT is the current format letter, or 0
49c50c785cSJohn Marino if none.
505796c8dcSSimon Schubert
515796c8dcSSimon Schubert We guess that "char" is a character. Explicitly signed and
525796c8dcSSimon Schubert unsigned character types are also characters. Integer data from
535796c8dcSSimon Schubert vector types is not. The user can override this by using the /s
545796c8dcSSimon Schubert format letter. */
555796c8dcSSimon Schubert
56cf7f2e2dSJohn Marino int
c_textual_element_type(struct type * type,char format)57cf7f2e2dSJohn Marino c_textual_element_type (struct type *type, char format)
585796c8dcSSimon Schubert {
595796c8dcSSimon Schubert struct type *true_type, *iter_type;
605796c8dcSSimon Schubert
615796c8dcSSimon Schubert if (format != 0 && format != 's')
625796c8dcSSimon Schubert return 0;
635796c8dcSSimon Schubert
645796c8dcSSimon Schubert /* We also rely on this for its side effect of setting up all the
655796c8dcSSimon Schubert typedef pointers. */
665796c8dcSSimon Schubert true_type = check_typedef (type);
675796c8dcSSimon Schubert
685796c8dcSSimon Schubert /* TYPE_CODE_CHAR is always textual. */
695796c8dcSSimon Schubert if (TYPE_CODE (true_type) == TYPE_CODE_CHAR)
705796c8dcSSimon Schubert return 1;
715796c8dcSSimon Schubert
725796c8dcSSimon Schubert /* Any other character-like types must be integral. */
735796c8dcSSimon Schubert if (TYPE_CODE (true_type) != TYPE_CODE_INT)
745796c8dcSSimon Schubert return 0;
755796c8dcSSimon Schubert
765796c8dcSSimon Schubert /* We peel typedefs one by one, looking for a match. */
775796c8dcSSimon Schubert iter_type = type;
785796c8dcSSimon Schubert while (iter_type)
795796c8dcSSimon Schubert {
805796c8dcSSimon Schubert /* Check the name of the type. */
815796c8dcSSimon Schubert if (TYPE_NAME (iter_type) && textual_name (TYPE_NAME (iter_type)))
825796c8dcSSimon Schubert return 1;
835796c8dcSSimon Schubert
845796c8dcSSimon Schubert if (TYPE_CODE (iter_type) != TYPE_CODE_TYPEDEF)
855796c8dcSSimon Schubert break;
865796c8dcSSimon Schubert
875796c8dcSSimon Schubert /* Peel a single typedef. If the typedef doesn't have a target
885796c8dcSSimon Schubert type, we use check_typedef and hope the result is ok -- it
895796c8dcSSimon Schubert might be for C++, where wchar_t is a built-in type. */
905796c8dcSSimon Schubert if (TYPE_TARGET_TYPE (iter_type))
915796c8dcSSimon Schubert iter_type = TYPE_TARGET_TYPE (iter_type);
925796c8dcSSimon Schubert else
935796c8dcSSimon Schubert iter_type = check_typedef (iter_type);
945796c8dcSSimon Schubert }
955796c8dcSSimon Schubert
965796c8dcSSimon Schubert if (format == 's')
975796c8dcSSimon Schubert {
98c50c785cSJohn Marino /* Print this as a string if we can manage it. For now, no wide
99c50c785cSJohn Marino character support. */
1005796c8dcSSimon Schubert if (TYPE_CODE (true_type) == TYPE_CODE_INT
1015796c8dcSSimon Schubert && TYPE_LENGTH (true_type) == 1)
1025796c8dcSSimon Schubert return 1;
1035796c8dcSSimon Schubert }
1045796c8dcSSimon Schubert else
1055796c8dcSSimon Schubert {
1065796c8dcSSimon Schubert /* If a one-byte TYPE_CODE_INT is missing the not-a-character
1075796c8dcSSimon Schubert flag, then we treat it as text; otherwise, we assume it's
1085796c8dcSSimon Schubert being used as data. */
1095796c8dcSSimon Schubert if (TYPE_CODE (true_type) == TYPE_CODE_INT
1105796c8dcSSimon Schubert && TYPE_LENGTH (true_type) == 1
1115796c8dcSSimon Schubert && !TYPE_NOTTEXT (true_type))
1125796c8dcSSimon Schubert return 1;
1135796c8dcSSimon Schubert }
1145796c8dcSSimon Schubert
1155796c8dcSSimon Schubert return 0;
1165796c8dcSSimon Schubert }
1175796c8dcSSimon Schubert
118*ef5ccd6cSJohn Marino /* Decorations for C. */
1195796c8dcSSimon Schubert
120*ef5ccd6cSJohn Marino static const struct generic_val_print_decorations c_decorations =
121*ef5ccd6cSJohn Marino {
122*ef5ccd6cSJohn Marino "",
123*ef5ccd6cSJohn Marino " + ",
124*ef5ccd6cSJohn Marino " * I",
125*ef5ccd6cSJohn Marino "true",
126*ef5ccd6cSJohn Marino "false",
127*ef5ccd6cSJohn Marino "void"
128*ef5ccd6cSJohn Marino };
129*ef5ccd6cSJohn Marino
130*ef5ccd6cSJohn Marino /* See val_print for a description of the various parameters of this
131*ef5ccd6cSJohn Marino function; they are identical. */
132*ef5ccd6cSJohn Marino
133*ef5ccd6cSJohn Marino void
c_val_print(struct type * type,const gdb_byte * valaddr,int embedded_offset,CORE_ADDR address,struct ui_file * stream,int recurse,const struct value * original_value,const struct value_print_options * options)134c50c785cSJohn Marino c_val_print (struct type *type, const gdb_byte *valaddr,
135c50c785cSJohn Marino int embedded_offset, CORE_ADDR address,
136c50c785cSJohn Marino struct ui_file *stream, int recurse,
137cf7f2e2dSJohn Marino const struct value *original_value,
1385796c8dcSSimon Schubert const struct value_print_options *options)
1395796c8dcSSimon Schubert {
1405796c8dcSSimon Schubert struct gdbarch *gdbarch = get_type_arch (type);
1415796c8dcSSimon Schubert enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
142c50c785cSJohn Marino unsigned int i = 0; /* Number of characters printed. */
1435796c8dcSSimon Schubert unsigned len;
1445796c8dcSSimon Schubert struct type *elttype, *unresolved_elttype;
1455796c8dcSSimon Schubert struct type *unresolved_type = type;
1465796c8dcSSimon Schubert unsigned eltlen;
1475796c8dcSSimon Schubert CORE_ADDR addr;
1485796c8dcSSimon Schubert
1495796c8dcSSimon Schubert CHECK_TYPEDEF (type);
1505796c8dcSSimon Schubert switch (TYPE_CODE (type))
1515796c8dcSSimon Schubert {
1525796c8dcSSimon Schubert case TYPE_CODE_ARRAY:
1535796c8dcSSimon Schubert unresolved_elttype = TYPE_TARGET_TYPE (type);
1545796c8dcSSimon Schubert elttype = check_typedef (unresolved_elttype);
1555796c8dcSSimon Schubert if (TYPE_LENGTH (type) > 0 && TYPE_LENGTH (unresolved_elttype) > 0)
1565796c8dcSSimon Schubert {
157c50c785cSJohn Marino LONGEST low_bound, high_bound;
158c50c785cSJohn Marino
159c50c785cSJohn Marino if (!get_array_bounds (type, &low_bound, &high_bound))
160c50c785cSJohn Marino error (_("Could not determine the array high bound"));
161c50c785cSJohn Marino
1625796c8dcSSimon Schubert eltlen = TYPE_LENGTH (elttype);
163c50c785cSJohn Marino len = high_bound - low_bound + 1;
1645796c8dcSSimon Schubert if (options->prettyprint_arrays)
1655796c8dcSSimon Schubert {
1665796c8dcSSimon Schubert print_spaces_filtered (2 + 2 * recurse, stream);
1675796c8dcSSimon Schubert }
1685796c8dcSSimon Schubert
169cf7f2e2dSJohn Marino /* Print arrays of textual chars with a string syntax, as
170cf7f2e2dSJohn Marino long as the entire array is valid. */
171c50c785cSJohn Marino if (c_textual_element_type (unresolved_elttype,
172c50c785cSJohn Marino options->format)
173c50c785cSJohn Marino && value_bytes_available (original_value, embedded_offset,
174c50c785cSJohn Marino TYPE_LENGTH (type))
175cf7f2e2dSJohn Marino && value_bits_valid (original_value,
176cf7f2e2dSJohn Marino TARGET_CHAR_BIT * embedded_offset,
177cf7f2e2dSJohn Marino TARGET_CHAR_BIT * TYPE_LENGTH (type)))
1785796c8dcSSimon Schubert {
179*ef5ccd6cSJohn Marino int force_ellipses = 0;
180*ef5ccd6cSJohn Marino
181c50c785cSJohn Marino /* If requested, look for the first null char and only
182c50c785cSJohn Marino print elements up to it. */
1835796c8dcSSimon Schubert if (options->stop_print_at_null)
1845796c8dcSSimon Schubert {
1855796c8dcSSimon Schubert unsigned int temp_len;
1865796c8dcSSimon Schubert
1875796c8dcSSimon Schubert for (temp_len = 0;
1885796c8dcSSimon Schubert (temp_len < len
1895796c8dcSSimon Schubert && temp_len < options->print_max
1905796c8dcSSimon Schubert && extract_unsigned_integer (valaddr + embedded_offset
1915796c8dcSSimon Schubert + temp_len * eltlen,
192cf7f2e2dSJohn Marino eltlen, byte_order) != 0);
1935796c8dcSSimon Schubert ++temp_len)
1945796c8dcSSimon Schubert ;
195*ef5ccd6cSJohn Marino
196*ef5ccd6cSJohn Marino /* Force LA_PRINT_STRING to print ellipses if
197*ef5ccd6cSJohn Marino we've printed the maximum characters and
198*ef5ccd6cSJohn Marino the next character is not \000. */
199*ef5ccd6cSJohn Marino if (temp_len == options->print_max && temp_len < len)
200*ef5ccd6cSJohn Marino {
201*ef5ccd6cSJohn Marino ULONGEST val
202*ef5ccd6cSJohn Marino = extract_unsigned_integer (valaddr + embedded_offset
203*ef5ccd6cSJohn Marino + temp_len * eltlen,
204*ef5ccd6cSJohn Marino eltlen, byte_order);
205*ef5ccd6cSJohn Marino if (val != 0)
206*ef5ccd6cSJohn Marino force_ellipses = 1;
207*ef5ccd6cSJohn Marino }
208*ef5ccd6cSJohn Marino
2095796c8dcSSimon Schubert len = temp_len;
2105796c8dcSSimon Schubert }
2115796c8dcSSimon Schubert
2125796c8dcSSimon Schubert LA_PRINT_STRING (stream, unresolved_elttype,
213cf7f2e2dSJohn Marino valaddr + embedded_offset, len,
214*ef5ccd6cSJohn Marino NULL, force_ellipses, options);
2155796c8dcSSimon Schubert i = len;
2165796c8dcSSimon Schubert }
2175796c8dcSSimon Schubert else
2185796c8dcSSimon Schubert {
2195796c8dcSSimon Schubert fprintf_filtered (stream, "{");
2205796c8dcSSimon Schubert /* If this is a virtual function table, print the 0th
221c50c785cSJohn Marino entry specially, and the rest of the members
222c50c785cSJohn Marino normally. */
2235796c8dcSSimon Schubert if (cp_is_vtbl_ptr_type (elttype))
2245796c8dcSSimon Schubert {
2255796c8dcSSimon Schubert i = 1;
226c50c785cSJohn Marino fprintf_filtered (stream, _("%d vtable entries"),
227c50c785cSJohn Marino len - 1);
2285796c8dcSSimon Schubert }
2295796c8dcSSimon Schubert else
2305796c8dcSSimon Schubert {
2315796c8dcSSimon Schubert i = 0;
2325796c8dcSSimon Schubert }
233c50c785cSJohn Marino val_print_array_elements (type, valaddr, embedded_offset,
234c50c785cSJohn Marino address, stream,
235cf7f2e2dSJohn Marino recurse, original_value, options, i);
2365796c8dcSSimon Schubert fprintf_filtered (stream, "}");
2375796c8dcSSimon Schubert }
2385796c8dcSSimon Schubert break;
2395796c8dcSSimon Schubert }
240c50c785cSJohn Marino /* Array of unspecified length: treat like pointer to first
241c50c785cSJohn Marino elt. */
242c50c785cSJohn Marino addr = address + embedded_offset;
2435796c8dcSSimon Schubert goto print_unpacked_pointer;
2445796c8dcSSimon Schubert
2455796c8dcSSimon Schubert case TYPE_CODE_METHODPTR:
2465796c8dcSSimon Schubert cplus_print_method_ptr (valaddr + embedded_offset, type, stream);
2475796c8dcSSimon Schubert break;
2485796c8dcSSimon Schubert
2495796c8dcSSimon Schubert case TYPE_CODE_PTR:
2505796c8dcSSimon Schubert if (options->format && options->format != 's')
2515796c8dcSSimon Schubert {
252c50c785cSJohn Marino val_print_scalar_formatted (type, valaddr, embedded_offset,
253c50c785cSJohn Marino original_value, options, 0, stream);
2545796c8dcSSimon Schubert break;
2555796c8dcSSimon Schubert }
2565796c8dcSSimon Schubert if (options->vtblprint && cp_is_vtbl_ptr_type (type))
2575796c8dcSSimon Schubert {
2585796c8dcSSimon Schubert /* Print the unmangled name if desired. */
2595796c8dcSSimon Schubert /* Print vtable entry - we only get here if we ARE using
260c50c785cSJohn Marino -fvtable_thunks. (Otherwise, look under
261c50c785cSJohn Marino TYPE_CODE_STRUCT.) */
2625796c8dcSSimon Schubert CORE_ADDR addr
2635796c8dcSSimon Schubert = extract_typed_address (valaddr + embedded_offset, type);
264cf7f2e2dSJohn Marino
265*ef5ccd6cSJohn Marino print_function_pointer_address (options, gdbarch, addr, stream);
2665796c8dcSSimon Schubert break;
2675796c8dcSSimon Schubert }
2685796c8dcSSimon Schubert unresolved_elttype = TYPE_TARGET_TYPE (type);
2695796c8dcSSimon Schubert elttype = check_typedef (unresolved_elttype);
2705796c8dcSSimon Schubert {
271*ef5ccd6cSJohn Marino int want_space;
272*ef5ccd6cSJohn Marino
2735796c8dcSSimon Schubert addr = unpack_pointer (type, valaddr + embedded_offset);
2745796c8dcSSimon Schubert print_unpacked_pointer:
2755796c8dcSSimon Schubert
276*ef5ccd6cSJohn Marino want_space = 0;
277*ef5ccd6cSJohn Marino
2785796c8dcSSimon Schubert if (TYPE_CODE (elttype) == TYPE_CODE_FUNC)
2795796c8dcSSimon Schubert {
2805796c8dcSSimon Schubert /* Try to print what function it points to. */
281*ef5ccd6cSJohn Marino print_function_pointer_address (options, gdbarch, addr, stream);
282*ef5ccd6cSJohn Marino return;
2835796c8dcSSimon Schubert }
2845796c8dcSSimon Schubert
285*ef5ccd6cSJohn Marino if (options->symbol_print)
286*ef5ccd6cSJohn Marino want_space = print_address_demangle (options, gdbarch, addr,
287*ef5ccd6cSJohn Marino stream, demangle);
288*ef5ccd6cSJohn Marino else if (options->addressprint)
289*ef5ccd6cSJohn Marino {
2905796c8dcSSimon Schubert fputs_filtered (paddress (gdbarch, addr), stream);
291*ef5ccd6cSJohn Marino want_space = 1;
292*ef5ccd6cSJohn Marino }
2935796c8dcSSimon Schubert
2945796c8dcSSimon Schubert /* For a pointer to a textual type, also print the string
2955796c8dcSSimon Schubert pointed to, unless pointer is null. */
2965796c8dcSSimon Schubert
297c50c785cSJohn Marino if (c_textual_element_type (unresolved_elttype,
298c50c785cSJohn Marino options->format)
2995796c8dcSSimon Schubert && addr != 0)
3005796c8dcSSimon Schubert {
301*ef5ccd6cSJohn Marino if (want_space)
302*ef5ccd6cSJohn Marino fputs_filtered (" ", stream);
303c50c785cSJohn Marino i = val_print_string (unresolved_elttype, NULL,
304c50c785cSJohn Marino addr, -1,
305c50c785cSJohn Marino stream, options);
3065796c8dcSSimon Schubert }
3075796c8dcSSimon Schubert else if (cp_is_vtbl_member (type))
3085796c8dcSSimon Schubert {
309c50c785cSJohn Marino /* Print vtbl's nicely. */
310c50c785cSJohn Marino CORE_ADDR vt_address = unpack_pointer (type,
311c50c785cSJohn Marino valaddr
312c50c785cSJohn Marino + embedded_offset);
3135796c8dcSSimon Schubert struct minimal_symbol *msymbol =
3145796c8dcSSimon Schubert lookup_minimal_symbol_by_pc (vt_address);
315*ef5ccd6cSJohn Marino
316*ef5ccd6cSJohn Marino /* If 'symbol_print' is set, we did the work above. */
317*ef5ccd6cSJohn Marino if (!options->symbol_print
318*ef5ccd6cSJohn Marino && (msymbol != NULL)
319cf7f2e2dSJohn Marino && (vt_address == SYMBOL_VALUE_ADDRESS (msymbol)))
3205796c8dcSSimon Schubert {
321*ef5ccd6cSJohn Marino if (want_space)
322*ef5ccd6cSJohn Marino fputs_filtered (" ", stream);
3235796c8dcSSimon Schubert fputs_filtered (" <", stream);
3245796c8dcSSimon Schubert fputs_filtered (SYMBOL_PRINT_NAME (msymbol), stream);
3255796c8dcSSimon Schubert fputs_filtered (">", stream);
326*ef5ccd6cSJohn Marino want_space = 1;
3275796c8dcSSimon Schubert }
328*ef5ccd6cSJohn Marino
3295796c8dcSSimon Schubert if (vt_address && options->vtblprint)
3305796c8dcSSimon Schubert {
3315796c8dcSSimon Schubert struct value *vt_val;
3325796c8dcSSimon Schubert struct symbol *wsym = (struct symbol *) NULL;
3335796c8dcSSimon Schubert struct type *wtype;
3345796c8dcSSimon Schubert struct block *block = (struct block *) NULL;
335*ef5ccd6cSJohn Marino struct field_of_this_result is_this_fld;
336*ef5ccd6cSJohn Marino
337*ef5ccd6cSJohn Marino if (want_space)
338*ef5ccd6cSJohn Marino fputs_filtered (" ", stream);
3395796c8dcSSimon Schubert
3405796c8dcSSimon Schubert if (msymbol != NULL)
341c50c785cSJohn Marino wsym = lookup_symbol (SYMBOL_LINKAGE_NAME (msymbol),
342c50c785cSJohn Marino block, VAR_DOMAIN,
343c50c785cSJohn Marino &is_this_fld);
3445796c8dcSSimon Schubert
3455796c8dcSSimon Schubert if (wsym)
3465796c8dcSSimon Schubert {
3475796c8dcSSimon Schubert wtype = SYMBOL_TYPE (wsym);
3485796c8dcSSimon Schubert }
3495796c8dcSSimon Schubert else
3505796c8dcSSimon Schubert {
3515796c8dcSSimon Schubert wtype = unresolved_elttype;
3525796c8dcSSimon Schubert }
3535796c8dcSSimon Schubert vt_val = value_at (wtype, vt_address);
354c50c785cSJohn Marino common_val_print (vt_val, stream, recurse + 1,
355c50c785cSJohn Marino options, current_language);
3565796c8dcSSimon Schubert if (options->pretty)
3575796c8dcSSimon Schubert {
3585796c8dcSSimon Schubert fprintf_filtered (stream, "\n");
3595796c8dcSSimon Schubert print_spaces_filtered (2 + 2 * recurse, stream);
3605796c8dcSSimon Schubert }
3615796c8dcSSimon Schubert }
3625796c8dcSSimon Schubert }
363*ef5ccd6cSJohn Marino return;
3645796c8dcSSimon Schubert }
3655796c8dcSSimon Schubert break;
3665796c8dcSSimon Schubert
3675796c8dcSSimon Schubert case TYPE_CODE_UNION:
3685796c8dcSSimon Schubert if (recurse && !options->unionprint)
3695796c8dcSSimon Schubert {
3705796c8dcSSimon Schubert fprintf_filtered (stream, "{...}");
3715796c8dcSSimon Schubert break;
3725796c8dcSSimon Schubert }
3735796c8dcSSimon Schubert /* Fall through. */
3745796c8dcSSimon Schubert case TYPE_CODE_STRUCT:
375c50c785cSJohn Marino /*FIXME: Abstract this away. */
3765796c8dcSSimon Schubert if (options->vtblprint && cp_is_vtbl_ptr_type (type))
3775796c8dcSSimon Schubert {
3785796c8dcSSimon Schubert /* Print the unmangled name if desired. */
3795796c8dcSSimon Schubert /* Print vtable entry - we only get here if NOT using
380c50c785cSJohn Marino -fvtable_thunks. (Otherwise, look under
381c50c785cSJohn Marino TYPE_CODE_PTR.) */
382c50c785cSJohn Marino int offset = (embedded_offset
383c50c785cSJohn Marino + TYPE_FIELD_BITPOS (type,
384c50c785cSJohn Marino VTBL_FNADDR_OFFSET) / 8);
385c50c785cSJohn Marino struct type *field_type = TYPE_FIELD_TYPE (type,
386c50c785cSJohn Marino VTBL_FNADDR_OFFSET);
3875796c8dcSSimon Schubert CORE_ADDR addr
3885796c8dcSSimon Schubert = extract_typed_address (valaddr + offset, field_type);
3895796c8dcSSimon Schubert
390*ef5ccd6cSJohn Marino print_function_pointer_address (options, gdbarch, addr, stream);
3915796c8dcSSimon Schubert }
3925796c8dcSSimon Schubert else
393cf7f2e2dSJohn Marino cp_print_value_fields_rtti (type, valaddr,
394c50c785cSJohn Marino embedded_offset, address,
395c50c785cSJohn Marino stream, recurse,
396c50c785cSJohn Marino original_value, options,
397c50c785cSJohn Marino NULL, 0);
3985796c8dcSSimon Schubert break;
3995796c8dcSSimon Schubert
4005796c8dcSSimon Schubert case TYPE_CODE_INT:
4015796c8dcSSimon Schubert if (options->format || options->output_format)
4025796c8dcSSimon Schubert {
4035796c8dcSSimon Schubert struct value_print_options opts = *options;
404cf7f2e2dSJohn Marino
4055796c8dcSSimon Schubert opts.format = (options->format ? options->format
4065796c8dcSSimon Schubert : options->output_format);
407c50c785cSJohn Marino val_print_scalar_formatted (type, valaddr, embedded_offset,
408c50c785cSJohn Marino original_value, &opts, 0, stream);
4095796c8dcSSimon Schubert }
4105796c8dcSSimon Schubert else
4115796c8dcSSimon Schubert {
412c50c785cSJohn Marino val_print_type_code_int (type, valaddr + embedded_offset,
413c50c785cSJohn Marino stream);
414c50c785cSJohn Marino /* C and C++ has no single byte int type, char is used
415c50c785cSJohn Marino instead. Since we don't know whether the value is really
416c50c785cSJohn Marino intended to be used as an integer or a character, print
417c50c785cSJohn Marino the character equivalent as well. */
418cf7f2e2dSJohn Marino if (c_textual_element_type (unresolved_type, options->format))
4195796c8dcSSimon Schubert {
4205796c8dcSSimon Schubert fputs_filtered (" ", stream);
421c50c785cSJohn Marino LA_PRINT_CHAR (unpack_long (type, valaddr + embedded_offset),
4225796c8dcSSimon Schubert unresolved_type, stream);
4235796c8dcSSimon Schubert }
4245796c8dcSSimon Schubert }
4255796c8dcSSimon Schubert break;
4265796c8dcSSimon Schubert
427*ef5ccd6cSJohn Marino case TYPE_CODE_MEMBERPTR:
428*ef5ccd6cSJohn Marino if (!options->format)
4295796c8dcSSimon Schubert {
430*ef5ccd6cSJohn Marino cp_print_class_member (valaddr + embedded_offset, type, stream, "&");
4315796c8dcSSimon Schubert break;
432*ef5ccd6cSJohn Marino }
433*ef5ccd6cSJohn Marino /* FALLTHROUGH */
4345796c8dcSSimon Schubert
435*ef5ccd6cSJohn Marino case TYPE_CODE_REF:
436*ef5ccd6cSJohn Marino case TYPE_CODE_ENUM:
437*ef5ccd6cSJohn Marino case TYPE_CODE_FLAGS:
438*ef5ccd6cSJohn Marino case TYPE_CODE_FUNC:
439*ef5ccd6cSJohn Marino case TYPE_CODE_METHOD:
440*ef5ccd6cSJohn Marino case TYPE_CODE_BOOL:
441*ef5ccd6cSJohn Marino case TYPE_CODE_RANGE:
4425796c8dcSSimon Schubert case TYPE_CODE_FLT:
4435796c8dcSSimon Schubert case TYPE_CODE_DECFLOAT:
4445796c8dcSSimon Schubert case TYPE_CODE_VOID:
4455796c8dcSSimon Schubert case TYPE_CODE_ERROR:
4465796c8dcSSimon Schubert case TYPE_CODE_UNDEF:
4475796c8dcSSimon Schubert case TYPE_CODE_COMPLEX:
448*ef5ccd6cSJohn Marino case TYPE_CODE_CHAR:
4495796c8dcSSimon Schubert default:
450*ef5ccd6cSJohn Marino generic_val_print (type, valaddr, embedded_offset, address,
451*ef5ccd6cSJohn Marino stream, recurse, original_value, options,
452*ef5ccd6cSJohn Marino &c_decorations);
453*ef5ccd6cSJohn Marino break;
4545796c8dcSSimon Schubert }
4555796c8dcSSimon Schubert gdb_flush (stream);
4565796c8dcSSimon Schubert }
4575796c8dcSSimon Schubert
458*ef5ccd6cSJohn Marino void
c_value_print(struct value * val,struct ui_file * stream,const struct value_print_options * options)4595796c8dcSSimon Schubert c_value_print (struct value *val, struct ui_file *stream,
4605796c8dcSSimon Schubert const struct value_print_options *options)
4615796c8dcSSimon Schubert {
4625796c8dcSSimon Schubert struct type *type, *real_type, *val_type;
4635796c8dcSSimon Schubert int full, top, using_enc;
4645796c8dcSSimon Schubert struct value_print_options opts = *options;
4655796c8dcSSimon Schubert
4665796c8dcSSimon Schubert opts.deref_ref = 1;
4675796c8dcSSimon Schubert
4685796c8dcSSimon Schubert /* If it is a pointer, indicate what it points to.
4695796c8dcSSimon Schubert
4705796c8dcSSimon Schubert Print type also if it is a reference.
4715796c8dcSSimon Schubert
4725796c8dcSSimon Schubert C++: if it is a member pointer, we will take care
4735796c8dcSSimon Schubert of that when we print it. */
4745796c8dcSSimon Schubert
4755796c8dcSSimon Schubert /* Preserve the original type before stripping typedefs. We prefer
4765796c8dcSSimon Schubert to pass down the original type when possible, but for local
4775796c8dcSSimon Schubert checks it is better to look past the typedefs. */
4785796c8dcSSimon Schubert val_type = value_type (val);
4795796c8dcSSimon Schubert type = check_typedef (val_type);
4805796c8dcSSimon Schubert
4815796c8dcSSimon Schubert if (TYPE_CODE (type) == TYPE_CODE_PTR
4825796c8dcSSimon Schubert || TYPE_CODE (type) == TYPE_CODE_REF)
4835796c8dcSSimon Schubert {
4845796c8dcSSimon Schubert /* Hack: remove (char *) for char strings. Their
4855796c8dcSSimon Schubert type is indicated by the quoted string anyway.
486cf7f2e2dSJohn Marino (Don't use c_textual_element_type here; quoted strings
4875796c8dcSSimon Schubert are always exactly (char *), (wchar_t *), or the like. */
4885796c8dcSSimon Schubert if (TYPE_CODE (val_type) == TYPE_CODE_PTR
4895796c8dcSSimon Schubert && TYPE_NAME (val_type) == NULL
4905796c8dcSSimon Schubert && TYPE_NAME (TYPE_TARGET_TYPE (val_type)) != NULL
491c50c785cSJohn Marino && (strcmp (TYPE_NAME (TYPE_TARGET_TYPE (val_type)),
492c50c785cSJohn Marino "char") == 0
4935796c8dcSSimon Schubert || textual_name (TYPE_NAME (TYPE_TARGET_TYPE (val_type)))))
4945796c8dcSSimon Schubert {
495c50c785cSJohn Marino /* Print nothing. */
4965796c8dcSSimon Schubert }
4975796c8dcSSimon Schubert else if (options->objectprint
4985796c8dcSSimon Schubert && (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_CLASS))
4995796c8dcSSimon Schubert {
5005796c8dcSSimon Schubert
5015796c8dcSSimon Schubert if (TYPE_CODE(type) == TYPE_CODE_REF)
5025796c8dcSSimon Schubert {
5035796c8dcSSimon Schubert /* Copy value, change to pointer, so we don't get an
504c50c785cSJohn Marino error about a non-pointer type in
505c50c785cSJohn Marino value_rtti_target_type. */
5065796c8dcSSimon Schubert struct value *temparg;
5075796c8dcSSimon Schubert temparg=value_copy(val);
508c50c785cSJohn Marino deprecated_set_value_type
509c50c785cSJohn Marino (temparg, lookup_pointer_type (TYPE_TARGET_TYPE (type)));
5105796c8dcSSimon Schubert val = temparg;
5115796c8dcSSimon Schubert }
512c50c785cSJohn Marino /* Pointer to class, check real type of object. */
5135796c8dcSSimon Schubert fprintf_filtered (stream, "(");
514c50c785cSJohn Marino
515c50c785cSJohn Marino if (value_entirely_available (val))
516c50c785cSJohn Marino {
517*ef5ccd6cSJohn Marino real_type = value_rtti_indirect_type (val, &full, &top,
518*ef5ccd6cSJohn Marino &using_enc);
5195796c8dcSSimon Schubert if (real_type)
5205796c8dcSSimon Schubert {
521c50c785cSJohn Marino /* RTTI entry found. */
522*ef5ccd6cSJohn Marino type = real_type;
523*ef5ccd6cSJohn Marino
524c50c785cSJohn Marino /* Need to adjust pointer value. */
525c50c785cSJohn Marino val = value_from_pointer (type, value_as_address (val) - top);
5265796c8dcSSimon Schubert
527c50c785cSJohn Marino /* Note: When we look up RTTI entries, we don't get
528c50c785cSJohn Marino any information on const or volatile
529c50c785cSJohn Marino attributes. */
530c50c785cSJohn Marino }
5315796c8dcSSimon Schubert }
5325796c8dcSSimon Schubert type_print (type, "", stream, -1);
5335796c8dcSSimon Schubert fprintf_filtered (stream, ") ");
5345796c8dcSSimon Schubert val_type = type;
5355796c8dcSSimon Schubert }
5365796c8dcSSimon Schubert else
5375796c8dcSSimon Schubert {
5385796c8dcSSimon Schubert /* normal case */
5395796c8dcSSimon Schubert fprintf_filtered (stream, "(");
5405796c8dcSSimon Schubert type_print (value_type (val), "", stream, -1);
5415796c8dcSSimon Schubert fprintf_filtered (stream, ") ");
5425796c8dcSSimon Schubert }
5435796c8dcSSimon Schubert }
5445796c8dcSSimon Schubert
5455796c8dcSSimon Schubert if (!value_initialized (val))
5465796c8dcSSimon Schubert fprintf_filtered (stream, " [uninitialized] ");
5475796c8dcSSimon Schubert
5485796c8dcSSimon Schubert if (options->objectprint && (TYPE_CODE (type) == TYPE_CODE_CLASS))
5495796c8dcSSimon Schubert {
550c50c785cSJohn Marino /* Attempt to determine real type of object. */
5515796c8dcSSimon Schubert real_type = value_rtti_type (val, &full, &top, &using_enc);
5525796c8dcSSimon Schubert if (real_type)
5535796c8dcSSimon Schubert {
554c50c785cSJohn Marino /* We have RTTI information, so use it. */
555c50c785cSJohn Marino val = value_full_object (val, real_type,
556c50c785cSJohn Marino full, top, using_enc);
5575796c8dcSSimon Schubert fprintf_filtered (stream, "(%s%s) ",
5585796c8dcSSimon Schubert TYPE_NAME (real_type),
5595796c8dcSSimon Schubert full ? "" : _(" [incomplete object]"));
560c50c785cSJohn Marino /* Print out object: enclosing type is same as real_type if
561c50c785cSJohn Marino full. */
562*ef5ccd6cSJohn Marino val_print (value_enclosing_type (val),
563cf7f2e2dSJohn Marino value_contents_for_printing (val), 0,
5645796c8dcSSimon Schubert value_address (val), stream, 0,
565cf7f2e2dSJohn Marino val, &opts, current_language);
566*ef5ccd6cSJohn Marino return;
567c50c785cSJohn Marino /* Note: When we look up RTTI entries, we don't get any
568c50c785cSJohn Marino information on const or volatile attributes. */
5695796c8dcSSimon Schubert }
5705796c8dcSSimon Schubert else if (type != check_typedef (value_enclosing_type (val)))
5715796c8dcSSimon Schubert {
572c50c785cSJohn Marino /* No RTTI information, so let's do our best. */
5735796c8dcSSimon Schubert fprintf_filtered (stream, "(%s ?) ",
5745796c8dcSSimon Schubert TYPE_NAME (value_enclosing_type (val)));
575*ef5ccd6cSJohn Marino val_print (value_enclosing_type (val),
576cf7f2e2dSJohn Marino value_contents_for_printing (val), 0,
5775796c8dcSSimon Schubert value_address (val), stream, 0,
578cf7f2e2dSJohn Marino val, &opts, current_language);
579*ef5ccd6cSJohn Marino return;
5805796c8dcSSimon Schubert }
581c50c785cSJohn Marino /* Otherwise, we end up at the return outside this "if". */
5825796c8dcSSimon Schubert }
5835796c8dcSSimon Schubert
584*ef5ccd6cSJohn Marino val_print (val_type, value_contents_for_printing (val),
5855796c8dcSSimon Schubert value_embedded_offset (val),
5865796c8dcSSimon Schubert value_address (val),
587cf7f2e2dSJohn Marino stream, 0,
588cf7f2e2dSJohn Marino val, &opts, current_language);
5895796c8dcSSimon Schubert }
590