GDB (API)
|
00001 /* Support for printing Pascal values for GDB, the GNU debugger. 00002 00003 Copyright (C) 2000-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 /* This file is derived from c-valprint.c */ 00021 00022 #include "defs.h" 00023 #include "gdb_obstack.h" 00024 #include "symtab.h" 00025 #include "gdbtypes.h" 00026 #include "expression.h" 00027 #include "value.h" 00028 #include "command.h" 00029 #include "gdbcmd.h" 00030 #include "gdbcore.h" 00031 #include "demangle.h" 00032 #include "valprint.h" 00033 #include "typeprint.h" 00034 #include "language.h" 00035 #include "target.h" 00036 #include "annotate.h" 00037 #include "p-lang.h" 00038 #include "cp-abi.h" 00039 #include "cp-support.h" 00040 #include "exceptions.h" 00041 00042 00043 /* Decorations for Pascal. */ 00044 00045 static const struct generic_val_print_decorations p_decorations = 00046 { 00047 "", 00048 " + ", 00049 " * I", 00050 "true", 00051 "false", 00052 "void" 00053 }; 00054 00055 /* See val_print for a description of the various parameters of this 00056 function; they are identical. */ 00057 00058 void 00059 pascal_val_print (struct type *type, const gdb_byte *valaddr, 00060 int embedded_offset, CORE_ADDR address, 00061 struct ui_file *stream, int recurse, 00062 const struct value *original_value, 00063 const struct value_print_options *options) 00064 { 00065 struct gdbarch *gdbarch = get_type_arch (type); 00066 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); 00067 unsigned int i = 0; /* Number of characters printed */ 00068 unsigned len; 00069 LONGEST low_bound, high_bound; 00070 struct type *elttype; 00071 unsigned eltlen; 00072 int length_pos, length_size, string_pos; 00073 struct type *char_type; 00074 CORE_ADDR addr; 00075 int want_space = 0; 00076 00077 CHECK_TYPEDEF (type); 00078 switch (TYPE_CODE (type)) 00079 { 00080 case TYPE_CODE_ARRAY: 00081 if (get_array_bounds (type, &low_bound, &high_bound)) 00082 { 00083 len = high_bound - low_bound + 1; 00084 elttype = check_typedef (TYPE_TARGET_TYPE (type)); 00085 eltlen = TYPE_LENGTH (elttype); 00086 if (options->prettyformat_arrays) 00087 { 00088 print_spaces_filtered (2 + 2 * recurse, stream); 00089 } 00090 /* If 's' format is used, try to print out as string. 00091 If no format is given, print as string if element type 00092 is of TYPE_CODE_CHAR and element size is 1,2 or 4. */ 00093 if (options->format == 's' 00094 || ((eltlen == 1 || eltlen == 2 || eltlen == 4) 00095 && TYPE_CODE (elttype) == TYPE_CODE_CHAR 00096 && options->format == 0)) 00097 { 00098 /* If requested, look for the first null char and only print 00099 elements up to it. */ 00100 if (options->stop_print_at_null) 00101 { 00102 unsigned int temp_len; 00103 00104 /* Look for a NULL char. */ 00105 for (temp_len = 0; 00106 extract_unsigned_integer (valaddr + embedded_offset + 00107 temp_len * eltlen, eltlen, 00108 byte_order) 00109 && temp_len < len && temp_len < options->print_max; 00110 temp_len++); 00111 len = temp_len; 00112 } 00113 00114 LA_PRINT_STRING (stream, TYPE_TARGET_TYPE (type), 00115 valaddr + embedded_offset, len, NULL, 0, 00116 options); 00117 i = len; 00118 } 00119 else 00120 { 00121 fprintf_filtered (stream, "{"); 00122 /* If this is a virtual function table, print the 0th 00123 entry specially, and the rest of the members normally. */ 00124 if (pascal_object_is_vtbl_ptr_type (elttype)) 00125 { 00126 i = 1; 00127 fprintf_filtered (stream, "%d vtable entries", len - 1); 00128 } 00129 else 00130 { 00131 i = 0; 00132 } 00133 val_print_array_elements (type, valaddr, embedded_offset, 00134 address, stream, recurse, 00135 original_value, options, i); 00136 fprintf_filtered (stream, "}"); 00137 } 00138 break; 00139 } 00140 /* Array of unspecified length: treat like pointer to first elt. */ 00141 addr = address + embedded_offset; 00142 goto print_unpacked_pointer; 00143 00144 case TYPE_CODE_PTR: 00145 if (options->format && options->format != 's') 00146 { 00147 val_print_scalar_formatted (type, valaddr, embedded_offset, 00148 original_value, options, 0, stream); 00149 break; 00150 } 00151 if (options->vtblprint && pascal_object_is_vtbl_ptr_type (type)) 00152 { 00153 /* Print the unmangled name if desired. */ 00154 /* Print vtable entry - we only get here if we ARE using 00155 -fvtable_thunks. (Otherwise, look under TYPE_CODE_STRUCT.) */ 00156 /* Extract the address, assume that it is unsigned. */ 00157 addr = extract_unsigned_integer (valaddr + embedded_offset, 00158 TYPE_LENGTH (type), byte_order); 00159 print_address_demangle (options, gdbarch, addr, stream, demangle); 00160 break; 00161 } 00162 check_typedef (TYPE_TARGET_TYPE (type)); 00163 00164 addr = unpack_pointer (type, valaddr + embedded_offset); 00165 print_unpacked_pointer: 00166 elttype = check_typedef (TYPE_TARGET_TYPE (type)); 00167 00168 if (TYPE_CODE (elttype) == TYPE_CODE_FUNC) 00169 { 00170 /* Try to print what function it points to. */ 00171 print_address_demangle (options, gdbarch, addr, stream, demangle); 00172 return; 00173 } 00174 00175 if (options->addressprint && options->format != 's') 00176 { 00177 fputs_filtered (paddress (gdbarch, addr), stream); 00178 want_space = 1; 00179 } 00180 00181 /* For a pointer to char or unsigned char, also print the string 00182 pointed to, unless pointer is null. */ 00183 if (((TYPE_LENGTH (elttype) == 1 00184 && (TYPE_CODE (elttype) == TYPE_CODE_INT 00185 || TYPE_CODE (elttype) == TYPE_CODE_CHAR)) 00186 || ((TYPE_LENGTH (elttype) == 2 || TYPE_LENGTH (elttype) == 4) 00187 && TYPE_CODE (elttype) == TYPE_CODE_CHAR)) 00188 && (options->format == 0 || options->format == 's') 00189 && addr != 0) 00190 { 00191 if (want_space) 00192 fputs_filtered (" ", stream); 00193 /* No wide string yet. */ 00194 i = val_print_string (elttype, NULL, addr, -1, stream, options); 00195 } 00196 /* Also for pointers to pascal strings. */ 00197 /* Note: this is Free Pascal specific: 00198 as GDB does not recognize stabs pascal strings 00199 Pascal strings are mapped to records 00200 with lowercase names PM. */ 00201 if (is_pascal_string_type (elttype, &length_pos, &length_size, 00202 &string_pos, &char_type, NULL) 00203 && addr != 0) 00204 { 00205 ULONGEST string_length; 00206 void *buffer; 00207 00208 if (want_space) 00209 fputs_filtered (" ", stream); 00210 buffer = xmalloc (length_size); 00211 read_memory (addr + length_pos, buffer, length_size); 00212 string_length = extract_unsigned_integer (buffer, length_size, 00213 byte_order); 00214 xfree (buffer); 00215 i = val_print_string (char_type, NULL, 00216 addr + string_pos, string_length, 00217 stream, options); 00218 } 00219 else if (pascal_object_is_vtbl_member (type)) 00220 { 00221 /* Print vtbl's nicely. */ 00222 CORE_ADDR vt_address = unpack_pointer (type, 00223 valaddr + embedded_offset); 00224 struct bound_minimal_symbol msymbol = 00225 lookup_minimal_symbol_by_pc (vt_address); 00226 00227 /* If 'symbol_print' is set, we did the work above. */ 00228 if (!options->symbol_print 00229 && (msymbol.minsym != NULL) 00230 && (vt_address == SYMBOL_VALUE_ADDRESS (msymbol.minsym))) 00231 { 00232 if (want_space) 00233 fputs_filtered (" ", stream); 00234 fputs_filtered ("<", stream); 00235 fputs_filtered (SYMBOL_PRINT_NAME (msymbol.minsym), stream); 00236 fputs_filtered (">", stream); 00237 want_space = 1; 00238 } 00239 if (vt_address && options->vtblprint) 00240 { 00241 struct value *vt_val; 00242 struct symbol *wsym = (struct symbol *) NULL; 00243 struct type *wtype; 00244 struct block *block = (struct block *) NULL; 00245 struct field_of_this_result is_this_fld; 00246 00247 if (want_space) 00248 fputs_filtered (" ", stream); 00249 00250 if (msymbol.minsym != NULL) 00251 wsym = lookup_symbol (SYMBOL_LINKAGE_NAME (msymbol.minsym), 00252 block, 00253 VAR_DOMAIN, &is_this_fld); 00254 00255 if (wsym) 00256 { 00257 wtype = SYMBOL_TYPE (wsym); 00258 } 00259 else 00260 { 00261 wtype = TYPE_TARGET_TYPE (type); 00262 } 00263 vt_val = value_at (wtype, vt_address); 00264 common_val_print (vt_val, stream, recurse + 1, options, 00265 current_language); 00266 if (options->prettyformat) 00267 { 00268 fprintf_filtered (stream, "\n"); 00269 print_spaces_filtered (2 + 2 * recurse, stream); 00270 } 00271 } 00272 } 00273 00274 return; 00275 00276 case TYPE_CODE_REF: 00277 case TYPE_CODE_ENUM: 00278 case TYPE_CODE_FLAGS: 00279 case TYPE_CODE_FUNC: 00280 case TYPE_CODE_RANGE: 00281 case TYPE_CODE_INT: 00282 case TYPE_CODE_FLT: 00283 case TYPE_CODE_VOID: 00284 case TYPE_CODE_ERROR: 00285 case TYPE_CODE_UNDEF: 00286 case TYPE_CODE_BOOL: 00287 case TYPE_CODE_CHAR: 00288 generic_val_print (type, valaddr, embedded_offset, address, 00289 stream, recurse, original_value, options, 00290 &p_decorations); 00291 break; 00292 00293 case TYPE_CODE_UNION: 00294 if (recurse && !options->unionprint) 00295 { 00296 fprintf_filtered (stream, "{...}"); 00297 break; 00298 } 00299 /* Fall through. */ 00300 case TYPE_CODE_STRUCT: 00301 if (options->vtblprint && pascal_object_is_vtbl_ptr_type (type)) 00302 { 00303 /* Print the unmangled name if desired. */ 00304 /* Print vtable entry - we only get here if NOT using 00305 -fvtable_thunks. (Otherwise, look under TYPE_CODE_PTR.) */ 00306 /* Extract the address, assume that it is unsigned. */ 00307 print_address_demangle 00308 (options, gdbarch, 00309 extract_unsigned_integer (valaddr + embedded_offset 00310 + TYPE_FIELD_BITPOS (type, 00311 VTBL_FNADDR_OFFSET) / 8, 00312 TYPE_LENGTH (TYPE_FIELD_TYPE (type, 00313 VTBL_FNADDR_OFFSET)), 00314 byte_order), 00315 stream, demangle); 00316 } 00317 else 00318 { 00319 if (is_pascal_string_type (type, &length_pos, &length_size, 00320 &string_pos, &char_type, NULL)) 00321 { 00322 len = extract_unsigned_integer (valaddr + embedded_offset 00323 + length_pos, length_size, 00324 byte_order); 00325 LA_PRINT_STRING (stream, char_type, 00326 valaddr + embedded_offset + string_pos, 00327 len, NULL, 0, options); 00328 } 00329 else 00330 pascal_object_print_value_fields (type, valaddr, embedded_offset, 00331 address, stream, recurse, 00332 original_value, options, 00333 NULL, 0); 00334 } 00335 break; 00336 00337 case TYPE_CODE_SET: 00338 elttype = TYPE_INDEX_TYPE (type); 00339 CHECK_TYPEDEF (elttype); 00340 if (TYPE_STUB (elttype)) 00341 { 00342 fprintf_filtered (stream, "<incomplete type>"); 00343 gdb_flush (stream); 00344 break; 00345 } 00346 else 00347 { 00348 struct type *range = elttype; 00349 LONGEST low_bound, high_bound; 00350 int i; 00351 int need_comma = 0; 00352 00353 fputs_filtered ("[", stream); 00354 00355 i = get_discrete_bounds (range, &low_bound, &high_bound); 00356 if (low_bound == 0 && high_bound == -1 && TYPE_LENGTH (type) > 0) 00357 { 00358 /* If we know the size of the set type, we can figure out the 00359 maximum value. */ 00360 i = 0; 00361 high_bound = TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1; 00362 TYPE_HIGH_BOUND (range) = high_bound; 00363 } 00364 maybe_bad_bstring: 00365 if (i < 0) 00366 { 00367 fputs_filtered ("<error value>", stream); 00368 goto done; 00369 } 00370 00371 for (i = low_bound; i <= high_bound; i++) 00372 { 00373 int element = value_bit_index (type, 00374 valaddr + embedded_offset, i); 00375 00376 if (element < 0) 00377 { 00378 i = element; 00379 goto maybe_bad_bstring; 00380 } 00381 if (element) 00382 { 00383 if (need_comma) 00384 fputs_filtered (", ", stream); 00385 print_type_scalar (range, i, stream); 00386 need_comma = 1; 00387 00388 if (i + 1 <= high_bound 00389 && value_bit_index (type, 00390 valaddr + embedded_offset, ++i)) 00391 { 00392 int j = i; 00393 00394 fputs_filtered ("..", stream); 00395 while (i + 1 <= high_bound 00396 && value_bit_index (type, 00397 valaddr + embedded_offset, 00398 ++i)) 00399 j = i; 00400 print_type_scalar (range, j, stream); 00401 } 00402 } 00403 } 00404 done: 00405 fputs_filtered ("]", stream); 00406 } 00407 break; 00408 00409 default: 00410 error (_("Invalid pascal type code %d in symbol table."), 00411 TYPE_CODE (type)); 00412 } 00413 gdb_flush (stream); 00414 } 00415 00416 void 00417 pascal_value_print (struct value *val, struct ui_file *stream, 00418 const struct value_print_options *options) 00419 { 00420 struct type *type = value_type (val); 00421 struct value_print_options opts = *options; 00422 00423 opts.deref_ref = 1; 00424 00425 /* If it is a pointer, indicate what it points to. 00426 00427 Print type also if it is a reference. 00428 00429 Object pascal: if it is a member pointer, we will take care 00430 of that when we print it. */ 00431 if (TYPE_CODE (type) == TYPE_CODE_PTR 00432 || TYPE_CODE (type) == TYPE_CODE_REF) 00433 { 00434 /* Hack: remove (char *) for char strings. Their 00435 type is indicated by the quoted string anyway. */ 00436 if (TYPE_CODE (type) == TYPE_CODE_PTR 00437 && TYPE_NAME (type) == NULL 00438 && TYPE_NAME (TYPE_TARGET_TYPE (type)) != NULL 00439 && strcmp (TYPE_NAME (TYPE_TARGET_TYPE (type)), "char") == 0) 00440 { 00441 /* Print nothing. */ 00442 } 00443 else 00444 { 00445 fprintf_filtered (stream, "("); 00446 type_print (type, "", stream, -1); 00447 fprintf_filtered (stream, ") "); 00448 } 00449 } 00450 common_val_print (val, stream, 0, &opts, current_language); 00451 } 00452 00453 00454 static void 00455 show_pascal_static_field_print (struct ui_file *file, int from_tty, 00456 struct cmd_list_element *c, const char *value) 00457 { 00458 fprintf_filtered (file, _("Printing of pascal static members is %s.\n"), 00459 value); 00460 } 00461 00462 static struct obstack dont_print_vb_obstack; 00463 static struct obstack dont_print_statmem_obstack; 00464 00465 static void pascal_object_print_static_field (struct value *, 00466 struct ui_file *, int, 00467 const struct value_print_options *); 00468 00469 static void pascal_object_print_value (struct type *, const gdb_byte *, 00470 int, 00471 CORE_ADDR, struct ui_file *, int, 00472 const struct value *, 00473 const struct value_print_options *, 00474 struct type **); 00475 00476 /* It was changed to this after 2.4.5. */ 00477 const char pascal_vtbl_ptr_name[] = 00478 {'_', '_', 'v', 't', 'b', 'l', '_', 'p', 't', 'r', '_', 't', 'y', 'p', 'e', 0}; 00479 00480 /* Return truth value for assertion that TYPE is of the type 00481 "pointer to virtual function". */ 00482 00483 int 00484 pascal_object_is_vtbl_ptr_type (struct type *type) 00485 { 00486 const char *typename = type_name_no_tag (type); 00487 00488 return (typename != NULL 00489 && strcmp (typename, pascal_vtbl_ptr_name) == 0); 00490 } 00491 00492 /* Return truth value for the assertion that TYPE is of the type 00493 "pointer to virtual function table". */ 00494 00495 int 00496 pascal_object_is_vtbl_member (struct type *type) 00497 { 00498 if (TYPE_CODE (type) == TYPE_CODE_PTR) 00499 { 00500 type = TYPE_TARGET_TYPE (type); 00501 if (TYPE_CODE (type) == TYPE_CODE_ARRAY) 00502 { 00503 type = TYPE_TARGET_TYPE (type); 00504 if (TYPE_CODE (type) == TYPE_CODE_STRUCT /* If not using 00505 thunks. */ 00506 || TYPE_CODE (type) == TYPE_CODE_PTR) /* If using thunks. */ 00507 { 00508 /* Virtual functions tables are full of pointers 00509 to virtual functions. */ 00510 return pascal_object_is_vtbl_ptr_type (type); 00511 } 00512 } 00513 } 00514 return 0; 00515 } 00516 00517 /* Mutually recursive subroutines of pascal_object_print_value and 00518 c_val_print to print out a structure's fields: 00519 pascal_object_print_value_fields and pascal_object_print_value. 00520 00521 TYPE, VALADDR, ADDRESS, STREAM, RECURSE, and OPTIONS have the 00522 same meanings as in pascal_object_print_value and c_val_print. 00523 00524 DONT_PRINT is an array of baseclass types that we 00525 should not print, or zero if called from top level. */ 00526 00527 void 00528 pascal_object_print_value_fields (struct type *type, const gdb_byte *valaddr, 00529 int offset, 00530 CORE_ADDR address, struct ui_file *stream, 00531 int recurse, 00532 const struct value *val, 00533 const struct value_print_options *options, 00534 struct type **dont_print_vb, 00535 int dont_print_statmem) 00536 { 00537 int i, len, n_baseclasses; 00538 char *last_dont_print = obstack_next_free (&dont_print_statmem_obstack); 00539 00540 CHECK_TYPEDEF (type); 00541 00542 fprintf_filtered (stream, "{"); 00543 len = TYPE_NFIELDS (type); 00544 n_baseclasses = TYPE_N_BASECLASSES (type); 00545 00546 /* Print out baseclasses such that we don't print 00547 duplicates of virtual baseclasses. */ 00548 if (n_baseclasses > 0) 00549 pascal_object_print_value (type, valaddr, offset, address, 00550 stream, recurse + 1, val, 00551 options, dont_print_vb); 00552 00553 if (!len && n_baseclasses == 1) 00554 fprintf_filtered (stream, "<No data fields>"); 00555 else 00556 { 00557 struct obstack tmp_obstack = dont_print_statmem_obstack; 00558 int fields_seen = 0; 00559 00560 if (dont_print_statmem == 0) 00561 { 00562 /* If we're at top level, carve out a completely fresh 00563 chunk of the obstack and use that until this particular 00564 invocation returns. */ 00565 obstack_finish (&dont_print_statmem_obstack); 00566 } 00567 00568 for (i = n_baseclasses; i < len; i++) 00569 { 00570 /* If requested, skip printing of static fields. */ 00571 if (!options->pascal_static_field_print 00572 && field_is_static (&TYPE_FIELD (type, i))) 00573 continue; 00574 if (fields_seen) 00575 fprintf_filtered (stream, ", "); 00576 else if (n_baseclasses > 0) 00577 { 00578 if (options->prettyformat) 00579 { 00580 fprintf_filtered (stream, "\n"); 00581 print_spaces_filtered (2 + 2 * recurse, stream); 00582 fputs_filtered ("members of ", stream); 00583 fputs_filtered (type_name_no_tag (type), stream); 00584 fputs_filtered (": ", stream); 00585 } 00586 } 00587 fields_seen = 1; 00588 00589 if (options->prettyformat) 00590 { 00591 fprintf_filtered (stream, "\n"); 00592 print_spaces_filtered (2 + 2 * recurse, stream); 00593 } 00594 else 00595 { 00596 wrap_here (n_spaces (2 + 2 * recurse)); 00597 } 00598 00599 annotate_field_begin (TYPE_FIELD_TYPE (type, i)); 00600 00601 if (field_is_static (&TYPE_FIELD (type, i))) 00602 fputs_filtered ("static ", stream); 00603 fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i), 00604 language_cplus, 00605 DMGL_PARAMS | DMGL_ANSI); 00606 annotate_field_name_end (); 00607 fputs_filtered (" = ", stream); 00608 annotate_field_value (); 00609 00610 if (!field_is_static (&TYPE_FIELD (type, i)) 00611 && TYPE_FIELD_PACKED (type, i)) 00612 { 00613 struct value *v; 00614 00615 /* Bitfields require special handling, especially due to byte 00616 order problems. */ 00617 if (TYPE_FIELD_IGNORE (type, i)) 00618 { 00619 fputs_filtered ("<optimized out or zero length>", stream); 00620 } 00621 else if (value_bits_synthetic_pointer (val, 00622 TYPE_FIELD_BITPOS (type, 00623 i), 00624 TYPE_FIELD_BITSIZE (type, 00625 i))) 00626 { 00627 fputs_filtered (_("<synthetic pointer>"), stream); 00628 } 00629 else if (!value_bits_valid (val, TYPE_FIELD_BITPOS (type, i), 00630 TYPE_FIELD_BITSIZE (type, i))) 00631 { 00632 val_print_optimized_out (val, stream); 00633 } 00634 else 00635 { 00636 struct value_print_options opts = *options; 00637 00638 v = value_field_bitfield (type, i, valaddr, offset, val); 00639 00640 opts.deref_ref = 0; 00641 common_val_print (v, stream, recurse + 1, &opts, 00642 current_language); 00643 } 00644 } 00645 else 00646 { 00647 if (TYPE_FIELD_IGNORE (type, i)) 00648 { 00649 fputs_filtered ("<optimized out or zero length>", stream); 00650 } 00651 else if (field_is_static (&TYPE_FIELD (type, i))) 00652 { 00653 /* struct value *v = value_static_field (type, i); 00654 v4.17 specific. */ 00655 struct value *v; 00656 00657 v = value_field_bitfield (type, i, valaddr, offset, val); 00658 00659 if (v == NULL) 00660 val_print_optimized_out (NULL, stream); 00661 else 00662 pascal_object_print_static_field (v, stream, recurse + 1, 00663 options); 00664 } 00665 else 00666 { 00667 struct value_print_options opts = *options; 00668 00669 opts.deref_ref = 0; 00670 /* val_print (TYPE_FIELD_TYPE (type, i), 00671 valaddr + TYPE_FIELD_BITPOS (type, i) / 8, 00672 address + TYPE_FIELD_BITPOS (type, i) / 8, 0, 00673 stream, format, 0, recurse + 1, pretty); */ 00674 val_print (TYPE_FIELD_TYPE (type, i), 00675 valaddr, offset + TYPE_FIELD_BITPOS (type, i) / 8, 00676 address, stream, recurse + 1, val, &opts, 00677 current_language); 00678 } 00679 } 00680 annotate_field_end (); 00681 } 00682 00683 if (dont_print_statmem == 0) 00684 { 00685 /* Free the space used to deal with the printing 00686 of the members from top level. */ 00687 obstack_free (&dont_print_statmem_obstack, last_dont_print); 00688 dont_print_statmem_obstack = tmp_obstack; 00689 } 00690 00691 if (options->prettyformat) 00692 { 00693 fprintf_filtered (stream, "\n"); 00694 print_spaces_filtered (2 * recurse, stream); 00695 } 00696 } 00697 fprintf_filtered (stream, "}"); 00698 } 00699 00700 /* Special val_print routine to avoid printing multiple copies of virtual 00701 baseclasses. */ 00702 00703 static void 00704 pascal_object_print_value (struct type *type, const gdb_byte *valaddr, 00705 int offset, 00706 CORE_ADDR address, struct ui_file *stream, 00707 int recurse, 00708 const struct value *val, 00709 const struct value_print_options *options, 00710 struct type **dont_print_vb) 00711 { 00712 struct type **last_dont_print 00713 = (struct type **) obstack_next_free (&dont_print_vb_obstack); 00714 struct obstack tmp_obstack = dont_print_vb_obstack; 00715 int i, n_baseclasses = TYPE_N_BASECLASSES (type); 00716 00717 if (dont_print_vb == 0) 00718 { 00719 /* If we're at top level, carve out a completely fresh 00720 chunk of the obstack and use that until this particular 00721 invocation returns. */ 00722 /* Bump up the high-water mark. Now alpha is omega. */ 00723 obstack_finish (&dont_print_vb_obstack); 00724 } 00725 00726 for (i = 0; i < n_baseclasses; i++) 00727 { 00728 int boffset = 0; 00729 struct type *baseclass = check_typedef (TYPE_BASECLASS (type, i)); 00730 const char *basename = type_name_no_tag (baseclass); 00731 const gdb_byte *base_valaddr = NULL; 00732 int thisoffset; 00733 volatile struct gdb_exception ex; 00734 int skip = 0; 00735 00736 if (BASETYPE_VIA_VIRTUAL (type, i)) 00737 { 00738 struct type **first_dont_print 00739 = (struct type **) obstack_base (&dont_print_vb_obstack); 00740 00741 int j = (struct type **) obstack_next_free (&dont_print_vb_obstack) 00742 - first_dont_print; 00743 00744 while (--j >= 0) 00745 if (baseclass == first_dont_print[j]) 00746 goto flush_it; 00747 00748 obstack_ptr_grow (&dont_print_vb_obstack, baseclass); 00749 } 00750 00751 thisoffset = offset; 00752 00753 TRY_CATCH (ex, RETURN_MASK_ERROR) 00754 { 00755 boffset = baseclass_offset (type, i, valaddr, offset, address, val); 00756 } 00757 if (ex.reason < 0 && ex.error == NOT_AVAILABLE_ERROR) 00758 skip = -1; 00759 else if (ex.reason < 0) 00760 skip = 1; 00761 else 00762 { 00763 skip = 0; 00764 00765 /* The virtual base class pointer might have been clobbered by the 00766 user program. Make sure that it still points to a valid memory 00767 location. */ 00768 00769 if (boffset < 0 || boffset >= TYPE_LENGTH (type)) 00770 { 00771 gdb_byte *buf; 00772 struct cleanup *back_to; 00773 00774 buf = xmalloc (TYPE_LENGTH (baseclass)); 00775 back_to = make_cleanup (xfree, buf); 00776 00777 base_valaddr = buf; 00778 if (target_read_memory (address + boffset, buf, 00779 TYPE_LENGTH (baseclass)) != 0) 00780 skip = 1; 00781 address = address + boffset; 00782 thisoffset = 0; 00783 boffset = 0; 00784 do_cleanups (back_to); 00785 } 00786 else 00787 base_valaddr = valaddr; 00788 } 00789 00790 if (options->prettyformat) 00791 { 00792 fprintf_filtered (stream, "\n"); 00793 print_spaces_filtered (2 * recurse, stream); 00794 } 00795 fputs_filtered ("<", stream); 00796 /* Not sure what the best notation is in the case where there is no 00797 baseclass name. */ 00798 00799 fputs_filtered (basename ? basename : "", stream); 00800 fputs_filtered ("> = ", stream); 00801 00802 if (skip < 0) 00803 val_print_unavailable (stream); 00804 else if (skip > 0) 00805 val_print_invalid_address (stream); 00806 else 00807 pascal_object_print_value_fields (baseclass, base_valaddr, 00808 thisoffset + boffset, address, 00809 stream, recurse, val, options, 00810 (struct type **) obstack_base (&dont_print_vb_obstack), 00811 0); 00812 fputs_filtered (", ", stream); 00813 00814 flush_it: 00815 ; 00816 } 00817 00818 if (dont_print_vb == 0) 00819 { 00820 /* Free the space used to deal with the printing 00821 of this type from top level. */ 00822 obstack_free (&dont_print_vb_obstack, last_dont_print); 00823 /* Reset watermark so that we can continue protecting 00824 ourselves from whatever we were protecting ourselves. */ 00825 dont_print_vb_obstack = tmp_obstack; 00826 } 00827 } 00828 00829 /* Print value of a static member. 00830 To avoid infinite recursion when printing a class that contains 00831 a static instance of the class, we keep the addresses of all printed 00832 static member classes in an obstack and refuse to print them more 00833 than once. 00834 00835 VAL contains the value to print, STREAM, RECURSE, and OPTIONS 00836 have the same meanings as in c_val_print. */ 00837 00838 static void 00839 pascal_object_print_static_field (struct value *val, 00840 struct ui_file *stream, 00841 int recurse, 00842 const struct value_print_options *options) 00843 { 00844 struct type *type = value_type (val); 00845 struct value_print_options opts; 00846 00847 if (TYPE_CODE (type) == TYPE_CODE_STRUCT) 00848 { 00849 CORE_ADDR *first_dont_print, addr; 00850 int i; 00851 00852 first_dont_print 00853 = (CORE_ADDR *) obstack_base (&dont_print_statmem_obstack); 00854 i = (CORE_ADDR *) obstack_next_free (&dont_print_statmem_obstack) 00855 - first_dont_print; 00856 00857 while (--i >= 0) 00858 { 00859 if (value_address (val) == first_dont_print[i]) 00860 { 00861 fputs_filtered ("\ 00862 <same as static member of an already seen type>", 00863 stream); 00864 return; 00865 } 00866 } 00867 00868 addr = value_address (val); 00869 obstack_grow (&dont_print_statmem_obstack, (char *) &addr, 00870 sizeof (CORE_ADDR)); 00871 00872 CHECK_TYPEDEF (type); 00873 pascal_object_print_value_fields (type, 00874 value_contents_for_printing (val), 00875 value_embedded_offset (val), 00876 addr, 00877 stream, recurse, 00878 val, options, NULL, 1); 00879 return; 00880 } 00881 00882 opts = *options; 00883 opts.deref_ref = 0; 00884 common_val_print (val, stream, recurse, &opts, current_language); 00885 } 00886 00887 /* -Wmissing-prototypes */ 00888 extern initialize_file_ftype _initialize_pascal_valprint; 00889 00890 void 00891 _initialize_pascal_valprint (void) 00892 { 00893 add_setshow_boolean_cmd ("pascal_static-members", class_support, 00894 &user_print_options.pascal_static_field_print, _("\ 00895 Set printing of pascal static members."), _("\ 00896 Show printing of pascal static members."), NULL, 00897 NULL, 00898 show_pascal_static_field_print, 00899 &setprintlist, &showprintlist); 00900 }