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