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