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"
42 /* Print data of type TYPE located at VALADDR (within GDB), which came from
43 the inferior at address ADDRESS, onto stdio stream STREAM according to
44 FORMAT (a letter or 0 for natural format). The data at VALADDR is in
47 If the data are a string pointer, returns the number of string characters
50 If DEREF_REF is nonzero, then dereference references, otherwise just print
53 The PRETTY parameter controls prettyprinting. */
57 pascal_val_print (struct type
*type
, char *valaddr
, int embedded_offset
,
58 CORE_ADDR address
, struct ui_file
*stream
, int format
,
59 int deref_ref
, int recurse
, enum val_prettyprint pretty
)
61 register unsigned int i
= 0; /* Number of characters printed */
69 switch (TYPE_CODE (type
))
72 if (TYPE_LENGTH (type
) > 0 && TYPE_LENGTH (TYPE_TARGET_TYPE (type
)) > 0)
74 elttype
= check_typedef (TYPE_TARGET_TYPE (type
));
75 eltlen
= TYPE_LENGTH (elttype
);
76 len
= TYPE_LENGTH (type
) / eltlen
;
77 if (prettyprint_arrays
)
79 print_spaces_filtered (2 + 2 * recurse
, stream
);
81 /* For an array of chars, print with string syntax. */
83 ((TYPE_CODE (elttype
) == TYPE_CODE_INT
)
84 || ((current_language
->la_language
== language_m2
)
85 && (TYPE_CODE (elttype
) == TYPE_CODE_CHAR
)))
86 && (format
== 0 || format
== 's'))
88 /* If requested, look for the first null char and only print
90 if (stop_print_at_null
)
92 unsigned int temp_len
;
94 /* Look for a NULL char. */
96 (valaddr
+ embedded_offset
)[temp_len
]
97 && temp_len
< len
&& temp_len
< print_max
;
102 LA_PRINT_STRING (stream
, valaddr
+ embedded_offset
, len
, 1, 0);
107 fprintf_filtered (stream
, "{");
108 /* If this is a virtual function table, print the 0th
109 entry specially, and the rest of the members normally. */
110 if (pascal_object_is_vtbl_ptr_type (elttype
))
113 fprintf_filtered (stream
, "%d vtable entries", len
- 1);
119 val_print_array_elements (type
, valaddr
+ embedded_offset
, address
, stream
,
120 format
, deref_ref
, recurse
, pretty
, i
);
121 fprintf_filtered (stream
, "}");
125 /* Array of unspecified length: treat like pointer to first elt. */
127 goto print_unpacked_pointer
;
130 if (format
&& format
!= 's')
132 print_scalar_formatted (valaddr
+ embedded_offset
, type
, format
, 0, stream
);
135 if (vtblprint
&& pascal_object_is_vtbl_ptr_type (type
))
137 /* Print the unmangled name if desired. */
138 /* Print vtable entry - we only get here if we ARE using
139 -fvtable_thunks. (Otherwise, look under TYPE_CODE_STRUCT.) */
140 print_address_demangle (extract_address (valaddr
+ embedded_offset
, TYPE_LENGTH (type
)),
144 elttype
= check_typedef (TYPE_TARGET_TYPE (type
));
145 if (TYPE_CODE (elttype
) == TYPE_CODE_METHOD
)
147 pascal_object_print_class_method (valaddr
+ embedded_offset
, type
, stream
);
149 else if (TYPE_CODE (elttype
) == TYPE_CODE_MEMBER
)
151 pascal_object_print_class_member (valaddr
+ embedded_offset
,
152 TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (type
)),
157 addr
= unpack_pointer (type
, valaddr
+ embedded_offset
);
158 print_unpacked_pointer
:
159 elttype
= check_typedef (TYPE_TARGET_TYPE (type
));
161 if (TYPE_CODE (elttype
) == TYPE_CODE_FUNC
)
163 /* Try to print what function it points to. */
164 print_address_demangle (addr
, stream
, demangle
);
165 /* Return value is irrelevant except for string pointers. */
169 if (addressprint
&& format
!= 's')
171 print_address_numeric (addr
, 1, stream
);
174 /* For a pointer to char or unsigned char, also print the string
175 pointed to, unless pointer is null. */
176 if (TYPE_LENGTH (elttype
) == 1
177 && TYPE_CODE (elttype
) == TYPE_CODE_INT
178 && (format
== 0 || format
== 's')
181 /* no wide string yet */
182 i
= val_print_string (addr
, -1, 1, stream
);
184 /* also for pointers to pascal strings */
185 /* Note: this is Free Pascal specific:
186 as GDB does not recognize stabs pascal strings
187 Pascal strings are mapped to records
188 with lowercase names PM */
189 /* I don't know what GPC does :( PM */
190 if (TYPE_CODE (elttype
) == TYPE_CODE_STRUCT
&&
191 TYPE_NFIELDS (elttype
) == 2 &&
192 strcmp (TYPE_FIELDS (elttype
)[0].name
, "length") == 0 &&
193 strcmp (TYPE_FIELDS (elttype
)[1].name
, "st") == 0 &&
197 read_memory (addr
, &bytelength
, 1);
198 i
= val_print_string (addr
+ 1, bytelength
, 1, stream
);
200 else if (pascal_object_is_vtbl_member (type
))
202 /* print vtbl's nicely */
203 CORE_ADDR vt_address
= unpack_pointer (type
, valaddr
+ embedded_offset
);
205 struct minimal_symbol
*msymbol
=
206 lookup_minimal_symbol_by_pc (vt_address
);
207 if ((msymbol
!= NULL
) &&
208 (vt_address
== SYMBOL_VALUE_ADDRESS (msymbol
)))
210 fputs_filtered (" <", stream
);
211 fputs_filtered (SYMBOL_SOURCE_NAME (msymbol
), stream
);
212 fputs_filtered (">", stream
);
214 if (vt_address
&& vtblprint
)
217 struct symbol
*wsym
= (struct symbol
*) NULL
;
220 struct block
*block
= (struct block
*) NULL
;
224 wsym
= lookup_symbol (SYMBOL_NAME (msymbol
), block
,
225 VAR_NAMESPACE
, &is_this_fld
, &s
);
229 wtype
= SYMBOL_TYPE (wsym
);
233 wtype
= TYPE_TARGET_TYPE (type
);
235 vt_val
= value_at (wtype
, vt_address
, NULL
);
236 val_print (VALUE_TYPE (vt_val
), VALUE_CONTENTS (vt_val
), 0,
237 VALUE_ADDRESS (vt_val
), stream
, format
,
238 deref_ref
, recurse
+ 1, pretty
);
241 fprintf_filtered (stream
, "\n");
242 print_spaces_filtered (2 + 2 * recurse
, stream
);
247 /* Return number of characters printed, including the terminating
248 '\0' if we reached the end. val_print_string takes care including
249 the terminating '\0' if necessary. */
254 case TYPE_CODE_MEMBER
:
255 error ("not implemented: member type in pascal_val_print");
259 elttype
= check_typedef (TYPE_TARGET_TYPE (type
));
260 if (TYPE_CODE (elttype
) == TYPE_CODE_MEMBER
)
262 pascal_object_print_class_member (valaddr
+ embedded_offset
,
263 TYPE_DOMAIN_TYPE (elttype
),
269 fprintf_filtered (stream
, "@");
270 print_address_numeric
271 (extract_address (valaddr
+ embedded_offset
,
272 TARGET_PTR_BIT
/ HOST_CHAR_BIT
), 1, stream
);
274 fputs_filtered (": ", stream
);
276 /* De-reference the reference. */
279 if (TYPE_CODE (elttype
) != TYPE_CODE_UNDEF
)
281 value_ptr deref_val
=
283 (TYPE_TARGET_TYPE (type
),
284 unpack_pointer (lookup_pointer_type (builtin_type_void
),
285 valaddr
+ embedded_offset
),
287 val_print (VALUE_TYPE (deref_val
),
288 VALUE_CONTENTS (deref_val
), 0,
289 VALUE_ADDRESS (deref_val
), stream
, format
,
290 deref_ref
, recurse
+ 1, pretty
);
293 fputs_filtered ("???", stream
);
297 case TYPE_CODE_UNION
:
298 if (recurse
&& !unionprint
)
300 fprintf_filtered (stream
, "{...}");
304 case TYPE_CODE_STRUCT
:
305 if (vtblprint
&& pascal_object_is_vtbl_ptr_type (type
))
307 /* Print the unmangled name if desired. */
308 /* Print vtable entry - we only get here if NOT using
309 -fvtable_thunks. (Otherwise, look under TYPE_CODE_PTR.) */
310 print_address_demangle (extract_address (
311 valaddr
+ embedded_offset
+ TYPE_FIELD_BITPOS (type
, VTBL_FNADDR_OFFSET
) / 8,
312 TYPE_LENGTH (TYPE_FIELD_TYPE (type
, VTBL_FNADDR_OFFSET
))),
317 if ((TYPE_NFIELDS (type
) == 2) &&
318 (strcmp (TYPE_FIELDS (type
)[0].name
, "length") == 0) &&
319 (strcmp (TYPE_FIELDS (type
)[1].name
, "st") == 0))
321 len
= (*(valaddr
+ embedded_offset
)) & 0xff;
322 LA_PRINT_STRING (stream
, valaddr
+ embedded_offset
+ 1, len
, /* width ?? */ 0, 0);
325 pascal_object_print_value_fields (type
, valaddr
+ embedded_offset
, address
, stream
, format
,
326 recurse
, pretty
, NULL
, 0);
333 print_scalar_formatted (valaddr
+ embedded_offset
, type
, format
, 0, stream
);
336 len
= TYPE_NFIELDS (type
);
337 val
= unpack_long (type
, valaddr
+ embedded_offset
);
338 for (i
= 0; i
< len
; i
++)
341 if (val
== TYPE_FIELD_BITPOS (type
, i
))
348 fputs_filtered (TYPE_FIELD_NAME (type
, i
), stream
);
352 print_longest (stream
, 'd', 0, val
);
359 print_scalar_formatted (valaddr
+ embedded_offset
, type
, format
, 0, stream
);
362 /* FIXME, we should consider, at least for ANSI C language, eliminating
363 the distinction made between FUNCs and POINTERs to FUNCs. */
364 fprintf_filtered (stream
, "{");
365 type_print (type
, "", stream
, -1);
366 fprintf_filtered (stream
, "} ");
367 /* Try to print what function it points to, and its address. */
368 print_address_demangle (address
, stream
, demangle
);
372 format
= format
? format
: output_format
;
374 print_scalar_formatted (valaddr
+ embedded_offset
, type
, format
, 0, stream
);
377 val
= unpack_long (type
, valaddr
+ embedded_offset
);
379 fputs_filtered ("false", stream
);
381 fputs_filtered ("true", stream
);
384 fputs_filtered ("true (", stream
);
385 fprintf_filtered (stream
, "%ld)", (long int) val
);
390 case TYPE_CODE_RANGE
:
391 /* FIXME: create_range_type does not set the unsigned bit in a
392 range type (I think it probably should copy it from the target
393 type), so we won't print values which are too large to
394 fit in a signed integer correctly. */
395 /* FIXME: Doesn't handle ranges of enums correctly. (Can't just
396 print with the target type, though, because the size of our type
397 and the target type might differ). */
401 format
= format
? format
: output_format
;
404 print_scalar_formatted (valaddr
+ embedded_offset
, type
, format
, 0, stream
);
408 val_print_type_code_int (type
, valaddr
+ embedded_offset
, stream
);
413 format
= format
? format
: output_format
;
416 print_scalar_formatted (valaddr
+ embedded_offset
, type
, format
, 0, stream
);
420 val
= unpack_long (type
, valaddr
+ embedded_offset
);
421 if (TYPE_UNSIGNED (type
))
422 fprintf_filtered (stream
, "%u", (unsigned int) val
);
424 fprintf_filtered (stream
, "%d", (int) val
);
425 fputs_filtered (" ", stream
);
426 LA_PRINT_CHAR ((unsigned char) val
, stream
);
433 print_scalar_formatted (valaddr
+ embedded_offset
, type
, format
, 0, stream
);
437 print_floating (valaddr
+ embedded_offset
, type
, stream
);
441 case TYPE_CODE_BITSTRING
:
443 elttype
= TYPE_INDEX_TYPE (type
);
444 CHECK_TYPEDEF (elttype
);
445 if (TYPE_FLAGS (elttype
) & TYPE_FLAG_STUB
)
447 fprintf_filtered (stream
, "<incomplete type>");
453 struct type
*range
= elttype
;
454 LONGEST low_bound
, high_bound
;
456 int is_bitstring
= TYPE_CODE (type
) == TYPE_CODE_BITSTRING
;
460 fputs_filtered ("B'", stream
);
462 fputs_filtered ("[", stream
);
464 i
= get_discrete_bounds (range
, &low_bound
, &high_bound
);
468 fputs_filtered ("<error value>", stream
);
472 for (i
= low_bound
; i
<= high_bound
; i
++)
474 int element
= value_bit_index (type
, valaddr
+ embedded_offset
, i
);
478 goto maybe_bad_bstring
;
481 fprintf_filtered (stream
, "%d", element
);
485 fputs_filtered (", ", stream
);
486 print_type_scalar (range
, i
, stream
);
489 if (i
+ 1 <= high_bound
&& value_bit_index (type
, valaddr
+ embedded_offset
, ++i
))
492 fputs_filtered ("..", stream
);
493 while (i
+ 1 <= high_bound
494 && value_bit_index (type
, valaddr
+ embedded_offset
, ++i
))
496 print_type_scalar (range
, j
, stream
);
502 fputs_filtered ("'", stream
);
504 fputs_filtered ("]", stream
);
509 fprintf_filtered (stream
, "void");
512 case TYPE_CODE_ERROR
:
513 fprintf_filtered (stream
, "<error type>");
516 case TYPE_CODE_UNDEF
:
517 /* This happens (without TYPE_FLAG_STUB set) on systems which don't use
518 dbx xrefs (NO_DBX_XREFS in gcc) if a file has a "struct foo *bar"
519 and no complete type for struct foo in that file. */
520 fprintf_filtered (stream
, "<incomplete type>");
524 error ("Invalid pascal type code %d in symbol table.", TYPE_CODE (type
));
531 pascal_value_print (value_ptr val
, struct ui_file
*stream
, int format
,
532 enum val_prettyprint pretty
)
534 struct type
*type
= VALUE_TYPE (val
);
536 /* If it is a pointer, indicate what it points to.
538 Print type also if it is a reference.
540 Object pascal: if it is a member pointer, we will take care
541 of that when we print it. */
542 if (TYPE_CODE (type
) == TYPE_CODE_PTR
||
543 TYPE_CODE (type
) == TYPE_CODE_REF
)
545 /* Hack: remove (char *) for char strings. Their
546 type is indicated by the quoted string anyway. */
547 if (TYPE_CODE (type
) == TYPE_CODE_PTR
&&
548 TYPE_NAME (type
) == NULL
&&
549 TYPE_NAME (TYPE_TARGET_TYPE (type
)) != NULL
&&
550 STREQ (TYPE_NAME (TYPE_TARGET_TYPE (type
)), "char"))
556 fprintf_filtered (stream
, "(");
557 type_print (type
, "", stream
, -1);
558 fprintf_filtered (stream
, ") ");
561 return val_print (type
, VALUE_CONTENTS (val
), VALUE_EMBEDDED_OFFSET (val
),
562 VALUE_ADDRESS (val
) + VALUE_OFFSET (val
),
563 stream
, format
, 1, 0, pretty
);
567 /******************************************************************************
568 Inserted from cp-valprint
569 ******************************************************************************/
571 extern int vtblprint
; /* Controls printing of vtbl's */
572 extern int objectprint
; /* Controls looking up an object's derived type
573 using what we find in its vtables. */
574 static int pascal_static_field_print
; /* Controls printing of static fields. */
576 static struct obstack dont_print_vb_obstack
;
577 static struct obstack dont_print_statmem_obstack
;
580 pascal_object_print_static_field (struct type
*, value_ptr
, struct ui_file
*, int, int,
581 enum val_prettyprint
);
584 pascal_object_print_value (struct type
*, char *, CORE_ADDR
, struct ui_file
*,
585 int, int, enum val_prettyprint
, struct type
**);
588 pascal_object_print_class_method (char *valaddr
, struct type
*type
,
589 struct ui_file
*stream
)
592 struct fn_field
*f
= NULL
;
601 struct type
*target_type
= check_typedef (TYPE_TARGET_TYPE (type
));
603 domain
= TYPE_DOMAIN_TYPE (target_type
);
604 if (domain
== (struct type
*) NULL
)
606 fprintf_filtered (stream
, "<unknown>");
609 addr
= unpack_pointer (lookup_pointer_type (builtin_type_void
), valaddr
);
610 if (METHOD_PTR_IS_VIRTUAL (addr
))
612 offset
= METHOD_PTR_TO_VOFFSET (addr
);
613 len
= TYPE_NFN_FIELDS (domain
);
614 for (i
= 0; i
< len
; i
++)
616 f
= TYPE_FN_FIELDLIST1 (domain
, i
);
617 len2
= TYPE_FN_FIELDLIST_LENGTH (domain
, i
);
619 for (j
= 0; j
< len2
; j
++)
622 if (TYPE_FN_FIELD_VOFFSET (f
, j
) == offset
)
624 if (TYPE_FN_FIELD_STUB (f
, j
))
625 check_stub_method (domain
, i
, j
);
634 sym
= find_pc_function (addr
);
637 error ("invalid pointer to member function");
639 len
= TYPE_NFN_FIELDS (domain
);
640 for (i
= 0; i
< len
; i
++)
642 f
= TYPE_FN_FIELDLIST1 (domain
, i
);
643 len2
= TYPE_FN_FIELDLIST_LENGTH (domain
, i
);
645 for (j
= 0; j
< len2
; j
++)
648 if (TYPE_FN_FIELD_STUB (f
, j
))
649 check_stub_method (domain
, i
, j
);
650 if (STREQ (SYMBOL_NAME (sym
), TYPE_FN_FIELD_PHYSNAME (f
, j
)))
660 char *demangled_name
;
662 fprintf_filtered (stream
, "&");
663 fprintf_filtered (stream
, kind
);
664 demangled_name
= cplus_demangle (TYPE_FN_FIELD_PHYSNAME (f
, j
),
665 DMGL_ANSI
| DMGL_PARAMS
);
666 if (demangled_name
== NULL
)
667 fprintf_filtered (stream
, "<badly mangled name %s>",
668 TYPE_FN_FIELD_PHYSNAME (f
, j
));
671 fputs_filtered (demangled_name
, stream
);
672 free (demangled_name
);
677 fprintf_filtered (stream
, "(");
678 type_print (type
, "", stream
, -1);
679 fprintf_filtered (stream
, ") %d", (int) addr
>> 3);
683 /* It was changed to this after 2.4.5. */
684 const char pascal_vtbl_ptr_name
[] =
685 {'_', '_', 'v', 't', 'b', 'l', '_', 'p', 't', 'r', '_', 't', 'y', 'p', 'e', 0};
687 /* Return truth value for assertion that TYPE is of the type
688 "pointer to virtual function". */
691 pascal_object_is_vtbl_ptr_type (struct type
*type
)
693 char *typename
= type_name_no_tag (type
);
695 return (typename
!= NULL
696 && (STREQ (typename
, pascal_vtbl_ptr_name
)));
699 /* Return truth value for the assertion that TYPE is of the type
700 "pointer to virtual function table". */
703 pascal_object_is_vtbl_member (struct type
*type
)
705 if (TYPE_CODE (type
) == TYPE_CODE_PTR
)
707 type
= TYPE_TARGET_TYPE (type
);
708 if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
)
710 type
= TYPE_TARGET_TYPE (type
);
711 if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
/* if not using thunks */
712 || TYPE_CODE (type
) == TYPE_CODE_PTR
) /* if using thunks */
714 /* Virtual functions tables are full of pointers
715 to virtual functions. */
716 return pascal_object_is_vtbl_ptr_type (type
);
723 /* Mutually recursive subroutines of pascal_object_print_value and c_val_print to
724 print out a structure's fields: pascal_object_print_value_fields and pascal_object_print_value.
726 TYPE, VALADDR, ADDRESS, STREAM, RECURSE, and PRETTY have the
727 same meanings as in pascal_object_print_value and c_val_print.
729 DONT_PRINT is an array of baseclass types that we
730 should not print, or zero if called from top level. */
733 pascal_object_print_value_fields (struct type
*type
, char *valaddr
,
734 CORE_ADDR address
, struct ui_file
*stream
,
735 int format
, int recurse
,
736 enum val_prettyprint pretty
,
737 struct type
**dont_print_vb
,
738 int dont_print_statmem
)
740 int i
, len
, n_baseclasses
;
741 struct obstack tmp_obstack
;
742 char *last_dont_print
= obstack_next_free (&dont_print_statmem_obstack
);
744 CHECK_TYPEDEF (type
);
746 fprintf_filtered (stream
, "{");
747 len
= TYPE_NFIELDS (type
);
748 n_baseclasses
= TYPE_N_BASECLASSES (type
);
750 /* Print out baseclasses such that we don't print
751 duplicates of virtual baseclasses. */
752 if (n_baseclasses
> 0)
753 pascal_object_print_value (type
, valaddr
, address
, stream
,
754 format
, recurse
+ 1, pretty
, dont_print_vb
);
756 if (!len
&& n_baseclasses
== 1)
757 fprintf_filtered (stream
, "<No data fields>");
760 extern int inspect_it
;
763 if (dont_print_statmem
== 0)
765 /* If we're at top level, carve out a completely fresh
766 chunk of the obstack and use that until this particular
767 invocation returns. */
768 tmp_obstack
= dont_print_statmem_obstack
;
769 obstack_finish (&dont_print_statmem_obstack
);
772 for (i
= n_baseclasses
; i
< len
; i
++)
774 /* If requested, skip printing of static fields. */
775 if (!pascal_static_field_print
&& TYPE_FIELD_STATIC (type
, i
))
778 fprintf_filtered (stream
, ", ");
779 else if (n_baseclasses
> 0)
783 fprintf_filtered (stream
, "\n");
784 print_spaces_filtered (2 + 2 * recurse
, stream
);
785 fputs_filtered ("members of ", stream
);
786 fputs_filtered (type_name_no_tag (type
), stream
);
787 fputs_filtered (": ", stream
);
794 fprintf_filtered (stream
, "\n");
795 print_spaces_filtered (2 + 2 * recurse
, stream
);
799 wrap_here (n_spaces (2 + 2 * recurse
));
803 if (TYPE_CODE (TYPE_FIELD_TYPE (type
, i
)) == TYPE_CODE_PTR
)
804 fputs_filtered ("\"( ptr \"", stream
);
806 fputs_filtered ("\"( nodef \"", stream
);
807 if (TYPE_FIELD_STATIC (type
, i
))
808 fputs_filtered ("static ", stream
);
809 fprintf_symbol_filtered (stream
, TYPE_FIELD_NAME (type
, i
),
811 DMGL_PARAMS
| DMGL_ANSI
);
812 fputs_filtered ("\" \"", stream
);
813 fprintf_symbol_filtered (stream
, TYPE_FIELD_NAME (type
, i
),
815 DMGL_PARAMS
| DMGL_ANSI
);
816 fputs_filtered ("\") \"", stream
);
820 annotate_field_begin (TYPE_FIELD_TYPE (type
, i
));
822 if (TYPE_FIELD_STATIC (type
, i
))
823 fputs_filtered ("static ", stream
);
824 fprintf_symbol_filtered (stream
, TYPE_FIELD_NAME (type
, i
),
826 DMGL_PARAMS
| DMGL_ANSI
);
827 annotate_field_name_end ();
828 fputs_filtered (" = ", stream
);
829 annotate_field_value ();
832 if (!TYPE_FIELD_STATIC (type
, i
) && TYPE_FIELD_PACKED (type
, i
))
836 /* Bitfields require special handling, especially due to byte
838 if (TYPE_FIELD_IGNORE (type
, i
))
840 fputs_filtered ("<optimized out or zero length>", stream
);
844 v
= value_from_longest (TYPE_FIELD_TYPE (type
, i
),
845 unpack_field_as_long (type
, valaddr
, i
));
847 val_print (TYPE_FIELD_TYPE (type
, i
), VALUE_CONTENTS (v
), 0, 0,
848 stream
, format
, 0, recurse
+ 1, pretty
);
853 if (TYPE_FIELD_IGNORE (type
, i
))
855 fputs_filtered ("<optimized out or zero length>", stream
);
857 else if (TYPE_FIELD_STATIC (type
, i
))
859 /* value_ptr v = value_static_field (type, i); v4.17 specific */
861 v
= value_from_longest (TYPE_FIELD_TYPE (type
, i
),
862 unpack_field_as_long (type
, valaddr
, i
));
865 fputs_filtered ("<optimized out>", stream
);
867 pascal_object_print_static_field (TYPE_FIELD_TYPE (type
, i
), v
,
868 stream
, format
, recurse
+ 1,
873 /* val_print (TYPE_FIELD_TYPE (type, i),
874 valaddr + TYPE_FIELD_BITPOS (type, i) / 8,
875 address + TYPE_FIELD_BITPOS (type, i) / 8, 0,
876 stream, format, 0, recurse + 1, pretty); */
877 val_print (TYPE_FIELD_TYPE (type
, i
),
878 valaddr
, TYPE_FIELD_BITPOS (type
, i
) / 8,
879 address
+ TYPE_FIELD_BITPOS (type
, i
) / 8,
880 stream
, format
, 0, recurse
+ 1, pretty
);
883 annotate_field_end ();
886 if (dont_print_statmem
== 0)
888 /* Free the space used to deal with the printing
889 of the members from top level. */
890 obstack_free (&dont_print_statmem_obstack
, last_dont_print
);
891 dont_print_statmem_obstack
= tmp_obstack
;
896 fprintf_filtered (stream
, "\n");
897 print_spaces_filtered (2 * recurse
, stream
);
900 fprintf_filtered (stream
, "}");
903 /* Special val_print routine to avoid printing multiple copies of virtual
907 pascal_object_print_value (struct type
*type
, char *valaddr
, CORE_ADDR address
,
908 struct ui_file
*stream
, int format
, int recurse
,
909 enum val_prettyprint pretty
,
910 struct type
**dont_print_vb
)
912 struct obstack tmp_obstack
;
913 struct type
**last_dont_print
914 = (struct type
**) obstack_next_free (&dont_print_vb_obstack
);
915 int i
, n_baseclasses
= TYPE_N_BASECLASSES (type
);
917 if (dont_print_vb
== 0)
919 /* If we're at top level, carve out a completely fresh
920 chunk of the obstack and use that until this particular
921 invocation returns. */
922 tmp_obstack
= dont_print_vb_obstack
;
923 /* Bump up the high-water mark. Now alpha is omega. */
924 obstack_finish (&dont_print_vb_obstack
);
927 for (i
= 0; i
< n_baseclasses
; i
++)
930 struct type
*baseclass
= check_typedef (TYPE_BASECLASS (type
, i
));
931 char *basename
= TYPE_NAME (baseclass
);
934 if (BASETYPE_VIA_VIRTUAL (type
, i
))
936 struct type
**first_dont_print
937 = (struct type
**) obstack_base (&dont_print_vb_obstack
);
939 int j
= (struct type
**) obstack_next_free (&dont_print_vb_obstack
)
943 if (baseclass
== first_dont_print
[j
])
946 obstack_ptr_grow (&dont_print_vb_obstack
, baseclass
);
949 boffset
= baseclass_offset (type
, i
, valaddr
, address
);
953 fprintf_filtered (stream
, "\n");
954 print_spaces_filtered (2 * recurse
, stream
);
956 fputs_filtered ("<", stream
);
957 /* Not sure what the best notation is in the case where there is no
960 fputs_filtered (basename
? basename
: "", stream
);
961 fputs_filtered ("> = ", stream
);
963 /* The virtual base class pointer might have been clobbered by the
964 user program. Make sure that it still points to a valid memory
967 if (boffset
!= -1 && (boffset
< 0 || boffset
>= TYPE_LENGTH (type
)))
969 base_valaddr
= (char *) alloca (TYPE_LENGTH (baseclass
));
970 if (target_read_memory (address
+ boffset
, base_valaddr
,
971 TYPE_LENGTH (baseclass
)) != 0)
975 base_valaddr
= valaddr
+ boffset
;
978 fprintf_filtered (stream
, "<invalid address>");
980 pascal_object_print_value_fields (baseclass
, base_valaddr
, address
+ boffset
,
981 stream
, format
, recurse
, pretty
,
982 (struct type
**) obstack_base (&dont_print_vb_obstack
),
984 fputs_filtered (", ", stream
);
990 if (dont_print_vb
== 0)
992 /* Free the space used to deal with the printing
993 of this type from top level. */
994 obstack_free (&dont_print_vb_obstack
, last_dont_print
);
995 /* Reset watermark so that we can continue protecting
996 ourselves from whatever we were protecting ourselves. */
997 dont_print_vb_obstack
= tmp_obstack
;
1001 /* Print value of a static member.
1002 To avoid infinite recursion when printing a class that contains
1003 a static instance of the class, we keep the addresses of all printed
1004 static member classes in an obstack and refuse to print them more
1007 VAL contains the value to print, TYPE, STREAM, RECURSE, and PRETTY
1008 have the same meanings as in c_val_print. */
1011 pascal_object_print_static_field (struct type
*type
, value_ptr val
,
1012 struct ui_file
*stream
, int format
,
1013 int recurse
, enum val_prettyprint pretty
)
1015 if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
)
1017 CORE_ADDR
*first_dont_print
;
1021 = (CORE_ADDR
*) obstack_base (&dont_print_statmem_obstack
);
1022 i
= (CORE_ADDR
*) obstack_next_free (&dont_print_statmem_obstack
)
1027 if (VALUE_ADDRESS (val
) == first_dont_print
[i
])
1029 fputs_filtered ("<same as static member of an already seen type>",
1035 obstack_grow (&dont_print_statmem_obstack
, (char *) &VALUE_ADDRESS (val
),
1036 sizeof (CORE_ADDR
));
1038 CHECK_TYPEDEF (type
);
1039 pascal_object_print_value_fields (type
, VALUE_CONTENTS (val
), VALUE_ADDRESS (val
),
1040 stream
, format
, recurse
, pretty
, NULL
, 1);
1043 val_print (type
, VALUE_CONTENTS (val
), 0, VALUE_ADDRESS (val
),
1044 stream
, format
, 0, recurse
, pretty
);
1048 pascal_object_print_class_member (char *valaddr
, struct type
*domain
,
1049 struct ui_file
*stream
, char *prefix
)
1052 /* VAL is a byte offset into the structure type DOMAIN.
1053 Find the name of the field for that offset and
1057 register unsigned int i
;
1058 unsigned len
= TYPE_NFIELDS (domain
);
1059 /* @@ Make VAL into bit offset */
1060 LONGEST val
= unpack_long (builtin_type_int
, valaddr
) << 3;
1061 for (i
= TYPE_N_BASECLASSES (domain
); i
< len
; i
++)
1063 int bitpos
= TYPE_FIELD_BITPOS (domain
, i
);
1067 if (val
< bitpos
&& i
!= 0)
1069 /* Somehow pointing into a field. */
1071 extra
= (val
- TYPE_FIELD_BITPOS (domain
, i
));
1082 fprintf_filtered (stream
, prefix
);
1083 name
= type_name_no_tag (domain
);
1085 fputs_filtered (name
, stream
);
1087 pascal_type_print_base (domain
, stream
, 0, 0);
1088 fprintf_filtered (stream
, "::");
1089 fputs_filtered (TYPE_FIELD_NAME (domain
, i
), stream
);
1091 fprintf_filtered (stream
, " + %d bytes", extra
);
1093 fprintf_filtered (stream
, " (offset in bits)");
1096 fprintf_filtered (stream
, "%ld", (long int) (val
>> 3));
1101 _initialize_pascal_valprint (void)
1104 (add_set_cmd ("pascal_static-members", class_support
, var_boolean
,
1105 (char *) &pascal_static_field_print
,
1106 "Set printing of pascal static members.",
1109 /* Turn on printing of static fields. */
1110 pascal_static_field_print
= 1;