* Makefile.in (SFILES_MAINDIR): Add ch-exp.y.
[deliverable/binutils-gdb.git] / gdb / valprint.c
CommitLineData
7d9884b9
JG
1/* Print values for GDB, the GNU debugger.
2 Copyright 1986, 1988, 1989, 1991 Free Software Foundation, Inc.
bd5635a1
RP
3
4This file is part of GDB.
5
36b9d39c 6This program is free software; you can redistribute it and/or modify
bd5635a1 7it under the terms of the GNU General Public License as published by
36b9d39c
JG
8the Free Software Foundation; either version 2 of the License, or
9(at your option) any later version.
bd5635a1 10
36b9d39c 11This program is distributed in the hope that it will be useful,
bd5635a1
RP
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
36b9d39c
JG
17along with this program; if not, write to the Free Software
18Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
bd5635a1 19
bd5635a1 20#include "defs.h"
2cd99985 21#include <string.h>
bd5635a1 22#include "symtab.h"
2cd99985 23#include "gdbtypes.h"
bd5635a1
RP
24#include "value.h"
25#include "gdbcore.h"
26#include "gdbcmd.h"
27#include "target.h"
28#include "obstack.h"
be3bc7ad 29#include "language.h"
8f793aa5 30#include "demangle.h"
bd5635a1
RP
31
32#include <errno.h>
2cd99985
PB
33
34/* Prototypes for local functions */
35
36static void
37print_string PARAMS ((FILE *, char *, unsigned int, int));
38
39static void
40show_print PARAMS ((char *, int));
41
42static void
43set_print PARAMS ((char *, int));
44
45static void
46set_radix PARAMS ((char *, int, struct cmd_list_element *));
47
48static void
49set_output_radix PARAMS ((char *, int, struct cmd_list_element *));
50
51static void
52type_print_base PARAMS ((struct type *, FILE *, int, int));
53
9e4667f6
FF
54static void
55type_print_args PARAMS ((struct type *, FILE *));
56
2cd99985 57static void
f9b5584c 58type_print_varspec_suffix PARAMS ((struct type *, FILE *, int, int, int));
2cd99985
PB
59
60static void
61type_print_varspec_prefix PARAMS ((struct type *, FILE *, int, int));
62
63static void
64type_print_derivation_info PARAMS ((FILE *, struct type *));
65
66static void
67type_print_method_args PARAMS ((struct type **, char *, char *, int, FILE *));
68
69static void
70cplus_val_print PARAMS ((struct type *, char *, FILE *, int, int,
71 enum val_prettyprint, struct type **));
72
73static void
74val_print_fields PARAMS ((struct type *, char *, FILE *, int, int,
75 enum val_prettyprint, struct type **));
76
77static int
78is_vtbl_member PARAMS ((struct type *));
79
80static int
81is_vtbl_ptr_type PARAMS ((struct type *));
82
83static void
84print_hex_chars PARAMS ((FILE *, unsigned char *, unsigned));
85
bd5635a1
RP
86extern 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
91static unsigned int print_max;
92
bd5635a1
RP
93/* Default input and output radixes, and output format letter. */
94
95unsigned input_radix = 10;
96unsigned output_radix = 10;
97int output_format = 0;
98
bd5635a1
RP
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
0dce3774
JK
102
103/* Define a mess of print controls. */
104
105int prettyprint; /* Controls pretty printing of structures */
106int vtblprint; /* Controls printing of vtbl's */
107int unionprint; /* Controls printing of nested unions. */
108int arrayprint; /* Controls pretty printing of arrays. */
109int addressprint; /* Controls pretty printing of addresses. */
110int objectprint; /* Controls looking up an object's derived type
111 using what we find in its vtables. */
112
113struct obstack dont_print_obstack;
114
bd5635a1
RP
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
2cd99985 121static void
bd5635a1
RP
122print_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
212void
213print_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. */
4ed3a9ea 242 memcpy ((char *) &low, valaddr, sizeof (low));
bd5635a1
RP
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
4ed3a9ea
FF
256 memcpy (&low, valaddr+4, sizeof (low));
257 memcpy (&high, valaddr+0, sizeof (high));
bd5635a1 258#else
4ed3a9ea
FF
259 memcpy (&low, valaddr+0, sizeof (low));
260 memcpy (&high, valaddr+4, sizeof (high));
bd5635a1 261#endif
4ed3a9ea
FF
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 }
bd5635a1
RP
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
be3bc7ad 290 fprintf_filtered (stream, len <= sizeof(float) ? "%.9g" : "%.17g", doub);
bd5635a1
RP
291}
292
293/* VALADDR points to an integer of LEN bytes. Print it in hex on stream. */
294static void
295print_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
322int
323value_print (val, stream, format, pretty)
324 value val;
325 FILE *stream;
2cd99985 326 int format;
bd5635a1
RP
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 }
aec4cb91 341
bd5635a1
RP
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
51b57ded 374 && !memcmp (VALUE_CONTENTS (val) + typelen * i,
bd5635a1
RP
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 {
0dce3774
JK
408 struct type *type = VALUE_TYPE (val);
409
bd5635a1
RP
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. */
0dce3774
JK
416 if (TYPE_CODE (type) == TYPE_CODE_PTR
417 || TYPE_CODE (type) == TYPE_CODE_REF)
bd5635a1
RP
418 {
419 /* Hack: remove (char *) for char strings. Their
420 type is indicated by the quoted string anyway. */
0dce3774
JK
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)))
bd5635a1
RP
425 {
426 /* Print nothing */
427 }
428 else
429 {
430 fprintf_filtered (stream, "(");
0dce3774 431 type_print (type, "", stream, -1);
bd5635a1
RP
432 fprintf_filtered (stream, ") ");
433 }
434 }
0dce3774 435 return val_print (type, VALUE_CONTENTS (val),
bd5635a1
RP
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". */
442static int
443is_vtbl_ptr_type(type)
444 struct type *type;
445{
abefb1f1 446 char *typename = type_name_no_tag (type);
bd5635a1 447 static const char vtbl_ptr_name[] =
bcccec8c 448 { CPLUS_MARKER,'v','t','b','l','_','p','t','r','_','t','y','p','e', 0 };
bd5635a1
RP
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". */
455static int
456is_vtbl_member(type)
457 struct type *type;
458{
0dce3774
JK
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)
bd5635a1 466 /* Virtual functions tables are full of pointers to virtual functions. */
0dce3774 467 return is_vtbl_ptr_type (TYPE_TARGET_TYPE (type));
bd5635a1
RP
468 return 0;
469}
470\f
bd5635a1
RP
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. */
2cd99985 479
bd5635a1
RP
480static void
481val_print_fields (type, valaddr, stream, format, recurse, pretty, dont_print)
482 struct type *type;
483 char *valaddr;
484 FILE *stream;
2cd99985 485 int format;
bd5635a1
RP
486 int recurse;
487 enum val_prettyprint pretty;
488 struct type **dont_print;
489{
490 int i, len, n_baseclasses;
491
be3bc7ad
JG
492 check_stub_type (type);
493
bd5635a1
RP
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 */
2640f7e1 513 if (TYPE_FIELD_STATIC (type, i))
bd5635a1
RP
514 continue;
515 if (fields_seen)
516 fprintf_filtered (stream, ", ");
517 else if (n_baseclasses > 0)
518 {
0efe20a6
FF
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 }
bd5635a1
RP
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);
b4cc55b5 545 fprint_symbol (stream, TYPE_FIELD_NAME (type, i));
bd5635a1 546 fputs_filtered ("\" \"", stream);
b4cc55b5 547 fprint_symbol (stream, TYPE_FIELD_NAME (type, i));
bd5635a1
RP
548 fputs_filtered ("\") \"", stream);
549 }
550 else
551 {
b4cc55b5 552 fprint_symbol (stream, TYPE_FIELD_NAME (type, i));
bd5635a1
RP
553 fputs_filtered (" = ", stream);
554 }
555 if (TYPE_FIELD_PACKED (type, i))
556 {
f266e564 557 value v;
bd5635a1 558
f266e564
JK
559 /* Bitfields require special handling, especially due to byte
560 order problems. */
bee3c1a1 561 v = value_from_longest (TYPE_FIELD_TYPE (type, i),
f266e564 562 unpack_field_as_long (type, valaddr, i));
bd5635a1 563
f266e564 564 val_print (TYPE_FIELD_TYPE (type, i), VALUE_CONTENTS (v), 0,
bd5635a1
RP
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
586static void
587cplus_val_print (type, valaddr, stream, format, recurse, pretty, dont_print)
588 struct type *type;
589 char *valaddr;
590 FILE *stream;
2cd99985 591 int format;
bd5635a1
RP
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;
0dce3774 614 int err;
bd5635a1
RP
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
e58de8a2 631 /* Fix to use baseclass_offset instead. FIXME */
0dce3774
JK
632 baddr = baseclass_addr (type, i, valaddr, 0, &err);
633 if (err == 0 && baddr == 0)
bd5635a1
RP
634 error ("could not find virtual baseclass `%s'\n",
635 type_name_no_tag (TYPE_BASECLASS (type, i)));
636
bd5635a1 637 if (pretty)
0efe20a6
FF
638 {
639 fprintf_filtered (stream, "\n");
640 print_spaces_filtered (2 * recurse, stream);
641 }
bd5635a1
RP
642 fputs_filtered ("<", stream);
643 fputs_filtered (type_name_no_tag (TYPE_BASECLASS (type, i)), stream);
644 fputs_filtered ("> = ", stream);
0dce3774
JK
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));
0efe20a6
FF
651 fputs_filtered (", ", stream);
652
bd5635a1
RP
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
4a11eef2
FF
668static void
669print_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
bd5635a1
RP
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
737int
2cd99985 738val_print (type, valaddr, address, stream, format, deref_ref, recurse, pretty)
bd5635a1
RP
739 struct type *type;
740 char *valaddr;
741 CORE_ADDR address;
742 FILE *stream;
2cd99985 743 int format;
bd5635a1
RP
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:
2a5ec41d 774 if (TYPE_LENGTH (type) > 0
bd5635a1
RP
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
0dce3774
JK
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++)
bd5635a1
RP
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
51b57ded
FF
822 && !memcmp (valaddr + i * eltlen,
823 valaddr + rep1 * eltlen, eltlen))
bd5635a1
RP
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 = "";
e1ce8aa5 867 CORE_ADDR addr;
bd5635a1 868
e1ce8aa5
JK
869 addr = unpack_pointer (lookup_pointer_type (builtin_type_void),
870 valaddr);
e58de8a2 871 if (METHOD_PTR_IS_VIRTUAL(addr))
bd5635a1 872 {
e58de8a2 873 int offset = METHOD_PTR_TO_VOFFSET(addr);
bd5635a1
RP
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;
e58de8a2 883 if (TYPE_FN_FIELD_VOFFSET (f, j) == offset)
bd5635a1 884 {
e58de8a2 885 kind = "virtual ";
bd5635a1
RP
886 goto common;
887 }
888 }
889 }
890 }
891 else
892 {
e1ce8aa5 893 struct symbol *sym = find_pc_function (addr);
bd5635a1
RP
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);
e1ce8aa5 929 fprintf_filtered (stream, ") %d", (int) addr >> 3);
bd5635a1
RP
930 }
931 else if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_MEMBER)
932 {
4a11eef2
FF
933 print_class_member (valaddr,
934 TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (type)),
935 stream, "&");
bd5635a1
RP
936 }
937 else
938 {
e1ce8aa5 939 CORE_ADDR addr = unpack_pointer (type, valaddr);
bd5635a1
RP
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
2cd99985 993 the end of the address space, it might not work. */
bd5635a1
RP
994 QUIT;
995 errcode = target_read_memory (addr, string, print_max);
2cd99985
PB
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 }
bd5635a1
RP
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 {
4ace50a5
FF
1031 error ("Error reading memory address 0x%x: %s.",
1032 addr + i, safe_strerror (errcode));
bd5635a1
RP
1033 }
1034 }
1035
1036 fflush (stream);
1037 }
1038 else /* print vtbl's nicely */
1039 if (is_vtbl_member(type))
1040 {
e1ce8aa5 1041 CORE_ADDR vt_address = unpack_pointer (type, valaddr);
bd5635a1 1042
2cd99985
PB
1043 struct minimal_symbol *msymbol =
1044 lookup_minimal_symbol_by_pc (vt_address);
1045 if ((msymbol != NULL) && (vt_address == msymbol -> address))
bd5635a1
RP
1046 {
1047 fputs_filtered (" <", stream);
8f793aa5
FF
1048 fputs_demangled (msymbol -> name, stream,
1049 DMGL_ANSI | DMGL_PARAMS);
bd5635a1
RP
1050 fputs_filtered (">", stream);
1051 }
1052 if (vtblprint)
1053 {
e1ce8aa5 1054 value vt_val;
bd5635a1 1055
e1ce8aa5
JK
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,
bd5635a1
RP
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:
4a11eef2
FF
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 }
bd5635a1
RP
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 {
e1ce8aa5
JK
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,
bd5635a1
RP
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
e1ce8aa5
JK
1148#ifdef LONG_LONG
1149 fprintf_filtered (stream, "%lld", val);
1150#else
1151 fprintf_filtered (stream, "%ld", val);
1152#endif
bd5635a1
RP
1153 break;
1154
1155 case TYPE_CODE_FUNC:
1156 if (format)
1157 {
1158 print_scalar_formatted (valaddr, type, format, 0, stream);
1159 break;
1160 }
36b9d39c
JG
1161 /* FIXME, we should consider, at least for ANSI C language, eliminating
1162 the distinction made between FUNCs and POINTERs to FUNCs. */
bd5635a1
RP
1163 fprintf_filtered (stream, "{");
1164 type_print (type, "", stream, -1);
1165 fprintf_filtered (stream, "} ");
36b9d39c
JG
1166 /* Try to print what function it points to, and its address. */
1167 print_address_demangle (address, stream, demangle);
bd5635a1
RP
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;
e1ce8aa5 1188 len = TYPE_LENGTH (type);
bd5635a1
RP
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
e2aab031
FF
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
e58de8a2
FF
1288 case TYPE_CODE_BOOL:
1289 val = unpack_long (builtin_type_chill_bool, valaddr);
1290 fprintf_filtered (stream, val ? "TRUE" : "FALSE");
1291 break;
1292
bd5635a1
RP
1293 default:
1294 error ("Invalid type code in symbol table.");
1295 }
1296 fflush (stream);
1297 return 0;
1298}
1299\f
be3bc7ad
JG
1300/* Print a description of a type in the format of a
1301 typedef for the current language.
1302 NEW is the new name for a type TYPE. */
1303void
1304typedef_print (type, new, stream)
1305 struct type *type;
1306 struct symbol *new;
1307 FILE *stream;
1308{
1309 switch (current_language->la_language)
1310 {
1311#ifdef _LANG_c
1312 case language_c:
7d9884b9 1313 case language_cplus:
be3bc7ad
JG
1314 fprintf_filtered(stream, "typedef ");
1315 type_print(type,"",stream,0);
1316 if(TYPE_NAME ((SYMBOL_TYPE (new))) == 0
1317 || 0 != strcmp (TYPE_NAME ((SYMBOL_TYPE (new))),
1318 SYMBOL_NAME (new)))
1319 fprintf_filtered(stream, " %s", SYMBOL_NAME(new));
1320 break;
1321#endif
1322#ifdef _LANG_m2
1323 case language_m2:
1324 fprintf_filtered(stream, "TYPE ");
1325 if(!TYPE_NAME(SYMBOL_TYPE(new)) ||
1326 strcmp (TYPE_NAME(SYMBOL_TYPE(new)),
1327 SYMBOL_NAME(new)))
1328 fprintf_filtered(stream, "%s = ", SYMBOL_NAME(new));
1329 else
1330 fprintf_filtered(stream, "<builtin> = ");
1331 type_print(type,"",stream,0);
1332 break;
e58de8a2
FF
1333#endif
1334#ifdef _LANG_chill
1335 case language_chill:
1336 error("Missing Chill support in function typedef_print."); /*FIXME*/
be3bc7ad
JG
1337#endif
1338 default:
1339 error("Language not supported.");
1340 }
1341 fprintf_filtered(stream, ";\n");
1342}
1343
1344
bd5635a1
RP
1345/* Print a description of a type TYPE
1346 in the form of a declaration of a variable named VARSTRING.
1347 (VARSTRING is demangled if necessary.)
1348 Output goes to STREAM (via stdio).
1349 If SHOW is positive, we show the contents of the outermost level
1350 of structure even if there is a type name that could be used instead.
1351 If SHOW is negative, we never show the details of elements' types. */
1352
1353void
1354type_print (type, varstring, stream, show)
1355 struct type *type;
1356 char *varstring;
1357 FILE *stream;
1358 int show;
1359{
1360 type_print_1 (type, varstring, stream, show, 0);
1361}
1362
1363/* LEVEL is the depth to indent lines by. */
1364
1365void
1366type_print_1 (type, varstring, stream, show, level)
1367 struct type *type;
1368 char *varstring;
1369 FILE *stream;
1370 int show;
1371 int level;
1372{
1373 register enum type_code code;
4341615d
FF
1374 char *demangled = NULL;
1375 int demangled_args;
f9b5584c 1376
bd5635a1
RP
1377 type_print_base (type, stream, show, level);
1378 code = TYPE_CODE (type);
1379 if ((varstring && *varstring)
1380 ||
1381 /* Need a space if going to print stars or brackets;
1382 but not if we will print just a type name. */
1383 ((show > 0 || TYPE_NAME (type) == 0)
1384 &&
1385 (code == TYPE_CODE_PTR || code == TYPE_CODE_FUNC
1386 || code == TYPE_CODE_METHOD
1387 || code == TYPE_CODE_ARRAY
1388 || code == TYPE_CODE_MEMBER
1389 || code == TYPE_CODE_REF)))
1390 fprintf_filtered (stream, " ");
1391 type_print_varspec_prefix (type, stream, show, 0);
4341615d
FF
1392
1393 /* See if the name has a C++ demangled equivalent, and if so, print that
1394 instead. */
1395
f9b5584c
FF
1396 if (demangle)
1397 {
1398 demangled = cplus_demangle (varstring, DMGL_ANSI | DMGL_PARAMS);
1399 }
4341615d
FF
1400 fputs_filtered ((demangled != NULL) ? demangled : varstring, stream);
1401
1402 /* For demangled function names, we have the arglist as part of the name,
1403 so don't print an additional pair of ()'s */
1404
1405 demangled_args = (demangled != NULL) && (code == TYPE_CODE_FUNC);
1406 type_print_varspec_suffix (type, stream, show, 0, demangled_args);
1407
1408 if (demangled)
f9b5584c 1409 {
f9b5584c
FF
1410 free (demangled);
1411 }
bd5635a1
RP
1412}
1413
1414/* Print the method arguments ARGS to the file STREAM. */
1415static void
1416type_print_method_args (args, prefix, varstring, staticp, stream)
1417 struct type **args;
1418 char *prefix, *varstring;
1419 int staticp;
1420 FILE *stream;
1421{
1422 int i;
1423
8f793aa5
FF
1424 fputs_demangled (prefix, stream, DMGL_ANSI | DMGL_PARAMS);
1425 fputs_demangled (varstring, stream, DMGL_ANSI | DMGL_PARAMS);
bd5635a1
RP
1426 fputs_filtered (" (", stream);
1427 if (args && args[!staticp] && args[!staticp]->code != TYPE_CODE_VOID)
1428 {
1429 i = !staticp; /* skip the class variable */
1430 while (1)
1431 {
1432 type_print (args[i++], "", stream, 0);
1433 if (!args[i])
1434 {
1435 fprintf_filtered (stream, " ...");
1436 break;
1437 }
1438 else if (args[i]->code != TYPE_CODE_VOID)
1439 {
1440 fprintf_filtered (stream, ", ");
1441 }
1442 else break;
1443 }
1444 }
1445 fprintf_filtered (stream, ")");
1446}
1447
9e4667f6
FF
1448/* If TYPE is a derived type, then print out derivation information.
1449 Print only the actual base classes of this type, not the base classes
1450 of the base classes. I.E. for the derivation hierarchy:
1451
1452 class A { int a; };
1453 class B : public A {int b; };
1454 class C : public B {int c; };
1455
1456 Print the type of class C as:
1457
1458 class C : public B {
1459 int c;
1460 }
1461
1462 Not as the following (like gdb used to), which is not legal C++ syntax for
1463 derived types and may be confused with the multiple inheritance form:
1464
1465 class C : public B : public A {
1466 int c;
1467 }
1468
1469 In general, gdb should try to print the types as closely as possible to
1470 the form that they appear in the source code. */
1471
bd5635a1
RP
1472static void
1473type_print_derivation_info (stream, type)
1474 FILE *stream;
1475 struct type *type;
1476{
1477 char *name;
9e4667f6 1478 int i;
bd5635a1 1479
9e4667f6 1480 for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
bd5635a1 1481 {
9e4667f6
FF
1482 fputs_filtered (i == 0 ? ": " : ", ", stream);
1483 fprintf_filtered (stream, "%s%s ",
1484 BASETYPE_VIA_PUBLIC (type, i) ? "public" : "private",
1485 BASETYPE_VIA_VIRTUAL(type, i) ? " virtual" : "");
1486 name = type_name_no_tag (TYPE_BASECLASS (type, i));
35fcebce
PB
1487 fprintf_filtered (stream, "%s", name ? name : "(null)");
1488 }
1489 if (i > 0)
1490 {
1491 fputs_filtered (" ", stream);
bd5635a1
RP
1492 }
1493}
1494
1495/* Print any asterisks or open-parentheses needed before the
1496 variable name (to describe its type).
1497
1498 On outermost call, pass 0 for PASSED_A_PTR.
1499 On outermost call, SHOW > 0 means should ignore
1500 any typename for TYPE and show its details.
1501 SHOW is always zero on recursive calls. */
1502
1503static void
1504type_print_varspec_prefix (type, stream, show, passed_a_ptr)
1505 struct type *type;
1506 FILE *stream;
1507 int show;
1508 int passed_a_ptr;
1509{
4a11eef2 1510 char *name;
bd5635a1
RP
1511 if (type == 0)
1512 return;
1513
1514 if (TYPE_NAME (type) && show <= 0)
1515 return;
1516
1517 QUIT;
1518
1519 switch (TYPE_CODE (type))
1520 {
1521 case TYPE_CODE_PTR:
1522 type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 1);
1523 fprintf_filtered (stream, "*");
1524 break;
1525
1526 case TYPE_CODE_MEMBER:
1527 if (passed_a_ptr)
1528 fprintf_filtered (stream, "(");
1529 type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0,
1530 0);
1531 fprintf_filtered (stream, " ");
4a11eef2
FF
1532 name = type_name_no_tag (TYPE_DOMAIN_TYPE (type));
1533 if (name)
1534 fputs_filtered (name, stream);
1535 else
1536 type_print_base (TYPE_DOMAIN_TYPE (type), stream, 0, passed_a_ptr);
bd5635a1
RP
1537 fprintf_filtered (stream, "::");
1538 break;
1539
1540 case TYPE_CODE_METHOD:
1541 if (passed_a_ptr)
1542 fprintf (stream, "(");
1543 type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0,
1544 0);
0dce3774
JK
1545 if (passed_a_ptr)
1546 {
1547 fprintf_filtered (stream, " ");
1548 type_print_base (TYPE_DOMAIN_TYPE (type), stream, 0,
1549 passed_a_ptr);
1550 fprintf_filtered (stream, "::");
1551 }
bd5635a1
RP
1552 break;
1553
1554 case TYPE_CODE_REF:
1555 type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 1);
1556 fprintf_filtered (stream, "&");
1557 break;
1558
1559 case TYPE_CODE_FUNC:
1560 type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0,
1561 0);
1562 if (passed_a_ptr)
1563 fprintf_filtered (stream, "(");
1564 break;
1565
1566 case TYPE_CODE_ARRAY:
1567 type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0,
1568 0);
1569 if (passed_a_ptr)
1570 fprintf_filtered (stream, "(");
2a5ec41d 1571 break;
bd5635a1
RP
1572
1573 case TYPE_CODE_UNDEF:
1574 case TYPE_CODE_STRUCT:
1575 case TYPE_CODE_UNION:
1576 case TYPE_CODE_ENUM:
1577 case TYPE_CODE_INT:
1578 case TYPE_CODE_FLT:
1579 case TYPE_CODE_VOID:
1580 case TYPE_CODE_ERROR:
7d9884b9
JG
1581 case TYPE_CODE_CHAR:
1582 case TYPE_CODE_BOOL:
51b57ded
FF
1583 case TYPE_CODE_SET:
1584 case TYPE_CODE_RANGE:
1585 case TYPE_CODE_PASCAL_ARRAY:
bd5635a1
RP
1586 /* These types need no prefix. They are listed here so that
1587 gcc -Wall will reveal any types that haven't been handled. */
1588 break;
1589 }
1590}
1591
9e4667f6
FF
1592static void
1593type_print_args (type, stream)
1594 struct type *type;
1595 FILE *stream;
1596{
1597 int i;
1598 struct type **args;
1599
1600 fprintf_filtered (stream, "(");
1601 args = TYPE_ARG_TYPES (type);
1602 if (args != NULL)
1603 {
1604 if (args[1] == NULL)
1605 {
1606 fprintf_filtered (stream, "...");
1607 }
1608 else
1609 {
1610 for (i = 1;
1611 args[i] != NULL && args[i]->code != TYPE_CODE_VOID;
1612 i++)
1613 {
1614 type_print_1 (args[i], "", stream, -1, 0);
1615 if (args[i+1] == NULL)
1616 {
1617 fprintf_filtered (stream, "...");
1618 }
1619 else if (args[i+1]->code != TYPE_CODE_VOID)
1620 {
1621 fprintf_filtered (stream, ",");
1622 wrap_here (" ");
1623 }
1624 }
1625 }
1626 }
1627 fprintf_filtered (stream, ")");
1628}
1629
bd5635a1
RP
1630/* Print any array sizes, function arguments or close parentheses
1631 needed after the variable name (to describe its type).
1632 Args work like type_print_varspec_prefix. */
1633
1634static void
f9b5584c 1635type_print_varspec_suffix (type, stream, show, passed_a_ptr, demangled_args)
bd5635a1
RP
1636 struct type *type;
1637 FILE *stream;
1638 int show;
1639 int passed_a_ptr;
f9b5584c 1640 int demangled_args;
bd5635a1
RP
1641{
1642 if (type == 0)
1643 return;
1644
1645 if (TYPE_NAME (type) && show <= 0)
1646 return;
1647
1648 QUIT;
1649
1650 switch (TYPE_CODE (type))
1651 {
1652 case TYPE_CODE_ARRAY:
1653 if (passed_a_ptr)
1654 fprintf_filtered (stream, ")");
1655
1656 fprintf_filtered (stream, "[");
bee3c1a1
JG
1657 if (TYPE_LENGTH (type) > 0
1658 && TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0)
bd5635a1
RP
1659 fprintf_filtered (stream, "%d",
1660 (TYPE_LENGTH (type)
1661 / TYPE_LENGTH (TYPE_TARGET_TYPE (type))));
1662 fprintf_filtered (stream, "]");
1663
1664 type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0,
f9b5584c 1665 0, 0);
bd5635a1
RP
1666 break;
1667
1668 case TYPE_CODE_MEMBER:
1669 if (passed_a_ptr)
1670 fprintf_filtered (stream, ")");
f9b5584c 1671 type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0, 0);
bd5635a1
RP
1672 break;
1673
1674 case TYPE_CODE_METHOD:
1675 if (passed_a_ptr)
1676 fprintf_filtered (stream, ")");
f9b5584c 1677 type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0, 0);
bd5635a1
RP
1678 if (passed_a_ptr)
1679 {
9e4667f6 1680 type_print_args (type, stream);
bd5635a1
RP
1681 }
1682 break;
1683
1684 case TYPE_CODE_PTR:
1685 case TYPE_CODE_REF:
f9b5584c 1686 type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 1, 0);
bd5635a1
RP
1687 break;
1688
1689 case TYPE_CODE_FUNC:
1690 type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0,
f9b5584c 1691 passed_a_ptr, 0);
bd5635a1
RP
1692 if (passed_a_ptr)
1693 fprintf_filtered (stream, ")");
f9b5584c
FF
1694 if (!demangled_args)
1695 fprintf_filtered (stream, "()");
bd5635a1
RP
1696 break;
1697
1698 case TYPE_CODE_UNDEF:
1699 case TYPE_CODE_STRUCT:
1700 case TYPE_CODE_UNION:
1701 case TYPE_CODE_ENUM:
1702 case TYPE_CODE_INT:
1703 case TYPE_CODE_FLT:
1704 case TYPE_CODE_VOID:
1705 case TYPE_CODE_ERROR:
7d9884b9
JG
1706 case TYPE_CODE_CHAR:
1707 case TYPE_CODE_BOOL:
51b57ded
FF
1708 case TYPE_CODE_SET:
1709 case TYPE_CODE_RANGE:
1710 case TYPE_CODE_PASCAL_ARRAY:
bd5635a1
RP
1711 /* These types do not need a suffix. They are listed so that
1712 gcc -Wall will report types that may not have been considered. */
1713 break;
1714 }
1715}
1716
1717/* Print the name of the type (or the ultimate pointer target,
1718 function value or array element), or the description of a
1719 structure or union.
1720
1721 SHOW nonzero means don't print this type as just its name;
1722 show its real definition even if it has a name.
1723 SHOW zero means print just typename or struct tag if there is one
1724 SHOW negative means abbreviate structure elements.
1725 SHOW is decremented for printing of structure elements.
1726
1727 LEVEL is the depth to indent by.
1728 We increase it for some recursive calls. */
1729
1730static void
1731type_print_base (type, stream, show, level)
1732 struct type *type;
1733 FILE *stream;
1734 int show;
1735 int level;
1736{
1737 char *name;
1738 register int i;
1739 register int len;
1740 register int lastval;
4341615d
FF
1741 char *mangled_name;
1742 char *demangled_name;
8050a57b 1743 enum {s_none, s_public, s_private, s_protected} section_type;
bd5635a1
RP
1744 QUIT;
1745
8ffd75c8 1746 wrap_here (" ");
4ace50a5 1747 if (type == NULL)
bd5635a1 1748 {
4ace50a5 1749 fputs_filtered ("<type unknown>", stream);
bd5635a1
RP
1750 return;
1751 }
1752
4ace50a5
FF
1753 /* When SHOW is zero or less, and there is a valid type name, then always
1754 just print the type name directly from the type. */
4a11eef2 1755
4ace50a5 1756 if ((show <= 0) && (TYPE_NAME (type) != NULL))
bd5635a1
RP
1757 {
1758 fputs_filtered (TYPE_NAME (type), stream);
1759 return;
1760 }
1761
1762 switch (TYPE_CODE (type))
1763 {
1764 case TYPE_CODE_ARRAY:
1765 case TYPE_CODE_PTR:
1766 case TYPE_CODE_MEMBER:
1767 case TYPE_CODE_REF:
1768 case TYPE_CODE_FUNC:
1769 case TYPE_CODE_METHOD:
1770 type_print_base (TYPE_TARGET_TYPE (type), stream, show, level);
1771 break;
1772
1773 case TYPE_CODE_STRUCT:
8050a57b
FF
1774 fprintf_filtered (stream,
1775 HAVE_CPLUS_STRUCT (type) ? "class " : "struct ");
bd5635a1
RP
1776 goto struct_union;
1777
1778 case TYPE_CODE_UNION:
1779 fprintf_filtered (stream, "union ");
1780 struct_union:
1781 if (name = type_name_no_tag (type))
1782 {
1783 fputs_filtered (name, stream);
1784 fputs_filtered (" ", stream);
8ffd75c8 1785 wrap_here (" ");
bd5635a1
RP
1786 }
1787 if (show < 0)
1788 fprintf_filtered (stream, "{...}");
1789 else
1790 {
1791 check_stub_type (type);
1792
1793 type_print_derivation_info (stream, type);
1794
9e4667f6
FF
1795 fprintf_filtered (stream, "{\n");
1796 if ((TYPE_NFIELDS (type) == 0) && (TYPE_NFN_FIELDS (type) == 0))
bd5635a1
RP
1797 {
1798 if (TYPE_FLAGS (type) & TYPE_FLAG_STUB)
9e4667f6 1799 fprintfi_filtered (level + 4, stream, "<incomplete type>\n");
bd5635a1 1800 else
9e4667f6 1801 fprintfi_filtered (level + 4, stream, "<no data fields>\n");
bd5635a1
RP
1802 }
1803
9e4667f6
FF
1804 /* Start off with no specific section type, so we can print
1805 one for the first field we find, and use that section type
1806 thereafter until we find another type. */
1807
1808 section_type = s_none;
1809
bd5635a1
RP
1810 /* If there is a base class for this type,
1811 do not print the field that it occupies. */
8050a57b 1812
9e4667f6 1813 len = TYPE_NFIELDS (type);
bd5635a1
RP
1814 for (i = TYPE_N_BASECLASSES (type); i < len; i++)
1815 {
1816 QUIT;
1817 /* Don't print out virtual function table. */
1818 if ((TYPE_FIELD_NAME (type, i))[5] == CPLUS_MARKER &&
1819 !strncmp (TYPE_FIELD_NAME (type, i), "_vptr", 5))
1820 continue;
1821
8050a57b
FF
1822 /* If this is a C++ class we can print the various C++ section
1823 labels. */
1824
1825 if (HAVE_CPLUS_STRUCT (type))
1826 {
1827 if (TYPE_FIELD_PROTECTED (type, i))
1828 {
1829 if (section_type != s_protected)
1830 {
1831 section_type = s_protected;
9e4667f6
FF
1832 fprintfi_filtered (level + 2, stream,
1833 "protected:\n");
8050a57b
FF
1834 }
1835 }
1836 else if (TYPE_FIELD_PRIVATE (type, i))
1837 {
1838 if (section_type != s_private)
1839 {
1840 section_type = s_private;
9e4667f6 1841 fprintfi_filtered (level + 2, stream, "private:\n");
8050a57b
FF
1842 }
1843 }
1844 else
1845 {
1846 if (section_type != s_public)
1847 {
1848 section_type = s_public;
9e4667f6 1849 fprintfi_filtered (level + 2, stream, "public:\n");
8050a57b
FF
1850 }
1851 }
1852 }
1853
bd5635a1
RP
1854 print_spaces_filtered (level + 4, stream);
1855 if (TYPE_FIELD_STATIC (type, i))
1856 {
1857 fprintf_filtered (stream, "static ");
1858 }
1859 type_print_1 (TYPE_FIELD_TYPE (type, i),
1860 TYPE_FIELD_NAME (type, i),
1861 stream, show - 1, level + 4);
2640f7e1 1862 if (!TYPE_FIELD_STATIC (type, i)
bd5635a1
RP
1863 && TYPE_FIELD_PACKED (type, i))
1864 {
1865 /* It is a bitfield. This code does not attempt
1866 to look at the bitpos and reconstruct filler,
1867 unnamed fields. This would lead to misleading
1868 results if the compiler does not put out fields
1869 for such things (I don't know what it does). */
1870 fprintf_filtered (stream, " : %d",
1871 TYPE_FIELD_BITSIZE (type, i));
1872 }
1873 fprintf_filtered (stream, ";\n");
1874 }
1875
e58de8a2 1876 /* If there are both fields and methods, put a space between. */
2640f7e1 1877 len = TYPE_NFN_FIELDS (type);
e58de8a2
FF
1878 if (len && section_type != s_none)
1879 fprintf_filtered (stream, "\n");
1880
1881 /* C++: print out the methods */
1882
bd5635a1
RP
1883 for (i = 0; i < len; i++)
1884 {
1885 struct fn_field *f = TYPE_FN_FIELDLIST1 (type, i);
1886 int j, len2 = TYPE_FN_FIELDLIST_LENGTH (type, i);
24b2fbdc 1887 char *method_name = TYPE_FN_FIELDLIST_NAME (type, i);
2cd99985 1888 int is_constructor = name && strcmp(method_name, name) == 0;
bd5635a1
RP
1889 for (j = 0; j < len2; j++)
1890 {
1891 QUIT;
9e4667f6
FF
1892 if (TYPE_FN_FIELD_PROTECTED (f, j))
1893 {
1894 if (section_type != s_protected)
1895 {
1896 section_type = s_protected;
1897 fprintfi_filtered (level + 2, stream,
1898 "protected:\n");
1899 }
1900 }
1901 else if (TYPE_FN_FIELD_PRIVATE (f, j))
1902 {
1903 if (section_type != s_private)
1904 {
1905 section_type = s_private;
1906 fprintfi_filtered (level + 2, stream, "private:\n");
1907 }
1908 }
1909 else
1910 {
1911 if (section_type != s_public)
1912 {
1913 section_type = s_public;
1914 fprintfi_filtered (level + 2, stream, "public:\n");
1915 }
1916 }
1917
bd5635a1
RP
1918 print_spaces_filtered (level + 4, stream);
1919 if (TYPE_FN_FIELD_VIRTUAL_P (f, j))
1920 fprintf_filtered (stream, "virtual ");
1921 else if (TYPE_FN_FIELD_STATIC_P (f, j))
1922 fprintf_filtered (stream, "static ");
aec4cb91
MT
1923 if (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)) == 0)
1924 {
1925 /* Keep GDB from crashing here. */
1926 fprintf (stream, "<undefined type> %s;\n",
1927 TYPE_FN_FIELD_PHYSNAME (f, j));
1928 break;
1929 }
24b2fbdc
PB
1930 else if (!is_constructor)
1931 {
1932 type_print (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j)),
1933 "", stream, 0);
1934 fputs_filtered (" ", stream);
1935 }
1936 if (TYPE_FN_FIELD_STUB (f, j))
bd5635a1
RP
1937 {
1938 /* Build something we can demangle. */
4341615d
FF
1939 mangled_name = gdb_mangle_name (type, i, j);
1940 demangled_name =
8f793aa5
FF
1941 cplus_demangle (mangled_name,
1942 DMGL_ANSI | DMGL_PARAMS);
4341615d 1943 if (demangled_name == NULL)
24b2fbdc 1944 fprintf_filtered (stream, "<badly mangled name %s>",
bd5635a1
RP
1945 mangled_name);
1946 else
1947 {
24b2fbdc 1948 fprintf_filtered (stream, "%s",
bd5635a1
RP
1949 strchr (demangled_name, ':') + 2);
1950 free (demangled_name);
1951 }
1952 free (mangled_name);
1953 }
1954 else if (TYPE_FN_FIELD_PHYSNAME (f, j)[0] == '_'
1955 && TYPE_FN_FIELD_PHYSNAME (f, j)[1] == CPLUS_MARKER)
1956 type_print_method_args
1957 (TYPE_FN_FIELD_ARGS (f, j) + 1, "~",
24b2fbdc 1958 method_name, 0, stream);
bd5635a1
RP
1959 else
1960 type_print_method_args
1961 (TYPE_FN_FIELD_ARGS (f, j), "",
24b2fbdc 1962 method_name,
bd5635a1
RP
1963 TYPE_FN_FIELD_STATIC_P (f, j), stream);
1964
1965 fprintf_filtered (stream, ";\n");
1966 }
1967 }
1968
9e4667f6 1969 fprintfi_filtered (level, stream, "}");
bd5635a1
RP
1970 }
1971 break;
1972
1973 case TYPE_CODE_ENUM:
1974 fprintf_filtered (stream, "enum ");
1975 if (name = type_name_no_tag (type))
1976 {
1977 fputs_filtered (name, stream);
1978 fputs_filtered (" ", stream);
1979 }
8ffd75c8 1980 wrap_here (" ");
bd5635a1
RP
1981 if (show < 0)
1982 fprintf_filtered (stream, "{...}");
1983 else
1984 {
1985 fprintf_filtered (stream, "{");
1986 len = TYPE_NFIELDS (type);
1987 lastval = 0;
1988 for (i = 0; i < len; i++)
1989 {
1990 QUIT;
1991 if (i) fprintf_filtered (stream, ", ");
8ffd75c8 1992 wrap_here (" ");
bd5635a1
RP
1993 fputs_filtered (TYPE_FIELD_NAME (type, i), stream);
1994 if (lastval != TYPE_FIELD_BITPOS (type, i))
1995 {
1996 fprintf_filtered (stream, " = %d", TYPE_FIELD_BITPOS (type, i));
1997 lastval = TYPE_FIELD_BITPOS (type, i);
1998 }
1999 lastval++;
2000 }
2001 fprintf_filtered (stream, "}");
2002 }
2003 break;
2004
bd5635a1
RP
2005 case TYPE_CODE_VOID:
2006 fprintf_filtered (stream, "void");
2007 break;
2008
e2aab031
FF
2009 case TYPE_CODE_UNDEF:
2010 fprintf_filtered (stream, "struct <unknown>");
bd5635a1
RP
2011 break;
2012
2013 case TYPE_CODE_ERROR:
2014 fprintf_filtered (stream, "<unknown type>");
2015 break;
2016
e2aab031
FF
2017 case TYPE_CODE_RANGE:
2018 /* This should not occur */
2019 fprintf_filtered (stream, "<range type>");
2020 break;
2021
bd5635a1 2022 default:
4ace50a5
FF
2023 /* Handle types not explicitly handled by the other cases,
2024 such as fundamental types. For these, just print whatever
2025 the type name is, as recorded in the type itself. If there
2026 is no type name, then complain. */
2027 if (TYPE_NAME (type) != NULL)
2028 {
2029 fputs_filtered (TYPE_NAME (type), stream);
2030 }
2031 else
2032 {
2033 error ("Invalid type code (%d) in symbol table.", TYPE_CODE (type));
2034 }
2035 break;
bd5635a1
RP
2036 }
2037}
2038\f
e1ce8aa5 2039#if 0
bd5635a1
RP
2040/* Validate an input or output radix setting, and make sure the user
2041 knows what they really did here. Radix setting is confusing, e.g.
2042 setting the input radix to "10" never changes it! */
2043
e1ce8aa5 2044/* ARGSUSED */
bd5635a1
RP
2045static void
2046set_input_radix (args, from_tty, c)
2047 char *args;
2048 int from_tty;
2049 struct cmd_list_element *c;
2050{
2051 unsigned radix = *(unsigned *)c->var;
2052
2053 if (from_tty)
2054 printf_filtered ("Input radix set to decimal %d, hex %x, octal %o\n",
2055 radix, radix, radix);
2056}
e1ce8aa5 2057#endif
bd5635a1 2058
e1ce8aa5 2059/* ARGSUSED */
bd5635a1
RP
2060static void
2061set_output_radix (args, from_tty, c)
2062 char *args;
2063 int from_tty;
2064 struct cmd_list_element *c;
2065{
2066 unsigned radix = *(unsigned *)c->var;
2067
2068 if (from_tty)
2069 printf_filtered ("Output radix set to decimal %d, hex %x, octal %o\n",
2070 radix, radix, radix);
2071
2072 /* FIXME, we really should be able to validate the setting BEFORE
2073 it takes effect. */
2074 switch (radix)
2075 {
2076 case 16:
2077 output_format = 'x';
2078 break;
2079 case 10:
2080 output_format = 0;
2081 break;
2082 case 8:
2083 output_format = 'o'; /* octal */
2084 break;
2085 default:
2086 output_format = 0;
2087 error ("Unsupported radix ``decimal %d''; using decimal output",
2088 radix);
2089 }
2090}
2091
2092/* Both at once */
2093static void
2094set_radix (arg, from_tty, c)
2095 char *arg;
2096 int from_tty;
2097 struct cmd_list_element *c;
2098{
2099 unsigned radix = *(unsigned *)c->var;
2100
2101 if (from_tty)
2102 printf_filtered ("Radix set to decimal %d, hex %x, octal %o\n",
2103 radix, radix, radix);
2104
2105 input_radix = radix;
2106 output_radix = radix;
2107
2108 set_output_radix (arg, 0, c);
2109}
2110\f
f266e564
JK
2111/*ARGSUSED*/
2112static void
2113set_print (arg, from_tty)
2114 char *arg;
2115 int from_tty;
2116{
2117 printf (
2118"\"set print\" must be followed by the name of a print subcommand.\n");
2119 help_list (setprintlist, "set print ", -1, stdout);
2120}
2121
2122/*ARGSUSED*/
2123static void
2124show_print (args, from_tty)
2125 char *args;
2126 int from_tty;
2127{
2128 cmd_show_list (showprintlist, from_tty, "");
2129}
2130\f
bd5635a1
RP
2131void
2132_initialize_valprint ()
2133{
2134 struct cmd_list_element *c;
2135
f266e564
JK
2136 add_prefix_cmd ("print", no_class, set_print,
2137 "Generic command for setting how things print.",
2138 &setprintlist, "set print ", 0, &setlist);
36b9d39c
JG
2139 add_alias_cmd ("p", "print", no_class, 1, &setlist);
2140 add_alias_cmd ("pr", "print", no_class, 1, &setlist); /* prefer set print
2141 to set prompt */
f266e564
JK
2142 add_prefix_cmd ("print", no_class, show_print,
2143 "Generic command for showing print settings.",
2144 &showprintlist, "show print ", 0, &showlist);
36b9d39c
JG
2145 add_alias_cmd ("p", "print", no_class, 1, &showlist);
2146 add_alias_cmd ("pr", "print", no_class, 1, &showlist);
f266e564 2147
bd5635a1 2148 add_show_from_set
f266e564 2149 (add_set_cmd ("elements", no_class, var_uinteger, (char *)&print_max,
bd5635a1 2150 "Set limit on string chars or array elements to print.\n\
f266e564
JK
2151\"set print elements 0\" causes there to be no limit.",
2152 &setprintlist),
2153 &showprintlist);
bd5635a1
RP
2154
2155 add_show_from_set
f266e564 2156 (add_set_cmd ("pretty", class_support, var_boolean, (char *)&prettyprint,
bd5635a1 2157 "Set prettyprinting of structures.",
f266e564
JK
2158 &setprintlist),
2159 &showprintlist);
bd5635a1
RP
2160
2161 add_show_from_set
f266e564 2162 (add_set_cmd ("union", class_support, var_boolean, (char *)&unionprint,
bd5635a1 2163 "Set printing of unions interior to structures.",
f266e564
JK
2164 &setprintlist),
2165 &showprintlist);
bd5635a1
RP
2166
2167 add_show_from_set
f266e564 2168 (add_set_cmd ("vtbl", class_support, var_boolean, (char *)&vtblprint,
bd5635a1 2169 "Set printing of C++ virtual function tables.",
f266e564
JK
2170 &setprintlist),
2171 &showprintlist);
bd5635a1
RP
2172
2173 add_show_from_set
f266e564 2174 (add_set_cmd ("array", class_support, var_boolean, (char *)&arrayprint,
bd5635a1 2175 "Set prettyprinting of arrays.",
f266e564
JK
2176 &setprintlist),
2177 &showprintlist);
bd5635a1 2178
0dce3774
JK
2179 add_show_from_set
2180 (add_set_cmd ("object", class_support, var_boolean, (char *)&objectprint,
2181 "Set printing of object's derived type based on vtable info.",
2182 &setprintlist),
2183 &showprintlist);
2184
bd5635a1 2185 add_show_from_set
f266e564 2186 (add_set_cmd ("address", class_support, var_boolean, (char *)&addressprint,
bd5635a1 2187 "Set printing of addresses.",
f266e564
JK
2188 &setprintlist),
2189 &showprintlist);
bd5635a1
RP
2190
2191#if 0
2192 /* The "show radix" cmd isn't good enough to show two separate values.
2193 The rest of the code works, but the show part is confusing, so don't
2194 let them be set separately 'til we work out "show". */
2195 c = add_set_cmd ("input-radix", class_support, var_uinteger,
2196 (char *)&input_radix,
2197 "Set default input radix for entering numbers.",
2198 &setlist);
2199 add_show_from_set (c, &showlist);
2200 c->function = set_input_radix;
2201
2202 c = add_set_cmd ("output-radix", class_support, var_uinteger,
2203 (char *)&output_radix,
2204 "Set default output radix for printing of values.",
2205 &setlist);
2206 add_show_from_set (c, &showlist);
2207 c->function = set_output_radix;
2208#endif
2209
2210 c = add_set_cmd ("radix", class_support, var_uinteger,
2211 (char *)&output_radix,
2212 "Set default input and output number radix.",
2213 &setlist);
2214 add_show_from_set (c, &showlist);
2cd99985 2215 c->function.sfunc = set_radix;
bd5635a1
RP
2216
2217 /* Give people the defaults which they are used to. */
2218 prettyprint = 0;
2219 unionprint = 1;
2220 vtblprint = 0;
2221 arrayprint = 0;
2222 addressprint = 1;
0dce3774 2223 objectprint = 0;
bd5635a1
RP
2224
2225 print_max = 200;
2226
bd5635a1
RP
2227 obstack_begin (&dont_print_obstack, 32 * sizeof (struct type *));
2228}
This page took 0.18066 seconds and 4 git commands to generate.