ac1611fc5aa9ffaee78a1b466f4135744d8992fc
[platform/upstream/binutils.git] / gdb / valprint.c
1 /* Print values for GDB, the GNU debugger.
2    Copyright 1986, 1988, 1989, 1991 Free Software Foundation, Inc.
3
4 This file is part of GDB.
5
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.
10
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.
15
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.  */
19
20 #include "defs.h"
21 #include <string.h>
22 #include "symtab.h"
23 #include "gdbtypes.h"
24 #include "value.h"
25 #include "gdbcore.h"
26 #include "gdbcmd.h"
27 #include "target.h"
28 #include "obstack.h"
29 #include "language.h"
30 #include "demangle.h"
31
32 #include <errno.h>
33
34 /* Prototypes for local functions */
35
36 static void
37 print_string PARAMS ((FILE *, char *, unsigned int, int));
38
39 static void
40 show_print PARAMS ((char *, int));
41
42 static void
43 set_print PARAMS ((char *, int));
44
45 static void
46 set_radix PARAMS ((char *, int, struct cmd_list_element *));
47
48 static void
49 set_output_radix PARAMS ((char *, int, struct cmd_list_element *));
50
51 static void
52 type_print_base PARAMS ((struct type *, FILE *, int, int));
53
54 static void
55 type_print_args PARAMS ((struct type *, FILE *));
56
57 static void
58 type_print_varspec_suffix PARAMS ((struct type *, FILE *, int, int, int));
59
60 static void
61 type_print_varspec_prefix PARAMS ((struct type *, FILE *, int, int));
62
63 static void
64 type_print_derivation_info PARAMS ((FILE *, struct type *));
65
66 static void
67 type_print_method_args PARAMS ((struct type **, char *, char *, int, FILE *));
68
69 static void
70 cplus_val_print PARAMS ((struct type *, char *, FILE *, int, int,
71                          enum val_prettyprint, struct type **));
72
73 static void
74 val_print_fields PARAMS ((struct type *, char *, FILE *, int, int,
75                           enum val_prettyprint, struct type **));
76
77 static int
78 is_vtbl_member PARAMS ((struct type *));
79
80 static int
81 is_vtbl_ptr_type PARAMS ((struct type *));
82
83 static void
84 print_hex_chars PARAMS ((FILE *, unsigned char *, unsigned));
85
86 extern int demangle;    /* whether to print C++ syms raw or source-form */
87
88 /* Maximum number of chars to print for a string pointer value
89    or vector contents, or UINT_MAX for no limit.  */
90
91 static unsigned int print_max;
92
93 /* Default input and output radixes, and output format letter.  */
94
95 unsigned input_radix = 10;
96 unsigned output_radix = 10;
97 int output_format = 0;
98
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
102
103 /* Define a mess of print controls.  */
104
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.  */
112
113 struct obstack dont_print_obstack;
114
115 \f
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.  */
120
121 static void
122 print_string (stream, string, length, force_ellipses)
123      FILE *stream;
124      char *string;
125      unsigned int length;
126      int force_ellipses;
127 {
128   register unsigned int i;
129   unsigned int things_printed = 0;
130   int in_quotes = 0;
131   int need_comma = 0;
132   extern int inspect_it;
133
134   if (length == 0)
135     {
136       fputs_filtered ("\"\"", stdout);
137       return;
138     }
139
140   for (i = 0; i < length && things_printed < print_max; ++i)
141     {
142       /* Position of the character we are examining
143          to see whether it is repeated.  */
144       unsigned int rep1;
145       /* Number of repetitions we have detected so far.  */
146       unsigned int reps;
147
148       QUIT;
149
150       if (need_comma)
151         {
152           fputs_filtered (", ", stream);
153           need_comma = 0;
154         }
155
156       rep1 = i + 1;
157       reps = 1;
158       while (rep1 < length && string[rep1] == string[i])
159         {
160           ++rep1;
161           ++reps;
162         }
163
164       if (reps > REPEAT_COUNT_THRESHOLD)
165         {
166           if (in_quotes)
167             {
168               if (inspect_it)
169                 fputs_filtered ("\\\", ", stream);
170               else
171                 fputs_filtered ("\", ", stream);
172               in_quotes = 0;
173             }
174           fputs_filtered ("'", stream);
175           printchar (string[i], stream, '\'');
176           fprintf_filtered (stream, "' <repeats %u times>", reps);
177           i = rep1 - 1;
178           things_printed += REPEAT_COUNT_THRESHOLD;
179           need_comma = 1;
180         }
181       else
182         {
183           if (!in_quotes)
184             {
185               if (inspect_it)
186                 fputs_filtered ("\\\"", stream);
187               else
188                 fputs_filtered ("\"", stream);
189               in_quotes = 1;
190             }
191           printchar (string[i], stream, '"');
192           ++things_printed;
193         }
194     }
195
196   /* Terminate the quotes if necessary.  */
197   if (in_quotes)
198     {
199       if (inspect_it)
200         fputs_filtered ("\\\"", stream);
201       else
202         fputs_filtered ("\"", stream);
203     }
204
205   if (force_ellipses || i < length)
206     fputs_filtered ("...", stream);
207 }
208
209 /* Print a floating point value of type TYPE, pointed to in GDB by VALADDR,
210    on STREAM.  */
211
212 void
213 print_floating (valaddr, type, stream)
214      char *valaddr;
215      struct type *type;
216      FILE *stream;
217 {
218   double doub;
219   int inv;
220   unsigned len = TYPE_LENGTH (type);
221   
222 #if defined (IEEE_FLOAT)
223
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.  */
230
231   {
232     long low, high;
233     /* Is the sign bit 0?  */
234     int nonnegative;
235     /* Is it is a NaN (i.e. the exponent is all ones and
236        the fraction is nonzero)?  */
237     int is_nan;
238
239     if (len == sizeof (float))
240       {
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));
248         low &= 0x7fffff;
249         high = 0;
250       }
251     else
252       {
253         /* It's double precision.  Get the high and low words.  */
254
255 #if TARGET_BYTE_ORDER == BIG_ENDIAN
256         memcpy (&low, valaddr+4,  sizeof (low));
257         memcpy (&high, valaddr+0, sizeof (high));
258 #else
259         memcpy (&low, valaddr+0,  sizeof (low));
260         memcpy (&high, valaddr+4, sizeof (high));
261 #endif
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)));
267         high &= 0xfffff;
268       }
269
270     if (is_nan)
271       {
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.  */
276         if (high)
277           fprintf_filtered (stream, "-NaN(0x%lx%.8lx)" + nonnegative,
278                             high, low);
279         else
280           fprintf_filtered (stream, "-NaN(0x%lx)" + nonnegative, low);
281         return;
282       }
283   }
284 #endif /* IEEE_FLOAT.  */
285
286   doub = unpack_double (type, valaddr, &inv);
287   if (inv)
288     fprintf_filtered (stream, "<invalid float value>");
289   else
290     fprintf_filtered (stream, len <= sizeof(float) ? "%.9g" : "%.17g", doub);
291 }
292
293 /* VALADDR points to an integer of LEN bytes.  Print it in hex on stream.  */
294 static void
295 print_hex_chars (stream, valaddr, len)
296      FILE *stream;
297      unsigned char *valaddr;
298      unsigned len;
299 {
300   unsigned char *p;
301   
302   fprintf_filtered (stream, "0x");
303 #if TARGET_BYTE_ORDER == BIG_ENDIAN
304   for (p = valaddr;
305        p < valaddr + len;
306        p++)
307 #else /* Little endian.  */
308   for (p = valaddr + len - 1;
309        p >= valaddr;
310        p--)
311 #endif
312     {
313       fprintf_filtered (stream, "%02x", *p);
314     }
315 }
316 \f
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.  */
321
322 int
323 value_print (val, stream, format, pretty)
324      value val;
325      FILE *stream;
326      int format;
327      enum val_prettyprint pretty;
328 {
329   register unsigned int i, n, typelen;
330
331   if (val == 0)
332     {
333       printf_filtered ("<address of value unknown>");
334       return 0;
335     }
336   if (VALUE_OPTIMIZED_OUT (val))
337     {
338       printf_filtered ("<value optimized out>");
339       return 0;
340     }
341
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.  */
345
346   else if (VALUE_REPEATED (val))
347     {
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
353           && format == 0)
354         print_string (stream, VALUE_CONTENTS (val), n, 0);
355       else
356         {
357           unsigned int things_printed = 0;
358           
359           for (i = 0; i < n && things_printed < print_max; i++)
360             {
361               /* Position of the array element we are examining to see
362                  whether it is repeated.  */
363               unsigned int rep1;
364               /* Number of repetitions we have detected so far.  */
365               unsigned int reps;
366
367               if (i != 0)
368                 fprintf_filtered (stream, ", ");
369               wrap_here ("");
370
371               rep1 = i + 1;
372               reps = 1;
373               while (rep1 < n
374                      && !memcmp (VALUE_CONTENTS (val) + typelen * i,
375                                VALUE_CONTENTS (val) + typelen * rep1, typelen))
376                 {
377                   ++reps;
378                   ++rep1;
379                 }
380
381               if (reps > REPEAT_COUNT_THRESHOLD)
382                 {
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);
388                   i = rep1 - 1;
389                   things_printed += REPEAT_COUNT_THRESHOLD;
390                 }
391               else
392                 {
393                   val_print (VALUE_TYPE (val),
394                              VALUE_CONTENTS (val) + typelen * i,
395                              VALUE_ADDRESS (val) + typelen * i,
396                              stream, format, 1, 0, pretty);
397                   things_printed++;
398                 }
399             }
400           if (i < n)
401             fprintf_filtered (stream, "...");
402         }
403       fprintf_filtered (stream, "}");
404       return n * typelen;
405     }
406   else
407     {
408       struct type *type = VALUE_TYPE (val);
409
410       /* If it is a pointer, indicate what it points to.
411
412          Print type also if it is a reference.
413
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)
418         {
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)))
425             {
426                 /* Print nothing */
427             }
428           else
429             {
430               fprintf_filtered (stream, "(");
431               type_print (type, "", stream, -1);
432               fprintf_filtered (stream, ") ");
433             }
434         }
435       return val_print (type, VALUE_CONTENTS (val),
436                         VALUE_ADDRESS (val), stream, format, 1, 0, pretty);
437     }
438 }
439
440 /* Return truth value for assertion that TYPE is of the type
441    "pointer to virtual function".  */
442 static int
443 is_vtbl_ptr_type(type)
444      struct type *type;
445 {
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 };
449
450   return (typename != NULL && !strcmp(typename, vtbl_ptr_name));
451 }
452
453 /* Return truth value for the assertion that TYPE is of the type
454    "pointer to virtual function table".  */
455 static int
456 is_vtbl_member(type)
457      struct type *type;
458 {
459   if (TYPE_CODE (type) == TYPE_CODE_PTR)
460     type = TYPE_TARGET_TYPE (type);
461   else
462     return 0;
463
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));
468   return 0;
469 }
470 \f
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.
473
474    TYPE, VALADDR, STREAM, RECURSE, and PRETTY have the
475    same meanings as in cplus_val_print and val_print.
476
477    DONT_PRINT is an array of baseclass types that we
478    should not print, or zero if called from top level.  */
479
480 static void
481 val_print_fields (type, valaddr, stream, format, recurse, pretty, dont_print)
482      struct type *type;
483      char *valaddr;
484      FILE *stream;
485      int format;
486      int recurse;
487      enum val_prettyprint pretty;
488      struct type **dont_print;
489 {
490   int i, len, n_baseclasses;
491
492   check_stub_type (type);
493
494   fprintf_filtered (stream, "{");
495   len = TYPE_NFIELDS (type);
496   n_baseclasses = TYPE_N_BASECLASSES (type);
497
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);
502
503   if (!len && n_baseclasses == 1)
504     fprintf_filtered (stream, "<No data fields>");
505   else
506     {
507       extern int inspect_it;
508       int fields_seen = 0;
509
510       for (i = n_baseclasses; i < len; i++)
511         {
512           /* Check if static field */
513           if (TYPE_FIELD_STATIC (type, i))
514             continue;
515           if (fields_seen)
516             fprintf_filtered (stream, ", ");
517           else if (n_baseclasses > 0)
518             {
519               if (pretty)
520                 {
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);
526                 }
527             }
528           fields_seen = 1;
529
530           if (pretty)
531             {
532               fprintf_filtered (stream, "\n");
533               print_spaces_filtered (2 + 2 * recurse, stream);
534             }
535           else 
536             {
537               wrap_here (n_spaces (2 + 2 * recurse));
538             }
539           if (inspect_it)
540             {
541               if (TYPE_CODE (TYPE_FIELD_TYPE (type, i)) == TYPE_CODE_PTR)
542                 fputs_filtered ("\"( ptr \"", stream);
543               else
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);
549             }
550           else
551             {
552               fprint_symbol (stream, TYPE_FIELD_NAME (type, i));
553               fputs_filtered (" = ", stream);
554             }
555           if (TYPE_FIELD_PACKED (type, i))
556             {
557               value v;
558
559               /* Bitfields require special handling, especially due to byte
560                  order problems.  */
561               v = value_from_longest (TYPE_FIELD_TYPE (type, i),
562                                    unpack_field_as_long (type, valaddr, i));
563
564               val_print (TYPE_FIELD_TYPE (type, i), VALUE_CONTENTS (v), 0,
565                          stream, format, 0, recurse + 1, pretty);
566             }
567           else
568             {
569               val_print (TYPE_FIELD_TYPE (type, i), 
570                          valaddr + TYPE_FIELD_BITPOS (type, i) / 8,
571                          0, stream, format, 0, recurse + 1, pretty);
572             }
573         }
574       if (pretty)
575         {
576           fprintf_filtered (stream, "\n");
577           print_spaces_filtered (2 * recurse, stream);
578         }
579     }
580   fprintf_filtered (stream, "}");
581 }
582
583 /* Special val_print routine to avoid printing multiple copies of virtual
584    baseclasses.  */
585
586 static void
587 cplus_val_print (type, valaddr, stream, format, recurse, pretty, dont_print)
588      struct type *type;
589      char *valaddr;
590      FILE *stream;
591      int format;
592      int recurse;
593      enum val_prettyprint pretty;
594      struct type **dont_print;
595 {
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);
600
601   if (dont_print == 0)
602     {
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);
609     }
610
611   for (i = 0; i < n_baseclasses; i++)
612     {
613       char *baddr;
614       int err;
615
616       if (BASETYPE_VIA_VIRTUAL (type, i))
617         {
618           struct type **first_dont_print
619             = (struct type **)obstack_base (&dont_print_obstack);
620
621           int j = (struct type **)obstack_next_free (&dont_print_obstack)
622             - first_dont_print;
623
624           while (--j >= 0)
625             if (TYPE_BASECLASS (type, i) == first_dont_print[j])
626               goto flush_it;
627
628           obstack_ptr_grow (&dont_print_obstack, TYPE_BASECLASS (type, i));
629         }
630
631       baddr = baseclass_addr (type, i, valaddr, 0, &err);
632       if (err == 0 && baddr == 0)
633         error ("could not find virtual baseclass `%s'\n",
634                type_name_no_tag (TYPE_BASECLASS (type, i)));
635
636       if (pretty)
637         {
638           fprintf_filtered (stream, "\n");
639           print_spaces_filtered (2 * recurse, stream);
640         }
641       fputs_filtered ("<", stream);
642       fputs_filtered (type_name_no_tag (TYPE_BASECLASS (type, i)), stream);
643       fputs_filtered ("> = ", stream);
644       if (err != 0)
645         fprintf_filtered (stream, "<invalid address 0x%x>", baddr);
646       else
647         val_print_fields (TYPE_BASECLASS (type, i), baddr, stream, format,
648                           recurse, pretty,
649                           (struct type **)obstack_base (&dont_print_obstack));
650       fputs_filtered (", ", stream);
651
652     flush_it:
653       ;
654     }
655
656   if (dont_print == 0)
657     {
658       /* Free the space used to deal with the printing
659          of this type from top level.  */
660       obstack_free (&dont_print_obstack, last_dont_print);
661       /* Reset watermark so that we can continue protecting
662          ourselves from whatever we were protecting ourselves.  */
663       dont_print_obstack = tmp_obstack;
664     }
665 }
666
667 static void
668 print_class_member (valaddr, domain, stream, prefix)
669      char *valaddr;
670      struct type *domain;
671      FILE *stream;
672      char *prefix;
673 {
674   
675   /* VAL is a byte offset into the structure type DOMAIN.
676      Find the name of the field for that offset and
677      print it.  */
678   int extra = 0;
679   int bits = 0;
680   register unsigned int i;
681   unsigned len = TYPE_NFIELDS (domain);
682   /* @@ Make VAL into bit offset */
683   LONGEST val = unpack_long (builtin_type_int, valaddr) << 3;
684   for (i = TYPE_N_BASECLASSES (domain); i < len; i++)
685     {
686       int bitpos = TYPE_FIELD_BITPOS (domain, i);
687       QUIT;
688       if (val == bitpos)
689         break;
690       if (val < bitpos && i != 0)
691         {
692           /* Somehow pointing into a field.  */
693           i -= 1;
694           extra = (val - TYPE_FIELD_BITPOS (domain, i));
695           if (extra & 0x7)
696             bits = 1;
697           else
698             extra >>= 3;
699           break;
700         }
701     }
702   if (i < len)
703     {
704       char *name;
705       fprintf_filtered (stream, prefix);
706       name = type_name_no_tag (domain);
707       if (name)
708         fputs_filtered (name, stream);
709       else
710         type_print_base (domain, stream, 0, 0);
711       fprintf_filtered (stream, "::");
712       fputs_filtered (TYPE_FIELD_NAME (domain, i), stream);
713       if (extra)
714         fprintf_filtered (stream, " + %d bytes", extra);
715       if (bits)
716         fprintf_filtered (stream, " (offset in bits)");
717     }
718   else
719     fprintf_filtered (stream, "%d", val >> 3);
720 }
721
722 /* Print data of type TYPE located at VALADDR (within GDB),
723    which came from the inferior at address ADDRESS,
724    onto stdio stream STREAM according to FORMAT
725    (a letter or 0 for natural format).  The data at VALADDR
726    is in target byte order.
727
728    If the data are a string pointer, returns the number of
729    sting characters printed.
730
731    if DEREF_REF is nonzero, then dereference references,
732    otherwise just print them like pointers.
733
734    The PRETTY parameter controls prettyprinting.  */
735
736 int
737 val_print (type, valaddr, address, stream, format, deref_ref, recurse, pretty)
738      struct type *type;
739      char *valaddr;
740      CORE_ADDR address;
741      FILE *stream;
742      int format;
743      int deref_ref;
744      int recurse;
745      enum val_prettyprint pretty;
746 {
747   register unsigned int i;
748   unsigned len;
749   struct type *elttype;
750   unsigned eltlen;
751   LONGEST val;
752   unsigned char c;
753
754   if (pretty == Val_pretty_default)
755     {
756       pretty = prettyprint ? Val_prettyprint : Val_no_prettyprint;
757     }
758   
759   QUIT;
760
761   check_stub_type (type);
762   
763   if (TYPE_FLAGS (type) & TYPE_FLAG_STUB)
764     {
765       fprintf_filtered (stream, "<unknown struct>");
766       fflush (stream);
767       return 0;
768     }
769   
770   switch (TYPE_CODE (type))
771     {
772     case TYPE_CODE_ARRAY:
773       if (TYPE_LENGTH (type) > 0
774           && TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0)
775         {
776           elttype = TYPE_TARGET_TYPE (type);
777           eltlen = TYPE_LENGTH (elttype);
778           len = TYPE_LENGTH (type) / eltlen;
779           if (arrayprint)
780             print_spaces_filtered (2 + 2 * recurse, stream);
781           fprintf_filtered (stream, "{");
782           /* For an array of chars, print with string syntax.  */
783           if (eltlen == 1 && TYPE_CODE (elttype) == TYPE_CODE_INT
784               && (format == 0 || format == 's') )
785             print_string (stream, valaddr, len, 0);
786           else
787             {
788               unsigned int things_printed = 0;
789               
790               /* If this is a virtual function table, print the 0th
791                  entry specially, and the rest of the members normally.  */
792               if (is_vtbl_ptr_type (elttype))
793                 {
794                   fprintf_filtered (stream, "%d vtable entries", len-1);
795                   i = 1;
796                 }
797               else
798                 i = 0;
799
800               for (; i < len && things_printed < print_max; i++)
801                 {
802                   /* Position of the array element we are examining to see
803                      whether it is repeated.  */
804                   unsigned int rep1;
805                   /* Number of repetitions we have detected so far.  */
806                   unsigned int reps;
807                   
808                   if (i != 0)
809                     if (arrayprint)
810                       {
811                         fprintf_filtered (stream, ",\n");
812                         print_spaces_filtered (2 + 2 * recurse, stream);
813                       }
814                     else
815                       fprintf_filtered (stream, ", ");
816                     wrap_here (n_spaces (2 + 2 * recurse));
817                   
818                   rep1 = i + 1;
819                   reps = 1;
820                   while (rep1 < len
821                          && !memcmp (valaddr + i * eltlen,
822                                      valaddr + rep1 * eltlen, eltlen))
823                     {
824                       ++reps;
825                       ++rep1;
826                     }
827
828                   if (reps > REPEAT_COUNT_THRESHOLD)
829                     {
830                       val_print (elttype, valaddr + i * eltlen,
831                                  0, stream, format, deref_ref,
832                                  recurse + 1, pretty);
833                       fprintf_filtered (stream, " <repeats %u times>", reps);
834                       i = rep1 - 1;
835                       things_printed += REPEAT_COUNT_THRESHOLD;
836                     }
837                   else
838                     {
839                       val_print (elttype, valaddr + i * eltlen,
840                                  0, stream, format, deref_ref,
841                                  recurse + 1, pretty);
842                       things_printed++;
843                     }
844                 }
845               if (i < len)
846                 fprintf_filtered (stream, "...");
847             }
848           fprintf_filtered (stream, "}");
849           break;
850         }
851       /* Array of unspecified length: treat like pointer to first elt.  */
852       valaddr = (char *) &address;
853
854     case TYPE_CODE_PTR:
855       if (format && format != 's')
856         {
857           print_scalar_formatted (valaddr, type, format, 0, stream);
858           break;
859         }
860       if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_METHOD)
861         {
862           struct type *domain = TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (type));
863           struct fn_field *f;
864           int j, len2;
865           char *kind = "";
866           CORE_ADDR addr;
867
868           addr = unpack_pointer (lookup_pointer_type (builtin_type_void),
869                                 valaddr);
870           if (addr < 128)                       /* FIXME!  What is this 128? */
871             {
872               len = TYPE_NFN_FIELDS (domain);
873               for (i = 0; i < len; i++)
874                 {
875                   f = TYPE_FN_FIELDLIST1 (domain, i);
876                   len2 = TYPE_FN_FIELDLIST_LENGTH (domain, i);
877
878                   for (j = 0; j < len2; j++)
879                     {
880                       QUIT;
881                       if (TYPE_FN_FIELD_VOFFSET (f, j) == addr)
882                         {
883                           kind = "virtual";
884                           goto common;
885                         }
886                     }
887                 }
888             }
889           else
890             {
891               struct symbol *sym = find_pc_function (addr);
892               if (sym == 0)
893                 error ("invalid pointer to member function");
894               len = TYPE_NFN_FIELDS (domain);
895               for (i = 0; i < len; i++)
896                 {
897                   f = TYPE_FN_FIELDLIST1 (domain, i);
898                   len2 = TYPE_FN_FIELDLIST_LENGTH (domain, i);
899
900                   for (j = 0; j < len2; j++)
901                     {
902                       QUIT;
903                       if (!strcmp (SYMBOL_NAME (sym), TYPE_FN_FIELD_PHYSNAME (f, j)))
904                         goto common;
905                     }
906                 }
907             }
908         common:
909           if (i < len)
910             {
911               fprintf_filtered (stream, "&");
912               type_print_varspec_prefix (TYPE_FN_FIELD_TYPE (f, j), stream, 0, 0);
913               fprintf (stream, kind);
914               if (TYPE_FN_FIELD_PHYSNAME (f, j)[0] == '_'
915                   && TYPE_FN_FIELD_PHYSNAME (f, j)[1] == CPLUS_MARKER)
916                 type_print_method_args
917                   (TYPE_FN_FIELD_ARGS (f, j) + 1, "~",
918                    TYPE_FN_FIELDLIST_NAME (domain, i), 0, stream);
919               else
920                 type_print_method_args
921                   (TYPE_FN_FIELD_ARGS (f, j), "",
922                    TYPE_FN_FIELDLIST_NAME (domain, i), 0, stream);
923               break;
924             }
925           fprintf_filtered (stream, "(");
926           type_print (type, "", stream, -1);
927           fprintf_filtered (stream, ") %d", (int) addr >> 3);
928         }
929       else if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_MEMBER)
930         {
931           print_class_member (valaddr,
932                               TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (type)),
933                               stream, "&");
934         }
935       else
936         {
937           CORE_ADDR addr = unpack_pointer (type, valaddr);
938           elttype = TYPE_TARGET_TYPE (type);
939
940           if (TYPE_CODE (elttype) == TYPE_CODE_FUNC)
941             {
942               /* Try to print what function it points to.  */
943               print_address_demangle (addr, stream, demangle);
944               /* Return value is irrelevant except for string pointers.  */
945               return 0;
946             }
947
948           if (addressprint && format != 's')
949             fprintf_filtered (stream, "0x%x", addr);
950
951           /* For a pointer to char or unsigned char,
952              also print the string pointed to, unless pointer is null.  */
953           i = 0;                /* Number of characters printed.  */
954           if (TYPE_LENGTH (elttype) == 1 
955               && TYPE_CODE (elttype) == TYPE_CODE_INT
956               && (format == 0 || format == 's')
957               && addr != 0
958               /* If print_max is UINT_MAX, the alloca below will fail.
959                  In that case don't try to print the string.  */
960               && print_max < UINT_MAX)
961             {
962               int first_addr_err = 0;
963               int errcode = 0;
964               
965               /* Get first character.  */
966               errcode = target_read_memory (addr, (char *)&c, 1);
967               if (errcode != 0)
968                 {
969                   /* First address out of bounds.  */
970                   first_addr_err = 1;
971                 }
972               else
973                 {
974                   /* A real string.  */
975                   char *string = (char *) alloca (print_max);
976
977                   /* If the loop ends by us hitting print_max characters,
978                      we need to have elipses at the end.  */
979                   int force_ellipses = 1;
980
981                   /* This loop always fetches print_max characters, even
982                      though print_string might want to print more or fewer
983                      (with repeated characters).  This is so that
984                      we don't spend forever fetching if we print
985                      a long string consisting of the same character
986                      repeated.  Also so we can do it all in one memory
987                      operation, which is faster.  However, this will be
988                      slower if print_max is set high, e.g. if you set
989                      print_max to 1000, not only will it take a long
990                      time to fetch short strings, but if you are near
991                      the end of the address space, it might not work. */
992                   QUIT;
993                   errcode = target_read_memory (addr, string, print_max);
994                   if (errcode != 0)
995                     {
996                       /* Try reading just one character.  If that succeeds,
997                          assume we hit the end of the address space, but
998                          the initial part of the string is probably safe. */
999                       char x[1];
1000                       errcode = target_read_memory (addr, x, 1);
1001                     }
1002                   if (errcode != 0)
1003                       force_ellipses = 0;
1004                   else 
1005                     for (i = 0; i < print_max; i++)
1006                       if (string[i] == '\0')
1007                         {
1008                           force_ellipses = 0;
1009                           break;
1010                         }
1011                   QUIT;
1012
1013                   if (addressprint)
1014                     fputs_filtered (" ", stream);
1015                   print_string (stream, string, i, force_ellipses);
1016                 }
1017
1018               if (errcode != 0)
1019                 {
1020                   if (errcode == EIO)
1021                     {
1022                       fprintf_filtered (stream,
1023                                         (" <Address 0x%x out of bounds>"
1024                                          + first_addr_err),
1025                                         addr + i);
1026                     }
1027                   else
1028                     {
1029                       error ("Error reading memory address 0x%x: %s.",
1030                              addr + i, safe_strerror (errcode));
1031                     }
1032                 }
1033
1034               fflush (stream);
1035             }
1036           else /* print vtbl's nicely */
1037           if (is_vtbl_member(type))
1038             {
1039               CORE_ADDR vt_address = unpack_pointer (type, valaddr);
1040
1041               struct minimal_symbol *msymbol =
1042                 lookup_minimal_symbol_by_pc (vt_address);
1043               if ((msymbol != NULL) && (vt_address == msymbol -> address))
1044                 {
1045                   fputs_filtered (" <", stream);
1046                   fputs_demangled (msymbol -> name, stream,
1047                                    DMGL_ANSI | DMGL_PARAMS);
1048                   fputs_filtered (">", stream);
1049                 }
1050               if (vtblprint)
1051                 {
1052                   value vt_val;
1053
1054                   vt_val = value_at (TYPE_TARGET_TYPE (type), vt_address);
1055                   val_print (VALUE_TYPE (vt_val), VALUE_CONTENTS (vt_val),
1056                              VALUE_ADDRESS (vt_val), stream, format,
1057                              deref_ref, recurse + 1, pretty);
1058                   if (pretty)
1059                     {
1060                       fprintf_filtered (stream, "\n");
1061                       print_spaces_filtered (2 + 2 * recurse, stream);
1062                     }
1063                 }
1064               }
1065
1066           /* Return number of characters printed, plus one for the
1067              terminating null if we have "reached the end".  */
1068           return i + (print_max && i != print_max);
1069         }
1070       break;
1071
1072     case TYPE_CODE_MEMBER:
1073       error ("not implemented: member type in val_print");
1074       break;
1075
1076     case TYPE_CODE_REF:
1077       if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_MEMBER)
1078         {
1079           print_class_member (valaddr,
1080                               TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (type)),
1081                               stream, "");
1082           break;
1083         }
1084       if (addressprint)
1085         {
1086           fprintf_filtered (stream, "@0x%lx",
1087                             unpack_long (builtin_type_int, valaddr));
1088           if (deref_ref)
1089             fputs_filtered (": ", stream);
1090         }
1091       /* De-reference the reference.  */
1092       if (deref_ref)
1093         {
1094           if (TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_UNDEF)
1095             {
1096               value deref_val =
1097                 value_at
1098                   (TYPE_TARGET_TYPE (type),
1099                    unpack_pointer (lookup_pointer_type (builtin_type_void),
1100                                    valaddr));
1101               val_print (VALUE_TYPE (deref_val), VALUE_CONTENTS (deref_val),
1102                          VALUE_ADDRESS (deref_val), stream, format,
1103                          deref_ref, recurse + 1, pretty);
1104             }
1105           else
1106             fputs_filtered ("???", stream);
1107         }
1108       break;
1109
1110     case TYPE_CODE_UNION:
1111       if (recurse && !unionprint)
1112         {
1113           fprintf_filtered (stream, "{...}");
1114           break;
1115         }
1116       /* Fall through.  */
1117     case TYPE_CODE_STRUCT:
1118       if (vtblprint && is_vtbl_ptr_type(type))
1119         {
1120           /* Print the unmangled name if desired.  */
1121           print_address_demangle(*((int *) (valaddr +   /* FIXME bytesex */
1122               TYPE_FIELD_BITPOS (type, VTBL_FNADDR_OFFSET) / 8)),
1123               stream, demangle);
1124           break;
1125         }
1126       val_print_fields (type, valaddr, stream, format, recurse, pretty, 0);
1127       break;
1128
1129     case TYPE_CODE_ENUM:
1130       if (format)
1131         {
1132           print_scalar_formatted (valaddr, type, format, 0, stream);
1133           break;
1134         }
1135       len = TYPE_NFIELDS (type);
1136       val = unpack_long (builtin_type_int, valaddr);
1137       for (i = 0; i < len; i++)
1138         {
1139           QUIT;
1140           if (val == TYPE_FIELD_BITPOS (type, i))
1141             break;
1142         }
1143       if (i < len)
1144         fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
1145       else
1146 #ifdef LONG_LONG
1147         fprintf_filtered (stream, "%lld", val);
1148 #else
1149         fprintf_filtered (stream, "%ld", val);
1150 #endif
1151       break;
1152
1153     case TYPE_CODE_FUNC:
1154       if (format)
1155         {
1156           print_scalar_formatted (valaddr, type, format, 0, stream);
1157           break;
1158         }
1159       /* FIXME, we should consider, at least for ANSI C language, eliminating
1160          the distinction made between FUNCs and POINTERs to FUNCs.  */
1161       fprintf_filtered (stream, "{");
1162       type_print (type, "", stream, -1);
1163       fprintf_filtered (stream, "} ");
1164       /* Try to print what function it points to, and its address.  */
1165       print_address_demangle (address, stream, demangle);
1166       break;
1167
1168     case TYPE_CODE_INT:
1169       if (format || output_format)
1170         {
1171           print_scalar_formatted (valaddr, type,
1172                                   format? format: output_format,
1173                                   0, stream);
1174           break;
1175         }
1176       if (TYPE_LENGTH (type) > sizeof (LONGEST))
1177         {
1178           if (TYPE_UNSIGNED (type))
1179             {
1180               /* First figure out whether the number in fact has zeros
1181                  in all its bytes more significant than least significant
1182                  sizeof (LONGEST) ones.  */
1183               char *p;
1184               /* Pointer to first (i.e. lowest address) nonzero character.  */
1185               char *first_addr;
1186               len = TYPE_LENGTH (type);
1187
1188 #if TARGET_BYTE_ORDER == BIG_ENDIAN
1189               for (p = valaddr;
1190                    len > sizeof (LONGEST)
1191                    && p < valaddr + TYPE_LENGTH (type);
1192                    p++)
1193 #else /* Little endian.  */
1194               first_addr = valaddr;
1195               for (p = valaddr + TYPE_LENGTH (type);
1196                    len > sizeof (LONGEST) && p >= valaddr;
1197                    p--)
1198 #endif /* Little endian.  */
1199                 {
1200                   if (*p == 0)
1201                     len--;
1202                   else
1203                     break;
1204                 }
1205 #if TARGET_BYTE_ORDER == BIG_ENDIAN
1206               first_addr = p;
1207 #endif
1208               
1209               if (len <= sizeof (LONGEST))
1210                 {
1211                   /* We can print it in decimal.  */
1212                   fprintf_filtered
1213                     (stream, 
1214 #if defined (LONG_LONG)
1215                      "%llu",
1216 #else
1217                      "%lu",
1218 #endif
1219                      unpack_long (BUILTIN_TYPE_LONGEST, first_addr));
1220                 }
1221               else
1222                 {
1223                   /* It is big, so print it in hex.  */
1224                   print_hex_chars (stream, (unsigned char *)first_addr, len);
1225                 }
1226             }
1227           else
1228             {
1229               /* Signed.  One could assume two's complement (a reasonable
1230                  assumption, I think) and do better than this.  */
1231               print_hex_chars (stream, (unsigned char *)valaddr,
1232                                TYPE_LENGTH (type));
1233             }
1234           break;
1235         }
1236 #ifdef PRINT_TYPELESS_INTEGER
1237       PRINT_TYPELESS_INTEGER (stream, type, unpack_long (type, valaddr));
1238 #else
1239 #ifndef LONG_LONG
1240       fprintf_filtered (stream,
1241                         TYPE_UNSIGNED (type) ? "%u" : "%d",
1242                         unpack_long (type, valaddr));
1243 #else
1244       fprintf_filtered (stream,
1245                         TYPE_UNSIGNED (type) ? "%llu" : "%lld",
1246                         unpack_long (type, valaddr));
1247 #endif
1248 #endif
1249                         
1250       if (TYPE_LENGTH (type) == 1)
1251         {
1252           fprintf_filtered (stream, " '");
1253           printchar ((unsigned char) unpack_long (type, valaddr), 
1254                      stream, '\'');
1255           fprintf_filtered (stream, "'");
1256         }
1257       break;
1258
1259     case TYPE_CODE_FLT:
1260       if (format)
1261         print_scalar_formatted (valaddr, type, format, 0, stream);
1262       else
1263         print_floating (valaddr, type, stream);
1264       break;
1265
1266     case TYPE_CODE_VOID:
1267       fprintf_filtered (stream, "void");
1268       break;
1269
1270     case TYPE_CODE_UNDEF:
1271       /* This happens (without TYPE_FLAG_STUB set) on systems which don't use
1272          dbx xrefs (NO_DBX_XREFS in gcc) if a file has a "struct foo *bar"
1273          and no complete type for struct foo in that file.  */
1274       fprintf_filtered (stream, "<unknown struct>");
1275       break;
1276
1277     case TYPE_CODE_ERROR:
1278       fprintf_filtered (stream, "?");
1279       break;
1280
1281     case TYPE_CODE_RANGE:
1282       /* FIXME, we should not ever have to print one of these yet.  */
1283       fprintf_filtered (stream, "<range type>");
1284       break;
1285
1286     default:
1287       error ("Invalid type code in symbol table.");
1288     }
1289   fflush (stream);
1290   return 0;
1291 }
1292 \f
1293 /* Print a description of a type in the format of a 
1294    typedef for the current language.
1295    NEW is the new name for a type TYPE. */
1296 void
1297 typedef_print (type, new, stream)
1298    struct type *type;
1299    struct symbol *new;
1300    FILE *stream;
1301 {
1302    switch (current_language->la_language)
1303    {
1304 #ifdef _LANG_c
1305    case language_c:
1306    case language_cplus:
1307       fprintf_filtered(stream, "typedef ");
1308       type_print(type,"",stream,0);
1309       if(TYPE_NAME ((SYMBOL_TYPE (new))) == 0
1310          || 0 != strcmp (TYPE_NAME ((SYMBOL_TYPE (new))),
1311                          SYMBOL_NAME (new)))
1312          fprintf_filtered(stream,  " %s", SYMBOL_NAME(new));
1313       break;
1314 #endif
1315 #ifdef _LANG_m2
1316    case language_m2:
1317       fprintf_filtered(stream, "TYPE ");
1318       if(!TYPE_NAME(SYMBOL_TYPE(new)) ||
1319          strcmp (TYPE_NAME(SYMBOL_TYPE(new)),
1320                     SYMBOL_NAME(new)))
1321          fprintf_filtered(stream, "%s = ", SYMBOL_NAME(new));
1322       else
1323          fprintf_filtered(stream, "<builtin> = ");
1324       type_print(type,"",stream,0);
1325       break;
1326 #endif
1327    default:
1328       error("Language not supported.");
1329    }
1330    fprintf_filtered(stream, ";\n");
1331 }
1332
1333
1334 /* Print a description of a type TYPE
1335    in the form of a declaration of a variable named VARSTRING.
1336    (VARSTRING is demangled if necessary.)
1337    Output goes to STREAM (via stdio).
1338    If SHOW is positive, we show the contents of the outermost level
1339    of structure even if there is a type name that could be used instead.
1340    If SHOW is negative, we never show the details of elements' types.  */
1341
1342 void
1343 type_print (type, varstring, stream, show)
1344      struct type *type;
1345      char *varstring;
1346      FILE *stream;
1347      int show;
1348 {
1349   type_print_1 (type, varstring, stream, show, 0);
1350 }
1351
1352 /* LEVEL is the depth to indent lines by.  */
1353
1354 void
1355 type_print_1 (type, varstring, stream, show, level)
1356      struct type *type;
1357      char *varstring;
1358      FILE *stream;
1359      int show;
1360      int level;
1361 {
1362   register enum type_code code;
1363   char *demangled = NULL;
1364   int demangled_args;
1365
1366   type_print_base (type, stream, show, level);
1367   code = TYPE_CODE (type);
1368   if ((varstring && *varstring)
1369       ||
1370       /* Need a space if going to print stars or brackets;
1371          but not if we will print just a type name.  */
1372       ((show > 0 || TYPE_NAME (type) == 0)
1373        &&
1374        (code == TYPE_CODE_PTR || code == TYPE_CODE_FUNC
1375         || code == TYPE_CODE_METHOD
1376         || code == TYPE_CODE_ARRAY
1377         || code == TYPE_CODE_MEMBER
1378         || code == TYPE_CODE_REF)))
1379     fprintf_filtered (stream, " ");
1380   type_print_varspec_prefix (type, stream, show, 0);
1381
1382   /* See if the name has a C++ demangled equivalent, and if so, print that
1383      instead. */
1384
1385   if (demangle)
1386     {
1387       demangled = cplus_demangle (varstring, DMGL_ANSI | DMGL_PARAMS);
1388     }
1389   fputs_filtered ((demangled != NULL) ? demangled : varstring, stream);
1390
1391   /* For demangled function names, we have the arglist as part of the name,
1392      so don't print an additional pair of ()'s */
1393
1394   demangled_args = (demangled != NULL) && (code == TYPE_CODE_FUNC);
1395   type_print_varspec_suffix (type, stream, show, 0, demangled_args);
1396
1397   if (demangled)
1398     {
1399       free (demangled);
1400     }
1401 }
1402
1403 /* Print the method arguments ARGS to the file STREAM.  */
1404 static void
1405 type_print_method_args (args, prefix, varstring, staticp, stream)
1406      struct type **args;
1407      char *prefix, *varstring;
1408      int staticp;
1409      FILE *stream;
1410 {
1411   int i;
1412
1413   fputs_demangled (prefix, stream, DMGL_ANSI | DMGL_PARAMS);
1414   fputs_demangled (varstring, stream, DMGL_ANSI | DMGL_PARAMS);
1415   fputs_filtered (" (", stream);
1416   if (args && args[!staticp] && args[!staticp]->code != TYPE_CODE_VOID)
1417     {
1418       i = !staticp;             /* skip the class variable */
1419       while (1)
1420         {
1421           type_print (args[i++], "", stream, 0);
1422           if (!args[i]) 
1423             {
1424               fprintf_filtered (stream, " ...");
1425               break;
1426             }
1427           else if (args[i]->code != TYPE_CODE_VOID)
1428             {
1429               fprintf_filtered (stream, ", ");
1430             }
1431           else break;
1432         }
1433     }
1434   fprintf_filtered (stream, ")");
1435 }
1436   
1437 /* If TYPE is a derived type, then print out derivation information.
1438    Print only the actual base classes of this type, not the base classes
1439    of the base classes.  I.E.  for the derivation hierarchy:
1440
1441         class A { int a; };
1442         class B : public A {int b; };
1443         class C : public B {int c; };
1444
1445    Print the type of class C as:
1446
1447         class C : public B {
1448                 int c;
1449         }
1450
1451    Not as the following (like gdb used to), which is not legal C++ syntax for
1452    derived types and may be confused with the multiple inheritance form:
1453
1454         class C : public B : public A {
1455                 int c;
1456         }
1457
1458    In general, gdb should try to print the types as closely as possible to
1459    the form that they appear in the source code. */
1460
1461 static void
1462 type_print_derivation_info (stream, type)
1463      FILE *stream;
1464      struct type *type;
1465 {
1466   char *name;
1467   int i;
1468
1469   for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
1470     {
1471       fputs_filtered (i == 0 ? ": " : ", ", stream);
1472       fprintf_filtered (stream, "%s%s ",
1473                         BASETYPE_VIA_PUBLIC (type, i) ? "public" : "private",
1474                         BASETYPE_VIA_VIRTUAL(type, i) ? " virtual" : "");
1475       name = type_name_no_tag (TYPE_BASECLASS (type, i));
1476       fprintf_filtered (stream, "%s ", name ? name : "(null)");
1477     }
1478 }
1479
1480 /* Print any asterisks or open-parentheses needed before the
1481    variable name (to describe its type).
1482
1483    On outermost call, pass 0 for PASSED_A_PTR.
1484    On outermost call, SHOW > 0 means should ignore
1485    any typename for TYPE and show its details.
1486    SHOW is always zero on recursive calls.  */
1487
1488 static void
1489 type_print_varspec_prefix (type, stream, show, passed_a_ptr)
1490      struct type *type;
1491      FILE *stream;
1492      int show;
1493      int passed_a_ptr;
1494 {
1495   char *name;
1496   if (type == 0)
1497     return;
1498
1499   if (TYPE_NAME (type) && show <= 0)
1500     return;
1501
1502   QUIT;
1503
1504   switch (TYPE_CODE (type))
1505     {
1506     case TYPE_CODE_PTR:
1507       type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 1);
1508       fprintf_filtered (stream, "*");
1509       break;
1510
1511     case TYPE_CODE_MEMBER:
1512       if (passed_a_ptr)
1513         fprintf_filtered (stream, "(");
1514       type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0,
1515                                  0);
1516       fprintf_filtered (stream, " ");
1517       name = type_name_no_tag (TYPE_DOMAIN_TYPE (type));
1518       if (name)
1519         fputs_filtered (name, stream);
1520       else
1521         type_print_base (TYPE_DOMAIN_TYPE (type), stream, 0, passed_a_ptr);
1522       fprintf_filtered (stream, "::");
1523       break;
1524
1525     case TYPE_CODE_METHOD:
1526       if (passed_a_ptr)
1527         fprintf (stream, "(");
1528       type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0,
1529                                  0);
1530       if (passed_a_ptr)
1531         {
1532           fprintf_filtered (stream, " ");
1533           type_print_base (TYPE_DOMAIN_TYPE (type), stream, 0,
1534                            passed_a_ptr);
1535           fprintf_filtered (stream, "::");
1536         }
1537       break;
1538
1539     case TYPE_CODE_REF:
1540       type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 1);
1541       fprintf_filtered (stream, "&");
1542       break;
1543
1544     case TYPE_CODE_FUNC:
1545       type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0,
1546                                  0);
1547       if (passed_a_ptr)
1548         fprintf_filtered (stream, "(");
1549       break;
1550
1551     case TYPE_CODE_ARRAY:
1552       type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0,
1553                                  0);
1554       if (passed_a_ptr)
1555         fprintf_filtered (stream, "(");
1556       break;
1557
1558     case TYPE_CODE_UNDEF:
1559     case TYPE_CODE_STRUCT:
1560     case TYPE_CODE_UNION:
1561     case TYPE_CODE_ENUM:
1562     case TYPE_CODE_INT:
1563     case TYPE_CODE_FLT:
1564     case TYPE_CODE_VOID:
1565     case TYPE_CODE_ERROR:
1566     case TYPE_CODE_CHAR:
1567     case TYPE_CODE_BOOL:
1568     case TYPE_CODE_SET:
1569     case TYPE_CODE_RANGE:
1570     case TYPE_CODE_PASCAL_ARRAY:
1571       /* These types need no prefix.  They are listed here so that
1572          gcc -Wall will reveal any types that haven't been handled.  */
1573       break;
1574     }
1575 }
1576
1577 static void
1578 type_print_args (type, stream)
1579      struct type *type;
1580      FILE *stream;
1581 {
1582   int i;
1583   struct type **args;
1584
1585   fprintf_filtered (stream, "(");
1586   args = TYPE_ARG_TYPES (type);
1587   if (args != NULL)
1588     {
1589       if (args[1] == NULL)
1590         {
1591           fprintf_filtered (stream, "...");
1592         }
1593       else
1594         {
1595           for (i = 1;
1596                args[i] != NULL && args[i]->code != TYPE_CODE_VOID;
1597                i++)
1598             {
1599               type_print_1 (args[i], "", stream, -1, 0);
1600               if (args[i+1] == NULL)
1601                 {
1602                   fprintf_filtered (stream, "...");
1603                 }
1604               else if (args[i+1]->code != TYPE_CODE_VOID)
1605                 {
1606                   fprintf_filtered (stream, ",");
1607                   wrap_here ("    ");
1608                 }
1609             }
1610         }
1611     }
1612   fprintf_filtered (stream, ")");
1613 }
1614
1615 /* Print any array sizes, function arguments or close parentheses
1616    needed after the variable name (to describe its type).
1617    Args work like type_print_varspec_prefix.  */
1618
1619 static void
1620 type_print_varspec_suffix (type, stream, show, passed_a_ptr, demangled_args)
1621      struct type *type;
1622      FILE *stream;
1623      int show;
1624      int passed_a_ptr;
1625      int demangled_args;
1626 {
1627   if (type == 0)
1628     return;
1629
1630   if (TYPE_NAME (type) && show <= 0)
1631     return;
1632
1633   QUIT;
1634
1635   switch (TYPE_CODE (type))
1636     {
1637     case TYPE_CODE_ARRAY:
1638       if (passed_a_ptr)
1639         fprintf_filtered (stream, ")");
1640       
1641       fprintf_filtered (stream, "[");
1642       if (TYPE_LENGTH (type) > 0
1643           && TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0)
1644         fprintf_filtered (stream, "%d",
1645                           (TYPE_LENGTH (type)
1646                            / TYPE_LENGTH (TYPE_TARGET_TYPE (type))));
1647       fprintf_filtered (stream, "]");
1648       
1649       type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0,
1650                                  0, 0);
1651       break;
1652
1653     case TYPE_CODE_MEMBER:
1654       if (passed_a_ptr)
1655         fprintf_filtered (stream, ")");
1656       type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0, 0);
1657       break;
1658
1659     case TYPE_CODE_METHOD:
1660       if (passed_a_ptr)
1661         fprintf_filtered (stream, ")");
1662       type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0, 0);
1663       if (passed_a_ptr)
1664         {
1665           type_print_args (type, stream);
1666         }
1667       break;
1668
1669     case TYPE_CODE_PTR:
1670     case TYPE_CODE_REF:
1671       type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 1, 0);
1672       break;
1673
1674     case TYPE_CODE_FUNC:
1675       type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0,
1676                                  passed_a_ptr, 0);
1677       if (passed_a_ptr)
1678         fprintf_filtered (stream, ")");
1679       if (!demangled_args)
1680         fprintf_filtered (stream, "()");
1681       break;
1682
1683     case TYPE_CODE_UNDEF:
1684     case TYPE_CODE_STRUCT:
1685     case TYPE_CODE_UNION:
1686     case TYPE_CODE_ENUM:
1687     case TYPE_CODE_INT:
1688     case TYPE_CODE_FLT:
1689     case TYPE_CODE_VOID:
1690     case TYPE_CODE_ERROR:
1691     case TYPE_CODE_CHAR:
1692     case TYPE_CODE_BOOL:
1693     case TYPE_CODE_SET:
1694     case TYPE_CODE_RANGE:
1695     case TYPE_CODE_PASCAL_ARRAY:
1696       /* These types do not need a suffix.  They are listed so that
1697          gcc -Wall will report types that may not have been considered.  */
1698       break;
1699     }
1700 }
1701
1702 /* Print the name of the type (or the ultimate pointer target,
1703    function value or array element), or the description of a
1704    structure or union.
1705
1706    SHOW nonzero means don't print this type as just its name;
1707    show its real definition even if it has a name.
1708    SHOW zero means print just typename or struct tag if there is one
1709    SHOW negative means abbreviate structure elements.
1710    SHOW is decremented for printing of structure elements.
1711
1712    LEVEL is the depth to indent by.
1713    We increase it for some recursive calls.  */
1714
1715 static void
1716 type_print_base (type, stream, show, level)
1717      struct type *type;
1718      FILE *stream;
1719      int show;
1720      int level;
1721 {
1722   char *name;
1723   register int i;
1724   register int len;
1725   register int lastval;
1726   char *mangled_name;
1727   char *demangled_name;
1728   enum {s_none, s_public, s_private, s_protected} section_type;
1729   QUIT;
1730
1731   wrap_here ("    ");
1732   if (type == NULL)
1733     {
1734       fputs_filtered ("<type unknown>", stream);
1735       return;
1736     }
1737
1738   /* When SHOW is zero or less, and there is a valid type name, then always
1739      just print the type name directly from the type. */
1740
1741   if ((show <= 0) && (TYPE_NAME (type) != NULL))
1742     {
1743       fputs_filtered (TYPE_NAME (type), stream);
1744       return;
1745     }
1746
1747   switch (TYPE_CODE (type))
1748     {
1749     case TYPE_CODE_ARRAY:
1750     case TYPE_CODE_PTR:
1751     case TYPE_CODE_MEMBER:
1752     case TYPE_CODE_REF:
1753     case TYPE_CODE_FUNC:
1754     case TYPE_CODE_METHOD:
1755       type_print_base (TYPE_TARGET_TYPE (type), stream, show, level);
1756       break;
1757
1758     case TYPE_CODE_STRUCT:
1759       fprintf_filtered (stream,
1760                         HAVE_CPLUS_STRUCT (type) ? "class " : "struct ");
1761       goto struct_union;
1762
1763     case TYPE_CODE_UNION:
1764       fprintf_filtered (stream, "union ");
1765     struct_union:
1766       if (name = type_name_no_tag (type))
1767         {
1768           fputs_filtered (name, stream);
1769           fputs_filtered (" ", stream);
1770           wrap_here ("    ");
1771         }
1772       if (show < 0)
1773         fprintf_filtered (stream, "{...}");
1774       else
1775         {
1776           check_stub_type (type);
1777           
1778           type_print_derivation_info (stream, type);
1779           
1780           fprintf_filtered (stream, "{\n");
1781           if ((TYPE_NFIELDS (type) == 0) && (TYPE_NFN_FIELDS (type) == 0))
1782             {
1783               if (TYPE_FLAGS (type) & TYPE_FLAG_STUB)
1784                 fprintfi_filtered (level + 4, stream, "<incomplete type>\n");
1785               else
1786                 fprintfi_filtered (level + 4, stream, "<no data fields>\n");
1787             }
1788
1789           /* Start off with no specific section type, so we can print
1790              one for the first field we find, and use that section type
1791              thereafter until we find another type. */
1792
1793           section_type = s_none;
1794
1795           /* If there is a base class for this type,
1796              do not print the field that it occupies.  */
1797
1798           len = TYPE_NFIELDS (type);
1799           for (i = TYPE_N_BASECLASSES (type); i < len; i++)
1800             {
1801               QUIT;
1802               /* Don't print out virtual function table.  */
1803               if ((TYPE_FIELD_NAME (type, i))[5] == CPLUS_MARKER &&
1804                   !strncmp (TYPE_FIELD_NAME (type, i), "_vptr", 5))
1805                 continue;
1806
1807               /* If this is a C++ class we can print the various C++ section
1808                  labels. */
1809
1810               if (HAVE_CPLUS_STRUCT (type))
1811                 {
1812                   if (TYPE_FIELD_PROTECTED (type, i))
1813                     {
1814                       if (section_type != s_protected)
1815                         {
1816                           section_type = s_protected;
1817                           fprintfi_filtered (level + 2, stream,
1818                                              "protected:\n");
1819                         }
1820                     }
1821                   else if (TYPE_FIELD_PRIVATE (type, i))
1822                     {
1823                       if (section_type != s_private)
1824                         {
1825                           section_type = s_private;
1826                           fprintfi_filtered (level + 2, stream, "private:\n");
1827                         }
1828                     }
1829                   else
1830                     {
1831                       if (section_type != s_public)
1832                         {
1833                           section_type = s_public;
1834                           fprintfi_filtered (level + 2, stream, "public:\n");
1835                         }
1836                     }
1837                 }
1838
1839               print_spaces_filtered (level + 4, stream);
1840               if (TYPE_FIELD_STATIC (type, i))
1841                 {
1842                   fprintf_filtered (stream, "static ");
1843                 }
1844               type_print_1 (TYPE_FIELD_TYPE (type, i),
1845                             TYPE_FIELD_NAME (type, i),
1846                             stream, show - 1, level + 4);
1847               if (!TYPE_FIELD_STATIC (type, i)
1848                   && TYPE_FIELD_PACKED (type, i))
1849                 {
1850                   /* It is a bitfield.  This code does not attempt
1851                      to look at the bitpos and reconstruct filler,
1852                      unnamed fields.  This would lead to misleading
1853                      results if the compiler does not put out fields
1854                      for such things (I don't know what it does).  */
1855                   fprintf_filtered (stream, " : %d",
1856                                     TYPE_FIELD_BITSIZE (type, i));
1857                 }
1858               fprintf_filtered (stream, ";\n");
1859             }
1860
1861           /* C++: print out the methods */
1862           len = TYPE_NFN_FIELDS (type);
1863           for (i = 0; i < len; i++)
1864             {
1865               struct fn_field *f = TYPE_FN_FIELDLIST1 (type, i);
1866               int j, len2 = TYPE_FN_FIELDLIST_LENGTH (type, i);
1867               char *method_name = TYPE_FN_FIELDLIST_NAME (type, i);
1868               int is_constructor = name && strcmp(method_name, name) == 0;
1869               for (j = 0; j < len2; j++)
1870                 {
1871                   QUIT;
1872                   if (TYPE_FN_FIELD_PROTECTED (f, j))
1873                     {
1874                       if (section_type != s_protected)
1875                         {
1876                           section_type = s_protected;
1877                           fprintfi_filtered (level + 2, stream,
1878                                              "protected:\n");
1879                         }
1880                     }
1881                   else if (TYPE_FN_FIELD_PRIVATE (f, j))
1882                     {
1883                       if (section_type != s_private)
1884                         {
1885                           section_type = s_private;
1886                           fprintfi_filtered (level + 2, stream, "private:\n");
1887                         }
1888                     }
1889                   else
1890                     {
1891                       if (section_type != s_public)
1892                         {
1893                           section_type = s_public;
1894                           fprintfi_filtered (level + 2, stream, "public:\n");
1895                         }
1896                     }
1897
1898                   print_spaces_filtered (level + 4, stream);
1899                   if (TYPE_FN_FIELD_VIRTUAL_P (f, j))
1900                     fprintf_filtered (stream, "virtual ");
1901                   else if (TYPE_FN_FIELD_STATIC_P (f, j))
1902                     fprintf_filtered (stream, "static ");
1903                   if (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)) == 0)
1904                     {
1905                       /* Keep GDB from crashing here.  */
1906                       fprintf (stream, "<undefined type> %s;\n",
1907                                TYPE_FN_FIELD_PHYSNAME (f, j));
1908                       break;
1909                     }
1910                   else if (!is_constructor)
1911                     {
1912                       type_print (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)),
1913                                   "", stream, 0);
1914                       fputs_filtered (" ", stream);
1915                     }
1916                   if (TYPE_FN_FIELD_STUB (f, j))
1917                     {
1918                       /* Build something we can demangle.  */
1919                       mangled_name = gdb_mangle_name (type, i, j);
1920                       demangled_name =
1921                           cplus_demangle (mangled_name,
1922                                           DMGL_ANSI | DMGL_PARAMS);
1923                       if (demangled_name == NULL)
1924                         fprintf_filtered (stream, "<badly mangled name %s>",
1925                             mangled_name);
1926                       else 
1927                         {
1928                           fprintf_filtered (stream, "%s",
1929                               strchr (demangled_name, ':') + 2);
1930                           free (demangled_name);
1931                         }
1932                       free (mangled_name);
1933                     }
1934                   else if (TYPE_FN_FIELD_PHYSNAME (f, j)[0] == '_'
1935                         && TYPE_FN_FIELD_PHYSNAME (f, j)[1] == CPLUS_MARKER)
1936                     type_print_method_args
1937                       (TYPE_FN_FIELD_ARGS (f, j) + 1, "~",
1938                        method_name, 0, stream);
1939                   else
1940                     type_print_method_args
1941                       (TYPE_FN_FIELD_ARGS (f, j), "",
1942                        method_name,
1943                        TYPE_FN_FIELD_STATIC_P (f, j), stream);
1944
1945                   fprintf_filtered (stream, ";\n");
1946                 }
1947             }
1948
1949           fprintfi_filtered (level, stream, "}");
1950         }
1951       break;
1952
1953     case TYPE_CODE_ENUM:
1954       fprintf_filtered (stream, "enum ");
1955       if (name = type_name_no_tag (type))
1956         {
1957           fputs_filtered (name, stream);
1958           fputs_filtered (" ", stream);
1959         }
1960       wrap_here ("    ");
1961       if (show < 0)
1962         fprintf_filtered (stream, "{...}");
1963       else
1964         {
1965           fprintf_filtered (stream, "{");
1966           len = TYPE_NFIELDS (type);
1967           lastval = 0;
1968           for (i = 0; i < len; i++)
1969             {
1970               QUIT;
1971               if (i) fprintf_filtered (stream, ", ");
1972               wrap_here ("    ");
1973               fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
1974               if (lastval != TYPE_FIELD_BITPOS (type, i))
1975                 {
1976                   fprintf_filtered (stream, " = %d", TYPE_FIELD_BITPOS (type, i));
1977                   lastval = TYPE_FIELD_BITPOS (type, i);
1978                 }
1979               lastval++;
1980             }
1981           fprintf_filtered (stream, "}");
1982         }
1983       break;
1984
1985     case TYPE_CODE_VOID:
1986       fprintf_filtered (stream, "void");
1987       break;
1988
1989     case TYPE_CODE_UNDEF:
1990       fprintf_filtered (stream, "struct <unknown>");
1991       break;
1992
1993     case TYPE_CODE_ERROR:
1994       fprintf_filtered (stream, "<unknown type>");
1995       break;
1996
1997     case TYPE_CODE_RANGE:
1998       /* This should not occur */
1999       fprintf_filtered (stream, "<range type>");
2000       break;
2001
2002     default:
2003       /* Handle types not explicitly handled by the other cases,
2004          such as fundamental types.  For these, just print whatever
2005          the type name is, as recorded in the type itself.  If there
2006          is no type name, then complain. */
2007       if (TYPE_NAME (type) != NULL)
2008         {
2009           fputs_filtered (TYPE_NAME (type), stream);
2010         }
2011       else
2012         {
2013           error ("Invalid type code (%d) in symbol table.", TYPE_CODE (type));
2014         }
2015       break;
2016     }
2017 }
2018 \f
2019 #if 0
2020 /* Validate an input or output radix setting, and make sure the user
2021    knows what they really did here.  Radix setting is confusing, e.g.
2022    setting the input radix to "10" never changes it!  */
2023
2024 /* ARGSUSED */
2025 static void
2026 set_input_radix (args, from_tty, c)
2027      char *args;
2028      int from_tty;
2029      struct cmd_list_element *c;
2030 {
2031   unsigned radix = *(unsigned *)c->var;
2032
2033   if (from_tty)
2034     printf_filtered ("Input radix set to decimal %d, hex %x, octal %o\n",
2035         radix, radix, radix);
2036 }
2037 #endif
2038
2039 /* ARGSUSED */
2040 static void
2041 set_output_radix (args, from_tty, c)
2042      char *args;
2043      int from_tty;
2044      struct cmd_list_element *c;
2045 {
2046   unsigned radix = *(unsigned *)c->var;
2047
2048   if (from_tty)
2049     printf_filtered ("Output radix set to decimal %d, hex %x, octal %o\n",
2050         radix, radix, radix);
2051
2052   /* FIXME, we really should be able to validate the setting BEFORE
2053      it takes effect.  */
2054   switch (radix)
2055     {
2056     case 16:
2057       output_format = 'x';
2058       break;
2059     case 10:
2060       output_format = 0;
2061       break;
2062     case 8:
2063       output_format = 'o';              /* octal */
2064       break;
2065     default:
2066       output_format = 0;
2067       error ("Unsupported radix ``decimal %d''; using decimal output",
2068               radix);
2069     }
2070 }
2071
2072 /* Both at once */
2073 static void
2074 set_radix (arg, from_tty, c)
2075      char *arg;
2076      int from_tty;
2077      struct cmd_list_element *c;
2078 {
2079   unsigned radix = *(unsigned *)c->var;
2080
2081   if (from_tty)
2082     printf_filtered ("Radix set to decimal %d, hex %x, octal %o\n",
2083         radix, radix, radix);
2084
2085   input_radix = radix;
2086   output_radix = radix;
2087
2088   set_output_radix (arg, 0, c);
2089 }
2090 \f
2091 /*ARGSUSED*/
2092 static void
2093 set_print (arg, from_tty)
2094      char *arg;
2095      int from_tty;
2096 {
2097   printf (
2098 "\"set print\" must be followed by the name of a print subcommand.\n");
2099   help_list (setprintlist, "set print ", -1, stdout);
2100 }
2101
2102 /*ARGSUSED*/
2103 static void
2104 show_print (args, from_tty)
2105      char *args;
2106      int from_tty;
2107 {
2108   cmd_show_list (showprintlist, from_tty, "");
2109 }
2110 \f
2111 void
2112 _initialize_valprint ()
2113 {
2114   struct cmd_list_element *c;
2115
2116   add_prefix_cmd ("print", no_class, set_print,
2117                   "Generic command for setting how things print.",
2118                   &setprintlist, "set print ", 0, &setlist);
2119   add_alias_cmd ("p", "print", no_class, 1, &setlist); 
2120   add_alias_cmd ("pr", "print", no_class, 1, &setlist); /* prefer set print
2121                                                                                                                    to     set prompt */
2122   add_prefix_cmd ("print", no_class, show_print,
2123                   "Generic command for showing print settings.",
2124                   &showprintlist, "show print ", 0, &showlist);
2125   add_alias_cmd ("p", "print", no_class, 1, &showlist); 
2126   add_alias_cmd ("pr", "print", no_class, 1, &showlist); 
2127
2128   add_show_from_set
2129     (add_set_cmd ("elements", no_class, var_uinteger, (char *)&print_max,
2130                   "Set limit on string chars or array elements to print.\n\
2131 \"set print elements 0\" causes there to be no limit.",
2132                   &setprintlist),
2133      &showprintlist);
2134
2135   add_show_from_set
2136     (add_set_cmd ("pretty", class_support, var_boolean, (char *)&prettyprint,
2137                   "Set prettyprinting of structures.",
2138                   &setprintlist),
2139      &showprintlist);
2140
2141   add_show_from_set
2142     (add_set_cmd ("union", class_support, var_boolean, (char *)&unionprint,
2143                   "Set printing of unions interior to structures.",
2144                   &setprintlist),
2145      &showprintlist);
2146   
2147   add_show_from_set
2148     (add_set_cmd ("vtbl", class_support, var_boolean, (char *)&vtblprint,
2149                   "Set printing of C++ virtual function tables.",
2150                   &setprintlist),
2151      &showprintlist);
2152
2153   add_show_from_set
2154     (add_set_cmd ("array", class_support, var_boolean, (char *)&arrayprint,
2155                   "Set prettyprinting of arrays.",
2156                   &setprintlist),
2157      &showprintlist);
2158
2159   add_show_from_set
2160     (add_set_cmd ("object", class_support, var_boolean, (char *)&objectprint,
2161           "Set printing of object's derived type based on vtable info.",
2162                   &setprintlist),
2163      &showprintlist);
2164
2165   add_show_from_set
2166     (add_set_cmd ("address", class_support, var_boolean, (char *)&addressprint,
2167                   "Set printing of addresses.",
2168                   &setprintlist),
2169      &showprintlist);
2170
2171 #if 0
2172   /* The "show radix" cmd isn't good enough to show two separate values.
2173      The rest of the code works, but the show part is confusing, so don't
2174      let them be set separately 'til we work out "show".  */
2175   c = add_set_cmd ("input-radix", class_support, var_uinteger,
2176                    (char *)&input_radix,
2177                   "Set default input radix for entering numbers.",
2178                   &setlist);
2179   add_show_from_set (c, &showlist);
2180   c->function = set_input_radix;
2181
2182   c = add_set_cmd ("output-radix", class_support, var_uinteger,
2183                    (char *)&output_radix,
2184                   "Set default output radix for printing of values.",
2185                   &setlist);
2186   add_show_from_set (c, &showlist);
2187   c->function = set_output_radix;
2188 #endif 
2189
2190   c = add_set_cmd ("radix", class_support, var_uinteger,
2191                    (char *)&output_radix,
2192                   "Set default input and output number radix.",
2193                   &setlist);
2194   add_show_from_set (c, &showlist);
2195   c->function.sfunc = set_radix;
2196
2197   /* Give people the defaults which they are used to.  */
2198   prettyprint = 0;
2199   unionprint = 1;
2200   vtblprint = 0;
2201   arrayprint = 0;
2202   addressprint = 1;
2203   objectprint = 0;
2204
2205   print_max = 200;
2206
2207   obstack_begin (&dont_print_obstack, 32 * sizeof (struct type *));
2208 }