1 /* Print values for GDB, the GNU debugger.
2 Copyright 1986, 1988, 1989, 1991 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
34 /* Prototypes for local functions */
37 print_string PARAMS ((FILE *, char *, unsigned int, int));
40 show_print PARAMS ((char *, int));
43 set_print PARAMS ((char *, int));
46 set_radix PARAMS ((char *, int, struct cmd_list_element *));
49 set_output_radix PARAMS ((char *, int, struct cmd_list_element *));
52 type_print_base PARAMS ((struct type *, FILE *, int, int));
55 type_print_args PARAMS ((struct type *, FILE *));
58 type_print_varspec_suffix PARAMS ((struct type *, FILE *, int, int, int));
61 type_print_varspec_prefix PARAMS ((struct type *, FILE *, int, int));
64 type_print_derivation_info PARAMS ((FILE *, struct type *));
67 type_print_method_args PARAMS ((struct type **, char *, char *, int, FILE *));
70 cplus_val_print PARAMS ((struct type *, char *, FILE *, int, int,
71 enum val_prettyprint, struct type **));
74 val_print_fields PARAMS ((struct type *, char *, FILE *, int, int,
75 enum val_prettyprint, struct type **));
78 is_vtbl_member PARAMS ((struct type *));
81 is_vtbl_ptr_type PARAMS ((struct type *));
84 print_hex_chars PARAMS ((FILE *, unsigned char *, unsigned));
86 extern int demangle; /* whether to print C++ syms raw or source-form */
88 /* Maximum number of chars to print for a string pointer value
89 or vector contents, or UINT_MAX for no limit. */
91 static unsigned int print_max;
93 /* Default input and output radixes, and output format letter. */
95 unsigned input_radix = 10;
96 unsigned output_radix = 10;
97 int output_format = 0;
99 /* Print repeat counts if there are more than this
100 many repetitions of an element in an array. */
101 #define REPEAT_COUNT_THRESHOLD 10
103 /* Define a mess of print controls. */
105 int prettyprint; /* Controls pretty printing of structures */
106 int vtblprint; /* Controls printing of vtbl's */
107 int unionprint; /* Controls printing of nested unions. */
108 int arrayprint; /* Controls pretty printing of arrays. */
109 int addressprint; /* Controls pretty printing of addresses. */
110 int objectprint; /* Controls looking up an object's derived type
111 using what we find in its vtables. */
113 struct obstack dont_print_obstack;
116 /* Print the character string STRING, printing at most LENGTH characters.
117 Printing stops early if the number hits print_max; repeat counts
118 are printed as appropriate. Print ellipses at the end if we
119 had to stop before printing LENGTH characters, or if FORCE_ELLIPSES. */
122 print_string (stream, string, length, force_ellipses)
128 register unsigned int i;
129 unsigned int things_printed = 0;
132 extern int inspect_it;
136 fputs_filtered ("\"\"", stdout);
140 for (i = 0; i < length && things_printed < print_max; ++i)
142 /* Position of the character we are examining
143 to see whether it is repeated. */
145 /* Number of repetitions we have detected so far. */
152 fputs_filtered (", ", stream);
158 while (rep1 < length && string[rep1] == string[i])
164 if (reps > REPEAT_COUNT_THRESHOLD)
169 fputs_filtered ("\\\", ", stream);
171 fputs_filtered ("\", ", stream);
174 fputs_filtered ("'", stream);
175 printchar (string[i], stream, '\'');
176 fprintf_filtered (stream, "' <repeats %u times>", reps);
178 things_printed += REPEAT_COUNT_THRESHOLD;
186 fputs_filtered ("\\\"", stream);
188 fputs_filtered ("\"", stream);
191 printchar (string[i], stream, '"');
196 /* Terminate the quotes if necessary. */
200 fputs_filtered ("\\\"", stream);
202 fputs_filtered ("\"", stream);
205 if (force_ellipses || i < length)
206 fputs_filtered ("...", stream);
209 /* Print a floating point value of type TYPE, pointed to in GDB by VALADDR,
213 print_floating (valaddr, type, stream)
220 unsigned len = TYPE_LENGTH (type);
222 #if defined (IEEE_FLOAT)
224 /* Check for NaN's. Note that this code does not depend on us being
225 on an IEEE conforming system. It only depends on the target
226 machine using IEEE representation. This means (a)
227 cross-debugging works right, and (2) IEEE_FLOAT can (and should)
228 be defined for systems like the 68881, which uses IEEE
229 representation, but is not IEEE conforming. */
233 /* Is the sign bit 0? */
235 /* Is it is a NaN (i.e. the exponent is all ones and
236 the fraction is nonzero)? */
239 if (len == sizeof (float))
241 /* It's single precision. */
242 memcpy ((char *) &low, valaddr, sizeof (low));
243 /* target -> host. */
244 SWAP_TARGET_AND_HOST (&low, sizeof (float));
245 nonnegative = low >= 0;
246 is_nan = ((((low >> 23) & 0xFF) == 0xFF)
247 && 0 != (low & 0x7FFFFF));
253 /* It's double precision. Get the high and low words. */
255 #if TARGET_BYTE_ORDER == BIG_ENDIAN
256 memcpy (&low, valaddr+4, sizeof (low));
257 memcpy (&high, valaddr+0, sizeof (high));
259 memcpy (&low, valaddr+0, sizeof (low));
260 memcpy (&high, valaddr+4, sizeof (high));
262 SWAP_TARGET_AND_HOST (&low, sizeof (low));
263 SWAP_TARGET_AND_HOST (&high, sizeof (high));
264 nonnegative = high >= 0;
265 is_nan = (((high >> 20) & 0x7ff) == 0x7ff
266 && ! ((((high & 0xfffff) == 0)) && (low == 0)));
272 /* The meaning of the sign and fraction is not defined by IEEE.
273 But the user might know what they mean. For example, they
274 (in an implementation-defined manner) distinguish between
275 signaling and quiet NaN's. */
277 fprintf_filtered (stream, "-NaN(0x%lx%.8lx)" + nonnegative,
280 fprintf_filtered (stream, "-NaN(0x%lx)" + nonnegative, low);
284 #endif /* IEEE_FLOAT. */
286 doub = unpack_double (type, valaddr, &inv);
288 fprintf_filtered (stream, "<invalid float value>");
290 fprintf_filtered (stream, len <= sizeof(float) ? "%.9g" : "%.17g", doub);
293 /* VALADDR points to an integer of LEN bytes. Print it in hex on stream. */
295 print_hex_chars (stream, valaddr, len)
297 unsigned char *valaddr;
302 fprintf_filtered (stream, "0x");
303 #if TARGET_BYTE_ORDER == BIG_ENDIAN
307 #else /* Little endian. */
308 for (p = valaddr + len - 1;
313 fprintf_filtered (stream, "%02x", *p);
317 /* Print the value VAL in C-ish syntax on stream STREAM.
318 FORMAT is a format-letter, or 0 for print in natural format of data type.
319 If the object printed is a string pointer, returns
320 the number of string bytes printed. */
323 value_print (val, stream, format, pretty)
327 enum val_prettyprint pretty;
329 register unsigned int i, n, typelen;
333 printf_filtered ("<address of value unknown>");
336 if (VALUE_OPTIMIZED_OUT (val))
338 printf_filtered ("<value optimized out>");
342 /* A "repeated" value really contains several values in a row.
343 They are made by the @ operator.
344 Print such values as if they were arrays. */
346 else if (VALUE_REPEATED (val))
348 n = VALUE_REPETITIONS (val);
349 typelen = TYPE_LENGTH (VALUE_TYPE (val));
350 fprintf_filtered (stream, "{");
351 /* Print arrays of characters using string syntax. */
352 if (typelen == 1 && TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_INT
354 print_string (stream, VALUE_CONTENTS (val), n, 0);
357 unsigned int things_printed = 0;
359 for (i = 0; i < n && things_printed < print_max; i++)
361 /* Position of the array element we are examining to see
362 whether it is repeated. */
364 /* Number of repetitions we have detected so far. */
368 fprintf_filtered (stream, ", ");
374 && !memcmp (VALUE_CONTENTS (val) + typelen * i,
375 VALUE_CONTENTS (val) + typelen * rep1, typelen))
381 if (reps > REPEAT_COUNT_THRESHOLD)
383 val_print (VALUE_TYPE (val),
384 VALUE_CONTENTS (val) + typelen * i,
385 VALUE_ADDRESS (val) + typelen * i,
386 stream, format, 1, 0, pretty);
387 fprintf (stream, " <repeats %u times>", reps);
389 things_printed += REPEAT_COUNT_THRESHOLD;
393 val_print (VALUE_TYPE (val),
394 VALUE_CONTENTS (val) + typelen * i,
395 VALUE_ADDRESS (val) + typelen * i,
396 stream, format, 1, 0, pretty);
401 fprintf_filtered (stream, "...");
403 fprintf_filtered (stream, "}");
408 struct type *type = VALUE_TYPE (val);
410 /* If it is a pointer, indicate what it points to.
412 Print type also if it is a reference.
414 C++: if it is a member pointer, we will take care
415 of that when we print it. */
416 if (TYPE_CODE (type) == TYPE_CODE_PTR
417 || TYPE_CODE (type) == TYPE_CODE_REF)
419 /* Hack: remove (char *) for char strings. Their
420 type is indicated by the quoted string anyway. */
421 if (TYPE_CODE (type) == TYPE_CODE_PTR
422 && TYPE_LENGTH (TYPE_TARGET_TYPE (type)) == sizeof(char)
423 && TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_INT
424 && !TYPE_UNSIGNED (TYPE_TARGET_TYPE (type)))
430 fprintf_filtered (stream, "(");
431 type_print (type, "", stream, -1);
432 fprintf_filtered (stream, ") ");
435 return val_print (type, VALUE_CONTENTS (val),
436 VALUE_ADDRESS (val), stream, format, 1, 0, pretty);
440 /* Return truth value for assertion that TYPE is of the type
441 "pointer to virtual function". */
443 is_vtbl_ptr_type(type)
446 char *typename = type_name_no_tag (type);
447 static const char vtbl_ptr_name[] =
448 { CPLUS_MARKER,'v','t','b','l','_','p','t','r','_','t','y','p','e', 0 };
450 return (typename != NULL && !strcmp(typename, vtbl_ptr_name));
453 /* Return truth value for the assertion that TYPE is of the type
454 "pointer to virtual function table". */
459 if (TYPE_CODE (type) == TYPE_CODE_PTR)
460 type = TYPE_TARGET_TYPE (type);
464 if (TYPE_CODE (type) == TYPE_CODE_ARRAY
465 && TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_STRUCT)
466 /* Virtual functions tables are full of pointers to virtual functions. */
467 return is_vtbl_ptr_type (TYPE_TARGET_TYPE (type));
471 /* Mutually recursive subroutines of cplus_val_print and val_print to print out
472 a structure's fields: val_print_fields and cplus_val_print.
474 TYPE, VALADDR, STREAM, RECURSE, and PRETTY have the
475 same meanings as in cplus_val_print and val_print.
477 DONT_PRINT is an array of baseclass types that we
478 should not print, or zero if called from top level. */
481 val_print_fields (type, valaddr, stream, format, recurse, pretty, dont_print)
487 enum val_prettyprint pretty;
488 struct type **dont_print;
490 int i, len, n_baseclasses;
492 check_stub_type (type);
494 fprintf_filtered (stream, "{");
495 len = TYPE_NFIELDS (type);
496 n_baseclasses = TYPE_N_BASECLASSES (type);
498 /* Print out baseclasses such that we don't print
499 duplicates of virtual baseclasses. */
500 if (n_baseclasses > 0)
501 cplus_val_print (type, valaddr, stream, format, recurse+1, pretty, dont_print);
503 if (!len && n_baseclasses == 1)
504 fprintf_filtered (stream, "<No data fields>");
507 extern int inspect_it;
510 for (i = n_baseclasses; i < len; i++)
512 /* Check if static field */
513 if (TYPE_FIELD_STATIC (type, i) || TYPE_FIELD_NESTED (type, i))
516 fprintf_filtered (stream, ", ");
517 else if (n_baseclasses > 0)
521 fprintf_filtered (stream, "\n");
522 print_spaces_filtered (2 + 2 * recurse, stream);
523 fputs_filtered ("members of ", stream);
524 fputs_filtered (type_name_no_tag (type), stream);
525 fputs_filtered (": ", stream);
532 fprintf_filtered (stream, "\n");
533 print_spaces_filtered (2 + 2 * recurse, stream);
537 wrap_here (n_spaces (2 + 2 * recurse));
541 if (TYPE_CODE (TYPE_FIELD_TYPE (type, i)) == TYPE_CODE_PTR)
542 fputs_filtered ("\"( ptr \"", stream);
544 fputs_filtered ("\"( nodef \"", stream);
545 fprint_symbol (stream, TYPE_FIELD_NAME (type, i));
546 fputs_filtered ("\" \"", stream);
547 fprint_symbol (stream, TYPE_FIELD_NAME (type, i));
548 fputs_filtered ("\") \"", stream);
552 fprint_symbol (stream, TYPE_FIELD_NAME (type, i));
553 fputs_filtered (" = ", stream);
555 if (TYPE_FIELD_PACKED (type, i))
559 /* Bitfields require special handling, especially due to byte
561 v = value_from_longest (TYPE_FIELD_TYPE (type, i),
562 unpack_field_as_long (type, valaddr, i));
564 val_print (TYPE_FIELD_TYPE (type, i), VALUE_CONTENTS (v), 0,
565 stream, format, 0, recurse + 1, pretty);
569 val_print (TYPE_FIELD_TYPE (type, i),
570 valaddr + TYPE_FIELD_BITPOS (type, i) / 8,
571 0, stream, format, 0, recurse + 1, pretty);
576 fprintf_filtered (stream, "\n");
577 print_spaces_filtered (2 * recurse, stream);
580 fprintf_filtered (stream, "}");
583 /* Special val_print routine to avoid printing multiple copies of virtual
587 cplus_val_print (type, valaddr, stream, format, recurse, pretty, dont_print)
593 enum val_prettyprint pretty;
594 struct type **dont_print;
596 struct obstack tmp_obstack;
597 struct type **last_dont_print
598 = (struct type **)obstack_next_free (&dont_print_obstack);
599 int i, n_baseclasses = TYPE_N_BASECLASSES (type);
603 /* If we're at top level, carve out a completely fresh
604 chunk of the obstack and use that until this particular
605 invocation returns. */
606 tmp_obstack = dont_print_obstack;
607 /* Bump up the high-water mark. Now alpha is omega. */
608 obstack_finish (&dont_print_obstack);
611 for (i = 0; i < n_baseclasses; i++)
616 if (BASETYPE_VIA_VIRTUAL (type, i))
618 struct type **first_dont_print
619 = (struct type **)obstack_base (&dont_print_obstack);
621 int j = (struct type **)obstack_next_free (&dont_print_obstack)
625 if (TYPE_BASECLASS (type, i) == first_dont_print[j])
628 obstack_ptr_grow (&dont_print_obstack, TYPE_BASECLASS (type, i));
631 /* Fix to use baseclass_offset instead. FIXME */
632 baddr = baseclass_addr (type, i, valaddr, 0, &err);
633 if (err == 0 && baddr == 0)
634 error ("could not find virtual baseclass `%s'\n",
635 type_name_no_tag (TYPE_BASECLASS (type, i)));
639 fprintf_filtered (stream, "\n");
640 print_spaces_filtered (2 * recurse, stream);
642 fputs_filtered ("<", stream);
643 fputs_filtered (type_name_no_tag (TYPE_BASECLASS (type, i)), stream);
644 fputs_filtered ("> = ", stream);
646 fprintf_filtered (stream, "<invalid address 0x%x>", baddr);
648 val_print_fields (TYPE_BASECLASS (type, i), baddr, stream, format,
650 (struct type **)obstack_base (&dont_print_obstack));
651 fputs_filtered (", ", stream);
659 /* Free the space used to deal with the printing
660 of this type from top level. */
661 obstack_free (&dont_print_obstack, last_dont_print);
662 /* Reset watermark so that we can continue protecting
663 ourselves from whatever we were protecting ourselves. */
664 dont_print_obstack = tmp_obstack;
669 print_class_member (valaddr, domain, stream, prefix)
676 /* VAL is a byte offset into the structure type DOMAIN.
677 Find the name of the field for that offset and
681 register unsigned int i;
682 unsigned len = TYPE_NFIELDS (domain);
683 /* @@ Make VAL into bit offset */
684 LONGEST val = unpack_long (builtin_type_int, valaddr) << 3;
685 for (i = TYPE_N_BASECLASSES (domain); i < len; i++)
687 int bitpos = TYPE_FIELD_BITPOS (domain, i);
691 if (val < bitpos && i != 0)
693 /* Somehow pointing into a field. */
695 extra = (val - TYPE_FIELD_BITPOS (domain, i));
706 fprintf_filtered (stream, prefix);
707 name = type_name_no_tag (domain);
709 fputs_filtered (name, stream);
711 type_print_base (domain, stream, 0, 0);
712 fprintf_filtered (stream, "::");
713 fputs_filtered (TYPE_FIELD_NAME (domain, i), stream);
715 fprintf_filtered (stream, " + %d bytes", extra);
717 fprintf_filtered (stream, " (offset in bits)");
720 fprintf_filtered (stream, "%d", val >> 3);
723 /* Print data of type TYPE located at VALADDR (within GDB),
724 which came from the inferior at address ADDRESS,
725 onto stdio stream STREAM according to FORMAT
726 (a letter or 0 for natural format). The data at VALADDR
727 is in target byte order.
729 If the data are a string pointer, returns the number of
730 sting characters printed.
732 if DEREF_REF is nonzero, then dereference references,
733 otherwise just print them like pointers.
735 The PRETTY parameter controls prettyprinting. */
738 val_print (type, valaddr, address, stream, format, deref_ref, recurse, pretty)
746 enum val_prettyprint pretty;
748 register unsigned int i;
750 struct type *elttype;
755 if (pretty == Val_pretty_default)
757 pretty = prettyprint ? Val_prettyprint : Val_no_prettyprint;
762 check_stub_type (type);
764 if (TYPE_FLAGS (type) & TYPE_FLAG_STUB)
766 fprintf_filtered (stream, "<unknown struct>");
771 switch (TYPE_CODE (type))
773 case TYPE_CODE_ARRAY:
774 if (TYPE_LENGTH (type) > 0
775 && TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0)
777 elttype = TYPE_TARGET_TYPE (type);
778 eltlen = TYPE_LENGTH (elttype);
779 len = TYPE_LENGTH (type) / eltlen;
781 print_spaces_filtered (2 + 2 * recurse, stream);
782 fprintf_filtered (stream, "{");
783 /* For an array of chars, print with string syntax. */
784 if (eltlen == 1 && TYPE_CODE (elttype) == TYPE_CODE_INT
785 && (format == 0 || format == 's') )
786 print_string (stream, valaddr, len, 0);
789 unsigned int things_printed = 0;
791 /* If this is a virtual function table, print the 0th
792 entry specially, and the rest of the members normally. */
793 if (is_vtbl_ptr_type (elttype))
795 fprintf_filtered (stream, "%d vtable entries", len-1);
801 for (; i < len && things_printed < print_max; i++)
803 /* Position of the array element we are examining to see
804 whether it is repeated. */
806 /* Number of repetitions we have detected so far. */
812 fprintf_filtered (stream, ",\n");
813 print_spaces_filtered (2 + 2 * recurse, stream);
816 fprintf_filtered (stream, ", ");
817 wrap_here (n_spaces (2 + 2 * recurse));
822 && !memcmp (valaddr + i * eltlen,
823 valaddr + rep1 * eltlen, eltlen))
829 if (reps > REPEAT_COUNT_THRESHOLD)
831 val_print (elttype, valaddr + i * eltlen,
832 0, stream, format, deref_ref,
833 recurse + 1, pretty);
834 fprintf_filtered (stream, " <repeats %u times>", reps);
836 things_printed += REPEAT_COUNT_THRESHOLD;
840 val_print (elttype, valaddr + i * eltlen,
841 0, stream, format, deref_ref,
842 recurse + 1, pretty);
847 fprintf_filtered (stream, "...");
849 fprintf_filtered (stream, "}");
852 /* Array of unspecified length: treat like pointer to first elt. */
853 valaddr = (char *) &address;
856 if (format && format != 's')
858 print_scalar_formatted (valaddr, type, format, 0, stream);
861 if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_METHOD)
863 struct type *domain = TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (type));
869 addr = unpack_pointer (lookup_pointer_type (builtin_type_void),
871 if (METHOD_PTR_IS_VIRTUAL(addr))
873 int offset = METHOD_PTR_TO_VOFFSET(addr);
874 len = TYPE_NFN_FIELDS (domain);
875 for (i = 0; i < len; i++)
877 f = TYPE_FN_FIELDLIST1 (domain, i);
878 len2 = TYPE_FN_FIELDLIST_LENGTH (domain, i);
880 for (j = 0; j < len2; j++)
883 if (TYPE_FN_FIELD_VOFFSET (f, j) == offset)
893 struct symbol *sym = find_pc_function (addr);
895 error ("invalid pointer to member function");
896 len = TYPE_NFN_FIELDS (domain);
897 for (i = 0; i < len; i++)
899 f = TYPE_FN_FIELDLIST1 (domain, i);
900 len2 = TYPE_FN_FIELDLIST_LENGTH (domain, i);
902 for (j = 0; j < len2; j++)
905 if (!strcmp (SYMBOL_NAME (sym), TYPE_FN_FIELD_PHYSNAME (f, j)))
913 fprintf_filtered (stream, "&");
914 type_print_varspec_prefix (TYPE_FN_FIELD_TYPE (f, j), stream, 0, 0);
915 fprintf (stream, kind);
916 if (TYPE_FN_FIELD_PHYSNAME (f, j)[0] == '_'
917 && TYPE_FN_FIELD_PHYSNAME (f, j)[1] == CPLUS_MARKER)
918 type_print_method_args
919 (TYPE_FN_FIELD_ARGS (f, j) + 1, "~",
920 TYPE_FN_FIELDLIST_NAME (domain, i), 0, stream);
922 type_print_method_args
923 (TYPE_FN_FIELD_ARGS (f, j), "",
924 TYPE_FN_FIELDLIST_NAME (domain, i), 0, stream);
927 fprintf_filtered (stream, "(");
928 type_print (type, "", stream, -1);
929 fprintf_filtered (stream, ") %d", (int) addr >> 3);
931 else if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_MEMBER)
933 print_class_member (valaddr,
934 TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (type)),
939 CORE_ADDR addr = unpack_pointer (type, valaddr);
940 elttype = TYPE_TARGET_TYPE (type);
942 if (TYPE_CODE (elttype) == TYPE_CODE_FUNC)
944 /* Try to print what function it points to. */
945 print_address_demangle (addr, stream, demangle);
946 /* Return value is irrelevant except for string pointers. */
950 if (addressprint && format != 's')
951 fprintf_filtered (stream, "0x%x", addr);
953 /* For a pointer to char or unsigned char,
954 also print the string pointed to, unless pointer is null. */
955 i = 0; /* Number of characters printed. */
956 if (TYPE_LENGTH (elttype) == 1
957 && TYPE_CODE (elttype) == TYPE_CODE_INT
958 && (format == 0 || format == 's')
960 /* If print_max is UINT_MAX, the alloca below will fail.
961 In that case don't try to print the string. */
962 && print_max < UINT_MAX)
964 int first_addr_err = 0;
967 /* Get first character. */
968 errcode = target_read_memory (addr, (char *)&c, 1);
971 /* First address out of bounds. */
977 char *string = (char *) alloca (print_max);
979 /* If the loop ends by us hitting print_max characters,
980 we need to have elipses at the end. */
981 int force_ellipses = 1;
983 /* This loop always fetches print_max characters, even
984 though print_string might want to print more or fewer
985 (with repeated characters). This is so that
986 we don't spend forever fetching if we print
987 a long string consisting of the same character
988 repeated. Also so we can do it all in one memory
989 operation, which is faster. However, this will be
990 slower if print_max is set high, e.g. if you set
991 print_max to 1000, not only will it take a long
992 time to fetch short strings, but if you are near
993 the end of the address space, it might not work. */
995 errcode = target_read_memory (addr, string, print_max);
998 /* Try reading just one character. If that succeeds,
999 assume we hit the end of the address space, but
1000 the initial part of the string is probably safe. */
1002 errcode = target_read_memory (addr, x, 1);
1007 for (i = 0; i < print_max; i++)
1008 if (string[i] == '\0')
1016 fputs_filtered (" ", stream);
1017 print_string (stream, string, i, force_ellipses);
1024 fprintf_filtered (stream,
1025 (" <Address 0x%x out of bounds>"
1031 error ("Error reading memory address 0x%x: %s.",
1032 addr + i, safe_strerror (errcode));
1038 else /* print vtbl's nicely */
1039 if (is_vtbl_member(type))
1041 CORE_ADDR vt_address = unpack_pointer (type, valaddr);
1043 struct minimal_symbol *msymbol =
1044 lookup_minimal_symbol_by_pc (vt_address);
1045 if ((msymbol != NULL) && (vt_address == msymbol -> address))
1047 fputs_filtered (" <", stream);
1048 fputs_demangled (msymbol -> name, stream,
1049 DMGL_ANSI | DMGL_PARAMS);
1050 fputs_filtered (">", stream);
1056 vt_val = value_at (TYPE_TARGET_TYPE (type), vt_address);
1057 val_print (VALUE_TYPE (vt_val), VALUE_CONTENTS (vt_val),
1058 VALUE_ADDRESS (vt_val), stream, format,
1059 deref_ref, recurse + 1, pretty);
1062 fprintf_filtered (stream, "\n");
1063 print_spaces_filtered (2 + 2 * recurse, stream);
1068 /* Return number of characters printed, plus one for the
1069 terminating null if we have "reached the end". */
1070 return i + (print_max && i != print_max);
1074 case TYPE_CODE_MEMBER:
1075 error ("not implemented: member type in val_print");
1079 if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_MEMBER)
1081 print_class_member (valaddr,
1082 TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (type)),
1088 fprintf_filtered (stream, "@0x%lx",
1089 unpack_long (builtin_type_int, valaddr));
1091 fputs_filtered (": ", stream);
1093 /* De-reference the reference. */
1096 if (TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_UNDEF)
1100 (TYPE_TARGET_TYPE (type),
1101 unpack_pointer (lookup_pointer_type (builtin_type_void),
1103 val_print (VALUE_TYPE (deref_val), VALUE_CONTENTS (deref_val),
1104 VALUE_ADDRESS (deref_val), stream, format,
1105 deref_ref, recurse + 1, pretty);
1108 fputs_filtered ("???", stream);
1112 case TYPE_CODE_UNION:
1113 if (recurse && !unionprint)
1115 fprintf_filtered (stream, "{...}");
1119 case TYPE_CODE_STRUCT:
1120 if (vtblprint && is_vtbl_ptr_type(type))
1122 /* Print the unmangled name if desired. */
1123 print_address_demangle(*((int *) (valaddr + /* FIXME bytesex */
1124 TYPE_FIELD_BITPOS (type, VTBL_FNADDR_OFFSET) / 8)),
1128 val_print_fields (type, valaddr, stream, format, recurse, pretty, 0);
1131 case TYPE_CODE_ENUM:
1134 print_scalar_formatted (valaddr, type, format, 0, stream);
1137 len = TYPE_NFIELDS (type);
1138 val = unpack_long (builtin_type_int, valaddr);
1139 for (i = 0; i < len; i++)
1142 if (val == TYPE_FIELD_BITPOS (type, i))
1146 fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
1149 fprintf_filtered (stream, "%lld", val);
1151 fprintf_filtered (stream, "%ld", val);
1155 case TYPE_CODE_FUNC:
1158 print_scalar_formatted (valaddr, type, format, 0, stream);
1161 /* FIXME, we should consider, at least for ANSI C language, eliminating
1162 the distinction made between FUNCs and POINTERs to FUNCs. */
1163 fprintf_filtered (stream, "{");
1164 type_print (type, "", stream, -1);
1165 fprintf_filtered (stream, "} ");
1166 /* Try to print what function it points to, and its address. */
1167 print_address_demangle (address, stream, demangle);
1171 if (format || output_format)
1173 print_scalar_formatted (valaddr, type,
1174 format? format: output_format,
1178 if (TYPE_LENGTH (type) > sizeof (LONGEST))
1180 if (TYPE_UNSIGNED (type))
1182 /* First figure out whether the number in fact has zeros
1183 in all its bytes more significant than least significant
1184 sizeof (LONGEST) ones. */
1186 /* Pointer to first (i.e. lowest address) nonzero character. */
1188 len = TYPE_LENGTH (type);
1190 #if TARGET_BYTE_ORDER == BIG_ENDIAN
1192 len > sizeof (LONGEST)
1193 && p < valaddr + TYPE_LENGTH (type);
1195 #else /* Little endian. */
1196 first_addr = valaddr;
1197 for (p = valaddr + TYPE_LENGTH (type);
1198 len > sizeof (LONGEST) && p >= valaddr;
1200 #endif /* Little endian. */
1207 #if TARGET_BYTE_ORDER == BIG_ENDIAN
1211 if (len <= sizeof (LONGEST))
1213 /* We can print it in decimal. */
1216 #if defined (LONG_LONG)
1221 unpack_long (BUILTIN_TYPE_LONGEST, first_addr));
1225 /* It is big, so print it in hex. */
1226 print_hex_chars (stream, (unsigned char *)first_addr, len);
1231 /* Signed. One could assume two's complement (a reasonable
1232 assumption, I think) and do better than this. */
1233 print_hex_chars (stream, (unsigned char *)valaddr,
1234 TYPE_LENGTH (type));
1238 #ifdef PRINT_TYPELESS_INTEGER
1239 PRINT_TYPELESS_INTEGER (stream, type, unpack_long (type, valaddr));
1242 fprintf_filtered (stream,
1243 TYPE_UNSIGNED (type) ? "%u" : "%d",
1244 unpack_long (type, valaddr));
1246 fprintf_filtered (stream,
1247 TYPE_UNSIGNED (type) ? "%llu" : "%lld",
1248 unpack_long (type, valaddr));
1252 if (TYPE_LENGTH (type) == 1)
1254 fprintf_filtered (stream, " '");
1255 printchar ((unsigned char) unpack_long (type, valaddr),
1257 fprintf_filtered (stream, "'");
1263 print_scalar_formatted (valaddr, type, format, 0, stream);
1265 print_floating (valaddr, type, stream);
1268 case TYPE_CODE_VOID:
1269 fprintf_filtered (stream, "void");
1272 case TYPE_CODE_UNDEF:
1273 /* This happens (without TYPE_FLAG_STUB set) on systems which don't use
1274 dbx xrefs (NO_DBX_XREFS in gcc) if a file has a "struct foo *bar"
1275 and no complete type for struct foo in that file. */
1276 fprintf_filtered (stream, "<unknown struct>");
1279 case TYPE_CODE_ERROR:
1280 fprintf_filtered (stream, "?");
1283 case TYPE_CODE_RANGE:
1284 /* FIXME, we should not ever have to print one of these yet. */
1285 fprintf_filtered (stream, "<range type>");
1289 error ("Invalid type code in symbol table.");
1295 /* Print a description of a type in the format of a
1296 typedef for the current language.
1297 NEW is the new name for a type TYPE. */
1299 typedef_print (type, new, stream)
1304 switch (current_language->la_language)
1308 case language_cplus:
1309 fprintf_filtered(stream, "typedef ");
1310 type_print(type,"",stream,0);
1311 if(TYPE_NAME ((SYMBOL_TYPE (new))) == 0
1312 || 0 != strcmp (TYPE_NAME ((SYMBOL_TYPE (new))),
1314 fprintf_filtered(stream, " %s", SYMBOL_NAME(new));
1319 fprintf_filtered(stream, "TYPE ");
1320 if(!TYPE_NAME(SYMBOL_TYPE(new)) ||
1321 strcmp (TYPE_NAME(SYMBOL_TYPE(new)),
1323 fprintf_filtered(stream, "%s = ", SYMBOL_NAME(new));
1325 fprintf_filtered(stream, "<builtin> = ");
1326 type_print(type,"",stream,0);
1330 error("Language not supported.");
1332 fprintf_filtered(stream, ";\n");
1336 /* Print a description of a type TYPE
1337 in the form of a declaration of a variable named VARSTRING.
1338 (VARSTRING is demangled if necessary.)
1339 Output goes to STREAM (via stdio).
1340 If SHOW is positive, we show the contents of the outermost level
1341 of structure even if there is a type name that could be used instead.
1342 If SHOW is negative, we never show the details of elements' types. */
1345 type_print (type, varstring, stream, show)
1351 type_print_1 (type, varstring, stream, show, 0);
1354 /* LEVEL is the depth to indent lines by. */
1357 type_print_1 (type, varstring, stream, show, level)
1364 register enum type_code code;
1365 char *demangled = NULL;
1368 type_print_base (type, stream, show, level);
1369 code = TYPE_CODE (type);
1370 if ((varstring && *varstring)
1372 /* Need a space if going to print stars or brackets;
1373 but not if we will print just a type name. */
1374 ((show > 0 || TYPE_NAME (type) == 0)
1376 (code == TYPE_CODE_PTR || code == TYPE_CODE_FUNC
1377 || code == TYPE_CODE_METHOD
1378 || code == TYPE_CODE_ARRAY
1379 || code == TYPE_CODE_MEMBER
1380 || code == TYPE_CODE_REF)))
1381 fprintf_filtered (stream, " ");
1382 type_print_varspec_prefix (type, stream, show, 0);
1384 /* See if the name has a C++ demangled equivalent, and if so, print that
1389 demangled = cplus_demangle (varstring, DMGL_ANSI | DMGL_PARAMS);
1391 fputs_filtered ((demangled != NULL) ? demangled : varstring, stream);
1393 /* For demangled function names, we have the arglist as part of the name,
1394 so don't print an additional pair of ()'s */
1396 demangled_args = (demangled != NULL) && (code == TYPE_CODE_FUNC);
1397 type_print_varspec_suffix (type, stream, show, 0, demangled_args);
1405 /* Print the method arguments ARGS to the file STREAM. */
1407 type_print_method_args (args, prefix, varstring, staticp, stream)
1409 char *prefix, *varstring;
1415 fputs_demangled (prefix, stream, DMGL_ANSI | DMGL_PARAMS);
1416 fputs_demangled (varstring, stream, DMGL_ANSI | DMGL_PARAMS);
1417 fputs_filtered (" (", stream);
1418 if (args && args[!staticp] && args[!staticp]->code != TYPE_CODE_VOID)
1420 i = !staticp; /* skip the class variable */
1423 type_print (args[i++], "", stream, 0);
1426 fprintf_filtered (stream, " ...");
1429 else if (args[i]->code != TYPE_CODE_VOID)
1431 fprintf_filtered (stream, ", ");
1436 fprintf_filtered (stream, ")");
1439 /* If TYPE is a derived type, then print out derivation information.
1440 Print only the actual base classes of this type, not the base classes
1441 of the base classes. I.E. for the derivation hierarchy:
1444 class B : public A {int b; };
1445 class C : public B {int c; };
1447 Print the type of class C as:
1449 class C : public B {
1453 Not as the following (like gdb used to), which is not legal C++ syntax for
1454 derived types and may be confused with the multiple inheritance form:
1456 class C : public B : public A {
1460 In general, gdb should try to print the types as closely as possible to
1461 the form that they appear in the source code. */
1464 type_print_derivation_info (stream, type)
1471 for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
1473 fputs_filtered (i == 0 ? ": " : ", ", stream);
1474 fprintf_filtered (stream, "%s%s ",
1475 BASETYPE_VIA_PUBLIC (type, i) ? "public" : "private",
1476 BASETYPE_VIA_VIRTUAL(type, i) ? " virtual" : "");
1477 name = type_name_no_tag (TYPE_BASECLASS (type, i));
1478 fprintf_filtered (stream, "%s", name ? name : "(null)");
1482 fputs_filtered (" ", stream);
1486 /* Print any asterisks or open-parentheses needed before the
1487 variable name (to describe its type).
1489 On outermost call, pass 0 for PASSED_A_PTR.
1490 On outermost call, SHOW > 0 means should ignore
1491 any typename for TYPE and show its details.
1492 SHOW is always zero on recursive calls. */
1495 type_print_varspec_prefix (type, stream, show, passed_a_ptr)
1505 if (TYPE_NAME (type) && show <= 0)
1510 switch (TYPE_CODE (type))
1513 type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 1);
1514 fprintf_filtered (stream, "*");
1517 case TYPE_CODE_MEMBER:
1519 fprintf_filtered (stream, "(");
1520 type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0,
1522 fprintf_filtered (stream, " ");
1523 name = type_name_no_tag (TYPE_DOMAIN_TYPE (type));
1525 fputs_filtered (name, stream);
1527 type_print_base (TYPE_DOMAIN_TYPE (type), stream, 0, passed_a_ptr);
1528 fprintf_filtered (stream, "::");
1531 case TYPE_CODE_METHOD:
1533 fprintf (stream, "(");
1534 type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0,
1538 fprintf_filtered (stream, " ");
1539 type_print_base (TYPE_DOMAIN_TYPE (type), stream, 0,
1541 fprintf_filtered (stream, "::");
1546 type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 1);
1547 fprintf_filtered (stream, "&");
1550 case TYPE_CODE_FUNC:
1551 type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0,
1554 fprintf_filtered (stream, "(");
1557 case TYPE_CODE_ARRAY:
1558 type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0,
1561 fprintf_filtered (stream, "(");
1564 case TYPE_CODE_UNDEF:
1565 case TYPE_CODE_STRUCT:
1566 case TYPE_CODE_UNION:
1567 case TYPE_CODE_ENUM:
1570 case TYPE_CODE_VOID:
1571 case TYPE_CODE_ERROR:
1572 case TYPE_CODE_CHAR:
1573 case TYPE_CODE_BOOL:
1575 case TYPE_CODE_RANGE:
1576 case TYPE_CODE_PASCAL_ARRAY:
1577 /* These types need no prefix. They are listed here so that
1578 gcc -Wall will reveal any types that haven't been handled. */
1584 type_print_args (type, stream)
1591 fprintf_filtered (stream, "(");
1592 args = TYPE_ARG_TYPES (type);
1595 if (args[1] == NULL)
1597 fprintf_filtered (stream, "...");
1602 args[i] != NULL && args[i]->code != TYPE_CODE_VOID;
1605 type_print_1 (args[i], "", stream, -1, 0);
1606 if (args[i+1] == NULL)
1608 fprintf_filtered (stream, "...");
1610 else if (args[i+1]->code != TYPE_CODE_VOID)
1612 fprintf_filtered (stream, ",");
1618 fprintf_filtered (stream, ")");
1621 /* Print any array sizes, function arguments or close parentheses
1622 needed after the variable name (to describe its type).
1623 Args work like type_print_varspec_prefix. */
1626 type_print_varspec_suffix (type, stream, show, passed_a_ptr, demangled_args)
1636 if (TYPE_NAME (type) && show <= 0)
1641 switch (TYPE_CODE (type))
1643 case TYPE_CODE_ARRAY:
1645 fprintf_filtered (stream, ")");
1647 fprintf_filtered (stream, "[");
1648 if (TYPE_LENGTH (type) > 0
1649 && TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0)
1650 fprintf_filtered (stream, "%d",
1652 / TYPE_LENGTH (TYPE_TARGET_TYPE (type))));
1653 fprintf_filtered (stream, "]");
1655 type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0,
1659 case TYPE_CODE_MEMBER:
1661 fprintf_filtered (stream, ")");
1662 type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0, 0);
1665 case TYPE_CODE_METHOD:
1667 fprintf_filtered (stream, ")");
1668 type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0, 0);
1671 type_print_args (type, stream);
1677 type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 1, 0);
1680 case TYPE_CODE_FUNC:
1681 type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0,
1684 fprintf_filtered (stream, ")");
1685 if (!demangled_args)
1686 fprintf_filtered (stream, "()");
1689 case TYPE_CODE_UNDEF:
1690 case TYPE_CODE_STRUCT:
1691 case TYPE_CODE_UNION:
1692 case TYPE_CODE_ENUM:
1695 case TYPE_CODE_VOID:
1696 case TYPE_CODE_ERROR:
1697 case TYPE_CODE_CHAR:
1698 case TYPE_CODE_BOOL:
1700 case TYPE_CODE_RANGE:
1701 case TYPE_CODE_PASCAL_ARRAY:
1702 /* These types do not need a suffix. They are listed so that
1703 gcc -Wall will report types that may not have been considered. */
1708 /* Print the name of the type (or the ultimate pointer target,
1709 function value or array element), or the description of a
1712 SHOW nonzero means don't print this type as just its name;
1713 show its real definition even if it has a name.
1714 SHOW zero means print just typename or struct tag if there is one
1715 SHOW negative means abbreviate structure elements.
1716 SHOW is decremented for printing of structure elements.
1718 LEVEL is the depth to indent by.
1719 We increase it for some recursive calls. */
1722 type_print_base (type, stream, show, level)
1731 register int lastval;
1733 char *demangled_name;
1734 enum {s_none, s_public, s_private, s_protected} section_type;
1740 fputs_filtered ("<type unknown>", stream);
1744 /* When SHOW is zero or less, and there is a valid type name, then always
1745 just print the type name directly from the type. */
1747 if ((show <= 0) && (TYPE_NAME (type) != NULL))
1749 fputs_filtered (TYPE_NAME (type), stream);
1753 switch (TYPE_CODE (type))
1755 case TYPE_CODE_ARRAY:
1757 case TYPE_CODE_MEMBER:
1759 case TYPE_CODE_FUNC:
1760 case TYPE_CODE_METHOD:
1761 type_print_base (TYPE_TARGET_TYPE (type), stream, show, level);
1764 case TYPE_CODE_STRUCT:
1765 fprintf_filtered (stream,
1766 HAVE_CPLUS_STRUCT (type) ? "class " : "struct ");
1769 case TYPE_CODE_UNION:
1770 fprintf_filtered (stream, "union ");
1772 if (name = type_name_no_tag (type))
1774 fputs_filtered (name, stream);
1775 fputs_filtered (" ", stream);
1779 fprintf_filtered (stream, "{...}");
1782 check_stub_type (type);
1784 type_print_derivation_info (stream, type);
1786 fprintf_filtered (stream, "{\n");
1787 if ((TYPE_NFIELDS (type) == 0) && (TYPE_NFN_FIELDS (type) == 0))
1789 if (TYPE_FLAGS (type) & TYPE_FLAG_STUB)
1790 fprintfi_filtered (level + 4, stream, "<incomplete type>\n");
1792 fprintfi_filtered (level + 4, stream, "<no data fields>\n");
1795 /* Start off with no specific section type, so we can print
1796 one for the first field we find, and use that section type
1797 thereafter until we find another type. */
1799 section_type = s_none;
1801 /* If there is a base class for this type,
1802 do not print the field that it occupies. */
1804 len = TYPE_NFIELDS (type);
1805 for (i = TYPE_N_BASECLASSES (type); i < len; i++)
1808 /* Don't print out virtual function table. */
1809 if ((TYPE_FIELD_NAME (type, i))[5] == CPLUS_MARKER &&
1810 !strncmp (TYPE_FIELD_NAME (type, i), "_vptr", 5))
1813 /* If this is a C++ class we can print the various C++ section
1816 if (HAVE_CPLUS_STRUCT (type))
1818 if (TYPE_FIELD_PROTECTED (type, i))
1820 if (section_type != s_protected)
1822 section_type = s_protected;
1823 fprintfi_filtered (level + 2, stream,
1827 else if (TYPE_FIELD_PRIVATE (type, i))
1829 if (section_type != s_private)
1831 section_type = s_private;
1832 fprintfi_filtered (level + 2, stream, "private:\n");
1837 if (section_type != s_public)
1839 section_type = s_public;
1840 fprintfi_filtered (level + 2, stream, "public:\n");
1845 print_spaces_filtered (level + 4, stream);
1846 if (TYPE_FIELD_STATIC (type, i))
1848 fprintf_filtered (stream, "static ");
1850 if (TYPE_FIELD_NESTED (type, i))
1852 fprintf_filtered (stream, "typedef ");
1854 type_print_1 (TYPE_FIELD_TYPE (type, i),
1855 TYPE_FIELD_NAME (type, i),
1856 stream, show - 1, level + 4);
1857 if (!TYPE_FIELD_STATIC (type, i) && !TYPE_FIELD_NESTED (type, i)
1858 && TYPE_FIELD_PACKED (type, i))
1860 /* It is a bitfield. This code does not attempt
1861 to look at the bitpos and reconstruct filler,
1862 unnamed fields. This would lead to misleading
1863 results if the compiler does not put out fields
1864 for such things (I don't know what it does). */
1865 fprintf_filtered (stream, " : %d",
1866 TYPE_FIELD_BITSIZE (type, i));
1868 fprintf_filtered (stream, ";\n");
1871 /* If there are both fields and methods, put a space between. */
1872 len = TYPE_NFN_FIELDS (type);
1873 if (len && section_type != s_none)
1874 fprintf_filtered (stream, "\n");
1876 /* C++: print out the methods */
1878 for (i = 0; i < len; i++)
1880 struct fn_field *f = TYPE_FN_FIELDLIST1 (type, i);
1881 int j, len2 = TYPE_FN_FIELDLIST_LENGTH (type, i);
1882 char *method_name = TYPE_FN_FIELDLIST_NAME (type, i);
1883 int is_constructor = name && strcmp(method_name, name) == 0;
1884 for (j = 0; j < len2; j++)
1887 if (TYPE_FN_FIELD_PROTECTED (f, j))
1889 if (section_type != s_protected)
1891 section_type = s_protected;
1892 fprintfi_filtered (level + 2, stream,
1896 else if (TYPE_FN_FIELD_PRIVATE (f, j))
1898 if (section_type != s_private)
1900 section_type = s_private;
1901 fprintfi_filtered (level + 2, stream, "private:\n");
1906 if (section_type != s_public)
1908 section_type = s_public;
1909 fprintfi_filtered (level + 2, stream, "public:\n");
1913 print_spaces_filtered (level + 4, stream);
1914 if (TYPE_FN_FIELD_VIRTUAL_P (f, j))
1915 fprintf_filtered (stream, "virtual ");
1916 else if (TYPE_FN_FIELD_STATIC_P (f, j))
1917 fprintf_filtered (stream, "static ");
1918 if (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)) == 0)
1920 /* Keep GDB from crashing here. */
1921 fprintf (stream, "<undefined type> %s;\n",
1922 TYPE_FN_FIELD_PHYSNAME (f, j));
1925 else if (!is_constructor)
1927 type_print (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)),
1929 fputs_filtered (" ", stream);
1931 if (TYPE_FN_FIELD_STUB (f, j))
1933 /* Build something we can demangle. */
1934 mangled_name = gdb_mangle_name (type, i, j);
1936 cplus_demangle (mangled_name,
1937 DMGL_ANSI | DMGL_PARAMS);
1938 if (demangled_name == NULL)
1939 fprintf_filtered (stream, "<badly mangled name %s>",
1943 fprintf_filtered (stream, "%s",
1944 strchr (demangled_name, ':') + 2);
1945 free (demangled_name);
1947 free (mangled_name);
1949 else if (TYPE_FN_FIELD_PHYSNAME (f, j)[0] == '_'
1950 && TYPE_FN_FIELD_PHYSNAME (f, j)[1] == CPLUS_MARKER)
1951 type_print_method_args
1952 (TYPE_FN_FIELD_ARGS (f, j) + 1, "~",
1953 method_name, 0, stream);
1955 type_print_method_args
1956 (TYPE_FN_FIELD_ARGS (f, j), "",
1958 TYPE_FN_FIELD_STATIC_P (f, j), stream);
1960 fprintf_filtered (stream, ";\n");
1964 fprintfi_filtered (level, stream, "}");
1968 case TYPE_CODE_ENUM:
1969 fprintf_filtered (stream, "enum ");
1970 if (name = type_name_no_tag (type))
1972 fputs_filtered (name, stream);
1973 fputs_filtered (" ", stream);
1977 fprintf_filtered (stream, "{...}");
1980 fprintf_filtered (stream, "{");
1981 len = TYPE_NFIELDS (type);
1983 for (i = 0; i < len; i++)
1986 if (i) fprintf_filtered (stream, ", ");
1988 fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
1989 if (lastval != TYPE_FIELD_BITPOS (type, i))
1991 fprintf_filtered (stream, " = %d", TYPE_FIELD_BITPOS (type, i));
1992 lastval = TYPE_FIELD_BITPOS (type, i);
1996 fprintf_filtered (stream, "}");
2000 case TYPE_CODE_VOID:
2001 fprintf_filtered (stream, "void");
2004 case TYPE_CODE_UNDEF:
2005 fprintf_filtered (stream, "struct <unknown>");
2008 case TYPE_CODE_ERROR:
2009 fprintf_filtered (stream, "<unknown type>");
2012 case TYPE_CODE_RANGE:
2013 /* This should not occur */
2014 fprintf_filtered (stream, "<range type>");
2018 /* Handle types not explicitly handled by the other cases,
2019 such as fundamental types. For these, just print whatever
2020 the type name is, as recorded in the type itself. If there
2021 is no type name, then complain. */
2022 if (TYPE_NAME (type) != NULL)
2024 fputs_filtered (TYPE_NAME (type), stream);
2028 error ("Invalid type code (%d) in symbol table.", TYPE_CODE (type));
2035 /* Validate an input or output radix setting, and make sure the user
2036 knows what they really did here. Radix setting is confusing, e.g.
2037 setting the input radix to "10" never changes it! */
2041 set_input_radix (args, from_tty, c)
2044 struct cmd_list_element *c;
2046 unsigned radix = *(unsigned *)c->var;
2049 printf_filtered ("Input radix set to decimal %d, hex %x, octal %o\n",
2050 radix, radix, radix);
2056 set_output_radix (args, from_tty, c)
2059 struct cmd_list_element *c;
2061 unsigned radix = *(unsigned *)c->var;
2064 printf_filtered ("Output radix set to decimal %d, hex %x, octal %o\n",
2065 radix, radix, radix);
2067 /* FIXME, we really should be able to validate the setting BEFORE
2072 output_format = 'x';
2078 output_format = 'o'; /* octal */
2082 error ("Unsupported radix ``decimal %d''; using decimal output",
2089 set_radix (arg, from_tty, c)
2092 struct cmd_list_element *c;
2094 unsigned radix = *(unsigned *)c->var;
2097 printf_filtered ("Radix set to decimal %d, hex %x, octal %o\n",
2098 radix, radix, radix);
2100 input_radix = radix;
2101 output_radix = radix;
2103 set_output_radix (arg, 0, c);
2108 set_print (arg, from_tty)
2113 "\"set print\" must be followed by the name of a print subcommand.\n");
2114 help_list (setprintlist, "set print ", -1, stdout);
2119 show_print (args, from_tty)
2123 cmd_show_list (showprintlist, from_tty, "");
2127 _initialize_valprint ()
2129 struct cmd_list_element *c;
2131 add_prefix_cmd ("print", no_class, set_print,
2132 "Generic command for setting how things print.",
2133 &setprintlist, "set print ", 0, &setlist);
2134 add_alias_cmd ("p", "print", no_class, 1, &setlist);
2135 add_alias_cmd ("pr", "print", no_class, 1, &setlist); /* prefer set print
2137 add_prefix_cmd ("print", no_class, show_print,
2138 "Generic command for showing print settings.",
2139 &showprintlist, "show print ", 0, &showlist);
2140 add_alias_cmd ("p", "print", no_class, 1, &showlist);
2141 add_alias_cmd ("pr", "print", no_class, 1, &showlist);
2144 (add_set_cmd ("elements", no_class, var_uinteger, (char *)&print_max,
2145 "Set limit on string chars or array elements to print.\n\
2146 \"set print elements 0\" causes there to be no limit.",
2151 (add_set_cmd ("pretty", class_support, var_boolean, (char *)&prettyprint,
2152 "Set prettyprinting of structures.",
2157 (add_set_cmd ("union", class_support, var_boolean, (char *)&unionprint,
2158 "Set printing of unions interior to structures.",
2163 (add_set_cmd ("vtbl", class_support, var_boolean, (char *)&vtblprint,
2164 "Set printing of C++ virtual function tables.",
2169 (add_set_cmd ("array", class_support, var_boolean, (char *)&arrayprint,
2170 "Set prettyprinting of arrays.",
2175 (add_set_cmd ("object", class_support, var_boolean, (char *)&objectprint,
2176 "Set printing of object's derived type based on vtable info.",
2181 (add_set_cmd ("address", class_support, var_boolean, (char *)&addressprint,
2182 "Set printing of addresses.",
2187 /* The "show radix" cmd isn't good enough to show two separate values.
2188 The rest of the code works, but the show part is confusing, so don't
2189 let them be set separately 'til we work out "show". */
2190 c = add_set_cmd ("input-radix", class_support, var_uinteger,
2191 (char *)&input_radix,
2192 "Set default input radix for entering numbers.",
2194 add_show_from_set (c, &showlist);
2195 c->function = set_input_radix;
2197 c = add_set_cmd ("output-radix", class_support, var_uinteger,
2198 (char *)&output_radix,
2199 "Set default output radix for printing of values.",
2201 add_show_from_set (c, &showlist);
2202 c->function = set_output_radix;
2205 c = add_set_cmd ("radix", class_support, var_uinteger,
2206 (char *)&output_radix,
2207 "Set default input and output number radix.",
2209 add_show_from_set (c, &showlist);
2210 c->function.sfunc = set_radix;
2212 /* Give people the defaults which they are used to. */
2222 obstack_begin (&dont_print_obstack, 32 * sizeof (struct type *));