1 /* Support for printing Pascal values for GDB, the GNU debugger.
3 Copyright (C) 2000, 2001, 2003, 2005, 2006, 2007, 2008, 2009, 2010, 2011
4 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 /* This file is derived from c-valprint.c */
24 #include "gdb_obstack.h"
27 #include "expression.h"
34 #include "typeprint.h"
40 #include "cp-support.h"
41 #include "exceptions.h"
44 /* See val_print for a description of the various parameters of this
45 function; they are identical. The semantics of the return value is
46 also identical to val_print. */
49 pascal_val_print (struct type *type, const gdb_byte *valaddr,
50 int embedded_offset, CORE_ADDR address,
51 struct ui_file *stream, int recurse,
52 const struct value *original_value,
53 const struct value_print_options *options)
55 struct gdbarch *gdbarch = get_type_arch (type);
56 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
57 unsigned int i = 0; /* Number of characters printed */
59 LONGEST low_bound, high_bound;
62 int length_pos, length_size, string_pos;
63 struct type *char_type;
68 switch (TYPE_CODE (type))
71 if (get_array_bounds (type, &low_bound, &high_bound))
73 len = high_bound - low_bound + 1;
74 elttype = check_typedef (TYPE_TARGET_TYPE (type));
75 eltlen = TYPE_LENGTH (elttype);
76 if (options->prettyprint_arrays)
78 print_spaces_filtered (2 + 2 * recurse, stream);
80 /* If 's' format is used, try to print out as string.
81 If no format is given, print as string if element type
82 is of TYPE_CODE_CHAR and element size is 1,2 or 4. */
83 if (options->format == 's'
84 || ((eltlen == 1 || eltlen == 2 || eltlen == 4)
85 && TYPE_CODE (elttype) == TYPE_CODE_CHAR
86 && options->format == 0))
88 /* If requested, look for the first null char and only print
90 if (options->stop_print_at_null)
92 unsigned int temp_len;
94 /* Look for a NULL char. */
96 extract_unsigned_integer (valaddr + embedded_offset +
97 temp_len * eltlen, eltlen,
99 && temp_len < len && temp_len < options->print_max;
104 LA_PRINT_STRING (stream, TYPE_TARGET_TYPE (type),
105 valaddr + embedded_offset, len, NULL, 0,
111 fprintf_filtered (stream, "{");
112 /* If this is a virtual function table, print the 0th
113 entry specially, and the rest of the members normally. */
114 if (pascal_object_is_vtbl_ptr_type (elttype))
117 fprintf_filtered (stream, "%d vtable entries", len - 1);
123 val_print_array_elements (type, valaddr, embedded_offset,
124 address, stream, recurse,
125 original_value, options, i);
126 fprintf_filtered (stream, "}");
130 /* Array of unspecified length: treat like pointer to first elt. */
131 addr = address + embedded_offset;
132 goto print_unpacked_pointer;
135 if (options->format && options->format != 's')
137 val_print_scalar_formatted (type, valaddr, embedded_offset,
138 original_value, options, 0, stream);
141 if (options->vtblprint && pascal_object_is_vtbl_ptr_type (type))
143 /* Print the unmangled name if desired. */
144 /* Print vtable entry - we only get here if we ARE using
145 -fvtable_thunks. (Otherwise, look under TYPE_CODE_STRUCT.) */
146 /* Extract the address, assume that it is unsigned. */
147 addr = extract_unsigned_integer (valaddr + embedded_offset,
148 TYPE_LENGTH (type), byte_order);
149 print_address_demangle (gdbarch, addr, stream, demangle);
152 check_typedef (TYPE_TARGET_TYPE (type));
154 addr = unpack_pointer (type, valaddr + embedded_offset);
155 print_unpacked_pointer:
156 elttype = check_typedef (TYPE_TARGET_TYPE (type));
158 if (TYPE_CODE (elttype) == TYPE_CODE_FUNC)
160 /* Try to print what function it points to. */
161 print_address_demangle (gdbarch, addr, stream, demangle);
162 /* Return value is irrelevant except for string pointers. */
166 if (options->addressprint && options->format != 's')
168 fputs_filtered (paddress (gdbarch, addr), stream);
171 /* For a pointer to char or unsigned char, also print the string
172 pointed to, unless pointer is null. */
173 if (((TYPE_LENGTH (elttype) == 1
174 && (TYPE_CODE (elttype) == TYPE_CODE_INT
175 || TYPE_CODE (elttype) == TYPE_CODE_CHAR))
176 || ((TYPE_LENGTH (elttype) == 2 || TYPE_LENGTH (elttype) == 4)
177 && TYPE_CODE (elttype) == TYPE_CODE_CHAR))
178 && (options->format == 0 || options->format == 's')
181 /* No wide string yet. */
182 i = val_print_string (elttype, NULL, addr, -1, stream, options);
184 /* Also for pointers to pascal strings. */
185 /* Note: this is Free Pascal specific:
186 as GDB does not recognize stabs pascal strings
187 Pascal strings are mapped to records
188 with lowercase names PM. */
189 if (is_pascal_string_type (elttype, &length_pos, &length_size,
190 &string_pos, &char_type, NULL)
193 ULONGEST string_length;
196 buffer = xmalloc (length_size);
197 read_memory (addr + length_pos, buffer, length_size);
198 string_length = extract_unsigned_integer (buffer, length_size,
201 i = val_print_string (char_type, NULL,
202 addr + string_pos, string_length,
205 else if (pascal_object_is_vtbl_member (type))
207 /* Print vtbl's nicely. */
208 CORE_ADDR vt_address = unpack_pointer (type,
209 valaddr + embedded_offset);
210 struct minimal_symbol *msymbol =
211 lookup_minimal_symbol_by_pc (vt_address);
213 if ((msymbol != NULL)
214 && (vt_address == SYMBOL_VALUE_ADDRESS (msymbol)))
216 fputs_filtered (" <", stream);
217 fputs_filtered (SYMBOL_PRINT_NAME (msymbol), stream);
218 fputs_filtered (">", stream);
220 if (vt_address && options->vtblprint)
222 struct value *vt_val;
223 struct symbol *wsym = (struct symbol *) NULL;
225 struct block *block = (struct block *) NULL;
229 wsym = lookup_symbol (SYMBOL_LINKAGE_NAME (msymbol), block,
230 VAR_DOMAIN, &is_this_fld);
234 wtype = SYMBOL_TYPE (wsym);
238 wtype = TYPE_TARGET_TYPE (type);
240 vt_val = value_at (wtype, vt_address);
241 common_val_print (vt_val, stream, recurse + 1, options,
245 fprintf_filtered (stream, "\n");
246 print_spaces_filtered (2 + 2 * recurse, stream);
251 /* Return number of characters printed, including the terminating
252 '\0' if we reached the end. val_print_string takes care including
253 the terminating '\0' if necessary. */
259 elttype = check_typedef (TYPE_TARGET_TYPE (type));
260 if (options->addressprint)
263 = extract_typed_address (valaddr + embedded_offset, type);
265 fprintf_filtered (stream, "@");
266 fputs_filtered (paddress (gdbarch, addr), stream);
267 if (options->deref_ref)
268 fputs_filtered (": ", stream);
270 /* De-reference the reference. */
271 if (options->deref_ref)
273 if (TYPE_CODE (elttype) != TYPE_CODE_UNDEF)
275 struct value *deref_val;
277 deref_val = coerce_ref_if_computed (original_value);
278 if (deref_val != NULL)
280 /* More complicated computed references are not supported. */
281 gdb_assert (embedded_offset == 0);
284 deref_val = value_at (TYPE_TARGET_TYPE (type),
285 unpack_pointer (type,
287 + embedded_offset)));
289 common_val_print (deref_val, stream, recurse + 1, options,
293 fputs_filtered ("???", stream);
297 case TYPE_CODE_UNION:
298 if (recurse && !options->unionprint)
300 fprintf_filtered (stream, "{...}");
304 case TYPE_CODE_STRUCT:
305 if (options->vtblprint && pascal_object_is_vtbl_ptr_type (type))
307 /* Print the unmangled name if desired. */
308 /* Print vtable entry - we only get here if NOT using
309 -fvtable_thunks. (Otherwise, look under TYPE_CODE_PTR.) */
310 /* Extract the address, assume that it is unsigned. */
311 print_address_demangle
313 extract_unsigned_integer (valaddr + embedded_offset
314 + TYPE_FIELD_BITPOS (type,
315 VTBL_FNADDR_OFFSET) / 8,
316 TYPE_LENGTH (TYPE_FIELD_TYPE (type,
317 VTBL_FNADDR_OFFSET)),
323 if (is_pascal_string_type (type, &length_pos, &length_size,
324 &string_pos, &char_type, NULL))
326 len = extract_unsigned_integer (valaddr + embedded_offset
327 + length_pos, length_size,
329 LA_PRINT_STRING (stream, char_type,
330 valaddr + embedded_offset + string_pos,
331 len, NULL, 0, options);
334 pascal_object_print_value_fields (type, valaddr, embedded_offset,
335 address, stream, recurse,
336 original_value, options,
344 val_print_scalar_formatted (type, valaddr, embedded_offset,
345 original_value, options, 0, stream);
348 len = TYPE_NFIELDS (type);
349 val = unpack_long (type, valaddr + embedded_offset);
350 for (i = 0; i < len; i++)
353 if (val == TYPE_FIELD_BITPOS (type, i))
360 fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
364 print_longest (stream, 'd', 0, val);
368 case TYPE_CODE_FLAGS:
370 val_print_scalar_formatted (type, valaddr, embedded_offset,
371 original_value, options, 0, stream);
373 val_print_type_code_flags (type, valaddr + embedded_offset, stream);
379 val_print_scalar_formatted (type, valaddr, embedded_offset,
380 original_value, options, 0, stream);
383 /* FIXME, we should consider, at least for ANSI C language, eliminating
384 the distinction made between FUNCs and POINTERs to FUNCs. */
385 fprintf_filtered (stream, "{");
386 type_print (type, "", stream, -1);
387 fprintf_filtered (stream, "} ");
388 /* Try to print what function it points to, and its address. */
389 print_address_demangle (gdbarch, address, stream, demangle);
393 if (options->format || options->output_format)
395 struct value_print_options opts = *options;
397 opts.format = (options->format ? options->format
398 : options->output_format);
399 val_print_scalar_formatted (type, valaddr, embedded_offset,
400 original_value, &opts, 0, stream);
404 val = unpack_long (type, valaddr + embedded_offset);
406 fputs_filtered ("false", stream);
408 fputs_filtered ("true", stream);
411 fputs_filtered ("true (", stream);
412 fprintf_filtered (stream, "%ld)", (long int) val);
417 case TYPE_CODE_RANGE:
418 /* FIXME: create_range_type does not set the unsigned bit in a
419 range type (I think it probably should copy it from the target
420 type), so we won't print values which are too large to
421 fit in a signed integer correctly. */
422 /* FIXME: Doesn't handle ranges of enums correctly. (Can't just
423 print with the target type, though, because the size of our type
424 and the target type might differ). */
428 if (options->format || options->output_format)
430 struct value_print_options opts = *options;
432 opts.format = (options->format ? options->format
433 : options->output_format);
434 val_print_scalar_formatted (type, valaddr, embedded_offset,
435 original_value, &opts, 0, stream);
439 val_print_type_code_int (type, valaddr + embedded_offset, stream);
444 if (options->format || options->output_format)
446 struct value_print_options opts = *options;
448 opts.format = (options->format ? options->format
449 : options->output_format);
450 val_print_scalar_formatted (type, valaddr, embedded_offset,
451 original_value, &opts, 0, stream);
455 val = unpack_long (type, valaddr + embedded_offset);
456 if (TYPE_UNSIGNED (type))
457 fprintf_filtered (stream, "%u", (unsigned int) val);
459 fprintf_filtered (stream, "%d", (int) val);
460 fputs_filtered (" ", stream);
461 LA_PRINT_CHAR ((unsigned char) val, type, stream);
468 val_print_scalar_formatted (type, valaddr, embedded_offset,
469 original_value, options, 0, stream);
473 print_floating (valaddr + embedded_offset, type, stream);
477 case TYPE_CODE_BITSTRING:
479 elttype = TYPE_INDEX_TYPE (type);
480 CHECK_TYPEDEF (elttype);
481 if (TYPE_STUB (elttype))
483 fprintf_filtered (stream, "<incomplete type>");
489 struct type *range = elttype;
490 LONGEST low_bound, high_bound;
492 int is_bitstring = TYPE_CODE (type) == TYPE_CODE_BITSTRING;
496 fputs_filtered ("B'", stream);
498 fputs_filtered ("[", stream);
500 i = get_discrete_bounds (range, &low_bound, &high_bound);
501 if (low_bound == 0 && high_bound == -1 && TYPE_LENGTH (type) > 0)
503 /* If we know the size of the set type, we can figure out the
506 high_bound = TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1;
507 TYPE_HIGH_BOUND (range) = high_bound;
512 fputs_filtered ("<error value>", stream);
516 for (i = low_bound; i <= high_bound; i++)
518 int element = value_bit_index (type,
519 valaddr + embedded_offset, i);
524 goto maybe_bad_bstring;
527 fprintf_filtered (stream, "%d", element);
531 fputs_filtered (", ", stream);
532 print_type_scalar (range, i, stream);
535 if (i + 1 <= high_bound
536 && value_bit_index (type,
537 valaddr + embedded_offset, ++i))
541 fputs_filtered ("..", stream);
542 while (i + 1 <= high_bound
543 && value_bit_index (type,
544 valaddr + embedded_offset,
547 print_type_scalar (range, j, stream);
553 fputs_filtered ("'", stream);
555 fputs_filtered ("]", stream);
560 fprintf_filtered (stream, "void");
563 case TYPE_CODE_ERROR:
564 fprintf_filtered (stream, "%s", TYPE_ERROR_NAME (type));
567 case TYPE_CODE_UNDEF:
568 /* This happens (without TYPE_FLAG_STUB set) on systems which don't use
569 dbx xrefs (NO_DBX_XREFS in gcc) if a file has a "struct foo *bar"
570 and no complete type for struct foo in that file. */
571 fprintf_filtered (stream, "<incomplete type>");
575 error (_("Invalid pascal type code %d in symbol table."),
583 pascal_value_print (struct value *val, struct ui_file *stream,
584 const struct value_print_options *options)
586 struct type *type = value_type (val);
587 struct value_print_options opts = *options;
591 /* If it is a pointer, indicate what it points to.
593 Print type also if it is a reference.
595 Object pascal: if it is a member pointer, we will take care
596 of that when we print it. */
597 if (TYPE_CODE (type) == TYPE_CODE_PTR
598 || TYPE_CODE (type) == TYPE_CODE_REF)
600 /* Hack: remove (char *) for char strings. Their
601 type is indicated by the quoted string anyway. */
602 if (TYPE_CODE (type) == TYPE_CODE_PTR
603 && TYPE_NAME (type) == NULL
604 && TYPE_NAME (TYPE_TARGET_TYPE (type)) != NULL
605 && strcmp (TYPE_NAME (TYPE_TARGET_TYPE (type)), "char") == 0)
611 fprintf_filtered (stream, "(");
612 type_print (type, "", stream, -1);
613 fprintf_filtered (stream, ") ");
616 return common_val_print (val, stream, 0, &opts, current_language);
621 show_pascal_static_field_print (struct ui_file *file, int from_tty,
622 struct cmd_list_element *c, const char *value)
624 fprintf_filtered (file, _("Printing of pascal static members is %s.\n"),
628 static struct obstack dont_print_vb_obstack;
629 static struct obstack dont_print_statmem_obstack;
631 static void pascal_object_print_static_field (struct value *,
632 struct ui_file *, int,
633 const struct value_print_options *);
635 static void pascal_object_print_value (struct type *, const gdb_byte *,
637 CORE_ADDR, struct ui_file *, int,
638 const struct value *,
639 const struct value_print_options *,
642 /* It was changed to this after 2.4.5. */
643 const char pascal_vtbl_ptr_name[] =
644 {'_', '_', 'v', 't', 'b', 'l', '_', 'p', 't', 'r', '_', 't', 'y', 'p', 'e', 0};
646 /* Return truth value for assertion that TYPE is of the type
647 "pointer to virtual function". */
650 pascal_object_is_vtbl_ptr_type (struct type *type)
652 char *typename = type_name_no_tag (type);
654 return (typename != NULL
655 && strcmp (typename, pascal_vtbl_ptr_name) == 0);
658 /* Return truth value for the assertion that TYPE is of the type
659 "pointer to virtual function table". */
662 pascal_object_is_vtbl_member (struct type *type)
664 if (TYPE_CODE (type) == TYPE_CODE_PTR)
666 type = TYPE_TARGET_TYPE (type);
667 if (TYPE_CODE (type) == TYPE_CODE_ARRAY)
669 type = TYPE_TARGET_TYPE (type);
670 if (TYPE_CODE (type) == TYPE_CODE_STRUCT /* If not using
672 || TYPE_CODE (type) == TYPE_CODE_PTR) /* If using thunks. */
674 /* Virtual functions tables are full of pointers
675 to virtual functions. */
676 return pascal_object_is_vtbl_ptr_type (type);
683 /* Mutually recursive subroutines of pascal_object_print_value and
684 c_val_print to print out a structure's fields:
685 pascal_object_print_value_fields and pascal_object_print_value.
687 TYPE, VALADDR, ADDRESS, STREAM, RECURSE, and OPTIONS have the
688 same meanings as in pascal_object_print_value and c_val_print.
690 DONT_PRINT is an array of baseclass types that we
691 should not print, or zero if called from top level. */
694 pascal_object_print_value_fields (struct type *type, const gdb_byte *valaddr,
696 CORE_ADDR address, struct ui_file *stream,
698 const struct value *val,
699 const struct value_print_options *options,
700 struct type **dont_print_vb,
701 int dont_print_statmem)
703 int i, len, n_baseclasses;
704 char *last_dont_print = obstack_next_free (&dont_print_statmem_obstack);
706 CHECK_TYPEDEF (type);
708 fprintf_filtered (stream, "{");
709 len = TYPE_NFIELDS (type);
710 n_baseclasses = TYPE_N_BASECLASSES (type);
712 /* Print out baseclasses such that we don't print
713 duplicates of virtual baseclasses. */
714 if (n_baseclasses > 0)
715 pascal_object_print_value (type, valaddr, offset, address,
716 stream, recurse + 1, val,
717 options, dont_print_vb);
719 if (!len && n_baseclasses == 1)
720 fprintf_filtered (stream, "<No data fields>");
723 struct obstack tmp_obstack = dont_print_statmem_obstack;
726 if (dont_print_statmem == 0)
728 /* If we're at top level, carve out a completely fresh
729 chunk of the obstack and use that until this particular
730 invocation returns. */
731 obstack_finish (&dont_print_statmem_obstack);
734 for (i = n_baseclasses; i < len; i++)
736 /* If requested, skip printing of static fields. */
737 if (!options->pascal_static_field_print
738 && field_is_static (&TYPE_FIELD (type, i)))
741 fprintf_filtered (stream, ", ");
742 else if (n_baseclasses > 0)
746 fprintf_filtered (stream, "\n");
747 print_spaces_filtered (2 + 2 * recurse, stream);
748 fputs_filtered ("members of ", stream);
749 fputs_filtered (type_name_no_tag (type), stream);
750 fputs_filtered (": ", stream);
757 fprintf_filtered (stream, "\n");
758 print_spaces_filtered (2 + 2 * recurse, stream);
762 wrap_here (n_spaces (2 + 2 * recurse));
764 if (options->inspect_it)
766 if (TYPE_CODE (TYPE_FIELD_TYPE (type, i)) == TYPE_CODE_PTR)
767 fputs_filtered ("\"( ptr \"", stream);
769 fputs_filtered ("\"( nodef \"", stream);
770 if (field_is_static (&TYPE_FIELD (type, i)))
771 fputs_filtered ("static ", stream);
772 fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i),
774 DMGL_PARAMS | DMGL_ANSI);
775 fputs_filtered ("\" \"", stream);
776 fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i),
778 DMGL_PARAMS | DMGL_ANSI);
779 fputs_filtered ("\") \"", stream);
783 annotate_field_begin (TYPE_FIELD_TYPE (type, i));
785 if (field_is_static (&TYPE_FIELD (type, i)))
786 fputs_filtered ("static ", stream);
787 fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i),
789 DMGL_PARAMS | DMGL_ANSI);
790 annotate_field_name_end ();
791 fputs_filtered (" = ", stream);
792 annotate_field_value ();
795 if (!field_is_static (&TYPE_FIELD (type, i))
796 && TYPE_FIELD_PACKED (type, i))
800 /* Bitfields require special handling, especially due to byte
802 if (TYPE_FIELD_IGNORE (type, i))
804 fputs_filtered ("<optimized out or zero length>", stream);
806 else if (value_bits_synthetic_pointer (val,
807 TYPE_FIELD_BITPOS (type,
809 TYPE_FIELD_BITSIZE (type,
812 fputs_filtered (_("<synthetic pointer>"), stream);
814 else if (!value_bits_valid (val, TYPE_FIELD_BITPOS (type, i),
815 TYPE_FIELD_BITSIZE (type, i)))
817 val_print_optimized_out (stream);
821 struct value_print_options opts = *options;
823 v = value_field_bitfield (type, i, valaddr, offset, val);
826 common_val_print (v, stream, recurse + 1, &opts,
832 if (TYPE_FIELD_IGNORE (type, i))
834 fputs_filtered ("<optimized out or zero length>", stream);
836 else if (field_is_static (&TYPE_FIELD (type, i)))
838 /* struct value *v = value_static_field (type, i);
842 v = value_field_bitfield (type, i, valaddr, offset, val);
845 val_print_optimized_out (stream);
847 pascal_object_print_static_field (v, stream, recurse + 1,
852 struct value_print_options opts = *options;
855 /* val_print (TYPE_FIELD_TYPE (type, i),
856 valaddr + TYPE_FIELD_BITPOS (type, i) / 8,
857 address + TYPE_FIELD_BITPOS (type, i) / 8, 0,
858 stream, format, 0, recurse + 1, pretty); */
859 val_print (TYPE_FIELD_TYPE (type, i),
860 valaddr, offset + TYPE_FIELD_BITPOS (type, i) / 8,
861 address, stream, recurse + 1, val, &opts,
865 annotate_field_end ();
868 if (dont_print_statmem == 0)
870 /* Free the space used to deal with the printing
871 of the members from top level. */
872 obstack_free (&dont_print_statmem_obstack, last_dont_print);
873 dont_print_statmem_obstack = tmp_obstack;
878 fprintf_filtered (stream, "\n");
879 print_spaces_filtered (2 * recurse, stream);
882 fprintf_filtered (stream, "}");
885 /* Special val_print routine to avoid printing multiple copies of virtual
889 pascal_object_print_value (struct type *type, const gdb_byte *valaddr,
891 CORE_ADDR address, struct ui_file *stream,
893 const struct value *val,
894 const struct value_print_options *options,
895 struct type **dont_print_vb)
897 struct type **last_dont_print
898 = (struct type **) obstack_next_free (&dont_print_vb_obstack);
899 struct obstack tmp_obstack = dont_print_vb_obstack;
900 int i, n_baseclasses = TYPE_N_BASECLASSES (type);
902 if (dont_print_vb == 0)
904 /* If we're at top level, carve out a completely fresh
905 chunk of the obstack and use that until this particular
906 invocation returns. */
907 /* Bump up the high-water mark. Now alpha is omega. */
908 obstack_finish (&dont_print_vb_obstack);
911 for (i = 0; i < n_baseclasses; i++)
914 struct type *baseclass = check_typedef (TYPE_BASECLASS (type, i));
915 char *basename = type_name_no_tag (baseclass);
916 const gdb_byte *base_valaddr = NULL;
918 volatile struct gdb_exception ex;
921 if (BASETYPE_VIA_VIRTUAL (type, i))
923 struct type **first_dont_print
924 = (struct type **) obstack_base (&dont_print_vb_obstack);
926 int j = (struct type **) obstack_next_free (&dont_print_vb_obstack)
930 if (baseclass == first_dont_print[j])
933 obstack_ptr_grow (&dont_print_vb_obstack, baseclass);
938 TRY_CATCH (ex, RETURN_MASK_ERROR)
940 boffset = baseclass_offset (type, i, valaddr, offset, address, val);
942 if (ex.reason < 0 && ex.error == NOT_AVAILABLE_ERROR)
944 else if (ex.reason < 0)
950 /* The virtual base class pointer might have been clobbered by the
951 user program. Make sure that it still points to a valid memory
954 if (boffset < 0 || boffset >= TYPE_LENGTH (type))
956 /* FIXME (alloc): not safe is baseclass is really really big. */
957 gdb_byte *buf = alloca (TYPE_LENGTH (baseclass));
960 if (target_read_memory (address + boffset, buf,
961 TYPE_LENGTH (baseclass)) != 0)
963 address = address + boffset;
968 base_valaddr = valaddr;
973 fprintf_filtered (stream, "\n");
974 print_spaces_filtered (2 * recurse, stream);
976 fputs_filtered ("<", stream);
977 /* Not sure what the best notation is in the case where there is no
980 fputs_filtered (basename ? basename : "", stream);
981 fputs_filtered ("> = ", stream);
984 val_print_unavailable (stream);
986 val_print_invalid_address (stream);
988 pascal_object_print_value_fields (baseclass, base_valaddr,
989 thisoffset + boffset, address,
990 stream, recurse, val, options,
991 (struct type **) obstack_base (&dont_print_vb_obstack),
993 fputs_filtered (", ", stream);
999 if (dont_print_vb == 0)
1001 /* Free the space used to deal with the printing
1002 of this type from top level. */
1003 obstack_free (&dont_print_vb_obstack, last_dont_print);
1004 /* Reset watermark so that we can continue protecting
1005 ourselves from whatever we were protecting ourselves. */
1006 dont_print_vb_obstack = tmp_obstack;
1010 /* Print value of a static member.
1011 To avoid infinite recursion when printing a class that contains
1012 a static instance of the class, we keep the addresses of all printed
1013 static member classes in an obstack and refuse to print them more
1016 VAL contains the value to print, STREAM, RECURSE, and OPTIONS
1017 have the same meanings as in c_val_print. */
1020 pascal_object_print_static_field (struct value *val,
1021 struct ui_file *stream,
1023 const struct value_print_options *options)
1025 struct type *type = value_type (val);
1026 struct value_print_options opts;
1028 if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
1030 CORE_ADDR *first_dont_print, addr;
1034 = (CORE_ADDR *) obstack_base (&dont_print_statmem_obstack);
1035 i = (CORE_ADDR *) obstack_next_free (&dont_print_statmem_obstack)
1040 if (value_address (val) == first_dont_print[i])
1043 <same as static member of an already seen type>",
1049 addr = value_address (val);
1050 obstack_grow (&dont_print_statmem_obstack, (char *) &addr,
1051 sizeof (CORE_ADDR));
1053 CHECK_TYPEDEF (type);
1054 pascal_object_print_value_fields (type,
1055 value_contents_for_printing (val),
1056 value_embedded_offset (val),
1059 val, options, NULL, 1);
1065 common_val_print (val, stream, recurse, &opts, current_language);
1068 /* -Wmissing-prototypes */
1069 extern initialize_file_ftype _initialize_pascal_valprint;
1072 _initialize_pascal_valprint (void)
1074 add_setshow_boolean_cmd ("pascal_static-members", class_support,
1075 &user_print_options.pascal_static_field_print, _("\
1076 Set printing of pascal static members."), _("\
1077 Show printing of pascal static members."), NULL,
1079 show_pascal_static_field_print,
1080 &setprintlist, &showprintlist);