1 /* prdbg.c -- Print out generic debugging information.
2 Copyright (C) 1995-2019 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 bfd_boolean push_type (struct pr_handle *, const char *);
80 static bfd_boolean prepend_type (struct pr_handle *, const char *);
81 static bfd_boolean append_type (struct pr_handle *, const char *);
82 static bfd_boolean substitute_type (struct pr_handle *, const char *);
83 static bfd_boolean indent_type (struct pr_handle *);
84 static char *pop_type (struct pr_handle *);
85 static void print_vma (bfd_vma, char *, bfd_boolean, bfd_boolean);
86 static bfd_boolean pr_fix_visibility
87 (struct pr_handle *, enum debug_visibility);
88 static bfd_boolean pr_start_compilation_unit (void *, const char *);
89 static bfd_boolean pr_start_source (void *, const char *);
90 static bfd_boolean pr_empty_type (void *);
91 static bfd_boolean pr_void_type (void *);
92 static bfd_boolean pr_int_type (void *, unsigned int, bfd_boolean);
93 static bfd_boolean pr_float_type (void *, unsigned int);
94 static bfd_boolean pr_complex_type (void *, unsigned int);
95 static bfd_boolean pr_bool_type (void *, unsigned int);
96 static bfd_boolean pr_enum_type
97 (void *, const char *, const char **, bfd_signed_vma *);
98 static bfd_boolean pr_pointer_type (void *);
99 static bfd_boolean pr_function_type (void *, int, bfd_boolean);
100 static bfd_boolean pr_reference_type (void *);
101 static bfd_boolean pr_range_type (void *, bfd_signed_vma, bfd_signed_vma);
102 static bfd_boolean pr_array_type
103 (void *, bfd_signed_vma, bfd_signed_vma, bfd_boolean);
104 static bfd_boolean pr_set_type (void *, bfd_boolean);
105 static bfd_boolean pr_offset_type (void *);
106 static bfd_boolean pr_method_type (void *, bfd_boolean, int, bfd_boolean);
107 static bfd_boolean pr_const_type (void *);
108 static bfd_boolean pr_volatile_type (void *);
109 static bfd_boolean pr_start_struct_type
110 (void *, const char *, unsigned int, bfd_boolean, unsigned int);
111 static bfd_boolean pr_struct_field
112 (void *, const char *, bfd_vma, bfd_vma, enum debug_visibility);
113 static bfd_boolean pr_end_struct_type (void *);
114 static bfd_boolean pr_start_class_type
115 (void *, const char *, unsigned int, bfd_boolean, unsigned int,
116 bfd_boolean, bfd_boolean);
117 static bfd_boolean pr_class_static_member
118 (void *, const char *, const char *, enum debug_visibility);
119 static bfd_boolean pr_class_baseclass
120 (void *, bfd_vma, bfd_boolean, enum debug_visibility);
121 static bfd_boolean pr_class_start_method (void *, const char *);
122 static bfd_boolean pr_class_method_variant
123 (void *, const char *, enum debug_visibility, bfd_boolean, bfd_boolean,
124 bfd_vma, bfd_boolean);
125 static bfd_boolean pr_class_static_method_variant
126 (void *, const char *, enum debug_visibility, bfd_boolean, bfd_boolean);
127 static bfd_boolean pr_class_end_method (void *);
128 static bfd_boolean pr_end_class_type (void *);
129 static bfd_boolean pr_typedef_type (void *, const char *);
130 static bfd_boolean pr_tag_type
131 (void *, const char *, unsigned int, enum debug_type_kind);
132 static bfd_boolean pr_typdef (void *, const char *);
133 static bfd_boolean pr_tag (void *, const char *);
134 static bfd_boolean pr_int_constant (void *, const char *, bfd_vma);
135 static bfd_boolean pr_float_constant (void *, const char *, double);
136 static bfd_boolean pr_typed_constant (void *, const char *, bfd_vma);
137 static bfd_boolean pr_variable
138 (void *, const char *, enum debug_var_kind, bfd_vma);
139 static bfd_boolean pr_start_function (void *, const char *, bfd_boolean);
140 static bfd_boolean pr_function_parameter
141 (void *, const char *, enum debug_parm_kind, bfd_vma);
142 static bfd_boolean pr_start_block (void *, bfd_vma);
143 static bfd_boolean pr_end_block (void *, bfd_vma);
144 static bfd_boolean pr_end_function (void *);
145 static bfd_boolean pr_lineno (void *, const char *, unsigned long, bfd_vma);
146 static bfd_boolean append_parent (struct pr_handle *, const char *);
147 /* Only used by tg_ code. */
148 static bfd_boolean tg_fix_visibility
149 (struct pr_handle *, enum debug_visibility);
150 static void find_address_in_section (bfd *, asection *, void *);
151 static void translate_addresses (bfd *, char *, FILE *, asymbol **);
152 static const char *visibility_name (enum debug_visibility);
153 /* Tags style replacements. */
154 static bfd_boolean tg_start_compilation_unit (void *, const char *);
155 static bfd_boolean tg_start_source (void *, const char *);
156 static bfd_boolean tg_enum_type
157 (void *, const char *, const char **, bfd_signed_vma *);
158 static bfd_boolean tg_start_struct_type
159 (void *, const char *, unsigned int, bfd_boolean, unsigned int);
160 static bfd_boolean pr_struct_field
161 (void *, const char *, bfd_vma, bfd_vma, enum debug_visibility);
162 static bfd_boolean tg_struct_field
163 (void *, const char *, bfd_vma, bfd_vma, enum debug_visibility);
164 static bfd_boolean tg_struct_field
165 (void *, const char *, bfd_vma, bfd_vma, enum debug_visibility);
166 static bfd_boolean tg_end_struct_type (void *);
167 static bfd_boolean tg_start_class_type
168 (void *, const char *, unsigned int, bfd_boolean, unsigned int, bfd_boolean, bfd_boolean);
169 static bfd_boolean tg_class_static_member
170 (void *, const char *, const char *, enum debug_visibility);
171 static bfd_boolean tg_class_baseclass
172 (void *, bfd_vma, bfd_boolean, enum debug_visibility);
173 static bfd_boolean tg_class_method_variant
174 (void *, const char *, enum debug_visibility, bfd_boolean, bfd_boolean, bfd_vma, bfd_boolean);
175 static bfd_boolean tg_class_static_method_variant
176 (void *, const char *, enum debug_visibility, bfd_boolean, bfd_boolean);
177 static bfd_boolean tg_end_class_type (void *);
178 static bfd_boolean tg_tag_type
179 (void *, const char *, unsigned int, enum debug_type_kind);
180 static bfd_boolean tg_typdef (void *, const char *);
181 static bfd_boolean tg_tag (void *, const char *);
182 static bfd_boolean tg_int_constant (void *, const char *, bfd_vma);
183 static bfd_boolean tg_float_constant (void *, const char *, double);
184 static bfd_boolean tg_typed_constant (void *, const char *, bfd_vma);
185 static bfd_boolean tg_variable
186 (void *, const char *, enum debug_var_kind, bfd_vma);
187 static bfd_boolean tg_start_function (void *, const char *, bfd_boolean);
188 static bfd_boolean tg_function_parameter
189 (void *, const char *, enum debug_parm_kind, bfd_vma);
190 static bfd_boolean tg_start_block (void *, bfd_vma);
191 static bfd_boolean tg_end_block (void *, bfd_vma);
192 static bfd_boolean tg_lineno (void *, const char *, unsigned long, bfd_vma);
194 static const struct debug_write_fns pr_fns =
196 pr_start_compilation_unit,
215 pr_start_struct_type,
219 pr_class_static_member,
221 pr_class_start_method,
222 pr_class_method_variant,
223 pr_class_static_method_variant,
235 pr_function_parameter,
242 static const struct debug_write_fns tg_fns =
244 tg_start_compilation_unit,
246 pr_empty_type, /* Same, push_type. */
247 pr_void_type, /* Same, push_type. */
248 pr_int_type, /* Same, push_type. */
249 pr_float_type, /* Same, push_type. */
250 pr_complex_type, /* Same, push_type. */
251 pr_bool_type, /* Same, push_type. */
253 pr_pointer_type, /* Same, changes to pointer. */
254 pr_function_type, /* Same, push_type. */
255 pr_reference_type, /* Same, changes to reference. */
256 pr_range_type, /* FIXME: What's that?. */
257 pr_array_type, /* Same, push_type. */
258 pr_set_type, /* FIXME: What's that?. */
259 pr_offset_type, /* FIXME: What's that?. */
260 pr_method_type, /* Same. */
261 pr_const_type, /* Same, changes to const. */
262 pr_volatile_type, /* Same, changes to volatile. */
263 tg_start_struct_type,
267 tg_class_static_member,
269 pr_class_start_method, /* Same, remembers that's a method. */
270 tg_class_method_variant,
271 tg_class_static_method_variant,
272 pr_class_end_method, /* Same, forgets that's a method. */
274 pr_typedef_type, /* Same, just push type. */
278 tg_int_constant, /* Untested. */
279 tg_float_constant, /* Untested. */
280 tg_typed_constant, /* Untested. */
283 tg_function_parameter,
286 pr_end_function, /* Same, does nothing. */
290 static int demangle_flags = DMGL_ANSI | DMGL_PARAMS;
292 /* Print out the generic debugging information recorded in dhandle. */
295 print_debugging_info (FILE *f, void *dhandle, bfd *abfd, asymbol **syms,
296 char * (*demangler) (struct bfd *, const char *, int),
299 struct pr_handle info;
305 info.filename = NULL;
308 info.demangler = demangler;
312 fputs ("!_TAG_FILE_FORMAT\t2\t/extended format/\n", f);
313 fputs ("!_TAG_FILE_SORTED\t0\t/0=unsorted, 1=sorted/\n", f);
314 fputs ("!_TAG_PROGRAM_AUTHOR\tIan Lance Taylor, Salvador E. Tropea and others\t//\n", f);
315 fputs ("!_TAG_PROGRAM_NAME\tobjdump\t/From GNU binutils/\n", f);
318 return as_tags ? debug_write (dhandle, &tg_fns, (void *) & info)
319 : debug_write (dhandle, &pr_fns, (void *) & info);
322 /* Indent to the current indentation level. */
325 indent (struct pr_handle *info)
329 for (i = 0; i < info->indent; i++)
333 /* Push a type on the type stack. */
336 push_type (struct pr_handle *info, const char *type)
343 n = (struct pr_stack *) xmalloc (sizeof *n);
344 memset (n, 0, sizeof *n);
346 n->type = xstrdup (type);
347 n->visibility = DEBUG_VISIBILITY_IGNORE;
349 n->next = info->stack;
355 /* Prepend a string onto the type on the top of the type stack. */
358 prepend_type (struct pr_handle *info, const char *s)
362 assert (info->stack != NULL);
364 n = (char *) xmalloc (strlen (s) + strlen (info->stack->type) + 1);
365 sprintf (n, "%s%s", s, info->stack->type);
366 free (info->stack->type);
367 info->stack->type = n;
372 /* Append a string to the type on the top of the type stack. */
375 append_type (struct pr_handle *info, const char *s)
382 assert (info->stack != NULL);
384 len = strlen (info->stack->type);
385 info->stack->type = (char *) xrealloc (info->stack->type,
386 len + strlen (s) + 1);
387 strcpy (info->stack->type + len, s);
392 /* Append a string to the parents on the top of the type stack. */
395 append_parent (struct pr_handle *info, const char *s)
402 assert (info->stack != NULL);
404 len = info->stack->parents ? strlen (info->stack->parents) : 0;
405 info->stack->parents = (char *) xrealloc (info->stack->parents,
406 len + strlen (s) + 1);
407 strcpy (info->stack->parents + len, s);
412 /* We use an underscore to indicate where the name should go in a type
413 string. This function substitutes a string for the underscore. If
414 there is no underscore, the name follows the type. */
417 substitute_type (struct pr_handle *info, const char *s)
421 assert (info->stack != NULL);
423 u = strchr (info->stack->type, '|');
428 n = (char *) xmalloc (strlen (info->stack->type) + strlen (s));
430 memcpy (n, info->stack->type, u - info->stack->type);
431 strcpy (n + (u - info->stack->type), s);
434 free (info->stack->type);
435 info->stack->type = n;
440 if (strchr (s, '|') != NULL
441 && (strchr (info->stack->type, '{') != NULL
442 || strchr (info->stack->type, '(') != NULL))
444 if (! prepend_type (info, "(")
445 || ! append_type (info, ")"))
452 return (append_type (info, " ")
453 && append_type (info, s));
456 /* Indent the type at the top of the stack by appending spaces. */
459 indent_type (struct pr_handle *info)
463 for (i = 0; i < info->indent; i++)
465 if (! append_type (info, " "))
472 /* Pop a type from the type stack. */
475 pop_type (struct pr_handle *info)
480 assert (info->stack != NULL);
483 info->stack = o->next;
490 /* Print a VMA value into a string. */
493 print_vma (bfd_vma vma, char *buf, bfd_boolean unsignedp, bfd_boolean hexp)
495 if (sizeof (vma) <= sizeof (unsigned long))
498 sprintf (buf, "0x%lx", (unsigned long) vma);
500 sprintf (buf, "%lu", (unsigned long) vma);
502 sprintf (buf, "%ld", (long) vma);
504 #if BFD_HOST_64BIT_LONG_LONG
505 else if (sizeof (vma) <= sizeof (unsigned long long))
509 sprintf (buf, "0x%llx", (unsigned long long) vma);
511 sprintf (buf, "%llu", (unsigned long long) vma);
513 sprintf (buf, "%lld", (long long) vma);
516 sprintf (buf, "0x%I64x", (unsigned long long) vma);
518 sprintf (buf, "%I64u", (unsigned long long) vma);
520 sprintf (buf, "%I64d", (long long) vma);
528 sprintf_vma (buf + 2, vma);
532 /* Start a new compilation unit. */
535 pr_start_compilation_unit (void *p, const char *filename)
537 struct pr_handle *info = (struct pr_handle *) p;
539 assert (info->indent == 0);
541 fprintf (info->f, "%s:\n", filename);
546 /* Start a source file within a compilation unit. */
549 pr_start_source (void *p, const char *filename)
551 struct pr_handle *info = (struct pr_handle *) p;
553 assert (info->indent == 0);
555 fprintf (info->f, " %s:\n", filename);
560 /* Push an empty type onto the type stack. */
563 pr_empty_type (void *p)
565 struct pr_handle *info = (struct pr_handle *) p;
567 return push_type (info, "<undefined>");
570 /* Push a void type onto the type stack. */
573 pr_void_type (void *p)
575 struct pr_handle *info = (struct pr_handle *) p;
577 return push_type (info, "void");
580 /* Push an integer type onto the type stack. */
583 pr_int_type (void *p, unsigned int size, bfd_boolean unsignedp)
585 struct pr_handle *info = (struct pr_handle *) p;
588 sprintf (ab, "%sint%d", unsignedp ? "u" : "", size * 8);
589 return push_type (info, ab);
592 /* Push a floating type onto the type stack. */
595 pr_float_type (void *p, unsigned int size)
597 struct pr_handle *info = (struct pr_handle *) p;
601 return push_type (info, "float");
603 return push_type (info, "double");
605 sprintf (ab, "float%d", size * 8);
606 return push_type (info, ab);
609 /* Push a complex type onto the type stack. */
612 pr_complex_type (void *p, unsigned int size)
614 struct pr_handle *info = (struct pr_handle *) p;
616 if (! pr_float_type (p, size))
619 return prepend_type (info, "complex ");
622 /* Push a bfd_boolean type onto the type stack. */
625 pr_bool_type (void *p, unsigned int size)
627 struct pr_handle *info = (struct pr_handle *) p;
630 sprintf (ab, "bool%d", size * 8);
632 return push_type (info, ab);
635 /* Push an enum type onto the type stack. */
638 pr_enum_type (void *p, const char *tag, const char **names,
639 bfd_signed_vma *values)
641 struct pr_handle *info = (struct pr_handle *) p;
645 if (! push_type (info, "enum "))
649 if (! append_type (info, tag)
650 || ! append_type (info, " "))
653 if (! append_type (info, "{ "))
658 if (! append_type (info, "/* undefined */"))
664 for (i = 0; names[i] != NULL; i++)
668 if (! append_type (info, ", "))
672 if (! append_type (info, names[i]))
675 if (values[i] != val)
679 print_vma (values[i], ab, FALSE, FALSE);
680 if (! append_type (info, " = ")
681 || ! append_type (info, ab))
690 return append_type (info, " }");
693 /* Turn the top type on the stack into a pointer. */
696 pr_pointer_type (void *p)
698 struct pr_handle *info = (struct pr_handle *) p;
701 assert (info->stack != NULL);
703 s = strchr (info->stack->type, '|');
704 if (s != NULL && s[1] == '[')
705 return substitute_type (info, "(*|)");
706 return substitute_type (info, "*|");
709 /* Turn the top type on the stack into a function returning that type. */
712 pr_function_type (void *p, int argcount, bfd_boolean varargs)
714 struct pr_handle *info = (struct pr_handle *) p;
719 assert (info->stack != NULL);
732 arg_types = (char **) xmalloc (argcount * sizeof *arg_types);
733 for (i = argcount - 1; i >= 0; i--)
735 if (! substitute_type (info, ""))
740 arg_types[i] = pop_type (info);
741 if (arg_types[i] == NULL)
746 len += strlen (arg_types[i]) + 2;
752 /* Now the return type is on the top of the stack. */
754 s = (char *) xmalloc (len);
755 LITSTRCPY (s, "(|) (");
758 strcat (s, "/* unknown */");
763 for (i = 0; i < argcount; i++)
767 strcat (s, arg_types[i]);
781 if (! substitute_type (info, s))
789 /* Turn the top type on the stack into a reference to that type. */
792 pr_reference_type (void *p)
794 struct pr_handle *info = (struct pr_handle *) p;
796 assert (info->stack != NULL);
798 return substitute_type (info, "&|");
801 /* Make a range type. */
804 pr_range_type (void *p, bfd_signed_vma lower, bfd_signed_vma upper)
806 struct pr_handle *info = (struct pr_handle *) p;
807 char abl[22], abu[22];
809 assert (info->stack != NULL);
811 if (! substitute_type (info, ""))
814 print_vma (lower, abl, FALSE, FALSE);
815 print_vma (upper, abu, FALSE, FALSE);
817 return (prepend_type (info, "range (")
818 && append_type (info, "):")
819 && append_type (info, abl)
820 && append_type (info, ":")
821 && append_type (info, abu));
824 /* Make an array type. */
827 pr_array_type (void *p, bfd_signed_vma lower, bfd_signed_vma upper,
830 struct pr_handle *info = (struct pr_handle *) p;
832 char abl[22], abu[22], ab[50];
834 range_type = pop_type (info);
835 if (range_type == NULL)
844 print_vma (upper + 1, abu, FALSE, FALSE);
845 sprintf (ab, "|[%s]", abu);
850 print_vma (lower, abl, FALSE, FALSE);
851 print_vma (upper, abu, FALSE, FALSE);
852 sprintf (ab, "|[%s:%s]", abl, abu);
855 if (! substitute_type (info, ab))
858 if (strcmp (range_type, "int") != 0)
860 if (! append_type (info, ":")
861 || ! append_type (info, range_type))
867 if (! append_type (info, " /* string */"))
874 /* Make a set type. */
877 pr_set_type (void *p, bfd_boolean bitstringp)
879 struct pr_handle *info = (struct pr_handle *) p;
881 if (! substitute_type (info, ""))
884 if (! prepend_type (info, "set { ")
885 || ! append_type (info, " }"))
890 if (! append_type (info, "/* bitstring */"))
897 /* Make an offset type. */
900 pr_offset_type (void *p)
902 struct pr_handle *info = (struct pr_handle *) p;
905 if (! substitute_type (info, ""))
912 return (substitute_type (info, "")
913 && prepend_type (info, " ")
914 && prepend_type (info, t)
915 && append_type (info, "::|"));
918 /* Make a method type. */
921 pr_method_type (void *p, bfd_boolean domain, int argcount, bfd_boolean varargs)
923 struct pr_handle *info = (struct pr_handle *) p;
935 if (! substitute_type (info, ""))
937 domain_type = pop_type (info);
938 if (domain_type == NULL)
940 if (CONST_STRNEQ (domain_type, "class ")
941 && strchr (domain_type + sizeof "class " - 1, ' ') == NULL)
942 domain_type += sizeof "class " - 1;
943 else if (CONST_STRNEQ (domain_type, "union class ")
944 && (strchr (domain_type + sizeof "union class " - 1, ' ')
946 domain_type += sizeof "union class " - 1;
947 len += strlen (domain_type);
959 arg_types = (char **) xmalloc (argcount * sizeof *arg_types);
960 for (i = argcount - 1; i >= 0; i--)
962 if (! substitute_type (info, ""))
967 arg_types[i] = pop_type (info);
968 if (arg_types[i] == NULL)
973 len += strlen (arg_types[i]) + 2;
979 /* Now the return type is on the top of the stack. */
981 s = (char *) xmalloc (len);
985 strcpy (s, domain_type);
989 strcat (s, "/* unknown */");
994 for (i = 0; i < argcount; i++)
998 strcat (s, arg_types[i]);
1012 if (! substitute_type (info, s))
1020 /* Make a const qualified type. */
1023 pr_const_type (void *p)
1025 struct pr_handle *info = (struct pr_handle *) p;
1027 return substitute_type (info, "const |");
1030 /* Make a volatile qualified type. */
1033 pr_volatile_type (void *p)
1035 struct pr_handle *info = (struct pr_handle *) p;
1037 return substitute_type (info, "volatile |");
1040 /* Start accumulating a struct type. */
1043 pr_start_struct_type (void *p, const char *tag, unsigned int id,
1044 bfd_boolean structp, unsigned int size)
1046 struct pr_handle *info = (struct pr_handle *) p;
1050 if (! push_type (info, structp ? "struct " : "union "))
1054 if (! append_type (info, tag))
1061 sprintf (idbuf, "%%anon%u", id);
1062 if (! append_type (info, idbuf))
1066 if (! append_type (info, " {"))
1068 if (size != 0 || tag != NULL)
1072 if (! append_type (info, " /*"))
1077 sprintf (ab, " size %u", size);
1078 if (! append_type (info, ab))
1083 sprintf (ab, " id %u", id);
1084 if (! append_type (info, ab))
1087 if (! append_type (info, " */"))
1090 if (! append_type (info, "\n"))
1093 info->stack->visibility = DEBUG_VISIBILITY_PUBLIC;
1095 return indent_type (info);
1098 /* Output the visibility of a field in a struct. */
1101 pr_fix_visibility (struct pr_handle *info, enum debug_visibility visibility)
1103 const char *s = NULL;
1107 assert (info->stack != NULL);
1109 if (info->stack->visibility == visibility)
1114 case DEBUG_VISIBILITY_PUBLIC:
1117 case DEBUG_VISIBILITY_PRIVATE:
1120 case DEBUG_VISIBILITY_PROTECTED:
1123 case DEBUG_VISIBILITY_IGNORE:
1131 /* Trim off a trailing space in the struct string, to make the
1132 output look a bit better, then stick on the visibility string. */
1134 t = info->stack->type;
1136 assert (t[len - 1] == ' ');
1139 if (! append_type (info, s)
1140 || ! append_type (info, ":\n")
1141 || ! indent_type (info))
1144 info->stack->visibility = visibility;
1149 /* Add a field to a struct type. */
1152 pr_struct_field (void *p, const char *name, bfd_vma bitpos, bfd_vma bitsize,
1153 enum debug_visibility visibility)
1155 struct pr_handle *info = (struct pr_handle *) p;
1159 if (! substitute_type (info, name))
1162 if (! append_type (info, "; /* "))
1167 print_vma (bitsize, ab, TRUE, FALSE);
1168 if (! append_type (info, "bitsize ")
1169 || ! append_type (info, ab)
1170 || ! append_type (info, ", "))
1174 print_vma (bitpos, ab, TRUE, FALSE);
1175 if (! append_type (info, "bitpos ")
1176 || ! append_type (info, ab)
1177 || ! append_type (info, " */\n")
1178 || ! indent_type (info))
1181 t = pop_type (info);
1185 if (! pr_fix_visibility (info, visibility))
1188 return append_type (info, t);
1191 /* Finish a struct type. */
1194 pr_end_struct_type (void *p)
1196 struct pr_handle *info = (struct pr_handle *) p;
1199 assert (info->stack != NULL);
1200 assert (info->indent >= 2);
1204 /* Change the trailing indentation to have a close brace. */
1205 s = info->stack->type + strlen (info->stack->type) - 2;
1206 assert (s[0] == ' ' && s[1] == ' ' && s[2] == '\0');
1214 /* Start a class type. */
1217 pr_start_class_type (void *p, const char *tag, unsigned int id,
1218 bfd_boolean structp, unsigned int size,
1219 bfd_boolean vptr, bfd_boolean ownvptr)
1221 struct pr_handle *info = (struct pr_handle *) p;
1226 if (vptr && ! ownvptr)
1228 tv = pop_type (info);
1233 if (! push_type (info, structp ? "class " : "union class "))
1237 if (! append_type (info, tag))
1244 sprintf (idbuf, "%%anon%u", id);
1245 if (! append_type (info, idbuf))
1249 if (! append_type (info, " {"))
1251 if (size != 0 || vptr || ownvptr || tag != NULL)
1253 if (! append_type (info, " /*"))
1260 sprintf (ab, "%u", size);
1261 if (! append_type (info, " size ")
1262 || ! append_type (info, ab))
1268 if (! append_type (info, " vtable "))
1272 if (! append_type (info, "self "))
1277 if (! append_type (info, tv)
1278 || ! append_type (info, " "))
1287 sprintf (ab, " id %u", id);
1288 if (! append_type (info, ab))
1292 if (! append_type (info, " */"))
1296 info->stack->visibility = DEBUG_VISIBILITY_PRIVATE;
1298 return (append_type (info, "\n")
1299 && indent_type (info));
1302 /* Add a static member to a class. */
1305 pr_class_static_member (void *p, const char *name, const char *physname,
1306 enum debug_visibility visibility)
1308 struct pr_handle *info = (struct pr_handle *) p;
1311 if (! substitute_type (info, name))
1314 if (! prepend_type (info, "static ")
1315 || ! append_type (info, "; /* ")
1316 || ! append_type (info, physname)
1317 || ! append_type (info, " */\n")
1318 || ! indent_type (info))
1321 t = pop_type (info);
1325 if (! pr_fix_visibility (info, visibility))
1328 return append_type (info, t);
1331 /* Add a base class to a class. */
1334 pr_class_baseclass (void *p, bfd_vma bitpos, bfd_boolean is_virtual,
1335 enum debug_visibility visibility)
1337 struct pr_handle *info = (struct pr_handle *) p;
1343 assert (info->stack != NULL && info->stack->next != NULL);
1345 if (! substitute_type (info, ""))
1348 t = pop_type (info);
1352 if (CONST_STRNEQ (t, "class "))
1353 t += sizeof "class " - 1;
1355 /* Push it back on to take advantage of the prepend_type and
1356 append_type routines. */
1357 if (! push_type (info, t))
1362 if (! prepend_type (info, "virtual "))
1368 case DEBUG_VISIBILITY_PUBLIC:
1371 case DEBUG_VISIBILITY_PROTECTED:
1372 prefix = "protected ";
1374 case DEBUG_VISIBILITY_PRIVATE:
1375 prefix = "private ";
1378 prefix = "/* unknown visibility */ ";
1382 if (! prepend_type (info, prefix))
1387 print_vma (bitpos, ab, TRUE, FALSE);
1388 if (! append_type (info, " /* bitpos ")
1389 || ! append_type (info, ab)
1390 || ! append_type (info, " */"))
1394 /* Now the top of the stack is something like "public A / * bitpos
1395 10 * /". The next element on the stack is something like "class
1396 xx { / * size 8 * /\n...". We want to substitute the top of the
1397 stack in before the {. */
1398 s = strchr (info->stack->next->type, '{');
1402 /* If there is already a ':', then we already have a baseclass, and
1403 we must append this one after a comma. */
1404 for (l = info->stack->next->type; l != s; l++)
1407 if (! prepend_type (info, l == s ? " : " : ", "))
1410 t = pop_type (info);
1414 n = (char *) xmalloc (strlen (info->stack->type) + strlen (t) + 1);
1415 memcpy (n, info->stack->type, s - info->stack->type);
1416 strcpy (n + (s - info->stack->type), t);
1419 free (info->stack->type);
1420 info->stack->type = n;
1427 /* Start adding a method to a class. */
1430 pr_class_start_method (void *p, const char *name)
1432 struct pr_handle *info = (struct pr_handle *) p;
1434 assert (info->stack != NULL);
1435 info->stack->method = name;
1439 /* Add a variant to a method. */
1442 pr_class_method_variant (void *p, const char *physname,
1443 enum debug_visibility visibility,
1444 bfd_boolean constp, bfd_boolean volatilep,
1445 bfd_vma voffset, bfd_boolean context)
1447 struct pr_handle *info = (struct pr_handle *) p;
1451 assert (info->stack != NULL);
1452 assert (info->stack->next != NULL);
1454 /* Put the const and volatile qualifiers on the type. */
1457 if (! append_type (info, " volatile"))
1462 if (! append_type (info, " const"))
1466 /* Stick the name of the method into its type. */
1467 if (! substitute_type (info,
1469 ? info->stack->next->next->method
1470 : info->stack->next->method)))
1474 method_type = pop_type (info);
1475 if (method_type == NULL)
1478 /* Pull off the context type if there is one. */
1480 context_type = NULL;
1483 context_type = pop_type (info);
1484 if (context_type == NULL)
1488 /* Now the top of the stack is the class. */
1490 if (! pr_fix_visibility (info, visibility))
1493 if (! append_type (info, method_type)
1494 || ! append_type (info, " /* ")
1495 || ! append_type (info, physname)
1496 || ! append_type (info, " "))
1498 if (context || voffset != 0)
1504 if (! append_type (info, "context ")
1505 || ! append_type (info, context_type)
1506 || ! append_type (info, " "))
1509 print_vma (voffset, ab, TRUE, FALSE);
1510 if (! append_type (info, "voffset ")
1511 || ! append_type (info, ab))
1515 return (append_type (info, " */;\n")
1516 && indent_type (info));
1519 /* Add a static variant to a method. */
1522 pr_class_static_method_variant (void *p, const char *physname,
1523 enum debug_visibility visibility,
1524 bfd_boolean constp, bfd_boolean volatilep)
1526 struct pr_handle *info = (struct pr_handle *) p;
1529 assert (info->stack != NULL);
1530 assert (info->stack->next != NULL);
1531 assert (info->stack->next->method != NULL);
1533 /* Put the const and volatile qualifiers on the type. */
1536 if (! append_type (info, " volatile"))
1541 if (! append_type (info, " const"))
1545 /* Mark it as static. */
1546 if (! prepend_type (info, "static "))
1549 /* Stick the name of the method into its type. */
1550 if (! substitute_type (info, info->stack->next->method))
1554 method_type = pop_type (info);
1555 if (method_type == NULL)
1558 /* Now the top of the stack is the class. */
1560 if (! pr_fix_visibility (info, visibility))
1563 return (append_type (info, method_type)
1564 && append_type (info, " /* ")
1565 && append_type (info, physname)
1566 && append_type (info, " */;\n")
1567 && indent_type (info));
1570 /* Finish up a method. */
1573 pr_class_end_method (void *p)
1575 struct pr_handle *info = (struct pr_handle *) p;
1577 info->stack->method = NULL;
1581 /* Finish up a class. */
1584 pr_end_class_type (void *p)
1586 return pr_end_struct_type (p);
1589 /* Push a type on the stack using a typedef name. */
1592 pr_typedef_type (void *p, const char *name)
1594 struct pr_handle *info = (struct pr_handle *) p;
1596 return push_type (info, name);
1599 /* Push a type on the stack using a tag name. */
1602 pr_tag_type (void *p, const char *name, unsigned int id,
1603 enum debug_type_kind kind)
1605 struct pr_handle *info = (struct pr_handle *) p;
1606 const char *t, *tag;
1611 case DEBUG_KIND_STRUCT:
1614 case DEBUG_KIND_UNION:
1617 case DEBUG_KIND_ENUM:
1620 case DEBUG_KIND_CLASS:
1623 case DEBUG_KIND_UNION_CLASS:
1631 if (! push_type (info, t))
1637 sprintf (idbuf, "%%anon%u", id);
1641 if (! append_type (info, tag))
1643 if (name != NULL && kind != DEBUG_KIND_ENUM)
1645 sprintf (idbuf, " /* id %u */", id);
1646 if (! append_type (info, idbuf))
1653 /* Output a typedef. */
1656 pr_typdef (void *p, const char *name)
1658 struct pr_handle *info = (struct pr_handle *) p;
1661 if (! substitute_type (info, name))
1664 s = pop_type (info);
1669 fprintf (info->f, "typedef %s;\n", s);
1676 /* Output a tag. The tag should already be in the string on the
1677 stack, so all we have to do here is print it out. */
1680 pr_tag (void *p, const char *name ATTRIBUTE_UNUSED)
1682 struct pr_handle *info = (struct pr_handle *) p;
1685 t = pop_type (info);
1690 fprintf (info->f, "%s;\n", t);
1697 /* Output an integer constant. */
1700 pr_int_constant (void *p, const char *name, bfd_vma val)
1702 struct pr_handle *info = (struct pr_handle *) p;
1706 print_vma (val, ab, FALSE, FALSE);
1707 fprintf (info->f, "const int %s = %s;\n", name, ab);
1711 /* Output a floating point constant. */
1714 pr_float_constant (void *p, const char *name, double val)
1716 struct pr_handle *info = (struct pr_handle *) p;
1719 fprintf (info->f, "const double %s = %g;\n", name, val);
1723 /* Output a typed constant. */
1726 pr_typed_constant (void *p, const char *name, bfd_vma val)
1728 struct pr_handle *info = (struct pr_handle *) p;
1732 t = pop_type (info);
1737 print_vma (val, ab, FALSE, FALSE);
1738 fprintf (info->f, "const %s %s = %s;\n", t, name, ab);
1745 /* Output a variable. */
1748 pr_variable (void *p, const char *name, enum debug_var_kind kind,
1751 struct pr_handle *info = (struct pr_handle *) p;
1755 if (! substitute_type (info, name))
1758 t = pop_type (info);
1766 case DEBUG_LOCAL_STATIC:
1767 fprintf (info->f, "static ");
1769 case DEBUG_REGISTER:
1770 fprintf (info->f, "register ");
1775 print_vma (val, ab, TRUE, TRUE);
1776 fprintf (info->f, "%s /* %s */;\n", t, ab);
1783 /* Start outputting a function. */
1786 pr_start_function (void *p, const char *name, bfd_boolean global)
1788 struct pr_handle *info = (struct pr_handle *) p;
1791 if (! substitute_type (info, name))
1794 t = pop_type (info);
1800 fprintf (info->f, "static ");
1801 fprintf (info->f, "%s (", t);
1803 info->parameter = 1;
1808 /* Output a function parameter. */
1811 pr_function_parameter (void *p, const char *name,
1812 enum debug_parm_kind kind, bfd_vma val)
1814 struct pr_handle *info = (struct pr_handle *) p;
1818 if (kind == DEBUG_PARM_REFERENCE
1819 || kind == DEBUG_PARM_REF_REG)
1821 if (! pr_reference_type (p))
1825 if (! substitute_type (info, name))
1828 t = pop_type (info);
1832 if (info->parameter != 1)
1833 fprintf (info->f, ", ");
1835 if (kind == DEBUG_PARM_REG || kind == DEBUG_PARM_REF_REG)
1836 fprintf (info->f, "register ");
1838 print_vma (val, ab, TRUE, TRUE);
1839 fprintf (info->f, "%s /* %s */", t, ab);
1848 /* Start writing out a block. */
1851 pr_start_block (void *p, bfd_vma addr)
1853 struct pr_handle *info = (struct pr_handle *) p;
1856 if (info->parameter > 0)
1858 fprintf (info->f, ")\n");
1859 info->parameter = 0;
1863 print_vma (addr, ab, TRUE, TRUE);
1864 fprintf (info->f, "{ /* %s */\n", ab);
1871 /* Write out line number information. */
1874 pr_lineno (void *p, const char *filename, unsigned long lineno, bfd_vma addr)
1876 struct pr_handle *info = (struct pr_handle *) p;
1880 print_vma (addr, ab, TRUE, TRUE);
1881 fprintf (info->f, "/* file %s line %lu addr %s */\n", filename, lineno, ab);
1886 /* Finish writing out a block. */
1889 pr_end_block (void *p, bfd_vma addr)
1891 struct pr_handle *info = (struct pr_handle *) p;
1897 print_vma (addr, ab, TRUE, TRUE);
1898 fprintf (info->f, "} /* %s */\n", ab);
1903 /* Finish writing out a function. */
1906 pr_end_function (void *p ATTRIBUTE_UNUSED)
1911 /* Tags style generation functions start here. */
1913 /* Variables for address to line translation. */
1915 static const char *filename;
1916 static const char *functionname;
1917 static unsigned int line;
1918 static bfd_boolean found;
1920 /* Look for an address in a section. This is called via
1921 bfd_map_over_sections. */
1924 find_address_in_section (bfd *abfd, asection *section, void *data)
1928 asymbol **syms = (asymbol **) data;
1933 if ((bfd_get_section_flags (abfd, section) & SEC_ALLOC) == 0)
1936 vma = bfd_get_section_vma (abfd, section);
1940 size = bfd_get_section_size (section);
1941 if (pc >= vma + size)
1944 found = bfd_find_nearest_line (abfd, section, syms, pc - vma,
1945 &filename, &functionname, &line);
1949 translate_addresses (bfd *abfd, char *addr_hex, FILE *f, asymbol **syms)
1951 pc = bfd_scan_vma (addr_hex, NULL, 16);
1953 bfd_map_over_sections (abfd, find_address_in_section, syms);
1958 fprintf (f, "%u", line);
1961 /* Start a new compilation unit. */
1964 tg_start_compilation_unit (void * p, const char *fname ATTRIBUTE_UNUSED)
1966 struct pr_handle *info = (struct pr_handle *) p;
1968 free (info->filename);
1969 /* Should it be relative? best way to do it here?. */
1970 info->filename = strdup (fname);
1975 /* Start a source file within a compilation unit. */
1978 tg_start_source (void *p, const char *fname)
1980 struct pr_handle *info = (struct pr_handle *) p;
1982 free (info->filename);
1983 /* Should it be relative? best way to do it here?. */
1984 info->filename = strdup (fname);
1989 /* Push an enum type onto the type stack. */
1992 tg_enum_type (void *p, const char *tag, const char **names,
1993 bfd_signed_vma *values)
1995 struct pr_handle *info = (struct pr_handle *) p;
2000 if (! pr_enum_type (p, tag, names, values))
2003 name = tag ? tag : "unknown";
2004 /* Generate an entry for the enum. */
2006 fprintf (info->f, "%s\t%s\t0;\"\tkind:e\ttype:%s\n", tag,
2007 info->filename, info->stack->type);
2009 /* Generate entries for the values. */
2012 for (i = 0; names[i] != NULL; i++)
2014 print_vma (values[i], ab, FALSE, FALSE);
2015 fprintf (info->f, "%s\t%s\t0;\"\tkind:g\tenum:%s\tvalue:%s\n",
2016 names[i], info->filename, name, ab);
2023 /* Start accumulating a struct type. */
2026 tg_start_struct_type (void *p, const char *tag, unsigned int id,
2027 bfd_boolean structp,
2028 unsigned int size ATTRIBUTE_UNUSED)
2030 struct pr_handle *info = (struct pr_handle *) p;
2039 sprintf (idbuf, "%%anon%u", id);
2042 if (! push_type (info, name))
2045 info->stack->flavor = structp ? "struct" : "union";
2047 fprintf (info->f, "%s\t%s\t0;\"\tkind:%c\n", name, info->filename,
2048 info->stack->flavor[0]);
2050 info->stack->visibility = DEBUG_VISIBILITY_PUBLIC;
2052 return indent_type (info);
2055 /* Output the visibility of a field in a struct. */
2058 tg_fix_visibility (struct pr_handle *info, enum debug_visibility visibility)
2060 assert (info->stack != NULL);
2062 if (info->stack->visibility == visibility)
2065 assert (info->stack->visibility != DEBUG_VISIBILITY_IGNORE);
2067 info->stack->visibility = visibility;
2072 /* Add a field to a struct type. */
2075 tg_struct_field (void *p, const char *name, bfd_vma bitpos ATTRIBUTE_UNUSED,
2076 bfd_vma bitsize ATTRIBUTE_UNUSED,
2077 enum debug_visibility visibility)
2079 struct pr_handle *info = (struct pr_handle *) p;
2082 t = pop_type (info);
2086 if (! tg_fix_visibility (info, visibility))
2089 /* It happens, a bug? */
2093 fprintf (info->f, "%s\t%s\t0;\"\tkind:m\ttype:%s\t%s:%s\taccess:%s\n",
2094 name, info->filename, t, info->stack->flavor, info->stack->type,
2095 visibility_name (visibility));
2100 /* Finish a struct type. */
2103 tg_end_struct_type (void *p ATTRIBUTE_UNUSED)
2105 assert (((struct pr_handle *) p)->stack != NULL);
2110 /* Start a class type. */
2113 tg_start_class_type (void *p, const char *tag, unsigned int id,
2114 bfd_boolean structp, unsigned int size,
2115 bfd_boolean vptr, bfd_boolean ownvptr)
2117 struct pr_handle *info = (struct pr_handle *) p;
2123 if (vptr && ! ownvptr)
2125 tv = pop_type (info);
2136 sprintf (idbuf, "%%anon%u", id);
2140 if (! push_type (info, name))
2143 info->stack->flavor = structp ? "class" : "union class";
2144 info->stack->parents = NULL;
2145 info->stack->num_parents = 0;
2147 if (size != 0 || vptr || ownvptr || tag != NULL)
2151 if (! append_type (info, " vtable "))
2155 if (! append_type (info, "self "))
2160 if (! append_type (info, tv)
2161 || ! append_type (info, " "))
2167 info->stack->visibility = DEBUG_VISIBILITY_PRIVATE;
2172 /* Add a static member to a class. */
2175 tg_class_static_member (void *p, const char *name,
2176 const char *physname ATTRIBUTE_UNUSED,
2177 enum debug_visibility visibility)
2179 struct pr_handle *info = (struct pr_handle *) p;
2181 int len_var, len_class;
2184 len_var = strlen (name);
2185 len_class = strlen (info->stack->next->type);
2186 full_name = (char *) xmalloc (len_var + len_class + 3);
2189 sprintf (full_name, "%s::%s", info->stack->next->type, name);
2191 if (! substitute_type (info, full_name))
2197 if (! prepend_type (info, "static "))
2203 t = pop_type (info);
2210 if (! tg_fix_visibility (info, visibility))
2217 fprintf (info->f, "%s\t%s\t0;\"\tkind:x\ttype:%s\tclass:%s\taccess:%s\n",
2218 name, info->filename, t, info->stack->type,
2219 visibility_name (visibility));
2226 /* Add a base class to a class. */
2229 tg_class_baseclass (void *p, bfd_vma bitpos ATTRIBUTE_UNUSED,
2230 bfd_boolean is_virtual, enum debug_visibility visibility)
2232 struct pr_handle *info = (struct pr_handle *) p;
2236 assert (info->stack != NULL && info->stack->next != NULL);
2238 t = pop_type (info);
2242 if (CONST_STRNEQ (t, "class "))
2243 t += sizeof "class " - 1;
2245 /* Push it back on to take advantage of the prepend_type and
2246 append_type routines. */
2247 if (! push_type (info, t))
2252 if (! prepend_type (info, "virtual "))
2258 case DEBUG_VISIBILITY_PUBLIC:
2261 case DEBUG_VISIBILITY_PROTECTED:
2262 prefix = "protected ";
2264 case DEBUG_VISIBILITY_PRIVATE:
2265 prefix = "private ";
2268 prefix = "/* unknown visibility */ ";
2272 if (! prepend_type (info, prefix))
2275 t = pop_type (info);
2279 if (info->stack->num_parents && ! append_parent (info, ", "))
2282 if (! append_parent (info, t))
2284 info->stack->num_parents++;
2291 /* Add a variant to a method. */
2294 tg_class_method_variant (void *p, const char *physname ATTRIBUTE_UNUSED,
2295 enum debug_visibility visibility,
2296 bfd_boolean constp, bfd_boolean volatilep,
2297 bfd_vma voffset ATTRIBUTE_UNUSED,
2298 bfd_boolean context)
2300 struct pr_handle *info = (struct pr_handle *) p;
2305 assert (info->stack != NULL);
2306 assert (info->stack->next != NULL);
2308 /* Put the const and volatile qualifiers on the type. */
2311 if (! append_type (info, " volatile"))
2316 if (! append_type (info, " const"))
2320 method_name = strdup (context ? info->stack->next->next->method
2321 : info->stack->next->method);
2323 /* Stick the name of the method into its type. */
2324 if (! substitute_type (info, method_name))
2331 method_type = pop_type (info);
2332 if (method_type == NULL)
2338 /* Pull off the context type if there is one. */
2340 context_type = NULL;
2343 context_type = pop_type (info);
2344 if (context_type == NULL)
2352 /* Now the top of the stack is the class. */
2353 if (! tg_fix_visibility (info, visibility))
2357 free (context_type);
2361 fprintf (info->f, "%s\t%s\t0;\"\tkind:p\ttype:%s\tclass:%s\n",
2362 method_name, info->filename, method_type, info->stack->type);
2365 free (context_type);
2370 /* Add a static variant to a method. */
2373 tg_class_static_method_variant (void *p,
2374 const char *physname ATTRIBUTE_UNUSED,
2375 enum debug_visibility visibility,
2376 bfd_boolean constp, bfd_boolean volatilep)
2378 struct pr_handle *info = (struct pr_handle *) p;
2382 assert (info->stack != NULL);
2383 assert (info->stack->next != NULL);
2384 assert (info->stack->next->method != NULL);
2386 /* Put the const and volatile qualifiers on the type. */
2389 if (! append_type (info, " volatile"))
2394 if (! append_type (info, " const"))
2398 /* Mark it as static. */
2399 if (! prepend_type (info, "static "))
2402 method_name = strdup (info->stack->next->method);
2403 /* Stick the name of the method into its type. */
2404 if (! substitute_type (info, info->stack->next->method))
2411 method_type = pop_type (info);
2412 if (method_type == NULL)
2418 /* Now the top of the stack is the class. */
2419 if (! tg_fix_visibility (info, visibility))
2426 fprintf (info->f, "%s\t%s\t0;\"\tkind:p\ttype:%s\tclass:%s\taccess:%s\n",
2427 method_name, info->filename, method_type, info->stack->type,
2428 visibility_name (visibility));
2435 /* Finish up a class. */
2438 tg_end_class_type (void *p)
2440 struct pr_handle *info = (struct pr_handle *) p;
2442 fprintf (info->f, "%s\t%s\t0;\"\tkind:c\ttype:%s", info->stack->type,
2443 info->filename, info->stack->flavor);
2444 if (info->stack->num_parents)
2446 fprintf (info->f, "\tinherits:%s", info->stack->parents);
2447 free (info->stack->parents);
2449 fputc ('\n', info->f);
2451 return tg_end_struct_type (p);
2454 /* Push a type on the stack using a tag name. */
2457 tg_tag_type (void *p, const char *name, unsigned int id,
2458 enum debug_type_kind kind)
2460 struct pr_handle *info = (struct pr_handle *) p;
2461 const char *t, *tag;
2466 case DEBUG_KIND_STRUCT:
2469 case DEBUG_KIND_UNION:
2472 case DEBUG_KIND_ENUM:
2475 case DEBUG_KIND_CLASS:
2478 case DEBUG_KIND_UNION_CLASS:
2486 if (! push_type (info, t))
2492 sprintf (idbuf, "%%anon%u", id);
2496 if (! append_type (info, tag))
2502 /* Output a typedef. */
2505 tg_typdef (void *p, const char *name)
2507 struct pr_handle *info = (struct pr_handle *) p;
2510 s = pop_type (info);
2514 fprintf (info->f, "%s\t%s\t0;\"\tkind:t\ttype:%s\n", name,
2522 /* Output a tag. The tag should already be in the string on the
2523 stack, so all we have to do here is print it out. */
2526 tg_tag (void *p ATTRIBUTE_UNUSED, const char *name ATTRIBUTE_UNUSED)
2528 struct pr_handle *info = (struct pr_handle *) p;
2531 t = pop_type (info);
2539 /* Output an integer constant. */
2542 tg_int_constant (void *p, const char *name, bfd_vma val)
2544 struct pr_handle *info = (struct pr_handle *) p;
2548 print_vma (val, ab, FALSE, FALSE);
2549 fprintf (info->f, "%s\t%s\t0;\"\tkind:v\ttype:const int\tvalue:%s\n",
2550 name, info->filename, ab);
2554 /* Output a floating point constant. */
2557 tg_float_constant (void *p, const char *name, double val)
2559 struct pr_handle *info = (struct pr_handle *) p;
2562 fprintf (info->f, "%s\t%s\t0;\"\tkind:v\ttype:const double\tvalue:%g\n",
2563 name, info->filename, val);
2567 /* Output a typed constant. */
2570 tg_typed_constant (void *p, const char *name, bfd_vma val)
2572 struct pr_handle *info = (struct pr_handle *) p;
2576 t = pop_type (info);
2581 print_vma (val, ab, FALSE, FALSE);
2582 fprintf (info->f, "%s\t%s\t0;\"\tkind:v\ttype:const %s\tvalue:%s\n",
2583 name, info->filename, t, ab);
2590 /* Output a variable. */
2593 tg_variable (void *p, const char *name, enum debug_var_kind kind,
2594 bfd_vma val ATTRIBUTE_UNUSED)
2596 struct pr_handle *info = (struct pr_handle *) p;
2597 char *t, *dname, *from_class;
2599 t = pop_type (info);
2604 if (info->demangler)
2605 dname = info->demangler (info->abfd, name, demangle_flags);
2611 sep = strstr (dname, "::");
2619 /* Obscure types as vts and type_info nodes. */
2623 fprintf (info->f, "%s\t%s\t0;\"\tkind:v\ttype:%s", name, info->filename, t);
2628 case DEBUG_LOCAL_STATIC:
2629 fprintf (info->f, "\tfile:");
2631 case DEBUG_REGISTER:
2632 fprintf (info->f, "\tregister:");
2639 fprintf (info->f, "\tclass:%s", from_class);
2644 fprintf (info->f, "\n");
2651 /* Start outputting a function. */
2654 tg_start_function (void *p, const char *name, bfd_boolean global)
2656 struct pr_handle *info = (struct pr_handle *) p;
2660 info->stack->flavor = "static";
2662 info->stack->flavor = NULL;
2665 if (info->demangler)
2666 dname = info->demangler (info->abfd, name, demangle_flags);
2668 if (! substitute_type (info, dname ? dname : name))
2671 info->stack->method = NULL;
2675 sep = strstr (dname, "::");
2678 info->stack->method = dname;
2684 info->stack->method = "";
2687 sep = strchr (name, '(');
2690 /* Obscure functions as type_info function. */
2693 info->stack->parents = strdup (name);
2695 if (! info->stack->method && ! append_type (info, "("))
2698 info->parameter = 1;
2703 /* Output a function parameter. */
2706 tg_function_parameter (void *p, const char *name, enum debug_parm_kind kind,
2707 bfd_vma val ATTRIBUTE_UNUSED)
2709 struct pr_handle *info = (struct pr_handle *) p;
2712 if (kind == DEBUG_PARM_REFERENCE
2713 || kind == DEBUG_PARM_REF_REG)
2715 if (! pr_reference_type (p))
2719 if (! substitute_type (info, name))
2722 t = pop_type (info);
2726 if (! info->stack->method)
2728 if (info->parameter != 1 && ! append_type (info, ", "))
2731 if (kind == DEBUG_PARM_REG || kind == DEBUG_PARM_REF_REG)
2732 if (! append_type (info, "register "))
2735 if (! append_type (info, t))
2746 /* Start writing out a block. */
2749 tg_start_block (void *p, bfd_vma addr)
2751 struct pr_handle *info = (struct pr_handle *) p;
2752 char ab[22], kind, *partof;
2756 if (info->parameter > 0)
2758 info->parameter = 0;
2761 fprintf (info->f, "%s\t%s\t", info->stack->parents, info->filename);
2762 free (info->stack->parents);
2764 print_vma (addr, ab, TRUE, TRUE);
2765 translate_addresses (info->abfd, ab, info->f, info->syms);
2766 local = info->stack->flavor != NULL;
2767 if (info->stack->method && *info->stack->method)
2770 partof = (char *) info->stack->method;
2776 if (! info->stack->method && ! append_type (info, ")"))
2779 t = pop_type (info);
2782 fprintf (info->f, ";\"\tkind:%c\ttype:%s", kind, t);
2784 fputs ("\tfile:", info->f);
2787 fprintf (info->f, "\tclass:%s", partof);
2790 fputc ('\n', info->f);
2796 /* Write out line number information. */
2799 tg_lineno (void *p ATTRIBUTE_UNUSED, const char *fname ATTRIBUTE_UNUSED,
2800 unsigned long lineno ATTRIBUTE_UNUSED,
2801 bfd_vma addr ATTRIBUTE_UNUSED)
2806 /* Finish writing out a block. */
2809 tg_end_block (void *p ATTRIBUTE_UNUSED, bfd_vma addr ATTRIBUTE_UNUSED)
2814 /* Convert the visibility value into a human readable name. */
2817 visibility_name (enum debug_visibility visibility)
2823 case DEBUG_VISIBILITY_PUBLIC:
2826 case DEBUG_VISIBILITY_PRIVATE:
2829 case DEBUG_VISIBILITY_PROTECTED:
2832 case DEBUG_VISIBILITY_IGNORE: