1 /* stabs.c -- Parse stabs debugging information
2 Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
3 Free Software Foundation, Inc.
4 Written by Ian Lance Taylor <ian@cygnus.com>.
6 This file is part of GNU Binutils.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
23 /* This file contains code which parses stabs debugging information.
24 The organization of this code is based on the gdb stabs reading
25 code. The job it does is somewhat different, because it is not
26 trying to identify the correct address for anything. */
32 #include "libiberty.h"
33 #include "safe-ctype.h"
37 #include "filenames.h"
38 #include "aout/aout64.h"
39 #include "aout/stab_gnu.h"
41 /* The number of predefined XCOFF types. */
43 #define XCOFF_TYPE_COUNT 34
45 /* This structure is used as a handle so that the stab parsing doesn't
46 need to use any static variables. */
52 /* TRUE if this is stabs in sections. */
54 /* The symbol table. */
56 /* The number of symbols. */
58 /* The accumulated file name string. */
60 /* The value of the last N_SO symbol. */
62 /* The value of the start of the file, so that we can handle file
63 relative N_LBRAC and N_RBRAC symbols. */
64 bfd_vma file_start_offset;
65 /* The offset of the start of the function, so that we can handle
66 function relative N_LBRAC and N_RBRAC symbols. */
67 bfd_vma function_start_offset;
68 /* The version number of gcc which compiled the current compilation
69 unit, 0 if not compiled by gcc. */
71 /* Whether an N_OPT symbol was seen that was not generated by gcc,
72 so that we can detect the SunPRO compiler. */
73 bfd_boolean n_opt_found;
74 /* The main file name. */
76 /* A stack of unfinished N_BINCL files. */
77 struct bincl_file *bincl_stack;
78 /* A list of finished N_BINCL files. */
79 struct bincl_file *bincl_list;
80 /* Whether we are inside a function or not. */
81 bfd_boolean within_function;
82 /* The address of the end of the function, used if we have seen an
83 N_FUN symbol while in a function. This is -1 if we have not seen
84 an N_FUN (the normal case). */
86 /* The depth of block nesting. */
88 /* List of pending variable definitions. */
89 struct stab_pending_var *pending;
90 /* Number of files for which we have types. */
92 /* Lists of types per file. */
93 struct stab_types **file_types;
94 /* Predefined XCOFF types. */
95 debug_type xcoff_types[XCOFF_TYPE_COUNT];
97 struct stab_tag *tags;
98 /* Set by parse_stab_type if it sees a structure defined as a cross
99 reference to itself. Reset by parse_stab_type otherwise. */
100 bfd_boolean self_crossref;
103 /* A list of these structures is used to hold pending variable
104 definitions seen before the N_LBRAC of a block. */
106 struct stab_pending_var
108 /* Next pending variable definition. */
109 struct stab_pending_var *next;
115 enum debug_var_kind kind;
120 /* A list of these structures is used to hold the types for a single
125 /* Next set of slots for this file. */
126 struct stab_types *next;
127 /* Types indexed by type number. */
128 #define STAB_TYPES_SLOTS (16)
129 debug_type types[STAB_TYPES_SLOTS];
132 /* We keep a list of undefined tags that we encounter, so that we can
133 fill them in if the tag is later defined. */
137 /* Next undefined tag. */
138 struct stab_tag *next;
142 enum debug_type_kind kind;
143 /* Slot to hold real type when we discover it. If we don't, we fill
144 in an undefined tag type. */
146 /* Indirect type we have created to point at slot. */
150 static char *savestring (const char *, int);
151 static bfd_vma parse_number (const char **, bfd_boolean *);
152 static void bad_stab (const char *);
153 static void warn_stab (const char *, const char *);
154 static bfd_boolean parse_stab_string
155 (void *, struct stab_handle *, int, int, bfd_vma, const char *);
156 static debug_type parse_stab_type
157 (void *, struct stab_handle *, const char *, const char **, debug_type **);
158 static bfd_boolean parse_stab_type_number (const char **, int *);
159 static debug_type parse_stab_range_type
160 (void *, struct stab_handle *, const char *, const char **, const int *);
161 static debug_type parse_stab_sun_builtin_type (void *, const char **);
162 static debug_type parse_stab_sun_floating_type (void *, const char **);
163 static debug_type parse_stab_enum_type (void *, const char **);
164 static debug_type parse_stab_struct_type
165 (void *, struct stab_handle *, const char *, const char **,
166 bfd_boolean, const int *);
167 static bfd_boolean parse_stab_baseclasses
168 (void *, struct stab_handle *, const char **, debug_baseclass **);
169 static bfd_boolean parse_stab_struct_fields
170 (void *, struct stab_handle *, const char **, debug_field **, bfd_boolean *);
171 static bfd_boolean parse_stab_cpp_abbrev
172 (void *, struct stab_handle *, const char **, debug_field *);
173 static bfd_boolean parse_stab_one_struct_field
174 (void *, struct stab_handle *, const char **, const char *,
175 debug_field *, bfd_boolean *);
176 static bfd_boolean parse_stab_members
177 (void *, struct stab_handle *, const char *, const char **, const int *,
179 static debug_type parse_stab_argtypes
180 (void *, struct stab_handle *, debug_type, const char *, const char *,
181 debug_type, const char *, bfd_boolean, bfd_boolean, const char **);
182 static bfd_boolean parse_stab_tilde_field
183 (void *, struct stab_handle *, const char **, const int *, debug_type *,
185 static debug_type parse_stab_array_type
186 (void *, struct stab_handle *, const char **, bfd_boolean);
187 static void push_bincl (struct stab_handle *, const char *, bfd_vma);
188 static const char *pop_bincl (struct stab_handle *);
189 static bfd_boolean find_excl (struct stab_handle *, const char *, bfd_vma);
190 static bfd_boolean stab_record_variable
191 (void *, struct stab_handle *, const char *, debug_type,
192 enum debug_var_kind, bfd_vma);
193 static bfd_boolean stab_emit_pending_vars (void *, struct stab_handle *);
194 static debug_type *stab_find_slot (struct stab_handle *, const int *);
195 static debug_type stab_find_type (void *, struct stab_handle *, const int *);
196 static bfd_boolean stab_record_type
197 (void *, struct stab_handle *, const int *, debug_type);
198 static debug_type stab_xcoff_builtin_type
199 (void *, struct stab_handle *, int);
200 static debug_type stab_find_tagged_type
201 (void *, struct stab_handle *, const char *, int, enum debug_type_kind);
202 static debug_type *stab_demangle_argtypes
203 (void *, struct stab_handle *, const char *, bfd_boolean *, unsigned int);
204 static debug_type *stab_demangle_v3_argtypes
205 (void *, struct stab_handle *, const char *, bfd_boolean *);
206 static debug_type stab_demangle_v3_arg
207 (void *, struct stab_handle *, struct demangle_component *, debug_type,
210 /* Save a string in memory. */
213 savestring (const char *start, int len)
217 ret = (char *) xmalloc (len + 1);
218 memcpy (ret, start, len);
223 /* Read a number from a string. */
226 parse_number (const char **pp, bfd_boolean *poverflow)
231 if (poverflow != NULL)
237 ul = strtoul (*pp, (char **) pp, 0);
238 if (ul + 1 != 0 || errno == 0)
240 /* If bfd_vma is larger than unsigned long, and the number is
241 meant to be negative, we have to make sure that we sign
244 return (bfd_vma) (bfd_signed_vma) (long) ul;
248 /* Note that even though strtoul overflowed, it should have set *pp
249 to the end of the number, which is where we want it. */
250 if (sizeof (bfd_vma) > sizeof (unsigned long))
255 bfd_vma over, lastdig;
256 bfd_boolean overflow;
259 /* Our own version of strtoul, for a bfd_vma. */
274 if (p[1] == 'x' || p[1] == 'X')
286 over = ((bfd_vma) (bfd_signed_vma) -1) / (bfd_vma) base;
287 lastdig = ((bfd_vma) (bfd_signed_vma) -1) % (bfd_vma) base;
298 else if (ISUPPER (d))
300 else if (ISLOWER (d))
308 if (v > over || (v == over && (bfd_vma) d > lastdig))
323 /* If we get here, the number is too large to represent in a
325 if (poverflow != NULL)
328 warn_stab (orig, _("numeric overflow"));
333 /* Give an error for a bad stab string. */
336 bad_stab (const char *p)
338 fprintf (stderr, _("Bad stab: %s\n"), p);
341 /* Warn about something in a stab string. */
344 warn_stab (const char *p, const char *err)
346 fprintf (stderr, _("Warning: %s: %s\n"), err, p);
349 /* Create a handle to parse stabs symbols with. */
352 start_stab (void *dhandle ATTRIBUTE_UNUSED, bfd *abfd, bfd_boolean sections,
353 asymbol **syms, long symcount)
355 struct stab_handle *ret;
357 ret = (struct stab_handle *) xmalloc (sizeof *ret);
358 memset (ret, 0, sizeof *ret);
360 ret->sections = sections;
362 ret->symcount = symcount;
364 ret->file_types = (struct stab_types **) xmalloc (sizeof *ret->file_types);
365 ret->file_types[0] = NULL;
366 ret->function_end = (bfd_vma) -1;
370 /* When we have processed all the stabs information, we need to go
371 through and fill in all the undefined tags. */
374 finish_stab (void *dhandle, void *handle)
376 struct stab_handle *info = (struct stab_handle *) handle;
379 if (info->within_function)
381 if (! stab_emit_pending_vars (dhandle, info)
382 || ! debug_end_function (dhandle, info->function_end))
384 info->within_function = FALSE;
385 info->function_end = (bfd_vma) -1;
388 for (st = info->tags; st != NULL; st = st->next)
390 enum debug_type_kind kind;
393 if (kind == DEBUG_KIND_ILLEGAL)
394 kind = DEBUG_KIND_STRUCT;
395 st->slot = debug_make_undefined_tagged_type (dhandle, st->name, kind);
396 if (st->slot == DEBUG_TYPE_NULL)
403 /* Handle a single stabs symbol. */
406 parse_stab (void *dhandle, void *handle, int type, int desc, bfd_vma value,
409 struct stab_handle *info = (struct stab_handle *) handle;
411 /* gcc will emit two N_SO strings per compilation unit, one for the
412 directory name and one for the file name. We just collect N_SO
413 strings as we see them, and start the new compilation unit when
414 we see a non N_SO symbol. */
415 if (info->so_string != NULL
416 && (type != N_SO || *string == '\0' || value != info->so_value))
418 if (! debug_set_filename (dhandle, info->so_string))
420 info->main_filename = info->so_string;
422 info->gcc_compiled = 0;
423 info->n_opt_found = FALSE;
425 /* Generally, for stabs in the symbol table, the N_LBRAC and
426 N_RBRAC symbols are relative to the N_SO symbol value. */
427 if (! info->sections)
428 info->file_start_offset = info->so_value;
430 /* We need to reset the mapping from type numbers to types. We
431 can't free the old mapping, because of the use of
432 debug_make_indirect_type. */
434 info->file_types = ((struct stab_types **)
435 xmalloc (sizeof *info->file_types));
436 info->file_types[0] = NULL;
438 info->so_string = NULL;
440 /* Now process whatever type we just got. */
450 /* Ignore extra outermost context from SunPRO cc and acc. */
451 if (info->n_opt_found && desc == 1)
454 if (! info->within_function)
456 fprintf (stderr, _("N_LBRAC not within function\n"));
460 /* Start an inner lexical block. */
461 if (! debug_start_block (dhandle,
463 + info->file_start_offset
464 + info->function_start_offset)))
467 /* Emit any pending variable definitions. */
468 if (! stab_emit_pending_vars (dhandle, info))
475 /* Ignore extra outermost context from SunPRO cc and acc. */
476 if (info->n_opt_found && desc == 1)
479 /* We shouldn't have any pending variable definitions here, but,
480 if we do, we probably need to emit them before closing the
482 if (! stab_emit_pending_vars (dhandle, info))
485 /* End an inner lexical block. */
486 if (! debug_end_block (dhandle,
488 + info->file_start_offset
489 + info->function_start_offset)))
493 if (info->block_depth < 0)
495 fprintf (stderr, _("Too many N_RBRACs\n"));
501 /* This always ends a function. */
502 if (info->within_function)
508 && info->function_end != (bfd_vma) -1
509 && info->function_end < endval)
510 endval = info->function_end;
511 if (! stab_emit_pending_vars (dhandle, info)
512 || ! debug_end_function (dhandle, endval))
514 info->within_function = FALSE;
515 info->function_end = (bfd_vma) -1;
518 /* An empty string is emitted by gcc at the end of a compilation
523 /* Just accumulate strings until we see a non N_SO symbol. If
524 the string starts with a directory separator or some other
525 form of absolute path specification, we discard the previously
526 accumulated strings. */
527 if (info->so_string == NULL)
528 info->so_string = xstrdup (string);
535 if (IS_ABSOLUTE_PATH (string))
536 info->so_string = xstrdup (string);
538 info->so_string = concat (info->so_string, string,
539 (const char *) NULL);
543 info->so_value = value;
548 /* Start an include file. */
549 if (! debug_start_source (dhandle, string))
554 /* Start an include file which may be replaced. */
555 push_bincl (info, string, value);
556 if (! debug_start_source (dhandle, string))
561 /* End an N_BINCL include. */
562 if (! debug_start_source (dhandle, pop_bincl (info)))
567 /* This is a duplicate of a header file named by N_BINCL which
568 was eliminated by the linker. */
569 if (! find_excl (info, string, value))
574 if (! debug_record_line (dhandle, desc,
575 value + (info->within_function
576 ? info->function_start_offset : 0)))
581 if (! debug_start_common_block (dhandle, string))
586 if (! debug_end_common_block (dhandle, string))
593 if (info->within_function)
595 /* This always marks the end of a function; we don't
596 need to worry about info->function_end. */
598 value += info->function_start_offset;
599 if (! stab_emit_pending_vars (dhandle, info)
600 || ! debug_end_function (dhandle, value))
602 info->within_function = FALSE;
603 info->function_end = (bfd_vma) -1;
608 /* A const static symbol in the .text section will have an N_FUN
609 entry. We need to use these to mark the end of the function,
610 in case we are looking at gcc output before it was changed to
611 always emit an empty N_FUN. We can't call debug_end_function
612 here, because it might be a local static symbol. */
613 if (info->within_function
614 && (info->function_end == (bfd_vma) -1
615 || value < info->function_end))
616 info->function_end = value;
619 /* FIXME: gdb checks the string for N_STSYM, N_LCSYM or N_ROSYM
620 symbols, and if it does not start with :S, gdb relocates the
621 value to the start of the section. gcc always seems to use
622 :S, so we don't worry about this. */
628 colon = strchr (string, ':');
630 && (colon[1] == 'f' || colon[1] == 'F'))
632 if (info->within_function)
637 if (info->function_end != (bfd_vma) -1
638 && info->function_end < endval)
639 endval = info->function_end;
640 if (! stab_emit_pending_vars (dhandle, info)
641 || ! debug_end_function (dhandle, endval))
643 info->function_end = (bfd_vma) -1;
645 /* For stabs in sections, line numbers and block addresses
646 are offsets from the start of the function. */
648 info->function_start_offset = value;
649 info->within_function = TRUE;
652 if (! parse_stab_string (dhandle, info, type, desc, value, string))
658 if (string != NULL && strcmp (string, "gcc2_compiled.") == 0)
659 info->gcc_compiled = 2;
660 else if (string != NULL && strcmp (string, "gcc_compiled.") == 0)
661 info->gcc_compiled = 1;
663 info->n_opt_found = TRUE;
676 /* Parse the stabs string. */
679 parse_stab_string (void *dhandle, struct stab_handle *info, int stabtype,
680 int desc, bfd_vma value, const char *string)
687 bfd_boolean self_crossref;
691 p = strchr (string, ':');
706 /* GCC 2.x puts the line number in desc. SunOS apparently puts in
707 the number of bytes occupied by a type or object, which we
709 if (info->gcc_compiled >= 2)
714 /* FIXME: Sometimes the special C++ names start with '.'. */
716 if (string[0] == '$')
724 /* Was: name = "vptr"; */
730 /* This was an anonymous type that was never fixed up. */
733 /* SunPRO (3.0 at least) static variable encoding. */
736 warn_stab (string, _("unknown C++ encoded name"));
743 if (p == string || (string[0] == ' ' && p == string + 1))
746 name = savestring (string, p - string);
750 if (ISDIGIT (*p) || *p == '(' || *p == '-')
758 /* c is a special case, not followed by a type-number.
759 SYMBOL:c=iVALUE for an integer constant symbol.
760 SYMBOL:c=rVALUE for a floating constant symbol.
761 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
762 e.g. "b:c=e6,0" for "const b = blob1"
763 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
773 /* Floating point constant. */
774 if (! debug_record_float_const (dhandle, name, atof (p)))
778 /* Integer constant. */
779 /* Defining integer constants this way is kind of silly,
780 since 'e' constants allows the compiler to give not only
781 the value, but the type as well. C has at least int,
782 long, unsigned int, and long long as constant types;
783 other languages probably should have at least unsigned as
784 well as signed constants. */
785 if (! debug_record_int_const (dhandle, name, atoi (p)))
789 /* SYMBOL:c=eTYPE,INTVALUE for a constant symbol whose value
790 can be represented as integral.
791 e.g. "b:c=e6,0" for "const b = blob1"
792 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
793 dtype = parse_stab_type (dhandle, info, (const char *) NULL,
794 &p, (debug_type **) NULL);
795 if (dtype == DEBUG_TYPE_NULL)
802 if (! debug_record_typed_const (dhandle, name, dtype, atoi (p)))
813 /* The name of a caught exception. */
814 dtype = parse_stab_type (dhandle, info, (const char *) NULL,
815 &p, (debug_type **) NULL);
816 if (dtype == DEBUG_TYPE_NULL)
818 if (! debug_record_label (dhandle, name, dtype, value))
824 /* A function definition. */
825 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
826 (debug_type **) NULL);
827 if (dtype == DEBUG_TYPE_NULL)
829 if (! debug_record_function (dhandle, name, dtype, type == 'F', value))
832 /* Sun acc puts declared types of arguments here. We don't care
833 about their actual types (FIXME -- we should remember the whole
834 function prototype), but the list may define some new types
835 that we have to remember, so we must scan it now. */
839 if (parse_stab_type (dhandle, info, (const char *) NULL, &p,
840 (debug_type **) NULL)
853 /* A global symbol. The value must be extracted from the
855 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
856 (debug_type **) NULL);
857 if (dtype == DEBUG_TYPE_NULL)
859 leading = bfd_get_symbol_leading_char (info->abfd);
860 for (c = info->symcount, ps = info->syms; c > 0; --c, ++ps)
864 n = bfd_asymbol_name (*ps);
865 if (leading != '\0' && *n == leading)
867 if (*n == *name && strcmp (n, name) == 0)
871 value = bfd_asymbol_value (*ps);
872 if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_GLOBAL,
878 /* This case is faked by a conditional above, when there is no
879 code letter in the dbx data. Dbx data never actually
883 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
884 (debug_type **) NULL);
885 if (dtype == DEBUG_TYPE_NULL)
887 if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_LOCAL,
893 /* A function parameter. */
895 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
896 (debug_type **) NULL);
899 /* pF is a two-letter code that means a function parameter in
900 Fortran. The type-number specifies the type of the return
901 value. Translate it into a pointer-to-function type. */
903 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
904 (debug_type **) NULL);
905 if (dtype != DEBUG_TYPE_NULL)
909 ftype = debug_make_function_type (dhandle, dtype,
910 (debug_type *) NULL, FALSE);
911 dtype = debug_make_pointer_type (dhandle, ftype);
914 if (dtype == DEBUG_TYPE_NULL)
916 if (! debug_record_parameter (dhandle, name, dtype, DEBUG_PARM_STACK,
920 /* FIXME: At this point gdb considers rearranging the parameter
921 address on a big endian machine if it is smaller than an int.
922 We have no way to do that, since we don't really know much
927 if (stabtype == N_FUN)
929 /* Prototype of a function referenced by this file. */
933 if (parse_stab_type (dhandle, info, (const char *) NULL, &p,
934 (debug_type **) NULL)
942 /* Parameter which is in a register. */
943 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
944 (debug_type **) NULL);
945 if (dtype == DEBUG_TYPE_NULL)
947 if (! debug_record_parameter (dhandle, name, dtype, DEBUG_PARM_REG,
953 /* Register variable (either global or local). */
954 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
955 (debug_type **) NULL);
956 if (dtype == DEBUG_TYPE_NULL)
958 if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_REGISTER,
962 /* FIXME: At this point gdb checks to combine pairs of 'p' and
963 'r' stabs into a single 'P' stab. */
967 /* Static symbol at top level of file. */
968 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
969 (debug_type **) NULL);
970 if (dtype == DEBUG_TYPE_NULL)
972 if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_STATIC,
979 dtype = parse_stab_type (dhandle, info, name, &p, &slot);
980 if (dtype == DEBUG_TYPE_NULL)
984 /* A nameless type. Nothing to do. */
988 dtype = debug_name_type (dhandle, name, dtype);
989 if (dtype == DEBUG_TYPE_NULL)
998 /* Struct, union, or enum tag. For GNU C++, this can be be followed
999 by 't' which means we are typedef'ing it as well. */
1003 /* FIXME: gdb sets synonym to TRUE if the current language
1012 dtype = parse_stab_type (dhandle, info, name, &p, &slot);
1013 if (dtype == DEBUG_TYPE_NULL)
1018 /* INFO->SELF_CROSSREF is set by parse_stab_type if this type is
1019 a cross reference to itself. These are generated by some
1021 self_crossref = info->self_crossref;
1023 dtype = debug_tag_type (dhandle, name, dtype);
1024 if (dtype == DEBUG_TYPE_NULL)
1029 /* See if we have a cross reference to this tag which we can now
1030 fill in. Avoid filling in a cross reference to ourselves,
1031 because that would lead to circular debugging information. */
1032 if (! self_crossref)
1034 register struct stab_tag **pst;
1036 for (pst = &info->tags; *pst != NULL; pst = &(*pst)->next)
1038 if ((*pst)->name[0] == name[0]
1039 && strcmp ((*pst)->name, name) == 0)
1041 (*pst)->slot = dtype;
1042 *pst = (*pst)->next;
1050 dtype = debug_name_type (dhandle, name, dtype);
1051 if (dtype == DEBUG_TYPE_NULL)
1061 /* Static symbol of local scope */
1062 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
1063 (debug_type **) NULL);
1064 if (dtype == DEBUG_TYPE_NULL)
1066 /* FIXME: gdb checks os9k_stabs here. */
1067 if (! stab_record_variable (dhandle, info, name, dtype,
1068 DEBUG_LOCAL_STATIC, value))
1073 /* Reference parameter. */
1074 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
1075 (debug_type **) NULL);
1076 if (dtype == DEBUG_TYPE_NULL)
1078 if (! debug_record_parameter (dhandle, name, dtype, DEBUG_PARM_REFERENCE,
1084 /* Reference parameter which is in a register. */
1085 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
1086 (debug_type **) NULL);
1087 if (dtype == DEBUG_TYPE_NULL)
1089 if (! debug_record_parameter (dhandle, name, dtype, DEBUG_PARM_REF_REG,
1095 /* This is used by Sun FORTRAN for "function result value".
1096 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
1097 that Pascal uses it too, but when I tried it Pascal used
1098 "x:3" (local symbol) instead. */
1099 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
1100 (debug_type **) NULL);
1101 if (dtype == DEBUG_TYPE_NULL)
1103 if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_LOCAL,
1113 /* FIXME: gdb converts structure values to structure pointers in a
1114 couple of cases, depending upon the target. */
1119 /* Parse a stabs type. The typename argument is non-NULL if this is a
1120 typedef or a tag definition. The pp argument points to the stab
1121 string, and is updated. The slotp argument points to a place to
1122 store the slot used if the type is being defined. */
1125 parse_stab_type (void *dhandle, struct stab_handle *info, const char *typename, const char **pp, debug_type **slotp)
1130 bfd_boolean stringp;
1142 info->self_crossref = FALSE;
1144 /* Read type number if present. The type number may be omitted.
1145 for instance in a two-dimensional array declared with type
1146 "ar1;1;10;ar1;1;10;4". */
1147 if (! ISDIGIT (**pp) && **pp != '(' && **pp != '-')
1149 /* 'typenums=' not present, type is anonymous. Read and return
1150 the definition, but don't put it in the type vector. */
1151 typenums[0] = typenums[1] = -1;
1155 if (! parse_stab_type_number (pp, typenums))
1156 return DEBUG_TYPE_NULL;
1159 /* Type is not being defined here. Either it already
1160 exists, or this is a forward reference to it. */
1161 return stab_find_type (dhandle, info, typenums);
1163 /* Only set the slot if the type is being defined. This means
1164 that the mapping from type numbers to types will only record
1165 the name of the typedef which defines a type. If we don't do
1166 this, then something like
1169 will record that i is of type foo. Unfortunately, stabs
1170 information is ambiguous about variable types. For this code,
1174 the stabs information records both i and j as having the same
1175 type. This could be fixed by patching the compiler. */
1176 if (slotp != NULL && typenums[0] >= 0 && typenums[1] >= 0)
1177 *slotp = stab_find_slot (info, typenums);
1179 /* Type is being defined here. */
1185 const char *p = *pp + 1;
1188 if (ISDIGIT (*p) || *p == '(' || *p == '-')
1192 /* Type attributes. */
1195 for (; *p != ';'; ++p)
1200 return DEBUG_TYPE_NULL;
1208 size = atoi (attr + 1);
1209 size /= 8; /* Size is in bits. We store it in bytes. */
1219 /* Ignore unrecognized type attributes, so future
1220 compilers can invent new ones. */
1233 enum debug_type_kind code;
1234 const char *q1, *q2, *p;
1236 /* A cross reference to another type. */
1240 code = DEBUG_KIND_STRUCT;
1243 code = DEBUG_KIND_UNION;
1246 code = DEBUG_KIND_ENUM;
1249 /* Complain and keep going, so compilers can invent new
1250 cross-reference types. */
1251 warn_stab (orig, _("unrecognized cross reference type"));
1252 code = DEBUG_KIND_STRUCT;
1257 q1 = strchr (*pp, '<');
1258 p = strchr (*pp, ':');
1262 return DEBUG_TYPE_NULL;
1264 if (q1 != NULL && p > q1 && p[1] == ':')
1268 for (q2 = q1; *q2 != '\0'; ++q2)
1272 else if (*q2 == '>')
1274 else if (*q2 == ':' && nest == 0)
1281 return DEBUG_TYPE_NULL;
1285 /* Some versions of g++ can emit stabs like
1287 which define structures in terms of themselves. We need to
1288 tell the caller to avoid building a circular structure. */
1289 if (typename != NULL
1290 && strncmp (typename, *pp, p - *pp) == 0
1291 && typename[p - *pp] == '\0')
1292 info->self_crossref = TRUE;
1294 dtype = stab_find_tagged_type (dhandle, info, *pp, p - *pp, code);
1316 /* This type is defined as another type. */
1320 /* Peek ahead at the number to detect void. */
1321 if (! parse_stab_type_number (pp, xtypenums))
1322 return DEBUG_TYPE_NULL;
1324 if (typenums[0] == xtypenums[0] && typenums[1] == xtypenums[1])
1326 /* This type is being defined as itself, which means that
1328 dtype = debug_make_void_type (dhandle);
1334 /* Go back to the number and have parse_stab_type get it.
1335 This means that we can deal with something like
1336 t(1,2)=(3,4)=... which the Lucid compiler uses. */
1337 dtype = parse_stab_type (dhandle, info, (const char *) NULL,
1338 pp, (debug_type **) NULL);
1339 if (dtype == DEBUG_TYPE_NULL)
1340 return DEBUG_TYPE_NULL;
1343 if (typenums[0] != -1)
1345 if (! stab_record_type (dhandle, info, typenums, dtype))
1346 return DEBUG_TYPE_NULL;
1353 dtype = debug_make_pointer_type (dhandle,
1354 parse_stab_type (dhandle, info,
1355 (const char *) NULL,
1357 (debug_type **) NULL));
1361 /* Reference to another type. */
1362 dtype = (debug_make_reference_type
1364 parse_stab_type (dhandle, info, (const char *) NULL, pp,
1365 (debug_type **) NULL)));
1369 /* Function returning another type. */
1370 /* FIXME: gdb checks os9k_stabs here. */
1371 dtype = (debug_make_function_type
1373 parse_stab_type (dhandle, info, (const char *) NULL, pp,
1374 (debug_type **) NULL),
1375 (debug_type *) NULL, FALSE));
1379 /* Const qualifier on some type (Sun). */
1380 /* FIXME: gdb accepts 'c' here if os9k_stabs. */
1381 dtype = debug_make_const_type (dhandle,
1382 parse_stab_type (dhandle, info,
1383 (const char *) NULL,
1385 (debug_type **) NULL));
1389 /* Volatile qual on some type (Sun). */
1390 /* FIXME: gdb accepts 'i' here if os9k_stabs. */
1391 dtype = (debug_make_volatile_type
1393 parse_stab_type (dhandle, info, (const char *) NULL, pp,
1394 (debug_type **) NULL)));
1398 /* Offset (class & variable) type. This is used for a pointer
1399 relative to an object. */
1406 domain = parse_stab_type (dhandle, info, (const char *) NULL, pp,
1407 (debug_type **) NULL);
1408 if (domain == DEBUG_TYPE_NULL)
1409 return DEBUG_TYPE_NULL;
1414 return DEBUG_TYPE_NULL;
1418 memtype = parse_stab_type (dhandle, info, (const char *) NULL, pp,
1419 (debug_type **) NULL);
1420 if (memtype == DEBUG_TYPE_NULL)
1421 return DEBUG_TYPE_NULL;
1423 dtype = debug_make_offset_type (dhandle, domain, memtype);
1428 /* Method (class & fn) type. */
1431 debug_type return_type;
1434 return_type = parse_stab_type (dhandle, info, (const char *) NULL,
1435 pp, (debug_type **) NULL);
1436 if (return_type == DEBUG_TYPE_NULL)
1437 return DEBUG_TYPE_NULL;
1441 return DEBUG_TYPE_NULL;
1444 dtype = debug_make_method_type (dhandle, return_type,
1446 (debug_type *) NULL, FALSE);
1451 debug_type return_type;
1455 bfd_boolean varargs;
1457 domain = parse_stab_type (dhandle, info, (const char *) NULL,
1458 pp, (debug_type **) NULL);
1459 if (domain == DEBUG_TYPE_NULL)
1460 return DEBUG_TYPE_NULL;
1465 return DEBUG_TYPE_NULL;
1469 return_type = parse_stab_type (dhandle, info, (const char *) NULL,
1470 pp, (debug_type **) NULL);
1471 if (return_type == DEBUG_TYPE_NULL)
1472 return DEBUG_TYPE_NULL;
1475 args = (debug_type *) xmalloc (alloc * sizeof *args);
1482 return DEBUG_TYPE_NULL;
1489 args = ((debug_type *)
1490 xrealloc (args, alloc * sizeof *args));
1493 args[n] = parse_stab_type (dhandle, info, (const char *) NULL,
1494 pp, (debug_type **) NULL);
1495 if (args[n] == DEBUG_TYPE_NULL)
1496 return DEBUG_TYPE_NULL;
1501 /* If the last type is not void, then this function takes a
1502 variable number of arguments. Otherwise, we must strip
1505 || debug_get_type_kind (dhandle, args[n - 1]) != DEBUG_KIND_VOID)
1513 args[n] = DEBUG_TYPE_NULL;
1515 dtype = debug_make_method_type (dhandle, return_type, domain, args,
1522 dtype = parse_stab_range_type (dhandle, info, typename, pp, typenums);
1526 /* FIXME: gdb checks os9k_stabs here. */
1527 /* Sun ACC builtin int type. */
1528 dtype = parse_stab_sun_builtin_type (dhandle, pp);
1532 /* Sun ACC builtin float type. */
1533 dtype = parse_stab_sun_floating_type (dhandle, pp);
1537 /* Enumeration type. */
1538 dtype = parse_stab_enum_type (dhandle, pp);
1543 /* Struct or union type. */
1544 dtype = parse_stab_struct_type (dhandle, info, typename, pp,
1545 descriptor == 's', typenums);
1553 return DEBUG_TYPE_NULL;
1557 dtype = parse_stab_array_type (dhandle, info, pp, stringp);
1561 dtype = debug_make_set_type (dhandle,
1562 parse_stab_type (dhandle, info,
1563 (const char *) NULL,
1565 (debug_type **) NULL),
1571 return DEBUG_TYPE_NULL;
1574 if (dtype == DEBUG_TYPE_NULL)
1575 return DEBUG_TYPE_NULL;
1577 if (typenums[0] != -1)
1579 if (! stab_record_type (dhandle, info, typenums, dtype))
1580 return DEBUG_TYPE_NULL;
1585 if (! debug_record_type_size (dhandle, dtype, (unsigned int) size))
1586 return DEBUG_TYPE_NULL;
1592 /* Read a number by which a type is referred to in dbx data, or
1593 perhaps read a pair (FILENUM, TYPENUM) in parentheses. Just a
1594 single number N is equivalent to (0,N). Return the two numbers by
1595 storing them in the vector TYPENUMS. */
1598 parse_stab_type_number (const char **pp, int *typenums)
1607 typenums[1] = (int) parse_number (pp, (bfd_boolean *) NULL);
1612 typenums[0] = (int) parse_number (pp, (bfd_boolean *) NULL);
1619 typenums[1] = (int) parse_number (pp, (bfd_boolean *) NULL);
1631 /* Parse a range type. */
1634 parse_stab_range_type (void *dhandle, struct stab_handle *info, const char *typename, const char **pp, const int *typenums)
1638 bfd_boolean self_subrange;
1639 debug_type index_type;
1640 const char *s2, *s3;
1641 bfd_signed_vma n2, n3;
1642 bfd_boolean ov2, ov3;
1646 index_type = DEBUG_TYPE_NULL;
1648 /* First comes a type we are a subrange of.
1649 In C it is usually 0, 1 or the type being defined. */
1650 if (! parse_stab_type_number (pp, rangenums))
1651 return DEBUG_TYPE_NULL;
1653 self_subrange = (rangenums[0] == typenums[0]
1654 && rangenums[1] == typenums[1]);
1659 index_type = parse_stab_type (dhandle, info, (const char *) NULL,
1660 pp, (debug_type **) NULL);
1661 if (index_type == DEBUG_TYPE_NULL)
1662 return DEBUG_TYPE_NULL;
1668 /* The remaining two operands are usually lower and upper bounds of
1669 the range. But in some special cases they mean something else. */
1671 n2 = parse_number (pp, &ov2);
1675 return DEBUG_TYPE_NULL;
1680 n3 = parse_number (pp, &ov3);
1684 return DEBUG_TYPE_NULL;
1690 /* gcc will emit range stabs for long long types. Handle this
1691 as a special case. FIXME: This needs to be more general. */
1692 #define LLLOW "01000000000000000000000;"
1693 #define LLHIGH "0777777777777777777777;"
1694 #define ULLHIGH "01777777777777777777777;"
1695 if (index_type == DEBUG_TYPE_NULL)
1697 if (strncmp (s2, LLLOW, sizeof LLLOW - 1) == 0
1698 && strncmp (s3, LLHIGH, sizeof LLHIGH - 1) == 0)
1699 return debug_make_int_type (dhandle, 8, FALSE);
1702 && strncmp (s3, ULLHIGH, sizeof ULLHIGH - 1) == 0)
1703 return debug_make_int_type (dhandle, 8, TRUE);
1706 warn_stab (orig, _("numeric overflow"));
1709 if (index_type == DEBUG_TYPE_NULL)
1711 /* A type defined as a subrange of itself, with both bounds 0,
1713 if (self_subrange && n2 == 0 && n3 == 0)
1714 return debug_make_void_type (dhandle);
1716 /* A type defined as a subrange of itself, with n2 positive and
1717 n3 zero, is a complex type, and n2 is the number of bytes. */
1718 if (self_subrange && n3 == 0 && n2 > 0)
1719 return debug_make_complex_type (dhandle, n2);
1721 /* If n3 is zero and n2 is positive, this is a floating point
1722 type, and n2 is the number of bytes. */
1723 if (n3 == 0 && n2 > 0)
1724 return debug_make_float_type (dhandle, n2);
1726 /* If the upper bound is -1, this is an unsigned int. */
1727 if (n2 == 0 && n3 == -1)
1729 /* When gcc is used with -gstabs, but not -gstabs+, it will emit
1730 long long int:t6=r1;0;-1;
1731 long long unsigned int:t7=r1;0;-1;
1732 We hack here to handle this reasonably. */
1733 if (typename != NULL)
1735 if (strcmp (typename, "long long int") == 0)
1736 return debug_make_int_type (dhandle, 8, FALSE);
1737 else if (strcmp (typename, "long long unsigned int") == 0)
1738 return debug_make_int_type (dhandle, 8, TRUE);
1740 /* FIXME: The size here really depends upon the target. */
1741 return debug_make_int_type (dhandle, 4, TRUE);
1744 /* A range of 0 to 127 is char. */
1745 if (self_subrange && n2 == 0 && n3 == 127)
1746 return debug_make_int_type (dhandle, 1, FALSE);
1748 /* FIXME: gdb checks for the language CHILL here. */
1753 return debug_make_int_type (dhandle, - n3, TRUE);
1754 else if (n3 == 0xff)
1755 return debug_make_int_type (dhandle, 1, TRUE);
1756 else if (n3 == 0xffff)
1757 return debug_make_int_type (dhandle, 2, TRUE);
1758 else if (n3 == (bfd_signed_vma) 0xffffffff)
1759 return debug_make_int_type (dhandle, 4, TRUE);
1761 else if (n3 == ((((bfd_signed_vma) 0xffffffff) << 32) | 0xffffffff))
1762 return debug_make_int_type (dhandle, 8, TRUE);
1767 && (self_subrange || n2 == -8))
1768 return debug_make_int_type (dhandle, - n2, TRUE);
1769 else if (n2 == - n3 - 1 || n2 == n3 + 1)
1772 return debug_make_int_type (dhandle, 1, FALSE);
1773 else if (n3 == 0x7fff)
1774 return debug_make_int_type (dhandle, 2, FALSE);
1775 else if (n3 == 0x7fffffff)
1776 return debug_make_int_type (dhandle, 4, FALSE);
1778 else if (n3 == ((((bfd_vma) 0x7fffffff) << 32) | 0xffffffff))
1779 return debug_make_int_type (dhandle, 8, FALSE);
1784 /* At this point I don't have the faintest idea how to deal with a
1785 self_subrange type; I'm going to assume that this is used as an
1786 idiom, and that all of them are special cases. So . . . */
1790 return DEBUG_TYPE_NULL;
1793 index_type = stab_find_type (dhandle, info, rangenums);
1794 if (index_type == DEBUG_TYPE_NULL)
1796 /* Does this actually ever happen? Is that why we are worrying
1797 about dealing with it rather than just calling error_type? */
1798 warn_stab (orig, _("missing index type"));
1799 index_type = debug_make_int_type (dhandle, 4, FALSE);
1802 return debug_make_range_type (dhandle, index_type, n2, n3);
1805 /* Sun's ACC uses a somewhat saner method for specifying the builtin
1806 typedefs in every file (for int, long, etc):
1808 type = b <signed> <width>; <offset>; <nbits>
1809 signed = u or s. Possible c in addition to u or s (for char?).
1810 offset = offset from high order bit to start bit of type.
1811 width is # bytes in object of this type, nbits is # bits in type.
1813 The width/offset stuff appears to be for small objects stored in
1814 larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
1818 parse_stab_sun_builtin_type (void *dhandle, const char **pp)
1821 bfd_boolean unsignedp;
1836 return DEBUG_TYPE_NULL;
1840 /* For some odd reason, all forms of char put a c here. This is strange
1841 because no other type has this honor. We can safely ignore this because
1842 we actually determine 'char'acterness by the number of bits specified in
1847 /* The first number appears to be the number of bytes occupied
1848 by this type, except that unsigned short is 4 instead of 2.
1849 Since this information is redundant with the third number,
1850 we will ignore it. */
1851 (void) parse_number (pp, (bfd_boolean *) NULL);
1855 return DEBUG_TYPE_NULL;
1859 /* The second number is always 0, so ignore it too. */
1860 (void) parse_number (pp, (bfd_boolean *) NULL);
1864 return DEBUG_TYPE_NULL;
1868 /* The third number is the number of bits for this type. */
1869 bits = parse_number (pp, (bfd_boolean *) NULL);
1871 /* The type *should* end with a semicolon. If it are embedded
1872 in a larger type the semicolon may be the only way to know where
1873 the type ends. If this type is at the end of the stabstring we
1874 can deal with the omitted semicolon (but we don't have to like
1875 it). Don't bother to complain(), Sun's compiler omits the semicolon
1881 return debug_make_void_type (dhandle);
1883 return debug_make_int_type (dhandle, bits / 8, unsignedp);
1886 /* Parse a builtin floating type generated by the Sun compiler. */
1889 parse_stab_sun_floating_type (void *dhandle, const char **pp)
1897 /* The first number has more details about the type, for example
1899 details = parse_number (pp, (bfd_boolean *) NULL);
1903 return DEBUG_TYPE_NULL;
1906 /* The second number is the number of bytes occupied by this type */
1907 bytes = parse_number (pp, (bfd_boolean *) NULL);
1911 return DEBUG_TYPE_NULL;
1914 if (details == NF_COMPLEX
1915 || details == NF_COMPLEX16
1916 || details == NF_COMPLEX32)
1917 return debug_make_complex_type (dhandle, bytes);
1919 return debug_make_float_type (dhandle, bytes);
1922 /* Handle an enum type. */
1925 parse_stab_enum_type (void *dhandle, const char **pp)
1929 bfd_signed_vma *values;
1935 /* FIXME: gdb checks os9k_stabs here. */
1937 /* The aix4 compiler emits an extra field before the enum members;
1938 my guess is it's a type of some sort. Just ignore it. */
1946 /* Read the value-names and their values.
1947 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
1948 A semicolon or comma instead of a NAME means the end. */
1950 names = (const char **) xmalloc (alloc * sizeof *names);
1951 values = (bfd_signed_vma *) xmalloc (alloc * sizeof *values);
1953 while (**pp != '\0' && **pp != ';' && **pp != ',')
1963 name = savestring (*pp, p - *pp);
1966 val = (bfd_signed_vma) parse_number (pp, (bfd_boolean *) NULL);
1970 return DEBUG_TYPE_NULL;
1977 names = ((const char **)
1978 xrealloc (names, alloc * sizeof *names));
1979 values = ((bfd_signed_vma *)
1980 xrealloc (values, alloc * sizeof *values));
1994 return debug_make_enum_type (dhandle, names, values);
1997 /* Read the description of a structure (or union type) and return an object
1998 describing the type.
2000 PP points to a character pointer that points to the next unconsumed token
2001 in the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;",
2002 *PP will point to "4a:1,0,32;;". */
2005 parse_stab_struct_type (void *dhandle, struct stab_handle *info,
2006 const char *tagname, const char **pp,
2007 bfd_boolean structp, const int *typenums)
2011 debug_baseclass *baseclasses;
2012 debug_field *fields;
2013 bfd_boolean statics;
2014 debug_method *methods;
2015 debug_type vptrbase;
2016 bfd_boolean ownvptr;
2021 size = parse_number (pp, (bfd_boolean *) NULL);
2023 /* Get the other information. */
2024 if (! parse_stab_baseclasses (dhandle, info, pp, &baseclasses)
2025 || ! parse_stab_struct_fields (dhandle, info, pp, &fields, &statics)
2026 || ! parse_stab_members (dhandle, info, tagname, pp, typenums, &methods)
2027 || ! parse_stab_tilde_field (dhandle, info, pp, typenums, &vptrbase,
2029 return DEBUG_TYPE_NULL;
2032 && baseclasses == NULL
2034 && vptrbase == DEBUG_TYPE_NULL
2036 return debug_make_struct_type (dhandle, structp, size, fields);
2038 return debug_make_object_type (dhandle, structp, size, fields, baseclasses,
2039 methods, vptrbase, ownvptr);
2042 /* The stabs for C++ derived classes contain baseclass information which
2043 is marked by a '!' character after the total size. This function is
2044 called when we encounter the baseclass marker, and slurps up all the
2045 baseclass information.
2047 Immediately following the '!' marker is the number of base classes that
2048 the class is derived from, followed by information for each base class.
2049 For each base class, there are two visibility specifiers, a bit offset
2050 to the base class information within the derived class, a reference to
2051 the type for the base class, and a terminating semicolon.
2053 A typical example, with two base classes, would be "!2,020,19;0264,21;".
2055 Baseclass information marker __________________|| | | | | | |
2056 Number of baseclasses __________________________| | | | | | |
2057 Visibility specifiers (2) ________________________| | | | | |
2058 Offset in bits from start of class _________________| | | | |
2059 Type number for base class ___________________________| | | |
2060 Visibility specifiers (2) _______________________________| | |
2061 Offset in bits from start of class ________________________| |
2062 Type number of base class ____________________________________|
2064 Return TRUE for success, FALSE for failure. */
2067 parse_stab_baseclasses (void *dhandle, struct stab_handle *info,
2068 const char **pp, debug_baseclass **retp)
2072 debug_baseclass *classes;
2080 /* No base classes. */
2085 c = (unsigned int) parse_number (pp, (bfd_boolean *) NULL);
2094 classes = (debug_baseclass *) xmalloc ((c + 1) * sizeof (**retp));
2096 for (i = 0; i < c; i++)
2098 bfd_boolean virtual;
2099 enum debug_visibility visibility;
2112 warn_stab (orig, _("unknown virtual character for baseclass"));
2121 visibility = DEBUG_VISIBILITY_PRIVATE;
2124 visibility = DEBUG_VISIBILITY_PROTECTED;
2127 visibility = DEBUG_VISIBILITY_PUBLIC;
2130 warn_stab (orig, _("unknown visibility character for baseclass"));
2131 visibility = DEBUG_VISIBILITY_PUBLIC;
2136 /* The remaining value is the bit offset of the portion of the
2137 object corresponding to this baseclass. Always zero in the
2138 absence of multiple inheritance. */
2139 bitpos = parse_number (pp, (bfd_boolean *) NULL);
2147 type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
2148 (debug_type **) NULL);
2149 if (type == DEBUG_TYPE_NULL)
2152 classes[i] = debug_make_baseclass (dhandle, type, bitpos, virtual,
2154 if (classes[i] == DEBUG_BASECLASS_NULL)
2162 classes[i] = DEBUG_BASECLASS_NULL;
2169 /* Read struct or class data fields. They have the form:
2171 NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
2173 At the end, we see a semicolon instead of a field.
2175 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
2178 The optional VISIBILITY is one of:
2180 '/0' (VISIBILITY_PRIVATE)
2181 '/1' (VISIBILITY_PROTECTED)
2182 '/2' (VISIBILITY_PUBLIC)
2183 '/9' (VISIBILITY_IGNORE)
2185 or nothing, for C style fields with public visibility.
2187 Returns 1 for success, 0 for failure. */
2190 parse_stab_struct_fields (void *dhandle, struct stab_handle *info,
2191 const char **pp, debug_field **retp,
2192 bfd_boolean *staticsp)
2196 debug_field *fields;
2207 fields = (debug_field *) xmalloc (alloc * sizeof *fields);
2210 /* FIXME: gdb checks os9k_stabs here. */
2214 /* Add 1 to c to leave room for NULL pointer at end. */
2218 fields = ((debug_field *)
2219 xrealloc (fields, alloc * sizeof *fields));
2222 /* If it starts with CPLUS_MARKER it is a special abbreviation,
2223 unless the CPLUS_MARKER is followed by an underscore, in
2224 which case it is just the name of an anonymous type, which we
2225 should handle like any other type name. We accept either '$'
2226 or '.', because a field name can never contain one of these
2227 characters except as a CPLUS_MARKER. */
2229 if ((*p == '$' || *p == '.') && p[1] != '_')
2232 if (! parse_stab_cpp_abbrev (dhandle, info, pp, fields + c))
2238 /* Look for the ':' that separates the field name from the field
2239 values. Data members are delimited by a single ':', while member
2240 functions are delimited by a pair of ':'s. When we hit the member
2241 functions (if any), terminate scan loop and return. */
2243 p = strchr (p, ':');
2253 if (! parse_stab_one_struct_field (dhandle, info, pp, p, fields + c,
2260 fields[c] = DEBUG_FIELD_NULL;
2267 /* Special GNU C++ name. */
2270 parse_stab_cpp_abbrev (void *dhandle, struct stab_handle *info,
2271 const char **pp, debug_field *retp)
2277 const char *typename;
2281 *retp = DEBUG_FIELD_NULL;
2295 /* At this point, *pp points to something like "22:23=*22...", where
2296 the type number before the ':' is the "context" and everything
2297 after is a regular type definition. Lookup the type, find it's
2298 name, and construct the field name. */
2300 context = parse_stab_type (dhandle, info, (const char *) NULL, pp,
2301 (debug_type **) NULL);
2302 if (context == DEBUG_TYPE_NULL)
2308 /* $vf -- a virtual function table pointer. */
2312 /* $vb -- a virtual bsomethingorother */
2313 typename = debug_get_type_name (dhandle, context);
2314 if (typename == NULL)
2316 warn_stab (orig, _("unnamed $vb type"));
2319 name = concat ("_vb$", typename, (const char *) NULL);
2322 warn_stab (orig, _("unrecognized C++ abbreviation"));
2323 name = "INVALID_CPLUSPLUS_ABBREV";
2334 type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
2335 (debug_type **) NULL);
2343 bitpos = parse_number (pp, (bfd_boolean *) NULL);
2351 *retp = debug_make_field (dhandle, name, type, bitpos, 0,
2352 DEBUG_VISIBILITY_PRIVATE);
2353 if (*retp == DEBUG_FIELD_NULL)
2359 /* Parse a single field in a struct or union. */
2362 parse_stab_one_struct_field (void *dhandle, struct stab_handle *info,
2363 const char **pp, const char *p,
2364 debug_field *retp, bfd_boolean *staticsp)
2368 enum debug_visibility visibility;
2375 /* FIXME: gdb checks ARM_DEMANGLING here. */
2377 name = savestring (*pp, p - *pp);
2382 visibility = DEBUG_VISIBILITY_PUBLIC;
2389 visibility = DEBUG_VISIBILITY_PRIVATE;
2392 visibility = DEBUG_VISIBILITY_PROTECTED;
2395 visibility = DEBUG_VISIBILITY_PUBLIC;
2398 warn_stab (orig, _("unknown visibility character for field"));
2399 visibility = DEBUG_VISIBILITY_PUBLIC;
2405 type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
2406 (debug_type **) NULL);
2407 if (type == DEBUG_TYPE_NULL)
2414 /* This is a static class member. */
2416 p = strchr (*pp, ';');
2423 varname = savestring (*pp, p - *pp);
2427 *retp = debug_make_static_member (dhandle, name, type, varname,
2441 bitpos = parse_number (pp, (bfd_boolean *) NULL);
2449 bitsize = parse_number (pp, (bfd_boolean *) NULL);
2457 if (bitpos == 0 && bitsize == 0)
2459 /* This can happen in two cases: (1) at least for gcc 2.4.5 or
2460 so, it is a field which has been optimized out. The correct
2461 stab for this case is to use VISIBILITY_IGNORE, but that is a
2462 recent invention. (2) It is a 0-size array. For example
2463 union { int num; char str[0]; } foo. Printing "<no value>"
2464 for str in "p foo" is OK, since foo.str (and thus foo.str[3])
2465 will continue to work, and a 0-size array as a whole doesn't
2466 have any contents to print.
2468 I suspect this probably could also happen with gcc -gstabs
2469 (not -gstabs+) for static fields, and perhaps other C++
2470 extensions. Hopefully few people use -gstabs with gdb, since
2471 it is intended for dbx compatibility. */
2472 visibility = DEBUG_VISIBILITY_IGNORE;
2475 /* FIXME: gdb does some stuff here to mark fields as unpacked. */
2477 *retp = debug_make_field (dhandle, name, type, bitpos, bitsize, visibility);
2482 /* Read member function stabs info for C++ classes. The form of each member
2485 NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;
2487 An example with two member functions is:
2489 afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;
2491 For the case of overloaded operators, the format is op$::*.funcs, where
2492 $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
2493 name (such as `+=') and `.' marks the end of the operator name. */
2496 parse_stab_members (void *dhandle, struct stab_handle *info,
2497 const char *tagname, const char **pp,
2498 const int *typenums, debug_method **retp)
2501 debug_method *methods;
2517 debug_method_variant *variants;
2519 unsigned int allocvars;
2520 debug_type look_ahead_type;
2522 p = strchr (*pp, ':');
2523 if (p == NULL || p[1] != ':')
2526 /* FIXME: Some systems use something other than '$' here. */
2527 if ((*pp)[0] != 'o' || (*pp)[1] != 'p' || (*pp)[2] != '$')
2529 name = savestring (*pp, p - *pp);
2534 /* This is a completely weird case. In order to stuff in the
2535 names that might contain colons (the usual name delimiter),
2536 Mike Tiemann defined a different name format which is
2537 signalled if the identifier is "op$". In that case, the
2538 format is "op$::XXXX." where XXXX is the name. This is
2539 used for names like "+" or "=". YUUUUUUUK! FIXME! */
2541 for (p = *pp; *p != '.' && *p != '\0'; p++)
2548 name = savestring (*pp, p - *pp);
2553 variants = ((debug_method_variant *)
2554 xmalloc (allocvars * sizeof *variants));
2557 look_ahead_type = DEBUG_TYPE_NULL;
2564 enum debug_visibility visibility;
2565 bfd_boolean constp, volatilep, staticp;
2568 const char *physname;
2569 bfd_boolean varargs;
2571 if (look_ahead_type != DEBUG_TYPE_NULL)
2573 /* g++ version 1 kludge */
2574 type = look_ahead_type;
2575 look_ahead_type = DEBUG_TYPE_NULL;
2579 type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
2580 (debug_type **) NULL);
2581 if (type == DEBUG_TYPE_NULL)
2591 p = strchr (*pp, ';');
2599 if (debug_get_type_kind (dhandle, type) == DEBUG_KIND_METHOD
2600 && debug_get_parameter_types (dhandle, type, &varargs) == NULL)
2603 argtypes = savestring (*pp, p - *pp);
2609 visibility = DEBUG_VISIBILITY_PRIVATE;
2612 visibility = DEBUG_VISIBILITY_PROTECTED;
2615 visibility = DEBUG_VISIBILITY_PUBLIC;
2625 /* Normal function. */
2629 /* const member function. */
2634 /* volatile member function. */
2639 /* const volatile member function. */
2647 /* File compiled with g++ version 1; no information. */
2650 warn_stab (orig, _("const/volatile indicator missing"));
2658 /* virtual member function, followed by index. The sign
2659 bit is supposedly set to distinguish
2660 pointers-to-methods from virtual function indicies. */
2662 voffset = parse_number (pp, (bfd_boolean *) NULL);
2669 voffset &= 0x7fffffff;
2671 if (**pp == ';' || *pp == '\0')
2673 /* Must be g++ version 1. */
2674 context = DEBUG_TYPE_NULL;
2678 /* Figure out from whence this virtual function
2679 came. It may belong to virtual function table of
2680 one of its baseclasses. */
2681 look_ahead_type = parse_stab_type (dhandle, info,
2682 (const char *) NULL,
2684 (debug_type **) NULL);
2687 /* g++ version 1 overloaded methods. */
2688 context = DEBUG_TYPE_NULL;
2692 context = look_ahead_type;
2693 look_ahead_type = DEBUG_TYPE_NULL;
2705 /* static member function. */
2709 context = DEBUG_TYPE_NULL;
2710 if (strncmp (argtypes, name, strlen (name)) != 0)
2715 warn_stab (orig, "member function type missing");
2717 context = DEBUG_TYPE_NULL;
2723 context = DEBUG_TYPE_NULL;
2727 /* If the type is not a stub, then the argtypes string is
2728 the physical name of the function. Otherwise the
2729 argtypes string is the mangled form of the argument
2730 types, and the full type and the physical name must be
2731 extracted from them. */
2733 physname = argtypes;
2736 debug_type class_type, return_type;
2738 class_type = stab_find_type (dhandle, info, typenums);
2739 if (class_type == DEBUG_TYPE_NULL)
2741 return_type = debug_get_return_type (dhandle, type);
2742 if (return_type == DEBUG_TYPE_NULL)
2747 type = parse_stab_argtypes (dhandle, info, class_type, name,
2748 tagname, return_type, argtypes,
2749 constp, volatilep, &physname);
2750 if (type == DEBUG_TYPE_NULL)
2754 if (cvars + 1 >= allocvars)
2757 variants = ((debug_method_variant *)
2759 allocvars * sizeof *variants));
2763 variants[cvars] = debug_make_method_variant (dhandle, physname,
2768 variants[cvars] = debug_make_static_method_variant (dhandle,
2774 if (variants[cvars] == DEBUG_METHOD_VARIANT_NULL)
2779 while (**pp != ';' && **pp != '\0');
2781 variants[cvars] = DEBUG_METHOD_VARIANT_NULL;
2789 methods = ((debug_method *)
2790 xrealloc (methods, alloc * sizeof *methods));
2793 methods[c] = debug_make_method (dhandle, name, variants);
2798 if (methods != NULL)
2799 methods[c] = DEBUG_METHOD_NULL;
2806 /* Parse a string representing argument types for a method. Stabs
2807 tries to save space by packing argument types into a mangled
2808 string. This string should give us enough information to extract
2809 both argument types and the physical name of the function, given
2813 parse_stab_argtypes (void *dhandle, struct stab_handle *info,
2814 debug_type class_type, const char *fieldname,
2815 const char *tagname, debug_type return_type,
2816 const char *argtypes, bfd_boolean constp,
2817 bfd_boolean volatilep, const char **pphysname)
2819 bfd_boolean is_full_physname_constructor;
2820 bfd_boolean is_constructor;
2821 bfd_boolean is_destructor;
2824 bfd_boolean varargs;
2825 unsigned int physname_len = 0;
2827 /* Constructors are sometimes handled specially. */
2828 is_full_physname_constructor = ((argtypes[0] == '_'
2829 && argtypes[1] == '_'
2830 && (ISDIGIT (argtypes[2])
2831 || argtypes[2] == 'Q'
2832 || argtypes[2] == 't'))
2833 || strncmp (argtypes, "__ct", 4) == 0);
2835 is_constructor = (is_full_physname_constructor
2837 && strcmp (fieldname, tagname) == 0));
2838 is_destructor = ((argtypes[0] == '_'
2839 && (argtypes[1] == '$' || argtypes[1] == '.')
2840 && argtypes[2] == '_')
2841 || strncmp (argtypes, "__dt", 4) == 0);
2842 is_v3 = argtypes[0] == '_' && argtypes[1] == 'Z';
2844 if (is_destructor || is_full_physname_constructor || is_v3)
2845 *pphysname = argtypes;
2849 const char *const_prefix;
2850 const char *volatile_prefix;
2852 unsigned int mangled_name_len;
2855 len = tagname == NULL ? 0 : strlen (tagname);
2856 const_prefix = constp ? "C" : "";
2857 volatile_prefix = volatilep ? "V" : "";
2860 sprintf (buf, "__%s%s", const_prefix, volatile_prefix);
2861 else if (tagname != NULL && strchr (tagname, '<') != NULL)
2863 /* Template methods are fully mangled. */
2864 sprintf (buf, "__%s%s", const_prefix, volatile_prefix);
2869 sprintf (buf, "__%s%s%d", const_prefix, volatile_prefix, len);
2871 mangled_name_len = ((is_constructor ? 0 : strlen (fieldname))
2877 if (fieldname[0] == 'o'
2878 && fieldname[1] == 'p'
2879 && (fieldname[2] == '$' || fieldname[2] == '.'))
2883 opname = cplus_mangle_opname (fieldname + 3, 0);
2886 fprintf (stderr, _("No mangling for \"%s\"\n"), fieldname);
2887 return DEBUG_TYPE_NULL;
2889 mangled_name_len += strlen (opname);
2890 physname = (char *) xmalloc (mangled_name_len);
2891 strncpy (physname, fieldname, 3);
2892 strcpy (physname + 3, opname);
2896 physname = (char *) xmalloc (mangled_name_len);
2900 strcpy (physname, fieldname);
2903 physname_len = strlen (physname);
2904 strcat (physname, buf);
2905 if (tagname != NULL)
2906 strcat (physname, tagname);
2907 strcat (physname, argtypes);
2909 *pphysname = physname;
2912 if (*argtypes == '\0' || is_destructor)
2914 args = (debug_type *) xmalloc (sizeof *args);
2916 return debug_make_method_type (dhandle, return_type, class_type, args,
2920 args = stab_demangle_argtypes (dhandle, info, *pphysname, &varargs, physname_len);
2922 return DEBUG_TYPE_NULL;
2924 return debug_make_method_type (dhandle, return_type, class_type, args,
2928 /* The tail end of stabs for C++ classes that contain a virtual function
2929 pointer contains a tilde, a %, and a type number.
2930 The type number refers to the base class (possibly this class itself) which
2931 contains the vtable pointer for the current class.
2933 This function is called when we have parsed all the method declarations,
2934 so we can look for the vptr base class info. */
2937 parse_stab_tilde_field (void *dhandle, struct stab_handle *info,
2938 const char **pp, const int *typenums,
2939 debug_type *retvptrbase, bfd_boolean *retownvptr)
2945 *retvptrbase = DEBUG_TYPE_NULL;
2946 *retownvptr = FALSE;
2950 /* If we are positioned at a ';', then skip it. */
2959 if (**pp == '=' || **pp == '+' || **pp == '-')
2961 /* Obsolete flags that used to indicate the presence of
2962 constructors and/or destructors. */
2973 /* The next number is the type number of the base class (possibly
2974 our own class) which supplies the vtable for this class. */
2975 if (! parse_stab_type_number (pp, vtypenums))
2978 if (vtypenums[0] == typenums[0]
2979 && vtypenums[1] == typenums[1])
2988 vtype = parse_stab_type (dhandle, info, (const char *) NULL, pp,
2989 (debug_type **) NULL);
2990 for (p = *pp; *p != ';' && *p != '\0'; p++)
2998 *retvptrbase = vtype;
3006 /* Read a definition of an array type. */
3009 parse_stab_array_type (void *dhandle, struct stab_handle *info,
3010 const char **pp, bfd_boolean stringp)
3015 debug_type index_type;
3016 bfd_boolean adjustable;
3017 bfd_signed_vma lower, upper;
3018 debug_type element_type;
3020 /* Format of an array type:
3021 "ar<index type>;lower;upper;<array_contents_type>".
3022 OS9000: "arlower,upper;<array_contents_type>".
3024 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
3025 for these, produce a type like float[][]. */
3029 /* FIXME: gdb checks os9k_stabs here. */
3031 /* If the index type is type 0, we take it as int. */
3033 if (! parse_stab_type_number (&p, typenums))
3034 return DEBUG_TYPE_NULL;
3035 if (typenums[0] == 0 && typenums[1] == 0 && **pp != '=')
3037 index_type = debug_find_named_type (dhandle, "int");
3038 if (index_type == DEBUG_TYPE_NULL)
3040 index_type = debug_make_int_type (dhandle, 4, FALSE);
3041 if (index_type == DEBUG_TYPE_NULL)
3042 return DEBUG_TYPE_NULL;
3048 index_type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
3049 (debug_type **) NULL);
3055 return DEBUG_TYPE_NULL;
3061 if (! ISDIGIT (**pp) && **pp != '-')
3067 lower = (bfd_signed_vma) parse_number (pp, (bfd_boolean *) NULL);
3071 return DEBUG_TYPE_NULL;
3075 if (! ISDIGIT (**pp) && **pp != '-')
3081 upper = (bfd_signed_vma) parse_number (pp, (bfd_boolean *) NULL);
3085 return DEBUG_TYPE_NULL;
3089 element_type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
3090 (debug_type **) NULL);
3091 if (element_type == DEBUG_TYPE_NULL)
3092 return DEBUG_TYPE_NULL;
3100 return debug_make_array_type (dhandle, element_type, index_type, lower,
3104 /* This struct holds information about files we have seen using
3109 /* The next N_BINCL file. */
3110 struct bincl_file *next;
3111 /* The next N_BINCL on the stack. */
3112 struct bincl_file *next_stack;
3113 /* The file name. */
3115 /* The hash value. */
3117 /* The file index. */
3119 /* The list of types defined in this file. */
3120 struct stab_types *file_types;
3123 /* Start a new N_BINCL file, pushing it onto the stack. */
3126 push_bincl (struct stab_handle *info, const char *name, bfd_vma hash)
3128 struct bincl_file *n;
3130 n = (struct bincl_file *) xmalloc (sizeof *n);
3131 n->next = info->bincl_list;
3132 n->next_stack = info->bincl_stack;
3135 n->file = info->files;
3136 n->file_types = NULL;
3137 info->bincl_list = n;
3138 info->bincl_stack = n;
3141 info->file_types = ((struct stab_types **)
3142 xrealloc (info->file_types,
3144 * sizeof *info->file_types)));
3145 info->file_types[n->file] = NULL;
3148 /* Finish an N_BINCL file, at an N_EINCL, popping the name off the
3152 pop_bincl (struct stab_handle *info)
3154 struct bincl_file *o;
3156 o = info->bincl_stack;
3158 return info->main_filename;
3159 info->bincl_stack = o->next_stack;
3161 o->file_types = info->file_types[o->file];
3163 if (info->bincl_stack == NULL)
3164 return info->main_filename;
3165 return info->bincl_stack->name;
3168 /* Handle an N_EXCL: get the types from the corresponding N_BINCL. */
3171 find_excl (struct stab_handle *info, const char *name, bfd_vma hash)
3173 struct bincl_file *l;
3176 info->file_types = ((struct stab_types **)
3177 xrealloc (info->file_types,
3179 * sizeof *info->file_types)));
3181 for (l = info->bincl_list; l != NULL; l = l->next)
3182 if (l->hash == hash && strcmp (l->name, name) == 0)
3186 warn_stab (name, _("Undefined N_EXCL"));
3187 info->file_types[info->files - 1] = NULL;
3191 info->file_types[info->files - 1] = l->file_types;
3196 /* Handle a variable definition. gcc emits variable definitions for a
3197 block before the N_LBRAC, so we must hold onto them until we see
3198 it. The SunPRO compiler emits variable definitions after the
3199 N_LBRAC, so we can call debug_record_variable immediately. */
3202 stab_record_variable (void *dhandle, struct stab_handle *info,
3203 const char *name, debug_type type,
3204 enum debug_var_kind kind, bfd_vma val)
3206 struct stab_pending_var *v;
3208 if ((kind == DEBUG_GLOBAL || kind == DEBUG_STATIC)
3209 || ! info->within_function
3210 || (info->gcc_compiled == 0 && info->n_opt_found))
3211 return debug_record_variable (dhandle, name, type, kind, val);
3213 v = (struct stab_pending_var *) xmalloc (sizeof *v);
3214 memset (v, 0, sizeof *v);
3216 v->next = info->pending;
3226 /* Emit pending variable definitions. This is called after we see the
3227 N_LBRAC that starts the block. */
3230 stab_emit_pending_vars (void *dhandle, struct stab_handle *info)
3232 struct stab_pending_var *v;
3237 struct stab_pending_var *next;
3239 if (! debug_record_variable (dhandle, v->name, v->type, v->kind, v->val))
3247 info->pending = NULL;
3252 /* Find the slot for a type in the database. */
3255 stab_find_slot (struct stab_handle *info, const int *typenums)
3259 struct stab_types **ps;
3261 filenum = typenums[0];
3262 index = typenums[1];
3264 if (filenum < 0 || (unsigned int) filenum >= info->files)
3266 fprintf (stderr, _("Type file number %d out of range\n"), filenum);
3271 fprintf (stderr, _("Type index number %d out of range\n"), index);
3275 ps = info->file_types + filenum;
3277 while (index >= STAB_TYPES_SLOTS)
3281 *ps = (struct stab_types *) xmalloc (sizeof **ps);
3282 memset (*ps, 0, sizeof **ps);
3285 index -= STAB_TYPES_SLOTS;
3289 *ps = (struct stab_types *) xmalloc (sizeof **ps);
3290 memset (*ps, 0, sizeof **ps);
3293 return (*ps)->types + index;
3296 /* Find a type given a type number. If the type has not been
3297 allocated yet, create an indirect type. */
3300 stab_find_type (void *dhandle, struct stab_handle *info, const int *typenums)
3304 if (typenums[0] == 0 && typenums[1] < 0)
3306 /* A negative type number indicates an XCOFF builtin type. */
3307 return stab_xcoff_builtin_type (dhandle, info, typenums[1]);
3310 slot = stab_find_slot (info, typenums);
3312 return DEBUG_TYPE_NULL;
3314 if (*slot == DEBUG_TYPE_NULL)
3315 return debug_make_indirect_type (dhandle, slot, (const char *) NULL);
3320 /* Record that a given type number refers to a given type. */
3323 stab_record_type (void *dhandle ATTRIBUTE_UNUSED, struct stab_handle *info,
3324 const int *typenums, debug_type type)
3328 slot = stab_find_slot (info, typenums);
3332 /* gdb appears to ignore type redefinitions, so we do as well. */
3339 /* Return an XCOFF builtin type. */
3342 stab_xcoff_builtin_type (void *dhandle, struct stab_handle *info,
3348 if (typenum >= 0 || typenum < -XCOFF_TYPE_COUNT)
3350 fprintf (stderr, _("Unrecognized XCOFF type %d\n"), typenum);
3351 return DEBUG_TYPE_NULL;
3353 if (info->xcoff_types[-typenum] != NULL)
3354 return info->xcoff_types[-typenum];
3359 /* The size of this and all the other types are fixed, defined
3360 by the debugging format. */
3362 rettype = debug_make_int_type (dhandle, 4, FALSE);
3366 rettype = debug_make_int_type (dhandle, 1, FALSE);
3370 rettype = debug_make_int_type (dhandle, 2, FALSE);
3374 rettype = debug_make_int_type (dhandle, 4, FALSE);
3377 name = "unsigned char";
3378 rettype = debug_make_int_type (dhandle, 1, TRUE);
3381 name = "signed char";
3382 rettype = debug_make_int_type (dhandle, 1, FALSE);
3385 name = "unsigned short";
3386 rettype = debug_make_int_type (dhandle, 2, TRUE);
3389 name = "unsigned int";
3390 rettype = debug_make_int_type (dhandle, 4, TRUE);
3394 rettype = debug_make_int_type (dhandle, 4, TRUE);
3396 name = "unsigned long";
3397 rettype = debug_make_int_type (dhandle, 4, TRUE);
3401 rettype = debug_make_void_type (dhandle);
3404 /* IEEE single precision (32 bit). */
3406 rettype = debug_make_float_type (dhandle, 4);
3409 /* IEEE double precision (64 bit). */
3411 rettype = debug_make_float_type (dhandle, 8);
3414 /* This is an IEEE double on the RS/6000, and different machines
3415 with different sizes for "long double" should use different
3416 negative type numbers. See stabs.texinfo. */
3417 name = "long double";
3418 rettype = debug_make_float_type (dhandle, 8);
3422 rettype = debug_make_int_type (dhandle, 4, FALSE);
3426 rettype = debug_make_bool_type (dhandle, 4);
3429 name = "short real";
3430 rettype = debug_make_float_type (dhandle, 4);
3434 rettype = debug_make_float_type (dhandle, 8);
3444 rettype = debug_make_int_type (dhandle, 1, TRUE);
3448 rettype = debug_make_bool_type (dhandle, 1);
3452 rettype = debug_make_bool_type (dhandle, 2);
3456 rettype = debug_make_bool_type (dhandle, 4);
3460 rettype = debug_make_bool_type (dhandle, 4);
3463 /* Complex type consisting of two IEEE single precision values. */
3465 rettype = debug_make_complex_type (dhandle, 8);
3468 /* Complex type consisting of two IEEE double precision values. */
3469 name = "double complex";
3470 rettype = debug_make_complex_type (dhandle, 16);
3474 rettype = debug_make_int_type (dhandle, 1, FALSE);
3478 rettype = debug_make_int_type (dhandle, 2, FALSE);
3482 rettype = debug_make_int_type (dhandle, 4, FALSE);
3487 rettype = debug_make_int_type (dhandle, 2, FALSE);
3491 rettype = debug_make_int_type (dhandle, 8, FALSE);
3494 name = "unsigned long long";
3495 rettype = debug_make_int_type (dhandle, 8, TRUE);
3499 rettype = debug_make_bool_type (dhandle, 8);
3503 rettype = debug_make_int_type (dhandle, 8, FALSE);
3509 rettype = debug_name_type (dhandle, name, rettype);
3511 info->xcoff_types[-typenum] = rettype;
3516 /* Find or create a tagged type. */
3519 stab_find_tagged_type (void *dhandle, struct stab_handle *info,
3520 const char *p, int len, enum debug_type_kind kind)
3524 struct stab_tag *st;
3526 name = savestring (p, len);
3528 /* We pass DEBUG_KIND_ILLEGAL because we want all tags in the same
3529 namespace. This is right for C, and I don't know how to handle
3530 other languages. FIXME. */
3531 dtype = debug_find_tagged_type (dhandle, name, DEBUG_KIND_ILLEGAL);
3532 if (dtype != DEBUG_TYPE_NULL)
3538 /* We need to allocate an entry on the undefined tag list. */
3539 for (st = info->tags; st != NULL; st = st->next)
3541 if (st->name[0] == name[0]
3542 && strcmp (st->name, name) == 0)
3544 if (st->kind == DEBUG_KIND_ILLEGAL)
3552 st = (struct stab_tag *) xmalloc (sizeof *st);
3553 memset (st, 0, sizeof *st);
3555 st->next = info->tags;
3558 st->slot = DEBUG_TYPE_NULL;
3559 st->type = debug_make_indirect_type (dhandle, &st->slot, name);
3566 /* In order to get the correct argument types for a stubbed method, we
3567 need to extract the argument types from a C++ mangled string.
3568 Since the argument types can refer back to the return type, this
3569 means that we must demangle the entire physical name. In gdb this
3570 is done by calling cplus_demangle and running the results back
3571 through the C++ expression parser. Since we have no expression
3572 parser, we must duplicate much of the work of cplus_demangle here.
3574 We assume that GNU style demangling is used, since this is only
3575 done for method stubs, and only g++ should output that form of
3576 debugging information. */
3578 /* This structure is used to hold a pointer to type information which
3579 demangling a string. */
3581 struct stab_demangle_typestring
3583 /* The start of the type. This is not null terminated. */
3584 const char *typestring;
3585 /* The length of the type. */
3589 /* This structure is used to hold information while demangling a
3592 struct stab_demangle_info
3594 /* The debugging information handle. */
3596 /* The stab information handle. */
3597 struct stab_handle *info;
3598 /* The array of arguments we are building. */
3600 /* Whether the method takes a variable number of arguments. */
3601 bfd_boolean varargs;
3602 /* The array of types we have remembered. */
3603 struct stab_demangle_typestring *typestrings;
3604 /* The number of typestrings. */
3605 unsigned int typestring_count;
3606 /* The number of typestring slots we have allocated. */
3607 unsigned int typestring_alloc;
3610 static void stab_bad_demangle (const char *);
3611 static unsigned int stab_demangle_count (const char **);
3612 static bfd_boolean stab_demangle_get_count (const char **, unsigned int *);
3613 static bfd_boolean stab_demangle_prefix
3614 (struct stab_demangle_info *, const char **, unsigned int);
3615 static bfd_boolean stab_demangle_function_name
3616 (struct stab_demangle_info *, const char **, const char *);
3617 static bfd_boolean stab_demangle_signature
3618 (struct stab_demangle_info *, const char **);
3619 static bfd_boolean stab_demangle_qualified
3620 (struct stab_demangle_info *, const char **, debug_type *);
3621 static bfd_boolean stab_demangle_template
3622 (struct stab_demangle_info *, const char **, char **);
3623 static bfd_boolean stab_demangle_class
3624 (struct stab_demangle_info *, const char **, const char **);
3625 static bfd_boolean stab_demangle_args
3626 (struct stab_demangle_info *, const char **, debug_type **, bfd_boolean *);
3627 static bfd_boolean stab_demangle_arg
3628 (struct stab_demangle_info *, const char **, debug_type **,
3629 unsigned int *, unsigned int *);
3630 static bfd_boolean stab_demangle_type
3631 (struct stab_demangle_info *, const char **, debug_type *);
3632 static bfd_boolean stab_demangle_fund_type
3633 (struct stab_demangle_info *, const char **, debug_type *);
3634 static bfd_boolean stab_demangle_remember_type
3635 (struct stab_demangle_info *, const char *, int);
3637 /* Warn about a bad demangling. */
3640 stab_bad_demangle (const char *s)
3642 fprintf (stderr, _("bad mangled name `%s'\n"), s);
3645 /* Get a count from a stab string. */
3648 stab_demangle_count (const char **pp)
3653 while (ISDIGIT (**pp))
3656 count += **pp - '0';
3662 /* Require a count in a string. The count may be multiple digits, in
3663 which case it must end in an underscore. */
3666 stab_demangle_get_count (const char **pp, unsigned int *pi)
3668 if (! ISDIGIT (**pp))
3686 while (ISDIGIT (*p));
3697 /* This function demangles a physical name, returning a NULL
3698 terminated array of argument types. */
3701 stab_demangle_argtypes (void *dhandle, struct stab_handle *info,
3702 const char *physname, bfd_boolean *pvarargs,
3703 unsigned int physname_len)
3705 struct stab_demangle_info minfo;
3707 /* Check for the g++ V3 ABI. */
3708 if (physname[0] == '_' && physname[1] == 'Z')
3709 return stab_demangle_v3_argtypes (dhandle, info, physname, pvarargs);
3711 minfo.dhandle = dhandle;
3714 minfo.varargs = FALSE;
3715 minfo.typestring_alloc = 10;
3716 minfo.typestrings = ((struct stab_demangle_typestring *)
3717 xmalloc (minfo.typestring_alloc
3718 * sizeof *minfo.typestrings));
3719 minfo.typestring_count = 0;
3721 /* cplus_demangle checks for special GNU mangled forms, but we can't
3722 see any of them in mangled method argument types. */
3724 if (! stab_demangle_prefix (&minfo, &physname, physname_len))
3727 if (*physname != '\0')
3729 if (! stab_demangle_signature (&minfo, &physname))
3733 free (minfo.typestrings);
3734 minfo.typestrings = NULL;
3736 if (minfo.args == NULL)
3737 fprintf (stderr, _("no argument types in mangled string\n"));
3739 *pvarargs = minfo.varargs;
3743 if (minfo.typestrings != NULL)
3744 free (minfo.typestrings);
3748 /* Demangle the prefix of the mangled name. */
3751 stab_demangle_prefix (struct stab_demangle_info *minfo, const char **pp,
3752 unsigned int physname_len)
3757 /* cplus_demangle checks for global constructors and destructors,
3758 but we can't see them in mangled argument types. */
3761 scan = *pp + physname_len;
3764 /* Look for `__'. */
3767 scan = strchr (scan, '_');
3768 while (scan != NULL && *++scan != '_');
3772 stab_bad_demangle (*pp);
3778 /* We found `__'; move ahead to the last contiguous `__' pair. */
3779 i = strspn (scan, "_");
3785 && (ISDIGIT (scan[2])
3789 /* This is a GNU style constructor name. */
3793 else if (scan == *pp
3794 && ! ISDIGIT (scan[2])
3797 /* Look for the `__' that separates the prefix from the
3799 while (*scan == '_')
3801 scan = strstr (scan, "__");
3802 if (scan == NULL || scan[2] == '\0')
3804 stab_bad_demangle (*pp);
3808 return stab_demangle_function_name (minfo, pp, scan);
3810 else if (scan[2] != '\0')
3812 /* The name doesn't start with `__', but it does contain `__'. */
3813 return stab_demangle_function_name (minfo, pp, scan);
3817 stab_bad_demangle (*pp);
3823 /* Demangle a function name prefix. The scan argument points to the
3824 double underscore which separates the function name from the
3828 stab_demangle_function_name (struct stab_demangle_info *minfo,
3829 const char **pp, const char *scan)
3833 /* The string from *pp to scan is the name of the function. We
3834 don't care about the name, since we just looking for argument
3835 types. However, for conversion operators, the name may include a
3836 type which we must remember in order to handle backreferences. */
3842 && strncmp (name, "type", 4) == 0
3843 && (name[4] == '$' || name[4] == '.'))
3847 /* This is a type conversion operator. */
3849 if (! stab_demangle_type (minfo, &tem, (debug_type *) NULL))
3852 else if (name[0] == '_'
3859 /* This is a type conversion operator. */
3861 if (! stab_demangle_type (minfo, &tem, (debug_type *) NULL))
3868 /* Demangle the signature. This is where the argument types are
3872 stab_demangle_signature (struct stab_demangle_info *minfo, const char **pp)
3875 bfd_boolean expect_func, func_done;
3880 expect_func = FALSE;
3884 while (**pp != '\0')
3890 if (! stab_demangle_qualified (minfo, pp, (debug_type *) NULL)
3891 || ! stab_demangle_remember_type (minfo, hold, *pp - hold))
3898 /* Static member function. FIXME: Can this happen? */
3905 /* Const member function. */
3911 case '0': case '1': case '2': case '3': case '4':
3912 case '5': case '6': case '7': case '8': case '9':
3915 if (! stab_demangle_class (minfo, pp, (const char **) NULL)
3916 || ! stab_demangle_remember_type (minfo, hold, *pp - hold))
3923 /* Function. I don't know if this actually happens with g++
3928 if (! stab_demangle_args (minfo, pp, &minfo->args, &minfo->varargs))
3936 if (! stab_demangle_template (minfo, pp, (char **) NULL)
3937 || ! stab_demangle_remember_type (minfo, hold, *pp - hold))
3944 /* At the outermost level, we cannot have a return type
3945 specified, so if we run into another '_' at this point we
3946 are dealing with a mangled name that is either bogus, or
3947 has been mangled by some algorithm we don't know how to
3948 deal with. So just reject the entire demangling. */
3949 stab_bad_demangle (orig);
3953 /* Assume we have stumbled onto the first outermost function
3954 argument token, and start processing args. */
3956 if (! stab_demangle_args (minfo, pp, &minfo->args, &minfo->varargs))
3964 if (! stab_demangle_args (minfo, pp, &minfo->args, &minfo->varargs))
3971 /* With GNU style demangling, bar__3foo is 'foo::bar(void)', and
3972 bar__3fooi is 'foo::bar(int)'. We get here when we find the
3973 first case, and need to ensure that the '(void)' gets added
3974 to the current declp. */
3975 if (! stab_demangle_args (minfo, pp, &minfo->args, &minfo->varargs))
3982 /* Demangle a qualified name, such as "Q25Outer5Inner" which is the
3983 mangled form of "Outer::Inner". */
3986 stab_demangle_qualified (struct stab_demangle_info *minfo, const char **pp,
3991 unsigned int qualifiers;
3999 /* GNU mangled name with more than 9 classes. The count is
4000 preceded by an underscore (to distinguish it from the <= 9
4001 case) and followed by an underscore. */
4003 if (! ISDIGIT (*p) || *p == '0')
4005 stab_bad_demangle (orig);
4008 qualifiers = atoi (p);
4009 while (ISDIGIT (*p))
4013 stab_bad_demangle (orig);
4019 case '1': case '2': case '3': case '4': case '5':
4020 case '6': case '7': case '8': case '9':
4021 qualifiers = (*pp)[1] - '0';
4022 /* Skip an optional underscore after the count. */
4023 if ((*pp)[2] == '_')
4030 stab_bad_demangle (orig);
4034 context = DEBUG_TYPE_NULL;
4036 /* Pick off the names. */
4037 while (qualifiers-- > 0)
4045 if (! stab_demangle_template (minfo, pp,
4046 ptype != NULL ? &name : NULL))
4051 context = stab_find_tagged_type (minfo->dhandle, minfo->info,
4052 name, strlen (name),
4055 if (context == DEBUG_TYPE_NULL)
4063 len = stab_demangle_count (pp);
4064 if (strlen (*pp) < len)
4066 stab_bad_demangle (orig);
4072 const debug_field *fields;
4075 if (context != DEBUG_TYPE_NULL)
4076 fields = debug_get_fields (minfo->dhandle, context);
4078 context = DEBUG_TYPE_NULL;
4084 /* Try to find the type by looking through the
4085 fields of context until we find a field with the
4086 same type. This ought to work for a class
4087 defined within a class, but it won't work for,
4088 e.g., an enum defined within a class. stabs does
4089 not give us enough information to figure out the
4092 name = savestring (*pp, len);
4094 for (; *fields != DEBUG_FIELD_NULL; fields++)
4099 ft = debug_get_field_type (minfo->dhandle, *fields);
4102 dn = debug_get_type_name (minfo->dhandle, ft);
4103 if (dn != NULL && strcmp (dn, name) == 0)
4113 if (context == DEBUG_TYPE_NULL)
4115 /* We have to fall back on finding the type by name.
4116 If there are more types to come, then this must
4117 be a class. Otherwise, it could be anything. */
4119 if (qualifiers == 0)
4123 name = savestring (*pp, len);
4124 context = debug_find_named_type (minfo->dhandle,
4129 if (context == DEBUG_TYPE_NULL)
4131 context = stab_find_tagged_type (minfo->dhandle,
4135 ? DEBUG_KIND_ILLEGAL
4136 : DEBUG_KIND_CLASS));
4137 if (context == DEBUG_TYPE_NULL)
4153 /* Demangle a template. If PNAME is not NULL, this sets *PNAME to a
4154 string representation of the template. */
4157 stab_demangle_template (struct stab_demangle_info *minfo, const char **pp,
4167 /* Skip the template name. */
4168 r = stab_demangle_count (pp);
4169 if (r == 0 || strlen (*pp) < r)
4171 stab_bad_demangle (orig);
4176 /* Get the size of the parameter list. */
4177 if (stab_demangle_get_count (pp, &r) == 0)
4179 stab_bad_demangle (orig);
4183 for (i = 0; i < r; i++)
4187 /* This is a type parameter. */
4189 if (! stab_demangle_type (minfo, pp, (debug_type *) NULL))
4195 bfd_boolean pointerp, realp, integralp, charp, boolp;
4206 /* This is a value parameter. */
4208 if (! stab_demangle_type (minfo, pp, (debug_type *) NULL))
4211 while (*old_p != '\0' && ! done)
4221 case 'C': /* Const. */
4222 case 'S': /* Signed. */
4223 case 'U': /* Unsigned. */
4224 case 'V': /* Volatile. */
4225 case 'F': /* Function. */
4226 case 'M': /* Member function. */
4230 case 'Q': /* Qualified name. */
4234 case 'T': /* Remembered type. */
4236 case 'v': /* Void. */
4238 case 'x': /* Long long. */
4239 case 'l': /* Long. */
4240 case 'i': /* Int. */
4241 case 's': /* Short. */
4242 case 'w': /* Wchar_t. */
4246 case 'b': /* Bool. */
4250 case 'c': /* Char. */
4254 case 'r': /* Long double. */
4255 case 'd': /* Double. */
4256 case 'f': /* Float. */
4261 /* Assume it's a user defined integral type. */
4272 while (ISDIGIT (**pp))
4281 val = stab_demangle_count (pp);
4284 stab_bad_demangle (orig);
4292 val = stab_demangle_count (pp);
4293 if (val != 0 && val != 1)
4295 stab_bad_demangle (orig);
4303 while (ISDIGIT (**pp))
4308 while (ISDIGIT (**pp))
4314 while (ISDIGIT (**pp))
4322 if (! stab_demangle_get_count (pp, &len))
4324 stab_bad_demangle (orig);
4332 /* We can translate this to a string fairly easily by invoking the
4333 regular demangling routine. */
4336 char *s1, *s2, *s3, *s4 = NULL;
4339 s1 = savestring (orig, *pp - orig);
4341 s2 = concat ("NoSuchStrinG__", s1, (const char *) NULL);
4345 s3 = cplus_demangle (s2, DMGL_ANSI);
4350 s4 = strstr (s3, "::NoSuchStrinG");
4351 if (s3 == NULL || s4 == NULL)
4353 stab_bad_demangle (orig);
4359 /* Eliminating all spaces, except those between > characters,
4360 makes it more likely that the demangled name will match the
4361 name which g++ used as the structure name. */
4362 for (from = to = s3; from != s4; ++from)
4364 || (from[1] == '>' && from > s3 && from[-1] == '>'))
4367 *pname = savestring (s3, to - s3);
4375 /* Demangle a class name. */
4378 stab_demangle_class (struct stab_demangle_info *minfo ATTRIBUTE_UNUSED,
4379 const char **pp, const char **pstart)
4386 n = stab_demangle_count (pp);
4387 if (strlen (*pp) < n)
4389 stab_bad_demangle (orig);
4401 /* Demangle function arguments. If the pargs argument is not NULL, it
4402 is set to a NULL terminated array holding the arguments. */
4405 stab_demangle_args (struct stab_demangle_info *minfo, const char **pp,
4406 debug_type **pargs, bfd_boolean *pvarargs)
4409 unsigned int alloc, count;
4416 *pargs = (debug_type *) xmalloc (alloc * sizeof **pargs);
4421 while (**pp != '_' && **pp != '\0' && **pp != 'e')
4423 if (**pp == 'N' || **pp == 'T')
4431 if (temptype == 'T')
4435 if (! stab_demangle_get_count (pp, &r))
4437 stab_bad_demangle (orig);
4442 if (! stab_demangle_get_count (pp, &t))
4444 stab_bad_demangle (orig);
4448 if (t >= minfo->typestring_count)
4450 stab_bad_demangle (orig);
4457 tem = minfo->typestrings[t].typestring;
4458 if (! stab_demangle_arg (minfo, &tem, pargs, &count, &alloc))
4464 if (! stab_demangle_arg (minfo, pp, pargs, &count, &alloc))
4470 (*pargs)[count] = DEBUG_TYPE_NULL;
4482 /* Demangle a single argument. */
4485 stab_demangle_arg (struct stab_demangle_info *minfo, const char **pp,
4486 debug_type **pargs, unsigned int *pcount,
4487 unsigned int *palloc)
4493 if (! stab_demangle_type (minfo, pp,
4494 pargs == NULL ? (debug_type *) NULL : &type)
4495 || ! stab_demangle_remember_type (minfo, start, *pp - start))
4500 if (type == DEBUG_TYPE_NULL)
4503 if (*pcount + 1 >= *palloc)
4506 *pargs = ((debug_type *)
4507 xrealloc (*pargs, *palloc * sizeof **pargs));
4509 (*pargs)[*pcount] = type;
4516 /* Demangle a type. If the ptype argument is not NULL, *ptype is set
4517 to the newly allocated type. */
4520 stab_demangle_type (struct stab_demangle_info *minfo, const char **pp,
4531 /* A pointer type. */
4533 if (! stab_demangle_type (minfo, pp, ptype))
4536 *ptype = debug_make_pointer_type (minfo->dhandle, *ptype);
4540 /* A reference type. */
4542 if (! stab_demangle_type (minfo, pp, ptype))
4545 *ptype = debug_make_reference_type (minfo->dhandle, *ptype);
4555 while (**pp != '\0' && **pp != '_')
4557 if (! ISDIGIT (**pp))
4559 stab_bad_demangle (orig);
4568 stab_bad_demangle (orig);
4573 if (! stab_demangle_type (minfo, pp, ptype))
4577 debug_type int_type;
4579 int_type = debug_find_named_type (minfo->dhandle, "int");
4580 if (int_type == NULL)
4581 int_type = debug_make_int_type (minfo->dhandle, 4, FALSE);
4582 *ptype = debug_make_array_type (minfo->dhandle, *ptype, int_type,
4589 /* A back reference to a remembered type. */
4595 if (! stab_demangle_get_count (pp, &i))
4597 stab_bad_demangle (orig);
4600 if (i >= minfo->typestring_count)
4602 stab_bad_demangle (orig);
4605 p = minfo->typestrings[i].typestring;
4606 if (! stab_demangle_type (minfo, &p, ptype))
4615 bfd_boolean varargs;
4618 if (! stab_demangle_args (minfo, pp,
4620 ? (debug_type **) NULL
4623 ? (bfd_boolean *) NULL
4628 /* cplus_demangle will accept a function without a return
4629 type, but I don't know when that will happen, or what
4630 to do if it does. */
4631 stab_bad_demangle (orig);
4635 if (! stab_demangle_type (minfo, pp, ptype))
4638 *ptype = debug_make_function_type (minfo->dhandle, *ptype, args,
4647 bfd_boolean memberp, constp, volatilep;
4648 debug_type class_type = DEBUG_TYPE_NULL;
4650 bfd_boolean varargs;
4654 memberp = **pp == 'M';
4663 n = stab_demangle_count (pp);
4664 if (strlen (*pp) < n)
4666 stab_bad_demangle (orig);
4674 class_type = stab_find_tagged_type (minfo->dhandle,
4678 if (class_type == DEBUG_TYPE_NULL)
4682 else if (**pp == 'Q')
4684 if (! stab_demangle_qualified (minfo, pp,
4686 ? (debug_type *) NULL
4692 stab_bad_demangle (orig);
4703 else if (**pp == 'V')
4710 stab_bad_demangle (orig);
4714 if (! stab_demangle_args (minfo, pp,
4716 ? (debug_type **) NULL
4719 ? (bfd_boolean *) NULL
4726 stab_bad_demangle (orig);
4731 if (! stab_demangle_type (minfo, pp, ptype))
4737 *ptype = debug_make_offset_type (minfo->dhandle, class_type,
4741 /* FIXME: We have no way to record constp or
4743 *ptype = debug_make_method_type (minfo->dhandle, *ptype,
4744 class_type, args, varargs);
4752 if (! stab_demangle_type (minfo, pp, ptype))
4758 if (! stab_demangle_type (minfo, pp, ptype))
4761 *ptype = debug_make_const_type (minfo->dhandle, *ptype);
4769 if (! stab_demangle_qualified (minfo, pp, ptype))
4775 if (! stab_demangle_fund_type (minfo, pp, ptype))
4783 /* Demangle a fundamental type. If the ptype argument is not NULL,
4784 *ptype is set to the newly allocated type. */
4787 stab_demangle_fund_type (struct stab_demangle_info *minfo, const char **pp,
4791 bfd_boolean constp, volatilep, unsignedp, signedp;
4836 /* cplus_demangle permits this, but I don't know what it means. */
4837 stab_bad_demangle (orig);
4840 case 'v': /* void */
4843 *ptype = debug_find_named_type (minfo->dhandle, "void");
4844 if (*ptype == DEBUG_TYPE_NULL)
4845 *ptype = debug_make_void_type (minfo->dhandle);
4850 case 'x': /* long long */
4853 *ptype = debug_find_named_type (minfo->dhandle,
4855 ? "long long unsigned int"
4856 : "long long int"));
4857 if (*ptype == DEBUG_TYPE_NULL)
4858 *ptype = debug_make_int_type (minfo->dhandle, 8, unsignedp);
4863 case 'l': /* long */
4866 *ptype = debug_find_named_type (minfo->dhandle,
4868 ? "long unsigned int"
4870 if (*ptype == DEBUG_TYPE_NULL)
4871 *ptype = debug_make_int_type (minfo->dhandle, 4, unsignedp);
4879 *ptype = debug_find_named_type (minfo->dhandle,
4883 if (*ptype == DEBUG_TYPE_NULL)
4884 *ptype = debug_make_int_type (minfo->dhandle, 4, unsignedp);
4889 case 's': /* short */
4892 *ptype = debug_find_named_type (minfo->dhandle,
4894 ? "short unsigned int"
4896 if (*ptype == DEBUG_TYPE_NULL)
4897 *ptype = debug_make_int_type (minfo->dhandle, 2, unsignedp);
4902 case 'b': /* bool */
4905 *ptype = debug_find_named_type (minfo->dhandle, "bool");
4906 if (*ptype == DEBUG_TYPE_NULL)
4907 *ptype = debug_make_bool_type (minfo->dhandle, 4);
4912 case 'c': /* char */
4915 *ptype = debug_find_named_type (minfo->dhandle,
4921 if (*ptype == DEBUG_TYPE_NULL)
4922 *ptype = debug_make_int_type (minfo->dhandle, 1, unsignedp);
4927 case 'w': /* wchar_t */
4930 *ptype = debug_find_named_type (minfo->dhandle, "__wchar_t");
4931 if (*ptype == DEBUG_TYPE_NULL)
4932 *ptype = debug_make_int_type (minfo->dhandle, 2, TRUE);
4937 case 'r': /* long double */
4940 *ptype = debug_find_named_type (minfo->dhandle, "long double");
4941 if (*ptype == DEBUG_TYPE_NULL)
4942 *ptype = debug_make_float_type (minfo->dhandle, 8);
4947 case 'd': /* double */
4950 *ptype = debug_find_named_type (minfo->dhandle, "double");
4951 if (*ptype == DEBUG_TYPE_NULL)
4952 *ptype = debug_make_float_type (minfo->dhandle, 8);
4957 case 'f': /* float */
4960 *ptype = debug_find_named_type (minfo->dhandle, "float");
4961 if (*ptype == DEBUG_TYPE_NULL)
4962 *ptype = debug_make_float_type (minfo->dhandle, 4);
4969 if (! ISDIGIT (**pp))
4971 stab_bad_demangle (orig);
4975 case '0': case '1': case '2': case '3': case '4':
4976 case '5': case '6': case '7': case '8': case '9':
4980 if (! stab_demangle_class (minfo, pp, &hold))
4986 name = savestring (hold, *pp - hold);
4987 *ptype = debug_find_named_type (minfo->dhandle, name);
4989 if (*ptype == DEBUG_TYPE_NULL)
4991 /* FIXME: It is probably incorrect to assume that
4992 undefined types are tagged types. */
4993 *ptype = stab_find_tagged_type (minfo->dhandle, minfo->info,
4995 DEBUG_KIND_ILLEGAL);
4996 if (*ptype == DEBUG_TYPE_NULL)
5007 if (! stab_demangle_template (minfo, pp,
5008 ptype != NULL ? &name : NULL))
5012 *ptype = stab_find_tagged_type (minfo->dhandle, minfo->info,
5013 name, strlen (name),
5016 if (*ptype == DEBUG_TYPE_NULL)
5023 stab_bad_demangle (orig);
5030 *ptype = debug_make_const_type (minfo->dhandle, *ptype);
5032 *ptype = debug_make_volatile_type (minfo->dhandle, *ptype);
5038 /* Remember a type string in a demangled string. */
5041 stab_demangle_remember_type (struct stab_demangle_info *minfo,
5042 const char *p, int len)
5044 if (minfo->typestring_count >= minfo->typestring_alloc)
5046 minfo->typestring_alloc += 10;
5047 minfo->typestrings = ((struct stab_demangle_typestring *)
5048 xrealloc (minfo->typestrings,
5049 (minfo->typestring_alloc
5050 * sizeof *minfo->typestrings)));
5053 minfo->typestrings[minfo->typestring_count].typestring = p;
5054 minfo->typestrings[minfo->typestring_count].len = (unsigned int) len;
5055 ++minfo->typestring_count;
5060 /* Demangle names encoded using the g++ V3 ABI. The newer versions of
5061 g++ which use this ABI do not encode ordinary method argument types
5062 in a mangled name; they simply output the argument types. However,
5063 for a static method, g++ simply outputs the return type and the
5064 physical name. So in that case we need to demangle the name here.
5065 Here PHYSNAME is the physical name of the function, and we set the
5066 variable pointed at by PVARARGS to indicate whether this function
5067 is varargs. This returns NULL, or a NULL terminated array of
5071 stab_demangle_v3_argtypes (void *dhandle, struct stab_handle *info,
5072 const char *physname, bfd_boolean *pvarargs)
5074 struct demangle_component *dc;
5076 unsigned int alloc, count;
5079 dc = cplus_demangle_v3_components (physname, DMGL_PARAMS | DMGL_ANSI, &mem);
5082 stab_bad_demangle (physname);
5086 /* We expect to see TYPED_NAME, and the right subtree describes the
5088 if (dc->type != DEMANGLE_COMPONENT_TYPED_NAME
5089 || dc->u.s_binary.right->type != DEMANGLE_COMPONENT_FUNCTION_TYPE)
5091 fprintf (stderr, _("Demangled name is not a function\n"));
5097 pargs = (debug_type *) xmalloc (alloc * sizeof *pargs);
5102 for (dc = dc->u.s_binary.right->u.s_binary.right;
5104 dc = dc->u.s_binary.right)
5107 bfd_boolean varargs;
5109 if (dc->type != DEMANGLE_COMPONENT_ARGLIST)
5111 fprintf (stderr, _("Unexpected type in demangle tree\n"));
5116 arg = stab_demangle_v3_arg (dhandle, info, dc->u.s_binary.left,
5129 if (count + 1 >= alloc)
5132 pargs = (debug_type *) xrealloc (pargs, alloc * sizeof *pargs);
5139 pargs[count] = DEBUG_TYPE_NULL;
5146 /* Convert a struct demangle_component tree describing an argument
5147 type into a debug_type. */
5150 stab_demangle_v3_arg (void *dhandle, struct stab_handle *info,
5151 struct demangle_component *dc, debug_type context,
5152 bfd_boolean *pvarargs)
5156 if (pvarargs != NULL)
5161 /* FIXME: These are demangle component types which we probably
5162 need to handle one way or another. */
5163 case DEMANGLE_COMPONENT_LOCAL_NAME:
5164 case DEMANGLE_COMPONENT_TYPED_NAME:
5165 case DEMANGLE_COMPONENT_TEMPLATE_PARAM:
5166 case DEMANGLE_COMPONENT_CTOR:
5167 case DEMANGLE_COMPONENT_DTOR:
5168 case DEMANGLE_COMPONENT_JAVA_CLASS:
5169 case DEMANGLE_COMPONENT_RESTRICT_THIS:
5170 case DEMANGLE_COMPONENT_VOLATILE_THIS:
5171 case DEMANGLE_COMPONENT_CONST_THIS:
5172 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL:
5173 case DEMANGLE_COMPONENT_COMPLEX:
5174 case DEMANGLE_COMPONENT_IMAGINARY:
5175 case DEMANGLE_COMPONENT_VENDOR_TYPE:
5176 case DEMANGLE_COMPONENT_FUNCTION_TYPE:
5177 case DEMANGLE_COMPONENT_ARRAY_TYPE:
5178 case DEMANGLE_COMPONENT_PTRMEM_TYPE:
5179 case DEMANGLE_COMPONENT_ARGLIST:
5181 fprintf (stderr, _("Unrecognized demangle component\n"));
5184 case DEMANGLE_COMPONENT_NAME:
5185 if (context != NULL)
5187 const debug_field *fields;
5189 fields = debug_get_fields (dhandle, context);
5192 /* Try to find this type by looking through the context
5194 for (; *fields != DEBUG_FIELD_NULL; fields++)
5199 ft = debug_get_field_type (dhandle, *fields);
5202 dn = debug_get_type_name (dhandle, ft);
5204 && (int) strlen (dn) == dc->u.s_name.len
5205 && strncmp (dn, dc->u.s_name.s, dc->u.s_name.len) == 0)
5210 return stab_find_tagged_type (dhandle, info, dc->u.s_name.s,
5211 dc->u.s_name.len, DEBUG_KIND_ILLEGAL);
5213 case DEMANGLE_COMPONENT_QUAL_NAME:
5214 context = stab_demangle_v3_arg (dhandle, info, dc->u.s_binary.left,
5216 if (context == NULL)
5218 return stab_demangle_v3_arg (dhandle, info, dc->u.s_binary.right,
5221 case DEMANGLE_COMPONENT_TEMPLATE:
5226 /* We print this component to get a class name which we can
5227 use. FIXME: This probably won't work if the template uses
5228 template parameters which refer to an outer template. */
5229 p = cplus_demangle_print (DMGL_PARAMS | DMGL_ANSI, dc, 20, &alc);
5232 fprintf (stderr, _("Failed to print demangled template\n"));
5235 dt = stab_find_tagged_type (dhandle, info, p, strlen (p),
5241 case DEMANGLE_COMPONENT_SUB_STD:
5242 return stab_find_tagged_type (dhandle, info, dc->u.s_string.string,
5243 dc->u.s_string.len, DEBUG_KIND_ILLEGAL);
5245 case DEMANGLE_COMPONENT_RESTRICT:
5246 case DEMANGLE_COMPONENT_VOLATILE:
5247 case DEMANGLE_COMPONENT_CONST:
5248 case DEMANGLE_COMPONENT_POINTER:
5249 case DEMANGLE_COMPONENT_REFERENCE:
5250 dt = stab_demangle_v3_arg (dhandle, info, dc->u.s_binary.left, NULL,
5259 case DEMANGLE_COMPONENT_RESTRICT:
5260 /* FIXME: We have no way to represent restrict. */
5262 case DEMANGLE_COMPONENT_VOLATILE:
5263 return debug_make_volatile_type (dhandle, dt);
5264 case DEMANGLE_COMPONENT_CONST:
5265 return debug_make_const_type (dhandle, dt);
5266 case DEMANGLE_COMPONENT_POINTER:
5267 return debug_make_pointer_type (dhandle, dt);
5268 case DEMANGLE_COMPONENT_REFERENCE:
5269 return debug_make_reference_type (dhandle, dt);
5272 case DEMANGLE_COMPONENT_BUILTIN_TYPE:
5278 /* We print this component in order to find out the type name.
5279 FIXME: Should we instead expose the
5280 demangle_builtin_type_info structure? */
5281 p = cplus_demangle_print (DMGL_PARAMS | DMGL_ANSI, dc, 20, &alc);
5284 fprintf (stderr, _("Couldn't get demangled builtin type\n"));
5288 /* The mangling is based on the type, but does not itself
5289 indicate what the sizes are. So we have to guess. */
5290 if (strcmp (p, "signed char") == 0)
5291 ret = debug_make_int_type (dhandle, 1, FALSE);
5292 else if (strcmp (p, "bool") == 0)
5293 ret = debug_make_bool_type (dhandle, 1);
5294 else if (strcmp (p, "char") == 0)
5295 ret = debug_make_int_type (dhandle, 1, FALSE);
5296 else if (strcmp (p, "double") == 0)
5297 ret = debug_make_float_type (dhandle, 8);
5298 else if (strcmp (p, "long double") == 0)
5299 ret = debug_make_float_type (dhandle, 8);
5300 else if (strcmp (p, "float") == 0)
5301 ret = debug_make_float_type (dhandle, 4);
5302 else if (strcmp (p, "__float128") == 0)
5303 ret = debug_make_float_type (dhandle, 16);
5304 else if (strcmp (p, "unsigned char") == 0)
5305 ret = debug_make_int_type (dhandle, 1, TRUE);
5306 else if (strcmp (p, "int") == 0)
5307 ret = debug_make_int_type (dhandle, 4, FALSE);
5308 else if (strcmp (p, "unsigned int") == 0)
5309 ret = debug_make_int_type (dhandle, 4, TRUE);
5310 else if (strcmp (p, "long") == 0)
5311 ret = debug_make_int_type (dhandle, 4, FALSE);
5312 else if (strcmp (p, "unsigned long") == 0)
5313 ret = debug_make_int_type (dhandle, 4, TRUE);
5314 else if (strcmp (p, "__int128") == 0)
5315 ret = debug_make_int_type (dhandle, 16, FALSE);
5316 else if (strcmp (p, "unsigned __int128") == 0)
5317 ret = debug_make_int_type (dhandle, 16, TRUE);
5318 else if (strcmp (p, "short") == 0)
5319 ret = debug_make_int_type (dhandle, 2, FALSE);
5320 else if (strcmp (p, "unsigned short") == 0)
5321 ret = debug_make_int_type (dhandle, 2, TRUE);
5322 else if (strcmp (p, "void") == 0)
5323 ret = debug_make_void_type (dhandle);
5324 else if (strcmp (p, "wchar_t") == 0)
5325 ret = debug_make_int_type (dhandle, 4, TRUE);
5326 else if (strcmp (p, "long long") == 0)
5327 ret = debug_make_int_type (dhandle, 8, FALSE);
5328 else if (strcmp (p, "unsigned long long") == 0)
5329 ret = debug_make_int_type (dhandle, 8, TRUE);
5330 else if (strcmp (p, "...") == 0)
5332 if (pvarargs == NULL)
5333 fprintf (stderr, _("Unexpected demangled varargs\n"));
5340 fprintf (stderr, _("Unrecognized demangled builtin type\n"));