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
)
489 sprintf (buf
, "%#" PRIx64
, (uint64_t) vma
);
491 sprintf (buf
, "%" PRIu64
, (uint64_t) vma
);
493 sprintf (buf
, "%" PRId64
, (int64_t) vma
);
496 /* Start a new compilation unit. */
499 pr_start_compilation_unit (void *p
, const char *filename
)
501 struct pr_handle
*info
= (struct pr_handle
*) p
;
503 assert (info
->indent
== 0);
505 fprintf (info
->f
, "%s:\n", filename
);
510 /* Start a source file within a compilation unit. */
513 pr_start_source (void *p
, const char *filename
)
515 struct pr_handle
*info
= (struct pr_handle
*) p
;
517 assert (info
->indent
== 0);
519 fprintf (info
->f
, " %s:\n", filename
);
524 /* Push an empty type onto the type stack. */
527 pr_empty_type (void *p
)
529 struct pr_handle
*info
= (struct pr_handle
*) p
;
531 return push_type (info
, "<undefined>");
534 /* Push a void type onto the type stack. */
537 pr_void_type (void *p
)
539 struct pr_handle
*info
= (struct pr_handle
*) p
;
541 return push_type (info
, "void");
544 /* Push an integer type onto the type stack. */
547 pr_int_type (void *p
, unsigned int size
, bool unsignedp
)
549 struct pr_handle
*info
= (struct pr_handle
*) p
;
552 sprintf (ab
, "%sint%d", unsignedp
? "u" : "", size
* 8);
553 return push_type (info
, ab
);
556 /* Push a floating type onto the type stack. */
559 pr_float_type (void *p
, unsigned int size
)
561 struct pr_handle
*info
= (struct pr_handle
*) p
;
565 return push_type (info
, "float");
567 return push_type (info
, "double");
569 sprintf (ab
, "float%d", size
* 8);
570 return push_type (info
, ab
);
573 /* Push a complex type onto the type stack. */
576 pr_complex_type (void *p
, unsigned int size
)
578 struct pr_handle
*info
= (struct pr_handle
*) p
;
580 if (! pr_float_type (p
, size
))
583 return prepend_type (info
, "complex ");
586 /* Push a bool type onto the type stack. */
589 pr_bool_type (void *p
, unsigned int size
)
591 struct pr_handle
*info
= (struct pr_handle
*) p
;
594 sprintf (ab
, "bool%d", size
* 8);
596 return push_type (info
, ab
);
599 /* Push an enum type onto the type stack. */
602 pr_enum_type (void *p
, const char *tag
, const char **names
,
603 bfd_signed_vma
*values
)
605 struct pr_handle
*info
= (struct pr_handle
*) p
;
609 if (! push_type (info
, "enum "))
613 if (! append_type (info
, tag
)
614 || ! append_type (info
, " "))
617 if (! append_type (info
, "{ "))
622 if (! append_type (info
, "/* undefined */"))
628 for (i
= 0; names
[i
] != NULL
; i
++)
632 if (! append_type (info
, ", "))
636 if (! append_type (info
, names
[i
]))
639 if (values
[i
] != val
)
643 print_vma (values
[i
], ab
, false, false);
644 if (! append_type (info
, " = ")
645 || ! append_type (info
, ab
))
654 return append_type (info
, " }");
657 /* Turn the top type on the stack into a pointer. */
660 pr_pointer_type (void *p
)
662 struct pr_handle
*info
= (struct pr_handle
*) p
;
665 assert (info
->stack
!= NULL
);
667 s
= strchr (info
->stack
->type
, '|');
668 if (s
!= NULL
&& s
[1] == '[')
669 return substitute_type (info
, "(*|)");
670 return substitute_type (info
, "*|");
673 /* Turn the top type on the stack into a function returning that type. */
676 pr_function_type (void *p
, int argcount
, bool varargs
)
678 struct pr_handle
*info
= (struct pr_handle
*) p
;
683 assert (info
->stack
!= NULL
);
696 arg_types
= (char **) xmalloc (argcount
* sizeof *arg_types
);
697 for (i
= argcount
- 1; i
>= 0; i
--)
699 if (! substitute_type (info
, ""))
704 arg_types
[i
] = pop_type (info
);
705 if (arg_types
[i
] == NULL
)
710 len
+= strlen (arg_types
[i
]) + 2;
716 /* Now the return type is on the top of the stack. */
718 s
= (char *) xmalloc (len
);
722 strcat (s
, "/* unknown */");
727 for (i
= 0; i
< argcount
; i
++)
731 strcat (s
, arg_types
[i
]);
745 bool ret
= substitute_type (info
, s
);
750 /* Turn the top type on the stack into a reference to that type. */
753 pr_reference_type (void *p
)
755 struct pr_handle
*info
= (struct pr_handle
*) p
;
757 assert (info
->stack
!= NULL
);
759 return substitute_type (info
, "&|");
762 /* Make a range type. */
765 pr_range_type (void *p
, bfd_signed_vma lower
, bfd_signed_vma upper
)
767 struct pr_handle
*info
= (struct pr_handle
*) p
;
768 char abl
[22], abu
[22];
770 assert (info
->stack
!= NULL
);
772 if (! substitute_type (info
, ""))
775 print_vma (lower
, abl
, false, false);
776 print_vma (upper
, abu
, false, false);
778 return (prepend_type (info
, "range (")
779 && append_type (info
, "):")
780 && append_type (info
, abl
)
781 && append_type (info
, ":")
782 && append_type (info
, abu
));
785 /* Make an array type. */
788 pr_array_type (void *p
, bfd_signed_vma lower
, bfd_signed_vma upper
,
791 struct pr_handle
*info
= (struct pr_handle
*) p
;
793 char abl
[22], abu
[22], ab
[50];
795 range_type
= pop_type (info
);
796 if (range_type
== NULL
)
805 print_vma (upper
+ 1, abu
, false, false);
806 sprintf (ab
, "|[%s]", abu
);
811 print_vma (lower
, abl
, false, false);
812 print_vma (upper
, abu
, false, false);
813 sprintf (ab
, "|[%s:%s]", abl
, abu
);
816 if (! substitute_type (info
, ab
))
819 if (strcmp (range_type
, "int") != 0)
821 if (! append_type (info
, ":")
822 || ! append_type (info
, range_type
))
828 if (! append_type (info
, " /* string */"))
835 /* Make a set type. */
838 pr_set_type (void *p
, bool bitstringp
)
840 struct pr_handle
*info
= (struct pr_handle
*) p
;
842 if (! substitute_type (info
, ""))
845 if (! prepend_type (info
, "set { ")
846 || ! append_type (info
, " }"))
851 if (! append_type (info
, "/* bitstring */"))
858 /* Make an offset type. */
861 pr_offset_type (void *p
)
863 struct pr_handle
*info
= (struct pr_handle
*) p
;
866 if (! substitute_type (info
, ""))
873 return (substitute_type (info
, "")
874 && prepend_type (info
, " ")
875 && prepend_type (info
, t
)
876 && append_type (info
, "::|"));
879 /* Make a method type. */
882 pr_method_type (void *p
, bool domain
, int argcount
, bool varargs
)
884 struct pr_handle
*info
= (struct pr_handle
*) p
;
896 if (! substitute_type (info
, ""))
898 domain_type
= pop_type (info
);
899 if (domain_type
== NULL
)
901 if (startswith (domain_type
, "class ")
902 && strchr (domain_type
+ sizeof "class " - 1, ' ') == NULL
)
903 domain_type
+= sizeof "class " - 1;
904 else if (startswith (domain_type
, "union class ")
905 && (strchr (domain_type
+ sizeof "union class " - 1, ' ')
907 domain_type
+= sizeof "union class " - 1;
908 len
+= strlen (domain_type
);
920 arg_types
= (char **) xmalloc (argcount
* sizeof *arg_types
);
921 for (i
= argcount
- 1; i
>= 0; i
--)
923 if (! substitute_type (info
, ""))
928 arg_types
[i
] = pop_type (info
);
929 if (arg_types
[i
] == NULL
)
934 len
+= strlen (arg_types
[i
]) + 2;
940 /* Now the return type is on the top of the stack. */
942 s
= (char *) xmalloc (len
);
946 strcpy (s
, domain_type
);
950 strcat (s
, "/* unknown */");
955 for (i
= 0; i
< argcount
; i
++)
959 strcat (s
, arg_types
[i
]);
973 if (! substitute_type (info
, s
))
981 /* Make a const qualified type. */
984 pr_const_type (void *p
)
986 struct pr_handle
*info
= (struct pr_handle
*) p
;
988 return substitute_type (info
, "const |");
991 /* Make a volatile qualified type. */
994 pr_volatile_type (void *p
)
996 struct pr_handle
*info
= (struct pr_handle
*) p
;
998 return substitute_type (info
, "volatile |");
1001 /* Start accumulating a struct type. */
1004 pr_start_struct_type (void *p
, const char *tag
, unsigned int id
,
1005 bool structp
, unsigned int size
)
1007 struct pr_handle
*info
= (struct pr_handle
*) p
;
1011 if (! push_type (info
, structp
? "struct " : "union "))
1015 if (! append_type (info
, tag
))
1022 sprintf (idbuf
, "%%anon%u", id
);
1023 if (! append_type (info
, idbuf
))
1027 if (! append_type (info
, " {"))
1029 if (size
!= 0 || tag
!= NULL
)
1033 if (! append_type (info
, " /*"))
1038 sprintf (ab
, " size %u", size
);
1039 if (! append_type (info
, ab
))
1044 sprintf (ab
, " id %u", id
);
1045 if (! append_type (info
, ab
))
1048 if (! append_type (info
, " */"))
1051 if (! append_type (info
, "\n"))
1054 info
->stack
->visibility
= DEBUG_VISIBILITY_PUBLIC
;
1056 return indent_type (info
);
1059 /* Output the visibility of a field in a struct. */
1062 pr_fix_visibility (struct pr_handle
*info
, enum debug_visibility visibility
)
1064 const char *s
= NULL
;
1068 assert (info
->stack
!= NULL
);
1070 if (info
->stack
->visibility
== visibility
)
1075 case DEBUG_VISIBILITY_PUBLIC
:
1078 case DEBUG_VISIBILITY_PRIVATE
:
1081 case DEBUG_VISIBILITY_PROTECTED
:
1084 case DEBUG_VISIBILITY_IGNORE
:
1092 /* Trim off a trailing space in the struct string, to make the
1093 output look a bit better, then stick on the visibility string. */
1095 t
= info
->stack
->type
;
1097 assert (t
[len
- 1] == ' ');
1100 if (! append_type (info
, s
)
1101 || ! append_type (info
, ":\n")
1102 || ! indent_type (info
))
1105 info
->stack
->visibility
= visibility
;
1110 /* Add a field to a struct type. */
1113 pr_struct_field (void *p
, const char *name
, bfd_vma bitpos
, bfd_vma bitsize
,
1114 enum debug_visibility visibility
)
1116 struct pr_handle
*info
= (struct pr_handle
*) p
;
1120 if (! substitute_type (info
, name
))
1123 if (! append_type (info
, "; /* "))
1128 print_vma (bitsize
, ab
, true, false);
1129 if (! append_type (info
, "bitsize ")
1130 || ! append_type (info
, ab
)
1131 || ! append_type (info
, ", "))
1135 print_vma (bitpos
, ab
, true, false);
1136 if (! append_type (info
, "bitpos ")
1137 || ! append_type (info
, ab
)
1138 || ! append_type (info
, " */\n")
1139 || ! indent_type (info
))
1142 t
= pop_type (info
);
1146 if (! pr_fix_visibility (info
, visibility
))
1149 return append_type (info
, t
);
1152 /* Finish a struct type. */
1155 pr_end_struct_type (void *p
)
1157 struct pr_handle
*info
= (struct pr_handle
*) p
;
1160 assert (info
->stack
!= NULL
);
1161 assert (info
->indent
>= 2);
1165 /* Change the trailing indentation to have a close brace. */
1166 s
= info
->stack
->type
+ strlen (info
->stack
->type
) - 2;
1167 assert (s
[0] == ' ' && s
[1] == ' ' && s
[2] == '\0');
1175 /* Start a class type. */
1178 pr_start_class_type (void *p
, const char *tag
, unsigned int id
,
1179 bool structp
, unsigned int size
,
1180 bool vptr
, bool ownvptr
)
1182 struct pr_handle
*info
= (struct pr_handle
*) p
;
1187 if (vptr
&& ! ownvptr
)
1189 tv
= pop_type (info
);
1194 if (! push_type (info
, structp
? "class " : "union class "))
1198 if (! append_type (info
, tag
))
1205 sprintf (idbuf
, "%%anon%u", id
);
1206 if (! append_type (info
, idbuf
))
1210 if (! append_type (info
, " {"))
1212 if (size
!= 0 || vptr
|| ownvptr
|| tag
!= NULL
)
1214 if (! append_type (info
, " /*"))
1221 sprintf (ab
, "%u", size
);
1222 if (! append_type (info
, " size ")
1223 || ! append_type (info
, ab
))
1229 if (! append_type (info
, " vtable "))
1233 if (! append_type (info
, "self "))
1238 if (! append_type (info
, tv
)
1239 || ! append_type (info
, " "))
1248 sprintf (ab
, " id %u", id
);
1249 if (! append_type (info
, ab
))
1253 if (! append_type (info
, " */"))
1257 info
->stack
->visibility
= DEBUG_VISIBILITY_PRIVATE
;
1259 return (append_type (info
, "\n")
1260 && indent_type (info
));
1263 /* Add a static member to a class. */
1266 pr_class_static_member (void *p
, const char *name
, const char *physname
,
1267 enum debug_visibility visibility
)
1269 struct pr_handle
*info
= (struct pr_handle
*) p
;
1272 if (! substitute_type (info
, name
))
1275 if (! prepend_type (info
, "static ")
1276 || ! append_type (info
, "; /* ")
1277 || ! append_type (info
, physname
)
1278 || ! append_type (info
, " */\n")
1279 || ! indent_type (info
))
1282 t
= pop_type (info
);
1286 if (! pr_fix_visibility (info
, visibility
))
1289 return append_type (info
, t
);
1292 /* Add a base class to a class. */
1295 pr_class_baseclass (void *p
, bfd_vma bitpos
, bool is_virtual
,
1296 enum debug_visibility visibility
)
1298 struct pr_handle
*info
= (struct pr_handle
*) p
;
1304 assert (info
->stack
!= NULL
&& info
->stack
->next
!= NULL
);
1306 if (! substitute_type (info
, ""))
1309 t
= pop_type (info
);
1313 if (startswith (t
, "class "))
1314 t
+= sizeof "class " - 1;
1316 /* Push it back on to take advantage of the prepend_type and
1317 append_type routines. */
1318 if (! push_type (info
, t
))
1323 if (! prepend_type (info
, "virtual "))
1329 case DEBUG_VISIBILITY_PUBLIC
:
1332 case DEBUG_VISIBILITY_PROTECTED
:
1333 prefix
= "protected ";
1335 case DEBUG_VISIBILITY_PRIVATE
:
1336 prefix
= "private ";
1339 prefix
= "/* unknown visibility */ ";
1343 if (! prepend_type (info
, prefix
))
1348 print_vma (bitpos
, ab
, true, false);
1349 if (! append_type (info
, " /* bitpos ")
1350 || ! append_type (info
, ab
)
1351 || ! append_type (info
, " */"))
1355 /* Now the top of the stack is something like "public A / * bitpos
1356 10 * /". The next element on the stack is something like "class
1357 xx { / * size 8 * /\n...". We want to substitute the top of the
1358 stack in before the {. */
1359 s
= strchr (info
->stack
->next
->type
, '{');
1363 /* If there is already a ':', then we already have a baseclass, and
1364 we must append this one after a comma. */
1365 for (l
= info
->stack
->next
->type
; l
!= s
; l
++)
1368 if (! prepend_type (info
, l
== s
? " : " : ", "))
1371 t
= pop_type (info
);
1375 n
= (char *) xmalloc (strlen (info
->stack
->type
) + strlen (t
) + 1);
1376 memcpy (n
, info
->stack
->type
, s
- info
->stack
->type
);
1377 strcpy (n
+ (s
- info
->stack
->type
), t
);
1380 free (info
->stack
->type
);
1381 info
->stack
->type
= n
;
1388 /* Start adding a method to a class. */
1391 pr_class_start_method (void *p
, const char *name
)
1393 struct pr_handle
*info
= (struct pr_handle
*) p
;
1395 assert (info
->stack
!= NULL
);
1396 info
->stack
->method
= name
;
1400 /* Add a variant to a method. */
1403 pr_class_method_variant (void *p
, const char *physname
,
1404 enum debug_visibility visibility
,
1405 bool constp
, bool volatilep
,
1406 bfd_vma voffset
, bool context
)
1408 struct pr_handle
*info
= (struct pr_handle
*) p
;
1412 assert (info
->stack
!= NULL
);
1413 assert (info
->stack
->next
!= NULL
);
1415 /* Put the const and volatile qualifiers on the type. */
1418 if (! append_type (info
, " volatile"))
1423 if (! append_type (info
, " const"))
1427 /* Stick the name of the method into its type. */
1428 if (! substitute_type (info
,
1430 ? info
->stack
->next
->next
->method
1431 : info
->stack
->next
->method
)))
1435 method_type
= pop_type (info
);
1436 if (method_type
== NULL
)
1439 /* Pull off the context type if there is one. */
1441 context_type
= NULL
;
1444 context_type
= pop_type (info
);
1445 if (context_type
== NULL
)
1449 /* Now the top of the stack is the class. */
1451 if (! pr_fix_visibility (info
, visibility
))
1454 if (! append_type (info
, method_type
)
1455 || ! append_type (info
, " /* ")
1456 || ! append_type (info
, physname
)
1457 || ! append_type (info
, " "))
1459 if (context
|| voffset
!= 0)
1465 if (! append_type (info
, "context ")
1466 || ! append_type (info
, context_type
)
1467 || ! append_type (info
, " "))
1470 print_vma (voffset
, ab
, true, false);
1471 if (! append_type (info
, "voffset ")
1472 || ! append_type (info
, ab
))
1476 return (append_type (info
, " */;\n")
1477 && indent_type (info
));
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 if (! pr_fix_visibility (info
, visibility
))
1524 return (append_type (info
, method_type
)
1525 && append_type (info
, " /* ")
1526 && append_type (info
, physname
)
1527 && append_type (info
, " */;\n")
1528 && 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 info
->stack
->method
= NULL
;
1542 /* Finish up a class. */
1545 pr_end_class_type (void *p
)
1547 return pr_end_struct_type (p
);
1550 /* Push a type on the stack using a typedef name. */
1553 pr_typedef_type (void *p
, const char *name
)
1555 struct pr_handle
*info
= (struct pr_handle
*) p
;
1557 return push_type (info
, name
);
1560 /* Push a type on the stack using a tag name. */
1563 pr_tag_type (void *p
, const char *name
, unsigned int id
,
1564 enum debug_type_kind kind
)
1566 struct pr_handle
*info
= (struct pr_handle
*) p
;
1567 const char *t
, *tag
;
1572 case DEBUG_KIND_STRUCT
:
1575 case DEBUG_KIND_UNION
:
1578 case DEBUG_KIND_ENUM
:
1581 case DEBUG_KIND_CLASS
:
1584 case DEBUG_KIND_UNION_CLASS
:
1588 /* PR 25625: Corrupt input can trigger this case. */
1592 if (! push_type (info
, t
))
1598 sprintf (idbuf
, "%%anon%u", id
);
1602 if (! append_type (info
, tag
))
1604 if (name
!= NULL
&& kind
!= DEBUG_KIND_ENUM
)
1606 sprintf (idbuf
, " /* id %u */", id
);
1607 if (! append_type (info
, idbuf
))
1614 /* Output a typedef. */
1617 pr_typdef (void *p
, const char *name
)
1619 struct pr_handle
*info
= (struct pr_handle
*) p
;
1622 if (! substitute_type (info
, name
))
1625 s
= pop_type (info
);
1630 fprintf (info
->f
, "typedef %s;\n", s
);
1637 /* Output a tag. The tag should already be in the string on the
1638 stack, so all we have to do here is print it out. */
1641 pr_tag (void *p
, const char *name ATTRIBUTE_UNUSED
)
1643 struct pr_handle
*info
= (struct pr_handle
*) p
;
1646 t
= pop_type (info
);
1651 fprintf (info
->f
, "%s;\n", t
);
1658 /* Output an integer constant. */
1661 pr_int_constant (void *p
, const char *name
, bfd_vma val
)
1663 struct pr_handle
*info
= (struct pr_handle
*) p
;
1667 print_vma (val
, ab
, false, false);
1668 fprintf (info
->f
, "const int %s = %s;\n", name
, ab
);
1672 /* Output a floating point constant. */
1675 pr_float_constant (void *p
, const char *name
, double val
)
1677 struct pr_handle
*info
= (struct pr_handle
*) p
;
1680 fprintf (info
->f
, "const double %s = %g;\n", name
, val
);
1684 /* Output a typed constant. */
1687 pr_typed_constant (void *p
, const char *name
, bfd_vma val
)
1689 struct pr_handle
*info
= (struct pr_handle
*) p
;
1693 t
= pop_type (info
);
1698 print_vma (val
, ab
, false, false);
1699 fprintf (info
->f
, "const %s %s = %s;\n", t
, name
, ab
);
1706 /* Output a variable. */
1709 pr_variable (void *p
, const char *name
, enum debug_var_kind kind
,
1712 struct pr_handle
*info
= (struct pr_handle
*) p
;
1716 if (! substitute_type (info
, name
))
1719 t
= pop_type (info
);
1727 case DEBUG_LOCAL_STATIC
:
1728 fprintf (info
->f
, "static ");
1730 case DEBUG_REGISTER
:
1731 fprintf (info
->f
, "register ");
1736 print_vma (val
, ab
, true, true);
1737 fprintf (info
->f
, "%s /* %s */;\n", t
, ab
);
1744 /* Start outputting a function. */
1747 pr_start_function (void *p
, const char *name
, bool global
)
1749 struct pr_handle
*info
= (struct pr_handle
*) p
;
1752 if (! substitute_type (info
, name
))
1755 t
= pop_type (info
);
1761 fprintf (info
->f
, "static ");
1762 fprintf (info
->f
, "%s (", t
);
1764 info
->parameter
= 1;
1769 /* Output a function parameter. */
1772 pr_function_parameter (void *p
, const char *name
,
1773 enum debug_parm_kind kind
, bfd_vma val
)
1775 struct pr_handle
*info
= (struct pr_handle
*) p
;
1779 if (kind
== DEBUG_PARM_REFERENCE
1780 || kind
== DEBUG_PARM_REF_REG
)
1782 if (! pr_reference_type (p
))
1786 if (! substitute_type (info
, name
))
1789 t
= pop_type (info
);
1793 if (info
->parameter
!= 1)
1794 fprintf (info
->f
, ", ");
1796 if (kind
== DEBUG_PARM_REG
|| kind
== DEBUG_PARM_REF_REG
)
1797 fprintf (info
->f
, "register ");
1799 print_vma (val
, ab
, true, true);
1800 fprintf (info
->f
, "%s /* %s */", t
, ab
);
1809 /* Start writing out a block. */
1812 pr_start_block (void *p
, bfd_vma addr
)
1814 struct pr_handle
*info
= (struct pr_handle
*) p
;
1817 if (info
->parameter
> 0)
1819 fprintf (info
->f
, ")\n");
1820 info
->parameter
= 0;
1824 print_vma (addr
, ab
, true, true);
1825 fprintf (info
->f
, "{ /* %s */\n", ab
);
1832 /* Write out line number information. */
1835 pr_lineno (void *p
, const char *filename
, unsigned long lineno
, bfd_vma addr
)
1837 struct pr_handle
*info
= (struct pr_handle
*) p
;
1841 print_vma (addr
, ab
, true, true);
1842 fprintf (info
->f
, "/* file %s line %lu addr %s */\n", filename
, lineno
, ab
);
1847 /* Finish writing out a block. */
1850 pr_end_block (void *p
, bfd_vma addr
)
1852 struct pr_handle
*info
= (struct pr_handle
*) p
;
1858 print_vma (addr
, ab
, true, true);
1859 fprintf (info
->f
, "} /* %s */\n", ab
);
1864 /* Finish writing out a function. */
1867 pr_end_function (void *p ATTRIBUTE_UNUSED
)
1872 /* Tags style generation functions start here. */
1874 /* Variables for address to line translation. */
1876 static const char *filename
;
1877 static const char *functionname
;
1878 static unsigned int line
;
1881 /* Look for an address in a section. This is called via
1882 bfd_map_over_sections. */
1885 find_address_in_section (bfd
*abfd
, asection
*section
, void *data
)
1889 asymbol
**syms
= (asymbol
**) data
;
1894 if ((bfd_section_flags (section
) & SEC_ALLOC
) == 0)
1897 vma
= bfd_section_vma (section
);
1901 size
= bfd_section_size (section
);
1902 if (pc
>= vma
+ size
)
1905 found
= bfd_find_nearest_line (abfd
, section
, syms
, pc
- vma
,
1906 &filename
, &functionname
, &line
);
1910 translate_addresses (bfd
*abfd
, char *addr_hex
, FILE *f
, asymbol
**syms
)
1912 pc
= bfd_scan_vma (addr_hex
, NULL
, 16);
1914 bfd_map_over_sections (abfd
, find_address_in_section
, syms
);
1919 fprintf (f
, "%u", line
);
1922 /* Start a new compilation unit. */
1925 tg_start_compilation_unit (void * p
, const char *fname ATTRIBUTE_UNUSED
)
1927 struct pr_handle
*info
= (struct pr_handle
*) p
;
1929 free (info
->filename
);
1930 /* Should it be relative? best way to do it here?. */
1931 info
->filename
= strdup (fname
);
1936 /* Start a source file within a compilation unit. */
1939 tg_start_source (void *p
, const char *fname
)
1941 struct pr_handle
*info
= (struct pr_handle
*) p
;
1943 free (info
->filename
);
1944 /* Should it be relative? best way to do it here?. */
1945 info
->filename
= strdup (fname
);
1950 /* Push an enum type onto the type stack. */
1953 tg_enum_type (void *p
, const char *tag
, const char **names
,
1954 bfd_signed_vma
*values
)
1956 struct pr_handle
*info
= (struct pr_handle
*) p
;
1961 if (! pr_enum_type (p
, tag
, names
, values
))
1964 name
= tag
? tag
: "unknown";
1965 /* Generate an entry for the enum. */
1967 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:e\ttype:%s\n", tag
,
1968 info
->filename
, info
->stack
->type
);
1970 /* Generate entries for the values. */
1973 for (i
= 0; names
[i
] != NULL
; i
++)
1975 print_vma (values
[i
], ab
, false, false);
1976 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:g\tenum:%s\tvalue:%s\n",
1977 names
[i
], info
->filename
, name
, ab
);
1984 /* Start accumulating a struct type. */
1987 tg_start_struct_type (void *p
, const char *tag
, unsigned int id
,
1989 unsigned int size ATTRIBUTE_UNUSED
)
1991 struct pr_handle
*info
= (struct pr_handle
*) p
;
2000 sprintf (idbuf
, "%%anon%u", id
);
2003 if (! push_type (info
, name
))
2006 info
->stack
->flavor
= structp
? "struct" : "union";
2008 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:%c\n", name
, info
->filename
,
2009 info
->stack
->flavor
[0]);
2011 info
->stack
->visibility
= DEBUG_VISIBILITY_PUBLIC
;
2013 return indent_type (info
);
2016 /* Output the visibility of a field in a struct. */
2019 tg_fix_visibility (struct pr_handle
*info
, enum debug_visibility visibility
)
2021 assert (info
->stack
!= NULL
);
2023 if (info
->stack
->visibility
== visibility
)
2026 assert (info
->stack
->visibility
!= DEBUG_VISIBILITY_IGNORE
);
2028 info
->stack
->visibility
= visibility
;
2033 /* Add a field to a struct type. */
2036 tg_struct_field (void *p
, const char *name
, bfd_vma bitpos ATTRIBUTE_UNUSED
,
2037 bfd_vma bitsize ATTRIBUTE_UNUSED
,
2038 enum debug_visibility visibility
)
2040 struct pr_handle
*info
= (struct pr_handle
*) p
;
2043 t
= pop_type (info
);
2047 if (! tg_fix_visibility (info
, visibility
))
2050 /* It happens, a bug? */
2054 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:m\ttype:%s\t%s:%s\taccess:%s\n",
2055 name
, info
->filename
, t
, info
->stack
->flavor
, info
->stack
->type
,
2056 visibility_name (visibility
));
2061 /* Finish a struct type. */
2064 tg_end_struct_type (void *p ATTRIBUTE_UNUSED
)
2066 assert (((struct pr_handle
*) p
)->stack
!= NULL
);
2071 /* Start a class type. */
2074 tg_start_class_type (void *p
, const char *tag
, unsigned int id
,
2075 bool structp
, unsigned int size
,
2076 bool vptr
, bool ownvptr
)
2078 struct pr_handle
*info
= (struct pr_handle
*) p
;
2085 if (vptr
&& ! ownvptr
)
2087 tv
= pop_type (info
);
2096 sprintf (idbuf
, "%%anon%u", id
);
2100 if (! push_type (info
, name
))
2103 info
->stack
->flavor
= structp
? "class" : "union class";
2104 info
->stack
->parents
= NULL
;
2105 info
->stack
->num_parents
= 0;
2107 if (size
!= 0 || vptr
|| ownvptr
|| tag
!= NULL
)
2111 if (! append_type (info
, " vtable "))
2115 if (! append_type (info
, "self "))
2120 if (! append_type (info
, tv
)
2121 || ! append_type (info
, " "))
2127 info
->stack
->visibility
= DEBUG_VISIBILITY_PRIVATE
;
2132 /* Add a static member to a class. */
2135 tg_class_static_member (void *p
, const char *name
,
2136 const char *physname ATTRIBUTE_UNUSED
,
2137 enum debug_visibility visibility
)
2139 struct pr_handle
*info
= (struct pr_handle
*) p
;
2141 int len_var
, len_class
;
2144 len_var
= strlen (name
);
2145 len_class
= strlen (info
->stack
->next
->type
);
2146 full_name
= (char *) xmalloc (len_var
+ len_class
+ 3);
2149 sprintf (full_name
, "%s::%s", info
->stack
->next
->type
, name
);
2151 if (! substitute_type (info
, full_name
))
2157 if (! prepend_type (info
, "static "))
2163 t
= pop_type (info
);
2170 if (! tg_fix_visibility (info
, visibility
))
2177 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:x\ttype:%s\tclass:%s\taccess:%s\n",
2178 name
, info
->filename
, t
, info
->stack
->type
,
2179 visibility_name (visibility
));
2186 /* Add a base class to a class. */
2189 tg_class_baseclass (void *p
, bfd_vma bitpos ATTRIBUTE_UNUSED
,
2190 bool is_virtual
, enum debug_visibility visibility
)
2192 struct pr_handle
*info
= (struct pr_handle
*) p
;
2196 assert (info
->stack
!= NULL
&& info
->stack
->next
!= NULL
);
2198 t
= pop_type (info
);
2202 if (startswith (t
, "class "))
2203 t
+= sizeof "class " - 1;
2205 /* Push it back on to take advantage of the prepend_type and
2206 append_type routines. */
2207 if (! push_type (info
, t
))
2212 if (! prepend_type (info
, "virtual "))
2218 case DEBUG_VISIBILITY_PUBLIC
:
2221 case DEBUG_VISIBILITY_PROTECTED
:
2222 prefix
= "protected ";
2224 case DEBUG_VISIBILITY_PRIVATE
:
2225 prefix
= "private ";
2228 prefix
= "/* unknown visibility */ ";
2232 if (! prepend_type (info
, prefix
))
2235 t
= pop_type (info
);
2239 if (info
->stack
->num_parents
&& ! append_parent (info
, ", "))
2242 if (! append_parent (info
, t
))
2244 info
->stack
->num_parents
++;
2251 /* Add a variant to a method. */
2254 tg_class_method_variant (void *p
, const char *physname ATTRIBUTE_UNUSED
,
2255 enum debug_visibility visibility
,
2256 bool constp
, bool volatilep
,
2257 bfd_vma voffset ATTRIBUTE_UNUSED
,
2260 struct pr_handle
*info
= (struct pr_handle
*) p
;
2265 assert (info
->stack
!= NULL
);
2266 assert (info
->stack
->next
!= NULL
);
2268 /* Put the const and volatile qualifiers on the type. */
2271 if (! append_type (info
, " volatile"))
2276 if (! append_type (info
, " const"))
2280 method_name
= strdup (context
? info
->stack
->next
->next
->method
2281 : info
->stack
->next
->method
);
2283 /* Stick the name of the method into its type. */
2284 if (! substitute_type (info
, method_name
))
2291 method_type
= pop_type (info
);
2292 if (method_type
== NULL
)
2298 /* Pull off the context type if there is one. */
2300 context_type
= NULL
;
2303 context_type
= pop_type (info
);
2304 if (context_type
== NULL
)
2312 /* Now the top of the stack is the class. */
2313 if (! tg_fix_visibility (info
, visibility
))
2317 free (context_type
);
2321 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:p\ttype:%s\tclass:%s\n",
2322 method_name
, info
->filename
, method_type
, info
->stack
->type
);
2325 free (context_type
);
2330 /* Add a static variant to a method. */
2333 tg_class_static_method_variant (void *p
,
2334 const char *physname ATTRIBUTE_UNUSED
,
2335 enum debug_visibility visibility
,
2336 bool constp
, bool volatilep
)
2338 struct pr_handle
*info
= (struct pr_handle
*) p
;
2342 assert (info
->stack
!= NULL
);
2343 assert (info
->stack
->next
!= NULL
);
2344 assert (info
->stack
->next
->method
!= NULL
);
2346 /* Put the const and volatile qualifiers on the type. */
2349 if (! append_type (info
, " volatile"))
2354 if (! append_type (info
, " const"))
2358 /* Mark it as static. */
2359 if (! prepend_type (info
, "static "))
2362 method_name
= strdup (info
->stack
->next
->method
);
2363 /* Stick the name of the method into its type. */
2364 if (! substitute_type (info
, info
->stack
->next
->method
))
2371 method_type
= pop_type (info
);
2372 if (method_type
== NULL
)
2378 /* Now the top of the stack is the class. */
2379 if (! tg_fix_visibility (info
, visibility
))
2386 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:p\ttype:%s\tclass:%s\taccess:%s\n",
2387 method_name
, info
->filename
, method_type
, info
->stack
->type
,
2388 visibility_name (visibility
));
2395 /* Finish up a class. */
2398 tg_end_class_type (void *p
)
2400 struct pr_handle
*info
= (struct pr_handle
*) p
;
2402 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:c\ttype:%s", info
->stack
->type
,
2403 info
->filename
, info
->stack
->flavor
);
2404 if (info
->stack
->num_parents
)
2406 fprintf (info
->f
, "\tinherits:%s", info
->stack
->parents
);
2407 free (info
->stack
->parents
);
2409 fputc ('\n', info
->f
);
2411 return tg_end_struct_type (p
);
2414 /* Push a type on the stack using a tag name. */
2417 tg_tag_type (void *p
, const char *name
, unsigned int id
,
2418 enum debug_type_kind kind
)
2420 struct pr_handle
*info
= (struct pr_handle
*) p
;
2421 const char *t
, *tag
;
2426 case DEBUG_KIND_STRUCT
:
2429 case DEBUG_KIND_UNION
:
2432 case DEBUG_KIND_ENUM
:
2435 case DEBUG_KIND_CLASS
:
2438 case DEBUG_KIND_UNION_CLASS
:
2446 if (! push_type (info
, t
))
2452 sprintf (idbuf
, "%%anon%u", id
);
2456 if (! append_type (info
, tag
))
2462 /* Output a typedef. */
2465 tg_typdef (void *p
, const char *name
)
2467 struct pr_handle
*info
= (struct pr_handle
*) p
;
2470 s
= pop_type (info
);
2474 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:t\ttype:%s\n", name
,
2482 /* Output a tag. The tag should already be in the string on the
2483 stack, so all we have to do here is print it out. */
2486 tg_tag (void *p ATTRIBUTE_UNUSED
, const char *name ATTRIBUTE_UNUSED
)
2488 struct pr_handle
*info
= (struct pr_handle
*) p
;
2491 t
= pop_type (info
);
2499 /* Output an integer constant. */
2502 tg_int_constant (void *p
, const char *name
, bfd_vma val
)
2504 struct pr_handle
*info
= (struct pr_handle
*) p
;
2508 print_vma (val
, ab
, false, false);
2509 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:v\ttype:const int\tvalue:%s\n",
2510 name
, info
->filename
, ab
);
2514 /* Output a floating point constant. */
2517 tg_float_constant (void *p
, const char *name
, double val
)
2519 struct pr_handle
*info
= (struct pr_handle
*) p
;
2522 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:v\ttype:const double\tvalue:%g\n",
2523 name
, info
->filename
, val
);
2527 /* Output a typed constant. */
2530 tg_typed_constant (void *p
, const char *name
, bfd_vma val
)
2532 struct pr_handle
*info
= (struct pr_handle
*) p
;
2536 t
= pop_type (info
);
2541 print_vma (val
, ab
, false, false);
2542 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:v\ttype:const %s\tvalue:%s\n",
2543 name
, info
->filename
, t
, ab
);
2550 /* Output a variable. */
2553 tg_variable (void *p
, const char *name
, enum debug_var_kind kind
,
2554 bfd_vma val ATTRIBUTE_UNUSED
)
2556 struct pr_handle
*info
= (struct pr_handle
*) p
;
2557 char *t
, *dname
, *from_class
;
2559 t
= pop_type (info
);
2564 if (info
->demangler
)
2565 dname
= info
->demangler (info
->abfd
, name
, demangle_flags
);
2571 sep
= strstr (dname
, "::");
2579 /* Obscure types as vts and type_info nodes. */
2583 fprintf (info
->f
, "%s\t%s\t0;\"\tkind:v\ttype:%s", name
, info
->filename
, t
);
2588 case DEBUG_LOCAL_STATIC
:
2589 fprintf (info
->f
, "\tfile:");
2591 case DEBUG_REGISTER
:
2592 fprintf (info
->f
, "\tregister:");
2599 fprintf (info
->f
, "\tclass:%s", from_class
);
2604 fprintf (info
->f
, "\n");
2611 /* Start outputting a function. */
2614 tg_start_function (void *p
, const char *name
, bool global
)
2616 struct pr_handle
*info
= (struct pr_handle
*) p
;
2620 info
->stack
->flavor
= "static";
2622 info
->stack
->flavor
= NULL
;
2625 if (info
->demangler
)
2626 dname
= info
->demangler (info
->abfd
, name
, demangle_flags
);
2628 if (! substitute_type (info
, dname
? dname
: name
))
2631 info
->stack
->method
= NULL
;
2635 sep
= strstr (dname
, "::");
2638 info
->stack
->method
= dname
;
2644 info
->stack
->method
= "";
2647 sep
= strchr (name
, '(');
2650 /* Obscure functions as type_info function. */
2653 info
->stack
->parents
= strdup (name
);
2655 if (! info
->stack
->method
&& ! append_type (info
, "("))
2658 info
->parameter
= 1;
2663 /* Output a function parameter. */
2666 tg_function_parameter (void *p
, const char *name
, enum debug_parm_kind kind
,
2667 bfd_vma val ATTRIBUTE_UNUSED
)
2669 struct pr_handle
*info
= (struct pr_handle
*) p
;
2672 if (kind
== DEBUG_PARM_REFERENCE
2673 || kind
== DEBUG_PARM_REF_REG
)
2675 if (! pr_reference_type (p
))
2679 if (! substitute_type (info
, name
))
2682 t
= pop_type (info
);
2686 if (! info
->stack
->method
)
2688 if (info
->parameter
!= 1 && ! append_type (info
, ", "))
2691 if (kind
== DEBUG_PARM_REG
|| kind
== DEBUG_PARM_REF_REG
)
2692 if (! append_type (info
, "register "))
2695 if (! append_type (info
, t
))
2706 /* Start writing out a block. */
2709 tg_start_block (void *p
, bfd_vma addr
)
2711 struct pr_handle
*info
= (struct pr_handle
*) p
;
2712 char ab
[22], kind
, *partof
;
2716 if (info
->parameter
> 0)
2718 info
->parameter
= 0;
2721 fprintf (info
->f
, "%s\t%s\t", info
->stack
->parents
, info
->filename
);
2722 free (info
->stack
->parents
);
2724 print_vma (addr
, ab
, true, true);
2725 translate_addresses (info
->abfd
, ab
, info
->f
, info
->syms
);
2726 local
= info
->stack
->flavor
!= NULL
;
2727 if (info
->stack
->method
&& *info
->stack
->method
)
2730 partof
= (char *) info
->stack
->method
;
2736 if (! info
->stack
->method
&& ! append_type (info
, ")"))
2739 t
= pop_type (info
);
2742 fprintf (info
->f
, ";\"\tkind:%c\ttype:%s", kind
, t
);
2744 fputs ("\tfile:", info
->f
);
2747 fprintf (info
->f
, "\tclass:%s", partof
);
2750 fputc ('\n', info
->f
);
2756 /* Write out line number information. */
2759 tg_lineno (void *p ATTRIBUTE_UNUSED
, const char *fname ATTRIBUTE_UNUSED
,
2760 unsigned long lineno ATTRIBUTE_UNUSED
,
2761 bfd_vma addr ATTRIBUTE_UNUSED
)
2766 /* Finish writing out a block. */
2769 tg_end_block (void *p ATTRIBUTE_UNUSED
, bfd_vma addr ATTRIBUTE_UNUSED
)
2774 /* Convert the visibility value into a human readable name. */
2777 visibility_name (enum debug_visibility visibility
)
2783 case DEBUG_VISIBILITY_PUBLIC
:
2786 case DEBUG_VISIBILITY_PRIVATE
:
2789 case DEBUG_VISIBILITY_PROTECTED
:
2792 case DEBUG_VISIBILITY_IGNORE
: