]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/valprint.c
A ton of changes to improve C++ debugging. See ChangeLog.
[thirdparty/binutils-gdb.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) || TYPE_FIELD_NESTED (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 /* 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)));
636
637 if (pretty)
638 {
639 fprintf_filtered (stream, "\n");
640 print_spaces_filtered (2 * recurse, stream);
641 }
642 fputs_filtered ("<", stream);
643 fputs_filtered (type_name_no_tag (TYPE_BASECLASS (type, i)), stream);
644 fputs_filtered ("> = ", stream);
645 if (err != 0)
646 fprintf_filtered (stream, "<invalid address 0x%x>", baddr);
647 else
648 val_print_fields (TYPE_BASECLASS (type, i), baddr, stream, format,
649 recurse, pretty,
650 (struct type **)obstack_base (&dont_print_obstack));
651 fputs_filtered (", ", stream);
652
653 flush_it:
654 ;
655 }
656
657 if (dont_print == 0)
658 {
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;
665 }
666 }
667
668 static void
669 print_class_member (valaddr, domain, stream, prefix)
670 char *valaddr;
671 struct type *domain;
672 FILE *stream;
673 char *prefix;
674 {
675
676 /* VAL is a byte offset into the structure type DOMAIN.
677 Find the name of the field for that offset and
678 print it. */
679 int extra = 0;
680 int bits = 0;
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++)
686 {
687 int bitpos = TYPE_FIELD_BITPOS (domain, i);
688 QUIT;
689 if (val == bitpos)
690 break;
691 if (val < bitpos && i != 0)
692 {
693 /* Somehow pointing into a field. */
694 i -= 1;
695 extra = (val - TYPE_FIELD_BITPOS (domain, i));
696 if (extra & 0x7)
697 bits = 1;
698 else
699 extra >>= 3;
700 break;
701 }
702 }
703 if (i < len)
704 {
705 char *name;
706 fprintf_filtered (stream, prefix);
707 name = type_name_no_tag (domain);
708 if (name)
709 fputs_filtered (name, stream);
710 else
711 type_print_base (domain, stream, 0, 0);
712 fprintf_filtered (stream, "::");
713 fputs_filtered (TYPE_FIELD_NAME (domain, i), stream);
714 if (extra)
715 fprintf_filtered (stream, " + %d bytes", extra);
716 if (bits)
717 fprintf_filtered (stream, " (offset in bits)");
718 }
719 else
720 fprintf_filtered (stream, "%d", val >> 3);
721 }
722
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.
728
729 If the data are a string pointer, returns the number of
730 sting characters printed.
731
732 if DEREF_REF is nonzero, then dereference references,
733 otherwise just print them like pointers.
734
735 The PRETTY parameter controls prettyprinting. */
736
737 int
738 val_print (type, valaddr, address, stream, format, deref_ref, recurse, pretty)
739 struct type *type;
740 char *valaddr;
741 CORE_ADDR address;
742 FILE *stream;
743 int format;
744 int deref_ref;
745 int recurse;
746 enum val_prettyprint pretty;
747 {
748 register unsigned int i;
749 unsigned len;
750 struct type *elttype;
751 unsigned eltlen;
752 LONGEST val;
753 unsigned char c;
754
755 if (pretty == Val_pretty_default)
756 {
757 pretty = prettyprint ? Val_prettyprint : Val_no_prettyprint;
758 }
759
760 QUIT;
761
762 check_stub_type (type);
763
764 if (TYPE_FLAGS (type) & TYPE_FLAG_STUB)
765 {
766 fprintf_filtered (stream, "<unknown struct>");
767 fflush (stream);
768 return 0;
769 }
770
771 switch (TYPE_CODE (type))
772 {
773 case TYPE_CODE_ARRAY:
774 if (TYPE_LENGTH (type) > 0
775 && TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0)
776 {
777 elttype = TYPE_TARGET_TYPE (type);
778 eltlen = TYPE_LENGTH (elttype);
779 len = TYPE_LENGTH (type) / eltlen;
780 if (arrayprint)
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);
787 else
788 {
789 unsigned int things_printed = 0;
790
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))
794 {
795 fprintf_filtered (stream, "%d vtable entries", len-1);
796 i = 1;
797 }
798 else
799 i = 0;
800
801 for (; i < len && things_printed < print_max; i++)
802 {
803 /* Position of the array element we are examining to see
804 whether it is repeated. */
805 unsigned int rep1;
806 /* Number of repetitions we have detected so far. */
807 unsigned int reps;
808
809 if (i != 0)
810 if (arrayprint)
811 {
812 fprintf_filtered (stream, ",\n");
813 print_spaces_filtered (2 + 2 * recurse, stream);
814 }
815 else
816 fprintf_filtered (stream, ", ");
817 wrap_here (n_spaces (2 + 2 * recurse));
818
819 rep1 = i + 1;
820 reps = 1;
821 while (rep1 < len
822 && !memcmp (valaddr + i * eltlen,
823 valaddr + rep1 * eltlen, eltlen))
824 {
825 ++reps;
826 ++rep1;
827 }
828
829 if (reps > REPEAT_COUNT_THRESHOLD)
830 {
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);
835 i = rep1 - 1;
836 things_printed += REPEAT_COUNT_THRESHOLD;
837 }
838 else
839 {
840 val_print (elttype, valaddr + i * eltlen,
841 0, stream, format, deref_ref,
842 recurse + 1, pretty);
843 things_printed++;
844 }
845 }
846 if (i < len)
847 fprintf_filtered (stream, "...");
848 }
849 fprintf_filtered (stream, "}");
850 break;
851 }
852 /* Array of unspecified length: treat like pointer to first elt. */
853 valaddr = (char *) &address;
854
855 case TYPE_CODE_PTR:
856 if (format && format != 's')
857 {
858 print_scalar_formatted (valaddr, type, format, 0, stream);
859 break;
860 }
861 if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_METHOD)
862 {
863 struct type *domain = TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (type));
864 struct fn_field *f;
865 int j, len2;
866 char *kind = "";
867 CORE_ADDR addr;
868
869 addr = unpack_pointer (lookup_pointer_type (builtin_type_void),
870 valaddr);
871 if (METHOD_PTR_IS_VIRTUAL(addr))
872 {
873 int offset = METHOD_PTR_TO_VOFFSET(addr);
874 len = TYPE_NFN_FIELDS (domain);
875 for (i = 0; i < len; i++)
876 {
877 f = TYPE_FN_FIELDLIST1 (domain, i);
878 len2 = TYPE_FN_FIELDLIST_LENGTH (domain, i);
879
880 for (j = 0; j < len2; j++)
881 {
882 QUIT;
883 if (TYPE_FN_FIELD_VOFFSET (f, j) == offset)
884 {
885 kind = "virtual ";
886 goto common;
887 }
888 }
889 }
890 }
891 else
892 {
893 struct symbol *sym = find_pc_function (addr);
894 if (sym == 0)
895 error ("invalid pointer to member function");
896 len = TYPE_NFN_FIELDS (domain);
897 for (i = 0; i < len; i++)
898 {
899 f = TYPE_FN_FIELDLIST1 (domain, i);
900 len2 = TYPE_FN_FIELDLIST_LENGTH (domain, i);
901
902 for (j = 0; j < len2; j++)
903 {
904 QUIT;
905 if (!strcmp (SYMBOL_NAME (sym), TYPE_FN_FIELD_PHYSNAME (f, j)))
906 goto common;
907 }
908 }
909 }
910 common:
911 if (i < len)
912 {
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);
921 else
922 type_print_method_args
923 (TYPE_FN_FIELD_ARGS (f, j), "",
924 TYPE_FN_FIELDLIST_NAME (domain, i), 0, stream);
925 break;
926 }
927 fprintf_filtered (stream, "(");
928 type_print (type, "", stream, -1);
929 fprintf_filtered (stream, ") %d", (int) addr >> 3);
930 }
931 else if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_MEMBER)
932 {
933 print_class_member (valaddr,
934 TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (type)),
935 stream, "&");
936 }
937 else
938 {
939 CORE_ADDR addr = unpack_pointer (type, valaddr);
940 elttype = TYPE_TARGET_TYPE (type);
941
942 if (TYPE_CODE (elttype) == TYPE_CODE_FUNC)
943 {
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. */
947 return 0;
948 }
949
950 if (addressprint && format != 's')
951 fprintf_filtered (stream, "0x%x", addr);
952
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')
959 && addr != 0
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)
963 {
964 int first_addr_err = 0;
965 int errcode = 0;
966
967 /* Get first character. */
968 errcode = target_read_memory (addr, (char *)&c, 1);
969 if (errcode != 0)
970 {
971 /* First address out of bounds. */
972 first_addr_err = 1;
973 }
974 else
975 {
976 /* A real string. */
977 char *string = (char *) alloca (print_max);
978
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;
982
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. */
994 QUIT;
995 errcode = target_read_memory (addr, string, print_max);
996 if (errcode != 0)
997 {
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. */
1001 char x[1];
1002 errcode = target_read_memory (addr, x, 1);
1003 }
1004 if (errcode != 0)
1005 force_ellipses = 0;
1006 else
1007 for (i = 0; i < print_max; i++)
1008 if (string[i] == '\0')
1009 {
1010 force_ellipses = 0;
1011 break;
1012 }
1013 QUIT;
1014
1015 if (addressprint)
1016 fputs_filtered (" ", stream);
1017 print_string (stream, string, i, force_ellipses);
1018 }
1019
1020 if (errcode != 0)
1021 {
1022 if (errcode == EIO)
1023 {
1024 fprintf_filtered (stream,
1025 (" <Address 0x%x out of bounds>"
1026 + first_addr_err),
1027 addr + i);
1028 }
1029 else
1030 {
1031 error ("Error reading memory address 0x%x: %s.",
1032 addr + i, safe_strerror (errcode));
1033 }
1034 }
1035
1036 fflush (stream);
1037 }
1038 else /* print vtbl's nicely */
1039 if (is_vtbl_member(type))
1040 {
1041 CORE_ADDR vt_address = unpack_pointer (type, valaddr);
1042
1043 struct minimal_symbol *msymbol =
1044 lookup_minimal_symbol_by_pc (vt_address);
1045 if ((msymbol != NULL) && (vt_address == msymbol -> address))
1046 {
1047 fputs_filtered (" <", stream);
1048 fputs_demangled (msymbol -> name, stream,
1049 DMGL_ANSI | DMGL_PARAMS);
1050 fputs_filtered (">", stream);
1051 }
1052 if (vtblprint)
1053 {
1054 value vt_val;
1055
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);
1060 if (pretty)
1061 {
1062 fprintf_filtered (stream, "\n");
1063 print_spaces_filtered (2 + 2 * recurse, stream);
1064 }
1065 }
1066 }
1067
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);
1071 }
1072 break;
1073
1074 case TYPE_CODE_MEMBER:
1075 error ("not implemented: member type in val_print");
1076 break;
1077
1078 case TYPE_CODE_REF:
1079 if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_MEMBER)
1080 {
1081 print_class_member (valaddr,
1082 TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (type)),
1083 stream, "");
1084 break;
1085 }
1086 if (addressprint)
1087 {
1088 fprintf_filtered (stream, "@0x%lx",
1089 unpack_long (builtin_type_int, valaddr));
1090 if (deref_ref)
1091 fputs_filtered (": ", stream);
1092 }
1093 /* De-reference the reference. */
1094 if (deref_ref)
1095 {
1096 if (TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_UNDEF)
1097 {
1098 value deref_val =
1099 value_at
1100 (TYPE_TARGET_TYPE (type),
1101 unpack_pointer (lookup_pointer_type (builtin_type_void),
1102 valaddr));
1103 val_print (VALUE_TYPE (deref_val), VALUE_CONTENTS (deref_val),
1104 VALUE_ADDRESS (deref_val), stream, format,
1105 deref_ref, recurse + 1, pretty);
1106 }
1107 else
1108 fputs_filtered ("???", stream);
1109 }
1110 break;
1111
1112 case TYPE_CODE_UNION:
1113 if (recurse && !unionprint)
1114 {
1115 fprintf_filtered (stream, "{...}");
1116 break;
1117 }
1118 /* Fall through. */
1119 case TYPE_CODE_STRUCT:
1120 if (vtblprint && is_vtbl_ptr_type(type))
1121 {
1122 /* Print the unmangled name if desired. */
1123 print_address_demangle(*((int *) (valaddr + /* FIXME bytesex */
1124 TYPE_FIELD_BITPOS (type, VTBL_FNADDR_OFFSET) / 8)),
1125 stream, demangle);
1126 break;
1127 }
1128 val_print_fields (type, valaddr, stream, format, recurse, pretty, 0);
1129 break;
1130
1131 case TYPE_CODE_ENUM:
1132 if (format)
1133 {
1134 print_scalar_formatted (valaddr, type, format, 0, stream);
1135 break;
1136 }
1137 len = TYPE_NFIELDS (type);
1138 val = unpack_long (builtin_type_int, valaddr);
1139 for (i = 0; i < len; i++)
1140 {
1141 QUIT;
1142 if (val == TYPE_FIELD_BITPOS (type, i))
1143 break;
1144 }
1145 if (i < len)
1146 fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
1147 else
1148 #ifdef LONG_LONG
1149 fprintf_filtered (stream, "%lld", val);
1150 #else
1151 fprintf_filtered (stream, "%ld", val);
1152 #endif
1153 break;
1154
1155 case TYPE_CODE_FUNC:
1156 if (format)
1157 {
1158 print_scalar_formatted (valaddr, type, format, 0, stream);
1159 break;
1160 }
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);
1168 break;
1169
1170 case TYPE_CODE_INT:
1171 if (format || output_format)
1172 {
1173 print_scalar_formatted (valaddr, type,
1174 format? format: output_format,
1175 0, stream);
1176 break;
1177 }
1178 if (TYPE_LENGTH (type) > sizeof (LONGEST))
1179 {
1180 if (TYPE_UNSIGNED (type))
1181 {
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. */
1185 char *p;
1186 /* Pointer to first (i.e. lowest address) nonzero character. */
1187 char *first_addr;
1188 len = TYPE_LENGTH (type);
1189
1190 #if TARGET_BYTE_ORDER == BIG_ENDIAN
1191 for (p = valaddr;
1192 len > sizeof (LONGEST)
1193 && p < valaddr + TYPE_LENGTH (type);
1194 p++)
1195 #else /* Little endian. */
1196 first_addr = valaddr;
1197 for (p = valaddr + TYPE_LENGTH (type);
1198 len > sizeof (LONGEST) && p >= valaddr;
1199 p--)
1200 #endif /* Little endian. */
1201 {
1202 if (*p == 0)
1203 len--;
1204 else
1205 break;
1206 }
1207 #if TARGET_BYTE_ORDER == BIG_ENDIAN
1208 first_addr = p;
1209 #endif
1210
1211 if (len <= sizeof (LONGEST))
1212 {
1213 /* We can print it in decimal. */
1214 fprintf_filtered
1215 (stream,
1216 #if defined (LONG_LONG)
1217 "%llu",
1218 #else
1219 "%lu",
1220 #endif
1221 unpack_long (BUILTIN_TYPE_LONGEST, first_addr));
1222 }
1223 else
1224 {
1225 /* It is big, so print it in hex. */
1226 print_hex_chars (stream, (unsigned char *)first_addr, len);
1227 }
1228 }
1229 else
1230 {
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));
1235 }
1236 break;
1237 }
1238 #ifdef PRINT_TYPELESS_INTEGER
1239 PRINT_TYPELESS_INTEGER (stream, type, unpack_long (type, valaddr));
1240 #else
1241 #ifndef LONG_LONG
1242 fprintf_filtered (stream,
1243 TYPE_UNSIGNED (type) ? "%u" : "%d",
1244 unpack_long (type, valaddr));
1245 #else
1246 fprintf_filtered (stream,
1247 TYPE_UNSIGNED (type) ? "%llu" : "%lld",
1248 unpack_long (type, valaddr));
1249 #endif
1250 #endif
1251
1252 if (TYPE_LENGTH (type) == 1)
1253 {
1254 fprintf_filtered (stream, " '");
1255 printchar ((unsigned char) unpack_long (type, valaddr),
1256 stream, '\'');
1257 fprintf_filtered (stream, "'");
1258 }
1259 break;
1260
1261 case TYPE_CODE_FLT:
1262 if (format)
1263 print_scalar_formatted (valaddr, type, format, 0, stream);
1264 else
1265 print_floating (valaddr, type, stream);
1266 break;
1267
1268 case TYPE_CODE_VOID:
1269 fprintf_filtered (stream, "void");
1270 break;
1271
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>");
1277 break;
1278
1279 case TYPE_CODE_ERROR:
1280 fprintf_filtered (stream, "?");
1281 break;
1282
1283 case TYPE_CODE_RANGE:
1284 /* FIXME, we should not ever have to print one of these yet. */
1285 fprintf_filtered (stream, "<range type>");
1286 break;
1287
1288 default:
1289 error ("Invalid type code in symbol table.");
1290 }
1291 fflush (stream);
1292 return 0;
1293 }
1294 \f
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. */
1298 void
1299 typedef_print (type, new, stream)
1300 struct type *type;
1301 struct symbol *new;
1302 FILE *stream;
1303 {
1304 switch (current_language->la_language)
1305 {
1306 #ifdef _LANG_c
1307 case language_c:
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))),
1313 SYMBOL_NAME (new)))
1314 fprintf_filtered(stream, " %s", SYMBOL_NAME(new));
1315 break;
1316 #endif
1317 #ifdef _LANG_m2
1318 case language_m2:
1319 fprintf_filtered(stream, "TYPE ");
1320 if(!TYPE_NAME(SYMBOL_TYPE(new)) ||
1321 strcmp (TYPE_NAME(SYMBOL_TYPE(new)),
1322 SYMBOL_NAME(new)))
1323 fprintf_filtered(stream, "%s = ", SYMBOL_NAME(new));
1324 else
1325 fprintf_filtered(stream, "<builtin> = ");
1326 type_print(type,"",stream,0);
1327 break;
1328 #endif
1329 default:
1330 error("Language not supported.");
1331 }
1332 fprintf_filtered(stream, ";\n");
1333 }
1334
1335
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. */
1343
1344 void
1345 type_print (type, varstring, stream, show)
1346 struct type *type;
1347 char *varstring;
1348 FILE *stream;
1349 int show;
1350 {
1351 type_print_1 (type, varstring, stream, show, 0);
1352 }
1353
1354 /* LEVEL is the depth to indent lines by. */
1355
1356 void
1357 type_print_1 (type, varstring, stream, show, level)
1358 struct type *type;
1359 char *varstring;
1360 FILE *stream;
1361 int show;
1362 int level;
1363 {
1364 register enum type_code code;
1365 char *demangled = NULL;
1366 int demangled_args;
1367
1368 type_print_base (type, stream, show, level);
1369 code = TYPE_CODE (type);
1370 if ((varstring && *varstring)
1371 ||
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)
1375 &&
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);
1383
1384 /* See if the name has a C++ demangled equivalent, and if so, print that
1385 instead. */
1386
1387 if (demangle)
1388 {
1389 demangled = cplus_demangle (varstring, DMGL_ANSI | DMGL_PARAMS);
1390 }
1391 fputs_filtered ((demangled != NULL) ? demangled : varstring, stream);
1392
1393 /* For demangled function names, we have the arglist as part of the name,
1394 so don't print an additional pair of ()'s */
1395
1396 demangled_args = (demangled != NULL) && (code == TYPE_CODE_FUNC);
1397 type_print_varspec_suffix (type, stream, show, 0, demangled_args);
1398
1399 if (demangled)
1400 {
1401 free (demangled);
1402 }
1403 }
1404
1405 /* Print the method arguments ARGS to the file STREAM. */
1406 static void
1407 type_print_method_args (args, prefix, varstring, staticp, stream)
1408 struct type **args;
1409 char *prefix, *varstring;
1410 int staticp;
1411 FILE *stream;
1412 {
1413 int i;
1414
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)
1419 {
1420 i = !staticp; /* skip the class variable */
1421 while (1)
1422 {
1423 type_print (args[i++], "", stream, 0);
1424 if (!args[i])
1425 {
1426 fprintf_filtered (stream, " ...");
1427 break;
1428 }
1429 else if (args[i]->code != TYPE_CODE_VOID)
1430 {
1431 fprintf_filtered (stream, ", ");
1432 }
1433 else break;
1434 }
1435 }
1436 fprintf_filtered (stream, ")");
1437 }
1438
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:
1442
1443 class A { int a; };
1444 class B : public A {int b; };
1445 class C : public B {int c; };
1446
1447 Print the type of class C as:
1448
1449 class C : public B {
1450 int c;
1451 }
1452
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:
1455
1456 class C : public B : public A {
1457 int c;
1458 }
1459
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. */
1462
1463 static void
1464 type_print_derivation_info (stream, type)
1465 FILE *stream;
1466 struct type *type;
1467 {
1468 char *name;
1469 int i;
1470
1471 for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
1472 {
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)");
1479 }
1480 if (i > 0)
1481 {
1482 fputs_filtered (" ", stream);
1483 }
1484 }
1485
1486 /* Print any asterisks or open-parentheses needed before the
1487 variable name (to describe its type).
1488
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. */
1493
1494 static void
1495 type_print_varspec_prefix (type, stream, show, passed_a_ptr)
1496 struct type *type;
1497 FILE *stream;
1498 int show;
1499 int passed_a_ptr;
1500 {
1501 char *name;
1502 if (type == 0)
1503 return;
1504
1505 if (TYPE_NAME (type) && show <= 0)
1506 return;
1507
1508 QUIT;
1509
1510 switch (TYPE_CODE (type))
1511 {
1512 case TYPE_CODE_PTR:
1513 type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 1);
1514 fprintf_filtered (stream, "*");
1515 break;
1516
1517 case TYPE_CODE_MEMBER:
1518 if (passed_a_ptr)
1519 fprintf_filtered (stream, "(");
1520 type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0,
1521 0);
1522 fprintf_filtered (stream, " ");
1523 name = type_name_no_tag (TYPE_DOMAIN_TYPE (type));
1524 if (name)
1525 fputs_filtered (name, stream);
1526 else
1527 type_print_base (TYPE_DOMAIN_TYPE (type), stream, 0, passed_a_ptr);
1528 fprintf_filtered (stream, "::");
1529 break;
1530
1531 case TYPE_CODE_METHOD:
1532 if (passed_a_ptr)
1533 fprintf (stream, "(");
1534 type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0,
1535 0);
1536 if (passed_a_ptr)
1537 {
1538 fprintf_filtered (stream, " ");
1539 type_print_base (TYPE_DOMAIN_TYPE (type), stream, 0,
1540 passed_a_ptr);
1541 fprintf_filtered (stream, "::");
1542 }
1543 break;
1544
1545 case TYPE_CODE_REF:
1546 type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 1);
1547 fprintf_filtered (stream, "&");
1548 break;
1549
1550 case TYPE_CODE_FUNC:
1551 type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0,
1552 0);
1553 if (passed_a_ptr)
1554 fprintf_filtered (stream, "(");
1555 break;
1556
1557 case TYPE_CODE_ARRAY:
1558 type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0,
1559 0);
1560 if (passed_a_ptr)
1561 fprintf_filtered (stream, "(");
1562 break;
1563
1564 case TYPE_CODE_UNDEF:
1565 case TYPE_CODE_STRUCT:
1566 case TYPE_CODE_UNION:
1567 case TYPE_CODE_ENUM:
1568 case TYPE_CODE_INT:
1569 case TYPE_CODE_FLT:
1570 case TYPE_CODE_VOID:
1571 case TYPE_CODE_ERROR:
1572 case TYPE_CODE_CHAR:
1573 case TYPE_CODE_BOOL:
1574 case TYPE_CODE_SET:
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. */
1579 break;
1580 }
1581 }
1582
1583 static void
1584 type_print_args (type, stream)
1585 struct type *type;
1586 FILE *stream;
1587 {
1588 int i;
1589 struct type **args;
1590
1591 fprintf_filtered (stream, "(");
1592 args = TYPE_ARG_TYPES (type);
1593 if (args != NULL)
1594 {
1595 if (args[1] == NULL)
1596 {
1597 fprintf_filtered (stream, "...");
1598 }
1599 else
1600 {
1601 for (i = 1;
1602 args[i] != NULL && args[i]->code != TYPE_CODE_VOID;
1603 i++)
1604 {
1605 type_print_1 (args[i], "", stream, -1, 0);
1606 if (args[i+1] == NULL)
1607 {
1608 fprintf_filtered (stream, "...");
1609 }
1610 else if (args[i+1]->code != TYPE_CODE_VOID)
1611 {
1612 fprintf_filtered (stream, ",");
1613 wrap_here (" ");
1614 }
1615 }
1616 }
1617 }
1618 fprintf_filtered (stream, ")");
1619 }
1620
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. */
1624
1625 static void
1626 type_print_varspec_suffix (type, stream, show, passed_a_ptr, demangled_args)
1627 struct type *type;
1628 FILE *stream;
1629 int show;
1630 int passed_a_ptr;
1631 int demangled_args;
1632 {
1633 if (type == 0)
1634 return;
1635
1636 if (TYPE_NAME (type) && show <= 0)
1637 return;
1638
1639 QUIT;
1640
1641 switch (TYPE_CODE (type))
1642 {
1643 case TYPE_CODE_ARRAY:
1644 if (passed_a_ptr)
1645 fprintf_filtered (stream, ")");
1646
1647 fprintf_filtered (stream, "[");
1648 if (TYPE_LENGTH (type) > 0
1649 && TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0)
1650 fprintf_filtered (stream, "%d",
1651 (TYPE_LENGTH (type)
1652 / TYPE_LENGTH (TYPE_TARGET_TYPE (type))));
1653 fprintf_filtered (stream, "]");
1654
1655 type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0,
1656 0, 0);
1657 break;
1658
1659 case TYPE_CODE_MEMBER:
1660 if (passed_a_ptr)
1661 fprintf_filtered (stream, ")");
1662 type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0, 0);
1663 break;
1664
1665 case TYPE_CODE_METHOD:
1666 if (passed_a_ptr)
1667 fprintf_filtered (stream, ")");
1668 type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0, 0);
1669 if (passed_a_ptr)
1670 {
1671 type_print_args (type, stream);
1672 }
1673 break;
1674
1675 case TYPE_CODE_PTR:
1676 case TYPE_CODE_REF:
1677 type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 1, 0);
1678 break;
1679
1680 case TYPE_CODE_FUNC:
1681 type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0,
1682 passed_a_ptr, 0);
1683 if (passed_a_ptr)
1684 fprintf_filtered (stream, ")");
1685 if (!demangled_args)
1686 fprintf_filtered (stream, "()");
1687 break;
1688
1689 case TYPE_CODE_UNDEF:
1690 case TYPE_CODE_STRUCT:
1691 case TYPE_CODE_UNION:
1692 case TYPE_CODE_ENUM:
1693 case TYPE_CODE_INT:
1694 case TYPE_CODE_FLT:
1695 case TYPE_CODE_VOID:
1696 case TYPE_CODE_ERROR:
1697 case TYPE_CODE_CHAR:
1698 case TYPE_CODE_BOOL:
1699 case TYPE_CODE_SET:
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. */
1704 break;
1705 }
1706 }
1707
1708 /* Print the name of the type (or the ultimate pointer target,
1709 function value or array element), or the description of a
1710 structure or union.
1711
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.
1717
1718 LEVEL is the depth to indent by.
1719 We increase it for some recursive calls. */
1720
1721 static void
1722 type_print_base (type, stream, show, level)
1723 struct type *type;
1724 FILE *stream;
1725 int show;
1726 int level;
1727 {
1728 char *name;
1729 register int i;
1730 register int len;
1731 register int lastval;
1732 char *mangled_name;
1733 char *demangled_name;
1734 enum {s_none, s_public, s_private, s_protected} section_type;
1735 QUIT;
1736
1737 wrap_here (" ");
1738 if (type == NULL)
1739 {
1740 fputs_filtered ("<type unknown>", stream);
1741 return;
1742 }
1743
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. */
1746
1747 if ((show <= 0) && (TYPE_NAME (type) != NULL))
1748 {
1749 fputs_filtered (TYPE_NAME (type), stream);
1750 return;
1751 }
1752
1753 switch (TYPE_CODE (type))
1754 {
1755 case TYPE_CODE_ARRAY:
1756 case TYPE_CODE_PTR:
1757 case TYPE_CODE_MEMBER:
1758 case TYPE_CODE_REF:
1759 case TYPE_CODE_FUNC:
1760 case TYPE_CODE_METHOD:
1761 type_print_base (TYPE_TARGET_TYPE (type), stream, show, level);
1762 break;
1763
1764 case TYPE_CODE_STRUCT:
1765 fprintf_filtered (stream,
1766 HAVE_CPLUS_STRUCT (type) ? "class " : "struct ");
1767 goto struct_union;
1768
1769 case TYPE_CODE_UNION:
1770 fprintf_filtered (stream, "union ");
1771 struct_union:
1772 if (name = type_name_no_tag (type))
1773 {
1774 fputs_filtered (name, stream);
1775 fputs_filtered (" ", stream);
1776 wrap_here (" ");
1777 }
1778 if (show < 0)
1779 fprintf_filtered (stream, "{...}");
1780 else
1781 {
1782 check_stub_type (type);
1783
1784 type_print_derivation_info (stream, type);
1785
1786 fprintf_filtered (stream, "{\n");
1787 if ((TYPE_NFIELDS (type) == 0) && (TYPE_NFN_FIELDS (type) == 0))
1788 {
1789 if (TYPE_FLAGS (type) & TYPE_FLAG_STUB)
1790 fprintfi_filtered (level + 4, stream, "<incomplete type>\n");
1791 else
1792 fprintfi_filtered (level + 4, stream, "<no data fields>\n");
1793 }
1794
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. */
1798
1799 section_type = s_none;
1800
1801 /* If there is a base class for this type,
1802 do not print the field that it occupies. */
1803
1804 len = TYPE_NFIELDS (type);
1805 for (i = TYPE_N_BASECLASSES (type); i < len; i++)
1806 {
1807 QUIT;
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))
1811 continue;
1812
1813 /* If this is a C++ class we can print the various C++ section
1814 labels. */
1815
1816 if (HAVE_CPLUS_STRUCT (type))
1817 {
1818 if (TYPE_FIELD_PROTECTED (type, i))
1819 {
1820 if (section_type != s_protected)
1821 {
1822 section_type = s_protected;
1823 fprintfi_filtered (level + 2, stream,
1824 "protected:\n");
1825 }
1826 }
1827 else if (TYPE_FIELD_PRIVATE (type, i))
1828 {
1829 if (section_type != s_private)
1830 {
1831 section_type = s_private;
1832 fprintfi_filtered (level + 2, stream, "private:\n");
1833 }
1834 }
1835 else
1836 {
1837 if (section_type != s_public)
1838 {
1839 section_type = s_public;
1840 fprintfi_filtered (level + 2, stream, "public:\n");
1841 }
1842 }
1843 }
1844
1845 print_spaces_filtered (level + 4, stream);
1846 if (TYPE_FIELD_STATIC (type, i))
1847 {
1848 fprintf_filtered (stream, "static ");
1849 }
1850 if (TYPE_FIELD_NESTED (type, i))
1851 {
1852 fprintf_filtered (stream, "typedef ");
1853 }
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))
1859 {
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));
1867 }
1868 fprintf_filtered (stream, ";\n");
1869 }
1870
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");
1875
1876 /* C++: print out the methods */
1877
1878 for (i = 0; i < len; i++)
1879 {
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++)
1885 {
1886 QUIT;
1887 if (TYPE_FN_FIELD_PROTECTED (f, j))
1888 {
1889 if (section_type != s_protected)
1890 {
1891 section_type = s_protected;
1892 fprintfi_filtered (level + 2, stream,
1893 "protected:\n");
1894 }
1895 }
1896 else if (TYPE_FN_FIELD_PRIVATE (f, j))
1897 {
1898 if (section_type != s_private)
1899 {
1900 section_type = s_private;
1901 fprintfi_filtered (level + 2, stream, "private:\n");
1902 }
1903 }
1904 else
1905 {
1906 if (section_type != s_public)
1907 {
1908 section_type = s_public;
1909 fprintfi_filtered (level + 2, stream, "public:\n");
1910 }
1911 }
1912
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)
1919 {
1920 /* Keep GDB from crashing here. */
1921 fprintf (stream, "<undefined type> %s;\n",
1922 TYPE_FN_FIELD_PHYSNAME (f, j));
1923 break;
1924 }
1925 else if (!is_constructor)
1926 {
1927 type_print (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)),
1928 "", stream, 0);
1929 fputs_filtered (" ", stream);
1930 }
1931 if (TYPE_FN_FIELD_STUB (f, j))
1932 {
1933 /* Build something we can demangle. */
1934 mangled_name = gdb_mangle_name (type, i, j);
1935 demangled_name =
1936 cplus_demangle (mangled_name,
1937 DMGL_ANSI | DMGL_PARAMS);
1938 if (demangled_name == NULL)
1939 fprintf_filtered (stream, "<badly mangled name %s>",
1940 mangled_name);
1941 else
1942 {
1943 fprintf_filtered (stream, "%s",
1944 strchr (demangled_name, ':') + 2);
1945 free (demangled_name);
1946 }
1947 free (mangled_name);
1948 }
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);
1954 else
1955 type_print_method_args
1956 (TYPE_FN_FIELD_ARGS (f, j), "",
1957 method_name,
1958 TYPE_FN_FIELD_STATIC_P (f, j), stream);
1959
1960 fprintf_filtered (stream, ";\n");
1961 }
1962 }
1963
1964 fprintfi_filtered (level, stream, "}");
1965 }
1966 break;
1967
1968 case TYPE_CODE_ENUM:
1969 fprintf_filtered (stream, "enum ");
1970 if (name = type_name_no_tag (type))
1971 {
1972 fputs_filtered (name, stream);
1973 fputs_filtered (" ", stream);
1974 }
1975 wrap_here (" ");
1976 if (show < 0)
1977 fprintf_filtered (stream, "{...}");
1978 else
1979 {
1980 fprintf_filtered (stream, "{");
1981 len = TYPE_NFIELDS (type);
1982 lastval = 0;
1983 for (i = 0; i < len; i++)
1984 {
1985 QUIT;
1986 if (i) fprintf_filtered (stream, ", ");
1987 wrap_here (" ");
1988 fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
1989 if (lastval != TYPE_FIELD_BITPOS (type, i))
1990 {
1991 fprintf_filtered (stream, " = %d", TYPE_FIELD_BITPOS (type, i));
1992 lastval = TYPE_FIELD_BITPOS (type, i);
1993 }
1994 lastval++;
1995 }
1996 fprintf_filtered (stream, "}");
1997 }
1998 break;
1999
2000 case TYPE_CODE_VOID:
2001 fprintf_filtered (stream, "void");
2002 break;
2003
2004 case TYPE_CODE_UNDEF:
2005 fprintf_filtered (stream, "struct <unknown>");
2006 break;
2007
2008 case TYPE_CODE_ERROR:
2009 fprintf_filtered (stream, "<unknown type>");
2010 break;
2011
2012 case TYPE_CODE_RANGE:
2013 /* This should not occur */
2014 fprintf_filtered (stream, "<range type>");
2015 break;
2016
2017 default:
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)
2023 {
2024 fputs_filtered (TYPE_NAME (type), stream);
2025 }
2026 else
2027 {
2028 error ("Invalid type code (%d) in symbol table.", TYPE_CODE (type));
2029 }
2030 break;
2031 }
2032 }
2033 \f
2034 #if 0
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! */
2038
2039 /* ARGSUSED */
2040 static void
2041 set_input_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 ("Input radix set to decimal %d, hex %x, octal %o\n",
2050 radix, radix, radix);
2051 }
2052 #endif
2053
2054 /* ARGSUSED */
2055 static void
2056 set_output_radix (args, from_tty, c)
2057 char *args;
2058 int from_tty;
2059 struct cmd_list_element *c;
2060 {
2061 unsigned radix = *(unsigned *)c->var;
2062
2063 if (from_tty)
2064 printf_filtered ("Output radix set to decimal %d, hex %x, octal %o\n",
2065 radix, radix, radix);
2066
2067 /* FIXME, we really should be able to validate the setting BEFORE
2068 it takes effect. */
2069 switch (radix)
2070 {
2071 case 16:
2072 output_format = 'x';
2073 break;
2074 case 10:
2075 output_format = 0;
2076 break;
2077 case 8:
2078 output_format = 'o'; /* octal */
2079 break;
2080 default:
2081 output_format = 0;
2082 error ("Unsupported radix ``decimal %d''; using decimal output",
2083 radix);
2084 }
2085 }
2086
2087 /* Both at once */
2088 static void
2089 set_radix (arg, from_tty, c)
2090 char *arg;
2091 int from_tty;
2092 struct cmd_list_element *c;
2093 {
2094 unsigned radix = *(unsigned *)c->var;
2095
2096 if (from_tty)
2097 printf_filtered ("Radix set to decimal %d, hex %x, octal %o\n",
2098 radix, radix, radix);
2099
2100 input_radix = radix;
2101 output_radix = radix;
2102
2103 set_output_radix (arg, 0, c);
2104 }
2105 \f
2106 /*ARGSUSED*/
2107 static void
2108 set_print (arg, from_tty)
2109 char *arg;
2110 int from_tty;
2111 {
2112 printf (
2113 "\"set print\" must be followed by the name of a print subcommand.\n");
2114 help_list (setprintlist, "set print ", -1, stdout);
2115 }
2116
2117 /*ARGSUSED*/
2118 static void
2119 show_print (args, from_tty)
2120 char *args;
2121 int from_tty;
2122 {
2123 cmd_show_list (showprintlist, from_tty, "");
2124 }
2125 \f
2126 void
2127 _initialize_valprint ()
2128 {
2129 struct cmd_list_element *c;
2130
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
2136 to set prompt */
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);
2142
2143 add_show_from_set
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.",
2147 &setprintlist),
2148 &showprintlist);
2149
2150 add_show_from_set
2151 (add_set_cmd ("pretty", class_support, var_boolean, (char *)&prettyprint,
2152 "Set prettyprinting of structures.",
2153 &setprintlist),
2154 &showprintlist);
2155
2156 add_show_from_set
2157 (add_set_cmd ("union", class_support, var_boolean, (char *)&unionprint,
2158 "Set printing of unions interior to structures.",
2159 &setprintlist),
2160 &showprintlist);
2161
2162 add_show_from_set
2163 (add_set_cmd ("vtbl", class_support, var_boolean, (char *)&vtblprint,
2164 "Set printing of C++ virtual function tables.",
2165 &setprintlist),
2166 &showprintlist);
2167
2168 add_show_from_set
2169 (add_set_cmd ("array", class_support, var_boolean, (char *)&arrayprint,
2170 "Set prettyprinting of arrays.",
2171 &setprintlist),
2172 &showprintlist);
2173
2174 add_show_from_set
2175 (add_set_cmd ("object", class_support, var_boolean, (char *)&objectprint,
2176 "Set printing of object's derived type based on vtable info.",
2177 &setprintlist),
2178 &showprintlist);
2179
2180 add_show_from_set
2181 (add_set_cmd ("address", class_support, var_boolean, (char *)&addressprint,
2182 "Set printing of addresses.",
2183 &setprintlist),
2184 &showprintlist);
2185
2186 #if 0
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.",
2193 &setlist);
2194 add_show_from_set (c, &showlist);
2195 c->function = set_input_radix;
2196
2197 c = add_set_cmd ("output-radix", class_support, var_uinteger,
2198 (char *)&output_radix,
2199 "Set default output radix for printing of values.",
2200 &setlist);
2201 add_show_from_set (c, &showlist);
2202 c->function = set_output_radix;
2203 #endif
2204
2205 c = add_set_cmd ("radix", class_support, var_uinteger,
2206 (char *)&output_radix,
2207 "Set default input and output number radix.",
2208 &setlist);
2209 add_show_from_set (c, &showlist);
2210 c->function.sfunc = set_radix;
2211
2212 /* Give people the defaults which they are used to. */
2213 prettyprint = 0;
2214 unionprint = 1;
2215 vtblprint = 0;
2216 arrayprint = 0;
2217 addressprint = 1;
2218 objectprint = 0;
2219
2220 print_max = 200;
2221
2222 obstack_begin (&dont_print_obstack, 32 * sizeof (struct type *));
2223 }