ada-valprint.c revision 1.11 1 1.1 christos /* Support for printing Ada values for GDB, the GNU debugger.
2 1.1 christos
3 1.11 christos Copyright (C) 1986-2024 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 <ctype.h>
21 1.11 christos #include "event-top.h"
22 1.11 christos #include "extract-store-integer.h"
23 1.1 christos #include "gdbtypes.h"
24 1.1 christos #include "expression.h"
25 1.1 christos #include "value.h"
26 1.1 christos #include "valprint.h"
27 1.1 christos #include "language.h"
28 1.1 christos #include "annotate.h"
29 1.1 christos #include "ada-lang.h"
30 1.8 christos #include "target-float.h"
31 1.9 christos #include "cli/cli-style.h"
32 1.9 christos #include "gdbarch.h"
33 1.1 christos
34 1.9 christos static int print_field_values (struct value *, struct value *,
35 1.1 christos struct ui_file *, int,
36 1.1 christos const struct value_print_options *,
37 1.9 christos int, const struct language_defn *);
38 1.9 christos
39 1.1 christos
40 1.1 christos
42 1.1 christos /* Assuming TYPE is a simple array type, prints its lower bound on STREAM,
43 1.1 christos if non-standard (i.e., other than 1 for numbers, other than lower bound
44 1.1 christos of index type for enumerated type). Returns 1 if something printed,
45 1.1 christos otherwise 0. */
46 1.1 christos
47 1.1 christos static int
48 1.1 christos print_optional_low_bound (struct ui_file *stream, struct type *type,
49 1.1 christos const struct value_print_options *options)
50 1.1 christos {
51 1.1 christos struct type *index_type;
52 1.1 christos LONGEST low_bound;
53 1.1 christos LONGEST high_bound;
54 1.1 christos
55 1.1 christos if (options->print_array_indexes)
56 1.1 christos return 0;
57 1.1 christos
58 1.1 christos if (!get_array_bounds (type, &low_bound, &high_bound))
59 1.1 christos return 0;
60 1.1 christos
61 1.1 christos /* If this is an empty array, then don't print the lower bound.
62 1.1 christos That would be confusing, because we would print the lower bound,
63 1.1 christos followed by... nothing! */
64 1.1 christos if (low_bound > high_bound)
65 1.1 christos return 0;
66 1.9 christos
67 1.1 christos index_type = type->index_type ();
68 1.9 christos
69 1.1 christos while (index_type->code () == TYPE_CODE_RANGE)
70 1.1 christos {
71 1.10 christos /* We need to know what the base type is, in order to do the
72 1.10 christos appropriate check below. Otherwise, if this is a subrange
73 1.10 christos of an enumerated type, where the underlying value of the
74 1.10 christos first element is typically 0, we might test the low bound
75 1.10 christos against the wrong value. */
76 1.1 christos index_type = index_type->target_type ();
77 1.1 christos }
78 1.8 christos
79 1.9 christos /* Don't print the lower bound if it's the default one. */
80 1.1 christos switch (index_type->code ())
81 1.1 christos {
82 1.8 christos case TYPE_CODE_BOOL:
83 1.1 christos case TYPE_CODE_CHAR:
84 1.1 christos if (low_bound == 0)
85 1.1 christos return 0;
86 1.1 christos break;
87 1.9 christos case TYPE_CODE_ENUM:
88 1.1 christos if (low_bound == 0)
89 1.10 christos return 0;
90 1.1 christos low_bound = index_type->field (low_bound).loc_enumval ();
91 1.1 christos break;
92 1.1 christos case TYPE_CODE_UNDEF:
93 1.11 christos index_type = NULL;
94 1.1 christos [[fallthrough]];
95 1.1 christos default:
96 1.1 christos if (low_bound == 1)
97 1.1 christos return 0;
98 1.1 christos break;
99 1.1 christos }
100 1.1 christos
101 1.10 christos ada_print_scalar (index_type, low_bound, stream);
102 1.1 christos gdb_printf (stream, " => ");
103 1.1 christos return 1;
104 1.1 christos }
105 1.1 christos
106 1.9 christos /* Version of val_print_array_elements for GNAT-style packed arrays.
107 1.9 christos Prints elements of packed array of type TYPE from VALADDR on
108 1.9 christos STREAM. Formats according to OPTIONS and separates with commas.
109 1.9 christos RECURSE is the recursion (nesting) level. TYPE must have been
110 1.1 christos decoded (as by ada_coerce_to_simple_array). */
111 1.1 christos
112 1.1 christos static void
113 1.9 christos val_print_packed_array_elements (struct type *type, const gdb_byte *valaddr,
114 1.1 christos int offset, struct ui_file *stream,
115 1.1 christos int recurse,
116 1.1 christos const struct value_print_options *options)
117 1.1 christos {
118 1.1 christos unsigned int i;
119 1.1 christos unsigned int things_printed = 0;
120 1.1 christos unsigned len;
121 1.11 christos struct type *elttype, *index_type;
122 1.1 christos unsigned long bitsize = type->field (0).bitsize ();
123 1.1 christos LONGEST low = 0;
124 1.10 christos
125 1.10 christos scoped_value_mark mark;
126 1.10 christos
127 1.9 christos elttype = type->target_type ();
128 1.1 christos index_type = type->index_type ();
129 1.1 christos
130 1.1 christos {
131 1.1 christos LONGEST high;
132 1.10 christos
133 1.1 christos if (!get_discrete_bounds (index_type, &low, &high))
134 1.9 christos len = 1;
135 1.8 christos else if (low > high)
136 1.10 christos {
137 1.10 christos /* The array length should normally be HIGH_POS - LOW_POS + 1.
138 1.10 christos But in Ada we allow LOW_POS to be greater than HIGH_POS for
139 1.10 christos empty arrays. In that situation, the array length is just zero,
140 1.9 christos not negative! */
141 1.8 christos len = 0;
142 1.9 christos }
143 1.9 christos else
144 1.1 christos len = high - low + 1;
145 1.1 christos }
146 1.9 christos
147 1.10 christos if (index_type->code () == TYPE_CODE_RANGE)
148 1.9 christos index_type = index_type->target_type ();
149 1.1 christos
150 1.1 christos i = 0;
151 1.1 christos annotate_array_section_begin (i, elttype);
152 1.1 christos
153 1.1 christos while (i < len && things_printed < options->print_max)
154 1.11 christos {
155 1.11 christos /* Both this outer loop and the inner loop that checks for
156 1.11 christos duplicates may allocate many values. To avoid using too much
157 1.11 christos memory, both spots release values as they work. */
158 1.11 christos scoped_value_mark outer_free_values;
159 1.1 christos
160 1.1 christos struct value *v0, *v1;
161 1.1 christos int i0;
162 1.1 christos
163 1.1 christos if (i != 0)
164 1.1 christos {
165 1.1 christos if (options->prettyformat_arrays)
166 1.10 christos {
167 1.10 christos gdb_printf (stream, ",\n");
168 1.1 christos print_spaces (2 + 2 * recurse, stream);
169 1.1 christos }
170 1.1 christos else
171 1.10 christos {
172 1.1 christos gdb_printf (stream, ", ");
173 1.1 christos }
174 1.9 christos }
175 1.9 christos else if (options->prettyformat_arrays)
176 1.10 christos {
177 1.10 christos gdb_printf (stream, "\n");
178 1.9 christos print_spaces (2 + 2 * recurse, stream);
179 1.10 christos }
180 1.1 christos stream->wrap_here (2 + 2 * recurse);
181 1.1 christos maybe_print_array_index (index_type, i + low, stream, options);
182 1.1 christos
183 1.1 christos i0 = i;
184 1.1 christos v0 = ada_value_primitive_packed_val (NULL, valaddr + offset,
185 1.1 christos (i0 * bitsize) / HOST_CHAR_BIT,
186 1.1 christos (i0 * bitsize) % HOST_CHAR_BIT,
187 1.1 christos bitsize, elttype);
188 1.1 christos while (1)
189 1.11 christos {
190 1.11 christos /* Make sure to free any values in the inner loop. */
191 1.11 christos scoped_value_mark free_values;
192 1.1 christos
193 1.1 christos i += 1;
194 1.1 christos if (i >= len)
195 1.1 christos break;
196 1.1 christos v1 = ada_value_primitive_packed_val (NULL, valaddr + offset,
197 1.1 christos (i * bitsize) / HOST_CHAR_BIT,
198 1.1 christos (i * bitsize) % HOST_CHAR_BIT,
199 1.11 christos bitsize, elttype);
200 1.11 christos if (check_typedef (v0->type ())->length ()
201 1.5 christos != check_typedef (v1->type ())->length ())
202 1.11 christos break;
203 1.11 christos if (!v0->contents_eq (v0->embedded_offset (),
204 1.11 christos v1, v1->embedded_offset (),
205 1.1 christos check_typedef (v0->type ())->length ()))
206 1.1 christos break;
207 1.1 christos }
208 1.1 christos
209 1.1 christos if (i - i0 > options->repeat_count_threshold)
210 1.1 christos {
211 1.1 christos struct value_print_options opts = *options;
212 1.11 christos
213 1.9 christos opts.deref_ref = false;
214 1.1 christos common_val_print (v0, stream, recurse + 1, &opts, current_language);
215 1.10 christos annotate_elt_rep (i - i0);
216 1.10 christos gdb_printf (stream, _(" %p[<repeats %u times>%p]"),
217 1.1 christos metadata_style.style ().ptr (), i - i0, nullptr);
218 1.1 christos annotate_elt_rep_end ();
219 1.1 christos
220 1.1 christos }
221 1.1 christos else
222 1.1 christos {
223 1.1 christos int j;
224 1.1 christos struct value_print_options opts = *options;
225 1.11 christos
226 1.1 christos opts.deref_ref = false;
227 1.1 christos for (j = i0; j < i; j += 1)
228 1.1 christos {
229 1.1 christos if (j > i0)
230 1.1 christos {
231 1.1 christos if (options->prettyformat_arrays)
232 1.10 christos {
233 1.10 christos gdb_printf (stream, ",\n");
234 1.1 christos print_spaces (2 + 2 * recurse, stream);
235 1.1 christos }
236 1.1 christos else
237 1.10 christos {
238 1.1 christos gdb_printf (stream, ", ");
239 1.10 christos }
240 1.1 christos stream->wrap_here (2 + 2 * recurse);
241 1.1 christos maybe_print_array_index (index_type, j + low,
242 1.1 christos stream, options);
243 1.9 christos }
244 1.9 christos common_val_print (v0, stream, recurse + 1, &opts,
245 1.1 christos current_language);
246 1.1 christos annotate_elt ();
247 1.1 christos }
248 1.1 christos }
249 1.1 christos things_printed += i - i0;
250 1.1 christos }
251 1.1 christos annotate_array_section_end ();
252 1.1 christos if (i < len)
253 1.10 christos {
254 1.1 christos gdb_printf (stream, "...");
255 1.1 christos }
256 1.1 christos }
257 1.1 christos
258 1.1 christos /* Print the character C on STREAM as part of the contents of a literal
259 1.1 christos string whose delimiter is QUOTER. TYPE_LEN is the length in bytes
260 1.1 christos of the character. */
261 1.1 christos
262 1.1 christos void
263 1.1 christos ada_emit_char (int c, struct type *type, struct ui_file *stream,
264 1.1 christos int quoter, int type_len)
265 1.1 christos {
266 1.1 christos /* If this character fits in the normal ASCII range, and is
267 1.1 christos a printable character, then print the character as if it was
268 1.1 christos an ASCII character, even if this is a wide character.
269 1.1 christos The UCHAR_MAX check is necessary because the isascii function
270 1.1 christos requires that its argument have a value of an unsigned char,
271 1.11 christos or EOF (EOF is obviously not printable). */
272 1.1 christos if (c <= UCHAR_MAX && isascii ((unsigned char)c) && isprint (c))
273 1.1 christos {
274 1.10 christos if (c == quoter && c == '"')
275 1.1 christos gdb_printf (stream, "\"\"");
276 1.10 christos else
277 1.1 christos gdb_printf (stream, "%c", c);
278 1.1 christos }
279 1.10 christos else
280 1.10 christos {
281 1.10 christos /* Follow GNAT's lead here and only use 6 digits for
282 1.10 christos wide_wide_character. */
283 1.10 christos gdb_printf (stream, "[\"%0*x\"]", std::min (6, type_len * 2), c);
284 1.1 christos }
285 1.1 christos }
286 1.1 christos
287 1.1 christos /* Character #I of STRING, given that TYPE_LEN is the size in bytes
288 1.1 christos of a character. */
289 1.1 christos
290 1.1 christos static int
291 1.1 christos char_at (const gdb_byte *string, int i, int type_len,
292 1.1 christos enum bfd_endian byte_order)
293 1.1 christos {
294 1.1 christos if (type_len == 1)
295 1.1 christos return string[i];
296 1.1 christos else
297 1.10 christos return (int) extract_unsigned_integer (string + type_len * i,
298 1.1 christos type_len, byte_order);
299 1.1 christos }
300 1.1 christos
301 1.1 christos /* Print a floating-point value of type TYPE, pointed to in GDB by
302 1.1 christos VALADDR, on STREAM. Use Ada formatting conventions: there must be
303 1.1 christos a decimal point, and at least one digit before and after the
304 1.1 christos point. We use the GNAT format for NaNs and infinities. */
305 1.1 christos
306 1.1 christos static void
307 1.1 christos ada_print_floating (const gdb_byte *valaddr, struct type *type,
308 1.1 christos struct ui_file *stream)
309 1.7 christos {
310 1.7 christos string_file tmp_stream;
311 1.7 christos
312 1.7 christos print_floating (valaddr, type, &tmp_stream);
313 1.10 christos
314 1.7 christos std::string s = tmp_stream.release ();
315 1.1 christos size_t skip_count = 0;
316 1.10 christos
317 1.10 christos /* Don't try to modify a result representing an error. */
318 1.10 christos if (s[0] == '<')
319 1.10 christos {
320 1.10 christos gdb_puts (s.c_str (), stream);
321 1.10 christos return;
322 1.10 christos }
323 1.1 christos
324 1.1 christos /* Modify for Ada rules. */
325 1.7 christos
326 1.7 christos size_t pos = s.find ("inf");
327 1.7 christos if (pos == std::string::npos)
328 1.7 christos pos = s.find ("Inf");
329 1.7 christos if (pos == std::string::npos)
330 1.7 christos pos = s.find ("INF");
331 1.7 christos if (pos != std::string::npos)
332 1.7 christos s.replace (pos, 3, "Inf");
333 1.7 christos
334 1.7 christos if (pos == std::string::npos)
335 1.7 christos {
336 1.7 christos pos = s.find ("nan");
337 1.7 christos if (pos == std::string::npos)
338 1.7 christos pos = s.find ("NaN");
339 1.7 christos if (pos == std::string::npos)
340 1.7 christos pos = s.find ("Nan");
341 1.7 christos if (pos != std::string::npos)
342 1.7 christos {
343 1.7 christos s[pos] = s[pos + 2] = 'N';
344 1.7 christos if (s[0] == '-')
345 1.1 christos skip_count = 1;
346 1.1 christos }
347 1.1 christos }
348 1.7 christos
349 1.7 christos if (pos == std::string::npos
350 1.7 christos && s.find ('.') == std::string::npos)
351 1.7 christos {
352 1.7 christos pos = s.find ('e');
353 1.10 christos if (pos == std::string::npos)
354 1.1 christos gdb_printf (stream, "%s.0", s.c_str ());
355 1.10 christos else
356 1.1 christos gdb_printf (stream, "%.*s.0%s", (int) pos, s.c_str (), &s[pos]);
357 1.1 christos }
358 1.10 christos else
359 1.1 christos gdb_printf (stream, "%s", &s[skip_count]);
360 1.1 christos }
361 1.1 christos
362 1.1 christos void
363 1.1 christos ada_printchar (int c, struct type *type, struct ui_file *stream)
364 1.10 christos {
365 1.10 christos gdb_puts ("'", stream);
366 1.10 christos ada_emit_char (c, type, stream, '\'', type->length ());
367 1.1 christos gdb_puts ("'", stream);
368 1.1 christos }
369 1.1 christos
370 1.1 christos /* [From print_type_scalar in typeprint.c]. Print VAL on STREAM in a
371 1.1 christos form appropriate for TYPE, if non-NULL. If TYPE is NULL, print VAL
372 1.1 christos like a default signed integer. */
373 1.1 christos
374 1.1 christos void
375 1.1 christos ada_print_scalar (struct type *type, LONGEST val, struct ui_file *stream)
376 1.1 christos {
377 1.1 christos if (!type)
378 1.1 christos {
379 1.1 christos print_longest (stream, 'd', 0, val);
380 1.1 christos return;
381 1.1 christos }
382 1.1 christos
383 1.1 christos type = ada_check_typedef (type);
384 1.9 christos
385 1.1 christos switch (type->code ())
386 1.1 christos {
387 1.1 christos
388 1.11 christos case TYPE_CODE_ENUM:
389 1.11 christos {
390 1.11 christos std::optional<LONGEST> posn = discrete_position (type, val);
391 1.11 christos if (posn.has_value ())
392 1.9 christos fputs_styled (ada_enum_name (type->field (*posn).name ()),
393 1.11 christos variable_name_style.style (), stream);
394 1.1 christos else
395 1.11 christos print_longest (stream, 'd', 0, val);
396 1.1 christos }
397 1.1 christos break;
398 1.1 christos
399 1.10 christos case TYPE_CODE_INT:
400 1.1 christos print_longest (stream, type->is_unsigned () ? 'u' : 'd', 0, val);
401 1.1 christos break;
402 1.1 christos
403 1.10 christos case TYPE_CODE_CHAR:
404 1.1 christos current_language->printchar (val, type, stream);
405 1.1 christos break;
406 1.1 christos
407 1.10 christos case TYPE_CODE_BOOL:
408 1.1 christos gdb_printf (stream, val ? "true" : "false");
409 1.1 christos break;
410 1.1 christos
411 1.10 christos case TYPE_CODE_RANGE:
412 1.1 christos ada_print_scalar (type->target_type (), val, stream);
413 1.1 christos return;
414 1.1 christos
415 1.1 christos case TYPE_CODE_UNDEF:
416 1.1 christos case TYPE_CODE_PTR:
417 1.1 christos case TYPE_CODE_ARRAY:
418 1.1 christos case TYPE_CODE_STRUCT:
419 1.1 christos case TYPE_CODE_UNION:
420 1.1 christos case TYPE_CODE_FUNC:
421 1.1 christos case TYPE_CODE_FLT:
422 1.1 christos case TYPE_CODE_VOID:
423 1.1 christos case TYPE_CODE_SET:
424 1.1 christos case TYPE_CODE_STRING:
425 1.1 christos case TYPE_CODE_ERROR:
426 1.1 christos case TYPE_CODE_MEMBERPTR:
427 1.1 christos case TYPE_CODE_METHODPTR:
428 1.1 christos case TYPE_CODE_METHOD:
429 1.1 christos case TYPE_CODE_REF:
430 1.1 christos warning (_("internal error: unhandled type in ada_print_scalar"));
431 1.1 christos break;
432 1.1 christos
433 1.1 christos default:
434 1.1 christos error (_("Invalid type code in symbol table."));
435 1.1 christos }
436 1.1 christos }
437 1.1 christos
438 1.1 christos /* Print the character string STRING, printing at most LENGTH characters.
439 1.1 christos Printing stops early if the number hits print_max; repeat counts
440 1.1 christos are printed as appropriate. Print ellipses at the end if we
441 1.1 christos had to stop before printing LENGTH characters, or if FORCE_ELLIPSES.
442 1.1 christos TYPE_LEN is the length (1 or 2) of the character type. */
443 1.1 christos
444 1.1 christos static void
445 1.1 christos printstr (struct ui_file *stream, struct type *elttype, const gdb_byte *string,
446 1.1 christos unsigned int length, int force_ellipses, int type_len,
447 1.1 christos const struct value_print_options *options)
448 1.9 christos {
449 1.1 christos enum bfd_endian byte_order = type_byte_order (elttype);
450 1.1 christos unsigned int i;
451 1.1 christos unsigned int things_printed = 0;
452 1.1 christos int in_quotes = 0;
453 1.1 christos int need_comma = 0;
454 1.1 christos
455 1.1 christos if (length == 0)
456 1.10 christos {
457 1.1 christos gdb_puts ("\"\"", stream);
458 1.1 christos return;
459 1.1 christos }
460 1.11 christos
461 1.11 christos unsigned int print_max_chars = get_print_max_chars (options);
462 1.1 christos for (i = 0; i < length && things_printed < print_max_chars; i += 1)
463 1.1 christos {
464 1.10 christos /* Position of the character we are examining
465 1.1 christos to see whether it is repeated. */
466 1.1 christos unsigned int rep1;
467 1.1 christos /* Number of repetitions we have detected so far. */
468 1.1 christos unsigned int reps;
469 1.1 christos
470 1.1 christos QUIT;
471 1.1 christos
472 1.1 christos if (need_comma)
473 1.10 christos {
474 1.1 christos gdb_puts (", ", stream);
475 1.1 christos need_comma = 0;
476 1.1 christos }
477 1.1 christos
478 1.1 christos rep1 = i + 1;
479 1.1 christos reps = 1;
480 1.1 christos while (rep1 < length
481 1.1 christos && char_at (string, rep1, type_len, byte_order)
482 1.1 christos == char_at (string, i, type_len, byte_order))
483 1.1 christos {
484 1.1 christos rep1 += 1;
485 1.1 christos reps += 1;
486 1.1 christos }
487 1.1 christos
488 1.1 christos if (reps > options->repeat_count_threshold)
489 1.1 christos {
490 1.1 christos if (in_quotes)
491 1.10 christos {
492 1.1 christos gdb_puts ("\", ", stream);
493 1.1 christos in_quotes = 0;
494 1.10 christos }
495 1.1 christos gdb_puts ("'", stream);
496 1.1 christos ada_emit_char (char_at (string, i, type_len, byte_order),
497 1.10 christos elttype, stream, '\'', type_len);
498 1.10 christos gdb_puts ("'", stream);
499 1.10 christos gdb_printf (stream, _(" %p[<repeats %u times>%p]"),
500 1.1 christos metadata_style.style ().ptr (), reps, nullptr);
501 1.1 christos i = rep1 - 1;
502 1.1 christos things_printed += options->repeat_count_threshold;
503 1.1 christos need_comma = 1;
504 1.1 christos }
505 1.1 christos else
506 1.1 christos {
507 1.1 christos if (!in_quotes)
508 1.10 christos {
509 1.1 christos gdb_puts ("\"", stream);
510 1.1 christos in_quotes = 1;
511 1.1 christos }
512 1.1 christos ada_emit_char (char_at (string, i, type_len, byte_order),
513 1.1 christos elttype, stream, '"', type_len);
514 1.1 christos things_printed += 1;
515 1.1 christos }
516 1.1 christos }
517 1.1 christos
518 1.1 christos /* Terminate the quotes if necessary. */
519 1.10 christos if (in_quotes)
520 1.1 christos gdb_puts ("\"", stream);
521 1.1 christos
522 1.10 christos if (force_ellipses || i < length)
523 1.1 christos gdb_puts ("...", stream);
524 1.1 christos }
525 1.1 christos
526 1.1 christos void
527 1.1 christos ada_printstr (struct ui_file *stream, struct type *type,
528 1.1 christos const gdb_byte *string, unsigned int length,
529 1.1 christos const char *encoding, int force_ellipses,
530 1.1 christos const struct value_print_options *options)
531 1.10 christos {
532 1.1 christos printstr (stream, type, string, length, force_ellipses, type->length (),
533 1.1 christos options);
534 1.1 christos }
535 1.1 christos
536 1.9 christos static int
537 1.9 christos print_variant_part (struct value *value, int field_num,
538 1.1 christos struct value *outer_value,
539 1.1 christos struct ui_file *stream, int recurse,
540 1.1 christos const struct value_print_options *options,
541 1.1 christos int comma_needed,
542 1.1 christos const struct language_defn *language)
543 1.11 christos {
544 1.9 christos struct type *type = value->type ();
545 1.9 christos struct type *var_type = type->field (field_num).type ();
546 1.1 christos int which = ada_which_variant_applies (var_type, outer_value);
547 1.1 christos
548 1.1 christos if (which < 0)
549 1.9 christos return 0;
550 1.9 christos
551 1.9 christos struct value *variant_field = value_field (value, field_num);
552 1.9 christos struct value *active_component = value_field (variant_field, which);
553 1.9 christos return print_field_values (active_component, outer_value, stream, recurse,
554 1.9 christos options, comma_needed, language);
555 1.9 christos }
556 1.9 christos
557 1.9 christos /* Print out fields of VALUE.
558 1.9 christos
559 1.9 christos STREAM, RECURSE, and OPTIONS have the same meanings as in
560 1.9 christos ada_print_value and ada_value_print.
561 1.9 christos
562 1.9 christos OUTER_VALUE gives the enclosing record (used to get discriminant
563 1.1 christos values when printing variant parts).
564 1.1 christos
565 1.1 christos COMMA_NEEDED is 1 if fields have been printed at the current recursion
566 1.1 christos level, so that a comma is needed before any field printed by this
567 1.1 christos call.
568 1.1 christos
569 1.1 christos Returns 1 if COMMA_NEEDED or any fields were printed. */
570 1.1 christos
571 1.9 christos static int
572 1.9 christos print_field_values (struct value *value, struct value *outer_value,
573 1.1 christos struct ui_file *stream, int recurse,
574 1.1 christos const struct value_print_options *options,
575 1.1 christos int comma_needed,
576 1.1 christos const struct language_defn *language)
577 1.1 christos {
578 1.1 christos int i, len;
579 1.11 christos
580 1.9 christos struct type *type = value->type ();
581 1.1 christos len = type->num_fields ();
582 1.1 christos
583 1.1 christos for (i = 0; i < len; i += 1)
584 1.1 christos {
585 1.1 christos if (ada_is_ignored_field (type, i))
586 1.1 christos continue;
587 1.1 christos
588 1.1 christos if (ada_is_wrapper_field (type, i))
589 1.9 christos {
590 1.9 christos struct value *field_val = ada_value_primitive_field (value, 0,
591 1.1 christos i, type);
592 1.9 christos comma_needed =
593 1.9 christos print_field_values (field_val, field_val,
594 1.9 christos stream, recurse, options,
595 1.1 christos comma_needed, language);
596 1.1 christos continue;
597 1.1 christos }
598 1.1 christos else if (ada_is_variant_part (type, i))
599 1.1 christos {
600 1.9 christos comma_needed =
601 1.9 christos print_variant_part (value, i, outer_value, stream, recurse,
602 1.1 christos options, comma_needed, language);
603 1.1 christos continue;
604 1.1 christos }
605 1.1 christos
606 1.10 christos if (comma_needed)
607 1.1 christos gdb_printf (stream, ", ");
608 1.1 christos comma_needed = 1;
609 1.1 christos
610 1.1 christos if (options->prettyformat)
611 1.10 christos {
612 1.10 christos gdb_printf (stream, "\n");
613 1.1 christos print_spaces (2 + 2 * recurse, stream);
614 1.1 christos }
615 1.1 christos else
616 1.10 christos {
617 1.1 christos stream->wrap_here (2 + 2 * recurse);
618 1.1 christos }
619 1.9 christos
620 1.10 christos annotate_field_begin (type->field (i).type ());
621 1.10 christos gdb_printf (stream, "%.*s",
622 1.10 christos ada_name_prefix_len (type->field (i).name ()),
623 1.1 christos type->field (i).name ());
624 1.10 christos annotate_field_name_end ();
625 1.1 christos gdb_puts (" => ", stream);
626 1.1 christos annotate_field_value ();
627 1.11 christos
628 1.1 christos if (type->field (i).is_packed ())
629 1.1 christos {
630 1.1 christos /* Bitfields require special handling, especially due to byte
631 1.11 christos order problems. */
632 1.1 christos if (type->field (i).is_ignored ())
633 1.9 christos {
634 1.9 christos fputs_styled (_("<optimized out or zero length>"),
635 1.1 christos metadata_style.style (), stream);
636 1.1 christos }
637 1.1 christos else
638 1.7 christos {
639 1.10 christos struct value *v;
640 1.11 christos int bit_pos = type->field (i).loc_bitpos ();
641 1.1 christos int bit_size = type->field (i).bitsize ();
642 1.1 christos struct value_print_options opts;
643 1.1 christos
644 1.9 christos v = ada_value_primitive_packed_val
645 1.9 christos (value, nullptr,
646 1.1 christos bit_pos / HOST_CHAR_BIT,
647 1.9 christos bit_pos % HOST_CHAR_BIT,
648 1.1 christos bit_size, type->field (i).type ());
649 1.11 christos opts = *options;
650 1.9 christos opts.deref_ref = false;
651 1.1 christos common_val_print (v, stream, recurse + 1, &opts, language);
652 1.1 christos }
653 1.1 christos }
654 1.1 christos else
655 1.1 christos {
656 1.1 christos struct value_print_options opts = *options;
657 1.11 christos
658 1.9 christos opts.deref_ref = false;
659 1.9 christos
660 1.9 christos struct value *v = value_field (value, i);
661 1.1 christos common_val_print (v, stream, recurse + 1, &opts, language);
662 1.1 christos }
663 1.1 christos annotate_field_end ();
664 1.1 christos }
665 1.1 christos
666 1.1 christos return comma_needed;
667 1.1 christos }
668 1.1 christos
669 1.1 christos /* Implement Ada val_print'ing for the case where TYPE is
670 1.1 christos a TYPE_CODE_ARRAY of characters. */
671 1.1 christos
672 1.1 christos static void
673 1.9 christos ada_val_print_string (struct type *type, const gdb_byte *valaddr,
674 1.1 christos int offset_aligned,
675 1.1 christos struct ui_file *stream, int recurse,
676 1.1 christos const struct value_print_options *options)
677 1.9 christos {
678 1.10 christos enum bfd_endian byte_order = type_byte_order (type);
679 1.1 christos struct type *elttype = type->target_type ();
680 1.1 christos unsigned int eltlen;
681 1.1 christos unsigned int len;
682 1.1 christos
683 1.1 christos /* We know that ELTTYPE cannot possibly be null, because we assume
684 1.1 christos that we're called only when TYPE is a string-like type.
685 1.1 christos Similarly, the size of ELTTYPE should also be non-null, since
686 1.1 christos it's a character-like type. */
687 1.10 christos gdb_assert (elttype != NULL);
688 1.1 christos gdb_assert (elttype->length () != 0);
689 1.10 christos
690 1.10 christos eltlen = elttype->length ();
691 1.1 christos len = type->length () / eltlen;
692 1.1 christos
693 1.1 christos /* If requested, look for the first null char and only print
694 1.1 christos elements up to it. */
695 1.1 christos if (options->stop_print_at_null)
696 1.11 christos {
697 1.1 christos unsigned int print_max_chars = get_print_max_chars (options);
698 1.1 christos int temp_len;
699 1.1 christos
700 1.1 christos /* Look for a NULL char. */
701 1.1 christos for (temp_len = 0;
702 1.11 christos (temp_len < len
703 1.1 christos && temp_len < print_max_chars
704 1.1 christos && char_at (valaddr + offset_aligned,
705 1.1 christos temp_len, eltlen, byte_order) != 0);
706 1.1 christos temp_len += 1);
707 1.1 christos len = temp_len;
708 1.1 christos }
709 1.1 christos
710 1.1 christos printstr (stream, elttype, valaddr + offset_aligned, len, 0,
711 1.1 christos eltlen, options);
712 1.1 christos }
713 1.9 christos
714 1.9 christos /* Implement Ada value_print'ing for the case where TYPE is a
715 1.1 christos TYPE_CODE_PTR. */
716 1.1 christos
717 1.9 christos static void
718 1.9 christos ada_value_print_ptr (struct value *val,
719 1.9 christos struct ui_file *stream, int recurse,
720 1.1 christos const struct value_print_options *options)
721 1.10 christos {
722 1.11 christos if (!options->format
723 1.11 christos && val->type ()->target_type ()->code () == TYPE_CODE_INT
724 1.10 christos && val->type ()->target_type ()->length () == 0)
725 1.10 christos {
726 1.10 christos gdb_puts ("null", stream);
727 1.10 christos return;
728 1.10 christos }
729 1.9 christos
730 1.1 christos common_val_print (val, stream, recurse, options, language_def (language_c));
731 1.11 christos
732 1.1 christos struct type *type = ada_check_typedef (val->type ());
733 1.1 christos if (ada_is_tag_type (type))
734 1.9 christos {
735 1.1 christos gdb::unique_xmalloc_ptr<char> name = ada_tag_name (val);
736 1.1 christos
737 1.10 christos if (name != NULL)
738 1.1 christos gdb_printf (stream, " (%s)", name.get ());
739 1.1 christos }
740 1.1 christos }
741 1.1 christos
742 1.1 christos /* Implement Ada val_print'ing for the case where TYPE is
743 1.1 christos a TYPE_CODE_INT or TYPE_CODE_RANGE. */
744 1.1 christos
745 1.9 christos static void
746 1.9 christos ada_value_print_num (struct value *val, struct ui_file *stream, int recurse,
747 1.1 christos const struct value_print_options *options)
748 1.11 christos {
749 1.11 christos struct type *type = ada_check_typedef (val->type ());
750 1.9 christos const gdb_byte *valaddr = val->contents_for_printing ().data ();
751 1.10 christos
752 1.10 christos if (type->code () == TYPE_CODE_RANGE
753 1.10 christos && (type->target_type ()->code () == TYPE_CODE_ENUM
754 1.10 christos || type->target_type ()->code () == TYPE_CODE_BOOL
755 1.9 christos || type->target_type ()->code () == TYPE_CODE_CHAR))
756 1.9 christos {
757 1.9 christos /* For enum-valued ranges, we want to recurse, because we'll end
758 1.9 christos up printing the constant's name rather than its numeric
759 1.11 christos value. Character and fixed-point types are also printed
760 1.10 christos differently, so recurse for those as well. */
761 1.9 christos struct type *target_type = type->target_type ();
762 1.9 christos val = value_cast (target_type, val);
763 1.9 christos common_val_print (val, stream, recurse + 1, options,
764 1.1 christos language_def (language_ada));
765 1.1 christos return;
766 1.1 christos }
767 1.1 christos else
768 1.1 christos {
769 1.1 christos int format = (options->format ? options->format
770 1.1 christos : options->output_format);
771 1.1 christos
772 1.1 christos if (format)
773 1.1 christos {
774 1.1 christos struct value_print_options opts = *options;
775 1.1 christos
776 1.9 christos opts.format = format;
777 1.1 christos value_print_scalar_formatted (val, &opts, 0, stream);
778 1.1 christos }
779 1.1 christos else if (ada_is_system_address_type (type))
780 1.1 christos {
781 1.1 christos /* FIXME: We want to print System.Address variables using
782 1.1 christos the same format as for any access type. But for some
783 1.1 christos reason GNAT encodes the System.Address type as an int,
784 1.1 christos so we have to work-around this deficiency by handling
785 1.1 christos System.Address values as a special case. */
786 1.10 christos
787 1.1 christos struct gdbarch *gdbarch = type->arch ();
788 1.9 christos struct type *ptr_type = builtin_type (gdbarch)->builtin_data_ptr;
789 1.1 christos CORE_ADDR addr = extract_typed_address (valaddr, ptr_type);
790 1.10 christos
791 1.1 christos gdb_printf (stream, "(");
792 1.10 christos type_print (type, "", stream, -1);
793 1.10 christos gdb_printf (stream, ") ");
794 1.1 christos gdb_puts (paddress (gdbarch, addr), stream);
795 1.1 christos }
796 1.1 christos else
797 1.9 christos {
798 1.1 christos value_print_scalar_formatted (val, options, 0, stream);
799 1.1 christos if (ada_is_character_type (type))
800 1.1 christos {
801 1.1 christos LONGEST c;
802 1.10 christos
803 1.9 christos gdb_puts (" ", stream);
804 1.1 christos c = unpack_long (type, valaddr);
805 1.1 christos ada_printchar (c, type, stream);
806 1.1 christos }
807 1.1 christos }
808 1.1 christos return;
809 1.1 christos }
810 1.1 christos }
811 1.1 christos
812 1.1 christos /* Implement Ada val_print'ing for the case where TYPE is
813 1.1 christos a TYPE_CODE_ENUM. */
814 1.1 christos
815 1.9 christos static void
816 1.9 christos ada_val_print_enum (struct value *value, struct ui_file *stream, int recurse,
817 1.1 christos const struct value_print_options *options)
818 1.1 christos {
819 1.1 christos LONGEST val;
820 1.1 christos
821 1.1 christos if (options->format)
822 1.9 christos {
823 1.1 christos value_print_scalar_formatted (value, options, 0, stream);
824 1.1 christos return;
825 1.1 christos }
826 1.11 christos
827 1.11 christos struct type *type = ada_check_typedef (value->type ());
828 1.9 christos const gdb_byte *valaddr = value->contents_for_printing ().data ();
829 1.9 christos int offset_aligned = ada_aligned_value_addr (type, valaddr) - valaddr;
830 1.1 christos
831 1.11 christos val = unpack_long (type, valaddr + offset_aligned);
832 1.11 christos std::optional<LONGEST> posn = discrete_position (type, val);
833 1.1 christos if (posn.has_value ())
834 1.11 christos {
835 1.1 christos const char *name = ada_enum_name (type->field (*posn).name ());
836 1.1 christos
837 1.10 christos if (name[0] == '\'')
838 1.10 christos gdb_printf (stream, "%ld %ps", (long) val,
839 1.10 christos styled_string (variable_name_style.style (),
840 1.1 christos name));
841 1.9 christos else
842 1.1 christos fputs_styled (name, variable_name_style.style (), stream);
843 1.1 christos }
844 1.1 christos else
845 1.1 christos print_longest (stream, 'd', 0, val);
846 1.1 christos }
847 1.9 christos
848 1.9 christos /* Implement Ada val_print'ing for the case where the type is
849 1.1 christos TYPE_CODE_STRUCT or TYPE_CODE_UNION. */
850 1.1 christos
851 1.9 christos static void
852 1.9 christos ada_val_print_struct_union (struct value *value,
853 1.9 christos struct ui_file *stream,
854 1.9 christos int recurse,
855 1.1 christos const struct value_print_options *options)
856 1.10 christos {
857 1.1 christos gdb_printf (stream, "(");
858 1.9 christos
859 1.9 christos if (print_field_values (value, value, stream, recurse, options,
860 1.1 christos 0, language_def (language_ada)) != 0
861 1.1 christos && options->prettyformat)
862 1.10 christos {
863 1.10 christos gdb_printf (stream, "\n");
864 1.1 christos print_spaces (2 * recurse, stream);
865 1.1 christos }
866 1.10 christos
867 1.1 christos gdb_printf (stream, ")");
868 1.1 christos }
869 1.9 christos
870 1.9 christos /* Implement Ada value_print'ing for the case where TYPE is a
871 1.1 christos TYPE_CODE_ARRAY. */
872 1.1 christos
873 1.9 christos static void
874 1.9 christos ada_value_print_array (struct value *val, struct ui_file *stream, int recurse,
875 1.1 christos const struct value_print_options *options)
876 1.11 christos {
877 1.9 christos struct type *type = ada_check_typedef (val->type ());
878 1.1 christos
879 1.1 christos /* For an array of characters, print with string syntax. */
880 1.1 christos if (ada_is_string_type (type)
881 1.1 christos && (options->format == 0 || options->format == 's'))
882 1.11 christos {
883 1.9 christos const gdb_byte *valaddr = val->contents_for_printing ().data ();
884 1.9 christos int offset_aligned = ada_aligned_value_addr (type, valaddr) - valaddr;
885 1.9 christos
886 1.1 christos ada_val_print_string (type, valaddr, offset_aligned, stream, recurse,
887 1.1 christos options);
888 1.1 christos return;
889 1.1 christos }
890 1.10 christos
891 1.1 christos gdb_printf (stream, "(");
892 1.10 christos print_optional_low_bound (stream, type, options);
893 1.11 christos
894 1.10 christos if (val->entirely_optimized_out ())
895 1.11 christos val_print_optimized_out (val, stream);
896 1.9 christos else if (type->field (0).bitsize () > 0)
897 1.11 christos {
898 1.9 christos const gdb_byte *valaddr = val->contents_for_printing ().data ();
899 1.9 christos int offset_aligned = ada_aligned_value_addr (type, valaddr) - valaddr;
900 1.9 christos val_print_packed_array_elements (type, valaddr, offset_aligned,
901 1.9 christos stream, recurse, options);
902 1.1 christos }
903 1.9 christos else
904 1.10 christos value_print_array_elements (val, stream, recurse, options, 0);
905 1.1 christos gdb_printf (stream, ")");
906 1.1 christos }
907 1.1 christos
908 1.1 christos /* Implement Ada val_print'ing for the case where TYPE is
909 1.1 christos a TYPE_CODE_REF. */
910 1.1 christos
911 1.1 christos static void
912 1.1 christos ada_val_print_ref (struct type *type, const gdb_byte *valaddr,
913 1.1 christos int offset, int offset_aligned, CORE_ADDR address,
914 1.7 christos struct ui_file *stream, int recurse,
915 1.9 christos struct value *original_value,
916 1.1 christos const struct value_print_options *options)
917 1.1 christos {
918 1.1 christos /* For references, the debugger is expected to print the value as
919 1.1 christos an address if DEREF_REF is null. But printing an address in place
920 1.1 christos of the object value would be confusing to an Ada programmer.
921 1.1 christos So, for Ada values, we print the actual dereferenced value
922 1.10 christos regardless. */
923 1.1 christos struct type *elttype = check_typedef (type->target_type ());
924 1.1 christos struct value *deref_val;
925 1.1 christos CORE_ADDR deref_val_int;
926 1.9 christos
927 1.1 christos if (elttype->code () == TYPE_CODE_UNDEF)
928 1.9 christos {
929 1.9 christos fputs_styled ("<ref to undefined type>", metadata_style.style (),
930 1.1 christos stream);
931 1.1 christos return;
932 1.1 christos }
933 1.1 christos
934 1.1 christos deref_val = coerce_ref_if_computed (original_value);
935 1.1 christos if (deref_val)
936 1.11 christos {
937 1.1 christos if (ada_is_tagged_type (deref_val->type (), 1))
938 1.1 christos deref_val = ada_tag_value_at_base_address (deref_val);
939 1.1 christos
940 1.9 christos common_val_print (deref_val, stream, recurse + 1, options,
941 1.1 christos language_def (language_ada));
942 1.1 christos return;
943 1.1 christos }
944 1.1 christos
945 1.1 christos deref_val_int = unpack_pointer (type, valaddr + offset_aligned);
946 1.1 christos if (deref_val_int == 0)
947 1.10 christos {
948 1.1 christos gdb_puts ("(null)", stream);
949 1.1 christos return;
950 1.1 christos }
951 1.1 christos
952 1.1 christos deref_val
953 1.1 christos = ada_value_ind (value_from_pointer (lookup_pointer_type (elttype),
954 1.11 christos deref_val_int));
955 1.1 christos if (ada_is_tagged_type (deref_val->type (), 1))
956 1.1 christos deref_val = ada_tag_value_at_base_address (deref_val);
957 1.11 christos
958 1.11 christos if (deref_val->lazy ())
959 1.7 christos deref_val->fetch_lazy ();
960 1.9 christos
961 1.9 christos common_val_print (deref_val, stream, recurse + 1,
962 1.1 christos options, language_def (language_ada));
963 1.1 christos }
964 1.9 christos
965 1.10 christos /* See the comment on ada_value_print. This function differs in that
966 1.10 christos it does not catch evaluation errors (leaving that to its
967 1.1 christos caller). */
968 1.10 christos
969 1.10 christos void
970 1.10 christos ada_value_print_inner (struct value *val, struct ui_file *stream, int recurse,
971 1.1 christos const struct value_print_options *options)
972 1.11 christos {
973 1.1 christos struct type *type = ada_check_typedef (val->type ());
974 1.1 christos
975 1.1 christos if (ada_is_array_descriptor_type (type)
976 1.9 christos || (ada_is_constrained_packed_array_type (type)
977 1.1 christos && type->code () != TYPE_CODE_PTR))
978 1.10 christos {
979 1.10 christos /* If this is a reference, coerce it now. This helps taking
980 1.10 christos care of the case where ADDRESS is meaningless because
981 1.10 christos original_value was not an lval. */
982 1.10 christos val = coerce_ref (val);
983 1.10 christos val = ada_get_decoded_value (val);
984 1.10 christos if (val == nullptr)
985 1.10 christos {
986 1.10 christos gdb_assert (type->code () == TYPE_CODE_TYPEDEF);
987 1.10 christos gdb_printf (stream, "0x0");
988 1.10 christos return;
989 1.1 christos }
990 1.10 christos }
991 1.10 christos else
992 1.1 christos val = ada_to_fixed_value (val);
993 1.11 christos
994 1.9 christos type = val->type ();
995 1.1 christos struct type *saved_type = type;
996 1.11 christos
997 1.11 christos const gdb_byte *valaddr = val->contents_for_printing ().data ();
998 1.9 christos CORE_ADDR address = val->address ();
999 1.10 christos gdb::array_view<const gdb_byte> view
1000 1.9 christos = gdb::make_array_view (valaddr, type->length ());
1001 1.9 christos type = ada_check_typedef (resolve_dynamic_type (type, view, address));
1002 1.9 christos if (type != saved_type)
1003 1.11 christos {
1004 1.11 christos val = val->copy ();
1005 1.9 christos val->deprecated_set_type (type);
1006 1.9 christos }
1007 1.10 christos
1008 1.10 christos if (is_fixed_point_type (type))
1009 1.10 christos type = type->fixed_point_type_base_type ();
1010 1.9 christos
1011 1.1 christos switch (type->code ())
1012 1.1 christos {
1013 1.9 christos default:
1014 1.9 christos common_val_print (val, stream, recurse, options,
1015 1.1 christos language_def (language_c));
1016 1.1 christos break;
1017 1.1 christos
1018 1.9 christos case TYPE_CODE_PTR:
1019 1.1 christos ada_value_print_ptr (val, stream, recurse, options);
1020 1.1 christos break;
1021 1.1 christos
1022 1.1 christos case TYPE_CODE_INT:
1023 1.9 christos case TYPE_CODE_RANGE:
1024 1.1 christos ada_value_print_num (val, stream, recurse, options);
1025 1.1 christos break;
1026 1.1 christos
1027 1.9 christos case TYPE_CODE_ENUM:
1028 1.1 christos ada_val_print_enum (val, stream, recurse, options);
1029 1.1 christos break;
1030 1.1 christos
1031 1.9 christos case TYPE_CODE_FLT:
1032 1.9 christos if (options->format)
1033 1.9 christos {
1034 1.9 christos common_val_print (val, stream, recurse, options,
1035 1.9 christos language_def (language_c));
1036 1.9 christos break;
1037 1.9 christos }
1038 1.9 christos
1039 1.1 christos ada_print_floating (valaddr, type, stream);
1040 1.1 christos break;
1041 1.1 christos
1042 1.1 christos case TYPE_CODE_UNION:
1043 1.9 christos case TYPE_CODE_STRUCT:
1044 1.1 christos ada_val_print_struct_union (val, stream, recurse, options);
1045 1.1 christos break;
1046 1.1 christos
1047 1.9 christos case TYPE_CODE_ARRAY:
1048 1.1 christos ada_value_print_array (val, stream, recurse, options);
1049 1.1 christos return;
1050 1.1 christos
1051 1.9 christos case TYPE_CODE_REF:
1052 1.9 christos ada_val_print_ref (type, valaddr, 0, 0,
1053 1.9 christos address, stream, recurse, val,
1054 1.1 christos options);
1055 1.1 christos break;
1056 1.1 christos }
1057 1.1 christos }
1058 1.1 christos
1059 1.1 christos void
1060 1.1 christos ada_value_print (struct value *val0, struct ui_file *stream,
1061 1.1 christos const struct value_print_options *options)
1062 1.1 christos {
1063 1.11 christos struct value *val = ada_to_fixed_value (val0);
1064 1.1 christos struct type *type = ada_check_typedef (val->type ());
1065 1.1 christos struct value_print_options opts;
1066 1.10 christos
1067 1.10 christos /* If it is a pointer, indicate what it points to; but not for
1068 1.10 christos "void *" pointers. */
1069 1.10 christos if (type->code () == TYPE_CODE_PTR
1070 1.10 christos && !(type->target_type ()->code () == TYPE_CODE_INT
1071 1.1 christos && type->target_type ()->length () == 0))
1072 1.1 christos {
1073 1.10 christos /* Hack: don't print (char *) for char strings. Their
1074 1.10 christos type is indicated by the quoted string anyway. */
1075 1.10 christos if (type->target_type ()->length () != sizeof (char)
1076 1.10 christos || type->target_type ()->code () != TYPE_CODE_INT
1077 1.1 christos || type->target_type ()->is_unsigned ())
1078 1.10 christos {
1079 1.1 christos gdb_printf (stream, "(");
1080 1.10 christos type_print (type, "", stream, -1);
1081 1.1 christos gdb_printf (stream, ") ");
1082 1.1 christos }
1083 1.1 christos }
1084 1.1 christos else if (ada_is_array_descriptor_type (type))
1085 1.1 christos {
1086 1.1 christos /* We do not print the type description unless TYPE is an array
1087 1.1 christos access type (this is encoded by the compiler as a typedef to
1088 1.9 christos a fat pointer - hence the check against TYPE_CODE_TYPEDEF). */
1089 1.10 christos if (type->code () == TYPE_CODE_TYPEDEF)
1090 1.10 christos {
1091 1.1 christos gdb_printf (stream, "(");
1092 1.10 christos type_print (type, "", stream, -1);
1093 1.1 christos gdb_printf (stream, ") ");
1094 1.1 christos }
1095 1.1 christos }
1096 1.1 christos
1097 1.11 christos opts = *options;
1098 1.9 christos opts.deref_ref = true;
1099 1.1 christos common_val_print (val, stream, 0, &opts, current_language);
1100 }
1101