Commit | Line | Data |
---|---|---|
4c4b4cd2 | 1 | /* Support for printing Ada values for GDB, the GNU debugger. |
d56612af | 2 | |
6aba47ca | 3 | Copyright (C) 1986, 1988, 1989, 1991, 1992, 1993, 1994, 1997, 2001, 2002, |
4c38e0a4 JB |
4 | 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 |
5 | Free Software Foundation, Inc. | |
14f9c5c9 | 6 | |
a9762ec7 | 7 | This file is part of GDB. |
14f9c5c9 | 8 | |
a9762ec7 JB |
9 | This program is free software; you can redistribute it and/or modify |
10 | it under the terms of the GNU General Public License as published by | |
11 | the Free Software Foundation; either version 3 of the License, or | |
12 | (at your option) any later version. | |
14f9c5c9 | 13 | |
a9762ec7 JB |
14 | This program is distributed in the hope that it will be useful, |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | GNU General Public License for more details. | |
14f9c5c9 | 18 | |
a9762ec7 JB |
19 | You should have received a copy of the GNU General Public License |
20 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
14f9c5c9 | 21 | |
14f9c5c9 | 22 | #include "defs.h" |
12c89474 | 23 | #include <ctype.h> |
4c4b4cd2 | 24 | #include "gdb_string.h" |
14f9c5c9 AS |
25 | #include "symtab.h" |
26 | #include "gdbtypes.h" | |
27 | #include "expression.h" | |
28 | #include "value.h" | |
29 | #include "demangle.h" | |
30 | #include "valprint.h" | |
31 | #include "language.h" | |
32 | #include "annotate.h" | |
33 | #include "ada-lang.h" | |
34 | #include "c-lang.h" | |
04714b91 | 35 | #include "infcall.h" |
60250e8b | 36 | #include "exceptions.h" |
8ca1c40e | 37 | #include "objfiles.h" |
14f9c5c9 | 38 | |
4c4b4cd2 | 39 | /* Encapsulates arguments to ada_val_print. */ |
d2e4a39e AS |
40 | struct ada_val_print_args |
41 | { | |
42 | struct type *type; | |
fc1a4b47 | 43 | const gdb_byte *valaddr0; |
14f9c5c9 AS |
44 | int embedded_offset; |
45 | CORE_ADDR address; | |
46 | struct ui_file *stream; | |
14f9c5c9 | 47 | int recurse; |
79a45b7d | 48 | const struct value_print_options *options; |
14f9c5c9 AS |
49 | }; |
50 | ||
fc1a4b47 | 51 | static void print_record (struct type *, const gdb_byte *, struct ui_file *, |
79a45b7d | 52 | int, const struct value_print_options *); |
14f9c5c9 | 53 | |
fc1a4b47 | 54 | static int print_field_values (struct type *, const gdb_byte *, |
79a45b7d TT |
55 | struct ui_file *, int, |
56 | const struct value_print_options *, | |
57 | int, struct type *, | |
fc1a4b47 | 58 | const gdb_byte *); |
14f9c5c9 | 59 | |
d2e4a39e | 60 | static void adjust_type_signedness (struct type *); |
14f9c5c9 | 61 | |
19c1ef65 | 62 | static int ada_val_print_stub (void *args0); |
14f9c5c9 | 63 | |
fc1a4b47 | 64 | static int ada_val_print_1 (struct type *, const gdb_byte *, int, CORE_ADDR, |
79a45b7d TT |
65 | struct ui_file *, int, |
66 | const struct value_print_options *); | |
14f9c5c9 AS |
67 | \f |
68 | ||
4c4b4cd2 | 69 | /* Make TYPE unsigned if its range of values includes no negatives. */ |
d2e4a39e | 70 | static void |
4dc81987 | 71 | adjust_type_signedness (struct type *type) |
14f9c5c9 | 72 | { |
d2e4a39e | 73 | if (type != NULL && TYPE_CODE (type) == TYPE_CODE_RANGE |
14f9c5c9 | 74 | && TYPE_LOW_BOUND (type) >= 0) |
876cecd0 | 75 | TYPE_UNSIGNED (type) = 1; |
d2e4a39e | 76 | } |
14f9c5c9 | 77 | |
e936309c JB |
78 | /* Assuming TYPE is a simple array type, prints its lower bound on STREAM, |
79 | if non-standard (i.e., other than 1 for numbers, other than lower bound | |
80 | of index type for enumerated type). Returns 1 if something printed, | |
81 | otherwise 0. */ | |
14f9c5c9 | 82 | |
d2e4a39e | 83 | static int |
79a45b7d TT |
84 | print_optional_low_bound (struct ui_file *stream, struct type *type, |
85 | const struct value_print_options *options) | |
14f9c5c9 AS |
86 | { |
87 | struct type *index_type; | |
88 | long low_bound; | |
e936309c | 89 | long high_bound; |
14f9c5c9 | 90 | |
79a45b7d | 91 | if (options->print_array_indexes) |
14f9c5c9 | 92 | return 0; |
e79af960 | 93 | |
e936309c JB |
94 | if (!get_array_bounds (type, &low_bound, &high_bound)) |
95 | return 0; | |
96 | ||
97 | /* If this is an empty array, then don't print the lower bound. | |
98 | That would be confusing, because we would print the lower bound, | |
99 | followed by... nothing! */ | |
100 | if (low_bound > high_bound) | |
14f9c5c9 | 101 | return 0; |
d2e4a39e | 102 | |
e79af960 JB |
103 | index_type = TYPE_INDEX_TYPE (type); |
104 | ||
fd1b946e JB |
105 | if (TYPE_CODE (index_type) == TYPE_CODE_RANGE) |
106 | { | |
107 | /* We need to know what the base type is, in order to do the | |
108 | appropriate check below. Otherwise, if this is a subrange | |
109 | of an enumerated type, where the underlying value of the | |
110 | first element is typically 0, we might test the low bound | |
111 | against the wrong value. */ | |
112 | index_type = TYPE_TARGET_TYPE (index_type); | |
113 | } | |
114 | ||
d2e4a39e AS |
115 | switch (TYPE_CODE (index_type)) |
116 | { | |
690cc4eb PH |
117 | case TYPE_CODE_BOOL: |
118 | if (low_bound == 0) | |
119 | return 0; | |
120 | break; | |
d2e4a39e AS |
121 | case TYPE_CODE_ENUM: |
122 | if (low_bound == TYPE_FIELD_BITPOS (index_type, 0)) | |
123 | return 0; | |
124 | break; | |
125 | case TYPE_CODE_UNDEF: | |
7c964f07 | 126 | index_type = NULL; |
d2e4a39e AS |
127 | /* FALL THROUGH */ |
128 | default: | |
129 | if (low_bound == 1) | |
130 | return 0; | |
131 | break; | |
132 | } | |
14f9c5c9 AS |
133 | |
134 | ada_print_scalar (index_type, (LONGEST) low_bound, stream); | |
135 | fprintf_filtered (stream, " => "); | |
136 | return 1; | |
137 | } | |
138 | ||
139 | /* Version of val_print_array_elements for GNAT-style packed arrays. | |
140 | Prints elements of packed array of type TYPE at bit offset | |
79a45b7d | 141 | BITOFFSET from VALADDR on STREAM. Formats according to OPTIONS and |
4c4b4cd2 | 142 | separates with commas. RECURSE is the recursion (nesting) level. |
79a45b7d | 143 | TYPE must have been decoded (as by ada_coerce_to_simple_array). */ |
14f9c5c9 AS |
144 | |
145 | static void | |
fc1a4b47 | 146 | val_print_packed_array_elements (struct type *type, const gdb_byte *valaddr, |
ebf56fd3 | 147 | int bitoffset, struct ui_file *stream, |
79a45b7d TT |
148 | int recurse, |
149 | const struct value_print_options *options) | |
14f9c5c9 AS |
150 | { |
151 | unsigned int i; | |
152 | unsigned int things_printed = 0; | |
153 | unsigned len; | |
e79af960 | 154 | struct type *elttype, *index_type; |
14f9c5c9 | 155 | unsigned eltlen; |
14f9c5c9 | 156 | unsigned long bitsize = TYPE_FIELD_BITSIZE (type, 0); |
d2e4a39e | 157 | struct value *mark = value_mark (); |
e79af960 | 158 | LONGEST low = 0; |
d2e4a39e | 159 | |
14f9c5c9 AS |
160 | elttype = TYPE_TARGET_TYPE (type); |
161 | eltlen = TYPE_LENGTH (check_typedef (elttype)); | |
e79af960 | 162 | index_type = TYPE_INDEX_TYPE (type); |
14f9c5c9 AS |
163 | |
164 | { | |
e79af960 | 165 | LONGEST high; |
262452ec | 166 | if (get_discrete_bounds (index_type, &low, &high) < 0) |
14f9c5c9 AS |
167 | len = 1; |
168 | else | |
169 | len = high - low + 1; | |
170 | } | |
171 | ||
172 | i = 0; | |
173 | annotate_array_section_begin (i, elttype); | |
174 | ||
79a45b7d | 175 | while (i < len && things_printed < options->print_max) |
14f9c5c9 AS |
176 | { |
177 | struct value *v0, *v1; | |
178 | int i0; | |
179 | ||
180 | if (i != 0) | |
181 | { | |
79a45b7d | 182 | if (options->prettyprint_arrays) |
14f9c5c9 AS |
183 | { |
184 | fprintf_filtered (stream, ",\n"); | |
185 | print_spaces_filtered (2 + 2 * recurse, stream); | |
186 | } | |
187 | else | |
188 | { | |
189 | fprintf_filtered (stream, ", "); | |
190 | } | |
191 | } | |
192 | wrap_here (n_spaces (2 + 2 * recurse)); | |
79a45b7d | 193 | maybe_print_array_index (index_type, i + low, stream, options); |
14f9c5c9 AS |
194 | |
195 | i0 = i; | |
d2e4a39e | 196 | v0 = ada_value_primitive_packed_val (NULL, valaddr, |
14f9c5c9 AS |
197 | (i0 * bitsize) / HOST_CHAR_BIT, |
198 | (i0 * bitsize) % HOST_CHAR_BIT, | |
199 | bitsize, elttype); | |
200 | while (1) | |
201 | { | |
202 | i += 1; | |
203 | if (i >= len) | |
204 | break; | |
d2e4a39e | 205 | v1 = ada_value_primitive_packed_val (NULL, valaddr, |
14f9c5c9 AS |
206 | (i * bitsize) / HOST_CHAR_BIT, |
207 | (i * bitsize) % HOST_CHAR_BIT, | |
208 | bitsize, elttype); | |
0fd88904 | 209 | if (memcmp (value_contents (v0), value_contents (v1), eltlen) != 0) |
14f9c5c9 AS |
210 | break; |
211 | } | |
212 | ||
79a45b7d | 213 | if (i - i0 > options->repeat_count_threshold) |
14f9c5c9 | 214 | { |
79a45b7d TT |
215 | struct value_print_options opts = *options; |
216 | opts.deref_ref = 0; | |
217 | val_print (elttype, value_contents (v0), 0, 0, stream, | |
218 | recurse + 1, &opts, current_language); | |
14f9c5c9 | 219 | annotate_elt_rep (i - i0); |
edefbb7c | 220 | fprintf_filtered (stream, _(" <repeats %u times>"), i - i0); |
14f9c5c9 AS |
221 | annotate_elt_rep_end (); |
222 | ||
223 | } | |
224 | else | |
225 | { | |
226 | int j; | |
79a45b7d TT |
227 | struct value_print_options opts = *options; |
228 | opts.deref_ref = 0; | |
14f9c5c9 AS |
229 | for (j = i0; j < i; j += 1) |
230 | { | |
d2e4a39e | 231 | if (j > i0) |
14f9c5c9 | 232 | { |
79a45b7d | 233 | if (options->prettyprint_arrays) |
14f9c5c9 AS |
234 | { |
235 | fprintf_filtered (stream, ",\n"); | |
236 | print_spaces_filtered (2 + 2 * recurse, stream); | |
237 | } | |
238 | else | |
239 | { | |
240 | fprintf_filtered (stream, ", "); | |
241 | } | |
242 | wrap_here (n_spaces (2 + 2 * recurse)); | |
e79af960 | 243 | maybe_print_array_index (index_type, j + low, |
79a45b7d | 244 | stream, options); |
14f9c5c9 | 245 | } |
79a45b7d TT |
246 | val_print (elttype, value_contents (v0), 0, 0, stream, |
247 | recurse + 1, &opts, current_language); | |
14f9c5c9 AS |
248 | annotate_elt (); |
249 | } | |
250 | } | |
251 | things_printed += i - i0; | |
252 | } | |
253 | annotate_array_section_end (); | |
254 | if (i < len) | |
255 | { | |
256 | fprintf_filtered (stream, "..."); | |
257 | } | |
258 | ||
259 | value_free_to_mark (mark); | |
260 | } | |
261 | ||
d2e4a39e | 262 | static struct type * |
fc1a4b47 | 263 | printable_val_type (struct type *type, const gdb_byte *valaddr) |
14f9c5c9 | 264 | { |
1ed6ede0 | 265 | return ada_to_fixed_type (ada_aligned_type (type), valaddr, 0, NULL, 1); |
14f9c5c9 AS |
266 | } |
267 | ||
268 | /* Print the character C on STREAM as part of the contents of a literal | |
269 | string whose delimiter is QUOTER. TYPE_LEN is the length in bytes | |
4c4b4cd2 | 270 | (1 or 2) of the character. */ |
14f9c5c9 AS |
271 | |
272 | void | |
6c7a06a3 TT |
273 | ada_emit_char (int c, struct type *type, struct ui_file *stream, |
274 | int quoter, int type_len) | |
14f9c5c9 AS |
275 | { |
276 | if (type_len != 2) | |
277 | type_len = 1; | |
278 | ||
279 | c &= (1 << (type_len * TARGET_CHAR_BIT)) - 1; | |
280 | ||
281 | if (isascii (c) && isprint (c)) | |
282 | { | |
283 | if (c == quoter && c == '"') | |
529cad9c | 284 | fprintf_filtered (stream, "\"\""); |
14f9c5c9 AS |
285 | else |
286 | fprintf_filtered (stream, "%c", c); | |
287 | } | |
288 | else | |
d2e4a39e | 289 | fprintf_filtered (stream, "[\"%0*x\"]", type_len * 2, c); |
14f9c5c9 AS |
290 | } |
291 | ||
292 | /* Character #I of STRING, given that TYPE_LEN is the size in bytes (1 | |
4c4b4cd2 | 293 | or 2) of a character. */ |
14f9c5c9 AS |
294 | |
295 | static int | |
e17a4113 UW |
296 | char_at (const gdb_byte *string, int i, int type_len, |
297 | enum bfd_endian byte_order) | |
14f9c5c9 AS |
298 | { |
299 | if (type_len == 1) | |
300 | return string[i]; | |
d2e4a39e | 301 | else |
e17a4113 | 302 | return (int) extract_unsigned_integer (string + 2 * i, 2, byte_order); |
14f9c5c9 AS |
303 | } |
304 | ||
4c4b4cd2 PH |
305 | /* Wrapper around memcpy to make it legal argument to ui_file_put */ |
306 | static void | |
307 | ui_memcpy (void *dest, const char *buffer, long len) | |
308 | { | |
309 | memcpy (dest, buffer, (size_t) len); | |
310 | ((char *) dest)[len] = '\0'; | |
311 | } | |
312 | ||
313 | /* Print a floating-point value of type TYPE, pointed to in GDB by | |
314 | VALADDR, on STREAM. Use Ada formatting conventions: there must be | |
315 | a decimal point, and at least one digit before and after the | |
316 | point. We use GNAT format for NaNs and infinities. */ | |
317 | static void | |
fc1a4b47 | 318 | ada_print_floating (const gdb_byte *valaddr, struct type *type, |
a2bd3dcd | 319 | struct ui_file *stream) |
4c4b4cd2 PH |
320 | { |
321 | char buffer[64]; | |
322 | char *s, *result; | |
323 | int len; | |
324 | struct ui_file *tmp_stream = mem_fileopen (); | |
325 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_stream); | |
326 | ||
327 | print_floating (valaddr, type, tmp_stream); | |
328 | ui_file_put (tmp_stream, ui_memcpy, buffer); | |
329 | do_cleanups (cleanups); | |
330 | ||
331 | result = buffer; | |
332 | len = strlen (result); | |
333 | ||
334 | /* Modify for Ada rules. */ | |
606b8d1a | 335 | |
c3e5cd34 PH |
336 | s = strstr (result, "inf"); |
337 | if (s == NULL) | |
338 | s = strstr (result, "Inf"); | |
339 | if (s == NULL) | |
340 | s = strstr (result, "INF"); | |
341 | if (s != NULL) | |
4c4b4cd2 | 342 | strcpy (s, "Inf"); |
c3e5cd34 PH |
343 | |
344 | if (s == NULL) | |
4c4b4cd2 | 345 | { |
c3e5cd34 PH |
346 | s = strstr (result, "nan"); |
347 | if (s == NULL) | |
348 | s = strstr (result, "NaN"); | |
349 | if (s == NULL) | |
350 | s = strstr (result, "Nan"); | |
351 | if (s != NULL) | |
352 | { | |
353 | s[0] = s[2] = 'N'; | |
354 | if (result[0] == '-') | |
355 | result += 1; | |
356 | } | |
4c4b4cd2 | 357 | } |
c3e5cd34 PH |
358 | |
359 | if (s == NULL && strchr (result, '.') == NULL) | |
4c4b4cd2 | 360 | { |
c3e5cd34 PH |
361 | s = strchr (result, 'e'); |
362 | if (s == NULL) | |
4c4b4cd2 PH |
363 | fprintf_filtered (stream, "%s.0", result); |
364 | else | |
365 | fprintf_filtered (stream, "%.*s.0%s", (int) (s-result), result, s); | |
366 | return; | |
367 | } | |
368 | fprintf_filtered (stream, "%s", result); | |
369 | } | |
370 | ||
14f9c5c9 | 371 | void |
6c7a06a3 | 372 | ada_printchar (int c, struct type *type, struct ui_file *stream) |
14f9c5c9 AS |
373 | { |
374 | fputs_filtered ("'", stream); | |
6c7a06a3 | 375 | ada_emit_char (c, type, stream, '\'', 1); |
14f9c5c9 AS |
376 | fputs_filtered ("'", stream); |
377 | } | |
378 | ||
379 | /* [From print_type_scalar in typeprint.c]. Print VAL on STREAM in a | |
7c964f07 UW |
380 | form appropriate for TYPE, if non-NULL. If TYPE is NULL, print VAL |
381 | like a default signed integer. */ | |
14f9c5c9 AS |
382 | |
383 | void | |
ebf56fd3 | 384 | ada_print_scalar (struct type *type, LONGEST val, struct ui_file *stream) |
14f9c5c9 AS |
385 | { |
386 | unsigned int i; | |
387 | unsigned len; | |
388 | ||
7c964f07 UW |
389 | if (!type) |
390 | { | |
391 | print_longest (stream, 'd', 0, val); | |
392 | return; | |
393 | } | |
394 | ||
61ee279c | 395 | type = ada_check_typedef (type); |
14f9c5c9 AS |
396 | |
397 | switch (TYPE_CODE (type)) | |
398 | { | |
399 | ||
400 | case TYPE_CODE_ENUM: | |
401 | len = TYPE_NFIELDS (type); | |
402 | for (i = 0; i < len; i++) | |
403 | { | |
404 | if (TYPE_FIELD_BITPOS (type, i) == val) | |
405 | { | |
406 | break; | |
407 | } | |
408 | } | |
409 | if (i < len) | |
410 | { | |
411 | fputs_filtered (ada_enum_name (TYPE_FIELD_NAME (type, i)), stream); | |
412 | } | |
413 | else | |
414 | { | |
415 | print_longest (stream, 'd', 0, val); | |
416 | } | |
417 | break; | |
418 | ||
419 | case TYPE_CODE_INT: | |
420 | print_longest (stream, TYPE_UNSIGNED (type) ? 'u' : 'd', 0, val); | |
421 | break; | |
422 | ||
423 | case TYPE_CODE_CHAR: | |
6c7a06a3 | 424 | LA_PRINT_CHAR ((unsigned char) val, type, stream); |
14f9c5c9 AS |
425 | break; |
426 | ||
427 | case TYPE_CODE_BOOL: | |
428 | fprintf_filtered (stream, val ? "true" : "false"); | |
429 | break; | |
430 | ||
431 | case TYPE_CODE_RANGE: | |
432 | ada_print_scalar (TYPE_TARGET_TYPE (type), val, stream); | |
433 | return; | |
434 | ||
435 | case TYPE_CODE_UNDEF: | |
436 | case TYPE_CODE_PTR: | |
437 | case TYPE_CODE_ARRAY: | |
438 | case TYPE_CODE_STRUCT: | |
439 | case TYPE_CODE_UNION: | |
440 | case TYPE_CODE_FUNC: | |
441 | case TYPE_CODE_FLT: | |
442 | case TYPE_CODE_VOID: | |
443 | case TYPE_CODE_SET: | |
444 | case TYPE_CODE_STRING: | |
445 | case TYPE_CODE_ERROR: | |
0d5de010 DJ |
446 | case TYPE_CODE_MEMBERPTR: |
447 | case TYPE_CODE_METHODPTR: | |
14f9c5c9 AS |
448 | case TYPE_CODE_METHOD: |
449 | case TYPE_CODE_REF: | |
edefbb7c | 450 | warning (_("internal error: unhandled type in ada_print_scalar")); |
14f9c5c9 AS |
451 | break; |
452 | ||
453 | default: | |
edefbb7c | 454 | error (_("Invalid type code in symbol table.")); |
14f9c5c9 AS |
455 | } |
456 | gdb_flush (stream); | |
457 | } | |
458 | ||
459 | /* Print the character string STRING, printing at most LENGTH characters. | |
460 | Printing stops early if the number hits print_max; repeat counts | |
461 | are printed as appropriate. Print ellipses at the end if we | |
462 | had to stop before printing LENGTH characters, or if | |
463 | FORCE_ELLIPSES. TYPE_LEN is the length (1 or 2) of the character type. | |
464 | */ | |
465 | ||
466 | static void | |
6c7a06a3 | 467 | printstr (struct ui_file *stream, struct type *elttype, const gdb_byte *string, |
79a45b7d TT |
468 | unsigned int length, int force_ellipses, int type_len, |
469 | const struct value_print_options *options) | |
14f9c5c9 | 470 | { |
e17a4113 | 471 | enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (elttype)); |
14f9c5c9 AS |
472 | unsigned int i; |
473 | unsigned int things_printed = 0; | |
474 | int in_quotes = 0; | |
475 | int need_comma = 0; | |
476 | ||
477 | if (length == 0) | |
478 | { | |
479 | fputs_filtered ("\"\"", stream); | |
480 | return; | |
481 | } | |
482 | ||
79a45b7d | 483 | for (i = 0; i < length && things_printed < options->print_max; i += 1) |
14f9c5c9 AS |
484 | { |
485 | /* Position of the character we are examining | |
d2e4a39e | 486 | to see whether it is repeated. */ |
14f9c5c9 AS |
487 | unsigned int rep1; |
488 | /* Number of repetitions we have detected so far. */ | |
489 | unsigned int reps; | |
490 | ||
491 | QUIT; | |
492 | ||
493 | if (need_comma) | |
494 | { | |
495 | fputs_filtered (", ", stream); | |
496 | need_comma = 0; | |
497 | } | |
498 | ||
499 | rep1 = i + 1; | |
500 | reps = 1; | |
c3e5cd34 | 501 | while (rep1 < length |
e17a4113 UW |
502 | && char_at (string, rep1, type_len, byte_order) |
503 | == char_at (string, i, type_len, byte_order)) | |
14f9c5c9 AS |
504 | { |
505 | rep1 += 1; | |
506 | reps += 1; | |
507 | } | |
508 | ||
79a45b7d | 509 | if (reps > options->repeat_count_threshold) |
14f9c5c9 AS |
510 | { |
511 | if (in_quotes) | |
512 | { | |
79a45b7d | 513 | if (options->inspect_it) |
14f9c5c9 AS |
514 | fputs_filtered ("\\\", ", stream); |
515 | else | |
516 | fputs_filtered ("\", ", stream); | |
517 | in_quotes = 0; | |
518 | } | |
519 | fputs_filtered ("'", stream); | |
e17a4113 UW |
520 | ada_emit_char (char_at (string, i, type_len, byte_order), |
521 | elttype, stream, '\'', type_len); | |
14f9c5c9 | 522 | fputs_filtered ("'", stream); |
edefbb7c | 523 | fprintf_filtered (stream, _(" <repeats %u times>"), reps); |
14f9c5c9 | 524 | i = rep1 - 1; |
79a45b7d | 525 | things_printed += options->repeat_count_threshold; |
14f9c5c9 AS |
526 | need_comma = 1; |
527 | } | |
528 | else | |
529 | { | |
530 | if (!in_quotes) | |
531 | { | |
79a45b7d | 532 | if (options->inspect_it) |
14f9c5c9 AS |
533 | fputs_filtered ("\\\"", stream); |
534 | else | |
535 | fputs_filtered ("\"", stream); | |
536 | in_quotes = 1; | |
537 | } | |
e17a4113 UW |
538 | ada_emit_char (char_at (string, i, type_len, byte_order), |
539 | elttype, stream, '"', type_len); | |
14f9c5c9 AS |
540 | things_printed += 1; |
541 | } | |
542 | } | |
543 | ||
544 | /* Terminate the quotes if necessary. */ | |
545 | if (in_quotes) | |
546 | { | |
79a45b7d | 547 | if (options->inspect_it) |
14f9c5c9 AS |
548 | fputs_filtered ("\\\"", stream); |
549 | else | |
550 | fputs_filtered ("\"", stream); | |
551 | } | |
552 | ||
553 | if (force_ellipses || i < length) | |
554 | fputs_filtered ("...", stream); | |
555 | } | |
556 | ||
557 | void | |
6c7a06a3 | 558 | ada_printstr (struct ui_file *stream, struct type *type, const gdb_byte *string, |
be759fcf | 559 | unsigned int length, 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 | ||
566 | ||
567 | /* Print data of type TYPE located at VALADDR (within GDB), which came from | |
568 | the inferior at address ADDRESS, onto stdio stream STREAM according to | |
79a45b7d | 569 | OPTIONS. The data at VALADDR is in target byte order. |
14f9c5c9 AS |
570 | |
571 | If the data is printed as a string, returns the number of string characters | |
572 | printed. | |
573 | ||
14f9c5c9 | 574 | RECURSE indicates the amount of indentation to supply before |
79a45b7d | 575 | continuation lines; this amount is roughly twice the value of RECURSE. */ |
14f9c5c9 AS |
576 | |
577 | int | |
fc1a4b47 | 578 | ada_val_print (struct type *type, const gdb_byte *valaddr0, |
a2bd3dcd | 579 | int embedded_offset, CORE_ADDR address, |
79a45b7d TT |
580 | struct ui_file *stream, int recurse, |
581 | const struct value_print_options *options) | |
14f9c5c9 AS |
582 | { |
583 | struct ada_val_print_args args; | |
d2e4a39e AS |
584 | args.type = type; |
585 | args.valaddr0 = valaddr0; | |
14f9c5c9 AS |
586 | args.embedded_offset = embedded_offset; |
587 | args.address = address; | |
588 | args.stream = stream; | |
14f9c5c9 | 589 | args.recurse = recurse; |
79a45b7d | 590 | args.options = options; |
14f9c5c9 AS |
591 | |
592 | return catch_errors (ada_val_print_stub, &args, NULL, RETURN_MASK_ALL); | |
593 | } | |
594 | ||
595 | /* Helper for ada_val_print; used as argument to catch_errors to | |
4c4b4cd2 | 596 | unmarshal the arguments to ada_val_print_1, which does the work. */ |
14f9c5c9 | 597 | static int |
19c1ef65 | 598 | ada_val_print_stub (void *args0) |
14f9c5c9 | 599 | { |
d2e4a39e AS |
600 | struct ada_val_print_args *argsp = (struct ada_val_print_args *) args0; |
601 | return ada_val_print_1 (argsp->type, argsp->valaddr0, | |
602 | argsp->embedded_offset, argsp->address, | |
79a45b7d | 603 | argsp->stream, argsp->recurse, argsp->options); |
14f9c5c9 AS |
604 | } |
605 | ||
e936309c JB |
606 | /* Assuming TYPE is a simple array, print the value of this array located |
607 | at VALADDR. See ada_val_print for a description of the various | |
608 | parameters of this function; they are identical. The semantics | |
609 | of the return value is also identical to ada_val_print. */ | |
610 | ||
611 | static int | |
612 | ada_val_print_array (struct type *type, const gdb_byte *valaddr, | |
79a45b7d TT |
613 | CORE_ADDR address, struct ui_file *stream, int recurse, |
614 | const struct value_print_options *options) | |
e936309c | 615 | { |
e17a4113 | 616 | enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type)); |
e936309c JB |
617 | struct type *elttype = TYPE_TARGET_TYPE (type); |
618 | unsigned int eltlen; | |
619 | unsigned int len; | |
620 | int result = 0; | |
621 | ||
622 | if (elttype == NULL) | |
623 | eltlen = 0; | |
624 | else | |
625 | eltlen = TYPE_LENGTH (elttype); | |
626 | if (eltlen == 0) | |
627 | len = 0; | |
628 | else | |
629 | len = TYPE_LENGTH (type) / eltlen; | |
630 | ||
631 | /* For an array of chars, print with string syntax. */ | |
79a45b7d TT |
632 | if (ada_is_string_type (type) |
633 | && (options->format == 0 || options->format == 's')) | |
e936309c | 634 | { |
79a45b7d | 635 | if (options->prettyprint_arrays) |
e936309c JB |
636 | print_spaces_filtered (2 + 2 * recurse, stream); |
637 | ||
638 | /* If requested, look for the first null char and only print | |
639 | elements up to it. */ | |
79a45b7d | 640 | if (options->stop_print_at_null) |
e936309c JB |
641 | { |
642 | int temp_len; | |
643 | ||
644 | /* Look for a NULL char. */ | |
645 | for (temp_len = 0; | |
646 | (temp_len < len | |
79a45b7d | 647 | && temp_len < options->print_max |
e17a4113 | 648 | && char_at (valaddr, temp_len, eltlen, byte_order) != 0); |
e936309c JB |
649 | temp_len += 1); |
650 | len = temp_len; | |
651 | } | |
652 | ||
6c7a06a3 | 653 | printstr (stream, elttype, valaddr, len, 0, eltlen, options); |
e936309c JB |
654 | result = len; |
655 | } | |
656 | else | |
657 | { | |
658 | fprintf_filtered (stream, "("); | |
79a45b7d | 659 | print_optional_low_bound (stream, type, options); |
e936309c JB |
660 | if (TYPE_FIELD_BITSIZE (type, 0) > 0) |
661 | val_print_packed_array_elements (type, valaddr, 0, stream, | |
79a45b7d | 662 | recurse, options); |
e936309c JB |
663 | else |
664 | val_print_array_elements (type, valaddr, address, stream, | |
79a45b7d | 665 | recurse, options, 0); |
e936309c JB |
666 | fprintf_filtered (stream, ")"); |
667 | } | |
668 | ||
669 | return result; | |
670 | } | |
671 | ||
14f9c5c9 | 672 | /* See the comment on ada_val_print. This function differs in that it |
e936309c | 673 | does not catch evaluation errors (leaving that to ada_val_print). */ |
14f9c5c9 AS |
674 | |
675 | static int | |
fc1a4b47 | 676 | ada_val_print_1 (struct type *type, const gdb_byte *valaddr0, |
a2bd3dcd | 677 | int embedded_offset, CORE_ADDR address, |
79a45b7d TT |
678 | struct ui_file *stream, int recurse, |
679 | const struct value_print_options *options) | |
14f9c5c9 AS |
680 | { |
681 | unsigned int len; | |
682 | int i; | |
683 | struct type *elttype; | |
684 | unsigned int eltlen; | |
685 | LONGEST val; | |
fc1a4b47 | 686 | const gdb_byte *valaddr = valaddr0 + embedded_offset; |
14f9c5c9 | 687 | |
61ee279c | 688 | type = ada_check_typedef (type); |
14f9c5c9 | 689 | |
ad82864c JB |
690 | if (ada_is_array_descriptor_type (type) |
691 | || ada_is_constrained_packed_array_type (type)) | |
14f9c5c9 AS |
692 | { |
693 | int retn; | |
d2e4a39e AS |
694 | struct value *mark = value_mark (); |
695 | struct value *val; | |
14f9c5c9 AS |
696 | val = value_from_contents_and_address (type, valaddr, address); |
697 | val = ada_coerce_to_simple_array_ptr (val); | |
698 | if (val == NULL) | |
699 | { | |
700 | fprintf_filtered (stream, "(null)"); | |
701 | retn = 0; | |
702 | } | |
703 | else | |
0fd88904 | 704 | retn = ada_val_print_1 (value_type (val), value_contents (val), 0, |
42ae5230 | 705 | value_address (val), stream, recurse, options); |
14f9c5c9 AS |
706 | value_free_to_mark (mark); |
707 | return retn; | |
708 | } | |
709 | ||
710 | valaddr = ada_aligned_value_addr (type, valaddr); | |
711 | embedded_offset -= valaddr - valaddr0 - embedded_offset; | |
712 | type = printable_val_type (type, valaddr); | |
713 | ||
714 | switch (TYPE_CODE (type)) | |
715 | { | |
716 | default: | |
d2e4a39e | 717 | return c_val_print (type, valaddr0, embedded_offset, address, stream, |
79a45b7d | 718 | recurse, options); |
14f9c5c9 | 719 | |
4c4b4cd2 PH |
720 | case TYPE_CODE_PTR: |
721 | { | |
722 | int ret = c_val_print (type, valaddr0, embedded_offset, address, | |
79a45b7d | 723 | stream, recurse, options); |
4c4b4cd2 PH |
724 | if (ada_is_tag_type (type)) |
725 | { | |
726 | struct value *val = | |
727 | value_from_contents_and_address (type, valaddr, address); | |
728 | const char *name = ada_tag_name (val); | |
729 | if (name != NULL) | |
730 | fprintf_filtered (stream, " (%s)", name); | |
731 | return 0; | |
732 | } | |
733 | return ret; | |
734 | } | |
735 | ||
14f9c5c9 AS |
736 | case TYPE_CODE_INT: |
737 | case TYPE_CODE_RANGE: | |
738 | if (ada_is_fixed_point_type (type)) | |
739 | { | |
740 | LONGEST v = unpack_long (type, valaddr); | |
741 | int len = TYPE_LENGTH (type); | |
742 | ||
743 | fprintf_filtered (stream, len < 4 ? "%.11g" : "%.17g", | |
744 | (double) ada_fixed_to_float (type, v)); | |
745 | return 0; | |
746 | } | |
14f9c5c9 AS |
747 | else if (TYPE_CODE (type) == TYPE_CODE_RANGE) |
748 | { | |
d2e4a39e | 749 | struct type *target_type = TYPE_TARGET_TYPE (type); |
14f9c5c9 AS |
750 | if (TYPE_LENGTH (type) != TYPE_LENGTH (target_type)) |
751 | { | |
752 | /* Obscure case of range type that has different length from | |
d2e4a39e AS |
753 | its base type. Perform a conversion, or we will get a |
754 | nonsense value. Actually, we could use the same | |
4c4b4cd2 | 755 | code regardless of lengths; I'm just avoiding a cast. */ |
d2e4a39e AS |
756 | struct value *v = value_cast (target_type, |
757 | value_from_contents_and_address | |
758 | (type, valaddr, 0)); | |
0fd88904 | 759 | return ada_val_print_1 (target_type, value_contents (v), 0, 0, |
79a45b7d | 760 | stream, recurse + 1, options); |
14f9c5c9 AS |
761 | } |
762 | else | |
d2e4a39e | 763 | return ada_val_print_1 (TYPE_TARGET_TYPE (type), |
14f9c5c9 | 764 | valaddr0, embedded_offset, |
79a45b7d | 765 | address, stream, recurse, options); |
14f9c5c9 | 766 | } |
d2e4a39e | 767 | else |
14f9c5c9 | 768 | { |
79a45b7d TT |
769 | int format = (options->format ? options->format |
770 | : options->output_format); | |
14f9c5c9 AS |
771 | if (format) |
772 | { | |
79a45b7d TT |
773 | struct value_print_options opts = *options; |
774 | opts.format = format; | |
775 | print_scalar_formatted (valaddr, type, &opts, 0, stream); | |
14f9c5c9 | 776 | } |
50810684 | 777 | else if (ada_is_system_address_type (type)) |
4c4b4cd2 PH |
778 | { |
779 | /* FIXME: We want to print System.Address variables using | |
780 | the same format as for any access type. But for some | |
781 | reason GNAT encodes the System.Address type as an int, | |
782 | so we have to work-around this deficiency by handling | |
50810684 | 783 | System.Address values as a special case. */ |
8ca1c40e | 784 | |
50810684 | 785 | struct gdbarch *gdbarch = get_type_arch (type); |
8ca1c40e | 786 | struct type *ptr_type = builtin_type (gdbarch)->builtin_data_ptr; |
5af949e3 | 787 | CORE_ADDR addr = extract_typed_address (valaddr, ptr_type); |
8ca1c40e | 788 | |
4c4b4cd2 PH |
789 | fprintf_filtered (stream, "("); |
790 | type_print (type, "", stream, -1); | |
791 | fprintf_filtered (stream, ") "); | |
5af949e3 | 792 | fputs_filtered (paddress (gdbarch, addr), stream); |
4c4b4cd2 | 793 | } |
14f9c5c9 AS |
794 | else |
795 | { | |
796 | val_print_type_code_int (type, valaddr, stream); | |
797 | if (ada_is_character_type (type)) | |
798 | { | |
799 | fputs_filtered (" ", stream); | |
800 | ada_printchar ((unsigned char) unpack_long (type, valaddr), | |
6c7a06a3 | 801 | type, stream); |
14f9c5c9 AS |
802 | } |
803 | } | |
804 | return 0; | |
805 | } | |
806 | ||
807 | case TYPE_CODE_ENUM: | |
79a45b7d | 808 | if (options->format) |
14f9c5c9 | 809 | { |
79a45b7d | 810 | print_scalar_formatted (valaddr, type, options, 0, stream); |
14f9c5c9 AS |
811 | break; |
812 | } | |
813 | len = TYPE_NFIELDS (type); | |
814 | val = unpack_long (type, valaddr); | |
815 | for (i = 0; i < len; i++) | |
816 | { | |
817 | QUIT; | |
818 | if (val == TYPE_FIELD_BITPOS (type, i)) | |
819 | { | |
820 | break; | |
821 | } | |
822 | } | |
823 | if (i < len) | |
824 | { | |
d2e4a39e AS |
825 | const char *name = ada_enum_name (TYPE_FIELD_NAME (type, i)); |
826 | if (name[0] == '\'') | |
14f9c5c9 AS |
827 | fprintf_filtered (stream, "%ld %s", (long) val, name); |
828 | else | |
829 | fputs_filtered (name, stream); | |
830 | } | |
831 | else | |
832 | { | |
833 | print_longest (stream, 'd', 0, val); | |
834 | } | |
835 | break; | |
d2e4a39e | 836 | |
4f2aea11 | 837 | case TYPE_CODE_FLAGS: |
79a45b7d TT |
838 | if (options->format) |
839 | print_scalar_formatted (valaddr, type, options, 0, stream); | |
4f2aea11 MK |
840 | else |
841 | val_print_type_code_flags (type, valaddr, stream); | |
842 | break; | |
843 | ||
4c4b4cd2 | 844 | case TYPE_CODE_FLT: |
79a45b7d | 845 | if (options->format) |
4c4b4cd2 | 846 | return c_val_print (type, valaddr0, embedded_offset, address, stream, |
79a45b7d | 847 | recurse, options); |
4c4b4cd2 PH |
848 | else |
849 | ada_print_floating (valaddr0 + embedded_offset, type, stream); | |
850 | break; | |
851 | ||
14f9c5c9 AS |
852 | case TYPE_CODE_UNION: |
853 | case TYPE_CODE_STRUCT: | |
854 | if (ada_is_bogus_array_descriptor (type)) | |
855 | { | |
856 | fprintf_filtered (stream, "(...?)"); | |
857 | return 0; | |
d2e4a39e | 858 | } |
14f9c5c9 AS |
859 | else |
860 | { | |
79a45b7d | 861 | print_record (type, valaddr, stream, recurse, options); |
14f9c5c9 AS |
862 | return 0; |
863 | } | |
864 | ||
865 | case TYPE_CODE_ARRAY: | |
79a45b7d TT |
866 | return ada_val_print_array (type, valaddr, address, stream, |
867 | recurse, options); | |
14f9c5c9 AS |
868 | |
869 | case TYPE_CODE_REF: | |
969a1360 JB |
870 | /* For references, the debugger is expected to print the value as |
871 | an address if DEREF_REF is null. But printing an address in place | |
872 | of the object value would be confusing to an Ada programmer. | |
873 | So, for Ada values, we print the actual dereferenced value | |
874 | regardless. */ | |
14f9c5c9 | 875 | elttype = check_typedef (TYPE_TARGET_TYPE (type)); |
969a1360 JB |
876 | |
877 | if (TYPE_CODE (elttype) != TYPE_CODE_UNDEF) | |
878 | { | |
d8631d21 | 879 | LONGEST deref_val_int = (LONGEST) unpack_pointer (type, valaddr); |
969a1360 JB |
880 | if (deref_val_int != 0) |
881 | { | |
882 | struct value *deref_val = | |
883 | ada_value_ind (value_from_longest | |
884 | (lookup_pointer_type (elttype), | |
885 | deref_val_int)); | |
886 | val_print (value_type (deref_val), | |
887 | value_contents (deref_val), 0, | |
42ae5230 | 888 | value_address (deref_val), stream, recurse + 1, |
79a45b7d | 889 | options, current_language); |
969a1360 JB |
890 | } |
891 | else | |
892 | fputs_filtered ("(null)", stream); | |
893 | } | |
894 | else | |
895 | fputs_filtered ("???", stream); | |
896 | ||
14f9c5c9 AS |
897 | break; |
898 | } | |
4c4b4cd2 | 899 | gdb_flush (stream); |
14f9c5c9 AS |
900 | return 0; |
901 | } | |
902 | ||
903 | static int | |
fc1a4b47 | 904 | print_variant_part (struct type *type, int field_num, const gdb_byte *valaddr, |
79a45b7d TT |
905 | struct ui_file *stream, int recurse, |
906 | const struct value_print_options *options, int comma_needed, | |
fc1a4b47 | 907 | struct type *outer_type, const gdb_byte *outer_valaddr) |
14f9c5c9 AS |
908 | { |
909 | struct type *var_type = TYPE_FIELD_TYPE (type, field_num); | |
d2e4a39e | 910 | int which = ada_which_variant_applies (var_type, outer_type, outer_valaddr); |
14f9c5c9 AS |
911 | |
912 | if (which < 0) | |
913 | return 0; | |
914 | else | |
d2e4a39e | 915 | return print_field_values |
14f9c5c9 AS |
916 | (TYPE_FIELD_TYPE (var_type, which), |
917 | valaddr + TYPE_FIELD_BITPOS (type, field_num) / HOST_CHAR_BIT | |
918 | + TYPE_FIELD_BITPOS (var_type, which) / HOST_CHAR_BIT, | |
79a45b7d | 919 | stream, recurse, options, |
14f9c5c9 AS |
920 | comma_needed, outer_type, outer_valaddr); |
921 | } | |
922 | ||
923 | int | |
79a45b7d TT |
924 | ada_value_print (struct value *val0, struct ui_file *stream, |
925 | const struct value_print_options *options) | |
14f9c5c9 | 926 | { |
fc1a4b47 | 927 | const gdb_byte *valaddr = value_contents (val0); |
42ae5230 | 928 | CORE_ADDR address = value_address (val0); |
d2e4a39e | 929 | struct type *type = |
1ed6ede0 | 930 | ada_to_fixed_type (value_type (val0), valaddr, address, NULL, 1); |
d2e4a39e AS |
931 | struct value *val = |
932 | value_from_contents_and_address (type, valaddr, address); | |
79a45b7d | 933 | struct value_print_options opts; |
14f9c5c9 | 934 | |
4c4b4cd2 PH |
935 | /* If it is a pointer, indicate what it points to. */ |
936 | if (TYPE_CODE (type) == TYPE_CODE_PTR) | |
14f9c5c9 | 937 | { |
4c4b4cd2 PH |
938 | /* Hack: don't print (char *) for char strings. Their |
939 | type is indicated by the quoted string anyway. */ | |
940 | if (TYPE_LENGTH (TYPE_TARGET_TYPE (type)) != sizeof (char) | |
941 | || TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_INT | |
942 | || TYPE_UNSIGNED (TYPE_TARGET_TYPE (type))) | |
14f9c5c9 AS |
943 | { |
944 | fprintf_filtered (stream, "("); | |
945 | type_print (type, "", stream, -1); | |
946 | fprintf_filtered (stream, ") "); | |
947 | } | |
948 | } | |
4c4b4cd2 | 949 | else if (ada_is_array_descriptor_type (type)) |
14f9c5c9 AS |
950 | { |
951 | fprintf_filtered (stream, "("); | |
952 | type_print (type, "", stream, -1); | |
953 | fprintf_filtered (stream, ") "); | |
954 | } | |
955 | else if (ada_is_bogus_array_descriptor (type)) | |
956 | { | |
957 | fprintf_filtered (stream, "("); | |
958 | type_print (type, "", stream, -1); | |
959 | fprintf_filtered (stream, ") (...?)"); | |
960 | return 0; | |
961 | } | |
4c4b4cd2 | 962 | |
79a45b7d TT |
963 | opts = *options; |
964 | opts.deref_ref = 1; | |
0fd88904 | 965 | return (val_print (type, value_contents (val), 0, address, |
79a45b7d | 966 | stream, 0, &opts, current_language)); |
14f9c5c9 | 967 | } |
d2e4a39e | 968 | |
14f9c5c9 | 969 | static void |
fc1a4b47 | 970 | print_record (struct type *type, const gdb_byte *valaddr, |
79a45b7d TT |
971 | struct ui_file *stream, int recurse, |
972 | const struct value_print_options *options) | |
14f9c5c9 | 973 | { |
61ee279c | 974 | type = ada_check_typedef (type); |
14f9c5c9 AS |
975 | |
976 | fprintf_filtered (stream, "("); | |
977 | ||
79a45b7d TT |
978 | if (print_field_values (type, valaddr, stream, recurse, options, |
979 | 0, type, valaddr) != 0 && options->pretty) | |
14f9c5c9 AS |
980 | { |
981 | fprintf_filtered (stream, "\n"); | |
982 | print_spaces_filtered (2 * recurse, stream); | |
983 | } | |
984 | ||
985 | fprintf_filtered (stream, ")"); | |
986 | } | |
987 | ||
988 | /* Print out fields of value at VALADDR having structure type TYPE. | |
4c4b4cd2 | 989 | |
79a45b7d | 990 | TYPE, VALADDR, STREAM, RECURSE, and OPTIONS have the |
4c4b4cd2 | 991 | same meanings as in ada_print_value and ada_val_print. |
14f9c5c9 AS |
992 | |
993 | OUTER_TYPE and OUTER_VALADDR give type and address of enclosing record | |
994 | (used to get discriminant values when printing variant parts). | |
995 | ||
4c4b4cd2 | 996 | COMMA_NEEDED is 1 if fields have been printed at the current recursion |
14f9c5c9 | 997 | level, so that a comma is needed before any field printed by this |
4c4b4cd2 | 998 | call. |
14f9c5c9 | 999 | |
4c4b4cd2 | 1000 | Returns 1 if COMMA_NEEDED or any fields were printed. */ |
14f9c5c9 AS |
1001 | |
1002 | static int | |
fc1a4b47 | 1003 | print_field_values (struct type *type, const gdb_byte *valaddr, |
79a45b7d TT |
1004 | struct ui_file *stream, int recurse, |
1005 | const struct value_print_options *options, | |
1006 | int comma_needed, | |
fc1a4b47 | 1007 | struct type *outer_type, const gdb_byte *outer_valaddr) |
14f9c5c9 AS |
1008 | { |
1009 | int i, len; | |
1010 | ||
1011 | len = TYPE_NFIELDS (type); | |
1012 | ||
1013 | for (i = 0; i < len; i += 1) | |
1014 | { | |
1015 | if (ada_is_ignored_field (type, i)) | |
d2e4a39e | 1016 | continue; |
14f9c5c9 AS |
1017 | |
1018 | if (ada_is_wrapper_field (type, i)) | |
1019 | { | |
d2e4a39e | 1020 | comma_needed = |
14f9c5c9 | 1021 | print_field_values (TYPE_FIELD_TYPE (type, i), |
d2e4a39e | 1022 | valaddr |
14f9c5c9 | 1023 | + TYPE_FIELD_BITPOS (type, i) / HOST_CHAR_BIT, |
79a45b7d | 1024 | stream, recurse, options, |
14f9c5c9 AS |
1025 | comma_needed, type, valaddr); |
1026 | continue; | |
1027 | } | |
1028 | else if (ada_is_variant_part (type, i)) | |
1029 | { | |
1030 | comma_needed = | |
1031 | print_variant_part (type, i, valaddr, | |
79a45b7d | 1032 | stream, recurse, options, comma_needed, |
14f9c5c9 AS |
1033 | outer_type, outer_valaddr); |
1034 | continue; | |
1035 | } | |
1036 | ||
1037 | if (comma_needed) | |
1038 | fprintf_filtered (stream, ", "); | |
1039 | comma_needed = 1; | |
1040 | ||
79a45b7d | 1041 | if (options->pretty) |
14f9c5c9 AS |
1042 | { |
1043 | fprintf_filtered (stream, "\n"); | |
1044 | print_spaces_filtered (2 + 2 * recurse, stream); | |
1045 | } | |
d2e4a39e | 1046 | else |
14f9c5c9 AS |
1047 | { |
1048 | wrap_here (n_spaces (2 + 2 * recurse)); | |
1049 | } | |
79a45b7d | 1050 | if (options->inspect_it) |
14f9c5c9 AS |
1051 | { |
1052 | if (TYPE_CODE (TYPE_FIELD_TYPE (type, i)) == TYPE_CODE_PTR) | |
1053 | fputs_filtered ("\"( ptr \"", stream); | |
1054 | else | |
1055 | fputs_filtered ("\"( nodef \"", stream); | |
1056 | fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i), | |
1057 | language_cplus, DMGL_NO_OPTS); | |
1058 | fputs_filtered ("\" \"", stream); | |
1059 | fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i), | |
1060 | language_cplus, DMGL_NO_OPTS); | |
1061 | fputs_filtered ("\") \"", stream); | |
1062 | } | |
1063 | else | |
1064 | { | |
1065 | annotate_field_begin (TYPE_FIELD_TYPE (type, i)); | |
d2e4a39e | 1066 | fprintf_filtered (stream, "%.*s", |
14f9c5c9 AS |
1067 | ada_name_prefix_len (TYPE_FIELD_NAME (type, i)), |
1068 | TYPE_FIELD_NAME (type, i)); | |
1069 | annotate_field_name_end (); | |
1070 | fputs_filtered (" => ", stream); | |
1071 | annotate_field_value (); | |
1072 | } | |
1073 | ||
1074 | if (TYPE_FIELD_PACKED (type, i)) | |
1075 | { | |
d2e4a39e | 1076 | struct value *v; |
14f9c5c9 AS |
1077 | |
1078 | /* Bitfields require special handling, especially due to byte | |
1079 | order problems. */ | |
b4ba55a1 | 1080 | if (HAVE_CPLUS_STRUCT (type) && TYPE_FIELD_IGNORE (type, i)) |
14f9c5c9 | 1081 | { |
edefbb7c | 1082 | fputs_filtered (_("<optimized out or zero length>"), stream); |
14f9c5c9 AS |
1083 | } |
1084 | else | |
1085 | { | |
1086 | int bit_pos = TYPE_FIELD_BITPOS (type, i); | |
1087 | int bit_size = TYPE_FIELD_BITSIZE (type, i); | |
79a45b7d | 1088 | struct value_print_options opts; |
d2e4a39e | 1089 | |
14f9c5c9 AS |
1090 | adjust_type_signedness (TYPE_FIELD_TYPE (type, i)); |
1091 | v = ada_value_primitive_packed_val (NULL, valaddr, | |
1092 | bit_pos / HOST_CHAR_BIT, | |
1093 | bit_pos % HOST_CHAR_BIT, | |
d2e4a39e | 1094 | bit_size, |
14f9c5c9 | 1095 | TYPE_FIELD_TYPE (type, i)); |
79a45b7d TT |
1096 | opts = *options; |
1097 | opts.deref_ref = 0; | |
0fd88904 | 1098 | val_print (TYPE_FIELD_TYPE (type, i), value_contents (v), 0, 0, |
79a45b7d | 1099 | stream, recurse + 1, &opts, current_language); |
14f9c5c9 AS |
1100 | } |
1101 | } | |
1102 | else | |
79a45b7d TT |
1103 | { |
1104 | struct value_print_options opts = *options; | |
1105 | opts.deref_ref = 0; | |
1106 | ada_val_print (TYPE_FIELD_TYPE (type, i), | |
1107 | valaddr + TYPE_FIELD_BITPOS (type, i) / HOST_CHAR_BIT, | |
1108 | 0, 0, stream, recurse + 1, &opts); | |
1109 | } | |
14f9c5c9 AS |
1110 | annotate_field_end (); |
1111 | } | |
1112 | ||
1113 | return comma_needed; | |
1114 | } |