GDB (API)
|
00001 /* Support for printing Ada values for GDB, the GNU debugger. 00002 00003 Copyright (C) 1986-2013 Free Software Foundation, Inc. 00004 00005 This file is part of GDB. 00006 00007 This program is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License as published by 00009 the Free Software Foundation; either version 3 of the License, or 00010 (at your option) any later version. 00011 00012 This program is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 00019 00020 #include "defs.h" 00021 #include <ctype.h> 00022 #include "gdb_string.h" 00023 #include "symtab.h" 00024 #include "gdbtypes.h" 00025 #include "expression.h" 00026 #include "value.h" 00027 #include "demangle.h" 00028 #include "valprint.h" 00029 #include "language.h" 00030 #include "annotate.h" 00031 #include "ada-lang.h" 00032 #include "c-lang.h" 00033 #include "infcall.h" 00034 #include "exceptions.h" 00035 #include "objfiles.h" 00036 00037 static void print_record (struct type *, const gdb_byte *, int, 00038 struct ui_file *, 00039 int, 00040 const struct value *, 00041 const struct value_print_options *); 00042 00043 static int print_field_values (struct type *, const gdb_byte *, 00044 int, 00045 struct ui_file *, int, 00046 const struct value *, 00047 const struct value_print_options *, 00048 int, struct type *, int); 00049 00050 static void adjust_type_signedness (struct type *); 00051 00052 static void ada_val_print_1 (struct type *, const gdb_byte *, int, CORE_ADDR, 00053 struct ui_file *, int, 00054 const struct value *, 00055 const struct value_print_options *); 00056 00057 00058 /* Make TYPE unsigned if its range of values includes no negatives. */ 00059 static void 00060 adjust_type_signedness (struct type *type) 00061 { 00062 if (type != NULL && TYPE_CODE (type) == TYPE_CODE_RANGE 00063 && TYPE_LOW_BOUND (type) >= 0) 00064 TYPE_UNSIGNED (type) = 1; 00065 } 00066 00067 /* Assuming TYPE is a simple array type, prints its lower bound on STREAM, 00068 if non-standard (i.e., other than 1 for numbers, other than lower bound 00069 of index type for enumerated type). Returns 1 if something printed, 00070 otherwise 0. */ 00071 00072 static int 00073 print_optional_low_bound (struct ui_file *stream, struct type *type, 00074 const struct value_print_options *options) 00075 { 00076 struct type *index_type; 00077 LONGEST low_bound; 00078 LONGEST high_bound; 00079 00080 if (options->print_array_indexes) 00081 return 0; 00082 00083 if (!get_array_bounds (type, &low_bound, &high_bound)) 00084 return 0; 00085 00086 /* If this is an empty array, then don't print the lower bound. 00087 That would be confusing, because we would print the lower bound, 00088 followed by... nothing! */ 00089 if (low_bound > high_bound) 00090 return 0; 00091 00092 index_type = TYPE_INDEX_TYPE (type); 00093 00094 if (TYPE_CODE (index_type) == TYPE_CODE_RANGE) 00095 { 00096 /* We need to know what the base type is, in order to do the 00097 appropriate check below. Otherwise, if this is a subrange 00098 of an enumerated type, where the underlying value of the 00099 first element is typically 0, we might test the low bound 00100 against the wrong value. */ 00101 index_type = TYPE_TARGET_TYPE (index_type); 00102 } 00103 00104 switch (TYPE_CODE (index_type)) 00105 { 00106 case TYPE_CODE_BOOL: 00107 if (low_bound == 0) 00108 return 0; 00109 break; 00110 case TYPE_CODE_ENUM: 00111 if (low_bound == TYPE_FIELD_ENUMVAL (index_type, 0)) 00112 return 0; 00113 break; 00114 case TYPE_CODE_UNDEF: 00115 index_type = NULL; 00116 /* FALL THROUGH */ 00117 default: 00118 if (low_bound == 1) 00119 return 0; 00120 break; 00121 } 00122 00123 ada_print_scalar (index_type, low_bound, stream); 00124 fprintf_filtered (stream, " => "); 00125 return 1; 00126 } 00127 00128 /* Version of val_print_array_elements for GNAT-style packed arrays. 00129 Prints elements of packed array of type TYPE at bit offset 00130 BITOFFSET from VALADDR on STREAM. Formats according to OPTIONS and 00131 separates with commas. RECURSE is the recursion (nesting) level. 00132 TYPE must have been decoded (as by ada_coerce_to_simple_array). */ 00133 00134 static void 00135 val_print_packed_array_elements (struct type *type, const gdb_byte *valaddr, 00136 int offset, 00137 int bitoffset, struct ui_file *stream, 00138 int recurse, 00139 const struct value *val, 00140 const struct value_print_options *options) 00141 { 00142 unsigned int i; 00143 unsigned int things_printed = 0; 00144 unsigned len; 00145 struct type *elttype, *index_type; 00146 unsigned eltlen; 00147 unsigned long bitsize = TYPE_FIELD_BITSIZE (type, 0); 00148 struct value *mark = value_mark (); 00149 LONGEST low = 0; 00150 00151 elttype = TYPE_TARGET_TYPE (type); 00152 eltlen = TYPE_LENGTH (check_typedef (elttype)); 00153 index_type = TYPE_INDEX_TYPE (type); 00154 00155 { 00156 LONGEST high; 00157 00158 if (get_discrete_bounds (index_type, &low, &high) < 0) 00159 len = 1; 00160 else 00161 len = high - low + 1; 00162 } 00163 00164 i = 0; 00165 annotate_array_section_begin (i, elttype); 00166 00167 while (i < len && things_printed < options->print_max) 00168 { 00169 struct value *v0, *v1; 00170 int i0; 00171 00172 if (i != 0) 00173 { 00174 if (options->prettyformat_arrays) 00175 { 00176 fprintf_filtered (stream, ",\n"); 00177 print_spaces_filtered (2 + 2 * recurse, stream); 00178 } 00179 else 00180 { 00181 fprintf_filtered (stream, ", "); 00182 } 00183 } 00184 wrap_here (n_spaces (2 + 2 * recurse)); 00185 maybe_print_array_index (index_type, i + low, stream, options); 00186 00187 i0 = i; 00188 v0 = ada_value_primitive_packed_val (NULL, valaddr + offset, 00189 (i0 * bitsize) / HOST_CHAR_BIT, 00190 (i0 * bitsize) % HOST_CHAR_BIT, 00191 bitsize, elttype); 00192 while (1) 00193 { 00194 i += 1; 00195 if (i >= len) 00196 break; 00197 v1 = ada_value_primitive_packed_val (NULL, valaddr + offset, 00198 (i * bitsize) / HOST_CHAR_BIT, 00199 (i * bitsize) % HOST_CHAR_BIT, 00200 bitsize, elttype); 00201 if (!value_available_contents_eq (v0, value_embedded_offset (v0), 00202 v1, value_embedded_offset (v1), 00203 eltlen)) 00204 break; 00205 } 00206 00207 if (i - i0 > options->repeat_count_threshold) 00208 { 00209 struct value_print_options opts = *options; 00210 00211 opts.deref_ref = 0; 00212 val_print (elttype, value_contents_for_printing (v0), 00213 value_embedded_offset (v0), 0, stream, 00214 recurse + 1, v0, &opts, current_language); 00215 annotate_elt_rep (i - i0); 00216 fprintf_filtered (stream, _(" <repeats %u times>"), i - i0); 00217 annotate_elt_rep_end (); 00218 00219 } 00220 else 00221 { 00222 int j; 00223 struct value_print_options opts = *options; 00224 00225 opts.deref_ref = 0; 00226 for (j = i0; j < i; j += 1) 00227 { 00228 if (j > i0) 00229 { 00230 if (options->prettyformat_arrays) 00231 { 00232 fprintf_filtered (stream, ",\n"); 00233 print_spaces_filtered (2 + 2 * recurse, stream); 00234 } 00235 else 00236 { 00237 fprintf_filtered (stream, ", "); 00238 } 00239 wrap_here (n_spaces (2 + 2 * recurse)); 00240 maybe_print_array_index (index_type, j + low, 00241 stream, options); 00242 } 00243 val_print (elttype, value_contents_for_printing (v0), 00244 value_embedded_offset (v0), 0, stream, 00245 recurse + 1, v0, &opts, current_language); 00246 annotate_elt (); 00247 } 00248 } 00249 things_printed += i - i0; 00250 } 00251 annotate_array_section_end (); 00252 if (i < len) 00253 { 00254 fprintf_filtered (stream, "..."); 00255 } 00256 00257 value_free_to_mark (mark); 00258 } 00259 00260 static struct type * 00261 printable_val_type (struct type *type, const gdb_byte *valaddr) 00262 { 00263 return ada_to_fixed_type (ada_aligned_type (type), valaddr, 0, NULL, 1); 00264 } 00265 00266 /* Print the character C on STREAM as part of the contents of a literal 00267 string whose delimiter is QUOTER. TYPE_LEN is the length in bytes 00268 of the character. */ 00269 00270 void 00271 ada_emit_char (int c, struct type *type, struct ui_file *stream, 00272 int quoter, int type_len) 00273 { 00274 /* If this character fits in the normal ASCII range, and is 00275 a printable character, then print the character as if it was 00276 an ASCII character, even if this is a wide character. 00277 The UCHAR_MAX check is necessary because the isascii function 00278 requires that its argument have a value of an unsigned char, 00279 or EOF (EOF is obviously not printable). */ 00280 if (c <= UCHAR_MAX && isascii (c) && isprint (c)) 00281 { 00282 if (c == quoter && c == '"') 00283 fprintf_filtered (stream, "\"\""); 00284 else 00285 fprintf_filtered (stream, "%c", c); 00286 } 00287 else 00288 fprintf_filtered (stream, "[\"%0*x\"]", type_len * 2, c); 00289 } 00290 00291 /* Character #I of STRING, given that TYPE_LEN is the size in bytes 00292 of a character. */ 00293 00294 static int 00295 char_at (const gdb_byte *string, int i, int type_len, 00296 enum bfd_endian byte_order) 00297 { 00298 if (type_len == 1) 00299 return string[i]; 00300 else 00301 return (int) extract_unsigned_integer (string + type_len * i, 00302 type_len, byte_order); 00303 } 00304 00305 /* Wrapper around memcpy to make it legal argument to ui_file_put. */ 00306 static void 00307 ui_memcpy (void *dest, const char *buffer, long len) 00308 { 00309 memcpy (dest, buffer, (size_t) len); 00310 ((char *) dest)[len] = '\0'; 00311 } 00312 00313 /* Print a floating-point value of type TYPE, pointed to in GDB by 00314 VALADDR, on STREAM. Use Ada formatting conventions: there must be 00315 a decimal point, and at least one digit before and after the 00316 point. We use GNAT format for NaNs and infinities. */ 00317 static void 00318 ada_print_floating (const gdb_byte *valaddr, struct type *type, 00319 struct ui_file *stream) 00320 { 00321 char buffer[64]; 00322 char *s, *result; 00323 struct ui_file *tmp_stream = mem_fileopen (); 00324 struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_stream); 00325 00326 print_floating (valaddr, type, tmp_stream); 00327 ui_file_put (tmp_stream, ui_memcpy, buffer); 00328 do_cleanups (cleanups); 00329 00330 result = buffer; 00331 00332 /* Modify for Ada rules. */ 00333 00334 s = strstr (result, "inf"); 00335 if (s == NULL) 00336 s = strstr (result, "Inf"); 00337 if (s == NULL) 00338 s = strstr (result, "INF"); 00339 if (s != NULL) 00340 strcpy (s, "Inf"); 00341 00342 if (s == NULL) 00343 { 00344 s = strstr (result, "nan"); 00345 if (s == NULL) 00346 s = strstr (result, "NaN"); 00347 if (s == NULL) 00348 s = strstr (result, "Nan"); 00349 if (s != NULL) 00350 { 00351 s[0] = s[2] = 'N'; 00352 if (result[0] == '-') 00353 result += 1; 00354 } 00355 } 00356 00357 if (s == NULL && strchr (result, '.') == NULL) 00358 { 00359 s = strchr (result, 'e'); 00360 if (s == NULL) 00361 fprintf_filtered (stream, "%s.0", result); 00362 else 00363 fprintf_filtered (stream, "%.*s.0%s", (int) (s-result), result, s); 00364 return; 00365 } 00366 fprintf_filtered (stream, "%s", result); 00367 } 00368 00369 void 00370 ada_printchar (int c, struct type *type, struct ui_file *stream) 00371 { 00372 fputs_filtered ("'", stream); 00373 ada_emit_char (c, type, stream, '\'', TYPE_LENGTH (type)); 00374 fputs_filtered ("'", stream); 00375 } 00376 00377 /* [From print_type_scalar in typeprint.c]. Print VAL on STREAM in a 00378 form appropriate for TYPE, if non-NULL. If TYPE is NULL, print VAL 00379 like a default signed integer. */ 00380 00381 void 00382 ada_print_scalar (struct type *type, LONGEST val, struct ui_file *stream) 00383 { 00384 unsigned int i; 00385 unsigned len; 00386 00387 if (!type) 00388 { 00389 print_longest (stream, 'd', 0, val); 00390 return; 00391 } 00392 00393 type = ada_check_typedef (type); 00394 00395 switch (TYPE_CODE (type)) 00396 { 00397 00398 case TYPE_CODE_ENUM: 00399 len = TYPE_NFIELDS (type); 00400 for (i = 0; i < len; i++) 00401 { 00402 if (TYPE_FIELD_ENUMVAL (type, i) == val) 00403 { 00404 break; 00405 } 00406 } 00407 if (i < len) 00408 { 00409 fputs_filtered (ada_enum_name (TYPE_FIELD_NAME (type, i)), stream); 00410 } 00411 else 00412 { 00413 print_longest (stream, 'd', 0, val); 00414 } 00415 break; 00416 00417 case TYPE_CODE_INT: 00418 print_longest (stream, TYPE_UNSIGNED (type) ? 'u' : 'd', 0, val); 00419 break; 00420 00421 case TYPE_CODE_CHAR: 00422 LA_PRINT_CHAR (val, type, stream); 00423 break; 00424 00425 case TYPE_CODE_BOOL: 00426 fprintf_filtered (stream, val ? "true" : "false"); 00427 break; 00428 00429 case TYPE_CODE_RANGE: 00430 ada_print_scalar (TYPE_TARGET_TYPE (type), val, stream); 00431 return; 00432 00433 case TYPE_CODE_UNDEF: 00434 case TYPE_CODE_PTR: 00435 case TYPE_CODE_ARRAY: 00436 case TYPE_CODE_STRUCT: 00437 case TYPE_CODE_UNION: 00438 case TYPE_CODE_FUNC: 00439 case TYPE_CODE_FLT: 00440 case TYPE_CODE_VOID: 00441 case TYPE_CODE_SET: 00442 case TYPE_CODE_STRING: 00443 case TYPE_CODE_ERROR: 00444 case TYPE_CODE_MEMBERPTR: 00445 case TYPE_CODE_METHODPTR: 00446 case TYPE_CODE_METHOD: 00447 case TYPE_CODE_REF: 00448 warning (_("internal error: unhandled type in ada_print_scalar")); 00449 break; 00450 00451 default: 00452 error (_("Invalid type code in symbol table.")); 00453 } 00454 gdb_flush (stream); 00455 } 00456 00457 /* Print the character string STRING, printing at most LENGTH characters. 00458 Printing stops early if the number hits print_max; repeat counts 00459 are printed as appropriate. Print ellipses at the end if we 00460 had to stop before printing LENGTH characters, or if FORCE_ELLIPSES. 00461 TYPE_LEN is the length (1 or 2) of the character type. */ 00462 00463 static void 00464 printstr (struct ui_file *stream, struct type *elttype, const gdb_byte *string, 00465 unsigned int length, int force_ellipses, int type_len, 00466 const struct value_print_options *options) 00467 { 00468 enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (elttype)); 00469 unsigned int i; 00470 unsigned int things_printed = 0; 00471 int in_quotes = 0; 00472 int need_comma = 0; 00473 00474 if (length == 0) 00475 { 00476 fputs_filtered ("\"\"", stream); 00477 return; 00478 } 00479 00480 for (i = 0; i < length && things_printed < options->print_max; i += 1) 00481 { 00482 /* Position of the character we are examining 00483 to see whether it is repeated. */ 00484 unsigned int rep1; 00485 /* Number of repetitions we have detected so far. */ 00486 unsigned int reps; 00487 00488 QUIT; 00489 00490 if (need_comma) 00491 { 00492 fputs_filtered (", ", stream); 00493 need_comma = 0; 00494 } 00495 00496 rep1 = i + 1; 00497 reps = 1; 00498 while (rep1 < length 00499 && char_at (string, rep1, type_len, byte_order) 00500 == char_at (string, i, type_len, byte_order)) 00501 { 00502 rep1 += 1; 00503 reps += 1; 00504 } 00505 00506 if (reps > options->repeat_count_threshold) 00507 { 00508 if (in_quotes) 00509 { 00510 fputs_filtered ("\", ", stream); 00511 in_quotes = 0; 00512 } 00513 fputs_filtered ("'", stream); 00514 ada_emit_char (char_at (string, i, type_len, byte_order), 00515 elttype, stream, '\'', type_len); 00516 fputs_filtered ("'", stream); 00517 fprintf_filtered (stream, _(" <repeats %u times>"), reps); 00518 i = rep1 - 1; 00519 things_printed += options->repeat_count_threshold; 00520 need_comma = 1; 00521 } 00522 else 00523 { 00524 if (!in_quotes) 00525 { 00526 fputs_filtered ("\"", stream); 00527 in_quotes = 1; 00528 } 00529 ada_emit_char (char_at (string, i, type_len, byte_order), 00530 elttype, stream, '"', type_len); 00531 things_printed += 1; 00532 } 00533 } 00534 00535 /* Terminate the quotes if necessary. */ 00536 if (in_quotes) 00537 fputs_filtered ("\"", stream); 00538 00539 if (force_ellipses || i < length) 00540 fputs_filtered ("...", stream); 00541 } 00542 00543 void 00544 ada_printstr (struct ui_file *stream, struct type *type, 00545 const gdb_byte *string, unsigned int length, 00546 const char *encoding, int force_ellipses, 00547 const struct value_print_options *options) 00548 { 00549 printstr (stream, type, string, length, force_ellipses, TYPE_LENGTH (type), 00550 options); 00551 } 00552 00553 00554 /* See val_print for a description of the various parameters of this 00555 function; they are identical. */ 00556 00557 void 00558 ada_val_print (struct type *type, const gdb_byte *valaddr, 00559 int embedded_offset, CORE_ADDR address, 00560 struct ui_file *stream, int recurse, 00561 const struct value *val, 00562 const struct value_print_options *options) 00563 { 00564 volatile struct gdb_exception except; 00565 00566 /* XXX: this catches QUIT/ctrl-c as well. Isn't that busted? */ 00567 TRY_CATCH (except, RETURN_MASK_ALL) 00568 { 00569 ada_val_print_1 (type, valaddr, embedded_offset, address, 00570 stream, recurse, val, options); 00571 } 00572 } 00573 00574 /* Assuming TYPE is a simple array, print the value of this array located 00575 at VALADDR + OFFSET. See ada_val_print for a description of the various 00576 parameters of this function; they are identical. */ 00577 00578 static void 00579 ada_val_print_array (struct type *type, const gdb_byte *valaddr, 00580 int offset, CORE_ADDR address, 00581 struct ui_file *stream, int recurse, 00582 const struct value *val, 00583 const struct value_print_options *options) 00584 { 00585 /* For an array of chars, print with string syntax. */ 00586 if (ada_is_string_type (type) 00587 && (options->format == 0 || options->format == 's')) 00588 { 00589 enum bfd_endian byte_order = gdbarch_byte_order (get_type_arch (type)); 00590 struct type *elttype = TYPE_TARGET_TYPE (type); 00591 unsigned int eltlen; 00592 unsigned int len; 00593 00594 /* We know that ELTTYPE cannot possibly be null, because we found 00595 that TYPE is a string-like type. Similarly, the size of ELTTYPE 00596 should also be non-null, since it's a character-like type. */ 00597 gdb_assert (elttype != NULL); 00598 gdb_assert (TYPE_LENGTH (elttype) != 0); 00599 00600 eltlen = TYPE_LENGTH (elttype); 00601 len = TYPE_LENGTH (type) / eltlen; 00602 00603 if (options->prettyformat_arrays) 00604 print_spaces_filtered (2 + 2 * recurse, stream); 00605 00606 /* If requested, look for the first null char and only print 00607 elements up to it. */ 00608 if (options->stop_print_at_null) 00609 { 00610 int temp_len; 00611 00612 /* Look for a NULL char. */ 00613 for (temp_len = 0; 00614 (temp_len < len 00615 && temp_len < options->print_max 00616 && char_at (valaddr + offset, 00617 temp_len, eltlen, byte_order) != 0); 00618 temp_len += 1); 00619 len = temp_len; 00620 } 00621 00622 printstr (stream, elttype, valaddr + offset, len, 0, eltlen, options); 00623 } 00624 else 00625 { 00626 fprintf_filtered (stream, "("); 00627 print_optional_low_bound (stream, type, options); 00628 if (TYPE_FIELD_BITSIZE (type, 0) > 0) 00629 val_print_packed_array_elements (type, valaddr, offset, 00630 0, stream, recurse, val, options); 00631 else 00632 val_print_array_elements (type, valaddr, offset, address, 00633 stream, recurse, val, options, 0); 00634 fprintf_filtered (stream, ")"); 00635 } 00636 } 00637 00638 /* See the comment on ada_val_print. This function differs in that it 00639 does not catch evaluation errors (leaving that to ada_val_print). */ 00640 00641 static void 00642 ada_val_print_1 (struct type *type, const gdb_byte *valaddr, 00643 int offset, CORE_ADDR address, 00644 struct ui_file *stream, int recurse, 00645 const struct value *original_value, 00646 const struct value_print_options *options) 00647 { 00648 int i; 00649 struct type *elttype; 00650 int offset_aligned; 00651 00652 type = ada_check_typedef (type); 00653 00654 if (ada_is_array_descriptor_type (type) 00655 || (ada_is_constrained_packed_array_type (type) 00656 && TYPE_CODE (type) != TYPE_CODE_PTR)) 00657 { 00658 struct value *mark = value_mark (); 00659 struct value *val; 00660 00661 val = value_from_contents_and_address (type, valaddr + offset, address); 00662 /* If this is a reference, coerce it now. This helps taking care 00663 of the case where ADDRESS is meaningless because original_value 00664 was not an lval. */ 00665 val = coerce_ref (val); 00666 if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF) /* array access type. */ 00667 val = ada_coerce_to_simple_array_ptr (val); 00668 else 00669 val = ada_coerce_to_simple_array (val); 00670 if (val == NULL) 00671 { 00672 gdb_assert (TYPE_CODE (type) == TYPE_CODE_TYPEDEF); 00673 fprintf_filtered (stream, "0x0"); 00674 } 00675 else 00676 ada_val_print_1 (value_type (val), 00677 value_contents_for_printing (val), 00678 value_embedded_offset (val), 00679 value_address (val), stream, recurse, 00680 val, options); 00681 value_free_to_mark (mark); 00682 return; 00683 } 00684 00685 offset_aligned = offset + ada_aligned_value_addr (type, valaddr) - valaddr; 00686 type = printable_val_type (type, valaddr + offset_aligned); 00687 00688 switch (TYPE_CODE (type)) 00689 { 00690 default: 00691 c_val_print (type, valaddr, offset, address, stream, 00692 recurse, original_value, options); 00693 break; 00694 00695 case TYPE_CODE_PTR: 00696 { 00697 c_val_print (type, valaddr, offset, address, 00698 stream, recurse, original_value, options); 00699 00700 if (ada_is_tag_type (type)) 00701 { 00702 struct value *val = 00703 value_from_contents_and_address (type, 00704 valaddr + offset_aligned, 00705 address + offset_aligned); 00706 const char *name = ada_tag_name (val); 00707 00708 if (name != NULL) 00709 fprintf_filtered (stream, " (%s)", name); 00710 } 00711 return; 00712 } 00713 00714 case TYPE_CODE_INT: 00715 case TYPE_CODE_RANGE: 00716 if (ada_is_fixed_point_type (type)) 00717 { 00718 LONGEST v = unpack_long (type, valaddr + offset_aligned); 00719 00720 fprintf_filtered (stream, TYPE_LENGTH (type) < 4 ? "%.11g" : "%.17g", 00721 (double) ada_fixed_to_float (type, v)); 00722 return; 00723 } 00724 else if (TYPE_CODE (type) == TYPE_CODE_RANGE) 00725 { 00726 struct type *target_type = TYPE_TARGET_TYPE (type); 00727 00728 if (TYPE_LENGTH (type) != TYPE_LENGTH (target_type)) 00729 { 00730 /* Obscure case of range type that has different length from 00731 its base type. Perform a conversion, or we will get a 00732 nonsense value. Actually, we could use the same 00733 code regardless of lengths; I'm just avoiding a cast. */ 00734 struct value *v1 00735 = value_from_contents_and_address (type, valaddr + offset, 0); 00736 struct value *v = value_cast (target_type, v1); 00737 00738 ada_val_print_1 (target_type, 00739 value_contents_for_printing (v), 00740 value_embedded_offset (v), 0, 00741 stream, recurse + 1, v, options); 00742 } 00743 else 00744 ada_val_print_1 (TYPE_TARGET_TYPE (type), 00745 valaddr, offset, 00746 address, stream, recurse, 00747 original_value, options); 00748 return; 00749 } 00750 else 00751 { 00752 int format = (options->format ? options->format 00753 : options->output_format); 00754 00755 if (format) 00756 { 00757 struct value_print_options opts = *options; 00758 00759 opts.format = format; 00760 val_print_scalar_formatted (type, valaddr, offset_aligned, 00761 original_value, &opts, 0, stream); 00762 } 00763 else if (ada_is_system_address_type (type)) 00764 { 00765 /* FIXME: We want to print System.Address variables using 00766 the same format as for any access type. But for some 00767 reason GNAT encodes the System.Address type as an int, 00768 so we have to work-around this deficiency by handling 00769 System.Address values as a special case. */ 00770 00771 struct gdbarch *gdbarch = get_type_arch (type); 00772 struct type *ptr_type = builtin_type (gdbarch)->builtin_data_ptr; 00773 CORE_ADDR addr = extract_typed_address (valaddr + offset_aligned, 00774 ptr_type); 00775 00776 fprintf_filtered (stream, "("); 00777 type_print (type, "", stream, -1); 00778 fprintf_filtered (stream, ") "); 00779 fputs_filtered (paddress (gdbarch, addr), stream); 00780 } 00781 else 00782 { 00783 val_print_type_code_int (type, valaddr + offset_aligned, stream); 00784 if (ada_is_character_type (type)) 00785 { 00786 LONGEST c; 00787 00788 fputs_filtered (" ", stream); 00789 c = unpack_long (type, valaddr + offset_aligned); 00790 ada_printchar (c, type, stream); 00791 } 00792 } 00793 return; 00794 } 00795 00796 case TYPE_CODE_ENUM: 00797 { 00798 unsigned int len; 00799 LONGEST val; 00800 00801 if (options->format) 00802 { 00803 val_print_scalar_formatted (type, valaddr, offset_aligned, 00804 original_value, options, 0, stream); 00805 break; 00806 } 00807 len = TYPE_NFIELDS (type); 00808 val = unpack_long (type, valaddr + offset_aligned); 00809 for (i = 0; i < len; i++) 00810 { 00811 QUIT; 00812 if (val == TYPE_FIELD_ENUMVAL (type, i)) 00813 { 00814 break; 00815 } 00816 } 00817 if (i < len) 00818 { 00819 const char *name = ada_enum_name (TYPE_FIELD_NAME (type, i)); 00820 00821 if (name[0] == '\'') 00822 fprintf_filtered (stream, "%ld %s", (long) val, name); 00823 else 00824 fputs_filtered (name, stream); 00825 } 00826 else 00827 { 00828 print_longest (stream, 'd', 0, val); 00829 } 00830 break; 00831 } 00832 00833 case TYPE_CODE_FLT: 00834 if (options->format) 00835 { 00836 c_val_print (type, valaddr, offset, address, stream, 00837 recurse, original_value, options); 00838 return; 00839 } 00840 else 00841 ada_print_floating (valaddr + offset, type, stream); 00842 break; 00843 00844 case TYPE_CODE_UNION: 00845 case TYPE_CODE_STRUCT: 00846 if (ada_is_bogus_array_descriptor (type)) 00847 { 00848 fprintf_filtered (stream, "(...?)"); 00849 return; 00850 } 00851 else 00852 { 00853 print_record (type, valaddr, offset_aligned, 00854 stream, recurse, original_value, options); 00855 return; 00856 } 00857 00858 case TYPE_CODE_ARRAY: 00859 ada_val_print_array (type, valaddr, offset_aligned, 00860 address, stream, recurse, original_value, 00861 options); 00862 return; 00863 00864 case TYPE_CODE_REF: 00865 /* For references, the debugger is expected to print the value as 00866 an address if DEREF_REF is null. But printing an address in place 00867 of the object value would be confusing to an Ada programmer. 00868 So, for Ada values, we print the actual dereferenced value 00869 regardless. */ 00870 elttype = check_typedef (TYPE_TARGET_TYPE (type)); 00871 00872 if (TYPE_CODE (elttype) != TYPE_CODE_UNDEF) 00873 { 00874 CORE_ADDR deref_val_int; 00875 struct value *deref_val; 00876 00877 deref_val = coerce_ref_if_computed (original_value); 00878 if (deref_val) 00879 { 00880 if (ada_is_tagged_type (value_type (deref_val), 1)) 00881 deref_val = ada_tag_value_at_base_address (deref_val); 00882 00883 common_val_print (deref_val, stream, recurse + 1, options, 00884 current_language); 00885 break; 00886 } 00887 00888 deref_val_int = unpack_pointer (type, valaddr + offset_aligned); 00889 if (deref_val_int != 0) 00890 { 00891 deref_val = 00892 ada_value_ind (value_from_pointer 00893 (lookup_pointer_type (elttype), 00894 deref_val_int)); 00895 00896 if (ada_is_tagged_type (value_type (deref_val), 1)) 00897 deref_val = ada_tag_value_at_base_address (deref_val); 00898 00899 val_print (value_type (deref_val), 00900 value_contents_for_printing (deref_val), 00901 value_embedded_offset (deref_val), 00902 value_address (deref_val), stream, recurse + 1, 00903 deref_val, options, current_language); 00904 } 00905 else 00906 fputs_filtered ("(null)", stream); 00907 } 00908 else 00909 fputs_filtered ("???", stream); 00910 00911 break; 00912 } 00913 gdb_flush (stream); 00914 } 00915 00916 static int 00917 print_variant_part (struct type *type, int field_num, 00918 const gdb_byte *valaddr, int offset, 00919 struct ui_file *stream, int recurse, 00920 const struct value *val, 00921 const struct value_print_options *options, 00922 int comma_needed, 00923 struct type *outer_type, int outer_offset) 00924 { 00925 struct type *var_type = TYPE_FIELD_TYPE (type, field_num); 00926 int which = ada_which_variant_applies (var_type, outer_type, 00927 valaddr + outer_offset); 00928 00929 if (which < 0) 00930 return 0; 00931 else 00932 return print_field_values 00933 (TYPE_FIELD_TYPE (var_type, which), 00934 valaddr, 00935 offset + TYPE_FIELD_BITPOS (type, field_num) / HOST_CHAR_BIT 00936 + TYPE_FIELD_BITPOS (var_type, which) / HOST_CHAR_BIT, 00937 stream, recurse, val, options, 00938 comma_needed, outer_type, outer_offset); 00939 } 00940 00941 void 00942 ada_value_print (struct value *val0, struct ui_file *stream, 00943 const struct value_print_options *options) 00944 { 00945 struct value *val = ada_to_fixed_value (val0); 00946 CORE_ADDR address = value_address (val); 00947 struct type *type = ada_check_typedef (value_type (val)); 00948 struct value_print_options opts; 00949 00950 /* If it is a pointer, indicate what it points to. */ 00951 if (TYPE_CODE (type) == TYPE_CODE_PTR) 00952 { 00953 /* Hack: don't print (char *) for char strings. Their 00954 type is indicated by the quoted string anyway. */ 00955 if (TYPE_LENGTH (TYPE_TARGET_TYPE (type)) != sizeof (char) 00956 || TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_INT 00957 || TYPE_UNSIGNED (TYPE_TARGET_TYPE (type))) 00958 { 00959 fprintf_filtered (stream, "("); 00960 type_print (type, "", stream, -1); 00961 fprintf_filtered (stream, ") "); 00962 } 00963 } 00964 else if (ada_is_array_descriptor_type (type)) 00965 { 00966 /* We do not print the type description unless TYPE is an array 00967 access type (this is encoded by the compiler as a typedef to 00968 a fat pointer - hence the check against TYPE_CODE_TYPEDEF). */ 00969 if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF) 00970 { 00971 fprintf_filtered (stream, "("); 00972 type_print (type, "", stream, -1); 00973 fprintf_filtered (stream, ") "); 00974 } 00975 } 00976 else if (ada_is_bogus_array_descriptor (type)) 00977 { 00978 fprintf_filtered (stream, "("); 00979 type_print (type, "", stream, -1); 00980 fprintf_filtered (stream, ") (...?)"); 00981 return; 00982 } 00983 00984 opts = *options; 00985 opts.deref_ref = 1; 00986 val_print (type, value_contents_for_printing (val), 00987 value_embedded_offset (val), address, 00988 stream, 0, val, &opts, current_language); 00989 } 00990 00991 static void 00992 print_record (struct type *type, const gdb_byte *valaddr, 00993 int offset, 00994 struct ui_file *stream, int recurse, 00995 const struct value *val, 00996 const struct value_print_options *options) 00997 { 00998 type = ada_check_typedef (type); 00999 01000 fprintf_filtered (stream, "("); 01001 01002 if (print_field_values (type, valaddr, offset, 01003 stream, recurse, val, options, 01004 0, type, offset) != 0 && options->prettyformat) 01005 { 01006 fprintf_filtered (stream, "\n"); 01007 print_spaces_filtered (2 * recurse, stream); 01008 } 01009 01010 fprintf_filtered (stream, ")"); 01011 } 01012 01013 /* Print out fields of value at VALADDR + OFFSET having structure type TYPE. 01014 01015 TYPE, VALADDR, OFFSET, STREAM, RECURSE, and OPTIONS have the same 01016 meanings as in ada_print_value and ada_val_print. 01017 01018 OUTER_TYPE and OUTER_OFFSET give type and address of enclosing 01019 record (used to get discriminant values when printing variant 01020 parts). 01021 01022 COMMA_NEEDED is 1 if fields have been printed at the current recursion 01023 level, so that a comma is needed before any field printed by this 01024 call. 01025 01026 Returns 1 if COMMA_NEEDED or any fields were printed. */ 01027 01028 static int 01029 print_field_values (struct type *type, const gdb_byte *valaddr, 01030 int offset, struct ui_file *stream, int recurse, 01031 const struct value *val, 01032 const struct value_print_options *options, 01033 int comma_needed, 01034 struct type *outer_type, int outer_offset) 01035 { 01036 int i, len; 01037 01038 len = TYPE_NFIELDS (type); 01039 01040 for (i = 0; i < len; i += 1) 01041 { 01042 if (ada_is_ignored_field (type, i)) 01043 continue; 01044 01045 if (ada_is_wrapper_field (type, i)) 01046 { 01047 comma_needed = 01048 print_field_values (TYPE_FIELD_TYPE (type, i), 01049 valaddr, 01050 (offset 01051 + TYPE_FIELD_BITPOS (type, i) / HOST_CHAR_BIT), 01052 stream, recurse, val, options, 01053 comma_needed, type, offset); 01054 continue; 01055 } 01056 else if (ada_is_variant_part (type, i)) 01057 { 01058 comma_needed = 01059 print_variant_part (type, i, valaddr, 01060 offset, stream, recurse, val, 01061 options, comma_needed, 01062 outer_type, outer_offset); 01063 continue; 01064 } 01065 01066 if (comma_needed) 01067 fprintf_filtered (stream, ", "); 01068 comma_needed = 1; 01069 01070 if (options->prettyformat) 01071 { 01072 fprintf_filtered (stream, "\n"); 01073 print_spaces_filtered (2 + 2 * recurse, stream); 01074 } 01075 else 01076 { 01077 wrap_here (n_spaces (2 + 2 * recurse)); 01078 } 01079 01080 annotate_field_begin (TYPE_FIELD_TYPE (type, i)); 01081 fprintf_filtered (stream, "%.*s", 01082 ada_name_prefix_len (TYPE_FIELD_NAME (type, i)), 01083 TYPE_FIELD_NAME (type, i)); 01084 annotate_field_name_end (); 01085 fputs_filtered (" => ", stream); 01086 annotate_field_value (); 01087 01088 if (TYPE_FIELD_PACKED (type, i)) 01089 { 01090 struct value *v; 01091 01092 /* Bitfields require special handling, especially due to byte 01093 order problems. */ 01094 if (HAVE_CPLUS_STRUCT (type) && TYPE_FIELD_IGNORE (type, i)) 01095 { 01096 fputs_filtered (_("<optimized out or zero length>"), stream); 01097 } 01098 else 01099 { 01100 int bit_pos = TYPE_FIELD_BITPOS (type, i); 01101 int bit_size = TYPE_FIELD_BITSIZE (type, i); 01102 struct value_print_options opts; 01103 01104 adjust_type_signedness (TYPE_FIELD_TYPE (type, i)); 01105 v = ada_value_primitive_packed_val 01106 (NULL, valaddr, 01107 offset + bit_pos / HOST_CHAR_BIT, 01108 bit_pos % HOST_CHAR_BIT, 01109 bit_size, TYPE_FIELD_TYPE (type, i)); 01110 opts = *options; 01111 opts.deref_ref = 0; 01112 val_print (TYPE_FIELD_TYPE (type, i), 01113 value_contents_for_printing (v), 01114 value_embedded_offset (v), 0, 01115 stream, recurse + 1, v, 01116 &opts, current_language); 01117 } 01118 } 01119 else 01120 { 01121 struct value_print_options opts = *options; 01122 01123 opts.deref_ref = 0; 01124 ada_val_print (TYPE_FIELD_TYPE (type, i), 01125 valaddr, 01126 (offset 01127 + TYPE_FIELD_BITPOS (type, i) / HOST_CHAR_BIT), 01128 0, stream, recurse + 1, val, &opts); 01129 } 01130 annotate_field_end (); 01131 } 01132 01133 return comma_needed; 01134 }