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