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