1 /* Support for printing Pascal values for GDB, the GNU debugger.
3 Copyright (C) 2000-2020 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 3 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, see <http://www.gnu.org/licenses/>. */
20 /* This file is derived from c-valprint.c */
23 #include "gdb_obstack.h"
26 #include "expression.h"
33 #include "typeprint.h"
39 #include "cp-support.h"
41 #include "gdbsupport/byte-vector.h"
42 #include "cli/cli-style.h"
45 static void pascal_object_print_value_fields (struct type
*, const gdb_byte
*,
47 CORE_ADDR
, struct ui_file
*,
50 const struct value_print_options
*,
53 /* Decorations for Pascal. */
55 static const struct generic_val_print_decorations p_decorations
=
67 /* See val_print for a description of the various parameters of this
68 function; they are identical. */
71 pascal_val_print (struct type
*type
,
72 int embedded_offset
, CORE_ADDR address
,
73 struct ui_file
*stream
, int recurse
,
74 struct value
*original_value
,
75 const struct value_print_options
*options
)
77 struct gdbarch
*gdbarch
= get_type_arch (type
);
78 enum bfd_endian byte_order
= type_byte_order (type
);
79 unsigned int i
= 0; /* Number of characters printed */
83 int length_pos
, length_size
, string_pos
;
84 struct type
*char_type
;
87 const gdb_byte
*valaddr
= value_contents_for_printing (original_value
);
89 type
= check_typedef (type
);
90 switch (TYPE_CODE (type
))
94 LONGEST low_bound
, high_bound
;
96 if (get_array_bounds (type
, &low_bound
, &high_bound
))
98 len
= high_bound
- low_bound
+ 1;
99 elttype
= check_typedef (TYPE_TARGET_TYPE (type
));
100 eltlen
= TYPE_LENGTH (elttype
);
101 if (options
->prettyformat_arrays
)
103 print_spaces_filtered (2 + 2 * recurse
, stream
);
105 /* If 's' format is used, try to print out as string.
106 If no format is given, print as string if element type
107 is of TYPE_CODE_CHAR and element size is 1,2 or 4. */
108 if (options
->format
== 's'
109 || ((eltlen
== 1 || eltlen
== 2 || eltlen
== 4)
110 && TYPE_CODE (elttype
) == TYPE_CODE_CHAR
111 && options
->format
== 0))
113 /* If requested, look for the first null char and only print
114 elements up to it. */
115 if (options
->stop_print_at_null
)
117 unsigned int temp_len
;
119 /* Look for a NULL char. */
121 extract_unsigned_integer (valaddr
+ embedded_offset
+
122 temp_len
* eltlen
, eltlen
,
124 && temp_len
< len
&& temp_len
< options
->print_max
;
129 LA_PRINT_STRING (stream
, TYPE_TARGET_TYPE (type
),
130 valaddr
+ embedded_offset
, len
, NULL
, 0,
136 fprintf_filtered (stream
, "{");
137 /* If this is a virtual function table, print the 0th
138 entry specially, and the rest of the members normally. */
139 if (pascal_object_is_vtbl_ptr_type (elttype
))
142 fprintf_filtered (stream
, "%d vtable entries", len
- 1);
148 val_print_array_elements (type
, embedded_offset
,
149 address
, stream
, recurse
,
150 original_value
, options
, i
);
151 fprintf_filtered (stream
, "}");
155 /* Array of unspecified length: treat like pointer to first elt. */
156 addr
= address
+ embedded_offset
;
158 goto print_unpacked_pointer
;
161 if (options
->format
&& options
->format
!= 's')
163 val_print_scalar_formatted (type
, embedded_offset
,
164 original_value
, options
, 0, stream
);
167 if (options
->vtblprint
&& pascal_object_is_vtbl_ptr_type (type
))
169 /* Print the unmangled name if desired. */
170 /* Print vtable entry - we only get here if we ARE using
171 -fvtable_thunks. (Otherwise, look under TYPE_CODE_STRUCT.) */
172 /* Extract the address, assume that it is unsigned. */
173 addr
= extract_unsigned_integer (valaddr
+ embedded_offset
,
174 TYPE_LENGTH (type
), byte_order
);
175 print_address_demangle (options
, gdbarch
, addr
, stream
, demangle
);
178 check_typedef (TYPE_TARGET_TYPE (type
));
180 addr
= unpack_pointer (type
, valaddr
+ embedded_offset
);
181 print_unpacked_pointer
:
182 elttype
= check_typedef (TYPE_TARGET_TYPE (type
));
184 if (TYPE_CODE (elttype
) == TYPE_CODE_FUNC
)
186 /* Try to print what function it points to. */
187 print_address_demangle (options
, gdbarch
, addr
, stream
, demangle
);
191 if (options
->addressprint
&& options
->format
!= 's')
193 fputs_filtered (paddress (gdbarch
, addr
), stream
);
197 /* For a pointer to char or unsigned char, also print the string
198 pointed to, unless pointer is null. */
199 if (((TYPE_LENGTH (elttype
) == 1
200 && (TYPE_CODE (elttype
) == TYPE_CODE_INT
201 || TYPE_CODE (elttype
) == TYPE_CODE_CHAR
))
202 || ((TYPE_LENGTH (elttype
) == 2 || TYPE_LENGTH (elttype
) == 4)
203 && TYPE_CODE (elttype
) == TYPE_CODE_CHAR
))
204 && (options
->format
== 0 || options
->format
== 's')
208 fputs_filtered (" ", stream
);
209 /* No wide string yet. */
210 i
= val_print_string (elttype
, NULL
, addr
, -1, stream
, options
);
212 /* Also for pointers to pascal strings. */
213 /* Note: this is Free Pascal specific:
214 as GDB does not recognize stabs pascal strings
215 Pascal strings are mapped to records
216 with lowercase names PM. */
217 if (is_pascal_string_type (elttype
, &length_pos
, &length_size
,
218 &string_pos
, &char_type
, NULL
)
221 ULONGEST string_length
;
225 fputs_filtered (" ", stream
);
226 buffer
= (gdb_byte
*) xmalloc (length_size
);
227 read_memory (addr
+ length_pos
, buffer
, length_size
);
228 string_length
= extract_unsigned_integer (buffer
, length_size
,
231 i
= val_print_string (char_type
, NULL
,
232 addr
+ string_pos
, string_length
,
235 else if (pascal_object_is_vtbl_member (type
))
237 /* Print vtbl's nicely. */
238 CORE_ADDR vt_address
= unpack_pointer (type
,
239 valaddr
+ embedded_offset
);
240 struct bound_minimal_symbol msymbol
=
241 lookup_minimal_symbol_by_pc (vt_address
);
243 /* If 'symbol_print' is set, we did the work above. */
244 if (!options
->symbol_print
245 && (msymbol
.minsym
!= NULL
)
246 && (vt_address
== BMSYMBOL_VALUE_ADDRESS (msymbol
)))
249 fputs_filtered (" ", stream
);
250 fputs_filtered ("<", stream
);
251 fputs_filtered (msymbol
.minsym
->print_name (), stream
);
252 fputs_filtered (">", stream
);
255 if (vt_address
&& options
->vtblprint
)
257 struct value
*vt_val
;
258 struct symbol
*wsym
= NULL
;
262 fputs_filtered (" ", stream
);
264 if (msymbol
.minsym
!= NULL
)
266 const char *search_name
= msymbol
.minsym
->search_name ();
267 wsym
= lookup_symbol_search_name (search_name
, NULL
,
273 wtype
= SYMBOL_TYPE (wsym
);
277 wtype
= TYPE_TARGET_TYPE (type
);
279 vt_val
= value_at (wtype
, vt_address
);
280 common_val_print (vt_val
, stream
, recurse
+ 1, options
,
282 if (options
->prettyformat
)
284 fprintf_filtered (stream
, "\n");
285 print_spaces_filtered (2 + 2 * recurse
, stream
);
294 case TYPE_CODE_FLAGS
:
296 case TYPE_CODE_RANGE
:
300 case TYPE_CODE_ERROR
:
301 case TYPE_CODE_UNDEF
:
304 generic_val_print (type
, embedded_offset
, address
,
305 stream
, recurse
, original_value
, options
,
309 case TYPE_CODE_UNION
:
310 if (recurse
&& !options
->unionprint
)
312 fprintf_filtered (stream
, "{...}");
316 case TYPE_CODE_STRUCT
:
317 if (options
->vtblprint
&& pascal_object_is_vtbl_ptr_type (type
))
319 /* Print the unmangled name if desired. */
320 /* Print vtable entry - we only get here if NOT using
321 -fvtable_thunks. (Otherwise, look under TYPE_CODE_PTR.) */
322 /* Extract the address, assume that it is unsigned. */
323 print_address_demangle
325 extract_unsigned_integer (valaddr
+ embedded_offset
326 + TYPE_FIELD_BITPOS (type
,
327 VTBL_FNADDR_OFFSET
) / 8,
328 TYPE_LENGTH (TYPE_FIELD_TYPE (type
,
329 VTBL_FNADDR_OFFSET
)),
335 if (is_pascal_string_type (type
, &length_pos
, &length_size
,
336 &string_pos
, &char_type
, NULL
))
338 len
= extract_unsigned_integer (valaddr
+ embedded_offset
339 + length_pos
, length_size
,
341 LA_PRINT_STRING (stream
, char_type
,
342 valaddr
+ embedded_offset
+ string_pos
,
343 len
, NULL
, 0, options
);
346 pascal_object_print_value_fields (type
, valaddr
, embedded_offset
,
347 address
, stream
, recurse
,
348 original_value
, options
,
354 elttype
= TYPE_INDEX_TYPE (type
);
355 elttype
= check_typedef (elttype
);
356 if (TYPE_STUB (elttype
))
358 fprintf_styled (stream
, metadata_style
.style (), "<incomplete type>");
363 struct type
*range
= elttype
;
364 LONGEST low_bound
, high_bound
;
367 fputs_filtered ("[", stream
);
369 int bound_info
= get_discrete_bounds (range
, &low_bound
, &high_bound
);
370 if (low_bound
== 0 && high_bound
== -1 && TYPE_LENGTH (type
) > 0)
372 /* If we know the size of the set type, we can figure out the
375 high_bound
= TYPE_LENGTH (type
) * TARGET_CHAR_BIT
- 1;
376 TYPE_HIGH_BOUND (range
) = high_bound
;
381 fputs_styled ("<error value>", metadata_style
.style (), stream
);
385 for (i
= low_bound
; i
<= high_bound
; i
++)
387 int element
= value_bit_index (type
,
388 valaddr
+ embedded_offset
, i
);
393 goto maybe_bad_bstring
;
398 fputs_filtered (", ", stream
);
399 print_type_scalar (range
, i
, stream
);
402 if (i
+ 1 <= high_bound
403 && value_bit_index (type
,
404 valaddr
+ embedded_offset
, ++i
))
408 fputs_filtered ("..", stream
);
409 while (i
+ 1 <= high_bound
410 && value_bit_index (type
,
411 valaddr
+ embedded_offset
,
414 print_type_scalar (range
, j
, stream
);
419 fputs_filtered ("]", stream
);
424 error (_("Invalid pascal type code %d in symbol table."),
432 pascal_value_print_inner (struct value
*val
, struct ui_file
*stream
,
434 const struct value_print_options
*options
)
437 struct type
*type
= check_typedef (value_type (val
));
438 struct gdbarch
*gdbarch
= get_type_arch (type
);
439 enum bfd_endian byte_order
= type_byte_order (type
);
440 unsigned int i
= 0; /* Number of characters printed */
442 struct type
*elttype
;
444 int length_pos
, length_size
, string_pos
;
445 struct type
*char_type
;
448 const gdb_byte
*valaddr
= value_contents_for_printing (val
);
450 switch (TYPE_CODE (type
))
452 case TYPE_CODE_ARRAY
:
454 LONGEST low_bound
, high_bound
;
456 if (get_array_bounds (type
, &low_bound
, &high_bound
))
458 len
= high_bound
- low_bound
+ 1;
459 elttype
= check_typedef (TYPE_TARGET_TYPE (type
));
460 eltlen
= TYPE_LENGTH (elttype
);
461 if (options
->prettyformat_arrays
)
463 print_spaces_filtered (2 + 2 * recurse
, stream
);
465 /* If 's' format is used, try to print out as string.
466 If no format is given, print as string if element type
467 is of TYPE_CODE_CHAR and element size is 1,2 or 4. */
468 if (options
->format
== 's'
469 || ((eltlen
== 1 || eltlen
== 2 || eltlen
== 4)
470 && TYPE_CODE (elttype
) == TYPE_CODE_CHAR
471 && options
->format
== 0))
473 /* If requested, look for the first null char and only print
474 elements up to it. */
475 if (options
->stop_print_at_null
)
477 unsigned int temp_len
;
479 /* Look for a NULL char. */
481 extract_unsigned_integer (valaddr
+ temp_len
* eltlen
,
483 && temp_len
< len
&& temp_len
< options
->print_max
;
488 LA_PRINT_STRING (stream
, TYPE_TARGET_TYPE (type
),
489 valaddr
, len
, NULL
, 0, options
);
494 fprintf_filtered (stream
, "{");
495 /* If this is a virtual function table, print the 0th
496 entry specially, and the rest of the members normally. */
497 if (pascal_object_is_vtbl_ptr_type (elttype
))
500 fprintf_filtered (stream
, "%d vtable entries", len
- 1);
506 value_print_array_elements (val
, stream
, recurse
, options
, i
);
507 fprintf_filtered (stream
, "}");
511 /* Array of unspecified length: treat like pointer to first elt. */
512 addr
= value_address (val
);
514 goto print_unpacked_pointer
;
517 if (options
->format
&& options
->format
!= 's')
519 value_print_scalar_formatted (val
, options
, 0, stream
);
522 if (options
->vtblprint
&& pascal_object_is_vtbl_ptr_type (type
))
524 /* Print the unmangled name if desired. */
525 /* Print vtable entry - we only get here if we ARE using
526 -fvtable_thunks. (Otherwise, look under TYPE_CODE_STRUCT.) */
527 /* Extract the address, assume that it is unsigned. */
528 addr
= extract_unsigned_integer (valaddr
,
529 TYPE_LENGTH (type
), byte_order
);
530 print_address_demangle (options
, gdbarch
, addr
, stream
, demangle
);
533 check_typedef (TYPE_TARGET_TYPE (type
));
535 addr
= unpack_pointer (type
, valaddr
);
536 print_unpacked_pointer
:
537 elttype
= check_typedef (TYPE_TARGET_TYPE (type
));
539 if (TYPE_CODE (elttype
) == TYPE_CODE_FUNC
)
541 /* Try to print what function it points to. */
542 print_address_demangle (options
, gdbarch
, addr
, stream
, demangle
);
546 if (options
->addressprint
&& options
->format
!= 's')
548 fputs_filtered (paddress (gdbarch
, addr
), stream
);
552 /* For a pointer to char or unsigned char, also print the string
553 pointed to, unless pointer is null. */
554 if (((TYPE_LENGTH (elttype
) == 1
555 && (TYPE_CODE (elttype
) == TYPE_CODE_INT
556 || TYPE_CODE (elttype
) == TYPE_CODE_CHAR
))
557 || ((TYPE_LENGTH (elttype
) == 2 || TYPE_LENGTH (elttype
) == 4)
558 && TYPE_CODE (elttype
) == TYPE_CODE_CHAR
))
559 && (options
->format
== 0 || options
->format
== 's')
563 fputs_filtered (" ", stream
);
564 /* No wide string yet. */
565 i
= val_print_string (elttype
, NULL
, addr
, -1, stream
, options
);
567 /* Also for pointers to pascal strings. */
568 /* Note: this is Free Pascal specific:
569 as GDB does not recognize stabs pascal strings
570 Pascal strings are mapped to records
571 with lowercase names PM. */
572 if (is_pascal_string_type (elttype
, &length_pos
, &length_size
,
573 &string_pos
, &char_type
, NULL
)
576 ULONGEST string_length
;
580 fputs_filtered (" ", stream
);
581 buffer
= (gdb_byte
*) xmalloc (length_size
);
582 read_memory (addr
+ length_pos
, buffer
, length_size
);
583 string_length
= extract_unsigned_integer (buffer
, length_size
,
586 i
= val_print_string (char_type
, NULL
,
587 addr
+ string_pos
, string_length
,
590 else if (pascal_object_is_vtbl_member (type
))
592 /* Print vtbl's nicely. */
593 CORE_ADDR vt_address
= unpack_pointer (type
, valaddr
);
594 struct bound_minimal_symbol msymbol
=
595 lookup_minimal_symbol_by_pc (vt_address
);
597 /* If 'symbol_print' is set, we did the work above. */
598 if (!options
->symbol_print
599 && (msymbol
.minsym
!= NULL
)
600 && (vt_address
== BMSYMBOL_VALUE_ADDRESS (msymbol
)))
603 fputs_filtered (" ", stream
);
604 fputs_filtered ("<", stream
);
605 fputs_filtered (msymbol
.minsym
->print_name (), stream
);
606 fputs_filtered (">", stream
);
609 if (vt_address
&& options
->vtblprint
)
611 struct value
*vt_val
;
612 struct symbol
*wsym
= NULL
;
616 fputs_filtered (" ", stream
);
618 if (msymbol
.minsym
!= NULL
)
620 const char *search_name
= msymbol
.minsym
->search_name ();
621 wsym
= lookup_symbol_search_name (search_name
, NULL
,
627 wtype
= SYMBOL_TYPE (wsym
);
631 wtype
= TYPE_TARGET_TYPE (type
);
633 vt_val
= value_at (wtype
, vt_address
);
634 common_val_print (vt_val
, stream
, recurse
+ 1, options
,
636 if (options
->prettyformat
)
638 fprintf_filtered (stream
, "\n");
639 print_spaces_filtered (2 + 2 * recurse
, stream
);
648 case TYPE_CODE_FLAGS
:
650 case TYPE_CODE_RANGE
:
654 case TYPE_CODE_ERROR
:
655 case TYPE_CODE_UNDEF
:
658 generic_value_print (val
, stream
, recurse
, options
, &p_decorations
);
661 case TYPE_CODE_UNION
:
662 if (recurse
&& !options
->unionprint
)
664 fprintf_filtered (stream
, "{...}");
668 case TYPE_CODE_STRUCT
:
669 if (options
->vtblprint
&& pascal_object_is_vtbl_ptr_type (type
))
671 /* Print the unmangled name if desired. */
672 /* Print vtable entry - we only get here if NOT using
673 -fvtable_thunks. (Otherwise, look under TYPE_CODE_PTR.) */
674 /* Extract the address, assume that it is unsigned. */
675 print_address_demangle
677 extract_unsigned_integer (valaddr
678 + TYPE_FIELD_BITPOS (type
,
679 VTBL_FNADDR_OFFSET
) / 8,
680 TYPE_LENGTH (TYPE_FIELD_TYPE (type
,
681 VTBL_FNADDR_OFFSET
)),
687 if (is_pascal_string_type (type
, &length_pos
, &length_size
,
688 &string_pos
, &char_type
, NULL
))
690 len
= extract_unsigned_integer (valaddr
+ length_pos
,
691 length_size
, byte_order
);
692 LA_PRINT_STRING (stream
, char_type
, valaddr
+ string_pos
,
693 len
, NULL
, 0, options
);
696 pascal_object_print_value_fields (type
, valaddr
, 0,
697 value_address (val
), stream
,
698 recurse
, val
, options
,
704 elttype
= TYPE_INDEX_TYPE (type
);
705 elttype
= check_typedef (elttype
);
706 if (TYPE_STUB (elttype
))
708 fprintf_styled (stream
, metadata_style
.style (), "<incomplete type>");
713 struct type
*range
= elttype
;
714 LONGEST low_bound
, high_bound
;
717 fputs_filtered ("[", stream
);
719 int bound_info
= get_discrete_bounds (range
, &low_bound
, &high_bound
);
720 if (low_bound
== 0 && high_bound
== -1 && TYPE_LENGTH (type
) > 0)
722 /* If we know the size of the set type, we can figure out the
725 high_bound
= TYPE_LENGTH (type
) * TARGET_CHAR_BIT
- 1;
726 TYPE_HIGH_BOUND (range
) = high_bound
;
731 fputs_styled ("<error value>", metadata_style
.style (), stream
);
735 for (i
= low_bound
; i
<= high_bound
; i
++)
737 int element
= value_bit_index (type
, valaddr
, i
);
742 goto maybe_bad_bstring
;
747 fputs_filtered (", ", stream
);
748 print_type_scalar (range
, i
, stream
);
751 if (i
+ 1 <= high_bound
752 && value_bit_index (type
, valaddr
, ++i
))
756 fputs_filtered ("..", stream
);
757 while (i
+ 1 <= high_bound
758 && value_bit_index (type
, valaddr
, ++i
))
760 print_type_scalar (range
, j
, stream
);
765 fputs_filtered ("]", stream
);
770 error (_("Invalid pascal type code %d in symbol table."),
777 pascal_value_print (struct value
*val
, struct ui_file
*stream
,
778 const struct value_print_options
*options
)
780 struct type
*type
= value_type (val
);
781 struct value_print_options opts
= *options
;
785 /* If it is a pointer, indicate what it points to.
787 Print type also if it is a reference.
789 Object pascal: if it is a member pointer, we will take care
790 of that when we print it. */
791 if (TYPE_CODE (type
) == TYPE_CODE_PTR
792 || TYPE_CODE (type
) == TYPE_CODE_REF
)
794 /* Hack: remove (char *) for char strings. Their
795 type is indicated by the quoted string anyway. */
796 if (TYPE_CODE (type
) == TYPE_CODE_PTR
797 && TYPE_NAME (type
) == NULL
798 && TYPE_NAME (TYPE_TARGET_TYPE (type
)) != NULL
799 && strcmp (TYPE_NAME (TYPE_TARGET_TYPE (type
)), "char") == 0)
805 fprintf_filtered (stream
, "(");
806 type_print (type
, "", stream
, -1);
807 fprintf_filtered (stream
, ") ");
810 common_val_print (val
, stream
, 0, &opts
, current_language
);
815 show_pascal_static_field_print (struct ui_file
*file
, int from_tty
,
816 struct cmd_list_element
*c
, const char *value
)
818 fprintf_filtered (file
, _("Printing of pascal static members is %s.\n"),
822 static struct obstack dont_print_vb_obstack
;
823 static struct obstack dont_print_statmem_obstack
;
825 static void pascal_object_print_static_field (struct value
*,
826 struct ui_file
*, int,
827 const struct value_print_options
*);
829 static void pascal_object_print_value (struct type
*, const gdb_byte
*,
831 CORE_ADDR
, struct ui_file
*, int,
833 const struct value_print_options
*,
836 /* It was changed to this after 2.4.5. */
837 const char pascal_vtbl_ptr_name
[] =
838 {'_', '_', 'v', 't', 'b', 'l', '_', 'p', 't', 'r', '_', 't', 'y', 'p', 'e', 0};
840 /* Return truth value for assertion that TYPE is of the type
841 "pointer to virtual function". */
844 pascal_object_is_vtbl_ptr_type (struct type
*type
)
846 const char *type_name
= TYPE_NAME (type
);
848 return (type_name
!= NULL
849 && strcmp (type_name
, pascal_vtbl_ptr_name
) == 0);
852 /* Return truth value for the assertion that TYPE is of the type
853 "pointer to virtual function table". */
856 pascal_object_is_vtbl_member (struct type
*type
)
858 if (TYPE_CODE (type
) == TYPE_CODE_PTR
)
860 type
= TYPE_TARGET_TYPE (type
);
861 if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
)
863 type
= TYPE_TARGET_TYPE (type
);
864 if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
/* If not using
866 || TYPE_CODE (type
) == TYPE_CODE_PTR
) /* If using thunks. */
868 /* Virtual functions tables are full of pointers
869 to virtual functions. */
870 return pascal_object_is_vtbl_ptr_type (type
);
877 /* Mutually recursive subroutines of pascal_object_print_value and
878 c_val_print to print out a structure's fields:
879 pascal_object_print_value_fields and pascal_object_print_value.
881 TYPE, VALADDR, ADDRESS, STREAM, RECURSE, and OPTIONS have the
882 same meanings as in pascal_object_print_value and c_val_print.
884 DONT_PRINT is an array of baseclass types that we
885 should not print, or zero if called from top level. */
888 pascal_object_print_value_fields (struct type
*type
, const gdb_byte
*valaddr
,
890 CORE_ADDR address
, struct ui_file
*stream
,
893 const struct value_print_options
*options
,
894 struct type
**dont_print_vb
,
895 int dont_print_statmem
)
897 int i
, len
, n_baseclasses
;
898 char *last_dont_print
899 = (char *) obstack_next_free (&dont_print_statmem_obstack
);
901 type
= check_typedef (type
);
903 fprintf_filtered (stream
, "{");
904 len
= TYPE_NFIELDS (type
);
905 n_baseclasses
= TYPE_N_BASECLASSES (type
);
907 /* Print out baseclasses such that we don't print
908 duplicates of virtual baseclasses. */
909 if (n_baseclasses
> 0)
910 pascal_object_print_value (type
, valaddr
, offset
, address
,
911 stream
, recurse
+ 1, val
,
912 options
, dont_print_vb
);
914 if (!len
&& n_baseclasses
== 1)
915 fprintf_styled (stream
, metadata_style
.style (), "<No data fields>");
918 struct obstack tmp_obstack
= dont_print_statmem_obstack
;
921 if (dont_print_statmem
== 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 obstack_finish (&dont_print_statmem_obstack
);
929 for (i
= n_baseclasses
; i
< len
; i
++)
931 /* If requested, skip printing of static fields. */
932 if (!options
->pascal_static_field_print
933 && field_is_static (&TYPE_FIELD (type
, i
)))
936 fprintf_filtered (stream
, ", ");
937 else if (n_baseclasses
> 0)
939 if (options
->prettyformat
)
941 fprintf_filtered (stream
, "\n");
942 print_spaces_filtered (2 + 2 * recurse
, stream
);
943 fputs_filtered ("members of ", stream
);
944 fputs_filtered (TYPE_NAME (type
), stream
);
945 fputs_filtered (": ", stream
);
950 if (options
->prettyformat
)
952 fprintf_filtered (stream
, "\n");
953 print_spaces_filtered (2 + 2 * recurse
, stream
);
957 wrap_here (n_spaces (2 + 2 * recurse
));
960 annotate_field_begin (TYPE_FIELD_TYPE (type
, i
));
962 if (field_is_static (&TYPE_FIELD (type
, i
)))
964 fputs_filtered ("static ", stream
);
965 fprintf_symbol_filtered (stream
,
966 TYPE_FIELD_NAME (type
, i
),
967 current_language
->la_language
,
968 DMGL_PARAMS
| DMGL_ANSI
);
971 fputs_styled (TYPE_FIELD_NAME (type
, i
),
972 variable_name_style
.style (), stream
);
973 annotate_field_name_end ();
974 fputs_filtered (" = ", stream
);
975 annotate_field_value ();
977 if (!field_is_static (&TYPE_FIELD (type
, i
))
978 && TYPE_FIELD_PACKED (type
, i
))
982 /* Bitfields require special handling, especially due to byte
984 if (TYPE_FIELD_IGNORE (type
, i
))
986 fputs_styled ("<optimized out or zero length>",
987 metadata_style
.style (), stream
);
989 else if (value_bits_synthetic_pointer (val
,
990 TYPE_FIELD_BITPOS (type
,
992 TYPE_FIELD_BITSIZE (type
,
995 fputs_styled (_("<synthetic pointer>"),
996 metadata_style
.style (), stream
);
1000 struct value_print_options opts
= *options
;
1002 v
= value_field_bitfield (type
, i
, valaddr
, offset
, val
);
1005 common_val_print (v
, stream
, recurse
+ 1, &opts
,
1011 if (TYPE_FIELD_IGNORE (type
, i
))
1013 fputs_styled ("<optimized out or zero length>",
1014 metadata_style
.style (), stream
);
1016 else if (field_is_static (&TYPE_FIELD (type
, i
)))
1018 /* struct value *v = value_static_field (type, i);
1022 v
= value_field_bitfield (type
, i
, valaddr
, offset
, val
);
1025 val_print_optimized_out (NULL
, stream
);
1027 pascal_object_print_static_field (v
, stream
, recurse
+ 1,
1032 struct value_print_options opts
= *options
;
1035 /* val_print (TYPE_FIELD_TYPE (type, i),
1036 valaddr + TYPE_FIELD_BITPOS (type, i) / 8,
1037 address + TYPE_FIELD_BITPOS (type, i) / 8, 0,
1038 stream, format, 0, recurse + 1, pretty); */
1039 val_print (TYPE_FIELD_TYPE (type
, i
),
1040 offset
+ TYPE_FIELD_BITPOS (type
, i
) / 8,
1041 address
, stream
, recurse
+ 1, val
, &opts
,
1045 annotate_field_end ();
1048 if (dont_print_statmem
== 0)
1050 /* Free the space used to deal with the printing
1051 of the members from top level. */
1052 obstack_free (&dont_print_statmem_obstack
, last_dont_print
);
1053 dont_print_statmem_obstack
= tmp_obstack
;
1056 if (options
->prettyformat
)
1058 fprintf_filtered (stream
, "\n");
1059 print_spaces_filtered (2 * recurse
, stream
);
1062 fprintf_filtered (stream
, "}");
1065 /* Special val_print routine to avoid printing multiple copies of virtual
1069 pascal_object_print_value (struct type
*type
, const gdb_byte
*valaddr
,
1071 CORE_ADDR address
, struct ui_file
*stream
,
1074 const struct value_print_options
*options
,
1075 struct type
**dont_print_vb
)
1077 struct type
**last_dont_print
1078 = (struct type
**) obstack_next_free (&dont_print_vb_obstack
);
1079 struct obstack tmp_obstack
= dont_print_vb_obstack
;
1080 int i
, n_baseclasses
= TYPE_N_BASECLASSES (type
);
1082 if (dont_print_vb
== 0)
1084 /* If we're at top level, carve out a completely fresh
1085 chunk of the obstack and use that until this particular
1086 invocation returns. */
1087 /* Bump up the high-water mark. Now alpha is omega. */
1088 obstack_finish (&dont_print_vb_obstack
);
1091 for (i
= 0; i
< n_baseclasses
; i
++)
1093 LONGEST boffset
= 0;
1094 struct type
*baseclass
= check_typedef (TYPE_BASECLASS (type
, i
));
1095 const char *basename
= TYPE_NAME (baseclass
);
1096 const gdb_byte
*base_valaddr
= NULL
;
1099 gdb::byte_vector buf
;
1101 if (BASETYPE_VIA_VIRTUAL (type
, i
))
1103 struct type
**first_dont_print
1104 = (struct type
**) obstack_base (&dont_print_vb_obstack
);
1106 int j
= (struct type
**) obstack_next_free (&dont_print_vb_obstack
)
1110 if (baseclass
== first_dont_print
[j
])
1113 obstack_ptr_grow (&dont_print_vb_obstack
, baseclass
);
1116 thisoffset
= offset
;
1120 boffset
= baseclass_offset (type
, i
, valaddr
, offset
, address
, val
);
1122 catch (const gdb_exception_error
&ex
)
1124 if (ex
.error
== NOT_AVAILABLE_ERROR
)
1132 /* The virtual base class pointer might have been clobbered by the
1133 user program. Make sure that it still points to a valid memory
1136 if (boffset
< 0 || boffset
>= TYPE_LENGTH (type
))
1138 buf
.resize (TYPE_LENGTH (baseclass
));
1140 base_valaddr
= buf
.data ();
1141 if (target_read_memory (address
+ boffset
, buf
.data (),
1142 TYPE_LENGTH (baseclass
)) != 0)
1144 address
= address
+ boffset
;
1149 base_valaddr
= valaddr
;
1152 if (options
->prettyformat
)
1154 fprintf_filtered (stream
, "\n");
1155 print_spaces_filtered (2 * recurse
, stream
);
1157 fputs_filtered ("<", stream
);
1158 /* Not sure what the best notation is in the case where there is no
1161 fputs_filtered (basename
? basename
: "", stream
);
1162 fputs_filtered ("> = ", stream
);
1165 val_print_unavailable (stream
);
1167 val_print_invalid_address (stream
);
1169 pascal_object_print_value_fields (baseclass
, base_valaddr
,
1170 thisoffset
+ boffset
, address
,
1171 stream
, recurse
, val
, options
,
1172 (struct type
**) obstack_base (&dont_print_vb_obstack
),
1174 fputs_filtered (", ", stream
);
1180 if (dont_print_vb
== 0)
1182 /* Free the space used to deal with the printing
1183 of this type from top level. */
1184 obstack_free (&dont_print_vb_obstack
, last_dont_print
);
1185 /* Reset watermark so that we can continue protecting
1186 ourselves from whatever we were protecting ourselves. */
1187 dont_print_vb_obstack
= tmp_obstack
;
1191 /* Print value of a static member.
1192 To avoid infinite recursion when printing a class that contains
1193 a static instance of the class, we keep the addresses of all printed
1194 static member classes in an obstack and refuse to print them more
1197 VAL contains the value to print, STREAM, RECURSE, and OPTIONS
1198 have the same meanings as in c_val_print. */
1201 pascal_object_print_static_field (struct value
*val
,
1202 struct ui_file
*stream
,
1204 const struct value_print_options
*options
)
1206 struct type
*type
= value_type (val
);
1207 struct value_print_options opts
;
1209 if (value_entirely_optimized_out (val
))
1211 val_print_optimized_out (val
, stream
);
1215 if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
)
1217 CORE_ADDR
*first_dont_print
, addr
;
1221 = (CORE_ADDR
*) obstack_base (&dont_print_statmem_obstack
);
1222 i
= (CORE_ADDR
*) obstack_next_free (&dont_print_statmem_obstack
)
1227 if (value_address (val
) == first_dont_print
[i
])
1230 <same as static member of an already seen type>"),
1231 metadata_style
.style (), stream
);
1236 addr
= value_address (val
);
1237 obstack_grow (&dont_print_statmem_obstack
, (char *) &addr
,
1238 sizeof (CORE_ADDR
));
1240 type
= check_typedef (type
);
1241 pascal_object_print_value_fields (type
,
1242 value_contents_for_printing (val
),
1243 value_embedded_offset (val
),
1246 val
, options
, NULL
, 1);
1252 common_val_print (val
, stream
, recurse
, &opts
, current_language
);
1255 void _initialize_pascal_valprint ();
1257 _initialize_pascal_valprint ()
1259 add_setshow_boolean_cmd ("pascal_static-members", class_support
,
1260 &user_print_options
.pascal_static_field_print
, _("\
1261 Set printing of pascal static members."), _("\
1262 Show printing of pascal static members."), NULL
,
1264 show_pascal_static_field_print
,
1265 &setprintlist
, &showprintlist
);