bfd/
[binutils.git] / binutils / prdbg.c
blob4b412e4c620359a327ac6355a3e0dd9529465cd2
1 /* prdbg.c -- Print out generic debugging information.
2 Copyright 1995, 1996, 2002, 2003, 2004 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 2 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., 59 Temple Place - Suite 330, Boston, MA
21 02111-1307, USA. */
23 /* This file prints out the generic debugging information, by
24 supplying a set of routines to debug_write. */
26 #include <stdio.h>
27 #include <assert.h>
29 #include "bfd.h"
30 #include "bucomm.h"
31 #include "libiberty.h"
32 #include "debug.h"
33 #include "budbg.h"
35 /* This is the structure we use as a handle for these routines. */
37 struct pr_handle
39 /* File to print information to. */
40 FILE *f;
41 /* Current indentation level. */
42 unsigned int indent;
43 /* Type stack. */
44 struct pr_stack *stack;
45 /* Parameter number we are about to output. */
46 int parameter;
47 /* The following are used only by the tags code (tg_). */
48 /* Name of the file we are using. */
49 char *filename;
50 /* The BFD. */
51 bfd *abfd;
52 /* The symbols table for this BFD. */
53 asymbol **syms;
54 /* Pointer to a function to demangle symbols. */
55 char *(*demangler) (bfd *, const char *);
58 /* The type stack. */
60 struct pr_stack
62 /* Next element on the stack. */
63 struct pr_stack *next;
64 /* This element. */
65 char *type;
66 /* Current visibility of fields if this is a class. */
67 enum debug_visibility visibility;
68 /* Name of the current method we are handling. */
69 const char *method;
70 /* The following are used only by the tags code (tg_). */
71 /* Type for the container (struct, union, class, union class). */
72 const char *flavor;
73 /* A comma separated list of parent classes. */
74 char *parents;
75 /* How many parents contains parents. */
76 int num_parents;
79 static void indent (struct pr_handle *);
80 static bfd_boolean push_type (struct pr_handle *, const char *);
81 static bfd_boolean prepend_type (struct pr_handle *, const char *);
82 static bfd_boolean append_type (struct pr_handle *, const char *);
83 static bfd_boolean substitute_type (struct pr_handle *, const char *);
84 static bfd_boolean indent_type (struct pr_handle *);
85 static char *pop_type (struct pr_handle *);
86 static void print_vma (bfd_vma, char *, bfd_boolean, bfd_boolean);
87 static bfd_boolean pr_fix_visibility
88 (struct pr_handle *, enum debug_visibility);
89 static bfd_boolean pr_start_compilation_unit (void *, const char *);
90 static bfd_boolean pr_start_source (void *, const char *);
91 static bfd_boolean pr_empty_type (void *);
92 static bfd_boolean pr_void_type (void *);
93 static bfd_boolean pr_int_type (void *, unsigned int, bfd_boolean);
94 static bfd_boolean pr_float_type (void *, unsigned int);
95 static bfd_boolean pr_complex_type (void *, unsigned int);
96 static bfd_boolean pr_bool_type (void *, unsigned int);
97 static bfd_boolean pr_enum_type
98 (void *, const char *, const char **, bfd_signed_vma *);
99 static bfd_boolean pr_pointer_type (void *);
100 static bfd_boolean pr_function_type (void *, int, bfd_boolean);
101 static bfd_boolean pr_reference_type (void *);
102 static bfd_boolean pr_range_type (void *, bfd_signed_vma, bfd_signed_vma);
103 static bfd_boolean pr_array_type
104 (void *, bfd_signed_vma, bfd_signed_vma, bfd_boolean);
105 static bfd_boolean pr_set_type (void *, bfd_boolean);
106 static bfd_boolean pr_offset_type (void *);
107 static bfd_boolean pr_method_type (void *, bfd_boolean, int, bfd_boolean);
108 static bfd_boolean pr_const_type (void *);
109 static bfd_boolean pr_volatile_type (void *);
110 static bfd_boolean pr_start_struct_type
111 (void *, const char *, unsigned int, bfd_boolean, unsigned int);
112 static bfd_boolean pr_struct_field
113 (void *, const char *, bfd_vma, bfd_vma, enum debug_visibility);
114 static bfd_boolean pr_end_struct_type (void *);
115 static bfd_boolean pr_start_class_type
116 (void *, const char *, unsigned int, bfd_boolean, unsigned int,
117 bfd_boolean, bfd_boolean);
118 static bfd_boolean pr_class_static_member
119 (void *, const char *, const char *, enum debug_visibility);
120 static bfd_boolean pr_class_baseclass
121 (void *, bfd_vma, bfd_boolean, enum debug_visibility);
122 static bfd_boolean pr_class_start_method (void *, const char *);
123 static bfd_boolean pr_class_method_variant
124 (void *, const char *, enum debug_visibility, bfd_boolean, bfd_boolean,
125 bfd_vma, bfd_boolean);
126 static bfd_boolean pr_class_static_method_variant
127 (void *, const char *, enum debug_visibility, bfd_boolean, bfd_boolean);
128 static bfd_boolean pr_class_end_method (void *);
129 static bfd_boolean pr_end_class_type (void *);
130 static bfd_boolean pr_typedef_type (void *, const char *);
131 static bfd_boolean pr_tag_type
132 (void *, const char *, unsigned int, enum debug_type_kind);
133 static bfd_boolean pr_typdef (void *, const char *);
134 static bfd_boolean pr_tag (void *, const char *);
135 static bfd_boolean pr_int_constant (void *, const char *, bfd_vma);
136 static bfd_boolean pr_float_constant (void *, const char *, double);
137 static bfd_boolean pr_typed_constant (void *, const char *, bfd_vma);
138 static bfd_boolean pr_variable
139 (void *, const char *, enum debug_var_kind, bfd_vma);
140 static bfd_boolean pr_start_function (void *, const char *, bfd_boolean);
141 static bfd_boolean pr_function_parameter
142 (void *, const char *, enum debug_parm_kind, bfd_vma);
143 static bfd_boolean pr_start_block (void *, bfd_vma);
144 static bfd_boolean pr_end_block (void *, bfd_vma);
145 static bfd_boolean pr_end_function (void *);
146 static bfd_boolean pr_lineno (void *, const char *, unsigned long, bfd_vma);
147 static bfd_boolean append_parent (struct pr_handle *, const char *);
148 /* Only used by tg_ code. */
149 static bfd_boolean tg_fix_visibility
150 (struct pr_handle *, enum debug_visibility);
151 static void find_address_in_section (bfd *, asection *, void *);
152 static void translate_addresses (bfd *, char *, FILE *, asymbol **);
153 static const char *visibility_name (enum debug_visibility);
154 /* Tags style replacements. */
155 static bfd_boolean tg_start_compilation_unit (void *, const char *);
156 static bfd_boolean tg_start_source (void *, const char *);
157 static bfd_boolean tg_enum_type
158 (void *, const char *, const char **, bfd_signed_vma *);
159 static bfd_boolean tg_start_struct_type
160 (void *, const char *, unsigned int, bfd_boolean, unsigned int);
161 static bfd_boolean pr_struct_field
162 (void *, const char *, bfd_vma, bfd_vma, enum debug_visibility);
163 static bfd_boolean tg_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_end_struct_type (void *);
168 static bfd_boolean tg_start_class_type
169 (void *, const char *, unsigned int, bfd_boolean, unsigned int, bfd_boolean, bfd_boolean);
170 static bfd_boolean tg_class_static_member
171 (void *, const char *, const char *, enum debug_visibility);
172 static bfd_boolean tg_class_baseclass
173 (void *, bfd_vma, bfd_boolean, enum debug_visibility);
174 static bfd_boolean tg_class_method_variant
175 (void *, const char *, enum debug_visibility, bfd_boolean, bfd_boolean, bfd_vma, bfd_boolean);
176 static bfd_boolean tg_class_static_method_variant
177 (void *, const char *, enum debug_visibility, bfd_boolean, bfd_boolean);
178 static bfd_boolean tg_end_class_type (void *);
179 static bfd_boolean tg_tag_type
180 (void *, const char *, unsigned int, enum debug_type_kind);
181 static bfd_boolean tg_typdef (void *, const char *);
182 static bfd_boolean tg_tag (void *, const char *);
183 static bfd_boolean tg_int_constant (void *, const char *, bfd_vma);
184 static bfd_boolean tg_float_constant (void *, const char *, double);
185 static bfd_boolean tg_typed_constant (void *, const char *, bfd_vma);
186 static bfd_boolean tg_variable
187 (void *, const char *, enum debug_var_kind, bfd_vma);
188 static bfd_boolean tg_start_function (void *, const char *, bfd_boolean);
189 static bfd_boolean tg_function_parameter
190 (void *, const char *, enum debug_parm_kind, bfd_vma);
191 static bfd_boolean tg_start_block (void *, bfd_vma);
192 static bfd_boolean tg_end_block (void *, bfd_vma);
193 static bfd_boolean tg_lineno (void *, const char *, unsigned long, bfd_vma);
195 static const struct debug_write_fns pr_fns =
197 pr_start_compilation_unit,
198 pr_start_source,
199 pr_empty_type,
200 pr_void_type,
201 pr_int_type,
202 pr_float_type,
203 pr_complex_type,
204 pr_bool_type,
205 pr_enum_type,
206 pr_pointer_type,
207 pr_function_type,
208 pr_reference_type,
209 pr_range_type,
210 pr_array_type,
211 pr_set_type,
212 pr_offset_type,
213 pr_method_type,
214 pr_const_type,
215 pr_volatile_type,
216 pr_start_struct_type,
217 pr_struct_field,
218 pr_end_struct_type,
219 pr_start_class_type,
220 pr_class_static_member,
221 pr_class_baseclass,
222 pr_class_start_method,
223 pr_class_method_variant,
224 pr_class_static_method_variant,
225 pr_class_end_method,
226 pr_end_class_type,
227 pr_typedef_type,
228 pr_tag_type,
229 pr_typdef,
230 pr_tag,
231 pr_int_constant,
232 pr_float_constant,
233 pr_typed_constant,
234 pr_variable,
235 pr_start_function,
236 pr_function_parameter,
237 pr_start_block,
238 pr_end_block,
239 pr_end_function,
240 pr_lineno
243 static const struct debug_write_fns tg_fns =
245 tg_start_compilation_unit,
246 tg_start_source,
247 pr_empty_type, /* Same, push_type. */
248 pr_void_type, /* Same, push_type. */
249 pr_int_type, /* Same, push_type. */
250 pr_float_type, /* Same, push_type. */
251 pr_complex_type, /* Same, push_type. */
252 pr_bool_type, /* Same, push_type. */
253 tg_enum_type,
254 pr_pointer_type, /* Same, changes to pointer. */
255 pr_function_type, /* Same, push_type. */
256 pr_reference_type, /* Same, changes to reference. */
257 pr_range_type, /* FIXME: What's that?. */
258 pr_array_type, /* Same, push_type. */
259 pr_set_type, /* FIXME: What's that?. */
260 pr_offset_type, /* FIXME: What's that?. */
261 pr_method_type, /* Same. */
262 pr_const_type, /* Same, changes to const. */
263 pr_volatile_type, /* Same, changes to volatile. */
264 tg_start_struct_type,
265 tg_struct_field,
266 tg_end_struct_type,
267 tg_start_class_type,
268 tg_class_static_member,
269 tg_class_baseclass,
270 pr_class_start_method, /* Same, remembers that's a method. */
271 tg_class_method_variant,
272 tg_class_static_method_variant,
273 pr_class_end_method, /* Same, forgets that's a method. */
274 tg_end_class_type,
275 pr_typedef_type, /* Same, just push type. */
276 tg_tag_type,
277 tg_typdef,
278 tg_tag,
279 tg_int_constant, /* Untested. */
280 tg_float_constant, /* Untested. */
281 tg_typed_constant, /* Untested. */
282 tg_variable,
283 tg_start_function,
284 tg_function_parameter,
285 tg_start_block,
286 tg_end_block,
287 pr_end_function, /* Same, does nothing. */
288 tg_lineno
291 /* Print out the generic debugging information recorded in dhandle. */
293 bfd_boolean
294 print_debugging_info (FILE *f, void *dhandle, bfd *abfd, asymbol **syms,
295 void *demangler, bfd_boolean as_tags)
297 struct pr_handle info;
299 info.f = f;
300 info.indent = 0;
301 info.stack = NULL;
302 info.parameter = 0;
303 info.filename = NULL;
304 info.abfd = abfd;
305 info.syms = syms;
306 info.demangler = demangler;
308 if (as_tags)
310 fputs ("!_TAG_FILE_FORMAT\t2\t/extended format/\n", f);
311 fputs ("!_TAG_FILE_SORTED\t0\t/0=unsorted, 1=sorted/\n", f);
312 fputs ("!_TAG_PROGRAM_AUTHOR\tIan Lance Taylor, Salvador E. Tropea and others\t//\n", f);
313 fputs ("!_TAG_PROGRAM_NAME\tobjdump\t/From GNU binutils/\n", f);
316 return as_tags ? debug_write (dhandle, &tg_fns, (void *) & info)
317 : debug_write (dhandle, &pr_fns, (void *) & info);
320 /* Indent to the current indentation level. */
322 static void
323 indent (struct pr_handle *info)
325 unsigned int i;
327 for (i = 0; i < info->indent; i++)
328 putc (' ', info->f);
331 /* Push a type on the type stack. */
333 static bfd_boolean
334 push_type (struct pr_handle *info, const char *type)
336 struct pr_stack *n;
338 if (type == NULL)
339 return FALSE;
341 n = (struct pr_stack *) xmalloc (sizeof *n);
342 memset (n, 0, sizeof *n);
344 n->type = xstrdup (type);
345 n->visibility = DEBUG_VISIBILITY_IGNORE;
346 n->method = NULL;
347 n->next = info->stack;
348 info->stack = n;
350 return TRUE;
353 /* Prepend a string onto the type on the top of the type stack. */
355 static bfd_boolean
356 prepend_type (struct pr_handle *info, const char *s)
358 char *n;
360 assert (info->stack != NULL);
362 n = (char *) xmalloc (strlen (s) + strlen (info->stack->type) + 1);
363 sprintf (n, "%s%s", s, info->stack->type);
364 free (info->stack->type);
365 info->stack->type = n;
367 return TRUE;
370 /* Append a string to the type on the top of the type stack. */
372 static bfd_boolean
373 append_type (struct pr_handle *info, const char *s)
375 unsigned int len;
377 if (s == NULL)
378 return FALSE;
380 assert (info->stack != NULL);
382 len = strlen (info->stack->type);
383 info->stack->type = (char *) xrealloc (info->stack->type,
384 len + strlen (s) + 1);
385 strcpy (info->stack->type + len, s);
387 return TRUE;
390 /* Append a string to the parents on the top of the type stack. */
392 static bfd_boolean
393 append_parent (struct pr_handle *info, const char *s)
395 unsigned int len;
397 if (s == NULL)
398 return FALSE;
400 assert (info->stack != NULL);
402 len = info->stack->parents ? strlen (info->stack->parents) : 0;
403 info->stack->parents = (char *) xrealloc (info->stack->parents,
404 len + strlen (s) + 1);
405 strcpy (info->stack->parents + len, s);
407 return TRUE;
410 /* We use an underscore to indicate where the name should go in a type
411 string. This function substitutes a string for the underscore. If
412 there is no underscore, the name follows the type. */
414 static bfd_boolean
415 substitute_type (struct pr_handle *info, const char *s)
417 char *u;
419 assert (info->stack != NULL);
421 u = strchr (info->stack->type, '|');
422 if (u != NULL)
424 char *n;
426 n = (char *) xmalloc (strlen (info->stack->type) + strlen (s));
428 memcpy (n, info->stack->type, u - info->stack->type);
429 strcpy (n + (u - info->stack->type), s);
430 strcat (n, u + 1);
432 free (info->stack->type);
433 info->stack->type = n;
435 return TRUE;
438 if (strchr (s, '|') != NULL
439 && (strchr (info->stack->type, '{') != NULL
440 || strchr (info->stack->type, '(') != NULL))
442 if (! prepend_type (info, "(")
443 || ! append_type (info, ")"))
444 return FALSE;
447 if (*s == '\0')
448 return TRUE;
450 return (append_type (info, " ")
451 && append_type (info, s));
454 /* Indent the type at the top of the stack by appending spaces. */
456 static bfd_boolean
457 indent_type (struct pr_handle *info)
459 unsigned int i;
461 for (i = 0; i < info->indent; i++)
463 if (! append_type (info, " "))
464 return FALSE;
467 return TRUE;
470 /* Pop a type from the type stack. */
472 static char *
473 pop_type (struct pr_handle *info)
475 struct pr_stack *o;
476 char *ret;
478 assert (info->stack != NULL);
480 o = info->stack;
481 info->stack = o->next;
482 ret = o->type;
483 free (o);
485 return ret;
488 /* Print a VMA value into a string. */
490 static void
491 print_vma (bfd_vma vma, char *buf, bfd_boolean unsignedp, bfd_boolean hexp)
493 if (sizeof (vma) <= sizeof (unsigned long))
495 if (hexp)
496 sprintf (buf, "0x%lx", (unsigned long) vma);
497 else if (unsignedp)
498 sprintf (buf, "%lu", (unsigned long) vma);
499 else
500 sprintf (buf, "%ld", (long) vma);
502 else
504 buf[0] = '0';
505 buf[1] = 'x';
506 sprintf_vma (buf + 2, vma);
510 /* Start a new compilation unit. */
512 static bfd_boolean
513 pr_start_compilation_unit (void *p, const char *filename)
515 struct pr_handle *info = (struct pr_handle *) p;
517 assert (info->indent == 0);
519 fprintf (info->f, "%s:\n", filename);
521 return TRUE;
524 /* Start a source file within a compilation unit. */
526 static bfd_boolean
527 pr_start_source (void *p, const char *filename)
529 struct pr_handle *info = (struct pr_handle *) p;
531 assert (info->indent == 0);
533 fprintf (info->f, " %s:\n", filename);
535 return TRUE;
538 /* Push an empty type onto the type stack. */
540 static bfd_boolean
541 pr_empty_type (void *p)
543 struct pr_handle *info = (struct pr_handle *) p;
545 return push_type (info, "<undefined>");
548 /* Push a void type onto the type stack. */
550 static bfd_boolean
551 pr_void_type (void *p)
553 struct pr_handle *info = (struct pr_handle *) p;
555 return push_type (info, "void");
558 /* Push an integer type onto the type stack. */
560 static bfd_boolean
561 pr_int_type (void *p, unsigned int size, bfd_boolean unsignedp)
563 struct pr_handle *info = (struct pr_handle *) p;
564 char ab[10];
566 sprintf (ab, "%sint%d", unsignedp ? "u" : "", size * 8);
567 return push_type (info, ab);
570 /* Push a floating type onto the type stack. */
572 static bfd_boolean
573 pr_float_type (void *p, unsigned int size)
575 struct pr_handle *info = (struct pr_handle *) p;
576 char ab[10];
578 if (size == 4)
579 return push_type (info, "float");
580 else if (size == 8)
581 return push_type (info, "double");
583 sprintf (ab, "float%d", size * 8);
584 return push_type (info, ab);
587 /* Push a complex type onto the type stack. */
589 static bfd_boolean
590 pr_complex_type (void *p, unsigned int size)
592 struct pr_handle *info = (struct pr_handle *) p;
594 if (! pr_float_type (p, size))
595 return FALSE;
597 return prepend_type (info, "complex ");
600 /* Push a bfd_boolean type onto the type stack. */
602 static bfd_boolean
603 pr_bool_type (void *p, unsigned int size)
605 struct pr_handle *info = (struct pr_handle *) p;
606 char ab[10];
608 sprintf (ab, "bool%d", size * 8);
610 return push_type (info, ab);
613 /* Push an enum type onto the type stack. */
615 static bfd_boolean
616 pr_enum_type (void *p, const char *tag, const char **names,
617 bfd_signed_vma *values)
619 struct pr_handle *info = (struct pr_handle *) p;
620 unsigned int i;
621 bfd_signed_vma val;
623 if (! push_type (info, "enum "))
624 return FALSE;
625 if (tag != NULL)
627 if (! append_type (info, tag)
628 || ! append_type (info, " "))
629 return FALSE;
631 if (! append_type (info, "{ "))
632 return FALSE;
634 if (names == NULL)
636 if (! append_type (info, "/* undefined */"))
637 return FALSE;
639 else
641 val = 0;
642 for (i = 0; names[i] != NULL; i++)
644 if (i > 0)
646 if (! append_type (info, ", "))
647 return FALSE;
650 if (! append_type (info, names[i]))
651 return FALSE;
653 if (values[i] != val)
655 char ab[20];
657 print_vma (values[i], ab, FALSE, FALSE);
658 if (! append_type (info, " = ")
659 || ! append_type (info, ab))
660 return FALSE;
661 val = values[i];
664 ++val;
668 return append_type (info, " }");
671 /* Turn the top type on the stack into a pointer. */
673 static bfd_boolean
674 pr_pointer_type (void *p)
676 struct pr_handle *info = (struct pr_handle *) p;
677 char *s;
679 assert (info->stack != NULL);
681 s = strchr (info->stack->type, '|');
682 if (s != NULL && s[1] == '[')
683 return substitute_type (info, "(*|)");
684 return substitute_type (info, "*|");
687 /* Turn the top type on the stack into a function returning that type. */
689 static bfd_boolean
690 pr_function_type (void *p, int argcount, bfd_boolean varargs)
692 struct pr_handle *info = (struct pr_handle *) p;
693 char **arg_types;
694 unsigned int len;
695 char *s;
697 assert (info->stack != NULL);
699 len = 10;
701 if (argcount <= 0)
703 arg_types = NULL;
704 len += 15;
706 else
708 int i;
710 arg_types = (char **) xmalloc (argcount * sizeof *arg_types);
711 for (i = argcount - 1; i >= 0; i--)
713 if (! substitute_type (info, ""))
714 return FALSE;
715 arg_types[i] = pop_type (info);
716 if (arg_types[i] == NULL)
717 return FALSE;
718 len += strlen (arg_types[i]) + 2;
720 if (varargs)
721 len += 5;
724 /* Now the return type is on the top of the stack. */
726 s = (char *) xmalloc (len);
727 strcpy (s, "(|) (");
729 if (argcount < 0)
730 strcat (s, "/* unknown */");
731 else
733 int i;
735 for (i = 0; i < argcount; i++)
737 if (i > 0)
738 strcat (s, ", ");
739 strcat (s, arg_types[i]);
741 if (varargs)
743 if (i > 0)
744 strcat (s, ", ");
745 strcat (s, "...");
747 if (argcount > 0)
748 free (arg_types);
751 strcat (s, ")");
753 if (! substitute_type (info, s))
754 return FALSE;
756 free (s);
758 return TRUE;
761 /* Turn the top type on the stack into a reference to that type. */
763 static bfd_boolean
764 pr_reference_type (void *p)
766 struct pr_handle *info = (struct pr_handle *) p;
768 assert (info->stack != NULL);
770 return substitute_type (info, "&|");
773 /* Make a range type. */
775 static bfd_boolean
776 pr_range_type (void *p, bfd_signed_vma lower, bfd_signed_vma upper)
778 struct pr_handle *info = (struct pr_handle *) p;
779 char abl[20], abu[20];
781 assert (info->stack != NULL);
783 if (! substitute_type (info, ""))
784 return FALSE;
786 print_vma (lower, abl, FALSE, FALSE);
787 print_vma (upper, abu, FALSE, FALSE);
789 return (prepend_type (info, "range (")
790 && append_type (info, "):")
791 && append_type (info, abl)
792 && append_type (info, ":")
793 && append_type (info, abu));
796 /* Make an array type. */
798 static bfd_boolean
799 pr_array_type (void *p, bfd_signed_vma lower, bfd_signed_vma upper,
800 bfd_boolean stringp)
802 struct pr_handle *info = (struct pr_handle *) p;
803 char *range_type;
804 char abl[20], abu[20], ab[50];
806 range_type = pop_type (info);
807 if (range_type == NULL)
808 return FALSE;
810 if (lower == 0)
812 if (upper == -1)
813 sprintf (ab, "|[]");
814 else
816 print_vma (upper + 1, abu, FALSE, FALSE);
817 sprintf (ab, "|[%s]", abu);
820 else
822 print_vma (lower, abl, FALSE, FALSE);
823 print_vma (upper, abu, FALSE, FALSE);
824 sprintf (ab, "|[%s:%s]", abl, abu);
827 if (! substitute_type (info, ab))
828 return FALSE;
830 if (strcmp (range_type, "int") != 0)
832 if (! append_type (info, ":")
833 || ! append_type (info, range_type))
834 return FALSE;
837 if (stringp)
839 if (! append_type (info, " /* string */"))
840 return FALSE;
843 return TRUE;
846 /* Make a set type. */
848 static bfd_boolean
849 pr_set_type (void *p, bfd_boolean bitstringp)
851 struct pr_handle *info = (struct pr_handle *) p;
853 if (! substitute_type (info, ""))
854 return FALSE;
856 if (! prepend_type (info, "set { ")
857 || ! append_type (info, " }"))
858 return FALSE;
860 if (bitstringp)
862 if (! append_type (info, "/* bitstring */"))
863 return FALSE;
866 return TRUE;
869 /* Make an offset type. */
871 static bfd_boolean
872 pr_offset_type (void *p)
874 struct pr_handle *info = (struct pr_handle *) p;
875 char *t;
877 if (! substitute_type (info, ""))
878 return FALSE;
880 t = pop_type (info);
881 if (t == NULL)
882 return FALSE;
884 return (substitute_type (info, "")
885 && prepend_type (info, " ")
886 && prepend_type (info, t)
887 && append_type (info, "::|"));
890 /* Make a method type. */
892 static bfd_boolean
893 pr_method_type (void *p, bfd_boolean domain, int argcount, bfd_boolean varargs)
895 struct pr_handle *info = (struct pr_handle *) p;
896 unsigned int len;
897 char *domain_type;
898 char **arg_types;
899 char *s;
901 len = 10;
903 if (! domain)
904 domain_type = NULL;
905 else
907 if (! substitute_type (info, ""))
908 return FALSE;
909 domain_type = pop_type (info);
910 if (domain_type == NULL)
911 return FALSE;
912 if (strncmp (domain_type, "class ", sizeof "class " - 1) == 0
913 && strchr (domain_type + sizeof "class " - 1, ' ') == NULL)
914 domain_type += sizeof "class " - 1;
915 else if (strncmp (domain_type, "union class ",
916 sizeof "union class ") == 0
917 && (strchr (domain_type + sizeof "union class " - 1, ' ')
918 == NULL))
919 domain_type += sizeof "union class " - 1;
920 len += strlen (domain_type);
923 if (argcount <= 0)
925 arg_types = NULL;
926 len += 15;
928 else
930 int i;
932 arg_types = (char **) xmalloc (argcount * sizeof *arg_types);
933 for (i = argcount - 1; i >= 0; i--)
935 if (! substitute_type (info, ""))
936 return FALSE;
937 arg_types[i] = pop_type (info);
938 if (arg_types[i] == NULL)
939 return FALSE;
940 len += strlen (arg_types[i]) + 2;
942 if (varargs)
943 len += 5;
946 /* Now the return type is on the top of the stack. */
948 s = (char *) xmalloc (len);
949 if (! domain)
950 *s = '\0';
951 else
952 strcpy (s, domain_type);
953 strcat (s, "::| (");
955 if (argcount < 0)
956 strcat (s, "/* unknown */");
957 else
959 int i;
961 for (i = 0; i < argcount; i++)
963 if (i > 0)
964 strcat (s, ", ");
965 strcat (s, arg_types[i]);
967 if (varargs)
969 if (i > 0)
970 strcat (s, ", ");
971 strcat (s, "...");
973 if (argcount > 0)
974 free (arg_types);
977 strcat (s, ")");
979 if (! substitute_type (info, s))
980 return FALSE;
982 free (s);
984 return TRUE;
987 /* Make a const qualified type. */
989 static bfd_boolean
990 pr_const_type (void *p)
992 struct pr_handle *info = (struct pr_handle *) p;
994 return substitute_type (info, "const |");
997 /* Make a volatile qualified type. */
999 static bfd_boolean
1000 pr_volatile_type (void *p)
1002 struct pr_handle *info = (struct pr_handle *) p;
1004 return substitute_type (info, "volatile |");
1007 /* Start accumulating a struct type. */
1009 static bfd_boolean
1010 pr_start_struct_type (void *p, const char *tag, unsigned int id,
1011 bfd_boolean structp, unsigned int size)
1013 struct pr_handle *info = (struct pr_handle *) p;
1015 info->indent += 2;
1017 if (! push_type (info, structp ? "struct " : "union "))
1018 return FALSE;
1019 if (tag != NULL)
1021 if (! append_type (info, tag))
1022 return FALSE;
1024 else
1026 char idbuf[20];
1028 sprintf (idbuf, "%%anon%u", id);
1029 if (! append_type (info, idbuf))
1030 return FALSE;
1033 if (! append_type (info, " {"))
1034 return FALSE;
1035 if (size != 0 || tag != NULL)
1037 char ab[30];
1039 if (! append_type (info, " /*"))
1040 return FALSE;
1042 if (size != 0)
1044 sprintf (ab, " size %u", size);
1045 if (! append_type (info, ab))
1046 return FALSE;
1048 if (tag != NULL)
1050 sprintf (ab, " id %u", id);
1051 if (! append_type (info, ab))
1052 return FALSE;
1054 if (! append_type (info, " */"))
1055 return FALSE;
1057 if (! append_type (info, "\n"))
1058 return FALSE;
1060 info->stack->visibility = DEBUG_VISIBILITY_PUBLIC;
1062 return indent_type (info);
1065 /* Output the visibility of a field in a struct. */
1067 static bfd_boolean
1068 pr_fix_visibility (struct pr_handle *info, enum debug_visibility visibility)
1070 const char *s = NULL;
1071 char *t;
1072 unsigned int len;
1074 assert (info->stack != NULL);
1076 if (info->stack->visibility == visibility)
1077 return TRUE;
1079 switch (visibility)
1081 case DEBUG_VISIBILITY_PUBLIC:
1082 s = "public";
1083 break;
1084 case DEBUG_VISIBILITY_PRIVATE:
1085 s = "private";
1086 break;
1087 case DEBUG_VISIBILITY_PROTECTED:
1088 s = "protected";
1089 break;
1090 case DEBUG_VISIBILITY_IGNORE:
1091 s = "/* ignore */";
1092 break;
1093 default:
1094 abort ();
1095 return FALSE;
1098 /* Trim off a trailing space in the struct string, to make the
1099 output look a bit better, then stick on the visibility string. */
1101 t = info->stack->type;
1102 len = strlen (t);
1103 assert (t[len - 1] == ' ');
1104 t[len - 1] = '\0';
1106 if (! append_type (info, s)
1107 || ! append_type (info, ":\n")
1108 || ! indent_type (info))
1109 return FALSE;
1111 info->stack->visibility = visibility;
1113 return TRUE;
1116 /* Add a field to a struct type. */
1118 static bfd_boolean
1119 pr_struct_field (void *p, const char *name, bfd_vma bitpos, bfd_vma bitsize,
1120 enum debug_visibility visibility)
1122 struct pr_handle *info = (struct pr_handle *) p;
1123 char ab[20];
1124 char *t;
1126 if (! substitute_type (info, name))
1127 return FALSE;
1129 if (! append_type (info, "; /* "))
1130 return FALSE;
1132 if (bitsize != 0)
1134 print_vma (bitsize, ab, TRUE, FALSE);
1135 if (! append_type (info, "bitsize ")
1136 || ! append_type (info, ab)
1137 || ! append_type (info, ", "))
1138 return FALSE;
1141 print_vma (bitpos, ab, TRUE, FALSE);
1142 if (! append_type (info, "bitpos ")
1143 || ! append_type (info, ab)
1144 || ! append_type (info, " */\n")
1145 || ! indent_type (info))
1146 return FALSE;
1148 t = pop_type (info);
1149 if (t == NULL)
1150 return FALSE;
1152 if (! pr_fix_visibility (info, visibility))
1153 return FALSE;
1155 return append_type (info, t);
1158 /* Finish a struct type. */
1160 static bfd_boolean
1161 pr_end_struct_type (void *p)
1163 struct pr_handle *info = (struct pr_handle *) p;
1164 char *s;
1166 assert (info->stack != NULL);
1167 assert (info->indent >= 2);
1169 info->indent -= 2;
1171 /* Change the trailing indentation to have a close brace. */
1172 s = info->stack->type + strlen (info->stack->type) - 2;
1173 assert (s[0] == ' ' && s[1] == ' ' && s[2] == '\0');
1175 *s++ = '}';
1176 *s = '\0';
1178 return TRUE;
1181 /* Start a class type. */
1183 static bfd_boolean
1184 pr_start_class_type (void *p, const char *tag, unsigned int id,
1185 bfd_boolean structp, unsigned int size,
1186 bfd_boolean vptr, bfd_boolean ownvptr)
1188 struct pr_handle *info = (struct pr_handle *) p;
1189 char *tv = NULL;
1191 info->indent += 2;
1193 if (vptr && ! ownvptr)
1195 tv = pop_type (info);
1196 if (tv == NULL)
1197 return FALSE;
1200 if (! push_type (info, structp ? "class " : "union class "))
1201 return FALSE;
1202 if (tag != NULL)
1204 if (! append_type (info, tag))
1205 return FALSE;
1207 else
1209 char idbuf[20];
1211 sprintf (idbuf, "%%anon%u", id);
1212 if (! append_type (info, idbuf))
1213 return FALSE;
1216 if (! append_type (info, " {"))
1217 return FALSE;
1218 if (size != 0 || vptr || ownvptr || tag != NULL)
1220 if (! append_type (info, " /*"))
1221 return FALSE;
1223 if (size != 0)
1225 char ab[20];
1227 sprintf (ab, "%u", size);
1228 if (! append_type (info, " size ")
1229 || ! append_type (info, ab))
1230 return FALSE;
1233 if (vptr)
1235 if (! append_type (info, " vtable "))
1236 return FALSE;
1237 if (ownvptr)
1239 if (! append_type (info, "self "))
1240 return FALSE;
1242 else
1244 if (! append_type (info, tv)
1245 || ! append_type (info, " "))
1246 return FALSE;
1250 if (tag != NULL)
1252 char ab[30];
1254 sprintf (ab, " id %u", id);
1255 if (! append_type (info, ab))
1256 return FALSE;
1259 if (! append_type (info, " */"))
1260 return FALSE;
1263 info->stack->visibility = DEBUG_VISIBILITY_PRIVATE;
1265 return (append_type (info, "\n")
1266 && indent_type (info));
1269 /* Add a static member to a class. */
1271 static bfd_boolean
1272 pr_class_static_member (void *p, const char *name, const char *physname,
1273 enum debug_visibility visibility)
1275 struct pr_handle *info = (struct pr_handle *) p;
1276 char *t;
1278 if (! substitute_type (info, name))
1279 return FALSE;
1281 if (! prepend_type (info, "static ")
1282 || ! append_type (info, "; /* ")
1283 || ! append_type (info, physname)
1284 || ! append_type (info, " */\n")
1285 || ! indent_type (info))
1286 return FALSE;
1288 t = pop_type (info);
1289 if (t == NULL)
1290 return FALSE;
1292 if (! pr_fix_visibility (info, visibility))
1293 return FALSE;
1295 return append_type (info, t);
1298 /* Add a base class to a class. */
1300 static bfd_boolean
1301 pr_class_baseclass (void *p, bfd_vma bitpos, bfd_boolean virtual,
1302 enum debug_visibility visibility)
1304 struct pr_handle *info = (struct pr_handle *) p;
1305 char *t;
1306 const char *prefix;
1307 char ab[20];
1308 char *s, *l, *n;
1310 assert (info->stack != NULL && info->stack->next != NULL);
1312 if (! substitute_type (info, ""))
1313 return FALSE;
1315 t = pop_type (info);
1316 if (t == NULL)
1317 return FALSE;
1319 if (strncmp (t, "class ", sizeof "class " - 1) == 0)
1320 t += sizeof "class " - 1;
1322 /* Push it back on to take advantage of the prepend_type and
1323 append_type routines. */
1324 if (! push_type (info, t))
1325 return FALSE;
1327 if (virtual)
1329 if (! prepend_type (info, "virtual "))
1330 return FALSE;
1333 switch (visibility)
1335 case DEBUG_VISIBILITY_PUBLIC:
1336 prefix = "public ";
1337 break;
1338 case DEBUG_VISIBILITY_PROTECTED:
1339 prefix = "protected ";
1340 break;
1341 case DEBUG_VISIBILITY_PRIVATE:
1342 prefix = "private ";
1343 break;
1344 default:
1345 prefix = "/* unknown visibility */ ";
1346 break;
1349 if (! prepend_type (info, prefix))
1350 return FALSE;
1352 if (bitpos != 0)
1354 print_vma (bitpos, ab, TRUE, FALSE);
1355 if (! append_type (info, " /* bitpos ")
1356 || ! append_type (info, ab)
1357 || ! append_type (info, " */"))
1358 return FALSE;
1361 /* Now the top of the stack is something like "public A / * bitpos
1362 10 * /". The next element on the stack is something like "class
1363 xx { / * size 8 * /\n...". We want to substitute the top of the
1364 stack in before the {. */
1365 s = strchr (info->stack->next->type, '{');
1366 assert (s != NULL);
1367 --s;
1369 /* If there is already a ':', then we already have a baseclass, and
1370 we must append this one after a comma. */
1371 for (l = info->stack->next->type; l != s; l++)
1372 if (*l == ':')
1373 break;
1374 if (! prepend_type (info, l == s ? " : " : ", "))
1375 return FALSE;
1377 t = pop_type (info);
1378 if (t == NULL)
1379 return FALSE;
1381 n = (char *) xmalloc (strlen (info->stack->type) + strlen (t) + 1);
1382 memcpy (n, info->stack->type, s - info->stack->type);
1383 strcpy (n + (s - info->stack->type), t);
1384 strcat (n, s);
1386 free (info->stack->type);
1387 info->stack->type = n;
1389 free (t);
1391 return TRUE;
1394 /* Start adding a method to a class. */
1396 static bfd_boolean
1397 pr_class_start_method (void *p, const char *name)
1399 struct pr_handle *info = (struct pr_handle *) p;
1401 assert (info->stack != NULL);
1402 info->stack->method = name;
1403 return TRUE;
1406 /* Add a variant to a method. */
1408 static bfd_boolean
1409 pr_class_method_variant (void *p, const char *physname,
1410 enum debug_visibility visibility,
1411 bfd_boolean constp, bfd_boolean volatilep,
1412 bfd_vma voffset, bfd_boolean context)
1414 struct pr_handle *info = (struct pr_handle *) p;
1415 char *method_type;
1416 char *context_type;
1418 assert (info->stack != NULL);
1419 assert (info->stack->next != NULL);
1421 /* Put the const and volatile qualifiers on the type. */
1422 if (volatilep)
1424 if (! append_type (info, " volatile"))
1425 return FALSE;
1427 if (constp)
1429 if (! append_type (info, " const"))
1430 return FALSE;
1433 /* Stick the name of the method into its type. */
1434 if (! substitute_type (info,
1435 (context
1436 ? info->stack->next->next->method
1437 : info->stack->next->method)))
1438 return FALSE;
1440 /* Get the type. */
1441 method_type = pop_type (info);
1442 if (method_type == NULL)
1443 return FALSE;
1445 /* Pull off the context type if there is one. */
1446 if (! context)
1447 context_type = NULL;
1448 else
1450 context_type = pop_type (info);
1451 if (context_type == NULL)
1452 return FALSE;
1455 /* Now the top of the stack is the class. */
1457 if (! pr_fix_visibility (info, visibility))
1458 return FALSE;
1460 if (! append_type (info, method_type)
1461 || ! append_type (info, " /* ")
1462 || ! append_type (info, physname)
1463 || ! append_type (info, " "))
1464 return FALSE;
1465 if (context || voffset != 0)
1467 char ab[20];
1469 if (context)
1471 if (! append_type (info, "context ")
1472 || ! append_type (info, context_type)
1473 || ! append_type (info, " "))
1474 return FALSE;
1476 print_vma (voffset, ab, TRUE, FALSE);
1477 if (! append_type (info, "voffset ")
1478 || ! append_type (info, ab))
1479 return FALSE;
1482 return (append_type (info, " */;\n")
1483 && indent_type (info));
1486 /* Add a static variant to a method. */
1488 static bfd_boolean
1489 pr_class_static_method_variant (void *p, const char *physname,
1490 enum debug_visibility visibility,
1491 bfd_boolean constp, bfd_boolean volatilep)
1493 struct pr_handle *info = (struct pr_handle *) p;
1494 char *method_type;
1496 assert (info->stack != NULL);
1497 assert (info->stack->next != NULL);
1498 assert (info->stack->next->method != NULL);
1500 /* Put the const and volatile qualifiers on the type. */
1501 if (volatilep)
1503 if (! append_type (info, " volatile"))
1504 return FALSE;
1506 if (constp)
1508 if (! append_type (info, " const"))
1509 return FALSE;
1512 /* Mark it as static. */
1513 if (! prepend_type (info, "static "))
1514 return FALSE;
1516 /* Stick the name of the method into its type. */
1517 if (! substitute_type (info, info->stack->next->method))
1518 return FALSE;
1520 /* Get the type. */
1521 method_type = pop_type (info);
1522 if (method_type == NULL)
1523 return FALSE;
1525 /* Now the top of the stack is the class. */
1527 if (! pr_fix_visibility (info, visibility))
1528 return FALSE;
1530 return (append_type (info, method_type)
1531 && append_type (info, " /* ")
1532 && append_type (info, physname)
1533 && append_type (info, " */;\n")
1534 && indent_type (info));
1537 /* Finish up a method. */
1539 static bfd_boolean
1540 pr_class_end_method (void *p)
1542 struct pr_handle *info = (struct pr_handle *) p;
1544 info->stack->method = NULL;
1545 return TRUE;
1548 /* Finish up a class. */
1550 static bfd_boolean
1551 pr_end_class_type (void *p)
1553 return pr_end_struct_type (p);
1556 /* Push a type on the stack using a typedef name. */
1558 static bfd_boolean
1559 pr_typedef_type (void *p, const char *name)
1561 struct pr_handle *info = (struct pr_handle *) p;
1563 return push_type (info, name);
1566 /* Push a type on the stack using a tag name. */
1568 static bfd_boolean
1569 pr_tag_type (void *p, const char *name, unsigned int id,
1570 enum debug_type_kind kind)
1572 struct pr_handle *info = (struct pr_handle *) p;
1573 const char *t, *tag;
1574 char idbuf[20];
1576 switch (kind)
1578 case DEBUG_KIND_STRUCT:
1579 t = "struct ";
1580 break;
1581 case DEBUG_KIND_UNION:
1582 t = "union ";
1583 break;
1584 case DEBUG_KIND_ENUM:
1585 t = "enum ";
1586 break;
1587 case DEBUG_KIND_CLASS:
1588 t = "class ";
1589 break;
1590 case DEBUG_KIND_UNION_CLASS:
1591 t = "union class ";
1592 break;
1593 default:
1594 abort ();
1595 return FALSE;
1598 if (! push_type (info, t))
1599 return FALSE;
1600 if (name != NULL)
1601 tag = name;
1602 else
1604 sprintf (idbuf, "%%anon%u", id);
1605 tag = idbuf;
1608 if (! append_type (info, tag))
1609 return FALSE;
1610 if (name != NULL && kind != DEBUG_KIND_ENUM)
1612 sprintf (idbuf, " /* id %u */", id);
1613 if (! append_type (info, idbuf))
1614 return FALSE;
1617 return TRUE;
1620 /* Output a typedef. */
1622 static bfd_boolean
1623 pr_typdef (void *p, const char *name)
1625 struct pr_handle *info = (struct pr_handle *) p;
1626 char *s;
1628 if (! substitute_type (info, name))
1629 return FALSE;
1631 s = pop_type (info);
1632 if (s == NULL)
1633 return FALSE;
1635 indent (info);
1636 fprintf (info->f, "typedef %s;\n", s);
1638 free (s);
1640 return TRUE;
1643 /* Output a tag. The tag should already be in the string on the
1644 stack, so all we have to do here is print it out. */
1646 static bfd_boolean
1647 pr_tag (void *p, const char *name ATTRIBUTE_UNUSED)
1649 struct pr_handle *info = (struct pr_handle *) p;
1650 char *t;
1652 t = pop_type (info);
1653 if (t == NULL)
1654 return FALSE;
1656 indent (info);
1657 fprintf (info->f, "%s;\n", t);
1659 free (t);
1661 return TRUE;
1664 /* Output an integer constant. */
1666 static bfd_boolean
1667 pr_int_constant (void *p, const char *name, bfd_vma val)
1669 struct pr_handle *info = (struct pr_handle *) p;
1670 char ab[20];
1672 indent (info);
1673 print_vma (val, ab, FALSE, FALSE);
1674 fprintf (info->f, "const int %s = %s;\n", name, ab);
1675 return TRUE;
1678 /* Output a floating point constant. */
1680 static bfd_boolean
1681 pr_float_constant (void *p, const char *name, double val)
1683 struct pr_handle *info = (struct pr_handle *) p;
1685 indent (info);
1686 fprintf (info->f, "const double %s = %g;\n", name, val);
1687 return TRUE;
1690 /* Output a typed constant. */
1692 static bfd_boolean
1693 pr_typed_constant (void *p, const char *name, bfd_vma val)
1695 struct pr_handle *info = (struct pr_handle *) p;
1696 char *t;
1697 char ab[20];
1699 t = pop_type (info);
1700 if (t == NULL)
1701 return FALSE;
1703 indent (info);
1704 print_vma (val, ab, FALSE, FALSE);
1705 fprintf (info->f, "const %s %s = %s;\n", t, name, ab);
1707 free (t);
1709 return TRUE;
1712 /* Output a variable. */
1714 static bfd_boolean
1715 pr_variable (void *p, const char *name, enum debug_var_kind kind,
1716 bfd_vma val)
1718 struct pr_handle *info = (struct pr_handle *) p;
1719 char *t;
1720 char ab[20];
1722 if (! substitute_type (info, name))
1723 return FALSE;
1725 t = pop_type (info);
1726 if (t == NULL)
1727 return FALSE;
1729 indent (info);
1730 switch (kind)
1732 case DEBUG_STATIC:
1733 case DEBUG_LOCAL_STATIC:
1734 fprintf (info->f, "static ");
1735 break;
1736 case DEBUG_REGISTER:
1737 fprintf (info->f, "register ");
1738 break;
1739 default:
1740 break;
1742 print_vma (val, ab, TRUE, TRUE);
1743 fprintf (info->f, "%s /* %s */;\n", t, ab);
1745 free (t);
1747 return TRUE;
1750 /* Start outputting a function. */
1752 static bfd_boolean
1753 pr_start_function (void *p, const char *name, bfd_boolean global)
1755 struct pr_handle *info = (struct pr_handle *) p;
1756 char *t;
1758 if (! substitute_type (info, name))
1759 return FALSE;
1761 t = pop_type (info);
1762 if (t == NULL)
1763 return FALSE;
1765 indent (info);
1766 if (! global)
1767 fprintf (info->f, "static ");
1768 fprintf (info->f, "%s (", t);
1770 info->parameter = 1;
1772 return TRUE;
1775 /* Output a function parameter. */
1777 static bfd_boolean
1778 pr_function_parameter (void *p, const char *name,
1779 enum debug_parm_kind kind, bfd_vma val)
1781 struct pr_handle *info = (struct pr_handle *) p;
1782 char *t;
1783 char ab[20];
1785 if (kind == DEBUG_PARM_REFERENCE
1786 || kind == DEBUG_PARM_REF_REG)
1788 if (! pr_reference_type (p))
1789 return FALSE;
1792 if (! substitute_type (info, name))
1793 return FALSE;
1795 t = pop_type (info);
1796 if (t == NULL)
1797 return FALSE;
1799 if (info->parameter != 1)
1800 fprintf (info->f, ", ");
1802 if (kind == DEBUG_PARM_REG || kind == DEBUG_PARM_REF_REG)
1803 fprintf (info->f, "register ");
1805 print_vma (val, ab, TRUE, TRUE);
1806 fprintf (info->f, "%s /* %s */", t, ab);
1808 free (t);
1810 ++info->parameter;
1812 return TRUE;
1815 /* Start writing out a block. */
1817 static bfd_boolean
1818 pr_start_block (void *p, bfd_vma addr)
1820 struct pr_handle *info = (struct pr_handle *) p;
1821 char ab[20];
1823 if (info->parameter > 0)
1825 fprintf (info->f, ")\n");
1826 info->parameter = 0;
1829 indent (info);
1830 print_vma (addr, ab, TRUE, TRUE);
1831 fprintf (info->f, "{ /* %s */\n", ab);
1833 info->indent += 2;
1835 return TRUE;
1838 /* Write out line number information. */
1840 static bfd_boolean
1841 pr_lineno (void *p, const char *filename, unsigned long lineno, bfd_vma addr)
1843 struct pr_handle *info = (struct pr_handle *) p;
1844 char ab[20];
1846 indent (info);
1847 print_vma (addr, ab, TRUE, TRUE);
1848 fprintf (info->f, "/* file %s line %lu addr %s */\n", filename, lineno, ab);
1850 return TRUE;
1853 /* Finish writing out a block. */
1855 static bfd_boolean
1856 pr_end_block (void *p, bfd_vma addr)
1858 struct pr_handle *info = (struct pr_handle *) p;
1859 char ab[20];
1861 info->indent -= 2;
1863 indent (info);
1864 print_vma (addr, ab, TRUE, TRUE);
1865 fprintf (info->f, "} /* %s */\n", ab);
1867 return TRUE;
1870 /* Finish writing out a function. */
1872 static bfd_boolean
1873 pr_end_function (void *p ATTRIBUTE_UNUSED)
1875 return TRUE;
1878 /* Tags style generation functions start here. */
1880 /* Variables for address to line translation. */
1881 static bfd_vma pc;
1882 static const char *filename;
1883 static const char *functionname;
1884 static unsigned int line;
1885 static bfd_boolean found;
1887 /* Look for an address in a section. This is called via
1888 bfd_map_over_sections. */
1890 static void
1891 find_address_in_section (bfd *abfd, asection *section, void *data)
1893 bfd_vma vma;
1894 bfd_size_type size;
1895 asymbol **syms = (asymbol **) data;
1897 if (found)
1898 return;
1900 if ((bfd_get_section_flags (abfd, section) & SEC_ALLOC) == 0)
1901 return;
1903 vma = bfd_get_section_vma (abfd, section);
1904 if (pc < vma)
1905 return;
1907 size = bfd_get_section_size (section);
1908 if (pc >= vma + size)
1909 return;
1911 found = bfd_find_nearest_line (abfd, section, syms, pc - vma,
1912 &filename, &functionname, &line);
1915 static void
1916 translate_addresses (bfd *abfd, char *addr_hex, FILE *f, asymbol **syms)
1918 pc = bfd_scan_vma (addr_hex, NULL, 16);
1919 found = FALSE;
1920 bfd_map_over_sections (abfd, find_address_in_section, syms);
1922 if (! found)
1923 fprintf (f, "??");
1924 else
1925 fprintf (f, "%u", line);
1928 /* Start a new compilation unit. */
1930 static bfd_boolean
1931 tg_start_compilation_unit (void * p, const char *filename ATTRIBUTE_UNUSED)
1933 struct pr_handle *info = (struct pr_handle *) p;
1935 fprintf (stderr, "New compilation unit: %s\n", filename);
1937 free (info->filename);
1938 /* Should it be relative? best way to do it here?. */
1939 info->filename = strdup (filename);
1941 return TRUE;
1944 /* Start a source file within a compilation unit. */
1946 static bfd_boolean
1947 tg_start_source (void *p, const char *filename)
1949 struct pr_handle *info = (struct pr_handle *) p;
1951 free (info->filename);
1952 /* Should it be relative? best way to do it here?. */
1953 info->filename = strdup (filename);
1955 return TRUE;
1958 /* Push an enum type onto the type stack. */
1960 static bfd_boolean
1961 tg_enum_type (void *p, const char *tag, const char **names,
1962 bfd_signed_vma *values)
1964 struct pr_handle *info = (struct pr_handle *) p;
1965 unsigned int i;
1966 const char *name;
1967 char ab[20];
1969 if (! pr_enum_type (p, tag, names, values))
1970 return FALSE;
1972 name = tag ? tag : "unknown";
1973 /* Generate an entry for the enum. */
1974 if (tag)
1975 fprintf (info->f, "%s\t%s\t0;\"\tkind:e\ttype:%s\n", tag,
1976 info->filename, info->stack->type);
1978 /* Generate entries for the values. */
1979 if (names != NULL)
1981 for (i = 0; names[i] != NULL; i++)
1983 print_vma (values[i], ab, FALSE, FALSE);
1984 fprintf (info->f, "%s\t%s\t0;\"\tkind:g\tenum:%s\tvalue:%s\n",
1985 names[i], info->filename, name, ab);
1989 return TRUE;
1992 /* Start accumulating a struct type. */
1994 static bfd_boolean
1995 tg_start_struct_type (void *p, const char *tag, unsigned int id,
1996 bfd_boolean structp,
1997 unsigned int size ATTRIBUTE_UNUSED)
1999 struct pr_handle *info = (struct pr_handle *) p;
2000 const char *name;
2001 char idbuf[20];
2003 if (tag != NULL)
2004 name = tag;
2005 else
2007 name = idbuf;
2008 sprintf (idbuf, "%%anon%u", id);
2011 if (! push_type (info, name))
2012 return FALSE;
2014 info->stack->flavor = structp ? "struct" : "union";
2016 fprintf (info->f, "%s\t%s\t0;\"\tkind:%c\n", name, info->filename,
2017 info->stack->flavor[0]);
2019 info->stack->visibility = DEBUG_VISIBILITY_PUBLIC;
2021 return indent_type (info);
2024 /* Output the visibility of a field in a struct. */
2026 static bfd_boolean
2027 tg_fix_visibility (struct pr_handle *info, enum debug_visibility visibility)
2029 assert (info->stack != NULL);
2031 if (info->stack->visibility == visibility)
2032 return TRUE;
2034 assert (info->stack->visibility != DEBUG_VISIBILITY_IGNORE);
2036 info->stack->visibility = visibility;
2038 return TRUE;
2041 /* Add a field to a struct type. */
2043 static bfd_boolean
2044 tg_struct_field (void *p, const char *name, bfd_vma bitpos ATTRIBUTE_UNUSED,
2045 bfd_vma bitsize ATTRIBUTE_UNUSED,
2046 enum debug_visibility visibility)
2048 struct pr_handle *info = (struct pr_handle *) p;
2049 char *t;
2051 t = pop_type (info);
2052 if (t == NULL)
2053 return FALSE;
2055 if (! tg_fix_visibility (info, visibility))
2056 return FALSE;
2058 /* It happens, a bug? */
2059 if (! name[0])
2060 return TRUE;
2062 fprintf (info->f, "%s\t%s\t0;\"\tkind:m\ttype:%s\t%s:%s\taccess:%s\n",
2063 name, info->filename, t, info->stack->flavor, info->stack->type,
2064 visibility_name (visibility));
2066 return TRUE;
2069 /* Finish a struct type. */
2071 static bfd_boolean
2072 tg_end_struct_type (void *p ATTRIBUTE_UNUSED)
2074 struct pr_handle *info = (struct pr_handle *) p;
2075 assert (info->stack != NULL);
2077 return TRUE;
2080 /* Start a class type. */
2082 static bfd_boolean
2083 tg_start_class_type (void *p, const char *tag, unsigned int id,
2084 bfd_boolean structp, unsigned int size,
2085 bfd_boolean vptr, bfd_boolean ownvptr)
2087 struct pr_handle *info = (struct pr_handle *) p;
2088 char *tv = NULL;
2089 const char *name;
2091 info->indent += 2;
2093 if (vptr && ! ownvptr)
2095 tv = pop_type (info);
2096 if (tv == NULL)
2097 return FALSE;
2100 if (tag != NULL)
2101 name = tag;
2102 else
2104 char idbuf[20];
2106 sprintf (idbuf, "%%anon%u", id);
2107 name = idbuf;
2110 if (! push_type (info, name))
2111 return FALSE;
2113 info->stack->flavor = structp ? "class" : "union class";
2114 info->stack->parents = NULL;
2115 info->stack->num_parents = 0;
2117 if (size != 0 || vptr || ownvptr || tag != NULL)
2119 if (vptr)
2121 if (! append_type (info, " vtable "))
2122 return FALSE;
2123 if (ownvptr)
2125 if (! append_type (info, "self "))
2126 return FALSE;
2128 else
2130 if (! append_type (info, tv)
2131 || ! append_type (info, " "))
2132 return FALSE;
2137 info->stack->visibility = DEBUG_VISIBILITY_PRIVATE;
2139 return TRUE;
2142 /* Add a static member to a class. */
2144 static bfd_boolean
2145 tg_class_static_member (void *p, const char *name,
2146 const char *physname ATTRIBUTE_UNUSED,
2147 enum debug_visibility visibility)
2149 struct pr_handle *info = (struct pr_handle *) p;
2150 char *t;
2151 int len_var, len_class;
2152 char *full_name;
2154 len_var = strlen (name);
2155 len_class = strlen (info->stack->next->type);
2156 full_name = (char *) xmalloc (len_var + len_class + 3);
2157 if (! full_name)
2158 return FALSE;
2159 memcpy (full_name, info->stack->next->type, len_class);
2160 memcpy (full_name + len_class, "::", 2);
2161 memcpy (full_name + len_class + 2, name, len_var + 1);
2163 if (! substitute_type (info, full_name))
2164 return FALSE;
2166 if (! prepend_type (info, "static "))
2167 return FALSE;
2169 t = pop_type (info);
2170 if (t == NULL)
2171 return FALSE;
2173 if (! tg_fix_visibility (info, visibility))
2174 return FALSE;
2176 fprintf (info->f, "%s\t%s\t0;\"\tkind:x\ttype:%s\tclass:%s\taccess:%s\n",
2177 name, info->filename, t, info->stack->type,
2178 visibility_name (visibility));
2179 free (t);
2180 free (full_name);
2182 return TRUE;
2185 /* Add a base class to a class. */
2187 static bfd_boolean
2188 tg_class_baseclass (void *p, bfd_vma bitpos ATTRIBUTE_UNUSED,
2189 bfd_boolean virtual, enum debug_visibility visibility)
2191 struct pr_handle *info = (struct pr_handle *) p;
2192 char *t;
2193 const char *prefix;
2195 assert (info->stack != NULL && info->stack->next != NULL);
2197 t = pop_type (info);
2198 if (t == NULL)
2199 return FALSE;
2201 if (strncmp (t, "class ", sizeof "class " - 1) == 0)
2202 t += sizeof "class " - 1;
2204 /* Push it back on to take advantage of the prepend_type and
2205 append_type routines. */
2206 if (! push_type (info, t))
2207 return FALSE;
2209 if (virtual)
2211 if (! prepend_type (info, "virtual "))
2212 return FALSE;
2215 switch (visibility)
2217 case DEBUG_VISIBILITY_PUBLIC:
2218 prefix = "public ";
2219 break;
2220 case DEBUG_VISIBILITY_PROTECTED:
2221 prefix = "protected ";
2222 break;
2223 case DEBUG_VISIBILITY_PRIVATE:
2224 prefix = "private ";
2225 break;
2226 default:
2227 prefix = "/* unknown visibility */ ";
2228 break;
2231 if (! prepend_type (info, prefix))
2232 return FALSE;
2234 t = pop_type (info);
2235 if (t == NULL)
2236 return FALSE;
2238 if (info->stack->num_parents && ! append_parent (info, ", "))
2239 return FALSE;
2241 if (! append_parent (info, t))
2242 return FALSE;
2243 info->stack->num_parents++;
2245 free (t);
2247 return TRUE;
2250 /* Add a variant to a method. */
2252 static bfd_boolean
2253 tg_class_method_variant (void *p, const char *physname ATTRIBUTE_UNUSED,
2254 enum debug_visibility visibility,
2255 bfd_boolean constp, bfd_boolean volatilep,
2256 bfd_vma voffset ATTRIBUTE_UNUSED,
2257 bfd_boolean context)
2259 struct pr_handle *info = (struct pr_handle *) p;
2260 char *method_type;
2261 char *context_type;
2262 char *method_name;
2264 assert (info->stack != NULL);
2265 assert (info->stack->next != NULL);
2267 /* Put the const and volatile qualifiers on the type. */
2268 if (volatilep)
2270 if (! append_type (info, " volatile"))
2271 return FALSE;
2273 if (constp)
2275 if (! append_type (info, " const"))
2276 return FALSE;
2279 method_name = strdup (context ? info->stack->next->next->method
2280 : info->stack->next->method);
2282 /* Stick the name of the method into its type. */
2283 if (! substitute_type (info, method_name))
2284 return FALSE;
2286 /* Get the type. */
2287 method_type = pop_type (info);
2288 if (method_type == NULL)
2289 return FALSE;
2291 /* Pull off the context type if there is one. */
2292 if (! context)
2293 context_type = NULL;
2294 else
2296 context_type = pop_type (info);
2297 if (context_type == NULL)
2298 return FALSE;
2301 /* Now the top of the stack is the class. */
2302 if (! tg_fix_visibility (info, visibility))
2303 return FALSE;
2305 fprintf (info->f, "%s\t%s\t0;\"\tkind:p\ttype:%s\tclass:%s\n",
2306 method_name, info->filename, method_type, info->stack->type);
2307 free (method_type);
2308 free (method_name);
2309 free (context_type);
2311 return TRUE;
2314 /* Add a static variant to a method. */
2316 static bfd_boolean
2317 tg_class_static_method_variant (void *p,
2318 const char *physname ATTRIBUTE_UNUSED,
2319 enum debug_visibility visibility,
2320 bfd_boolean constp, bfd_boolean volatilep)
2322 struct pr_handle *info = (struct pr_handle *) p;
2323 char *method_type;
2324 char *method_name;
2326 assert (info->stack != NULL);
2327 assert (info->stack->next != NULL);
2328 assert (info->stack->next->method != NULL);
2330 /* Put the const and volatile qualifiers on the type. */
2331 if (volatilep)
2333 if (! append_type (info, " volatile"))
2334 return FALSE;
2336 if (constp)
2338 if (! append_type (info, " const"))
2339 return FALSE;
2342 /* Mark it as static. */
2343 if (! prepend_type (info, "static "))
2344 return FALSE;
2346 method_name = strdup (info->stack->next->method);
2347 /* Stick the name of the method into its type. */
2348 if (! substitute_type (info, info->stack->next->method))
2349 return FALSE;
2351 /* Get the type. */
2352 method_type = pop_type (info);
2353 if (method_type == NULL)
2354 return FALSE;
2356 /* Now the top of the stack is the class. */
2357 if (! tg_fix_visibility (info, visibility))
2358 return FALSE;
2360 fprintf (info->f, "%s\t%s\t0;\"\tkind:p\ttype:%s\tclass:%s\taccess:%s\n",
2361 method_name, info->filename, method_type, info->stack->type,
2362 visibility_name (visibility));
2363 free (method_type);
2364 free (method_name);
2366 return TRUE;
2369 /* Finish up a class. */
2371 static bfd_boolean
2372 tg_end_class_type (void *p)
2374 struct pr_handle *info = (struct pr_handle *) p;
2376 fprintf (info->f, "%s\t%s\t0;\"\tkind:c\ttype:%s", info->stack->type,
2377 info->filename, info->stack->flavor);
2378 if (info->stack->num_parents)
2380 fprintf (info->f, "\tinherits:%s", info->stack->parents);
2381 free (info->stack->parents);
2383 fputc ('\n', info->f);
2385 return tg_end_struct_type (p);
2388 /* Push a type on the stack using a tag name. */
2390 static bfd_boolean
2391 tg_tag_type (void *p, const char *name, unsigned int id,
2392 enum debug_type_kind kind)
2394 struct pr_handle *info = (struct pr_handle *) p;
2395 const char *t, *tag;
2396 char idbuf[20];
2398 switch (kind)
2400 case DEBUG_KIND_STRUCT:
2401 t = "struct ";
2402 break;
2403 case DEBUG_KIND_UNION:
2404 t = "union ";
2405 break;
2406 case DEBUG_KIND_ENUM:
2407 t = "enum ";
2408 break;
2409 case DEBUG_KIND_CLASS:
2410 t = "class ";
2411 break;
2412 case DEBUG_KIND_UNION_CLASS:
2413 t = "union class ";
2414 break;
2415 default:
2416 abort ();
2417 return FALSE;
2420 if (! push_type (info, t))
2421 return FALSE;
2422 if (name != NULL)
2423 tag = name;
2424 else
2426 sprintf (idbuf, "%%anon%u", id);
2427 tag = idbuf;
2430 if (! append_type (info, tag))
2431 return FALSE;
2433 return TRUE;
2436 /* Output a typedef. */
2438 static bfd_boolean
2439 tg_typdef (void *p, const char *name)
2441 struct pr_handle *info = (struct pr_handle *) p;
2442 char *s;
2444 s = pop_type (info);
2445 if (s == NULL)
2446 return FALSE;
2448 fprintf (info->f, "%s\t%s\t0;\"\tkind:t\ttype:%s\n", name,
2449 info->filename, s);
2451 free (s);
2453 return TRUE;
2456 /* Output a tag. The tag should already be in the string on the
2457 stack, so all we have to do here is print it out. */
2459 static bfd_boolean
2460 tg_tag (void *p ATTRIBUTE_UNUSED, const char *name ATTRIBUTE_UNUSED)
2462 struct pr_handle *info = (struct pr_handle *) p;
2463 char *t;
2465 t = pop_type (info);
2466 if (t == NULL)
2467 return FALSE;
2468 free (t);
2470 return TRUE;
2473 /* Output an integer constant. */
2475 static bfd_boolean
2476 tg_int_constant (void *p, const char *name, bfd_vma val)
2478 struct pr_handle *info = (struct pr_handle *) p;
2479 char ab[20];
2481 indent (info);
2482 print_vma (val, ab, FALSE, FALSE);
2483 fprintf (info->f, "%s\t%s\t0;\"\tkind:v\ttype:const int\tvalue:%s\n",
2484 name, info->filename, ab);
2485 return TRUE;
2488 /* Output a floating point constant. */
2490 static bfd_boolean
2491 tg_float_constant (void *p, const char *name, double val)
2493 struct pr_handle *info = (struct pr_handle *) p;
2495 indent (info);
2496 fprintf (info->f, "%s\t%s\t0;\"\tkind:v\ttype:const double\tvalue:%g\n",
2497 name, info->filename, val);
2498 return TRUE;
2501 /* Output a typed constant. */
2503 static bfd_boolean
2504 tg_typed_constant (void *p, const char *name, bfd_vma val)
2506 struct pr_handle *info = (struct pr_handle *) p;
2507 char *t;
2508 char ab[20];
2510 t = pop_type (info);
2511 if (t == NULL)
2512 return FALSE;
2514 indent (info);
2515 print_vma (val, ab, FALSE, FALSE);
2516 fprintf (info->f, "%s\t%s\t0;\"\tkind:v\ttype:const %s\tvalue:%s\n",
2517 name, info->filename, t, ab);
2519 free (t);
2521 return TRUE;
2524 /* Output a variable. */
2526 static bfd_boolean
2527 tg_variable (void *p, const char *name, enum debug_var_kind kind,
2528 bfd_vma val ATTRIBUTE_UNUSED)
2530 struct pr_handle *info = (struct pr_handle *) p;
2531 char *t;
2532 const char *dname, *from_class;
2534 t = pop_type (info);
2535 if (t == NULL)
2536 return FALSE;
2538 dname = name;
2539 if (info->demangler)
2541 dname = info->demangler (info->abfd, name);
2542 if (strcmp (name, dname) == 0)
2544 free ((char *) dname);
2545 dname = name;
2549 if (dname != name)
2551 char *sep;
2552 sep = strstr (dname, "::");
2553 if (sep)
2555 *sep = 0;
2556 name = sep + 2;
2557 from_class = dname;
2559 else
2561 /* Obscure types as vts and type_info nodes. */
2562 name = dname;
2563 from_class = NULL;
2566 else
2567 from_class = NULL;
2569 fprintf (info->f, "%s\t%s\t0;\"\tkind:v\ttype:%s", name, info->filename, t);
2571 switch (kind)
2573 case DEBUG_STATIC:
2574 case DEBUG_LOCAL_STATIC:
2575 fprintf (info->f, "\tfile:");
2576 break;
2577 case DEBUG_REGISTER:
2578 fprintf (info->f, "\tregister:");
2579 break;
2580 default:
2581 break;
2584 if (from_class)
2586 fprintf (info->f, "\tclass:%s",from_class);
2587 free ((char *) dname);
2590 fprintf (info->f, "\n");
2592 free (t);
2594 return TRUE;
2597 /* Start outputting a function. */
2599 static bfd_boolean
2600 tg_start_function (void *p, const char *name, bfd_boolean global)
2602 struct pr_handle *info = (struct pr_handle *) p;
2603 const char *dname;
2605 if (! global)
2606 info->stack->flavor = "static";
2607 else
2608 info->stack->flavor = NULL;
2610 dname = name;
2611 if (info->demangler)
2613 dname = info->demangler (info->abfd, name);
2614 if (strcmp (name, dname) == 0)
2616 free ((char *) dname);
2617 dname = name;
2621 if (! substitute_type (info, dname))
2622 return FALSE;
2624 if (dname != name)
2626 char *sep;
2627 sep = strstr (dname, "::");
2628 if (sep)
2630 info->stack->method = dname;
2631 *sep = 0;
2632 name = sep + 2;
2634 else
2636 info->stack->method = "";
2637 name = dname;
2639 sep = strchr (name, '(');
2640 if (sep)
2641 *sep = 0;
2642 /* Obscure functions as type_info function. */
2644 else
2645 info->stack->method = NULL;
2647 info->stack->parents = strdup (name);
2649 if (! info->stack->method && ! append_type (info, "("))
2650 return FALSE;
2652 info->parameter = 1;
2654 return TRUE;
2657 /* Output a function parameter. */
2659 static bfd_boolean
2660 tg_function_parameter (void *p, const char *name, enum debug_parm_kind kind,
2661 bfd_vma val ATTRIBUTE_UNUSED)
2663 struct pr_handle *info = (struct pr_handle *) p;
2664 char *t;
2666 if (kind == DEBUG_PARM_REFERENCE
2667 || kind == DEBUG_PARM_REF_REG)
2669 if (! pr_reference_type (p))
2670 return FALSE;
2673 if (! substitute_type (info, name))
2674 return FALSE;
2676 t = pop_type (info);
2677 if (t == NULL)
2678 return FALSE;
2680 if (! info->stack->method)
2682 if (info->parameter != 1 && ! append_type (info, ", "))
2683 return FALSE;
2685 if (kind == DEBUG_PARM_REG || kind == DEBUG_PARM_REF_REG)
2686 if (! append_type (info, "register "))
2687 return FALSE;
2689 if (! append_type (info, t))
2690 return FALSE;
2693 free (t);
2695 ++info->parameter;
2697 return TRUE;
2700 /* Start writing out a block. */
2702 static bfd_boolean
2703 tg_start_block (void *p, bfd_vma addr)
2705 struct pr_handle *info = (struct pr_handle *) p;
2706 char ab[20], kind, *partof;
2707 char *t;
2708 bfd_boolean local;
2710 if (info->parameter > 0)
2712 info->parameter = 0;
2714 /* Delayed name. */
2715 fprintf (info->f, "%s\t%s\t", info->stack->parents, info->filename);
2716 free (info->stack->parents);
2718 print_vma (addr, ab, TRUE, TRUE);
2719 translate_addresses (info->abfd, ab, info->f, info->syms);
2720 local = info->stack->flavor != NULL;
2721 if (info->stack->method && *info->stack->method)
2723 kind = 'm';
2724 partof = (char *) info->stack->method;
2726 else
2728 kind = 'f';
2729 partof = NULL;
2730 if (! info->stack->method && ! append_type (info, ")"))
2731 return FALSE;
2733 t = pop_type (info);
2734 if (t == NULL)
2735 return FALSE;
2736 fprintf (info->f, ";\"\tkind:%c\ttype:%s", kind, t);
2737 if (local)
2738 fputs ("\tfile:", info->f);
2739 if (partof)
2741 fprintf (info->f, "\tclass:%s", partof);
2742 free (partof);
2744 fputc ('\n', info->f);
2747 return TRUE;
2750 /* Write out line number information. */
2752 static bfd_boolean
2753 tg_lineno (void *p ATTRIBUTE_UNUSED, const char *filename ATTRIBUTE_UNUSED,
2754 unsigned long lineno ATTRIBUTE_UNUSED,
2755 bfd_vma addr ATTRIBUTE_UNUSED)
2757 return TRUE;
2760 /* Finish writing out a block. */
2762 static bfd_boolean
2763 tg_end_block (void *p ATTRIBUTE_UNUSED, bfd_vma addr ATTRIBUTE_UNUSED)
2765 return TRUE;
2768 /* Convert the visibility value into a human readable name. */
2770 static const char *
2771 visibility_name (enum debug_visibility visibility)
2773 const char *s;
2775 switch (visibility)
2777 case DEBUG_VISIBILITY_PUBLIC:
2778 s = "public";
2779 break;
2780 case DEBUG_VISIBILITY_PRIVATE:
2781 s = "private";
2782 break;
2783 case DEBUG_VISIBILITY_PROTECTED:
2784 s = "protected";
2785 break;
2786 case DEBUG_VISIBILITY_IGNORE:
2787 s = "/* ignore */";
2788 break;
2789 default:
2790 abort ();
2791 return FALSE;
2793 return s;