]>
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 | |
490f124f PA |
39 | static void print_record (struct type *, const gdb_byte *, int, |
40 | struct ui_file *, | |
0e03807e TT |
41 | int, |
42 | const struct value *, | |
43 | const struct value_print_options *); | |
14f9c5c9 | 44 | |
fc1a4b47 | 45 | static int print_field_values (struct type *, const gdb_byte *, |
490f124f | 46 | int, |
79a45b7d | 47 | struct ui_file *, int, |
0e03807e | 48 | const struct value *, |
79a45b7d | 49 | const struct value_print_options *, |
490f124f | 50 | int, struct type *, int); |
14f9c5c9 | 51 | |
d2e4a39e | 52 | static void adjust_type_signedness (struct type *); |
14f9c5c9 | 53 | |
fc1a4b47 | 54 | static int ada_val_print_1 (struct type *, const gdb_byte *, int, CORE_ADDR, |
79a45b7d | 55 | struct ui_file *, int, |
0e03807e | 56 | const struct value *, |
79a45b7d | 57 | const struct value_print_options *); |
14f9c5c9 AS |
58 | \f |
59 | ||
4c4b4cd2 | 60 | /* Make TYPE unsigned if its range of values includes no negatives. */ |
d2e4a39e | 61 | static void |
4dc81987 | 62 | adjust_type_signedness (struct type *type) |
14f9c5c9 | 63 | { |
d2e4a39e | 64 | if (type != NULL && TYPE_CODE (type) == TYPE_CODE_RANGE |
14f9c5c9 | 65 | && TYPE_LOW_BOUND (type) >= 0) |
876cecd0 | 66 | TYPE_UNSIGNED (type) = 1; |
d2e4a39e | 67 | } |
14f9c5c9 | 68 | |
e936309c JB |
69 | /* Assuming TYPE is a simple array type, prints its lower bound on STREAM, |
70 | if non-standard (i.e., other than 1 for numbers, other than lower bound | |
71 | of index type for enumerated type). Returns 1 if something printed, | |
72 | otherwise 0. */ | |
14f9c5c9 | 73 | |
d2e4a39e | 74 | static int |
79a45b7d TT |
75 | print_optional_low_bound (struct ui_file *stream, struct type *type, |
76 | const struct value_print_options *options) | |
14f9c5c9 AS |
77 | { |
78 | struct type *index_type; | |
df178451 PM |
79 | LONGEST low_bound; |
80 | LONGEST high_bound; | |
14f9c5c9 | 81 | |
79a45b7d | 82 | if (options->print_array_indexes) |
14f9c5c9 | 83 | return 0; |
e79af960 | 84 | |
e936309c JB |
85 | if (!get_array_bounds (type, &low_bound, &high_bound)) |
86 | return 0; | |
87 | ||
88 | /* If this is an empty array, then don't print the lower bound. | |
89 | That would be confusing, because we would print the lower bound, | |
90 | followed by... nothing! */ | |
91 | if (low_bound > high_bound) | |
14f9c5c9 | 92 | return 0; |
d2e4a39e | 93 | |
e79af960 JB |
94 | index_type = TYPE_INDEX_TYPE (type); |
95 | ||
fd1b946e JB |
96 | if (TYPE_CODE (index_type) == TYPE_CODE_RANGE) |
97 | { | |
98 | /* We need to know what the base type is, in order to do the | |
99 | appropriate check below. Otherwise, if this is a subrange | |
100 | of an enumerated type, where the underlying value of the | |
101 | first element is typically 0, we might test the low bound | |
102 | against the wrong value. */ | |
103 | index_type = TYPE_TARGET_TYPE (index_type); | |
104 | } | |
105 | ||
d2e4a39e AS |
106 | switch (TYPE_CODE (index_type)) |
107 | { | |
690cc4eb PH |
108 | case TYPE_CODE_BOOL: |
109 | if (low_bound == 0) | |
110 | return 0; | |
111 | break; | |
d2e4a39e AS |
112 | case TYPE_CODE_ENUM: |
113 | if (low_bound == TYPE_FIELD_BITPOS (index_type, 0)) | |
114 | return 0; | |
115 | break; | |
116 | case TYPE_CODE_UNDEF: | |
7c964f07 | 117 | index_type = NULL; |
d2e4a39e AS |
118 | /* FALL THROUGH */ |
119 | default: | |
120 | if (low_bound == 1) | |
121 | return 0; | |
122 | break; | |
123 | } | |
14f9c5c9 | 124 | |
df178451 | 125 | ada_print_scalar (index_type, low_bound, stream); |
14f9c5c9 AS |
126 | fprintf_filtered (stream, " => "); |
127 | return 1; | |
128 | } | |
129 | ||
130 | /* Version of val_print_array_elements for GNAT-style packed arrays. | |
131 | Prints elements of packed array of type TYPE at bit offset | |
79a45b7d | 132 | BITOFFSET from VALADDR on STREAM. Formats according to OPTIONS and |
4c4b4cd2 | 133 | separates with commas. RECURSE is the recursion (nesting) level. |
79a45b7d | 134 | TYPE must have been decoded (as by ada_coerce_to_simple_array). */ |
14f9c5c9 AS |
135 | |
136 | static void | |
fc1a4b47 | 137 | val_print_packed_array_elements (struct type *type, const gdb_byte *valaddr, |
490f124f | 138 | int offset, |
ebf56fd3 | 139 | int bitoffset, struct ui_file *stream, |
79a45b7d | 140 | int recurse, |
0e03807e | 141 | const struct value *val, |
79a45b7d | 142 | const struct value_print_options *options) |
14f9c5c9 AS |
143 | { |
144 | unsigned int i; | |
145 | unsigned int things_printed = 0; | |
146 | unsigned len; | |
e79af960 | 147 | struct type *elttype, *index_type; |
14f9c5c9 | 148 | unsigned eltlen; |
14f9c5c9 | 149 | unsigned long bitsize = TYPE_FIELD_BITSIZE (type, 0); |
d2e4a39e | 150 | struct value *mark = value_mark (); |
e79af960 | 151 | LONGEST low = 0; |
d2e4a39e | 152 | |
14f9c5c9 AS |
153 | elttype = TYPE_TARGET_TYPE (type); |
154 | eltlen = TYPE_LENGTH (check_typedef (elttype)); | |
e79af960 | 155 | index_type = TYPE_INDEX_TYPE (type); |
14f9c5c9 AS |
156 | |
157 | { | |
e79af960 | 158 | LONGEST high; |
5b4ee69b | 159 | |
262452ec | 160 | if (get_discrete_bounds (index_type, &low, &high) < 0) |
14f9c5c9 AS |
161 | len = 1; |
162 | else | |
163 | len = high - low + 1; | |
164 | } | |
165 | ||
166 | i = 0; | |
167 | annotate_array_section_begin (i, elttype); | |
168 | ||
79a45b7d | 169 | while (i < len && things_printed < options->print_max) |
14f9c5c9 AS |
170 | { |
171 | struct value *v0, *v1; | |
172 | int i0; | |
173 | ||
174 | if (i != 0) | |
175 | { | |
79a45b7d | 176 | if (options->prettyprint_arrays) |
14f9c5c9 AS |
177 | { |
178 | fprintf_filtered (stream, ",\n"); | |
179 | print_spaces_filtered (2 + 2 * recurse, stream); | |
180 | } | |
181 | else | |
182 | { | |
183 | fprintf_filtered (stream, ", "); | |
184 | } | |
185 | } | |
186 | wrap_here (n_spaces (2 + 2 * recurse)); | |
79a45b7d | 187 | maybe_print_array_index (index_type, i + low, stream, options); |
14f9c5c9 AS |
188 | |
189 | i0 = i; | |
490f124f | 190 | v0 = ada_value_primitive_packed_val (NULL, valaddr + offset, |
14f9c5c9 AS |
191 | (i0 * bitsize) / HOST_CHAR_BIT, |
192 | (i0 * bitsize) % HOST_CHAR_BIT, | |
193 | bitsize, elttype); | |
194 | while (1) | |
195 | { | |
196 | i += 1; | |
197 | if (i >= len) | |
198 | break; | |
490f124f | 199 | v1 = ada_value_primitive_packed_val (NULL, valaddr + offset, |
14f9c5c9 AS |
200 | (i * bitsize) / HOST_CHAR_BIT, |
201 | (i * bitsize) % HOST_CHAR_BIT, | |
202 | bitsize, elttype); | |
c8c1c22f PA |
203 | if (!value_available_contents_eq (v0, value_embedded_offset (v0), |
204 | v1, value_embedded_offset (v1), | |
205 | eltlen)) | |
14f9c5c9 AS |
206 | break; |
207 | } | |
208 | ||
79a45b7d | 209 | if (i - i0 > options->repeat_count_threshold) |
14f9c5c9 | 210 | { |
79a45b7d | 211 | struct value_print_options opts = *options; |
5b4ee69b | 212 | |
79a45b7d | 213 | opts.deref_ref = 0; |
490f124f PA |
214 | val_print (elttype, value_contents_for_printing (v0), |
215 | value_embedded_offset (v0), 0, stream, | |
a491d753 | 216 | recurse + 1, v0, &opts, current_language); |
14f9c5c9 | 217 | annotate_elt_rep (i - i0); |
edefbb7c | 218 | fprintf_filtered (stream, _(" <repeats %u times>"), i - i0); |
14f9c5c9 AS |
219 | annotate_elt_rep_end (); |
220 | ||
221 | } | |
222 | else | |
223 | { | |
224 | int j; | |
79a45b7d | 225 | struct value_print_options opts = *options; |
5b4ee69b | 226 | |
79a45b7d | 227 | opts.deref_ref = 0; |
14f9c5c9 AS |
228 | for (j = i0; j < i; j += 1) |
229 | { | |
d2e4a39e | 230 | if (j > i0) |
14f9c5c9 | 231 | { |
79a45b7d | 232 | if (options->prettyprint_arrays) |
14f9c5c9 AS |
233 | { |
234 | fprintf_filtered (stream, ",\n"); | |
235 | print_spaces_filtered (2 + 2 * recurse, stream); | |
236 | } | |
237 | else | |
238 | { | |
239 | fprintf_filtered (stream, ", "); | |
240 | } | |
241 | wrap_here (n_spaces (2 + 2 * recurse)); | |
e79af960 | 242 | maybe_print_array_index (index_type, j + low, |
79a45b7d | 243 | stream, options); |
14f9c5c9 | 244 | } |
490f124f PA |
245 | val_print (elttype, value_contents_for_printing (v0), |
246 | value_embedded_offset (v0), 0, stream, | |
a491d753 | 247 | recurse + 1, v0, &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 | |
4ffa5a33 | 270 | 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 | 275 | { |
4ffa5a33 JB |
276 | /* If this character fits in the normal ASCII range, and is |
277 | a printable character, then print the character as if it was | |
278 | an ASCII character, even if this is a wide character. | |
279 | The UCHAR_MAX check is necessary because the isascii function | |
280 | requires that its argument have a value of an unsigned char, | |
281 | or EOF (EOF is obviously not printable). */ | |
282 | if (c <= UCHAR_MAX && isascii (c) && isprint (c)) | |
14f9c5c9 AS |
283 | { |
284 | if (c == quoter && c == '"') | |
529cad9c | 285 | fprintf_filtered (stream, "\"\""); |
14f9c5c9 AS |
286 | else |
287 | fprintf_filtered (stream, "%c", c); | |
288 | } | |
289 | else | |
d2e4a39e | 290 | fprintf_filtered (stream, "[\"%0*x\"]", type_len * 2, c); |
14f9c5c9 AS |
291 | } |
292 | ||
4ffa5a33 JB |
293 | /* Character #I of STRING, given that TYPE_LEN is the size in bytes |
294 | of a character. */ | |
14f9c5c9 AS |
295 | |
296 | static int | |
e17a4113 UW |
297 | char_at (const gdb_byte *string, int i, int type_len, |
298 | enum bfd_endian byte_order) | |
14f9c5c9 AS |
299 | { |
300 | if (type_len == 1) | |
301 | return string[i]; | |
d2e4a39e | 302 | else |
4ffa5a33 JB |
303 | return (int) extract_unsigned_integer (string + type_len * i, |
304 | type_len, byte_order); | |
14f9c5c9 AS |
305 | } |
306 | ||
0963b4bd | 307 | /* Wrapper around memcpy to make it legal argument to ui_file_put. */ |
4c4b4cd2 PH |
308 | static void |
309 | ui_memcpy (void *dest, const char *buffer, long len) | |
310 | { | |
311 | memcpy (dest, buffer, (size_t) len); | |
312 | ((char *) dest)[len] = '\0'; | |
313 | } | |
314 | ||
315 | /* Print a floating-point value of type TYPE, pointed to in GDB by | |
316 | VALADDR, on STREAM. Use Ada formatting conventions: there must be | |
317 | a decimal point, and at least one digit before and after the | |
318 | point. We use GNAT format for NaNs and infinities. */ | |
319 | static void | |
fc1a4b47 | 320 | ada_print_floating (const gdb_byte *valaddr, struct type *type, |
a2bd3dcd | 321 | struct ui_file *stream) |
4c4b4cd2 PH |
322 | { |
323 | char buffer[64]; | |
324 | char *s, *result; | |
325 | int len; | |
326 | struct ui_file *tmp_stream = mem_fileopen (); | |
327 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_stream); | |
328 | ||
329 | print_floating (valaddr, type, tmp_stream); | |
330 | ui_file_put (tmp_stream, ui_memcpy, buffer); | |
331 | do_cleanups (cleanups); | |
332 | ||
333 | result = buffer; | |
334 | len = strlen (result); | |
335 | ||
336 | /* Modify for Ada rules. */ | |
606b8d1a | 337 | |
c3e5cd34 PH |
338 | s = strstr (result, "inf"); |
339 | if (s == NULL) | |
340 | s = strstr (result, "Inf"); | |
341 | if (s == NULL) | |
342 | s = strstr (result, "INF"); | |
343 | if (s != NULL) | |
4c4b4cd2 | 344 | strcpy (s, "Inf"); |
c3e5cd34 PH |
345 | |
346 | if (s == NULL) | |
4c4b4cd2 | 347 | { |
c3e5cd34 PH |
348 | s = strstr (result, "nan"); |
349 | if (s == NULL) | |
350 | s = strstr (result, "NaN"); | |
351 | if (s == NULL) | |
352 | s = strstr (result, "Nan"); | |
353 | if (s != NULL) | |
354 | { | |
355 | s[0] = s[2] = 'N'; | |
356 | if (result[0] == '-') | |
357 | result += 1; | |
358 | } | |
4c4b4cd2 | 359 | } |
c3e5cd34 PH |
360 | |
361 | if (s == NULL && strchr (result, '.') == NULL) | |
4c4b4cd2 | 362 | { |
c3e5cd34 PH |
363 | s = strchr (result, 'e'); |
364 | if (s == NULL) | |
4c4b4cd2 PH |
365 | fprintf_filtered (stream, "%s.0", result); |
366 | else | |
367 | fprintf_filtered (stream, "%.*s.0%s", (int) (s-result), result, s); | |
368 | return; | |
369 | } | |
370 | fprintf_filtered (stream, "%s", result); | |
371 | } | |
372 | ||
14f9c5c9 | 373 | void |
6c7a06a3 | 374 | ada_printchar (int c, struct type *type, struct ui_file *stream) |
14f9c5c9 AS |
375 | { |
376 | fputs_filtered ("'", stream); | |
447b483c | 377 | ada_emit_char (c, type, stream, '\'', TYPE_LENGTH (type)); |
14f9c5c9 AS |
378 | fputs_filtered ("'", stream); |
379 | } | |
380 | ||
381 | /* [From print_type_scalar in typeprint.c]. Print VAL on STREAM in a | |
7c964f07 UW |
382 | form appropriate for TYPE, if non-NULL. If TYPE is NULL, print VAL |
383 | like a default signed integer. */ | |
14f9c5c9 AS |
384 | |
385 | void | |
ebf56fd3 | 386 | ada_print_scalar (struct type *type, LONGEST val, struct ui_file *stream) |
14f9c5c9 AS |
387 | { |
388 | unsigned int i; | |
389 | unsigned len; | |
390 | ||
7c964f07 UW |
391 | if (!type) |
392 | { | |
393 | print_longest (stream, 'd', 0, val); | |
394 | return; | |
395 | } | |
396 | ||
61ee279c | 397 | type = ada_check_typedef (type); |
14f9c5c9 AS |
398 | |
399 | switch (TYPE_CODE (type)) | |
400 | { | |
401 | ||
402 | case TYPE_CODE_ENUM: | |
403 | len = TYPE_NFIELDS (type); | |
404 | for (i = 0; i < len; i++) | |
405 | { | |
406 | if (TYPE_FIELD_BITPOS (type, i) == val) | |
407 | { | |
408 | break; | |
409 | } | |
410 | } | |
411 | if (i < len) | |
412 | { | |
413 | fputs_filtered (ada_enum_name (TYPE_FIELD_NAME (type, i)), stream); | |
414 | } | |
415 | else | |
416 | { | |
417 | print_longest (stream, 'd', 0, val); | |
418 | } | |
419 | break; | |
420 | ||
421 | case TYPE_CODE_INT: | |
422 | print_longest (stream, TYPE_UNSIGNED (type) ? 'u' : 'd', 0, val); | |
423 | break; | |
424 | ||
425 | case TYPE_CODE_CHAR: | |
10d44370 | 426 | LA_PRINT_CHAR (val, type, stream); |
14f9c5c9 AS |
427 | break; |
428 | ||
429 | case TYPE_CODE_BOOL: | |
430 | fprintf_filtered (stream, val ? "true" : "false"); | |
431 | break; | |
432 | ||
433 | case TYPE_CODE_RANGE: | |
434 | ada_print_scalar (TYPE_TARGET_TYPE (type), val, stream); | |
435 | return; | |
436 | ||
437 | case TYPE_CODE_UNDEF: | |
438 | case TYPE_CODE_PTR: | |
439 | case TYPE_CODE_ARRAY: | |
440 | case TYPE_CODE_STRUCT: | |
441 | case TYPE_CODE_UNION: | |
442 | case TYPE_CODE_FUNC: | |
443 | case TYPE_CODE_FLT: | |
444 | case TYPE_CODE_VOID: | |
445 | case TYPE_CODE_SET: | |
446 | case TYPE_CODE_STRING: | |
447 | case TYPE_CODE_ERROR: | |
0d5de010 DJ |
448 | case TYPE_CODE_MEMBERPTR: |
449 | case TYPE_CODE_METHODPTR: | |
14f9c5c9 AS |
450 | case TYPE_CODE_METHOD: |
451 | case TYPE_CODE_REF: | |
edefbb7c | 452 | warning (_("internal error: unhandled type in ada_print_scalar")); |
14f9c5c9 AS |
453 | break; |
454 | ||
455 | default: | |
edefbb7c | 456 | error (_("Invalid type code in symbol table.")); |
14f9c5c9 AS |
457 | } |
458 | gdb_flush (stream); | |
459 | } | |
460 | ||
461 | /* Print the character string STRING, printing at most LENGTH characters. | |
462 | Printing stops early if the number hits print_max; repeat counts | |
463 | are printed as appropriate. Print ellipses at the end if we | |
9a153e0b JB |
464 | had to stop before printing LENGTH characters, or if FORCE_ELLIPSES. |
465 | TYPE_LEN is the length (1 or 2) of the character type. */ | |
14f9c5c9 AS |
466 | |
467 | static void | |
6c7a06a3 | 468 | printstr (struct ui_file *stream, struct type *elttype, const gdb_byte *string, |
79a45b7d TT |
469 | unsigned int length, int force_ellipses, int type_len, |
470 | const struct value_print_options *options) | |
14f9c5c9 | 471 | { |
e17a4113 | 472 | enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (elttype)); |
14f9c5c9 AS |
473 | unsigned int i; |
474 | unsigned int things_printed = 0; | |
475 | int in_quotes = 0; | |
476 | int need_comma = 0; | |
477 | ||
478 | if (length == 0) | |
479 | { | |
480 | fputs_filtered ("\"\"", stream); | |
481 | return; | |
482 | } | |
483 | ||
79a45b7d | 484 | for (i = 0; i < length && things_printed < options->print_max; i += 1) |
14f9c5c9 AS |
485 | { |
486 | /* Position of the character we are examining | |
d2e4a39e | 487 | to see whether it is repeated. */ |
14f9c5c9 AS |
488 | unsigned int rep1; |
489 | /* Number of repetitions we have detected so far. */ | |
490 | unsigned int reps; | |
491 | ||
492 | QUIT; | |
493 | ||
494 | if (need_comma) | |
495 | { | |
496 | fputs_filtered (", ", stream); | |
497 | need_comma = 0; | |
498 | } | |
499 | ||
500 | rep1 = i + 1; | |
501 | reps = 1; | |
c3e5cd34 | 502 | while (rep1 < length |
e17a4113 UW |
503 | && char_at (string, rep1, type_len, byte_order) |
504 | == char_at (string, i, type_len, byte_order)) | |
14f9c5c9 AS |
505 | { |
506 | rep1 += 1; | |
507 | reps += 1; | |
508 | } | |
509 | ||
79a45b7d | 510 | if (reps > options->repeat_count_threshold) |
14f9c5c9 AS |
511 | { |
512 | if (in_quotes) | |
513 | { | |
79a45b7d | 514 | if (options->inspect_it) |
14f9c5c9 AS |
515 | fputs_filtered ("\\\", ", stream); |
516 | else | |
517 | fputs_filtered ("\", ", stream); | |
518 | in_quotes = 0; | |
519 | } | |
520 | fputs_filtered ("'", stream); | |
e17a4113 UW |
521 | ada_emit_char (char_at (string, i, type_len, byte_order), |
522 | elttype, stream, '\'', type_len); | |
14f9c5c9 | 523 | fputs_filtered ("'", stream); |
edefbb7c | 524 | fprintf_filtered (stream, _(" <repeats %u times>"), reps); |
14f9c5c9 | 525 | i = rep1 - 1; |
79a45b7d | 526 | things_printed += options->repeat_count_threshold; |
14f9c5c9 AS |
527 | need_comma = 1; |
528 | } | |
529 | else | |
530 | { | |
531 | if (!in_quotes) | |
532 | { | |
79a45b7d | 533 | if (options->inspect_it) |
14f9c5c9 AS |
534 | fputs_filtered ("\\\"", stream); |
535 | else | |
536 | fputs_filtered ("\"", stream); | |
537 | in_quotes = 1; | |
538 | } | |
e17a4113 UW |
539 | ada_emit_char (char_at (string, i, type_len, byte_order), |
540 | elttype, stream, '"', type_len); | |
14f9c5c9 AS |
541 | things_printed += 1; |
542 | } | |
543 | } | |
544 | ||
545 | /* Terminate the quotes if necessary. */ | |
546 | if (in_quotes) | |
547 | { | |
79a45b7d | 548 | if (options->inspect_it) |
14f9c5c9 AS |
549 | fputs_filtered ("\\\"", stream); |
550 | else | |
551 | fputs_filtered ("\"", stream); | |
552 | } | |
553 | ||
554 | if (force_ellipses || i < length) | |
555 | fputs_filtered ("...", stream); | |
556 | } | |
557 | ||
558 | void | |
0963b4bd MS |
559 | ada_printstr (struct ui_file *stream, struct type *type, |
560 | const gdb_byte *string, unsigned int length, | |
561 | const char *encoding, int force_ellipses, | |
79a45b7d | 562 | const struct value_print_options *options) |
14f9c5c9 | 563 | { |
6c7a06a3 TT |
564 | printstr (stream, type, string, length, force_ellipses, TYPE_LENGTH (type), |
565 | options); | |
14f9c5c9 AS |
566 | } |
567 | ||
568 | ||
32b72a42 PA |
569 | /* See val_print for a description of the various parameters of this |
570 | function; they are identical. The semantics of the return value is | |
571 | also identical to val_print. */ | |
14f9c5c9 AS |
572 | |
573 | int | |
490f124f | 574 | ada_val_print (struct type *type, const gdb_byte *valaddr, |
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 | |
490f124f | 583 | /* XXX: this catches QUIT/ctrl-c as well. Isn't that busted? */ |
0e03807e TT |
584 | TRY_CATCH (except, RETURN_MASK_ALL) |
585 | { | |
490f124f | 586 | result = ada_val_print_1 (type, valaddr, embedded_offset, address, |
0e03807e TT |
587 | stream, recurse, val, options); |
588 | } | |
5b4ee69b | 589 | |
0e03807e TT |
590 | if (except.reason < 0) |
591 | result = 0; | |
592 | ||
593 | return result; | |
14f9c5c9 AS |
594 | } |
595 | ||
e936309c | 596 | /* Assuming TYPE is a simple array, print the value of this array located |
32b72a42 | 597 | at VALADDR + OFFSET. See ada_val_print for a description of the various |
e936309c JB |
598 | parameters of this function; they are identical. The semantics |
599 | of the return value is also identical to ada_val_print. */ | |
600 | ||
601 | static int | |
602 | ada_val_print_array (struct type *type, const gdb_byte *valaddr, | |
490f124f PA |
603 | int offset, CORE_ADDR address, |
604 | struct ui_file *stream, int recurse, | |
0e03807e | 605 | const struct value *val, |
79a45b7d | 606 | const struct value_print_options *options) |
e936309c | 607 | { |
e17a4113 | 608 | enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type)); |
e936309c | 609 | struct type *elttype = TYPE_TARGET_TYPE (type); |
e936309c JB |
610 | int result = 0; |
611 | ||
e936309c | 612 | /* For an array of chars, print with string syntax. */ |
79a45b7d TT |
613 | if (ada_is_string_type (type) |
614 | && (options->format == 0 || options->format == 's')) | |
e936309c | 615 | { |
9addb3b9 JB |
616 | unsigned int eltlen; |
617 | unsigned int len; | |
618 | ||
619 | if (elttype == NULL) | |
620 | eltlen = 0; | |
621 | else | |
622 | eltlen = TYPE_LENGTH (elttype); | |
623 | if (eltlen == 0) | |
624 | len = 0; | |
625 | else | |
626 | len = TYPE_LENGTH (type) / eltlen; | |
627 | ||
79a45b7d | 628 | if (options->prettyprint_arrays) |
e936309c JB |
629 | print_spaces_filtered (2 + 2 * recurse, stream); |
630 | ||
631 | /* If requested, look for the first null char and only print | |
632 | elements up to it. */ | |
79a45b7d | 633 | if (options->stop_print_at_null) |
e936309c JB |
634 | { |
635 | int temp_len; | |
636 | ||
637 | /* Look for a NULL char. */ | |
638 | for (temp_len = 0; | |
639 | (temp_len < len | |
79a45b7d | 640 | && temp_len < options->print_max |
490f124f PA |
641 | && char_at (valaddr + offset, |
642 | temp_len, eltlen, byte_order) != 0); | |
e936309c JB |
643 | temp_len += 1); |
644 | len = temp_len; | |
645 | } | |
646 | ||
490f124f | 647 | printstr (stream, elttype, valaddr + offset, len, 0, eltlen, options); |
e936309c JB |
648 | result = len; |
649 | } | |
650 | else | |
651 | { | |
652 | fprintf_filtered (stream, "("); | |
79a45b7d | 653 | print_optional_low_bound (stream, type, options); |
e936309c | 654 | if (TYPE_FIELD_BITSIZE (type, 0) > 0) |
490f124f PA |
655 | val_print_packed_array_elements (type, valaddr, offset, |
656 | 0, stream, recurse, val, options); | |
e936309c | 657 | else |
490f124f PA |
658 | val_print_array_elements (type, valaddr, offset, address, |
659 | stream, recurse, val, options, 0); | |
e936309c JB |
660 | fprintf_filtered (stream, ")"); |
661 | } | |
662 | ||
663 | return result; | |
664 | } | |
665 | ||
14f9c5c9 | 666 | /* See the comment on ada_val_print. This function differs in that it |
e936309c | 667 | does not catch evaluation errors (leaving that to ada_val_print). */ |
14f9c5c9 AS |
668 | |
669 | static int | |
490f124f PA |
670 | ada_val_print_1 (struct type *type, const gdb_byte *valaddr, |
671 | int offset, CORE_ADDR address, | |
79a45b7d | 672 | struct ui_file *stream, int recurse, |
0e03807e | 673 | const struct value *original_value, |
79a45b7d | 674 | const struct value_print_options *options) |
14f9c5c9 AS |
675 | { |
676 | unsigned int len; | |
677 | int i; | |
678 | struct type *elttype; | |
14f9c5c9 | 679 | LONGEST val; |
490f124f | 680 | int offset_aligned; |
14f9c5c9 | 681 | |
61ee279c | 682 | type = ada_check_typedef (type); |
14f9c5c9 | 683 | |
ad82864c JB |
684 | if (ada_is_array_descriptor_type (type) |
685 | || ada_is_constrained_packed_array_type (type)) | |
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 | { | |
490f124f PA |
900 | CORE_ADDR deref_val_int |
901 | = unpack_pointer (type, valaddr + offset_aligned); | |
5b4ee69b | 902 | |
969a1360 JB |
903 | if (deref_val_int != 0) |
904 | { | |
905 | struct value *deref_val = | |
490f124f | 906 | ada_value_ind (value_from_pointer |
969a1360 JB |
907 | (lookup_pointer_type (elttype), |
908 | deref_val_int)); | |
5b4ee69b | 909 | |
969a1360 | 910 | val_print (value_type (deref_val), |
490f124f PA |
911 | value_contents_for_printing (deref_val), |
912 | value_embedded_offset (deref_val), | |
42ae5230 | 913 | value_address (deref_val), stream, recurse + 1, |
a491d753 | 914 | deref_val, options, current_language); |
969a1360 JB |
915 | } |
916 | else | |
917 | fputs_filtered ("(null)", stream); | |
918 | } | |
919 | else | |
920 | fputs_filtered ("???", stream); | |
921 | ||
14f9c5c9 AS |
922 | break; |
923 | } | |
4c4b4cd2 | 924 | gdb_flush (stream); |
14f9c5c9 AS |
925 | return 0; |
926 | } | |
927 | ||
928 | static int | |
490f124f PA |
929 | print_variant_part (struct type *type, int field_num, |
930 | const gdb_byte *valaddr, int offset, | |
79a45b7d | 931 | struct ui_file *stream, int recurse, |
0e03807e | 932 | const struct value *val, |
0963b4bd MS |
933 | const struct value_print_options *options, |
934 | int comma_needed, | |
490f124f | 935 | struct type *outer_type, int outer_offset) |
14f9c5c9 AS |
936 | { |
937 | struct type *var_type = TYPE_FIELD_TYPE (type, field_num); | |
490f124f PA |
938 | int which = ada_which_variant_applies (var_type, outer_type, |
939 | valaddr + outer_offset); | |
14f9c5c9 AS |
940 | |
941 | if (which < 0) | |
942 | return 0; | |
943 | else | |
d2e4a39e | 944 | return print_field_values |
14f9c5c9 | 945 | (TYPE_FIELD_TYPE (var_type, which), |
490f124f PA |
946 | valaddr, |
947 | offset + TYPE_FIELD_BITPOS (type, field_num) / HOST_CHAR_BIT | |
14f9c5c9 | 948 | + TYPE_FIELD_BITPOS (var_type, which) / HOST_CHAR_BIT, |
0e03807e | 949 | stream, recurse, val, options, |
490f124f | 950 | comma_needed, outer_type, outer_offset); |
14f9c5c9 AS |
951 | } |
952 | ||
953 | int | |
79a45b7d TT |
954 | ada_value_print (struct value *val0, struct ui_file *stream, |
955 | const struct value_print_options *options) | |
14f9c5c9 | 956 | { |
0c3acc09 JB |
957 | struct value *val = ada_to_fixed_value (val0); |
958 | CORE_ADDR address = value_address (val); | |
959 | struct type *type = value_type (val); | |
79a45b7d | 960 | struct value_print_options opts; |
14f9c5c9 | 961 | |
4c4b4cd2 PH |
962 | /* If it is a pointer, indicate what it points to. */ |
963 | if (TYPE_CODE (type) == TYPE_CODE_PTR) | |
14f9c5c9 | 964 | { |
4c4b4cd2 PH |
965 | /* Hack: don't print (char *) for char strings. Their |
966 | type is indicated by the quoted string anyway. */ | |
967 | if (TYPE_LENGTH (TYPE_TARGET_TYPE (type)) != sizeof (char) | |
968 | || TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_INT | |
969 | || TYPE_UNSIGNED (TYPE_TARGET_TYPE (type))) | |
14f9c5c9 AS |
970 | { |
971 | fprintf_filtered (stream, "("); | |
972 | type_print (type, "", stream, -1); | |
973 | fprintf_filtered (stream, ") "); | |
974 | } | |
975 | } | |
4c4b4cd2 | 976 | else if (ada_is_array_descriptor_type (type)) |
14f9c5c9 | 977 | { |
720d1a40 JB |
978 | /* We do not print the type description unless TYPE is an array |
979 | access type (this is encoded by the compiler as a typedef to | |
980 | a fat pointer - hence the check against TYPE_CODE_TYPEDEF). */ | |
981 | if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF) | |
982 | { | |
983 | fprintf_filtered (stream, "("); | |
984 | type_print (type, "", stream, -1); | |
985 | fprintf_filtered (stream, ") "); | |
986 | } | |
14f9c5c9 AS |
987 | } |
988 | else if (ada_is_bogus_array_descriptor (type)) | |
989 | { | |
990 | fprintf_filtered (stream, "("); | |
991 | type_print (type, "", stream, -1); | |
992 | fprintf_filtered (stream, ") (...?)"); | |
993 | return 0; | |
994 | } | |
4c4b4cd2 | 995 | |
79a45b7d TT |
996 | opts = *options; |
997 | opts.deref_ref = 1; | |
490f124f PA |
998 | return (val_print (type, value_contents_for_printing (val), |
999 | value_embedded_offset (val), address, | |
0e03807e | 1000 | stream, 0, val, &opts, current_language)); |
14f9c5c9 | 1001 | } |
d2e4a39e | 1002 | |
14f9c5c9 | 1003 | static void |
fc1a4b47 | 1004 | print_record (struct type *type, const gdb_byte *valaddr, |
490f124f | 1005 | int offset, |
79a45b7d | 1006 | struct ui_file *stream, int recurse, |
0e03807e | 1007 | const struct value *val, |
79a45b7d | 1008 | const struct value_print_options *options) |
14f9c5c9 | 1009 | { |
61ee279c | 1010 | type = ada_check_typedef (type); |
14f9c5c9 AS |
1011 | |
1012 | fprintf_filtered (stream, "("); | |
1013 | ||
490f124f PA |
1014 | if (print_field_values (type, valaddr, offset, |
1015 | stream, recurse, val, options, | |
1016 | 0, type, offset) != 0 && options->pretty) | |
14f9c5c9 AS |
1017 | { |
1018 | fprintf_filtered (stream, "\n"); | |
1019 | print_spaces_filtered (2 * recurse, stream); | |
1020 | } | |
1021 | ||
1022 | fprintf_filtered (stream, ")"); | |
1023 | } | |
1024 | ||
32b72a42 | 1025 | /* Print out fields of value at VALADDR + OFFSET having structure type TYPE. |
4c4b4cd2 | 1026 | |
32b72a42 PA |
1027 | TYPE, VALADDR, OFFSET, STREAM, RECURSE, and OPTIONS have the same |
1028 | meanings as in ada_print_value and ada_val_print. | |
14f9c5c9 | 1029 | |
32b72a42 PA |
1030 | OUTER_TYPE and OUTER_OFFSET give type and address of enclosing |
1031 | record (used to get discriminant values when printing variant | |
1032 | parts). | |
14f9c5c9 | 1033 | |
4c4b4cd2 | 1034 | COMMA_NEEDED is 1 if fields have been printed at the current recursion |
14f9c5c9 | 1035 | level, so that a comma is needed before any field printed by this |
4c4b4cd2 | 1036 | call. |
14f9c5c9 | 1037 | |
4c4b4cd2 | 1038 | Returns 1 if COMMA_NEEDED or any fields were printed. */ |
14f9c5c9 AS |
1039 | |
1040 | static int | |
fc1a4b47 | 1041 | print_field_values (struct type *type, const gdb_byte *valaddr, |
490f124f | 1042 | int offset, struct ui_file *stream, int recurse, |
0e03807e | 1043 | const struct value *val, |
79a45b7d TT |
1044 | const struct value_print_options *options, |
1045 | int comma_needed, | |
490f124f | 1046 | struct type *outer_type, int outer_offset) |
14f9c5c9 AS |
1047 | { |
1048 | int i, len; | |
1049 | ||
1050 | len = TYPE_NFIELDS (type); | |
1051 | ||
1052 | for (i = 0; i < len; i += 1) | |
1053 | { | |
1054 | if (ada_is_ignored_field (type, i)) | |
d2e4a39e | 1055 | continue; |
14f9c5c9 AS |
1056 | |
1057 | if (ada_is_wrapper_field (type, i)) | |
1058 | { | |
d2e4a39e | 1059 | comma_needed = |
14f9c5c9 | 1060 | print_field_values (TYPE_FIELD_TYPE (type, i), |
490f124f PA |
1061 | valaddr, |
1062 | (offset | |
1063 | + TYPE_FIELD_BITPOS (type, i) / HOST_CHAR_BIT), | |
0e03807e | 1064 | stream, recurse, val, options, |
490f124f | 1065 | comma_needed, type, offset); |
14f9c5c9 AS |
1066 | continue; |
1067 | } | |
1068 | else if (ada_is_variant_part (type, i)) | |
1069 | { | |
1070 | comma_needed = | |
1071 | print_variant_part (type, i, valaddr, | |
490f124f PA |
1072 | offset, stream, recurse, val, |
1073 | options, comma_needed, | |
1074 | outer_type, outer_offset); | |
14f9c5c9 AS |
1075 | continue; |
1076 | } | |
1077 | ||
1078 | if (comma_needed) | |
1079 | fprintf_filtered (stream, ", "); | |
1080 | comma_needed = 1; | |
1081 | ||
79a45b7d | 1082 | if (options->pretty) |
14f9c5c9 AS |
1083 | { |
1084 | fprintf_filtered (stream, "\n"); | |
1085 | print_spaces_filtered (2 + 2 * recurse, stream); | |
1086 | } | |
d2e4a39e | 1087 | else |
14f9c5c9 AS |
1088 | { |
1089 | wrap_here (n_spaces (2 + 2 * recurse)); | |
1090 | } | |
79a45b7d | 1091 | if (options->inspect_it) |
14f9c5c9 AS |
1092 | { |
1093 | if (TYPE_CODE (TYPE_FIELD_TYPE (type, i)) == TYPE_CODE_PTR) | |
1094 | fputs_filtered ("\"( ptr \"", stream); | |
1095 | else | |
1096 | fputs_filtered ("\"( nodef \"", stream); | |
1097 | fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i), | |
1098 | language_cplus, DMGL_NO_OPTS); | |
1099 | fputs_filtered ("\" \"", stream); | |
1100 | fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i), | |
1101 | language_cplus, DMGL_NO_OPTS); | |
1102 | fputs_filtered ("\") \"", stream); | |
1103 | } | |
1104 | else | |
1105 | { | |
1106 | annotate_field_begin (TYPE_FIELD_TYPE (type, i)); | |
d2e4a39e | 1107 | fprintf_filtered (stream, "%.*s", |
14f9c5c9 AS |
1108 | ada_name_prefix_len (TYPE_FIELD_NAME (type, i)), |
1109 | TYPE_FIELD_NAME (type, i)); | |
1110 | annotate_field_name_end (); | |
1111 | fputs_filtered (" => ", stream); | |
1112 | annotate_field_value (); | |
1113 | } | |
1114 | ||
1115 | if (TYPE_FIELD_PACKED (type, i)) | |
1116 | { | |
d2e4a39e | 1117 | struct value *v; |
14f9c5c9 AS |
1118 | |
1119 | /* Bitfields require special handling, especially due to byte | |
1120 | order problems. */ | |
b4ba55a1 | 1121 | if (HAVE_CPLUS_STRUCT (type) && TYPE_FIELD_IGNORE (type, i)) |
14f9c5c9 | 1122 | { |
edefbb7c | 1123 | fputs_filtered (_("<optimized out or zero length>"), stream); |
14f9c5c9 AS |
1124 | } |
1125 | else | |
1126 | { | |
1127 | int bit_pos = TYPE_FIELD_BITPOS (type, i); | |
1128 | int bit_size = TYPE_FIELD_BITSIZE (type, i); | |
79a45b7d | 1129 | struct value_print_options opts; |
d2e4a39e | 1130 | |
14f9c5c9 | 1131 | adjust_type_signedness (TYPE_FIELD_TYPE (type, i)); |
490f124f PA |
1132 | v = ada_value_primitive_packed_val |
1133 | (NULL, valaddr, | |
1134 | offset + bit_pos / HOST_CHAR_BIT, | |
1135 | bit_pos % HOST_CHAR_BIT, | |
1136 | bit_size, TYPE_FIELD_TYPE (type, i)); | |
79a45b7d TT |
1137 | opts = *options; |
1138 | opts.deref_ref = 0; | |
490f124f PA |
1139 | val_print (TYPE_FIELD_TYPE (type, i), |
1140 | value_contents_for_printing (v), | |
1141 | value_embedded_offset (v), 0, | |
0e03807e TT |
1142 | stream, recurse + 1, v, |
1143 | &opts, current_language); | |
14f9c5c9 AS |
1144 | } |
1145 | } | |
1146 | else | |
79a45b7d TT |
1147 | { |
1148 | struct value_print_options opts = *options; | |
5b4ee69b | 1149 | |
79a45b7d TT |
1150 | opts.deref_ref = 0; |
1151 | ada_val_print (TYPE_FIELD_TYPE (type, i), | |
490f124f PA |
1152 | valaddr, |
1153 | (offset | |
1154 | + TYPE_FIELD_BITPOS (type, i) / HOST_CHAR_BIT), | |
1155 | 0, stream, recurse + 1, val, &opts); | |
79a45b7d | 1156 | } |
14f9c5c9 AS |
1157 | annotate_field_end (); |
1158 | } | |
1159 | ||
1160 | return comma_needed; | |
1161 | } |