1 /* prdbg.c -- Print out generic debugging information.
2 Copyright (C) 1995-2022 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. */
74 /* How many parents contains parents. */
78 static void indent (struct pr_handle
*);
79 static bool push_type (struct pr_handle
*, const char *);
80 static bool prepend_type (struct pr_handle
*, const char *);
81 static bool append_type (struct pr_handle
*, const char *);
82 static bool substitute_type (struct pr_handle
*, const char *);
83 static bool indent_type (struct pr_handle
*);
84 static char *pop_type (struct pr_handle
*);
85 static void print_vma (bfd_vma
, char *, bool, bool);
86 static bool pr_fix_visibility (struct pr_handle
*, enum debug_visibility
);
87 static bool pr_start_compilation_unit (void *, const char *);
88 static bool pr_start_source (void *, const char *);
89 static bool pr_empty_type (void *);
90 static bool pr_void_type (void *);
91 static bool pr_int_type (void *, unsigned int, bool);
92 static bool pr_float_type (void *, unsigned int);
93 static bool pr_complex_type (void *, unsigned int);
94 static bool pr_bool_type (void *, unsigned int);
95 static bool pr_enum_type
96 (void *, const char *, const char **, bfd_signed_vma
*);
97 static bool pr_pointer_type (void *);
98 static bool pr_function_type (void *, int, bool);
99 static bool pr_reference_type (void *);
100 static bool pr_range_type (void *, bfd_signed_vma
, bfd_signed_vma
);
101 static bool pr_array_type (void *, bfd_signed_vma
, bfd_signed_vma
, bool);
102 static bool pr_set_type (void *, bool);
103 static bool pr_offset_type (void *);
104 static bool pr_method_type (void *, bool, int, bool);
105 static bool pr_const_type (void *);
106 static bool pr_volatile_type (void *);
107 static bool pr_start_struct_type
108 (void *, const char *, unsigned int, bool, unsigned int);
109 static bool pr_struct_field
110 (void *, const char *, bfd_vma
, bfd_vma
, enum debug_visibility
);
111 static bool pr_end_struct_type (void *);
112 static bool pr_start_class_type
113 (void *, const char *, unsigned int, bool, unsigned int, bool, bool);
114 static bool pr_class_static_member
115 (void *, const char *, const char *, enum debug_visibility
);
116 static bool pr_class_baseclass
117 (void *, bfd_vma
, bool, enum debug_visibility
);
118 static bool pr_class_start_method (void *, const char *);
119 static bool pr_class_method_variant
120 (void *, const char *, enum debug_visibility
, bool, bool, bfd_vma
, bool);
121 static bool pr_class_static_method_variant
122 (void *, const char *, enum debug_visibility
, bool, bool);
123 static bool pr_class_end_method (void *);
124 static bool pr_end_class_type (void *);
125 static bool pr_typedef_type (void *, const char *);
126 static bool pr_tag_type
127 (void *, const char *, unsigned int, enum debug_type_kind
);
128 static bool pr_typdef (void *, const char *);
129 static bool pr_tag (void *, const char *);
130 static bool pr_int_constant (void *, const char *, bfd_vma
);
131 static bool pr_float_constant (void *, const char *, double);
132 static bool pr_typed_constant (void *, const char *, bfd_vma
);
133 static bool pr_variable (void *, const char *, enum debug_var_kind
, bfd_vma
);
134 static bool pr_start_function (void *, const char *, bool);
135 static bool pr_function_parameter
136 (void *, const char *, enum debug_parm_kind
, bfd_vma
);
137 static bool pr_start_block (void *, bfd_vma
);
138 static bool pr_end_block (void *, bfd_vma
);
139 static bool pr_end_function (void *);
140 static bool pr_lineno (void *, const char *, unsigned long, bfd_vma
);
141 static bool append_parent (struct pr_handle
*, const char *);
142 /* Only used by tg_ code. */
143 static bool tg_fix_visibility
144 (struct pr_handle
*, enum debug_visibility
);
145 static void find_address_in_section (bfd
*, asection
*, void *);
146 static void translate_addresses (bfd
*, char *, FILE *, asymbol
**);
147 static const char *visibility_name (enum debug_visibility
);
148 /* Tags style replacements. */
149 static bool tg_start_compilation_unit (void *, const char *);
150 static bool tg_start_source (void *, const char *);
151 static bool tg_enum_type
152 (void *, const char *, const char **, bfd_signed_vma
*);
153 static bool tg_start_struct_type
154 (void *, const char *, unsigned int, bool, unsigned int);
155 static bool pr_struct_field
156 (void *, const char *, bfd_vma
, bfd_vma
, enum debug_visibility
);
157 static bool tg_struct_field
158 (void *, const char *, bfd_vma
, bfd_vma
, enum debug_visibility
);
159 static bool tg_struct_field
160 (void *, const char *, bfd_vma
, bfd_vma
, enum debug_visibility
);
161 static bool tg_end_struct_type (void *);
162 static bool tg_start_class_type
163 (void *, const char *, unsigned int, bool, unsigned int, bool, bool);
164 static bool tg_class_static_member
165 (void *, const char *, const char *, enum debug_visibility
);
166 static bool tg_class_baseclass (void *, bfd_vma
, bool, enum debug_visibility
);
167 static bool tg_class_method_variant
168 (void *, const char *, enum debug_visibility
, bool, bool, bfd_vma
, bool);
169 static bool tg_class_static_method_variant
170 (void *, const char *, enum debug_visibility
, bool, bool);
171 static bool tg_end_class_type (void *);
172 static bool tg_tag_type
173 (void *, const char *, unsigned int, enum debug_type_kind
);
174 static bool tg_typdef (void *, const char *);
175 static bool tg_tag (void *, const char *);
176 static bool tg_int_constant (void *, const char *, bfd_vma
);
177 static bool tg_float_constant (void *, const char *, double);
178 static bool tg_typed_constant (void *, const char *, bfd_vma
);
179 static bool tg_variable (void *, const char *, enum debug_var_kind
, bfd_vma
);
180 static bool tg_start_function (void *, const char *, bool);
181 static bool tg_function_parameter
182 (void *, const char *, enum debug_parm_kind
, bfd_vma
);
183 static bool tg_start_block (void *, bfd_vma
);
184 static bool tg_end_block (void *, bfd_vma
);
185 static bool tg_lineno (void *, const char *, unsigned long, bfd_vma
);
187 static const struct debug_write_fns pr_fns
=
189 pr_start_compilation_unit
,
208 pr_start_struct_type
,
212 pr_class_static_member
,
214 pr_class_start_method
,
215 pr_class_method_variant
,
216 pr_class_static_method_variant
,
228 pr_function_parameter
,
235 static const struct debug_write_fns tg_fns
=
237 tg_start_compilation_unit
,
239 pr_empty_type
, /* Same, push_type. */
240 pr_void_type
, /* Same, push_type. */
241 pr_int_type
, /* Same, push_type. */
242 pr_float_type
, /* Same, push_type. */
243 pr_complex_type
, /* Same, push_type. */
244 pr_bool_type
, /* Same, push_type. */
246 pr_pointer_type
, /* Same, changes to pointer. */
247 pr_function_type
, /* Same, push_type. */
248 pr_reference_type
, /* Same, changes to reference. */
249 pr_range_type
, /* FIXME: What's that?. */
250 pr_array_type
, /* Same, push_type. */
251 pr_set_type
, /* FIXME: What's that?. */
252 pr_offset_type
, /* FIXME: What's that?. */
253 pr_method_type
, /* Same. */
254 pr_const_type
, /* Same, changes to const. */
255 pr_volatile_type
, /* Same, changes to volatile. */
256 tg_start_struct_type
,
260 tg_class_static_member
,
262 pr_class_start_method
, /* Same, remembers that's a method. */
263 tg_class_method_variant
,
264 tg_class_static_method_variant
,
265 pr_class_end_method
, /* Same, forgets that's a method. */
267 pr_typedef_type
, /* Same, just push type. */
271 tg_int_constant
, /* Untested. */
272 tg_float_constant
, /* Untested. */
273 tg_typed_constant
, /* Untested. */
276 tg_function_parameter
,
279 pr_end_function
, /* Same, does nothing. */
283 static int demangle_flags
= DMGL_ANSI
| DMGL_PARAMS
;
285 /* Print out the generic debugging information recorded in dhandle. */
288 print_debugging_info (FILE *f
, void *dhandle
, bfd
*abfd
, asymbol
**syms
,
289 char * (*demangler
) (struct bfd
*, const char *, int),
292 struct pr_handle info
;
298 info
.filename
= NULL
;
301 info
.demangler
= demangler
;
305 fputs ("!_TAG_FILE_FORMAT\t2\t/extended format/\n", f
);
306 fputs ("!_TAG_FILE_SORTED\t0\t/0=unsorted, 1=sorted/\n", f
);
307 fputs ("!_TAG_PROGRAM_AUTHOR\tIan Lance Taylor, Salvador E. Tropea and others\t//\n", f
);
308 fputs ("!_TAG_PROGRAM_NAME\tobjdump\t/From GNU binutils/\n", f
);
311 return as_tags
? debug_write (dhandle
, &tg_fns
, (void *) & info
)
312 : debug_write (dhandle
, &pr_fns
, (void *) & info
);
315 /* Indent to the current indentation level. */
318 indent (struct pr_handle
*info
)
322 for (i
= 0; i
< info
->indent
; i
++)
326 /* Push a type on the type stack. */
329 push_type (struct pr_handle
*info
, const char *type
)
336 n
= (struct pr_stack
*) xmalloc (sizeof *n
);
337 memset (n
, 0, sizeof *n
);
339 n
->type
= xstrdup (type
);
340 n
->visibility
= DEBUG_VISIBILITY_IGNORE
;
342 n
->next
= info
->stack
;
348 /* Prepend a string onto the type on the top of the type stack. */
351 prepend_type (struct pr_handle
*info
, const char *s
)
355 assert (info
->stack
!= NULL
);
357 n
= (char *) xmalloc (strlen (s
) + strlen (info
->stack
->type
) + 1);
358 sprintf (n
, "%s%s", s
, info
->stack
->type
);
359 free (info
->stack
->type
);
360 info
->stack
->type
= n
;
365 /* Append a string to the type on the top of the type stack. */
368 append_type (struct pr_handle
*info
, const char *s
)
375 assert (info
->stack
!= NULL
);
377 len
= strlen (info
->stack
->type
);
378 info
->stack
->type
= (char *) xrealloc (info
->stack
->type
,
379 len
+ strlen (s
) + 1);
380 strcpy (info
->stack
->type
+ len
, s
);
385 /* Append a string to the parents on the top of the type stack. */
388 append_parent (struct pr_handle
*info
, const char *s
)
395 assert (info
->stack
!= NULL
);
397 len
= info
->stack
->parents
? strlen (info
->stack
->parents
) : 0;
398 info
->stack
->parents
= (char *) xrealloc (info
->stack
->parents
,
399 len
+ strlen (s
) + 1);
400 strcpy (info
->stack
->parents
+ len
, s
);
405 /* We use an underscore to indicate where the name should go in a type
406 string. This function substitutes a string for the underscore. If
407 there is no underscore, the name follows the type. */
410 substitute_type (struct pr_handle
*info
, const char *s
)
414 assert (info
->stack
!= NULL
);
416 u
= strchr (info
->stack
->type
, '|');
421 n
= (char *) xmalloc (strlen (info
->stack
->type
) + strlen (s
));
423 memcpy (n
, info
->stack
->type
, u
- info
->stack
->type
);
424 strcpy (n
+ (u
- info
->stack
->type
), s
);
427 free (info
->stack
->type
);
428 info
->stack
->type
= n
;
433 if (strchr (s
, '|') != NULL
434 && (strchr (info
->stack
->type
, '{') != NULL
435 || strchr (info
->stack
->type
, '(') != NULL
))
437 if (! prepend_type (info
, "(")
438 || ! append_type (info
, ")"))
445 return (append_type (info
, " ")
446 && append_type (info
, s
));
449 /* Indent the type at the top of the stack by appending spaces. */
452 indent_type (struct pr_handle
*info
)
456 for (i
= 0; i
< info
->indent
; i
++)
458 if (! append_type (info
, " "))
465 /* Pop a type from the type stack. */
468 pop_type (struct pr_handle
*info
)
473 assert (info
->stack
!= NULL
);
476 info
->stack
= o
->next
;
483 /* Print a VMA value into a string. */
486 print_vma (bfd_vma vma
, char *buf
, bool unsignedp
, bool hexp
)
488 if (sizeof (vma
) <= sizeof (unsigned long))
491 sprintf (buf
, "0x%lx", (unsigned long) vma
);
493 sprintf (buf
, "%lu", (unsigned long) vma
);
495 sprintf (buf
, "%ld", (long) vma
);
497 #if BFD_HOST_64BIT_LONG_LONG
498 else if (sizeof (vma
) <= sizeof (unsigned long long))
502 sprintf (buf
, "0x%llx", (unsigned long long) vma
);
504 sprintf (buf
, "%llu", (unsigned long long) vma
);
506 sprintf (buf
, "%lld", (long long) vma
);
509 sprintf (buf
, "0x%I64x", (unsigned long long) vma
);
511 sprintf (buf
, "%I64u", (unsigned long long) vma
);
513 sprintf (buf
, "%I64d", (long long) vma
);
521 sprintf_vma (buf
+ 2, vma
);
525 /* Start a new compilation unit. */
528 pr_start_compilation_unit (void *p
, const char *filename
)
530 struct pr_handle
*info
= (struct pr_handle
*) p
;
532 assert (info
->indent
== 0);
534 fprintf (info
->f
, "%s:\n", filename
);
539 /* Start a source file within a compilation unit. */
542 pr_start_source (void *p
, const char *filename
)
544 struct pr_handle
*info
= (struct pr_handle
*) p
;
546 assert (info
->indent
== 0);
548 fprintf (info
->f
, " %s:\n", filename
);
553 /* Push an empty type onto the type stack. */
556 pr_empty_type (void *p
)
558 struct pr_handle
*info
= (struct pr_handle
*) p
;
560 return push_type (info
, "<undefined>");
563 /* Push a void type onto the type stack. */
566 pr_void_type (void *p
)
568 struct pr_handle
*info
= (struct pr_handle
*) p
;
570 return push_type (info
, "void");
573 /* Push an integer type onto the type stack. */
576 pr_int_type (void *p
, unsigned int size
, bool unsignedp
)
578 struct pr_handle
*info
= (struct pr_handle
*) p
;
581 sprintf (ab
, "%sint%d", unsignedp
? "u" : "", size
* 8);
582 return push_type (info
, ab
);
585 /* Push a floating type onto the type stack. */
588 pr_float_type (void *p
, unsigned int size
)
590 struct pr_handle
*info
= (struct pr_handle
*) p
;
594 return push_type (info
, "float");
596 return push_type (info
, "double");
598 sprintf (ab
, "float%d", size
* 8);
599 return push_type (info
, ab
);
602 /* Push a complex type onto the type stack. */
605 pr_complex_type (void *p
, unsigned int size
)
607 struct pr_handle
*info
= (struct pr_handle
*) p
;
609 if (! pr_float_type (p
, size
))
612 return prepend_type (info
, "complex ");
615 /* Push a bool type onto the type stack. */
618 pr_bool_type (void *p
, unsigned int size
)
620 struct pr_handle
*info
= (struct pr_handle
*) p
;
623 sprintf (ab
, "bool%d", size
* 8);
625 return push_type (info
, ab
);
628 /* Push an enum type onto the type stack. */
631 pr_enum_type (void *p
, const char *tag
, const char **names
,
632 bfd_signed_vma
*values
)
634 struct pr_handle
*info
= (struct pr_handle
*) p
;
638 if (! push_type (info
, "enum "))
642 if (! append_type (info
, tag
)
643 || ! append_type (info
, " "))
646 if (! append_type (info
, "{ "))
651 if (! append_type (info
, "/* undefined */"))
657 for (i
= 0; names
[i
] != NULL
; i
++)
661 if (! append_type (info
, ", "))
665 if (! append_type (info
, names
[i
]))
668 if (values
[i
] != val
)
672 print_vma (values
[i
], ab
, false, false);
673 if (! append_type (info
, " = ")
674 || ! append_type (info
, ab
))
683 return append_type (info
, " }");
686 /* Turn the top type on the stack into a pointer. */
689 pr_pointer_type (void *p
)
691 struct pr_handle
*info
= (struct pr_handle
*) p
;
694 assert (info
->stack
!= NULL
);
696 s
= strchr (info
->stack
->type
, '|');
697 if (s
!= NULL
&& s
[1] == '[')
698 return substitute_type (info
, "(*|)");
699 return substitute_type (info
, "*|");
702 /* Turn the top type on the stack into a function returning that type. */
705 pr_function_type (void *p
, int argcount
, bool varargs
)
707 struct pr_handle
*info
= (struct pr_handle
*) p
;
712 assert (info
->stack
!= NULL
);
725 arg_types
= (char **) xmalloc (argcount
* sizeof *arg_types
);
726 for (i
= argcount
- 1; i
>= 0; i
--)
728 if (! substitute_type (info
, ""))
733 arg_types
[i
] = pop_type (info
);
734 if (arg_types
[i
] == NULL
)
739 len
+= strlen (arg_types
[i
]) + 2;
745 /* Now the return type is on the top of the stack. */
747 s
= (char *) xmalloc (len
);
751 strcat (s
, "/* unknown */");
756 for (i
= 0; i
< argcount
; i
++)
760 strcat (s
, arg_types
[i
]);
774 if (! substitute_type (info
, s
))
782 /* Turn the top type on the stack into a reference to that type. */
785 pr_reference_type (void *p
)
787 struct pr_handle
*info
= (struct pr_handle
*) p
;
789 assert (info
->stack
!= NULL
);
791 return substitute_type (info
, "&|");
794 /* Make a range type. */
797 pr_range_type (void *p
, bfd_signed_vma lower
, bfd_signed_vma upper
)
799 struct pr_handle
*info
= (struct pr_handle
*) p
;
800 char abl
[22], abu
[22];
802 assert (info
->stack
!= NULL
);
804 if (! substitute_type (info
, ""))
807 print_vma (lower
, abl
, false, false);
808 print_vma (upper
, abu
, false, false);
810 return (prepend_type (info
, "range (")
811 && append_type (info
, "):")
812 && append_type (info
, abl
)
813 && append_type (info
, ":")
814 && append_type (info
, abu
));
817 /* Make an array type. */
820 pr_array_type (void *p
, bfd_signed_vma lower
, bfd_signed_vma upper
,
823 struct pr_handle
*info
= (struct pr_handle
*) p
;
825 char abl
[22], abu
[22], ab
[50];
827 range_type
= pop_type (info
);
828 if (range_type
== NULL
)
837 print_vma (upper
+ 1, abu
, false, false);
838 sprintf (ab
, "|[%s]", abu
);
843 print_vma (lower
, abl
, false, false);
844 print_vma (upper
, abu
, false, false);
845 sprintf (ab
, "|[%s:%s]", abl
, abu
);
848 if (! substitute_type (info
, ab
))
851 if (strcmp (range_type
, "int") != 0)
853 if (! append_type (info
, ":")
854 || ! append_type (info
, range_type
))
860 if (! append_type (info
, " /* string */"))
867 /* Make a set type. */
870 pr_set_type (void *p
, bool bitstringp
)
872 struct pr_handle
*info
= (struct pr_handle
*) p
;
874 if (! substitute_type (info
, ""))
877 if (! prepend_type (info
, "set { ")
878 || ! append_type (info
, " }"))
883 if (! append_type (info
, "/* bitstring */"))
890 /* Make an offset type. */
893 pr_offset_type (void *p
)
895 struct pr_handle
*info
= (struct pr_handle
*) p
;
898 if (! substitute_type (info
, ""))
905 return (substitute_type (info
, "")
906 && prepend_type (info
, " ")
907 && prepend_type (info
, t
)
908 && append_type (info
, "::|"));
911 /* Make a method type. */
914 pr_method_type (void *p
, bool domain
, int argcount
, bool varargs
)
916 struct pr_handle
*info
= (struct pr_handle
*) p
;
928 if (! substitute_type (info
, ""))
930 domain_type
= pop_type (info
);
931 if (domain_type
== NULL
)
933 if (startswith (domain_type
, "class ")
934 && strchr (domain_type
+ sizeof "class " - 1, ' ') == NULL
)
935 domain_type
+= sizeof "class " - 1;
936 else if (startswith (domain_type
, "union class ")
937 && (strchr (domain_type
+ sizeof "union class " - 1, ' ')
939 domain_type
+= sizeof "union class " - 1;
940 len
+= strlen (domain_type
);
952 arg_types
= (char **) xmalloc (argcount
* sizeof *arg_types
);
953 for (i
= argcount
- 1; i
>= 0; i
--)
955 if (! substitute_type (info
, ""))
960 arg_types
[i
] = pop_type (info
);
961 if (arg_types
[i
] == NULL
)
966 len
+= strlen (arg_types
[i
]) + 2;
972 /* Now the return type is on the top of the stack. */
974 s
= (char *) xmalloc (len
);
978 strcpy (s
, domain_type
);
982 strcat (s
, "/* unknown */");
987 for (i
= 0; i
< argcount
; i
++)
991 strcat (s
, arg_types
[i
]);
1005 if (! substitute_type (info
, s
))
1013 /* Make a const qualified type. */
1016 pr_const_type (void *p
)
1018 struct pr_handle
*info
= (struct pr_handle
*) p
;
1020 return substitute_type (info
, "const |");
1023 /* Make a volatile qualified type. */
1026 pr_volatile_type (void *p
)
1028 struct pr_handle
*info
= (struct pr_handle
*) p
;
1030 return substitute_type (info
, "volatile |");
1033 /* Start accumulating a struct type. */
1036 pr_start_struct_type (void *p
, const char *tag
, unsigned int id
,
1037 bool structp
, unsigned int size
)
1039 struct pr_handle
*info
= (struct pr_handle
*) p
;
1043 if (! push_type (info
, structp
? "struct " : "union "))
1047 if (! append_type (info
, tag
))
1054 sprintf (idbuf
, "%%anon%u", id
);
1055 if (! append_type (info
, idbuf
))
1059 if (! append_type (info
, " {"))
1061 if (size
!= 0 || tag
!= NULL
)
1065 if (! append_type (info
, " /*"))
1070 sprintf (ab
, " size %u", size
);
1071 if (! append_type (info
, ab
))
1076 sprintf (ab
, " id %u", id
);
1077 if (! append_type (info
, ab
))
1080 if (! append_type (info
, " */"))
1083 if (! append_type (info
, "\n"))
1086 info
->stack
->visibility
= DEBUG_VISIBILITY_PUBLIC
;
1088 return indent_type (info
);
1091 /* Output the visibility of a field in a struct. */
1094 pr_fix_visibility (struct pr_handle
*info
, enum debug_visibility visibility
)
1096 const char *s
= NULL
;
1100 assert (info
->stack
!= NULL
);
1102 if (info
->stack
->visibility
== visibility
)
1107 case DEBUG_VISIBILITY_PUBLIC
:
1110 case DEBUG_VISIBILITY_PRIVATE
:
1113 case DEBUG_VISIBILITY_PROTECTED
:
1116 case DEBUG_VISIBILITY_IGNORE
:
1124 /* Trim off a trailing space in the struct string, to make the
1125 output look a bit better, then stick on the visibility string. */
1127 t
= info
->stack
->type
;
1129 assert (t
[len
- 1] == ' ');
1132 if (! append_type (info
, s
)
1133 || ! append_type (info
, ":\n")
1134 || ! indent_type (info
))
1137 info
->stack
->visibility
= visibility
;
1142 /* Add a field to a struct type. */
1145 pr_struct_field (void *p
, const char *name
, bfd_vma bitpos
, bfd_vma bitsize
,
1146 enum debug_visibility visibility
)
1148 struct pr_handle
*info
= (struct pr_handle
*) p
;
1152 if (! substitute_type (info
, name
))
1155 if (! append_type (info
, "; /* "))
1160 print_vma (bitsize
, ab
, true, false);
1161 if (! append_type (info
, "bitsize ")
1162 || ! append_type (info
, ab
)
1163 || ! append_type (info
, ", "))
1167 print_vma (bitpos
, ab
, true, false);
1168 if (! append_type (info
, "bitpos ")
1169 || ! append_type (info
, ab
)
1170 || ! append_type (info
, " */\n")
1171 || ! indent_type (info
))
1174 t
= pop_type (info
);
1178 if (! pr_fix_visibility (info
, visibility
))
1181 return append_type (info
, t
);
1184 /* Finish a struct type. */
1187 pr_end_struct_type (void *p
)
1189 struct pr_handle
*info
= (struct pr_handle
*) p
;
1192 assert (info
->stack
!= NULL
);
1193 assert (info
->indent
>= 2);
1197 /* Change the trailing indentation to have a close brace. */
1198 s
= info
->stack
->type
+ strlen (info
->stack
->type
) - 2;
1199 assert (s
[0] == ' ' && s
[1] == ' ' && s
[2] == '\0');
1207 /* Start a class type. */
1210 pr_start_class_type (void *p
, const char *tag
, unsigned int id
,
1211 bool structp
, unsigned int size
,
1212 bool vptr
, bool ownvptr
)
1214 struct pr_handle
*info
= (struct pr_handle
*) p
;
1219 if (vptr
&& ! ownvptr
)
1221 tv
= pop_type (info
);
1226 if (! push_type (info
, structp
? "class " : "union class "))
1230 if (! append_type (info
, tag
))
1237 sprintf (idbuf
, "%%anon%u", id
);
1238 if (! append_type (info
, idbuf
))
1242 if (! append_type (info
, " {"))
1244 if (size
!= 0 || vptr
|| ownvptr
|| tag
!= NULL
)
1246 if (! append_type (info
, " /*"))
1253 sprintf (ab
, "%u", size
);
1254 if (! append_type (info
, " size ")
1255 || ! append_type (info
, ab
))
1261 if (! append_type (info
, " vtable "))
1265 if (! append_type (info
, "self "))
1270 if (! append_type (info
, tv
)
1271 || ! append_type (info
, " "))
1280 sprintf (ab
, " id %u", id
);
1281 if (! append_type (info
, ab
))
1285 if (! append_type (info
, " */"))
1289 info
->stack
->visibility
= DEBUG_VISIBILITY_PRIVATE
;
1291 return (append_type (info
, "\n")
1292 && indent_type (info
));
1295 /* Add a static member to a class. */
1298 pr_class_static_member (void *p
, const char *name
, const char *physname
,
1299 enum debug_visibility visibility
)
1301 struct pr_handle
*info
= (struct pr_handle
*) p
;
1304 if (! substitute_type (info
, name
))
1307 if (! prepend_type (info
, "static ")
1308 || ! append_type (info
, "; /* ")
1309 || ! append_type (info
, physname
)
1310 || ! append_type (info
, " */\n")
1311 || ! indent_type (info
))
1314 t
= pop_type (info
);
1318 if (! pr_fix_visibility (info
, visibility
))
1321 return append_type (info
, t
);
1324 /* Add a base class to a class. */
1327 pr_class_baseclass (void *p
, bfd_vma bitpos
, bool is_virtual
,
1328 enum debug_visibility visibility
)
1330 struct pr_handle
*info
= (struct pr_handle
*) p
;
1336 assert (info
->stack
!= NULL
&& info
->stack
->next
!= NULL
);
1338 if (! substitute_type (info
, ""))
1341 t
= pop_type (info
);
1345 if (startswith (t
, "class "))
1346 t
+= sizeof "class " - 1;
1348 /* Push it back on to take advantage of the prepend_type and
1349 append_type routines. */
1350 if (! push_type (info
, t
))
1355 if (! prepend_type (info
, "virtual "))
1361 case DEBUG_VISIBILITY_PUBLIC
:
1364 case DEBUG_VISIBILITY_PROTECTED
:
1365 prefix
= "protected ";
1367 case DEBUG_VISIBILITY_PRIVATE
:
1368 prefix
= "private ";
1371 prefix
= "/* unknown visibility */ ";
1375 if (! prepend_type (info
, prefix
))
1380 print_vma (bitpos
, ab
, true, false);
1381 if (! append_type (info
, " /* bitpos ")
1382 || ! append_type (info
, ab
)
1383 || ! append_type (info
, " */"))
1387 /* Now the top of the stack is something like "public A / * bitpos
1388 10 * /". The next element on the stack is something like "class
1389 xx { / * size 8 * /\n...". We want to substitute the top of the
1390 stack in before the {. */
1391 s
= strchr (info
->stack
->next
->type
, '{');
1395 /* If there is already a ':', then we already have a baseclass, and
1396 we must append this one after a comma. */
1397 for (l
= info
->stack
->next
->type
; l
!= s
; l
++)
1400 if (! prepend_type (info
, l
== s
? " : " : ", "))
1403 t
= pop_type (info
);
1407 n
= (char *) xmalloc (strlen (info
->stack
->type
) + strlen (t
) + 1);
1408 memcpy (n
, info
->stack
->type
, s
- info
->stack
->type
);
1409 strcpy (n
+ (s
- info
->stack
->type
), t
);
1412 free (info
->stack
->type
);
1413 info
->stack
->type
= n
;
1420 /* Start adding a method to a class. */
1423 pr_class_start_method (void *p
, const char *name
)
1425 struct pr_handle
*info
= (struct pr_handle
*) p
;
1427 assert (info
->stack
!= NULL
);
1428 info
->stack
->method
= name
;
1432 /* Add a variant to a method. */
1435 pr_class_method_variant (void *p
, const char *physname
,
1436 enum debug_visibility visibility
,
1437 bool constp
, bool volatilep
,
1438 bfd_vma voffset
, bool context
)
1440 struct pr_handle
*info
= (struct pr_handle
*) p
;
1444 assert (info
->stack
!= NULL
);
1445 assert (info
->stack
->next
!= NULL
);
1447 /* Put the const and volatile qualifiers on the type. */
1450 if (! append_type (info
, " volatile"))
1455 if (! append_type (info
, " const"))
1459 /* Stick the name of the method into its type. */
1460 if (! substitute_type (info
,
1462 ? info
->stack
->next
->next
->method
1463 : info
->stack
->next
->method
)))
1467 method_type
= pop_type (info
);
1468 if (method_type
== NULL
)
1471 /* Pull off the context type if there is one. */
1473 context_type
= NULL
;
1476 context_type
= pop_type (info
);
1477 if (context_type
== NULL
)
1481 /* Now the top of the stack is the class. */
1483 if (! pr_fix_visibility (info
, visibility
))
1486 if (! append_type (info
, method_type
)
1487 || ! append_type (info
, " /* ")
1488 || ! append_type (info
, physname
)
1489 || ! append_type (info
, " "))
1491 if (context
|| voffset
!= 0)
1497 if (! append_type (info
, "context ")
1498 || ! append_type (info
, context_type
)
1499 || ! append_type (info
, " "))
1502 print_vma (voffset
, ab
, true, false);
1503 if (! append_type (info
, "voffset ")
1504 || ! append_type (info
, ab
))
1508 return (append_type (info
, " */;\n")
1509 && indent_type (info
));
1512 /* Add a static variant to a method. */
1515 pr_class_static_method_variant (void *p
, const char *physname
,
1516 enum debug_visibility visibility
,
1517 bool constp
, bool volatilep
)
1519 struct pr_handle
*info
= (struct pr_handle
*) p
;
1522 assert (info
->stack
!= NULL
);
1523 assert (info
->stack
->next
!= NULL
);
1524 assert (info
->stack
->next
->method
!= NULL
);
1526 /* Put the const and volatile qualifiers on the type. */
1529 if (! append_type (info
, " volatile"))
1534 if (! append_type (info
, " const"))
1538 /* Mark it as static. */
1539 if (! prepend_type (info
, "static "))
1542 /* Stick the name of the method into its type. */
1543 if (! substitute_type (info
, info
->stack
->next
->method
))
1547 method_type
= pop_type (info
);
1548 if (method_type
== NULL
)
1551 /* Now the top of the stack is the class. */
1553 if (! pr_fix_visibility (info
, visibility
))
1556 return (append_type (info
, method_type
)
1557 && append_type (info
, " /* ")
1558 && append_type (info
, physname
)
1559 && append_type (info
, " */;\n")
1560 && indent_type (info
));
1563 /* Finish up a method. */
1566 pr_class_end_method (void *p
)
1568 struct pr_handle
*info
= (struct pr_handle
*) p
;
1570 info
->stack
->method
= NULL
;
1574 /* Finish up a class. */
1577 pr_end_class_type (void *p
)
1579 return pr_end_struct_type (p
);
1582 /* Push a type on the stack using a typedef name. */
1585 pr_typedef_type (void *p
, const char *name
)
1587 struct pr_handle
*info
= (struct pr_handle
*) p
;
1589 return push_type (info
, name
);
1592 /* Push a type on the stack using a tag name. */
1595 pr_tag_type (void *p
, const char *name
, unsigned int id
,
1596 enum debug_type_kind kind
)
1598 struct pr_handle
*info
= (struct pr_handle
*) p
;
1599 const char *t
, *tag
;
1604 case DEBUG_KIND_STRUCT
:
1607 case DEBUG_KIND_UNION
:
1610 case DEBUG_KIND_ENUM
:
1613 case DEBUG_KIND_CLASS
:
1616 case DEBUG_KIND_UNION_CLASS
:
1620 /* PR 25625: Corrupt input can trigger this case. */
1624 if (! push_type (info
, t
))
1630 sprintf (idbuf
, "%%anon%u", id
);
1634 if (! append_type (info
, tag
))
1636 if (name
!= NULL
&& kind
!= DEBUG_KIND_ENUM
)
1638 sprintf (idbuf
, " /* id %u */", id
);
1639 if (! append_type (info
, idbuf
))
1646 /* Output a typedef. */
1649 pr_typdef (void *p
, const char *name
)
1651 struct pr_handle
*info
= (struct pr_handle
*) p
;
1654 if (! substitute_type (info
, name
))
1657 s
= pop_type (info
);
1662 fprintf (info
->f
, "typedef %s;\n", s
);
1669 /* Output a tag. The tag should already be in the string on the
1670 stack, so all we have to do here is print it out. */
1673 pr_tag (void *p
, const char *name ATTRIBUTE_UNUSED
)
1675 struct pr_handle
*info
= (struct pr_handle
*) p
;
1678 t
= pop_type (info
);
1683 fprintf (info
->f
, "%s;\n", t
);
1690 /* Output an integer constant. */
1693 pr_int_constant (void *p
, const char *name
, bfd_vma val
)
1695 struct pr_handle
*info
= (struct pr_handle
*) p
;
1699 print_vma (val
, ab
, false, false);
1700 fprintf (info
->f
, "const int %s = %s;\n", name
, ab
);
1704 /* Output a floating point constant. */
1707 pr_float_constant (void *p
, const char *name
, double val
)
1709 struct pr_handle
*info
= (struct pr_handle
*) p
;
1712 fprintf (info
->f
, "const double %s = %g;\n", name
, val
);
1716 /* Output a typed constant. */
1719 pr_typed_constant (void *p
, const char *name
, bfd_vma val
)
1721 struct pr_handle
*info
= (struct pr_handle
*) p
;
1725 t
= pop_type (info
);
1730 print_vma (val
, ab
, false, false);
1731 fprintf (info
->f
, "const %s %s = %s;\n", t
, name
, ab
);
1738 /* Output a variable. */
1741 pr_variable (void *p
, const char *name
, enum debug_var_kind kind
,
1744 struct pr_handle
*info
= (struct pr_handle
*) p
;
1748 if (! substitute_type (info
, name
))
1751 t
= pop_type (info
);
1759 case DEBUG_LOCAL_STATIC
:
1760 fprintf (info
->f
, "static ");
1762 case DEBUG_REGISTER
:
1763 fprintf (info
->f
, "register ");
1768 print_vma (val
, ab
, true, true);
1769 fprintf (info
->f
, "%s /* %s */;\n", t
, ab
);
1776 /* Start outputting a function. */
1779 pr_start_function (void *p
, const char *name
, bool global
)
1781 struct pr_handle
*info
= (struct pr_handle
*) p
;
1784 if (! substitute_type (info
, name
))
1787 t
= pop_type (info
);
1793 fprintf (info
->f
, "static ");
1794 fprintf (info
->f
, "%s (", t
);
1796 info
->parameter
= 1;
1801 /* Output a function parameter. */
1804 pr_function_parameter (void *p
, const char *name
,
1805 enum debug_parm_kind kind
, bfd_vma val
)
1807 struct pr_handle
*info
= (struct pr_handle
*) p
;
1811 if (kind
== DEBUG_PARM_REFERENCE
1812 || kind
== DEBUG_PARM_REF_REG
)
1814 if (! pr_reference_type (p
))
1818 if (! substitute_type (info
, name
))
1821 t
= pop_type (info
);
1825 if (info
->parameter
!= 1)
1826 fprintf (info
->f
, ", ");
1828 if (kind
== DEBUG_PARM_REG
|| kind
== DEBUG_PARM_REF_REG
)
1829 fprintf (info
->f
, "register ");
1831 print_vma (val
, ab
, true, true);
1832 fprintf (info
->f
, "%s /* %s */", t
, ab
);
1841 /* Start writing out a block. */
1844 pr_start_block (void *p
, bfd_vma addr
)
1846 struct pr_handle
*info
= (struct pr_handle
*) p
;
1849 if (info
->parameter
> 0)
1851 fprintf (info
->f
, ")\n");
1852 info
->parameter
= 0;
1856 print_vma (addr
, ab
, true, true);
1857 fprintf (info
->f
, "{ /* %s */\n", ab
);
1864 /* Write out line number information. */
1867 pr_lineno (void *p
, const char *filename
, unsigned long lineno
, bfd_vma addr
)
1869 struct pr_handle
*info
= (struct pr_handle
*) p
;
1873 print_vma (addr
, ab
, true, true);
1874 fprintf (info
->f
, "/* file %s line %lu addr %s */\n", filename
, lineno
, ab
);
1879 /* Finish writing out a block. */
1882 pr_end_block (void *p
, bfd_vma addr
)
1884 struct pr_handle
*info
= (struct pr_handle
*) p
;
1890 print_vma (addr
, ab
, true, true);
1891 fprintf (info
->f
, "} /* %s */\n", ab
);
1896 /* Finish writing out a function. */
1899 pr_end_function (void *p ATTRIBUTE_UNUSED
)
1904 /* Tags style generation functions start here. */
1906 /* Variables for address to line translation. */
1908 static const char *filename
;
1909 static const char *functionname
;
1910 static unsigned int line
;
1913 /* Look for an address in a section. This is called via
1914 bfd_map_over_sections. */
1917 find_address_in_section (bfd
*abfd
, asection
*section
, void *data
)
1921 asymbol
**syms
= (asymbol
**) data
;
1926 if ((bfd_section_flags (section
) & SEC_ALLOC
) == 0)
1929 vma
= bfd_section_vma (section
);
1933 size
= bfd_section_size (section
);
1934 if (pc
>= vma
+ size
)
1937 found
= bfd_find_nearest_line (abfd
, section
, syms
, pc
- vma
,
1938 &filename
, &functionname
, &line
);
1942 translate_addresses (bfd
*abfd
, char *addr_hex
, FILE *f
, asymbol
**syms
)
1944 pc
= bfd_scan_vma (addr_hex
, NULL
, 16);
1946 bfd_map_over_sections (abfd
, find_address_in_section
, syms
);
1951 fprintf (f
, "%u", line
);
1954 /* Start a new compilation unit. */
1957 tg_start_compilation_unit (void * p
, const char *fname ATTRIBUTE_UNUSED
)
1959 struct pr_handle
*info
= (struct pr_handle
*) p
;
1961 free (info
->filename
);
1962 /* Should it be relative? best way to do it here?. */
1963 info
->filename
= strdup (fname
);
1968 /* Start a source file within a compilation unit. */
1971 tg_start_source (void *p
, const char *fname
)
1973 struct pr_handle
*info
= (struct pr_handle
*) p
;
1975 free (info
->filename
);
1976 /* Should it be relative? best way to do it here?. */
1977 info
->filename
= strdup (fname
);
1982 /* Push an enum type onto the type stack. */
1985 tg_enum_type (void *p
, const char *tag
, const char **names
,
1986 bfd_signed_vma
*values
)
1988 struct pr_handle
*info
= (struct pr_handle
*) p
;
1993 if (! pr_enum_type (p
, tag
, names
, values
))
1996 name
= tag
? tag
: "unknown";
1997 /* Generate an entry for the enum. */
1999 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:e\ttype:%s\n", tag
,
2000 info
->filename
, info
->stack
->type
);
2002 /* Generate entries for the values. */
2005 for (i
= 0; names
[i
] != NULL
; i
++)
2007 print_vma (values
[i
], ab
, false, false);
2008 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:g\tenum:%s\tvalue:%s\n",
2009 names
[i
], info
->filename
, name
, ab
);
2016 /* Start accumulating a struct type. */
2019 tg_start_struct_type (void *p
, const char *tag
, unsigned int id
,
2021 unsigned int size ATTRIBUTE_UNUSED
)
2023 struct pr_handle
*info
= (struct pr_handle
*) p
;
2032 sprintf (idbuf
, "%%anon%u", id
);
2035 if (! push_type (info
, name
))
2038 info
->stack
->flavor
= structp
? "struct" : "union";
2040 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:%c\n", name
, info
->filename
,
2041 info
->stack
->flavor
[0]);
2043 info
->stack
->visibility
= DEBUG_VISIBILITY_PUBLIC
;
2045 return indent_type (info
);
2048 /* Output the visibility of a field in a struct. */
2051 tg_fix_visibility (struct pr_handle
*info
, enum debug_visibility visibility
)
2053 assert (info
->stack
!= NULL
);
2055 if (info
->stack
->visibility
== visibility
)
2058 assert (info
->stack
->visibility
!= DEBUG_VISIBILITY_IGNORE
);
2060 info
->stack
->visibility
= visibility
;
2065 /* Add a field to a struct type. */
2068 tg_struct_field (void *p
, const char *name
, bfd_vma bitpos ATTRIBUTE_UNUSED
,
2069 bfd_vma bitsize ATTRIBUTE_UNUSED
,
2070 enum debug_visibility visibility
)
2072 struct pr_handle
*info
= (struct pr_handle
*) p
;
2075 t
= pop_type (info
);
2079 if (! tg_fix_visibility (info
, visibility
))
2082 /* It happens, a bug? */
2086 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:m\ttype:%s\t%s:%s\taccess:%s\n",
2087 name
, info
->filename
, t
, info
->stack
->flavor
, info
->stack
->type
,
2088 visibility_name (visibility
));
2093 /* Finish a struct type. */
2096 tg_end_struct_type (void *p ATTRIBUTE_UNUSED
)
2098 assert (((struct pr_handle
*) p
)->stack
!= NULL
);
2103 /* Start a class type. */
2106 tg_start_class_type (void *p
, const char *tag
, unsigned int id
,
2107 bool structp
, unsigned int size
,
2108 bool vptr
, bool ownvptr
)
2110 struct pr_handle
*info
= (struct pr_handle
*) p
;
2117 if (vptr
&& ! ownvptr
)
2119 tv
= pop_type (info
);
2128 sprintf (idbuf
, "%%anon%u", id
);
2132 if (! push_type (info
, name
))
2135 info
->stack
->flavor
= structp
? "class" : "union class";
2136 info
->stack
->parents
= NULL
;
2137 info
->stack
->num_parents
= 0;
2139 if (size
!= 0 || vptr
|| ownvptr
|| tag
!= NULL
)
2143 if (! append_type (info
, " vtable "))
2147 if (! append_type (info
, "self "))
2152 if (! append_type (info
, tv
)
2153 || ! append_type (info
, " "))
2159 info
->stack
->visibility
= DEBUG_VISIBILITY_PRIVATE
;
2164 /* Add a static member to a class. */
2167 tg_class_static_member (void *p
, const char *name
,
2168 const char *physname ATTRIBUTE_UNUSED
,
2169 enum debug_visibility visibility
)
2171 struct pr_handle
*info
= (struct pr_handle
*) p
;
2173 int len_var
, len_class
;
2176 len_var
= strlen (name
);
2177 len_class
= strlen (info
->stack
->next
->type
);
2178 full_name
= (char *) xmalloc (len_var
+ len_class
+ 3);
2181 sprintf (full_name
, "%s::%s", info
->stack
->next
->type
, name
);
2183 if (! substitute_type (info
, full_name
))
2189 if (! prepend_type (info
, "static "))
2195 t
= pop_type (info
);
2202 if (! tg_fix_visibility (info
, visibility
))
2209 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:x\ttype:%s\tclass:%s\taccess:%s\n",
2210 name
, info
->filename
, t
, info
->stack
->type
,
2211 visibility_name (visibility
));
2218 /* Add a base class to a class. */
2221 tg_class_baseclass (void *p
, bfd_vma bitpos ATTRIBUTE_UNUSED
,
2222 bool is_virtual
, enum debug_visibility visibility
)
2224 struct pr_handle
*info
= (struct pr_handle
*) p
;
2228 assert (info
->stack
!= NULL
&& info
->stack
->next
!= NULL
);
2230 t
= pop_type (info
);
2234 if (startswith (t
, "class "))
2235 t
+= sizeof "class " - 1;
2237 /* Push it back on to take advantage of the prepend_type and
2238 append_type routines. */
2239 if (! push_type (info
, t
))
2244 if (! prepend_type (info
, "virtual "))
2250 case DEBUG_VISIBILITY_PUBLIC
:
2253 case DEBUG_VISIBILITY_PROTECTED
:
2254 prefix
= "protected ";
2256 case DEBUG_VISIBILITY_PRIVATE
:
2257 prefix
= "private ";
2260 prefix
= "/* unknown visibility */ ";
2264 if (! prepend_type (info
, prefix
))
2267 t
= pop_type (info
);
2271 if (info
->stack
->num_parents
&& ! append_parent (info
, ", "))
2274 if (! append_parent (info
, t
))
2276 info
->stack
->num_parents
++;
2283 /* Add a variant to a method. */
2286 tg_class_method_variant (void *p
, const char *physname ATTRIBUTE_UNUSED
,
2287 enum debug_visibility visibility
,
2288 bool constp
, bool volatilep
,
2289 bfd_vma voffset ATTRIBUTE_UNUSED
,
2292 struct pr_handle
*info
= (struct pr_handle
*) p
;
2297 assert (info
->stack
!= NULL
);
2298 assert (info
->stack
->next
!= NULL
);
2300 /* Put the const and volatile qualifiers on the type. */
2303 if (! append_type (info
, " volatile"))
2308 if (! append_type (info
, " const"))
2312 method_name
= strdup (context
? info
->stack
->next
->next
->method
2313 : info
->stack
->next
->method
);
2315 /* Stick the name of the method into its type. */
2316 if (! substitute_type (info
, method_name
))
2323 method_type
= pop_type (info
);
2324 if (method_type
== NULL
)
2330 /* Pull off the context type if there is one. */
2332 context_type
= NULL
;
2335 context_type
= pop_type (info
);
2336 if (context_type
== NULL
)
2344 /* Now the top of the stack is the class. */
2345 if (! tg_fix_visibility (info
, visibility
))
2349 free (context_type
);
2353 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:p\ttype:%s\tclass:%s\n",
2354 method_name
, info
->filename
, method_type
, info
->stack
->type
);
2357 free (context_type
);
2362 /* Add a static variant to a method. */
2365 tg_class_static_method_variant (void *p
,
2366 const char *physname ATTRIBUTE_UNUSED
,
2367 enum debug_visibility visibility
,
2368 bool constp
, bool volatilep
)
2370 struct pr_handle
*info
= (struct pr_handle
*) p
;
2374 assert (info
->stack
!= NULL
);
2375 assert (info
->stack
->next
!= NULL
);
2376 assert (info
->stack
->next
->method
!= NULL
);
2378 /* Put the const and volatile qualifiers on the type. */
2381 if (! append_type (info
, " volatile"))
2386 if (! append_type (info
, " const"))
2390 /* Mark it as static. */
2391 if (! prepend_type (info
, "static "))
2394 method_name
= strdup (info
->stack
->next
->method
);
2395 /* Stick the name of the method into its type. */
2396 if (! substitute_type (info
, info
->stack
->next
->method
))
2403 method_type
= pop_type (info
);
2404 if (method_type
== NULL
)
2410 /* Now the top of the stack is the class. */
2411 if (! tg_fix_visibility (info
, visibility
))
2418 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:p\ttype:%s\tclass:%s\taccess:%s\n",
2419 method_name
, info
->filename
, method_type
, info
->stack
->type
,
2420 visibility_name (visibility
));
2427 /* Finish up a class. */
2430 tg_end_class_type (void *p
)
2432 struct pr_handle
*info
= (struct pr_handle
*) p
;
2434 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:c\ttype:%s", info
->stack
->type
,
2435 info
->filename
, info
->stack
->flavor
);
2436 if (info
->stack
->num_parents
)
2438 fprintf (info
->f
, "\tinherits:%s", info
->stack
->parents
);
2439 free (info
->stack
->parents
);
2441 fputc ('\n', info
->f
);
2443 return tg_end_struct_type (p
);
2446 /* Push a type on the stack using a tag name. */
2449 tg_tag_type (void *p
, const char *name
, unsigned int id
,
2450 enum debug_type_kind kind
)
2452 struct pr_handle
*info
= (struct pr_handle
*) p
;
2453 const char *t
, *tag
;
2458 case DEBUG_KIND_STRUCT
:
2461 case DEBUG_KIND_UNION
:
2464 case DEBUG_KIND_ENUM
:
2467 case DEBUG_KIND_CLASS
:
2470 case DEBUG_KIND_UNION_CLASS
:
2478 if (! push_type (info
, t
))
2484 sprintf (idbuf
, "%%anon%u", id
);
2488 if (! append_type (info
, tag
))
2494 /* Output a typedef. */
2497 tg_typdef (void *p
, const char *name
)
2499 struct pr_handle
*info
= (struct pr_handle
*) p
;
2502 s
= pop_type (info
);
2506 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:t\ttype:%s\n", name
,
2514 /* Output a tag. The tag should already be in the string on the
2515 stack, so all we have to do here is print it out. */
2518 tg_tag (void *p ATTRIBUTE_UNUSED
, const char *name ATTRIBUTE_UNUSED
)
2520 struct pr_handle
*info
= (struct pr_handle
*) p
;
2523 t
= pop_type (info
);
2531 /* Output an integer constant. */
2534 tg_int_constant (void *p
, const char *name
, bfd_vma val
)
2536 struct pr_handle
*info
= (struct pr_handle
*) p
;
2540 print_vma (val
, ab
, false, false);
2541 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:v\ttype:const int\tvalue:%s\n",
2542 name
, info
->filename
, ab
);
2546 /* Output a floating point constant. */
2549 tg_float_constant (void *p
, const char *name
, double val
)
2551 struct pr_handle
*info
= (struct pr_handle
*) p
;
2554 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:v\ttype:const double\tvalue:%g\n",
2555 name
, info
->filename
, val
);
2559 /* Output a typed constant. */
2562 tg_typed_constant (void *p
, const char *name
, bfd_vma val
)
2564 struct pr_handle
*info
= (struct pr_handle
*) p
;
2568 t
= pop_type (info
);
2573 print_vma (val
, ab
, false, false);
2574 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:v\ttype:const %s\tvalue:%s\n",
2575 name
, info
->filename
, t
, ab
);
2582 /* Output a variable. */
2585 tg_variable (void *p
, const char *name
, enum debug_var_kind kind
,
2586 bfd_vma val ATTRIBUTE_UNUSED
)
2588 struct pr_handle
*info
= (struct pr_handle
*) p
;
2589 char *t
, *dname
, *from_class
;
2591 t
= pop_type (info
);
2596 if (info
->demangler
)
2597 dname
= info
->demangler (info
->abfd
, name
, demangle_flags
);
2603 sep
= strstr (dname
, "::");
2611 /* Obscure types as vts and type_info nodes. */
2615 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:v\ttype:%s", name
, info
->filename
, t
);
2620 case DEBUG_LOCAL_STATIC
:
2621 fprintf (info
->f
, "\tfile:");
2623 case DEBUG_REGISTER
:
2624 fprintf (info
->f
, "\tregister:");
2631 fprintf (info
->f
, "\tclass:%s", from_class
);
2636 fprintf (info
->f
, "\n");
2643 /* Start outputting a function. */
2646 tg_start_function (void *p
, const char *name
, bool global
)
2648 struct pr_handle
*info
= (struct pr_handle
*) p
;
2652 info
->stack
->flavor
= "static";
2654 info
->stack
->flavor
= NULL
;
2657 if (info
->demangler
)
2658 dname
= info
->demangler (info
->abfd
, name
, demangle_flags
);
2660 if (! substitute_type (info
, dname
? dname
: name
))
2663 info
->stack
->method
= NULL
;
2667 sep
= strstr (dname
, "::");
2670 info
->stack
->method
= dname
;
2676 info
->stack
->method
= "";
2679 sep
= strchr (name
, '(');
2682 /* Obscure functions as type_info function. */
2685 info
->stack
->parents
= strdup (name
);
2687 if (! info
->stack
->method
&& ! append_type (info
, "("))
2690 info
->parameter
= 1;
2695 /* Output a function parameter. */
2698 tg_function_parameter (void *p
, const char *name
, enum debug_parm_kind kind
,
2699 bfd_vma val ATTRIBUTE_UNUSED
)
2701 struct pr_handle
*info
= (struct pr_handle
*) p
;
2704 if (kind
== DEBUG_PARM_REFERENCE
2705 || kind
== DEBUG_PARM_REF_REG
)
2707 if (! pr_reference_type (p
))
2711 if (! substitute_type (info
, name
))
2714 t
= pop_type (info
);
2718 if (! info
->stack
->method
)
2720 if (info
->parameter
!= 1 && ! append_type (info
, ", "))
2723 if (kind
== DEBUG_PARM_REG
|| kind
== DEBUG_PARM_REF_REG
)
2724 if (! append_type (info
, "register "))
2727 if (! append_type (info
, t
))
2738 /* Start writing out a block. */
2741 tg_start_block (void *p
, bfd_vma addr
)
2743 struct pr_handle
*info
= (struct pr_handle
*) p
;
2744 char ab
[22], kind
, *partof
;
2748 if (info
->parameter
> 0)
2750 info
->parameter
= 0;
2753 fprintf (info
->f
, "%s\t%s\t", info
->stack
->parents
, info
->filename
);
2754 free (info
->stack
->parents
);
2756 print_vma (addr
, ab
, true, true);
2757 translate_addresses (info
->abfd
, ab
, info
->f
, info
->syms
);
2758 local
= info
->stack
->flavor
!= NULL
;
2759 if (info
->stack
->method
&& *info
->stack
->method
)
2762 partof
= (char *) info
->stack
->method
;
2768 if (! info
->stack
->method
&& ! append_type (info
, ")"))
2771 t
= pop_type (info
);
2774 fprintf (info
->f
, ";\"\tkind:%c\ttype:%s", kind
, t
);
2776 fputs ("\tfile:", info
->f
);
2779 fprintf (info
->f
, "\tclass:%s", partof
);
2782 fputc ('\n', info
->f
);
2788 /* Write out line number information. */
2791 tg_lineno (void *p ATTRIBUTE_UNUSED
, const char *fname ATTRIBUTE_UNUSED
,
2792 unsigned long lineno ATTRIBUTE_UNUSED
,
2793 bfd_vma addr ATTRIBUTE_UNUSED
)
2798 /* Finish writing out a block. */
2801 tg_end_block (void *p ATTRIBUTE_UNUSED
, bfd_vma addr ATTRIBUTE_UNUSED
)
2806 /* Convert the visibility value into a human readable name. */
2809 visibility_name (enum debug_visibility visibility
)
2815 case DEBUG_VISIBILITY_PUBLIC
:
2818 case DEBUG_VISIBILITY_PRIVATE
:
2821 case DEBUG_VISIBILITY_PROTECTED
:
2824 case DEBUG_VISIBILITY_IGNORE
: