gdb-2.8.1
[binutils-gdb.git] / gdb / valprint.c
1 /* Print values for GNU debugger gdb.
2 Copyright (C) 1986, 1988 Free Software Foundation, Inc.
3
4 GDB is distributed in the hope that it will be useful, but WITHOUT ANY
5 WARRANTY. No author or distributor accepts responsibility to anyone
6 for the consequences of using it or for whether it serves any
7 particular purpose or works at all, unless he says so in writing.
8 Refer to the GDB General Public License for full details.
9
10 Everyone is granted permission to copy, modify and redistribute GDB,
11 but only under the conditions described in the GDB General Public
12 License. A copy of this license is supposed to have been given to you
13 along with GDB so you can know your rights and responsibilities. It
14 should be in a file named COPYING. Among other things, the copyright
15 notice and this notice must be preserved on all copies.
16
17 In other words, go ahead and share GDB, but don't try to stop
18 anyone else from sharing it farther. Help stamp out software hoarding!
19 */
20
21 #include <stdio.h>
22 #include "defs.h"
23 #include "initialize.h"
24 #include "param.h"
25 #include "symtab.h"
26 #include "value.h"
27
28 /* Maximum number of chars to print for a string pointer value
29 or vector contents. */
30
31 static int print_max;
32
33 static void type_print_varspec_suffix ();
34 static void type_print_varspec_prefix ();
35 static void type_print_base ();
36 static void type_print_method_args ();
37
38 START_FILE
39
40 char **unsigned_type_table;
41 char **signed_type_table;
42 char **float_type_table;
43 \f
44 /* Print the value VAL in C-ish syntax on stream STREAM.
45 FORMAT is a format-letter, or 0 for print in natural format of data type.
46 If the object printed is a string pointer, returns
47 the number of string bytes printed. */
48
49 value_print (val, stream, format)
50 value val;
51 FILE *stream;
52 char format;
53 {
54 register int i, n, typelen;
55
56 /* A "repeated" value really contains several values in a row.
57 They are made by the @ operator.
58 Print such values as if they were arrays. */
59
60 if (VALUE_REPEATED (val))
61 {
62 n = VALUE_REPETITIONS (val);
63 typelen = TYPE_LENGTH (VALUE_TYPE (val));
64 fputc ('{', stream);
65 /* Print arrays of characters using string syntax. */
66 if (typelen == 1 && TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_INT
67 && format == 0)
68 {
69 fputc ('"', stream);
70 for (i = 0; i < n && i < print_max; i++)
71 {
72 QUIT;
73 printchar (VALUE_CONTENTS (val)[i], stream, '"');
74 }
75 if (i < n)
76 fprintf (stream, "...");
77 fputc ('"', stream);
78 }
79 else
80 {
81 for (i = 0; i < n && i < print_max; i++)
82 {
83 if (i)
84 fprintf (stream, ", ");
85 val_print (VALUE_TYPE (val), VALUE_CONTENTS (val) + typelen * i,
86 VALUE_ADDRESS (val) + typelen * i, stream, format, 1);
87 }
88 if (i < n)
89 fprintf (stream, "...");
90 }
91 fputc ('}', stream);
92 }
93 else
94 {
95 /* A simple (nonrepeated) value */
96 /* If it is a pointer, indicate what it points to.
97
98 C++: print type also if it is a reference.
99
100 If it is a member pointer, we will take care
101 of that when we print it. */
102 if (TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_PTR
103 || TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_REF)
104 {
105 fprintf (stream, "(");
106 type_print (VALUE_TYPE (val), "", stream, -1);
107 fprintf (stream, ") ");
108 }
109 return val_print (VALUE_TYPE (val), VALUE_CONTENTS (val),
110 VALUE_ADDRESS (val), stream, format, 1);
111 }
112 }
113 \f
114 /* Print data of type TYPE located at VALADDR (within GDB),
115 which came from the inferior at address ADDRESS,
116 onto stdio stream STREAM according to FORMAT
117 (a letter or 0 for natural format).
118
119 If the data are a string pointer, returns the number of
120 sting characters printed.
121
122 If DEREF_REF is nonzero, then dereference references,
123 otherwise just print them like pointers. */
124
125 int
126 val_print (type, valaddr, address, stream, format, deref_ref)
127 struct type *type;
128 char *valaddr;
129 CORE_ADDR address;
130 FILE *stream;
131 char format;
132 int deref_ref;
133 {
134 register int i;
135 int len, n_baseclasses;
136 struct type *elttype;
137 int eltlen;
138 int val;
139 unsigned char c;
140
141 QUIT;
142
143 switch (TYPE_CODE (type))
144 {
145 case TYPE_CODE_ARRAY:
146 if (TYPE_LENGTH (type) >= 0)
147 {
148 elttype = TYPE_TARGET_TYPE (type);
149 eltlen = TYPE_LENGTH (elttype);
150 len = TYPE_LENGTH (type) / eltlen;
151 fprintf (stream, "{");
152 /* For an array of chars, print with string syntax. */
153 if (eltlen == 1 && TYPE_CODE (elttype) == TYPE_CODE_INT
154 && format == 0)
155 {
156 fputc ('"', stream);
157 for (i = 0; i < len && i < print_max; i++)
158 {
159 QUIT;
160 printchar (valaddr[i], stream, '"');
161 }
162 if (i < len)
163 fprintf (stream, "...");
164 fputc ('"', stream);
165 }
166 else
167 {
168 for (i = 0; i < len && i < print_max; i++)
169 {
170 if (i) fprintf (stream, ", ");
171 val_print (elttype, valaddr + i * eltlen,
172 0, stream, format, deref_ref);
173 }
174 if (i < len)
175 fprintf (stream, "...");
176 }
177 fprintf (stream, "}");
178 break;
179 }
180 /* Array of unspecified length: treat like pointer. */
181
182 case TYPE_CODE_PTR:
183 if (format)
184 {
185 print_scalar_formatted (valaddr, type, format, 0, stream);
186 break;
187 }
188 if (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_MEMBER)
189 {
190 struct type *domain = TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (type));
191 struct type *target = TYPE_TARGET_TYPE (TYPE_TARGET_TYPE (type));
192 struct fn_field *f;
193 int j, len2;
194 char *kind = "";
195
196 val = unpack_long (builtin_type_int, valaddr);
197 if (TYPE_CODE (target) == TYPE_CODE_FUNC)
198 {
199 if (val < 128)
200 {
201 len = TYPE_NFN_FIELDS (domain);
202 for (i = 0; i < len; i++)
203 {
204 f = TYPE_FN_FIELDLIST1 (domain, i);
205 len2 = TYPE_FN_FIELDLIST_LENGTH (domain, i);
206
207 for (j = 0; j < len2; j++)
208 {
209 QUIT;
210 if (TYPE_FN_FIELD_VOFFSET (f, j) == val)
211 {
212 kind = "virtual";
213 goto common;
214 }
215 }
216 }
217 }
218 else
219 {
220 struct symbol *sym = find_pc_function (val);
221 if (sym == 0)
222 error ("invalid pointer to member function");
223 len = TYPE_NFN_FIELDS (domain);
224 for (i = 0; i < len; i++)
225 {
226 f = TYPE_FN_FIELDLIST1 (domain, i);
227 len2 = TYPE_FN_FIELDLIST_LENGTH (domain, i);
228
229 for (j = 0; j < len2; j++)
230 {
231 QUIT;
232 if (!strcmp (SYMBOL_NAME (sym), TYPE_FN_FIELD_PHYSNAME (f, j)))
233 goto common;
234 }
235 }
236 }
237 common:
238 if (i < len)
239 {
240 fputc ('&', stream);
241 type_print_varspec_prefix (TYPE_FN_FIELD_TYPE (f, j), stream, 0, 0);
242 fprintf (stream, kind);
243 if (TYPE_FN_FIELD_PHYSNAME (f, j)[0] == '_'
244 && TYPE_FN_FIELD_PHYSNAME (f, j)[1] == '$')
245 type_print_method_args
246 (TYPE_FN_FIELD_ARGS (f, j) + 1, "~",
247 TYPE_FN_FIELDLIST_NAME (domain, i), stream);
248 else
249 type_print_method_args
250 (TYPE_FN_FIELD_ARGS (f, j), "",
251 TYPE_FN_FIELDLIST_NAME (domain, i), stream);
252 break;
253 }
254 }
255 else
256 {
257 /* VAL is a byte offset into the structure type DOMAIN.
258 Find the name of the field for that offset and
259 print it. */
260 int extra = 0;
261 int bits = 0;
262 len = TYPE_NFIELDS (domain);
263 val <<= 3; /* @@ Make VAL into bit offset */
264 for (i = 0; i < len; i++)
265 {
266 int bitpos = TYPE_FIELD_BITPOS (domain, i);
267 QUIT;
268 if (val == bitpos)
269 break;
270 if (val < bitpos && i > 0)
271 {
272 int ptrsize = (TYPE_LENGTH (builtin_type_char) * TYPE_LENGTH (target));
273 /* Somehow pointing into a field. */
274 i -= 1;
275 extra = (val - TYPE_FIELD_BITPOS (domain, i));
276 if (extra & 0x3)
277 bits = 1;
278 else
279 extra >>= 3;
280 break;
281 }
282 }
283 if (i < len)
284 {
285 fputc ('&', stream);
286 type_print_base (domain, stream, 0, 0);
287 fprintf (stream, "::");
288 fprintf (stream, "%s", TYPE_FIELD_NAME (domain, i));
289 if (extra)
290 fprintf (stream, " + %d bytes", extra);
291 if (bits)
292 fprintf (stream, " (offset in bits)");
293 break;
294 }
295 }
296 fputc ('(', stream);
297 type_print (type, "", stream, -1);
298 fprintf (stream, ") %d", val >> 3);
299 }
300 else
301 {
302 fprintf (stream, "0x%x", * (int *) valaddr);
303 /* For a pointer to char or unsigned char,
304 also print the string pointed to, unless pointer is null. */
305
306 /* For an array of chars, print with string syntax. */
307 elttype = TYPE_TARGET_TYPE (type);
308 if (TYPE_LENGTH (elttype) == 1 && TYPE_CODE (elttype) == TYPE_CODE_INT
309 && format == 0
310 && unpack_long (type, valaddr) != 0)
311 {
312 fputc (' ', stream);
313 fputc ('"', stream);
314 for (i = 0; i < print_max; i++)
315 {
316 QUIT;
317 read_memory (unpack_long (type, valaddr) + i, &c, 1);
318 if (c == 0)
319 break;
320 printchar (c, stream, '"');
321 }
322 fputc ('"', stream);
323 if (i == print_max)
324 fprintf (stream, "...");
325 fflush (stream);
326 /* Return number of characters printed, plus one for the
327 terminating null if we have "reached the end". */
328 return i + (i != print_max);
329 }
330 }
331 break;
332
333 case TYPE_CODE_MEMBER:
334 error ("not implemented: member type in val_print");
335 break;
336
337 case TYPE_CODE_REF:
338 fprintf (stream, "0x%x", * (int *) valaddr);
339 /* De-reference the reference. */
340 if (deref_ref)
341 if (TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_UNDEF)
342 {
343 value val = value_at (TYPE_TARGET_TYPE (type), * (int *)valaddr);
344 fprintf (stream, " = ");
345 val_print (VALUE_TYPE (val), VALUE_CONTENTS (val),
346 VALUE_ADDRESS (val), stream, format, deref_ref);
347 }
348 else
349 fprintf (stream, " = ???");
350 break;
351
352 case TYPE_CODE_STRUCT:
353 case TYPE_CODE_UNION:
354 fprintf (stream, "{");
355 len = TYPE_NFIELDS (type);
356 n_baseclasses = TYPE_N_BASECLASSES (type);
357 for (i = 1; i <= n_baseclasses; i++)
358 {
359 fprintf (stream, "\n<%s> = ", TYPE_NAME (TYPE_BASECLASS (type, i)));
360 val_print (TYPE_FIELD_TYPE (type, 0),
361 valaddr + TYPE_FIELD_BITPOS (type, i-1) / 8,
362 0, stream, 0, 0);
363 }
364 if (i > 1) fprintf (stream, "\nmembers of %s: ", TYPE_NAME (type));
365 for (i -= 1; i < len; i++)
366 {
367 if (i > n_baseclasses) fprintf (stream, ", ");
368 fprintf (stream, "%s = ", TYPE_FIELD_NAME (type, i));
369 /* check if static field */
370 if (TYPE_FIELD_STATIC (type, i))
371 {
372 value v;
373
374 v = value_static_field (type, TYPE_FIELD_NAME (type, i), i);
375 val_print (TYPE_FIELD_TYPE (type, i),
376 VALUE_CONTENTS (v), 0, stream, format, deref_ref);
377 }
378 else if (TYPE_FIELD_PACKED (type, i))
379 {
380 val = unpack_field_as_long (type, valaddr, i);
381 val_print (TYPE_FIELD_TYPE (type, i), &val, 0, stream, format, deref_ref);
382 }
383 else
384 val_print (TYPE_FIELD_TYPE (type, i),
385 valaddr + TYPE_FIELD_BITPOS (type, i) / 8,
386 0, stream, format, deref_ref);
387 }
388 fprintf (stream, "}");
389 break;
390
391 case TYPE_CODE_ENUM:
392 if (format)
393 {
394 print_scalar_formatted (valaddr, type, format, 0, stream);
395 break;
396 }
397 len = TYPE_NFIELDS (type);
398 val = unpack_long (builtin_type_int, valaddr);
399 for (i = 0; i < len; i++)
400 {
401 QUIT;
402 if (val == TYPE_FIELD_VALUE (type, i))
403 break;
404 }
405 if (i < len)
406 fprintf (stream, "%s", TYPE_FIELD_NAME (type, i));
407 else
408 fprintf (stream, "%d", val);
409 break;
410
411 case TYPE_CODE_FUNC:
412 if (format)
413 {
414 print_scalar_formatted (valaddr, type, format, 0, stream);
415 break;
416 }
417 fprintf (stream, "{");
418 type_print (type, "", stream, -1);
419 fprintf (stream, "} ");
420 fprintf (stream, "0x%x", address);
421 break;
422
423 case TYPE_CODE_INT:
424 if (format)
425 {
426 print_scalar_formatted (valaddr, type, format, 0, stream);
427 break;
428 }
429 fprintf (stream,
430 TYPE_UNSIGNED (type) ? "%u" : "%d",
431 unpack_long (type, valaddr));
432 if (TYPE_LENGTH (type) == 1)
433 {
434 fprintf (stream, " '");
435 printchar (unpack_long (type, valaddr), stream, '\'');
436 fputc ('\'', stream);
437 }
438 break;
439
440 case TYPE_CODE_FLT:
441 if (format)
442 {
443 print_scalar_formatted (valaddr, type, format, 0, stream);
444 break;
445 }
446 #ifdef IEEE_FLOAT
447 if (is_nan (unpack_double (type, valaddr)))
448 {
449 fprintf (stream, "Nan");
450 break;
451 }
452 #endif
453 fprintf (stream, "%g", unpack_double (type, valaddr));
454 break;
455
456 case TYPE_CODE_VOID:
457 fprintf (stream, "void");
458 break;
459
460 default:
461 error ("Invalid type code in symbol table.");
462 }
463 fflush (stream);
464 }
465 \f
466 #ifdef IEEE_FLOAT
467
468 union ieee {
469 int i[2];
470 double d;
471 };
472
473 /* Nonzero if ARG (a double) is a NAN. */
474
475 int
476 is_nan (arg)
477 union ieee arg;
478 {
479 int lowhalf, highhalf;
480 union { int i; char c; } test;
481
482 /* Separate the high and low words of the double.
483 Distinguish big and little-endian machines. */
484 test.i = 1;
485 if (test.c != 1)
486 /* Big-endian machine */
487 lowhalf = arg.i[1], highhalf = arg.i[0];
488 else
489 lowhalf = arg.i[0], highhalf = arg.i[1];
490
491 /* Nan: exponent is the maximum possible, and fraction is nonzero. */
492 return (((highhalf>>20) & 0x7ff) == 0x7ff
493 &&
494 ! ((highhalf & 0xfffff == 0) && (lowhalf == 0)));
495 }
496 #endif
497 \f
498 /* Print a description of a type TYPE
499 in the form of a declaration of a variable named VARSTRING.
500 Output goes to STREAM (via stdio).
501 If SHOW is positive, we show the contents of the outermost level
502 of structure even if there is a type name that could be used instead.
503 If SHOW is negative, we never show the details of elements' types. */
504
505 type_print (type, varstring, stream, show)
506 struct type *type;
507 char *varstring;
508 FILE *stream;
509 int show;
510 {
511 type_print_1 (type, varstring, stream, show, 0);
512 }
513
514 /* LEVEL is the depth to indent lines by. */
515
516 type_print_1 (type, varstring, stream, show, level)
517 struct type *type;
518 char *varstring;
519 FILE *stream;
520 int show;
521 int level;
522 {
523 register enum type_code code;
524 type_print_base (type, stream, show, level);
525 code = TYPE_CODE (type);
526 if ((varstring && *varstring)
527 ||
528 /* Need a space if going to print stars or brackets;
529 but not if we will print just a type name. */
530 ((show > 0 || TYPE_NAME (type) == 0)
531 &&
532 (code == TYPE_CODE_PTR || code == TYPE_CODE_FUNC
533 || code == TYPE_CODE_ARRAY
534 || code == TYPE_CODE_MEMBER
535 || code == TYPE_CODE_REF)))
536 fprintf (stream, " ");
537 type_print_varspec_prefix (type, stream, show, 0);
538 fprintf (stream, "%s", varstring);
539 type_print_varspec_suffix (type, stream, show, 0);
540 }
541
542 /* Print the method arguments ARGS to the file STREAM. */
543 static void
544 type_print_method_args (args, prefix, varstring, stream)
545 struct type **args;
546 char *prefix, *varstring;
547 FILE *stream;
548 {
549 int i;
550
551 fprintf (stream, " %s%s (", prefix, varstring);
552 if (args[1] && args[1]->code != TYPE_CODE_VOID)
553 {
554 i = 1; /* skip the class variable */
555 while (1)
556 {
557 type_print (args[i++], "", stream, 0);
558 if (!args[i])
559 {
560 fprintf (stream, " ...");
561 break;
562 }
563 else if (args[i]->code != TYPE_CODE_VOID)
564 {
565 fprintf (stream, ", ");
566 }
567 else break;
568 }
569 }
570 fprintf (stream, ")");
571 }
572
573 /* If TYPE is a derived type, then print out derivation
574 information. Print out all layers of the type heirarchy
575 until we encounter one with multiple inheritance.
576 At that point, print out that ply, and return. */
577 static void
578 type_print_derivation_info (stream, type)
579 FILE *stream;
580 struct type *type;
581 {
582 char *name;
583 int i, n_baseclasses = TYPE_N_BASECLASSES (type);
584 struct type *basetype = 0;
585
586 while (type && n_baseclasses == 1)
587 {
588 basetype = TYPE_BASECLASS (type, 1);
589 if (TYPE_NAME (basetype) && (name = TYPE_NAME (basetype)))
590 {
591 while (*name != ' ') name++;
592 fprintf (stream, ": %s%s %s ",
593 TYPE_VIA_PUBLIC (basetype) ? "public" : "private",
594 TYPE_VIA_VIRTUAL (basetype) ? " virtual" : "",
595 name + 1);
596 }
597 n_baseclasses = TYPE_N_BASECLASSES (basetype);
598 type = basetype;
599 }
600
601 if (type)
602 {
603 if (n_baseclasses != 0)
604 fprintf (stream, ": ");
605 for (i = 1; i <= n_baseclasses; i++)
606 {
607 basetype = TYPE_BASECLASS (type, i);
608 if (TYPE_NAME (basetype) && (name = TYPE_NAME (basetype)))
609 {
610 while (*name != ' ') name++;
611 fprintf (stream, "%s%s %s",
612 TYPE_VIA_PUBLIC (basetype) ? "public" : "private",
613 TYPE_VIA_VIRTUAL (basetype) ? " virtual" : "",
614 name + 1);
615 }
616 if (i < n_baseclasses)
617 fprintf (stream, ", ");
618 }
619 putc (' ', stream);
620 }
621 }
622
623 /* Print any asterisks or open-parentheses needed before the
624 variable name (to describe its type).
625
626 On outermost call, pass 0 for PASSED_A_PTR.
627 On outermost call, SHOW > 0 means should ignore
628 any typename for TYPE and show its details.
629 SHOW is always zero on recursive calls. */
630
631 static void
632 type_print_varspec_prefix (type, stream, show, passed_a_ptr)
633 struct type *type;
634 FILE *stream;
635 int show;
636 int passed_a_ptr;
637 {
638 if (type == 0)
639 return;
640
641 if (TYPE_NAME (type) && show <= 0)
642 return;
643
644 QUIT;
645
646 switch (TYPE_CODE (type))
647 {
648 case TYPE_CODE_PTR:
649 type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 1);
650 fputc ('*', stream);
651 break;
652
653 case TYPE_CODE_MEMBER:
654 type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0,
655 passed_a_ptr);
656 fputc (' ', stream);
657 type_print_base (TYPE_DOMAIN_TYPE (type), stream, 0,
658 passed_a_ptr);
659 fprintf (stream, "::");
660 break;
661
662 case TYPE_CODE_REF:
663 type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 1);
664 fputc ('&', stream);
665 break;
666
667 case TYPE_CODE_FUNC:
668 case TYPE_CODE_ARRAY:
669 type_print_varspec_prefix (TYPE_TARGET_TYPE (type), stream, 0, 0);
670 if (passed_a_ptr)
671 fputc ('(', stream);
672 break;
673 }
674 }
675
676 /* Print any array sizes, function arguments or close parentheses
677 needed after the variable name (to describe its type).
678 Args work like type_print_varspec_prefix. */
679
680 static void
681 type_print_varspec_suffix (type, stream, show, passed_a_ptr)
682 struct type *type;
683 FILE *stream;
684 int show;
685 int passed_a_ptr;
686 {
687 if (type == 0)
688 return;
689
690 if (TYPE_NAME (type) && show <= 0)
691 return;
692
693 QUIT;
694
695 switch (TYPE_CODE (type))
696 {
697 case TYPE_CODE_ARRAY:
698 type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0);
699 if (passed_a_ptr)
700 fprintf (stream, ")");
701 fprintf (stream, "[");
702 if (TYPE_LENGTH (type) >= 0)
703 fprintf (stream, "%d",
704 TYPE_LENGTH (type) / TYPE_LENGTH (TYPE_TARGET_TYPE (type)));
705 fprintf (stream, "]");
706 break;
707
708 case TYPE_CODE_MEMBER:
709 if (passed_a_ptr)
710 fputc (')', stream);
711 type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0);
712 break;
713
714 case TYPE_CODE_PTR:
715 case TYPE_CODE_REF:
716 type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 1);
717 break;
718
719 case TYPE_CODE_FUNC:
720 type_print_varspec_suffix (TYPE_TARGET_TYPE (type), stream, 0, 0);
721 if (passed_a_ptr)
722 fprintf (stream, ")");
723 fprintf (stream, "()");
724 break;
725 }
726 }
727
728 /* Print the name of the type (or the ultimate pointer target,
729 function value or array element), or the description of a
730 structure or union.
731
732 SHOW nonzero means don't print this type as just its name;
733 show its real definition even if it has a name.
734 SHOW zero means print just typename or struct tag if there is one
735 SHOW negative means abbreviate structure elements.
736 SHOW is decremented for printing of structure elements.
737
738 LEVEL is the depth to indent by.
739 We increase it for some recursive calls. */
740
741 static void
742 type_print_base (type, stream, show, level)
743 struct type *type;
744 FILE *stream;
745 int show;
746 int level;
747 {
748 char *name;
749 register int i;
750 register int len;
751 register int lastval;
752
753 QUIT;
754
755 if (type == 0)
756 {
757 fprintf (stream, "type unknown");
758 return;
759 }
760
761 if (TYPE_NAME (type) && show <= 0)
762 {
763 fprintf (stream, TYPE_NAME (type));
764 return;
765 }
766
767 switch (TYPE_CODE (type))
768 {
769 case TYPE_CODE_ARRAY:
770 case TYPE_CODE_PTR:
771 case TYPE_CODE_MEMBER:
772 case TYPE_CODE_REF:
773 case TYPE_CODE_FUNC:
774 type_print_base (TYPE_TARGET_TYPE (type), stream, show, level);
775 break;
776
777 case TYPE_CODE_STRUCT:
778 fprintf (stream, "struct ");
779 goto struct_union;
780
781 case TYPE_CODE_UNION:
782 fprintf (stream, "union ");
783 struct_union:
784 if (TYPE_NAME (type) && (name = TYPE_NAME (type)))
785 {
786 while (*name != ' ') name++;
787 fprintf (stream, "%s ", name + 1);
788 }
789 if (show < 0)
790 fprintf (stream, "{...}");
791 else
792 {
793 int i;
794
795 type_print_derivation_info (stream, type);
796
797 fprintf (stream, "{");
798 len = TYPE_NFIELDS (type);
799 if (len) fprintf (stream, "\n");
800 else fprintf (stream, "<no data fields>\n");
801
802 for (i = TYPE_N_BASECLASSES (type); i < len; i++)
803 {
804 QUIT;
805 /* Don't print out virtual function table. */
806 if (! strncmp (TYPE_FIELD_NAME (type, i),
807 "_vptr$", 6))
808 continue;
809
810 print_spaces (level + 4, stream);
811
812 /* If this is a bit-field and there is a gap before it,
813 print a nameless field to account for the gap. */
814
815 if (TYPE_FIELD_PACKED (type, i))
816 {
817 int gap = (TYPE_FIELD_BITPOS (type, i)
818 - (i > 0
819 ? (TYPE_FIELD_BITPOS (type, i - 1)
820 + (TYPE_FIELD_PACKED (type, i - 1)
821 ? TYPE_FIELD_BITSIZE (type, i - 1)
822 : TYPE_LENGTH (TYPE_FIELD_TYPE (type, i - 1)) * 8))
823 : 0));
824 if (gap != 0)
825 {
826 fprintf (stream, "int : %d;\n", gap);
827 print_spaces (level + 4, stream);
828 }
829 }
830
831 /* Print the declaration of this field. */
832
833 if (TYPE_FIELD_STATIC (type, i))
834 {
835 fprintf (stream, "static ");
836 }
837 type_print_1 (TYPE_FIELD_TYPE (type, i),
838 TYPE_FIELD_NAME (type, i),
839 stream, show - 1, level + 4);
840
841 /* Print the field width. */
842
843 if (TYPE_FIELD_PACKED (type, i))
844 fprintf (stream, " : %d", TYPE_FIELD_BITSIZE (type, i));
845
846 fprintf (stream, ";\n");
847 }
848
849 /* C++: print out the methods */
850 len = TYPE_NFN_FIELDS (type);
851 if (len) fprintf (stream, "\n");
852 for (i = 0; i < len; i++)
853 {
854 struct fn_field *f = TYPE_FN_FIELDLIST1 (type, i);
855 int j, len2 = TYPE_FN_FIELDLIST_LENGTH (type, i);
856
857 for (j = 0; j < len2; j++)
858 {
859 QUIT;
860 print_spaces (level + 4, stream);
861 if (TYPE_FN_FIELD_VIRTUAL_P (f, j))
862 fprintf (stream, "virtual ");
863 type_print (TYPE_TARGET_TYPE (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f, j))), "", stream, 0);
864 if (TYPE_FN_FIELD_PHYSNAME (f, j)[0] == '_'
865 && TYPE_FN_FIELD_PHYSNAME (f, j)[1] == '$')
866 type_print_method_args
867 (TYPE_FN_FIELD_ARGS (f, j) + 1, "~",
868 TYPE_FN_FIELDLIST_NAME (type, i), stream);
869 else
870 type_print_method_args
871 (TYPE_FN_FIELD_ARGS (f, j), "",
872 TYPE_FN_FIELDLIST_NAME (type, i), stream);
873
874 fprintf (stream, ";\n");
875 }
876 if (len2) fprintf (stream, "\n");
877 }
878
879 print_spaces (level, stream);
880 fputc ('}', stream);
881 }
882 break;
883
884 case TYPE_CODE_ENUM:
885 fprintf (stream, "enum ");
886 if (TYPE_NAME (type))
887 {
888 name = TYPE_NAME (type);
889 while (*name != ' ') name++;
890 fprintf (stream, "%s ", name + 1);
891 }
892 if (show < 0)
893 fprintf (stream, "{...}");
894 else
895 {
896 fprintf (stream, "{");
897 len = TYPE_NFIELDS (type);
898 lastval = 0;
899 for (i = 0; i < len; i++)
900 {
901 QUIT;
902 if (i) fprintf (stream, ", ");
903 fprintf (stream, "%s", TYPE_FIELD_NAME (type, i));
904 if (lastval != TYPE_FIELD_VALUE (type, i))
905 {
906 fprintf (stream, " : %d", TYPE_FIELD_VALUE (type, i));
907 lastval = TYPE_FIELD_VALUE (type, i);
908 }
909 lastval++;
910 }
911 fprintf (stream, "}");
912 }
913 break;
914
915 case TYPE_CODE_INT:
916 if (TYPE_UNSIGNED (type))
917 name = unsigned_type_table[TYPE_LENGTH (type)];
918 else
919 name = signed_type_table[TYPE_LENGTH (type)];
920 fprintf (stream, "%s", name);
921 break;
922
923 case TYPE_CODE_FLT:
924 name = float_type_table[TYPE_LENGTH (type)];
925 fprintf (stream, "%s", name);
926 break;
927
928 case TYPE_CODE_VOID:
929 fprintf (stream, "void");
930 break;
931
932 case 0:
933 fprintf (stream, "struct unknown");
934 break;
935
936 default:
937 error ("Invalid type code in symbol table.");
938 }
939 }
940 \f
941 static void
942 set_maximum_command (arg)
943 char *arg;
944 {
945 if (!arg) error_no_arg ("value for maximum elements to print");
946 print_max = atoi (arg);
947 }
948
949 static
950 initialize ()
951 {
952 add_com ("set-maximum", class_vars, set_maximum_command,
953 "Set NUMBER as limit on string chars or array elements to print.");
954
955 print_max = 200;
956
957 unsigned_type_table
958 = (char **) xmalloc ((1 + sizeof (unsigned long)) * sizeof (char *));
959 bzero (unsigned_type_table, (1 + sizeof (unsigned long)));
960 unsigned_type_table[sizeof (unsigned char)] = "unsigned char";
961 unsigned_type_table[sizeof (unsigned short)] = "unsigned short";
962 unsigned_type_table[sizeof (unsigned long)] = "unsigned long";
963 unsigned_type_table[sizeof (unsigned int)] = "unsigned int";
964
965 signed_type_table
966 = (char **) xmalloc ((1 + sizeof (long)) * sizeof (char *));
967 bzero (signed_type_table, (1 + sizeof (long)));
968 signed_type_table[sizeof (char)] = "char";
969 signed_type_table[sizeof (short)] = "short";
970 signed_type_table[sizeof (long)] = "long";
971 signed_type_table[sizeof (int)] = "int";
972
973 float_type_table
974 = (char **) xmalloc ((1 + sizeof (double)) * sizeof (char *));
975 bzero (float_type_table, (1 + sizeof (double)));
976 float_type_table[sizeof (float)] = "float";
977 float_type_table[sizeof (double)] = "double";
978 }
979
980 END_FILE