1 /* Print values for GNU debugger gdb.
2 Copyright (C) 1986, 1988, 1989 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 extern char *sys_errlist
[];
35 extern void print_scalar_formatted(); /* printcmd.c */
36 extern void print_address_demangle(); /* printcmd.c */
37 extern int demangle
; /* whether to print C++ syms raw or source-form */
39 /* Maximum number of chars to print for a string pointer value
40 or vector contents, or UINT_MAX for no limit. */
42 static unsigned int print_max
;
44 static void type_print_varspec_suffix ();
45 static void type_print_varspec_prefix ();
46 static void type_print_base ();
47 static void type_print_method_args ();
49 /* Default input and output radixes, and output format letter. */
51 unsigned input_radix
= 10;
52 unsigned output_radix
= 10;
53 int output_format
= 0;
56 char **unsigned_type_table
;
57 char **signed_type_table
;
58 char **float_type_table
;
61 /* Print repeat counts if there are more than this
62 many repetitions of an element in an array. */
63 #define REPEAT_COUNT_THRESHOLD 10
65 /* Define a mess of print controls. */
67 int prettyprint
; /* Controls pretty printing of structures */
68 int vtblprint
; /* Controls printing of vtbl's */
69 int unionprint
; /* Controls printing of nested unions. */
70 int arrayprint
; /* Controls pretty printing of arrays. */
71 int addressprint
; /* Controls pretty printing of addresses. */
72 int objectprint
; /* Controls looking up an object's derived type
73 using what we find in its vtables. */
75 struct obstack dont_print_obstack
;
77 static void cplus_val_print ();
79 /* Print the character string STRING, printing at most LENGTH characters.
80 Printing stops early if the number hits print_max; repeat counts
81 are printed as appropriate. Print ellipses at the end if we
82 had to stop before printing LENGTH characters, or if FORCE_ELLIPSES. */
85 print_string (stream
, string
, length
, force_ellipses
)
91 register unsigned int i
;
92 unsigned int things_printed
= 0;
95 extern int inspect_it
;
99 fputs_filtered ("\"\"", stdout
);
103 for (i
= 0; i
< length
&& things_printed
< print_max
; ++i
)
105 /* Position of the character we are examining
106 to see whether it is repeated. */
108 /* Number of repetitions we have detected so far. */
115 fputs_filtered (", ", stream
);
121 while (rep1
< length
&& string
[rep1
] == string
[i
])
127 if (reps
> REPEAT_COUNT_THRESHOLD
)
132 fputs_filtered ("\\\", ", stream
);
134 fputs_filtered ("\", ", stream
);
137 fputs_filtered ("'", stream
);
138 printchar (string
[i
], stream
, '\'');
139 fprintf_filtered (stream
, "' <repeats %u times>", reps
);
141 things_printed
+= REPEAT_COUNT_THRESHOLD
;
149 fputs_filtered ("\\\"", stream
);
151 fputs_filtered ("\"", stream
);
154 printchar (string
[i
], stream
, '"');
159 /* Terminate the quotes if necessary. */
163 fputs_filtered ("\\\"", stream
);
165 fputs_filtered ("\"", stream
);
168 if (force_ellipses
|| i
< length
)
169 fputs_filtered ("...", stream
);
172 /* Print a floating point value of type TYPE, pointed to in GDB by VALADDR,
176 print_floating (valaddr
, type
, stream
)
183 unsigned len
= TYPE_LENGTH (type
);
185 #if defined (IEEE_FLOAT)
187 /* Check for NaN's. Note that this code does not depend on us being
188 on an IEEE conforming system. It only depends on the target
189 machine using IEEE representation. This means (a)
190 cross-debugging works right, and (2) IEEE_FLOAT can (and should)
191 be defined for systems like the 68881, which uses IEEE
192 representation, but is not IEEE conforming. */
196 /* Is the sign bit 0? */
198 /* Is it is a NaN (i.e. the exponent is all ones and
199 the fraction is nonzero)? */
202 if (len
== sizeof (float))
204 /* It's single precision. */
205 bcopy (valaddr
, &low
, sizeof (low
));
206 /* target -> host. */
207 SWAP_TARGET_AND_HOST (&low
, sizeof (float));
208 nonnegative
= low
>= 0;
209 is_nan
= ((((low
>> 23) & 0xFF) == 0xFF)
210 && 0 != (low
& 0x7FFFFF));
216 /* It's double precision. Get the high and low words. */
218 #if TARGET_BYTE_ORDER == BIG_ENDIAN
219 bcopy (valaddr
+4, &low
, sizeof (low
));
220 bcopy (valaddr
+0, &high
, sizeof (high
));
222 bcopy (valaddr
+0, &low
, sizeof (low
));
223 bcopy (valaddr
+4, &high
, sizeof (high
));
225 SWAP_TARGET_AND_HOST (&low
, sizeof (low
));
226 SWAP_TARGET_AND_HOST (&high
, sizeof (high
));
227 nonnegative
= high
>= 0;
228 is_nan
= (((high
>> 20) & 0x7ff) == 0x7ff
229 && ! ((((high
& 0xfffff) == 0)) && (low
== 0)));
235 /* The meaning of the sign and fraction is not defined by IEEE.
236 But the user might know what they mean. For example, they
237 (in an implementation-defined manner) distinguish between
238 signaling and quiet NaN's. */
240 fprintf_filtered (stream
, "-NaN(0x%lx%.8lx)" + nonnegative
,
243 fprintf_filtered (stream
, "-NaN(0x%lx)" + nonnegative
, low
);
247 #endif /* IEEE_FLOAT. */
249 doub
= unpack_double (type
, valaddr
, &inv
);
251 fprintf_filtered (stream
, "<invalid float value>");
253 fprintf_filtered (stream
, len
<= sizeof(float) ? "%.6g" : "%.17g", doub
);
256 /* VALADDR points to an integer of LEN bytes. Print it in hex on stream. */
258 print_hex_chars (stream
, valaddr
, len
)
260 unsigned char *valaddr
;
265 fprintf_filtered (stream
, "0x");
266 #if TARGET_BYTE_ORDER == BIG_ENDIAN
270 #else /* Little endian. */
271 for (p
= valaddr
+ len
- 1;
276 fprintf_filtered (stream
, "%02x", *p
);
280 /* Print the value VAL in C-ish syntax on stream STREAM.
281 FORMAT is a format-letter, or 0 for print in natural format of data type.
282 If the object printed is a string pointer, returns
283 the number of string bytes printed. */
286 value_print (val
, stream
, format
, pretty
)
290 enum val_prettyprint pretty
;
292 register unsigned int i
, n
, typelen
;
296 printf_filtered ("<address of value unknown>");
299 if (VALUE_OPTIMIZED_OUT (val
))
301 printf_filtered ("<value optimized out>");
305 /* A "repeated" value really contains several values in a row.
306 They are made by the @ operator.
307 Print such values as if they were arrays. */
309 else if (VALUE_REPEATED (val
))
311 n
= VALUE_REPETITIONS (val
);
312 typelen
= TYPE_LENGTH (VALUE_TYPE (val
));
313 fprintf_filtered (stream
, "{");
314 /* Print arrays of characters using string syntax. */
315 if (typelen
== 1 && TYPE_CODE (VALUE_TYPE (val
)) == TYPE_CODE_INT
317 print_string (stream
, VALUE_CONTENTS (val
), n
, 0);
320 unsigned int things_printed
= 0;
322 for (i
= 0; i
< n
&& things_printed
< print_max
; i
++)
324 /* Position of the array element we are examining to see
325 whether it is repeated. */
327 /* Number of repetitions we have detected so far. */
331 fprintf_filtered (stream
, ", ");
337 && !bcmp (VALUE_CONTENTS (val
) + typelen
* i
,
338 VALUE_CONTENTS (val
) + typelen
* rep1
, typelen
))
344 if (reps
> REPEAT_COUNT_THRESHOLD
)
346 val_print (VALUE_TYPE (val
),
347 VALUE_CONTENTS (val
) + typelen
* i
,
348 VALUE_ADDRESS (val
) + typelen
* i
,
349 stream
, format
, 1, 0, pretty
);
350 fprintf (stream
, " <repeats %u times>", reps
);
352 things_printed
+= REPEAT_COUNT_THRESHOLD
;
356 val_print (VALUE_TYPE (val
),
357 VALUE_CONTENTS (val
) + typelen
* i
,
358 VALUE_ADDRESS (val
) + typelen
* i
,
359 stream
, format
, 1, 0, pretty
);
364 fprintf_filtered (stream
, "...");
366 fprintf_filtered (stream
, "}");
371 struct type
*type
= VALUE_TYPE (val
);
373 /* If it is a pointer, indicate what it points to.
375 Print type also if it is a reference.
377 C++: if it is a member pointer, we will take care
378 of that when we print it. */
379 if (TYPE_CODE (type
) == TYPE_CODE_PTR
380 || TYPE_CODE (type
) == TYPE_CODE_REF
)
382 /* Hack: remove (char *) for char strings. Their
383 type is indicated by the quoted string anyway. */
384 if (TYPE_CODE (type
) == TYPE_CODE_PTR
385 && TYPE_LENGTH (TYPE_TARGET_TYPE (type
)) == sizeof(char)
386 && TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_INT
387 && !TYPE_UNSIGNED (TYPE_TARGET_TYPE (type
)))
393 fprintf_filtered (stream
, "(");
394 type_print (type
, "", stream
, -1);
395 fprintf_filtered (stream
, ") ");
398 return val_print (type
, VALUE_CONTENTS (val
),
399 VALUE_ADDRESS (val
), stream
, format
, 1, 0, pretty
);
403 /* Return truth value for assertion that TYPE is of the type
404 "pointer to virtual function". */
406 is_vtbl_ptr_type(type
)
409 char *typename
= TYPE_NAME(type
);
410 static const char vtbl_ptr_name
[] =
411 { CPLUS_MARKER
,'v','t','b','l','_','p','t','r','_','t','y','p','e' };
413 return (typename
!= NULL
&& !strcmp(typename
, vtbl_ptr_name
));
416 /* Return truth value for the assertion that TYPE is of the type
417 "pointer to virtual function table". */
422 if (TYPE_CODE (type
) == TYPE_CODE_PTR
)
423 type
= TYPE_TARGET_TYPE (type
);
427 if (TYPE_CODE (type
) == TYPE_CODE_ARRAY
428 && TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_STRUCT
)
429 /* Virtual functions tables are full of pointers to virtual functions. */
430 return is_vtbl_ptr_type (TYPE_TARGET_TYPE (type
));
434 /* Mutually recursive subroutines of cplus_val_print and val_print to print out
435 a structure's fields: val_print_fields and cplus_val_print.
437 TYPE, VALADDR, STREAM, RECURSE, and PRETTY have the
438 same meanings as in cplus_val_print and val_print.
440 DONT_PRINT is an array of baseclass types that we
441 should not print, or zero if called from top level. */
443 val_print_fields (type
, valaddr
, stream
, format
, recurse
, pretty
, dont_print
)
449 enum val_prettyprint pretty
;
450 struct type
**dont_print
;
452 int i
, len
, n_baseclasses
;
454 fprintf_filtered (stream
, "{");
455 len
= TYPE_NFIELDS (type
);
456 n_baseclasses
= TYPE_N_BASECLASSES (type
);
458 /* Print out baseclasses such that we don't print
459 duplicates of virtual baseclasses. */
460 if (n_baseclasses
> 0)
461 cplus_val_print (type
, valaddr
, stream
, format
, recurse
+1, pretty
, dont_print
);
463 if (!len
&& n_baseclasses
== 1)
464 fprintf_filtered (stream
, "<No data fields>");
467 extern int inspect_it
;
470 for (i
= n_baseclasses
; i
< len
; i
++)
472 /* Check if static field */
473 if (TYPE_FIELD_STATIC (type
, i
))
476 fprintf_filtered (stream
, ", ");
477 else if (n_baseclasses
> 0)
479 fprintf_filtered (stream
, "\n");
480 print_spaces_filtered (2 + 2 * recurse
, stream
);
481 fputs_filtered ("members of ", stream
);
482 fputs_filtered (type_name_no_tag (type
), stream
);
483 fputs_filtered (": ", stream
);
489 fprintf_filtered (stream
, "\n");
490 print_spaces_filtered (2 + 2 * recurse
, stream
);
494 wrap_here (n_spaces (2 + 2 * recurse
));
498 if (TYPE_CODE (TYPE_FIELD_TYPE (type
, i
)) == TYPE_CODE_PTR
)
499 fputs_filtered ("\"( ptr \"", stream
);
501 fputs_filtered ("\"( nodef \"", stream
);
502 fputs_filtered (TYPE_FIELD_NAME (type
, i
), stream
);
503 fputs_filtered ("\" \"", stream
);
504 fputs_filtered (TYPE_FIELD_NAME (type
, i
), stream
);
505 fputs_filtered ("\") \"", stream
);
509 fputs_filtered (TYPE_FIELD_NAME (type
, i
), stream
);
510 fputs_filtered (" = ", stream
);
512 if (TYPE_FIELD_PACKED (type
, i
))
516 /* Bitfields require special handling, especially due to byte
518 v
= value_from_long (TYPE_FIELD_TYPE (type
, i
),
519 unpack_field_as_long (type
, valaddr
, i
));
521 val_print (TYPE_FIELD_TYPE (type
, i
), VALUE_CONTENTS (v
), 0,
522 stream
, format
, 0, recurse
+ 1, pretty
);
526 val_print (TYPE_FIELD_TYPE (type
, i
),
527 valaddr
+ TYPE_FIELD_BITPOS (type
, i
) / 8,
528 0, stream
, format
, 0, recurse
+ 1, pretty
);
533 fprintf_filtered (stream
, "\n");
534 print_spaces_filtered (2 * recurse
, stream
);
537 fprintf_filtered (stream
, "}");
540 /* Special val_print routine to avoid printing multiple copies of virtual
544 cplus_val_print (type
, valaddr
, stream
, format
, recurse
, pretty
, dont_print
)
550 enum val_prettyprint pretty
;
551 struct type
**dont_print
;
553 struct obstack tmp_obstack
;
554 struct type
**last_dont_print
555 = (struct type
**)obstack_next_free (&dont_print_obstack
);
556 int i
, n_baseclasses
= TYPE_N_BASECLASSES (type
);
560 /* If we're at top level, carve out a completely fresh
561 chunk of the obstack and use that until this particular
562 invocation returns. */
563 tmp_obstack
= dont_print_obstack
;
564 /* Bump up the high-water mark. Now alpha is omega. */
565 obstack_finish (&dont_print_obstack
);
568 for (i
= 0; i
< n_baseclasses
; i
++)
573 if (BASETYPE_VIA_VIRTUAL (type
, i
))
575 struct type
**first_dont_print
576 = (struct type
**)obstack_base (&dont_print_obstack
);
578 int j
= (struct type
**)obstack_next_free (&dont_print_obstack
)
582 if (TYPE_BASECLASS (type
, i
) == first_dont_print
[j
])
585 obstack_ptr_grow (&dont_print_obstack
, TYPE_BASECLASS (type
, i
));
588 baddr
= baseclass_addr (type
, i
, valaddr
, 0, &err
);
589 if (err
== 0 && baddr
== 0)
590 error ("could not find virtual baseclass `%s'\n",
591 type_name_no_tag (TYPE_BASECLASS (type
, i
)));
593 fprintf_filtered (stream
, "\n");
595 print_spaces_filtered (2 + 2 * recurse
, stream
);
596 fputs_filtered ("<", stream
);
597 fputs_filtered (type_name_no_tag (TYPE_BASECLASS (type
, i
)), stream
);
598 fputs_filtered ("> = ", stream
);
600 fprintf_filtered (stream
, "<invalid address 0x%x>", baddr
);
602 val_print_fields (TYPE_BASECLASS (type
, i
), baddr
, stream
, format
,
604 (struct type
**)obstack_base (&dont_print_obstack
));
611 /* Free the space used to deal with the printing
612 of this type from top level. */
613 obstack_free (&dont_print_obstack
, last_dont_print
);
614 /* Reset watermark so that we can continue protecting
615 ourselves from whatever we were protecting ourselves. */
616 dont_print_obstack
= tmp_obstack
;
620 /* Print data of type TYPE located at VALADDR (within GDB),
621 which came from the inferior at address ADDRESS,
622 onto stdio stream STREAM according to FORMAT
623 (a letter or 0 for natural format). The data at VALADDR
624 is in target byte order.
626 If the data are a string pointer, returns the number of
627 sting characters printed.
629 if DEREF_REF is nonzero, then dereference references,
630 otherwise just print them like pointers.
632 The PRETTY parameter controls prettyprinting. */
635 val_print (type
, valaddr
, address
, stream
, format
,
636 deref_ref
, recurse
, pretty
)
644 enum val_prettyprint pretty
;
646 register unsigned int i
;
648 struct type
*elttype
;
653 if (pretty
== Val_pretty_default
)
655 pretty
= prettyprint
? Val_prettyprint
: Val_no_prettyprint
;
660 check_stub_type (type
);
662 if (TYPE_FLAGS (type
) & TYPE_FLAG_STUB
)
664 fprintf_filtered (stream
, "<unknown struct>");
669 switch (TYPE_CODE (type
))
671 case TYPE_CODE_ARRAY
:
672 /* FIXME: TYPE_LENGTH (type) is unsigned and therefore always
673 0. Is "> 0" meant? I'm not sure what an "array of
674 unspecified length" (mentioned in the comment for the else-part
676 if (TYPE_LENGTH (type
) >= 0
677 && TYPE_LENGTH (TYPE_TARGET_TYPE (type
)) > 0)
679 elttype
= TYPE_TARGET_TYPE (type
);
680 eltlen
= TYPE_LENGTH (elttype
);
681 len
= TYPE_LENGTH (type
) / eltlen
;
683 print_spaces_filtered (2 + 2 * recurse
, stream
);
684 fprintf_filtered (stream
, "{");
685 /* For an array of chars, print with string syntax. */
686 if (eltlen
== 1 && TYPE_CODE (elttype
) == TYPE_CODE_INT
687 && (format
== 0 || format
== 's') )
688 print_string (stream
, valaddr
, len
, 0);
691 unsigned int things_printed
= 0;
693 /* If this is a virtual function table, print the 0th
694 entry specially, and the rest of the members normally. */
695 if (is_vtbl_ptr_type (elttype
))
697 fprintf_filtered (stream
, "%d vtable entries", len
-1);
703 for (; i
< len
&& things_printed
< print_max
; i
++)
705 /* Position of the array element we are examining to see
706 whether it is repeated. */
708 /* Number of repetitions we have detected so far. */
714 fprintf_filtered (stream
, ",\n");
715 print_spaces_filtered (2 + 2 * recurse
, stream
);
718 fprintf_filtered (stream
, ", ");
719 wrap_here (n_spaces (2 + 2 * recurse
));
724 && !bcmp (valaddr
+ i
* eltlen
,
725 valaddr
+ rep1
* eltlen
, eltlen
))
731 if (reps
> REPEAT_COUNT_THRESHOLD
)
733 val_print (elttype
, valaddr
+ i
* eltlen
,
734 0, stream
, format
, deref_ref
,
735 recurse
+ 1, pretty
);
736 fprintf_filtered (stream
, " <repeats %u times>", reps
);
738 things_printed
+= REPEAT_COUNT_THRESHOLD
;
742 val_print (elttype
, valaddr
+ i
* eltlen
,
743 0, stream
, format
, deref_ref
,
744 recurse
+ 1, pretty
);
749 fprintf_filtered (stream
, "...");
751 fprintf_filtered (stream
, "}");
754 /* Array of unspecified length: treat like pointer to first elt. */
755 valaddr
= (char *) &address
;
758 if (format
&& format
!= 's')
760 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
763 if (TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_METHOD
)
765 struct type
*domain
= TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (type
));
771 addr
= unpack_pointer (lookup_pointer_type (builtin_type_void
),
775 len
= TYPE_NFN_FIELDS (domain
);
776 for (i
= 0; i
< len
; i
++)
778 f
= TYPE_FN_FIELDLIST1 (domain
, i
);
779 len2
= TYPE_FN_FIELDLIST_LENGTH (domain
, i
);
781 for (j
= 0; j
< len2
; j
++)
784 if (TYPE_FN_FIELD_VOFFSET (f
, j
) == addr
)
794 struct symbol
*sym
= find_pc_function (addr
);
796 error ("invalid pointer to member function");
797 len
= TYPE_NFN_FIELDS (domain
);
798 for (i
= 0; i
< len
; i
++)
800 f
= TYPE_FN_FIELDLIST1 (domain
, i
);
801 len2
= TYPE_FN_FIELDLIST_LENGTH (domain
, i
);
803 for (j
= 0; j
< len2
; j
++)
806 if (!strcmp (SYMBOL_NAME (sym
), TYPE_FN_FIELD_PHYSNAME (f
, j
)))
814 fprintf_filtered (stream
, "&");
815 type_print_varspec_prefix (TYPE_FN_FIELD_TYPE (f
, j
), stream
, 0, 0);
816 fprintf (stream
, kind
);
817 if (TYPE_FN_FIELD_PHYSNAME (f
, j
)[0] == '_'
818 && TYPE_FN_FIELD_PHYSNAME (f
, j
)[1] == CPLUS_MARKER
)
819 type_print_method_args
820 (TYPE_FN_FIELD_ARGS (f
, j
) + 1, "~",
821 TYPE_FN_FIELDLIST_NAME (domain
, i
), 0, stream
);
823 type_print_method_args
824 (TYPE_FN_FIELD_ARGS (f
, j
), "",
825 TYPE_FN_FIELDLIST_NAME (domain
, i
), 0, stream
);
828 fprintf_filtered (stream
, "(");
829 type_print (type
, "", stream
, -1);
830 fprintf_filtered (stream
, ") %d", (int) addr
>> 3);
832 else if (TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_MEMBER
)
834 struct type
*domain
= TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (type
));
836 /* VAL is a byte offset into the structure type DOMAIN.
837 Find the name of the field for that offset and
841 len
= TYPE_NFIELDS (domain
);
842 /* @@ Make VAL into bit offset */
843 val
= unpack_long (builtin_type_int
, valaddr
) << 3;
844 for (i
= TYPE_N_BASECLASSES (domain
); i
< len
; i
++)
846 int bitpos
= TYPE_FIELD_BITPOS (domain
, i
);
850 if (val
< bitpos
&& i
!= 0)
852 /* Somehow pointing into a field. */
854 extra
= (val
- TYPE_FIELD_BITPOS (domain
, i
));
864 fprintf_filtered (stream
, "&");
865 type_print_base (domain
, stream
, 0, 0);
866 fprintf_filtered (stream
, "::");
867 fputs_filtered (TYPE_FIELD_NAME (domain
, i
), stream
);
869 fprintf_filtered (stream
, " + %d bytes", extra
);
871 fprintf_filtered (stream
, " (offset in bits)");
874 fprintf_filtered (stream
, "%d", val
>> 3);
878 CORE_ADDR addr
= unpack_pointer (type
, valaddr
);
879 elttype
= TYPE_TARGET_TYPE (type
);
881 if (TYPE_CODE (elttype
) == TYPE_CODE_FUNC
)
883 /* Try to print what function it points to. */
884 print_address_demangle (addr
, stream
, demangle
);
885 /* Return value is irrelevant except for string pointers. */
889 if (addressprint
&& format
!= 's')
890 fprintf_filtered (stream
, "0x%x", addr
);
892 /* For a pointer to char or unsigned char,
893 also print the string pointed to, unless pointer is null. */
894 i
= 0; /* Number of characters printed. */
895 if (TYPE_LENGTH (elttype
) == 1
896 && TYPE_CODE (elttype
) == TYPE_CODE_INT
897 && (format
== 0 || format
== 's')
899 /* If print_max is UINT_MAX, the alloca below will fail.
900 In that case don't try to print the string. */
901 && print_max
< UINT_MAX
)
903 int first_addr_err
= 0;
906 /* Get first character. */
907 errcode
= target_read_memory (addr
, (char *)&c
, 1);
910 /* First address out of bounds. */
916 char *string
= (char *) alloca (print_max
);
918 /* If the loop ends by us hitting print_max characters,
919 we need to have elipses at the end. */
920 int force_ellipses
= 1;
922 /* This loop always fetches print_max characters, even
923 though print_string might want to print more or fewer
924 (with repeated characters). This is so that
925 we don't spend forever fetching if we print
926 a long string consisting of the same character
927 repeated. Also so we can do it all in one memory
928 operation, which is faster. However, this will be
929 slower if print_max is set high, e.g. if you set
930 print_max to 1000, not only will it take a long
931 time to fetch short strings, but if you are near
932 the end of the address space, it might not work.
935 errcode
= target_read_memory (addr
, string
, print_max
);
939 for (i
= 0; i
< print_max
; i
++)
940 if (string
[i
] == '\0')
948 fputs_filtered (" ", stream
);
949 print_string (stream
, string
, i
, force_ellipses
);
956 fprintf_filtered (stream
,
957 (" <Address 0x%x out of bounds>"
963 if (errcode
>= sys_nerr
|| errcode
< 0)
964 error ("Error reading memory address 0x%x: unknown error (%d).",
967 error ("Error reading memory address 0x%x: %s.",
968 addr
+ i
, sys_errlist
[errcode
]);
974 else /* print vtbl's nicely */
975 if (is_vtbl_member(type
))
977 CORE_ADDR vt_address
= unpack_pointer (type
, valaddr
);
979 int vt_index
= find_pc_misc_function (vt_address
);
981 && vt_address
== misc_function_vector
[vt_index
].address
)
983 fputs_filtered (" <", stream
);
984 fputs_demangled (misc_function_vector
[vt_index
].name
,
986 fputs_filtered (">", stream
);
992 vt_val
= value_at (TYPE_TARGET_TYPE (type
), vt_address
);
993 val_print (VALUE_TYPE (vt_val
), VALUE_CONTENTS (vt_val
),
994 VALUE_ADDRESS (vt_val
), stream
, format
,
995 deref_ref
, recurse
+ 1, pretty
);
998 fprintf_filtered (stream
, "\n");
999 print_spaces_filtered (2 + 2 * recurse
, stream
);
1004 /* Return number of characters printed, plus one for the
1005 terminating null if we have "reached the end". */
1006 return i
+ (print_max
&& i
!= print_max
);
1010 case TYPE_CODE_MEMBER
:
1011 error ("not implemented: member type in val_print");
1017 fprintf_filtered (stream
, "@0x%lx",
1018 unpack_long (builtin_type_int
, valaddr
));
1020 fputs_filtered (": ", stream
);
1022 /* De-reference the reference. */
1025 if (TYPE_CODE (TYPE_TARGET_TYPE (type
)) != TYPE_CODE_UNDEF
)
1029 (TYPE_TARGET_TYPE (type
),
1030 unpack_pointer (lookup_pointer_type (builtin_type_void
),
1032 val_print (VALUE_TYPE (deref_val
), VALUE_CONTENTS (deref_val
),
1033 VALUE_ADDRESS (deref_val
), stream
, format
,
1034 deref_ref
, recurse
+ 1, pretty
);
1037 fputs_filtered ("???", stream
);
1041 case TYPE_CODE_UNION
:
1042 if (recurse
&& !unionprint
)
1044 fprintf_filtered (stream
, "{...}");
1048 case TYPE_CODE_STRUCT
:
1049 if (vtblprint
&& is_vtbl_ptr_type(type
))
1051 /* Print the unmangled name if desired. */
1052 print_address_demangle(*((int *) (valaddr
+ /* FIXME bytesex */
1053 TYPE_FIELD_BITPOS (type
, VTBL_FNADDR_OFFSET
) / 8)),
1057 val_print_fields (type
, valaddr
, stream
, format
, recurse
, pretty
, 0);
1060 case TYPE_CODE_ENUM
:
1063 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
1066 len
= TYPE_NFIELDS (type
);
1067 val
= unpack_long (builtin_type_int
, valaddr
);
1068 for (i
= 0; i
< len
; i
++)
1071 if (val
== TYPE_FIELD_BITPOS (type
, i
))
1075 fputs_filtered (TYPE_FIELD_NAME (type
, i
), stream
);
1078 fprintf_filtered (stream
, "%lld", val
);
1080 fprintf_filtered (stream
, "%ld", val
);
1084 case TYPE_CODE_FUNC
:
1087 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
1090 /* FIXME, we should consider, at least for ANSI C language, eliminating
1091 the distinction made between FUNCs and POINTERs to FUNCs. */
1092 fprintf_filtered (stream
, "{");
1093 type_print (type
, "", stream
, -1);
1094 fprintf_filtered (stream
, "} ");
1095 /* Try to print what function it points to, and its address. */
1096 print_address_demangle (address
, stream
, demangle
);
1100 if (format
|| output_format
)
1102 print_scalar_formatted (valaddr
, type
,
1103 format
? format
: output_format
,
1107 if (TYPE_LENGTH (type
) > sizeof (LONGEST
))
1109 if (TYPE_UNSIGNED (type
))
1111 /* First figure out whether the number in fact has zeros
1112 in all its bytes more significant than least significant
1113 sizeof (LONGEST) ones. */
1115 /* Pointer to first (i.e. lowest address) nonzero character. */
1117 len
= TYPE_LENGTH (type
);
1119 #if TARGET_BYTE_ORDER == BIG_ENDIAN
1121 len
> sizeof (LONGEST
)
1122 && p
< valaddr
+ TYPE_LENGTH (type
);
1124 #else /* Little endian. */
1125 first_addr
= valaddr
;
1126 for (p
= valaddr
+ TYPE_LENGTH (type
);
1127 len
> sizeof (LONGEST
) && p
>= valaddr
;
1129 #endif /* Little endian. */
1136 #if TARGET_BYTE_ORDER == BIG_ENDIAN
1140 if (len
<= sizeof (LONGEST
))
1142 /* We can print it in decimal. */
1145 #if defined (LONG_LONG)
1150 unpack_long (BUILTIN_TYPE_LONGEST
, first_addr
));
1154 /* It is big, so print it in hex. */
1155 print_hex_chars (stream
, (unsigned char *)first_addr
, len
);
1160 /* Signed. One could assume two's complement (a reasonable
1161 assumption, I think) and do better than this. */
1162 print_hex_chars (stream
, (unsigned char *)valaddr
,
1163 TYPE_LENGTH (type
));
1167 #ifdef PRINT_TYPELESS_INTEGER
1168 PRINT_TYPELESS_INTEGER (stream
, type
, unpack_long (type
, valaddr
));
1171 fprintf_filtered (stream
,
1172 TYPE_UNSIGNED (type
) ? "%u" : "%d",
1173 unpack_long (type
, valaddr
));
1175 fprintf_filtered (stream
,
1176 TYPE_UNSIGNED (type
) ? "%llu" : "%lld",
1177 unpack_long (type
, valaddr
));
1181 if (TYPE_LENGTH (type
) == 1)
1183 fprintf_filtered (stream
, " '");
1184 printchar ((unsigned char) unpack_long (type
, valaddr
),
1186 fprintf_filtered (stream
, "'");
1192 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
1194 print_floating (valaddr
, type
, stream
);
1197 case TYPE_CODE_VOID
:
1198 fprintf_filtered (stream
, "void");
1201 case TYPE_CODE_UNDEF
:
1202 /* This happens (without TYPE_FLAG_STUB set) on systems which don't use
1203 dbx xrefs (NO_DBX_XREFS in gcc) if a file has a "struct foo *bar"
1204 and no complete type for struct foo in that file. */
1205 fprintf_filtered (stream
, "<unknown struct>");
1208 case TYPE_CODE_ERROR
:
1209 fprintf_filtered (stream
, "?");
1213 error ("Invalid type code in symbol table.");
1219 /* Print a description of a type TYPE
1220 in the form of a declaration of a variable named VARSTRING.
1221 (VARSTRING is demangled if necessary.)
1222 Output goes to STREAM (via stdio).
1223 If SHOW is positive, we show the contents of the outermost level
1224 of structure even if there is a type name that could be used instead.
1225 If SHOW is negative, we never show the details of elements' types. */
1228 type_print (type
, varstring
, stream
, show
)
1234 type_print_1 (type
, varstring
, stream
, show
, 0);
1237 /* LEVEL is the depth to indent lines by. */
1240 type_print_1 (type
, varstring
, stream
, show
, level
)
1247 register enum type_code code
;
1248 type_print_base (type
, stream
, show
, level
);
1249 code
= TYPE_CODE (type
);
1250 if ((varstring
&& *varstring
)
1252 /* Need a space if going to print stars or brackets;
1253 but not if we will print just a type name. */
1254 ((show
> 0 || TYPE_NAME (type
) == 0)
1256 (code
== TYPE_CODE_PTR
|| code
== TYPE_CODE_FUNC
1257 || code
== TYPE_CODE_METHOD
1258 || code
== TYPE_CODE_ARRAY
1259 || code
== TYPE_CODE_MEMBER
1260 || code
== TYPE_CODE_REF
)))
1261 fprintf_filtered (stream
, " ");
1262 type_print_varspec_prefix (type
, stream
, show
, 0);
1263 fputs_demangled (varstring
, stream
, -1); /* Print demangled name
1264 without arguments */
1265 type_print_varspec_suffix (type
, stream
, show
, 0);
1268 /* Print the method arguments ARGS to the file STREAM. */
1270 type_print_method_args (args
, prefix
, varstring
, staticp
, stream
)
1272 char *prefix
, *varstring
;
1278 fputs_filtered (" ", stream
);
1279 fputs_demangled (prefix
, stream
, 1);
1280 fputs_demangled (varstring
, stream
, 1);
1281 fputs_filtered (" (", stream
);
1282 if (args
&& args
[!staticp
] && args
[!staticp
]->code
!= TYPE_CODE_VOID
)
1284 i
= !staticp
; /* skip the class variable */
1287 type_print (args
[i
++], "", stream
, 0);
1290 fprintf_filtered (stream
, " ...");
1293 else if (args
[i
]->code
!= TYPE_CODE_VOID
)
1295 fprintf_filtered (stream
, ", ");
1300 fprintf_filtered (stream
, ")");
1303 /* If TYPE is a derived type, then print out derivation
1304 information. Print out all layers of the type heirarchy
1305 until we encounter one with multiple inheritance.
1306 At that point, print out that ply, and return. */
1308 type_print_derivation_info (stream
, type
)
1313 int i
, n_baseclasses
= TYPE_N_BASECLASSES (type
);
1314 struct type
*basetype
= 0;
1316 while (type
&& n_baseclasses
> 0)
1318 /* Not actually sure about this one -- Bryan. */
1319 check_stub_type (type
);
1321 fprintf_filtered (stream
, ": ");
1324 basetype
= TYPE_BASECLASS (type
, i
);
1325 if (name
= type_name_no_tag (basetype
))
1327 fprintf_filtered (stream
, "%s%s ",
1328 BASETYPE_VIA_PUBLIC(type
, i
) ? "public" : "private",
1329 BASETYPE_VIA_VIRTUAL(type
, i
) ? " virtual" : "");
1330 fputs_filtered (name
, stream
);
1333 if (i
>= n_baseclasses
)
1335 fprintf_filtered (stream
, ", ");
1338 fprintf_filtered (stream
, " ");
1339 if (n_baseclasses
!= 1)
1341 n_baseclasses
= TYPE_N_BASECLASSES (basetype
);
1346 /* Print any asterisks or open-parentheses needed before the
1347 variable name (to describe its type).
1349 On outermost call, pass 0 for PASSED_A_PTR.
1350 On outermost call, SHOW > 0 means should ignore
1351 any typename for TYPE and show its details.
1352 SHOW is always zero on recursive calls. */
1355 type_print_varspec_prefix (type
, stream
, show
, passed_a_ptr
)
1364 if (TYPE_NAME (type
) && show
<= 0)
1369 switch (TYPE_CODE (type
))
1372 type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0, 1);
1373 fprintf_filtered (stream
, "*");
1376 case TYPE_CODE_MEMBER
:
1378 fprintf_filtered (stream
, "(");
1379 type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0,
1381 fprintf_filtered (stream
, " ");
1382 type_print_base (TYPE_DOMAIN_TYPE (type
), stream
, 0,
1384 fprintf_filtered (stream
, "::");
1387 case TYPE_CODE_METHOD
:
1389 fprintf (stream
, "(");
1390 type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0,
1394 fprintf_filtered (stream
, " ");
1395 type_print_base (TYPE_DOMAIN_TYPE (type
), stream
, 0,
1397 fprintf_filtered (stream
, "::");
1402 type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0, 1);
1403 fprintf_filtered (stream
, "&");
1406 case TYPE_CODE_FUNC
:
1407 type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0,
1410 fprintf_filtered (stream
, "(");
1413 case TYPE_CODE_ARRAY
:
1414 type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0,
1417 fprintf_filtered (stream
, "(");
1419 case TYPE_CODE_UNDEF
:
1420 case TYPE_CODE_STRUCT
:
1421 case TYPE_CODE_UNION
:
1422 case TYPE_CODE_ENUM
:
1425 case TYPE_CODE_VOID
:
1426 case TYPE_CODE_ERROR
:
1427 /* These types need no prefix. They are listed here so that
1428 gcc -Wall will reveal any types that haven't been handled. */
1433 /* Print any array sizes, function arguments or close parentheses
1434 needed after the variable name (to describe its type).
1435 Args work like type_print_varspec_prefix. */
1438 type_print_varspec_suffix (type
, stream
, show
, passed_a_ptr
)
1447 if (TYPE_NAME (type
) && show
<= 0)
1452 switch (TYPE_CODE (type
))
1454 case TYPE_CODE_ARRAY
:
1456 fprintf_filtered (stream
, ")");
1458 fprintf_filtered (stream
, "[");
1459 if (/* always true */ /* TYPE_LENGTH (type) >= 0
1460 && */ TYPE_LENGTH (TYPE_TARGET_TYPE (type
)) > 0)
1461 fprintf_filtered (stream
, "%d",
1463 / TYPE_LENGTH (TYPE_TARGET_TYPE (type
))));
1464 fprintf_filtered (stream
, "]");
1466 type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0,
1470 case TYPE_CODE_MEMBER
:
1472 fprintf_filtered (stream
, ")");
1473 type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0, 0);
1476 case TYPE_CODE_METHOD
:
1478 fprintf_filtered (stream
, ")");
1479 type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0, 0);
1483 struct type
**args
= TYPE_ARG_TYPES (type
);
1485 fprintf_filtered (stream
, "(");
1487 fprintf_filtered (stream
, "...");
1488 else for (i
= 1; args
[i
] != 0 && args
[i
]->code
!= TYPE_CODE_VOID
; i
++)
1490 type_print_1 (args
[i
], "", stream
, -1, 0);
1492 fprintf_filtered (stream
, "...");
1493 else if (args
[i
+1]->code
!= TYPE_CODE_VOID
) {
1494 fprintf_filtered (stream
, ",");
1498 fprintf_filtered (stream
, ")");
1504 type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0, 1);
1507 case TYPE_CODE_FUNC
:
1508 type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0,
1511 fprintf_filtered (stream
, ")");
1512 fprintf_filtered (stream
, "()");
1515 case TYPE_CODE_UNDEF
:
1516 case TYPE_CODE_STRUCT
:
1517 case TYPE_CODE_UNION
:
1518 case TYPE_CODE_ENUM
:
1521 case TYPE_CODE_VOID
:
1522 case TYPE_CODE_ERROR
:
1523 /* These types do not need a suffix. They are listed so that
1524 gcc -Wall will report types that may not have been considered. */
1529 /* Print the name of the type (or the ultimate pointer target,
1530 function value or array element), or the description of a
1533 SHOW nonzero means don't print this type as just its name;
1534 show its real definition even if it has a name.
1535 SHOW zero means print just typename or struct tag if there is one
1536 SHOW negative means abbreviate structure elements.
1537 SHOW is decremented for printing of structure elements.
1539 LEVEL is the depth to indent by.
1540 We increase it for some recursive calls. */
1543 type_print_base (type
, stream
, show
, level
)
1552 register int lastval
;
1559 fprintf_filtered (stream
, "type unknown");
1563 if (TYPE_NAME (type
) && show
<= 0)
1565 fputs_filtered (TYPE_NAME (type
), stream
);
1569 switch (TYPE_CODE (type
))
1571 case TYPE_CODE_ARRAY
:
1573 case TYPE_CODE_MEMBER
:
1575 case TYPE_CODE_FUNC
:
1576 case TYPE_CODE_METHOD
:
1577 type_print_base (TYPE_TARGET_TYPE (type
), stream
, show
, level
);
1580 case TYPE_CODE_STRUCT
:
1581 fprintf_filtered (stream
, "struct ");
1584 case TYPE_CODE_UNION
:
1585 fprintf_filtered (stream
, "union ");
1587 if (name
= type_name_no_tag (type
))
1589 fputs_filtered (name
, stream
);
1590 fputs_filtered (" ", stream
);
1594 fprintf_filtered (stream
, "{...}");
1597 check_stub_type (type
);
1599 type_print_derivation_info (stream
, type
);
1601 fprintf_filtered (stream
, "{");
1602 len
= TYPE_NFIELDS (type
);
1604 fprintf_filtered (stream
, "\n");
1607 if (TYPE_FLAGS (type
) & TYPE_FLAG_STUB
)
1608 fprintf_filtered (stream
, "<incomplete type>\n");
1610 fprintf_filtered (stream
, "<no data fields>\n");
1613 /* If there is a base class for this type,
1614 do not print the field that it occupies. */
1615 for (i
= TYPE_N_BASECLASSES (type
); i
< len
; i
++)
1618 /* Don't print out virtual function table. */
1619 if ((TYPE_FIELD_NAME (type
, i
))[5] == CPLUS_MARKER
&&
1620 !strncmp (TYPE_FIELD_NAME (type
, i
), "_vptr", 5))
1623 print_spaces_filtered (level
+ 4, stream
);
1624 if (TYPE_FIELD_STATIC (type
, i
))
1626 fprintf_filtered (stream
, "static ");
1628 type_print_1 (TYPE_FIELD_TYPE (type
, i
),
1629 TYPE_FIELD_NAME (type
, i
),
1630 stream
, show
- 1, level
+ 4);
1631 if (!TYPE_FIELD_STATIC (type
, i
)
1632 && TYPE_FIELD_PACKED (type
, i
))
1634 /* It is a bitfield. This code does not attempt
1635 to look at the bitpos and reconstruct filler,
1636 unnamed fields. This would lead to misleading
1637 results if the compiler does not put out fields
1638 for such things (I don't know what it does). */
1639 fprintf_filtered (stream
, " : %d",
1640 TYPE_FIELD_BITSIZE (type
, i
));
1642 fprintf_filtered (stream
, ";\n");
1645 /* C++: print out the methods */
1646 len
= TYPE_NFN_FIELDS (type
);
1647 if (len
) fprintf_filtered (stream
, "\n");
1648 for (i
= 0; i
< len
; i
++)
1650 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (type
, i
);
1651 int j
, len2
= TYPE_FN_FIELDLIST_LENGTH (type
, i
);
1653 for (j
= 0; j
< len2
; j
++)
1656 print_spaces_filtered (level
+ 4, stream
);
1657 if (TYPE_FN_FIELD_VIRTUAL_P (f
, j
))
1658 fprintf_filtered (stream
, "virtual ");
1659 else if (TYPE_FN_FIELD_STATIC_P (f
, j
))
1660 fprintf_filtered (stream
, "static ");
1661 if (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f
, j
)) == 0)
1663 /* Keep GDB from crashing here. */
1664 fprintf (stream
, "<undefined type> %s;\n",
1665 TYPE_FN_FIELD_PHYSNAME (f
, j
));
1669 type_print (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f
, j
)), "", stream
, 0);
1670 if (TYPE_FLAGS (TYPE_FN_FIELD_TYPE (f
, j
)) & TYPE_FLAG_STUB
)
1672 /* Build something we can demangle. */
1673 char *strchr (), *gdb_mangle_typename ();
1674 char *inner_name
= gdb_mangle_typename (type
);
1676 = (char *)xmalloc (strlen (TYPE_FN_FIELDLIST_NAME (type
, i
))
1677 + strlen (inner_name
)
1678 + strlen (TYPE_FN_FIELD_PHYSNAME (f
, j
))
1680 char *demangled_name
, *cplus_demangle ();
1681 strcpy (mangled_name
, TYPE_FN_FIELDLIST_NAME (type
, i
));
1682 strcat (mangled_name
, inner_name
);
1683 strcat (mangled_name
, TYPE_FN_FIELD_PHYSNAME (f
, j
));
1684 demangled_name
= cplus_demangle (mangled_name
, 1);
1685 if (demangled_name
== 0)
1686 fprintf_filtered (stream
, " <badly mangled name %s>",
1690 fprintf_filtered (stream
, " %s",
1691 strchr (demangled_name
, ':') + 2);
1692 free (demangled_name
);
1694 free (mangled_name
);
1696 else if (TYPE_FN_FIELD_PHYSNAME (f
, j
)[0] == '_'
1697 && TYPE_FN_FIELD_PHYSNAME (f
, j
)[1] == CPLUS_MARKER
)
1698 type_print_method_args
1699 (TYPE_FN_FIELD_ARGS (f
, j
) + 1, "~",
1700 TYPE_FN_FIELDLIST_NAME (type
, i
), 0, stream
);
1702 type_print_method_args
1703 (TYPE_FN_FIELD_ARGS (f
, j
), "",
1704 TYPE_FN_FIELDLIST_NAME (type
, i
),
1705 TYPE_FN_FIELD_STATIC_P (f
, j
), stream
);
1707 fprintf_filtered (stream
, ";\n");
1711 print_spaces_filtered (level
, stream
);
1712 fprintf_filtered (stream
, "}");
1716 case TYPE_CODE_ENUM
:
1717 fprintf_filtered (stream
, "enum ");
1718 if (name
= type_name_no_tag (type
))
1720 fputs_filtered (name
, stream
);
1721 fputs_filtered (" ", stream
);
1725 fprintf_filtered (stream
, "{...}");
1728 fprintf_filtered (stream
, "{");
1729 len
= TYPE_NFIELDS (type
);
1731 for (i
= 0; i
< len
; i
++)
1734 if (i
) fprintf_filtered (stream
, ", ");
1736 fputs_filtered (TYPE_FIELD_NAME (type
, i
), stream
);
1737 if (lastval
!= TYPE_FIELD_BITPOS (type
, i
))
1739 fprintf_filtered (stream
, " = %d", TYPE_FIELD_BITPOS (type
, i
));
1740 lastval
= TYPE_FIELD_BITPOS (type
, i
);
1744 fprintf_filtered (stream
, "}");
1749 if (TYPE_LENGTH (type
) > sizeof (LONGEST
))
1751 fprintf_filtered (stream
, "<%d bit integer>",
1752 TYPE_LENGTH (type
) * TARGET_CHAR_BIT
);
1756 if (TYPE_UNSIGNED (type
))
1757 name
= unsigned_type_table
[TYPE_LENGTH (type
)];
1759 name
= signed_type_table
[TYPE_LENGTH (type
)];
1761 fputs_filtered (name
, stream
);
1765 name
= float_type_table
[TYPE_LENGTH (type
)];
1766 fputs_filtered (name
, stream
);
1769 case TYPE_CODE_VOID
:
1770 fprintf_filtered (stream
, "void");
1774 fprintf_filtered (stream
, "struct unknown");
1777 case TYPE_CODE_ERROR
:
1778 fprintf_filtered (stream
, "<unknown type>");
1782 error ("Invalid type code in symbol table.");
1787 /* Validate an input or output radix setting, and make sure the user
1788 knows what they really did here. Radix setting is confusing, e.g.
1789 setting the input radix to "10" never changes it! */
1793 set_input_radix (args
, from_tty
, c
)
1796 struct cmd_list_element
*c
;
1798 unsigned radix
= *(unsigned *)c
->var
;
1801 printf_filtered ("Input radix set to decimal %d, hex %x, octal %o\n",
1802 radix
, radix
, radix
);
1808 set_output_radix (args
, from_tty
, c
)
1811 struct cmd_list_element
*c
;
1813 unsigned radix
= *(unsigned *)c
->var
;
1816 printf_filtered ("Output radix set to decimal %d, hex %x, octal %o\n",
1817 radix
, radix
, radix
);
1819 /* FIXME, we really should be able to validate the setting BEFORE
1824 output_format
= 'x';
1830 output_format
= 'o'; /* octal */
1834 error ("Unsupported radix ``decimal %d''; using decimal output",
1841 set_radix (arg
, from_tty
, c
)
1844 struct cmd_list_element
*c
;
1846 unsigned radix
= *(unsigned *)c
->var
;
1849 printf_filtered ("Radix set to decimal %d, hex %x, octal %o\n",
1850 radix
, radix
, radix
);
1852 input_radix
= radix
;
1853 output_radix
= radix
;
1855 set_output_radix (arg
, 0, c
);
1858 struct cmd_list_element
*setprintlist
= NULL
;
1859 struct cmd_list_element
*showprintlist
= NULL
;
1863 set_print (arg
, from_tty
)
1868 "\"set print\" must be followed by the name of a print subcommand.\n");
1869 help_list (setprintlist
, "set print ", -1, stdout
);
1874 show_print (args
, from_tty
)
1878 cmd_show_list (showprintlist
, from_tty
, "");
1882 _initialize_valprint ()
1884 struct cmd_list_element
*c
;
1886 add_prefix_cmd ("print", no_class
, set_print
,
1887 "Generic command for setting how things print.",
1888 &setprintlist
, "set print ", 0, &setlist
);
1889 add_alias_cmd ("p", "print", no_class
, 1, &setlist
);
1890 add_alias_cmd ("pr", "print", no_class
, 1, &setlist
); /* prefer set print
1892 add_prefix_cmd ("print", no_class
, show_print
,
1893 "Generic command for showing print settings.",
1894 &showprintlist
, "show print ", 0, &showlist
);
1895 add_alias_cmd ("p", "print", no_class
, 1, &showlist
);
1896 add_alias_cmd ("pr", "print", no_class
, 1, &showlist
);
1899 (add_set_cmd ("elements", no_class
, var_uinteger
, (char *)&print_max
,
1900 "Set limit on string chars or array elements to print.\n\
1901 \"set print elements 0\" causes there to be no limit.",
1906 (add_set_cmd ("pretty", class_support
, var_boolean
, (char *)&prettyprint
,
1907 "Set prettyprinting of structures.",
1912 (add_set_cmd ("union", class_support
, var_boolean
, (char *)&unionprint
,
1913 "Set printing of unions interior to structures.",
1918 (add_set_cmd ("vtbl", class_support
, var_boolean
, (char *)&vtblprint
,
1919 "Set printing of C++ virtual function tables.",
1924 (add_set_cmd ("array", class_support
, var_boolean
, (char *)&arrayprint
,
1925 "Set prettyprinting of arrays.",
1930 (add_set_cmd ("object", class_support
, var_boolean
, (char *)&objectprint
,
1931 "Set printing of object's derived type based on vtable info.",
1936 (add_set_cmd ("address", class_support
, var_boolean
, (char *)&addressprint
,
1937 "Set printing of addresses.",
1942 /* The "show radix" cmd isn't good enough to show two separate values.
1943 The rest of the code works, but the show part is confusing, so don't
1944 let them be set separately 'til we work out "show". */
1945 c
= add_set_cmd ("input-radix", class_support
, var_uinteger
,
1946 (char *)&input_radix
,
1947 "Set default input radix for entering numbers.",
1949 add_show_from_set (c
, &showlist
);
1950 c
->function
= set_input_radix
;
1952 c
= add_set_cmd ("output-radix", class_support
, var_uinteger
,
1953 (char *)&output_radix
,
1954 "Set default output radix for printing of values.",
1956 add_show_from_set (c
, &showlist
);
1957 c
->function
= set_output_radix
;
1960 c
= add_set_cmd ("radix", class_support
, var_uinteger
,
1961 (char *)&output_radix
,
1962 "Set default input and output number radix.",
1964 add_show_from_set (c
, &showlist
);
1965 c
->function
= set_radix
;
1967 /* Give people the defaults which they are used to. */
1978 = (char **) xmalloc ((1 + sizeof (unsigned LONGEST
)) * sizeof (char *));
1979 bzero (unsigned_type_table
, (1 + sizeof (unsigned LONGEST
)));
1980 unsigned_type_table
[sizeof (unsigned char)] = "unsigned char";
1981 unsigned_type_table
[sizeof (unsigned short)] = "unsigned short";
1982 unsigned_type_table
[sizeof (unsigned long)] = "unsigned long";
1983 unsigned_type_table
[sizeof (unsigned int)] = "unsigned int";
1985 unsigned_type_table
[sizeof (unsigned long long)] = "unsigned long long";
1989 = (char **) xmalloc ((1 + sizeof (LONGEST
)) * sizeof (char *));
1990 bzero (signed_type_table
, (1 + sizeof (LONGEST
)));
1991 signed_type_table
[sizeof (char)] = "char";
1992 signed_type_table
[sizeof (short)] = "short";
1993 signed_type_table
[sizeof (long)] = "long";
1994 signed_type_table
[sizeof (int)] = "int";
1996 signed_type_table
[sizeof (long long)] = "long long";
2000 = (char **) xmalloc ((1 + sizeof (double)) * sizeof (char *));
2001 bzero (float_type_table
, (1 + sizeof (double)));
2002 float_type_table
[sizeof (float)] = "float";
2003 float_type_table
[sizeof (double)] = "double";
2004 obstack_begin (&dont_print_obstack
, 32 * sizeof (struct type
*));