Raise WARNS to 6 and silence resulting warnings.
[dragonfly.git] / contrib / gdb-6 / gdb / p-valprint.c
blob0f40d6d2157749c2615ca2f2f5f5db7347ce9bea
1 /* Support for printing Pascal values for GDB, the GNU debugger.
3 Copyright (C) 2000, 2001, 2003, 2005, 2006, 2007
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 */
23 #include "defs.h"
24 #include "gdb_obstack.h"
25 #include "symtab.h"
26 #include "gdbtypes.h"
27 #include "expression.h"
28 #include "value.h"
29 #include "command.h"
30 #include "gdbcmd.h"
31 #include "gdbcore.h"
32 #include "demangle.h"
33 #include "valprint.h"
34 #include "typeprint.h"
35 #include "language.h"
36 #include "target.h"
37 #include "annotate.h"
38 #include "p-lang.h"
39 #include "cp-abi.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
48 target byte order.
50 If the data are a string pointer, returns the number of string characters
51 printed.
53 If DEREF_REF is nonzero, then dereference references, otherwise just print
54 them like pointers.
56 The PRETTY parameter controls prettyprinting. */
59 int
60 pascal_val_print (struct type *type, const gdb_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 */
66 unsigned len;
67 struct type *elttype;
68 unsigned eltlen;
69 int length_pos, length_size, string_pos;
70 int char_size;
71 LONGEST val;
72 CORE_ADDR addr;
74 CHECK_TYPEDEF (type);
75 switch (TYPE_CODE (type))
77 case TYPE_CODE_ARRAY:
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. */
88 if (eltlen == 1
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
95 elements up to it. */
96 if (stop_print_at_null)
98 unsigned int temp_len;
100 /* Look for a NULL char. */
101 for (temp_len = 0;
102 (valaddr + embedded_offset)[temp_len]
103 && temp_len < len && temp_len < print_max;
104 temp_len++);
105 len = temp_len;
108 LA_PRINT_STRING (stream, valaddr + embedded_offset, len, 1, 0);
109 i = len;
111 else
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))
118 i = 1;
119 fprintf_filtered (stream, "%d vtable entries", len - 1);
121 else
123 i = 0;
125 val_print_array_elements (type, valaddr + embedded_offset, address, stream,
126 format, deref_ref, recurse, pretty, i);
127 fprintf_filtered (stream, "}");
129 break;
131 /* Array of unspecified length: treat like pointer to first elt. */
132 addr = address;
133 goto print_unpacked_pointer;
135 case TYPE_CODE_PTR:
136 if (format && format != 's')
138 print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream);
139 break;
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)),
148 stream, demangle);
149 break;
151 elttype = check_typedef (TYPE_TARGET_TYPE (type));
153 addr = unpack_pointer (type, valaddr + embedded_offset);
154 print_unpacked_pointer:
155 elttype = check_typedef (TYPE_TARGET_TYPE (type));
157 if (TYPE_CODE (elttype) == TYPE_CODE_FUNC)
159 /* Try to print what function it points to. */
160 print_address_demangle (addr, stream, demangle);
161 /* Return value is irrelevant except for string pointers. */
162 return (0);
165 if (addressprint && format != 's')
167 fputs_filtered (paddress (addr), stream);
170 /* For a pointer to char or unsigned char, also print the string
171 pointed to, unless pointer is null. */
172 if (TYPE_LENGTH (elttype) == 1
173 && TYPE_CODE (elttype) == TYPE_CODE_INT
174 && (format == 0 || format == 's')
175 && addr != 0)
177 /* no wide string yet */
178 i = val_print_string (addr, -1, 1, stream);
180 /* also for pointers to pascal strings */
181 /* Note: this is Free Pascal specific:
182 as GDB does not recognize stabs pascal strings
183 Pascal strings are mapped to records
184 with lowercase names PM */
185 if (is_pascal_string_type (elttype, &length_pos, &length_size,
186 &string_pos, &char_size, NULL)
187 && addr != 0)
189 ULONGEST string_length;
190 void *buffer;
191 buffer = xmalloc (length_size);
192 read_memory (addr + length_pos, buffer, length_size);
193 string_length = extract_unsigned_integer (buffer, length_size);
194 xfree (buffer);
195 i = val_print_string (addr + string_pos, string_length, char_size, stream);
197 else if (pascal_object_is_vtbl_member (type))
199 /* print vtbl's nicely */
200 CORE_ADDR vt_address = unpack_pointer (type, valaddr + embedded_offset);
202 struct minimal_symbol *msymbol =
203 lookup_minimal_symbol_by_pc (vt_address);
204 if ((msymbol != NULL)
205 && (vt_address == SYMBOL_VALUE_ADDRESS (msymbol)))
207 fputs_filtered (" <", stream);
208 fputs_filtered (SYMBOL_PRINT_NAME (msymbol), stream);
209 fputs_filtered (">", stream);
211 if (vt_address && vtblprint)
213 struct value *vt_val;
214 struct symbol *wsym = (struct symbol *) NULL;
215 struct type *wtype;
216 struct block *block = (struct block *) NULL;
217 int is_this_fld;
219 if (msymbol != NULL)
220 wsym = lookup_symbol (SYMBOL_LINKAGE_NAME (msymbol), block,
221 VAR_DOMAIN, &is_this_fld, NULL);
223 if (wsym)
225 wtype = SYMBOL_TYPE (wsym);
227 else
229 wtype = TYPE_TARGET_TYPE (type);
231 vt_val = value_at (wtype, vt_address);
232 common_val_print (vt_val, stream, format, deref_ref,
233 recurse + 1, pretty);
234 if (pretty)
236 fprintf_filtered (stream, "\n");
237 print_spaces_filtered (2 + 2 * recurse, stream);
242 /* Return number of characters printed, including the terminating
243 '\0' if we reached the end. val_print_string takes care including
244 the terminating '\0' if necessary. */
245 return i;
247 break;
249 case TYPE_CODE_REF:
250 elttype = check_typedef (TYPE_TARGET_TYPE (type));
251 if (addressprint)
253 fprintf_filtered (stream, "@");
254 /* Extract the address, assume that it is unsigned. */
255 fputs_filtered (paddress (
256 extract_unsigned_integer (valaddr + embedded_offset,
257 gdbarch_ptr_bit (current_gdbarch) / HOST_CHAR_BIT)), stream);
258 if (deref_ref)
259 fputs_filtered (": ", stream);
261 /* De-reference the reference. */
262 if (deref_ref)
264 if (TYPE_CODE (elttype) != TYPE_CODE_UNDEF)
266 struct value *deref_val =
267 value_at
268 (TYPE_TARGET_TYPE (type),
269 unpack_pointer (lookup_pointer_type (builtin_type_void),
270 valaddr + embedded_offset));
271 common_val_print (deref_val, stream, format, deref_ref,
272 recurse + 1, pretty);
274 else
275 fputs_filtered ("???", stream);
277 break;
279 case TYPE_CODE_UNION:
280 if (recurse && !unionprint)
282 fprintf_filtered (stream, "{...}");
283 break;
285 /* Fall through. */
286 case TYPE_CODE_STRUCT:
287 if (vtblprint && pascal_object_is_vtbl_ptr_type (type))
289 /* Print the unmangled name if desired. */
290 /* Print vtable entry - we only get here if NOT using
291 -fvtable_thunks. (Otherwise, look under TYPE_CODE_PTR.) */
292 /* Extract the address, assume that it is unsigned. */
293 print_address_demangle
294 (extract_unsigned_integer (valaddr + embedded_offset + TYPE_FIELD_BITPOS (type, VTBL_FNADDR_OFFSET) / 8,
295 TYPE_LENGTH (TYPE_FIELD_TYPE (type, VTBL_FNADDR_OFFSET))),
296 stream, demangle);
298 else
300 if (is_pascal_string_type (type, &length_pos, &length_size,
301 &string_pos, &char_size, NULL))
303 len = extract_unsigned_integer (valaddr + embedded_offset + length_pos, length_size);
304 LA_PRINT_STRING (stream, valaddr + embedded_offset + string_pos, len, char_size, 0);
306 else
307 pascal_object_print_value_fields (type, valaddr + embedded_offset, address, stream, format,
308 recurse, pretty, NULL, 0);
310 break;
312 case TYPE_CODE_ENUM:
313 if (format)
315 print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream);
316 break;
318 len = TYPE_NFIELDS (type);
319 val = unpack_long (type, valaddr + embedded_offset);
320 for (i = 0; i < len; i++)
322 QUIT;
323 if (val == TYPE_FIELD_BITPOS (type, i))
325 break;
328 if (i < len)
330 fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
332 else
334 print_longest (stream, 'd', 0, val);
336 break;
338 case TYPE_CODE_FLAGS:
339 if (format)
340 print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream);
341 else
342 val_print_type_code_flags (type, valaddr + embedded_offset, stream);
343 break;
345 case TYPE_CODE_FUNC:
346 if (format)
348 print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream);
349 break;
351 /* FIXME, we should consider, at least for ANSI C language, eliminating
352 the distinction made between FUNCs and POINTERs to FUNCs. */
353 fprintf_filtered (stream, "{");
354 type_print (type, "", stream, -1);
355 fprintf_filtered (stream, "} ");
356 /* Try to print what function it points to, and its address. */
357 print_address_demangle (address, stream, demangle);
358 break;
360 case TYPE_CODE_BOOL:
361 format = format ? format : output_format;
362 if (format)
363 print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream);
364 else
366 val = unpack_long (type, valaddr + embedded_offset);
367 if (val == 0)
368 fputs_filtered ("false", stream);
369 else if (val == 1)
370 fputs_filtered ("true", stream);
371 else
373 fputs_filtered ("true (", stream);
374 fprintf_filtered (stream, "%ld)", (long int) val);
377 break;
379 case TYPE_CODE_RANGE:
380 /* FIXME: create_range_type does not set the unsigned bit in a
381 range type (I think it probably should copy it from the target
382 type), so we won't print values which are too large to
383 fit in a signed integer correctly. */
384 /* FIXME: Doesn't handle ranges of enums correctly. (Can't just
385 print with the target type, though, because the size of our type
386 and the target type might differ). */
387 /* FALLTHROUGH */
389 case TYPE_CODE_INT:
390 format = format ? format : output_format;
391 if (format)
393 print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream);
395 else
397 val_print_type_code_int (type, valaddr + embedded_offset, stream);
399 break;
401 case TYPE_CODE_CHAR:
402 format = format ? format : output_format;
403 if (format)
405 print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream);
407 else
409 val = unpack_long (type, valaddr + embedded_offset);
410 if (TYPE_UNSIGNED (type))
411 fprintf_filtered (stream, "%u", (unsigned int) val);
412 else
413 fprintf_filtered (stream, "%d", (int) val);
414 fputs_filtered (" ", stream);
415 LA_PRINT_CHAR ((unsigned char) val, stream);
417 break;
419 case TYPE_CODE_FLT:
420 if (format)
422 print_scalar_formatted (valaddr + embedded_offset, type, format, 0, stream);
424 else
426 print_floating (valaddr + embedded_offset, type, stream);
428 break;
430 case TYPE_CODE_BITSTRING:
431 case TYPE_CODE_SET:
432 elttype = TYPE_INDEX_TYPE (type);
433 CHECK_TYPEDEF (elttype);
434 if (TYPE_STUB (elttype))
436 fprintf_filtered (stream, "<incomplete type>");
437 gdb_flush (stream);
438 break;
440 else
442 struct type *range = elttype;
443 LONGEST low_bound, high_bound;
444 int i;
445 int is_bitstring = TYPE_CODE (type) == TYPE_CODE_BITSTRING;
446 int need_comma = 0;
448 if (is_bitstring)
449 fputs_filtered ("B'", stream);
450 else
451 fputs_filtered ("[", stream);
453 i = get_discrete_bounds (range, &low_bound, &high_bound);
454 maybe_bad_bstring:
455 if (i < 0)
457 fputs_filtered ("<error value>", stream);
458 goto done;
461 for (i = low_bound; i <= high_bound; i++)
463 int element = value_bit_index (type, valaddr + embedded_offset, i);
464 if (element < 0)
466 i = element;
467 goto maybe_bad_bstring;
469 if (is_bitstring)
470 fprintf_filtered (stream, "%d", element);
471 else if (element)
473 if (need_comma)
474 fputs_filtered (", ", stream);
475 print_type_scalar (range, i, stream);
476 need_comma = 1;
478 if (i + 1 <= high_bound && value_bit_index (type, valaddr + embedded_offset, ++i))
480 int j = i;
481 fputs_filtered ("..", stream);
482 while (i + 1 <= high_bound
483 && value_bit_index (type, valaddr + embedded_offset, ++i))
484 j = i;
485 print_type_scalar (range, j, stream);
489 done:
490 if (is_bitstring)
491 fputs_filtered ("'", stream);
492 else
493 fputs_filtered ("]", stream);
495 break;
497 case TYPE_CODE_VOID:
498 fprintf_filtered (stream, "void");
499 break;
501 case TYPE_CODE_ERROR:
502 fprintf_filtered (stream, "<error type>");
503 break;
505 case TYPE_CODE_UNDEF:
506 /* This happens (without TYPE_FLAG_STUB set) on systems which don't use
507 dbx xrefs (NO_DBX_XREFS in gcc) if a file has a "struct foo *bar"
508 and no complete type for struct foo in that file. */
509 fprintf_filtered (stream, "<incomplete type>");
510 break;
512 default:
513 error (_("Invalid pascal type code %d in symbol table."), TYPE_CODE (type));
515 gdb_flush (stream);
516 return (0);
520 pascal_value_print (struct value *val, struct ui_file *stream, int format,
521 enum val_prettyprint pretty)
523 struct type *type = value_type (val);
525 /* If it is a pointer, indicate what it points to.
527 Print type also if it is a reference.
529 Object pascal: if it is a member pointer, we will take care
530 of that when we print it. */
531 if (TYPE_CODE (type) == TYPE_CODE_PTR
532 || TYPE_CODE (type) == TYPE_CODE_REF)
534 /* Hack: remove (char *) for char strings. Their
535 type is indicated by the quoted string anyway. */
536 if (TYPE_CODE (type) == TYPE_CODE_PTR
537 && TYPE_NAME (type) == NULL
538 && TYPE_NAME (TYPE_TARGET_TYPE (type)) != NULL
539 && strcmp (TYPE_NAME (TYPE_TARGET_TYPE (type)), "char") == 0)
541 /* Print nothing */
543 else
545 fprintf_filtered (stream, "(");
546 type_print (type, "", stream, -1);
547 fprintf_filtered (stream, ") ");
550 return common_val_print (val, stream, format, 1, 0, pretty);
554 /******************************************************************************
555 Inserted from cp-valprint
556 ******************************************************************************/
558 extern int vtblprint; /* Controls printing of vtbl's */
559 extern int objectprint; /* Controls looking up an object's derived type
560 using what we find in its vtables. */
561 static int pascal_static_field_print; /* Controls printing of static fields. */
562 static void
563 show_pascal_static_field_print (struct ui_file *file, int from_tty,
564 struct cmd_list_element *c, const char *value)
566 fprintf_filtered (file, _("Printing of pascal static members is %s.\n"),
567 value);
570 static struct obstack dont_print_vb_obstack;
571 static struct obstack dont_print_statmem_obstack;
573 static void pascal_object_print_static_field (struct value *,
574 struct ui_file *, int, int,
575 enum val_prettyprint);
577 static void pascal_object_print_value (struct type *, const gdb_byte *,
578 CORE_ADDR, struct ui_file *,
579 int, int, enum val_prettyprint,
580 struct type **);
582 /* It was changed to this after 2.4.5. */
583 const char pascal_vtbl_ptr_name[] =
584 {'_', '_', 'v', 't', 'b', 'l', '_', 'p', 't', 'r', '_', 't', 'y', 'p', 'e', 0};
586 /* Return truth value for assertion that TYPE is of the type
587 "pointer to virtual function". */
590 pascal_object_is_vtbl_ptr_type (struct type *type)
592 char *typename = type_name_no_tag (type);
594 return (typename != NULL
595 && strcmp (typename, pascal_vtbl_ptr_name) == 0);
598 /* Return truth value for the assertion that TYPE is of the type
599 "pointer to virtual function table". */
602 pascal_object_is_vtbl_member (struct type *type)
604 if (TYPE_CODE (type) == TYPE_CODE_PTR)
606 type = TYPE_TARGET_TYPE (type);
607 if (TYPE_CODE (type) == TYPE_CODE_ARRAY)
609 type = TYPE_TARGET_TYPE (type);
610 if (TYPE_CODE (type) == TYPE_CODE_STRUCT /* if not using thunks */
611 || TYPE_CODE (type) == TYPE_CODE_PTR) /* if using thunks */
613 /* Virtual functions tables are full of pointers
614 to virtual functions. */
615 return pascal_object_is_vtbl_ptr_type (type);
619 return 0;
622 /* Mutually recursive subroutines of pascal_object_print_value and
623 c_val_print to print out a structure's fields:
624 pascal_object_print_value_fields and pascal_object_print_value.
626 TYPE, VALADDR, ADDRESS, STREAM, RECURSE, and PRETTY have the
627 same meanings as in pascal_object_print_value and c_val_print.
629 DONT_PRINT is an array of baseclass types that we
630 should not print, or zero if called from top level. */
632 void
633 pascal_object_print_value_fields (struct type *type, const gdb_byte *valaddr,
634 CORE_ADDR address, struct ui_file *stream,
635 int format, int recurse,
636 enum val_prettyprint pretty,
637 struct type **dont_print_vb,
638 int dont_print_statmem)
640 int i, len, n_baseclasses;
641 char *last_dont_print = obstack_next_free (&dont_print_statmem_obstack);
643 CHECK_TYPEDEF (type);
645 fprintf_filtered (stream, "{");
646 len = TYPE_NFIELDS (type);
647 n_baseclasses = TYPE_N_BASECLASSES (type);
649 /* Print out baseclasses such that we don't print
650 duplicates of virtual baseclasses. */
651 if (n_baseclasses > 0)
652 pascal_object_print_value (type, valaddr, address, stream,
653 format, recurse + 1, pretty, dont_print_vb);
655 if (!len && n_baseclasses == 1)
656 fprintf_filtered (stream, "<No data fields>");
657 else
659 struct obstack tmp_obstack = dont_print_statmem_obstack;
660 int fields_seen = 0;
662 if (dont_print_statmem == 0)
664 /* If we're at top level, carve out a completely fresh
665 chunk of the obstack and use that until this particular
666 invocation returns. */
667 obstack_finish (&dont_print_statmem_obstack);
670 for (i = n_baseclasses; i < len; i++)
672 /* If requested, skip printing of static fields. */
673 if (!pascal_static_field_print && TYPE_FIELD_STATIC (type, i))
674 continue;
675 if (fields_seen)
676 fprintf_filtered (stream, ", ");
677 else if (n_baseclasses > 0)
679 if (pretty)
681 fprintf_filtered (stream, "\n");
682 print_spaces_filtered (2 + 2 * recurse, stream);
683 fputs_filtered ("members of ", stream);
684 fputs_filtered (type_name_no_tag (type), stream);
685 fputs_filtered (": ", stream);
688 fields_seen = 1;
690 if (pretty)
692 fprintf_filtered (stream, "\n");
693 print_spaces_filtered (2 + 2 * recurse, stream);
695 else
697 wrap_here (n_spaces (2 + 2 * recurse));
699 if (inspect_it)
701 if (TYPE_CODE (TYPE_FIELD_TYPE (type, i)) == TYPE_CODE_PTR)
702 fputs_filtered ("\"( ptr \"", stream);
703 else
704 fputs_filtered ("\"( nodef \"", stream);
705 if (TYPE_FIELD_STATIC (type, i))
706 fputs_filtered ("static ", stream);
707 fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i),
708 language_cplus,
709 DMGL_PARAMS | DMGL_ANSI);
710 fputs_filtered ("\" \"", stream);
711 fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i),
712 language_cplus,
713 DMGL_PARAMS | DMGL_ANSI);
714 fputs_filtered ("\") \"", stream);
716 else
718 annotate_field_begin (TYPE_FIELD_TYPE (type, i));
720 if (TYPE_FIELD_STATIC (type, i))
721 fputs_filtered ("static ", stream);
722 fprintf_symbol_filtered (stream, TYPE_FIELD_NAME (type, i),
723 language_cplus,
724 DMGL_PARAMS | DMGL_ANSI);
725 annotate_field_name_end ();
726 fputs_filtered (" = ", stream);
727 annotate_field_value ();
730 if (!TYPE_FIELD_STATIC (type, i) && TYPE_FIELD_PACKED (type, i))
732 struct value *v;
734 /* Bitfields require special handling, especially due to byte
735 order problems. */
736 if (TYPE_FIELD_IGNORE (type, i))
738 fputs_filtered ("<optimized out or zero length>", stream);
740 else
742 v = value_from_longest (TYPE_FIELD_TYPE (type, i),
743 unpack_field_as_long (type, valaddr, i));
745 common_val_print (v, stream, format, 0, recurse + 1, pretty);
748 else
750 if (TYPE_FIELD_IGNORE (type, i))
752 fputs_filtered ("<optimized out or zero length>", stream);
754 else if (TYPE_FIELD_STATIC (type, i))
756 /* struct value *v = value_static_field (type, i); v4.17 specific */
757 struct value *v;
758 v = value_from_longest (TYPE_FIELD_TYPE (type, i),
759 unpack_field_as_long (type, valaddr, i));
761 if (v == NULL)
762 fputs_filtered ("<optimized out>", stream);
763 else
764 pascal_object_print_static_field (v, stream, format,
765 recurse + 1, pretty);
767 else
769 /* val_print (TYPE_FIELD_TYPE (type, i),
770 valaddr + TYPE_FIELD_BITPOS (type, i) / 8,
771 address + TYPE_FIELD_BITPOS (type, i) / 8, 0,
772 stream, format, 0, recurse + 1, pretty); */
773 val_print (TYPE_FIELD_TYPE (type, i),
774 valaddr, TYPE_FIELD_BITPOS (type, i) / 8,
775 address + TYPE_FIELD_BITPOS (type, i) / 8,
776 stream, format, 0, recurse + 1, pretty);
779 annotate_field_end ();
782 if (dont_print_statmem == 0)
784 /* Free the space used to deal with the printing
785 of the members from top level. */
786 obstack_free (&dont_print_statmem_obstack, last_dont_print);
787 dont_print_statmem_obstack = tmp_obstack;
790 if (pretty)
792 fprintf_filtered (stream, "\n");
793 print_spaces_filtered (2 * recurse, stream);
796 fprintf_filtered (stream, "}");
799 /* Special val_print routine to avoid printing multiple copies of virtual
800 baseclasses. */
802 static void
803 pascal_object_print_value (struct type *type, const gdb_byte *valaddr,
804 CORE_ADDR address, struct ui_file *stream,
805 int format, int recurse,
806 enum val_prettyprint pretty,
807 struct type **dont_print_vb)
809 struct type **last_dont_print
810 = (struct type **) obstack_next_free (&dont_print_vb_obstack);
811 struct obstack tmp_obstack = dont_print_vb_obstack;
812 int i, n_baseclasses = TYPE_N_BASECLASSES (type);
814 if (dont_print_vb == 0)
816 /* If we're at top level, carve out a completely fresh
817 chunk of the obstack and use that until this particular
818 invocation returns. */
819 /* Bump up the high-water mark. Now alpha is omega. */
820 obstack_finish (&dont_print_vb_obstack);
823 for (i = 0; i < n_baseclasses; i++)
825 int boffset;
826 struct type *baseclass = check_typedef (TYPE_BASECLASS (type, i));
827 char *basename = type_name_no_tag (baseclass);
828 const gdb_byte *base_valaddr;
830 if (BASETYPE_VIA_VIRTUAL (type, i))
832 struct type **first_dont_print
833 = (struct type **) obstack_base (&dont_print_vb_obstack);
835 int j = (struct type **) obstack_next_free (&dont_print_vb_obstack)
836 - first_dont_print;
838 while (--j >= 0)
839 if (baseclass == first_dont_print[j])
840 goto flush_it;
842 obstack_ptr_grow (&dont_print_vb_obstack, baseclass);
845 boffset = baseclass_offset (type, i, valaddr, address);
847 if (pretty)
849 fprintf_filtered (stream, "\n");
850 print_spaces_filtered (2 * recurse, stream);
852 fputs_filtered ("<", stream);
853 /* Not sure what the best notation is in the case where there is no
854 baseclass name. */
856 fputs_filtered (basename ? basename : "", stream);
857 fputs_filtered ("> = ", stream);
859 /* The virtual base class pointer might have been clobbered by the
860 user program. Make sure that it still points to a valid memory
861 location. */
863 if (boffset != -1 && (boffset < 0 || boffset >= TYPE_LENGTH (type)))
865 /* FIXME (alloc): not safe is baseclass is really really big. */
866 gdb_byte *buf = alloca (TYPE_LENGTH (baseclass));
867 base_valaddr = buf;
868 if (target_read_memory (address + boffset, buf,
869 TYPE_LENGTH (baseclass)) != 0)
870 boffset = -1;
872 else
873 base_valaddr = valaddr + boffset;
875 if (boffset == -1)
876 fprintf_filtered (stream, "<invalid address>");
877 else
878 pascal_object_print_value_fields (baseclass, base_valaddr, address + boffset,
879 stream, format, recurse, pretty,
880 (struct type **) obstack_base (&dont_print_vb_obstack),
882 fputs_filtered (", ", stream);
884 flush_it:
888 if (dont_print_vb == 0)
890 /* Free the space used to deal with the printing
891 of this type from top level. */
892 obstack_free (&dont_print_vb_obstack, last_dont_print);
893 /* Reset watermark so that we can continue protecting
894 ourselves from whatever we were protecting ourselves. */
895 dont_print_vb_obstack = tmp_obstack;
899 /* Print value of a static member.
900 To avoid infinite recursion when printing a class that contains
901 a static instance of the class, we keep the addresses of all printed
902 static member classes in an obstack and refuse to print them more
903 than once.
905 VAL contains the value to print, STREAM, RECURSE, and PRETTY
906 have the same meanings as in c_val_print. */
908 static void
909 pascal_object_print_static_field (struct value *val,
910 struct ui_file *stream, int format,
911 int recurse, enum val_prettyprint pretty)
913 struct type *type = value_type (val);
915 if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
917 CORE_ADDR *first_dont_print;
918 int i;
920 first_dont_print
921 = (CORE_ADDR *) obstack_base (&dont_print_statmem_obstack);
922 i = (CORE_ADDR *) obstack_next_free (&dont_print_statmem_obstack)
923 - first_dont_print;
925 while (--i >= 0)
927 if (VALUE_ADDRESS (val) == first_dont_print[i])
929 fputs_filtered ("<same as static member of an already seen type>",
930 stream);
931 return;
935 obstack_grow (&dont_print_statmem_obstack, (char *) &VALUE_ADDRESS (val),
936 sizeof (CORE_ADDR));
938 CHECK_TYPEDEF (type);
939 pascal_object_print_value_fields (type, value_contents (val), VALUE_ADDRESS (val),
940 stream, format, recurse, pretty, NULL, 1);
941 return;
943 common_val_print (val, stream, format, 0, recurse, pretty);
946 extern initialize_file_ftype _initialize_pascal_valprint; /* -Wmissing-prototypes */
948 void
949 _initialize_pascal_valprint (void)
951 add_setshow_boolean_cmd ("pascal_static-members", class_support,
952 &pascal_static_field_print, _("\
953 Set printing of pascal static members."), _("\
954 Show printing of pascal static members."), NULL,
955 NULL,
956 show_pascal_static_field_print,
957 &setprintlist, &showprintlist);
958 /* Turn on printing of static fields. */
959 pascal_static_field_print = 1;