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 /* GNU software is only expected to run on systems with 32-bit integers. */
27 #define UINT_MAX 0xffffffff
29 /* Maximum number of chars to print for a string pointer value
30 or vector contents, or UINT_MAX for no limit. */
32 static unsigned int print_max
;
34 static void type_print_varspec_suffix ();
35 static void type_print_varspec_prefix ();
36 static void type_print_base ();
37 static void type_print_method_args ();
40 char **unsigned_type_table
;
41 char **signed_type_table
;
42 char **float_type_table
;
45 /* Print repeat counts if there are more than this
46 many repetitions of an element in an array. */
47 #define REPEAT_COUNT_THRESHOLD 10
49 /* Print the character string STRING, printing at most LENGTH characters.
50 Printing stops early if the number hits print_max; repeat counts
51 are printed as appropriate. Print ellipses at the end if we
52 had to stop before printing LENGTH characters, or if FORCE_ELLIPSES. */
55 print_string (stream
, string
, length
, force_ellipses
)
61 register unsigned int i
;
62 unsigned int things_printed
= 0;
68 fputs_filtered ("\"\"", stdout
);
72 for (i
= 0; i
< length
&& things_printed
< print_max
; ++i
)
74 /* Position of the character we are examining
75 to see whether it is repeated. */
77 /* Number of repititions we have detected so far. */
84 fputs_filtered (", ", stream
);
90 while (rep1
< length
&& string
[rep1
] == string
[i
])
96 if (reps
> REPEAT_COUNT_THRESHOLD
)
100 fputs_filtered ("\", ", stream
);
103 fputs_filtered ("'", stream
);
104 printchar (string
[i
], stream
, '\'');
105 fprintf_filtered (stream
, "' <repeats %u times>", reps
);
107 things_printed
+= REPEAT_COUNT_THRESHOLD
;
114 fputs_filtered ("\"", stream
);
117 printchar (string
[i
], stream
, '"');
122 /* Terminate the quotes if necessary. */
124 fputs_filtered ("\"", stream
);
126 if (force_ellipses
|| i
< length
)
127 fputs_filtered ("...", stream
);
130 /* Print the value VAL in C-ish syntax on stream STREAM.
131 FORMAT is a format-letter, or 0 for print in natural format of data type.
132 If the object printed is a string pointer, returns
133 the number of string bytes printed. */
136 value_print (val
, stream
, format
, pretty
)
140 enum val_prettyprint pretty
;
142 register unsigned int i
, n
, typelen
;
144 /* A "repeated" value really contains several values in a row.
145 They are made by the @ operator.
146 Print such values as if they were arrays. */
148 if (VALUE_REPEATED (val
))
150 n
= VALUE_REPETITIONS (val
);
151 typelen
= TYPE_LENGTH (VALUE_TYPE (val
));
152 fprintf_filtered (stream
, "{");
153 /* Print arrays of characters using string syntax. */
154 if (typelen
== 1 && TYPE_CODE (VALUE_TYPE (val
)) == TYPE_CODE_INT
156 print_string (stream
, VALUE_CONTENTS (val
), n
, 0);
159 unsigned int things_printed
= 0;
161 for (i
= 0; i
< n
&& things_printed
< print_max
; i
++)
163 /* Position of the array element we are examining to see
164 whether it is repeated. */
166 /* Number of repititions we have detected so far. */
170 fprintf_filtered (stream
, ", ");
175 && !bcmp (VALUE_CONTENTS (val
) + typelen
* i
,
176 VALUE_CONTENTS (val
) + typelen
* rep1
, typelen
))
182 if (reps
> REPEAT_COUNT_THRESHOLD
)
184 val_print (VALUE_TYPE (val
),
185 VALUE_CONTENTS (val
) + typelen
* i
,
186 VALUE_ADDRESS (val
) + typelen
* i
,
187 stream
, format
, 1, 0, pretty
);
188 fprintf (stream
, " <repeats %u times>", reps
);
190 things_printed
+= REPEAT_COUNT_THRESHOLD
;
194 val_print (VALUE_TYPE (val
),
195 VALUE_CONTENTS (val
) + typelen
* i
,
196 VALUE_ADDRESS (val
) + typelen
* i
,
197 stream
, format
, 1, 0, pretty
);
202 fprintf_filtered (stream
, "...");
204 fprintf_filtered (stream
, "}");
209 /* If it is a pointer, indicate what it points to.
211 Print type also if it is a reference.
213 C++: if it is a member pointer, we will take care
214 of that when we print it. */
215 if (TYPE_CODE (VALUE_TYPE (val
)) == TYPE_CODE_PTR
216 || TYPE_CODE (VALUE_TYPE (val
)) == TYPE_CODE_REF
)
218 fprintf_filtered (stream
, "(");
219 type_print (VALUE_TYPE (val
), "", stream
, -1);
220 fprintf_filtered (stream
, ") ");
222 /* If this is a function pointer, try to print what
223 function it is pointing to by name. */
224 if (TYPE_CODE (TYPE_TARGET_TYPE (VALUE_TYPE (val
)))
227 print_address (((int *) VALUE_CONTENTS (val
))[0], stream
);
228 /* Return value is irrelevant except for string pointers. */
232 return val_print (VALUE_TYPE (val
), VALUE_CONTENTS (val
),
233 VALUE_ADDRESS (val
), stream
, format
, 1, 0, pretty
);
237 static int prettyprint
; /* Controls prettyprinting of structures. */
238 int unionprint
; /* Controls printing of nested unions. */
240 /* Print data of type TYPE located at VALADDR (within GDB),
241 which came from the inferior at address ADDRESS,
242 onto stdio stream STREAM according to FORMAT
243 (a letter or 0 for natural format).
245 If the data are a string pointer, returns the number of
246 sting characters printed.
248 if DEREF_REF is nonzero, then dereference references,
249 otherwise just print them like pointers.
251 The PRETTY parameter controls prettyprinting. */
254 val_print (type
, valaddr
, address
, stream
, format
,
255 deref_ref
, recurse
, pretty
)
263 enum val_prettyprint pretty
;
265 register unsigned int i
;
266 int len
, n_baseclasses
;
267 struct type
*elttype
;
272 if (pretty
== Val_pretty_default
)
274 pretty
= prettyprint
? Val_prettyprint
: Val_no_prettyprint
;
279 if (TYPE_FLAGS (type
) & TYPE_FLAG_STUB
)
281 fprintf_filtered (stream
, "<Type not defined in this context>");
286 switch (TYPE_CODE (type
))
288 case TYPE_CODE_ARRAY
:
289 if (TYPE_LENGTH (type
) >= 0
290 && TYPE_LENGTH (TYPE_TARGET_TYPE (type
)) > 0)
292 elttype
= TYPE_TARGET_TYPE (type
);
293 eltlen
= TYPE_LENGTH (elttype
);
294 len
= TYPE_LENGTH (type
) / eltlen
;
295 fprintf_filtered (stream
, "{");
296 /* For an array of chars, print with string syntax. */
297 if (eltlen
== 1 && TYPE_CODE (elttype
) == TYPE_CODE_INT
299 print_string (stream
, valaddr
, len
, 0);
302 unsigned int things_printed
= 0;
304 for (i
= 0; i
< len
&& things_printed
< print_max
; i
++)
306 /* Position of the array element we are examining to see
307 whether it is repeated. */
309 /* Number of repititions we have detected so far. */
313 fprintf_filtered (stream
, ", ");
318 && !bcmp (valaddr
+ i
* eltlen
,
319 valaddr
+ rep1
* eltlen
, eltlen
))
325 if (reps
> REPEAT_COUNT_THRESHOLD
)
327 val_print (elttype
, valaddr
+ i
* eltlen
,
328 0, stream
, format
, deref_ref
,
329 recurse
+ 1, pretty
);
330 fprintf_filtered (stream
, " <repeats %u times>", reps
);
332 things_printed
+= REPEAT_COUNT_THRESHOLD
;
336 val_print (elttype
, valaddr
+ i
* eltlen
,
337 0, stream
, format
, deref_ref
,
338 recurse
+ 1, pretty
);
343 fprintf_filtered (stream
, "...");
345 fprintf_filtered (stream
, "}");
348 /* Array of unspecified length: treat like pointer to first elt. */
349 valaddr
= (char *) &address
;
354 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
357 if (TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_METHOD
)
359 struct type
*domain
= TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (type
));
360 struct type
*target
= TYPE_TARGET_TYPE (TYPE_TARGET_TYPE (type
));
365 val
= unpack_long (builtin_type_int
, valaddr
);
368 len
= TYPE_NFN_FIELDS (domain
);
369 for (i
= 0; i
< len
; i
++)
371 f
= TYPE_FN_FIELDLIST1 (domain
, i
);
372 len2
= TYPE_FN_FIELDLIST_LENGTH (domain
, i
);
374 for (j
= 0; j
< len2
; j
++)
377 if (TYPE_FN_FIELD_VOFFSET (f
, j
) == val
)
387 struct symbol
*sym
= find_pc_function ((CORE_ADDR
) val
);
389 error ("invalid pointer to member function");
390 len
= TYPE_NFN_FIELDS (domain
);
391 for (i
= 0; i
< len
; i
++)
393 f
= TYPE_FN_FIELDLIST1 (domain
, i
);
394 len2
= TYPE_FN_FIELDLIST_LENGTH (domain
, i
);
396 for (j
= 0; j
< len2
; j
++)
399 if (!strcmp (SYMBOL_NAME (sym
), TYPE_FN_FIELD_PHYSNAME (f
, j
)))
407 fprintf_filtered (stream
, "&");
408 type_print_varspec_prefix (TYPE_FN_FIELD_TYPE (f
, j
), stream
, 0, 0);
409 fprintf (stream
, kind
);
410 if (TYPE_FN_FIELD_PHYSNAME (f
, j
)[0] == '_'
411 && TYPE_FN_FIELD_PHYSNAME (f
, j
)[1] == '$')
412 type_print_method_args
413 (TYPE_FN_FIELD_ARGS (f
, j
) + 1, "~",
414 TYPE_FN_FIELDLIST_NAME (domain
, i
), 0, stream
);
416 type_print_method_args
417 (TYPE_FN_FIELD_ARGS (f
, j
), "",
418 TYPE_FN_FIELDLIST_NAME (domain
, i
), 0, stream
);
421 fprintf_filtered (stream
, "(");
422 type_print (type
, "", stream
, -1);
423 fprintf_filtered (stream
, ") %d", (int) val
>> 3);
425 else if (TYPE_CODE (TYPE_TARGET_TYPE (type
)) == TYPE_CODE_MEMBER
)
427 struct type
*domain
= TYPE_DOMAIN_TYPE (TYPE_TARGET_TYPE (type
));
428 struct type
*target
= TYPE_TARGET_TYPE (TYPE_TARGET_TYPE (type
));
431 /* VAL is a byte offset into the structure type DOMAIN.
432 Find the name of the field for that offset and
436 len
= TYPE_NFIELDS (domain
);
437 /* @@ Make VAL into bit offset */
438 val
= unpack_long (builtin_type_int
, valaddr
) << 3;
439 for (i
= 0; i
< len
; i
++)
441 int bitpos
= TYPE_FIELD_BITPOS (domain
, i
);
445 if (val
< bitpos
&& i
> 0)
447 int ptrsize
= (TYPE_LENGTH (builtin_type_char
) * TYPE_LENGTH (target
));
448 /* Somehow pointing into a field. */
450 extra
= (val
- TYPE_FIELD_BITPOS (domain
, i
));
460 fprintf_filtered (stream
, "&");
461 type_print_base (domain
, stream
, 0, 0);
462 fprintf_filtered (stream
, "::");
463 fputs_filtered (TYPE_FIELD_NAME (domain
, i
), stream
);
465 fprintf_filtered (stream
, " + %d bytes", extra
);
467 fprintf_filtered (stream
, " (offset in bits)");
470 fprintf_filtered (stream
, "%d", val
>> 3);
474 fprintf_filtered (stream
, "0x%x", * (int *) valaddr
);
475 /* For a pointer to char or unsigned char,
476 also print the string pointed to, unless pointer is null. */
478 /* For an array of chars, print with string syntax. */
479 elttype
= TYPE_TARGET_TYPE (type
);
480 i
= 0; /* Number of characters printed. */
481 if (TYPE_LENGTH (elttype
) == 1
482 && TYPE_CODE (elttype
) == TYPE_CODE_INT
484 && unpack_long (type
, valaddr
) != 0
485 /* If print_max is UINT_MAX, the alloca below will fail.
486 In that case don't try to print the string. */
487 && print_max
< UINT_MAX
)
489 fprintf_filtered (stream
, " ");
491 /* Get first character. */
492 if (read_memory ( (CORE_ADDR
) unpack_long (type
, valaddr
),
495 /* First address out of bounds. */
496 fprintf_filtered (stream
, "<Address 0x%x out of bounds>",
497 (* (int *) valaddr
));
503 int out_of_bounds
= 0;
504 char *string
= (char *) alloca (print_max
);
506 /* If the loop ends by us hitting print_max characters,
507 we need to have elipses at the end. */
508 int force_ellipses
= 1;
510 /* This loop only fetches print_max characters, even
511 though print_string might want to print more
512 (with repeated characters). This is so that
513 we don't spend forever fetching if we print
514 a long string consisting of the same character
516 while (i
< print_max
)
519 if (read_memory ((CORE_ADDR
) unpack_long (type
, valaddr
)
536 print_string (stream
, string
, i
, force_ellipses
);
538 fprintf_filtered (stream
,
539 " <Address 0x%x out of bounds>",
540 (*(int *) valaddr
) + i
);
545 /* Return number of characters printed, plus one for the
546 terminating null if we have "reached the end". */
547 return i
+ (print_max
&& i
!= print_max
);
551 case TYPE_CODE_MEMBER
:
552 error ("not implemented: member type in val_print");
556 fprintf_filtered (stream
, "(0x%x &) = ", * (int *) valaddr
);
557 /* De-reference the reference. */
560 if (TYPE_CODE (TYPE_TARGET_TYPE (type
)) != TYPE_CODE_UNDEF
)
562 value val
= value_at (TYPE_TARGET_TYPE (type
), * (int *) valaddr
);
563 val_print (VALUE_TYPE (val
), VALUE_CONTENTS (val
),
564 VALUE_ADDRESS (val
), stream
, format
,
565 deref_ref
, recurse
+ 1, pretty
);
568 fprintf_filtered (stream
, "???");
572 case TYPE_CODE_UNION
:
573 if (recurse
&& !unionprint
)
575 fprintf_filtered (stream
, "{...}");
579 case TYPE_CODE_STRUCT
:
580 fprintf_filtered (stream
, "{");
581 len
= TYPE_NFIELDS (type
);
582 n_baseclasses
= TYPE_N_BASECLASSES (type
);
583 for (i
= 1; i
<= n_baseclasses
; i
++)
585 fprintf_filtered (stream
, "\n");
587 print_spaces_filtered (2 + 2 * recurse
, stream
);
588 fputs_filtered ("<", stream
);
589 fputs_filtered (TYPE_NAME (TYPE_BASECLASS (type
, i
)), stream
);
590 fputs_filtered ("> = ", stream
);
591 val_print (TYPE_FIELD_TYPE (type
, 0),
592 valaddr
+ TYPE_FIELD_BITPOS (type
, i
-1) / 8,
593 0, stream
, 0, 0, recurse
+ 1, pretty
);
596 fprintf_filtered (stream
, "\n");
597 print_spaces_filtered (2 + 2 * recurse
, stream
);
598 fputs_filtered ("members of ", stream
);
599 fputs_filtered (TYPE_NAME (type
), stream
);
600 fputs_filtered (": ", stream
);
603 fprintf_filtered (stream
, "<No data fields>");
606 for (i
-= 1; i
< len
; i
++)
608 if (i
> n_baseclasses
) fprintf_filtered (stream
, ", ");
611 fprintf_filtered (stream
, "\n");
612 print_spaces_filtered (2 + 2 * recurse
, stream
);
614 fputs_filtered (TYPE_FIELD_NAME (type
, i
), stream
);
615 fputs_filtered (" = ", stream
);
616 /* check if static field */
617 if (TYPE_FIELD_STATIC (type
, i
))
621 v
= value_static_field (type
, TYPE_FIELD_NAME (type
, i
), i
);
622 val_print (TYPE_FIELD_TYPE (type
, i
),
623 VALUE_CONTENTS (v
), 0, stream
, format
,
624 deref_ref
, recurse
+ 1, pretty
);
626 else if (TYPE_FIELD_PACKED (type
, i
))
628 char *valp
= (char *) & val
;
629 union {int i
; char c
;} test
;
632 valp
+= sizeof val
- TYPE_LENGTH (TYPE_FIELD_TYPE (type
, i
));
633 val
= unpack_field_as_long (type
, valaddr
, i
);
634 val_print (TYPE_FIELD_TYPE (type
, i
), valp
, 0,
635 stream
, format
, deref_ref
, recurse
+ 1, pretty
);
639 val_print (TYPE_FIELD_TYPE (type
, i
),
640 valaddr
+ TYPE_FIELD_BITPOS (type
, i
) / 8,
641 0, stream
, format
, deref_ref
,
642 recurse
+ 1, pretty
);
647 fprintf_filtered (stream
, "\n");
648 print_spaces_filtered (2 * recurse
, stream
);
651 fprintf_filtered (stream
, "}");
657 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
660 len
= TYPE_NFIELDS (type
);
661 val
= unpack_long (builtin_type_int
, valaddr
);
662 for (i
= 0; i
< len
; i
++)
665 if (val
== TYPE_FIELD_BITPOS (type
, i
))
669 fputs_filtered (TYPE_FIELD_NAME (type
, i
), stream
);
671 fprintf_filtered (stream
, "%d", (int) val
);
677 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
680 fprintf_filtered (stream
, "{");
681 type_print (type
, "", stream
, -1);
682 fprintf_filtered (stream
, "} ");
683 fprintf_filtered (stream
, "0x%x", address
);
689 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
692 #ifdef PRINT_TYPELESS_INTEGER
693 PRINT_TYPELESS_INTEGER (stream
, type
, unpack_long (type
, valaddr
));
696 fprintf_filtered (stream
,
697 TYPE_UNSIGNED (type
) ? "%u" : "%d",
698 unpack_long (type
, valaddr
));
700 fprintf_filtered (stream
,
701 TYPE_UNSIGNED (type
) ? "%llu" : "%lld",
702 unpack_long (type
, valaddr
));
706 if (TYPE_LENGTH (type
) == 1)
708 fprintf_filtered (stream
, " '");
709 printchar ((unsigned char) unpack_long (type
, valaddr
),
711 fprintf_filtered (stream
, "'");
718 print_scalar_formatted (valaddr
, type
, format
, 0, stream
);
722 if (is_nan ((char *) valaddr
, TYPE_LENGTH (type
)))
724 fprintf_filtered (stream
, "NaN");
732 doub
= unpack_double (type
, valaddr
, &inv
);
734 fprintf_filtered (stream
, "Invalid float value");
736 fprintf_filtered (stream
,
737 TYPE_LENGTH (type
) <= 4? "%.6g": "%.16g", doub
);
742 fprintf_filtered (stream
, "void");
746 error ("Invalid type code in symbol table.");
754 /* Nonzero if ARG (a double) is a NAN. */
761 int lowhalf
, highhalf
;
764 long i
[2]; /* ASSUMED 32 BITS */
765 float f
; /* ASSUMED 32 BITS */
766 double d
; /* ASSUMED 64 BITS */
769 arg
= (union ieee
*)fp
;
772 * Single precision float.
774 if (len
== sizeof(long))
776 highhalf
= arg
->i
[0];
777 return ((((highhalf
>> 23) & 0xFF) == 0xFF)
778 && 0 != (highhalf
& 0x7FFFFF));
781 /* Separate the high and low words of the double.
782 Distinguish big and little-endian machines. */
783 #ifdef WORDS_BIG_ENDIAN
784 lowhalf
= arg
->i
[1], highhalf
= arg
->i
[0];
786 lowhalf
= arg
->i
[0], highhalf
= arg
->i
[1];
789 /* Nan: exponent is the maximum possible, and fraction is nonzero. */
790 return (((highhalf
>>20) & 0x7ff) == 0x7ff
791 && ! ((highhalf
& 0xfffff == 0) && (lowhalf
== 0)));
795 /* Print a description of a type TYPE
796 in the form of a declaration of a variable named VARSTRING.
797 Output goes to STREAM (via stdio).
798 If SHOW is positive, we show the contents of the outermost level
799 of structure even if there is a type name that could be used instead.
800 If SHOW is negative, we never show the details of elements' types. */
803 type_print (type
, varstring
, stream
, show
)
809 type_print_1 (type
, varstring
, stream
, show
, 0);
812 /* LEVEL is the depth to indent lines by. */
815 type_print_1 (type
, varstring
, stream
, show
, level
)
822 register enum type_code code
;
823 type_print_base (type
, stream
, show
, level
);
824 code
= TYPE_CODE (type
);
825 if ((varstring
&& *varstring
)
827 /* Need a space if going to print stars or brackets;
828 but not if we will print just a type name. */
829 ((show
> 0 || TYPE_NAME (type
) == 0)
831 (code
== TYPE_CODE_PTR
|| code
== TYPE_CODE_FUNC
832 || code
== TYPE_CODE_METHOD
833 || code
== TYPE_CODE_ARRAY
834 || code
== TYPE_CODE_MEMBER
835 || code
== TYPE_CODE_REF
)))
836 fprintf_filtered (stream
, " ");
837 type_print_varspec_prefix (type
, stream
, show
, 0);
838 fputs_filtered (varstring
, stream
);
839 type_print_varspec_suffix (type
, stream
, show
, 0);
842 /* Print the method arguments ARGS to the file STREAM. */
844 type_print_method_args (args
, prefix
, varstring
, staticp
, stream
)
846 char *prefix
, *varstring
;
852 fputs_filtered (" ", stream
);
853 fputs_filtered (prefix
, stream
);
854 fputs_filtered (varstring
, stream
);
855 fputs_filtered (" (", stream
);
856 if (args
&& args
[!staticp
] && args
[!staticp
]->code
!= TYPE_CODE_VOID
)
858 i
= !staticp
; /* skip the class variable */
861 type_print (args
[i
++], "", stream
, 0);
864 fprintf_filtered (stream
, " ...");
867 else if (args
[i
]->code
!= TYPE_CODE_VOID
)
869 fprintf_filtered (stream
, ", ");
874 fprintf_filtered (stream
, ")");
877 /* If TYPE is a derived type, then print out derivation
878 information. Print out all layers of the type heirarchy
879 until we encounter one with multiple inheritance.
880 At that point, print out that ply, and return. */
882 type_print_derivation_info (stream
, type
)
887 int i
, n_baseclasses
= TYPE_N_BASECLASSES (type
);
888 struct type
*basetype
= 0;
890 while (type
&& n_baseclasses
== 1)
892 basetype
= TYPE_BASECLASS (type
, 1);
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
);
900 fputs_filtered (" ", stream
);
902 n_baseclasses
= TYPE_N_BASECLASSES (basetype
);
908 if (n_baseclasses
!= 0)
909 fprintf_filtered (stream
, ": ");
910 for (i
= 1; i
<= n_baseclasses
; i
++)
912 basetype
= TYPE_BASECLASS (type
, i
);
913 if (TYPE_NAME (basetype
) && (name
= TYPE_NAME (basetype
)))
915 while (*name
!= ' ') name
++;
916 fprintf_filtered (stream
, "%s%s ",
917 TYPE_VIA_PUBLIC (basetype
) ? "public" : "private",
918 TYPE_VIA_VIRTUAL (basetype
) ? " virtual" : "");
919 fputs_filtered (name
+ 1, stream
);
921 if (i
< n_baseclasses
)
922 fprintf_filtered (stream
, ", ");
924 fprintf_filtered (stream
, " ");
928 /* Print any asterisks or open-parentheses needed before the
929 variable name (to describe its type).
931 On outermost call, pass 0 for PASSED_A_PTR.
932 On outermost call, SHOW > 0 means should ignore
933 any typename for TYPE and show its details.
934 SHOW is always zero on recursive calls. */
937 type_print_varspec_prefix (type
, stream
, show
, passed_a_ptr
)
946 if (TYPE_NAME (type
) && show
<= 0)
951 switch (TYPE_CODE (type
))
954 type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0, 1);
955 fprintf_filtered (stream
, "*");
958 case TYPE_CODE_MEMBER
:
960 fprintf_filtered (stream
, "(");
961 type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0,
963 fprintf_filtered (stream
, " ");
964 type_print_base (TYPE_DOMAIN_TYPE (type
), stream
, 0,
966 fprintf_filtered (stream
, "::");
969 case TYPE_CODE_METHOD
:
971 fprintf (stream
, "(");
972 type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0,
974 fprintf_filtered (stream
, " ");
975 type_print_base (TYPE_DOMAIN_TYPE (type
), stream
, 0,
977 fprintf_filtered (stream
, "::");
981 type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0, 1);
982 fprintf_filtered (stream
, "&");
986 type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0,
989 fprintf_filtered (stream
, "(");
992 case TYPE_CODE_ARRAY
:
993 type_print_varspec_prefix (TYPE_TARGET_TYPE (type
), stream
, 0,
996 fprintf_filtered (stream
, "(");
1000 /* Print any array sizes, function arguments or close parentheses
1001 needed after the variable name (to describe its type).
1002 Args work like type_print_varspec_prefix. */
1005 type_print_varspec_suffix (type
, stream
, show
, passed_a_ptr
)
1014 if (TYPE_NAME (type
) && show
<= 0)
1019 switch (TYPE_CODE (type
))
1021 case TYPE_CODE_ARRAY
:
1023 fprintf_filtered (stream
, ")");
1025 fprintf_filtered (stream
, "[");
1026 if (TYPE_LENGTH (type
) >= 0
1027 && TYPE_LENGTH (TYPE_TARGET_TYPE (type
)) > 0)
1028 fprintf_filtered (stream
, "%d",
1030 / TYPE_LENGTH (TYPE_TARGET_TYPE (type
))));
1031 fprintf_filtered (stream
, "]");
1033 type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0,
1037 case TYPE_CODE_MEMBER
:
1039 fprintf_filtered (stream
, ")");
1040 type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0, 0);
1043 case TYPE_CODE_METHOD
:
1045 fprintf_filtered (stream
, ")");
1046 type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0, 0);
1050 struct type
**args
= TYPE_ARG_TYPES (type
);
1052 fprintf_filtered (stream
, "(");
1054 fprintf_filtered (stream
, "...");
1055 else for (i
= 1; args
[i
] != 0 && args
[i
]->code
!= TYPE_CODE_VOID
; i
++)
1057 type_print_1 (args
[i
], "", stream
, -1, 0);
1059 fprintf_filtered (stream
, "...");
1060 else if (args
[i
+1]->code
!= TYPE_CODE_VOID
)
1061 fprintf_filtered (stream
, ",");
1063 fprintf_filtered (stream
, ")");
1069 type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0, 1);
1072 case TYPE_CODE_FUNC
:
1073 type_print_varspec_suffix (TYPE_TARGET_TYPE (type
), stream
, 0,
1076 fprintf_filtered (stream
, ")");
1077 fprintf_filtered (stream
, "()");
1082 /* Print the name of the type (or the ultimate pointer target,
1083 function value or array element), or the description of a
1086 SHOW nonzero means don't print this type as just its name;
1087 show its real definition even if it has a name.
1088 SHOW zero means print just typename or struct tag if there is one
1089 SHOW negative means abbreviate structure elements.
1090 SHOW is decremented for printing of structure elements.
1092 LEVEL is the depth to indent by.
1093 We increase it for some recursive calls. */
1096 type_print_base (type
, stream
, show
, level
)
1105 register int lastval
;
1111 fprintf_filtered (stream
, "type unknown");
1115 if (TYPE_NAME (type
) && show
<= 0)
1117 fputs_filtered (TYPE_NAME (type
), stream
);
1121 switch (TYPE_CODE (type
))
1123 case TYPE_CODE_ARRAY
:
1125 case TYPE_CODE_MEMBER
:
1127 case TYPE_CODE_FUNC
:
1128 case TYPE_CODE_METHOD
:
1129 type_print_base (TYPE_TARGET_TYPE (type
), stream
, show
, level
);
1132 case TYPE_CODE_STRUCT
:
1133 fprintf_filtered (stream
, "struct ");
1136 case TYPE_CODE_UNION
:
1137 fprintf_filtered (stream
, "union ");
1139 if (TYPE_NAME (type
) && (name
= TYPE_NAME (type
)))
1141 while (*name
!= ' ') name
++;
1142 fputs_filtered (name
+ 1, stream
);
1143 fputs_filtered (" ", stream
);
1146 fprintf_filtered (stream
, "{...}");
1151 type_print_derivation_info (stream
, type
);
1153 fprintf_filtered (stream
, "{");
1154 len
= TYPE_NFIELDS (type
);
1156 fprintf_filtered (stream
, "\n");
1159 if (TYPE_FLAGS (type
) & TYPE_FLAG_STUB
)
1160 fprintf_filtered (stream
, "<incomplete type>\n");
1162 fprintf_filtered (stream
, "<no data fields>\n");
1165 /* If there is a base class for this type,
1166 do not print the field that it occupies. */
1167 for (i
= TYPE_N_BASECLASSES (type
); i
< len
; i
++)
1170 /* Don't print out virtual function table. */
1171 if (! strncmp (TYPE_FIELD_NAME (type
, i
),
1175 print_spaces_filtered (level
+ 4, stream
);
1176 if (TYPE_FIELD_STATIC (type
, i
))
1178 fprintf_filtered (stream
, "static ");
1180 type_print_1 (TYPE_FIELD_TYPE (type
, i
),
1181 TYPE_FIELD_NAME (type
, i
),
1182 stream
, show
- 1, level
+ 4);
1183 if (!TYPE_FIELD_STATIC (type
, i
)
1184 && TYPE_FIELD_PACKED (type
, i
))
1186 /* It is a bitfield. This code does not attempt
1187 to look at the bitpos and reconstruct filler,
1188 unnamed fields. This would lead to misleading
1189 results if the compiler does not put out fields
1190 for such things (I don't know what it does). */
1191 fprintf_filtered (stream
, " : %d",
1192 TYPE_FIELD_BITSIZE (type
, i
));
1194 fprintf_filtered (stream
, ";\n");
1197 /* C++: print out the methods */
1198 len
= TYPE_NFN_FIELDS (type
);
1199 if (len
) fprintf_filtered (stream
, "\n");
1200 for (i
= 0; i
< len
; i
++)
1202 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (type
, i
);
1203 int j
, len2
= TYPE_FN_FIELDLIST_LENGTH (type
, i
);
1205 for (j
= 0; j
< len2
; j
++)
1208 print_spaces_filtered (level
+ 4, stream
);
1209 if (TYPE_FN_FIELD_VIRTUAL_P (f
, j
))
1210 fprintf_filtered (stream
, "virtual ");
1211 else if (TYPE_FN_FIELD_STATIC_P (f
, j
))
1212 fprintf_filtered (stream
, "static ");
1213 type_print (TYPE_TARGET_TYPE (TYPE_FN_FIELD_TYPE (f
, j
)), "", stream
, 0);
1214 if (TYPE_FN_FIELD_PHYSNAME (f
, j
)[0] == '_'
1215 && TYPE_FN_FIELD_PHYSNAME (f
, j
)[1] == '$')
1216 type_print_method_args
1217 (TYPE_FN_FIELD_ARGS (f
, j
) + 1, "~",
1218 TYPE_FN_FIELDLIST_NAME (type
, i
), 0, stream
);
1220 type_print_method_args
1221 (TYPE_FN_FIELD_ARGS (f
, j
), "",
1222 TYPE_FN_FIELDLIST_NAME (type
, i
),
1223 TYPE_FN_FIELD_STATIC_P (f
, j
), stream
);
1225 fprintf_filtered (stream
, ";\n");
1227 if (len2
) fprintf_filtered (stream
, "\n");
1230 print_spaces_filtered (level
, stream
);
1231 fprintf_filtered (stream
, "}");
1235 case TYPE_CODE_ENUM
:
1236 fprintf_filtered (stream
, "enum ");
1237 if (TYPE_NAME (type
))
1239 name
= TYPE_NAME (type
);
1240 while (*name
!= ' ') name
++;
1241 fputs_filtered (name
+ 1, stream
);
1242 fputs_filtered (" ", stream
);
1245 fprintf_filtered (stream
, "{...}");
1248 fprintf_filtered (stream
, "{");
1249 len
= TYPE_NFIELDS (type
);
1251 for (i
= 0; i
< len
; i
++)
1254 if (i
) fprintf_filtered (stream
, ", ");
1255 fputs_filtered (TYPE_FIELD_NAME (type
, i
), stream
);
1256 if (lastval
!= TYPE_FIELD_BITPOS (type
, i
))
1258 fprintf_filtered (stream
, " : %d", TYPE_FIELD_BITPOS (type
, i
));
1259 lastval
= TYPE_FIELD_BITPOS (type
, i
);
1263 fprintf_filtered (stream
, "}");
1268 if (TYPE_UNSIGNED (type
))
1269 name
= unsigned_type_table
[TYPE_LENGTH (type
)];
1271 name
= signed_type_table
[TYPE_LENGTH (type
)];
1272 fputs_filtered (name
, stream
);
1276 name
= float_type_table
[TYPE_LENGTH (type
)];
1277 fputs_filtered (name
, stream
);
1280 case TYPE_CODE_VOID
:
1281 fprintf_filtered (stream
, "void");
1285 fprintf_filtered (stream
, "struct unknown");
1289 error ("Invalid type code in symbol table.");
1294 set_maximum_command (arg
)
1297 if (!arg
) error_no_arg ("value for maximum elements to print");
1298 print_max
= parse_and_eval_address (arg
);
1300 print_max
= UINT_MAX
;
1304 set_prettyprint_command (arg
, from_tty
)
1308 prettyprint
= parse_binary_operation ("set prettyprint", arg
);
1312 set_unionprint_command (arg
, from_tty
)
1316 unionprint
= parse_binary_operation ("set unionprint", arg
);
1319 format_info (arg
, from_tty
)
1324 error ("\"info format\" does not take any arguments.");
1325 printf ("Prettyprinting of structures is %s.\n",
1326 prettyprint
? "on" : "off");
1327 printf ("Printing of unions interior to structures is %s.\n",
1328 unionprint
? "on" : "off");
1329 if (print_max
== UINT_MAX
)
1331 ("There is no maximum number of array elements printed.\n");
1334 ("The maximum number of array elements printed is %d.\n", print_max
);
1337 extern struct cmd_list_element
*setlist
;
1340 _initialize_valprint ()
1342 add_cmd ("array-max", class_vars
, set_maximum_command
,
1343 "Set NUMBER as limit on string chars or array elements to print.\n\
1344 \"set array-max 0\" causes there to be no limit.",
1347 add_cmd ("prettyprint", class_support
, set_prettyprint_command
,
1348 "Turn prettyprinting of structures on and off.",
1350 add_alias_cmd ("pp", "prettyprint", class_support
, 1, &setlist
);
1352 add_cmd ("unionprint", class_support
, set_unionprint_command
,
1353 "Turn printing of unions interior to structures on and off.",
1356 add_info ("format", format_info
,
1357 "Show current settings of data formatting options.");
1359 /* Give people the defaults which they are used to. */
1366 = (char **) xmalloc ((1 + sizeof (unsigned LONGEST
)) * sizeof (char *));
1367 bzero (unsigned_type_table
, (1 + sizeof (unsigned LONGEST
)));
1368 unsigned_type_table
[sizeof (unsigned char)] = "unsigned char";
1369 unsigned_type_table
[sizeof (unsigned short)] = "unsigned short";
1370 unsigned_type_table
[sizeof (unsigned long)] = "unsigned long";
1371 unsigned_type_table
[sizeof (unsigned int)] = "unsigned int";
1373 unsigned_type_table
[sizeof (unsigned long long)] = "unsigned long long";
1377 = (char **) xmalloc ((1 + sizeof (LONGEST
)) * sizeof (char *));
1378 bzero (signed_type_table
, (1 + sizeof (LONGEST
)));
1379 signed_type_table
[sizeof (char)] = "char";
1380 signed_type_table
[sizeof (short)] = "short";
1381 signed_type_table
[sizeof (long)] = "long";
1382 signed_type_table
[sizeof (int)] = "int";
1384 signed_type_table
[sizeof (long long)] = "long long";
1388 = (char **) xmalloc ((1 + sizeof (double)) * sizeof (char *));
1389 bzero (float_type_table
, (1 + sizeof (double)));
1390 float_type_table
[sizeof (float)] = "float";
1391 float_type_table
[sizeof (double)] = "double";
This page took 0.079273 seconds and 4 git commands to generate.