1 /* prdbg.c -- Print out generic debugging information.
2 Copyright 1995, 1996, 2002, 2003 Free Software Foundation, Inc.
3 Written by Ian Lance Taylor <ian@cygnus.com>.
4 Tags style generation written by Salvador E. Tropea <set@computer.org>.
6 This file is part of GNU Binutils.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
23 /* This file prints out the generic debugging information, by
24 supplying a set of routines to debug_write. */
31 #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 *);
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. */
80 PARAMS ((struct pr_handle
*));
81 static bfd_boolean push_type
82 PARAMS ((struct pr_handle
*, const char *));
83 static bfd_boolean prepend_type
84 PARAMS ((struct pr_handle
*, const char *));
85 static bfd_boolean append_type
86 PARAMS ((struct pr_handle
*, const char *));
87 static bfd_boolean substitute_type
88 PARAMS ((struct pr_handle
*, const char *));
89 static bfd_boolean indent_type
90 PARAMS ((struct pr_handle
*));
92 PARAMS ((struct pr_handle
*));
94 PARAMS ((bfd_vma
, char *, bfd_boolean
, bfd_boolean
));
95 static bfd_boolean pr_fix_visibility
96 PARAMS ((struct pr_handle
*, enum debug_visibility
));
97 static bfd_boolean pr_start_compilation_unit
98 PARAMS ((PTR
, const char *));
99 static bfd_boolean pr_start_source
100 PARAMS ((PTR
, const char *));
101 static bfd_boolean pr_empty_type
103 static bfd_boolean pr_void_type
105 static bfd_boolean pr_int_type
106 PARAMS ((PTR
, unsigned int, bfd_boolean
));
107 static bfd_boolean pr_float_type
108 PARAMS ((PTR
, unsigned int));
109 static bfd_boolean pr_complex_type
110 PARAMS ((PTR
, unsigned int));
111 static bfd_boolean pr_bool_type
112 PARAMS ((PTR
, unsigned int));
113 static bfd_boolean pr_enum_type
114 PARAMS ((PTR
, const char *, const char **, bfd_signed_vma
*));
115 static bfd_boolean pr_pointer_type
117 static bfd_boolean pr_function_type
118 PARAMS ((PTR
, int, bfd_boolean
));
119 static bfd_boolean pr_reference_type
121 static bfd_boolean pr_range_type
122 PARAMS ((PTR
, bfd_signed_vma
, bfd_signed_vma
));
123 static bfd_boolean pr_array_type
124 PARAMS ((PTR
, bfd_signed_vma
, bfd_signed_vma
, bfd_boolean
));
125 static bfd_boolean pr_set_type
126 PARAMS ((PTR
, bfd_boolean
));
127 static bfd_boolean pr_offset_type
129 static bfd_boolean pr_method_type
130 PARAMS ((PTR
, bfd_boolean
, int, bfd_boolean
));
131 static bfd_boolean pr_const_type
133 static bfd_boolean pr_volatile_type
135 static bfd_boolean pr_start_struct_type
136 PARAMS ((PTR
, const char *, unsigned int, bfd_boolean
, unsigned int));
137 static bfd_boolean pr_struct_field
138 PARAMS ((PTR
, const char *, bfd_vma
, bfd_vma
, enum debug_visibility
));
139 static bfd_boolean pr_end_struct_type
141 static bfd_boolean pr_start_class_type
142 PARAMS ((PTR
, const char *, unsigned int, bfd_boolean
, unsigned int,
143 bfd_boolean
, bfd_boolean
));
144 static bfd_boolean pr_class_static_member
145 PARAMS ((PTR
, const char *, const char *, enum debug_visibility
));
146 static bfd_boolean pr_class_baseclass
147 PARAMS ((PTR
, bfd_vma
, bfd_boolean
, enum debug_visibility
));
148 static bfd_boolean pr_class_start_method
149 PARAMS ((PTR
, const char *));
150 static bfd_boolean pr_class_method_variant
151 PARAMS ((PTR
, const char *, enum debug_visibility
, bfd_boolean
, bfd_boolean
,
152 bfd_vma
, bfd_boolean
));
153 static bfd_boolean pr_class_static_method_variant
154 PARAMS ((PTR
, const char *, enum debug_visibility
, bfd_boolean
,
156 static bfd_boolean pr_class_end_method
158 static bfd_boolean pr_end_class_type
160 static bfd_boolean pr_typedef_type
161 PARAMS ((PTR
, const char *));
162 static bfd_boolean pr_tag_type
163 PARAMS ((PTR
, const char *, unsigned int, enum debug_type_kind
));
164 static bfd_boolean pr_typdef
165 PARAMS ((PTR
, const char *));
166 static bfd_boolean pr_tag
167 PARAMS ((PTR
, const char *));
168 static bfd_boolean pr_int_constant
169 PARAMS ((PTR
, const char *, bfd_vma
));
170 static bfd_boolean pr_float_constant
171 PARAMS ((PTR
, const char *, double));
172 static bfd_boolean pr_typed_constant
173 PARAMS ((PTR
, const char *, bfd_vma
));
174 static bfd_boolean pr_variable
175 PARAMS ((PTR
, const char *, enum debug_var_kind
, bfd_vma
));
176 static bfd_boolean pr_start_function
177 PARAMS ((PTR
, const char *, bfd_boolean
));
178 static bfd_boolean pr_function_parameter
179 PARAMS ((PTR
, const char *, enum debug_parm_kind
, bfd_vma
));
180 static bfd_boolean pr_start_block
181 PARAMS ((PTR
, bfd_vma
));
182 static bfd_boolean pr_end_block
183 PARAMS ((PTR
, bfd_vma
));
184 static bfd_boolean pr_end_function
186 static bfd_boolean pr_lineno
187 PARAMS ((PTR
, const char *, unsigned long, bfd_vma
));
188 static bfd_boolean
append_parent (struct pr_handle
*, const char *);
189 /* Only used by tg_ code. */
190 static bfd_boolean
tg_fix_visibility (struct pr_handle
*, enum debug_visibility
);
191 static void find_address_in_section (bfd
*, asection
*, void *);
192 static void translate_addresses (bfd
*, char *, FILE *, asymbol
**);
193 static const char *visibility_name (enum debug_visibility
);
194 /* Tags style replacements. */
195 static bfd_boolean
tg_start_compilation_unit (void *, const char *);
196 static bfd_boolean
tg_start_source (void *, const char *);
197 static bfd_boolean
tg_enum_type (void *, const char *, const char **, bfd_signed_vma
*);
198 static bfd_boolean
tg_start_struct_type (void *, const char *, unsigned int, bfd_boolean
, unsigned int);
199 static bfd_boolean
pr_struct_field (void *, const char *, bfd_vma
, bfd_vma
, enum debug_visibility
);
200 static bfd_boolean
tg_struct_field (void *, const char *, bfd_vma
, bfd_vma
, enum debug_visibility
);
201 static bfd_boolean
tg_struct_field (void *, const char *, bfd_vma
, bfd_vma
, enum debug_visibility
);
202 static bfd_boolean
tg_end_struct_type (void *);
203 static bfd_boolean
tg_start_class_type (void *, const char *, unsigned int, bfd_boolean
, unsigned int, bfd_boolean
, bfd_boolean
);
204 static bfd_boolean
tg_class_static_member (void *, const char *, const char *, enum debug_visibility
);
205 static bfd_boolean
tg_class_baseclass (void *, bfd_vma
, bfd_boolean
, enum debug_visibility
);
206 static bfd_boolean
tg_class_method_variant (void *, const char *, enum debug_visibility
, bfd_boolean
, bfd_boolean
, bfd_vma
, bfd_boolean
);
207 static bfd_boolean
tg_class_static_method_variant (void *, const char *, enum debug_visibility
, bfd_boolean
, bfd_boolean
);
208 static bfd_boolean
tg_end_class_type (void *);
209 static bfd_boolean
tg_tag_type (void *, const char *, unsigned int, enum debug_type_kind
);
210 static bfd_boolean
tg_typdef (void *, const char *);
211 static bfd_boolean
tg_tag (void *, const char *);
212 static bfd_boolean
tg_int_constant (void *, const char *, bfd_vma
);
213 static bfd_boolean
tg_float_constant (void *, const char *, double);
214 static bfd_boolean
tg_typed_constant (void *, const char *, bfd_vma
);
215 static bfd_boolean
tg_variable (void *, const char *, enum debug_var_kind
, bfd_vma
);
216 static bfd_boolean
tg_start_function (void *, const char *, bfd_boolean
);
217 static bfd_boolean
tg_function_parameter (void *, const char *, enum debug_parm_kind
, bfd_vma
);
218 static bfd_boolean
tg_start_block (void *, bfd_vma
);
219 static bfd_boolean
tg_end_block (void *, bfd_vma
);
220 static bfd_boolean
tg_lineno (void *, const char *, unsigned long, bfd_vma
);
222 static const struct debug_write_fns pr_fns
=
224 pr_start_compilation_unit
,
243 pr_start_struct_type
,
247 pr_class_static_member
,
249 pr_class_start_method
,
250 pr_class_method_variant
,
251 pr_class_static_method_variant
,
263 pr_function_parameter
,
270 static const struct debug_write_fns tg_fns
=
272 tg_start_compilation_unit
,
274 pr_empty_type
, /* Same, push_type. */
275 pr_void_type
, /* Same, push_type. */
276 pr_int_type
, /* Same, push_type. */
277 pr_float_type
, /* Same, push_type. */
278 pr_complex_type
, /* Same, push_type. */
279 pr_bool_type
, /* Same, push_type. */
281 pr_pointer_type
, /* Same, changes to pointer. */
282 pr_function_type
, /* Same, push_type. */
283 pr_reference_type
, /* Same, changes to reference. */
284 pr_range_type
, /* FIXME: What's that?. */
285 pr_array_type
, /* Same, push_type. */
286 pr_set_type
, /* FIXME: What's that?. */
287 pr_offset_type
, /* FIXME: What's that?. */
288 pr_method_type
, /* Same. */
289 pr_const_type
, /* Same, changes to const. */
290 pr_volatile_type
, /* Same, changes to volatile. */
291 tg_start_struct_type
,
295 tg_class_static_member
,
297 pr_class_start_method
, /* Same, remmembers that's a method. */
298 tg_class_method_variant
,
299 tg_class_static_method_variant
,
300 pr_class_end_method
, /* Same, forgets that's a method. */
302 pr_typedef_type
, /* Same, just push type. */
306 tg_int_constant
, /* Untested. */
307 tg_float_constant
, /* Untested. */
308 tg_typed_constant
, /* Untested. */
311 tg_function_parameter
,
314 pr_end_function
, /* Same, does nothing. */
318 /* Print out the generic debugging information recorded in dhandle. */
321 print_debugging_info (f
, dhandle
, abfd
, syms
, demangler
, as_tags
)
329 struct pr_handle info
;
335 info
.filename
= NULL
;
338 info
.demangler
= demangler
;
342 fputs ("!_TAG_FILE_FORMAT\t2\t/extended format/\n", f
);
343 fputs ("!_TAG_FILE_SORTED\t0\t/0=unsorted, 1=sorted/\n", f
);
344 fputs ("!_TAG_PROGRAM_AUTHOR\tIan Lance Taylor, Salvador E. Tropea and others\t//\n", f
);
345 fputs ("!_TAG_PROGRAM_NAME\tobjdump\t/From GNU binutils/\n", f
);
348 return as_tags
? debug_write (dhandle
, &tg_fns
, (void *) & info
)
349 : debug_write (dhandle
, &pr_fns
, (void *) & info
);
352 /* Indent to the current indentation level. */
356 struct pr_handle
*info
;
360 for (i
= 0; i
< info
->indent
; i
++)
364 /* Push a type on the type stack. */
367 push_type (info
, type
)
368 struct pr_handle
*info
;
376 n
= (struct pr_stack
*) xmalloc (sizeof *n
);
377 memset (n
, 0, sizeof *n
);
379 n
->type
= xstrdup (type
);
380 n
->visibility
= DEBUG_VISIBILITY_IGNORE
;
382 n
->next
= info
->stack
;
388 /* Prepend a string onto the type on the top of the type stack. */
391 prepend_type (info
, s
)
392 struct pr_handle
*info
;
397 assert (info
->stack
!= NULL
);
399 n
= (char *) xmalloc (strlen (s
) + strlen (info
->stack
->type
) + 1);
400 sprintf (n
, "%s%s", s
, info
->stack
->type
);
401 free (info
->stack
->type
);
402 info
->stack
->type
= n
;
407 /* Append a string to the type on the top of the type stack. */
410 append_type (info
, s
)
411 struct pr_handle
*info
;
419 assert (info
->stack
!= NULL
);
421 len
= strlen (info
->stack
->type
);
422 info
->stack
->type
= (char *) xrealloc (info
->stack
->type
,
423 len
+ strlen (s
) + 1);
424 strcpy (info
->stack
->type
+ len
, s
);
429 /* Append a string to the parents on the top of the type stack. */
432 append_parent (struct pr_handle
*info
, const char *s
)
439 assert (info
->stack
!= NULL
);
441 len
= info
->stack
->parents
? strlen (info
->stack
->parents
) : 0;
442 info
->stack
->parents
= (char *) xrealloc (info
->stack
->parents
,
443 len
+ strlen (s
) + 1);
444 strcpy (info
->stack
->parents
+ len
, s
);
449 /* We use an underscore to indicate where the name should go in a type
450 string. This function substitutes a string for the underscore. If
451 there is no underscore, the name follows the type. */
454 substitute_type (info
, s
)
455 struct pr_handle
*info
;
460 assert (info
->stack
!= NULL
);
462 u
= strchr (info
->stack
->type
, '|');
467 n
= (char *) xmalloc (strlen (info
->stack
->type
) + strlen (s
));
469 memcpy (n
, info
->stack
->type
, u
- info
->stack
->type
);
470 strcpy (n
+ (u
- info
->stack
->type
), s
);
473 free (info
->stack
->type
);
474 info
->stack
->type
= n
;
479 if (strchr (s
, '|') != NULL
480 && (strchr (info
->stack
->type
, '{') != NULL
481 || strchr (info
->stack
->type
, '(') != NULL
))
483 if (! prepend_type (info
, "(")
484 || ! append_type (info
, ")"))
491 return (append_type (info
, " ")
492 && append_type (info
, s
));
495 /* Indent the type at the top of the stack by appending spaces. */
499 struct pr_handle
*info
;
503 for (i
= 0; i
< info
->indent
; i
++)
505 if (! append_type (info
, " "))
512 /* Pop a type from the type stack. */
516 struct pr_handle
*info
;
521 assert (info
->stack
!= NULL
);
524 info
->stack
= o
->next
;
531 /* Print a VMA value into a string. */
534 print_vma (vma
, buf
, unsignedp
, hexp
)
537 bfd_boolean unsignedp
;
540 if (sizeof (vma
) <= sizeof (unsigned long))
543 sprintf (buf
, "0x%lx", (unsigned long) vma
);
545 sprintf (buf
, "%lu", (unsigned long) vma
);
547 sprintf (buf
, "%ld", (long) vma
);
553 sprintf_vma (buf
+ 2, vma
);
557 /* Start a new compilation unit. */
560 pr_start_compilation_unit (p
, filename
)
562 const char *filename
;
564 struct pr_handle
*info
= (struct pr_handle
*) p
;
566 assert (info
->indent
== 0);
568 fprintf (info
->f
, "%s:\n", filename
);
573 /* Start a source file within a compilation unit. */
576 pr_start_source (p
, filename
)
578 const char *filename
;
580 struct pr_handle
*info
= (struct pr_handle
*) p
;
582 assert (info
->indent
== 0);
584 fprintf (info
->f
, " %s:\n", filename
);
589 /* Push an empty type onto the type stack. */
595 struct pr_handle
*info
= (struct pr_handle
*) p
;
597 return push_type (info
, "<undefined>");
600 /* Push a void type onto the type stack. */
606 struct pr_handle
*info
= (struct pr_handle
*) p
;
608 return push_type (info
, "void");
611 /* Push an integer type onto the type stack. */
614 pr_int_type (p
, size
, unsignedp
)
617 bfd_boolean unsignedp
;
619 struct pr_handle
*info
= (struct pr_handle
*) p
;
622 sprintf (ab
, "%sint%d", unsignedp
? "u" : "", size
* 8);
623 return push_type (info
, ab
);
626 /* Push a floating type onto the type stack. */
629 pr_float_type (p
, size
)
633 struct pr_handle
*info
= (struct pr_handle
*) p
;
637 return push_type (info
, "float");
639 return push_type (info
, "double");
641 sprintf (ab
, "float%d", size
* 8);
642 return push_type (info
, ab
);
645 /* Push a complex type onto the type stack. */
648 pr_complex_type (p
, size
)
652 struct pr_handle
*info
= (struct pr_handle
*) p
;
654 if (! pr_float_type (p
, size
))
657 return prepend_type (info
, "complex ");
660 /* Push a bfd_boolean type onto the type stack. */
663 pr_bool_type (p
, size
)
667 struct pr_handle
*info
= (struct pr_handle
*) p
;
670 sprintf (ab
, "bool%d", size
* 8);
672 return push_type (info
, ab
);
675 /* Push an enum type onto the type stack. */
678 pr_enum_type (p
, tag
, names
, values
)
682 bfd_signed_vma
*values
;
684 struct pr_handle
*info
= (struct pr_handle
*) p
;
688 if (! push_type (info
, "enum "))
692 if (! append_type (info
, tag
)
693 || ! append_type (info
, " "))
696 if (! append_type (info
, "{ "))
701 if (! append_type (info
, "/* undefined */"))
707 for (i
= 0; names
[i
] != NULL
; i
++)
711 if (! append_type (info
, ", "))
715 if (! append_type (info
, names
[i
]))
718 if (values
[i
] != val
)
722 print_vma (values
[i
], ab
, FALSE
, FALSE
);
723 if (! append_type (info
, " = ")
724 || ! append_type (info
, ab
))
733 return append_type (info
, " }");
736 /* Turn the top type on the stack into a pointer. */
742 struct pr_handle
*info
= (struct pr_handle
*) p
;
745 assert (info
->stack
!= NULL
);
747 s
= strchr (info
->stack
->type
, '|');
748 if (s
!= NULL
&& s
[1] == '[')
749 return substitute_type (info
, "(*|)");
750 return substitute_type (info
, "*|");
753 /* Turn the top type on the stack into a function returning that type. */
756 pr_function_type (p
, argcount
, varargs
)
761 struct pr_handle
*info
= (struct pr_handle
*) p
;
766 assert (info
->stack
!= NULL
);
779 arg_types
= (char **) xmalloc (argcount
* sizeof *arg_types
);
780 for (i
= argcount
- 1; i
>= 0; i
--)
782 if (! substitute_type (info
, ""))
784 arg_types
[i
] = pop_type (info
);
785 if (arg_types
[i
] == NULL
)
787 len
+= strlen (arg_types
[i
]) + 2;
793 /* Now the return type is on the top of the stack. */
795 s
= (char *) xmalloc (len
);
799 strcat (s
, "/* unknown */");
804 for (i
= 0; i
< argcount
; i
++)
808 strcat (s
, arg_types
[i
]);
822 if (! substitute_type (info
, s
))
830 /* Turn the top type on the stack into a reference to that type. */
833 pr_reference_type (p
)
836 struct pr_handle
*info
= (struct pr_handle
*) p
;
838 assert (info
->stack
!= NULL
);
840 return substitute_type (info
, "&|");
843 /* Make a range type. */
846 pr_range_type (p
, lower
, upper
)
848 bfd_signed_vma lower
;
849 bfd_signed_vma upper
;
851 struct pr_handle
*info
= (struct pr_handle
*) p
;
852 char abl
[20], abu
[20];
854 assert (info
->stack
!= NULL
);
856 if (! substitute_type (info
, ""))
859 print_vma (lower
, abl
, FALSE
, FALSE
);
860 print_vma (upper
, abu
, FALSE
, FALSE
);
862 return (prepend_type (info
, "range (")
863 && append_type (info
, "):")
864 && append_type (info
, abl
)
865 && append_type (info
, ":")
866 && append_type (info
, abu
));
869 /* Make an array type. */
872 pr_array_type (p
, lower
, upper
, stringp
)
874 bfd_signed_vma lower
;
875 bfd_signed_vma upper
;
878 struct pr_handle
*info
= (struct pr_handle
*) p
;
880 char abl
[20], abu
[20], ab
[50];
882 range_type
= pop_type (info
);
883 if (range_type
== NULL
)
892 print_vma (upper
+ 1, abu
, FALSE
, FALSE
);
893 sprintf (ab
, "|[%s]", abu
);
898 print_vma (lower
, abl
, FALSE
, FALSE
);
899 print_vma (upper
, abu
, FALSE
, FALSE
);
900 sprintf (ab
, "|[%s:%s]", abl
, abu
);
903 if (! substitute_type (info
, ab
))
906 if (strcmp (range_type
, "int") != 0)
908 if (! append_type (info
, ":")
909 || ! append_type (info
, range_type
))
915 if (! append_type (info
, " /* string */"))
922 /* Make a set type. */
925 pr_set_type (p
, bitstringp
)
927 bfd_boolean bitstringp
;
929 struct pr_handle
*info
= (struct pr_handle
*) p
;
931 if (! substitute_type (info
, ""))
934 if (! prepend_type (info
, "set { ")
935 || ! append_type (info
, " }"))
940 if (! append_type (info
, "/* bitstring */"))
947 /* Make an offset type. */
953 struct pr_handle
*info
= (struct pr_handle
*) p
;
956 if (! substitute_type (info
, ""))
963 return (substitute_type (info
, "")
964 && prepend_type (info
, " ")
965 && prepend_type (info
, t
)
966 && append_type (info
, "::|"));
969 /* Make a method type. */
972 pr_method_type (p
, domain
, argcount
, varargs
)
978 struct pr_handle
*info
= (struct pr_handle
*) p
;
990 if (! substitute_type (info
, ""))
992 domain_type
= pop_type (info
);
993 if (domain_type
== NULL
)
995 if (strncmp (domain_type
, "class ", sizeof "class " - 1) == 0
996 && strchr (domain_type
+ sizeof "class " - 1, ' ') == NULL
)
997 domain_type
+= sizeof "class " - 1;
998 else if (strncmp (domain_type
, "union class ",
999 sizeof "union class ") == 0
1000 && (strchr (domain_type
+ sizeof "union class " - 1, ' ')
1002 domain_type
+= sizeof "union class " - 1;
1003 len
+= strlen (domain_type
);
1015 arg_types
= (char **) xmalloc (argcount
* sizeof *arg_types
);
1016 for (i
= argcount
- 1; i
>= 0; i
--)
1018 if (! substitute_type (info
, ""))
1020 arg_types
[i
] = pop_type (info
);
1021 if (arg_types
[i
] == NULL
)
1023 len
+= strlen (arg_types
[i
]) + 2;
1029 /* Now the return type is on the top of the stack. */
1031 s
= (char *) xmalloc (len
);
1035 strcpy (s
, domain_type
);
1036 strcat (s
, "::| (");
1039 strcat (s
, "/* unknown */");
1044 for (i
= 0; i
< argcount
; i
++)
1048 strcat (s
, arg_types
[i
]);
1062 if (! substitute_type (info
, s
))
1070 /* Make a const qualified type. */
1076 struct pr_handle
*info
= (struct pr_handle
*) p
;
1078 return substitute_type (info
, "const |");
1081 /* Make a volatile qualified type. */
1084 pr_volatile_type (p
)
1087 struct pr_handle
*info
= (struct pr_handle
*) p
;
1089 return substitute_type (info
, "volatile |");
1092 /* Start accumulating a struct type. */
1095 pr_start_struct_type (p
, tag
, id
, structp
, size
)
1099 bfd_boolean structp
;
1102 struct pr_handle
*info
= (struct pr_handle
*) p
;
1106 if (! push_type (info
, structp
? "struct " : "union "))
1110 if (! append_type (info
, tag
))
1117 sprintf (idbuf
, "%%anon%u", id
);
1118 if (! append_type (info
, idbuf
))
1122 if (! append_type (info
, " {"))
1124 if (size
!= 0 || tag
!= NULL
)
1128 if (! append_type (info
, " /*"))
1133 sprintf (ab
, " size %u", size
);
1134 if (! append_type (info
, ab
))
1139 sprintf (ab
, " id %u", id
);
1140 if (! append_type (info
, ab
))
1143 if (! append_type (info
, " */"))
1146 if (! append_type (info
, "\n"))
1149 info
->stack
->visibility
= DEBUG_VISIBILITY_PUBLIC
;
1151 return indent_type (info
);
1154 /* Output the visibility of a field in a struct. */
1157 pr_fix_visibility (info
, visibility
)
1158 struct pr_handle
*info
;
1159 enum debug_visibility visibility
;
1161 const char *s
= NULL
;
1165 assert (info
->stack
!= NULL
);
1167 if (info
->stack
->visibility
== visibility
)
1172 case DEBUG_VISIBILITY_PUBLIC
:
1175 case DEBUG_VISIBILITY_PRIVATE
:
1178 case DEBUG_VISIBILITY_PROTECTED
:
1181 case DEBUG_VISIBILITY_IGNORE
:
1189 /* Trim off a trailing space in the struct string, to make the
1190 output look a bit better, then stick on the visibility string. */
1192 t
= info
->stack
->type
;
1194 assert (t
[len
- 1] == ' ');
1197 if (! append_type (info
, s
)
1198 || ! append_type (info
, ":\n")
1199 || ! indent_type (info
))
1202 info
->stack
->visibility
= visibility
;
1207 /* Add a field to a struct type. */
1210 pr_struct_field (p
, name
, bitpos
, bitsize
, visibility
)
1215 enum debug_visibility visibility
;
1217 struct pr_handle
*info
= (struct pr_handle
*) p
;
1221 if (! substitute_type (info
, name
))
1224 if (! append_type (info
, "; /* "))
1229 print_vma (bitsize
, ab
, TRUE
, FALSE
);
1230 if (! append_type (info
, "bitsize ")
1231 || ! append_type (info
, ab
)
1232 || ! append_type (info
, ", "))
1236 print_vma (bitpos
, ab
, TRUE
, FALSE
);
1237 if (! append_type (info
, "bitpos ")
1238 || ! append_type (info
, ab
)
1239 || ! append_type (info
, " */\n")
1240 || ! indent_type (info
))
1243 t
= pop_type (info
);
1247 if (! pr_fix_visibility (info
, visibility
))
1250 return append_type (info
, t
);
1253 /* Finish a struct type. */
1256 pr_end_struct_type (p
)
1259 struct pr_handle
*info
= (struct pr_handle
*) p
;
1262 assert (info
->stack
!= NULL
);
1263 assert (info
->indent
>= 2);
1267 /* Change the trailing indentation to have a close brace. */
1268 s
= info
->stack
->type
+ strlen (info
->stack
->type
) - 2;
1269 assert (s
[0] == ' ' && s
[1] == ' ' && s
[2] == '\0');
1277 /* Start a class type. */
1280 pr_start_class_type (p
, tag
, id
, structp
, size
, vptr
, ownvptr
)
1284 bfd_boolean structp
;
1287 bfd_boolean ownvptr
;
1289 struct pr_handle
*info
= (struct pr_handle
*) p
;
1294 if (vptr
&& ! ownvptr
)
1296 tv
= pop_type (info
);
1301 if (! push_type (info
, structp
? "class " : "union class "))
1305 if (! append_type (info
, tag
))
1312 sprintf (idbuf
, "%%anon%u", id
);
1313 if (! append_type (info
, idbuf
))
1317 if (! append_type (info
, " {"))
1319 if (size
!= 0 || vptr
|| ownvptr
|| tag
!= NULL
)
1321 if (! append_type (info
, " /*"))
1328 sprintf (ab
, "%u", size
);
1329 if (! append_type (info
, " size ")
1330 || ! append_type (info
, ab
))
1336 if (! append_type (info
, " vtable "))
1340 if (! append_type (info
, "self "))
1345 if (! append_type (info
, tv
)
1346 || ! append_type (info
, " "))
1355 sprintf (ab
, " id %u", id
);
1356 if (! append_type (info
, ab
))
1360 if (! append_type (info
, " */"))
1364 info
->stack
->visibility
= DEBUG_VISIBILITY_PRIVATE
;
1366 return (append_type (info
, "\n")
1367 && indent_type (info
));
1370 /* Add a static member to a class. */
1373 pr_class_static_member (p
, name
, physname
, visibility
)
1376 const char *physname
;
1377 enum debug_visibility visibility
;
1379 struct pr_handle
*info
= (struct pr_handle
*) p
;
1382 if (! substitute_type (info
, name
))
1385 if (! prepend_type (info
, "static ")
1386 || ! append_type (info
, "; /* ")
1387 || ! append_type (info
, physname
)
1388 || ! append_type (info
, " */\n")
1389 || ! indent_type (info
))
1392 t
= pop_type (info
);
1396 if (! pr_fix_visibility (info
, visibility
))
1399 return append_type (info
, t
);
1402 /* Add a base class to a class. */
1405 pr_class_baseclass (p
, bitpos
, virtual, visibility
)
1408 bfd_boolean
virtual;
1409 enum debug_visibility visibility
;
1411 struct pr_handle
*info
= (struct pr_handle
*) p
;
1417 assert (info
->stack
!= NULL
&& info
->stack
->next
!= NULL
);
1419 if (! substitute_type (info
, ""))
1422 t
= pop_type (info
);
1426 if (strncmp (t
, "class ", sizeof "class " - 1) == 0)
1427 t
+= sizeof "class " - 1;
1429 /* Push it back on to take advantage of the prepend_type and
1430 append_type routines. */
1431 if (! push_type (info
, t
))
1436 if (! prepend_type (info
, "virtual "))
1442 case DEBUG_VISIBILITY_PUBLIC
:
1445 case DEBUG_VISIBILITY_PROTECTED
:
1446 prefix
= "protected ";
1448 case DEBUG_VISIBILITY_PRIVATE
:
1449 prefix
= "private ";
1452 prefix
= "/* unknown visibility */ ";
1456 if (! prepend_type (info
, prefix
))
1461 print_vma (bitpos
, ab
, TRUE
, FALSE
);
1462 if (! append_type (info
, " /* bitpos ")
1463 || ! append_type (info
, ab
)
1464 || ! append_type (info
, " */"))
1468 /* Now the top of the stack is something like "public A / * bitpos
1469 10 * /". The next element on the stack is something like "class
1470 xx { / * size 8 * /\n...". We want to substitute the top of the
1471 stack in before the {. */
1472 s
= strchr (info
->stack
->next
->type
, '{');
1476 /* If there is already a ':', then we already have a baseclass, and
1477 we must append this one after a comma. */
1478 for (l
= info
->stack
->next
->type
; l
!= s
; l
++)
1481 if (! prepend_type (info
, l
== s
? " : " : ", "))
1484 t
= pop_type (info
);
1488 n
= (char *) xmalloc (strlen (info
->stack
->type
) + strlen (t
) + 1);
1489 memcpy (n
, info
->stack
->type
, s
- info
->stack
->type
);
1490 strcpy (n
+ (s
- info
->stack
->type
), t
);
1493 free (info
->stack
->type
);
1494 info
->stack
->type
= n
;
1501 /* Start adding a method to a class. */
1504 pr_class_start_method (p
, name
)
1508 struct pr_handle
*info
= (struct pr_handle
*) p
;
1510 assert (info
->stack
!= NULL
);
1511 info
->stack
->method
= name
;
1515 /* Add a variant to a method. */
1518 pr_class_method_variant (p
, physname
, visibility
, constp
, volatilep
, voffset
,
1521 const char *physname
;
1522 enum debug_visibility visibility
;
1524 bfd_boolean volatilep
;
1526 bfd_boolean context
;
1528 struct pr_handle
*info
= (struct pr_handle
*) p
;
1532 assert (info
->stack
!= NULL
);
1533 assert (info
->stack
->next
!= NULL
);
1535 /* Put the const and volatile qualifiers on the type. */
1538 if (! append_type (info
, " volatile"))
1543 if (! append_type (info
, " const"))
1547 /* Stick the name of the method into its type. */
1548 if (! substitute_type (info
,
1550 ? info
->stack
->next
->next
->method
1551 : info
->stack
->next
->method
)))
1555 method_type
= pop_type (info
);
1556 if (method_type
== NULL
)
1559 /* Pull off the context type if there is one. */
1561 context_type
= NULL
;
1564 context_type
= pop_type (info
);
1565 if (context_type
== NULL
)
1569 /* Now the top of the stack is the class. */
1571 if (! pr_fix_visibility (info
, visibility
))
1574 if (! append_type (info
, method_type
)
1575 || ! append_type (info
, " /* ")
1576 || ! append_type (info
, physname
)
1577 || ! append_type (info
, " "))
1579 if (context
|| voffset
!= 0)
1585 if (! append_type (info
, "context ")
1586 || ! append_type (info
, context_type
)
1587 || ! append_type (info
, " "))
1590 print_vma (voffset
, ab
, TRUE
, FALSE
);
1591 if (! append_type (info
, "voffset ")
1592 || ! append_type (info
, ab
))
1596 return (append_type (info
, " */;\n")
1597 && indent_type (info
));
1600 /* Add a static variant to a method. */
1603 pr_class_static_method_variant (p
, physname
, visibility
, constp
, volatilep
)
1605 const char *physname
;
1606 enum debug_visibility visibility
;
1608 bfd_boolean volatilep
;
1610 struct pr_handle
*info
= (struct pr_handle
*) p
;
1613 assert (info
->stack
!= NULL
);
1614 assert (info
->stack
->next
!= NULL
);
1615 assert (info
->stack
->next
->method
!= NULL
);
1617 /* Put the const and volatile qualifiers on the type. */
1620 if (! append_type (info
, " volatile"))
1625 if (! append_type (info
, " const"))
1629 /* Mark it as static. */
1630 if (! prepend_type (info
, "static "))
1633 /* Stick the name of the method into its type. */
1634 if (! substitute_type (info
, info
->stack
->next
->method
))
1638 method_type
= pop_type (info
);
1639 if (method_type
== NULL
)
1642 /* Now the top of the stack is the class. */
1644 if (! pr_fix_visibility (info
, visibility
))
1647 return (append_type (info
, method_type
)
1648 && append_type (info
, " /* ")
1649 && append_type (info
, physname
)
1650 && append_type (info
, " */;\n")
1651 && indent_type (info
));
1654 /* Finish up a method. */
1657 pr_class_end_method (p
)
1660 struct pr_handle
*info
= (struct pr_handle
*) p
;
1662 info
->stack
->method
= NULL
;
1666 /* Finish up a class. */
1669 pr_end_class_type (p
)
1672 return pr_end_struct_type (p
);
1675 /* Push a type on the stack using a typedef name. */
1678 pr_typedef_type (p
, name
)
1682 struct pr_handle
*info
= (struct pr_handle
*) p
;
1684 return push_type (info
, name
);
1687 /* Push a type on the stack using a tag name. */
1690 pr_tag_type (p
, name
, id
, kind
)
1694 enum debug_type_kind kind
;
1696 struct pr_handle
*info
= (struct pr_handle
*) p
;
1697 const char *t
, *tag
;
1702 case DEBUG_KIND_STRUCT
:
1705 case DEBUG_KIND_UNION
:
1708 case DEBUG_KIND_ENUM
:
1711 case DEBUG_KIND_CLASS
:
1714 case DEBUG_KIND_UNION_CLASS
:
1722 if (! push_type (info
, t
))
1728 sprintf (idbuf
, "%%anon%u", id
);
1732 if (! append_type (info
, tag
))
1734 if (name
!= NULL
&& kind
!= DEBUG_KIND_ENUM
)
1736 sprintf (idbuf
, " /* id %u */", id
);
1737 if (! append_type (info
, idbuf
))
1744 /* Output a typedef. */
1751 struct pr_handle
*info
= (struct pr_handle
*) p
;
1754 if (! substitute_type (info
, name
))
1757 s
= pop_type (info
);
1762 fprintf (info
->f
, "typedef %s;\n", s
);
1769 /* Output a tag. The tag should already be in the string on the
1770 stack, so all we have to do here is print it out. */
1775 const char *name ATTRIBUTE_UNUSED
;
1777 struct pr_handle
*info
= (struct pr_handle
*) p
;
1780 t
= pop_type (info
);
1785 fprintf (info
->f
, "%s;\n", t
);
1792 /* Output an integer constant. */
1795 pr_int_constant (p
, name
, val
)
1800 struct pr_handle
*info
= (struct pr_handle
*) p
;
1804 print_vma (val
, ab
, FALSE
, FALSE
);
1805 fprintf (info
->f
, "const int %s = %s;\n", name
, ab
);
1809 /* Output a floating point constant. */
1812 pr_float_constant (p
, name
, val
)
1817 struct pr_handle
*info
= (struct pr_handle
*) p
;
1820 fprintf (info
->f
, "const double %s = %g;\n", name
, val
);
1824 /* Output a typed constant. */
1827 pr_typed_constant (p
, name
, val
)
1832 struct pr_handle
*info
= (struct pr_handle
*) p
;
1836 t
= pop_type (info
);
1841 print_vma (val
, ab
, FALSE
, FALSE
);
1842 fprintf (info
->f
, "const %s %s = %s;\n", t
, name
, ab
);
1849 /* Output a variable. */
1852 pr_variable (p
, name
, kind
, val
)
1855 enum debug_var_kind kind
;
1858 struct pr_handle
*info
= (struct pr_handle
*) p
;
1862 if (! substitute_type (info
, name
))
1865 t
= pop_type (info
);
1873 case DEBUG_LOCAL_STATIC
:
1874 fprintf (info
->f
, "static ");
1876 case DEBUG_REGISTER
:
1877 fprintf (info
->f
, "register ");
1882 print_vma (val
, ab
, TRUE
, TRUE
);
1883 fprintf (info
->f
, "%s /* %s */;\n", t
, ab
);
1890 /* Start outputting a function. */
1893 pr_start_function (p
, name
, global
)
1898 struct pr_handle
*info
= (struct pr_handle
*) p
;
1901 if (! substitute_type (info
, name
))
1904 t
= pop_type (info
);
1910 fprintf (info
->f
, "static ");
1911 fprintf (info
->f
, "%s (", t
);
1913 info
->parameter
= 1;
1918 /* Output a function parameter. */
1921 pr_function_parameter (p
, name
, kind
, val
)
1924 enum debug_parm_kind kind
;
1927 struct pr_handle
*info
= (struct pr_handle
*) p
;
1931 if (kind
== DEBUG_PARM_REFERENCE
1932 || kind
== DEBUG_PARM_REF_REG
)
1934 if (! pr_reference_type (p
))
1938 if (! substitute_type (info
, name
))
1941 t
= pop_type (info
);
1945 if (info
->parameter
!= 1)
1946 fprintf (info
->f
, ", ");
1948 if (kind
== DEBUG_PARM_REG
|| kind
== DEBUG_PARM_REF_REG
)
1949 fprintf (info
->f
, "register ");
1951 print_vma (val
, ab
, TRUE
, TRUE
);
1952 fprintf (info
->f
, "%s /* %s */", t
, ab
);
1961 /* Start writing out a block. */
1964 pr_start_block (p
, addr
)
1968 struct pr_handle
*info
= (struct pr_handle
*) p
;
1971 if (info
->parameter
> 0)
1973 fprintf (info
->f
, ")\n");
1974 info
->parameter
= 0;
1978 print_vma (addr
, ab
, TRUE
, TRUE
);
1979 fprintf (info
->f
, "{ /* %s */\n", ab
);
1986 /* Write out line number information. */
1989 pr_lineno (p
, filename
, lineno
, addr
)
1991 const char *filename
;
1992 unsigned long lineno
;
1995 struct pr_handle
*info
= (struct pr_handle
*) p
;
1999 print_vma (addr
, ab
, TRUE
, TRUE
);
2000 fprintf (info
->f
, "/* file %s line %lu addr %s */\n", filename
, lineno
, ab
);
2005 /* Finish writing out a block. */
2008 pr_end_block (p
, addr
)
2012 struct pr_handle
*info
= (struct pr_handle
*) p
;
2018 print_vma (addr
, ab
, TRUE
, TRUE
);
2019 fprintf (info
->f
, "} /* %s */\n", ab
);
2024 /* Finish writing out a function. */
2028 PTR p ATTRIBUTE_UNUSED
;
2033 /* Tags style generation functions start here. */
2035 /* Variables for address to line translation. */
2037 static const char *filename
;
2038 static const char *functionname
;
2039 static unsigned int line
;
2040 static bfd_boolean found
;
2042 /* Look for an address in a section. This is called via
2043 bfd_map_over_sections. */
2046 find_address_in_section (bfd
*abfd
, asection
*section
, void *data
)
2050 asymbol
**syms
= (asymbol
**) data
;
2055 if ((bfd_get_section_flags (abfd
, section
) & SEC_ALLOC
) == 0)
2058 vma
= bfd_get_section_vma (abfd
, section
);
2062 size
= bfd_get_section_size_before_reloc (section
);
2063 if (pc
>= vma
+ size
)
2066 found
= bfd_find_nearest_line (abfd
, section
, syms
, pc
- vma
,
2067 &filename
, &functionname
, &line
);
2071 translate_addresses (bfd
*abfd
, char *addr_hex
, FILE *f
, asymbol
**syms
)
2073 pc
= bfd_scan_vma (addr_hex
, NULL
, 16);
2075 bfd_map_over_sections (abfd
, find_address_in_section
, syms
);
2080 fprintf (f
, "%u", line
);
2083 /* Start a new compilation unit. */
2086 tg_start_compilation_unit (void * p
, const char *filename ATTRIBUTE_UNUSED
)
2088 struct pr_handle
*info
= (struct pr_handle
*) p
;
2090 fprintf (stderr
, "New compilation unit: %s\n", filename
);
2092 free (info
->filename
);
2093 /* Should it be relative? best way to do it here?. */
2094 info
->filename
= strdup (filename
);
2099 /* Start a source file within a compilation unit. */
2102 tg_start_source (void *p
, const char *filename
)
2104 struct pr_handle
*info
= (struct pr_handle
*) p
;
2106 free (info
->filename
);
2107 /* Should it be relative? best way to do it here?. */
2108 info
->filename
= strdup (filename
);
2113 /* Push an enum type onto the type stack. */
2116 tg_enum_type (void *p
, const char *tag
, const char **names
,
2117 bfd_signed_vma
*values
)
2119 struct pr_handle
*info
= (struct pr_handle
*) p
;
2124 if (! pr_enum_type (p
, tag
, names
, values
))
2127 name
= tag
? tag
: "unknown";
2128 /* Generate an entry for the enum. */
2130 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:e\ttype:%s\n", tag
,
2131 info
->filename
, info
->stack
->type
);
2133 /* Generate entries for the values. */
2136 for (i
= 0; names
[i
] != NULL
; i
++)
2138 print_vma (values
[i
], ab
, FALSE
, FALSE
);
2139 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:g\tenum:%s\tvalue:%s\n",
2140 names
[i
], info
->filename
, name
, ab
);
2147 /* Start accumulating a struct type. */
2150 tg_start_struct_type (void *p
, const char *tag
, unsigned int id
,
2151 bfd_boolean structp
, unsigned int size ATTRIBUTE_UNUSED
)
2153 struct pr_handle
*info
= (struct pr_handle
*) p
;
2162 sprintf (idbuf
, "%%anon%u", id
);
2165 if (! push_type (info
, name
))
2168 info
->stack
->flavor
= structp
? "struct" : "union";
2170 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:%c\n", name
, info
->filename
,
2171 info
->stack
->flavor
[0]);
2173 info
->stack
->visibility
= DEBUG_VISIBILITY_PUBLIC
;
2175 return indent_type (info
);
2178 /* Output the visibility of a field in a struct. */
2181 tg_fix_visibility (struct pr_handle
*info
, enum debug_visibility visibility
)
2183 assert (info
->stack
!= NULL
);
2185 if (info
->stack
->visibility
== visibility
)
2188 assert (info
->stack
->visibility
!= DEBUG_VISIBILITY_IGNORE
);
2190 info
->stack
->visibility
= visibility
;
2195 /* Add a field to a struct type. */
2198 tg_struct_field (void *p
, const char *name
, bfd_vma bitpos ATTRIBUTE_UNUSED
,
2199 bfd_vma bitsize ATTRIBUTE_UNUSED
,
2200 enum debug_visibility visibility
)
2202 struct pr_handle
*info
= (struct pr_handle
*) p
;
2205 t
= pop_type (info
);
2209 if (! tg_fix_visibility (info
, visibility
))
2212 /* It happends, a bug? */
2216 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:m\ttype:%s\t%s:%s\taccess:%s\n",
2217 name
, info
->filename
, t
, info
->stack
->flavor
, info
->stack
->type
,
2218 visibility_name (visibility
));
2223 /* Finish a struct type. */
2226 tg_end_struct_type (void *p ATTRIBUTE_UNUSED
)
2228 struct pr_handle
*info
= (struct pr_handle
*) p
;
2229 assert (info
->stack
!= NULL
);
2234 /* Start a class type. */
2237 tg_start_class_type (void *p
, const char *tag
, unsigned int id
,
2238 bfd_boolean structp
, unsigned int size
,
2239 bfd_boolean vptr
, bfd_boolean ownvptr
)
2241 struct pr_handle
*info
= (struct pr_handle
*) p
;
2247 if (vptr
&& ! ownvptr
)
2249 tv
= pop_type (info
);
2260 sprintf (idbuf
, "%%anon%u", id
);
2264 if (! push_type (info
, name
))
2267 info
->stack
->flavor
= structp
? "class" : "union class";
2268 info
->stack
->parents
= NULL
;
2269 info
->stack
->num_parents
= 0;
2271 if (size
!= 0 || vptr
|| ownvptr
|| tag
!= NULL
)
2275 if (! append_type (info
, " vtable "))
2279 if (! append_type (info
, "self "))
2284 if (! append_type (info
, tv
)
2285 || ! append_type (info
, " "))
2291 info
->stack
->visibility
= DEBUG_VISIBILITY_PRIVATE
;
2296 /* Add a static member to a class. */
2299 tg_class_static_member (void *p
, const char *name
,
2300 const char *physname ATTRIBUTE_UNUSED
,
2301 enum debug_visibility visibility
)
2303 struct pr_handle
*info
= (struct pr_handle
*) p
;
2305 int len_var
, len_class
;
2308 len_var
= strlen (name
);
2309 len_class
= strlen (info
->stack
->next
->type
);
2310 full_name
= (char *) xmalloc (len_var
+ len_class
+ 3);
2313 memcpy (full_name
, info
->stack
->next
->type
, len_class
);
2314 memcpy (full_name
+ len_class
, "::", 2);
2315 memcpy (full_name
+ len_class
+ 2, name
, len_var
+ 1);
2317 if (! substitute_type (info
, full_name
))
2320 if (! prepend_type (info
, "static "))
2323 t
= pop_type (info
);
2327 if (! tg_fix_visibility (info
, visibility
))
2330 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:x\ttype:%s\tclass:%s\taccess:%s\n",
2331 name
, info
->filename
, t
, info
->stack
->type
,
2332 visibility_name (visibility
));
2339 /* Add a base class to a class. */
2342 tg_class_baseclass (void *p
, bfd_vma bitpos ATTRIBUTE_UNUSED
,
2343 bfd_boolean
virtual, enum debug_visibility visibility
)
2345 struct pr_handle
*info
= (struct pr_handle
*) p
;
2349 assert (info
->stack
!= NULL
&& info
->stack
->next
!= NULL
);
2351 t
= pop_type (info
);
2355 if (strncmp (t
, "class ", sizeof "class " - 1) == 0)
2356 t
+= sizeof "class " - 1;
2358 /* Push it back on to take advantage of the prepend_type and
2359 append_type routines. */
2360 if (! push_type (info
, t
))
2365 if (! prepend_type (info
, "virtual "))
2371 case DEBUG_VISIBILITY_PUBLIC
:
2374 case DEBUG_VISIBILITY_PROTECTED
:
2375 prefix
= "protected ";
2377 case DEBUG_VISIBILITY_PRIVATE
:
2378 prefix
= "private ";
2381 prefix
= "/* unknown visibility */ ";
2385 if (! prepend_type (info
, prefix
))
2388 t
= pop_type (info
);
2392 if (info
->stack
->num_parents
&& ! append_parent (info
, ", "))
2395 if (! append_parent (info
, t
))
2397 info
->stack
->num_parents
++;
2404 /* Add a variant to a method. */
2407 tg_class_method_variant (void *p
, const char *physname ATTRIBUTE_UNUSED
,
2408 enum debug_visibility visibility
,
2409 bfd_boolean constp
, bfd_boolean volatilep
,
2410 bfd_vma voffset ATTRIBUTE_UNUSED
,
2411 bfd_boolean context
)
2413 struct pr_handle
*info
= (struct pr_handle
*) p
;
2418 assert (info
->stack
!= NULL
);
2419 assert (info
->stack
->next
!= NULL
);
2421 /* Put the const and volatile qualifiers on the type. */
2424 if (! append_type (info
, " volatile"))
2429 if (! append_type (info
, " const"))
2433 method_name
= strdup (context
? info
->stack
->next
->next
->method
2434 : info
->stack
->next
->method
);
2436 /* Stick the name of the method into its type. */
2437 if (! substitute_type (info
, method_name
))
2441 method_type
= pop_type (info
);
2442 if (method_type
== NULL
)
2445 /* Pull off the context type if there is one. */
2447 context_type
= NULL
;
2450 context_type
= pop_type (info
);
2451 if (context_type
== NULL
)
2455 /* Now the top of the stack is the class. */
2456 if (! tg_fix_visibility (info
, visibility
))
2459 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:p\ttype:%s\tclass:%s\n",
2460 method_name
, info
->filename
, method_type
, info
->stack
->type
);
2463 free (context_type
);
2468 /* Add a static variant to a method. */
2471 tg_class_static_method_variant (void *p
,
2472 const char *physname ATTRIBUTE_UNUSED
,
2473 enum debug_visibility visibility
,
2475 bfd_boolean volatilep
)
2477 struct pr_handle
*info
= (struct pr_handle
*) p
;
2481 assert (info
->stack
!= NULL
);
2482 assert (info
->stack
->next
!= NULL
);
2483 assert (info
->stack
->next
->method
!= NULL
);
2485 /* Put the const and volatile qualifiers on the type. */
2488 if (! append_type (info
, " volatile"))
2493 if (! append_type (info
, " const"))
2497 /* Mark it as static. */
2498 if (! prepend_type (info
, "static "))
2501 method_name
= strdup (info
->stack
->next
->method
);
2502 /* Stick the name of the method into its type. */
2503 if (! substitute_type (info
, info
->stack
->next
->method
))
2507 method_type
= pop_type (info
);
2508 if (method_type
== NULL
)
2511 /* Now the top of the stack is the class. */
2512 if (! tg_fix_visibility (info
, visibility
))
2515 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:p\ttype:%s\tclass:%s\taccess:%s\n",
2516 method_name
, info
->filename
, method_type
, info
->stack
->type
,
2517 visibility_name (visibility
));
2524 /* Finish up a class. */
2527 tg_end_class_type (void *p
)
2529 struct pr_handle
*info
= (struct pr_handle
*) p
;
2531 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:c\ttype:%s", info
->stack
->type
,
2532 info
->filename
, info
->stack
->flavor
);
2533 if (info
->stack
->num_parents
)
2535 fprintf (info
->f
, "\tinherits:%s", info
->stack
->parents
);
2536 free (info
->stack
->parents
);
2538 fputc ('\n', info
->f
);
2540 return tg_end_struct_type (p
);
2543 /* Push a type on the stack using a tag name. */
2546 tg_tag_type (void *p
, const char *name
, unsigned int id
,
2547 enum debug_type_kind kind
)
2549 struct pr_handle
*info
= (struct pr_handle
*) p
;
2550 const char *t
, *tag
;
2555 case DEBUG_KIND_STRUCT
:
2558 case DEBUG_KIND_UNION
:
2561 case DEBUG_KIND_ENUM
:
2564 case DEBUG_KIND_CLASS
:
2567 case DEBUG_KIND_UNION_CLASS
:
2575 if (! push_type (info
, t
))
2581 sprintf (idbuf
, "%%anon%u", id
);
2585 if (! append_type (info
, tag
))
2591 /* Output a typedef. */
2594 tg_typdef (void *p
, const char *name
)
2596 struct pr_handle
*info
= (struct pr_handle
*) p
;
2599 s
= pop_type (info
);
2603 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:t\ttype:%s\n", name
,
2611 /* Output a tag. The tag should already be in the string on the
2612 stack, so all we have to do here is print it out. */
2615 tg_tag (void *p ATTRIBUTE_UNUSED
, const char *name ATTRIBUTE_UNUSED
)
2617 struct pr_handle
*info
= (struct pr_handle
*) p
;
2620 t
= pop_type (info
);
2628 /* Output an integer constant. */
2631 tg_int_constant (void *p
, const char *name
, bfd_vma val
)
2633 struct pr_handle
*info
= (struct pr_handle
*) p
;
2637 print_vma (val
, ab
, FALSE
, FALSE
);
2638 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:v\ttype:const int\tvalue:%s\n",
2639 name
, info
->filename
, ab
);
2643 /* Output a floating point constant. */
2646 tg_float_constant (void *p
, const char *name
, double val
)
2648 struct pr_handle
*info
= (struct pr_handle
*) p
;
2651 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:v\ttype:const double\tvalue:%g\n",
2652 name
, info
->filename
, val
);
2656 /* Output a typed constant. */
2659 tg_typed_constant (void *p
, const char *name
, bfd_vma val
)
2661 struct pr_handle
*info
= (struct pr_handle
*) p
;
2665 t
= pop_type (info
);
2670 print_vma (val
, ab
, FALSE
, FALSE
);
2671 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:v\ttype:const %s\tvalue:%s\n",
2672 name
, info
->filename
, t
, ab
);
2679 /* Output a variable. */
2682 tg_variable (void *p
, const char *name
, enum debug_var_kind kind
,
2683 bfd_vma val ATTRIBUTE_UNUSED
)
2685 struct pr_handle
*info
= (struct pr_handle
*) p
;
2687 const char *dname
, *from_class
;
2689 t
= pop_type (info
);
2694 if (info
->demangler
)
2696 dname
= info
->demangler (info
->abfd
, name
);
2697 if (strcmp (name
, dname
) == 0)
2699 free ((char *) dname
);
2707 sep
= strstr (dname
, "::");
2716 /* Obscure types as vts and type_info nodes. */
2724 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:v\ttype:%s", name
, info
->filename
, t
);
2729 case DEBUG_LOCAL_STATIC
:
2730 fprintf (info
->f
, "\tfile:");
2732 case DEBUG_REGISTER
:
2733 fprintf (info
->f
, "\tregister:");
2741 fprintf (info
->f
, "\tclass:%s",from_class
);
2742 free ((char *) dname
);
2745 fprintf (info
->f
, "\n");
2752 /* Start outputting a function. */
2755 tg_start_function (void *p
, const char *name
, bfd_boolean global
)
2757 struct pr_handle
*info
= (struct pr_handle
*) p
;
2761 info
->stack
->flavor
= "static";
2763 info
->stack
->flavor
= NULL
;
2766 if (info
->demangler
)
2768 dname
= info
->demangler (info
->abfd
, name
);
2769 if (strcmp (name
, dname
) == 0)
2771 free ((char *) dname
);
2776 if (! substitute_type (info
, dname
))
2782 sep
= strstr (dname
, "::");
2785 info
->stack
->method
= dname
;
2791 info
->stack
->method
= "";
2794 sep
= strchr (name
, '(');
2797 /* Obscure functions as type_info function. */
2800 info
->stack
->method
= NULL
;
2802 info
->stack
->parents
= strdup (name
);
2804 if (! info
->stack
->method
&& ! append_type (info
, "("))
2807 info
->parameter
= 1;
2812 /* Output a function parameter. */
2815 tg_function_parameter (void *p
, const char *name
, enum debug_parm_kind kind
,
2816 bfd_vma val ATTRIBUTE_UNUSED
)
2818 struct pr_handle
*info
= (struct pr_handle
*) p
;
2821 if (kind
== DEBUG_PARM_REFERENCE
2822 || kind
== DEBUG_PARM_REF_REG
)
2824 if (! pr_reference_type (p
))
2828 if (! substitute_type (info
, name
))
2831 t
= pop_type (info
);
2835 if (! info
->stack
->method
)
2837 if (info
->parameter
!= 1 && ! append_type (info
, ", "))
2840 if (kind
== DEBUG_PARM_REG
|| kind
== DEBUG_PARM_REF_REG
)
2841 if (! append_type (info
, "register "))
2844 if (! append_type (info
, t
))
2855 /* Start writing out a block. */
2858 tg_start_block (void *p
, bfd_vma addr
)
2860 struct pr_handle
*info
= (struct pr_handle
*) p
;
2861 char ab
[20], kind
, *partof
;
2865 if (info
->parameter
> 0)
2867 info
->parameter
= 0;
2870 fprintf (info
->f
, "%s\t%s\t", info
->stack
->parents
, info
->filename
);
2871 free (info
->stack
->parents
);
2873 print_vma (addr
, ab
, TRUE
, TRUE
);
2874 translate_addresses (info
->abfd
, ab
, info
->f
, info
->syms
);
2875 local
= info
->stack
->flavor
!= NULL
;
2876 if (info
->stack
->method
&& *info
->stack
->method
)
2879 partof
= (char *) info
->stack
->method
;
2885 if (! info
->stack
->method
&& ! append_type (info
, ")"))
2888 t
= pop_type (info
);
2891 fprintf (info
->f
, ";\"\tkind:%c\ttype:%s", kind
, t
);
2893 fputs ("\tfile:", info
->f
);
2896 fprintf (info
->f
, "\tclass:%s", partof
);
2899 fputc ('\n', info
->f
);
2905 /* Write out line number information. */
2908 tg_lineno (void *p ATTRIBUTE_UNUSED
,
2909 const char *filename ATTRIBUTE_UNUSED
,
2910 unsigned long lineno ATTRIBUTE_UNUSED
,
2911 bfd_vma addr ATTRIBUTE_UNUSED
)
2916 /* Finish writing out a block. */
2919 tg_end_block (void *p ATTRIBUTE_UNUSED
, bfd_vma addr ATTRIBUTE_UNUSED
)
2924 /* Convert the visibility value into a human readable name. */
2927 visibility_name (enum debug_visibility visibility
)
2933 case DEBUG_VISIBILITY_PUBLIC
:
2936 case DEBUG_VISIBILITY_PRIVATE
:
2939 case DEBUG_VISIBILITY_PROTECTED
:
2942 case DEBUG_VISIBILITY_IGNORE
: