[PATCH 40/57][Arm][OBJDUMP] Add support for MVE instructions: vdup, veor, vfma, vfms...
[binutils-gdb.git] / binutils / prdbg.c
blobd44f5c4fccd63e2f5555fb68918a93fd04d6e44f
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
21 02110-1301, USA. */
23 /* This file prints out the generic debugging information, by
24 supplying a set of routines to debug_write. */
26 #include "sysdep.h"
27 #include <assert.h>
28 #include "bfd.h"
29 #include "libiberty.h"
30 #include "demangle.h"
31 #include "debug.h"
32 #include "budbg.h"
34 /* This is the structure we use as a handle for these routines. */
36 struct pr_handle
38 /* File to print information to. */
39 FILE *f;
40 /* Current indentation level. */
41 unsigned int indent;
42 /* Type stack. */
43 struct pr_stack *stack;
44 /* Parameter number we are about to output. */
45 int parameter;
46 /* The following are used only by the tags code (tg_). */
47 /* Name of the file we are using. */
48 char *filename;
49 /* The BFD. */
50 bfd *abfd;
51 /* The symbols table for this BFD. */
52 asymbol **syms;
53 /* Pointer to a function to demangle symbols. */
54 char *(*demangler) (bfd *, const char *, int);
57 /* The type stack. */
59 struct pr_stack
61 /* Next element on the stack. */
62 struct pr_stack *next;
63 /* This element. */
64 char *type;
65 /* Current visibility of fields if this is a class. */
66 enum debug_visibility visibility;
67 /* Name of the current method we are handling. */
68 const char *method;
69 /* The following are used only by the tags code (tg_). */
70 /* Type for the container (struct, union, class, union class). */
71 const char *flavor;
72 /* A comma separated list of parent classes. */
73 char *parents;
74 /* How many parents contains parents. */
75 int num_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,
197 pr_start_source,
198 pr_empty_type,
199 pr_void_type,
200 pr_int_type,
201 pr_float_type,
202 pr_complex_type,
203 pr_bool_type,
204 pr_enum_type,
205 pr_pointer_type,
206 pr_function_type,
207 pr_reference_type,
208 pr_range_type,
209 pr_array_type,
210 pr_set_type,
211 pr_offset_type,
212 pr_method_type,
213 pr_const_type,
214 pr_volatile_type,
215 pr_start_struct_type,
216 pr_struct_field,
217 pr_end_struct_type,
218 pr_start_class_type,
219 pr_class_static_member,
220 pr_class_baseclass,
221 pr_class_start_method,
222 pr_class_method_variant,
223 pr_class_static_method_variant,
224 pr_class_end_method,
225 pr_end_class_type,
226 pr_typedef_type,
227 pr_tag_type,
228 pr_typdef,
229 pr_tag,
230 pr_int_constant,
231 pr_float_constant,
232 pr_typed_constant,
233 pr_variable,
234 pr_start_function,
235 pr_function_parameter,
236 pr_start_block,
237 pr_end_block,
238 pr_end_function,
239 pr_lineno
242 static const struct debug_write_fns tg_fns =
244 tg_start_compilation_unit,
245 tg_start_source,
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. */
252 tg_enum_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,
264 tg_struct_field,
265 tg_end_struct_type,
266 tg_start_class_type,
267 tg_class_static_member,
268 tg_class_baseclass,
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. */
273 tg_end_class_type,
274 pr_typedef_type, /* Same, just push type. */
275 tg_tag_type,
276 tg_typdef,
277 tg_tag,
278 tg_int_constant, /* Untested. */
279 tg_float_constant, /* Untested. */
280 tg_typed_constant, /* Untested. */
281 tg_variable,
282 tg_start_function,
283 tg_function_parameter,
284 tg_start_block,
285 tg_end_block,
286 pr_end_function, /* Same, does nothing. */
287 tg_lineno
290 static int demangle_flags = DMGL_ANSI | DMGL_PARAMS;
292 /* Print out the generic debugging information recorded in dhandle. */
294 bfd_boolean
295 print_debugging_info (FILE *f, void *dhandle, bfd *abfd, asymbol **syms,
296 char * (*demangler) (struct bfd *, const char *, int),
297 bfd_boolean as_tags)
299 struct pr_handle info;
301 info.f = f;
302 info.indent = 0;
303 info.stack = NULL;
304 info.parameter = 0;
305 info.filename = NULL;
306 info.abfd = abfd;
307 info.syms = syms;
308 info.demangler = demangler;
310 if (as_tags)
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. */
324 static void
325 indent (struct pr_handle *info)
327 unsigned int i;
329 for (i = 0; i < info->indent; i++)
330 putc (' ', info->f);
333 /* Push a type on the type stack. */
335 static bfd_boolean
336 push_type (struct pr_handle *info, const char *type)
338 struct pr_stack *n;
340 if (type == NULL)
341 return FALSE;
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;
348 n->method = NULL;
349 n->next = info->stack;
350 info->stack = n;
352 return TRUE;
355 /* Prepend a string onto the type on the top of the type stack. */
357 static bfd_boolean
358 prepend_type (struct pr_handle *info, const char *s)
360 char *n;
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;
369 return TRUE;
372 /* Append a string to the type on the top of the type stack. */
374 static bfd_boolean
375 append_type (struct pr_handle *info, const char *s)
377 unsigned int len;
379 if (s == NULL)
380 return FALSE;
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);
389 return TRUE;
392 /* Append a string to the parents on the top of the type stack. */
394 static bfd_boolean
395 append_parent (struct pr_handle *info, const char *s)
397 unsigned int len;
399 if (s == NULL)
400 return FALSE;
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);
409 return TRUE;
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. */
416 static bfd_boolean
417 substitute_type (struct pr_handle *info, const char *s)
419 char *u;
421 assert (info->stack != NULL);
423 u = strchr (info->stack->type, '|');
424 if (u != NULL)
426 char *n;
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);
432 strcat (n, u + 1);
434 free (info->stack->type);
435 info->stack->type = n;
437 return TRUE;
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, ")"))
446 return FALSE;
449 if (*s == '\0')
450 return TRUE;
452 return (append_type (info, " ")
453 && append_type (info, s));
456 /* Indent the type at the top of the stack by appending spaces. */
458 static bfd_boolean
459 indent_type (struct pr_handle *info)
461 unsigned int i;
463 for (i = 0; i < info->indent; i++)
465 if (! append_type (info, " "))
466 return FALSE;
469 return TRUE;
472 /* Pop a type from the type stack. */
474 static char *
475 pop_type (struct pr_handle *info)
477 struct pr_stack *o;
478 char *ret;
480 assert (info->stack != NULL);
482 o = info->stack;
483 info->stack = o->next;
484 ret = o->type;
485 free (o);
487 return ret;
490 /* Print a VMA value into a string. */
492 static void
493 print_vma (bfd_vma vma, char *buf, bfd_boolean unsignedp, bfd_boolean hexp)
495 if (sizeof (vma) <= sizeof (unsigned long))
497 if (hexp)
498 sprintf (buf, "0x%lx", (unsigned long) vma);
499 else if (unsignedp)
500 sprintf (buf, "%lu", (unsigned long) vma);
501 else
502 sprintf (buf, "%ld", (long) vma);
504 #if BFD_HOST_64BIT_LONG_LONG
505 else if (sizeof (vma) <= sizeof (unsigned long long))
507 #ifndef __MSVCRT__
508 if (hexp)
509 sprintf (buf, "0x%llx", (unsigned long long) vma);
510 else if (unsignedp)
511 sprintf (buf, "%llu", (unsigned long long) vma);
512 else
513 sprintf (buf, "%lld", (long long) vma);
514 #else
515 if (hexp)
516 sprintf (buf, "0x%I64x", (unsigned long long) vma);
517 else if (unsignedp)
518 sprintf (buf, "%I64u", (unsigned long long) vma);
519 else
520 sprintf (buf, "%I64d", (long long) vma);
521 #endif
523 #endif
524 else
526 buf[0] = '0';
527 buf[1] = 'x';
528 sprintf_vma (buf + 2, vma);
532 /* Start a new compilation unit. */
534 static bfd_boolean
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);
543 return TRUE;
546 /* Start a source file within a compilation unit. */
548 static bfd_boolean
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);
557 return TRUE;
560 /* Push an empty type onto the type stack. */
562 static bfd_boolean
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. */
572 static bfd_boolean
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. */
582 static bfd_boolean
583 pr_int_type (void *p, unsigned int size, bfd_boolean unsignedp)
585 struct pr_handle *info = (struct pr_handle *) p;
586 char ab[40];
588 sprintf (ab, "%sint%d", unsignedp ? "u" : "", size * 8);
589 return push_type (info, ab);
592 /* Push a floating type onto the type stack. */
594 static bfd_boolean
595 pr_float_type (void *p, unsigned int size)
597 struct pr_handle *info = (struct pr_handle *) p;
598 char ab[40];
600 if (size == 4)
601 return push_type (info, "float");
602 else if (size == 8)
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. */
611 static bfd_boolean
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))
617 return FALSE;
619 return prepend_type (info, "complex ");
622 /* Push a bfd_boolean type onto the type stack. */
624 static bfd_boolean
625 pr_bool_type (void *p, unsigned int size)
627 struct pr_handle *info = (struct pr_handle *) p;
628 char ab[40];
630 sprintf (ab, "bool%d", size * 8);
632 return push_type (info, ab);
635 /* Push an enum type onto the type stack. */
637 static bfd_boolean
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;
642 unsigned int i;
643 bfd_signed_vma val;
645 if (! push_type (info, "enum "))
646 return FALSE;
647 if (tag != NULL)
649 if (! append_type (info, tag)
650 || ! append_type (info, " "))
651 return FALSE;
653 if (! append_type (info, "{ "))
654 return FALSE;
656 if (names == NULL)
658 if (! append_type (info, "/* undefined */"))
659 return FALSE;
661 else
663 val = 0;
664 for (i = 0; names[i] != NULL; i++)
666 if (i > 0)
668 if (! append_type (info, ", "))
669 return FALSE;
672 if (! append_type (info, names[i]))
673 return FALSE;
675 if (values[i] != val)
677 char ab[22];
679 print_vma (values[i], ab, FALSE, FALSE);
680 if (! append_type (info, " = ")
681 || ! append_type (info, ab))
682 return FALSE;
683 val = values[i];
686 ++val;
690 return append_type (info, " }");
693 /* Turn the top type on the stack into a pointer. */
695 static bfd_boolean
696 pr_pointer_type (void *p)
698 struct pr_handle *info = (struct pr_handle *) p;
699 char *s;
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. */
711 static bfd_boolean
712 pr_function_type (void *p, int argcount, bfd_boolean varargs)
714 struct pr_handle *info = (struct pr_handle *) p;
715 char **arg_types;
716 unsigned int len;
717 char *s;
719 assert (info->stack != NULL);
721 len = 10;
723 if (argcount <= 0)
725 arg_types = NULL;
726 len += 15;
728 else
730 int i;
732 arg_types = (char **) xmalloc (argcount * sizeof *arg_types);
733 for (i = argcount - 1; i >= 0; i--)
735 if (! substitute_type (info, ""))
737 free (arg_types);
738 return FALSE;
740 arg_types[i] = pop_type (info);
741 if (arg_types[i] == NULL)
743 free (arg_types);
744 return FALSE;
746 len += strlen (arg_types[i]) + 2;
748 if (varargs)
749 len += 5;
752 /* Now the return type is on the top of the stack. */
754 s = (char *) xmalloc (len);
755 LITSTRCPY (s, "(|) (");
757 if (argcount < 0)
758 strcat (s, "/* unknown */");
759 else
761 int i;
763 for (i = 0; i < argcount; i++)
765 if (i > 0)
766 strcat (s, ", ");
767 strcat (s, arg_types[i]);
769 if (varargs)
771 if (i > 0)
772 strcat (s, ", ");
773 strcat (s, "...");
775 if (argcount > 0)
776 free (arg_types);
779 strcat (s, ")");
781 if (! substitute_type (info, s))
782 return FALSE;
784 free (s);
786 return TRUE;
789 /* Turn the top type on the stack into a reference to that type. */
791 static bfd_boolean
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. */
803 static bfd_boolean
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, ""))
812 return FALSE;
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. */
826 static bfd_boolean
827 pr_array_type (void *p, bfd_signed_vma lower, bfd_signed_vma upper,
828 bfd_boolean stringp)
830 struct pr_handle *info = (struct pr_handle *) p;
831 char *range_type;
832 char abl[22], abu[22], ab[50];
834 range_type = pop_type (info);
835 if (range_type == NULL)
836 return FALSE;
838 if (lower == 0)
840 if (upper == -1)
841 sprintf (ab, "|[]");
842 else
844 print_vma (upper + 1, abu, FALSE, FALSE);
845 sprintf (ab, "|[%s]", abu);
848 else
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))
856 return FALSE;
858 if (strcmp (range_type, "int") != 0)
860 if (! append_type (info, ":")
861 || ! append_type (info, range_type))
862 return FALSE;
865 if (stringp)
867 if (! append_type (info, " /* string */"))
868 return FALSE;
871 return TRUE;
874 /* Make a set type. */
876 static bfd_boolean
877 pr_set_type (void *p, bfd_boolean bitstringp)
879 struct pr_handle *info = (struct pr_handle *) p;
881 if (! substitute_type (info, ""))
882 return FALSE;
884 if (! prepend_type (info, "set { ")
885 || ! append_type (info, " }"))
886 return FALSE;
888 if (bitstringp)
890 if (! append_type (info, "/* bitstring */"))
891 return FALSE;
894 return TRUE;
897 /* Make an offset type. */
899 static bfd_boolean
900 pr_offset_type (void *p)
902 struct pr_handle *info = (struct pr_handle *) p;
903 char *t;
905 if (! substitute_type (info, ""))
906 return FALSE;
908 t = pop_type (info);
909 if (t == NULL)
910 return FALSE;
912 return (substitute_type (info, "")
913 && prepend_type (info, " ")
914 && prepend_type (info, t)
915 && append_type (info, "::|"));
918 /* Make a method type. */
920 static bfd_boolean
921 pr_method_type (void *p, bfd_boolean domain, int argcount, bfd_boolean varargs)
923 struct pr_handle *info = (struct pr_handle *) p;
924 unsigned int len;
925 char *domain_type;
926 char **arg_types;
927 char *s;
929 len = 10;
931 if (! domain)
932 domain_type = NULL;
933 else
935 if (! substitute_type (info, ""))
936 return FALSE;
937 domain_type = pop_type (info);
938 if (domain_type == NULL)
939 return FALSE;
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, ' ')
945 == NULL))
946 domain_type += sizeof "union class " - 1;
947 len += strlen (domain_type);
950 if (argcount <= 0)
952 arg_types = NULL;
953 len += 15;
955 else
957 int i;
959 arg_types = (char **) xmalloc (argcount * sizeof *arg_types);
960 for (i = argcount - 1; i >= 0; i--)
962 if (! substitute_type (info, ""))
964 free (arg_types);
965 return FALSE;
967 arg_types[i] = pop_type (info);
968 if (arg_types[i] == NULL)
970 free (arg_types);
971 return FALSE;
973 len += strlen (arg_types[i]) + 2;
975 if (varargs)
976 len += 5;
979 /* Now the return type is on the top of the stack. */
981 s = (char *) xmalloc (len);
982 if (! domain)
983 *s = '\0';
984 else
985 strcpy (s, domain_type);
986 strcat (s, "::| (");
988 if (argcount < 0)
989 strcat (s, "/* unknown */");
990 else
992 int i;
994 for (i = 0; i < argcount; i++)
996 if (i > 0)
997 strcat (s, ", ");
998 strcat (s, arg_types[i]);
1000 if (varargs)
1002 if (i > 0)
1003 strcat (s, ", ");
1004 strcat (s, "...");
1006 if (argcount > 0)
1007 free (arg_types);
1010 strcat (s, ")");
1012 if (! substitute_type (info, s))
1013 return FALSE;
1015 free (s);
1017 return TRUE;
1020 /* Make a const qualified type. */
1022 static bfd_boolean
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. */
1032 static bfd_boolean
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. */
1042 static bfd_boolean
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;
1048 info->indent += 2;
1050 if (! push_type (info, structp ? "struct " : "union "))
1051 return FALSE;
1052 if (tag != NULL)
1054 if (! append_type (info, tag))
1055 return FALSE;
1057 else
1059 char idbuf[20];
1061 sprintf (idbuf, "%%anon%u", id);
1062 if (! append_type (info, idbuf))
1063 return FALSE;
1066 if (! append_type (info, " {"))
1067 return FALSE;
1068 if (size != 0 || tag != NULL)
1070 char ab[30];
1072 if (! append_type (info, " /*"))
1073 return FALSE;
1075 if (size != 0)
1077 sprintf (ab, " size %u", size);
1078 if (! append_type (info, ab))
1079 return FALSE;
1081 if (tag != NULL)
1083 sprintf (ab, " id %u", id);
1084 if (! append_type (info, ab))
1085 return FALSE;
1087 if (! append_type (info, " */"))
1088 return FALSE;
1090 if (! append_type (info, "\n"))
1091 return FALSE;
1093 info->stack->visibility = DEBUG_VISIBILITY_PUBLIC;
1095 return indent_type (info);
1098 /* Output the visibility of a field in a struct. */
1100 static bfd_boolean
1101 pr_fix_visibility (struct pr_handle *info, enum debug_visibility visibility)
1103 const char *s = NULL;
1104 char *t;
1105 unsigned int len;
1107 assert (info->stack != NULL);
1109 if (info->stack->visibility == visibility)
1110 return TRUE;
1112 switch (visibility)
1114 case DEBUG_VISIBILITY_PUBLIC:
1115 s = "public";
1116 break;
1117 case DEBUG_VISIBILITY_PRIVATE:
1118 s = "private";
1119 break;
1120 case DEBUG_VISIBILITY_PROTECTED:
1121 s = "protected";
1122 break;
1123 case DEBUG_VISIBILITY_IGNORE:
1124 s = "/* ignore */";
1125 break;
1126 default:
1127 abort ();
1128 return FALSE;
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;
1135 len = strlen (t);
1136 assert (t[len - 1] == ' ');
1137 t[len - 1] = '\0';
1139 if (! append_type (info, s)
1140 || ! append_type (info, ":\n")
1141 || ! indent_type (info))
1142 return FALSE;
1144 info->stack->visibility = visibility;
1146 return TRUE;
1149 /* Add a field to a struct type. */
1151 static bfd_boolean
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;
1156 char ab[22];
1157 char *t;
1159 if (! substitute_type (info, name))
1160 return FALSE;
1162 if (! append_type (info, "; /* "))
1163 return FALSE;
1165 if (bitsize != 0)
1167 print_vma (bitsize, ab, TRUE, FALSE);
1168 if (! append_type (info, "bitsize ")
1169 || ! append_type (info, ab)
1170 || ! append_type (info, ", "))
1171 return FALSE;
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))
1179 return FALSE;
1181 t = pop_type (info);
1182 if (t == NULL)
1183 return FALSE;
1185 if (! pr_fix_visibility (info, visibility))
1186 return FALSE;
1188 return append_type (info, t);
1191 /* Finish a struct type. */
1193 static bfd_boolean
1194 pr_end_struct_type (void *p)
1196 struct pr_handle *info = (struct pr_handle *) p;
1197 char *s;
1199 assert (info->stack != NULL);
1200 assert (info->indent >= 2);
1202 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');
1208 *s++ = '}';
1209 *s = '\0';
1211 return TRUE;
1214 /* Start a class type. */
1216 static bfd_boolean
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;
1222 char *tv = NULL;
1224 info->indent += 2;
1226 if (vptr && ! ownvptr)
1228 tv = pop_type (info);
1229 if (tv == NULL)
1230 return FALSE;
1233 if (! push_type (info, structp ? "class " : "union class "))
1234 return FALSE;
1235 if (tag != NULL)
1237 if (! append_type (info, tag))
1238 return FALSE;
1240 else
1242 char idbuf[20];
1244 sprintf (idbuf, "%%anon%u", id);
1245 if (! append_type (info, idbuf))
1246 return FALSE;
1249 if (! append_type (info, " {"))
1250 return FALSE;
1251 if (size != 0 || vptr || ownvptr || tag != NULL)
1253 if (! append_type (info, " /*"))
1254 return FALSE;
1256 if (size != 0)
1258 char ab[20];
1260 sprintf (ab, "%u", size);
1261 if (! append_type (info, " size ")
1262 || ! append_type (info, ab))
1263 return FALSE;
1266 if (vptr)
1268 if (! append_type (info, " vtable "))
1269 return FALSE;
1270 if (ownvptr)
1272 if (! append_type (info, "self "))
1273 return FALSE;
1275 else
1277 if (! append_type (info, tv)
1278 || ! append_type (info, " "))
1279 return FALSE;
1283 if (tag != NULL)
1285 char ab[30];
1287 sprintf (ab, " id %u", id);
1288 if (! append_type (info, ab))
1289 return FALSE;
1292 if (! append_type (info, " */"))
1293 return FALSE;
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. */
1304 static bfd_boolean
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;
1309 char *t;
1311 if (! substitute_type (info, name))
1312 return FALSE;
1314 if (! prepend_type (info, "static ")
1315 || ! append_type (info, "; /* ")
1316 || ! append_type (info, physname)
1317 || ! append_type (info, " */\n")
1318 || ! indent_type (info))
1319 return FALSE;
1321 t = pop_type (info);
1322 if (t == NULL)
1323 return FALSE;
1325 if (! pr_fix_visibility (info, visibility))
1326 return FALSE;
1328 return append_type (info, t);
1331 /* Add a base class to a class. */
1333 static bfd_boolean
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;
1338 char *t;
1339 const char *prefix;
1340 char ab[22];
1341 char *s, *l, *n;
1343 assert (info->stack != NULL && info->stack->next != NULL);
1345 if (! substitute_type (info, ""))
1346 return FALSE;
1348 t = pop_type (info);
1349 if (t == NULL)
1350 return FALSE;
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))
1358 return FALSE;
1360 if (is_virtual)
1362 if (! prepend_type (info, "virtual "))
1363 return FALSE;
1366 switch (visibility)
1368 case DEBUG_VISIBILITY_PUBLIC:
1369 prefix = "public ";
1370 break;
1371 case DEBUG_VISIBILITY_PROTECTED:
1372 prefix = "protected ";
1373 break;
1374 case DEBUG_VISIBILITY_PRIVATE:
1375 prefix = "private ";
1376 break;
1377 default:
1378 prefix = "/* unknown visibility */ ";
1379 break;
1382 if (! prepend_type (info, prefix))
1383 return FALSE;
1385 if (bitpos != 0)
1387 print_vma (bitpos, ab, TRUE, FALSE);
1388 if (! append_type (info, " /* bitpos ")
1389 || ! append_type (info, ab)
1390 || ! append_type (info, " */"))
1391 return FALSE;
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, '{');
1399 assert (s != NULL);
1400 --s;
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++)
1405 if (*l == ':')
1406 break;
1407 if (! prepend_type (info, l == s ? " : " : ", "))
1408 return FALSE;
1410 t = pop_type (info);
1411 if (t == NULL)
1412 return FALSE;
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);
1417 strcat (n, s);
1419 free (info->stack->type);
1420 info->stack->type = n;
1422 free (t);
1424 return TRUE;
1427 /* Start adding a method to a class. */
1429 static bfd_boolean
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;
1436 return TRUE;
1439 /* Add a variant to a method. */
1441 static bfd_boolean
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;
1448 char *method_type;
1449 char *context_type;
1451 assert (info->stack != NULL);
1452 assert (info->stack->next != NULL);
1454 /* Put the const and volatile qualifiers on the type. */
1455 if (volatilep)
1457 if (! append_type (info, " volatile"))
1458 return FALSE;
1460 if (constp)
1462 if (! append_type (info, " const"))
1463 return FALSE;
1466 /* Stick the name of the method into its type. */
1467 if (! substitute_type (info,
1468 (context
1469 ? info->stack->next->next->method
1470 : info->stack->next->method)))
1471 return FALSE;
1473 /* Get the type. */
1474 method_type = pop_type (info);
1475 if (method_type == NULL)
1476 return FALSE;
1478 /* Pull off the context type if there is one. */
1479 if (! context)
1480 context_type = NULL;
1481 else
1483 context_type = pop_type (info);
1484 if (context_type == NULL)
1485 return FALSE;
1488 /* Now the top of the stack is the class. */
1490 if (! pr_fix_visibility (info, visibility))
1491 return FALSE;
1493 if (! append_type (info, method_type)
1494 || ! append_type (info, " /* ")
1495 || ! append_type (info, physname)
1496 || ! append_type (info, " "))
1497 return FALSE;
1498 if (context || voffset != 0)
1500 char ab[22];
1502 if (context)
1504 if (! append_type (info, "context ")
1505 || ! append_type (info, context_type)
1506 || ! append_type (info, " "))
1507 return FALSE;
1509 print_vma (voffset, ab, TRUE, FALSE);
1510 if (! append_type (info, "voffset ")
1511 || ! append_type (info, ab))
1512 return FALSE;
1515 return (append_type (info, " */;\n")
1516 && indent_type (info));
1519 /* Add a static variant to a method. */
1521 static bfd_boolean
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;
1527 char *method_type;
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. */
1534 if (volatilep)
1536 if (! append_type (info, " volatile"))
1537 return FALSE;
1539 if (constp)
1541 if (! append_type (info, " const"))
1542 return FALSE;
1545 /* Mark it as static. */
1546 if (! prepend_type (info, "static "))
1547 return FALSE;
1549 /* Stick the name of the method into its type. */
1550 if (! substitute_type (info, info->stack->next->method))
1551 return FALSE;
1553 /* Get the type. */
1554 method_type = pop_type (info);
1555 if (method_type == NULL)
1556 return FALSE;
1558 /* Now the top of the stack is the class. */
1560 if (! pr_fix_visibility (info, visibility))
1561 return FALSE;
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. */
1572 static bfd_boolean
1573 pr_class_end_method (void *p)
1575 struct pr_handle *info = (struct pr_handle *) p;
1577 info->stack->method = NULL;
1578 return TRUE;
1581 /* Finish up a class. */
1583 static bfd_boolean
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. */
1591 static bfd_boolean
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. */
1601 static bfd_boolean
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;
1607 char idbuf[22];
1609 switch (kind)
1611 case DEBUG_KIND_STRUCT:
1612 t = "struct ";
1613 break;
1614 case DEBUG_KIND_UNION:
1615 t = "union ";
1616 break;
1617 case DEBUG_KIND_ENUM:
1618 t = "enum ";
1619 break;
1620 case DEBUG_KIND_CLASS:
1621 t = "class ";
1622 break;
1623 case DEBUG_KIND_UNION_CLASS:
1624 t = "union class ";
1625 break;
1626 default:
1627 abort ();
1628 return FALSE;
1631 if (! push_type (info, t))
1632 return FALSE;
1633 if (name != NULL)
1634 tag = name;
1635 else
1637 sprintf (idbuf, "%%anon%u", id);
1638 tag = idbuf;
1641 if (! append_type (info, tag))
1642 return FALSE;
1643 if (name != NULL && kind != DEBUG_KIND_ENUM)
1645 sprintf (idbuf, " /* id %u */", id);
1646 if (! append_type (info, idbuf))
1647 return FALSE;
1650 return TRUE;
1653 /* Output a typedef. */
1655 static bfd_boolean
1656 pr_typdef (void *p, const char *name)
1658 struct pr_handle *info = (struct pr_handle *) p;
1659 char *s;
1661 if (! substitute_type (info, name))
1662 return FALSE;
1664 s = pop_type (info);
1665 if (s == NULL)
1666 return FALSE;
1668 indent (info);
1669 fprintf (info->f, "typedef %s;\n", s);
1671 free (s);
1673 return TRUE;
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. */
1679 static bfd_boolean
1680 pr_tag (void *p, const char *name ATTRIBUTE_UNUSED)
1682 struct pr_handle *info = (struct pr_handle *) p;
1683 char *t;
1685 t = pop_type (info);
1686 if (t == NULL)
1687 return FALSE;
1689 indent (info);
1690 fprintf (info->f, "%s;\n", t);
1692 free (t);
1694 return TRUE;
1697 /* Output an integer constant. */
1699 static bfd_boolean
1700 pr_int_constant (void *p, const char *name, bfd_vma val)
1702 struct pr_handle *info = (struct pr_handle *) p;
1703 char ab[22];
1705 indent (info);
1706 print_vma (val, ab, FALSE, FALSE);
1707 fprintf (info->f, "const int %s = %s;\n", name, ab);
1708 return TRUE;
1711 /* Output a floating point constant. */
1713 static bfd_boolean
1714 pr_float_constant (void *p, const char *name, double val)
1716 struct pr_handle *info = (struct pr_handle *) p;
1718 indent (info);
1719 fprintf (info->f, "const double %s = %g;\n", name, val);
1720 return TRUE;
1723 /* Output a typed constant. */
1725 static bfd_boolean
1726 pr_typed_constant (void *p, const char *name, bfd_vma val)
1728 struct pr_handle *info = (struct pr_handle *) p;
1729 char *t;
1730 char ab[22];
1732 t = pop_type (info);
1733 if (t == NULL)
1734 return FALSE;
1736 indent (info);
1737 print_vma (val, ab, FALSE, FALSE);
1738 fprintf (info->f, "const %s %s = %s;\n", t, name, ab);
1740 free (t);
1742 return TRUE;
1745 /* Output a variable. */
1747 static bfd_boolean
1748 pr_variable (void *p, const char *name, enum debug_var_kind kind,
1749 bfd_vma val)
1751 struct pr_handle *info = (struct pr_handle *) p;
1752 char *t;
1753 char ab[22];
1755 if (! substitute_type (info, name))
1756 return FALSE;
1758 t = pop_type (info);
1759 if (t == NULL)
1760 return FALSE;
1762 indent (info);
1763 switch (kind)
1765 case DEBUG_STATIC:
1766 case DEBUG_LOCAL_STATIC:
1767 fprintf (info->f, "static ");
1768 break;
1769 case DEBUG_REGISTER:
1770 fprintf (info->f, "register ");
1771 break;
1772 default:
1773 break;
1775 print_vma (val, ab, TRUE, TRUE);
1776 fprintf (info->f, "%s /* %s */;\n", t, ab);
1778 free (t);
1780 return TRUE;
1783 /* Start outputting a function. */
1785 static bfd_boolean
1786 pr_start_function (void *p, const char *name, bfd_boolean global)
1788 struct pr_handle *info = (struct pr_handle *) p;
1789 char *t;
1791 if (! substitute_type (info, name))
1792 return FALSE;
1794 t = pop_type (info);
1795 if (t == NULL)
1796 return FALSE;
1798 indent (info);
1799 if (! global)
1800 fprintf (info->f, "static ");
1801 fprintf (info->f, "%s (", t);
1803 info->parameter = 1;
1805 return TRUE;
1808 /* Output a function parameter. */
1810 static bfd_boolean
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;
1815 char *t;
1816 char ab[22];
1818 if (kind == DEBUG_PARM_REFERENCE
1819 || kind == DEBUG_PARM_REF_REG)
1821 if (! pr_reference_type (p))
1822 return FALSE;
1825 if (! substitute_type (info, name))
1826 return FALSE;
1828 t = pop_type (info);
1829 if (t == NULL)
1830 return FALSE;
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);
1841 free (t);
1843 ++info->parameter;
1845 return TRUE;
1848 /* Start writing out a block. */
1850 static bfd_boolean
1851 pr_start_block (void *p, bfd_vma addr)
1853 struct pr_handle *info = (struct pr_handle *) p;
1854 char ab[22];
1856 if (info->parameter > 0)
1858 fprintf (info->f, ")\n");
1859 info->parameter = 0;
1862 indent (info);
1863 print_vma (addr, ab, TRUE, TRUE);
1864 fprintf (info->f, "{ /* %s */\n", ab);
1866 info->indent += 2;
1868 return TRUE;
1871 /* Write out line number information. */
1873 static bfd_boolean
1874 pr_lineno (void *p, const char *filename, unsigned long lineno, bfd_vma addr)
1876 struct pr_handle *info = (struct pr_handle *) p;
1877 char ab[22];
1879 indent (info);
1880 print_vma (addr, ab, TRUE, TRUE);
1881 fprintf (info->f, "/* file %s line %lu addr %s */\n", filename, lineno, ab);
1883 return TRUE;
1886 /* Finish writing out a block. */
1888 static bfd_boolean
1889 pr_end_block (void *p, bfd_vma addr)
1891 struct pr_handle *info = (struct pr_handle *) p;
1892 char ab[22];
1894 info->indent -= 2;
1896 indent (info);
1897 print_vma (addr, ab, TRUE, TRUE);
1898 fprintf (info->f, "} /* %s */\n", ab);
1900 return TRUE;
1903 /* Finish writing out a function. */
1905 static bfd_boolean
1906 pr_end_function (void *p ATTRIBUTE_UNUSED)
1908 return TRUE;
1911 /* Tags style generation functions start here. */
1913 /* Variables for address to line translation. */
1914 static bfd_vma pc;
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. */
1923 static void
1924 find_address_in_section (bfd *abfd, asection *section, void *data)
1926 bfd_vma vma;
1927 bfd_size_type size;
1928 asymbol **syms = (asymbol **) data;
1930 if (found)
1931 return;
1933 if ((bfd_get_section_flags (abfd, section) & SEC_ALLOC) == 0)
1934 return;
1936 vma = bfd_get_section_vma (abfd, section);
1937 if (pc < vma)
1938 return;
1940 size = bfd_get_section_size (section);
1941 if (pc >= vma + size)
1942 return;
1944 found = bfd_find_nearest_line (abfd, section, syms, pc - vma,
1945 &filename, &functionname, &line);
1948 static void
1949 translate_addresses (bfd *abfd, char *addr_hex, FILE *f, asymbol **syms)
1951 pc = bfd_scan_vma (addr_hex, NULL, 16);
1952 found = FALSE;
1953 bfd_map_over_sections (abfd, find_address_in_section, syms);
1955 if (! found)
1956 fprintf (f, "??");
1957 else
1958 fprintf (f, "%u", line);
1961 /* Start a new compilation unit. */
1963 static bfd_boolean
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);
1972 return TRUE;
1975 /* Start a source file within a compilation unit. */
1977 static bfd_boolean
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);
1986 return TRUE;
1989 /* Push an enum type onto the type stack. */
1991 static bfd_boolean
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;
1996 unsigned int i;
1997 const char *name;
1998 char ab[22];
2000 if (! pr_enum_type (p, tag, names, values))
2001 return FALSE;
2003 name = tag ? tag : "unknown";
2004 /* Generate an entry for the enum. */
2005 if (tag)
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. */
2010 if (names != NULL)
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);
2020 return TRUE;
2023 /* Start accumulating a struct type. */
2025 static bfd_boolean
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;
2031 const char *name;
2032 char idbuf[20];
2034 if (tag != NULL)
2035 name = tag;
2036 else
2038 name = idbuf;
2039 sprintf (idbuf, "%%anon%u", id);
2042 if (! push_type (info, name))
2043 return FALSE;
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. */
2057 static bfd_boolean
2058 tg_fix_visibility (struct pr_handle *info, enum debug_visibility visibility)
2060 assert (info->stack != NULL);
2062 if (info->stack->visibility == visibility)
2063 return TRUE;
2065 assert (info->stack->visibility != DEBUG_VISIBILITY_IGNORE);
2067 info->stack->visibility = visibility;
2069 return TRUE;
2072 /* Add a field to a struct type. */
2074 static bfd_boolean
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;
2080 char *t;
2082 t = pop_type (info);
2083 if (t == NULL)
2084 return FALSE;
2086 if (! tg_fix_visibility (info, visibility))
2087 return FALSE;
2089 /* It happens, a bug? */
2090 if (! name[0])
2091 return TRUE;
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));
2097 return TRUE;
2100 /* Finish a struct type. */
2102 static bfd_boolean
2103 tg_end_struct_type (void *p ATTRIBUTE_UNUSED)
2105 assert (((struct pr_handle *) p)->stack != NULL);
2107 return TRUE;
2110 /* Start a class type. */
2112 static bfd_boolean
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;
2118 char *tv = NULL;
2119 const char *name;
2121 info->indent += 2;
2123 if (vptr && ! ownvptr)
2125 tv = pop_type (info);
2126 if (tv == NULL)
2127 return FALSE;
2130 if (tag != NULL)
2131 name = tag;
2132 else
2134 char idbuf[20];
2136 sprintf (idbuf, "%%anon%u", id);
2137 name = idbuf;
2140 if (! push_type (info, name))
2141 return FALSE;
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)
2149 if (vptr)
2151 if (! append_type (info, " vtable "))
2152 return FALSE;
2153 if (ownvptr)
2155 if (! append_type (info, "self "))
2156 return FALSE;
2158 else
2160 if (! append_type (info, tv)
2161 || ! append_type (info, " "))
2162 return FALSE;
2167 info->stack->visibility = DEBUG_VISIBILITY_PRIVATE;
2169 return TRUE;
2172 /* Add a static member to a class. */
2174 static bfd_boolean
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;
2180 char *t;
2181 int len_var, len_class;
2182 char *full_name;
2184 len_var = strlen (name);
2185 len_class = strlen (info->stack->next->type);
2186 full_name = (char *) xmalloc (len_var + len_class + 3);
2187 if (! full_name)
2188 return FALSE;
2189 sprintf (full_name, "%s::%s", info->stack->next->type, name);
2191 if (! substitute_type (info, full_name))
2193 free (full_name);
2194 return FALSE;
2197 if (! prepend_type (info, "static "))
2199 free (full_name);
2200 return FALSE;
2203 t = pop_type (info);
2204 if (t == NULL)
2206 free (full_name);
2207 return FALSE;
2210 if (! tg_fix_visibility (info, visibility))
2212 free (t);
2213 free (full_name);
2214 return FALSE;
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));
2220 free (t);
2221 free (full_name);
2223 return TRUE;
2226 /* Add a base class to a class. */
2228 static bfd_boolean
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;
2233 char *t;
2234 const char *prefix;
2236 assert (info->stack != NULL && info->stack->next != NULL);
2238 t = pop_type (info);
2239 if (t == NULL)
2240 return FALSE;
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))
2248 return FALSE;
2250 if (is_virtual)
2252 if (! prepend_type (info, "virtual "))
2253 return FALSE;
2256 switch (visibility)
2258 case DEBUG_VISIBILITY_PUBLIC:
2259 prefix = "public ";
2260 break;
2261 case DEBUG_VISIBILITY_PROTECTED:
2262 prefix = "protected ";
2263 break;
2264 case DEBUG_VISIBILITY_PRIVATE:
2265 prefix = "private ";
2266 break;
2267 default:
2268 prefix = "/* unknown visibility */ ";
2269 break;
2272 if (! prepend_type (info, prefix))
2273 return FALSE;
2275 t = pop_type (info);
2276 if (t == NULL)
2277 return FALSE;
2279 if (info->stack->num_parents && ! append_parent (info, ", "))
2280 return FALSE;
2282 if (! append_parent (info, t))
2283 return FALSE;
2284 info->stack->num_parents++;
2286 free (t);
2288 return TRUE;
2291 /* Add a variant to a method. */
2293 static bfd_boolean
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;
2301 char *method_type;
2302 char *context_type;
2303 char *method_name;
2305 assert (info->stack != NULL);
2306 assert (info->stack->next != NULL);
2308 /* Put the const and volatile qualifiers on the type. */
2309 if (volatilep)
2311 if (! append_type (info, " volatile"))
2312 return FALSE;
2314 if (constp)
2316 if (! append_type (info, " const"))
2317 return FALSE;
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))
2326 free (method_name);
2327 return FALSE;
2330 /* Get the type. */
2331 method_type = pop_type (info);
2332 if (method_type == NULL)
2334 free (method_name);
2335 return FALSE;
2338 /* Pull off the context type if there is one. */
2339 if (! context)
2340 context_type = NULL;
2341 else
2343 context_type = pop_type (info);
2344 if (context_type == NULL)
2346 free (method_type);
2347 free (method_name);
2348 return FALSE;
2352 /* Now the top of the stack is the class. */
2353 if (! tg_fix_visibility (info, visibility))
2355 free (method_type);
2356 free (method_name);
2357 free (context_type);
2358 return FALSE;
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);
2363 free (method_type);
2364 free (method_name);
2365 free (context_type);
2367 return TRUE;
2370 /* Add a static variant to a method. */
2372 static bfd_boolean
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;
2379 char *method_type;
2380 char *method_name;
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. */
2387 if (volatilep)
2389 if (! append_type (info, " volatile"))
2390 return FALSE;
2392 if (constp)
2394 if (! append_type (info, " const"))
2395 return FALSE;
2398 /* Mark it as static. */
2399 if (! prepend_type (info, "static "))
2400 return FALSE;
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))
2406 free (method_name);
2407 return FALSE;
2410 /* Get the type. */
2411 method_type = pop_type (info);
2412 if (method_type == NULL)
2414 free (method_name);
2415 return FALSE;
2418 /* Now the top of the stack is the class. */
2419 if (! tg_fix_visibility (info, visibility))
2421 free (method_type);
2422 free (method_name);
2423 return FALSE;
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));
2429 free (method_type);
2430 free (method_name);
2432 return TRUE;
2435 /* Finish up a class. */
2437 static bfd_boolean
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. */
2456 static bfd_boolean
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;
2462 char idbuf[20];
2464 switch (kind)
2466 case DEBUG_KIND_STRUCT:
2467 t = "struct ";
2468 break;
2469 case DEBUG_KIND_UNION:
2470 t = "union ";
2471 break;
2472 case DEBUG_KIND_ENUM:
2473 t = "enum ";
2474 break;
2475 case DEBUG_KIND_CLASS:
2476 t = "class ";
2477 break;
2478 case DEBUG_KIND_UNION_CLASS:
2479 t = "union class ";
2480 break;
2481 default:
2482 abort ();
2483 return FALSE;
2486 if (! push_type (info, t))
2487 return FALSE;
2488 if (name != NULL)
2489 tag = name;
2490 else
2492 sprintf (idbuf, "%%anon%u", id);
2493 tag = idbuf;
2496 if (! append_type (info, tag))
2497 return FALSE;
2499 return TRUE;
2502 /* Output a typedef. */
2504 static bfd_boolean
2505 tg_typdef (void *p, const char *name)
2507 struct pr_handle *info = (struct pr_handle *) p;
2508 char *s;
2510 s = pop_type (info);
2511 if (s == NULL)
2512 return FALSE;
2514 fprintf (info->f, "%s\t%s\t0;\"\tkind:t\ttype:%s\n", name,
2515 info->filename, s);
2517 free (s);
2519 return TRUE;
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. */
2525 static bfd_boolean
2526 tg_tag (void *p ATTRIBUTE_UNUSED, const char *name ATTRIBUTE_UNUSED)
2528 struct pr_handle *info = (struct pr_handle *) p;
2529 char *t;
2531 t = pop_type (info);
2532 if (t == NULL)
2533 return FALSE;
2534 free (t);
2536 return TRUE;
2539 /* Output an integer constant. */
2541 static bfd_boolean
2542 tg_int_constant (void *p, const char *name, bfd_vma val)
2544 struct pr_handle *info = (struct pr_handle *) p;
2545 char ab[22];
2547 indent (info);
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);
2551 return TRUE;
2554 /* Output a floating point constant. */
2556 static bfd_boolean
2557 tg_float_constant (void *p, const char *name, double val)
2559 struct pr_handle *info = (struct pr_handle *) p;
2561 indent (info);
2562 fprintf (info->f, "%s\t%s\t0;\"\tkind:v\ttype:const double\tvalue:%g\n",
2563 name, info->filename, val);
2564 return TRUE;
2567 /* Output a typed constant. */
2569 static bfd_boolean
2570 tg_typed_constant (void *p, const char *name, bfd_vma val)
2572 struct pr_handle *info = (struct pr_handle *) p;
2573 char *t;
2574 char ab[22];
2576 t = pop_type (info);
2577 if (t == NULL)
2578 return FALSE;
2580 indent (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);
2585 free (t);
2587 return TRUE;
2590 /* Output a variable. */
2592 static bfd_boolean
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);
2600 if (t == NULL)
2601 return FALSE;
2603 dname = NULL;
2604 if (info->demangler)
2605 dname = info->demangler (info->abfd, name, demangle_flags);
2607 from_class = NULL;
2608 if (dname != NULL)
2610 char *sep;
2611 sep = strstr (dname, "::");
2612 if (sep)
2614 *sep = 0;
2615 name = sep + 2;
2616 from_class = dname;
2618 else
2619 /* Obscure types as vts and type_info nodes. */
2620 name = dname;
2623 fprintf (info->f, "%s\t%s\t0;\"\tkind:v\ttype:%s", name, info->filename, t);
2625 switch (kind)
2627 case DEBUG_STATIC:
2628 case DEBUG_LOCAL_STATIC:
2629 fprintf (info->f, "\tfile:");
2630 break;
2631 case DEBUG_REGISTER:
2632 fprintf (info->f, "\tregister:");
2633 break;
2634 default:
2635 break;
2638 if (from_class)
2639 fprintf (info->f, "\tclass:%s", from_class);
2641 if (dname)
2642 free (dname);
2644 fprintf (info->f, "\n");
2646 free (t);
2648 return TRUE;
2651 /* Start outputting a function. */
2653 static bfd_boolean
2654 tg_start_function (void *p, const char *name, bfd_boolean global)
2656 struct pr_handle *info = (struct pr_handle *) p;
2657 char *dname;
2659 if (! global)
2660 info->stack->flavor = "static";
2661 else
2662 info->stack->flavor = NULL;
2664 dname = NULL;
2665 if (info->demangler)
2666 dname = info->demangler (info->abfd, name, demangle_flags);
2668 if (! substitute_type (info, dname ? dname : name))
2669 return FALSE;
2671 info->stack->method = NULL;
2672 if (dname != NULL)
2674 char *sep;
2675 sep = strstr (dname, "::");
2676 if (sep)
2678 info->stack->method = dname;
2679 *sep = 0;
2680 name = sep + 2;
2682 else
2684 info->stack->method = "";
2685 name = dname;
2687 sep = strchr (name, '(');
2688 if (sep)
2689 *sep = 0;
2690 /* Obscure functions as type_info function. */
2693 info->stack->parents = strdup (name);
2695 if (! info->stack->method && ! append_type (info, "("))
2696 return FALSE;
2698 info->parameter = 1;
2700 return TRUE;
2703 /* Output a function parameter. */
2705 static bfd_boolean
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;
2710 char *t;
2712 if (kind == DEBUG_PARM_REFERENCE
2713 || kind == DEBUG_PARM_REF_REG)
2715 if (! pr_reference_type (p))
2716 return FALSE;
2719 if (! substitute_type (info, name))
2720 return FALSE;
2722 t = pop_type (info);
2723 if (t == NULL)
2724 return FALSE;
2726 if (! info->stack->method)
2728 if (info->parameter != 1 && ! append_type (info, ", "))
2729 return FALSE;
2731 if (kind == DEBUG_PARM_REG || kind == DEBUG_PARM_REF_REG)
2732 if (! append_type (info, "register "))
2733 return FALSE;
2735 if (! append_type (info, t))
2736 return FALSE;
2739 free (t);
2741 ++info->parameter;
2743 return TRUE;
2746 /* Start writing out a block. */
2748 static bfd_boolean
2749 tg_start_block (void *p, bfd_vma addr)
2751 struct pr_handle *info = (struct pr_handle *) p;
2752 char ab[22], kind, *partof;
2753 char *t;
2754 bfd_boolean local;
2756 if (info->parameter > 0)
2758 info->parameter = 0;
2760 /* Delayed name. */
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)
2769 kind = 'm';
2770 partof = (char *) info->stack->method;
2772 else
2774 kind = 'f';
2775 partof = NULL;
2776 if (! info->stack->method && ! append_type (info, ")"))
2777 return FALSE;
2779 t = pop_type (info);
2780 if (t == NULL)
2781 return FALSE;
2782 fprintf (info->f, ";\"\tkind:%c\ttype:%s", kind, t);
2783 if (local)
2784 fputs ("\tfile:", info->f);
2785 if (partof)
2787 fprintf (info->f, "\tclass:%s", partof);
2788 free (partof);
2790 fputc ('\n', info->f);
2793 return TRUE;
2796 /* Write out line number information. */
2798 static bfd_boolean
2799 tg_lineno (void *p ATTRIBUTE_UNUSED, const char *fname ATTRIBUTE_UNUSED,
2800 unsigned long lineno ATTRIBUTE_UNUSED,
2801 bfd_vma addr ATTRIBUTE_UNUSED)
2803 return TRUE;
2806 /* Finish writing out a block. */
2808 static bfd_boolean
2809 tg_end_block (void *p ATTRIBUTE_UNUSED, bfd_vma addr ATTRIBUTE_UNUSED)
2811 return TRUE;
2814 /* Convert the visibility value into a human readable name. */
2816 static const char *
2817 visibility_name (enum debug_visibility visibility)
2819 const char *s;
2821 switch (visibility)
2823 case DEBUG_VISIBILITY_PUBLIC:
2824 s = "public";
2825 break;
2826 case DEBUG_VISIBILITY_PRIVATE:
2827 s = "private";
2828 break;
2829 case DEBUG_VISIBILITY_PROTECTED:
2830 s = "protected";
2831 break;
2832 case DEBUG_VISIBILITY_IGNORE:
2833 s = "/* ignore */";
2834 break;
2835 default:
2836 abort ();
2837 return FALSE;
2839 return s;