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_args
PARAMS ((struct type
*, FILE *));
58 type_print_varspec_suffix
PARAMS ((struct type
*, FILE *, int, int, int));
61 type_print_varspec_prefix
PARAMS ((struct type
*, FILE *, int, int));
64 type_print_derivation_info
PARAMS ((FILE *, struct type
*));
67 type_print_method_args
PARAMS ((struct type
**, char *, char *, int, FILE *));
70 cplus_val_print
PARAMS ((struct type
*, char *, FILE *, int, int,
71 enum val_prettyprint
, struct type
**));
74 val_print_fields
PARAMS ((struct type
*, char *, FILE *, int, int,
75 enum val_prettyprint
, struct type
**));
78 is_vtbl_member
PARAMS ((struct type
*));
81 is_vtbl_ptr_type
PARAMS ((struct type
*));
84 print_hex_chars
PARAMS ((FILE *, unsigned char *, unsigned));
86 extern int demangle
; /* whether to print C++ syms raw or source-form */
88 /* Maximum number of chars to print for a string pointer value
89 or vector contents, or UINT_MAX for no limit. */
91 static unsigned int print_max
;
93 /* Default input and output radixes, and output format letter. */
95 unsigned input_radix
= 10;
96 unsigned output_radix
= 10;
97 int output_format
= 0;
99 /* Print repeat counts if there are more than this
100 many repetitions of an element in an array. */
101 #define REPEAT_COUNT_THRESHOLD 10
103 /* Define a mess of print controls. */
105 int prettyprint
; /* Controls pretty printing of structures */
106 int vtblprint
; /* Controls printing of vtbl's */
107 int unionprint
; /* Controls printing of nested unions. */
108 int arrayprint
; /* Controls pretty printing of arrays. */
109 int addressprint
; /* Controls pretty printing of addresses. */
110 int objectprint
; /* Controls looking up an object's derived type
111 using what we find in its vtables. */
113 struct obstack dont_print_obstack
;
116 /* Print the character string STRING, printing at most LENGTH characters.
117 Printing stops early if the number hits print_max; repeat counts
118 are printed as appropriate. Print ellipses at the end if we
119 had to stop before printing LENGTH characters, or if FORCE_ELLIPSES. */
122 print_string (stream
, string
, length
, force_ellipses
)
128 register unsigned int i
;
129 unsigned int things_printed
= 0;
132 extern int inspect_it
;
136 fputs_filtered ("\"\"", stdout
);
140 for (i
= 0; i
< length
&& things_printed
< print_max
; ++i
)
142 /* Position of the character we are examining
143 to see whether it is repeated. */
145 /* Number of repetitions we have detected so far. */
152 fputs_filtered (", ", stream
);
158 while (rep1
< length
&& string
[rep1
] == string
[i
])
164 if (reps
> REPEAT_COUNT_THRESHOLD
)
169 fputs_filtered ("\\\", ", stream
);
171 fputs_filtered ("\", ", stream
);
174 fputs_filtered ("'", stream
);
175 printchar (string
[i
], stream
, '\'');
176 fprintf_filtered (stream
, "' <repeats %u times>", reps
);
178 things_printed
+= REPEAT_COUNT_THRESHOLD
;
186 fputs_filtered ("\\\"", stream
);
188 fputs_filtered ("\"", stream
);
191 printchar (string
[i
], stream
, '"');
196 /* Terminate the quotes if necessary. */
200 fputs_filtered ("\\\"", stream
);
202 fputs_filtered ("\"", stream
);
205 if (force_ellipses
|| i
< length
)
206 fputs_filtered ("...", stream
);
209 /* Print a floating point value of type TYPE, pointed to in GDB by VALADDR,
213 print_floating (valaddr
, type
, stream
)
220 unsigned len
= TYPE_LENGTH (type
);
222 #if defined (IEEE_FLOAT)
224 /* Check for NaN's. Note that this code does not depend on us being
225 on an IEEE conforming system. It only depends on the target
226 machine using IEEE representation. This means (a)
227 cross-debugging works right, and (2) IEEE_FLOAT can (and should)
228 be defined for systems like the 68881, which uses IEEE
229 representation, but is not IEEE conforming. */
233 /* Is the sign bit 0? */
235 /* Is it is a NaN (i.e. the exponent is all ones and
236 the fraction is nonzero)? */
239 if (len
== sizeof (float))
241 /* It's single precision. */
242 memcpy ((char *) &low
, valaddr
, sizeof (low
));
243 /* target -> host. */
244 SWAP_TARGET_AND_HOST (&low
, sizeof (float));
245 nonnegative
= low
>= 0;
246 is_nan
= ((((low
>> 23) & 0xFF) == 0xFF)
247 && 0 != (low
& 0x7FFFFF));
253 /* It's double precision. Get the high and low words. */
255 #if TARGET_BYTE_ORDER == BIG_ENDIAN
256 memcpy (&low
, valaddr
+4, sizeof (low
));
257 memcpy (&high
, valaddr
+0, sizeof (high
));
259 memcpy (&low
, valaddr
+0, sizeof (low
));
260 memcpy (&high
, valaddr
+4, sizeof (high
));
262 SWAP_TARGET_AND_HOST (&low
, sizeof (low
));
263 SWAP_TARGET_AND_HOST (&high
, sizeof (high
));
264 nonnegative
= high
>= 0;
265 is_nan
= (((high
>> 20) & 0x7ff) == 0x7ff
266 && ! ((((high
& 0xfffff) == 0)) && (low
== 0)));
272 /* The meaning of the sign and fraction is not defined by IEEE.
273 But the user might know what they mean. For example, they
274 (in an implementation-defined manner) distinguish between
275 signaling and quiet NaN's. */
277 fprintf_filtered (stream
, "-NaN(0x%lx%.8lx)" + nonnegative
,
280 fprintf_filtered (stream
, "-NaN(0x%lx)" + nonnegative
, low
);
284 #endif /* IEEE_FLOAT. */
286 doub
= unpack_double (type
, valaddr
, &inv
);
288 fprintf_filtered (stream
, "<invalid float value>");
290 fprintf_filtered (stream
, len
<= sizeof(float) ? "%.9g" : "%.17g", doub
);
293 /* VALADDR points to an integer of LEN bytes. Print it in hex on stream. */
295 print_hex_chars (stream
, valaddr
, len
)
297 unsigned char *valaddr
;
302 fprintf_filtered (stream
, "0x");
303 #if TARGET_BYTE_ORDER == BIG_ENDIAN
307 #else /* Little endian. */
308 for (p
= valaddr
+ len
- 1;
313 fprintf_filtered (stream
, "%02x", *p
);
317 /* Print the value VAL in C-ish syntax on stream STREAM.
318 FORMAT is a format-letter, or 0 for print in natural format of data type.
319 If the object printed is a string pointer, returns
320 the number of string bytes printed. */
323 value_print (val
, stream
, format
, pretty
)
327 enum val_prettyprint pretty
;
329 register unsigned int i
, n
, typelen
;
333 printf_filtered ("<address of value unknown>");
336 if (VALUE_OPTIMIZED_OUT (val
))
338 printf_filtered ("<value optimized out>");
342 /* A "repeated" value really contains several values in a row.
343 They are made by the @ operator.
344 Print such values as if they were arrays. */
346 else if (VALUE_REPEATED (val
))
348 n
= VALUE_REPETITIONS (val
);
349 typelen
= TYPE_LENGTH (VALUE_TYPE (val
));
350 fprintf_filtered (stream
, "{");
351 /* Print arrays of characters using string syntax. */
352 if (typelen
== 1 && TYPE_CODE (VALUE_TYPE (val
)) == TYPE_CODE_INT
354 print_string (stream
, VALUE_CONTENTS (val
), n
, 0);
357 unsigned int things_printed
= 0;
359 for (i
= 0; i
< n
&& things_printed
< print_max
; i
++)
361 /* Position of the array element we are examining to see
362 whether it is repeated. */
364 /* Number of repetitions we have detected so far. */
368 fprintf_filtered (stream
, ", ");
374 && !memcmp (VALUE_CONTENTS (val
) + typelen
* i
,
375 VALUE_CONTENTS (val
) + typelen
* rep1
, typelen
))
381 if (reps
> REPEAT_COUNT_THRESHOLD
)
383 val_print (VALUE_TYPE (val
),
384 VALUE_CONTENTS (val
) + typelen
* i
,
385 VALUE_ADDRESS (val
) + typelen
* i
,
386 stream
, format
, 1, 0, pretty
);
387 fprintf (stream
, " <repeats %u times>", reps
);
389 things_printed
+= REPEAT_COUNT_THRESHOLD
;
393 val_print (VALUE_TYPE (val
),
394 VALUE_CONTENTS (val
) + typelen
* i
,
395 VALUE_ADDRESS (val
) + typelen
* i
,
396 stream
, format
, 1, 0, pretty
);
401 fprintf_filtered (stream
, "...");
403 fprintf_filtered (stream
, "}");
408 struct type
*type
= VALUE_TYPE (val
);
410 /* If it is a pointer, indicate what it points to.
412 Print type also if it is a reference.
414 C++: if it is a member pointer, we will take care
415 of that when we print it. */
416 if (TYPE_CODE (type
) == TYPE_CODE_PTR
417 || TYPE_CODE (type
) == TYPE_CODE_REF
)
419 /* Hack: remove (char *) for char strings. Their
420 type is indicated by the quoted string anyway. */
421 if (TYPE_CODE (type
) == TYPE_CODE_PTR
422 && TYPE_LENGTH (TYPE_TARGET_TYPE (type
)) == sizeof(char)
423 && TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_INT
424 && !TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
)))
430 fprintf_filtered (stream
, "(");
431 type_print (type
, "", stream
, -1);
432 fprintf_filtered (stream
, ") ");
435 return val_print (type
, VALUE_CONTENTS (val
),
436 VALUE_ADDRESS (val
), stream
, format
, 1, 0, pretty
);
440 /* Return truth value for assertion that TYPE is of the type
441 "pointer to virtual function". */
443 is_vtbl_ptr_type(type
)
446 char *typename
= type_name_no_tag (type
);
447 static const char vtbl_ptr_name
[] =
448 { CPLUS_MARKER
,'v','t','b','l','_','p','t','r','_','t','y','p','e', 0 };
450 return (typename
!= NULL
&& !strcmp(typename
, vtbl_ptr_name
));
453 /* Return truth value for the assertion that TYPE is of the type
454 "pointer to virtual function table". */
459 if (TYPE_CODE (type
) == TYPE_CODE_PTR
)
460 type
= TYPE_TARGET_TYPE (type
);
464 if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
465 && TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_STRUCT
)
466 /* Virtual functions tables are full of pointers to virtual functions. */
467 return is_vtbl_ptr_type (TYPE_TARGET_TYPE (type
));
471 /* Mutually recursive subroutines of cplus_val_print and val_print to print out
472 a structure's fields: val_print_fields and cplus_val_print.
474 TYPE, VALADDR, STREAM, RECURSE, and PRETTY have the
475 same meanings as in cplus_val_print and val_print.
477 DONT_PRINT is an array of baseclass types that we
478 should not print, or zero if called from top level. */
481 val_print_fields (type
, valaddr
, stream
, format
, recurse
, pretty
, dont_print
)
487 enum val_prettyprint pretty
;
488 struct type
**dont_print
;
490 int i
, len
, n_baseclasses
;
492 check_stub_type (type
);
494 fprintf_filtered (stream
, "{");
495 len
= TYPE_NFIELDS (type
);
496 n_baseclasses
= TYPE_N_BASECLASSES (type
);
498 /* Print out baseclasses such that we don't print
499 duplicates of virtual baseclasses. */
500 if (n_baseclasses
> 0)
501 cplus_val_print (type
, valaddr
, stream
, format
, recurse
+1, pretty
, dont_print
);
503 if (!len
&& n_baseclasses
== 1)
504 fprintf_filtered (stream
, "<No data fields>");
507 extern int inspect_it
;
510 for (i
= n_baseclasses
; i
< len
; i
++)
512 /* Check if static field */
513 if (TYPE_FIELD_STATIC (type
, i
))
516 fprintf_filtered (stream
, ", ");
517 else if (n_baseclasses
> 0)
521 fprintf_filtered (stream
, "\n");
522 print_spaces_filtered (2 + 2 * recurse
, stream
);
523 fputs_filtered ("members of ", stream
);
524 fputs_filtered (type_name_no_tag (type
), stream
);
525 fputs_filtered (": ", stream
);
532 fprintf_filtered (stream
, "\n");
533 print_spaces_filtered (2 + 2 * recurse
, stream
);
537 wrap_here (n_spaces (2 + 2 * recurse
));
541 if (TYPE_CODE (TYPE_FIELD_TYPE (type
, i
)) == TYPE_CODE_PTR
)
542 fputs_filtered ("\"( ptr \"", stream
);
544 fputs_filtered ("\"( nodef \"", stream
);
545 fprint_symbol (stream
, TYPE_FIELD_NAME (type
, i
));
546 fputs_filtered ("\" \"", stream
);
547 fprint_symbol (stream
, TYPE_FIELD_NAME (type
, i
));
548 fputs_filtered ("\") \"", stream
);
552 fprint_symbol (stream
, TYPE_FIELD_NAME (type
, i
));
553 fputs_filtered (" = ", stream
);
555 if (TYPE_FIELD_PACKED (type
, i
))
559 /* Bitfields require special handling, especially due to byte
561 v
= value_from_longest (TYPE_FIELD_TYPE (type
, i
),
562 unpack_field_as_long (type
, valaddr
, i
));
564 val_print (TYPE_FIELD_TYPE (type
, i
), VALUE_CONTENTS (v
), 0,
565 stream
, format
, 0, recurse
+ 1, pretty
);
569 val_print (TYPE_FIELD_TYPE (type
, i
),
570 valaddr
+ TYPE_FIELD_BITPOS (type
, i
) / 8,
571 0, stream
, format
, 0, recurse
+ 1, pretty
);
576 fprintf_filtered (stream
, "\n");
577 print_spaces_filtered (2 * recurse
, stream
);
580 fprintf_filtered (stream
, "}");
583 /* Special val_print routine to avoid printing multiple copies of virtual
587 cplus_val_print (type
, valaddr
, stream
, format
, recurse
, pretty
, dont_print
)
593 enum val_prettyprint pretty
;
594 struct type
**dont_print
;
596 struct obstack tmp_obstack
;
597 struct type
**last_dont_print
598 = (struct type
**)obstack_next_free (&dont_print_obstack
);
599 int i
, n_baseclasses
= TYPE_N_BASECLASSES (type
);
603 /* If we're at top level, carve out a completely fresh
604 chunk of the obstack and use that until this particular
605 invocation returns. */
606 tmp_obstack
= dont_print_obstack
;
607 /* Bump up the high-water mark. Now alpha is omega. */
608 obstack_finish (&dont_print_obstack
);
611 for (i
= 0; i
< n_baseclasses
; i
++)
616 if (BASETYPE_VIA_VIRTUAL (type
, i
))
618 struct type
**first_dont_print
619 = (struct type
**)obstack_base (&dont_print_obstack
);
621 int j
= (struct type
**)obstack_next_free (&dont_print_obstack
)
625 if (TYPE_BASECLASS (type
, i
) == first_dont_print
[j
])
628 obstack_ptr_grow (&dont_print_obstack
, TYPE_BASECLASS (type
, i
));
631 baddr
= baseclass_addr (type
, i
, valaddr
, 0, &err
);
632 if (err
== 0 && baddr
== 0)
633 error ("could not find virtual baseclass `%s'\n",
634 type_name_no_tag (TYPE_BASECLASS (type
, i
)));
638 fprintf_filtered (stream
, "\n");
639 print_spaces_filtered (2 * recurse
, stream
);
641 fputs_filtered ("<", stream
);
642 fputs_filtered (type_name_no_tag (TYPE_BASECLASS (type
, i
)), stream
);
643 fputs_filtered ("> = ", stream
);
645 fprintf_filtered (stream
, "<invalid address 0x%x>", baddr
);
647 val_print_fields (TYPE_BASECLASS (type
, i
), baddr
, stream
, format
,
649 (struct type
**)obstack_base (&dont_print_obstack
));
650 fputs_filtered (", ", stream
);
658 /* Free the space used to deal with the printing
659 of this type from top level. */
660 obstack_free (&dont_print_obstack
, last_dont_print
);
661 /* Reset watermark so that we can continue protecting
662 ourselves from whatever we were protecting ourselves. */
663 dont_print_obstack
= tmp_obstack
;
668 print_class_member (valaddr
, domain
, stream
, prefix
)
675 /* VAL is a byte offset into the structure type DOMAIN.
676 Find the name of the field for that offset and
680 register unsigned int i
;
681 unsigned len
= TYPE_NFIELDS (domain
);
682 /* @@ Make VAL into bit offset */
683 LONGEST val
= unpack_long (builtin_type_int
, valaddr
) << 3;
684 for (i
= TYPE_N_BASECLASSES (domain
); i
< len
; i
++)
686 int bitpos
= TYPE_FIELD_BITPOS (domain
, i
);
690 if (val
< bitpos
&& i
!= 0)
692 /* Somehow pointing into a field. */
694 extra
= (val
- TYPE_FIELD_BITPOS (domain
, i
));
705 fprintf_filtered (stream
, prefix
);
706 name
= type_name_no_tag (domain
);
708 fputs_filtered (name
, stream
);
710 type_print_base (domain
, stream
, 0, 0);
711 fprintf_filtered (stream
, "::");
712 fputs_filtered (TYPE_FIELD_NAME (domain
, i
), stream
);
714 fprintf_filtered (stream
, " + %d bytes", extra
);
716 fprintf_filtered (stream
, " (offset in bits)");
719 fprintf_filtered (stream
, "%d", val
>> 3);
722 /* Print data of type TYPE located at VALADDR (within GDB),
723 which came from the inferior at address ADDRESS,
724 onto stdio stream STREAM according to FORMAT
725 (a letter or 0 for natural format). The data at VALADDR
726 is in target byte order.
728 If the data are a string pointer, returns the number of
729 sting characters printed.
731 if DEREF_REF is nonzero, then dereference references,
732 otherwise just print them like pointers.
734 The PRETTY parameter controls prettyprinting. */
737 val_print (type
, valaddr
, address
, stream
, format
, deref_ref
, recurse
, pretty
)
745 enum val_prettyprint pretty
;
747 register unsigned int i
;
749 struct type
*elttype
;
754 if (pretty
== Val_pretty_default
)
756 pretty
= prettyprint
? Val_prettyprint
: Val_no_prettyprint
;
761 check_stub_type (type
);
763 if (TYPE_FLAGS (type
) & TYPE_FLAG_STUB
)
765 fprintf_filtered (stream
, "<unknown struct>");
770 switch (TYPE_CODE (type
))
772 case TYPE_CODE_ARRAY
:
773 if (TYPE_LENGTH (type
) > 0
774 && TYPE_LENGTH (TYPE_TARGET_TYPE (type
)) > 0)
776 elttype
= TYPE_TARGET_TYPE (type
);
777 eltlen
= TYPE_LENGTH (elttype
);
778 len
= TYPE_LENGTH (type
) / eltlen
;
780 print_spaces_filtered (2 + 2 * recurse
, stream
);
781 fprintf_filtered (stream
, "{");
782 /* For an array of chars, print with string syntax. */
783 if (eltlen
== 1 && TYPE_CODE (elttype
) == TYPE_CODE_INT
784 && (format
== 0 || format
== 's') )
785 print_string (stream
, valaddr
, len
, 0);
788 unsigned int things_printed
= 0;
790 /* If this is a virtual function table, print the 0th
791 entry specially, and the rest of the members normally. */
792 if (is_vtbl_ptr_type (elttype
))
794 fprintf_filtered (stream
, "%d vtable entries", len
-1);
800 for (; i
< len
&& things_printed
< print_max
; i
++)
802 /* Position of the array element we are examining to see
803 whether it is repeated. */
805 /* Number of repetitions we have detected so far. */
811 fprintf_filtered (stream
, ",\n");
812 print_spaces_filtered (2 + 2 * recurse
, stream
);
815 fprintf_filtered (stream
, ", ");
816 wrap_here (n_spaces (2 + 2 * recurse
));
821 && !memcmp (valaddr
+ i
* eltlen
,
822 valaddr
+ rep1
* eltlen
, eltlen
))
828 if (reps
> REPEAT_COUNT_THRESHOLD
)
830 val_print (elttype
, valaddr
+ i
* eltlen
,
831 0, stream
, format
, deref_ref
,
832 recurse
+ 1, pretty
);
833 fprintf_filtered (stream
, " <repeats %u times>", reps
);
835 things_printed
+= REPEAT_COUNT_THRESHOLD
;
839 val_print (elttype
, valaddr
+ i
* eltlen
,
840 0, stream
, format
, deref_ref
,
841 recurse
+ 1, pretty
);
846 fprintf_filtered (stream
, "...");
848 fprintf_filtered (stream
, "}");
851 /* Array of unspecified length: treat like pointer to first elt. */
852 valaddr
= (char *) &address
;
855 if (format
&& format
!= 's')
857 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
860 if (TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_METHOD
)
862 struct type
*domain
= TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (type
));
868 addr
= unpack_pointer (lookup_pointer_type (builtin_type_void
),
870 if (addr
< 128) /* FIXME! What is this 128? */
872 len
= TYPE_NFN_FIELDS (domain
);
873 for (i
= 0; i
< len
; i
++)
875 f
= TYPE_FN_FIELDLIST1 (domain
, i
);
876 len2
= TYPE_FN_FIELDLIST_LENGTH (domain
, i
);
878 for (j
= 0; j
< len2
; j
++)
881 if (TYPE_FN_FIELD_VOFFSET (f
, j
) == addr
)
891 struct symbol
*sym
= find_pc_function (addr
);
893 error ("invalid pointer to member function");
894 len
= TYPE_NFN_FIELDS (domain
);
895 for (i
= 0; i
< len
; i
++)
897 f
= TYPE_FN_FIELDLIST1 (domain
, i
);
898 len2
= TYPE_FN_FIELDLIST_LENGTH (domain
, i
);
900 for (j
= 0; j
< len2
; j
++)
903 if (!strcmp (SYMBOL_NAME (sym
), TYPE_FN_FIELD_PHYSNAME (f
, j
)))
911 fprintf_filtered (stream
, "&");
912 type_print_varspec_prefix (TYPE_FN_FIELD_TYPE (f
, j
), stream
, 0, 0);
913 fprintf (stream
, kind
);
914 if (TYPE_FN_FIELD_PHYSNAME (f
, j
)[0] == '_'
915 && TYPE_FN_FIELD_PHYSNAME (f
, j
)[1] == CPLUS_MARKER
)
916 type_print_method_args
917 (TYPE_FN_FIELD_ARGS (f
, j
) + 1, "~",
918 TYPE_FN_FIELDLIST_NAME (domain
, i
), 0, stream
);
920 type_print_method_args
921 (TYPE_FN_FIELD_ARGS (f
, j
), "",
922 TYPE_FN_FIELDLIST_NAME (domain
, i
), 0, stream
);
925 fprintf_filtered (stream
, "(");
926 type_print (type
, "", stream
, -1);
927 fprintf_filtered (stream
, ") %d", (int) addr
>> 3);
929 else if (TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_MEMBER
)
931 print_class_member (valaddr
,
932 TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (type
)),
937 CORE_ADDR addr
= unpack_pointer (type
, valaddr
);
938 elttype
= TYPE_TARGET_TYPE (type
);
940 if (TYPE_CODE (elttype
) == TYPE_CODE_FUNC
)
942 /* Try to print what function it points to. */
943 print_address_demangle (addr
, stream
, demangle
);
944 /* Return value is irrelevant except for string pointers. */
948 if (addressprint
&& format
!= 's')
949 fprintf_filtered (stream
, "0x%x", addr
);
951 /* For a pointer to char or unsigned char,
952 also print the string pointed to, unless pointer is null. */
953 i
= 0; /* Number of characters printed. */
954 if (TYPE_LENGTH (elttype
) == 1
955 && TYPE_CODE (elttype
) == TYPE_CODE_INT
956 && (format
== 0 || format
== 's')
958 /* If print_max is UINT_MAX, the alloca below will fail.
959 In that case don't try to print the string. */
960 && print_max
< UINT_MAX
)
962 int first_addr_err
= 0;
965 /* Get first character. */
966 errcode
= target_read_memory (addr
, (char *)&c
, 1);
969 /* First address out of bounds. */
975 char *string
= (char *) alloca (print_max
);
977 /* If the loop ends by us hitting print_max characters,
978 we need to have elipses at the end. */
979 int force_ellipses
= 1;
981 /* This loop always fetches print_max characters, even
982 though print_string might want to print more or fewer
983 (with repeated characters). This is so that
984 we don't spend forever fetching if we print
985 a long string consisting of the same character
986 repeated. Also so we can do it all in one memory
987 operation, which is faster. However, this will be
988 slower if print_max is set high, e.g. if you set
989 print_max to 1000, not only will it take a long
990 time to fetch short strings, but if you are near
991 the end of the address space, it might not work. */
993 errcode
= target_read_memory (addr
, string
, print_max
);
996 /* Try reading just one character. If that succeeds,
997 assume we hit the end of the address space, but
998 the initial part of the string is probably safe. */
1000 errcode
= target_read_memory (addr
, x
, 1);
1005 for (i
= 0; i
< print_max
; i
++)
1006 if (string
[i
] == '\0')
1014 fputs_filtered (" ", stream
);
1015 print_string (stream
, string
, i
, force_ellipses
);
1022 fprintf_filtered (stream
,
1023 (" <Address 0x%x out of bounds>"
1029 error ("Error reading memory address 0x%x: %s.",
1030 addr
+ i
, safe_strerror (errcode
));
1036 else /* print vtbl's nicely */
1037 if (is_vtbl_member(type
))
1039 CORE_ADDR vt_address
= unpack_pointer (type
, valaddr
);
1041 struct minimal_symbol
*msymbol
=
1042 lookup_minimal_symbol_by_pc (vt_address
);
1043 if ((msymbol
!= NULL
) && (vt_address
== msymbol
-> address
))
1045 fputs_filtered (" <", stream
);
1046 fputs_demangled (msymbol
-> name
, stream
,
1047 DMGL_ANSI
| DMGL_PARAMS
);
1048 fputs_filtered (">", stream
);
1054 vt_val
= value_at (TYPE_TARGET_TYPE (type
), vt_address
);
1055 val_print (VALUE_TYPE (vt_val
), VALUE_CONTENTS (vt_val
),
1056 VALUE_ADDRESS (vt_val
), stream
, format
,
1057 deref_ref
, recurse
+ 1, pretty
);
1060 fprintf_filtered (stream
, "\n");
1061 print_spaces_filtered (2 + 2 * recurse
, stream
);
1066 /* Return number of characters printed, plus one for the
1067 terminating null if we have "reached the end". */
1068 return i
+ (print_max
&& i
!= print_max
);
1072 case TYPE_CODE_MEMBER
:
1073 error ("not implemented: member type in val_print");
1077 if (TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_MEMBER
)
1079 print_class_member (valaddr
,
1080 TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (type
)),
1086 fprintf_filtered (stream
, "@0x%lx",
1087 unpack_long (builtin_type_int
, valaddr
));
1089 fputs_filtered (": ", stream
);
1091 /* De-reference the reference. */
1094 if (TYPE_CODE (TYPE_TARGET_TYPE (type
)) != TYPE_CODE_UNDEF
)
1098 (TYPE_TARGET_TYPE (type
),
1099 unpack_pointer (lookup_pointer_type (builtin_type_void
),
1101 val_print (VALUE_TYPE (deref_val
), VALUE_CONTENTS (deref_val
),
1102 VALUE_ADDRESS (deref_val
), stream
, format
,
1103 deref_ref
, recurse
+ 1, pretty
);
1106 fputs_filtered ("???", stream
);
1110 case TYPE_CODE_UNION
:
1111 if (recurse
&& !unionprint
)
1113 fprintf_filtered (stream
, "{...}");
1117 case TYPE_CODE_STRUCT
:
1118 if (vtblprint
&& is_vtbl_ptr_type(type
))
1120 /* Print the unmangled name if desired. */
1121 print_address_demangle(*((int *) (valaddr
+ /* FIXME bytesex */
1122 TYPE_FIELD_BITPOS (type
, VTBL_FNADDR_OFFSET
) / 8)),
1126 val_print_fields (type
, valaddr
, stream
, format
, recurse
, pretty
, 0);
1129 case TYPE_CODE_ENUM
:
1132 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
1135 len
= TYPE_NFIELDS (type
);
1136 val
= unpack_long (builtin_type_int
, valaddr
);
1137 for (i
= 0; i
< len
; i
++)
1140 if (val
== TYPE_FIELD_BITPOS (type
, i
))
1144 fputs_filtered (TYPE_FIELD_NAME (type
, i
), stream
);
1147 fprintf_filtered (stream
, "%lld", val
);
1149 fprintf_filtered (stream
, "%ld", val
);
1153 case TYPE_CODE_FUNC
:
1156 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
1159 /* FIXME, we should consider, at least for ANSI C language, eliminating
1160 the distinction made between FUNCs and POINTERs to FUNCs. */
1161 fprintf_filtered (stream
, "{");
1162 type_print (type
, "", stream
, -1);
1163 fprintf_filtered (stream
, "} ");
1164 /* Try to print what function it points to, and its address. */
1165 print_address_demangle (address
, stream
, demangle
);
1169 if (format
|| output_format
)
1171 print_scalar_formatted (valaddr
, type
,
1172 format
? format
: output_format
,
1176 if (TYPE_LENGTH (type
) > sizeof (LONGEST
))
1178 if (TYPE_UNSIGNED (type
))
1180 /* First figure out whether the number in fact has zeros
1181 in all its bytes more significant than least significant
1182 sizeof (LONGEST) ones. */
1184 /* Pointer to first (i.e. lowest address) nonzero character. */
1186 len
= TYPE_LENGTH (type
);
1188 #if TARGET_BYTE_ORDER == BIG_ENDIAN
1190 len
> sizeof (LONGEST
)
1191 && p
< valaddr
+ TYPE_LENGTH (type
);
1193 #else /* Little endian. */
1194 first_addr
= valaddr
;
1195 for (p
= valaddr
+ TYPE_LENGTH (type
);
1196 len
> sizeof (LONGEST
) && p
>= valaddr
;
1198 #endif /* Little endian. */
1205 #if TARGET_BYTE_ORDER == BIG_ENDIAN
1209 if (len
<= sizeof (LONGEST
))
1211 /* We can print it in decimal. */
1214 #if defined (LONG_LONG)
1219 unpack_long (BUILTIN_TYPE_LONGEST
, first_addr
));
1223 /* It is big, so print it in hex. */
1224 print_hex_chars (stream
, (unsigned char *)first_addr
, len
);
1229 /* Signed. One could assume two's complement (a reasonable
1230 assumption, I think) and do better than this. */
1231 print_hex_chars (stream
, (unsigned char *)valaddr
,
1232 TYPE_LENGTH (type
));
1236 #ifdef PRINT_TYPELESS_INTEGER
1237 PRINT_TYPELESS_INTEGER (stream
, type
, unpack_long (type
, valaddr
));
1240 fprintf_filtered (stream
,
1241 TYPE_UNSIGNED (type
) ? "%u" : "%d",
1242 unpack_long (type
, valaddr
));
1244 fprintf_filtered (stream
,
1245 TYPE_UNSIGNED (type
) ? "%llu" : "%lld",
1246 unpack_long (type
, valaddr
));
1250 if (TYPE_LENGTH (type
) == 1)
1252 fprintf_filtered (stream
, " '");
1253 printchar ((unsigned char) unpack_long (type
, valaddr
),
1255 fprintf_filtered (stream
, "'");
1261 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
1263 print_floating (valaddr
, type
, stream
);
1266 case TYPE_CODE_VOID
:
1267 fprintf_filtered (stream
, "void");
1270 case TYPE_CODE_UNDEF
:
1271 /* This happens (without TYPE_FLAG_STUB set) on systems which don't use
1272 dbx xrefs (NO_DBX_XREFS in gcc) if a file has a "struct foo *bar"
1273 and no complete type for struct foo in that file. */
1274 fprintf_filtered (stream
, "<unknown struct>");
1277 case TYPE_CODE_ERROR
:
1278 fprintf_filtered (stream
, "?");
1281 case TYPE_CODE_RANGE
:
1282 /* FIXME, we should not ever have to print one of these yet. */
1283 fprintf_filtered (stream
, "<range type>");
1287 error ("Invalid type code in symbol table.");
1293 /* Print a description of a type in the format of a
1294 typedef for the current language.
1295 NEW is the new name for a type TYPE. */
1297 typedef_print (type
, new, stream
)
1302 switch (current_language
->la_language
)
1306 case language_cplus
:
1307 fprintf_filtered(stream
, "typedef ");
1308 type_print(type
,"",stream
,0);
1309 if(TYPE_NAME ((SYMBOL_TYPE (new))) == 0
1310 || 0 != strcmp (TYPE_NAME ((SYMBOL_TYPE (new))),
1312 fprintf_filtered(stream
, " %s", SYMBOL_NAME(new));
1317 fprintf_filtered(stream
, "TYPE ");
1318 if(!TYPE_NAME(SYMBOL_TYPE(new)) ||
1319 strcmp (TYPE_NAME(SYMBOL_TYPE(new)),
1321 fprintf_filtered(stream
, "%s = ", SYMBOL_NAME(new));
1323 fprintf_filtered(stream
, "<builtin> = ");
1324 type_print(type
,"",stream
,0);
1328 error("Language not supported.");
1330 fprintf_filtered(stream
, ";\n");
1334 /* Print a description of a type TYPE
1335 in the form of a declaration of a variable named VARSTRING.
1336 (VARSTRING is demangled if necessary.)
1337 Output goes to STREAM (via stdio).
1338 If SHOW is positive, we show the contents of the outermost level
1339 of structure even if there is a type name that could be used instead.
1340 If SHOW is negative, we never show the details of elements' types. */
1343 type_print (type
, varstring
, stream
, show
)
1349 type_print_1 (type
, varstring
, stream
, show
, 0);
1352 /* LEVEL is the depth to indent lines by. */
1355 type_print_1 (type
, varstring
, stream
, show
, level
)
1362 register enum type_code code
;
1363 char *demangled
= NULL
;
1366 type_print_base (type
, stream
, show
, level
);
1367 code
= TYPE_CODE (type
);
1368 if ((varstring
&& *varstring
)
1370 /* Need a space if going to print stars or brackets;
1371 but not if we will print just a type name. */
1372 ((show
> 0 || TYPE_NAME (type
) == 0)
1374 (code
== TYPE_CODE_PTR
|| code
== TYPE_CODE_FUNC
1375 || code
== TYPE_CODE_METHOD
1376 || code
== TYPE_CODE_ARRAY
1377 || code
== TYPE_CODE_MEMBER
1378 || code
== TYPE_CODE_REF
)))
1379 fprintf_filtered (stream
, " ");
1380 type_print_varspec_prefix (type
, stream
, show
, 0);
1382 /* See if the name has a C++ demangled equivalent, and if so, print that
1387 demangled
= cplus_demangle (varstring
, DMGL_ANSI
| DMGL_PARAMS
);
1389 fputs_filtered ((demangled
!= NULL
) ? demangled
: varstring
, stream
);
1391 /* For demangled function names, we have the arglist as part of the name,
1392 so don't print an additional pair of ()'s */
1394 demangled_args
= (demangled
!= NULL
) && (code
== TYPE_CODE_FUNC
);
1395 type_print_varspec_suffix (type
, stream
, show
, 0, demangled_args
);
1403 /* Print the method arguments ARGS to the file STREAM. */
1405 type_print_method_args (args
, prefix
, varstring
, staticp
, stream
)
1407 char *prefix
, *varstring
;
1413 fputs_demangled (prefix
, stream
, DMGL_ANSI
| DMGL_PARAMS
);
1414 fputs_demangled (varstring
, stream
, DMGL_ANSI
| DMGL_PARAMS
);
1415 fputs_filtered (" (", stream
);
1416 if (args
&& args
[!staticp
] && args
[!staticp
]->code
!= TYPE_CODE_VOID
)
1418 i
= !staticp
; /* skip the class variable */
1421 type_print (args
[i
++], "", stream
, 0);
1424 fprintf_filtered (stream
, " ...");
1427 else if (args
[i
]->code
!= TYPE_CODE_VOID
)
1429 fprintf_filtered (stream
, ", ");
1434 fprintf_filtered (stream
, ")");
1437 /* If TYPE is a derived type, then print out derivation information.
1438 Print only the actual base classes of this type, not the base classes
1439 of the base classes. I.E. for the derivation hierarchy:
1442 class B : public A {int b; };
1443 class C : public B {int c; };
1445 Print the type of class C as:
1447 class C : public B {
1451 Not as the following (like gdb used to), which is not legal C++ syntax for
1452 derived types and may be confused with the multiple inheritance form:
1454 class C : public B : public A {
1458 In general, gdb should try to print the types as closely as possible to
1459 the form that they appear in the source code. */
1462 type_print_derivation_info (stream
, type
)
1469 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
1471 fputs_filtered (i
== 0 ? ": " : ", ", stream
);
1472 fprintf_filtered (stream
, "%s%s ",
1473 BASETYPE_VIA_PUBLIC (type
, i
) ? "public" : "private",
1474 BASETYPE_VIA_VIRTUAL(type
, i
) ? " virtual" : "");
1475 name
= type_name_no_tag (TYPE_BASECLASS (type
, i
));
1476 fprintf_filtered (stream
, "%s", name
? name
: "(null)");
1480 fputs_filtered (" ", stream
);
1484 /* Print any asterisks or open-parentheses needed before the
1485 variable name (to describe its type).
1487 On outermost call, pass 0 for PASSED_A_PTR.
1488 On outermost call, SHOW > 0 means should ignore
1489 any typename for TYPE and show its details.
1490 SHOW is always zero on recursive calls. */
1493 type_print_varspec_prefix (type
, stream
, show
, passed_a_ptr
)
1503 if (TYPE_NAME (type
) && show
<= 0)
1508 switch (TYPE_CODE (type
))
1511 type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0, 1);
1512 fprintf_filtered (stream
, "*");
1515 case TYPE_CODE_MEMBER
:
1517 fprintf_filtered (stream
, "(");
1518 type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0,
1520 fprintf_filtered (stream
, " ");
1521 name
= type_name_no_tag (TYPE_DOMAIN_TYPE (type
));
1523 fputs_filtered (name
, stream
);
1525 type_print_base (TYPE_DOMAIN_TYPE (type
), stream
, 0, passed_a_ptr
);
1526 fprintf_filtered (stream
, "::");
1529 case TYPE_CODE_METHOD
:
1531 fprintf (stream
, "(");
1532 type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0,
1536 fprintf_filtered (stream
, " ");
1537 type_print_base (TYPE_DOMAIN_TYPE (type
), stream
, 0,
1539 fprintf_filtered (stream
, "::");
1544 type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0, 1);
1545 fprintf_filtered (stream
, "&");
1548 case TYPE_CODE_FUNC
:
1549 type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0,
1552 fprintf_filtered (stream
, "(");
1555 case TYPE_CODE_ARRAY
:
1556 type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0,
1559 fprintf_filtered (stream
, "(");
1562 case TYPE_CODE_UNDEF
:
1563 case TYPE_CODE_STRUCT
:
1564 case TYPE_CODE_UNION
:
1565 case TYPE_CODE_ENUM
:
1568 case TYPE_CODE_VOID
:
1569 case TYPE_CODE_ERROR
:
1570 case TYPE_CODE_CHAR
:
1571 case TYPE_CODE_BOOL
:
1573 case TYPE_CODE_RANGE
:
1574 case TYPE_CODE_PASCAL_ARRAY
:
1575 /* These types need no prefix. They are listed here so that
1576 gcc -Wall will reveal any types that haven't been handled. */
1582 type_print_args (type
, stream
)
1589 fprintf_filtered (stream
, "(");
1590 args
= TYPE_ARG_TYPES (type
);
1593 if (args
[1] == NULL
)
1595 fprintf_filtered (stream
, "...");
1600 args
[i
] != NULL
&& args
[i
]->code
!= TYPE_CODE_VOID
;
1603 type_print_1 (args
[i
], "", stream
, -1, 0);
1604 if (args
[i
+1] == NULL
)
1606 fprintf_filtered (stream
, "...");
1608 else if (args
[i
+1]->code
!= TYPE_CODE_VOID
)
1610 fprintf_filtered (stream
, ",");
1616 fprintf_filtered (stream
, ")");
1619 /* Print any array sizes, function arguments or close parentheses
1620 needed after the variable name (to describe its type).
1621 Args work like type_print_varspec_prefix. */
1624 type_print_varspec_suffix (type
, stream
, show
, passed_a_ptr
, demangled_args
)
1634 if (TYPE_NAME (type
) && show
<= 0)
1639 switch (TYPE_CODE (type
))
1641 case TYPE_CODE_ARRAY
:
1643 fprintf_filtered (stream
, ")");
1645 fprintf_filtered (stream
, "[");
1646 if (TYPE_LENGTH (type
) > 0
1647 && TYPE_LENGTH (TYPE_TARGET_TYPE (type
)) > 0)
1648 fprintf_filtered (stream
, "%d",
1650 / TYPE_LENGTH (TYPE_TARGET_TYPE (type
))));
1651 fprintf_filtered (stream
, "]");
1653 type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0,
1657 case TYPE_CODE_MEMBER
:
1659 fprintf_filtered (stream
, ")");
1660 type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0, 0, 0);
1663 case TYPE_CODE_METHOD
:
1665 fprintf_filtered (stream
, ")");
1666 type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0, 0, 0);
1669 type_print_args (type
, stream
);
1675 type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0, 1, 0);
1678 case TYPE_CODE_FUNC
:
1679 type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0,
1682 fprintf_filtered (stream
, ")");
1683 if (!demangled_args
)
1684 fprintf_filtered (stream
, "()");
1687 case TYPE_CODE_UNDEF
:
1688 case TYPE_CODE_STRUCT
:
1689 case TYPE_CODE_UNION
:
1690 case TYPE_CODE_ENUM
:
1693 case TYPE_CODE_VOID
:
1694 case TYPE_CODE_ERROR
:
1695 case TYPE_CODE_CHAR
:
1696 case TYPE_CODE_BOOL
:
1698 case TYPE_CODE_RANGE
:
1699 case TYPE_CODE_PASCAL_ARRAY
:
1700 /* These types do not need a suffix. They are listed so that
1701 gcc -Wall will report types that may not have been considered. */
1706 /* Print the name of the type (or the ultimate pointer target,
1707 function value or array element), or the description of a
1710 SHOW nonzero means don't print this type as just its name;
1711 show its real definition even if it has a name.
1712 SHOW zero means print just typename or struct tag if there is one
1713 SHOW negative means abbreviate structure elements.
1714 SHOW is decremented for printing of structure elements.
1716 LEVEL is the depth to indent by.
1717 We increase it for some recursive calls. */
1720 type_print_base (type
, stream
, show
, level
)
1729 register int lastval
;
1731 char *demangled_name
;
1732 enum {s_none
, s_public
, s_private
, s_protected
} section_type
;
1738 fputs_filtered ("<type unknown>", stream
);
1742 /* When SHOW is zero or less, and there is a valid type name, then always
1743 just print the type name directly from the type. */
1745 if ((show
<= 0) && (TYPE_NAME (type
) != NULL
))
1747 fputs_filtered (TYPE_NAME (type
), stream
);
1751 switch (TYPE_CODE (type
))
1753 case TYPE_CODE_ARRAY
:
1755 case TYPE_CODE_MEMBER
:
1757 case TYPE_CODE_FUNC
:
1758 case TYPE_CODE_METHOD
:
1759 type_print_base (TYPE_TARGET_TYPE (type
), stream
, show
, level
);
1762 case TYPE_CODE_STRUCT
:
1763 fprintf_filtered (stream
,
1764 HAVE_CPLUS_STRUCT (type
) ? "class " : "struct ");
1767 case TYPE_CODE_UNION
:
1768 fprintf_filtered (stream
, "union ");
1770 if (name
= type_name_no_tag (type
))
1772 fputs_filtered (name
, stream
);
1773 fputs_filtered (" ", stream
);
1777 fprintf_filtered (stream
, "{...}");
1780 check_stub_type (type
);
1782 type_print_derivation_info (stream
, type
);
1784 fprintf_filtered (stream
, "{\n");
1785 if ((TYPE_NFIELDS (type
) == 0) && (TYPE_NFN_FIELDS (type
) == 0))
1787 if (TYPE_FLAGS (type
) & TYPE_FLAG_STUB
)
1788 fprintfi_filtered (level
+ 4, stream
, "<incomplete type>\n");
1790 fprintfi_filtered (level
+ 4, stream
, "<no data fields>\n");
1793 /* Start off with no specific section type, so we can print
1794 one for the first field we find, and use that section type
1795 thereafter until we find another type. */
1797 section_type
= s_none
;
1799 /* If there is a base class for this type,
1800 do not print the field that it occupies. */
1802 len
= TYPE_NFIELDS (type
);
1803 for (i
= TYPE_N_BASECLASSES (type
); i
< len
; i
++)
1806 /* Don't print out virtual function table. */
1807 if ((TYPE_FIELD_NAME (type
, i
))[5] == CPLUS_MARKER
&&
1808 !strncmp (TYPE_FIELD_NAME (type
, i
), "_vptr", 5))
1811 /* If this is a C++ class we can print the various C++ section
1814 if (HAVE_CPLUS_STRUCT (type
))
1816 if (TYPE_FIELD_PROTECTED (type
, i
))
1818 if (section_type
!= s_protected
)
1820 section_type
= s_protected
;
1821 fprintfi_filtered (level
+ 2, stream
,
1825 else if (TYPE_FIELD_PRIVATE (type
, i
))
1827 if (section_type
!= s_private
)
1829 section_type
= s_private
;
1830 fprintfi_filtered (level
+ 2, stream
, "private:\n");
1835 if (section_type
!= s_public
)
1837 section_type
= s_public
;
1838 fprintfi_filtered (level
+ 2, stream
, "public:\n");
1843 print_spaces_filtered (level
+ 4, stream
);
1844 if (TYPE_FIELD_STATIC (type
, i
))
1846 fprintf_filtered (stream
, "static ");
1848 type_print_1 (TYPE_FIELD_TYPE (type
, i
),
1849 TYPE_FIELD_NAME (type
, i
),
1850 stream
, show
- 1, level
+ 4);
1851 if (!TYPE_FIELD_STATIC (type
, i
)
1852 && TYPE_FIELD_PACKED (type
, i
))
1854 /* It is a bitfield. This code does not attempt
1855 to look at the bitpos and reconstruct filler,
1856 unnamed fields. This would lead to misleading
1857 results if the compiler does not put out fields
1858 for such things (I don't know what it does). */
1859 fprintf_filtered (stream
, " : %d",
1860 TYPE_FIELD_BITSIZE (type
, i
));
1862 fprintf_filtered (stream
, ";\n");
1865 /* C++: print out the methods */
1866 len
= TYPE_NFN_FIELDS (type
);
1867 for (i
= 0; i
< len
; i
++)
1869 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (type
, i
);
1870 int j
, len2
= TYPE_FN_FIELDLIST_LENGTH (type
, i
);
1871 char *method_name
= TYPE_FN_FIELDLIST_NAME (type
, i
);
1872 int is_constructor
= name
&& strcmp(method_name
, name
) == 0;
1873 for (j
= 0; j
< len2
; j
++)
1876 if (TYPE_FN_FIELD_PROTECTED (f
, j
))
1878 if (section_type
!= s_protected
)
1880 section_type
= s_protected
;
1881 fprintfi_filtered (level
+ 2, stream
,
1885 else if (TYPE_FN_FIELD_PRIVATE (f
, j
))
1887 if (section_type
!= s_private
)
1889 section_type
= s_private
;
1890 fprintfi_filtered (level
+ 2, stream
, "private:\n");
1895 if (section_type
!= s_public
)
1897 section_type
= s_public
;
1898 fprintfi_filtered (level
+ 2, stream
, "public:\n");
1902 print_spaces_filtered (level
+ 4, stream
);
1903 if (TYPE_FN_FIELD_VIRTUAL_P (f
, j
))
1904 fprintf_filtered (stream
, "virtual ");
1905 else if (TYPE_FN_FIELD_STATIC_P (f
, j
))
1906 fprintf_filtered (stream
, "static ");
1907 if (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f
, j
)) == 0)
1909 /* Keep GDB from crashing here. */
1910 fprintf (stream
, "<undefined type> %s;\n",
1911 TYPE_FN_FIELD_PHYSNAME (f
, j
));
1914 else if (!is_constructor
)
1916 type_print (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f
, j
)),
1918 fputs_filtered (" ", stream
);
1920 if (TYPE_FN_FIELD_STUB (f
, j
))
1922 /* Build something we can demangle. */
1923 mangled_name
= gdb_mangle_name (type
, i
, j
);
1925 cplus_demangle (mangled_name
,
1926 DMGL_ANSI
| DMGL_PARAMS
);
1927 if (demangled_name
== NULL
)
1928 fprintf_filtered (stream
, "<badly mangled name %s>",
1932 fprintf_filtered (stream
, "%s",
1933 strchr (demangled_name
, ':') + 2);
1934 free (demangled_name
);
1936 free (mangled_name
);
1938 else if (TYPE_FN_FIELD_PHYSNAME (f
, j
)[0] == '_'
1939 && TYPE_FN_FIELD_PHYSNAME (f
, j
)[1] == CPLUS_MARKER
)
1940 type_print_method_args
1941 (TYPE_FN_FIELD_ARGS (f
, j
) + 1, "~",
1942 method_name
, 0, stream
);
1944 type_print_method_args
1945 (TYPE_FN_FIELD_ARGS (f
, j
), "",
1947 TYPE_FN_FIELD_STATIC_P (f
, j
), stream
);
1949 fprintf_filtered (stream
, ";\n");
1953 fprintfi_filtered (level
, stream
, "}");
1957 case TYPE_CODE_ENUM
:
1958 fprintf_filtered (stream
, "enum ");
1959 if (name
= type_name_no_tag (type
))
1961 fputs_filtered (name
, stream
);
1962 fputs_filtered (" ", stream
);
1966 fprintf_filtered (stream
, "{...}");
1969 fprintf_filtered (stream
, "{");
1970 len
= TYPE_NFIELDS (type
);
1972 for (i
= 0; i
< len
; i
++)
1975 if (i
) fprintf_filtered (stream
, ", ");
1977 fputs_filtered (TYPE_FIELD_NAME (type
, i
), stream
);
1978 if (lastval
!= TYPE_FIELD_BITPOS (type
, i
))
1980 fprintf_filtered (stream
, " = %d", TYPE_FIELD_BITPOS (type
, i
));
1981 lastval
= TYPE_FIELD_BITPOS (type
, i
);
1985 fprintf_filtered (stream
, "}");
1989 case TYPE_CODE_VOID
:
1990 fprintf_filtered (stream
, "void");
1993 case TYPE_CODE_UNDEF
:
1994 fprintf_filtered (stream
, "struct <unknown>");
1997 case TYPE_CODE_ERROR
:
1998 fprintf_filtered (stream
, "<unknown type>");
2001 case TYPE_CODE_RANGE
:
2002 /* This should not occur */
2003 fprintf_filtered (stream
, "<range type>");
2007 /* Handle types not explicitly handled by the other cases,
2008 such as fundamental types. For these, just print whatever
2009 the type name is, as recorded in the type itself. If there
2010 is no type name, then complain. */
2011 if (TYPE_NAME (type
) != NULL
)
2013 fputs_filtered (TYPE_NAME (type
), stream
);
2017 error ("Invalid type code (%d) in symbol table.", TYPE_CODE (type
));
2024 /* Validate an input or output radix setting, and make sure the user
2025 knows what they really did here. Radix setting is confusing, e.g.
2026 setting the input radix to "10" never changes it! */
2030 set_input_radix (args
, from_tty
, c
)
2033 struct cmd_list_element
*c
;
2035 unsigned radix
= *(unsigned *)c
->var
;
2038 printf_filtered ("Input radix set to decimal %d, hex %x, octal %o\n",
2039 radix
, radix
, radix
);
2045 set_output_radix (args
, from_tty
, c
)
2048 struct cmd_list_element
*c
;
2050 unsigned radix
= *(unsigned *)c
->var
;
2053 printf_filtered ("Output radix set to decimal %d, hex %x, octal %o\n",
2054 radix
, radix
, radix
);
2056 /* FIXME, we really should be able to validate the setting BEFORE
2061 output_format
= 'x';
2067 output_format
= 'o'; /* octal */
2071 error ("Unsupported radix ``decimal %d''; using decimal output",
2078 set_radix (arg
, from_tty
, c
)
2081 struct cmd_list_element
*c
;
2083 unsigned radix
= *(unsigned *)c
->var
;
2086 printf_filtered ("Radix set to decimal %d, hex %x, octal %o\n",
2087 radix
, radix
, radix
);
2089 input_radix
= radix
;
2090 output_radix
= radix
;
2092 set_output_radix (arg
, 0, c
);
2097 set_print (arg
, from_tty
)
2102 "\"set print\" must be followed by the name of a print subcommand.\n");
2103 help_list (setprintlist
, "set print ", -1, stdout
);
2108 show_print (args
, from_tty
)
2112 cmd_show_list (showprintlist
, from_tty
, "");
2116 _initialize_valprint ()
2118 struct cmd_list_element
*c
;
2120 add_prefix_cmd ("print", no_class
, set_print
,
2121 "Generic command for setting how things print.",
2122 &setprintlist
, "set print ", 0, &setlist
);
2123 add_alias_cmd ("p", "print", no_class
, 1, &setlist
);
2124 add_alias_cmd ("pr", "print", no_class
, 1, &setlist
); /* prefer set print
2126 add_prefix_cmd ("print", no_class
, show_print
,
2127 "Generic command for showing print settings.",
2128 &showprintlist
, "show print ", 0, &showlist
);
2129 add_alias_cmd ("p", "print", no_class
, 1, &showlist
);
2130 add_alias_cmd ("pr", "print", no_class
, 1, &showlist
);
2133 (add_set_cmd ("elements", no_class
, var_uinteger
, (char *)&print_max
,
2134 "Set limit on string chars or array elements to print.\n\
2135 \"set print elements 0\" causes there to be no limit.",
2140 (add_set_cmd ("pretty", class_support
, var_boolean
, (char *)&prettyprint
,
2141 "Set prettyprinting of structures.",
2146 (add_set_cmd ("union", class_support
, var_boolean
, (char *)&unionprint
,
2147 "Set printing of unions interior to structures.",
2152 (add_set_cmd ("vtbl", class_support
, var_boolean
, (char *)&vtblprint
,
2153 "Set printing of C++ virtual function tables.",
2158 (add_set_cmd ("array", class_support
, var_boolean
, (char *)&arrayprint
,
2159 "Set prettyprinting of arrays.",
2164 (add_set_cmd ("object", class_support
, var_boolean
, (char *)&objectprint
,
2165 "Set printing of object's derived type based on vtable info.",
2170 (add_set_cmd ("address", class_support
, var_boolean
, (char *)&addressprint
,
2171 "Set printing of addresses.",
2176 /* The "show radix" cmd isn't good enough to show two separate values.
2177 The rest of the code works, but the show part is confusing, so don't
2178 let them be set separately 'til we work out "show". */
2179 c
= add_set_cmd ("input-radix", class_support
, var_uinteger
,
2180 (char *)&input_radix
,
2181 "Set default input radix for entering numbers.",
2183 add_show_from_set (c
, &showlist
);
2184 c
->function
= set_input_radix
;
2186 c
= add_set_cmd ("output-radix", class_support
, var_uinteger
,
2187 (char *)&output_radix
,
2188 "Set default output radix for printing of values.",
2190 add_show_from_set (c
, &showlist
);
2191 c
->function
= set_output_radix
;
2194 c
= add_set_cmd ("radix", class_support
, var_uinteger
,
2195 (char *)&output_radix
,
2196 "Set default input and output number radix.",
2198 add_show_from_set (c
, &showlist
);
2199 c
->function
.sfunc
= set_radix
;
2201 /* Give people the defaults which they are used to. */
2211 obstack_begin (&dont_print_obstack
, 32 * sizeof (struct type
*));