1 /* prdbg.c -- Print out generic debugging information.
2 Copyright (C) 1995-2023 Free Software Foundation, Inc.
3 Written by Ian Lance Taylor <ian@cygnus.com>.
4 Tags style generation written by Salvador E. Tropea <set@computer.org>.
6 This file is part of GNU Binutils.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
23 /* This file prints out the generic debugging information, by
24 supplying a set of routines to debug_write. */
29 #include "libiberty.h"
34 /* This is the structure we use as a handle for these routines. */
38 /* File to print information to. */
40 /* Current indentation level. */
43 struct pr_stack
*stack
;
44 /* Parameter number we are about to output. */
46 /* The following are used only by the tags code (tg_). */
47 /* Name of the file we are using. */
51 /* The symbols table for this BFD. */
53 /* Pointer to a function to demangle symbols. */
54 char *(*demangler
) (bfd
*, const char *, int);
61 /* Next element on the stack. */
62 struct pr_stack
*next
;
65 /* Current visibility of fields if this is a class. */
66 enum debug_visibility visibility
;
67 /* Name of the current method we are handling. */
69 /* The following are used only by the tags code (tg_). */
70 /* Type for the container (struct, union, class, union class). */
72 /* A comma separated list of parent classes. */
76 static bool pr_start_compilation_unit (void *, const char *);
77 static bool pr_start_source (void *, const char *);
78 static bool pr_empty_type (void *);
79 static bool pr_void_type (void *);
80 static bool pr_int_type (void *, unsigned int, bool);
81 static bool pr_float_type (void *, unsigned int);
82 static bool pr_complex_type (void *, unsigned int);
83 static bool pr_bool_type (void *, unsigned int);
84 static bool pr_enum_type
85 (void *, const char *, const char **, bfd_signed_vma
*);
86 static bool pr_pointer_type (void *);
87 static bool pr_function_type (void *, int, bool);
88 static bool pr_reference_type (void *);
89 static bool pr_range_type (void *, bfd_signed_vma
, bfd_signed_vma
);
90 static bool pr_array_type (void *, bfd_signed_vma
, bfd_signed_vma
, bool);
91 static bool pr_set_type (void *, bool);
92 static bool pr_offset_type (void *);
93 static bool pr_method_type (void *, bool, int, bool);
94 static bool pr_const_type (void *);
95 static bool pr_volatile_type (void *);
96 static bool pr_start_struct_type
97 (void *, const char *, unsigned int, bool, unsigned int);
98 static bool pr_struct_field
99 (void *, const char *, bfd_vma
, bfd_vma
, enum debug_visibility
);
100 static bool pr_end_struct_type (void *);
101 static bool pr_start_class_type
102 (void *, const char *, unsigned int, bool, unsigned int, bool, bool);
103 static bool pr_class_static_member
104 (void *, const char *, const char *, enum debug_visibility
);
105 static bool pr_class_baseclass
106 (void *, bfd_vma
, bool, enum debug_visibility
);
107 static bool pr_class_start_method (void *, const char *);
108 static bool pr_class_method_variant
109 (void *, const char *, enum debug_visibility
, bool, bool, bfd_vma
, bool);
110 static bool pr_class_static_method_variant
111 (void *, const char *, enum debug_visibility
, bool, bool);
112 static bool pr_class_end_method (void *);
113 static bool pr_end_class_type (void *);
114 static bool pr_typedef_type (void *, const char *);
115 static bool pr_tag_type
116 (void *, const char *, unsigned int, enum debug_type_kind
);
117 static bool pr_typdef (void *, const char *);
118 static bool pr_tag (void *, const char *);
119 static bool pr_int_constant (void *, const char *, bfd_vma
);
120 static bool pr_float_constant (void *, const char *, double);
121 static bool pr_typed_constant (void *, const char *, bfd_vma
);
122 static bool pr_variable (void *, const char *, enum debug_var_kind
, bfd_vma
);
123 static bool pr_start_function (void *, const char *, bool);
124 static bool pr_function_parameter
125 (void *, const char *, enum debug_parm_kind
, bfd_vma
);
126 static bool pr_start_block (void *, bfd_vma
);
127 static bool pr_end_block (void *, bfd_vma
);
128 static bool pr_end_function (void *);
129 static bool pr_lineno (void *, const char *, unsigned long, bfd_vma
);
131 static const char *visibility_name (enum debug_visibility
);
133 /* Tags style replacements. */
134 static bool tg_start_compilation_unit (void *, const char *);
135 static bool tg_start_source (void *, const char *);
136 static bool tg_enum_type
137 (void *, const char *, const char **, bfd_signed_vma
*);
138 static bool tg_start_struct_type
139 (void *, const char *, unsigned int, bool, unsigned int);
140 static bool pr_struct_field
141 (void *, const char *, bfd_vma
, bfd_vma
, enum debug_visibility
);
142 static bool tg_struct_field
143 (void *, const char *, bfd_vma
, bfd_vma
, enum debug_visibility
);
144 static bool tg_struct_field
145 (void *, const char *, bfd_vma
, bfd_vma
, enum debug_visibility
);
146 static bool tg_end_struct_type (void *);
147 static bool tg_start_class_type
148 (void *, const char *, unsigned int, bool, unsigned int, bool, bool);
149 static bool tg_class_static_member
150 (void *, const char *, const char *, enum debug_visibility
);
151 static bool tg_class_baseclass (void *, bfd_vma
, bool, enum debug_visibility
);
152 static bool tg_class_method_variant
153 (void *, const char *, enum debug_visibility
, bool, bool, bfd_vma
, bool);
154 static bool tg_class_static_method_variant
155 (void *, const char *, enum debug_visibility
, bool, bool);
156 static bool tg_end_class_type (void *);
157 static bool tg_tag_type
158 (void *, const char *, unsigned int, enum debug_type_kind
);
159 static bool tg_typdef (void *, const char *);
160 static bool tg_tag (void *, const char *);
161 static bool tg_int_constant (void *, const char *, bfd_vma
);
162 static bool tg_float_constant (void *, const char *, double);
163 static bool tg_typed_constant (void *, const char *, bfd_vma
);
164 static bool tg_variable (void *, const char *, enum debug_var_kind
, bfd_vma
);
165 static bool tg_start_function (void *, const char *, bool);
166 static bool tg_function_parameter
167 (void *, const char *, enum debug_parm_kind
, bfd_vma
);
168 static bool tg_start_block (void *, bfd_vma
);
169 static bool tg_end_block (void *, bfd_vma
);
170 static bool tg_lineno (void *, const char *, unsigned long, bfd_vma
);
172 static const struct debug_write_fns pr_fns
=
174 pr_start_compilation_unit
,
193 pr_start_struct_type
,
197 pr_class_static_member
,
199 pr_class_start_method
,
200 pr_class_method_variant
,
201 pr_class_static_method_variant
,
213 pr_function_parameter
,
220 static const struct debug_write_fns tg_fns
=
222 tg_start_compilation_unit
,
224 pr_empty_type
, /* Same, push_type. */
225 pr_void_type
, /* Same, push_type. */
226 pr_int_type
, /* Same, push_type. */
227 pr_float_type
, /* Same, push_type. */
228 pr_complex_type
, /* Same, push_type. */
229 pr_bool_type
, /* Same, push_type. */
231 pr_pointer_type
, /* Same, changes to pointer. */
232 pr_function_type
, /* Same, push_type. */
233 pr_reference_type
, /* Same, changes to reference. */
234 pr_range_type
, /* FIXME: What's that?. */
235 pr_array_type
, /* Same, push_type. */
236 pr_set_type
, /* FIXME: What's that?. */
237 pr_offset_type
, /* FIXME: What's that?. */
238 pr_method_type
, /* Same. */
239 pr_const_type
, /* Same, changes to const. */
240 pr_volatile_type
, /* Same, changes to volatile. */
241 tg_start_struct_type
,
245 tg_class_static_member
,
247 pr_class_start_method
, /* Same, remembers that's a method. */
248 tg_class_method_variant
,
249 tg_class_static_method_variant
,
250 pr_class_end_method
, /* Same, forgets that's a method. */
252 pr_typedef_type
, /* Same, just push type. */
256 tg_int_constant
, /* Untested. */
257 tg_float_constant
, /* Untested. */
258 tg_typed_constant
, /* Untested. */
261 tg_function_parameter
,
264 pr_end_function
, /* Same, does nothing. */
268 static int demangle_flags
= DMGL_ANSI
| DMGL_PARAMS
;
270 /* Print out the generic debugging information recorded in dhandle. */
273 print_debugging_info (FILE *f
, void *dhandle
, bfd
*abfd
, asymbol
**syms
,
274 char * (*demangler
) (struct bfd
*, const char *, int),
277 struct pr_handle info
;
283 info
.filename
= NULL
;
286 info
.demangler
= demangler
;
290 fputs ("!_TAG_FILE_FORMAT\t2\t/extended format/\n", f
);
291 fputs ("!_TAG_FILE_SORTED\t0\t/0=unsorted, 1=sorted/\n", f
);
292 fputs ("!_TAG_PROGRAM_AUTHOR\tIan Lance Taylor, Salvador E. Tropea and others\t//\n", f
);
293 fputs ("!_TAG_PROGRAM_NAME\tobjdump\t/From GNU binutils/\n", f
);
296 bool ret
= debug_write (dhandle
, as_tags
? &tg_fns
: &pr_fns
, &info
);
297 while (info
.stack
!= NULL
)
299 struct pr_stack
*s
= info
.stack
;
300 info
.stack
= s
->next
;
306 free (info
.filename
);
310 /* Indent to the current indentation level. */
313 indent (struct pr_handle
*info
)
317 for (i
= 0; i
< info
->indent
; i
++)
321 /* Push a type on the type stack. */
324 push_type (struct pr_handle
*info
, const char *type
)
331 n
= xmalloc (sizeof *n
);
332 memset (n
, 0, sizeof *n
);
334 n
->type
= xstrdup (type
);
335 n
->visibility
= DEBUG_VISIBILITY_IGNORE
;
337 n
->next
= info
->stack
;
343 /* Prepend a string onto the type on the top of the type stack. */
346 prepend_type (struct pr_handle
*info
, const char *s
)
350 assert (info
->stack
!= NULL
);
352 n
= xmalloc (strlen (s
) + strlen (info
->stack
->type
) + 1);
353 sprintf (n
, "%s%s", s
, info
->stack
->type
);
354 free (info
->stack
->type
);
355 info
->stack
->type
= n
;
360 /* Append a string to the type on the top of the type stack. */
363 append_type (struct pr_handle
*info
, const char *s
)
370 assert (info
->stack
!= NULL
);
372 len
= strlen (info
->stack
->type
);
373 info
->stack
->type
= xrealloc (info
->stack
->type
, len
+ strlen (s
) + 1);
374 strcpy (info
->stack
->type
+ len
, s
);
379 /* Append a string to the parents on the top of the type stack. */
382 append_parent (struct pr_handle
*info
, const char *s
)
389 assert (info
->stack
!= NULL
);
391 len
= info
->stack
->parents
? strlen (info
->stack
->parents
) : 0;
392 info
->stack
->parents
= xrealloc (info
->stack
->parents
, len
+ strlen (s
) + 1);
393 strcpy (info
->stack
->parents
+ len
, s
);
398 /* We use an underscore to indicate where the name should go in a type
399 string. This function substitutes a string for the underscore. If
400 there is no underscore, the name follows the type. */
403 substitute_type (struct pr_handle
*info
, const char *s
)
407 assert (info
->stack
!= NULL
);
409 u
= strchr (info
->stack
->type
, '|');
414 n
= xmalloc (strlen (info
->stack
->type
) + strlen (s
));
416 memcpy (n
, info
->stack
->type
, u
- info
->stack
->type
);
417 strcpy (n
+ (u
- info
->stack
->type
), s
);
420 free (info
->stack
->type
);
421 info
->stack
->type
= n
;
426 if (strchr (s
, '|') != NULL
427 && (strchr (info
->stack
->type
, '{') != NULL
428 || strchr (info
->stack
->type
, '(') != NULL
))
430 if (! prepend_type (info
, "(")
431 || ! append_type (info
, ")"))
438 return (append_type (info
, " ")
439 && append_type (info
, s
));
442 /* Indent the type at the top of the stack by appending spaces. */
445 indent_type (struct pr_handle
*info
)
449 for (i
= 0; i
< info
->indent
; i
++)
451 if (! append_type (info
, " "))
458 /* Pop a type from the type stack. */
461 pop_type (struct pr_handle
*info
)
466 assert (info
->stack
!= NULL
);
469 info
->stack
= o
->next
;
476 /* Print a VMA value into a string. */
479 print_vma (bfd_vma vma
, char *buf
, bool unsignedp
, bool hexp
)
482 sprintf (buf
, "%#" PRIx64
, (uint64_t) vma
);
484 sprintf (buf
, "%" PRIu64
, (uint64_t) vma
);
486 sprintf (buf
, "%" PRId64
, (int64_t) vma
);
489 /* Start a new compilation unit. */
492 pr_start_compilation_unit (void *p
, const char *filename
)
494 struct pr_handle
*info
= (struct pr_handle
*) p
;
496 assert (info
->indent
== 0);
498 fprintf (info
->f
, "%s:\n", filename
);
503 /* Start a source file within a compilation unit. */
506 pr_start_source (void *p
, const char *filename
)
508 struct pr_handle
*info
= (struct pr_handle
*) p
;
510 assert (info
->indent
== 0);
512 fprintf (info
->f
, " %s:\n", filename
);
517 /* Push an empty type onto the type stack. */
520 pr_empty_type (void *p
)
522 struct pr_handle
*info
= (struct pr_handle
*) p
;
524 return push_type (info
, "<undefined>");
527 /* Push a void type onto the type stack. */
530 pr_void_type (void *p
)
532 struct pr_handle
*info
= (struct pr_handle
*) p
;
534 return push_type (info
, "void");
537 /* Push an integer type onto the type stack. */
540 pr_int_type (void *p
, unsigned int size
, bool unsignedp
)
542 struct pr_handle
*info
= (struct pr_handle
*) p
;
545 sprintf (ab
, "%sint%d", unsignedp
? "u" : "", size
* 8);
546 return push_type (info
, ab
);
549 /* Push a floating type onto the type stack. */
552 pr_float_type (void *p
, unsigned int size
)
554 struct pr_handle
*info
= (struct pr_handle
*) p
;
558 return push_type (info
, "float");
560 return push_type (info
, "double");
562 sprintf (ab
, "float%d", size
* 8);
563 return push_type (info
, ab
);
566 /* Push a complex type onto the type stack. */
569 pr_complex_type (void *p
, unsigned int size
)
571 struct pr_handle
*info
= (struct pr_handle
*) p
;
573 if (! pr_float_type (p
, size
))
576 return prepend_type (info
, "complex ");
579 /* Push a bool type onto the type stack. */
582 pr_bool_type (void *p
, unsigned int size
)
584 struct pr_handle
*info
= (struct pr_handle
*) p
;
587 sprintf (ab
, "bool%d", size
* 8);
589 return push_type (info
, ab
);
592 /* Push an enum type onto the type stack. */
595 pr_enum_type (void *p
, const char *tag
, const char **names
,
596 bfd_signed_vma
*values
)
598 struct pr_handle
*info
= (struct pr_handle
*) p
;
602 if (! push_type (info
, "enum "))
606 if (! append_type (info
, tag
)
607 || ! append_type (info
, " "))
610 if (! append_type (info
, "{ "))
615 if (! append_type (info
, "/* undefined */"))
621 for (i
= 0; names
[i
] != NULL
; i
++)
625 if (! append_type (info
, ", "))
629 if (! append_type (info
, names
[i
]))
632 if (values
[i
] != val
)
636 print_vma (values
[i
], ab
, false, false);
637 if (! append_type (info
, " = ")
638 || ! append_type (info
, ab
))
647 return append_type (info
, " }");
650 /* Turn the top type on the stack into a pointer. */
653 pr_pointer_type (void *p
)
655 struct pr_handle
*info
= (struct pr_handle
*) p
;
658 assert (info
->stack
!= NULL
);
660 s
= strchr (info
->stack
->type
, '|');
661 if (s
!= NULL
&& s
[1] == '[')
662 return substitute_type (info
, "(*|)");
663 return substitute_type (info
, "*|");
666 /* Turn the top type on the stack into a function returning that type. */
669 pr_function_type (void *p
, int argcount
, bool varargs
)
671 struct pr_handle
*info
= (struct pr_handle
*) p
;
676 assert (info
->stack
!= NULL
);
689 arg_types
= xmalloc (argcount
* sizeof (*arg_types
));
690 for (i
= argcount
- 1; i
>= 0; i
--)
692 if (!substitute_type (info
, "")
693 || (arg_types
[i
] = pop_type (info
)) == NULL
)
695 for (int j
= i
+ 1; j
< argcount
; j
++)
700 len
+= strlen (arg_types
[i
]) + 2;
706 /* Now the return type is on the top of the stack. */
712 strcat (s
, "/* unknown */");
717 for (i
= 0; i
< argcount
; i
++)
721 strcat (s
, arg_types
[i
]);
735 bool ret
= substitute_type (info
, s
);
740 /* Turn the top type on the stack into a reference to that type. */
743 pr_reference_type (void *p
)
745 struct pr_handle
*info
= (struct pr_handle
*) p
;
747 assert (info
->stack
!= NULL
);
749 return substitute_type (info
, "&|");
752 /* Make a range type. */
755 pr_range_type (void *p
, bfd_signed_vma lower
, bfd_signed_vma upper
)
757 struct pr_handle
*info
= (struct pr_handle
*) p
;
758 char abl
[22], abu
[22];
760 assert (info
->stack
!= NULL
);
762 if (! substitute_type (info
, ""))
765 print_vma (lower
, abl
, false, false);
766 print_vma (upper
, abu
, false, false);
768 return (prepend_type (info
, "range (")
769 && append_type (info
, "):")
770 && append_type (info
, abl
)
771 && append_type (info
, ":")
772 && append_type (info
, abu
));
775 /* Make an array type. */
778 pr_array_type (void *p
, bfd_signed_vma lower
, bfd_signed_vma upper
,
781 struct pr_handle
*info
= (struct pr_handle
*) p
;
783 char abl
[22], abu
[22], ab
[50];
785 range_type
= pop_type (info
);
786 if (range_type
== NULL
)
795 print_vma (upper
+ 1, abu
, false, false);
796 sprintf (ab
, "|[%s]", abu
);
801 print_vma (lower
, abl
, false, false);
802 print_vma (upper
, abu
, false, false);
803 sprintf (ab
, "|[%s:%s]", abl
, abu
);
806 if (! substitute_type (info
, ab
))
809 if (strcmp (range_type
, "int") != 0)
811 if (! append_type (info
, ":")
812 || ! append_type (info
, range_type
))
818 if (! append_type (info
, " /* string */"))
830 /* Make a set type. */
833 pr_set_type (void *p
, bool bitstringp
)
835 struct pr_handle
*info
= (struct pr_handle
*) p
;
837 if (! substitute_type (info
, ""))
840 if (! prepend_type (info
, "set { ")
841 || ! append_type (info
, " }"))
846 if (! append_type (info
, "/* bitstring */"))
853 /* Make an offset type. */
856 pr_offset_type (void *p
)
858 struct pr_handle
*info
= (struct pr_handle
*) p
;
861 if (! substitute_type (info
, ""))
868 bool ret
= (substitute_type (info
, "")
869 && prepend_type (info
, " ")
870 && prepend_type (info
, t
)
871 && append_type (info
, "::|"));
876 /* Make a method type. */
879 pr_method_type (void *p
, bool domain
, int argcount
, bool varargs
)
881 struct pr_handle
*info
= (struct pr_handle
*) p
;
883 char *domain_type
= NULL
, *free_domain
= NULL
;
891 if (! substitute_type (info
, ""))
893 domain_type
= pop_type (info
);
894 if (domain_type
== NULL
)
896 free_domain
= domain_type
;
897 if (startswith (domain_type
, "class ")
898 && strchr (domain_type
+ sizeof "class " - 1, ' ') == NULL
)
899 domain_type
+= sizeof "class " - 1;
900 else if (startswith (domain_type
, "union class ")
901 && (strchr (domain_type
+ sizeof "union class " - 1, ' ')
903 domain_type
+= sizeof "union class " - 1;
904 len
+= strlen (domain_type
);
916 arg_types
= xmalloc (argcount
* sizeof (*arg_types
));
917 for (i
= argcount
- 1; i
>= 0; i
--)
919 if (!substitute_type (info
, "")
920 || (arg_types
[i
] = pop_type (info
)) == NULL
)
922 for (int j
= i
+ 1; j
< argcount
; ++j
)
927 len
+= strlen (arg_types
[i
]) + 2;
933 /* Now the return type is on the top of the stack. */
939 strcpy (s
, domain_type
);
945 strcat (s
, "/* unknown */");
950 for (i
= 0; i
< argcount
; i
++)
954 strcat (s
, arg_types
[i
]);
968 bool ret
= substitute_type (info
, s
);
973 /* Make a const qualified type. */
976 pr_const_type (void *p
)
978 struct pr_handle
*info
= (struct pr_handle
*) p
;
980 return substitute_type (info
, "const |");
983 /* Make a volatile qualified type. */
986 pr_volatile_type (void *p
)
988 struct pr_handle
*info
= (struct pr_handle
*) p
;
990 return substitute_type (info
, "volatile |");
993 /* Start accumulating a struct type. */
996 pr_start_struct_type (void *p
, const char *tag
, unsigned int id
,
997 bool structp
, unsigned int size
)
999 struct pr_handle
*info
= (struct pr_handle
*) p
;
1003 if (! push_type (info
, structp
? "struct " : "union "))
1007 if (! append_type (info
, tag
))
1014 sprintf (idbuf
, "%%anon%u", id
);
1015 if (! append_type (info
, idbuf
))
1019 if (! append_type (info
, " {"))
1021 if (size
!= 0 || tag
!= NULL
)
1025 if (! append_type (info
, " /*"))
1030 sprintf (ab
, " size %u", size
);
1031 if (! append_type (info
, ab
))
1036 sprintf (ab
, " id %u", id
);
1037 if (! append_type (info
, ab
))
1040 if (! append_type (info
, " */"))
1043 if (! append_type (info
, "\n"))
1046 info
->stack
->visibility
= DEBUG_VISIBILITY_PUBLIC
;
1048 return indent_type (info
);
1051 /* Output the visibility of a field in a struct. */
1054 pr_fix_visibility (struct pr_handle
*info
, enum debug_visibility visibility
)
1056 const char *s
= NULL
;
1060 assert (info
->stack
!= NULL
);
1062 if (info
->stack
->visibility
== visibility
)
1067 case DEBUG_VISIBILITY_PUBLIC
:
1070 case DEBUG_VISIBILITY_PRIVATE
:
1073 case DEBUG_VISIBILITY_PROTECTED
:
1076 case DEBUG_VISIBILITY_IGNORE
:
1084 /* Trim off a trailing space in the struct string, to make the
1085 output look a bit better, then stick on the visibility string. */
1087 t
= info
->stack
->type
;
1089 assert (t
[len
- 1] == ' ');
1092 if (! append_type (info
, s
)
1093 || ! append_type (info
, ":\n")
1094 || ! indent_type (info
))
1097 info
->stack
->visibility
= visibility
;
1102 /* Add a field to a struct type. */
1105 pr_struct_field (void *p
, const char *name
, bfd_vma bitpos
, bfd_vma bitsize
,
1106 enum debug_visibility visibility
)
1108 struct pr_handle
*info
= (struct pr_handle
*) p
;
1112 if (! substitute_type (info
, name
))
1115 if (! append_type (info
, "; /* "))
1120 print_vma (bitsize
, ab
, true, false);
1121 if (! append_type (info
, "bitsize ")
1122 || ! append_type (info
, ab
)
1123 || ! append_type (info
, ", "))
1127 print_vma (bitpos
, ab
, true, false);
1128 if (! append_type (info
, "bitpos ")
1129 || ! append_type (info
, ab
)
1130 || ! append_type (info
, " */\n")
1131 || ! indent_type (info
))
1134 t
= pop_type (info
);
1138 bool ret
= pr_fix_visibility (info
, visibility
) && append_type (info
, t
);
1143 /* Finish a struct type. */
1146 pr_end_struct_type (void *p
)
1148 struct pr_handle
*info
= (struct pr_handle
*) p
;
1151 assert (info
->stack
!= NULL
);
1152 assert (info
->indent
>= 2);
1156 /* Change the trailing indentation to have a close brace. */
1157 s
= info
->stack
->type
+ strlen (info
->stack
->type
) - 2;
1158 assert (s
[0] == ' ' && s
[1] == ' ' && s
[2] == '\0');
1166 /* Start a class type. */
1169 pr_start_class_type (void *p
, const char *tag
, unsigned int id
,
1170 bool structp
, unsigned int size
,
1171 bool vptr
, bool ownvptr
)
1173 struct pr_handle
*info
= (struct pr_handle
*) p
;
1179 if (vptr
&& ! ownvptr
)
1181 tv
= pop_type (info
);
1186 if (! push_type (info
, structp
? "class " : "union class "))
1190 if (! append_type (info
, tag
))
1197 sprintf (idbuf
, "%%anon%u", id
);
1198 if (! append_type (info
, idbuf
))
1202 if (! append_type (info
, " {"))
1204 if (size
!= 0 || vptr
|| ownvptr
|| tag
!= NULL
)
1206 if (! append_type (info
, " /*"))
1213 sprintf (ab
, "%u", size
);
1214 if (! append_type (info
, " size ")
1215 || ! append_type (info
, ab
))
1221 if (! append_type (info
, " vtable "))
1225 if (! append_type (info
, "self "))
1230 if (! append_type (info
, tv
)
1231 || ! append_type (info
, " "))
1240 sprintf (ab
, " id %u", id
);
1241 if (! append_type (info
, ab
))
1245 if (! append_type (info
, " */"))
1249 info
->stack
->visibility
= DEBUG_VISIBILITY_PRIVATE
;
1251 ret
= append_type (info
, "\n") && indent_type (info
);
1257 /* Add a static member to a class. */
1260 pr_class_static_member (void *p
, const char *name
, const char *physname
,
1261 enum debug_visibility visibility
)
1263 struct pr_handle
*info
= (struct pr_handle
*) p
;
1266 if (! substitute_type (info
, name
))
1269 if (! prepend_type (info
, "static ")
1270 || ! append_type (info
, "; /* ")
1271 || ! append_type (info
, physname
)
1272 || ! append_type (info
, " */\n")
1273 || ! indent_type (info
))
1276 t
= pop_type (info
);
1280 bool ret
= pr_fix_visibility (info
, visibility
) && append_type (info
, t
);
1285 /* Add a base class to a class. */
1288 pr_class_baseclass (void *p
, bfd_vma bitpos
, bool is_virtual
,
1289 enum debug_visibility visibility
)
1291 struct pr_handle
*info
= (struct pr_handle
*) p
;
1297 assert (info
->stack
!= NULL
&& info
->stack
->next
!= NULL
);
1299 if (! substitute_type (info
, ""))
1302 t
= pop_type (info
);
1306 /* Push it back on to take advantage of the prepend_type and
1307 append_type routines. */
1308 if (! push_type (info
, t
+ (startswith (t
, "class ")
1309 ? sizeof "class " - 1 : 0)))
1318 if (! prepend_type (info
, "virtual "))
1324 case DEBUG_VISIBILITY_PUBLIC
:
1327 case DEBUG_VISIBILITY_PROTECTED
:
1328 prefix
= "protected ";
1330 case DEBUG_VISIBILITY_PRIVATE
:
1331 prefix
= "private ";
1334 prefix
= "/* unknown visibility */ ";
1338 if (! prepend_type (info
, prefix
))
1343 print_vma (bitpos
, ab
, true, false);
1344 if (! append_type (info
, " /* bitpos ")
1345 || ! append_type (info
, ab
)
1346 || ! append_type (info
, " */"))
1350 /* Now the top of the stack is something like "public A / * bitpos
1351 10 * /". The next element on the stack is something like "class
1352 xx { / * size 8 * /\n...". We want to substitute the top of the
1353 stack in before the {. */
1354 s
= strchr (info
->stack
->next
->type
, '{');
1358 /* If there is already a ':', then we already have a baseclass, and
1359 we must append this one after a comma. */
1360 for (l
= info
->stack
->next
->type
; l
!= s
; l
++)
1363 if (! prepend_type (info
, l
== s
? " : " : ", "))
1366 t
= pop_type (info
);
1370 n
= xmalloc (strlen (info
->stack
->type
) + strlen (t
) + 1);
1371 memcpy (n
, info
->stack
->type
, s
- info
->stack
->type
);
1372 strcpy (n
+ (s
- info
->stack
->type
), t
);
1375 free (info
->stack
->type
);
1376 info
->stack
->type
= n
;
1383 /* Start adding a method to a class. */
1386 pr_class_start_method (void *p
, const char *name
)
1388 struct pr_handle
*info
= (struct pr_handle
*) p
;
1390 assert (info
->stack
!= NULL
);
1391 free (info
->stack
->method
);
1392 info
->stack
->method
= xstrdup (name
);
1396 /* Add a variant to a method. */
1399 pr_class_method_variant (void *p
, const char *physname
,
1400 enum debug_visibility visibility
,
1401 bool constp
, bool volatilep
,
1402 bfd_vma voffset
, bool context
)
1404 struct pr_handle
*info
= (struct pr_handle
*) p
;
1409 assert (info
->stack
!= NULL
);
1410 assert (info
->stack
->next
!= NULL
);
1412 /* Put the const and volatile qualifiers on the type. */
1415 if (! append_type (info
, " volatile"))
1420 if (! append_type (info
, " const"))
1424 /* Stick the name of the method into its type. */
1425 if (! substitute_type (info
,
1427 ? info
->stack
->next
->next
->method
1428 : info
->stack
->next
->method
)))
1432 method_type
= pop_type (info
);
1433 if (method_type
== NULL
)
1436 /* Pull off the context type if there is one. */
1438 context_type
= NULL
;
1441 context_type
= pop_type (info
);
1442 if (context_type
== NULL
)
1446 /* Now the top of the stack is the class. */
1448 if (! pr_fix_visibility (info
, visibility
))
1451 if (! append_type (info
, method_type
)
1452 || ! append_type (info
, " /* ")
1453 || ! append_type (info
, physname
)
1454 || ! append_type (info
, " "))
1456 if (context
|| voffset
!= 0)
1462 if (! append_type (info
, "context ")
1463 || ! append_type (info
, context_type
)
1464 || ! append_type (info
, " "))
1467 print_vma (voffset
, ab
, true, false);
1468 if (! append_type (info
, "voffset ")
1469 || ! append_type (info
, ab
))
1473 ret
= append_type (info
, " */;\n") && indent_type (info
);
1476 free (context_type
);
1480 /* Add a static variant to a method. */
1483 pr_class_static_method_variant (void *p
, const char *physname
,
1484 enum debug_visibility visibility
,
1485 bool constp
, bool volatilep
)
1487 struct pr_handle
*info
= (struct pr_handle
*) p
;
1490 assert (info
->stack
!= NULL
);
1491 assert (info
->stack
->next
!= NULL
);
1492 assert (info
->stack
->next
->method
!= NULL
);
1494 /* Put the const and volatile qualifiers on the type. */
1497 if (! append_type (info
, " volatile"))
1502 if (! append_type (info
, " const"))
1506 /* Mark it as static. */
1507 if (! prepend_type (info
, "static "))
1510 /* Stick the name of the method into its type. */
1511 if (! substitute_type (info
, info
->stack
->next
->method
))
1515 method_type
= pop_type (info
);
1516 if (method_type
== NULL
)
1519 /* Now the top of the stack is the class. */
1521 bool ret
= (pr_fix_visibility (info
, visibility
)
1522 && append_type (info
, method_type
)
1523 && append_type (info
, " /* ")
1524 && append_type (info
, physname
)
1525 && append_type (info
, " */;\n")
1526 && indent_type (info
));
1531 /* Finish up a method. */
1534 pr_class_end_method (void *p
)
1536 struct pr_handle
*info
= (struct pr_handle
*) p
;
1538 free (info
->stack
->method
);
1539 info
->stack
->method
= NULL
;
1543 /* Finish up a class. */
1546 pr_end_class_type (void *p
)
1548 return pr_end_struct_type (p
);
1551 /* Push a type on the stack using a typedef name. */
1554 pr_typedef_type (void *p
, const char *name
)
1556 struct pr_handle
*info
= (struct pr_handle
*) p
;
1558 return push_type (info
, name
);
1561 /* Push a type on the stack using a tag name. */
1564 pr_tag_type (void *p
, const char *name
, unsigned int id
,
1565 enum debug_type_kind kind
)
1567 struct pr_handle
*info
= (struct pr_handle
*) p
;
1568 const char *t
, *tag
;
1573 case DEBUG_KIND_STRUCT
:
1576 case DEBUG_KIND_UNION
:
1579 case DEBUG_KIND_ENUM
:
1582 case DEBUG_KIND_CLASS
:
1585 case DEBUG_KIND_UNION_CLASS
:
1589 /* PR 25625: Corrupt input can trigger this case. */
1593 if (! push_type (info
, t
))
1599 sprintf (idbuf
, "%%anon%u", id
);
1603 if (! append_type (info
, tag
))
1605 if (name
!= NULL
&& kind
!= DEBUG_KIND_ENUM
)
1607 sprintf (idbuf
, " /* id %u */", id
);
1608 if (! append_type (info
, idbuf
))
1615 /* Output a typedef. */
1618 pr_typdef (void *p
, const char *name
)
1620 struct pr_handle
*info
= (struct pr_handle
*) p
;
1623 if (! substitute_type (info
, name
))
1626 s
= pop_type (info
);
1631 fprintf (info
->f
, "typedef %s;\n", s
);
1638 /* Output a tag. The tag should already be in the string on the
1639 stack, so all we have to do here is print it out. */
1642 pr_tag (void *p
, const char *name ATTRIBUTE_UNUSED
)
1644 struct pr_handle
*info
= (struct pr_handle
*) p
;
1647 t
= pop_type (info
);
1652 fprintf (info
->f
, "%s;\n", t
);
1659 /* Output an integer constant. */
1662 pr_int_constant (void *p
, const char *name
, bfd_vma val
)
1664 struct pr_handle
*info
= (struct pr_handle
*) p
;
1668 print_vma (val
, ab
, false, false);
1669 fprintf (info
->f
, "const int %s = %s;\n", name
, ab
);
1673 /* Output a floating point constant. */
1676 pr_float_constant (void *p
, const char *name
, double val
)
1678 struct pr_handle
*info
= (struct pr_handle
*) p
;
1681 fprintf (info
->f
, "const double %s = %g;\n", name
, val
);
1685 /* Output a typed constant. */
1688 pr_typed_constant (void *p
, const char *name
, bfd_vma val
)
1690 struct pr_handle
*info
= (struct pr_handle
*) p
;
1694 t
= pop_type (info
);
1699 print_vma (val
, ab
, false, false);
1700 fprintf (info
->f
, "const %s %s = %s;\n", t
, name
, ab
);
1707 /* Output a variable. */
1710 pr_variable (void *p
, const char *name
, enum debug_var_kind kind
,
1713 struct pr_handle
*info
= (struct pr_handle
*) p
;
1717 if (! substitute_type (info
, name
))
1720 t
= pop_type (info
);
1728 case DEBUG_LOCAL_STATIC
:
1729 fprintf (info
->f
, "static ");
1731 case DEBUG_REGISTER
:
1732 fprintf (info
->f
, "register ");
1737 print_vma (val
, ab
, true, true);
1738 fprintf (info
->f
, "%s /* %s */;\n", t
, ab
);
1745 /* Start outputting a function. */
1748 pr_start_function (void *p
, const char *name
, bool global
)
1750 struct pr_handle
*info
= (struct pr_handle
*) p
;
1753 if (! substitute_type (info
, name
))
1756 t
= pop_type (info
);
1762 fprintf (info
->f
, "static ");
1763 fprintf (info
->f
, "%s (", t
);
1767 info
->parameter
= 1;
1772 /* Output a function parameter. */
1775 pr_function_parameter (void *p
, const char *name
,
1776 enum debug_parm_kind kind
, bfd_vma val
)
1778 struct pr_handle
*info
= (struct pr_handle
*) p
;
1782 if (kind
== DEBUG_PARM_REFERENCE
1783 || kind
== DEBUG_PARM_REF_REG
)
1785 if (! pr_reference_type (p
))
1789 if (! substitute_type (info
, name
))
1792 t
= pop_type (info
);
1796 if (info
->parameter
!= 1)
1797 fprintf (info
->f
, ", ");
1799 if (kind
== DEBUG_PARM_REG
|| kind
== DEBUG_PARM_REF_REG
)
1800 fprintf (info
->f
, "register ");
1802 print_vma (val
, ab
, true, true);
1803 fprintf (info
->f
, "%s /* %s */", t
, ab
);
1812 /* Start writing out a block. */
1815 pr_start_block (void *p
, bfd_vma addr
)
1817 struct pr_handle
*info
= (struct pr_handle
*) p
;
1820 if (info
->parameter
> 0)
1822 fprintf (info
->f
, ")\n");
1823 info
->parameter
= 0;
1827 print_vma (addr
, ab
, true, true);
1828 fprintf (info
->f
, "{ /* %s */\n", ab
);
1835 /* Write out line number information. */
1838 pr_lineno (void *p
, const char *filename
, unsigned long lineno
, bfd_vma addr
)
1840 struct pr_handle
*info
= (struct pr_handle
*) p
;
1844 print_vma (addr
, ab
, true, true);
1845 fprintf (info
->f
, "/* file %s line %lu addr %s */\n", filename
, lineno
, ab
);
1850 /* Finish writing out a block. */
1853 pr_end_block (void *p
, bfd_vma addr
)
1855 struct pr_handle
*info
= (struct pr_handle
*) p
;
1861 print_vma (addr
, ab
, true, true);
1862 fprintf (info
->f
, "} /* %s */\n", ab
);
1867 /* Finish writing out a function. */
1870 pr_end_function (void *p ATTRIBUTE_UNUSED
)
1875 /* Tags style generation functions start here. */
1877 /* Variables for address to line translation. */
1879 static const char *filename
;
1880 static const char *functionname
;
1881 static unsigned int line
;
1884 /* Look for an address in a section. This is called via
1885 bfd_map_over_sections. */
1888 find_address_in_section (bfd
*abfd
, asection
*section
, void *data
)
1892 asymbol
**syms
= (asymbol
**) data
;
1897 if ((bfd_section_flags (section
) & SEC_ALLOC
) == 0)
1900 vma
= bfd_section_vma (section
);
1904 size
= bfd_section_size (section
);
1905 if (pc
>= vma
+ size
)
1908 found
= bfd_find_nearest_line (abfd
, section
, syms
, pc
- vma
,
1909 &filename
, &functionname
, &line
);
1913 translate_addresses (bfd
*abfd
, char *addr_hex
, FILE *f
, asymbol
**syms
)
1915 pc
= bfd_scan_vma (addr_hex
, NULL
, 16);
1917 bfd_map_over_sections (abfd
, find_address_in_section
, syms
);
1922 fprintf (f
, "%u", line
);
1925 /* Start a new compilation unit. */
1928 tg_start_compilation_unit (void * p
, const char *fname ATTRIBUTE_UNUSED
)
1930 struct pr_handle
*info
= (struct pr_handle
*) p
;
1932 free (info
->filename
);
1933 /* Should it be relative? best way to do it here?. */
1934 info
->filename
= xstrdup (fname
);
1939 /* Start a source file within a compilation unit. */
1942 tg_start_source (void *p
, const char *fname
)
1944 struct pr_handle
*info
= (struct pr_handle
*) p
;
1946 free (info
->filename
);
1947 /* Should it be relative? best way to do it here?. */
1948 info
->filename
= xstrdup (fname
);
1953 /* Push an enum type onto the type stack. */
1956 tg_enum_type (void *p
, const char *tag
, const char **names
,
1957 bfd_signed_vma
*values
)
1959 struct pr_handle
*info
= (struct pr_handle
*) p
;
1964 if (! pr_enum_type (p
, tag
, names
, values
))
1967 name
= tag
? tag
: "unknown";
1968 /* Generate an entry for the enum. */
1970 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:e\ttype:%s\n", tag
,
1971 info
->filename
, info
->stack
->type
);
1973 /* Generate entries for the values. */
1976 for (i
= 0; names
[i
] != NULL
; i
++)
1978 print_vma (values
[i
], ab
, false, false);
1979 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:g\tenum:%s\tvalue:%s\n",
1980 names
[i
], info
->filename
, name
, ab
);
1987 /* Start accumulating a struct type. */
1990 tg_start_struct_type (void *p
, const char *tag
, unsigned int id
,
1992 unsigned int size ATTRIBUTE_UNUSED
)
1994 struct pr_handle
*info
= (struct pr_handle
*) p
;
2003 sprintf (idbuf
, "%%anon%u", id
);
2006 if (! push_type (info
, name
))
2009 info
->stack
->flavor
= structp
? "struct" : "union";
2011 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:%c\n", name
, info
->filename
,
2012 info
->stack
->flavor
[0]);
2014 info
->stack
->visibility
= DEBUG_VISIBILITY_PUBLIC
;
2016 return indent_type (info
);
2019 /* Output the visibility of a field in a struct. */
2022 tg_fix_visibility (struct pr_handle
*info
, enum debug_visibility visibility
)
2024 assert (info
->stack
!= NULL
);
2026 if (info
->stack
->visibility
== visibility
)
2029 assert (info
->stack
->visibility
!= DEBUG_VISIBILITY_IGNORE
);
2031 info
->stack
->visibility
= visibility
;
2036 /* Add a field to a struct type. */
2039 tg_struct_field (void *p
, const char *name
, bfd_vma bitpos ATTRIBUTE_UNUSED
,
2040 bfd_vma bitsize ATTRIBUTE_UNUSED
,
2041 enum debug_visibility visibility
)
2043 struct pr_handle
*info
= (struct pr_handle
*) p
;
2046 t
= pop_type (info
);
2050 if (! tg_fix_visibility (info
, visibility
))
2056 /* It happens, a bug? */
2063 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:m\ttype:%s\t%s:%s\taccess:%s\n",
2064 name
, info
->filename
, t
, info
->stack
->flavor
, info
->stack
->type
,
2065 visibility_name (visibility
));
2072 /* Finish a struct type. */
2075 tg_end_struct_type (void *p ATTRIBUTE_UNUSED
)
2077 assert (((struct pr_handle
*) p
)->stack
!= NULL
);
2082 /* Start a class type. */
2085 tg_start_class_type (void *p
, const char *tag
, unsigned int id
,
2086 bool structp
, unsigned int size
,
2087 bool vptr
, bool ownvptr
)
2089 struct pr_handle
*info
= (struct pr_handle
*) p
;
2097 if (vptr
&& ! ownvptr
)
2099 tv
= pop_type (info
);
2108 sprintf (idbuf
, "%%anon%u", id
);
2112 if (! push_type (info
, name
))
2115 info
->stack
->flavor
= structp
? "class" : "union class";
2116 free (info
->stack
->parents
);
2117 info
->stack
->parents
= NULL
;
2119 if (size
!= 0 || vptr
|| ownvptr
|| tag
!= NULL
)
2123 if (! append_type (info
, " vtable "))
2127 if (! append_type (info
, "self "))
2132 if (! append_type (info
, tv
)
2133 || ! append_type (info
, " "))
2139 info
->stack
->visibility
= DEBUG_VISIBILITY_PRIVATE
;
2147 /* Add a static member to a class. */
2150 tg_class_static_member (void *p
, const char *name
,
2151 const char *physname ATTRIBUTE_UNUSED
,
2152 enum debug_visibility visibility
)
2154 struct pr_handle
*info
= (struct pr_handle
*) p
;
2156 int len_var
, len_class
;
2159 len_var
= strlen (name
);
2160 len_class
= strlen (info
->stack
->next
->type
);
2161 full_name
= xmalloc (len_var
+ len_class
+ 3);
2162 sprintf (full_name
, "%s::%s", info
->stack
->next
->type
, name
);
2164 if (! substitute_type (info
, full_name
))
2170 if (! prepend_type (info
, "static "))
2176 t
= pop_type (info
);
2183 if (! tg_fix_visibility (info
, visibility
))
2190 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:x\ttype:%s\tclass:%s\taccess:%s\n",
2191 name
, info
->filename
, t
, info
->stack
->type
,
2192 visibility_name (visibility
));
2199 /* Add a base class to a class. */
2202 tg_class_baseclass (void *p
, bfd_vma bitpos ATTRIBUTE_UNUSED
,
2203 bool is_virtual
, enum debug_visibility visibility
)
2205 struct pr_handle
*info
= (struct pr_handle
*) p
;
2209 assert (info
->stack
!= NULL
&& info
->stack
->next
!= NULL
);
2211 t
= pop_type (info
);
2215 /* Push it back on to take advantage of the prepend_type and
2216 append_type routines. */
2217 if (! push_type (info
, t
+ (startswith (t
, "class ")
2218 ? sizeof "class " - 1 : 0)))
2227 if (! prepend_type (info
, "virtual "))
2233 case DEBUG_VISIBILITY_PUBLIC
:
2236 case DEBUG_VISIBILITY_PROTECTED
:
2237 prefix
= "protected ";
2239 case DEBUG_VISIBILITY_PRIVATE
:
2240 prefix
= "private ";
2243 prefix
= "/* unknown visibility */ ";
2247 if (! prepend_type (info
, prefix
))
2250 t
= pop_type (info
);
2254 bool ret
= ((!info
->stack
->parents
|| append_parent (info
, ", "))
2255 && append_parent (info
, t
));
2260 /* Add a variant to a method. */
2263 tg_class_method_variant (void *p
, const char *physname ATTRIBUTE_UNUSED
,
2264 enum debug_visibility visibility
,
2265 bool constp
, bool volatilep
,
2266 bfd_vma voffset ATTRIBUTE_UNUSED
,
2269 struct pr_handle
*info
= (struct pr_handle
*) p
;
2274 assert (info
->stack
!= NULL
);
2275 assert (info
->stack
->next
!= NULL
);
2277 /* Put the const and volatile qualifiers on the type. */
2280 if (! append_type (info
, " volatile"))
2285 if (! append_type (info
, " const"))
2289 method_name
= strdup (context
? info
->stack
->next
->next
->method
2290 : info
->stack
->next
->method
);
2292 /* Stick the name of the method into its type. */
2293 if (! substitute_type (info
, method_name
))
2300 method_type
= pop_type (info
);
2301 if (method_type
== NULL
)
2307 /* Pull off the context type if there is one. */
2309 context_type
= NULL
;
2312 context_type
= pop_type (info
);
2313 if (context_type
== NULL
)
2321 /* Now the top of the stack is the class. */
2322 if (! tg_fix_visibility (info
, visibility
))
2326 free (context_type
);
2330 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:p\ttype:%s\tclass:%s\n",
2331 method_name
, info
->filename
, method_type
, info
->stack
->type
);
2334 free (context_type
);
2339 /* Add a static variant to a method. */
2342 tg_class_static_method_variant (void *p
,
2343 const char *physname ATTRIBUTE_UNUSED
,
2344 enum debug_visibility visibility
,
2345 bool constp
, bool volatilep
)
2347 struct pr_handle
*info
= (struct pr_handle
*) p
;
2351 assert (info
->stack
!= NULL
);
2352 assert (info
->stack
->next
!= NULL
);
2353 assert (info
->stack
->next
->method
!= NULL
);
2355 /* Put the const and volatile qualifiers on the type. */
2358 if (! append_type (info
, " volatile"))
2363 if (! append_type (info
, " const"))
2367 /* Mark it as static. */
2368 if (! prepend_type (info
, "static "))
2371 method_name
= strdup (info
->stack
->next
->method
);
2372 /* Stick the name of the method into its type. */
2373 if (! substitute_type (info
, info
->stack
->next
->method
))
2380 method_type
= pop_type (info
);
2381 if (method_type
== NULL
)
2387 /* Now the top of the stack is the class. */
2388 if (! tg_fix_visibility (info
, visibility
))
2395 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:p\ttype:%s\tclass:%s\taccess:%s\n",
2396 method_name
, info
->filename
, method_type
, info
->stack
->type
,
2397 visibility_name (visibility
));
2404 /* Finish up a class. */
2407 tg_end_class_type (void *p
)
2409 struct pr_handle
*info
= (struct pr_handle
*) p
;
2411 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:c\ttype:%s", info
->stack
->type
,
2412 info
->filename
, info
->stack
->flavor
);
2413 if (info
->stack
->parents
)
2415 fprintf (info
->f
, "\tinherits:%s", info
->stack
->parents
);
2416 free (info
->stack
->parents
);
2417 info
->stack
->parents
= NULL
;
2419 fputc ('\n', info
->f
);
2421 return tg_end_struct_type (p
);
2424 /* Push a type on the stack using a tag name. */
2427 tg_tag_type (void *p
, const char *name
, unsigned int id
,
2428 enum debug_type_kind kind
)
2430 struct pr_handle
*info
= (struct pr_handle
*) p
;
2431 const char *t
, *tag
;
2436 case DEBUG_KIND_STRUCT
:
2439 case DEBUG_KIND_UNION
:
2442 case DEBUG_KIND_ENUM
:
2445 case DEBUG_KIND_CLASS
:
2448 case DEBUG_KIND_UNION_CLASS
:
2456 if (! push_type (info
, t
))
2462 sprintf (idbuf
, "%%anon%u", id
);
2466 if (! append_type (info
, tag
))
2472 /* Output a typedef. */
2475 tg_typdef (void *p
, const char *name
)
2477 struct pr_handle
*info
= (struct pr_handle
*) p
;
2480 s
= pop_type (info
);
2484 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:t\ttype:%s\n", name
,
2492 /* Output a tag. The tag should already be in the string on the
2493 stack, so all we have to do here is print it out. */
2496 tg_tag (void *p ATTRIBUTE_UNUSED
, const char *name ATTRIBUTE_UNUSED
)
2498 struct pr_handle
*info
= (struct pr_handle
*) p
;
2501 t
= pop_type (info
);
2509 /* Output an integer constant. */
2512 tg_int_constant (void *p
, const char *name
, bfd_vma val
)
2514 struct pr_handle
*info
= (struct pr_handle
*) p
;
2518 print_vma (val
, ab
, false, false);
2519 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:v\ttype:const int\tvalue:%s\n",
2520 name
, info
->filename
, ab
);
2524 /* Output a floating point constant. */
2527 tg_float_constant (void *p
, const char *name
, double val
)
2529 struct pr_handle
*info
= (struct pr_handle
*) p
;
2532 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:v\ttype:const double\tvalue:%g\n",
2533 name
, info
->filename
, val
);
2537 /* Output a typed constant. */
2540 tg_typed_constant (void *p
, const char *name
, bfd_vma val
)
2542 struct pr_handle
*info
= (struct pr_handle
*) p
;
2546 t
= pop_type (info
);
2551 print_vma (val
, ab
, false, false);
2552 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:v\ttype:const %s\tvalue:%s\n",
2553 name
, info
->filename
, t
, ab
);
2560 /* Output a variable. */
2563 tg_variable (void *p
, const char *name
, enum debug_var_kind kind
,
2564 bfd_vma val ATTRIBUTE_UNUSED
)
2566 struct pr_handle
*info
= (struct pr_handle
*) p
;
2567 char *t
, *dname
, *from_class
;
2569 t
= pop_type (info
);
2574 if (info
->demangler
)
2575 dname
= info
->demangler (info
->abfd
, name
, demangle_flags
);
2581 sep
= strstr (dname
, "::");
2589 /* Obscure types as vts and type_info nodes. */
2593 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:v\ttype:%s", name
, info
->filename
, t
);
2598 case DEBUG_LOCAL_STATIC
:
2599 fprintf (info
->f
, "\tfile:");
2601 case DEBUG_REGISTER
:
2602 fprintf (info
->f
, "\tregister:");
2609 fprintf (info
->f
, "\tclass:%s", from_class
);
2614 fprintf (info
->f
, "\n");
2621 /* Start outputting a function. */
2624 tg_start_function (void *p
, const char *name
, bool global
)
2626 struct pr_handle
*info
= (struct pr_handle
*) p
;
2630 info
->stack
->flavor
= "static";
2632 info
->stack
->flavor
= NULL
;
2635 if (info
->demangler
)
2636 dname
= info
->demangler (info
->abfd
, name
, demangle_flags
);
2638 if (! substitute_type (info
, dname
? dname
: name
))
2641 free (info
->stack
->method
);
2642 info
->stack
->method
= NULL
;
2646 sep
= strstr (dname
, "::");
2649 info
->stack
->method
= dname
;
2656 info
->stack
->method
= xstrdup ("");
2659 sep
= strchr (name
, '(');
2662 /* Obscure functions as type_info function. */
2665 free (info
->stack
->parents
);
2666 info
->stack
->parents
= strdup (name
);
2669 if (! info
->stack
->method
&& ! append_type (info
, "("))
2672 info
->parameter
= 1;
2677 /* Output a function parameter. */
2680 tg_function_parameter (void *p
, const char *name
, enum debug_parm_kind kind
,
2681 bfd_vma val ATTRIBUTE_UNUSED
)
2683 struct pr_handle
*info
= (struct pr_handle
*) p
;
2686 if (kind
== DEBUG_PARM_REFERENCE
2687 || kind
== DEBUG_PARM_REF_REG
)
2689 if (! pr_reference_type (p
))
2693 if (! substitute_type (info
, name
))
2696 t
= pop_type (info
);
2700 if (! info
->stack
->method
)
2702 if (info
->parameter
!= 1 && ! append_type (info
, ", "))
2708 if (kind
== DEBUG_PARM_REG
|| kind
== DEBUG_PARM_REF_REG
)
2709 if (! append_type (info
, "register "))
2715 if (! append_type (info
, t
))
2729 /* Start writing out a block. */
2732 tg_start_block (void *p
, bfd_vma addr
)
2734 struct pr_handle
*info
= (struct pr_handle
*) p
;
2735 char ab
[22], kind
, *partof
;
2739 if (info
->parameter
> 0)
2741 info
->parameter
= 0;
2744 fprintf (info
->f
, "%s\t%s\t", info
->stack
->parents
, info
->filename
);
2745 free (info
->stack
->parents
);
2746 info
->stack
->parents
= NULL
;
2748 print_vma (addr
, ab
, true, true);
2749 translate_addresses (info
->abfd
, ab
, info
->f
, info
->syms
);
2750 local
= info
->stack
->flavor
!= NULL
;
2751 if (info
->stack
->method
&& *info
->stack
->method
)
2754 partof
= (char *) info
->stack
->method
;
2760 if (! info
->stack
->method
&& ! append_type (info
, ")"))
2763 t
= pop_type (info
);
2766 fprintf (info
->f
, ";\"\tkind:%c\ttype:%s", kind
, t
);
2769 fputs ("\tfile:", info
->f
);
2771 fprintf (info
->f
, "\tclass:%s", partof
);
2772 fputc ('\n', info
->f
);
2773 free (info
->stack
->method
);
2774 info
->stack
->method
= NULL
;
2780 /* Write out line number information. */
2783 tg_lineno (void *p ATTRIBUTE_UNUSED
, const char *fname ATTRIBUTE_UNUSED
,
2784 unsigned long lineno ATTRIBUTE_UNUSED
,
2785 bfd_vma addr ATTRIBUTE_UNUSED
)
2790 /* Finish writing out a block. */
2793 tg_end_block (void *p ATTRIBUTE_UNUSED
, bfd_vma addr ATTRIBUTE_UNUSED
)
2798 /* Convert the visibility value into a human readable name. */
2801 visibility_name (enum debug_visibility visibility
)
2807 case DEBUG_VISIBILITY_PUBLIC
:
2810 case DEBUG_VISIBILITY_PRIVATE
:
2813 case DEBUG_VISIBILITY_PROTECTED
:
2816 case DEBUG_VISIBILITY_IGNORE
: