1 /* prdbg.c -- Print out generic debugging information.
2 Copyright (C) 1995 Free Software Foundation, Inc.
3 Written by Ian Lance Taylor <ian@cygnus.com>.
5 This file is part of GNU Binutils.
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.
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.
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
22 /* This file prints out the generic debugging information, by
23 supplying a set of routines to debug_write. */
30 #include "libiberty.h"
34 /* This is the structure we use as a handle for these routines. */
38 /* File to print information to. */
40 /* Current indentation level. */
43 struct pr_stack *stack;
44 /* Parameter number we are about to output. */
52 /* Next element on the stack. */
53 struct pr_stack *next;
56 /* Current visibility of fields if this is a class. */
57 enum debug_visibility visibility;
58 /* Name of the current method we are handling. */
62 static void indent PARAMS ((struct pr_handle *));
63 static boolean push_type PARAMS ((struct pr_handle *, const char *));
64 static boolean prepend_type PARAMS ((struct pr_handle *, const char *));
65 static boolean append_type PARAMS ((struct pr_handle *, const char *));
66 static boolean substitute_type PARAMS ((struct pr_handle *, const char *));
67 static boolean indent_type PARAMS ((struct pr_handle *));
68 static char *pop_type PARAMS ((struct pr_handle *));
69 static void print_vma PARAMS ((bfd_vma, char *, boolean, boolean));
70 static boolean pr_fix_visibility
71 PARAMS ((struct pr_handle *, enum debug_visibility));
73 static boolean pr_start_compilation_unit PARAMS ((PTR, const char *));
74 static boolean pr_start_source PARAMS ((PTR, const char *));
75 static boolean pr_empty_type PARAMS ((PTR));
76 static boolean pr_void_type PARAMS ((PTR));
77 static boolean pr_int_type PARAMS ((PTR, unsigned int, boolean));
78 static boolean pr_float_type PARAMS ((PTR, unsigned int));
79 static boolean pr_complex_type PARAMS ((PTR, unsigned int));
80 static boolean pr_bool_type PARAMS ((PTR, unsigned int));
81 static boolean pr_enum_type PARAMS ((PTR, const char **, bfd_signed_vma *));
82 static boolean pr_pointer_type PARAMS ((PTR));
83 static boolean pr_function_type PARAMS ((PTR));
84 static boolean pr_reference_type PARAMS ((PTR));
85 static boolean pr_range_type PARAMS ((PTR, bfd_signed_vma, bfd_signed_vma));
86 static boolean pr_array_type
87 PARAMS ((PTR, bfd_signed_vma, bfd_signed_vma, boolean));
88 static boolean pr_set_type PARAMS ((PTR, boolean));
89 static boolean pr_offset_type PARAMS ((PTR));
90 static boolean pr_method_type PARAMS ((PTR, boolean, int));
91 static boolean pr_const_type PARAMS ((PTR));
92 static boolean pr_volatile_type PARAMS ((PTR));
93 static boolean pr_start_struct_type PARAMS ((PTR, boolean, unsigned int));
94 static boolean pr_struct_field
95 PARAMS ((PTR, const char *, bfd_vma, bfd_vma, enum debug_visibility));
96 static boolean pr_end_struct_type PARAMS ((PTR));
97 static boolean pr_start_class_type
98 PARAMS ((PTR, boolean, unsigned int, boolean, boolean));
99 static boolean pr_class_static_member
100 PARAMS ((PTR, const char *, const char *, enum debug_visibility));
101 static boolean pr_class_baseclass
102 PARAMS ((PTR, bfd_vma, boolean, enum debug_visibility));
103 static boolean pr_class_start_method PARAMS ((PTR, const char *));
104 static boolean pr_class_method_variant
105 PARAMS ((PTR, const char *, enum debug_visibility, boolean, boolean,
107 static boolean pr_class_static_method_variant
108 PARAMS ((PTR, const char *, enum debug_visibility, boolean, boolean));
109 static boolean pr_class_end_method PARAMS ((PTR));
110 static boolean pr_end_class_type PARAMS ((PTR));
111 static boolean pr_typedef_type PARAMS ((PTR, const char *));
112 static boolean pr_tag_type PARAMS ((PTR, const char *, enum debug_type_kind));
113 static boolean pr_typdef PARAMS ((PTR, const char *));
114 static boolean pr_tag PARAMS ((PTR, const char *));
115 static boolean pr_int_constant PARAMS ((PTR, const char *, bfd_vma));
116 static boolean pr_float_constant PARAMS ((PTR, const char *, double));
117 static boolean pr_typed_constant PARAMS ((PTR, const char *, bfd_vma));
118 static boolean pr_variable
119 PARAMS ((PTR, const char *, enum debug_var_kind, bfd_vma));
120 static boolean pr_start_function PARAMS ((PTR, const char *, boolean));
121 static boolean pr_function_parameter
122 PARAMS ((PTR, const char *, enum debug_parm_kind, bfd_vma));
123 static boolean pr_start_block PARAMS ((PTR, bfd_vma));
124 static boolean pr_lineno PARAMS ((PTR, const char *, unsigned long, bfd_vma));
125 static boolean pr_end_block PARAMS ((PTR, bfd_vma));
126 static boolean pr_end_function PARAMS ((PTR));
128 static const struct debug_write_fns pr_fns =
130 pr_start_compilation_unit,
149 pr_start_struct_type,
153 pr_class_static_member,
155 pr_class_start_method,
156 pr_class_method_variant,
157 pr_class_static_method_variant,
169 pr_function_parameter,
176 /* Print out the generic debugging information recorded in dhandle. */
179 print_debugging_info (f, dhandle)
183 struct pr_handle info;
190 return debug_write (dhandle, &pr_fns, (PTR) &info);
193 /* Indent to the current indentation level. */
197 struct pr_handle *info;
201 for (i = 0; i < info->indent; i++)
205 /* Push a type on the type stack. */
208 push_type (info, type)
209 struct pr_handle *info;
217 n = (struct pr_stack *) xmalloc (sizeof *n);
218 memset (n, 0, sizeof *n);
220 n->type = xstrdup (type);
221 n->visibility = DEBUG_VISIBILITY_IGNORE;
223 n->next = info->stack;
229 /* Prepend a string onto the type on the top of the type stack. */
232 prepend_type (info, s)
233 struct pr_handle *info;
238 assert (info->stack != NULL);
240 n = (char *) xmalloc (strlen (s) + strlen (info->stack->type) + 1);
241 sprintf (n, "%s%s", s, info->stack->type);
242 free (info->stack->type);
243 info->stack->type = n;
248 /* Append a string to the type on the top of the type stack. */
251 append_type (info, s)
252 struct pr_handle *info;
260 assert (info->stack != NULL);
262 len = strlen (info->stack->type);
263 info->stack->type = (char *) xrealloc (info->stack->type,
264 len + strlen (s) + 1);
265 strcpy (info->stack->type + len, s);
270 /* We use an underscore to indicate where the name should go in a type
271 string. This function substitutes a string for the underscore. If
272 there is no underscore, the name follows the type. */
275 substitute_type (info, s)
276 struct pr_handle *info;
281 assert (info->stack != NULL);
283 u = strchr (info->stack->type, '|');
288 n = (char *) xmalloc (strlen (info->stack->type) + strlen (s));
290 memcpy (n, info->stack->type, u - info->stack->type);
291 strcpy (n + (u - info->stack->type), s);
294 free (info->stack->type);
295 info->stack->type = n;
300 if (strchr (s, '|') != NULL
301 && (strchr (info->stack->type, '{') != NULL
302 || strchr (info->stack->type, '(') != NULL))
304 if (! prepend_type (info, "(")
305 || ! append_type (info, ")"))
312 return (append_type (info, " ")
313 && append_type (info, s));
316 /* Indent the type at the top of the stack by appending spaces. */
320 struct pr_handle *info;
324 for (i = 0; i < info->indent; i++)
326 if (! append_type (info, " "))
333 /* Pop a type from the type stack. */
337 struct pr_handle *info;
342 assert (info->stack != NULL);
345 info->stack = o->next;
349 s = strchr (ret, '+');
351 memmove (s, s + 2, strlen (s + 2) + 1);
356 /* Print a VMA value into a string. */
359 print_vma (vma, buf, unsignedp, hexp)
365 if (sizeof (vma) <= sizeof (unsigned long))
368 sprintf (buf, "0x%lx", (unsigned long) vma);
370 sprintf (buf, "%lu", (unsigned long) vma);
372 sprintf (buf, "%ld", (long) vma);
378 sprintf_vma (buf + 2, vma);
382 /* Start a new compilation unit. */
385 pr_start_compilation_unit (p, filename)
387 const char *filename;
389 struct pr_handle *info = (struct pr_handle *) p;
391 assert (info->indent == 0);
393 fprintf (info->f, "%s:\n", filename);
398 /* Start a source file within a compilation unit. */
401 pr_start_source (p, filename)
403 const char *filename;
405 struct pr_handle *info = (struct pr_handle *) p;
407 assert (info->indent == 0);
409 fprintf (info->f, " %s:\n", filename);
414 /* Push an empty type onto the type stack. */
420 struct pr_handle *info = (struct pr_handle *) p;
422 return push_type (info, "<undefined>");
425 /* Push a void type onto the type stack. */
431 struct pr_handle *info = (struct pr_handle *) p;
433 return push_type (info, "void");
436 /* Push an integer type onto the type stack. */
439 pr_int_type (p, size, unsignedp)
444 struct pr_handle *info = (struct pr_handle *) p;
447 sprintf (ab, "%sint%d", unsignedp ? "u" : "", size * 8);
448 return push_type (info, ab);
451 /* Push a floating type onto the type stack. */
454 pr_float_type (p, size)
458 struct pr_handle *info = (struct pr_handle *) p;
462 return push_type (info, "float");
464 return push_type (info, "double");
466 sprintf (ab, "float%d", size * 8);
467 return push_type (info, ab);
470 /* Push a complex type onto the type stack. */
473 pr_complex_type (p, size)
477 struct pr_handle *info = (struct pr_handle *) p;
479 if (! pr_float_type (p, size))
482 return prepend_type (info, "complex ");
485 /* Push a boolean type onto the type stack. */
488 pr_bool_type (p, size)
492 struct pr_handle *info = (struct pr_handle *) p;
495 sprintf (ab, "bool%d", size * 8);
497 return push_type (info, ab);
500 /* Push an enum type onto the type stack. */
503 pr_enum_type (p, names, values)
506 bfd_signed_vma *values;
508 struct pr_handle *info = (struct pr_handle *) p;
512 /* The + indicates where the tag goes, if there is one. */
513 if (! push_type (info, "enum + { "))
517 for (i = 0; names[i] != NULL; i++)
521 if (! append_type (info, ", "))
525 if (! append_type (info, names[i]))
528 if (values[i] != val)
532 print_vma (values[i], ab, false, false);
533 if (! append_type (info, " = ")
534 || ! append_type (info, ab))
542 return append_type (info, " }");
545 /* Turn the top type on the stack into a pointer. */
551 struct pr_handle *info = (struct pr_handle *) p;
553 assert (info->stack != NULL);
555 return substitute_type (info, "*|");
558 /* Turn the top type on the stack into a function returning that type. */
564 struct pr_handle *info = (struct pr_handle *) p;
566 assert (info->stack != NULL);
568 return substitute_type (info, "(|) ()");
571 /* Turn the top type on the stack into a reference to that type. */
574 pr_reference_type (p)
577 struct pr_handle *info = (struct pr_handle *) p;
579 assert (info->stack != NULL);
581 return substitute_type (info, "&|");
584 /* Make a range type. */
587 pr_range_type (p, lower, upper)
589 bfd_signed_vma lower;
590 bfd_signed_vma upper;
592 struct pr_handle *info = (struct pr_handle *) p;
593 char abl[20], abu[20];
595 assert (info->stack != NULL);
597 if (! substitute_type (info, ""))
600 print_vma (lower, abl, false, false);
601 print_vma (upper, abu, false, false);
603 return (prepend_type (info, "range (")
604 && append_type (info, "):")
605 && append_type (info, abl)
606 && append_type (info, ":")
607 && append_type (info, abu));
610 /* Make an array type. */
614 pr_array_type (p, lower, upper, stringp)
616 bfd_signed_vma lower;
617 bfd_signed_vma upper;
620 struct pr_handle *info = (struct pr_handle *) p;
622 char abl[20], abu[20], ab[50];
624 range_type = pop_type (info);
625 if (range_type == NULL)
634 print_vma (upper + 1, abu, false, false);
635 sprintf (ab, "|[%s]", abu);
640 print_vma (lower, abl, false, false);
641 print_vma (upper, abu, false, false);
642 sprintf (ab, "|[%s:%s]", abl, abu);
645 if (! substitute_type (info, ab))
648 if (strcmp (range_type, "int") != 0)
650 if (! append_type (info, ":")
651 || ! append_type (info, range_type))
657 if (! append_type (info, " /* string */"))
664 /* Make a set type. */
668 pr_set_type (p, bitstringp)
672 struct pr_handle *info = (struct pr_handle *) p;
674 if (! substitute_type (info, ""))
677 if (! prepend_type (info, "set { ")
678 || ! append_type (info, " }"))
683 if (! append_type (info, "/* bitstring */"))
690 /* Make an offset type. */
696 struct pr_handle *info = (struct pr_handle *) p;
699 if (! substitute_type (info, ""))
706 return (substitute_type (info, "")
707 && prepend_type (info, " ")
708 && prepend_type (info, t)
709 && append_type (info, "::|"));
712 /* Make a method type. */
715 pr_method_type (p, domain, argcount)
720 struct pr_handle *info = (struct pr_handle *) p;
732 if (! substitute_type (info, ""))
734 domain_type = pop_type (info);
735 if (domain_type == NULL)
737 if (strncmp (domain_type, "class ", sizeof "class " - 1) == 0
738 && strchr (domain_type + sizeof "class " - 1, ' ') == NULL)
739 domain_type += sizeof "class " - 1;
740 else if (strncmp (domain_type, "union class ",
741 sizeof "union class ") == 0
742 && (strchr (domain_type + sizeof "union class " - 1, ' ')
744 domain_type += sizeof "union class " - 1;
745 len += strlen (domain_type);
757 arg_types = (char **) xmalloc (argcount * sizeof *arg_types);
758 for (i = argcount - 1; i >= 0; i--)
760 if (! substitute_type (info, ""))
762 arg_types[i] = pop_type (info);
763 if (arg_types[i] == NULL)
765 len += strlen (arg_types[i]) + 2;
769 /* Now the return type is on the top of the stack. */
771 s = (char *) xmalloc (len);
775 strcpy (s, domain_type);
779 strcat (s, "/* unknown */");
784 for (i = 0; i < argcount; i++)
788 strcat (s, arg_types[i]);
794 if (! substitute_type (info, s))
802 /* Make a const qualified type. */
808 struct pr_handle *info = (struct pr_handle *) p;
810 return substitute_type (info, "const |");
813 /* Make a volatile qualified type. */
819 struct pr_handle *info = (struct pr_handle *) p;
821 return substitute_type (info, "volatile |");
824 /* Start accumulating a struct type. */
827 pr_start_struct_type (p, structp, size)
832 struct pr_handle *info = (struct pr_handle *) p;
843 sprintf (ab, "%s + { /* size %u */\n", t, size);
845 sprintf (ab, "%s + {\n", t);
846 if (! push_type (info, ab))
848 info->stack->visibility = DEBUG_VISIBILITY_PUBLIC;
849 return indent_type (info);
852 /* Output the visibility of a field in a struct. */
855 pr_fix_visibility (info, visibility)
856 struct pr_handle *info;
857 enum debug_visibility visibility;
860 struct pr_stack *top;
864 assert (info->stack != NULL && info->stack->next != NULL);
866 if (info->stack->next->visibility == visibility)
869 assert (info->stack->next->visibility != DEBUG_VISIBILITY_IGNORE);
873 case DEBUG_VISIBILITY_PUBLIC:
876 case DEBUG_VISIBILITY_PRIVATE:
879 case DEBUG_VISIBILITY_PROTECTED:
887 /* Trim off a trailing space in the struct string, to make the
888 output look a bit better, then stick on the visibility string.
889 Pop the stack temporarily to make the string manipulation
893 info->stack = top->next;
895 t = info->stack->type;
897 assert (t[len - 1] == ' ');
900 if (! append_type (info, s)
901 || ! append_type (info, ":\n")
902 || ! indent_type (info))
905 info->stack->visibility = visibility;
912 /* Add a field to a struct type. */
915 pr_struct_field (p, name, bitpos, bitsize, visibility)
920 enum debug_visibility visibility;
922 struct pr_handle *info = (struct pr_handle *) p;
925 if (! pr_fix_visibility (info, visibility))
928 if (! substitute_type (info, name))
931 if (! append_type (info, "; /* "))
936 print_vma (bitsize, ab, true, false);
937 if (! append_type (info, "bitsize ")
938 || ! append_type (info, ab)
939 || ! append_type (info, ", "))
943 print_vma (bitpos, ab, true, false);
944 if (! append_type (info, "bitpos ")
945 || ! append_type (info, ab)
946 || ! append_type (info, " */\n")
947 || ! indent_type (info))
950 return append_type (info, pop_type (info));
953 /* Finish a struct type. */
956 pr_end_struct_type (p)
959 struct pr_handle *info = (struct pr_handle *) p;
962 assert (info->stack != NULL);
963 assert (info->indent >= 2);
967 /* Change the trailing indentation to have a close brace. */
968 s = info->stack->type + strlen (info->stack->type) - 2;
969 assert (strcmp (s, " ") == 0);
977 /* Start a class type. */
980 pr_start_class_type (p, structp, size, vptr, ownvptr)
987 struct pr_handle *info = (struct pr_handle *) p;
992 if (vptr && ! ownvptr)
994 tv = pop_type (info);
999 if (! push_type (info, structp ? "class" : "union class")
1000 || ! append_type (info, " + {"))
1002 if (size != 0 || vptr || ownvptr)
1004 if (! append_type (info, " /*"))
1011 sprintf (ab, "%u", size);
1012 if (! append_type (info, " size ")
1013 || ! append_type (info, ab))
1019 if (! append_type (info, " vtable "))
1023 if (! append_type (info, "self "))
1028 if (! append_type (info, tv)
1029 || ! append_type (info, " "))
1034 if (! append_type (info, " */"))
1038 info->stack->visibility = DEBUG_VISIBILITY_PRIVATE;
1040 return (append_type (info, "\n")
1041 && indent_type (info));
1044 /* Add a static member to a class. */
1047 pr_class_static_member (p, name, physname, visibility)
1050 const char *physname;
1051 enum debug_visibility visibility;
1053 struct pr_handle *info = (struct pr_handle *) p;
1055 if (! pr_fix_visibility (info, visibility))
1058 if (! substitute_type (info, name))
1061 return (prepend_type (info, "static ")
1062 && append_type (info, "; /* physname ")
1063 && append_type (info, physname)
1064 && append_type (info, " */\n")
1065 && indent_type (info)
1066 && append_type (info, pop_type (info)));
1069 /* Add a base class to a class. */
1072 pr_class_baseclass (p, bitpos, virtual, visibility)
1076 enum debug_visibility visibility;
1078 struct pr_handle *info = (struct pr_handle *) p;
1084 assert (info->stack != NULL && info->stack->next != NULL);
1086 if (! substitute_type (info, ""))
1089 t = pop_type (info);
1093 if (strncmp (t, "class ", sizeof "class " - 1) == 0)
1094 t += sizeof "class " - 1;
1096 /* Push it back on to take advantage of the prepend_type and
1097 append_type routines. */
1098 if (! push_type (info, t))
1103 if (! prepend_type (info, "virtual "))
1109 case DEBUG_VISIBILITY_PUBLIC:
1112 case DEBUG_VISIBILITY_PROTECTED:
1113 prefix = "protected ";
1115 case DEBUG_VISIBILITY_PRIVATE:
1116 prefix = "private ";
1119 prefix = "/* unknown visibility */ ";
1123 if (! prepend_type (info, prefix))
1128 print_vma (bitpos, ab, true, false);
1129 if (! append_type (info, " /* bitpos ")
1130 || ! append_type (info, ab)
1131 || ! append_type (info, " */"))
1135 /* Now the top of the stack is something like "public A / * bitpos
1136 10 * /". The next element on the stack is something like "class
1137 + { / * size 8 * /\n...". We want to substitute the top of the
1138 stack in after the +. */
1139 s = strchr (info->stack->next->type, '+');
1145 assert (s[1] == '{');
1146 if (! prepend_type (info, " : "))
1151 /* We already have a baseclass. Append this one after a comma. */
1152 s = strchr (s, '{');
1155 if (! prepend_type (info, ", "))
1159 t = pop_type (info);
1163 n = (char *) xmalloc (strlen (info->stack->type) + strlen (t) + 1);
1164 memcpy (n, info->stack->type, s - info->stack->type);
1165 strcpy (n + (s - info->stack->type), t);
1168 free (info->stack->type);
1169 info->stack->type = n;
1176 /* Start adding a method to a class. */
1179 pr_class_start_method (p, name)
1183 struct pr_handle *info = (struct pr_handle *) p;
1185 if (! push_type (info, ""))
1187 info->stack->method = name;
1191 /* Add a variant to a method. */
1194 pr_class_method_variant (p, argtypes, visibility, constp, volatilep, voffset,
1197 const char *argtypes;
1198 enum debug_visibility visibility;
1204 struct pr_handle *info = (struct pr_handle *) p;
1208 assert (info->stack != NULL);
1209 assert (info->stack->next != NULL);
1211 /* Put the const and volatile qualifiers on the type. */
1214 if (! prepend_type (info, "volatile "))
1219 if (! prepend_type (info, "const "))
1223 /* Stick the name of the method into its type. */
1224 if (! substitute_type (info,
1226 ? info->stack->next->next->method
1227 : info->stack->next->method)))
1231 method_type = pop_type (info);
1232 if (method_type == NULL)
1235 /* Pull off the context type if there is one. */
1237 context_type = NULL;
1240 context_type = pop_type (info);
1241 if (context_type == NULL)
1245 /* Now the top of the stack is the holder for the method, and the
1246 second element on the stack is the class. */
1248 if (! pr_fix_visibility (info, visibility))
1251 if (! append_type (info, method_type)
1252 || ! append_type (info, " /* ")
1253 || ! append_type (info, argtypes))
1255 if (context || voffset != 0)
1261 if (! append_type (info, "context ")
1262 || ! append_type (info, context_type)
1263 || ! append_type (info, " "))
1266 print_vma (voffset, ab, true, false);
1267 if (! append_type (info, "voffset ")
1268 || ! append_type (info, ab))
1272 return (append_type (info, " */;\n")
1273 && indent_type (info));
1276 /* Add a static variant to a method. */
1279 pr_class_static_method_variant (p, argtypes, visibility, constp, volatilep)
1281 const char *argtypes;
1282 enum debug_visibility visibility;
1286 struct pr_handle *info = (struct pr_handle *) p;
1289 assert (info->stack != NULL);
1290 assert (info->stack->next != NULL);
1291 assert (info->stack->next->method != NULL);
1293 /* Put the const and volatile qualifiers on the type. */
1296 if (! prepend_type (info, "volatile "))
1301 if (! prepend_type (info, "const "))
1305 /* Mark it as static. */
1306 if (! prepend_type (info, "static "))
1309 /* Stick the name of the method into its type. */
1310 if (! substitute_type (info, info->stack->next->method))
1314 method_type = pop_type (info);
1315 if (method_type == NULL)
1318 /* Now the top of the stack is the holder for the method, and the
1319 second element on the stack is the class. */
1321 if (! pr_fix_visibility (info, visibility))
1324 return (append_type (info, method_type)
1325 && append_type (info, " /* ")
1326 && append_type (info, argtypes)
1327 && append_type (info, " */;\n")
1328 && indent_type (info));
1331 /* Finish up a method. */
1334 pr_class_end_method (p)
1337 struct pr_handle *info = (struct pr_handle *) p;
1339 /* The method variants have been appended to the string on top of
1340 the stack with the correct indentation. We just need the append
1341 the string on top of the stack to the class string that is second
1343 return append_type (info, pop_type (info));
1346 /* Finish up a class. */
1349 pr_end_class_type (p)
1352 return pr_end_struct_type (p);
1355 /* Push a type on the stack using a typedef name. */
1358 pr_typedef_type (p, name)
1362 struct pr_handle *info = (struct pr_handle *) p;
1364 return push_type (info, name);
1367 /* Push a type on the stack using a tag name. */
1370 pr_tag_type (p, name, kind)
1373 enum debug_type_kind kind;
1375 struct pr_handle *info = (struct pr_handle *) p;
1380 case DEBUG_KIND_STRUCT:
1383 case DEBUG_KIND_UNION:
1386 case DEBUG_KIND_ENUM:
1389 case DEBUG_KIND_CLASS:
1392 case DEBUG_KIND_UNION_CLASS:
1400 return (push_type (info, t)
1401 && append_type (info, name));
1404 /* Output a typedef. */
1411 struct pr_handle *info = (struct pr_handle *) p;
1414 if (! substitute_type (info, name))
1417 s = pop_type (info);
1422 fprintf (info->f, "typedef %s;\n", s);
1436 struct pr_handle *info = (struct pr_handle *) p;
1439 assert (info->stack != NULL);
1441 t = info->stack->type;
1443 s = strchr (t, '+');
1446 n = (char *) xmalloc (strlen (t) + strlen (name));
1448 memcpy (n, t, s - t);
1449 strcpy (n + (s - t), name);
1453 info->stack->type = n;
1455 t = pop_type (info);
1460 fprintf (info->f, "%s;\n", t);
1467 /* Output an integer constant. */
1470 pr_int_constant (p, name, val)
1475 struct pr_handle *info = (struct pr_handle *) info;
1479 print_vma (val, ab, false, false);
1480 fprintf (info->f, "const int %s = %s;\n", name, ab);
1484 /* Output a floating point constant. */
1487 pr_float_constant (p, name, val)
1492 struct pr_handle *info = (struct pr_handle *) info;
1495 fprintf (info->f, "const double %s = %g;\n", name, val);
1499 /* Output a typed constant. */
1502 pr_typed_constant (p, name, val)
1507 struct pr_handle *info = (struct pr_handle *) p;
1511 t = pop_type (info);
1516 print_vma (val, ab, false, false);
1517 fprintf (info->f, "const %s %s = %s;\n", t, name, ab);
1524 /* Output a variable. */
1527 pr_variable (p, name, kind, val)
1530 enum debug_var_kind kind;
1533 struct pr_handle *info = (struct pr_handle *) p;
1537 if (! substitute_type (info, name))
1540 t = pop_type (info);
1548 case DEBUG_LOCAL_STATIC:
1549 fprintf (info->f, "static ");
1551 case DEBUG_REGISTER:
1552 fprintf (info->f, "register ");
1557 print_vma (val, ab, true, true);
1558 fprintf (info->f, "%s /* %s */;\n", t, ab);
1565 /* Start outputting a function. */
1568 pr_start_function (p, name, global)
1573 struct pr_handle *info = (struct pr_handle *) p;
1576 if (! substitute_type (info, name))
1579 t = pop_type (info);
1585 fprintf (info->f, "static ");
1586 fprintf (info->f, "%s (", t);
1588 info->parameter = 1;
1593 /* Output a function parameter. */
1596 pr_function_parameter (p, name, kind, val)
1599 enum debug_parm_kind kind;
1602 struct pr_handle *info = (struct pr_handle *) p;
1606 if (kind == DEBUG_PARM_REFERENCE
1607 || kind == DEBUG_PARM_REF_REG)
1609 if (! pr_reference_type (p))
1613 if (! substitute_type (info, name))
1616 t = pop_type (info);
1620 if (info->parameter != 1)
1621 fprintf (info->f, ", ");
1623 if (kind == DEBUG_PARM_REG || kind == DEBUG_PARM_REF_REG)
1624 fprintf (info->f, "register ");
1626 print_vma (val, ab, true, true);
1627 fprintf (info->f, "%s /* %s */", t, ab);
1636 /* Start writing out a block. */
1639 pr_start_block (p, addr)
1643 struct pr_handle *info = (struct pr_handle *) p;
1646 if (info->parameter > 0)
1648 fprintf (info->f, ")\n");
1649 info->parameter = 0;
1653 print_vma (addr, ab, true, true);
1654 fprintf (info->f, "{ /* %s */\n", ab);
1661 /* Write out line number information. */
1664 pr_lineno (p, filename, lineno, addr)
1666 const char *filename;
1667 unsigned long lineno;
1670 struct pr_handle *info = (struct pr_handle *) p;
1674 print_vma (addr, ab, true, true);
1675 fprintf (info->f, "/* file %s line %lu addr %s */\n", filename, lineno, ab);
1680 /* Finish writing out a block. */
1683 pr_end_block (p, addr)
1687 struct pr_handle *info = (struct pr_handle *) p;
1693 print_vma (addr, ab, true, true);
1694 fprintf (info->f, "} /* %s */\n", ab);
1699 /* Finish writing out a function. */