1 /* prdbg.c -- Print out generic debugging information.
2 Copyright 1995, 1996, 1999, 2002, 2003, 2004, 2005, 2006, 2007, 2008
3 Free Software Foundation, Inc.
4 Written by Ian Lance Taylor <ian@cygnus.com>.
5 Tags style generation written by Salvador E. Tropea <set@computer.org>.
7 This file is part of GNU Binutils.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
24 /* This file prints out the generic debugging information, by
25 supplying a set of routines to debug_write. */
30 #include "libiberty.h"
35 /* This is the structure we use as a handle for these routines. */
39 /* File to print information to. */
41 /* Current indentation level. */
44 struct pr_stack
*stack
;
45 /* Parameter number we are about to output. */
47 /* The following are used only by the tags code (tg_). */
48 /* Name of the file we are using. */
52 /* The symbols table for this BFD. */
54 /* Pointer to a function to demangle symbols. */
55 char *(*demangler
) (bfd
*, const char *, int);
62 /* Next element on the stack. */
63 struct pr_stack
*next
;
66 /* Current visibility of fields if this is a class. */
67 enum debug_visibility visibility
;
68 /* Name of the current method we are handling. */
70 /* The following are used only by the tags code (tg_). */
71 /* Type for the container (struct, union, class, union class). */
73 /* A comma separated list of parent classes. */
75 /* How many parents contains parents. */
79 static void indent (struct pr_handle
*);
80 static bfd_boolean
push_type (struct pr_handle
*, const char *);
81 static bfd_boolean
prepend_type (struct pr_handle
*, const char *);
82 static bfd_boolean
append_type (struct pr_handle
*, const char *);
83 static bfd_boolean
substitute_type (struct pr_handle
*, const char *);
84 static bfd_boolean
indent_type (struct pr_handle
*);
85 static char *pop_type (struct pr_handle
*);
86 static void print_vma (bfd_vma
, char *, bfd_boolean
, bfd_boolean
);
87 static bfd_boolean pr_fix_visibility
88 (struct pr_handle
*, enum debug_visibility
);
89 static bfd_boolean
pr_start_compilation_unit (void *, const char *);
90 static bfd_boolean
pr_start_source (void *, const char *);
91 static bfd_boolean
pr_empty_type (void *);
92 static bfd_boolean
pr_void_type (void *);
93 static bfd_boolean
pr_int_type (void *, unsigned int, bfd_boolean
);
94 static bfd_boolean
pr_float_type (void *, unsigned int);
95 static bfd_boolean
pr_complex_type (void *, unsigned int);
96 static bfd_boolean
pr_bool_type (void *, unsigned int);
97 static bfd_boolean pr_enum_type
98 (void *, const char *, const char **, bfd_signed_vma
*);
99 static bfd_boolean
pr_pointer_type (void *);
100 static bfd_boolean
pr_function_type (void *, int, bfd_boolean
);
101 static bfd_boolean
pr_reference_type (void *);
102 static bfd_boolean
pr_range_type (void *, bfd_signed_vma
, bfd_signed_vma
);
103 static bfd_boolean pr_array_type
104 (void *, bfd_signed_vma
, bfd_signed_vma
, bfd_boolean
);
105 static bfd_boolean
pr_set_type (void *, bfd_boolean
);
106 static bfd_boolean
pr_offset_type (void *);
107 static bfd_boolean
pr_method_type (void *, bfd_boolean
, int, bfd_boolean
);
108 static bfd_boolean
pr_const_type (void *);
109 static bfd_boolean
pr_volatile_type (void *);
110 static bfd_boolean pr_start_struct_type
111 (void *, const char *, unsigned int, bfd_boolean
, unsigned int);
112 static bfd_boolean pr_struct_field
113 (void *, const char *, bfd_vma
, bfd_vma
, enum debug_visibility
);
114 static bfd_boolean
pr_end_struct_type (void *);
115 static bfd_boolean pr_start_class_type
116 (void *, const char *, unsigned int, bfd_boolean
, unsigned int,
117 bfd_boolean
, bfd_boolean
);
118 static bfd_boolean pr_class_static_member
119 (void *, const char *, const char *, enum debug_visibility
);
120 static bfd_boolean pr_class_baseclass
121 (void *, bfd_vma
, bfd_boolean
, enum debug_visibility
);
122 static bfd_boolean
pr_class_start_method (void *, const char *);
123 static bfd_boolean pr_class_method_variant
124 (void *, const char *, enum debug_visibility
, bfd_boolean
, bfd_boolean
,
125 bfd_vma
, bfd_boolean
);
126 static bfd_boolean pr_class_static_method_variant
127 (void *, const char *, enum debug_visibility
, bfd_boolean
, bfd_boolean
);
128 static bfd_boolean
pr_class_end_method (void *);
129 static bfd_boolean
pr_end_class_type (void *);
130 static bfd_boolean
pr_typedef_type (void *, const char *);
131 static bfd_boolean pr_tag_type
132 (void *, const char *, unsigned int, enum debug_type_kind
);
133 static bfd_boolean
pr_typdef (void *, const char *);
134 static bfd_boolean
pr_tag (void *, const char *);
135 static bfd_boolean
pr_int_constant (void *, const char *, bfd_vma
);
136 static bfd_boolean
pr_float_constant (void *, const char *, double);
137 static bfd_boolean
pr_typed_constant (void *, const char *, bfd_vma
);
138 static bfd_boolean pr_variable
139 (void *, const char *, enum debug_var_kind
, bfd_vma
);
140 static bfd_boolean
pr_start_function (void *, const char *, bfd_boolean
);
141 static bfd_boolean pr_function_parameter
142 (void *, const char *, enum debug_parm_kind
, bfd_vma
);
143 static bfd_boolean
pr_start_block (void *, bfd_vma
);
144 static bfd_boolean
pr_end_block (void *, bfd_vma
);
145 static bfd_boolean
pr_end_function (void *);
146 static bfd_boolean
pr_lineno (void *, const char *, unsigned long, bfd_vma
);
147 static bfd_boolean
append_parent (struct pr_handle
*, const char *);
148 /* Only used by tg_ code. */
149 static bfd_boolean tg_fix_visibility
150 (struct pr_handle
*, enum debug_visibility
);
151 static void find_address_in_section (bfd
*, asection
*, void *);
152 static void translate_addresses (bfd
*, char *, FILE *, asymbol
**);
153 static const char *visibility_name (enum debug_visibility
);
154 /* Tags style replacements. */
155 static bfd_boolean
tg_start_compilation_unit (void *, const char *);
156 static bfd_boolean
tg_start_source (void *, const char *);
157 static bfd_boolean tg_enum_type
158 (void *, const char *, const char **, bfd_signed_vma
*);
159 static bfd_boolean tg_start_struct_type
160 (void *, const char *, unsigned int, bfd_boolean
, unsigned int);
161 static bfd_boolean pr_struct_field
162 (void *, const char *, bfd_vma
, bfd_vma
, enum debug_visibility
);
163 static bfd_boolean tg_struct_field
164 (void *, const char *, bfd_vma
, bfd_vma
, enum debug_visibility
);
165 static bfd_boolean tg_struct_field
166 (void *, const char *, bfd_vma
, bfd_vma
, enum debug_visibility
);
167 static bfd_boolean
tg_end_struct_type (void *);
168 static bfd_boolean tg_start_class_type
169 (void *, const char *, unsigned int, bfd_boolean
, unsigned int, bfd_boolean
, bfd_boolean
);
170 static bfd_boolean tg_class_static_member
171 (void *, const char *, const char *, enum debug_visibility
);
172 static bfd_boolean tg_class_baseclass
173 (void *, bfd_vma
, bfd_boolean
, enum debug_visibility
);
174 static bfd_boolean tg_class_method_variant
175 (void *, const char *, enum debug_visibility
, bfd_boolean
, bfd_boolean
, bfd_vma
, bfd_boolean
);
176 static bfd_boolean tg_class_static_method_variant
177 (void *, const char *, enum debug_visibility
, bfd_boolean
, bfd_boolean
);
178 static bfd_boolean
tg_end_class_type (void *);
179 static bfd_boolean tg_tag_type
180 (void *, const char *, unsigned int, enum debug_type_kind
);
181 static bfd_boolean
tg_typdef (void *, const char *);
182 static bfd_boolean
tg_tag (void *, const char *);
183 static bfd_boolean
tg_int_constant (void *, const char *, bfd_vma
);
184 static bfd_boolean
tg_float_constant (void *, const char *, double);
185 static bfd_boolean
tg_typed_constant (void *, const char *, bfd_vma
);
186 static bfd_boolean tg_variable
187 (void *, const char *, enum debug_var_kind
, bfd_vma
);
188 static bfd_boolean
tg_start_function (void *, const char *, bfd_boolean
);
189 static bfd_boolean tg_function_parameter
190 (void *, const char *, enum debug_parm_kind
, bfd_vma
);
191 static bfd_boolean
tg_start_block (void *, bfd_vma
);
192 static bfd_boolean
tg_end_block (void *, bfd_vma
);
193 static bfd_boolean
tg_lineno (void *, const char *, unsigned long, bfd_vma
);
195 static const struct debug_write_fns pr_fns
=
197 pr_start_compilation_unit
,
216 pr_start_struct_type
,
220 pr_class_static_member
,
222 pr_class_start_method
,
223 pr_class_method_variant
,
224 pr_class_static_method_variant
,
236 pr_function_parameter
,
243 static const struct debug_write_fns tg_fns
=
245 tg_start_compilation_unit
,
247 pr_empty_type
, /* Same, push_type. */
248 pr_void_type
, /* Same, push_type. */
249 pr_int_type
, /* Same, push_type. */
250 pr_float_type
, /* Same, push_type. */
251 pr_complex_type
, /* Same, push_type. */
252 pr_bool_type
, /* Same, push_type. */
254 pr_pointer_type
, /* Same, changes to pointer. */
255 pr_function_type
, /* Same, push_type. */
256 pr_reference_type
, /* Same, changes to reference. */
257 pr_range_type
, /* FIXME: What's that?. */
258 pr_array_type
, /* Same, push_type. */
259 pr_set_type
, /* FIXME: What's that?. */
260 pr_offset_type
, /* FIXME: What's that?. */
261 pr_method_type
, /* Same. */
262 pr_const_type
, /* Same, changes to const. */
263 pr_volatile_type
, /* Same, changes to volatile. */
264 tg_start_struct_type
,
268 tg_class_static_member
,
270 pr_class_start_method
, /* Same, remembers that's a method. */
271 tg_class_method_variant
,
272 tg_class_static_method_variant
,
273 pr_class_end_method
, /* Same, forgets that's a method. */
275 pr_typedef_type
, /* Same, just push type. */
279 tg_int_constant
, /* Untested. */
280 tg_float_constant
, /* Untested. */
281 tg_typed_constant
, /* Untested. */
284 tg_function_parameter
,
287 pr_end_function
, /* Same, does nothing. */
291 /* Print out the generic debugging information recorded in dhandle. */
294 print_debugging_info (FILE *f
, void *dhandle
, bfd
*abfd
, asymbol
**syms
,
295 void *demangler
, bfd_boolean as_tags
)
297 struct pr_handle info
;
303 info
.filename
= NULL
;
306 info
.demangler
= (char * (*)(struct bfd
*, const char *, int)) demangler
;
310 fputs ("!_TAG_FILE_FORMAT\t2\t/extended format/\n", f
);
311 fputs ("!_TAG_FILE_SORTED\t0\t/0=unsorted, 1=sorted/\n", f
);
312 fputs ("!_TAG_PROGRAM_AUTHOR\tIan Lance Taylor, Salvador E. Tropea and others\t//\n", f
);
313 fputs ("!_TAG_PROGRAM_NAME\tobjdump\t/From GNU binutils/\n", f
);
316 return as_tags
? debug_write (dhandle
, &tg_fns
, (void *) & info
)
317 : debug_write (dhandle
, &pr_fns
, (void *) & info
);
320 /* Indent to the current indentation level. */
323 indent (struct pr_handle
*info
)
327 for (i
= 0; i
< info
->indent
; i
++)
331 /* Push a type on the type stack. */
334 push_type (struct pr_handle
*info
, const char *type
)
341 n
= (struct pr_stack
*) xmalloc (sizeof *n
);
342 memset (n
, 0, sizeof *n
);
344 n
->type
= xstrdup (type
);
345 n
->visibility
= DEBUG_VISIBILITY_IGNORE
;
347 n
->next
= info
->stack
;
353 /* Prepend a string onto the type on the top of the type stack. */
356 prepend_type (struct pr_handle
*info
, const char *s
)
360 assert (info
->stack
!= NULL
);
362 n
= (char *) xmalloc (strlen (s
) + strlen (info
->stack
->type
) + 1);
363 sprintf (n
, "%s%s", s
, info
->stack
->type
);
364 free (info
->stack
->type
);
365 info
->stack
->type
= n
;
370 /* Append a string to the type on the top of the type stack. */
373 append_type (struct pr_handle
*info
, const char *s
)
380 assert (info
->stack
!= NULL
);
382 len
= strlen (info
->stack
->type
);
383 info
->stack
->type
= (char *) xrealloc (info
->stack
->type
,
384 len
+ strlen (s
) + 1);
385 strcpy (info
->stack
->type
+ len
, s
);
390 /* Append a string to the parents on the top of the type stack. */
393 append_parent (struct pr_handle
*info
, const char *s
)
400 assert (info
->stack
!= NULL
);
402 len
= info
->stack
->parents
? strlen (info
->stack
->parents
) : 0;
403 info
->stack
->parents
= (char *) xrealloc (info
->stack
->parents
,
404 len
+ strlen (s
) + 1);
405 strcpy (info
->stack
->parents
+ len
, s
);
410 /* We use an underscore to indicate where the name should go in a type
411 string. This function substitutes a string for the underscore. If
412 there is no underscore, the name follows the type. */
415 substitute_type (struct pr_handle
*info
, const char *s
)
419 assert (info
->stack
!= NULL
);
421 u
= strchr (info
->stack
->type
, '|');
426 n
= (char *) xmalloc (strlen (info
->stack
->type
) + strlen (s
));
428 memcpy (n
, info
->stack
->type
, u
- info
->stack
->type
);
429 strcpy (n
+ (u
- info
->stack
->type
), s
);
432 free (info
->stack
->type
);
433 info
->stack
->type
= n
;
438 if (strchr (s
, '|') != NULL
439 && (strchr (info
->stack
->type
, '{') != NULL
440 || strchr (info
->stack
->type
, '(') != NULL
))
442 if (! prepend_type (info
, "(")
443 || ! append_type (info
, ")"))
450 return (append_type (info
, " ")
451 && append_type (info
, s
));
454 /* Indent the type at the top of the stack by appending spaces. */
457 indent_type (struct pr_handle
*info
)
461 for (i
= 0; i
< info
->indent
; i
++)
463 if (! append_type (info
, " "))
470 /* Pop a type from the type stack. */
473 pop_type (struct pr_handle
*info
)
478 assert (info
->stack
!= NULL
);
481 info
->stack
= o
->next
;
488 /* Print a VMA value into a string. */
491 print_vma (bfd_vma vma
, char *buf
, bfd_boolean unsignedp
, bfd_boolean hexp
)
493 if (sizeof (vma
) <= sizeof (unsigned long))
496 sprintf (buf
, "0x%lx", (unsigned long) vma
);
498 sprintf (buf
, "%lu", (unsigned long) vma
);
500 sprintf (buf
, "%ld", (long) vma
);
502 #if BFD_HOST_64BIT_LONG_LONG
503 else if (sizeof (vma
) <= sizeof (unsigned long long))
507 sprintf (buf
, "0x%llx", (unsigned long long) vma
);
509 sprintf (buf
, "%llu", (unsigned long long) vma
);
511 sprintf (buf
, "%lld", (long long) vma
);
514 sprintf (buf
, "0x%I64x", (unsigned long long) vma
);
516 sprintf (buf
, "%I64u", (unsigned long long) vma
);
518 sprintf (buf
, "%I64d", (long long) vma
);
526 sprintf_vma (buf
+ 2, vma
);
530 /* Start a new compilation unit. */
533 pr_start_compilation_unit (void *p
, const char *filename
)
535 struct pr_handle
*info
= (struct pr_handle
*) p
;
537 assert (info
->indent
== 0);
539 fprintf (info
->f
, "%s:\n", filename
);
544 /* Start a source file within a compilation unit. */
547 pr_start_source (void *p
, const char *filename
)
549 struct pr_handle
*info
= (struct pr_handle
*) p
;
551 assert (info
->indent
== 0);
553 fprintf (info
->f
, " %s:\n", filename
);
558 /* Push an empty type onto the type stack. */
561 pr_empty_type (void *p
)
563 struct pr_handle
*info
= (struct pr_handle
*) p
;
565 return push_type (info
, "<undefined>");
568 /* Push a void type onto the type stack. */
571 pr_void_type (void *p
)
573 struct pr_handle
*info
= (struct pr_handle
*) p
;
575 return push_type (info
, "void");
578 /* Push an integer type onto the type stack. */
581 pr_int_type (void *p
, unsigned int size
, bfd_boolean unsignedp
)
583 struct pr_handle
*info
= (struct pr_handle
*) p
;
586 sprintf (ab
, "%sint%d", unsignedp
? "u" : "", size
* 8);
587 return push_type (info
, ab
);
590 /* Push a floating type onto the type stack. */
593 pr_float_type (void *p
, unsigned int size
)
595 struct pr_handle
*info
= (struct pr_handle
*) p
;
599 return push_type (info
, "float");
601 return push_type (info
, "double");
603 sprintf (ab
, "float%d", size
* 8);
604 return push_type (info
, ab
);
607 /* Push a complex type onto the type stack. */
610 pr_complex_type (void *p
, unsigned int size
)
612 struct pr_handle
*info
= (struct pr_handle
*) p
;
614 if (! pr_float_type (p
, size
))
617 return prepend_type (info
, "complex ");
620 /* Push a bfd_boolean type onto the type stack. */
623 pr_bool_type (void *p
, unsigned int size
)
625 struct pr_handle
*info
= (struct pr_handle
*) p
;
628 sprintf (ab
, "bool%d", size
* 8);
630 return push_type (info
, ab
);
633 /* Push an enum type onto the type stack. */
636 pr_enum_type (void *p
, const char *tag
, const char **names
,
637 bfd_signed_vma
*values
)
639 struct pr_handle
*info
= (struct pr_handle
*) p
;
643 if (! push_type (info
, "enum "))
647 if (! append_type (info
, tag
)
648 || ! append_type (info
, " "))
651 if (! append_type (info
, "{ "))
656 if (! append_type (info
, "/* undefined */"))
662 for (i
= 0; names
[i
] != NULL
; i
++)
666 if (! append_type (info
, ", "))
670 if (! append_type (info
, names
[i
]))
673 if (values
[i
] != val
)
677 print_vma (values
[i
], ab
, FALSE
, FALSE
);
678 if (! append_type (info
, " = ")
679 || ! append_type (info
, ab
))
688 return append_type (info
, " }");
691 /* Turn the top type on the stack into a pointer. */
694 pr_pointer_type (void *p
)
696 struct pr_handle
*info
= (struct pr_handle
*) p
;
699 assert (info
->stack
!= NULL
);
701 s
= strchr (info
->stack
->type
, '|');
702 if (s
!= NULL
&& s
[1] == '[')
703 return substitute_type (info
, "(*|)");
704 return substitute_type (info
, "*|");
707 /* Turn the top type on the stack into a function returning that type. */
710 pr_function_type (void *p
, int argcount
, bfd_boolean varargs
)
712 struct pr_handle
*info
= (struct pr_handle
*) p
;
717 assert (info
->stack
!= NULL
);
730 arg_types
= (char **) xmalloc (argcount
* sizeof *arg_types
);
731 for (i
= argcount
- 1; i
>= 0; i
--)
733 if (! substitute_type (info
, ""))
735 arg_types
[i
] = pop_type (info
);
736 if (arg_types
[i
] == NULL
)
738 len
+= strlen (arg_types
[i
]) + 2;
744 /* Now the return type is on the top of the stack. */
746 s
= (char *) xmalloc (len
);
747 LITSTRCPY (s
, "(|) (");
750 strcat (s
, "/* unknown */");
755 for (i
= 0; i
< argcount
; i
++)
759 strcat (s
, arg_types
[i
]);
773 if (! substitute_type (info
, s
))
781 /* Turn the top type on the stack into a reference to that type. */
784 pr_reference_type (void *p
)
786 struct pr_handle
*info
= (struct pr_handle
*) p
;
788 assert (info
->stack
!= NULL
);
790 return substitute_type (info
, "&|");
793 /* Make a range type. */
796 pr_range_type (void *p
, bfd_signed_vma lower
, bfd_signed_vma upper
)
798 struct pr_handle
*info
= (struct pr_handle
*) p
;
799 char abl
[20], abu
[20];
801 assert (info
->stack
!= NULL
);
803 if (! substitute_type (info
, ""))
806 print_vma (lower
, abl
, FALSE
, FALSE
);
807 print_vma (upper
, abu
, FALSE
, FALSE
);
809 return (prepend_type (info
, "range (")
810 && append_type (info
, "):")
811 && append_type (info
, abl
)
812 && append_type (info
, ":")
813 && append_type (info
, abu
));
816 /* Make an array type. */
819 pr_array_type (void *p
, bfd_signed_vma lower
, bfd_signed_vma upper
,
822 struct pr_handle
*info
= (struct pr_handle
*) p
;
824 char abl
[20], abu
[20], ab
[50];
826 range_type
= pop_type (info
);
827 if (range_type
== NULL
)
836 print_vma (upper
+ 1, abu
, FALSE
, FALSE
);
837 sprintf (ab
, "|[%s]", abu
);
842 print_vma (lower
, abl
, FALSE
, FALSE
);
843 print_vma (upper
, abu
, FALSE
, FALSE
);
844 sprintf (ab
, "|[%s:%s]", abl
, abu
);
847 if (! substitute_type (info
, ab
))
850 if (strcmp (range_type
, "int") != 0)
852 if (! append_type (info
, ":")
853 || ! append_type (info
, range_type
))
859 if (! append_type (info
, " /* string */"))
866 /* Make a set type. */
869 pr_set_type (void *p
, bfd_boolean bitstringp
)
871 struct pr_handle
*info
= (struct pr_handle
*) p
;
873 if (! substitute_type (info
, ""))
876 if (! prepend_type (info
, "set { ")
877 || ! append_type (info
, " }"))
882 if (! append_type (info
, "/* bitstring */"))
889 /* Make an offset type. */
892 pr_offset_type (void *p
)
894 struct pr_handle
*info
= (struct pr_handle
*) p
;
897 if (! substitute_type (info
, ""))
904 return (substitute_type (info
, "")
905 && prepend_type (info
, " ")
906 && prepend_type (info
, t
)
907 && append_type (info
, "::|"));
910 /* Make a method type. */
913 pr_method_type (void *p
, bfd_boolean domain
, int argcount
, bfd_boolean varargs
)
915 struct pr_handle
*info
= (struct pr_handle
*) p
;
927 if (! substitute_type (info
, ""))
929 domain_type
= pop_type (info
);
930 if (domain_type
== NULL
)
932 if (CONST_STRNEQ (domain_type
, "class ")
933 && strchr (domain_type
+ sizeof "class " - 1, ' ') == NULL
)
934 domain_type
+= sizeof "class " - 1;
935 else if (CONST_STRNEQ (domain_type
, "union class ")
936 && (strchr (domain_type
+ sizeof "union class " - 1, ' ')
938 domain_type
+= sizeof "union class " - 1;
939 len
+= strlen (domain_type
);
951 arg_types
= (char **) xmalloc (argcount
* sizeof *arg_types
);
952 for (i
= argcount
- 1; i
>= 0; i
--)
954 if (! substitute_type (info
, ""))
956 arg_types
[i
] = pop_type (info
);
957 if (arg_types
[i
] == NULL
)
959 len
+= strlen (arg_types
[i
]) + 2;
965 /* Now the return type is on the top of the stack. */
967 s
= (char *) xmalloc (len
);
971 strcpy (s
, domain_type
);
975 strcat (s
, "/* unknown */");
980 for (i
= 0; i
< argcount
; i
++)
984 strcat (s
, arg_types
[i
]);
998 if (! substitute_type (info
, s
))
1006 /* Make a const qualified type. */
1009 pr_const_type (void *p
)
1011 struct pr_handle
*info
= (struct pr_handle
*) p
;
1013 return substitute_type (info
, "const |");
1016 /* Make a volatile qualified type. */
1019 pr_volatile_type (void *p
)
1021 struct pr_handle
*info
= (struct pr_handle
*) p
;
1023 return substitute_type (info
, "volatile |");
1026 /* Start accumulating a struct type. */
1029 pr_start_struct_type (void *p
, const char *tag
, unsigned int id
,
1030 bfd_boolean structp
, unsigned int size
)
1032 struct pr_handle
*info
= (struct pr_handle
*) p
;
1036 if (! push_type (info
, structp
? "struct " : "union "))
1040 if (! append_type (info
, tag
))
1047 sprintf (idbuf
, "%%anon%u", id
);
1048 if (! append_type (info
, idbuf
))
1052 if (! append_type (info
, " {"))
1054 if (size
!= 0 || tag
!= NULL
)
1058 if (! append_type (info
, " /*"))
1063 sprintf (ab
, " size %u", size
);
1064 if (! append_type (info
, ab
))
1069 sprintf (ab
, " id %u", id
);
1070 if (! append_type (info
, ab
))
1073 if (! append_type (info
, " */"))
1076 if (! append_type (info
, "\n"))
1079 info
->stack
->visibility
= DEBUG_VISIBILITY_PUBLIC
;
1081 return indent_type (info
);
1084 /* Output the visibility of a field in a struct. */
1087 pr_fix_visibility (struct pr_handle
*info
, enum debug_visibility visibility
)
1089 const char *s
= NULL
;
1093 assert (info
->stack
!= NULL
);
1095 if (info
->stack
->visibility
== visibility
)
1100 case DEBUG_VISIBILITY_PUBLIC
:
1103 case DEBUG_VISIBILITY_PRIVATE
:
1106 case DEBUG_VISIBILITY_PROTECTED
:
1109 case DEBUG_VISIBILITY_IGNORE
:
1117 /* Trim off a trailing space in the struct string, to make the
1118 output look a bit better, then stick on the visibility string. */
1120 t
= info
->stack
->type
;
1122 assert (t
[len
- 1] == ' ');
1125 if (! append_type (info
, s
)
1126 || ! append_type (info
, ":\n")
1127 || ! indent_type (info
))
1130 info
->stack
->visibility
= visibility
;
1135 /* Add a field to a struct type. */
1138 pr_struct_field (void *p
, const char *name
, bfd_vma bitpos
, bfd_vma bitsize
,
1139 enum debug_visibility visibility
)
1141 struct pr_handle
*info
= (struct pr_handle
*) p
;
1145 if (! substitute_type (info
, name
))
1148 if (! append_type (info
, "; /* "))
1153 print_vma (bitsize
, ab
, TRUE
, FALSE
);
1154 if (! append_type (info
, "bitsize ")
1155 || ! append_type (info
, ab
)
1156 || ! append_type (info
, ", "))
1160 print_vma (bitpos
, ab
, TRUE
, FALSE
);
1161 if (! append_type (info
, "bitpos ")
1162 || ! append_type (info
, ab
)
1163 || ! append_type (info
, " */\n")
1164 || ! indent_type (info
))
1167 t
= pop_type (info
);
1171 if (! pr_fix_visibility (info
, visibility
))
1174 return append_type (info
, t
);
1177 /* Finish a struct type. */
1180 pr_end_struct_type (void *p
)
1182 struct pr_handle
*info
= (struct pr_handle
*) p
;
1185 assert (info
->stack
!= NULL
);
1186 assert (info
->indent
>= 2);
1190 /* Change the trailing indentation to have a close brace. */
1191 s
= info
->stack
->type
+ strlen (info
->stack
->type
) - 2;
1192 assert (s
[0] == ' ' && s
[1] == ' ' && s
[2] == '\0');
1200 /* Start a class type. */
1203 pr_start_class_type (void *p
, const char *tag
, unsigned int id
,
1204 bfd_boolean structp
, unsigned int size
,
1205 bfd_boolean vptr
, bfd_boolean ownvptr
)
1207 struct pr_handle
*info
= (struct pr_handle
*) p
;
1212 if (vptr
&& ! ownvptr
)
1214 tv
= pop_type (info
);
1219 if (! push_type (info
, structp
? "class " : "union class "))
1223 if (! append_type (info
, tag
))
1230 sprintf (idbuf
, "%%anon%u", id
);
1231 if (! append_type (info
, idbuf
))
1235 if (! append_type (info
, " {"))
1237 if (size
!= 0 || vptr
|| ownvptr
|| tag
!= NULL
)
1239 if (! append_type (info
, " /*"))
1246 sprintf (ab
, "%u", size
);
1247 if (! append_type (info
, " size ")
1248 || ! append_type (info
, ab
))
1254 if (! append_type (info
, " vtable "))
1258 if (! append_type (info
, "self "))
1263 if (! append_type (info
, tv
)
1264 || ! append_type (info
, " "))
1273 sprintf (ab
, " id %u", id
);
1274 if (! append_type (info
, ab
))
1278 if (! append_type (info
, " */"))
1282 info
->stack
->visibility
= DEBUG_VISIBILITY_PRIVATE
;
1284 return (append_type (info
, "\n")
1285 && indent_type (info
));
1288 /* Add a static member to a class. */
1291 pr_class_static_member (void *p
, const char *name
, const char *physname
,
1292 enum debug_visibility visibility
)
1294 struct pr_handle
*info
= (struct pr_handle
*) p
;
1297 if (! substitute_type (info
, name
))
1300 if (! prepend_type (info
, "static ")
1301 || ! append_type (info
, "; /* ")
1302 || ! append_type (info
, physname
)
1303 || ! append_type (info
, " */\n")
1304 || ! indent_type (info
))
1307 t
= pop_type (info
);
1311 if (! pr_fix_visibility (info
, visibility
))
1314 return append_type (info
, t
);
1317 /* Add a base class to a class. */
1320 pr_class_baseclass (void *p
, bfd_vma bitpos
, bfd_boolean is_virtual
,
1321 enum debug_visibility visibility
)
1323 struct pr_handle
*info
= (struct pr_handle
*) p
;
1329 assert (info
->stack
!= NULL
&& info
->stack
->next
!= NULL
);
1331 if (! substitute_type (info
, ""))
1334 t
= pop_type (info
);
1338 if (CONST_STRNEQ (t
, "class "))
1339 t
+= sizeof "class " - 1;
1341 /* Push it back on to take advantage of the prepend_type and
1342 append_type routines. */
1343 if (! push_type (info
, t
))
1348 if (! prepend_type (info
, "virtual "))
1354 case DEBUG_VISIBILITY_PUBLIC
:
1357 case DEBUG_VISIBILITY_PROTECTED
:
1358 prefix
= "protected ";
1360 case DEBUG_VISIBILITY_PRIVATE
:
1361 prefix
= "private ";
1364 prefix
= "/* unknown visibility */ ";
1368 if (! prepend_type (info
, prefix
))
1373 print_vma (bitpos
, ab
, TRUE
, FALSE
);
1374 if (! append_type (info
, " /* bitpos ")
1375 || ! append_type (info
, ab
)
1376 || ! append_type (info
, " */"))
1380 /* Now the top of the stack is something like "public A / * bitpos
1381 10 * /". The next element on the stack is something like "class
1382 xx { / * size 8 * /\n...". We want to substitute the top of the
1383 stack in before the {. */
1384 s
= strchr (info
->stack
->next
->type
, '{');
1388 /* If there is already a ':', then we already have a baseclass, and
1389 we must append this one after a comma. */
1390 for (l
= info
->stack
->next
->type
; l
!= s
; l
++)
1393 if (! prepend_type (info
, l
== s
? " : " : ", "))
1396 t
= pop_type (info
);
1400 n
= (char *) xmalloc (strlen (info
->stack
->type
) + strlen (t
) + 1);
1401 memcpy (n
, info
->stack
->type
, s
- info
->stack
->type
);
1402 strcpy (n
+ (s
- info
->stack
->type
), t
);
1405 free (info
->stack
->type
);
1406 info
->stack
->type
= n
;
1413 /* Start adding a method to a class. */
1416 pr_class_start_method (void *p
, const char *name
)
1418 struct pr_handle
*info
= (struct pr_handle
*) p
;
1420 assert (info
->stack
!= NULL
);
1421 info
->stack
->method
= name
;
1425 /* Add a variant to a method. */
1428 pr_class_method_variant (void *p
, const char *physname
,
1429 enum debug_visibility visibility
,
1430 bfd_boolean constp
, bfd_boolean volatilep
,
1431 bfd_vma voffset
, bfd_boolean context
)
1433 struct pr_handle
*info
= (struct pr_handle
*) p
;
1437 assert (info
->stack
!= NULL
);
1438 assert (info
->stack
->next
!= NULL
);
1440 /* Put the const and volatile qualifiers on the type. */
1443 if (! append_type (info
, " volatile"))
1448 if (! append_type (info
, " const"))
1452 /* Stick the name of the method into its type. */
1453 if (! substitute_type (info
,
1455 ? info
->stack
->next
->next
->method
1456 : info
->stack
->next
->method
)))
1460 method_type
= pop_type (info
);
1461 if (method_type
== NULL
)
1464 /* Pull off the context type if there is one. */
1466 context_type
= NULL
;
1469 context_type
= pop_type (info
);
1470 if (context_type
== NULL
)
1474 /* Now the top of the stack is the class. */
1476 if (! pr_fix_visibility (info
, visibility
))
1479 if (! append_type (info
, method_type
)
1480 || ! append_type (info
, " /* ")
1481 || ! append_type (info
, physname
)
1482 || ! append_type (info
, " "))
1484 if (context
|| voffset
!= 0)
1490 if (! append_type (info
, "context ")
1491 || ! append_type (info
, context_type
)
1492 || ! append_type (info
, " "))
1495 print_vma (voffset
, ab
, TRUE
, FALSE
);
1496 if (! append_type (info
, "voffset ")
1497 || ! append_type (info
, ab
))
1501 return (append_type (info
, " */;\n")
1502 && indent_type (info
));
1505 /* Add a static variant to a method. */
1508 pr_class_static_method_variant (void *p
, const char *physname
,
1509 enum debug_visibility visibility
,
1510 bfd_boolean constp
, bfd_boolean volatilep
)
1512 struct pr_handle
*info
= (struct pr_handle
*) p
;
1515 assert (info
->stack
!= NULL
);
1516 assert (info
->stack
->next
!= NULL
);
1517 assert (info
->stack
->next
->method
!= NULL
);
1519 /* Put the const and volatile qualifiers on the type. */
1522 if (! append_type (info
, " volatile"))
1527 if (! append_type (info
, " const"))
1531 /* Mark it as static. */
1532 if (! prepend_type (info
, "static "))
1535 /* Stick the name of the method into its type. */
1536 if (! substitute_type (info
, info
->stack
->next
->method
))
1540 method_type
= pop_type (info
);
1541 if (method_type
== NULL
)
1544 /* Now the top of the stack is the class. */
1546 if (! pr_fix_visibility (info
, visibility
))
1549 return (append_type (info
, method_type
)
1550 && append_type (info
, " /* ")
1551 && append_type (info
, physname
)
1552 && append_type (info
, " */;\n")
1553 && indent_type (info
));
1556 /* Finish up a method. */
1559 pr_class_end_method (void *p
)
1561 struct pr_handle
*info
= (struct pr_handle
*) p
;
1563 info
->stack
->method
= NULL
;
1567 /* Finish up a class. */
1570 pr_end_class_type (void *p
)
1572 return pr_end_struct_type (p
);
1575 /* Push a type on the stack using a typedef name. */
1578 pr_typedef_type (void *p
, const char *name
)
1580 struct pr_handle
*info
= (struct pr_handle
*) p
;
1582 return push_type (info
, name
);
1585 /* Push a type on the stack using a tag name. */
1588 pr_tag_type (void *p
, const char *name
, unsigned int id
,
1589 enum debug_type_kind kind
)
1591 struct pr_handle
*info
= (struct pr_handle
*) p
;
1592 const char *t
, *tag
;
1597 case DEBUG_KIND_STRUCT
:
1600 case DEBUG_KIND_UNION
:
1603 case DEBUG_KIND_ENUM
:
1606 case DEBUG_KIND_CLASS
:
1609 case DEBUG_KIND_UNION_CLASS
:
1617 if (! push_type (info
, t
))
1623 sprintf (idbuf
, "%%anon%u", id
);
1627 if (! append_type (info
, tag
))
1629 if (name
!= NULL
&& kind
!= DEBUG_KIND_ENUM
)
1631 sprintf (idbuf
, " /* id %u */", id
);
1632 if (! append_type (info
, idbuf
))
1639 /* Output a typedef. */
1642 pr_typdef (void *p
, const char *name
)
1644 struct pr_handle
*info
= (struct pr_handle
*) p
;
1647 if (! substitute_type (info
, name
))
1650 s
= pop_type (info
);
1655 fprintf (info
->f
, "typedef %s;\n", s
);
1662 /* Output a tag. The tag should already be in the string on the
1663 stack, so all we have to do here is print it out. */
1666 pr_tag (void *p
, const char *name ATTRIBUTE_UNUSED
)
1668 struct pr_handle
*info
= (struct pr_handle
*) p
;
1671 t
= pop_type (info
);
1676 fprintf (info
->f
, "%s;\n", t
);
1683 /* Output an integer constant. */
1686 pr_int_constant (void *p
, const char *name
, bfd_vma val
)
1688 struct pr_handle
*info
= (struct pr_handle
*) p
;
1692 print_vma (val
, ab
, FALSE
, FALSE
);
1693 fprintf (info
->f
, "const int %s = %s;\n", name
, ab
);
1697 /* Output a floating point constant. */
1700 pr_float_constant (void *p
, const char *name
, double val
)
1702 struct pr_handle
*info
= (struct pr_handle
*) p
;
1705 fprintf (info
->f
, "const double %s = %g;\n", name
, val
);
1709 /* Output a typed constant. */
1712 pr_typed_constant (void *p
, const char *name
, bfd_vma val
)
1714 struct pr_handle
*info
= (struct pr_handle
*) p
;
1718 t
= pop_type (info
);
1723 print_vma (val
, ab
, FALSE
, FALSE
);
1724 fprintf (info
->f
, "const %s %s = %s;\n", t
, name
, ab
);
1731 /* Output a variable. */
1734 pr_variable (void *p
, const char *name
, enum debug_var_kind kind
,
1737 struct pr_handle
*info
= (struct pr_handle
*) p
;
1741 if (! substitute_type (info
, name
))
1744 t
= pop_type (info
);
1752 case DEBUG_LOCAL_STATIC
:
1753 fprintf (info
->f
, "static ");
1755 case DEBUG_REGISTER
:
1756 fprintf (info
->f
, "register ");
1761 print_vma (val
, ab
, TRUE
, TRUE
);
1762 fprintf (info
->f
, "%s /* %s */;\n", t
, ab
);
1769 /* Start outputting a function. */
1772 pr_start_function (void *p
, const char *name
, bfd_boolean global
)
1774 struct pr_handle
*info
= (struct pr_handle
*) p
;
1777 if (! substitute_type (info
, name
))
1780 t
= pop_type (info
);
1786 fprintf (info
->f
, "static ");
1787 fprintf (info
->f
, "%s (", t
);
1789 info
->parameter
= 1;
1794 /* Output a function parameter. */
1797 pr_function_parameter (void *p
, const char *name
,
1798 enum debug_parm_kind kind
, bfd_vma val
)
1800 struct pr_handle
*info
= (struct pr_handle
*) p
;
1804 if (kind
== DEBUG_PARM_REFERENCE
1805 || kind
== DEBUG_PARM_REF_REG
)
1807 if (! pr_reference_type (p
))
1811 if (! substitute_type (info
, name
))
1814 t
= pop_type (info
);
1818 if (info
->parameter
!= 1)
1819 fprintf (info
->f
, ", ");
1821 if (kind
== DEBUG_PARM_REG
|| kind
== DEBUG_PARM_REF_REG
)
1822 fprintf (info
->f
, "register ");
1824 print_vma (val
, ab
, TRUE
, TRUE
);
1825 fprintf (info
->f
, "%s /* %s */", t
, ab
);
1834 /* Start writing out a block. */
1837 pr_start_block (void *p
, bfd_vma addr
)
1839 struct pr_handle
*info
= (struct pr_handle
*) p
;
1842 if (info
->parameter
> 0)
1844 fprintf (info
->f
, ")\n");
1845 info
->parameter
= 0;
1849 print_vma (addr
, ab
, TRUE
, TRUE
);
1850 fprintf (info
->f
, "{ /* %s */\n", ab
);
1857 /* Write out line number information. */
1860 pr_lineno (void *p
, const char *filename
, unsigned long lineno
, bfd_vma addr
)
1862 struct pr_handle
*info
= (struct pr_handle
*) p
;
1866 print_vma (addr
, ab
, TRUE
, TRUE
);
1867 fprintf (info
->f
, "/* file %s line %lu addr %s */\n", filename
, lineno
, ab
);
1872 /* Finish writing out a block. */
1875 pr_end_block (void *p
, bfd_vma addr
)
1877 struct pr_handle
*info
= (struct pr_handle
*) p
;
1883 print_vma (addr
, ab
, TRUE
, TRUE
);
1884 fprintf (info
->f
, "} /* %s */\n", ab
);
1889 /* Finish writing out a function. */
1892 pr_end_function (void *p ATTRIBUTE_UNUSED
)
1897 /* Tags style generation functions start here. */
1899 /* Variables for address to line translation. */
1901 static const char *filename
;
1902 static const char *functionname
;
1903 static unsigned int line
;
1904 static bfd_boolean found
;
1906 /* Look for an address in a section. This is called via
1907 bfd_map_over_sections. */
1910 find_address_in_section (bfd
*abfd
, asection
*section
, void *data
)
1914 asymbol
**syms
= (asymbol
**) data
;
1919 if ((bfd_get_section_flags (abfd
, section
) & SEC_ALLOC
) == 0)
1922 vma
= bfd_get_section_vma (abfd
, section
);
1926 size
= bfd_get_section_size (section
);
1927 if (pc
>= vma
+ size
)
1930 found
= bfd_find_nearest_line (abfd
, section
, syms
, pc
- vma
,
1931 &filename
, &functionname
, &line
);
1935 translate_addresses (bfd
*abfd
, char *addr_hex
, FILE *f
, asymbol
**syms
)
1937 pc
= bfd_scan_vma (addr_hex
, NULL
, 16);
1939 bfd_map_over_sections (abfd
, find_address_in_section
, syms
);
1944 fprintf (f
, "%u", line
);
1947 /* Start a new compilation unit. */
1950 tg_start_compilation_unit (void * p
, const char *filename ATTRIBUTE_UNUSED
)
1952 struct pr_handle
*info
= (struct pr_handle
*) p
;
1954 free (info
->filename
);
1955 /* Should it be relative? best way to do it here?. */
1956 info
->filename
= strdup (filename
);
1961 /* Start a source file within a compilation unit. */
1964 tg_start_source (void *p
, const char *filename
)
1966 struct pr_handle
*info
= (struct pr_handle
*) p
;
1968 free (info
->filename
);
1969 /* Should it be relative? best way to do it here?. */
1970 info
->filename
= strdup (filename
);
1975 /* Push an enum type onto the type stack. */
1978 tg_enum_type (void *p
, const char *tag
, const char **names
,
1979 bfd_signed_vma
*values
)
1981 struct pr_handle
*info
= (struct pr_handle
*) p
;
1986 if (! pr_enum_type (p
, tag
, names
, values
))
1989 name
= tag
? tag
: "unknown";
1990 /* Generate an entry for the enum. */
1992 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:e\ttype:%s\n", tag
,
1993 info
->filename
, info
->stack
->type
);
1995 /* Generate entries for the values. */
1998 for (i
= 0; names
[i
] != NULL
; i
++)
2000 print_vma (values
[i
], ab
, FALSE
, FALSE
);
2001 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:g\tenum:%s\tvalue:%s\n",
2002 names
[i
], info
->filename
, name
, ab
);
2009 /* Start accumulating a struct type. */
2012 tg_start_struct_type (void *p
, const char *tag
, unsigned int id
,
2013 bfd_boolean structp
,
2014 unsigned int size ATTRIBUTE_UNUSED
)
2016 struct pr_handle
*info
= (struct pr_handle
*) p
;
2025 sprintf (idbuf
, "%%anon%u", id
);
2028 if (! push_type (info
, name
))
2031 info
->stack
->flavor
= structp
? "struct" : "union";
2033 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:%c\n", name
, info
->filename
,
2034 info
->stack
->flavor
[0]);
2036 info
->stack
->visibility
= DEBUG_VISIBILITY_PUBLIC
;
2038 return indent_type (info
);
2041 /* Output the visibility of a field in a struct. */
2044 tg_fix_visibility (struct pr_handle
*info
, enum debug_visibility visibility
)
2046 assert (info
->stack
!= NULL
);
2048 if (info
->stack
->visibility
== visibility
)
2051 assert (info
->stack
->visibility
!= DEBUG_VISIBILITY_IGNORE
);
2053 info
->stack
->visibility
= visibility
;
2058 /* Add a field to a struct type. */
2061 tg_struct_field (void *p
, const char *name
, bfd_vma bitpos ATTRIBUTE_UNUSED
,
2062 bfd_vma bitsize ATTRIBUTE_UNUSED
,
2063 enum debug_visibility visibility
)
2065 struct pr_handle
*info
= (struct pr_handle
*) p
;
2068 t
= pop_type (info
);
2072 if (! tg_fix_visibility (info
, visibility
))
2075 /* It happens, a bug? */
2079 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:m\ttype:%s\t%s:%s\taccess:%s\n",
2080 name
, info
->filename
, t
, info
->stack
->flavor
, info
->stack
->type
,
2081 visibility_name (visibility
));
2086 /* Finish a struct type. */
2089 tg_end_struct_type (void *p ATTRIBUTE_UNUSED
)
2091 struct pr_handle
*info
= (struct pr_handle
*) p
;
2092 assert (info
->stack
!= NULL
);
2097 /* Start a class type. */
2100 tg_start_class_type (void *p
, const char *tag
, unsigned int id
,
2101 bfd_boolean structp
, unsigned int size
,
2102 bfd_boolean vptr
, bfd_boolean ownvptr
)
2104 struct pr_handle
*info
= (struct pr_handle
*) p
;
2110 if (vptr
&& ! ownvptr
)
2112 tv
= pop_type (info
);
2123 sprintf (idbuf
, "%%anon%u", id
);
2127 if (! push_type (info
, name
))
2130 info
->stack
->flavor
= structp
? "class" : "union class";
2131 info
->stack
->parents
= NULL
;
2132 info
->stack
->num_parents
= 0;
2134 if (size
!= 0 || vptr
|| ownvptr
|| tag
!= NULL
)
2138 if (! append_type (info
, " vtable "))
2142 if (! append_type (info
, "self "))
2147 if (! append_type (info
, tv
)
2148 || ! append_type (info
, " "))
2154 info
->stack
->visibility
= DEBUG_VISIBILITY_PRIVATE
;
2159 /* Add a static member to a class. */
2162 tg_class_static_member (void *p
, const char *name
,
2163 const char *physname ATTRIBUTE_UNUSED
,
2164 enum debug_visibility visibility
)
2166 struct pr_handle
*info
= (struct pr_handle
*) p
;
2168 int len_var
, len_class
;
2171 len_var
= strlen (name
);
2172 len_class
= strlen (info
->stack
->next
->type
);
2173 full_name
= (char *) xmalloc (len_var
+ len_class
+ 3);
2176 sprintf (full_name
, "%s::%s", info
->stack
->next
->type
, name
);
2178 if (! substitute_type (info
, full_name
))
2181 if (! prepend_type (info
, "static "))
2184 t
= pop_type (info
);
2188 if (! tg_fix_visibility (info
, visibility
))
2191 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:x\ttype:%s\tclass:%s\taccess:%s\n",
2192 name
, info
->filename
, t
, info
->stack
->type
,
2193 visibility_name (visibility
));
2200 /* Add a base class to a class. */
2203 tg_class_baseclass (void *p
, bfd_vma bitpos ATTRIBUTE_UNUSED
,
2204 bfd_boolean is_virtual
, enum debug_visibility visibility
)
2206 struct pr_handle
*info
= (struct pr_handle
*) p
;
2210 assert (info
->stack
!= NULL
&& info
->stack
->next
!= NULL
);
2212 t
= pop_type (info
);
2216 if (CONST_STRNEQ (t
, "class "))
2217 t
+= sizeof "class " - 1;
2219 /* Push it back on to take advantage of the prepend_type and
2220 append_type routines. */
2221 if (! push_type (info
, t
))
2226 if (! prepend_type (info
, "virtual "))
2232 case DEBUG_VISIBILITY_PUBLIC
:
2235 case DEBUG_VISIBILITY_PROTECTED
:
2236 prefix
= "protected ";
2238 case DEBUG_VISIBILITY_PRIVATE
:
2239 prefix
= "private ";
2242 prefix
= "/* unknown visibility */ ";
2246 if (! prepend_type (info
, prefix
))
2249 t
= pop_type (info
);
2253 if (info
->stack
->num_parents
&& ! append_parent (info
, ", "))
2256 if (! append_parent (info
, t
))
2258 info
->stack
->num_parents
++;
2265 /* Add a variant to a method. */
2268 tg_class_method_variant (void *p
, const char *physname ATTRIBUTE_UNUSED
,
2269 enum debug_visibility visibility
,
2270 bfd_boolean constp
, bfd_boolean volatilep
,
2271 bfd_vma voffset ATTRIBUTE_UNUSED
,
2272 bfd_boolean context
)
2274 struct pr_handle
*info
= (struct pr_handle
*) p
;
2279 assert (info
->stack
!= NULL
);
2280 assert (info
->stack
->next
!= NULL
);
2282 /* Put the const and volatile qualifiers on the type. */
2285 if (! append_type (info
, " volatile"))
2290 if (! append_type (info
, " const"))
2294 method_name
= strdup (context
? info
->stack
->next
->next
->method
2295 : info
->stack
->next
->method
);
2297 /* Stick the name of the method into its type. */
2298 if (! substitute_type (info
, method_name
))
2302 method_type
= pop_type (info
);
2303 if (method_type
== NULL
)
2306 /* Pull off the context type if there is one. */
2308 context_type
= NULL
;
2311 context_type
= pop_type (info
);
2312 if (context_type
== NULL
)
2316 /* Now the top of the stack is the class. */
2317 if (! tg_fix_visibility (info
, visibility
))
2320 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:p\ttype:%s\tclass:%s\n",
2321 method_name
, info
->filename
, method_type
, info
->stack
->type
);
2324 free (context_type
);
2329 /* Add a static variant to a method. */
2332 tg_class_static_method_variant (void *p
,
2333 const char *physname ATTRIBUTE_UNUSED
,
2334 enum debug_visibility visibility
,
2335 bfd_boolean constp
, bfd_boolean volatilep
)
2337 struct pr_handle
*info
= (struct pr_handle
*) p
;
2341 assert (info
->stack
!= NULL
);
2342 assert (info
->stack
->next
!= NULL
);
2343 assert (info
->stack
->next
->method
!= NULL
);
2345 /* Put the const and volatile qualifiers on the type. */
2348 if (! append_type (info
, " volatile"))
2353 if (! append_type (info
, " const"))
2357 /* Mark it as static. */
2358 if (! prepend_type (info
, "static "))
2361 method_name
= strdup (info
->stack
->next
->method
);
2362 /* Stick the name of the method into its type. */
2363 if (! substitute_type (info
, info
->stack
->next
->method
))
2367 method_type
= pop_type (info
);
2368 if (method_type
== NULL
)
2371 /* Now the top of the stack is the class. */
2372 if (! tg_fix_visibility (info
, visibility
))
2375 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:p\ttype:%s\tclass:%s\taccess:%s\n",
2376 method_name
, info
->filename
, method_type
, info
->stack
->type
,
2377 visibility_name (visibility
));
2384 /* Finish up a class. */
2387 tg_end_class_type (void *p
)
2389 struct pr_handle
*info
= (struct pr_handle
*) p
;
2391 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:c\ttype:%s", info
->stack
->type
,
2392 info
->filename
, info
->stack
->flavor
);
2393 if (info
->stack
->num_parents
)
2395 fprintf (info
->f
, "\tinherits:%s", info
->stack
->parents
);
2396 free (info
->stack
->parents
);
2398 fputc ('\n', info
->f
);
2400 return tg_end_struct_type (p
);
2403 /* Push a type on the stack using a tag name. */
2406 tg_tag_type (void *p
, const char *name
, unsigned int id
,
2407 enum debug_type_kind kind
)
2409 struct pr_handle
*info
= (struct pr_handle
*) p
;
2410 const char *t
, *tag
;
2415 case DEBUG_KIND_STRUCT
:
2418 case DEBUG_KIND_UNION
:
2421 case DEBUG_KIND_ENUM
:
2424 case DEBUG_KIND_CLASS
:
2427 case DEBUG_KIND_UNION_CLASS
:
2435 if (! push_type (info
, t
))
2441 sprintf (idbuf
, "%%anon%u", id
);
2445 if (! append_type (info
, tag
))
2451 /* Output a typedef. */
2454 tg_typdef (void *p
, const char *name
)
2456 struct pr_handle
*info
= (struct pr_handle
*) p
;
2459 s
= pop_type (info
);
2463 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:t\ttype:%s\n", name
,
2471 /* Output a tag. The tag should already be in the string on the
2472 stack, so all we have to do here is print it out. */
2475 tg_tag (void *p ATTRIBUTE_UNUSED
, const char *name ATTRIBUTE_UNUSED
)
2477 struct pr_handle
*info
= (struct pr_handle
*) p
;
2480 t
= pop_type (info
);
2488 /* Output an integer constant. */
2491 tg_int_constant (void *p
, const char *name
, bfd_vma val
)
2493 struct pr_handle
*info
= (struct pr_handle
*) p
;
2497 print_vma (val
, ab
, FALSE
, FALSE
);
2498 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:v\ttype:const int\tvalue:%s\n",
2499 name
, info
->filename
, ab
);
2503 /* Output a floating point constant. */
2506 tg_float_constant (void *p
, const char *name
, double val
)
2508 struct pr_handle
*info
= (struct pr_handle
*) p
;
2511 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:v\ttype:const double\tvalue:%g\n",
2512 name
, info
->filename
, val
);
2516 /* Output a typed constant. */
2519 tg_typed_constant (void *p
, const char *name
, bfd_vma val
)
2521 struct pr_handle
*info
= (struct pr_handle
*) p
;
2525 t
= pop_type (info
);
2530 print_vma (val
, ab
, FALSE
, FALSE
);
2531 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:v\ttype:const %s\tvalue:%s\n",
2532 name
, info
->filename
, t
, ab
);
2539 /* Output a variable. */
2542 tg_variable (void *p
, const char *name
, enum debug_var_kind kind
,
2543 bfd_vma val ATTRIBUTE_UNUSED
)
2545 struct pr_handle
*info
= (struct pr_handle
*) p
;
2546 char *t
, *dname
, *from_class
;
2548 t
= pop_type (info
);
2553 if (info
->demangler
)
2554 dname
= info
->demangler (info
->abfd
, name
, DMGL_ANSI
| DMGL_PARAMS
);
2560 sep
= strstr (dname
, "::");
2568 /* Obscure types as vts and type_info nodes. */
2572 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:v\ttype:%s", name
, info
->filename
, t
);
2577 case DEBUG_LOCAL_STATIC
:
2578 fprintf (info
->f
, "\tfile:");
2580 case DEBUG_REGISTER
:
2581 fprintf (info
->f
, "\tregister:");
2588 fprintf (info
->f
, "\tclass:%s", from_class
);
2593 fprintf (info
->f
, "\n");
2600 /* Start outputting a function. */
2603 tg_start_function (void *p
, const char *name
, bfd_boolean global
)
2605 struct pr_handle
*info
= (struct pr_handle
*) p
;
2609 info
->stack
->flavor
= "static";
2611 info
->stack
->flavor
= NULL
;
2614 if (info
->demangler
)
2615 dname
= info
->demangler (info
->abfd
, name
, DMGL_ANSI
| DMGL_PARAMS
);
2617 if (! substitute_type (info
, dname
? dname
: name
))
2620 info
->stack
->method
= NULL
;
2624 sep
= strstr (dname
, "::");
2627 info
->stack
->method
= dname
;
2633 info
->stack
->method
= "";
2636 sep
= strchr (name
, '(');
2639 /* Obscure functions as type_info function. */
2642 info
->stack
->parents
= strdup (name
);
2644 if (! info
->stack
->method
&& ! append_type (info
, "("))
2647 info
->parameter
= 1;
2652 /* Output a function parameter. */
2655 tg_function_parameter (void *p
, const char *name
, enum debug_parm_kind kind
,
2656 bfd_vma val ATTRIBUTE_UNUSED
)
2658 struct pr_handle
*info
= (struct pr_handle
*) p
;
2661 if (kind
== DEBUG_PARM_REFERENCE
2662 || kind
== DEBUG_PARM_REF_REG
)
2664 if (! pr_reference_type (p
))
2668 if (! substitute_type (info
, name
))
2671 t
= pop_type (info
);
2675 if (! info
->stack
->method
)
2677 if (info
->parameter
!= 1 && ! append_type (info
, ", "))
2680 if (kind
== DEBUG_PARM_REG
|| kind
== DEBUG_PARM_REF_REG
)
2681 if (! append_type (info
, "register "))
2684 if (! append_type (info
, t
))
2695 /* Start writing out a block. */
2698 tg_start_block (void *p
, bfd_vma addr
)
2700 struct pr_handle
*info
= (struct pr_handle
*) p
;
2701 char ab
[20], kind
, *partof
;
2705 if (info
->parameter
> 0)
2707 info
->parameter
= 0;
2710 fprintf (info
->f
, "%s\t%s\t", info
->stack
->parents
, info
->filename
);
2711 free (info
->stack
->parents
);
2713 print_vma (addr
, ab
, TRUE
, TRUE
);
2714 translate_addresses (info
->abfd
, ab
, info
->f
, info
->syms
);
2715 local
= info
->stack
->flavor
!= NULL
;
2716 if (info
->stack
->method
&& *info
->stack
->method
)
2719 partof
= (char *) info
->stack
->method
;
2725 if (! info
->stack
->method
&& ! append_type (info
, ")"))
2728 t
= pop_type (info
);
2731 fprintf (info
->f
, ";\"\tkind:%c\ttype:%s", kind
, t
);
2733 fputs ("\tfile:", info
->f
);
2736 fprintf (info
->f
, "\tclass:%s", partof
);
2739 fputc ('\n', info
->f
);
2745 /* Write out line number information. */
2748 tg_lineno (void *p ATTRIBUTE_UNUSED
, const char *filename ATTRIBUTE_UNUSED
,
2749 unsigned long lineno ATTRIBUTE_UNUSED
,
2750 bfd_vma addr ATTRIBUTE_UNUSED
)
2755 /* Finish writing out a block. */
2758 tg_end_block (void *p ATTRIBUTE_UNUSED
, bfd_vma addr ATTRIBUTE_UNUSED
)
2763 /* Convert the visibility value into a human readable name. */
2766 visibility_name (enum debug_visibility visibility
)
2772 case DEBUG_VISIBILITY_PUBLIC
:
2775 case DEBUG_VISIBILITY_PRIVATE
:
2778 case DEBUG_VISIBILITY_PROTECTED
:
2781 case DEBUG_VISIBILITY_IGNORE
: