Introduce f_value_print_innner
[deliverable/binutils-gdb.git] / gdb / ada-valprint.c
CommitLineData
4c4b4cd2 1/* Support for printing Ada values for GDB, the GNU debugger.
d56612af 2
b811d2c2 3 Copyright (C) 1986-2020 Free Software Foundation, Inc.
14f9c5c9 4
a9762ec7 5 This file is part of GDB.
14f9c5c9 6
a9762ec7
JB
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
14f9c5c9 11
a9762ec7
JB
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
14f9c5c9 16
a9762ec7
JB
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
14f9c5c9 19
14f9c5c9 20#include "defs.h"
12c89474 21#include <ctype.h>
4de283e4
TT
22#include "gdbtypes.h"
23#include "expression.h"
24#include "value.h"
4de283e4
TT
25#include "valprint.h"
26#include "language.h"
d55e5aa6 27#include "annotate.h"
4de283e4 28#include "ada-lang.h"
50eff16b 29#include "target-float.h"
7f6aba03 30#include "cli/cli-style.h"
cdc46a9f 31#include "gdbarch.h"
14f9c5c9 32
fc1a4b47 33static int print_field_values (struct type *, const gdb_byte *,
490f124f 34 int,
79a45b7d 35 struct ui_file *, int,
e8b24d9f 36 struct value *,
79a45b7d 37 const struct value_print_options *,
8e355c5d
JB
38 int, struct type *, int,
39 const struct language_defn *);
14f9c5c9
AS
40\f
41
4c4b4cd2 42/* Make TYPE unsigned if its range of values includes no negatives. */
d2e4a39e 43static void
4dc81987 44adjust_type_signedness (struct type *type)
14f9c5c9 45{
d2e4a39e 46 if (type != NULL && TYPE_CODE (type) == TYPE_CODE_RANGE
14f9c5c9 47 && TYPE_LOW_BOUND (type) >= 0)
876cecd0 48 TYPE_UNSIGNED (type) = 1;
d2e4a39e 49}
14f9c5c9 50
e936309c
JB
51/* Assuming TYPE is a simple array type, prints its lower bound on STREAM,
52 if non-standard (i.e., other than 1 for numbers, other than lower bound
53 of index type for enumerated type). Returns 1 if something printed,
54 otherwise 0. */
14f9c5c9 55
d2e4a39e 56static int
79a45b7d
TT
57print_optional_low_bound (struct ui_file *stream, struct type *type,
58 const struct value_print_options *options)
14f9c5c9
AS
59{
60 struct type *index_type;
df178451
PM
61 LONGEST low_bound;
62 LONGEST high_bound;
14f9c5c9 63
79a45b7d 64 if (options->print_array_indexes)
14f9c5c9 65 return 0;
e79af960 66
e936309c
JB
67 if (!get_array_bounds (type, &low_bound, &high_bound))
68 return 0;
69
70 /* If this is an empty array, then don't print the lower bound.
71 That would be confusing, because we would print the lower bound,
72 followed by... nothing! */
73 if (low_bound > high_bound)
14f9c5c9 74 return 0;
d2e4a39e 75
e79af960
JB
76 index_type = TYPE_INDEX_TYPE (type);
77
859cf5d1 78 while (TYPE_CODE (index_type) == TYPE_CODE_RANGE)
fd1b946e
JB
79 {
80 /* We need to know what the base type is, in order to do the
81 appropriate check below. Otherwise, if this is a subrange
82 of an enumerated type, where the underlying value of the
83 first element is typically 0, we might test the low bound
84 against the wrong value. */
85 index_type = TYPE_TARGET_TYPE (index_type);
86 }
87
e3861a03 88 /* Don't print the lower bound if it's the default one. */
d2e4a39e
AS
89 switch (TYPE_CODE (index_type))
90 {
690cc4eb 91 case TYPE_CODE_BOOL:
e3861a03 92 case TYPE_CODE_CHAR:
690cc4eb
PH
93 if (low_bound == 0)
94 return 0;
95 break;
d2e4a39e 96 case TYPE_CODE_ENUM:
14e75d8e 97 if (low_bound == TYPE_FIELD_ENUMVAL (index_type, 0))
d2e4a39e
AS
98 return 0;
99 break;
100 case TYPE_CODE_UNDEF:
7c964f07 101 index_type = NULL;
d2e4a39e
AS
102 /* FALL THROUGH */
103 default:
104 if (low_bound == 1)
105 return 0;
106 break;
107 }
14f9c5c9 108
df178451 109 ada_print_scalar (index_type, low_bound, stream);
14f9c5c9
AS
110 fprintf_filtered (stream, " => ");
111 return 1;
112}
113
114/* Version of val_print_array_elements for GNAT-style packed arrays.
115 Prints elements of packed array of type TYPE at bit offset
79a45b7d 116 BITOFFSET from VALADDR on STREAM. Formats according to OPTIONS and
4c4b4cd2 117 separates with commas. RECURSE is the recursion (nesting) level.
79a45b7d 118 TYPE must have been decoded (as by ada_coerce_to_simple_array). */
14f9c5c9
AS
119
120static void
fc1a4b47 121val_print_packed_array_elements (struct type *type, const gdb_byte *valaddr,
490f124f 122 int offset,
ebf56fd3 123 int bitoffset, struct ui_file *stream,
79a45b7d 124 int recurse,
e8b24d9f 125 struct value *val,
79a45b7d 126 const struct value_print_options *options)
14f9c5c9
AS
127{
128 unsigned int i;
129 unsigned int things_printed = 0;
130 unsigned len;
e79af960 131 struct type *elttype, *index_type;
14f9c5c9 132 unsigned long bitsize = TYPE_FIELD_BITSIZE (type, 0);
d2e4a39e 133 struct value *mark = value_mark ();
e79af960 134 LONGEST low = 0;
d2e4a39e 135
14f9c5c9 136 elttype = TYPE_TARGET_TYPE (type);
e79af960 137 index_type = TYPE_INDEX_TYPE (type);
14f9c5c9
AS
138
139 {
e79af960 140 LONGEST high;
04bafb1e 141 struct type *base_index_type;
5b4ee69b 142
262452ec 143 if (get_discrete_bounds (index_type, &low, &high) < 0)
14f9c5c9
AS
144 len = 1;
145 else
146 len = high - low + 1;
04bafb1e
XR
147
148 if (TYPE_CODE (index_type) == TYPE_CODE_RANGE)
149 base_index_type = TYPE_TARGET_TYPE (index_type);
150 else
151 base_index_type = index_type;
152
153 if (TYPE_CODE (base_index_type) == TYPE_CODE_ENUM)
154 {
155 LONGEST low_pos, high_pos;
156
157 /* Non-contiguous enumerations types can by used as index types
158 so the array length is computed from the positions of the
159 first and last literal in the enumeration type, and not from
160 the values of these literals. */
161
162 if (!discrete_position (base_index_type, low, &low_pos)
163 || !discrete_position (base_index_type, high, &high_pos))
164 {
165 warning (_("unable to get positions in array, use bounds instead"));
166 low_pos = low;
167 high_pos = high;
168 }
169
170 /* The array length should normally be HIGH_POS - LOW_POS + 1.
171 But in Ada we allow LOW_POS to be greater than HIGH_POS for
172 empty arrays. In that situation, the array length is just zero,
173 not negative! */
174
175 if (low_pos > high_pos)
176 len = 0;
177 else
178 len = high_pos - low_pos + 1;
179 }
14f9c5c9
AS
180 }
181
182 i = 0;
183 annotate_array_section_begin (i, elttype);
184
79a45b7d 185 while (i < len && things_printed < options->print_max)
14f9c5c9
AS
186 {
187 struct value *v0, *v1;
188 int i0;
189
190 if (i != 0)
191 {
2a998fc0 192 if (options->prettyformat_arrays)
14f9c5c9
AS
193 {
194 fprintf_filtered (stream, ",\n");
195 print_spaces_filtered (2 + 2 * recurse, stream);
196 }
197 else
198 {
199 fprintf_filtered (stream, ", ");
200 }
201 }
202 wrap_here (n_spaces (2 + 2 * recurse));
79a45b7d 203 maybe_print_array_index (index_type, i + low, stream, options);
14f9c5c9
AS
204
205 i0 = i;
490f124f 206 v0 = ada_value_primitive_packed_val (NULL, valaddr + offset,
14f9c5c9
AS
207 (i0 * bitsize) / HOST_CHAR_BIT,
208 (i0 * bitsize) % HOST_CHAR_BIT,
209 bitsize, elttype);
210 while (1)
211 {
212 i += 1;
213 if (i >= len)
214 break;
490f124f 215 v1 = ada_value_primitive_packed_val (NULL, valaddr + offset,
14f9c5c9
AS
216 (i * bitsize) / HOST_CHAR_BIT,
217 (i * bitsize) % HOST_CHAR_BIT,
218 bitsize, elttype);
2478d075
JB
219 if (TYPE_LENGTH (check_typedef (value_type (v0)))
220 != TYPE_LENGTH (check_typedef (value_type (v1))))
221 break;
9a0dc9e3
PA
222 if (!value_contents_eq (v0, value_embedded_offset (v0),
223 v1, value_embedded_offset (v1),
2478d075 224 TYPE_LENGTH (check_typedef (value_type (v0)))))
14f9c5c9
AS
225 break;
226 }
227
79a45b7d 228 if (i - i0 > options->repeat_count_threshold)
14f9c5c9 229 {
79a45b7d 230 struct value_print_options opts = *options;
5b4ee69b 231
79a45b7d 232 opts.deref_ref = 0;
e8b24d9f 233 val_print (elttype,
490f124f 234 value_embedded_offset (v0), 0, stream,
a491d753 235 recurse + 1, v0, &opts, current_language);
14f9c5c9 236 annotate_elt_rep (i - i0);
7f6aba03
TT
237 fprintf_filtered (stream, _(" %p[<repeats %u times>%p]"),
238 metadata_style.style ().ptr (), i - i0, nullptr);
14f9c5c9
AS
239 annotate_elt_rep_end ();
240
241 }
242 else
243 {
244 int j;
79a45b7d 245 struct value_print_options opts = *options;
5b4ee69b 246
79a45b7d 247 opts.deref_ref = 0;
14f9c5c9
AS
248 for (j = i0; j < i; j += 1)
249 {
d2e4a39e 250 if (j > i0)
14f9c5c9 251 {
2a998fc0 252 if (options->prettyformat_arrays)
14f9c5c9
AS
253 {
254 fprintf_filtered (stream, ",\n");
255 print_spaces_filtered (2 + 2 * recurse, stream);
256 }
257 else
258 {
259 fprintf_filtered (stream, ", ");
260 }
261 wrap_here (n_spaces (2 + 2 * recurse));
e79af960 262 maybe_print_array_index (index_type, j + low,
79a45b7d 263 stream, options);
14f9c5c9 264 }
e8b24d9f 265 val_print (elttype,
490f124f 266 value_embedded_offset (v0), 0, stream,
a491d753 267 recurse + 1, v0, &opts, current_language);
14f9c5c9
AS
268 annotate_elt ();
269 }
270 }
271 things_printed += i - i0;
272 }
273 annotate_array_section_end ();
274 if (i < len)
275 {
276 fprintf_filtered (stream, "...");
277 }
278
279 value_free_to_mark (mark);
280}
281
d2e4a39e 282static struct type *
fc1a4b47 283printable_val_type (struct type *type, const gdb_byte *valaddr)
14f9c5c9 284{
1ed6ede0 285 return ada_to_fixed_type (ada_aligned_type (type), valaddr, 0, NULL, 1);
14f9c5c9
AS
286}
287
288/* Print the character C on STREAM as part of the contents of a literal
289 string whose delimiter is QUOTER. TYPE_LEN is the length in bytes
4ffa5a33 290 of the character. */
14f9c5c9
AS
291
292void
6c7a06a3
TT
293ada_emit_char (int c, struct type *type, struct ui_file *stream,
294 int quoter, int type_len)
14f9c5c9 295{
4ffa5a33
JB
296 /* If this character fits in the normal ASCII range, and is
297 a printable character, then print the character as if it was
298 an ASCII character, even if this is a wide character.
299 The UCHAR_MAX check is necessary because the isascii function
300 requires that its argument have a value of an unsigned char,
301 or EOF (EOF is obviously not printable). */
302 if (c <= UCHAR_MAX && isascii (c) && isprint (c))
14f9c5c9
AS
303 {
304 if (c == quoter && c == '"')
529cad9c 305 fprintf_filtered (stream, "\"\"");
14f9c5c9
AS
306 else
307 fprintf_filtered (stream, "%c", c);
308 }
309 else
d2e4a39e 310 fprintf_filtered (stream, "[\"%0*x\"]", type_len * 2, c);
14f9c5c9
AS
311}
312
4ffa5a33
JB
313/* Character #I of STRING, given that TYPE_LEN is the size in bytes
314 of a character. */
14f9c5c9
AS
315
316static int
e17a4113
UW
317char_at (const gdb_byte *string, int i, int type_len,
318 enum bfd_endian byte_order)
14f9c5c9
AS
319{
320 if (type_len == 1)
321 return string[i];
d2e4a39e 322 else
4ffa5a33
JB
323 return (int) extract_unsigned_integer (string + type_len * i,
324 type_len, byte_order);
14f9c5c9
AS
325}
326
4c4b4cd2
PH
327/* Print a floating-point value of type TYPE, pointed to in GDB by
328 VALADDR, on STREAM. Use Ada formatting conventions: there must be
329 a decimal point, and at least one digit before and after the
4fbf5aa5
JB
330 point. We use the GNAT format for NaNs and infinities. */
331
4c4b4cd2 332static void
fc1a4b47 333ada_print_floating (const gdb_byte *valaddr, struct type *type,
a2bd3dcd 334 struct ui_file *stream)
4c4b4cd2 335{
d7e74731 336 string_file tmp_stream;
4c4b4cd2 337
d7e74731 338 print_floating (valaddr, type, &tmp_stream);
77e1c742 339
d7e74731 340 std::string &s = tmp_stream.string ();
77e1c742 341 size_t skip_count = 0;
4c4b4cd2
PH
342
343 /* Modify for Ada rules. */
606b8d1a 344
77e1c742
PA
345 size_t pos = s.find ("inf");
346 if (pos == std::string::npos)
347 pos = s.find ("Inf");
348 if (pos == std::string::npos)
349 pos = s.find ("INF");
350 if (pos != std::string::npos)
351 s.replace (pos, 3, "Inf");
c3e5cd34 352
77e1c742 353 if (pos == std::string::npos)
4c4b4cd2 354 {
77e1c742
PA
355 pos = s.find ("nan");
356 if (pos == std::string::npos)
357 pos = s.find ("NaN");
358 if (pos == std::string::npos)
359 pos = s.find ("Nan");
360 if (pos != std::string::npos)
c3e5cd34 361 {
77e1c742
PA
362 s[pos] = s[pos + 2] = 'N';
363 if (s[0] == '-')
364 skip_count = 1;
c3e5cd34 365 }
4c4b4cd2 366 }
c3e5cd34 367
77e1c742
PA
368 if (pos == std::string::npos
369 && s.find ('.') == std::string::npos)
4c4b4cd2 370 {
77e1c742
PA
371 pos = s.find ('e');
372 if (pos == std::string::npos)
373 fprintf_filtered (stream, "%s.0", s.c_str ());
4c4b4cd2 374 else
77e1c742 375 fprintf_filtered (stream, "%.*s.0%s", (int) pos, s.c_str (), &s[pos]);
4c4b4cd2 376 }
4fbf5aa5 377 else
77e1c742 378 fprintf_filtered (stream, "%s", &s[skip_count]);
4c4b4cd2
PH
379}
380
14f9c5c9 381void
6c7a06a3 382ada_printchar (int c, struct type *type, struct ui_file *stream)
14f9c5c9
AS
383{
384 fputs_filtered ("'", stream);
447b483c 385 ada_emit_char (c, type, stream, '\'', TYPE_LENGTH (type));
14f9c5c9
AS
386 fputs_filtered ("'", stream);
387}
388
389/* [From print_type_scalar in typeprint.c]. Print VAL on STREAM in a
7c964f07
UW
390 form appropriate for TYPE, if non-NULL. If TYPE is NULL, print VAL
391 like a default signed integer. */
14f9c5c9
AS
392
393void
ebf56fd3 394ada_print_scalar (struct type *type, LONGEST val, struct ui_file *stream)
14f9c5c9
AS
395{
396 unsigned int i;
397 unsigned len;
398
7c964f07
UW
399 if (!type)
400 {
401 print_longest (stream, 'd', 0, val);
402 return;
403 }
404
61ee279c 405 type = ada_check_typedef (type);
14f9c5c9
AS
406
407 switch (TYPE_CODE (type))
408 {
409
410 case TYPE_CODE_ENUM:
411 len = TYPE_NFIELDS (type);
412 for (i = 0; i < len; i++)
413 {
14e75d8e 414 if (TYPE_FIELD_ENUMVAL (type, i) == val)
14f9c5c9
AS
415 {
416 break;
417 }
418 }
419 if (i < len)
420 {
3f0cbb04
TT
421 fputs_styled (ada_enum_name (TYPE_FIELD_NAME (type, i)),
422 variable_name_style.style (), stream);
14f9c5c9
AS
423 }
424 else
425 {
426 print_longest (stream, 'd', 0, val);
427 }
428 break;
429
430 case TYPE_CODE_INT:
431 print_longest (stream, TYPE_UNSIGNED (type) ? 'u' : 'd', 0, val);
432 break;
433
434 case TYPE_CODE_CHAR:
10d44370 435 LA_PRINT_CHAR (val, type, stream);
14f9c5c9
AS
436 break;
437
438 case TYPE_CODE_BOOL:
439 fprintf_filtered (stream, val ? "true" : "false");
440 break;
441
442 case TYPE_CODE_RANGE:
443 ada_print_scalar (TYPE_TARGET_TYPE (type), val, stream);
444 return;
445
446 case TYPE_CODE_UNDEF:
447 case TYPE_CODE_PTR:
448 case TYPE_CODE_ARRAY:
449 case TYPE_CODE_STRUCT:
450 case TYPE_CODE_UNION:
451 case TYPE_CODE_FUNC:
452 case TYPE_CODE_FLT:
453 case TYPE_CODE_VOID:
454 case TYPE_CODE_SET:
455 case TYPE_CODE_STRING:
456 case TYPE_CODE_ERROR:
0d5de010
DJ
457 case TYPE_CODE_MEMBERPTR:
458 case TYPE_CODE_METHODPTR:
14f9c5c9
AS
459 case TYPE_CODE_METHOD:
460 case TYPE_CODE_REF:
edefbb7c 461 warning (_("internal error: unhandled type in ada_print_scalar"));
14f9c5c9
AS
462 break;
463
464 default:
edefbb7c 465 error (_("Invalid type code in symbol table."));
14f9c5c9 466 }
14f9c5c9
AS
467}
468
469/* Print the character string STRING, printing at most LENGTH characters.
470 Printing stops early if the number hits print_max; repeat counts
471 are printed as appropriate. Print ellipses at the end if we
9a153e0b
JB
472 had to stop before printing LENGTH characters, or if FORCE_ELLIPSES.
473 TYPE_LEN is the length (1 or 2) of the character type. */
14f9c5c9
AS
474
475static void
6c7a06a3 476printstr (struct ui_file *stream, struct type *elttype, const gdb_byte *string,
79a45b7d
TT
477 unsigned int length, int force_ellipses, int type_len,
478 const struct value_print_options *options)
14f9c5c9 479{
34877895 480 enum bfd_endian byte_order = type_byte_order (elttype);
14f9c5c9
AS
481 unsigned int i;
482 unsigned int things_printed = 0;
483 int in_quotes = 0;
484 int need_comma = 0;
485
486 if (length == 0)
487 {
488 fputs_filtered ("\"\"", stream);
489 return;
490 }
491
79a45b7d 492 for (i = 0; i < length && things_printed < options->print_max; i += 1)
14f9c5c9
AS
493 {
494 /* Position of the character we are examining
d2e4a39e 495 to see whether it is repeated. */
14f9c5c9
AS
496 unsigned int rep1;
497 /* Number of repetitions we have detected so far. */
498 unsigned int reps;
499
500 QUIT;
501
502 if (need_comma)
503 {
504 fputs_filtered (", ", stream);
505 need_comma = 0;
506 }
507
508 rep1 = i + 1;
509 reps = 1;
c3e5cd34 510 while (rep1 < length
e17a4113
UW
511 && char_at (string, rep1, type_len, byte_order)
512 == char_at (string, i, type_len, byte_order))
14f9c5c9
AS
513 {
514 rep1 += 1;
515 reps += 1;
516 }
517
79a45b7d 518 if (reps > options->repeat_count_threshold)
14f9c5c9
AS
519 {
520 if (in_quotes)
521 {
e93a8774 522 fputs_filtered ("\", ", stream);
14f9c5c9
AS
523 in_quotes = 0;
524 }
525 fputs_filtered ("'", stream);
e17a4113
UW
526 ada_emit_char (char_at (string, i, type_len, byte_order),
527 elttype, stream, '\'', type_len);
14f9c5c9 528 fputs_filtered ("'", stream);
7f6aba03
TT
529 fprintf_filtered (stream, _(" %p[<repeats %u times>%p]"),
530 metadata_style.style ().ptr (), reps, nullptr);
14f9c5c9 531 i = rep1 - 1;
79a45b7d 532 things_printed += options->repeat_count_threshold;
14f9c5c9
AS
533 need_comma = 1;
534 }
535 else
536 {
537 if (!in_quotes)
538 {
e93a8774 539 fputs_filtered ("\"", stream);
14f9c5c9
AS
540 in_quotes = 1;
541 }
e17a4113
UW
542 ada_emit_char (char_at (string, i, type_len, byte_order),
543 elttype, stream, '"', type_len);
14f9c5c9
AS
544 things_printed += 1;
545 }
546 }
547
548 /* Terminate the quotes if necessary. */
549 if (in_quotes)
e93a8774 550 fputs_filtered ("\"", stream);
14f9c5c9
AS
551
552 if (force_ellipses || i < length)
553 fputs_filtered ("...", stream);
554}
555
556void
0963b4bd
MS
557ada_printstr (struct ui_file *stream, struct type *type,
558 const gdb_byte *string, unsigned int length,
559 const char *encoding, int force_ellipses,
79a45b7d 560 const struct value_print_options *options)
14f9c5c9 561{
6c7a06a3
TT
562 printstr (stream, type, string, length, force_ellipses, TYPE_LENGTH (type),
563 options);
14f9c5c9
AS
564}
565
bdf779a0
JB
566static int
567print_variant_part (struct type *type, int field_num,
568 const gdb_byte *valaddr, int offset,
569 struct ui_file *stream, int recurse,
e8b24d9f 570 struct value *val,
bdf779a0
JB
571 const struct value_print_options *options,
572 int comma_needed,
8e355c5d
JB
573 struct type *outer_type, int outer_offset,
574 const struct language_defn *language)
bdf779a0
JB
575{
576 struct type *var_type = TYPE_FIELD_TYPE (type, field_num);
577 int which = ada_which_variant_applies (var_type, outer_type,
578 valaddr + outer_offset);
579
580 if (which < 0)
581 return 0;
582 else
583 return print_field_values
584 (TYPE_FIELD_TYPE (var_type, which),
585 valaddr,
586 offset + TYPE_FIELD_BITPOS (type, field_num) / HOST_CHAR_BIT
587 + TYPE_FIELD_BITPOS (var_type, which) / HOST_CHAR_BIT,
588 stream, recurse, val, options,
8e355c5d 589 comma_needed, outer_type, outer_offset, language);
bdf779a0
JB
590}
591
592/* Print out fields of value at VALADDR + OFFSET having structure type TYPE.
593
594 TYPE, VALADDR, OFFSET, STREAM, RECURSE, and OPTIONS have the same
595 meanings as in ada_print_value and ada_val_print.
596
597 OUTER_TYPE and OUTER_OFFSET give type and address of enclosing
598 record (used to get discriminant values when printing variant
599 parts).
600
601 COMMA_NEEDED is 1 if fields have been printed at the current recursion
602 level, so that a comma is needed before any field printed by this
603 call.
604
605 Returns 1 if COMMA_NEEDED or any fields were printed. */
606
607static int
608print_field_values (struct type *type, const gdb_byte *valaddr,
609 int offset, struct ui_file *stream, int recurse,
e8b24d9f 610 struct value *val,
bdf779a0
JB
611 const struct value_print_options *options,
612 int comma_needed,
8e355c5d
JB
613 struct type *outer_type, int outer_offset,
614 const struct language_defn *language)
bdf779a0
JB
615{
616 int i, len;
617
618 len = TYPE_NFIELDS (type);
619
620 for (i = 0; i < len; i += 1)
621 {
622 if (ada_is_ignored_field (type, i))
623 continue;
624
625 if (ada_is_wrapper_field (type, i))
626 {
627 comma_needed =
628 print_field_values (TYPE_FIELD_TYPE (type, i),
629 valaddr,
630 (offset
631 + TYPE_FIELD_BITPOS (type, i) / HOST_CHAR_BIT),
632 stream, recurse, val, options,
8e355c5d 633 comma_needed, type, offset, language);
bdf779a0
JB
634 continue;
635 }
636 else if (ada_is_variant_part (type, i))
637 {
638 comma_needed =
639 print_variant_part (type, i, valaddr,
640 offset, stream, recurse, val,
641 options, comma_needed,
8e355c5d 642 outer_type, outer_offset, language);
bdf779a0
JB
643 continue;
644 }
645
646 if (comma_needed)
647 fprintf_filtered (stream, ", ");
648 comma_needed = 1;
649
650 if (options->prettyformat)
651 {
652 fprintf_filtered (stream, "\n");
653 print_spaces_filtered (2 + 2 * recurse, stream);
654 }
655 else
656 {
657 wrap_here (n_spaces (2 + 2 * recurse));
658 }
659
660 annotate_field_begin (TYPE_FIELD_TYPE (type, i));
661 fprintf_filtered (stream, "%.*s",
662 ada_name_prefix_len (TYPE_FIELD_NAME (type, i)),
663 TYPE_FIELD_NAME (type, i));
664 annotate_field_name_end ();
665 fputs_filtered (" => ", stream);
666 annotate_field_value ();
667
668 if (TYPE_FIELD_PACKED (type, i))
669 {
bdf779a0
JB
670 /* Bitfields require special handling, especially due to byte
671 order problems. */
672 if (HAVE_CPLUS_STRUCT (type) && TYPE_FIELD_IGNORE (type, i))
673 {
7f6aba03
TT
674 fputs_styled (_("<optimized out or zero length>"),
675 metadata_style.style (), stream);
bdf779a0
JB
676 }
677 else
678 {
e8b24d9f 679 struct value *v;
bdf779a0
JB
680 int bit_pos = TYPE_FIELD_BITPOS (type, i);
681 int bit_size = TYPE_FIELD_BITSIZE (type, i);
682 struct value_print_options opts;
683
684 adjust_type_signedness (TYPE_FIELD_TYPE (type, i));
685 v = ada_value_primitive_packed_val
686 (NULL, valaddr,
687 offset + bit_pos / HOST_CHAR_BIT,
688 bit_pos % HOST_CHAR_BIT,
689 bit_size, TYPE_FIELD_TYPE (type, i));
690 opts = *options;
691 opts.deref_ref = 0;
692 val_print (TYPE_FIELD_TYPE (type, i),
bdf779a0
JB
693 value_embedded_offset (v), 0,
694 stream, recurse + 1, v,
8e355c5d 695 &opts, language);
bdf779a0
JB
696 }
697 }
698 else
699 {
700 struct value_print_options opts = *options;
701
702 opts.deref_ref = 0;
e8b24d9f 703 val_print (TYPE_FIELD_TYPE (type, i),
8e355c5d
JB
704 (offset + TYPE_FIELD_BITPOS (type, i) / HOST_CHAR_BIT),
705 0, stream, recurse + 1, val, &opts, language);
bdf779a0
JB
706 }
707 annotate_field_end ();
708 }
709
710 return comma_needed;
711}
712
71855601
JB
713/* Implement Ada val_print'ing for the case where TYPE is
714 a TYPE_CODE_ARRAY of characters. */
715
716static void
717ada_val_print_string (struct type *type, const gdb_byte *valaddr,
718 int offset, int offset_aligned, CORE_ADDR address,
719 struct ui_file *stream, int recurse,
e8b24d9f 720 struct value *original_value,
71855601
JB
721 const struct value_print_options *options)
722{
34877895 723 enum bfd_endian byte_order = type_byte_order (type);
71855601
JB
724 struct type *elttype = TYPE_TARGET_TYPE (type);
725 unsigned int eltlen;
726 unsigned int len;
727
728 /* We know that ELTTYPE cannot possibly be null, because we assume
729 that we're called only when TYPE is a string-like type.
730 Similarly, the size of ELTTYPE should also be non-null, since
731 it's a character-like type. */
732 gdb_assert (elttype != NULL);
733 gdb_assert (TYPE_LENGTH (elttype) != 0);
734
735 eltlen = TYPE_LENGTH (elttype);
736 len = TYPE_LENGTH (type) / eltlen;
737
738 if (options->prettyformat_arrays)
739 print_spaces_filtered (2 + 2 * recurse, stream);
740
741 /* If requested, look for the first null char and only print
742 elements up to it. */
743 if (options->stop_print_at_null)
744 {
745 int temp_len;
746
747 /* Look for a NULL char. */
748 for (temp_len = 0;
749 (temp_len < len
750 && temp_len < options->print_max
751 && char_at (valaddr + offset_aligned,
752 temp_len, eltlen, byte_order) != 0);
753 temp_len += 1);
754 len = temp_len;
755 }
756
757 printstr (stream, elttype, valaddr + offset_aligned, len, 0,
758 eltlen, options);
759}
760
8004dfd1
JB
761/* Implement Ada val_print-ing for GNAT arrays (Eg. fat pointers,
762 thin pointers, etc). */
763
764static void
765ada_val_print_gnat_array (struct type *type, const gdb_byte *valaddr,
766 int offset, CORE_ADDR address,
767 struct ui_file *stream, int recurse,
e8b24d9f 768 struct value *original_value,
2228ef77 769 const struct value_print_options *options)
8004dfd1
JB
770{
771 struct value *mark = value_mark ();
772 struct value *val;
773
774 val = value_from_contents_and_address (type, valaddr + offset, address);
775 /* If this is a reference, coerce it now. This helps taking care
776 of the case where ADDRESS is meaningless because original_value
777 was not an lval. */
778 val = coerce_ref (val);
779 if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF) /* array access type. */
780 val = ada_coerce_to_simple_array_ptr (val);
781 else
782 val = ada_coerce_to_simple_array (val);
783 if (val == NULL)
784 {
785 gdb_assert (TYPE_CODE (type) == TYPE_CODE_TYPEDEF);
786 fprintf_filtered (stream, "0x0");
787 }
788 else
e8b24d9f 789 val_print (value_type (val),
8004dfd1 790 value_embedded_offset (val), value_address (val),
2228ef77
XR
791 stream, recurse, val, options,
792 language_def (language_ada));
8004dfd1
JB
793 value_free_to_mark (mark);
794}
795
796/* Implement Ada val_print'ing for the case where TYPE is
797 a TYPE_CODE_PTR. */
798
799static void
800ada_val_print_ptr (struct type *type, const gdb_byte *valaddr,
801 int offset, int offset_aligned, CORE_ADDR address,
802 struct ui_file *stream, int recurse,
e8b24d9f 803 struct value *original_value,
2228ef77 804 const struct value_print_options *options)
8004dfd1 805{
e8b24d9f 806 val_print (type, offset, address, stream, recurse,
8004dfd1
JB
807 original_value, options, language_def (language_c));
808
809 if (ada_is_tag_type (type))
810 {
811 struct value *val =
812 value_from_contents_and_address (type,
813 valaddr + offset_aligned,
814 address + offset_aligned);
815 const char *name = ada_tag_name (val);
816
817 if (name != NULL)
818 fprintf_filtered (stream, " (%s)", name);
819 }
820}
821
822/* Implement Ada val_print'ing for the case where TYPE is
823 a TYPE_CODE_INT or TYPE_CODE_RANGE. */
824
825static void
826ada_val_print_num (struct type *type, const gdb_byte *valaddr,
827 int offset, int offset_aligned, CORE_ADDR address,
828 struct ui_file *stream, int recurse,
e8b24d9f 829 struct value *original_value,
2228ef77 830 const struct value_print_options *options)
8004dfd1
JB
831{
832 if (ada_is_fixed_point_type (type))
833 {
50eff16b
UW
834 struct value *scale = ada_scaling_factor (type);
835 struct value *v = value_from_contents (type, valaddr + offset_aligned);
836 v = value_cast (value_type (scale), v);
837 v = value_binop (v, scale, BINOP_MUL);
838
839 const char *fmt = TYPE_LENGTH (type) < 4 ? "%.11g" : "%.17g";
840 std::string str
841 = target_float_to_string (value_contents (v), value_type (v), fmt);
842 fputs_filtered (str.c_str (), stream);
8004dfd1
JB
843 return;
844 }
4e962e74
TT
845 else if (TYPE_CODE (type) == TYPE_CODE_RANGE
846 && (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_ENUM
847 || TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_BOOL
848 || TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_CHAR))
8004dfd1 849 {
4e962e74
TT
850 /* For enum-valued ranges, we want to recurse, because we'll end
851 up printing the constant's name rather than its numeric
852 value. Character and fixed-point types are also printed
853 differently, so recuse for those as well. */
8004dfd1
JB
854 struct type *target_type = TYPE_TARGET_TYPE (type);
855
856 if (TYPE_LENGTH (type) != TYPE_LENGTH (target_type))
857 {
858 /* Obscure case of range type that has different length from
859 its base type. Perform a conversion, or we will get a
860 nonsense value. Actually, we could use the same
861 code regardless of lengths; I'm just avoiding a cast. */
862 struct value *v1
863 = value_from_contents_and_address (type, valaddr + offset, 0);
864 struct value *v = value_cast (target_type, v1);
865
e8b24d9f 866 val_print (target_type,
8004dfd1 867 value_embedded_offset (v), 0, stream,
2228ef77
XR
868 recurse + 1, v, options,
869 language_def (language_ada));
8004dfd1
JB
870 }
871 else
e8b24d9f 872 val_print (TYPE_TARGET_TYPE (type), offset,
8004dfd1 873 address, stream, recurse, original_value,
2228ef77 874 options, language_def (language_ada));
8004dfd1
JB
875 return;
876 }
877 else
878 {
879 int format = (options->format ? options->format
880 : options->output_format);
881
882 if (format)
883 {
884 struct value_print_options opts = *options;
885
886 opts.format = format;
e8b24d9f 887 val_print_scalar_formatted (type, offset_aligned,
8004dfd1
JB
888 original_value, &opts, 0, stream);
889 }
890 else if (ada_is_system_address_type (type))
891 {
892 /* FIXME: We want to print System.Address variables using
893 the same format as for any access type. But for some
894 reason GNAT encodes the System.Address type as an int,
895 so we have to work-around this deficiency by handling
896 System.Address values as a special case. */
897
898 struct gdbarch *gdbarch = get_type_arch (type);
899 struct type *ptr_type = builtin_type (gdbarch)->builtin_data_ptr;
900 CORE_ADDR addr = extract_typed_address (valaddr + offset_aligned,
901 ptr_type);
902
903 fprintf_filtered (stream, "(");
904 type_print (type, "", stream, -1);
905 fprintf_filtered (stream, ") ");
906 fputs_filtered (paddress (gdbarch, addr), stream);
907 }
908 else
909 {
f12f6bad
TT
910 val_print_scalar_formatted (type, offset_aligned,
911 original_value, options, 0, stream);
8004dfd1
JB
912 if (ada_is_character_type (type))
913 {
914 LONGEST c;
915
916 fputs_filtered (" ", stream);
917 c = unpack_long (type, valaddr + offset_aligned);
918 ada_printchar (c, type, stream);
919 }
920 }
921 return;
922 }
923}
924
925/* Implement Ada val_print'ing for the case where TYPE is
926 a TYPE_CODE_ENUM. */
927
928static void
929ada_val_print_enum (struct type *type, const gdb_byte *valaddr,
930 int offset, int offset_aligned, CORE_ADDR address,
931 struct ui_file *stream, int recurse,
e8b24d9f 932 struct value *original_value,
2228ef77 933 const struct value_print_options *options)
8004dfd1
JB
934{
935 int i;
936 unsigned int len;
937 LONGEST val;
938
939 if (options->format)
940 {
e8b24d9f 941 val_print_scalar_formatted (type, offset_aligned,
8004dfd1
JB
942 original_value, options, 0, stream);
943 return;
944 }
945
946 len = TYPE_NFIELDS (type);
947 val = unpack_long (type, valaddr + offset_aligned);
948 for (i = 0; i < len; i++)
949 {
950 QUIT;
951 if (val == TYPE_FIELD_ENUMVAL (type, i))
952 break;
953 }
954
955 if (i < len)
956 {
957 const char *name = ada_enum_name (TYPE_FIELD_NAME (type, i));
958
959 if (name[0] == '\'')
3f0cbb04
TT
960 fprintf_filtered (stream, "%ld %ps", (long) val,
961 styled_string (variable_name_style.style (),
962 name));
8004dfd1 963 else
3f0cbb04 964 fputs_styled (name, variable_name_style.style (), stream);
8004dfd1
JB
965 }
966 else
967 print_longest (stream, 'd', 0, val);
968}
969
970/* Implement Ada val_print'ing for the case where TYPE is
971 a TYPE_CODE_FLT. */
972
973static void
974ada_val_print_flt (struct type *type, const gdb_byte *valaddr,
975 int offset, int offset_aligned, CORE_ADDR address,
976 struct ui_file *stream, int recurse,
e8b24d9f 977 struct value *original_value,
2228ef77 978 const struct value_print_options *options)
8004dfd1
JB
979{
980 if (options->format)
981 {
e8b24d9f 982 val_print (type, offset, address, stream, recurse,
8004dfd1
JB
983 original_value, options, language_def (language_c));
984 return;
985 }
986
987 ada_print_floating (valaddr + offset, type, stream);
988}
989
990/* Implement Ada val_print'ing for the case where TYPE is
991 a TYPE_CODE_STRUCT or TYPE_CODE_UNION. */
992
993static void
994ada_val_print_struct_union
995 (struct type *type, const gdb_byte *valaddr, int offset,
996 int offset_aligned, CORE_ADDR address, struct ui_file *stream,
e8b24d9f 997 int recurse, struct value *original_value,
2228ef77 998 const struct value_print_options *options)
8004dfd1
JB
999{
1000 if (ada_is_bogus_array_descriptor (type))
1001 {
1002 fprintf_filtered (stream, "(...?)");
1003 return;
1004 }
1005
079e4591
JB
1006 fprintf_filtered (stream, "(");
1007
1008 if (print_field_values (type, valaddr, offset_aligned,
1009 stream, recurse, original_value, options,
2228ef77
XR
1010 0, type, offset_aligned,
1011 language_def (language_ada)) != 0
079e4591
JB
1012 && options->prettyformat)
1013 {
1014 fprintf_filtered (stream, "\n");
1015 print_spaces_filtered (2 * recurse, stream);
1016 }
1017
1018 fprintf_filtered (stream, ")");
8004dfd1
JB
1019}
1020
4eb27a30
JB
1021/* Implement Ada val_print'ing for the case where TYPE is
1022 a TYPE_CODE_ARRAY. */
1023
1024static void
1025ada_val_print_array (struct type *type, const gdb_byte *valaddr,
1026 int offset, int offset_aligned, CORE_ADDR address,
1027 struct ui_file *stream, int recurse,
e8b24d9f 1028 struct value *original_value,
4eb27a30
JB
1029 const struct value_print_options *options)
1030{
71855601 1031 /* For an array of characters, print with string syntax. */
4eb27a30
JB
1032 if (ada_is_string_type (type)
1033 && (options->format == 0 || options->format == 's'))
1034 {
71855601
JB
1035 ada_val_print_string (type, valaddr, offset, offset_aligned,
1036 address, stream, recurse, original_value,
1037 options);
1038 return;
4eb27a30 1039 }
71855601
JB
1040
1041 fprintf_filtered (stream, "(");
1042 print_optional_low_bound (stream, type, options);
1043 if (TYPE_FIELD_BITSIZE (type, 0) > 0)
1044 val_print_packed_array_elements (type, valaddr, offset_aligned,
1045 0, stream, recurse,
1046 original_value, options);
4eb27a30 1047 else
e8b24d9f 1048 val_print_array_elements (type, offset_aligned, address,
71855601
JB
1049 stream, recurse, original_value,
1050 options, 0);
1051 fprintf_filtered (stream, ")");
4eb27a30
JB
1052}
1053
8004dfd1
JB
1054/* Implement Ada val_print'ing for the case where TYPE is
1055 a TYPE_CODE_REF. */
1056
1057static void
1058ada_val_print_ref (struct type *type, const gdb_byte *valaddr,
1059 int offset, int offset_aligned, CORE_ADDR address,
1060 struct ui_file *stream, int recurse,
e8b24d9f 1061 struct value *original_value,
2228ef77 1062 const struct value_print_options *options)
8004dfd1
JB
1063{
1064 /* For references, the debugger is expected to print the value as
1065 an address if DEREF_REF is null. But printing an address in place
1066 of the object value would be confusing to an Ada programmer.
1067 So, for Ada values, we print the actual dereferenced value
1068 regardless. */
1069 struct type *elttype = check_typedef (TYPE_TARGET_TYPE (type));
34b27950
JB
1070 struct value *deref_val;
1071 CORE_ADDR deref_val_int;
8004dfd1 1072
34b27950 1073 if (TYPE_CODE (elttype) == TYPE_CODE_UNDEF)
8004dfd1 1074 {
7f6aba03
TT
1075 fputs_styled ("<ref to undefined type>", metadata_style.style (),
1076 stream);
34b27950
JB
1077 return;
1078 }
8004dfd1 1079
34b27950
JB
1080 deref_val = coerce_ref_if_computed (original_value);
1081 if (deref_val)
1082 {
1083 if (ada_is_tagged_type (value_type (deref_val), 1))
1084 deref_val = ada_tag_value_at_base_address (deref_val);
8004dfd1 1085
34b27950 1086 common_val_print (deref_val, stream, recurse + 1, options,
2228ef77 1087 language_def (language_ada));
34b27950
JB
1088 return;
1089 }
8004dfd1 1090
34b27950
JB
1091 deref_val_int = unpack_pointer (type, valaddr + offset_aligned);
1092 if (deref_val_int == 0)
1093 {
1094 fputs_filtered ("(null)", stream);
1095 return;
8004dfd1 1096 }
34b27950
JB
1097
1098 deref_val
1099 = ada_value_ind (value_from_pointer (lookup_pointer_type (elttype),
1100 deref_val_int));
1101 if (ada_is_tagged_type (value_type (deref_val), 1))
1102 deref_val = ada_tag_value_at_base_address (deref_val);
1103
c1b5a1a6
JB
1104 /* Make sure that the object does not have an unreasonable size
1105 before trying to print it. This can happen for instance with
1106 references to dynamic objects whose contents is uninitialized
1107 (Eg: an array whose bounds are not set yet). */
1108 ada_ensure_varsize_limit (value_type (deref_val));
1109
7d45f3df
YQ
1110 if (value_lazy (deref_val))
1111 value_fetch_lazy (deref_val);
1112
34b27950 1113 val_print (value_type (deref_val),
34b27950
JB
1114 value_embedded_offset (deref_val),
1115 value_address (deref_val), stream, recurse + 1,
2228ef77 1116 deref_val, options, language_def (language_ada));
8004dfd1
JB
1117}
1118
14f9c5c9 1119/* See the comment on ada_val_print. This function differs in that it
e936309c 1120 does not catch evaluation errors (leaving that to ada_val_print). */
14f9c5c9 1121
d3eab38a 1122static void
e8b24d9f 1123ada_val_print_1 (struct type *type,
490f124f 1124 int offset, CORE_ADDR address,
79a45b7d 1125 struct ui_file *stream, int recurse,
e8b24d9f 1126 struct value *original_value,
2228ef77 1127 const struct value_print_options *options)
14f9c5c9 1128{
490f124f 1129 int offset_aligned;
e8b24d9f 1130 const gdb_byte *valaddr = value_contents_for_printing (original_value);
14f9c5c9 1131
61ee279c 1132 type = ada_check_typedef (type);
14f9c5c9 1133
ad82864c 1134 if (ada_is_array_descriptor_type (type)
d2d43431
JB
1135 || (ada_is_constrained_packed_array_type (type)
1136 && TYPE_CODE (type) != TYPE_CODE_PTR))
14f9c5c9 1137 {
8004dfd1
JB
1138 ada_val_print_gnat_array (type, valaddr, offset, address,
1139 stream, recurse, original_value,
2228ef77 1140 options);
d3eab38a 1141 return;
14f9c5c9
AS
1142 }
1143
490f124f
PA
1144 offset_aligned = offset + ada_aligned_value_addr (type, valaddr) - valaddr;
1145 type = printable_val_type (type, valaddr + offset_aligned);
62c67f3c
JB
1146 type = resolve_dynamic_type (type, valaddr + offset_aligned,
1147 address + offset_aligned);
14f9c5c9
AS
1148
1149 switch (TYPE_CODE (type))
1150 {
1151 default:
e8b24d9f 1152 val_print (type, offset, address, stream, recurse,
cd1630f9 1153 original_value, options, language_def (language_c));
d3eab38a 1154 break;
14f9c5c9 1155
4c4b4cd2 1156 case TYPE_CODE_PTR:
8004dfd1
JB
1157 ada_val_print_ptr (type, valaddr, offset, offset_aligned,
1158 address, stream, recurse, original_value,
2228ef77 1159 options);
8004dfd1 1160 break;
4c4b4cd2 1161
14f9c5c9
AS
1162 case TYPE_CODE_INT:
1163 case TYPE_CODE_RANGE:
8004dfd1
JB
1164 ada_val_print_num (type, valaddr, offset, offset_aligned,
1165 address, stream, recurse, original_value,
2228ef77 1166 options);
8004dfd1 1167 break;
14f9c5c9
AS
1168
1169 case TYPE_CODE_ENUM:
8004dfd1
JB
1170 ada_val_print_enum (type, valaddr, offset, offset_aligned,
1171 address, stream, recurse, original_value,
2228ef77 1172 options);
8004dfd1 1173 break;
d2e4a39e 1174
4c4b4cd2 1175 case TYPE_CODE_FLT:
8004dfd1
JB
1176 ada_val_print_flt (type, valaddr, offset, offset_aligned,
1177 address, stream, recurse, original_value,
2228ef77 1178 options);
4c4b4cd2
PH
1179 break;
1180
14f9c5c9
AS
1181 case TYPE_CODE_UNION:
1182 case TYPE_CODE_STRUCT:
8004dfd1
JB
1183 ada_val_print_struct_union (type, valaddr, offset, offset_aligned,
1184 address, stream, recurse,
2228ef77 1185 original_value, options);
8004dfd1 1186 break;
14f9c5c9
AS
1187
1188 case TYPE_CODE_ARRAY:
4eb27a30 1189 ada_val_print_array (type, valaddr, offset, offset_aligned,
d3eab38a
TT
1190 address, stream, recurse, original_value,
1191 options);
1192 return;
14f9c5c9
AS
1193
1194 case TYPE_CODE_REF:
8004dfd1
JB
1195 ada_val_print_ref (type, valaddr, offset, offset_aligned,
1196 address, stream, recurse, original_value,
2228ef77 1197 options);
14f9c5c9
AS
1198 break;
1199 }
14f9c5c9
AS
1200}
1201
bdf779a0
JB
1202/* See val_print for a description of the various parameters of this
1203 function; they are identical. */
1204
1205void
e8b24d9f 1206ada_val_print (struct type *type,
bdf779a0
JB
1207 int embedded_offset, CORE_ADDR address,
1208 struct ui_file *stream, int recurse,
e8b24d9f 1209 struct value *val,
bdf779a0 1210 const struct value_print_options *options)
14f9c5c9 1211{
a70b8144 1212 try
bdf779a0 1213 {
e8b24d9f 1214 ada_val_print_1 (type, embedded_offset, address,
2228ef77 1215 stream, recurse, val, options);
bdf779a0 1216 }
230d2906 1217 catch (const gdb_exception_error &except)
492d29ea 1218 {
7f6aba03
TT
1219 fprintf_styled (stream, metadata_style.style (),
1220 _("<error reading variable: %s>"),
1221 except.what ());
492d29ea 1222 }
14f9c5c9
AS
1223}
1224
8e069a98 1225void
79a45b7d
TT
1226ada_value_print (struct value *val0, struct ui_file *stream,
1227 const struct value_print_options *options)
14f9c5c9 1228{
0c3acc09
JB
1229 struct value *val = ada_to_fixed_value (val0);
1230 CORE_ADDR address = value_address (val);
cc330e39 1231 struct type *type = ada_check_typedef (value_type (val));
79a45b7d 1232 struct value_print_options opts;
14f9c5c9 1233
4c4b4cd2
PH
1234 /* If it is a pointer, indicate what it points to. */
1235 if (TYPE_CODE (type) == TYPE_CODE_PTR)
14f9c5c9 1236 {
4c4b4cd2
PH
1237 /* Hack: don't print (char *) for char strings. Their
1238 type is indicated by the quoted string anyway. */
1239 if (TYPE_LENGTH (TYPE_TARGET_TYPE (type)) != sizeof (char)
1240 || TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_INT
1241 || TYPE_UNSIGNED (TYPE_TARGET_TYPE (type)))
14f9c5c9
AS
1242 {
1243 fprintf_filtered (stream, "(");
1244 type_print (type, "", stream, -1);
1245 fprintf_filtered (stream, ") ");
1246 }
1247 }
4c4b4cd2 1248 else if (ada_is_array_descriptor_type (type))
14f9c5c9 1249 {
720d1a40
JB
1250 /* We do not print the type description unless TYPE is an array
1251 access type (this is encoded by the compiler as a typedef to
1252 a fat pointer - hence the check against TYPE_CODE_TYPEDEF). */
1253 if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
1254 {
1255 fprintf_filtered (stream, "(");
1256 type_print (type, "", stream, -1);
1257 fprintf_filtered (stream, ") ");
1258 }
14f9c5c9
AS
1259 }
1260 else if (ada_is_bogus_array_descriptor (type))
1261 {
1262 fprintf_filtered (stream, "(");
1263 type_print (type, "", stream, -1);
1264 fprintf_filtered (stream, ") (...?)");
8e069a98 1265 return;
14f9c5c9 1266 }
4c4b4cd2 1267
79a45b7d
TT
1268 opts = *options;
1269 opts.deref_ref = 1;
e8b24d9f 1270 val_print (type,
8e069a98
TT
1271 value_embedded_offset (val), address,
1272 stream, 0, val, &opts, current_language);
14f9c5c9 1273}
This page took 1.143691 seconds and 4 git commands to generate.