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