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"
45 /* Print data of type TYPE located at VALADDR (within GDB), which came from
46 the inferior at address ADDRESS, onto stdio stream STREAM according to
47 OPTIONS. The data at VALADDR is in target byte order.
49 If the data are a string pointer, returns the number of string characters
54 pascal_val_print (struct type *type, const gdb_byte *valaddr,
55 int embedded_offset, CORE_ADDR address,
56 struct ui_file *stream, int recurse,
57 const struct value *original_value,
58 const struct value_print_options *options)
60 struct gdbarch *gdbarch = get_type_arch (type);
61 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
62 unsigned int i = 0; /* Number of characters printed */
64 LONGEST low_bound, high_bound;
67 int length_pos, length_size, string_pos;
68 struct type *char_type;
73 switch (TYPE_CODE (type))
76 if (get_array_bounds (type, &low_bound, &high_bound))
78 len = high_bound - low_bound + 1;
79 elttype = check_typedef (TYPE_TARGET_TYPE (type));
80 eltlen = TYPE_LENGTH (elttype);
81 if (options->prettyprint_arrays)
83 print_spaces_filtered (2 + 2 * recurse, stream);
85 /* If 's' format is used, try to print out as string.
86 If no format is given, print as string if element type
87 is of TYPE_CODE_CHAR and element size is 1,2 or 4. */
88 if (options->format == 's'
89 || ((eltlen == 1 || eltlen == 2 || eltlen == 4)
90 && TYPE_CODE (elttype) == TYPE_CODE_CHAR
91 && options->format == 0))
93 /* If requested, look for the first null char and only print
95 if (options->stop_print_at_null)
97 unsigned int temp_len;
99 /* Look for a NULL char. */
101 extract_unsigned_integer (valaddr + embedded_offset +
102 temp_len * eltlen, eltlen,
104 && temp_len < len && temp_len < options->print_max;
109 LA_PRINT_STRING (stream, TYPE_TARGET_TYPE (type),
110 valaddr + embedded_offset, len, NULL, 0,
116 fprintf_filtered (stream, "{");
117 /* If this is a virtual function table, print the 0th
118 entry specially, and the rest of the members normally. */
119 if (pascal_object_is_vtbl_ptr_type (elttype))
122 fprintf_filtered (stream, "%d vtable entries", len - 1);
128 val_print_array_elements (type, valaddr, embedded_offset,
129 address, stream, recurse,
130 original_value, options, i);
131 fprintf_filtered (stream, "}");
135 /* Array of unspecified length: treat like pointer to first elt. */
137 goto print_unpacked_pointer;
140 if (options->format && options->format != 's')
142 val_print_scalar_formatted (type, valaddr, embedded_offset,
143 original_value, options, 0, stream);
146 if (options->vtblprint && pascal_object_is_vtbl_ptr_type (type))
148 /* Print the unmangled name if desired. */
149 /* Print vtable entry - we only get here if we ARE using
150 -fvtable_thunks. (Otherwise, look under TYPE_CODE_STRUCT.) */
151 /* Extract the address, assume that it is unsigned. */
152 addr = extract_unsigned_integer (valaddr + embedded_offset,
153 TYPE_LENGTH (type), byte_order);
154 print_address_demangle (gdbarch, addr, stream, demangle);
157 elttype = check_typedef (TYPE_TARGET_TYPE (type));
159 addr = unpack_pointer (type, valaddr + embedded_offset);
160 print_unpacked_pointer:
161 elttype = check_typedef (TYPE_TARGET_TYPE (type));
163 if (TYPE_CODE (elttype) == TYPE_CODE_FUNC)
165 /* Try to print what function it points to. */
166 print_address_demangle (gdbarch, addr, stream, demangle);
167 /* Return value is irrelevant except for string pointers. */
171 if (options->addressprint && options->format != 's')
173 fputs_filtered (paddress (gdbarch, addr), stream);
176 /* For a pointer to char or unsigned char, also print the string
177 pointed to, unless pointer is null. */
178 if (((TYPE_LENGTH (elttype) == 1
179 && (TYPE_CODE (elttype) == TYPE_CODE_INT
180 || TYPE_CODE (elttype) == TYPE_CODE_CHAR))
181 || ((TYPE_LENGTH (elttype) == 2 || TYPE_LENGTH (elttype) == 4)
182 && TYPE_CODE (elttype) == TYPE_CODE_CHAR))
183 && (options->format == 0 || options->format == 's')
186 /* No wide string yet. */
187 i = val_print_string (elttype, NULL, addr, -1, stream, options);
189 /* Also for pointers to pascal strings. */
190 /* Note: this is Free Pascal specific:
191 as GDB does not recognize stabs pascal strings
192 Pascal strings are mapped to records
193 with lowercase names PM. */
194 if (is_pascal_string_type (elttype, &length_pos, &length_size,
195 &string_pos, &char_type, NULL)
198 ULONGEST string_length;
201 buffer = xmalloc (length_size);
202 read_memory (addr + length_pos, buffer, length_size);
203 string_length = extract_unsigned_integer (buffer, length_size,
206 i = val_print_string (char_type, NULL,
207 addr + string_pos, string_length,
210 else if (pascal_object_is_vtbl_member (type))
212 /* Print vtbl's nicely. */
213 CORE_ADDR vt_address = unpack_pointer (type,
214 valaddr + embedded_offset);
215 struct minimal_symbol *msymbol =
216 lookup_minimal_symbol_by_pc (vt_address);
218 if ((msymbol != NULL)
219 && (vt_address == SYMBOL_VALUE_ADDRESS (msymbol)))
221 fputs_filtered (" <", stream);
222 fputs_filtered (SYMBOL_PRINT_NAME (msymbol), stream);
223 fputs_filtered (">", stream);
225 if (vt_address && options->vtblprint)
227 struct value *vt_val;
228 struct symbol *wsym = (struct symbol *) NULL;
230 struct block *block = (struct block *) NULL;
234 wsym = lookup_symbol (SYMBOL_LINKAGE_NAME (msymbol), block,
235 VAR_DOMAIN, &is_this_fld);
239 wtype = SYMBOL_TYPE (wsym);
243 wtype = TYPE_TARGET_TYPE (type);
245 vt_val = value_at (wtype, vt_address);
246 common_val_print (vt_val, stream, recurse + 1, options,
250 fprintf_filtered (stream, "\n");
251 print_spaces_filtered (2 + 2 * recurse, stream);
256 /* Return number of characters printed, including the terminating
257 '\0' if we reached the end. val_print_string takes care including
258 the terminating '\0' if necessary. */
264 elttype = check_typedef (TYPE_TARGET_TYPE (type));
265 if (options->addressprint)
268 = extract_typed_address (valaddr + embedded_offset, type);
270 fprintf_filtered (stream, "@");
271 fputs_filtered (paddress (gdbarch, addr), stream);
272 if (options->deref_ref)
273 fputs_filtered (": ", stream);
275 /* De-reference the reference. */
276 if (options->deref_ref)
278 if (TYPE_CODE (elttype) != TYPE_CODE_UNDEF)
280 struct value *deref_val =
282 (TYPE_TARGET_TYPE (type),
283 unpack_pointer (type, valaddr + embedded_offset));
285 common_val_print (deref_val, stream, recurse + 1, options,
289 fputs_filtered ("???", stream);
293 case TYPE_CODE_UNION:
294 if (recurse && !options->unionprint)
296 fprintf_filtered (stream, "{...}");
300 case TYPE_CODE_STRUCT:
301 if (options->vtblprint && pascal_object_is_vtbl_ptr_type (type))
303 /* Print the unmangled name if desired. */
304 /* Print vtable entry - we only get here if NOT using
305 -fvtable_thunks. (Otherwise, look under TYPE_CODE_PTR.) */
306 /* Extract the address, assume that it is unsigned. */
307 print_address_demangle
309 extract_unsigned_integer (valaddr + embedded_offset
310 + TYPE_FIELD_BITPOS (type,
311 VTBL_FNADDR_OFFSET) / 8,
312 TYPE_LENGTH (TYPE_FIELD_TYPE (type,
313 VTBL_FNADDR_OFFSET)),
319 if (is_pascal_string_type (type, &length_pos, &length_size,
320 &string_pos, &char_type, NULL))
322 len = extract_unsigned_integer (valaddr + embedded_offset
323 + length_pos, length_size,
325 LA_PRINT_STRING (stream, char_type,
326 valaddr + embedded_offset + string_pos,
327 len, NULL, 0, options);
330 pascal_object_print_value_fields (type, valaddr, embedded_offset,
331 address, stream, recurse,
332 original_value, options,
340 val_print_scalar_formatted (type, valaddr, embedded_offset,
341 original_value, options, 0, stream);
344 len = TYPE_NFIELDS (type);
345 val = unpack_long (type, valaddr + embedded_offset);
346 for (i = 0; i < len; i++)
349 if (val == TYPE_FIELD_BITPOS (type, i))
356 fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
360 print_longest (stream, 'd', 0, val);
364 case TYPE_CODE_FLAGS:
366 val_print_scalar_formatted (type, valaddr, embedded_offset,
367 original_value, options, 0, stream);
369 val_print_type_code_flags (type, valaddr + embedded_offset, stream);
375 val_print_scalar_formatted (type, valaddr, embedded_offset,
376 original_value, options, 0, stream);
379 /* FIXME, we should consider, at least for ANSI C language, eliminating
380 the distinction made between FUNCs and POINTERs to FUNCs. */
381 fprintf_filtered (stream, "{");
382 type_print (type, "", stream, -1);
383 fprintf_filtered (stream, "} ");
384 /* Try to print what function it points to, and its address. */
385 print_address_demangle (gdbarch, address, stream, demangle);
389 if (options->format || options->output_format)
391 struct value_print_options opts = *options;
393 opts.format = (options->format ? options->format
394 : options->output_format);
395 val_print_scalar_formatted (type, valaddr, embedded_offset,
396 original_value, &opts, 0, stream);
400 val = unpack_long (type, valaddr + embedded_offset);
402 fputs_filtered ("false", stream);
404 fputs_filtered ("true", stream);
407 fputs_filtered ("true (", stream);
408 fprintf_filtered (stream, "%ld)", (long int) val);
413 case TYPE_CODE_RANGE:
414 /* FIXME: create_range_type does not set the unsigned bit in a
415 range type (I think it probably should copy it from the target
416 type), so we won't print values which are too large to
417 fit in a signed integer correctly. */
418 /* FIXME: Doesn't handle ranges of enums correctly. (Can't just
419 print with the target type, though, because the size of our type
420 and the target type might differ). */
424 if (options->format || options->output_format)
426 struct value_print_options opts = *options;
428 opts.format = (options->format ? options->format
429 : options->output_format);
430 val_print_scalar_formatted (type, valaddr, embedded_offset,
431 original_value, &opts, 0, stream);
435 val_print_type_code_int (type, valaddr + embedded_offset, stream);
440 if (options->format || options->output_format)
442 struct value_print_options opts = *options;
444 opts.format = (options->format ? options->format
445 : options->output_format);
446 val_print_scalar_formatted (type, valaddr, embedded_offset,
447 original_value, &opts, 0, stream);
451 val = unpack_long (type, valaddr + embedded_offset);
452 if (TYPE_UNSIGNED (type))
453 fprintf_filtered (stream, "%u", (unsigned int) val);
455 fprintf_filtered (stream, "%d", (int) val);
456 fputs_filtered (" ", stream);
457 LA_PRINT_CHAR ((unsigned char) val, type, stream);
464 val_print_scalar_formatted (type, valaddr, embedded_offset,
465 original_value, options, 0, stream);
469 print_floating (valaddr + embedded_offset, type, stream);
473 case TYPE_CODE_BITSTRING:
475 elttype = TYPE_INDEX_TYPE (type);
476 CHECK_TYPEDEF (elttype);
477 if (TYPE_STUB (elttype))
479 fprintf_filtered (stream, "<incomplete type>");
485 struct type *range = elttype;
486 LONGEST low_bound, high_bound;
488 int is_bitstring = TYPE_CODE (type) == TYPE_CODE_BITSTRING;
492 fputs_filtered ("B'", stream);
494 fputs_filtered ("[", stream);
496 i = get_discrete_bounds (range, &low_bound, &high_bound);
497 if (low_bound == 0 && high_bound == -1 && TYPE_LENGTH (type) > 0)
499 /* If we know the size of the set type, we can figure out the
502 high_bound = TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1;
503 TYPE_HIGH_BOUND (range) = high_bound;
508 fputs_filtered ("<error value>", stream);
512 for (i = low_bound; i <= high_bound; i++)
514 int element = value_bit_index (type,
515 valaddr + embedded_offset, i);
520 goto maybe_bad_bstring;
523 fprintf_filtered (stream, "%d", element);
527 fputs_filtered (", ", stream);
528 print_type_scalar (range, i, stream);
531 if (i + 1 <= high_bound
532 && value_bit_index (type,
533 valaddr + embedded_offset, ++i))
537 fputs_filtered ("..", stream);
538 while (i + 1 <= high_bound
539 && value_bit_index (type,
540 valaddr + embedded_offset,
543 print_type_scalar (range, j, stream);
549 fputs_filtered ("'", stream);
551 fputs_filtered ("]", stream);
556 fprintf_filtered (stream, "void");
559 case TYPE_CODE_ERROR:
560 fprintf_filtered (stream, "%s", TYPE_ERROR_NAME (type));
563 case TYPE_CODE_UNDEF:
564 /* This happens (without TYPE_FLAG_STUB set) on systems which don't use
565 dbx xrefs (NO_DBX_XREFS in gcc) if a file has a "struct foo *bar"
566 and no complete type for struct foo in that file. */
567 fprintf_filtered (stream, "<incomplete type>");
571 error (_("Invalid pascal type code %d in symbol table."),
579 pascal_value_print (struct value *val, struct ui_file *stream,
580 const struct value_print_options *options)
582 struct type *type = value_type (val);
583 struct value_print_options opts = *options;
587 /* If it is a pointer, indicate what it points to.
589 Print type also if it is a reference.
591 Object pascal: if it is a member pointer, we will take care
592 of that when we print it. */
593 if (TYPE_CODE (type) == TYPE_CODE_PTR
594 || TYPE_CODE (type) == TYPE_CODE_REF)
596 /* Hack: remove (char *) for char strings. Their
597 type is indicated by the quoted string anyway. */
598 if (TYPE_CODE (type) == TYPE_CODE_PTR
599 && TYPE_NAME (type) == NULL
600 && TYPE_NAME (TYPE_TARGET_TYPE (type)) != NULL
601 && strcmp (TYPE_NAME (TYPE_TARGET_TYPE (type)), "char") == 0)
607 fprintf_filtered (stream, "(");
608 type_print (type, "", stream, -1);
609 fprintf_filtered (stream, ") ");
612 return common_val_print (val, stream, 0, &opts, current_language);
617 show_pascal_static_field_print (struct ui_file *file, int from_tty,
618 struct cmd_list_element *c, const char *value)
620 fprintf_filtered (file, _("Printing of pascal static members is %s.\n"),
624 static struct obstack dont_print_vb_obstack;
625 static struct obstack dont_print_statmem_obstack;
627 static void pascal_object_print_static_field (struct value *,
628 struct ui_file *, int,
629 const struct value_print_options *);
631 static void pascal_object_print_value (struct type *, const gdb_byte *,
633 CORE_ADDR, struct ui_file *, int,
634 const struct value *,
635 const struct value_print_options *,
638 /* It was changed to this after 2.4.5. */
639 const char pascal_vtbl_ptr_name[] =
640 {'_', '_', 'v', 't', 'b', 'l', '_', 'p', 't', 'r', '_', 't', 'y', 'p', 'e', 0};
642 /* Return truth value for assertion that TYPE is of the type
643 "pointer to virtual function". */
646 pascal_object_is_vtbl_ptr_type (struct type *type)
648 char *typename = type_name_no_tag (type);
650 return (typename != NULL
651 && strcmp (typename, pascal_vtbl_ptr_name) == 0);
654 /* Return truth value for the assertion that TYPE is of the type
655 "pointer to virtual function table". */
658 pascal_object_is_vtbl_member (struct type *type)
660 if (TYPE_CODE (type) == TYPE_CODE_PTR)
662 type = TYPE_TARGET_TYPE (type);
663 if (TYPE_CODE (type) == TYPE_CODE_ARRAY)
665 type = TYPE_TARGET_TYPE (type);
666 if (TYPE_CODE (type) == TYPE_CODE_STRUCT /* If not using
668 || TYPE_CODE (type) == TYPE_CODE_PTR) /* If using thunks. */
670 /* Virtual functions tables are full of pointers
671 to virtual functions. */
672 return pascal_object_is_vtbl_ptr_type (type);
679 /* Mutually recursive subroutines of pascal_object_print_value and
680 c_val_print to print out a structure's fields:
681 pascal_object_print_value_fields and pascal_object_print_value.
683 TYPE, VALADDR, ADDRESS, STREAM, RECURSE, and OPTIONS have the
684 same meanings as in pascal_object_print_value and c_val_print.
686 DONT_PRINT is an array of baseclass types that we
687 should not print, or zero if called from top level. */
690 pascal_object_print_value_fields (struct type *type, const gdb_byte *valaddr,
692 CORE_ADDR address, struct ui_file *stream,
694 const struct value *val,
695 const struct value_print_options *options,
696 struct type **dont_print_vb,
697 int dont_print_statmem)
699 int i, len, n_baseclasses;
700 char *last_dont_print = obstack_next_free (&dont_print_statmem_obstack);
702 CHECK_TYPEDEF (type);
704 fprintf_filtered (stream, "{");
705 len = TYPE_NFIELDS (type);
706 n_baseclasses = TYPE_N_BASECLASSES (type);
708 /* Print out baseclasses such that we don't print
709 duplicates of virtual baseclasses. */
710 if (n_baseclasses > 0)
711 pascal_object_print_value (type, valaddr, offset, address,
712 stream, recurse + 1, val,
713 options, dont_print_vb);
715 if (!len && n_baseclasses == 1)
716 fprintf_filtered (stream, "<No data fields>");
719 struct obstack tmp_obstack = dont_print_statmem_obstack;
722 if (dont_print_statmem == 0)
724 /* If we're at top level, carve out a completely fresh
725 chunk of the obstack and use that until this particular
726 invocation returns. */
727 obstack_finish (&dont_print_statmem_obstack);
730 for (i = n_baseclasses; i < len; i++)
732 /* If requested, skip printing of static fields. */
733 if (!options->pascal_static_field_print
734 && field_is_static (&TYPE_FIELD (type, i)))
737 fprintf_filtered (stream, ", ");
738 else if (n_baseclasses > 0)
742 fprintf_filtered (stream, "\n");
743 print_spaces_filtered (2 + 2 * recurse, stream);
744 fputs_filtered ("members of ", stream);
745 fputs_filtered (type_name_no_tag (type), stream);
746 fputs_filtered (": ", stream);
753 fprintf_filtered (stream, "\n");
754 print_spaces_filtered (2 + 2 * recurse, stream);
758 wrap_here (n_spaces (2 + 2 * recurse));
760 if (options->inspect_it)
762 if (TYPE_CODE (TYPE_FIELD_TYPE (type, i)) == TYPE_CODE_PTR)
763 fputs_filtered ("\"( ptr \"", stream);
765 fputs_filtered ("\"( nodef \"", stream);
766 if (field_is_static (&TYPE_FIELD (type, i)))
767 fputs_filtered ("static ", stream);
768 fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i),
770 DMGL_PARAMS | DMGL_ANSI);
771 fputs_filtered ("\" \"", stream);
772 fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i),
774 DMGL_PARAMS | DMGL_ANSI);
775 fputs_filtered ("\") \"", stream);
779 annotate_field_begin (TYPE_FIELD_TYPE (type, i));
781 if (field_is_static (&TYPE_FIELD (type, i)))
782 fputs_filtered ("static ", stream);
783 fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i),
785 DMGL_PARAMS | DMGL_ANSI);
786 annotate_field_name_end ();
787 fputs_filtered (" = ", stream);
788 annotate_field_value ();
791 if (!field_is_static (&TYPE_FIELD (type, i))
792 && TYPE_FIELD_PACKED (type, i))
796 /* Bitfields require special handling, especially due to byte
798 if (TYPE_FIELD_IGNORE (type, i))
800 fputs_filtered ("<optimized out or zero length>", stream);
802 else if (value_bits_synthetic_pointer (val,
803 TYPE_FIELD_BITPOS (type,
805 TYPE_FIELD_BITSIZE (type,
808 fputs_filtered (_("<synthetic pointer>"), stream);
810 else if (!value_bits_valid (val, TYPE_FIELD_BITPOS (type, i),
811 TYPE_FIELD_BITSIZE (type, i)))
813 val_print_optimized_out (stream);
817 struct value_print_options opts = *options;
819 v = value_from_longest (TYPE_FIELD_TYPE (type, i),
820 unpack_field_as_long (type,
821 valaddr + offset, i));
824 common_val_print (v, stream, recurse + 1, &opts,
830 if (TYPE_FIELD_IGNORE (type, i))
832 fputs_filtered ("<optimized out or zero length>", stream);
834 else if (field_is_static (&TYPE_FIELD (type, i)))
836 /* struct value *v = value_static_field (type, i);
840 v = value_from_longest
841 (TYPE_FIELD_TYPE (type, i),
842 unpack_field_as_long (type, valaddr + offset, i));
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;
919 if (BASETYPE_VIA_VIRTUAL (type, i))
921 struct type **first_dont_print
922 = (struct type **) obstack_base (&dont_print_vb_obstack);
924 int j = (struct type **) obstack_next_free (&dont_print_vb_obstack)
928 if (baseclass == first_dont_print[j])
931 obstack_ptr_grow (&dont_print_vb_obstack, baseclass);
936 boffset = baseclass_offset (type, i, valaddr + offset, address + offset);
940 fprintf_filtered (stream, "\n");
941 print_spaces_filtered (2 * recurse, stream);
943 fputs_filtered ("<", stream);
944 /* Not sure what the best notation is in the case where there is no
947 fputs_filtered (basename ? basename : "", stream);
948 fputs_filtered ("> = ", stream);
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 != -1 && (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;
971 fprintf_filtered (stream, "<invalid address>");
973 pascal_object_print_value_fields (baseclass, base_valaddr,
974 thisoffset + boffset, address,
975 stream, recurse, val, options,
976 (struct type **) obstack_base (&dont_print_vb_obstack),
978 fputs_filtered (", ", stream);
984 if (dont_print_vb == 0)
986 /* Free the space used to deal with the printing
987 of this type from top level. */
988 obstack_free (&dont_print_vb_obstack, last_dont_print);
989 /* Reset watermark so that we can continue protecting
990 ourselves from whatever we were protecting ourselves. */
991 dont_print_vb_obstack = tmp_obstack;
995 /* Print value of a static member.
996 To avoid infinite recursion when printing a class that contains
997 a static instance of the class, we keep the addresses of all printed
998 static member classes in an obstack and refuse to print them more
1001 VAL contains the value to print, STREAM, RECURSE, and OPTIONS
1002 have the same meanings as in c_val_print. */
1005 pascal_object_print_static_field (struct value *val,
1006 struct ui_file *stream,
1008 const struct value_print_options *options)
1010 struct type *type = value_type (val);
1011 struct value_print_options opts;
1013 if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
1015 CORE_ADDR *first_dont_print, addr;
1019 = (CORE_ADDR *) obstack_base (&dont_print_statmem_obstack);
1020 i = (CORE_ADDR *) obstack_next_free (&dont_print_statmem_obstack)
1025 if (value_address (val) == first_dont_print[i])
1028 <same as static member of an already seen type>",
1034 addr = value_address (val);
1035 obstack_grow (&dont_print_statmem_obstack, (char *) &addr,
1036 sizeof (CORE_ADDR));
1038 CHECK_TYPEDEF (type);
1039 pascal_object_print_value_fields (type,
1040 value_contents_for_printing (val),
1041 value_embedded_offset (val),
1044 val, options, NULL, 1);
1050 common_val_print (val, stream, recurse, &opts, current_language);
1053 /* -Wmissing-prototypes */
1054 extern initialize_file_ftype _initialize_pascal_valprint;
1057 _initialize_pascal_valprint (void)
1059 add_setshow_boolean_cmd ("pascal_static-members", class_support,
1060 &user_print_options.pascal_static_field_print, _("\
1061 Set printing of pascal static members."), _("\
1062 Show printing of pascal static members."), NULL,
1064 show_pascal_static_field_print,
1065 &setprintlist, &showprintlist);