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