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. */
33 /* Prototypes for local functions */
36 print_string
PARAMS ((FILE *, char *, unsigned int, int));
39 show_print
PARAMS ((char *, int));
42 set_print
PARAMS ((char *, int));
45 set_radix
PARAMS ((char *, int, struct cmd_list_element
*));
48 set_output_radix
PARAMS ((char *, int, struct cmd_list_element
*));
51 type_print_base
PARAMS ((struct type
*, FILE *, int, int));
54 type_print_varspec_suffix
PARAMS ((struct type
*, FILE *, int, int));
57 type_print_varspec_prefix
PARAMS ((struct type
*, FILE *, int, int));
60 type_print_derivation_info
PARAMS ((FILE *, struct type
*));
63 type_print_method_args
PARAMS ((struct type
**, char *, char *, int, FILE *));
66 cplus_val_print
PARAMS ((struct type
*, char *, FILE *, int, int,
67 enum val_prettyprint
, struct type
**));
70 val_print_fields
PARAMS ((struct type
*, char *, FILE *, int, int,
71 enum val_prettyprint
, struct type
**));
74 is_vtbl_member
PARAMS ((struct type
*));
77 is_vtbl_ptr_type
PARAMS ((struct type
*));
80 print_hex_chars
PARAMS ((FILE *, unsigned char *, unsigned));
83 extern char *sys_errlist
[];
85 extern int demangle
; /* whether to print C++ syms raw or source-form */
87 /* Maximum number of chars to print for a string pointer value
88 or vector contents, or UINT_MAX for no limit. */
90 static unsigned int print_max
;
92 /* Default input and output radixes, and output format letter. */
94 unsigned input_radix
= 10;
95 unsigned output_radix
= 10;
96 int output_format
= 0;
98 /* Print repeat counts if there are more than this
99 many repetitions of an element in an array. */
100 #define REPEAT_COUNT_THRESHOLD 10
102 /* Define a mess of print controls. */
104 int prettyprint
; /* Controls pretty printing of structures */
105 int vtblprint
; /* Controls printing of vtbl's */
106 int unionprint
; /* Controls printing of nested unions. */
107 int arrayprint
; /* Controls pretty printing of arrays. */
108 int addressprint
; /* Controls pretty printing of addresses. */
109 int objectprint
; /* Controls looking up an object's derived type
110 using what we find in its vtables. */
112 struct obstack dont_print_obstack
;
115 /* Print the character string STRING, printing at most LENGTH characters.
116 Printing stops early if the number hits print_max; repeat counts
117 are printed as appropriate. Print ellipses at the end if we
118 had to stop before printing LENGTH characters, or if FORCE_ELLIPSES. */
121 print_string (stream
, string
, length
, force_ellipses
)
127 register unsigned int i
;
128 unsigned int things_printed
= 0;
131 extern int inspect_it
;
135 fputs_filtered ("\"\"", stdout
);
139 for (i
= 0; i
< length
&& things_printed
< print_max
; ++i
)
141 /* Position of the character we are examining
142 to see whether it is repeated. */
144 /* Number of repetitions we have detected so far. */
151 fputs_filtered (", ", stream
);
157 while (rep1
< length
&& string
[rep1
] == string
[i
])
163 if (reps
> REPEAT_COUNT_THRESHOLD
)
168 fputs_filtered ("\\\", ", stream
);
170 fputs_filtered ("\", ", stream
);
173 fputs_filtered ("'", stream
);
174 printchar (string
[i
], stream
, '\'');
175 fprintf_filtered (stream
, "' <repeats %u times>", reps
);
177 things_printed
+= REPEAT_COUNT_THRESHOLD
;
185 fputs_filtered ("\\\"", stream
);
187 fputs_filtered ("\"", stream
);
190 printchar (string
[i
], stream
, '"');
195 /* Terminate the quotes if necessary. */
199 fputs_filtered ("\\\"", stream
);
201 fputs_filtered ("\"", stream
);
204 if (force_ellipses
|| i
< length
)
205 fputs_filtered ("...", stream
);
208 /* Print a floating point value of type TYPE, pointed to in GDB by VALADDR,
212 print_floating (valaddr
, type
, stream
)
219 unsigned len
= TYPE_LENGTH (type
);
221 #if defined (IEEE_FLOAT)
223 /* Check for NaN's. Note that this code does not depend on us being
224 on an IEEE conforming system. It only depends on the target
225 machine using IEEE representation. This means (a)
226 cross-debugging works right, and (2) IEEE_FLOAT can (and should)
227 be defined for systems like the 68881, which uses IEEE
228 representation, but is not IEEE conforming. */
232 /* Is the sign bit 0? */
234 /* Is it is a NaN (i.e. the exponent is all ones and
235 the fraction is nonzero)? */
238 if (len
== sizeof (float))
240 /* It's single precision. */
241 bcopy (valaddr
, &low
, sizeof (low
));
242 /* target -> host. */
243 SWAP_TARGET_AND_HOST (&low
, sizeof (float));
244 nonnegative
= low
>= 0;
245 is_nan
= ((((low
>> 23) & 0xFF) == 0xFF)
246 && 0 != (low
& 0x7FFFFF));
252 /* It's double precision. Get the high and low words. */
254 #if TARGET_BYTE_ORDER == BIG_ENDIAN
255 bcopy (valaddr
+4, &low
, sizeof (low
));
256 bcopy (valaddr
+0, &high
, sizeof (high
));
258 bcopy (valaddr
+0, &low
, sizeof (low
));
259 bcopy (valaddr
+4, &high
, sizeof (high
));
261 SWAP_TARGET_AND_HOST (&low
, sizeof (low
));
262 SWAP_TARGET_AND_HOST (&high
, sizeof (high
));
263 nonnegative
= high
>= 0;
264 is_nan
= (((high
>> 20) & 0x7ff) == 0x7ff
265 && ! ((((high
& 0xfffff) == 0)) && (low
== 0)));
271 /* The meaning of the sign and fraction is not defined by IEEE.
272 But the user might know what they mean. For example, they
273 (in an implementation-defined manner) distinguish between
274 signaling and quiet NaN's. */
276 fprintf_filtered (stream
, "-NaN(0x%lx%.8lx)" + nonnegative
,
279 fprintf_filtered (stream
, "-NaN(0x%lx)" + nonnegative
, low
);
283 #endif /* IEEE_FLOAT. */
285 doub
= unpack_double (type
, valaddr
, &inv
);
287 fprintf_filtered (stream
, "<invalid float value>");
289 fprintf_filtered (stream
, len
<= sizeof(float) ? "%.9g" : "%.17g", doub
);
292 /* VALADDR points to an integer of LEN bytes. Print it in hex on stream. */
294 print_hex_chars (stream
, valaddr
, len
)
296 unsigned char *valaddr
;
301 fprintf_filtered (stream
, "0x");
302 #if TARGET_BYTE_ORDER == BIG_ENDIAN
306 #else /* Little endian. */
307 for (p
= valaddr
+ len
- 1;
312 fprintf_filtered (stream
, "%02x", *p
);
316 /* Print the value VAL in C-ish syntax on stream STREAM.
317 FORMAT is a format-letter, or 0 for print in natural format of data type.
318 If the object printed is a string pointer, returns
319 the number of string bytes printed. */
322 value_print (val
, stream
, format
, pretty
)
326 enum val_prettyprint pretty
;
328 register unsigned int i
, n
, typelen
;
332 printf_filtered ("<address of value unknown>");
335 if (VALUE_OPTIMIZED_OUT (val
))
337 printf_filtered ("<value optimized out>");
341 /* A "repeated" value really contains several values in a row.
342 They are made by the @ operator.
343 Print such values as if they were arrays. */
345 else if (VALUE_REPEATED (val
))
347 n
= VALUE_REPETITIONS (val
);
348 typelen
= TYPE_LENGTH (VALUE_TYPE (val
));
349 fprintf_filtered (stream
, "{");
350 /* Print arrays of characters using string syntax. */
351 if (typelen
== 1 && TYPE_CODE (VALUE_TYPE (val
)) == TYPE_CODE_INT
353 print_string (stream
, VALUE_CONTENTS (val
), n
, 0);
356 unsigned int things_printed
= 0;
358 for (i
= 0; i
< n
&& things_printed
< print_max
; i
++)
360 /* Position of the array element we are examining to see
361 whether it is repeated. */
363 /* Number of repetitions we have detected so far. */
367 fprintf_filtered (stream
, ", ");
373 && !bcmp (VALUE_CONTENTS (val
) + typelen
* i
,
374 VALUE_CONTENTS (val
) + typelen
* rep1
, typelen
))
380 if (reps
> REPEAT_COUNT_THRESHOLD
)
382 val_print (VALUE_TYPE (val
),
383 VALUE_CONTENTS (val
) + typelen
* i
,
384 VALUE_ADDRESS (val
) + typelen
* i
,
385 stream
, format
, 1, 0, pretty
);
386 fprintf (stream
, " <repeats %u times>", reps
);
388 things_printed
+= REPEAT_COUNT_THRESHOLD
;
392 val_print (VALUE_TYPE (val
),
393 VALUE_CONTENTS (val
) + typelen
* i
,
394 VALUE_ADDRESS (val
) + typelen
* i
,
395 stream
, format
, 1, 0, pretty
);
400 fprintf_filtered (stream
, "...");
402 fprintf_filtered (stream
, "}");
407 struct type
*type
= VALUE_TYPE (val
);
409 /* If it is a pointer, indicate what it points to.
411 Print type also if it is a reference.
413 C++: if it is a member pointer, we will take care
414 of that when we print it. */
415 if (TYPE_CODE (type
) == TYPE_CODE_PTR
416 || TYPE_CODE (type
) == TYPE_CODE_REF
)
418 /* Hack: remove (char *) for char strings. Their
419 type is indicated by the quoted string anyway. */
420 if (TYPE_CODE (type
) == TYPE_CODE_PTR
421 && TYPE_LENGTH (TYPE_TARGET_TYPE (type
)) == sizeof(char)
422 && TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_INT
423 && !TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
)))
429 fprintf_filtered (stream
, "(");
430 type_print (type
, "", stream
, -1);
431 fprintf_filtered (stream
, ") ");
434 return val_print (type
, VALUE_CONTENTS (val
),
435 VALUE_ADDRESS (val
), stream
, format
, 1, 0, pretty
);
439 /* Return truth value for assertion that TYPE is of the type
440 "pointer to virtual function". */
442 is_vtbl_ptr_type(type
)
445 char *typename
= type_name_no_tag (type
);
446 static const char vtbl_ptr_name
[] =
447 { CPLUS_MARKER
,'v','t','b','l','_','p','t','r','_','t','y','p','e', 0 };
449 return (typename
!= NULL
&& !strcmp(typename
, vtbl_ptr_name
));
452 /* Return truth value for the assertion that TYPE is of the type
453 "pointer to virtual function table". */
458 if (TYPE_CODE (type
) == TYPE_CODE_PTR
)
459 type
= TYPE_TARGET_TYPE (type
);
463 if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
464 && TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_STRUCT
)
465 /* Virtual functions tables are full of pointers to virtual functions. */
466 return is_vtbl_ptr_type (TYPE_TARGET_TYPE (type
));
470 /* Mutually recursive subroutines of cplus_val_print and val_print to print out
471 a structure's fields: val_print_fields and cplus_val_print.
473 TYPE, VALADDR, STREAM, RECURSE, and PRETTY have the
474 same meanings as in cplus_val_print and val_print.
476 DONT_PRINT is an array of baseclass types that we
477 should not print, or zero if called from top level. */
480 val_print_fields (type
, valaddr
, stream
, format
, recurse
, pretty
, dont_print
)
486 enum val_prettyprint pretty
;
487 struct type
**dont_print
;
489 int i
, len
, n_baseclasses
;
491 check_stub_type (type
);
493 fprintf_filtered (stream
, "{");
494 len
= TYPE_NFIELDS (type
);
495 n_baseclasses
= TYPE_N_BASECLASSES (type
);
497 /* Print out baseclasses such that we don't print
498 duplicates of virtual baseclasses. */
499 if (n_baseclasses
> 0)
500 cplus_val_print (type
, valaddr
, stream
, format
, recurse
+1, pretty
, dont_print
);
502 if (!len
&& n_baseclasses
== 1)
503 fprintf_filtered (stream
, "<No data fields>");
506 extern int inspect_it
;
509 for (i
= n_baseclasses
; i
< len
; i
++)
511 /* Check if static field */
512 if (TYPE_FIELD_STATIC (type
, i
))
515 fprintf_filtered (stream
, ", ");
516 else if (n_baseclasses
> 0)
518 fprintf_filtered (stream
, "\n");
519 print_spaces_filtered (2 + 2 * recurse
, stream
);
520 fputs_filtered ("members of ", stream
);
521 fputs_filtered (type_name_no_tag (type
), stream
);
522 fputs_filtered (": ", stream
);
528 fprintf_filtered (stream
, "\n");
529 print_spaces_filtered (2 + 2 * recurse
, stream
);
533 wrap_here (n_spaces (2 + 2 * recurse
));
537 if (TYPE_CODE (TYPE_FIELD_TYPE (type
, i
)) == TYPE_CODE_PTR
)
538 fputs_filtered ("\"( ptr \"", stream
);
540 fputs_filtered ("\"( nodef \"", stream
);
541 fputs_filtered (TYPE_FIELD_NAME (type
, i
), stream
);
542 fputs_filtered ("\" \"", stream
);
543 fputs_filtered (TYPE_FIELD_NAME (type
, i
), stream
);
544 fputs_filtered ("\") \"", stream
);
548 fputs_filtered (TYPE_FIELD_NAME (type
, i
), stream
);
549 fputs_filtered (" = ", stream
);
551 if (TYPE_FIELD_PACKED (type
, i
))
555 /* Bitfields require special handling, especially due to byte
557 v
= value_from_longest (TYPE_FIELD_TYPE (type
, i
),
558 unpack_field_as_long (type
, valaddr
, i
));
560 val_print (TYPE_FIELD_TYPE (type
, i
), VALUE_CONTENTS (v
), 0,
561 stream
, format
, 0, recurse
+ 1, pretty
);
565 val_print (TYPE_FIELD_TYPE (type
, i
),
566 valaddr
+ TYPE_FIELD_BITPOS (type
, i
) / 8,
567 0, stream
, format
, 0, recurse
+ 1, pretty
);
572 fprintf_filtered (stream
, "\n");
573 print_spaces_filtered (2 * recurse
, stream
);
576 fprintf_filtered (stream
, "}");
579 /* Special val_print routine to avoid printing multiple copies of virtual
583 cplus_val_print (type
, valaddr
, stream
, format
, recurse
, pretty
, dont_print
)
589 enum val_prettyprint pretty
;
590 struct type
**dont_print
;
592 struct obstack tmp_obstack
;
593 struct type
**last_dont_print
594 = (struct type
**)obstack_next_free (&dont_print_obstack
);
595 int i
, n_baseclasses
= TYPE_N_BASECLASSES (type
);
599 /* If we're at top level, carve out a completely fresh
600 chunk of the obstack and use that until this particular
601 invocation returns. */
602 tmp_obstack
= dont_print_obstack
;
603 /* Bump up the high-water mark. Now alpha is omega. */
604 obstack_finish (&dont_print_obstack
);
607 for (i
= 0; i
< n_baseclasses
; i
++)
612 if (BASETYPE_VIA_VIRTUAL (type
, i
))
614 struct type
**first_dont_print
615 = (struct type
**)obstack_base (&dont_print_obstack
);
617 int j
= (struct type
**)obstack_next_free (&dont_print_obstack
)
621 if (TYPE_BASECLASS (type
, i
) == first_dont_print
[j
])
624 obstack_ptr_grow (&dont_print_obstack
, TYPE_BASECLASS (type
, i
));
627 baddr
= baseclass_addr (type
, i
, valaddr
, 0, &err
);
628 if (err
== 0 && baddr
== 0)
629 error ("could not find virtual baseclass `%s'\n",
630 type_name_no_tag (TYPE_BASECLASS (type
, i
)));
632 fprintf_filtered (stream
, "\n");
634 print_spaces_filtered (2 + 2 * recurse
, stream
);
635 fputs_filtered ("<", stream
);
636 fputs_filtered (type_name_no_tag (TYPE_BASECLASS (type
, i
)), stream
);
637 fputs_filtered ("> = ", stream
);
639 fprintf_filtered (stream
, "<invalid address 0x%x>", baddr
);
641 val_print_fields (TYPE_BASECLASS (type
, i
), baddr
, stream
, format
,
643 (struct type
**)obstack_base (&dont_print_obstack
));
650 /* Free the space used to deal with the printing
651 of this type from top level. */
652 obstack_free (&dont_print_obstack
, last_dont_print
);
653 /* Reset watermark so that we can continue protecting
654 ourselves from whatever we were protecting ourselves. */
655 dont_print_obstack
= tmp_obstack
;
660 print_class_member (valaddr
, domain
, stream
, prefix
)
667 /* VAL is a byte offset into the structure type DOMAIN.
668 Find the name of the field for that offset and
672 register unsigned int i
;
673 unsigned len
= TYPE_NFIELDS (domain
);
674 /* @@ Make VAL into bit offset */
675 LONGEST val
= unpack_long (builtin_type_int
, valaddr
) << 3;
676 for (i
= TYPE_N_BASECLASSES (domain
); i
< len
; i
++)
678 int bitpos
= TYPE_FIELD_BITPOS (domain
, i
);
682 if (val
< bitpos
&& i
!= 0)
684 /* Somehow pointing into a field. */
686 extra
= (val
- TYPE_FIELD_BITPOS (domain
, i
));
697 fprintf_filtered (stream
, prefix
);
698 name
= type_name_no_tag (domain
);
700 fputs_filtered (name
, stream
);
702 type_print_base (domain
, stream
, 0, 0);
703 fprintf_filtered (stream
, "::");
704 fputs_filtered (TYPE_FIELD_NAME (domain
, i
), stream
);
706 fprintf_filtered (stream
, " + %d bytes", extra
);
708 fprintf_filtered (stream
, " (offset in bits)");
711 fprintf_filtered (stream
, "%d", val
>> 3);
714 /* Print data of type TYPE located at VALADDR (within GDB),
715 which came from the inferior at address ADDRESS,
716 onto stdio stream STREAM according to FORMAT
717 (a letter or 0 for natural format). The data at VALADDR
718 is in target byte order.
720 If the data are a string pointer, returns the number of
721 sting characters printed.
723 if DEREF_REF is nonzero, then dereference references,
724 otherwise just print them like pointers.
726 The PRETTY parameter controls prettyprinting. */
729 val_print (type
, valaddr
, address
, stream
, format
, deref_ref
, recurse
, pretty
)
737 enum val_prettyprint pretty
;
739 register unsigned int i
;
741 struct type
*elttype
;
746 if (pretty
== Val_pretty_default
)
748 pretty
= prettyprint
? Val_prettyprint
: Val_no_prettyprint
;
753 check_stub_type (type
);
755 if (TYPE_FLAGS (type
) & TYPE_FLAG_STUB
)
757 fprintf_filtered (stream
, "<unknown struct>");
762 switch (TYPE_CODE (type
))
764 case TYPE_CODE_ARRAY
:
765 if (TYPE_LENGTH (type
) > 0
766 && TYPE_LENGTH (TYPE_TARGET_TYPE (type
)) > 0)
768 elttype
= TYPE_TARGET_TYPE (type
);
769 eltlen
= TYPE_LENGTH (elttype
);
770 len
= TYPE_LENGTH (type
) / eltlen
;
772 print_spaces_filtered (2 + 2 * recurse
, stream
);
773 fprintf_filtered (stream
, "{");
774 /* For an array of chars, print with string syntax. */
775 if (eltlen
== 1 && TYPE_CODE (elttype
) == TYPE_CODE_INT
776 && (format
== 0 || format
== 's') )
777 print_string (stream
, valaddr
, len
, 0);
780 unsigned int things_printed
= 0;
782 /* If this is a virtual function table, print the 0th
783 entry specially, and the rest of the members normally. */
784 if (is_vtbl_ptr_type (elttype
))
786 fprintf_filtered (stream
, "%d vtable entries", len
-1);
792 for (; i
< len
&& things_printed
< print_max
; i
++)
794 /* Position of the array element we are examining to see
795 whether it is repeated. */
797 /* Number of repetitions we have detected so far. */
803 fprintf_filtered (stream
, ",\n");
804 print_spaces_filtered (2 + 2 * recurse
, stream
);
807 fprintf_filtered (stream
, ", ");
808 wrap_here (n_spaces (2 + 2 * recurse
));
813 && !bcmp (valaddr
+ i
* eltlen
,
814 valaddr
+ rep1
* eltlen
, eltlen
))
820 if (reps
> REPEAT_COUNT_THRESHOLD
)
822 val_print (elttype
, valaddr
+ i
* eltlen
,
823 0, stream
, format
, deref_ref
,
824 recurse
+ 1, pretty
);
825 fprintf_filtered (stream
, " <repeats %u times>", reps
);
827 things_printed
+= REPEAT_COUNT_THRESHOLD
;
831 val_print (elttype
, valaddr
+ i
* eltlen
,
832 0, stream
, format
, deref_ref
,
833 recurse
+ 1, pretty
);
838 fprintf_filtered (stream
, "...");
840 fprintf_filtered (stream
, "}");
843 /* Array of unspecified length: treat like pointer to first elt. */
844 valaddr
= (char *) &address
;
847 if (format
&& format
!= 's')
849 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
852 if (TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_METHOD
)
854 struct type
*domain
= TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (type
));
860 addr
= unpack_pointer (lookup_pointer_type (builtin_type_void
),
862 if (addr
< 128) /* FIXME! What is this 128? */
864 len
= TYPE_NFN_FIELDS (domain
);
865 for (i
= 0; i
< len
; i
++)
867 f
= TYPE_FN_FIELDLIST1 (domain
, i
);
868 len2
= TYPE_FN_FIELDLIST_LENGTH (domain
, i
);
870 for (j
= 0; j
< len2
; j
++)
873 if (TYPE_FN_FIELD_VOFFSET (f
, j
) == addr
)
883 struct symbol
*sym
= find_pc_function (addr
);
885 error ("invalid pointer to member function");
886 len
= TYPE_NFN_FIELDS (domain
);
887 for (i
= 0; i
< len
; i
++)
889 f
= TYPE_FN_FIELDLIST1 (domain
, i
);
890 len2
= TYPE_FN_FIELDLIST_LENGTH (domain
, i
);
892 for (j
= 0; j
< len2
; j
++)
895 if (!strcmp (SYMBOL_NAME (sym
), TYPE_FN_FIELD_PHYSNAME (f
, j
)))
903 fprintf_filtered (stream
, "&");
904 type_print_varspec_prefix (TYPE_FN_FIELD_TYPE (f
, j
), stream
, 0, 0);
905 fprintf (stream
, kind
);
906 if (TYPE_FN_FIELD_PHYSNAME (f
, j
)[0] == '_'
907 && TYPE_FN_FIELD_PHYSNAME (f
, j
)[1] == CPLUS_MARKER
)
908 type_print_method_args
909 (TYPE_FN_FIELD_ARGS (f
, j
) + 1, "~",
910 TYPE_FN_FIELDLIST_NAME (domain
, i
), 0, stream
);
912 type_print_method_args
913 (TYPE_FN_FIELD_ARGS (f
, j
), "",
914 TYPE_FN_FIELDLIST_NAME (domain
, i
), 0, stream
);
917 fprintf_filtered (stream
, "(");
918 type_print (type
, "", stream
, -1);
919 fprintf_filtered (stream
, ") %d", (int) addr
>> 3);
921 else if (TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_MEMBER
)
923 print_class_member (valaddr
,
924 TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (type
)),
929 CORE_ADDR addr
= unpack_pointer (type
, valaddr
);
930 elttype
= TYPE_TARGET_TYPE (type
);
932 if (TYPE_CODE (elttype
) == TYPE_CODE_FUNC
)
934 /* Try to print what function it points to. */
935 print_address_demangle (addr
, stream
, demangle
);
936 /* Return value is irrelevant except for string pointers. */
940 if (addressprint
&& format
!= 's')
941 fprintf_filtered (stream
, "0x%x", addr
);
943 /* For a pointer to char or unsigned char,
944 also print the string pointed to, unless pointer is null. */
945 i
= 0; /* Number of characters printed. */
946 if (TYPE_LENGTH (elttype
) == 1
947 && TYPE_CODE (elttype
) == TYPE_CODE_INT
948 && (format
== 0 || format
== 's')
950 /* If print_max is UINT_MAX, the alloca below will fail.
951 In that case don't try to print the string. */
952 && print_max
< UINT_MAX
)
954 int first_addr_err
= 0;
957 /* Get first character. */
958 errcode
= target_read_memory (addr
, (char *)&c
, 1);
961 /* First address out of bounds. */
967 char *string
= (char *) alloca (print_max
);
969 /* If the loop ends by us hitting print_max characters,
970 we need to have elipses at the end. */
971 int force_ellipses
= 1;
973 /* This loop always fetches print_max characters, even
974 though print_string might want to print more or fewer
975 (with repeated characters). This is so that
976 we don't spend forever fetching if we print
977 a long string consisting of the same character
978 repeated. Also so we can do it all in one memory
979 operation, which is faster. However, this will be
980 slower if print_max is set high, e.g. if you set
981 print_max to 1000, not only will it take a long
982 time to fetch short strings, but if you are near
983 the end of the address space, it might not work. */
985 errcode
= target_read_memory (addr
, string
, print_max
);
988 /* Try reading just one character. If that succeeds,
989 assume we hit the end of the address space, but
990 the initial part of the string is probably safe. */
992 errcode
= target_read_memory (addr
, x
, 1);
997 for (i
= 0; i
< print_max
; i
++)
998 if (string
[i
] == '\0')
1006 fputs_filtered (" ", stream
);
1007 print_string (stream
, string
, i
, force_ellipses
);
1014 fprintf_filtered (stream
,
1015 (" <Address 0x%x out of bounds>"
1021 if (errcode
>= sys_nerr
|| errcode
< 0)
1022 error ("Error reading memory address 0x%x: unknown error (%d).",
1025 error ("Error reading memory address 0x%x: %s.",
1026 addr
+ i
, sys_errlist
[errcode
]);
1032 else /* print vtbl's nicely */
1033 if (is_vtbl_member(type
))
1035 CORE_ADDR vt_address
= unpack_pointer (type
, valaddr
);
1037 struct minimal_symbol
*msymbol
=
1038 lookup_minimal_symbol_by_pc (vt_address
);
1039 if ((msymbol
!= NULL
) && (vt_address
== msymbol
-> address
))
1041 fputs_filtered (" <", stream
);
1042 fputs_demangled (msymbol
-> name
, stream
, 1);
1043 fputs_filtered (">", stream
);
1049 vt_val
= value_at (TYPE_TARGET_TYPE (type
), vt_address
);
1050 val_print (VALUE_TYPE (vt_val
), VALUE_CONTENTS (vt_val
),
1051 VALUE_ADDRESS (vt_val
), stream
, format
,
1052 deref_ref
, recurse
+ 1, pretty
);
1055 fprintf_filtered (stream
, "\n");
1056 print_spaces_filtered (2 + 2 * recurse
, stream
);
1061 /* Return number of characters printed, plus one for the
1062 terminating null if we have "reached the end". */
1063 return i
+ (print_max
&& i
!= print_max
);
1067 case TYPE_CODE_MEMBER
:
1068 error ("not implemented: member type in val_print");
1072 if (TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_MEMBER
)
1074 print_class_member (valaddr
,
1075 TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (type
)),
1081 fprintf_filtered (stream
, "@0x%lx",
1082 unpack_long (builtin_type_int
, valaddr
));
1084 fputs_filtered (": ", stream
);
1086 /* De-reference the reference. */
1089 if (TYPE_CODE (TYPE_TARGET_TYPE (type
)) != TYPE_CODE_UNDEF
)
1093 (TYPE_TARGET_TYPE (type
),
1094 unpack_pointer (lookup_pointer_type (builtin_type_void
),
1096 val_print (VALUE_TYPE (deref_val
), VALUE_CONTENTS (deref_val
),
1097 VALUE_ADDRESS (deref_val
), stream
, format
,
1098 deref_ref
, recurse
+ 1, pretty
);
1101 fputs_filtered ("???", stream
);
1105 case TYPE_CODE_UNION
:
1106 if (recurse
&& !unionprint
)
1108 fprintf_filtered (stream
, "{...}");
1112 case TYPE_CODE_STRUCT
:
1113 if (vtblprint
&& is_vtbl_ptr_type(type
))
1115 /* Print the unmangled name if desired. */
1116 print_address_demangle(*((int *) (valaddr
+ /* FIXME bytesex */
1117 TYPE_FIELD_BITPOS (type
, VTBL_FNADDR_OFFSET
) / 8)),
1121 val_print_fields (type
, valaddr
, stream
, format
, recurse
, pretty
, 0);
1124 case TYPE_CODE_ENUM
:
1127 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
1130 len
= TYPE_NFIELDS (type
);
1131 val
= unpack_long (builtin_type_int
, valaddr
);
1132 for (i
= 0; i
< len
; i
++)
1135 if (val
== TYPE_FIELD_BITPOS (type
, i
))
1139 fputs_filtered (TYPE_FIELD_NAME (type
, i
), stream
);
1142 fprintf_filtered (stream
, "%lld", val
);
1144 fprintf_filtered (stream
, "%ld", val
);
1148 case TYPE_CODE_FUNC
:
1151 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
1154 /* FIXME, we should consider, at least for ANSI C language, eliminating
1155 the distinction made between FUNCs and POINTERs to FUNCs. */
1156 fprintf_filtered (stream
, "{");
1157 type_print (type
, "", stream
, -1);
1158 fprintf_filtered (stream
, "} ");
1159 /* Try to print what function it points to, and its address. */
1160 print_address_demangle (address
, stream
, demangle
);
1164 if (format
|| output_format
)
1166 print_scalar_formatted (valaddr
, type
,
1167 format
? format
: output_format
,
1171 if (TYPE_LENGTH (type
) > sizeof (LONGEST
))
1173 if (TYPE_UNSIGNED (type
))
1175 /* First figure out whether the number in fact has zeros
1176 in all its bytes more significant than least significant
1177 sizeof (LONGEST) ones. */
1179 /* Pointer to first (i.e. lowest address) nonzero character. */
1181 len
= TYPE_LENGTH (type
);
1183 #if TARGET_BYTE_ORDER == BIG_ENDIAN
1185 len
> sizeof (LONGEST
)
1186 && p
< valaddr
+ TYPE_LENGTH (type
);
1188 #else /* Little endian. */
1189 first_addr
= valaddr
;
1190 for (p
= valaddr
+ TYPE_LENGTH (type
);
1191 len
> sizeof (LONGEST
) && p
>= valaddr
;
1193 #endif /* Little endian. */
1200 #if TARGET_BYTE_ORDER == BIG_ENDIAN
1204 if (len
<= sizeof (LONGEST
))
1206 /* We can print it in decimal. */
1209 #if defined (LONG_LONG)
1214 unpack_long (BUILTIN_TYPE_LONGEST
, first_addr
));
1218 /* It is big, so print it in hex. */
1219 print_hex_chars (stream
, (unsigned char *)first_addr
, len
);
1224 /* Signed. One could assume two's complement (a reasonable
1225 assumption, I think) and do better than this. */
1226 print_hex_chars (stream
, (unsigned char *)valaddr
,
1227 TYPE_LENGTH (type
));
1231 #ifdef PRINT_TYPELESS_INTEGER
1232 PRINT_TYPELESS_INTEGER (stream
, type
, unpack_long (type
, valaddr
));
1235 fprintf_filtered (stream
,
1236 TYPE_UNSIGNED (type
) ? "%u" : "%d",
1237 unpack_long (type
, valaddr
));
1239 fprintf_filtered (stream
,
1240 TYPE_UNSIGNED (type
) ? "%llu" : "%lld",
1241 unpack_long (type
, valaddr
));
1245 if (TYPE_LENGTH (type
) == 1)
1247 fprintf_filtered (stream
, " '");
1248 printchar ((unsigned char) unpack_long (type
, valaddr
),
1250 fprintf_filtered (stream
, "'");
1256 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
1258 print_floating (valaddr
, type
, stream
);
1261 case TYPE_CODE_VOID
:
1262 fprintf_filtered (stream
, "void");
1265 case TYPE_CODE_UNDEF
:
1266 /* This happens (without TYPE_FLAG_STUB set) on systems which don't use
1267 dbx xrefs (NO_DBX_XREFS in gcc) if a file has a "struct foo *bar"
1268 and no complete type for struct foo in that file. */
1269 fprintf_filtered (stream
, "<unknown struct>");
1272 case TYPE_CODE_ERROR
:
1273 fprintf_filtered (stream
, "?");
1276 case TYPE_CODE_RANGE
:
1277 /* FIXME, we should not ever have to print one of these yet. */
1278 fprintf_filtered (stream
, "<range type>");
1282 error ("Invalid type code in symbol table.");
1288 /* Print a description of a type in the format of a
1289 typedef for the current language.
1290 NEW is the new name for a type TYPE. */
1292 typedef_print (type
, new, stream
)
1297 switch (current_language
->la_language
)
1301 case language_cplus
:
1302 fprintf_filtered(stream
, "typedef ");
1303 type_print(type
,"",stream
,0);
1304 if(TYPE_NAME ((SYMBOL_TYPE (new))) == 0
1305 || 0 != strcmp (TYPE_NAME ((SYMBOL_TYPE (new))),
1307 fprintf_filtered(stream
, " %s", SYMBOL_NAME(new));
1312 fprintf_filtered(stream
, "TYPE ");
1313 if(!TYPE_NAME(SYMBOL_TYPE(new)) ||
1314 strcmp (TYPE_NAME(SYMBOL_TYPE(new)),
1316 fprintf_filtered(stream
, "%s = ", SYMBOL_NAME(new));
1318 fprintf_filtered(stream
, "<builtin> = ");
1319 type_print(type
,"",stream
,0);
1323 error("Language not supported.");
1325 fprintf_filtered(stream
, ";\n");
1329 /* Print a description of a type TYPE
1330 in the form of a declaration of a variable named VARSTRING.
1331 (VARSTRING is demangled if necessary.)
1332 Output goes to STREAM (via stdio).
1333 If SHOW is positive, we show the contents of the outermost level
1334 of structure even if there is a type name that could be used instead.
1335 If SHOW is negative, we never show the details of elements' types. */
1338 type_print (type
, varstring
, stream
, show
)
1344 type_print_1 (type
, varstring
, stream
, show
, 0);
1347 /* LEVEL is the depth to indent lines by. */
1350 type_print_1 (type
, varstring
, stream
, show
, level
)
1357 register enum type_code code
;
1358 type_print_base (type
, stream
, show
, level
);
1359 code
= TYPE_CODE (type
);
1360 if ((varstring
&& *varstring
)
1362 /* Need a space if going to print stars or brackets;
1363 but not if we will print just a type name. */
1364 ((show
> 0 || TYPE_NAME (type
) == 0)
1366 (code
== TYPE_CODE_PTR
|| code
== TYPE_CODE_FUNC
1367 || code
== TYPE_CODE_METHOD
1368 || code
== TYPE_CODE_ARRAY
1369 || code
== TYPE_CODE_MEMBER
1370 || code
== TYPE_CODE_REF
)))
1371 fprintf_filtered (stream
, " ");
1372 type_print_varspec_prefix (type
, stream
, show
, 0);
1373 fputs_demangled (varstring
, stream
, -1); /* Print demangled name
1374 without arguments */
1375 type_print_varspec_suffix (type
, stream
, show
, 0);
1378 /* Print the method arguments ARGS to the file STREAM. */
1380 type_print_method_args (args
, prefix
, varstring
, staticp
, stream
)
1382 char *prefix
, *varstring
;
1388 fputs_demangled (prefix
, stream
, 1);
1389 fputs_demangled (varstring
, stream
, 1);
1390 fputs_filtered (" (", stream
);
1391 if (args
&& args
[!staticp
] && args
[!staticp
]->code
!= TYPE_CODE_VOID
)
1393 i
= !staticp
; /* skip the class variable */
1396 type_print (args
[i
++], "", stream
, 0);
1399 fprintf_filtered (stream
, " ...");
1402 else if (args
[i
]->code
!= TYPE_CODE_VOID
)
1404 fprintf_filtered (stream
, ", ");
1409 fprintf_filtered (stream
, ")");
1412 /* If TYPE is a derived type, then print out derivation
1413 information. Print out all layers of the type heirarchy
1414 until we encounter one with multiple inheritance.
1415 At that point, print out that ply, and return. */
1417 type_print_derivation_info (stream
, type
)
1422 int i
, n_baseclasses
= TYPE_N_BASECLASSES (type
);
1423 struct type
*basetype
= 0;
1425 while (type
&& n_baseclasses
> 0)
1427 /* Not actually sure about this one -- Bryan. */
1428 check_stub_type (type
);
1430 fprintf_filtered (stream
, ": ");
1433 basetype
= TYPE_BASECLASS (type
, i
);
1434 if (name
= type_name_no_tag (basetype
))
1436 fprintf_filtered (stream
, "%s%s ",
1437 BASETYPE_VIA_PUBLIC(type
, i
) ? "public" : "private",
1438 BASETYPE_VIA_VIRTUAL(type
, i
) ? " virtual" : "");
1439 fputs_filtered (name
, stream
);
1442 if (i
>= n_baseclasses
)
1444 fprintf_filtered (stream
, ", ");
1447 fprintf_filtered (stream
, " ");
1448 if (n_baseclasses
!= 1)
1450 n_baseclasses
= TYPE_N_BASECLASSES (basetype
);
1455 /* Print any asterisks or open-parentheses needed before the
1456 variable name (to describe its type).
1458 On outermost call, pass 0 for PASSED_A_PTR.
1459 On outermost call, SHOW > 0 means should ignore
1460 any typename for TYPE and show its details.
1461 SHOW is always zero on recursive calls. */
1464 type_print_varspec_prefix (type
, stream
, show
, passed_a_ptr
)
1474 if (TYPE_NAME (type
) && show
<= 0)
1479 switch (TYPE_CODE (type
))
1482 type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0, 1);
1483 fprintf_filtered (stream
, "*");
1486 case TYPE_CODE_MEMBER
:
1488 fprintf_filtered (stream
, "(");
1489 type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0,
1491 fprintf_filtered (stream
, " ");
1492 name
= type_name_no_tag (TYPE_DOMAIN_TYPE (type
));
1494 fputs_filtered (name
, stream
);
1496 type_print_base (TYPE_DOMAIN_TYPE (type
), stream
, 0, passed_a_ptr
);
1497 fprintf_filtered (stream
, "::");
1500 case TYPE_CODE_METHOD
:
1502 fprintf (stream
, "(");
1503 type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0,
1507 fprintf_filtered (stream
, " ");
1508 type_print_base (TYPE_DOMAIN_TYPE (type
), stream
, 0,
1510 fprintf_filtered (stream
, "::");
1515 type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0, 1);
1516 fprintf_filtered (stream
, "&");
1519 case TYPE_CODE_FUNC
:
1520 type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0,
1523 fprintf_filtered (stream
, "(");
1526 case TYPE_CODE_ARRAY
:
1527 type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0,
1530 fprintf_filtered (stream
, "(");
1533 case TYPE_CODE_UNDEF
:
1534 case TYPE_CODE_STRUCT
:
1535 case TYPE_CODE_UNION
:
1536 case TYPE_CODE_ENUM
:
1539 case TYPE_CODE_VOID
:
1540 case TYPE_CODE_ERROR
:
1541 case TYPE_CODE_CHAR
:
1542 case TYPE_CODE_BOOL
:
1543 /* These types need no prefix. They are listed here so that
1544 gcc -Wall will reveal any types that haven't been handled. */
1549 /* Print any array sizes, function arguments or close parentheses
1550 needed after the variable name (to describe its type).
1551 Args work like type_print_varspec_prefix. */
1554 type_print_varspec_suffix (type
, stream
, show
, passed_a_ptr
)
1563 if (TYPE_NAME (type
) && show
<= 0)
1568 switch (TYPE_CODE (type
))
1570 case TYPE_CODE_ARRAY
:
1572 fprintf_filtered (stream
, ")");
1574 fprintf_filtered (stream
, "[");
1575 if (TYPE_LENGTH (type
) > 0
1576 && TYPE_LENGTH (TYPE_TARGET_TYPE (type
)) > 0)
1577 fprintf_filtered (stream
, "%d",
1579 / TYPE_LENGTH (TYPE_TARGET_TYPE (type
))));
1580 fprintf_filtered (stream
, "]");
1582 type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0,
1586 case TYPE_CODE_MEMBER
:
1588 fprintf_filtered (stream
, ")");
1589 type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0, 0);
1592 case TYPE_CODE_METHOD
:
1594 fprintf_filtered (stream
, ")");
1595 type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0, 0);
1599 struct type
**args
= TYPE_ARG_TYPES (type
);
1601 fprintf_filtered (stream
, "(");
1603 fprintf_filtered (stream
, "...");
1604 else for (i
= 1; args
[i
] != 0 && args
[i
]->code
!= TYPE_CODE_VOID
; i
++)
1606 type_print_1 (args
[i
], "", stream
, -1, 0);
1608 fprintf_filtered (stream
, "...");
1609 else if (args
[i
+1]->code
!= TYPE_CODE_VOID
) {
1610 fprintf_filtered (stream
, ",");
1614 fprintf_filtered (stream
, ")");
1620 type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0, 1);
1623 case TYPE_CODE_FUNC
:
1624 type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0,
1627 fprintf_filtered (stream
, ")");
1628 fprintf_filtered (stream
, "()");
1631 case TYPE_CODE_UNDEF
:
1632 case TYPE_CODE_STRUCT
:
1633 case TYPE_CODE_UNION
:
1634 case TYPE_CODE_ENUM
:
1637 case TYPE_CODE_VOID
:
1638 case TYPE_CODE_ERROR
:
1639 case TYPE_CODE_CHAR
:
1640 case TYPE_CODE_BOOL
:
1641 /* These types do not need a suffix. They are listed so that
1642 gcc -Wall will report types that may not have been considered. */
1647 /* Print the name of the type (or the ultimate pointer target,
1648 function value or array element), or the description of a
1651 SHOW nonzero means don't print this type as just its name;
1652 show its real definition even if it has a name.
1653 SHOW zero means print just typename or struct tag if there is one
1654 SHOW negative means abbreviate structure elements.
1655 SHOW is decremented for printing of structure elements.
1657 LEVEL is the depth to indent by.
1658 We increase it for some recursive calls. */
1661 type_print_base (type
, stream
, show
, level
)
1670 register int lastval
;
1677 fprintf_filtered (stream
, "<type unknown>");
1681 /* If the type is a fundamental type, then always print the type name
1682 directly from the type. Also print the type name directly whenever
1683 SHOW drops to zero and there is a valid type name to print. */
1685 if ((TYPE_FLAGS (type
) & TYPE_FLAG_FUND_TYPE
) ||
1686 ((show
<= 0) && (TYPE_NAME (type
) != NULL
)))
1688 fputs_filtered (TYPE_NAME (type
), stream
);
1692 switch (TYPE_CODE (type
))
1694 case TYPE_CODE_ARRAY
:
1696 case TYPE_CODE_MEMBER
:
1698 case TYPE_CODE_FUNC
:
1699 case TYPE_CODE_METHOD
:
1700 type_print_base (TYPE_TARGET_TYPE (type
), stream
, show
, level
);
1703 case TYPE_CODE_STRUCT
:
1704 fprintf_filtered (stream
, "struct ");
1707 case TYPE_CODE_UNION
:
1708 fprintf_filtered (stream
, "union ");
1710 if (name
= type_name_no_tag (type
))
1712 fputs_filtered (name
, stream
);
1713 fputs_filtered (" ", stream
);
1717 fprintf_filtered (stream
, "{...}");
1720 check_stub_type (type
);
1722 type_print_derivation_info (stream
, type
);
1724 fprintf_filtered (stream
, "{");
1725 len
= TYPE_NFIELDS (type
);
1727 fprintf_filtered (stream
, "\n");
1730 if (TYPE_FLAGS (type
) & TYPE_FLAG_STUB
)
1731 fprintf_filtered (stream
, "<incomplete type>\n");
1733 fprintf_filtered (stream
, "<no data fields>\n");
1736 /* If there is a base class for this type,
1737 do not print the field that it occupies. */
1738 for (i
= TYPE_N_BASECLASSES (type
); i
< len
; i
++)
1741 /* Don't print out virtual function table. */
1742 if ((TYPE_FIELD_NAME (type
, i
))[5] == CPLUS_MARKER
&&
1743 !strncmp (TYPE_FIELD_NAME (type
, i
), "_vptr", 5))
1746 print_spaces_filtered (level
+ 4, stream
);
1747 if (TYPE_FIELD_STATIC (type
, i
))
1749 fprintf_filtered (stream
, "static ");
1751 type_print_1 (TYPE_FIELD_TYPE (type
, i
),
1752 TYPE_FIELD_NAME (type
, i
),
1753 stream
, show
- 1, level
+ 4);
1754 if (!TYPE_FIELD_STATIC (type
, i
)
1755 && TYPE_FIELD_PACKED (type
, i
))
1757 /* It is a bitfield. This code does not attempt
1758 to look at the bitpos and reconstruct filler,
1759 unnamed fields. This would lead to misleading
1760 results if the compiler does not put out fields
1761 for such things (I don't know what it does). */
1762 fprintf_filtered (stream
, " : %d",
1763 TYPE_FIELD_BITSIZE (type
, i
));
1765 fprintf_filtered (stream
, ";\n");
1768 /* C++: print out the methods */
1769 len
= TYPE_NFN_FIELDS (type
);
1770 if (len
) fprintf_filtered (stream
, "\n");
1771 for (i
= 0; i
< len
; i
++)
1773 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (type
, i
);
1774 int j
, len2
= TYPE_FN_FIELDLIST_LENGTH (type
, i
);
1775 char *method_name
= TYPE_FN_FIELDLIST_NAME (type
, i
);
1776 int is_constructor
= name
&& strcmp(method_name
, name
) == 0;
1777 for (j
= 0; j
< len2
; j
++)
1780 print_spaces_filtered (level
+ 4, stream
);
1781 if (TYPE_FN_FIELD_VIRTUAL_P (f
, j
))
1782 fprintf_filtered (stream
, "virtual ");
1783 else if (TYPE_FN_FIELD_STATIC_P (f
, j
))
1784 fprintf_filtered (stream
, "static ");
1785 if (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f
, j
)) == 0)
1787 /* Keep GDB from crashing here. */
1788 fprintf (stream
, "<undefined type> %s;\n",
1789 TYPE_FN_FIELD_PHYSNAME (f
, j
));
1792 else if (!is_constructor
)
1794 type_print (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f
, j
)),
1796 fputs_filtered (" ", stream
);
1798 if (TYPE_FN_FIELD_STUB (f
, j
))
1800 /* Build something we can demangle. */
1801 char *mangled_name
= gdb_mangle_name (type
, i
, j
);
1802 char *demangled_name
= cplus_demangle (mangled_name
, 1);
1803 if (demangled_name
== 0)
1804 fprintf_filtered (stream
, "<badly mangled name %s>",
1808 fprintf_filtered (stream
, "%s",
1809 strchr (demangled_name
, ':') + 2);
1810 free (demangled_name
);
1812 free (mangled_name
);
1814 else if (TYPE_FN_FIELD_PHYSNAME (f
, j
)[0] == '_'
1815 && TYPE_FN_FIELD_PHYSNAME (f
, j
)[1] == CPLUS_MARKER
)
1816 type_print_method_args
1817 (TYPE_FN_FIELD_ARGS (f
, j
) + 1, "~",
1818 method_name
, 0, stream
);
1820 type_print_method_args
1821 (TYPE_FN_FIELD_ARGS (f
, j
), "",
1823 TYPE_FN_FIELD_STATIC_P (f
, j
), stream
);
1825 fprintf_filtered (stream
, ";\n");
1829 print_spaces_filtered (level
, stream
);
1830 fprintf_filtered (stream
, "}");
1834 case TYPE_CODE_ENUM
:
1835 fprintf_filtered (stream
, "enum ");
1836 if (name
= type_name_no_tag (type
))
1838 fputs_filtered (name
, stream
);
1839 fputs_filtered (" ", stream
);
1843 fprintf_filtered (stream
, "{...}");
1846 fprintf_filtered (stream
, "{");
1847 len
= TYPE_NFIELDS (type
);
1849 for (i
= 0; i
< len
; i
++)
1852 if (i
) fprintf_filtered (stream
, ", ");
1854 fputs_filtered (TYPE_FIELD_NAME (type
, i
), stream
);
1855 if (lastval
!= TYPE_FIELD_BITPOS (type
, i
))
1857 fprintf_filtered (stream
, " = %d", TYPE_FIELD_BITPOS (type
, i
));
1858 lastval
= TYPE_FIELD_BITPOS (type
, i
);
1862 fprintf_filtered (stream
, "}");
1866 case TYPE_CODE_VOID
:
1867 fprintf_filtered (stream
, "void");
1870 case TYPE_CODE_UNDEF
:
1871 fprintf_filtered (stream
, "struct <unknown>");
1874 case TYPE_CODE_ERROR
:
1875 fprintf_filtered (stream
, "<unknown type>");
1878 case TYPE_CODE_RANGE
:
1879 /* This should not occur */
1880 fprintf_filtered (stream
, "<range type>");
1884 error ("Invalid type code in symbol table.");
1889 /* Validate an input or output radix setting, and make sure the user
1890 knows what they really did here. Radix setting is confusing, e.g.
1891 setting the input radix to "10" never changes it! */
1895 set_input_radix (args
, from_tty
, c
)
1898 struct cmd_list_element
*c
;
1900 unsigned radix
= *(unsigned *)c
->var
;
1903 printf_filtered ("Input radix set to decimal %d, hex %x, octal %o\n",
1904 radix
, radix
, radix
);
1910 set_output_radix (args
, from_tty
, c
)
1913 struct cmd_list_element
*c
;
1915 unsigned radix
= *(unsigned *)c
->var
;
1918 printf_filtered ("Output radix set to decimal %d, hex %x, octal %o\n",
1919 radix
, radix
, radix
);
1921 /* FIXME, we really should be able to validate the setting BEFORE
1926 output_format
= 'x';
1932 output_format
= 'o'; /* octal */
1936 error ("Unsupported radix ``decimal %d''; using decimal output",
1943 set_radix (arg
, from_tty
, c
)
1946 struct cmd_list_element
*c
;
1948 unsigned radix
= *(unsigned *)c
->var
;
1951 printf_filtered ("Radix set to decimal %d, hex %x, octal %o\n",
1952 radix
, radix
, radix
);
1954 input_radix
= radix
;
1955 output_radix
= radix
;
1957 set_output_radix (arg
, 0, c
);
1960 struct cmd_list_element
*setprintlist
= NULL
;
1961 struct cmd_list_element
*showprintlist
= NULL
;
1965 set_print (arg
, from_tty
)
1970 "\"set print\" must be followed by the name of a print subcommand.\n");
1971 help_list (setprintlist
, "set print ", -1, stdout
);
1976 show_print (args
, from_tty
)
1980 cmd_show_list (showprintlist
, from_tty
, "");
1984 _initialize_valprint ()
1986 struct cmd_list_element
*c
;
1988 add_prefix_cmd ("print", no_class
, set_print
,
1989 "Generic command for setting how things print.",
1990 &setprintlist
, "set print ", 0, &setlist
);
1991 add_alias_cmd ("p", "print", no_class
, 1, &setlist
);
1992 add_alias_cmd ("pr", "print", no_class
, 1, &setlist
); /* prefer set print
1994 add_prefix_cmd ("print", no_class
, show_print
,
1995 "Generic command for showing print settings.",
1996 &showprintlist
, "show print ", 0, &showlist
);
1997 add_alias_cmd ("p", "print", no_class
, 1, &showlist
);
1998 add_alias_cmd ("pr", "print", no_class
, 1, &showlist
);
2001 (add_set_cmd ("elements", no_class
, var_uinteger
, (char *)&print_max
,
2002 "Set limit on string chars or array elements to print.\n\
2003 \"set print elements 0\" causes there to be no limit.",
2008 (add_set_cmd ("pretty", class_support
, var_boolean
, (char *)&prettyprint
,
2009 "Set prettyprinting of structures.",
2014 (add_set_cmd ("union", class_support
, var_boolean
, (char *)&unionprint
,
2015 "Set printing of unions interior to structures.",
2020 (add_set_cmd ("vtbl", class_support
, var_boolean
, (char *)&vtblprint
,
2021 "Set printing of C++ virtual function tables.",
2026 (add_set_cmd ("array", class_support
, var_boolean
, (char *)&arrayprint
,
2027 "Set prettyprinting of arrays.",
2032 (add_set_cmd ("object", class_support
, var_boolean
, (char *)&objectprint
,
2033 "Set printing of object's derived type based on vtable info.",
2038 (add_set_cmd ("address", class_support
, var_boolean
, (char *)&addressprint
,
2039 "Set printing of addresses.",
2044 /* The "show radix" cmd isn't good enough to show two separate values.
2045 The rest of the code works, but the show part is confusing, so don't
2046 let them be set separately 'til we work out "show". */
2047 c
= add_set_cmd ("input-radix", class_support
, var_uinteger
,
2048 (char *)&input_radix
,
2049 "Set default input radix for entering numbers.",
2051 add_show_from_set (c
, &showlist
);
2052 c
->function
= set_input_radix
;
2054 c
= add_set_cmd ("output-radix", class_support
, var_uinteger
,
2055 (char *)&output_radix
,
2056 "Set default output radix for printing of values.",
2058 add_show_from_set (c
, &showlist
);
2059 c
->function
= set_output_radix
;
2062 c
= add_set_cmd ("radix", class_support
, var_uinteger
,
2063 (char *)&output_radix
,
2064 "Set default input and output number radix.",
2066 add_show_from_set (c
, &showlist
);
2067 c
->function
.sfunc
= set_radix
;
2069 /* Give people the defaults which they are used to. */
2079 obstack_begin (&dont_print_obstack
, 32 * sizeof (struct type
*));