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