1 /* stabs.c -- Parse stabs debugging information
2 Copyright (C) 1995-2018 Free Software Foundation, Inc.
3 Written by Ian Lance Taylor <ian@cygnus.com>.
5 This file is part of GNU Binutils.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
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.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
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. */
29 #include "libiberty.h"
30 #include "safe-ctype.h"
34 #include "filenames.h"
35 #include "aout/aout64.h"
36 #include "aout/stab_gnu.h"
38 /* The number of predefined XCOFF types. */
40 #define XCOFF_TYPE_COUNT 34
42 /* This structure is used as a handle so that the stab parsing doesn't
43 need to use any static variables. */
49 /* TRUE if this is stabs in sections. */
51 /* The symbol table. */
53 /* The number of symbols. */
55 /* The accumulated file name string. */
57 /* The value of the last N_SO symbol. */
59 /* The value of the start of the file, so that we can handle file
60 relative N_LBRAC and N_RBRAC symbols. */
61 bfd_vma file_start_offset;
62 /* The offset of the start of the function, so that we can handle
63 function relative N_LBRAC and N_RBRAC symbols. */
64 bfd_vma function_start_offset;
65 /* The version number of gcc which compiled the current compilation
66 unit, 0 if not compiled by gcc. */
68 /* Whether an N_OPT symbol was seen that was not generated by gcc,
69 so that we can detect the SunPRO compiler. */
70 bfd_boolean n_opt_found;
71 /* The main file name. */
73 /* A stack of unfinished N_BINCL files. */
74 struct bincl_file *bincl_stack;
75 /* A list of finished N_BINCL files. */
76 struct bincl_file *bincl_list;
77 /* Whether we are inside a function or not. */
78 bfd_boolean within_function;
79 /* The address of the end of the function, used if we have seen an
80 N_FUN symbol while in a function. This is -1 if we have not seen
81 an N_FUN (the normal case). */
83 /* The depth of block nesting. */
85 /* List of pending variable definitions. */
86 struct stab_pending_var *pending;
87 /* Number of files for which we have types. */
89 /* Lists of types per file. */
90 struct stab_types **file_types;
91 /* Predefined XCOFF types. */
92 debug_type xcoff_types[XCOFF_TYPE_COUNT];
94 struct stab_tag *tags;
95 /* Set by parse_stab_type if it sees a structure defined as a cross
96 reference to itself. Reset by parse_stab_type otherwise. */
97 bfd_boolean self_crossref;
100 /* A list of these structures is used to hold pending variable
101 definitions seen before the N_LBRAC of a block. */
103 struct stab_pending_var
105 /* Next pending variable definition. */
106 struct stab_pending_var *next;
112 enum debug_var_kind kind;
117 /* A list of these structures is used to hold the types for a single
122 /* Next set of slots for this file. */
123 struct stab_types *next;
124 /* Types indexed by type number. */
125 #define STAB_TYPES_SLOTS (16)
126 debug_type types[STAB_TYPES_SLOTS];
129 /* We keep a list of undefined tags that we encounter, so that we can
130 fill them in if the tag is later defined. */
134 /* Next undefined tag. */
135 struct stab_tag *next;
139 enum debug_type_kind kind;
140 /* Slot to hold real type when we discover it. If we don't, we fill
141 in an undefined tag type. */
143 /* Indirect type we have created to point at slot. */
147 static char *savestring (const char *, int);
149 static void bad_stab (const char *);
150 static void warn_stab (const char *, const char *);
151 static bfd_boolean parse_stab_string
152 (void *, struct stab_handle *, int, int, bfd_vma,
153 const char *, const char *);
154 static debug_type parse_stab_type
155 (void *, struct stab_handle *, const char *, const char **,
156 debug_type **, const char *);
157 static bfd_boolean parse_stab_type_number
158 (const char **, int *, const char *);
159 static debug_type parse_stab_range_type
160 (void *, struct stab_handle *, const char *, const char **,
161 const int *, const char *);
162 static debug_type parse_stab_sun_builtin_type
163 (void *, const char **, const char *);
164 static debug_type parse_stab_sun_floating_type
165 (void *, const char **, const char *);
166 static debug_type parse_stab_enum_type
167 (void *, const char **, const char *);
168 static debug_type parse_stab_struct_type
169 (void *, struct stab_handle *, const char *, const char **,
170 bfd_boolean, const int *, const char *);
171 static bfd_boolean parse_stab_baseclasses
172 (void *, struct stab_handle *, const char **, debug_baseclass **,
174 static bfd_boolean parse_stab_struct_fields
175 (void *, struct stab_handle *, const char **, debug_field **,
176 bfd_boolean *, const char *);
177 static bfd_boolean parse_stab_cpp_abbrev
178 (void *, struct stab_handle *, const char **, debug_field *, const char *);
179 static bfd_boolean parse_stab_one_struct_field
180 (void *, struct stab_handle *, const char **, const char *,
181 debug_field *, bfd_boolean *, const char *);
182 static bfd_boolean parse_stab_members
183 (void *, struct stab_handle *, const char *, const char **, const int *,
184 debug_method **, const char *);
185 static debug_type parse_stab_argtypes
186 (void *, struct stab_handle *, debug_type, const char *, const char *,
187 debug_type, const char *, bfd_boolean, bfd_boolean, const char **);
188 static bfd_boolean parse_stab_tilde_field
189 (void *, struct stab_handle *, const char **, const int *, debug_type *,
190 bfd_boolean *, const char *);
191 static debug_type parse_stab_array_type
192 (void *, struct stab_handle *, const char **, bfd_boolean, const char *);
193 static void push_bincl (struct stab_handle *, const char *, bfd_vma);
194 static const char *pop_bincl (struct stab_handle *);
195 static bfd_boolean find_excl (struct stab_handle *, const char *, bfd_vma);
196 static bfd_boolean stab_record_variable
197 (void *, struct stab_handle *, const char *, debug_type,
198 enum debug_var_kind, bfd_vma);
199 static bfd_boolean stab_emit_pending_vars (void *, struct stab_handle *);
200 static debug_type *stab_find_slot (struct stab_handle *, const int *);
201 static debug_type stab_find_type (void *, struct stab_handle *, const int *);
202 static bfd_boolean stab_record_type
203 (void *, struct stab_handle *, const int *, debug_type);
204 static debug_type stab_xcoff_builtin_type
205 (void *, struct stab_handle *, int);
206 static debug_type stab_find_tagged_type
207 (void *, struct stab_handle *, const char *, int, enum debug_type_kind);
208 static debug_type *stab_demangle_argtypes
209 (void *, struct stab_handle *, const char *, bfd_boolean *, unsigned int);
210 static debug_type *stab_demangle_v3_argtypes
211 (void *, struct stab_handle *, const char *, bfd_boolean *);
212 static debug_type *stab_demangle_v3_arglist
213 (void *, struct stab_handle *, struct demangle_component *, bfd_boolean *);
214 static debug_type stab_demangle_v3_arg
215 (void *, struct stab_handle *, struct demangle_component *, debug_type,
218 /* Save a string in memory. */
221 savestring (const char *start, int len)
225 ret = (char *) xmalloc (len + 1);
226 memcpy (ret, start, len);
231 /* Read a number from a string. */
234 parse_number (const char **pp, bfd_boolean *poverflow, const char *p_end)
239 if (poverflow != NULL)
246 /* Stop early if we are passed an empty string. */
251 ul = strtoul (*pp, (char **) pp, 0);
252 if (ul + 1 != 0 || errno == 0)
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
258 return (bfd_vma) (bfd_signed_vma) (long) ul;
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 if (sizeof (bfd_vma) > sizeof (unsigned long))
269 bfd_vma over, lastdig;
270 bfd_boolean overflow;
273 /* Our own version of strtoul, for a bfd_vma. */
288 if (p[1] == 'x' || p[1] == 'X')
300 over = ((bfd_vma) (bfd_signed_vma) -1) / (bfd_vma) base;
301 lastdig = ((bfd_vma) (bfd_signed_vma) -1) % (bfd_vma) base;
312 else if (ISUPPER (d))
314 else if (ISLOWER (d))
322 if (v > over || (v == over && (bfd_vma) d > lastdig))
337 /* If we get here, the number is too large to represent in a
339 if (poverflow != NULL)
342 warn_stab (orig, _("numeric overflow"));
347 /* Give an error for a bad stab string. */
350 bad_stab (const char *p)
352 fprintf (stderr, _("Bad stab: %s\n"), p);
355 /* Warn about something in a stab string. */
358 warn_stab (const char *p, const char *err)
360 fprintf (stderr, _("Warning: %s: %s\n"), err, p);
363 /* Create a handle to parse stabs symbols with. */
366 start_stab (void *dhandle ATTRIBUTE_UNUSED, bfd *abfd, bfd_boolean sections,
367 asymbol **syms, long symcount)
369 struct stab_handle *ret;
371 ret = (struct stab_handle *) xmalloc (sizeof *ret);
372 memset (ret, 0, sizeof *ret);
374 ret->sections = sections;
376 ret->symcount = symcount;
378 ret->file_types = (struct stab_types **) xmalloc (sizeof *ret->file_types);
379 ret->file_types[0] = NULL;
380 ret->function_end = (bfd_vma) -1;
384 /* When we have processed all the stabs information, we need to go
385 through and fill in all the undefined tags. */
388 finish_stab (void *dhandle, void *handle)
390 struct stab_handle *info = (struct stab_handle *) handle;
393 if (info->within_function)
395 if (! stab_emit_pending_vars (dhandle, info)
396 || ! debug_end_function (dhandle, info->function_end))
398 info->within_function = FALSE;
399 info->function_end = (bfd_vma) -1;
402 for (st = info->tags; st != NULL; st = st->next)
404 enum debug_type_kind kind;
407 if (kind == DEBUG_KIND_ILLEGAL)
408 kind = DEBUG_KIND_STRUCT;
409 st->slot = debug_make_undefined_tagged_type (dhandle, st->name, kind);
410 if (st->slot == DEBUG_TYPE_NULL)
417 /* Handle a single stabs symbol. */
420 parse_stab (void *dhandle, void *handle, int type, int desc, bfd_vma value,
423 const char * string_end;
424 struct stab_handle *info = (struct stab_handle *) handle;
426 /* gcc will emit two N_SO strings per compilation unit, one for the
427 directory name and one for the file name. We just collect N_SO
428 strings as we see them, and start the new compilation unit when
429 we see a non N_SO symbol. */
430 if (info->so_string != NULL
431 && (type != N_SO || *string == '\0' || value != info->so_value))
433 if (! debug_set_filename (dhandle, info->so_string))
435 info->main_filename = info->so_string;
437 info->gcc_compiled = 0;
438 info->n_opt_found = FALSE;
440 /* Generally, for stabs in the symbol table, the N_LBRAC and
441 N_RBRAC symbols are relative to the N_SO symbol value. */
442 if (! info->sections)
443 info->file_start_offset = info->so_value;
445 /* We need to reset the mapping from type numbers to types. We
446 can't free the old mapping, because of the use of
447 debug_make_indirect_type. */
449 info->file_types = ((struct stab_types **)
450 xmalloc (sizeof *info->file_types));
451 info->file_types[0] = NULL;
453 info->so_string = NULL;
455 /* Now process whatever type we just got. */
458 string_end = string + strlen (string);
467 /* Ignore extra outermost context from SunPRO cc and acc. */
468 if (info->n_opt_found && desc == 1)
471 if (! info->within_function)
473 fprintf (stderr, _("N_LBRAC not within function\n"));
477 /* Start an inner lexical block. */
478 if (! debug_start_block (dhandle,
480 + info->file_start_offset
481 + info->function_start_offset)))
484 /* Emit any pending variable definitions. */
485 if (! stab_emit_pending_vars (dhandle, info))
492 /* Ignore extra outermost context from SunPRO cc and acc. */
493 if (info->n_opt_found && desc == 1)
496 /* We shouldn't have any pending variable definitions here, but,
497 if we do, we probably need to emit them before closing the
499 if (! stab_emit_pending_vars (dhandle, info))
502 /* End an inner lexical block. */
503 if (! debug_end_block (dhandle,
505 + info->file_start_offset
506 + info->function_start_offset)))
510 if (info->block_depth < 0)
512 fprintf (stderr, _("Too many N_RBRACs\n"));
518 /* This always ends a function. */
519 if (info->within_function)
525 && info->function_end != (bfd_vma) -1
526 && info->function_end < endval)
527 endval = info->function_end;
528 if (! stab_emit_pending_vars (dhandle, info)
529 || ! debug_end_function (dhandle, endval))
531 info->within_function = FALSE;
532 info->function_end = (bfd_vma) -1;
535 /* An empty string is emitted by gcc at the end of a compilation
540 /* Just accumulate strings until we see a non N_SO symbol. If
541 the string starts with a directory separator or some other
542 form of absolute path specification, we discard the previously
543 accumulated strings. */
544 if (info->so_string == NULL)
545 info->so_string = xstrdup (string);
552 if (IS_ABSOLUTE_PATH (string))
553 info->so_string = xstrdup (string);
555 info->so_string = concat (info->so_string, string,
556 (const char *) NULL);
560 info->so_value = value;
565 /* Start an include file. */
566 if (! debug_start_source (dhandle, string))
571 /* Start an include file which may be replaced. */
572 push_bincl (info, string, value);
573 if (! debug_start_source (dhandle, string))
578 /* End an N_BINCL include. */
579 if (! debug_start_source (dhandle, pop_bincl (info)))
584 /* This is a duplicate of a header file named by N_BINCL which
585 was eliminated by the linker. */
586 if (! find_excl (info, string, value))
591 if (! debug_record_line (dhandle, desc,
592 value + (info->within_function
593 ? info->function_start_offset : 0)))
598 if (! debug_start_common_block (dhandle, string))
603 if (! debug_end_common_block (dhandle, string))
610 if (info->within_function)
612 /* This always marks the end of a function; we don't
613 need to worry about info->function_end. */
615 value += info->function_start_offset;
616 if (! stab_emit_pending_vars (dhandle, info)
617 || ! debug_end_function (dhandle, value))
619 info->within_function = FALSE;
620 info->function_end = (bfd_vma) -1;
625 /* A const static symbol in the .text section will have an N_FUN
626 entry. We need to use these to mark the end of the function,
627 in case we are looking at gcc output before it was changed to
628 always emit an empty N_FUN. We can't call debug_end_function
629 here, because it might be a local static symbol. */
630 if (info->within_function
631 && (info->function_end == (bfd_vma) -1
632 || value < info->function_end))
633 info->function_end = value;
636 /* FIXME: gdb checks the string for N_STSYM, N_LCSYM or N_ROSYM
637 symbols, and if it does not start with :S, gdb relocates the
638 value to the start of the section. gcc always seems to use
639 :S, so we don't worry about this. */
645 colon = strchr (string, ':');
647 && (colon[1] == 'f' || colon[1] == 'F'))
649 if (info->within_function)
654 if (info->function_end != (bfd_vma) -1
655 && info->function_end < endval)
656 endval = info->function_end;
657 if (! stab_emit_pending_vars (dhandle, info)
658 || ! debug_end_function (dhandle, endval))
660 info->function_end = (bfd_vma) -1;
662 /* For stabs in sections, line numbers and block addresses
663 are offsets from the start of the function. */
665 info->function_start_offset = value;
666 info->within_function = TRUE;
669 if (! parse_stab_string (dhandle, info, type, desc, value, string, string_end))
675 if (string != NULL && strcmp (string, "gcc2_compiled.") == 0)
676 info->gcc_compiled = 2;
677 else if (string != NULL && strcmp (string, "gcc_compiled.") == 0)
678 info->gcc_compiled = 1;
680 info->n_opt_found = TRUE;
693 /* Parse the stabs string. */
696 parse_stab_string (void *dhandle, struct stab_handle *info, int stabtype,
697 int desc ATTRIBUTE_UNUSED, bfd_vma value,
698 const char *string, const char * string_end)
705 bfd_boolean self_crossref;
708 p = strchr (string, ':');
723 /* FIXME: Sometimes the special C++ names start with '.'. */
725 if (string[0] == '$')
733 /* Was: name = "vptr"; */
739 /* This was an anonymous type that was never fixed up. */
742 /* SunPRO (3.0 at least) static variable encoding. */
745 warn_stab (string, _("unknown C++ encoded name"));
752 if (p == string || (string[0] == ' ' && p == string + 1))
755 name = savestring (string, p - string);
759 if (ISDIGIT (*p) || *p == '(' || *p == '-')
772 /* c is a special case, not followed by a type-number.
773 SYMBOL:c=iVALUE for an integer constant symbol.
774 SYMBOL:c=rVALUE for a floating constant symbol.
775 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
776 e.g. "b:c=e6,0" for "const b = blob1"
777 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
787 /* Floating point constant. */
788 if (! debug_record_float_const (dhandle, name, atof (p)))
792 /* Integer constant. */
793 /* Defining integer constants this way is kind of silly,
794 since 'e' constants allows the compiler to give not only
795 the value, but the type as well. C has at least int,
796 long, unsigned int, and long long as constant types;
797 other languages probably should have at least unsigned as
798 well as signed constants. */
799 if (! debug_record_int_const (dhandle, name, atoi (p)))
803 /* SYMBOL:c=eTYPE,INTVALUE for a constant symbol whose value
804 can be represented as integral.
805 e.g. "b:c=e6,0" for "const b = blob1"
806 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
807 dtype = parse_stab_type (dhandle, info, (const char *) NULL,
808 &p, (debug_type **) NULL, string_end);
809 if (dtype == DEBUG_TYPE_NULL)
816 if (! debug_record_typed_const (dhandle, name, dtype, atoi (p)))
827 /* The name of a caught exception. */
828 dtype = parse_stab_type (dhandle, info, (const char *) NULL,
829 &p, (debug_type **) NULL, string_end);
830 if (dtype == DEBUG_TYPE_NULL)
832 if (! debug_record_label (dhandle, name, dtype, value))
838 /* A function definition. */
839 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
840 (debug_type **) NULL, string_end);
841 if (dtype == DEBUG_TYPE_NULL)
843 if (! debug_record_function (dhandle, name, dtype, type == 'F', value))
846 /* Sun acc puts declared types of arguments here. We don't care
847 about their actual types (FIXME -- we should remember the whole
848 function prototype), but the list may define some new types
849 that we have to remember, so we must scan it now. */
853 if (parse_stab_type (dhandle, info, (const char *) NULL, &p,
854 (debug_type **) NULL, string_end)
865 /* A global symbol. The value must be extracted from the
867 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
868 (debug_type **) NULL, string_end);
869 if (dtype == DEBUG_TYPE_NULL)
876 leading = bfd_get_symbol_leading_char (info->abfd);
877 for (c = info->symcount, ps = info->syms; c > 0; --c, ++ps)
881 n = bfd_asymbol_name (*ps);
882 if (leading != '\0' && *n == leading)
884 if (*n == *name && strcmp (n, name) == 0)
889 value = bfd_asymbol_value (*ps);
892 if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_GLOBAL,
898 /* This case is faked by a conditional above, when there is no
899 code letter in the dbx data. Dbx data never actually
903 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
904 (debug_type **) NULL, string_end);
905 if (dtype == DEBUG_TYPE_NULL)
907 if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_LOCAL,
913 /* A function parameter. */
915 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
916 (debug_type **) NULL, string_end);
919 /* pF is a two-letter code that means a function parameter in
920 Fortran. The type-number specifies the type of the return
921 value. Translate it into a pointer-to-function type. */
923 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
924 (debug_type **) NULL, string_end);
925 if (dtype != DEBUG_TYPE_NULL)
929 ftype = debug_make_function_type (dhandle, dtype,
930 (debug_type *) NULL, FALSE);
931 dtype = debug_make_pointer_type (dhandle, ftype);
934 if (dtype == DEBUG_TYPE_NULL)
936 if (! debug_record_parameter (dhandle, name, dtype, DEBUG_PARM_STACK,
940 /* FIXME: At this point gdb considers rearranging the parameter
941 address on a big endian machine if it is smaller than an int.
942 We have no way to do that, since we don't really know much
947 if (stabtype == N_FUN)
949 /* Prototype of a function referenced by this file. */
953 if (parse_stab_type (dhandle, info, (const char *) NULL, &p,
954 (debug_type **) NULL, string_end)
962 /* Parameter which is in a register. */
963 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
964 (debug_type **) NULL, string_end);
965 if (dtype == DEBUG_TYPE_NULL)
967 if (! debug_record_parameter (dhandle, name, dtype, DEBUG_PARM_REG,
973 /* Register variable (either global or local). */
974 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
975 (debug_type **) NULL, string_end);
976 if (dtype == DEBUG_TYPE_NULL)
978 if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_REGISTER,
982 /* FIXME: At this point gdb checks to combine pairs of 'p' and
983 'r' stabs into a single 'P' stab. */
987 /* Static symbol at top level of file. */
988 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
989 (debug_type **) NULL, string_end);
990 if (dtype == DEBUG_TYPE_NULL)
992 if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_STATIC,
999 dtype = parse_stab_type (dhandle, info, name, &p, &slot, string_end);
1000 if (dtype == DEBUG_TYPE_NULL)
1004 /* A nameless type. Nothing to do. */
1008 dtype = debug_name_type (dhandle, name, dtype);
1009 if (dtype == DEBUG_TYPE_NULL)
1018 /* Struct, union, or enum tag. For GNU C++, this can be followed
1019 by 't' which means we are typedef'ing it as well. */
1023 /* FIXME: gdb sets synonym to TRUE if the current language
1032 dtype = parse_stab_type (dhandle, info, name, &p, &slot, string_end);
1033 if (dtype == DEBUG_TYPE_NULL)
1038 /* INFO->SELF_CROSSREF is set by parse_stab_type if this type is
1039 a cross reference to itself. These are generated by some
1041 self_crossref = info->self_crossref;
1043 dtype = debug_tag_type (dhandle, name, dtype);
1044 if (dtype == DEBUG_TYPE_NULL)
1049 /* See if we have a cross reference to this tag which we can now
1050 fill in. Avoid filling in a cross reference to ourselves,
1051 because that would lead to circular debugging information. */
1052 if (! self_crossref)
1054 register struct stab_tag **pst;
1056 for (pst = &info->tags; *pst != NULL; pst = &(*pst)->next)
1058 if ((*pst)->name[0] == name[0]
1059 && strcmp ((*pst)->name, name) == 0)
1061 (*pst)->slot = dtype;
1062 *pst = (*pst)->next;
1070 dtype = debug_name_type (dhandle, name, dtype);
1071 if (dtype == DEBUG_TYPE_NULL)
1081 /* Static symbol of local scope */
1082 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
1083 (debug_type **) NULL, string_end);
1084 if (dtype == DEBUG_TYPE_NULL)
1086 /* FIXME: gdb checks os9k_stabs here. */
1087 if (! stab_record_variable (dhandle, info, name, dtype,
1088 DEBUG_LOCAL_STATIC, value))
1093 /* Reference parameter. */
1094 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
1095 (debug_type **) NULL, string_end);
1096 if (dtype == DEBUG_TYPE_NULL)
1098 if (! debug_record_parameter (dhandle, name, dtype, DEBUG_PARM_REFERENCE,
1104 /* Reference parameter which is in a register. */
1105 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
1106 (debug_type **) NULL, string_end);
1107 if (dtype == DEBUG_TYPE_NULL)
1109 if (! debug_record_parameter (dhandle, name, dtype, DEBUG_PARM_REF_REG,
1115 /* This is used by Sun FORTRAN for "function result value".
1116 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
1117 that Pascal uses it too, but when I tried it Pascal used
1118 "x:3" (local symbol) instead. */
1119 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
1120 (debug_type **) NULL, string_end);
1121 if (dtype == DEBUG_TYPE_NULL)
1123 if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_LOCAL,
1129 /* SUNPro C++ Namespace =Yn0. */
1130 /* Skip the namespace mapping, as it is not used now. */
1131 if (*(++p) == 'n' && *(++p) == '0')
1139 /* TODO SUNPro C++ support:
1140 Support default arguments after F,P parameters
1141 Ya = Anonymous unions
1142 YM,YD = Pointers to class members
1144 YR = Run-time type information (RTTI) */
1153 /* FIXME: gdb converts structure values to structure pointers in a
1154 couple of cases, depending upon the target. */
1159 /* Parse a stabs type. The typename argument is non-NULL if this is a
1160 typedef or a tag definition. The pp argument points to the stab
1161 string, and is updated. The slotp argument points to a place to
1162 store the slot used if the type is being defined. */
1165 parse_stab_type (void * dhandle,
1166 struct stab_handle * info,
1167 const char * type_name,
1169 debug_type ** slotp,
1175 bfd_boolean stringp;
1184 return DEBUG_TYPE_NULL;
1189 info->self_crossref = FALSE;
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 (**pp) && **pp != '(' && **pp != '-')
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;
1202 if (! parse_stab_type_number (pp, typenums, p_end))
1203 return DEBUG_TYPE_NULL;
1206 /* Type is not being defined here. Either it already
1207 exists, or this is a forward reference to it. */
1208 return stab_find_type (dhandle, info, typenums);
1210 /* Only set the slot if the type is being defined. This means
1211 that the mapping from type numbers to types will only record
1212 the name of the typedef which defines a type. If we don't do
1213 this, then something like
1216 will record that i is of type foo. Unfortunately, stabs
1217 information is ambiguous about variable types. For this code,
1221 the stabs information records both i and j as having the same
1222 type. This could be fixed by patching the compiler. */
1223 if (slotp != NULL && typenums[0] >= 0 && typenums[1] >= 0)
1224 *slotp = stab_find_slot (info, typenums);
1226 /* Type is being defined here. */
1232 const char *p = *pp + 1;
1235 if (ISDIGIT (*p) || *p == '(' || *p == '-')
1239 /* Type attributes. */
1242 for (; *p != ';'; ++p)
1247 return DEBUG_TYPE_NULL;
1255 size = atoi (attr + 1);
1256 size /= 8; /* Size is in bits. We store it in bytes. */
1267 return DEBUG_TYPE_NULL;
1270 /* Ignore unrecognized type attributes, so future
1271 compilers can invent new ones. */
1284 enum debug_type_kind code;
1285 const char *q1, *q2, *p;
1287 /* A cross reference to another type. */
1291 code = DEBUG_KIND_STRUCT;
1294 code = DEBUG_KIND_UNION;
1297 code = DEBUG_KIND_ENUM;
1301 return DEBUG_TYPE_NULL;
1304 /* Complain and keep going, so compilers can invent new
1305 cross-reference types. */
1306 warn_stab (orig, _("unrecognized cross reference type"));
1307 code = DEBUG_KIND_STRUCT;
1312 q1 = strchr (*pp, '<');
1313 p = strchr (*pp, ':');
1317 return DEBUG_TYPE_NULL;
1319 if (q1 != NULL && p > q1 && p[1] == ':')
1323 for (q2 = q1; *q2 != '\0'; ++q2)
1327 else if (*q2 == '>')
1329 else if (*q2 == ':' && nest == 0)
1336 return DEBUG_TYPE_NULL;
1340 /* Some versions of g++ can emit stabs like
1342 which define structures in terms of themselves. We need to
1343 tell the caller to avoid building a circular structure. */
1344 if (type_name != NULL
1345 && strncmp (type_name, *pp, p - *pp) == 0
1346 && type_name[p - *pp] == '\0')
1347 info->self_crossref = TRUE;
1349 dtype = stab_find_tagged_type (dhandle, info, *pp, p - *pp, code);
1371 /* This type is defined as another type. */
1375 /* Peek ahead at the number to detect void. */
1376 if (! parse_stab_type_number (pp, xtypenums, p_end))
1377 return DEBUG_TYPE_NULL;
1379 if (typenums[0] == xtypenums[0] && typenums[1] == xtypenums[1])
1381 /* This type is being defined as itself, which means that
1383 dtype = debug_make_void_type (dhandle);
1389 /* Go back to the number and have parse_stab_type get it.
1390 This means that we can deal with something like
1391 t(1,2)=(3,4)=... which the Lucid compiler uses. */
1392 dtype = parse_stab_type (dhandle, info, (const char *) NULL,
1393 pp, (debug_type **) NULL, p_end);
1394 if (dtype == DEBUG_TYPE_NULL)
1395 return DEBUG_TYPE_NULL;
1398 if (typenums[0] != -1)
1400 if (! stab_record_type (dhandle, info, typenums, dtype))
1401 return DEBUG_TYPE_NULL;
1408 dtype = debug_make_pointer_type (dhandle,
1409 parse_stab_type (dhandle, info,
1410 (const char *) NULL,
1412 (debug_type **) NULL,
1417 /* Reference to another type. */
1418 dtype = (debug_make_reference_type
1420 parse_stab_type (dhandle, info, (const char *) NULL, pp,
1421 (debug_type **) NULL, p_end)));
1425 /* Function returning another type. */
1426 /* FIXME: gdb checks os9k_stabs here. */
1427 dtype = (debug_make_function_type
1429 parse_stab_type (dhandle, info, (const char *) NULL, pp,
1430 (debug_type **) NULL, p_end),
1431 (debug_type *) NULL, FALSE));
1435 /* Const qualifier on some type (Sun). */
1436 /* FIXME: gdb accepts 'c' here if os9k_stabs. */
1437 dtype = debug_make_const_type (dhandle,
1438 parse_stab_type (dhandle, info,
1439 (const char *) NULL,
1441 (debug_type **) NULL,
1446 /* Volatile qual on some type (Sun). */
1447 /* FIXME: gdb accepts 'i' here if os9k_stabs. */
1448 dtype = (debug_make_volatile_type
1450 parse_stab_type (dhandle, info, (const char *) NULL, pp,
1451 (debug_type **) NULL, p_end)));
1455 /* Offset (class & variable) type. This is used for a pointer
1456 relative to an object. */
1463 domain = parse_stab_type (dhandle, info, (const char *) NULL, pp,
1464 (debug_type **) NULL, p_end);
1465 if (domain == DEBUG_TYPE_NULL)
1466 return DEBUG_TYPE_NULL;
1471 return DEBUG_TYPE_NULL;
1475 memtype = parse_stab_type (dhandle, info, (const char *) NULL, pp,
1476 (debug_type **) NULL, p_end);
1477 if (memtype == DEBUG_TYPE_NULL)
1478 return DEBUG_TYPE_NULL;
1480 dtype = debug_make_offset_type (dhandle, domain, memtype);
1485 /* Method (class & fn) type. */
1488 debug_type return_type;
1491 return_type = parse_stab_type (dhandle, info, (const char *) NULL,
1492 pp, (debug_type **) NULL, p_end);
1493 if (return_type == DEBUG_TYPE_NULL)
1494 return DEBUG_TYPE_NULL;
1498 return DEBUG_TYPE_NULL;
1501 dtype = debug_make_method_type (dhandle, return_type,
1503 (debug_type *) NULL, FALSE);
1508 debug_type return_type;
1512 bfd_boolean varargs;
1514 domain = parse_stab_type (dhandle, info, (const char *) NULL,
1515 pp, (debug_type **) NULL, p_end);
1516 if (domain == DEBUG_TYPE_NULL)
1517 return DEBUG_TYPE_NULL;
1522 return DEBUG_TYPE_NULL;
1526 return_type = parse_stab_type (dhandle, info, (const char *) NULL,
1527 pp, (debug_type **) NULL, p_end);
1528 if (return_type == DEBUG_TYPE_NULL)
1529 return DEBUG_TYPE_NULL;
1532 args = (debug_type *) xmalloc (alloc * sizeof *args);
1539 return DEBUG_TYPE_NULL;
1546 args = ((debug_type *)
1547 xrealloc (args, alloc * sizeof *args));
1550 args[n] = parse_stab_type (dhandle, info, (const char *) NULL,
1551 pp, (debug_type **) NULL, p_end);
1552 if (args[n] == DEBUG_TYPE_NULL)
1553 return DEBUG_TYPE_NULL;
1558 /* If the last type is not void, then this function takes a
1559 variable number of arguments. Otherwise, we must strip
1562 || debug_get_type_kind (dhandle, args[n - 1]) != DEBUG_KIND_VOID)
1570 args[n] = DEBUG_TYPE_NULL;
1572 dtype = debug_make_method_type (dhandle, return_type, domain, args,
1579 dtype = parse_stab_range_type (dhandle, info, type_name, pp, typenums, p_end);
1583 /* FIXME: gdb checks os9k_stabs here. */
1584 /* Sun ACC builtin int type. */
1585 dtype = parse_stab_sun_builtin_type (dhandle, pp, p_end);
1589 /* Sun ACC builtin float type. */
1590 dtype = parse_stab_sun_floating_type (dhandle, pp, p_end);
1594 /* Enumeration type. */
1595 dtype = parse_stab_enum_type (dhandle, pp, p_end);
1600 /* Struct or union type. */
1601 dtype = parse_stab_struct_type (dhandle, info, type_name, pp,
1602 descriptor == 's', typenums, p_end);
1610 return DEBUG_TYPE_NULL;
1614 dtype = parse_stab_array_type (dhandle, info, pp, stringp, p_end);
1618 dtype = debug_make_set_type (dhandle,
1619 parse_stab_type (dhandle, info,
1620 (const char *) NULL,
1622 (debug_type **) NULL,
1629 return DEBUG_TYPE_NULL;
1632 if (dtype == DEBUG_TYPE_NULL)
1633 return DEBUG_TYPE_NULL;
1635 if (typenums[0] != -1)
1637 if (! stab_record_type (dhandle, info, typenums, dtype))
1638 return DEBUG_TYPE_NULL;
1643 if (! debug_record_type_size (dhandle, dtype, (unsigned int) size))
1644 return DEBUG_TYPE_NULL;
1650 /* Read a number by which a type is referred to in dbx data, or
1651 perhaps read a pair (FILENUM, TYPENUM) in parentheses. Just a
1652 single number N is equivalent to (0,N). Return the two numbers by
1653 storing them in the vector TYPENUMS. */
1656 parse_stab_type_number (const char **pp, int *typenums, const char *p_end)
1665 typenums[1] = (int) parse_number (pp, (bfd_boolean *) NULL, p_end);
1670 typenums[0] = (int) parse_number (pp, (bfd_boolean *) NULL, p_end);
1678 typenums[1] = (int) parse_number (pp, (bfd_boolean *) NULL, p_end);
1689 /* Parse a range type. */
1692 parse_stab_range_type (void * dhandle,
1693 struct stab_handle * info,
1694 const char * type_name,
1696 const int * typenums,
1701 bfd_boolean self_subrange;
1702 debug_type index_type;
1703 const char *s2, *s3;
1704 bfd_signed_vma n2, n3;
1705 bfd_boolean ov2, ov3;
1709 return DEBUG_TYPE_NULL;
1711 index_type = DEBUG_TYPE_NULL;
1713 /* First comes a type we are a subrange of.
1714 In C it is usually 0, 1 or the type being defined. */
1715 if (! parse_stab_type_number (pp, rangenums, p_end))
1716 return DEBUG_TYPE_NULL;
1718 self_subrange = (rangenums[0] == typenums[0]
1719 && rangenums[1] == typenums[1]);
1724 index_type = parse_stab_type (dhandle, info, (const char *) NULL,
1725 pp, (debug_type **) NULL, p_end);
1726 if (index_type == DEBUG_TYPE_NULL)
1727 return DEBUG_TYPE_NULL;
1733 /* The remaining two operands are usually lower and upper bounds of
1734 the range. But in some special cases they mean something else. */
1736 n2 = parse_number (pp, &ov2, p_end);
1740 return DEBUG_TYPE_NULL;
1745 n3 = parse_number (pp, &ov3, p_end);
1749 return DEBUG_TYPE_NULL;
1755 /* gcc will emit range stabs for long long types. Handle this
1756 as a special case. FIXME: This needs to be more general. */
1757 #define LLLOW "01000000000000000000000;"
1758 #define LLHIGH "0777777777777777777777;"
1759 #define ULLHIGH "01777777777777777777777;"
1760 if (index_type == DEBUG_TYPE_NULL)
1762 if (CONST_STRNEQ (s2, LLLOW)
1763 && CONST_STRNEQ (s3, LLHIGH))
1764 return debug_make_int_type (dhandle, 8, FALSE);
1767 && CONST_STRNEQ (s3, ULLHIGH))
1768 return debug_make_int_type (dhandle, 8, TRUE);
1771 warn_stab (orig, _("numeric overflow"));
1774 if (index_type == DEBUG_TYPE_NULL)
1776 /* A type defined as a subrange of itself, with both bounds 0,
1778 if (self_subrange && n2 == 0 && n3 == 0)
1779 return debug_make_void_type (dhandle);
1781 /* A type defined as a subrange of itself, with n2 positive and
1782 n3 zero, is a complex type, and n2 is the number of bytes. */
1783 if (self_subrange && n3 == 0 && n2 > 0)
1784 return debug_make_complex_type (dhandle, n2);
1786 /* If n3 is zero and n2 is positive, this is a floating point
1787 type, and n2 is the number of bytes. */
1788 if (n3 == 0 && n2 > 0)
1789 return debug_make_float_type (dhandle, n2);
1791 /* If the upper bound is -1, this is an unsigned int. */
1792 if (n2 == 0 && n3 == -1)
1794 /* When gcc is used with -gstabs, but not -gstabs+, it will emit
1795 long long int:t6=r1;0;-1;
1796 long long unsigned int:t7=r1;0;-1;
1797 We hack here to handle this reasonably. */
1798 if (type_name != NULL)
1800 if (strcmp (type_name, "long long int") == 0)
1801 return debug_make_int_type (dhandle, 8, FALSE);
1802 else if (strcmp (type_name, "long long unsigned int") == 0)
1803 return debug_make_int_type (dhandle, 8, TRUE);
1805 /* FIXME: The size here really depends upon the target. */
1806 return debug_make_int_type (dhandle, 4, TRUE);
1809 /* A range of 0 to 127 is char. */
1810 if (self_subrange && n2 == 0 && n3 == 127)
1811 return debug_make_int_type (dhandle, 1, FALSE);
1813 /* FIXME: gdb checks for the language CHILL here. */
1818 return debug_make_int_type (dhandle, - n3, TRUE);
1819 else if (n3 == 0xff)
1820 return debug_make_int_type (dhandle, 1, TRUE);
1821 else if (n3 == 0xffff)
1822 return debug_make_int_type (dhandle, 2, TRUE);
1823 else if (n3 == (bfd_signed_vma) 0xffffffff)
1824 return debug_make_int_type (dhandle, 4, TRUE);
1826 else if (n3 == (bfd_signed_vma) 0xffffffffffffffffLL)
1827 return debug_make_int_type (dhandle, 8, TRUE);
1832 && (self_subrange || n2 == -8))
1833 return debug_make_int_type (dhandle, - n2, TRUE);
1834 else if (n2 == - n3 - 1 || n2 == n3 + 1)
1837 return debug_make_int_type (dhandle, 1, FALSE);
1838 else if (n3 == 0x7fff)
1839 return debug_make_int_type (dhandle, 2, FALSE);
1840 else if (n3 == 0x7fffffff)
1841 return debug_make_int_type (dhandle, 4, FALSE);
1843 else if (n3 == ((((bfd_vma) 0x7fffffff) << 32) | 0xffffffff))
1844 return debug_make_int_type (dhandle, 8, FALSE);
1849 /* At this point I don't have the faintest idea how to deal with a
1850 self_subrange type; I'm going to assume that this is used as an
1851 idiom, and that all of them are special cases. So . . . */
1855 return DEBUG_TYPE_NULL;
1858 index_type = stab_find_type (dhandle, info, rangenums);
1859 if (index_type == DEBUG_TYPE_NULL)
1861 /* Does this actually ever happen? Is that why we are worrying
1862 about dealing with it rather than just calling error_type? */
1863 warn_stab (orig, _("missing index type"));
1864 index_type = debug_make_int_type (dhandle, 4, FALSE);
1867 return debug_make_range_type (dhandle, index_type, n2, n3);
1870 /* Sun's ACC uses a somewhat saner method for specifying the builtin
1871 typedefs in every file (for int, long, etc):
1873 type = b <signed> <width>; <offset>; <nbits>
1874 signed = u or s. Possible c in addition to u or s (for char?).
1875 offset = offset from high order bit to start bit of type.
1876 width is # bytes in object of this type, nbits is # bits in type.
1878 The width/offset stuff appears to be for small objects stored in
1879 larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
1883 parse_stab_sun_builtin_type (void *dhandle, const char **pp, const char * p_end)
1886 bfd_boolean unsignedp;
1891 return DEBUG_TYPE_NULL;
1903 return DEBUG_TYPE_NULL;
1907 /* OpenSolaris source code indicates that one of "cbv" characters
1908 can come next and specify the intrinsic 'iformat' encoding.
1909 'c' is character encoding, 'b' is boolean encoding, and 'v' is
1910 varargs encoding. This field can be safely ignored because
1911 the type of the field is determined from the bitwidth extracted
1913 if (**pp == 'c' || **pp == 'b' || **pp == 'v')
1916 /* The first number appears to be the number of bytes occupied
1917 by this type, except that unsigned short is 4 instead of 2.
1918 Since this information is redundant with the third number,
1919 we will ignore it. */
1920 (void) parse_number (pp, (bfd_boolean *) NULL, p_end);
1924 return DEBUG_TYPE_NULL;
1928 /* The second number is always 0, so ignore it too. */
1929 (void) parse_number (pp, (bfd_boolean *) NULL, p_end);
1933 return DEBUG_TYPE_NULL;
1937 /* The third number is the number of bits for this type. */
1938 bits = parse_number (pp, (bfd_boolean *) NULL, p_end);
1940 /* The type *should* end with a semicolon. If it are embedded
1941 in a larger type the semicolon may be the only way to know where
1942 the type ends. If this type is at the end of the stabstring we
1943 can deal with the omitted semicolon (but we don't have to like
1944 it). Don't bother to complain(), Sun's compiler omits the semicolon
1950 return debug_make_void_type (dhandle);
1952 return debug_make_int_type (dhandle, bits / 8, unsignedp);
1955 /* Parse a builtin floating type generated by the Sun compiler. */
1958 parse_stab_sun_floating_type (void *dhandle, const char **pp, const char *p_end)
1966 return DEBUG_TYPE_NULL;
1968 /* The first number has more details about the type, for example
1970 details = parse_number (pp, (bfd_boolean *) NULL, p_end);
1974 return DEBUG_TYPE_NULL;
1977 /* The second number is the number of bytes occupied by this type */
1978 bytes = parse_number (pp, (bfd_boolean *) NULL, p_end);
1982 return DEBUG_TYPE_NULL;
1985 if (details == NF_COMPLEX
1986 || details == NF_COMPLEX16
1987 || details == NF_COMPLEX32)
1988 return debug_make_complex_type (dhandle, bytes);
1990 return debug_make_float_type (dhandle, bytes);
1993 /* Handle an enum type. */
1996 parse_stab_enum_type (void *dhandle, const char **pp, const char * p_end)
2000 bfd_signed_vma *values;
2006 return DEBUG_TYPE_NULL;
2008 /* FIXME: gdb checks os9k_stabs here. */
2010 /* The aix4 compiler emits an extra field before the enum members;
2011 my guess is it's a type of some sort. Just ignore it. */
2014 while (**pp != ':' && **pp != 0)
2020 return DEBUG_TYPE_NULL;
2025 /* Read the value-names and their values.
2026 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
2027 A semicolon or comma instead of a NAME means the end. */
2029 names = (const char **) xmalloc (alloc * sizeof *names);
2030 values = (bfd_signed_vma *) xmalloc (alloc * sizeof *values);
2032 while (**pp != '\0' && **pp != ';' && **pp != ',')
2039 while (*p != ':' && *p != 0)
2047 return DEBUG_TYPE_NULL;
2050 name = savestring (*pp, p - *pp);
2053 val = (bfd_signed_vma) parse_number (pp, (bfd_boolean *) NULL, p_end);
2060 return DEBUG_TYPE_NULL;
2067 names = ((const char **)
2068 xrealloc (names, alloc * sizeof *names));
2069 values = ((bfd_signed_vma *)
2070 xrealloc (values, alloc * sizeof *values));
2084 return debug_make_enum_type (dhandle, names, values);
2087 /* Read the description of a structure (or union type) and return an object
2088 describing the type.
2090 PP points to a character pointer that points to the next unconsumed token
2091 in the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;",
2092 *PP will point to "4a:1,0,32;;". */
2095 parse_stab_struct_type (void * dhandle,
2096 struct stab_handle * info,
2097 const char * tagname,
2099 bfd_boolean structp,
2100 const int * typenums,
2104 debug_baseclass *baseclasses;
2105 debug_field *fields = NULL;
2106 bfd_boolean statics;
2107 debug_method *methods;
2108 debug_type vptrbase;
2109 bfd_boolean ownvptr;
2112 size = parse_number (pp, (bfd_boolean *) NULL, p_end);
2114 /* Get the other information. */
2115 if (! parse_stab_baseclasses (dhandle, info, pp, &baseclasses, p_end)
2116 || ! parse_stab_struct_fields (dhandle, info, pp, &fields, &statics, p_end)
2117 || ! parse_stab_members (dhandle, info, tagname, pp, typenums, &methods, p_end)
2118 || ! parse_stab_tilde_field (dhandle, info, pp, typenums, &vptrbase,
2123 return DEBUG_TYPE_NULL;
2127 && baseclasses == NULL
2129 && vptrbase == DEBUG_TYPE_NULL
2131 return debug_make_struct_type (dhandle, structp, size, fields);
2133 return debug_make_object_type (dhandle, structp, size, fields, baseclasses,
2134 methods, vptrbase, ownvptr);
2137 /* The stabs for C++ derived classes contain baseclass information which
2138 is marked by a '!' character after the total size. This function is
2139 called when we encounter the baseclass marker, and slurps up all the
2140 baseclass information.
2142 Immediately following the '!' marker is the number of base classes that
2143 the class is derived from, followed by information for each base class.
2144 For each base class, there are two visibility specifiers, a bit offset
2145 to the base class information within the derived class, a reference to
2146 the type for the base class, and a terminating semicolon.
2148 A typical example, with two base classes, would be "!2,020,19;0264,21;".
2150 Baseclass information marker __________________|| | | | | | |
2151 Number of baseclasses __________________________| | | | | | |
2152 Visibility specifiers (2) ________________________| | | | | |
2153 Offset in bits from start of class _________________| | | | |
2154 Type number for base class ___________________________| | | |
2155 Visibility specifiers (2) _______________________________| | |
2156 Offset in bits from start of class ________________________| |
2157 Type number of base class ____________________________________|
2159 Return TRUE for success, FALSE for failure. */
2162 parse_stab_baseclasses (void * dhandle,
2163 struct stab_handle * info,
2165 debug_baseclass ** retp,
2170 debug_baseclass *classes;
2180 /* No base classes. */
2185 c = (unsigned int) parse_number (pp, (bfd_boolean *) NULL, p_end);
2194 classes = (debug_baseclass *) xmalloc ((c + 1) * sizeof (**retp));
2196 for (i = 0; i < c; i++)
2198 bfd_boolean is_virtual;
2199 enum debug_visibility visibility;
2215 warn_stab (orig, _("unknown virtual character for baseclass"));
2224 visibility = DEBUG_VISIBILITY_PRIVATE;
2227 visibility = DEBUG_VISIBILITY_PROTECTED;
2230 visibility = DEBUG_VISIBILITY_PUBLIC;
2236 warn_stab (orig, _("unknown visibility character for baseclass"));
2237 visibility = DEBUG_VISIBILITY_PUBLIC;
2242 /* The remaining value is the bit offset of the portion of the
2243 object corresponding to this baseclass. Always zero in the
2244 absence of multiple inheritance. */
2245 bitpos = parse_number (pp, (bfd_boolean *) NULL, p_end);
2253 type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
2254 (debug_type **) NULL, p_end);
2255 if (type == DEBUG_TYPE_NULL)
2258 classes[i] = debug_make_baseclass (dhandle, type, bitpos, is_virtual,
2260 if (classes[i] == DEBUG_BASECLASS_NULL)
2268 classes[i] = DEBUG_BASECLASS_NULL;
2275 /* Read struct or class data fields. They have the form:
2277 NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
2279 At the end, we see a semicolon instead of a field.
2281 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
2284 The optional VISIBILITY is one of:
2286 '/0' (VISIBILITY_PRIVATE)
2287 '/1' (VISIBILITY_PROTECTED)
2288 '/2' (VISIBILITY_PUBLIC)
2289 '/9' (VISIBILITY_IGNORE)
2291 or nothing, for C style fields with public visibility.
2293 Returns 1 for success, 0 for failure. */
2296 parse_stab_struct_fields (void * dhandle,
2297 struct stab_handle * info,
2299 debug_field ** retp,
2300 bfd_boolean * staticsp,
2305 debug_field *fields;
2318 fields = (debug_field *) xmalloc (alloc * sizeof *fields);
2321 /* FIXME: gdb checks os9k_stabs here. */
2325 /* Add 1 to c to leave room for NULL pointer at end. */
2329 fields = ((debug_field *)
2330 xrealloc (fields, alloc * sizeof *fields));
2333 /* If it starts with CPLUS_MARKER it is a special abbreviation,
2334 unless the CPLUS_MARKER is followed by an underscore, in
2335 which case it is just the name of an anonymous type, which we
2336 should handle like any other type name. We accept either '$'
2337 or '.', because a field name can never contain one of these
2338 characters except as a CPLUS_MARKER. */
2340 if ((*p == '$' || *p == '.') && p[1] != '_')
2343 if (! parse_stab_cpp_abbrev (dhandle, info, pp, fields + c, p_end))
2352 /* Look for the ':' that separates the field name from the field
2353 values. Data members are delimited by a single ':', while member
2354 functions are delimited by a pair of ':'s. When we hit the member
2355 functions (if any), terminate scan loop and return. */
2357 p = strchr (p, ':');
2368 if (! parse_stab_one_struct_field (dhandle, info, pp, p, fields + c,
2375 fields[c] = DEBUG_FIELD_NULL;
2382 /* Special GNU C++ name. */
2385 parse_stab_cpp_abbrev (void * dhandle,
2386 struct stab_handle * info,
2395 const char *type_name;
2399 *retp = DEBUG_FIELD_NULL;
2413 if (cpp_abbrev == 0)
2420 /* At this point, *pp points to something like "22:23=*22...", where
2421 the type number before the ':' is the "context" and everything
2422 after is a regular type definition. Lookup the type, find it's
2423 name, and construct the field name. */
2425 context = parse_stab_type (dhandle, info, (const char *) NULL, pp,
2426 (debug_type **) NULL, p_end);
2427 if (context == DEBUG_TYPE_NULL)
2433 /* $vf -- a virtual function table pointer. */
2437 /* $vb -- a virtual bsomethingorother */
2438 type_name = debug_get_type_name (dhandle, context);
2439 if (type_name == NULL)
2441 warn_stab (orig, _("unnamed $vb type"));
2444 name = concat ("_vb$", type_name, (const char *) NULL);
2447 warn_stab (orig, _("unrecognized C++ abbreviation"));
2448 name = "INVALID_CPLUSPLUS_ABBREV";
2459 type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
2460 (debug_type **) NULL, p_end);
2468 bitpos = parse_number (pp, (bfd_boolean *) NULL, p_end);
2476 *retp = debug_make_field (dhandle, name, type, bitpos, 0,
2477 DEBUG_VISIBILITY_PRIVATE);
2478 if (*retp == DEBUG_FIELD_NULL)
2484 /* Parse a single field in a struct or union. */
2487 parse_stab_one_struct_field (void * dhandle,
2488 struct stab_handle * info,
2492 bfd_boolean * staticsp,
2497 enum debug_visibility visibility;
2506 /* FIXME: gdb checks ARM_DEMANGLING here. */
2508 name = savestring (*pp, p - *pp);
2513 visibility = DEBUG_VISIBILITY_PUBLIC;
2520 visibility = DEBUG_VISIBILITY_PRIVATE;
2523 visibility = DEBUG_VISIBILITY_PROTECTED;
2526 visibility = DEBUG_VISIBILITY_PUBLIC;
2532 warn_stab (orig, _("unknown visibility character for field"));
2533 visibility = DEBUG_VISIBILITY_PUBLIC;
2539 type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
2540 (debug_type **) NULL, p_end);
2541 if (type == DEBUG_TYPE_NULL)
2551 /* This is a static class member. */
2553 p = strchr (*pp, ';');
2561 varname = savestring (*pp, p - *pp);
2565 *retp = debug_make_static_member (dhandle, name, type, varname,
2580 bitpos = parse_number (pp, (bfd_boolean *) NULL, p_end);
2589 bitsize = parse_number (pp, (bfd_boolean *) NULL, p_end);
2598 if (bitpos == 0 && bitsize == 0)
2600 /* This can happen in two cases: (1) at least for gcc 2.4.5 or
2601 so, it is a field which has been optimized out. The correct
2602 stab for this case is to use VISIBILITY_IGNORE, but that is a
2603 recent invention. (2) It is a 0-size array. For example
2604 union { int num; char str[0]; } foo. Printing "<no value>"
2605 for str in "p foo" is OK, since foo.str (and thus foo.str[3])
2606 will continue to work, and a 0-size array as a whole doesn't
2607 have any contents to print.
2609 I suspect this probably could also happen with gcc -gstabs
2610 (not -gstabs+) for static fields, and perhaps other C++
2611 extensions. Hopefully few people use -gstabs with gdb, since
2612 it is intended for dbx compatibility. */
2613 visibility = DEBUG_VISIBILITY_IGNORE;
2616 /* FIXME: gdb does some stuff here to mark fields as unpacked. */
2618 *retp = debug_make_field (dhandle, name, type, bitpos, bitsize, visibility);
2623 /* Read member function stabs info for C++ classes. The form of each member
2626 NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;
2628 An example with two member functions is:
2630 afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;
2632 For the case of overloaded operators, the format is op$::*.funcs, where
2633 $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
2634 name (such as `+=') and `.' marks the end of the operator name. */
2637 parse_stab_members (void * dhandle,
2638 struct stab_handle * info,
2639 const char * tagname,
2641 const int * typenums,
2642 debug_method ** retp,
2646 debug_method *methods;
2650 debug_method_variant *variants = NULL;
2651 char *argtypes = NULL;
2667 unsigned int allocvars;
2668 debug_type look_ahead_type;
2670 p = strchr (*pp, ':');
2671 if (p == NULL || p[1] != ':')
2674 /* FIXME: Some systems use something other than '$' here. */
2675 if ((*pp)[0] != 'o' || (*pp)[1] != 'p' || (*pp)[2] != '$')
2677 name = savestring (*pp, p - *pp);
2682 /* This is a completely weird case. In order to stuff in the
2683 names that might contain colons (the usual name delimiter),
2684 Mike Tiemann defined a different name format which is
2685 signalled if the identifier is "op$". In that case, the
2686 format is "op$::XXXX." where XXXX is the name. This is
2687 used for names like "+" or "=". YUUUUUUUK! FIXME! */
2689 for (p = *pp; *p != '.' && *p != '\0'; p++)
2696 name = savestring (*pp, p - *pp);
2701 variants = ((debug_method_variant *)
2702 xmalloc (allocvars * sizeof *variants));
2705 look_ahead_type = DEBUG_TYPE_NULL;
2711 enum debug_visibility visibility;
2712 bfd_boolean constp, volatilep, staticp;
2715 const char *physname;
2716 bfd_boolean varargs;
2718 if (look_ahead_type != DEBUG_TYPE_NULL)
2720 /* g++ version 1 kludge */
2721 type = look_ahead_type;
2722 look_ahead_type = DEBUG_TYPE_NULL;
2726 type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
2727 (debug_type **) NULL, p_end);
2728 if (type == DEBUG_TYPE_NULL)
2739 p = strchr (*pp, ';');
2747 if (debug_get_type_kind (dhandle, type) == DEBUG_KIND_METHOD
2748 && debug_get_parameter_types (dhandle, type, &varargs) == NULL)
2751 argtypes = savestring (*pp, p - *pp);
2757 visibility = DEBUG_VISIBILITY_PRIVATE;
2760 visibility = DEBUG_VISIBILITY_PROTECTED;
2766 visibility = DEBUG_VISIBILITY_PUBLIC;
2776 /* Normal function. */
2780 /* const member function. */
2785 /* volatile member function. */
2790 /* const volatile member function. */
2798 /* File compiled with g++ version 1; no information. */
2801 warn_stab (orig, _("const/volatile indicator missing"));
2809 /* virtual member function, followed by index. The sign
2810 bit is supposedly set to distinguish
2811 pointers-to-methods from virtual function indices. */
2813 voffset = parse_number (pp, (bfd_boolean *) NULL, p_end);
2820 voffset &= 0x7fffffff;
2822 if (**pp == ';' || **pp == '\0')
2824 /* Must be g++ version 1. */
2825 context = DEBUG_TYPE_NULL;
2829 /* Figure out from whence this virtual function
2830 came. It may belong to virtual function table of
2831 one of its baseclasses. */
2832 look_ahead_type = parse_stab_type (dhandle, info,
2833 (const char *) NULL,
2835 (debug_type **) NULL,
2839 /* g++ version 1 overloaded methods. */
2840 context = DEBUG_TYPE_NULL;
2844 context = look_ahead_type;
2845 look_ahead_type = DEBUG_TYPE_NULL;
2857 /* static member function. */
2861 context = DEBUG_TYPE_NULL;
2862 if (strncmp (argtypes, name, strlen (name)) != 0)
2867 warn_stab (orig, "member function type missing");
2869 context = DEBUG_TYPE_NULL;
2875 context = DEBUG_TYPE_NULL;
2879 /* If the type is not a stub, then the argtypes string is
2880 the physical name of the function. Otherwise the
2881 argtypes string is the mangled form of the argument
2882 types, and the full type and the physical name must be
2883 extracted from them. */
2884 physname = argtypes;
2887 debug_type class_type, return_type;
2889 class_type = stab_find_type (dhandle, info, typenums);
2890 if (class_type == DEBUG_TYPE_NULL)
2892 return_type = debug_get_return_type (dhandle, type);
2893 if (return_type == DEBUG_TYPE_NULL)
2898 type = parse_stab_argtypes (dhandle, info, class_type, name,
2899 tagname, return_type, argtypes,
2900 constp, volatilep, &physname);
2901 if (type == DEBUG_TYPE_NULL)
2905 if (cvars + 1 >= allocvars)
2908 variants = ((debug_method_variant *)
2910 allocvars * sizeof *variants));
2914 variants[cvars] = debug_make_method_variant (dhandle, physname,
2919 variants[cvars] = debug_make_static_method_variant (dhandle,
2925 if (variants[cvars] == DEBUG_METHOD_VARIANT_NULL)
2930 while (**pp != ';' && **pp != '\0');
2932 variants[cvars] = DEBUG_METHOD_VARIANT_NULL;
2940 methods = ((debug_method *)
2941 xrealloc (methods, alloc * sizeof *methods));
2944 methods[c] = debug_make_method (dhandle, name, variants);
2949 if (methods != NULL)
2950 methods[c] = DEBUG_METHOD_NULL;
2959 if (variants != NULL)
2961 if (argtypes != NULL)
2966 /* Parse a string representing argument types for a method. Stabs
2967 tries to save space by packing argument types into a mangled
2968 string. This string should give us enough information to extract
2969 both argument types and the physical name of the function, given
2973 parse_stab_argtypes (void *dhandle, struct stab_handle *info,
2974 debug_type class_type, const char *fieldname,
2975 const char *tagname, debug_type return_type,
2976 const char *argtypes, bfd_boolean constp,
2977 bfd_boolean volatilep, const char **pphysname)
2979 bfd_boolean is_full_physname_constructor;
2980 bfd_boolean is_constructor;
2981 bfd_boolean is_destructor;
2984 bfd_boolean varargs;
2985 unsigned int physname_len = 0;
2987 /* Constructors are sometimes handled specially. */
2988 is_full_physname_constructor = ((argtypes[0] == '_'
2989 && argtypes[1] == '_'
2990 && (ISDIGIT (argtypes[2])
2991 || argtypes[2] == 'Q'
2992 || argtypes[2] == 't'))
2993 || CONST_STRNEQ (argtypes, "__ct"));
2995 is_constructor = (is_full_physname_constructor
2997 && strcmp (fieldname, tagname) == 0));
2998 is_destructor = ((argtypes[0] == '_'
2999 && (argtypes[1] == '$' || argtypes[1] == '.')
3000 && argtypes[2] == '_')
3001 || CONST_STRNEQ (argtypes, "__dt"));
3002 is_v3 = argtypes[0] == '_' && argtypes[1] == 'Z';
3004 if (!(is_destructor || is_full_physname_constructor || is_v3))
3007 const char *const_prefix;
3008 const char *volatile_prefix;
3010 unsigned int mangled_name_len;
3013 len = tagname == NULL ? 0 : strlen (tagname);
3014 const_prefix = constp ? "C" : "";
3015 volatile_prefix = volatilep ? "V" : "";
3018 sprintf (buf, "__%s%s", const_prefix, volatile_prefix);
3019 else if (tagname != NULL && strchr (tagname, '<') != NULL)
3021 /* Template methods are fully mangled. */
3022 sprintf (buf, "__%s%s", const_prefix, volatile_prefix);
3027 sprintf (buf, "__%s%s%d", const_prefix, volatile_prefix, len);
3029 mangled_name_len = ((is_constructor ? 0 : strlen (fieldname))
3035 if (fieldname[0] == 'o'
3036 && fieldname[1] == 'p'
3037 && (fieldname[2] == '$' || fieldname[2] == '.'))
3041 opname = cplus_mangle_opname (fieldname + 3, 0);
3044 fprintf (stderr, _("No mangling for \"%s\"\n"), fieldname);
3045 return DEBUG_TYPE_NULL;
3047 mangled_name_len += strlen (opname);
3048 physname = (char *) xmalloc (mangled_name_len);
3049 strncpy (physname, fieldname, 3);
3050 strcpy (physname + 3, opname);
3054 physname = (char *) xmalloc (mangled_name_len);
3058 strcpy (physname, fieldname);
3061 physname_len = strlen (physname);
3062 strcat (physname, buf);
3063 if (tagname != NULL)
3064 strcat (physname, tagname);
3065 strcat (physname, argtypes);
3067 *pphysname = physname;
3070 if (*argtypes == '\0' || is_destructor)
3072 args = (debug_type *) xmalloc (sizeof *args);
3074 return debug_make_method_type (dhandle, return_type, class_type, args,
3078 args = stab_demangle_argtypes (dhandle, info, *pphysname, &varargs, physname_len);
3080 return DEBUG_TYPE_NULL;
3082 return debug_make_method_type (dhandle, return_type, class_type, args,
3086 /* The tail end of stabs for C++ classes that contain a virtual function
3087 pointer contains a tilde, a %, and a type number.
3088 The type number refers to the base class (possibly this class itself) which
3089 contains the vtable pointer for the current class.
3091 This function is called when we have parsed all the method declarations,
3092 so we can look for the vptr base class info. */
3095 parse_stab_tilde_field (void * dhandle,
3096 struct stab_handle * info,
3098 const int * typenums,
3099 debug_type * retvptrbase,
3100 bfd_boolean * retownvptr,
3107 *retvptrbase = DEBUG_TYPE_NULL;
3108 *retownvptr = FALSE;
3114 /* If we are positioned at a ';', then skip it. */
3122 if (**pp == '=' || **pp == '+' || **pp == '-')
3124 /* Obsolete flags that used to indicate the presence of
3125 constructors and/or destructors. */
3135 /* The next number is the type number of the base class (possibly
3136 our own class) which supplies the vtable for this class. */
3137 if (! parse_stab_type_number (pp, vtypenums, p_end))
3140 if (vtypenums[0] == typenums[0]
3141 && vtypenums[1] == typenums[1])
3150 vtype = parse_stab_type (dhandle, info, (const char *) NULL, pp,
3151 (debug_type **) NULL, p_end);
3152 for (p = *pp; *p != ';' && *p != '\0'; p++)
3160 *retvptrbase = vtype;
3168 /* Read a definition of an array type. */
3171 parse_stab_array_type (void * dhandle,
3172 struct stab_handle * info,
3174 bfd_boolean stringp,
3180 debug_type index_type;
3181 bfd_boolean adjustable;
3182 bfd_signed_vma lower, upper;
3183 debug_type element_type;
3185 /* Format of an array type:
3186 "ar<index type>;lower;upper;<array_contents_type>".
3187 OS9000: "arlower,upper;<array_contents_type>".
3189 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
3190 for these, produce a type like float[][]. */
3194 return DEBUG_TYPE_NULL;
3196 /* FIXME: gdb checks os9k_stabs here. */
3198 /* If the index type is type 0, we take it as int. */
3200 if (! parse_stab_type_number (&p, typenums, p_end))
3201 return DEBUG_TYPE_NULL;
3203 if (typenums[0] == 0 && typenums[1] == 0 && **pp != '=')
3205 index_type = debug_find_named_type (dhandle, "int");
3206 if (index_type == DEBUG_TYPE_NULL)
3208 index_type = debug_make_int_type (dhandle, 4, FALSE);
3209 if (index_type == DEBUG_TYPE_NULL)
3210 return DEBUG_TYPE_NULL;
3216 index_type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
3217 (debug_type **) NULL, p_end);
3223 return DEBUG_TYPE_NULL;
3229 if (! ISDIGIT (**pp) && **pp != '-' && **pp != 0)
3235 lower = (bfd_signed_vma) parse_number (pp, (bfd_boolean *) NULL, p_end);
3239 return DEBUG_TYPE_NULL;
3243 if (! ISDIGIT (**pp) && **pp != '-' && **pp != 0)
3249 upper = (bfd_signed_vma) parse_number (pp, (bfd_boolean *) NULL, p_end);
3253 return DEBUG_TYPE_NULL;
3257 element_type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
3258 (debug_type **) NULL, p_end);
3259 if (element_type == DEBUG_TYPE_NULL)
3260 return DEBUG_TYPE_NULL;
3268 return debug_make_array_type (dhandle, element_type, index_type, lower,
3272 /* This struct holds information about files we have seen using
3277 /* The next N_BINCL file. */
3278 struct bincl_file *next;
3279 /* The next N_BINCL on the stack. */
3280 struct bincl_file *next_stack;
3281 /* The file name. */
3283 /* The hash value. */
3285 /* The file index. */
3287 /* The list of types defined in this file. */
3288 struct stab_types *file_types;
3291 /* Start a new N_BINCL file, pushing it onto the stack. */
3294 push_bincl (struct stab_handle *info, const char *name, bfd_vma hash)
3296 struct bincl_file *n;
3298 n = (struct bincl_file *) xmalloc (sizeof *n);
3299 n->next = info->bincl_list;
3300 n->next_stack = info->bincl_stack;
3303 n->file = info->files;
3304 n->file_types = NULL;
3305 info->bincl_list = n;
3306 info->bincl_stack = n;
3309 info->file_types = ((struct stab_types **)
3310 xrealloc (info->file_types,
3312 * sizeof *info->file_types)));
3313 info->file_types[n->file] = NULL;
3316 /* Finish an N_BINCL file, at an N_EINCL, popping the name off the
3320 pop_bincl (struct stab_handle *info)
3322 struct bincl_file *o;
3324 o = info->bincl_stack;
3326 return info->main_filename;
3327 info->bincl_stack = o->next_stack;
3329 o->file_types = info->file_types[o->file];
3331 if (info->bincl_stack == NULL)
3332 return info->main_filename;
3333 return info->bincl_stack->name;
3336 /* Handle an N_EXCL: get the types from the corresponding N_BINCL. */
3339 find_excl (struct stab_handle *info, const char *name, bfd_vma hash)
3341 struct bincl_file *l;
3344 info->file_types = ((struct stab_types **)
3345 xrealloc (info->file_types,
3347 * sizeof *info->file_types)));
3349 for (l = info->bincl_list; l != NULL; l = l->next)
3350 if (l->hash == hash && strcmp (l->name, name) == 0)
3354 warn_stab (name, _("Undefined N_EXCL"));
3355 info->file_types[info->files - 1] = NULL;
3359 info->file_types[info->files - 1] = l->file_types;
3364 /* Handle a variable definition. gcc emits variable definitions for a
3365 block before the N_LBRAC, so we must hold onto them until we see
3366 it. The SunPRO compiler emits variable definitions after the
3367 N_LBRAC, so we can call debug_record_variable immediately. */
3370 stab_record_variable (void *dhandle, struct stab_handle *info,
3371 const char *name, debug_type type,
3372 enum debug_var_kind kind, bfd_vma val)
3374 struct stab_pending_var *v;
3376 if ((kind == DEBUG_GLOBAL || kind == DEBUG_STATIC)
3377 || ! info->within_function
3378 || (info->gcc_compiled == 0 && info->n_opt_found))
3379 return debug_record_variable (dhandle, name, type, kind, val);
3381 v = (struct stab_pending_var *) xmalloc (sizeof *v);
3382 memset (v, 0, sizeof *v);
3384 v->next = info->pending;
3394 /* Emit pending variable definitions. This is called after we see the
3395 N_LBRAC that starts the block. */
3398 stab_emit_pending_vars (void *dhandle, struct stab_handle *info)
3400 struct stab_pending_var *v;
3405 struct stab_pending_var *next;
3407 if (! debug_record_variable (dhandle, v->name, v->type, v->kind, v->val))
3415 info->pending = NULL;
3420 /* Find the slot for a type in the database. */
3423 stab_find_slot (struct stab_handle *info, const int *typenums)
3427 struct stab_types **ps;
3429 filenum = typenums[0];
3430 tindex = typenums[1];
3432 if (filenum < 0 || (unsigned int) filenum >= info->files)
3434 fprintf (stderr, _("Type file number %d out of range\n"), filenum);
3439 fprintf (stderr, _("Type index number %d out of range\n"), tindex);
3443 ps = info->file_types + filenum;
3445 while (tindex >= STAB_TYPES_SLOTS)
3449 *ps = (struct stab_types *) xmalloc (sizeof **ps);
3450 memset (*ps, 0, sizeof **ps);
3453 tindex -= STAB_TYPES_SLOTS;
3457 *ps = (struct stab_types *) xmalloc (sizeof **ps);
3458 memset (*ps, 0, sizeof **ps);
3461 return (*ps)->types + tindex;
3464 /* Find a type given a type number. If the type has not been
3465 allocated yet, create an indirect type. */
3468 stab_find_type (void *dhandle, struct stab_handle *info, const int *typenums)
3472 if (typenums[0] == 0 && typenums[1] < 0)
3474 /* A negative type number indicates an XCOFF builtin type. */
3475 return stab_xcoff_builtin_type (dhandle, info, typenums[1]);
3478 slot = stab_find_slot (info, typenums);
3480 return DEBUG_TYPE_NULL;
3482 if (*slot == DEBUG_TYPE_NULL)
3483 return debug_make_indirect_type (dhandle, slot, (const char *) NULL);
3488 /* Record that a given type number refers to a given type. */
3491 stab_record_type (void *dhandle ATTRIBUTE_UNUSED, struct stab_handle *info,
3492 const int *typenums, debug_type type)
3496 slot = stab_find_slot (info, typenums);
3500 /* gdb appears to ignore type redefinitions, so we do as well. */
3507 /* Return an XCOFF builtin type. */
3510 stab_xcoff_builtin_type (void *dhandle, struct stab_handle *info,
3516 if (typenum >= 0 || typenum < -XCOFF_TYPE_COUNT)
3518 fprintf (stderr, _("Unrecognized XCOFF type %d\n"), typenum);
3519 return DEBUG_TYPE_NULL;
3521 if (info->xcoff_types[-typenum] != NULL)
3522 return info->xcoff_types[-typenum];
3527 /* The size of this and all the other types are fixed, defined
3528 by the debugging format. */
3530 rettype = debug_make_int_type (dhandle, 4, FALSE);
3534 rettype = debug_make_int_type (dhandle, 1, FALSE);
3538 rettype = debug_make_int_type (dhandle, 2, FALSE);
3542 rettype = debug_make_int_type (dhandle, 4, FALSE);
3545 name = "unsigned char";
3546 rettype = debug_make_int_type (dhandle, 1, TRUE);
3549 name = "signed char";
3550 rettype = debug_make_int_type (dhandle, 1, FALSE);
3553 name = "unsigned short";
3554 rettype = debug_make_int_type (dhandle, 2, TRUE);
3557 name = "unsigned int";
3558 rettype = debug_make_int_type (dhandle, 4, TRUE);
3562 rettype = debug_make_int_type (dhandle, 4, TRUE);
3565 name = "unsigned long";
3566 rettype = debug_make_int_type (dhandle, 4, TRUE);
3570 rettype = debug_make_void_type (dhandle);
3573 /* IEEE single precision (32 bit). */
3575 rettype = debug_make_float_type (dhandle, 4);
3578 /* IEEE double precision (64 bit). */
3580 rettype = debug_make_float_type (dhandle, 8);
3583 /* This is an IEEE double on the RS/6000, and different machines
3584 with different sizes for "long double" should use different
3585 negative type numbers. See stabs.texinfo. */
3586 name = "long double";
3587 rettype = debug_make_float_type (dhandle, 8);
3591 rettype = debug_make_int_type (dhandle, 4, FALSE);
3595 rettype = debug_make_bool_type (dhandle, 4);
3598 name = "short real";
3599 rettype = debug_make_float_type (dhandle, 4);
3603 rettype = debug_make_float_type (dhandle, 8);
3613 rettype = debug_make_int_type (dhandle, 1, TRUE);
3617 rettype = debug_make_bool_type (dhandle, 1);
3621 rettype = debug_make_bool_type (dhandle, 2);
3625 rettype = debug_make_bool_type (dhandle, 4);
3629 rettype = debug_make_bool_type (dhandle, 4);
3632 /* Complex type consisting of two IEEE single precision values. */
3634 rettype = debug_make_complex_type (dhandle, 8);
3637 /* Complex type consisting of two IEEE double precision values. */
3638 name = "double complex";
3639 rettype = debug_make_complex_type (dhandle, 16);
3643 rettype = debug_make_int_type (dhandle, 1, FALSE);
3647 rettype = debug_make_int_type (dhandle, 2, FALSE);
3651 rettype = debug_make_int_type (dhandle, 4, FALSE);
3656 rettype = debug_make_int_type (dhandle, 2, FALSE);
3660 rettype = debug_make_int_type (dhandle, 8, FALSE);
3663 name = "unsigned long long";
3664 rettype = debug_make_int_type (dhandle, 8, TRUE);
3668 rettype = debug_make_bool_type (dhandle, 8);
3672 rettype = debug_make_int_type (dhandle, 8, FALSE);
3678 rettype = debug_name_type (dhandle, name, rettype);
3680 info->xcoff_types[-typenum] = rettype;
3685 /* Find or create a tagged type. */
3688 stab_find_tagged_type (void *dhandle, struct stab_handle *info,
3689 const char *p, int len, enum debug_type_kind kind)
3693 struct stab_tag *st;
3695 name = savestring (p, len);
3697 /* We pass DEBUG_KIND_ILLEGAL because we want all tags in the same
3698 namespace. This is right for C, and I don't know how to handle
3699 other languages. FIXME. */
3700 dtype = debug_find_tagged_type (dhandle, name, DEBUG_KIND_ILLEGAL);
3701 if (dtype != DEBUG_TYPE_NULL)
3707 /* We need to allocate an entry on the undefined tag list. */
3708 for (st = info->tags; st != NULL; st = st->next)
3710 if (st->name[0] == name[0]
3711 && strcmp (st->name, name) == 0)
3713 if (st->kind == DEBUG_KIND_ILLEGAL)
3721 st = (struct stab_tag *) xmalloc (sizeof *st);
3722 memset (st, 0, sizeof *st);
3724 st->next = info->tags;
3727 st->slot = DEBUG_TYPE_NULL;
3728 st->type = debug_make_indirect_type (dhandle, &st->slot, name);
3735 /* In order to get the correct argument types for a stubbed method, we
3736 need to extract the argument types from a C++ mangled string.
3737 Since the argument types can refer back to the return type, this
3738 means that we must demangle the entire physical name. In gdb this
3739 is done by calling cplus_demangle and running the results back
3740 through the C++ expression parser. Since we have no expression
3741 parser, we must duplicate much of the work of cplus_demangle here.
3743 We assume that GNU style demangling is used, since this is only
3744 done for method stubs, and only g++ should output that form of
3745 debugging information. */
3747 /* This structure is used to hold a pointer to type information which
3748 demangling a string. */
3750 struct stab_demangle_typestring
3752 /* The start of the type. This is not null terminated. */
3753 const char *typestring;
3754 /* The length of the type. */
3758 /* This structure is used to hold information while demangling a
3761 struct stab_demangle_info
3763 /* The debugging information handle. */
3765 /* The stab information handle. */
3766 struct stab_handle *info;
3767 /* The array of arguments we are building. */
3769 /* Whether the method takes a variable number of arguments. */
3770 bfd_boolean varargs;
3771 /* The array of types we have remembered. */
3772 struct stab_demangle_typestring *typestrings;
3773 /* The number of typestrings. */
3774 unsigned int typestring_count;
3775 /* The number of typestring slots we have allocated. */
3776 unsigned int typestring_alloc;
3779 static void stab_bad_demangle (const char *);
3780 static unsigned int stab_demangle_count (const char **);
3781 static bfd_boolean stab_demangle_get_count (const char **, unsigned int *);
3782 static bfd_boolean stab_demangle_prefix
3783 (struct stab_demangle_info *, const char **, unsigned int);
3784 static bfd_boolean stab_demangle_function_name
3785 (struct stab_demangle_info *, const char **, const char *);
3786 static bfd_boolean stab_demangle_signature
3787 (struct stab_demangle_info *, const char **);
3788 static bfd_boolean stab_demangle_qualified
3789 (struct stab_demangle_info *, const char **, debug_type *);
3790 static bfd_boolean stab_demangle_template
3791 (struct stab_demangle_info *, const char **, char **);
3792 static bfd_boolean stab_demangle_class
3793 (struct stab_demangle_info *, const char **, const char **);
3794 static bfd_boolean stab_demangle_args
3795 (struct stab_demangle_info *, const char **, debug_type **, bfd_boolean *);
3796 static bfd_boolean stab_demangle_arg
3797 (struct stab_demangle_info *, const char **, debug_type **,
3798 unsigned int *, unsigned int *);
3799 static bfd_boolean stab_demangle_type
3800 (struct stab_demangle_info *, const char **, debug_type *);
3801 static bfd_boolean stab_demangle_fund_type
3802 (struct stab_demangle_info *, const char **, debug_type *);
3803 static bfd_boolean stab_demangle_remember_type
3804 (struct stab_demangle_info *, const char *, int);
3806 /* Warn about a bad demangling. */
3809 stab_bad_demangle (const char *s)
3811 fprintf (stderr, _("bad mangled name `%s'\n"), s);
3814 /* Get a count from a stab string. */
3817 stab_demangle_count (const char **pp)
3822 while (ISDIGIT (**pp))
3825 count += **pp - '0';
3831 /* Require a count in a string. The count may be multiple digits, in
3832 which case it must end in an underscore. */
3835 stab_demangle_get_count (const char **pp, unsigned int *pi)
3837 if (! ISDIGIT (**pp))
3855 while (ISDIGIT (*p));
3866 /* This function demangles a physical name, returning a NULL
3867 terminated array of argument types. */
3870 stab_demangle_argtypes (void *dhandle, struct stab_handle *info,
3871 const char *physname, bfd_boolean *pvarargs,
3872 unsigned int physname_len)
3874 struct stab_demangle_info minfo;
3876 /* Check for the g++ V3 ABI. */
3877 if (physname[0] == '_' && physname[1] == 'Z')
3878 return stab_demangle_v3_argtypes (dhandle, info, physname, pvarargs);
3880 minfo.dhandle = dhandle;
3883 minfo.varargs = FALSE;
3884 minfo.typestring_alloc = 10;
3885 minfo.typestrings = ((struct stab_demangle_typestring *)
3886 xmalloc (minfo.typestring_alloc
3887 * sizeof *minfo.typestrings));
3888 minfo.typestring_count = 0;
3890 /* cplus_demangle checks for special GNU mangled forms, but we can't
3891 see any of them in mangled method argument types. */
3893 if (! stab_demangle_prefix (&minfo, &physname, physname_len))
3896 if (*physname != '\0')
3898 if (! stab_demangle_signature (&minfo, &physname))
3902 free (minfo.typestrings);
3903 minfo.typestrings = NULL;
3905 if (minfo.args == NULL)
3906 fprintf (stderr, _("no argument types in mangled string\n"));
3908 *pvarargs = minfo.varargs;
3912 if (minfo.typestrings != NULL)
3913 free (minfo.typestrings);
3917 /* Demangle the prefix of the mangled name. */
3920 stab_demangle_prefix (struct stab_demangle_info *minfo, const char **pp,
3921 unsigned int physname_len)
3926 /* cplus_demangle checks for global constructors and destructors,
3927 but we can't see them in mangled argument types. */
3930 scan = *pp + physname_len;
3933 /* Look for `__'. */
3936 scan = strchr (scan, '_');
3937 while (scan != NULL && *++scan != '_');
3941 stab_bad_demangle (*pp);
3947 /* We found `__'; move ahead to the last contiguous `__' pair. */
3948 i = strspn (scan, "_");
3954 && (ISDIGIT (scan[2])
3958 /* This is a GNU style constructor name. */
3962 else if (scan == *pp
3963 && ! ISDIGIT (scan[2])
3966 /* Look for the `__' that separates the prefix from the
3968 while (*scan == '_')
3970 scan = strstr (scan, "__");
3971 if (scan == NULL || scan[2] == '\0')
3973 stab_bad_demangle (*pp);
3977 return stab_demangle_function_name (minfo, pp, scan);
3979 else if (scan[2] != '\0')
3981 /* The name doesn't start with `__', but it does contain `__'. */
3982 return stab_demangle_function_name (minfo, pp, scan);
3986 stab_bad_demangle (*pp);
3992 /* Demangle a function name prefix. The scan argument points to the
3993 double underscore which separates the function name from the
3997 stab_demangle_function_name (struct stab_demangle_info *minfo,
3998 const char **pp, const char *scan)
4002 /* The string from *pp to scan is the name of the function. We
4003 don't care about the name, since we just looking for argument
4004 types. However, for conversion operators, the name may include a
4005 type which we must remember in order to handle backreferences. */
4011 && CONST_STRNEQ (name, "type")
4012 && (name[4] == '$' || name[4] == '.'))
4016 /* This is a type conversion operator. */
4018 if (! stab_demangle_type (minfo, &tem, (debug_type *) NULL))
4021 else if (name[0] == '_'
4028 /* This is a type conversion operator. */
4030 if (! stab_demangle_type (minfo, &tem, (debug_type *) NULL))
4037 /* Demangle the signature. This is where the argument types are
4041 stab_demangle_signature (struct stab_demangle_info *minfo, const char **pp)
4044 bfd_boolean expect_func, func_done;
4049 expect_func = FALSE;
4053 while (**pp != '\0')
4059 if (! stab_demangle_qualified (minfo, pp, (debug_type *) NULL)
4060 || ! stab_demangle_remember_type (minfo, hold, *pp - hold))
4067 /* Static member function. FIXME: Can this happen? */
4074 /* Const member function. */
4080 case '0': case '1': case '2': case '3': case '4':
4081 case '5': case '6': case '7': case '8': case '9':
4084 if (! stab_demangle_class (minfo, pp, (const char **) NULL)
4085 || ! stab_demangle_remember_type (minfo, hold, *pp - hold))
4092 /* Function. I don't know if this actually happens with g++
4097 if (! stab_demangle_args (minfo, pp, &minfo->args, &minfo->varargs))
4105 if (! stab_demangle_template (minfo, pp, (char **) NULL)
4106 || ! stab_demangle_remember_type (minfo, hold, *pp - hold))
4113 /* At the outermost level, we cannot have a return type
4114 specified, so if we run into another '_' at this point we
4115 are dealing with a mangled name that is either bogus, or
4116 has been mangled by some algorithm we don't know how to
4117 deal with. So just reject the entire demangling. */
4118 stab_bad_demangle (orig);
4122 /* Assume we have stumbled onto the first outermost function
4123 argument token, and start processing args. */
4125 if (! stab_demangle_args (minfo, pp, &minfo->args, &minfo->varargs))
4133 if (! stab_demangle_args (minfo, pp, &minfo->args, &minfo->varargs))
4140 /* With GNU style demangling, bar__3foo is 'foo::bar(void)', and
4141 bar__3fooi is 'foo::bar(int)'. We get here when we find the
4142 first case, and need to ensure that the '(void)' gets added
4143 to the current declp. */
4144 if (! stab_demangle_args (minfo, pp, &minfo->args, &minfo->varargs))
4151 /* Demangle a qualified name, such as "Q25Outer5Inner" which is the
4152 mangled form of "Outer::Inner". */
4155 stab_demangle_qualified (struct stab_demangle_info *minfo, const char **pp,
4160 unsigned int qualifiers;
4168 /* GNU mangled name with more than 9 classes. The count is
4169 preceded by an underscore (to distinguish it from the <= 9
4170 case) and followed by an underscore. */
4172 if (! ISDIGIT (*p) || *p == '0')
4174 stab_bad_demangle (orig);
4177 qualifiers = atoi (p);
4178 while (ISDIGIT (*p))
4182 stab_bad_demangle (orig);
4188 case '1': case '2': case '3': case '4': case '5':
4189 case '6': case '7': case '8': case '9':
4190 qualifiers = (*pp)[1] - '0';
4191 /* Skip an optional underscore after the count. */
4192 if ((*pp)[2] == '_')
4199 stab_bad_demangle (orig);
4203 context = DEBUG_TYPE_NULL;
4205 /* Pick off the names. */
4206 while (qualifiers-- > 0)
4214 if (! stab_demangle_template (minfo, pp,
4215 ptype != NULL ? &name : NULL))
4220 context = stab_find_tagged_type (minfo->dhandle, minfo->info,
4221 name, strlen (name),
4224 if (context == DEBUG_TYPE_NULL)
4232 len = stab_demangle_count (pp);
4233 if (strlen (*pp) < len)
4235 stab_bad_demangle (orig);
4241 const debug_field *fields;
4244 if (context != DEBUG_TYPE_NULL)
4245 fields = debug_get_fields (minfo->dhandle, context);
4247 context = DEBUG_TYPE_NULL;
4253 /* Try to find the type by looking through the
4254 fields of context until we find a field with the
4255 same type. This ought to work for a class
4256 defined within a class, but it won't work for,
4257 e.g., an enum defined within a class. stabs does
4258 not give us enough information to figure out the
4261 name = savestring (*pp, len);
4263 for (; *fields != DEBUG_FIELD_NULL; fields++)
4268 ft = debug_get_field_type (minfo->dhandle, *fields);
4274 dn = debug_get_type_name (minfo->dhandle, ft);
4275 if (dn != NULL && strcmp (dn, name) == 0)
4285 if (context == DEBUG_TYPE_NULL)
4287 /* We have to fall back on finding the type by name.
4288 If there are more types to come, then this must
4289 be a class. Otherwise, it could be anything. */
4291 if (qualifiers == 0)
4295 name = savestring (*pp, len);
4296 context = debug_find_named_type (minfo->dhandle,
4301 if (context == DEBUG_TYPE_NULL)
4303 context = stab_find_tagged_type (minfo->dhandle,
4307 ? DEBUG_KIND_ILLEGAL
4308 : DEBUG_KIND_CLASS));
4309 if (context == DEBUG_TYPE_NULL)
4325 /* Demangle a template. If PNAME is not NULL, this sets *PNAME to a
4326 string representation of the template. */
4329 stab_demangle_template (struct stab_demangle_info *minfo, const char **pp,
4339 /* Skip the template name. */
4340 r = stab_demangle_count (pp);
4341 if (r == 0 || strlen (*pp) < r)
4343 stab_bad_demangle (orig);
4348 /* Get the size of the parameter list. */
4349 if (stab_demangle_get_count (pp, &r) == 0)
4351 stab_bad_demangle (orig);
4355 for (i = 0; i < r; i++)
4359 /* This is a type parameter. */
4361 if (! stab_demangle_type (minfo, pp, (debug_type *) NULL))
4367 bfd_boolean pointerp, realp, integralp, charp, boolp;
4378 /* This is a value parameter. */
4380 if (! stab_demangle_type (minfo, pp, (debug_type *) NULL))
4383 while (*old_p != '\0' && ! done)
4393 case 'C': /* Const. */
4394 case 'S': /* Signed. */
4395 case 'U': /* Unsigned. */
4396 case 'V': /* Volatile. */
4397 case 'F': /* Function. */
4398 case 'M': /* Member function. */
4402 case 'Q': /* Qualified name. */
4406 case 'T': /* Remembered type. */
4408 case 'v': /* Void. */
4410 case 'x': /* Long long. */
4411 case 'l': /* Long. */
4412 case 'i': /* Int. */
4413 case 's': /* Short. */
4414 case 'w': /* Wchar_t. */
4418 case 'b': /* Bool. */
4422 case 'c': /* Char. */
4426 case 'r': /* Long double. */
4427 case 'd': /* Double. */
4428 case 'f': /* Float. */
4433 /* Assume it's a user defined integral type. */
4444 while (ISDIGIT (**pp))
4453 val = stab_demangle_count (pp);
4456 stab_bad_demangle (orig);
4464 val = stab_demangle_count (pp);
4465 if (val != 0 && val != 1)
4467 stab_bad_demangle (orig);
4475 while (ISDIGIT (**pp))
4480 while (ISDIGIT (**pp))
4486 while (ISDIGIT (**pp))
4494 len = stab_demangle_count (pp);
4497 stab_bad_demangle (orig);
4505 /* We can translate this to a string fairly easily by invoking the
4506 regular demangling routine. */
4509 char *s1, *s2, *s3, *s4 = NULL;
4512 s1 = savestring (orig, *pp - orig);
4514 s2 = concat ("NoSuchStrinG__", s1, (const char *) NULL);
4518 s3 = cplus_demangle (s2, DMGL_ANSI);
4523 s4 = strstr (s3, "::NoSuchStrinG");
4524 if (s3 == NULL || s4 == NULL)
4526 stab_bad_demangle (orig);
4532 /* Eliminating all spaces, except those between > characters,
4533 makes it more likely that the demangled name will match the
4534 name which g++ used as the structure name. */
4535 for (from = to = s3; from != s4; ++from)
4537 || (from[1] == '>' && from > s3 && from[-1] == '>'))
4540 *pname = savestring (s3, to - s3);
4548 /* Demangle a class name. */
4551 stab_demangle_class (struct stab_demangle_info *minfo ATTRIBUTE_UNUSED,
4552 const char **pp, const char **pstart)
4559 n = stab_demangle_count (pp);
4560 if (strlen (*pp) < n)
4562 stab_bad_demangle (orig);
4574 /* Demangle function arguments. If the pargs argument is not NULL, it
4575 is set to a NULL terminated array holding the arguments. */
4578 stab_demangle_args (struct stab_demangle_info *minfo, const char **pp,
4579 debug_type **pargs, bfd_boolean *pvarargs)
4582 unsigned int alloc, count;
4589 *pargs = (debug_type *) xmalloc (alloc * sizeof **pargs);
4594 while (**pp != '_' && **pp != '\0' && **pp != 'e')
4596 if (**pp == 'N' || **pp == 'T')
4604 if (temptype == 'T')
4608 if (! stab_demangle_get_count (pp, &r))
4610 stab_bad_demangle (orig);
4615 if (! stab_demangle_get_count (pp, &t))
4617 stab_bad_demangle (orig);
4621 if (t >= minfo->typestring_count)
4623 stab_bad_demangle (orig);
4630 tem = minfo->typestrings[t].typestring;
4631 if (! stab_demangle_arg (minfo, &tem, pargs, &count, &alloc))
4637 if (! stab_demangle_arg (minfo, pp, pargs, &count, &alloc))
4643 (*pargs)[count] = DEBUG_TYPE_NULL;
4655 /* Demangle a single argument. */
4658 stab_demangle_arg (struct stab_demangle_info *minfo, const char **pp,
4659 debug_type **pargs, unsigned int *pcount,
4660 unsigned int *palloc)
4666 if (! stab_demangle_type (minfo, pp,
4667 pargs == NULL ? (debug_type *) NULL : &type)
4668 || ! stab_demangle_remember_type (minfo, start, *pp - start))
4673 if (type == DEBUG_TYPE_NULL)
4676 if (*pcount + 1 >= *palloc)
4679 *pargs = ((debug_type *)
4680 xrealloc (*pargs, *palloc * sizeof **pargs));
4682 (*pargs)[*pcount] = type;
4689 /* Demangle a type. If the ptype argument is not NULL, *ptype is set
4690 to the newly allocated type. */
4693 stab_demangle_type (struct stab_demangle_info *minfo, const char **pp,
4704 /* A pointer type. */
4706 if (! stab_demangle_type (minfo, pp, ptype))
4709 *ptype = debug_make_pointer_type (minfo->dhandle, *ptype);
4713 /* A reference type. */
4715 if (! stab_demangle_type (minfo, pp, ptype))
4718 *ptype = debug_make_reference_type (minfo->dhandle, *ptype);
4728 while (**pp != '\0' && **pp != '_')
4730 if (! ISDIGIT (**pp))
4732 stab_bad_demangle (orig);
4741 stab_bad_demangle (orig);
4746 if (! stab_demangle_type (minfo, pp, ptype))
4750 debug_type int_type;
4752 int_type = debug_find_named_type (minfo->dhandle, "int");
4753 if (int_type == NULL)
4754 int_type = debug_make_int_type (minfo->dhandle, 4, FALSE);
4755 *ptype = debug_make_array_type (minfo->dhandle, *ptype, int_type,
4762 /* A back reference to a remembered type. */
4768 if (! stab_demangle_get_count (pp, &i))
4770 stab_bad_demangle (orig);
4773 if (i >= minfo->typestring_count)
4775 stab_bad_demangle (orig);
4778 p = minfo->typestrings[i].typestring;
4779 if (! stab_demangle_type (minfo, &p, ptype))
4788 bfd_boolean varargs;
4791 if (! stab_demangle_args (minfo, pp,
4793 ? (debug_type **) NULL
4796 ? (bfd_boolean *) NULL
4801 /* cplus_demangle will accept a function without a return
4802 type, but I don't know when that will happen, or what
4803 to do if it does. */
4804 stab_bad_demangle (orig);
4808 if (! stab_demangle_type (minfo, pp, ptype))
4811 *ptype = debug_make_function_type (minfo->dhandle, *ptype, args,
4820 bfd_boolean memberp;
4821 debug_type class_type = DEBUG_TYPE_NULL;
4823 bfd_boolean varargs;
4827 memberp = **pp == 'M';
4834 n = stab_demangle_count (pp);
4835 if (strlen (*pp) < n)
4837 stab_bad_demangle (orig);
4845 class_type = stab_find_tagged_type (minfo->dhandle,
4849 if (class_type == DEBUG_TYPE_NULL)
4853 else if (**pp == 'Q')
4855 if (! stab_demangle_qualified (minfo, pp,
4857 ? (debug_type *) NULL
4863 stab_bad_demangle (orig);
4873 else if (**pp == 'V')
4879 stab_bad_demangle (orig);
4883 if (! stab_demangle_args (minfo, pp,
4885 ? (debug_type **) NULL
4888 ? (bfd_boolean *) NULL
4895 stab_bad_demangle (orig);
4900 if (! stab_demangle_type (minfo, pp, ptype))
4906 *ptype = debug_make_offset_type (minfo->dhandle, class_type,
4910 /* FIXME: We have no way to record constp or
4912 *ptype = debug_make_method_type (minfo->dhandle, *ptype,
4913 class_type, args, varargs);
4921 if (! stab_demangle_type (minfo, pp, ptype))
4927 if (! stab_demangle_type (minfo, pp, ptype))
4930 *ptype = debug_make_const_type (minfo->dhandle, *ptype);
4935 if (! stab_demangle_qualified (minfo, pp, ptype))
4941 if (! stab_demangle_fund_type (minfo, pp, ptype))
4949 /* Demangle a fundamental type. If the ptype argument is not NULL,
4950 *ptype is set to the newly allocated type. */
4953 stab_demangle_fund_type (struct stab_demangle_info *minfo, const char **pp,
4957 bfd_boolean constp, volatilep, unsignedp, signedp;
5002 /* cplus_demangle permits this, but I don't know what it means. */
5003 stab_bad_demangle (orig);
5006 case 'v': /* void */
5009 *ptype = debug_find_named_type (minfo->dhandle, "void");
5010 if (*ptype == DEBUG_TYPE_NULL)
5011 *ptype = debug_make_void_type (minfo->dhandle);
5016 case 'x': /* long long */
5019 *ptype = debug_find_named_type (minfo->dhandle,
5021 ? "long long unsigned int"
5022 : "long long int"));
5023 if (*ptype == DEBUG_TYPE_NULL)
5024 *ptype = debug_make_int_type (minfo->dhandle, 8, unsignedp);
5029 case 'l': /* long */
5032 *ptype = debug_find_named_type (minfo->dhandle,
5034 ? "long unsigned int"
5036 if (*ptype == DEBUG_TYPE_NULL)
5037 *ptype = debug_make_int_type (minfo->dhandle, 4, unsignedp);
5045 *ptype = debug_find_named_type (minfo->dhandle,
5049 if (*ptype == DEBUG_TYPE_NULL)
5050 *ptype = debug_make_int_type (minfo->dhandle, 4, unsignedp);
5055 case 's': /* short */
5058 *ptype = debug_find_named_type (minfo->dhandle,
5060 ? "short unsigned int"
5062 if (*ptype == DEBUG_TYPE_NULL)
5063 *ptype = debug_make_int_type (minfo->dhandle, 2, unsignedp);
5068 case 'b': /* bool */
5071 *ptype = debug_find_named_type (minfo->dhandle, "bool");
5072 if (*ptype == DEBUG_TYPE_NULL)
5073 *ptype = debug_make_bool_type (minfo->dhandle, 4);
5078 case 'c': /* char */
5081 *ptype = debug_find_named_type (minfo->dhandle,
5087 if (*ptype == DEBUG_TYPE_NULL)
5088 *ptype = debug_make_int_type (minfo->dhandle, 1, unsignedp);
5093 case 'w': /* wchar_t */
5096 *ptype = debug_find_named_type (minfo->dhandle, "__wchar_t");
5097 if (*ptype == DEBUG_TYPE_NULL)
5098 *ptype = debug_make_int_type (minfo->dhandle, 2, TRUE);
5103 case 'r': /* long double */
5106 *ptype = debug_find_named_type (minfo->dhandle, "long double");
5107 if (*ptype == DEBUG_TYPE_NULL)
5108 *ptype = debug_make_float_type (minfo->dhandle, 8);
5113 case 'd': /* double */
5116 *ptype = debug_find_named_type (minfo->dhandle, "double");
5117 if (*ptype == DEBUG_TYPE_NULL)
5118 *ptype = debug_make_float_type (minfo->dhandle, 8);
5123 case 'f': /* float */
5126 *ptype = debug_find_named_type (minfo->dhandle, "float");
5127 if (*ptype == DEBUG_TYPE_NULL)
5128 *ptype = debug_make_float_type (minfo->dhandle, 4);
5135 if (! ISDIGIT (**pp))
5137 stab_bad_demangle (orig);
5141 case '0': case '1': case '2': case '3': case '4':
5142 case '5': case '6': case '7': case '8': case '9':
5146 if (! stab_demangle_class (minfo, pp, &hold))
5152 name = savestring (hold, *pp - hold);
5153 *ptype = debug_find_named_type (minfo->dhandle, name);
5155 if (*ptype == DEBUG_TYPE_NULL)
5157 /* FIXME: It is probably incorrect to assume that
5158 undefined types are tagged types. */
5159 *ptype = stab_find_tagged_type (minfo->dhandle, minfo->info,
5161 DEBUG_KIND_ILLEGAL);
5162 if (*ptype == DEBUG_TYPE_NULL)
5173 if (! stab_demangle_template (minfo, pp,
5174 ptype != NULL ? &name : NULL))
5178 *ptype = stab_find_tagged_type (minfo->dhandle, minfo->info,
5179 name, strlen (name),
5182 if (*ptype == DEBUG_TYPE_NULL)
5189 stab_bad_demangle (orig);
5196 *ptype = debug_make_const_type (minfo->dhandle, *ptype);
5198 *ptype = debug_make_volatile_type (minfo->dhandle, *ptype);
5204 /* Remember a type string in a demangled string. */
5207 stab_demangle_remember_type (struct stab_demangle_info *minfo,
5208 const char *p, int len)
5210 if (minfo->typestring_count >= minfo->typestring_alloc)
5212 minfo->typestring_alloc += 10;
5213 minfo->typestrings = ((struct stab_demangle_typestring *)
5214 xrealloc (minfo->typestrings,
5215 (minfo->typestring_alloc
5216 * sizeof *minfo->typestrings)));
5219 minfo->typestrings[minfo->typestring_count].typestring = p;
5220 minfo->typestrings[minfo->typestring_count].len = (unsigned int) len;
5221 ++minfo->typestring_count;
5226 /* Demangle names encoded using the g++ V3 ABI. The newer versions of
5227 g++ which use this ABI do not encode ordinary method argument types
5228 in a mangled name; they simply output the argument types. However,
5229 for a static method, g++ simply outputs the return type and the
5230 physical name. So in that case we need to demangle the name here.
5231 Here PHYSNAME is the physical name of the function, and we set the
5232 variable pointed at by PVARARGS to indicate whether this function
5233 is varargs. This returns NULL, or a NULL terminated array of
5237 stab_demangle_v3_argtypes (void *dhandle, struct stab_handle *info,
5238 const char *physname, bfd_boolean *pvarargs)
5240 struct demangle_component *dc;
5244 dc = cplus_demangle_v3_components (physname, DMGL_PARAMS | DMGL_ANSI, &mem);
5247 stab_bad_demangle (physname);
5251 /* We expect to see TYPED_NAME, and the right subtree describes the
5253 if (dc->type != DEMANGLE_COMPONENT_TYPED_NAME
5254 || dc->u.s_binary.right->type != DEMANGLE_COMPONENT_FUNCTION_TYPE)
5256 fprintf (stderr, _("Demangled name is not a function\n"));
5261 pargs = stab_demangle_v3_arglist (dhandle, info,
5262 dc->u.s_binary.right->u.s_binary.right,
5270 /* Demangle an argument list in a struct demangle_component tree.
5271 Returns a DEBUG_TYPE_NULL terminated array of argument types, and
5272 sets *PVARARGS to indicate whether this is a varargs function. */
5275 stab_demangle_v3_arglist (void *dhandle, struct stab_handle *info,
5276 struct demangle_component *arglist,
5277 bfd_boolean *pvarargs)
5279 struct demangle_component *dc;
5280 unsigned int alloc, count;
5284 pargs = (debug_type *) xmalloc (alloc * sizeof *pargs);
5291 dc = dc->u.s_binary.right)
5294 bfd_boolean varargs;
5296 if (dc->type != DEMANGLE_COMPONENT_ARGLIST)
5298 fprintf (stderr, _("Unexpected type in v3 arglist demangling\n"));
5303 /* PR 13925: Cope if the demangler returns an empty
5304 context for a function with no arguments. */
5305 if (dc->u.s_binary.left == NULL)
5308 arg = stab_demangle_v3_arg (dhandle, info, dc->u.s_binary.left,
5321 if (count + 1 >= alloc)
5324 pargs = (debug_type *) xrealloc (pargs, alloc * sizeof *pargs);
5331 pargs[count] = DEBUG_TYPE_NULL;
5336 /* Convert a struct demangle_component tree describing an argument
5337 type into a debug_type. */
5340 stab_demangle_v3_arg (void *dhandle, struct stab_handle *info,
5341 struct demangle_component *dc, debug_type context,
5342 bfd_boolean *pvarargs)
5346 if (pvarargs != NULL)
5351 /* FIXME: These are demangle component types which we probably
5352 need to handle one way or another. */
5353 case DEMANGLE_COMPONENT_LOCAL_NAME:
5354 case DEMANGLE_COMPONENT_TYPED_NAME:
5355 case DEMANGLE_COMPONENT_TEMPLATE_PARAM:
5356 case DEMANGLE_COMPONENT_CTOR:
5357 case DEMANGLE_COMPONENT_DTOR:
5358 case DEMANGLE_COMPONENT_JAVA_CLASS:
5359 case DEMANGLE_COMPONENT_RESTRICT_THIS:
5360 case DEMANGLE_COMPONENT_VOLATILE_THIS:
5361 case DEMANGLE_COMPONENT_CONST_THIS:
5362 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL:
5363 case DEMANGLE_COMPONENT_COMPLEX:
5364 case DEMANGLE_COMPONENT_IMAGINARY:
5365 case DEMANGLE_COMPONENT_VENDOR_TYPE:
5366 case DEMANGLE_COMPONENT_ARRAY_TYPE:
5367 case DEMANGLE_COMPONENT_PTRMEM_TYPE:
5368 case DEMANGLE_COMPONENT_ARGLIST:
5370 fprintf (stderr, _("Unrecognized demangle component %d\n"),
5374 case DEMANGLE_COMPONENT_NAME:
5375 if (context != NULL)
5377 const debug_field *fields;
5379 fields = debug_get_fields (dhandle, context);
5382 /* Try to find this type by looking through the context
5384 for (; *fields != DEBUG_FIELD_NULL; fields++)
5389 ft = debug_get_field_type (dhandle, *fields);
5392 dn = debug_get_type_name (dhandle, ft);
5394 && (int) strlen (dn) == dc->u.s_name.len
5395 && strncmp (dn, dc->u.s_name.s, dc->u.s_name.len) == 0)
5400 return stab_find_tagged_type (dhandle, info, dc->u.s_name.s,
5401 dc->u.s_name.len, DEBUG_KIND_ILLEGAL);
5403 case DEMANGLE_COMPONENT_QUAL_NAME:
5404 context = stab_demangle_v3_arg (dhandle, info, dc->u.s_binary.left,
5406 if (context == NULL)
5408 return stab_demangle_v3_arg (dhandle, info, dc->u.s_binary.right,
5411 case DEMANGLE_COMPONENT_TEMPLATE:
5416 /* We print this component to get a class name which we can
5417 use. FIXME: This probably won't work if the template uses
5418 template parameters which refer to an outer template. */
5419 p = cplus_demangle_print (DMGL_PARAMS | DMGL_ANSI, dc, 20, &alc);
5422 fprintf (stderr, _("Failed to print demangled template\n"));
5425 dt = stab_find_tagged_type (dhandle, info, p, strlen (p),
5431 case DEMANGLE_COMPONENT_SUB_STD:
5432 return stab_find_tagged_type (dhandle, info, dc->u.s_string.string,
5433 dc->u.s_string.len, DEBUG_KIND_ILLEGAL);
5435 case DEMANGLE_COMPONENT_RESTRICT:
5436 case DEMANGLE_COMPONENT_VOLATILE:
5437 case DEMANGLE_COMPONENT_CONST:
5438 case DEMANGLE_COMPONENT_POINTER:
5439 case DEMANGLE_COMPONENT_REFERENCE:
5440 dt = stab_demangle_v3_arg (dhandle, info, dc->u.s_binary.left, NULL,
5449 case DEMANGLE_COMPONENT_RESTRICT:
5450 /* FIXME: We have no way to represent restrict. */
5452 case DEMANGLE_COMPONENT_VOLATILE:
5453 return debug_make_volatile_type (dhandle, dt);
5454 case DEMANGLE_COMPONENT_CONST:
5455 return debug_make_const_type (dhandle, dt);
5456 case DEMANGLE_COMPONENT_POINTER:
5457 return debug_make_pointer_type (dhandle, dt);
5458 case DEMANGLE_COMPONENT_REFERENCE:
5459 return debug_make_reference_type (dhandle, dt);
5462 case DEMANGLE_COMPONENT_FUNCTION_TYPE:
5465 bfd_boolean varargs;
5467 if (dc->u.s_binary.left == NULL)
5469 /* In this case the return type is actually unknown.
5470 However, I'm not sure this will ever arise in practice;
5471 normally an unknown return type would only appear at
5472 the top level, which is handled above. */
5473 dt = debug_make_void_type (dhandle);
5476 dt = stab_demangle_v3_arg (dhandle, info, dc->u.s_binary.left, NULL,
5481 pargs = stab_demangle_v3_arglist (dhandle, info,
5482 dc->u.s_binary.right,
5487 return debug_make_function_type (dhandle, dt, pargs, varargs);
5490 case DEMANGLE_COMPONENT_BUILTIN_TYPE:
5496 /* We print this component in order to find out the type name.
5497 FIXME: Should we instead expose the
5498 demangle_builtin_type_info structure? */
5499 p = cplus_demangle_print (DMGL_PARAMS | DMGL_ANSI, dc, 20, &alc);
5502 fprintf (stderr, _("Couldn't get demangled builtin type\n"));
5506 /* The mangling is based on the type, but does not itself
5507 indicate what the sizes are. So we have to guess. */
5508 if (strcmp (p, "signed char") == 0)
5509 ret = debug_make_int_type (dhandle, 1, FALSE);
5510 else if (strcmp (p, "bool") == 0)
5511 ret = debug_make_bool_type (dhandle, 1);
5512 else if (strcmp (p, "char") == 0)
5513 ret = debug_make_int_type (dhandle, 1, FALSE);
5514 else if (strcmp (p, "double") == 0)
5515 ret = debug_make_float_type (dhandle, 8);
5516 else if (strcmp (p, "long double") == 0)
5517 ret = debug_make_float_type (dhandle, 8);
5518 else if (strcmp (p, "float") == 0)
5519 ret = debug_make_float_type (dhandle, 4);
5520 else if (strcmp (p, "__float128") == 0)
5521 ret = debug_make_float_type (dhandle, 16);
5522 else if (strcmp (p, "unsigned char") == 0)
5523 ret = debug_make_int_type (dhandle, 1, TRUE);
5524 else if (strcmp (p, "int") == 0)
5525 ret = debug_make_int_type (dhandle, 4, FALSE);
5526 else if (strcmp (p, "unsigned int") == 0)
5527 ret = debug_make_int_type (dhandle, 4, TRUE);
5528 else if (strcmp (p, "long") == 0)
5529 ret = debug_make_int_type (dhandle, 4, FALSE);
5530 else if (strcmp (p, "unsigned long") == 0)
5531 ret = debug_make_int_type (dhandle, 4, TRUE);
5532 else if (strcmp (p, "__int128") == 0)
5533 ret = debug_make_int_type (dhandle, 16, FALSE);
5534 else if (strcmp (p, "unsigned __int128") == 0)
5535 ret = debug_make_int_type (dhandle, 16, TRUE);
5536 else if (strcmp (p, "short") == 0)
5537 ret = debug_make_int_type (dhandle, 2, FALSE);
5538 else if (strcmp (p, "unsigned short") == 0)
5539 ret = debug_make_int_type (dhandle, 2, TRUE);
5540 else if (strcmp (p, "void") == 0)
5541 ret = debug_make_void_type (dhandle);
5542 else if (strcmp (p, "wchar_t") == 0)
5543 ret = debug_make_int_type (dhandle, 4, TRUE);
5544 else if (strcmp (p, "long long") == 0)
5545 ret = debug_make_int_type (dhandle, 8, FALSE);
5546 else if (strcmp (p, "unsigned long long") == 0)
5547 ret = debug_make_int_type (dhandle, 8, TRUE);
5548 else if (strcmp (p, "...") == 0)
5550 if (pvarargs == NULL)
5551 fprintf (stderr, _("Unexpected demangled varargs\n"));
5558 fprintf (stderr, _("Unrecognized demangled builtin type\n"));