* readelf.c (byte_get_signed): New.
[deliverable/binutils-gdb.git] / binutils / prdbg.c
1 /* prdbg.c -- Print out generic debugging information.
2 Copyright 1995, 1996, 2002 Free Software Foundation, Inc.
3 Written by Ian Lance Taylor <ian@cygnus.com>.
4
5 This file is part of GNU Binutils.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA. */
21
22 /* This file prints out the generic debugging information, by
23 supplying a set of routines to debug_write. */
24
25 #include <stdio.h>
26 #include <assert.h>
27
28 #include "bfd.h"
29 #include "bucomm.h"
30 #include "libiberty.h"
31 #include "debug.h"
32 #include "budbg.h"
33
34 /* This is the structure we use as a handle for these routines. */
35
36 struct pr_handle
37 {
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 };
47
48 /* The type stack. */
49
50 struct pr_stack
51 {
52 /* Next element on the stack. */
53 struct pr_stack *next;
54 /* This element. */
55 char *type;
56 /* Current visibility of fields if this is a class. */
57 enum debug_visibility visibility;
58 /* Name of the current method we are handling. */
59 const char *method;
60 };
61
62 static void indent
63 PARAMS ((struct pr_handle *));
64 static bfd_boolean push_type
65 PARAMS ((struct pr_handle *, const char *));
66 static bfd_boolean prepend_type
67 PARAMS ((struct pr_handle *, const char *));
68 static bfd_boolean append_type
69 PARAMS ((struct pr_handle *, const char *));
70 static bfd_boolean substitute_type
71 PARAMS ((struct pr_handle *, const char *));
72 static bfd_boolean indent_type
73 PARAMS ((struct pr_handle *));
74 static char *pop_type
75 PARAMS ((struct pr_handle *));
76 static void print_vma
77 PARAMS ((bfd_vma, char *, bfd_boolean, bfd_boolean));
78 static bfd_boolean pr_fix_visibility
79 PARAMS ((struct pr_handle *, enum debug_visibility));
80 static bfd_boolean pr_start_compilation_unit
81 PARAMS ((PTR, const char *));
82 static bfd_boolean pr_start_source
83 PARAMS ((PTR, const char *));
84 static bfd_boolean pr_empty_type
85 PARAMS ((PTR));
86 static bfd_boolean pr_void_type
87 PARAMS ((PTR));
88 static bfd_boolean pr_int_type
89 PARAMS ((PTR, unsigned int, bfd_boolean));
90 static bfd_boolean pr_float_type
91 PARAMS ((PTR, unsigned int));
92 static bfd_boolean pr_complex_type
93 PARAMS ((PTR, unsigned int));
94 static bfd_boolean pr_bool_type
95 PARAMS ((PTR, unsigned int));
96 static bfd_boolean pr_enum_type
97 PARAMS ((PTR, const char *, const char **, bfd_signed_vma *));
98 static bfd_boolean pr_pointer_type
99 PARAMS ((PTR));
100 static bfd_boolean pr_function_type
101 PARAMS ((PTR, int, bfd_boolean));
102 static bfd_boolean pr_reference_type
103 PARAMS ((PTR));
104 static bfd_boolean pr_range_type
105 PARAMS ((PTR, bfd_signed_vma, bfd_signed_vma));
106 static bfd_boolean pr_array_type
107 PARAMS ((PTR, bfd_signed_vma, bfd_signed_vma, bfd_boolean));
108 static bfd_boolean pr_set_type
109 PARAMS ((PTR, bfd_boolean));
110 static bfd_boolean pr_offset_type
111 PARAMS ((PTR));
112 static bfd_boolean pr_method_type
113 PARAMS ((PTR, bfd_boolean, int, bfd_boolean));
114 static bfd_boolean pr_const_type
115 PARAMS ((PTR));
116 static bfd_boolean pr_volatile_type
117 PARAMS ((PTR));
118 static bfd_boolean pr_start_struct_type
119 PARAMS ((PTR, const char *, unsigned int, bfd_boolean, unsigned int));
120 static bfd_boolean pr_struct_field
121 PARAMS ((PTR, const char *, bfd_vma, bfd_vma, enum debug_visibility));
122 static bfd_boolean pr_end_struct_type
123 PARAMS ((PTR));
124 static bfd_boolean pr_start_class_type
125 PARAMS ((PTR, const char *, unsigned int, bfd_boolean, unsigned int,
126 bfd_boolean, bfd_boolean));
127 static bfd_boolean pr_class_static_member
128 PARAMS ((PTR, const char *, const char *, enum debug_visibility));
129 static bfd_boolean pr_class_baseclass
130 PARAMS ((PTR, bfd_vma, bfd_boolean, enum debug_visibility));
131 static bfd_boolean pr_class_start_method
132 PARAMS ((PTR, const char *));
133 static bfd_boolean pr_class_method_variant
134 PARAMS ((PTR, const char *, enum debug_visibility, bfd_boolean, bfd_boolean,
135 bfd_vma, bfd_boolean));
136 static bfd_boolean pr_class_static_method_variant
137 PARAMS ((PTR, const char *, enum debug_visibility, bfd_boolean,
138 bfd_boolean));
139 static bfd_boolean pr_class_end_method
140 PARAMS ((PTR));
141 static bfd_boolean pr_end_class_type
142 PARAMS ((PTR));
143 static bfd_boolean pr_typedef_type
144 PARAMS ((PTR, const char *));
145 static bfd_boolean pr_tag_type
146 PARAMS ((PTR, const char *, unsigned int, enum debug_type_kind));
147 static bfd_boolean pr_typdef
148 PARAMS ((PTR, const char *));
149 static bfd_boolean pr_tag
150 PARAMS ((PTR, const char *));
151 static bfd_boolean pr_int_constant
152 PARAMS ((PTR, const char *, bfd_vma));
153 static bfd_boolean pr_float_constant
154 PARAMS ((PTR, const char *, double));
155 static bfd_boolean pr_typed_constant
156 PARAMS ((PTR, const char *, bfd_vma));
157 static bfd_boolean pr_variable
158 PARAMS ((PTR, const char *, enum debug_var_kind, bfd_vma));
159 static bfd_boolean pr_start_function
160 PARAMS ((PTR, const char *, bfd_boolean));
161 static bfd_boolean pr_function_parameter
162 PARAMS ((PTR, const char *, enum debug_parm_kind, bfd_vma));
163 static bfd_boolean pr_start_block
164 PARAMS ((PTR, bfd_vma));
165 static bfd_boolean pr_end_block
166 PARAMS ((PTR, bfd_vma));
167 static bfd_boolean pr_end_function
168 PARAMS ((PTR));
169 static bfd_boolean pr_lineno
170 PARAMS ((PTR, const char *, unsigned long, bfd_vma));
171
172 static const struct debug_write_fns pr_fns =
173 {
174 pr_start_compilation_unit,
175 pr_start_source,
176 pr_empty_type,
177 pr_void_type,
178 pr_int_type,
179 pr_float_type,
180 pr_complex_type,
181 pr_bool_type,
182 pr_enum_type,
183 pr_pointer_type,
184 pr_function_type,
185 pr_reference_type,
186 pr_range_type,
187 pr_array_type,
188 pr_set_type,
189 pr_offset_type,
190 pr_method_type,
191 pr_const_type,
192 pr_volatile_type,
193 pr_start_struct_type,
194 pr_struct_field,
195 pr_end_struct_type,
196 pr_start_class_type,
197 pr_class_static_member,
198 pr_class_baseclass,
199 pr_class_start_method,
200 pr_class_method_variant,
201 pr_class_static_method_variant,
202 pr_class_end_method,
203 pr_end_class_type,
204 pr_typedef_type,
205 pr_tag_type,
206 pr_typdef,
207 pr_tag,
208 pr_int_constant,
209 pr_float_constant,
210 pr_typed_constant,
211 pr_variable,
212 pr_start_function,
213 pr_function_parameter,
214 pr_start_block,
215 pr_end_block,
216 pr_end_function,
217 pr_lineno
218 };
219 \f
220 /* Print out the generic debugging information recorded in dhandle. */
221
222 bfd_boolean
223 print_debugging_info (f, dhandle)
224 FILE *f;
225 PTR dhandle;
226 {
227 struct pr_handle info;
228
229 info.f = f;
230 info.indent = 0;
231 info.stack = NULL;
232 info.parameter = 0;
233
234 return debug_write (dhandle, &pr_fns, (PTR) &info);
235 }
236 \f
237 /* Indent to the current indentation level. */
238
239 static void
240 indent (info)
241 struct pr_handle *info;
242 {
243 unsigned int i;
244
245 for (i = 0; i < info->indent; i++)
246 putc (' ', info->f);
247 }
248
249 /* Push a type on the type stack. */
250
251 static bfd_boolean
252 push_type (info, type)
253 struct pr_handle *info;
254 const char *type;
255 {
256 struct pr_stack *n;
257
258 if (type == NULL)
259 return FALSE;
260
261 n = (struct pr_stack *) xmalloc (sizeof *n);
262 memset (n, 0, sizeof *n);
263
264 n->type = xstrdup (type);
265 n->visibility = DEBUG_VISIBILITY_IGNORE;
266 n->method = NULL;
267 n->next = info->stack;
268 info->stack = n;
269
270 return TRUE;
271 }
272
273 /* Prepend a string onto the type on the top of the type stack. */
274
275 static bfd_boolean
276 prepend_type (info, s)
277 struct pr_handle *info;
278 const char *s;
279 {
280 char *n;
281
282 assert (info->stack != NULL);
283
284 n = (char *) xmalloc (strlen (s) + strlen (info->stack->type) + 1);
285 sprintf (n, "%s%s", s, info->stack->type);
286 free (info->stack->type);
287 info->stack->type = n;
288
289 return TRUE;
290 }
291
292 /* Append a string to the type on the top of the type stack. */
293
294 static bfd_boolean
295 append_type (info, s)
296 struct pr_handle *info;
297 const char *s;
298 {
299 unsigned int len;
300
301 if (s == NULL)
302 return FALSE;
303
304 assert (info->stack != NULL);
305
306 len = strlen (info->stack->type);
307 info->stack->type = (char *) xrealloc (info->stack->type,
308 len + strlen (s) + 1);
309 strcpy (info->stack->type + len, s);
310
311 return TRUE;
312 }
313
314 /* We use an underscore to indicate where the name should go in a type
315 string. This function substitutes a string for the underscore. If
316 there is no underscore, the name follows the type. */
317
318 static bfd_boolean
319 substitute_type (info, s)
320 struct pr_handle *info;
321 const char *s;
322 {
323 char *u;
324
325 assert (info->stack != NULL);
326
327 u = strchr (info->stack->type, '|');
328 if (u != NULL)
329 {
330 char *n;
331
332 n = (char *) xmalloc (strlen (info->stack->type) + strlen (s));
333
334 memcpy (n, info->stack->type, u - info->stack->type);
335 strcpy (n + (u - info->stack->type), s);
336 strcat (n, u + 1);
337
338 free (info->stack->type);
339 info->stack->type = n;
340
341 return TRUE;
342 }
343
344 if (strchr (s, '|') != NULL
345 && (strchr (info->stack->type, '{') != NULL
346 || strchr (info->stack->type, '(') != NULL))
347 {
348 if (! prepend_type (info, "(")
349 || ! append_type (info, ")"))
350 return FALSE;
351 }
352
353 if (*s == '\0')
354 return TRUE;
355
356 return (append_type (info, " ")
357 && append_type (info, s));
358 }
359
360 /* Indent the type at the top of the stack by appending spaces. */
361
362 static bfd_boolean
363 indent_type (info)
364 struct pr_handle *info;
365 {
366 unsigned int i;
367
368 for (i = 0; i < info->indent; i++)
369 {
370 if (! append_type (info, " "))
371 return FALSE;
372 }
373
374 return TRUE;
375 }
376
377 /* Pop a type from the type stack. */
378
379 static char *
380 pop_type (info)
381 struct pr_handle *info;
382 {
383 struct pr_stack *o;
384 char *ret;
385
386 assert (info->stack != NULL);
387
388 o = info->stack;
389 info->stack = o->next;
390 ret = o->type;
391 free (o);
392
393 return ret;
394 }
395
396 /* Print a VMA value into a string. */
397
398 static void
399 print_vma (vma, buf, unsignedp, hexp)
400 bfd_vma vma;
401 char *buf;
402 bfd_boolean unsignedp;
403 bfd_boolean hexp;
404 {
405 if (sizeof (vma) <= sizeof (unsigned long))
406 {
407 if (hexp)
408 sprintf (buf, "0x%lx", (unsigned long) vma);
409 else if (unsignedp)
410 sprintf (buf, "%lu", (unsigned long) vma);
411 else
412 sprintf (buf, "%ld", (long) vma);
413 }
414 else
415 {
416 buf[0] = '0';
417 buf[1] = 'x';
418 sprintf_vma (buf + 2, vma);
419 }
420 }
421 \f
422 /* Start a new compilation unit. */
423
424 static bfd_boolean
425 pr_start_compilation_unit (p, filename)
426 PTR p;
427 const char *filename;
428 {
429 struct pr_handle *info = (struct pr_handle *) p;
430
431 assert (info->indent == 0);
432
433 fprintf (info->f, "%s:\n", filename);
434
435 return TRUE;
436 }
437
438 /* Start a source file within a compilation unit. */
439
440 static bfd_boolean
441 pr_start_source (p, filename)
442 PTR p;
443 const char *filename;
444 {
445 struct pr_handle *info = (struct pr_handle *) p;
446
447 assert (info->indent == 0);
448
449 fprintf (info->f, " %s:\n", filename);
450
451 return TRUE;
452 }
453
454 /* Push an empty type onto the type stack. */
455
456 static bfd_boolean
457 pr_empty_type (p)
458 PTR p;
459 {
460 struct pr_handle *info = (struct pr_handle *) p;
461
462 return push_type (info, "<undefined>");
463 }
464
465 /* Push a void type onto the type stack. */
466
467 static bfd_boolean
468 pr_void_type (p)
469 PTR p;
470 {
471 struct pr_handle *info = (struct pr_handle *) p;
472
473 return push_type (info, "void");
474 }
475
476 /* Push an integer type onto the type stack. */
477
478 static bfd_boolean
479 pr_int_type (p, size, unsignedp)
480 PTR p;
481 unsigned int size;
482 bfd_boolean unsignedp;
483 {
484 struct pr_handle *info = (struct pr_handle *) p;
485 char ab[10];
486
487 sprintf (ab, "%sint%d", unsignedp ? "u" : "", size * 8);
488 return push_type (info, ab);
489 }
490
491 /* Push a floating type onto the type stack. */
492
493 static bfd_boolean
494 pr_float_type (p, size)
495 PTR p;
496 unsigned int size;
497 {
498 struct pr_handle *info = (struct pr_handle *) p;
499 char ab[10];
500
501 if (size == 4)
502 return push_type (info, "float");
503 else if (size == 8)
504 return push_type (info, "double");
505
506 sprintf (ab, "float%d", size * 8);
507 return push_type (info, ab);
508 }
509
510 /* Push a complex type onto the type stack. */
511
512 static bfd_boolean
513 pr_complex_type (p, size)
514 PTR p;
515 unsigned int size;
516 {
517 struct pr_handle *info = (struct pr_handle *) p;
518
519 if (! pr_float_type (p, size))
520 return FALSE;
521
522 return prepend_type (info, "complex ");
523 }
524
525 /* Push a bfd_boolean type onto the type stack. */
526
527 static bfd_boolean
528 pr_bool_type (p, size)
529 PTR p;
530 unsigned int size;
531 {
532 struct pr_handle *info = (struct pr_handle *) p;
533 char ab[10];
534
535 sprintf (ab, "bool%d", size * 8);
536
537 return push_type (info, ab);
538 }
539
540 /* Push an enum type onto the type stack. */
541
542 static bfd_boolean
543 pr_enum_type (p, tag, names, values)
544 PTR p;
545 const char *tag;
546 const char **names;
547 bfd_signed_vma *values;
548 {
549 struct pr_handle *info = (struct pr_handle *) p;
550 unsigned int i;
551 bfd_signed_vma val;
552
553 if (! push_type (info, "enum "))
554 return FALSE;
555 if (tag != NULL)
556 {
557 if (! append_type (info, tag)
558 || ! append_type (info, " "))
559 return FALSE;
560 }
561 if (! append_type (info, "{ "))
562 return FALSE;
563
564 if (names == NULL)
565 {
566 if (! append_type (info, "/* undefined */"))
567 return FALSE;
568 }
569 else
570 {
571 val = 0;
572 for (i = 0; names[i] != NULL; i++)
573 {
574 if (i > 0)
575 {
576 if (! append_type (info, ", "))
577 return FALSE;
578 }
579
580 if (! append_type (info, names[i]))
581 return FALSE;
582
583 if (values[i] != val)
584 {
585 char ab[20];
586
587 print_vma (values[i], ab, FALSE, FALSE);
588 if (! append_type (info, " = ")
589 || ! append_type (info, ab))
590 return FALSE;
591 val = values[i];
592 }
593
594 ++val;
595 }
596 }
597
598 return append_type (info, " }");
599 }
600
601 /* Turn the top type on the stack into a pointer. */
602
603 static bfd_boolean
604 pr_pointer_type (p)
605 PTR p;
606 {
607 struct pr_handle *info = (struct pr_handle *) p;
608 char *s;
609
610 assert (info->stack != NULL);
611
612 s = strchr (info->stack->type, '|');
613 if (s != NULL && s[1] == '[')
614 return substitute_type (info, "(*|)");
615 return substitute_type (info, "*|");
616 }
617
618 /* Turn the top type on the stack into a function returning that type. */
619
620 static bfd_boolean
621 pr_function_type (p, argcount, varargs)
622 PTR p;
623 int argcount;
624 bfd_boolean varargs;
625 {
626 struct pr_handle *info = (struct pr_handle *) p;
627 char **arg_types;
628 unsigned int len;
629 char *s;
630
631 assert (info->stack != NULL);
632
633 len = 10;
634
635 if (argcount <= 0)
636 {
637 arg_types = NULL;
638 len += 15;
639 }
640 else
641 {
642 int i;
643
644 arg_types = (char **) xmalloc (argcount * sizeof *arg_types);
645 for (i = argcount - 1; i >= 0; i--)
646 {
647 if (! substitute_type (info, ""))
648 return FALSE;
649 arg_types[i] = pop_type (info);
650 if (arg_types[i] == NULL)
651 return FALSE;
652 len += strlen (arg_types[i]) + 2;
653 }
654 if (varargs)
655 len += 5;
656 }
657
658 /* Now the return type is on the top of the stack. */
659
660 s = (char *) xmalloc (len);
661 strcpy (s, "(|) (");
662
663 if (argcount < 0)
664 strcat (s, "/* unknown */");
665 else
666 {
667 int i;
668
669 for (i = 0; i < argcount; i++)
670 {
671 if (i > 0)
672 strcat (s, ", ");
673 strcat (s, arg_types[i]);
674 }
675 if (varargs)
676 {
677 if (i > 0)
678 strcat (s, ", ");
679 strcat (s, "...");
680 }
681 if (argcount > 0)
682 free (arg_types);
683 }
684
685 strcat (s, ")");
686
687 if (! substitute_type (info, s))
688 return FALSE;
689
690 free (s);
691
692 return TRUE;
693 }
694
695 /* Turn the top type on the stack into a reference to that type. */
696
697 static bfd_boolean
698 pr_reference_type (p)
699 PTR p;
700 {
701 struct pr_handle *info = (struct pr_handle *) p;
702
703 assert (info->stack != NULL);
704
705 return substitute_type (info, "&|");
706 }
707
708 /* Make a range type. */
709
710 static bfd_boolean
711 pr_range_type (p, lower, upper)
712 PTR p;
713 bfd_signed_vma lower;
714 bfd_signed_vma upper;
715 {
716 struct pr_handle *info = (struct pr_handle *) p;
717 char abl[20], abu[20];
718
719 assert (info->stack != NULL);
720
721 if (! substitute_type (info, ""))
722 return FALSE;
723
724 print_vma (lower, abl, FALSE, FALSE);
725 print_vma (upper, abu, FALSE, FALSE);
726
727 return (prepend_type (info, "range (")
728 && append_type (info, "):")
729 && append_type (info, abl)
730 && append_type (info, ":")
731 && append_type (info, abu));
732 }
733
734 /* Make an array type. */
735
736 static bfd_boolean
737 pr_array_type (p, lower, upper, stringp)
738 PTR p;
739 bfd_signed_vma lower;
740 bfd_signed_vma upper;
741 bfd_boolean stringp;
742 {
743 struct pr_handle *info = (struct pr_handle *) p;
744 char *range_type;
745 char abl[20], abu[20], ab[50];
746
747 range_type = pop_type (info);
748 if (range_type == NULL)
749 return FALSE;
750
751 if (lower == 0)
752 {
753 if (upper == -1)
754 sprintf (ab, "|[]");
755 else
756 {
757 print_vma (upper + 1, abu, FALSE, FALSE);
758 sprintf (ab, "|[%s]", abu);
759 }
760 }
761 else
762 {
763 print_vma (lower, abl, FALSE, FALSE);
764 print_vma (upper, abu, FALSE, FALSE);
765 sprintf (ab, "|[%s:%s]", abl, abu);
766 }
767
768 if (! substitute_type (info, ab))
769 return FALSE;
770
771 if (strcmp (range_type, "int") != 0)
772 {
773 if (! append_type (info, ":")
774 || ! append_type (info, range_type))
775 return FALSE;
776 }
777
778 if (stringp)
779 {
780 if (! append_type (info, " /* string */"))
781 return FALSE;
782 }
783
784 return TRUE;
785 }
786
787 /* Make a set type. */
788
789 static bfd_boolean
790 pr_set_type (p, bitstringp)
791 PTR p;
792 bfd_boolean bitstringp;
793 {
794 struct pr_handle *info = (struct pr_handle *) p;
795
796 if (! substitute_type (info, ""))
797 return FALSE;
798
799 if (! prepend_type (info, "set { ")
800 || ! append_type (info, " }"))
801 return FALSE;
802
803 if (bitstringp)
804 {
805 if (! append_type (info, "/* bitstring */"))
806 return FALSE;
807 }
808
809 return TRUE;
810 }
811
812 /* Make an offset type. */
813
814 static bfd_boolean
815 pr_offset_type (p)
816 PTR p;
817 {
818 struct pr_handle *info = (struct pr_handle *) p;
819 char *t;
820
821 if (! substitute_type (info, ""))
822 return FALSE;
823
824 t = pop_type (info);
825 if (t == NULL)
826 return FALSE;
827
828 return (substitute_type (info, "")
829 && prepend_type (info, " ")
830 && prepend_type (info, t)
831 && append_type (info, "::|"));
832 }
833
834 /* Make a method type. */
835
836 static bfd_boolean
837 pr_method_type (p, domain, argcount, varargs)
838 PTR p;
839 bfd_boolean domain;
840 int argcount;
841 bfd_boolean varargs;
842 {
843 struct pr_handle *info = (struct pr_handle *) p;
844 unsigned int len;
845 char *domain_type;
846 char **arg_types;
847 char *s;
848
849 len = 10;
850
851 if (! domain)
852 domain_type = NULL;
853 else
854 {
855 if (! substitute_type (info, ""))
856 return FALSE;
857 domain_type = pop_type (info);
858 if (domain_type == NULL)
859 return FALSE;
860 if (strncmp (domain_type, "class ", sizeof "class " - 1) == 0
861 && strchr (domain_type + sizeof "class " - 1, ' ') == NULL)
862 domain_type += sizeof "class " - 1;
863 else if (strncmp (domain_type, "union class ",
864 sizeof "union class ") == 0
865 && (strchr (domain_type + sizeof "union class " - 1, ' ')
866 == NULL))
867 domain_type += sizeof "union class " - 1;
868 len += strlen (domain_type);
869 }
870
871 if (argcount <= 0)
872 {
873 arg_types = NULL;
874 len += 15;
875 }
876 else
877 {
878 int i;
879
880 arg_types = (char **) xmalloc (argcount * sizeof *arg_types);
881 for (i = argcount - 1; i >= 0; i--)
882 {
883 if (! substitute_type (info, ""))
884 return FALSE;
885 arg_types[i] = pop_type (info);
886 if (arg_types[i] == NULL)
887 return FALSE;
888 len += strlen (arg_types[i]) + 2;
889 }
890 if (varargs)
891 len += 5;
892 }
893
894 /* Now the return type is on the top of the stack. */
895
896 s = (char *) xmalloc (len);
897 if (! domain)
898 *s = '\0';
899 else
900 strcpy (s, domain_type);
901 strcat (s, "::| (");
902
903 if (argcount < 0)
904 strcat (s, "/* unknown */");
905 else
906 {
907 int i;
908
909 for (i = 0; i < argcount; i++)
910 {
911 if (i > 0)
912 strcat (s, ", ");
913 strcat (s, arg_types[i]);
914 }
915 if (varargs)
916 {
917 if (i > 0)
918 strcat (s, ", ");
919 strcat (s, "...");
920 }
921 if (argcount > 0)
922 free (arg_types);
923 }
924
925 strcat (s, ")");
926
927 if (! substitute_type (info, s))
928 return FALSE;
929
930 free (s);
931
932 return TRUE;
933 }
934
935 /* Make a const qualified type. */
936
937 static bfd_boolean
938 pr_const_type (p)
939 PTR p;
940 {
941 struct pr_handle *info = (struct pr_handle *) p;
942
943 return substitute_type (info, "const |");
944 }
945
946 /* Make a volatile qualified type. */
947
948 static bfd_boolean
949 pr_volatile_type (p)
950 PTR p;
951 {
952 struct pr_handle *info = (struct pr_handle *) p;
953
954 return substitute_type (info, "volatile |");
955 }
956
957 /* Start accumulating a struct type. */
958
959 static bfd_boolean
960 pr_start_struct_type (p, tag, id, structp, size)
961 PTR p;
962 const char *tag;
963 unsigned int id;
964 bfd_boolean structp;
965 unsigned int size;
966 {
967 struct pr_handle *info = (struct pr_handle *) p;
968
969 info->indent += 2;
970
971 if (! push_type (info, structp ? "struct " : "union "))
972 return FALSE;
973 if (tag != NULL)
974 {
975 if (! append_type (info, tag))
976 return FALSE;
977 }
978 else
979 {
980 char idbuf[20];
981
982 sprintf (idbuf, "%%anon%u", id);
983 if (! append_type (info, idbuf))
984 return FALSE;
985 }
986
987 if (! append_type (info, " {"))
988 return FALSE;
989 if (size != 0 || tag != NULL)
990 {
991 char ab[30];
992
993 if (! append_type (info, " /*"))
994 return FALSE;
995
996 if (size != 0)
997 {
998 sprintf (ab, " size %u", size);
999 if (! append_type (info, ab))
1000 return FALSE;
1001 }
1002 if (tag != NULL)
1003 {
1004 sprintf (ab, " id %u", id);
1005 if (! append_type (info, ab))
1006 return FALSE;
1007 }
1008 if (! append_type (info, " */"))
1009 return FALSE;
1010 }
1011 if (! append_type (info, "\n"))
1012 return FALSE;
1013
1014 info->stack->visibility = DEBUG_VISIBILITY_PUBLIC;
1015
1016 return indent_type (info);
1017 }
1018
1019 /* Output the visibility of a field in a struct. */
1020
1021 static bfd_boolean
1022 pr_fix_visibility (info, visibility)
1023 struct pr_handle *info;
1024 enum debug_visibility visibility;
1025 {
1026 const char *s = NULL;
1027 char *t;
1028 unsigned int len;
1029
1030 assert (info->stack != NULL);
1031
1032 if (info->stack->visibility == visibility)
1033 return TRUE;
1034
1035 switch (visibility)
1036 {
1037 case DEBUG_VISIBILITY_PUBLIC:
1038 s = "public";
1039 break;
1040 case DEBUG_VISIBILITY_PRIVATE:
1041 s = "private";
1042 break;
1043 case DEBUG_VISIBILITY_PROTECTED:
1044 s = "protected";
1045 break;
1046 case DEBUG_VISIBILITY_IGNORE:
1047 s = "/* ignore */";
1048 break;
1049 default:
1050 abort ();
1051 return FALSE;
1052 }
1053
1054 /* Trim off a trailing space in the struct string, to make the
1055 output look a bit better, then stick on the visibility string. */
1056
1057 t = info->stack->type;
1058 len = strlen (t);
1059 assert (t[len - 1] == ' ');
1060 t[len - 1] = '\0';
1061
1062 if (! append_type (info, s)
1063 || ! append_type (info, ":\n")
1064 || ! indent_type (info))
1065 return FALSE;
1066
1067 info->stack->visibility = visibility;
1068
1069 return TRUE;
1070 }
1071
1072 /* Add a field to a struct type. */
1073
1074 static bfd_boolean
1075 pr_struct_field (p, name, bitpos, bitsize, visibility)
1076 PTR p;
1077 const char *name;
1078 bfd_vma bitpos;
1079 bfd_vma bitsize;
1080 enum debug_visibility visibility;
1081 {
1082 struct pr_handle *info = (struct pr_handle *) p;
1083 char ab[20];
1084 char *t;
1085
1086 if (! substitute_type (info, name))
1087 return FALSE;
1088
1089 if (! append_type (info, "; /* "))
1090 return FALSE;
1091
1092 if (bitsize != 0)
1093 {
1094 print_vma (bitsize, ab, TRUE, FALSE);
1095 if (! append_type (info, "bitsize ")
1096 || ! append_type (info, ab)
1097 || ! append_type (info, ", "))
1098 return FALSE;
1099 }
1100
1101 print_vma (bitpos, ab, TRUE, FALSE);
1102 if (! append_type (info, "bitpos ")
1103 || ! append_type (info, ab)
1104 || ! append_type (info, " */\n")
1105 || ! indent_type (info))
1106 return FALSE;
1107
1108 t = pop_type (info);
1109 if (t == NULL)
1110 return FALSE;
1111
1112 if (! pr_fix_visibility (info, visibility))
1113 return FALSE;
1114
1115 return append_type (info, t);
1116 }
1117
1118 /* Finish a struct type. */
1119
1120 static bfd_boolean
1121 pr_end_struct_type (p)
1122 PTR p;
1123 {
1124 struct pr_handle *info = (struct pr_handle *) p;
1125 char *s;
1126
1127 assert (info->stack != NULL);
1128 assert (info->indent >= 2);
1129
1130 info->indent -= 2;
1131
1132 /* Change the trailing indentation to have a close brace. */
1133 s = info->stack->type + strlen (info->stack->type) - 2;
1134 assert (s[0] == ' ' && s[1] == ' ' && s[2] == '\0');
1135
1136 *s++ = '}';
1137 *s = '\0';
1138
1139 return TRUE;
1140 }
1141
1142 /* Start a class type. */
1143
1144 static bfd_boolean
1145 pr_start_class_type (p, tag, id, structp, size, vptr, ownvptr)
1146 PTR p;
1147 const char *tag;
1148 unsigned int id;
1149 bfd_boolean structp;
1150 unsigned int size;
1151 bfd_boolean vptr;
1152 bfd_boolean ownvptr;
1153 {
1154 struct pr_handle *info = (struct pr_handle *) p;
1155 char *tv = NULL;
1156
1157 info->indent += 2;
1158
1159 if (vptr && ! ownvptr)
1160 {
1161 tv = pop_type (info);
1162 if (tv == NULL)
1163 return FALSE;
1164 }
1165
1166 if (! push_type (info, structp ? "class " : "union class "))
1167 return FALSE;
1168 if (tag != NULL)
1169 {
1170 if (! append_type (info, tag))
1171 return FALSE;
1172 }
1173 else
1174 {
1175 char idbuf[20];
1176
1177 sprintf (idbuf, "%%anon%u", id);
1178 if (! append_type (info, idbuf))
1179 return FALSE;
1180 }
1181
1182 if (! append_type (info, " {"))
1183 return FALSE;
1184 if (size != 0 || vptr || ownvptr || tag != NULL)
1185 {
1186 if (! append_type (info, " /*"))
1187 return FALSE;
1188
1189 if (size != 0)
1190 {
1191 char ab[20];
1192
1193 sprintf (ab, "%u", size);
1194 if (! append_type (info, " size ")
1195 || ! append_type (info, ab))
1196 return FALSE;
1197 }
1198
1199 if (vptr)
1200 {
1201 if (! append_type (info, " vtable "))
1202 return FALSE;
1203 if (ownvptr)
1204 {
1205 if (! append_type (info, "self "))
1206 return FALSE;
1207 }
1208 else
1209 {
1210 if (! append_type (info, tv)
1211 || ! append_type (info, " "))
1212 return FALSE;
1213 }
1214 }
1215
1216 if (tag != NULL)
1217 {
1218 char ab[30];
1219
1220 sprintf (ab, " id %u", id);
1221 if (! append_type (info, ab))
1222 return FALSE;
1223 }
1224
1225 if (! append_type (info, " */"))
1226 return FALSE;
1227 }
1228
1229 info->stack->visibility = DEBUG_VISIBILITY_PRIVATE;
1230
1231 return (append_type (info, "\n")
1232 && indent_type (info));
1233 }
1234
1235 /* Add a static member to a class. */
1236
1237 static bfd_boolean
1238 pr_class_static_member (p, name, physname, visibility)
1239 PTR p;
1240 const char *name;
1241 const char *physname;
1242 enum debug_visibility visibility;
1243 {
1244 struct pr_handle *info = (struct pr_handle *) p;
1245 char *t;
1246
1247 if (! substitute_type (info, name))
1248 return FALSE;
1249
1250 if (! prepend_type (info, "static ")
1251 || ! append_type (info, "; /* ")
1252 || ! append_type (info, physname)
1253 || ! append_type (info, " */\n")
1254 || ! indent_type (info))
1255 return FALSE;
1256
1257 t = pop_type (info);
1258 if (t == NULL)
1259 return FALSE;
1260
1261 if (! pr_fix_visibility (info, visibility))
1262 return FALSE;
1263
1264 return append_type (info, t);
1265 }
1266
1267 /* Add a base class to a class. */
1268
1269 static bfd_boolean
1270 pr_class_baseclass (p, bitpos, virtual, visibility)
1271 PTR p;
1272 bfd_vma bitpos;
1273 bfd_boolean virtual;
1274 enum debug_visibility visibility;
1275 {
1276 struct pr_handle *info = (struct pr_handle *) p;
1277 char *t;
1278 const char *prefix;
1279 char ab[20];
1280 char *s, *l, *n;
1281
1282 assert (info->stack != NULL && info->stack->next != NULL);
1283
1284 if (! substitute_type (info, ""))
1285 return FALSE;
1286
1287 t = pop_type (info);
1288 if (t == NULL)
1289 return FALSE;
1290
1291 if (strncmp (t, "class ", sizeof "class " - 1) == 0)
1292 t += sizeof "class " - 1;
1293
1294 /* Push it back on to take advantage of the prepend_type and
1295 append_type routines. */
1296 if (! push_type (info, t))
1297 return FALSE;
1298
1299 if (virtual)
1300 {
1301 if (! prepend_type (info, "virtual "))
1302 return FALSE;
1303 }
1304
1305 switch (visibility)
1306 {
1307 case DEBUG_VISIBILITY_PUBLIC:
1308 prefix = "public ";
1309 break;
1310 case DEBUG_VISIBILITY_PROTECTED:
1311 prefix = "protected ";
1312 break;
1313 case DEBUG_VISIBILITY_PRIVATE:
1314 prefix = "private ";
1315 break;
1316 default:
1317 prefix = "/* unknown visibility */ ";
1318 break;
1319 }
1320
1321 if (! prepend_type (info, prefix))
1322 return FALSE;
1323
1324 if (bitpos != 0)
1325 {
1326 print_vma (bitpos, ab, TRUE, FALSE);
1327 if (! append_type (info, " /* bitpos ")
1328 || ! append_type (info, ab)
1329 || ! append_type (info, " */"))
1330 return FALSE;
1331 }
1332
1333 /* Now the top of the stack is something like "public A / * bitpos
1334 10 * /". The next element on the stack is something like "class
1335 xx { / * size 8 * /\n...". We want to substitute the top of the
1336 stack in before the {. */
1337 s = strchr (info->stack->next->type, '{');
1338 assert (s != NULL);
1339 --s;
1340
1341 /* If there is already a ':', then we already have a baseclass, and
1342 we must append this one after a comma. */
1343 for (l = info->stack->next->type; l != s; l++)
1344 if (*l == ':')
1345 break;
1346 if (! prepend_type (info, l == s ? " : " : ", "))
1347 return FALSE;
1348
1349 t = pop_type (info);
1350 if (t == NULL)
1351 return FALSE;
1352
1353 n = (char *) xmalloc (strlen (info->stack->type) + strlen (t) + 1);
1354 memcpy (n, info->stack->type, s - info->stack->type);
1355 strcpy (n + (s - info->stack->type), t);
1356 strcat (n, s);
1357
1358 free (info->stack->type);
1359 info->stack->type = n;
1360
1361 free (t);
1362
1363 return TRUE;
1364 }
1365
1366 /* Start adding a method to a class. */
1367
1368 static bfd_boolean
1369 pr_class_start_method (p, name)
1370 PTR p;
1371 const char *name;
1372 {
1373 struct pr_handle *info = (struct pr_handle *) p;
1374
1375 assert (info->stack != NULL);
1376 info->stack->method = name;
1377 return TRUE;
1378 }
1379
1380 /* Add a variant to a method. */
1381
1382 static bfd_boolean
1383 pr_class_method_variant (p, physname, visibility, constp, volatilep, voffset,
1384 context)
1385 PTR p;
1386 const char *physname;
1387 enum debug_visibility visibility;
1388 bfd_boolean constp;
1389 bfd_boolean volatilep;
1390 bfd_vma voffset;
1391 bfd_boolean context;
1392 {
1393 struct pr_handle *info = (struct pr_handle *) p;
1394 char *method_type;
1395 char *context_type;
1396
1397 assert (info->stack != NULL);
1398 assert (info->stack->next != NULL);
1399
1400 /* Put the const and volatile qualifiers on the type. */
1401 if (volatilep)
1402 {
1403 if (! append_type (info, " volatile"))
1404 return FALSE;
1405 }
1406 if (constp)
1407 {
1408 if (! append_type (info, " const"))
1409 return FALSE;
1410 }
1411
1412 /* Stick the name of the method into its type. */
1413 if (! substitute_type (info,
1414 (context
1415 ? info->stack->next->next->method
1416 : info->stack->next->method)))
1417 return FALSE;
1418
1419 /* Get the type. */
1420 method_type = pop_type (info);
1421 if (method_type == NULL)
1422 return FALSE;
1423
1424 /* Pull off the context type if there is one. */
1425 if (! context)
1426 context_type = NULL;
1427 else
1428 {
1429 context_type = pop_type (info);
1430 if (context_type == NULL)
1431 return FALSE;
1432 }
1433
1434 /* Now the top of the stack is the class. */
1435
1436 if (! pr_fix_visibility (info, visibility))
1437 return FALSE;
1438
1439 if (! append_type (info, method_type)
1440 || ! append_type (info, " /* ")
1441 || ! append_type (info, physname)
1442 || ! append_type (info, " "))
1443 return FALSE;
1444 if (context || voffset != 0)
1445 {
1446 char ab[20];
1447
1448 if (context)
1449 {
1450 if (! append_type (info, "context ")
1451 || ! append_type (info, context_type)
1452 || ! append_type (info, " "))
1453 return FALSE;
1454 }
1455 print_vma (voffset, ab, TRUE, FALSE);
1456 if (! append_type (info, "voffset ")
1457 || ! append_type (info, ab))
1458 return FALSE;
1459 }
1460
1461 return (append_type (info, " */;\n")
1462 && indent_type (info));
1463 }
1464
1465 /* Add a static variant to a method. */
1466
1467 static bfd_boolean
1468 pr_class_static_method_variant (p, physname, visibility, constp, volatilep)
1469 PTR p;
1470 const char *physname;
1471 enum debug_visibility visibility;
1472 bfd_boolean constp;
1473 bfd_boolean volatilep;
1474 {
1475 struct pr_handle *info = (struct pr_handle *) p;
1476 char *method_type;
1477
1478 assert (info->stack != NULL);
1479 assert (info->stack->next != NULL);
1480 assert (info->stack->next->method != NULL);
1481
1482 /* Put the const and volatile qualifiers on the type. */
1483 if (volatilep)
1484 {
1485 if (! append_type (info, " volatile"))
1486 return FALSE;
1487 }
1488 if (constp)
1489 {
1490 if (! append_type (info, " const"))
1491 return FALSE;
1492 }
1493
1494 /* Mark it as static. */
1495 if (! prepend_type (info, "static "))
1496 return FALSE;
1497
1498 /* Stick the name of the method into its type. */
1499 if (! substitute_type (info, info->stack->next->method))
1500 return FALSE;
1501
1502 /* Get the type. */
1503 method_type = pop_type (info);
1504 if (method_type == NULL)
1505 return FALSE;
1506
1507 /* Now the top of the stack is the class. */
1508
1509 if (! pr_fix_visibility (info, visibility))
1510 return FALSE;
1511
1512 return (append_type (info, method_type)
1513 && append_type (info, " /* ")
1514 && append_type (info, physname)
1515 && append_type (info, " */;\n")
1516 && indent_type (info));
1517 }
1518
1519 /* Finish up a method. */
1520
1521 static bfd_boolean
1522 pr_class_end_method (p)
1523 PTR p;
1524 {
1525 struct pr_handle *info = (struct pr_handle *) p;
1526
1527 info->stack->method = NULL;
1528 return TRUE;
1529 }
1530
1531 /* Finish up a class. */
1532
1533 static bfd_boolean
1534 pr_end_class_type (p)
1535 PTR p;
1536 {
1537 return pr_end_struct_type (p);
1538 }
1539
1540 /* Push a type on the stack using a typedef name. */
1541
1542 static bfd_boolean
1543 pr_typedef_type (p, name)
1544 PTR p;
1545 const char *name;
1546 {
1547 struct pr_handle *info = (struct pr_handle *) p;
1548
1549 return push_type (info, name);
1550 }
1551
1552 /* Push a type on the stack using a tag name. */
1553
1554 static bfd_boolean
1555 pr_tag_type (p, name, id, kind)
1556 PTR p;
1557 const char *name;
1558 unsigned int id;
1559 enum debug_type_kind kind;
1560 {
1561 struct pr_handle *info = (struct pr_handle *) p;
1562 const char *t, *tag;
1563 char idbuf[20];
1564
1565 switch (kind)
1566 {
1567 case DEBUG_KIND_STRUCT:
1568 t = "struct ";
1569 break;
1570 case DEBUG_KIND_UNION:
1571 t = "union ";
1572 break;
1573 case DEBUG_KIND_ENUM:
1574 t = "enum ";
1575 break;
1576 case DEBUG_KIND_CLASS:
1577 t = "class ";
1578 break;
1579 case DEBUG_KIND_UNION_CLASS:
1580 t = "union class ";
1581 break;
1582 default:
1583 abort ();
1584 return FALSE;
1585 }
1586
1587 if (! push_type (info, t))
1588 return FALSE;
1589 if (name != NULL)
1590 tag = name;
1591 else
1592 {
1593 sprintf (idbuf, "%%anon%u", id);
1594 tag = idbuf;
1595 }
1596
1597 if (! append_type (info, tag))
1598 return FALSE;
1599 if (name != NULL && kind != DEBUG_KIND_ENUM)
1600 {
1601 sprintf (idbuf, " /* id %u */", id);
1602 if (! append_type (info, idbuf))
1603 return FALSE;
1604 }
1605
1606 return TRUE;
1607 }
1608
1609 /* Output a typedef. */
1610
1611 static bfd_boolean
1612 pr_typdef (p, name)
1613 PTR p;
1614 const char *name;
1615 {
1616 struct pr_handle *info = (struct pr_handle *) p;
1617 char *s;
1618
1619 if (! substitute_type (info, name))
1620 return FALSE;
1621
1622 s = pop_type (info);
1623 if (s == NULL)
1624 return FALSE;
1625
1626 indent (info);
1627 fprintf (info->f, "typedef %s;\n", s);
1628
1629 free (s);
1630
1631 return TRUE;
1632 }
1633
1634 /* Output a tag. The tag should already be in the string on the
1635 stack, so all we have to do here is print it out. */
1636
1637 static bfd_boolean
1638 pr_tag (p, name)
1639 PTR p;
1640 const char *name ATTRIBUTE_UNUSED;
1641 {
1642 struct pr_handle *info = (struct pr_handle *) p;
1643 char *t;
1644
1645 t = pop_type (info);
1646 if (t == NULL)
1647 return FALSE;
1648
1649 indent (info);
1650 fprintf (info->f, "%s;\n", t);
1651
1652 free (t);
1653
1654 return TRUE;
1655 }
1656
1657 /* Output an integer constant. */
1658
1659 static bfd_boolean
1660 pr_int_constant (p, name, val)
1661 PTR p;
1662 const char *name;
1663 bfd_vma val;
1664 {
1665 struct pr_handle *info = (struct pr_handle *) p;
1666 char ab[20];
1667
1668 indent (info);
1669 print_vma (val, ab, FALSE, FALSE);
1670 fprintf (info->f, "const int %s = %s;\n", name, ab);
1671 return TRUE;
1672 }
1673
1674 /* Output a floating point constant. */
1675
1676 static bfd_boolean
1677 pr_float_constant (p, name, val)
1678 PTR p;
1679 const char *name;
1680 double val;
1681 {
1682 struct pr_handle *info = (struct pr_handle *) p;
1683
1684 indent (info);
1685 fprintf (info->f, "const double %s = %g;\n", name, val);
1686 return TRUE;
1687 }
1688
1689 /* Output a typed constant. */
1690
1691 static bfd_boolean
1692 pr_typed_constant (p, name, val)
1693 PTR p;
1694 const char *name;
1695 bfd_vma val;
1696 {
1697 struct pr_handle *info = (struct pr_handle *) p;
1698 char *t;
1699 char ab[20];
1700
1701 t = pop_type (info);
1702 if (t == NULL)
1703 return FALSE;
1704
1705 indent (info);
1706 print_vma (val, ab, FALSE, FALSE);
1707 fprintf (info->f, "const %s %s = %s;\n", t, name, ab);
1708
1709 free (t);
1710
1711 return TRUE;
1712 }
1713
1714 /* Output a variable. */
1715
1716 static bfd_boolean
1717 pr_variable (p, name, kind, val)
1718 PTR p;
1719 const char *name;
1720 enum debug_var_kind kind;
1721 bfd_vma val;
1722 {
1723 struct pr_handle *info = (struct pr_handle *) p;
1724 char *t;
1725 char ab[20];
1726
1727 if (! substitute_type (info, name))
1728 return FALSE;
1729
1730 t = pop_type (info);
1731 if (t == NULL)
1732 return FALSE;
1733
1734 indent (info);
1735 switch (kind)
1736 {
1737 case DEBUG_STATIC:
1738 case DEBUG_LOCAL_STATIC:
1739 fprintf (info->f, "static ");
1740 break;
1741 case DEBUG_REGISTER:
1742 fprintf (info->f, "register ");
1743 break;
1744 default:
1745 break;
1746 }
1747 print_vma (val, ab, TRUE, TRUE);
1748 fprintf (info->f, "%s /* %s */;\n", t, ab);
1749
1750 free (t);
1751
1752 return TRUE;
1753 }
1754
1755 /* Start outputting a function. */
1756
1757 static bfd_boolean
1758 pr_start_function (p, name, global)
1759 PTR p;
1760 const char *name;
1761 bfd_boolean global;
1762 {
1763 struct pr_handle *info = (struct pr_handle *) p;
1764 char *t;
1765
1766 if (! substitute_type (info, name))
1767 return FALSE;
1768
1769 t = pop_type (info);
1770 if (t == NULL)
1771 return FALSE;
1772
1773 indent (info);
1774 if (! global)
1775 fprintf (info->f, "static ");
1776 fprintf (info->f, "%s (", t);
1777
1778 info->parameter = 1;
1779
1780 return TRUE;
1781 }
1782
1783 /* Output a function parameter. */
1784
1785 static bfd_boolean
1786 pr_function_parameter (p, name, kind, val)
1787 PTR p;
1788 const char *name;
1789 enum debug_parm_kind kind;
1790 bfd_vma val;
1791 {
1792 struct pr_handle *info = (struct pr_handle *) p;
1793 char *t;
1794 char ab[20];
1795
1796 if (kind == DEBUG_PARM_REFERENCE
1797 || kind == DEBUG_PARM_REF_REG)
1798 {
1799 if (! pr_reference_type (p))
1800 return FALSE;
1801 }
1802
1803 if (! substitute_type (info, name))
1804 return FALSE;
1805
1806 t = pop_type (info);
1807 if (t == NULL)
1808 return FALSE;
1809
1810 if (info->parameter != 1)
1811 fprintf (info->f, ", ");
1812
1813 if (kind == DEBUG_PARM_REG || kind == DEBUG_PARM_REF_REG)
1814 fprintf (info->f, "register ");
1815
1816 print_vma (val, ab, TRUE, TRUE);
1817 fprintf (info->f, "%s /* %s */", t, ab);
1818
1819 free (t);
1820
1821 ++info->parameter;
1822
1823 return TRUE;
1824 }
1825
1826 /* Start writing out a block. */
1827
1828 static bfd_boolean
1829 pr_start_block (p, addr)
1830 PTR p;
1831 bfd_vma addr;
1832 {
1833 struct pr_handle *info = (struct pr_handle *) p;
1834 char ab[20];
1835
1836 if (info->parameter > 0)
1837 {
1838 fprintf (info->f, ")\n");
1839 info->parameter = 0;
1840 }
1841
1842 indent (info);
1843 print_vma (addr, ab, TRUE, TRUE);
1844 fprintf (info->f, "{ /* %s */\n", ab);
1845
1846 info->indent += 2;
1847
1848 return TRUE;
1849 }
1850
1851 /* Write out line number information. */
1852
1853 static bfd_boolean
1854 pr_lineno (p, filename, lineno, addr)
1855 PTR p;
1856 const char *filename;
1857 unsigned long lineno;
1858 bfd_vma addr;
1859 {
1860 struct pr_handle *info = (struct pr_handle *) p;
1861 char ab[20];
1862
1863 indent (info);
1864 print_vma (addr, ab, TRUE, TRUE);
1865 fprintf (info->f, "/* file %s line %lu addr %s */\n", filename, lineno, ab);
1866
1867 return TRUE;
1868 }
1869
1870 /* Finish writing out a block. */
1871
1872 static bfd_boolean
1873 pr_end_block (p, addr)
1874 PTR p;
1875 bfd_vma addr;
1876 {
1877 struct pr_handle *info = (struct pr_handle *) p;
1878 char ab[20];
1879
1880 info->indent -= 2;
1881
1882 indent (info);
1883 print_vma (addr, ab, TRUE, TRUE);
1884 fprintf (info->f, "} /* %s */\n", ab);
1885
1886 return TRUE;
1887 }
1888
1889 /* Finish writing out a function. */
1890
1891 static bfd_boolean
1892 pr_end_function (p)
1893 PTR p ATTRIBUTE_UNUSED;
1894 {
1895 return TRUE;
1896 }
This page took 0.091696 seconds and 4 git commands to generate.