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