1 /* Support for printing Pascal values for GDB, the GNU debugger.
3 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21 /* This file is derived from c-valprint.c */
27 #include "expression.h"
34 #include "typeprint.h"
43 /* Print data of type TYPE located at VALADDR (within GDB), which came from
44 the inferior at address ADDRESS, onto stdio stream STREAM according to
45 FORMAT (a letter or 0 for natural format). The data at VALADDR is in
48 If the data are a string pointer, returns the number of string characters
51 If DEREF_REF is nonzero, then dereference references, otherwise just print
54 The PRETTY parameter controls prettyprinting. */
58 pascal_val_print (struct type *type, char *valaddr, int embedded_offset,
59 CORE_ADDR address, struct ui_file *stream, int format,
60 int deref_ref, int recurse, enum val_prettyprint pretty)
62 register unsigned int i = 0; /* Number of characters printed */
70 switch (TYPE_CODE (type))
73 if (TYPE_LENGTH (type) > 0 && TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0)
75 elttype = check_typedef (TYPE_TARGET_TYPE (type));
76 eltlen = TYPE_LENGTH (elttype);
77 len = TYPE_LENGTH (type) / eltlen;
78 if (prettyprint_arrays)
80 print_spaces_filtered (2 + 2 * recurse, stream);
82 /* For an array of chars, print with string syntax. */
84 ((TYPE_CODE (elttype) == TYPE_CODE_INT)
85 || ((current_language->la_language == language_m2)
86 && (TYPE_CODE (elttype) == TYPE_CODE_CHAR)))
87 && (format == 0 || format == 's'))
89 /* If requested, look for the first null char and only print
91 if (stop_print_at_null)
93 unsigned int temp_len;
95 /* Look for a NULL char. */
97 (valaddr + embedded_offset)[temp_len]
98 && temp_len < len && temp_len < print_max;
103 LA_PRINT_STRING (stream, valaddr + embedded_offset, len, 1, 0);
108 fprintf_filtered (stream, "{");
109 /* If this is a virtual function table, print the 0th
110 entry specially, and the rest of the members normally. */
111 if (pascal_object_is_vtbl_ptr_type (elttype))
114 fprintf_filtered (stream, "%d vtable entries", len - 1);
120 val_print_array_elements (type, valaddr + embedded_offset, address, stream,
121 format, deref_ref, recurse, pretty, i);
122 fprintf_filtered (stream, "}");
126 /* Array of unspecified length: treat like pointer to first elt. */
128 goto print_unpacked_pointer;
131 if (format && format != 's')
133 print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream);
136 if (vtblprint && pascal_object_is_vtbl_ptr_type (type))
138 /* Print the unmangled name if desired. */
139 /* Print vtable entry - we only get here if we ARE using
140 -fvtable_thunks. (Otherwise, look under TYPE_CODE_STRUCT.) */
141 print_address_demangle (extract_address (valaddr + embedded_offset, TYPE_LENGTH (type)),
145 elttype = check_typedef (TYPE_TARGET_TYPE (type));
146 if (TYPE_CODE (elttype) == TYPE_CODE_METHOD)
148 pascal_object_print_class_method (valaddr + embedded_offset, type, stream);
150 else if (TYPE_CODE (elttype) == TYPE_CODE_MEMBER)
152 pascal_object_print_class_member (valaddr + embedded_offset,
153 TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (type)),
158 addr = unpack_pointer (type, valaddr + embedded_offset);
159 print_unpacked_pointer:
160 elttype = check_typedef (TYPE_TARGET_TYPE (type));
162 if (TYPE_CODE (elttype) == TYPE_CODE_FUNC)
164 /* Try to print what function it points to. */
165 print_address_demangle (addr, stream, demangle);
166 /* Return value is irrelevant except for string pointers. */
170 if (addressprint && format != 's')
172 print_address_numeric (addr, 1, stream);
175 /* For a pointer to char or unsigned char, also print the string
176 pointed to, unless pointer is null. */
177 if (TYPE_LENGTH (elttype) == 1
178 && TYPE_CODE (elttype) == TYPE_CODE_INT
179 && (format == 0 || format == 's')
182 /* no wide string yet */
183 i = val_print_string (addr, -1, 1, stream);
185 /* also for pointers to pascal strings */
186 /* Note: this is Free Pascal specific:
187 as GDB does not recognize stabs pascal strings
188 Pascal strings are mapped to records
189 with lowercase names PM */
190 /* I don't know what GPC does :( PM */
191 if (TYPE_CODE (elttype) == TYPE_CODE_STRUCT &&
192 TYPE_NFIELDS (elttype) == 2 &&
193 strcmp (TYPE_FIELDS (elttype)[0].name, "length") == 0 &&
194 strcmp (TYPE_FIELDS (elttype)[1].name, "st") == 0 &&
198 read_memory (addr, &bytelength, 1);
199 i = val_print_string (addr + 1, bytelength, 1, stream);
201 else if (pascal_object_is_vtbl_member (type))
203 /* print vtbl's nicely */
204 CORE_ADDR vt_address = unpack_pointer (type, valaddr + embedded_offset);
206 struct minimal_symbol *msymbol =
207 lookup_minimal_symbol_by_pc (vt_address);
208 if ((msymbol != NULL) &&
209 (vt_address == SYMBOL_VALUE_ADDRESS (msymbol)))
211 fputs_filtered (" <", stream);
212 fputs_filtered (SYMBOL_SOURCE_NAME (msymbol), stream);
213 fputs_filtered (">", stream);
215 if (vt_address && vtblprint)
218 struct symbol *wsym = (struct symbol *) NULL;
221 struct block *block = (struct block *) NULL;
225 wsym = lookup_symbol (SYMBOL_NAME (msymbol), block,
226 VAR_NAMESPACE, &is_this_fld, &s);
230 wtype = SYMBOL_TYPE (wsym);
234 wtype = TYPE_TARGET_TYPE (type);
236 vt_val = value_at (wtype, vt_address, NULL);
237 val_print (VALUE_TYPE (vt_val), VALUE_CONTENTS (vt_val), 0,
238 VALUE_ADDRESS (vt_val), stream, format,
239 deref_ref, recurse + 1, pretty);
242 fprintf_filtered (stream, "\n");
243 print_spaces_filtered (2 + 2 * recurse, stream);
248 /* Return number of characters printed, including the terminating
249 '\0' if we reached the end. val_print_string takes care including
250 the terminating '\0' if necessary. */
255 case TYPE_CODE_MEMBER:
256 error ("not implemented: member type in pascal_val_print");
260 elttype = check_typedef (TYPE_TARGET_TYPE (type));
261 if (TYPE_CODE (elttype) == TYPE_CODE_MEMBER)
263 pascal_object_print_class_member (valaddr + embedded_offset,
264 TYPE_DOMAIN_TYPE (elttype),
270 fprintf_filtered (stream, "@");
271 print_address_numeric
272 (extract_address (valaddr + embedded_offset,
273 TARGET_PTR_BIT / HOST_CHAR_BIT), 1, stream);
275 fputs_filtered (": ", stream);
277 /* De-reference the reference. */
280 if (TYPE_CODE (elttype) != TYPE_CODE_UNDEF)
282 value_ptr deref_val =
284 (TYPE_TARGET_TYPE (type),
285 unpack_pointer (lookup_pointer_type (builtin_type_void),
286 valaddr + embedded_offset),
288 val_print (VALUE_TYPE (deref_val),
289 VALUE_CONTENTS (deref_val), 0,
290 VALUE_ADDRESS (deref_val), stream, format,
291 deref_ref, recurse + 1, pretty);
294 fputs_filtered ("???", stream);
298 case TYPE_CODE_UNION:
299 if (recurse && !unionprint)
301 fprintf_filtered (stream, "{...}");
305 case TYPE_CODE_STRUCT:
306 if (vtblprint && pascal_object_is_vtbl_ptr_type (type))
308 /* Print the unmangled name if desired. */
309 /* Print vtable entry - we only get here if NOT using
310 -fvtable_thunks. (Otherwise, look under TYPE_CODE_PTR.) */
311 print_address_demangle (extract_address (
312 valaddr + embedded_offset + TYPE_FIELD_BITPOS (type, VTBL_FNADDR_OFFSET) / 8,
313 TYPE_LENGTH (TYPE_FIELD_TYPE (type, VTBL_FNADDR_OFFSET))),
318 if ((TYPE_NFIELDS (type) == 2) &&
319 (strcmp (TYPE_FIELDS (type)[0].name, "length") == 0) &&
320 (strcmp (TYPE_FIELDS (type)[1].name, "st") == 0))
322 len = (*(valaddr + embedded_offset)) & 0xff;
323 LA_PRINT_STRING (stream, valaddr + embedded_offset + 1, len, /* width ?? */ 0, 0);
326 pascal_object_print_value_fields (type, valaddr + embedded_offset, address, stream, format,
327 recurse, pretty, NULL, 0);
334 print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream);
337 len = TYPE_NFIELDS (type);
338 val = unpack_long (type, valaddr + embedded_offset);
339 for (i = 0; i < len; i++)
342 if (val == TYPE_FIELD_BITPOS (type, i))
349 fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
353 print_longest (stream, 'd', 0, val);
360 print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream);
363 /* FIXME, we should consider, at least for ANSI C language, eliminating
364 the distinction made between FUNCs and POINTERs to FUNCs. */
365 fprintf_filtered (stream, "{");
366 type_print (type, "", stream, -1);
367 fprintf_filtered (stream, "} ");
368 /* Try to print what function it points to, and its address. */
369 print_address_demangle (address, stream, demangle);
373 format = format ? format : output_format;
375 print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream);
378 val = unpack_long (type, valaddr + embedded_offset);
380 fputs_filtered ("false", stream);
382 fputs_filtered ("true", stream);
385 fputs_filtered ("true (", stream);
386 fprintf_filtered (stream, "%ld)", (long int) val);
391 case TYPE_CODE_RANGE:
392 /* FIXME: create_range_type does not set the unsigned bit in a
393 range type (I think it probably should copy it from the target
394 type), so we won't print values which are too large to
395 fit in a signed integer correctly. */
396 /* FIXME: Doesn't handle ranges of enums correctly. (Can't just
397 print with the target type, though, because the size of our type
398 and the target type might differ). */
402 format = format ? format : output_format;
405 print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream);
409 val_print_type_code_int (type, valaddr + embedded_offset, stream);
414 format = format ? format : output_format;
417 print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream);
421 val = unpack_long (type, valaddr + embedded_offset);
422 if (TYPE_UNSIGNED (type))
423 fprintf_filtered (stream, "%u", (unsigned int) val);
425 fprintf_filtered (stream, "%d", (int) val);
426 fputs_filtered (" ", stream);
427 LA_PRINT_CHAR ((unsigned char) val, stream);
434 print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream);
438 print_floating (valaddr + embedded_offset, type, stream);
442 case TYPE_CODE_BITSTRING:
444 elttype = TYPE_INDEX_TYPE (type);
445 CHECK_TYPEDEF (elttype);
446 if (TYPE_FLAGS (elttype) & TYPE_FLAG_STUB)
448 fprintf_filtered (stream, "<incomplete type>");
454 struct type *range = elttype;
455 LONGEST low_bound, high_bound;
457 int is_bitstring = TYPE_CODE (type) == TYPE_CODE_BITSTRING;
461 fputs_filtered ("B'", stream);
463 fputs_filtered ("[", stream);
465 i = get_discrete_bounds (range, &low_bound, &high_bound);
469 fputs_filtered ("<error value>", stream);
473 for (i = low_bound; i <= high_bound; i++)
475 int element = value_bit_index (type, valaddr + embedded_offset, i);
479 goto maybe_bad_bstring;
482 fprintf_filtered (stream, "%d", element);
486 fputs_filtered (", ", stream);
487 print_type_scalar (range, i, stream);
490 if (i + 1 <= high_bound && value_bit_index (type, valaddr + embedded_offset, ++i))
493 fputs_filtered ("..", stream);
494 while (i + 1 <= high_bound
495 && value_bit_index (type, valaddr + embedded_offset, ++i))
497 print_type_scalar (range, j, stream);
503 fputs_filtered ("'", stream);
505 fputs_filtered ("]", stream);
510 fprintf_filtered (stream, "void");
513 case TYPE_CODE_ERROR:
514 fprintf_filtered (stream, "<error type>");
517 case TYPE_CODE_UNDEF:
518 /* This happens (without TYPE_FLAG_STUB set) on systems which don't use
519 dbx xrefs (NO_DBX_XREFS in gcc) if a file has a "struct foo *bar"
520 and no complete type for struct foo in that file. */
521 fprintf_filtered (stream, "<incomplete type>");
525 error ("Invalid pascal type code %d in symbol table.", TYPE_CODE (type));
532 pascal_value_print (value_ptr val, struct ui_file *stream, int format,
533 enum val_prettyprint pretty)
535 struct type *type = VALUE_TYPE (val);
537 /* If it is a pointer, indicate what it points to.
539 Print type also if it is a reference.
541 Object pascal: if it is a member pointer, we will take care
542 of that when we print it. */
543 if (TYPE_CODE (type) == TYPE_CODE_PTR ||
544 TYPE_CODE (type) == TYPE_CODE_REF)
546 /* Hack: remove (char *) for char strings. Their
547 type is indicated by the quoted string anyway. */
548 if (TYPE_CODE (type) == TYPE_CODE_PTR &&
549 TYPE_NAME (type) == NULL &&
550 TYPE_NAME (TYPE_TARGET_TYPE (type)) != NULL &&
551 STREQ (TYPE_NAME (TYPE_TARGET_TYPE (type)), "char"))
557 fprintf_filtered (stream, "(");
558 type_print (type, "", stream, -1);
559 fprintf_filtered (stream, ") ");
562 return val_print (type, VALUE_CONTENTS (val), VALUE_EMBEDDED_OFFSET (val),
563 VALUE_ADDRESS (val) + VALUE_OFFSET (val),
564 stream, format, 1, 0, pretty);
568 /******************************************************************************
569 Inserted from cp-valprint
570 ******************************************************************************/
572 extern int vtblprint; /* Controls printing of vtbl's */
573 extern int objectprint; /* Controls looking up an object's derived type
574 using what we find in its vtables. */
575 static int pascal_static_field_print; /* Controls printing of static fields. */
577 static struct obstack dont_print_vb_obstack;
578 static struct obstack dont_print_statmem_obstack;
581 pascal_object_print_static_field (struct type *, value_ptr, struct ui_file *, int, int,
582 enum val_prettyprint);
585 pascal_object_print_value (struct type *, char *, CORE_ADDR, struct ui_file *,
586 int, int, enum val_prettyprint, struct type **);
589 pascal_object_print_class_method (char *valaddr, struct type *type,
590 struct ui_file *stream)
593 struct fn_field *f = NULL;
602 struct type *target_type = check_typedef (TYPE_TARGET_TYPE (type));
604 domain = TYPE_DOMAIN_TYPE (target_type);
605 if (domain == (struct type *) NULL)
607 fprintf_filtered (stream, "<unknown>");
610 addr = unpack_pointer (lookup_pointer_type (builtin_type_void), valaddr);
611 if (METHOD_PTR_IS_VIRTUAL (addr))
613 offset = METHOD_PTR_TO_VOFFSET (addr);
614 len = TYPE_NFN_FIELDS (domain);
615 for (i = 0; i < len; i++)
617 f = TYPE_FN_FIELDLIST1 (domain, i);
618 len2 = TYPE_FN_FIELDLIST_LENGTH (domain, i);
620 for (j = 0; j < len2; j++)
623 if (TYPE_FN_FIELD_VOFFSET (f, j) == offset)
625 if (TYPE_FN_FIELD_STUB (f, j))
626 check_stub_method (domain, i, j);
635 sym = find_pc_function (addr);
638 error ("invalid pointer to member function");
640 len = TYPE_NFN_FIELDS (domain);
641 for (i = 0; i < len; i++)
643 f = TYPE_FN_FIELDLIST1 (domain, i);
644 len2 = TYPE_FN_FIELDLIST_LENGTH (domain, i);
646 for (j = 0; j < len2; j++)
649 if (TYPE_FN_FIELD_STUB (f, j))
650 check_stub_method (domain, i, j);
651 if (STREQ (SYMBOL_NAME (sym), TYPE_FN_FIELD_PHYSNAME (f, j)))
661 char *demangled_name;
663 fprintf_filtered (stream, "&");
664 fprintf_filtered (stream, kind);
665 demangled_name = cplus_demangle (TYPE_FN_FIELD_PHYSNAME (f, j),
666 DMGL_ANSI | DMGL_PARAMS);
667 if (demangled_name == NULL)
668 fprintf_filtered (stream, "<badly mangled name %s>",
669 TYPE_FN_FIELD_PHYSNAME (f, j));
672 fputs_filtered (demangled_name, stream);
673 xfree (demangled_name);
678 fprintf_filtered (stream, "(");
679 type_print (type, "", stream, -1);
680 fprintf_filtered (stream, ") %d", (int) addr >> 3);
684 /* It was changed to this after 2.4.5. */
685 const char pascal_vtbl_ptr_name[] =
686 {'_', '_', 'v', 't', 'b', 'l', '_', 'p', 't', 'r', '_', 't', 'y', 'p', 'e', 0};
688 /* Return truth value for assertion that TYPE is of the type
689 "pointer to virtual function". */
692 pascal_object_is_vtbl_ptr_type (struct type *type)
694 char *typename = type_name_no_tag (type);
696 return (typename != NULL
697 && (STREQ (typename, pascal_vtbl_ptr_name)));
700 /* Return truth value for the assertion that TYPE is of the type
701 "pointer to virtual function table". */
704 pascal_object_is_vtbl_member (struct type *type)
706 if (TYPE_CODE (type) == TYPE_CODE_PTR)
708 type = TYPE_TARGET_TYPE (type);
709 if (TYPE_CODE (type) == TYPE_CODE_ARRAY)
711 type = TYPE_TARGET_TYPE (type);
712 if (TYPE_CODE (type) == TYPE_CODE_STRUCT /* if not using thunks */
713 || TYPE_CODE (type) == TYPE_CODE_PTR) /* if using thunks */
715 /* Virtual functions tables are full of pointers
716 to virtual functions. */
717 return pascal_object_is_vtbl_ptr_type (type);
724 /* Mutually recursive subroutines of pascal_object_print_value and c_val_print to
725 print out a structure's fields: pascal_object_print_value_fields and pascal_object_print_value.
727 TYPE, VALADDR, ADDRESS, STREAM, RECURSE, and PRETTY have the
728 same meanings as in pascal_object_print_value and c_val_print.
730 DONT_PRINT is an array of baseclass types that we
731 should not print, or zero if called from top level. */
734 pascal_object_print_value_fields (struct type *type, char *valaddr,
735 CORE_ADDR address, struct ui_file *stream,
736 int format, int recurse,
737 enum val_prettyprint pretty,
738 struct type **dont_print_vb,
739 int dont_print_statmem)
741 int i, len, n_baseclasses;
742 struct obstack tmp_obstack;
743 char *last_dont_print = obstack_next_free (&dont_print_statmem_obstack);
745 CHECK_TYPEDEF (type);
747 fprintf_filtered (stream, "{");
748 len = TYPE_NFIELDS (type);
749 n_baseclasses = TYPE_N_BASECLASSES (type);
751 /* Print out baseclasses such that we don't print
752 duplicates of virtual baseclasses. */
753 if (n_baseclasses > 0)
754 pascal_object_print_value (type, valaddr, address, stream,
755 format, recurse + 1, pretty, dont_print_vb);
757 if (!len && n_baseclasses == 1)
758 fprintf_filtered (stream, "<No data fields>");
761 extern int inspect_it;
764 if (dont_print_statmem == 0)
766 /* If we're at top level, carve out a completely fresh
767 chunk of the obstack and use that until this particular
768 invocation returns. */
769 tmp_obstack = dont_print_statmem_obstack;
770 obstack_finish (&dont_print_statmem_obstack);
773 for (i = n_baseclasses; i < len; i++)
775 /* If requested, skip printing of static fields. */
776 if (!pascal_static_field_print && TYPE_FIELD_STATIC (type, i))
779 fprintf_filtered (stream, ", ");
780 else if (n_baseclasses > 0)
784 fprintf_filtered (stream, "\n");
785 print_spaces_filtered (2 + 2 * recurse, stream);
786 fputs_filtered ("members of ", stream);
787 fputs_filtered (type_name_no_tag (type), stream);
788 fputs_filtered (": ", stream);
795 fprintf_filtered (stream, "\n");
796 print_spaces_filtered (2 + 2 * recurse, stream);
800 wrap_here (n_spaces (2 + 2 * recurse));
804 if (TYPE_CODE (TYPE_FIELD_TYPE (type, i)) == TYPE_CODE_PTR)
805 fputs_filtered ("\"( ptr \"", stream);
807 fputs_filtered ("\"( nodef \"", stream);
808 if (TYPE_FIELD_STATIC (type, i))
809 fputs_filtered ("static ", stream);
810 fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i),
812 DMGL_PARAMS | DMGL_ANSI);
813 fputs_filtered ("\" \"", stream);
814 fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i),
816 DMGL_PARAMS | DMGL_ANSI);
817 fputs_filtered ("\") \"", stream);
821 annotate_field_begin (TYPE_FIELD_TYPE (type, i));
823 if (TYPE_FIELD_STATIC (type, i))
824 fputs_filtered ("static ", stream);
825 fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i),
827 DMGL_PARAMS | DMGL_ANSI);
828 annotate_field_name_end ();
829 fputs_filtered (" = ", stream);
830 annotate_field_value ();
833 if (!TYPE_FIELD_STATIC (type, i) && TYPE_FIELD_PACKED (type, i))
837 /* Bitfields require special handling, especially due to byte
839 if (TYPE_FIELD_IGNORE (type, i))
841 fputs_filtered ("<optimized out or zero length>", stream);
845 v = value_from_longest (TYPE_FIELD_TYPE (type, i),
846 unpack_field_as_long (type, valaddr, i));
848 val_print (TYPE_FIELD_TYPE (type, i), VALUE_CONTENTS (v), 0, 0,
849 stream, format, 0, recurse + 1, pretty);
854 if (TYPE_FIELD_IGNORE (type, i))
856 fputs_filtered ("<optimized out or zero length>", stream);
858 else if (TYPE_FIELD_STATIC (type, i))
860 /* value_ptr v = value_static_field (type, i); v4.17 specific */
862 v = value_from_longest (TYPE_FIELD_TYPE (type, i),
863 unpack_field_as_long (type, valaddr, i));
866 fputs_filtered ("<optimized out>", stream);
868 pascal_object_print_static_field (TYPE_FIELD_TYPE (type, i), v,
869 stream, format, recurse + 1,
874 /* val_print (TYPE_FIELD_TYPE (type, i),
875 valaddr + TYPE_FIELD_BITPOS (type, i) / 8,
876 address + TYPE_FIELD_BITPOS (type, i) / 8, 0,
877 stream, format, 0, recurse + 1, pretty); */
878 val_print (TYPE_FIELD_TYPE (type, i),
879 valaddr, TYPE_FIELD_BITPOS (type, i) / 8,
880 address + TYPE_FIELD_BITPOS (type, i) / 8,
881 stream, format, 0, recurse + 1, pretty);
884 annotate_field_end ();
887 if (dont_print_statmem == 0)
889 /* Free the space used to deal with the printing
890 of the members from top level. */
891 obstack_free (&dont_print_statmem_obstack, last_dont_print);
892 dont_print_statmem_obstack = tmp_obstack;
897 fprintf_filtered (stream, "\n");
898 print_spaces_filtered (2 * recurse, stream);
901 fprintf_filtered (stream, "}");
904 /* Special val_print routine to avoid printing multiple copies of virtual
908 pascal_object_print_value (struct type *type, char *valaddr, CORE_ADDR address,
909 struct ui_file *stream, int format, int recurse,
910 enum val_prettyprint pretty,
911 struct type **dont_print_vb)
913 struct obstack tmp_obstack;
914 struct type **last_dont_print
915 = (struct type **) obstack_next_free (&dont_print_vb_obstack);
916 int i, n_baseclasses = TYPE_N_BASECLASSES (type);
918 if (dont_print_vb == 0)
920 /* If we're at top level, carve out a completely fresh
921 chunk of the obstack and use that until this particular
922 invocation returns. */
923 tmp_obstack = dont_print_vb_obstack;
924 /* Bump up the high-water mark. Now alpha is omega. */
925 obstack_finish (&dont_print_vb_obstack);
928 for (i = 0; i < n_baseclasses; i++)
931 struct type *baseclass = check_typedef (TYPE_BASECLASS (type, i));
932 char *basename = TYPE_NAME (baseclass);
935 if (BASETYPE_VIA_VIRTUAL (type, i))
937 struct type **first_dont_print
938 = (struct type **) obstack_base (&dont_print_vb_obstack);
940 int j = (struct type **) obstack_next_free (&dont_print_vb_obstack)
944 if (baseclass == first_dont_print[j])
947 obstack_ptr_grow (&dont_print_vb_obstack, baseclass);
950 boffset = baseclass_offset (type, i, valaddr, address);
954 fprintf_filtered (stream, "\n");
955 print_spaces_filtered (2 * recurse, stream);
957 fputs_filtered ("<", stream);
958 /* Not sure what the best notation is in the case where there is no
961 fputs_filtered (basename ? basename : "", stream);
962 fputs_filtered ("> = ", stream);
964 /* The virtual base class pointer might have been clobbered by the
965 user program. Make sure that it still points to a valid memory
968 if (boffset != -1 && (boffset < 0 || boffset >= TYPE_LENGTH (type)))
970 base_valaddr = (char *) alloca (TYPE_LENGTH (baseclass));
971 if (target_read_memory (address + boffset, base_valaddr,
972 TYPE_LENGTH (baseclass)) != 0)
976 base_valaddr = valaddr + boffset;
979 fprintf_filtered (stream, "<invalid address>");
981 pascal_object_print_value_fields (baseclass, base_valaddr, address + boffset,
982 stream, format, recurse, pretty,
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, TYPE, STREAM, RECURSE, and PRETTY
1009 have the same meanings as in c_val_print. */
1012 pascal_object_print_static_field (struct type *type, value_ptr val,
1013 struct ui_file *stream, int format,
1014 int recurse, enum val_prettyprint pretty)
1016 if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
1018 CORE_ADDR *first_dont_print;
1022 = (CORE_ADDR *) obstack_base (&dont_print_statmem_obstack);
1023 i = (CORE_ADDR *) obstack_next_free (&dont_print_statmem_obstack)
1028 if (VALUE_ADDRESS (val) == first_dont_print[i])
1030 fputs_filtered ("<same as static member of an already seen type>",
1036 obstack_grow (&dont_print_statmem_obstack, (char *) &VALUE_ADDRESS (val),
1037 sizeof (CORE_ADDR));
1039 CHECK_TYPEDEF (type);
1040 pascal_object_print_value_fields (type, VALUE_CONTENTS (val), VALUE_ADDRESS (val),
1041 stream, format, recurse, pretty, NULL, 1);
1044 val_print (type, VALUE_CONTENTS (val), 0, VALUE_ADDRESS (val),
1045 stream, format, 0, recurse, pretty);
1049 pascal_object_print_class_member (char *valaddr, struct type *domain,
1050 struct ui_file *stream, char *prefix)
1053 /* VAL is a byte offset into the structure type DOMAIN.
1054 Find the name of the field for that offset and
1058 register unsigned int i;
1059 unsigned len = TYPE_NFIELDS (domain);
1060 /* @@ Make VAL into bit offset */
1061 LONGEST val = unpack_long (builtin_type_int, valaddr) << 3;
1062 for (i = TYPE_N_BASECLASSES (domain); i < len; i++)
1064 int bitpos = TYPE_FIELD_BITPOS (domain, i);
1068 if (val < bitpos && i != 0)
1070 /* Somehow pointing into a field. */
1072 extra = (val - TYPE_FIELD_BITPOS (domain, i));
1083 fprintf_filtered (stream, prefix);
1084 name = type_name_no_tag (domain);
1086 fputs_filtered (name, stream);
1088 pascal_type_print_base (domain, stream, 0, 0);
1089 fprintf_filtered (stream, "::");
1090 fputs_filtered (TYPE_FIELD_NAME (domain, i), stream);
1092 fprintf_filtered (stream, " + %d bytes", extra);
1094 fprintf_filtered (stream, " (offset in bits)");
1097 fprintf_filtered (stream, "%ld", (long int) (val >> 3));
1102 _initialize_pascal_valprint (void)
1105 (add_set_cmd ("pascal_static-members", class_support, var_boolean,
1106 (char *) &pascal_static_field_print,
1107 "Set printing of pascal static members.",
1110 /* Turn on printing of static fields. */
1111 pascal_static_field_print = 1;