1 /* Print values for GDB, the GNU debugger.
2 Copyright 1986, 1988, 1989, 1991 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
34 /* Prototypes for local functions */
37 print_string
PARAMS ((FILE *, char *, unsigned int, int));
40 show_print
PARAMS ((char *, int));
43 set_print
PARAMS ((char *, int));
46 set_radix
PARAMS ((char *, int, struct cmd_list_element
*));
49 set_output_radix
PARAMS ((char *, int, struct cmd_list_element
*));
52 type_print_base
PARAMS ((struct type
*, FILE *, int, int));
55 type_print_varspec_suffix
PARAMS ((struct type
*, FILE *, int, int));
58 type_print_varspec_prefix
PARAMS ((struct type
*, FILE *, int, int));
61 type_print_derivation_info
PARAMS ((FILE *, struct type
*));
64 type_print_method_args
PARAMS ((struct type
**, char *, char *, int, FILE *));
67 cplus_val_print
PARAMS ((struct type
*, char *, FILE *, int, int,
68 enum val_prettyprint
, struct type
**));
71 val_print_fields
PARAMS ((struct type
*, char *, FILE *, int, int,
72 enum val_prettyprint
, struct type
**));
75 is_vtbl_member
PARAMS ((struct type
*));
78 is_vtbl_ptr_type
PARAMS ((struct type
*));
81 print_hex_chars
PARAMS ((FILE *, unsigned char *, unsigned));
83 extern int demangle
; /* whether to print C++ syms raw or source-form */
85 /* Maximum number of chars to print for a string pointer value
86 or vector contents, or UINT_MAX for no limit. */
88 static unsigned int print_max
;
90 /* Default input and output radixes, and output format letter. */
92 unsigned input_radix
= 10;
93 unsigned output_radix
= 10;
94 int output_format
= 0;
96 /* Print repeat counts if there are more than this
97 many repetitions of an element in an array. */
98 #define REPEAT_COUNT_THRESHOLD 10
100 /* Define a mess of print controls. */
102 int prettyprint
; /* Controls pretty printing of structures */
103 int vtblprint
; /* Controls printing of vtbl's */
104 int unionprint
; /* Controls printing of nested unions. */
105 int arrayprint
; /* Controls pretty printing of arrays. */
106 int addressprint
; /* Controls pretty printing of addresses. */
107 int objectprint
; /* Controls looking up an object's derived type
108 using what we find in its vtables. */
110 struct obstack dont_print_obstack
;
113 /* Print the character string STRING, printing at most LENGTH characters.
114 Printing stops early if the number hits print_max; repeat counts
115 are printed as appropriate. Print ellipses at the end if we
116 had to stop before printing LENGTH characters, or if FORCE_ELLIPSES. */
119 print_string (stream
, string
, length
, force_ellipses
)
125 register unsigned int i
;
126 unsigned int things_printed
= 0;
129 extern int inspect_it
;
133 fputs_filtered ("\"\"", stdout
);
137 for (i
= 0; i
< length
&& things_printed
< print_max
; ++i
)
139 /* Position of the character we are examining
140 to see whether it is repeated. */
142 /* Number of repetitions we have detected so far. */
149 fputs_filtered (", ", stream
);
155 while (rep1
< length
&& string
[rep1
] == string
[i
])
161 if (reps
> REPEAT_COUNT_THRESHOLD
)
166 fputs_filtered ("\\\", ", stream
);
168 fputs_filtered ("\", ", stream
);
171 fputs_filtered ("'", stream
);
172 printchar (string
[i
], stream
, '\'');
173 fprintf_filtered (stream
, "' <repeats %u times>", reps
);
175 things_printed
+= REPEAT_COUNT_THRESHOLD
;
183 fputs_filtered ("\\\"", stream
);
185 fputs_filtered ("\"", stream
);
188 printchar (string
[i
], stream
, '"');
193 /* Terminate the quotes if necessary. */
197 fputs_filtered ("\\\"", stream
);
199 fputs_filtered ("\"", stream
);
202 if (force_ellipses
|| i
< length
)
203 fputs_filtered ("...", stream
);
206 /* Print a floating point value of type TYPE, pointed to in GDB by VALADDR,
210 print_floating (valaddr
, type
, stream
)
217 unsigned len
= TYPE_LENGTH (type
);
219 #if defined (IEEE_FLOAT)
221 /* Check for NaN's. Note that this code does not depend on us being
222 on an IEEE conforming system. It only depends on the target
223 machine using IEEE representation. This means (a)
224 cross-debugging works right, and (2) IEEE_FLOAT can (and should)
225 be defined for systems like the 68881, which uses IEEE
226 representation, but is not IEEE conforming. */
230 /* Is the sign bit 0? */
232 /* Is it is a NaN (i.e. the exponent is all ones and
233 the fraction is nonzero)? */
236 if (len
== sizeof (float))
238 /* It's single precision. */
239 bcopy (valaddr
, &low
, sizeof (low
));
240 /* target -> host. */
241 SWAP_TARGET_AND_HOST (&low
, sizeof (float));
242 nonnegative
= low
>= 0;
243 is_nan
= ((((low
>> 23) & 0xFF) == 0xFF)
244 && 0 != (low
& 0x7FFFFF));
250 /* It's double precision. Get the high and low words. */
252 #if TARGET_BYTE_ORDER == BIG_ENDIAN
253 bcopy (valaddr
+4, &low
, sizeof (low
));
254 bcopy (valaddr
+0, &high
, sizeof (high
));
256 bcopy (valaddr
+0, &low
, sizeof (low
));
257 bcopy (valaddr
+4, &high
, sizeof (high
));
259 SWAP_TARGET_AND_HOST (&low
, sizeof (low
));
260 SWAP_TARGET_AND_HOST (&high
, sizeof (high
));
261 nonnegative
= high
>= 0;
262 is_nan
= (((high
>> 20) & 0x7ff) == 0x7ff
263 && ! ((((high
& 0xfffff) == 0)) && (low
== 0)));
269 /* The meaning of the sign and fraction is not defined by IEEE.
270 But the user might know what they mean. For example, they
271 (in an implementation-defined manner) distinguish between
272 signaling and quiet NaN's. */
274 fprintf_filtered (stream
, "-NaN(0x%lx%.8lx)" + nonnegative
,
277 fprintf_filtered (stream
, "-NaN(0x%lx)" + nonnegative
, low
);
281 #endif /* IEEE_FLOAT. */
283 doub
= unpack_double (type
, valaddr
, &inv
);
285 fprintf_filtered (stream
, "<invalid float value>");
287 fprintf_filtered (stream
, len
<= sizeof(float) ? "%.9g" : "%.17g", doub
);
290 /* VALADDR points to an integer of LEN bytes. Print it in hex on stream. */
292 print_hex_chars (stream
, valaddr
, len
)
294 unsigned char *valaddr
;
299 fprintf_filtered (stream
, "0x");
300 #if TARGET_BYTE_ORDER == BIG_ENDIAN
304 #else /* Little endian. */
305 for (p
= valaddr
+ len
- 1;
310 fprintf_filtered (stream
, "%02x", *p
);
314 /* Print the value VAL in C-ish syntax on stream STREAM.
315 FORMAT is a format-letter, or 0 for print in natural format of data type.
316 If the object printed is a string pointer, returns
317 the number of string bytes printed. */
320 value_print (val
, stream
, format
, pretty
)
324 enum val_prettyprint pretty
;
326 register unsigned int i
, n
, typelen
;
330 printf_filtered ("<address of value unknown>");
333 if (VALUE_OPTIMIZED_OUT (val
))
335 printf_filtered ("<value optimized out>");
339 /* A "repeated" value really contains several values in a row.
340 They are made by the @ operator.
341 Print such values as if they were arrays. */
343 else if (VALUE_REPEATED (val
))
345 n
= VALUE_REPETITIONS (val
);
346 typelen
= TYPE_LENGTH (VALUE_TYPE (val
));
347 fprintf_filtered (stream
, "{");
348 /* Print arrays of characters using string syntax. */
349 if (typelen
== 1 && TYPE_CODE (VALUE_TYPE (val
)) == TYPE_CODE_INT
351 print_string (stream
, VALUE_CONTENTS (val
), n
, 0);
354 unsigned int things_printed
= 0;
356 for (i
= 0; i
< n
&& things_printed
< print_max
; i
++)
358 /* Position of the array element we are examining to see
359 whether it is repeated. */
361 /* Number of repetitions we have detected so far. */
365 fprintf_filtered (stream
, ", ");
371 && !bcmp (VALUE_CONTENTS (val
) + typelen
* i
,
372 VALUE_CONTENTS (val
) + typelen
* rep1
, typelen
))
378 if (reps
> REPEAT_COUNT_THRESHOLD
)
380 val_print (VALUE_TYPE (val
),
381 VALUE_CONTENTS (val
) + typelen
* i
,
382 VALUE_ADDRESS (val
) + typelen
* i
,
383 stream
, format
, 1, 0, pretty
);
384 fprintf (stream
, " <repeats %u times>", reps
);
386 things_printed
+= REPEAT_COUNT_THRESHOLD
;
390 val_print (VALUE_TYPE (val
),
391 VALUE_CONTENTS (val
) + typelen
* i
,
392 VALUE_ADDRESS (val
) + typelen
* i
,
393 stream
, format
, 1, 0, pretty
);
398 fprintf_filtered (stream
, "...");
400 fprintf_filtered (stream
, "}");
405 struct type
*type
= VALUE_TYPE (val
);
407 /* If it is a pointer, indicate what it points to.
409 Print type also if it is a reference.
411 C++: if it is a member pointer, we will take care
412 of that when we print it. */
413 if (TYPE_CODE (type
) == TYPE_CODE_PTR
414 || TYPE_CODE (type
) == TYPE_CODE_REF
)
416 /* Hack: remove (char *) for char strings. Their
417 type is indicated by the quoted string anyway. */
418 if (TYPE_CODE (type
) == TYPE_CODE_PTR
419 && TYPE_LENGTH (TYPE_TARGET_TYPE (type
)) == sizeof(char)
420 && TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_INT
421 && !TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
)))
427 fprintf_filtered (stream
, "(");
428 type_print (type
, "", stream
, -1);
429 fprintf_filtered (stream
, ") ");
432 return val_print (type
, VALUE_CONTENTS (val
),
433 VALUE_ADDRESS (val
), stream
, format
, 1, 0, pretty
);
437 /* Return truth value for assertion that TYPE is of the type
438 "pointer to virtual function". */
440 is_vtbl_ptr_type(type
)
443 char *typename
= type_name_no_tag (type
);
444 static const char vtbl_ptr_name
[] =
445 { CPLUS_MARKER
,'v','t','b','l','_','p','t','r','_','t','y','p','e', 0 };
447 return (typename
!= NULL
&& !strcmp(typename
, vtbl_ptr_name
));
450 /* Return truth value for the assertion that TYPE is of the type
451 "pointer to virtual function table". */
456 if (TYPE_CODE (type
) == TYPE_CODE_PTR
)
457 type
= TYPE_TARGET_TYPE (type
);
461 if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
462 && TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_STRUCT
)
463 /* Virtual functions tables are full of pointers to virtual functions. */
464 return is_vtbl_ptr_type (TYPE_TARGET_TYPE (type
));
468 /* Mutually recursive subroutines of cplus_val_print and val_print to print out
469 a structure's fields: val_print_fields and cplus_val_print.
471 TYPE, VALADDR, STREAM, RECURSE, and PRETTY have the
472 same meanings as in cplus_val_print and val_print.
474 DONT_PRINT is an array of baseclass types that we
475 should not print, or zero if called from top level. */
478 val_print_fields (type
, valaddr
, stream
, format
, recurse
, pretty
, dont_print
)
484 enum val_prettyprint pretty
;
485 struct type
**dont_print
;
487 int i
, len
, n_baseclasses
;
489 check_stub_type (type
);
491 fprintf_filtered (stream
, "{");
492 len
= TYPE_NFIELDS (type
);
493 n_baseclasses
= TYPE_N_BASECLASSES (type
);
495 /* Print out baseclasses such that we don't print
496 duplicates of virtual baseclasses. */
497 if (n_baseclasses
> 0)
498 cplus_val_print (type
, valaddr
, stream
, format
, recurse
+1, pretty
, dont_print
);
500 if (!len
&& n_baseclasses
== 1)
501 fprintf_filtered (stream
, "<No data fields>");
504 extern int inspect_it
;
507 for (i
= n_baseclasses
; i
< len
; i
++)
509 /* Check if static field */
510 if (TYPE_FIELD_STATIC (type
, i
))
513 fprintf_filtered (stream
, ", ");
514 else if (n_baseclasses
> 0)
516 fprintf_filtered (stream
, "\n");
517 print_spaces_filtered (2 + 2 * recurse
, stream
);
518 fputs_filtered ("members of ", stream
);
519 fputs_filtered (type_name_no_tag (type
), stream
);
520 fputs_filtered (": ", stream
);
526 fprintf_filtered (stream
, "\n");
527 print_spaces_filtered (2 + 2 * recurse
, stream
);
531 wrap_here (n_spaces (2 + 2 * recurse
));
535 if (TYPE_CODE (TYPE_FIELD_TYPE (type
, i
)) == TYPE_CODE_PTR
)
536 fputs_filtered ("\"( ptr \"", stream
);
538 fputs_filtered ("\"( nodef \"", stream
);
539 fputs_filtered (TYPE_FIELD_NAME (type
, i
), stream
);
540 fputs_filtered ("\" \"", stream
);
541 fputs_filtered (TYPE_FIELD_NAME (type
, i
), stream
);
542 fputs_filtered ("\") \"", stream
);
546 fputs_filtered (TYPE_FIELD_NAME (type
, i
), stream
);
547 fputs_filtered (" = ", stream
);
549 if (TYPE_FIELD_PACKED (type
, i
))
553 /* Bitfields require special handling, especially due to byte
555 v
= value_from_longest (TYPE_FIELD_TYPE (type
, i
),
556 unpack_field_as_long (type
, valaddr
, i
));
558 val_print (TYPE_FIELD_TYPE (type
, i
), VALUE_CONTENTS (v
), 0,
559 stream
, format
, 0, recurse
+ 1, pretty
);
563 val_print (TYPE_FIELD_TYPE (type
, i
),
564 valaddr
+ TYPE_FIELD_BITPOS (type
, i
) / 8,
565 0, stream
, format
, 0, recurse
+ 1, pretty
);
570 fprintf_filtered (stream
, "\n");
571 print_spaces_filtered (2 * recurse
, stream
);
574 fprintf_filtered (stream
, "}");
577 /* Special val_print routine to avoid printing multiple copies of virtual
581 cplus_val_print (type
, valaddr
, stream
, format
, recurse
, pretty
, dont_print
)
587 enum val_prettyprint pretty
;
588 struct type
**dont_print
;
590 struct obstack tmp_obstack
;
591 struct type
**last_dont_print
592 = (struct type
**)obstack_next_free (&dont_print_obstack
);
593 int i
, n_baseclasses
= TYPE_N_BASECLASSES (type
);
597 /* If we're at top level, carve out a completely fresh
598 chunk of the obstack and use that until this particular
599 invocation returns. */
600 tmp_obstack
= dont_print_obstack
;
601 /* Bump up the high-water mark. Now alpha is omega. */
602 obstack_finish (&dont_print_obstack
);
605 for (i
= 0; i
< n_baseclasses
; i
++)
610 if (BASETYPE_VIA_VIRTUAL (type
, i
))
612 struct type
**first_dont_print
613 = (struct type
**)obstack_base (&dont_print_obstack
);
615 int j
= (struct type
**)obstack_next_free (&dont_print_obstack
)
619 if (TYPE_BASECLASS (type
, i
) == first_dont_print
[j
])
622 obstack_ptr_grow (&dont_print_obstack
, TYPE_BASECLASS (type
, i
));
625 baddr
= baseclass_addr (type
, i
, valaddr
, 0, &err
);
626 if (err
== 0 && baddr
== 0)
627 error ("could not find virtual baseclass `%s'\n",
628 type_name_no_tag (TYPE_BASECLASS (type
, i
)));
630 fprintf_filtered (stream
, "\n");
632 print_spaces_filtered (2 + 2 * recurse
, stream
);
633 fputs_filtered ("<", stream
);
634 fputs_filtered (type_name_no_tag (TYPE_BASECLASS (type
, i
)), stream
);
635 fputs_filtered ("> = ", stream
);
637 fprintf_filtered (stream
, "<invalid address 0x%x>", baddr
);
639 val_print_fields (TYPE_BASECLASS (type
, i
), baddr
, stream
, format
,
641 (struct type
**)obstack_base (&dont_print_obstack
));
648 /* Free the space used to deal with the printing
649 of this type from top level. */
650 obstack_free (&dont_print_obstack
, last_dont_print
);
651 /* Reset watermark so that we can continue protecting
652 ourselves from whatever we were protecting ourselves. */
653 dont_print_obstack
= tmp_obstack
;
658 print_class_member (valaddr
, domain
, stream
, prefix
)
665 /* VAL is a byte offset into the structure type DOMAIN.
666 Find the name of the field for that offset and
670 register unsigned int i
;
671 unsigned len
= TYPE_NFIELDS (domain
);
672 /* @@ Make VAL into bit offset */
673 LONGEST val
= unpack_long (builtin_type_int
, valaddr
) << 3;
674 for (i
= TYPE_N_BASECLASSES (domain
); i
< len
; i
++)
676 int bitpos
= TYPE_FIELD_BITPOS (domain
, i
);
680 if (val
< bitpos
&& i
!= 0)
682 /* Somehow pointing into a field. */
684 extra
= (val
- TYPE_FIELD_BITPOS (domain
, i
));
695 fprintf_filtered (stream
, prefix
);
696 name
= type_name_no_tag (domain
);
698 fputs_filtered (name
, stream
);
700 type_print_base (domain
, stream
, 0, 0);
701 fprintf_filtered (stream
, "::");
702 fputs_filtered (TYPE_FIELD_NAME (domain
, i
), stream
);
704 fprintf_filtered (stream
, " + %d bytes", extra
);
706 fprintf_filtered (stream
, " (offset in bits)");
709 fprintf_filtered (stream
, "%d", val
>> 3);
712 /* Print data of type TYPE located at VALADDR (within GDB),
713 which came from the inferior at address ADDRESS,
714 onto stdio stream STREAM according to FORMAT
715 (a letter or 0 for natural format). The data at VALADDR
716 is in target byte order.
718 If the data are a string pointer, returns the number of
719 sting characters printed.
721 if DEREF_REF is nonzero, then dereference references,
722 otherwise just print them like pointers.
724 The PRETTY parameter controls prettyprinting. */
727 val_print (type
, valaddr
, address
, stream
, format
, deref_ref
, recurse
, pretty
)
735 enum val_prettyprint pretty
;
737 register unsigned int i
;
739 struct type
*elttype
;
744 if (pretty
== Val_pretty_default
)
746 pretty
= prettyprint
? Val_prettyprint
: Val_no_prettyprint
;
751 check_stub_type (type
);
753 if (TYPE_FLAGS (type
) & TYPE_FLAG_STUB
)
755 fprintf_filtered (stream
, "<unknown struct>");
760 switch (TYPE_CODE (type
))
762 case TYPE_CODE_ARRAY
:
763 if (TYPE_LENGTH (type
) > 0
764 && TYPE_LENGTH (TYPE_TARGET_TYPE (type
)) > 0)
766 elttype
= TYPE_TARGET_TYPE (type
);
767 eltlen
= TYPE_LENGTH (elttype
);
768 len
= TYPE_LENGTH (type
) / eltlen
;
770 print_spaces_filtered (2 + 2 * recurse
, stream
);
771 fprintf_filtered (stream
, "{");
772 /* For an array of chars, print with string syntax. */
773 if (eltlen
== 1 && TYPE_CODE (elttype
) == TYPE_CODE_INT
774 && (format
== 0 || format
== 's') )
775 print_string (stream
, valaddr
, len
, 0);
778 unsigned int things_printed
= 0;
780 /* If this is a virtual function table, print the 0th
781 entry specially, and the rest of the members normally. */
782 if (is_vtbl_ptr_type (elttype
))
784 fprintf_filtered (stream
, "%d vtable entries", len
-1);
790 for (; i
< len
&& things_printed
< print_max
; i
++)
792 /* Position of the array element we are examining to see
793 whether it is repeated. */
795 /* Number of repetitions we have detected so far. */
801 fprintf_filtered (stream
, ",\n");
802 print_spaces_filtered (2 + 2 * recurse
, stream
);
805 fprintf_filtered (stream
, ", ");
806 wrap_here (n_spaces (2 + 2 * recurse
));
811 && !bcmp (valaddr
+ i
* eltlen
,
812 valaddr
+ rep1
* eltlen
, eltlen
))
818 if (reps
> REPEAT_COUNT_THRESHOLD
)
820 val_print (elttype
, valaddr
+ i
* eltlen
,
821 0, stream
, format
, deref_ref
,
822 recurse
+ 1, pretty
);
823 fprintf_filtered (stream
, " <repeats %u times>", reps
);
825 things_printed
+= REPEAT_COUNT_THRESHOLD
;
829 val_print (elttype
, valaddr
+ i
* eltlen
,
830 0, stream
, format
, deref_ref
,
831 recurse
+ 1, pretty
);
836 fprintf_filtered (stream
, "...");
838 fprintf_filtered (stream
, "}");
841 /* Array of unspecified length: treat like pointer to first elt. */
842 valaddr
= (char *) &address
;
845 if (format
&& format
!= 's')
847 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
850 if (TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_METHOD
)
852 struct type
*domain
= TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (type
));
858 addr
= unpack_pointer (lookup_pointer_type (builtin_type_void
),
860 if (addr
< 128) /* FIXME! What is this 128? */
862 len
= TYPE_NFN_FIELDS (domain
);
863 for (i
= 0; i
< len
; i
++)
865 f
= TYPE_FN_FIELDLIST1 (domain
, i
);
866 len2
= TYPE_FN_FIELDLIST_LENGTH (domain
, i
);
868 for (j
= 0; j
< len2
; j
++)
871 if (TYPE_FN_FIELD_VOFFSET (f
, j
) == addr
)
881 struct symbol
*sym
= find_pc_function (addr
);
883 error ("invalid pointer to member function");
884 len
= TYPE_NFN_FIELDS (domain
);
885 for (i
= 0; i
< len
; i
++)
887 f
= TYPE_FN_FIELDLIST1 (domain
, i
);
888 len2
= TYPE_FN_FIELDLIST_LENGTH (domain
, i
);
890 for (j
= 0; j
< len2
; j
++)
893 if (!strcmp (SYMBOL_NAME (sym
), TYPE_FN_FIELD_PHYSNAME (f
, j
)))
901 fprintf_filtered (stream
, "&");
902 type_print_varspec_prefix (TYPE_FN_FIELD_TYPE (f
, j
), stream
, 0, 0);
903 fprintf (stream
, kind
);
904 if (TYPE_FN_FIELD_PHYSNAME (f
, j
)[0] == '_'
905 && TYPE_FN_FIELD_PHYSNAME (f
, j
)[1] == CPLUS_MARKER
)
906 type_print_method_args
907 (TYPE_FN_FIELD_ARGS (f
, j
) + 1, "~",
908 TYPE_FN_FIELDLIST_NAME (domain
, i
), 0, stream
);
910 type_print_method_args
911 (TYPE_FN_FIELD_ARGS (f
, j
), "",
912 TYPE_FN_FIELDLIST_NAME (domain
, i
), 0, stream
);
915 fprintf_filtered (stream
, "(");
916 type_print (type
, "", stream
, -1);
917 fprintf_filtered (stream
, ") %d", (int) addr
>> 3);
919 else if (TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_MEMBER
)
921 print_class_member (valaddr
,
922 TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (type
)),
927 CORE_ADDR addr
= unpack_pointer (type
, valaddr
);
928 elttype
= TYPE_TARGET_TYPE (type
);
930 if (TYPE_CODE (elttype
) == TYPE_CODE_FUNC
)
932 /* Try to print what function it points to. */
933 print_address_demangle (addr
, stream
, demangle
);
934 /* Return value is irrelevant except for string pointers. */
938 if (addressprint
&& format
!= 's')
939 fprintf_filtered (stream
, "0x%x", addr
);
941 /* For a pointer to char or unsigned char,
942 also print the string pointed to, unless pointer is null. */
943 i
= 0; /* Number of characters printed. */
944 if (TYPE_LENGTH (elttype
) == 1
945 && TYPE_CODE (elttype
) == TYPE_CODE_INT
946 && (format
== 0 || format
== 's')
948 /* If print_max is UINT_MAX, the alloca below will fail.
949 In that case don't try to print the string. */
950 && print_max
< UINT_MAX
)
952 int first_addr_err
= 0;
955 /* Get first character. */
956 errcode
= target_read_memory (addr
, (char *)&c
, 1);
959 /* First address out of bounds. */
965 char *string
= (char *) alloca (print_max
);
967 /* If the loop ends by us hitting print_max characters,
968 we need to have elipses at the end. */
969 int force_ellipses
= 1;
971 /* This loop always fetches print_max characters, even
972 though print_string might want to print more or fewer
973 (with repeated characters). This is so that
974 we don't spend forever fetching if we print
975 a long string consisting of the same character
976 repeated. Also so we can do it all in one memory
977 operation, which is faster. However, this will be
978 slower if print_max is set high, e.g. if you set
979 print_max to 1000, not only will it take a long
980 time to fetch short strings, but if you are near
981 the end of the address space, it might not work. */
983 errcode
= target_read_memory (addr
, string
, print_max
);
986 /* Try reading just one character. If that succeeds,
987 assume we hit the end of the address space, but
988 the initial part of the string is probably safe. */
990 errcode
= target_read_memory (addr
, x
, 1);
995 for (i
= 0; i
< print_max
; i
++)
996 if (string
[i
] == '\0')
1004 fputs_filtered (" ", stream
);
1005 print_string (stream
, string
, i
, force_ellipses
);
1012 fprintf_filtered (stream
,
1013 (" <Address 0x%x out of bounds>"
1019 error ("Error reading memory address 0x%x: %s.",
1020 addr
+ i
, safe_strerror (errcode
));
1026 else /* print vtbl's nicely */
1027 if (is_vtbl_member(type
))
1029 CORE_ADDR vt_address
= unpack_pointer (type
, valaddr
);
1031 struct minimal_symbol
*msymbol
=
1032 lookup_minimal_symbol_by_pc (vt_address
);
1033 if ((msymbol
!= NULL
) && (vt_address
== msymbol
-> address
))
1035 fputs_filtered (" <", stream
);
1036 fputs_demangled (msymbol
-> name
, stream
,
1037 DMGL_ANSI
| DMGL_PARAMS
);
1038 fputs_filtered (">", stream
);
1044 vt_val
= value_at (TYPE_TARGET_TYPE (type
), vt_address
);
1045 val_print (VALUE_TYPE (vt_val
), VALUE_CONTENTS (vt_val
),
1046 VALUE_ADDRESS (vt_val
), stream
, format
,
1047 deref_ref
, recurse
+ 1, pretty
);
1050 fprintf_filtered (stream
, "\n");
1051 print_spaces_filtered (2 + 2 * recurse
, stream
);
1056 /* Return number of characters printed, plus one for the
1057 terminating null if we have "reached the end". */
1058 return i
+ (print_max
&& i
!= print_max
);
1062 case TYPE_CODE_MEMBER
:
1063 error ("not implemented: member type in val_print");
1067 if (TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_MEMBER
)
1069 print_class_member (valaddr
,
1070 TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (type
)),
1076 fprintf_filtered (stream
, "@0x%lx",
1077 unpack_long (builtin_type_int
, valaddr
));
1079 fputs_filtered (": ", stream
);
1081 /* De-reference the reference. */
1084 if (TYPE_CODE (TYPE_TARGET_TYPE (type
)) != TYPE_CODE_UNDEF
)
1088 (TYPE_TARGET_TYPE (type
),
1089 unpack_pointer (lookup_pointer_type (builtin_type_void
),
1091 val_print (VALUE_TYPE (deref_val
), VALUE_CONTENTS (deref_val
),
1092 VALUE_ADDRESS (deref_val
), stream
, format
,
1093 deref_ref
, recurse
+ 1, pretty
);
1096 fputs_filtered ("???", stream
);
1100 case TYPE_CODE_UNION
:
1101 if (recurse
&& !unionprint
)
1103 fprintf_filtered (stream
, "{...}");
1107 case TYPE_CODE_STRUCT
:
1108 if (vtblprint
&& is_vtbl_ptr_type(type
))
1110 /* Print the unmangled name if desired. */
1111 print_address_demangle(*((int *) (valaddr
+ /* FIXME bytesex */
1112 TYPE_FIELD_BITPOS (type
, VTBL_FNADDR_OFFSET
) / 8)),
1116 val_print_fields (type
, valaddr
, stream
, format
, recurse
, pretty
, 0);
1119 case TYPE_CODE_ENUM
:
1122 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
1125 len
= TYPE_NFIELDS (type
);
1126 val
= unpack_long (builtin_type_int
, valaddr
);
1127 for (i
= 0; i
< len
; i
++)
1130 if (val
== TYPE_FIELD_BITPOS (type
, i
))
1134 fputs_filtered (TYPE_FIELD_NAME (type
, i
), stream
);
1137 fprintf_filtered (stream
, "%lld", val
);
1139 fprintf_filtered (stream
, "%ld", val
);
1143 case TYPE_CODE_FUNC
:
1146 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
1149 /* FIXME, we should consider, at least for ANSI C language, eliminating
1150 the distinction made between FUNCs and POINTERs to FUNCs. */
1151 fprintf_filtered (stream
, "{");
1152 type_print (type
, "", stream
, -1);
1153 fprintf_filtered (stream
, "} ");
1154 /* Try to print what function it points to, and its address. */
1155 print_address_demangle (address
, stream
, demangle
);
1159 if (format
|| output_format
)
1161 print_scalar_formatted (valaddr
, type
,
1162 format
? format
: output_format
,
1166 if (TYPE_LENGTH (type
) > sizeof (LONGEST
))
1168 if (TYPE_UNSIGNED (type
))
1170 /* First figure out whether the number in fact has zeros
1171 in all its bytes more significant than least significant
1172 sizeof (LONGEST) ones. */
1174 /* Pointer to first (i.e. lowest address) nonzero character. */
1176 len
= TYPE_LENGTH (type
);
1178 #if TARGET_BYTE_ORDER == BIG_ENDIAN
1180 len
> sizeof (LONGEST
)
1181 && p
< valaddr
+ TYPE_LENGTH (type
);
1183 #else /* Little endian. */
1184 first_addr
= valaddr
;
1185 for (p
= valaddr
+ TYPE_LENGTH (type
);
1186 len
> sizeof (LONGEST
) && p
>= valaddr
;
1188 #endif /* Little endian. */
1195 #if TARGET_BYTE_ORDER == BIG_ENDIAN
1199 if (len
<= sizeof (LONGEST
))
1201 /* We can print it in decimal. */
1204 #if defined (LONG_LONG)
1209 unpack_long (BUILTIN_TYPE_LONGEST
, first_addr
));
1213 /* It is big, so print it in hex. */
1214 print_hex_chars (stream
, (unsigned char *)first_addr
, len
);
1219 /* Signed. One could assume two's complement (a reasonable
1220 assumption, I think) and do better than this. */
1221 print_hex_chars (stream
, (unsigned char *)valaddr
,
1222 TYPE_LENGTH (type
));
1226 #ifdef PRINT_TYPELESS_INTEGER
1227 PRINT_TYPELESS_INTEGER (stream
, type
, unpack_long (type
, valaddr
));
1230 fprintf_filtered (stream
,
1231 TYPE_UNSIGNED (type
) ? "%u" : "%d",
1232 unpack_long (type
, valaddr
));
1234 fprintf_filtered (stream
,
1235 TYPE_UNSIGNED (type
) ? "%llu" : "%lld",
1236 unpack_long (type
, valaddr
));
1240 if (TYPE_LENGTH (type
) == 1)
1242 fprintf_filtered (stream
, " '");
1243 printchar ((unsigned char) unpack_long (type
, valaddr
),
1245 fprintf_filtered (stream
, "'");
1251 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
1253 print_floating (valaddr
, type
, stream
);
1256 case TYPE_CODE_VOID
:
1257 fprintf_filtered (stream
, "void");
1260 case TYPE_CODE_UNDEF
:
1261 /* This happens (without TYPE_FLAG_STUB set) on systems which don't use
1262 dbx xrefs (NO_DBX_XREFS in gcc) if a file has a "struct foo *bar"
1263 and no complete type for struct foo in that file. */
1264 fprintf_filtered (stream
, "<unknown struct>");
1267 case TYPE_CODE_ERROR
:
1268 fprintf_filtered (stream
, "?");
1271 case TYPE_CODE_RANGE
:
1272 /* FIXME, we should not ever have to print one of these yet. */
1273 fprintf_filtered (stream
, "<range type>");
1277 error ("Invalid type code in symbol table.");
1283 /* Print a description of a type in the format of a
1284 typedef for the current language.
1285 NEW is the new name for a type TYPE. */
1287 typedef_print (type
, new, stream
)
1292 switch (current_language
->la_language
)
1296 case language_cplus
:
1297 fprintf_filtered(stream
, "typedef ");
1298 type_print(type
,"",stream
,0);
1299 if(TYPE_NAME ((SYMBOL_TYPE (new))) == 0
1300 || 0 != strcmp (TYPE_NAME ((SYMBOL_TYPE (new))),
1302 fprintf_filtered(stream
, " %s", SYMBOL_NAME(new));
1307 fprintf_filtered(stream
, "TYPE ");
1308 if(!TYPE_NAME(SYMBOL_TYPE(new)) ||
1309 strcmp (TYPE_NAME(SYMBOL_TYPE(new)),
1311 fprintf_filtered(stream
, "%s = ", SYMBOL_NAME(new));
1313 fprintf_filtered(stream
, "<builtin> = ");
1314 type_print(type
,"",stream
,0);
1318 error("Language not supported.");
1320 fprintf_filtered(stream
, ";\n");
1324 /* Print a description of a type TYPE
1325 in the form of a declaration of a variable named VARSTRING.
1326 (VARSTRING is demangled if necessary.)
1327 Output goes to STREAM (via stdio).
1328 If SHOW is positive, we show the contents of the outermost level
1329 of structure even if there is a type name that could be used instead.
1330 If SHOW is negative, we never show the details of elements' types. */
1333 type_print (type
, varstring
, stream
, show
)
1339 type_print_1 (type
, varstring
, stream
, show
, 0);
1342 /* LEVEL is the depth to indent lines by. */
1345 type_print_1 (type
, varstring
, stream
, show
, level
)
1352 register enum type_code code
;
1353 type_print_base (type
, stream
, show
, level
);
1354 code
= TYPE_CODE (type
);
1355 if ((varstring
&& *varstring
)
1357 /* Need a space if going to print stars or brackets;
1358 but not if we will print just a type name. */
1359 ((show
> 0 || TYPE_NAME (type
) == 0)
1361 (code
== TYPE_CODE_PTR
|| code
== TYPE_CODE_FUNC
1362 || code
== TYPE_CODE_METHOD
1363 || code
== TYPE_CODE_ARRAY
1364 || code
== TYPE_CODE_MEMBER
1365 || code
== TYPE_CODE_REF
)))
1366 fprintf_filtered (stream
, " ");
1367 type_print_varspec_prefix (type
, stream
, show
, 0);
1368 /* FIXME: Previously this printed demangled names without function args,
1369 which is a lose since you can't distinguish between overloaded function
1370 names (try "info func" for example). This change is still not optimal,
1371 since you now get a superflous pair of parens for functions, but at
1372 least you can distinguish them. */
1373 fputs_demangled (varstring
, stream
, DMGL_PARAMS
);
1374 type_print_varspec_suffix (type
, stream
, show
, 0);
1377 /* Print the method arguments ARGS to the file STREAM. */
1379 type_print_method_args (args
, prefix
, varstring
, staticp
, stream
)
1381 char *prefix
, *varstring
;
1387 fputs_demangled (prefix
, stream
, DMGL_ANSI
| DMGL_PARAMS
);
1388 fputs_demangled (varstring
, stream
, DMGL_ANSI
| DMGL_PARAMS
);
1389 fputs_filtered (" (", stream
);
1390 if (args
&& args
[!staticp
] && args
[!staticp
]->code
!= TYPE_CODE_VOID
)
1392 i
= !staticp
; /* skip the class variable */
1395 type_print (args
[i
++], "", stream
, 0);
1398 fprintf_filtered (stream
, " ...");
1401 else if (args
[i
]->code
!= TYPE_CODE_VOID
)
1403 fprintf_filtered (stream
, ", ");
1408 fprintf_filtered (stream
, ")");
1411 /* If TYPE is a derived type, then print out derivation
1412 information. Print out all layers of the type heirarchy
1413 until we encounter one with multiple inheritance.
1414 At that point, print out that ply, and return. */
1416 type_print_derivation_info (stream
, type
)
1421 int i
, n_baseclasses
= TYPE_N_BASECLASSES (type
);
1422 struct type
*basetype
= 0;
1424 while (type
&& n_baseclasses
> 0)
1426 /* Not actually sure about this one -- Bryan. */
1427 check_stub_type (type
);
1429 fprintf_filtered (stream
, ": ");
1432 basetype
= TYPE_BASECLASS (type
, i
);
1433 if (name
= type_name_no_tag (basetype
))
1435 fprintf_filtered (stream
, "%s%s ",
1436 BASETYPE_VIA_PUBLIC(type
, i
) ? "public" : "private",
1437 BASETYPE_VIA_VIRTUAL(type
, i
) ? " virtual" : "");
1438 fputs_filtered (name
, stream
);
1441 if (i
>= n_baseclasses
)
1443 fprintf_filtered (stream
, ", ");
1446 fprintf_filtered (stream
, " ");
1447 if (n_baseclasses
!= 1)
1449 n_baseclasses
= TYPE_N_BASECLASSES (basetype
);
1454 /* Print any asterisks or open-parentheses needed before the
1455 variable name (to describe its type).
1457 On outermost call, pass 0 for PASSED_A_PTR.
1458 On outermost call, SHOW > 0 means should ignore
1459 any typename for TYPE and show its details.
1460 SHOW is always zero on recursive calls. */
1463 type_print_varspec_prefix (type
, stream
, show
, passed_a_ptr
)
1473 if (TYPE_NAME (type
) && show
<= 0)
1478 switch (TYPE_CODE (type
))
1481 type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0, 1);
1482 fprintf_filtered (stream
, "*");
1485 case TYPE_CODE_MEMBER
:
1487 fprintf_filtered (stream
, "(");
1488 type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0,
1490 fprintf_filtered (stream
, " ");
1491 name
= type_name_no_tag (TYPE_DOMAIN_TYPE (type
));
1493 fputs_filtered (name
, stream
);
1495 type_print_base (TYPE_DOMAIN_TYPE (type
), stream
, 0, passed_a_ptr
);
1496 fprintf_filtered (stream
, "::");
1499 case TYPE_CODE_METHOD
:
1501 fprintf (stream
, "(");
1502 type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0,
1506 fprintf_filtered (stream
, " ");
1507 type_print_base (TYPE_DOMAIN_TYPE (type
), stream
, 0,
1509 fprintf_filtered (stream
, "::");
1514 type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0, 1);
1515 fprintf_filtered (stream
, "&");
1518 case TYPE_CODE_FUNC
:
1519 type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0,
1522 fprintf_filtered (stream
, "(");
1525 case TYPE_CODE_ARRAY
:
1526 type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0,
1529 fprintf_filtered (stream
, "(");
1532 case TYPE_CODE_UNDEF
:
1533 case TYPE_CODE_STRUCT
:
1534 case TYPE_CODE_UNION
:
1535 case TYPE_CODE_ENUM
:
1538 case TYPE_CODE_VOID
:
1539 case TYPE_CODE_ERROR
:
1540 case TYPE_CODE_CHAR
:
1541 case TYPE_CODE_BOOL
:
1542 /* These types need no prefix. They are listed here so that
1543 gcc -Wall will reveal any types that haven't been handled. */
1548 /* Print any array sizes, function arguments or close parentheses
1549 needed after the variable name (to describe its type).
1550 Args work like type_print_varspec_prefix. */
1553 type_print_varspec_suffix (type
, stream
, show
, passed_a_ptr
)
1562 if (TYPE_NAME (type
) && show
<= 0)
1567 switch (TYPE_CODE (type
))
1569 case TYPE_CODE_ARRAY
:
1571 fprintf_filtered (stream
, ")");
1573 fprintf_filtered (stream
, "[");
1574 if (TYPE_LENGTH (type
) > 0
1575 && TYPE_LENGTH (TYPE_TARGET_TYPE (type
)) > 0)
1576 fprintf_filtered (stream
, "%d",
1578 / TYPE_LENGTH (TYPE_TARGET_TYPE (type
))));
1579 fprintf_filtered (stream
, "]");
1581 type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0,
1585 case TYPE_CODE_MEMBER
:
1587 fprintf_filtered (stream
, ")");
1588 type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0, 0);
1591 case TYPE_CODE_METHOD
:
1593 fprintf_filtered (stream
, ")");
1594 type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0, 0);
1598 struct type
**args
= TYPE_ARG_TYPES (type
);
1600 fprintf_filtered (stream
, "(");
1602 fprintf_filtered (stream
, "...");
1603 else for (i
= 1; args
[i
] != 0 && args
[i
]->code
!= TYPE_CODE_VOID
; i
++)
1605 type_print_1 (args
[i
], "", stream
, -1, 0);
1607 fprintf_filtered (stream
, "...");
1608 else if (args
[i
+1]->code
!= TYPE_CODE_VOID
) {
1609 fprintf_filtered (stream
, ",");
1613 fprintf_filtered (stream
, ")");
1619 type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0, 1);
1622 case TYPE_CODE_FUNC
:
1623 type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0,
1626 fprintf_filtered (stream
, ")");
1627 fprintf_filtered (stream
, "()");
1630 case TYPE_CODE_UNDEF
:
1631 case TYPE_CODE_STRUCT
:
1632 case TYPE_CODE_UNION
:
1633 case TYPE_CODE_ENUM
:
1636 case TYPE_CODE_VOID
:
1637 case TYPE_CODE_ERROR
:
1638 case TYPE_CODE_CHAR
:
1639 case TYPE_CODE_BOOL
:
1640 /* These types do not need a suffix. They are listed so that
1641 gcc -Wall will report types that may not have been considered. */
1646 /* Print the name of the type (or the ultimate pointer target,
1647 function value or array element), or the description of a
1650 SHOW nonzero means don't print this type as just its name;
1651 show its real definition even if it has a name.
1652 SHOW zero means print just typename or struct tag if there is one
1653 SHOW negative means abbreviate structure elements.
1654 SHOW is decremented for printing of structure elements.
1656 LEVEL is the depth to indent by.
1657 We increase it for some recursive calls. */
1660 type_print_base (type
, stream
, show
, level
)
1669 register int lastval
;
1676 fputs_filtered ("<type unknown>", stream
);
1680 /* When SHOW is zero or less, and there is a valid type name, then always
1681 just print the type name directly from the type. */
1683 if ((show
<= 0) && (TYPE_NAME (type
) != NULL
))
1685 fputs_filtered (TYPE_NAME (type
), stream
);
1689 switch (TYPE_CODE (type
))
1691 case TYPE_CODE_ARRAY
:
1693 case TYPE_CODE_MEMBER
:
1695 case TYPE_CODE_FUNC
:
1696 case TYPE_CODE_METHOD
:
1697 type_print_base (TYPE_TARGET_TYPE (type
), stream
, show
, level
);
1700 case TYPE_CODE_STRUCT
:
1701 fprintf_filtered (stream
, "struct ");
1704 case TYPE_CODE_UNION
:
1705 fprintf_filtered (stream
, "union ");
1707 if (name
= type_name_no_tag (type
))
1709 fputs_filtered (name
, stream
);
1710 fputs_filtered (" ", stream
);
1714 fprintf_filtered (stream
, "{...}");
1717 check_stub_type (type
);
1719 type_print_derivation_info (stream
, type
);
1721 fprintf_filtered (stream
, "{");
1722 len
= TYPE_NFIELDS (type
);
1724 fprintf_filtered (stream
, "\n");
1727 if (TYPE_FLAGS (type
) & TYPE_FLAG_STUB
)
1728 fprintf_filtered (stream
, "<incomplete type>\n");
1730 fprintf_filtered (stream
, "<no data fields>\n");
1733 /* If there is a base class for this type,
1734 do not print the field that it occupies. */
1735 for (i
= TYPE_N_BASECLASSES (type
); i
< len
; i
++)
1738 /* Don't print out virtual function table. */
1739 if ((TYPE_FIELD_NAME (type
, i
))[5] == CPLUS_MARKER
&&
1740 !strncmp (TYPE_FIELD_NAME (type
, i
), "_vptr", 5))
1743 print_spaces_filtered (level
+ 4, stream
);
1744 if (TYPE_FIELD_STATIC (type
, i
))
1746 fprintf_filtered (stream
, "static ");
1748 type_print_1 (TYPE_FIELD_TYPE (type
, i
),
1749 TYPE_FIELD_NAME (type
, i
),
1750 stream
, show
- 1, level
+ 4);
1751 if (!TYPE_FIELD_STATIC (type
, i
)
1752 && TYPE_FIELD_PACKED (type
, i
))
1754 /* It is a bitfield. This code does not attempt
1755 to look at the bitpos and reconstruct filler,
1756 unnamed fields. This would lead to misleading
1757 results if the compiler does not put out fields
1758 for such things (I don't know what it does). */
1759 fprintf_filtered (stream
, " : %d",
1760 TYPE_FIELD_BITSIZE (type
, i
));
1762 fprintf_filtered (stream
, ";\n");
1765 /* C++: print out the methods */
1766 len
= TYPE_NFN_FIELDS (type
);
1767 if (len
) fprintf_filtered (stream
, "\n");
1768 for (i
= 0; i
< len
; i
++)
1770 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (type
, i
);
1771 int j
, len2
= TYPE_FN_FIELDLIST_LENGTH (type
, i
);
1772 char *method_name
= TYPE_FN_FIELDLIST_NAME (type
, i
);
1773 int is_constructor
= name
&& strcmp(method_name
, name
) == 0;
1774 for (j
= 0; j
< len2
; j
++)
1777 print_spaces_filtered (level
+ 4, stream
);
1778 if (TYPE_FN_FIELD_VIRTUAL_P (f
, j
))
1779 fprintf_filtered (stream
, "virtual ");
1780 else if (TYPE_FN_FIELD_STATIC_P (f
, j
))
1781 fprintf_filtered (stream
, "static ");
1782 if (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f
, j
)) == 0)
1784 /* Keep GDB from crashing here. */
1785 fprintf (stream
, "<undefined type> %s;\n",
1786 TYPE_FN_FIELD_PHYSNAME (f
, j
));
1789 else if (!is_constructor
)
1791 type_print (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f
, j
)),
1793 fputs_filtered (" ", stream
);
1795 if (TYPE_FN_FIELD_STUB (f
, j
))
1797 /* Build something we can demangle. */
1798 char *mangled_name
= gdb_mangle_name (type
, i
, j
);
1799 char *demangled_name
=
1800 cplus_demangle (mangled_name
,
1801 DMGL_ANSI
| DMGL_PARAMS
);
1802 if (demangled_name
== 0)
1803 fprintf_filtered (stream
, "<badly mangled name %s>",
1807 fprintf_filtered (stream
, "%s",
1808 strchr (demangled_name
, ':') + 2);
1809 free (demangled_name
);
1811 free (mangled_name
);
1813 else if (TYPE_FN_FIELD_PHYSNAME (f
, j
)[0] == '_'
1814 && TYPE_FN_FIELD_PHYSNAME (f
, j
)[1] == CPLUS_MARKER
)
1815 type_print_method_args
1816 (TYPE_FN_FIELD_ARGS (f
, j
) + 1, "~",
1817 method_name
, 0, stream
);
1819 type_print_method_args
1820 (TYPE_FN_FIELD_ARGS (f
, j
), "",
1822 TYPE_FN_FIELD_STATIC_P (f
, j
), stream
);
1824 fprintf_filtered (stream
, ";\n");
1828 print_spaces_filtered (level
, stream
);
1829 fprintf_filtered (stream
, "}");
1833 case TYPE_CODE_ENUM
:
1834 fprintf_filtered (stream
, "enum ");
1835 if (name
= type_name_no_tag (type
))
1837 fputs_filtered (name
, stream
);
1838 fputs_filtered (" ", stream
);
1842 fprintf_filtered (stream
, "{...}");
1845 fprintf_filtered (stream
, "{");
1846 len
= TYPE_NFIELDS (type
);
1848 for (i
= 0; i
< len
; i
++)
1851 if (i
) fprintf_filtered (stream
, ", ");
1853 fputs_filtered (TYPE_FIELD_NAME (type
, i
), stream
);
1854 if (lastval
!= TYPE_FIELD_BITPOS (type
, i
))
1856 fprintf_filtered (stream
, " = %d", TYPE_FIELD_BITPOS (type
, i
));
1857 lastval
= TYPE_FIELD_BITPOS (type
, i
);
1861 fprintf_filtered (stream
, "}");
1865 case TYPE_CODE_VOID
:
1866 fprintf_filtered (stream
, "void");
1869 case TYPE_CODE_UNDEF
:
1870 fprintf_filtered (stream
, "struct <unknown>");
1873 case TYPE_CODE_ERROR
:
1874 fprintf_filtered (stream
, "<unknown type>");
1877 case TYPE_CODE_RANGE
:
1878 /* This should not occur */
1879 fprintf_filtered (stream
, "<range type>");
1883 /* Handle types not explicitly handled by the other cases,
1884 such as fundamental types. For these, just print whatever
1885 the type name is, as recorded in the type itself. If there
1886 is no type name, then complain. */
1887 if (TYPE_NAME (type
) != NULL
)
1889 fputs_filtered (TYPE_NAME (type
), stream
);
1893 error ("Invalid type code (%d) in symbol table.", TYPE_CODE (type
));
1900 /* Validate an input or output radix setting, and make sure the user
1901 knows what they really did here. Radix setting is confusing, e.g.
1902 setting the input radix to "10" never changes it! */
1906 set_input_radix (args
, from_tty
, c
)
1909 struct cmd_list_element
*c
;
1911 unsigned radix
= *(unsigned *)c
->var
;
1914 printf_filtered ("Input radix set to decimal %d, hex %x, octal %o\n",
1915 radix
, radix
, radix
);
1921 set_output_radix (args
, from_tty
, c
)
1924 struct cmd_list_element
*c
;
1926 unsigned radix
= *(unsigned *)c
->var
;
1929 printf_filtered ("Output radix set to decimal %d, hex %x, octal %o\n",
1930 radix
, radix
, radix
);
1932 /* FIXME, we really should be able to validate the setting BEFORE
1937 output_format
= 'x';
1943 output_format
= 'o'; /* octal */
1947 error ("Unsupported radix ``decimal %d''; using decimal output",
1954 set_radix (arg
, from_tty
, c
)
1957 struct cmd_list_element
*c
;
1959 unsigned radix
= *(unsigned *)c
->var
;
1962 printf_filtered ("Radix set to decimal %d, hex %x, octal %o\n",
1963 radix
, radix
, radix
);
1965 input_radix
= radix
;
1966 output_radix
= radix
;
1968 set_output_radix (arg
, 0, c
);
1971 struct cmd_list_element
*setprintlist
= NULL
;
1972 struct cmd_list_element
*showprintlist
= NULL
;
1976 set_print (arg
, from_tty
)
1981 "\"set print\" must be followed by the name of a print subcommand.\n");
1982 help_list (setprintlist
, "set print ", -1, stdout
);
1987 show_print (args
, from_tty
)
1991 cmd_show_list (showprintlist
, from_tty
, "");
1995 _initialize_valprint ()
1997 struct cmd_list_element
*c
;
1999 add_prefix_cmd ("print", no_class
, set_print
,
2000 "Generic command for setting how things print.",
2001 &setprintlist
, "set print ", 0, &setlist
);
2002 add_alias_cmd ("p", "print", no_class
, 1, &setlist
);
2003 add_alias_cmd ("pr", "print", no_class
, 1, &setlist
); /* prefer set print
2005 add_prefix_cmd ("print", no_class
, show_print
,
2006 "Generic command for showing print settings.",
2007 &showprintlist
, "show print ", 0, &showlist
);
2008 add_alias_cmd ("p", "print", no_class
, 1, &showlist
);
2009 add_alias_cmd ("pr", "print", no_class
, 1, &showlist
);
2012 (add_set_cmd ("elements", no_class
, var_uinteger
, (char *)&print_max
,
2013 "Set limit on string chars or array elements to print.\n\
2014 \"set print elements 0\" causes there to be no limit.",
2019 (add_set_cmd ("pretty", class_support
, var_boolean
, (char *)&prettyprint
,
2020 "Set prettyprinting of structures.",
2025 (add_set_cmd ("union", class_support
, var_boolean
, (char *)&unionprint
,
2026 "Set printing of unions interior to structures.",
2031 (add_set_cmd ("vtbl", class_support
, var_boolean
, (char *)&vtblprint
,
2032 "Set printing of C++ virtual function tables.",
2037 (add_set_cmd ("array", class_support
, var_boolean
, (char *)&arrayprint
,
2038 "Set prettyprinting of arrays.",
2043 (add_set_cmd ("object", class_support
, var_boolean
, (char *)&objectprint
,
2044 "Set printing of object's derived type based on vtable info.",
2049 (add_set_cmd ("address", class_support
, var_boolean
, (char *)&addressprint
,
2050 "Set printing of addresses.",
2055 /* The "show radix" cmd isn't good enough to show two separate values.
2056 The rest of the code works, but the show part is confusing, so don't
2057 let them be set separately 'til we work out "show". */
2058 c
= add_set_cmd ("input-radix", class_support
, var_uinteger
,
2059 (char *)&input_radix
,
2060 "Set default input radix for entering numbers.",
2062 add_show_from_set (c
, &showlist
);
2063 c
->function
= set_input_radix
;
2065 c
= add_set_cmd ("output-radix", class_support
, var_uinteger
,
2066 (char *)&output_radix
,
2067 "Set default output radix for printing of values.",
2069 add_show_from_set (c
, &showlist
);
2070 c
->function
= set_output_radix
;
2073 c
= add_set_cmd ("radix", class_support
, var_uinteger
,
2074 (char *)&output_radix
,
2075 "Set default input and output number radix.",
2077 add_show_from_set (c
, &showlist
);
2078 c
->function
.sfunc
= set_radix
;
2080 /* Give people the defaults which they are used to. */
2090 obstack_begin (&dont_print_obstack
, 32 * sizeof (struct type
*));