1 /* prdbg.c -- Print out generic debugging information.
2 Copyright 1995, 1996 Free Software Foundation, Inc.
3 Written by Ian Lance Taylor <ian@cygnus.com>.
5 This file is part of GNU Binutils.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22 /* This file prints out the generic debugging information, by
23 supplying a set of routines to debug_write. */
30 #include "libiberty.h"
34 /* This is the structure we use as a handle for these routines. */
38 /* File to print information to. */
40 /* Current indentation level. */
43 struct pr_stack
*stack
;
44 /* Parameter number we are about to output. */
52 /* Next element on the stack. */
53 struct pr_stack
*next
;
56 /* Current visibility of fields if this is a class. */
57 enum debug_visibility visibility
;
58 /* Name of the current method we are handling. */
62 static void indent
PARAMS ((struct pr_handle
*));
63 static boolean push_type
PARAMS ((struct pr_handle
*, const char *));
64 static boolean prepend_type
PARAMS ((struct pr_handle
*, const char *));
65 static boolean append_type
PARAMS ((struct pr_handle
*, const char *));
66 static boolean substitute_type
PARAMS ((struct pr_handle
*, const char *));
67 static boolean indent_type
PARAMS ((struct pr_handle
*));
68 static char *pop_type
PARAMS ((struct pr_handle
*));
69 static void print_vma
PARAMS ((bfd_vma
, char *, boolean
, boolean
));
70 static boolean pr_fix_visibility
71 PARAMS ((struct pr_handle
*, enum debug_visibility
));
73 static boolean pr_start_compilation_unit
PARAMS ((PTR
, const char *));
74 static boolean pr_start_source
PARAMS ((PTR
, const char *));
75 static boolean pr_empty_type
PARAMS ((PTR
));
76 static boolean pr_void_type
PARAMS ((PTR
));
77 static boolean pr_int_type
PARAMS ((PTR
, unsigned int, boolean
));
78 static boolean pr_float_type
PARAMS ((PTR
, unsigned int));
79 static boolean pr_complex_type
PARAMS ((PTR
, unsigned int));
80 static boolean pr_bool_type
PARAMS ((PTR
, unsigned int));
81 static boolean pr_enum_type
82 PARAMS ((PTR
, const char *, const char **, bfd_signed_vma
*));
83 static boolean pr_pointer_type
PARAMS ((PTR
));
84 static boolean pr_function_type
PARAMS ((PTR
, int, boolean
));
85 static boolean pr_reference_type
PARAMS ((PTR
));
86 static boolean pr_range_type
PARAMS ((PTR
, bfd_signed_vma
, bfd_signed_vma
));
87 static boolean pr_array_type
88 PARAMS ((PTR
, bfd_signed_vma
, bfd_signed_vma
, boolean
));
89 static boolean pr_set_type
PARAMS ((PTR
, boolean
));
90 static boolean pr_offset_type
PARAMS ((PTR
));
91 static boolean pr_method_type
PARAMS ((PTR
, boolean
, int, boolean
));
92 static boolean pr_const_type
PARAMS ((PTR
));
93 static boolean pr_volatile_type
PARAMS ((PTR
));
94 static boolean pr_start_struct_type
95 PARAMS ((PTR
, const char *, unsigned int, boolean
, unsigned int));
96 static boolean pr_struct_field
97 PARAMS ((PTR
, const char *, bfd_vma
, bfd_vma
, enum debug_visibility
));
98 static boolean pr_end_struct_type
PARAMS ((PTR
));
99 static boolean pr_start_class_type
100 PARAMS ((PTR
, const char *, unsigned int, boolean
, unsigned int, boolean
,
102 static boolean pr_class_static_member
103 PARAMS ((PTR
, const char *, const char *, enum debug_visibility
));
104 static boolean pr_class_baseclass
105 PARAMS ((PTR
, bfd_vma
, boolean
, enum debug_visibility
));
106 static boolean pr_class_start_method
PARAMS ((PTR
, const char *));
107 static boolean pr_class_method_variant
108 PARAMS ((PTR
, const char *, enum debug_visibility
, boolean
, boolean
,
110 static boolean pr_class_static_method_variant
111 PARAMS ((PTR
, const char *, enum debug_visibility
, boolean
, boolean
));
112 static boolean pr_class_end_method
PARAMS ((PTR
));
113 static boolean pr_end_class_type
PARAMS ((PTR
));
114 static boolean pr_typedef_type
PARAMS ((PTR
, const char *));
115 static boolean pr_tag_type
116 PARAMS ((PTR
, const char *, unsigned int, enum debug_type_kind
));
117 static boolean pr_typdef
PARAMS ((PTR
, const char *));
118 static boolean pr_tag
PARAMS ((PTR
, const char *));
119 static boolean pr_int_constant
PARAMS ((PTR
, const char *, bfd_vma
));
120 static boolean pr_float_constant
PARAMS ((PTR
, const char *, double));
121 static boolean pr_typed_constant
PARAMS ((PTR
, const char *, bfd_vma
));
122 static boolean pr_variable
123 PARAMS ((PTR
, const char *, enum debug_var_kind
, bfd_vma
));
124 static boolean pr_start_function
PARAMS ((PTR
, const char *, boolean
));
125 static boolean pr_function_parameter
126 PARAMS ((PTR
, const char *, enum debug_parm_kind
, bfd_vma
));
127 static boolean pr_start_block
PARAMS ((PTR
, bfd_vma
));
128 static boolean pr_end_block
PARAMS ((PTR
, bfd_vma
));
129 static boolean pr_end_function
PARAMS ((PTR
));
130 static boolean pr_lineno
PARAMS ((PTR
, const char *, unsigned long, bfd_vma
));
132 static const struct debug_write_fns pr_fns
=
134 pr_start_compilation_unit
,
153 pr_start_struct_type
,
157 pr_class_static_member
,
159 pr_class_start_method
,
160 pr_class_method_variant
,
161 pr_class_static_method_variant
,
173 pr_function_parameter
,
180 /* Print out the generic debugging information recorded in dhandle. */
183 print_debugging_info (f
, dhandle
)
187 struct pr_handle info
;
194 return debug_write (dhandle
, &pr_fns
, (PTR
) &info
);
197 /* Indent to the current indentation level. */
201 struct pr_handle
*info
;
205 for (i
= 0; i
< info
->indent
; i
++)
209 /* Push a type on the type stack. */
212 push_type (info
, type
)
213 struct pr_handle
*info
;
221 n
= (struct pr_stack
*) xmalloc (sizeof *n
);
222 memset (n
, 0, sizeof *n
);
224 n
->type
= xstrdup (type
);
225 n
->visibility
= DEBUG_VISIBILITY_IGNORE
;
227 n
->next
= info
->stack
;
233 /* Prepend a string onto the type on the top of the type stack. */
236 prepend_type (info
, s
)
237 struct pr_handle
*info
;
242 assert (info
->stack
!= NULL
);
244 n
= (char *) xmalloc (strlen (s
) + strlen (info
->stack
->type
) + 1);
245 sprintf (n
, "%s%s", s
, info
->stack
->type
);
246 free (info
->stack
->type
);
247 info
->stack
->type
= n
;
252 /* Append a string to the type on the top of the type stack. */
255 append_type (info
, s
)
256 struct pr_handle
*info
;
264 assert (info
->stack
!= NULL
);
266 len
= strlen (info
->stack
->type
);
267 info
->stack
->type
= (char *) xrealloc (info
->stack
->type
,
268 len
+ strlen (s
) + 1);
269 strcpy (info
->stack
->type
+ len
, s
);
274 /* We use an underscore to indicate where the name should go in a type
275 string. This function substitutes a string for the underscore. If
276 there is no underscore, the name follows the type. */
279 substitute_type (info
, s
)
280 struct pr_handle
*info
;
285 assert (info
->stack
!= NULL
);
287 u
= strchr (info
->stack
->type
, '|');
292 n
= (char *) xmalloc (strlen (info
->stack
->type
) + strlen (s
));
294 memcpy (n
, info
->stack
->type
, u
- info
->stack
->type
);
295 strcpy (n
+ (u
- info
->stack
->type
), s
);
298 free (info
->stack
->type
);
299 info
->stack
->type
= n
;
304 if (strchr (s
, '|') != NULL
305 && (strchr (info
->stack
->type
, '{') != NULL
306 || strchr (info
->stack
->type
, '(') != NULL
))
308 if (! prepend_type (info
, "(")
309 || ! append_type (info
, ")"))
316 return (append_type (info
, " ")
317 && append_type (info
, s
));
320 /* Indent the type at the top of the stack by appending spaces. */
324 struct pr_handle
*info
;
328 for (i
= 0; i
< info
->indent
; i
++)
330 if (! append_type (info
, " "))
337 /* Pop a type from the type stack. */
341 struct pr_handle
*info
;
346 assert (info
->stack
!= NULL
);
349 info
->stack
= o
->next
;
356 /* Print a VMA value into a string. */
359 print_vma (vma
, buf
, unsignedp
, hexp
)
365 if (sizeof (vma
) <= sizeof (unsigned long))
368 sprintf (buf
, "0x%lx", (unsigned long) vma
);
370 sprintf (buf
, "%lu", (unsigned long) vma
);
372 sprintf (buf
, "%ld", (long) vma
);
378 sprintf_vma (buf
+ 2, vma
);
382 /* Start a new compilation unit. */
385 pr_start_compilation_unit (p
, filename
)
387 const char *filename
;
389 struct pr_handle
*info
= (struct pr_handle
*) p
;
391 assert (info
->indent
== 0);
393 fprintf (info
->f
, "%s:\n", filename
);
398 /* Start a source file within a compilation unit. */
401 pr_start_source (p
, filename
)
403 const char *filename
;
405 struct pr_handle
*info
= (struct pr_handle
*) p
;
407 assert (info
->indent
== 0);
409 fprintf (info
->f
, " %s:\n", filename
);
414 /* Push an empty type onto the type stack. */
420 struct pr_handle
*info
= (struct pr_handle
*) p
;
422 return push_type (info
, "<undefined>");
425 /* Push a void type onto the type stack. */
431 struct pr_handle
*info
= (struct pr_handle
*) p
;
433 return push_type (info
, "void");
436 /* Push an integer type onto the type stack. */
439 pr_int_type (p
, size
, unsignedp
)
444 struct pr_handle
*info
= (struct pr_handle
*) p
;
447 sprintf (ab
, "%sint%d", unsignedp
? "u" : "", size
* 8);
448 return push_type (info
, ab
);
451 /* Push a floating type onto the type stack. */
454 pr_float_type (p
, size
)
458 struct pr_handle
*info
= (struct pr_handle
*) p
;
462 return push_type (info
, "float");
464 return push_type (info
, "double");
466 sprintf (ab
, "float%d", size
* 8);
467 return push_type (info
, ab
);
470 /* Push a complex type onto the type stack. */
473 pr_complex_type (p
, size
)
477 struct pr_handle
*info
= (struct pr_handle
*) p
;
479 if (! pr_float_type (p
, size
))
482 return prepend_type (info
, "complex ");
485 /* Push a boolean type onto the type stack. */
488 pr_bool_type (p
, size
)
492 struct pr_handle
*info
= (struct pr_handle
*) p
;
495 sprintf (ab
, "bool%d", size
* 8);
497 return push_type (info
, ab
);
500 /* Push an enum type onto the type stack. */
503 pr_enum_type (p
, tag
, names
, values
)
507 bfd_signed_vma
*values
;
509 struct pr_handle
*info
= (struct pr_handle
*) p
;
513 if (! push_type (info
, "enum "))
517 if (! append_type (info
, tag
)
518 || ! append_type (info
, " "))
521 if (! append_type (info
, "{ "))
526 if (! append_type (info
, "/* undefined */"))
532 for (i
= 0; names
[i
] != NULL
; i
++)
536 if (! append_type (info
, ", "))
540 if (! append_type (info
, names
[i
]))
543 if (values
[i
] != val
)
547 print_vma (values
[i
], ab
, false, false);
548 if (! append_type (info
, " = ")
549 || ! append_type (info
, ab
))
558 return append_type (info
, " }");
561 /* Turn the top type on the stack into a pointer. */
567 struct pr_handle
*info
= (struct pr_handle
*) p
;
570 assert (info
->stack
!= NULL
);
572 s
= strchr (info
->stack
->type
, '|');
573 if (s
!= NULL
&& s
[1] == '[')
574 return substitute_type (info
, "(*|)");
575 return substitute_type (info
, "*|");
578 /* Turn the top type on the stack into a function returning that type. */
581 pr_function_type (p
, argcount
, varargs
)
586 struct pr_handle
*info
= (struct pr_handle
*) p
;
591 assert (info
->stack
!= NULL
);
604 arg_types
= (char **) xmalloc (argcount
* sizeof *arg_types
);
605 for (i
= argcount
- 1; i
>= 0; i
--)
607 if (! substitute_type (info
, ""))
609 arg_types
[i
] = pop_type (info
);
610 if (arg_types
[i
] == NULL
)
612 len
+= strlen (arg_types
[i
]) + 2;
618 /* Now the return type is on the top of the stack. */
620 s
= (char *) xmalloc (len
);
624 strcat (s
, "/* unknown */");
629 for (i
= 0; i
< argcount
; i
++)
633 strcat (s
, arg_types
[i
]);
647 if (! substitute_type (info
, s
))
655 /* Turn the top type on the stack into a reference to that type. */
658 pr_reference_type (p
)
661 struct pr_handle
*info
= (struct pr_handle
*) p
;
663 assert (info
->stack
!= NULL
);
665 return substitute_type (info
, "&|");
668 /* Make a range type. */
671 pr_range_type (p
, lower
, upper
)
673 bfd_signed_vma lower
;
674 bfd_signed_vma upper
;
676 struct pr_handle
*info
= (struct pr_handle
*) p
;
677 char abl
[20], abu
[20];
679 assert (info
->stack
!= NULL
);
681 if (! substitute_type (info
, ""))
684 print_vma (lower
, abl
, false, false);
685 print_vma (upper
, abu
, false, false);
687 return (prepend_type (info
, "range (")
688 && append_type (info
, "):")
689 && append_type (info
, abl
)
690 && append_type (info
, ":")
691 && append_type (info
, abu
));
694 /* Make an array type. */
697 pr_array_type (p
, lower
, upper
, stringp
)
699 bfd_signed_vma lower
;
700 bfd_signed_vma upper
;
703 struct pr_handle
*info
= (struct pr_handle
*) p
;
705 char abl
[20], abu
[20], ab
[50];
707 range_type
= pop_type (info
);
708 if (range_type
== NULL
)
717 print_vma (upper
+ 1, abu
, false, false);
718 sprintf (ab
, "|[%s]", abu
);
723 print_vma (lower
, abl
, false, false);
724 print_vma (upper
, abu
, false, false);
725 sprintf (ab
, "|[%s:%s]", abl
, abu
);
728 if (! substitute_type (info
, ab
))
731 if (strcmp (range_type
, "int") != 0)
733 if (! append_type (info
, ":")
734 || ! append_type (info
, range_type
))
740 if (! append_type (info
, " /* string */"))
747 /* Make a set type. */
750 pr_set_type (p
, bitstringp
)
754 struct pr_handle
*info
= (struct pr_handle
*) p
;
756 if (! substitute_type (info
, ""))
759 if (! prepend_type (info
, "set { ")
760 || ! append_type (info
, " }"))
765 if (! append_type (info
, "/* bitstring */"))
772 /* Make an offset type. */
778 struct pr_handle
*info
= (struct pr_handle
*) p
;
781 if (! substitute_type (info
, ""))
788 return (substitute_type (info
, "")
789 && prepend_type (info
, " ")
790 && prepend_type (info
, t
)
791 && append_type (info
, "::|"));
794 /* Make a method type. */
797 pr_method_type (p
, domain
, argcount
, varargs
)
803 struct pr_handle
*info
= (struct pr_handle
*) p
;
815 if (! substitute_type (info
, ""))
817 domain_type
= pop_type (info
);
818 if (domain_type
== NULL
)
820 if (strncmp (domain_type
, "class ", sizeof "class " - 1) == 0
821 && strchr (domain_type
+ sizeof "class " - 1, ' ') == NULL
)
822 domain_type
+= sizeof "class " - 1;
823 else if (strncmp (domain_type
, "union class ",
824 sizeof "union class ") == 0
825 && (strchr (domain_type
+ sizeof "union class " - 1, ' ')
827 domain_type
+= sizeof "union class " - 1;
828 len
+= strlen (domain_type
);
840 arg_types
= (char **) xmalloc (argcount
* sizeof *arg_types
);
841 for (i
= argcount
- 1; i
>= 0; i
--)
843 if (! substitute_type (info
, ""))
845 arg_types
[i
] = pop_type (info
);
846 if (arg_types
[i
] == NULL
)
848 len
+= strlen (arg_types
[i
]) + 2;
854 /* Now the return type is on the top of the stack. */
856 s
= (char *) xmalloc (len
);
860 strcpy (s
, domain_type
);
864 strcat (s
, "/* unknown */");
869 for (i
= 0; i
< argcount
; i
++)
873 strcat (s
, arg_types
[i
]);
887 if (! substitute_type (info
, s
))
895 /* Make a const qualified type. */
901 struct pr_handle
*info
= (struct pr_handle
*) p
;
903 return substitute_type (info
, "const |");
906 /* Make a volatile qualified type. */
912 struct pr_handle
*info
= (struct pr_handle
*) p
;
914 return substitute_type (info
, "volatile |");
917 /* Start accumulating a struct type. */
920 pr_start_struct_type (p
, tag
, id
, structp
, size
)
927 struct pr_handle
*info
= (struct pr_handle
*) p
;
931 if (! push_type (info
, structp
? "struct " : "union "))
935 if (! append_type (info
, tag
))
942 sprintf (idbuf
, "%%anon%u", id
);
943 if (! append_type (info
, idbuf
))
947 if (! append_type (info
, " {"))
949 if (size
!= 0 || tag
!= NULL
)
953 if (! append_type (info
, " /*"))
958 sprintf (ab
, " size %u", size
);
959 if (! append_type (info
, ab
))
964 sprintf (ab
, " id %u", id
);
965 if (! append_type (info
, ab
))
968 if (! append_type (info
, " */"))
971 if (! append_type (info
, "\n"))
974 info
->stack
->visibility
= DEBUG_VISIBILITY_PUBLIC
;
976 return indent_type (info
);
979 /* Output the visibility of a field in a struct. */
982 pr_fix_visibility (info
, visibility
)
983 struct pr_handle
*info
;
984 enum debug_visibility visibility
;
986 const char *s
= NULL
;
990 assert (info
->stack
!= NULL
);
992 if (info
->stack
->visibility
== visibility
)
995 assert (info
->stack
->visibility
!= DEBUG_VISIBILITY_IGNORE
);
999 case DEBUG_VISIBILITY_PUBLIC
:
1002 case DEBUG_VISIBILITY_PRIVATE
:
1005 case DEBUG_VISIBILITY_PROTECTED
:
1008 case DEBUG_VISIBILITY_IGNORE
:
1016 /* Trim off a trailing space in the struct string, to make the
1017 output look a bit better, then stick on the visibility string. */
1019 t
= info
->stack
->type
;
1021 assert (t
[len
- 1] == ' ');
1024 if (! append_type (info
, s
)
1025 || ! append_type (info
, ":\n")
1026 || ! indent_type (info
))
1029 info
->stack
->visibility
= visibility
;
1034 /* Add a field to a struct type. */
1037 pr_struct_field (p
, name
, bitpos
, bitsize
, visibility
)
1042 enum debug_visibility visibility
;
1044 struct pr_handle
*info
= (struct pr_handle
*) p
;
1048 if (! substitute_type (info
, name
))
1051 if (! append_type (info
, "; /* "))
1056 print_vma (bitsize
, ab
, true, false);
1057 if (! append_type (info
, "bitsize ")
1058 || ! append_type (info
, ab
)
1059 || ! append_type (info
, ", "))
1063 print_vma (bitpos
, ab
, true, false);
1064 if (! append_type (info
, "bitpos ")
1065 || ! append_type (info
, ab
)
1066 || ! append_type (info
, " */\n")
1067 || ! indent_type (info
))
1070 t
= pop_type (info
);
1074 if (! pr_fix_visibility (info
, visibility
))
1077 return append_type (info
, t
);
1080 /* Finish a struct type. */
1083 pr_end_struct_type (p
)
1086 struct pr_handle
*info
= (struct pr_handle
*) p
;
1089 assert (info
->stack
!= NULL
);
1090 assert (info
->indent
>= 2);
1094 /* Change the trailing indentation to have a close brace. */
1095 s
= info
->stack
->type
+ strlen (info
->stack
->type
) - 2;
1096 assert (s
[0] == ' ' && s
[1] == ' ' && s
[2] == '\0');
1104 /* Start a class type. */
1107 pr_start_class_type (p
, tag
, id
, structp
, size
, vptr
, ownvptr
)
1116 struct pr_handle
*info
= (struct pr_handle
*) p
;
1121 if (vptr
&& ! ownvptr
)
1123 tv
= pop_type (info
);
1128 if (! push_type (info
, structp
? "class " : "union class "))
1132 if (! append_type (info
, tag
))
1139 sprintf (idbuf
, "%%anon%u", id
);
1140 if (! append_type (info
, idbuf
))
1144 if (! append_type (info
, " {"))
1146 if (size
!= 0 || vptr
|| ownvptr
|| tag
!= NULL
)
1148 if (! append_type (info
, " /*"))
1155 sprintf (ab
, "%u", size
);
1156 if (! append_type (info
, " size ")
1157 || ! append_type (info
, ab
))
1163 if (! append_type (info
, " vtable "))
1167 if (! append_type (info
, "self "))
1172 if (! append_type (info
, tv
)
1173 || ! append_type (info
, " "))
1182 sprintf (ab
, " id %u", id
);
1183 if (! append_type (info
, ab
))
1187 if (! append_type (info
, " */"))
1191 info
->stack
->visibility
= DEBUG_VISIBILITY_PRIVATE
;
1193 return (append_type (info
, "\n")
1194 && indent_type (info
));
1197 /* Add a static member to a class. */
1200 pr_class_static_member (p
, name
, physname
, visibility
)
1203 const char *physname
;
1204 enum debug_visibility visibility
;
1206 struct pr_handle
*info
= (struct pr_handle
*) p
;
1209 if (! substitute_type (info
, name
))
1212 if (! prepend_type (info
, "static ")
1213 || ! append_type (info
, "; /* ")
1214 || ! append_type (info
, physname
)
1215 || ! append_type (info
, " */\n")
1216 || ! indent_type (info
))
1219 t
= pop_type (info
);
1223 if (! pr_fix_visibility (info
, visibility
))
1226 return append_type (info
, t
);
1229 /* Add a base class to a class. */
1232 pr_class_baseclass (p
, bitpos
, virtual, visibility
)
1236 enum debug_visibility visibility
;
1238 struct pr_handle
*info
= (struct pr_handle
*) p
;
1244 assert (info
->stack
!= NULL
&& info
->stack
->next
!= NULL
);
1246 if (! substitute_type (info
, ""))
1249 t
= pop_type (info
);
1253 if (strncmp (t
, "class ", sizeof "class " - 1) == 0)
1254 t
+= sizeof "class " - 1;
1256 /* Push it back on to take advantage of the prepend_type and
1257 append_type routines. */
1258 if (! push_type (info
, t
))
1263 if (! prepend_type (info
, "virtual "))
1269 case DEBUG_VISIBILITY_PUBLIC
:
1272 case DEBUG_VISIBILITY_PROTECTED
:
1273 prefix
= "protected ";
1275 case DEBUG_VISIBILITY_PRIVATE
:
1276 prefix
= "private ";
1279 prefix
= "/* unknown visibility */ ";
1283 if (! prepend_type (info
, prefix
))
1288 print_vma (bitpos
, ab
, true, false);
1289 if (! append_type (info
, " /* bitpos ")
1290 || ! append_type (info
, ab
)
1291 || ! append_type (info
, " */"))
1295 /* Now the top of the stack is something like "public A / * bitpos
1296 10 * /". The next element on the stack is something like "class
1297 xx { / * size 8 * /\n...". We want to substitute the top of the
1298 stack in before the {. */
1299 s
= strchr (info
->stack
->next
->type
, '{');
1303 /* If there is already a ':', then we already have a baseclass, and
1304 we must append this one after a comma. */
1305 for (l
= info
->stack
->next
->type
; l
!= s
; l
++)
1308 if (! prepend_type (info
, l
== s
? " : " : ", "))
1311 t
= pop_type (info
);
1315 n
= (char *) xmalloc (strlen (info
->stack
->type
) + strlen (t
) + 1);
1316 memcpy (n
, info
->stack
->type
, s
- info
->stack
->type
);
1317 strcpy (n
+ (s
- info
->stack
->type
), t
);
1320 free (info
->stack
->type
);
1321 info
->stack
->type
= n
;
1328 /* Start adding a method to a class. */
1331 pr_class_start_method (p
, name
)
1335 struct pr_handle
*info
= (struct pr_handle
*) p
;
1337 assert (info
->stack
!= NULL
);
1338 info
->stack
->method
= name
;
1342 /* Add a variant to a method. */
1345 pr_class_method_variant (p
, physname
, visibility
, constp
, volatilep
, voffset
,
1348 const char *physname
;
1349 enum debug_visibility visibility
;
1355 struct pr_handle
*info
= (struct pr_handle
*) p
;
1359 assert (info
->stack
!= NULL
);
1360 assert (info
->stack
->next
!= NULL
);
1362 /* Put the const and volatile qualifiers on the type. */
1365 if (! append_type (info
, " volatile"))
1370 if (! append_type (info
, " const"))
1374 /* Stick the name of the method into its type. */
1375 if (! substitute_type (info
,
1377 ? info
->stack
->next
->next
->method
1378 : info
->stack
->next
->method
)))
1382 method_type
= pop_type (info
);
1383 if (method_type
== NULL
)
1386 /* Pull off the context type if there is one. */
1388 context_type
= NULL
;
1391 context_type
= pop_type (info
);
1392 if (context_type
== NULL
)
1396 /* Now the top of the stack is the class. */
1398 if (! pr_fix_visibility (info
, visibility
))
1401 if (! append_type (info
, method_type
)
1402 || ! append_type (info
, " /* ")
1403 || ! append_type (info
, physname
)
1404 || ! append_type (info
, " "))
1406 if (context
|| voffset
!= 0)
1412 if (! append_type (info
, "context ")
1413 || ! append_type (info
, context_type
)
1414 || ! append_type (info
, " "))
1417 print_vma (voffset
, ab
, true, false);
1418 if (! append_type (info
, "voffset ")
1419 || ! append_type (info
, ab
))
1423 return (append_type (info
, " */;\n")
1424 && indent_type (info
));
1427 /* Add a static variant to a method. */
1430 pr_class_static_method_variant (p
, physname
, visibility
, constp
, volatilep
)
1432 const char *physname
;
1433 enum debug_visibility visibility
;
1437 struct pr_handle
*info
= (struct pr_handle
*) p
;
1440 assert (info
->stack
!= NULL
);
1441 assert (info
->stack
->next
!= NULL
);
1442 assert (info
->stack
->next
->method
!= NULL
);
1444 /* Put the const and volatile qualifiers on the type. */
1447 if (! append_type (info
, " volatile"))
1452 if (! append_type (info
, " const"))
1456 /* Mark it as static. */
1457 if (! prepend_type (info
, "static "))
1460 /* Stick the name of the method into its type. */
1461 if (! substitute_type (info
, info
->stack
->next
->method
))
1465 method_type
= pop_type (info
);
1466 if (method_type
== NULL
)
1469 /* Now the top of the stack is the class. */
1471 if (! pr_fix_visibility (info
, visibility
))
1474 return (append_type (info
, method_type
)
1475 && append_type (info
, " /* ")
1476 && append_type (info
, physname
)
1477 && append_type (info
, " */;\n")
1478 && indent_type (info
));
1481 /* Finish up a method. */
1484 pr_class_end_method (p
)
1487 struct pr_handle
*info
= (struct pr_handle
*) p
;
1489 info
->stack
->method
= NULL
;
1493 /* Finish up a class. */
1496 pr_end_class_type (p
)
1499 return pr_end_struct_type (p
);
1502 /* Push a type on the stack using a typedef name. */
1505 pr_typedef_type (p
, name
)
1509 struct pr_handle
*info
= (struct pr_handle
*) p
;
1511 return push_type (info
, name
);
1514 /* Push a type on the stack using a tag name. */
1517 pr_tag_type (p
, name
, id
, kind
)
1521 enum debug_type_kind kind
;
1523 struct pr_handle
*info
= (struct pr_handle
*) p
;
1524 const char *t
, *tag
;
1529 case DEBUG_KIND_STRUCT
:
1532 case DEBUG_KIND_UNION
:
1535 case DEBUG_KIND_ENUM
:
1538 case DEBUG_KIND_CLASS
:
1541 case DEBUG_KIND_UNION_CLASS
:
1549 if (! push_type (info
, t
))
1555 sprintf (idbuf
, "%%anon%u", id
);
1559 if (! append_type (info
, tag
))
1561 if (name
!= NULL
&& kind
!= DEBUG_KIND_ENUM
)
1563 sprintf (idbuf
, " /* id %u */", id
);
1564 if (! append_type (info
, idbuf
))
1571 /* Output a typedef. */
1578 struct pr_handle
*info
= (struct pr_handle
*) p
;
1581 if (! substitute_type (info
, name
))
1584 s
= pop_type (info
);
1589 fprintf (info
->f
, "typedef %s;\n", s
);
1596 /* Output a tag. The tag should already be in the string on the
1597 stack, so all we have to do here is print it out. */
1602 const char *name ATTRIBUTE_UNUSED
;
1604 struct pr_handle
*info
= (struct pr_handle
*) p
;
1607 t
= pop_type (info
);
1612 fprintf (info
->f
, "%s;\n", t
);
1619 /* Output an integer constant. */
1622 pr_int_constant (p
, name
, val
)
1627 struct pr_handle
*info
= (struct pr_handle
*) p
;
1631 print_vma (val
, ab
, false, false);
1632 fprintf (info
->f
, "const int %s = %s;\n", name
, ab
);
1636 /* Output a floating point constant. */
1639 pr_float_constant (p
, name
, val
)
1644 struct pr_handle
*info
= (struct pr_handle
*) p
;
1647 fprintf (info
->f
, "const double %s = %g;\n", name
, val
);
1651 /* Output a typed constant. */
1654 pr_typed_constant (p
, name
, val
)
1659 struct pr_handle
*info
= (struct pr_handle
*) p
;
1663 t
= pop_type (info
);
1668 print_vma (val
, ab
, false, false);
1669 fprintf (info
->f
, "const %s %s = %s;\n", t
, name
, ab
);
1676 /* Output a variable. */
1679 pr_variable (p
, name
, kind
, val
)
1682 enum debug_var_kind kind
;
1685 struct pr_handle
*info
= (struct pr_handle
*) p
;
1689 if (! substitute_type (info
, name
))
1692 t
= pop_type (info
);
1700 case DEBUG_LOCAL_STATIC
:
1701 fprintf (info
->f
, "static ");
1703 case DEBUG_REGISTER
:
1704 fprintf (info
->f
, "register ");
1709 print_vma (val
, ab
, true, true);
1710 fprintf (info
->f
, "%s /* %s */;\n", t
, ab
);
1717 /* Start outputting a function. */
1720 pr_start_function (p
, name
, global
)
1725 struct pr_handle
*info
= (struct pr_handle
*) p
;
1728 if (! substitute_type (info
, name
))
1731 t
= pop_type (info
);
1737 fprintf (info
->f
, "static ");
1738 fprintf (info
->f
, "%s (", t
);
1740 info
->parameter
= 1;
1745 /* Output a function parameter. */
1748 pr_function_parameter (p
, name
, kind
, val
)
1751 enum debug_parm_kind kind
;
1754 struct pr_handle
*info
= (struct pr_handle
*) p
;
1758 if (kind
== DEBUG_PARM_REFERENCE
1759 || kind
== DEBUG_PARM_REF_REG
)
1761 if (! pr_reference_type (p
))
1765 if (! substitute_type (info
, name
))
1768 t
= pop_type (info
);
1772 if (info
->parameter
!= 1)
1773 fprintf (info
->f
, ", ");
1775 if (kind
== DEBUG_PARM_REG
|| kind
== DEBUG_PARM_REF_REG
)
1776 fprintf (info
->f
, "register ");
1778 print_vma (val
, ab
, true, true);
1779 fprintf (info
->f
, "%s /* %s */", t
, ab
);
1788 /* Start writing out a block. */
1791 pr_start_block (p
, addr
)
1795 struct pr_handle
*info
= (struct pr_handle
*) p
;
1798 if (info
->parameter
> 0)
1800 fprintf (info
->f
, ")\n");
1801 info
->parameter
= 0;
1805 print_vma (addr
, ab
, true, true);
1806 fprintf (info
->f
, "{ /* %s */\n", ab
);
1813 /* Write out line number information. */
1816 pr_lineno (p
, filename
, lineno
, addr
)
1818 const char *filename
;
1819 unsigned long lineno
;
1822 struct pr_handle
*info
= (struct pr_handle
*) p
;
1826 print_vma (addr
, ab
, true, true);
1827 fprintf (info
->f
, "/* file %s line %lu addr %s */\n", filename
, lineno
, ab
);
1832 /* Finish writing out a block. */
1835 pr_end_block (p
, addr
)
1839 struct pr_handle
*info
= (struct pr_handle
*) p
;
1845 print_vma (addr
, ab
, true, true);
1846 fprintf (info
->f
, "} /* %s */\n", ab
);
1851 /* Finish writing out a function. */
1855 PTR p ATTRIBUTE_UNUSED
;