1 /* Print values for GDB, the GNU debugger.
2 Copyright 1986, 1988, 1989, 1991 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
33 /* Prototypes for local functions */
36 print_string PARAMS ((FILE *, char *, unsigned int, int));
39 show_print PARAMS ((char *, int));
42 set_print PARAMS ((char *, int));
45 set_radix PARAMS ((char *, int, struct cmd_list_element *));
48 set_output_radix PARAMS ((char *, int, struct cmd_list_element *));
51 type_print_base PARAMS ((struct type *, FILE *, int, int));
54 type_print_varspec_suffix PARAMS ((struct type *, FILE *, int, int));
57 type_print_varspec_prefix PARAMS ((struct type *, FILE *, int, int));
60 type_print_derivation_info PARAMS ((FILE *, struct type *));
63 type_print_method_args PARAMS ((struct type **, char *, char *, int, FILE *));
66 cplus_val_print PARAMS ((struct type *, char *, FILE *, int, int,
67 enum val_prettyprint, struct type **));
70 val_print_fields PARAMS ((struct type *, char *, FILE *, int, int,
71 enum val_prettyprint, struct type **));
74 is_vtbl_member PARAMS ((struct type *));
77 is_vtbl_ptr_type PARAMS ((struct type *));
80 print_hex_chars PARAMS ((FILE *, unsigned char *, unsigned));
83 extern char *sys_errlist[];
85 extern int demangle; /* whether to print C++ syms raw or source-form */
87 /* Maximum number of chars to print for a string pointer value
88 or vector contents, or UINT_MAX for no limit. */
90 static unsigned int print_max;
92 /* Default input and output radixes, and output format letter. */
94 unsigned input_radix = 10;
95 unsigned output_radix = 10;
96 int output_format = 0;
99 char **unsigned_type_table;
100 char **signed_type_table;
101 char **float_type_table;
104 /* Print repeat counts if there are more than this
105 many repetitions of an element in an array. */
106 #define REPEAT_COUNT_THRESHOLD 10
108 /* Define a mess of print controls. */
110 int prettyprint; /* Controls pretty printing of structures */
111 int vtblprint; /* Controls printing of vtbl's */
112 int unionprint; /* Controls printing of nested unions. */
113 int arrayprint; /* Controls pretty printing of arrays. */
114 int addressprint; /* Controls pretty printing of addresses. */
115 int objectprint; /* Controls looking up an object's derived type
116 using what we find in its vtables. */
118 struct obstack dont_print_obstack;
121 /* Print the character string STRING, printing at most LENGTH characters.
122 Printing stops early if the number hits print_max; repeat counts
123 are printed as appropriate. Print ellipses at the end if we
124 had to stop before printing LENGTH characters, or if FORCE_ELLIPSES. */
127 print_string (stream, string, length, force_ellipses)
133 register unsigned int i;
134 unsigned int things_printed = 0;
137 extern int inspect_it;
141 fputs_filtered ("\"\"", stdout);
145 for (i = 0; i < length && things_printed < print_max; ++i)
147 /* Position of the character we are examining
148 to see whether it is repeated. */
150 /* Number of repetitions we have detected so far. */
157 fputs_filtered (", ", stream);
163 while (rep1 < length && string[rep1] == string[i])
169 if (reps > REPEAT_COUNT_THRESHOLD)
174 fputs_filtered ("\\\", ", stream);
176 fputs_filtered ("\", ", stream);
179 fputs_filtered ("'", stream);
180 printchar (string[i], stream, '\'');
181 fprintf_filtered (stream, "' <repeats %u times>", reps);
183 things_printed += REPEAT_COUNT_THRESHOLD;
191 fputs_filtered ("\\\"", stream);
193 fputs_filtered ("\"", stream);
196 printchar (string[i], stream, '"');
201 /* Terminate the quotes if necessary. */
205 fputs_filtered ("\\\"", stream);
207 fputs_filtered ("\"", stream);
210 if (force_ellipses || i < length)
211 fputs_filtered ("...", stream);
214 /* Print a floating point value of type TYPE, pointed to in GDB by VALADDR,
218 print_floating (valaddr, type, stream)
225 unsigned len = TYPE_LENGTH (type);
227 #if defined (IEEE_FLOAT)
229 /* Check for NaN's. Note that this code does not depend on us being
230 on an IEEE conforming system. It only depends on the target
231 machine using IEEE representation. This means (a)
232 cross-debugging works right, and (2) IEEE_FLOAT can (and should)
233 be defined for systems like the 68881, which uses IEEE
234 representation, but is not IEEE conforming. */
238 /* Is the sign bit 0? */
240 /* Is it is a NaN (i.e. the exponent is all ones and
241 the fraction is nonzero)? */
244 if (len == sizeof (float))
246 /* It's single precision. */
247 bcopy (valaddr, &low, sizeof (low));
248 /* target -> host. */
249 SWAP_TARGET_AND_HOST (&low, sizeof (float));
250 nonnegative = low >= 0;
251 is_nan = ((((low >> 23) & 0xFF) == 0xFF)
252 && 0 != (low & 0x7FFFFF));
258 /* It's double precision. Get the high and low words. */
260 #if TARGET_BYTE_ORDER == BIG_ENDIAN
261 bcopy (valaddr+4, &low, sizeof (low));
262 bcopy (valaddr+0, &high, sizeof (high));
264 bcopy (valaddr+0, &low, sizeof (low));
265 bcopy (valaddr+4, &high, sizeof (high));
267 SWAP_TARGET_AND_HOST (&low, sizeof (low));
268 SWAP_TARGET_AND_HOST (&high, sizeof (high));
269 nonnegative = high >= 0;
270 is_nan = (((high >> 20) & 0x7ff) == 0x7ff
271 && ! ((((high & 0xfffff) == 0)) && (low == 0)));
277 /* The meaning of the sign and fraction is not defined by IEEE.
278 But the user might know what they mean. For example, they
279 (in an implementation-defined manner) distinguish between
280 signaling and quiet NaN's. */
282 fprintf_filtered (stream, "-NaN(0x%lx%.8lx)" + nonnegative,
285 fprintf_filtered (stream, "-NaN(0x%lx)" + nonnegative, low);
289 #endif /* IEEE_FLOAT. */
291 doub = unpack_double (type, valaddr, &inv);
293 fprintf_filtered (stream, "<invalid float value>");
295 fprintf_filtered (stream, len <= sizeof(float) ? "%.9g" : "%.17g", doub);
298 /* VALADDR points to an integer of LEN bytes. Print it in hex on stream. */
300 print_hex_chars (stream, valaddr, len)
302 unsigned char *valaddr;
307 fprintf_filtered (stream, "0x");
308 #if TARGET_BYTE_ORDER == BIG_ENDIAN
312 #else /* Little endian. */
313 for (p = valaddr + len - 1;
318 fprintf_filtered (stream, "%02x", *p);
322 /* Print the value VAL in C-ish syntax on stream STREAM.
323 FORMAT is a format-letter, or 0 for print in natural format of data type.
324 If the object printed is a string pointer, returns
325 the number of string bytes printed. */
328 value_print (val, stream, format, pretty)
332 enum val_prettyprint pretty;
334 register unsigned int i, n, typelen;
338 printf_filtered ("<address of value unknown>");
341 if (VALUE_OPTIMIZED_OUT (val))
343 printf_filtered ("<value optimized out>");
347 /* A "repeated" value really contains several values in a row.
348 They are made by the @ operator.
349 Print such values as if they were arrays. */
351 else if (VALUE_REPEATED (val))
353 n = VALUE_REPETITIONS (val);
354 typelen = TYPE_LENGTH (VALUE_TYPE (val));
355 fprintf_filtered (stream, "{");
356 /* Print arrays of characters using string syntax. */
357 if (typelen == 1 && TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_INT
359 print_string (stream, VALUE_CONTENTS (val), n, 0);
362 unsigned int things_printed = 0;
364 for (i = 0; i < n && things_printed < print_max; i++)
366 /* Position of the array element we are examining to see
367 whether it is repeated. */
369 /* Number of repetitions we have detected so far. */
373 fprintf_filtered (stream, ", ");
379 && !bcmp (VALUE_CONTENTS (val) + typelen * i,
380 VALUE_CONTENTS (val) + typelen * rep1, typelen))
386 if (reps > REPEAT_COUNT_THRESHOLD)
388 val_print (VALUE_TYPE (val),
389 VALUE_CONTENTS (val) + typelen * i,
390 VALUE_ADDRESS (val) + typelen * i,
391 stream, format, 1, 0, pretty);
392 fprintf (stream, " <repeats %u times>", reps);
394 things_printed += REPEAT_COUNT_THRESHOLD;
398 val_print (VALUE_TYPE (val),
399 VALUE_CONTENTS (val) + typelen * i,
400 VALUE_ADDRESS (val) + typelen * i,
401 stream, format, 1, 0, pretty);
406 fprintf_filtered (stream, "...");
408 fprintf_filtered (stream, "}");
413 struct type *type = VALUE_TYPE (val);
415 /* If it is a pointer, indicate what it points to.
417 Print type also if it is a reference.
419 C++: if it is a member pointer, we will take care
420 of that when we print it. */
421 if (TYPE_CODE (type) == TYPE_CODE_PTR
422 || TYPE_CODE (type) == TYPE_CODE_REF)
424 /* Hack: remove (char *) for char strings. Their
425 type is indicated by the quoted string anyway. */
426 if (TYPE_CODE (type) == TYPE_CODE_PTR
427 && TYPE_LENGTH (TYPE_TARGET_TYPE (type)) == sizeof(char)
428 && TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_INT
429 && !TYPE_UNSIGNED (TYPE_TARGET_TYPE (type)))
435 fprintf_filtered (stream, "(");
436 type_print (type, "", stream, -1);
437 fprintf_filtered (stream, ") ");
440 return val_print (type, VALUE_CONTENTS (val),
441 VALUE_ADDRESS (val), stream, format, 1, 0, pretty);
445 /* Return truth value for assertion that TYPE is of the type
446 "pointer to virtual function". */
448 is_vtbl_ptr_type(type)
451 char *typename = type_name_no_tag (type);
452 static const char vtbl_ptr_name[] =
453 { CPLUS_MARKER,'v','t','b','l','_','p','t','r','_','t','y','p','e', 0 };
455 return (typename != NULL && !strcmp(typename, vtbl_ptr_name));
458 /* Return truth value for the assertion that TYPE is of the type
459 "pointer to virtual function table". */
464 if (TYPE_CODE (type) == TYPE_CODE_PTR)
465 type = TYPE_TARGET_TYPE (type);
469 if (TYPE_CODE (type) == TYPE_CODE_ARRAY
470 && TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_STRUCT)
471 /* Virtual functions tables are full of pointers to virtual functions. */
472 return is_vtbl_ptr_type (TYPE_TARGET_TYPE (type));
476 /* Mutually recursive subroutines of cplus_val_print and val_print to print out
477 a structure's fields: val_print_fields and cplus_val_print.
479 TYPE, VALADDR, STREAM, RECURSE, and PRETTY have the
480 same meanings as in cplus_val_print and val_print.
482 DONT_PRINT is an array of baseclass types that we
483 should not print, or zero if called from top level. */
486 val_print_fields (type, valaddr, stream, format, recurse, pretty, dont_print)
492 enum val_prettyprint pretty;
493 struct type **dont_print;
495 int i, len, n_baseclasses;
497 check_stub_type (type);
499 fprintf_filtered (stream, "{");
500 len = TYPE_NFIELDS (type);
501 n_baseclasses = TYPE_N_BASECLASSES (type);
503 /* Print out baseclasses such that we don't print
504 duplicates of virtual baseclasses. */
505 if (n_baseclasses > 0)
506 cplus_val_print (type, valaddr, stream, format, recurse+1, pretty, dont_print);
508 if (!len && n_baseclasses == 1)
509 fprintf_filtered (stream, "<No data fields>");
512 extern int inspect_it;
515 for (i = n_baseclasses; i < len; i++)
517 /* Check if static field */
518 if (TYPE_FIELD_STATIC (type, i))
521 fprintf_filtered (stream, ", ");
522 else if (n_baseclasses > 0)
524 fprintf_filtered (stream, "\n");
525 print_spaces_filtered (2 + 2 * recurse, stream);
526 fputs_filtered ("members of ", stream);
527 fputs_filtered (type_name_no_tag (type), stream);
528 fputs_filtered (": ", stream);
534 fprintf_filtered (stream, "\n");
535 print_spaces_filtered (2 + 2 * recurse, stream);
539 wrap_here (n_spaces (2 + 2 * recurse));
543 if (TYPE_CODE (TYPE_FIELD_TYPE (type, i)) == TYPE_CODE_PTR)
544 fputs_filtered ("\"( ptr \"", stream);
546 fputs_filtered ("\"( nodef \"", stream);
547 fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
548 fputs_filtered ("\" \"", stream);
549 fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
550 fputs_filtered ("\") \"", stream);
554 fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
555 fputs_filtered (" = ", stream);
557 if (TYPE_FIELD_PACKED (type, i))
561 /* Bitfields require special handling, especially due to byte
563 v = value_from_longest (TYPE_FIELD_TYPE (type, i),
564 unpack_field_as_long (type, valaddr, i));
566 val_print (TYPE_FIELD_TYPE (type, i), VALUE_CONTENTS (v), 0,
567 stream, format, 0, recurse + 1, pretty);
571 val_print (TYPE_FIELD_TYPE (type, i),
572 valaddr + TYPE_FIELD_BITPOS (type, i) / 8,
573 0, stream, format, 0, recurse + 1, pretty);
578 fprintf_filtered (stream, "\n");
579 print_spaces_filtered (2 * recurse, stream);
582 fprintf_filtered (stream, "}");
585 /* Special val_print routine to avoid printing multiple copies of virtual
589 cplus_val_print (type, valaddr, stream, format, recurse, pretty, dont_print)
595 enum val_prettyprint pretty;
596 struct type **dont_print;
598 struct obstack tmp_obstack;
599 struct type **last_dont_print
600 = (struct type **)obstack_next_free (&dont_print_obstack);
601 int i, n_baseclasses = TYPE_N_BASECLASSES (type);
605 /* If we're at top level, carve out a completely fresh
606 chunk of the obstack and use that until this particular
607 invocation returns. */
608 tmp_obstack = dont_print_obstack;
609 /* Bump up the high-water mark. Now alpha is omega. */
610 obstack_finish (&dont_print_obstack);
613 for (i = 0; i < n_baseclasses; i++)
618 if (BASETYPE_VIA_VIRTUAL (type, i))
620 struct type **first_dont_print
621 = (struct type **)obstack_base (&dont_print_obstack);
623 int j = (struct type **)obstack_next_free (&dont_print_obstack)
627 if (TYPE_BASECLASS (type, i) == first_dont_print[j])
630 obstack_ptr_grow (&dont_print_obstack, TYPE_BASECLASS (type, i));
633 baddr = baseclass_addr (type, i, valaddr, 0, &err);
634 if (err == 0 && baddr == 0)
635 error ("could not find virtual baseclass `%s'\n",
636 type_name_no_tag (TYPE_BASECLASS (type, i)));
638 fprintf_filtered (stream, "\n");
640 print_spaces_filtered (2 + 2 * recurse, stream);
641 fputs_filtered ("<", stream);
642 fputs_filtered (type_name_no_tag (TYPE_BASECLASS (type, i)), stream);
643 fputs_filtered ("> = ", stream);
645 fprintf_filtered (stream, "<invalid address 0x%x>", baddr);
647 val_print_fields (TYPE_BASECLASS (type, i), baddr, stream, format,
649 (struct type **)obstack_base (&dont_print_obstack));
656 /* Free the space used to deal with the printing
657 of this type from top level. */
658 obstack_free (&dont_print_obstack, last_dont_print);
659 /* Reset watermark so that we can continue protecting
660 ourselves from whatever we were protecting ourselves. */
661 dont_print_obstack = tmp_obstack;
665 /* Print data of type TYPE located at VALADDR (within GDB),
666 which came from the inferior at address ADDRESS,
667 onto stdio stream STREAM according to FORMAT
668 (a letter or 0 for natural format). The data at VALADDR
669 is in target byte order.
671 If the data are a string pointer, returns the number of
672 sting characters printed.
674 if DEREF_REF is nonzero, then dereference references,
675 otherwise just print them like pointers.
677 The PRETTY parameter controls prettyprinting. */
680 val_print (type, valaddr, address, stream, format, deref_ref, recurse, pretty)
688 enum val_prettyprint pretty;
690 register unsigned int i;
692 struct type *elttype;
697 if (pretty == Val_pretty_default)
699 pretty = prettyprint ? Val_prettyprint : Val_no_prettyprint;
704 check_stub_type (type);
706 if (TYPE_FLAGS (type) & TYPE_FLAG_STUB)
708 fprintf_filtered (stream, "<unknown struct>");
713 switch (TYPE_CODE (type))
715 case TYPE_CODE_ARRAY:
716 if (TYPE_LENGTH (type) > 0
717 && TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0)
719 elttype = TYPE_TARGET_TYPE (type);
720 eltlen = TYPE_LENGTH (elttype);
721 len = TYPE_LENGTH (type) / eltlen;
723 print_spaces_filtered (2 + 2 * recurse, stream);
724 fprintf_filtered (stream, "{");
725 /* For an array of chars, print with string syntax. */
726 if (eltlen == 1 && TYPE_CODE (elttype) == TYPE_CODE_INT
727 && (format == 0 || format == 's') )
728 print_string (stream, valaddr, len, 0);
731 unsigned int things_printed = 0;
733 /* If this is a virtual function table, print the 0th
734 entry specially, and the rest of the members normally. */
735 if (is_vtbl_ptr_type (elttype))
737 fprintf_filtered (stream, "%d vtable entries", len-1);
743 for (; i < len && things_printed < print_max; i++)
745 /* Position of the array element we are examining to see
746 whether it is repeated. */
748 /* Number of repetitions we have detected so far. */
754 fprintf_filtered (stream, ",\n");
755 print_spaces_filtered (2 + 2 * recurse, stream);
758 fprintf_filtered (stream, ", ");
759 wrap_here (n_spaces (2 + 2 * recurse));
764 && !bcmp (valaddr + i * eltlen,
765 valaddr + rep1 * eltlen, eltlen))
771 if (reps > REPEAT_COUNT_THRESHOLD)
773 val_print (elttype, valaddr + i * eltlen,
774 0, stream, format, deref_ref,
775 recurse + 1, pretty);
776 fprintf_filtered (stream, " <repeats %u times>", reps);
778 things_printed += REPEAT_COUNT_THRESHOLD;
782 val_print (elttype, valaddr + i * eltlen,
783 0, stream, format, deref_ref,
784 recurse + 1, pretty);
789 fprintf_filtered (stream, "...");
791 fprintf_filtered (stream, "}");
794 /* Array of unspecified length: treat like pointer to first elt. */
795 valaddr = (char *) &address;
798 if (format && format != 's')
800 print_scalar_formatted (valaddr, type, format, 0, stream);
803 if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_METHOD)
805 struct type *domain = TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (type));
811 addr = unpack_pointer (lookup_pointer_type (builtin_type_void),
813 if (addr < 128) /* FIXME! What is this 128? */
815 len = TYPE_NFN_FIELDS (domain);
816 for (i = 0; i < len; i++)
818 f = TYPE_FN_FIELDLIST1 (domain, i);
819 len2 = TYPE_FN_FIELDLIST_LENGTH (domain, i);
821 for (j = 0; j < len2; j++)
824 if (TYPE_FN_FIELD_VOFFSET (f, j) == addr)
834 struct symbol *sym = find_pc_function (addr);
836 error ("invalid pointer to member function");
837 len = TYPE_NFN_FIELDS (domain);
838 for (i = 0; i < len; i++)
840 f = TYPE_FN_FIELDLIST1 (domain, i);
841 len2 = TYPE_FN_FIELDLIST_LENGTH (domain, i);
843 for (j = 0; j < len2; j++)
846 if (!strcmp (SYMBOL_NAME (sym), TYPE_FN_FIELD_PHYSNAME (f, j)))
854 fprintf_filtered (stream, "&");
855 type_print_varspec_prefix (TYPE_FN_FIELD_TYPE (f, j), stream, 0, 0);
856 fprintf (stream, kind);
857 if (TYPE_FN_FIELD_PHYSNAME (f, j)[0] == '_'
858 && TYPE_FN_FIELD_PHYSNAME (f, j)[1] == CPLUS_MARKER)
859 type_print_method_args
860 (TYPE_FN_FIELD_ARGS (f, j) + 1, "~",
861 TYPE_FN_FIELDLIST_NAME (domain, i), 0, stream);
863 type_print_method_args
864 (TYPE_FN_FIELD_ARGS (f, j), "",
865 TYPE_FN_FIELDLIST_NAME (domain, i), 0, stream);
868 fprintf_filtered (stream, "(");
869 type_print (type, "", stream, -1);
870 fprintf_filtered (stream, ") %d", (int) addr >> 3);
872 else if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_MEMBER)
874 struct type *domain = TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (type));
876 /* VAL is a byte offset into the structure type DOMAIN.
877 Find the name of the field for that offset and
881 len = TYPE_NFIELDS (domain);
882 /* @@ Make VAL into bit offset */
883 val = unpack_long (builtin_type_int, valaddr) << 3;
884 for (i = TYPE_N_BASECLASSES (domain); i < len; i++)
886 int bitpos = TYPE_FIELD_BITPOS (domain, i);
890 if (val < bitpos && i != 0)
892 /* Somehow pointing into a field. */
894 extra = (val - TYPE_FIELD_BITPOS (domain, i));
904 fprintf_filtered (stream, "&");
905 type_print_base (domain, stream, 0, 0);
906 fprintf_filtered (stream, "::");
907 fputs_filtered (TYPE_FIELD_NAME (domain, i), stream);
909 fprintf_filtered (stream, " + %d bytes", extra);
911 fprintf_filtered (stream, " (offset in bits)");
914 fprintf_filtered (stream, "%d", val >> 3);
918 CORE_ADDR addr = unpack_pointer (type, valaddr);
919 elttype = TYPE_TARGET_TYPE (type);
921 if (TYPE_CODE (elttype) == TYPE_CODE_FUNC)
923 /* Try to print what function it points to. */
924 print_address_demangle (addr, stream, demangle);
925 /* Return value is irrelevant except for string pointers. */
929 if (addressprint && format != 's')
930 fprintf_filtered (stream, "0x%x", addr);
932 /* For a pointer to char or unsigned char,
933 also print the string pointed to, unless pointer is null. */
934 i = 0; /* Number of characters printed. */
935 if (TYPE_LENGTH (elttype) == 1
936 && TYPE_CODE (elttype) == TYPE_CODE_INT
937 && (format == 0 || format == 's')
939 /* If print_max is UINT_MAX, the alloca below will fail.
940 In that case don't try to print the string. */
941 && print_max < UINT_MAX)
943 int first_addr_err = 0;
946 /* Get first character. */
947 errcode = target_read_memory (addr, (char *)&c, 1);
950 /* First address out of bounds. */
956 char *string = (char *) alloca (print_max);
958 /* If the loop ends by us hitting print_max characters,
959 we need to have elipses at the end. */
960 int force_ellipses = 1;
962 /* This loop always fetches print_max characters, even
963 though print_string might want to print more or fewer
964 (with repeated characters). This is so that
965 we don't spend forever fetching if we print
966 a long string consisting of the same character
967 repeated. Also so we can do it all in one memory
968 operation, which is faster. However, this will be
969 slower if print_max is set high, e.g. if you set
970 print_max to 1000, not only will it take a long
971 time to fetch short strings, but if you are near
972 the end of the address space, it might not work. */
974 errcode = target_read_memory (addr, string, print_max);
977 /* Try reading just one character. If that succeeds,
978 assume we hit the end of the address space, but
979 the initial part of the string is probably safe. */
981 errcode = target_read_memory (addr, x, 1);
986 for (i = 0; i < print_max; i++)
987 if (string[i] == '\0')
995 fputs_filtered (" ", stream);
996 print_string (stream, string, i, force_ellipses);
1003 fprintf_filtered (stream,
1004 (" <Address 0x%x out of bounds>"
1010 if (errcode >= sys_nerr || errcode < 0)
1011 error ("Error reading memory address 0x%x: unknown error (%d).",
1014 error ("Error reading memory address 0x%x: %s.",
1015 addr + i, sys_errlist[errcode]);
1021 else /* print vtbl's nicely */
1022 if (is_vtbl_member(type))
1024 CORE_ADDR vt_address = unpack_pointer (type, valaddr);
1026 struct minimal_symbol *msymbol =
1027 lookup_minimal_symbol_by_pc (vt_address);
1028 if ((msymbol != NULL) && (vt_address == msymbol -> address))
1030 fputs_filtered (" <", stream);
1031 fputs_demangled (msymbol -> name, stream, 1);
1032 fputs_filtered (">", stream);
1038 vt_val = value_at (TYPE_TARGET_TYPE (type), vt_address);
1039 val_print (VALUE_TYPE (vt_val), VALUE_CONTENTS (vt_val),
1040 VALUE_ADDRESS (vt_val), stream, format,
1041 deref_ref, recurse + 1, pretty);
1044 fprintf_filtered (stream, "\n");
1045 print_spaces_filtered (2 + 2 * recurse, stream);
1050 /* Return number of characters printed, plus one for the
1051 terminating null if we have "reached the end". */
1052 return i + (print_max && i != print_max);
1056 case TYPE_CODE_MEMBER:
1057 error ("not implemented: member type in val_print");
1063 fprintf_filtered (stream, "@0x%lx",
1064 unpack_long (builtin_type_int, valaddr));
1066 fputs_filtered (": ", stream);
1068 /* De-reference the reference. */
1071 if (TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_UNDEF)
1075 (TYPE_TARGET_TYPE (type),
1076 unpack_pointer (lookup_pointer_type (builtin_type_void),
1078 val_print (VALUE_TYPE (deref_val), VALUE_CONTENTS (deref_val),
1079 VALUE_ADDRESS (deref_val), stream, format,
1080 deref_ref, recurse + 1, pretty);
1083 fputs_filtered ("???", stream);
1087 case TYPE_CODE_UNION:
1088 if (recurse && !unionprint)
1090 fprintf_filtered (stream, "{...}");
1094 case TYPE_CODE_STRUCT:
1095 if (vtblprint && is_vtbl_ptr_type(type))
1097 /* Print the unmangled name if desired. */
1098 print_address_demangle(*((int *) (valaddr + /* FIXME bytesex */
1099 TYPE_FIELD_BITPOS (type, VTBL_FNADDR_OFFSET) / 8)),
1103 val_print_fields (type, valaddr, stream, format, recurse, pretty, 0);
1106 case TYPE_CODE_ENUM:
1109 print_scalar_formatted (valaddr, type, format, 0, stream);
1112 len = TYPE_NFIELDS (type);
1113 val = unpack_long (builtin_type_int, valaddr);
1114 for (i = 0; i < len; i++)
1117 if (val == TYPE_FIELD_BITPOS (type, i))
1121 fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
1124 fprintf_filtered (stream, "%lld", val);
1126 fprintf_filtered (stream, "%ld", val);
1130 case TYPE_CODE_FUNC:
1133 print_scalar_formatted (valaddr, type, format, 0, stream);
1136 /* FIXME, we should consider, at least for ANSI C language, eliminating
1137 the distinction made between FUNCs and POINTERs to FUNCs. */
1138 fprintf_filtered (stream, "{");
1139 type_print (type, "", stream, -1);
1140 fprintf_filtered (stream, "} ");
1141 /* Try to print what function it points to, and its address. */
1142 print_address_demangle (address, stream, demangle);
1146 if (format || output_format)
1148 print_scalar_formatted (valaddr, type,
1149 format? format: output_format,
1153 if (TYPE_LENGTH (type) > sizeof (LONGEST))
1155 if (TYPE_UNSIGNED (type))
1157 /* First figure out whether the number in fact has zeros
1158 in all its bytes more significant than least significant
1159 sizeof (LONGEST) ones. */
1161 /* Pointer to first (i.e. lowest address) nonzero character. */
1163 len = TYPE_LENGTH (type);
1165 #if TARGET_BYTE_ORDER == BIG_ENDIAN
1167 len > sizeof (LONGEST)
1168 && p < valaddr + TYPE_LENGTH (type);
1170 #else /* Little endian. */
1171 first_addr = valaddr;
1172 for (p = valaddr + TYPE_LENGTH (type);
1173 len > sizeof (LONGEST) && p >= valaddr;
1175 #endif /* Little endian. */
1182 #if TARGET_BYTE_ORDER == BIG_ENDIAN
1186 if (len <= sizeof (LONGEST))
1188 /* We can print it in decimal. */
1191 #if defined (LONG_LONG)
1196 unpack_long (BUILTIN_TYPE_LONGEST, first_addr));
1200 /* It is big, so print it in hex. */
1201 print_hex_chars (stream, (unsigned char *)first_addr, len);
1206 /* Signed. One could assume two's complement (a reasonable
1207 assumption, I think) and do better than this. */
1208 print_hex_chars (stream, (unsigned char *)valaddr,
1209 TYPE_LENGTH (type));
1213 #ifdef PRINT_TYPELESS_INTEGER
1214 PRINT_TYPELESS_INTEGER (stream, type, unpack_long (type, valaddr));
1217 fprintf_filtered (stream,
1218 TYPE_UNSIGNED (type) ? "%u" : "%d",
1219 unpack_long (type, valaddr));
1221 fprintf_filtered (stream,
1222 TYPE_UNSIGNED (type) ? "%llu" : "%lld",
1223 unpack_long (type, valaddr));
1227 if (TYPE_LENGTH (type) == 1)
1229 fprintf_filtered (stream, " '");
1230 printchar ((unsigned char) unpack_long (type, valaddr),
1232 fprintf_filtered (stream, "'");
1238 print_scalar_formatted (valaddr, type, format, 0, stream);
1240 print_floating (valaddr, type, stream);
1243 case TYPE_CODE_VOID:
1244 fprintf_filtered (stream, "void");
1247 case TYPE_CODE_UNDEF:
1248 /* This happens (without TYPE_FLAG_STUB set) on systems which don't use
1249 dbx xrefs (NO_DBX_XREFS in gcc) if a file has a "struct foo *bar"
1250 and no complete type for struct foo in that file. */
1251 fprintf_filtered (stream, "<unknown struct>");
1254 case TYPE_CODE_ERROR:
1255 fprintf_filtered (stream, "?");
1258 case TYPE_CODE_RANGE:
1259 /* FIXME, we should not ever have to print one of these yet. */
1260 fprintf_filtered (stream, "<range type>");
1264 error ("Invalid type code in symbol table.");
1270 /* Print a description of a type in the format of a
1271 typedef for the current language.
1272 NEW is the new name for a type TYPE. */
1274 typedef_print (type, new, stream)
1279 switch (current_language->la_language)
1283 case language_cplus:
1284 fprintf_filtered(stream, "typedef ");
1285 type_print(type,"",stream,0);
1286 if(TYPE_NAME ((SYMBOL_TYPE (new))) == 0
1287 || 0 != strcmp (TYPE_NAME ((SYMBOL_TYPE (new))),
1289 fprintf_filtered(stream, " %s", SYMBOL_NAME(new));
1294 fprintf_filtered(stream, "TYPE ");
1295 if(!TYPE_NAME(SYMBOL_TYPE(new)) ||
1296 strcmp (TYPE_NAME(SYMBOL_TYPE(new)),
1298 fprintf_filtered(stream, "%s = ", SYMBOL_NAME(new));
1300 fprintf_filtered(stream, "<builtin> = ");
1301 type_print(type,"",stream,0);
1305 error("Language not supported.");
1307 fprintf_filtered(stream, ";\n");
1311 /* Print a description of a type TYPE
1312 in the form of a declaration of a variable named VARSTRING.
1313 (VARSTRING is demangled if necessary.)
1314 Output goes to STREAM (via stdio).
1315 If SHOW is positive, we show the contents of the outermost level
1316 of structure even if there is a type name that could be used instead.
1317 If SHOW is negative, we never show the details of elements' types. */
1320 type_print (type, varstring, stream, show)
1326 type_print_1 (type, varstring, stream, show, 0);
1329 /* LEVEL is the depth to indent lines by. */
1332 type_print_1 (type, varstring, stream, show, level)
1339 register enum type_code code;
1340 type_print_base (type, stream, show, level);
1341 code = TYPE_CODE (type);
1342 if ((varstring && *varstring)
1344 /* Need a space if going to print stars or brackets;
1345 but not if we will print just a type name. */
1346 ((show > 0 || TYPE_NAME (type) == 0)
1348 (code == TYPE_CODE_PTR || code == TYPE_CODE_FUNC
1349 || code == TYPE_CODE_METHOD
1350 || code == TYPE_CODE_ARRAY
1351 || code == TYPE_CODE_MEMBER
1352 || code == TYPE_CODE_REF)))
1353 fprintf_filtered (stream, " ");
1354 type_print_varspec_prefix (type, stream, show, 0);
1355 fputs_demangled (varstring, stream, -1); /* Print demangled name
1356 without arguments */
1357 type_print_varspec_suffix (type, stream, show, 0);
1360 /* Print the method arguments ARGS to the file STREAM. */
1362 type_print_method_args (args, prefix, varstring, staticp, stream)
1364 char *prefix, *varstring;
1370 fputs_demangled (prefix, stream, 1);
1371 fputs_demangled (varstring, stream, 1);
1372 fputs_filtered (" (", stream);
1373 if (args && args[!staticp] && args[!staticp]->code != TYPE_CODE_VOID)
1375 i = !staticp; /* skip the class variable */
1378 type_print (args[i++], "", stream, 0);
1381 fprintf_filtered (stream, " ...");
1384 else if (args[i]->code != TYPE_CODE_VOID)
1386 fprintf_filtered (stream, ", ");
1391 fprintf_filtered (stream, ")");
1394 /* If TYPE is a derived type, then print out derivation
1395 information. Print out all layers of the type heirarchy
1396 until we encounter one with multiple inheritance.
1397 At that point, print out that ply, and return. */
1399 type_print_derivation_info (stream, type)
1404 int i, n_baseclasses = TYPE_N_BASECLASSES (type);
1405 struct type *basetype = 0;
1407 while (type && n_baseclasses > 0)
1409 /* Not actually sure about this one -- Bryan. */
1410 check_stub_type (type);
1412 fprintf_filtered (stream, ": ");
1415 basetype = TYPE_BASECLASS (type, i);
1416 if (name = type_name_no_tag (basetype))
1418 fprintf_filtered (stream, "%s%s ",
1419 BASETYPE_VIA_PUBLIC(type, i) ? "public" : "private",
1420 BASETYPE_VIA_VIRTUAL(type, i) ? " virtual" : "");
1421 fputs_filtered (name, stream);
1424 if (i >= n_baseclasses)
1426 fprintf_filtered (stream, ", ");
1429 fprintf_filtered (stream, " ");
1430 if (n_baseclasses != 1)
1432 n_baseclasses = TYPE_N_BASECLASSES (basetype);
1437 /* Print any asterisks or open-parentheses needed before the
1438 variable name (to describe its type).
1440 On outermost call, pass 0 for PASSED_A_PTR.
1441 On outermost call, SHOW > 0 means should ignore
1442 any typename for TYPE and show its details.
1443 SHOW is always zero on recursive calls. */
1446 type_print_varspec_prefix (type, stream, show, passed_a_ptr)
1455 if (TYPE_NAME (type) && show <= 0)
1460 switch (TYPE_CODE (type))
1463 type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 1);
1464 fprintf_filtered (stream, "*");
1467 case TYPE_CODE_MEMBER:
1469 fprintf_filtered (stream, "(");
1470 type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0,
1472 fprintf_filtered (stream, " ");
1473 type_print_base (TYPE_DOMAIN_TYPE (type), stream, 0,
1475 fprintf_filtered (stream, "::");
1478 case TYPE_CODE_METHOD:
1480 fprintf (stream, "(");
1481 type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0,
1485 fprintf_filtered (stream, " ");
1486 type_print_base (TYPE_DOMAIN_TYPE (type), stream, 0,
1488 fprintf_filtered (stream, "::");
1493 type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 1);
1494 fprintf_filtered (stream, "&");
1497 case TYPE_CODE_FUNC:
1498 type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0,
1501 fprintf_filtered (stream, "(");
1504 case TYPE_CODE_ARRAY:
1505 type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0,
1508 fprintf_filtered (stream, "(");
1511 case TYPE_CODE_UNDEF:
1512 case TYPE_CODE_STRUCT:
1513 case TYPE_CODE_UNION:
1514 case TYPE_CODE_ENUM:
1517 case TYPE_CODE_VOID:
1518 case TYPE_CODE_ERROR:
1519 case TYPE_CODE_CHAR:
1520 case TYPE_CODE_BOOL:
1521 /* These types need no prefix. They are listed here so that
1522 gcc -Wall will reveal any types that haven't been handled. */
1527 /* Print any array sizes, function arguments or close parentheses
1528 needed after the variable name (to describe its type).
1529 Args work like type_print_varspec_prefix. */
1532 type_print_varspec_suffix (type, stream, show, passed_a_ptr)
1541 if (TYPE_NAME (type) && show <= 0)
1546 switch (TYPE_CODE (type))
1548 case TYPE_CODE_ARRAY:
1550 fprintf_filtered (stream, ")");
1552 fprintf_filtered (stream, "[");
1553 if (TYPE_LENGTH (type) > 0
1554 && TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0)
1555 fprintf_filtered (stream, "%d",
1557 / TYPE_LENGTH (TYPE_TARGET_TYPE (type))));
1558 fprintf_filtered (stream, "]");
1560 type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0,
1564 case TYPE_CODE_MEMBER:
1566 fprintf_filtered (stream, ")");
1567 type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0);
1570 case TYPE_CODE_METHOD:
1572 fprintf_filtered (stream, ")");
1573 type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0);
1577 struct type **args = TYPE_ARG_TYPES (type);
1579 fprintf_filtered (stream, "(");
1581 fprintf_filtered (stream, "...");
1582 else for (i = 1; args[i] != 0 && args[i]->code != TYPE_CODE_VOID; i++)
1584 type_print_1 (args[i], "", stream, -1, 0);
1586 fprintf_filtered (stream, "...");
1587 else if (args[i+1]->code != TYPE_CODE_VOID) {
1588 fprintf_filtered (stream, ",");
1592 fprintf_filtered (stream, ")");
1598 type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 1);
1601 case TYPE_CODE_FUNC:
1602 type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0,
1605 fprintf_filtered (stream, ")");
1606 fprintf_filtered (stream, "()");
1609 case TYPE_CODE_UNDEF:
1610 case TYPE_CODE_STRUCT:
1611 case TYPE_CODE_UNION:
1612 case TYPE_CODE_ENUM:
1615 case TYPE_CODE_VOID:
1616 case TYPE_CODE_ERROR:
1617 case TYPE_CODE_CHAR:
1618 case TYPE_CODE_BOOL:
1619 /* These types do not need a suffix. They are listed so that
1620 gcc -Wall will report types that may not have been considered. */
1625 /* Print the name of the type (or the ultimate pointer target,
1626 function value or array element), or the description of a
1629 SHOW nonzero means don't print this type as just its name;
1630 show its real definition even if it has a name.
1631 SHOW zero means print just typename or struct tag if there is one
1632 SHOW negative means abbreviate structure elements.
1633 SHOW is decremented for printing of structure elements.
1635 LEVEL is the depth to indent by.
1636 We increase it for some recursive calls. */
1639 type_print_base (type, stream, show, level)
1648 register int lastval;
1655 fprintf_filtered (stream, "<type unknown>");
1659 if (TYPE_NAME (type) && show <= 0)
1661 fputs_filtered (TYPE_NAME (type), stream);
1665 switch (TYPE_CODE (type))
1667 case TYPE_CODE_ARRAY:
1669 case TYPE_CODE_MEMBER:
1671 case TYPE_CODE_FUNC:
1672 case TYPE_CODE_METHOD:
1673 type_print_base (TYPE_TARGET_TYPE (type), stream, show, level);
1676 case TYPE_CODE_STRUCT:
1677 fprintf_filtered (stream, "struct ");
1680 case TYPE_CODE_UNION:
1681 fprintf_filtered (stream, "union ");
1683 if (name = type_name_no_tag (type))
1685 fputs_filtered (name, stream);
1686 fputs_filtered (" ", stream);
1690 fprintf_filtered (stream, "{...}");
1693 check_stub_type (type);
1695 type_print_derivation_info (stream, type);
1697 fprintf_filtered (stream, "{");
1698 len = TYPE_NFIELDS (type);
1700 fprintf_filtered (stream, "\n");
1703 if (TYPE_FLAGS (type) & TYPE_FLAG_STUB)
1704 fprintf_filtered (stream, "<incomplete type>\n");
1706 fprintf_filtered (stream, "<no data fields>\n");
1709 /* If there is a base class for this type,
1710 do not print the field that it occupies. */
1711 for (i = TYPE_N_BASECLASSES (type); i < len; i++)
1714 /* Don't print out virtual function table. */
1715 if ((TYPE_FIELD_NAME (type, i))[5] == CPLUS_MARKER &&
1716 !strncmp (TYPE_FIELD_NAME (type, i), "_vptr", 5))
1719 print_spaces_filtered (level + 4, stream);
1720 if (TYPE_FIELD_STATIC (type, i))
1722 fprintf_filtered (stream, "static ");
1724 type_print_1 (TYPE_FIELD_TYPE (type, i),
1725 TYPE_FIELD_NAME (type, i),
1726 stream, show - 1, level + 4);
1727 if (!TYPE_FIELD_STATIC (type, i)
1728 && TYPE_FIELD_PACKED (type, i))
1730 /* It is a bitfield. This code does not attempt
1731 to look at the bitpos and reconstruct filler,
1732 unnamed fields. This would lead to misleading
1733 results if the compiler does not put out fields
1734 for such things (I don't know what it does). */
1735 fprintf_filtered (stream, " : %d",
1736 TYPE_FIELD_BITSIZE (type, i));
1738 fprintf_filtered (stream, ";\n");
1741 /* C++: print out the methods */
1742 len = TYPE_NFN_FIELDS (type);
1743 if (len) fprintf_filtered (stream, "\n");
1744 for (i = 0; i < len; i++)
1746 struct fn_field *f = TYPE_FN_FIELDLIST1 (type, i);
1747 int j, len2 = TYPE_FN_FIELDLIST_LENGTH (type, i);
1748 char *method_name = TYPE_FN_FIELDLIST_NAME (type, i);
1749 int is_constructor = name && strcmp(method_name, name) == 0;
1750 for (j = 0; j < len2; j++)
1753 print_spaces_filtered (level + 4, stream);
1754 if (TYPE_FN_FIELD_VIRTUAL_P (f, j))
1755 fprintf_filtered (stream, "virtual ");
1756 else if (TYPE_FN_FIELD_STATIC_P (f, j))
1757 fprintf_filtered (stream, "static ");
1758 if (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)) == 0)
1760 /* Keep GDB from crashing here. */
1761 fprintf (stream, "<undefined type> %s;\n",
1762 TYPE_FN_FIELD_PHYSNAME (f, j));
1765 else if (!is_constructor)
1767 type_print (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)),
1769 fputs_filtered (" ", stream);
1771 if (TYPE_FN_FIELD_STUB (f, j))
1773 /* Build something we can demangle. */
1774 char *mangled_name = gdb_mangle_name (type, i, j);
1775 char *demangled_name = cplus_demangle (mangled_name, 1);
1776 if (demangled_name == 0)
1777 fprintf_filtered (stream, "<badly mangled name %s>",
1781 fprintf_filtered (stream, "%s",
1782 strchr (demangled_name, ':') + 2);
1783 free (demangled_name);
1785 free (mangled_name);
1787 else if (TYPE_FN_FIELD_PHYSNAME (f, j)[0] == '_'
1788 && TYPE_FN_FIELD_PHYSNAME (f, j)[1] == CPLUS_MARKER)
1789 type_print_method_args
1790 (TYPE_FN_FIELD_ARGS (f, j) + 1, "~",
1791 method_name, 0, stream);
1793 type_print_method_args
1794 (TYPE_FN_FIELD_ARGS (f, j), "",
1796 TYPE_FN_FIELD_STATIC_P (f, j), stream);
1798 fprintf_filtered (stream, ";\n");
1802 print_spaces_filtered (level, stream);
1803 fprintf_filtered (stream, "}");
1807 case TYPE_CODE_ENUM:
1808 fprintf_filtered (stream, "enum ");
1809 if (name = type_name_no_tag (type))
1811 fputs_filtered (name, stream);
1812 fputs_filtered (" ", stream);
1816 fprintf_filtered (stream, "{...}");
1819 fprintf_filtered (stream, "{");
1820 len = TYPE_NFIELDS (type);
1822 for (i = 0; i < len; i++)
1825 if (i) fprintf_filtered (stream, ", ");
1827 fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
1828 if (lastval != TYPE_FIELD_BITPOS (type, i))
1830 fprintf_filtered (stream, " = %d", TYPE_FIELD_BITPOS (type, i));
1831 lastval = TYPE_FIELD_BITPOS (type, i);
1835 fprintf_filtered (stream, "}");
1841 if (TYPE_LENGTH (type) <= sizeof (LONGEST))
1843 if (TYPE_UNSIGNED (type))
1844 name = unsigned_type_table[TYPE_LENGTH (type)];
1846 name = signed_type_table[TYPE_LENGTH (type)];
1849 fputs_filtered (name, stream);
1851 fprintf_filtered (stream, "<%d bit integer>",
1852 TYPE_LENGTH (type) * TARGET_CHAR_BIT);
1856 name = float_type_table[TYPE_LENGTH (type)];
1857 fputs_filtered (name, stream);
1860 case TYPE_CODE_VOID:
1861 fprintf_filtered (stream, "void");
1864 case TYPE_CODE_UNDEF:
1865 fprintf_filtered (stream, "struct <unknown>");
1868 case TYPE_CODE_ERROR:
1869 fprintf_filtered (stream, "<unknown type>");
1872 case TYPE_CODE_RANGE:
1873 /* This should not occur */
1874 fprintf_filtered (stream, "<range type>");
1878 error ("Invalid type code in symbol table.");
1883 /* Validate an input or output radix setting, and make sure the user
1884 knows what they really did here. Radix setting is confusing, e.g.
1885 setting the input radix to "10" never changes it! */
1889 set_input_radix (args, from_tty, c)
1892 struct cmd_list_element *c;
1894 unsigned radix = *(unsigned *)c->var;
1897 printf_filtered ("Input radix set to decimal %d, hex %x, octal %o\n",
1898 radix, radix, radix);
1904 set_output_radix (args, from_tty, c)
1907 struct cmd_list_element *c;
1909 unsigned radix = *(unsigned *)c->var;
1912 printf_filtered ("Output radix set to decimal %d, hex %x, octal %o\n",
1913 radix, radix, radix);
1915 /* FIXME, we really should be able to validate the setting BEFORE
1920 output_format = 'x';
1926 output_format = 'o'; /* octal */
1930 error ("Unsupported radix ``decimal %d''; using decimal output",
1937 set_radix (arg, from_tty, c)
1940 struct cmd_list_element *c;
1942 unsigned radix = *(unsigned *)c->var;
1945 printf_filtered ("Radix set to decimal %d, hex %x, octal %o\n",
1946 radix, radix, radix);
1948 input_radix = radix;
1949 output_radix = radix;
1951 set_output_radix (arg, 0, c);
1954 struct cmd_list_element *setprintlist = NULL;
1955 struct cmd_list_element *showprintlist = NULL;
1959 set_print (arg, from_tty)
1964 "\"set print\" must be followed by the name of a print subcommand.\n");
1965 help_list (setprintlist, "set print ", -1, stdout);
1970 show_print (args, from_tty)
1974 cmd_show_list (showprintlist, from_tty, "");
1978 _initialize_valprint ()
1980 struct cmd_list_element *c;
1982 add_prefix_cmd ("print", no_class, set_print,
1983 "Generic command for setting how things print.",
1984 &setprintlist, "set print ", 0, &setlist);
1985 add_alias_cmd ("p", "print", no_class, 1, &setlist);
1986 add_alias_cmd ("pr", "print", no_class, 1, &setlist); /* prefer set print
1988 add_prefix_cmd ("print", no_class, show_print,
1989 "Generic command for showing print settings.",
1990 &showprintlist, "show print ", 0, &showlist);
1991 add_alias_cmd ("p", "print", no_class, 1, &showlist);
1992 add_alias_cmd ("pr", "print", no_class, 1, &showlist);
1995 (add_set_cmd ("elements", no_class, var_uinteger, (char *)&print_max,
1996 "Set limit on string chars or array elements to print.\n\
1997 \"set print elements 0\" causes there to be no limit.",
2002 (add_set_cmd ("pretty", class_support, var_boolean, (char *)&prettyprint,
2003 "Set prettyprinting of structures.",
2008 (add_set_cmd ("union", class_support, var_boolean, (char *)&unionprint,
2009 "Set printing of unions interior to structures.",
2014 (add_set_cmd ("vtbl", class_support, var_boolean, (char *)&vtblprint,
2015 "Set printing of C++ virtual function tables.",
2020 (add_set_cmd ("array", class_support, var_boolean, (char *)&arrayprint,
2021 "Set prettyprinting of arrays.",
2026 (add_set_cmd ("object", class_support, var_boolean, (char *)&objectprint,
2027 "Set printing of object's derived type based on vtable info.",
2032 (add_set_cmd ("address", class_support, var_boolean, (char *)&addressprint,
2033 "Set printing of addresses.",
2038 /* The "show radix" cmd isn't good enough to show two separate values.
2039 The rest of the code works, but the show part is confusing, so don't
2040 let them be set separately 'til we work out "show". */
2041 c = add_set_cmd ("input-radix", class_support, var_uinteger,
2042 (char *)&input_radix,
2043 "Set default input radix for entering numbers.",
2045 add_show_from_set (c, &showlist);
2046 c->function = set_input_radix;
2048 c = add_set_cmd ("output-radix", class_support, var_uinteger,
2049 (char *)&output_radix,
2050 "Set default output radix for printing of values.",
2052 add_show_from_set (c, &showlist);
2053 c->function = set_output_radix;
2056 c = add_set_cmd ("radix", class_support, var_uinteger,
2057 (char *)&output_radix,
2058 "Set default input and output number radix.",
2060 add_show_from_set (c, &showlist);
2061 c->function.sfunc = set_radix;
2063 /* Give people the defaults which they are used to. */
2073 /* Initialize the names of the various types based on their lengths on
2074 the target, in bits. Note that ordering is important, so that for example,
2075 if ints and longs are the same size, that size will default to "int". */
2077 unsigned_type_table = (char **)
2078 xmalloc ((1 + (TARGET_LONG_LONG_BIT/TARGET_CHAR_BIT)) * sizeof (char *));
2079 bzero (unsigned_type_table, (1 + (TARGET_LONG_LONG_BIT/TARGET_CHAR_BIT)));
2080 unsigned_type_table[TARGET_CHAR_BIT/TARGET_CHAR_BIT] = "unsigned char";
2081 unsigned_type_table[TARGET_SHORT_BIT/TARGET_CHAR_BIT] = "unsigned short";
2082 unsigned_type_table[TARGET_LONG_LONG_BIT/TARGET_CHAR_BIT] = "unsigned long long";
2083 unsigned_type_table[TARGET_LONG_BIT/TARGET_CHAR_BIT] = "unsigned long";
2084 unsigned_type_table[TARGET_INT_BIT/TARGET_CHAR_BIT] = "unsigned int";
2086 signed_type_table = (char **)
2087 xmalloc ((1 + (TARGET_LONG_LONG_BIT/TARGET_CHAR_BIT)) * sizeof (char *));
2088 bzero (signed_type_table, (1 + (TARGET_LONG_LONG_BIT/TARGET_CHAR_BIT)));
2089 signed_type_table[TARGET_CHAR_BIT/TARGET_CHAR_BIT] = "char";
2090 signed_type_table[TARGET_SHORT_BIT/TARGET_CHAR_BIT] = "short";
2091 signed_type_table[TARGET_LONG_LONG_BIT/TARGET_CHAR_BIT] = "long long";
2092 signed_type_table[TARGET_LONG_BIT/TARGET_CHAR_BIT] = "long";
2093 signed_type_table[TARGET_INT_BIT/TARGET_CHAR_BIT] = "int";
2095 float_type_table = (char **)
2096 xmalloc ((1 + (TARGET_LONG_DOUBLE_BIT/TARGET_CHAR_BIT)) * sizeof (char *));
2097 bzero (float_type_table, (1 + (TARGET_LONG_DOUBLE_BIT/TARGET_CHAR_BIT)));
2098 float_type_table[TARGET_FLOAT_BIT/TARGET_CHAR_BIT] = "float";
2099 float_type_table[TARGET_DOUBLE_COMPLEX_BIT/TARGET_CHAR_BIT] = "double complex";
2100 float_type_table[TARGET_COMPLEX_BIT/TARGET_CHAR_BIT] = "complex";
2101 float_type_table[TARGET_LONG_DOUBLE_BIT/TARGET_CHAR_BIT] = "long double";
2102 float_type_table[TARGET_DOUBLE_BIT/TARGET_CHAR_BIT] = "double";
2104 obstack_begin (&dont_print_obstack, 32 * sizeof (struct type *));