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