Deleted Added
full compact
prdbg.c (104834) prdbg.c (130561)
1/* prdbg.c -- Print out generic debugging information.
1/* prdbg.c -- Print out generic debugging information.
2 Copyright 1995, 1996 Free Software Foundation, Inc.
2 Copyright 1995, 1996, 2002, 2003 Free Software Foundation, Inc.
3 Written by Ian Lance Taylor <ian@cygnus.com>.
3 Written by Ian Lance Taylor <ian@cygnus.com>.
4 Tags style generation written by Salvador E. Tropea <set@computer.org>.
4
5 This file is part of GNU Binutils.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11

--- 26 unchanged lines hidden (view full) ---

38 /* File to print information to. */
39 FILE *f;
40 /* Current indentation level. */
41 unsigned int indent;
42 /* Type stack. */
43 struct pr_stack *stack;
44 /* Parameter number we are about to output. */
45 int parameter;
5
6 This file is part of GNU Binutils.
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12

--- 26 unchanged lines hidden (view full) ---

39 /* File to print information to. */
40 FILE *f;
41 /* Current indentation level. */
42 unsigned int indent;
43 /* Type stack. */
44 struct pr_stack *stack;
45 /* Parameter number we are about to output. */
46 int parameter;
47 /* The following are used only by the tags code (tg_). */
48 /* Name of the file we are using. */
49 char *filename;
50 /* The BFD. */
51 bfd *abfd;
52 /* The symbols table for this BFD. */
53 asymbol **syms;
54 /* Pointer to a function to demangle symbols. */
55 char *(*demangler) (bfd *, const char *);
46};
47
48/* The type stack. */
49
50struct pr_stack
51{
52 /* Next element on the stack. */
53 struct pr_stack *next;
54 /* This element. */
55 char *type;
56 /* Current visibility of fields if this is a class. */
57 enum debug_visibility visibility;
58 /* Name of the current method we are handling. */
59 const char *method;
56};
57
58/* The type stack. */
59
60struct pr_stack
61{
62 /* Next element on the stack. */
63 struct pr_stack *next;
64 /* This element. */
65 char *type;
66 /* Current visibility of fields if this is a class. */
67 enum debug_visibility visibility;
68 /* Name of the current method we are handling. */
69 const char *method;
70 /* The following are used only by the tags code (tg_). */
71 /* Type for the container (struct, union, class, union class). */
72 const char *flavor;
73 /* A comma separated list of parent classes. */
74 char *parents;
75 /* How many parents contains parents. */
76 int num_parents;
60};
61
77};
78
62static void indent PARAMS ((struct pr_handle *));
63static boolean push_type PARAMS ((struct pr_handle *, const char *));
64static boolean prepend_type PARAMS ((struct pr_handle *, const char *));
65static boolean append_type PARAMS ((struct pr_handle *, const char *));
66static boolean substitute_type PARAMS ((struct pr_handle *, const char *));
67static boolean indent_type PARAMS ((struct pr_handle *));
68static char *pop_type PARAMS ((struct pr_handle *));
69static void print_vma PARAMS ((bfd_vma, char *, boolean, boolean));
70static boolean pr_fix_visibility
71 PARAMS ((struct pr_handle *, enum debug_visibility));
72
73static boolean pr_start_compilation_unit PARAMS ((PTR, const char *));
74static boolean pr_start_source PARAMS ((PTR, const char *));
75static boolean pr_empty_type PARAMS ((PTR));
76static boolean pr_void_type PARAMS ((PTR));
77static boolean pr_int_type PARAMS ((PTR, unsigned int, boolean));
78static boolean pr_float_type PARAMS ((PTR, unsigned int));
79static boolean pr_complex_type PARAMS ((PTR, unsigned int));
80static boolean pr_bool_type PARAMS ((PTR, unsigned int));
81static boolean pr_enum_type
82 PARAMS ((PTR, const char *, const char **, bfd_signed_vma *));
83static boolean pr_pointer_type PARAMS ((PTR));
84static boolean pr_function_type PARAMS ((PTR, int, boolean));
85static boolean pr_reference_type PARAMS ((PTR));
86static boolean pr_range_type PARAMS ((PTR, bfd_signed_vma, bfd_signed_vma));
87static boolean pr_array_type
88 PARAMS ((PTR, bfd_signed_vma, bfd_signed_vma, boolean));
89static boolean pr_set_type PARAMS ((PTR, boolean));
90static boolean pr_offset_type PARAMS ((PTR));
91static boolean pr_method_type PARAMS ((PTR, boolean, int, boolean));
92static boolean pr_const_type PARAMS ((PTR));
93static boolean pr_volatile_type PARAMS ((PTR));
94static boolean pr_start_struct_type
95 PARAMS ((PTR, const char *, unsigned int, boolean, unsigned int));
96static boolean pr_struct_field
97 PARAMS ((PTR, const char *, bfd_vma, bfd_vma, enum debug_visibility));
98static boolean pr_end_struct_type PARAMS ((PTR));
99static boolean pr_start_class_type
100 PARAMS ((PTR, const char *, unsigned int, boolean, unsigned int, boolean,
101 boolean));
102static boolean pr_class_static_member
103 PARAMS ((PTR, const char *, const char *, enum debug_visibility));
104static boolean pr_class_baseclass
105 PARAMS ((PTR, bfd_vma, boolean, enum debug_visibility));
106static boolean pr_class_start_method PARAMS ((PTR, const char *));
107static boolean pr_class_method_variant
108 PARAMS ((PTR, const char *, enum debug_visibility, boolean, boolean,
109 bfd_vma, boolean));
110static boolean pr_class_static_method_variant
111 PARAMS ((PTR, const char *, enum debug_visibility, boolean, boolean));
112static boolean pr_class_end_method PARAMS ((PTR));
113static boolean pr_end_class_type PARAMS ((PTR));
114static boolean pr_typedef_type PARAMS ((PTR, const char *));
115static boolean pr_tag_type
116 PARAMS ((PTR, const char *, unsigned int, enum debug_type_kind));
117static boolean pr_typdef PARAMS ((PTR, const char *));
118static boolean pr_tag PARAMS ((PTR, const char *));
119static boolean pr_int_constant PARAMS ((PTR, const char *, bfd_vma));
120static boolean pr_float_constant PARAMS ((PTR, const char *, double));
121static boolean pr_typed_constant PARAMS ((PTR, const char *, bfd_vma));
122static boolean pr_variable
123 PARAMS ((PTR, const char *, enum debug_var_kind, bfd_vma));
124static boolean pr_start_function PARAMS ((PTR, const char *, boolean));
125static boolean pr_function_parameter
126 PARAMS ((PTR, const char *, enum debug_parm_kind, bfd_vma));
127static boolean pr_start_block PARAMS ((PTR, bfd_vma));
128static boolean pr_end_block PARAMS ((PTR, bfd_vma));
129static boolean pr_end_function PARAMS ((PTR));
130static boolean pr_lineno PARAMS ((PTR, const char *, unsigned long, bfd_vma));
131
79static void indent (struct pr_handle *);
80static bfd_boolean push_type (struct pr_handle *, const char *);
81static bfd_boolean prepend_type (struct pr_handle *, const char *);
82static bfd_boolean append_type (struct pr_handle *, const char *);
83static bfd_boolean substitute_type (struct pr_handle *, const char *);
84static bfd_boolean indent_type (struct pr_handle *);
85static char *pop_type (struct pr_handle *);
86static void print_vma (bfd_vma, char *, bfd_boolean, bfd_boolean);
87static bfd_boolean pr_fix_visibility
88 (struct pr_handle *, enum debug_visibility);
89static bfd_boolean pr_start_compilation_unit (void *, const char *);
90static bfd_boolean pr_start_source (void *, const char *);
91static bfd_boolean pr_empty_type (void *);
92static bfd_boolean pr_void_type (void *);
93static bfd_boolean pr_int_type (void *, unsigned int, bfd_boolean);
94static bfd_boolean pr_float_type (void *, unsigned int);
95static bfd_boolean pr_complex_type (void *, unsigned int);
96static bfd_boolean pr_bool_type (void *, unsigned int);
97static bfd_boolean pr_enum_type
98 (void *, const char *, const char **, bfd_signed_vma *);
99static bfd_boolean pr_pointer_type (void *);
100static bfd_boolean pr_function_type (void *, int, bfd_boolean);
101static bfd_boolean pr_reference_type (void *);
102static bfd_boolean pr_range_type (void *, bfd_signed_vma, bfd_signed_vma);
103static bfd_boolean pr_array_type
104 (void *, bfd_signed_vma, bfd_signed_vma, bfd_boolean);
105static bfd_boolean pr_set_type (void *, bfd_boolean);
106static bfd_boolean pr_offset_type (void *);
107static bfd_boolean pr_method_type (void *, bfd_boolean, int, bfd_boolean);
108static bfd_boolean pr_const_type (void *);
109static bfd_boolean pr_volatile_type (void *);
110static bfd_boolean pr_start_struct_type
111 (void *, const char *, unsigned int, bfd_boolean, unsigned int);
112static bfd_boolean pr_struct_field
113 (void *, const char *, bfd_vma, bfd_vma, enum debug_visibility);
114static bfd_boolean pr_end_struct_type (void *);
115static bfd_boolean pr_start_class_type
116 (void *, const char *, unsigned int, bfd_boolean, unsigned int,
117 bfd_boolean, bfd_boolean);
118static bfd_boolean pr_class_static_member
119 (void *, const char *, const char *, enum debug_visibility);
120static bfd_boolean pr_class_baseclass
121 (void *, bfd_vma, bfd_boolean, enum debug_visibility);
122static bfd_boolean pr_class_start_method (void *, const char *);
123static bfd_boolean pr_class_method_variant
124 (void *, const char *, enum debug_visibility, bfd_boolean, bfd_boolean,
125 bfd_vma, bfd_boolean);
126static bfd_boolean pr_class_static_method_variant
127 (void *, const char *, enum debug_visibility, bfd_boolean, bfd_boolean);
128static bfd_boolean pr_class_end_method (void *);
129static bfd_boolean pr_end_class_type (void *);
130static bfd_boolean pr_typedef_type (void *, const char *);
131static bfd_boolean pr_tag_type
132 (void *, const char *, unsigned int, enum debug_type_kind);
133static bfd_boolean pr_typdef (void *, const char *);
134static bfd_boolean pr_tag (void *, const char *);
135static bfd_boolean pr_int_constant (void *, const char *, bfd_vma);
136static bfd_boolean pr_float_constant (void *, const char *, double);
137static bfd_boolean pr_typed_constant (void *, const char *, bfd_vma);
138static bfd_boolean pr_variable
139 (void *, const char *, enum debug_var_kind, bfd_vma);
140static bfd_boolean pr_start_function (void *, const char *, bfd_boolean);
141static bfd_boolean pr_function_parameter
142 (void *, const char *, enum debug_parm_kind, bfd_vma);
143static bfd_boolean pr_start_block (void *, bfd_vma);
144static bfd_boolean pr_end_block (void *, bfd_vma);
145static bfd_boolean pr_end_function (void *);
146static bfd_boolean pr_lineno (void *, const char *, unsigned long, bfd_vma);
147static bfd_boolean append_parent (struct pr_handle *, const char *);
148/* Only used by tg_ code. */
149static bfd_boolean tg_fix_visibility
150 (struct pr_handle *, enum debug_visibility);
151static void find_address_in_section (bfd *, asection *, void *);
152static void translate_addresses (bfd *, char *, FILE *, asymbol **);
153static const char *visibility_name (enum debug_visibility);
154/* Tags style replacements. */
155static bfd_boolean tg_start_compilation_unit (void *, const char *);
156static bfd_boolean tg_start_source (void *, const char *);
157static bfd_boolean tg_enum_type
158 (void *, const char *, const char **, bfd_signed_vma *);
159static bfd_boolean tg_start_struct_type
160 (void *, const char *, unsigned int, bfd_boolean, unsigned int);
161static bfd_boolean pr_struct_field
162 (void *, const char *, bfd_vma, bfd_vma, enum debug_visibility);
163static bfd_boolean tg_struct_field
164 (void *, const char *, bfd_vma, bfd_vma, enum debug_visibility);
165static bfd_boolean tg_struct_field
166 (void *, const char *, bfd_vma, bfd_vma, enum debug_visibility);
167static bfd_boolean tg_end_struct_type (void *);
168static bfd_boolean tg_start_class_type
169 (void *, const char *, unsigned int, bfd_boolean, unsigned int, bfd_boolean, bfd_boolean);
170static bfd_boolean tg_class_static_member
171 (void *, const char *, const char *, enum debug_visibility);
172static bfd_boolean tg_class_baseclass
173 (void *, bfd_vma, bfd_boolean, enum debug_visibility);
174static bfd_boolean tg_class_method_variant
175 (void *, const char *, enum debug_visibility, bfd_boolean, bfd_boolean, bfd_vma, bfd_boolean);
176static bfd_boolean tg_class_static_method_variant
177 (void *, const char *, enum debug_visibility, bfd_boolean, bfd_boolean);
178static bfd_boolean tg_end_class_type (void *);
179static bfd_boolean tg_tag_type
180 (void *, const char *, unsigned int, enum debug_type_kind);
181static bfd_boolean tg_typdef (void *, const char *);
182static bfd_boolean tg_tag (void *, const char *);
183static bfd_boolean tg_int_constant (void *, const char *, bfd_vma);
184static bfd_boolean tg_float_constant (void *, const char *, double);
185static bfd_boolean tg_typed_constant (void *, const char *, bfd_vma);
186static bfd_boolean tg_variable
187 (void *, const char *, enum debug_var_kind, bfd_vma);
188static bfd_boolean tg_start_function (void *, const char *, bfd_boolean);
189static bfd_boolean tg_function_parameter
190 (void *, const char *, enum debug_parm_kind, bfd_vma);
191static bfd_boolean tg_start_block (void *, bfd_vma);
192static bfd_boolean tg_end_block (void *, bfd_vma);
193static bfd_boolean tg_lineno (void *, const char *, unsigned long, bfd_vma);
194
132static const struct debug_write_fns pr_fns =
133{
134 pr_start_compilation_unit,
135 pr_start_source,
136 pr_empty_type,
137 pr_void_type,
138 pr_int_type,
139 pr_float_type,

--- 32 unchanged lines hidden (view full) ---

172 pr_start_function,
173 pr_function_parameter,
174 pr_start_block,
175 pr_end_block,
176 pr_end_function,
177 pr_lineno
178};
179
195static const struct debug_write_fns pr_fns =
196{
197 pr_start_compilation_unit,
198 pr_start_source,
199 pr_empty_type,
200 pr_void_type,
201 pr_int_type,
202 pr_float_type,

--- 32 unchanged lines hidden (view full) ---

235 pr_start_function,
236 pr_function_parameter,
237 pr_start_block,
238 pr_end_block,
239 pr_end_function,
240 pr_lineno
241};
242
243static const struct debug_write_fns tg_fns =
244{
245 tg_start_compilation_unit,
246 tg_start_source,
247 pr_empty_type, /* Same, push_type. */
248 pr_void_type, /* Same, push_type. */
249 pr_int_type, /* Same, push_type. */
250 pr_float_type, /* Same, push_type. */
251 pr_complex_type, /* Same, push_type. */
252 pr_bool_type, /* Same, push_type. */
253 tg_enum_type,
254 pr_pointer_type, /* Same, changes to pointer. */
255 pr_function_type, /* Same, push_type. */
256 pr_reference_type, /* Same, changes to reference. */
257 pr_range_type, /* FIXME: What's that?. */
258 pr_array_type, /* Same, push_type. */
259 pr_set_type, /* FIXME: What's that?. */
260 pr_offset_type, /* FIXME: What's that?. */
261 pr_method_type, /* Same. */
262 pr_const_type, /* Same, changes to const. */
263 pr_volatile_type, /* Same, changes to volatile. */
264 tg_start_struct_type,
265 tg_struct_field,
266 tg_end_struct_type,
267 tg_start_class_type,
268 tg_class_static_member,
269 tg_class_baseclass,
270 pr_class_start_method, /* Same, remembers that's a method. */
271 tg_class_method_variant,
272 tg_class_static_method_variant,
273 pr_class_end_method, /* Same, forgets that's a method. */
274 tg_end_class_type,
275 pr_typedef_type, /* Same, just push type. */
276 tg_tag_type,
277 tg_typdef,
278 tg_tag,
279 tg_int_constant, /* Untested. */
280 tg_float_constant, /* Untested. */
281 tg_typed_constant, /* Untested. */
282 tg_variable,
283 tg_start_function,
284 tg_function_parameter,
285 tg_start_block,
286 tg_end_block,
287 pr_end_function, /* Same, does nothing. */
288 tg_lineno
289};
290
180/* Print out the generic debugging information recorded in dhandle. */
181
291/* Print out the generic debugging information recorded in dhandle. */
292
182boolean
183print_debugging_info (f, dhandle)
184 FILE *f;
185 PTR dhandle;
293bfd_boolean
294print_debugging_info (FILE *f, void *dhandle, bfd *abfd, asymbol **syms,
295 void *demangler, bfd_boolean as_tags)
186{
187 struct pr_handle info;
188
189 info.f = f;
190 info.indent = 0;
191 info.stack = NULL;
192 info.parameter = 0;
296{
297 struct pr_handle info;
298
299 info.f = f;
300 info.indent = 0;
301 info.stack = NULL;
302 info.parameter = 0;
303 info.filename = NULL;
304 info.abfd = abfd;
305 info.syms = syms;
306 info.demangler = demangler;
193
307
194 return debug_write (dhandle, &pr_fns, (PTR) &info);
308 if (as_tags)
309 {
310 fputs ("!_TAG_FILE_FORMAT\t2\t/extended format/\n", f);
311 fputs ("!_TAG_FILE_SORTED\t0\t/0=unsorted, 1=sorted/\n", f);
312 fputs ("!_TAG_PROGRAM_AUTHOR\tIan Lance Taylor, Salvador E. Tropea and others\t//\n", f);
313 fputs ("!_TAG_PROGRAM_NAME\tobjdump\t/From GNU binutils/\n", f);
314 }
315
316 return as_tags ? debug_write (dhandle, &tg_fns, (void *) & info)
317 : debug_write (dhandle, &pr_fns, (void *) & info);
195}
196
197/* Indent to the current indentation level. */
198
199static void
318}
319
320/* Indent to the current indentation level. */
321
322static void
200indent (info)
201 struct pr_handle *info;
323indent (struct pr_handle *info)
202{
203 unsigned int i;
204
205 for (i = 0; i < info->indent; i++)
206 putc (' ', info->f);
207}
208
209/* Push a type on the type stack. */
210
324{
325 unsigned int i;
326
327 for (i = 0; i < info->indent; i++)
328 putc (' ', info->f);
329}
330
331/* Push a type on the type stack. */
332
211static boolean
212push_type (info, type)
213 struct pr_handle *info;
214 const char *type;
333static bfd_boolean
334push_type (struct pr_handle *info, const char *type)
215{
216 struct pr_stack *n;
217
218 if (type == NULL)
335{
336 struct pr_stack *n;
337
338 if (type == NULL)
219 return false;
339 return FALSE;
220
221 n = (struct pr_stack *) xmalloc (sizeof *n);
222 memset (n, 0, sizeof *n);
223
224 n->type = xstrdup (type);
225 n->visibility = DEBUG_VISIBILITY_IGNORE;
226 n->method = NULL;
227 n->next = info->stack;
228 info->stack = n;
229
340
341 n = (struct pr_stack *) xmalloc (sizeof *n);
342 memset (n, 0, sizeof *n);
343
344 n->type = xstrdup (type);
345 n->visibility = DEBUG_VISIBILITY_IGNORE;
346 n->method = NULL;
347 n->next = info->stack;
348 info->stack = n;
349
230 return true;
350 return TRUE;
231}
232
233/* Prepend a string onto the type on the top of the type stack. */
234
351}
352
353/* Prepend a string onto the type on the top of the type stack. */
354
235static boolean
236prepend_type (info, s)
237 struct pr_handle *info;
238 const char *s;
355static bfd_boolean
356prepend_type (struct pr_handle *info, const char *s)
239{
240 char *n;
241
242 assert (info->stack != NULL);
243
244 n = (char *) xmalloc (strlen (s) + strlen (info->stack->type) + 1);
245 sprintf (n, "%s%s", s, info->stack->type);
246 free (info->stack->type);
247 info->stack->type = n;
248
357{
358 char *n;
359
360 assert (info->stack != NULL);
361
362 n = (char *) xmalloc (strlen (s) + strlen (info->stack->type) + 1);
363 sprintf (n, "%s%s", s, info->stack->type);
364 free (info->stack->type);
365 info->stack->type = n;
366
249 return true;
367 return TRUE;
250}
251
252/* Append a string to the type on the top of the type stack. */
253
368}
369
370/* Append a string to the type on the top of the type stack. */
371
254static boolean
255append_type (info, s)
256 struct pr_handle *info;
257 const char *s;
372static bfd_boolean
373append_type (struct pr_handle *info, const char *s)
258{
259 unsigned int len;
260
261 if (s == NULL)
374{
375 unsigned int len;
376
377 if (s == NULL)
262 return false;
378 return FALSE;
263
264 assert (info->stack != NULL);
265
266 len = strlen (info->stack->type);
267 info->stack->type = (char *) xrealloc (info->stack->type,
268 len + strlen (s) + 1);
269 strcpy (info->stack->type + len, s);
270
379
380 assert (info->stack != NULL);
381
382 len = strlen (info->stack->type);
383 info->stack->type = (char *) xrealloc (info->stack->type,
384 len + strlen (s) + 1);
385 strcpy (info->stack->type + len, s);
386
271 return true;
387 return TRUE;
272}
273
388}
389
390/* Append a string to the parents on the top of the type stack. */
391
392static bfd_boolean
393append_parent (struct pr_handle *info, const char *s)
394{
395 unsigned int len;
396
397 if (s == NULL)
398 return FALSE;
399
400 assert (info->stack != NULL);
401
402 len = info->stack->parents ? strlen (info->stack->parents) : 0;
403 info->stack->parents = (char *) xrealloc (info->stack->parents,
404 len + strlen (s) + 1);
405 strcpy (info->stack->parents + len, s);
406
407 return TRUE;
408}
409
274/* We use an underscore to indicate where the name should go in a type
275 string. This function substitutes a string for the underscore. If
276 there is no underscore, the name follows the type. */
277
410/* We use an underscore to indicate where the name should go in a type
411 string. This function substitutes a string for the underscore. If
412 there is no underscore, the name follows the type. */
413
278static boolean
279substitute_type (info, s)
280 struct pr_handle *info;
281 const char *s;
414static bfd_boolean
415substitute_type (struct pr_handle *info, const char *s)
282{
283 char *u;
284
285 assert (info->stack != NULL);
286
287 u = strchr (info->stack->type, '|');
288 if (u != NULL)
289 {
290 char *n;
291
292 n = (char *) xmalloc (strlen (info->stack->type) + strlen (s));
293
294 memcpy (n, info->stack->type, u - info->stack->type);
295 strcpy (n + (u - info->stack->type), s);
296 strcat (n, u + 1);
297
298 free (info->stack->type);
299 info->stack->type = n;
300
416{
417 char *u;
418
419 assert (info->stack != NULL);
420
421 u = strchr (info->stack->type, '|');
422 if (u != NULL)
423 {
424 char *n;
425
426 n = (char *) xmalloc (strlen (info->stack->type) + strlen (s));
427
428 memcpy (n, info->stack->type, u - info->stack->type);
429 strcpy (n + (u - info->stack->type), s);
430 strcat (n, u + 1);
431
432 free (info->stack->type);
433 info->stack->type = n;
434
301 return true;
435 return TRUE;
302 }
303
304 if (strchr (s, '|') != NULL
305 && (strchr (info->stack->type, '{') != NULL
306 || strchr (info->stack->type, '(') != NULL))
307 {
308 if (! prepend_type (info, "(")
309 || ! append_type (info, ")"))
436 }
437
438 if (strchr (s, '|') != NULL
439 && (strchr (info->stack->type, '{') != NULL
440 || strchr (info->stack->type, '(') != NULL))
441 {
442 if (! prepend_type (info, "(")
443 || ! append_type (info, ")"))
310 return false;
444 return FALSE;
311 }
312
313 if (*s == '\0')
445 }
446
447 if (*s == '\0')
314 return true;
448 return TRUE;
315
316 return (append_type (info, " ")
317 && append_type (info, s));
318}
319
320/* Indent the type at the top of the stack by appending spaces. */
321
449
450 return (append_type (info, " ")
451 && append_type (info, s));
452}
453
454/* Indent the type at the top of the stack by appending spaces. */
455
322static boolean
323indent_type (info)
324 struct pr_handle *info;
456static bfd_boolean
457indent_type (struct pr_handle *info)
325{
326 unsigned int i;
327
328 for (i = 0; i < info->indent; i++)
329 {
330 if (! append_type (info, " "))
458{
459 unsigned int i;
460
461 for (i = 0; i < info->indent; i++)
462 {
463 if (! append_type (info, " "))
331 return false;
464 return FALSE;
332 }
333
465 }
466
334 return true;
467 return TRUE;
335}
336
337/* Pop a type from the type stack. */
338
339static char *
468}
469
470/* Pop a type from the type stack. */
471
472static char *
340pop_type (info)
341 struct pr_handle *info;
473pop_type (struct pr_handle *info)
342{
343 struct pr_stack *o;
344 char *ret;
345
346 assert (info->stack != NULL);
347
348 o = info->stack;
349 info->stack = o->next;
350 ret = o->type;
351 free (o);
352
353 return ret;
354}
355
356/* Print a VMA value into a string. */
357
358static void
474{
475 struct pr_stack *o;
476 char *ret;
477
478 assert (info->stack != NULL);
479
480 o = info->stack;
481 info->stack = o->next;
482 ret = o->type;
483 free (o);
484
485 return ret;
486}
487
488/* Print a VMA value into a string. */
489
490static void
359print_vma (vma, buf, unsignedp, hexp)
360 bfd_vma vma;
361 char *buf;
362 boolean unsignedp;
363 boolean hexp;
491print_vma (bfd_vma vma, char *buf, bfd_boolean unsignedp, bfd_boolean hexp)
364{
365 if (sizeof (vma) <= sizeof (unsigned long))
366 {
367 if (hexp)
368 sprintf (buf, "0x%lx", (unsigned long) vma);
369 else if (unsignedp)
370 sprintf (buf, "%lu", (unsigned long) vma);
371 else

--- 4 unchanged lines hidden (view full) ---

376 buf[0] = '0';
377 buf[1] = 'x';
378 sprintf_vma (buf + 2, vma);
379 }
380}
381
382/* Start a new compilation unit. */
383
492{
493 if (sizeof (vma) <= sizeof (unsigned long))
494 {
495 if (hexp)
496 sprintf (buf, "0x%lx", (unsigned long) vma);
497 else if (unsignedp)
498 sprintf (buf, "%lu", (unsigned long) vma);
499 else

--- 4 unchanged lines hidden (view full) ---

504 buf[0] = '0';
505 buf[1] = 'x';
506 sprintf_vma (buf + 2, vma);
507 }
508}
509
510/* Start a new compilation unit. */
511
384static boolean
385pr_start_compilation_unit (p, filename)
386 PTR p;
387 const char *filename;
512static bfd_boolean
513pr_start_compilation_unit (void *p, const char *filename)
388{
389 struct pr_handle *info = (struct pr_handle *) p;
390
391 assert (info->indent == 0);
392
393 fprintf (info->f, "%s:\n", filename);
394
514{
515 struct pr_handle *info = (struct pr_handle *) p;
516
517 assert (info->indent == 0);
518
519 fprintf (info->f, "%s:\n", filename);
520
395 return true;
521 return TRUE;
396}
397
398/* Start a source file within a compilation unit. */
399
522}
523
524/* Start a source file within a compilation unit. */
525
400static boolean
401pr_start_source (p, filename)
402 PTR p;
403 const char *filename;
526static bfd_boolean
527pr_start_source (void *p, const char *filename)
404{
405 struct pr_handle *info = (struct pr_handle *) p;
406
407 assert (info->indent == 0);
408
409 fprintf (info->f, " %s:\n", filename);
410
528{
529 struct pr_handle *info = (struct pr_handle *) p;
530
531 assert (info->indent == 0);
532
533 fprintf (info->f, " %s:\n", filename);
534
411 return true;
535 return TRUE;
412}
413
414/* Push an empty type onto the type stack. */
415
536}
537
538/* Push an empty type onto the type stack. */
539
416static boolean
417pr_empty_type (p)
418 PTR p;
540static bfd_boolean
541pr_empty_type (void *p)
419{
420 struct pr_handle *info = (struct pr_handle *) p;
421
422 return push_type (info, "<undefined>");
423}
424
425/* Push a void type onto the type stack. */
426
542{
543 struct pr_handle *info = (struct pr_handle *) p;
544
545 return push_type (info, "<undefined>");
546}
547
548/* Push a void type onto the type stack. */
549
427static boolean
428pr_void_type (p)
429 PTR p;
550static bfd_boolean
551pr_void_type (void *p)
430{
431 struct pr_handle *info = (struct pr_handle *) p;
432
433 return push_type (info, "void");
434}
435
436/* Push an integer type onto the type stack. */
437
552{
553 struct pr_handle *info = (struct pr_handle *) p;
554
555 return push_type (info, "void");
556}
557
558/* Push an integer type onto the type stack. */
559
438static boolean
439pr_int_type (p, size, unsignedp)
440 PTR p;
441 unsigned int size;
442 boolean unsignedp;
560static bfd_boolean
561pr_int_type (void *p, unsigned int size, bfd_boolean unsignedp)
443{
444 struct pr_handle *info = (struct pr_handle *) p;
445 char ab[10];
446
447 sprintf (ab, "%sint%d", unsignedp ? "u" : "", size * 8);
448 return push_type (info, ab);
449}
450
451/* Push a floating type onto the type stack. */
452
562{
563 struct pr_handle *info = (struct pr_handle *) p;
564 char ab[10];
565
566 sprintf (ab, "%sint%d", unsignedp ? "u" : "", size * 8);
567 return push_type (info, ab);
568}
569
570/* Push a floating type onto the type stack. */
571
453static boolean
454pr_float_type (p, size)
455 PTR p;
456 unsigned int size;
572static bfd_boolean
573pr_float_type (void *p, unsigned int size)
457{
458 struct pr_handle *info = (struct pr_handle *) p;
459 char ab[10];
460
461 if (size == 4)
462 return push_type (info, "float");
463 else if (size == 8)
464 return push_type (info, "double");
465
466 sprintf (ab, "float%d", size * 8);
467 return push_type (info, ab);
468}
469
470/* Push a complex type onto the type stack. */
471
574{
575 struct pr_handle *info = (struct pr_handle *) p;
576 char ab[10];
577
578 if (size == 4)
579 return push_type (info, "float");
580 else if (size == 8)
581 return push_type (info, "double");
582
583 sprintf (ab, "float%d", size * 8);
584 return push_type (info, ab);
585}
586
587/* Push a complex type onto the type stack. */
588
472static boolean
473pr_complex_type (p, size)
474 PTR p;
475 unsigned int size;
589static bfd_boolean
590pr_complex_type (void *p, unsigned int size)
476{
477 struct pr_handle *info = (struct pr_handle *) p;
478
479 if (! pr_float_type (p, size))
591{
592 struct pr_handle *info = (struct pr_handle *) p;
593
594 if (! pr_float_type (p, size))
480 return false;
595 return FALSE;
481
482 return prepend_type (info, "complex ");
483}
484
596
597 return prepend_type (info, "complex ");
598}
599
485/* Push a boolean type onto the type stack. */
600/* Push a bfd_boolean type onto the type stack. */
486
601
487static boolean
488pr_bool_type (p, size)
489 PTR p;
490 unsigned int size;
602static bfd_boolean
603pr_bool_type (void *p, unsigned int size)
491{
492 struct pr_handle *info = (struct pr_handle *) p;
493 char ab[10];
494
495 sprintf (ab, "bool%d", size * 8);
496
497 return push_type (info, ab);
498}
499
500/* Push an enum type onto the type stack. */
501
604{
605 struct pr_handle *info = (struct pr_handle *) p;
606 char ab[10];
607
608 sprintf (ab, "bool%d", size * 8);
609
610 return push_type (info, ab);
611}
612
613/* Push an enum type onto the type stack. */
614
502static boolean
503pr_enum_type (p, tag, names, values)
504 PTR p;
505 const char *tag;
506 const char **names;
507 bfd_signed_vma *values;
615static bfd_boolean
616pr_enum_type (void *p, const char *tag, const char **names,
617 bfd_signed_vma *values)
508{
509 struct pr_handle *info = (struct pr_handle *) p;
510 unsigned int i;
511 bfd_signed_vma val;
512
513 if (! push_type (info, "enum "))
618{
619 struct pr_handle *info = (struct pr_handle *) p;
620 unsigned int i;
621 bfd_signed_vma val;
622
623 if (! push_type (info, "enum "))
514 return false;
624 return FALSE;
515 if (tag != NULL)
516 {
517 if (! append_type (info, tag)
518 || ! append_type (info, " "))
625 if (tag != NULL)
626 {
627 if (! append_type (info, tag)
628 || ! append_type (info, " "))
519 return false;
629 return FALSE;
520 }
521 if (! append_type (info, "{ "))
630 }
631 if (! append_type (info, "{ "))
522 return false;
632 return FALSE;
523
524 if (names == NULL)
525 {
526 if (! append_type (info, "/* undefined */"))
633
634 if (names == NULL)
635 {
636 if (! append_type (info, "/* undefined */"))
527 return false;
637 return FALSE;
528 }
529 else
530 {
531 val = 0;
532 for (i = 0; names[i] != NULL; i++)
533 {
534 if (i > 0)
535 {
536 if (! append_type (info, ", "))
638 }
639 else
640 {
641 val = 0;
642 for (i = 0; names[i] != NULL; i++)
643 {
644 if (i > 0)
645 {
646 if (! append_type (info, ", "))
537 return false;
647 return FALSE;
538 }
539
540 if (! append_type (info, names[i]))
648 }
649
650 if (! append_type (info, names[i]))
541 return false;
651 return FALSE;
542
543 if (values[i] != val)
544 {
545 char ab[20];
546
652
653 if (values[i] != val)
654 {
655 char ab[20];
656
547 print_vma (values[i], ab, false, false);
657 print_vma (values[i], ab, FALSE, FALSE);
548 if (! append_type (info, " = ")
549 || ! append_type (info, ab))
658 if (! append_type (info, " = ")
659 || ! append_type (info, ab))
550 return false;
660 return FALSE;
551 val = values[i];
552 }
553
554 ++val;
555 }
556 }
557
558 return append_type (info, " }");
559}
560
561/* Turn the top type on the stack into a pointer. */
562
661 val = values[i];
662 }
663
664 ++val;
665 }
666 }
667
668 return append_type (info, " }");
669}
670
671/* Turn the top type on the stack into a pointer. */
672
563static boolean
564pr_pointer_type (p)
565 PTR p;
673static bfd_boolean
674pr_pointer_type (void *p)
566{
567 struct pr_handle *info = (struct pr_handle *) p;
568 char *s;
569
570 assert (info->stack != NULL);
571
572 s = strchr (info->stack->type, '|');
573 if (s != NULL && s[1] == '[')
574 return substitute_type (info, "(*|)");
575 return substitute_type (info, "*|");
576}
577
578/* Turn the top type on the stack into a function returning that type. */
579
675{
676 struct pr_handle *info = (struct pr_handle *) p;
677 char *s;
678
679 assert (info->stack != NULL);
680
681 s = strchr (info->stack->type, '|');
682 if (s != NULL && s[1] == '[')
683 return substitute_type (info, "(*|)");
684 return substitute_type (info, "*|");
685}
686
687/* Turn the top type on the stack into a function returning that type. */
688
580static boolean
581pr_function_type (p, argcount, varargs)
582 PTR p;
583 int argcount;
584 boolean varargs;
689static bfd_boolean
690pr_function_type (void *p, int argcount, bfd_boolean varargs)
585{
586 struct pr_handle *info = (struct pr_handle *) p;
587 char **arg_types;
588 unsigned int len;
589 char *s;
590
591 assert (info->stack != NULL);
592

--- 7 unchanged lines hidden (view full) ---

600 else
601 {
602 int i;
603
604 arg_types = (char **) xmalloc (argcount * sizeof *arg_types);
605 for (i = argcount - 1; i >= 0; i--)
606 {
607 if (! substitute_type (info, ""))
691{
692 struct pr_handle *info = (struct pr_handle *) p;
693 char **arg_types;
694 unsigned int len;
695 char *s;
696
697 assert (info->stack != NULL);
698

--- 7 unchanged lines hidden (view full) ---

706 else
707 {
708 int i;
709
710 arg_types = (char **) xmalloc (argcount * sizeof *arg_types);
711 for (i = argcount - 1; i >= 0; i--)
712 {
713 if (! substitute_type (info, ""))
608 return false;
714 return FALSE;
609 arg_types[i] = pop_type (info);
610 if (arg_types[i] == NULL)
715 arg_types[i] = pop_type (info);
716 if (arg_types[i] == NULL)
611 return false;
717 return FALSE;
612 len += strlen (arg_types[i]) + 2;
613 }
614 if (varargs)
615 len += 5;
616 }
617
618 /* Now the return type is on the top of the stack. */
619

--- 20 unchanged lines hidden (view full) ---

640 }
641 if (argcount > 0)
642 free (arg_types);
643 }
644
645 strcat (s, ")");
646
647 if (! substitute_type (info, s))
718 len += strlen (arg_types[i]) + 2;
719 }
720 if (varargs)
721 len += 5;
722 }
723
724 /* Now the return type is on the top of the stack. */
725

--- 20 unchanged lines hidden (view full) ---

746 }
747 if (argcount > 0)
748 free (arg_types);
749 }
750
751 strcat (s, ")");
752
753 if (! substitute_type (info, s))
648 return false;
754 return FALSE;
649
650 free (s);
651
755
756 free (s);
757
652 return true;
758 return TRUE;
653}
654
655/* Turn the top type on the stack into a reference to that type. */
656
759}
760
761/* Turn the top type on the stack into a reference to that type. */
762
657static boolean
658pr_reference_type (p)
659 PTR p;
763static bfd_boolean
764pr_reference_type (void *p)
660{
661 struct pr_handle *info = (struct pr_handle *) p;
662
663 assert (info->stack != NULL);
664
665 return substitute_type (info, "&|");
666}
667
668/* Make a range type. */
669
765{
766 struct pr_handle *info = (struct pr_handle *) p;
767
768 assert (info->stack != NULL);
769
770 return substitute_type (info, "&|");
771}
772
773/* Make a range type. */
774
670static boolean
671pr_range_type (p, lower, upper)
672 PTR p;
673 bfd_signed_vma lower;
674 bfd_signed_vma upper;
775static bfd_boolean
776pr_range_type (void *p, bfd_signed_vma lower, bfd_signed_vma upper)
675{
676 struct pr_handle *info = (struct pr_handle *) p;
677 char abl[20], abu[20];
678
679 assert (info->stack != NULL);
680
681 if (! substitute_type (info, ""))
777{
778 struct pr_handle *info = (struct pr_handle *) p;
779 char abl[20], abu[20];
780
781 assert (info->stack != NULL);
782
783 if (! substitute_type (info, ""))
682 return false;
784 return FALSE;
683
785
684 print_vma (lower, abl, false, false);
685 print_vma (upper, abu, false, false);
786 print_vma (lower, abl, FALSE, FALSE);
787 print_vma (upper, abu, FALSE, FALSE);
686
687 return (prepend_type (info, "range (")
688 && append_type (info, "):")
689 && append_type (info, abl)
690 && append_type (info, ":")
691 && append_type (info, abu));
692}
693
694/* Make an array type. */
695
788
789 return (prepend_type (info, "range (")
790 && append_type (info, "):")
791 && append_type (info, abl)
792 && append_type (info, ":")
793 && append_type (info, abu));
794}
795
796/* Make an array type. */
797
696static boolean
697pr_array_type (p, lower, upper, stringp)
698 PTR p;
699 bfd_signed_vma lower;
700 bfd_signed_vma upper;
701 boolean stringp;
798static bfd_boolean
799pr_array_type (void *p, bfd_signed_vma lower, bfd_signed_vma upper,
800 bfd_boolean stringp)
702{
703 struct pr_handle *info = (struct pr_handle *) p;
704 char *range_type;
705 char abl[20], abu[20], ab[50];
706
707 range_type = pop_type (info);
708 if (range_type == NULL)
801{
802 struct pr_handle *info = (struct pr_handle *) p;
803 char *range_type;
804 char abl[20], abu[20], ab[50];
805
806 range_type = pop_type (info);
807 if (range_type == NULL)
709 return false;
808 return FALSE;
710
711 if (lower == 0)
712 {
713 if (upper == -1)
714 sprintf (ab, "|[]");
715 else
716 {
809
810 if (lower == 0)
811 {
812 if (upper == -1)
813 sprintf (ab, "|[]");
814 else
815 {
717 print_vma (upper + 1, abu, false, false);
816 print_vma (upper + 1, abu, FALSE, FALSE);
718 sprintf (ab, "|[%s]", abu);
719 }
720 }
721 else
722 {
817 sprintf (ab, "|[%s]", abu);
818 }
819 }
820 else
821 {
723 print_vma (lower, abl, false, false);
724 print_vma (upper, abu, false, false);
822 print_vma (lower, abl, FALSE, FALSE);
823 print_vma (upper, abu, FALSE, FALSE);
725 sprintf (ab, "|[%s:%s]", abl, abu);
726 }
727
728 if (! substitute_type (info, ab))
824 sprintf (ab, "|[%s:%s]", abl, abu);
825 }
826
827 if (! substitute_type (info, ab))
729 return false;
828 return FALSE;
730
731 if (strcmp (range_type, "int") != 0)
732 {
733 if (! append_type (info, ":")
734 || ! append_type (info, range_type))
829
830 if (strcmp (range_type, "int") != 0)
831 {
832 if (! append_type (info, ":")
833 || ! append_type (info, range_type))
735 return false;
834 return FALSE;
736 }
737
738 if (stringp)
739 {
740 if (! append_type (info, " /* string */"))
835 }
836
837 if (stringp)
838 {
839 if (! append_type (info, " /* string */"))
741 return false;
840 return FALSE;
742 }
743
841 }
842
744 return true;
843 return TRUE;
745}
746
747/* Make a set type. */
748
844}
845
846/* Make a set type. */
847
749static boolean
750pr_set_type (p, bitstringp)
751 PTR p;
752 boolean bitstringp;
848static bfd_boolean
849pr_set_type (void *p, bfd_boolean bitstringp)
753{
754 struct pr_handle *info = (struct pr_handle *) p;
755
756 if (! substitute_type (info, ""))
850{
851 struct pr_handle *info = (struct pr_handle *) p;
852
853 if (! substitute_type (info, ""))
757 return false;
854 return FALSE;
758
759 if (! prepend_type (info, "set { ")
760 || ! append_type (info, " }"))
855
856 if (! prepend_type (info, "set { ")
857 || ! append_type (info, " }"))
761 return false;
858 return FALSE;
762
763 if (bitstringp)
764 {
765 if (! append_type (info, "/* bitstring */"))
859
860 if (bitstringp)
861 {
862 if (! append_type (info, "/* bitstring */"))
766 return false;
863 return FALSE;
767 }
768
864 }
865
769 return true;
866 return TRUE;
770}
771
772/* Make an offset type. */
773
867}
868
869/* Make an offset type. */
870
774static boolean
775pr_offset_type (p)
776 PTR p;
871static bfd_boolean
872pr_offset_type (void *p)
777{
778 struct pr_handle *info = (struct pr_handle *) p;
779 char *t;
780
781 if (! substitute_type (info, ""))
873{
874 struct pr_handle *info = (struct pr_handle *) p;
875 char *t;
876
877 if (! substitute_type (info, ""))
782 return false;
878 return FALSE;
783
784 t = pop_type (info);
785 if (t == NULL)
879
880 t = pop_type (info);
881 if (t == NULL)
786 return false;
882 return FALSE;
787
788 return (substitute_type (info, "")
789 && prepend_type (info, " ")
790 && prepend_type (info, t)
791 && append_type (info, "::|"));
792}
793
794/* Make a method type. */
795
883
884 return (substitute_type (info, "")
885 && prepend_type (info, " ")
886 && prepend_type (info, t)
887 && append_type (info, "::|"));
888}
889
890/* Make a method type. */
891
796static boolean
797pr_method_type (p, domain, argcount, varargs)
798 PTR p;
799 boolean domain;
800 int argcount;
801 boolean varargs;
892static bfd_boolean
893pr_method_type (void *p, bfd_boolean domain, int argcount, bfd_boolean varargs)
802{
803 struct pr_handle *info = (struct pr_handle *) p;
804 unsigned int len;
805 char *domain_type;
806 char **arg_types;
807 char *s;
808
809 len = 10;
810
811 if (! domain)
812 domain_type = NULL;
813 else
814 {
815 if (! substitute_type (info, ""))
894{
895 struct pr_handle *info = (struct pr_handle *) p;
896 unsigned int len;
897 char *domain_type;
898 char **arg_types;
899 char *s;
900
901 len = 10;
902
903 if (! domain)
904 domain_type = NULL;
905 else
906 {
907 if (! substitute_type (info, ""))
816 return false;
908 return FALSE;
817 domain_type = pop_type (info);
818 if (domain_type == NULL)
909 domain_type = pop_type (info);
910 if (domain_type == NULL)
819 return false;
911 return FALSE;
820 if (strncmp (domain_type, "class ", sizeof "class " - 1) == 0
821 && strchr (domain_type + sizeof "class " - 1, ' ') == NULL)
822 domain_type += sizeof "class " - 1;
823 else if (strncmp (domain_type, "union class ",
824 sizeof "union class ") == 0
825 && (strchr (domain_type + sizeof "union class " - 1, ' ')
826 == NULL))
827 domain_type += sizeof "union class " - 1;

--- 8 unchanged lines hidden (view full) ---

836 else
837 {
838 int i;
839
840 arg_types = (char **) xmalloc (argcount * sizeof *arg_types);
841 for (i = argcount - 1; i >= 0; i--)
842 {
843 if (! substitute_type (info, ""))
912 if (strncmp (domain_type, "class ", sizeof "class " - 1) == 0
913 && strchr (domain_type + sizeof "class " - 1, ' ') == NULL)
914 domain_type += sizeof "class " - 1;
915 else if (strncmp (domain_type, "union class ",
916 sizeof "union class ") == 0
917 && (strchr (domain_type + sizeof "union class " - 1, ' ')
918 == NULL))
919 domain_type += sizeof "union class " - 1;

--- 8 unchanged lines hidden (view full) ---

928 else
929 {
930 int i;
931
932 arg_types = (char **) xmalloc (argcount * sizeof *arg_types);
933 for (i = argcount - 1; i >= 0; i--)
934 {
935 if (! substitute_type (info, ""))
844 return false;
936 return FALSE;
845 arg_types[i] = pop_type (info);
846 if (arg_types[i] == NULL)
937 arg_types[i] = pop_type (info);
938 if (arg_types[i] == NULL)
847 return false;
939 return FALSE;
848 len += strlen (arg_types[i]) + 2;
849 }
850 if (varargs)
851 len += 5;
852 }
853
854 /* Now the return type is on the top of the stack. */
855

--- 24 unchanged lines hidden (view full) ---

880 }
881 if (argcount > 0)
882 free (arg_types);
883 }
884
885 strcat (s, ")");
886
887 if (! substitute_type (info, s))
940 len += strlen (arg_types[i]) + 2;
941 }
942 if (varargs)
943 len += 5;
944 }
945
946 /* Now the return type is on the top of the stack. */
947

--- 24 unchanged lines hidden (view full) ---

972 }
973 if (argcount > 0)
974 free (arg_types);
975 }
976
977 strcat (s, ")");
978
979 if (! substitute_type (info, s))
888 return false;
980 return FALSE;
889
890 free (s);
891
981
982 free (s);
983
892 return true;
984 return TRUE;
893}
894
895/* Make a const qualified type. */
896
985}
986
987/* Make a const qualified type. */
988
897static boolean
898pr_const_type (p)
899 PTR p;
989static bfd_boolean
990pr_const_type (void *p)
900{
901 struct pr_handle *info = (struct pr_handle *) p;
902
903 return substitute_type (info, "const |");
904}
905
906/* Make a volatile qualified type. */
907
991{
992 struct pr_handle *info = (struct pr_handle *) p;
993
994 return substitute_type (info, "const |");
995}
996
997/* Make a volatile qualified type. */
998
908static boolean
909pr_volatile_type (p)
910 PTR p;
999static bfd_boolean
1000pr_volatile_type (void *p)
911{
912 struct pr_handle *info = (struct pr_handle *) p;
913
914 return substitute_type (info, "volatile |");
915}
916
917/* Start accumulating a struct type. */
918
1001{
1002 struct pr_handle *info = (struct pr_handle *) p;
1003
1004 return substitute_type (info, "volatile |");
1005}
1006
1007/* Start accumulating a struct type. */
1008
919static boolean
920pr_start_struct_type (p, tag, id, structp, size)
921 PTR p;
922 const char *tag;
923 unsigned int id;
924 boolean structp;
925 unsigned int size;
1009static bfd_boolean
1010pr_start_struct_type (void *p, const char *tag, unsigned int id,
1011 bfd_boolean structp, unsigned int size)
926{
927 struct pr_handle *info = (struct pr_handle *) p;
928
929 info->indent += 2;
930
931 if (! push_type (info, structp ? "struct " : "union "))
1012{
1013 struct pr_handle *info = (struct pr_handle *) p;
1014
1015 info->indent += 2;
1016
1017 if (! push_type (info, structp ? "struct " : "union "))
932 return false;
1018 return FALSE;
933 if (tag != NULL)
934 {
935 if (! append_type (info, tag))
1019 if (tag != NULL)
1020 {
1021 if (! append_type (info, tag))
936 return false;
1022 return FALSE;
937 }
938 else
939 {
940 char idbuf[20];
941
942 sprintf (idbuf, "%%anon%u", id);
943 if (! append_type (info, idbuf))
1023 }
1024 else
1025 {
1026 char idbuf[20];
1027
1028 sprintf (idbuf, "%%anon%u", id);
1029 if (! append_type (info, idbuf))
944 return false;
1030 return FALSE;
945 }
946
947 if (! append_type (info, " {"))
1031 }
1032
1033 if (! append_type (info, " {"))
948 return false;
1034 return FALSE;
949 if (size != 0 || tag != NULL)
950 {
951 char ab[30];
952
953 if (! append_type (info, " /*"))
1035 if (size != 0 || tag != NULL)
1036 {
1037 char ab[30];
1038
1039 if (! append_type (info, " /*"))
954 return false;
1040 return FALSE;
955
956 if (size != 0)
957 {
958 sprintf (ab, " size %u", size);
959 if (! append_type (info, ab))
1041
1042 if (size != 0)
1043 {
1044 sprintf (ab, " size %u", size);
1045 if (! append_type (info, ab))
960 return false;
1046 return FALSE;
961 }
962 if (tag != NULL)
963 {
964 sprintf (ab, " id %u", id);
965 if (! append_type (info, ab))
1047 }
1048 if (tag != NULL)
1049 {
1050 sprintf (ab, " id %u", id);
1051 if (! append_type (info, ab))
966 return false;
1052 return FALSE;
967 }
968 if (! append_type (info, " */"))
1053 }
1054 if (! append_type (info, " */"))
969 return false;
1055 return FALSE;
970 }
971 if (! append_type (info, "\n"))
1056 }
1057 if (! append_type (info, "\n"))
972 return false;
1058 return FALSE;
973
974 info->stack->visibility = DEBUG_VISIBILITY_PUBLIC;
975
976 return indent_type (info);
977}
978
979/* Output the visibility of a field in a struct. */
980
1059
1060 info->stack->visibility = DEBUG_VISIBILITY_PUBLIC;
1061
1062 return indent_type (info);
1063}
1064
1065/* Output the visibility of a field in a struct. */
1066
981static boolean
982pr_fix_visibility (info, visibility)
983 struct pr_handle *info;
984 enum debug_visibility visibility;
1067static bfd_boolean
1068pr_fix_visibility (struct pr_handle *info, enum debug_visibility visibility)
985{
986 const char *s = NULL;
987 char *t;
988 unsigned int len;
989
990 assert (info->stack != NULL);
991
992 if (info->stack->visibility == visibility)
1069{
1070 const char *s = NULL;
1071 char *t;
1072 unsigned int len;
1073
1074 assert (info->stack != NULL);
1075
1076 if (info->stack->visibility == visibility)
993 return true;
1077 return TRUE;
994
1078
995 assert (info->stack->visibility != DEBUG_VISIBILITY_IGNORE);
996
997 switch (visibility)
998 {
999 case DEBUG_VISIBILITY_PUBLIC:
1000 s = "public";
1001 break;
1002 case DEBUG_VISIBILITY_PRIVATE:
1003 s = "private";
1004 break;
1005 case DEBUG_VISIBILITY_PROTECTED:
1006 s = "protected";
1007 break;
1008 case DEBUG_VISIBILITY_IGNORE:
1009 s = "/* ignore */";
1010 break;
1011 default:
1012 abort ();
1079 switch (visibility)
1080 {
1081 case DEBUG_VISIBILITY_PUBLIC:
1082 s = "public";
1083 break;
1084 case DEBUG_VISIBILITY_PRIVATE:
1085 s = "private";
1086 break;
1087 case DEBUG_VISIBILITY_PROTECTED:
1088 s = "protected";
1089 break;
1090 case DEBUG_VISIBILITY_IGNORE:
1091 s = "/* ignore */";
1092 break;
1093 default:
1094 abort ();
1013 return false;
1095 return FALSE;
1014 }
1015
1016 /* Trim off a trailing space in the struct string, to make the
1017 output look a bit better, then stick on the visibility string. */
1018
1019 t = info->stack->type;
1020 len = strlen (t);
1021 assert (t[len - 1] == ' ');
1022 t[len - 1] = '\0';
1023
1024 if (! append_type (info, s)
1025 || ! append_type (info, ":\n")
1026 || ! indent_type (info))
1096 }
1097
1098 /* Trim off a trailing space in the struct string, to make the
1099 output look a bit better, then stick on the visibility string. */
1100
1101 t = info->stack->type;
1102 len = strlen (t);
1103 assert (t[len - 1] == ' ');
1104 t[len - 1] = '\0';
1105
1106 if (! append_type (info, s)
1107 || ! append_type (info, ":\n")
1108 || ! indent_type (info))
1027 return false;
1109 return FALSE;
1028
1029 info->stack->visibility = visibility;
1030
1110
1111 info->stack->visibility = visibility;
1112
1031 return true;
1113 return TRUE;
1032}
1033
1034/* Add a field to a struct type. */
1035
1114}
1115
1116/* Add a field to a struct type. */
1117
1036static boolean
1037pr_struct_field (p, name, bitpos, bitsize, visibility)
1038 PTR p;
1039 const char *name;
1040 bfd_vma bitpos;
1041 bfd_vma bitsize;
1042 enum debug_visibility visibility;
1118static bfd_boolean
1119pr_struct_field (void *p, const char *name, bfd_vma bitpos, bfd_vma bitsize,
1120 enum debug_visibility visibility)
1043{
1044 struct pr_handle *info = (struct pr_handle *) p;
1045 char ab[20];
1046 char *t;
1047
1048 if (! substitute_type (info, name))
1121{
1122 struct pr_handle *info = (struct pr_handle *) p;
1123 char ab[20];
1124 char *t;
1125
1126 if (! substitute_type (info, name))
1049 return false;
1127 return FALSE;
1050
1051 if (! append_type (info, "; /* "))
1128
1129 if (! append_type (info, "; /* "))
1052 return false;
1130 return FALSE;
1053
1054 if (bitsize != 0)
1055 {
1131
1132 if (bitsize != 0)
1133 {
1056 print_vma (bitsize, ab, true, false);
1134 print_vma (bitsize, ab, TRUE, FALSE);
1057 if (! append_type (info, "bitsize ")
1058 || ! append_type (info, ab)
1059 || ! append_type (info, ", "))
1135 if (! append_type (info, "bitsize ")
1136 || ! append_type (info, ab)
1137 || ! append_type (info, ", "))
1060 return false;
1138 return FALSE;
1061 }
1062
1139 }
1140
1063 print_vma (bitpos, ab, true, false);
1141 print_vma (bitpos, ab, TRUE, FALSE);
1064 if (! append_type (info, "bitpos ")
1065 || ! append_type (info, ab)
1066 || ! append_type (info, " */\n")
1067 || ! indent_type (info))
1142 if (! append_type (info, "bitpos ")
1143 || ! append_type (info, ab)
1144 || ! append_type (info, " */\n")
1145 || ! indent_type (info))
1068 return false;
1146 return FALSE;
1069
1070 t = pop_type (info);
1071 if (t == NULL)
1147
1148 t = pop_type (info);
1149 if (t == NULL)
1072 return false;
1150 return FALSE;
1073
1074 if (! pr_fix_visibility (info, visibility))
1151
1152 if (! pr_fix_visibility (info, visibility))
1075 return false;
1153 return FALSE;
1076
1077 return append_type (info, t);
1078}
1079
1080/* Finish a struct type. */
1081
1154
1155 return append_type (info, t);
1156}
1157
1158/* Finish a struct type. */
1159
1082static boolean
1083pr_end_struct_type (p)
1084 PTR p;
1160static bfd_boolean
1161pr_end_struct_type (void *p)
1085{
1086 struct pr_handle *info = (struct pr_handle *) p;
1087 char *s;
1088
1089 assert (info->stack != NULL);
1090 assert (info->indent >= 2);
1091
1092 info->indent -= 2;
1093
1094 /* Change the trailing indentation to have a close brace. */
1095 s = info->stack->type + strlen (info->stack->type) - 2;
1096 assert (s[0] == ' ' && s[1] == ' ' && s[2] == '\0');
1097
1098 *s++ = '}';
1099 *s = '\0';
1100
1162{
1163 struct pr_handle *info = (struct pr_handle *) p;
1164 char *s;
1165
1166 assert (info->stack != NULL);
1167 assert (info->indent >= 2);
1168
1169 info->indent -= 2;
1170
1171 /* Change the trailing indentation to have a close brace. */
1172 s = info->stack->type + strlen (info->stack->type) - 2;
1173 assert (s[0] == ' ' && s[1] == ' ' && s[2] == '\0');
1174
1175 *s++ = '}';
1176 *s = '\0';
1177
1101 return true;
1178 return TRUE;
1102}
1103
1104/* Start a class type. */
1105
1179}
1180
1181/* Start a class type. */
1182
1106static boolean
1107pr_start_class_type (p, tag, id, structp, size, vptr, ownvptr)
1108 PTR p;
1109 const char *tag;
1110 unsigned int id;
1111 boolean structp;
1112 unsigned int size;
1113 boolean vptr;
1114 boolean ownvptr;
1183static bfd_boolean
1184pr_start_class_type (void *p, const char *tag, unsigned int id,
1185 bfd_boolean structp, unsigned int size,
1186 bfd_boolean vptr, bfd_boolean ownvptr)
1115{
1116 struct pr_handle *info = (struct pr_handle *) p;
1117 char *tv = NULL;
1118
1119 info->indent += 2;
1120
1121 if (vptr && ! ownvptr)
1122 {
1123 tv = pop_type (info);
1124 if (tv == NULL)
1187{
1188 struct pr_handle *info = (struct pr_handle *) p;
1189 char *tv = NULL;
1190
1191 info->indent += 2;
1192
1193 if (vptr && ! ownvptr)
1194 {
1195 tv = pop_type (info);
1196 if (tv == NULL)
1125 return false;
1197 return FALSE;
1126 }
1127
1128 if (! push_type (info, structp ? "class " : "union class "))
1198 }
1199
1200 if (! push_type (info, structp ? "class " : "union class "))
1129 return false;
1201 return FALSE;
1130 if (tag != NULL)
1131 {
1132 if (! append_type (info, tag))
1202 if (tag != NULL)
1203 {
1204 if (! append_type (info, tag))
1133 return false;
1205 return FALSE;
1134 }
1135 else
1136 {
1137 char idbuf[20];
1138
1139 sprintf (idbuf, "%%anon%u", id);
1140 if (! append_type (info, idbuf))
1206 }
1207 else
1208 {
1209 char idbuf[20];
1210
1211 sprintf (idbuf, "%%anon%u", id);
1212 if (! append_type (info, idbuf))
1141 return false;
1213 return FALSE;
1142 }
1143
1144 if (! append_type (info, " {"))
1214 }
1215
1216 if (! append_type (info, " {"))
1145 return false;
1217 return FALSE;
1146 if (size != 0 || vptr || ownvptr || tag != NULL)
1147 {
1148 if (! append_type (info, " /*"))
1218 if (size != 0 || vptr || ownvptr || tag != NULL)
1219 {
1220 if (! append_type (info, " /*"))
1149 return false;
1221 return FALSE;
1150
1151 if (size != 0)
1152 {
1153 char ab[20];
1154
1155 sprintf (ab, "%u", size);
1156 if (! append_type (info, " size ")
1157 || ! append_type (info, ab))
1222
1223 if (size != 0)
1224 {
1225 char ab[20];
1226
1227 sprintf (ab, "%u", size);
1228 if (! append_type (info, " size ")
1229 || ! append_type (info, ab))
1158 return false;
1230 return FALSE;
1159 }
1160
1161 if (vptr)
1162 {
1163 if (! append_type (info, " vtable "))
1231 }
1232
1233 if (vptr)
1234 {
1235 if (! append_type (info, " vtable "))
1164 return false;
1236 return FALSE;
1165 if (ownvptr)
1166 {
1167 if (! append_type (info, "self "))
1237 if (ownvptr)
1238 {
1239 if (! append_type (info, "self "))
1168 return false;
1240 return FALSE;
1169 }
1170 else
1171 {
1172 if (! append_type (info, tv)
1173 || ! append_type (info, " "))
1241 }
1242 else
1243 {
1244 if (! append_type (info, tv)
1245 || ! append_type (info, " "))
1174 return false;
1246 return FALSE;
1175 }
1176 }
1177
1178 if (tag != NULL)
1179 {
1180 char ab[30];
1181
1182 sprintf (ab, " id %u", id);
1183 if (! append_type (info, ab))
1247 }
1248 }
1249
1250 if (tag != NULL)
1251 {
1252 char ab[30];
1253
1254 sprintf (ab, " id %u", id);
1255 if (! append_type (info, ab))
1184 return false;
1256 return FALSE;
1185 }
1186
1187 if (! append_type (info, " */"))
1257 }
1258
1259 if (! append_type (info, " */"))
1188 return false;
1260 return FALSE;
1189 }
1190
1191 info->stack->visibility = DEBUG_VISIBILITY_PRIVATE;
1192
1193 return (append_type (info, "\n")
1194 && indent_type (info));
1195}
1196
1197/* Add a static member to a class. */
1198
1261 }
1262
1263 info->stack->visibility = DEBUG_VISIBILITY_PRIVATE;
1264
1265 return (append_type (info, "\n")
1266 && indent_type (info));
1267}
1268
1269/* Add a static member to a class. */
1270
1199static boolean
1200pr_class_static_member (p, name, physname, visibility)
1201 PTR p;
1202 const char *name;
1203 const char *physname;
1204 enum debug_visibility visibility;
1271static bfd_boolean
1272pr_class_static_member (void *p, const char *name, const char *physname,
1273 enum debug_visibility visibility)
1205{
1206 struct pr_handle *info = (struct pr_handle *) p;
1207 char *t;
1208
1209 if (! substitute_type (info, name))
1274{
1275 struct pr_handle *info = (struct pr_handle *) p;
1276 char *t;
1277
1278 if (! substitute_type (info, name))
1210 return false;
1279 return FALSE;
1211
1212 if (! prepend_type (info, "static ")
1213 || ! append_type (info, "; /* ")
1214 || ! append_type (info, physname)
1215 || ! append_type (info, " */\n")
1216 || ! indent_type (info))
1280
1281 if (! prepend_type (info, "static ")
1282 || ! append_type (info, "; /* ")
1283 || ! append_type (info, physname)
1284 || ! append_type (info, " */\n")
1285 || ! indent_type (info))
1217 return false;
1286 return FALSE;
1218
1219 t = pop_type (info);
1220 if (t == NULL)
1287
1288 t = pop_type (info);
1289 if (t == NULL)
1221 return false;
1290 return FALSE;
1222
1223 if (! pr_fix_visibility (info, visibility))
1291
1292 if (! pr_fix_visibility (info, visibility))
1224 return false;
1293 return FALSE;
1225
1226 return append_type (info, t);
1227}
1228
1229/* Add a base class to a class. */
1230
1294
1295 return append_type (info, t);
1296}
1297
1298/* Add a base class to a class. */
1299
1231static boolean
1232pr_class_baseclass (p, bitpos, virtual, visibility)
1233 PTR p;
1234 bfd_vma bitpos;
1235 boolean virtual;
1236 enum debug_visibility visibility;
1300static bfd_boolean
1301pr_class_baseclass (void *p, bfd_vma bitpos, bfd_boolean virtual,
1302 enum debug_visibility visibility)
1237{
1238 struct pr_handle *info = (struct pr_handle *) p;
1239 char *t;
1240 const char *prefix;
1241 char ab[20];
1242 char *s, *l, *n;
1243
1244 assert (info->stack != NULL && info->stack->next != NULL);
1245
1246 if (! substitute_type (info, ""))
1303{
1304 struct pr_handle *info = (struct pr_handle *) p;
1305 char *t;
1306 const char *prefix;
1307 char ab[20];
1308 char *s, *l, *n;
1309
1310 assert (info->stack != NULL && info->stack->next != NULL);
1311
1312 if (! substitute_type (info, ""))
1247 return false;
1313 return FALSE;
1248
1249 t = pop_type (info);
1250 if (t == NULL)
1314
1315 t = pop_type (info);
1316 if (t == NULL)
1251 return false;
1317 return FALSE;
1252
1253 if (strncmp (t, "class ", sizeof "class " - 1) == 0)
1254 t += sizeof "class " - 1;
1255
1256 /* Push it back on to take advantage of the prepend_type and
1257 append_type routines. */
1258 if (! push_type (info, t))
1318
1319 if (strncmp (t, "class ", sizeof "class " - 1) == 0)
1320 t += sizeof "class " - 1;
1321
1322 /* Push it back on to take advantage of the prepend_type and
1323 append_type routines. */
1324 if (! push_type (info, t))
1259 return false;
1325 return FALSE;
1260
1261 if (virtual)
1262 {
1263 if (! prepend_type (info, "virtual "))
1326
1327 if (virtual)
1328 {
1329 if (! prepend_type (info, "virtual "))
1264 return false;
1330 return FALSE;
1265 }
1266
1267 switch (visibility)
1268 {
1269 case DEBUG_VISIBILITY_PUBLIC:
1270 prefix = "public ";
1271 break;
1272 case DEBUG_VISIBILITY_PROTECTED:
1273 prefix = "protected ";
1274 break;
1275 case DEBUG_VISIBILITY_PRIVATE:
1276 prefix = "private ";
1277 break;
1278 default:
1279 prefix = "/* unknown visibility */ ";
1280 break;
1281 }
1282
1283 if (! prepend_type (info, prefix))
1331 }
1332
1333 switch (visibility)
1334 {
1335 case DEBUG_VISIBILITY_PUBLIC:
1336 prefix = "public ";
1337 break;
1338 case DEBUG_VISIBILITY_PROTECTED:
1339 prefix = "protected ";
1340 break;
1341 case DEBUG_VISIBILITY_PRIVATE:
1342 prefix = "private ";
1343 break;
1344 default:
1345 prefix = "/* unknown visibility */ ";
1346 break;
1347 }
1348
1349 if (! prepend_type (info, prefix))
1284 return false;
1350 return FALSE;
1285
1286 if (bitpos != 0)
1287 {
1351
1352 if (bitpos != 0)
1353 {
1288 print_vma (bitpos, ab, true, false);
1354 print_vma (bitpos, ab, TRUE, FALSE);
1289 if (! append_type (info, " /* bitpos ")
1290 || ! append_type (info, ab)
1291 || ! append_type (info, " */"))
1355 if (! append_type (info, " /* bitpos ")
1356 || ! append_type (info, ab)
1357 || ! append_type (info, " */"))
1292 return false;
1358 return FALSE;
1293 }
1294
1295 /* Now the top of the stack is something like "public A / * bitpos
1296 10 * /". The next element on the stack is something like "class
1297 xx { / * size 8 * /\n...". We want to substitute the top of the
1298 stack in before the {. */
1299 s = strchr (info->stack->next->type, '{');
1300 assert (s != NULL);
1301 --s;
1302
1303 /* If there is already a ':', then we already have a baseclass, and
1304 we must append this one after a comma. */
1305 for (l = info->stack->next->type; l != s; l++)
1306 if (*l == ':')
1307 break;
1308 if (! prepend_type (info, l == s ? " : " : ", "))
1359 }
1360
1361 /* Now the top of the stack is something like "public A / * bitpos
1362 10 * /". The next element on the stack is something like "class
1363 xx { / * size 8 * /\n...". We want to substitute the top of the
1364 stack in before the {. */
1365 s = strchr (info->stack->next->type, '{');
1366 assert (s != NULL);
1367 --s;
1368
1369 /* If there is already a ':', then we already have a baseclass, and
1370 we must append this one after a comma. */
1371 for (l = info->stack->next->type; l != s; l++)
1372 if (*l == ':')
1373 break;
1374 if (! prepend_type (info, l == s ? " : " : ", "))
1309 return false;
1375 return FALSE;
1310
1311 t = pop_type (info);
1312 if (t == NULL)
1376
1377 t = pop_type (info);
1378 if (t == NULL)
1313 return false;
1379 return FALSE;
1314
1315 n = (char *) xmalloc (strlen (info->stack->type) + strlen (t) + 1);
1316 memcpy (n, info->stack->type, s - info->stack->type);
1317 strcpy (n + (s - info->stack->type), t);
1318 strcat (n, s);
1319
1320 free (info->stack->type);
1321 info->stack->type = n;
1322
1323 free (t);
1324
1380
1381 n = (char *) xmalloc (strlen (info->stack->type) + strlen (t) + 1);
1382 memcpy (n, info->stack->type, s - info->stack->type);
1383 strcpy (n + (s - info->stack->type), t);
1384 strcat (n, s);
1385
1386 free (info->stack->type);
1387 info->stack->type = n;
1388
1389 free (t);
1390
1325 return true;
1391 return TRUE;
1326}
1327
1328/* Start adding a method to a class. */
1329
1392}
1393
1394/* Start adding a method to a class. */
1395
1330static boolean
1331pr_class_start_method (p, name)
1332 PTR p;
1333 const char *name;
1396static bfd_boolean
1397pr_class_start_method (void *p, const char *name)
1334{
1335 struct pr_handle *info = (struct pr_handle *) p;
1336
1337 assert (info->stack != NULL);
1338 info->stack->method = name;
1398{
1399 struct pr_handle *info = (struct pr_handle *) p;
1400
1401 assert (info->stack != NULL);
1402 info->stack->method = name;
1339 return true;
1403 return TRUE;
1340}
1341
1342/* Add a variant to a method. */
1343
1404}
1405
1406/* Add a variant to a method. */
1407
1344static boolean
1345pr_class_method_variant (p, physname, visibility, constp, volatilep, voffset,
1346 context)
1347 PTR p;
1348 const char *physname;
1349 enum debug_visibility visibility;
1350 boolean constp;
1351 boolean volatilep;
1352 bfd_vma voffset;
1353 boolean context;
1408static bfd_boolean
1409pr_class_method_variant (void *p, const char *physname,
1410 enum debug_visibility visibility,
1411 bfd_boolean constp, bfd_boolean volatilep,
1412 bfd_vma voffset, bfd_boolean context)
1354{
1355 struct pr_handle *info = (struct pr_handle *) p;
1356 char *method_type;
1357 char *context_type;
1358
1359 assert (info->stack != NULL);
1360 assert (info->stack->next != NULL);
1361
1362 /* Put the const and volatile qualifiers on the type. */
1363 if (volatilep)
1364 {
1365 if (! append_type (info, " volatile"))
1413{
1414 struct pr_handle *info = (struct pr_handle *) p;
1415 char *method_type;
1416 char *context_type;
1417
1418 assert (info->stack != NULL);
1419 assert (info->stack->next != NULL);
1420
1421 /* Put the const and volatile qualifiers on the type. */
1422 if (volatilep)
1423 {
1424 if (! append_type (info, " volatile"))
1366 return false;
1425 return FALSE;
1367 }
1368 if (constp)
1369 {
1370 if (! append_type (info, " const"))
1426 }
1427 if (constp)
1428 {
1429 if (! append_type (info, " const"))
1371 return false;
1430 return FALSE;
1372 }
1373
1374 /* Stick the name of the method into its type. */
1375 if (! substitute_type (info,
1376 (context
1377 ? info->stack->next->next->method
1378 : info->stack->next->method)))
1431 }
1432
1433 /* Stick the name of the method into its type. */
1434 if (! substitute_type (info,
1435 (context
1436 ? info->stack->next->next->method
1437 : info->stack->next->method)))
1379 return false;
1438 return FALSE;
1380
1381 /* Get the type. */
1382 method_type = pop_type (info);
1383 if (method_type == NULL)
1439
1440 /* Get the type. */
1441 method_type = pop_type (info);
1442 if (method_type == NULL)
1384 return false;
1443 return FALSE;
1385
1386 /* Pull off the context type if there is one. */
1387 if (! context)
1388 context_type = NULL;
1389 else
1390 {
1391 context_type = pop_type (info);
1392 if (context_type == NULL)
1444
1445 /* Pull off the context type if there is one. */
1446 if (! context)
1447 context_type = NULL;
1448 else
1449 {
1450 context_type = pop_type (info);
1451 if (context_type == NULL)
1393 return false;
1452 return FALSE;
1394 }
1395
1396 /* Now the top of the stack is the class. */
1397
1398 if (! pr_fix_visibility (info, visibility))
1453 }
1454
1455 /* Now the top of the stack is the class. */
1456
1457 if (! pr_fix_visibility (info, visibility))
1399 return false;
1458 return FALSE;
1400
1401 if (! append_type (info, method_type)
1402 || ! append_type (info, " /* ")
1403 || ! append_type (info, physname)
1404 || ! append_type (info, " "))
1459
1460 if (! append_type (info, method_type)
1461 || ! append_type (info, " /* ")
1462 || ! append_type (info, physname)
1463 || ! append_type (info, " "))
1405 return false;
1464 return FALSE;
1406 if (context || voffset != 0)
1407 {
1408 char ab[20];
1409
1410 if (context)
1411 {
1412 if (! append_type (info, "context ")
1413 || ! append_type (info, context_type)
1414 || ! append_type (info, " "))
1465 if (context || voffset != 0)
1466 {
1467 char ab[20];
1468
1469 if (context)
1470 {
1471 if (! append_type (info, "context ")
1472 || ! append_type (info, context_type)
1473 || ! append_type (info, " "))
1415 return false;
1474 return FALSE;
1416 }
1475 }
1417 print_vma (voffset, ab, true, false);
1476 print_vma (voffset, ab, TRUE, FALSE);
1418 if (! append_type (info, "voffset ")
1419 || ! append_type (info, ab))
1477 if (! append_type (info, "voffset ")
1478 || ! append_type (info, ab))
1420 return false;
1479 return FALSE;
1421 }
1422
1423 return (append_type (info, " */;\n")
1424 && indent_type (info));
1425}
1426
1427/* Add a static variant to a method. */
1428
1480 }
1481
1482 return (append_type (info, " */;\n")
1483 && indent_type (info));
1484}
1485
1486/* Add a static variant to a method. */
1487
1429static boolean
1430pr_class_static_method_variant (p, physname, visibility, constp, volatilep)
1431 PTR p;
1432 const char *physname;
1433 enum debug_visibility visibility;
1434 boolean constp;
1435 boolean volatilep;
1488static bfd_boolean
1489pr_class_static_method_variant (void *p, const char *physname,
1490 enum debug_visibility visibility,
1491 bfd_boolean constp, bfd_boolean volatilep)
1436{
1437 struct pr_handle *info = (struct pr_handle *) p;
1438 char *method_type;
1439
1440 assert (info->stack != NULL);
1441 assert (info->stack->next != NULL);
1442 assert (info->stack->next->method != NULL);
1443
1444 /* Put the const and volatile qualifiers on the type. */
1445 if (volatilep)
1446 {
1447 if (! append_type (info, " volatile"))
1492{
1493 struct pr_handle *info = (struct pr_handle *) p;
1494 char *method_type;
1495
1496 assert (info->stack != NULL);
1497 assert (info->stack->next != NULL);
1498 assert (info->stack->next->method != NULL);
1499
1500 /* Put the const and volatile qualifiers on the type. */
1501 if (volatilep)
1502 {
1503 if (! append_type (info, " volatile"))
1448 return false;
1504 return FALSE;
1449 }
1450 if (constp)
1451 {
1452 if (! append_type (info, " const"))
1505 }
1506 if (constp)
1507 {
1508 if (! append_type (info, " const"))
1453 return false;
1509 return FALSE;
1454 }
1455
1456 /* Mark it as static. */
1457 if (! prepend_type (info, "static "))
1510 }
1511
1512 /* Mark it as static. */
1513 if (! prepend_type (info, "static "))
1458 return false;
1514 return FALSE;
1459
1460 /* Stick the name of the method into its type. */
1461 if (! substitute_type (info, info->stack->next->method))
1515
1516 /* Stick the name of the method into its type. */
1517 if (! substitute_type (info, info->stack->next->method))
1462 return false;
1518 return FALSE;
1463
1464 /* Get the type. */
1465 method_type = pop_type (info);
1466 if (method_type == NULL)
1519
1520 /* Get the type. */
1521 method_type = pop_type (info);
1522 if (method_type == NULL)
1467 return false;
1523 return FALSE;
1468
1469 /* Now the top of the stack is the class. */
1470
1471 if (! pr_fix_visibility (info, visibility))
1524
1525 /* Now the top of the stack is the class. */
1526
1527 if (! pr_fix_visibility (info, visibility))
1472 return false;
1528 return FALSE;
1473
1474 return (append_type (info, method_type)
1475 && append_type (info, " /* ")
1476 && append_type (info, physname)
1477 && append_type (info, " */;\n")
1478 && indent_type (info));
1479}
1480
1481/* Finish up a method. */
1482
1529
1530 return (append_type (info, method_type)
1531 && append_type (info, " /* ")
1532 && append_type (info, physname)
1533 && append_type (info, " */;\n")
1534 && indent_type (info));
1535}
1536
1537/* Finish up a method. */
1538
1483static boolean
1484pr_class_end_method (p)
1485 PTR p;
1539static bfd_boolean
1540pr_class_end_method (void *p)
1486{
1487 struct pr_handle *info = (struct pr_handle *) p;
1488
1489 info->stack->method = NULL;
1541{
1542 struct pr_handle *info = (struct pr_handle *) p;
1543
1544 info->stack->method = NULL;
1490 return true;
1545 return TRUE;
1491}
1492
1493/* Finish up a class. */
1494
1546}
1547
1548/* Finish up a class. */
1549
1495static boolean
1496pr_end_class_type (p)
1497 PTR p;
1550static bfd_boolean
1551pr_end_class_type (void *p)
1498{
1499 return pr_end_struct_type (p);
1500}
1501
1502/* Push a type on the stack using a typedef name. */
1503
1552{
1553 return pr_end_struct_type (p);
1554}
1555
1556/* Push a type on the stack using a typedef name. */
1557
1504static boolean
1505pr_typedef_type (p, name)
1506 PTR p;
1507 const char *name;
1558static bfd_boolean
1559pr_typedef_type (void *p, const char *name)
1508{
1509 struct pr_handle *info = (struct pr_handle *) p;
1510
1511 return push_type (info, name);
1512}
1513
1514/* Push a type on the stack using a tag name. */
1515
1560{
1561 struct pr_handle *info = (struct pr_handle *) p;
1562
1563 return push_type (info, name);
1564}
1565
1566/* Push a type on the stack using a tag name. */
1567
1516static boolean
1517pr_tag_type (p, name, id, kind)
1518 PTR p;
1519 const char *name;
1520 unsigned int id;
1521 enum debug_type_kind kind;
1568static bfd_boolean
1569pr_tag_type (void *p, const char *name, unsigned int id,
1570 enum debug_type_kind kind)
1522{
1523 struct pr_handle *info = (struct pr_handle *) p;
1524 const char *t, *tag;
1525 char idbuf[20];
1526
1527 switch (kind)
1528 {
1529 case DEBUG_KIND_STRUCT:

--- 8 unchanged lines hidden (view full) ---

1538 case DEBUG_KIND_CLASS:
1539 t = "class ";
1540 break;
1541 case DEBUG_KIND_UNION_CLASS:
1542 t = "union class ";
1543 break;
1544 default:
1545 abort ();
1571{
1572 struct pr_handle *info = (struct pr_handle *) p;
1573 const char *t, *tag;
1574 char idbuf[20];
1575
1576 switch (kind)
1577 {
1578 case DEBUG_KIND_STRUCT:

--- 8 unchanged lines hidden (view full) ---

1587 case DEBUG_KIND_CLASS:
1588 t = "class ";
1589 break;
1590 case DEBUG_KIND_UNION_CLASS:
1591 t = "union class ";
1592 break;
1593 default:
1594 abort ();
1546 return false;
1595 return FALSE;
1547 }
1548
1549 if (! push_type (info, t))
1596 }
1597
1598 if (! push_type (info, t))
1550 return false;
1599 return FALSE;
1551 if (name != NULL)
1552 tag = name;
1553 else
1554 {
1555 sprintf (idbuf, "%%anon%u", id);
1556 tag = idbuf;
1557 }
1558
1559 if (! append_type (info, tag))
1600 if (name != NULL)
1601 tag = name;
1602 else
1603 {
1604 sprintf (idbuf, "%%anon%u", id);
1605 tag = idbuf;
1606 }
1607
1608 if (! append_type (info, tag))
1560 return false;
1609 return FALSE;
1561 if (name != NULL && kind != DEBUG_KIND_ENUM)
1562 {
1563 sprintf (idbuf, " /* id %u */", id);
1564 if (! append_type (info, idbuf))
1610 if (name != NULL && kind != DEBUG_KIND_ENUM)
1611 {
1612 sprintf (idbuf, " /* id %u */", id);
1613 if (! append_type (info, idbuf))
1565 return false;
1614 return FALSE;
1566 }
1567
1615 }
1616
1568 return true;
1617 return TRUE;
1569}
1570
1571/* Output a typedef. */
1572
1618}
1619
1620/* Output a typedef. */
1621
1573static boolean
1574pr_typdef (p, name)
1575 PTR p;
1576 const char *name;
1622static bfd_boolean
1623pr_typdef (void *p, const char *name)
1577{
1578 struct pr_handle *info = (struct pr_handle *) p;
1579 char *s;
1580
1581 if (! substitute_type (info, name))
1624{
1625 struct pr_handle *info = (struct pr_handle *) p;
1626 char *s;
1627
1628 if (! substitute_type (info, name))
1582 return false;
1629 return FALSE;
1583
1584 s = pop_type (info);
1585 if (s == NULL)
1630
1631 s = pop_type (info);
1632 if (s == NULL)
1586 return false;
1633 return FALSE;
1587
1588 indent (info);
1589 fprintf (info->f, "typedef %s;\n", s);
1590
1591 free (s);
1592
1634
1635 indent (info);
1636 fprintf (info->f, "typedef %s;\n", s);
1637
1638 free (s);
1639
1593 return true;
1640 return TRUE;
1594}
1595
1596/* Output a tag. The tag should already be in the string on the
1597 stack, so all we have to do here is print it out. */
1598
1641}
1642
1643/* Output a tag. The tag should already be in the string on the
1644 stack, so all we have to do here is print it out. */
1645
1599static boolean
1600pr_tag (p, name)
1601 PTR p;
1602 const char *name ATTRIBUTE_UNUSED;
1646static bfd_boolean
1647pr_tag (void *p, const char *name ATTRIBUTE_UNUSED)
1603{
1604 struct pr_handle *info = (struct pr_handle *) p;
1605 char *t;
1606
1607 t = pop_type (info);
1608 if (t == NULL)
1648{
1649 struct pr_handle *info = (struct pr_handle *) p;
1650 char *t;
1651
1652 t = pop_type (info);
1653 if (t == NULL)
1609 return false;
1654 return FALSE;
1610
1611 indent (info);
1612 fprintf (info->f, "%s;\n", t);
1613
1614 free (t);
1615
1655
1656 indent (info);
1657 fprintf (info->f, "%s;\n", t);
1658
1659 free (t);
1660
1616 return true;
1661 return TRUE;
1617}
1618
1619/* Output an integer constant. */
1620
1662}
1663
1664/* Output an integer constant. */
1665
1621static boolean
1622pr_int_constant (p, name, val)
1623 PTR p;
1624 const char *name;
1625 bfd_vma val;
1666static bfd_boolean
1667pr_int_constant (void *p, const char *name, bfd_vma val)
1626{
1627 struct pr_handle *info = (struct pr_handle *) p;
1628 char ab[20];
1629
1630 indent (info);
1668{
1669 struct pr_handle *info = (struct pr_handle *) p;
1670 char ab[20];
1671
1672 indent (info);
1631 print_vma (val, ab, false, false);
1673 print_vma (val, ab, FALSE, FALSE);
1632 fprintf (info->f, "const int %s = %s;\n", name, ab);
1674 fprintf (info->f, "const int %s = %s;\n", name, ab);
1633 return true;
1675 return TRUE;
1634}
1635
1636/* Output a floating point constant. */
1637
1676}
1677
1678/* Output a floating point constant. */
1679
1638static boolean
1639pr_float_constant (p, name, val)
1640 PTR p;
1641 const char *name;
1642 double val;
1680static bfd_boolean
1681pr_float_constant (void *p, const char *name, double val)
1643{
1644 struct pr_handle *info = (struct pr_handle *) p;
1645
1646 indent (info);
1647 fprintf (info->f, "const double %s = %g;\n", name, val);
1682{
1683 struct pr_handle *info = (struct pr_handle *) p;
1684
1685 indent (info);
1686 fprintf (info->f, "const double %s = %g;\n", name, val);
1648 return true;
1687 return TRUE;
1649}
1650
1651/* Output a typed constant. */
1652
1688}
1689
1690/* Output a typed constant. */
1691
1653static boolean
1654pr_typed_constant (p, name, val)
1655 PTR p;
1656 const char *name;
1657 bfd_vma val;
1692static bfd_boolean
1693pr_typed_constant (void *p, const char *name, bfd_vma val)
1658{
1659 struct pr_handle *info = (struct pr_handle *) p;
1660 char *t;
1661 char ab[20];
1662
1663 t = pop_type (info);
1664 if (t == NULL)
1694{
1695 struct pr_handle *info = (struct pr_handle *) p;
1696 char *t;
1697 char ab[20];
1698
1699 t = pop_type (info);
1700 if (t == NULL)
1665 return false;
1701 return FALSE;
1666
1667 indent (info);
1702
1703 indent (info);
1668 print_vma (val, ab, false, false);
1704 print_vma (val, ab, FALSE, FALSE);
1669 fprintf (info->f, "const %s %s = %s;\n", t, name, ab);
1670
1671 free (t);
1672
1705 fprintf (info->f, "const %s %s = %s;\n", t, name, ab);
1706
1707 free (t);
1708
1673 return true;
1709 return TRUE;
1674}
1675
1676/* Output a variable. */
1677
1710}
1711
1712/* Output a variable. */
1713
1678static boolean
1679pr_variable (p, name, kind, val)
1680 PTR p;
1681 const char *name;
1682 enum debug_var_kind kind;
1683 bfd_vma val;
1714static bfd_boolean
1715pr_variable (void *p, const char *name, enum debug_var_kind kind,
1716 bfd_vma val)
1684{
1685 struct pr_handle *info = (struct pr_handle *) p;
1686 char *t;
1687 char ab[20];
1688
1689 if (! substitute_type (info, name))
1717{
1718 struct pr_handle *info = (struct pr_handle *) p;
1719 char *t;
1720 char ab[20];
1721
1722 if (! substitute_type (info, name))
1690 return false;
1723 return FALSE;
1691
1692 t = pop_type (info);
1693 if (t == NULL)
1724
1725 t = pop_type (info);
1726 if (t == NULL)
1694 return false;
1727 return FALSE;
1695
1696 indent (info);
1697 switch (kind)
1698 {
1699 case DEBUG_STATIC:
1700 case DEBUG_LOCAL_STATIC:
1701 fprintf (info->f, "static ");
1702 break;
1703 case DEBUG_REGISTER:
1704 fprintf (info->f, "register ");
1705 break;
1706 default:
1707 break;
1708 }
1728
1729 indent (info);
1730 switch (kind)
1731 {
1732 case DEBUG_STATIC:
1733 case DEBUG_LOCAL_STATIC:
1734 fprintf (info->f, "static ");
1735 break;
1736 case DEBUG_REGISTER:
1737 fprintf (info->f, "register ");
1738 break;
1739 default:
1740 break;
1741 }
1709 print_vma (val, ab, true, true);
1742 print_vma (val, ab, TRUE, TRUE);
1710 fprintf (info->f, "%s /* %s */;\n", t, ab);
1711
1712 free (t);
1713
1743 fprintf (info->f, "%s /* %s */;\n", t, ab);
1744
1745 free (t);
1746
1714 return true;
1747 return TRUE;
1715}
1716
1717/* Start outputting a function. */
1718
1748}
1749
1750/* Start outputting a function. */
1751
1719static boolean
1720pr_start_function (p, name, global)
1721 PTR p;
1722 const char *name;
1723 boolean global;
1752static bfd_boolean
1753pr_start_function (void *p, const char *name, bfd_boolean global)
1724{
1725 struct pr_handle *info = (struct pr_handle *) p;
1726 char *t;
1727
1728 if (! substitute_type (info, name))
1754{
1755 struct pr_handle *info = (struct pr_handle *) p;
1756 char *t;
1757
1758 if (! substitute_type (info, name))
1729 return false;
1759 return FALSE;
1730
1731 t = pop_type (info);
1732 if (t == NULL)
1760
1761 t = pop_type (info);
1762 if (t == NULL)
1733 return false;
1763 return FALSE;
1734
1735 indent (info);
1736 if (! global)
1737 fprintf (info->f, "static ");
1738 fprintf (info->f, "%s (", t);
1739
1740 info->parameter = 1;
1741
1764
1765 indent (info);
1766 if (! global)
1767 fprintf (info->f, "static ");
1768 fprintf (info->f, "%s (", t);
1769
1770 info->parameter = 1;
1771
1742 return true;
1772 return TRUE;
1743}
1744
1745/* Output a function parameter. */
1746
1773}
1774
1775/* Output a function parameter. */
1776
1747static boolean
1748pr_function_parameter (p, name, kind, val)
1749 PTR p;
1750 const char *name;
1751 enum debug_parm_kind kind;
1752 bfd_vma val;
1777static bfd_boolean
1778pr_function_parameter (void *p, const char *name,
1779 enum debug_parm_kind kind, bfd_vma val)
1753{
1754 struct pr_handle *info = (struct pr_handle *) p;
1755 char *t;
1756 char ab[20];
1757
1758 if (kind == DEBUG_PARM_REFERENCE
1759 || kind == DEBUG_PARM_REF_REG)
1760 {
1761 if (! pr_reference_type (p))
1780{
1781 struct pr_handle *info = (struct pr_handle *) p;
1782 char *t;
1783 char ab[20];
1784
1785 if (kind == DEBUG_PARM_REFERENCE
1786 || kind == DEBUG_PARM_REF_REG)
1787 {
1788 if (! pr_reference_type (p))
1762 return false;
1789 return FALSE;
1763 }
1764
1765 if (! substitute_type (info, name))
1790 }
1791
1792 if (! substitute_type (info, name))
1766 return false;
1793 return FALSE;
1767
1768 t = pop_type (info);
1769 if (t == NULL)
1794
1795 t = pop_type (info);
1796 if (t == NULL)
1770 return false;
1797 return FALSE;
1771
1772 if (info->parameter != 1)
1773 fprintf (info->f, ", ");
1774
1775 if (kind == DEBUG_PARM_REG || kind == DEBUG_PARM_REF_REG)
1776 fprintf (info->f, "register ");
1777
1798
1799 if (info->parameter != 1)
1800 fprintf (info->f, ", ");
1801
1802 if (kind == DEBUG_PARM_REG || kind == DEBUG_PARM_REF_REG)
1803 fprintf (info->f, "register ");
1804
1778 print_vma (val, ab, true, true);
1805 print_vma (val, ab, TRUE, TRUE);
1779 fprintf (info->f, "%s /* %s */", t, ab);
1780
1781 free (t);
1782
1783 ++info->parameter;
1784
1806 fprintf (info->f, "%s /* %s */", t, ab);
1807
1808 free (t);
1809
1810 ++info->parameter;
1811
1785 return true;
1812 return TRUE;
1786}
1787
1788/* Start writing out a block. */
1789
1813}
1814
1815/* Start writing out a block. */
1816
1790static boolean
1791pr_start_block (p, addr)
1792 PTR p;
1793 bfd_vma addr;
1817static bfd_boolean
1818pr_start_block (void *p, bfd_vma addr)
1794{
1795 struct pr_handle *info = (struct pr_handle *) p;
1796 char ab[20];
1797
1798 if (info->parameter > 0)
1799 {
1800 fprintf (info->f, ")\n");
1801 info->parameter = 0;
1802 }
1803
1804 indent (info);
1819{
1820 struct pr_handle *info = (struct pr_handle *) p;
1821 char ab[20];
1822
1823 if (info->parameter > 0)
1824 {
1825 fprintf (info->f, ")\n");
1826 info->parameter = 0;
1827 }
1828
1829 indent (info);
1805 print_vma (addr, ab, true, true);
1830 print_vma (addr, ab, TRUE, TRUE);
1806 fprintf (info->f, "{ /* %s */\n", ab);
1807
1808 info->indent += 2;
1809
1831 fprintf (info->f, "{ /* %s */\n", ab);
1832
1833 info->indent += 2;
1834
1810 return true;
1835 return TRUE;
1811}
1812
1813/* Write out line number information. */
1814
1836}
1837
1838/* Write out line number information. */
1839
1815static boolean
1816pr_lineno (p, filename, lineno, addr)
1817 PTR p;
1818 const char *filename;
1819 unsigned long lineno;
1820 bfd_vma addr;
1840static bfd_boolean
1841pr_lineno (void *p, const char *filename, unsigned long lineno, bfd_vma addr)
1821{
1822 struct pr_handle *info = (struct pr_handle *) p;
1823 char ab[20];
1824
1825 indent (info);
1842{
1843 struct pr_handle *info = (struct pr_handle *) p;
1844 char ab[20];
1845
1846 indent (info);
1826 print_vma (addr, ab, true, true);
1847 print_vma (addr, ab, TRUE, TRUE);
1827 fprintf (info->f, "/* file %s line %lu addr %s */\n", filename, lineno, ab);
1828
1848 fprintf (info->f, "/* file %s line %lu addr %s */\n", filename, lineno, ab);
1849
1829 return true;
1850 return TRUE;
1830}
1831
1832/* Finish writing out a block. */
1833
1851}
1852
1853/* Finish writing out a block. */
1854
1834static boolean
1835pr_end_block (p, addr)
1836 PTR p;
1837 bfd_vma addr;
1855static bfd_boolean
1856pr_end_block (void *p, bfd_vma addr)
1838{
1839 struct pr_handle *info = (struct pr_handle *) p;
1840 char ab[20];
1841
1842 info->indent -= 2;
1843
1844 indent (info);
1857{
1858 struct pr_handle *info = (struct pr_handle *) p;
1859 char ab[20];
1860
1861 info->indent -= 2;
1862
1863 indent (info);
1845 print_vma (addr, ab, true, true);
1864 print_vma (addr, ab, TRUE, TRUE);
1846 fprintf (info->f, "} /* %s */\n", ab);
1847
1865 fprintf (info->f, "} /* %s */\n", ab);
1866
1848 return true;
1867 return TRUE;
1849}
1850
1851/* Finish writing out a function. */
1852
1868}
1869
1870/* Finish writing out a function. */
1871
1853static boolean
1854pr_end_function (p)
1855 PTR p ATTRIBUTE_UNUSED;
1872static bfd_boolean
1873pr_end_function (void *p ATTRIBUTE_UNUSED)
1856{
1874{
1857 return true;
1875 return TRUE;
1858}
1876}
1877
1878/* Tags style generation functions start here. */
1879
1880/* Variables for address to line translation. */
1881static bfd_vma pc;
1882static const char *filename;
1883static const char *functionname;
1884static unsigned int line;
1885static bfd_boolean found;
1886
1887/* Look for an address in a section. This is called via
1888 bfd_map_over_sections. */
1889
1890static void
1891find_address_in_section (bfd *abfd, asection *section, void *data)
1892{
1893 bfd_vma vma;
1894 bfd_size_type size;
1895 asymbol **syms = (asymbol **) data;
1896
1897 if (found)
1898 return;
1899
1900 if ((bfd_get_section_flags (abfd, section) & SEC_ALLOC) == 0)
1901 return;
1902
1903 vma = bfd_get_section_vma (abfd, section);
1904 if (pc < vma)
1905 return;
1906
1907 size = bfd_get_section_size_before_reloc (section);
1908 if (pc >= vma + size)
1909 return;
1910
1911 found = bfd_find_nearest_line (abfd, section, syms, pc - vma,
1912 &filename, &functionname, &line);
1913}
1914
1915static void
1916translate_addresses (bfd *abfd, char *addr_hex, FILE *f, asymbol **syms)
1917{
1918 pc = bfd_scan_vma (addr_hex, NULL, 16);
1919 found = FALSE;
1920 bfd_map_over_sections (abfd, find_address_in_section, syms);
1921
1922 if (! found)
1923 fprintf (f, "??");
1924 else
1925 fprintf (f, "%u", line);
1926}
1927
1928/* Start a new compilation unit. */
1929
1930static bfd_boolean
1931tg_start_compilation_unit (void * p, const char *filename ATTRIBUTE_UNUSED)
1932{
1933 struct pr_handle *info = (struct pr_handle *) p;
1934
1935 fprintf (stderr, "New compilation unit: %s\n", filename);
1936
1937 free (info->filename);
1938 /* Should it be relative? best way to do it here?. */
1939 info->filename = strdup (filename);
1940
1941 return TRUE;
1942}
1943
1944/* Start a source file within a compilation unit. */
1945
1946static bfd_boolean
1947tg_start_source (void *p, const char *filename)
1948{
1949 struct pr_handle *info = (struct pr_handle *) p;
1950
1951 free (info->filename);
1952 /* Should it be relative? best way to do it here?. */
1953 info->filename = strdup (filename);
1954
1955 return TRUE;
1956}
1957
1958/* Push an enum type onto the type stack. */
1959
1960static bfd_boolean
1961tg_enum_type (void *p, const char *tag, const char **names,
1962 bfd_signed_vma *values)
1963{
1964 struct pr_handle *info = (struct pr_handle *) p;
1965 unsigned int i;
1966 const char *name;
1967 char ab[20];
1968
1969 if (! pr_enum_type (p, tag, names, values))
1970 return FALSE;
1971
1972 name = tag ? tag : "unknown";
1973 /* Generate an entry for the enum. */
1974 if (tag)
1975 fprintf (info->f, "%s\t%s\t0;\"\tkind:e\ttype:%s\n", tag,
1976 info->filename, info->stack->type);
1977
1978 /* Generate entries for the values. */
1979 if (names != NULL)
1980 {
1981 for (i = 0; names[i] != NULL; i++)
1982 {
1983 print_vma (values[i], ab, FALSE, FALSE);
1984 fprintf (info->f, "%s\t%s\t0;\"\tkind:g\tenum:%s\tvalue:%s\n",
1985 names[i], info->filename, name, ab);
1986 }
1987 }
1988
1989 return TRUE;
1990}
1991
1992/* Start accumulating a struct type. */
1993
1994static bfd_boolean
1995tg_start_struct_type (void *p, const char *tag, unsigned int id,
1996 bfd_boolean structp,
1997 unsigned int size ATTRIBUTE_UNUSED)
1998{
1999 struct pr_handle *info = (struct pr_handle *) p;
2000 const char *name;
2001 char idbuf[20];
2002
2003 if (tag != NULL)
2004 name = tag;
2005 else
2006 {
2007 name = idbuf;
2008 sprintf (idbuf, "%%anon%u", id);
2009 }
2010
2011 if (! push_type (info, name))
2012 return FALSE;
2013
2014 info->stack->flavor = structp ? "struct" : "union";
2015
2016 fprintf (info->f, "%s\t%s\t0;\"\tkind:%c\n", name, info->filename,
2017 info->stack->flavor[0]);
2018
2019 info->stack->visibility = DEBUG_VISIBILITY_PUBLIC;
2020
2021 return indent_type (info);
2022}
2023
2024/* Output the visibility of a field in a struct. */
2025
2026static bfd_boolean
2027tg_fix_visibility (struct pr_handle *info, enum debug_visibility visibility)
2028{
2029 assert (info->stack != NULL);
2030
2031 if (info->stack->visibility == visibility)
2032 return TRUE;
2033
2034 assert (info->stack->visibility != DEBUG_VISIBILITY_IGNORE);
2035
2036 info->stack->visibility = visibility;
2037
2038 return TRUE;
2039}
2040
2041/* Add a field to a struct type. */
2042
2043static bfd_boolean
2044tg_struct_field (void *p, const char *name, bfd_vma bitpos ATTRIBUTE_UNUSED,
2045 bfd_vma bitsize ATTRIBUTE_UNUSED,
2046 enum debug_visibility visibility)
2047{
2048 struct pr_handle *info = (struct pr_handle *) p;
2049 char *t;
2050
2051 t = pop_type (info);
2052 if (t == NULL)
2053 return FALSE;
2054
2055 if (! tg_fix_visibility (info, visibility))
2056 return FALSE;
2057
2058 /* It happens, a bug? */
2059 if (! name[0])
2060 return TRUE;
2061
2062 fprintf (info->f, "%s\t%s\t0;\"\tkind:m\ttype:%s\t%s:%s\taccess:%s\n",
2063 name, info->filename, t, info->stack->flavor, info->stack->type,
2064 visibility_name (visibility));
2065
2066 return TRUE;
2067}
2068
2069/* Finish a struct type. */
2070
2071static bfd_boolean
2072tg_end_struct_type (void *p ATTRIBUTE_UNUSED)
2073{
2074 struct pr_handle *info = (struct pr_handle *) p;
2075 assert (info->stack != NULL);
2076
2077 return TRUE;
2078}
2079
2080/* Start a class type. */
2081
2082static bfd_boolean
2083tg_start_class_type (void *p, const char *tag, unsigned int id,
2084 bfd_boolean structp, unsigned int size,
2085 bfd_boolean vptr, bfd_boolean ownvptr)
2086{
2087 struct pr_handle *info = (struct pr_handle *) p;
2088 char *tv = NULL;
2089 const char *name;
2090
2091 info->indent += 2;
2092
2093 if (vptr && ! ownvptr)
2094 {
2095 tv = pop_type (info);
2096 if (tv == NULL)
2097 return FALSE;
2098 }
2099
2100 if (tag != NULL)
2101 name = tag;
2102 else
2103 {
2104 char idbuf[20];
2105
2106 sprintf (idbuf, "%%anon%u", id);
2107 name = idbuf;
2108 }
2109
2110 if (! push_type (info, name))
2111 return FALSE;
2112
2113 info->stack->flavor = structp ? "class" : "union class";
2114 info->stack->parents = NULL;
2115 info->stack->num_parents = 0;
2116
2117 if (size != 0 || vptr || ownvptr || tag != NULL)
2118 {
2119 if (vptr)
2120 {
2121 if (! append_type (info, " vtable "))
2122 return FALSE;
2123 if (ownvptr)
2124 {
2125 if (! append_type (info, "self "))
2126 return FALSE;
2127 }
2128 else
2129 {
2130 if (! append_type (info, tv)
2131 || ! append_type (info, " "))
2132 return FALSE;
2133 }
2134 }
2135 }
2136
2137 info->stack->visibility = DEBUG_VISIBILITY_PRIVATE;
2138
2139 return TRUE;
2140}
2141
2142/* Add a static member to a class. */
2143
2144static bfd_boolean
2145tg_class_static_member (void *p, const char *name,
2146 const char *physname ATTRIBUTE_UNUSED,
2147 enum debug_visibility visibility)
2148{
2149 struct pr_handle *info = (struct pr_handle *) p;
2150 char *t;
2151 int len_var, len_class;
2152 char *full_name;
2153
2154 len_var = strlen (name);
2155 len_class = strlen (info->stack->next->type);
2156 full_name = (char *) xmalloc (len_var + len_class + 3);
2157 if (! full_name)
2158 return FALSE;
2159 memcpy (full_name, info->stack->next->type, len_class);
2160 memcpy (full_name + len_class, "::", 2);
2161 memcpy (full_name + len_class + 2, name, len_var + 1);
2162
2163 if (! substitute_type (info, full_name))
2164 return FALSE;
2165
2166 if (! prepend_type (info, "static "))
2167 return FALSE;
2168
2169 t = pop_type (info);
2170 if (t == NULL)
2171 return FALSE;
2172
2173 if (! tg_fix_visibility (info, visibility))
2174 return FALSE;
2175
2176 fprintf (info->f, "%s\t%s\t0;\"\tkind:x\ttype:%s\tclass:%s\taccess:%s\n",
2177 name, info->filename, t, info->stack->type,
2178 visibility_name (visibility));
2179 free (t);
2180 free (full_name);
2181
2182 return TRUE;
2183}
2184
2185/* Add a base class to a class. */
2186
2187static bfd_boolean
2188tg_class_baseclass (void *p, bfd_vma bitpos ATTRIBUTE_UNUSED,
2189 bfd_boolean virtual, enum debug_visibility visibility)
2190{
2191 struct pr_handle *info = (struct pr_handle *) p;
2192 char *t;
2193 const char *prefix;
2194
2195 assert (info->stack != NULL && info->stack->next != NULL);
2196
2197 t = pop_type (info);
2198 if (t == NULL)
2199 return FALSE;
2200
2201 if (strncmp (t, "class ", sizeof "class " - 1) == 0)
2202 t += sizeof "class " - 1;
2203
2204 /* Push it back on to take advantage of the prepend_type and
2205 append_type routines. */
2206 if (! push_type (info, t))
2207 return FALSE;
2208
2209 if (virtual)
2210 {
2211 if (! prepend_type (info, "virtual "))
2212 return FALSE;
2213 }
2214
2215 switch (visibility)
2216 {
2217 case DEBUG_VISIBILITY_PUBLIC:
2218 prefix = "public ";
2219 break;
2220 case DEBUG_VISIBILITY_PROTECTED:
2221 prefix = "protected ";
2222 break;
2223 case DEBUG_VISIBILITY_PRIVATE:
2224 prefix = "private ";
2225 break;
2226 default:
2227 prefix = "/* unknown visibility */ ";
2228 break;
2229 }
2230
2231 if (! prepend_type (info, prefix))
2232 return FALSE;
2233
2234 t = pop_type (info);
2235 if (t == NULL)
2236 return FALSE;
2237
2238 if (info->stack->num_parents && ! append_parent (info, ", "))
2239 return FALSE;
2240
2241 if (! append_parent (info, t))
2242 return FALSE;
2243 info->stack->num_parents++;
2244
2245 free (t);
2246
2247 return TRUE;
2248}
2249
2250/* Add a variant to a method. */
2251
2252static bfd_boolean
2253tg_class_method_variant (void *p, const char *physname ATTRIBUTE_UNUSED,
2254 enum debug_visibility visibility,
2255 bfd_boolean constp, bfd_boolean volatilep,
2256 bfd_vma voffset ATTRIBUTE_UNUSED,
2257 bfd_boolean context)
2258{
2259 struct pr_handle *info = (struct pr_handle *) p;
2260 char *method_type;
2261 char *context_type;
2262 char *method_name;
2263
2264 assert (info->stack != NULL);
2265 assert (info->stack->next != NULL);
2266
2267 /* Put the const and volatile qualifiers on the type. */
2268 if (volatilep)
2269 {
2270 if (! append_type (info, " volatile"))
2271 return FALSE;
2272 }
2273 if (constp)
2274 {
2275 if (! append_type (info, " const"))
2276 return FALSE;
2277 }
2278
2279 method_name = strdup (context ? info->stack->next->next->method
2280 : info->stack->next->method);
2281
2282 /* Stick the name of the method into its type. */
2283 if (! substitute_type (info, method_name))
2284 return FALSE;
2285
2286 /* Get the type. */
2287 method_type = pop_type (info);
2288 if (method_type == NULL)
2289 return FALSE;
2290
2291 /* Pull off the context type if there is one. */
2292 if (! context)
2293 context_type = NULL;
2294 else
2295 {
2296 context_type = pop_type (info);
2297 if (context_type == NULL)
2298 return FALSE;
2299 }
2300
2301 /* Now the top of the stack is the class. */
2302 if (! tg_fix_visibility (info, visibility))
2303 return FALSE;
2304
2305 fprintf (info->f, "%s\t%s\t0;\"\tkind:p\ttype:%s\tclass:%s\n",
2306 method_name, info->filename, method_type, info->stack->type);
2307 free (method_type);
2308 free (method_name);
2309 free (context_type);
2310
2311 return TRUE;
2312}
2313
2314/* Add a static variant to a method. */
2315
2316static bfd_boolean
2317tg_class_static_method_variant (void *p,
2318 const char *physname ATTRIBUTE_UNUSED,
2319 enum debug_visibility visibility,
2320 bfd_boolean constp, bfd_boolean volatilep)
2321{
2322 struct pr_handle *info = (struct pr_handle *) p;
2323 char *method_type;
2324 char *method_name;
2325
2326 assert (info->stack != NULL);
2327 assert (info->stack->next != NULL);
2328 assert (info->stack->next->method != NULL);
2329
2330 /* Put the const and volatile qualifiers on the type. */
2331 if (volatilep)
2332 {
2333 if (! append_type (info, " volatile"))
2334 return FALSE;
2335 }
2336 if (constp)
2337 {
2338 if (! append_type (info, " const"))
2339 return FALSE;
2340 }
2341
2342 /* Mark it as static. */
2343 if (! prepend_type (info, "static "))
2344 return FALSE;
2345
2346 method_name = strdup (info->stack->next->method);
2347 /* Stick the name of the method into its type. */
2348 if (! substitute_type (info, info->stack->next->method))
2349 return FALSE;
2350
2351 /* Get the type. */
2352 method_type = pop_type (info);
2353 if (method_type == NULL)
2354 return FALSE;
2355
2356 /* Now the top of the stack is the class. */
2357 if (! tg_fix_visibility (info, visibility))
2358 return FALSE;
2359
2360 fprintf (info->f, "%s\t%s\t0;\"\tkind:p\ttype:%s\tclass:%s\taccess:%s\n",
2361 method_name, info->filename, method_type, info->stack->type,
2362 visibility_name (visibility));
2363 free (method_type);
2364 free (method_name);
2365
2366 return TRUE;
2367}
2368
2369/* Finish up a class. */
2370
2371static bfd_boolean
2372tg_end_class_type (void *p)
2373{
2374 struct pr_handle *info = (struct pr_handle *) p;
2375
2376 fprintf (info->f, "%s\t%s\t0;\"\tkind:c\ttype:%s", info->stack->type,
2377 info->filename, info->stack->flavor);
2378 if (info->stack->num_parents)
2379 {
2380 fprintf (info->f, "\tinherits:%s", info->stack->parents);
2381 free (info->stack->parents);
2382 }
2383 fputc ('\n', info->f);
2384
2385 return tg_end_struct_type (p);
2386}
2387
2388/* Push a type on the stack using a tag name. */
2389
2390static bfd_boolean
2391tg_tag_type (void *p, const char *name, unsigned int id,
2392 enum debug_type_kind kind)
2393{
2394 struct pr_handle *info = (struct pr_handle *) p;
2395 const char *t, *tag;
2396 char idbuf[20];
2397
2398 switch (kind)
2399 {
2400 case DEBUG_KIND_STRUCT:
2401 t = "struct ";
2402 break;
2403 case DEBUG_KIND_UNION:
2404 t = "union ";
2405 break;
2406 case DEBUG_KIND_ENUM:
2407 t = "enum ";
2408 break;
2409 case DEBUG_KIND_CLASS:
2410 t = "class ";
2411 break;
2412 case DEBUG_KIND_UNION_CLASS:
2413 t = "union class ";
2414 break;
2415 default:
2416 abort ();
2417 return FALSE;
2418 }
2419
2420 if (! push_type (info, t))
2421 return FALSE;
2422 if (name != NULL)
2423 tag = name;
2424 else
2425 {
2426 sprintf (idbuf, "%%anon%u", id);
2427 tag = idbuf;
2428 }
2429
2430 if (! append_type (info, tag))
2431 return FALSE;
2432
2433 return TRUE;
2434}
2435
2436/* Output a typedef. */
2437
2438static bfd_boolean
2439tg_typdef (void *p, const char *name)
2440{
2441 struct pr_handle *info = (struct pr_handle *) p;
2442 char *s;
2443
2444 s = pop_type (info);
2445 if (s == NULL)
2446 return FALSE;
2447
2448 fprintf (info->f, "%s\t%s\t0;\"\tkind:t\ttype:%s\n", name,
2449 info->filename, s);
2450
2451 free (s);
2452
2453 return TRUE;
2454}
2455
2456/* Output a tag. The tag should already be in the string on the
2457 stack, so all we have to do here is print it out. */
2458
2459static bfd_boolean
2460tg_tag (void *p ATTRIBUTE_UNUSED, const char *name ATTRIBUTE_UNUSED)
2461{
2462 struct pr_handle *info = (struct pr_handle *) p;
2463 char *t;
2464
2465 t = pop_type (info);
2466 if (t == NULL)
2467 return FALSE;
2468 free (t);
2469
2470 return TRUE;
2471}
2472
2473/* Output an integer constant. */
2474
2475static bfd_boolean
2476tg_int_constant (void *p, const char *name, bfd_vma val)
2477{
2478 struct pr_handle *info = (struct pr_handle *) p;
2479 char ab[20];
2480
2481 indent (info);
2482 print_vma (val, ab, FALSE, FALSE);
2483 fprintf (info->f, "%s\t%s\t0;\"\tkind:v\ttype:const int\tvalue:%s\n",
2484 name, info->filename, ab);
2485 return TRUE;
2486}
2487
2488/* Output a floating point constant. */
2489
2490static bfd_boolean
2491tg_float_constant (void *p, const char *name, double val)
2492{
2493 struct pr_handle *info = (struct pr_handle *) p;
2494
2495 indent (info);
2496 fprintf (info->f, "%s\t%s\t0;\"\tkind:v\ttype:const double\tvalue:%g\n",
2497 name, info->filename, val);
2498 return TRUE;
2499}
2500
2501/* Output a typed constant. */
2502
2503static bfd_boolean
2504tg_typed_constant (void *p, const char *name, bfd_vma val)
2505{
2506 struct pr_handle *info = (struct pr_handle *) p;
2507 char *t;
2508 char ab[20];
2509
2510 t = pop_type (info);
2511 if (t == NULL)
2512 return FALSE;
2513
2514 indent (info);
2515 print_vma (val, ab, FALSE, FALSE);
2516 fprintf (info->f, "%s\t%s\t0;\"\tkind:v\ttype:const %s\tvalue:%s\n",
2517 name, info->filename, t, ab);
2518
2519 free (t);
2520
2521 return TRUE;
2522}
2523
2524/* Output a variable. */
2525
2526static bfd_boolean
2527tg_variable (void *p, const char *name, enum debug_var_kind kind,
2528 bfd_vma val ATTRIBUTE_UNUSED)
2529{
2530 struct pr_handle *info = (struct pr_handle *) p;
2531 char *t;
2532 const char *dname, *from_class;
2533
2534 t = pop_type (info);
2535 if (t == NULL)
2536 return FALSE;
2537
2538 dname = name;
2539 if (info->demangler)
2540 {
2541 dname = info->demangler (info->abfd, name);
2542 if (strcmp (name, dname) == 0)
2543 {
2544 free ((char *) dname);
2545 dname = name;
2546 }
2547 }
2548
2549 if (dname != name)
2550 {
2551 char *sep;
2552 sep = strstr (dname, "::");
2553 if (sep)
2554 {
2555 *sep = 0;
2556 name = sep + 2;
2557 from_class = dname;
2558 }
2559 else
2560 {
2561 /* Obscure types as vts and type_info nodes. */
2562 name = dname;
2563 from_class = NULL;
2564 }
2565 }
2566 else
2567 from_class = NULL;
2568
2569 fprintf (info->f, "%s\t%s\t0;\"\tkind:v\ttype:%s", name, info->filename, t);
2570
2571 switch (kind)
2572 {
2573 case DEBUG_STATIC:
2574 case DEBUG_LOCAL_STATIC:
2575 fprintf (info->f, "\tfile:");
2576 break;
2577 case DEBUG_REGISTER:
2578 fprintf (info->f, "\tregister:");
2579 break;
2580 default:
2581 break;
2582 }
2583
2584 if (from_class)
2585 {
2586 fprintf (info->f, "\tclass:%s",from_class);
2587 free ((char *) dname);
2588 }
2589
2590 fprintf (info->f, "\n");
2591
2592 free (t);
2593
2594 return TRUE;
2595}
2596
2597/* Start outputting a function. */
2598
2599static bfd_boolean
2600tg_start_function (void *p, const char *name, bfd_boolean global)
2601{
2602 struct pr_handle *info = (struct pr_handle *) p;
2603 const char *dname;
2604
2605 if (! global)
2606 info->stack->flavor = "static";
2607 else
2608 info->stack->flavor = NULL;
2609
2610 dname = name;
2611 if (info->demangler)
2612 {
2613 dname = info->demangler (info->abfd, name);
2614 if (strcmp (name, dname) == 0)
2615 {
2616 free ((char *) dname);
2617 dname = name;
2618 }
2619 }
2620
2621 if (! substitute_type (info, dname))
2622 return FALSE;
2623
2624 if (dname != name)
2625 {
2626 char *sep;
2627 sep = strstr (dname, "::");
2628 if (sep)
2629 {
2630 info->stack->method = dname;
2631 *sep = 0;
2632 name = sep + 2;
2633 }
2634 else
2635 {
2636 info->stack->method = "";
2637 name = dname;
2638 }
2639 sep = strchr (name, '(');
2640 if (sep)
2641 *sep = 0;
2642 /* Obscure functions as type_info function. */
2643 }
2644 else
2645 info->stack->method = NULL;
2646
2647 info->stack->parents = strdup (name);
2648
2649 if (! info->stack->method && ! append_type (info, "("))
2650 return FALSE;
2651
2652 info->parameter = 1;
2653
2654 return TRUE;
2655}
2656
2657/* Output a function parameter. */
2658
2659static bfd_boolean
2660tg_function_parameter (void *p, const char *name, enum debug_parm_kind kind,
2661 bfd_vma val ATTRIBUTE_UNUSED)
2662{
2663 struct pr_handle *info = (struct pr_handle *) p;
2664 char *t;
2665
2666 if (kind == DEBUG_PARM_REFERENCE
2667 || kind == DEBUG_PARM_REF_REG)
2668 {
2669 if (! pr_reference_type (p))
2670 return FALSE;
2671 }
2672
2673 if (! substitute_type (info, name))
2674 return FALSE;
2675
2676 t = pop_type (info);
2677 if (t == NULL)
2678 return FALSE;
2679
2680 if (! info->stack->method)
2681 {
2682 if (info->parameter != 1 && ! append_type (info, ", "))
2683 return FALSE;
2684
2685 if (kind == DEBUG_PARM_REG || kind == DEBUG_PARM_REF_REG)
2686 if (! append_type (info, "register "))
2687 return FALSE;
2688
2689 if (! append_type (info, t))
2690 return FALSE;
2691 }
2692
2693 free (t);
2694
2695 ++info->parameter;
2696
2697 return TRUE;
2698}
2699
2700/* Start writing out a block. */
2701
2702static bfd_boolean
2703tg_start_block (void *p, bfd_vma addr)
2704{
2705 struct pr_handle *info = (struct pr_handle *) p;
2706 char ab[20], kind, *partof;
2707 char *t;
2708 bfd_boolean local;
2709
2710 if (info->parameter > 0)
2711 {
2712 info->parameter = 0;
2713
2714 /* Delayed name. */
2715 fprintf (info->f, "%s\t%s\t", info->stack->parents, info->filename);
2716 free (info->stack->parents);
2717
2718 print_vma (addr, ab, TRUE, TRUE);
2719 translate_addresses (info->abfd, ab, info->f, info->syms);
2720 local = info->stack->flavor != NULL;
2721 if (info->stack->method && *info->stack->method)
2722 {
2723 kind = 'm';
2724 partof = (char *) info->stack->method;
2725 }
2726 else
2727 {
2728 kind = 'f';
2729 partof = NULL;
2730 if (! info->stack->method && ! append_type (info, ")"))
2731 return FALSE;
2732 }
2733 t = pop_type (info);
2734 if (t == NULL)
2735 return FALSE;
2736 fprintf (info->f, ";\"\tkind:%c\ttype:%s", kind, t);
2737 if (local)
2738 fputs ("\tfile:", info->f);
2739 if (partof)
2740 {
2741 fprintf (info->f, "\tclass:%s", partof);
2742 free (partof);
2743 }
2744 fputc ('\n', info->f);
2745 }
2746
2747 return TRUE;
2748}
2749
2750/* Write out line number information. */
2751
2752static bfd_boolean
2753tg_lineno (void *p ATTRIBUTE_UNUSED, const char *filename ATTRIBUTE_UNUSED,
2754 unsigned long lineno ATTRIBUTE_UNUSED,
2755 bfd_vma addr ATTRIBUTE_UNUSED)
2756{
2757 return TRUE;
2758}
2759
2760/* Finish writing out a block. */
2761
2762static bfd_boolean
2763tg_end_block (void *p ATTRIBUTE_UNUSED, bfd_vma addr ATTRIBUTE_UNUSED)
2764{
2765 return TRUE;
2766}
2767
2768/* Convert the visibility value into a human readable name. */
2769
2770static const char *
2771visibility_name (enum debug_visibility visibility)
2772{
2773 const char *s;
2774
2775 switch (visibility)
2776 {
2777 case DEBUG_VISIBILITY_PUBLIC:
2778 s = "public";
2779 break;
2780 case DEBUG_VISIBILITY_PRIVATE:
2781 s = "private";
2782 break;
2783 case DEBUG_VISIBILITY_PROTECTED:
2784 s = "protected";
2785 break;
2786 case DEBUG_VISIBILITY_IGNORE:
2787 s = "/* ignore */";
2788 break;
2789 default:
2790 abort ();
2791 return FALSE;
2792 }
2793 return s;
2794}