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));
82 extern int demangle
; /* whether to print C++ syms raw or source-form */
84 /* Maximum number of chars to print for a string pointer value
85 or vector contents, or UINT_MAX for no limit. */
87 static unsigned int print_max
;
89 /* Default input and output radixes, and output format letter. */
91 unsigned input_radix
= 10;
92 unsigned output_radix
= 10;
93 int output_format
= 0;
95 /* Print repeat counts if there are more than this
96 many repetitions of an element in an array. */
97 #define REPEAT_COUNT_THRESHOLD 10
99 /* Define a mess of print controls. */
101 int prettyprint
; /* Controls pretty printing of structures */
102 int vtblprint
; /* Controls printing of vtbl's */
103 int unionprint
; /* Controls printing of nested unions. */
104 int arrayprint
; /* Controls pretty printing of arrays. */
105 int addressprint
; /* Controls pretty printing of addresses. */
106 int objectprint
; /* Controls looking up an object's derived type
107 using what we find in its vtables. */
109 struct obstack dont_print_obstack
;
112 /* Print the character string STRING, printing at most LENGTH characters.
113 Printing stops early if the number hits print_max; repeat counts
114 are printed as appropriate. Print ellipses at the end if we
115 had to stop before printing LENGTH characters, or if FORCE_ELLIPSES. */
118 print_string (stream
, string
, length
, force_ellipses
)
124 register unsigned int i
;
125 unsigned int things_printed
= 0;
128 extern int inspect_it
;
132 fputs_filtered ("\"\"", stdout
);
136 for (i
= 0; i
< length
&& things_printed
< print_max
; ++i
)
138 /* Position of the character we are examining
139 to see whether it is repeated. */
141 /* Number of repetitions we have detected so far. */
148 fputs_filtered (", ", stream
);
154 while (rep1
< length
&& string
[rep1
] == string
[i
])
160 if (reps
> REPEAT_COUNT_THRESHOLD
)
165 fputs_filtered ("\\\", ", stream
);
167 fputs_filtered ("\", ", stream
);
170 fputs_filtered ("'", stream
);
171 printchar (string
[i
], stream
, '\'');
172 fprintf_filtered (stream
, "' <repeats %u times>", reps
);
174 things_printed
+= REPEAT_COUNT_THRESHOLD
;
182 fputs_filtered ("\\\"", stream
);
184 fputs_filtered ("\"", stream
);
187 printchar (string
[i
], stream
, '"');
192 /* Terminate the quotes if necessary. */
196 fputs_filtered ("\\\"", stream
);
198 fputs_filtered ("\"", stream
);
201 if (force_ellipses
|| i
< length
)
202 fputs_filtered ("...", stream
);
205 /* Print a floating point value of type TYPE, pointed to in GDB by VALADDR,
209 print_floating (valaddr
, type
, stream
)
216 unsigned len
= TYPE_LENGTH (type
);
218 #if defined (IEEE_FLOAT)
220 /* Check for NaN's. Note that this code does not depend on us being
221 on an IEEE conforming system. It only depends on the target
222 machine using IEEE representation. This means (a)
223 cross-debugging works right, and (2) IEEE_FLOAT can (and should)
224 be defined for systems like the 68881, which uses IEEE
225 representation, but is not IEEE conforming. */
229 /* Is the sign bit 0? */
231 /* Is it is a NaN (i.e. the exponent is all ones and
232 the fraction is nonzero)? */
235 if (len
== sizeof (float))
237 /* It's single precision. */
238 bcopy (valaddr
, &low
, sizeof (low
));
239 /* target -> host. */
240 SWAP_TARGET_AND_HOST (&low
, sizeof (float));
241 nonnegative
= low
>= 0;
242 is_nan
= ((((low
>> 23) & 0xFF) == 0xFF)
243 && 0 != (low
& 0x7FFFFF));
249 /* It's double precision. Get the high and low words. */
251 #if TARGET_BYTE_ORDER == BIG_ENDIAN
252 bcopy (valaddr
+4, &low
, sizeof (low
));
253 bcopy (valaddr
+0, &high
, sizeof (high
));
255 bcopy (valaddr
+0, &low
, sizeof (low
));
256 bcopy (valaddr
+4, &high
, sizeof (high
));
258 SWAP_TARGET_AND_HOST (&low
, sizeof (low
));
259 SWAP_TARGET_AND_HOST (&high
, sizeof (high
));
260 nonnegative
= high
>= 0;
261 is_nan
= (((high
>> 20) & 0x7ff) == 0x7ff
262 && ! ((((high
& 0xfffff) == 0)) && (low
== 0)));
268 /* The meaning of the sign and fraction is not defined by IEEE.
269 But the user might know what they mean. For example, they
270 (in an implementation-defined manner) distinguish between
271 signaling and quiet NaN's. */
273 fprintf_filtered (stream
, "-NaN(0x%lx%.8lx)" + nonnegative
,
276 fprintf_filtered (stream
, "-NaN(0x%lx)" + nonnegative
, low
);
280 #endif /* IEEE_FLOAT. */
282 doub
= unpack_double (type
, valaddr
, &inv
);
284 fprintf_filtered (stream
, "<invalid float value>");
286 fprintf_filtered (stream
, len
<= sizeof(float) ? "%.9g" : "%.17g", doub
);
289 /* VALADDR points to an integer of LEN bytes. Print it in hex on stream. */
291 print_hex_chars (stream
, valaddr
, len
)
293 unsigned char *valaddr
;
298 fprintf_filtered (stream
, "0x");
299 #if TARGET_BYTE_ORDER == BIG_ENDIAN
303 #else /* Little endian. */
304 for (p
= valaddr
+ len
- 1;
309 fprintf_filtered (stream
, "%02x", *p
);
313 /* Print the value VAL in C-ish syntax on stream STREAM.
314 FORMAT is a format-letter, or 0 for print in natural format of data type.
315 If the object printed is a string pointer, returns
316 the number of string bytes printed. */
319 value_print (val
, stream
, format
, pretty
)
323 enum val_prettyprint pretty
;
325 register unsigned int i
, n
, typelen
;
329 printf_filtered ("<address of value unknown>");
332 if (VALUE_OPTIMIZED_OUT (val
))
334 printf_filtered ("<value optimized out>");
338 /* A "repeated" value really contains several values in a row.
339 They are made by the @ operator.
340 Print such values as if they were arrays. */
342 else if (VALUE_REPEATED (val
))
344 n
= VALUE_REPETITIONS (val
);
345 typelen
= TYPE_LENGTH (VALUE_TYPE (val
));
346 fprintf_filtered (stream
, "{");
347 /* Print arrays of characters using string syntax. */
348 if (typelen
== 1 && TYPE_CODE (VALUE_TYPE (val
)) == TYPE_CODE_INT
350 print_string (stream
, VALUE_CONTENTS (val
), n
, 0);
353 unsigned int things_printed
= 0;
355 for (i
= 0; i
< n
&& things_printed
< print_max
; i
++)
357 /* Position of the array element we are examining to see
358 whether it is repeated. */
360 /* Number of repetitions we have detected so far. */
364 fprintf_filtered (stream
, ", ");
370 && !bcmp (VALUE_CONTENTS (val
) + typelen
* i
,
371 VALUE_CONTENTS (val
) + typelen
* rep1
, typelen
))
377 if (reps
> REPEAT_COUNT_THRESHOLD
)
379 val_print (VALUE_TYPE (val
),
380 VALUE_CONTENTS (val
) + typelen
* i
,
381 VALUE_ADDRESS (val
) + typelen
* i
,
382 stream
, format
, 1, 0, pretty
);
383 fprintf (stream
, " <repeats %u times>", reps
);
385 things_printed
+= REPEAT_COUNT_THRESHOLD
;
389 val_print (VALUE_TYPE (val
),
390 VALUE_CONTENTS (val
) + typelen
* i
,
391 VALUE_ADDRESS (val
) + typelen
* i
,
392 stream
, format
, 1, 0, pretty
);
397 fprintf_filtered (stream
, "...");
399 fprintf_filtered (stream
, "}");
404 struct type
*type
= VALUE_TYPE (val
);
406 /* If it is a pointer, indicate what it points to.
408 Print type also if it is a reference.
410 C++: if it is a member pointer, we will take care
411 of that when we print it. */
412 if (TYPE_CODE (type
) == TYPE_CODE_PTR
413 || TYPE_CODE (type
) == TYPE_CODE_REF
)
415 /* Hack: remove (char *) for char strings. Their
416 type is indicated by the quoted string anyway. */
417 if (TYPE_CODE (type
) == TYPE_CODE_PTR
418 && TYPE_LENGTH (TYPE_TARGET_TYPE (type
)) == sizeof(char)
419 && TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_INT
420 && !TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
)))
426 fprintf_filtered (stream
, "(");
427 type_print (type
, "", stream
, -1);
428 fprintf_filtered (stream
, ") ");
431 return val_print (type
, VALUE_CONTENTS (val
),
432 VALUE_ADDRESS (val
), stream
, format
, 1, 0, pretty
);
436 /* Return truth value for assertion that TYPE is of the type
437 "pointer to virtual function". */
439 is_vtbl_ptr_type(type
)
442 char *typename
= type_name_no_tag (type
);
443 static const char vtbl_ptr_name
[] =
444 { CPLUS_MARKER
,'v','t','b','l','_','p','t','r','_','t','y','p','e', 0 };
446 return (typename
!= NULL
&& !strcmp(typename
, vtbl_ptr_name
));
449 /* Return truth value for the assertion that TYPE is of the type
450 "pointer to virtual function table". */
455 if (TYPE_CODE (type
) == TYPE_CODE_PTR
)
456 type
= TYPE_TARGET_TYPE (type
);
460 if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
461 && TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_STRUCT
)
462 /* Virtual functions tables are full of pointers to virtual functions. */
463 return is_vtbl_ptr_type (TYPE_TARGET_TYPE (type
));
467 /* Mutually recursive subroutines of cplus_val_print and val_print to print out
468 a structure's fields: val_print_fields and cplus_val_print.
470 TYPE, VALADDR, STREAM, RECURSE, and PRETTY have the
471 same meanings as in cplus_val_print and val_print.
473 DONT_PRINT is an array of baseclass types that we
474 should not print, or zero if called from top level. */
477 val_print_fields (type
, valaddr
, stream
, format
, recurse
, pretty
, dont_print
)
483 enum val_prettyprint pretty
;
484 struct type
**dont_print
;
486 int i
, len
, n_baseclasses
;
488 check_stub_type (type
);
490 fprintf_filtered (stream
, "{");
491 len
= TYPE_NFIELDS (type
);
492 n_baseclasses
= TYPE_N_BASECLASSES (type
);
494 /* Print out baseclasses such that we don't print
495 duplicates of virtual baseclasses. */
496 if (n_baseclasses
> 0)
497 cplus_val_print (type
, valaddr
, stream
, format
, recurse
+1, pretty
, dont_print
);
499 if (!len
&& n_baseclasses
== 1)
500 fprintf_filtered (stream
, "<No data fields>");
503 extern int inspect_it
;
506 for (i
= n_baseclasses
; i
< len
; i
++)
508 /* Check if static field */
509 if (TYPE_FIELD_STATIC (type
, i
))
512 fprintf_filtered (stream
, ", ");
513 else if (n_baseclasses
> 0)
515 fprintf_filtered (stream
, "\n");
516 print_spaces_filtered (2 + 2 * recurse
, stream
);
517 fputs_filtered ("members of ", stream
);
518 fputs_filtered (type_name_no_tag (type
), stream
);
519 fputs_filtered (": ", stream
);
525 fprintf_filtered (stream
, "\n");
526 print_spaces_filtered (2 + 2 * recurse
, stream
);
530 wrap_here (n_spaces (2 + 2 * recurse
));
534 if (TYPE_CODE (TYPE_FIELD_TYPE (type
, i
)) == TYPE_CODE_PTR
)
535 fputs_filtered ("\"( ptr \"", stream
);
537 fputs_filtered ("\"( nodef \"", stream
);
538 fputs_filtered (TYPE_FIELD_NAME (type
, i
), stream
);
539 fputs_filtered ("\" \"", stream
);
540 fputs_filtered (TYPE_FIELD_NAME (type
, i
), stream
);
541 fputs_filtered ("\") \"", stream
);
545 fputs_filtered (TYPE_FIELD_NAME (type
, i
), stream
);
546 fputs_filtered (" = ", stream
);
548 if (TYPE_FIELD_PACKED (type
, i
))
552 /* Bitfields require special handling, especially due to byte
554 v
= value_from_longest (TYPE_FIELD_TYPE (type
, i
),
555 unpack_field_as_long (type
, valaddr
, i
));
557 val_print (TYPE_FIELD_TYPE (type
, i
), VALUE_CONTENTS (v
), 0,
558 stream
, format
, 0, recurse
+ 1, pretty
);
562 val_print (TYPE_FIELD_TYPE (type
, i
),
563 valaddr
+ TYPE_FIELD_BITPOS (type
, i
) / 8,
564 0, stream
, format
, 0, recurse
+ 1, pretty
);
569 fprintf_filtered (stream
, "\n");
570 print_spaces_filtered (2 * recurse
, stream
);
573 fprintf_filtered (stream
, "}");
576 /* Special val_print routine to avoid printing multiple copies of virtual
580 cplus_val_print (type
, valaddr
, stream
, format
, recurse
, pretty
, dont_print
)
586 enum val_prettyprint pretty
;
587 struct type
**dont_print
;
589 struct obstack tmp_obstack
;
590 struct type
**last_dont_print
591 = (struct type
**)obstack_next_free (&dont_print_obstack
);
592 int i
, n_baseclasses
= TYPE_N_BASECLASSES (type
);
596 /* If we're at top level, carve out a completely fresh
597 chunk of the obstack and use that until this particular
598 invocation returns. */
599 tmp_obstack
= dont_print_obstack
;
600 /* Bump up the high-water mark. Now alpha is omega. */
601 obstack_finish (&dont_print_obstack
);
604 for (i
= 0; i
< n_baseclasses
; i
++)
609 if (BASETYPE_VIA_VIRTUAL (type
, i
))
611 struct type
**first_dont_print
612 = (struct type
**)obstack_base (&dont_print_obstack
);
614 int j
= (struct type
**)obstack_next_free (&dont_print_obstack
)
618 if (TYPE_BASECLASS (type
, i
) == first_dont_print
[j
])
621 obstack_ptr_grow (&dont_print_obstack
, TYPE_BASECLASS (type
, i
));
624 baddr
= baseclass_addr (type
, i
, valaddr
, 0, &err
);
625 if (err
== 0 && baddr
== 0)
626 error ("could not find virtual baseclass `%s'\n",
627 type_name_no_tag (TYPE_BASECLASS (type
, i
)));
629 fprintf_filtered (stream
, "\n");
631 print_spaces_filtered (2 + 2 * recurse
, stream
);
632 fputs_filtered ("<", stream
);
633 fputs_filtered (type_name_no_tag (TYPE_BASECLASS (type
, i
)), stream
);
634 fputs_filtered ("> = ", stream
);
636 fprintf_filtered (stream
, "<invalid address 0x%x>", baddr
);
638 val_print_fields (TYPE_BASECLASS (type
, i
), baddr
, stream
, format
,
640 (struct type
**)obstack_base (&dont_print_obstack
));
647 /* Free the space used to deal with the printing
648 of this type from top level. */
649 obstack_free (&dont_print_obstack
, last_dont_print
);
650 /* Reset watermark so that we can continue protecting
651 ourselves from whatever we were protecting ourselves. */
652 dont_print_obstack
= tmp_obstack
;
657 print_class_member (valaddr
, domain
, stream
, prefix
)
664 /* VAL is a byte offset into the structure type DOMAIN.
665 Find the name of the field for that offset and
669 register unsigned int i
;
670 unsigned len
= TYPE_NFIELDS (domain
);
671 /* @@ Make VAL into bit offset */
672 LONGEST val
= unpack_long (builtin_type_int
, valaddr
) << 3;
673 for (i
= TYPE_N_BASECLASSES (domain
); i
< len
; i
++)
675 int bitpos
= TYPE_FIELD_BITPOS (domain
, i
);
679 if (val
< bitpos
&& i
!= 0)
681 /* Somehow pointing into a field. */
683 extra
= (val
- TYPE_FIELD_BITPOS (domain
, i
));
694 fprintf_filtered (stream
, prefix
);
695 name
= type_name_no_tag (domain
);
697 fputs_filtered (name
, stream
);
699 type_print_base (domain
, stream
, 0, 0);
700 fprintf_filtered (stream
, "::");
701 fputs_filtered (TYPE_FIELD_NAME (domain
, i
), stream
);
703 fprintf_filtered (stream
, " + %d bytes", extra
);
705 fprintf_filtered (stream
, " (offset in bits)");
708 fprintf_filtered (stream
, "%d", val
>> 3);
711 /* Print data of type TYPE located at VALADDR (within GDB),
712 which came from the inferior at address ADDRESS,
713 onto stdio stream STREAM according to FORMAT
714 (a letter or 0 for natural format). The data at VALADDR
715 is in target byte order.
717 If the data are a string pointer, returns the number of
718 sting characters printed.
720 if DEREF_REF is nonzero, then dereference references,
721 otherwise just print them like pointers.
723 The PRETTY parameter controls prettyprinting. */
726 val_print (type
, valaddr
, address
, stream
, format
, deref_ref
, recurse
, pretty
)
734 enum val_prettyprint pretty
;
736 register unsigned int i
;
738 struct type
*elttype
;
743 if (pretty
== Val_pretty_default
)
745 pretty
= prettyprint
? Val_prettyprint
: Val_no_prettyprint
;
750 check_stub_type (type
);
752 if (TYPE_FLAGS (type
) & TYPE_FLAG_STUB
)
754 fprintf_filtered (stream
, "<unknown struct>");
759 switch (TYPE_CODE (type
))
761 case TYPE_CODE_ARRAY
:
762 if (TYPE_LENGTH (type
) > 0
763 && TYPE_LENGTH (TYPE_TARGET_TYPE (type
)) > 0)
765 elttype
= TYPE_TARGET_TYPE (type
);
766 eltlen
= TYPE_LENGTH (elttype
);
767 len
= TYPE_LENGTH (type
) / eltlen
;
769 print_spaces_filtered (2 + 2 * recurse
, stream
);
770 fprintf_filtered (stream
, "{");
771 /* For an array of chars, print with string syntax. */
772 if (eltlen
== 1 && TYPE_CODE (elttype
) == TYPE_CODE_INT
773 && (format
== 0 || format
== 's') )
774 print_string (stream
, valaddr
, len
, 0);
777 unsigned int things_printed
= 0;
779 /* If this is a virtual function table, print the 0th
780 entry specially, and the rest of the members normally. */
781 if (is_vtbl_ptr_type (elttype
))
783 fprintf_filtered (stream
, "%d vtable entries", len
-1);
789 for (; i
< len
&& things_printed
< print_max
; i
++)
791 /* Position of the array element we are examining to see
792 whether it is repeated. */
794 /* Number of repetitions we have detected so far. */
800 fprintf_filtered (stream
, ",\n");
801 print_spaces_filtered (2 + 2 * recurse
, stream
);
804 fprintf_filtered (stream
, ", ");
805 wrap_here (n_spaces (2 + 2 * recurse
));
810 && !bcmp (valaddr
+ i
* eltlen
,
811 valaddr
+ rep1
* eltlen
, eltlen
))
817 if (reps
> REPEAT_COUNT_THRESHOLD
)
819 val_print (elttype
, valaddr
+ i
* eltlen
,
820 0, stream
, format
, deref_ref
,
821 recurse
+ 1, pretty
);
822 fprintf_filtered (stream
, " <repeats %u times>", reps
);
824 things_printed
+= REPEAT_COUNT_THRESHOLD
;
828 val_print (elttype
, valaddr
+ i
* eltlen
,
829 0, stream
, format
, deref_ref
,
830 recurse
+ 1, pretty
);
835 fprintf_filtered (stream
, "...");
837 fprintf_filtered (stream
, "}");
840 /* Array of unspecified length: treat like pointer to first elt. */
841 valaddr
= (char *) &address
;
844 if (format
&& format
!= 's')
846 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
849 if (TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_METHOD
)
851 struct type
*domain
= TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (type
));
857 addr
= unpack_pointer (lookup_pointer_type (builtin_type_void
),
859 if (addr
< 128) /* FIXME! What is this 128? */
861 len
= TYPE_NFN_FIELDS (domain
);
862 for (i
= 0; i
< len
; i
++)
864 f
= TYPE_FN_FIELDLIST1 (domain
, i
);
865 len2
= TYPE_FN_FIELDLIST_LENGTH (domain
, i
);
867 for (j
= 0; j
< len2
; j
++)
870 if (TYPE_FN_FIELD_VOFFSET (f
, j
) == addr
)
880 struct symbol
*sym
= find_pc_function (addr
);
882 error ("invalid pointer to member function");
883 len
= TYPE_NFN_FIELDS (domain
);
884 for (i
= 0; i
< len
; i
++)
886 f
= TYPE_FN_FIELDLIST1 (domain
, i
);
887 len2
= TYPE_FN_FIELDLIST_LENGTH (domain
, i
);
889 for (j
= 0; j
< len2
; j
++)
892 if (!strcmp (SYMBOL_NAME (sym
), TYPE_FN_FIELD_PHYSNAME (f
, j
)))
900 fprintf_filtered (stream
, "&");
901 type_print_varspec_prefix (TYPE_FN_FIELD_TYPE (f
, j
), stream
, 0, 0);
902 fprintf (stream
, kind
);
903 if (TYPE_FN_FIELD_PHYSNAME (f
, j
)[0] == '_'
904 && TYPE_FN_FIELD_PHYSNAME (f
, j
)[1] == CPLUS_MARKER
)
905 type_print_method_args
906 (TYPE_FN_FIELD_ARGS (f
, j
) + 1, "~",
907 TYPE_FN_FIELDLIST_NAME (domain
, i
), 0, stream
);
909 type_print_method_args
910 (TYPE_FN_FIELD_ARGS (f
, j
), "",
911 TYPE_FN_FIELDLIST_NAME (domain
, i
), 0, stream
);
914 fprintf_filtered (stream
, "(");
915 type_print (type
, "", stream
, -1);
916 fprintf_filtered (stream
, ") %d", (int) addr
>> 3);
918 else if (TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_MEMBER
)
920 print_class_member (valaddr
,
921 TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (type
)),
926 CORE_ADDR addr
= unpack_pointer (type
, valaddr
);
927 elttype
= TYPE_TARGET_TYPE (type
);
929 if (TYPE_CODE (elttype
) == TYPE_CODE_FUNC
)
931 /* Try to print what function it points to. */
932 print_address_demangle (addr
, stream
, demangle
);
933 /* Return value is irrelevant except for string pointers. */
937 if (addressprint
&& format
!= 's')
938 fprintf_filtered (stream
, "0x%x", addr
);
940 /* For a pointer to char or unsigned char,
941 also print the string pointed to, unless pointer is null. */
942 i
= 0; /* Number of characters printed. */
943 if (TYPE_LENGTH (elttype
) == 1
944 && TYPE_CODE (elttype
) == TYPE_CODE_INT
945 && (format
== 0 || format
== 's')
947 /* If print_max is UINT_MAX, the alloca below will fail.
948 In that case don't try to print the string. */
949 && print_max
< UINT_MAX
)
951 int first_addr_err
= 0;
954 /* Get first character. */
955 errcode
= target_read_memory (addr
, (char *)&c
, 1);
958 /* First address out of bounds. */
964 char *string
= (char *) alloca (print_max
);
966 /* If the loop ends by us hitting print_max characters,
967 we need to have elipses at the end. */
968 int force_ellipses
= 1;
970 /* This loop always fetches print_max characters, even
971 though print_string might want to print more or fewer
972 (with repeated characters). This is so that
973 we don't spend forever fetching if we print
974 a long string consisting of the same character
975 repeated. Also so we can do it all in one memory
976 operation, which is faster. However, this will be
977 slower if print_max is set high, e.g. if you set
978 print_max to 1000, not only will it take a long
979 time to fetch short strings, but if you are near
980 the end of the address space, it might not work. */
982 errcode
= target_read_memory (addr
, string
, print_max
);
985 /* Try reading just one character. If that succeeds,
986 assume we hit the end of the address space, but
987 the initial part of the string is probably safe. */
989 errcode
= target_read_memory (addr
, x
, 1);
994 for (i
= 0; i
< print_max
; i
++)
995 if (string
[i
] == '\0')
1003 fputs_filtered (" ", stream
);
1004 print_string (stream
, string
, i
, force_ellipses
);
1011 fprintf_filtered (stream
,
1012 (" <Address 0x%x out of bounds>"
1018 error ("Error reading memory address 0x%x: %s.",
1019 addr
+ i
, safe_strerror (errcode
));
1025 else /* print vtbl's nicely */
1026 if (is_vtbl_member(type
))
1028 CORE_ADDR vt_address
= unpack_pointer (type
, valaddr
);
1030 struct minimal_symbol
*msymbol
=
1031 lookup_minimal_symbol_by_pc (vt_address
);
1032 if ((msymbol
!= NULL
) && (vt_address
== msymbol
-> address
))
1034 fputs_filtered (" <", stream
);
1035 fputs_demangled (msymbol
-> name
, stream
, 1);
1036 fputs_filtered (">", stream
);
1042 vt_val
= value_at (TYPE_TARGET_TYPE (type
), vt_address
);
1043 val_print (VALUE_TYPE (vt_val
), VALUE_CONTENTS (vt_val
),
1044 VALUE_ADDRESS (vt_val
), stream
, format
,
1045 deref_ref
, recurse
+ 1, pretty
);
1048 fprintf_filtered (stream
, "\n");
1049 print_spaces_filtered (2 + 2 * recurse
, stream
);
1054 /* Return number of characters printed, plus one for the
1055 terminating null if we have "reached the end". */
1056 return i
+ (print_max
&& i
!= print_max
);
1060 case TYPE_CODE_MEMBER
:
1061 error ("not implemented: member type in val_print");
1065 if (TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_MEMBER
)
1067 print_class_member (valaddr
,
1068 TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (type
)),
1074 fprintf_filtered (stream
, "@0x%lx",
1075 unpack_long (builtin_type_int
, valaddr
));
1077 fputs_filtered (": ", stream
);
1079 /* De-reference the reference. */
1082 if (TYPE_CODE (TYPE_TARGET_TYPE (type
)) != TYPE_CODE_UNDEF
)
1086 (TYPE_TARGET_TYPE (type
),
1087 unpack_pointer (lookup_pointer_type (builtin_type_void
),
1089 val_print (VALUE_TYPE (deref_val
), VALUE_CONTENTS (deref_val
),
1090 VALUE_ADDRESS (deref_val
), stream
, format
,
1091 deref_ref
, recurse
+ 1, pretty
);
1094 fputs_filtered ("???", stream
);
1098 case TYPE_CODE_UNION
:
1099 if (recurse
&& !unionprint
)
1101 fprintf_filtered (stream
, "{...}");
1105 case TYPE_CODE_STRUCT
:
1106 if (vtblprint
&& is_vtbl_ptr_type(type
))
1108 /* Print the unmangled name if desired. */
1109 print_address_demangle(*((int *) (valaddr
+ /* FIXME bytesex */
1110 TYPE_FIELD_BITPOS (type
, VTBL_FNADDR_OFFSET
) / 8)),
1114 val_print_fields (type
, valaddr
, stream
, format
, recurse
, pretty
, 0);
1117 case TYPE_CODE_ENUM
:
1120 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
1123 len
= TYPE_NFIELDS (type
);
1124 val
= unpack_long (builtin_type_int
, valaddr
);
1125 for (i
= 0; i
< len
; i
++)
1128 if (val
== TYPE_FIELD_BITPOS (type
, i
))
1132 fputs_filtered (TYPE_FIELD_NAME (type
, i
), stream
);
1135 fprintf_filtered (stream
, "%lld", val
);
1137 fprintf_filtered (stream
, "%ld", val
);
1141 case TYPE_CODE_FUNC
:
1144 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
1147 /* FIXME, we should consider, at least for ANSI C language, eliminating
1148 the distinction made between FUNCs and POINTERs to FUNCs. */
1149 fprintf_filtered (stream
, "{");
1150 type_print (type
, "", stream
, -1);
1151 fprintf_filtered (stream
, "} ");
1152 /* Try to print what function it points to, and its address. */
1153 print_address_demangle (address
, stream
, demangle
);
1157 if (format
|| output_format
)
1159 print_scalar_formatted (valaddr
, type
,
1160 format
? format
: output_format
,
1164 if (TYPE_LENGTH (type
) > sizeof (LONGEST
))
1166 if (TYPE_UNSIGNED (type
))
1168 /* First figure out whether the number in fact has zeros
1169 in all its bytes more significant than least significant
1170 sizeof (LONGEST) ones. */
1172 /* Pointer to first (i.e. lowest address) nonzero character. */
1174 len
= TYPE_LENGTH (type
);
1176 #if TARGET_BYTE_ORDER == BIG_ENDIAN
1178 len
> sizeof (LONGEST
)
1179 && p
< valaddr
+ TYPE_LENGTH (type
);
1181 #else /* Little endian. */
1182 first_addr
= valaddr
;
1183 for (p
= valaddr
+ TYPE_LENGTH (type
);
1184 len
> sizeof (LONGEST
) && p
>= valaddr
;
1186 #endif /* Little endian. */
1193 #if TARGET_BYTE_ORDER == BIG_ENDIAN
1197 if (len
<= sizeof (LONGEST
))
1199 /* We can print it in decimal. */
1202 #if defined (LONG_LONG)
1207 unpack_long (BUILTIN_TYPE_LONGEST
, first_addr
));
1211 /* It is big, so print it in hex. */
1212 print_hex_chars (stream
, (unsigned char *)first_addr
, len
);
1217 /* Signed. One could assume two's complement (a reasonable
1218 assumption, I think) and do better than this. */
1219 print_hex_chars (stream
, (unsigned char *)valaddr
,
1220 TYPE_LENGTH (type
));
1224 #ifdef PRINT_TYPELESS_INTEGER
1225 PRINT_TYPELESS_INTEGER (stream
, type
, unpack_long (type
, valaddr
));
1228 fprintf_filtered (stream
,
1229 TYPE_UNSIGNED (type
) ? "%u" : "%d",
1230 unpack_long (type
, valaddr
));
1232 fprintf_filtered (stream
,
1233 TYPE_UNSIGNED (type
) ? "%llu" : "%lld",
1234 unpack_long (type
, valaddr
));
1238 if (TYPE_LENGTH (type
) == 1)
1240 fprintf_filtered (stream
, " '");
1241 printchar ((unsigned char) unpack_long (type
, valaddr
),
1243 fprintf_filtered (stream
, "'");
1249 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
1251 print_floating (valaddr
, type
, stream
);
1254 case TYPE_CODE_VOID
:
1255 fprintf_filtered (stream
, "void");
1258 case TYPE_CODE_UNDEF
:
1259 /* This happens (without TYPE_FLAG_STUB set) on systems which don't use
1260 dbx xrefs (NO_DBX_XREFS in gcc) if a file has a "struct foo *bar"
1261 and no complete type for struct foo in that file. */
1262 fprintf_filtered (stream
, "<unknown struct>");
1265 case TYPE_CODE_ERROR
:
1266 fprintf_filtered (stream
, "?");
1269 case TYPE_CODE_RANGE
:
1270 /* FIXME, we should not ever have to print one of these yet. */
1271 fprintf_filtered (stream
, "<range type>");
1275 error ("Invalid type code in symbol table.");
1281 /* Print a description of a type in the format of a
1282 typedef for the current language.
1283 NEW is the new name for a type TYPE. */
1285 typedef_print (type
, new, stream
)
1290 switch (current_language
->la_language
)
1294 case language_cplus
:
1295 fprintf_filtered(stream
, "typedef ");
1296 type_print(type
,"",stream
,0);
1297 if(TYPE_NAME ((SYMBOL_TYPE (new))) == 0
1298 || 0 != strcmp (TYPE_NAME ((SYMBOL_TYPE (new))),
1300 fprintf_filtered(stream
, " %s", SYMBOL_NAME(new));
1305 fprintf_filtered(stream
, "TYPE ");
1306 if(!TYPE_NAME(SYMBOL_TYPE(new)) ||
1307 strcmp (TYPE_NAME(SYMBOL_TYPE(new)),
1309 fprintf_filtered(stream
, "%s = ", SYMBOL_NAME(new));
1311 fprintf_filtered(stream
, "<builtin> = ");
1312 type_print(type
,"",stream
,0);
1316 error("Language not supported.");
1318 fprintf_filtered(stream
, ";\n");
1322 /* Print a description of a type TYPE
1323 in the form of a declaration of a variable named VARSTRING.
1324 (VARSTRING is demangled if necessary.)
1325 Output goes to STREAM (via stdio).
1326 If SHOW is positive, we show the contents of the outermost level
1327 of structure even if there is a type name that could be used instead.
1328 If SHOW is negative, we never show the details of elements' types. */
1331 type_print (type
, varstring
, stream
, show
)
1337 type_print_1 (type
, varstring
, stream
, show
, 0);
1340 /* LEVEL is the depth to indent lines by. */
1343 type_print_1 (type
, varstring
, stream
, show
, level
)
1350 register enum type_code code
;
1351 type_print_base (type
, stream
, show
, level
);
1352 code
= TYPE_CODE (type
);
1353 if ((varstring
&& *varstring
)
1355 /* Need a space if going to print stars or brackets;
1356 but not if we will print just a type name. */
1357 ((show
> 0 || TYPE_NAME (type
) == 0)
1359 (code
== TYPE_CODE_PTR
|| code
== TYPE_CODE_FUNC
1360 || code
== TYPE_CODE_METHOD
1361 || code
== TYPE_CODE_ARRAY
1362 || code
== TYPE_CODE_MEMBER
1363 || code
== TYPE_CODE_REF
)))
1364 fprintf_filtered (stream
, " ");
1365 type_print_varspec_prefix (type
, stream
, show
, 0);
1366 fputs_demangled (varstring
, stream
, -1); /* Print demangled name
1367 without arguments */
1368 type_print_varspec_suffix (type
, stream
, show
, 0);
1371 /* Print the method arguments ARGS to the file STREAM. */
1373 type_print_method_args (args
, prefix
, varstring
, staticp
, stream
)
1375 char *prefix
, *varstring
;
1381 fputs_demangled (prefix
, stream
, 1);
1382 fputs_demangled (varstring
, stream
, 1);
1383 fputs_filtered (" (", stream
);
1384 if (args
&& args
[!staticp
] && args
[!staticp
]->code
!= TYPE_CODE_VOID
)
1386 i
= !staticp
; /* skip the class variable */
1389 type_print (args
[i
++], "", stream
, 0);
1392 fprintf_filtered (stream
, " ...");
1395 else if (args
[i
]->code
!= TYPE_CODE_VOID
)
1397 fprintf_filtered (stream
, ", ");
1402 fprintf_filtered (stream
, ")");
1405 /* If TYPE is a derived type, then print out derivation
1406 information. Print out all layers of the type heirarchy
1407 until we encounter one with multiple inheritance.
1408 At that point, print out that ply, and return. */
1410 type_print_derivation_info (stream
, type
)
1415 int i
, n_baseclasses
= TYPE_N_BASECLASSES (type
);
1416 struct type
*basetype
= 0;
1418 while (type
&& n_baseclasses
> 0)
1420 /* Not actually sure about this one -- Bryan. */
1421 check_stub_type (type
);
1423 fprintf_filtered (stream
, ": ");
1426 basetype
= TYPE_BASECLASS (type
, i
);
1427 if (name
= type_name_no_tag (basetype
))
1429 fprintf_filtered (stream
, "%s%s ",
1430 BASETYPE_VIA_PUBLIC(type
, i
) ? "public" : "private",
1431 BASETYPE_VIA_VIRTUAL(type
, i
) ? " virtual" : "");
1432 fputs_filtered (name
, stream
);
1435 if (i
>= n_baseclasses
)
1437 fprintf_filtered (stream
, ", ");
1440 fprintf_filtered (stream
, " ");
1441 if (n_baseclasses
!= 1)
1443 n_baseclasses
= TYPE_N_BASECLASSES (basetype
);
1448 /* Print any asterisks or open-parentheses needed before the
1449 variable name (to describe its type).
1451 On outermost call, pass 0 for PASSED_A_PTR.
1452 On outermost call, SHOW > 0 means should ignore
1453 any typename for TYPE and show its details.
1454 SHOW is always zero on recursive calls. */
1457 type_print_varspec_prefix (type
, stream
, show
, passed_a_ptr
)
1467 if (TYPE_NAME (type
) && show
<= 0)
1472 switch (TYPE_CODE (type
))
1475 type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0, 1);
1476 fprintf_filtered (stream
, "*");
1479 case TYPE_CODE_MEMBER
:
1481 fprintf_filtered (stream
, "(");
1482 type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0,
1484 fprintf_filtered (stream
, " ");
1485 name
= type_name_no_tag (TYPE_DOMAIN_TYPE (type
));
1487 fputs_filtered (name
, stream
);
1489 type_print_base (TYPE_DOMAIN_TYPE (type
), stream
, 0, passed_a_ptr
);
1490 fprintf_filtered (stream
, "::");
1493 case TYPE_CODE_METHOD
:
1495 fprintf (stream
, "(");
1496 type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0,
1500 fprintf_filtered (stream
, " ");
1501 type_print_base (TYPE_DOMAIN_TYPE (type
), stream
, 0,
1503 fprintf_filtered (stream
, "::");
1508 type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0, 1);
1509 fprintf_filtered (stream
, "&");
1512 case TYPE_CODE_FUNC
:
1513 type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0,
1516 fprintf_filtered (stream
, "(");
1519 case TYPE_CODE_ARRAY
:
1520 type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0,
1523 fprintf_filtered (stream
, "(");
1526 case TYPE_CODE_UNDEF
:
1527 case TYPE_CODE_STRUCT
:
1528 case TYPE_CODE_UNION
:
1529 case TYPE_CODE_ENUM
:
1532 case TYPE_CODE_VOID
:
1533 case TYPE_CODE_ERROR
:
1534 case TYPE_CODE_CHAR
:
1535 case TYPE_CODE_BOOL
:
1536 /* These types need no prefix. They are listed here so that
1537 gcc -Wall will reveal any types that haven't been handled. */
1542 /* Print any array sizes, function arguments or close parentheses
1543 needed after the variable name (to describe its type).
1544 Args work like type_print_varspec_prefix. */
1547 type_print_varspec_suffix (type
, stream
, show
, passed_a_ptr
)
1556 if (TYPE_NAME (type
) && show
<= 0)
1561 switch (TYPE_CODE (type
))
1563 case TYPE_CODE_ARRAY
:
1565 fprintf_filtered (stream
, ")");
1567 fprintf_filtered (stream
, "[");
1568 if (TYPE_LENGTH (type
) > 0
1569 && TYPE_LENGTH (TYPE_TARGET_TYPE (type
)) > 0)
1570 fprintf_filtered (stream
, "%d",
1572 / TYPE_LENGTH (TYPE_TARGET_TYPE (type
))));
1573 fprintf_filtered (stream
, "]");
1575 type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0,
1579 case TYPE_CODE_MEMBER
:
1581 fprintf_filtered (stream
, ")");
1582 type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0, 0);
1585 case TYPE_CODE_METHOD
:
1587 fprintf_filtered (stream
, ")");
1588 type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0, 0);
1592 struct type
**args
= TYPE_ARG_TYPES (type
);
1594 fprintf_filtered (stream
, "(");
1596 fprintf_filtered (stream
, "...");
1597 else for (i
= 1; args
[i
] != 0 && args
[i
]->code
!= TYPE_CODE_VOID
; i
++)
1599 type_print_1 (args
[i
], "", stream
, -1, 0);
1601 fprintf_filtered (stream
, "...");
1602 else if (args
[i
+1]->code
!= TYPE_CODE_VOID
) {
1603 fprintf_filtered (stream
, ",");
1607 fprintf_filtered (stream
, ")");
1613 type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0, 1);
1616 case TYPE_CODE_FUNC
:
1617 type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0,
1620 fprintf_filtered (stream
, ")");
1621 fprintf_filtered (stream
, "()");
1624 case TYPE_CODE_UNDEF
:
1625 case TYPE_CODE_STRUCT
:
1626 case TYPE_CODE_UNION
:
1627 case TYPE_CODE_ENUM
:
1630 case TYPE_CODE_VOID
:
1631 case TYPE_CODE_ERROR
:
1632 case TYPE_CODE_CHAR
:
1633 case TYPE_CODE_BOOL
:
1634 /* These types do not need a suffix. They are listed so that
1635 gcc -Wall will report types that may not have been considered. */
1640 /* Print the name of the type (or the ultimate pointer target,
1641 function value or array element), or the description of a
1644 SHOW nonzero means don't print this type as just its name;
1645 show its real definition even if it has a name.
1646 SHOW zero means print just typename or struct tag if there is one
1647 SHOW negative means abbreviate structure elements.
1648 SHOW is decremented for printing of structure elements.
1650 LEVEL is the depth to indent by.
1651 We increase it for some recursive calls. */
1654 type_print_base (type
, stream
, show
, level
)
1663 register int lastval
;
1670 fputs_filtered ("<type unknown>", stream
);
1674 /* When SHOW is zero or less, and there is a valid type name, then always
1675 just print the type name directly from the type. */
1677 if ((show
<= 0) && (TYPE_NAME (type
) != NULL
))
1679 fputs_filtered (TYPE_NAME (type
), stream
);
1683 switch (TYPE_CODE (type
))
1685 case TYPE_CODE_ARRAY
:
1687 case TYPE_CODE_MEMBER
:
1689 case TYPE_CODE_FUNC
:
1690 case TYPE_CODE_METHOD
:
1691 type_print_base (TYPE_TARGET_TYPE (type
), stream
, show
, level
);
1694 case TYPE_CODE_STRUCT
:
1695 fprintf_filtered (stream
, "struct ");
1698 case TYPE_CODE_UNION
:
1699 fprintf_filtered (stream
, "union ");
1701 if (name
= type_name_no_tag (type
))
1703 fputs_filtered (name
, stream
);
1704 fputs_filtered (" ", stream
);
1708 fprintf_filtered (stream
, "{...}");
1711 check_stub_type (type
);
1713 type_print_derivation_info (stream
, type
);
1715 fprintf_filtered (stream
, "{");
1716 len
= TYPE_NFIELDS (type
);
1718 fprintf_filtered (stream
, "\n");
1721 if (TYPE_FLAGS (type
) & TYPE_FLAG_STUB
)
1722 fprintf_filtered (stream
, "<incomplete type>\n");
1724 fprintf_filtered (stream
, "<no data fields>\n");
1727 /* If there is a base class for this type,
1728 do not print the field that it occupies. */
1729 for (i
= TYPE_N_BASECLASSES (type
); i
< len
; i
++)
1732 /* Don't print out virtual function table. */
1733 if ((TYPE_FIELD_NAME (type
, i
))[5] == CPLUS_MARKER
&&
1734 !strncmp (TYPE_FIELD_NAME (type
, i
), "_vptr", 5))
1737 print_spaces_filtered (level
+ 4, stream
);
1738 if (TYPE_FIELD_STATIC (type
, i
))
1740 fprintf_filtered (stream
, "static ");
1742 type_print_1 (TYPE_FIELD_TYPE (type
, i
),
1743 TYPE_FIELD_NAME (type
, i
),
1744 stream
, show
- 1, level
+ 4);
1745 if (!TYPE_FIELD_STATIC (type
, i
)
1746 && TYPE_FIELD_PACKED (type
, i
))
1748 /* It is a bitfield. This code does not attempt
1749 to look at the bitpos and reconstruct filler,
1750 unnamed fields. This would lead to misleading
1751 results if the compiler does not put out fields
1752 for such things (I don't know what it does). */
1753 fprintf_filtered (stream
, " : %d",
1754 TYPE_FIELD_BITSIZE (type
, i
));
1756 fprintf_filtered (stream
, ";\n");
1759 /* C++: print out the methods */
1760 len
= TYPE_NFN_FIELDS (type
);
1761 if (len
) fprintf_filtered (stream
, "\n");
1762 for (i
= 0; i
< len
; i
++)
1764 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (type
, i
);
1765 int j
, len2
= TYPE_FN_FIELDLIST_LENGTH (type
, i
);
1766 char *method_name
= TYPE_FN_FIELDLIST_NAME (type
, i
);
1767 int is_constructor
= name
&& strcmp(method_name
, name
) == 0;
1768 for (j
= 0; j
< len2
; j
++)
1771 print_spaces_filtered (level
+ 4, stream
);
1772 if (TYPE_FN_FIELD_VIRTUAL_P (f
, j
))
1773 fprintf_filtered (stream
, "virtual ");
1774 else if (TYPE_FN_FIELD_STATIC_P (f
, j
))
1775 fprintf_filtered (stream
, "static ");
1776 if (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f
, j
)) == 0)
1778 /* Keep GDB from crashing here. */
1779 fprintf (stream
, "<undefined type> %s;\n",
1780 TYPE_FN_FIELD_PHYSNAME (f
, j
));
1783 else if (!is_constructor
)
1785 type_print (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f
, j
)),
1787 fputs_filtered (" ", stream
);
1789 if (TYPE_FN_FIELD_STUB (f
, j
))
1791 /* Build something we can demangle. */
1792 char *mangled_name
= gdb_mangle_name (type
, i
, j
);
1793 char *demangled_name
= cplus_demangle (mangled_name
, 1);
1794 if (demangled_name
== 0)
1795 fprintf_filtered (stream
, "<badly mangled name %s>",
1799 fprintf_filtered (stream
, "%s",
1800 strchr (demangled_name
, ':') + 2);
1801 free (demangled_name
);
1803 free (mangled_name
);
1805 else if (TYPE_FN_FIELD_PHYSNAME (f
, j
)[0] == '_'
1806 && TYPE_FN_FIELD_PHYSNAME (f
, j
)[1] == CPLUS_MARKER
)
1807 type_print_method_args
1808 (TYPE_FN_FIELD_ARGS (f
, j
) + 1, "~",
1809 method_name
, 0, stream
);
1811 type_print_method_args
1812 (TYPE_FN_FIELD_ARGS (f
, j
), "",
1814 TYPE_FN_FIELD_STATIC_P (f
, j
), stream
);
1816 fprintf_filtered (stream
, ";\n");
1820 print_spaces_filtered (level
, stream
);
1821 fprintf_filtered (stream
, "}");
1825 case TYPE_CODE_ENUM
:
1826 fprintf_filtered (stream
, "enum ");
1827 if (name
= type_name_no_tag (type
))
1829 fputs_filtered (name
, stream
);
1830 fputs_filtered (" ", stream
);
1834 fprintf_filtered (stream
, "{...}");
1837 fprintf_filtered (stream
, "{");
1838 len
= TYPE_NFIELDS (type
);
1840 for (i
= 0; i
< len
; i
++)
1843 if (i
) fprintf_filtered (stream
, ", ");
1845 fputs_filtered (TYPE_FIELD_NAME (type
, i
), stream
);
1846 if (lastval
!= TYPE_FIELD_BITPOS (type
, i
))
1848 fprintf_filtered (stream
, " = %d", TYPE_FIELD_BITPOS (type
, i
));
1849 lastval
= TYPE_FIELD_BITPOS (type
, i
);
1853 fprintf_filtered (stream
, "}");
1857 case TYPE_CODE_VOID
:
1858 fprintf_filtered (stream
, "void");
1861 case TYPE_CODE_UNDEF
:
1862 fprintf_filtered (stream
, "struct <unknown>");
1865 case TYPE_CODE_ERROR
:
1866 fprintf_filtered (stream
, "<unknown type>");
1869 case TYPE_CODE_RANGE
:
1870 /* This should not occur */
1871 fprintf_filtered (stream
, "<range type>");
1875 /* Handle types not explicitly handled by the other cases,
1876 such as fundamental types. For these, just print whatever
1877 the type name is, as recorded in the type itself. If there
1878 is no type name, then complain. */
1879 if (TYPE_NAME (type
) != NULL
)
1881 fputs_filtered (TYPE_NAME (type
), stream
);
1885 error ("Invalid type code (%d) in symbol table.", TYPE_CODE (type
));
1892 /* Validate an input or output radix setting, and make sure the user
1893 knows what they really did here. Radix setting is confusing, e.g.
1894 setting the input radix to "10" never changes it! */
1898 set_input_radix (args
, from_tty
, c
)
1901 struct cmd_list_element
*c
;
1903 unsigned radix
= *(unsigned *)c
->var
;
1906 printf_filtered ("Input radix set to decimal %d, hex %x, octal %o\n",
1907 radix
, radix
, radix
);
1913 set_output_radix (args
, from_tty
, c
)
1916 struct cmd_list_element
*c
;
1918 unsigned radix
= *(unsigned *)c
->var
;
1921 printf_filtered ("Output radix set to decimal %d, hex %x, octal %o\n",
1922 radix
, radix
, radix
);
1924 /* FIXME, we really should be able to validate the setting BEFORE
1929 output_format
= 'x';
1935 output_format
= 'o'; /* octal */
1939 error ("Unsupported radix ``decimal %d''; using decimal output",
1946 set_radix (arg
, from_tty
, c
)
1949 struct cmd_list_element
*c
;
1951 unsigned radix
= *(unsigned *)c
->var
;
1954 printf_filtered ("Radix set to decimal %d, hex %x, octal %o\n",
1955 radix
, radix
, radix
);
1957 input_radix
= radix
;
1958 output_radix
= radix
;
1960 set_output_radix (arg
, 0, c
);
1963 struct cmd_list_element
*setprintlist
= NULL
;
1964 struct cmd_list_element
*showprintlist
= NULL
;
1968 set_print (arg
, from_tty
)
1973 "\"set print\" must be followed by the name of a print subcommand.\n");
1974 help_list (setprintlist
, "set print ", -1, stdout
);
1979 show_print (args
, from_tty
)
1983 cmd_show_list (showprintlist
, from_tty
, "");
1987 _initialize_valprint ()
1989 struct cmd_list_element
*c
;
1991 add_prefix_cmd ("print", no_class
, set_print
,
1992 "Generic command for setting how things print.",
1993 &setprintlist
, "set print ", 0, &setlist
);
1994 add_alias_cmd ("p", "print", no_class
, 1, &setlist
);
1995 add_alias_cmd ("pr", "print", no_class
, 1, &setlist
); /* prefer set print
1997 add_prefix_cmd ("print", no_class
, show_print
,
1998 "Generic command for showing print settings.",
1999 &showprintlist
, "show print ", 0, &showlist
);
2000 add_alias_cmd ("p", "print", no_class
, 1, &showlist
);
2001 add_alias_cmd ("pr", "print", no_class
, 1, &showlist
);
2004 (add_set_cmd ("elements", no_class
, var_uinteger
, (char *)&print_max
,
2005 "Set limit on string chars or array elements to print.\n\
2006 \"set print elements 0\" causes there to be no limit.",
2011 (add_set_cmd ("pretty", class_support
, var_boolean
, (char *)&prettyprint
,
2012 "Set prettyprinting of structures.",
2017 (add_set_cmd ("union", class_support
, var_boolean
, (char *)&unionprint
,
2018 "Set printing of unions interior to structures.",
2023 (add_set_cmd ("vtbl", class_support
, var_boolean
, (char *)&vtblprint
,
2024 "Set printing of C++ virtual function tables.",
2029 (add_set_cmd ("array", class_support
, var_boolean
, (char *)&arrayprint
,
2030 "Set prettyprinting of arrays.",
2035 (add_set_cmd ("object", class_support
, var_boolean
, (char *)&objectprint
,
2036 "Set printing of object's derived type based on vtable info.",
2041 (add_set_cmd ("address", class_support
, var_boolean
, (char *)&addressprint
,
2042 "Set printing of addresses.",
2047 /* The "show radix" cmd isn't good enough to show two separate values.
2048 The rest of the code works, but the show part is confusing, so don't
2049 let them be set separately 'til we work out "show". */
2050 c
= add_set_cmd ("input-radix", class_support
, var_uinteger
,
2051 (char *)&input_radix
,
2052 "Set default input radix for entering numbers.",
2054 add_show_from_set (c
, &showlist
);
2055 c
->function
= set_input_radix
;
2057 c
= add_set_cmd ("output-radix", class_support
, var_uinteger
,
2058 (char *)&output_radix
,
2059 "Set default output radix for printing of values.",
2061 add_show_from_set (c
, &showlist
);
2062 c
->function
= set_output_radix
;
2065 c
= add_set_cmd ("radix", class_support
, var_uinteger
,
2066 (char *)&output_radix
,
2067 "Set default input and output number radix.",
2069 add_show_from_set (c
, &showlist
);
2070 c
->function
.sfunc
= set_radix
;
2072 /* Give people the defaults which they are used to. */
2082 obstack_begin (&dont_print_obstack
, 32 * sizeof (struct type
*));