1 /* prdbg.c -- Print out generic debugging information.
2 Copyright 1995, 1996, 1999, 2002, 2003, 2004, 2006, 2007
3 Free Software Foundation, Inc.
4 Written by Ian Lance Taylor <ian@cygnus.com>.
5 Tags style generation written by Salvador E. Tropea <set@computer.org>.
7 This file is part of GNU Binutils.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
24 /* This file prints out the generic debugging information, by
25 supplying a set of routines to debug_write. */
32 #include "libiberty.h"
37 /* This is the structure we use as a handle for these routines. */
41 /* File to print information to. */
43 /* Current indentation level. */
46 struct pr_stack *stack;
47 /* Parameter number we are about to output. */
49 /* The following are used only by the tags code (tg_). */
50 /* Name of the file we are using. */
54 /* The symbols table for this BFD. */
56 /* Pointer to a function to demangle symbols. */
57 char *(*demangler) (bfd *, const char *, int);
64 /* Next element on the stack. */
65 struct pr_stack *next;
68 /* Current visibility of fields if this is a class. */
69 enum debug_visibility visibility;
70 /* Name of the current method we are handling. */
72 /* The following are used only by the tags code (tg_). */
73 /* Type for the container (struct, union, class, union class). */
75 /* A comma separated list of parent classes. */
77 /* How many parents contains parents. */
81 static void indent (struct pr_handle *);
82 static bfd_boolean push_type (struct pr_handle *, const char *);
83 static bfd_boolean prepend_type (struct pr_handle *, const char *);
84 static bfd_boolean append_type (struct pr_handle *, const char *);
85 static bfd_boolean substitute_type (struct pr_handle *, const char *);
86 static bfd_boolean indent_type (struct pr_handle *);
87 static char *pop_type (struct pr_handle *);
88 static void print_vma (bfd_vma, char *, bfd_boolean, bfd_boolean);
89 static bfd_boolean pr_fix_visibility
90 (struct pr_handle *, enum debug_visibility);
91 static bfd_boolean pr_start_compilation_unit (void *, const char *);
92 static bfd_boolean pr_start_source (void *, const char *);
93 static bfd_boolean pr_empty_type (void *);
94 static bfd_boolean pr_void_type (void *);
95 static bfd_boolean pr_int_type (void *, unsigned int, bfd_boolean);
96 static bfd_boolean pr_float_type (void *, unsigned int);
97 static bfd_boolean pr_complex_type (void *, unsigned int);
98 static bfd_boolean pr_bool_type (void *, unsigned int);
99 static bfd_boolean pr_enum_type
100 (void *, const char *, const char **, bfd_signed_vma *);
101 static bfd_boolean pr_pointer_type (void *);
102 static bfd_boolean pr_function_type (void *, int, bfd_boolean);
103 static bfd_boolean pr_reference_type (void *);
104 static bfd_boolean pr_range_type (void *, bfd_signed_vma, bfd_signed_vma);
105 static bfd_boolean pr_array_type
106 (void *, bfd_signed_vma, bfd_signed_vma, bfd_boolean);
107 static bfd_boolean pr_set_type (void *, bfd_boolean);
108 static bfd_boolean pr_offset_type (void *);
109 static bfd_boolean pr_method_type (void *, bfd_boolean, int, bfd_boolean);
110 static bfd_boolean pr_const_type (void *);
111 static bfd_boolean pr_volatile_type (void *);
112 static bfd_boolean pr_start_struct_type
113 (void *, const char *, unsigned int, bfd_boolean, unsigned int);
114 static bfd_boolean pr_struct_field
115 (void *, const char *, bfd_vma, bfd_vma, enum debug_visibility);
116 static bfd_boolean pr_end_struct_type (void *);
117 static bfd_boolean pr_start_class_type
118 (void *, const char *, unsigned int, bfd_boolean, unsigned int,
119 bfd_boolean, bfd_boolean);
120 static bfd_boolean pr_class_static_member
121 (void *, const char *, const char *, enum debug_visibility);
122 static bfd_boolean pr_class_baseclass
123 (void *, bfd_vma, bfd_boolean, enum debug_visibility);
124 static bfd_boolean pr_class_start_method (void *, const char *);
125 static bfd_boolean pr_class_method_variant
126 (void *, const char *, enum debug_visibility, bfd_boolean, bfd_boolean,
127 bfd_vma, bfd_boolean);
128 static bfd_boolean pr_class_static_method_variant
129 (void *, const char *, enum debug_visibility, bfd_boolean, bfd_boolean);
130 static bfd_boolean pr_class_end_method (void *);
131 static bfd_boolean pr_end_class_type (void *);
132 static bfd_boolean pr_typedef_type (void *, const char *);
133 static bfd_boolean pr_tag_type
134 (void *, const char *, unsigned int, enum debug_type_kind);
135 static bfd_boolean pr_typdef (void *, const char *);
136 static bfd_boolean pr_tag (void *, const char *);
137 static bfd_boolean pr_int_constant (void *, const char *, bfd_vma);
138 static bfd_boolean pr_float_constant (void *, const char *, double);
139 static bfd_boolean pr_typed_constant (void *, const char *, bfd_vma);
140 static bfd_boolean pr_variable
141 (void *, const char *, enum debug_var_kind, bfd_vma);
142 static bfd_boolean pr_start_function (void *, const char *, bfd_boolean);
143 static bfd_boolean pr_function_parameter
144 (void *, const char *, enum debug_parm_kind, bfd_vma);
145 static bfd_boolean pr_start_block (void *, bfd_vma);
146 static bfd_boolean pr_end_block (void *, bfd_vma);
147 static bfd_boolean pr_end_function (void *);
148 static bfd_boolean pr_lineno (void *, const char *, unsigned long, bfd_vma);
149 static bfd_boolean append_parent (struct pr_handle *, const char *);
150 /* Only used by tg_ code. */
151 static bfd_boolean tg_fix_visibility
152 (struct pr_handle *, enum debug_visibility);
153 static void find_address_in_section (bfd *, asection *, void *);
154 static void translate_addresses (bfd *, char *, FILE *, asymbol **);
155 static const char *visibility_name (enum debug_visibility);
156 /* Tags style replacements. */
157 static bfd_boolean tg_start_compilation_unit (void *, const char *);
158 static bfd_boolean tg_start_source (void *, const char *);
159 static bfd_boolean tg_enum_type
160 (void *, const char *, const char **, bfd_signed_vma *);
161 static bfd_boolean tg_start_struct_type
162 (void *, const char *, unsigned int, bfd_boolean, unsigned int);
163 static bfd_boolean pr_struct_field
164 (void *, const char *, bfd_vma, bfd_vma, enum debug_visibility);
165 static bfd_boolean tg_struct_field
166 (void *, const char *, bfd_vma, bfd_vma, enum debug_visibility);
167 static bfd_boolean tg_struct_field
168 (void *, const char *, bfd_vma, bfd_vma, enum debug_visibility);
169 static bfd_boolean tg_end_struct_type (void *);
170 static bfd_boolean tg_start_class_type
171 (void *, const char *, unsigned int, bfd_boolean, unsigned int, bfd_boolean, bfd_boolean);
172 static bfd_boolean tg_class_static_member
173 (void *, const char *, const char *, enum debug_visibility);
174 static bfd_boolean tg_class_baseclass
175 (void *, bfd_vma, bfd_boolean, enum debug_visibility);
176 static bfd_boolean tg_class_method_variant
177 (void *, const char *, enum debug_visibility, bfd_boolean, bfd_boolean, bfd_vma, bfd_boolean);
178 static bfd_boolean tg_class_static_method_variant
179 (void *, const char *, enum debug_visibility, bfd_boolean, bfd_boolean);
180 static bfd_boolean tg_end_class_type (void *);
181 static bfd_boolean tg_tag_type
182 (void *, const char *, unsigned int, enum debug_type_kind);
183 static bfd_boolean tg_typdef (void *, const char *);
184 static bfd_boolean tg_tag (void *, const char *);
185 static bfd_boolean tg_int_constant (void *, const char *, bfd_vma);
186 static bfd_boolean tg_float_constant (void *, const char *, double);
187 static bfd_boolean tg_typed_constant (void *, const char *, bfd_vma);
188 static bfd_boolean tg_variable
189 (void *, const char *, enum debug_var_kind, bfd_vma);
190 static bfd_boolean tg_start_function (void *, const char *, bfd_boolean);
191 static bfd_boolean tg_function_parameter
192 (void *, const char *, enum debug_parm_kind, bfd_vma);
193 static bfd_boolean tg_start_block (void *, bfd_vma);
194 static bfd_boolean tg_end_block (void *, bfd_vma);
195 static bfd_boolean tg_lineno (void *, const char *, unsigned long, bfd_vma);
197 static const struct debug_write_fns pr_fns =
199 pr_start_compilation_unit,
218 pr_start_struct_type,
222 pr_class_static_member,
224 pr_class_start_method,
225 pr_class_method_variant,
226 pr_class_static_method_variant,
238 pr_function_parameter,
245 static const struct debug_write_fns tg_fns =
247 tg_start_compilation_unit,
249 pr_empty_type, /* Same, push_type. */
250 pr_void_type, /* Same, push_type. */
251 pr_int_type, /* Same, push_type. */
252 pr_float_type, /* Same, push_type. */
253 pr_complex_type, /* Same, push_type. */
254 pr_bool_type, /* Same, push_type. */
256 pr_pointer_type, /* Same, changes to pointer. */
257 pr_function_type, /* Same, push_type. */
258 pr_reference_type, /* Same, changes to reference. */
259 pr_range_type, /* FIXME: What's that?. */
260 pr_array_type, /* Same, push_type. */
261 pr_set_type, /* FIXME: What's that?. */
262 pr_offset_type, /* FIXME: What's that?. */
263 pr_method_type, /* Same. */
264 pr_const_type, /* Same, changes to const. */
265 pr_volatile_type, /* Same, changes to volatile. */
266 tg_start_struct_type,
270 tg_class_static_member,
272 pr_class_start_method, /* Same, remembers that's a method. */
273 tg_class_method_variant,
274 tg_class_static_method_variant,
275 pr_class_end_method, /* Same, forgets that's a method. */
277 pr_typedef_type, /* Same, just push type. */
281 tg_int_constant, /* Untested. */
282 tg_float_constant, /* Untested. */
283 tg_typed_constant, /* Untested. */
286 tg_function_parameter,
289 pr_end_function, /* Same, does nothing. */
293 /* Print out the generic debugging information recorded in dhandle. */
296 print_debugging_info (FILE *f, void *dhandle, bfd *abfd, asymbol **syms,
297 void *demangler, bfd_boolean as_tags)
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);
508 sprintf_vma (buf + 2, vma);
512 /* Start a new compilation unit. */
515 pr_start_compilation_unit (void *p, const char *filename)
517 struct pr_handle *info = (struct pr_handle *) p;
519 assert (info->indent == 0);
521 fprintf (info->f, "%s:\n", filename);
526 /* Start a source file within a compilation unit. */
529 pr_start_source (void *p, const char *filename)
531 struct pr_handle *info = (struct pr_handle *) p;
533 assert (info->indent == 0);
535 fprintf (info->f, " %s:\n", filename);
540 /* Push an empty type onto the type stack. */
543 pr_empty_type (void *p)
545 struct pr_handle *info = (struct pr_handle *) p;
547 return push_type (info, "<undefined>");
550 /* Push a void type onto the type stack. */
553 pr_void_type (void *p)
555 struct pr_handle *info = (struct pr_handle *) p;
557 return push_type (info, "void");
560 /* Push an integer type onto the type stack. */
563 pr_int_type (void *p, unsigned int size, bfd_boolean unsignedp)
565 struct pr_handle *info = (struct pr_handle *) p;
568 sprintf (ab, "%sint%d", unsignedp ? "u" : "", size * 8);
569 return push_type (info, ab);
572 /* Push a floating type onto the type stack. */
575 pr_float_type (void *p, unsigned int size)
577 struct pr_handle *info = (struct pr_handle *) p;
581 return push_type (info, "float");
583 return push_type (info, "double");
585 sprintf (ab, "float%d", size * 8);
586 return push_type (info, ab);
589 /* Push a complex type onto the type stack. */
592 pr_complex_type (void *p, unsigned int size)
594 struct pr_handle *info = (struct pr_handle *) p;
596 if (! pr_float_type (p, size))
599 return prepend_type (info, "complex ");
602 /* Push a bfd_boolean type onto the type stack. */
605 pr_bool_type (void *p, unsigned int size)
607 struct pr_handle *info = (struct pr_handle *) p;
610 sprintf (ab, "bool%d", size * 8);
612 return push_type (info, ab);
615 /* Push an enum type onto the type stack. */
618 pr_enum_type (void *p, const char *tag, const char **names,
619 bfd_signed_vma *values)
621 struct pr_handle *info = (struct pr_handle *) p;
625 if (! push_type (info, "enum "))
629 if (! append_type (info, tag)
630 || ! append_type (info, " "))
633 if (! append_type (info, "{ "))
638 if (! append_type (info, "/* undefined */"))
644 for (i = 0; names[i] != NULL; i++)
648 if (! append_type (info, ", "))
652 if (! append_type (info, names[i]))
655 if (values[i] != val)
659 print_vma (values[i], ab, FALSE, FALSE);
660 if (! append_type (info, " = ")
661 || ! append_type (info, ab))
670 return append_type (info, " }");
673 /* Turn the top type on the stack into a pointer. */
676 pr_pointer_type (void *p)
678 struct pr_handle *info = (struct pr_handle *) p;
681 assert (info->stack != NULL);
683 s = strchr (info->stack->type, '|');
684 if (s != NULL && s[1] == '[')
685 return substitute_type (info, "(*|)");
686 return substitute_type (info, "*|");
689 /* Turn the top type on the stack into a function returning that type. */
692 pr_function_type (void *p, int argcount, bfd_boolean varargs)
694 struct pr_handle *info = (struct pr_handle *) p;
699 assert (info->stack != NULL);
712 arg_types = (char **) xmalloc (argcount * sizeof *arg_types);
713 for (i = argcount - 1; i >= 0; i--)
715 if (! substitute_type (info, ""))
717 arg_types[i] = pop_type (info);
718 if (arg_types[i] == NULL)
720 len += strlen (arg_types[i]) + 2;
726 /* Now the return type is on the top of the stack. */
729 LITSTRCPY (s, "(|) (");
732 strcat (s, "/* unknown */");
737 for (i = 0; i < argcount; i++)
741 strcat (s, arg_types[i]);
755 if (! substitute_type (info, s))
763 /* Turn the top type on the stack into a reference to that type. */
766 pr_reference_type (void *p)
768 struct pr_handle *info = (struct pr_handle *) p;
770 assert (info->stack != NULL);
772 return substitute_type (info, "&|");
775 /* Make a range type. */
778 pr_range_type (void *p, bfd_signed_vma lower, bfd_signed_vma upper)
780 struct pr_handle *info = (struct pr_handle *) p;
781 char abl[20], abu[20];
783 assert (info->stack != NULL);
785 if (! substitute_type (info, ""))
788 print_vma (lower, abl, FALSE, FALSE);
789 print_vma (upper, abu, FALSE, FALSE);
791 return (prepend_type (info, "range (")
792 && append_type (info, "):")
793 && append_type (info, abl)
794 && append_type (info, ":")
795 && append_type (info, abu));
798 /* Make an array type. */
801 pr_array_type (void *p, bfd_signed_vma lower, bfd_signed_vma upper,
804 struct pr_handle *info = (struct pr_handle *) p;
806 char abl[20], abu[20], ab[50];
808 range_type = pop_type (info);
809 if (range_type == NULL)
818 print_vma (upper + 1, abu, FALSE, FALSE);
819 sprintf (ab, "|[%s]", abu);
824 print_vma (lower, abl, FALSE, FALSE);
825 print_vma (upper, abu, FALSE, FALSE);
826 sprintf (ab, "|[%s:%s]", abl, abu);
829 if (! substitute_type (info, ab))
832 if (strcmp (range_type, "int") != 0)
834 if (! append_type (info, ":")
835 || ! append_type (info, range_type))
841 if (! append_type (info, " /* string */"))
848 /* Make a set type. */
851 pr_set_type (void *p, bfd_boolean bitstringp)
853 struct pr_handle *info = (struct pr_handle *) p;
855 if (! substitute_type (info, ""))
858 if (! prepend_type (info, "set { ")
859 || ! append_type (info, " }"))
864 if (! append_type (info, "/* bitstring */"))
871 /* Make an offset type. */
874 pr_offset_type (void *p)
876 struct pr_handle *info = (struct pr_handle *) p;
879 if (! substitute_type (info, ""))
886 return (substitute_type (info, "")
887 && prepend_type (info, " ")
888 && prepend_type (info, t)
889 && append_type (info, "::|"));
892 /* Make a method type. */
895 pr_method_type (void *p, bfd_boolean domain, int argcount, bfd_boolean varargs)
897 struct pr_handle *info = (struct pr_handle *) p;
909 if (! substitute_type (info, ""))
911 domain_type = pop_type (info);
912 if (domain_type == NULL)
914 if (CONST_STRNEQ (domain_type, "class ")
915 && strchr (domain_type + sizeof "class " - 1, ' ') == NULL)
916 domain_type += sizeof "class " - 1;
917 else if (CONST_STRNEQ (domain_type, "union class ")
918 && (strchr (domain_type + sizeof "union class " - 1, ' ')
920 domain_type += sizeof "union class " - 1;
921 len += strlen (domain_type);
933 arg_types = (char **) xmalloc (argcount * sizeof *arg_types);
934 for (i = argcount - 1; i >= 0; i--)
936 if (! substitute_type (info, ""))
938 arg_types[i] = pop_type (info);
939 if (arg_types[i] == NULL)
941 len += strlen (arg_types[i]) + 2;
947 /* Now the return type is on the top of the stack. */
949 s = (char *) xmalloc (len);
953 strcpy (s, domain_type);
957 strcat (s, "/* unknown */");
962 for (i = 0; i < argcount; i++)
966 strcat (s, arg_types[i]);
980 if (! substitute_type (info, s))
988 /* Make a const qualified type. */
991 pr_const_type (void *p)
993 struct pr_handle *info = (struct pr_handle *) p;
995 return substitute_type (info, "const |");
998 /* Make a volatile qualified type. */
1001 pr_volatile_type (void *p)
1003 struct pr_handle *info = (struct pr_handle *) p;
1005 return substitute_type (info, "volatile |");
1008 /* Start accumulating a struct type. */
1011 pr_start_struct_type (void *p, const char *tag, unsigned int id,
1012 bfd_boolean structp, unsigned int size)
1014 struct pr_handle *info = (struct pr_handle *) p;
1018 if (! push_type (info, structp ? "struct " : "union "))
1022 if (! append_type (info, tag))
1029 sprintf (idbuf, "%%anon%u", id);
1030 if (! append_type (info, idbuf))
1034 if (! append_type (info, " {"))
1036 if (size != 0 || tag != NULL)
1040 if (! append_type (info, " /*"))
1045 sprintf (ab, " size %u", size);
1046 if (! append_type (info, ab))
1051 sprintf (ab, " id %u", id);
1052 if (! append_type (info, ab))
1055 if (! append_type (info, " */"))
1058 if (! append_type (info, "\n"))
1061 info->stack->visibility = DEBUG_VISIBILITY_PUBLIC;
1063 return indent_type (info);
1066 /* Output the visibility of a field in a struct. */
1069 pr_fix_visibility (struct pr_handle *info, enum debug_visibility visibility)
1071 const char *s = NULL;
1075 assert (info->stack != NULL);
1077 if (info->stack->visibility == visibility)
1082 case DEBUG_VISIBILITY_PUBLIC:
1085 case DEBUG_VISIBILITY_PRIVATE:
1088 case DEBUG_VISIBILITY_PROTECTED:
1091 case DEBUG_VISIBILITY_IGNORE:
1099 /* Trim off a trailing space in the struct string, to make the
1100 output look a bit better, then stick on the visibility string. */
1102 t = info->stack->type;
1104 assert (t[len - 1] == ' ');
1107 if (! append_type (info, s)
1108 || ! append_type (info, ":\n")
1109 || ! indent_type (info))
1112 info->stack->visibility = visibility;
1117 /* Add a field to a struct type. */
1120 pr_struct_field (void *p, const char *name, bfd_vma bitpos, bfd_vma bitsize,
1121 enum debug_visibility visibility)
1123 struct pr_handle *info = (struct pr_handle *) p;
1127 if (! substitute_type (info, name))
1130 if (! append_type (info, "; /* "))
1135 print_vma (bitsize, ab, TRUE, FALSE);
1136 if (! append_type (info, "bitsize ")
1137 || ! append_type (info, ab)
1138 || ! append_type (info, ", "))
1142 print_vma (bitpos, ab, TRUE, FALSE);
1143 if (! append_type (info, "bitpos ")
1144 || ! append_type (info, ab)
1145 || ! append_type (info, " */\n")
1146 || ! indent_type (info))
1149 t = pop_type (info);
1153 if (! pr_fix_visibility (info, visibility))
1156 return append_type (info, t);
1159 /* Finish a struct type. */
1162 pr_end_struct_type (void *p)
1164 struct pr_handle *info = (struct pr_handle *) p;
1167 assert (info->stack != NULL);
1168 assert (info->indent >= 2);
1172 /* Change the trailing indentation to have a close brace. */
1173 s = info->stack->type + strlen (info->stack->type) - 2;
1174 assert (s[0] == ' ' && s[1] == ' ' && s[2] == '\0');
1182 /* Start a class type. */
1185 pr_start_class_type (void *p, const char *tag, unsigned int id,
1186 bfd_boolean structp, unsigned int size,
1187 bfd_boolean vptr, bfd_boolean ownvptr)
1189 struct pr_handle *info = (struct pr_handle *) p;
1194 if (vptr && ! ownvptr)
1196 tv = pop_type (info);
1201 if (! push_type (info, structp ? "class " : "union class "))
1205 if (! append_type (info, tag))
1212 sprintf (idbuf, "%%anon%u", id);
1213 if (! append_type (info, idbuf))
1217 if (! append_type (info, " {"))
1219 if (size != 0 || vptr || ownvptr || tag != NULL)
1221 if (! append_type (info, " /*"))
1228 sprintf (ab, "%u", size);
1229 if (! append_type (info, " size ")
1230 || ! append_type (info, ab))
1236 if (! append_type (info, " vtable "))
1240 if (! append_type (info, "self "))
1245 if (! append_type (info, tv)
1246 || ! append_type (info, " "))
1255 sprintf (ab, " id %u", id);
1256 if (! append_type (info, ab))
1260 if (! append_type (info, " */"))
1264 info->stack->visibility = DEBUG_VISIBILITY_PRIVATE;
1266 return (append_type (info, "\n")
1267 && indent_type (info));
1270 /* Add a static member to a class. */
1273 pr_class_static_member (void *p, const char *name, const char *physname,
1274 enum debug_visibility visibility)
1276 struct pr_handle *info = (struct pr_handle *) p;
1279 if (! substitute_type (info, name))
1282 if (! prepend_type (info, "static ")
1283 || ! append_type (info, "; /* ")
1284 || ! append_type (info, physname)
1285 || ! append_type (info, " */\n")
1286 || ! indent_type (info))
1289 t = pop_type (info);
1293 if (! pr_fix_visibility (info, visibility))
1296 return append_type (info, t);
1299 /* Add a base class to a class. */
1302 pr_class_baseclass (void *p, bfd_vma bitpos, bfd_boolean virtual,
1303 enum debug_visibility visibility)
1305 struct pr_handle *info = (struct pr_handle *) p;
1311 assert (info->stack != NULL && info->stack->next != NULL);
1313 if (! substitute_type (info, ""))
1316 t = pop_type (info);
1320 if (CONST_STRNEQ (t, "class "))
1321 t += sizeof "class " - 1;
1323 /* Push it back on to take advantage of the prepend_type and
1324 append_type routines. */
1325 if (! push_type (info, t))
1330 if (! prepend_type (info, "virtual "))
1336 case DEBUG_VISIBILITY_PUBLIC:
1339 case DEBUG_VISIBILITY_PROTECTED:
1340 prefix = "protected ";
1342 case DEBUG_VISIBILITY_PRIVATE:
1343 prefix = "private ";
1346 prefix = "/* unknown visibility */ ";
1350 if (! prepend_type (info, prefix))
1355 print_vma (bitpos, ab, TRUE, FALSE);
1356 if (! append_type (info, " /* bitpos ")
1357 || ! append_type (info, ab)
1358 || ! append_type (info, " */"))
1362 /* Now the top of the stack is something like "public A / * bitpos
1363 10 * /". The next element on the stack is something like "class
1364 xx { / * size 8 * /\n...". We want to substitute the top of the
1365 stack in before the {. */
1366 s = strchr (info->stack->next->type, '{');
1370 /* If there is already a ':', then we already have a baseclass, and
1371 we must append this one after a comma. */
1372 for (l = info->stack->next->type; l != s; l++)
1375 if (! prepend_type (info, l == s ? " : " : ", "))
1378 t = pop_type (info);
1382 n = (char *) xmalloc (strlen (info->stack->type) + strlen (t) + 1);
1383 memcpy (n, info->stack->type, s - info->stack->type);
1384 strcpy (n + (s - info->stack->type), t);
1387 free (info->stack->type);
1388 info->stack->type = n;
1395 /* Start adding a method to a class. */
1398 pr_class_start_method (void *p, const char *name)
1400 struct pr_handle *info = (struct pr_handle *) p;
1402 assert (info->stack != NULL);
1403 info->stack->method = name;
1407 /* Add a variant to a method. */
1410 pr_class_method_variant (void *p, const char *physname,
1411 enum debug_visibility visibility,
1412 bfd_boolean constp, bfd_boolean volatilep,
1413 bfd_vma voffset, bfd_boolean context)
1415 struct pr_handle *info = (struct pr_handle *) p;
1419 assert (info->stack != NULL);
1420 assert (info->stack->next != NULL);
1422 /* Put the const and volatile qualifiers on the type. */
1425 if (! append_type (info, " volatile"))
1430 if (! append_type (info, " const"))
1434 /* Stick the name of the method into its type. */
1435 if (! substitute_type (info,
1437 ? info->stack->next->next->method
1438 : info->stack->next->method)))
1442 method_type = pop_type (info);
1443 if (method_type == NULL)
1446 /* Pull off the context type if there is one. */
1448 context_type = NULL;
1451 context_type = pop_type (info);
1452 if (context_type == NULL)
1456 /* Now the top of the stack is the class. */
1458 if (! pr_fix_visibility (info, visibility))
1461 if (! append_type (info, method_type)
1462 || ! append_type (info, " /* ")
1463 || ! append_type (info, physname)
1464 || ! append_type (info, " "))
1466 if (context || voffset != 0)
1472 if (! append_type (info, "context ")
1473 || ! append_type (info, context_type)
1474 || ! append_type (info, " "))
1477 print_vma (voffset, ab, TRUE, FALSE);
1478 if (! append_type (info, "voffset ")
1479 || ! append_type (info, ab))
1483 return (append_type (info, " */;\n")
1484 && indent_type (info));
1487 /* Add a static variant to a method. */
1490 pr_class_static_method_variant (void *p, const char *physname,
1491 enum debug_visibility visibility,
1492 bfd_boolean constp, bfd_boolean volatilep)
1494 struct pr_handle *info = (struct pr_handle *) p;
1497 assert (info->stack != NULL);
1498 assert (info->stack->next != NULL);
1499 assert (info->stack->next->method != NULL);
1501 /* Put the const and volatile qualifiers on the type. */
1504 if (! append_type (info, " volatile"))
1509 if (! append_type (info, " const"))
1513 /* Mark it as static. */
1514 if (! prepend_type (info, "static "))
1517 /* Stick the name of the method into its type. */
1518 if (! substitute_type (info, info->stack->next->method))
1522 method_type = pop_type (info);
1523 if (method_type == NULL)
1526 /* Now the top of the stack is the class. */
1528 if (! pr_fix_visibility (info, visibility))
1531 return (append_type (info, method_type)
1532 && append_type (info, " /* ")
1533 && append_type (info, physname)
1534 && append_type (info, " */;\n")
1535 && indent_type (info));
1538 /* Finish up a method. */
1541 pr_class_end_method (void *p)
1543 struct pr_handle *info = (struct pr_handle *) p;
1545 info->stack->method = NULL;
1549 /* Finish up a class. */
1552 pr_end_class_type (void *p)
1554 return pr_end_struct_type (p);
1557 /* Push a type on the stack using a typedef name. */
1560 pr_typedef_type (void *p, const char *name)
1562 struct pr_handle *info = (struct pr_handle *) p;
1564 return push_type (info, name);
1567 /* Push a type on the stack using a tag name. */
1570 pr_tag_type (void *p, const char *name, unsigned int id,
1571 enum debug_type_kind kind)
1573 struct pr_handle *info = (struct pr_handle *) p;
1574 const char *t, *tag;
1579 case DEBUG_KIND_STRUCT:
1582 case DEBUG_KIND_UNION:
1585 case DEBUG_KIND_ENUM:
1588 case DEBUG_KIND_CLASS:
1591 case DEBUG_KIND_UNION_CLASS:
1599 if (! push_type (info, t))
1605 sprintf (idbuf, "%%anon%u", id);
1609 if (! append_type (info, tag))
1611 if (name != NULL && kind != DEBUG_KIND_ENUM)
1613 sprintf (idbuf, " /* id %u */", id);
1614 if (! append_type (info, idbuf))
1621 /* Output a typedef. */
1624 pr_typdef (void *p, const char *name)
1626 struct pr_handle *info = (struct pr_handle *) p;
1629 if (! substitute_type (info, name))
1632 s = pop_type (info);
1637 fprintf (info->f, "typedef %s;\n", s);
1644 /* Output a tag. The tag should already be in the string on the
1645 stack, so all we have to do here is print it out. */
1648 pr_tag (void *p, const char *name ATTRIBUTE_UNUSED)
1650 struct pr_handle *info = (struct pr_handle *) p;
1653 t = pop_type (info);
1658 fprintf (info->f, "%s;\n", t);
1665 /* Output an integer constant. */
1668 pr_int_constant (void *p, const char *name, bfd_vma val)
1670 struct pr_handle *info = (struct pr_handle *) p;
1674 print_vma (val, ab, FALSE, FALSE);
1675 fprintf (info->f, "const int %s = %s;\n", name, ab);
1679 /* Output a floating point constant. */
1682 pr_float_constant (void *p, const char *name, double val)
1684 struct pr_handle *info = (struct pr_handle *) p;
1687 fprintf (info->f, "const double %s = %g;\n", name, val);
1691 /* Output a typed constant. */
1694 pr_typed_constant (void *p, const char *name, bfd_vma val)
1696 struct pr_handle *info = (struct pr_handle *) p;
1700 t = pop_type (info);
1705 print_vma (val, ab, FALSE, FALSE);
1706 fprintf (info->f, "const %s %s = %s;\n", t, name, ab);
1713 /* Output a variable. */
1716 pr_variable (void *p, const char *name, enum debug_var_kind kind,
1719 struct pr_handle *info = (struct pr_handle *) p;
1723 if (! substitute_type (info, name))
1726 t = pop_type (info);
1734 case DEBUG_LOCAL_STATIC:
1735 fprintf (info->f, "static ");
1737 case DEBUG_REGISTER:
1738 fprintf (info->f, "register ");
1743 print_vma (val, ab, TRUE, TRUE);
1744 fprintf (info->f, "%s /* %s */;\n", t, ab);
1751 /* Start outputting a function. */
1754 pr_start_function (void *p, const char *name, bfd_boolean global)
1756 struct pr_handle *info = (struct pr_handle *) p;
1759 if (! substitute_type (info, name))
1762 t = pop_type (info);
1768 fprintf (info->f, "static ");
1769 fprintf (info->f, "%s (", t);
1771 info->parameter = 1;
1776 /* Output a function parameter. */
1779 pr_function_parameter (void *p, const char *name,
1780 enum debug_parm_kind kind, bfd_vma val)
1782 struct pr_handle *info = (struct pr_handle *) p;
1786 if (kind == DEBUG_PARM_REFERENCE
1787 || kind == DEBUG_PARM_REF_REG)
1789 if (! pr_reference_type (p))
1793 if (! substitute_type (info, name))
1796 t = pop_type (info);
1800 if (info->parameter != 1)
1801 fprintf (info->f, ", ");
1803 if (kind == DEBUG_PARM_REG || kind == DEBUG_PARM_REF_REG)
1804 fprintf (info->f, "register ");
1806 print_vma (val, ab, TRUE, TRUE);
1807 fprintf (info->f, "%s /* %s */", t, ab);
1816 /* Start writing out a block. */
1819 pr_start_block (void *p, bfd_vma addr)
1821 struct pr_handle *info = (struct pr_handle *) p;
1824 if (info->parameter > 0)
1826 fprintf (info->f, ")\n");
1827 info->parameter = 0;
1831 print_vma (addr, ab, TRUE, TRUE);
1832 fprintf (info->f, "{ /* %s */\n", ab);
1839 /* Write out line number information. */
1842 pr_lineno (void *p, const char *filename, unsigned long lineno, bfd_vma addr)
1844 struct pr_handle *info = (struct pr_handle *) p;
1848 print_vma (addr, ab, TRUE, TRUE);
1849 fprintf (info->f, "/* file %s line %lu addr %s */\n", filename, lineno, ab);
1854 /* Finish writing out a block. */
1857 pr_end_block (void *p, bfd_vma addr)
1859 struct pr_handle *info = (struct pr_handle *) p;
1865 print_vma (addr, ab, TRUE, TRUE);
1866 fprintf (info->f, "} /* %s */\n", ab);
1871 /* Finish writing out a function. */
1874 pr_end_function (void *p ATTRIBUTE_UNUSED)
1879 /* Tags style generation functions start here. */
1881 /* Variables for address to line translation. */
1883 static const char *filename;
1884 static const char *functionname;
1885 static unsigned int line;
1886 static bfd_boolean found;
1888 /* Look for an address in a section. This is called via
1889 bfd_map_over_sections. */
1892 find_address_in_section (bfd *abfd, asection *section, void *data)
1896 asymbol **syms = (asymbol **) data;
1901 if ((bfd_get_section_flags (abfd, section) & SEC_ALLOC) == 0)
1904 vma = bfd_get_section_vma (abfd, section);
1908 size = bfd_get_section_size (section);
1909 if (pc >= vma + size)
1912 found = bfd_find_nearest_line (abfd, section, syms, pc - vma,
1913 &filename, &functionname, &line);
1917 translate_addresses (bfd *abfd, char *addr_hex, FILE *f, asymbol **syms)
1919 pc = bfd_scan_vma (addr_hex, NULL, 16);
1921 bfd_map_over_sections (abfd, find_address_in_section, syms);
1926 fprintf (f, "%u", line);
1929 /* Start a new compilation unit. */
1932 tg_start_compilation_unit (void * p, const char *filename ATTRIBUTE_UNUSED)
1934 struct pr_handle *info = (struct pr_handle *) p;
1936 fprintf (stderr, "New compilation unit: %s\n", filename);
1938 free (info->filename);
1939 /* Should it be relative? best way to do it here?. */
1940 info->filename = strdup (filename);
1945 /* Start a source file within a compilation unit. */
1948 tg_start_source (void *p, const char *filename)
1950 struct pr_handle *info = (struct pr_handle *) p;
1952 free (info->filename);
1953 /* Should it be relative? best way to do it here?. */
1954 info->filename = strdup (filename);
1959 /* Push an enum type onto the type stack. */
1962 tg_enum_type (void *p, const char *tag, const char **names,
1963 bfd_signed_vma *values)
1965 struct pr_handle *info = (struct pr_handle *) p;
1970 if (! pr_enum_type (p, tag, names, values))
1973 name = tag ? tag : "unknown";
1974 /* Generate an entry for the enum. */
1976 fprintf (info->f, "%s\t%s\t0;\"\tkind:e\ttype:%s\n", tag,
1977 info->filename, info->stack->type);
1979 /* Generate entries for the values. */
1982 for (i = 0; names[i] != NULL; i++)
1984 print_vma (values[i], ab, FALSE, FALSE);
1985 fprintf (info->f, "%s\t%s\t0;\"\tkind:g\tenum:%s\tvalue:%s\n",
1986 names[i], info->filename, name, ab);
1993 /* Start accumulating a struct type. */
1996 tg_start_struct_type (void *p, const char *tag, unsigned int id,
1997 bfd_boolean structp,
1998 unsigned int size ATTRIBUTE_UNUSED)
2000 struct pr_handle *info = (struct pr_handle *) p;
2009 sprintf (idbuf, "%%anon%u", id);
2012 if (! push_type (info, name))
2015 info->stack->flavor = structp ? "struct" : "union";
2017 fprintf (info->f, "%s\t%s\t0;\"\tkind:%c\n", name, info->filename,
2018 info->stack->flavor[0]);
2020 info->stack->visibility = DEBUG_VISIBILITY_PUBLIC;
2022 return indent_type (info);
2025 /* Output the visibility of a field in a struct. */
2028 tg_fix_visibility (struct pr_handle *info, enum debug_visibility visibility)
2030 assert (info->stack != NULL);
2032 if (info->stack->visibility == visibility)
2035 assert (info->stack->visibility != DEBUG_VISIBILITY_IGNORE);
2037 info->stack->visibility = visibility;
2042 /* Add a field to a struct type. */
2045 tg_struct_field (void *p, const char *name, bfd_vma bitpos ATTRIBUTE_UNUSED,
2046 bfd_vma bitsize ATTRIBUTE_UNUSED,
2047 enum debug_visibility visibility)
2049 struct pr_handle *info = (struct pr_handle *) p;
2052 t = pop_type (info);
2056 if (! tg_fix_visibility (info, visibility))
2059 /* It happens, a bug? */
2063 fprintf (info->f, "%s\t%s\t0;\"\tkind:m\ttype:%s\t%s:%s\taccess:%s\n",
2064 name, info->filename, t, info->stack->flavor, info->stack->type,
2065 visibility_name (visibility));
2070 /* Finish a struct type. */
2073 tg_end_struct_type (void *p ATTRIBUTE_UNUSED)
2075 struct pr_handle *info = (struct pr_handle *) p;
2076 assert (info->stack != NULL);
2081 /* Start a class type. */
2084 tg_start_class_type (void *p, const char *tag, unsigned int id,
2085 bfd_boolean structp, unsigned int size,
2086 bfd_boolean vptr, bfd_boolean ownvptr)
2088 struct pr_handle *info = (struct pr_handle *) p;
2094 if (vptr && ! ownvptr)
2096 tv = pop_type (info);
2107 sprintf (idbuf, "%%anon%u", id);
2111 if (! push_type (info, name))
2114 info->stack->flavor = structp ? "class" : "union class";
2115 info->stack->parents = NULL;
2116 info->stack->num_parents = 0;
2118 if (size != 0 || vptr || ownvptr || tag != NULL)
2122 if (! append_type (info, " vtable "))
2126 if (! append_type (info, "self "))
2131 if (! append_type (info, tv)
2132 || ! append_type (info, " "))
2138 info->stack->visibility = DEBUG_VISIBILITY_PRIVATE;
2143 /* Add a static member to a class. */
2146 tg_class_static_member (void *p, const char *name,
2147 const char *physname ATTRIBUTE_UNUSED,
2148 enum debug_visibility visibility)
2150 struct pr_handle *info = (struct pr_handle *) p;
2152 int len_var, len_class;
2155 len_var = strlen (name);
2156 len_class = strlen (info->stack->next->type);
2157 full_name = xmalloc (len_var + len_class + 3);
2160 sprintf (full_name, "%s::%s", info->stack->next->type, name);
2162 if (! substitute_type (info, full_name))
2165 if (! prepend_type (info, "static "))
2168 t = pop_type (info);
2172 if (! tg_fix_visibility (info, visibility))
2175 fprintf (info->f, "%s\t%s\t0;\"\tkind:x\ttype:%s\tclass:%s\taccess:%s\n",
2176 name, info->filename, t, info->stack->type,
2177 visibility_name (visibility));
2184 /* Add a base class to a class. */
2187 tg_class_baseclass (void *p, bfd_vma bitpos ATTRIBUTE_UNUSED,
2188 bfd_boolean virtual, enum debug_visibility visibility)
2190 struct pr_handle *info = (struct pr_handle *) p;
2194 assert (info->stack != NULL && info->stack->next != NULL);
2196 t = pop_type (info);
2200 if (CONST_STRNEQ (t, "class "))
2201 t += sizeof "class " - 1;
2203 /* Push it back on to take advantage of the prepend_type and
2204 append_type routines. */
2205 if (! push_type (info, t))
2210 if (! prepend_type (info, "virtual "))
2216 case DEBUG_VISIBILITY_PUBLIC:
2219 case DEBUG_VISIBILITY_PROTECTED:
2220 prefix = "protected ";
2222 case DEBUG_VISIBILITY_PRIVATE:
2223 prefix = "private ";
2226 prefix = "/* unknown visibility */ ";
2230 if (! prepend_type (info, prefix))
2233 t = pop_type (info);
2237 if (info->stack->num_parents && ! append_parent (info, ", "))
2240 if (! append_parent (info, t))
2242 info->stack->num_parents++;
2249 /* Add a variant to a method. */
2252 tg_class_method_variant (void *p, const char *physname ATTRIBUTE_UNUSED,
2253 enum debug_visibility visibility,
2254 bfd_boolean constp, bfd_boolean volatilep,
2255 bfd_vma voffset ATTRIBUTE_UNUSED,
2256 bfd_boolean context)
2258 struct pr_handle *info = (struct pr_handle *) p;
2263 assert (info->stack != NULL);
2264 assert (info->stack->next != NULL);
2266 /* Put the const and volatile qualifiers on the type. */
2269 if (! append_type (info, " volatile"))
2274 if (! append_type (info, " const"))
2278 method_name = strdup (context ? info->stack->next->next->method
2279 : info->stack->next->method);
2281 /* Stick the name of the method into its type. */
2282 if (! substitute_type (info, method_name))
2286 method_type = pop_type (info);
2287 if (method_type == NULL)
2290 /* Pull off the context type if there is one. */
2292 context_type = NULL;
2295 context_type = pop_type (info);
2296 if (context_type == NULL)
2300 /* Now the top of the stack is the class. */
2301 if (! tg_fix_visibility (info, visibility))
2304 fprintf (info->f, "%s\t%s\t0;\"\tkind:p\ttype:%s\tclass:%s\n",
2305 method_name, info->filename, method_type, info->stack->type);
2308 free (context_type);
2313 /* Add a static variant to a method. */
2316 tg_class_static_method_variant (void *p,
2317 const char *physname ATTRIBUTE_UNUSED,
2318 enum debug_visibility visibility,
2319 bfd_boolean constp, bfd_boolean volatilep)
2321 struct pr_handle *info = (struct pr_handle *) p;
2325 assert (info->stack != NULL);
2326 assert (info->stack->next != NULL);
2327 assert (info->stack->next->method != NULL);
2329 /* Put the const and volatile qualifiers on the type. */
2332 if (! append_type (info, " volatile"))
2337 if (! append_type (info, " const"))
2341 /* Mark it as static. */
2342 if (! prepend_type (info, "static "))
2345 method_name = strdup (info->stack->next->method);
2346 /* Stick the name of the method into its type. */
2347 if (! substitute_type (info, info->stack->next->method))
2351 method_type = pop_type (info);
2352 if (method_type == NULL)
2355 /* Now the top of the stack is the class. */
2356 if (! tg_fix_visibility (info, visibility))
2359 fprintf (info->f, "%s\t%s\t0;\"\tkind:p\ttype:%s\tclass:%s\taccess:%s\n",
2360 method_name, info->filename, method_type, info->stack->type,
2361 visibility_name (visibility));
2368 /* Finish up a class. */
2371 tg_end_class_type (void *p)
2373 struct pr_handle *info = (struct pr_handle *) p;
2375 fprintf (info->f, "%s\t%s\t0;\"\tkind:c\ttype:%s", info->stack->type,
2376 info->filename, info->stack->flavor);
2377 if (info->stack->num_parents)
2379 fprintf (info->f, "\tinherits:%s", info->stack->parents);
2380 free (info->stack->parents);
2382 fputc ('\n', info->f);
2384 return tg_end_struct_type (p);
2387 /* Push a type on the stack using a tag name. */
2390 tg_tag_type (void *p, const char *name, unsigned int id,
2391 enum debug_type_kind kind)
2393 struct pr_handle *info = (struct pr_handle *) p;
2394 const char *t, *tag;
2399 case DEBUG_KIND_STRUCT:
2402 case DEBUG_KIND_UNION:
2405 case DEBUG_KIND_ENUM:
2408 case DEBUG_KIND_CLASS:
2411 case DEBUG_KIND_UNION_CLASS:
2419 if (! push_type (info, t))
2425 sprintf (idbuf, "%%anon%u", id);
2429 if (! append_type (info, tag))
2435 /* Output a typedef. */
2438 tg_typdef (void *p, const char *name)
2440 struct pr_handle *info = (struct pr_handle *) p;
2443 s = pop_type (info);
2447 fprintf (info->f, "%s\t%s\t0;\"\tkind:t\ttype:%s\n", name,
2455 /* Output a tag. The tag should already be in the string on the
2456 stack, so all we have to do here is print it out. */
2459 tg_tag (void *p ATTRIBUTE_UNUSED, const char *name ATTRIBUTE_UNUSED)
2461 struct pr_handle *info = (struct pr_handle *) p;
2464 t = pop_type (info);
2472 /* Output an integer constant. */
2475 tg_int_constant (void *p, const char *name, bfd_vma val)
2477 struct pr_handle *info = (struct pr_handle *) p;
2481 print_vma (val, ab, FALSE, FALSE);
2482 fprintf (info->f, "%s\t%s\t0;\"\tkind:v\ttype:const int\tvalue:%s\n",
2483 name, info->filename, ab);
2487 /* Output a floating point constant. */
2490 tg_float_constant (void *p, const char *name, double val)
2492 struct pr_handle *info = (struct pr_handle *) p;
2495 fprintf (info->f, "%s\t%s\t0;\"\tkind:v\ttype:const double\tvalue:%g\n",
2496 name, info->filename, val);
2500 /* Output a typed constant. */
2503 tg_typed_constant (void *p, const char *name, bfd_vma val)
2505 struct pr_handle *info = (struct pr_handle *) p;
2509 t = pop_type (info);
2514 print_vma (val, ab, FALSE, FALSE);
2515 fprintf (info->f, "%s\t%s\t0;\"\tkind:v\ttype:const %s\tvalue:%s\n",
2516 name, info->filename, t, ab);
2523 /* Output a variable. */
2526 tg_variable (void *p, const char *name, enum debug_var_kind kind,
2527 bfd_vma val ATTRIBUTE_UNUSED)
2529 struct pr_handle *info = (struct pr_handle *) p;
2531 const char *dname, *from_class;
2533 t = pop_type (info);
2538 if (info->demangler)
2540 dname = info->demangler (info->abfd, name, DMGL_ANSI | DMGL_PARAMS);
2541 if (strcmp (name, dname) == 0)
2543 free ((char *) dname);
2551 sep = strstr (dname, "::");
2560 /* Obscure types as vts and type_info nodes. */
2568 fprintf (info->f, "%s\t%s\t0;\"\tkind:v\ttype:%s", name, info->filename, t);
2573 case DEBUG_LOCAL_STATIC:
2574 fprintf (info->f, "\tfile:");
2576 case DEBUG_REGISTER:
2577 fprintf (info->f, "\tregister:");
2585 fprintf (info->f, "\tclass:%s",from_class);
2586 free ((char *) dname);
2589 fprintf (info->f, "\n");
2596 /* Start outputting a function. */
2599 tg_start_function (void *p, const char *name, bfd_boolean global)
2601 struct pr_handle *info = (struct pr_handle *) p;
2605 info->stack->flavor = "static";
2607 info->stack->flavor = NULL;
2610 if (info->demangler)
2612 dname = info->demangler (info->abfd, name, DMGL_ANSI | DMGL_PARAMS);
2613 if (strcmp (name, dname) == 0)
2615 free ((char *) dname);
2620 if (! substitute_type (info, dname))
2626 sep = strstr (dname, "::");
2629 info->stack->method = dname;
2635 info->stack->method = "";
2638 sep = strchr (name, '(');
2641 /* Obscure functions as type_info function. */
2644 info->stack->method = NULL;
2646 info->stack->parents = strdup (name);
2648 if (! info->stack->method && ! append_type (info, "("))
2651 info->parameter = 1;
2656 /* Output a function parameter. */
2659 tg_function_parameter (void *p, const char *name, enum debug_parm_kind kind,
2660 bfd_vma val ATTRIBUTE_UNUSED)
2662 struct pr_handle *info = (struct pr_handle *) p;
2665 if (kind == DEBUG_PARM_REFERENCE
2666 || kind == DEBUG_PARM_REF_REG)
2668 if (! pr_reference_type (p))
2672 if (! substitute_type (info, name))
2675 t = pop_type (info);
2679 if (! info->stack->method)
2681 if (info->parameter != 1 && ! append_type (info, ", "))
2684 if (kind == DEBUG_PARM_REG || kind == DEBUG_PARM_REF_REG)
2685 if (! append_type (info, "register "))
2688 if (! append_type (info, t))
2699 /* Start writing out a block. */
2702 tg_start_block (void *p, bfd_vma addr)
2704 struct pr_handle *info = (struct pr_handle *) p;
2705 char ab[20], kind, *partof;
2709 if (info->parameter > 0)
2711 info->parameter = 0;
2714 fprintf (info->f, "%s\t%s\t", info->stack->parents, info->filename);
2715 free (info->stack->parents);
2717 print_vma (addr, ab, TRUE, TRUE);
2718 translate_addresses (info->abfd, ab, info->f, info->syms);
2719 local = info->stack->flavor != NULL;
2720 if (info->stack->method && *info->stack->method)
2723 partof = (char *) info->stack->method;
2729 if (! info->stack->method && ! append_type (info, ")"))
2732 t = pop_type (info);
2735 fprintf (info->f, ";\"\tkind:%c\ttype:%s", kind, t);
2737 fputs ("\tfile:", info->f);
2740 fprintf (info->f, "\tclass:%s", partof);
2743 fputc ('\n', info->f);
2749 /* Write out line number information. */
2752 tg_lineno (void *p ATTRIBUTE_UNUSED, const char *filename ATTRIBUTE_UNUSED,
2753 unsigned long lineno ATTRIBUTE_UNUSED,
2754 bfd_vma addr ATTRIBUTE_UNUSED)
2759 /* Finish writing out a block. */
2762 tg_end_block (void *p ATTRIBUTE_UNUSED, bfd_vma addr ATTRIBUTE_UNUSED)
2767 /* Convert the visibility value into a human readable name. */
2770 visibility_name (enum debug_visibility visibility)
2776 case DEBUG_VISIBILITY_PUBLIC:
2779 case DEBUG_VISIBILITY_PRIVATE:
2782 case DEBUG_VISIBILITY_PROTECTED:
2785 case DEBUG_VISIBILITY_IGNORE: