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, |
9b254dd1 | 4 | 2003, 2004, 2005, 2006, 2007, 2008 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" |
14f9c5c9 | 36 | |
4c4b4cd2 | 37 | /* Encapsulates arguments to ada_val_print. */ |
d2e4a39e AS |
38 | struct ada_val_print_args |
39 | { | |
40 | struct type *type; | |
fc1a4b47 | 41 | const gdb_byte *valaddr0; |
14f9c5c9 AS |
42 | int embedded_offset; |
43 | CORE_ADDR address; | |
44 | struct ui_file *stream; | |
45 | int format; | |
46 | int deref_ref; | |
47 | int recurse; | |
48 | enum val_prettyprint pretty; | |
49 | }; | |
50 | ||
fc1a4b47 | 51 | static void print_record (struct type *, const gdb_byte *, struct ui_file *, |
a2bd3dcd | 52 | int, int, enum val_prettyprint); |
14f9c5c9 | 53 | |
fc1a4b47 | 54 | static int print_field_values (struct type *, const gdb_byte *, |
d2e4a39e AS |
55 | struct ui_file *, int, int, |
56 | enum val_prettyprint, 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, |
d2e4a39e AS |
64 | struct ui_file *, int, int, int, |
65 | enum val_prettyprint); | |
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 AS |
73 | && TYPE_LOW_BOUND (type) >= 0) |
74 | TYPE_FLAGS (type) |= TYPE_FLAG_UNSIGNED; | |
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 |
ebf56fd3 | 83 | print_optional_low_bound (struct ui_file *stream, struct type *type) |
14f9c5c9 AS |
84 | { |
85 | struct type *index_type; | |
86 | long low_bound; | |
e936309c | 87 | long high_bound; |
14f9c5c9 | 88 | |
e79af960 | 89 | if (print_array_indexes_p ()) |
14f9c5c9 | 90 | return 0; |
e79af960 | 91 | |
e936309c JB |
92 | if (!get_array_bounds (type, &low_bound, &high_bound)) |
93 | return 0; | |
94 | ||
95 | /* If this is an empty array, then don't print the lower bound. | |
96 | That would be confusing, because we would print the lower bound, | |
97 | followed by... nothing! */ | |
98 | if (low_bound > high_bound) | |
14f9c5c9 | 99 | return 0; |
d2e4a39e | 100 | |
e79af960 JB |
101 | index_type = TYPE_INDEX_TYPE (type); |
102 | ||
fd1b946e JB |
103 | if (TYPE_CODE (index_type) == TYPE_CODE_RANGE) |
104 | { | |
105 | /* We need to know what the base type is, in order to do the | |
106 | appropriate check below. Otherwise, if this is a subrange | |
107 | of an enumerated type, where the underlying value of the | |
108 | first element is typically 0, we might test the low bound | |
109 | against the wrong value. */ | |
110 | index_type = TYPE_TARGET_TYPE (index_type); | |
111 | } | |
112 | ||
d2e4a39e AS |
113 | switch (TYPE_CODE (index_type)) |
114 | { | |
115 | case TYPE_CODE_ENUM: | |
116 | if (low_bound == TYPE_FIELD_BITPOS (index_type, 0)) | |
117 | return 0; | |
118 | break; | |
119 | case TYPE_CODE_UNDEF: | |
120 | index_type = builtin_type_long; | |
121 | /* FALL THROUGH */ | |
122 | default: | |
123 | if (low_bound == 1) | |
124 | return 0; | |
125 | break; | |
126 | } | |
14f9c5c9 AS |
127 | |
128 | ada_print_scalar (index_type, (LONGEST) low_bound, stream); | |
129 | fprintf_filtered (stream, " => "); | |
130 | return 1; | |
131 | } | |
132 | ||
133 | /* Version of val_print_array_elements for GNAT-style packed arrays. | |
134 | Prints elements of packed array of type TYPE at bit offset | |
135 | BITOFFSET from VALADDR on STREAM. Formats according to FORMAT and | |
4c4b4cd2 PH |
136 | separates with commas. RECURSE is the recursion (nesting) level. |
137 | If PRETTY, uses "prettier" format. TYPE must have been decoded (as | |
d2e4a39e | 138 | by ada_coerce_to_simple_array). */ |
14f9c5c9 AS |
139 | |
140 | static void | |
fc1a4b47 | 141 | val_print_packed_array_elements (struct type *type, const gdb_byte *valaddr, |
ebf56fd3 AS |
142 | int bitoffset, struct ui_file *stream, |
143 | int format, int recurse, | |
144 | enum val_prettyprint pretty) | |
14f9c5c9 AS |
145 | { |
146 | unsigned int i; | |
147 | unsigned int things_printed = 0; | |
148 | unsigned len; | |
e79af960 | 149 | struct type *elttype, *index_type; |
14f9c5c9 | 150 | unsigned eltlen; |
14f9c5c9 | 151 | unsigned long bitsize = TYPE_FIELD_BITSIZE (type, 0); |
d2e4a39e | 152 | struct value *mark = value_mark (); |
e79af960 | 153 | LONGEST low = 0; |
d2e4a39e | 154 | |
14f9c5c9 AS |
155 | elttype = TYPE_TARGET_TYPE (type); |
156 | eltlen = TYPE_LENGTH (check_typedef (elttype)); | |
e79af960 | 157 | index_type = TYPE_INDEX_TYPE (type); |
14f9c5c9 AS |
158 | |
159 | { | |
e79af960 | 160 | LONGEST high; |
14f9c5c9 AS |
161 | if (get_discrete_bounds (TYPE_FIELD_TYPE (type, 0), &low, &high) < 0) |
162 | len = 1; | |
163 | else | |
164 | len = high - low + 1; | |
165 | } | |
166 | ||
167 | i = 0; | |
168 | annotate_array_section_begin (i, elttype); | |
169 | ||
170 | while (i < len && things_printed < print_max) | |
171 | { | |
172 | struct value *v0, *v1; | |
173 | int i0; | |
174 | ||
175 | if (i != 0) | |
176 | { | |
177 | if (prettyprint_arrays) | |
178 | { | |
179 | fprintf_filtered (stream, ",\n"); | |
180 | print_spaces_filtered (2 + 2 * recurse, stream); | |
181 | } | |
182 | else | |
183 | { | |
184 | fprintf_filtered (stream, ", "); | |
185 | } | |
186 | } | |
187 | wrap_here (n_spaces (2 + 2 * recurse)); | |
e79af960 | 188 | maybe_print_array_index (index_type, i + low, stream, format, pretty); |
14f9c5c9 AS |
189 | |
190 | i0 = i; | |
d2e4a39e | 191 | v0 = ada_value_primitive_packed_val (NULL, valaddr, |
14f9c5c9 AS |
192 | (i0 * bitsize) / HOST_CHAR_BIT, |
193 | (i0 * bitsize) % HOST_CHAR_BIT, | |
194 | bitsize, elttype); | |
195 | while (1) | |
196 | { | |
197 | i += 1; | |
198 | if (i >= len) | |
199 | break; | |
d2e4a39e | 200 | v1 = ada_value_primitive_packed_val (NULL, valaddr, |
14f9c5c9 AS |
201 | (i * bitsize) / HOST_CHAR_BIT, |
202 | (i * bitsize) % HOST_CHAR_BIT, | |
203 | bitsize, elttype); | |
0fd88904 | 204 | if (memcmp (value_contents (v0), value_contents (v1), eltlen) != 0) |
14f9c5c9 AS |
205 | break; |
206 | } | |
207 | ||
208 | if (i - i0 > repeat_count_threshold) | |
209 | { | |
0fd88904 | 210 | val_print (elttype, value_contents (v0), 0, 0, stream, format, |
d8ca156b | 211 | 0, recurse + 1, pretty, 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; | |
220 | for (j = i0; j < i; j += 1) | |
221 | { | |
d2e4a39e | 222 | if (j > i0) |
14f9c5c9 AS |
223 | { |
224 | if (prettyprint_arrays) | |
225 | { | |
226 | fprintf_filtered (stream, ",\n"); | |
227 | print_spaces_filtered (2 + 2 * recurse, stream); | |
228 | } | |
229 | else | |
230 | { | |
231 | fprintf_filtered (stream, ", "); | |
232 | } | |
233 | wrap_here (n_spaces (2 + 2 * recurse)); | |
e79af960 JB |
234 | maybe_print_array_index (index_type, j + low, |
235 | stream, format, pretty); | |
14f9c5c9 | 236 | } |
0fd88904 | 237 | val_print (elttype, value_contents (v0), 0, 0, stream, format, |
d8ca156b | 238 | 0, recurse + 1, pretty, current_language); |
14f9c5c9 AS |
239 | annotate_elt (); |
240 | } | |
241 | } | |
242 | things_printed += i - i0; | |
243 | } | |
244 | annotate_array_section_end (); | |
245 | if (i < len) | |
246 | { | |
247 | fprintf_filtered (stream, "..."); | |
248 | } | |
249 | ||
250 | value_free_to_mark (mark); | |
251 | } | |
252 | ||
d2e4a39e | 253 | static struct type * |
fc1a4b47 | 254 | printable_val_type (struct type *type, const gdb_byte *valaddr) |
14f9c5c9 | 255 | { |
1ed6ede0 | 256 | return ada_to_fixed_type (ada_aligned_type (type), valaddr, 0, NULL, 1); |
14f9c5c9 AS |
257 | } |
258 | ||
259 | /* Print the character C on STREAM as part of the contents of a literal | |
260 | string whose delimiter is QUOTER. TYPE_LEN is the length in bytes | |
4c4b4cd2 | 261 | (1 or 2) of the character. */ |
14f9c5c9 AS |
262 | |
263 | void | |
ebf56fd3 | 264 | ada_emit_char (int c, struct ui_file *stream, int quoter, int type_len) |
14f9c5c9 AS |
265 | { |
266 | if (type_len != 2) | |
267 | type_len = 1; | |
268 | ||
269 | c &= (1 << (type_len * TARGET_CHAR_BIT)) - 1; | |
270 | ||
271 | if (isascii (c) && isprint (c)) | |
272 | { | |
273 | if (c == quoter && c == '"') | |
529cad9c | 274 | fprintf_filtered (stream, "\"\""); |
14f9c5c9 AS |
275 | else |
276 | fprintf_filtered (stream, "%c", c); | |
277 | } | |
278 | else | |
d2e4a39e | 279 | fprintf_filtered (stream, "[\"%0*x\"]", type_len * 2, c); |
14f9c5c9 AS |
280 | } |
281 | ||
282 | /* Character #I of STRING, given that TYPE_LEN is the size in bytes (1 | |
4c4b4cd2 | 283 | or 2) of a character. */ |
14f9c5c9 AS |
284 | |
285 | static int | |
fc1a4b47 | 286 | char_at (const gdb_byte *string, int i, int type_len) |
14f9c5c9 AS |
287 | { |
288 | if (type_len == 1) | |
289 | return string[i]; | |
d2e4a39e AS |
290 | else |
291 | return (int) extract_unsigned_integer (string + 2 * i, 2); | |
14f9c5c9 AS |
292 | } |
293 | ||
4c4b4cd2 PH |
294 | /* Wrapper around memcpy to make it legal argument to ui_file_put */ |
295 | static void | |
296 | ui_memcpy (void *dest, const char *buffer, long len) | |
297 | { | |
298 | memcpy (dest, buffer, (size_t) len); | |
299 | ((char *) dest)[len] = '\0'; | |
300 | } | |
301 | ||
302 | /* Print a floating-point value of type TYPE, pointed to in GDB by | |
303 | VALADDR, on STREAM. Use Ada formatting conventions: there must be | |
304 | a decimal point, and at least one digit before and after the | |
305 | point. We use GNAT format for NaNs and infinities. */ | |
306 | static void | |
fc1a4b47 | 307 | ada_print_floating (const gdb_byte *valaddr, struct type *type, |
a2bd3dcd | 308 | struct ui_file *stream) |
4c4b4cd2 PH |
309 | { |
310 | char buffer[64]; | |
311 | char *s, *result; | |
312 | int len; | |
313 | struct ui_file *tmp_stream = mem_fileopen (); | |
314 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_stream); | |
315 | ||
316 | print_floating (valaddr, type, tmp_stream); | |
317 | ui_file_put (tmp_stream, ui_memcpy, buffer); | |
318 | do_cleanups (cleanups); | |
319 | ||
320 | result = buffer; | |
321 | len = strlen (result); | |
322 | ||
323 | /* Modify for Ada rules. */ | |
c3e5cd34 PH |
324 | |
325 | s = strstr (result, "inf"); | |
326 | if (s == NULL) | |
327 | s = strstr (result, "Inf"); | |
328 | if (s == NULL) | |
329 | s = strstr (result, "INF"); | |
330 | if (s != NULL) | |
4c4b4cd2 | 331 | strcpy (s, "Inf"); |
c3e5cd34 PH |
332 | |
333 | if (s == NULL) | |
4c4b4cd2 | 334 | { |
c3e5cd34 PH |
335 | s = strstr (result, "nan"); |
336 | if (s == NULL) | |
337 | s = strstr (result, "NaN"); | |
338 | if (s == NULL) | |
339 | s = strstr (result, "Nan"); | |
340 | if (s != NULL) | |
341 | { | |
342 | s[0] = s[2] = 'N'; | |
343 | if (result[0] == '-') | |
344 | result += 1; | |
345 | } | |
4c4b4cd2 | 346 | } |
c3e5cd34 PH |
347 | |
348 | if (s == NULL && strchr (result, '.') == NULL) | |
4c4b4cd2 | 349 | { |
c3e5cd34 PH |
350 | s = strchr (result, 'e'); |
351 | if (s == NULL) | |
4c4b4cd2 PH |
352 | fprintf_filtered (stream, "%s.0", result); |
353 | else | |
354 | fprintf_filtered (stream, "%.*s.0%s", (int) (s-result), result, s); | |
355 | return; | |
356 | } | |
357 | fprintf_filtered (stream, "%s", result); | |
358 | } | |
359 | ||
14f9c5c9 | 360 | void |
ebf56fd3 | 361 | ada_printchar (int c, struct ui_file *stream) |
14f9c5c9 AS |
362 | { |
363 | fputs_filtered ("'", stream); | |
364 | ada_emit_char (c, stream, '\'', 1); | |
365 | fputs_filtered ("'", stream); | |
366 | } | |
367 | ||
368 | /* [From print_type_scalar in typeprint.c]. Print VAL on STREAM in a | |
4c4b4cd2 | 369 | form appropriate for TYPE. */ |
14f9c5c9 AS |
370 | |
371 | void | |
ebf56fd3 | 372 | ada_print_scalar (struct type *type, LONGEST val, struct ui_file *stream) |
14f9c5c9 AS |
373 | { |
374 | unsigned int i; | |
375 | unsigned len; | |
376 | ||
61ee279c | 377 | type = ada_check_typedef (type); |
14f9c5c9 AS |
378 | |
379 | switch (TYPE_CODE (type)) | |
380 | { | |
381 | ||
382 | case TYPE_CODE_ENUM: | |
383 | len = TYPE_NFIELDS (type); | |
384 | for (i = 0; i < len; i++) | |
385 | { | |
386 | if (TYPE_FIELD_BITPOS (type, i) == val) | |
387 | { | |
388 | break; | |
389 | } | |
390 | } | |
391 | if (i < len) | |
392 | { | |
393 | fputs_filtered (ada_enum_name (TYPE_FIELD_NAME (type, i)), stream); | |
394 | } | |
395 | else | |
396 | { | |
397 | print_longest (stream, 'd', 0, val); | |
398 | } | |
399 | break; | |
400 | ||
401 | case TYPE_CODE_INT: | |
402 | print_longest (stream, TYPE_UNSIGNED (type) ? 'u' : 'd', 0, val); | |
403 | break; | |
404 | ||
405 | case TYPE_CODE_CHAR: | |
406 | LA_PRINT_CHAR ((unsigned char) val, stream); | |
407 | break; | |
408 | ||
409 | case TYPE_CODE_BOOL: | |
410 | fprintf_filtered (stream, val ? "true" : "false"); | |
411 | break; | |
412 | ||
413 | case TYPE_CODE_RANGE: | |
414 | ada_print_scalar (TYPE_TARGET_TYPE (type), val, stream); | |
415 | return; | |
416 | ||
417 | case TYPE_CODE_UNDEF: | |
418 | case TYPE_CODE_PTR: | |
419 | case TYPE_CODE_ARRAY: | |
420 | case TYPE_CODE_STRUCT: | |
421 | case TYPE_CODE_UNION: | |
422 | case TYPE_CODE_FUNC: | |
423 | case TYPE_CODE_FLT: | |
424 | case TYPE_CODE_VOID: | |
425 | case TYPE_CODE_SET: | |
426 | case TYPE_CODE_STRING: | |
427 | case TYPE_CODE_ERROR: | |
0d5de010 DJ |
428 | case TYPE_CODE_MEMBERPTR: |
429 | case TYPE_CODE_METHODPTR: | |
14f9c5c9 AS |
430 | case TYPE_CODE_METHOD: |
431 | case TYPE_CODE_REF: | |
edefbb7c | 432 | warning (_("internal error: unhandled type in ada_print_scalar")); |
14f9c5c9 AS |
433 | break; |
434 | ||
435 | default: | |
edefbb7c | 436 | error (_("Invalid type code in symbol table.")); |
14f9c5c9 AS |
437 | } |
438 | gdb_flush (stream); | |
439 | } | |
440 | ||
441 | /* Print the character string STRING, printing at most LENGTH characters. | |
442 | Printing stops early if the number hits print_max; repeat counts | |
443 | are printed as appropriate. Print ellipses at the end if we | |
444 | had to stop before printing LENGTH characters, or if | |
445 | FORCE_ELLIPSES. TYPE_LEN is the length (1 or 2) of the character type. | |
446 | */ | |
447 | ||
448 | static void | |
fc1a4b47 | 449 | printstr (struct ui_file *stream, const gdb_byte *string, |
d56612af | 450 | unsigned int length, int force_ellipses, int type_len) |
14f9c5c9 AS |
451 | { |
452 | unsigned int i; | |
453 | unsigned int things_printed = 0; | |
454 | int in_quotes = 0; | |
455 | int need_comma = 0; | |
456 | ||
457 | if (length == 0) | |
458 | { | |
459 | fputs_filtered ("\"\"", stream); | |
460 | return; | |
461 | } | |
462 | ||
463 | for (i = 0; i < length && things_printed < print_max; i += 1) | |
464 | { | |
465 | /* Position of the character we are examining | |
d2e4a39e | 466 | to see whether it is repeated. */ |
14f9c5c9 AS |
467 | unsigned int rep1; |
468 | /* Number of repetitions we have detected so far. */ | |
469 | unsigned int reps; | |
470 | ||
471 | QUIT; | |
472 | ||
473 | if (need_comma) | |
474 | { | |
475 | fputs_filtered (", ", stream); | |
476 | need_comma = 0; | |
477 | } | |
478 | ||
479 | rep1 = i + 1; | |
480 | reps = 1; | |
c3e5cd34 PH |
481 | while (rep1 < length |
482 | && char_at (string, rep1, type_len) == char_at (string, i, | |
483 | type_len)) | |
14f9c5c9 AS |
484 | { |
485 | rep1 += 1; | |
486 | reps += 1; | |
487 | } | |
488 | ||
489 | if (reps > repeat_count_threshold) | |
490 | { | |
491 | if (in_quotes) | |
492 | { | |
493 | if (inspect_it) | |
494 | fputs_filtered ("\\\", ", stream); | |
495 | else | |
496 | fputs_filtered ("\", ", stream); | |
497 | in_quotes = 0; | |
498 | } | |
499 | fputs_filtered ("'", stream); | |
d2e4a39e AS |
500 | ada_emit_char (char_at (string, i, type_len), stream, '\'', |
501 | type_len); | |
14f9c5c9 | 502 | fputs_filtered ("'", stream); |
edefbb7c | 503 | fprintf_filtered (stream, _(" <repeats %u times>"), reps); |
14f9c5c9 AS |
504 | i = rep1 - 1; |
505 | things_printed += repeat_count_threshold; | |
506 | need_comma = 1; | |
507 | } | |
508 | else | |
509 | { | |
510 | if (!in_quotes) | |
511 | { | |
512 | if (inspect_it) | |
513 | fputs_filtered ("\\\"", stream); | |
514 | else | |
515 | fputs_filtered ("\"", stream); | |
516 | in_quotes = 1; | |
517 | } | |
518 | ada_emit_char (char_at (string, i, type_len), stream, '"', | |
519 | type_len); | |
520 | things_printed += 1; | |
521 | } | |
522 | } | |
523 | ||
524 | /* Terminate the quotes if necessary. */ | |
525 | if (in_quotes) | |
526 | { | |
527 | if (inspect_it) | |
528 | fputs_filtered ("\\\"", stream); | |
529 | else | |
530 | fputs_filtered ("\"", stream); | |
531 | } | |
532 | ||
533 | if (force_ellipses || i < length) | |
534 | fputs_filtered ("...", stream); | |
535 | } | |
536 | ||
537 | void | |
fc1a4b47 | 538 | ada_printstr (struct ui_file *stream, const gdb_byte *string, |
ce27fb25 | 539 | unsigned int length, int width, int force_ellipses) |
14f9c5c9 AS |
540 | { |
541 | printstr (stream, string, length, force_ellipses, width); | |
542 | } | |
543 | ||
544 | ||
545 | /* Print data of type TYPE located at VALADDR (within GDB), which came from | |
546 | the inferior at address ADDRESS, onto stdio stream STREAM according to | |
4c4b4cd2 | 547 | FORMAT (a letter as for the printf % codes or 0 for natural format). |
14f9c5c9 AS |
548 | The data at VALADDR is in target byte order. |
549 | ||
550 | If the data is printed as a string, returns the number of string characters | |
551 | printed. | |
552 | ||
553 | If DEREF_REF is nonzero, then dereference references, otherwise just print | |
554 | them like pointers. | |
555 | ||
556 | RECURSE indicates the amount of indentation to supply before | |
557 | continuation lines; this amount is roughly twice the value of RECURSE. | |
558 | ||
559 | When PRETTY is non-zero, prints record fields on separate lines. | |
560 | (For some reason, the current version of gdb instead uses a global | |
561 | variable---prettyprint_arrays--- to causes a similar effect on | |
562 | arrays.) */ | |
563 | ||
564 | int | |
fc1a4b47 | 565 | ada_val_print (struct type *type, const gdb_byte *valaddr0, |
a2bd3dcd AC |
566 | int embedded_offset, CORE_ADDR address, |
567 | struct ui_file *stream, int format, int deref_ref, | |
568 | int recurse, enum val_prettyprint pretty) | |
14f9c5c9 AS |
569 | { |
570 | struct ada_val_print_args args; | |
d2e4a39e AS |
571 | args.type = type; |
572 | args.valaddr0 = valaddr0; | |
14f9c5c9 AS |
573 | args.embedded_offset = embedded_offset; |
574 | args.address = address; | |
575 | args.stream = stream; | |
576 | args.format = format; | |
577 | args.deref_ref = deref_ref; | |
578 | args.recurse = recurse; | |
579 | args.pretty = pretty; | |
580 | ||
581 | return catch_errors (ada_val_print_stub, &args, NULL, RETURN_MASK_ALL); | |
582 | } | |
583 | ||
584 | /* Helper for ada_val_print; used as argument to catch_errors to | |
4c4b4cd2 | 585 | unmarshal the arguments to ada_val_print_1, which does the work. */ |
14f9c5c9 | 586 | static int |
19c1ef65 | 587 | ada_val_print_stub (void *args0) |
14f9c5c9 | 588 | { |
d2e4a39e AS |
589 | struct ada_val_print_args *argsp = (struct ada_val_print_args *) args0; |
590 | return ada_val_print_1 (argsp->type, argsp->valaddr0, | |
591 | argsp->embedded_offset, argsp->address, | |
592 | argsp->stream, argsp->format, argsp->deref_ref, | |
593 | argsp->recurse, argsp->pretty); | |
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, | |
603 | CORE_ADDR address, struct ui_file *stream, int format, | |
604 | int deref_ref, int recurse, enum val_prettyprint pretty) | |
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. */ | |
621 | if (ada_is_string_type (type) && (format == 0 || format == 's')) | |
622 | { | |
623 | if (prettyprint_arrays) | |
624 | print_spaces_filtered (2 + 2 * recurse, stream); | |
625 | ||
626 | /* If requested, look for the first null char and only print | |
627 | elements up to it. */ | |
628 | if (stop_print_at_null) | |
629 | { | |
630 | int temp_len; | |
631 | ||
632 | /* Look for a NULL char. */ | |
633 | for (temp_len = 0; | |
634 | (temp_len < len | |
635 | && temp_len < print_max | |
636 | && char_at (valaddr, temp_len, eltlen) != 0); | |
637 | temp_len += 1); | |
638 | len = temp_len; | |
639 | } | |
640 | ||
641 | printstr (stream, valaddr, len, 0, eltlen); | |
642 | result = len; | |
643 | } | |
644 | else | |
645 | { | |
646 | fprintf_filtered (stream, "("); | |
647 | print_optional_low_bound (stream, type); | |
648 | if (TYPE_FIELD_BITSIZE (type, 0) > 0) | |
649 | val_print_packed_array_elements (type, valaddr, 0, stream, | |
650 | format, recurse, pretty); | |
651 | else | |
652 | val_print_array_elements (type, valaddr, address, stream, | |
653 | format, deref_ref, recurse, | |
654 | pretty, 0); | |
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 AC |
666 | int embedded_offset, CORE_ADDR address, |
667 | struct ui_file *stream, int format, | |
ebf56fd3 | 668 | int deref_ref, int recurse, enum val_prettyprint pretty) |
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, |
d2e4a39e | 693 | VALUE_ADDRESS (val), stream, format, |
14f9c5c9 AS |
694 | deref_ref, recurse, pretty); |
695 | value_free_to_mark (mark); | |
696 | return retn; | |
697 | } | |
698 | ||
699 | valaddr = ada_aligned_value_addr (type, valaddr); | |
700 | embedded_offset -= valaddr - valaddr0 - embedded_offset; | |
701 | type = printable_val_type (type, valaddr); | |
702 | ||
703 | switch (TYPE_CODE (type)) | |
704 | { | |
705 | default: | |
d2e4a39e | 706 | return c_val_print (type, valaddr0, embedded_offset, address, stream, |
14f9c5c9 AS |
707 | format, deref_ref, recurse, pretty); |
708 | ||
4c4b4cd2 PH |
709 | case TYPE_CODE_PTR: |
710 | { | |
711 | int ret = c_val_print (type, valaddr0, embedded_offset, address, | |
712 | stream, format, deref_ref, recurse, pretty); | |
713 | if (ada_is_tag_type (type)) | |
714 | { | |
715 | struct value *val = | |
716 | value_from_contents_and_address (type, valaddr, address); | |
717 | const char *name = ada_tag_name (val); | |
718 | if (name != NULL) | |
719 | fprintf_filtered (stream, " (%s)", name); | |
720 | return 0; | |
721 | } | |
722 | return ret; | |
723 | } | |
724 | ||
14f9c5c9 AS |
725 | case TYPE_CODE_INT: |
726 | case TYPE_CODE_RANGE: | |
727 | if (ada_is_fixed_point_type (type)) | |
728 | { | |
729 | LONGEST v = unpack_long (type, valaddr); | |
730 | int len = TYPE_LENGTH (type); | |
731 | ||
732 | fprintf_filtered (stream, len < 4 ? "%.11g" : "%.17g", | |
733 | (double) ada_fixed_to_float (type, v)); | |
734 | return 0; | |
735 | } | |
736 | else if (ada_is_vax_floating_type (type)) | |
737 | { | |
d2e4a39e | 738 | struct value *val = |
14f9c5c9 | 739 | value_from_contents_and_address (type, valaddr, address); |
d2e4a39e | 740 | struct value *func = ada_vax_float_print_function (type); |
14f9c5c9 AS |
741 | if (func != 0) |
742 | { | |
d2e4a39e AS |
743 | static struct type *parray_of_char = NULL; |
744 | struct value *printable_val; | |
745 | ||
746 | if (parray_of_char == NULL) | |
747 | parray_of_char = | |
748 | make_pointer_type | |
749 | (create_array_type | |
750 | (NULL, builtin_type_char, | |
751 | create_range_type (NULL, builtin_type_int, 0, 32)), NULL); | |
752 | ||
753 | printable_val = | |
14f9c5c9 | 754 | value_ind (value_cast (parray_of_char, |
d2e4a39e AS |
755 | call_function_by_hand (func, 1, |
756 | &val))); | |
757 | ||
0fd88904 | 758 | fprintf_filtered (stream, "%s", value_contents (printable_val)); |
14f9c5c9 AS |
759 | return 0; |
760 | } | |
4c4b4cd2 | 761 | /* No special printing function. Do as best we can. */ |
14f9c5c9 AS |
762 | } |
763 | else if (TYPE_CODE (type) == TYPE_CODE_RANGE) | |
764 | { | |
d2e4a39e | 765 | struct type *target_type = TYPE_TARGET_TYPE (type); |
14f9c5c9 AS |
766 | if (TYPE_LENGTH (type) != TYPE_LENGTH (target_type)) |
767 | { | |
768 | /* Obscure case of range type that has different length from | |
d2e4a39e AS |
769 | its base type. Perform a conversion, or we will get a |
770 | nonsense value. Actually, we could use the same | |
4c4b4cd2 | 771 | code regardless of lengths; I'm just avoiding a cast. */ |
d2e4a39e AS |
772 | struct value *v = value_cast (target_type, |
773 | value_from_contents_and_address | |
774 | (type, valaddr, 0)); | |
0fd88904 | 775 | return ada_val_print_1 (target_type, value_contents (v), 0, 0, |
14f9c5c9 AS |
776 | stream, format, 0, recurse + 1, pretty); |
777 | } | |
778 | else | |
d2e4a39e | 779 | return ada_val_print_1 (TYPE_TARGET_TYPE (type), |
14f9c5c9 | 780 | valaddr0, embedded_offset, |
d2e4a39e | 781 | address, stream, format, deref_ref, |
14f9c5c9 AS |
782 | recurse, pretty); |
783 | } | |
d2e4a39e | 784 | else |
14f9c5c9 AS |
785 | { |
786 | format = format ? format : output_format; | |
787 | if (format) | |
788 | { | |
789 | print_scalar_formatted (valaddr, type, format, 0, stream); | |
790 | } | |
4c4b4cd2 PH |
791 | else if (ada_is_system_address_type (type)) |
792 | { | |
793 | /* FIXME: We want to print System.Address variables using | |
794 | the same format as for any access type. But for some | |
795 | reason GNAT encodes the System.Address type as an int, | |
796 | so we have to work-around this deficiency by handling | |
797 | System.Address values as a special case. */ | |
798 | fprintf_filtered (stream, "("); | |
799 | type_print (type, "", stream, -1); | |
800 | fprintf_filtered (stream, ") "); | |
ed49a04f MD |
801 | fputs_filtered (paddress (extract_typed_address |
802 | (valaddr, builtin_type_void_data_ptr)), | |
803 | stream); | |
4c4b4cd2 | 804 | } |
14f9c5c9 AS |
805 | else |
806 | { | |
807 | val_print_type_code_int (type, valaddr, stream); | |
808 | if (ada_is_character_type (type)) | |
809 | { | |
810 | fputs_filtered (" ", stream); | |
811 | ada_printchar ((unsigned char) unpack_long (type, valaddr), | |
812 | stream); | |
813 | } | |
814 | } | |
815 | return 0; | |
816 | } | |
817 | ||
818 | case TYPE_CODE_ENUM: | |
819 | if (format) | |
820 | { | |
821 | print_scalar_formatted (valaddr, type, format, 0, stream); | |
822 | break; | |
823 | } | |
824 | len = TYPE_NFIELDS (type); | |
825 | val = unpack_long (type, valaddr); | |
826 | for (i = 0; i < len; i++) | |
827 | { | |
828 | QUIT; | |
829 | if (val == TYPE_FIELD_BITPOS (type, i)) | |
830 | { | |
831 | break; | |
832 | } | |
833 | } | |
834 | if (i < len) | |
835 | { | |
d2e4a39e AS |
836 | const char *name = ada_enum_name (TYPE_FIELD_NAME (type, i)); |
837 | if (name[0] == '\'') | |
14f9c5c9 AS |
838 | fprintf_filtered (stream, "%ld %s", (long) val, name); |
839 | else | |
840 | fputs_filtered (name, stream); | |
841 | } | |
842 | else | |
843 | { | |
844 | print_longest (stream, 'd', 0, val); | |
845 | } | |
846 | break; | |
d2e4a39e | 847 | |
4f2aea11 MK |
848 | case TYPE_CODE_FLAGS: |
849 | if (format) | |
850 | print_scalar_formatted (valaddr, type, format, 0, stream); | |
851 | else | |
852 | val_print_type_code_flags (type, valaddr, stream); | |
853 | break; | |
854 | ||
4c4b4cd2 PH |
855 | case TYPE_CODE_FLT: |
856 | if (format) | |
857 | return c_val_print (type, valaddr0, embedded_offset, address, stream, | |
858 | format, deref_ref, recurse, pretty); | |
859 | else | |
860 | ada_print_floating (valaddr0 + embedded_offset, type, stream); | |
861 | break; | |
862 | ||
14f9c5c9 AS |
863 | case TYPE_CODE_UNION: |
864 | case TYPE_CODE_STRUCT: | |
865 | if (ada_is_bogus_array_descriptor (type)) | |
866 | { | |
867 | fprintf_filtered (stream, "(...?)"); | |
868 | return 0; | |
d2e4a39e | 869 | } |
14f9c5c9 AS |
870 | else |
871 | { | |
d2e4a39e | 872 | print_record (type, valaddr, stream, format, recurse, pretty); |
14f9c5c9 AS |
873 | return 0; |
874 | } | |
875 | ||
876 | case TYPE_CODE_ARRAY: | |
e936309c JB |
877 | return ada_val_print_array (type, valaddr, address, stream, format, |
878 | deref_ref, recurse, pretty); | |
14f9c5c9 AS |
879 | |
880 | case TYPE_CODE_REF: | |
969a1360 JB |
881 | /* For references, the debugger is expected to print the value as |
882 | an address if DEREF_REF is null. But printing an address in place | |
883 | of the object value would be confusing to an Ada programmer. | |
884 | So, for Ada values, we print the actual dereferenced value | |
885 | regardless. */ | |
14f9c5c9 | 886 | elttype = check_typedef (TYPE_TARGET_TYPE (type)); |
969a1360 JB |
887 | |
888 | if (TYPE_CODE (elttype) != TYPE_CODE_UNDEF) | |
889 | { | |
890 | LONGEST deref_val_int = (LONGEST) | |
891 | unpack_pointer (lookup_pointer_type (builtin_type_void), | |
892 | valaddr); | |
893 | if (deref_val_int != 0) | |
894 | { | |
895 | struct value *deref_val = | |
896 | ada_value_ind (value_from_longest | |
897 | (lookup_pointer_type (elttype), | |
898 | deref_val_int)); | |
899 | val_print (value_type (deref_val), | |
900 | value_contents (deref_val), 0, | |
901 | VALUE_ADDRESS (deref_val), stream, format, | |
d8ca156b | 902 | deref_ref, recurse + 1, pretty, current_language); |
969a1360 JB |
903 | } |
904 | else | |
905 | fputs_filtered ("(null)", stream); | |
906 | } | |
907 | else | |
908 | fputs_filtered ("???", stream); | |
909 | ||
14f9c5c9 AS |
910 | break; |
911 | } | |
4c4b4cd2 | 912 | gdb_flush (stream); |
14f9c5c9 AS |
913 | return 0; |
914 | } | |
915 | ||
916 | static int | |
fc1a4b47 | 917 | print_variant_part (struct type *type, int field_num, const gdb_byte *valaddr, |
ebf56fd3 AS |
918 | struct ui_file *stream, int format, int recurse, |
919 | enum val_prettyprint pretty, int comma_needed, | |
fc1a4b47 | 920 | struct type *outer_type, const gdb_byte *outer_valaddr) |
14f9c5c9 AS |
921 | { |
922 | struct type *var_type = TYPE_FIELD_TYPE (type, field_num); | |
d2e4a39e | 923 | int which = ada_which_variant_applies (var_type, outer_type, outer_valaddr); |
14f9c5c9 AS |
924 | |
925 | if (which < 0) | |
926 | return 0; | |
927 | else | |
d2e4a39e | 928 | return print_field_values |
14f9c5c9 AS |
929 | (TYPE_FIELD_TYPE (var_type, which), |
930 | valaddr + TYPE_FIELD_BITPOS (type, field_num) / HOST_CHAR_BIT | |
931 | + TYPE_FIELD_BITPOS (var_type, which) / HOST_CHAR_BIT, | |
932 | stream, format, recurse, pretty, | |
933 | comma_needed, outer_type, outer_valaddr); | |
934 | } | |
935 | ||
936 | int | |
d2e4a39e | 937 | ada_value_print (struct value *val0, struct ui_file *stream, int format, |
ebf56fd3 | 938 | enum val_prettyprint pretty) |
14f9c5c9 | 939 | { |
fc1a4b47 | 940 | const gdb_byte *valaddr = value_contents (val0); |
df407dfe | 941 | CORE_ADDR address = VALUE_ADDRESS (val0) + value_offset (val0); |
d2e4a39e | 942 | struct type *type = |
1ed6ede0 | 943 | ada_to_fixed_type (value_type (val0), valaddr, address, NULL, 1); |
d2e4a39e AS |
944 | struct value *val = |
945 | value_from_contents_and_address (type, valaddr, address); | |
14f9c5c9 | 946 | |
4c4b4cd2 PH |
947 | /* If it is a pointer, indicate what it points to. */ |
948 | if (TYPE_CODE (type) == TYPE_CODE_PTR) | |
14f9c5c9 | 949 | { |
4c4b4cd2 PH |
950 | /* Hack: don't print (char *) for char strings. Their |
951 | type is indicated by the quoted string anyway. */ | |
952 | if (TYPE_LENGTH (TYPE_TARGET_TYPE (type)) != sizeof (char) | |
953 | || TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_INT | |
954 | || TYPE_UNSIGNED (TYPE_TARGET_TYPE (type))) | |
14f9c5c9 AS |
955 | { |
956 | fprintf_filtered (stream, "("); | |
957 | type_print (type, "", stream, -1); | |
958 | fprintf_filtered (stream, ") "); | |
959 | } | |
960 | } | |
4c4b4cd2 | 961 | else if (ada_is_array_descriptor_type (type)) |
14f9c5c9 AS |
962 | { |
963 | fprintf_filtered (stream, "("); | |
964 | type_print (type, "", stream, -1); | |
965 | fprintf_filtered (stream, ") "); | |
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 | |
0fd88904 | 975 | return (val_print (type, value_contents (val), 0, address, |
d8ca156b | 976 | stream, format, 1, 0, pretty, current_language)); |
14f9c5c9 | 977 | } |
d2e4a39e | 978 | |
14f9c5c9 | 979 | static void |
fc1a4b47 | 980 | print_record (struct type *type, const gdb_byte *valaddr, |
a2bd3dcd AC |
981 | struct ui_file *stream, int format, int recurse, |
982 | enum val_prettyprint pretty) | |
14f9c5c9 | 983 | { |
61ee279c | 984 | type = ada_check_typedef (type); |
14f9c5c9 AS |
985 | |
986 | fprintf_filtered (stream, "("); | |
987 | ||
988 | if (print_field_values (type, valaddr, stream, format, recurse, pretty, | |
d2e4a39e | 989 | 0, type, valaddr) != 0 && pretty) |
14f9c5c9 AS |
990 | { |
991 | fprintf_filtered (stream, "\n"); | |
992 | print_spaces_filtered (2 * recurse, stream); | |
993 | } | |
994 | ||
995 | fprintf_filtered (stream, ")"); | |
996 | } | |
997 | ||
998 | /* Print out fields of value at VALADDR having structure type TYPE. | |
4c4b4cd2 | 999 | |
14f9c5c9 | 1000 | TYPE, VALADDR, STREAM, FORMAT, RECURSE, and PRETTY have the |
4c4b4cd2 | 1001 | same meanings as in ada_print_value and ada_val_print. |
14f9c5c9 AS |
1002 | |
1003 | OUTER_TYPE and OUTER_VALADDR give type and address of enclosing record | |
1004 | (used to get discriminant values when printing variant parts). | |
1005 | ||
4c4b4cd2 | 1006 | COMMA_NEEDED is 1 if fields have been printed at the current recursion |
14f9c5c9 | 1007 | level, so that a comma is needed before any field printed by this |
4c4b4cd2 | 1008 | call. |
14f9c5c9 | 1009 | |
4c4b4cd2 | 1010 | Returns 1 if COMMA_NEEDED or any fields were printed. */ |
14f9c5c9 AS |
1011 | |
1012 | static int | |
fc1a4b47 | 1013 | print_field_values (struct type *type, const gdb_byte *valaddr, |
a2bd3dcd AC |
1014 | struct ui_file *stream, int format, int recurse, |
1015 | enum val_prettyprint pretty, 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 AS |
1032 | + TYPE_FIELD_BITPOS (type, i) / HOST_CHAR_BIT, |
1033 | stream, format, recurse, pretty, | |
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, | |
1041 | stream, format, recurse, pretty, comma_needed, | |
1042 | outer_type, outer_valaddr); | |
1043 | continue; | |
1044 | } | |
1045 | ||
1046 | if (comma_needed) | |
1047 | fprintf_filtered (stream, ", "); | |
1048 | comma_needed = 1; | |
1049 | ||
1050 | if (pretty) | |
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 | } | |
1059 | if (inspect_it) | |
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); | |
d2e4a39e | 1098 | |
14f9c5c9 AS |
1099 | adjust_type_signedness (TYPE_FIELD_TYPE (type, i)); |
1100 | v = ada_value_primitive_packed_val (NULL, valaddr, | |
1101 | bit_pos / HOST_CHAR_BIT, | |
1102 | bit_pos % HOST_CHAR_BIT, | |
d2e4a39e | 1103 | bit_size, |
14f9c5c9 | 1104 | TYPE_FIELD_TYPE (type, i)); |
0fd88904 | 1105 | val_print (TYPE_FIELD_TYPE (type, i), value_contents (v), 0, 0, |
d8ca156b JB |
1106 | stream, format, 0, recurse + 1, pretty, |
1107 | current_language); | |
14f9c5c9 AS |
1108 | } |
1109 | } | |
1110 | else | |
d2e4a39e AS |
1111 | ada_val_print (TYPE_FIELD_TYPE (type, i), |
1112 | valaddr + TYPE_FIELD_BITPOS (type, i) / HOST_CHAR_BIT, | |
1113 | 0, 0, stream, format, 0, recurse + 1, pretty); | |
14f9c5c9 AS |
1114 | annotate_field_end (); |
1115 | } | |
1116 | ||
1117 | return comma_needed; | |
1118 | } |