1 /* Print values for GNU debugger gdb.
2 Copyright (C) 1986, 1988, 1989 Free Software Foundation, Inc.
4 This file is part of GDB.
6 GDB is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 1, or (at your option)
11 GDB is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GDB; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
26 /* Maximum number of chars to print for a string pointer value
27 or vector contents. */
31 static void type_print_varspec_suffix ();
32 static void type_print_varspec_prefix ();
33 static void type_print_base ();
34 static void type_print_method_args ();
37 char **unsigned_type_table
;
38 char **signed_type_table
;
39 char **float_type_table
;
42 /* Print repeat counts if there are more than this
43 many repetitions of an element in an array. */
44 #define REPEAT_COUNT_THRESHOLD 10
46 /* Print the character string STRING, printing at most LENGTH characters.
47 Printing stops early if the number hits print_max; repeat counts
48 are printed as appropriate. */
51 print_string (stream
, string
, length
)
56 register unsigned int i
;
57 unsigned int things_printed
= 0;
63 fputs_filtered ("\"\"", stdout
);
67 for (i
= 0; i
< length
&& things_printed
< print_max
; ++i
)
69 /* Position of the character we are examining
70 to see whether it is repeated. */
72 /* Number of repititions we have detected so far. */
79 fputs_filtered (", ", stream
);
85 while (rep1
< length
&& string
[rep1
] == string
[i
])
91 if (reps
> REPEAT_COUNT_THRESHOLD
)
95 fputs_filtered ("\", ", stream
);
98 fputs_filtered ("'", stream
);
99 printchar (string
[i
], stream
, '\'');
100 fprintf_filtered (stream
, "' <repeats %u times>", reps
);
102 things_printed
+= REPEAT_COUNT_THRESHOLD
;
109 fputs_filtered ("\"", stream
);
112 printchar (string
[i
], stream
, '"');
117 /* Terminate the quotes if necessary. */
119 fputs_filtered ("\"", stream
);
121 /* Print ellipses if we stopped before printing LENGTH characters. */
123 fputs_filtered ("...", stream
);
126 /* Print the value VAL in C-ish syntax on stream STREAM.
127 FORMAT is a format-letter, or 0 for print in natural format of data type.
128 If the object printed is a string pointer, returns
129 the number of string bytes printed. */
132 value_print (val
, stream
, format
, pretty
)
136 enum val_prettyprint pretty
;
138 register unsigned int i
, n
, typelen
;
140 /* A "repeated" value really contains several values in a row.
141 They are made by the @ operator.
142 Print such values as if they were arrays. */
144 if (VALUE_REPEATED (val
))
146 n
= VALUE_REPETITIONS (val
);
147 typelen
= TYPE_LENGTH (VALUE_TYPE (val
));
148 fprintf_filtered (stream
, "{");
149 /* Print arrays of characters using string syntax. */
150 if (typelen
== 1 && TYPE_CODE (VALUE_TYPE (val
)) == TYPE_CODE_INT
152 print_string (stream
, VALUE_CONTENTS (val
), n
);
155 unsigned int things_printed
= 0;
157 for (i
= 0; i
< n
&& things_printed
< print_max
; i
++)
159 /* Position of the array element we are examining to see
160 whether it is repeated. */
162 /* Number of repititions we have detected so far. */
166 fprintf_filtered (stream
, ", ");
171 && !bcmp (VALUE_CONTENTS (val
) + typelen
* i
,
172 VALUE_CONTENTS (val
) + typelen
* rep1
, typelen
))
178 if (reps
> REPEAT_COUNT_THRESHOLD
)
180 val_print (VALUE_TYPE (val
),
181 VALUE_CONTENTS (val
) + typelen
* i
,
182 VALUE_ADDRESS (val
) + typelen
* i
,
183 stream
, format
, 1, 0, pretty
);
184 fprintf (stream
, " <repeats %u times>", reps
);
186 things_printed
+= REPEAT_COUNT_THRESHOLD
;
190 val_print (VALUE_TYPE (val
),
191 VALUE_CONTENTS (val
) + typelen
* i
,
192 VALUE_ADDRESS (val
) + typelen
* i
,
193 stream
, format
, 1, 0, pretty
);
198 fprintf_filtered (stream
, "...");
200 fprintf_filtered (stream
, "}");
205 /* If it is a pointer, indicate what it points to.
207 Print type also if it is a reference.
209 C++: if it is a member pointer, we will take care
210 of that when we print it. */
211 if (TYPE_CODE (VALUE_TYPE (val
)) == TYPE_CODE_PTR
212 || TYPE_CODE (VALUE_TYPE (val
)) == TYPE_CODE_REF
)
214 fprintf_filtered (stream
, "(");
215 type_print (VALUE_TYPE (val
), "", stream
, -1);
216 fprintf_filtered (stream
, ") ");
218 /* If this is a function pointer, try to print what
219 function it is pointing to by name. */
220 if (TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (val
)))
223 print_address (((int *) VALUE_CONTENTS (val
))[0], stream
);
224 /* Return value is irrelevant except for string pointers. */
228 return val_print (VALUE_TYPE (val
), VALUE_CONTENTS (val
),
229 VALUE_ADDRESS (val
), stream
, format
, 1, 0, pretty
);
233 static int prettyprint
; /* Controls prettyprinting of structures. */
234 int unionprint
; /* Controls printing of nested unions. */
236 /* Print data of type TYPE located at VALADDR (within GDB),
237 which came from the inferior at address ADDRESS,
238 onto stdio stream STREAM according to FORMAT
239 (a letter or 0 for natural format).
241 If the data are a string pointer, returns the number of
242 sting characters printed.
244 if DEREF_REF is nonzero, then dereference references,
245 otherwise just print them like pointers.
247 The PRETTY parameter controls prettyprinting. */
250 val_print (type
, valaddr
, address
, stream
, format
,
251 deref_ref
, recurse
, pretty
)
259 enum val_prettyprint pretty
;
261 register unsigned int i
;
262 int len
, n_baseclasses
;
263 struct type
*elttype
;
268 if (pretty
== Val_pretty_default
)
270 pretty
= prettyprint
? Val_prettyprint
: Val_no_prettyprint
;
275 if (TYPE_FLAGS (type
) & TYPE_FLAG_STUB
)
277 fprintf_filtered (stream
, "<Type not defined in this context>");
282 switch (TYPE_CODE (type
))
284 case TYPE_CODE_ARRAY
:
285 if (TYPE_LENGTH (type
) >= 0
286 && TYPE_LENGTH (TYPE_TARGET_TYPE (type
)) > 0)
288 elttype
= TYPE_TARGET_TYPE (type
);
289 eltlen
= TYPE_LENGTH (elttype
);
290 len
= TYPE_LENGTH (type
) / eltlen
;
291 fprintf_filtered (stream
, "{");
292 /* For an array of chars, print with string syntax. */
293 if (eltlen
== 1 && TYPE_CODE (elttype
) == TYPE_CODE_INT
295 print_string (stream
, valaddr
, len
);
298 unsigned int things_printed
= 0;
300 for (i
= 0; i
< len
&& things_printed
< print_max
; i
++)
302 /* Position of the array element we are examining to see
303 whether it is repeated. */
305 /* Number of repititions we have detected so far. */
309 fprintf_filtered (stream
, ", ");
314 && !bcmp (valaddr
+ i
* eltlen
,
315 valaddr
+ rep1
* eltlen
, eltlen
))
321 if (reps
> REPEAT_COUNT_THRESHOLD
)
323 val_print (elttype
, valaddr
+ i
* eltlen
,
324 0, stream
, format
, deref_ref
,
325 recurse
+ 1, pretty
);
326 fprintf_filtered (stream
, " <repeats %u times>", reps
);
328 things_printed
+= REPEAT_COUNT_THRESHOLD
;
332 val_print (elttype
, valaddr
+ i
* eltlen
,
333 0, stream
, format
, deref_ref
,
334 recurse
+ 1, pretty
);
339 fprintf_filtered (stream
, "...");
341 fprintf_filtered (stream
, "}");
344 /* Array of unspecified length: treat like pointer to first elt. */
345 valaddr
= (char *) &address
;
350 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
353 if (TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_METHOD
)
355 struct type
*domain
= TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (type
));
356 struct type
*target
= TYPE_TARGET_TYPE (TYPE_TARGET_TYPE (type
));
361 val
= unpack_long (builtin_type_int
, valaddr
);
364 len
= TYPE_NFN_FIELDS (domain
);
365 for (i
= 0; i
< len
; i
++)
367 f
= TYPE_FN_FIELDLIST1 (domain
, i
);
368 len2
= TYPE_FN_FIELDLIST_LENGTH (domain
, i
);
370 for (j
= 0; j
< len2
; j
++)
373 if (TYPE_FN_FIELD_VOFFSET (f
, j
) == val
)
383 struct symbol
*sym
= find_pc_function ((CORE_ADDR
) val
);
385 error ("invalid pointer to member function");
386 len
= TYPE_NFN_FIELDS (domain
);
387 for (i
= 0; i
< len
; i
++)
389 f
= TYPE_FN_FIELDLIST1 (domain
, i
);
390 len2
= TYPE_FN_FIELDLIST_LENGTH (domain
, i
);
392 for (j
= 0; j
< len2
; j
++)
395 if (!strcmp (SYMBOL_NAME (sym
), TYPE_FN_FIELD_PHYSNAME (f
, j
)))
403 fprintf_filtered (stream
, "&");
404 type_print_varspec_prefix (TYPE_FN_FIELD_TYPE (f
, j
), stream
, 0, 0);
405 fprintf (stream
, kind
);
406 if (TYPE_FN_FIELD_PHYSNAME (f
, j
)[0] == '_'
407 && TYPE_FN_FIELD_PHYSNAME (f
, j
)[1] == '$')
408 type_print_method_args
409 (TYPE_FN_FIELD_ARGS (f
, j
) + 1, "~",
410 TYPE_FN_FIELDLIST_NAME (domain
, i
), 0, stream
);
412 type_print_method_args
413 (TYPE_FN_FIELD_ARGS (f
, j
), "",
414 TYPE_FN_FIELDLIST_NAME (domain
, i
), 0, stream
);
417 fprintf_filtered (stream
, "(");
418 type_print (type
, "", stream
, -1);
419 fprintf_filtered (stream
, ") %d", (int) val
>> 3);
421 else if (TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_MEMBER
)
423 struct type
*domain
= TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (type
));
424 struct type
*target
= TYPE_TARGET_TYPE (TYPE_TARGET_TYPE (type
));
427 /* VAL is a byte offset into the structure type DOMAIN.
428 Find the name of the field for that offset and
432 len
= TYPE_NFIELDS (domain
);
433 /* @@ Make VAL into bit offset */
434 val
= unpack_long (builtin_type_int
, valaddr
) << 3;
435 for (i
= 0; i
< len
; i
++)
437 int bitpos
= TYPE_FIELD_BITPOS (domain
, i
);
441 if (val
< bitpos
&& i
> 0)
443 int ptrsize
= (TYPE_LENGTH (builtin_type_char
) * TYPE_LENGTH (target
));
444 /* Somehow pointing into a field. */
446 extra
= (val
- TYPE_FIELD_BITPOS (domain
, i
));
456 fprintf_filtered (stream
, "&");
457 type_print_base (domain
, stream
, 0, 0);
458 fprintf_filtered (stream
, "::");
459 fputs_filtered (TYPE_FIELD_NAME (domain
, i
), stream
);
461 fprintf_filtered (stream
, " + %d bytes", extra
);
463 fprintf_filtered (stream
, " (offset in bits)");
466 fprintf_filtered (stream
, "%d", val
>> 3);
470 fprintf_filtered (stream
, "0x%x", * (int *) valaddr
);
471 /* For a pointer to char or unsigned char,
472 also print the string pointed to, unless pointer is null. */
474 /* For an array of chars, print with string syntax. */
475 elttype
= TYPE_TARGET_TYPE (type
);
476 i
= 0; /* Number of characters printed. */
477 if (TYPE_LENGTH (elttype
) == 1
478 && TYPE_CODE (elttype
) == TYPE_CODE_INT
480 && unpack_long (type
, valaddr
) != 0
483 fprintf_filtered (stream
, " ");
485 /* Get first character. */
486 if (read_memory ( (CORE_ADDR
) unpack_long (type
, valaddr
),
489 /* First address out of bounds. */
490 fprintf_filtered (stream
, "<Address 0x%x out of bounds>",
491 (* (int *) valaddr
));
497 int out_of_bounds
= 0;
498 char *string
= (char *) alloca (print_max
);
500 while (i
< print_max
)
503 if (read_memory ((CORE_ADDR
) unpack_long (type
, valaddr
)
516 print_string (stream
, string
, i
);
518 fprintf_filtered (stream
,
519 "*** <Address 0x%x out of bounds>",
520 (*(int *) valaddr
) + i
);
525 /* Return number of characters printed, plus one for the
526 terminating null if we have "reached the end". */
527 return i
+ (print_max
&& i
!= print_max
);
531 case TYPE_CODE_MEMBER
:
532 error ("not implemented: member type in val_print");
536 fprintf_filtered (stream
, "(0x%x &) = ", * (int *) valaddr
);
537 /* De-reference the reference. */
540 if (TYPE_CODE (TYPE_TARGET_TYPE (type
)) != TYPE_CODE_UNDEF
)
542 value val
= value_at (TYPE_TARGET_TYPE (type
), * (int *) valaddr
);
543 val_print (VALUE_TYPE (val
), VALUE_CONTENTS (val
),
544 VALUE_ADDRESS (val
), stream
, format
,
545 deref_ref
, recurse
+ 1, pretty
);
548 fprintf_filtered (stream
, "???");
552 case TYPE_CODE_UNION
:
553 if (recurse
&& !unionprint
)
555 fprintf_filtered (stream
, "{...}");
559 case TYPE_CODE_STRUCT
:
560 fprintf_filtered (stream
, "{");
561 len
= TYPE_NFIELDS (type
);
562 n_baseclasses
= TYPE_N_BASECLASSES (type
);
563 for (i
= 1; i
<= n_baseclasses
; i
++)
565 fprintf_filtered (stream
, "\n");
567 print_spaces_filtered (2 + 2 * recurse
, stream
);
568 fputs_filtered ("<", stream
);
569 fputs_filtered (TYPE_NAME (TYPE_BASECLASS (type
, i
)), stream
);
570 fputs_filtered ("> = ", stream
);
571 val_print (TYPE_FIELD_TYPE (type
, 0),
572 valaddr
+ TYPE_FIELD_BITPOS (type
, i
-1) / 8,
573 0, stream
, 0, 0, recurse
+ 1, pretty
);
576 fprintf_filtered (stream
, "\n");
577 print_spaces_filtered (2 + 2 * recurse
, stream
);
578 fputs_filtered ("members of ", stream
);
579 fputs_filtered (TYPE_NAME (type
), stream
);
580 fputs_filtered (": ", stream
);
583 fprintf_filtered (stream
, "<No data fields>");
586 for (i
-= 1; i
< len
; i
++)
588 if (i
> n_baseclasses
) fprintf_filtered (stream
, ", ");
591 fprintf_filtered (stream
, "\n");
592 print_spaces_filtered (2 + 2 * recurse
, stream
);
594 fputs_filtered (TYPE_FIELD_NAME (type
, i
), stream
);
595 fputs_filtered (" = ", stream
);
596 /* check if static field */
597 if (TYPE_FIELD_STATIC (type
, i
))
601 v
= value_static_field (type
, TYPE_FIELD_NAME (type
, i
), i
);
602 val_print (TYPE_FIELD_TYPE (type
, i
),
603 VALUE_CONTENTS (v
), 0, stream
, format
,
604 deref_ref
, recurse
+ 1, pretty
);
606 else if (TYPE_FIELD_PACKED (type
, i
))
608 char *valp
= (char *) & val
;
609 union {int i
; char c
;} test
;
612 valp
+= sizeof val
- TYPE_LENGTH (TYPE_FIELD_TYPE (type
, i
));
613 val
= unpack_field_as_long (type
, valaddr
, i
);
614 val_print (TYPE_FIELD_TYPE (type
, i
), valp
, 0,
615 stream
, format
, deref_ref
, recurse
+ 1, pretty
);
619 val_print (TYPE_FIELD_TYPE (type
, i
),
620 valaddr
+ TYPE_FIELD_BITPOS (type
, i
) / 8,
621 0, stream
, format
, deref_ref
,
622 recurse
+ 1, pretty
);
627 fprintf_filtered (stream
, "\n");
628 print_spaces_filtered (2 * recurse
, stream
);
631 fprintf_filtered (stream
, "}");
637 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
640 len
= TYPE_NFIELDS (type
);
641 val
= unpack_long (builtin_type_int
, valaddr
);
642 for (i
= 0; i
< len
; i
++)
645 if (val
== TYPE_FIELD_BITPOS (type
, i
))
649 fputs_filtered (TYPE_FIELD_NAME (type
, i
), stream
);
651 fprintf_filtered (stream
, "%d", (int) val
);
657 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
660 fprintf_filtered (stream
, "{");
661 type_print (type
, "", stream
, -1);
662 fprintf_filtered (stream
, "} ");
663 fprintf_filtered (stream
, "0x%x", address
);
669 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
672 #ifdef PRINT_TYPELESS_INTEGER
673 PRINT_TYPELESS_INTEGER (stream
, type
, unpack_long (type
, valaddr
));
676 fprintf_filtered (stream
,
677 TYPE_UNSIGNED (type
) ? "%u" : "%d",
678 unpack_long (type
, valaddr
));
680 fprintf_filtered (stream
,
681 TYPE_UNSIGNED (type
) ? "%llu" : "%lld",
682 unpack_long (type
, valaddr
));
686 if (TYPE_LENGTH (type
) == 1)
688 fprintf_filtered (stream
, " '");
689 printchar ((unsigned char) unpack_long (type
, valaddr
),
691 fprintf_filtered (stream
, "'");
698 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
702 if (is_nan ((void *) valaddr
, TYPE_LENGTH (type
)))
704 fprintf_filtered (stream
, "NaN");
712 doub
= unpack_double (type
, valaddr
, &inv
);
714 fprintf_filtered (stream
, "Invalid float value");
716 fprintf_filtered (stream
,
717 TYPE_LENGTH (type
) <= 4? "%.6g": "%.16g", doub
);
722 fprintf_filtered (stream
, "void");
726 error ("Invalid type code in symbol table.");
734 /* Nonzero if ARG (a double) is a NAN. */
741 int lowhalf
, highhalf
;
744 long i
[2]; /* ASSUMED 32 BITS */
745 float f
; /* ASSUMED 32 BITS */
746 double d
; /* ASSUMED 64 BITS */
749 arg
= (union ieee
*)fp
;
752 * Single precision float.
754 if (len
== sizeof(long))
756 highhalf
= arg
->i
[0];
757 return ((((highhalf
>> 23) & 0xFF) == 0xFF)
758 && 0 != (highhalf
& 0x7FFFFF));
761 /* Separate the high and low words of the double.
762 Distinguish big and little-endian machines. */
763 #ifdef WORDS_BIG_ENDIAN
764 lowhalf
= arg
->i
[1], highhalf
= arg
->i
[0];
766 lowhalf
= arg
->i
[0], highhalf
= arg
->i
[1];
769 /* Nan: exponent is the maximum possible, and fraction is nonzero. */
770 return (((highhalf
>>20) & 0x7ff) == 0x7ff
771 && ! ((highhalf
& 0xfffff == 0) && (lowhalf
== 0)));
775 /* Print a description of a type TYPE
776 in the form of a declaration of a variable named VARSTRING.
777 Output goes to STREAM (via stdio).
778 If SHOW is positive, we show the contents of the outermost level
779 of structure even if there is a type name that could be used instead.
780 If SHOW is negative, we never show the details of elements' types. */
783 type_print (type
, varstring
, stream
, show
)
789 type_print_1 (type
, varstring
, stream
, show
, 0);
792 /* LEVEL is the depth to indent lines by. */
795 type_print_1 (type
, varstring
, stream
, show
, level
)
802 register enum type_code code
;
803 type_print_base (type
, stream
, show
, level
);
804 code
= TYPE_CODE (type
);
805 if ((varstring
&& *varstring
)
807 /* Need a space if going to print stars or brackets;
808 but not if we will print just a type name. */
809 ((show
> 0 || TYPE_NAME (type
) == 0)
811 (code
== TYPE_CODE_PTR
|| code
== TYPE_CODE_FUNC
812 || code
== TYPE_CODE_METHOD
813 || code
== TYPE_CODE_ARRAY
814 || code
== TYPE_CODE_MEMBER
815 || code
== TYPE_CODE_REF
)))
816 fprintf_filtered (stream
, " ");
817 type_print_varspec_prefix (type
, stream
, show
, 0);
818 fputs_filtered (varstring
, stream
);
819 type_print_varspec_suffix (type
, stream
, show
, 0);
822 /* Print the method arguments ARGS to the file STREAM. */
824 type_print_method_args (args
, prefix
, varstring
, staticp
, stream
)
826 char *prefix
, *varstring
;
832 fputs_filtered (" ", stream
);
833 fputs_filtered (prefix
, stream
);
834 fputs_filtered (varstring
, stream
);
835 fputs_filtered (" (", stream
);
836 if (args
&& args
[!staticp
] && args
[!staticp
]->code
!= TYPE_CODE_VOID
)
838 i
= !staticp
; /* skip the class variable */
841 type_print (args
[i
++], "", stream
, 0);
844 fprintf_filtered (stream
, " ...");
847 else if (args
[i
]->code
!= TYPE_CODE_VOID
)
849 fprintf_filtered (stream
, ", ");
854 fprintf_filtered (stream
, ")");
857 /* If TYPE is a derived type, then print out derivation
858 information. Print out all layers of the type heirarchy
859 until we encounter one with multiple inheritance.
860 At that point, print out that ply, and return. */
862 type_print_derivation_info (stream
, type
)
867 int i
, n_baseclasses
= TYPE_N_BASECLASSES (type
);
868 struct type
*basetype
= 0;
870 while (type
&& n_baseclasses
== 1)
872 basetype
= TYPE_BASECLASS (type
, 1);
873 if (TYPE_NAME (basetype
) && (name
= TYPE_NAME (basetype
)))
875 while (*name
!= ' ') name
++;
876 fprintf_filtered (stream
, ": %s%s ",
877 TYPE_VIA_PUBLIC (basetype
) ? "public" : "private",
878 TYPE_VIA_VIRTUAL (basetype
) ? " virtual" : "");
879 fputs_filtered (name
+ 1, stream
);
880 fputs_filtered (" ", stream
);
882 n_baseclasses
= TYPE_N_BASECLASSES (basetype
);
888 if (n_baseclasses
!= 0)
889 fprintf_filtered (stream
, ": ");
890 for (i
= 1; i
<= n_baseclasses
; i
++)
892 basetype
= TYPE_BASECLASS (type
, i
);
893 if (TYPE_NAME (basetype
) && (name
= TYPE_NAME (basetype
)))
895 while (*name
!= ' ') name
++;
896 fprintf_filtered (stream
, "%s%s ",
897 TYPE_VIA_PUBLIC (basetype
) ? "public" : "private",
898 TYPE_VIA_VIRTUAL (basetype
) ? " virtual" : "");
899 fputs_filtered (name
+ 1, stream
);
901 if (i
< n_baseclasses
)
902 fprintf_filtered (stream
, ", ");
904 fprintf_filtered (stream
, " ");
908 /* Print any asterisks or open-parentheses needed before the
909 variable name (to describe its type).
911 On outermost call, pass 0 for PASSED_A_PTR.
912 On outermost call, SHOW > 0 means should ignore
913 any typename for TYPE and show its details.
914 SHOW is always zero on recursive calls. */
917 type_print_varspec_prefix (type
, stream
, show
, passed_a_ptr
)
926 if (TYPE_NAME (type
) && show
<= 0)
931 switch (TYPE_CODE (type
))
934 type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0, 1);
935 fprintf_filtered (stream
, "*");
938 case TYPE_CODE_MEMBER
:
940 fprintf_filtered (stream
, "(");
941 type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0,
943 fprintf_filtered (stream
, " ");
944 type_print_base (TYPE_DOMAIN_TYPE (type
), stream
, 0,
946 fprintf_filtered (stream
, "::");
949 case TYPE_CODE_METHOD
:
951 fprintf (stream
, "(");
952 type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0,
954 fprintf_filtered (stream
, " ");
955 type_print_base (TYPE_DOMAIN_TYPE (type
), stream
, 0,
957 fprintf_filtered (stream
, "::");
961 type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0, 1);
962 fprintf_filtered (stream
, "&");
966 type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0,
969 fprintf_filtered (stream
, "(");
972 case TYPE_CODE_ARRAY
:
973 type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0,
976 fprintf_filtered (stream
, "(");
980 /* Print any array sizes, function arguments or close parentheses
981 needed after the variable name (to describe its type).
982 Args work like type_print_varspec_prefix. */
985 type_print_varspec_suffix (type
, stream
, show
, passed_a_ptr
)
994 if (TYPE_NAME (type
) && show
<= 0)
999 switch (TYPE_CODE (type
))
1001 case TYPE_CODE_ARRAY
:
1003 fprintf_filtered (stream
, ")");
1005 fprintf_filtered (stream
, "[");
1006 if (TYPE_LENGTH (type
) >= 0
1007 && TYPE_LENGTH (TYPE_TARGET_TYPE (type
)) > 0)
1008 fprintf_filtered (stream
, "%d",
1010 / TYPE_LENGTH (TYPE_TARGET_TYPE (type
))));
1011 fprintf_filtered (stream
, "]");
1013 type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0,
1017 case TYPE_CODE_MEMBER
:
1019 fprintf_filtered (stream
, ")");
1020 type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0, 0);
1023 case TYPE_CODE_METHOD
:
1025 fprintf_filtered (stream
, ")");
1026 type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0, 0);
1030 struct type
**args
= TYPE_ARG_TYPES (type
);
1032 fprintf_filtered (stream
, "(");
1034 fprintf_filtered (stream
, "...");
1035 else for (i
= 1; args
[i
] != 0 && args
[i
]->code
!= TYPE_CODE_VOID
; i
++)
1037 type_print_1 (args
[i
], "", stream
, -1, 0);
1039 fprintf_filtered (stream
, "...");
1040 else if (args
[i
+1]->code
!= TYPE_CODE_VOID
)
1041 fprintf_filtered (stream
, ",");
1043 fprintf_filtered (stream
, ")");
1049 type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0, 1);
1052 case TYPE_CODE_FUNC
:
1053 type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0,
1056 fprintf_filtered (stream
, ")");
1057 fprintf_filtered (stream
, "()");
1062 /* Print the name of the type (or the ultimate pointer target,
1063 function value or array element), or the description of a
1066 SHOW nonzero means don't print this type as just its name;
1067 show its real definition even if it has a name.
1068 SHOW zero means print just typename or struct tag if there is one
1069 SHOW negative means abbreviate structure elements.
1070 SHOW is decremented for printing of structure elements.
1072 LEVEL is the depth to indent by.
1073 We increase it for some recursive calls. */
1076 type_print_base (type
, stream
, show
, level
)
1085 register int lastval
;
1091 fprintf_filtered (stream
, "type unknown");
1095 if (TYPE_NAME (type
) && show
<= 0)
1097 fputs_filtered (TYPE_NAME (type
), stream
);
1101 switch (TYPE_CODE (type
))
1103 case TYPE_CODE_ARRAY
:
1105 case TYPE_CODE_MEMBER
:
1107 case TYPE_CODE_FUNC
:
1108 case TYPE_CODE_METHOD
:
1109 type_print_base (TYPE_TARGET_TYPE (type
), stream
, show
, level
);
1112 case TYPE_CODE_STRUCT
:
1113 fprintf_filtered (stream
, "struct ");
1116 case TYPE_CODE_UNION
:
1117 fprintf_filtered (stream
, "union ");
1119 if (TYPE_NAME (type
) && (name
= TYPE_NAME (type
)))
1121 while (*name
!= ' ') name
++;
1122 fputs_filtered (name
+ 1, stream
);
1123 fputs_filtered (" ", stream
);
1126 fprintf_filtered (stream
, "{...}");
1131 type_print_derivation_info (stream
, type
);
1133 fprintf_filtered (stream
, "{");
1134 len
= TYPE_NFIELDS (type
);
1136 fprintf_filtered (stream
, "\n");
1139 if (TYPE_FLAGS (type
) & TYPE_FLAG_STUB
)
1140 fprintf_filtered (stream
, "<incomplete type>\n");
1142 fprintf_filtered (stream
, "<no data fields>\n");
1145 /* If there is a base class for this type,
1146 do not print the field that it occupies. */
1147 for (i
= TYPE_N_BASECLASSES (type
); i
< len
; i
++)
1150 /* Don't print out virtual function table. */
1151 if (! strncmp (TYPE_FIELD_NAME (type
, i
),
1155 print_spaces_filtered (level
+ 4, stream
);
1156 if (TYPE_FIELD_STATIC (type
, i
))
1158 fprintf_filtered (stream
, "static ");
1160 type_print_1 (TYPE_FIELD_TYPE (type
, i
),
1161 TYPE_FIELD_NAME (type
, i
),
1162 stream
, show
- 1, level
+ 4);
1163 if (!TYPE_FIELD_STATIC (type
, i
)
1164 && TYPE_FIELD_PACKED (type
, i
))
1166 /* It is a bitfield. This code does not attempt
1167 to look at the bitpos and reconstruct filler,
1168 unnamed fields. This would lead to misleading
1169 results if the compiler does not put out fields
1170 for such things (I don't know what it does). */
1171 fprintf_filtered (stream
, " : %d",
1172 TYPE_FIELD_BITSIZE (type
, i
));
1174 fprintf_filtered (stream
, ";\n");
1177 /* C++: print out the methods */
1178 len
= TYPE_NFN_FIELDS (type
);
1179 if (len
) fprintf_filtered (stream
, "\n");
1180 for (i
= 0; i
< len
; i
++)
1182 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (type
, i
);
1183 int j
, len2
= TYPE_FN_FIELDLIST_LENGTH (type
, i
);
1185 for (j
= 0; j
< len2
; j
++)
1188 print_spaces_filtered (level
+ 4, stream
);
1189 if (TYPE_FN_FIELD_VIRTUAL_P (f
, j
))
1190 fprintf_filtered (stream
, "virtual ");
1191 else if (TYPE_FN_FIELD_STATIC_P (f
, j
))
1192 fprintf_filtered (stream
, "static ");
1193 type_print (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f
, j
)), "", stream
, 0);
1194 if (TYPE_FN_FIELD_PHYSNAME (f
, j
)[0] == '_'
1195 && TYPE_FN_FIELD_PHYSNAME (f
, j
)[1] == '$')
1196 type_print_method_args
1197 (TYPE_FN_FIELD_ARGS (f
, j
) + 1, "~",
1198 TYPE_FN_FIELDLIST_NAME (type
, i
), 0, stream
);
1200 type_print_method_args
1201 (TYPE_FN_FIELD_ARGS (f
, j
), "",
1202 TYPE_FN_FIELDLIST_NAME (type
, i
),
1203 TYPE_FN_FIELD_STATIC_P (f
, j
), stream
);
1205 fprintf_filtered (stream
, ";\n");
1207 if (len2
) fprintf_filtered (stream
, "\n");
1210 print_spaces_filtered (level
, stream
);
1211 fprintf_filtered (stream
, "}");
1215 case TYPE_CODE_ENUM
:
1216 fprintf_filtered (stream
, "enum ");
1217 if (TYPE_NAME (type
))
1219 name
= TYPE_NAME (type
);
1220 while (*name
!= ' ') name
++;
1221 fputs_filtered (name
+ 1, stream
);
1222 fputs_filtered (" ", stream
);
1225 fprintf_filtered (stream
, "{...}");
1228 fprintf_filtered (stream
, "{");
1229 len
= TYPE_NFIELDS (type
);
1231 for (i
= 0; i
< len
; i
++)
1234 if (i
) fprintf_filtered (stream
, ", ");
1235 fputs_filtered (TYPE_FIELD_NAME (type
, i
), stream
);
1236 if (lastval
!= TYPE_FIELD_BITPOS (type
, i
))
1238 fprintf_filtered (stream
, " : %d", TYPE_FIELD_BITPOS (type
, i
));
1239 lastval
= TYPE_FIELD_BITPOS (type
, i
);
1243 fprintf_filtered (stream
, "}");
1248 if (TYPE_UNSIGNED (type
))
1249 name
= unsigned_type_table
[TYPE_LENGTH (type
)];
1251 name
= signed_type_table
[TYPE_LENGTH (type
)];
1252 fputs_filtered (name
, stream
);
1256 name
= float_type_table
[TYPE_LENGTH (type
)];
1257 fputs_filtered (name
, stream
);
1260 case TYPE_CODE_VOID
:
1261 fprintf_filtered (stream
, "void");
1265 fprintf_filtered (stream
, "struct unknown");
1269 error ("Invalid type code in symbol table.");
1274 set_maximum_command (arg
)
1277 if (!arg
) error_no_arg ("value for maximum elements to print");
1278 print_max
= parse_and_eval_address (arg
);
1282 set_prettyprint_command (arg
, from_tty
)
1286 prettyprint
= parse_binary_operation ("set prettyprint", arg
);
1290 set_unionprint_command (arg
, from_tty
)
1294 unionprint
= parse_binary_operation ("set unionprint", arg
);
1297 format_info (arg
, from_tty
)
1302 error ("\"info format\" does not take any arguments.");
1303 printf ("Prettyprinting of structures is %s.\n",
1304 prettyprint
? "on" : "off");
1305 printf ("Printing of unions interior to structures is %s.\n",
1306 unionprint
? "on" : "off");
1307 printf ("The maximum number of array elements printed is %d.\n",
1311 extern struct cmd_list_element
*setlist
;
1314 _initialize_valprint ()
1316 add_cmd ("array-max", class_vars
, set_maximum_command
,
1317 "Set NUMBER as limit on string chars or array elements to print.",
1320 add_cmd ("prettyprint", class_support
, set_prettyprint_command
,
1321 "Turn prettyprinting of structures on and off.",
1323 add_alias_cmd ("pp", "prettyprint", class_support
, 1, &setlist
);
1325 add_cmd ("unionprint", class_support
, set_unionprint_command
,
1326 "Turn printing of unions interior to structures on and off.",
1329 add_info ("format", format_info
,
1330 "Show current settings of data formatting options.");
1332 /* Give people the defaults which they are used to. */
1339 = (char **) xmalloc ((1 + sizeof (unsigned LONGEST
)) * sizeof (char *));
1340 bzero (unsigned_type_table
, (1 + sizeof (unsigned LONGEST
)));
1341 unsigned_type_table
[sizeof (unsigned char)] = "unsigned char";
1342 unsigned_type_table
[sizeof (unsigned short)] = "unsigned short";
1343 unsigned_type_table
[sizeof (unsigned long)] = "unsigned long";
1344 unsigned_type_table
[sizeof (unsigned int)] = "unsigned int";
1346 unsigned_type_table
[sizeof (unsigned long long)] = "unsigned long long";
1350 = (char **) xmalloc ((1 + sizeof (LONGEST
)) * sizeof (char *));
1351 bzero (signed_type_table
, (1 + sizeof (LONGEST
)));
1352 signed_type_table
[sizeof (char)] = "char";
1353 signed_type_table
[sizeof (short)] = "short";
1354 signed_type_table
[sizeof (long)] = "long";
1355 signed_type_table
[sizeof (int)] = "int";
1357 signed_type_table
[sizeof (long long)] = "long long";
1361 = (char **) xmalloc ((1 + sizeof (double)) * sizeof (char *));
1362 bzero (float_type_table
, (1 + sizeof (double)));
1363 float_type_table
[sizeof (float)] = "float";
1364 float_type_table
[sizeof (double)] = "double";
This page took 0.057274 seconds and 5 git commands to generate.