1 /* prdbg.c -- Print out generic debugging information.
2 Copyright 1995, 1996, 1999, 2002, 2003, 2004, 2006, 2007
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 2 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
);
506 sprintf_vma (buf
+ 2, vma
);
510 /* Start a new compilation unit. */
513 pr_start_compilation_unit (void *p
, const char *filename
)
515 struct pr_handle
*info
= (struct pr_handle
*) p
;
517 assert (info
->indent
== 0);
519 fprintf (info
->f
, "%s:\n", filename
);
524 /* Start a source file within a compilation unit. */
527 pr_start_source (void *p
, const char *filename
)
529 struct pr_handle
*info
= (struct pr_handle
*) p
;
531 assert (info
->indent
== 0);
533 fprintf (info
->f
, " %s:\n", filename
);
538 /* Push an empty type onto the type stack. */
541 pr_empty_type (void *p
)
543 struct pr_handle
*info
= (struct pr_handle
*) p
;
545 return push_type (info
, "<undefined>");
548 /* Push a void type onto the type stack. */
551 pr_void_type (void *p
)
553 struct pr_handle
*info
= (struct pr_handle
*) p
;
555 return push_type (info
, "void");
558 /* Push an integer type onto the type stack. */
561 pr_int_type (void *p
, unsigned int size
, bfd_boolean unsignedp
)
563 struct pr_handle
*info
= (struct pr_handle
*) p
;
566 sprintf (ab
, "%sint%d", unsignedp
? "u" : "", size
* 8);
567 return push_type (info
, ab
);
570 /* Push a floating type onto the type stack. */
573 pr_float_type (void *p
, unsigned int size
)
575 struct pr_handle
*info
= (struct pr_handle
*) p
;
579 return push_type (info
, "float");
581 return push_type (info
, "double");
583 sprintf (ab
, "float%d", size
* 8);
584 return push_type (info
, ab
);
587 /* Push a complex type onto the type stack. */
590 pr_complex_type (void *p
, unsigned int size
)
592 struct pr_handle
*info
= (struct pr_handle
*) p
;
594 if (! pr_float_type (p
, size
))
597 return prepend_type (info
, "complex ");
600 /* Push a bfd_boolean type onto the type stack. */
603 pr_bool_type (void *p
, unsigned int size
)
605 struct pr_handle
*info
= (struct pr_handle
*) p
;
608 sprintf (ab
, "bool%d", size
* 8);
610 return push_type (info
, ab
);
613 /* Push an enum type onto the type stack. */
616 pr_enum_type (void *p
, const char *tag
, const char **names
,
617 bfd_signed_vma
*values
)
619 struct pr_handle
*info
= (struct pr_handle
*) p
;
623 if (! push_type (info
, "enum "))
627 if (! append_type (info
, tag
)
628 || ! append_type (info
, " "))
631 if (! append_type (info
, "{ "))
636 if (! append_type (info
, "/* undefined */"))
642 for (i
= 0; names
[i
] != NULL
; i
++)
646 if (! append_type (info
, ", "))
650 if (! append_type (info
, names
[i
]))
653 if (values
[i
] != val
)
657 print_vma (values
[i
], ab
, FALSE
, FALSE
);
658 if (! append_type (info
, " = ")
659 || ! append_type (info
, ab
))
668 return append_type (info
, " }");
671 /* Turn the top type on the stack into a pointer. */
674 pr_pointer_type (void *p
)
676 struct pr_handle
*info
= (struct pr_handle
*) p
;
679 assert (info
->stack
!= NULL
);
681 s
= strchr (info
->stack
->type
, '|');
682 if (s
!= NULL
&& s
[1] == '[')
683 return substitute_type (info
, "(*|)");
684 return substitute_type (info
, "*|");
687 /* Turn the top type on the stack into a function returning that type. */
690 pr_function_type (void *p
, int argcount
, bfd_boolean varargs
)
692 struct pr_handle
*info
= (struct pr_handle
*) p
;
697 assert (info
->stack
!= NULL
);
710 arg_types
= (char **) xmalloc (argcount
* sizeof *arg_types
);
711 for (i
= argcount
- 1; i
>= 0; i
--)
713 if (! substitute_type (info
, ""))
715 arg_types
[i
] = pop_type (info
);
716 if (arg_types
[i
] == NULL
)
718 len
+= strlen (arg_types
[i
]) + 2;
724 /* Now the return type is on the top of the stack. */
727 LITSTRCPY (s
, "(|) (");
730 strcat (s
, "/* unknown */");
735 for (i
= 0; i
< argcount
; i
++)
739 strcat (s
, arg_types
[i
]);
753 if (! substitute_type (info
, s
))
761 /* Turn the top type on the stack into a reference to that type. */
764 pr_reference_type (void *p
)
766 struct pr_handle
*info
= (struct pr_handle
*) p
;
768 assert (info
->stack
!= NULL
);
770 return substitute_type (info
, "&|");
773 /* Make a range type. */
776 pr_range_type (void *p
, bfd_signed_vma lower
, bfd_signed_vma upper
)
778 struct pr_handle
*info
= (struct pr_handle
*) p
;
779 char abl
[20], abu
[20];
781 assert (info
->stack
!= NULL
);
783 if (! substitute_type (info
, ""))
786 print_vma (lower
, abl
, FALSE
, FALSE
);
787 print_vma (upper
, abu
, FALSE
, FALSE
);
789 return (prepend_type (info
, "range (")
790 && append_type (info
, "):")
791 && append_type (info
, abl
)
792 && append_type (info
, ":")
793 && append_type (info
, abu
));
796 /* Make an array type. */
799 pr_array_type (void *p
, bfd_signed_vma lower
, bfd_signed_vma upper
,
802 struct pr_handle
*info
= (struct pr_handle
*) p
;
804 char abl
[20], abu
[20], ab
[50];
806 range_type
= pop_type (info
);
807 if (range_type
== NULL
)
816 print_vma (upper
+ 1, abu
, FALSE
, FALSE
);
817 sprintf (ab
, "|[%s]", abu
);
822 print_vma (lower
, abl
, FALSE
, FALSE
);
823 print_vma (upper
, abu
, FALSE
, FALSE
);
824 sprintf (ab
, "|[%s:%s]", abl
, abu
);
827 if (! substitute_type (info
, ab
))
830 if (strcmp (range_type
, "int") != 0)
832 if (! append_type (info
, ":")
833 || ! append_type (info
, range_type
))
839 if (! append_type (info
, " /* string */"))
846 /* Make a set type. */
849 pr_set_type (void *p
, bfd_boolean bitstringp
)
851 struct pr_handle
*info
= (struct pr_handle
*) p
;
853 if (! substitute_type (info
, ""))
856 if (! prepend_type (info
, "set { ")
857 || ! append_type (info
, " }"))
862 if (! append_type (info
, "/* bitstring */"))
869 /* Make an offset type. */
872 pr_offset_type (void *p
)
874 struct pr_handle
*info
= (struct pr_handle
*) p
;
877 if (! substitute_type (info
, ""))
884 return (substitute_type (info
, "")
885 && prepend_type (info
, " ")
886 && prepend_type (info
, t
)
887 && append_type (info
, "::|"));
890 /* Make a method type. */
893 pr_method_type (void *p
, bfd_boolean domain
, int argcount
, bfd_boolean varargs
)
895 struct pr_handle
*info
= (struct pr_handle
*) p
;
907 if (! substitute_type (info
, ""))
909 domain_type
= pop_type (info
);
910 if (domain_type
== NULL
)
912 if (CONST_STRNEQ (domain_type
, "class ")
913 && strchr (domain_type
+ sizeof "class " - 1, ' ') == NULL
)
914 domain_type
+= sizeof "class " - 1;
915 else if (CONST_STRNEQ (domain_type
, "union class ")
916 && (strchr (domain_type
+ sizeof "union class " - 1, ' ')
918 domain_type
+= sizeof "union class " - 1;
919 len
+= strlen (domain_type
);
931 arg_types
= (char **) xmalloc (argcount
* sizeof *arg_types
);
932 for (i
= argcount
- 1; i
>= 0; i
--)
934 if (! substitute_type (info
, ""))
936 arg_types
[i
] = pop_type (info
);
937 if (arg_types
[i
] == NULL
)
939 len
+= strlen (arg_types
[i
]) + 2;
945 /* Now the return type is on the top of the stack. */
947 s
= (char *) xmalloc (len
);
951 strcpy (s
, domain_type
);
955 strcat (s
, "/* unknown */");
960 for (i
= 0; i
< argcount
; i
++)
964 strcat (s
, arg_types
[i
]);
978 if (! substitute_type (info
, s
))
986 /* Make a const qualified type. */
989 pr_const_type (void *p
)
991 struct pr_handle
*info
= (struct pr_handle
*) p
;
993 return substitute_type (info
, "const |");
996 /* Make a volatile qualified type. */
999 pr_volatile_type (void *p
)
1001 struct pr_handle
*info
= (struct pr_handle
*) p
;
1003 return substitute_type (info
, "volatile |");
1006 /* Start accumulating a struct type. */
1009 pr_start_struct_type (void *p
, const char *tag
, unsigned int id
,
1010 bfd_boolean structp
, unsigned int size
)
1012 struct pr_handle
*info
= (struct pr_handle
*) p
;
1016 if (! push_type (info
, structp
? "struct " : "union "))
1020 if (! append_type (info
, tag
))
1027 sprintf (idbuf
, "%%anon%u", id
);
1028 if (! append_type (info
, idbuf
))
1032 if (! append_type (info
, " {"))
1034 if (size
!= 0 || tag
!= NULL
)
1038 if (! append_type (info
, " /*"))
1043 sprintf (ab
, " size %u", size
);
1044 if (! append_type (info
, ab
))
1049 sprintf (ab
, " id %u", id
);
1050 if (! append_type (info
, ab
))
1053 if (! append_type (info
, " */"))
1056 if (! append_type (info
, "\n"))
1059 info
->stack
->visibility
= DEBUG_VISIBILITY_PUBLIC
;
1061 return indent_type (info
);
1064 /* Output the visibility of a field in a struct. */
1067 pr_fix_visibility (struct pr_handle
*info
, enum debug_visibility visibility
)
1069 const char *s
= NULL
;
1073 assert (info
->stack
!= NULL
);
1075 if (info
->stack
->visibility
== visibility
)
1080 case DEBUG_VISIBILITY_PUBLIC
:
1083 case DEBUG_VISIBILITY_PRIVATE
:
1086 case DEBUG_VISIBILITY_PROTECTED
:
1089 case DEBUG_VISIBILITY_IGNORE
:
1097 /* Trim off a trailing space in the struct string, to make the
1098 output look a bit better, then stick on the visibility string. */
1100 t
= info
->stack
->type
;
1102 assert (t
[len
- 1] == ' ');
1105 if (! append_type (info
, s
)
1106 || ! append_type (info
, ":\n")
1107 || ! indent_type (info
))
1110 info
->stack
->visibility
= visibility
;
1115 /* Add a field to a struct type. */
1118 pr_struct_field (void *p
, const char *name
, bfd_vma bitpos
, bfd_vma bitsize
,
1119 enum debug_visibility visibility
)
1121 struct pr_handle
*info
= (struct pr_handle
*) p
;
1125 if (! substitute_type (info
, name
))
1128 if (! append_type (info
, "; /* "))
1133 print_vma (bitsize
, ab
, TRUE
, FALSE
);
1134 if (! append_type (info
, "bitsize ")
1135 || ! append_type (info
, ab
)
1136 || ! append_type (info
, ", "))
1140 print_vma (bitpos
, ab
, TRUE
, FALSE
);
1141 if (! append_type (info
, "bitpos ")
1142 || ! append_type (info
, ab
)
1143 || ! append_type (info
, " */\n")
1144 || ! indent_type (info
))
1147 t
= pop_type (info
);
1151 if (! pr_fix_visibility (info
, visibility
))
1154 return append_type (info
, t
);
1157 /* Finish a struct type. */
1160 pr_end_struct_type (void *p
)
1162 struct pr_handle
*info
= (struct pr_handle
*) p
;
1165 assert (info
->stack
!= NULL
);
1166 assert (info
->indent
>= 2);
1170 /* Change the trailing indentation to have a close brace. */
1171 s
= info
->stack
->type
+ strlen (info
->stack
->type
) - 2;
1172 assert (s
[0] == ' ' && s
[1] == ' ' && s
[2] == '\0');
1180 /* Start a class type. */
1183 pr_start_class_type (void *p
, const char *tag
, unsigned int id
,
1184 bfd_boolean structp
, unsigned int size
,
1185 bfd_boolean vptr
, bfd_boolean ownvptr
)
1187 struct pr_handle
*info
= (struct pr_handle
*) p
;
1192 if (vptr
&& ! ownvptr
)
1194 tv
= pop_type (info
);
1199 if (! push_type (info
, structp
? "class " : "union class "))
1203 if (! append_type (info
, tag
))
1210 sprintf (idbuf
, "%%anon%u", id
);
1211 if (! append_type (info
, idbuf
))
1215 if (! append_type (info
, " {"))
1217 if (size
!= 0 || vptr
|| ownvptr
|| tag
!= NULL
)
1219 if (! append_type (info
, " /*"))
1226 sprintf (ab
, "%u", size
);
1227 if (! append_type (info
, " size ")
1228 || ! append_type (info
, ab
))
1234 if (! append_type (info
, " vtable "))
1238 if (! append_type (info
, "self "))
1243 if (! append_type (info
, tv
)
1244 || ! append_type (info
, " "))
1253 sprintf (ab
, " id %u", id
);
1254 if (! append_type (info
, ab
))
1258 if (! append_type (info
, " */"))
1262 info
->stack
->visibility
= DEBUG_VISIBILITY_PRIVATE
;
1264 return (append_type (info
, "\n")
1265 && indent_type (info
));
1268 /* Add a static member to a class. */
1271 pr_class_static_member (void *p
, const char *name
, const char *physname
,
1272 enum debug_visibility visibility
)
1274 struct pr_handle
*info
= (struct pr_handle
*) p
;
1277 if (! substitute_type (info
, name
))
1280 if (! prepend_type (info
, "static ")
1281 || ! append_type (info
, "; /* ")
1282 || ! append_type (info
, physname
)
1283 || ! append_type (info
, " */\n")
1284 || ! indent_type (info
))
1287 t
= pop_type (info
);
1291 if (! pr_fix_visibility (info
, visibility
))
1294 return append_type (info
, t
);
1297 /* Add a base class to a class. */
1300 pr_class_baseclass (void *p
, bfd_vma bitpos
, bfd_boolean
virtual,
1301 enum debug_visibility visibility
)
1303 struct pr_handle
*info
= (struct pr_handle
*) p
;
1309 assert (info
->stack
!= NULL
&& info
->stack
->next
!= NULL
);
1311 if (! substitute_type (info
, ""))
1314 t
= pop_type (info
);
1318 if (CONST_STRNEQ (t
, "class "))
1319 t
+= sizeof "class " - 1;
1321 /* Push it back on to take advantage of the prepend_type and
1322 append_type routines. */
1323 if (! push_type (info
, t
))
1328 if (! prepend_type (info
, "virtual "))
1334 case DEBUG_VISIBILITY_PUBLIC
:
1337 case DEBUG_VISIBILITY_PROTECTED
:
1338 prefix
= "protected ";
1340 case DEBUG_VISIBILITY_PRIVATE
:
1341 prefix
= "private ";
1344 prefix
= "/* unknown visibility */ ";
1348 if (! prepend_type (info
, prefix
))
1353 print_vma (bitpos
, ab
, TRUE
, FALSE
);
1354 if (! append_type (info
, " /* bitpos ")
1355 || ! append_type (info
, ab
)
1356 || ! append_type (info
, " */"))
1360 /* Now the top of the stack is something like "public A / * bitpos
1361 10 * /". The next element on the stack is something like "class
1362 xx { / * size 8 * /\n...". We want to substitute the top of the
1363 stack in before the {. */
1364 s
= strchr (info
->stack
->next
->type
, '{');
1368 /* If there is already a ':', then we already have a baseclass, and
1369 we must append this one after a comma. */
1370 for (l
= info
->stack
->next
->type
; l
!= s
; l
++)
1373 if (! prepend_type (info
, l
== s
? " : " : ", "))
1376 t
= pop_type (info
);
1380 n
= (char *) xmalloc (strlen (info
->stack
->type
) + strlen (t
) + 1);
1381 memcpy (n
, info
->stack
->type
, s
- info
->stack
->type
);
1382 strcpy (n
+ (s
- info
->stack
->type
), t
);
1385 free (info
->stack
->type
);
1386 info
->stack
->type
= n
;
1393 /* Start adding a method to a class. */
1396 pr_class_start_method (void *p
, const char *name
)
1398 struct pr_handle
*info
= (struct pr_handle
*) p
;
1400 assert (info
->stack
!= NULL
);
1401 info
->stack
->method
= name
;
1405 /* Add a variant to a method. */
1408 pr_class_method_variant (void *p
, const char *physname
,
1409 enum debug_visibility visibility
,
1410 bfd_boolean constp
, bfd_boolean volatilep
,
1411 bfd_vma voffset
, bfd_boolean context
)
1413 struct pr_handle
*info
= (struct pr_handle
*) p
;
1417 assert (info
->stack
!= NULL
);
1418 assert (info
->stack
->next
!= NULL
);
1420 /* Put the const and volatile qualifiers on the type. */
1423 if (! append_type (info
, " volatile"))
1428 if (! append_type (info
, " const"))
1432 /* Stick the name of the method into its type. */
1433 if (! substitute_type (info
,
1435 ? info
->stack
->next
->next
->method
1436 : info
->stack
->next
->method
)))
1440 method_type
= pop_type (info
);
1441 if (method_type
== NULL
)
1444 /* Pull off the context type if there is one. */
1446 context_type
= NULL
;
1449 context_type
= pop_type (info
);
1450 if (context_type
== NULL
)
1454 /* Now the top of the stack is the class. */
1456 if (! pr_fix_visibility (info
, visibility
))
1459 if (! append_type (info
, method_type
)
1460 || ! append_type (info
, " /* ")
1461 || ! append_type (info
, physname
)
1462 || ! append_type (info
, " "))
1464 if (context
|| voffset
!= 0)
1470 if (! append_type (info
, "context ")
1471 || ! append_type (info
, context_type
)
1472 || ! append_type (info
, " "))
1475 print_vma (voffset
, ab
, TRUE
, FALSE
);
1476 if (! append_type (info
, "voffset ")
1477 || ! append_type (info
, ab
))
1481 return (append_type (info
, " */;\n")
1482 && indent_type (info
));
1485 /* Add a static variant to a method. */
1488 pr_class_static_method_variant (void *p
, const char *physname
,
1489 enum debug_visibility visibility
,
1490 bfd_boolean constp
, bfd_boolean volatilep
)
1492 struct pr_handle
*info
= (struct pr_handle
*) p
;
1495 assert (info
->stack
!= NULL
);
1496 assert (info
->stack
->next
!= NULL
);
1497 assert (info
->stack
->next
->method
!= NULL
);
1499 /* Put the const and volatile qualifiers on the type. */
1502 if (! append_type (info
, " volatile"))
1507 if (! append_type (info
, " const"))
1511 /* Mark it as static. */
1512 if (! prepend_type (info
, "static "))
1515 /* Stick the name of the method into its type. */
1516 if (! substitute_type (info
, info
->stack
->next
->method
))
1520 method_type
= pop_type (info
);
1521 if (method_type
== NULL
)
1524 /* Now the top of the stack is the class. */
1526 if (! pr_fix_visibility (info
, visibility
))
1529 return (append_type (info
, method_type
)
1530 && append_type (info
, " /* ")
1531 && append_type (info
, physname
)
1532 && append_type (info
, " */;\n")
1533 && indent_type (info
));
1536 /* Finish up a method. */
1539 pr_class_end_method (void *p
)
1541 struct pr_handle
*info
= (struct pr_handle
*) p
;
1543 info
->stack
->method
= NULL
;
1547 /* Finish up a class. */
1550 pr_end_class_type (void *p
)
1552 return pr_end_struct_type (p
);
1555 /* Push a type on the stack using a typedef name. */
1558 pr_typedef_type (void *p
, const char *name
)
1560 struct pr_handle
*info
= (struct pr_handle
*) p
;
1562 return push_type (info
, name
);
1565 /* Push a type on the stack using a tag name. */
1568 pr_tag_type (void *p
, const char *name
, unsigned int id
,
1569 enum debug_type_kind kind
)
1571 struct pr_handle
*info
= (struct pr_handle
*) p
;
1572 const char *t
, *tag
;
1577 case DEBUG_KIND_STRUCT
:
1580 case DEBUG_KIND_UNION
:
1583 case DEBUG_KIND_ENUM
:
1586 case DEBUG_KIND_CLASS
:
1589 case DEBUG_KIND_UNION_CLASS
:
1597 if (! push_type (info
, t
))
1603 sprintf (idbuf
, "%%anon%u", id
);
1607 if (! append_type (info
, tag
))
1609 if (name
!= NULL
&& kind
!= DEBUG_KIND_ENUM
)
1611 sprintf (idbuf
, " /* id %u */", id
);
1612 if (! append_type (info
, idbuf
))
1619 /* Output a typedef. */
1622 pr_typdef (void *p
, const char *name
)
1624 struct pr_handle
*info
= (struct pr_handle
*) p
;
1627 if (! substitute_type (info
, name
))
1630 s
= pop_type (info
);
1635 fprintf (info
->f
, "typedef %s;\n", s
);
1642 /* Output a tag. The tag should already be in the string on the
1643 stack, so all we have to do here is print it out. */
1646 pr_tag (void *p
, const char *name ATTRIBUTE_UNUSED
)
1648 struct pr_handle
*info
= (struct pr_handle
*) p
;
1651 t
= pop_type (info
);
1656 fprintf (info
->f
, "%s;\n", t
);
1663 /* Output an integer constant. */
1666 pr_int_constant (void *p
, const char *name
, bfd_vma val
)
1668 struct pr_handle
*info
= (struct pr_handle
*) p
;
1672 print_vma (val
, ab
, FALSE
, FALSE
);
1673 fprintf (info
->f
, "const int %s = %s;\n", name
, ab
);
1677 /* Output a floating point constant. */
1680 pr_float_constant (void *p
, const char *name
, double val
)
1682 struct pr_handle
*info
= (struct pr_handle
*) p
;
1685 fprintf (info
->f
, "const double %s = %g;\n", name
, val
);
1689 /* Output a typed constant. */
1692 pr_typed_constant (void *p
, const char *name
, bfd_vma val
)
1694 struct pr_handle
*info
= (struct pr_handle
*) p
;
1698 t
= pop_type (info
);
1703 print_vma (val
, ab
, FALSE
, FALSE
);
1704 fprintf (info
->f
, "const %s %s = %s;\n", t
, name
, ab
);
1711 /* Output a variable. */
1714 pr_variable (void *p
, const char *name
, enum debug_var_kind kind
,
1717 struct pr_handle
*info
= (struct pr_handle
*) p
;
1721 if (! substitute_type (info
, name
))
1724 t
= pop_type (info
);
1732 case DEBUG_LOCAL_STATIC
:
1733 fprintf (info
->f
, "static ");
1735 case DEBUG_REGISTER
:
1736 fprintf (info
->f
, "register ");
1741 print_vma (val
, ab
, TRUE
, TRUE
);
1742 fprintf (info
->f
, "%s /* %s */;\n", t
, ab
);
1749 /* Start outputting a function. */
1752 pr_start_function (void *p
, const char *name
, bfd_boolean global
)
1754 struct pr_handle
*info
= (struct pr_handle
*) p
;
1757 if (! substitute_type (info
, name
))
1760 t
= pop_type (info
);
1766 fprintf (info
->f
, "static ");
1767 fprintf (info
->f
, "%s (", t
);
1769 info
->parameter
= 1;
1774 /* Output a function parameter. */
1777 pr_function_parameter (void *p
, const char *name
,
1778 enum debug_parm_kind kind
, bfd_vma val
)
1780 struct pr_handle
*info
= (struct pr_handle
*) p
;
1784 if (kind
== DEBUG_PARM_REFERENCE
1785 || kind
== DEBUG_PARM_REF_REG
)
1787 if (! pr_reference_type (p
))
1791 if (! substitute_type (info
, name
))
1794 t
= pop_type (info
);
1798 if (info
->parameter
!= 1)
1799 fprintf (info
->f
, ", ");
1801 if (kind
== DEBUG_PARM_REG
|| kind
== DEBUG_PARM_REF_REG
)
1802 fprintf (info
->f
, "register ");
1804 print_vma (val
, ab
, TRUE
, TRUE
);
1805 fprintf (info
->f
, "%s /* %s */", t
, ab
);
1814 /* Start writing out a block. */
1817 pr_start_block (void *p
, bfd_vma addr
)
1819 struct pr_handle
*info
= (struct pr_handle
*) p
;
1822 if (info
->parameter
> 0)
1824 fprintf (info
->f
, ")\n");
1825 info
->parameter
= 0;
1829 print_vma (addr
, ab
, TRUE
, TRUE
);
1830 fprintf (info
->f
, "{ /* %s */\n", ab
);
1837 /* Write out line number information. */
1840 pr_lineno (void *p
, const char *filename
, unsigned long lineno
, bfd_vma addr
)
1842 struct pr_handle
*info
= (struct pr_handle
*) p
;
1846 print_vma (addr
, ab
, TRUE
, TRUE
);
1847 fprintf (info
->f
, "/* file %s line %lu addr %s */\n", filename
, lineno
, ab
);
1852 /* Finish writing out a block. */
1855 pr_end_block (void *p
, bfd_vma addr
)
1857 struct pr_handle
*info
= (struct pr_handle
*) p
;
1863 print_vma (addr
, ab
, TRUE
, TRUE
);
1864 fprintf (info
->f
, "} /* %s */\n", ab
);
1869 /* Finish writing out a function. */
1872 pr_end_function (void *p ATTRIBUTE_UNUSED
)
1877 /* Tags style generation functions start here. */
1879 /* Variables for address to line translation. */
1881 static const char *filename
;
1882 static const char *functionname
;
1883 static unsigned int line
;
1884 static bfd_boolean found
;
1886 /* Look for an address in a section. This is called via
1887 bfd_map_over_sections. */
1890 find_address_in_section (bfd
*abfd
, asection
*section
, void *data
)
1894 asymbol
**syms
= (asymbol
**) data
;
1899 if ((bfd_get_section_flags (abfd
, section
) & SEC_ALLOC
) == 0)
1902 vma
= bfd_get_section_vma (abfd
, section
);
1906 size
= bfd_get_section_size (section
);
1907 if (pc
>= vma
+ size
)
1910 found
= bfd_find_nearest_line (abfd
, section
, syms
, pc
- vma
,
1911 &filename
, &functionname
, &line
);
1915 translate_addresses (bfd
*abfd
, char *addr_hex
, FILE *f
, asymbol
**syms
)
1917 pc
= bfd_scan_vma (addr_hex
, NULL
, 16);
1919 bfd_map_over_sections (abfd
, find_address_in_section
, syms
);
1924 fprintf (f
, "%u", line
);
1927 /* Start a new compilation unit. */
1930 tg_start_compilation_unit (void * p
, const char *filename ATTRIBUTE_UNUSED
)
1932 struct pr_handle
*info
= (struct pr_handle
*) p
;
1934 fprintf (stderr
, "New compilation unit: %s\n", filename
);
1936 free (info
->filename
);
1937 /* Should it be relative? best way to do it here?. */
1938 info
->filename
= strdup (filename
);
1943 /* Start a source file within a compilation unit. */
1946 tg_start_source (void *p
, const char *filename
)
1948 struct pr_handle
*info
= (struct pr_handle
*) p
;
1950 free (info
->filename
);
1951 /* Should it be relative? best way to do it here?. */
1952 info
->filename
= strdup (filename
);
1957 /* Push an enum type onto the type stack. */
1960 tg_enum_type (void *p
, const char *tag
, const char **names
,
1961 bfd_signed_vma
*values
)
1963 struct pr_handle
*info
= (struct pr_handle
*) p
;
1968 if (! pr_enum_type (p
, tag
, names
, values
))
1971 name
= tag
? tag
: "unknown";
1972 /* Generate an entry for the enum. */
1974 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:e\ttype:%s\n", tag
,
1975 info
->filename
, info
->stack
->type
);
1977 /* Generate entries for the values. */
1980 for (i
= 0; names
[i
] != NULL
; i
++)
1982 print_vma (values
[i
], ab
, FALSE
, FALSE
);
1983 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:g\tenum:%s\tvalue:%s\n",
1984 names
[i
], info
->filename
, name
, ab
);
1991 /* Start accumulating a struct type. */
1994 tg_start_struct_type (void *p
, const char *tag
, unsigned int id
,
1995 bfd_boolean structp
,
1996 unsigned int size ATTRIBUTE_UNUSED
)
1998 struct pr_handle
*info
= (struct pr_handle
*) p
;
2007 sprintf (idbuf
, "%%anon%u", id
);
2010 if (! push_type (info
, name
))
2013 info
->stack
->flavor
= structp
? "struct" : "union";
2015 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:%c\n", name
, info
->filename
,
2016 info
->stack
->flavor
[0]);
2018 info
->stack
->visibility
= DEBUG_VISIBILITY_PUBLIC
;
2020 return indent_type (info
);
2023 /* Output the visibility of a field in a struct. */
2026 tg_fix_visibility (struct pr_handle
*info
, enum debug_visibility visibility
)
2028 assert (info
->stack
!= NULL
);
2030 if (info
->stack
->visibility
== visibility
)
2033 assert (info
->stack
->visibility
!= DEBUG_VISIBILITY_IGNORE
);
2035 info
->stack
->visibility
= visibility
;
2040 /* Add a field to a struct type. */
2043 tg_struct_field (void *p
, const char *name
, bfd_vma bitpos ATTRIBUTE_UNUSED
,
2044 bfd_vma bitsize ATTRIBUTE_UNUSED
,
2045 enum debug_visibility visibility
)
2047 struct pr_handle
*info
= (struct pr_handle
*) p
;
2050 t
= pop_type (info
);
2054 if (! tg_fix_visibility (info
, visibility
))
2057 /* It happens, a bug? */
2061 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:m\ttype:%s\t%s:%s\taccess:%s\n",
2062 name
, info
->filename
, t
, info
->stack
->flavor
, info
->stack
->type
,
2063 visibility_name (visibility
));
2068 /* Finish a struct type. */
2071 tg_end_struct_type (void *p ATTRIBUTE_UNUSED
)
2073 struct pr_handle
*info
= (struct pr_handle
*) p
;
2074 assert (info
->stack
!= NULL
);
2079 /* Start a class type. */
2082 tg_start_class_type (void *p
, const char *tag
, unsigned int id
,
2083 bfd_boolean structp
, unsigned int size
,
2084 bfd_boolean vptr
, bfd_boolean ownvptr
)
2086 struct pr_handle
*info
= (struct pr_handle
*) p
;
2092 if (vptr
&& ! ownvptr
)
2094 tv
= pop_type (info
);
2105 sprintf (idbuf
, "%%anon%u", id
);
2109 if (! push_type (info
, name
))
2112 info
->stack
->flavor
= structp
? "class" : "union class";
2113 info
->stack
->parents
= NULL
;
2114 info
->stack
->num_parents
= 0;
2116 if (size
!= 0 || vptr
|| ownvptr
|| tag
!= NULL
)
2120 if (! append_type (info
, " vtable "))
2124 if (! append_type (info
, "self "))
2129 if (! append_type (info
, tv
)
2130 || ! append_type (info
, " "))
2136 info
->stack
->visibility
= DEBUG_VISIBILITY_PRIVATE
;
2141 /* Add a static member to a class. */
2144 tg_class_static_member (void *p
, const char *name
,
2145 const char *physname ATTRIBUTE_UNUSED
,
2146 enum debug_visibility visibility
)
2148 struct pr_handle
*info
= (struct pr_handle
*) p
;
2150 int len_var
, len_class
;
2153 len_var
= strlen (name
);
2154 len_class
= strlen (info
->stack
->next
->type
);
2155 full_name
= xmalloc (len_var
+ len_class
+ 3);
2158 sprintf (full_name
, "%s::%s", info
->stack
->next
->type
, name
);
2160 if (! substitute_type (info
, full_name
))
2163 if (! prepend_type (info
, "static "))
2166 t
= pop_type (info
);
2170 if (! tg_fix_visibility (info
, visibility
))
2173 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:x\ttype:%s\tclass:%s\taccess:%s\n",
2174 name
, info
->filename
, t
, info
->stack
->type
,
2175 visibility_name (visibility
));
2182 /* Add a base class to a class. */
2185 tg_class_baseclass (void *p
, bfd_vma bitpos ATTRIBUTE_UNUSED
,
2186 bfd_boolean
virtual, enum debug_visibility visibility
)
2188 struct pr_handle
*info
= (struct pr_handle
*) p
;
2192 assert (info
->stack
!= NULL
&& info
->stack
->next
!= NULL
);
2194 t
= pop_type (info
);
2198 if (CONST_STRNEQ (t
, "class "))
2199 t
+= sizeof "class " - 1;
2201 /* Push it back on to take advantage of the prepend_type and
2202 append_type routines. */
2203 if (! push_type (info
, t
))
2208 if (! prepend_type (info
, "virtual "))
2214 case DEBUG_VISIBILITY_PUBLIC
:
2217 case DEBUG_VISIBILITY_PROTECTED
:
2218 prefix
= "protected ";
2220 case DEBUG_VISIBILITY_PRIVATE
:
2221 prefix
= "private ";
2224 prefix
= "/* unknown visibility */ ";
2228 if (! prepend_type (info
, prefix
))
2231 t
= pop_type (info
);
2235 if (info
->stack
->num_parents
&& ! append_parent (info
, ", "))
2238 if (! append_parent (info
, t
))
2240 info
->stack
->num_parents
++;
2247 /* Add a variant to a method. */
2250 tg_class_method_variant (void *p
, const char *physname ATTRIBUTE_UNUSED
,
2251 enum debug_visibility visibility
,
2252 bfd_boolean constp
, bfd_boolean volatilep
,
2253 bfd_vma voffset ATTRIBUTE_UNUSED
,
2254 bfd_boolean context
)
2256 struct pr_handle
*info
= (struct pr_handle
*) p
;
2261 assert (info
->stack
!= NULL
);
2262 assert (info
->stack
->next
!= NULL
);
2264 /* Put the const and volatile qualifiers on the type. */
2267 if (! append_type (info
, " volatile"))
2272 if (! append_type (info
, " const"))
2276 method_name
= strdup (context
? info
->stack
->next
->next
->method
2277 : info
->stack
->next
->method
);
2279 /* Stick the name of the method into its type. */
2280 if (! substitute_type (info
, method_name
))
2284 method_type
= pop_type (info
);
2285 if (method_type
== NULL
)
2288 /* Pull off the context type if there is one. */
2290 context_type
= NULL
;
2293 context_type
= pop_type (info
);
2294 if (context_type
== NULL
)
2298 /* Now the top of the stack is the class. */
2299 if (! tg_fix_visibility (info
, visibility
))
2302 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:p\ttype:%s\tclass:%s\n",
2303 method_name
, info
->filename
, method_type
, info
->stack
->type
);
2306 free (context_type
);
2311 /* Add a static variant to a method. */
2314 tg_class_static_method_variant (void *p
,
2315 const char *physname ATTRIBUTE_UNUSED
,
2316 enum debug_visibility visibility
,
2317 bfd_boolean constp
, bfd_boolean volatilep
)
2319 struct pr_handle
*info
= (struct pr_handle
*) p
;
2323 assert (info
->stack
!= NULL
);
2324 assert (info
->stack
->next
!= NULL
);
2325 assert (info
->stack
->next
->method
!= NULL
);
2327 /* Put the const and volatile qualifiers on the type. */
2330 if (! append_type (info
, " volatile"))
2335 if (! append_type (info
, " const"))
2339 /* Mark it as static. */
2340 if (! prepend_type (info
, "static "))
2343 method_name
= strdup (info
->stack
->next
->method
);
2344 /* Stick the name of the method into its type. */
2345 if (! substitute_type (info
, info
->stack
->next
->method
))
2349 method_type
= pop_type (info
);
2350 if (method_type
== NULL
)
2353 /* Now the top of the stack is the class. */
2354 if (! tg_fix_visibility (info
, visibility
))
2357 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:p\ttype:%s\tclass:%s\taccess:%s\n",
2358 method_name
, info
->filename
, method_type
, info
->stack
->type
,
2359 visibility_name (visibility
));
2366 /* Finish up a class. */
2369 tg_end_class_type (void *p
)
2371 struct pr_handle
*info
= (struct pr_handle
*) p
;
2373 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:c\ttype:%s", info
->stack
->type
,
2374 info
->filename
, info
->stack
->flavor
);
2375 if (info
->stack
->num_parents
)
2377 fprintf (info
->f
, "\tinherits:%s", info
->stack
->parents
);
2378 free (info
->stack
->parents
);
2380 fputc ('\n', info
->f
);
2382 return tg_end_struct_type (p
);
2385 /* Push a type on the stack using a tag name. */
2388 tg_tag_type (void *p
, const char *name
, unsigned int id
,
2389 enum debug_type_kind kind
)
2391 struct pr_handle
*info
= (struct pr_handle
*) p
;
2392 const char *t
, *tag
;
2397 case DEBUG_KIND_STRUCT
:
2400 case DEBUG_KIND_UNION
:
2403 case DEBUG_KIND_ENUM
:
2406 case DEBUG_KIND_CLASS
:
2409 case DEBUG_KIND_UNION_CLASS
:
2417 if (! push_type (info
, t
))
2423 sprintf (idbuf
, "%%anon%u", id
);
2427 if (! append_type (info
, tag
))
2433 /* Output a typedef. */
2436 tg_typdef (void *p
, const char *name
)
2438 struct pr_handle
*info
= (struct pr_handle
*) p
;
2441 s
= pop_type (info
);
2445 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:t\ttype:%s\n", name
,
2453 /* Output a tag. The tag should already be in the string on the
2454 stack, so all we have to do here is print it out. */
2457 tg_tag (void *p ATTRIBUTE_UNUSED
, const char *name ATTRIBUTE_UNUSED
)
2459 struct pr_handle
*info
= (struct pr_handle
*) p
;
2462 t
= pop_type (info
);
2470 /* Output an integer constant. */
2473 tg_int_constant (void *p
, const char *name
, bfd_vma val
)
2475 struct pr_handle
*info
= (struct pr_handle
*) p
;
2479 print_vma (val
, ab
, FALSE
, FALSE
);
2480 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:v\ttype:const int\tvalue:%s\n",
2481 name
, info
->filename
, ab
);
2485 /* Output a floating point constant. */
2488 tg_float_constant (void *p
, const char *name
, double val
)
2490 struct pr_handle
*info
= (struct pr_handle
*) p
;
2493 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:v\ttype:const double\tvalue:%g\n",
2494 name
, info
->filename
, val
);
2498 /* Output a typed constant. */
2501 tg_typed_constant (void *p
, const char *name
, bfd_vma val
)
2503 struct pr_handle
*info
= (struct pr_handle
*) p
;
2507 t
= pop_type (info
);
2512 print_vma (val
, ab
, FALSE
, FALSE
);
2513 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:v\ttype:const %s\tvalue:%s\n",
2514 name
, info
->filename
, t
, ab
);
2521 /* Output a variable. */
2524 tg_variable (void *p
, const char *name
, enum debug_var_kind kind
,
2525 bfd_vma val ATTRIBUTE_UNUSED
)
2527 struct pr_handle
*info
= (struct pr_handle
*) p
;
2528 char *t
, *dname
, *from_class
;
2530 t
= pop_type (info
);
2535 if (info
->demangler
)
2536 dname
= info
->demangler (info
->abfd
, name
, DMGL_ANSI
| DMGL_PARAMS
);
2542 sep
= strstr (dname
, "::");
2550 /* Obscure types as vts and type_info nodes. */
2554 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:v\ttype:%s", name
, info
->filename
, t
);
2559 case DEBUG_LOCAL_STATIC
:
2560 fprintf (info
->f
, "\tfile:");
2562 case DEBUG_REGISTER
:
2563 fprintf (info
->f
, "\tregister:");
2570 fprintf (info
->f
, "\tclass:%s", from_class
);
2575 fprintf (info
->f
, "\n");
2582 /* Start outputting a function. */
2585 tg_start_function (void *p
, const char *name
, bfd_boolean global
)
2587 struct pr_handle
*info
= (struct pr_handle
*) p
;
2591 info
->stack
->flavor
= "static";
2593 info
->stack
->flavor
= NULL
;
2596 if (info
->demangler
)
2597 dname
= info
->demangler (info
->abfd
, name
, DMGL_ANSI
| DMGL_PARAMS
);
2599 if (! substitute_type (info
, dname
? dname
: name
))
2602 info
->stack
->method
= NULL
;
2606 sep
= strstr (dname
, "::");
2609 info
->stack
->method
= dname
;
2615 info
->stack
->method
= "";
2618 sep
= strchr (name
, '(');
2621 /* Obscure functions as type_info function. */
2624 info
->stack
->parents
= strdup (name
);
2626 if (! info
->stack
->method
&& ! append_type (info
, "("))
2629 info
->parameter
= 1;
2634 /* Output a function parameter. */
2637 tg_function_parameter (void *p
, const char *name
, enum debug_parm_kind kind
,
2638 bfd_vma val ATTRIBUTE_UNUSED
)
2640 struct pr_handle
*info
= (struct pr_handle
*) p
;
2643 if (kind
== DEBUG_PARM_REFERENCE
2644 || kind
== DEBUG_PARM_REF_REG
)
2646 if (! pr_reference_type (p
))
2650 if (! substitute_type (info
, name
))
2653 t
= pop_type (info
);
2657 if (! info
->stack
->method
)
2659 if (info
->parameter
!= 1 && ! append_type (info
, ", "))
2662 if (kind
== DEBUG_PARM_REG
|| kind
== DEBUG_PARM_REF_REG
)
2663 if (! append_type (info
, "register "))
2666 if (! append_type (info
, t
))
2677 /* Start writing out a block. */
2680 tg_start_block (void *p
, bfd_vma addr
)
2682 struct pr_handle
*info
= (struct pr_handle
*) p
;
2683 char ab
[20], kind
, *partof
;
2687 if (info
->parameter
> 0)
2689 info
->parameter
= 0;
2692 fprintf (info
->f
, "%s\t%s\t", info
->stack
->parents
, info
->filename
);
2693 free (info
->stack
->parents
);
2695 print_vma (addr
, ab
, TRUE
, TRUE
);
2696 translate_addresses (info
->abfd
, ab
, info
->f
, info
->syms
);
2697 local
= info
->stack
->flavor
!= NULL
;
2698 if (info
->stack
->method
&& *info
->stack
->method
)
2701 partof
= (char *) info
->stack
->method
;
2707 if (! info
->stack
->method
&& ! append_type (info
, ")"))
2710 t
= pop_type (info
);
2713 fprintf (info
->f
, ";\"\tkind:%c\ttype:%s", kind
, t
);
2715 fputs ("\tfile:", info
->f
);
2718 fprintf (info
->f
, "\tclass:%s", partof
);
2721 fputc ('\n', info
->f
);
2727 /* Write out line number information. */
2730 tg_lineno (void *p ATTRIBUTE_UNUSED
, const char *filename ATTRIBUTE_UNUSED
,
2731 unsigned long lineno ATTRIBUTE_UNUSED
,
2732 bfd_vma addr ATTRIBUTE_UNUSED
)
2737 /* Finish writing out a block. */
2740 tg_end_block (void *p ATTRIBUTE_UNUSED
, bfd_vma addr ATTRIBUTE_UNUSED
)
2745 /* Convert the visibility value into a human readable name. */
2748 visibility_name (enum debug_visibility visibility
)
2754 case DEBUG_VISIBILITY_PUBLIC
:
2757 case DEBUG_VISIBILITY_PRIVATE
:
2760 case DEBUG_VISIBILITY_PROTECTED
:
2763 case DEBUG_VISIBILITY_IGNORE
: