Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* stabs.c -- Parse stabs debugging information |
3db64b00 | 2 | Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, |
3d540e93 | 3 | 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. |
252b5132 RH |
4 | Written by Ian Lance Taylor <ian@cygnus.com>. |
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 | |
32866df7 | 10 | the Free Software Foundation; either version 3 of the License, or |
252b5132 RH |
11 | (at your option) any later version. |
12 | ||
13 | This program is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
19 | along with this program; if not, write to the Free Software | |
b43b5d5f NC |
20 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA |
21 | 02110-1301, USA. */ | |
252b5132 RH |
22 | |
23 | /* This file contains code which parses stabs debugging information. | |
24 | The organization of this code is based on the gdb stabs reading | |
25 | code. The job it does is somewhat different, because it is not | |
26 | trying to identify the correct address for anything. */ | |
27 | ||
3db64b00 | 28 | #include "sysdep.h" |
252b5132 | 29 | #include "bfd.h" |
252b5132 | 30 | #include "libiberty.h" |
3882b010 | 31 | #include "safe-ctype.h" |
252b5132 RH |
32 | #include "demangle.h" |
33 | #include "debug.h" | |
34 | #include "budbg.h" | |
8855cbca | 35 | #include "filenames.h" |
252b5132 RH |
36 | #include "aout/aout64.h" |
37 | #include "aout/stab_gnu.h" | |
38 | ||
252b5132 RH |
39 | /* The number of predefined XCOFF types. */ |
40 | ||
41 | #define XCOFF_TYPE_COUNT 34 | |
42 | ||
43 | /* This structure is used as a handle so that the stab parsing doesn't | |
44 | need to use any static variables. */ | |
45 | ||
46 | struct stab_handle | |
47 | { | |
48 | /* The BFD. */ | |
49 | bfd *abfd; | |
b34976b6 AM |
50 | /* TRUE if this is stabs in sections. */ |
51 | bfd_boolean sections; | |
252b5132 RH |
52 | /* The symbol table. */ |
53 | asymbol **syms; | |
54 | /* The number of symbols. */ | |
55 | long symcount; | |
56 | /* The accumulated file name string. */ | |
57 | char *so_string; | |
58 | /* The value of the last N_SO symbol. */ | |
59 | bfd_vma so_value; | |
60 | /* The value of the start of the file, so that we can handle file | |
61 | relative N_LBRAC and N_RBRAC symbols. */ | |
62 | bfd_vma file_start_offset; | |
63 | /* The offset of the start of the function, so that we can handle | |
64 | function relative N_LBRAC and N_RBRAC symbols. */ | |
65 | bfd_vma function_start_offset; | |
66 | /* The version number of gcc which compiled the current compilation | |
67 | unit, 0 if not compiled by gcc. */ | |
68 | int gcc_compiled; | |
69 | /* Whether an N_OPT symbol was seen that was not generated by gcc, | |
70 | so that we can detect the SunPRO compiler. */ | |
b34976b6 | 71 | bfd_boolean n_opt_found; |
252b5132 RH |
72 | /* The main file name. */ |
73 | char *main_filename; | |
74 | /* A stack of unfinished N_BINCL files. */ | |
75 | struct bincl_file *bincl_stack; | |
76 | /* A list of finished N_BINCL files. */ | |
77 | struct bincl_file *bincl_list; | |
78 | /* Whether we are inside a function or not. */ | |
b34976b6 | 79 | bfd_boolean within_function; |
252b5132 RH |
80 | /* The address of the end of the function, used if we have seen an |
81 | N_FUN symbol while in a function. This is -1 if we have not seen | |
82 | an N_FUN (the normal case). */ | |
83 | bfd_vma function_end; | |
84 | /* The depth of block nesting. */ | |
85 | int block_depth; | |
86 | /* List of pending variable definitions. */ | |
87 | struct stab_pending_var *pending; | |
88 | /* Number of files for which we have types. */ | |
89 | unsigned int files; | |
90 | /* Lists of types per file. */ | |
91 | struct stab_types **file_types; | |
92 | /* Predefined XCOFF types. */ | |
93 | debug_type xcoff_types[XCOFF_TYPE_COUNT]; | |
94 | /* Undefined tags. */ | |
95 | struct stab_tag *tags; | |
96 | /* Set by parse_stab_type if it sees a structure defined as a cross | |
97 | reference to itself. Reset by parse_stab_type otherwise. */ | |
b34976b6 | 98 | bfd_boolean self_crossref; |
252b5132 RH |
99 | }; |
100 | ||
101 | /* A list of these structures is used to hold pending variable | |
102 | definitions seen before the N_LBRAC of a block. */ | |
103 | ||
104 | struct stab_pending_var | |
105 | { | |
106 | /* Next pending variable definition. */ | |
107 | struct stab_pending_var *next; | |
108 | /* Name. */ | |
109 | const char *name; | |
110 | /* Type. */ | |
111 | debug_type type; | |
112 | /* Kind. */ | |
113 | enum debug_var_kind kind; | |
114 | /* Value. */ | |
115 | bfd_vma val; | |
116 | }; | |
117 | ||
118 | /* A list of these structures is used to hold the types for a single | |
119 | file. */ | |
120 | ||
121 | struct stab_types | |
122 | { | |
123 | /* Next set of slots for this file. */ | |
124 | struct stab_types *next; | |
125 | /* Types indexed by type number. */ | |
126 | #define STAB_TYPES_SLOTS (16) | |
127 | debug_type types[STAB_TYPES_SLOTS]; | |
128 | }; | |
129 | ||
130 | /* We keep a list of undefined tags that we encounter, so that we can | |
131 | fill them in if the tag is later defined. */ | |
132 | ||
133 | struct stab_tag | |
134 | { | |
135 | /* Next undefined tag. */ | |
136 | struct stab_tag *next; | |
137 | /* Tag name. */ | |
138 | const char *name; | |
139 | /* Type kind. */ | |
140 | enum debug_type_kind kind; | |
141 | /* Slot to hold real type when we discover it. If we don't, we fill | |
142 | in an undefined tag type. */ | |
143 | debug_type slot; | |
144 | /* Indirect type we have created to point at slot. */ | |
145 | debug_type type; | |
146 | }; | |
147 | ||
2da42df6 AJ |
148 | static char *savestring (const char *, int); |
149 | static bfd_vma parse_number (const char **, bfd_boolean *); | |
150 | static void bad_stab (const char *); | |
151 | static void warn_stab (const char *, const char *); | |
b34976b6 | 152 | static bfd_boolean parse_stab_string |
2da42df6 | 153 | (void *, struct stab_handle *, int, int, bfd_vma, const char *); |
252b5132 | 154 | static debug_type parse_stab_type |
2da42df6 AJ |
155 | (void *, struct stab_handle *, const char *, const char **, debug_type **); |
156 | static bfd_boolean parse_stab_type_number (const char **, int *); | |
252b5132 | 157 | static debug_type parse_stab_range_type |
2da42df6 AJ |
158 | (void *, struct stab_handle *, const char *, const char **, const int *); |
159 | static debug_type parse_stab_sun_builtin_type (void *, const char **); | |
160 | static debug_type parse_stab_sun_floating_type (void *, const char **); | |
161 | static debug_type parse_stab_enum_type (void *, const char **); | |
252b5132 | 162 | static debug_type parse_stab_struct_type |
2da42df6 AJ |
163 | (void *, struct stab_handle *, const char *, const char **, |
164 | bfd_boolean, const int *); | |
b34976b6 | 165 | static bfd_boolean parse_stab_baseclasses |
2da42df6 | 166 | (void *, struct stab_handle *, const char **, debug_baseclass **); |
b34976b6 | 167 | static bfd_boolean parse_stab_struct_fields |
2da42df6 | 168 | (void *, struct stab_handle *, const char **, debug_field **, bfd_boolean *); |
b34976b6 | 169 | static bfd_boolean parse_stab_cpp_abbrev |
2da42df6 | 170 | (void *, struct stab_handle *, const char **, debug_field *); |
b34976b6 | 171 | static bfd_boolean parse_stab_one_struct_field |
2da42df6 AJ |
172 | (void *, struct stab_handle *, const char **, const char *, |
173 | debug_field *, bfd_boolean *); | |
b34976b6 | 174 | static bfd_boolean parse_stab_members |
2da42df6 AJ |
175 | (void *, struct stab_handle *, const char *, const char **, const int *, |
176 | debug_method **); | |
252b5132 | 177 | static debug_type parse_stab_argtypes |
2da42df6 AJ |
178 | (void *, struct stab_handle *, debug_type, const char *, const char *, |
179 | debug_type, const char *, bfd_boolean, bfd_boolean, const char **); | |
b34976b6 | 180 | static bfd_boolean parse_stab_tilde_field |
2da42df6 AJ |
181 | (void *, struct stab_handle *, const char **, const int *, debug_type *, |
182 | bfd_boolean *); | |
252b5132 | 183 | static debug_type parse_stab_array_type |
2da42df6 AJ |
184 | (void *, struct stab_handle *, const char **, bfd_boolean); |
185 | static void push_bincl (struct stab_handle *, const char *, bfd_vma); | |
186 | static const char *pop_bincl (struct stab_handle *); | |
187 | static bfd_boolean find_excl (struct stab_handle *, const char *, bfd_vma); | |
b34976b6 | 188 | static bfd_boolean stab_record_variable |
2da42df6 AJ |
189 | (void *, struct stab_handle *, const char *, debug_type, |
190 | enum debug_var_kind, bfd_vma); | |
191 | static bfd_boolean stab_emit_pending_vars (void *, struct stab_handle *); | |
192 | static debug_type *stab_find_slot (struct stab_handle *, const int *); | |
193 | static debug_type stab_find_type (void *, struct stab_handle *, const int *); | |
b34976b6 | 194 | static bfd_boolean stab_record_type |
2da42df6 | 195 | (void *, struct stab_handle *, const int *, debug_type); |
252b5132 | 196 | static debug_type stab_xcoff_builtin_type |
2da42df6 | 197 | (void *, struct stab_handle *, int); |
252b5132 | 198 | static debug_type stab_find_tagged_type |
2da42df6 | 199 | (void *, struct stab_handle *, const char *, int, enum debug_type_kind); |
252b5132 | 200 | static debug_type *stab_demangle_argtypes |
2da42df6 | 201 | (void *, struct stab_handle *, const char *, bfd_boolean *, unsigned int); |
041821e6 ILT |
202 | static debug_type *stab_demangle_v3_argtypes |
203 | (void *, struct stab_handle *, const char *, bfd_boolean *); | |
2b4c4cc4 ILT |
204 | static debug_type *stab_demangle_v3_arglist |
205 | (void *, struct stab_handle *, struct demangle_component *, bfd_boolean *); | |
041821e6 ILT |
206 | static debug_type stab_demangle_v3_arg |
207 | (void *, struct stab_handle *, struct demangle_component *, debug_type, | |
208 | bfd_boolean *); | |
252b5132 RH |
209 | |
210 | /* Save a string in memory. */ | |
211 | ||
212 | static char * | |
2da42df6 | 213 | savestring (const char *start, int len) |
252b5132 RH |
214 | { |
215 | char *ret; | |
216 | ||
217 | ret = (char *) xmalloc (len + 1); | |
218 | memcpy (ret, start, len); | |
219 | ret[len] = '\0'; | |
220 | return ret; | |
221 | } | |
222 | ||
223 | /* Read a number from a string. */ | |
224 | ||
225 | static bfd_vma | |
2da42df6 | 226 | parse_number (const char **pp, bfd_boolean *poverflow) |
252b5132 RH |
227 | { |
228 | unsigned long ul; | |
229 | const char *orig; | |
230 | ||
231 | if (poverflow != NULL) | |
b34976b6 | 232 | *poverflow = FALSE; |
252b5132 RH |
233 | |
234 | orig = *pp; | |
235 | ||
236 | errno = 0; | |
237 | ul = strtoul (*pp, (char **) pp, 0); | |
238 | if (ul + 1 != 0 || errno == 0) | |
239 | { | |
240 | /* If bfd_vma is larger than unsigned long, and the number is | |
241 | meant to be negative, we have to make sure that we sign | |
242 | extend properly. */ | |
243 | if (*orig == '-') | |
244 | return (bfd_vma) (bfd_signed_vma) (long) ul; | |
245 | return (bfd_vma) ul; | |
246 | } | |
247 | ||
248 | /* Note that even though strtoul overflowed, it should have set *pp | |
249 | to the end of the number, which is where we want it. */ | |
252b5132 RH |
250 | if (sizeof (bfd_vma) > sizeof (unsigned long)) |
251 | { | |
252 | const char *p; | |
b34976b6 | 253 | bfd_boolean neg; |
252b5132 RH |
254 | int base; |
255 | bfd_vma over, lastdig; | |
b34976b6 | 256 | bfd_boolean overflow; |
252b5132 RH |
257 | bfd_vma v; |
258 | ||
259 | /* Our own version of strtoul, for a bfd_vma. */ | |
252b5132 RH |
260 | p = orig; |
261 | ||
b34976b6 | 262 | neg = FALSE; |
252b5132 RH |
263 | if (*p == '+') |
264 | ++p; | |
265 | else if (*p == '-') | |
266 | { | |
b34976b6 | 267 | neg = TRUE; |
252b5132 RH |
268 | ++p; |
269 | } | |
270 | ||
271 | base = 10; | |
272 | if (*p == '0') | |
273 | { | |
274 | if (p[1] == 'x' || p[1] == 'X') | |
275 | { | |
276 | base = 16; | |
277 | p += 2; | |
278 | } | |
279 | else | |
280 | { | |
281 | base = 8; | |
282 | ++p; | |
283 | } | |
284 | } | |
285 | ||
286 | over = ((bfd_vma) (bfd_signed_vma) -1) / (bfd_vma) base; | |
287 | lastdig = ((bfd_vma) (bfd_signed_vma) -1) % (bfd_vma) base; | |
288 | ||
b34976b6 | 289 | overflow = FALSE; |
252b5132 RH |
290 | v = 0; |
291 | while (1) | |
292 | { | |
293 | int d; | |
294 | ||
295 | d = *p++; | |
3882b010 | 296 | if (ISDIGIT (d)) |
252b5132 | 297 | d -= '0'; |
3882b010 | 298 | else if (ISUPPER (d)) |
252b5132 | 299 | d -= 'A'; |
3882b010 | 300 | else if (ISLOWER (d)) |
252b5132 RH |
301 | d -= 'a'; |
302 | else | |
303 | break; | |
304 | ||
305 | if (d >= base) | |
306 | break; | |
307 | ||
308 | if (v > over || (v == over && (bfd_vma) d > lastdig)) | |
309 | { | |
b34976b6 | 310 | overflow = TRUE; |
252b5132 RH |
311 | break; |
312 | } | |
313 | } | |
314 | ||
315 | if (! overflow) | |
316 | { | |
317 | if (neg) | |
318 | v = - v; | |
319 | return v; | |
320 | } | |
321 | } | |
322 | ||
323 | /* If we get here, the number is too large to represent in a | |
324 | bfd_vma. */ | |
252b5132 | 325 | if (poverflow != NULL) |
b34976b6 | 326 | *poverflow = TRUE; |
252b5132 RH |
327 | else |
328 | warn_stab (orig, _("numeric overflow")); | |
329 | ||
330 | return 0; | |
331 | } | |
332 | ||
333 | /* Give an error for a bad stab string. */ | |
334 | ||
335 | static void | |
2da42df6 | 336 | bad_stab (const char *p) |
252b5132 RH |
337 | { |
338 | fprintf (stderr, _("Bad stab: %s\n"), p); | |
339 | } | |
340 | ||
341 | /* Warn about something in a stab string. */ | |
342 | ||
343 | static void | |
2da42df6 | 344 | warn_stab (const char *p, const char *err) |
252b5132 RH |
345 | { |
346 | fprintf (stderr, _("Warning: %s: %s\n"), err, p); | |
347 | } | |
348 | ||
349 | /* Create a handle to parse stabs symbols with. */ | |
350 | ||
2da42df6 AJ |
351 | void * |
352 | start_stab (void *dhandle ATTRIBUTE_UNUSED, bfd *abfd, bfd_boolean sections, | |
353 | asymbol **syms, long symcount) | |
252b5132 RH |
354 | { |
355 | struct stab_handle *ret; | |
356 | ||
357 | ret = (struct stab_handle *) xmalloc (sizeof *ret); | |
358 | memset (ret, 0, sizeof *ret); | |
359 | ret->abfd = abfd; | |
360 | ret->sections = sections; | |
361 | ret->syms = syms; | |
362 | ret->symcount = symcount; | |
363 | ret->files = 1; | |
364 | ret->file_types = (struct stab_types **) xmalloc (sizeof *ret->file_types); | |
365 | ret->file_types[0] = NULL; | |
366 | ret->function_end = (bfd_vma) -1; | |
2da42df6 | 367 | return (void *) ret; |
252b5132 RH |
368 | } |
369 | ||
370 | /* When we have processed all the stabs information, we need to go | |
371 | through and fill in all the undefined tags. */ | |
372 | ||
b34976b6 | 373 | bfd_boolean |
2da42df6 | 374 | finish_stab (void *dhandle, void *handle) |
252b5132 RH |
375 | { |
376 | struct stab_handle *info = (struct stab_handle *) handle; | |
377 | struct stab_tag *st; | |
378 | ||
379 | if (info->within_function) | |
380 | { | |
381 | if (! stab_emit_pending_vars (dhandle, info) | |
382 | || ! debug_end_function (dhandle, info->function_end)) | |
b34976b6 AM |
383 | return FALSE; |
384 | info->within_function = FALSE; | |
252b5132 RH |
385 | info->function_end = (bfd_vma) -1; |
386 | } | |
387 | ||
388 | for (st = info->tags; st != NULL; st = st->next) | |
389 | { | |
390 | enum debug_type_kind kind; | |
391 | ||
392 | kind = st->kind; | |
393 | if (kind == DEBUG_KIND_ILLEGAL) | |
394 | kind = DEBUG_KIND_STRUCT; | |
395 | st->slot = debug_make_undefined_tagged_type (dhandle, st->name, kind); | |
396 | if (st->slot == DEBUG_TYPE_NULL) | |
b34976b6 | 397 | return FALSE; |
252b5132 RH |
398 | } |
399 | ||
b34976b6 | 400 | return TRUE; |
252b5132 RH |
401 | } |
402 | ||
403 | /* Handle a single stabs symbol. */ | |
404 | ||
b34976b6 | 405 | bfd_boolean |
2da42df6 AJ |
406 | parse_stab (void *dhandle, void *handle, int type, int desc, bfd_vma value, |
407 | const char *string) | |
252b5132 RH |
408 | { |
409 | struct stab_handle *info = (struct stab_handle *) handle; | |
410 | ||
411 | /* gcc will emit two N_SO strings per compilation unit, one for the | |
412 | directory name and one for the file name. We just collect N_SO | |
413 | strings as we see them, and start the new compilation unit when | |
414 | we see a non N_SO symbol. */ | |
415 | if (info->so_string != NULL | |
416 | && (type != N_SO || *string == '\0' || value != info->so_value)) | |
417 | { | |
418 | if (! debug_set_filename (dhandle, info->so_string)) | |
b34976b6 | 419 | return FALSE; |
252b5132 RH |
420 | info->main_filename = info->so_string; |
421 | ||
422 | info->gcc_compiled = 0; | |
b34976b6 | 423 | info->n_opt_found = FALSE; |
252b5132 RH |
424 | |
425 | /* Generally, for stabs in the symbol table, the N_LBRAC and | |
426 | N_RBRAC symbols are relative to the N_SO symbol value. */ | |
427 | if (! info->sections) | |
428 | info->file_start_offset = info->so_value; | |
429 | ||
430 | /* We need to reset the mapping from type numbers to types. We | |
431 | can't free the old mapping, because of the use of | |
432 | debug_make_indirect_type. */ | |
433 | info->files = 1; | |
434 | info->file_types = ((struct stab_types **) | |
435 | xmalloc (sizeof *info->file_types)); | |
436 | info->file_types[0] = NULL; | |
437 | ||
438 | info->so_string = NULL; | |
439 | ||
440 | /* Now process whatever type we just got. */ | |
441 | } | |
442 | ||
443 | switch (type) | |
444 | { | |
445 | case N_FN: | |
446 | case N_FN_SEQ: | |
447 | break; | |
448 | ||
449 | case N_LBRAC: | |
450 | /* Ignore extra outermost context from SunPRO cc and acc. */ | |
451 | if (info->n_opt_found && desc == 1) | |
452 | break; | |
453 | ||
454 | if (! info->within_function) | |
455 | { | |
456 | fprintf (stderr, _("N_LBRAC not within function\n")); | |
b34976b6 | 457 | return FALSE; |
252b5132 RH |
458 | } |
459 | ||
460 | /* Start an inner lexical block. */ | |
461 | if (! debug_start_block (dhandle, | |
462 | (value | |
463 | + info->file_start_offset | |
464 | + info->function_start_offset))) | |
b34976b6 | 465 | return FALSE; |
252b5132 RH |
466 | |
467 | /* Emit any pending variable definitions. */ | |
468 | if (! stab_emit_pending_vars (dhandle, info)) | |
b34976b6 | 469 | return FALSE; |
252b5132 RH |
470 | |
471 | ++info->block_depth; | |
472 | break; | |
473 | ||
474 | case N_RBRAC: | |
475 | /* Ignore extra outermost context from SunPRO cc and acc. */ | |
476 | if (info->n_opt_found && desc == 1) | |
477 | break; | |
478 | ||
479 | /* We shouldn't have any pending variable definitions here, but, | |
480 | if we do, we probably need to emit them before closing the | |
481 | block. */ | |
482 | if (! stab_emit_pending_vars (dhandle, info)) | |
b34976b6 | 483 | return FALSE; |
252b5132 RH |
484 | |
485 | /* End an inner lexical block. */ | |
486 | if (! debug_end_block (dhandle, | |
487 | (value | |
488 | + info->file_start_offset | |
489 | + info->function_start_offset))) | |
b34976b6 | 490 | return FALSE; |
252b5132 RH |
491 | |
492 | --info->block_depth; | |
493 | if (info->block_depth < 0) | |
494 | { | |
495 | fprintf (stderr, _("Too many N_RBRACs\n")); | |
b34976b6 | 496 | return FALSE; |
252b5132 RH |
497 | } |
498 | break; | |
499 | ||
500 | case N_SO: | |
501 | /* This always ends a function. */ | |
502 | if (info->within_function) | |
503 | { | |
504 | bfd_vma endval; | |
505 | ||
506 | endval = value; | |
507 | if (*string != '\0' | |
508 | && info->function_end != (bfd_vma) -1 | |
509 | && info->function_end < endval) | |
510 | endval = info->function_end; | |
511 | if (! stab_emit_pending_vars (dhandle, info) | |
512 | || ! debug_end_function (dhandle, endval)) | |
b34976b6 AM |
513 | return FALSE; |
514 | info->within_function = FALSE; | |
252b5132 RH |
515 | info->function_end = (bfd_vma) -1; |
516 | } | |
517 | ||
518 | /* An empty string is emitted by gcc at the end of a compilation | |
519 | unit. */ | |
520 | if (*string == '\0') | |
b34976b6 | 521 | return TRUE; |
252b5132 RH |
522 | |
523 | /* Just accumulate strings until we see a non N_SO symbol. If | |
524 | the string starts with a directory separator or some other | |
525 | form of absolute path specification, we discard the previously | |
526 | accumulated strings. */ | |
527 | if (info->so_string == NULL) | |
528 | info->so_string = xstrdup (string); | |
529 | else | |
530 | { | |
531 | char *f; | |
532 | ||
533 | f = info->so_string; | |
534 | ||
9f66665a | 535 | if (IS_ABSOLUTE_PATH (string)) |
252b5132 RH |
536 | info->so_string = xstrdup (string); |
537 | else | |
538 | info->so_string = concat (info->so_string, string, | |
539 | (const char *) NULL); | |
540 | free (f); | |
541 | } | |
542 | ||
543 | info->so_value = value; | |
544 | ||
545 | break; | |
546 | ||
547 | case N_SOL: | |
548 | /* Start an include file. */ | |
549 | if (! debug_start_source (dhandle, string)) | |
b34976b6 | 550 | return FALSE; |
252b5132 RH |
551 | break; |
552 | ||
553 | case N_BINCL: | |
554 | /* Start an include file which may be replaced. */ | |
555 | push_bincl (info, string, value); | |
556 | if (! debug_start_source (dhandle, string)) | |
b34976b6 | 557 | return FALSE; |
252b5132 RH |
558 | break; |
559 | ||
560 | case N_EINCL: | |
561 | /* End an N_BINCL include. */ | |
562 | if (! debug_start_source (dhandle, pop_bincl (info))) | |
b34976b6 | 563 | return FALSE; |
252b5132 RH |
564 | break; |
565 | ||
566 | case N_EXCL: | |
567 | /* This is a duplicate of a header file named by N_BINCL which | |
568 | was eliminated by the linker. */ | |
569 | if (! find_excl (info, string, value)) | |
b34976b6 | 570 | return FALSE; |
252b5132 RH |
571 | break; |
572 | ||
573 | case N_SLINE: | |
574 | if (! debug_record_line (dhandle, desc, | |
6de15b9e NC |
575 | value + (info->within_function |
576 | ? info->function_start_offset : 0))) | |
b34976b6 | 577 | return FALSE; |
252b5132 RH |
578 | break; |
579 | ||
580 | case N_BCOMM: | |
581 | if (! debug_start_common_block (dhandle, string)) | |
b34976b6 | 582 | return FALSE; |
252b5132 RH |
583 | break; |
584 | ||
585 | case N_ECOMM: | |
586 | if (! debug_end_common_block (dhandle, string)) | |
b34976b6 | 587 | return FALSE; |
252b5132 RH |
588 | break; |
589 | ||
590 | case N_FUN: | |
591 | if (*string == '\0') | |
592 | { | |
593 | if (info->within_function) | |
594 | { | |
595 | /* This always marks the end of a function; we don't | |
596 | need to worry about info->function_end. */ | |
597 | if (info->sections) | |
598 | value += info->function_start_offset; | |
599 | if (! stab_emit_pending_vars (dhandle, info) | |
600 | || ! debug_end_function (dhandle, value)) | |
b34976b6 AM |
601 | return FALSE; |
602 | info->within_function = FALSE; | |
252b5132 RH |
603 | info->function_end = (bfd_vma) -1; |
604 | } | |
605 | break; | |
606 | } | |
607 | ||
608 | /* A const static symbol in the .text section will have an N_FUN | |
609 | entry. We need to use these to mark the end of the function, | |
610 | in case we are looking at gcc output before it was changed to | |
611 | always emit an empty N_FUN. We can't call debug_end_function | |
612 | here, because it might be a local static symbol. */ | |
613 | if (info->within_function | |
614 | && (info->function_end == (bfd_vma) -1 | |
615 | || value < info->function_end)) | |
616 | info->function_end = value; | |
617 | ||
618 | /* Fall through. */ | |
619 | /* FIXME: gdb checks the string for N_STSYM, N_LCSYM or N_ROSYM | |
620 | symbols, and if it does not start with :S, gdb relocates the | |
621 | value to the start of the section. gcc always seems to use | |
622 | :S, so we don't worry about this. */ | |
623 | /* Fall through. */ | |
624 | default: | |
625 | { | |
626 | const char *colon; | |
627 | ||
628 | colon = strchr (string, ':'); | |
629 | if (colon != NULL | |
630 | && (colon[1] == 'f' || colon[1] == 'F')) | |
631 | { | |
632 | if (info->within_function) | |
633 | { | |
634 | bfd_vma endval; | |
635 | ||
636 | endval = value; | |
637 | if (info->function_end != (bfd_vma) -1 | |
638 | && info->function_end < endval) | |
639 | endval = info->function_end; | |
640 | if (! stab_emit_pending_vars (dhandle, info) | |
641 | || ! debug_end_function (dhandle, endval)) | |
b34976b6 | 642 | return FALSE; |
252b5132 RH |
643 | info->function_end = (bfd_vma) -1; |
644 | } | |
645 | /* For stabs in sections, line numbers and block addresses | |
646 | are offsets from the start of the function. */ | |
647 | if (info->sections) | |
648 | info->function_start_offset = value; | |
b34976b6 | 649 | info->within_function = TRUE; |
252b5132 RH |
650 | } |
651 | ||
652 | if (! parse_stab_string (dhandle, info, type, desc, value, string)) | |
b34976b6 | 653 | return FALSE; |
252b5132 RH |
654 | } |
655 | break; | |
656 | ||
657 | case N_OPT: | |
658 | if (string != NULL && strcmp (string, "gcc2_compiled.") == 0) | |
659 | info->gcc_compiled = 2; | |
660 | else if (string != NULL && strcmp (string, "gcc_compiled.") == 0) | |
661 | info->gcc_compiled = 1; | |
662 | else | |
b34976b6 | 663 | info->n_opt_found = TRUE; |
252b5132 RH |
664 | break; |
665 | ||
666 | case N_OBJ: | |
667 | case N_ENDM: | |
668 | case N_MAIN: | |
8855cbca | 669 | case N_WARNING: |
252b5132 RH |
670 | break; |
671 | } | |
672 | ||
b34976b6 | 673 | return TRUE; |
252b5132 RH |
674 | } |
675 | ||
676 | /* Parse the stabs string. */ | |
677 | ||
b34976b6 | 678 | static bfd_boolean |
2da42df6 | 679 | parse_stab_string (void *dhandle, struct stab_handle *info, int stabtype, |
3d540e93 | 680 | int desc ATTRIBUTE_UNUSED, bfd_vma value, const char *string) |
252b5132 RH |
681 | { |
682 | const char *p; | |
683 | char *name; | |
684 | int type; | |
685 | debug_type dtype; | |
b34976b6 AM |
686 | bfd_boolean synonym; |
687 | bfd_boolean self_crossref; | |
252b5132 RH |
688 | debug_type *slot; |
689 | ||
690 | p = strchr (string, ':'); | |
691 | if (p == NULL) | |
b34976b6 | 692 | return TRUE; |
252b5132 RH |
693 | |
694 | while (p[1] == ':') | |
695 | { | |
696 | p += 2; | |
697 | p = strchr (p, ':'); | |
698 | if (p == NULL) | |
699 | { | |
700 | bad_stab (string); | |
b34976b6 | 701 | return FALSE; |
252b5132 RH |
702 | } |
703 | } | |
704 | ||
252b5132 RH |
705 | /* FIXME: Sometimes the special C++ names start with '.'. */ |
706 | name = NULL; | |
707 | if (string[0] == '$') | |
708 | { | |
709 | switch (string[1]) | |
710 | { | |
711 | case 't': | |
712 | name = "this"; | |
713 | break; | |
714 | case 'v': | |
715 | /* Was: name = "vptr"; */ | |
716 | break; | |
717 | case 'e': | |
718 | name = "eh_throw"; | |
719 | break; | |
720 | case '_': | |
721 | /* This was an anonymous type that was never fixed up. */ | |
722 | break; | |
723 | case 'X': | |
724 | /* SunPRO (3.0 at least) static variable encoding. */ | |
725 | break; | |
726 | default: | |
727 | warn_stab (string, _("unknown C++ encoded name")); | |
728 | break; | |
729 | } | |
730 | } | |
731 | ||
732 | if (name == NULL) | |
733 | { | |
734 | if (p == string || (string[0] == ' ' && p == string + 1)) | |
735 | name = NULL; | |
736 | else | |
737 | name = savestring (string, p - string); | |
738 | } | |
739 | ||
740 | ++p; | |
3882b010 | 741 | if (ISDIGIT (*p) || *p == '(' || *p == '-') |
252b5132 RH |
742 | type = 'l'; |
743 | else | |
744 | type = *p++; | |
745 | ||
746 | switch (type) | |
747 | { | |
748 | case 'c': | |
749 | /* c is a special case, not followed by a type-number. | |
750 | SYMBOL:c=iVALUE for an integer constant symbol. | |
751 | SYMBOL:c=rVALUE for a floating constant symbol. | |
752 | SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol. | |
753 | e.g. "b:c=e6,0" for "const b = blob1" | |
754 | (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */ | |
755 | if (*p != '=') | |
756 | { | |
757 | bad_stab (string); | |
b34976b6 | 758 | return FALSE; |
252b5132 RH |
759 | } |
760 | ++p; | |
761 | switch (*p++) | |
762 | { | |
763 | case 'r': | |
764 | /* Floating point constant. */ | |
765 | if (! debug_record_float_const (dhandle, name, atof (p))) | |
b34976b6 | 766 | return FALSE; |
252b5132 RH |
767 | break; |
768 | case 'i': | |
769 | /* Integer constant. */ | |
770 | /* Defining integer constants this way is kind of silly, | |
771 | since 'e' constants allows the compiler to give not only | |
772 | the value, but the type as well. C has at least int, | |
773 | long, unsigned int, and long long as constant types; | |
774 | other languages probably should have at least unsigned as | |
775 | well as signed constants. */ | |
776 | if (! debug_record_int_const (dhandle, name, atoi (p))) | |
b34976b6 | 777 | return FALSE; |
252b5132 RH |
778 | break; |
779 | case 'e': | |
780 | /* SYMBOL:c=eTYPE,INTVALUE for a constant symbol whose value | |
781 | can be represented as integral. | |
782 | e.g. "b:c=e6,0" for "const b = blob1" | |
783 | (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */ | |
784 | dtype = parse_stab_type (dhandle, info, (const char *) NULL, | |
785 | &p, (debug_type **) NULL); | |
786 | if (dtype == DEBUG_TYPE_NULL) | |
b34976b6 | 787 | return FALSE; |
252b5132 RH |
788 | if (*p != ',') |
789 | { | |
790 | bad_stab (string); | |
b34976b6 | 791 | return FALSE; |
252b5132 RH |
792 | } |
793 | if (! debug_record_typed_const (dhandle, name, dtype, atoi (p))) | |
b34976b6 | 794 | return FALSE; |
252b5132 RH |
795 | break; |
796 | default: | |
797 | bad_stab (string); | |
b34976b6 | 798 | return FALSE; |
252b5132 RH |
799 | } |
800 | ||
801 | break; | |
802 | ||
803 | case 'C': | |
804 | /* The name of a caught exception. */ | |
805 | dtype = parse_stab_type (dhandle, info, (const char *) NULL, | |
806 | &p, (debug_type **) NULL); | |
807 | if (dtype == DEBUG_TYPE_NULL) | |
b34976b6 | 808 | return FALSE; |
252b5132 | 809 | if (! debug_record_label (dhandle, name, dtype, value)) |
b34976b6 | 810 | return FALSE; |
252b5132 RH |
811 | break; |
812 | ||
813 | case 'f': | |
814 | case 'F': | |
815 | /* A function definition. */ | |
816 | dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p, | |
817 | (debug_type **) NULL); | |
818 | if (dtype == DEBUG_TYPE_NULL) | |
b34976b6 | 819 | return FALSE; |
252b5132 | 820 | if (! debug_record_function (dhandle, name, dtype, type == 'F', value)) |
b34976b6 | 821 | return FALSE; |
252b5132 RH |
822 | |
823 | /* Sun acc puts declared types of arguments here. We don't care | |
824 | about their actual types (FIXME -- we should remember the whole | |
825 | function prototype), but the list may define some new types | |
826 | that we have to remember, so we must scan it now. */ | |
827 | while (*p == ';') | |
828 | { | |
829 | ++p; | |
830 | if (parse_stab_type (dhandle, info, (const char *) NULL, &p, | |
831 | (debug_type **) NULL) | |
832 | == DEBUG_TYPE_NULL) | |
b34976b6 | 833 | return FALSE; |
252b5132 RH |
834 | } |
835 | ||
836 | break; | |
837 | ||
838 | case 'G': | |
839 | { | |
840 | char leading; | |
841 | long c; | |
842 | asymbol **ps; | |
843 | ||
844 | /* A global symbol. The value must be extracted from the | |
845 | symbol table. */ | |
846 | dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p, | |
847 | (debug_type **) NULL); | |
848 | if (dtype == DEBUG_TYPE_NULL) | |
b34976b6 | 849 | return FALSE; |
252b5132 RH |
850 | leading = bfd_get_symbol_leading_char (info->abfd); |
851 | for (c = info->symcount, ps = info->syms; c > 0; --c, ++ps) | |
852 | { | |
853 | const char *n; | |
854 | ||
855 | n = bfd_asymbol_name (*ps); | |
856 | if (leading != '\0' && *n == leading) | |
857 | ++n; | |
858 | if (*n == *name && strcmp (n, name) == 0) | |
859 | break; | |
860 | } | |
861 | if (c > 0) | |
862 | value = bfd_asymbol_value (*ps); | |
863 | if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_GLOBAL, | |
864 | value)) | |
b34976b6 | 865 | return FALSE; |
252b5132 RH |
866 | } |
867 | break; | |
868 | ||
869 | /* This case is faked by a conditional above, when there is no | |
870 | code letter in the dbx data. Dbx data never actually | |
871 | contains 'l'. */ | |
872 | case 'l': | |
873 | case 's': | |
874 | dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p, | |
875 | (debug_type **) NULL); | |
876 | if (dtype == DEBUG_TYPE_NULL) | |
b34976b6 | 877 | return FALSE; |
252b5132 RH |
878 | if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_LOCAL, |
879 | value)) | |
b34976b6 | 880 | return FALSE; |
252b5132 RH |
881 | break; |
882 | ||
883 | case 'p': | |
884 | /* A function parameter. */ | |
885 | if (*p != 'F') | |
886 | dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p, | |
887 | (debug_type **) NULL); | |
888 | else | |
889 | { | |
890 | /* pF is a two-letter code that means a function parameter in | |
891 | Fortran. The type-number specifies the type of the return | |
892 | value. Translate it into a pointer-to-function type. */ | |
893 | ++p; | |
894 | dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p, | |
895 | (debug_type **) NULL); | |
896 | if (dtype != DEBUG_TYPE_NULL) | |
897 | { | |
898 | debug_type ftype; | |
899 | ||
900 | ftype = debug_make_function_type (dhandle, dtype, | |
b34976b6 | 901 | (debug_type *) NULL, FALSE); |
252b5132 RH |
902 | dtype = debug_make_pointer_type (dhandle, ftype); |
903 | } | |
904 | } | |
905 | if (dtype == DEBUG_TYPE_NULL) | |
b34976b6 | 906 | return FALSE; |
252b5132 RH |
907 | if (! debug_record_parameter (dhandle, name, dtype, DEBUG_PARM_STACK, |
908 | value)) | |
b34976b6 | 909 | return FALSE; |
252b5132 RH |
910 | |
911 | /* FIXME: At this point gdb considers rearranging the parameter | |
912 | address on a big endian machine if it is smaller than an int. | |
913 | We have no way to do that, since we don't really know much | |
914 | about the target. */ | |
252b5132 RH |
915 | break; |
916 | ||
917 | case 'P': | |
918 | if (stabtype == N_FUN) | |
919 | { | |
920 | /* Prototype of a function referenced by this file. */ | |
921 | while (*p == ';') | |
922 | { | |
923 | ++p; | |
924 | if (parse_stab_type (dhandle, info, (const char *) NULL, &p, | |
925 | (debug_type **) NULL) | |
926 | == DEBUG_TYPE_NULL) | |
b34976b6 | 927 | return FALSE; |
252b5132 RH |
928 | } |
929 | break; | |
930 | } | |
931 | /* Fall through. */ | |
932 | case 'R': | |
933 | /* Parameter which is in a register. */ | |
934 | dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p, | |
935 | (debug_type **) NULL); | |
936 | if (dtype == DEBUG_TYPE_NULL) | |
b34976b6 | 937 | return FALSE; |
252b5132 RH |
938 | if (! debug_record_parameter (dhandle, name, dtype, DEBUG_PARM_REG, |
939 | value)) | |
b34976b6 | 940 | return FALSE; |
252b5132 RH |
941 | break; |
942 | ||
943 | case 'r': | |
944 | /* Register variable (either global or local). */ | |
945 | dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p, | |
946 | (debug_type **) NULL); | |
947 | if (dtype == DEBUG_TYPE_NULL) | |
b34976b6 | 948 | return FALSE; |
252b5132 RH |
949 | if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_REGISTER, |
950 | value)) | |
b34976b6 | 951 | return FALSE; |
252b5132 RH |
952 | |
953 | /* FIXME: At this point gdb checks to combine pairs of 'p' and | |
954 | 'r' stabs into a single 'P' stab. */ | |
252b5132 RH |
955 | break; |
956 | ||
957 | case 'S': | |
7eb5191a | 958 | /* Static symbol at top level of file. */ |
252b5132 RH |
959 | dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p, |
960 | (debug_type **) NULL); | |
961 | if (dtype == DEBUG_TYPE_NULL) | |
b34976b6 | 962 | return FALSE; |
252b5132 RH |
963 | if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_STATIC, |
964 | value)) | |
b34976b6 | 965 | return FALSE; |
252b5132 RH |
966 | break; |
967 | ||
968 | case 't': | |
969 | /* A typedef. */ | |
970 | dtype = parse_stab_type (dhandle, info, name, &p, &slot); | |
971 | if (dtype == DEBUG_TYPE_NULL) | |
b34976b6 | 972 | return FALSE; |
252b5132 RH |
973 | if (name == NULL) |
974 | { | |
975 | /* A nameless type. Nothing to do. */ | |
b34976b6 | 976 | return TRUE; |
252b5132 RH |
977 | } |
978 | ||
979 | dtype = debug_name_type (dhandle, name, dtype); | |
980 | if (dtype == DEBUG_TYPE_NULL) | |
b34976b6 | 981 | return FALSE; |
252b5132 RH |
982 | |
983 | if (slot != NULL) | |
984 | *slot = dtype; | |
985 | ||
986 | break; | |
987 | ||
988 | case 'T': | |
989 | /* Struct, union, or enum tag. For GNU C++, this can be be followed | |
990 | by 't' which means we are typedef'ing it as well. */ | |
991 | if (*p != 't') | |
992 | { | |
b34976b6 AM |
993 | synonym = FALSE; |
994 | /* FIXME: gdb sets synonym to TRUE if the current language | |
252b5132 RH |
995 | is C++. */ |
996 | } | |
997 | else | |
998 | { | |
b34976b6 | 999 | synonym = TRUE; |
252b5132 RH |
1000 | ++p; |
1001 | } | |
1002 | ||
1003 | dtype = parse_stab_type (dhandle, info, name, &p, &slot); | |
1004 | if (dtype == DEBUG_TYPE_NULL) | |
b34976b6 | 1005 | return FALSE; |
252b5132 | 1006 | if (name == NULL) |
b34976b6 | 1007 | return TRUE; |
252b5132 RH |
1008 | |
1009 | /* INFO->SELF_CROSSREF is set by parse_stab_type if this type is | |
1010 | a cross reference to itself. These are generated by some | |
1011 | versions of g++. */ | |
1012 | self_crossref = info->self_crossref; | |
1013 | ||
1014 | dtype = debug_tag_type (dhandle, name, dtype); | |
1015 | if (dtype == DEBUG_TYPE_NULL) | |
b34976b6 | 1016 | return FALSE; |
252b5132 RH |
1017 | if (slot != NULL) |
1018 | *slot = dtype; | |
1019 | ||
1020 | /* See if we have a cross reference to this tag which we can now | |
1021 | fill in. Avoid filling in a cross reference to ourselves, | |
1022 | because that would lead to circular debugging information. */ | |
1023 | if (! self_crossref) | |
1024 | { | |
1025 | register struct stab_tag **pst; | |
1026 | ||
1027 | for (pst = &info->tags; *pst != NULL; pst = &(*pst)->next) | |
1028 | { | |
1029 | if ((*pst)->name[0] == name[0] | |
1030 | && strcmp ((*pst)->name, name) == 0) | |
1031 | { | |
1032 | (*pst)->slot = dtype; | |
1033 | *pst = (*pst)->next; | |
1034 | break; | |
1035 | } | |
1036 | } | |
1037 | } | |
1038 | ||
1039 | if (synonym) | |
1040 | { | |
1041 | dtype = debug_name_type (dhandle, name, dtype); | |
1042 | if (dtype == DEBUG_TYPE_NULL) | |
b34976b6 | 1043 | return FALSE; |
252b5132 RH |
1044 | |
1045 | if (slot != NULL) | |
1046 | *slot = dtype; | |
1047 | } | |
1048 | ||
1049 | break; | |
1050 | ||
1051 | case 'V': | |
1052 | /* Static symbol of local scope */ | |
1053 | dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p, | |
1054 | (debug_type **) NULL); | |
1055 | if (dtype == DEBUG_TYPE_NULL) | |
b34976b6 | 1056 | return FALSE; |
252b5132 RH |
1057 | /* FIXME: gdb checks os9k_stabs here. */ |
1058 | if (! stab_record_variable (dhandle, info, name, dtype, | |
1059 | DEBUG_LOCAL_STATIC, value)) | |
b34976b6 | 1060 | return FALSE; |
252b5132 RH |
1061 | break; |
1062 | ||
1063 | case 'v': | |
1064 | /* Reference parameter. */ | |
1065 | dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p, | |
1066 | (debug_type **) NULL); | |
1067 | if (dtype == DEBUG_TYPE_NULL) | |
b34976b6 | 1068 | return FALSE; |
252b5132 RH |
1069 | if (! debug_record_parameter (dhandle, name, dtype, DEBUG_PARM_REFERENCE, |
1070 | value)) | |
b34976b6 | 1071 | return FALSE; |
252b5132 RH |
1072 | break; |
1073 | ||
1074 | case 'a': | |
1075 | /* Reference parameter which is in a register. */ | |
1076 | dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p, | |
1077 | (debug_type **) NULL); | |
1078 | if (dtype == DEBUG_TYPE_NULL) | |
b34976b6 | 1079 | return FALSE; |
252b5132 RH |
1080 | if (! debug_record_parameter (dhandle, name, dtype, DEBUG_PARM_REF_REG, |
1081 | value)) | |
b34976b6 | 1082 | return FALSE; |
252b5132 RH |
1083 | break; |
1084 | ||
1085 | case 'X': | |
1086 | /* This is used by Sun FORTRAN for "function result value". | |
1087 | Sun claims ("dbx and dbxtool interfaces", 2nd ed) | |
1088 | that Pascal uses it too, but when I tried it Pascal used | |
1089 | "x:3" (local symbol) instead. */ | |
1090 | dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p, | |
1091 | (debug_type **) NULL); | |
1092 | if (dtype == DEBUG_TYPE_NULL) | |
b34976b6 | 1093 | return FALSE; |
252b5132 RH |
1094 | if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_LOCAL, |
1095 | value)) | |
b34976b6 | 1096 | return FALSE; |
252b5132 RH |
1097 | break; |
1098 | ||
6176abac NC |
1099 | case 'Y': |
1100 | /* SUNPro C++ Namespace =Yn0. */ | |
1101 | /* Skip the namespace mapping, as it is not used now. */ | |
1102 | if (*(++p) == 'n' && *(++p) == '0') | |
1103 | { | |
1104 | /* =Yn0name; */ | |
1105 | while (*p != ';') | |
1106 | ++p; | |
1107 | ++p; | |
1108 | return TRUE; | |
1109 | } | |
1110 | /* TODO SUNPro C++ support: | |
1111 | Support default arguments after F,P parameters | |
1112 | Ya = Anonymous unions | |
1113 | YM,YD = Pointers to class members | |
1114 | YT,YI = Templates | |
1115 | YR = Run-time type information (RTTI) */ | |
1116 | ||
1117 | /* Fall through. */ | |
1118 | ||
252b5132 RH |
1119 | default: |
1120 | bad_stab (string); | |
b34976b6 | 1121 | return FALSE; |
252b5132 RH |
1122 | } |
1123 | ||
1124 | /* FIXME: gdb converts structure values to structure pointers in a | |
1125 | couple of cases, depending upon the target. */ | |
1126 | ||
b34976b6 | 1127 | return TRUE; |
252b5132 RH |
1128 | } |
1129 | ||
1130 | /* Parse a stabs type. The typename argument is non-NULL if this is a | |
1131 | typedef or a tag definition. The pp argument points to the stab | |
1132 | string, and is updated. The slotp argument points to a place to | |
1133 | store the slot used if the type is being defined. */ | |
1134 | ||
1135 | static debug_type | |
3f5e193b | 1136 | parse_stab_type (void *dhandle, struct stab_handle *info, const char *type_name, const char **pp, debug_type **slotp) |
252b5132 RH |
1137 | { |
1138 | const char *orig; | |
1139 | int typenums[2]; | |
1140 | int size; | |
b34976b6 | 1141 | bfd_boolean stringp; |
252b5132 RH |
1142 | int descriptor; |
1143 | debug_type dtype; | |
1144 | ||
1145 | if (slotp != NULL) | |
1146 | *slotp = NULL; | |
1147 | ||
1148 | orig = *pp; | |
1149 | ||
1150 | size = -1; | |
b34976b6 | 1151 | stringp = FALSE; |
252b5132 | 1152 | |
b34976b6 | 1153 | info->self_crossref = FALSE; |
252b5132 RH |
1154 | |
1155 | /* Read type number if present. The type number may be omitted. | |
1156 | for instance in a two-dimensional array declared with type | |
1157 | "ar1;1;10;ar1;1;10;4". */ | |
3882b010 | 1158 | if (! ISDIGIT (**pp) && **pp != '(' && **pp != '-') |
252b5132 RH |
1159 | { |
1160 | /* 'typenums=' not present, type is anonymous. Read and return | |
1161 | the definition, but don't put it in the type vector. */ | |
1162 | typenums[0] = typenums[1] = -1; | |
1163 | } | |
1164 | else | |
1165 | { | |
1166 | if (! parse_stab_type_number (pp, typenums)) | |
1167 | return DEBUG_TYPE_NULL; | |
1168 | ||
1169 | if (**pp != '=') | |
7eb5191a NC |
1170 | /* Type is not being defined here. Either it already |
1171 | exists, or this is a forward reference to it. */ | |
1172 | return stab_find_type (dhandle, info, typenums); | |
252b5132 RH |
1173 | |
1174 | /* Only set the slot if the type is being defined. This means | |
1175 | that the mapping from type numbers to types will only record | |
1176 | the name of the typedef which defines a type. If we don't do | |
1177 | this, then something like | |
1178 | typedef int foo; | |
1179 | int i; | |
1180 | will record that i is of type foo. Unfortunately, stabs | |
1181 | information is ambiguous about variable types. For this code, | |
1182 | typedef int foo; | |
1183 | int i; | |
1184 | foo j; | |
1185 | the stabs information records both i and j as having the same | |
1186 | type. This could be fixed by patching the compiler. */ | |
1187 | if (slotp != NULL && typenums[0] >= 0 && typenums[1] >= 0) | |
1188 | *slotp = stab_find_slot (info, typenums); | |
1189 | ||
1190 | /* Type is being defined here. */ | |
1191 | /* Skip the '='. */ | |
1192 | ++*pp; | |
1193 | ||
1194 | while (**pp == '@') | |
1195 | { | |
1196 | const char *p = *pp + 1; | |
1197 | const char *attr; | |
1198 | ||
3882b010 | 1199 | if (ISDIGIT (*p) || *p == '(' || *p == '-') |
7eb5191a NC |
1200 | /* Member type. */ |
1201 | break; | |
252b5132 RH |
1202 | |
1203 | /* Type attributes. */ | |
1204 | attr = p; | |
1205 | ||
1206 | for (; *p != ';'; ++p) | |
1207 | { | |
1208 | if (*p == '\0') | |
1209 | { | |
1210 | bad_stab (orig); | |
1211 | return DEBUG_TYPE_NULL; | |
1212 | } | |
1213 | } | |
1214 | *pp = p + 1; | |
1215 | ||
1216 | switch (*attr) | |
1217 | { | |
1218 | case 's': | |
1219 | size = atoi (attr + 1); | |
944e5c61 | 1220 | size /= 8; /* Size is in bits. We store it in bytes. */ |
252b5132 RH |
1221 | if (size <= 0) |
1222 | size = -1; | |
1223 | break; | |
1224 | ||
1225 | case 'S': | |
b34976b6 | 1226 | stringp = TRUE; |
252b5132 RH |
1227 | break; |
1228 | ||
1229 | default: | |
1230 | /* Ignore unrecognized type attributes, so future | |
1231 | compilers can invent new ones. */ | |
1232 | break; | |
1233 | } | |
1234 | } | |
1235 | } | |
1236 | ||
1237 | descriptor = **pp; | |
1238 | ++*pp; | |
1239 | ||
1240 | switch (descriptor) | |
1241 | { | |
1242 | case 'x': | |
1243 | { | |
1244 | enum debug_type_kind code; | |
1245 | const char *q1, *q2, *p; | |
1246 | ||
1247 | /* A cross reference to another type. */ | |
252b5132 RH |
1248 | switch (**pp) |
1249 | { | |
1250 | case 's': | |
1251 | code = DEBUG_KIND_STRUCT; | |
1252 | break; | |
1253 | case 'u': | |
1254 | code = DEBUG_KIND_UNION; | |
1255 | break; | |
1256 | case 'e': | |
1257 | code = DEBUG_KIND_ENUM; | |
1258 | break; | |
1259 | default: | |
1260 | /* Complain and keep going, so compilers can invent new | |
1261 | cross-reference types. */ | |
1262 | warn_stab (orig, _("unrecognized cross reference type")); | |
1263 | code = DEBUG_KIND_STRUCT; | |
1264 | break; | |
1265 | } | |
1266 | ++*pp; | |
1267 | ||
1268 | q1 = strchr (*pp, '<'); | |
1269 | p = strchr (*pp, ':'); | |
1270 | if (p == NULL) | |
1271 | { | |
1272 | bad_stab (orig); | |
1273 | return DEBUG_TYPE_NULL; | |
1274 | } | |
c602a165 | 1275 | if (q1 != NULL && p > q1 && p[1] == ':') |
252b5132 | 1276 | { |
c602a165 ILT |
1277 | int nest = 0; |
1278 | ||
1279 | for (q2 = q1; *q2 != '\0'; ++q2) | |
1280 | { | |
1281 | if (*q2 == '<') | |
1282 | ++nest; | |
1283 | else if (*q2 == '>') | |
1284 | --nest; | |
1285 | else if (*q2 == ':' && nest == 0) | |
1286 | break; | |
1287 | } | |
1288 | p = q2; | |
1289 | if (*p != ':') | |
252b5132 RH |
1290 | { |
1291 | bad_stab (orig); | |
1292 | return DEBUG_TYPE_NULL; | |
1293 | } | |
1294 | } | |
1295 | ||
1296 | /* Some versions of g++ can emit stabs like | |
1297 | fleep:T20=xsfleep: | |
1298 | which define structures in terms of themselves. We need to | |
1299 | tell the caller to avoid building a circular structure. */ | |
3f5e193b NC |
1300 | if (type_name != NULL |
1301 | && strncmp (type_name, *pp, p - *pp) == 0 | |
1302 | && type_name[p - *pp] == '\0') | |
b34976b6 | 1303 | info->self_crossref = TRUE; |
252b5132 RH |
1304 | |
1305 | dtype = stab_find_tagged_type (dhandle, info, *pp, p - *pp, code); | |
1306 | ||
1307 | *pp = p + 1; | |
1308 | } | |
1309 | break; | |
1310 | ||
1311 | case '-': | |
1312 | case '0': | |
1313 | case '1': | |
1314 | case '2': | |
1315 | case '3': | |
1316 | case '4': | |
1317 | case '5': | |
1318 | case '6': | |
1319 | case '7': | |
1320 | case '8': | |
1321 | case '9': | |
1322 | case '(': | |
1323 | { | |
1324 | const char *hold; | |
1325 | int xtypenums[2]; | |
1326 | ||
1327 | /* This type is defined as another type. */ | |
252b5132 RH |
1328 | (*pp)--; |
1329 | hold = *pp; | |
1330 | ||
1331 | /* Peek ahead at the number to detect void. */ | |
1332 | if (! parse_stab_type_number (pp, xtypenums)) | |
1333 | return DEBUG_TYPE_NULL; | |
1334 | ||
1335 | if (typenums[0] == xtypenums[0] && typenums[1] == xtypenums[1]) | |
1336 | { | |
1337 | /* This type is being defined as itself, which means that | |
1338 | it is void. */ | |
1339 | dtype = debug_make_void_type (dhandle); | |
1340 | } | |
1341 | else | |
1342 | { | |
1343 | *pp = hold; | |
1344 | ||
1345 | /* Go back to the number and have parse_stab_type get it. | |
1346 | This means that we can deal with something like | |
1347 | t(1,2)=(3,4)=... which the Lucid compiler uses. */ | |
1348 | dtype = parse_stab_type (dhandle, info, (const char *) NULL, | |
1349 | pp, (debug_type **) NULL); | |
1350 | if (dtype == DEBUG_TYPE_NULL) | |
1351 | return DEBUG_TYPE_NULL; | |
1352 | } | |
1353 | ||
1354 | if (typenums[0] != -1) | |
1355 | { | |
1356 | if (! stab_record_type (dhandle, info, typenums, dtype)) | |
1357 | return DEBUG_TYPE_NULL; | |
1358 | } | |
1359 | ||
1360 | break; | |
1361 | } | |
1362 | ||
1363 | case '*': | |
1364 | dtype = debug_make_pointer_type (dhandle, | |
1365 | parse_stab_type (dhandle, info, | |
1366 | (const char *) NULL, | |
1367 | pp, | |
1368 | (debug_type **) NULL)); | |
1369 | break; | |
1370 | ||
1371 | case '&': | |
1372 | /* Reference to another type. */ | |
1373 | dtype = (debug_make_reference_type | |
1374 | (dhandle, | |
1375 | parse_stab_type (dhandle, info, (const char *) NULL, pp, | |
1376 | (debug_type **) NULL))); | |
1377 | break; | |
1378 | ||
1379 | case 'f': | |
1380 | /* Function returning another type. */ | |
1381 | /* FIXME: gdb checks os9k_stabs here. */ | |
1382 | dtype = (debug_make_function_type | |
1383 | (dhandle, | |
1384 | parse_stab_type (dhandle, info, (const char *) NULL, pp, | |
1385 | (debug_type **) NULL), | |
b34976b6 | 1386 | (debug_type *) NULL, FALSE)); |
252b5132 RH |
1387 | break; |
1388 | ||
1389 | case 'k': | |
1390 | /* Const qualifier on some type (Sun). */ | |
1391 | /* FIXME: gdb accepts 'c' here if os9k_stabs. */ | |
1392 | dtype = debug_make_const_type (dhandle, | |
1393 | parse_stab_type (dhandle, info, | |
1394 | (const char *) NULL, | |
1395 | pp, | |
1396 | (debug_type **) NULL)); | |
1397 | break; | |
1398 | ||
1399 | case 'B': | |
1400 | /* Volatile qual on some type (Sun). */ | |
1401 | /* FIXME: gdb accepts 'i' here if os9k_stabs. */ | |
1402 | dtype = (debug_make_volatile_type | |
1403 | (dhandle, | |
1404 | parse_stab_type (dhandle, info, (const char *) NULL, pp, | |
1405 | (debug_type **) NULL))); | |
1406 | break; | |
1407 | ||
1408 | case '@': | |
1409 | /* Offset (class & variable) type. This is used for a pointer | |
1410 | relative to an object. */ | |
1411 | { | |
1412 | debug_type domain; | |
1413 | debug_type memtype; | |
1414 | ||
1415 | /* Member type. */ | |
1416 | ||
1417 | domain = parse_stab_type (dhandle, info, (const char *) NULL, pp, | |
1418 | (debug_type **) NULL); | |
1419 | if (domain == DEBUG_TYPE_NULL) | |
1420 | return DEBUG_TYPE_NULL; | |
1421 | ||
1422 | if (**pp != ',') | |
1423 | { | |
1424 | bad_stab (orig); | |
1425 | return DEBUG_TYPE_NULL; | |
1426 | } | |
1427 | ++*pp; | |
1428 | ||
1429 | memtype = parse_stab_type (dhandle, info, (const char *) NULL, pp, | |
1430 | (debug_type **) NULL); | |
1431 | if (memtype == DEBUG_TYPE_NULL) | |
1432 | return DEBUG_TYPE_NULL; | |
1433 | ||
1434 | dtype = debug_make_offset_type (dhandle, domain, memtype); | |
1435 | } | |
1436 | break; | |
1437 | ||
1438 | case '#': | |
1439 | /* Method (class & fn) type. */ | |
1440 | if (**pp == '#') | |
1441 | { | |
1442 | debug_type return_type; | |
1443 | ||
1444 | ++*pp; | |
1445 | return_type = parse_stab_type (dhandle, info, (const char *) NULL, | |
1446 | pp, (debug_type **) NULL); | |
1447 | if (return_type == DEBUG_TYPE_NULL) | |
1448 | return DEBUG_TYPE_NULL; | |
1449 | if (**pp != ';') | |
1450 | { | |
1451 | bad_stab (orig); | |
1452 | return DEBUG_TYPE_NULL; | |
1453 | } | |
1454 | ++*pp; | |
1455 | dtype = debug_make_method_type (dhandle, return_type, | |
1456 | DEBUG_TYPE_NULL, | |
b34976b6 | 1457 | (debug_type *) NULL, FALSE); |
252b5132 RH |
1458 | } |
1459 | else | |
1460 | { | |
1461 | debug_type domain; | |
1462 | debug_type return_type; | |
1463 | debug_type *args; | |
1464 | unsigned int n; | |
1465 | unsigned int alloc; | |
b34976b6 | 1466 | bfd_boolean varargs; |
252b5132 RH |
1467 | |
1468 | domain = parse_stab_type (dhandle, info, (const char *) NULL, | |
1469 | pp, (debug_type **) NULL); | |
1470 | if (domain == DEBUG_TYPE_NULL) | |
1471 | return DEBUG_TYPE_NULL; | |
1472 | ||
1473 | if (**pp != ',') | |
1474 | { | |
1475 | bad_stab (orig); | |
1476 | return DEBUG_TYPE_NULL; | |
1477 | } | |
1478 | ++*pp; | |
1479 | ||
1480 | return_type = parse_stab_type (dhandle, info, (const char *) NULL, | |
1481 | pp, (debug_type **) NULL); | |
1482 | if (return_type == DEBUG_TYPE_NULL) | |
1483 | return DEBUG_TYPE_NULL; | |
1484 | ||
1485 | alloc = 10; | |
1486 | args = (debug_type *) xmalloc (alloc * sizeof *args); | |
1487 | n = 0; | |
1488 | while (**pp != ';') | |
1489 | { | |
1490 | if (**pp != ',') | |
1491 | { | |
1492 | bad_stab (orig); | |
1493 | return DEBUG_TYPE_NULL; | |
1494 | } | |
1495 | ++*pp; | |
1496 | ||
1497 | if (n + 1 >= alloc) | |
1498 | { | |
1499 | alloc += 10; | |
1500 | args = ((debug_type *) | |
2da42df6 | 1501 | xrealloc (args, alloc * sizeof *args)); |
252b5132 RH |
1502 | } |
1503 | ||
1504 | args[n] = parse_stab_type (dhandle, info, (const char *) NULL, | |
1505 | pp, (debug_type **) NULL); | |
1506 | if (args[n] == DEBUG_TYPE_NULL) | |
1507 | return DEBUG_TYPE_NULL; | |
1508 | ++n; | |
1509 | } | |
1510 | ++*pp; | |
1511 | ||
1512 | /* If the last type is not void, then this function takes a | |
1513 | variable number of arguments. Otherwise, we must strip | |
1514 | the void type. */ | |
1515 | if (n == 0 | |
1516 | || debug_get_type_kind (dhandle, args[n - 1]) != DEBUG_KIND_VOID) | |
b34976b6 | 1517 | varargs = TRUE; |
252b5132 RH |
1518 | else |
1519 | { | |
1520 | --n; | |
b34976b6 | 1521 | varargs = FALSE; |
252b5132 RH |
1522 | } |
1523 | ||
1524 | args[n] = DEBUG_TYPE_NULL; | |
1525 | ||
1526 | dtype = debug_make_method_type (dhandle, return_type, domain, args, | |
1527 | varargs); | |
1528 | } | |
1529 | break; | |
1530 | ||
1531 | case 'r': | |
1532 | /* Range type. */ | |
3f5e193b | 1533 | dtype = parse_stab_range_type (dhandle, info, type_name, pp, typenums); |
252b5132 RH |
1534 | break; |
1535 | ||
1536 | case 'b': | |
1537 | /* FIXME: gdb checks os9k_stabs here. */ | |
1538 | /* Sun ACC builtin int type. */ | |
1539 | dtype = parse_stab_sun_builtin_type (dhandle, pp); | |
1540 | break; | |
1541 | ||
1542 | case 'R': | |
1543 | /* Sun ACC builtin float type. */ | |
1544 | dtype = parse_stab_sun_floating_type (dhandle, pp); | |
1545 | break; | |
1546 | ||
1547 | case 'e': | |
1548 | /* Enumeration type. */ | |
1549 | dtype = parse_stab_enum_type (dhandle, pp); | |
1550 | break; | |
1551 | ||
1552 | case 's': | |
1553 | case 'u': | |
1554 | /* Struct or union type. */ | |
3f5e193b | 1555 | dtype = parse_stab_struct_type (dhandle, info, type_name, pp, |
252b5132 RH |
1556 | descriptor == 's', typenums); |
1557 | break; | |
1558 | ||
1559 | case 'a': | |
1560 | /* Array type. */ | |
1561 | if (**pp != 'r') | |
1562 | { | |
1563 | bad_stab (orig); | |
1564 | return DEBUG_TYPE_NULL; | |
1565 | } | |
1566 | ++*pp; | |
1567 | ||
1568 | dtype = parse_stab_array_type (dhandle, info, pp, stringp); | |
1569 | break; | |
1570 | ||
1571 | case 'S': | |
1572 | dtype = debug_make_set_type (dhandle, | |
1573 | parse_stab_type (dhandle, info, | |
1574 | (const char *) NULL, | |
1575 | pp, | |
1576 | (debug_type **) NULL), | |
1577 | stringp); | |
1578 | break; | |
1579 | ||
1580 | default: | |
1581 | bad_stab (orig); | |
1582 | return DEBUG_TYPE_NULL; | |
1583 | } | |
1584 | ||
1585 | if (dtype == DEBUG_TYPE_NULL) | |
1586 | return DEBUG_TYPE_NULL; | |
1587 | ||
1588 | if (typenums[0] != -1) | |
1589 | { | |
1590 | if (! stab_record_type (dhandle, info, typenums, dtype)) | |
1591 | return DEBUG_TYPE_NULL; | |
1592 | } | |
1593 | ||
1594 | if (size != -1) | |
1595 | { | |
1596 | if (! debug_record_type_size (dhandle, dtype, (unsigned int) size)) | |
3dceb55b | 1597 | return DEBUG_TYPE_NULL; |
252b5132 RH |
1598 | } |
1599 | ||
1600 | return dtype; | |
1601 | } | |
1602 | ||
1603 | /* Read a number by which a type is referred to in dbx data, or | |
1604 | perhaps read a pair (FILENUM, TYPENUM) in parentheses. Just a | |
1605 | single number N is equivalent to (0,N). Return the two numbers by | |
1606 | storing them in the vector TYPENUMS. */ | |
1607 | ||
b34976b6 | 1608 | static bfd_boolean |
2da42df6 | 1609 | parse_stab_type_number (const char **pp, int *typenums) |
252b5132 RH |
1610 | { |
1611 | const char *orig; | |
1612 | ||
1613 | orig = *pp; | |
1614 | ||
1615 | if (**pp != '(') | |
1616 | { | |
1617 | typenums[0] = 0; | |
b34976b6 | 1618 | typenums[1] = (int) parse_number (pp, (bfd_boolean *) NULL); |
252b5132 RH |
1619 | } |
1620 | else | |
1621 | { | |
1622 | ++*pp; | |
b34976b6 | 1623 | typenums[0] = (int) parse_number (pp, (bfd_boolean *) NULL); |
252b5132 RH |
1624 | if (**pp != ',') |
1625 | { | |
1626 | bad_stab (orig); | |
b34976b6 | 1627 | return FALSE; |
252b5132 RH |
1628 | } |
1629 | ++*pp; | |
b34976b6 | 1630 | typenums[1] = (int) parse_number (pp, (bfd_boolean *) NULL); |
252b5132 RH |
1631 | if (**pp != ')') |
1632 | { | |
1633 | bad_stab (orig); | |
b34976b6 | 1634 | return FALSE; |
252b5132 RH |
1635 | } |
1636 | ++*pp; | |
1637 | } | |
1638 | ||
b34976b6 | 1639 | return TRUE; |
252b5132 RH |
1640 | } |
1641 | ||
1642 | /* Parse a range type. */ | |
1643 | ||
1644 | static debug_type | |
3f5e193b | 1645 | parse_stab_range_type (void *dhandle, struct stab_handle *info, const char *type_name, const char **pp, const int *typenums) |
252b5132 RH |
1646 | { |
1647 | const char *orig; | |
1648 | int rangenums[2]; | |
b34976b6 | 1649 | bfd_boolean self_subrange; |
252b5132 RH |
1650 | debug_type index_type; |
1651 | const char *s2, *s3; | |
1652 | bfd_signed_vma n2, n3; | |
b34976b6 | 1653 | bfd_boolean ov2, ov3; |
252b5132 RH |
1654 | |
1655 | orig = *pp; | |
1656 | ||
1657 | index_type = DEBUG_TYPE_NULL; | |
1658 | ||
1659 | /* First comes a type we are a subrange of. | |
1660 | In C it is usually 0, 1 or the type being defined. */ | |
1661 | if (! parse_stab_type_number (pp, rangenums)) | |
1662 | return DEBUG_TYPE_NULL; | |
1663 | ||
1664 | self_subrange = (rangenums[0] == typenums[0] | |
1665 | && rangenums[1] == typenums[1]); | |
1666 | ||
1667 | if (**pp == '=') | |
1668 | { | |
1669 | *pp = orig; | |
1670 | index_type = parse_stab_type (dhandle, info, (const char *) NULL, | |
1671 | pp, (debug_type **) NULL); | |
1672 | if (index_type == DEBUG_TYPE_NULL) | |
1673 | return DEBUG_TYPE_NULL; | |
1674 | } | |
1675 | ||
1676 | if (**pp == ';') | |
1677 | ++*pp; | |
1678 | ||
1679 | /* The remaining two operands are usually lower and upper bounds of | |
1680 | the range. But in some special cases they mean something else. */ | |
1681 | s2 = *pp; | |
1682 | n2 = parse_number (pp, &ov2); | |
1683 | if (**pp != ';') | |
1684 | { | |
1685 | bad_stab (orig); | |
1686 | return DEBUG_TYPE_NULL; | |
1687 | } | |
1688 | ++*pp; | |
1689 | ||
1690 | s3 = *pp; | |
1691 | n3 = parse_number (pp, &ov3); | |
1692 | if (**pp != ';') | |
1693 | { | |
1694 | bad_stab (orig); | |
1695 | return DEBUG_TYPE_NULL; | |
1696 | } | |
1697 | ++*pp; | |
1698 | ||
1699 | if (ov2 || ov3) | |
1700 | { | |
1701 | /* gcc will emit range stabs for long long types. Handle this | |
1702 | as a special case. FIXME: This needs to be more general. */ | |
7eb5191a NC |
1703 | #define LLLOW "01000000000000000000000;" |
1704 | #define LLHIGH "0777777777777777777777;" | |
252b5132 RH |
1705 | #define ULLHIGH "01777777777777777777777;" |
1706 | if (index_type == DEBUG_TYPE_NULL) | |
1707 | { | |
0112cd26 NC |
1708 | if (CONST_STRNEQ (s2, LLLOW) |
1709 | && CONST_STRNEQ (s3, LLHIGH)) | |
b34976b6 | 1710 | return debug_make_int_type (dhandle, 8, FALSE); |
252b5132 RH |
1711 | if (! ov2 |
1712 | && n2 == 0 | |
0112cd26 | 1713 | && CONST_STRNEQ (s3, ULLHIGH)) |
b34976b6 | 1714 | return debug_make_int_type (dhandle, 8, TRUE); |
252b5132 RH |
1715 | } |
1716 | ||
1717 | warn_stab (orig, _("numeric overflow")); | |
1718 | } | |
1719 | ||
1720 | if (index_type == DEBUG_TYPE_NULL) | |
1721 | { | |
1722 | /* A type defined as a subrange of itself, with both bounds 0, | |
1723 | is void. */ | |
1724 | if (self_subrange && n2 == 0 && n3 == 0) | |
1725 | return debug_make_void_type (dhandle); | |
1726 | ||
1727 | /* A type defined as a subrange of itself, with n2 positive and | |
1728 | n3 zero, is a complex type, and n2 is the number of bytes. */ | |
1729 | if (self_subrange && n3 == 0 && n2 > 0) | |
1730 | return debug_make_complex_type (dhandle, n2); | |
1731 | ||
1732 | /* If n3 is zero and n2 is positive, this is a floating point | |
1733 | type, and n2 is the number of bytes. */ | |
1734 | if (n3 == 0 && n2 > 0) | |
1735 | return debug_make_float_type (dhandle, n2); | |
1736 | ||
1737 | /* If the upper bound is -1, this is an unsigned int. */ | |
1738 | if (n2 == 0 && n3 == -1) | |
1739 | { | |
1740 | /* When gcc is used with -gstabs, but not -gstabs+, it will emit | |
1741 | long long int:t6=r1;0;-1; | |
1742 | long long unsigned int:t7=r1;0;-1; | |
1743 | We hack here to handle this reasonably. */ | |
3f5e193b | 1744 | if (type_name != NULL) |
252b5132 | 1745 | { |
3f5e193b | 1746 | if (strcmp (type_name, "long long int") == 0) |
b34976b6 | 1747 | return debug_make_int_type (dhandle, 8, FALSE); |
3f5e193b | 1748 | else if (strcmp (type_name, "long long unsigned int") == 0) |
b34976b6 | 1749 | return debug_make_int_type (dhandle, 8, TRUE); |
252b5132 RH |
1750 | } |
1751 | /* FIXME: The size here really depends upon the target. */ | |
b34976b6 | 1752 | return debug_make_int_type (dhandle, 4, TRUE); |
252b5132 RH |
1753 | } |
1754 | ||
1755 | /* A range of 0 to 127 is char. */ | |
1756 | if (self_subrange && n2 == 0 && n3 == 127) | |
b34976b6 | 1757 | return debug_make_int_type (dhandle, 1, FALSE); |
252b5132 RH |
1758 | |
1759 | /* FIXME: gdb checks for the language CHILL here. */ | |
1760 | ||
1761 | if (n2 == 0) | |
1762 | { | |
1763 | if (n3 < 0) | |
b34976b6 | 1764 | return debug_make_int_type (dhandle, - n3, TRUE); |
252b5132 | 1765 | else if (n3 == 0xff) |
b34976b6 | 1766 | return debug_make_int_type (dhandle, 1, TRUE); |
252b5132 | 1767 | else if (n3 == 0xffff) |
b34976b6 | 1768 | return debug_make_int_type (dhandle, 2, TRUE); |
b4c96d0d | 1769 | else if (n3 == (bfd_signed_vma) 0xffffffff) |
b34976b6 | 1770 | return debug_make_int_type (dhandle, 4, TRUE); |
252b5132 | 1771 | #ifdef BFD64 |
3c9f43b1 | 1772 | else if (n3 == ((((bfd_signed_vma) 0xffffffff) << 32) | 0xffffffff)) |
b34976b6 | 1773 | return debug_make_int_type (dhandle, 8, TRUE); |
252b5132 RH |
1774 | #endif |
1775 | } | |
1776 | else if (n3 == 0 | |
1777 | && n2 < 0 | |
1778 | && (self_subrange || n2 == -8)) | |
b34976b6 | 1779 | return debug_make_int_type (dhandle, - n2, TRUE); |
252b5132 RH |
1780 | else if (n2 == - n3 - 1 || n2 == n3 + 1) |
1781 | { | |
1782 | if (n3 == 0x7f) | |
b34976b6 | 1783 | return debug_make_int_type (dhandle, 1, FALSE); |
252b5132 | 1784 | else if (n3 == 0x7fff) |
b34976b6 | 1785 | return debug_make_int_type (dhandle, 2, FALSE); |
252b5132 | 1786 | else if (n3 == 0x7fffffff) |
b34976b6 | 1787 | return debug_make_int_type (dhandle, 4, FALSE); |
252b5132 RH |
1788 | #ifdef BFD64 |
1789 | else if (n3 == ((((bfd_vma) 0x7fffffff) << 32) | 0xffffffff)) | |
b34976b6 | 1790 | return debug_make_int_type (dhandle, 8, FALSE); |
252b5132 RH |
1791 | #endif |
1792 | } | |
1793 | } | |
1794 | ||
1795 | /* At this point I don't have the faintest idea how to deal with a | |
1796 | self_subrange type; I'm going to assume that this is used as an | |
1797 | idiom, and that all of them are special cases. So . . . */ | |
1798 | if (self_subrange) | |
1799 | { | |
1800 | bad_stab (orig); | |
1801 | return DEBUG_TYPE_NULL; | |
1802 | } | |
1803 | ||
1804 | index_type = stab_find_type (dhandle, info, rangenums); | |
1805 | if (index_type == DEBUG_TYPE_NULL) | |
1806 | { | |
1807 | /* Does this actually ever happen? Is that why we are worrying | |
1808 | about dealing with it rather than just calling error_type? */ | |
1809 | warn_stab (orig, _("missing index type")); | |
b34976b6 | 1810 | index_type = debug_make_int_type (dhandle, 4, FALSE); |
252b5132 RH |
1811 | } |
1812 | ||
1813 | return debug_make_range_type (dhandle, index_type, n2, n3); | |
1814 | } | |
1815 | ||
1816 | /* Sun's ACC uses a somewhat saner method for specifying the builtin | |
1817 | typedefs in every file (for int, long, etc): | |
1818 | ||
1819 | type = b <signed> <width>; <offset>; <nbits> | |
1820 | signed = u or s. Possible c in addition to u or s (for char?). | |
1821 | offset = offset from high order bit to start bit of type. | |
1822 | width is # bytes in object of this type, nbits is # bits in type. | |
1823 | ||
1824 | The width/offset stuff appears to be for small objects stored in | |
1825 | larger ones (e.g. `shorts' in `int' registers). We ignore it for now, | |
1826 | FIXME. */ | |
1827 | ||
1828 | static debug_type | |
2da42df6 | 1829 | parse_stab_sun_builtin_type (void *dhandle, const char **pp) |
252b5132 RH |
1830 | { |
1831 | const char *orig; | |
b34976b6 | 1832 | bfd_boolean unsignedp; |
252b5132 RH |
1833 | bfd_vma bits; |
1834 | ||
1835 | orig = *pp; | |
1836 | ||
1837 | switch (**pp) | |
1838 | { | |
1839 | case 's': | |
b34976b6 | 1840 | unsignedp = FALSE; |
252b5132 RH |
1841 | break; |
1842 | case 'u': | |
b34976b6 | 1843 | unsignedp = TRUE; |
252b5132 RH |
1844 | break; |
1845 | default: | |
1846 | bad_stab (orig); | |
1847 | return DEBUG_TYPE_NULL; | |
1848 | } | |
1849 | ++*pp; | |
1850 | ||
42b722c1 NC |
1851 | /* OpenSolaris source code indicates that one of "cbv" characters |
1852 | can come next and specify the intrinsic 'iformat' encoding. | |
1853 | 'c' is character encoding, 'b' is boolean encoding, and 'v' is | |
1854 | varargs encoding. This field can be safely ignored because | |
1855 | the type of the field is determined from the bitwidth extracted | |
1856 | below. */ | |
1857 | if (**pp == 'c' || **pp == 'b' || **pp == 'v') | |
252b5132 RH |
1858 | ++*pp; |
1859 | ||
1860 | /* The first number appears to be the number of bytes occupied | |
1861 | by this type, except that unsigned short is 4 instead of 2. | |
1862 | Since this information is redundant with the third number, | |
1863 | we will ignore it. */ | |
b34976b6 | 1864 | (void) parse_number (pp, (bfd_boolean *) NULL); |
252b5132 RH |
1865 | if (**pp != ';') |
1866 | { | |
1867 | bad_stab (orig); | |
1868 | return DEBUG_TYPE_NULL; | |
1869 | } | |
1870 | ++*pp; | |
1871 | ||
9f66665a | 1872 | /* The second number is always 0, so ignore it too. */ |
b34976b6 | 1873 | (void) parse_number (pp, (bfd_boolean *) NULL); |
252b5132 RH |
1874 | if (**pp != ';') |
1875 | { | |
1876 | bad_stab (orig); | |
1877 | return DEBUG_TYPE_NULL; | |
1878 | } | |
1879 | ++*pp; | |
1880 | ||
9f66665a | 1881 | /* The third number is the number of bits for this type. */ |
b34976b6 | 1882 | bits = parse_number (pp, (bfd_boolean *) NULL); |
252b5132 RH |
1883 | |
1884 | /* The type *should* end with a semicolon. If it are embedded | |
1885 | in a larger type the semicolon may be the only way to know where | |
1886 | the type ends. If this type is at the end of the stabstring we | |
1887 | can deal with the omitted semicolon (but we don't have to like | |
1888 | it). Don't bother to complain(), Sun's compiler omits the semicolon | |
1889 | for "void". */ | |
1890 | if (**pp == ';') | |
1891 | ++*pp; | |
1892 | ||
1893 | if (bits == 0) | |
1894 | return debug_make_void_type (dhandle); | |
1895 | ||
1896 | return debug_make_int_type (dhandle, bits / 8, unsignedp); | |
1897 | } | |
1898 | ||
1899 | /* Parse a builtin floating type generated by the Sun compiler. */ | |
1900 | ||
1901 | static debug_type | |
2da42df6 | 1902 | parse_stab_sun_floating_type (void *dhandle, const char **pp) |
252b5132 RH |
1903 | { |
1904 | const char *orig; | |
1905 | bfd_vma details; | |
1906 | bfd_vma bytes; | |
1907 | ||
1908 | orig = *pp; | |
1909 | ||
1910 | /* The first number has more details about the type, for example | |
1911 | FN_COMPLEX. */ | |
b34976b6 | 1912 | details = parse_number (pp, (bfd_boolean *) NULL); |
252b5132 RH |
1913 | if (**pp != ';') |
1914 | { | |
1915 | bad_stab (orig); | |
1916 | return DEBUG_TYPE_NULL; | |
1917 | } | |
1918 | ||
1919 | /* The second number is the number of bytes occupied by this type */ | |
b34976b6 | 1920 | bytes = parse_number (pp, (bfd_boolean *) NULL); |
252b5132 RH |
1921 | if (**pp != ';') |
1922 | { | |
1923 | bad_stab (orig); | |
1924 | return DEBUG_TYPE_NULL; | |
1925 | } | |
1926 | ||
1927 | if (details == NF_COMPLEX | |
1928 | || details == NF_COMPLEX16 | |
1929 | || details == NF_COMPLEX32) | |
1930 | return debug_make_complex_type (dhandle, bytes); | |
1931 | ||
9f66665a | 1932 | return debug_make_float_type (dhandle, bytes); |
252b5132 RH |
1933 | } |
1934 | ||
1935 | /* Handle an enum type. */ | |
1936 | ||
1937 | static debug_type | |
2da42df6 | 1938 | parse_stab_enum_type (void *dhandle, const char **pp) |
252b5132 RH |
1939 | { |
1940 | const char *orig; | |
1941 | const char **names; | |
1942 | bfd_signed_vma *values; | |
1943 | unsigned int n; | |
1944 | unsigned int alloc; | |
1945 | ||
1946 | orig = *pp; | |
1947 | ||
1948 | /* FIXME: gdb checks os9k_stabs here. */ | |
1949 | ||
1950 | /* The aix4 compiler emits an extra field before the enum members; | |
1951 | my guess is it's a type of some sort. Just ignore it. */ | |
1952 | if (**pp == '-') | |
1953 | { | |
1954 | while (**pp != ':') | |
1955 | ++*pp; | |
1956 | ++*pp; | |
1957 | } | |
1958 | ||
1959 | /* Read the value-names and their values. | |
1960 | The input syntax is NAME:VALUE,NAME:VALUE, and so on. | |
1961 | A semicolon or comma instead of a NAME means the end. */ | |
1962 | alloc = 10; | |
1963 | names = (const char **) xmalloc (alloc * sizeof *names); | |
1964 | values = (bfd_signed_vma *) xmalloc (alloc * sizeof *values); | |
1965 | n = 0; | |
1966 | while (**pp != '\0' && **pp != ';' && **pp != ',') | |
1967 | { | |
1968 | const char *p; | |
1969 | char *name; | |
1970 | bfd_signed_vma val; | |
1971 | ||
1972 | p = *pp; | |
1973 | while (*p != ':') | |
1974 | ++p; | |
1975 | ||
1976 | name = savestring (*pp, p - *pp); | |
1977 | ||
1978 | *pp = p + 1; | |
b34976b6 | 1979 | val = (bfd_signed_vma) parse_number (pp, (bfd_boolean *) NULL); |
252b5132 RH |
1980 | if (**pp != ',') |
1981 | { | |
1982 | bad_stab (orig); | |
1983 | return DEBUG_TYPE_NULL; | |
1984 | } | |
1985 | ++*pp; | |
1986 | ||
1987 | if (n + 1 >= alloc) | |
1988 | { | |
1989 | alloc += 10; | |
1990 | names = ((const char **) | |
2da42df6 | 1991 | xrealloc (names, alloc * sizeof *names)); |
252b5132 | 1992 | values = ((bfd_signed_vma *) |
2da42df6 | 1993 | xrealloc (values, alloc * sizeof *values)); |
252b5132 RH |
1994 | } |
1995 | ||
1996 | names[n] = name; | |
1997 | values[n] = val; | |
1998 | ++n; | |
1999 | } | |
2000 | ||
2001 | names[n] = NULL; | |
2002 | values[n] = 0; | |
2003 | ||
2004 | if (**pp == ';') | |
2005 | ++*pp; | |
2006 | ||
2007 | return debug_make_enum_type (dhandle, names, values); | |
2008 | } | |
2009 | ||
2010 | /* Read the description of a structure (or union type) and return an object | |
2011 | describing the type. | |
2012 | ||
2013 | PP points to a character pointer that points to the next unconsumed token | |
1be59579 | 2014 | in the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;", |
252b5132 RH |
2015 | *PP will point to "4a:1,0,32;;". */ |
2016 | ||
2017 | static debug_type | |
2da42df6 AJ |
2018 | parse_stab_struct_type (void *dhandle, struct stab_handle *info, |
2019 | const char *tagname, const char **pp, | |
2020 | bfd_boolean structp, const int *typenums) | |
252b5132 | 2021 | { |
252b5132 RH |
2022 | bfd_vma size; |
2023 | debug_baseclass *baseclasses; | |
2024 | debug_field *fields; | |
b34976b6 | 2025 | bfd_boolean statics; |
252b5132 RH |
2026 | debug_method *methods; |
2027 | debug_type vptrbase; | |
b34976b6 | 2028 | bfd_boolean ownvptr; |
252b5132 | 2029 | |
252b5132 | 2030 | /* Get the size. */ |
b34976b6 | 2031 | size = parse_number (pp, (bfd_boolean *) NULL); |
252b5132 RH |
2032 | |
2033 | /* Get the other information. */ | |
2034 | if (! parse_stab_baseclasses (dhandle, info, pp, &baseclasses) | |
2035 | || ! parse_stab_struct_fields (dhandle, info, pp, &fields, &statics) | |
2036 | || ! parse_stab_members (dhandle, info, tagname, pp, typenums, &methods) | |
2037 | || ! parse_stab_tilde_field (dhandle, info, pp, typenums, &vptrbase, | |
2038 | &ownvptr)) | |
2039 | return DEBUG_TYPE_NULL; | |
2040 | ||
2041 | if (! statics | |
2042 | && baseclasses == NULL | |
2043 | && methods == NULL | |
2044 | && vptrbase == DEBUG_TYPE_NULL | |
2045 | && ! ownvptr) | |
2046 | return debug_make_struct_type (dhandle, structp, size, fields); | |
2047 | ||
2048 | return debug_make_object_type (dhandle, structp, size, fields, baseclasses, | |
2049 | methods, vptrbase, ownvptr); | |
2050 | } | |
2051 | ||
2052 | /* The stabs for C++ derived classes contain baseclass information which | |
2053 | is marked by a '!' character after the total size. This function is | |
2054 | called when we encounter the baseclass marker, and slurps up all the | |
2055 | baseclass information. | |
2056 | ||
2057 | Immediately following the '!' marker is the number of base classes that | |
2058 | the class is derived from, followed by information for each base class. | |
2059 | For each base class, there are two visibility specifiers, a bit offset | |
2060 | to the base class information within the derived class, a reference to | |
2061 | the type for the base class, and a terminating semicolon. | |
2062 | ||
2063 | A typical example, with two base classes, would be "!2,020,19;0264,21;". | |
2da42df6 | 2064 | ^^ ^ ^ ^ ^ ^ ^ |
252b5132 RH |
2065 | Baseclass information marker __________________|| | | | | | | |
2066 | Number of baseclasses __________________________| | | | | | | | |
2067 | Visibility specifiers (2) ________________________| | | | | | | |
2068 | Offset in bits from start of class _________________| | | | | | |
2069 | Type number for base class ___________________________| | | | | |
2070 | Visibility specifiers (2) _______________________________| | | | |
2071 | Offset in bits from start of class ________________________| | | |
2072 | Type number of base class ____________________________________| | |
2073 | ||
b34976b6 | 2074 | Return TRUE for success, FALSE for failure. */ |
252b5132 | 2075 | |
b34976b6 | 2076 | static bfd_boolean |
2da42df6 AJ |
2077 | parse_stab_baseclasses (void *dhandle, struct stab_handle *info, |
2078 | const char **pp, debug_baseclass **retp) | |
252b5132 RH |
2079 | { |
2080 | const char *orig; | |
2081 | unsigned int c, i; | |
2082 | debug_baseclass *classes; | |
2083 | ||
2084 | *retp = NULL; | |
2085 | ||
2086 | orig = *pp; | |
2087 | ||
2088 | if (**pp != '!') | |
2089 | { | |
2090 | /* No base classes. */ | |
b34976b6 | 2091 | return TRUE; |
252b5132 RH |
2092 | } |
2093 | ++*pp; | |
2094 | ||
b34976b6 | 2095 | c = (unsigned int) parse_number (pp, (bfd_boolean *) NULL); |
252b5132 RH |
2096 | |
2097 | if (**pp != ',') | |
2098 | { | |
2099 | bad_stab (orig); | |
b34976b6 | 2100 | return FALSE; |
252b5132 RH |
2101 | } |
2102 | ++*pp; | |
2103 | ||
2104 | classes = (debug_baseclass *) xmalloc ((c + 1) * sizeof (**retp)); | |
2105 | ||
2106 | for (i = 0; i < c; i++) | |
2107 | { | |
3f5e193b | 2108 | bfd_boolean is_virtual; |
252b5132 RH |
2109 | enum debug_visibility visibility; |
2110 | bfd_vma bitpos; | |
2111 | debug_type type; | |
2112 | ||
2113 | switch (**pp) | |
2114 | { | |
2115 | case '0': | |
3f5e193b | 2116 | is_virtual = FALSE; |
252b5132 RH |
2117 | break; |
2118 | case '1': | |
3f5e193b | 2119 | is_virtual = TRUE; |
252b5132 RH |
2120 | break; |
2121 | default: | |
2122 | warn_stab (orig, _("unknown virtual character for baseclass")); | |
3f5e193b | 2123 | is_virtual = FALSE; |
252b5132 RH |
2124 | break; |
2125 | } | |
2126 | ++*pp; | |
2127 | ||
2128 | switch (**pp) | |
2129 | { | |
2130 | case '0': | |
2131 | visibility = DEBUG_VISIBILITY_PRIVATE; | |
2132 | break; | |
2133 | case '1': | |
2134 | visibility = DEBUG_VISIBILITY_PROTECTED; | |
2135 | break; | |
2136 | case '2': | |
2137 | visibility = DEBUG_VISIBILITY_PUBLIC; | |
2138 | break; | |
2139 | default: | |
2140 | warn_stab (orig, _("unknown visibility character for baseclass")); | |
2141 | visibility = DEBUG_VISIBILITY_PUBLIC; | |
2142 | break; | |
2143 | } | |
2144 | ++*pp; | |
2145 | ||
2146 | /* The remaining value is the bit offset of the portion of the | |
2147 | object corresponding to this baseclass. Always zero in the | |
2148 | absence of multiple inheritance. */ | |
b34976b6 | 2149 | bitpos = parse_number (pp, (bfd_boolean *) NULL); |
252b5132 RH |
2150 | if (**pp != ',') |
2151 | { | |
2152 | bad_stab (orig); | |
b34976b6 | 2153 | return FALSE; |
252b5132 RH |
2154 | } |
2155 | ++*pp; | |
2156 | ||
2157 | type = parse_stab_type (dhandle, info, (const char *) NULL, pp, | |
2158 | (debug_type **) NULL); | |
2159 | if (type == DEBUG_TYPE_NULL) | |
b34976b6 | 2160 | return FALSE; |
252b5132 | 2161 | |
3f5e193b | 2162 | classes[i] = debug_make_baseclass (dhandle, type, bitpos, is_virtual, |
252b5132 RH |
2163 | visibility); |
2164 | if (classes[i] == DEBUG_BASECLASS_NULL) | |
b34976b6 | 2165 | return FALSE; |
252b5132 RH |
2166 | |
2167 | if (**pp != ';') | |
b34976b6 | 2168 | return FALSE; |
252b5132 RH |
2169 | ++*pp; |
2170 | } | |
2171 | ||
2172 | classes[i] = DEBUG_BASECLASS_NULL; | |
2173 | ||
2174 | *retp = classes; | |
2175 | ||
b34976b6 | 2176 | return TRUE; |
252b5132 RH |
2177 | } |
2178 | ||
2179 | /* Read struct or class data fields. They have the form: | |
2180 | ||
2da42df6 | 2181 | NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ; |
252b5132 RH |
2182 | |
2183 | At the end, we see a semicolon instead of a field. | |
2184 | ||
2185 | In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for | |
2186 | a static field. | |
2187 | ||
2188 | The optional VISIBILITY is one of: | |
2189 | ||
2da42df6 | 2190 | '/0' (VISIBILITY_PRIVATE) |
252b5132 RH |
2191 | '/1' (VISIBILITY_PROTECTED) |
2192 | '/2' (VISIBILITY_PUBLIC) | |
2193 | '/9' (VISIBILITY_IGNORE) | |
2194 | ||
2195 | or nothing, for C style fields with public visibility. | |
2196 | ||
2197 | Returns 1 for success, 0 for failure. */ | |
2198 | ||
b34976b6 | 2199 | static bfd_boolean |
2da42df6 AJ |
2200 | parse_stab_struct_fields (void *dhandle, struct stab_handle *info, |
2201 | const char **pp, debug_field **retp, | |
2202 | bfd_boolean *staticsp) | |
252b5132 RH |
2203 | { |
2204 | const char *orig; | |
2205 | const char *p; | |
2206 | debug_field *fields; | |
2207 | unsigned int c; | |
2208 | unsigned int alloc; | |
2209 | ||
2210 | *retp = NULL; | |
b34976b6 | 2211 | *staticsp = FALSE; |
252b5132 RH |
2212 | |
2213 | orig = *pp; | |
2214 | ||
2215 | c = 0; | |
2216 | alloc = 10; | |
2217 | fields = (debug_field *) xmalloc (alloc * sizeof *fields); | |
2218 | while (**pp != ';') | |
2219 | { | |
2220 | /* FIXME: gdb checks os9k_stabs here. */ | |
2221 | ||
2222 | p = *pp; | |
2223 | ||
2224 | /* Add 1 to c to leave room for NULL pointer at end. */ | |
2225 | if (c + 1 >= alloc) | |
2226 | { | |
2227 | alloc += 10; | |
2228 | fields = ((debug_field *) | |
2da42df6 | 2229 | xrealloc (fields, alloc * sizeof *fields)); |
252b5132 RH |
2230 | } |
2231 | ||
2232 | /* If it starts with CPLUS_MARKER it is a special abbreviation, | |
2233 | unless the CPLUS_MARKER is followed by an underscore, in | |
2234 | which case it is just the name of an anonymous type, which we | |
2235 | should handle like any other type name. We accept either '$' | |
2236 | or '.', because a field name can never contain one of these | |
2237 | characters except as a CPLUS_MARKER. */ | |
2238 | ||
2239 | if ((*p == '$' || *p == '.') && p[1] != '_') | |
2240 | { | |
2241 | ++*pp; | |
2242 | if (! parse_stab_cpp_abbrev (dhandle, info, pp, fields + c)) | |
b34976b6 | 2243 | return FALSE; |
252b5132 RH |
2244 | ++c; |
2245 | continue; | |
2246 | } | |
2247 | ||
2248 | /* Look for the ':' that separates the field name from the field | |
2249 | values. Data members are delimited by a single ':', while member | |
2250 | functions are delimited by a pair of ':'s. When we hit the member | |
9f66665a | 2251 | functions (if any), terminate scan loop and return. */ |
252b5132 RH |
2252 | |
2253 | p = strchr (p, ':'); | |
2254 | if (p == NULL) | |
2255 | { | |
2256 | bad_stab (orig); | |
b34976b6 | 2257 | return FALSE; |
252b5132 RH |
2258 | } |
2259 | ||
2260 | if (p[1] == ':') | |
2261 | break; | |
2262 | ||
2263 | if (! parse_stab_one_struct_field (dhandle, info, pp, p, fields + c, | |
2264 | staticsp)) | |
b34976b6 | 2265 | return FALSE; |
252b5132 RH |
2266 | |
2267 | ++c; | |
2268 | } | |
2269 | ||
2270 | fields[c] = DEBUG_FIELD_NULL; | |
2271 | ||
2272 | *retp = fields; | |
2273 | ||
b34976b6 | 2274 | return TRUE; |
252b5132 RH |
2275 | } |
2276 | ||
2277 | /* Special GNU C++ name. */ | |
2278 | ||
b34976b6 | 2279 | static bfd_boolean |
2da42df6 AJ |
2280 | parse_stab_cpp_abbrev (void *dhandle, struct stab_handle *info, |
2281 | const char **pp, debug_field *retp) | |
252b5132 RH |
2282 | { |
2283 | const char *orig; | |
2284 | int cpp_abbrev; | |
2285 | debug_type context; | |
2286 | const char *name; | |
3f5e193b | 2287 | const char *type_name; |
252b5132 RH |
2288 | debug_type type; |
2289 | bfd_vma bitpos; | |
2290 | ||
2291 | *retp = DEBUG_FIELD_NULL; | |
2292 | ||
2293 | orig = *pp; | |
2294 | ||
2295 | if (**pp != 'v') | |
2296 | { | |
2297 | bad_stab (*pp); | |
b34976b6 | 2298 | return FALSE; |
252b5132 RH |
2299 | } |
2300 | ++*pp; | |
2301 | ||
2302 | cpp_abbrev = **pp; | |
2303 | ++*pp; | |
2304 | ||
2305 | /* At this point, *pp points to something like "22:23=*22...", where | |
2306 | the type number before the ':' is the "context" and everything | |
2307 | after is a regular type definition. Lookup the type, find it's | |
2308 | name, and construct the field name. */ | |
2309 | ||
2310 | context = parse_stab_type (dhandle, info, (const char *) NULL, pp, | |
2311 | (debug_type **) NULL); | |
2312 | if (context == DEBUG_TYPE_NULL) | |
b34976b6 | 2313 | return FALSE; |
252b5132 RH |
2314 | |
2315 | switch (cpp_abbrev) | |
2316 | { | |
2317 | case 'f': | |
2318 | /* $vf -- a virtual function table pointer. */ | |
2319 | name = "_vptr$"; | |
2320 | break; | |
2321 | case 'b': | |
2322 | /* $vb -- a virtual bsomethingorother */ | |
3f5e193b NC |
2323 | type_name = debug_get_type_name (dhandle, context); |
2324 | if (type_name == NULL) | |
252b5132 RH |
2325 | { |
2326 | warn_stab (orig, _("unnamed $vb type")); | |
3f5e193b | 2327 | type_name = "FOO"; |
252b5132 | 2328 | } |
3f5e193b | 2329 | name = concat ("_vb$", type_name, (const char *) NULL); |
252b5132 RH |
2330 | break; |
2331 | default: | |
2332 | warn_stab (orig, _("unrecognized C++ abbreviation")); | |
2333 | name = "INVALID_CPLUSPLUS_ABBREV"; | |
2334 | break; | |
2335 | } | |
2336 | ||
2337 | if (**pp != ':') | |
2338 | { | |
2339 | bad_stab (orig); | |
b34976b6 | 2340 | return FALSE; |
252b5132 RH |
2341 | } |
2342 | ++*pp; | |
2343 | ||
2344 | type = parse_stab_type (dhandle, info, (const char *) NULL, pp, | |
2345 | (debug_type **) NULL); | |
2346 | if (**pp != ',') | |
2347 | { | |
2348 | bad_stab (orig); | |
b34976b6 | 2349 | return FALSE; |
252b5132 RH |
2350 | } |
2351 | ++*pp; | |
2352 | ||
b34976b6 | 2353 | bitpos = parse_number (pp, (bfd_boolean *) NULL); |
252b5132 RH |
2354 | if (**pp != ';') |
2355 | { | |
2356 | bad_stab (orig); | |
b34976b6 | 2357 | return FALSE; |
252b5132 RH |
2358 | } |
2359 | ++*pp; | |
2360 | ||
2361 | *retp = debug_make_field (dhandle, name, type, bitpos, 0, | |
2362 | DEBUG_VISIBILITY_PRIVATE); | |
2363 | if (*retp == DEBUG_FIELD_NULL) | |
b34976b6 | 2364 | return FALSE; |
252b5132 | 2365 | |
b34976b6 | 2366 | return TRUE; |
252b5132 RH |
2367 | } |
2368 | ||
2369 | /* Parse a single field in a struct or union. */ | |
2370 | ||
b34976b6 | 2371 | static bfd_boolean |
2da42df6 AJ |
2372 | parse_stab_one_struct_field (void *dhandle, struct stab_handle *info, |
2373 | const char **pp, const char *p, | |
2374 | debug_field *retp, bfd_boolean *staticsp) | |
252b5132 RH |
2375 | { |
2376 | const char *orig; | |
2377 | char *name; | |
2378 | enum debug_visibility visibility; | |
2379 | debug_type type; | |
2380 | bfd_vma bitpos; | |
2381 | bfd_vma bitsize; | |
2382 | ||
2383 | orig = *pp; | |
2384 | ||
2385 | /* FIXME: gdb checks ARM_DEMANGLING here. */ | |
2386 | ||
2387 | name = savestring (*pp, p - *pp); | |
2388 | ||
2389 | *pp = p + 1; | |
2390 | ||
2391 | if (**pp != '/') | |
2392 | visibility = DEBUG_VISIBILITY_PUBLIC; | |
2393 | else | |
2394 | { | |
2395 | ++*pp; | |
2396 | switch (**pp) | |
2397 | { | |
2398 | case '0': | |
2399 | visibility = DEBUG_VISIBILITY_PRIVATE; | |
2400 | break; | |
2401 | case '1': | |
2402 | visibility = DEBUG_VISIBILITY_PROTECTED; | |
2403 | break; | |
2404 | case '2': | |
2405 | visibility = DEBUG_VISIBILITY_PUBLIC; | |
2406 | break; | |
2407 | default: | |
2408 | warn_stab (orig, _("unknown visibility character for field")); | |
2409 | visibility = DEBUG_VISIBILITY_PUBLIC; | |
2410 | break; | |
2411 | } | |
2412 | ++*pp; | |
2413 | } | |
2414 | ||
2415 | type = parse_stab_type (dhandle, info, (const char *) NULL, pp, | |
2416 | (debug_type **) NULL); | |
2417 | if (type == DEBUG_TYPE_NULL) | |
b34976b6 | 2418 | return FALSE; |
252b5132 RH |
2419 | |
2420 | if (**pp == ':') | |
2421 | { | |
2422 | char *varname; | |
2423 | ||
2424 | /* This is a static class member. */ | |
2425 | ++*pp; | |
2426 | p = strchr (*pp, ';'); | |
2427 | if (p == NULL) | |
2428 | { | |
2429 | bad_stab (orig); | |
b34976b6 | 2430 | return FALSE; |
252b5132 RH |
2431 | } |
2432 | ||
2433 | varname = savestring (*pp, p - *pp); | |
2434 | ||
2435 | *pp = p + 1; | |
2436 | ||
2437 | *retp = debug_make_static_member (dhandle, name, type, varname, | |
2438 | visibility); | |
b34976b6 | 2439 | *staticsp = TRUE; |
252b5132 | 2440 | |
b34976b6 | 2441 | return TRUE; |
252b5132 RH |
2442 | } |
2443 | ||
2444 | if (**pp != ',') | |
2445 | { | |
2446 | bad_stab (orig); | |
b34976b6 | 2447 | return FALSE; |
252b5132 RH |
2448 | } |
2449 | ++*pp; | |
2450 | ||
b34976b6 | 2451 | bitpos = parse_number (pp, (bfd_boolean *) NULL); |
252b5132 RH |
2452 | if (**pp != ',') |
2453 | { | |
2454 | bad_stab (orig); | |
b34976b6 | 2455 | return FALSE; |
252b5132 RH |
2456 | } |
2457 | ++*pp; | |
2458 | ||
b34976b6 | 2459 | bitsize = parse_number (pp, (bfd_boolean *) NULL); |
252b5132 RH |
2460 | if (**pp != ';') |
2461 | { | |
2462 | bad_stab (orig); | |
b34976b6 | 2463 | return FALSE; |
252b5132 RH |
2464 | } |
2465 | ++*pp; | |
2466 | ||
2467 | if (bitpos == 0 && bitsize == 0) | |
2468 | { | |
2469 | /* This can happen in two cases: (1) at least for gcc 2.4.5 or | |
2470 | so, it is a field which has been optimized out. The correct | |
2471 | stab for this case is to use VISIBILITY_IGNORE, but that is a | |
2472 | recent invention. (2) It is a 0-size array. For example | |
2473 | union { int num; char str[0]; } foo. Printing "<no value>" | |
2474 | for str in "p foo" is OK, since foo.str (and thus foo.str[3]) | |
2475 | will continue to work, and a 0-size array as a whole doesn't | |
2476 | have any contents to print. | |
2477 | ||
2478 | I suspect this probably could also happen with gcc -gstabs | |
2479 | (not -gstabs+) for static fields, and perhaps other C++ | |
2480 | extensions. Hopefully few people use -gstabs with gdb, since | |
2481 | it is intended for dbx compatibility. */ | |
2482 | visibility = DEBUG_VISIBILITY_IGNORE; | |
2483 | } | |
2484 | ||
2485 | /* FIXME: gdb does some stuff here to mark fields as unpacked. */ | |
2486 | ||
2487 | *retp = debug_make_field (dhandle, name, type, bitpos, bitsize, visibility); | |
2488 | ||
b34976b6 | 2489 | return TRUE; |
252b5132 RH |
2490 | } |
2491 | ||
2492 | /* Read member function stabs info for C++ classes. The form of each member | |
2493 | function data is: | |
2494 | ||
2495 | NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ; | |
2496 | ||
2497 | An example with two member functions is: | |
2498 | ||
2499 | afunc1::20=##15;:i;2A.;afunc2::20:i;2A.; | |
2500 | ||
2501 | For the case of overloaded operators, the format is op$::*.funcs, where | |
2502 | $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator | |
2503 | name (such as `+=') and `.' marks the end of the operator name. */ | |
2504 | ||
b34976b6 | 2505 | static bfd_boolean |
2da42df6 AJ |
2506 | parse_stab_members (void *dhandle, struct stab_handle *info, |
2507 | const char *tagname, const char **pp, | |
2508 | const int *typenums, debug_method **retp) | |
252b5132 RH |
2509 | { |
2510 | const char *orig; | |
2511 | debug_method *methods; | |
2512 | unsigned int c; | |
2513 | unsigned int alloc; | |
2514 | ||
2515 | *retp = NULL; | |
2516 | ||
2517 | orig = *pp; | |
2518 | ||
2519 | alloc = 0; | |
2520 | methods = NULL; | |
2521 | c = 0; | |
2522 | ||
2523 | while (**pp != ';') | |
2524 | { | |
2525 | const char *p; | |
2526 | char *name; | |
2527 | debug_method_variant *variants; | |
2528 | unsigned int cvars; | |
2529 | unsigned int allocvars; | |
2530 | debug_type look_ahead_type; | |
2531 | ||
2532 | p = strchr (*pp, ':'); | |
2533 | if (p == NULL || p[1] != ':') | |
2534 | break; | |
2535 | ||
2536 | /* FIXME: Some systems use something other than '$' here. */ | |
2537 | if ((*pp)[0] != 'o' || (*pp)[1] != 'p' || (*pp)[2] != '$') | |
2538 | { | |
2539 | name = savestring (*pp, p - *pp); | |
2540 | *pp = p + 2; | |
2541 | } | |
2542 | else | |
2543 | { | |
aaad4cf3 | 2544 | /* This is a completely weird case. In order to stuff in the |
252b5132 RH |
2545 | names that might contain colons (the usual name delimiter), |
2546 | Mike Tiemann defined a different name format which is | |
2547 | signalled if the identifier is "op$". In that case, the | |
2548 | format is "op$::XXXX." where XXXX is the name. This is | |
2549 | used for names like "+" or "=". YUUUUUUUK! FIXME! */ | |
2550 | *pp = p + 2; | |
2551 | for (p = *pp; *p != '.' && *p != '\0'; p++) | |
2552 | ; | |
2553 | if (*p != '.') | |
2554 | { | |
2555 | bad_stab (orig); | |
b34976b6 | 2556 | return FALSE; |
252b5132 RH |
2557 | } |
2558 | name = savestring (*pp, p - *pp); | |
2559 | *pp = p + 1; | |
2560 | } | |
2561 | ||
2562 | allocvars = 10; | |
2563 | variants = ((debug_method_variant *) | |
2564 | xmalloc (allocvars * sizeof *variants)); | |
2565 | cvars = 0; | |
2566 | ||
2567 | look_ahead_type = DEBUG_TYPE_NULL; | |
2568 | ||
2569 | do | |
2570 | { | |
2571 | debug_type type; | |
b34976b6 | 2572 | bfd_boolean stub; |
252b5132 RH |
2573 | char *argtypes; |
2574 | enum debug_visibility visibility; | |
b34976b6 | 2575 | bfd_boolean constp, volatilep, staticp; |
252b5132 RH |
2576 | bfd_vma voffset; |
2577 | debug_type context; | |
2578 | const char *physname; | |
b34976b6 | 2579 | bfd_boolean varargs; |
252b5132 RH |
2580 | |
2581 | if (look_ahead_type != DEBUG_TYPE_NULL) | |
2582 | { | |
2583 | /* g++ version 1 kludge */ | |
2584 | type = look_ahead_type; | |
2585 | look_ahead_type = DEBUG_TYPE_NULL; | |
2586 | } | |
2587 | else | |
2588 | { | |
2589 | type = parse_stab_type (dhandle, info, (const char *) NULL, pp, | |
2590 | (debug_type **) NULL); | |
2591 | if (type == DEBUG_TYPE_NULL) | |
b34976b6 | 2592 | return FALSE; |
252b5132 RH |
2593 | if (**pp != ':') |
2594 | { | |
2595 | bad_stab (orig); | |
b34976b6 | 2596 | return FALSE; |
252b5132 RH |
2597 | } |
2598 | } | |
2599 | ||
2600 | ++*pp; | |
2601 | p = strchr (*pp, ';'); | |
2602 | if (p == NULL) | |
2603 | { | |
2604 | bad_stab (orig); | |
b34976b6 | 2605 | return FALSE; |
252b5132 RH |
2606 | } |
2607 | ||
b34976b6 | 2608 | stub = FALSE; |
252b5132 RH |
2609 | if (debug_get_type_kind (dhandle, type) == DEBUG_KIND_METHOD |
2610 | && debug_get_parameter_types (dhandle, type, &varargs) == NULL) | |
b34976b6 | 2611 | stub = TRUE; |
252b5132 RH |
2612 | |
2613 | argtypes = savestring (*pp, p - *pp); | |
2614 | *pp = p + 1; | |
2615 | ||
2616 | switch (**pp) | |
2617 | { | |
2618 | case '0': | |
2619 | visibility = DEBUG_VISIBILITY_PRIVATE; | |
2620 | break; | |
2621 | case '1': | |
2622 | visibility = DEBUG_VISIBILITY_PROTECTED; | |
2623 | break; | |
2624 | default: | |
2625 | visibility = DEBUG_VISIBILITY_PUBLIC; | |
2626 | break; | |
2627 | } | |
2628 | ++*pp; | |
2629 | ||
b34976b6 AM |
2630 | constp = FALSE; |
2631 | volatilep = FALSE; | |
252b5132 RH |
2632 | switch (**pp) |
2633 | { | |
2634 | case 'A': | |
2635 | /* Normal function. */ | |
2636 | ++*pp; | |
2637 | break; | |
2638 | case 'B': | |
2639 | /* const member function. */ | |
b34976b6 | 2640 | constp = TRUE; |
252b5132 RH |
2641 | ++*pp; |
2642 | break; | |
2643 | case 'C': | |
2644 | /* volatile member function. */ | |
b34976b6 | 2645 | volatilep = TRUE; |
252b5132 RH |
2646 | ++*pp; |
2647 | break; | |
2648 | case 'D': | |
2649 | /* const volatile member function. */ | |
b34976b6 AM |
2650 | constp = TRUE; |
2651 | volatilep = TRUE; | |
252b5132 RH |
2652 | ++*pp; |
2653 | break; | |
2654 | case '*': | |
2655 | case '?': | |
2656 | case '.': | |
2657 | /* File compiled with g++ version 1; no information. */ | |
2658 | break; | |
2659 | default: | |
2660 | warn_stab (orig, _("const/volatile indicator missing")); | |
2661 | break; | |
2662 | } | |
2663 | ||
b34976b6 | 2664 | staticp = FALSE; |
252b5132 RH |
2665 | switch (**pp) |
2666 | { | |
2667 | case '*': | |
2668 | /* virtual member function, followed by index. The sign | |
2669 | bit is supposedly set to distinguish | |
2670 | pointers-to-methods from virtual function indicies. */ | |
2671 | ++*pp; | |
b34976b6 | 2672 | voffset = parse_number (pp, (bfd_boolean *) NULL); |
252b5132 RH |
2673 | if (**pp != ';') |
2674 | { | |
2675 | bad_stab (orig); | |
b34976b6 | 2676 | return FALSE; |
252b5132 RH |
2677 | } |
2678 | ++*pp; | |
2679 | voffset &= 0x7fffffff; | |
2680 | ||
2681 | if (**pp == ';' || *pp == '\0') | |
2682 | { | |
2683 | /* Must be g++ version 1. */ | |
2684 | context = DEBUG_TYPE_NULL; | |
2685 | } | |
2686 | else | |
2687 | { | |
2688 | /* Figure out from whence this virtual function | |
2689 | came. It may belong to virtual function table of | |
2690 | one of its baseclasses. */ | |
9f66665a KH |
2691 | look_ahead_type = parse_stab_type (dhandle, info, |
2692 | (const char *) NULL, | |
2693 | pp, | |
2694 | (debug_type **) NULL); | |
2695 | if (**pp == ':') | |
2696 | { | |
2697 | /* g++ version 1 overloaded methods. */ | |
2698 | context = DEBUG_TYPE_NULL; | |
2699 | } | |
2700 | else | |
2701 | { | |
2702 | context = look_ahead_type; | |
2703 | look_ahead_type = DEBUG_TYPE_NULL; | |
2704 | if (**pp != ';') | |
2705 | { | |
2706 | bad_stab (orig); | |
b34976b6 | 2707 | return FALSE; |
9f66665a KH |
2708 | } |
2709 | ++*pp; | |
2710 | } | |
2711 | } | |
252b5132 RH |
2712 | break; |
2713 | ||
2714 | case '?': | |
2715 | /* static member function. */ | |
2716 | ++*pp; | |
b34976b6 | 2717 | staticp = TRUE; |
252b5132 RH |
2718 | voffset = 0; |
2719 | context = DEBUG_TYPE_NULL; | |
2720 | if (strncmp (argtypes, name, strlen (name)) != 0) | |
b34976b6 | 2721 | stub = TRUE; |
252b5132 RH |
2722 | break; |
2723 | ||
2724 | default: | |
2725 | warn_stab (orig, "member function type missing"); | |
2726 | voffset = 0; | |
2727 | context = DEBUG_TYPE_NULL; | |
2728 | break; | |
2729 | ||
2730 | case '.': | |
2731 | ++*pp; | |
2732 | voffset = 0; | |
2733 | context = DEBUG_TYPE_NULL; | |
2734 | break; | |
2735 | } | |
2736 | ||
2737 | /* If the type is not a stub, then the argtypes string is | |
2738 | the physical name of the function. Otherwise the | |
2739 | argtypes string is the mangled form of the argument | |
2740 | types, and the full type and the physical name must be | |
2741 | extracted from them. */ | |
2742 | if (! stub) | |
2743 | physname = argtypes; | |
2744 | else | |
2745 | { | |
2746 | debug_type class_type, return_type; | |
2747 | ||
2748 | class_type = stab_find_type (dhandle, info, typenums); | |
2749 | if (class_type == DEBUG_TYPE_NULL) | |
b34976b6 | 2750 | return FALSE; |
252b5132 RH |
2751 | return_type = debug_get_return_type (dhandle, type); |
2752 | if (return_type == DEBUG_TYPE_NULL) | |
2753 | { | |
2754 | bad_stab (orig); | |
b34976b6 | 2755 | return FALSE; |
252b5132 RH |
2756 | } |
2757 | type = parse_stab_argtypes (dhandle, info, class_type, name, | |
2758 | tagname, return_type, argtypes, | |
2759 | constp, volatilep, &physname); | |
2760 | if (type == DEBUG_TYPE_NULL) | |
b34976b6 | 2761 | return FALSE; |
252b5132 RH |
2762 | } |
2763 | ||
2764 | if (cvars + 1 >= allocvars) | |
2765 | { | |
2766 | allocvars += 10; | |
2767 | variants = ((debug_method_variant *) | |
2da42df6 | 2768 | xrealloc (variants, |
252b5132 RH |
2769 | allocvars * sizeof *variants)); |
2770 | } | |
2771 | ||
2772 | if (! staticp) | |
2773 | variants[cvars] = debug_make_method_variant (dhandle, physname, | |
2774 | type, visibility, | |
2775 | constp, volatilep, | |
2776 | voffset, context); | |
2777 | else | |
2778 | variants[cvars] = debug_make_static_method_variant (dhandle, | |
2779 | physname, | |
2780 | type, | |
2781 | visibility, | |
2782 | constp, | |
2783 | volatilep); | |
2784 | if (variants[cvars] == DEBUG_METHOD_VARIANT_NULL) | |
b34976b6 | 2785 | return FALSE; |
252b5132 RH |
2786 | |
2787 | ++cvars; | |
2788 | } | |
2789 | while (**pp != ';' && **pp != '\0'); | |
2790 | ||
2791 | variants[cvars] = DEBUG_METHOD_VARIANT_NULL; | |
2792 | ||
2793 | if (**pp != '\0') | |
2794 | ++*pp; | |
2795 | ||
2796 | if (c + 1 >= alloc) | |
2797 | { | |
2798 | alloc += 10; | |
2799 | methods = ((debug_method *) | |
2da42df6 | 2800 | xrealloc (methods, alloc * sizeof *methods)); |
252b5132 RH |
2801 | } |
2802 | ||
2803 | methods[c] = debug_make_method (dhandle, name, variants); | |
2804 | ||
2805 | ++c; | |
2806 | } | |
2807 | ||
2808 | if (methods != NULL) | |
2809 | methods[c] = DEBUG_METHOD_NULL; | |
2810 | ||
2811 | *retp = methods; | |
2812 | ||
b34976b6 | 2813 | return TRUE; |
252b5132 RH |
2814 | } |
2815 | ||
2816 | /* Parse a string representing argument types for a method. Stabs | |
2817 | tries to save space by packing argument types into a mangled | |
2818 | string. This string should give us enough information to extract | |
2819 | both argument types and the physical name of the function, given | |
2820 | the tag name. */ | |
2821 | ||
2822 | static debug_type | |
2da42df6 AJ |
2823 | parse_stab_argtypes (void *dhandle, struct stab_handle *info, |
2824 | debug_type class_type, const char *fieldname, | |
2825 | const char *tagname, debug_type return_type, | |
2826 | const char *argtypes, bfd_boolean constp, | |
2827 | bfd_boolean volatilep, const char **pphysname) | |
252b5132 | 2828 | { |
b34976b6 AM |
2829 | bfd_boolean is_full_physname_constructor; |
2830 | bfd_boolean is_constructor; | |
2831 | bfd_boolean is_destructor; | |
041821e6 | 2832 | bfd_boolean is_v3; |
252b5132 | 2833 | debug_type *args; |
b34976b6 | 2834 | bfd_boolean varargs; |
4b73ca92 | 2835 | unsigned int physname_len = 0; |
252b5132 RH |
2836 | |
2837 | /* Constructors are sometimes handled specially. */ | |
2838 | is_full_physname_constructor = ((argtypes[0] == '_' | |
2839 | && argtypes[1] == '_' | |
3882b010 | 2840 | && (ISDIGIT (argtypes[2]) |
252b5132 RH |
2841 | || argtypes[2] == 'Q' |
2842 | || argtypes[2] == 't')) | |
0112cd26 | 2843 | || CONST_STRNEQ (argtypes, "__ct")); |
252b5132 RH |
2844 | |
2845 | is_constructor = (is_full_physname_constructor | |
2846 | || (tagname != NULL | |
2847 | && strcmp (fieldname, tagname) == 0)); | |
2848 | is_destructor = ((argtypes[0] == '_' | |
2849 | && (argtypes[1] == '$' || argtypes[1] == '.') | |
2850 | && argtypes[2] == '_') | |
0112cd26 | 2851 | || CONST_STRNEQ (argtypes, "__dt")); |
041821e6 | 2852 | is_v3 = argtypes[0] == '_' && argtypes[1] == 'Z'; |
252b5132 | 2853 | |
041821e6 | 2854 | if (is_destructor || is_full_physname_constructor || is_v3) |
252b5132 RH |
2855 | *pphysname = argtypes; |
2856 | else | |
2857 | { | |
2858 | unsigned int len; | |
2859 | const char *const_prefix; | |
2860 | const char *volatile_prefix; | |
2861 | char buf[20]; | |
2862 | unsigned int mangled_name_len; | |
2863 | char *physname; | |
2864 | ||
2865 | len = tagname == NULL ? 0 : strlen (tagname); | |
2866 | const_prefix = constp ? "C" : ""; | |
2867 | volatile_prefix = volatilep ? "V" : ""; | |
2868 | ||
2869 | if (len == 0) | |
2870 | sprintf (buf, "__%s%s", const_prefix, volatile_prefix); | |
2871 | else if (tagname != NULL && strchr (tagname, '<') != NULL) | |
2872 | { | |
2873 | /* Template methods are fully mangled. */ | |
2874 | sprintf (buf, "__%s%s", const_prefix, volatile_prefix); | |
2875 | tagname = NULL; | |
2876 | len = 0; | |
2877 | } | |
2878 | else | |
2879 | sprintf (buf, "__%s%s%d", const_prefix, volatile_prefix, len); | |
2880 | ||
2881 | mangled_name_len = ((is_constructor ? 0 : strlen (fieldname)) | |
2882 | + strlen (buf) | |
2883 | + len | |
2884 | + strlen (argtypes) | |
2885 | + 1); | |
2886 | ||
2887 | if (fieldname[0] == 'o' | |
2888 | && fieldname[1] == 'p' | |
2889 | && (fieldname[2] == '$' || fieldname[2] == '.')) | |
2890 | { | |
2891 | const char *opname; | |
2892 | ||
2893 | opname = cplus_mangle_opname (fieldname + 3, 0); | |
2894 | if (opname == NULL) | |
2895 | { | |
2896 | fprintf (stderr, _("No mangling for \"%s\"\n"), fieldname); | |
2897 | return DEBUG_TYPE_NULL; | |
2898 | } | |
2899 | mangled_name_len += strlen (opname); | |
2900 | physname = (char *) xmalloc (mangled_name_len); | |
2901 | strncpy (physname, fieldname, 3); | |
2902 | strcpy (physname + 3, opname); | |
2903 | } | |
2904 | else | |
2905 | { | |
2906 | physname = (char *) xmalloc (mangled_name_len); | |
2907 | if (is_constructor) | |
2908 | physname[0] = '\0'; | |
2909 | else | |
2910 | strcpy (physname, fieldname); | |
2911 | } | |
2912 | ||
4b73ca92 | 2913 | physname_len = strlen (physname); |
252b5132 RH |
2914 | strcat (physname, buf); |
2915 | if (tagname != NULL) | |
2916 | strcat (physname, tagname); | |
2917 | strcat (physname, argtypes); | |
2918 | ||
2919 | *pphysname = physname; | |
2920 | } | |
2921 | ||
2922 | if (*argtypes == '\0' || is_destructor) | |
2923 | { | |
2924 | args = (debug_type *) xmalloc (sizeof *args); | |
2925 | *args = NULL; | |
2926 | return debug_make_method_type (dhandle, return_type, class_type, args, | |
b34976b6 | 2927 | FALSE); |
252b5132 RH |
2928 | } |
2929 | ||
4b73ca92 | 2930 | args = stab_demangle_argtypes (dhandle, info, *pphysname, &varargs, physname_len); |
252b5132 RH |
2931 | if (args == NULL) |
2932 | return DEBUG_TYPE_NULL; | |
2933 | ||
2934 | return debug_make_method_type (dhandle, return_type, class_type, args, | |
2935 | varargs); | |
2936 | } | |
2937 | ||
2938 | /* The tail end of stabs for C++ classes that contain a virtual function | |
2939 | pointer contains a tilde, a %, and a type number. | |
2940 | The type number refers to the base class (possibly this class itself) which | |
2941 | contains the vtable pointer for the current class. | |
2942 | ||
2943 | This function is called when we have parsed all the method declarations, | |
2944 | so we can look for the vptr base class info. */ | |
2945 | ||
b34976b6 | 2946 | static bfd_boolean |
2da42df6 AJ |
2947 | parse_stab_tilde_field (void *dhandle, struct stab_handle *info, |
2948 | const char **pp, const int *typenums, | |
2949 | debug_type *retvptrbase, bfd_boolean *retownvptr) | |
252b5132 RH |
2950 | { |
2951 | const char *orig; | |
2952 | const char *hold; | |
2953 | int vtypenums[2]; | |
2954 | ||
2955 | *retvptrbase = DEBUG_TYPE_NULL; | |
b34976b6 | 2956 | *retownvptr = FALSE; |
252b5132 RH |
2957 | |
2958 | orig = *pp; | |
2959 | ||
9f66665a | 2960 | /* If we are positioned at a ';', then skip it. */ |
252b5132 RH |
2961 | if (**pp == ';') |
2962 | ++*pp; | |
2963 | ||
2964 | if (**pp != '~') | |
b34976b6 | 2965 | return TRUE; |
252b5132 RH |
2966 | |
2967 | ++*pp; | |
2968 | ||
2969 | if (**pp == '=' || **pp == '+' || **pp == '-') | |
2970 | { | |
2971 | /* Obsolete flags that used to indicate the presence of | |
9f66665a | 2972 | constructors and/or destructors. */ |
252b5132 RH |
2973 | ++*pp; |
2974 | } | |
2975 | ||
2976 | if (**pp != '%') | |
b34976b6 | 2977 | return TRUE; |
252b5132 RH |
2978 | |
2979 | ++*pp; | |
2980 | ||
2981 | hold = *pp; | |
2982 | ||
2983 | /* The next number is the type number of the base class (possibly | |
2984 | our own class) which supplies the vtable for this class. */ | |
2985 | if (! parse_stab_type_number (pp, vtypenums)) | |
b34976b6 | 2986 | return FALSE; |
252b5132 RH |
2987 | |
2988 | if (vtypenums[0] == typenums[0] | |
2989 | && vtypenums[1] == typenums[1]) | |
b34976b6 | 2990 | *retownvptr = TRUE; |
252b5132 RH |
2991 | else |
2992 | { | |
2993 | debug_type vtype; | |
2994 | const char *p; | |
2995 | ||
2996 | *pp = hold; | |
2997 | ||
2998 | vtype = parse_stab_type (dhandle, info, (const char *) NULL, pp, | |
2999 | (debug_type **) NULL); | |
3000 | for (p = *pp; *p != ';' && *p != '\0'; p++) | |
3001 | ; | |
3002 | if (*p != ';') | |
3003 | { | |
3004 | bad_stab (orig); | |
b34976b6 | 3005 | return FALSE; |
252b5132 RH |
3006 | } |
3007 | ||
3008 | *retvptrbase = vtype; | |
3009 | ||
3010 | *pp = p + 1; | |
3011 | } | |
3012 | ||
b34976b6 | 3013 | return TRUE; |
252b5132 RH |
3014 | } |
3015 | ||
3016 | /* Read a definition of an array type. */ | |
3017 | ||
3018 | static debug_type | |
2da42df6 AJ |
3019 | parse_stab_array_type (void *dhandle, struct stab_handle *info, |
3020 | const char **pp, bfd_boolean stringp) | |
252b5132 RH |
3021 | { |
3022 | const char *orig; | |
3023 | const char *p; | |
3024 | int typenums[2]; | |
3025 | debug_type index_type; | |
b34976b6 | 3026 | bfd_boolean adjustable; |
252b5132 RH |
3027 | bfd_signed_vma lower, upper; |
3028 | debug_type element_type; | |
3029 | ||
3030 | /* Format of an array type: | |
3031 | "ar<index type>;lower;upper;<array_contents_type>". | |
3032 | OS9000: "arlower,upper;<array_contents_type>". | |
3033 | ||
3034 | Fortran adjustable arrays use Adigits or Tdigits for lower or upper; | |
3035 | for these, produce a type like float[][]. */ | |
3036 | ||
3037 | orig = *pp; | |
3038 | ||
3039 | /* FIXME: gdb checks os9k_stabs here. */ | |
3040 | ||
3041 | /* If the index type is type 0, we take it as int. */ | |
3042 | p = *pp; | |
3043 | if (! parse_stab_type_number (&p, typenums)) | |
3dceb55b | 3044 | return DEBUG_TYPE_NULL; |
252b5132 RH |
3045 | if (typenums[0] == 0 && typenums[1] == 0 && **pp != '=') |
3046 | { | |
3047 | index_type = debug_find_named_type (dhandle, "int"); | |
3048 | if (index_type == DEBUG_TYPE_NULL) | |
3049 | { | |
b34976b6 | 3050 | index_type = debug_make_int_type (dhandle, 4, FALSE); |
252b5132 | 3051 | if (index_type == DEBUG_TYPE_NULL) |
3dceb55b | 3052 | return DEBUG_TYPE_NULL; |
252b5132 RH |
3053 | } |
3054 | *pp = p; | |
3055 | } | |
3056 | else | |
3057 | { | |
3058 | index_type = parse_stab_type (dhandle, info, (const char *) NULL, pp, | |
3059 | (debug_type **) NULL); | |
3060 | } | |
3061 | ||
3062 | if (**pp != ';') | |
3063 | { | |
3064 | bad_stab (orig); | |
3065 | return DEBUG_TYPE_NULL; | |
3066 | } | |
3067 | ++*pp; | |
3068 | ||
b34976b6 | 3069 | adjustable = FALSE; |
252b5132 | 3070 | |
3882b010 | 3071 | if (! ISDIGIT (**pp) && **pp != '-') |
252b5132 RH |
3072 | { |
3073 | ++*pp; | |
b34976b6 | 3074 | adjustable = TRUE; |
252b5132 RH |
3075 | } |
3076 | ||
b34976b6 | 3077 | lower = (bfd_signed_vma) parse_number (pp, (bfd_boolean *) NULL); |
252b5132 RH |
3078 | if (**pp != ';') |
3079 | { | |
3080 | bad_stab (orig); | |
3dceb55b | 3081 | return DEBUG_TYPE_NULL; |
252b5132 RH |
3082 | } |
3083 | ++*pp; | |
3084 | ||
3882b010 | 3085 | if (! ISDIGIT (**pp) && **pp != '-') |
252b5132 RH |
3086 | { |
3087 | ++*pp; | |
b34976b6 | 3088 | adjustable = TRUE; |
252b5132 RH |
3089 | } |
3090 | ||
b34976b6 | 3091 | upper = (bfd_signed_vma) parse_number (pp, (bfd_boolean *) NULL); |
252b5132 RH |
3092 | if (**pp != ';') |
3093 | { | |
3094 | bad_stab (orig); | |
3dceb55b | 3095 | return DEBUG_TYPE_NULL; |
252b5132 RH |
3096 | } |
3097 | ++*pp; | |
3098 | ||
3099 | element_type = parse_stab_type (dhandle, info, (const char *) NULL, pp, | |
3100 | (debug_type **) NULL); | |
3101 | if (element_type == DEBUG_TYPE_NULL) | |
3dceb55b | 3102 | return DEBUG_TYPE_NULL; |
252b5132 RH |
3103 | |
3104 | if (adjustable) | |
3105 | { | |
3106 | lower = 0; | |
3107 | upper = -1; | |
3108 | } | |
3109 | ||
3110 | return debug_make_array_type (dhandle, element_type, index_type, lower, | |
3111 | upper, stringp); | |
3112 | } | |
3113 | ||
3114 | /* This struct holds information about files we have seen using | |
3115 | N_BINCL. */ | |
3116 | ||
3117 | struct bincl_file | |
3118 | { | |
3119 | /* The next N_BINCL file. */ | |
3120 | struct bincl_file *next; | |
3121 | /* The next N_BINCL on the stack. */ | |
3122 | struct bincl_file *next_stack; | |
3123 | /* The file name. */ | |
3124 | const char *name; | |
3125 | /* The hash value. */ | |
3126 | bfd_vma hash; | |
3127 | /* The file index. */ | |
3128 | unsigned int file; | |
3129 | /* The list of types defined in this file. */ | |
3130 | struct stab_types *file_types; | |
3131 | }; | |
3132 | ||
3133 | /* Start a new N_BINCL file, pushing it onto the stack. */ | |
3134 | ||
3135 | static void | |
2da42df6 | 3136 | push_bincl (struct stab_handle *info, const char *name, bfd_vma hash) |
252b5132 RH |
3137 | { |
3138 | struct bincl_file *n; | |
3139 | ||
3140 | n = (struct bincl_file *) xmalloc (sizeof *n); | |
3141 | n->next = info->bincl_list; | |
3142 | n->next_stack = info->bincl_stack; | |
3143 | n->name = name; | |
3144 | n->hash = hash; | |
3145 | n->file = info->files; | |
3146 | n->file_types = NULL; | |
3147 | info->bincl_list = n; | |
3148 | info->bincl_stack = n; | |
3149 | ||
3150 | ++info->files; | |
3151 | info->file_types = ((struct stab_types **) | |
2da42df6 | 3152 | xrealloc (info->file_types, |
252b5132 RH |
3153 | (info->files |
3154 | * sizeof *info->file_types))); | |
3155 | info->file_types[n->file] = NULL; | |
3156 | } | |
3157 | ||
3158 | /* Finish an N_BINCL file, at an N_EINCL, popping the name off the | |
3159 | stack. */ | |
3160 | ||
3161 | static const char * | |
2da42df6 | 3162 | pop_bincl (struct stab_handle *info) |
252b5132 RH |
3163 | { |
3164 | struct bincl_file *o; | |
3165 | ||
3166 | o = info->bincl_stack; | |
3167 | if (o == NULL) | |
3168 | return info->main_filename; | |
3169 | info->bincl_stack = o->next_stack; | |
3170 | ||
3171 | o->file_types = info->file_types[o->file]; | |
3172 | ||
3173 | if (info->bincl_stack == NULL) | |
3174 | return info->main_filename; | |
3175 | return info->bincl_stack->name; | |
3176 | } | |
3177 | ||
3178 | /* Handle an N_EXCL: get the types from the corresponding N_BINCL. */ | |
3179 | ||
b34976b6 | 3180 | static bfd_boolean |
2da42df6 | 3181 | find_excl (struct stab_handle *info, const char *name, bfd_vma hash) |
252b5132 RH |
3182 | { |
3183 | struct bincl_file *l; | |
3184 | ||
3185 | ++info->files; | |
3186 | info->file_types = ((struct stab_types **) | |
2da42df6 | 3187 | xrealloc (info->file_types, |
252b5132 RH |
3188 | (info->files |
3189 | * sizeof *info->file_types))); | |
3190 | ||
3191 | for (l = info->bincl_list; l != NULL; l = l->next) | |
3192 | if (l->hash == hash && strcmp (l->name, name) == 0) | |
3193 | break; | |
3194 | if (l == NULL) | |
3195 | { | |
3196 | warn_stab (name, _("Undefined N_EXCL")); | |
3197 | info->file_types[info->files - 1] = NULL; | |
b34976b6 | 3198 | return TRUE; |
252b5132 RH |
3199 | } |
3200 | ||
3201 | info->file_types[info->files - 1] = l->file_types; | |
3202 | ||
b34976b6 | 3203 | return TRUE; |
252b5132 RH |
3204 | } |
3205 | ||
3206 | /* Handle a variable definition. gcc emits variable definitions for a | |
3207 | block before the N_LBRAC, so we must hold onto them until we see | |
3208 | it. The SunPRO compiler emits variable definitions after the | |
3209 | N_LBRAC, so we can call debug_record_variable immediately. */ | |
3210 | ||
b34976b6 | 3211 | static bfd_boolean |
2da42df6 AJ |
3212 | stab_record_variable (void *dhandle, struct stab_handle *info, |
3213 | const char *name, debug_type type, | |
3214 | enum debug_var_kind kind, bfd_vma val) | |
252b5132 RH |
3215 | { |
3216 | struct stab_pending_var *v; | |
3217 | ||
3218 | if ((kind == DEBUG_GLOBAL || kind == DEBUG_STATIC) | |
3219 | || ! info->within_function | |
3220 | || (info->gcc_compiled == 0 && info->n_opt_found)) | |
3221 | return debug_record_variable (dhandle, name, type, kind, val); | |
3222 | ||
3223 | v = (struct stab_pending_var *) xmalloc (sizeof *v); | |
3224 | memset (v, 0, sizeof *v); | |
3225 | ||
3226 | v->next = info->pending; | |
3227 | v->name = name; | |
3228 | v->type = type; | |
3229 | v->kind = kind; | |
3230 | v->val = val; | |
3231 | info->pending = v; | |
3232 | ||
b34976b6 | 3233 | return TRUE; |
252b5132 RH |
3234 | } |
3235 | ||
3236 | /* Emit pending variable definitions. This is called after we see the | |
3237 | N_LBRAC that starts the block. */ | |
3238 | ||
b34976b6 | 3239 | static bfd_boolean |
2da42df6 | 3240 | stab_emit_pending_vars (void *dhandle, struct stab_handle *info) |
252b5132 RH |
3241 | { |
3242 | struct stab_pending_var *v; | |
3243 | ||
3244 | v = info->pending; | |
3245 | while (v != NULL) | |
3246 | { | |
3247 | struct stab_pending_var *next; | |
3248 | ||
3249 | if (! debug_record_variable (dhandle, v->name, v->type, v->kind, v->val)) | |
b34976b6 | 3250 | return FALSE; |
252b5132 RH |
3251 | |
3252 | next = v->next; | |
3253 | free (v); | |
3254 | v = next; | |
3255 | } | |
3256 | ||
3257 | info->pending = NULL; | |
3258 | ||
b34976b6 | 3259 | return TRUE; |
252b5132 RH |
3260 | } |
3261 | ||
3262 | /* Find the slot for a type in the database. */ | |
3263 | ||
3264 | static debug_type * | |
2da42df6 | 3265 | stab_find_slot (struct stab_handle *info, const int *typenums) |
252b5132 RH |
3266 | { |
3267 | int filenum; | |
91d6fa6a | 3268 | int tindex; |
252b5132 RH |
3269 | struct stab_types **ps; |
3270 | ||
3271 | filenum = typenums[0]; | |
91d6fa6a | 3272 | tindex = typenums[1]; |
252b5132 RH |
3273 | |
3274 | if (filenum < 0 || (unsigned int) filenum >= info->files) | |
3275 | { | |
3276 | fprintf (stderr, _("Type file number %d out of range\n"), filenum); | |
3277 | return NULL; | |
3278 | } | |
91d6fa6a | 3279 | if (tindex < 0) |
252b5132 | 3280 | { |
91d6fa6a | 3281 | fprintf (stderr, _("Type index number %d out of range\n"), tindex); |
252b5132 RH |
3282 | return NULL; |
3283 | } | |
3284 | ||
3285 | ps = info->file_types + filenum; | |
3286 | ||
91d6fa6a | 3287 | while (tindex >= STAB_TYPES_SLOTS) |
252b5132 RH |
3288 | { |
3289 | if (*ps == NULL) | |
3290 | { | |
3291 | *ps = (struct stab_types *) xmalloc (sizeof **ps); | |
3292 | memset (*ps, 0, sizeof **ps); | |
3293 | } | |
3294 | ps = &(*ps)->next; | |
91d6fa6a | 3295 | tindex -= STAB_TYPES_SLOTS; |
252b5132 RH |
3296 | } |
3297 | if (*ps == NULL) | |
3298 | { | |
3299 | *ps = (struct stab_types *) xmalloc (sizeof **ps); | |
3300 | memset (*ps, 0, sizeof **ps); | |
3301 | } | |
3302 | ||
91d6fa6a | 3303 | return (*ps)->types + tindex; |
252b5132 RH |
3304 | } |
3305 | ||
3306 | /* Find a type given a type number. If the type has not been | |
3307 | allocated yet, create an indirect type. */ | |
3308 | ||
3309 | static debug_type | |
2da42df6 | 3310 | stab_find_type (void *dhandle, struct stab_handle *info, const int *typenums) |
252b5132 RH |
3311 | { |
3312 | debug_type *slot; | |
3313 | ||
3314 | if (typenums[0] == 0 && typenums[1] < 0) | |
3315 | { | |
3316 | /* A negative type number indicates an XCOFF builtin type. */ | |
3317 | return stab_xcoff_builtin_type (dhandle, info, typenums[1]); | |
3318 | } | |
3319 | ||
3320 | slot = stab_find_slot (info, typenums); | |
3321 | if (slot == NULL) | |
3322 | return DEBUG_TYPE_NULL; | |
3323 | ||
3324 | if (*slot == DEBUG_TYPE_NULL) | |
3325 | return debug_make_indirect_type (dhandle, slot, (const char *) NULL); | |
3326 | ||
3327 | return *slot; | |
3328 | } | |
3329 | ||
3330 | /* Record that a given type number refers to a given type. */ | |
3331 | ||
b34976b6 | 3332 | static bfd_boolean |
2da42df6 AJ |
3333 | stab_record_type (void *dhandle ATTRIBUTE_UNUSED, struct stab_handle *info, |
3334 | const int *typenums, debug_type type) | |
252b5132 RH |
3335 | { |
3336 | debug_type *slot; | |
3337 | ||
3338 | slot = stab_find_slot (info, typenums); | |
3339 | if (slot == NULL) | |
b34976b6 | 3340 | return FALSE; |
252b5132 RH |
3341 | |
3342 | /* gdb appears to ignore type redefinitions, so we do as well. */ | |
3343 | ||
3344 | *slot = type; | |
3345 | ||
b34976b6 | 3346 | return TRUE; |
252b5132 RH |
3347 | } |
3348 | ||
3349 | /* Return an XCOFF builtin type. */ | |
3350 | ||
3351 | static debug_type | |
2da42df6 AJ |
3352 | stab_xcoff_builtin_type (void *dhandle, struct stab_handle *info, |
3353 | int typenum) | |
252b5132 RH |
3354 | { |
3355 | debug_type rettype; | |
3356 | const char *name; | |
3357 | ||
3358 | if (typenum >= 0 || typenum < -XCOFF_TYPE_COUNT) | |
3359 | { | |
3360 | fprintf (stderr, _("Unrecognized XCOFF type %d\n"), typenum); | |
3361 | return DEBUG_TYPE_NULL; | |
3362 | } | |
3363 | if (info->xcoff_types[-typenum] != NULL) | |
3364 | return info->xcoff_types[-typenum]; | |
3365 | ||
3366 | switch (-typenum) | |
3367 | { | |
3368 | case 1: | |
3369 | /* The size of this and all the other types are fixed, defined | |
3370 | by the debugging format. */ | |
3371 | name = "int"; | |
b34976b6 | 3372 | rettype = debug_make_int_type (dhandle, 4, FALSE); |
252b5132 RH |
3373 | break; |
3374 | case 2: | |
3375 | name = "char"; | |
b34976b6 | 3376 | rettype = debug_make_int_type (dhandle, 1, FALSE); |
252b5132 RH |
3377 | break; |
3378 | case 3: | |
3379 | name = "short"; | |
b34976b6 | 3380 | rettype = debug_make_int_type (dhandle, 2, FALSE); |
252b5132 RH |
3381 | break; |
3382 | case 4: | |
3383 | name = "long"; | |
b34976b6 | 3384 | rettype = debug_make_int_type (dhandle, 4, FALSE); |
252b5132 RH |
3385 | break; |
3386 | case 5: | |
3387 | name = "unsigned char"; | |
b34976b6 | 3388 | rettype = debug_make_int_type (dhandle, 1, TRUE); |
252b5132 RH |
3389 | break; |
3390 | case 6: | |
3391 | name = "signed char"; | |
b34976b6 | 3392 | rettype = debug_make_int_type (dhandle, 1, FALSE); |
252b5132 RH |
3393 | break; |
3394 | case 7: | |
3395 | name = "unsigned short"; | |
b34976b6 | 3396 | rettype = debug_make_int_type (dhandle, 2, TRUE); |
252b5132 RH |
3397 | break; |
3398 | case 8: | |
3399 | name = "unsigned int"; | |
b34976b6 | 3400 | rettype = debug_make_int_type (dhandle, 4, TRUE); |
252b5132 RH |
3401 | break; |
3402 | case 9: | |
3403 | name = "unsigned"; | |
b34976b6 | 3404 | rettype = debug_make_int_type (dhandle, 4, TRUE); |
252b5132 RH |
3405 | case 10: |
3406 | name = "unsigned long"; | |
b34976b6 | 3407 | rettype = debug_make_int_type (dhandle, 4, TRUE); |
252b5132 RH |
3408 | break; |
3409 | case 11: | |
3410 | name = "void"; | |
3411 | rettype = debug_make_void_type (dhandle); | |
3412 | break; | |
3413 | case 12: | |
3414 | /* IEEE single precision (32 bit). */ | |
3415 | name = "float"; | |
3416 | rettype = debug_make_float_type (dhandle, 4); | |
3417 | break; | |
3418 | case 13: | |
3419 | /* IEEE double precision (64 bit). */ | |
3420 | name = "double"; | |
3421 | rettype = debug_make_float_type (dhandle, 8); | |
3422 | break; | |
3423 | case 14: | |
3424 | /* This is an IEEE double on the RS/6000, and different machines | |
3425 | with different sizes for "long double" should use different | |
3426 | negative type numbers. See stabs.texinfo. */ | |
3427 | name = "long double"; | |
3428 | rettype = debug_make_float_type (dhandle, 8); | |
3429 | break; | |
3430 | case 15: | |
3431 | name = "integer"; | |
b34976b6 | 3432 | rettype = debug_make_int_type (dhandle, 4, FALSE); |
252b5132 RH |
3433 | break; |
3434 | case 16: | |
3435 | name = "boolean"; | |
3436 | rettype = debug_make_bool_type (dhandle, 4); | |
3437 | break; | |
3438 | case 17: | |
3439 | name = "short real"; | |
3440 | rettype = debug_make_float_type (dhandle, 4); | |
3441 | break; | |
3442 | case 18: | |
3443 | name = "real"; | |
3444 | rettype = debug_make_float_type (dhandle, 8); | |
3445 | break; | |
3446 | case 19: | |
3447 | /* FIXME */ | |
3448 | name = "stringptr"; | |
3449 | rettype = NULL; | |
3450 | break; | |
3451 | case 20: | |
3452 | /* FIXME */ | |
3453 | name = "character"; | |
b34976b6 | 3454 | rettype = debug_make_int_type (dhandle, 1, TRUE); |
252b5132 RH |
3455 | break; |
3456 | case 21: | |
3457 | name = "logical*1"; | |
3458 | rettype = debug_make_bool_type (dhandle, 1); | |
3459 | break; | |
3460 | case 22: | |
3461 | name = "logical*2"; | |
3462 | rettype = debug_make_bool_type (dhandle, 2); | |
3463 | break; | |
3464 | case 23: | |
3465 | name = "logical*4"; | |
3466 | rettype = debug_make_bool_type (dhandle, 4); | |
3467 | break; | |
3468 | case 24: | |
3469 | name = "logical"; | |
3470 | rettype = debug_make_bool_type (dhandle, 4); | |
3471 | break; | |
3472 | case 25: | |
3473 | /* Complex type consisting of two IEEE single precision values. */ | |
3474 | name = "complex"; | |
3475 | rettype = debug_make_complex_type (dhandle, 8); | |
3476 | break; | |
3477 | case 26: | |
3478 | /* Complex type consisting of two IEEE double precision values. */ | |
3479 | name = "double complex"; | |
3480 | rettype = debug_make_complex_type (dhandle, 16); | |
3481 | break; | |
3482 | case 27: | |
3483 | name = "integer*1"; | |
b34976b6 | 3484 | rettype = debug_make_int_type (dhandle, 1, FALSE); |
252b5132 RH |
3485 | break; |
3486 | case 28: | |
3487 | name = "integer*2"; | |
b34976b6 | 3488 | rettype = debug_make_int_type (dhandle, 2, FALSE); |
252b5132 RH |
3489 | break; |
3490 | case 29: | |
3491 | name = "integer*4"; | |
b34976b6 | 3492 | rettype = debug_make_int_type (dhandle, 4, FALSE); |
252b5132 RH |
3493 | break; |
3494 | case 30: | |
3495 | /* FIXME */ | |
3496 | name = "wchar"; | |
b34976b6 | 3497 | rettype = debug_make_int_type (dhandle, 2, FALSE); |
252b5132 RH |
3498 | break; |
3499 | case 31: | |
3500 | name = "long long"; | |
b34976b6 | 3501 | rettype = debug_make_int_type (dhandle, 8, FALSE); |
252b5132 RH |
3502 | break; |
3503 | case 32: | |
3504 | name = "unsigned long long"; | |
b34976b6 | 3505 | rettype = debug_make_int_type (dhandle, 8, TRUE); |
252b5132 RH |
3506 | break; |
3507 | case 33: | |
3508 | name = "logical*8"; | |
3509 | rettype = debug_make_bool_type (dhandle, 8); | |
3510 | break; | |
3511 | case 34: | |
3512 | name = "integer*8"; | |
b34976b6 | 3513 | rettype = debug_make_int_type (dhandle, 8, FALSE); |
252b5132 RH |
3514 | break; |
3515 | default: | |
3516 | abort (); | |
3517 | } | |
3518 | ||
3519 | rettype = debug_name_type (dhandle, name, rettype); | |
3520 | ||
3521 | info->xcoff_types[-typenum] = rettype; | |
3522 | ||
3523 | return rettype; | |
3524 | } | |
3525 | ||
3526 | /* Find or create a tagged type. */ | |
3527 | ||
3528 | static debug_type | |
2da42df6 AJ |
3529 | stab_find_tagged_type (void *dhandle, struct stab_handle *info, |
3530 | const char *p, int len, enum debug_type_kind kind) | |
252b5132 RH |
3531 | { |
3532 | char *name; | |
3533 | debug_type dtype; | |
3534 | struct stab_tag *st; | |
3535 | ||
3536 | name = savestring (p, len); | |
3537 | ||
3538 | /* We pass DEBUG_KIND_ILLEGAL because we want all tags in the same | |
3539 | namespace. This is right for C, and I don't know how to handle | |
3540 | other languages. FIXME. */ | |
3541 | dtype = debug_find_tagged_type (dhandle, name, DEBUG_KIND_ILLEGAL); | |
3542 | if (dtype != DEBUG_TYPE_NULL) | |
3543 | { | |
3544 | free (name); | |
3545 | return dtype; | |
3546 | } | |
3547 | ||
3548 | /* We need to allocate an entry on the undefined tag list. */ | |
3549 | for (st = info->tags; st != NULL; st = st->next) | |
3550 | { | |
3551 | if (st->name[0] == name[0] | |
3552 | && strcmp (st->name, name) == 0) | |
3553 | { | |
3554 | if (st->kind == DEBUG_KIND_ILLEGAL) | |
3555 | st->kind = kind; | |
3556 | free (name); | |
3557 | break; | |
3558 | } | |
3559 | } | |
3560 | if (st == NULL) | |
3561 | { | |
3562 | st = (struct stab_tag *) xmalloc (sizeof *st); | |
3563 | memset (st, 0, sizeof *st); | |
3564 | ||
3565 | st->next = info->tags; | |
3566 | st->name = name; | |
3567 | st->kind = kind; | |
3568 | st->slot = DEBUG_TYPE_NULL; | |
3569 | st->type = debug_make_indirect_type (dhandle, &st->slot, name); | |
3570 | info->tags = st; | |
3571 | } | |
3572 | ||
3573 | return st->type; | |
3574 | } | |
3575 | \f | |
3576 | /* In order to get the correct argument types for a stubbed method, we | |
3577 | need to extract the argument types from a C++ mangled string. | |
3578 | Since the argument types can refer back to the return type, this | |
3579 | means that we must demangle the entire physical name. In gdb this | |
3580 | is done by calling cplus_demangle and running the results back | |
3581 | through the C++ expression parser. Since we have no expression | |
3582 | parser, we must duplicate much of the work of cplus_demangle here. | |
3583 | ||
3584 | We assume that GNU style demangling is used, since this is only | |
3585 | done for method stubs, and only g++ should output that form of | |
3586 | debugging information. */ | |
3587 | ||
3588 | /* This structure is used to hold a pointer to type information which | |
3589 | demangling a string. */ | |
3590 | ||
3591 | struct stab_demangle_typestring | |
3592 | { | |
3593 | /* The start of the type. This is not null terminated. */ | |
3594 | const char *typestring; | |
3595 | /* The length of the type. */ | |
3596 | unsigned int len; | |
3597 | }; | |
3598 | ||
3599 | /* This structure is used to hold information while demangling a | |
3600 | string. */ | |
3601 | ||
3602 | struct stab_demangle_info | |
3603 | { | |
3604 | /* The debugging information handle. */ | |
2da42df6 | 3605 | void *dhandle; |
252b5132 RH |
3606 | /* The stab information handle. */ |
3607 | struct stab_handle *info; | |
3608 | /* The array of arguments we are building. */ | |
3609 | debug_type *args; | |
3610 | /* Whether the method takes a variable number of arguments. */ | |
b34976b6 | 3611 | bfd_boolean varargs; |
252b5132 RH |
3612 | /* The array of types we have remembered. */ |
3613 | struct stab_demangle_typestring *typestrings; | |
3614 | /* The number of typestrings. */ | |
3615 | unsigned int typestring_count; | |
3616 | /* The number of typestring slots we have allocated. */ | |
3617 | unsigned int typestring_alloc; | |
3618 | }; | |
3619 | ||
2da42df6 AJ |
3620 | static void stab_bad_demangle (const char *); |
3621 | static unsigned int stab_demangle_count (const char **); | |
3622 | static bfd_boolean stab_demangle_get_count (const char **, unsigned int *); | |
b34976b6 | 3623 | static bfd_boolean stab_demangle_prefix |
2da42df6 | 3624 | (struct stab_demangle_info *, const char **, unsigned int); |
b34976b6 | 3625 | static bfd_boolean stab_demangle_function_name |
2da42df6 | 3626 | (struct stab_demangle_info *, const char **, const char *); |
b34976b6 | 3627 | static bfd_boolean stab_demangle_signature |
2da42df6 | 3628 | (struct stab_demangle_info *, const char **); |
b34976b6 | 3629 | static bfd_boolean stab_demangle_qualified |
2da42df6 | 3630 | (struct stab_demangle_info *, const char **, debug_type *); |
b34976b6 | 3631 | static bfd_boolean stab_demangle_template |
2da42df6 | 3632 | (struct stab_demangle_info *, const char **, char **); |
b34976b6 | 3633 | static bfd_boolean stab_demangle_class |
2da42df6 | 3634 | (struct stab_demangle_info *, const char **, const char **); |
b34976b6 | 3635 | static bfd_boolean stab_demangle_args |
2da42df6 | 3636 | (struct stab_demangle_info *, const char **, debug_type **, bfd_boolean *); |
b34976b6 | 3637 | static bfd_boolean stab_demangle_arg |
2da42df6 AJ |
3638 | (struct stab_demangle_info *, const char **, debug_type **, |
3639 | unsigned int *, unsigned int *); | |
b34976b6 | 3640 | static bfd_boolean stab_demangle_type |
2da42df6 | 3641 | (struct stab_demangle_info *, const char **, debug_type *); |
b34976b6 | 3642 | static bfd_boolean stab_demangle_fund_type |
2da42df6 | 3643 | (struct stab_demangle_info *, const char **, debug_type *); |
b34976b6 | 3644 | static bfd_boolean stab_demangle_remember_type |
2da42df6 | 3645 | (struct stab_demangle_info *, const char *, int); |
252b5132 RH |
3646 | |
3647 | /* Warn about a bad demangling. */ | |
3648 | ||
3649 | static void | |
2da42df6 | 3650 | stab_bad_demangle (const char *s) |
252b5132 RH |
3651 | { |
3652 | fprintf (stderr, _("bad mangled name `%s'\n"), s); | |
3653 | } | |
3654 | ||
3655 | /* Get a count from a stab string. */ | |
3656 | ||
3657 | static unsigned int | |
2da42df6 | 3658 | stab_demangle_count (const char **pp) |
252b5132 RH |
3659 | { |
3660 | unsigned int count; | |
3661 | ||
3662 | count = 0; | |
3882b010 | 3663 | while (ISDIGIT (**pp)) |
252b5132 RH |
3664 | { |
3665 | count *= 10; | |
3666 | count += **pp - '0'; | |
3667 | ++*pp; | |
3668 | } | |
3669 | return count; | |
3670 | } | |
3671 | ||
3672 | /* Require a count in a string. The count may be multiple digits, in | |
3673 | which case it must end in an underscore. */ | |
3674 | ||
b34976b6 | 3675 | static bfd_boolean |
2da42df6 | 3676 | stab_demangle_get_count (const char **pp, unsigned int *pi) |
252b5132 | 3677 | { |
3882b010 | 3678 | if (! ISDIGIT (**pp)) |
b34976b6 | 3679 | return FALSE; |
252b5132 RH |
3680 | |
3681 | *pi = **pp - '0'; | |
3682 | ++*pp; | |
3882b010 | 3683 | if (ISDIGIT (**pp)) |
252b5132 RH |
3684 | { |
3685 | unsigned int count; | |
3686 | const char *p; | |
3687 | ||
3688 | count = *pi; | |
3689 | p = *pp; | |
3690 | do | |
3691 | { | |
3692 | count *= 10; | |
3693 | count += *p - '0'; | |
3694 | ++p; | |
3695 | } | |
3882b010 | 3696 | while (ISDIGIT (*p)); |
252b5132 RH |
3697 | if (*p == '_') |
3698 | { | |
3699 | *pp = p + 1; | |
3700 | *pi = count; | |
3701 | } | |
3702 | } | |
3703 | ||
b34976b6 | 3704 | return TRUE; |
252b5132 RH |
3705 | } |
3706 | ||
3707 | /* This function demangles a physical name, returning a NULL | |
3708 | terminated array of argument types. */ | |
3709 | ||
3710 | static debug_type * | |
2da42df6 AJ |
3711 | stab_demangle_argtypes (void *dhandle, struct stab_handle *info, |
3712 | const char *physname, bfd_boolean *pvarargs, | |
3713 | unsigned int physname_len) | |
252b5132 RH |
3714 | { |
3715 | struct stab_demangle_info minfo; | |
3716 | ||
041821e6 ILT |
3717 | /* Check for the g++ V3 ABI. */ |
3718 | if (physname[0] == '_' && physname[1] == 'Z') | |
3719 | return stab_demangle_v3_argtypes (dhandle, info, physname, pvarargs); | |
3720 | ||
252b5132 RH |
3721 | minfo.dhandle = dhandle; |
3722 | minfo.info = info; | |
3723 | minfo.args = NULL; | |
b34976b6 | 3724 | minfo.varargs = FALSE; |
252b5132 RH |
3725 | minfo.typestring_alloc = 10; |
3726 | minfo.typestrings = ((struct stab_demangle_typestring *) | |
3727 | xmalloc (minfo.typestring_alloc | |
3728 | * sizeof *minfo.typestrings)); | |
3729 | minfo.typestring_count = 0; | |
3730 | ||
3731 | /* cplus_demangle checks for special GNU mangled forms, but we can't | |
3732 | see any of them in mangled method argument types. */ | |
3733 | ||
4b73ca92 | 3734 | if (! stab_demangle_prefix (&minfo, &physname, physname_len)) |
252b5132 RH |
3735 | goto error_return; |
3736 | ||
3737 | if (*physname != '\0') | |
3738 | { | |
3739 | if (! stab_demangle_signature (&minfo, &physname)) | |
3740 | goto error_return; | |
3741 | } | |
3742 | ||
3743 | free (minfo.typestrings); | |
3744 | minfo.typestrings = NULL; | |
3745 | ||
3746 | if (minfo.args == NULL) | |
3747 | fprintf (stderr, _("no argument types in mangled string\n")); | |
3748 | ||
3749 | *pvarargs = minfo.varargs; | |
3750 | return minfo.args; | |
3751 | ||
3752 | error_return: | |
3753 | if (minfo.typestrings != NULL) | |
3754 | free (minfo.typestrings); | |
3755 | return NULL; | |
3756 | } | |
3757 | ||
3758 | /* Demangle the prefix of the mangled name. */ | |
3759 | ||
b34976b6 | 3760 | static bfd_boolean |
2da42df6 AJ |
3761 | stab_demangle_prefix (struct stab_demangle_info *minfo, const char **pp, |
3762 | unsigned int physname_len) | |
252b5132 RH |
3763 | { |
3764 | const char *scan; | |
3765 | unsigned int i; | |
3766 | ||
3767 | /* cplus_demangle checks for global constructors and destructors, | |
3768 | but we can't see them in mangled argument types. */ | |
3769 | ||
4b73ca92 NC |
3770 | if (physname_len) |
3771 | scan = *pp + physname_len; | |
3772 | else | |
252b5132 | 3773 | { |
4b73ca92 NC |
3774 | /* Look for `__'. */ |
3775 | scan = *pp; | |
3776 | do | |
3777 | scan = strchr (scan, '_'); | |
3778 | while (scan != NULL && *++scan != '_'); | |
252b5132 | 3779 | |
4b73ca92 NC |
3780 | if (scan == NULL) |
3781 | { | |
3782 | stab_bad_demangle (*pp); | |
b34976b6 | 3783 | return FALSE; |
4b73ca92 | 3784 | } |
252b5132 | 3785 | |
4b73ca92 | 3786 | --scan; |
252b5132 | 3787 | |
4b73ca92 NC |
3788 | /* We found `__'; move ahead to the last contiguous `__' pair. */ |
3789 | i = strspn (scan, "_"); | |
3790 | if (i > 2) | |
3791 | scan += i - 2; | |
3792 | } | |
252b5132 RH |
3793 | |
3794 | if (scan == *pp | |
3882b010 | 3795 | && (ISDIGIT (scan[2]) |
252b5132 RH |
3796 | || scan[2] == 'Q' |
3797 | || scan[2] == 't')) | |
3798 | { | |
3799 | /* This is a GNU style constructor name. */ | |
3800 | *pp = scan + 2; | |
b34976b6 | 3801 | return TRUE; |
252b5132 RH |
3802 | } |
3803 | else if (scan == *pp | |
3882b010 | 3804 | && ! ISDIGIT (scan[2]) |
252b5132 RH |
3805 | && scan[2] != 't') |
3806 | { | |
3807 | /* Look for the `__' that separates the prefix from the | |
3808 | signature. */ | |
3809 | while (*scan == '_') | |
3810 | ++scan; | |
3811 | scan = strstr (scan, "__"); | |
3812 | if (scan == NULL || scan[2] == '\0') | |
3813 | { | |
3814 | stab_bad_demangle (*pp); | |
b34976b6 | 3815 | return FALSE; |
252b5132 RH |
3816 | } |
3817 | ||
3818 | return stab_demangle_function_name (minfo, pp, scan); | |
3819 | } | |
3820 | else if (scan[2] != '\0') | |
3821 | { | |
3822 | /* The name doesn't start with `__', but it does contain `__'. */ | |
3823 | return stab_demangle_function_name (minfo, pp, scan); | |
3824 | } | |
3825 | else | |
3826 | { | |
3827 | stab_bad_demangle (*pp); | |
b34976b6 | 3828 | return FALSE; |
252b5132 RH |
3829 | } |
3830 | /*NOTREACHED*/ | |
3831 | } | |
3832 | ||
3833 | /* Demangle a function name prefix. The scan argument points to the | |
3834 | double underscore which separates the function name from the | |
3835 | signature. */ | |
3836 | ||
b34976b6 | 3837 | static bfd_boolean |
2da42df6 AJ |
3838 | stab_demangle_function_name (struct stab_demangle_info *minfo, |
3839 | const char **pp, const char *scan) | |
252b5132 RH |
3840 | { |
3841 | const char *name; | |
3842 | ||
3843 | /* The string from *pp to scan is the name of the function. We | |
3844 | don't care about the name, since we just looking for argument | |
3845 | types. However, for conversion operators, the name may include a | |
3846 | type which we must remember in order to handle backreferences. */ | |
3847 | ||
3848 | name = *pp; | |
3849 | *pp = scan + 2; | |
3850 | ||
3851 | if (*pp - name >= 5 | |
0112cd26 | 3852 | && CONST_STRNEQ (name, "type") |
252b5132 RH |
3853 | && (name[4] == '$' || name[4] == '.')) |
3854 | { | |
3855 | const char *tem; | |
3856 | ||
3857 | /* This is a type conversion operator. */ | |
3858 | tem = name + 5; | |
3859 | if (! stab_demangle_type (minfo, &tem, (debug_type *) NULL)) | |
b34976b6 | 3860 | return FALSE; |
252b5132 RH |
3861 | } |
3862 | else if (name[0] == '_' | |
3863 | && name[1] == '_' | |
3864 | && name[2] == 'o' | |
3865 | && name[3] == 'p') | |
3866 | { | |
3867 | const char *tem; | |
3868 | ||
3869 | /* This is a type conversion operator. */ | |
3870 | tem = name + 4; | |
3871 | if (! stab_demangle_type (minfo, &tem, (debug_type *) NULL)) | |
b34976b6 | 3872 | return FALSE; |
252b5132 RH |
3873 | } |
3874 | ||
b34976b6 | 3875 | return TRUE; |
252b5132 RH |
3876 | } |
3877 | ||
3878 | /* Demangle the signature. This is where the argument types are | |
3879 | found. */ | |
3880 | ||
b34976b6 | 3881 | static bfd_boolean |
2da42df6 | 3882 | stab_demangle_signature (struct stab_demangle_info *minfo, const char **pp) |
252b5132 RH |
3883 | { |
3884 | const char *orig; | |
b34976b6 | 3885 | bfd_boolean expect_func, func_done; |
252b5132 RH |
3886 | const char *hold; |
3887 | ||
3888 | orig = *pp; | |
3889 | ||
b34976b6 AM |
3890 | expect_func = FALSE; |
3891 | func_done = FALSE; | |
252b5132 RH |
3892 | hold = NULL; |
3893 | ||
3894 | while (**pp != '\0') | |
3895 | { | |
3896 | switch (**pp) | |
3897 | { | |
3898 | case 'Q': | |
3899 | hold = *pp; | |
3900 | if (! stab_demangle_qualified (minfo, pp, (debug_type *) NULL) | |
3901 | || ! stab_demangle_remember_type (minfo, hold, *pp - hold)) | |
b34976b6 AM |
3902 | return FALSE; |
3903 | expect_func = TRUE; | |
252b5132 RH |
3904 | hold = NULL; |
3905 | break; | |
3906 | ||
3907 | case 'S': | |
3908 | /* Static member function. FIXME: Can this happen? */ | |
3909 | if (hold == NULL) | |
3910 | hold = *pp; | |
3911 | ++*pp; | |
3912 | break; | |
3913 | ||
3914 | case 'C': | |
3915 | /* Const member function. */ | |
3916 | if (hold == NULL) | |
3917 | hold = *pp; | |
3918 | ++*pp; | |
3919 | break; | |
3920 | ||
3921 | case '0': case '1': case '2': case '3': case '4': | |
3922 | case '5': case '6': case '7': case '8': case '9': | |
3923 | if (hold == NULL) | |
3924 | hold = *pp; | |
3925 | if (! stab_demangle_class (minfo, pp, (const char **) NULL) | |
3926 | || ! stab_demangle_remember_type (minfo, hold, *pp - hold)) | |
b34976b6 AM |
3927 | return FALSE; |
3928 | expect_func = TRUE; | |
252b5132 RH |
3929 | hold = NULL; |
3930 | break; | |
3931 | ||
3932 | case 'F': | |
3933 | /* Function. I don't know if this actually happens with g++ | |
3934 | output. */ | |
3935 | hold = NULL; | |
b34976b6 | 3936 | func_done = TRUE; |
252b5132 RH |
3937 | ++*pp; |
3938 | if (! stab_demangle_args (minfo, pp, &minfo->args, &minfo->varargs)) | |
b34976b6 | 3939 | return FALSE; |
252b5132 RH |
3940 | break; |
3941 | ||
3942 | case 't': | |
3943 | /* Template. */ | |
3944 | if (hold == NULL) | |
3945 | hold = *pp; | |
3946 | if (! stab_demangle_template (minfo, pp, (char **) NULL) | |
3947 | || ! stab_demangle_remember_type (minfo, hold, *pp - hold)) | |
b34976b6 | 3948 | return FALSE; |
252b5132 | 3949 | hold = NULL; |
b34976b6 | 3950 | expect_func = TRUE; |
252b5132 RH |
3951 | break; |
3952 | ||
3953 | case '_': | |
3954 | /* At the outermost level, we cannot have a return type | |
3955 | specified, so if we run into another '_' at this point we | |
3956 | are dealing with a mangled name that is either bogus, or | |
3957 | has been mangled by some algorithm we don't know how to | |
3958 | deal with. So just reject the entire demangling. */ | |
3959 | stab_bad_demangle (orig); | |
b34976b6 | 3960 | return FALSE; |
252b5132 RH |
3961 | |
3962 | default: | |
3963 | /* Assume we have stumbled onto the first outermost function | |
3964 | argument token, and start processing args. */ | |
b34976b6 | 3965 | func_done = TRUE; |
252b5132 | 3966 | if (! stab_demangle_args (minfo, pp, &minfo->args, &minfo->varargs)) |
b34976b6 | 3967 | return FALSE; |
252b5132 RH |
3968 | break; |
3969 | } | |
3970 | ||
3971 | if (expect_func) | |
3972 | { | |
b34976b6 | 3973 | func_done = TRUE; |
252b5132 | 3974 | if (! stab_demangle_args (minfo, pp, &minfo->args, &minfo->varargs)) |
b34976b6 | 3975 | return FALSE; |
252b5132 RH |
3976 | } |
3977 | } | |
3978 | ||
3979 | if (! func_done) | |
3980 | { | |
3981 | /* With GNU style demangling, bar__3foo is 'foo::bar(void)', and | |
3982 | bar__3fooi is 'foo::bar(int)'. We get here when we find the | |
3983 | first case, and need to ensure that the '(void)' gets added | |
3984 | to the current declp. */ | |
3985 | if (! stab_demangle_args (minfo, pp, &minfo->args, &minfo->varargs)) | |
b34976b6 | 3986 | return FALSE; |
252b5132 RH |
3987 | } |
3988 | ||
b34976b6 | 3989 | return TRUE; |
252b5132 RH |
3990 | } |
3991 | ||
3992 | /* Demangle a qualified name, such as "Q25Outer5Inner" which is the | |
3993 | mangled form of "Outer::Inner". */ | |
3994 | ||
b34976b6 | 3995 | static bfd_boolean |
2da42df6 AJ |
3996 | stab_demangle_qualified (struct stab_demangle_info *minfo, const char **pp, |
3997 | debug_type *ptype) | |
252b5132 RH |
3998 | { |
3999 | const char *orig; | |
4000 | const char *p; | |
4001 | unsigned int qualifiers; | |
4002 | debug_type context; | |
4003 | ||
4004 | orig = *pp; | |
4005 | ||
4006 | switch ((*pp)[1]) | |
4007 | { | |
4008 | case '_': | |
4009 | /* GNU mangled name with more than 9 classes. The count is | |
4010 | preceded by an underscore (to distinguish it from the <= 9 | |
4011 | case) and followed by an underscore. */ | |
4012 | p = *pp + 2; | |
3882b010 | 4013 | if (! ISDIGIT (*p) || *p == '0') |
252b5132 RH |
4014 | { |
4015 | stab_bad_demangle (orig); | |
b34976b6 | 4016 | return FALSE; |
252b5132 RH |
4017 | } |
4018 | qualifiers = atoi (p); | |
3882b010 | 4019 | while (ISDIGIT (*p)) |
252b5132 RH |
4020 | ++p; |
4021 | if (*p != '_') | |
4022 | { | |
4023 | stab_bad_demangle (orig); | |
b34976b6 | 4024 | return FALSE; |
252b5132 RH |
4025 | } |
4026 | *pp = p + 1; | |
4027 | break; | |
4028 | ||
4029 | case '1': case '2': case '3': case '4': case '5': | |
4030 | case '6': case '7': case '8': case '9': | |
4031 | qualifiers = (*pp)[1] - '0'; | |
4032 | /* Skip an optional underscore after the count. */ | |
4033 | if ((*pp)[2] == '_') | |
4034 | ++*pp; | |
4035 | *pp += 2; | |
4036 | break; | |
4037 | ||
4038 | case '0': | |
4039 | default: | |
4040 | stab_bad_demangle (orig); | |
b34976b6 | 4041 | return FALSE; |
252b5132 RH |
4042 | } |
4043 | ||
4044 | context = DEBUG_TYPE_NULL; | |
4045 | ||
4046 | /* Pick off the names. */ | |
4047 | while (qualifiers-- > 0) | |
4048 | { | |
4049 | if (**pp == '_') | |
4050 | ++*pp; | |
4051 | if (**pp == 't') | |
4052 | { | |
4053 | char *name; | |
4054 | ||
4055 | if (! stab_demangle_template (minfo, pp, | |
4056 | ptype != NULL ? &name : NULL)) | |
b34976b6 | 4057 | return FALSE; |
252b5132 RH |
4058 | |
4059 | if (ptype != NULL) | |
4060 | { | |
4061 | context = stab_find_tagged_type (minfo->dhandle, minfo->info, | |
4062 | name, strlen (name), | |
4063 | DEBUG_KIND_CLASS); | |
4064 | free (name); | |
4065 | if (context == DEBUG_TYPE_NULL) | |
b34976b6 | 4066 | return FALSE; |
252b5132 RH |
4067 | } |
4068 | } | |
4069 | else | |
4070 | { | |
4071 | unsigned int len; | |
4072 | ||
4073 | len = stab_demangle_count (pp); | |
4074 | if (strlen (*pp) < len) | |
4075 | { | |
4076 | stab_bad_demangle (orig); | |
b34976b6 | 4077 | return FALSE; |
252b5132 RH |
4078 | } |
4079 | ||
4080 | if (ptype != NULL) | |
4081 | { | |
4082 | const debug_field *fields; | |
4083 | ||
4084 | fields = NULL; | |
4085 | if (context != DEBUG_TYPE_NULL) | |
4086 | fields = debug_get_fields (minfo->dhandle, context); | |
4087 | ||
4088 | context = DEBUG_TYPE_NULL; | |
4089 | ||
4090 | if (fields != NULL) | |
4091 | { | |
4092 | char *name; | |
4093 | ||
4094 | /* Try to find the type by looking through the | |
4095 | fields of context until we find a field with the | |
4096 | same type. This ought to work for a class | |
4097 | defined within a class, but it won't work for, | |
4098 | e.g., an enum defined within a class. stabs does | |
4099 | not give us enough information to figure out the | |
4100 | latter case. */ | |
4101 | ||
4102 | name = savestring (*pp, len); | |
4103 | ||
4104 | for (; *fields != DEBUG_FIELD_NULL; fields++) | |
4105 | { | |
4106 | debug_type ft; | |
4107 | const char *dn; | |
4108 | ||
4109 | ft = debug_get_field_type (minfo->dhandle, *fields); | |
4110 | if (ft == NULL) | |
b34976b6 | 4111 | return FALSE; |
252b5132 RH |
4112 | dn = debug_get_type_name (minfo->dhandle, ft); |
4113 | if (dn != NULL && strcmp (dn, name) == 0) | |
4114 | { | |
4115 | context = ft; | |
4116 | break; | |
4117 | } | |
4118 | } | |
4119 | ||
4120 | free (name); | |
4121 | } | |
4122 | ||
4123 | if (context == DEBUG_TYPE_NULL) | |
4124 | { | |
4125 | /* We have to fall back on finding the type by name. | |
4126 | If there are more types to come, then this must | |
4127 | be a class. Otherwise, it could be anything. */ | |
4128 | ||
4129 | if (qualifiers == 0) | |
4130 | { | |
4131 | char *name; | |
4132 | ||
4133 | name = savestring (*pp, len); | |
4134 | context = debug_find_named_type (minfo->dhandle, | |
4135 | name); | |
4136 | free (name); | |
4137 | } | |
4138 | ||
4139 | if (context == DEBUG_TYPE_NULL) | |
4140 | { | |
4141 | context = stab_find_tagged_type (minfo->dhandle, | |
4142 | minfo->info, | |
4143 | *pp, len, | |
4144 | (qualifiers == 0 | |
4145 | ? DEBUG_KIND_ILLEGAL | |
4146 | : DEBUG_KIND_CLASS)); | |
4147 | if (context == DEBUG_TYPE_NULL) | |
b34976b6 | 4148 | return FALSE; |
252b5132 RH |
4149 | } |
4150 | } | |
4151 | } | |
4152 | ||
4153 | *pp += len; | |
4154 | } | |
4155 | } | |
4156 | ||
4157 | if (ptype != NULL) | |
4158 | *ptype = context; | |
4159 | ||
b34976b6 | 4160 | return TRUE; |
252b5132 RH |
4161 | } |
4162 | ||
4163 | /* Demangle a template. If PNAME is not NULL, this sets *PNAME to a | |
4164 | string representation of the template. */ | |
4165 | ||
b34976b6 | 4166 | static bfd_boolean |
2da42df6 AJ |
4167 | stab_demangle_template (struct stab_demangle_info *minfo, const char **pp, |
4168 | char **pname) | |
252b5132 RH |
4169 | { |
4170 | const char *orig; | |
4171 | unsigned int r, i; | |
4172 | ||
4173 | orig = *pp; | |
4174 | ||
4175 | ++*pp; | |
4176 | ||
4177 | /* Skip the template name. */ | |
4178 | r = stab_demangle_count (pp); | |
4179 | if (r == 0 || strlen (*pp) < r) | |
4180 | { | |
4181 | stab_bad_demangle (orig); | |
b34976b6 | 4182 | return FALSE; |
252b5132 RH |
4183 | } |
4184 | *pp += r; | |
4185 | ||
4186 | /* Get the size of the parameter list. */ | |
4187 | if (stab_demangle_get_count (pp, &r) == 0) | |
4188 | { | |
4189 | stab_bad_demangle (orig); | |
b34976b6 | 4190 | return FALSE; |
252b5132 RH |
4191 | } |
4192 | ||
4193 | for (i = 0; i < r; i++) | |
4194 | { | |
4195 | if (**pp == 'Z') | |
4196 | { | |
4197 | /* This is a type parameter. */ | |
4198 | ++*pp; | |
4199 | if (! stab_demangle_type (minfo, pp, (debug_type *) NULL)) | |
b34976b6 | 4200 | return FALSE; |
252b5132 RH |
4201 | } |
4202 | else | |
4203 | { | |
4204 | const char *old_p; | |
b34976b6 AM |
4205 | bfd_boolean pointerp, realp, integralp, charp, boolp; |
4206 | bfd_boolean done; | |
252b5132 RH |
4207 | |
4208 | old_p = *pp; | |
b34976b6 AM |
4209 | pointerp = FALSE; |
4210 | realp = FALSE; | |
4211 | integralp = FALSE; | |
4212 | charp = FALSE; | |
4213 | boolp = FALSE; | |
4214 | done = FALSE; | |
252b5132 RH |
4215 | |
4216 | /* This is a value parameter. */ | |
4217 | ||
4218 | if (! stab_demangle_type (minfo, pp, (debug_type *) NULL)) | |
b34976b6 | 4219 | return FALSE; |
252b5132 RH |
4220 | |
4221 | while (*old_p != '\0' && ! done) | |
4222 | { | |
4223 | switch (*old_p) | |
4224 | { | |
4225 | case 'P': | |
4226 | case 'p': | |
4227 | case 'R': | |
b34976b6 AM |
4228 | pointerp = TRUE; |
4229 | done = TRUE; | |
252b5132 RH |
4230 | break; |
4231 | case 'C': /* Const. */ | |
4232 | case 'S': /* Signed. */ | |
4233 | case 'U': /* Unsigned. */ | |
4234 | case 'V': /* Volatile. */ | |
4235 | case 'F': /* Function. */ | |
4236 | case 'M': /* Member function. */ | |
4237 | case 'O': /* ??? */ | |
4238 | ++old_p; | |
4239 | break; | |
4240 | case 'Q': /* Qualified name. */ | |
b34976b6 AM |
4241 | integralp = TRUE; |
4242 | done = TRUE; | |
252b5132 RH |
4243 | break; |
4244 | case 'T': /* Remembered type. */ | |
4245 | abort (); | |
4246 | case 'v': /* Void. */ | |
4247 | abort (); | |
4248 | case 'x': /* Long long. */ | |
4249 | case 'l': /* Long. */ | |
4250 | case 'i': /* Int. */ | |
4251 | case 's': /* Short. */ | |
4252 | case 'w': /* Wchar_t. */ | |
b34976b6 AM |
4253 | integralp = TRUE; |
4254 | done = TRUE; | |
252b5132 RH |
4255 | break; |
4256 | case 'b': /* Bool. */ | |
b34976b6 AM |
4257 | boolp = TRUE; |
4258 | done = TRUE; | |
252b5132 RH |
4259 | break; |
4260 | case 'c': /* Char. */ | |
b34976b6 AM |
4261 | charp = TRUE; |
4262 | done = TRUE; | |
252b5132 RH |
4263 | break; |
4264 | case 'r': /* Long double. */ | |
4265 | case 'd': /* Double. */ | |
4266 | case 'f': /* Float. */ | |
b34976b6 AM |
4267 | realp = TRUE; |
4268 | done = TRUE; | |
252b5132 RH |
4269 | break; |
4270 | default: | |
4271 | /* Assume it's a user defined integral type. */ | |
b34976b6 AM |
4272 | integralp = TRUE; |
4273 | done = TRUE; | |
252b5132 RH |
4274 | break; |
4275 | } | |
4276 | } | |
4277 | ||
4278 | if (integralp) | |
4279 | { | |
4280 | if (**pp == 'm') | |
4281 | ++*pp; | |
3882b010 | 4282 | while (ISDIGIT (**pp)) |
252b5132 RH |
4283 | ++*pp; |
4284 | } | |
4285 | else if (charp) | |
4286 | { | |
4287 | unsigned int val; | |
4288 | ||
4289 | if (**pp == 'm') | |
4290 | ++*pp; | |
4291 | val = stab_demangle_count (pp); | |
4292 | if (val == 0) | |
4293 | { | |
4294 | stab_bad_demangle (orig); | |
b34976b6 | 4295 | return FALSE; |
252b5132 RH |
4296 | } |
4297 | } | |
4298 | else if (boolp) | |
4299 | { | |
4300 | unsigned int val; | |
4301 | ||
4302 | val = stab_demangle_count (pp); | |
4303 | if (val != 0 && val != 1) | |
4304 | { | |
4305 | stab_bad_demangle (orig); | |
b34976b6 | 4306 | return FALSE; |
252b5132 RH |
4307 | } |
4308 | } | |
4309 | else if (realp) | |
4310 | { | |
4311 | if (**pp == 'm') | |
4312 | ++*pp; | |
3882b010 | 4313 | while (ISDIGIT (**pp)) |
252b5132 RH |
4314 | ++*pp; |
4315 | if (**pp == '.') | |
4316 | { | |
4317 | ++*pp; | |
3882b010 | 4318 | while (ISDIGIT (**pp)) |
252b5132 RH |
4319 | ++*pp; |
4320 | } | |
4321 | if (**pp == 'e') | |
4322 | { | |
4323 | ++*pp; | |
3882b010 | 4324 | while (ISDIGIT (**pp)) |
252b5132 RH |
4325 | ++*pp; |
4326 | } | |
4327 | } | |
4328 | else if (pointerp) | |
4329 | { | |
4330 | unsigned int len; | |
4331 | ||
2b25cacb ILT |
4332 | len = stab_demangle_count (pp); |
4333 | if (len == 0) | |
252b5132 RH |
4334 | { |
4335 | stab_bad_demangle (orig); | |
b34976b6 | 4336 | return FALSE; |
252b5132 RH |
4337 | } |
4338 | *pp += len; | |
4339 | } | |
4340 | } | |
4341 | } | |
4342 | ||
4343 | /* We can translate this to a string fairly easily by invoking the | |
4344 | regular demangling routine. */ | |
4345 | if (pname != NULL) | |
4346 | { | |
d81d6584 | 4347 | char *s1, *s2, *s3, *s4 = NULL; |
252b5132 RH |
4348 | char *from, *to; |
4349 | ||
4350 | s1 = savestring (orig, *pp - orig); | |
4351 | ||
4352 | s2 = concat ("NoSuchStrinG__", s1, (const char *) NULL); | |
4353 | ||
4354 | free (s1); | |
4355 | ||
4356 | s3 = cplus_demangle (s2, DMGL_ANSI); | |
4357 | ||
4358 | free (s2); | |
4359 | ||
4360 | if (s3 != NULL) | |
4361 | s4 = strstr (s3, "::NoSuchStrinG"); | |
4362 | if (s3 == NULL || s4 == NULL) | |
4363 | { | |
4364 | stab_bad_demangle (orig); | |
4365 | if (s3 != NULL) | |
4366 | free (s3); | |
b34976b6 | 4367 | return FALSE; |
252b5132 RH |
4368 | } |
4369 | ||
4370 | /* Eliminating all spaces, except those between > characters, | |
4371 | makes it more likely that the demangled name will match the | |
4372 | name which g++ used as the structure name. */ | |
4373 | for (from = to = s3; from != s4; ++from) | |
4374 | if (*from != ' ' | |
4375 | || (from[1] == '>' && from > s3 && from[-1] == '>')) | |
4376 | *to++ = *from; | |
4377 | ||
4378 | *pname = savestring (s3, to - s3); | |
4379 | ||
4380 | free (s3); | |
4381 | } | |
4382 | ||
b34976b6 | 4383 | return TRUE; |
252b5132 RH |
4384 | } |
4385 | ||
4386 | /* Demangle a class name. */ | |
4387 | ||
b34976b6 | 4388 | static bfd_boolean |
2da42df6 AJ |
4389 | stab_demangle_class (struct stab_demangle_info *minfo ATTRIBUTE_UNUSED, |
4390 | const char **pp, const char **pstart) | |
252b5132 RH |
4391 | { |
4392 | const char *orig; | |
4393 | unsigned int n; | |
4394 | ||
4395 | orig = *pp; | |
4396 | ||
4397 | n = stab_demangle_count (pp); | |
4398 | if (strlen (*pp) < n) | |
4399 | { | |
4400 | stab_bad_demangle (orig); | |
b34976b6 | 4401 | return FALSE; |
252b5132 RH |
4402 | } |
4403 | ||
4404 | if (pstart != NULL) | |
4405 | *pstart = *pp; | |
4406 | ||
4407 | *pp += n; | |
4408 | ||
b34976b6 | 4409 | return TRUE; |
252b5132 RH |
4410 | } |
4411 | ||
4412 | /* Demangle function arguments. If the pargs argument is not NULL, it | |
4413 | is set to a NULL terminated array holding the arguments. */ | |
4414 | ||
b34976b6 | 4415 | static bfd_boolean |
2da42df6 AJ |
4416 | stab_demangle_args (struct stab_demangle_info *minfo, const char **pp, |
4417 | debug_type **pargs, bfd_boolean *pvarargs) | |
252b5132 RH |
4418 | { |
4419 | const char *orig; | |
4420 | unsigned int alloc, count; | |
4421 | ||
4422 | orig = *pp; | |
4423 | ||
4424 | alloc = 10; | |
4425 | if (pargs != NULL) | |
4426 | { | |
4427 | *pargs = (debug_type *) xmalloc (alloc * sizeof **pargs); | |
b34976b6 | 4428 | *pvarargs = FALSE; |
252b5132 RH |
4429 | } |
4430 | count = 0; | |
4431 | ||
4432 | while (**pp != '_' && **pp != '\0' && **pp != 'e') | |
4433 | { | |
4434 | if (**pp == 'N' || **pp == 'T') | |
4435 | { | |
4436 | char temptype; | |
4437 | unsigned int r, t; | |
4438 | ||
4439 | temptype = **pp; | |
4440 | ++*pp; | |
4441 | ||
4442 | if (temptype == 'T') | |
4443 | r = 1; | |
4444 | else | |
4445 | { | |
4446 | if (! stab_demangle_get_count (pp, &r)) | |
4447 | { | |
4448 | stab_bad_demangle (orig); | |
b34976b6 | 4449 | return FALSE; |
252b5132 RH |
4450 | } |
4451 | } | |
4452 | ||
4453 | if (! stab_demangle_get_count (pp, &t)) | |
4454 | { | |
4455 | stab_bad_demangle (orig); | |
b34976b6 | 4456 | return FALSE; |
252b5132 RH |
4457 | } |
4458 | ||
4459 | if (t >= minfo->typestring_count) | |
4460 | { | |
4461 | stab_bad_demangle (orig); | |
b34976b6 | 4462 | return FALSE; |
252b5132 RH |
4463 | } |
4464 | while (r-- > 0) | |
4465 | { | |
4466 | const char *tem; | |
4467 | ||
4468 | tem = minfo->typestrings[t].typestring; | |
4469 | if (! stab_demangle_arg (minfo, &tem, pargs, &count, &alloc)) | |
b34976b6 | 4470 | return FALSE; |
252b5132 RH |
4471 | } |
4472 | } | |
4473 | else | |
4474 | { | |
4475 | if (! stab_demangle_arg (minfo, pp, pargs, &count, &alloc)) | |
b34976b6 | 4476 | return FALSE; |
252b5132 RH |
4477 | } |
4478 | } | |
4479 | ||
4480 | if (pargs != NULL) | |
4481 | (*pargs)[count] = DEBUG_TYPE_NULL; | |
4482 | ||
4483 | if (**pp == 'e') | |
4484 | { | |
4485 | if (pargs != NULL) | |
b34976b6 | 4486 | *pvarargs = TRUE; |
252b5132 RH |
4487 | ++*pp; |
4488 | } | |
4489 | ||
b34976b6 | 4490 | return TRUE; |
252b5132 RH |
4491 | } |
4492 | ||
4493 | /* Demangle a single argument. */ | |
4494 | ||
b34976b6 | 4495 | static bfd_boolean |
2da42df6 AJ |
4496 | stab_demangle_arg (struct stab_demangle_info *minfo, const char **pp, |
4497 | debug_type **pargs, unsigned int *pcount, | |
4498 | unsigned int *palloc) | |
252b5132 RH |
4499 | { |
4500 | const char *start; | |
4501 | debug_type type; | |
4502 | ||
4503 | start = *pp; | |
4504 | if (! stab_demangle_type (minfo, pp, | |
4505 | pargs == NULL ? (debug_type *) NULL : &type) | |
4506 | || ! stab_demangle_remember_type (minfo, start, *pp - start)) | |
b34976b6 | 4507 | return FALSE; |
252b5132 RH |
4508 | |
4509 | if (pargs != NULL) | |
4510 | { | |
4511 | if (type == DEBUG_TYPE_NULL) | |
b34976b6 | 4512 | return FALSE; |
252b5132 RH |
4513 | |
4514 | if (*pcount + 1 >= *palloc) | |
4515 | { | |
4516 | *palloc += 10; | |
4517 | *pargs = ((debug_type *) | |
4518 | xrealloc (*pargs, *palloc * sizeof **pargs)); | |
4519 | } | |
4520 | (*pargs)[*pcount] = type; | |
4521 | ++*pcount; | |
4522 | } | |
4523 | ||
b34976b6 | 4524 | return TRUE; |
252b5132 RH |
4525 | } |
4526 | ||
4527 | /* Demangle a type. If the ptype argument is not NULL, *ptype is set | |
4528 | to the newly allocated type. */ | |
4529 | ||
b34976b6 | 4530 | static bfd_boolean |
2da42df6 AJ |
4531 | stab_demangle_type (struct stab_demangle_info *minfo, const char **pp, |
4532 | debug_type *ptype) | |
252b5132 RH |
4533 | { |
4534 | const char *orig; | |
4535 | ||
4536 | orig = *pp; | |
4537 | ||
4538 | switch (**pp) | |
4539 | { | |
4540 | case 'P': | |
4541 | case 'p': | |
4542 | /* A pointer type. */ | |
4543 | ++*pp; | |
4544 | if (! stab_demangle_type (minfo, pp, ptype)) | |
b34976b6 | 4545 | return FALSE; |
252b5132 RH |
4546 | if (ptype != NULL) |
4547 | *ptype = debug_make_pointer_type (minfo->dhandle, *ptype); | |
4548 | break; | |
4549 | ||
4550 | case 'R': | |
4551 | /* A reference type. */ | |
4552 | ++*pp; | |
4553 | if (! stab_demangle_type (minfo, pp, ptype)) | |
b34976b6 | 4554 | return FALSE; |
252b5132 RH |
4555 | if (ptype != NULL) |
4556 | *ptype = debug_make_reference_type (minfo->dhandle, *ptype); | |
4557 | break; | |
4558 | ||
4559 | case 'A': | |
4560 | /* An array. */ | |
4561 | { | |
4562 | unsigned long high; | |
4563 | ||
4564 | ++*pp; | |
4565 | high = 0; | |
4566 | while (**pp != '\0' && **pp != '_') | |
4567 | { | |
3882b010 | 4568 | if (! ISDIGIT (**pp)) |
252b5132 RH |
4569 | { |
4570 | stab_bad_demangle (orig); | |
b34976b6 | 4571 | return FALSE; |
252b5132 RH |
4572 | } |
4573 | high *= 10; | |
4574 | high += **pp - '0'; | |
4575 | ++*pp; | |
4576 | } | |
4577 | if (**pp != '_') | |
4578 | { | |
4579 | stab_bad_demangle (orig); | |
b34976b6 | 4580 | return FALSE; |
252b5132 RH |
4581 | } |
4582 | ++*pp; | |
4583 | ||
4584 | if (! stab_demangle_type (minfo, pp, ptype)) | |
b34976b6 | 4585 | return FALSE; |
252b5132 RH |
4586 | if (ptype != NULL) |
4587 | { | |
4588 | debug_type int_type; | |
4589 | ||
4590 | int_type = debug_find_named_type (minfo->dhandle, "int"); | |
4591 | if (int_type == NULL) | |
b34976b6 | 4592 | int_type = debug_make_int_type (minfo->dhandle, 4, FALSE); |
252b5132 | 4593 | *ptype = debug_make_array_type (minfo->dhandle, *ptype, int_type, |
b34976b6 | 4594 | 0, high, FALSE); |
252b5132 RH |
4595 | } |
4596 | } | |
4597 | break; | |
4598 | ||
4599 | case 'T': | |
4600 | /* A back reference to a remembered type. */ | |
4601 | { | |
4602 | unsigned int i; | |
4603 | const char *p; | |
4604 | ||
4605 | ++*pp; | |
4606 | if (! stab_demangle_get_count (pp, &i)) | |
4607 | { | |
4608 | stab_bad_demangle (orig); | |
b34976b6 | 4609 | return FALSE; |
252b5132 RH |
4610 | } |
4611 | if (i >= minfo->typestring_count) | |
4612 | { | |
4613 | stab_bad_demangle (orig); | |
b34976b6 | 4614 | return FALSE; |
252b5132 RH |
4615 | } |
4616 | p = minfo->typestrings[i].typestring; | |
4617 | if (! stab_demangle_type (minfo, &p, ptype)) | |
b34976b6 | 4618 | return FALSE; |
252b5132 RH |
4619 | } |
4620 | break; | |
4621 | ||
4622 | case 'F': | |
4623 | /* A function. */ | |
4624 | { | |
4625 | debug_type *args; | |
b34976b6 | 4626 | bfd_boolean varargs; |
252b5132 RH |
4627 | |
4628 | ++*pp; | |
4629 | if (! stab_demangle_args (minfo, pp, | |
4630 | (ptype == NULL | |
4631 | ? (debug_type **) NULL | |
4632 | : &args), | |
4633 | (ptype == NULL | |
b34976b6 | 4634 | ? (bfd_boolean *) NULL |
252b5132 | 4635 | : &varargs))) |
b34976b6 | 4636 | return FALSE; |
252b5132 RH |
4637 | if (**pp != '_') |
4638 | { | |
4639 | /* cplus_demangle will accept a function without a return | |
4640 | type, but I don't know when that will happen, or what | |
4641 | to do if it does. */ | |
4642 | stab_bad_demangle (orig); | |
b34976b6 | 4643 | return FALSE; |
252b5132 RH |
4644 | } |
4645 | ++*pp; | |
4646 | if (! stab_demangle_type (minfo, pp, ptype)) | |
b34976b6 | 4647 | return FALSE; |
252b5132 RH |
4648 | if (ptype != NULL) |
4649 | *ptype = debug_make_function_type (minfo->dhandle, *ptype, args, | |
4650 | varargs); | |
4651 | ||
4652 | } | |
4653 | break; | |
4654 | ||
4655 | case 'M': | |
4656 | case 'O': | |
4657 | { | |
3d540e93 | 4658 | bfd_boolean memberp; |
c602a165 | 4659 | debug_type class_type = DEBUG_TYPE_NULL; |
252b5132 | 4660 | debug_type *args; |
b34976b6 | 4661 | bfd_boolean varargs; |
252b5132 RH |
4662 | unsigned int n; |
4663 | const char *name; | |
4664 | ||
4665 | memberp = **pp == 'M'; | |
252b5132 | 4666 | args = NULL; |
b34976b6 | 4667 | varargs = FALSE; |
252b5132 RH |
4668 | |
4669 | ++*pp; | |
3882b010 | 4670 | if (ISDIGIT (**pp)) |
252b5132 | 4671 | { |
c602a165 ILT |
4672 | n = stab_demangle_count (pp); |
4673 | if (strlen (*pp) < n) | |
4674 | { | |
4675 | stab_bad_demangle (orig); | |
b34976b6 | 4676 | return FALSE; |
c602a165 ILT |
4677 | } |
4678 | name = *pp; | |
4679 | *pp += n; | |
4680 | ||
4681 | if (ptype != NULL) | |
4682 | { | |
4683 | class_type = stab_find_tagged_type (minfo->dhandle, | |
4684 | minfo->info, | |
4685 | name, (int) n, | |
4686 | DEBUG_KIND_CLASS); | |
4687 | if (class_type == DEBUG_TYPE_NULL) | |
b34976b6 | 4688 | return FALSE; |
c602a165 | 4689 | } |
252b5132 | 4690 | } |
c602a165 ILT |
4691 | else if (**pp == 'Q') |
4692 | { | |
4693 | if (! stab_demangle_qualified (minfo, pp, | |
4694 | (ptype == NULL | |
4695 | ? (debug_type *) NULL | |
4696 | : &class_type))) | |
b34976b6 | 4697 | return FALSE; |
c602a165 ILT |
4698 | } |
4699 | else | |
252b5132 RH |
4700 | { |
4701 | stab_bad_demangle (orig); | |
b34976b6 | 4702 | return FALSE; |
252b5132 | 4703 | } |
252b5132 RH |
4704 | |
4705 | if (memberp) | |
4706 | { | |
4707 | if (**pp == 'C') | |
4708 | { | |
252b5132 RH |
4709 | ++*pp; |
4710 | } | |
4711 | else if (**pp == 'V') | |
4712 | { | |
252b5132 RH |
4713 | ++*pp; |
4714 | } | |
4715 | if (**pp != 'F') | |
4716 | { | |
4717 | stab_bad_demangle (orig); | |
b34976b6 | 4718 | return FALSE; |
252b5132 RH |
4719 | } |
4720 | ++*pp; | |
4721 | if (! stab_demangle_args (minfo, pp, | |
4722 | (ptype == NULL | |
4723 | ? (debug_type **) NULL | |
4724 | : &args), | |
4725 | (ptype == NULL | |
b34976b6 | 4726 | ? (bfd_boolean *) NULL |
252b5132 | 4727 | : &varargs))) |
b34976b6 | 4728 | return FALSE; |
252b5132 RH |
4729 | } |
4730 | ||
4731 | if (**pp != '_') | |
4732 | { | |
4733 | stab_bad_demangle (orig); | |
b34976b6 | 4734 | return FALSE; |
252b5132 RH |
4735 | } |
4736 | ++*pp; | |
4737 | ||
4738 | if (! stab_demangle_type (minfo, pp, ptype)) | |
b34976b6 | 4739 | return FALSE; |
252b5132 RH |
4740 | |
4741 | if (ptype != NULL) | |
4742 | { | |
252b5132 RH |
4743 | if (! memberp) |
4744 | *ptype = debug_make_offset_type (minfo->dhandle, class_type, | |
4745 | *ptype); | |
4746 | else | |
4747 | { | |
4748 | /* FIXME: We have no way to record constp or | |
4749 | volatilep. */ | |
4750 | *ptype = debug_make_method_type (minfo->dhandle, *ptype, | |
4751 | class_type, args, varargs); | |
4752 | } | |
4753 | } | |
4754 | } | |
4755 | break; | |
4756 | ||
4757 | case 'G': | |
4758 | ++*pp; | |
4759 | if (! stab_demangle_type (minfo, pp, ptype)) | |
b34976b6 | 4760 | return FALSE; |
252b5132 RH |
4761 | break; |
4762 | ||
4763 | case 'C': | |
4764 | ++*pp; | |
4765 | if (! stab_demangle_type (minfo, pp, ptype)) | |
b34976b6 | 4766 | return FALSE; |
252b5132 RH |
4767 | if (ptype != NULL) |
4768 | *ptype = debug_make_const_type (minfo->dhandle, *ptype); | |
4769 | break; | |
4770 | ||
4771 | case 'Q': | |
4772 | { | |
252b5132 | 4773 | if (! stab_demangle_qualified (minfo, pp, ptype)) |
b34976b6 | 4774 | return FALSE; |
252b5132 RH |
4775 | } |
4776 | break; | |
4777 | ||
4778 | default: | |
4779 | if (! stab_demangle_fund_type (minfo, pp, ptype)) | |
b34976b6 | 4780 | return FALSE; |
252b5132 RH |
4781 | break; |
4782 | } | |
4783 | ||
b34976b6 | 4784 | return TRUE; |
252b5132 RH |
4785 | } |
4786 | ||
4787 | /* Demangle a fundamental type. If the ptype argument is not NULL, | |
4788 | *ptype is set to the newly allocated type. */ | |
4789 | ||
b34976b6 | 4790 | static bfd_boolean |
2da42df6 AJ |
4791 | stab_demangle_fund_type (struct stab_demangle_info *minfo, const char **pp, |
4792 | debug_type *ptype) | |
252b5132 RH |
4793 | { |
4794 | const char *orig; | |
b34976b6 AM |
4795 | bfd_boolean constp, volatilep, unsignedp, signedp; |
4796 | bfd_boolean done; | |
252b5132 RH |
4797 | |
4798 | orig = *pp; | |
4799 | ||
b34976b6 AM |
4800 | constp = FALSE; |
4801 | volatilep = FALSE; | |
4802 | unsignedp = FALSE; | |
4803 | signedp = FALSE; | |
252b5132 | 4804 | |
b34976b6 | 4805 | done = FALSE; |
252b5132 RH |
4806 | while (! done) |
4807 | { | |
4808 | switch (**pp) | |
4809 | { | |
4810 | case 'C': | |
b34976b6 | 4811 | constp = TRUE; |
252b5132 RH |
4812 | ++*pp; |
4813 | break; | |
4814 | ||
4815 | case 'U': | |
b34976b6 | 4816 | unsignedp = TRUE; |
252b5132 RH |
4817 | ++*pp; |
4818 | break; | |
4819 | ||
4820 | case 'S': | |
b34976b6 | 4821 | signedp = TRUE; |
252b5132 RH |
4822 | ++*pp; |
4823 | break; | |
4824 | ||
4825 | case 'V': | |
b34976b6 | 4826 | volatilep = TRUE; |
252b5132 RH |
4827 | ++*pp; |
4828 | break; | |
4829 | ||
4830 | default: | |
b34976b6 | 4831 | done = TRUE; |
252b5132 RH |
4832 | break; |
4833 | } | |
4834 | } | |
4835 | ||
4836 | switch (**pp) | |
4837 | { | |
4838 | case '\0': | |
4839 | case '_': | |
4840 | /* cplus_demangle permits this, but I don't know what it means. */ | |
4841 | stab_bad_demangle (orig); | |
4842 | break; | |
4843 | ||
4844 | case 'v': /* void */ | |
4845 | if (ptype != NULL) | |
4846 | { | |
4847 | *ptype = debug_find_named_type (minfo->dhandle, "void"); | |
4848 | if (*ptype == DEBUG_TYPE_NULL) | |
4849 | *ptype = debug_make_void_type (minfo->dhandle); | |
4850 | } | |
4851 | ++*pp; | |
4852 | break; | |
4853 | ||
4854 | case 'x': /* long long */ | |
4855 | if (ptype != NULL) | |
4856 | { | |
4857 | *ptype = debug_find_named_type (minfo->dhandle, | |
4858 | (unsignedp | |
4859 | ? "long long unsigned int" | |
4860 | : "long long int")); | |
4861 | if (*ptype == DEBUG_TYPE_NULL) | |
4862 | *ptype = debug_make_int_type (minfo->dhandle, 8, unsignedp); | |
4863 | } | |
4864 | ++*pp; | |
4865 | break; | |
4866 | ||
4867 | case 'l': /* long */ | |
4868 | if (ptype != NULL) | |
4869 | { | |
4870 | *ptype = debug_find_named_type (minfo->dhandle, | |
4871 | (unsignedp | |
4872 | ? "long unsigned int" | |
4873 | : "long int")); | |
4874 | if (*ptype == DEBUG_TYPE_NULL) | |
4875 | *ptype = debug_make_int_type (minfo->dhandle, 4, unsignedp); | |
4876 | } | |
4877 | ++*pp; | |
4878 | break; | |
4879 | ||
4880 | case 'i': /* int */ | |
4881 | if (ptype != NULL) | |
4882 | { | |
4883 | *ptype = debug_find_named_type (minfo->dhandle, | |
4884 | (unsignedp | |
4885 | ? "unsigned int" | |
4886 | : "int")); | |
4887 | if (*ptype == DEBUG_TYPE_NULL) | |
4888 | *ptype = debug_make_int_type (minfo->dhandle, 4, unsignedp); | |
4889 | } | |
4890 | ++*pp; | |
4891 | break; | |
4892 | ||
4893 | case 's': /* short */ | |
4894 | if (ptype != NULL) | |
4895 | { | |
4896 | *ptype = debug_find_named_type (minfo->dhandle, | |
4897 | (unsignedp | |
4898 | ? "short unsigned int" | |
4899 | : "short int")); | |
4900 | if (*ptype == DEBUG_TYPE_NULL) | |
4901 | *ptype = debug_make_int_type (minfo->dhandle, 2, unsignedp); | |
4902 | } | |
4903 | ++*pp; | |
4904 | break; | |
4905 | ||
4906 | case 'b': /* bool */ | |
4907 | if (ptype != NULL) | |
4908 | { | |
4909 | *ptype = debug_find_named_type (minfo->dhandle, "bool"); | |
4910 | if (*ptype == DEBUG_TYPE_NULL) | |
4911 | *ptype = debug_make_bool_type (minfo->dhandle, 4); | |
4912 | } | |
4913 | ++*pp; | |
4914 | break; | |
4915 | ||
4916 | case 'c': /* char */ | |
4917 | if (ptype != NULL) | |
4918 | { | |
4919 | *ptype = debug_find_named_type (minfo->dhandle, | |
4920 | (unsignedp | |
4921 | ? "unsigned char" | |
4922 | : (signedp | |
4923 | ? "signed char" | |
4924 | : "char"))); | |
4925 | if (*ptype == DEBUG_TYPE_NULL) | |
4926 | *ptype = debug_make_int_type (minfo->dhandle, 1, unsignedp); | |
4927 | } | |
4928 | ++*pp; | |
4929 | break; | |
4930 | ||
4931 | case 'w': /* wchar_t */ | |
4932 | if (ptype != NULL) | |
4933 | { | |
4934 | *ptype = debug_find_named_type (minfo->dhandle, "__wchar_t"); | |
4935 | if (*ptype == DEBUG_TYPE_NULL) | |
b34976b6 | 4936 | *ptype = debug_make_int_type (minfo->dhandle, 2, TRUE); |
252b5132 RH |
4937 | } |
4938 | ++*pp; | |
4939 | break; | |
4940 | ||
4941 | case 'r': /* long double */ | |
4942 | if (ptype != NULL) | |
4943 | { | |
4944 | *ptype = debug_find_named_type (minfo->dhandle, "long double"); | |
4945 | if (*ptype == DEBUG_TYPE_NULL) | |
4946 | *ptype = debug_make_float_type (minfo->dhandle, 8); | |
4947 | } | |
4948 | ++*pp; | |
4949 | break; | |
4950 | ||
4951 | case 'd': /* double */ | |
4952 | if (ptype != NULL) | |
4953 | { | |
4954 | *ptype = debug_find_named_type (minfo->dhandle, "double"); | |
4955 | if (*ptype == DEBUG_TYPE_NULL) | |
4956 | *ptype = debug_make_float_type (minfo->dhandle, 8); | |
4957 | } | |
4958 | ++*pp; | |
4959 | break; | |
4960 | ||
4961 | case 'f': /* float */ | |
4962 | if (ptype != NULL) | |
4963 | { | |
4964 | *ptype = debug_find_named_type (minfo->dhandle, "float"); | |
4965 | if (*ptype == DEBUG_TYPE_NULL) | |
4966 | *ptype = debug_make_float_type (minfo->dhandle, 4); | |
4967 | } | |
4968 | ++*pp; | |
4969 | break; | |
4970 | ||
4971 | case 'G': | |
4972 | ++*pp; | |
3882b010 | 4973 | if (! ISDIGIT (**pp)) |
252b5132 RH |
4974 | { |
4975 | stab_bad_demangle (orig); | |
b34976b6 | 4976 | return FALSE; |
252b5132 RH |
4977 | } |
4978 | /* Fall through. */ | |
4979 | case '0': case '1': case '2': case '3': case '4': | |
4980 | case '5': case '6': case '7': case '8': case '9': | |
4981 | { | |
4982 | const char *hold; | |
4983 | ||
4984 | if (! stab_demangle_class (minfo, pp, &hold)) | |
b34976b6 | 4985 | return FALSE; |
252b5132 RH |
4986 | if (ptype != NULL) |
4987 | { | |
4988 | char *name; | |
4989 | ||
4990 | name = savestring (hold, *pp - hold); | |
4991 | *ptype = debug_find_named_type (minfo->dhandle, name); | |
4992 | free (name); | |
4993 | if (*ptype == DEBUG_TYPE_NULL) | |
4994 | { | |
4995 | /* FIXME: It is probably incorrect to assume that | |
4996 | undefined types are tagged types. */ | |
4997 | *ptype = stab_find_tagged_type (minfo->dhandle, minfo->info, | |
4998 | hold, *pp - hold, | |
4999 | DEBUG_KIND_ILLEGAL); | |
5000 | if (*ptype == DEBUG_TYPE_NULL) | |
b34976b6 | 5001 | return FALSE; |
252b5132 RH |
5002 | } |
5003 | } | |
5004 | } | |
5005 | break; | |
5006 | ||
5007 | case 't': | |
5008 | { | |
5009 | char *name; | |
5010 | ||
5011 | if (! stab_demangle_template (minfo, pp, | |
5012 | ptype != NULL ? &name : NULL)) | |
b34976b6 | 5013 | return FALSE; |
252b5132 RH |
5014 | if (ptype != NULL) |
5015 | { | |
5016 | *ptype = stab_find_tagged_type (minfo->dhandle, minfo->info, | |
5017 | name, strlen (name), | |
5018 | DEBUG_KIND_CLASS); | |
5019 | free (name); | |
5020 | if (*ptype == DEBUG_TYPE_NULL) | |
b34976b6 | 5021 | return FALSE; |
252b5132 RH |
5022 | } |
5023 | } | |
5024 | break; | |
5025 | ||
5026 | default: | |
5027 | stab_bad_demangle (orig); | |
b34976b6 | 5028 | return FALSE; |
252b5132 RH |
5029 | } |
5030 | ||
5031 | if (ptype != NULL) | |
5032 | { | |
5033 | if (constp) | |
5034 | *ptype = debug_make_const_type (minfo->dhandle, *ptype); | |
5035 | if (volatilep) | |
5036 | *ptype = debug_make_volatile_type (minfo->dhandle, *ptype); | |
5037 | } | |
5038 | ||
b34976b6 | 5039 | return TRUE; |
252b5132 RH |
5040 | } |
5041 | ||
5042 | /* Remember a type string in a demangled string. */ | |
5043 | ||
b34976b6 | 5044 | static bfd_boolean |
2da42df6 AJ |
5045 | stab_demangle_remember_type (struct stab_demangle_info *minfo, |
5046 | const char *p, int len) | |
252b5132 RH |
5047 | { |
5048 | if (minfo->typestring_count >= minfo->typestring_alloc) | |
5049 | { | |
5050 | minfo->typestring_alloc += 10; | |
5051 | minfo->typestrings = ((struct stab_demangle_typestring *) | |
5052 | xrealloc (minfo->typestrings, | |
5053 | (minfo->typestring_alloc | |
5054 | * sizeof *minfo->typestrings))); | |
5055 | } | |
5056 | ||
5057 | minfo->typestrings[minfo->typestring_count].typestring = p; | |
5058 | minfo->typestrings[minfo->typestring_count].len = (unsigned int) len; | |
5059 | ++minfo->typestring_count; | |
5060 | ||
b34976b6 | 5061 | return TRUE; |
252b5132 | 5062 | } |
041821e6 ILT |
5063 | \f |
5064 | /* Demangle names encoded using the g++ V3 ABI. The newer versions of | |
5065 | g++ which use this ABI do not encode ordinary method argument types | |
5066 | in a mangled name; they simply output the argument types. However, | |
5067 | for a static method, g++ simply outputs the return type and the | |
5068 | physical name. So in that case we need to demangle the name here. | |
5069 | Here PHYSNAME is the physical name of the function, and we set the | |
5070 | variable pointed at by PVARARGS to indicate whether this function | |
5071 | is varargs. This returns NULL, or a NULL terminated array of | |
5072 | argument types. */ | |
5073 | ||
5074 | static debug_type * | |
5075 | stab_demangle_v3_argtypes (void *dhandle, struct stab_handle *info, | |
5076 | const char *physname, bfd_boolean *pvarargs) | |
5077 | { | |
5078 | struct demangle_component *dc; | |
5079 | void *mem; | |
041821e6 ILT |
5080 | debug_type *pargs; |
5081 | ||
5082 | dc = cplus_demangle_v3_components (physname, DMGL_PARAMS | DMGL_ANSI, &mem); | |
5083 | if (dc == NULL) | |
5084 | { | |
5085 | stab_bad_demangle (physname); | |
5086 | return NULL; | |
5087 | } | |
5088 | ||
5089 | /* We expect to see TYPED_NAME, and the right subtree describes the | |
5090 | function type. */ | |
5091 | if (dc->type != DEMANGLE_COMPONENT_TYPED_NAME | |
5092 | || dc->u.s_binary.right->type != DEMANGLE_COMPONENT_FUNCTION_TYPE) | |
5093 | { | |
5094 | fprintf (stderr, _("Demangled name is not a function\n")); | |
5095 | free (mem); | |
5096 | return NULL; | |
5097 | } | |
5098 | ||
2b4c4cc4 ILT |
5099 | pargs = stab_demangle_v3_arglist (dhandle, info, |
5100 | dc->u.s_binary.right->u.s_binary.right, | |
5101 | pvarargs); | |
5102 | ||
5103 | free (mem); | |
5104 | ||
5105 | return pargs; | |
5106 | } | |
5107 | ||
5108 | /* Demangle an argument list in a struct demangle_component tree. | |
5109 | Returns a DEBUG_TYPE_NULL terminated array of argument types, and | |
5110 | sets *PVARARGS to indicate whether this is a varargs function. */ | |
5111 | ||
5112 | static debug_type * | |
5113 | stab_demangle_v3_arglist (void *dhandle, struct stab_handle *info, | |
5114 | struct demangle_component *arglist, | |
5115 | bfd_boolean *pvarargs) | |
5116 | { | |
5117 | struct demangle_component *dc; | |
5118 | unsigned int alloc, count; | |
5119 | debug_type *pargs; | |
5120 | ||
041821e6 ILT |
5121 | alloc = 10; |
5122 | pargs = (debug_type *) xmalloc (alloc * sizeof *pargs); | |
5123 | *pvarargs = FALSE; | |
5124 | ||
5125 | count = 0; | |
5126 | ||
2b4c4cc4 | 5127 | for (dc = arglist; |
041821e6 ILT |
5128 | dc != NULL; |
5129 | dc = dc->u.s_binary.right) | |
5130 | { | |
5131 | debug_type arg; | |
5132 | bfd_boolean varargs; | |
5133 | ||
5134 | if (dc->type != DEMANGLE_COMPONENT_ARGLIST) | |
5135 | { | |
2b4c4cc4 ILT |
5136 | fprintf (stderr, _("Unexpected type in v3 arglist demangling\n")); |
5137 | free (pargs); | |
041821e6 ILT |
5138 | return NULL; |
5139 | } | |
5140 | ||
5141 | arg = stab_demangle_v3_arg (dhandle, info, dc->u.s_binary.left, | |
5142 | NULL, &varargs); | |
5143 | if (arg == NULL) | |
5144 | { | |
5145 | if (varargs) | |
5146 | { | |
5147 | *pvarargs = TRUE; | |
5148 | continue; | |
5149 | } | |
2b4c4cc4 | 5150 | free (pargs); |
041821e6 ILT |
5151 | return NULL; |
5152 | } | |
5153 | ||
5154 | if (count + 1 >= alloc) | |
5155 | { | |
5156 | alloc += 10; | |
5157 | pargs = (debug_type *) xrealloc (pargs, alloc * sizeof *pargs); | |
5158 | } | |
5159 | ||
5160 | pargs[count] = arg; | |
5161 | ++count; | |
5162 | } | |
5163 | ||
5164 | pargs[count] = DEBUG_TYPE_NULL; | |
5165 | ||
041821e6 ILT |
5166 | return pargs; |
5167 | } | |
5168 | ||
5169 | /* Convert a struct demangle_component tree describing an argument | |
5170 | type into a debug_type. */ | |
5171 | ||
5172 | static debug_type | |
5173 | stab_demangle_v3_arg (void *dhandle, struct stab_handle *info, | |
5174 | struct demangle_component *dc, debug_type context, | |
5175 | bfd_boolean *pvarargs) | |
5176 | { | |
5177 | debug_type dt; | |
5178 | ||
5179 | if (pvarargs != NULL) | |
5180 | *pvarargs = FALSE; | |
5181 | ||
5182 | switch (dc->type) | |
5183 | { | |
5184 | /* FIXME: These are demangle component types which we probably | |
5185 | need to handle one way or another. */ | |
5186 | case DEMANGLE_COMPONENT_LOCAL_NAME: | |
5187 | case DEMANGLE_COMPONENT_TYPED_NAME: | |
5188 | case DEMANGLE_COMPONENT_TEMPLATE_PARAM: | |
5189 | case DEMANGLE_COMPONENT_CTOR: | |
5190 | case DEMANGLE_COMPONENT_DTOR: | |
5191 | case DEMANGLE_COMPONENT_JAVA_CLASS: | |
5192 | case DEMANGLE_COMPONENT_RESTRICT_THIS: | |
5193 | case DEMANGLE_COMPONENT_VOLATILE_THIS: | |
5194 | case DEMANGLE_COMPONENT_CONST_THIS: | |
5195 | case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL: | |
5196 | case DEMANGLE_COMPONENT_COMPLEX: | |
5197 | case DEMANGLE_COMPONENT_IMAGINARY: | |
5198 | case DEMANGLE_COMPONENT_VENDOR_TYPE: | |
041821e6 ILT |
5199 | case DEMANGLE_COMPONENT_ARRAY_TYPE: |
5200 | case DEMANGLE_COMPONENT_PTRMEM_TYPE: | |
5201 | case DEMANGLE_COMPONENT_ARGLIST: | |
5202 | default: | |
2b4c4cc4 ILT |
5203 | fprintf (stderr, _("Unrecognized demangle component %d\n"), |
5204 | (int) dc->type); | |
041821e6 ILT |
5205 | return NULL; |
5206 | ||
5207 | case DEMANGLE_COMPONENT_NAME: | |
5208 | if (context != NULL) | |
5209 | { | |
5210 | const debug_field *fields; | |
5211 | ||
5212 | fields = debug_get_fields (dhandle, context); | |
5213 | if (fields != NULL) | |
5214 | { | |
5215 | /* Try to find this type by looking through the context | |
5216 | class. */ | |
5217 | for (; *fields != DEBUG_FIELD_NULL; fields++) | |
5218 | { | |
5219 | debug_type ft; | |
5220 | const char *dn; | |
5221 | ||
5222 | ft = debug_get_field_type (dhandle, *fields); | |
5223 | if (ft == NULL) | |
5224 | return NULL; | |
5225 | dn = debug_get_type_name (dhandle, ft); | |
5226 | if (dn != NULL | |
5227 | && (int) strlen (dn) == dc->u.s_name.len | |
5228 | && strncmp (dn, dc->u.s_name.s, dc->u.s_name.len) == 0) | |
5229 | return ft; | |
5230 | } | |
5231 | } | |
5232 | } | |
5233 | return stab_find_tagged_type (dhandle, info, dc->u.s_name.s, | |
5234 | dc->u.s_name.len, DEBUG_KIND_ILLEGAL); | |
5235 | ||
5236 | case DEMANGLE_COMPONENT_QUAL_NAME: | |
5237 | context = stab_demangle_v3_arg (dhandle, info, dc->u.s_binary.left, | |
5238 | context, NULL); | |
5239 | if (context == NULL) | |
5240 | return NULL; | |
5241 | return stab_demangle_v3_arg (dhandle, info, dc->u.s_binary.right, | |
5242 | context, NULL); | |
5243 | ||
5244 | case DEMANGLE_COMPONENT_TEMPLATE: | |
5245 | { | |
5246 | char *p; | |
5247 | size_t alc; | |
5248 | ||
5249 | /* We print this component to get a class name which we can | |
5250 | use. FIXME: This probably won't work if the template uses | |
5251 | template parameters which refer to an outer template. */ | |
5252 | p = cplus_demangle_print (DMGL_PARAMS | DMGL_ANSI, dc, 20, &alc); | |
5253 | if (p == NULL) | |
5254 | { | |
5255 | fprintf (stderr, _("Failed to print demangled template\n")); | |
5256 | return NULL; | |
5257 | } | |
5258 | dt = stab_find_tagged_type (dhandle, info, p, strlen (p), | |
5259 | DEBUG_KIND_CLASS); | |
5260 | free (p); | |
5261 | return dt; | |
5262 | } | |
5263 | ||
5264 | case DEMANGLE_COMPONENT_SUB_STD: | |
5265 | return stab_find_tagged_type (dhandle, info, dc->u.s_string.string, | |
5266 | dc->u.s_string.len, DEBUG_KIND_ILLEGAL); | |
5267 | ||
5268 | case DEMANGLE_COMPONENT_RESTRICT: | |
5269 | case DEMANGLE_COMPONENT_VOLATILE: | |
5270 | case DEMANGLE_COMPONENT_CONST: | |
5271 | case DEMANGLE_COMPONENT_POINTER: | |
5272 | case DEMANGLE_COMPONENT_REFERENCE: | |
5273 | dt = stab_demangle_v3_arg (dhandle, info, dc->u.s_binary.left, NULL, | |
5274 | NULL); | |
5275 | if (dt == NULL) | |
5276 | return NULL; | |
5277 | ||
5278 | switch (dc->type) | |
5279 | { | |
5280 | default: | |
5281 | abort (); | |
5282 | case DEMANGLE_COMPONENT_RESTRICT: | |
5283 | /* FIXME: We have no way to represent restrict. */ | |
5284 | return dt; | |
5285 | case DEMANGLE_COMPONENT_VOLATILE: | |
5286 | return debug_make_volatile_type (dhandle, dt); | |
5287 | case DEMANGLE_COMPONENT_CONST: | |
5288 | return debug_make_const_type (dhandle, dt); | |
5289 | case DEMANGLE_COMPONENT_POINTER: | |
5290 | return debug_make_pointer_type (dhandle, dt); | |
5291 | case DEMANGLE_COMPONENT_REFERENCE: | |
5292 | return debug_make_reference_type (dhandle, dt); | |
5293 | } | |
5294 | ||
2b4c4cc4 ILT |
5295 | case DEMANGLE_COMPONENT_FUNCTION_TYPE: |
5296 | { | |
5297 | debug_type *pargs; | |
5298 | bfd_boolean varargs; | |
5299 | ||
5300 | if (dc->u.s_binary.left == NULL) | |
5301 | { | |
5302 | /* In this case the return type is actually unknown. | |
5303 | However, I'm not sure this will ever arise in practice; | |
5304 | normally an unknown return type would only appear at | |
5305 | the top level, which is handled above. */ | |
5306 | dt = debug_make_void_type (dhandle); | |
5307 | } | |
5308 | else | |
5309 | dt = stab_demangle_v3_arg (dhandle, info, dc->u.s_binary.left, NULL, | |
5310 | NULL); | |
5311 | if (dt == NULL) | |
5312 | return NULL; | |
5313 | ||
5314 | pargs = stab_demangle_v3_arglist (dhandle, info, | |
5315 | dc->u.s_binary.right, | |
5316 | &varargs); | |
5317 | if (pargs == NULL) | |
5318 | return NULL; | |
5319 | ||
5320 | return debug_make_function_type (dhandle, dt, pargs, varargs); | |
5321 | } | |
5322 | ||
041821e6 ILT |
5323 | case DEMANGLE_COMPONENT_BUILTIN_TYPE: |
5324 | { | |
5325 | char *p; | |
5326 | size_t alc; | |
5327 | debug_type ret; | |
5328 | ||
5329 | /* We print this component in order to find out the type name. | |
5330 | FIXME: Should we instead expose the | |
5331 | demangle_builtin_type_info structure? */ | |
5332 | p = cplus_demangle_print (DMGL_PARAMS | DMGL_ANSI, dc, 20, &alc); | |
5333 | if (p == NULL) | |
5334 | { | |
5335 | fprintf (stderr, _("Couldn't get demangled builtin type\n")); | |
5336 | return NULL; | |
5337 | } | |
5338 | ||
5339 | /* The mangling is based on the type, but does not itself | |
5340 | indicate what the sizes are. So we have to guess. */ | |
5341 | if (strcmp (p, "signed char") == 0) | |
5342 | ret = debug_make_int_type (dhandle, 1, FALSE); | |
5343 | else if (strcmp (p, "bool") == 0) | |
5344 | ret = debug_make_bool_type (dhandle, 1); | |
5345 | else if (strcmp (p, "char") == 0) | |
5346 | ret = debug_make_int_type (dhandle, 1, FALSE); | |
5347 | else if (strcmp (p, "double") == 0) | |
5348 | ret = debug_make_float_type (dhandle, 8); | |
5349 | else if (strcmp (p, "long double") == 0) | |
5350 | ret = debug_make_float_type (dhandle, 8); | |
5351 | else if (strcmp (p, "float") == 0) | |
5352 | ret = debug_make_float_type (dhandle, 4); | |
5353 | else if (strcmp (p, "__float128") == 0) | |
5354 | ret = debug_make_float_type (dhandle, 16); | |
5355 | else if (strcmp (p, "unsigned char") == 0) | |
5356 | ret = debug_make_int_type (dhandle, 1, TRUE); | |
5357 | else if (strcmp (p, "int") == 0) | |
5358 | ret = debug_make_int_type (dhandle, 4, FALSE); | |
5359 | else if (strcmp (p, "unsigned int") == 0) | |
5360 | ret = debug_make_int_type (dhandle, 4, TRUE); | |
5361 | else if (strcmp (p, "long") == 0) | |
5362 | ret = debug_make_int_type (dhandle, 4, FALSE); | |
5363 | else if (strcmp (p, "unsigned long") == 0) | |
5364 | ret = debug_make_int_type (dhandle, 4, TRUE); | |
5365 | else if (strcmp (p, "__int128") == 0) | |
5366 | ret = debug_make_int_type (dhandle, 16, FALSE); | |
5367 | else if (strcmp (p, "unsigned __int128") == 0) | |
5368 | ret = debug_make_int_type (dhandle, 16, TRUE); | |
5369 | else if (strcmp (p, "short") == 0) | |
5370 | ret = debug_make_int_type (dhandle, 2, FALSE); | |
5371 | else if (strcmp (p, "unsigned short") == 0) | |
5372 | ret = debug_make_int_type (dhandle, 2, TRUE); | |
5373 | else if (strcmp (p, "void") == 0) | |
5374 | ret = debug_make_void_type (dhandle); | |
5375 | else if (strcmp (p, "wchar_t") == 0) | |
5376 | ret = debug_make_int_type (dhandle, 4, TRUE); | |
5377 | else if (strcmp (p, "long long") == 0) | |
5378 | ret = debug_make_int_type (dhandle, 8, FALSE); | |
5379 | else if (strcmp (p, "unsigned long long") == 0) | |
5380 | ret = debug_make_int_type (dhandle, 8, TRUE); | |
5381 | else if (strcmp (p, "...") == 0) | |
5382 | { | |
5383 | if (pvarargs == NULL) | |
5384 | fprintf (stderr, _("Unexpected demangled varargs\n")); | |
5385 | else | |
5386 | *pvarargs = TRUE; | |
5387 | ret = NULL; | |
5388 | } | |
5389 | else | |
5390 | { | |
5391 | fprintf (stderr, _("Unrecognized demangled builtin type\n")); | |
5392 | ret = NULL; | |
5393 | } | |
5394 | ||
5395 | free (p); | |
5396 | ||
5397 | return ret; | |
5398 | } | |
5399 | } | |
5400 | } |