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