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