Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* prdbg.c -- Print out generic debugging information. |
ed180cc5 | 2 | Copyright 1995, 1996, 1999, 2002, 2003, 2004, 2006, 2007 |
aef6203b | 3 | Free Software Foundation, Inc. |
252b5132 | 4 | Written by Ian Lance Taylor <ian@cygnus.com>. |
51cdc6e0 | 5 | Tags style generation written by Salvador E. Tropea <set@computer.org>. |
252b5132 RH |
6 | |
7 | This file is part of GNU Binutils. | |
8 | ||
9 | This program is free software; you can redistribute it and/or modify | |
10 | it under the terms of the GNU General Public License as published by | |
11 | the Free Software Foundation; either version 2 of the License, or | |
12 | (at your option) any later version. | |
13 | ||
14 | This program is distributed in the hope that it will be useful, | |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | GNU General Public License for more details. | |
18 | ||
19 | You should have received a copy of the GNU General Public License | |
20 | along with this program; if not, write to the Free Software | |
b43b5d5f NC |
21 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA |
22 | 02110-1301, USA. */ | |
252b5132 RH |
23 | |
24 | /* This file prints out the generic debugging information, by | |
25 | supplying a set of routines to debug_write. */ | |
26 | ||
27 | #include <stdio.h> | |
28 | #include <assert.h> | |
29 | ||
30 | #include "bfd.h" | |
31 | #include "bucomm.h" | |
32 | #include "libiberty.h" | |
ed180cc5 | 33 | #include "demangle.h" |
252b5132 RH |
34 | #include "debug.h" |
35 | #include "budbg.h" | |
36 | ||
37 | /* This is the structure we use as a handle for these routines. */ | |
38 | ||
39 | struct pr_handle | |
40 | { | |
41 | /* File to print information to. */ | |
42 | FILE *f; | |
43 | /* Current indentation level. */ | |
44 | unsigned int indent; | |
45 | /* Type stack. */ | |
46 | struct pr_stack *stack; | |
47 | /* Parameter number we are about to output. */ | |
48 | int parameter; | |
51cdc6e0 NC |
49 | /* The following are used only by the tags code (tg_). */ |
50 | /* Name of the file we are using. */ | |
51 | char *filename; | |
52 | /* The BFD. */ | |
53 | bfd *abfd; | |
54 | /* The symbols table for this BFD. */ | |
55 | asymbol **syms; | |
56 | /* Pointer to a function to demangle symbols. */ | |
ed180cc5 | 57 | char *(*demangler) (bfd *, const char *, int); |
252b5132 RH |
58 | }; |
59 | ||
60 | /* The type stack. */ | |
61 | ||
62 | struct pr_stack | |
63 | { | |
64 | /* Next element on the stack. */ | |
65 | struct pr_stack *next; | |
66 | /* This element. */ | |
67 | char *type; | |
68 | /* Current visibility of fields if this is a class. */ | |
69 | enum debug_visibility visibility; | |
70 | /* Name of the current method we are handling. */ | |
71 | const char *method; | |
51cdc6e0 NC |
72 | /* The following are used only by the tags code (tg_). */ |
73 | /* Type for the container (struct, union, class, union class). */ | |
74 | const char *flavor; | |
75 | /* A comma separated list of parent classes. */ | |
76 | char *parents; | |
77 | /* How many parents contains parents. */ | |
78 | int num_parents; | |
252b5132 RH |
79 | }; |
80 | ||
2da42df6 AJ |
81 | static void indent (struct pr_handle *); |
82 | static bfd_boolean push_type (struct pr_handle *, const char *); | |
83 | static bfd_boolean prepend_type (struct pr_handle *, const char *); | |
84 | static bfd_boolean append_type (struct pr_handle *, const char *); | |
85 | static bfd_boolean substitute_type (struct pr_handle *, const char *); | |
86 | static bfd_boolean indent_type (struct pr_handle *); | |
87 | static char *pop_type (struct pr_handle *); | |
88 | static void print_vma (bfd_vma, char *, bfd_boolean, bfd_boolean); | |
b34976b6 | 89 | static bfd_boolean pr_fix_visibility |
2da42df6 AJ |
90 | (struct pr_handle *, enum debug_visibility); |
91 | static bfd_boolean pr_start_compilation_unit (void *, const char *); | |
92 | static bfd_boolean pr_start_source (void *, const char *); | |
93 | static bfd_boolean pr_empty_type (void *); | |
94 | static bfd_boolean pr_void_type (void *); | |
95 | static bfd_boolean pr_int_type (void *, unsigned int, bfd_boolean); | |
96 | static bfd_boolean pr_float_type (void *, unsigned int); | |
97 | static bfd_boolean pr_complex_type (void *, unsigned int); | |
98 | static bfd_boolean pr_bool_type (void *, unsigned int); | |
b34976b6 | 99 | static bfd_boolean pr_enum_type |
2da42df6 AJ |
100 | (void *, const char *, const char **, bfd_signed_vma *); |
101 | static bfd_boolean pr_pointer_type (void *); | |
102 | static bfd_boolean pr_function_type (void *, int, bfd_boolean); | |
103 | static bfd_boolean pr_reference_type (void *); | |
104 | static bfd_boolean pr_range_type (void *, bfd_signed_vma, bfd_signed_vma); | |
b34976b6 | 105 | static bfd_boolean pr_array_type |
2da42df6 AJ |
106 | (void *, bfd_signed_vma, bfd_signed_vma, bfd_boolean); |
107 | static bfd_boolean pr_set_type (void *, bfd_boolean); | |
108 | static bfd_boolean pr_offset_type (void *); | |
109 | static bfd_boolean pr_method_type (void *, bfd_boolean, int, bfd_boolean); | |
110 | static bfd_boolean pr_const_type (void *); | |
111 | static bfd_boolean pr_volatile_type (void *); | |
b34976b6 | 112 | static bfd_boolean pr_start_struct_type |
2da42df6 | 113 | (void *, const char *, unsigned int, bfd_boolean, unsigned int); |
b34976b6 | 114 | static bfd_boolean pr_struct_field |
2da42df6 AJ |
115 | (void *, const char *, bfd_vma, bfd_vma, enum debug_visibility); |
116 | static bfd_boolean pr_end_struct_type (void *); | |
b34976b6 | 117 | static bfd_boolean pr_start_class_type |
2da42df6 AJ |
118 | (void *, const char *, unsigned int, bfd_boolean, unsigned int, |
119 | bfd_boolean, bfd_boolean); | |
b34976b6 | 120 | static bfd_boolean pr_class_static_member |
2da42df6 | 121 | (void *, const char *, const char *, enum debug_visibility); |
b34976b6 | 122 | static bfd_boolean pr_class_baseclass |
2da42df6 AJ |
123 | (void *, bfd_vma, bfd_boolean, enum debug_visibility); |
124 | static bfd_boolean pr_class_start_method (void *, const char *); | |
b34976b6 | 125 | static bfd_boolean pr_class_method_variant |
2da42df6 AJ |
126 | (void *, const char *, enum debug_visibility, bfd_boolean, bfd_boolean, |
127 | bfd_vma, bfd_boolean); | |
b34976b6 | 128 | static bfd_boolean pr_class_static_method_variant |
2da42df6 AJ |
129 | (void *, const char *, enum debug_visibility, bfd_boolean, bfd_boolean); |
130 | static bfd_boolean pr_class_end_method (void *); | |
131 | static bfd_boolean pr_end_class_type (void *); | |
132 | static bfd_boolean pr_typedef_type (void *, const char *); | |
b34976b6 | 133 | static bfd_boolean pr_tag_type |
2da42df6 AJ |
134 | (void *, const char *, unsigned int, enum debug_type_kind); |
135 | static bfd_boolean pr_typdef (void *, const char *); | |
136 | static bfd_boolean pr_tag (void *, const char *); | |
137 | static bfd_boolean pr_int_constant (void *, const char *, bfd_vma); | |
138 | static bfd_boolean pr_float_constant (void *, const char *, double); | |
139 | static bfd_boolean pr_typed_constant (void *, const char *, bfd_vma); | |
b34976b6 | 140 | static bfd_boolean pr_variable |
2da42df6 AJ |
141 | (void *, const char *, enum debug_var_kind, bfd_vma); |
142 | static bfd_boolean pr_start_function (void *, const char *, bfd_boolean); | |
b34976b6 | 143 | static bfd_boolean pr_function_parameter |
2da42df6 AJ |
144 | (void *, const char *, enum debug_parm_kind, bfd_vma); |
145 | static bfd_boolean pr_start_block (void *, bfd_vma); | |
146 | static bfd_boolean pr_end_block (void *, bfd_vma); | |
147 | static bfd_boolean pr_end_function (void *); | |
148 | static bfd_boolean pr_lineno (void *, const char *, unsigned long, bfd_vma); | |
51cdc6e0 NC |
149 | static bfd_boolean append_parent (struct pr_handle *, const char *); |
150 | /* Only used by tg_ code. */ | |
2da42df6 AJ |
151 | static bfd_boolean tg_fix_visibility |
152 | (struct pr_handle *, enum debug_visibility); | |
51cdc6e0 NC |
153 | static void find_address_in_section (bfd *, asection *, void *); |
154 | static void translate_addresses (bfd *, char *, FILE *, asymbol **); | |
155 | static const char *visibility_name (enum debug_visibility); | |
156 | /* Tags style replacements. */ | |
157 | static bfd_boolean tg_start_compilation_unit (void *, const char *); | |
158 | static bfd_boolean tg_start_source (void *, const char *); | |
2da42df6 AJ |
159 | static bfd_boolean tg_enum_type |
160 | (void *, const char *, const char **, bfd_signed_vma *); | |
161 | static bfd_boolean tg_start_struct_type | |
162 | (void *, const char *, unsigned int, bfd_boolean, unsigned int); | |
163 | static bfd_boolean pr_struct_field | |
164 | (void *, const char *, bfd_vma, bfd_vma, enum debug_visibility); | |
165 | static bfd_boolean tg_struct_field | |
166 | (void *, const char *, bfd_vma, bfd_vma, enum debug_visibility); | |
167 | static bfd_boolean tg_struct_field | |
168 | (void *, const char *, bfd_vma, bfd_vma, enum debug_visibility); | |
51cdc6e0 | 169 | static bfd_boolean tg_end_struct_type (void *); |
2da42df6 AJ |
170 | static bfd_boolean tg_start_class_type |
171 | (void *, const char *, unsigned int, bfd_boolean, unsigned int, bfd_boolean, bfd_boolean); | |
172 | static bfd_boolean tg_class_static_member | |
173 | (void *, const char *, const char *, enum debug_visibility); | |
174 | static bfd_boolean tg_class_baseclass | |
175 | (void *, bfd_vma, bfd_boolean, enum debug_visibility); | |
176 | static bfd_boolean tg_class_method_variant | |
177 | (void *, const char *, enum debug_visibility, bfd_boolean, bfd_boolean, bfd_vma, bfd_boolean); | |
178 | static bfd_boolean tg_class_static_method_variant | |
179 | (void *, const char *, enum debug_visibility, bfd_boolean, bfd_boolean); | |
51cdc6e0 | 180 | static bfd_boolean tg_end_class_type (void *); |
2da42df6 AJ |
181 | static bfd_boolean tg_tag_type |
182 | (void *, const char *, unsigned int, enum debug_type_kind); | |
51cdc6e0 NC |
183 | static bfd_boolean tg_typdef (void *, const char *); |
184 | static bfd_boolean tg_tag (void *, const char *); | |
185 | static bfd_boolean tg_int_constant (void *, const char *, bfd_vma); | |
186 | static bfd_boolean tg_float_constant (void *, const char *, double); | |
187 | static bfd_boolean tg_typed_constant (void *, const char *, bfd_vma); | |
2da42df6 AJ |
188 | static bfd_boolean tg_variable |
189 | (void *, const char *, enum debug_var_kind, bfd_vma); | |
51cdc6e0 | 190 | static bfd_boolean tg_start_function (void *, const char *, bfd_boolean); |
2da42df6 AJ |
191 | static bfd_boolean tg_function_parameter |
192 | (void *, const char *, enum debug_parm_kind, bfd_vma); | |
51cdc6e0 NC |
193 | static bfd_boolean tg_start_block (void *, bfd_vma); |
194 | static bfd_boolean tg_end_block (void *, bfd_vma); | |
195 | static bfd_boolean tg_lineno (void *, const char *, unsigned long, bfd_vma); | |
196 | \f | |
252b5132 RH |
197 | static const struct debug_write_fns pr_fns = |
198 | { | |
199 | pr_start_compilation_unit, | |
200 | pr_start_source, | |
201 | pr_empty_type, | |
202 | pr_void_type, | |
203 | pr_int_type, | |
204 | pr_float_type, | |
205 | pr_complex_type, | |
206 | pr_bool_type, | |
207 | pr_enum_type, | |
208 | pr_pointer_type, | |
209 | pr_function_type, | |
210 | pr_reference_type, | |
211 | pr_range_type, | |
212 | pr_array_type, | |
213 | pr_set_type, | |
214 | pr_offset_type, | |
215 | pr_method_type, | |
216 | pr_const_type, | |
217 | pr_volatile_type, | |
218 | pr_start_struct_type, | |
219 | pr_struct_field, | |
220 | pr_end_struct_type, | |
221 | pr_start_class_type, | |
222 | pr_class_static_member, | |
223 | pr_class_baseclass, | |
224 | pr_class_start_method, | |
225 | pr_class_method_variant, | |
226 | pr_class_static_method_variant, | |
227 | pr_class_end_method, | |
228 | pr_end_class_type, | |
229 | pr_typedef_type, | |
230 | pr_tag_type, | |
231 | pr_typdef, | |
232 | pr_tag, | |
233 | pr_int_constant, | |
234 | pr_float_constant, | |
235 | pr_typed_constant, | |
236 | pr_variable, | |
237 | pr_start_function, | |
238 | pr_function_parameter, | |
239 | pr_start_block, | |
240 | pr_end_block, | |
241 | pr_end_function, | |
242 | pr_lineno | |
243 | }; | |
244 | \f | |
51cdc6e0 NC |
245 | static const struct debug_write_fns tg_fns = |
246 | { | |
247 | tg_start_compilation_unit, | |
248 | tg_start_source, | |
249 | pr_empty_type, /* Same, push_type. */ | |
250 | pr_void_type, /* Same, push_type. */ | |
251 | pr_int_type, /* Same, push_type. */ | |
252 | pr_float_type, /* Same, push_type. */ | |
253 | pr_complex_type, /* Same, push_type. */ | |
254 | pr_bool_type, /* Same, push_type. */ | |
255 | tg_enum_type, | |
256 | pr_pointer_type, /* Same, changes to pointer. */ | |
257 | pr_function_type, /* Same, push_type. */ | |
258 | pr_reference_type, /* Same, changes to reference. */ | |
259 | pr_range_type, /* FIXME: What's that?. */ | |
260 | pr_array_type, /* Same, push_type. */ | |
261 | pr_set_type, /* FIXME: What's that?. */ | |
262 | pr_offset_type, /* FIXME: What's that?. */ | |
263 | pr_method_type, /* Same. */ | |
264 | pr_const_type, /* Same, changes to const. */ | |
265 | pr_volatile_type, /* Same, changes to volatile. */ | |
266 | tg_start_struct_type, | |
267 | tg_struct_field, | |
268 | tg_end_struct_type, | |
269 | tg_start_class_type, | |
270 | tg_class_static_member, | |
271 | tg_class_baseclass, | |
50c2245b | 272 | pr_class_start_method, /* Same, remembers that's a method. */ |
51cdc6e0 NC |
273 | tg_class_method_variant, |
274 | tg_class_static_method_variant, | |
275 | pr_class_end_method, /* Same, forgets that's a method. */ | |
276 | tg_end_class_type, | |
277 | pr_typedef_type, /* Same, just push type. */ | |
278 | tg_tag_type, | |
279 | tg_typdef, | |
280 | tg_tag, | |
281 | tg_int_constant, /* Untested. */ | |
282 | tg_float_constant, /* Untested. */ | |
283 | tg_typed_constant, /* Untested. */ | |
284 | tg_variable, | |
285 | tg_start_function, | |
286 | tg_function_parameter, | |
287 | tg_start_block, | |
288 | tg_end_block, | |
289 | pr_end_function, /* Same, does nothing. */ | |
290 | tg_lineno | |
291 | }; | |
292 | \f | |
252b5132 RH |
293 | /* Print out the generic debugging information recorded in dhandle. */ |
294 | ||
b34976b6 | 295 | bfd_boolean |
2da42df6 AJ |
296 | print_debugging_info (FILE *f, void *dhandle, bfd *abfd, asymbol **syms, |
297 | void *demangler, bfd_boolean as_tags) | |
252b5132 RH |
298 | { |
299 | struct pr_handle info; | |
300 | ||
301 | info.f = f; | |
302 | info.indent = 0; | |
303 | info.stack = NULL; | |
304 | info.parameter = 0; | |
51cdc6e0 NC |
305 | info.filename = NULL; |
306 | info.abfd = abfd; | |
307 | info.syms = syms; | |
308 | info.demangler = demangler; | |
309 | ||
310 | if (as_tags) | |
311 | { | |
312 | fputs ("!_TAG_FILE_FORMAT\t2\t/extended format/\n", f); | |
313 | fputs ("!_TAG_FILE_SORTED\t0\t/0=unsorted, 1=sorted/\n", f); | |
314 | fputs ("!_TAG_PROGRAM_AUTHOR\tIan Lance Taylor, Salvador E. Tropea and others\t//\n", f); | |
315 | fputs ("!_TAG_PROGRAM_NAME\tobjdump\t/From GNU binutils/\n", f); | |
316 | } | |
252b5132 | 317 | |
51cdc6e0 NC |
318 | return as_tags ? debug_write (dhandle, &tg_fns, (void *) & info) |
319 | : debug_write (dhandle, &pr_fns, (void *) & info); | |
252b5132 RH |
320 | } |
321 | \f | |
322 | /* Indent to the current indentation level. */ | |
323 | ||
324 | static void | |
2da42df6 | 325 | indent (struct pr_handle *info) |
252b5132 RH |
326 | { |
327 | unsigned int i; | |
328 | ||
329 | for (i = 0; i < info->indent; i++) | |
330 | putc (' ', info->f); | |
331 | } | |
332 | ||
333 | /* Push a type on the type stack. */ | |
334 | ||
b34976b6 | 335 | static bfd_boolean |
2da42df6 | 336 | push_type (struct pr_handle *info, const char *type) |
252b5132 RH |
337 | { |
338 | struct pr_stack *n; | |
339 | ||
340 | if (type == NULL) | |
b34976b6 | 341 | return FALSE; |
252b5132 RH |
342 | |
343 | n = (struct pr_stack *) xmalloc (sizeof *n); | |
344 | memset (n, 0, sizeof *n); | |
345 | ||
346 | n->type = xstrdup (type); | |
347 | n->visibility = DEBUG_VISIBILITY_IGNORE; | |
348 | n->method = NULL; | |
349 | n->next = info->stack; | |
350 | info->stack = n; | |
351 | ||
b34976b6 | 352 | return TRUE; |
252b5132 RH |
353 | } |
354 | ||
355 | /* Prepend a string onto the type on the top of the type stack. */ | |
356 | ||
b34976b6 | 357 | static bfd_boolean |
2da42df6 | 358 | prepend_type (struct pr_handle *info, const char *s) |
252b5132 RH |
359 | { |
360 | char *n; | |
361 | ||
362 | assert (info->stack != NULL); | |
363 | ||
364 | n = (char *) xmalloc (strlen (s) + strlen (info->stack->type) + 1); | |
365 | sprintf (n, "%s%s", s, info->stack->type); | |
366 | free (info->stack->type); | |
367 | info->stack->type = n; | |
368 | ||
b34976b6 | 369 | return TRUE; |
252b5132 RH |
370 | } |
371 | ||
372 | /* Append a string to the type on the top of the type stack. */ | |
373 | ||
b34976b6 | 374 | static bfd_boolean |
2da42df6 | 375 | append_type (struct pr_handle *info, const char *s) |
252b5132 RH |
376 | { |
377 | unsigned int len; | |
378 | ||
379 | if (s == NULL) | |
b34976b6 | 380 | return FALSE; |
252b5132 RH |
381 | |
382 | assert (info->stack != NULL); | |
383 | ||
384 | len = strlen (info->stack->type); | |
385 | info->stack->type = (char *) xrealloc (info->stack->type, | |
386 | len + strlen (s) + 1); | |
387 | strcpy (info->stack->type + len, s); | |
388 | ||
b34976b6 | 389 | return TRUE; |
252b5132 RH |
390 | } |
391 | ||
51cdc6e0 NC |
392 | /* Append a string to the parents on the top of the type stack. */ |
393 | ||
394 | static bfd_boolean | |
395 | append_parent (struct pr_handle *info, const char *s) | |
396 | { | |
397 | unsigned int len; | |
398 | ||
399 | if (s == NULL) | |
400 | return FALSE; | |
401 | ||
402 | assert (info->stack != NULL); | |
403 | ||
404 | len = info->stack->parents ? strlen (info->stack->parents) : 0; | |
405 | info->stack->parents = (char *) xrealloc (info->stack->parents, | |
406 | len + strlen (s) + 1); | |
407 | strcpy (info->stack->parents + len, s); | |
408 | ||
409 | return TRUE; | |
410 | } | |
411 | ||
252b5132 RH |
412 | /* We use an underscore to indicate where the name should go in a type |
413 | string. This function substitutes a string for the underscore. If | |
414 | there is no underscore, the name follows the type. */ | |
415 | ||
b34976b6 | 416 | static bfd_boolean |
2da42df6 | 417 | substitute_type (struct pr_handle *info, const char *s) |
252b5132 RH |
418 | { |
419 | char *u; | |
420 | ||
421 | assert (info->stack != NULL); | |
422 | ||
423 | u = strchr (info->stack->type, '|'); | |
424 | if (u != NULL) | |
425 | { | |
426 | char *n; | |
427 | ||
428 | n = (char *) xmalloc (strlen (info->stack->type) + strlen (s)); | |
429 | ||
430 | memcpy (n, info->stack->type, u - info->stack->type); | |
431 | strcpy (n + (u - info->stack->type), s); | |
432 | strcat (n, u + 1); | |
433 | ||
434 | free (info->stack->type); | |
435 | info->stack->type = n; | |
436 | ||
b34976b6 | 437 | return TRUE; |
252b5132 RH |
438 | } |
439 | ||
440 | if (strchr (s, '|') != NULL | |
441 | && (strchr (info->stack->type, '{') != NULL | |
442 | || strchr (info->stack->type, '(') != NULL)) | |
443 | { | |
444 | if (! prepend_type (info, "(") | |
445 | || ! append_type (info, ")")) | |
b34976b6 | 446 | return FALSE; |
252b5132 RH |
447 | } |
448 | ||
449 | if (*s == '\0') | |
b34976b6 | 450 | return TRUE; |
252b5132 RH |
451 | |
452 | return (append_type (info, " ") | |
453 | && append_type (info, s)); | |
454 | } | |
455 | ||
456 | /* Indent the type at the top of the stack by appending spaces. */ | |
457 | ||
b34976b6 | 458 | static bfd_boolean |
2da42df6 | 459 | indent_type (struct pr_handle *info) |
252b5132 RH |
460 | { |
461 | unsigned int i; | |
462 | ||
463 | for (i = 0; i < info->indent; i++) | |
464 | { | |
465 | if (! append_type (info, " ")) | |
b34976b6 | 466 | return FALSE; |
252b5132 RH |
467 | } |
468 | ||
b34976b6 | 469 | return TRUE; |
252b5132 RH |
470 | } |
471 | ||
472 | /* Pop a type from the type stack. */ | |
473 | ||
474 | static char * | |
2da42df6 | 475 | pop_type (struct pr_handle *info) |
252b5132 RH |
476 | { |
477 | struct pr_stack *o; | |
478 | char *ret; | |
479 | ||
480 | assert (info->stack != NULL); | |
481 | ||
482 | o = info->stack; | |
483 | info->stack = o->next; | |
484 | ret = o->type; | |
485 | free (o); | |
486 | ||
487 | return ret; | |
488 | } | |
489 | ||
490 | /* Print a VMA value into a string. */ | |
491 | ||
492 | static void | |
2da42df6 | 493 | print_vma (bfd_vma vma, char *buf, bfd_boolean unsignedp, bfd_boolean hexp) |
252b5132 RH |
494 | { |
495 | if (sizeof (vma) <= sizeof (unsigned long)) | |
496 | { | |
497 | if (hexp) | |
498 | sprintf (buf, "0x%lx", (unsigned long) vma); | |
499 | else if (unsignedp) | |
500 | sprintf (buf, "%lu", (unsigned long) vma); | |
501 | else | |
502 | sprintf (buf, "%ld", (long) vma); | |
503 | } | |
504 | else | |
505 | { | |
506 | buf[0] = '0'; | |
507 | buf[1] = 'x'; | |
508 | sprintf_vma (buf + 2, vma); | |
509 | } | |
510 | } | |
511 | \f | |
512 | /* Start a new compilation unit. */ | |
513 | ||
b34976b6 | 514 | static bfd_boolean |
2da42df6 | 515 | pr_start_compilation_unit (void *p, const char *filename) |
252b5132 RH |
516 | { |
517 | struct pr_handle *info = (struct pr_handle *) p; | |
518 | ||
519 | assert (info->indent == 0); | |
520 | ||
521 | fprintf (info->f, "%s:\n", filename); | |
522 | ||
b34976b6 | 523 | return TRUE; |
252b5132 RH |
524 | } |
525 | ||
526 | /* Start a source file within a compilation unit. */ | |
527 | ||
b34976b6 | 528 | static bfd_boolean |
2da42df6 | 529 | pr_start_source (void *p, const char *filename) |
252b5132 RH |
530 | { |
531 | struct pr_handle *info = (struct pr_handle *) p; | |
532 | ||
533 | assert (info->indent == 0); | |
534 | ||
535 | fprintf (info->f, " %s:\n", filename); | |
536 | ||
b34976b6 | 537 | return TRUE; |
252b5132 RH |
538 | } |
539 | ||
540 | /* Push an empty type onto the type stack. */ | |
541 | ||
b34976b6 | 542 | static bfd_boolean |
2da42df6 | 543 | pr_empty_type (void *p) |
252b5132 RH |
544 | { |
545 | struct pr_handle *info = (struct pr_handle *) p; | |
546 | ||
547 | return push_type (info, "<undefined>"); | |
548 | } | |
549 | ||
550 | /* Push a void type onto the type stack. */ | |
551 | ||
b34976b6 | 552 | static bfd_boolean |
2da42df6 | 553 | pr_void_type (void *p) |
252b5132 RH |
554 | { |
555 | struct pr_handle *info = (struct pr_handle *) p; | |
556 | ||
557 | return push_type (info, "void"); | |
558 | } | |
559 | ||
560 | /* Push an integer type onto the type stack. */ | |
561 | ||
b34976b6 | 562 | static bfd_boolean |
2da42df6 | 563 | pr_int_type (void *p, unsigned int size, bfd_boolean unsignedp) |
252b5132 RH |
564 | { |
565 | struct pr_handle *info = (struct pr_handle *) p; | |
566 | char ab[10]; | |
567 | ||
568 | sprintf (ab, "%sint%d", unsignedp ? "u" : "", size * 8); | |
569 | return push_type (info, ab); | |
570 | } | |
571 | ||
572 | /* Push a floating type onto the type stack. */ | |
573 | ||
b34976b6 | 574 | static bfd_boolean |
2da42df6 | 575 | pr_float_type (void *p, unsigned int size) |
252b5132 RH |
576 | { |
577 | struct pr_handle *info = (struct pr_handle *) p; | |
578 | char ab[10]; | |
579 | ||
580 | if (size == 4) | |
581 | return push_type (info, "float"); | |
582 | else if (size == 8) | |
583 | return push_type (info, "double"); | |
584 | ||
585 | sprintf (ab, "float%d", size * 8); | |
586 | return push_type (info, ab); | |
587 | } | |
588 | ||
589 | /* Push a complex type onto the type stack. */ | |
590 | ||
b34976b6 | 591 | static bfd_boolean |
2da42df6 | 592 | pr_complex_type (void *p, unsigned int size) |
252b5132 RH |
593 | { |
594 | struct pr_handle *info = (struct pr_handle *) p; | |
595 | ||
596 | if (! pr_float_type (p, size)) | |
b34976b6 | 597 | return FALSE; |
252b5132 RH |
598 | |
599 | return prepend_type (info, "complex "); | |
600 | } | |
601 | ||
b34976b6 | 602 | /* Push a bfd_boolean type onto the type stack. */ |
252b5132 | 603 | |
b34976b6 | 604 | static bfd_boolean |
2da42df6 | 605 | pr_bool_type (void *p, unsigned int size) |
252b5132 RH |
606 | { |
607 | struct pr_handle *info = (struct pr_handle *) p; | |
608 | char ab[10]; | |
609 | ||
610 | sprintf (ab, "bool%d", size * 8); | |
611 | ||
612 | return push_type (info, ab); | |
613 | } | |
614 | ||
615 | /* Push an enum type onto the type stack. */ | |
616 | ||
b34976b6 | 617 | static bfd_boolean |
2da42df6 AJ |
618 | pr_enum_type (void *p, const char *tag, const char **names, |
619 | bfd_signed_vma *values) | |
252b5132 RH |
620 | { |
621 | struct pr_handle *info = (struct pr_handle *) p; | |
622 | unsigned int i; | |
623 | bfd_signed_vma val; | |
624 | ||
625 | if (! push_type (info, "enum ")) | |
b34976b6 | 626 | return FALSE; |
252b5132 RH |
627 | if (tag != NULL) |
628 | { | |
629 | if (! append_type (info, tag) | |
630 | || ! append_type (info, " ")) | |
b34976b6 | 631 | return FALSE; |
252b5132 RH |
632 | } |
633 | if (! append_type (info, "{ ")) | |
b34976b6 | 634 | return FALSE; |
252b5132 RH |
635 | |
636 | if (names == NULL) | |
637 | { | |
638 | if (! append_type (info, "/* undefined */")) | |
b34976b6 | 639 | return FALSE; |
252b5132 RH |
640 | } |
641 | else | |
642 | { | |
643 | val = 0; | |
644 | for (i = 0; names[i] != NULL; i++) | |
645 | { | |
646 | if (i > 0) | |
647 | { | |
648 | if (! append_type (info, ", ")) | |
b34976b6 | 649 | return FALSE; |
252b5132 RH |
650 | } |
651 | ||
652 | if (! append_type (info, names[i])) | |
b34976b6 | 653 | return FALSE; |
252b5132 RH |
654 | |
655 | if (values[i] != val) | |
656 | { | |
657 | char ab[20]; | |
658 | ||
b34976b6 | 659 | print_vma (values[i], ab, FALSE, FALSE); |
252b5132 RH |
660 | if (! append_type (info, " = ") |
661 | || ! append_type (info, ab)) | |
b34976b6 | 662 | return FALSE; |
252b5132 RH |
663 | val = values[i]; |
664 | } | |
665 | ||
666 | ++val; | |
667 | } | |
668 | } | |
669 | ||
670 | return append_type (info, " }"); | |
671 | } | |
672 | ||
673 | /* Turn the top type on the stack into a pointer. */ | |
674 | ||
b34976b6 | 675 | static bfd_boolean |
2da42df6 | 676 | pr_pointer_type (void *p) |
252b5132 RH |
677 | { |
678 | struct pr_handle *info = (struct pr_handle *) p; | |
679 | char *s; | |
680 | ||
681 | assert (info->stack != NULL); | |
682 | ||
683 | s = strchr (info->stack->type, '|'); | |
684 | if (s != NULL && s[1] == '[') | |
685 | return substitute_type (info, "(*|)"); | |
686 | return substitute_type (info, "*|"); | |
687 | } | |
688 | ||
689 | /* Turn the top type on the stack into a function returning that type. */ | |
690 | ||
b34976b6 | 691 | static bfd_boolean |
2da42df6 | 692 | pr_function_type (void *p, int argcount, bfd_boolean varargs) |
252b5132 RH |
693 | { |
694 | struct pr_handle *info = (struct pr_handle *) p; | |
695 | char **arg_types; | |
696 | unsigned int len; | |
697 | char *s; | |
698 | ||
699 | assert (info->stack != NULL); | |
700 | ||
701 | len = 10; | |
702 | ||
703 | if (argcount <= 0) | |
704 | { | |
705 | arg_types = NULL; | |
706 | len += 15; | |
707 | } | |
708 | else | |
709 | { | |
710 | int i; | |
711 | ||
712 | arg_types = (char **) xmalloc (argcount * sizeof *arg_types); | |
713 | for (i = argcount - 1; i >= 0; i--) | |
714 | { | |
715 | if (! substitute_type (info, "")) | |
b34976b6 | 716 | return FALSE; |
252b5132 RH |
717 | arg_types[i] = pop_type (info); |
718 | if (arg_types[i] == NULL) | |
b34976b6 | 719 | return FALSE; |
252b5132 RH |
720 | len += strlen (arg_types[i]) + 2; |
721 | } | |
722 | if (varargs) | |
723 | len += 5; | |
724 | } | |
725 | ||
726 | /* Now the return type is on the top of the stack. */ | |
727 | ||
ea9986ff NC |
728 | s = xmalloc (len); |
729 | LITSTRCPY (s, "(|) ("); | |
252b5132 RH |
730 | |
731 | if (argcount < 0) | |
732 | strcat (s, "/* unknown */"); | |
733 | else | |
734 | { | |
735 | int i; | |
736 | ||
737 | for (i = 0; i < argcount; i++) | |
738 | { | |
739 | if (i > 0) | |
740 | strcat (s, ", "); | |
741 | strcat (s, arg_types[i]); | |
742 | } | |
743 | if (varargs) | |
744 | { | |
745 | if (i > 0) | |
746 | strcat (s, ", "); | |
747 | strcat (s, "..."); | |
748 | } | |
749 | if (argcount > 0) | |
750 | free (arg_types); | |
751 | } | |
752 | ||
753 | strcat (s, ")"); | |
754 | ||
755 | if (! substitute_type (info, s)) | |
b34976b6 | 756 | return FALSE; |
252b5132 RH |
757 | |
758 | free (s); | |
759 | ||
b34976b6 | 760 | return TRUE; |
252b5132 RH |
761 | } |
762 | ||
763 | /* Turn the top type on the stack into a reference to that type. */ | |
764 | ||
b34976b6 | 765 | static bfd_boolean |
2da42df6 | 766 | pr_reference_type (void *p) |
252b5132 RH |
767 | { |
768 | struct pr_handle *info = (struct pr_handle *) p; | |
769 | ||
770 | assert (info->stack != NULL); | |
771 | ||
772 | return substitute_type (info, "&|"); | |
773 | } | |
774 | ||
775 | /* Make a range type. */ | |
776 | ||
b34976b6 | 777 | static bfd_boolean |
2da42df6 | 778 | pr_range_type (void *p, bfd_signed_vma lower, bfd_signed_vma upper) |
252b5132 RH |
779 | { |
780 | struct pr_handle *info = (struct pr_handle *) p; | |
781 | char abl[20], abu[20]; | |
782 | ||
783 | assert (info->stack != NULL); | |
784 | ||
785 | if (! substitute_type (info, "")) | |
b34976b6 | 786 | return FALSE; |
252b5132 | 787 | |
b34976b6 AM |
788 | print_vma (lower, abl, FALSE, FALSE); |
789 | print_vma (upper, abu, FALSE, FALSE); | |
252b5132 RH |
790 | |
791 | return (prepend_type (info, "range (") | |
792 | && append_type (info, "):") | |
793 | && append_type (info, abl) | |
794 | && append_type (info, ":") | |
795 | && append_type (info, abu)); | |
796 | } | |
797 | ||
798 | /* Make an array type. */ | |
799 | ||
b34976b6 | 800 | static bfd_boolean |
2da42df6 AJ |
801 | pr_array_type (void *p, bfd_signed_vma lower, bfd_signed_vma upper, |
802 | bfd_boolean stringp) | |
252b5132 RH |
803 | { |
804 | struct pr_handle *info = (struct pr_handle *) p; | |
805 | char *range_type; | |
806 | char abl[20], abu[20], ab[50]; | |
807 | ||
808 | range_type = pop_type (info); | |
809 | if (range_type == NULL) | |
b34976b6 | 810 | return FALSE; |
252b5132 RH |
811 | |
812 | if (lower == 0) | |
813 | { | |
814 | if (upper == -1) | |
815 | sprintf (ab, "|[]"); | |
816 | else | |
817 | { | |
b34976b6 | 818 | print_vma (upper + 1, abu, FALSE, FALSE); |
252b5132 RH |
819 | sprintf (ab, "|[%s]", abu); |
820 | } | |
821 | } | |
822 | else | |
823 | { | |
b34976b6 AM |
824 | print_vma (lower, abl, FALSE, FALSE); |
825 | print_vma (upper, abu, FALSE, FALSE); | |
252b5132 RH |
826 | sprintf (ab, "|[%s:%s]", abl, abu); |
827 | } | |
828 | ||
829 | if (! substitute_type (info, ab)) | |
b34976b6 | 830 | return FALSE; |
252b5132 RH |
831 | |
832 | if (strcmp (range_type, "int") != 0) | |
833 | { | |
834 | if (! append_type (info, ":") | |
835 | || ! append_type (info, range_type)) | |
b34976b6 | 836 | return FALSE; |
252b5132 RH |
837 | } |
838 | ||
839 | if (stringp) | |
840 | { | |
841 | if (! append_type (info, " /* string */")) | |
b34976b6 | 842 | return FALSE; |
252b5132 RH |
843 | } |
844 | ||
b34976b6 | 845 | return TRUE; |
252b5132 RH |
846 | } |
847 | ||
848 | /* Make a set type. */ | |
849 | ||
b34976b6 | 850 | static bfd_boolean |
2da42df6 | 851 | pr_set_type (void *p, bfd_boolean bitstringp) |
252b5132 RH |
852 | { |
853 | struct pr_handle *info = (struct pr_handle *) p; | |
854 | ||
855 | if (! substitute_type (info, "")) | |
b34976b6 | 856 | return FALSE; |
252b5132 RH |
857 | |
858 | if (! prepend_type (info, "set { ") | |
859 | || ! append_type (info, " }")) | |
b34976b6 | 860 | return FALSE; |
252b5132 RH |
861 | |
862 | if (bitstringp) | |
863 | { | |
864 | if (! append_type (info, "/* bitstring */")) | |
b34976b6 | 865 | return FALSE; |
252b5132 RH |
866 | } |
867 | ||
b34976b6 | 868 | return TRUE; |
252b5132 RH |
869 | } |
870 | ||
871 | /* Make an offset type. */ | |
872 | ||
b34976b6 | 873 | static bfd_boolean |
2da42df6 | 874 | pr_offset_type (void *p) |
252b5132 RH |
875 | { |
876 | struct pr_handle *info = (struct pr_handle *) p; | |
877 | char *t; | |
878 | ||
879 | if (! substitute_type (info, "")) | |
b34976b6 | 880 | return FALSE; |
252b5132 RH |
881 | |
882 | t = pop_type (info); | |
883 | if (t == NULL) | |
b34976b6 | 884 | return FALSE; |
252b5132 RH |
885 | |
886 | return (substitute_type (info, "") | |
887 | && prepend_type (info, " ") | |
888 | && prepend_type (info, t) | |
889 | && append_type (info, "::|")); | |
890 | } | |
891 | ||
892 | /* Make a method type. */ | |
893 | ||
b34976b6 | 894 | static bfd_boolean |
2da42df6 | 895 | pr_method_type (void *p, bfd_boolean domain, int argcount, bfd_boolean varargs) |
252b5132 RH |
896 | { |
897 | struct pr_handle *info = (struct pr_handle *) p; | |
898 | unsigned int len; | |
899 | char *domain_type; | |
900 | char **arg_types; | |
901 | char *s; | |
902 | ||
903 | len = 10; | |
904 | ||
905 | if (! domain) | |
906 | domain_type = NULL; | |
907 | else | |
908 | { | |
909 | if (! substitute_type (info, "")) | |
b34976b6 | 910 | return FALSE; |
252b5132 RH |
911 | domain_type = pop_type (info); |
912 | if (domain_type == NULL) | |
b34976b6 | 913 | return FALSE; |
0112cd26 | 914 | if (CONST_STRNEQ (domain_type, "class ") |
252b5132 RH |
915 | && strchr (domain_type + sizeof "class " - 1, ' ') == NULL) |
916 | domain_type += sizeof "class " - 1; | |
0112cd26 | 917 | else if (CONST_STRNEQ (domain_type, "union class ") |
252b5132 RH |
918 | && (strchr (domain_type + sizeof "union class " - 1, ' ') |
919 | == NULL)) | |
920 | domain_type += sizeof "union class " - 1; | |
921 | len += strlen (domain_type); | |
922 | } | |
923 | ||
924 | if (argcount <= 0) | |
925 | { | |
926 | arg_types = NULL; | |
927 | len += 15; | |
928 | } | |
929 | else | |
930 | { | |
931 | int i; | |
932 | ||
933 | arg_types = (char **) xmalloc (argcount * sizeof *arg_types); | |
934 | for (i = argcount - 1; i >= 0; i--) | |
935 | { | |
936 | if (! substitute_type (info, "")) | |
b34976b6 | 937 | return FALSE; |
252b5132 RH |
938 | arg_types[i] = pop_type (info); |
939 | if (arg_types[i] == NULL) | |
b34976b6 | 940 | return FALSE; |
252b5132 RH |
941 | len += strlen (arg_types[i]) + 2; |
942 | } | |
943 | if (varargs) | |
944 | len += 5; | |
945 | } | |
946 | ||
947 | /* Now the return type is on the top of the stack. */ | |
948 | ||
949 | s = (char *) xmalloc (len); | |
950 | if (! domain) | |
951 | *s = '\0'; | |
952 | else | |
953 | strcpy (s, domain_type); | |
954 | strcat (s, "::| ("); | |
955 | ||
956 | if (argcount < 0) | |
957 | strcat (s, "/* unknown */"); | |
958 | else | |
959 | { | |
960 | int i; | |
961 | ||
962 | for (i = 0; i < argcount; i++) | |
963 | { | |
964 | if (i > 0) | |
965 | strcat (s, ", "); | |
966 | strcat (s, arg_types[i]); | |
967 | } | |
968 | if (varargs) | |
969 | { | |
970 | if (i > 0) | |
971 | strcat (s, ", "); | |
972 | strcat (s, "..."); | |
973 | } | |
974 | if (argcount > 0) | |
975 | free (arg_types); | |
976 | } | |
977 | ||
978 | strcat (s, ")"); | |
979 | ||
980 | if (! substitute_type (info, s)) | |
b34976b6 | 981 | return FALSE; |
252b5132 RH |
982 | |
983 | free (s); | |
984 | ||
b34976b6 | 985 | return TRUE; |
252b5132 RH |
986 | } |
987 | ||
988 | /* Make a const qualified type. */ | |
989 | ||
b34976b6 | 990 | static bfd_boolean |
2da42df6 | 991 | pr_const_type (void *p) |
252b5132 RH |
992 | { |
993 | struct pr_handle *info = (struct pr_handle *) p; | |
994 | ||
995 | return substitute_type (info, "const |"); | |
996 | } | |
997 | ||
998 | /* Make a volatile qualified type. */ | |
999 | ||
b34976b6 | 1000 | static bfd_boolean |
2da42df6 | 1001 | pr_volatile_type (void *p) |
252b5132 RH |
1002 | { |
1003 | struct pr_handle *info = (struct pr_handle *) p; | |
1004 | ||
1005 | return substitute_type (info, "volatile |"); | |
1006 | } | |
1007 | ||
1008 | /* Start accumulating a struct type. */ | |
1009 | ||
b34976b6 | 1010 | static bfd_boolean |
2da42df6 AJ |
1011 | pr_start_struct_type (void *p, const char *tag, unsigned int id, |
1012 | bfd_boolean structp, unsigned int size) | |
252b5132 RH |
1013 | { |
1014 | struct pr_handle *info = (struct pr_handle *) p; | |
1015 | ||
1016 | info->indent += 2; | |
1017 | ||
1018 | if (! push_type (info, structp ? "struct " : "union ")) | |
b34976b6 | 1019 | return FALSE; |
252b5132 RH |
1020 | if (tag != NULL) |
1021 | { | |
1022 | if (! append_type (info, tag)) | |
b34976b6 | 1023 | return FALSE; |
252b5132 RH |
1024 | } |
1025 | else | |
1026 | { | |
1027 | char idbuf[20]; | |
1028 | ||
1029 | sprintf (idbuf, "%%anon%u", id); | |
1030 | if (! append_type (info, idbuf)) | |
b34976b6 | 1031 | return FALSE; |
252b5132 RH |
1032 | } |
1033 | ||
1034 | if (! append_type (info, " {")) | |
b34976b6 | 1035 | return FALSE; |
252b5132 RH |
1036 | if (size != 0 || tag != NULL) |
1037 | { | |
1038 | char ab[30]; | |
1039 | ||
1040 | if (! append_type (info, " /*")) | |
b34976b6 | 1041 | return FALSE; |
252b5132 RH |
1042 | |
1043 | if (size != 0) | |
1044 | { | |
1045 | sprintf (ab, " size %u", size); | |
1046 | if (! append_type (info, ab)) | |
b34976b6 | 1047 | return FALSE; |
252b5132 RH |
1048 | } |
1049 | if (tag != NULL) | |
1050 | { | |
1051 | sprintf (ab, " id %u", id); | |
1052 | if (! append_type (info, ab)) | |
b34976b6 | 1053 | return FALSE; |
252b5132 RH |
1054 | } |
1055 | if (! append_type (info, " */")) | |
b34976b6 | 1056 | return FALSE; |
252b5132 RH |
1057 | } |
1058 | if (! append_type (info, "\n")) | |
b34976b6 | 1059 | return FALSE; |
252b5132 RH |
1060 | |
1061 | info->stack->visibility = DEBUG_VISIBILITY_PUBLIC; | |
1062 | ||
1063 | return indent_type (info); | |
1064 | } | |
1065 | ||
1066 | /* Output the visibility of a field in a struct. */ | |
1067 | ||
b34976b6 | 1068 | static bfd_boolean |
2da42df6 | 1069 | pr_fix_visibility (struct pr_handle *info, enum debug_visibility visibility) |
252b5132 | 1070 | { |
b4c96d0d | 1071 | const char *s = NULL; |
252b5132 RH |
1072 | char *t; |
1073 | unsigned int len; | |
1074 | ||
1075 | assert (info->stack != NULL); | |
1076 | ||
1077 | if (info->stack->visibility == visibility) | |
b34976b6 | 1078 | return TRUE; |
252b5132 | 1079 | |
252b5132 RH |
1080 | switch (visibility) |
1081 | { | |
1082 | case DEBUG_VISIBILITY_PUBLIC: | |
1083 | s = "public"; | |
1084 | break; | |
1085 | case DEBUG_VISIBILITY_PRIVATE: | |
1086 | s = "private"; | |
1087 | break; | |
1088 | case DEBUG_VISIBILITY_PROTECTED: | |
1089 | s = "protected"; | |
1090 | break; | |
1091 | case DEBUG_VISIBILITY_IGNORE: | |
1092 | s = "/* ignore */"; | |
1093 | break; | |
1094 | default: | |
1095 | abort (); | |
b34976b6 | 1096 | return FALSE; |
252b5132 RH |
1097 | } |
1098 | ||
1099 | /* Trim off a trailing space in the struct string, to make the | |
1100 | output look a bit better, then stick on the visibility string. */ | |
1101 | ||
1102 | t = info->stack->type; | |
1103 | len = strlen (t); | |
1104 | assert (t[len - 1] == ' '); | |
1105 | t[len - 1] = '\0'; | |
1106 | ||
1107 | if (! append_type (info, s) | |
1108 | || ! append_type (info, ":\n") | |
1109 | || ! indent_type (info)) | |
b34976b6 | 1110 | return FALSE; |
252b5132 RH |
1111 | |
1112 | info->stack->visibility = visibility; | |
1113 | ||
b34976b6 | 1114 | return TRUE; |
252b5132 RH |
1115 | } |
1116 | ||
1117 | /* Add a field to a struct type. */ | |
1118 | ||
b34976b6 | 1119 | static bfd_boolean |
2da42df6 AJ |
1120 | pr_struct_field (void *p, const char *name, bfd_vma bitpos, bfd_vma bitsize, |
1121 | enum debug_visibility visibility) | |
252b5132 RH |
1122 | { |
1123 | struct pr_handle *info = (struct pr_handle *) p; | |
1124 | char ab[20]; | |
1125 | char *t; | |
1126 | ||
1127 | if (! substitute_type (info, name)) | |
b34976b6 | 1128 | return FALSE; |
252b5132 RH |
1129 | |
1130 | if (! append_type (info, "; /* ")) | |
b34976b6 | 1131 | return FALSE; |
252b5132 RH |
1132 | |
1133 | if (bitsize != 0) | |
1134 | { | |
b34976b6 | 1135 | print_vma (bitsize, ab, TRUE, FALSE); |
252b5132 RH |
1136 | if (! append_type (info, "bitsize ") |
1137 | || ! append_type (info, ab) | |
1138 | || ! append_type (info, ", ")) | |
b34976b6 | 1139 | return FALSE; |
252b5132 RH |
1140 | } |
1141 | ||
b34976b6 | 1142 | print_vma (bitpos, ab, TRUE, FALSE); |
252b5132 RH |
1143 | if (! append_type (info, "bitpos ") |
1144 | || ! append_type (info, ab) | |
1145 | || ! append_type (info, " */\n") | |
1146 | || ! indent_type (info)) | |
b34976b6 | 1147 | return FALSE; |
252b5132 RH |
1148 | |
1149 | t = pop_type (info); | |
1150 | if (t == NULL) | |
b34976b6 | 1151 | return FALSE; |
252b5132 RH |
1152 | |
1153 | if (! pr_fix_visibility (info, visibility)) | |
b34976b6 | 1154 | return FALSE; |
252b5132 RH |
1155 | |
1156 | return append_type (info, t); | |
1157 | } | |
1158 | ||
1159 | /* Finish a struct type. */ | |
1160 | ||
b34976b6 | 1161 | static bfd_boolean |
2da42df6 | 1162 | pr_end_struct_type (void *p) |
252b5132 RH |
1163 | { |
1164 | struct pr_handle *info = (struct pr_handle *) p; | |
1165 | char *s; | |
1166 | ||
1167 | assert (info->stack != NULL); | |
1168 | assert (info->indent >= 2); | |
1169 | ||
1170 | info->indent -= 2; | |
1171 | ||
1172 | /* Change the trailing indentation to have a close brace. */ | |
1173 | s = info->stack->type + strlen (info->stack->type) - 2; | |
1174 | assert (s[0] == ' ' && s[1] == ' ' && s[2] == '\0'); | |
1175 | ||
1176 | *s++ = '}'; | |
1177 | *s = '\0'; | |
1178 | ||
b34976b6 | 1179 | return TRUE; |
252b5132 RH |
1180 | } |
1181 | ||
1182 | /* Start a class type. */ | |
1183 | ||
b34976b6 | 1184 | static bfd_boolean |
2da42df6 AJ |
1185 | pr_start_class_type (void *p, const char *tag, unsigned int id, |
1186 | bfd_boolean structp, unsigned int size, | |
1187 | bfd_boolean vptr, bfd_boolean ownvptr) | |
252b5132 RH |
1188 | { |
1189 | struct pr_handle *info = (struct pr_handle *) p; | |
1190 | char *tv = NULL; | |
1191 | ||
1192 | info->indent += 2; | |
1193 | ||
1194 | if (vptr && ! ownvptr) | |
1195 | { | |
1196 | tv = pop_type (info); | |
1197 | if (tv == NULL) | |
b34976b6 | 1198 | return FALSE; |
252b5132 RH |
1199 | } |
1200 | ||
1201 | if (! push_type (info, structp ? "class " : "union class ")) | |
b34976b6 | 1202 | return FALSE; |
252b5132 RH |
1203 | if (tag != NULL) |
1204 | { | |
1205 | if (! append_type (info, tag)) | |
b34976b6 | 1206 | return FALSE; |
252b5132 RH |
1207 | } |
1208 | else | |
1209 | { | |
1210 | char idbuf[20]; | |
1211 | ||
1212 | sprintf (idbuf, "%%anon%u", id); | |
1213 | if (! append_type (info, idbuf)) | |
b34976b6 | 1214 | return FALSE; |
252b5132 RH |
1215 | } |
1216 | ||
1217 | if (! append_type (info, " {")) | |
b34976b6 | 1218 | return FALSE; |
252b5132 RH |
1219 | if (size != 0 || vptr || ownvptr || tag != NULL) |
1220 | { | |
1221 | if (! append_type (info, " /*")) | |
b34976b6 | 1222 | return FALSE; |
252b5132 RH |
1223 | |
1224 | if (size != 0) | |
1225 | { | |
1226 | char ab[20]; | |
1227 | ||
1228 | sprintf (ab, "%u", size); | |
1229 | if (! append_type (info, " size ") | |
1230 | || ! append_type (info, ab)) | |
b34976b6 | 1231 | return FALSE; |
252b5132 RH |
1232 | } |
1233 | ||
1234 | if (vptr) | |
1235 | { | |
1236 | if (! append_type (info, " vtable ")) | |
b34976b6 | 1237 | return FALSE; |
252b5132 RH |
1238 | if (ownvptr) |
1239 | { | |
1240 | if (! append_type (info, "self ")) | |
b34976b6 | 1241 | return FALSE; |
252b5132 RH |
1242 | } |
1243 | else | |
1244 | { | |
1245 | if (! append_type (info, tv) | |
1246 | || ! append_type (info, " ")) | |
b34976b6 | 1247 | return FALSE; |
252b5132 RH |
1248 | } |
1249 | } | |
1250 | ||
1251 | if (tag != NULL) | |
1252 | { | |
1253 | char ab[30]; | |
1254 | ||
1255 | sprintf (ab, " id %u", id); | |
1256 | if (! append_type (info, ab)) | |
b34976b6 | 1257 | return FALSE; |
252b5132 RH |
1258 | } |
1259 | ||
1260 | if (! append_type (info, " */")) | |
b34976b6 | 1261 | return FALSE; |
252b5132 RH |
1262 | } |
1263 | ||
1264 | info->stack->visibility = DEBUG_VISIBILITY_PRIVATE; | |
1265 | ||
1266 | return (append_type (info, "\n") | |
1267 | && indent_type (info)); | |
1268 | } | |
1269 | ||
1270 | /* Add a static member to a class. */ | |
1271 | ||
b34976b6 | 1272 | static bfd_boolean |
2da42df6 AJ |
1273 | pr_class_static_member (void *p, const char *name, const char *physname, |
1274 | enum debug_visibility visibility) | |
252b5132 RH |
1275 | { |
1276 | struct pr_handle *info = (struct pr_handle *) p; | |
1277 | char *t; | |
1278 | ||
1279 | if (! substitute_type (info, name)) | |
b34976b6 | 1280 | return FALSE; |
252b5132 RH |
1281 | |
1282 | if (! prepend_type (info, "static ") | |
1283 | || ! append_type (info, "; /* ") | |
1284 | || ! append_type (info, physname) | |
1285 | || ! append_type (info, " */\n") | |
1286 | || ! indent_type (info)) | |
b34976b6 | 1287 | return FALSE; |
252b5132 RH |
1288 | |
1289 | t = pop_type (info); | |
1290 | if (t == NULL) | |
b34976b6 | 1291 | return FALSE; |
252b5132 RH |
1292 | |
1293 | if (! pr_fix_visibility (info, visibility)) | |
b34976b6 | 1294 | return FALSE; |
252b5132 RH |
1295 | |
1296 | return append_type (info, t); | |
1297 | } | |
1298 | ||
1299 | /* Add a base class to a class. */ | |
1300 | ||
b34976b6 | 1301 | static bfd_boolean |
2da42df6 AJ |
1302 | pr_class_baseclass (void *p, bfd_vma bitpos, bfd_boolean virtual, |
1303 | enum debug_visibility visibility) | |
252b5132 RH |
1304 | { |
1305 | struct pr_handle *info = (struct pr_handle *) p; | |
1306 | char *t; | |
1307 | const char *prefix; | |
1308 | char ab[20]; | |
1309 | char *s, *l, *n; | |
1310 | ||
1311 | assert (info->stack != NULL && info->stack->next != NULL); | |
1312 | ||
1313 | if (! substitute_type (info, "")) | |
b34976b6 | 1314 | return FALSE; |
252b5132 RH |
1315 | |
1316 | t = pop_type (info); | |
1317 | if (t == NULL) | |
b34976b6 | 1318 | return FALSE; |
252b5132 | 1319 | |
0112cd26 | 1320 | if (CONST_STRNEQ (t, "class ")) |
252b5132 RH |
1321 | t += sizeof "class " - 1; |
1322 | ||
1323 | /* Push it back on to take advantage of the prepend_type and | |
1324 | append_type routines. */ | |
1325 | if (! push_type (info, t)) | |
b34976b6 | 1326 | return FALSE; |
252b5132 RH |
1327 | |
1328 | if (virtual) | |
1329 | { | |
1330 | if (! prepend_type (info, "virtual ")) | |
b34976b6 | 1331 | return FALSE; |
252b5132 RH |
1332 | } |
1333 | ||
1334 | switch (visibility) | |
1335 | { | |
1336 | case DEBUG_VISIBILITY_PUBLIC: | |
1337 | prefix = "public "; | |
1338 | break; | |
1339 | case DEBUG_VISIBILITY_PROTECTED: | |
1340 | prefix = "protected "; | |
1341 | break; | |
1342 | case DEBUG_VISIBILITY_PRIVATE: | |
1343 | prefix = "private "; | |
1344 | break; | |
1345 | default: | |
1346 | prefix = "/* unknown visibility */ "; | |
1347 | break; | |
1348 | } | |
1349 | ||
1350 | if (! prepend_type (info, prefix)) | |
b34976b6 | 1351 | return FALSE; |
252b5132 RH |
1352 | |
1353 | if (bitpos != 0) | |
1354 | { | |
b34976b6 | 1355 | print_vma (bitpos, ab, TRUE, FALSE); |
252b5132 RH |
1356 | if (! append_type (info, " /* bitpos ") |
1357 | || ! append_type (info, ab) | |
1358 | || ! append_type (info, " */")) | |
b34976b6 | 1359 | return FALSE; |
252b5132 RH |
1360 | } |
1361 | ||
1362 | /* Now the top of the stack is something like "public A / * bitpos | |
1363 | 10 * /". The next element on the stack is something like "class | |
1364 | xx { / * size 8 * /\n...". We want to substitute the top of the | |
1365 | stack in before the {. */ | |
1366 | s = strchr (info->stack->next->type, '{'); | |
1367 | assert (s != NULL); | |
1368 | --s; | |
1369 | ||
1370 | /* If there is already a ':', then we already have a baseclass, and | |
1371 | we must append this one after a comma. */ | |
1372 | for (l = info->stack->next->type; l != s; l++) | |
1373 | if (*l == ':') | |
1374 | break; | |
1375 | if (! prepend_type (info, l == s ? " : " : ", ")) | |
b34976b6 | 1376 | return FALSE; |
252b5132 RH |
1377 | |
1378 | t = pop_type (info); | |
1379 | if (t == NULL) | |
b34976b6 | 1380 | return FALSE; |
252b5132 RH |
1381 | |
1382 | n = (char *) xmalloc (strlen (info->stack->type) + strlen (t) + 1); | |
1383 | memcpy (n, info->stack->type, s - info->stack->type); | |
1384 | strcpy (n + (s - info->stack->type), t); | |
1385 | strcat (n, s); | |
1386 | ||
1387 | free (info->stack->type); | |
1388 | info->stack->type = n; | |
1389 | ||
1390 | free (t); | |
1391 | ||
b34976b6 | 1392 | return TRUE; |
252b5132 RH |
1393 | } |
1394 | ||
1395 | /* Start adding a method to a class. */ | |
1396 | ||
b34976b6 | 1397 | static bfd_boolean |
2da42df6 | 1398 | pr_class_start_method (void *p, const char *name) |
252b5132 RH |
1399 | { |
1400 | struct pr_handle *info = (struct pr_handle *) p; | |
1401 | ||
1402 | assert (info->stack != NULL); | |
1403 | info->stack->method = name; | |
b34976b6 | 1404 | return TRUE; |
252b5132 RH |
1405 | } |
1406 | ||
1407 | /* Add a variant to a method. */ | |
1408 | ||
b34976b6 | 1409 | static bfd_boolean |
2da42df6 AJ |
1410 | pr_class_method_variant (void *p, const char *physname, |
1411 | enum debug_visibility visibility, | |
1412 | bfd_boolean constp, bfd_boolean volatilep, | |
1413 | bfd_vma voffset, bfd_boolean context) | |
252b5132 RH |
1414 | { |
1415 | struct pr_handle *info = (struct pr_handle *) p; | |
1416 | char *method_type; | |
1417 | char *context_type; | |
1418 | ||
1419 | assert (info->stack != NULL); | |
1420 | assert (info->stack->next != NULL); | |
1421 | ||
1422 | /* Put the const and volatile qualifiers on the type. */ | |
1423 | if (volatilep) | |
1424 | { | |
1425 | if (! append_type (info, " volatile")) | |
b34976b6 | 1426 | return FALSE; |
252b5132 RH |
1427 | } |
1428 | if (constp) | |
1429 | { | |
1430 | if (! append_type (info, " const")) | |
b34976b6 | 1431 | return FALSE; |
252b5132 RH |
1432 | } |
1433 | ||
1434 | /* Stick the name of the method into its type. */ | |
1435 | if (! substitute_type (info, | |
1436 | (context | |
1437 | ? info->stack->next->next->method | |
1438 | : info->stack->next->method))) | |
b34976b6 | 1439 | return FALSE; |
252b5132 RH |
1440 | |
1441 | /* Get the type. */ | |
1442 | method_type = pop_type (info); | |
1443 | if (method_type == NULL) | |
b34976b6 | 1444 | return FALSE; |
252b5132 RH |
1445 | |
1446 | /* Pull off the context type if there is one. */ | |
1447 | if (! context) | |
1448 | context_type = NULL; | |
1449 | else | |
1450 | { | |
1451 | context_type = pop_type (info); | |
1452 | if (context_type == NULL) | |
b34976b6 | 1453 | return FALSE; |
252b5132 RH |
1454 | } |
1455 | ||
1456 | /* Now the top of the stack is the class. */ | |
1457 | ||
1458 | if (! pr_fix_visibility (info, visibility)) | |
b34976b6 | 1459 | return FALSE; |
252b5132 RH |
1460 | |
1461 | if (! append_type (info, method_type) | |
1462 | || ! append_type (info, " /* ") | |
1463 | || ! append_type (info, physname) | |
1464 | || ! append_type (info, " ")) | |
b34976b6 | 1465 | return FALSE; |
252b5132 RH |
1466 | if (context || voffset != 0) |
1467 | { | |
1468 | char ab[20]; | |
1469 | ||
1470 | if (context) | |
1471 | { | |
1472 | if (! append_type (info, "context ") | |
1473 | || ! append_type (info, context_type) | |
1474 | || ! append_type (info, " ")) | |
b34976b6 | 1475 | return FALSE; |
252b5132 | 1476 | } |
b34976b6 | 1477 | print_vma (voffset, ab, TRUE, FALSE); |
252b5132 RH |
1478 | if (! append_type (info, "voffset ") |
1479 | || ! append_type (info, ab)) | |
b34976b6 | 1480 | return FALSE; |
252b5132 RH |
1481 | } |
1482 | ||
1483 | return (append_type (info, " */;\n") | |
1484 | && indent_type (info)); | |
1485 | } | |
1486 | ||
1487 | /* Add a static variant to a method. */ | |
1488 | ||
b34976b6 | 1489 | static bfd_boolean |
2da42df6 AJ |
1490 | pr_class_static_method_variant (void *p, const char *physname, |
1491 | enum debug_visibility visibility, | |
1492 | bfd_boolean constp, bfd_boolean volatilep) | |
252b5132 RH |
1493 | { |
1494 | struct pr_handle *info = (struct pr_handle *) p; | |
1495 | char *method_type; | |
1496 | ||
1497 | assert (info->stack != NULL); | |
1498 | assert (info->stack->next != NULL); | |
1499 | assert (info->stack->next->method != NULL); | |
1500 | ||
1501 | /* Put the const and volatile qualifiers on the type. */ | |
1502 | if (volatilep) | |
1503 | { | |
1504 | if (! append_type (info, " volatile")) | |
b34976b6 | 1505 | return FALSE; |
252b5132 RH |
1506 | } |
1507 | if (constp) | |
1508 | { | |
1509 | if (! append_type (info, " const")) | |
b34976b6 | 1510 | return FALSE; |
252b5132 RH |
1511 | } |
1512 | ||
1513 | /* Mark it as static. */ | |
1514 | if (! prepend_type (info, "static ")) | |
b34976b6 | 1515 | return FALSE; |
252b5132 RH |
1516 | |
1517 | /* Stick the name of the method into its type. */ | |
1518 | if (! substitute_type (info, info->stack->next->method)) | |
b34976b6 | 1519 | return FALSE; |
252b5132 RH |
1520 | |
1521 | /* Get the type. */ | |
1522 | method_type = pop_type (info); | |
1523 | if (method_type == NULL) | |
b34976b6 | 1524 | return FALSE; |
252b5132 RH |
1525 | |
1526 | /* Now the top of the stack is the class. */ | |
1527 | ||
1528 | if (! pr_fix_visibility (info, visibility)) | |
b34976b6 | 1529 | return FALSE; |
252b5132 RH |
1530 | |
1531 | return (append_type (info, method_type) | |
1532 | && append_type (info, " /* ") | |
1533 | && append_type (info, physname) | |
1534 | && append_type (info, " */;\n") | |
1535 | && indent_type (info)); | |
1536 | } | |
1537 | ||
1538 | /* Finish up a method. */ | |
1539 | ||
b34976b6 | 1540 | static bfd_boolean |
2da42df6 | 1541 | pr_class_end_method (void *p) |
252b5132 RH |
1542 | { |
1543 | struct pr_handle *info = (struct pr_handle *) p; | |
1544 | ||
1545 | info->stack->method = NULL; | |
b34976b6 | 1546 | return TRUE; |
252b5132 RH |
1547 | } |
1548 | ||
1549 | /* Finish up a class. */ | |
1550 | ||
b34976b6 | 1551 | static bfd_boolean |
2da42df6 | 1552 | pr_end_class_type (void *p) |
252b5132 RH |
1553 | { |
1554 | return pr_end_struct_type (p); | |
1555 | } | |
1556 | ||
1557 | /* Push a type on the stack using a typedef name. */ | |
1558 | ||
b34976b6 | 1559 | static bfd_boolean |
2da42df6 | 1560 | pr_typedef_type (void *p, const char *name) |
252b5132 RH |
1561 | { |
1562 | struct pr_handle *info = (struct pr_handle *) p; | |
1563 | ||
1564 | return push_type (info, name); | |
1565 | } | |
1566 | ||
1567 | /* Push a type on the stack using a tag name. */ | |
1568 | ||
b34976b6 | 1569 | static bfd_boolean |
2da42df6 AJ |
1570 | pr_tag_type (void *p, const char *name, unsigned int id, |
1571 | enum debug_type_kind kind) | |
252b5132 RH |
1572 | { |
1573 | struct pr_handle *info = (struct pr_handle *) p; | |
1574 | const char *t, *tag; | |
1575 | char idbuf[20]; | |
1576 | ||
1577 | switch (kind) | |
1578 | { | |
1579 | case DEBUG_KIND_STRUCT: | |
1580 | t = "struct "; | |
1581 | break; | |
1582 | case DEBUG_KIND_UNION: | |
1583 | t = "union "; | |
1584 | break; | |
1585 | case DEBUG_KIND_ENUM: | |
1586 | t = "enum "; | |
1587 | break; | |
1588 | case DEBUG_KIND_CLASS: | |
1589 | t = "class "; | |
1590 | break; | |
1591 | case DEBUG_KIND_UNION_CLASS: | |
1592 | t = "union class "; | |
1593 | break; | |
1594 | default: | |
1595 | abort (); | |
b34976b6 | 1596 | return FALSE; |
252b5132 RH |
1597 | } |
1598 | ||
1599 | if (! push_type (info, t)) | |
b34976b6 | 1600 | return FALSE; |
252b5132 RH |
1601 | if (name != NULL) |
1602 | tag = name; | |
1603 | else | |
1604 | { | |
1605 | sprintf (idbuf, "%%anon%u", id); | |
1606 | tag = idbuf; | |
1607 | } | |
1608 | ||
1609 | if (! append_type (info, tag)) | |
b34976b6 | 1610 | return FALSE; |
252b5132 RH |
1611 | if (name != NULL && kind != DEBUG_KIND_ENUM) |
1612 | { | |
1613 | sprintf (idbuf, " /* id %u */", id); | |
1614 | if (! append_type (info, idbuf)) | |
b34976b6 | 1615 | return FALSE; |
252b5132 RH |
1616 | } |
1617 | ||
b34976b6 | 1618 | return TRUE; |
252b5132 RH |
1619 | } |
1620 | ||
1621 | /* Output a typedef. */ | |
1622 | ||
b34976b6 | 1623 | static bfd_boolean |
2da42df6 | 1624 | pr_typdef (void *p, const char *name) |
252b5132 RH |
1625 | { |
1626 | struct pr_handle *info = (struct pr_handle *) p; | |
1627 | char *s; | |
1628 | ||
1629 | if (! substitute_type (info, name)) | |
b34976b6 | 1630 | return FALSE; |
252b5132 RH |
1631 | |
1632 | s = pop_type (info); | |
1633 | if (s == NULL) | |
b34976b6 | 1634 | return FALSE; |
252b5132 RH |
1635 | |
1636 | indent (info); | |
1637 | fprintf (info->f, "typedef %s;\n", s); | |
1638 | ||
1639 | free (s); | |
1640 | ||
b34976b6 | 1641 | return TRUE; |
252b5132 RH |
1642 | } |
1643 | ||
1644 | /* Output a tag. The tag should already be in the string on the | |
1645 | stack, so all we have to do here is print it out. */ | |
1646 | ||
b34976b6 | 1647 | static bfd_boolean |
2da42df6 | 1648 | pr_tag (void *p, const char *name ATTRIBUTE_UNUSED) |
252b5132 RH |
1649 | { |
1650 | struct pr_handle *info = (struct pr_handle *) p; | |
1651 | char *t; | |
1652 | ||
1653 | t = pop_type (info); | |
1654 | if (t == NULL) | |
b34976b6 | 1655 | return FALSE; |
252b5132 RH |
1656 | |
1657 | indent (info); | |
1658 | fprintf (info->f, "%s;\n", t); | |
1659 | ||
1660 | free (t); | |
1661 | ||
b34976b6 | 1662 | return TRUE; |
252b5132 RH |
1663 | } |
1664 | ||
1665 | /* Output an integer constant. */ | |
1666 | ||
b34976b6 | 1667 | static bfd_boolean |
2da42df6 | 1668 | pr_int_constant (void *p, const char *name, bfd_vma val) |
252b5132 RH |
1669 | { |
1670 | struct pr_handle *info = (struct pr_handle *) p; | |
1671 | char ab[20]; | |
1672 | ||
1673 | indent (info); | |
b34976b6 | 1674 | print_vma (val, ab, FALSE, FALSE); |
252b5132 | 1675 | fprintf (info->f, "const int %s = %s;\n", name, ab); |
b34976b6 | 1676 | return TRUE; |
252b5132 RH |
1677 | } |
1678 | ||
1679 | /* Output a floating point constant. */ | |
1680 | ||
b34976b6 | 1681 | static bfd_boolean |
2da42df6 | 1682 | pr_float_constant (void *p, const char *name, double val) |
252b5132 RH |
1683 | { |
1684 | struct pr_handle *info = (struct pr_handle *) p; | |
1685 | ||
1686 | indent (info); | |
1687 | fprintf (info->f, "const double %s = %g;\n", name, val); | |
b34976b6 | 1688 | return TRUE; |
252b5132 RH |
1689 | } |
1690 | ||
1691 | /* Output a typed constant. */ | |
1692 | ||
b34976b6 | 1693 | static bfd_boolean |
2da42df6 | 1694 | pr_typed_constant (void *p, const char *name, bfd_vma val) |
252b5132 RH |
1695 | { |
1696 | struct pr_handle *info = (struct pr_handle *) p; | |
1697 | char *t; | |
1698 | char ab[20]; | |
1699 | ||
1700 | t = pop_type (info); | |
1701 | if (t == NULL) | |
b34976b6 | 1702 | return FALSE; |
252b5132 RH |
1703 | |
1704 | indent (info); | |
b34976b6 | 1705 | print_vma (val, ab, FALSE, FALSE); |
252b5132 RH |
1706 | fprintf (info->f, "const %s %s = %s;\n", t, name, ab); |
1707 | ||
1708 | free (t); | |
1709 | ||
b34976b6 | 1710 | return TRUE; |
252b5132 RH |
1711 | } |
1712 | ||
1713 | /* Output a variable. */ | |
1714 | ||
b34976b6 | 1715 | static bfd_boolean |
2da42df6 AJ |
1716 | pr_variable (void *p, const char *name, enum debug_var_kind kind, |
1717 | bfd_vma val) | |
252b5132 RH |
1718 | { |
1719 | struct pr_handle *info = (struct pr_handle *) p; | |
1720 | char *t; | |
1721 | char ab[20]; | |
1722 | ||
1723 | if (! substitute_type (info, name)) | |
b34976b6 | 1724 | return FALSE; |
252b5132 RH |
1725 | |
1726 | t = pop_type (info); | |
1727 | if (t == NULL) | |
b34976b6 | 1728 | return FALSE; |
252b5132 RH |
1729 | |
1730 | indent (info); | |
1731 | switch (kind) | |
1732 | { | |
1733 | case DEBUG_STATIC: | |
1734 | case DEBUG_LOCAL_STATIC: | |
1735 | fprintf (info->f, "static "); | |
1736 | break; | |
1737 | case DEBUG_REGISTER: | |
1738 | fprintf (info->f, "register "); | |
1739 | break; | |
1740 | default: | |
1741 | break; | |
1742 | } | |
b34976b6 | 1743 | print_vma (val, ab, TRUE, TRUE); |
252b5132 RH |
1744 | fprintf (info->f, "%s /* %s */;\n", t, ab); |
1745 | ||
1746 | free (t); | |
1747 | ||
b34976b6 | 1748 | return TRUE; |
252b5132 RH |
1749 | } |
1750 | ||
1751 | /* Start outputting a function. */ | |
1752 | ||
b34976b6 | 1753 | static bfd_boolean |
2da42df6 | 1754 | pr_start_function (void *p, const char *name, bfd_boolean global) |
252b5132 RH |
1755 | { |
1756 | struct pr_handle *info = (struct pr_handle *) p; | |
1757 | char *t; | |
1758 | ||
1759 | if (! substitute_type (info, name)) | |
b34976b6 | 1760 | return FALSE; |
252b5132 RH |
1761 | |
1762 | t = pop_type (info); | |
1763 | if (t == NULL) | |
b34976b6 | 1764 | return FALSE; |
252b5132 RH |
1765 | |
1766 | indent (info); | |
1767 | if (! global) | |
1768 | fprintf (info->f, "static "); | |
1769 | fprintf (info->f, "%s (", t); | |
1770 | ||
1771 | info->parameter = 1; | |
1772 | ||
b34976b6 | 1773 | return TRUE; |
252b5132 RH |
1774 | } |
1775 | ||
1776 | /* Output a function parameter. */ | |
1777 | ||
b34976b6 | 1778 | static bfd_boolean |
2da42df6 AJ |
1779 | pr_function_parameter (void *p, const char *name, |
1780 | enum debug_parm_kind kind, bfd_vma val) | |
252b5132 RH |
1781 | { |
1782 | struct pr_handle *info = (struct pr_handle *) p; | |
1783 | char *t; | |
1784 | char ab[20]; | |
1785 | ||
1786 | if (kind == DEBUG_PARM_REFERENCE | |
1787 | || kind == DEBUG_PARM_REF_REG) | |
1788 | { | |
1789 | if (! pr_reference_type (p)) | |
b34976b6 | 1790 | return FALSE; |
252b5132 RH |
1791 | } |
1792 | ||
1793 | if (! substitute_type (info, name)) | |
b34976b6 | 1794 | return FALSE; |
252b5132 RH |
1795 | |
1796 | t = pop_type (info); | |
1797 | if (t == NULL) | |
b34976b6 | 1798 | return FALSE; |
252b5132 RH |
1799 | |
1800 | if (info->parameter != 1) | |
1801 | fprintf (info->f, ", "); | |
1802 | ||
1803 | if (kind == DEBUG_PARM_REG || kind == DEBUG_PARM_REF_REG) | |
1804 | fprintf (info->f, "register "); | |
1805 | ||
b34976b6 | 1806 | print_vma (val, ab, TRUE, TRUE); |
252b5132 RH |
1807 | fprintf (info->f, "%s /* %s */", t, ab); |
1808 | ||
1809 | free (t); | |
1810 | ||
1811 | ++info->parameter; | |
1812 | ||
b34976b6 | 1813 | return TRUE; |
252b5132 RH |
1814 | } |
1815 | ||
1816 | /* Start writing out a block. */ | |
1817 | ||
b34976b6 | 1818 | static bfd_boolean |
2da42df6 | 1819 | pr_start_block (void *p, bfd_vma addr) |
252b5132 RH |
1820 | { |
1821 | struct pr_handle *info = (struct pr_handle *) p; | |
1822 | char ab[20]; | |
1823 | ||
1824 | if (info->parameter > 0) | |
1825 | { | |
1826 | fprintf (info->f, ")\n"); | |
1827 | info->parameter = 0; | |
1828 | } | |
1829 | ||
1830 | indent (info); | |
b34976b6 | 1831 | print_vma (addr, ab, TRUE, TRUE); |
252b5132 RH |
1832 | fprintf (info->f, "{ /* %s */\n", ab); |
1833 | ||
1834 | info->indent += 2; | |
1835 | ||
b34976b6 | 1836 | return TRUE; |
252b5132 RH |
1837 | } |
1838 | ||
1839 | /* Write out line number information. */ | |
1840 | ||
b34976b6 | 1841 | static bfd_boolean |
2da42df6 | 1842 | pr_lineno (void *p, const char *filename, unsigned long lineno, bfd_vma addr) |
252b5132 RH |
1843 | { |
1844 | struct pr_handle *info = (struct pr_handle *) p; | |
1845 | char ab[20]; | |
1846 | ||
1847 | indent (info); | |
b34976b6 | 1848 | print_vma (addr, ab, TRUE, TRUE); |
252b5132 RH |
1849 | fprintf (info->f, "/* file %s line %lu addr %s */\n", filename, lineno, ab); |
1850 | ||
b34976b6 | 1851 | return TRUE; |
252b5132 RH |
1852 | } |
1853 | ||
1854 | /* Finish writing out a block. */ | |
1855 | ||
b34976b6 | 1856 | static bfd_boolean |
2da42df6 | 1857 | pr_end_block (void *p, bfd_vma addr) |
252b5132 RH |
1858 | { |
1859 | struct pr_handle *info = (struct pr_handle *) p; | |
1860 | char ab[20]; | |
1861 | ||
1862 | info->indent -= 2; | |
1863 | ||
1864 | indent (info); | |
b34976b6 | 1865 | print_vma (addr, ab, TRUE, TRUE); |
252b5132 RH |
1866 | fprintf (info->f, "} /* %s */\n", ab); |
1867 | ||
b34976b6 | 1868 | return TRUE; |
252b5132 RH |
1869 | } |
1870 | ||
1871 | /* Finish writing out a function. */ | |
1872 | ||
b34976b6 | 1873 | static bfd_boolean |
2da42df6 | 1874 | pr_end_function (void *p ATTRIBUTE_UNUSED) |
252b5132 | 1875 | { |
b34976b6 | 1876 | return TRUE; |
252b5132 | 1877 | } |
51cdc6e0 NC |
1878 | \f |
1879 | /* Tags style generation functions start here. */ | |
1880 | ||
1881 | /* Variables for address to line translation. */ | |
1882 | static bfd_vma pc; | |
1883 | static const char *filename; | |
1884 | static const char *functionname; | |
1885 | static unsigned int line; | |
1886 | static bfd_boolean found; | |
1887 | ||
1888 | /* Look for an address in a section. This is called via | |
1889 | bfd_map_over_sections. */ | |
1890 | ||
1891 | static void | |
1892 | find_address_in_section (bfd *abfd, asection *section, void *data) | |
1893 | { | |
1894 | bfd_vma vma; | |
1895 | bfd_size_type size; | |
1896 | asymbol **syms = (asymbol **) data; | |
1897 | ||
1898 | if (found) | |
1899 | return; | |
1900 | ||
1901 | if ((bfd_get_section_flags (abfd, section) & SEC_ALLOC) == 0) | |
1902 | return; | |
1903 | ||
1904 | vma = bfd_get_section_vma (abfd, section); | |
1905 | if (pc < vma) | |
1906 | return; | |
1907 | ||
135dfb4a | 1908 | size = bfd_get_section_size (section); |
51cdc6e0 NC |
1909 | if (pc >= vma + size) |
1910 | return; | |
1911 | ||
1912 | found = bfd_find_nearest_line (abfd, section, syms, pc - vma, | |
1913 | &filename, &functionname, &line); | |
1914 | } | |
1915 | ||
1916 | static void | |
1917 | translate_addresses (bfd *abfd, char *addr_hex, FILE *f, asymbol **syms) | |
1918 | { | |
1919 | pc = bfd_scan_vma (addr_hex, NULL, 16); | |
1920 | found = FALSE; | |
1921 | bfd_map_over_sections (abfd, find_address_in_section, syms); | |
1922 | ||
1923 | if (! found) | |
1924 | fprintf (f, "??"); | |
1925 | else | |
1926 | fprintf (f, "%u", line); | |
1927 | } | |
1928 | ||
1929 | /* Start a new compilation unit. */ | |
1930 | ||
1931 | static bfd_boolean | |
1932 | tg_start_compilation_unit (void * p, const char *filename ATTRIBUTE_UNUSED) | |
1933 | { | |
1934 | struct pr_handle *info = (struct pr_handle *) p; | |
1935 | ||
1936 | fprintf (stderr, "New compilation unit: %s\n", filename); | |
1937 | ||
1938 | free (info->filename); | |
1939 | /* Should it be relative? best way to do it here?. */ | |
1940 | info->filename = strdup (filename); | |
1941 | ||
1942 | return TRUE; | |
1943 | } | |
1944 | ||
1945 | /* Start a source file within a compilation unit. */ | |
1946 | ||
1947 | static bfd_boolean | |
1948 | tg_start_source (void *p, const char *filename) | |
1949 | { | |
1950 | struct pr_handle *info = (struct pr_handle *) p; | |
1951 | ||
1952 | free (info->filename); | |
1953 | /* Should it be relative? best way to do it here?. */ | |
1954 | info->filename = strdup (filename); | |
1955 | ||
1956 | return TRUE; | |
1957 | } | |
1958 | ||
1959 | /* Push an enum type onto the type stack. */ | |
1960 | ||
1961 | static bfd_boolean | |
1962 | tg_enum_type (void *p, const char *tag, const char **names, | |
1963 | bfd_signed_vma *values) | |
1964 | { | |
1965 | struct pr_handle *info = (struct pr_handle *) p; | |
1966 | unsigned int i; | |
1967 | const char *name; | |
1968 | char ab[20]; | |
1969 | ||
1970 | if (! pr_enum_type (p, tag, names, values)) | |
1971 | return FALSE; | |
1972 | ||
1973 | name = tag ? tag : "unknown"; | |
1974 | /* Generate an entry for the enum. */ | |
1975 | if (tag) | |
1976 | fprintf (info->f, "%s\t%s\t0;\"\tkind:e\ttype:%s\n", tag, | |
1977 | info->filename, info->stack->type); | |
1978 | ||
1979 | /* Generate entries for the values. */ | |
1980 | if (names != NULL) | |
1981 | { | |
1982 | for (i = 0; names[i] != NULL; i++) | |
1983 | { | |
1984 | print_vma (values[i], ab, FALSE, FALSE); | |
1985 | fprintf (info->f, "%s\t%s\t0;\"\tkind:g\tenum:%s\tvalue:%s\n", | |
1986 | names[i], info->filename, name, ab); | |
1987 | } | |
1988 | } | |
1989 | ||
1990 | return TRUE; | |
1991 | } | |
1992 | ||
1993 | /* Start accumulating a struct type. */ | |
1994 | ||
1995 | static bfd_boolean | |
1996 | tg_start_struct_type (void *p, const char *tag, unsigned int id, | |
2da42df6 AJ |
1997 | bfd_boolean structp, |
1998 | unsigned int size ATTRIBUTE_UNUSED) | |
51cdc6e0 NC |
1999 | { |
2000 | struct pr_handle *info = (struct pr_handle *) p; | |
2001 | const char *name; | |
2002 | char idbuf[20]; | |
2003 | ||
2004 | if (tag != NULL) | |
2005 | name = tag; | |
2006 | else | |
2007 | { | |
2008 | name = idbuf; | |
2009 | sprintf (idbuf, "%%anon%u", id); | |
2010 | } | |
2011 | ||
2012 | if (! push_type (info, name)) | |
2013 | return FALSE; | |
2014 | ||
2015 | info->stack->flavor = structp ? "struct" : "union"; | |
2016 | ||
2017 | fprintf (info->f, "%s\t%s\t0;\"\tkind:%c\n", name, info->filename, | |
2018 | info->stack->flavor[0]); | |
2019 | ||
2020 | info->stack->visibility = DEBUG_VISIBILITY_PUBLIC; | |
2021 | ||
2022 | return indent_type (info); | |
2023 | } | |
2024 | ||
2025 | /* Output the visibility of a field in a struct. */ | |
2026 | ||
2027 | static bfd_boolean | |
2028 | tg_fix_visibility (struct pr_handle *info, enum debug_visibility visibility) | |
2029 | { | |
2030 | assert (info->stack != NULL); | |
2031 | ||
2032 | if (info->stack->visibility == visibility) | |
2033 | return TRUE; | |
2034 | ||
2035 | assert (info->stack->visibility != DEBUG_VISIBILITY_IGNORE); | |
2036 | ||
2037 | info->stack->visibility = visibility; | |
2038 | ||
2039 | return TRUE; | |
2040 | } | |
2041 | ||
2042 | /* Add a field to a struct type. */ | |
2043 | ||
2044 | static bfd_boolean | |
2045 | tg_struct_field (void *p, const char *name, bfd_vma bitpos ATTRIBUTE_UNUSED, | |
2046 | bfd_vma bitsize ATTRIBUTE_UNUSED, | |
2047 | enum debug_visibility visibility) | |
2048 | { | |
2049 | struct pr_handle *info = (struct pr_handle *) p; | |
2050 | char *t; | |
2051 | ||
2052 | t = pop_type (info); | |
2053 | if (t == NULL) | |
2054 | return FALSE; | |
2055 | ||
2056 | if (! tg_fix_visibility (info, visibility)) | |
2057 | return FALSE; | |
2058 | ||
aaad4cf3 | 2059 | /* It happens, a bug? */ |
51cdc6e0 NC |
2060 | if (! name[0]) |
2061 | return TRUE; | |
2062 | ||
2063 | fprintf (info->f, "%s\t%s\t0;\"\tkind:m\ttype:%s\t%s:%s\taccess:%s\n", | |
2064 | name, info->filename, t, info->stack->flavor, info->stack->type, | |
2065 | visibility_name (visibility)); | |
2066 | ||
2067 | return TRUE; | |
2068 | } | |
2069 | ||
2070 | /* Finish a struct type. */ | |
2071 | ||
2072 | static bfd_boolean | |
2073 | tg_end_struct_type (void *p ATTRIBUTE_UNUSED) | |
2074 | { | |
2075 | struct pr_handle *info = (struct pr_handle *) p; | |
2076 | assert (info->stack != NULL); | |
2077 | ||
2078 | return TRUE; | |
2079 | } | |
2080 | ||
2081 | /* Start a class type. */ | |
2082 | ||
2083 | static bfd_boolean | |
2084 | tg_start_class_type (void *p, const char *tag, unsigned int id, | |
2085 | bfd_boolean structp, unsigned int size, | |
2086 | bfd_boolean vptr, bfd_boolean ownvptr) | |
2087 | { | |
2088 | struct pr_handle *info = (struct pr_handle *) p; | |
2089 | char *tv = NULL; | |
2090 | const char *name; | |
2091 | ||
2092 | info->indent += 2; | |
2093 | ||
2094 | if (vptr && ! ownvptr) | |
2095 | { | |
2096 | tv = pop_type (info); | |
2097 | if (tv == NULL) | |
2098 | return FALSE; | |
2099 | } | |
2100 | ||
2101 | if (tag != NULL) | |
2102 | name = tag; | |
2103 | else | |
2104 | { | |
2105 | char idbuf[20]; | |
2106 | ||
2107 | sprintf (idbuf, "%%anon%u", id); | |
2108 | name = idbuf; | |
2109 | } | |
2110 | ||
2111 | if (! push_type (info, name)) | |
2112 | return FALSE; | |
2113 | ||
2114 | info->stack->flavor = structp ? "class" : "union class"; | |
2115 | info->stack->parents = NULL; | |
2116 | info->stack->num_parents = 0; | |
2117 | ||
2118 | if (size != 0 || vptr || ownvptr || tag != NULL) | |
2119 | { | |
2120 | if (vptr) | |
2121 | { | |
2122 | if (! append_type (info, " vtable ")) | |
2123 | return FALSE; | |
2124 | if (ownvptr) | |
2125 | { | |
2126 | if (! append_type (info, "self ")) | |
2127 | return FALSE; | |
2128 | } | |
2129 | else | |
2130 | { | |
2131 | if (! append_type (info, tv) | |
2132 | || ! append_type (info, " ")) | |
2133 | return FALSE; | |
2134 | } | |
2135 | } | |
2136 | } | |
2137 | ||
2138 | info->stack->visibility = DEBUG_VISIBILITY_PRIVATE; | |
2139 | ||
2140 | return TRUE; | |
2141 | } | |
2142 | ||
2143 | /* Add a static member to a class. */ | |
2144 | ||
2145 | static bfd_boolean | |
2146 | tg_class_static_member (void *p, const char *name, | |
2147 | const char *physname ATTRIBUTE_UNUSED, | |
2148 | enum debug_visibility visibility) | |
2149 | { | |
2150 | struct pr_handle *info = (struct pr_handle *) p; | |
2151 | char *t; | |
2152 | int len_var, len_class; | |
2153 | char *full_name; | |
2154 | ||
2155 | len_var = strlen (name); | |
2156 | len_class = strlen (info->stack->next->type); | |
ea9986ff | 2157 | full_name = xmalloc (len_var + len_class + 3); |
51cdc6e0 NC |
2158 | if (! full_name) |
2159 | return FALSE; | |
ea9986ff | 2160 | sprintf (full_name, "%s::%s", info->stack->next->type, name); |
51cdc6e0 NC |
2161 | |
2162 | if (! substitute_type (info, full_name)) | |
2163 | return FALSE; | |
2164 | ||
2165 | if (! prepend_type (info, "static ")) | |
2166 | return FALSE; | |
2167 | ||
2168 | t = pop_type (info); | |
2169 | if (t == NULL) | |
2170 | return FALSE; | |
2171 | ||
2172 | if (! tg_fix_visibility (info, visibility)) | |
2173 | return FALSE; | |
2174 | ||
2175 | fprintf (info->f, "%s\t%s\t0;\"\tkind:x\ttype:%s\tclass:%s\taccess:%s\n", | |
2176 | name, info->filename, t, info->stack->type, | |
2177 | visibility_name (visibility)); | |
2178 | free (t); | |
2179 | free (full_name); | |
2180 | ||
2181 | return TRUE; | |
2182 | } | |
2183 | ||
2184 | /* Add a base class to a class. */ | |
2185 | ||
2186 | static bfd_boolean | |
2187 | tg_class_baseclass (void *p, bfd_vma bitpos ATTRIBUTE_UNUSED, | |
2188 | bfd_boolean virtual, enum debug_visibility visibility) | |
2189 | { | |
2190 | struct pr_handle *info = (struct pr_handle *) p; | |
2191 | char *t; | |
2192 | const char *prefix; | |
2193 | ||
2194 | assert (info->stack != NULL && info->stack->next != NULL); | |
2195 | ||
2196 | t = pop_type (info); | |
2197 | if (t == NULL) | |
2198 | return FALSE; | |
2199 | ||
0112cd26 | 2200 | if (CONST_STRNEQ (t, "class ")) |
51cdc6e0 NC |
2201 | t += sizeof "class " - 1; |
2202 | ||
2203 | /* Push it back on to take advantage of the prepend_type and | |
2204 | append_type routines. */ | |
2205 | if (! push_type (info, t)) | |
2206 | return FALSE; | |
2207 | ||
2208 | if (virtual) | |
2209 | { | |
2210 | if (! prepend_type (info, "virtual ")) | |
2211 | return FALSE; | |
2212 | } | |
2213 | ||
2214 | switch (visibility) | |
2215 | { | |
2216 | case DEBUG_VISIBILITY_PUBLIC: | |
2217 | prefix = "public "; | |
2218 | break; | |
2219 | case DEBUG_VISIBILITY_PROTECTED: | |
2220 | prefix = "protected "; | |
2221 | break; | |
2222 | case DEBUG_VISIBILITY_PRIVATE: | |
2223 | prefix = "private "; | |
2224 | break; | |
2225 | default: | |
2226 | prefix = "/* unknown visibility */ "; | |
2227 | break; | |
2228 | } | |
2229 | ||
2230 | if (! prepend_type (info, prefix)) | |
2231 | return FALSE; | |
2232 | ||
2233 | t = pop_type (info); | |
2234 | if (t == NULL) | |
2235 | return FALSE; | |
2236 | ||
2237 | if (info->stack->num_parents && ! append_parent (info, ", ")) | |
2238 | return FALSE; | |
2239 | ||
2240 | if (! append_parent (info, t)) | |
2241 | return FALSE; | |
2242 | info->stack->num_parents++; | |
2243 | ||
2244 | free (t); | |
2245 | ||
2246 | return TRUE; | |
2247 | } | |
2248 | ||
2249 | /* Add a variant to a method. */ | |
2250 | ||
2251 | static bfd_boolean | |
2252 | tg_class_method_variant (void *p, const char *physname ATTRIBUTE_UNUSED, | |
2253 | enum debug_visibility visibility, | |
2254 | bfd_boolean constp, bfd_boolean volatilep, | |
2255 | bfd_vma voffset ATTRIBUTE_UNUSED, | |
2256 | bfd_boolean context) | |
2257 | { | |
2258 | struct pr_handle *info = (struct pr_handle *) p; | |
2259 | char *method_type; | |
2260 | char *context_type; | |
2261 | char *method_name; | |
2262 | ||
2263 | assert (info->stack != NULL); | |
2264 | assert (info->stack->next != NULL); | |
2265 | ||
2266 | /* Put the const and volatile qualifiers on the type. */ | |
2267 | if (volatilep) | |
2268 | { | |
2269 | if (! append_type (info, " volatile")) | |
2270 | return FALSE; | |
2271 | } | |
2272 | if (constp) | |
2273 | { | |
2274 | if (! append_type (info, " const")) | |
2275 | return FALSE; | |
2276 | } | |
2277 | ||
2278 | method_name = strdup (context ? info->stack->next->next->method | |
2279 | : info->stack->next->method); | |
2da42df6 | 2280 | |
51cdc6e0 NC |
2281 | /* Stick the name of the method into its type. */ |
2282 | if (! substitute_type (info, method_name)) | |
2283 | return FALSE; | |
2284 | ||
2285 | /* Get the type. */ | |
2286 | method_type = pop_type (info); | |
2287 | if (method_type == NULL) | |
2288 | return FALSE; | |
2289 | ||
2290 | /* Pull off the context type if there is one. */ | |
2291 | if (! context) | |
2292 | context_type = NULL; | |
2293 | else | |
2294 | { | |
2295 | context_type = pop_type (info); | |
2296 | if (context_type == NULL) | |
2297 | return FALSE; | |
2298 | } | |
2299 | ||
2300 | /* Now the top of the stack is the class. */ | |
2301 | if (! tg_fix_visibility (info, visibility)) | |
2302 | return FALSE; | |
2303 | ||
2304 | fprintf (info->f, "%s\t%s\t0;\"\tkind:p\ttype:%s\tclass:%s\n", | |
2305 | method_name, info->filename, method_type, info->stack->type); | |
2306 | free (method_type); | |
2307 | free (method_name); | |
2308 | free (context_type); | |
2da42df6 | 2309 | |
51cdc6e0 NC |
2310 | return TRUE; |
2311 | } | |
2312 | ||
2313 | /* Add a static variant to a method. */ | |
2314 | ||
2315 | static bfd_boolean | |
2316 | tg_class_static_method_variant (void *p, | |
2317 | const char *physname ATTRIBUTE_UNUSED, | |
2318 | enum debug_visibility visibility, | |
2da42df6 | 2319 | bfd_boolean constp, bfd_boolean volatilep) |
51cdc6e0 NC |
2320 | { |
2321 | struct pr_handle *info = (struct pr_handle *) p; | |
2322 | char *method_type; | |
2323 | char *method_name; | |
2324 | ||
2325 | assert (info->stack != NULL); | |
2326 | assert (info->stack->next != NULL); | |
2327 | assert (info->stack->next->method != NULL); | |
2328 | ||
2329 | /* Put the const and volatile qualifiers on the type. */ | |
2330 | if (volatilep) | |
2331 | { | |
2332 | if (! append_type (info, " volatile")) | |
2333 | return FALSE; | |
2334 | } | |
2335 | if (constp) | |
2336 | { | |
2337 | if (! append_type (info, " const")) | |
2338 | return FALSE; | |
2339 | } | |
2340 | ||
2341 | /* Mark it as static. */ | |
2342 | if (! prepend_type (info, "static ")) | |
2343 | return FALSE; | |
2344 | ||
2345 | method_name = strdup (info->stack->next->method); | |
2346 | /* Stick the name of the method into its type. */ | |
2347 | if (! substitute_type (info, info->stack->next->method)) | |
2348 | return FALSE; | |
2349 | ||
2350 | /* Get the type. */ | |
2351 | method_type = pop_type (info); | |
2352 | if (method_type == NULL) | |
2353 | return FALSE; | |
2354 | ||
2355 | /* Now the top of the stack is the class. */ | |
2356 | if (! tg_fix_visibility (info, visibility)) | |
2357 | return FALSE; | |
2358 | ||
2359 | fprintf (info->f, "%s\t%s\t0;\"\tkind:p\ttype:%s\tclass:%s\taccess:%s\n", | |
2360 | method_name, info->filename, method_type, info->stack->type, | |
2361 | visibility_name (visibility)); | |
2362 | free (method_type); | |
2363 | free (method_name); | |
2364 | ||
2365 | return TRUE; | |
2366 | } | |
2367 | ||
2368 | /* Finish up a class. */ | |
2369 | ||
2370 | static bfd_boolean | |
2371 | tg_end_class_type (void *p) | |
2372 | { | |
2373 | struct pr_handle *info = (struct pr_handle *) p; | |
2374 | ||
2375 | fprintf (info->f, "%s\t%s\t0;\"\tkind:c\ttype:%s", info->stack->type, | |
2376 | info->filename, info->stack->flavor); | |
2377 | if (info->stack->num_parents) | |
2378 | { | |
2379 | fprintf (info->f, "\tinherits:%s", info->stack->parents); | |
2380 | free (info->stack->parents); | |
2381 | } | |
2382 | fputc ('\n', info->f); | |
2383 | ||
2384 | return tg_end_struct_type (p); | |
2385 | } | |
2386 | ||
2387 | /* Push a type on the stack using a tag name. */ | |
2388 | ||
2389 | static bfd_boolean | |
2390 | tg_tag_type (void *p, const char *name, unsigned int id, | |
2391 | enum debug_type_kind kind) | |
2392 | { | |
2393 | struct pr_handle *info = (struct pr_handle *) p; | |
2394 | const char *t, *tag; | |
2395 | char idbuf[20]; | |
2396 | ||
2397 | switch (kind) | |
2398 | { | |
2399 | case DEBUG_KIND_STRUCT: | |
2400 | t = "struct "; | |
2401 | break; | |
2402 | case DEBUG_KIND_UNION: | |
2403 | t = "union "; | |
2404 | break; | |
2405 | case DEBUG_KIND_ENUM: | |
2406 | t = "enum "; | |
2407 | break; | |
2408 | case DEBUG_KIND_CLASS: | |
2409 | t = "class "; | |
2410 | break; | |
2411 | case DEBUG_KIND_UNION_CLASS: | |
2412 | t = "union class "; | |
2413 | break; | |
2414 | default: | |
2415 | abort (); | |
2416 | return FALSE; | |
2417 | } | |
2418 | ||
2419 | if (! push_type (info, t)) | |
2420 | return FALSE; | |
2421 | if (name != NULL) | |
2422 | tag = name; | |
2423 | else | |
2424 | { | |
2425 | sprintf (idbuf, "%%anon%u", id); | |
2426 | tag = idbuf; | |
2427 | } | |
2428 | ||
2429 | if (! append_type (info, tag)) | |
2430 | return FALSE; | |
2431 | ||
2432 | return TRUE; | |
2433 | } | |
2434 | ||
2435 | /* Output a typedef. */ | |
2436 | ||
2437 | static bfd_boolean | |
2438 | tg_typdef (void *p, const char *name) | |
2439 | { | |
2440 | struct pr_handle *info = (struct pr_handle *) p; | |
2441 | char *s; | |
2442 | ||
2443 | s = pop_type (info); | |
2444 | if (s == NULL) | |
2445 | return FALSE; | |
2446 | ||
2447 | fprintf (info->f, "%s\t%s\t0;\"\tkind:t\ttype:%s\n", name, | |
2448 | info->filename, s); | |
2449 | ||
2450 | free (s); | |
2451 | ||
2452 | return TRUE; | |
2453 | } | |
2454 | ||
2455 | /* Output a tag. The tag should already be in the string on the | |
2456 | stack, so all we have to do here is print it out. */ | |
2457 | ||
2458 | static bfd_boolean | |
2459 | tg_tag (void *p ATTRIBUTE_UNUSED, const char *name ATTRIBUTE_UNUSED) | |
2460 | { | |
2461 | struct pr_handle *info = (struct pr_handle *) p; | |
2462 | char *t; | |
2463 | ||
2464 | t = pop_type (info); | |
2465 | if (t == NULL) | |
2466 | return FALSE; | |
2467 | free (t); | |
2468 | ||
2469 | return TRUE; | |
2470 | } | |
2471 | ||
2472 | /* Output an integer constant. */ | |
2473 | ||
2474 | static bfd_boolean | |
2475 | tg_int_constant (void *p, const char *name, bfd_vma val) | |
2476 | { | |
2477 | struct pr_handle *info = (struct pr_handle *) p; | |
2478 | char ab[20]; | |
2479 | ||
2480 | indent (info); | |
2481 | print_vma (val, ab, FALSE, FALSE); | |
2482 | fprintf (info->f, "%s\t%s\t0;\"\tkind:v\ttype:const int\tvalue:%s\n", | |
2483 | name, info->filename, ab); | |
2484 | return TRUE; | |
2485 | } | |
2486 | ||
2487 | /* Output a floating point constant. */ | |
2488 | ||
2489 | static bfd_boolean | |
2490 | tg_float_constant (void *p, const char *name, double val) | |
2491 | { | |
2492 | struct pr_handle *info = (struct pr_handle *) p; | |
2493 | ||
2494 | indent (info); | |
2495 | fprintf (info->f, "%s\t%s\t0;\"\tkind:v\ttype:const double\tvalue:%g\n", | |
2496 | name, info->filename, val); | |
2497 | return TRUE; | |
2498 | } | |
2499 | ||
2500 | /* Output a typed constant. */ | |
2501 | ||
2502 | static bfd_boolean | |
2503 | tg_typed_constant (void *p, const char *name, bfd_vma val) | |
2504 | { | |
2505 | struct pr_handle *info = (struct pr_handle *) p; | |
2506 | char *t; | |
2507 | char ab[20]; | |
2508 | ||
2509 | t = pop_type (info); | |
2510 | if (t == NULL) | |
2511 | return FALSE; | |
2512 | ||
2513 | indent (info); | |
2514 | print_vma (val, ab, FALSE, FALSE); | |
2515 | fprintf (info->f, "%s\t%s\t0;\"\tkind:v\ttype:const %s\tvalue:%s\n", | |
2516 | name, info->filename, t, ab); | |
2517 | ||
2518 | free (t); | |
2519 | ||
2520 | return TRUE; | |
2521 | } | |
2522 | ||
2523 | /* Output a variable. */ | |
2524 | ||
2525 | static bfd_boolean | |
2526 | tg_variable (void *p, const char *name, enum debug_var_kind kind, | |
2527 | bfd_vma val ATTRIBUTE_UNUSED) | |
2528 | { | |
2529 | struct pr_handle *info = (struct pr_handle *) p; | |
2530 | char *t; | |
2531 | const char *dname, *from_class; | |
2532 | ||
2533 | t = pop_type (info); | |
2534 | if (t == NULL) | |
2535 | return FALSE; | |
2536 | ||
2537 | dname = name; | |
2538 | if (info->demangler) | |
2539 | { | |
ed180cc5 | 2540 | dname = info->demangler (info->abfd, name, DMGL_ANSI | DMGL_PARAMS); |
51cdc6e0 NC |
2541 | if (strcmp (name, dname) == 0) |
2542 | { | |
2543 | free ((char *) dname); | |
2544 | dname = name; | |
2545 | } | |
2546 | } | |
2547 | ||
2548 | if (dname != name) | |
2549 | { | |
2550 | char *sep; | |
2551 | sep = strstr (dname, "::"); | |
2552 | if (sep) | |
2553 | { | |
2554 | *sep = 0; | |
2555 | name = sep + 2; | |
2556 | from_class = dname; | |
2557 | } | |
2558 | else | |
2559 | { | |
2560 | /* Obscure types as vts and type_info nodes. */ | |
2561 | name = dname; | |
2562 | from_class = NULL; | |
2563 | } | |
2564 | } | |
2565 | else | |
2566 | from_class = NULL; | |
2567 | ||
2568 | fprintf (info->f, "%s\t%s\t0;\"\tkind:v\ttype:%s", name, info->filename, t); | |
2569 | ||
2570 | switch (kind) | |
2571 | { | |
2572 | case DEBUG_STATIC: | |
2573 | case DEBUG_LOCAL_STATIC: | |
2574 | fprintf (info->f, "\tfile:"); | |
2575 | break; | |
2576 | case DEBUG_REGISTER: | |
2577 | fprintf (info->f, "\tregister:"); | |
2578 | break; | |
2579 | default: | |
2580 | break; | |
2581 | } | |
2582 | ||
2583 | if (from_class) | |
2584 | { | |
2585 | fprintf (info->f, "\tclass:%s",from_class); | |
2586 | free ((char *) dname); | |
2587 | } | |
2588 | ||
2589 | fprintf (info->f, "\n"); | |
2590 | ||
2591 | free (t); | |
2592 | ||
2593 | return TRUE; | |
2594 | } | |
2595 | ||
2596 | /* Start outputting a function. */ | |
2597 | ||
2598 | static bfd_boolean | |
2599 | tg_start_function (void *p, const char *name, bfd_boolean global) | |
2600 | { | |
2601 | struct pr_handle *info = (struct pr_handle *) p; | |
2602 | const char *dname; | |
2603 | ||
2604 | if (! global) | |
2605 | info->stack->flavor = "static"; | |
2606 | else | |
2607 | info->stack->flavor = NULL; | |
2608 | ||
2609 | dname = name; | |
2610 | if (info->demangler) | |
2611 | { | |
ed180cc5 | 2612 | dname = info->demangler (info->abfd, name, DMGL_ANSI | DMGL_PARAMS); |
51cdc6e0 NC |
2613 | if (strcmp (name, dname) == 0) |
2614 | { | |
2615 | free ((char *) dname); | |
2616 | dname = name; | |
2617 | } | |
2618 | } | |
2619 | ||
2620 | if (! substitute_type (info, dname)) | |
2621 | return FALSE; | |
2da42df6 | 2622 | |
51cdc6e0 NC |
2623 | if (dname != name) |
2624 | { | |
2625 | char *sep; | |
2626 | sep = strstr (dname, "::"); | |
2627 | if (sep) | |
2628 | { | |
2629 | info->stack->method = dname; | |
2630 | *sep = 0; | |
2631 | name = sep + 2; | |
2632 | } | |
2633 | else | |
2634 | { | |
2635 | info->stack->method = ""; | |
2636 | name = dname; | |
2637 | } | |
2638 | sep = strchr (name, '('); | |
2639 | if (sep) | |
2640 | *sep = 0; | |
2641 | /* Obscure functions as type_info function. */ | |
2642 | } | |
2643 | else | |
2644 | info->stack->method = NULL; | |
2645 | ||
2646 | info->stack->parents = strdup (name); | |
2647 | ||
2648 | if (! info->stack->method && ! append_type (info, "(")) | |
2649 | return FALSE; | |
2650 | ||
2651 | info->parameter = 1; | |
2652 | ||
2653 | return TRUE; | |
2654 | } | |
2655 | ||
2656 | /* Output a function parameter. */ | |
2657 | ||
2658 | static bfd_boolean | |
2659 | tg_function_parameter (void *p, const char *name, enum debug_parm_kind kind, | |
2660 | bfd_vma val ATTRIBUTE_UNUSED) | |
2661 | { | |
2662 | struct pr_handle *info = (struct pr_handle *) p; | |
2663 | char *t; | |
2664 | ||
2665 | if (kind == DEBUG_PARM_REFERENCE | |
2666 | || kind == DEBUG_PARM_REF_REG) | |
2667 | { | |
2668 | if (! pr_reference_type (p)) | |
2669 | return FALSE; | |
2670 | } | |
2671 | ||
2672 | if (! substitute_type (info, name)) | |
2673 | return FALSE; | |
2674 | ||
2675 | t = pop_type (info); | |
2676 | if (t == NULL) | |
2677 | return FALSE; | |
2678 | ||
2679 | if (! info->stack->method) | |
2680 | { | |
2681 | if (info->parameter != 1 && ! append_type (info, ", ")) | |
2682 | return FALSE; | |
2da42df6 | 2683 | |
51cdc6e0 NC |
2684 | if (kind == DEBUG_PARM_REG || kind == DEBUG_PARM_REF_REG) |
2685 | if (! append_type (info, "register ")) | |
2686 | return FALSE; | |
2da42df6 | 2687 | |
51cdc6e0 NC |
2688 | if (! append_type (info, t)) |
2689 | return FALSE; | |
2690 | } | |
2691 | ||
2692 | free (t); | |
2693 | ||
2694 | ++info->parameter; | |
2695 | ||
2696 | return TRUE; | |
2697 | } | |
2698 | ||
2699 | /* Start writing out a block. */ | |
2700 | ||
2701 | static bfd_boolean | |
2702 | tg_start_block (void *p, bfd_vma addr) | |
2703 | { | |
2704 | struct pr_handle *info = (struct pr_handle *) p; | |
2705 | char ab[20], kind, *partof; | |
2706 | char *t; | |
2707 | bfd_boolean local; | |
2708 | ||
2709 | if (info->parameter > 0) | |
2710 | { | |
2711 | info->parameter = 0; | |
2712 | ||
2713 | /* Delayed name. */ | |
2714 | fprintf (info->f, "%s\t%s\t", info->stack->parents, info->filename); | |
2715 | free (info->stack->parents); | |
2716 | ||
2717 | print_vma (addr, ab, TRUE, TRUE); | |
2718 | translate_addresses (info->abfd, ab, info->f, info->syms); | |
2719 | local = info->stack->flavor != NULL; | |
2720 | if (info->stack->method && *info->stack->method) | |
2721 | { | |
2722 | kind = 'm'; | |
2723 | partof = (char *) info->stack->method; | |
2724 | } | |
2725 | else | |
2726 | { | |
2727 | kind = 'f'; | |
2728 | partof = NULL; | |
2729 | if (! info->stack->method && ! append_type (info, ")")) | |
2730 | return FALSE; | |
2731 | } | |
2732 | t = pop_type (info); | |
2733 | if (t == NULL) | |
2734 | return FALSE; | |
2735 | fprintf (info->f, ";\"\tkind:%c\ttype:%s", kind, t); | |
2736 | if (local) | |
2737 | fputs ("\tfile:", info->f); | |
2738 | if (partof) | |
2739 | { | |
2740 | fprintf (info->f, "\tclass:%s", partof); | |
2741 | free (partof); | |
2742 | } | |
2743 | fputc ('\n', info->f); | |
2744 | } | |
2745 | ||
2746 | return TRUE; | |
2747 | } | |
2748 | ||
2749 | /* Write out line number information. */ | |
2750 | ||
2751 | static bfd_boolean | |
2da42df6 | 2752 | tg_lineno (void *p ATTRIBUTE_UNUSED, const char *filename ATTRIBUTE_UNUSED, |
51cdc6e0 NC |
2753 | unsigned long lineno ATTRIBUTE_UNUSED, |
2754 | bfd_vma addr ATTRIBUTE_UNUSED) | |
2755 | { | |
2756 | return TRUE; | |
2757 | } | |
2758 | ||
2759 | /* Finish writing out a block. */ | |
2760 | ||
2761 | static bfd_boolean | |
2762 | tg_end_block (void *p ATTRIBUTE_UNUSED, bfd_vma addr ATTRIBUTE_UNUSED) | |
2763 | { | |
2764 | return TRUE; | |
2765 | } | |
2766 | ||
2767 | /* Convert the visibility value into a human readable name. */ | |
2768 | ||
2769 | static const char * | |
2770 | visibility_name (enum debug_visibility visibility) | |
2771 | { | |
2772 | const char *s; | |
2773 | ||
2774 | switch (visibility) | |
2775 | { | |
2776 | case DEBUG_VISIBILITY_PUBLIC: | |
2777 | s = "public"; | |
2778 | break; | |
2779 | case DEBUG_VISIBILITY_PRIVATE: | |
2780 | s = "private"; | |
2781 | break; | |
2782 | case DEBUG_VISIBILITY_PROTECTED: | |
2783 | s = "protected"; | |
2784 | break; | |
2785 | case DEBUG_VISIBILITY_IGNORE: | |
2786 | s = "/* ignore */"; | |
2787 | break; | |
2788 | default: | |
2789 | abort (); | |
2790 | return FALSE; | |
2791 | } | |
2792 | return s; | |
2793 | } |