c-valprint.c revision 1.1.1.5 1 1.1 christos /* Support for printing C values for GDB, the GNU debugger.
2 1.1 christos
3 1.1.1.5 christos Copyright (C) 1986-2019 Free Software Foundation, Inc.
4 1.1 christos
5 1.1 christos This file is part of GDB.
6 1.1 christos
7 1.1 christos This program is free software; you can redistribute it and/or modify
8 1.1 christos it under the terms of the GNU General Public License as published by
9 1.1 christos the Free Software Foundation; either version 3 of the License, or
10 1.1 christos (at your option) any later version.
11 1.1 christos
12 1.1 christos This program is distributed in the hope that it will be useful,
13 1.1 christos but WITHOUT ANY WARRANTY; without even the implied warranty of
14 1.1 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 1.1 christos GNU General Public License for more details.
16 1.1 christos
17 1.1 christos You should have received a copy of the GNU General Public License
18 1.1 christos along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 1.1 christos
20 1.1 christos #include "defs.h"
21 1.1 christos #include "symtab.h"
22 1.1 christos #include "gdbtypes.h"
23 1.1 christos #include "expression.h"
24 1.1 christos #include "value.h"
25 1.1 christos #include "valprint.h"
26 1.1 christos #include "language.h"
27 1.1 christos #include "c-lang.h"
28 1.1 christos #include "cp-abi.h"
29 1.1 christos #include "target.h"
30 1.1.1.2 christos #include "objfiles.h"
31 1.1 christos
32 1.1 christos
34 1.1 christos /* A helper for c_textual_element_type. This checks the name of the
35 1.1 christos typedef. This is bogus but it isn't apparent that the compiler
36 1.1 christos provides us the help we may need. */
37 1.1 christos
38 1.1 christos static int
39 1.1 christos textual_name (const char *name)
40 1.1 christos {
41 1.1 christos return (!strcmp (name, "wchar_t")
42 1.1 christos || !strcmp (name, "char16_t")
43 1.1 christos || !strcmp (name, "char32_t"));
44 1.1 christos }
45 1.1 christos
46 1.1 christos /* Apply a heuristic to decide whether an array of TYPE or a pointer
47 1.1 christos to TYPE should be printed as a textual string. Return non-zero if
48 1.1 christos it should, or zero if it should be treated as an array of integers
49 1.1 christos or pointer to integers. FORMAT is the current format letter, or 0
50 1.1 christos if none.
51 1.1 christos
52 1.1 christos We guess that "char" is a character. Explicitly signed and
53 1.1 christos unsigned character types are also characters. Integer data from
54 1.1 christos vector types is not. The user can override this by using the /s
55 1.1 christos format letter. */
56 1.1 christos
57 1.1 christos int
58 1.1 christos c_textual_element_type (struct type *type, char format)
59 1.1 christos {
60 1.1 christos struct type *true_type, *iter_type;
61 1.1 christos
62 1.1 christos if (format != 0 && format != 's')
63 1.1 christos return 0;
64 1.1 christos
65 1.1 christos /* We also rely on this for its side effect of setting up all the
66 1.1 christos typedef pointers. */
67 1.1 christos true_type = check_typedef (type);
68 1.1 christos
69 1.1 christos /* TYPE_CODE_CHAR is always textual. */
70 1.1 christos if (TYPE_CODE (true_type) == TYPE_CODE_CHAR)
71 1.1 christos return 1;
72 1.1 christos
73 1.1 christos /* Any other character-like types must be integral. */
74 1.1 christos if (TYPE_CODE (true_type) != TYPE_CODE_INT)
75 1.1 christos return 0;
76 1.1 christos
77 1.1 christos /* We peel typedefs one by one, looking for a match. */
78 1.1 christos iter_type = type;
79 1.1 christos while (iter_type)
80 1.1 christos {
81 1.1 christos /* Check the name of the type. */
82 1.1 christos if (TYPE_NAME (iter_type) && textual_name (TYPE_NAME (iter_type)))
83 1.1 christos return 1;
84 1.1 christos
85 1.1 christos if (TYPE_CODE (iter_type) != TYPE_CODE_TYPEDEF)
86 1.1 christos break;
87 1.1 christos
88 1.1 christos /* Peel a single typedef. If the typedef doesn't have a target
89 1.1 christos type, we use check_typedef and hope the result is ok -- it
90 1.1 christos might be for C++, where wchar_t is a built-in type. */
91 1.1 christos if (TYPE_TARGET_TYPE (iter_type))
92 1.1 christos iter_type = TYPE_TARGET_TYPE (iter_type);
93 1.1 christos else
94 1.1 christos iter_type = check_typedef (iter_type);
95 1.1 christos }
96 1.1 christos
97 1.1 christos if (format == 's')
98 1.1 christos {
99 1.1 christos /* Print this as a string if we can manage it. For now, no wide
100 1.1 christos character support. */
101 1.1 christos if (TYPE_CODE (true_type) == TYPE_CODE_INT
102 1.1 christos && TYPE_LENGTH (true_type) == 1)
103 1.1 christos return 1;
104 1.1 christos }
105 1.1 christos else
106 1.1 christos {
107 1.1 christos /* If a one-byte TYPE_CODE_INT is missing the not-a-character
108 1.1 christos flag, then we treat it as text; otherwise, we assume it's
109 1.1 christos being used as data. */
110 1.1 christos if (TYPE_CODE (true_type) == TYPE_CODE_INT
111 1.1 christos && TYPE_LENGTH (true_type) == 1
112 1.1 christos && !TYPE_NOTTEXT (true_type))
113 1.1 christos return 1;
114 1.1 christos }
115 1.1 christos
116 1.1 christos return 0;
117 1.1 christos }
118 1.1 christos
119 1.1 christos /* Decorations for C. */
120 1.1 christos
121 1.1 christos static const struct generic_val_print_decorations c_decorations =
122 1.1 christos {
123 1.1 christos "",
124 1.1 christos " + ",
125 1.1 christos " * I",
126 1.1 christos "true",
127 1.1.1.3 christos "false",
128 1.1.1.3 christos "void",
129 1.1.1.3 christos "{",
130 1.1 christos "}"
131 1.1 christos };
132 1.1.1.3 christos
133 1.1 christos /* Print a pointer based on the type of its target.
134 1.1.1.3 christos
135 1.1.1.3 christos Arguments to this functions are roughly the same as those in c_val_print.
136 1.1.1.3 christos A difference is that ADDRESS is the address to print, with embedded_offset
137 1.1.1.3 christos already added. UNRESOLVED_ELTTYPE and ELTTYPE represent the pointed type,
138 1.1.1.3 christos respectively before and after check_typedef. */
139 1.1.1.3 christos
140 1.1.1.3 christos static void
141 1.1.1.3 christos print_unpacked_pointer (struct type *type, struct type *elttype,
142 1.1.1.3 christos struct type *unresolved_elttype,
143 1.1.1.3 christos const gdb_byte *valaddr, int embedded_offset,
144 1.1.1.3 christos CORE_ADDR address, struct ui_file *stream, int recurse,
145 1.1 christos const struct value_print_options *options)
146 1.1.1.3 christos {
147 1.1 christos int want_space = 0;
148 1.1 christos struct gdbarch *gdbarch = get_type_arch (type);
149 1.1.1.3 christos
150 1.1 christos if (TYPE_CODE (elttype) == TYPE_CODE_FUNC)
151 1.1.1.3 christos {
152 1.1.1.3 christos /* Try to print what function it points to. */
153 1.1.1.3 christos print_function_pointer_address (options, gdbarch, address, stream);
154 1.1.1.3 christos return;
155 1.1.1.3 christos }
156 1.1.1.3 christos
157 1.1.1.3 christos if (options->symbol_print)
158 1.1.1.3 christos want_space = print_address_demangle (options, gdbarch, address, stream,
159 1.1.1.3 christos demangle);
160 1.1.1.3 christos else if (options->addressprint)
161 1.1.1.3 christos {
162 1.1.1.3 christos fputs_filtered (paddress (gdbarch, address), stream);
163 1.1.1.3 christos want_space = 1;
164 1.1.1.3 christos }
165 1.1.1.3 christos
166 1.1.1.3 christos /* For a pointer to a textual type, also print the string
167 1.1.1.3 christos pointed to, unless pointer is null. */
168 1.1.1.3 christos
169 1.1.1.3 christos if (c_textual_element_type (unresolved_elttype, options->format)
170 1.1.1.3 christos && address != 0)
171 1.1.1.3 christos {
172 1.1.1.3 christos if (want_space)
173 1.1.1.3 christos fputs_filtered (" ", stream);
174 1.1.1.3 christos val_print_string (unresolved_elttype, NULL, address, -1, stream, options);
175 1.1.1.3 christos }
176 1.1.1.3 christos else if (cp_is_vtbl_member (type))
177 1.1.1.3 christos {
178 1.1.1.3 christos /* Print vtbl's nicely. */
179 1.1.1.3 christos CORE_ADDR vt_address = unpack_pointer (type, valaddr + embedded_offset);
180 1.1.1.3 christos struct bound_minimal_symbol msymbol =
181 1.1.1.3 christos lookup_minimal_symbol_by_pc (vt_address);
182 1.1.1.3 christos
183 1.1.1.3 christos /* If 'symbol_print' is set, we did the work above. */
184 1.1.1.3 christos if (!options->symbol_print
185 1.1.1.3 christos && (msymbol.minsym != NULL)
186 1.1.1.3 christos && (vt_address == BMSYMBOL_VALUE_ADDRESS (msymbol)))
187 1.1.1.3 christos {
188 1.1.1.3 christos if (want_space)
189 1.1.1.3 christos fputs_filtered (" ", stream);
190 1.1.1.3 christos fputs_filtered (" <", stream);
191 1.1.1.3 christos fputs_filtered (MSYMBOL_PRINT_NAME (msymbol.minsym), stream);
192 1.1.1.3 christos fputs_filtered (">", stream);
193 1.1.1.3 christos want_space = 1;
194 1.1.1.3 christos }
195 1.1.1.3 christos
196 1.1.1.3 christos if (vt_address && options->vtblprint)
197 1.1.1.3 christos {
198 1.1.1.3 christos struct value *vt_val;
199 1.1.1.3 christos struct symbol *wsym = NULL;
200 1.1.1.3 christos struct type *wtype;
201 1.1.1.3 christos struct block *block = NULL;
202 1.1.1.3 christos
203 1.1.1.3 christos if (want_space)
204 1.1.1.3 christos fputs_filtered (" ", stream);
205 1.1.1.3 christos
206 1.1.1.5 christos if (msymbol.minsym != NULL)
207 1.1.1.5 christos {
208 1.1.1.5 christos const char *search_name
209 1.1.1.5 christos = MSYMBOL_SEARCH_NAME (msymbol.minsym);
210 1.1.1.5 christos wsym = lookup_symbol_search_name (search_name, block,
211 1.1.1.5 christos VAR_DOMAIN).symbol;
212 1.1.1.3 christos }
213 1.1.1.3 christos
214 1.1 christos if (wsym)
215 1.1.1.3 christos {
216 1.1.1.3 christos wtype = SYMBOL_TYPE (wsym);
217 1.1.1.3 christos }
218 1.1.1.3 christos else
219 1.1.1.3 christos {
220 1.1.1.3 christos wtype = unresolved_elttype;
221 1.1.1.3 christos }
222 1.1.1.3 christos vt_val = value_at (wtype, vt_address);
223 1.1.1.3 christos common_val_print (vt_val, stream, recurse + 1, options,
224 1.1.1.3 christos current_language);
225 1.1.1.3 christos if (options->prettyformat)
226 1.1.1.3 christos {
227 1.1 christos fprintf_filtered (stream, "\n");
228 1.1 christos print_spaces_filtered (2 + 2 * recurse, stream);
229 1.1.1.3 christos }
230 1.1.1.3 christos }
231 1.1.1.3 christos }
232 1.1 christos }
233 1.1.1.3 christos
234 1.1 christos /* c_val_print helper for TYPE_CODE_ARRAY. */
235 1.1.1.3 christos
236 1.1.1.3 christos static void
237 1.1.1.3 christos c_val_print_array (struct type *type, const gdb_byte *valaddr,
238 1.1.1.3 christos int embedded_offset, CORE_ADDR address,
239 1.1.1.4 christos struct ui_file *stream, int recurse,
240 1.1.1.3 christos struct value *original_value,
241 1.1.1.3 christos const struct value_print_options *options)
242 1.1.1.3 christos {
243 1.1.1.3 christos struct type *unresolved_elttype = TYPE_TARGET_TYPE (type);
244 1.1.1.3 christos struct type *elttype = check_typedef (unresolved_elttype);
245 1.1.1.3 christos struct gdbarch *arch = get_type_arch (type);
246 1.1 christos int unit_size = gdbarch_addressable_memory_unit_size (arch);
247 1.1.1.3 christos
248 1.1.1.3 christos if (TYPE_LENGTH (type) > 0 && TYPE_LENGTH (unresolved_elttype) > 0)
249 1.1.1.3 christos {
250 1.1.1.3 christos LONGEST low_bound, high_bound;
251 1.1.1.3 christos int eltlen, len;
252 1.1.1.3 christos struct gdbarch *gdbarch = get_type_arch (type);
253 1.1.1.3 christos enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
254 1.1.1.3 christos unsigned int i = 0; /* Number of characters printed. */
255 1.1.1.3 christos
256 1.1.1.3 christos if (!get_array_bounds (type, &low_bound, &high_bound))
257 1.1.1.3 christos error (_("Could not determine the array high bound"));
258 1.1.1.3 christos
259 1.1.1.3 christos eltlen = TYPE_LENGTH (elttype);
260 1.1.1.3 christos len = high_bound - low_bound + 1;
261 1.1.1.3 christos if (options->prettyformat_arrays)
262 1.1.1.3 christos {
263 1.1.1.3 christos print_spaces_filtered (2 + 2 * recurse, stream);
264 1.1.1.3 christos }
265 1.1.1.3 christos
266 1.1.1.3 christos /* Print arrays of textual chars with a string syntax, as
267 1.1.1.3 christos long as the entire array is valid. */
268 1.1.1.3 christos if (c_textual_element_type (unresolved_elttype,
269 1.1.1.3 christos options->format)
270 1.1.1.3 christos && value_bytes_available (original_value, embedded_offset,
271 1.1.1.3 christos TYPE_LENGTH (type))
272 1.1.1.3 christos && !value_bits_any_optimized_out (original_value,
273 1.1.1.3 christos TARGET_CHAR_BIT * embedded_offset,
274 1.1.1.3 christos TARGET_CHAR_BIT * TYPE_LENGTH (type)))
275 1.1.1.3 christos {
276 1.1.1.3 christos int force_ellipses = 0;
277 1.1.1.3 christos
278 1.1.1.3 christos /* If requested, look for the first null char and only
279 1.1.1.3 christos print elements up to it. */
280 1.1.1.3 christos if (options->stop_print_at_null)
281 1.1.1.3 christos {
282 1.1 christos unsigned int temp_len;
283 1.1.1.3 christos
284 1.1.1.3 christos for (temp_len = 0;
285 1.1.1.3 christos (temp_len < len
286 1.1.1.3 christos && temp_len < options->print_max
287 1.1.1.3 christos && extract_unsigned_integer (valaddr
288 1.1.1.3 christos + embedded_offset * unit_size
289 1.1.1.3 christos + temp_len * eltlen,
290 1.1.1.3 christos eltlen, byte_order) != 0);
291 1.1.1.3 christos ++temp_len)
292 1.1.1.3 christos ;
293 1.1.1.3 christos
294 1.1.1.3 christos /* Force LA_PRINT_STRING to print ellipses if
295 1.1.1.3 christos we've printed the maximum characters and
296 1.1.1.3 christos the next character is not \000. */
297 1.1.1.3 christos if (temp_len == options->print_max && temp_len < len)
298 1.1.1.3 christos {
299 1.1.1.3 christos ULONGEST val
300 1.1.1.3 christos = extract_unsigned_integer (valaddr
301 1.1.1.3 christos + embedded_offset * unit_size
302 1.1.1.3 christos + temp_len * eltlen,
303 1.1.1.3 christos eltlen, byte_order);
304 1.1.1.3 christos if (val != 0)
305 1.1 christos force_ellipses = 1;
306 1.1 christos }
307 1.1.1.3 christos
308 1.1.1.3 christos len = temp_len;
309 1.1.1.3 christos }
310 1.1.1.3 christos
311 1.1.1.3 christos LA_PRINT_STRING (stream, unresolved_elttype,
312 1.1.1.3 christos valaddr + embedded_offset * unit_size, len,
313 1.1.1.3 christos NULL, force_ellipses, options);
314 1.1.1.3 christos i = len;
315 1.1.1.3 christos }
316 1.1.1.3 christos else
317 1.1.1.3 christos {
318 1.1.1.3 christos fprintf_filtered (stream, "{");
319 1.1.1.3 christos /* If this is a virtual function table, print the 0th
320 1.1.1.3 christos entry specially, and the rest of the members
321 1.1.1.3 christos normally. */
322 1.1.1.3 christos if (cp_is_vtbl_ptr_type (elttype))
323 1.1.1.3 christos {
324 1.1.1.3 christos i = 1;
325 1.1.1.3 christos fprintf_filtered (stream, _("%d vtable entries"),
326 1.1 christos len - 1);
327 1.1 christos }
328 1.1 christos else
329 1.1.1.3 christos {
330 1.1 christos i = 0;
331 1.1.1.4 christos }
332 1.1.1.3 christos val_print_array_elements (type, embedded_offset,
333 1.1.1.3 christos address, stream,
334 1.1.1.3 christos recurse, original_value, options, i);
335 1.1 christos fprintf_filtered (stream, "}");
336 1.1.1.3 christos }
337 1.1.1.3 christos }
338 1.1.1.3 christos else
339 1.1.1.3 christos {
340 1.1.1.3 christos /* Array of unspecified length: treat like pointer to first elt. */
341 1.1.1.3 christos print_unpacked_pointer (type, elttype, unresolved_elttype, valaddr,
342 1.1.1.3 christos embedded_offset, address + embedded_offset,
343 1.1.1.3 christos stream, recurse, options);
344 1.1.1.3 christos }
345 1.1 christos }
346 1.1.1.3 christos
347 1.1 christos /* c_val_print helper for TYPE_CODE_PTR. */
348 1.1.1.3 christos
349 1.1.1.3 christos static void
350 1.1.1.3 christos c_val_print_ptr (struct type *type, const gdb_byte *valaddr,
351 1.1.1.4 christos int embedded_offset, struct ui_file *stream, int recurse,
352 1.1.1.3 christos struct value *original_value,
353 1.1.1.3 christos const struct value_print_options *options)
354 1.1.1.3 christos {
355 1.1.1.3 christos struct gdbarch *arch = get_type_arch (type);
356 1.1 christos int unit_size = gdbarch_addressable_memory_unit_size (arch);
357 1.1.1.3 christos
358 1.1.1.3 christos if (options->format && options->format != 's')
359 1.1.1.4 christos {
360 1.1.1.3 christos val_print_scalar_formatted (type, embedded_offset,
361 1.1.1.3 christos original_value, options, 0, stream);
362 1.1.1.3 christos }
363 1.1.1.3 christos else if (options->vtblprint && cp_is_vtbl_ptr_type (type))
364 1.1.1.3 christos {
365 1.1.1.3 christos /* Print the unmangled name if desired. */
366 1.1.1.3 christos /* Print vtable entry - we only get here if we ARE using
367 1.1.1.3 christos -fvtable_thunks. (Otherwise, look under
368 1.1.1.3 christos TYPE_CODE_STRUCT.) */
369 1.1.1.3 christos CORE_ADDR addr
370 1.1.1.3 christos = extract_typed_address (valaddr + embedded_offset, type);
371 1.1 christos struct gdbarch *gdbarch = get_type_arch (type);
372 1.1.1.3 christos
373 1.1.1.3 christos print_function_pointer_address (options, gdbarch, addr, stream);
374 1.1.1.3 christos }
375 1.1.1.3 christos else
376 1.1.1.3 christos {
377 1.1.1.3 christos struct type *unresolved_elttype = TYPE_TARGET_TYPE (type);
378 1.1.1.3 christos struct type *elttype = check_typedef (unresolved_elttype);
379 1.1.1.3 christos CORE_ADDR addr = unpack_pointer (type,
380 1.1 christos valaddr + embedded_offset * unit_size);
381 1.1.1.3 christos
382 1.1.1.3 christos print_unpacked_pointer (type, elttype, unresolved_elttype, valaddr,
383 1.1.1.3 christos embedded_offset, addr, stream, recurse, options);
384 1.1.1.3 christos }
385 1.1 christos }
386 1.1.1.3 christos
387 1.1 christos /* c_val_print helper for TYPE_CODE_STRUCT. */
388 1.1.1.3 christos
389 1.1.1.3 christos static void
390 1.1.1.3 christos c_val_print_struct (struct type *type, const gdb_byte *valaddr,
391 1.1.1.3 christos int embedded_offset, CORE_ADDR address,
392 1.1.1.4 christos struct ui_file *stream, int recurse,
393 1.1.1.3 christos struct value *original_value,
394 1.1.1.3 christos const struct value_print_options *options)
395 1.1.1.3 christos {
396 1.1.1.3 christos if (options->vtblprint && cp_is_vtbl_ptr_type (type))
397 1.1.1.3 christos {
398 1.1.1.3 christos /* Print the unmangled name if desired. */
399 1.1.1.3 christos /* Print vtable entry - we only get here if NOT using
400 1.1.1.3 christos -fvtable_thunks. (Otherwise, look under
401 1.1.1.3 christos TYPE_CODE_PTR.) */
402 1.1.1.3 christos struct gdbarch *gdbarch = get_type_arch (type);
403 1.1.1.3 christos int offset = (embedded_offset
404 1.1.1.3 christos + TYPE_FIELD_BITPOS (type,
405 1.1.1.3 christos VTBL_FNADDR_OFFSET) / 8);
406 1.1.1.3 christos struct type *field_type = TYPE_FIELD_TYPE (type, VTBL_FNADDR_OFFSET);
407 1.1 christos CORE_ADDR addr = extract_typed_address (valaddr + offset, field_type);
408 1.1.1.3 christos
409 1.1.1.3 christos print_function_pointer_address (options, gdbarch, addr, stream);
410 1.1.1.3 christos }
411 1.1.1.3 christos else
412 1.1.1.3 christos cp_print_value_fields_rtti (type, valaddr,
413 1.1.1.3 christos embedded_offset, address,
414 1.1.1.3 christos stream, recurse,
415 1.1.1.3 christos original_value, options,
416 1.1.1.3 christos NULL, 0);
417 1.1 christos }
418 1.1.1.3 christos
419 1.1 christos /* c_val_print helper for TYPE_CODE_UNION. */
420 1.1.1.3 christos
421 1.1.1.3 christos static void
422 1.1.1.3 christos c_val_print_union (struct type *type, const gdb_byte *valaddr,
423 1.1.1.3 christos int embedded_offset, CORE_ADDR address,
424 1.1.1.4 christos struct ui_file *stream, int recurse,
425 1.1.1.3 christos struct value *original_value,
426 1.1.1.3 christos const struct value_print_options *options)
427 1.1.1.3 christos {
428 1.1.1.3 christos if (recurse && !options->unionprint)
429 1.1.1.3 christos {
430 1.1.1.3 christos fprintf_filtered (stream, "{...}");
431 1.1.1.3 christos }
432 1.1.1.3 christos else
433 1.1.1.3 christos {
434 1.1.1.3 christos c_val_print_struct (type, valaddr, embedded_offset, address, stream,
435 1.1.1.3 christos recurse, original_value, options);
436 1.1.1.3 christos }
437 1.1.1.3 christos }
438 1.1.1.3 christos
439 1.1.1.3 christos /* c_val_print helper for TYPE_CODE_INT. */
440 1.1.1.3 christos
441 1.1.1.3 christos static void
442 1.1.1.3 christos c_val_print_int (struct type *type, struct type *unresolved_type,
443 1.1.1.4 christos const gdb_byte *valaddr, int embedded_offset,
444 1.1.1.3 christos struct ui_file *stream, struct value *original_value,
445 1.1.1.3 christos const struct value_print_options *options)
446 1.1.1.3 christos {
447 1.1.1.3 christos struct gdbarch *arch = get_type_arch (type);
448 1.1.1.3 christos int unit_size = gdbarch_addressable_memory_unit_size (arch);
449 1.1.1.3 christos
450 1.1.1.3 christos if (options->format || options->output_format)
451 1.1.1.3 christos {
452 1.1.1.3 christos struct value_print_options opts = *options;
453 1.1.1.3 christos
454 1.1.1.3 christos opts.format = (options->format ? options->format
455 1.1.1.4 christos : options->output_format);
456 1.1.1.3 christos val_print_scalar_formatted (type, embedded_offset,
457 1.1.1.3 christos original_value, &opts, 0, stream);
458 1.1.1.3 christos }
459 1.1.1.3 christos else
460 1.1.1.5 christos {
461 1.1.1.5 christos val_print_scalar_formatted (type, embedded_offset,
462 1.1.1.3 christos original_value, options, 0, stream);
463 1.1.1.3 christos /* C and C++ has no single byte int type, char is used
464 1.1.1.3 christos instead. Since we don't know whether the value is really
465 1.1.1.3 christos intended to be used as an integer or a character, print
466 1.1.1.3 christos the character equivalent as well. */
467 1.1.1.3 christos if (c_textual_element_type (unresolved_type, options->format))
468 1.1.1.3 christos {
469 1.1.1.3 christos fputs_filtered (" ", stream);
470 1.1.1.3 christos LA_PRINT_CHAR (unpack_long (type,
471 1.1.1.3 christos valaddr + embedded_offset * unit_size),
472 1.1 christos unresolved_type, stream);
473 1.1.1.3 christos }
474 1.1.1.3 christos }
475 1.1.1.3 christos }
476 1.1.1.3 christos
477 1.1.1.3 christos /* c_val_print helper for TYPE_CODE_MEMBERPTR. */
478 1.1.1.3 christos
479 1.1.1.3 christos static void
480 1.1.1.3 christos c_val_print_memberptr (struct type *type, const gdb_byte *valaddr,
481 1.1.1.3 christos int embedded_offset, CORE_ADDR address,
482 1.1.1.4 christos struct ui_file *stream, int recurse,
483 1.1.1.3 christos struct value *original_value,
484 1.1.1.3 christos const struct value_print_options *options)
485 1.1.1.3 christos {
486 1.1.1.3 christos if (!options->format)
487 1.1.1.3 christos {
488 1.1.1.3 christos cp_print_class_member (valaddr + embedded_offset, type, stream, "&");
489 1.1.1.3 christos }
490 1.1.1.3 christos else
491 1.1.1.4 christos {
492 1.1.1.3 christos generic_val_print (type, embedded_offset, address, stream,
493 1.1.1.3 christos recurse, original_value, options, &c_decorations);
494 1.1.1.3 christos }
495 1.1.1.3 christos }
496 1.1.1.3 christos
497 1.1.1.3 christos /* See val_print for a description of the various parameters of this
498 1.1.1.3 christos function; they are identical. */
499 1.1.1.3 christos
500 1.1.1.4 christos void
501 1.1.1.3 christos c_val_print (struct type *type,
502 1.1.1.3 christos int embedded_offset, CORE_ADDR address,
503 1.1.1.4 christos struct ui_file *stream, int recurse,
504 1.1.1.3 christos struct value *original_value,
505 1.1.1.3 christos const struct value_print_options *options)
506 1.1.1.3 christos {
507 1.1.1.4 christos struct type *unresolved_type = type;
508 1.1.1.3 christos const gdb_byte *valaddr = value_contents_for_printing (original_value);
509 1.1.1.3 christos
510 1.1.1.3 christos type = check_typedef (type);
511 1.1.1.3 christos switch (TYPE_CODE (type))
512 1.1.1.3 christos {
513 1.1.1.3 christos case TYPE_CODE_ARRAY:
514 1.1.1.3 christos c_val_print_array (type, valaddr, embedded_offset, address, stream,
515 1.1.1.3 christos recurse, original_value, options);
516 1.1.1.3 christos break;
517 1.1.1.3 christos
518 1.1.1.3 christos case TYPE_CODE_METHODPTR:
519 1.1.1.3 christos cplus_print_method_ptr (valaddr + embedded_offset, type, stream);
520 1.1.1.3 christos break;
521 1.1.1.3 christos
522 1.1.1.3 christos case TYPE_CODE_PTR:
523 1.1.1.3 christos c_val_print_ptr (type, valaddr, embedded_offset, stream, recurse,
524 1.1 christos original_value, options);
525 1.1 christos break;
526 1.1 christos
527 1.1.1.3 christos case TYPE_CODE_UNION:
528 1.1.1.3 christos c_val_print_union (type, valaddr, embedded_offset, address, stream,
529 1.1.1.3 christos recurse, original_value, options);
530 1.1 christos break;
531 1.1.1.3 christos
532 1.1.1.3 christos case TYPE_CODE_STRUCT:
533 1.1.1.3 christos c_val_print_struct (type, valaddr, embedded_offset, address, stream,
534 1.1 christos recurse, original_value, options);
535 1.1 christos break;
536 1.1 christos
537 1.1.1.3 christos case TYPE_CODE_INT:
538 1.1.1.3 christos c_val_print_int (type, unresolved_type, valaddr, embedded_offset, stream,
539 1.1 christos original_value, options);
540 1.1 christos break;
541 1.1 christos
542 1.1.1.3 christos case TYPE_CODE_MEMBERPTR:
543 1.1.1.3 christos c_val_print_memberptr (type, valaddr, embedded_offset, address, stream,
544 1.1.1.3 christos recurse, original_value, options);
545 1.1 christos break;
546 1.1 christos
547 1.1.1.4 christos case TYPE_CODE_REF:
548 1.1 christos case TYPE_CODE_RVALUE_REF:
549 1.1 christos case TYPE_CODE_ENUM:
550 1.1 christos case TYPE_CODE_FLAGS:
551 1.1 christos case TYPE_CODE_FUNC:
552 1.1 christos case TYPE_CODE_METHOD:
553 1.1 christos case TYPE_CODE_BOOL:
554 1.1 christos case TYPE_CODE_RANGE:
555 1.1 christos case TYPE_CODE_FLT:
556 1.1 christos case TYPE_CODE_DECFLOAT:
557 1.1 christos case TYPE_CODE_VOID:
558 1.1 christos case TYPE_CODE_ERROR:
559 1.1 christos case TYPE_CODE_UNDEF:
560 1.1 christos case TYPE_CODE_COMPLEX:
561 1.1 christos case TYPE_CODE_CHAR:
562 1.1.1.4 christos default:
563 1.1 christos generic_val_print (type, embedded_offset, address,
564 1.1 christos stream, recurse, original_value, options,
565 1.1 christos &c_decorations);
566 1.1 christos break;
567 1.1 christos }
568 1.1 christos gdb_flush (stream);
569 1.1 christos }
570 1.1 christos
571 1.1 christos void
573 1.1 christos c_value_print (struct value *val, struct ui_file *stream,
574 1.1 christos const struct value_print_options *options)
575 1.1.1.3 christos {
576 1.1.1.3 christos struct type *type, *real_type, *val_type;
577 1.1 christos int full, using_enc;
578 1.1 christos LONGEST top;
579 1.1 christos struct value_print_options opts = *options;
580 1.1 christos
581 1.1 christos opts.deref_ref = 1;
582 1.1 christos
583 1.1 christos /* If it is a pointer, indicate what it points to.
584 1.1 christos
585 1.1 christos Print type also if it is a reference.
586 1.1 christos
587 1.1 christos C++: if it is a member pointer, we will take care
588 1.1 christos of that when we print it. */
589 1.1 christos
590 1.1 christos /* Preserve the original type before stripping typedefs. We prefer
591 1.1 christos to pass down the original type when possible, but for local
592 1.1 christos checks it is better to look past the typedefs. */
593 1.1 christos val_type = value_type (val);
594 1.1.1.4 christos type = check_typedef (val_type);
595 1.1 christos
596 1.1 christos if (TYPE_CODE (type) == TYPE_CODE_PTR || TYPE_IS_REFERENCE (type))
597 1.1 christos {
598 1.1 christos /* Hack: remove (char *) for char strings. Their
599 1.1 christos type is indicated by the quoted string anyway.
600 1.1 christos (Don't use c_textual_element_type here; quoted strings
601 1.1 christos are always exactly (char *), (wchar_t *), or the like. */
602 1.1 christos if (TYPE_CODE (val_type) == TYPE_CODE_PTR
603 1.1 christos && TYPE_NAME (val_type) == NULL
604 1.1 christos && TYPE_NAME (TYPE_TARGET_TYPE (val_type)) != NULL
605 1.1 christos && (strcmp (TYPE_NAME (TYPE_TARGET_TYPE (val_type)),
606 1.1 christos "char") == 0
607 1.1 christos || textual_name (TYPE_NAME (TYPE_TARGET_TYPE (val_type)))))
608 1.1 christos {
609 1.1 christos /* Print nothing. */
610 1.1.1.2 christos }
611 1.1 christos else if (options->objectprint
612 1.1.1.4 christos && (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_STRUCT))
613 1.1.1.4 christos {
614 1.1 christos int is_ref = TYPE_IS_REFERENCE (type);
615 1.1 christos enum type_code refcode = TYPE_CODE_UNDEF;
616 1.1.1.4 christos
617 1.1.1.4 christos if (is_ref)
618 1.1.1.4 christos {
619 1.1.1.4 christos val = value_addr (val);
620 1.1 christos refcode = TYPE_CODE (type);
621 1.1 christos }
622 1.1 christos
623 1.1 christos /* Pointer to class, check real type of object. */
624 1.1 christos fprintf_filtered (stream, "(");
625 1.1.1.3 christos
626 1.1 christos if (value_entirely_available (val))
627 1.1 christos {
628 1.1 christos real_type = value_rtti_indirect_type (val, &full, &top,
629 1.1 christos &using_enc);
630 1.1 christos if (real_type)
631 1.1 christos {
632 1.1 christos /* RTTI entry found. */
633 1.1 christos type = real_type;
634 1.1 christos
635 1.1 christos /* Need to adjust pointer value. */
636 1.1 christos val = value_from_pointer (real_type,
637 1.1 christos value_as_address (val) - top);
638 1.1 christos
639 1.1 christos /* Note: When we look up RTTI entries, we don't get
640 1.1 christos any information on const or volatile
641 1.1 christos attributes. */
642 1.1.1.3 christos }
643 1.1.1.3 christos }
644 1.1.1.3 christos
645 1.1.1.4 christos if (is_ref)
646 1.1.1.3 christos {
647 1.1.1.3 christos val = value_ref (value_ind (val), refcode);
648 1.1.1.3 christos type = value_type (val);
649 1.1.1.3 christos }
650 1.1 christos
651 1.1 christos type_print (type, "", stream, -1);
652 1.1 christos fprintf_filtered (stream, ") ");
653 1.1 christos val_type = type;
654 1.1 christos }
655 1.1 christos else
656 1.1 christos {
657 1.1 christos /* normal case */
658 1.1 christos fprintf_filtered (stream, "(");
659 1.1 christos type_print (value_type (val), "", stream, -1);
660 1.1 christos fprintf_filtered (stream, ") ");
661 1.1 christos }
662 1.1 christos }
663 1.1 christos
664 1.1 christos if (!value_initialized (val))
665 1.1.1.2 christos fprintf_filtered (stream, " [uninitialized] ");
666 1.1 christos
667 1.1 christos if (options->objectprint && (TYPE_CODE (type) == TYPE_CODE_STRUCT))
668 1.1 christos {
669 1.1 christos /* Attempt to determine real type of object. */
670 1.1 christos real_type = value_rtti_type (val, &full, &top, &using_enc);
671 1.1 christos if (real_type)
672 1.1 christos {
673 1.1 christos /* We have RTTI information, so use it. */
674 1.1 christos val = value_full_object (val, real_type,
675 1.1 christos full, top, using_enc);
676 1.1 christos fprintf_filtered (stream, "(%s%s) ",
677 1.1 christos TYPE_NAME (real_type),
678 1.1 christos full ? "" : _(" [incomplete object]"));
679 1.1 christos /* Print out object: enclosing type is same as real_type if
680 1.1.1.4 christos full. */
681 1.1 christos val_print (value_enclosing_type (val),
682 1.1 christos 0,
683 1.1 christos value_address (val), stream, 0,
684 1.1 christos val, &opts, current_language);
685 1.1 christos return;
686 1.1 christos /* Note: When we look up RTTI entries, we don't get any
687 1.1 christos information on const or volatile attributes. */
688 1.1 christos }
689 1.1 christos else if (type != check_typedef (value_enclosing_type (val)))
690 1.1 christos {
691 1.1 christos /* No RTTI information, so let's do our best. */
692 1.1 christos fprintf_filtered (stream, "(%s ?) ",
693 1.1.1.4 christos TYPE_NAME (value_enclosing_type (val)));
694 1.1 christos val_print (value_enclosing_type (val),
695 1.1 christos 0,
696 1.1 christos value_address (val), stream, 0,
697 1.1 christos val, &opts, current_language);
698 1.1 christos return;
699 1.1 christos }
700 1.1 christos /* Otherwise, we end up at the return outside this "if". */
701 1.1.1.4 christos }
702 1.1 christos
703 1.1 christos val_print (val_type,
704 1.1 christos value_embedded_offset (val),
705 1.1 christos value_address (val),
706 1.1 christos stream, 0,
707 val, &opts, current_language);
708 }
709