1 /* Support for printing Pascal values for GDB, the GNU debugger.
3 Copyright 2000, 2001, 2003, 2005 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 */
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 FORMAT (a letter or 0 for natural format). The data at VALADDR is in
50 If the data are a string pointer, returns the number of string characters
53 If DEREF_REF is nonzero, then dereference references, otherwise just print
56 The PRETTY parameter controls prettyprinting. */
60 pascal_val_print (struct type *type, const bfd_byte *valaddr,
61 int embedded_offset, CORE_ADDR address,
62 struct ui_file *stream, int format, int deref_ref,
63 int recurse, enum val_prettyprint pretty)
65 unsigned int i = 0; /* Number of characters printed */
69 int length_pos, length_size, string_pos;
75 switch (TYPE_CODE (type))
78 if (TYPE_LENGTH (type) > 0 && TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0)
80 elttype = check_typedef (TYPE_TARGET_TYPE (type));
81 eltlen = TYPE_LENGTH (elttype);
82 len = TYPE_LENGTH (type) / eltlen;
83 if (prettyprint_arrays)
85 print_spaces_filtered (2 + 2 * recurse, stream);
87 /* For an array of chars, print with string syntax. */
89 ((TYPE_CODE (elttype) == TYPE_CODE_INT)
90 || ((current_language->la_language == language_m2)
91 && (TYPE_CODE (elttype) == TYPE_CODE_CHAR)))
92 && (format == 0 || format == 's'))
94 /* If requested, look for the first null char and only print
96 if (stop_print_at_null)
98 unsigned int temp_len;
100 /* Look for a NULL char. */
102 (valaddr + embedded_offset)[temp_len]
103 && temp_len < len && temp_len < print_max;
108 LA_PRINT_STRING (stream, valaddr + embedded_offset, len, 1, 0);
113 fprintf_filtered (stream, "{");
114 /* If this is a virtual function table, print the 0th
115 entry specially, and the rest of the members normally. */
116 if (pascal_object_is_vtbl_ptr_type (elttype))
119 fprintf_filtered (stream, "%d vtable entries", len - 1);
125 val_print_array_elements (type, valaddr + embedded_offset, address, stream,
126 format, deref_ref, recurse, pretty, i);
127 fprintf_filtered (stream, "}");
131 /* Array of unspecified length: treat like pointer to first elt. */
133 goto print_unpacked_pointer;
136 if (format && format != 's')
138 print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream);
141 if (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 print_address_demangle (extract_unsigned_integer (valaddr + embedded_offset, TYPE_LENGTH (type)),
151 elttype = check_typedef (TYPE_TARGET_TYPE (type));
152 if (TYPE_CODE (elttype) == TYPE_CODE_METHOD)
154 pascal_object_print_class_method (valaddr + embedded_offset, type, stream);
156 else if (TYPE_CODE (elttype) == TYPE_CODE_MEMBER)
158 pascal_object_print_class_member (valaddr + embedded_offset,
159 TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (type)),
164 addr = unpack_pointer (type, valaddr + embedded_offset);
165 print_unpacked_pointer:
166 elttype = check_typedef (TYPE_TARGET_TYPE (type));
168 if (TYPE_CODE (elttype) == TYPE_CODE_FUNC)
170 /* Try to print what function it points to. */
171 print_address_demangle (addr, stream, demangle);
172 /* Return value is irrelevant except for string pointers. */
176 if (addressprint && format != 's')
178 print_address_numeric (addr, 1, stream);
181 /* For a pointer to char or unsigned char, also print the string
182 pointed to, unless pointer is null. */
183 if (TYPE_LENGTH (elttype) == 1
184 && TYPE_CODE (elttype) == TYPE_CODE_INT
185 && (format == 0 || format == 's')
188 /* no wide string yet */
189 i = val_print_string (addr, -1, 1, stream);
191 /* also for pointers to pascal strings */
192 /* Note: this is Free Pascal specific:
193 as GDB does not recognize stabs pascal strings
194 Pascal strings are mapped to records
195 with lowercase names PM */
196 if (is_pascal_string_type (elttype, &length_pos, &length_size,
197 &string_pos, &char_size, NULL)
200 ULONGEST string_length;
202 buffer = xmalloc (length_size);
203 read_memory (addr + length_pos, buffer, length_size);
204 string_length = extract_unsigned_integer (buffer, length_size);
206 i = val_print_string (addr + string_pos, string_length, char_size, stream);
208 else if (pascal_object_is_vtbl_member (type))
210 /* print vtbl's nicely */
211 CORE_ADDR vt_address = unpack_pointer (type, valaddr + embedded_offset);
213 struct minimal_symbol *msymbol =
214 lookup_minimal_symbol_by_pc (vt_address);
215 if ((msymbol != NULL)
216 && (vt_address == SYMBOL_VALUE_ADDRESS (msymbol)))
218 fputs_filtered (" <", stream);
219 fputs_filtered (SYMBOL_PRINT_NAME (msymbol), stream);
220 fputs_filtered (">", stream);
222 if (vt_address && vtblprint)
224 struct value *vt_val;
225 struct symbol *wsym = (struct symbol *) NULL;
227 struct block *block = (struct block *) NULL;
231 wsym = lookup_symbol (DEPRECATED_SYMBOL_NAME (msymbol), block,
232 VAR_DOMAIN, &is_this_fld, NULL);
236 wtype = SYMBOL_TYPE (wsym);
240 wtype = TYPE_TARGET_TYPE (type);
242 vt_val = value_at (wtype, vt_address);
243 val_print (value_type (vt_val), value_contents (vt_val), 0,
244 VALUE_ADDRESS (vt_val), stream, format,
245 deref_ref, recurse + 1, pretty);
248 fprintf_filtered (stream, "\n");
249 print_spaces_filtered (2 + 2 * recurse, stream);
254 /* Return number of characters printed, including the terminating
255 '\0' if we reached the end. val_print_string takes care including
256 the terminating '\0' if necessary. */
261 case TYPE_CODE_MEMBER:
262 error (_("not implemented: member type in pascal_val_print"));
266 elttype = check_typedef (TYPE_TARGET_TYPE (type));
267 if (TYPE_CODE (elttype) == TYPE_CODE_MEMBER)
269 pascal_object_print_class_member (valaddr + embedded_offset,
270 TYPE_DOMAIN_TYPE (elttype),
276 fprintf_filtered (stream, "@");
277 /* Extract the address, assume that it is unsigned. */
278 print_address_numeric
279 (extract_unsigned_integer (valaddr + embedded_offset,
280 TARGET_PTR_BIT / HOST_CHAR_BIT),
283 fputs_filtered (": ", stream);
285 /* De-reference the reference. */
288 if (TYPE_CODE (elttype) != TYPE_CODE_UNDEF)
290 struct value *deref_val =
292 (TYPE_TARGET_TYPE (type),
293 unpack_pointer (lookup_pointer_type (builtin_type_void),
294 valaddr + embedded_offset));
295 val_print (value_type (deref_val),
296 value_contents (deref_val), 0,
297 VALUE_ADDRESS (deref_val), stream, format,
298 deref_ref, recurse + 1, pretty);
301 fputs_filtered ("???", stream);
305 case TYPE_CODE_UNION:
306 if (recurse && !unionprint)
308 fprintf_filtered (stream, "{...}");
312 case TYPE_CODE_STRUCT:
313 if (vtblprint && pascal_object_is_vtbl_ptr_type (type))
315 /* Print the unmangled name if desired. */
316 /* Print vtable entry - we only get here if NOT using
317 -fvtable_thunks. (Otherwise, look under TYPE_CODE_PTR.) */
318 /* Extract the address, assume that it is unsigned. */
319 print_address_demangle
320 (extract_unsigned_integer (valaddr + embedded_offset + TYPE_FIELD_BITPOS (type, VTBL_FNADDR_OFFSET) / 8,
321 TYPE_LENGTH (TYPE_FIELD_TYPE (type, VTBL_FNADDR_OFFSET))),
326 if (is_pascal_string_type (type, &length_pos, &length_size,
327 &string_pos, &char_size, NULL))
329 len = extract_unsigned_integer (valaddr + embedded_offset + length_pos, length_size);
330 LA_PRINT_STRING (stream, valaddr + embedded_offset + string_pos, len, char_size, 0);
333 pascal_object_print_value_fields (type, valaddr + embedded_offset, address, stream, format,
334 recurse, pretty, NULL, 0);
341 print_scalar_formatted (valaddr + embedded_offset, type, format, 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);
367 print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream);
370 /* FIXME, we should consider, at least for ANSI C language, eliminating
371 the distinction made between FUNCs and POINTERs to FUNCs. */
372 fprintf_filtered (stream, "{");
373 type_print (type, "", stream, -1);
374 fprintf_filtered (stream, "} ");
375 /* Try to print what function it points to, and its address. */
376 print_address_demangle (address, stream, demangle);
380 format = format ? format : output_format;
382 print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream);
385 val = unpack_long (type, valaddr + embedded_offset);
387 fputs_filtered ("false", stream);
389 fputs_filtered ("true", stream);
392 fputs_filtered ("true (", stream);
393 fprintf_filtered (stream, "%ld)", (long int) val);
398 case TYPE_CODE_RANGE:
399 /* FIXME: create_range_type does not set the unsigned bit in a
400 range type (I think it probably should copy it from the target
401 type), so we won't print values which are too large to
402 fit in a signed integer correctly. */
403 /* FIXME: Doesn't handle ranges of enums correctly. (Can't just
404 print with the target type, though, because the size of our type
405 and the target type might differ). */
409 format = format ? format : output_format;
412 print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream);
416 val_print_type_code_int (type, valaddr + embedded_offset, stream);
421 format = format ? format : output_format;
424 print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream);
428 val = unpack_long (type, valaddr + embedded_offset);
429 if (TYPE_UNSIGNED (type))
430 fprintf_filtered (stream, "%u", (unsigned int) val);
432 fprintf_filtered (stream, "%d", (int) val);
433 fputs_filtered (" ", stream);
434 LA_PRINT_CHAR ((unsigned char) val, stream);
441 print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream);
445 print_floating (valaddr + embedded_offset, type, stream);
449 case TYPE_CODE_BITSTRING:
451 elttype = TYPE_INDEX_TYPE (type);
452 CHECK_TYPEDEF (elttype);
453 if (TYPE_STUB (elttype))
455 fprintf_filtered (stream, "<incomplete type>");
461 struct type *range = elttype;
462 LONGEST low_bound, high_bound;
464 int is_bitstring = TYPE_CODE (type) == TYPE_CODE_BITSTRING;
468 fputs_filtered ("B'", stream);
470 fputs_filtered ("[", stream);
472 i = get_discrete_bounds (range, &low_bound, &high_bound);
476 fputs_filtered ("<error value>", stream);
480 for (i = low_bound; i <= high_bound; i++)
482 int element = value_bit_index (type, valaddr + embedded_offset, i);
486 goto maybe_bad_bstring;
489 fprintf_filtered (stream, "%d", element);
493 fputs_filtered (", ", stream);
494 print_type_scalar (range, i, stream);
497 if (i + 1 <= high_bound && value_bit_index (type, valaddr + embedded_offset, ++i))
500 fputs_filtered ("..", stream);
501 while (i + 1 <= high_bound
502 && value_bit_index (type, valaddr + embedded_offset, ++i))
504 print_type_scalar (range, j, stream);
510 fputs_filtered ("'", stream);
512 fputs_filtered ("]", stream);
517 fprintf_filtered (stream, "void");
520 case TYPE_CODE_ERROR:
521 fprintf_filtered (stream, "<error type>");
524 case TYPE_CODE_UNDEF:
525 /* This happens (without TYPE_FLAG_STUB set) on systems which don't use
526 dbx xrefs (NO_DBX_XREFS in gcc) if a file has a "struct foo *bar"
527 and no complete type for struct foo in that file. */
528 fprintf_filtered (stream, "<incomplete type>");
532 error (_("Invalid pascal type code %d in symbol table."), TYPE_CODE (type));
539 pascal_value_print (struct value *val, struct ui_file *stream, int format,
540 enum val_prettyprint pretty)
542 struct type *type = value_type (val);
544 /* If it is a pointer, indicate what it points to.
546 Print type also if it is a reference.
548 Object pascal: if it is a member pointer, we will take care
549 of that when we print it. */
550 if (TYPE_CODE (type) == TYPE_CODE_PTR ||
551 TYPE_CODE (type) == TYPE_CODE_REF)
553 /* Hack: remove (char *) for char strings. Their
554 type is indicated by the quoted string anyway. */
555 if (TYPE_CODE (type) == TYPE_CODE_PTR &&
556 TYPE_NAME (type) == NULL &&
557 TYPE_NAME (TYPE_TARGET_TYPE (type)) != NULL
558 && strcmp (TYPE_NAME (TYPE_TARGET_TYPE (type)), "char") == 0)
564 fprintf_filtered (stream, "(");
565 type_print (type, "", stream, -1);
566 fprintf_filtered (stream, ") ");
569 return val_print (type, value_contents (val), value_embedded_offset (val),
570 VALUE_ADDRESS (val) + value_offset (val),
571 stream, format, 1, 0, pretty);
575 /******************************************************************************
576 Inserted from cp-valprint
577 ******************************************************************************/
579 extern int vtblprint; /* Controls printing of vtbl's */
580 extern int objectprint; /* Controls looking up an object's derived type
581 using what we find in its vtables. */
582 static int pascal_static_field_print; /* Controls printing of static fields. */
584 static struct obstack dont_print_vb_obstack;
585 static struct obstack dont_print_statmem_obstack;
587 static void pascal_object_print_static_field (struct type *, struct value *,
588 struct ui_file *, int, int,
589 enum val_prettyprint);
591 static void pascal_object_print_value (struct type *, const bfd_byte *,
592 CORE_ADDR, struct ui_file *,
593 int, int, enum val_prettyprint,
597 pascal_object_print_class_method (const bfd_byte *valaddr, struct type *type,
598 struct ui_file *stream)
601 struct fn_field *f = NULL;
610 struct type *target_type = check_typedef (TYPE_TARGET_TYPE (type));
612 domain = TYPE_DOMAIN_TYPE (target_type);
613 if (domain == (struct type *) NULL)
615 fprintf_filtered (stream, "<unknown>");
618 addr = unpack_pointer (lookup_pointer_type (builtin_type_void), valaddr);
619 if (METHOD_PTR_IS_VIRTUAL (addr))
621 offset = METHOD_PTR_TO_VOFFSET (addr);
622 len = TYPE_NFN_FIELDS (domain);
623 for (i = 0; i < len; i++)
625 f = TYPE_FN_FIELDLIST1 (domain, i);
626 len2 = TYPE_FN_FIELDLIST_LENGTH (domain, i);
628 check_stub_method_group (domain, i);
629 for (j = 0; j < len2; j++)
631 if (TYPE_FN_FIELD_VOFFSET (f, j) == offset)
641 sym = find_pc_function (addr);
644 error (_("invalid pointer to member function"));
646 len = TYPE_NFN_FIELDS (domain);
647 for (i = 0; i < len; i++)
649 f = TYPE_FN_FIELDLIST1 (domain, i);
650 len2 = TYPE_FN_FIELDLIST_LENGTH (domain, i);
652 check_stub_method_group (domain, i);
653 for (j = 0; j < len2; j++)
655 if (DEPRECATED_STREQ (DEPRECATED_SYMBOL_NAME (sym), TYPE_FN_FIELD_PHYSNAME (f, j)))
663 char *demangled_name;
665 fprintf_filtered (stream, "&");
666 fputs_filtered (kind, stream);
667 demangled_name = cplus_demangle (TYPE_FN_FIELD_PHYSNAME (f, j),
668 DMGL_ANSI | DMGL_PARAMS);
669 if (demangled_name == NULL)
670 fprintf_filtered (stream, "<badly mangled name %s>",
671 TYPE_FN_FIELD_PHYSNAME (f, j));
674 fputs_filtered (demangled_name, stream);
675 xfree (demangled_name);
680 fprintf_filtered (stream, "(");
681 type_print (type, "", stream, -1);
682 fprintf_filtered (stream, ") %d", (int) addr >> 3);
686 /* It was changed to this after 2.4.5. */
687 const char pascal_vtbl_ptr_name[] =
688 {'_', '_', 'v', 't', 'b', 'l', '_', 'p', 't', 'r', '_', 't', 'y', 'p', 'e', 0};
690 /* Return truth value for assertion that TYPE is of the type
691 "pointer to virtual function". */
694 pascal_object_is_vtbl_ptr_type (struct type *type)
696 char *typename = type_name_no_tag (type);
698 return (typename != NULL
699 && strcmp (typename, pascal_vtbl_ptr_name) == 0);
702 /* Return truth value for the assertion that TYPE is of the type
703 "pointer to virtual function table". */
706 pascal_object_is_vtbl_member (struct type *type)
708 if (TYPE_CODE (type) == TYPE_CODE_PTR)
710 type = TYPE_TARGET_TYPE (type);
711 if (TYPE_CODE (type) == TYPE_CODE_ARRAY)
713 type = TYPE_TARGET_TYPE (type);
714 if (TYPE_CODE (type) == TYPE_CODE_STRUCT /* if not using thunks */
715 || TYPE_CODE (type) == TYPE_CODE_PTR) /* if using thunks */
717 /* Virtual functions tables are full of pointers
718 to virtual functions. */
719 return pascal_object_is_vtbl_ptr_type (type);
726 /* Mutually recursive subroutines of pascal_object_print_value and
727 c_val_print to print out a structure's fields:
728 pascal_object_print_value_fields and pascal_object_print_value.
730 TYPE, VALADDR, ADDRESS, STREAM, RECURSE, and PRETTY have the
731 same meanings as in pascal_object_print_value and c_val_print.
733 DONT_PRINT is an array of baseclass types that we
734 should not print, or zero if called from top level. */
737 pascal_object_print_value_fields (struct type *type, const bfd_byte *valaddr,
738 CORE_ADDR address, struct ui_file *stream,
739 int format, int recurse,
740 enum val_prettyprint pretty,
741 struct type **dont_print_vb,
742 int dont_print_statmem)
744 int i, len, n_baseclasses;
745 struct obstack tmp_obstack;
746 char *last_dont_print = obstack_next_free (&dont_print_statmem_obstack);
748 CHECK_TYPEDEF (type);
750 fprintf_filtered (stream, "{");
751 len = TYPE_NFIELDS (type);
752 n_baseclasses = TYPE_N_BASECLASSES (type);
754 /* Print out baseclasses such that we don't print
755 duplicates of virtual baseclasses. */
756 if (n_baseclasses > 0)
757 pascal_object_print_value (type, valaddr, address, stream,
758 format, recurse + 1, pretty, dont_print_vb);
760 if (!len && n_baseclasses == 1)
761 fprintf_filtered (stream, "<No data fields>");
766 if (dont_print_statmem == 0)
768 /* If we're at top level, carve out a completely fresh
769 chunk of the obstack and use that until this particular
770 invocation returns. */
771 tmp_obstack = dont_print_statmem_obstack;
772 obstack_finish (&dont_print_statmem_obstack);
775 for (i = n_baseclasses; i < len; i++)
777 /* If requested, skip printing of static fields. */
778 if (!pascal_static_field_print && TYPE_FIELD_STATIC (type, i))
781 fprintf_filtered (stream, ", ");
782 else if (n_baseclasses > 0)
786 fprintf_filtered (stream, "\n");
787 print_spaces_filtered (2 + 2 * recurse, stream);
788 fputs_filtered ("members of ", stream);
789 fputs_filtered (type_name_no_tag (type), stream);
790 fputs_filtered (": ", stream);
797 fprintf_filtered (stream, "\n");
798 print_spaces_filtered (2 + 2 * recurse, stream);
802 wrap_here (n_spaces (2 + 2 * recurse));
806 if (TYPE_CODE (TYPE_FIELD_TYPE (type, i)) == TYPE_CODE_PTR)
807 fputs_filtered ("\"( ptr \"", stream);
809 fputs_filtered ("\"( nodef \"", stream);
810 if (TYPE_FIELD_STATIC (type, i))
811 fputs_filtered ("static ", stream);
812 fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i),
814 DMGL_PARAMS | DMGL_ANSI);
815 fputs_filtered ("\" \"", stream);
816 fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i),
818 DMGL_PARAMS | DMGL_ANSI);
819 fputs_filtered ("\") \"", stream);
823 annotate_field_begin (TYPE_FIELD_TYPE (type, i));
825 if (TYPE_FIELD_STATIC (type, i))
826 fputs_filtered ("static ", stream);
827 fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i),
829 DMGL_PARAMS | DMGL_ANSI);
830 annotate_field_name_end ();
831 fputs_filtered (" = ", stream);
832 annotate_field_value ();
835 if (!TYPE_FIELD_STATIC (type, i) && TYPE_FIELD_PACKED (type, i))
839 /* Bitfields require special handling, especially due to byte
841 if (TYPE_FIELD_IGNORE (type, i))
843 fputs_filtered ("<optimized out or zero length>", stream);
847 v = value_from_longest (TYPE_FIELD_TYPE (type, i),
848 unpack_field_as_long (type, valaddr, i));
850 val_print (TYPE_FIELD_TYPE (type, i), value_contents (v), 0, 0,
851 stream, format, 0, recurse + 1, pretty);
856 if (TYPE_FIELD_IGNORE (type, i))
858 fputs_filtered ("<optimized out or zero length>", stream);
860 else if (TYPE_FIELD_STATIC (type, i))
862 /* struct value *v = value_static_field (type, i); v4.17 specific */
864 v = value_from_longest (TYPE_FIELD_TYPE (type, i),
865 unpack_field_as_long (type, valaddr, i));
868 fputs_filtered ("<optimized out>", stream);
870 pascal_object_print_static_field (TYPE_FIELD_TYPE (type, i), v,
871 stream, format, recurse + 1,
876 /* val_print (TYPE_FIELD_TYPE (type, i),
877 valaddr + TYPE_FIELD_BITPOS (type, i) / 8,
878 address + TYPE_FIELD_BITPOS (type, i) / 8, 0,
879 stream, format, 0, recurse + 1, pretty); */
880 val_print (TYPE_FIELD_TYPE (type, i),
881 valaddr, TYPE_FIELD_BITPOS (type, i) / 8,
882 address + TYPE_FIELD_BITPOS (type, i) / 8,
883 stream, format, 0, recurse + 1, pretty);
886 annotate_field_end ();
889 if (dont_print_statmem == 0)
891 /* Free the space used to deal with the printing
892 of the members from top level. */
893 obstack_free (&dont_print_statmem_obstack, last_dont_print);
894 dont_print_statmem_obstack = tmp_obstack;
899 fprintf_filtered (stream, "\n");
900 print_spaces_filtered (2 * recurse, stream);
903 fprintf_filtered (stream, "}");
906 /* Special val_print routine to avoid printing multiple copies of virtual
910 pascal_object_print_value (struct type *type, const bfd_byte *valaddr,
911 CORE_ADDR address, struct ui_file *stream,
912 int format, int recurse,
913 enum val_prettyprint pretty,
914 struct type **dont_print_vb)
916 struct obstack tmp_obstack;
917 struct type **last_dont_print
918 = (struct type **) obstack_next_free (&dont_print_vb_obstack);
919 int i, n_baseclasses = TYPE_N_BASECLASSES (type);
921 if (dont_print_vb == 0)
923 /* If we're at top level, carve out a completely fresh
924 chunk of the obstack and use that until this particular
925 invocation returns. */
926 tmp_obstack = dont_print_vb_obstack;
927 /* Bump up the high-water mark. Now alpha is omega. */
928 obstack_finish (&dont_print_vb_obstack);
931 for (i = 0; i < n_baseclasses; i++)
934 struct type *baseclass = check_typedef (TYPE_BASECLASS (type, i));
935 char *basename = TYPE_NAME (baseclass);
936 const bfd_byte *base_valaddr;
938 if (BASETYPE_VIA_VIRTUAL (type, i))
940 struct type **first_dont_print
941 = (struct type **) obstack_base (&dont_print_vb_obstack);
943 int j = (struct type **) obstack_next_free (&dont_print_vb_obstack)
947 if (baseclass == first_dont_print[j])
950 obstack_ptr_grow (&dont_print_vb_obstack, baseclass);
953 boffset = baseclass_offset (type, i, valaddr, address);
957 fprintf_filtered (stream, "\n");
958 print_spaces_filtered (2 * recurse, stream);
960 fputs_filtered ("<", stream);
961 /* Not sure what the best notation is in the case where there is no
964 fputs_filtered (basename ? basename : "", stream);
965 fputs_filtered ("> = ", stream);
967 /* The virtual base class pointer might have been clobbered by the
968 user program. Make sure that it still points to a valid memory
971 if (boffset != -1 && (boffset < 0 || boffset >= TYPE_LENGTH (type)))
973 /* FIXME (alloc): not safe is baseclass is really really big. */
974 bfd_byte *buf = alloca (TYPE_LENGTH (baseclass));
976 if (target_read_memory (address + boffset, buf,
977 TYPE_LENGTH (baseclass)) != 0)
981 base_valaddr = valaddr + boffset;
984 fprintf_filtered (stream, "<invalid address>");
986 pascal_object_print_value_fields (baseclass, base_valaddr, address + boffset,
987 stream, format, recurse, pretty,
988 (struct type **) obstack_base (&dont_print_vb_obstack),
990 fputs_filtered (", ", stream);
996 if (dont_print_vb == 0)
998 /* Free the space used to deal with the printing
999 of this type from top level. */
1000 obstack_free (&dont_print_vb_obstack, last_dont_print);
1001 /* Reset watermark so that we can continue protecting
1002 ourselves from whatever we were protecting ourselves. */
1003 dont_print_vb_obstack = tmp_obstack;
1007 /* Print value of a static member.
1008 To avoid infinite recursion when printing a class that contains
1009 a static instance of the class, we keep the addresses of all printed
1010 static member classes in an obstack and refuse to print them more
1013 VAL contains the value to print, TYPE, STREAM, RECURSE, and PRETTY
1014 have the same meanings as in c_val_print. */
1017 pascal_object_print_static_field (struct type *type, struct value *val,
1018 struct ui_file *stream, int format,
1019 int recurse, enum val_prettyprint pretty)
1021 if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
1023 CORE_ADDR *first_dont_print;
1027 = (CORE_ADDR *) obstack_base (&dont_print_statmem_obstack);
1028 i = (CORE_ADDR *) obstack_next_free (&dont_print_statmem_obstack)
1033 if (VALUE_ADDRESS (val) == first_dont_print[i])
1035 fputs_filtered ("<same as static member of an already seen type>",
1041 obstack_grow (&dont_print_statmem_obstack, (char *) &VALUE_ADDRESS (val),
1042 sizeof (CORE_ADDR));
1044 CHECK_TYPEDEF (type);
1045 pascal_object_print_value_fields (type, value_contents (val), VALUE_ADDRESS (val),
1046 stream, format, recurse, pretty, NULL, 1);
1049 val_print (type, value_contents (val), 0, VALUE_ADDRESS (val),
1050 stream, format, 0, recurse, pretty);
1054 pascal_object_print_class_member (const bfd_byte *valaddr, struct type *domain,
1055 struct ui_file *stream, char *prefix)
1058 /* VAL is a byte offset into the structure type DOMAIN.
1059 Find the name of the field for that offset and
1064 unsigned len = TYPE_NFIELDS (domain);
1065 /* @@ Make VAL into bit offset */
1066 LONGEST val = unpack_long (builtin_type_int, valaddr) << 3;
1067 for (i = TYPE_N_BASECLASSES (domain); i < len; i++)
1069 int bitpos = TYPE_FIELD_BITPOS (domain, i);
1073 if (val < bitpos && i != 0)
1075 /* Somehow pointing into a field. */
1077 extra = (val - TYPE_FIELD_BITPOS (domain, i));
1088 fputs_filtered (prefix, stream);
1089 name = type_name_no_tag (domain);
1091 fputs_filtered (name, stream);
1093 pascal_type_print_base (domain, stream, 0, 0);
1094 fprintf_filtered (stream, "::");
1095 fputs_filtered (TYPE_FIELD_NAME (domain, i), stream);
1097 fprintf_filtered (stream, " + %d bytes", extra);
1099 fprintf_filtered (stream, " (offset in bits)");
1102 fprintf_filtered (stream, "%ld", (long int) (val >> 3));
1105 extern initialize_file_ftype _initialize_pascal_valprint; /* -Wmissing-prototypes */
1108 _initialize_pascal_valprint (void)
1110 deprecated_add_show_from_set
1111 (add_set_cmd ("pascal_static-members", class_support, var_boolean,
1112 (char *) &pascal_static_field_print,
1113 "Set printing of pascal static members.",
1116 /* Turn on printing of static fields. */
1117 pascal_static_field_print = 1;