1 /* Support for printing Pascal values for GDB, the GNU debugger.
3 Copyright (C) 2000-2001, 2003, 2005-2012 Free Software Foundation,
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. */
48 pascal_val_print (struct type *type, const gdb_byte *valaddr,
49 int embedded_offset, CORE_ADDR address,
50 struct ui_file *stream, int recurse,
51 const struct value *original_value,
52 const struct value_print_options *options)
54 struct gdbarch *gdbarch = get_type_arch (type);
55 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
56 unsigned int i = 0; /* Number of characters printed */
58 LONGEST low_bound, high_bound;
61 int length_pos, length_size, string_pos;
62 struct type *char_type;
67 switch (TYPE_CODE (type))
70 if (get_array_bounds (type, &low_bound, &high_bound))
72 len = high_bound - low_bound + 1;
73 elttype = check_typedef (TYPE_TARGET_TYPE (type));
74 eltlen = TYPE_LENGTH (elttype);
75 if (options->prettyprint_arrays)
77 print_spaces_filtered (2 + 2 * recurse, stream);
79 /* If 's' format is used, try to print out as string.
80 If no format is given, print as string if element type
81 is of TYPE_CODE_CHAR and element size is 1,2 or 4. */
82 if (options->format == 's'
83 || ((eltlen == 1 || eltlen == 2 || eltlen == 4)
84 && TYPE_CODE (elttype) == TYPE_CODE_CHAR
85 && options->format == 0))
87 /* If requested, look for the first null char and only print
89 if (options->stop_print_at_null)
91 unsigned int temp_len;
93 /* Look for a NULL char. */
95 extract_unsigned_integer (valaddr + embedded_offset +
96 temp_len * eltlen, eltlen,
98 && temp_len < len && temp_len < options->print_max;
103 LA_PRINT_STRING (stream, TYPE_TARGET_TYPE (type),
104 valaddr + embedded_offset, len, NULL, 0,
110 fprintf_filtered (stream, "{");
111 /* If this is a virtual function table, print the 0th
112 entry specially, and the rest of the members normally. */
113 if (pascal_object_is_vtbl_ptr_type (elttype))
116 fprintf_filtered (stream, "%d vtable entries", len - 1);
122 val_print_array_elements (type, valaddr, embedded_offset,
123 address, stream, recurse,
124 original_value, options, i);
125 fprintf_filtered (stream, "}");
129 /* Array of unspecified length: treat like pointer to first elt. */
130 addr = address + embedded_offset;
131 goto print_unpacked_pointer;
134 if (options->format && options->format != 's')
136 val_print_scalar_formatted (type, valaddr, embedded_offset,
137 original_value, options, 0, stream);
140 if (options->vtblprint && pascal_object_is_vtbl_ptr_type (type))
142 /* Print the unmangled name if desired. */
143 /* Print vtable entry - we only get here if we ARE using
144 -fvtable_thunks. (Otherwise, look under TYPE_CODE_STRUCT.) */
145 /* Extract the address, assume that it is unsigned. */
146 addr = extract_unsigned_integer (valaddr + embedded_offset,
147 TYPE_LENGTH (type), byte_order);
148 print_address_demangle (gdbarch, addr, stream, demangle);
151 check_typedef (TYPE_TARGET_TYPE (type));
153 addr = unpack_pointer (type, valaddr + embedded_offset);
154 print_unpacked_pointer:
155 elttype = check_typedef (TYPE_TARGET_TYPE (type));
157 if (TYPE_CODE (elttype) == TYPE_CODE_FUNC)
159 /* Try to print what function it points to. */
160 print_address_demangle (gdbarch, addr, stream, demangle);
164 if (options->addressprint && options->format != 's')
166 fputs_filtered (paddress (gdbarch, addr), stream);
169 /* For a pointer to char or unsigned char, also print the string
170 pointed to, unless pointer is null. */
171 if (((TYPE_LENGTH (elttype) == 1
172 && (TYPE_CODE (elttype) == TYPE_CODE_INT
173 || TYPE_CODE (elttype) == TYPE_CODE_CHAR))
174 || ((TYPE_LENGTH (elttype) == 2 || TYPE_LENGTH (elttype) == 4)
175 && TYPE_CODE (elttype) == TYPE_CODE_CHAR))
176 && (options->format == 0 || options->format == 's')
179 /* No wide string yet. */
180 i = val_print_string (elttype, NULL, addr, -1, stream, options);
182 /* Also for pointers to pascal strings. */
183 /* Note: this is Free Pascal specific:
184 as GDB does not recognize stabs pascal strings
185 Pascal strings are mapped to records
186 with lowercase names PM. */
187 if (is_pascal_string_type (elttype, &length_pos, &length_size,
188 &string_pos, &char_type, NULL)
191 ULONGEST string_length;
194 buffer = xmalloc (length_size);
195 read_memory (addr + length_pos, buffer, length_size);
196 string_length = extract_unsigned_integer (buffer, length_size,
199 i = val_print_string (char_type, NULL,
200 addr + string_pos, string_length,
203 else if (pascal_object_is_vtbl_member (type))
205 /* Print vtbl's nicely. */
206 CORE_ADDR vt_address = unpack_pointer (type,
207 valaddr + embedded_offset);
208 struct minimal_symbol *msymbol =
209 lookup_minimal_symbol_by_pc (vt_address);
211 if ((msymbol != NULL)
212 && (vt_address == SYMBOL_VALUE_ADDRESS (msymbol)))
214 fputs_filtered (" <", stream);
215 fputs_filtered (SYMBOL_PRINT_NAME (msymbol), stream);
216 fputs_filtered (">", stream);
218 if (vt_address && options->vtblprint)
220 struct value *vt_val;
221 struct symbol *wsym = (struct symbol *) NULL;
223 struct block *block = (struct block *) NULL;
227 wsym = lookup_symbol (SYMBOL_LINKAGE_NAME (msymbol), block,
228 VAR_DOMAIN, &is_this_fld);
232 wtype = SYMBOL_TYPE (wsym);
236 wtype = TYPE_TARGET_TYPE (type);
238 vt_val = value_at (wtype, vt_address);
239 common_val_print (vt_val, stream, recurse + 1, options,
243 fprintf_filtered (stream, "\n");
244 print_spaces_filtered (2 + 2 * recurse, stream);
252 elttype = check_typedef (TYPE_TARGET_TYPE (type));
253 if (options->addressprint)
256 = extract_typed_address (valaddr + embedded_offset, type);
258 fprintf_filtered (stream, "@");
259 fputs_filtered (paddress (gdbarch, addr), stream);
260 if (options->deref_ref)
261 fputs_filtered (": ", stream);
263 /* De-reference the reference. */
264 if (options->deref_ref)
266 if (TYPE_CODE (elttype) != TYPE_CODE_UNDEF)
268 struct value *deref_val;
270 deref_val = coerce_ref_if_computed (original_value);
271 if (deref_val != NULL)
273 /* More complicated computed references are not supported. */
274 gdb_assert (embedded_offset == 0);
277 deref_val = value_at (TYPE_TARGET_TYPE (type),
278 unpack_pointer (type,
280 + embedded_offset)));
282 common_val_print (deref_val, stream, recurse + 1, options,
286 fputs_filtered ("???", stream);
290 case TYPE_CODE_UNION:
291 if (recurse && !options->unionprint)
293 fprintf_filtered (stream, "{...}");
297 case TYPE_CODE_STRUCT:
298 if (options->vtblprint && pascal_object_is_vtbl_ptr_type (type))
300 /* Print the unmangled name if desired. */
301 /* Print vtable entry - we only get here if NOT using
302 -fvtable_thunks. (Otherwise, look under TYPE_CODE_PTR.) */
303 /* Extract the address, assume that it is unsigned. */
304 print_address_demangle
306 extract_unsigned_integer (valaddr + embedded_offset
307 + TYPE_FIELD_BITPOS (type,
308 VTBL_FNADDR_OFFSET) / 8,
309 TYPE_LENGTH (TYPE_FIELD_TYPE (type,
310 VTBL_FNADDR_OFFSET)),
316 if (is_pascal_string_type (type, &length_pos, &length_size,
317 &string_pos, &char_type, NULL))
319 len = extract_unsigned_integer (valaddr + embedded_offset
320 + length_pos, length_size,
322 LA_PRINT_STRING (stream, char_type,
323 valaddr + embedded_offset + string_pos,
324 len, NULL, 0, options);
327 pascal_object_print_value_fields (type, valaddr, embedded_offset,
328 address, stream, recurse,
329 original_value, options,
337 val_print_scalar_formatted (type, valaddr, embedded_offset,
338 original_value, options, 0, stream);
341 len = TYPE_NFIELDS (type);
342 val = unpack_long (type, valaddr + embedded_offset);
343 for (i = 0; i < len; i++)
346 if (val == TYPE_FIELD_BITPOS (type, i))
353 fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
357 print_longest (stream, 'd', 0, val);
361 case TYPE_CODE_FLAGS:
363 val_print_scalar_formatted (type, valaddr, embedded_offset,
364 original_value, options, 0, stream);
366 val_print_type_code_flags (type, valaddr + embedded_offset, stream);
372 val_print_scalar_formatted (type, valaddr, embedded_offset,
373 original_value, options, 0, stream);
376 /* FIXME, we should consider, at least for ANSI C language, eliminating
377 the distinction made between FUNCs and POINTERs to FUNCs. */
378 fprintf_filtered (stream, "{");
379 type_print (type, "", stream, -1);
380 fprintf_filtered (stream, "} ");
381 /* Try to print what function it points to, and its address. */
382 print_address_demangle (gdbarch, address, stream, demangle);
386 if (options->format || options->output_format)
388 struct value_print_options opts = *options;
390 opts.format = (options->format ? options->format
391 : options->output_format);
392 val_print_scalar_formatted (type, valaddr, embedded_offset,
393 original_value, &opts, 0, stream);
397 val = unpack_long (type, valaddr + embedded_offset);
399 fputs_filtered ("false", stream);
401 fputs_filtered ("true", stream);
404 fputs_filtered ("true (", stream);
405 fprintf_filtered (stream, "%ld)", (long int) val);
410 case TYPE_CODE_RANGE:
411 /* FIXME: create_range_type does not set the unsigned bit in a
412 range type (I think it probably should copy it from the target
413 type), so we won't print values which are too large to
414 fit in a signed integer correctly. */
415 /* FIXME: Doesn't handle ranges of enums correctly. (Can't just
416 print with the target type, though, because the size of our type
417 and the target type might differ). */
421 if (options->format || options->output_format)
423 struct value_print_options opts = *options;
425 opts.format = (options->format ? options->format
426 : options->output_format);
427 val_print_scalar_formatted (type, valaddr, embedded_offset,
428 original_value, &opts, 0, stream);
432 val_print_type_code_int (type, valaddr + embedded_offset, stream);
437 if (options->format || options->output_format)
439 struct value_print_options opts = *options;
441 opts.format = (options->format ? options->format
442 : options->output_format);
443 val_print_scalar_formatted (type, valaddr, embedded_offset,
444 original_value, &opts, 0, stream);
448 val = unpack_long (type, valaddr + embedded_offset);
449 if (TYPE_UNSIGNED (type))
450 fprintf_filtered (stream, "%u", (unsigned int) val);
452 fprintf_filtered (stream, "%d", (int) val);
453 fputs_filtered (" ", stream);
454 LA_PRINT_CHAR ((unsigned char) val, type, stream);
461 val_print_scalar_formatted (type, valaddr, embedded_offset,
462 original_value, options, 0, stream);
466 print_floating (valaddr + embedded_offset, type, stream);
470 case TYPE_CODE_BITSTRING:
472 elttype = TYPE_INDEX_TYPE (type);
473 CHECK_TYPEDEF (elttype);
474 if (TYPE_STUB (elttype))
476 fprintf_filtered (stream, "<incomplete type>");
482 struct type *range = elttype;
483 LONGEST low_bound, high_bound;
485 int is_bitstring = TYPE_CODE (type) == TYPE_CODE_BITSTRING;
489 fputs_filtered ("B'", stream);
491 fputs_filtered ("[", stream);
493 i = get_discrete_bounds (range, &low_bound, &high_bound);
494 if (low_bound == 0 && high_bound == -1 && TYPE_LENGTH (type) > 0)
496 /* If we know the size of the set type, we can figure out the
499 high_bound = TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1;
500 TYPE_HIGH_BOUND (range) = high_bound;
505 fputs_filtered ("<error value>", stream);
509 for (i = low_bound; i <= high_bound; i++)
511 int element = value_bit_index (type,
512 valaddr + embedded_offset, i);
517 goto maybe_bad_bstring;
520 fprintf_filtered (stream, "%d", element);
524 fputs_filtered (", ", stream);
525 print_type_scalar (range, i, stream);
528 if (i + 1 <= high_bound
529 && value_bit_index (type,
530 valaddr + embedded_offset, ++i))
534 fputs_filtered ("..", stream);
535 while (i + 1 <= high_bound
536 && value_bit_index (type,
537 valaddr + embedded_offset,
540 print_type_scalar (range, j, stream);
546 fputs_filtered ("'", stream);
548 fputs_filtered ("]", stream);
553 fprintf_filtered (stream, "void");
556 case TYPE_CODE_ERROR:
557 fprintf_filtered (stream, "%s", TYPE_ERROR_NAME (type));
560 case TYPE_CODE_UNDEF:
561 /* This happens (without TYPE_FLAG_STUB set) on systems which don't use
562 dbx xrefs (NO_DBX_XREFS in gcc) if a file has a "struct foo *bar"
563 and no complete type for struct foo in that file. */
564 fprintf_filtered (stream, "<incomplete type>");
568 error (_("Invalid pascal type code %d in symbol table."),
575 pascal_value_print (struct value *val, struct ui_file *stream,
576 const struct value_print_options *options)
578 struct type *type = value_type (val);
579 struct value_print_options opts = *options;
583 /* If it is a pointer, indicate what it points to.
585 Print type also if it is a reference.
587 Object pascal: if it is a member pointer, we will take care
588 of that when we print it. */
589 if (TYPE_CODE (type) == TYPE_CODE_PTR
590 || TYPE_CODE (type) == TYPE_CODE_REF)
592 /* Hack: remove (char *) for char strings. Their
593 type is indicated by the quoted string anyway. */
594 if (TYPE_CODE (type) == TYPE_CODE_PTR
595 && TYPE_NAME (type) == NULL
596 && TYPE_NAME (TYPE_TARGET_TYPE (type)) != NULL
597 && strcmp (TYPE_NAME (TYPE_TARGET_TYPE (type)), "char") == 0)
603 fprintf_filtered (stream, "(");
604 type_print (type, "", stream, -1);
605 fprintf_filtered (stream, ") ");
608 common_val_print (val, stream, 0, &opts, current_language);
613 show_pascal_static_field_print (struct ui_file *file, int from_tty,
614 struct cmd_list_element *c, const char *value)
616 fprintf_filtered (file, _("Printing of pascal static members is %s.\n"),
620 static struct obstack dont_print_vb_obstack;
621 static struct obstack dont_print_statmem_obstack;
623 static void pascal_object_print_static_field (struct value *,
624 struct ui_file *, int,
625 const struct value_print_options *);
627 static void pascal_object_print_value (struct type *, const gdb_byte *,
629 CORE_ADDR, struct ui_file *, int,
630 const struct value *,
631 const struct value_print_options *,
634 /* It was changed to this after 2.4.5. */
635 const char pascal_vtbl_ptr_name[] =
636 {'_', '_', 'v', 't', 'b', 'l', '_', 'p', 't', 'r', '_', 't', 'y', 'p', 'e', 0};
638 /* Return truth value for assertion that TYPE is of the type
639 "pointer to virtual function". */
642 pascal_object_is_vtbl_ptr_type (struct type *type)
644 const char *typename = type_name_no_tag (type);
646 return (typename != NULL
647 && strcmp (typename, pascal_vtbl_ptr_name) == 0);
650 /* Return truth value for the assertion that TYPE is of the type
651 "pointer to virtual function table". */
654 pascal_object_is_vtbl_member (struct type *type)
656 if (TYPE_CODE (type) == TYPE_CODE_PTR)
658 type = TYPE_TARGET_TYPE (type);
659 if (TYPE_CODE (type) == TYPE_CODE_ARRAY)
661 type = TYPE_TARGET_TYPE (type);
662 if (TYPE_CODE (type) == TYPE_CODE_STRUCT /* If not using
664 || TYPE_CODE (type) == TYPE_CODE_PTR) /* If using thunks. */
666 /* Virtual functions tables are full of pointers
667 to virtual functions. */
668 return pascal_object_is_vtbl_ptr_type (type);
675 /* Mutually recursive subroutines of pascal_object_print_value and
676 c_val_print to print out a structure's fields:
677 pascal_object_print_value_fields and pascal_object_print_value.
679 TYPE, VALADDR, ADDRESS, STREAM, RECURSE, and OPTIONS have the
680 same meanings as in pascal_object_print_value and c_val_print.
682 DONT_PRINT is an array of baseclass types that we
683 should not print, or zero if called from top level. */
686 pascal_object_print_value_fields (struct type *type, const gdb_byte *valaddr,
688 CORE_ADDR address, struct ui_file *stream,
690 const struct value *val,
691 const struct value_print_options *options,
692 struct type **dont_print_vb,
693 int dont_print_statmem)
695 int i, len, n_baseclasses;
696 char *last_dont_print = obstack_next_free (&dont_print_statmem_obstack);
698 CHECK_TYPEDEF (type);
700 fprintf_filtered (stream, "{");
701 len = TYPE_NFIELDS (type);
702 n_baseclasses = TYPE_N_BASECLASSES (type);
704 /* Print out baseclasses such that we don't print
705 duplicates of virtual baseclasses. */
706 if (n_baseclasses > 0)
707 pascal_object_print_value (type, valaddr, offset, address,
708 stream, recurse + 1, val,
709 options, dont_print_vb);
711 if (!len && n_baseclasses == 1)
712 fprintf_filtered (stream, "<No data fields>");
715 struct obstack tmp_obstack = dont_print_statmem_obstack;
718 if (dont_print_statmem == 0)
720 /* If we're at top level, carve out a completely fresh
721 chunk of the obstack and use that until this particular
722 invocation returns. */
723 obstack_finish (&dont_print_statmem_obstack);
726 for (i = n_baseclasses; i < len; i++)
728 /* If requested, skip printing of static fields. */
729 if (!options->pascal_static_field_print
730 && field_is_static (&TYPE_FIELD (type, i)))
733 fprintf_filtered (stream, ", ");
734 else if (n_baseclasses > 0)
738 fprintf_filtered (stream, "\n");
739 print_spaces_filtered (2 + 2 * recurse, stream);
740 fputs_filtered ("members of ", stream);
741 fputs_filtered (type_name_no_tag (type), stream);
742 fputs_filtered (": ", stream);
749 fprintf_filtered (stream, "\n");
750 print_spaces_filtered (2 + 2 * recurse, stream);
754 wrap_here (n_spaces (2 + 2 * recurse));
756 if (options->inspect_it)
758 if (TYPE_CODE (TYPE_FIELD_TYPE (type, i)) == TYPE_CODE_PTR)
759 fputs_filtered ("\"( ptr \"", stream);
761 fputs_filtered ("\"( nodef \"", stream);
762 if (field_is_static (&TYPE_FIELD (type, i)))
763 fputs_filtered ("static ", stream);
764 fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i),
766 DMGL_PARAMS | DMGL_ANSI);
767 fputs_filtered ("\" \"", stream);
768 fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i),
770 DMGL_PARAMS | DMGL_ANSI);
771 fputs_filtered ("\") \"", stream);
775 annotate_field_begin (TYPE_FIELD_TYPE (type, i));
777 if (field_is_static (&TYPE_FIELD (type, i)))
778 fputs_filtered ("static ", stream);
779 fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i),
781 DMGL_PARAMS | DMGL_ANSI);
782 annotate_field_name_end ();
783 fputs_filtered (" = ", stream);
784 annotate_field_value ();
787 if (!field_is_static (&TYPE_FIELD (type, i))
788 && TYPE_FIELD_PACKED (type, i))
792 /* Bitfields require special handling, especially due to byte
794 if (TYPE_FIELD_IGNORE (type, i))
796 fputs_filtered ("<optimized out or zero length>", stream);
798 else if (value_bits_synthetic_pointer (val,
799 TYPE_FIELD_BITPOS (type,
801 TYPE_FIELD_BITSIZE (type,
804 fputs_filtered (_("<synthetic pointer>"), stream);
806 else if (!value_bits_valid (val, TYPE_FIELD_BITPOS (type, i),
807 TYPE_FIELD_BITSIZE (type, i)))
809 val_print_optimized_out (stream);
813 struct value_print_options opts = *options;
815 v = value_field_bitfield (type, i, valaddr, offset, val);
818 common_val_print (v, stream, recurse + 1, &opts,
824 if (TYPE_FIELD_IGNORE (type, i))
826 fputs_filtered ("<optimized out or zero length>", stream);
828 else if (field_is_static (&TYPE_FIELD (type, i)))
830 /* struct value *v = value_static_field (type, i);
834 v = value_field_bitfield (type, i, valaddr, offset, val);
837 val_print_optimized_out (stream);
839 pascal_object_print_static_field (v, stream, recurse + 1,
844 struct value_print_options opts = *options;
847 /* val_print (TYPE_FIELD_TYPE (type, i),
848 valaddr + TYPE_FIELD_BITPOS (type, i) / 8,
849 address + TYPE_FIELD_BITPOS (type, i) / 8, 0,
850 stream, format, 0, recurse + 1, pretty); */
851 val_print (TYPE_FIELD_TYPE (type, i),
852 valaddr, offset + TYPE_FIELD_BITPOS (type, i) / 8,
853 address, stream, recurse + 1, val, &opts,
857 annotate_field_end ();
860 if (dont_print_statmem == 0)
862 /* Free the space used to deal with the printing
863 of the members from top level. */
864 obstack_free (&dont_print_statmem_obstack, last_dont_print);
865 dont_print_statmem_obstack = tmp_obstack;
870 fprintf_filtered (stream, "\n");
871 print_spaces_filtered (2 * recurse, stream);
874 fprintf_filtered (stream, "}");
877 /* Special val_print routine to avoid printing multiple copies of virtual
881 pascal_object_print_value (struct type *type, const gdb_byte *valaddr,
883 CORE_ADDR address, struct ui_file *stream,
885 const struct value *val,
886 const struct value_print_options *options,
887 struct type **dont_print_vb)
889 struct type **last_dont_print
890 = (struct type **) obstack_next_free (&dont_print_vb_obstack);
891 struct obstack tmp_obstack = dont_print_vb_obstack;
892 int i, n_baseclasses = TYPE_N_BASECLASSES (type);
894 if (dont_print_vb == 0)
896 /* If we're at top level, carve out a completely fresh
897 chunk of the obstack and use that until this particular
898 invocation returns. */
899 /* Bump up the high-water mark. Now alpha is omega. */
900 obstack_finish (&dont_print_vb_obstack);
903 for (i = 0; i < n_baseclasses; i++)
906 struct type *baseclass = check_typedef (TYPE_BASECLASS (type, i));
907 const char *basename = type_name_no_tag (baseclass);
908 const gdb_byte *base_valaddr = NULL;
910 volatile struct gdb_exception ex;
913 if (BASETYPE_VIA_VIRTUAL (type, i))
915 struct type **first_dont_print
916 = (struct type **) obstack_base (&dont_print_vb_obstack);
918 int j = (struct type **) obstack_next_free (&dont_print_vb_obstack)
922 if (baseclass == first_dont_print[j])
925 obstack_ptr_grow (&dont_print_vb_obstack, baseclass);
930 TRY_CATCH (ex, RETURN_MASK_ERROR)
932 boffset = baseclass_offset (type, i, valaddr, offset, address, val);
934 if (ex.reason < 0 && ex.error == NOT_AVAILABLE_ERROR)
936 else if (ex.reason < 0)
942 /* The virtual base class pointer might have been clobbered by the
943 user program. Make sure that it still points to a valid memory
946 if (boffset < 0 || boffset >= TYPE_LENGTH (type))
948 /* FIXME (alloc): not safe is baseclass is really really big. */
949 gdb_byte *buf = alloca (TYPE_LENGTH (baseclass));
952 if (target_read_memory (address + boffset, buf,
953 TYPE_LENGTH (baseclass)) != 0)
955 address = address + boffset;
960 base_valaddr = valaddr;
965 fprintf_filtered (stream, "\n");
966 print_spaces_filtered (2 * recurse, stream);
968 fputs_filtered ("<", stream);
969 /* Not sure what the best notation is in the case where there is no
972 fputs_filtered (basename ? basename : "", stream);
973 fputs_filtered ("> = ", stream);
976 val_print_unavailable (stream);
978 val_print_invalid_address (stream);
980 pascal_object_print_value_fields (baseclass, base_valaddr,
981 thisoffset + boffset, address,
982 stream, recurse, val, options,
983 (struct type **) obstack_base (&dont_print_vb_obstack),
985 fputs_filtered (", ", stream);
991 if (dont_print_vb == 0)
993 /* Free the space used to deal with the printing
994 of this type from top level. */
995 obstack_free (&dont_print_vb_obstack, last_dont_print);
996 /* Reset watermark so that we can continue protecting
997 ourselves from whatever we were protecting ourselves. */
998 dont_print_vb_obstack = tmp_obstack;
1002 /* Print value of a static member.
1003 To avoid infinite recursion when printing a class that contains
1004 a static instance of the class, we keep the addresses of all printed
1005 static member classes in an obstack and refuse to print them more
1008 VAL contains the value to print, STREAM, RECURSE, and OPTIONS
1009 have the same meanings as in c_val_print. */
1012 pascal_object_print_static_field (struct value *val,
1013 struct ui_file *stream,
1015 const struct value_print_options *options)
1017 struct type *type = value_type (val);
1018 struct value_print_options opts;
1020 if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
1022 CORE_ADDR *first_dont_print, addr;
1026 = (CORE_ADDR *) obstack_base (&dont_print_statmem_obstack);
1027 i = (CORE_ADDR *) obstack_next_free (&dont_print_statmem_obstack)
1032 if (value_address (val) == first_dont_print[i])
1035 <same as static member of an already seen type>",
1041 addr = value_address (val);
1042 obstack_grow (&dont_print_statmem_obstack, (char *) &addr,
1043 sizeof (CORE_ADDR));
1045 CHECK_TYPEDEF (type);
1046 pascal_object_print_value_fields (type,
1047 value_contents_for_printing (val),
1048 value_embedded_offset (val),
1051 val, options, NULL, 1);
1057 common_val_print (val, stream, recurse, &opts, current_language);
1060 /* -Wmissing-prototypes */
1061 extern initialize_file_ftype _initialize_pascal_valprint;
1064 _initialize_pascal_valprint (void)
1066 add_setshow_boolean_cmd ("pascal_static-members", class_support,
1067 &user_print_options.pascal_static_field_print, _("\
1068 Set printing of pascal static members."), _("\
1069 Show printing of pascal static members."), NULL,
1071 show_pascal_static_field_print,
1072 &setprintlist, &showprintlist);