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