1 /* Support for printing Pascal values for GDB, the GNU debugger.
3 Copyright (C) 2000, 2001, 2003, 2005, 2006, 2007, 2008, 2009, 2010
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
, address
, stream
,
129 recurse
, original_value
, options
, i
);
130 fprintf_filtered (stream
, "}");
134 /* Array of unspecified length: treat like pointer to first elt. */
136 goto print_unpacked_pointer
;
139 if (options
->format
&& options
->format
!= 's')
141 print_scalar_formatted (valaddr
+ embedded_offset
, type
,
145 if (options
->vtblprint
&& pascal_object_is_vtbl_ptr_type (type
))
147 /* Print the unmangled name if desired. */
148 /* Print vtable entry - we only get here if we ARE using
149 -fvtable_thunks. (Otherwise, look under TYPE_CODE_STRUCT.) */
150 /* Extract the address, assume that it is unsigned. */
151 addr
= extract_unsigned_integer (valaddr
+ embedded_offset
,
152 TYPE_LENGTH (type
), byte_order
);
153 print_address_demangle (gdbarch
, addr
, stream
, demangle
);
156 elttype
= check_typedef (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 (gdbarch
, addr
, stream
, demangle
);
166 /* Return value is irrelevant except for string pointers. */
170 if (options
->addressprint
&& options
->format
!= 's')
172 fputs_filtered (paddress (gdbarch
, addr
), 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 || TYPE_CODE (elttype
) == TYPE_CODE_CHAR
))
180 || ((TYPE_LENGTH (elttype
) == 2 || TYPE_LENGTH (elttype
) == 4)
181 && TYPE_CODE (elttype
) == TYPE_CODE_CHAR
))
182 && (options
->format
== 0 || options
->format
== 's')
185 /* no wide string yet */
186 i
= val_print_string (elttype
, NULL
, addr
, -1, stream
, options
);
188 /* also for pointers to pascal strings */
189 /* Note: this is Free Pascal specific:
190 as GDB does not recognize stabs pascal strings
191 Pascal strings are mapped to records
192 with lowercase names PM */
193 if (is_pascal_string_type (elttype
, &length_pos
, &length_size
,
194 &string_pos
, &char_type
, NULL
)
197 ULONGEST string_length
;
200 buffer
= xmalloc (length_size
);
201 read_memory (addr
+ length_pos
, buffer
, length_size
);
202 string_length
= extract_unsigned_integer (buffer
, length_size
,
205 i
= val_print_string (char_type
, NULL
,
206 addr
+ string_pos
, string_length
,
209 else if (pascal_object_is_vtbl_member (type
))
211 /* print vtbl's nicely */
212 CORE_ADDR vt_address
= unpack_pointer (type
, valaddr
+ embedded_offset
);
213 struct minimal_symbol
*msymbol
=
214 lookup_minimal_symbol_by_pc (vt_address
);
216 if ((msymbol
!= NULL
)
217 && (vt_address
== SYMBOL_VALUE_ADDRESS (msymbol
)))
219 fputs_filtered (" <", stream
);
220 fputs_filtered (SYMBOL_PRINT_NAME (msymbol
), stream
);
221 fputs_filtered (">", stream
);
223 if (vt_address
&& options
->vtblprint
)
225 struct value
*vt_val
;
226 struct symbol
*wsym
= (struct symbol
*) NULL
;
228 struct block
*block
= (struct block
*) NULL
;
232 wsym
= lookup_symbol (SYMBOL_LINKAGE_NAME (msymbol
), block
,
233 VAR_DOMAIN
, &is_this_fld
);
237 wtype
= SYMBOL_TYPE (wsym
);
241 wtype
= TYPE_TARGET_TYPE (type
);
243 vt_val
= value_at (wtype
, vt_address
);
244 common_val_print (vt_val
, stream
, recurse
+ 1, options
,
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. */
262 elttype
= check_typedef (TYPE_TARGET_TYPE (type
));
263 if (options
->addressprint
)
266 = extract_typed_address (valaddr
+ embedded_offset
, type
);
268 fprintf_filtered (stream
, "@");
269 fputs_filtered (paddress (gdbarch
, addr
), stream
);
270 if (options
->deref_ref
)
271 fputs_filtered (": ", stream
);
273 /* De-reference the reference. */
274 if (options
->deref_ref
)
276 if (TYPE_CODE (elttype
) != TYPE_CODE_UNDEF
)
278 struct value
*deref_val
=
280 (TYPE_TARGET_TYPE (type
),
281 unpack_pointer (type
, valaddr
+ embedded_offset
));
283 common_val_print (deref_val
, stream
, recurse
+ 1, options
,
287 fputs_filtered ("???", stream
);
291 case TYPE_CODE_UNION
:
292 if (recurse
&& !options
->unionprint
)
294 fprintf_filtered (stream
, "{...}");
298 case TYPE_CODE_STRUCT
:
299 if (options
->vtblprint
&& pascal_object_is_vtbl_ptr_type (type
))
301 /* Print the unmangled name if desired. */
302 /* Print vtable entry - we only get here if NOT using
303 -fvtable_thunks. (Otherwise, look under TYPE_CODE_PTR.) */
304 /* Extract the address, assume that it is unsigned. */
305 print_address_demangle
307 extract_unsigned_integer (valaddr
+ embedded_offset
+ TYPE_FIELD_BITPOS (type
, VTBL_FNADDR_OFFSET
) / 8,
308 TYPE_LENGTH (TYPE_FIELD_TYPE (type
, VTBL_FNADDR_OFFSET
)), byte_order
),
313 if (is_pascal_string_type (type
, &length_pos
, &length_size
,
314 &string_pos
, &char_type
, NULL
))
316 len
= extract_unsigned_integer (valaddr
+ embedded_offset
+ length_pos
, length_size
, byte_order
);
317 LA_PRINT_STRING (stream
, char_type
,
318 valaddr
+ embedded_offset
+ string_pos
,
319 len
, NULL
, 0, options
);
322 pascal_object_print_value_fields (type
, valaddr
+ embedded_offset
, address
, stream
,
323 recurse
, original_value
, options
, NULL
, 0);
330 print_scalar_formatted (valaddr
+ embedded_offset
, type
,
334 len
= TYPE_NFIELDS (type
);
335 val
= unpack_long (type
, valaddr
+ embedded_offset
);
336 for (i
= 0; i
< len
; i
++)
339 if (val
== TYPE_FIELD_BITPOS (type
, i
))
346 fputs_filtered (TYPE_FIELD_NAME (type
, i
), stream
);
350 print_longest (stream
, 'd', 0, val
);
354 case TYPE_CODE_FLAGS
:
356 print_scalar_formatted (valaddr
+ embedded_offset
, type
,
359 val_print_type_code_flags (type
, valaddr
+ embedded_offset
, stream
);
365 print_scalar_formatted (valaddr
+ embedded_offset
, type
,
369 /* FIXME, we should consider, at least for ANSI C language, eliminating
370 the distinction made between FUNCs and POINTERs to FUNCs. */
371 fprintf_filtered (stream
, "{");
372 type_print (type
, "", stream
, -1);
373 fprintf_filtered (stream
, "} ");
374 /* Try to print what function it points to, and its address. */
375 print_address_demangle (gdbarch
, address
, stream
, demangle
);
379 if (options
->format
|| options
->output_format
)
381 struct value_print_options opts
= *options
;
383 opts
.format
= (options
->format
? options
->format
384 : options
->output_format
);
385 print_scalar_formatted (valaddr
+ embedded_offset
, type
,
390 val
= unpack_long (type
, valaddr
+ embedded_offset
);
392 fputs_filtered ("false", stream
);
394 fputs_filtered ("true", stream
);
397 fputs_filtered ("true (", stream
);
398 fprintf_filtered (stream
, "%ld)", (long int) val
);
403 case TYPE_CODE_RANGE
:
404 /* FIXME: create_range_type does not set the unsigned bit in a
405 range type (I think it probably should copy it from the target
406 type), so we won't print values which are too large to
407 fit in a signed integer correctly. */
408 /* FIXME: Doesn't handle ranges of enums correctly. (Can't just
409 print with the target type, though, because the size of our type
410 and the target type might differ). */
414 if (options
->format
|| options
->output_format
)
416 struct value_print_options opts
= *options
;
418 opts
.format
= (options
->format
? options
->format
419 : options
->output_format
);
420 print_scalar_formatted (valaddr
+ embedded_offset
, type
,
425 val_print_type_code_int (type
, valaddr
+ embedded_offset
, stream
);
430 if (options
->format
|| options
->output_format
)
432 struct value_print_options opts
= *options
;
434 opts
.format
= (options
->format
? options
->format
435 : options
->output_format
);
436 print_scalar_formatted (valaddr
+ embedded_offset
, type
,
441 val
= unpack_long (type
, valaddr
+ embedded_offset
);
442 if (TYPE_UNSIGNED (type
))
443 fprintf_filtered (stream
, "%u", (unsigned int) val
);
445 fprintf_filtered (stream
, "%d", (int) val
);
446 fputs_filtered (" ", stream
);
447 LA_PRINT_CHAR ((unsigned char) val
, type
, stream
);
454 print_scalar_formatted (valaddr
+ embedded_offset
, type
,
459 print_floating (valaddr
+ embedded_offset
, type
, stream
);
463 case TYPE_CODE_BITSTRING
:
465 elttype
= TYPE_INDEX_TYPE (type
);
466 CHECK_TYPEDEF (elttype
);
467 if (TYPE_STUB (elttype
))
469 fprintf_filtered (stream
, "<incomplete type>");
475 struct type
*range
= elttype
;
476 LONGEST low_bound
, high_bound
;
478 int is_bitstring
= TYPE_CODE (type
) == TYPE_CODE_BITSTRING
;
482 fputs_filtered ("B'", stream
);
484 fputs_filtered ("[", stream
);
486 i
= get_discrete_bounds (range
, &low_bound
, &high_bound
);
487 if (low_bound
== 0 && high_bound
== -1 && TYPE_LENGTH (type
) > 0)
489 /* If we know the size of the set type, we can figure out the
492 high_bound
= TYPE_LENGTH (type
) * TARGET_CHAR_BIT
- 1;
493 TYPE_HIGH_BOUND (range
) = high_bound
;
498 fputs_filtered ("<error value>", stream
);
502 for (i
= low_bound
; i
<= high_bound
; i
++)
504 int element
= value_bit_index (type
, valaddr
+ embedded_offset
, i
);
509 goto maybe_bad_bstring
;
512 fprintf_filtered (stream
, "%d", element
);
516 fputs_filtered (", ", stream
);
517 print_type_scalar (range
, i
, stream
);
520 if (i
+ 1 <= high_bound
&& value_bit_index (type
, valaddr
+ embedded_offset
, ++i
))
524 fputs_filtered ("..", stream
);
525 while (i
+ 1 <= high_bound
526 && value_bit_index (type
, valaddr
+ embedded_offset
, ++i
))
528 print_type_scalar (range
, j
, stream
);
534 fputs_filtered ("'", stream
);
536 fputs_filtered ("]", stream
);
541 fprintf_filtered (stream
, "void");
544 case TYPE_CODE_ERROR
:
545 fprintf_filtered (stream
, "%s", TYPE_ERROR_NAME (type
));
548 case TYPE_CODE_UNDEF
:
549 /* This happens (without TYPE_FLAG_STUB set) on systems which don't use
550 dbx xrefs (NO_DBX_XREFS in gcc) if a file has a "struct foo *bar"
551 and no complete type for struct foo in that file. */
552 fprintf_filtered (stream
, "<incomplete type>");
556 error (_("Invalid pascal type code %d in symbol table."), TYPE_CODE (type
));
563 pascal_value_print (struct value
*val
, struct ui_file
*stream
,
564 const struct value_print_options
*options
)
566 struct type
*type
= value_type (val
);
567 struct value_print_options opts
= *options
;
571 /* If it is a pointer, indicate what it points to.
573 Print type also if it is a reference.
575 Object pascal: if it is a member pointer, we will take care
576 of that when we print it. */
577 if (TYPE_CODE (type
) == TYPE_CODE_PTR
578 || TYPE_CODE (type
) == TYPE_CODE_REF
)
580 /* Hack: remove (char *) for char strings. Their
581 type is indicated by the quoted string anyway. */
582 if (TYPE_CODE (type
) == TYPE_CODE_PTR
583 && TYPE_NAME (type
) == NULL
584 && TYPE_NAME (TYPE_TARGET_TYPE (type
)) != NULL
585 && strcmp (TYPE_NAME (TYPE_TARGET_TYPE (type
)), "char") == 0)
591 fprintf_filtered (stream
, "(");
592 type_print (type
, "", stream
, -1);
593 fprintf_filtered (stream
, ") ");
596 return common_val_print (val
, stream
, 0, &opts
, current_language
);
601 show_pascal_static_field_print (struct ui_file
*file
, int from_tty
,
602 struct cmd_list_element
*c
, const char *value
)
604 fprintf_filtered (file
, _("Printing of pascal static members is %s.\n"),
608 static struct obstack dont_print_vb_obstack
;
609 static struct obstack dont_print_statmem_obstack
;
611 static void pascal_object_print_static_field (struct value
*,
612 struct ui_file
*, int,
613 const struct value_print_options
*);
615 static void pascal_object_print_value (struct type
*, const gdb_byte
*,
616 CORE_ADDR
, struct ui_file
*, int,
617 const struct value
*,
618 const struct value_print_options
*,
621 /* It was changed to this after 2.4.5. */
622 const char pascal_vtbl_ptr_name
[] =
623 {'_', '_', 'v', 't', 'b', 'l', '_', 'p', 't', 'r', '_', 't', 'y', 'p', 'e', 0};
625 /* Return truth value for assertion that TYPE is of the type
626 "pointer to virtual function". */
629 pascal_object_is_vtbl_ptr_type (struct type
*type
)
631 char *typename
= type_name_no_tag (type
);
633 return (typename
!= NULL
634 && strcmp (typename
, pascal_vtbl_ptr_name
) == 0);
637 /* Return truth value for the assertion that TYPE is of the type
638 "pointer to virtual function table". */
641 pascal_object_is_vtbl_member (struct type
*type
)
643 if (TYPE_CODE (type
) == TYPE_CODE_PTR
)
645 type
= TYPE_TARGET_TYPE (type
);
646 if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
)
648 type
= TYPE_TARGET_TYPE (type
);
649 if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
/* if not using thunks */
650 || TYPE_CODE (type
) == TYPE_CODE_PTR
) /* if using thunks */
652 /* Virtual functions tables are full of pointers
653 to virtual functions. */
654 return pascal_object_is_vtbl_ptr_type (type
);
661 /* Mutually recursive subroutines of pascal_object_print_value and
662 c_val_print to print out a structure's fields:
663 pascal_object_print_value_fields and pascal_object_print_value.
665 TYPE, VALADDR, ADDRESS, STREAM, RECURSE, and OPTIONS have the
666 same meanings as in pascal_object_print_value and c_val_print.
668 DONT_PRINT is an array of baseclass types that we
669 should not print, or zero if called from top level. */
672 pascal_object_print_value_fields (struct type
*type
, const gdb_byte
*valaddr
,
673 CORE_ADDR address
, struct ui_file
*stream
,
675 const struct value
*val
,
676 const struct value_print_options
*options
,
677 struct type
**dont_print_vb
,
678 int dont_print_statmem
)
680 int i
, len
, n_baseclasses
;
681 char *last_dont_print
= obstack_next_free (&dont_print_statmem_obstack
);
683 CHECK_TYPEDEF (type
);
685 fprintf_filtered (stream
, "{");
686 len
= TYPE_NFIELDS (type
);
687 n_baseclasses
= TYPE_N_BASECLASSES (type
);
689 /* Print out baseclasses such that we don't print
690 duplicates of virtual baseclasses. */
691 if (n_baseclasses
> 0)
692 pascal_object_print_value (type
, valaddr
, address
, stream
,
693 recurse
+ 1, val
, options
, dont_print_vb
);
695 if (!len
&& n_baseclasses
== 1)
696 fprintf_filtered (stream
, "<No data fields>");
699 struct obstack tmp_obstack
= dont_print_statmem_obstack
;
702 if (dont_print_statmem
== 0)
704 /* If we're at top level, carve out a completely fresh
705 chunk of the obstack and use that until this particular
706 invocation returns. */
707 obstack_finish (&dont_print_statmem_obstack
);
710 for (i
= n_baseclasses
; i
< len
; i
++)
712 /* If requested, skip printing of static fields. */
713 if (!options
->pascal_static_field_print
714 && field_is_static (&TYPE_FIELD (type
, i
)))
717 fprintf_filtered (stream
, ", ");
718 else if (n_baseclasses
> 0)
722 fprintf_filtered (stream
, "\n");
723 print_spaces_filtered (2 + 2 * recurse
, stream
);
724 fputs_filtered ("members of ", stream
);
725 fputs_filtered (type_name_no_tag (type
), stream
);
726 fputs_filtered (": ", stream
);
733 fprintf_filtered (stream
, "\n");
734 print_spaces_filtered (2 + 2 * recurse
, stream
);
738 wrap_here (n_spaces (2 + 2 * recurse
));
740 if (options
->inspect_it
)
742 if (TYPE_CODE (TYPE_FIELD_TYPE (type
, i
)) == TYPE_CODE_PTR
)
743 fputs_filtered ("\"( ptr \"", stream
);
745 fputs_filtered ("\"( nodef \"", stream
);
746 if (field_is_static (&TYPE_FIELD (type
, i
)))
747 fputs_filtered ("static ", stream
);
748 fprintf_symbol_filtered (stream
, TYPE_FIELD_NAME (type
, i
),
750 DMGL_PARAMS
| DMGL_ANSI
);
751 fputs_filtered ("\" \"", stream
);
752 fprintf_symbol_filtered (stream
, TYPE_FIELD_NAME (type
, i
),
754 DMGL_PARAMS
| DMGL_ANSI
);
755 fputs_filtered ("\") \"", stream
);
759 annotate_field_begin (TYPE_FIELD_TYPE (type
, i
));
761 if (field_is_static (&TYPE_FIELD (type
, i
)))
762 fputs_filtered ("static ", stream
);
763 fprintf_symbol_filtered (stream
, TYPE_FIELD_NAME (type
, i
),
765 DMGL_PARAMS
| DMGL_ANSI
);
766 annotate_field_name_end ();
767 fputs_filtered (" = ", stream
);
768 annotate_field_value ();
771 if (!field_is_static (&TYPE_FIELD (type
, i
))
772 && TYPE_FIELD_PACKED (type
, i
))
776 /* Bitfields require special handling, especially due to byte
778 if (TYPE_FIELD_IGNORE (type
, i
))
780 fputs_filtered ("<optimized out or zero length>", stream
);
782 else if (!value_bits_valid (val
, TYPE_FIELD_BITPOS (type
, i
),
783 TYPE_FIELD_BITSIZE (type
, i
)))
785 fputs_filtered (_("<value optimized out>"), stream
);
789 struct value_print_options opts
= *options
;
791 v
= value_from_longest (TYPE_FIELD_TYPE (type
, i
),
792 unpack_field_as_long (type
, valaddr
, i
));
795 common_val_print (v
, stream
, recurse
+ 1, &opts
,
801 if (TYPE_FIELD_IGNORE (type
, i
))
803 fputs_filtered ("<optimized out or zero length>", stream
);
805 else if (field_is_static (&TYPE_FIELD (type
, i
)))
807 /* struct value *v = value_static_field (type, i); v4.17 specific */
810 v
= value_from_longest (TYPE_FIELD_TYPE (type
, i
),
811 unpack_field_as_long (type
, valaddr
, i
));
814 fputs_filtered ("<optimized out>", stream
);
816 pascal_object_print_static_field (v
, stream
, recurse
+ 1,
821 struct value_print_options opts
= *options
;
824 /* val_print (TYPE_FIELD_TYPE (type, i),
825 valaddr + TYPE_FIELD_BITPOS (type, i) / 8,
826 address + TYPE_FIELD_BITPOS (type, i) / 8, 0,
827 stream, format, 0, recurse + 1, pretty); */
828 val_print (TYPE_FIELD_TYPE (type
, i
),
829 valaddr
, TYPE_FIELD_BITPOS (type
, i
) / 8,
830 address
+ TYPE_FIELD_BITPOS (type
, i
) / 8,
831 stream
, recurse
+ 1, val
, &opts
,
835 annotate_field_end ();
838 if (dont_print_statmem
== 0)
840 /* Free the space used to deal with the printing
841 of the members from top level. */
842 obstack_free (&dont_print_statmem_obstack
, last_dont_print
);
843 dont_print_statmem_obstack
= tmp_obstack
;
848 fprintf_filtered (stream
, "\n");
849 print_spaces_filtered (2 * recurse
, stream
);
852 fprintf_filtered (stream
, "}");
855 /* Special val_print routine to avoid printing multiple copies of virtual
859 pascal_object_print_value (struct type
*type
, const gdb_byte
*valaddr
,
860 CORE_ADDR address
, struct ui_file
*stream
,
862 const struct value
*val
,
863 const struct value_print_options
*options
,
864 struct type
**dont_print_vb
)
866 struct type
**last_dont_print
867 = (struct type
**) obstack_next_free (&dont_print_vb_obstack
);
868 struct obstack tmp_obstack
= dont_print_vb_obstack
;
869 int i
, n_baseclasses
= TYPE_N_BASECLASSES (type
);
871 if (dont_print_vb
== 0)
873 /* If we're at top level, carve out a completely fresh
874 chunk of the obstack and use that until this particular
875 invocation returns. */
876 /* Bump up the high-water mark. Now alpha is omega. */
877 obstack_finish (&dont_print_vb_obstack
);
880 for (i
= 0; i
< n_baseclasses
; i
++)
883 struct type
*baseclass
= check_typedef (TYPE_BASECLASS (type
, i
));
884 char *basename
= type_name_no_tag (baseclass
);
885 const gdb_byte
*base_valaddr
;
887 if (BASETYPE_VIA_VIRTUAL (type
, i
))
889 struct type
**first_dont_print
890 = (struct type
**) obstack_base (&dont_print_vb_obstack
);
892 int j
= (struct type
**) obstack_next_free (&dont_print_vb_obstack
)
896 if (baseclass
== first_dont_print
[j
])
899 obstack_ptr_grow (&dont_print_vb_obstack
, baseclass
);
902 boffset
= baseclass_offset (type
, i
, valaddr
, address
);
906 fprintf_filtered (stream
, "\n");
907 print_spaces_filtered (2 * recurse
, stream
);
909 fputs_filtered ("<", stream
);
910 /* Not sure what the best notation is in the case where there is no
913 fputs_filtered (basename
? basename
: "", stream
);
914 fputs_filtered ("> = ", stream
);
916 /* The virtual base class pointer might have been clobbered by the
917 user program. Make sure that it still points to a valid memory
920 if (boffset
!= -1 && (boffset
< 0 || boffset
>= TYPE_LENGTH (type
)))
922 /* FIXME (alloc): not safe is baseclass is really really big. */
923 gdb_byte
*buf
= alloca (TYPE_LENGTH (baseclass
));
926 if (target_read_memory (address
+ boffset
, buf
,
927 TYPE_LENGTH (baseclass
)) != 0)
931 base_valaddr
= valaddr
+ boffset
;
934 fprintf_filtered (stream
, "<invalid address>");
936 pascal_object_print_value_fields (baseclass
, base_valaddr
, address
+ boffset
,
937 stream
, recurse
, val
, options
,
938 (struct type
**) obstack_base (&dont_print_vb_obstack
),
940 fputs_filtered (", ", stream
);
946 if (dont_print_vb
== 0)
948 /* Free the space used to deal with the printing
949 of this type from top level. */
950 obstack_free (&dont_print_vb_obstack
, last_dont_print
);
951 /* Reset watermark so that we can continue protecting
952 ourselves from whatever we were protecting ourselves. */
953 dont_print_vb_obstack
= tmp_obstack
;
957 /* Print value of a static member.
958 To avoid infinite recursion when printing a class that contains
959 a static instance of the class, we keep the addresses of all printed
960 static member classes in an obstack and refuse to print them more
963 VAL contains the value to print, STREAM, RECURSE, and OPTIONS
964 have the same meanings as in c_val_print. */
967 pascal_object_print_static_field (struct value
*val
,
968 struct ui_file
*stream
,
970 const struct value_print_options
*options
)
972 struct type
*type
= value_type (val
);
973 struct value_print_options opts
;
975 if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
)
977 CORE_ADDR
*first_dont_print
, addr
;
981 = (CORE_ADDR
*) obstack_base (&dont_print_statmem_obstack
);
982 i
= (CORE_ADDR
*) obstack_next_free (&dont_print_statmem_obstack
)
987 if (value_address (val
) == first_dont_print
[i
])
989 fputs_filtered ("<same as static member of an already seen type>",
995 addr
= value_address (val
);
996 obstack_grow (&dont_print_statmem_obstack
, (char *) &addr
,
999 CHECK_TYPEDEF (type
);
1000 pascal_object_print_value_fields (type
, value_contents (val
), addr
,
1001 stream
, recurse
, NULL
, options
,
1008 common_val_print (val
, stream
, recurse
, &opts
, current_language
);
1011 extern initialize_file_ftype _initialize_pascal_valprint
; /* -Wmissing-prototypes */
1014 _initialize_pascal_valprint (void)
1016 add_setshow_boolean_cmd ("pascal_static-members", class_support
,
1017 &user_print_options
.pascal_static_field_print
, _("\
1018 Set printing of pascal static members."), _("\
1019 Show printing of pascal static members."), NULL
,
1021 show_pascal_static_field_print
,
1022 &setprintlist
, &showprintlist
);