1 /* prdbg.c -- Print out generic debugging information.
2 Copyright 1995, 1996, 1999, 2002, 2003, 2004, 2006, 2007, 2008
3 Free Software Foundation, Inc.
4 Written by Ian Lance Taylor <ian@cygnus.com>.
5 Tags style generation written by Salvador E. Tropea <set@computer.org>.
7 This file is part of GNU Binutils.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
24 /* This file prints out the generic debugging information, by
25 supplying a set of routines to debug_write. */
30 #include "libiberty.h"
35 /* This is the structure we use as a handle for these routines. */
39 /* File to print information to. */
41 /* Current indentation level. */
44 struct pr_stack
*stack
;
45 /* Parameter number we are about to output. */
47 /* The following are used only by the tags code (tg_). */
48 /* Name of the file we are using. */
52 /* The symbols table for this BFD. */
54 /* Pointer to a function to demangle symbols. */
55 char *(*demangler
) (bfd
*, const char *, int);
62 /* Next element on the stack. */
63 struct pr_stack
*next
;
66 /* Current visibility of fields if this is a class. */
67 enum debug_visibility visibility
;
68 /* Name of the current method we are handling. */
70 /* The following are used only by the tags code (tg_). */
71 /* Type for the container (struct, union, class, union class). */
73 /* A comma separated list of parent classes. */
75 /* How many parents contains parents. */
79 static void indent (struct pr_handle
*);
80 static bfd_boolean
push_type (struct pr_handle
*, const char *);
81 static bfd_boolean
prepend_type (struct pr_handle
*, const char *);
82 static bfd_boolean
append_type (struct pr_handle
*, const char *);
83 static bfd_boolean
substitute_type (struct pr_handle
*, const char *);
84 static bfd_boolean
indent_type (struct pr_handle
*);
85 static char *pop_type (struct pr_handle
*);
86 static void print_vma (bfd_vma
, char *, bfd_boolean
, bfd_boolean
);
87 static bfd_boolean pr_fix_visibility
88 (struct pr_handle
*, enum debug_visibility
);
89 static bfd_boolean
pr_start_compilation_unit (void *, const char *);
90 static bfd_boolean
pr_start_source (void *, const char *);
91 static bfd_boolean
pr_empty_type (void *);
92 static bfd_boolean
pr_void_type (void *);
93 static bfd_boolean
pr_int_type (void *, unsigned int, bfd_boolean
);
94 static bfd_boolean
pr_float_type (void *, unsigned int);
95 static bfd_boolean
pr_complex_type (void *, unsigned int);
96 static bfd_boolean
pr_bool_type (void *, unsigned int);
97 static bfd_boolean pr_enum_type
98 (void *, const char *, const char **, bfd_signed_vma
*);
99 static bfd_boolean
pr_pointer_type (void *);
100 static bfd_boolean
pr_function_type (void *, int, bfd_boolean
);
101 static bfd_boolean
pr_reference_type (void *);
102 static bfd_boolean
pr_range_type (void *, bfd_signed_vma
, bfd_signed_vma
);
103 static bfd_boolean pr_array_type
104 (void *, bfd_signed_vma
, bfd_signed_vma
, bfd_boolean
);
105 static bfd_boolean
pr_set_type (void *, bfd_boolean
);
106 static bfd_boolean
pr_offset_type (void *);
107 static bfd_boolean
pr_method_type (void *, bfd_boolean
, int, bfd_boolean
);
108 static bfd_boolean
pr_const_type (void *);
109 static bfd_boolean
pr_volatile_type (void *);
110 static bfd_boolean pr_start_struct_type
111 (void *, const char *, unsigned int, bfd_boolean
, unsigned int);
112 static bfd_boolean pr_struct_field
113 (void *, const char *, bfd_vma
, bfd_vma
, enum debug_visibility
);
114 static bfd_boolean
pr_end_struct_type (void *);
115 static bfd_boolean pr_start_class_type
116 (void *, const char *, unsigned int, bfd_boolean
, unsigned int,
117 bfd_boolean
, bfd_boolean
);
118 static bfd_boolean pr_class_static_member
119 (void *, const char *, const char *, enum debug_visibility
);
120 static bfd_boolean pr_class_baseclass
121 (void *, bfd_vma
, bfd_boolean
, enum debug_visibility
);
122 static bfd_boolean
pr_class_start_method (void *, const char *);
123 static bfd_boolean pr_class_method_variant
124 (void *, const char *, enum debug_visibility
, bfd_boolean
, bfd_boolean
,
125 bfd_vma
, bfd_boolean
);
126 static bfd_boolean pr_class_static_method_variant
127 (void *, const char *, enum debug_visibility
, bfd_boolean
, bfd_boolean
);
128 static bfd_boolean
pr_class_end_method (void *);
129 static bfd_boolean
pr_end_class_type (void *);
130 static bfd_boolean
pr_typedef_type (void *, const char *);
131 static bfd_boolean pr_tag_type
132 (void *, const char *, unsigned int, enum debug_type_kind
);
133 static bfd_boolean
pr_typdef (void *, const char *);
134 static bfd_boolean
pr_tag (void *, const char *);
135 static bfd_boolean
pr_int_constant (void *, const char *, bfd_vma
);
136 static bfd_boolean
pr_float_constant (void *, const char *, double);
137 static bfd_boolean
pr_typed_constant (void *, const char *, bfd_vma
);
138 static bfd_boolean pr_variable
139 (void *, const char *, enum debug_var_kind
, bfd_vma
);
140 static bfd_boolean
pr_start_function (void *, const char *, bfd_boolean
);
141 static bfd_boolean pr_function_parameter
142 (void *, const char *, enum debug_parm_kind
, bfd_vma
);
143 static bfd_boolean
pr_start_block (void *, bfd_vma
);
144 static bfd_boolean
pr_end_block (void *, bfd_vma
);
145 static bfd_boolean
pr_end_function (void *);
146 static bfd_boolean
pr_lineno (void *, const char *, unsigned long, bfd_vma
);
147 static bfd_boolean
append_parent (struct pr_handle
*, const char *);
148 /* Only used by tg_ code. */
149 static bfd_boolean tg_fix_visibility
150 (struct pr_handle
*, enum debug_visibility
);
151 static void find_address_in_section (bfd
*, asection
*, void *);
152 static void translate_addresses (bfd
*, char *, FILE *, asymbol
**);
153 static const char *visibility_name (enum debug_visibility
);
154 /* Tags style replacements. */
155 static bfd_boolean
tg_start_compilation_unit (void *, const char *);
156 static bfd_boolean
tg_start_source (void *, const char *);
157 static bfd_boolean tg_enum_type
158 (void *, const char *, const char **, bfd_signed_vma
*);
159 static bfd_boolean tg_start_struct_type
160 (void *, const char *, unsigned int, bfd_boolean
, unsigned int);
161 static bfd_boolean pr_struct_field
162 (void *, const char *, bfd_vma
, bfd_vma
, enum debug_visibility
);
163 static bfd_boolean tg_struct_field
164 (void *, const char *, bfd_vma
, bfd_vma
, enum debug_visibility
);
165 static bfd_boolean tg_struct_field
166 (void *, const char *, bfd_vma
, bfd_vma
, enum debug_visibility
);
167 static bfd_boolean
tg_end_struct_type (void *);
168 static bfd_boolean tg_start_class_type
169 (void *, const char *, unsigned int, bfd_boolean
, unsigned int, bfd_boolean
, bfd_boolean
);
170 static bfd_boolean tg_class_static_member
171 (void *, const char *, const char *, enum debug_visibility
);
172 static bfd_boolean tg_class_baseclass
173 (void *, bfd_vma
, bfd_boolean
, enum debug_visibility
);
174 static bfd_boolean tg_class_method_variant
175 (void *, const char *, enum debug_visibility
, bfd_boolean
, bfd_boolean
, bfd_vma
, bfd_boolean
);
176 static bfd_boolean tg_class_static_method_variant
177 (void *, const char *, enum debug_visibility
, bfd_boolean
, bfd_boolean
);
178 static bfd_boolean
tg_end_class_type (void *);
179 static bfd_boolean tg_tag_type
180 (void *, const char *, unsigned int, enum debug_type_kind
);
181 static bfd_boolean
tg_typdef (void *, const char *);
182 static bfd_boolean
tg_tag (void *, const char *);
183 static bfd_boolean
tg_int_constant (void *, const char *, bfd_vma
);
184 static bfd_boolean
tg_float_constant (void *, const char *, double);
185 static bfd_boolean
tg_typed_constant (void *, const char *, bfd_vma
);
186 static bfd_boolean tg_variable
187 (void *, const char *, enum debug_var_kind
, bfd_vma
);
188 static bfd_boolean
tg_start_function (void *, const char *, bfd_boolean
);
189 static bfd_boolean tg_function_parameter
190 (void *, const char *, enum debug_parm_kind
, bfd_vma
);
191 static bfd_boolean
tg_start_block (void *, bfd_vma
);
192 static bfd_boolean
tg_end_block (void *, bfd_vma
);
193 static bfd_boolean
tg_lineno (void *, const char *, unsigned long, bfd_vma
);
195 static const struct debug_write_fns pr_fns
=
197 pr_start_compilation_unit
,
216 pr_start_struct_type
,
220 pr_class_static_member
,
222 pr_class_start_method
,
223 pr_class_method_variant
,
224 pr_class_static_method_variant
,
236 pr_function_parameter
,
243 static const struct debug_write_fns tg_fns
=
245 tg_start_compilation_unit
,
247 pr_empty_type
, /* Same, push_type. */
248 pr_void_type
, /* Same, push_type. */
249 pr_int_type
, /* Same, push_type. */
250 pr_float_type
, /* Same, push_type. */
251 pr_complex_type
, /* Same, push_type. */
252 pr_bool_type
, /* Same, push_type. */
254 pr_pointer_type
, /* Same, changes to pointer. */
255 pr_function_type
, /* Same, push_type. */
256 pr_reference_type
, /* Same, changes to reference. */
257 pr_range_type
, /* FIXME: What's that?. */
258 pr_array_type
, /* Same, push_type. */
259 pr_set_type
, /* FIXME: What's that?. */
260 pr_offset_type
, /* FIXME: What's that?. */
261 pr_method_type
, /* Same. */
262 pr_const_type
, /* Same, changes to const. */
263 pr_volatile_type
, /* Same, changes to volatile. */
264 tg_start_struct_type
,
268 tg_class_static_member
,
270 pr_class_start_method
, /* Same, remembers that's a method. */
271 tg_class_method_variant
,
272 tg_class_static_method_variant
,
273 pr_class_end_method
, /* Same, forgets that's a method. */
275 pr_typedef_type
, /* Same, just push type. */
279 tg_int_constant
, /* Untested. */
280 tg_float_constant
, /* Untested. */
281 tg_typed_constant
, /* Untested. */
284 tg_function_parameter
,
287 pr_end_function
, /* Same, does nothing. */
291 /* Print out the generic debugging information recorded in dhandle. */
294 print_debugging_info (FILE *f
, void *dhandle
, bfd
*abfd
, asymbol
**syms
,
295 void *demangler
, bfd_boolean as_tags
)
297 struct pr_handle info
;
303 info
.filename
= NULL
;
306 info
.demangler
= demangler
;
310 fputs ("!_TAG_FILE_FORMAT\t2\t/extended format/\n", f
);
311 fputs ("!_TAG_FILE_SORTED\t0\t/0=unsorted, 1=sorted/\n", f
);
312 fputs ("!_TAG_PROGRAM_AUTHOR\tIan Lance Taylor, Salvador E. Tropea and others\t//\n", f
);
313 fputs ("!_TAG_PROGRAM_NAME\tobjdump\t/From GNU binutils/\n", f
);
316 return as_tags
? debug_write (dhandle
, &tg_fns
, (void *) & info
)
317 : debug_write (dhandle
, &pr_fns
, (void *) & info
);
320 /* Indent to the current indentation level. */
323 indent (struct pr_handle
*info
)
327 for (i
= 0; i
< info
->indent
; i
++)
331 /* Push a type on the type stack. */
334 push_type (struct pr_handle
*info
, const char *type
)
341 n
= (struct pr_stack
*) xmalloc (sizeof *n
);
342 memset (n
, 0, sizeof *n
);
344 n
->type
= xstrdup (type
);
345 n
->visibility
= DEBUG_VISIBILITY_IGNORE
;
347 n
->next
= info
->stack
;
353 /* Prepend a string onto the type on the top of the type stack. */
356 prepend_type (struct pr_handle
*info
, const char *s
)
360 assert (info
->stack
!= NULL
);
362 n
= (char *) xmalloc (strlen (s
) + strlen (info
->stack
->type
) + 1);
363 sprintf (n
, "%s%s", s
, info
->stack
->type
);
364 free (info
->stack
->type
);
365 info
->stack
->type
= n
;
370 /* Append a string to the type on the top of the type stack. */
373 append_type (struct pr_handle
*info
, const char *s
)
380 assert (info
->stack
!= NULL
);
382 len
= strlen (info
->stack
->type
);
383 info
->stack
->type
= (char *) xrealloc (info
->stack
->type
,
384 len
+ strlen (s
) + 1);
385 strcpy (info
->stack
->type
+ len
, s
);
390 /* Append a string to the parents on the top of the type stack. */
393 append_parent (struct pr_handle
*info
, const char *s
)
400 assert (info
->stack
!= NULL
);
402 len
= info
->stack
->parents
? strlen (info
->stack
->parents
) : 0;
403 info
->stack
->parents
= (char *) xrealloc (info
->stack
->parents
,
404 len
+ strlen (s
) + 1);
405 strcpy (info
->stack
->parents
+ len
, s
);
410 /* We use an underscore to indicate where the name should go in a type
411 string. This function substitutes a string for the underscore. If
412 there is no underscore, the name follows the type. */
415 substitute_type (struct pr_handle
*info
, const char *s
)
419 assert (info
->stack
!= NULL
);
421 u
= strchr (info
->stack
->type
, '|');
426 n
= (char *) xmalloc (strlen (info
->stack
->type
) + strlen (s
));
428 memcpy (n
, info
->stack
->type
, u
- info
->stack
->type
);
429 strcpy (n
+ (u
- info
->stack
->type
), s
);
432 free (info
->stack
->type
);
433 info
->stack
->type
= n
;
438 if (strchr (s
, '|') != NULL
439 && (strchr (info
->stack
->type
, '{') != NULL
440 || strchr (info
->stack
->type
, '(') != NULL
))
442 if (! prepend_type (info
, "(")
443 || ! append_type (info
, ")"))
450 return (append_type (info
, " ")
451 && append_type (info
, s
));
454 /* Indent the type at the top of the stack by appending spaces. */
457 indent_type (struct pr_handle
*info
)
461 for (i
= 0; i
< info
->indent
; i
++)
463 if (! append_type (info
, " "))
470 /* Pop a type from the type stack. */
473 pop_type (struct pr_handle
*info
)
478 assert (info
->stack
!= NULL
);
481 info
->stack
= o
->next
;
488 /* Print a VMA value into a string. */
491 print_vma (bfd_vma vma
, char *buf
, bfd_boolean unsignedp
, bfd_boolean hexp
)
493 if (sizeof (vma
) <= sizeof (unsigned long))
496 sprintf (buf
, "0x%lx", (unsigned long) vma
);
498 sprintf (buf
, "%lu", (unsigned long) vma
);
500 sprintf (buf
, "%ld", (long) vma
);
502 #if BFD_HOST_64BIT_LONG_LONG
503 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
);
517 sprintf_vma (buf
+ 2, vma
);
521 /* Start a new compilation unit. */
524 pr_start_compilation_unit (void *p
, const char *filename
)
526 struct pr_handle
*info
= (struct pr_handle
*) p
;
528 assert (info
->indent
== 0);
530 fprintf (info
->f
, "%s:\n", filename
);
535 /* Start a source file within a compilation unit. */
538 pr_start_source (void *p
, const char *filename
)
540 struct pr_handle
*info
= (struct pr_handle
*) p
;
542 assert (info
->indent
== 0);
544 fprintf (info
->f
, " %s:\n", filename
);
549 /* Push an empty type onto the type stack. */
552 pr_empty_type (void *p
)
554 struct pr_handle
*info
= (struct pr_handle
*) p
;
556 return push_type (info
, "<undefined>");
559 /* Push a void type onto the type stack. */
562 pr_void_type (void *p
)
564 struct pr_handle
*info
= (struct pr_handle
*) p
;
566 return push_type (info
, "void");
569 /* Push an integer type onto the type stack. */
572 pr_int_type (void *p
, unsigned int size
, bfd_boolean unsignedp
)
574 struct pr_handle
*info
= (struct pr_handle
*) p
;
577 sprintf (ab
, "%sint%d", unsignedp
? "u" : "", size
* 8);
578 return push_type (info
, ab
);
581 /* Push a floating type onto the type stack. */
584 pr_float_type (void *p
, unsigned int size
)
586 struct pr_handle
*info
= (struct pr_handle
*) p
;
590 return push_type (info
, "float");
592 return push_type (info
, "double");
594 sprintf (ab
, "float%d", size
* 8);
595 return push_type (info
, ab
);
598 /* Push a complex type onto the type stack. */
601 pr_complex_type (void *p
, unsigned int size
)
603 struct pr_handle
*info
= (struct pr_handle
*) p
;
605 if (! pr_float_type (p
, size
))
608 return prepend_type (info
, "complex ");
611 /* Push a bfd_boolean type onto the type stack. */
614 pr_bool_type (void *p
, unsigned int size
)
616 struct pr_handle
*info
= (struct pr_handle
*) p
;
619 sprintf (ab
, "bool%d", size
* 8);
621 return push_type (info
, ab
);
624 /* Push an enum type onto the type stack. */
627 pr_enum_type (void *p
, const char *tag
, const char **names
,
628 bfd_signed_vma
*values
)
630 struct pr_handle
*info
= (struct pr_handle
*) p
;
634 if (! push_type (info
, "enum "))
638 if (! append_type (info
, tag
)
639 || ! append_type (info
, " "))
642 if (! append_type (info
, "{ "))
647 if (! append_type (info
, "/* undefined */"))
653 for (i
= 0; names
[i
] != NULL
; i
++)
657 if (! append_type (info
, ", "))
661 if (! append_type (info
, names
[i
]))
664 if (values
[i
] != val
)
668 print_vma (values
[i
], ab
, FALSE
, FALSE
);
669 if (! append_type (info
, " = ")
670 || ! append_type (info
, ab
))
679 return append_type (info
, " }");
682 /* Turn the top type on the stack into a pointer. */
685 pr_pointer_type (void *p
)
687 struct pr_handle
*info
= (struct pr_handle
*) p
;
690 assert (info
->stack
!= NULL
);
692 s
= strchr (info
->stack
->type
, '|');
693 if (s
!= NULL
&& s
[1] == '[')
694 return substitute_type (info
, "(*|)");
695 return substitute_type (info
, "*|");
698 /* Turn the top type on the stack into a function returning that type. */
701 pr_function_type (void *p
, int argcount
, bfd_boolean varargs
)
703 struct pr_handle
*info
= (struct pr_handle
*) p
;
708 assert (info
->stack
!= NULL
);
721 arg_types
= (char **) xmalloc (argcount
* sizeof *arg_types
);
722 for (i
= argcount
- 1; i
>= 0; i
--)
724 if (! substitute_type (info
, ""))
726 arg_types
[i
] = pop_type (info
);
727 if (arg_types
[i
] == NULL
)
729 len
+= strlen (arg_types
[i
]) + 2;
735 /* Now the return type is on the top of the stack. */
738 LITSTRCPY (s
, "(|) (");
741 strcat (s
, "/* unknown */");
746 for (i
= 0; i
< argcount
; i
++)
750 strcat (s
, arg_types
[i
]);
764 if (! substitute_type (info
, s
))
772 /* Turn the top type on the stack into a reference to that type. */
775 pr_reference_type (void *p
)
777 struct pr_handle
*info
= (struct pr_handle
*) p
;
779 assert (info
->stack
!= NULL
);
781 return substitute_type (info
, "&|");
784 /* Make a range type. */
787 pr_range_type (void *p
, bfd_signed_vma lower
, bfd_signed_vma upper
)
789 struct pr_handle
*info
= (struct pr_handle
*) p
;
790 char abl
[20], abu
[20];
792 assert (info
->stack
!= NULL
);
794 if (! substitute_type (info
, ""))
797 print_vma (lower
, abl
, FALSE
, FALSE
);
798 print_vma (upper
, abu
, FALSE
, FALSE
);
800 return (prepend_type (info
, "range (")
801 && append_type (info
, "):")
802 && append_type (info
, abl
)
803 && append_type (info
, ":")
804 && append_type (info
, abu
));
807 /* Make an array type. */
810 pr_array_type (void *p
, bfd_signed_vma lower
, bfd_signed_vma upper
,
813 struct pr_handle
*info
= (struct pr_handle
*) p
;
815 char abl
[20], abu
[20], ab
[50];
817 range_type
= pop_type (info
);
818 if (range_type
== NULL
)
827 print_vma (upper
+ 1, abu
, FALSE
, FALSE
);
828 sprintf (ab
, "|[%s]", abu
);
833 print_vma (lower
, abl
, FALSE
, FALSE
);
834 print_vma (upper
, abu
, FALSE
, FALSE
);
835 sprintf (ab
, "|[%s:%s]", abl
, abu
);
838 if (! substitute_type (info
, ab
))
841 if (strcmp (range_type
, "int") != 0)
843 if (! append_type (info
, ":")
844 || ! append_type (info
, range_type
))
850 if (! append_type (info
, " /* string */"))
857 /* Make a set type. */
860 pr_set_type (void *p
, bfd_boolean bitstringp
)
862 struct pr_handle
*info
= (struct pr_handle
*) p
;
864 if (! substitute_type (info
, ""))
867 if (! prepend_type (info
, "set { ")
868 || ! append_type (info
, " }"))
873 if (! append_type (info
, "/* bitstring */"))
880 /* Make an offset type. */
883 pr_offset_type (void *p
)
885 struct pr_handle
*info
= (struct pr_handle
*) p
;
888 if (! substitute_type (info
, ""))
895 return (substitute_type (info
, "")
896 && prepend_type (info
, " ")
897 && prepend_type (info
, t
)
898 && append_type (info
, "::|"));
901 /* Make a method type. */
904 pr_method_type (void *p
, bfd_boolean domain
, int argcount
, bfd_boolean varargs
)
906 struct pr_handle
*info
= (struct pr_handle
*) p
;
918 if (! substitute_type (info
, ""))
920 domain_type
= pop_type (info
);
921 if (domain_type
== NULL
)
923 if (CONST_STRNEQ (domain_type
, "class ")
924 && strchr (domain_type
+ sizeof "class " - 1, ' ') == NULL
)
925 domain_type
+= sizeof "class " - 1;
926 else if (CONST_STRNEQ (domain_type
, "union class ")
927 && (strchr (domain_type
+ sizeof "union class " - 1, ' ')
929 domain_type
+= sizeof "union class " - 1;
930 len
+= strlen (domain_type
);
942 arg_types
= (char **) xmalloc (argcount
* sizeof *arg_types
);
943 for (i
= argcount
- 1; i
>= 0; i
--)
945 if (! substitute_type (info
, ""))
947 arg_types
[i
] = pop_type (info
);
948 if (arg_types
[i
] == NULL
)
950 len
+= strlen (arg_types
[i
]) + 2;
956 /* Now the return type is on the top of the stack. */
958 s
= (char *) xmalloc (len
);
962 strcpy (s
, domain_type
);
966 strcat (s
, "/* unknown */");
971 for (i
= 0; i
< argcount
; i
++)
975 strcat (s
, arg_types
[i
]);
989 if (! substitute_type (info
, s
))
997 /* Make a const qualified type. */
1000 pr_const_type (void *p
)
1002 struct pr_handle
*info
= (struct pr_handle
*) p
;
1004 return substitute_type (info
, "const |");
1007 /* Make a volatile qualified type. */
1010 pr_volatile_type (void *p
)
1012 struct pr_handle
*info
= (struct pr_handle
*) p
;
1014 return substitute_type (info
, "volatile |");
1017 /* Start accumulating a struct type. */
1020 pr_start_struct_type (void *p
, const char *tag
, unsigned int id
,
1021 bfd_boolean structp
, unsigned int size
)
1023 struct pr_handle
*info
= (struct pr_handle
*) p
;
1027 if (! push_type (info
, structp
? "struct " : "union "))
1031 if (! append_type (info
, tag
))
1038 sprintf (idbuf
, "%%anon%u", id
);
1039 if (! append_type (info
, idbuf
))
1043 if (! append_type (info
, " {"))
1045 if (size
!= 0 || tag
!= NULL
)
1049 if (! append_type (info
, " /*"))
1054 sprintf (ab
, " size %u", size
);
1055 if (! append_type (info
, ab
))
1060 sprintf (ab
, " id %u", id
);
1061 if (! append_type (info
, ab
))
1064 if (! append_type (info
, " */"))
1067 if (! append_type (info
, "\n"))
1070 info
->stack
->visibility
= DEBUG_VISIBILITY_PUBLIC
;
1072 return indent_type (info
);
1075 /* Output the visibility of a field in a struct. */
1078 pr_fix_visibility (struct pr_handle
*info
, enum debug_visibility visibility
)
1080 const char *s
= NULL
;
1084 assert (info
->stack
!= NULL
);
1086 if (info
->stack
->visibility
== visibility
)
1091 case DEBUG_VISIBILITY_PUBLIC
:
1094 case DEBUG_VISIBILITY_PRIVATE
:
1097 case DEBUG_VISIBILITY_PROTECTED
:
1100 case DEBUG_VISIBILITY_IGNORE
:
1108 /* Trim off a trailing space in the struct string, to make the
1109 output look a bit better, then stick on the visibility string. */
1111 t
= info
->stack
->type
;
1113 assert (t
[len
- 1] == ' ');
1116 if (! append_type (info
, s
)
1117 || ! append_type (info
, ":\n")
1118 || ! indent_type (info
))
1121 info
->stack
->visibility
= visibility
;
1126 /* Add a field to a struct type. */
1129 pr_struct_field (void *p
, const char *name
, bfd_vma bitpos
, bfd_vma bitsize
,
1130 enum debug_visibility visibility
)
1132 struct pr_handle
*info
= (struct pr_handle
*) p
;
1136 if (! substitute_type (info
, name
))
1139 if (! append_type (info
, "; /* "))
1144 print_vma (bitsize
, ab
, TRUE
, FALSE
);
1145 if (! append_type (info
, "bitsize ")
1146 || ! append_type (info
, ab
)
1147 || ! append_type (info
, ", "))
1151 print_vma (bitpos
, ab
, TRUE
, FALSE
);
1152 if (! append_type (info
, "bitpos ")
1153 || ! append_type (info
, ab
)
1154 || ! append_type (info
, " */\n")
1155 || ! indent_type (info
))
1158 t
= pop_type (info
);
1162 if (! pr_fix_visibility (info
, visibility
))
1165 return append_type (info
, t
);
1168 /* Finish a struct type. */
1171 pr_end_struct_type (void *p
)
1173 struct pr_handle
*info
= (struct pr_handle
*) p
;
1176 assert (info
->stack
!= NULL
);
1177 assert (info
->indent
>= 2);
1181 /* Change the trailing indentation to have a close brace. */
1182 s
= info
->stack
->type
+ strlen (info
->stack
->type
) - 2;
1183 assert (s
[0] == ' ' && s
[1] == ' ' && s
[2] == '\0');
1191 /* Start a class type. */
1194 pr_start_class_type (void *p
, const char *tag
, unsigned int id
,
1195 bfd_boolean structp
, unsigned int size
,
1196 bfd_boolean vptr
, bfd_boolean ownvptr
)
1198 struct pr_handle
*info
= (struct pr_handle
*) p
;
1203 if (vptr
&& ! ownvptr
)
1205 tv
= pop_type (info
);
1210 if (! push_type (info
, structp
? "class " : "union class "))
1214 if (! append_type (info
, tag
))
1221 sprintf (idbuf
, "%%anon%u", id
);
1222 if (! append_type (info
, idbuf
))
1226 if (! append_type (info
, " {"))
1228 if (size
!= 0 || vptr
|| ownvptr
|| tag
!= NULL
)
1230 if (! append_type (info
, " /*"))
1237 sprintf (ab
, "%u", size
);
1238 if (! append_type (info
, " size ")
1239 || ! append_type (info
, ab
))
1245 if (! append_type (info
, " vtable "))
1249 if (! append_type (info
, "self "))
1254 if (! append_type (info
, tv
)
1255 || ! append_type (info
, " "))
1264 sprintf (ab
, " id %u", id
);
1265 if (! append_type (info
, ab
))
1269 if (! append_type (info
, " */"))
1273 info
->stack
->visibility
= DEBUG_VISIBILITY_PRIVATE
;
1275 return (append_type (info
, "\n")
1276 && indent_type (info
));
1279 /* Add a static member to a class. */
1282 pr_class_static_member (void *p
, const char *name
, const char *physname
,
1283 enum debug_visibility visibility
)
1285 struct pr_handle
*info
= (struct pr_handle
*) p
;
1288 if (! substitute_type (info
, name
))
1291 if (! prepend_type (info
, "static ")
1292 || ! append_type (info
, "; /* ")
1293 || ! append_type (info
, physname
)
1294 || ! append_type (info
, " */\n")
1295 || ! indent_type (info
))
1298 t
= pop_type (info
);
1302 if (! pr_fix_visibility (info
, visibility
))
1305 return append_type (info
, t
);
1308 /* Add a base class to a class. */
1311 pr_class_baseclass (void *p
, bfd_vma bitpos
, bfd_boolean
virtual,
1312 enum debug_visibility visibility
)
1314 struct pr_handle
*info
= (struct pr_handle
*) p
;
1320 assert (info
->stack
!= NULL
&& info
->stack
->next
!= NULL
);
1322 if (! substitute_type (info
, ""))
1325 t
= pop_type (info
);
1329 if (CONST_STRNEQ (t
, "class "))
1330 t
+= sizeof "class " - 1;
1332 /* Push it back on to take advantage of the prepend_type and
1333 append_type routines. */
1334 if (! push_type (info
, t
))
1339 if (! prepend_type (info
, "virtual "))
1345 case DEBUG_VISIBILITY_PUBLIC
:
1348 case DEBUG_VISIBILITY_PROTECTED
:
1349 prefix
= "protected ";
1351 case DEBUG_VISIBILITY_PRIVATE
:
1352 prefix
= "private ";
1355 prefix
= "/* unknown visibility */ ";
1359 if (! prepend_type (info
, prefix
))
1364 print_vma (bitpos
, ab
, TRUE
, FALSE
);
1365 if (! append_type (info
, " /* bitpos ")
1366 || ! append_type (info
, ab
)
1367 || ! append_type (info
, " */"))
1371 /* Now the top of the stack is something like "public A / * bitpos
1372 10 * /". The next element on the stack is something like "class
1373 xx { / * size 8 * /\n...". We want to substitute the top of the
1374 stack in before the {. */
1375 s
= strchr (info
->stack
->next
->type
, '{');
1379 /* If there is already a ':', then we already have a baseclass, and
1380 we must append this one after a comma. */
1381 for (l
= info
->stack
->next
->type
; l
!= s
; l
++)
1384 if (! prepend_type (info
, l
== s
? " : " : ", "))
1387 t
= pop_type (info
);
1391 n
= (char *) xmalloc (strlen (info
->stack
->type
) + strlen (t
) + 1);
1392 memcpy (n
, info
->stack
->type
, s
- info
->stack
->type
);
1393 strcpy (n
+ (s
- info
->stack
->type
), t
);
1396 free (info
->stack
->type
);
1397 info
->stack
->type
= n
;
1404 /* Start adding a method to a class. */
1407 pr_class_start_method (void *p
, const char *name
)
1409 struct pr_handle
*info
= (struct pr_handle
*) p
;
1411 assert (info
->stack
!= NULL
);
1412 info
->stack
->method
= name
;
1416 /* Add a variant to a method. */
1419 pr_class_method_variant (void *p
, const char *physname
,
1420 enum debug_visibility visibility
,
1421 bfd_boolean constp
, bfd_boolean volatilep
,
1422 bfd_vma voffset
, bfd_boolean context
)
1424 struct pr_handle
*info
= (struct pr_handle
*) p
;
1428 assert (info
->stack
!= NULL
);
1429 assert (info
->stack
->next
!= NULL
);
1431 /* Put the const and volatile qualifiers on the type. */
1434 if (! append_type (info
, " volatile"))
1439 if (! append_type (info
, " const"))
1443 /* Stick the name of the method into its type. */
1444 if (! substitute_type (info
,
1446 ? info
->stack
->next
->next
->method
1447 : info
->stack
->next
->method
)))
1451 method_type
= pop_type (info
);
1452 if (method_type
== NULL
)
1455 /* Pull off the context type if there is one. */
1457 context_type
= NULL
;
1460 context_type
= pop_type (info
);
1461 if (context_type
== NULL
)
1465 /* Now the top of the stack is the class. */
1467 if (! pr_fix_visibility (info
, visibility
))
1470 if (! append_type (info
, method_type
)
1471 || ! append_type (info
, " /* ")
1472 || ! append_type (info
, physname
)
1473 || ! append_type (info
, " "))
1475 if (context
|| voffset
!= 0)
1481 if (! append_type (info
, "context ")
1482 || ! append_type (info
, context_type
)
1483 || ! append_type (info
, " "))
1486 print_vma (voffset
, ab
, TRUE
, FALSE
);
1487 if (! append_type (info
, "voffset ")
1488 || ! append_type (info
, ab
))
1492 return (append_type (info
, " */;\n")
1493 && indent_type (info
));
1496 /* Add a static variant to a method. */
1499 pr_class_static_method_variant (void *p
, const char *physname
,
1500 enum debug_visibility visibility
,
1501 bfd_boolean constp
, bfd_boolean volatilep
)
1503 struct pr_handle
*info
= (struct pr_handle
*) p
;
1506 assert (info
->stack
!= NULL
);
1507 assert (info
->stack
->next
!= NULL
);
1508 assert (info
->stack
->next
->method
!= NULL
);
1510 /* Put the const and volatile qualifiers on the type. */
1513 if (! append_type (info
, " volatile"))
1518 if (! append_type (info
, " const"))
1522 /* Mark it as static. */
1523 if (! prepend_type (info
, "static "))
1526 /* Stick the name of the method into its type. */
1527 if (! substitute_type (info
, info
->stack
->next
->method
))
1531 method_type
= pop_type (info
);
1532 if (method_type
== NULL
)
1535 /* Now the top of the stack is the class. */
1537 if (! pr_fix_visibility (info
, visibility
))
1540 return (append_type (info
, method_type
)
1541 && append_type (info
, " /* ")
1542 && append_type (info
, physname
)
1543 && append_type (info
, " */;\n")
1544 && indent_type (info
));
1547 /* Finish up a method. */
1550 pr_class_end_method (void *p
)
1552 struct pr_handle
*info
= (struct pr_handle
*) p
;
1554 info
->stack
->method
= NULL
;
1558 /* Finish up a class. */
1561 pr_end_class_type (void *p
)
1563 return pr_end_struct_type (p
);
1566 /* Push a type on the stack using a typedef name. */
1569 pr_typedef_type (void *p
, const char *name
)
1571 struct pr_handle
*info
= (struct pr_handle
*) p
;
1573 return push_type (info
, name
);
1576 /* Push a type on the stack using a tag name. */
1579 pr_tag_type (void *p
, const char *name
, unsigned int id
,
1580 enum debug_type_kind kind
)
1582 struct pr_handle
*info
= (struct pr_handle
*) p
;
1583 const char *t
, *tag
;
1588 case DEBUG_KIND_STRUCT
:
1591 case DEBUG_KIND_UNION
:
1594 case DEBUG_KIND_ENUM
:
1597 case DEBUG_KIND_CLASS
:
1600 case DEBUG_KIND_UNION_CLASS
:
1608 if (! push_type (info
, t
))
1614 sprintf (idbuf
, "%%anon%u", id
);
1618 if (! append_type (info
, tag
))
1620 if (name
!= NULL
&& kind
!= DEBUG_KIND_ENUM
)
1622 sprintf (idbuf
, " /* id %u */", id
);
1623 if (! append_type (info
, idbuf
))
1630 /* Output a typedef. */
1633 pr_typdef (void *p
, const char *name
)
1635 struct pr_handle
*info
= (struct pr_handle
*) p
;
1638 if (! substitute_type (info
, name
))
1641 s
= pop_type (info
);
1646 fprintf (info
->f
, "typedef %s;\n", s
);
1653 /* Output a tag. The tag should already be in the string on the
1654 stack, so all we have to do here is print it out. */
1657 pr_tag (void *p
, const char *name ATTRIBUTE_UNUSED
)
1659 struct pr_handle
*info
= (struct pr_handle
*) p
;
1662 t
= pop_type (info
);
1667 fprintf (info
->f
, "%s;\n", t
);
1674 /* Output an integer constant. */
1677 pr_int_constant (void *p
, const char *name
, bfd_vma val
)
1679 struct pr_handle
*info
= (struct pr_handle
*) p
;
1683 print_vma (val
, ab
, FALSE
, FALSE
);
1684 fprintf (info
->f
, "const int %s = %s;\n", name
, ab
);
1688 /* Output a floating point constant. */
1691 pr_float_constant (void *p
, const char *name
, double val
)
1693 struct pr_handle
*info
= (struct pr_handle
*) p
;
1696 fprintf (info
->f
, "const double %s = %g;\n", name
, val
);
1700 /* Output a typed constant. */
1703 pr_typed_constant (void *p
, const char *name
, bfd_vma val
)
1705 struct pr_handle
*info
= (struct pr_handle
*) p
;
1709 t
= pop_type (info
);
1714 print_vma (val
, ab
, FALSE
, FALSE
);
1715 fprintf (info
->f
, "const %s %s = %s;\n", t
, name
, ab
);
1722 /* Output a variable. */
1725 pr_variable (void *p
, const char *name
, enum debug_var_kind kind
,
1728 struct pr_handle
*info
= (struct pr_handle
*) p
;
1732 if (! substitute_type (info
, name
))
1735 t
= pop_type (info
);
1743 case DEBUG_LOCAL_STATIC
:
1744 fprintf (info
->f
, "static ");
1746 case DEBUG_REGISTER
:
1747 fprintf (info
->f
, "register ");
1752 print_vma (val
, ab
, TRUE
, TRUE
);
1753 fprintf (info
->f
, "%s /* %s */;\n", t
, ab
);
1760 /* Start outputting a function. */
1763 pr_start_function (void *p
, const char *name
, bfd_boolean global
)
1765 struct pr_handle
*info
= (struct pr_handle
*) p
;
1768 if (! substitute_type (info
, name
))
1771 t
= pop_type (info
);
1777 fprintf (info
->f
, "static ");
1778 fprintf (info
->f
, "%s (", t
);
1780 info
->parameter
= 1;
1785 /* Output a function parameter. */
1788 pr_function_parameter (void *p
, const char *name
,
1789 enum debug_parm_kind kind
, bfd_vma val
)
1791 struct pr_handle
*info
= (struct pr_handle
*) p
;
1795 if (kind
== DEBUG_PARM_REFERENCE
1796 || kind
== DEBUG_PARM_REF_REG
)
1798 if (! pr_reference_type (p
))
1802 if (! substitute_type (info
, name
))
1805 t
= pop_type (info
);
1809 if (info
->parameter
!= 1)
1810 fprintf (info
->f
, ", ");
1812 if (kind
== DEBUG_PARM_REG
|| kind
== DEBUG_PARM_REF_REG
)
1813 fprintf (info
->f
, "register ");
1815 print_vma (val
, ab
, TRUE
, TRUE
);
1816 fprintf (info
->f
, "%s /* %s */", t
, ab
);
1825 /* Start writing out a block. */
1828 pr_start_block (void *p
, bfd_vma addr
)
1830 struct pr_handle
*info
= (struct pr_handle
*) p
;
1833 if (info
->parameter
> 0)
1835 fprintf (info
->f
, ")\n");
1836 info
->parameter
= 0;
1840 print_vma (addr
, ab
, TRUE
, TRUE
);
1841 fprintf (info
->f
, "{ /* %s */\n", ab
);
1848 /* Write out line number information. */
1851 pr_lineno (void *p
, const char *filename
, unsigned long lineno
, bfd_vma addr
)
1853 struct pr_handle
*info
= (struct pr_handle
*) p
;
1857 print_vma (addr
, ab
, TRUE
, TRUE
);
1858 fprintf (info
->f
, "/* file %s line %lu addr %s */\n", filename
, lineno
, ab
);
1863 /* Finish writing out a block. */
1866 pr_end_block (void *p
, bfd_vma addr
)
1868 struct pr_handle
*info
= (struct pr_handle
*) p
;
1874 print_vma (addr
, ab
, TRUE
, TRUE
);
1875 fprintf (info
->f
, "} /* %s */\n", ab
);
1880 /* Finish writing out a function. */
1883 pr_end_function (void *p ATTRIBUTE_UNUSED
)
1888 /* Tags style generation functions start here. */
1890 /* Variables for address to line translation. */
1892 static const char *filename
;
1893 static const char *functionname
;
1894 static unsigned int line
;
1895 static bfd_boolean found
;
1897 /* Look for an address in a section. This is called via
1898 bfd_map_over_sections. */
1901 find_address_in_section (bfd
*abfd
, asection
*section
, void *data
)
1905 asymbol
**syms
= (asymbol
**) data
;
1910 if ((bfd_get_section_flags (abfd
, section
) & SEC_ALLOC
) == 0)
1913 vma
= bfd_get_section_vma (abfd
, section
);
1917 size
= bfd_get_section_size (section
);
1918 if (pc
>= vma
+ size
)
1921 found
= bfd_find_nearest_line (abfd
, section
, syms
, pc
- vma
,
1922 &filename
, &functionname
, &line
);
1926 translate_addresses (bfd
*abfd
, char *addr_hex
, FILE *f
, asymbol
**syms
)
1928 pc
= bfd_scan_vma (addr_hex
, NULL
, 16);
1930 bfd_map_over_sections (abfd
, find_address_in_section
, syms
);
1935 fprintf (f
, "%u", line
);
1938 /* Start a new compilation unit. */
1941 tg_start_compilation_unit (void * p
, const char *filename ATTRIBUTE_UNUSED
)
1943 struct pr_handle
*info
= (struct pr_handle
*) p
;
1945 fprintf (stderr
, "New compilation unit: %s\n", filename
);
1947 free (info
->filename
);
1948 /* Should it be relative? best way to do it here?. */
1949 info
->filename
= strdup (filename
);
1954 /* Start a source file within a compilation unit. */
1957 tg_start_source (void *p
, const char *filename
)
1959 struct pr_handle
*info
= (struct pr_handle
*) p
;
1961 free (info
->filename
);
1962 /* Should it be relative? best way to do it here?. */
1963 info
->filename
= strdup (filename
);
1968 /* Push an enum type onto the type stack. */
1971 tg_enum_type (void *p
, const char *tag
, const char **names
,
1972 bfd_signed_vma
*values
)
1974 struct pr_handle
*info
= (struct pr_handle
*) p
;
1979 if (! pr_enum_type (p
, tag
, names
, values
))
1982 name
= tag
? tag
: "unknown";
1983 /* Generate an entry for the enum. */
1985 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:e\ttype:%s\n", tag
,
1986 info
->filename
, info
->stack
->type
);
1988 /* Generate entries for the values. */
1991 for (i
= 0; names
[i
] != NULL
; i
++)
1993 print_vma (values
[i
], ab
, FALSE
, FALSE
);
1994 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:g\tenum:%s\tvalue:%s\n",
1995 names
[i
], info
->filename
, name
, ab
);
2002 /* Start accumulating a struct type. */
2005 tg_start_struct_type (void *p
, const char *tag
, unsigned int id
,
2006 bfd_boolean structp
,
2007 unsigned int size ATTRIBUTE_UNUSED
)
2009 struct pr_handle
*info
= (struct pr_handle
*) p
;
2018 sprintf (idbuf
, "%%anon%u", id
);
2021 if (! push_type (info
, name
))
2024 info
->stack
->flavor
= structp
? "struct" : "union";
2026 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:%c\n", name
, info
->filename
,
2027 info
->stack
->flavor
[0]);
2029 info
->stack
->visibility
= DEBUG_VISIBILITY_PUBLIC
;
2031 return indent_type (info
);
2034 /* Output the visibility of a field in a struct. */
2037 tg_fix_visibility (struct pr_handle
*info
, enum debug_visibility visibility
)
2039 assert (info
->stack
!= NULL
);
2041 if (info
->stack
->visibility
== visibility
)
2044 assert (info
->stack
->visibility
!= DEBUG_VISIBILITY_IGNORE
);
2046 info
->stack
->visibility
= visibility
;
2051 /* Add a field to a struct type. */
2054 tg_struct_field (void *p
, const char *name
, bfd_vma bitpos ATTRIBUTE_UNUSED
,
2055 bfd_vma bitsize ATTRIBUTE_UNUSED
,
2056 enum debug_visibility visibility
)
2058 struct pr_handle
*info
= (struct pr_handle
*) p
;
2061 t
= pop_type (info
);
2065 if (! tg_fix_visibility (info
, visibility
))
2068 /* It happens, a bug? */
2072 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:m\ttype:%s\t%s:%s\taccess:%s\n",
2073 name
, info
->filename
, t
, info
->stack
->flavor
, info
->stack
->type
,
2074 visibility_name (visibility
));
2079 /* Finish a struct type. */
2082 tg_end_struct_type (void *p ATTRIBUTE_UNUSED
)
2084 struct pr_handle
*info
= (struct pr_handle
*) p
;
2085 assert (info
->stack
!= NULL
);
2090 /* Start a class type. */
2093 tg_start_class_type (void *p
, const char *tag
, unsigned int id
,
2094 bfd_boolean structp
, unsigned int size
,
2095 bfd_boolean vptr
, bfd_boolean ownvptr
)
2097 struct pr_handle
*info
= (struct pr_handle
*) p
;
2103 if (vptr
&& ! ownvptr
)
2105 tv
= pop_type (info
);
2116 sprintf (idbuf
, "%%anon%u", id
);
2120 if (! push_type (info
, name
))
2123 info
->stack
->flavor
= structp
? "class" : "union class";
2124 info
->stack
->parents
= NULL
;
2125 info
->stack
->num_parents
= 0;
2127 if (size
!= 0 || vptr
|| ownvptr
|| tag
!= NULL
)
2131 if (! append_type (info
, " vtable "))
2135 if (! append_type (info
, "self "))
2140 if (! append_type (info
, tv
)
2141 || ! append_type (info
, " "))
2147 info
->stack
->visibility
= DEBUG_VISIBILITY_PRIVATE
;
2152 /* Add a static member to a class. */
2155 tg_class_static_member (void *p
, const char *name
,
2156 const char *physname ATTRIBUTE_UNUSED
,
2157 enum debug_visibility visibility
)
2159 struct pr_handle
*info
= (struct pr_handle
*) p
;
2161 int len_var
, len_class
;
2164 len_var
= strlen (name
);
2165 len_class
= strlen (info
->stack
->next
->type
);
2166 full_name
= xmalloc (len_var
+ len_class
+ 3);
2169 sprintf (full_name
, "%s::%s", info
->stack
->next
->type
, name
);
2171 if (! substitute_type (info
, full_name
))
2174 if (! prepend_type (info
, "static "))
2177 t
= pop_type (info
);
2181 if (! tg_fix_visibility (info
, visibility
))
2184 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:x\ttype:%s\tclass:%s\taccess:%s\n",
2185 name
, info
->filename
, t
, info
->stack
->type
,
2186 visibility_name (visibility
));
2193 /* Add a base class to a class. */
2196 tg_class_baseclass (void *p
, bfd_vma bitpos ATTRIBUTE_UNUSED
,
2197 bfd_boolean
virtual, enum debug_visibility visibility
)
2199 struct pr_handle
*info
= (struct pr_handle
*) p
;
2203 assert (info
->stack
!= NULL
&& info
->stack
->next
!= NULL
);
2205 t
= pop_type (info
);
2209 if (CONST_STRNEQ (t
, "class "))
2210 t
+= sizeof "class " - 1;
2212 /* Push it back on to take advantage of the prepend_type and
2213 append_type routines. */
2214 if (! push_type (info
, t
))
2219 if (! prepend_type (info
, "virtual "))
2225 case DEBUG_VISIBILITY_PUBLIC
:
2228 case DEBUG_VISIBILITY_PROTECTED
:
2229 prefix
= "protected ";
2231 case DEBUG_VISIBILITY_PRIVATE
:
2232 prefix
= "private ";
2235 prefix
= "/* unknown visibility */ ";
2239 if (! prepend_type (info
, prefix
))
2242 t
= pop_type (info
);
2246 if (info
->stack
->num_parents
&& ! append_parent (info
, ", "))
2249 if (! append_parent (info
, t
))
2251 info
->stack
->num_parents
++;
2258 /* Add a variant to a method. */
2261 tg_class_method_variant (void *p
, const char *physname ATTRIBUTE_UNUSED
,
2262 enum debug_visibility visibility
,
2263 bfd_boolean constp
, bfd_boolean volatilep
,
2264 bfd_vma voffset ATTRIBUTE_UNUSED
,
2265 bfd_boolean context
)
2267 struct pr_handle
*info
= (struct pr_handle
*) p
;
2272 assert (info
->stack
!= NULL
);
2273 assert (info
->stack
->next
!= NULL
);
2275 /* Put the const and volatile qualifiers on the type. */
2278 if (! append_type (info
, " volatile"))
2283 if (! append_type (info
, " const"))
2287 method_name
= strdup (context
? info
->stack
->next
->next
->method
2288 : info
->stack
->next
->method
);
2290 /* Stick the name of the method into its type. */
2291 if (! substitute_type (info
, method_name
))
2295 method_type
= pop_type (info
);
2296 if (method_type
== NULL
)
2299 /* Pull off the context type if there is one. */
2301 context_type
= NULL
;
2304 context_type
= pop_type (info
);
2305 if (context_type
== NULL
)
2309 /* Now the top of the stack is the class. */
2310 if (! tg_fix_visibility (info
, visibility
))
2313 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:p\ttype:%s\tclass:%s\n",
2314 method_name
, info
->filename
, method_type
, info
->stack
->type
);
2317 free (context_type
);
2322 /* Add a static variant to a method. */
2325 tg_class_static_method_variant (void *p
,
2326 const char *physname ATTRIBUTE_UNUSED
,
2327 enum debug_visibility visibility
,
2328 bfd_boolean constp
, bfd_boolean volatilep
)
2330 struct pr_handle
*info
= (struct pr_handle
*) p
;
2334 assert (info
->stack
!= NULL
);
2335 assert (info
->stack
->next
!= NULL
);
2336 assert (info
->stack
->next
->method
!= NULL
);
2338 /* Put the const and volatile qualifiers on the type. */
2341 if (! append_type (info
, " volatile"))
2346 if (! append_type (info
, " const"))
2350 /* Mark it as static. */
2351 if (! prepend_type (info
, "static "))
2354 method_name
= strdup (info
->stack
->next
->method
);
2355 /* Stick the name of the method into its type. */
2356 if (! substitute_type (info
, info
->stack
->next
->method
))
2360 method_type
= pop_type (info
);
2361 if (method_type
== NULL
)
2364 /* Now the top of the stack is the class. */
2365 if (! tg_fix_visibility (info
, visibility
))
2368 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:p\ttype:%s\tclass:%s\taccess:%s\n",
2369 method_name
, info
->filename
, method_type
, info
->stack
->type
,
2370 visibility_name (visibility
));
2377 /* Finish up a class. */
2380 tg_end_class_type (void *p
)
2382 struct pr_handle
*info
= (struct pr_handle
*) p
;
2384 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:c\ttype:%s", info
->stack
->type
,
2385 info
->filename
, info
->stack
->flavor
);
2386 if (info
->stack
->num_parents
)
2388 fprintf (info
->f
, "\tinherits:%s", info
->stack
->parents
);
2389 free (info
->stack
->parents
);
2391 fputc ('\n', info
->f
);
2393 return tg_end_struct_type (p
);
2396 /* Push a type on the stack using a tag name. */
2399 tg_tag_type (void *p
, const char *name
, unsigned int id
,
2400 enum debug_type_kind kind
)
2402 struct pr_handle
*info
= (struct pr_handle
*) p
;
2403 const char *t
, *tag
;
2408 case DEBUG_KIND_STRUCT
:
2411 case DEBUG_KIND_UNION
:
2414 case DEBUG_KIND_ENUM
:
2417 case DEBUG_KIND_CLASS
:
2420 case DEBUG_KIND_UNION_CLASS
:
2428 if (! push_type (info
, t
))
2434 sprintf (idbuf
, "%%anon%u", id
);
2438 if (! append_type (info
, tag
))
2444 /* Output a typedef. */
2447 tg_typdef (void *p
, const char *name
)
2449 struct pr_handle
*info
= (struct pr_handle
*) p
;
2452 s
= pop_type (info
);
2456 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:t\ttype:%s\n", name
,
2464 /* Output a tag. The tag should already be in the string on the
2465 stack, so all we have to do here is print it out. */
2468 tg_tag (void *p ATTRIBUTE_UNUSED
, const char *name ATTRIBUTE_UNUSED
)
2470 struct pr_handle
*info
= (struct pr_handle
*) p
;
2473 t
= pop_type (info
);
2481 /* Output an integer constant. */
2484 tg_int_constant (void *p
, const char *name
, bfd_vma val
)
2486 struct pr_handle
*info
= (struct pr_handle
*) p
;
2490 print_vma (val
, ab
, FALSE
, FALSE
);
2491 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:v\ttype:const int\tvalue:%s\n",
2492 name
, info
->filename
, ab
);
2496 /* Output a floating point constant. */
2499 tg_float_constant (void *p
, const char *name
, double val
)
2501 struct pr_handle
*info
= (struct pr_handle
*) p
;
2504 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:v\ttype:const double\tvalue:%g\n",
2505 name
, info
->filename
, val
);
2509 /* Output a typed constant. */
2512 tg_typed_constant (void *p
, const char *name
, bfd_vma val
)
2514 struct pr_handle
*info
= (struct pr_handle
*) p
;
2518 t
= pop_type (info
);
2523 print_vma (val
, ab
, FALSE
, FALSE
);
2524 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:v\ttype:const %s\tvalue:%s\n",
2525 name
, info
->filename
, t
, ab
);
2532 /* Output a variable. */
2535 tg_variable (void *p
, const char *name
, enum debug_var_kind kind
,
2536 bfd_vma val ATTRIBUTE_UNUSED
)
2538 struct pr_handle
*info
= (struct pr_handle
*) p
;
2539 char *t
, *dname
, *from_class
;
2541 t
= pop_type (info
);
2546 if (info
->demangler
)
2547 dname
= info
->demangler (info
->abfd
, name
, DMGL_ANSI
| DMGL_PARAMS
);
2553 sep
= strstr (dname
, "::");
2561 /* Obscure types as vts and type_info nodes. */
2565 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:v\ttype:%s", name
, info
->filename
, t
);
2570 case DEBUG_LOCAL_STATIC
:
2571 fprintf (info
->f
, "\tfile:");
2573 case DEBUG_REGISTER
:
2574 fprintf (info
->f
, "\tregister:");
2581 fprintf (info
->f
, "\tclass:%s", from_class
);
2586 fprintf (info
->f
, "\n");
2593 /* Start outputting a function. */
2596 tg_start_function (void *p
, const char *name
, bfd_boolean global
)
2598 struct pr_handle
*info
= (struct pr_handle
*) p
;
2602 info
->stack
->flavor
= "static";
2604 info
->stack
->flavor
= NULL
;
2607 if (info
->demangler
)
2608 dname
= info
->demangler (info
->abfd
, name
, DMGL_ANSI
| DMGL_PARAMS
);
2610 if (! substitute_type (info
, dname
? dname
: name
))
2613 info
->stack
->method
= NULL
;
2617 sep
= strstr (dname
, "::");
2620 info
->stack
->method
= dname
;
2626 info
->stack
->method
= "";
2629 sep
= strchr (name
, '(');
2632 /* Obscure functions as type_info function. */
2635 info
->stack
->parents
= strdup (name
);
2637 if (! info
->stack
->method
&& ! append_type (info
, "("))
2640 info
->parameter
= 1;
2645 /* Output a function parameter. */
2648 tg_function_parameter (void *p
, const char *name
, enum debug_parm_kind kind
,
2649 bfd_vma val ATTRIBUTE_UNUSED
)
2651 struct pr_handle
*info
= (struct pr_handle
*) p
;
2654 if (kind
== DEBUG_PARM_REFERENCE
2655 || kind
== DEBUG_PARM_REF_REG
)
2657 if (! pr_reference_type (p
))
2661 if (! substitute_type (info
, name
))
2664 t
= pop_type (info
);
2668 if (! info
->stack
->method
)
2670 if (info
->parameter
!= 1 && ! append_type (info
, ", "))
2673 if (kind
== DEBUG_PARM_REG
|| kind
== DEBUG_PARM_REF_REG
)
2674 if (! append_type (info
, "register "))
2677 if (! append_type (info
, t
))
2688 /* Start writing out a block. */
2691 tg_start_block (void *p
, bfd_vma addr
)
2693 struct pr_handle
*info
= (struct pr_handle
*) p
;
2694 char ab
[20], kind
, *partof
;
2698 if (info
->parameter
> 0)
2700 info
->parameter
= 0;
2703 fprintf (info
->f
, "%s\t%s\t", info
->stack
->parents
, info
->filename
);
2704 free (info
->stack
->parents
);
2706 print_vma (addr
, ab
, TRUE
, TRUE
);
2707 translate_addresses (info
->abfd
, ab
, info
->f
, info
->syms
);
2708 local
= info
->stack
->flavor
!= NULL
;
2709 if (info
->stack
->method
&& *info
->stack
->method
)
2712 partof
= (char *) info
->stack
->method
;
2718 if (! info
->stack
->method
&& ! append_type (info
, ")"))
2721 t
= pop_type (info
);
2724 fprintf (info
->f
, ";\"\tkind:%c\ttype:%s", kind
, t
);
2726 fputs ("\tfile:", info
->f
);
2729 fprintf (info
->f
, "\tclass:%s", partof
);
2732 fputc ('\n', info
->f
);
2738 /* Write out line number information. */
2741 tg_lineno (void *p ATTRIBUTE_UNUSED
, const char *filename ATTRIBUTE_UNUSED
,
2742 unsigned long lineno ATTRIBUTE_UNUSED
,
2743 bfd_vma addr ATTRIBUTE_UNUSED
)
2748 /* Finish writing out a block. */
2751 tg_end_block (void *p ATTRIBUTE_UNUSED
, bfd_vma addr ATTRIBUTE_UNUSED
)
2756 /* Convert the visibility value into a human readable name. */
2759 visibility_name (enum debug_visibility visibility
)
2765 case DEBUG_VISIBILITY_PUBLIC
:
2768 case DEBUG_VISIBILITY_PRIVATE
:
2771 case DEBUG_VISIBILITY_PROTECTED
:
2774 case DEBUG_VISIBILITY_IGNORE
: