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