1 /* prdbg.c -- Print out generic debugging information.
2 Copyright (C) 1995-2014 Free Software Foundation, Inc.
3 Written by Ian Lance Taylor <ian@cygnus.com>.
4 Tags style generation written by Salvador E. Tropea <set@computer.org>.
6 This file is part of GNU Binutils.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
23 /* This file prints out the generic debugging information, by
24 supplying a set of routines to debug_write. */
29 #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. */
46 /* The following are used only by the tags code (tg_). */
47 /* Name of the file we are using. */
51 /* The symbols table for this BFD. */
53 /* Pointer to a function to demangle symbols. */
54 char *(*demangler
) (bfd
*, const char *, int);
61 /* Next element on the stack. */
62 struct pr_stack
*next
;
65 /* Current visibility of fields if this is a class. */
66 enum debug_visibility visibility
;
67 /* Name of the current method we are handling. */
69 /* The following are used only by the tags code (tg_). */
70 /* Type for the container (struct, union, class, union class). */
72 /* A comma separated list of parent classes. */
74 /* How many parents contains parents. */
78 static void indent (struct pr_handle
*);
79 static bfd_boolean
push_type (struct pr_handle
*, const char *);
80 static bfd_boolean
prepend_type (struct pr_handle
*, const char *);
81 static bfd_boolean
append_type (struct pr_handle
*, const char *);
82 static bfd_boolean
substitute_type (struct pr_handle
*, const char *);
83 static bfd_boolean
indent_type (struct pr_handle
*);
84 static char *pop_type (struct pr_handle
*);
85 static void print_vma (bfd_vma
, char *, bfd_boolean
, bfd_boolean
);
86 static bfd_boolean pr_fix_visibility
87 (struct pr_handle
*, enum debug_visibility
);
88 static bfd_boolean
pr_start_compilation_unit (void *, const char *);
89 static bfd_boolean
pr_start_source (void *, const char *);
90 static bfd_boolean
pr_empty_type (void *);
91 static bfd_boolean
pr_void_type (void *);
92 static bfd_boolean
pr_int_type (void *, unsigned int, bfd_boolean
);
93 static bfd_boolean
pr_float_type (void *, unsigned int);
94 static bfd_boolean
pr_complex_type (void *, unsigned int);
95 static bfd_boolean
pr_bool_type (void *, unsigned int);
96 static bfd_boolean pr_enum_type
97 (void *, const char *, const char **, bfd_signed_vma
*);
98 static bfd_boolean
pr_pointer_type (void *);
99 static bfd_boolean
pr_function_type (void *, int, bfd_boolean
);
100 static bfd_boolean
pr_reference_type (void *);
101 static bfd_boolean
pr_range_type (void *, bfd_signed_vma
, bfd_signed_vma
);
102 static bfd_boolean pr_array_type
103 (void *, bfd_signed_vma
, bfd_signed_vma
, bfd_boolean
);
104 static bfd_boolean
pr_set_type (void *, bfd_boolean
);
105 static bfd_boolean
pr_offset_type (void *);
106 static bfd_boolean
pr_method_type (void *, bfd_boolean
, int, bfd_boolean
);
107 static bfd_boolean
pr_const_type (void *);
108 static bfd_boolean
pr_volatile_type (void *);
109 static bfd_boolean pr_start_struct_type
110 (void *, const char *, unsigned int, bfd_boolean
, unsigned int);
111 static bfd_boolean pr_struct_field
112 (void *, const char *, bfd_vma
, bfd_vma
, enum debug_visibility
);
113 static bfd_boolean
pr_end_struct_type (void *);
114 static bfd_boolean pr_start_class_type
115 (void *, const char *, unsigned int, bfd_boolean
, unsigned int,
116 bfd_boolean
, bfd_boolean
);
117 static bfd_boolean pr_class_static_member
118 (void *, const char *, const char *, enum debug_visibility
);
119 static bfd_boolean pr_class_baseclass
120 (void *, bfd_vma
, bfd_boolean
, enum debug_visibility
);
121 static bfd_boolean
pr_class_start_method (void *, const char *);
122 static bfd_boolean pr_class_method_variant
123 (void *, const char *, enum debug_visibility
, bfd_boolean
, bfd_boolean
,
124 bfd_vma
, bfd_boolean
);
125 static bfd_boolean pr_class_static_method_variant
126 (void *, const char *, enum debug_visibility
, bfd_boolean
, bfd_boolean
);
127 static bfd_boolean
pr_class_end_method (void *);
128 static bfd_boolean
pr_end_class_type (void *);
129 static bfd_boolean
pr_typedef_type (void *, const char *);
130 static bfd_boolean pr_tag_type
131 (void *, const char *, unsigned int, enum debug_type_kind
);
132 static bfd_boolean
pr_typdef (void *, const char *);
133 static bfd_boolean
pr_tag (void *, const char *);
134 static bfd_boolean
pr_int_constant (void *, const char *, bfd_vma
);
135 static bfd_boolean
pr_float_constant (void *, const char *, double);
136 static bfd_boolean
pr_typed_constant (void *, const char *, bfd_vma
);
137 static bfd_boolean pr_variable
138 (void *, const char *, enum debug_var_kind
, bfd_vma
);
139 static bfd_boolean
pr_start_function (void *, const char *, bfd_boolean
);
140 static bfd_boolean pr_function_parameter
141 (void *, const char *, enum debug_parm_kind
, bfd_vma
);
142 static bfd_boolean
pr_start_block (void *, bfd_vma
);
143 static bfd_boolean
pr_end_block (void *, bfd_vma
);
144 static bfd_boolean
pr_end_function (void *);
145 static bfd_boolean
pr_lineno (void *, const char *, unsigned long, bfd_vma
);
146 static bfd_boolean
append_parent (struct pr_handle
*, const char *);
147 /* Only used by tg_ code. */
148 static bfd_boolean tg_fix_visibility
149 (struct pr_handle
*, enum debug_visibility
);
150 static void find_address_in_section (bfd
*, asection
*, void *);
151 static void translate_addresses (bfd
*, char *, FILE *, asymbol
**);
152 static const char *visibility_name (enum debug_visibility
);
153 /* Tags style replacements. */
154 static bfd_boolean
tg_start_compilation_unit (void *, const char *);
155 static bfd_boolean
tg_start_source (void *, const char *);
156 static bfd_boolean tg_enum_type
157 (void *, const char *, const char **, bfd_signed_vma
*);
158 static bfd_boolean tg_start_struct_type
159 (void *, const char *, unsigned int, bfd_boolean
, unsigned int);
160 static bfd_boolean pr_struct_field
161 (void *, const char *, bfd_vma
, bfd_vma
, enum debug_visibility
);
162 static bfd_boolean tg_struct_field
163 (void *, const char *, bfd_vma
, bfd_vma
, enum debug_visibility
);
164 static bfd_boolean tg_struct_field
165 (void *, const char *, bfd_vma
, bfd_vma
, enum debug_visibility
);
166 static bfd_boolean
tg_end_struct_type (void *);
167 static bfd_boolean tg_start_class_type
168 (void *, const char *, unsigned int, bfd_boolean
, unsigned int, bfd_boolean
, bfd_boolean
);
169 static bfd_boolean tg_class_static_member
170 (void *, const char *, const char *, enum debug_visibility
);
171 static bfd_boolean tg_class_baseclass
172 (void *, bfd_vma
, bfd_boolean
, enum debug_visibility
);
173 static bfd_boolean tg_class_method_variant
174 (void *, const char *, enum debug_visibility
, bfd_boolean
, bfd_boolean
, bfd_vma
, bfd_boolean
);
175 static bfd_boolean tg_class_static_method_variant
176 (void *, const char *, enum debug_visibility
, bfd_boolean
, bfd_boolean
);
177 static bfd_boolean
tg_end_class_type (void *);
178 static bfd_boolean tg_tag_type
179 (void *, const char *, unsigned int, enum debug_type_kind
);
180 static bfd_boolean
tg_typdef (void *, const char *);
181 static bfd_boolean
tg_tag (void *, const char *);
182 static bfd_boolean
tg_int_constant (void *, const char *, bfd_vma
);
183 static bfd_boolean
tg_float_constant (void *, const char *, double);
184 static bfd_boolean
tg_typed_constant (void *, const char *, bfd_vma
);
185 static bfd_boolean tg_variable
186 (void *, const char *, enum debug_var_kind
, bfd_vma
);
187 static bfd_boolean
tg_start_function (void *, const char *, bfd_boolean
);
188 static bfd_boolean tg_function_parameter
189 (void *, const char *, enum debug_parm_kind
, bfd_vma
);
190 static bfd_boolean
tg_start_block (void *, bfd_vma
);
191 static bfd_boolean
tg_end_block (void *, bfd_vma
);
192 static bfd_boolean
tg_lineno (void *, const char *, unsigned long, bfd_vma
);
194 static const struct debug_write_fns pr_fns
=
196 pr_start_compilation_unit
,
215 pr_start_struct_type
,
219 pr_class_static_member
,
221 pr_class_start_method
,
222 pr_class_method_variant
,
223 pr_class_static_method_variant
,
235 pr_function_parameter
,
242 static const struct debug_write_fns tg_fns
=
244 tg_start_compilation_unit
,
246 pr_empty_type
, /* Same, push_type. */
247 pr_void_type
, /* Same, push_type. */
248 pr_int_type
, /* Same, push_type. */
249 pr_float_type
, /* Same, push_type. */
250 pr_complex_type
, /* Same, push_type. */
251 pr_bool_type
, /* Same, push_type. */
253 pr_pointer_type
, /* Same, changes to pointer. */
254 pr_function_type
, /* Same, push_type. */
255 pr_reference_type
, /* Same, changes to reference. */
256 pr_range_type
, /* FIXME: What's that?. */
257 pr_array_type
, /* Same, push_type. */
258 pr_set_type
, /* FIXME: What's that?. */
259 pr_offset_type
, /* FIXME: What's that?. */
260 pr_method_type
, /* Same. */
261 pr_const_type
, /* Same, changes to const. */
262 pr_volatile_type
, /* Same, changes to volatile. */
263 tg_start_struct_type
,
267 tg_class_static_member
,
269 pr_class_start_method
, /* Same, remembers that's a method. */
270 tg_class_method_variant
,
271 tg_class_static_method_variant
,
272 pr_class_end_method
, /* Same, forgets that's a method. */
274 pr_typedef_type
, /* Same, just push type. */
278 tg_int_constant
, /* Untested. */
279 tg_float_constant
, /* Untested. */
280 tg_typed_constant
, /* Untested. */
283 tg_function_parameter
,
286 pr_end_function
, /* Same, does nothing. */
290 /* Print out the generic debugging information recorded in dhandle. */
293 print_debugging_info (FILE *f
, void *dhandle
, bfd
*abfd
, asymbol
**syms
,
294 void *demangler
, bfd_boolean as_tags
)
296 struct pr_handle info
;
302 info
.filename
= NULL
;
305 info
.demangler
= (char * (*)(struct bfd
*, const char *, int)) demangler
;
309 fputs ("!_TAG_FILE_FORMAT\t2\t/extended format/\n", f
);
310 fputs ("!_TAG_FILE_SORTED\t0\t/0=unsorted, 1=sorted/\n", f
);
311 fputs ("!_TAG_PROGRAM_AUTHOR\tIan Lance Taylor, Salvador E. Tropea and others\t//\n", f
);
312 fputs ("!_TAG_PROGRAM_NAME\tobjdump\t/From GNU binutils/\n", f
);
315 return as_tags
? debug_write (dhandle
, &tg_fns
, (void *) & info
)
316 : debug_write (dhandle
, &pr_fns
, (void *) & info
);
319 /* Indent to the current indentation level. */
322 indent (struct pr_handle
*info
)
326 for (i
= 0; i
< info
->indent
; i
++)
330 /* Push a type on the type stack. */
333 push_type (struct pr_handle
*info
, const char *type
)
340 n
= (struct pr_stack
*) xmalloc (sizeof *n
);
341 memset (n
, 0, sizeof *n
);
343 n
->type
= xstrdup (type
);
344 n
->visibility
= DEBUG_VISIBILITY_IGNORE
;
346 n
->next
= info
->stack
;
352 /* Prepend a string onto the type on the top of the type stack. */
355 prepend_type (struct pr_handle
*info
, const char *s
)
359 assert (info
->stack
!= NULL
);
361 n
= (char *) xmalloc (strlen (s
) + strlen (info
->stack
->type
) + 1);
362 sprintf (n
, "%s%s", s
, info
->stack
->type
);
363 free (info
->stack
->type
);
364 info
->stack
->type
= n
;
369 /* Append a string to the type on the top of the type stack. */
372 append_type (struct pr_handle
*info
, const char *s
)
379 assert (info
->stack
!= NULL
);
381 len
= strlen (info
->stack
->type
);
382 info
->stack
->type
= (char *) xrealloc (info
->stack
->type
,
383 len
+ strlen (s
) + 1);
384 strcpy (info
->stack
->type
+ len
, s
);
389 /* Append a string to the parents on the top of the type stack. */
392 append_parent (struct pr_handle
*info
, const char *s
)
399 assert (info
->stack
!= NULL
);
401 len
= info
->stack
->parents
? strlen (info
->stack
->parents
) : 0;
402 info
->stack
->parents
= (char *) xrealloc (info
->stack
->parents
,
403 len
+ strlen (s
) + 1);
404 strcpy (info
->stack
->parents
+ len
, s
);
409 /* We use an underscore to indicate where the name should go in a type
410 string. This function substitutes a string for the underscore. If
411 there is no underscore, the name follows the type. */
414 substitute_type (struct pr_handle
*info
, const char *s
)
418 assert (info
->stack
!= NULL
);
420 u
= strchr (info
->stack
->type
, '|');
425 n
= (char *) xmalloc (strlen (info
->stack
->type
) + strlen (s
));
427 memcpy (n
, info
->stack
->type
, u
- info
->stack
->type
);
428 strcpy (n
+ (u
- info
->stack
->type
), s
);
431 free (info
->stack
->type
);
432 info
->stack
->type
= n
;
437 if (strchr (s
, '|') != NULL
438 && (strchr (info
->stack
->type
, '{') != NULL
439 || strchr (info
->stack
->type
, '(') != NULL
))
441 if (! prepend_type (info
, "(")
442 || ! append_type (info
, ")"))
449 return (append_type (info
, " ")
450 && append_type (info
, s
));
453 /* Indent the type at the top of the stack by appending spaces. */
456 indent_type (struct pr_handle
*info
)
460 for (i
= 0; i
< info
->indent
; i
++)
462 if (! append_type (info
, " "))
469 /* Pop a type from the type stack. */
472 pop_type (struct pr_handle
*info
)
477 assert (info
->stack
!= NULL
);
480 info
->stack
= o
->next
;
487 /* Print a VMA value into a string. */
490 print_vma (bfd_vma vma
, char *buf
, bfd_boolean unsignedp
, bfd_boolean hexp
)
492 if (sizeof (vma
) <= sizeof (unsigned long))
495 sprintf (buf
, "0x%lx", (unsigned long) vma
);
497 sprintf (buf
, "%lu", (unsigned long) vma
);
499 sprintf (buf
, "%ld", (long) vma
);
501 #if BFD_HOST_64BIT_LONG_LONG
502 else if (sizeof (vma
) <= sizeof (unsigned long long))
506 sprintf (buf
, "0x%llx", (unsigned long long) vma
);
508 sprintf (buf
, "%llu", (unsigned long long) vma
);
510 sprintf (buf
, "%lld", (long long) vma
);
513 sprintf (buf
, "0x%I64x", (unsigned long long) vma
);
515 sprintf (buf
, "%I64u", (unsigned long long) vma
);
517 sprintf (buf
, "%I64d", (long long) vma
);
525 sprintf_vma (buf
+ 2, vma
);
529 /* Start a new compilation unit. */
532 pr_start_compilation_unit (void *p
, const char *filename
)
534 struct pr_handle
*info
= (struct pr_handle
*) p
;
536 assert (info
->indent
== 0);
538 fprintf (info
->f
, "%s:\n", filename
);
543 /* Start a source file within a compilation unit. */
546 pr_start_source (void *p
, const char *filename
)
548 struct pr_handle
*info
= (struct pr_handle
*) p
;
550 assert (info
->indent
== 0);
552 fprintf (info
->f
, " %s:\n", filename
);
557 /* Push an empty type onto the type stack. */
560 pr_empty_type (void *p
)
562 struct pr_handle
*info
= (struct pr_handle
*) p
;
564 return push_type (info
, "<undefined>");
567 /* Push a void type onto the type stack. */
570 pr_void_type (void *p
)
572 struct pr_handle
*info
= (struct pr_handle
*) p
;
574 return push_type (info
, "void");
577 /* Push an integer type onto the type stack. */
580 pr_int_type (void *p
, unsigned int size
, bfd_boolean unsignedp
)
582 struct pr_handle
*info
= (struct pr_handle
*) p
;
585 sprintf (ab
, "%sint%d", unsignedp
? "u" : "", size
* 8);
586 return push_type (info
, ab
);
589 /* Push a floating type onto the type stack. */
592 pr_float_type (void *p
, unsigned int size
)
594 struct pr_handle
*info
= (struct pr_handle
*) p
;
598 return push_type (info
, "float");
600 return push_type (info
, "double");
602 sprintf (ab
, "float%d", size
* 8);
603 return push_type (info
, ab
);
606 /* Push a complex type onto the type stack. */
609 pr_complex_type (void *p
, unsigned int size
)
611 struct pr_handle
*info
= (struct pr_handle
*) p
;
613 if (! pr_float_type (p
, size
))
616 return prepend_type (info
, "complex ");
619 /* Push a bfd_boolean type onto the type stack. */
622 pr_bool_type (void *p
, unsigned int size
)
624 struct pr_handle
*info
= (struct pr_handle
*) p
;
627 sprintf (ab
, "bool%d", size
* 8);
629 return push_type (info
, ab
);
632 /* Push an enum type onto the type stack. */
635 pr_enum_type (void *p
, const char *tag
, const char **names
,
636 bfd_signed_vma
*values
)
638 struct pr_handle
*info
= (struct pr_handle
*) p
;
642 if (! push_type (info
, "enum "))
646 if (! append_type (info
, tag
)
647 || ! append_type (info
, " "))
650 if (! append_type (info
, "{ "))
655 if (! append_type (info
, "/* undefined */"))
661 for (i
= 0; names
[i
] != NULL
; i
++)
665 if (! append_type (info
, ", "))
669 if (! append_type (info
, names
[i
]))
672 if (values
[i
] != val
)
676 print_vma (values
[i
], ab
, FALSE
, FALSE
);
677 if (! append_type (info
, " = ")
678 || ! append_type (info
, ab
))
687 return append_type (info
, " }");
690 /* Turn the top type on the stack into a pointer. */
693 pr_pointer_type (void *p
)
695 struct pr_handle
*info
= (struct pr_handle
*) p
;
698 assert (info
->stack
!= NULL
);
700 s
= strchr (info
->stack
->type
, '|');
701 if (s
!= NULL
&& s
[1] == '[')
702 return substitute_type (info
, "(*|)");
703 return substitute_type (info
, "*|");
706 /* Turn the top type on the stack into a function returning that type. */
709 pr_function_type (void *p
, int argcount
, bfd_boolean varargs
)
711 struct pr_handle
*info
= (struct pr_handle
*) p
;
716 assert (info
->stack
!= NULL
);
729 arg_types
= (char **) xmalloc (argcount
* sizeof *arg_types
);
730 for (i
= argcount
- 1; i
>= 0; i
--)
732 if (! substitute_type (info
, ""))
737 arg_types
[i
] = pop_type (info
);
738 if (arg_types
[i
] == NULL
)
743 len
+= strlen (arg_types
[i
]) + 2;
749 /* Now the return type is on the top of the stack. */
751 s
= (char *) xmalloc (len
);
752 LITSTRCPY (s
, "(|) (");
755 strcat (s
, "/* unknown */");
760 for (i
= 0; i
< argcount
; i
++)
764 strcat (s
, arg_types
[i
]);
778 if (! substitute_type (info
, s
))
786 /* Turn the top type on the stack into a reference to that type. */
789 pr_reference_type (void *p
)
791 struct pr_handle
*info
= (struct pr_handle
*) p
;
793 assert (info
->stack
!= NULL
);
795 return substitute_type (info
, "&|");
798 /* Make a range type. */
801 pr_range_type (void *p
, bfd_signed_vma lower
, bfd_signed_vma upper
)
803 struct pr_handle
*info
= (struct pr_handle
*) p
;
804 char abl
[20], abu
[20];
806 assert (info
->stack
!= NULL
);
808 if (! substitute_type (info
, ""))
811 print_vma (lower
, abl
, FALSE
, FALSE
);
812 print_vma (upper
, abu
, FALSE
, FALSE
);
814 return (prepend_type (info
, "range (")
815 && append_type (info
, "):")
816 && append_type (info
, abl
)
817 && append_type (info
, ":")
818 && append_type (info
, abu
));
821 /* Make an array type. */
824 pr_array_type (void *p
, bfd_signed_vma lower
, bfd_signed_vma upper
,
827 struct pr_handle
*info
= (struct pr_handle
*) p
;
829 char abl
[20], abu
[20], ab
[50];
831 range_type
= pop_type (info
);
832 if (range_type
== NULL
)
841 print_vma (upper
+ 1, abu
, FALSE
, FALSE
);
842 sprintf (ab
, "|[%s]", abu
);
847 print_vma (lower
, abl
, FALSE
, FALSE
);
848 print_vma (upper
, abu
, FALSE
, FALSE
);
849 sprintf (ab
, "|[%s:%s]", abl
, abu
);
852 if (! substitute_type (info
, ab
))
855 if (strcmp (range_type
, "int") != 0)
857 if (! append_type (info
, ":")
858 || ! append_type (info
, range_type
))
864 if (! append_type (info
, " /* string */"))
871 /* Make a set type. */
874 pr_set_type (void *p
, bfd_boolean bitstringp
)
876 struct pr_handle
*info
= (struct pr_handle
*) p
;
878 if (! substitute_type (info
, ""))
881 if (! prepend_type (info
, "set { ")
882 || ! append_type (info
, " }"))
887 if (! append_type (info
, "/* bitstring */"))
894 /* Make an offset type. */
897 pr_offset_type (void *p
)
899 struct pr_handle
*info
= (struct pr_handle
*) p
;
902 if (! substitute_type (info
, ""))
909 return (substitute_type (info
, "")
910 && prepend_type (info
, " ")
911 && prepend_type (info
, t
)
912 && append_type (info
, "::|"));
915 /* Make a method type. */
918 pr_method_type (void *p
, bfd_boolean domain
, int argcount
, bfd_boolean varargs
)
920 struct pr_handle
*info
= (struct pr_handle
*) p
;
932 if (! substitute_type (info
, ""))
934 domain_type
= pop_type (info
);
935 if (domain_type
== NULL
)
937 if (CONST_STRNEQ (domain_type
, "class ")
938 && strchr (domain_type
+ sizeof "class " - 1, ' ') == NULL
)
939 domain_type
+= sizeof "class " - 1;
940 else if (CONST_STRNEQ (domain_type
, "union class ")
941 && (strchr (domain_type
+ sizeof "union class " - 1, ' ')
943 domain_type
+= sizeof "union class " - 1;
944 len
+= strlen (domain_type
);
956 arg_types
= (char **) xmalloc (argcount
* sizeof *arg_types
);
957 for (i
= argcount
- 1; i
>= 0; i
--)
959 if (! substitute_type (info
, ""))
964 arg_types
[i
] = pop_type (info
);
965 if (arg_types
[i
] == NULL
)
970 len
+= strlen (arg_types
[i
]) + 2;
976 /* Now the return type is on the top of the stack. */
978 s
= (char *) xmalloc (len
);
982 strcpy (s
, domain_type
);
986 strcat (s
, "/* unknown */");
991 for (i
= 0; i
< argcount
; i
++)
995 strcat (s
, arg_types
[i
]);
1009 if (! substitute_type (info
, s
))
1017 /* Make a const qualified type. */
1020 pr_const_type (void *p
)
1022 struct pr_handle
*info
= (struct pr_handle
*) p
;
1024 return substitute_type (info
, "const |");
1027 /* Make a volatile qualified type. */
1030 pr_volatile_type (void *p
)
1032 struct pr_handle
*info
= (struct pr_handle
*) p
;
1034 return substitute_type (info
, "volatile |");
1037 /* Start accumulating a struct type. */
1040 pr_start_struct_type (void *p
, const char *tag
, unsigned int id
,
1041 bfd_boolean structp
, unsigned int size
)
1043 struct pr_handle
*info
= (struct pr_handle
*) p
;
1047 if (! push_type (info
, structp
? "struct " : "union "))
1051 if (! append_type (info
, tag
))
1058 sprintf (idbuf
, "%%anon%u", id
);
1059 if (! append_type (info
, idbuf
))
1063 if (! append_type (info
, " {"))
1065 if (size
!= 0 || tag
!= NULL
)
1069 if (! append_type (info
, " /*"))
1074 sprintf (ab
, " size %u", size
);
1075 if (! append_type (info
, ab
))
1080 sprintf (ab
, " id %u", id
);
1081 if (! append_type (info
, ab
))
1084 if (! append_type (info
, " */"))
1087 if (! append_type (info
, "\n"))
1090 info
->stack
->visibility
= DEBUG_VISIBILITY_PUBLIC
;
1092 return indent_type (info
);
1095 /* Output the visibility of a field in a struct. */
1098 pr_fix_visibility (struct pr_handle
*info
, enum debug_visibility visibility
)
1100 const char *s
= NULL
;
1104 assert (info
->stack
!= NULL
);
1106 if (info
->stack
->visibility
== visibility
)
1111 case DEBUG_VISIBILITY_PUBLIC
:
1114 case DEBUG_VISIBILITY_PRIVATE
:
1117 case DEBUG_VISIBILITY_PROTECTED
:
1120 case DEBUG_VISIBILITY_IGNORE
:
1128 /* Trim off a trailing space in the struct string, to make the
1129 output look a bit better, then stick on the visibility string. */
1131 t
= info
->stack
->type
;
1133 assert (t
[len
- 1] == ' ');
1136 if (! append_type (info
, s
)
1137 || ! append_type (info
, ":\n")
1138 || ! indent_type (info
))
1141 info
->stack
->visibility
= visibility
;
1146 /* Add a field to a struct type. */
1149 pr_struct_field (void *p
, const char *name
, bfd_vma bitpos
, bfd_vma bitsize
,
1150 enum debug_visibility visibility
)
1152 struct pr_handle
*info
= (struct pr_handle
*) p
;
1156 if (! substitute_type (info
, name
))
1159 if (! append_type (info
, "; /* "))
1164 print_vma (bitsize
, ab
, TRUE
, FALSE
);
1165 if (! append_type (info
, "bitsize ")
1166 || ! append_type (info
, ab
)
1167 || ! append_type (info
, ", "))
1171 print_vma (bitpos
, ab
, TRUE
, FALSE
);
1172 if (! append_type (info
, "bitpos ")
1173 || ! append_type (info
, ab
)
1174 || ! append_type (info
, " */\n")
1175 || ! indent_type (info
))
1178 t
= pop_type (info
);
1182 if (! pr_fix_visibility (info
, visibility
))
1185 return append_type (info
, t
);
1188 /* Finish a struct type. */
1191 pr_end_struct_type (void *p
)
1193 struct pr_handle
*info
= (struct pr_handle
*) p
;
1196 assert (info
->stack
!= NULL
);
1197 assert (info
->indent
>= 2);
1201 /* Change the trailing indentation to have a close brace. */
1202 s
= info
->stack
->type
+ strlen (info
->stack
->type
) - 2;
1203 assert (s
[0] == ' ' && s
[1] == ' ' && s
[2] == '\0');
1211 /* Start a class type. */
1214 pr_start_class_type (void *p
, const char *tag
, unsigned int id
,
1215 bfd_boolean structp
, unsigned int size
,
1216 bfd_boolean vptr
, bfd_boolean ownvptr
)
1218 struct pr_handle
*info
= (struct pr_handle
*) p
;
1223 if (vptr
&& ! ownvptr
)
1225 tv
= pop_type (info
);
1230 if (! push_type (info
, structp
? "class " : "union class "))
1234 if (! append_type (info
, tag
))
1241 sprintf (idbuf
, "%%anon%u", id
);
1242 if (! append_type (info
, idbuf
))
1246 if (! append_type (info
, " {"))
1248 if (size
!= 0 || vptr
|| ownvptr
|| tag
!= NULL
)
1250 if (! append_type (info
, " /*"))
1257 sprintf (ab
, "%u", size
);
1258 if (! append_type (info
, " size ")
1259 || ! append_type (info
, ab
))
1265 if (! append_type (info
, " vtable "))
1269 if (! append_type (info
, "self "))
1274 if (! append_type (info
, tv
)
1275 || ! append_type (info
, " "))
1284 sprintf (ab
, " id %u", id
);
1285 if (! append_type (info
, ab
))
1289 if (! append_type (info
, " */"))
1293 info
->stack
->visibility
= DEBUG_VISIBILITY_PRIVATE
;
1295 return (append_type (info
, "\n")
1296 && indent_type (info
));
1299 /* Add a static member to a class. */
1302 pr_class_static_member (void *p
, const char *name
, const char *physname
,
1303 enum debug_visibility visibility
)
1305 struct pr_handle
*info
= (struct pr_handle
*) p
;
1308 if (! substitute_type (info
, name
))
1311 if (! prepend_type (info
, "static ")
1312 || ! append_type (info
, "; /* ")
1313 || ! append_type (info
, physname
)
1314 || ! append_type (info
, " */\n")
1315 || ! indent_type (info
))
1318 t
= pop_type (info
);
1322 if (! pr_fix_visibility (info
, visibility
))
1325 return append_type (info
, t
);
1328 /* Add a base class to a class. */
1331 pr_class_baseclass (void *p
, bfd_vma bitpos
, bfd_boolean is_virtual
,
1332 enum debug_visibility visibility
)
1334 struct pr_handle
*info
= (struct pr_handle
*) p
;
1340 assert (info
->stack
!= NULL
&& info
->stack
->next
!= NULL
);
1342 if (! substitute_type (info
, ""))
1345 t
= pop_type (info
);
1349 if (CONST_STRNEQ (t
, "class "))
1350 t
+= sizeof "class " - 1;
1352 /* Push it back on to take advantage of the prepend_type and
1353 append_type routines. */
1354 if (! push_type (info
, t
))
1359 if (! prepend_type (info
, "virtual "))
1365 case DEBUG_VISIBILITY_PUBLIC
:
1368 case DEBUG_VISIBILITY_PROTECTED
:
1369 prefix
= "protected ";
1371 case DEBUG_VISIBILITY_PRIVATE
:
1372 prefix
= "private ";
1375 prefix
= "/* unknown visibility */ ";
1379 if (! prepend_type (info
, prefix
))
1384 print_vma (bitpos
, ab
, TRUE
, FALSE
);
1385 if (! append_type (info
, " /* bitpos ")
1386 || ! append_type (info
, ab
)
1387 || ! append_type (info
, " */"))
1391 /* Now the top of the stack is something like "public A / * bitpos
1392 10 * /". The next element on the stack is something like "class
1393 xx { / * size 8 * /\n...". We want to substitute the top of the
1394 stack in before the {. */
1395 s
= strchr (info
->stack
->next
->type
, '{');
1399 /* If there is already a ':', then we already have a baseclass, and
1400 we must append this one after a comma. */
1401 for (l
= info
->stack
->next
->type
; l
!= s
; l
++)
1404 if (! prepend_type (info
, l
== s
? " : " : ", "))
1407 t
= pop_type (info
);
1411 n
= (char *) xmalloc (strlen (info
->stack
->type
) + strlen (t
) + 1);
1412 memcpy (n
, info
->stack
->type
, s
- info
->stack
->type
);
1413 strcpy (n
+ (s
- info
->stack
->type
), t
);
1416 free (info
->stack
->type
);
1417 info
->stack
->type
= n
;
1424 /* Start adding a method to a class. */
1427 pr_class_start_method (void *p
, const char *name
)
1429 struct pr_handle
*info
= (struct pr_handle
*) p
;
1431 assert (info
->stack
!= NULL
);
1432 info
->stack
->method
= name
;
1436 /* Add a variant to a method. */
1439 pr_class_method_variant (void *p
, const char *physname
,
1440 enum debug_visibility visibility
,
1441 bfd_boolean constp
, bfd_boolean volatilep
,
1442 bfd_vma voffset
, bfd_boolean context
)
1444 struct pr_handle
*info
= (struct pr_handle
*) p
;
1448 assert (info
->stack
!= NULL
);
1449 assert (info
->stack
->next
!= NULL
);
1451 /* Put the const and volatile qualifiers on the type. */
1454 if (! append_type (info
, " volatile"))
1459 if (! append_type (info
, " const"))
1463 /* Stick the name of the method into its type. */
1464 if (! substitute_type (info
,
1466 ? info
->stack
->next
->next
->method
1467 : info
->stack
->next
->method
)))
1471 method_type
= pop_type (info
);
1472 if (method_type
== NULL
)
1475 /* Pull off the context type if there is one. */
1477 context_type
= NULL
;
1480 context_type
= pop_type (info
);
1481 if (context_type
== NULL
)
1485 /* Now the top of the stack is the class. */
1487 if (! pr_fix_visibility (info
, visibility
))
1490 if (! append_type (info
, method_type
)
1491 || ! append_type (info
, " /* ")
1492 || ! append_type (info
, physname
)
1493 || ! append_type (info
, " "))
1495 if (context
|| voffset
!= 0)
1501 if (! append_type (info
, "context ")
1502 || ! append_type (info
, context_type
)
1503 || ! append_type (info
, " "))
1506 print_vma (voffset
, ab
, TRUE
, FALSE
);
1507 if (! append_type (info
, "voffset ")
1508 || ! append_type (info
, ab
))
1512 return (append_type (info
, " */;\n")
1513 && indent_type (info
));
1516 /* Add a static variant to a method. */
1519 pr_class_static_method_variant (void *p
, const char *physname
,
1520 enum debug_visibility visibility
,
1521 bfd_boolean constp
, bfd_boolean volatilep
)
1523 struct pr_handle
*info
= (struct pr_handle
*) p
;
1526 assert (info
->stack
!= NULL
);
1527 assert (info
->stack
->next
!= NULL
);
1528 assert (info
->stack
->next
->method
!= NULL
);
1530 /* Put the const and volatile qualifiers on the type. */
1533 if (! append_type (info
, " volatile"))
1538 if (! append_type (info
, " const"))
1542 /* Mark it as static. */
1543 if (! prepend_type (info
, "static "))
1546 /* Stick the name of the method into its type. */
1547 if (! substitute_type (info
, info
->stack
->next
->method
))
1551 method_type
= pop_type (info
);
1552 if (method_type
== NULL
)
1555 /* Now the top of the stack is the class. */
1557 if (! pr_fix_visibility (info
, visibility
))
1560 return (append_type (info
, method_type
)
1561 && append_type (info
, " /* ")
1562 && append_type (info
, physname
)
1563 && append_type (info
, " */;\n")
1564 && indent_type (info
));
1567 /* Finish up a method. */
1570 pr_class_end_method (void *p
)
1572 struct pr_handle
*info
= (struct pr_handle
*) p
;
1574 info
->stack
->method
= NULL
;
1578 /* Finish up a class. */
1581 pr_end_class_type (void *p
)
1583 return pr_end_struct_type (p
);
1586 /* Push a type on the stack using a typedef name. */
1589 pr_typedef_type (void *p
, const char *name
)
1591 struct pr_handle
*info
= (struct pr_handle
*) p
;
1593 return push_type (info
, name
);
1596 /* Push a type on the stack using a tag name. */
1599 pr_tag_type (void *p
, const char *name
, unsigned int id
,
1600 enum debug_type_kind kind
)
1602 struct pr_handle
*info
= (struct pr_handle
*) p
;
1603 const char *t
, *tag
;
1608 case DEBUG_KIND_STRUCT
:
1611 case DEBUG_KIND_UNION
:
1614 case DEBUG_KIND_ENUM
:
1617 case DEBUG_KIND_CLASS
:
1620 case DEBUG_KIND_UNION_CLASS
:
1628 if (! push_type (info
, t
))
1634 sprintf (idbuf
, "%%anon%u", id
);
1638 if (! append_type (info
, tag
))
1640 if (name
!= NULL
&& kind
!= DEBUG_KIND_ENUM
)
1642 sprintf (idbuf
, " /* id %u */", id
);
1643 if (! append_type (info
, idbuf
))
1650 /* Output a typedef. */
1653 pr_typdef (void *p
, const char *name
)
1655 struct pr_handle
*info
= (struct pr_handle
*) p
;
1658 if (! substitute_type (info
, name
))
1661 s
= pop_type (info
);
1666 fprintf (info
->f
, "typedef %s;\n", s
);
1673 /* Output a tag. The tag should already be in the string on the
1674 stack, so all we have to do here is print it out. */
1677 pr_tag (void *p
, const char *name ATTRIBUTE_UNUSED
)
1679 struct pr_handle
*info
= (struct pr_handle
*) p
;
1682 t
= pop_type (info
);
1687 fprintf (info
->f
, "%s;\n", t
);
1694 /* Output an integer constant. */
1697 pr_int_constant (void *p
, const char *name
, bfd_vma val
)
1699 struct pr_handle
*info
= (struct pr_handle
*) p
;
1703 print_vma (val
, ab
, FALSE
, FALSE
);
1704 fprintf (info
->f
, "const int %s = %s;\n", name
, ab
);
1708 /* Output a floating point constant. */
1711 pr_float_constant (void *p
, const char *name
, double val
)
1713 struct pr_handle
*info
= (struct pr_handle
*) p
;
1716 fprintf (info
->f
, "const double %s = %g;\n", name
, val
);
1720 /* Output a typed constant. */
1723 pr_typed_constant (void *p
, const char *name
, bfd_vma val
)
1725 struct pr_handle
*info
= (struct pr_handle
*) p
;
1729 t
= pop_type (info
);
1734 print_vma (val
, ab
, FALSE
, FALSE
);
1735 fprintf (info
->f
, "const %s %s = %s;\n", t
, name
, ab
);
1742 /* Output a variable. */
1745 pr_variable (void *p
, const char *name
, enum debug_var_kind kind
,
1748 struct pr_handle
*info
= (struct pr_handle
*) p
;
1752 if (! substitute_type (info
, name
))
1755 t
= pop_type (info
);
1763 case DEBUG_LOCAL_STATIC
:
1764 fprintf (info
->f
, "static ");
1766 case DEBUG_REGISTER
:
1767 fprintf (info
->f
, "register ");
1772 print_vma (val
, ab
, TRUE
, TRUE
);
1773 fprintf (info
->f
, "%s /* %s */;\n", t
, ab
);
1780 /* Start outputting a function. */
1783 pr_start_function (void *p
, const char *name
, bfd_boolean global
)
1785 struct pr_handle
*info
= (struct pr_handle
*) p
;
1788 if (! substitute_type (info
, name
))
1791 t
= pop_type (info
);
1797 fprintf (info
->f
, "static ");
1798 fprintf (info
->f
, "%s (", t
);
1800 info
->parameter
= 1;
1805 /* Output a function parameter. */
1808 pr_function_parameter (void *p
, const char *name
,
1809 enum debug_parm_kind kind
, bfd_vma val
)
1811 struct pr_handle
*info
= (struct pr_handle
*) p
;
1815 if (kind
== DEBUG_PARM_REFERENCE
1816 || kind
== DEBUG_PARM_REF_REG
)
1818 if (! pr_reference_type (p
))
1822 if (! substitute_type (info
, name
))
1825 t
= pop_type (info
);
1829 if (info
->parameter
!= 1)
1830 fprintf (info
->f
, ", ");
1832 if (kind
== DEBUG_PARM_REG
|| kind
== DEBUG_PARM_REF_REG
)
1833 fprintf (info
->f
, "register ");
1835 print_vma (val
, ab
, TRUE
, TRUE
);
1836 fprintf (info
->f
, "%s /* %s */", t
, ab
);
1845 /* Start writing out a block. */
1848 pr_start_block (void *p
, bfd_vma addr
)
1850 struct pr_handle
*info
= (struct pr_handle
*) p
;
1853 if (info
->parameter
> 0)
1855 fprintf (info
->f
, ")\n");
1856 info
->parameter
= 0;
1860 print_vma (addr
, ab
, TRUE
, TRUE
);
1861 fprintf (info
->f
, "{ /* %s */\n", ab
);
1868 /* Write out line number information. */
1871 pr_lineno (void *p
, const char *filename
, unsigned long lineno
, bfd_vma addr
)
1873 struct pr_handle
*info
= (struct pr_handle
*) p
;
1877 print_vma (addr
, ab
, TRUE
, TRUE
);
1878 fprintf (info
->f
, "/* file %s line %lu addr %s */\n", filename
, lineno
, ab
);
1883 /* Finish writing out a block. */
1886 pr_end_block (void *p
, bfd_vma addr
)
1888 struct pr_handle
*info
= (struct pr_handle
*) p
;
1894 print_vma (addr
, ab
, TRUE
, TRUE
);
1895 fprintf (info
->f
, "} /* %s */\n", ab
);
1900 /* Finish writing out a function. */
1903 pr_end_function (void *p ATTRIBUTE_UNUSED
)
1908 /* Tags style generation functions start here. */
1910 /* Variables for address to line translation. */
1912 static const char *filename
;
1913 static const char *functionname
;
1914 static unsigned int line
;
1915 static bfd_boolean found
;
1917 /* Look for an address in a section. This is called via
1918 bfd_map_over_sections. */
1921 find_address_in_section (bfd
*abfd
, asection
*section
, void *data
)
1925 asymbol
**syms
= (asymbol
**) data
;
1930 if ((bfd_get_section_flags (abfd
, section
) & SEC_ALLOC
) == 0)
1933 vma
= bfd_get_section_vma (abfd
, section
);
1937 size
= bfd_get_section_size (section
);
1938 if (pc
>= vma
+ size
)
1941 found
= bfd_find_nearest_line (abfd
, section
, syms
, pc
- vma
,
1942 &filename
, &functionname
, &line
);
1946 translate_addresses (bfd
*abfd
, char *addr_hex
, FILE *f
, asymbol
**syms
)
1948 pc
= bfd_scan_vma (addr_hex
, NULL
, 16);
1950 bfd_map_over_sections (abfd
, find_address_in_section
, syms
);
1955 fprintf (f
, "%u", line
);
1958 /* Start a new compilation unit. */
1961 tg_start_compilation_unit (void * p
, const char *fname ATTRIBUTE_UNUSED
)
1963 struct pr_handle
*info
= (struct pr_handle
*) p
;
1965 free (info
->filename
);
1966 /* Should it be relative? best way to do it here?. */
1967 info
->filename
= strdup (fname
);
1972 /* Start a source file within a compilation unit. */
1975 tg_start_source (void *p
, const char *fname
)
1977 struct pr_handle
*info
= (struct pr_handle
*) p
;
1979 free (info
->filename
);
1980 /* Should it be relative? best way to do it here?. */
1981 info
->filename
= strdup (fname
);
1986 /* Push an enum type onto the type stack. */
1989 tg_enum_type (void *p
, const char *tag
, const char **names
,
1990 bfd_signed_vma
*values
)
1992 struct pr_handle
*info
= (struct pr_handle
*) p
;
1997 if (! pr_enum_type (p
, tag
, names
, values
))
2000 name
= tag
? tag
: "unknown";
2001 /* Generate an entry for the enum. */
2003 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:e\ttype:%s\n", tag
,
2004 info
->filename
, info
->stack
->type
);
2006 /* Generate entries for the values. */
2009 for (i
= 0; names
[i
] != NULL
; i
++)
2011 print_vma (values
[i
], ab
, FALSE
, FALSE
);
2012 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:g\tenum:%s\tvalue:%s\n",
2013 names
[i
], info
->filename
, name
, ab
);
2020 /* Start accumulating a struct type. */
2023 tg_start_struct_type (void *p
, const char *tag
, unsigned int id
,
2024 bfd_boolean structp
,
2025 unsigned int size ATTRIBUTE_UNUSED
)
2027 struct pr_handle
*info
= (struct pr_handle
*) p
;
2036 sprintf (idbuf
, "%%anon%u", id
);
2039 if (! push_type (info
, name
))
2042 info
->stack
->flavor
= structp
? "struct" : "union";
2044 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:%c\n", name
, info
->filename
,
2045 info
->stack
->flavor
[0]);
2047 info
->stack
->visibility
= DEBUG_VISIBILITY_PUBLIC
;
2049 return indent_type (info
);
2052 /* Output the visibility of a field in a struct. */
2055 tg_fix_visibility (struct pr_handle
*info
, enum debug_visibility visibility
)
2057 assert (info
->stack
!= NULL
);
2059 if (info
->stack
->visibility
== visibility
)
2062 assert (info
->stack
->visibility
!= DEBUG_VISIBILITY_IGNORE
);
2064 info
->stack
->visibility
= visibility
;
2069 /* Add a field to a struct type. */
2072 tg_struct_field (void *p
, const char *name
, bfd_vma bitpos ATTRIBUTE_UNUSED
,
2073 bfd_vma bitsize ATTRIBUTE_UNUSED
,
2074 enum debug_visibility visibility
)
2076 struct pr_handle
*info
= (struct pr_handle
*) p
;
2079 t
= pop_type (info
);
2083 if (! tg_fix_visibility (info
, visibility
))
2086 /* It happens, a bug? */
2090 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:m\ttype:%s\t%s:%s\taccess:%s\n",
2091 name
, info
->filename
, t
, info
->stack
->flavor
, info
->stack
->type
,
2092 visibility_name (visibility
));
2097 /* Finish a struct type. */
2100 tg_end_struct_type (void *p ATTRIBUTE_UNUSED
)
2102 assert (((struct pr_handle
*) p
)->stack
!= NULL
);
2107 /* Start a class type. */
2110 tg_start_class_type (void *p
, const char *tag
, unsigned int id
,
2111 bfd_boolean structp
, unsigned int size
,
2112 bfd_boolean vptr
, bfd_boolean ownvptr
)
2114 struct pr_handle
*info
= (struct pr_handle
*) p
;
2120 if (vptr
&& ! ownvptr
)
2122 tv
= pop_type (info
);
2133 sprintf (idbuf
, "%%anon%u", id
);
2137 if (! push_type (info
, name
))
2140 info
->stack
->flavor
= structp
? "class" : "union class";
2141 info
->stack
->parents
= NULL
;
2142 info
->stack
->num_parents
= 0;
2144 if (size
!= 0 || vptr
|| ownvptr
|| tag
!= NULL
)
2148 if (! append_type (info
, " vtable "))
2152 if (! append_type (info
, "self "))
2157 if (! append_type (info
, tv
)
2158 || ! append_type (info
, " "))
2164 info
->stack
->visibility
= DEBUG_VISIBILITY_PRIVATE
;
2169 /* Add a static member to a class. */
2172 tg_class_static_member (void *p
, const char *name
,
2173 const char *physname ATTRIBUTE_UNUSED
,
2174 enum debug_visibility visibility
)
2176 struct pr_handle
*info
= (struct pr_handle
*) p
;
2178 int len_var
, len_class
;
2181 len_var
= strlen (name
);
2182 len_class
= strlen (info
->stack
->next
->type
);
2183 full_name
= (char *) xmalloc (len_var
+ len_class
+ 3);
2186 sprintf (full_name
, "%s::%s", info
->stack
->next
->type
, name
);
2188 if (! substitute_type (info
, full_name
))
2194 if (! prepend_type (info
, "static "))
2200 t
= pop_type (info
);
2207 if (! tg_fix_visibility (info
, visibility
))
2214 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:x\ttype:%s\tclass:%s\taccess:%s\n",
2215 name
, info
->filename
, t
, info
->stack
->type
,
2216 visibility_name (visibility
));
2223 /* Add a base class to a class. */
2226 tg_class_baseclass (void *p
, bfd_vma bitpos ATTRIBUTE_UNUSED
,
2227 bfd_boolean is_virtual
, enum debug_visibility visibility
)
2229 struct pr_handle
*info
= (struct pr_handle
*) p
;
2233 assert (info
->stack
!= NULL
&& info
->stack
->next
!= NULL
);
2235 t
= pop_type (info
);
2239 if (CONST_STRNEQ (t
, "class "))
2240 t
+= sizeof "class " - 1;
2242 /* Push it back on to take advantage of the prepend_type and
2243 append_type routines. */
2244 if (! push_type (info
, t
))
2249 if (! prepend_type (info
, "virtual "))
2255 case DEBUG_VISIBILITY_PUBLIC
:
2258 case DEBUG_VISIBILITY_PROTECTED
:
2259 prefix
= "protected ";
2261 case DEBUG_VISIBILITY_PRIVATE
:
2262 prefix
= "private ";
2265 prefix
= "/* unknown visibility */ ";
2269 if (! prepend_type (info
, prefix
))
2272 t
= pop_type (info
);
2276 if (info
->stack
->num_parents
&& ! append_parent (info
, ", "))
2279 if (! append_parent (info
, t
))
2281 info
->stack
->num_parents
++;
2288 /* Add a variant to a method. */
2291 tg_class_method_variant (void *p
, const char *physname ATTRIBUTE_UNUSED
,
2292 enum debug_visibility visibility
,
2293 bfd_boolean constp
, bfd_boolean volatilep
,
2294 bfd_vma voffset ATTRIBUTE_UNUSED
,
2295 bfd_boolean context
)
2297 struct pr_handle
*info
= (struct pr_handle
*) p
;
2302 assert (info
->stack
!= NULL
);
2303 assert (info
->stack
->next
!= NULL
);
2305 /* Put the const and volatile qualifiers on the type. */
2308 if (! append_type (info
, " volatile"))
2313 if (! append_type (info
, " const"))
2317 method_name
= strdup (context
? info
->stack
->next
->next
->method
2318 : info
->stack
->next
->method
);
2320 /* Stick the name of the method into its type. */
2321 if (! substitute_type (info
, method_name
))
2328 method_type
= pop_type (info
);
2329 if (method_type
== NULL
)
2335 /* Pull off the context type if there is one. */
2337 context_type
= NULL
;
2340 context_type
= pop_type (info
);
2341 if (context_type
== NULL
)
2349 /* Now the top of the stack is the class. */
2350 if (! tg_fix_visibility (info
, visibility
))
2354 free (context_type
);
2358 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:p\ttype:%s\tclass:%s\n",
2359 method_name
, info
->filename
, method_type
, info
->stack
->type
);
2362 free (context_type
);
2367 /* Add a static variant to a method. */
2370 tg_class_static_method_variant (void *p
,
2371 const char *physname ATTRIBUTE_UNUSED
,
2372 enum debug_visibility visibility
,
2373 bfd_boolean constp
, bfd_boolean volatilep
)
2375 struct pr_handle
*info
= (struct pr_handle
*) p
;
2379 assert (info
->stack
!= NULL
);
2380 assert (info
->stack
->next
!= NULL
);
2381 assert (info
->stack
->next
->method
!= NULL
);
2383 /* Put the const and volatile qualifiers on the type. */
2386 if (! append_type (info
, " volatile"))
2391 if (! append_type (info
, " const"))
2395 /* Mark it as static. */
2396 if (! prepend_type (info
, "static "))
2399 method_name
= strdup (info
->stack
->next
->method
);
2400 /* Stick the name of the method into its type. */
2401 if (! substitute_type (info
, info
->stack
->next
->method
))
2408 method_type
= pop_type (info
);
2409 if (method_type
== NULL
)
2415 /* Now the top of the stack is the class. */
2416 if (! tg_fix_visibility (info
, visibility
))
2423 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:p\ttype:%s\tclass:%s\taccess:%s\n",
2424 method_name
, info
->filename
, method_type
, info
->stack
->type
,
2425 visibility_name (visibility
));
2432 /* Finish up a class. */
2435 tg_end_class_type (void *p
)
2437 struct pr_handle
*info
= (struct pr_handle
*) p
;
2439 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:c\ttype:%s", info
->stack
->type
,
2440 info
->filename
, info
->stack
->flavor
);
2441 if (info
->stack
->num_parents
)
2443 fprintf (info
->f
, "\tinherits:%s", info
->stack
->parents
);
2444 free (info
->stack
->parents
);
2446 fputc ('\n', info
->f
);
2448 return tg_end_struct_type (p
);
2451 /* Push a type on the stack using a tag name. */
2454 tg_tag_type (void *p
, const char *name
, unsigned int id
,
2455 enum debug_type_kind kind
)
2457 struct pr_handle
*info
= (struct pr_handle
*) p
;
2458 const char *t
, *tag
;
2463 case DEBUG_KIND_STRUCT
:
2466 case DEBUG_KIND_UNION
:
2469 case DEBUG_KIND_ENUM
:
2472 case DEBUG_KIND_CLASS
:
2475 case DEBUG_KIND_UNION_CLASS
:
2483 if (! push_type (info
, t
))
2489 sprintf (idbuf
, "%%anon%u", id
);
2493 if (! append_type (info
, tag
))
2499 /* Output a typedef. */
2502 tg_typdef (void *p
, const char *name
)
2504 struct pr_handle
*info
= (struct pr_handle
*) p
;
2507 s
= pop_type (info
);
2511 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:t\ttype:%s\n", name
,
2519 /* Output a tag. The tag should already be in the string on the
2520 stack, so all we have to do here is print it out. */
2523 tg_tag (void *p ATTRIBUTE_UNUSED
, const char *name ATTRIBUTE_UNUSED
)
2525 struct pr_handle
*info
= (struct pr_handle
*) p
;
2528 t
= pop_type (info
);
2536 /* Output an integer constant. */
2539 tg_int_constant (void *p
, const char *name
, bfd_vma val
)
2541 struct pr_handle
*info
= (struct pr_handle
*) p
;
2545 print_vma (val
, ab
, FALSE
, FALSE
);
2546 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:v\ttype:const int\tvalue:%s\n",
2547 name
, info
->filename
, ab
);
2551 /* Output a floating point constant. */
2554 tg_float_constant (void *p
, const char *name
, double val
)
2556 struct pr_handle
*info
= (struct pr_handle
*) p
;
2559 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:v\ttype:const double\tvalue:%g\n",
2560 name
, info
->filename
, val
);
2564 /* Output a typed constant. */
2567 tg_typed_constant (void *p
, const char *name
, bfd_vma val
)
2569 struct pr_handle
*info
= (struct pr_handle
*) p
;
2573 t
= pop_type (info
);
2578 print_vma (val
, ab
, FALSE
, FALSE
);
2579 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:v\ttype:const %s\tvalue:%s\n",
2580 name
, info
->filename
, t
, ab
);
2587 /* Output a variable. */
2590 tg_variable (void *p
, const char *name
, enum debug_var_kind kind
,
2591 bfd_vma val ATTRIBUTE_UNUSED
)
2593 struct pr_handle
*info
= (struct pr_handle
*) p
;
2594 char *t
, *dname
, *from_class
;
2596 t
= pop_type (info
);
2601 if (info
->demangler
)
2602 dname
= info
->demangler (info
->abfd
, name
, DMGL_ANSI
| DMGL_PARAMS
);
2608 sep
= strstr (dname
, "::");
2616 /* Obscure types as vts and type_info nodes. */
2620 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:v\ttype:%s", name
, info
->filename
, t
);
2625 case DEBUG_LOCAL_STATIC
:
2626 fprintf (info
->f
, "\tfile:");
2628 case DEBUG_REGISTER
:
2629 fprintf (info
->f
, "\tregister:");
2636 fprintf (info
->f
, "\tclass:%s", from_class
);
2641 fprintf (info
->f
, "\n");
2648 /* Start outputting a function. */
2651 tg_start_function (void *p
, const char *name
, bfd_boolean global
)
2653 struct pr_handle
*info
= (struct pr_handle
*) p
;
2657 info
->stack
->flavor
= "static";
2659 info
->stack
->flavor
= NULL
;
2662 if (info
->demangler
)
2663 dname
= info
->demangler (info
->abfd
, name
, DMGL_ANSI
| DMGL_PARAMS
);
2665 if (! substitute_type (info
, dname
? dname
: name
))
2668 info
->stack
->method
= NULL
;
2672 sep
= strstr (dname
, "::");
2675 info
->stack
->method
= dname
;
2681 info
->stack
->method
= "";
2684 sep
= strchr (name
, '(');
2687 /* Obscure functions as type_info function. */
2690 info
->stack
->parents
= strdup (name
);
2692 if (! info
->stack
->method
&& ! append_type (info
, "("))
2695 info
->parameter
= 1;
2700 /* Output a function parameter. */
2703 tg_function_parameter (void *p
, const char *name
, enum debug_parm_kind kind
,
2704 bfd_vma val ATTRIBUTE_UNUSED
)
2706 struct pr_handle
*info
= (struct pr_handle
*) p
;
2709 if (kind
== DEBUG_PARM_REFERENCE
2710 || kind
== DEBUG_PARM_REF_REG
)
2712 if (! pr_reference_type (p
))
2716 if (! substitute_type (info
, name
))
2719 t
= pop_type (info
);
2723 if (! info
->stack
->method
)
2725 if (info
->parameter
!= 1 && ! append_type (info
, ", "))
2728 if (kind
== DEBUG_PARM_REG
|| kind
== DEBUG_PARM_REF_REG
)
2729 if (! append_type (info
, "register "))
2732 if (! append_type (info
, t
))
2743 /* Start writing out a block. */
2746 tg_start_block (void *p
, bfd_vma addr
)
2748 struct pr_handle
*info
= (struct pr_handle
*) p
;
2749 char ab
[20], kind
, *partof
;
2753 if (info
->parameter
> 0)
2755 info
->parameter
= 0;
2758 fprintf (info
->f
, "%s\t%s\t", info
->stack
->parents
, info
->filename
);
2759 free (info
->stack
->parents
);
2761 print_vma (addr
, ab
, TRUE
, TRUE
);
2762 translate_addresses (info
->abfd
, ab
, info
->f
, info
->syms
);
2763 local
= info
->stack
->flavor
!= NULL
;
2764 if (info
->stack
->method
&& *info
->stack
->method
)
2767 partof
= (char *) info
->stack
->method
;
2773 if (! info
->stack
->method
&& ! append_type (info
, ")"))
2776 t
= pop_type (info
);
2779 fprintf (info
->f
, ";\"\tkind:%c\ttype:%s", kind
, t
);
2781 fputs ("\tfile:", info
->f
);
2784 fprintf (info
->f
, "\tclass:%s", partof
);
2787 fputc ('\n', info
->f
);
2793 /* Write out line number information. */
2796 tg_lineno (void *p ATTRIBUTE_UNUSED
, const char *fname ATTRIBUTE_UNUSED
,
2797 unsigned long lineno ATTRIBUTE_UNUSED
,
2798 bfd_vma addr ATTRIBUTE_UNUSED
)
2803 /* Finish writing out a block. */
2806 tg_end_block (void *p ATTRIBUTE_UNUSED
, bfd_vma addr ATTRIBUTE_UNUSED
)
2811 /* Convert the visibility value into a human readable name. */
2814 visibility_name (enum debug_visibility visibility
)
2820 case DEBUG_VISIBILITY_PUBLIC
:
2823 case DEBUG_VISIBILITY_PRIVATE
:
2826 case DEBUG_VISIBILITY_PROTECTED
:
2829 case DEBUG_VISIBILITY_IGNORE
: