1 /* prdbg.c -- Print out generic debugging information.
2 Copyright 1995, 1996, 2002 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. */
63 PARAMS ((struct pr_handle
*));
64 static bfd_boolean push_type
65 PARAMS ((struct pr_handle
*, const char *));
66 static bfd_boolean prepend_type
67 PARAMS ((struct pr_handle
*, const char *));
68 static bfd_boolean append_type
69 PARAMS ((struct pr_handle
*, const char *));
70 static bfd_boolean substitute_type
71 PARAMS ((struct pr_handle
*, const char *));
72 static bfd_boolean indent_type
73 PARAMS ((struct pr_handle
*));
75 PARAMS ((struct pr_handle
*));
77 PARAMS ((bfd_vma
, char *, bfd_boolean
, bfd_boolean
));
78 static bfd_boolean pr_fix_visibility
79 PARAMS ((struct pr_handle
*, enum debug_visibility
));
80 static bfd_boolean pr_start_compilation_unit
81 PARAMS ((PTR
, const char *));
82 static bfd_boolean pr_start_source
83 PARAMS ((PTR
, const char *));
84 static bfd_boolean pr_empty_type
86 static bfd_boolean pr_void_type
88 static bfd_boolean pr_int_type
89 PARAMS ((PTR
, unsigned int, bfd_boolean
));
90 static bfd_boolean pr_float_type
91 PARAMS ((PTR
, unsigned int));
92 static bfd_boolean pr_complex_type
93 PARAMS ((PTR
, unsigned int));
94 static bfd_boolean pr_bool_type
95 PARAMS ((PTR
, unsigned int));
96 static bfd_boolean pr_enum_type
97 PARAMS ((PTR
, const char *, const char **, bfd_signed_vma
*));
98 static bfd_boolean pr_pointer_type
100 static bfd_boolean pr_function_type
101 PARAMS ((PTR
, int, bfd_boolean
));
102 static bfd_boolean pr_reference_type
104 static bfd_boolean pr_range_type
105 PARAMS ((PTR
, bfd_signed_vma
, bfd_signed_vma
));
106 static bfd_boolean pr_array_type
107 PARAMS ((PTR
, bfd_signed_vma
, bfd_signed_vma
, bfd_boolean
));
108 static bfd_boolean pr_set_type
109 PARAMS ((PTR
, bfd_boolean
));
110 static bfd_boolean pr_offset_type
112 static bfd_boolean pr_method_type
113 PARAMS ((PTR
, bfd_boolean
, int, bfd_boolean
));
114 static bfd_boolean pr_const_type
116 static bfd_boolean pr_volatile_type
118 static bfd_boolean pr_start_struct_type
119 PARAMS ((PTR
, const char *, unsigned int, bfd_boolean
, unsigned int));
120 static bfd_boolean pr_struct_field
121 PARAMS ((PTR
, const char *, bfd_vma
, bfd_vma
, enum debug_visibility
));
122 static bfd_boolean pr_end_struct_type
124 static bfd_boolean pr_start_class_type
125 PARAMS ((PTR
, const char *, unsigned int, bfd_boolean
, unsigned int,
126 bfd_boolean
, bfd_boolean
));
127 static bfd_boolean pr_class_static_member
128 PARAMS ((PTR
, const char *, const char *, enum debug_visibility
));
129 static bfd_boolean pr_class_baseclass
130 PARAMS ((PTR
, bfd_vma
, bfd_boolean
, enum debug_visibility
));
131 static bfd_boolean pr_class_start_method
132 PARAMS ((PTR
, const char *));
133 static bfd_boolean pr_class_method_variant
134 PARAMS ((PTR
, const char *, enum debug_visibility
, bfd_boolean
, bfd_boolean
,
135 bfd_vma
, bfd_boolean
));
136 static bfd_boolean pr_class_static_method_variant
137 PARAMS ((PTR
, const char *, enum debug_visibility
, bfd_boolean
,
139 static bfd_boolean pr_class_end_method
141 static bfd_boolean pr_end_class_type
143 static bfd_boolean pr_typedef_type
144 PARAMS ((PTR
, const char *));
145 static bfd_boolean pr_tag_type
146 PARAMS ((PTR
, const char *, unsigned int, enum debug_type_kind
));
147 static bfd_boolean pr_typdef
148 PARAMS ((PTR
, const char *));
149 static bfd_boolean pr_tag
150 PARAMS ((PTR
, const char *));
151 static bfd_boolean pr_int_constant
152 PARAMS ((PTR
, const char *, bfd_vma
));
153 static bfd_boolean pr_float_constant
154 PARAMS ((PTR
, const char *, double));
155 static bfd_boolean pr_typed_constant
156 PARAMS ((PTR
, const char *, bfd_vma
));
157 static bfd_boolean pr_variable
158 PARAMS ((PTR
, const char *, enum debug_var_kind
, bfd_vma
));
159 static bfd_boolean pr_start_function
160 PARAMS ((PTR
, const char *, bfd_boolean
));
161 static bfd_boolean pr_function_parameter
162 PARAMS ((PTR
, const char *, enum debug_parm_kind
, bfd_vma
));
163 static bfd_boolean pr_start_block
164 PARAMS ((PTR
, bfd_vma
));
165 static bfd_boolean pr_end_block
166 PARAMS ((PTR
, bfd_vma
));
167 static bfd_boolean pr_end_function
169 static bfd_boolean pr_lineno
170 PARAMS ((PTR
, const char *, unsigned long, bfd_vma
));
172 static const struct debug_write_fns pr_fns
=
174 pr_start_compilation_unit
,
193 pr_start_struct_type
,
197 pr_class_static_member
,
199 pr_class_start_method
,
200 pr_class_method_variant
,
201 pr_class_static_method_variant
,
213 pr_function_parameter
,
220 /* Print out the generic debugging information recorded in dhandle. */
223 print_debugging_info (f
, dhandle
)
227 struct pr_handle info
;
234 return debug_write (dhandle
, &pr_fns
, (PTR
) &info
);
237 /* Indent to the current indentation level. */
241 struct pr_handle
*info
;
245 for (i
= 0; i
< info
->indent
; i
++)
249 /* Push a type on the type stack. */
252 push_type (info
, type
)
253 struct pr_handle
*info
;
261 n
= (struct pr_stack
*) xmalloc (sizeof *n
);
262 memset (n
, 0, sizeof *n
);
264 n
->type
= xstrdup (type
);
265 n
->visibility
= DEBUG_VISIBILITY_IGNORE
;
267 n
->next
= info
->stack
;
273 /* Prepend a string onto the type on the top of the type stack. */
276 prepend_type (info
, s
)
277 struct pr_handle
*info
;
282 assert (info
->stack
!= NULL
);
284 n
= (char *) xmalloc (strlen (s
) + strlen (info
->stack
->type
) + 1);
285 sprintf (n
, "%s%s", s
, info
->stack
->type
);
286 free (info
->stack
->type
);
287 info
->stack
->type
= n
;
292 /* Append a string to the type on the top of the type stack. */
295 append_type (info
, s
)
296 struct pr_handle
*info
;
304 assert (info
->stack
!= NULL
);
306 len
= strlen (info
->stack
->type
);
307 info
->stack
->type
= (char *) xrealloc (info
->stack
->type
,
308 len
+ strlen (s
) + 1);
309 strcpy (info
->stack
->type
+ len
, s
);
314 /* We use an underscore to indicate where the name should go in a type
315 string. This function substitutes a string for the underscore. If
316 there is no underscore, the name follows the type. */
319 substitute_type (info
, s
)
320 struct pr_handle
*info
;
325 assert (info
->stack
!= NULL
);
327 u
= strchr (info
->stack
->type
, '|');
332 n
= (char *) xmalloc (strlen (info
->stack
->type
) + strlen (s
));
334 memcpy (n
, info
->stack
->type
, u
- info
->stack
->type
);
335 strcpy (n
+ (u
- info
->stack
->type
), s
);
338 free (info
->stack
->type
);
339 info
->stack
->type
= n
;
344 if (strchr (s
, '|') != NULL
345 && (strchr (info
->stack
->type
, '{') != NULL
346 || strchr (info
->stack
->type
, '(') != NULL
))
348 if (! prepend_type (info
, "(")
349 || ! append_type (info
, ")"))
356 return (append_type (info
, " ")
357 && append_type (info
, s
));
360 /* Indent the type at the top of the stack by appending spaces. */
364 struct pr_handle
*info
;
368 for (i
= 0; i
< info
->indent
; i
++)
370 if (! append_type (info
, " "))
377 /* Pop a type from the type stack. */
381 struct pr_handle
*info
;
386 assert (info
->stack
!= NULL
);
389 info
->stack
= o
->next
;
396 /* Print a VMA value into a string. */
399 print_vma (vma
, buf
, unsignedp
, hexp
)
402 bfd_boolean unsignedp
;
405 if (sizeof (vma
) <= sizeof (unsigned long))
408 sprintf (buf
, "0x%lx", (unsigned long) vma
);
410 sprintf (buf
, "%lu", (unsigned long) vma
);
412 sprintf (buf
, "%ld", (long) vma
);
418 sprintf_vma (buf
+ 2, vma
);
422 /* Start a new compilation unit. */
425 pr_start_compilation_unit (p
, filename
)
427 const char *filename
;
429 struct pr_handle
*info
= (struct pr_handle
*) p
;
431 assert (info
->indent
== 0);
433 fprintf (info
->f
, "%s:\n", filename
);
438 /* Start a source file within a compilation unit. */
441 pr_start_source (p
, filename
)
443 const char *filename
;
445 struct pr_handle
*info
= (struct pr_handle
*) p
;
447 assert (info
->indent
== 0);
449 fprintf (info
->f
, " %s:\n", filename
);
454 /* Push an empty type onto the type stack. */
460 struct pr_handle
*info
= (struct pr_handle
*) p
;
462 return push_type (info
, "<undefined>");
465 /* Push a void type onto the type stack. */
471 struct pr_handle
*info
= (struct pr_handle
*) p
;
473 return push_type (info
, "void");
476 /* Push an integer type onto the type stack. */
479 pr_int_type (p
, size
, unsignedp
)
482 bfd_boolean unsignedp
;
484 struct pr_handle
*info
= (struct pr_handle
*) p
;
487 sprintf (ab
, "%sint%d", unsignedp
? "u" : "", size
* 8);
488 return push_type (info
, ab
);
491 /* Push a floating type onto the type stack. */
494 pr_float_type (p
, size
)
498 struct pr_handle
*info
= (struct pr_handle
*) p
;
502 return push_type (info
, "float");
504 return push_type (info
, "double");
506 sprintf (ab
, "float%d", size
* 8);
507 return push_type (info
, ab
);
510 /* Push a complex type onto the type stack. */
513 pr_complex_type (p
, size
)
517 struct pr_handle
*info
= (struct pr_handle
*) p
;
519 if (! pr_float_type (p
, size
))
522 return prepend_type (info
, "complex ");
525 /* Push a bfd_boolean type onto the type stack. */
528 pr_bool_type (p
, size
)
532 struct pr_handle
*info
= (struct pr_handle
*) p
;
535 sprintf (ab
, "bool%d", size
* 8);
537 return push_type (info
, ab
);
540 /* Push an enum type onto the type stack. */
543 pr_enum_type (p
, tag
, names
, values
)
547 bfd_signed_vma
*values
;
549 struct pr_handle
*info
= (struct pr_handle
*) p
;
553 if (! push_type (info
, "enum "))
557 if (! append_type (info
, tag
)
558 || ! append_type (info
, " "))
561 if (! append_type (info
, "{ "))
566 if (! append_type (info
, "/* undefined */"))
572 for (i
= 0; names
[i
] != NULL
; i
++)
576 if (! append_type (info
, ", "))
580 if (! append_type (info
, names
[i
]))
583 if (values
[i
] != val
)
587 print_vma (values
[i
], ab
, FALSE
, FALSE
);
588 if (! append_type (info
, " = ")
589 || ! append_type (info
, ab
))
598 return append_type (info
, " }");
601 /* Turn the top type on the stack into a pointer. */
607 struct pr_handle
*info
= (struct pr_handle
*) p
;
610 assert (info
->stack
!= NULL
);
612 s
= strchr (info
->stack
->type
, '|');
613 if (s
!= NULL
&& s
[1] == '[')
614 return substitute_type (info
, "(*|)");
615 return substitute_type (info
, "*|");
618 /* Turn the top type on the stack into a function returning that type. */
621 pr_function_type (p
, argcount
, varargs
)
626 struct pr_handle
*info
= (struct pr_handle
*) p
;
631 assert (info
->stack
!= NULL
);
644 arg_types
= (char **) xmalloc (argcount
* sizeof *arg_types
);
645 for (i
= argcount
- 1; i
>= 0; i
--)
647 if (! substitute_type (info
, ""))
649 arg_types
[i
] = pop_type (info
);
650 if (arg_types
[i
] == NULL
)
652 len
+= strlen (arg_types
[i
]) + 2;
658 /* Now the return type is on the top of the stack. */
660 s
= (char *) xmalloc (len
);
664 strcat (s
, "/* unknown */");
669 for (i
= 0; i
< argcount
; i
++)
673 strcat (s
, arg_types
[i
]);
687 if (! substitute_type (info
, s
))
695 /* Turn the top type on the stack into a reference to that type. */
698 pr_reference_type (p
)
701 struct pr_handle
*info
= (struct pr_handle
*) p
;
703 assert (info
->stack
!= NULL
);
705 return substitute_type (info
, "&|");
708 /* Make a range type. */
711 pr_range_type (p
, lower
, upper
)
713 bfd_signed_vma lower
;
714 bfd_signed_vma upper
;
716 struct pr_handle
*info
= (struct pr_handle
*) p
;
717 char abl
[20], abu
[20];
719 assert (info
->stack
!= NULL
);
721 if (! substitute_type (info
, ""))
724 print_vma (lower
, abl
, FALSE
, FALSE
);
725 print_vma (upper
, abu
, FALSE
, FALSE
);
727 return (prepend_type (info
, "range (")
728 && append_type (info
, "):")
729 && append_type (info
, abl
)
730 && append_type (info
, ":")
731 && append_type (info
, abu
));
734 /* Make an array type. */
737 pr_array_type (p
, lower
, upper
, stringp
)
739 bfd_signed_vma lower
;
740 bfd_signed_vma upper
;
743 struct pr_handle
*info
= (struct pr_handle
*) p
;
745 char abl
[20], abu
[20], ab
[50];
747 range_type
= pop_type (info
);
748 if (range_type
== NULL
)
757 print_vma (upper
+ 1, abu
, FALSE
, FALSE
);
758 sprintf (ab
, "|[%s]", abu
);
763 print_vma (lower
, abl
, FALSE
, FALSE
);
764 print_vma (upper
, abu
, FALSE
, FALSE
);
765 sprintf (ab
, "|[%s:%s]", abl
, abu
);
768 if (! substitute_type (info
, ab
))
771 if (strcmp (range_type
, "int") != 0)
773 if (! append_type (info
, ":")
774 || ! append_type (info
, range_type
))
780 if (! append_type (info
, " /* string */"))
787 /* Make a set type. */
790 pr_set_type (p
, bitstringp
)
792 bfd_boolean bitstringp
;
794 struct pr_handle
*info
= (struct pr_handle
*) p
;
796 if (! substitute_type (info
, ""))
799 if (! prepend_type (info
, "set { ")
800 || ! append_type (info
, " }"))
805 if (! append_type (info
, "/* bitstring */"))
812 /* Make an offset type. */
818 struct pr_handle
*info
= (struct pr_handle
*) p
;
821 if (! substitute_type (info
, ""))
828 return (substitute_type (info
, "")
829 && prepend_type (info
, " ")
830 && prepend_type (info
, t
)
831 && append_type (info
, "::|"));
834 /* Make a method type. */
837 pr_method_type (p
, domain
, argcount
, varargs
)
843 struct pr_handle
*info
= (struct pr_handle
*) p
;
855 if (! substitute_type (info
, ""))
857 domain_type
= pop_type (info
);
858 if (domain_type
== NULL
)
860 if (strncmp (domain_type
, "class ", sizeof "class " - 1) == 0
861 && strchr (domain_type
+ sizeof "class " - 1, ' ') == NULL
)
862 domain_type
+= sizeof "class " - 1;
863 else if (strncmp (domain_type
, "union class ",
864 sizeof "union class ") == 0
865 && (strchr (domain_type
+ sizeof "union class " - 1, ' ')
867 domain_type
+= sizeof "union class " - 1;
868 len
+= strlen (domain_type
);
880 arg_types
= (char **) xmalloc (argcount
* sizeof *arg_types
);
881 for (i
= argcount
- 1; i
>= 0; i
--)
883 if (! substitute_type (info
, ""))
885 arg_types
[i
] = pop_type (info
);
886 if (arg_types
[i
] == NULL
)
888 len
+= strlen (arg_types
[i
]) + 2;
894 /* Now the return type is on the top of the stack. */
896 s
= (char *) xmalloc (len
);
900 strcpy (s
, domain_type
);
904 strcat (s
, "/* unknown */");
909 for (i
= 0; i
< argcount
; i
++)
913 strcat (s
, arg_types
[i
]);
927 if (! substitute_type (info
, s
))
935 /* Make a const qualified type. */
941 struct pr_handle
*info
= (struct pr_handle
*) p
;
943 return substitute_type (info
, "const |");
946 /* Make a volatile qualified type. */
952 struct pr_handle
*info
= (struct pr_handle
*) p
;
954 return substitute_type (info
, "volatile |");
957 /* Start accumulating a struct type. */
960 pr_start_struct_type (p
, tag
, id
, structp
, size
)
967 struct pr_handle
*info
= (struct pr_handle
*) p
;
971 if (! push_type (info
, structp
? "struct " : "union "))
975 if (! append_type (info
, tag
))
982 sprintf (idbuf
, "%%anon%u", id
);
983 if (! append_type (info
, idbuf
))
987 if (! append_type (info
, " {"))
989 if (size
!= 0 || tag
!= NULL
)
993 if (! append_type (info
, " /*"))
998 sprintf (ab
, " size %u", size
);
999 if (! append_type (info
, ab
))
1004 sprintf (ab
, " id %u", id
);
1005 if (! append_type (info
, ab
))
1008 if (! append_type (info
, " */"))
1011 if (! append_type (info
, "\n"))
1014 info
->stack
->visibility
= DEBUG_VISIBILITY_PUBLIC
;
1016 return indent_type (info
);
1019 /* Output the visibility of a field in a struct. */
1022 pr_fix_visibility (info
, visibility
)
1023 struct pr_handle
*info
;
1024 enum debug_visibility visibility
;
1026 const char *s
= NULL
;
1030 assert (info
->stack
!= NULL
);
1032 if (info
->stack
->visibility
== visibility
)
1037 case DEBUG_VISIBILITY_PUBLIC
:
1040 case DEBUG_VISIBILITY_PRIVATE
:
1043 case DEBUG_VISIBILITY_PROTECTED
:
1046 case DEBUG_VISIBILITY_IGNORE
:
1054 /* Trim off a trailing space in the struct string, to make the
1055 output look a bit better, then stick on the visibility string. */
1057 t
= info
->stack
->type
;
1059 assert (t
[len
- 1] == ' ');
1062 if (! append_type (info
, s
)
1063 || ! append_type (info
, ":\n")
1064 || ! indent_type (info
))
1067 info
->stack
->visibility
= visibility
;
1072 /* Add a field to a struct type. */
1075 pr_struct_field (p
, name
, bitpos
, bitsize
, visibility
)
1080 enum debug_visibility visibility
;
1082 struct pr_handle
*info
= (struct pr_handle
*) p
;
1086 if (! substitute_type (info
, name
))
1089 if (! append_type (info
, "; /* "))
1094 print_vma (bitsize
, ab
, TRUE
, FALSE
);
1095 if (! append_type (info
, "bitsize ")
1096 || ! append_type (info
, ab
)
1097 || ! append_type (info
, ", "))
1101 print_vma (bitpos
, ab
, TRUE
, FALSE
);
1102 if (! append_type (info
, "bitpos ")
1103 || ! append_type (info
, ab
)
1104 || ! append_type (info
, " */\n")
1105 || ! indent_type (info
))
1108 t
= pop_type (info
);
1112 if (! pr_fix_visibility (info
, visibility
))
1115 return append_type (info
, t
);
1118 /* Finish a struct type. */
1121 pr_end_struct_type (p
)
1124 struct pr_handle
*info
= (struct pr_handle
*) p
;
1127 assert (info
->stack
!= NULL
);
1128 assert (info
->indent
>= 2);
1132 /* Change the trailing indentation to have a close brace. */
1133 s
= info
->stack
->type
+ strlen (info
->stack
->type
) - 2;
1134 assert (s
[0] == ' ' && s
[1] == ' ' && s
[2] == '\0');
1142 /* Start a class type. */
1145 pr_start_class_type (p
, tag
, id
, structp
, size
, vptr
, ownvptr
)
1149 bfd_boolean structp
;
1152 bfd_boolean ownvptr
;
1154 struct pr_handle
*info
= (struct pr_handle
*) p
;
1159 if (vptr
&& ! ownvptr
)
1161 tv
= pop_type (info
);
1166 if (! push_type (info
, structp
? "class " : "union class "))
1170 if (! append_type (info
, tag
))
1177 sprintf (idbuf
, "%%anon%u", id
);
1178 if (! append_type (info
, idbuf
))
1182 if (! append_type (info
, " {"))
1184 if (size
!= 0 || vptr
|| ownvptr
|| tag
!= NULL
)
1186 if (! append_type (info
, " /*"))
1193 sprintf (ab
, "%u", size
);
1194 if (! append_type (info
, " size ")
1195 || ! append_type (info
, ab
))
1201 if (! append_type (info
, " vtable "))
1205 if (! append_type (info
, "self "))
1210 if (! append_type (info
, tv
)
1211 || ! append_type (info
, " "))
1220 sprintf (ab
, " id %u", id
);
1221 if (! append_type (info
, ab
))
1225 if (! append_type (info
, " */"))
1229 info
->stack
->visibility
= DEBUG_VISIBILITY_PRIVATE
;
1231 return (append_type (info
, "\n")
1232 && indent_type (info
));
1235 /* Add a static member to a class. */
1238 pr_class_static_member (p
, name
, physname
, visibility
)
1241 const char *physname
;
1242 enum debug_visibility visibility
;
1244 struct pr_handle
*info
= (struct pr_handle
*) p
;
1247 if (! substitute_type (info
, name
))
1250 if (! prepend_type (info
, "static ")
1251 || ! append_type (info
, "; /* ")
1252 || ! append_type (info
, physname
)
1253 || ! append_type (info
, " */\n")
1254 || ! indent_type (info
))
1257 t
= pop_type (info
);
1261 if (! pr_fix_visibility (info
, visibility
))
1264 return append_type (info
, t
);
1267 /* Add a base class to a class. */
1270 pr_class_baseclass (p
, bitpos
, virtual, visibility
)
1273 bfd_boolean
virtual;
1274 enum debug_visibility visibility
;
1276 struct pr_handle
*info
= (struct pr_handle
*) p
;
1282 assert (info
->stack
!= NULL
&& info
->stack
->next
!= NULL
);
1284 if (! substitute_type (info
, ""))
1287 t
= pop_type (info
);
1291 if (strncmp (t
, "class ", sizeof "class " - 1) == 0)
1292 t
+= sizeof "class " - 1;
1294 /* Push it back on to take advantage of the prepend_type and
1295 append_type routines. */
1296 if (! push_type (info
, t
))
1301 if (! prepend_type (info
, "virtual "))
1307 case DEBUG_VISIBILITY_PUBLIC
:
1310 case DEBUG_VISIBILITY_PROTECTED
:
1311 prefix
= "protected ";
1313 case DEBUG_VISIBILITY_PRIVATE
:
1314 prefix
= "private ";
1317 prefix
= "/* unknown visibility */ ";
1321 if (! prepend_type (info
, prefix
))
1326 print_vma (bitpos
, ab
, TRUE
, FALSE
);
1327 if (! append_type (info
, " /* bitpos ")
1328 || ! append_type (info
, ab
)
1329 || ! append_type (info
, " */"))
1333 /* Now the top of the stack is something like "public A / * bitpos
1334 10 * /". The next element on the stack is something like "class
1335 xx { / * size 8 * /\n...". We want to substitute the top of the
1336 stack in before the {. */
1337 s
= strchr (info
->stack
->next
->type
, '{');
1341 /* If there is already a ':', then we already have a baseclass, and
1342 we must append this one after a comma. */
1343 for (l
= info
->stack
->next
->type
; l
!= s
; l
++)
1346 if (! prepend_type (info
, l
== s
? " : " : ", "))
1349 t
= pop_type (info
);
1353 n
= (char *) xmalloc (strlen (info
->stack
->type
) + strlen (t
) + 1);
1354 memcpy (n
, info
->stack
->type
, s
- info
->stack
->type
);
1355 strcpy (n
+ (s
- info
->stack
->type
), t
);
1358 free (info
->stack
->type
);
1359 info
->stack
->type
= n
;
1366 /* Start adding a method to a class. */
1369 pr_class_start_method (p
, name
)
1373 struct pr_handle
*info
= (struct pr_handle
*) p
;
1375 assert (info
->stack
!= NULL
);
1376 info
->stack
->method
= name
;
1380 /* Add a variant to a method. */
1383 pr_class_method_variant (p
, physname
, visibility
, constp
, volatilep
, voffset
,
1386 const char *physname
;
1387 enum debug_visibility visibility
;
1389 bfd_boolean volatilep
;
1391 bfd_boolean context
;
1393 struct pr_handle
*info
= (struct pr_handle
*) p
;
1397 assert (info
->stack
!= NULL
);
1398 assert (info
->stack
->next
!= NULL
);
1400 /* Put the const and volatile qualifiers on the type. */
1403 if (! append_type (info
, " volatile"))
1408 if (! append_type (info
, " const"))
1412 /* Stick the name of the method into its type. */
1413 if (! substitute_type (info
,
1415 ? info
->stack
->next
->next
->method
1416 : info
->stack
->next
->method
)))
1420 method_type
= pop_type (info
);
1421 if (method_type
== NULL
)
1424 /* Pull off the context type if there is one. */
1426 context_type
= NULL
;
1429 context_type
= pop_type (info
);
1430 if (context_type
== NULL
)
1434 /* Now the top of the stack is the class. */
1436 if (! pr_fix_visibility (info
, visibility
))
1439 if (! append_type (info
, method_type
)
1440 || ! append_type (info
, " /* ")
1441 || ! append_type (info
, physname
)
1442 || ! append_type (info
, " "))
1444 if (context
|| voffset
!= 0)
1450 if (! append_type (info
, "context ")
1451 || ! append_type (info
, context_type
)
1452 || ! append_type (info
, " "))
1455 print_vma (voffset
, ab
, TRUE
, FALSE
);
1456 if (! append_type (info
, "voffset ")
1457 || ! append_type (info
, ab
))
1461 return (append_type (info
, " */;\n")
1462 && indent_type (info
));
1465 /* Add a static variant to a method. */
1468 pr_class_static_method_variant (p
, physname
, visibility
, constp
, volatilep
)
1470 const char *physname
;
1471 enum debug_visibility visibility
;
1473 bfd_boolean volatilep
;
1475 struct pr_handle
*info
= (struct pr_handle
*) p
;
1478 assert (info
->stack
!= NULL
);
1479 assert (info
->stack
->next
!= NULL
);
1480 assert (info
->stack
->next
->method
!= NULL
);
1482 /* Put the const and volatile qualifiers on the type. */
1485 if (! append_type (info
, " volatile"))
1490 if (! append_type (info
, " const"))
1494 /* Mark it as static. */
1495 if (! prepend_type (info
, "static "))
1498 /* Stick the name of the method into its type. */
1499 if (! substitute_type (info
, info
->stack
->next
->method
))
1503 method_type
= pop_type (info
);
1504 if (method_type
== NULL
)
1507 /* Now the top of the stack is the class. */
1509 if (! pr_fix_visibility (info
, visibility
))
1512 return (append_type (info
, method_type
)
1513 && append_type (info
, " /* ")
1514 && append_type (info
, physname
)
1515 && append_type (info
, " */;\n")
1516 && indent_type (info
));
1519 /* Finish up a method. */
1522 pr_class_end_method (p
)
1525 struct pr_handle
*info
= (struct pr_handle
*) p
;
1527 info
->stack
->method
= NULL
;
1531 /* Finish up a class. */
1534 pr_end_class_type (p
)
1537 return pr_end_struct_type (p
);
1540 /* Push a type on the stack using a typedef name. */
1543 pr_typedef_type (p
, name
)
1547 struct pr_handle
*info
= (struct pr_handle
*) p
;
1549 return push_type (info
, name
);
1552 /* Push a type on the stack using a tag name. */
1555 pr_tag_type (p
, name
, id
, kind
)
1559 enum debug_type_kind kind
;
1561 struct pr_handle
*info
= (struct pr_handle
*) p
;
1562 const char *t
, *tag
;
1567 case DEBUG_KIND_STRUCT
:
1570 case DEBUG_KIND_UNION
:
1573 case DEBUG_KIND_ENUM
:
1576 case DEBUG_KIND_CLASS
:
1579 case DEBUG_KIND_UNION_CLASS
:
1587 if (! push_type (info
, t
))
1593 sprintf (idbuf
, "%%anon%u", id
);
1597 if (! append_type (info
, tag
))
1599 if (name
!= NULL
&& kind
!= DEBUG_KIND_ENUM
)
1601 sprintf (idbuf
, " /* id %u */", id
);
1602 if (! append_type (info
, idbuf
))
1609 /* Output a typedef. */
1616 struct pr_handle
*info
= (struct pr_handle
*) p
;
1619 if (! substitute_type (info
, name
))
1622 s
= pop_type (info
);
1627 fprintf (info
->f
, "typedef %s;\n", s
);
1634 /* Output a tag. The tag should already be in the string on the
1635 stack, so all we have to do here is print it out. */
1640 const char *name ATTRIBUTE_UNUSED
;
1642 struct pr_handle
*info
= (struct pr_handle
*) p
;
1645 t
= pop_type (info
);
1650 fprintf (info
->f
, "%s;\n", t
);
1657 /* Output an integer constant. */
1660 pr_int_constant (p
, name
, val
)
1665 struct pr_handle
*info
= (struct pr_handle
*) p
;
1669 print_vma (val
, ab
, FALSE
, FALSE
);
1670 fprintf (info
->f
, "const int %s = %s;\n", name
, ab
);
1674 /* Output a floating point constant. */
1677 pr_float_constant (p
, name
, val
)
1682 struct pr_handle
*info
= (struct pr_handle
*) p
;
1685 fprintf (info
->f
, "const double %s = %g;\n", name
, val
);
1689 /* Output a typed constant. */
1692 pr_typed_constant (p
, name
, val
)
1697 struct pr_handle
*info
= (struct pr_handle
*) p
;
1701 t
= pop_type (info
);
1706 print_vma (val
, ab
, FALSE
, FALSE
);
1707 fprintf (info
->f
, "const %s %s = %s;\n", t
, name
, ab
);
1714 /* Output a variable. */
1717 pr_variable (p
, name
, kind
, val
)
1720 enum debug_var_kind kind
;
1723 struct pr_handle
*info
= (struct pr_handle
*) p
;
1727 if (! substitute_type (info
, name
))
1730 t
= pop_type (info
);
1738 case DEBUG_LOCAL_STATIC
:
1739 fprintf (info
->f
, "static ");
1741 case DEBUG_REGISTER
:
1742 fprintf (info
->f
, "register ");
1747 print_vma (val
, ab
, TRUE
, TRUE
);
1748 fprintf (info
->f
, "%s /* %s */;\n", t
, ab
);
1755 /* Start outputting a function. */
1758 pr_start_function (p
, name
, global
)
1763 struct pr_handle
*info
= (struct pr_handle
*) p
;
1766 if (! substitute_type (info
, name
))
1769 t
= pop_type (info
);
1775 fprintf (info
->f
, "static ");
1776 fprintf (info
->f
, "%s (", t
);
1778 info
->parameter
= 1;
1783 /* Output a function parameter. */
1786 pr_function_parameter (p
, name
, kind
, val
)
1789 enum debug_parm_kind kind
;
1792 struct pr_handle
*info
= (struct pr_handle
*) p
;
1796 if (kind
== DEBUG_PARM_REFERENCE
1797 || kind
== DEBUG_PARM_REF_REG
)
1799 if (! pr_reference_type (p
))
1803 if (! substitute_type (info
, name
))
1806 t
= pop_type (info
);
1810 if (info
->parameter
!= 1)
1811 fprintf (info
->f
, ", ");
1813 if (kind
== DEBUG_PARM_REG
|| kind
== DEBUG_PARM_REF_REG
)
1814 fprintf (info
->f
, "register ");
1816 print_vma (val
, ab
, TRUE
, TRUE
);
1817 fprintf (info
->f
, "%s /* %s */", t
, ab
);
1826 /* Start writing out a block. */
1829 pr_start_block (p
, addr
)
1833 struct pr_handle
*info
= (struct pr_handle
*) p
;
1836 if (info
->parameter
> 0)
1838 fprintf (info
->f
, ")\n");
1839 info
->parameter
= 0;
1843 print_vma (addr
, ab
, TRUE
, TRUE
);
1844 fprintf (info
->f
, "{ /* %s */\n", ab
);
1851 /* Write out line number information. */
1854 pr_lineno (p
, filename
, lineno
, addr
)
1856 const char *filename
;
1857 unsigned long lineno
;
1860 struct pr_handle
*info
= (struct pr_handle
*) p
;
1864 print_vma (addr
, ab
, TRUE
, TRUE
);
1865 fprintf (info
->f
, "/* file %s line %lu addr %s */\n", filename
, lineno
, ab
);
1870 /* Finish writing out a block. */
1873 pr_end_block (p
, addr
)
1877 struct pr_handle
*info
= (struct pr_handle
*) p
;
1883 print_vma (addr
, ab
, TRUE
, TRUE
);
1884 fprintf (info
->f
, "} /* %s */\n", ab
);
1889 /* Finish writing out a function. */
1893 PTR p ATTRIBUTE_UNUSED
;