1 /* Print values for GDB, the GNU debugger.
2 Copyright 1986, 1988, 1989, 1991 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
34 /* Prototypes for local functions */
37 print_string PARAMS ((FILE *, char *, unsigned int, int));
40 show_print PARAMS ((char *, int));
43 set_print PARAMS ((char *, int));
46 set_radix PARAMS ((char *, int, struct cmd_list_element *));
49 set_output_radix PARAMS ((char *, int, struct cmd_list_element *));
52 type_print_base PARAMS ((struct type *, FILE *, int, int));
55 type_print_varspec_suffix PARAMS ((struct type *, FILE *, int, int, int));
58 type_print_varspec_prefix PARAMS ((struct type *, FILE *, int, int));
61 type_print_derivation_info PARAMS ((FILE *, struct type *));
64 type_print_method_args PARAMS ((struct type **, char *, char *, int, FILE *));
67 cplus_val_print PARAMS ((struct type *, char *, FILE *, int, int,
68 enum val_prettyprint, struct type **));
71 val_print_fields PARAMS ((struct type *, char *, FILE *, int, int,
72 enum val_prettyprint, struct type **));
75 is_vtbl_member PARAMS ((struct type *));
78 is_vtbl_ptr_type PARAMS ((struct type *));
81 print_hex_chars PARAMS ((FILE *, unsigned char *, unsigned));
83 extern int demangle; /* whether to print C++ syms raw or source-form */
85 /* Maximum number of chars to print for a string pointer value
86 or vector contents, or UINT_MAX for no limit. */
88 static unsigned int print_max;
90 /* Default input and output radixes, and output format letter. */
92 unsigned input_radix = 10;
93 unsigned output_radix = 10;
94 int output_format = 0;
96 /* Print repeat counts if there are more than this
97 many repetitions of an element in an array. */
98 #define REPEAT_COUNT_THRESHOLD 10
100 /* Define a mess of print controls. */
102 int prettyprint; /* Controls pretty printing of structures */
103 int vtblprint; /* Controls printing of vtbl's */
104 int unionprint; /* Controls printing of nested unions. */
105 int arrayprint; /* Controls pretty printing of arrays. */
106 int addressprint; /* Controls pretty printing of addresses. */
107 int objectprint; /* Controls looking up an object's derived type
108 using what we find in its vtables. */
110 struct obstack dont_print_obstack;
113 /* Print the character string STRING, printing at most LENGTH characters.
114 Printing stops early if the number hits print_max; repeat counts
115 are printed as appropriate. Print ellipses at the end if we
116 had to stop before printing LENGTH characters, or if FORCE_ELLIPSES. */
119 print_string (stream, string, length, force_ellipses)
125 register unsigned int i;
126 unsigned int things_printed = 0;
129 extern int inspect_it;
133 fputs_filtered ("\"\"", stdout);
137 for (i = 0; i < length && things_printed < print_max; ++i)
139 /* Position of the character we are examining
140 to see whether it is repeated. */
142 /* Number of repetitions we have detected so far. */
149 fputs_filtered (", ", stream);
155 while (rep1 < length && string[rep1] == string[i])
161 if (reps > REPEAT_COUNT_THRESHOLD)
166 fputs_filtered ("\\\", ", stream);
168 fputs_filtered ("\", ", stream);
171 fputs_filtered ("'", stream);
172 printchar (string[i], stream, '\'');
173 fprintf_filtered (stream, "' <repeats %u times>", reps);
175 things_printed += REPEAT_COUNT_THRESHOLD;
183 fputs_filtered ("\\\"", stream);
185 fputs_filtered ("\"", stream);
188 printchar (string[i], stream, '"');
193 /* Terminate the quotes if necessary. */
197 fputs_filtered ("\\\"", stream);
199 fputs_filtered ("\"", stream);
202 if (force_ellipses || i < length)
203 fputs_filtered ("...", stream);
206 /* Print a floating point value of type TYPE, pointed to in GDB by VALADDR,
210 print_floating (valaddr, type, stream)
217 unsigned len = TYPE_LENGTH (type);
219 #if defined (IEEE_FLOAT)
221 /* Check for NaN's. Note that this code does not depend on us being
222 on an IEEE conforming system. It only depends on the target
223 machine using IEEE representation. This means (a)
224 cross-debugging works right, and (2) IEEE_FLOAT can (and should)
225 be defined for systems like the 68881, which uses IEEE
226 representation, but is not IEEE conforming. */
230 /* Is the sign bit 0? */
232 /* Is it is a NaN (i.e. the exponent is all ones and
233 the fraction is nonzero)? */
236 if (len == sizeof (float))
238 /* It's single precision. */
239 bcopy (valaddr, &low, sizeof (low));
240 /* target -> host. */
241 SWAP_TARGET_AND_HOST (&low, sizeof (float));
242 nonnegative = low >= 0;
243 is_nan = ((((low >> 23) & 0xFF) == 0xFF)
244 && 0 != (low & 0x7FFFFF));
250 /* It's double precision. Get the high and low words. */
252 #if TARGET_BYTE_ORDER == BIG_ENDIAN
253 bcopy (valaddr+4, &low, sizeof (low));
254 bcopy (valaddr+0, &high, sizeof (high));
256 bcopy (valaddr+0, &low, sizeof (low));
257 bcopy (valaddr+4, &high, sizeof (high));
259 SWAP_TARGET_AND_HOST (&low, sizeof (low));
260 SWAP_TARGET_AND_HOST (&high, sizeof (high));
261 nonnegative = high >= 0;
262 is_nan = (((high >> 20) & 0x7ff) == 0x7ff
263 && ! ((((high & 0xfffff) == 0)) && (low == 0)));
269 /* The meaning of the sign and fraction is not defined by IEEE.
270 But the user might know what they mean. For example, they
271 (in an implementation-defined manner) distinguish between
272 signaling and quiet NaN's. */
274 fprintf_filtered (stream, "-NaN(0x%lx%.8lx)" + nonnegative,
277 fprintf_filtered (stream, "-NaN(0x%lx)" + nonnegative, low);
281 #endif /* IEEE_FLOAT. */
283 doub = unpack_double (type, valaddr, &inv);
285 fprintf_filtered (stream, "<invalid float value>");
287 fprintf_filtered (stream, len <= sizeof(float) ? "%.9g" : "%.17g", doub);
290 /* VALADDR points to an integer of LEN bytes. Print it in hex on stream. */
292 print_hex_chars (stream, valaddr, len)
294 unsigned char *valaddr;
299 fprintf_filtered (stream, "0x");
300 #if TARGET_BYTE_ORDER == BIG_ENDIAN
304 #else /* Little endian. */
305 for (p = valaddr + len - 1;
310 fprintf_filtered (stream, "%02x", *p);
314 /* Print the value VAL in C-ish syntax on stream STREAM.
315 FORMAT is a format-letter, or 0 for print in natural format of data type.
316 If the object printed is a string pointer, returns
317 the number of string bytes printed. */
320 value_print (val, stream, format, pretty)
324 enum val_prettyprint pretty;
326 register unsigned int i, n, typelen;
330 printf_filtered ("<address of value unknown>");
333 if (VALUE_OPTIMIZED_OUT (val))
335 printf_filtered ("<value optimized out>");
339 /* A "repeated" value really contains several values in a row.
340 They are made by the @ operator.
341 Print such values as if they were arrays. */
343 else if (VALUE_REPEATED (val))
345 n = VALUE_REPETITIONS (val);
346 typelen = TYPE_LENGTH (VALUE_TYPE (val));
347 fprintf_filtered (stream, "{");
348 /* Print arrays of characters using string syntax. */
349 if (typelen == 1 && TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_INT
351 print_string (stream, VALUE_CONTENTS (val), n, 0);
354 unsigned int things_printed = 0;
356 for (i = 0; i < n && things_printed < print_max; i++)
358 /* Position of the array element we are examining to see
359 whether it is repeated. */
361 /* Number of repetitions we have detected so far. */
365 fprintf_filtered (stream, ", ");
371 && !bcmp (VALUE_CONTENTS (val) + typelen * i,
372 VALUE_CONTENTS (val) + typelen * rep1, typelen))
378 if (reps > REPEAT_COUNT_THRESHOLD)
380 val_print (VALUE_TYPE (val),
381 VALUE_CONTENTS (val) + typelen * i,
382 VALUE_ADDRESS (val) + typelen * i,
383 stream, format, 1, 0, pretty);
384 fprintf (stream, " <repeats %u times>", reps);
386 things_printed += REPEAT_COUNT_THRESHOLD;
390 val_print (VALUE_TYPE (val),
391 VALUE_CONTENTS (val) + typelen * i,
392 VALUE_ADDRESS (val) + typelen * i,
393 stream, format, 1, 0, pretty);
398 fprintf_filtered (stream, "...");
400 fprintf_filtered (stream, "}");
405 struct type *type = VALUE_TYPE (val);
407 /* If it is a pointer, indicate what it points to.
409 Print type also if it is a reference.
411 C++: if it is a member pointer, we will take care
412 of that when we print it. */
413 if (TYPE_CODE (type) == TYPE_CODE_PTR
414 || TYPE_CODE (type) == TYPE_CODE_REF)
416 /* Hack: remove (char *) for char strings. Their
417 type is indicated by the quoted string anyway. */
418 if (TYPE_CODE (type) == TYPE_CODE_PTR
419 && TYPE_LENGTH (TYPE_TARGET_TYPE (type)) == sizeof(char)
420 && TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_INT
421 && !TYPE_UNSIGNED (TYPE_TARGET_TYPE (type)))
427 fprintf_filtered (stream, "(");
428 type_print (type, "", stream, -1);
429 fprintf_filtered (stream, ") ");
432 return val_print (type, VALUE_CONTENTS (val),
433 VALUE_ADDRESS (val), stream, format, 1, 0, pretty);
437 /* Return truth value for assertion that TYPE is of the type
438 "pointer to virtual function". */
440 is_vtbl_ptr_type(type)
443 char *typename = type_name_no_tag (type);
444 static const char vtbl_ptr_name[] =
445 { CPLUS_MARKER,'v','t','b','l','_','p','t','r','_','t','y','p','e', 0 };
447 return (typename != NULL && !strcmp(typename, vtbl_ptr_name));
450 /* Return truth value for the assertion that TYPE is of the type
451 "pointer to virtual function table". */
456 if (TYPE_CODE (type) == TYPE_CODE_PTR)
457 type = TYPE_TARGET_TYPE (type);
461 if (TYPE_CODE (type) == TYPE_CODE_ARRAY
462 && TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_STRUCT)
463 /* Virtual functions tables are full of pointers to virtual functions. */
464 return is_vtbl_ptr_type (TYPE_TARGET_TYPE (type));
468 /* Mutually recursive subroutines of cplus_val_print and val_print to print out
469 a structure's fields: val_print_fields and cplus_val_print.
471 TYPE, VALADDR, STREAM, RECURSE, and PRETTY have the
472 same meanings as in cplus_val_print and val_print.
474 DONT_PRINT is an array of baseclass types that we
475 should not print, or zero if called from top level. */
478 val_print_fields (type, valaddr, stream, format, recurse, pretty, dont_print)
484 enum val_prettyprint pretty;
485 struct type **dont_print;
487 int i, len, n_baseclasses;
489 check_stub_type (type);
491 fprintf_filtered (stream, "{");
492 len = TYPE_NFIELDS (type);
493 n_baseclasses = TYPE_N_BASECLASSES (type);
495 /* Print out baseclasses such that we don't print
496 duplicates of virtual baseclasses. */
497 if (n_baseclasses > 0)
498 cplus_val_print (type, valaddr, stream, format, recurse+1, pretty, dont_print);
500 if (!len && n_baseclasses == 1)
501 fprintf_filtered (stream, "<No data fields>");
504 extern int inspect_it;
507 for (i = n_baseclasses; i < len; i++)
509 /* Check if static field */
510 if (TYPE_FIELD_STATIC (type, i))
513 fprintf_filtered (stream, ", ");
514 else if (n_baseclasses > 0)
518 fprintf_filtered (stream, "\n");
519 print_spaces_filtered (2 + 2 * recurse, stream);
520 fputs_filtered ("members of ", stream);
521 fputs_filtered (type_name_no_tag (type), stream);
522 fputs_filtered (": ", stream);
529 fprintf_filtered (stream, "\n");
530 print_spaces_filtered (2 + 2 * recurse, stream);
534 wrap_here (n_spaces (2 + 2 * recurse));
538 if (TYPE_CODE (TYPE_FIELD_TYPE (type, i)) == TYPE_CODE_PTR)
539 fputs_filtered ("\"( ptr \"", stream);
541 fputs_filtered ("\"( nodef \"", stream);
542 fprint_symbol (stream, TYPE_FIELD_NAME (type, i));
543 fputs_filtered ("\" \"", stream);
544 fprint_symbol (stream, TYPE_FIELD_NAME (type, i));
545 fputs_filtered ("\") \"", stream);
549 fprint_symbol (stream, TYPE_FIELD_NAME (type, i));
550 fputs_filtered (" = ", stream);
552 if (TYPE_FIELD_PACKED (type, i))
556 /* Bitfields require special handling, especially due to byte
558 v = value_from_longest (TYPE_FIELD_TYPE (type, i),
559 unpack_field_as_long (type, valaddr, i));
561 val_print (TYPE_FIELD_TYPE (type, i), VALUE_CONTENTS (v), 0,
562 stream, format, 0, recurse + 1, pretty);
566 val_print (TYPE_FIELD_TYPE (type, i),
567 valaddr + TYPE_FIELD_BITPOS (type, i) / 8,
568 0, stream, format, 0, recurse + 1, pretty);
573 fprintf_filtered (stream, "\n");
574 print_spaces_filtered (2 * recurse, stream);
577 fprintf_filtered (stream, "}");
580 /* Special val_print routine to avoid printing multiple copies of virtual
584 cplus_val_print (type, valaddr, stream, format, recurse, pretty, dont_print)
590 enum val_prettyprint pretty;
591 struct type **dont_print;
593 struct obstack tmp_obstack;
594 struct type **last_dont_print
595 = (struct type **)obstack_next_free (&dont_print_obstack);
596 int i, n_baseclasses = TYPE_N_BASECLASSES (type);
600 /* If we're at top level, carve out a completely fresh
601 chunk of the obstack and use that until this particular
602 invocation returns. */
603 tmp_obstack = dont_print_obstack;
604 /* Bump up the high-water mark. Now alpha is omega. */
605 obstack_finish (&dont_print_obstack);
608 for (i = 0; i < n_baseclasses; i++)
613 if (BASETYPE_VIA_VIRTUAL (type, i))
615 struct type **first_dont_print
616 = (struct type **)obstack_base (&dont_print_obstack);
618 int j = (struct type **)obstack_next_free (&dont_print_obstack)
622 if (TYPE_BASECLASS (type, i) == first_dont_print[j])
625 obstack_ptr_grow (&dont_print_obstack, TYPE_BASECLASS (type, i));
628 baddr = baseclass_addr (type, i, valaddr, 0, &err);
629 if (err == 0 && baddr == 0)
630 error ("could not find virtual baseclass `%s'\n",
631 type_name_no_tag (TYPE_BASECLASS (type, i)));
635 fprintf_filtered (stream, "\n");
636 print_spaces_filtered (2 * recurse, stream);
638 fputs_filtered ("<", stream);
639 fputs_filtered (type_name_no_tag (TYPE_BASECLASS (type, i)), stream);
640 fputs_filtered ("> = ", stream);
642 fprintf_filtered (stream, "<invalid address 0x%x>", baddr);
644 val_print_fields (TYPE_BASECLASS (type, i), baddr, stream, format,
646 (struct type **)obstack_base (&dont_print_obstack));
647 fputs_filtered (", ", stream);
655 /* Free the space used to deal with the printing
656 of this type from top level. */
657 obstack_free (&dont_print_obstack, last_dont_print);
658 /* Reset watermark so that we can continue protecting
659 ourselves from whatever we were protecting ourselves. */
660 dont_print_obstack = tmp_obstack;
665 print_class_member (valaddr, domain, stream, prefix)
672 /* VAL is a byte offset into the structure type DOMAIN.
673 Find the name of the field for that offset and
677 register unsigned int i;
678 unsigned len = TYPE_NFIELDS (domain);
679 /* @@ Make VAL into bit offset */
680 LONGEST val = unpack_long (builtin_type_int, valaddr) << 3;
681 for (i = TYPE_N_BASECLASSES (domain); i < len; i++)
683 int bitpos = TYPE_FIELD_BITPOS (domain, i);
687 if (val < bitpos && i != 0)
689 /* Somehow pointing into a field. */
691 extra = (val - TYPE_FIELD_BITPOS (domain, i));
702 fprintf_filtered (stream, prefix);
703 name = type_name_no_tag (domain);
705 fputs_filtered (name, stream);
707 type_print_base (domain, stream, 0, 0);
708 fprintf_filtered (stream, "::");
709 fputs_filtered (TYPE_FIELD_NAME (domain, i), stream);
711 fprintf_filtered (stream, " + %d bytes", extra);
713 fprintf_filtered (stream, " (offset in bits)");
716 fprintf_filtered (stream, "%d", val >> 3);
719 /* Print data of type TYPE located at VALADDR (within GDB),
720 which came from the inferior at address ADDRESS,
721 onto stdio stream STREAM according to FORMAT
722 (a letter or 0 for natural format). The data at VALADDR
723 is in target byte order.
725 If the data are a string pointer, returns the number of
726 sting characters printed.
728 if DEREF_REF is nonzero, then dereference references,
729 otherwise just print them like pointers.
731 The PRETTY parameter controls prettyprinting. */
734 val_print (type, valaddr, address, stream, format, deref_ref, recurse, pretty)
742 enum val_prettyprint pretty;
744 register unsigned int i;
746 struct type *elttype;
751 if (pretty == Val_pretty_default)
753 pretty = prettyprint ? Val_prettyprint : Val_no_prettyprint;
758 check_stub_type (type);
760 if (TYPE_FLAGS (type) & TYPE_FLAG_STUB)
762 fprintf_filtered (stream, "<unknown struct>");
767 switch (TYPE_CODE (type))
769 case TYPE_CODE_ARRAY:
770 if (TYPE_LENGTH (type) > 0
771 && TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0)
773 elttype = TYPE_TARGET_TYPE (type);
774 eltlen = TYPE_LENGTH (elttype);
775 len = TYPE_LENGTH (type) / eltlen;
777 print_spaces_filtered (2 + 2 * recurse, stream);
778 fprintf_filtered (stream, "{");
779 /* For an array of chars, print with string syntax. */
780 if (eltlen == 1 && TYPE_CODE (elttype) == TYPE_CODE_INT
781 && (format == 0 || format == 's') )
782 print_string (stream, valaddr, len, 0);
785 unsigned int things_printed = 0;
787 /* If this is a virtual function table, print the 0th
788 entry specially, and the rest of the members normally. */
789 if (is_vtbl_ptr_type (elttype))
791 fprintf_filtered (stream, "%d vtable entries", len-1);
797 for (; i < len && things_printed < print_max; i++)
799 /* Position of the array element we are examining to see
800 whether it is repeated. */
802 /* Number of repetitions we have detected so far. */
808 fprintf_filtered (stream, ",\n");
809 print_spaces_filtered (2 + 2 * recurse, stream);
812 fprintf_filtered (stream, ", ");
813 wrap_here (n_spaces (2 + 2 * recurse));
818 && !bcmp (valaddr + i * eltlen,
819 valaddr + rep1 * eltlen, eltlen))
825 if (reps > REPEAT_COUNT_THRESHOLD)
827 val_print (elttype, valaddr + i * eltlen,
828 0, stream, format, deref_ref,
829 recurse + 1, pretty);
830 fprintf_filtered (stream, " <repeats %u times>", reps);
832 things_printed += REPEAT_COUNT_THRESHOLD;
836 val_print (elttype, valaddr + i * eltlen,
837 0, stream, format, deref_ref,
838 recurse + 1, pretty);
843 fprintf_filtered (stream, "...");
845 fprintf_filtered (stream, "}");
848 /* Array of unspecified length: treat like pointer to first elt. */
849 valaddr = (char *) &address;
852 if (format && format != 's')
854 print_scalar_formatted (valaddr, type, format, 0, stream);
857 if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_METHOD)
859 struct type *domain = TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (type));
865 addr = unpack_pointer (lookup_pointer_type (builtin_type_void),
867 if (addr < 128) /* FIXME! What is this 128? */
869 len = TYPE_NFN_FIELDS (domain);
870 for (i = 0; i < len; i++)
872 f = TYPE_FN_FIELDLIST1 (domain, i);
873 len2 = TYPE_FN_FIELDLIST_LENGTH (domain, i);
875 for (j = 0; j < len2; j++)
878 if (TYPE_FN_FIELD_VOFFSET (f, j) == addr)
888 struct symbol *sym = find_pc_function (addr);
890 error ("invalid pointer to member function");
891 len = TYPE_NFN_FIELDS (domain);
892 for (i = 0; i < len; i++)
894 f = TYPE_FN_FIELDLIST1 (domain, i);
895 len2 = TYPE_FN_FIELDLIST_LENGTH (domain, i);
897 for (j = 0; j < len2; j++)
900 if (!strcmp (SYMBOL_NAME (sym), TYPE_FN_FIELD_PHYSNAME (f, j)))
908 fprintf_filtered (stream, "&");
909 type_print_varspec_prefix (TYPE_FN_FIELD_TYPE (f, j), stream, 0, 0);
910 fprintf (stream, kind);
911 if (TYPE_FN_FIELD_PHYSNAME (f, j)[0] == '_'
912 && TYPE_FN_FIELD_PHYSNAME (f, j)[1] == CPLUS_MARKER)
913 type_print_method_args
914 (TYPE_FN_FIELD_ARGS (f, j) + 1, "~",
915 TYPE_FN_FIELDLIST_NAME (domain, i), 0, stream);
917 type_print_method_args
918 (TYPE_FN_FIELD_ARGS (f, j), "",
919 TYPE_FN_FIELDLIST_NAME (domain, i), 0, stream);
922 fprintf_filtered (stream, "(");
923 type_print (type, "", stream, -1);
924 fprintf_filtered (stream, ") %d", (int) addr >> 3);
926 else if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_MEMBER)
928 print_class_member (valaddr,
929 TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (type)),
934 CORE_ADDR addr = unpack_pointer (type, valaddr);
935 elttype = TYPE_TARGET_TYPE (type);
937 if (TYPE_CODE (elttype) == TYPE_CODE_FUNC)
939 /* Try to print what function it points to. */
940 print_address_demangle (addr, stream, demangle);
941 /* Return value is irrelevant except for string pointers. */
945 if (addressprint && format != 's')
946 fprintf_filtered (stream, "0x%x", addr);
948 /* For a pointer to char or unsigned char,
949 also print the string pointed to, unless pointer is null. */
950 i = 0; /* Number of characters printed. */
951 if (TYPE_LENGTH (elttype) == 1
952 && TYPE_CODE (elttype) == TYPE_CODE_INT
953 && (format == 0 || format == 's')
955 /* If print_max is UINT_MAX, the alloca below will fail.
956 In that case don't try to print the string. */
957 && print_max < UINT_MAX)
959 int first_addr_err = 0;
962 /* Get first character. */
963 errcode = target_read_memory (addr, (char *)&c, 1);
966 /* First address out of bounds. */
972 char *string = (char *) alloca (print_max);
974 /* If the loop ends by us hitting print_max characters,
975 we need to have elipses at the end. */
976 int force_ellipses = 1;
978 /* This loop always fetches print_max characters, even
979 though print_string might want to print more or fewer
980 (with repeated characters). This is so that
981 we don't spend forever fetching if we print
982 a long string consisting of the same character
983 repeated. Also so we can do it all in one memory
984 operation, which is faster. However, this will be
985 slower if print_max is set high, e.g. if you set
986 print_max to 1000, not only will it take a long
987 time to fetch short strings, but if you are near
988 the end of the address space, it might not work. */
990 errcode = target_read_memory (addr, string, print_max);
993 /* Try reading just one character. If that succeeds,
994 assume we hit the end of the address space, but
995 the initial part of the string is probably safe. */
997 errcode = target_read_memory (addr, x, 1);
1002 for (i = 0; i < print_max; i++)
1003 if (string[i] == '\0')
1011 fputs_filtered (" ", stream);
1012 print_string (stream, string, i, force_ellipses);
1019 fprintf_filtered (stream,
1020 (" <Address 0x%x out of bounds>"
1026 error ("Error reading memory address 0x%x: %s.",
1027 addr + i, safe_strerror (errcode));
1033 else /* print vtbl's nicely */
1034 if (is_vtbl_member(type))
1036 CORE_ADDR vt_address = unpack_pointer (type, valaddr);
1038 struct minimal_symbol *msymbol =
1039 lookup_minimal_symbol_by_pc (vt_address);
1040 if ((msymbol != NULL) && (vt_address == msymbol -> address))
1042 fputs_filtered (" <", stream);
1043 fputs_demangled (msymbol -> name, stream,
1044 DMGL_ANSI | DMGL_PARAMS);
1045 fputs_filtered (">", stream);
1051 vt_val = value_at (TYPE_TARGET_TYPE (type), vt_address);
1052 val_print (VALUE_TYPE (vt_val), VALUE_CONTENTS (vt_val),
1053 VALUE_ADDRESS (vt_val), stream, format,
1054 deref_ref, recurse + 1, pretty);
1057 fprintf_filtered (stream, "\n");
1058 print_spaces_filtered (2 + 2 * recurse, stream);
1063 /* Return number of characters printed, plus one for the
1064 terminating null if we have "reached the end". */
1065 return i + (print_max && i != print_max);
1069 case TYPE_CODE_MEMBER:
1070 error ("not implemented: member type in val_print");
1074 if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_MEMBER)
1076 print_class_member (valaddr,
1077 TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (type)),
1083 fprintf_filtered (stream, "@0x%lx",
1084 unpack_long (builtin_type_int, valaddr));
1086 fputs_filtered (": ", stream);
1088 /* De-reference the reference. */
1091 if (TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_UNDEF)
1095 (TYPE_TARGET_TYPE (type),
1096 unpack_pointer (lookup_pointer_type (builtin_type_void),
1098 val_print (VALUE_TYPE (deref_val), VALUE_CONTENTS (deref_val),
1099 VALUE_ADDRESS (deref_val), stream, format,
1100 deref_ref, recurse + 1, pretty);
1103 fputs_filtered ("???", stream);
1107 case TYPE_CODE_UNION:
1108 if (recurse && !unionprint)
1110 fprintf_filtered (stream, "{...}");
1114 case TYPE_CODE_STRUCT:
1115 if (vtblprint && is_vtbl_ptr_type(type))
1117 /* Print the unmangled name if desired. */
1118 print_address_demangle(*((int *) (valaddr + /* FIXME bytesex */
1119 TYPE_FIELD_BITPOS (type, VTBL_FNADDR_OFFSET) / 8)),
1123 val_print_fields (type, valaddr, stream, format, recurse, pretty, 0);
1126 case TYPE_CODE_ENUM:
1129 print_scalar_formatted (valaddr, type, format, 0, stream);
1132 len = TYPE_NFIELDS (type);
1133 val = unpack_long (builtin_type_int, valaddr);
1134 for (i = 0; i < len; i++)
1137 if (val == TYPE_FIELD_BITPOS (type, i))
1141 fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
1144 fprintf_filtered (stream, "%lld", val);
1146 fprintf_filtered (stream, "%ld", val);
1150 case TYPE_CODE_FUNC:
1153 print_scalar_formatted (valaddr, type, format, 0, stream);
1156 /* FIXME, we should consider, at least for ANSI C language, eliminating
1157 the distinction made between FUNCs and POINTERs to FUNCs. */
1158 fprintf_filtered (stream, "{");
1159 type_print (type, "", stream, -1);
1160 fprintf_filtered (stream, "} ");
1161 /* Try to print what function it points to, and its address. */
1162 print_address_demangle (address, stream, demangle);
1166 if (format || output_format)
1168 print_scalar_formatted (valaddr, type,
1169 format? format: output_format,
1173 if (TYPE_LENGTH (type) > sizeof (LONGEST))
1175 if (TYPE_UNSIGNED (type))
1177 /* First figure out whether the number in fact has zeros
1178 in all its bytes more significant than least significant
1179 sizeof (LONGEST) ones. */
1181 /* Pointer to first (i.e. lowest address) nonzero character. */
1183 len = TYPE_LENGTH (type);
1185 #if TARGET_BYTE_ORDER == BIG_ENDIAN
1187 len > sizeof (LONGEST)
1188 && p < valaddr + TYPE_LENGTH (type);
1190 #else /* Little endian. */
1191 first_addr = valaddr;
1192 for (p = valaddr + TYPE_LENGTH (type);
1193 len > sizeof (LONGEST) && p >= valaddr;
1195 #endif /* Little endian. */
1202 #if TARGET_BYTE_ORDER == BIG_ENDIAN
1206 if (len <= sizeof (LONGEST))
1208 /* We can print it in decimal. */
1211 #if defined (LONG_LONG)
1216 unpack_long (BUILTIN_TYPE_LONGEST, first_addr));
1220 /* It is big, so print it in hex. */
1221 print_hex_chars (stream, (unsigned char *)first_addr, len);
1226 /* Signed. One could assume two's complement (a reasonable
1227 assumption, I think) and do better than this. */
1228 print_hex_chars (stream, (unsigned char *)valaddr,
1229 TYPE_LENGTH (type));
1233 #ifdef PRINT_TYPELESS_INTEGER
1234 PRINT_TYPELESS_INTEGER (stream, type, unpack_long (type, valaddr));
1237 fprintf_filtered (stream,
1238 TYPE_UNSIGNED (type) ? "%u" : "%d",
1239 unpack_long (type, valaddr));
1241 fprintf_filtered (stream,
1242 TYPE_UNSIGNED (type) ? "%llu" : "%lld",
1243 unpack_long (type, valaddr));
1247 if (TYPE_LENGTH (type) == 1)
1249 fprintf_filtered (stream, " '");
1250 printchar ((unsigned char) unpack_long (type, valaddr),
1252 fprintf_filtered (stream, "'");
1258 print_scalar_formatted (valaddr, type, format, 0, stream);
1260 print_floating (valaddr, type, stream);
1263 case TYPE_CODE_VOID:
1264 fprintf_filtered (stream, "void");
1267 case TYPE_CODE_UNDEF:
1268 /* This happens (without TYPE_FLAG_STUB set) on systems which don't use
1269 dbx xrefs (NO_DBX_XREFS in gcc) if a file has a "struct foo *bar"
1270 and no complete type for struct foo in that file. */
1271 fprintf_filtered (stream, "<unknown struct>");
1274 case TYPE_CODE_ERROR:
1275 fprintf_filtered (stream, "?");
1278 case TYPE_CODE_RANGE:
1279 /* FIXME, we should not ever have to print one of these yet. */
1280 fprintf_filtered (stream, "<range type>");
1284 error ("Invalid type code in symbol table.");
1290 /* Print a description of a type in the format of a
1291 typedef for the current language.
1292 NEW is the new name for a type TYPE. */
1294 typedef_print (type, new, stream)
1299 switch (current_language->la_language)
1303 case language_cplus:
1304 fprintf_filtered(stream, "typedef ");
1305 type_print(type,"",stream,0);
1306 if(TYPE_NAME ((SYMBOL_TYPE (new))) == 0
1307 || 0 != strcmp (TYPE_NAME ((SYMBOL_TYPE (new))),
1309 fprintf_filtered(stream, " %s", SYMBOL_NAME(new));
1314 fprintf_filtered(stream, "TYPE ");
1315 if(!TYPE_NAME(SYMBOL_TYPE(new)) ||
1316 strcmp (TYPE_NAME(SYMBOL_TYPE(new)),
1318 fprintf_filtered(stream, "%s = ", SYMBOL_NAME(new));
1320 fprintf_filtered(stream, "<builtin> = ");
1321 type_print(type,"",stream,0);
1325 error("Language not supported.");
1327 fprintf_filtered(stream, ";\n");
1331 /* Print a description of a type TYPE
1332 in the form of a declaration of a variable named VARSTRING.
1333 (VARSTRING is demangled if necessary.)
1334 Output goes to STREAM (via stdio).
1335 If SHOW is positive, we show the contents of the outermost level
1336 of structure even if there is a type name that could be used instead.
1337 If SHOW is negative, we never show the details of elements' types. */
1340 type_print (type, varstring, stream, show)
1346 type_print_1 (type, varstring, stream, show, 0);
1349 /* LEVEL is the depth to indent lines by. */
1352 type_print_1 (type, varstring, stream, show, level)
1359 register enum type_code code;
1360 char *demangled = NULL;
1363 type_print_base (type, stream, show, level);
1364 code = TYPE_CODE (type);
1365 if ((varstring && *varstring)
1367 /* Need a space if going to print stars or brackets;
1368 but not if we will print just a type name. */
1369 ((show > 0 || TYPE_NAME (type) == 0)
1371 (code == TYPE_CODE_PTR || code == TYPE_CODE_FUNC
1372 || code == TYPE_CODE_METHOD
1373 || code == TYPE_CODE_ARRAY
1374 || code == TYPE_CODE_MEMBER
1375 || code == TYPE_CODE_REF)))
1376 fprintf_filtered (stream, " ");
1377 type_print_varspec_prefix (type, stream, show, 0);
1379 /* See if the name has a C++ demangled equivalent, and if so, print that
1384 demangled = cplus_demangle (varstring, DMGL_ANSI | DMGL_PARAMS);
1386 fputs_filtered ((demangled != NULL) ? demangled : varstring, stream);
1388 /* For demangled function names, we have the arglist as part of the name,
1389 so don't print an additional pair of ()'s */
1391 demangled_args = (demangled != NULL) && (code == TYPE_CODE_FUNC);
1392 type_print_varspec_suffix (type, stream, show, 0, demangled_args);
1400 /* Print the method arguments ARGS to the file STREAM. */
1402 type_print_method_args (args, prefix, varstring, staticp, stream)
1404 char *prefix, *varstring;
1410 fputs_demangled (prefix, stream, DMGL_ANSI | DMGL_PARAMS);
1411 fputs_demangled (varstring, stream, DMGL_ANSI | DMGL_PARAMS);
1412 fputs_filtered (" (", stream);
1413 if (args && args[!staticp] && args[!staticp]->code != TYPE_CODE_VOID)
1415 i = !staticp; /* skip the class variable */
1418 type_print (args[i++], "", stream, 0);
1421 fprintf_filtered (stream, " ...");
1424 else if (args[i]->code != TYPE_CODE_VOID)
1426 fprintf_filtered (stream, ", ");
1431 fprintf_filtered (stream, ")");
1434 /* If TYPE is a derived type, then print out derivation
1435 information. Print out all layers of the type heirarchy
1436 until we encounter one with multiple inheritance.
1437 At that point, print out that ply, and return. */
1439 type_print_derivation_info (stream, type)
1444 int i, n_baseclasses = TYPE_N_BASECLASSES (type);
1445 struct type *basetype = 0;
1447 while (type && n_baseclasses > 0)
1449 /* Not actually sure about this one -- Bryan. */
1450 check_stub_type (type);
1452 fprintf_filtered (stream, ": ");
1455 basetype = TYPE_BASECLASS (type, i);
1456 if (name = type_name_no_tag (basetype))
1458 fprintf_filtered (stream, "%s%s ",
1459 BASETYPE_VIA_PUBLIC(type, i) ? "public" : "private",
1460 BASETYPE_VIA_VIRTUAL(type, i) ? " virtual" : "");
1461 fputs_filtered (name, stream);
1464 if (i >= n_baseclasses)
1466 fprintf_filtered (stream, ", ");
1469 fprintf_filtered (stream, " ");
1470 if (n_baseclasses != 1)
1472 n_baseclasses = TYPE_N_BASECLASSES (basetype);
1477 /* Print any asterisks or open-parentheses needed before the
1478 variable name (to describe its type).
1480 On outermost call, pass 0 for PASSED_A_PTR.
1481 On outermost call, SHOW > 0 means should ignore
1482 any typename for TYPE and show its details.
1483 SHOW is always zero on recursive calls. */
1486 type_print_varspec_prefix (type, stream, show, passed_a_ptr)
1496 if (TYPE_NAME (type) && show <= 0)
1501 switch (TYPE_CODE (type))
1504 type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 1);
1505 fprintf_filtered (stream, "*");
1508 case TYPE_CODE_MEMBER:
1510 fprintf_filtered (stream, "(");
1511 type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0,
1513 fprintf_filtered (stream, " ");
1514 name = type_name_no_tag (TYPE_DOMAIN_TYPE (type));
1516 fputs_filtered (name, stream);
1518 type_print_base (TYPE_DOMAIN_TYPE (type), stream, 0, passed_a_ptr);
1519 fprintf_filtered (stream, "::");
1522 case TYPE_CODE_METHOD:
1524 fprintf (stream, "(");
1525 type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0,
1529 fprintf_filtered (stream, " ");
1530 type_print_base (TYPE_DOMAIN_TYPE (type), stream, 0,
1532 fprintf_filtered (stream, "::");
1537 type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 1);
1538 fprintf_filtered (stream, "&");
1541 case TYPE_CODE_FUNC:
1542 type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0,
1545 fprintf_filtered (stream, "(");
1548 case TYPE_CODE_ARRAY:
1549 type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0,
1552 fprintf_filtered (stream, "(");
1555 case TYPE_CODE_UNDEF:
1556 case TYPE_CODE_STRUCT:
1557 case TYPE_CODE_UNION:
1558 case TYPE_CODE_ENUM:
1561 case TYPE_CODE_VOID:
1562 case TYPE_CODE_ERROR:
1563 case TYPE_CODE_CHAR:
1564 case TYPE_CODE_BOOL:
1565 /* These types need no prefix. They are listed here so that
1566 gcc -Wall will reveal any types that haven't been handled. */
1571 /* Print any array sizes, function arguments or close parentheses
1572 needed after the variable name (to describe its type).
1573 Args work like type_print_varspec_prefix. */
1576 type_print_varspec_suffix (type, stream, show, passed_a_ptr, demangled_args)
1586 if (TYPE_NAME (type) && show <= 0)
1591 switch (TYPE_CODE (type))
1593 case TYPE_CODE_ARRAY:
1595 fprintf_filtered (stream, ")");
1597 fprintf_filtered (stream, "[");
1598 if (TYPE_LENGTH (type) > 0
1599 && TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0)
1600 fprintf_filtered (stream, "%d",
1602 / TYPE_LENGTH (TYPE_TARGET_TYPE (type))));
1603 fprintf_filtered (stream, "]");
1605 type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0,
1609 case TYPE_CODE_MEMBER:
1611 fprintf_filtered (stream, ")");
1612 type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0, 0);
1615 case TYPE_CODE_METHOD:
1617 fprintf_filtered (stream, ")");
1618 type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0, 0);
1622 struct type **args = TYPE_ARG_TYPES (type);
1624 fprintf_filtered (stream, "(");
1626 fprintf_filtered (stream, "...");
1627 else for (i = 1; args[i] != 0 && args[i]->code != TYPE_CODE_VOID; i++)
1629 type_print_1 (args[i], "", stream, -1, 0);
1631 fprintf_filtered (stream, "...");
1632 else if (args[i+1]->code != TYPE_CODE_VOID) {
1633 fprintf_filtered (stream, ",");
1637 fprintf_filtered (stream, ")");
1643 type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 1, 0);
1646 case TYPE_CODE_FUNC:
1647 type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0,
1650 fprintf_filtered (stream, ")");
1651 if (!demangled_args)
1652 fprintf_filtered (stream, "()");
1655 case TYPE_CODE_UNDEF:
1656 case TYPE_CODE_STRUCT:
1657 case TYPE_CODE_UNION:
1658 case TYPE_CODE_ENUM:
1661 case TYPE_CODE_VOID:
1662 case TYPE_CODE_ERROR:
1663 case TYPE_CODE_CHAR:
1664 case TYPE_CODE_BOOL:
1665 /* These types do not need a suffix. They are listed so that
1666 gcc -Wall will report types that may not have been considered. */
1671 /* Print the name of the type (or the ultimate pointer target,
1672 function value or array element), or the description of a
1675 SHOW nonzero means don't print this type as just its name;
1676 show its real definition even if it has a name.
1677 SHOW zero means print just typename or struct tag if there is one
1678 SHOW negative means abbreviate structure elements.
1679 SHOW is decremented for printing of structure elements.
1681 LEVEL is the depth to indent by.
1682 We increase it for some recursive calls. */
1685 type_print_base (type, stream, show, level)
1694 register int lastval;
1696 char *demangled_name;
1703 fputs_filtered ("<type unknown>", stream);
1707 /* When SHOW is zero or less, and there is a valid type name, then always
1708 just print the type name directly from the type. */
1710 if ((show <= 0) && (TYPE_NAME (type) != NULL))
1712 fputs_filtered (TYPE_NAME (type), stream);
1716 switch (TYPE_CODE (type))
1718 case TYPE_CODE_ARRAY:
1720 case TYPE_CODE_MEMBER:
1722 case TYPE_CODE_FUNC:
1723 case TYPE_CODE_METHOD:
1724 type_print_base (TYPE_TARGET_TYPE (type), stream, show, level);
1727 case TYPE_CODE_STRUCT:
1728 fprintf_filtered (stream, "struct ");
1731 case TYPE_CODE_UNION:
1732 fprintf_filtered (stream, "union ");
1734 if (name = type_name_no_tag (type))
1736 fputs_filtered (name, stream);
1737 fputs_filtered (" ", stream);
1741 fprintf_filtered (stream, "{...}");
1744 check_stub_type (type);
1746 type_print_derivation_info (stream, type);
1748 fprintf_filtered (stream, "{");
1749 len = TYPE_NFIELDS (type);
1751 fprintf_filtered (stream, "\n");
1754 if (TYPE_FLAGS (type) & TYPE_FLAG_STUB)
1755 fprintf_filtered (stream, "<incomplete type>\n");
1757 fprintf_filtered (stream, "<no data fields>\n");
1760 /* If there is a base class for this type,
1761 do not print the field that it occupies. */
1762 for (i = TYPE_N_BASECLASSES (type); i < len; i++)
1765 /* Don't print out virtual function table. */
1766 if ((TYPE_FIELD_NAME (type, i))[5] == CPLUS_MARKER &&
1767 !strncmp (TYPE_FIELD_NAME (type, i), "_vptr", 5))
1770 print_spaces_filtered (level + 4, stream);
1771 if (TYPE_FIELD_STATIC (type, i))
1773 fprintf_filtered (stream, "static ");
1775 type_print_1 (TYPE_FIELD_TYPE (type, i),
1776 TYPE_FIELD_NAME (type, i),
1777 stream, show - 1, level + 4);
1778 if (!TYPE_FIELD_STATIC (type, i)
1779 && TYPE_FIELD_PACKED (type, i))
1781 /* It is a bitfield. This code does not attempt
1782 to look at the bitpos and reconstruct filler,
1783 unnamed fields. This would lead to misleading
1784 results if the compiler does not put out fields
1785 for such things (I don't know what it does). */
1786 fprintf_filtered (stream, " : %d",
1787 TYPE_FIELD_BITSIZE (type, i));
1789 fprintf_filtered (stream, ";\n");
1792 /* C++: print out the methods */
1793 len = TYPE_NFN_FIELDS (type);
1794 if (len) fprintf_filtered (stream, "\n");
1795 for (i = 0; i < len; i++)
1797 struct fn_field *f = TYPE_FN_FIELDLIST1 (type, i);
1798 int j, len2 = TYPE_FN_FIELDLIST_LENGTH (type, i);
1799 char *method_name = TYPE_FN_FIELDLIST_NAME (type, i);
1800 int is_constructor = name && strcmp(method_name, name) == 0;
1801 for (j = 0; j < len2; j++)
1804 print_spaces_filtered (level + 4, stream);
1805 if (TYPE_FN_FIELD_VIRTUAL_P (f, j))
1806 fprintf_filtered (stream, "virtual ");
1807 else if (TYPE_FN_FIELD_STATIC_P (f, j))
1808 fprintf_filtered (stream, "static ");
1809 if (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)) == 0)
1811 /* Keep GDB from crashing here. */
1812 fprintf (stream, "<undefined type> %s;\n",
1813 TYPE_FN_FIELD_PHYSNAME (f, j));
1816 else if (!is_constructor)
1818 type_print (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)),
1820 fputs_filtered (" ", stream);
1822 if (TYPE_FN_FIELD_STUB (f, j))
1824 /* Build something we can demangle. */
1825 mangled_name = gdb_mangle_name (type, i, j);
1827 cplus_demangle (mangled_name,
1828 DMGL_ANSI | DMGL_PARAMS);
1829 if (demangled_name == NULL)
1830 fprintf_filtered (stream, "<badly mangled name %s>",
1834 fprintf_filtered (stream, "%s",
1835 strchr (demangled_name, ':') + 2);
1836 free (demangled_name);
1838 free (mangled_name);
1840 else if (TYPE_FN_FIELD_PHYSNAME (f, j)[0] == '_'
1841 && TYPE_FN_FIELD_PHYSNAME (f, j)[1] == CPLUS_MARKER)
1842 type_print_method_args
1843 (TYPE_FN_FIELD_ARGS (f, j) + 1, "~",
1844 method_name, 0, stream);
1846 type_print_method_args
1847 (TYPE_FN_FIELD_ARGS (f, j), "",
1849 TYPE_FN_FIELD_STATIC_P (f, j), stream);
1851 fprintf_filtered (stream, ";\n");
1855 print_spaces_filtered (level, stream);
1856 fprintf_filtered (stream, "}");
1860 case TYPE_CODE_ENUM:
1861 fprintf_filtered (stream, "enum ");
1862 if (name = type_name_no_tag (type))
1864 fputs_filtered (name, stream);
1865 fputs_filtered (" ", stream);
1869 fprintf_filtered (stream, "{...}");
1872 fprintf_filtered (stream, "{");
1873 len = TYPE_NFIELDS (type);
1875 for (i = 0; i < len; i++)
1878 if (i) fprintf_filtered (stream, ", ");
1880 fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
1881 if (lastval != TYPE_FIELD_BITPOS (type, i))
1883 fprintf_filtered (stream, " = %d", TYPE_FIELD_BITPOS (type, i));
1884 lastval = TYPE_FIELD_BITPOS (type, i);
1888 fprintf_filtered (stream, "}");
1892 case TYPE_CODE_VOID:
1893 fprintf_filtered (stream, "void");
1896 case TYPE_CODE_UNDEF:
1897 fprintf_filtered (stream, "struct <unknown>");
1900 case TYPE_CODE_ERROR:
1901 fprintf_filtered (stream, "<unknown type>");
1904 case TYPE_CODE_RANGE:
1905 /* This should not occur */
1906 fprintf_filtered (stream, "<range type>");
1910 /* Handle types not explicitly handled by the other cases,
1911 such as fundamental types. For these, just print whatever
1912 the type name is, as recorded in the type itself. If there
1913 is no type name, then complain. */
1914 if (TYPE_NAME (type) != NULL)
1916 fputs_filtered (TYPE_NAME (type), stream);
1920 error ("Invalid type code (%d) in symbol table.", TYPE_CODE (type));
1927 /* Validate an input or output radix setting, and make sure the user
1928 knows what they really did here. Radix setting is confusing, e.g.
1929 setting the input radix to "10" never changes it! */
1933 set_input_radix (args, from_tty, c)
1936 struct cmd_list_element *c;
1938 unsigned radix = *(unsigned *)c->var;
1941 printf_filtered ("Input radix set to decimal %d, hex %x, octal %o\n",
1942 radix, radix, radix);
1948 set_output_radix (args, from_tty, c)
1951 struct cmd_list_element *c;
1953 unsigned radix = *(unsigned *)c->var;
1956 printf_filtered ("Output radix set to decimal %d, hex %x, octal %o\n",
1957 radix, radix, radix);
1959 /* FIXME, we really should be able to validate the setting BEFORE
1964 output_format = 'x';
1970 output_format = 'o'; /* octal */
1974 error ("Unsupported radix ``decimal %d''; using decimal output",
1981 set_radix (arg, from_tty, c)
1984 struct cmd_list_element *c;
1986 unsigned radix = *(unsigned *)c->var;
1989 printf_filtered ("Radix set to decimal %d, hex %x, octal %o\n",
1990 radix, radix, radix);
1992 input_radix = radix;
1993 output_radix = radix;
1995 set_output_radix (arg, 0, c);
1998 struct cmd_list_element *setprintlist = NULL;
1999 struct cmd_list_element *showprintlist = NULL;
2003 set_print (arg, from_tty)
2008 "\"set print\" must be followed by the name of a print subcommand.\n");
2009 help_list (setprintlist, "set print ", -1, stdout);
2014 show_print (args, from_tty)
2018 cmd_show_list (showprintlist, from_tty, "");
2022 _initialize_valprint ()
2024 struct cmd_list_element *c;
2026 add_prefix_cmd ("print", no_class, set_print,
2027 "Generic command for setting how things print.",
2028 &setprintlist, "set print ", 0, &setlist);
2029 add_alias_cmd ("p", "print", no_class, 1, &setlist);
2030 add_alias_cmd ("pr", "print", no_class, 1, &setlist); /* prefer set print
2032 add_prefix_cmd ("print", no_class, show_print,
2033 "Generic command for showing print settings.",
2034 &showprintlist, "show print ", 0, &showlist);
2035 add_alias_cmd ("p", "print", no_class, 1, &showlist);
2036 add_alias_cmd ("pr", "print", no_class, 1, &showlist);
2039 (add_set_cmd ("elements", no_class, var_uinteger, (char *)&print_max,
2040 "Set limit on string chars or array elements to print.\n\
2041 \"set print elements 0\" causes there to be no limit.",
2046 (add_set_cmd ("pretty", class_support, var_boolean, (char *)&prettyprint,
2047 "Set prettyprinting of structures.",
2052 (add_set_cmd ("union", class_support, var_boolean, (char *)&unionprint,
2053 "Set printing of unions interior to structures.",
2058 (add_set_cmd ("vtbl", class_support, var_boolean, (char *)&vtblprint,
2059 "Set printing of C++ virtual function tables.",
2064 (add_set_cmd ("array", class_support, var_boolean, (char *)&arrayprint,
2065 "Set prettyprinting of arrays.",
2070 (add_set_cmd ("object", class_support, var_boolean, (char *)&objectprint,
2071 "Set printing of object's derived type based on vtable info.",
2076 (add_set_cmd ("address", class_support, var_boolean, (char *)&addressprint,
2077 "Set printing of addresses.",
2082 /* The "show radix" cmd isn't good enough to show two separate values.
2083 The rest of the code works, but the show part is confusing, so don't
2084 let them be set separately 'til we work out "show". */
2085 c = add_set_cmd ("input-radix", class_support, var_uinteger,
2086 (char *)&input_radix,
2087 "Set default input radix for entering numbers.",
2089 add_show_from_set (c, &showlist);
2090 c->function = set_input_radix;
2092 c = add_set_cmd ("output-radix", class_support, var_uinteger,
2093 (char *)&output_radix,
2094 "Set default output radix for printing of values.",
2096 add_show_from_set (c, &showlist);
2097 c->function = set_output_radix;
2100 c = add_set_cmd ("radix", class_support, var_uinteger,
2101 (char *)&output_radix,
2102 "Set default input and output number radix.",
2104 add_show_from_set (c, &showlist);
2105 c->function.sfunc = set_radix;
2107 /* Give people the defaults which they are used to. */
2117 obstack_begin (&dont_print_obstack, 32 * sizeof (struct type *));