1 /* stabs.c -- Parse stabs debugging information
2 Copyright (C) 1995-2015 Free Software Foundation, Inc.
3 Written by Ian Lance Taylor <ian@cygnus.com>.
5 This file is part of GNU Binutils.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
22 /* This file contains code which parses stabs debugging information.
23 The organization of this code is based on the gdb stabs reading
24 code. The job it does is somewhat different, because it is not
25 trying to identify the correct address for anything. */
29 #include "libiberty.h"
30 #include "safe-ctype.h"
34 #include "filenames.h"
35 #include "aout/aout64.h"
36 #include "aout/stab_gnu.h"
38 /* The number of predefined XCOFF types. */
40 #define XCOFF_TYPE_COUNT 34
42 /* This structure is used as a handle so that the stab parsing doesn't
43 need to use any static variables. */
49 /* TRUE if this is stabs in sections. */
51 /* The symbol table. */
53 /* The number of symbols. */
55 /* The accumulated file name string. */
57 /* The value of the last N_SO symbol. */
59 /* The value of the start of the file, so that we can handle file
60 relative N_LBRAC and N_RBRAC symbols. */
61 bfd_vma file_start_offset;
62 /* The offset of the start of the function, so that we can handle
63 function relative N_LBRAC and N_RBRAC symbols. */
64 bfd_vma function_start_offset;
65 /* The version number of gcc which compiled the current compilation
66 unit, 0 if not compiled by gcc. */
68 /* Whether an N_OPT symbol was seen that was not generated by gcc,
69 so that we can detect the SunPRO compiler. */
70 bfd_boolean n_opt_found;
71 /* The main file name. */
73 /* A stack of unfinished N_BINCL files. */
74 struct bincl_file *bincl_stack;
75 /* A list of finished N_BINCL files. */
76 struct bincl_file *bincl_list;
77 /* Whether we are inside a function or not. */
78 bfd_boolean within_function;
79 /* The address of the end of the function, used if we have seen an
80 N_FUN symbol while in a function. This is -1 if we have not seen
81 an N_FUN (the normal case). */
83 /* The depth of block nesting. */
85 /* List of pending variable definitions. */
86 struct stab_pending_var *pending;
87 /* Number of files for which we have types. */
89 /* Lists of types per file. */
90 struct stab_types **file_types;
91 /* Predefined XCOFF types. */
92 debug_type xcoff_types[XCOFF_TYPE_COUNT];
94 struct stab_tag *tags;
95 /* Set by parse_stab_type if it sees a structure defined as a cross
96 reference to itself. Reset by parse_stab_type otherwise. */
97 bfd_boolean self_crossref;
100 /* A list of these structures is used to hold pending variable
101 definitions seen before the N_LBRAC of a block. */
103 struct stab_pending_var
105 /* Next pending variable definition. */
106 struct stab_pending_var *next;
112 enum debug_var_kind kind;
117 /* A list of these structures is used to hold the types for a single
122 /* Next set of slots for this file. */
123 struct stab_types *next;
124 /* Types indexed by type number. */
125 #define STAB_TYPES_SLOTS (16)
126 debug_type types[STAB_TYPES_SLOTS];
129 /* We keep a list of undefined tags that we encounter, so that we can
130 fill them in if the tag is later defined. */
134 /* Next undefined tag. */
135 struct stab_tag *next;
139 enum debug_type_kind kind;
140 /* Slot to hold real type when we discover it. If we don't, we fill
141 in an undefined tag type. */
143 /* Indirect type we have created to point at slot. */
147 static char *savestring (const char *, int);
148 static bfd_vma parse_number (const char **, bfd_boolean *);
149 static void bad_stab (const char *);
150 static void warn_stab (const char *, const char *);
151 static bfd_boolean parse_stab_string
152 (void *, struct stab_handle *, int, int, bfd_vma, const char *);
153 static debug_type parse_stab_type
154 (void *, struct stab_handle *, const char *, const char **, debug_type **);
155 static bfd_boolean parse_stab_type_number (const char **, int *);
156 static debug_type parse_stab_range_type
157 (void *, struct stab_handle *, const char *, const char **, const int *);
158 static debug_type parse_stab_sun_builtin_type (void *, const char **);
159 static debug_type parse_stab_sun_floating_type (void *, const char **);
160 static debug_type parse_stab_enum_type (void *, const char **);
161 static debug_type parse_stab_struct_type
162 (void *, struct stab_handle *, const char *, const char **,
163 bfd_boolean, const int *);
164 static bfd_boolean parse_stab_baseclasses
165 (void *, struct stab_handle *, const char **, debug_baseclass **);
166 static bfd_boolean parse_stab_struct_fields
167 (void *, struct stab_handle *, const char **, debug_field **, bfd_boolean *);
168 static bfd_boolean parse_stab_cpp_abbrev
169 (void *, struct stab_handle *, const char **, debug_field *);
170 static bfd_boolean parse_stab_one_struct_field
171 (void *, struct stab_handle *, const char **, const char *,
172 debug_field *, bfd_boolean *);
173 static bfd_boolean parse_stab_members
174 (void *, struct stab_handle *, const char *, const char **, const int *,
176 static debug_type parse_stab_argtypes
177 (void *, struct stab_handle *, debug_type, const char *, const char *,
178 debug_type, const char *, bfd_boolean, bfd_boolean, const char **);
179 static bfd_boolean parse_stab_tilde_field
180 (void *, struct stab_handle *, const char **, const int *, debug_type *,
182 static debug_type parse_stab_array_type
183 (void *, struct stab_handle *, const char **, bfd_boolean);
184 static void push_bincl (struct stab_handle *, const char *, bfd_vma);
185 static const char *pop_bincl (struct stab_handle *);
186 static bfd_boolean find_excl (struct stab_handle *, const char *, bfd_vma);
187 static bfd_boolean stab_record_variable
188 (void *, struct stab_handle *, const char *, debug_type,
189 enum debug_var_kind, bfd_vma);
190 static bfd_boolean stab_emit_pending_vars (void *, struct stab_handle *);
191 static debug_type *stab_find_slot (struct stab_handle *, const int *);
192 static debug_type stab_find_type (void *, struct stab_handle *, const int *);
193 static bfd_boolean stab_record_type
194 (void *, struct stab_handle *, const int *, debug_type);
195 static debug_type stab_xcoff_builtin_type
196 (void *, struct stab_handle *, int);
197 static debug_type stab_find_tagged_type
198 (void *, struct stab_handle *, const char *, int, enum debug_type_kind);
199 static debug_type *stab_demangle_argtypes
200 (void *, struct stab_handle *, const char *, bfd_boolean *, unsigned int);
201 static debug_type *stab_demangle_v3_argtypes
202 (void *, struct stab_handle *, const char *, bfd_boolean *);
203 static debug_type *stab_demangle_v3_arglist
204 (void *, struct stab_handle *, struct demangle_component *, bfd_boolean *);
205 static debug_type stab_demangle_v3_arg
206 (void *, struct stab_handle *, struct demangle_component *, debug_type,
209 /* Save a string in memory. */
212 savestring (const char *start, int len)
216 ret = (char *) xmalloc (len + 1);
217 memcpy (ret, start, len);
222 /* Read a number from a string. */
225 parse_number (const char **pp, bfd_boolean *poverflow)
230 if (poverflow != NULL)
236 ul = strtoul (*pp, (char **) pp, 0);
237 if (ul + 1 != 0 || errno == 0)
239 /* If bfd_vma is larger than unsigned long, and the number is
240 meant to be negative, we have to make sure that we sign
243 return (bfd_vma) (bfd_signed_vma) (long) ul;
247 /* Note that even though strtoul overflowed, it should have set *pp
248 to the end of the number, which is where we want it. */
249 if (sizeof (bfd_vma) > sizeof (unsigned long))
254 bfd_vma over, lastdig;
255 bfd_boolean overflow;
258 /* Our own version of strtoul, for a bfd_vma. */
273 if (p[1] == 'x' || p[1] == 'X')
285 over = ((bfd_vma) (bfd_signed_vma) -1) / (bfd_vma) base;
286 lastdig = ((bfd_vma) (bfd_signed_vma) -1) % (bfd_vma) base;
297 else if (ISUPPER (d))
299 else if (ISLOWER (d))
307 if (v > over || (v == over && (bfd_vma) d > lastdig))
322 /* If we get here, the number is too large to represent in a
324 if (poverflow != NULL)
327 warn_stab (orig, _("numeric overflow"));
332 /* Give an error for a bad stab string. */
335 bad_stab (const char *p)
337 fprintf (stderr, _("Bad stab: %s\n"), p);
340 /* Warn about something in a stab string. */
343 warn_stab (const char *p, const char *err)
345 fprintf (stderr, _("Warning: %s: %s\n"), err, p);
348 /* Create a handle to parse stabs symbols with. */
351 start_stab (void *dhandle ATTRIBUTE_UNUSED, bfd *abfd, bfd_boolean sections,
352 asymbol **syms, long symcount)
354 struct stab_handle *ret;
356 ret = (struct stab_handle *) xmalloc (sizeof *ret);
357 memset (ret, 0, sizeof *ret);
359 ret->sections = sections;
361 ret->symcount = symcount;
363 ret->file_types = (struct stab_types **) xmalloc (sizeof *ret->file_types);
364 ret->file_types[0] = NULL;
365 ret->function_end = (bfd_vma) -1;
369 /* When we have processed all the stabs information, we need to go
370 through and fill in all the undefined tags. */
373 finish_stab (void *dhandle, void *handle)
375 struct stab_handle *info = (struct stab_handle *) handle;
378 if (info->within_function)
380 if (! stab_emit_pending_vars (dhandle, info)
381 || ! debug_end_function (dhandle, info->function_end))
383 info->within_function = FALSE;
384 info->function_end = (bfd_vma) -1;
387 for (st = info->tags; st != NULL; st = st->next)
389 enum debug_type_kind kind;
392 if (kind == DEBUG_KIND_ILLEGAL)
393 kind = DEBUG_KIND_STRUCT;
394 st->slot = debug_make_undefined_tagged_type (dhandle, st->name, kind);
395 if (st->slot == DEBUG_TYPE_NULL)
402 /* Handle a single stabs symbol. */
405 parse_stab (void *dhandle, void *handle, int type, int desc, bfd_vma value,
408 struct stab_handle *info = (struct stab_handle *) handle;
410 /* gcc will emit two N_SO strings per compilation unit, one for the
411 directory name and one for the file name. We just collect N_SO
412 strings as we see them, and start the new compilation unit when
413 we see a non N_SO symbol. */
414 if (info->so_string != NULL
415 && (type != N_SO || *string == '\0' || value != info->so_value))
417 if (! debug_set_filename (dhandle, info->so_string))
419 info->main_filename = info->so_string;
421 info->gcc_compiled = 0;
422 info->n_opt_found = FALSE;
424 /* Generally, for stabs in the symbol table, the N_LBRAC and
425 N_RBRAC symbols are relative to the N_SO symbol value. */
426 if (! info->sections)
427 info->file_start_offset = info->so_value;
429 /* We need to reset the mapping from type numbers to types. We
430 can't free the old mapping, because of the use of
431 debug_make_indirect_type. */
433 info->file_types = ((struct stab_types **)
434 xmalloc (sizeof *info->file_types));
435 info->file_types[0] = NULL;
437 info->so_string = NULL;
439 /* Now process whatever type we just got. */
449 /* Ignore extra outermost context from SunPRO cc and acc. */
450 if (info->n_opt_found && desc == 1)
453 if (! info->within_function)
455 fprintf (stderr, _("N_LBRAC not within function\n"));
459 /* Start an inner lexical block. */
460 if (! debug_start_block (dhandle,
462 + info->file_start_offset
463 + info->function_start_offset)))
466 /* Emit any pending variable definitions. */
467 if (! stab_emit_pending_vars (dhandle, info))
474 /* Ignore extra outermost context from SunPRO cc and acc. */
475 if (info->n_opt_found && desc == 1)
478 /* We shouldn't have any pending variable definitions here, but,
479 if we do, we probably need to emit them before closing the
481 if (! stab_emit_pending_vars (dhandle, info))
484 /* End an inner lexical block. */
485 if (! debug_end_block (dhandle,
487 + info->file_start_offset
488 + info->function_start_offset)))
492 if (info->block_depth < 0)
494 fprintf (stderr, _("Too many N_RBRACs\n"));
500 /* This always ends a function. */
501 if (info->within_function)
507 && info->function_end != (bfd_vma) -1
508 && info->function_end < endval)
509 endval = info->function_end;
510 if (! stab_emit_pending_vars (dhandle, info)
511 || ! debug_end_function (dhandle, endval))
513 info->within_function = FALSE;
514 info->function_end = (bfd_vma) -1;
517 /* An empty string is emitted by gcc at the end of a compilation
522 /* Just accumulate strings until we see a non N_SO symbol. If
523 the string starts with a directory separator or some other
524 form of absolute path specification, we discard the previously
525 accumulated strings. */
526 if (info->so_string == NULL)
527 info->so_string = xstrdup (string);
534 if (IS_ABSOLUTE_PATH (string))
535 info->so_string = xstrdup (string);
537 info->so_string = concat (info->so_string, string,
538 (const char *) NULL);
542 info->so_value = value;
547 /* Start an include file. */
548 if (! debug_start_source (dhandle, string))
553 /* Start an include file which may be replaced. */
554 push_bincl (info, string, value);
555 if (! debug_start_source (dhandle, string))
560 /* End an N_BINCL include. */
561 if (! debug_start_source (dhandle, pop_bincl (info)))
566 /* This is a duplicate of a header file named by N_BINCL which
567 was eliminated by the linker. */
568 if (! find_excl (info, string, value))
573 if (! debug_record_line (dhandle, desc,
574 value + (info->within_function
575 ? info->function_start_offset : 0)))
580 if (! debug_start_common_block (dhandle, string))
585 if (! debug_end_common_block (dhandle, string))
592 if (info->within_function)
594 /* This always marks the end of a function; we don't
595 need to worry about info->function_end. */
597 value += info->function_start_offset;
598 if (! stab_emit_pending_vars (dhandle, info)
599 || ! debug_end_function (dhandle, value))
601 info->within_function = FALSE;
602 info->function_end = (bfd_vma) -1;
607 /* A const static symbol in the .text section will have an N_FUN
608 entry. We need to use these to mark the end of the function,
609 in case we are looking at gcc output before it was changed to
610 always emit an empty N_FUN. We can't call debug_end_function
611 here, because it might be a local static symbol. */
612 if (info->within_function
613 && (info->function_end == (bfd_vma) -1
614 || value < info->function_end))
615 info->function_end = value;
618 /* FIXME: gdb checks the string for N_STSYM, N_LCSYM or N_ROSYM
619 symbols, and if it does not start with :S, gdb relocates the
620 value to the start of the section. gcc always seems to use
621 :S, so we don't worry about this. */
627 colon = strchr (string, ':');
629 && (colon[1] == 'f' || colon[1] == 'F'))
631 if (info->within_function)
636 if (info->function_end != (bfd_vma) -1
637 && info->function_end < endval)
638 endval = info->function_end;
639 if (! stab_emit_pending_vars (dhandle, info)
640 || ! debug_end_function (dhandle, endval))
642 info->function_end = (bfd_vma) -1;
644 /* For stabs in sections, line numbers and block addresses
645 are offsets from the start of the function. */
647 info->function_start_offset = value;
648 info->within_function = TRUE;
651 if (! parse_stab_string (dhandle, info, type, desc, value, string))
657 if (string != NULL && strcmp (string, "gcc2_compiled.") == 0)
658 info->gcc_compiled = 2;
659 else if (string != NULL && strcmp (string, "gcc_compiled.") == 0)
660 info->gcc_compiled = 1;
662 info->n_opt_found = TRUE;
675 /* Parse the stabs string. */
678 parse_stab_string (void *dhandle, struct stab_handle *info, int stabtype,
679 int desc ATTRIBUTE_UNUSED, bfd_vma value, const char *string)
686 bfd_boolean self_crossref;
689 p = strchr (string, ':');
704 /* FIXME: Sometimes the special C++ names start with '.'. */
706 if (string[0] == '$')
714 /* Was: name = "vptr"; */
720 /* This was an anonymous type that was never fixed up. */
723 /* SunPRO (3.0 at least) static variable encoding. */
726 warn_stab (string, _("unknown C++ encoded name"));
733 if (p == string || (string[0] == ' ' && p == string + 1))
736 name = savestring (string, p - string);
740 if (ISDIGIT (*p) || *p == '(' || *p == '-')
748 /* c is a special case, not followed by a type-number.
749 SYMBOL:c=iVALUE for an integer constant symbol.
750 SYMBOL:c=rVALUE for a floating constant symbol.
751 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
752 e.g. "b:c=e6,0" for "const b = blob1"
753 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
763 /* Floating point constant. */
764 if (! debug_record_float_const (dhandle, name, atof (p)))
768 /* Integer constant. */
769 /* Defining integer constants this way is kind of silly,
770 since 'e' constants allows the compiler to give not only
771 the value, but the type as well. C has at least int,
772 long, unsigned int, and long long as constant types;
773 other languages probably should have at least unsigned as
774 well as signed constants. */
775 if (! debug_record_int_const (dhandle, name, atoi (p)))
779 /* SYMBOL:c=eTYPE,INTVALUE for a constant symbol whose value
780 can be represented as integral.
781 e.g. "b:c=e6,0" for "const b = blob1"
782 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
783 dtype = parse_stab_type (dhandle, info, (const char *) NULL,
784 &p, (debug_type **) NULL);
785 if (dtype == DEBUG_TYPE_NULL)
792 if (! debug_record_typed_const (dhandle, name, dtype, atoi (p)))
803 /* The name of a caught exception. */
804 dtype = parse_stab_type (dhandle, info, (const char *) NULL,
805 &p, (debug_type **) NULL);
806 if (dtype == DEBUG_TYPE_NULL)
808 if (! debug_record_label (dhandle, name, dtype, value))
814 /* A function definition. */
815 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
816 (debug_type **) NULL);
817 if (dtype == DEBUG_TYPE_NULL)
819 if (! debug_record_function (dhandle, name, dtype, type == 'F', value))
822 /* Sun acc puts declared types of arguments here. We don't care
823 about their actual types (FIXME -- we should remember the whole
824 function prototype), but the list may define some new types
825 that we have to remember, so we must scan it now. */
829 if (parse_stab_type (dhandle, info, (const char *) NULL, &p,
830 (debug_type **) NULL)
841 /* A global symbol. The value must be extracted from the
843 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
844 (debug_type **) NULL);
845 if (dtype == DEBUG_TYPE_NULL)
852 leading = bfd_get_symbol_leading_char (info->abfd);
853 for (c = info->symcount, ps = info->syms; c > 0; --c, ++ps)
857 n = bfd_asymbol_name (*ps);
858 if (leading != '\0' && *n == leading)
860 if (*n == *name && strcmp (n, name) == 0)
865 value = bfd_asymbol_value (*ps);
868 if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_GLOBAL,
874 /* This case is faked by a conditional above, when there is no
875 code letter in the dbx data. Dbx data never actually
879 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
880 (debug_type **) NULL);
881 if (dtype == DEBUG_TYPE_NULL)
883 if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_LOCAL,
889 /* A function parameter. */
891 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
892 (debug_type **) NULL);
895 /* pF is a two-letter code that means a function parameter in
896 Fortran. The type-number specifies the type of the return
897 value. Translate it into a pointer-to-function type. */
899 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
900 (debug_type **) NULL);
901 if (dtype != DEBUG_TYPE_NULL)
905 ftype = debug_make_function_type (dhandle, dtype,
906 (debug_type *) NULL, FALSE);
907 dtype = debug_make_pointer_type (dhandle, ftype);
910 if (dtype == DEBUG_TYPE_NULL)
912 if (! debug_record_parameter (dhandle, name, dtype, DEBUG_PARM_STACK,
916 /* FIXME: At this point gdb considers rearranging the parameter
917 address on a big endian machine if it is smaller than an int.
918 We have no way to do that, since we don't really know much
923 if (stabtype == N_FUN)
925 /* Prototype of a function referenced by this file. */
929 if (parse_stab_type (dhandle, info, (const char *) NULL, &p,
930 (debug_type **) NULL)
938 /* Parameter which is in a register. */
939 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
940 (debug_type **) NULL);
941 if (dtype == DEBUG_TYPE_NULL)
943 if (! debug_record_parameter (dhandle, name, dtype, DEBUG_PARM_REG,
949 /* Register variable (either global or local). */
950 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
951 (debug_type **) NULL);
952 if (dtype == DEBUG_TYPE_NULL)
954 if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_REGISTER,
958 /* FIXME: At this point gdb checks to combine pairs of 'p' and
959 'r' stabs into a single 'P' stab. */
963 /* Static symbol at top level of file. */
964 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
965 (debug_type **) NULL);
966 if (dtype == DEBUG_TYPE_NULL)
968 if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_STATIC,
975 dtype = parse_stab_type (dhandle, info, name, &p, &slot);
976 if (dtype == DEBUG_TYPE_NULL)
980 /* A nameless type. Nothing to do. */
984 dtype = debug_name_type (dhandle, name, dtype);
985 if (dtype == DEBUG_TYPE_NULL)
994 /* Struct, union, or enum tag. For GNU C++, this can be be followed
995 by 't' which means we are typedef'ing it as well. */
999 /* FIXME: gdb sets synonym to TRUE if the current language
1008 dtype = parse_stab_type (dhandle, info, name, &p, &slot);
1009 if (dtype == DEBUG_TYPE_NULL)
1014 /* INFO->SELF_CROSSREF is set by parse_stab_type if this type is
1015 a cross reference to itself. These are generated by some
1017 self_crossref = info->self_crossref;
1019 dtype = debug_tag_type (dhandle, name, dtype);
1020 if (dtype == DEBUG_TYPE_NULL)
1025 /* See if we have a cross reference to this tag which we can now
1026 fill in. Avoid filling in a cross reference to ourselves,
1027 because that would lead to circular debugging information. */
1028 if (! self_crossref)
1030 register struct stab_tag **pst;
1032 for (pst = &info->tags; *pst != NULL; pst = &(*pst)->next)
1034 if ((*pst)->name[0] == name[0]
1035 && strcmp ((*pst)->name, name) == 0)
1037 (*pst)->slot = dtype;
1038 *pst = (*pst)->next;
1046 dtype = debug_name_type (dhandle, name, dtype);
1047 if (dtype == DEBUG_TYPE_NULL)
1057 /* Static symbol of local scope */
1058 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
1059 (debug_type **) NULL);
1060 if (dtype == DEBUG_TYPE_NULL)
1062 /* FIXME: gdb checks os9k_stabs here. */
1063 if (! stab_record_variable (dhandle, info, name, dtype,
1064 DEBUG_LOCAL_STATIC, value))
1069 /* Reference parameter. */
1070 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
1071 (debug_type **) NULL);
1072 if (dtype == DEBUG_TYPE_NULL)
1074 if (! debug_record_parameter (dhandle, name, dtype, DEBUG_PARM_REFERENCE,
1080 /* Reference parameter which is in a register. */
1081 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
1082 (debug_type **) NULL);
1083 if (dtype == DEBUG_TYPE_NULL)
1085 if (! debug_record_parameter (dhandle, name, dtype, DEBUG_PARM_REF_REG,
1091 /* This is used by Sun FORTRAN for "function result value".
1092 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
1093 that Pascal uses it too, but when I tried it Pascal used
1094 "x:3" (local symbol) instead. */
1095 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
1096 (debug_type **) NULL);
1097 if (dtype == DEBUG_TYPE_NULL)
1099 if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_LOCAL,
1105 /* SUNPro C++ Namespace =Yn0. */
1106 /* Skip the namespace mapping, as it is not used now. */
1107 if (*(++p) == 'n' && *(++p) == '0')
1115 /* TODO SUNPro C++ support:
1116 Support default arguments after F,P parameters
1117 Ya = Anonymous unions
1118 YM,YD = Pointers to class members
1120 YR = Run-time type information (RTTI) */
1129 /* FIXME: gdb converts structure values to structure pointers in a
1130 couple of cases, depending upon the target. */
1135 /* Parse a stabs type. The typename argument is non-NULL if this is a
1136 typedef or a tag definition. The pp argument points to the stab
1137 string, and is updated. The slotp argument points to a place to
1138 store the slot used if the type is being defined. */
1141 parse_stab_type (void *dhandle, struct stab_handle *info, const char *type_name, const char **pp, debug_type **slotp)
1146 bfd_boolean stringp;
1158 info->self_crossref = FALSE;
1160 /* Read type number if present. The type number may be omitted.
1161 for instance in a two-dimensional array declared with type
1162 "ar1;1;10;ar1;1;10;4". */
1163 if (! ISDIGIT (**pp) && **pp != '(' && **pp != '-')
1165 /* 'typenums=' not present, type is anonymous. Read and return
1166 the definition, but don't put it in the type vector. */
1167 typenums[0] = typenums[1] = -1;
1171 if (! parse_stab_type_number (pp, typenums))
1172 return DEBUG_TYPE_NULL;
1175 /* Type is not being defined here. Either it already
1176 exists, or this is a forward reference to it. */
1177 return stab_find_type (dhandle, info, typenums);
1179 /* Only set the slot if the type is being defined. This means
1180 that the mapping from type numbers to types will only record
1181 the name of the typedef which defines a type. If we don't do
1182 this, then something like
1185 will record that i is of type foo. Unfortunately, stabs
1186 information is ambiguous about variable types. For this code,
1190 the stabs information records both i and j as having the same
1191 type. This could be fixed by patching the compiler. */
1192 if (slotp != NULL && typenums[0] >= 0 && typenums[1] >= 0)
1193 *slotp = stab_find_slot (info, typenums);
1195 /* Type is being defined here. */
1201 const char *p = *pp + 1;
1204 if (ISDIGIT (*p) || *p == '(' || *p == '-')
1208 /* Type attributes. */
1211 for (; *p != ';'; ++p)
1216 return DEBUG_TYPE_NULL;
1224 size = atoi (attr + 1);
1225 size /= 8; /* Size is in bits. We store it in bytes. */
1235 /* Ignore unrecognized type attributes, so future
1236 compilers can invent new ones. */
1249 enum debug_type_kind code;
1250 const char *q1, *q2, *p;
1252 /* A cross reference to another type. */
1256 code = DEBUG_KIND_STRUCT;
1259 code = DEBUG_KIND_UNION;
1262 code = DEBUG_KIND_ENUM;
1265 /* Complain and keep going, so compilers can invent new
1266 cross-reference types. */
1267 warn_stab (orig, _("unrecognized cross reference type"));
1268 code = DEBUG_KIND_STRUCT;
1273 q1 = strchr (*pp, '<');
1274 p = strchr (*pp, ':');
1278 return DEBUG_TYPE_NULL;
1280 if (q1 != NULL && p > q1 && p[1] == ':')
1284 for (q2 = q1; *q2 != '\0'; ++q2)
1288 else if (*q2 == '>')
1290 else if (*q2 == ':' && nest == 0)
1297 return DEBUG_TYPE_NULL;
1301 /* Some versions of g++ can emit stabs like
1303 which define structures in terms of themselves. We need to
1304 tell the caller to avoid building a circular structure. */
1305 if (type_name != NULL
1306 && strncmp (type_name, *pp, p - *pp) == 0
1307 && type_name[p - *pp] == '\0')
1308 info->self_crossref = TRUE;
1310 dtype = stab_find_tagged_type (dhandle, info, *pp, p - *pp, code);
1332 /* This type is defined as another type. */
1336 /* Peek ahead at the number to detect void. */
1337 if (! parse_stab_type_number (pp, xtypenums))
1338 return DEBUG_TYPE_NULL;
1340 if (typenums[0] == xtypenums[0] && typenums[1] == xtypenums[1])
1342 /* This type is being defined as itself, which means that
1344 dtype = debug_make_void_type (dhandle);
1350 /* Go back to the number and have parse_stab_type get it.
1351 This means that we can deal with something like
1352 t(1,2)=(3,4)=... which the Lucid compiler uses. */
1353 dtype = parse_stab_type (dhandle, info, (const char *) NULL,
1354 pp, (debug_type **) NULL);
1355 if (dtype == DEBUG_TYPE_NULL)
1356 return DEBUG_TYPE_NULL;
1359 if (typenums[0] != -1)
1361 if (! stab_record_type (dhandle, info, typenums, dtype))
1362 return DEBUG_TYPE_NULL;
1369 dtype = debug_make_pointer_type (dhandle,
1370 parse_stab_type (dhandle, info,
1371 (const char *) NULL,
1373 (debug_type **) NULL));
1377 /* Reference to another type. */
1378 dtype = (debug_make_reference_type
1380 parse_stab_type (dhandle, info, (const char *) NULL, pp,
1381 (debug_type **) NULL)));
1385 /* Function returning another type. */
1386 /* FIXME: gdb checks os9k_stabs here. */
1387 dtype = (debug_make_function_type
1389 parse_stab_type (dhandle, info, (const char *) NULL, pp,
1390 (debug_type **) NULL),
1391 (debug_type *) NULL, FALSE));
1395 /* Const qualifier on some type (Sun). */
1396 /* FIXME: gdb accepts 'c' here if os9k_stabs. */
1397 dtype = debug_make_const_type (dhandle,
1398 parse_stab_type (dhandle, info,
1399 (const char *) NULL,
1401 (debug_type **) NULL));
1405 /* Volatile qual on some type (Sun). */
1406 /* FIXME: gdb accepts 'i' here if os9k_stabs. */
1407 dtype = (debug_make_volatile_type
1409 parse_stab_type (dhandle, info, (const char *) NULL, pp,
1410 (debug_type **) NULL)));
1414 /* Offset (class & variable) type. This is used for a pointer
1415 relative to an object. */
1422 domain = parse_stab_type (dhandle, info, (const char *) NULL, pp,
1423 (debug_type **) NULL);
1424 if (domain == DEBUG_TYPE_NULL)
1425 return DEBUG_TYPE_NULL;
1430 return DEBUG_TYPE_NULL;
1434 memtype = parse_stab_type (dhandle, info, (const char *) NULL, pp,
1435 (debug_type **) NULL);
1436 if (memtype == DEBUG_TYPE_NULL)
1437 return DEBUG_TYPE_NULL;
1439 dtype = debug_make_offset_type (dhandle, domain, memtype);
1444 /* Method (class & fn) type. */
1447 debug_type return_type;
1450 return_type = parse_stab_type (dhandle, info, (const char *) NULL,
1451 pp, (debug_type **) NULL);
1452 if (return_type == DEBUG_TYPE_NULL)
1453 return DEBUG_TYPE_NULL;
1457 return DEBUG_TYPE_NULL;
1460 dtype = debug_make_method_type (dhandle, return_type,
1462 (debug_type *) NULL, FALSE);
1467 debug_type return_type;
1471 bfd_boolean varargs;
1473 domain = parse_stab_type (dhandle, info, (const char *) NULL,
1474 pp, (debug_type **) NULL);
1475 if (domain == DEBUG_TYPE_NULL)
1476 return DEBUG_TYPE_NULL;
1481 return DEBUG_TYPE_NULL;
1485 return_type = parse_stab_type (dhandle, info, (const char *) NULL,
1486 pp, (debug_type **) NULL);
1487 if (return_type == DEBUG_TYPE_NULL)
1488 return DEBUG_TYPE_NULL;
1491 args = (debug_type *) xmalloc (alloc * sizeof *args);
1498 return DEBUG_TYPE_NULL;
1505 args = ((debug_type *)
1506 xrealloc (args, alloc * sizeof *args));
1509 args[n] = parse_stab_type (dhandle, info, (const char *) NULL,
1510 pp, (debug_type **) NULL);
1511 if (args[n] == DEBUG_TYPE_NULL)
1512 return DEBUG_TYPE_NULL;
1517 /* If the last type is not void, then this function takes a
1518 variable number of arguments. Otherwise, we must strip
1521 || debug_get_type_kind (dhandle, args[n - 1]) != DEBUG_KIND_VOID)
1529 args[n] = DEBUG_TYPE_NULL;
1531 dtype = debug_make_method_type (dhandle, return_type, domain, args,
1538 dtype = parse_stab_range_type (dhandle, info, type_name, pp, typenums);
1542 /* FIXME: gdb checks os9k_stabs here. */
1543 /* Sun ACC builtin int type. */
1544 dtype = parse_stab_sun_builtin_type (dhandle, pp);
1548 /* Sun ACC builtin float type. */
1549 dtype = parse_stab_sun_floating_type (dhandle, pp);
1553 /* Enumeration type. */
1554 dtype = parse_stab_enum_type (dhandle, pp);
1559 /* Struct or union type. */
1560 dtype = parse_stab_struct_type (dhandle, info, type_name, pp,
1561 descriptor == 's', typenums);
1569 return DEBUG_TYPE_NULL;
1573 dtype = parse_stab_array_type (dhandle, info, pp, stringp);
1577 dtype = debug_make_set_type (dhandle,
1578 parse_stab_type (dhandle, info,
1579 (const char *) NULL,
1581 (debug_type **) NULL),
1587 return DEBUG_TYPE_NULL;
1590 if (dtype == DEBUG_TYPE_NULL)
1591 return DEBUG_TYPE_NULL;
1593 if (typenums[0] != -1)
1595 if (! stab_record_type (dhandle, info, typenums, dtype))
1596 return DEBUG_TYPE_NULL;
1601 if (! debug_record_type_size (dhandle, dtype, (unsigned int) size))
1602 return DEBUG_TYPE_NULL;
1608 /* Read a number by which a type is referred to in dbx data, or
1609 perhaps read a pair (FILENUM, TYPENUM) in parentheses. Just a
1610 single number N is equivalent to (0,N). Return the two numbers by
1611 storing them in the vector TYPENUMS. */
1614 parse_stab_type_number (const char **pp, int *typenums)
1623 typenums[1] = (int) parse_number (pp, (bfd_boolean *) NULL);
1628 typenums[0] = (int) parse_number (pp, (bfd_boolean *) NULL);
1635 typenums[1] = (int) parse_number (pp, (bfd_boolean *) NULL);
1647 /* Parse a range type. */
1650 parse_stab_range_type (void *dhandle, struct stab_handle *info, const char *type_name, const char **pp, const int *typenums)
1654 bfd_boolean self_subrange;
1655 debug_type index_type;
1656 const char *s2, *s3;
1657 bfd_signed_vma n2, n3;
1658 bfd_boolean ov2, ov3;
1662 index_type = DEBUG_TYPE_NULL;
1664 /* First comes a type we are a subrange of.
1665 In C it is usually 0, 1 or the type being defined. */
1666 if (! parse_stab_type_number (pp, rangenums))
1667 return DEBUG_TYPE_NULL;
1669 self_subrange = (rangenums[0] == typenums[0]
1670 && rangenums[1] == typenums[1]);
1675 index_type = parse_stab_type (dhandle, info, (const char *) NULL,
1676 pp, (debug_type **) NULL);
1677 if (index_type == DEBUG_TYPE_NULL)
1678 return DEBUG_TYPE_NULL;
1684 /* The remaining two operands are usually lower and upper bounds of
1685 the range. But in some special cases they mean something else. */
1687 n2 = parse_number (pp, &ov2);
1691 return DEBUG_TYPE_NULL;
1696 n3 = parse_number (pp, &ov3);
1700 return DEBUG_TYPE_NULL;
1706 /* gcc will emit range stabs for long long types. Handle this
1707 as a special case. FIXME: This needs to be more general. */
1708 #define LLLOW "01000000000000000000000;"
1709 #define LLHIGH "0777777777777777777777;"
1710 #define ULLHIGH "01777777777777777777777;"
1711 if (index_type == DEBUG_TYPE_NULL)
1713 if (CONST_STRNEQ (s2, LLLOW)
1714 && CONST_STRNEQ (s3, LLHIGH))
1715 return debug_make_int_type (dhandle, 8, FALSE);
1718 && CONST_STRNEQ (s3, ULLHIGH))
1719 return debug_make_int_type (dhandle, 8, TRUE);
1722 warn_stab (orig, _("numeric overflow"));
1725 if (index_type == DEBUG_TYPE_NULL)
1727 /* A type defined as a subrange of itself, with both bounds 0,
1729 if (self_subrange && n2 == 0 && n3 == 0)
1730 return debug_make_void_type (dhandle);
1732 /* A type defined as a subrange of itself, with n2 positive and
1733 n3 zero, is a complex type, and n2 is the number of bytes. */
1734 if (self_subrange && n3 == 0 && n2 > 0)
1735 return debug_make_complex_type (dhandle, n2);
1737 /* If n3 is zero and n2 is positive, this is a floating point
1738 type, and n2 is the number of bytes. */
1739 if (n3 == 0 && n2 > 0)
1740 return debug_make_float_type (dhandle, n2);
1742 /* If the upper bound is -1, this is an unsigned int. */
1743 if (n2 == 0 && n3 == -1)
1745 /* When gcc is used with -gstabs, but not -gstabs+, it will emit
1746 long long int:t6=r1;0;-1;
1747 long long unsigned int:t7=r1;0;-1;
1748 We hack here to handle this reasonably. */
1749 if (type_name != NULL)
1751 if (strcmp (type_name, "long long int") == 0)
1752 return debug_make_int_type (dhandle, 8, FALSE);
1753 else if (strcmp (type_name, "long long unsigned int") == 0)
1754 return debug_make_int_type (dhandle, 8, TRUE);
1756 /* FIXME: The size here really depends upon the target. */
1757 return debug_make_int_type (dhandle, 4, TRUE);
1760 /* A range of 0 to 127 is char. */
1761 if (self_subrange && n2 == 0 && n3 == 127)
1762 return debug_make_int_type (dhandle, 1, FALSE);
1764 /* FIXME: gdb checks for the language CHILL here. */
1769 return debug_make_int_type (dhandle, - n3, TRUE);
1770 else if (n3 == 0xff)
1771 return debug_make_int_type (dhandle, 1, TRUE);
1772 else if (n3 == 0xffff)
1773 return debug_make_int_type (dhandle, 2, TRUE);
1774 else if (n3 == (bfd_signed_vma) 0xffffffff)
1775 return debug_make_int_type (dhandle, 4, TRUE);
1777 else if (n3 == (bfd_signed_vma) 0xffffffffffffffffLL)
1778 return debug_make_int_type (dhandle, 8, TRUE);
1783 && (self_subrange || n2 == -8))
1784 return debug_make_int_type (dhandle, - n2, TRUE);
1785 else if (n2 == - n3 - 1 || n2 == n3 + 1)
1788 return debug_make_int_type (dhandle, 1, FALSE);
1789 else if (n3 == 0x7fff)
1790 return debug_make_int_type (dhandle, 2, FALSE);
1791 else if (n3 == 0x7fffffff)
1792 return debug_make_int_type (dhandle, 4, FALSE);
1794 else if (n3 == ((((bfd_vma) 0x7fffffff) << 32) | 0xffffffff))
1795 return debug_make_int_type (dhandle, 8, FALSE);
1800 /* At this point I don't have the faintest idea how to deal with a
1801 self_subrange type; I'm going to assume that this is used as an
1802 idiom, and that all of them are special cases. So . . . */
1806 return DEBUG_TYPE_NULL;
1809 index_type = stab_find_type (dhandle, info, rangenums);
1810 if (index_type == DEBUG_TYPE_NULL)
1812 /* Does this actually ever happen? Is that why we are worrying
1813 about dealing with it rather than just calling error_type? */
1814 warn_stab (orig, _("missing index type"));
1815 index_type = debug_make_int_type (dhandle, 4, FALSE);
1818 return debug_make_range_type (dhandle, index_type, n2, n3);
1821 /* Sun's ACC uses a somewhat saner method for specifying the builtin
1822 typedefs in every file (for int, long, etc):
1824 type = b <signed> <width>; <offset>; <nbits>
1825 signed = u or s. Possible c in addition to u or s (for char?).
1826 offset = offset from high order bit to start bit of type.
1827 width is # bytes in object of this type, nbits is # bits in type.
1829 The width/offset stuff appears to be for small objects stored in
1830 larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
1834 parse_stab_sun_builtin_type (void *dhandle, const char **pp)
1837 bfd_boolean unsignedp;
1852 return DEBUG_TYPE_NULL;
1856 /* OpenSolaris source code indicates that one of "cbv" characters
1857 can come next and specify the intrinsic 'iformat' encoding.
1858 'c' is character encoding, 'b' is boolean encoding, and 'v' is
1859 varargs encoding. This field can be safely ignored because
1860 the type of the field is determined from the bitwidth extracted
1862 if (**pp == 'c' || **pp == 'b' || **pp == 'v')
1865 /* The first number appears to be the number of bytes occupied
1866 by this type, except that unsigned short is 4 instead of 2.
1867 Since this information is redundant with the third number,
1868 we will ignore it. */
1869 (void) parse_number (pp, (bfd_boolean *) NULL);
1873 return DEBUG_TYPE_NULL;
1877 /* The second number is always 0, so ignore it too. */
1878 (void) parse_number (pp, (bfd_boolean *) NULL);
1882 return DEBUG_TYPE_NULL;
1886 /* The third number is the number of bits for this type. */
1887 bits = parse_number (pp, (bfd_boolean *) NULL);
1889 /* The type *should* end with a semicolon. If it are embedded
1890 in a larger type the semicolon may be the only way to know where
1891 the type ends. If this type is at the end of the stabstring we
1892 can deal with the omitted semicolon (but we don't have to like
1893 it). Don't bother to complain(), Sun's compiler omits the semicolon
1899 return debug_make_void_type (dhandle);
1901 return debug_make_int_type (dhandle, bits / 8, unsignedp);
1904 /* Parse a builtin floating type generated by the Sun compiler. */
1907 parse_stab_sun_floating_type (void *dhandle, const char **pp)
1915 /* The first number has more details about the type, for example
1917 details = parse_number (pp, (bfd_boolean *) NULL);
1921 return DEBUG_TYPE_NULL;
1924 /* The second number is the number of bytes occupied by this type */
1925 bytes = parse_number (pp, (bfd_boolean *) NULL);
1929 return DEBUG_TYPE_NULL;
1932 if (details == NF_COMPLEX
1933 || details == NF_COMPLEX16
1934 || details == NF_COMPLEX32)
1935 return debug_make_complex_type (dhandle, bytes);
1937 return debug_make_float_type (dhandle, bytes);
1940 /* Handle an enum type. */
1943 parse_stab_enum_type (void *dhandle, const char **pp)
1947 bfd_signed_vma *values;
1953 /* FIXME: gdb checks os9k_stabs here. */
1955 /* The aix4 compiler emits an extra field before the enum members;
1956 my guess is it's a type of some sort. Just ignore it. */
1964 /* Read the value-names and their values.
1965 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
1966 A semicolon or comma instead of a NAME means the end. */
1968 names = (const char **) xmalloc (alloc * sizeof *names);
1969 values = (bfd_signed_vma *) xmalloc (alloc * sizeof *values);
1971 while (**pp != '\0' && **pp != ';' && **pp != ',')
1981 name = savestring (*pp, p - *pp);
1984 val = (bfd_signed_vma) parse_number (pp, (bfd_boolean *) NULL);
1991 return DEBUG_TYPE_NULL;
1998 names = ((const char **)
1999 xrealloc (names, alloc * sizeof *names));
2000 values = ((bfd_signed_vma *)
2001 xrealloc (values, alloc * sizeof *values));
2015 return debug_make_enum_type (dhandle, names, values);
2018 /* Read the description of a structure (or union type) and return an object
2019 describing the type.
2021 PP points to a character pointer that points to the next unconsumed token
2022 in the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;",
2023 *PP will point to "4a:1,0,32;;". */
2026 parse_stab_struct_type (void *dhandle, struct stab_handle *info,
2027 const char *tagname, const char **pp,
2028 bfd_boolean structp, const int *typenums)
2031 debug_baseclass *baseclasses;
2032 debug_field *fields = NULL;
2033 bfd_boolean statics;
2034 debug_method *methods;
2035 debug_type vptrbase;
2036 bfd_boolean ownvptr;
2039 size = parse_number (pp, (bfd_boolean *) NULL);
2041 /* Get the other information. */
2042 if (! parse_stab_baseclasses (dhandle, info, pp, &baseclasses)
2043 || ! parse_stab_struct_fields (dhandle, info, pp, &fields, &statics)
2044 || ! parse_stab_members (dhandle, info, tagname, pp, typenums, &methods)
2045 || ! parse_stab_tilde_field (dhandle, info, pp, typenums, &vptrbase,
2050 return DEBUG_TYPE_NULL;
2054 && baseclasses == NULL
2056 && vptrbase == DEBUG_TYPE_NULL
2058 return debug_make_struct_type (dhandle, structp, size, fields);
2060 return debug_make_object_type (dhandle, structp, size, fields, baseclasses,
2061 methods, vptrbase, ownvptr);
2064 /* The stabs for C++ derived classes contain baseclass information which
2065 is marked by a '!' character after the total size. This function is
2066 called when we encounter the baseclass marker, and slurps up all the
2067 baseclass information.
2069 Immediately following the '!' marker is the number of base classes that
2070 the class is derived from, followed by information for each base class.
2071 For each base class, there are two visibility specifiers, a bit offset
2072 to the base class information within the derived class, a reference to
2073 the type for the base class, and a terminating semicolon.
2075 A typical example, with two base classes, would be "!2,020,19;0264,21;".
2077 Baseclass information marker __________________|| | | | | | |
2078 Number of baseclasses __________________________| | | | | | |
2079 Visibility specifiers (2) ________________________| | | | | |
2080 Offset in bits from start of class _________________| | | | |
2081 Type number for base class ___________________________| | | |
2082 Visibility specifiers (2) _______________________________| | |
2083 Offset in bits from start of class ________________________| |
2084 Type number of base class ____________________________________|
2086 Return TRUE for success, FALSE for failure. */
2089 parse_stab_baseclasses (void *dhandle, struct stab_handle *info,
2090 const char **pp, debug_baseclass **retp)
2094 debug_baseclass *classes;
2102 /* No base classes. */
2107 c = (unsigned int) parse_number (pp, (bfd_boolean *) NULL);
2116 classes = (debug_baseclass *) xmalloc ((c + 1) * sizeof (**retp));
2118 for (i = 0; i < c; i++)
2120 bfd_boolean is_virtual;
2121 enum debug_visibility visibility;
2134 warn_stab (orig, _("unknown virtual character for baseclass"));
2143 visibility = DEBUG_VISIBILITY_PRIVATE;
2146 visibility = DEBUG_VISIBILITY_PROTECTED;
2149 visibility = DEBUG_VISIBILITY_PUBLIC;
2152 warn_stab (orig, _("unknown visibility character for baseclass"));
2153 visibility = DEBUG_VISIBILITY_PUBLIC;
2158 /* The remaining value is the bit offset of the portion of the
2159 object corresponding to this baseclass. Always zero in the
2160 absence of multiple inheritance. */
2161 bitpos = parse_number (pp, (bfd_boolean *) NULL);
2169 type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
2170 (debug_type **) NULL);
2171 if (type == DEBUG_TYPE_NULL)
2174 classes[i] = debug_make_baseclass (dhandle, type, bitpos, is_virtual,
2176 if (classes[i] == DEBUG_BASECLASS_NULL)
2184 classes[i] = DEBUG_BASECLASS_NULL;
2191 /* Read struct or class data fields. They have the form:
2193 NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
2195 At the end, we see a semicolon instead of a field.
2197 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
2200 The optional VISIBILITY is one of:
2202 '/0' (VISIBILITY_PRIVATE)
2203 '/1' (VISIBILITY_PROTECTED)
2204 '/2' (VISIBILITY_PUBLIC)
2205 '/9' (VISIBILITY_IGNORE)
2207 or nothing, for C style fields with public visibility.
2209 Returns 1 for success, 0 for failure. */
2212 parse_stab_struct_fields (void *dhandle, struct stab_handle *info,
2213 const char **pp, debug_field **retp,
2214 bfd_boolean *staticsp)
2218 debug_field *fields;
2229 fields = (debug_field *) xmalloc (alloc * sizeof *fields);
2232 /* FIXME: gdb checks os9k_stabs here. */
2236 /* Add 1 to c to leave room for NULL pointer at end. */
2240 fields = ((debug_field *)
2241 xrealloc (fields, alloc * sizeof *fields));
2244 /* If it starts with CPLUS_MARKER it is a special abbreviation,
2245 unless the CPLUS_MARKER is followed by an underscore, in
2246 which case it is just the name of an anonymous type, which we
2247 should handle like any other type name. We accept either '$'
2248 or '.', because a field name can never contain one of these
2249 characters except as a CPLUS_MARKER. */
2251 if ((*p == '$' || *p == '.') && p[1] != '_')
2254 if (! parse_stab_cpp_abbrev (dhandle, info, pp, fields + c))
2263 /* Look for the ':' that separates the field name from the field
2264 values. Data members are delimited by a single ':', while member
2265 functions are delimited by a pair of ':'s. When we hit the member
2266 functions (if any), terminate scan loop and return. */
2268 p = strchr (p, ':');
2279 if (! parse_stab_one_struct_field (dhandle, info, pp, p, fields + c,
2286 fields[c] = DEBUG_FIELD_NULL;
2293 /* Special GNU C++ name. */
2296 parse_stab_cpp_abbrev (void *dhandle, struct stab_handle *info,
2297 const char **pp, debug_field *retp)
2303 const char *type_name;
2307 *retp = DEBUG_FIELD_NULL;
2321 /* At this point, *pp points to something like "22:23=*22...", where
2322 the type number before the ':' is the "context" and everything
2323 after is a regular type definition. Lookup the type, find it's
2324 name, and construct the field name. */
2326 context = parse_stab_type (dhandle, info, (const char *) NULL, pp,
2327 (debug_type **) NULL);
2328 if (context == DEBUG_TYPE_NULL)
2334 /* $vf -- a virtual function table pointer. */
2338 /* $vb -- a virtual bsomethingorother */
2339 type_name = debug_get_type_name (dhandle, context);
2340 if (type_name == NULL)
2342 warn_stab (orig, _("unnamed $vb type"));
2345 name = concat ("_vb$", type_name, (const char *) NULL);
2348 warn_stab (orig, _("unrecognized C++ abbreviation"));
2349 name = "INVALID_CPLUSPLUS_ABBREV";
2360 type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
2361 (debug_type **) NULL);
2369 bitpos = parse_number (pp, (bfd_boolean *) NULL);
2377 *retp = debug_make_field (dhandle, name, type, bitpos, 0,
2378 DEBUG_VISIBILITY_PRIVATE);
2379 if (*retp == DEBUG_FIELD_NULL)
2385 /* Parse a single field in a struct or union. */
2388 parse_stab_one_struct_field (void *dhandle, struct stab_handle *info,
2389 const char **pp, const char *p,
2390 debug_field *retp, bfd_boolean *staticsp)
2394 enum debug_visibility visibility;
2401 /* FIXME: gdb checks ARM_DEMANGLING here. */
2403 name = savestring (*pp, p - *pp);
2408 visibility = DEBUG_VISIBILITY_PUBLIC;
2415 visibility = DEBUG_VISIBILITY_PRIVATE;
2418 visibility = DEBUG_VISIBILITY_PROTECTED;
2421 visibility = DEBUG_VISIBILITY_PUBLIC;
2424 warn_stab (orig, _("unknown visibility character for field"));
2425 visibility = DEBUG_VISIBILITY_PUBLIC;
2431 type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
2432 (debug_type **) NULL);
2433 if (type == DEBUG_TYPE_NULL)
2443 /* This is a static class member. */
2445 p = strchr (*pp, ';');
2453 varname = savestring (*pp, p - *pp);
2457 *retp = debug_make_static_member (dhandle, name, type, varname,
2472 bitpos = parse_number (pp, (bfd_boolean *) NULL);
2481 bitsize = parse_number (pp, (bfd_boolean *) NULL);
2490 if (bitpos == 0 && bitsize == 0)
2492 /* This can happen in two cases: (1) at least for gcc 2.4.5 or
2493 so, it is a field which has been optimized out. The correct
2494 stab for this case is to use VISIBILITY_IGNORE, but that is a
2495 recent invention. (2) It is a 0-size array. For example
2496 union { int num; char str[0]; } foo. Printing "<no value>"
2497 for str in "p foo" is OK, since foo.str (and thus foo.str[3])
2498 will continue to work, and a 0-size array as a whole doesn't
2499 have any contents to print.
2501 I suspect this probably could also happen with gcc -gstabs
2502 (not -gstabs+) for static fields, and perhaps other C++
2503 extensions. Hopefully few people use -gstabs with gdb, since
2504 it is intended for dbx compatibility. */
2505 visibility = DEBUG_VISIBILITY_IGNORE;
2508 /* FIXME: gdb does some stuff here to mark fields as unpacked. */
2510 *retp = debug_make_field (dhandle, name, type, bitpos, bitsize, visibility);
2515 /* Read member function stabs info for C++ classes. The form of each member
2518 NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;
2520 An example with two member functions is:
2522 afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;
2524 For the case of overloaded operators, the format is op$::*.funcs, where
2525 $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
2526 name (such as `+=') and `.' marks the end of the operator name. */
2529 parse_stab_members (void *dhandle, struct stab_handle *info,
2530 const char *tagname, const char **pp,
2531 const int *typenums, debug_method **retp)
2534 debug_method *methods;
2538 debug_method_variant *variants = NULL;
2539 char *argtypes = NULL;
2553 unsigned int allocvars;
2554 debug_type look_ahead_type;
2556 p = strchr (*pp, ':');
2557 if (p == NULL || p[1] != ':')
2560 /* FIXME: Some systems use something other than '$' here. */
2561 if ((*pp)[0] != 'o' || (*pp)[1] != 'p' || (*pp)[2] != '$')
2563 name = savestring (*pp, p - *pp);
2568 /* This is a completely weird case. In order to stuff in the
2569 names that might contain colons (the usual name delimiter),
2570 Mike Tiemann defined a different name format which is
2571 signalled if the identifier is "op$". In that case, the
2572 format is "op$::XXXX." where XXXX is the name. This is
2573 used for names like "+" or "=". YUUUUUUUK! FIXME! */
2575 for (p = *pp; *p != '.' && *p != '\0'; p++)
2582 name = savestring (*pp, p - *pp);
2587 variants = ((debug_method_variant *)
2588 xmalloc (allocvars * sizeof *variants));
2591 look_ahead_type = DEBUG_TYPE_NULL;
2597 enum debug_visibility visibility;
2598 bfd_boolean constp, volatilep, staticp;
2601 const char *physname;
2602 bfd_boolean varargs;
2604 if (look_ahead_type != DEBUG_TYPE_NULL)
2606 /* g++ version 1 kludge */
2607 type = look_ahead_type;
2608 look_ahead_type = DEBUG_TYPE_NULL;
2612 type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
2613 (debug_type **) NULL);
2614 if (type == DEBUG_TYPE_NULL)
2625 p = strchr (*pp, ';');
2633 if (debug_get_type_kind (dhandle, type) == DEBUG_KIND_METHOD
2634 && debug_get_parameter_types (dhandle, type, &varargs) == NULL)
2637 argtypes = savestring (*pp, p - *pp);
2643 visibility = DEBUG_VISIBILITY_PRIVATE;
2646 visibility = DEBUG_VISIBILITY_PROTECTED;
2649 visibility = DEBUG_VISIBILITY_PUBLIC;
2659 /* Normal function. */
2663 /* const member function. */
2668 /* volatile member function. */
2673 /* const volatile member function. */
2681 /* File compiled with g++ version 1; no information. */
2684 warn_stab (orig, _("const/volatile indicator missing"));
2692 /* virtual member function, followed by index. The sign
2693 bit is supposedly set to distinguish
2694 pointers-to-methods from virtual function indicies. */
2696 voffset = parse_number (pp, (bfd_boolean *) NULL);
2703 voffset &= 0x7fffffff;
2705 if (**pp == ';' || *pp == '\0')
2707 /* Must be g++ version 1. */
2708 context = DEBUG_TYPE_NULL;
2712 /* Figure out from whence this virtual function
2713 came. It may belong to virtual function table of
2714 one of its baseclasses. */
2715 look_ahead_type = parse_stab_type (dhandle, info,
2716 (const char *) NULL,
2718 (debug_type **) NULL);
2721 /* g++ version 1 overloaded methods. */
2722 context = DEBUG_TYPE_NULL;
2726 context = look_ahead_type;
2727 look_ahead_type = DEBUG_TYPE_NULL;
2739 /* static member function. */
2743 context = DEBUG_TYPE_NULL;
2744 if (strncmp (argtypes, name, strlen (name)) != 0)
2749 warn_stab (orig, "member function type missing");
2751 context = DEBUG_TYPE_NULL;
2757 context = DEBUG_TYPE_NULL;
2761 /* If the type is not a stub, then the argtypes string is
2762 the physical name of the function. Otherwise the
2763 argtypes string is the mangled form of the argument
2764 types, and the full type and the physical name must be
2765 extracted from them. */
2766 physname = argtypes;
2769 debug_type class_type, return_type;
2771 class_type = stab_find_type (dhandle, info, typenums);
2772 if (class_type == DEBUG_TYPE_NULL)
2774 return_type = debug_get_return_type (dhandle, type);
2775 if (return_type == DEBUG_TYPE_NULL)
2780 type = parse_stab_argtypes (dhandle, info, class_type, name,
2781 tagname, return_type, argtypes,
2782 constp, volatilep, &physname);
2783 if (type == DEBUG_TYPE_NULL)
2787 if (cvars + 1 >= allocvars)
2790 variants = ((debug_method_variant *)
2792 allocvars * sizeof *variants));
2796 variants[cvars] = debug_make_method_variant (dhandle, physname,
2801 variants[cvars] = debug_make_static_method_variant (dhandle,
2807 if (variants[cvars] == DEBUG_METHOD_VARIANT_NULL)
2812 while (**pp != ';' && **pp != '\0');
2814 variants[cvars] = DEBUG_METHOD_VARIANT_NULL;
2822 methods = ((debug_method *)
2823 xrealloc (methods, alloc * sizeof *methods));
2826 methods[c] = debug_make_method (dhandle, name, variants);
2831 if (methods != NULL)
2832 methods[c] = DEBUG_METHOD_NULL;
2841 if (variants != NULL)
2843 if (argtypes != NULL)
2848 /* Parse a string representing argument types for a method. Stabs
2849 tries to save space by packing argument types into a mangled
2850 string. This string should give us enough information to extract
2851 both argument types and the physical name of the function, given
2855 parse_stab_argtypes (void *dhandle, struct stab_handle *info,
2856 debug_type class_type, const char *fieldname,
2857 const char *tagname, debug_type return_type,
2858 const char *argtypes, bfd_boolean constp,
2859 bfd_boolean volatilep, const char **pphysname)
2861 bfd_boolean is_full_physname_constructor;
2862 bfd_boolean is_constructor;
2863 bfd_boolean is_destructor;
2866 bfd_boolean varargs;
2867 unsigned int physname_len = 0;
2869 /* Constructors are sometimes handled specially. */
2870 is_full_physname_constructor = ((argtypes[0] == '_'
2871 && argtypes[1] == '_'
2872 && (ISDIGIT (argtypes[2])
2873 || argtypes[2] == 'Q'
2874 || argtypes[2] == 't'))
2875 || CONST_STRNEQ (argtypes, "__ct"));
2877 is_constructor = (is_full_physname_constructor
2879 && strcmp (fieldname, tagname) == 0));
2880 is_destructor = ((argtypes[0] == '_'
2881 && (argtypes[1] == '$' || argtypes[1] == '.')
2882 && argtypes[2] == '_')
2883 || CONST_STRNEQ (argtypes, "__dt"));
2884 is_v3 = argtypes[0] == '_' && argtypes[1] == 'Z';
2886 if (!(is_destructor || is_full_physname_constructor || is_v3))
2889 const char *const_prefix;
2890 const char *volatile_prefix;
2892 unsigned int mangled_name_len;
2895 len = tagname == NULL ? 0 : strlen (tagname);
2896 const_prefix = constp ? "C" : "";
2897 volatile_prefix = volatilep ? "V" : "";
2900 sprintf (buf, "__%s%s", const_prefix, volatile_prefix);
2901 else if (tagname != NULL && strchr (tagname, '<') != NULL)
2903 /* Template methods are fully mangled. */
2904 sprintf (buf, "__%s%s", const_prefix, volatile_prefix);
2909 sprintf (buf, "__%s%s%d", const_prefix, volatile_prefix, len);
2911 mangled_name_len = ((is_constructor ? 0 : strlen (fieldname))
2917 if (fieldname[0] == 'o'
2918 && fieldname[1] == 'p'
2919 && (fieldname[2] == '$' || fieldname[2] == '.'))
2923 opname = cplus_mangle_opname (fieldname + 3, 0);
2926 fprintf (stderr, _("No mangling for \"%s\"\n"), fieldname);
2927 return DEBUG_TYPE_NULL;
2929 mangled_name_len += strlen (opname);
2930 physname = (char *) xmalloc (mangled_name_len);
2931 strncpy (physname, fieldname, 3);
2932 strcpy (physname + 3, opname);
2936 physname = (char *) xmalloc (mangled_name_len);
2940 strcpy (physname, fieldname);
2943 physname_len = strlen (physname);
2944 strcat (physname, buf);
2945 if (tagname != NULL)
2946 strcat (physname, tagname);
2947 strcat (physname, argtypes);
2949 *pphysname = physname;
2952 if (*argtypes == '\0' || is_destructor)
2954 args = (debug_type *) xmalloc (sizeof *args);
2956 return debug_make_method_type (dhandle, return_type, class_type, args,
2960 args = stab_demangle_argtypes (dhandle, info, *pphysname, &varargs, physname_len);
2962 return DEBUG_TYPE_NULL;
2964 return debug_make_method_type (dhandle, return_type, class_type, args,
2968 /* The tail end of stabs for C++ classes that contain a virtual function
2969 pointer contains a tilde, a %, and a type number.
2970 The type number refers to the base class (possibly this class itself) which
2971 contains the vtable pointer for the current class.
2973 This function is called when we have parsed all the method declarations,
2974 so we can look for the vptr base class info. */
2977 parse_stab_tilde_field (void *dhandle, struct stab_handle *info,
2978 const char **pp, const int *typenums,
2979 debug_type *retvptrbase, bfd_boolean *retownvptr)
2985 *retvptrbase = DEBUG_TYPE_NULL;
2986 *retownvptr = FALSE;
2990 /* If we are positioned at a ';', then skip it. */
2999 if (**pp == '=' || **pp == '+' || **pp == '-')
3001 /* Obsolete flags that used to indicate the presence of
3002 constructors and/or destructors. */
3013 /* The next number is the type number of the base class (possibly
3014 our own class) which supplies the vtable for this class. */
3015 if (! parse_stab_type_number (pp, vtypenums))
3018 if (vtypenums[0] == typenums[0]
3019 && vtypenums[1] == typenums[1])
3028 vtype = parse_stab_type (dhandle, info, (const char *) NULL, pp,
3029 (debug_type **) NULL);
3030 for (p = *pp; *p != ';' && *p != '\0'; p++)
3038 *retvptrbase = vtype;
3046 /* Read a definition of an array type. */
3049 parse_stab_array_type (void *dhandle, struct stab_handle *info,
3050 const char **pp, bfd_boolean stringp)
3055 debug_type index_type;
3056 bfd_boolean adjustable;
3057 bfd_signed_vma lower, upper;
3058 debug_type element_type;
3060 /* Format of an array type:
3061 "ar<index type>;lower;upper;<array_contents_type>".
3062 OS9000: "arlower,upper;<array_contents_type>".
3064 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
3065 for these, produce a type like float[][]. */
3069 /* FIXME: gdb checks os9k_stabs here. */
3071 /* If the index type is type 0, we take it as int. */
3073 if (! parse_stab_type_number (&p, typenums))
3074 return DEBUG_TYPE_NULL;
3075 if (typenums[0] == 0 && typenums[1] == 0 && **pp != '=')
3077 index_type = debug_find_named_type (dhandle, "int");
3078 if (index_type == DEBUG_TYPE_NULL)
3080 index_type = debug_make_int_type (dhandle, 4, FALSE);
3081 if (index_type == DEBUG_TYPE_NULL)
3082 return DEBUG_TYPE_NULL;
3088 index_type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
3089 (debug_type **) NULL);
3095 return DEBUG_TYPE_NULL;
3101 if (! ISDIGIT (**pp) && **pp != '-')
3107 lower = (bfd_signed_vma) parse_number (pp, (bfd_boolean *) NULL);
3111 return DEBUG_TYPE_NULL;
3115 if (! ISDIGIT (**pp) && **pp != '-')
3121 upper = (bfd_signed_vma) parse_number (pp, (bfd_boolean *) NULL);
3125 return DEBUG_TYPE_NULL;
3129 element_type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
3130 (debug_type **) NULL);
3131 if (element_type == DEBUG_TYPE_NULL)
3132 return DEBUG_TYPE_NULL;
3140 return debug_make_array_type (dhandle, element_type, index_type, lower,
3144 /* This struct holds information about files we have seen using
3149 /* The next N_BINCL file. */
3150 struct bincl_file *next;
3151 /* The next N_BINCL on the stack. */
3152 struct bincl_file *next_stack;
3153 /* The file name. */
3155 /* The hash value. */
3157 /* The file index. */
3159 /* The list of types defined in this file. */
3160 struct stab_types *file_types;
3163 /* Start a new N_BINCL file, pushing it onto the stack. */
3166 push_bincl (struct stab_handle *info, const char *name, bfd_vma hash)
3168 struct bincl_file *n;
3170 n = (struct bincl_file *) xmalloc (sizeof *n);
3171 n->next = info->bincl_list;
3172 n->next_stack = info->bincl_stack;
3175 n->file = info->files;
3176 n->file_types = NULL;
3177 info->bincl_list = n;
3178 info->bincl_stack = n;
3181 info->file_types = ((struct stab_types **)
3182 xrealloc (info->file_types,
3184 * sizeof *info->file_types)));
3185 info->file_types[n->file] = NULL;
3188 /* Finish an N_BINCL file, at an N_EINCL, popping the name off the
3192 pop_bincl (struct stab_handle *info)
3194 struct bincl_file *o;
3196 o = info->bincl_stack;
3198 return info->main_filename;
3199 info->bincl_stack = o->next_stack;
3201 o->file_types = info->file_types[o->file];
3203 if (info->bincl_stack == NULL)
3204 return info->main_filename;
3205 return info->bincl_stack->name;
3208 /* Handle an N_EXCL: get the types from the corresponding N_BINCL. */
3211 find_excl (struct stab_handle *info, const char *name, bfd_vma hash)
3213 struct bincl_file *l;
3216 info->file_types = ((struct stab_types **)
3217 xrealloc (info->file_types,
3219 * sizeof *info->file_types)));
3221 for (l = info->bincl_list; l != NULL; l = l->next)
3222 if (l->hash == hash && strcmp (l->name, name) == 0)
3226 warn_stab (name, _("Undefined N_EXCL"));
3227 info->file_types[info->files - 1] = NULL;
3231 info->file_types[info->files - 1] = l->file_types;
3236 /* Handle a variable definition. gcc emits variable definitions for a
3237 block before the N_LBRAC, so we must hold onto them until we see
3238 it. The SunPRO compiler emits variable definitions after the
3239 N_LBRAC, so we can call debug_record_variable immediately. */
3242 stab_record_variable (void *dhandle, struct stab_handle *info,
3243 const char *name, debug_type type,
3244 enum debug_var_kind kind, bfd_vma val)
3246 struct stab_pending_var *v;
3248 if ((kind == DEBUG_GLOBAL || kind == DEBUG_STATIC)
3249 || ! info->within_function
3250 || (info->gcc_compiled == 0 && info->n_opt_found))
3251 return debug_record_variable (dhandle, name, type, kind, val);
3253 v = (struct stab_pending_var *) xmalloc (sizeof *v);
3254 memset (v, 0, sizeof *v);
3256 v->next = info->pending;
3266 /* Emit pending variable definitions. This is called after we see the
3267 N_LBRAC that starts the block. */
3270 stab_emit_pending_vars (void *dhandle, struct stab_handle *info)
3272 struct stab_pending_var *v;
3277 struct stab_pending_var *next;
3279 if (! debug_record_variable (dhandle, v->name, v->type, v->kind, v->val))
3287 info->pending = NULL;
3292 /* Find the slot for a type in the database. */
3295 stab_find_slot (struct stab_handle *info, const int *typenums)
3299 struct stab_types **ps;
3301 filenum = typenums[0];
3302 tindex = typenums[1];
3304 if (filenum < 0 || (unsigned int) filenum >= info->files)
3306 fprintf (stderr, _("Type file number %d out of range\n"), filenum);
3311 fprintf (stderr, _("Type index number %d out of range\n"), tindex);
3315 ps = info->file_types + filenum;
3317 while (tindex >= STAB_TYPES_SLOTS)
3321 *ps = (struct stab_types *) xmalloc (sizeof **ps);
3322 memset (*ps, 0, sizeof **ps);
3325 tindex -= STAB_TYPES_SLOTS;
3329 *ps = (struct stab_types *) xmalloc (sizeof **ps);
3330 memset (*ps, 0, sizeof **ps);
3333 return (*ps)->types + tindex;
3336 /* Find a type given a type number. If the type has not been
3337 allocated yet, create an indirect type. */
3340 stab_find_type (void *dhandle, struct stab_handle *info, const int *typenums)
3344 if (typenums[0] == 0 && typenums[1] < 0)
3346 /* A negative type number indicates an XCOFF builtin type. */
3347 return stab_xcoff_builtin_type (dhandle, info, typenums[1]);
3350 slot = stab_find_slot (info, typenums);
3352 return DEBUG_TYPE_NULL;
3354 if (*slot == DEBUG_TYPE_NULL)
3355 return debug_make_indirect_type (dhandle, slot, (const char *) NULL);
3360 /* Record that a given type number refers to a given type. */
3363 stab_record_type (void *dhandle ATTRIBUTE_UNUSED, struct stab_handle *info,
3364 const int *typenums, debug_type type)
3368 slot = stab_find_slot (info, typenums);
3372 /* gdb appears to ignore type redefinitions, so we do as well. */
3379 /* Return an XCOFF builtin type. */
3382 stab_xcoff_builtin_type (void *dhandle, struct stab_handle *info,
3388 if (typenum >= 0 || typenum < -XCOFF_TYPE_COUNT)
3390 fprintf (stderr, _("Unrecognized XCOFF type %d\n"), typenum);
3391 return DEBUG_TYPE_NULL;
3393 if (info->xcoff_types[-typenum] != NULL)
3394 return info->xcoff_types[-typenum];
3399 /* The size of this and all the other types are fixed, defined
3400 by the debugging format. */
3402 rettype = debug_make_int_type (dhandle, 4, FALSE);
3406 rettype = debug_make_int_type (dhandle, 1, FALSE);
3410 rettype = debug_make_int_type (dhandle, 2, FALSE);
3414 rettype = debug_make_int_type (dhandle, 4, FALSE);
3417 name = "unsigned char";
3418 rettype = debug_make_int_type (dhandle, 1, TRUE);
3421 name = "signed char";
3422 rettype = debug_make_int_type (dhandle, 1, FALSE);
3425 name = "unsigned short";
3426 rettype = debug_make_int_type (dhandle, 2, TRUE);
3429 name = "unsigned int";
3430 rettype = debug_make_int_type (dhandle, 4, TRUE);
3434 rettype = debug_make_int_type (dhandle, 4, TRUE);
3436 name = "unsigned long";
3437 rettype = debug_make_int_type (dhandle, 4, TRUE);
3441 rettype = debug_make_void_type (dhandle);
3444 /* IEEE single precision (32 bit). */
3446 rettype = debug_make_float_type (dhandle, 4);
3449 /* IEEE double precision (64 bit). */
3451 rettype = debug_make_float_type (dhandle, 8);
3454 /* This is an IEEE double on the RS/6000, and different machines
3455 with different sizes for "long double" should use different
3456 negative type numbers. See stabs.texinfo. */
3457 name = "long double";
3458 rettype = debug_make_float_type (dhandle, 8);
3462 rettype = debug_make_int_type (dhandle, 4, FALSE);
3466 rettype = debug_make_bool_type (dhandle, 4);
3469 name = "short real";
3470 rettype = debug_make_float_type (dhandle, 4);
3474 rettype = debug_make_float_type (dhandle, 8);
3484 rettype = debug_make_int_type (dhandle, 1, TRUE);
3488 rettype = debug_make_bool_type (dhandle, 1);
3492 rettype = debug_make_bool_type (dhandle, 2);
3496 rettype = debug_make_bool_type (dhandle, 4);
3500 rettype = debug_make_bool_type (dhandle, 4);
3503 /* Complex type consisting of two IEEE single precision values. */
3505 rettype = debug_make_complex_type (dhandle, 8);
3508 /* Complex type consisting of two IEEE double precision values. */
3509 name = "double complex";
3510 rettype = debug_make_complex_type (dhandle, 16);
3514 rettype = debug_make_int_type (dhandle, 1, FALSE);
3518 rettype = debug_make_int_type (dhandle, 2, FALSE);
3522 rettype = debug_make_int_type (dhandle, 4, FALSE);
3527 rettype = debug_make_int_type (dhandle, 2, FALSE);
3531 rettype = debug_make_int_type (dhandle, 8, FALSE);
3534 name = "unsigned long long";
3535 rettype = debug_make_int_type (dhandle, 8, TRUE);
3539 rettype = debug_make_bool_type (dhandle, 8);
3543 rettype = debug_make_int_type (dhandle, 8, FALSE);
3549 rettype = debug_name_type (dhandle, name, rettype);
3551 info->xcoff_types[-typenum] = rettype;
3556 /* Find or create a tagged type. */
3559 stab_find_tagged_type (void *dhandle, struct stab_handle *info,
3560 const char *p, int len, enum debug_type_kind kind)
3564 struct stab_tag *st;
3566 name = savestring (p, len);
3568 /* We pass DEBUG_KIND_ILLEGAL because we want all tags in the same
3569 namespace. This is right for C, and I don't know how to handle
3570 other languages. FIXME. */
3571 dtype = debug_find_tagged_type (dhandle, name, DEBUG_KIND_ILLEGAL);
3572 if (dtype != DEBUG_TYPE_NULL)
3578 /* We need to allocate an entry on the undefined tag list. */
3579 for (st = info->tags; st != NULL; st = st->next)
3581 if (st->name[0] == name[0]
3582 && strcmp (st->name, name) == 0)
3584 if (st->kind == DEBUG_KIND_ILLEGAL)
3592 st = (struct stab_tag *) xmalloc (sizeof *st);
3593 memset (st, 0, sizeof *st);
3595 st->next = info->tags;
3598 st->slot = DEBUG_TYPE_NULL;
3599 st->type = debug_make_indirect_type (dhandle, &st->slot, name);
3606 /* In order to get the correct argument types for a stubbed method, we
3607 need to extract the argument types from a C++ mangled string.
3608 Since the argument types can refer back to the return type, this
3609 means that we must demangle the entire physical name. In gdb this
3610 is done by calling cplus_demangle and running the results back
3611 through the C++ expression parser. Since we have no expression
3612 parser, we must duplicate much of the work of cplus_demangle here.
3614 We assume that GNU style demangling is used, since this is only
3615 done for method stubs, and only g++ should output that form of
3616 debugging information. */
3618 /* This structure is used to hold a pointer to type information which
3619 demangling a string. */
3621 struct stab_demangle_typestring
3623 /* The start of the type. This is not null terminated. */
3624 const char *typestring;
3625 /* The length of the type. */
3629 /* This structure is used to hold information while demangling a
3632 struct stab_demangle_info
3634 /* The debugging information handle. */
3636 /* The stab information handle. */
3637 struct stab_handle *info;
3638 /* The array of arguments we are building. */
3640 /* Whether the method takes a variable number of arguments. */
3641 bfd_boolean varargs;
3642 /* The array of types we have remembered. */
3643 struct stab_demangle_typestring *typestrings;
3644 /* The number of typestrings. */
3645 unsigned int typestring_count;
3646 /* The number of typestring slots we have allocated. */
3647 unsigned int typestring_alloc;
3650 static void stab_bad_demangle (const char *);
3651 static unsigned int stab_demangle_count (const char **);
3652 static bfd_boolean stab_demangle_get_count (const char **, unsigned int *);
3653 static bfd_boolean stab_demangle_prefix
3654 (struct stab_demangle_info *, const char **, unsigned int);
3655 static bfd_boolean stab_demangle_function_name
3656 (struct stab_demangle_info *, const char **, const char *);
3657 static bfd_boolean stab_demangle_signature
3658 (struct stab_demangle_info *, const char **);
3659 static bfd_boolean stab_demangle_qualified
3660 (struct stab_demangle_info *, const char **, debug_type *);
3661 static bfd_boolean stab_demangle_template
3662 (struct stab_demangle_info *, const char **, char **);
3663 static bfd_boolean stab_demangle_class
3664 (struct stab_demangle_info *, const char **, const char **);
3665 static bfd_boolean stab_demangle_args
3666 (struct stab_demangle_info *, const char **, debug_type **, bfd_boolean *);
3667 static bfd_boolean stab_demangle_arg
3668 (struct stab_demangle_info *, const char **, debug_type **,
3669 unsigned int *, unsigned int *);
3670 static bfd_boolean stab_demangle_type
3671 (struct stab_demangle_info *, const char **, debug_type *);
3672 static bfd_boolean stab_demangle_fund_type
3673 (struct stab_demangle_info *, const char **, debug_type *);
3674 static bfd_boolean stab_demangle_remember_type
3675 (struct stab_demangle_info *, const char *, int);
3677 /* Warn about a bad demangling. */
3680 stab_bad_demangle (const char *s)
3682 fprintf (stderr, _("bad mangled name `%s'\n"), s);
3685 /* Get a count from a stab string. */
3688 stab_demangle_count (const char **pp)
3693 while (ISDIGIT (**pp))
3696 count += **pp - '0';
3702 /* Require a count in a string. The count may be multiple digits, in
3703 which case it must end in an underscore. */
3706 stab_demangle_get_count (const char **pp, unsigned int *pi)
3708 if (! ISDIGIT (**pp))
3726 while (ISDIGIT (*p));
3737 /* This function demangles a physical name, returning a NULL
3738 terminated array of argument types. */
3741 stab_demangle_argtypes (void *dhandle, struct stab_handle *info,
3742 const char *physname, bfd_boolean *pvarargs,
3743 unsigned int physname_len)
3745 struct stab_demangle_info minfo;
3747 /* Check for the g++ V3 ABI. */
3748 if (physname[0] == '_' && physname[1] == 'Z')
3749 return stab_demangle_v3_argtypes (dhandle, info, physname, pvarargs);
3751 minfo.dhandle = dhandle;
3754 minfo.varargs = FALSE;
3755 minfo.typestring_alloc = 10;
3756 minfo.typestrings = ((struct stab_demangle_typestring *)
3757 xmalloc (minfo.typestring_alloc
3758 * sizeof *minfo.typestrings));
3759 minfo.typestring_count = 0;
3761 /* cplus_demangle checks for special GNU mangled forms, but we can't
3762 see any of them in mangled method argument types. */
3764 if (! stab_demangle_prefix (&minfo, &physname, physname_len))
3767 if (*physname != '\0')
3769 if (! stab_demangle_signature (&minfo, &physname))
3773 free (minfo.typestrings);
3774 minfo.typestrings = NULL;
3776 if (minfo.args == NULL)
3777 fprintf (stderr, _("no argument types in mangled string\n"));
3779 *pvarargs = minfo.varargs;
3783 if (minfo.typestrings != NULL)
3784 free (minfo.typestrings);
3788 /* Demangle the prefix of the mangled name. */
3791 stab_demangle_prefix (struct stab_demangle_info *minfo, const char **pp,
3792 unsigned int physname_len)
3797 /* cplus_demangle checks for global constructors and destructors,
3798 but we can't see them in mangled argument types. */
3801 scan = *pp + physname_len;
3804 /* Look for `__'. */
3807 scan = strchr (scan, '_');
3808 while (scan != NULL && *++scan != '_');
3812 stab_bad_demangle (*pp);
3818 /* We found `__'; move ahead to the last contiguous `__' pair. */
3819 i = strspn (scan, "_");
3825 && (ISDIGIT (scan[2])
3829 /* This is a GNU style constructor name. */
3833 else if (scan == *pp
3834 && ! ISDIGIT (scan[2])
3837 /* Look for the `__' that separates the prefix from the
3839 while (*scan == '_')
3841 scan = strstr (scan, "__");
3842 if (scan == NULL || scan[2] == '\0')
3844 stab_bad_demangle (*pp);
3848 return stab_demangle_function_name (minfo, pp, scan);
3850 else if (scan[2] != '\0')
3852 /* The name doesn't start with `__', but it does contain `__'. */
3853 return stab_demangle_function_name (minfo, pp, scan);
3857 stab_bad_demangle (*pp);
3863 /* Demangle a function name prefix. The scan argument points to the
3864 double underscore which separates the function name from the
3868 stab_demangle_function_name (struct stab_demangle_info *minfo,
3869 const char **pp, const char *scan)
3873 /* The string from *pp to scan is the name of the function. We
3874 don't care about the name, since we just looking for argument
3875 types. However, for conversion operators, the name may include a
3876 type which we must remember in order to handle backreferences. */
3882 && CONST_STRNEQ (name, "type")
3883 && (name[4] == '$' || name[4] == '.'))
3887 /* This is a type conversion operator. */
3889 if (! stab_demangle_type (minfo, &tem, (debug_type *) NULL))
3892 else if (name[0] == '_'
3899 /* This is a type conversion operator. */
3901 if (! stab_demangle_type (minfo, &tem, (debug_type *) NULL))
3908 /* Demangle the signature. This is where the argument types are
3912 stab_demangle_signature (struct stab_demangle_info *minfo, const char **pp)
3915 bfd_boolean expect_func, func_done;
3920 expect_func = FALSE;
3924 while (**pp != '\0')
3930 if (! stab_demangle_qualified (minfo, pp, (debug_type *) NULL)
3931 || ! stab_demangle_remember_type (minfo, hold, *pp - hold))
3938 /* Static member function. FIXME: Can this happen? */
3945 /* Const member function. */
3951 case '0': case '1': case '2': case '3': case '4':
3952 case '5': case '6': case '7': case '8': case '9':
3955 if (! stab_demangle_class (minfo, pp, (const char **) NULL)
3956 || ! stab_demangle_remember_type (minfo, hold, *pp - hold))
3963 /* Function. I don't know if this actually happens with g++
3968 if (! stab_demangle_args (minfo, pp, &minfo->args, &minfo->varargs))
3976 if (! stab_demangle_template (minfo, pp, (char **) NULL)
3977 || ! stab_demangle_remember_type (minfo, hold, *pp - hold))
3984 /* At the outermost level, we cannot have a return type
3985 specified, so if we run into another '_' at this point we
3986 are dealing with a mangled name that is either bogus, or
3987 has been mangled by some algorithm we don't know how to
3988 deal with. So just reject the entire demangling. */
3989 stab_bad_demangle (orig);
3993 /* Assume we have stumbled onto the first outermost function
3994 argument token, and start processing args. */
3996 if (! stab_demangle_args (minfo, pp, &minfo->args, &minfo->varargs))
4004 if (! stab_demangle_args (minfo, pp, &minfo->args, &minfo->varargs))
4011 /* With GNU style demangling, bar__3foo is 'foo::bar(void)', and
4012 bar__3fooi is 'foo::bar(int)'. We get here when we find the
4013 first case, and need to ensure that the '(void)' gets added
4014 to the current declp. */
4015 if (! stab_demangle_args (minfo, pp, &minfo->args, &minfo->varargs))
4022 /* Demangle a qualified name, such as "Q25Outer5Inner" which is the
4023 mangled form of "Outer::Inner". */
4026 stab_demangle_qualified (struct stab_demangle_info *minfo, const char **pp,
4031 unsigned int qualifiers;
4039 /* GNU mangled name with more than 9 classes. The count is
4040 preceded by an underscore (to distinguish it from the <= 9
4041 case) and followed by an underscore. */
4043 if (! ISDIGIT (*p) || *p == '0')
4045 stab_bad_demangle (orig);
4048 qualifiers = atoi (p);
4049 while (ISDIGIT (*p))
4053 stab_bad_demangle (orig);
4059 case '1': case '2': case '3': case '4': case '5':
4060 case '6': case '7': case '8': case '9':
4061 qualifiers = (*pp)[1] - '0';
4062 /* Skip an optional underscore after the count. */
4063 if ((*pp)[2] == '_')
4070 stab_bad_demangle (orig);
4074 context = DEBUG_TYPE_NULL;
4076 /* Pick off the names. */
4077 while (qualifiers-- > 0)
4085 if (! stab_demangle_template (minfo, pp,
4086 ptype != NULL ? &name : NULL))
4091 context = stab_find_tagged_type (minfo->dhandle, minfo->info,
4092 name, strlen (name),
4095 if (context == DEBUG_TYPE_NULL)
4103 len = stab_demangle_count (pp);
4104 if (strlen (*pp) < len)
4106 stab_bad_demangle (orig);
4112 const debug_field *fields;
4115 if (context != DEBUG_TYPE_NULL)
4116 fields = debug_get_fields (minfo->dhandle, context);
4118 context = DEBUG_TYPE_NULL;
4124 /* Try to find the type by looking through the
4125 fields of context until we find a field with the
4126 same type. This ought to work for a class
4127 defined within a class, but it won't work for,
4128 e.g., an enum defined within a class. stabs does
4129 not give us enough information to figure out the
4132 name = savestring (*pp, len);
4134 for (; *fields != DEBUG_FIELD_NULL; fields++)
4139 ft = debug_get_field_type (minfo->dhandle, *fields);
4145 dn = debug_get_type_name (minfo->dhandle, ft);
4146 if (dn != NULL && strcmp (dn, name) == 0)
4156 if (context == DEBUG_TYPE_NULL)
4158 /* We have to fall back on finding the type by name.
4159 If there are more types to come, then this must
4160 be a class. Otherwise, it could be anything. */
4162 if (qualifiers == 0)
4166 name = savestring (*pp, len);
4167 context = debug_find_named_type (minfo->dhandle,
4172 if (context == DEBUG_TYPE_NULL)
4174 context = stab_find_tagged_type (minfo->dhandle,
4178 ? DEBUG_KIND_ILLEGAL
4179 : DEBUG_KIND_CLASS));
4180 if (context == DEBUG_TYPE_NULL)
4196 /* Demangle a template. If PNAME is not NULL, this sets *PNAME to a
4197 string representation of the template. */
4200 stab_demangle_template (struct stab_demangle_info *minfo, const char **pp,
4210 /* Skip the template name. */
4211 r = stab_demangle_count (pp);
4212 if (r == 0 || strlen (*pp) < r)
4214 stab_bad_demangle (orig);
4219 /* Get the size of the parameter list. */
4220 if (stab_demangle_get_count (pp, &r) == 0)
4222 stab_bad_demangle (orig);
4226 for (i = 0; i < r; i++)
4230 /* This is a type parameter. */
4232 if (! stab_demangle_type (minfo, pp, (debug_type *) NULL))
4238 bfd_boolean pointerp, realp, integralp, charp, boolp;
4249 /* This is a value parameter. */
4251 if (! stab_demangle_type (minfo, pp, (debug_type *) NULL))
4254 while (*old_p != '\0' && ! done)
4264 case 'C': /* Const. */
4265 case 'S': /* Signed. */
4266 case 'U': /* Unsigned. */
4267 case 'V': /* Volatile. */
4268 case 'F': /* Function. */
4269 case 'M': /* Member function. */
4273 case 'Q': /* Qualified name. */
4277 case 'T': /* Remembered type. */
4279 case 'v': /* Void. */
4281 case 'x': /* Long long. */
4282 case 'l': /* Long. */
4283 case 'i': /* Int. */
4284 case 's': /* Short. */
4285 case 'w': /* Wchar_t. */
4289 case 'b': /* Bool. */
4293 case 'c': /* Char. */
4297 case 'r': /* Long double. */
4298 case 'd': /* Double. */
4299 case 'f': /* Float. */
4304 /* Assume it's a user defined integral type. */
4315 while (ISDIGIT (**pp))
4324 val = stab_demangle_count (pp);
4327 stab_bad_demangle (orig);
4335 val = stab_demangle_count (pp);
4336 if (val != 0 && val != 1)
4338 stab_bad_demangle (orig);
4346 while (ISDIGIT (**pp))
4351 while (ISDIGIT (**pp))
4357 while (ISDIGIT (**pp))
4365 len = stab_demangle_count (pp);
4368 stab_bad_demangle (orig);
4376 /* We can translate this to a string fairly easily by invoking the
4377 regular demangling routine. */
4380 char *s1, *s2, *s3, *s4 = NULL;
4383 s1 = savestring (orig, *pp - orig);
4385 s2 = concat ("NoSuchStrinG__", s1, (const char *) NULL);
4389 s3 = cplus_demangle (s2, DMGL_ANSI);
4394 s4 = strstr (s3, "::NoSuchStrinG");
4395 if (s3 == NULL || s4 == NULL)
4397 stab_bad_demangle (orig);
4403 /* Eliminating all spaces, except those between > characters,
4404 makes it more likely that the demangled name will match the
4405 name which g++ used as the structure name. */
4406 for (from = to = s3; from != s4; ++from)
4408 || (from[1] == '>' && from > s3 && from[-1] == '>'))
4411 *pname = savestring (s3, to - s3);
4419 /* Demangle a class name. */
4422 stab_demangle_class (struct stab_demangle_info *minfo ATTRIBUTE_UNUSED,
4423 const char **pp, const char **pstart)
4430 n = stab_demangle_count (pp);
4431 if (strlen (*pp) < n)
4433 stab_bad_demangle (orig);
4445 /* Demangle function arguments. If the pargs argument is not NULL, it
4446 is set to a NULL terminated array holding the arguments. */
4449 stab_demangle_args (struct stab_demangle_info *minfo, const char **pp,
4450 debug_type **pargs, bfd_boolean *pvarargs)
4453 unsigned int alloc, count;
4460 *pargs = (debug_type *) xmalloc (alloc * sizeof **pargs);
4465 while (**pp != '_' && **pp != '\0' && **pp != 'e')
4467 if (**pp == 'N' || **pp == 'T')
4475 if (temptype == 'T')
4479 if (! stab_demangle_get_count (pp, &r))
4481 stab_bad_demangle (orig);
4486 if (! stab_demangle_get_count (pp, &t))
4488 stab_bad_demangle (orig);
4492 if (t >= minfo->typestring_count)
4494 stab_bad_demangle (orig);
4501 tem = minfo->typestrings[t].typestring;
4502 if (! stab_demangle_arg (minfo, &tem, pargs, &count, &alloc))
4508 if (! stab_demangle_arg (minfo, pp, pargs, &count, &alloc))
4514 (*pargs)[count] = DEBUG_TYPE_NULL;
4526 /* Demangle a single argument. */
4529 stab_demangle_arg (struct stab_demangle_info *minfo, const char **pp,
4530 debug_type **pargs, unsigned int *pcount,
4531 unsigned int *palloc)
4537 if (! stab_demangle_type (minfo, pp,
4538 pargs == NULL ? (debug_type *) NULL : &type)
4539 || ! stab_demangle_remember_type (minfo, start, *pp - start))
4544 if (type == DEBUG_TYPE_NULL)
4547 if (*pcount + 1 >= *palloc)
4550 *pargs = ((debug_type *)
4551 xrealloc (*pargs, *palloc * sizeof **pargs));
4553 (*pargs)[*pcount] = type;
4560 /* Demangle a type. If the ptype argument is not NULL, *ptype is set
4561 to the newly allocated type. */
4564 stab_demangle_type (struct stab_demangle_info *minfo, const char **pp,
4575 /* A pointer type. */
4577 if (! stab_demangle_type (minfo, pp, ptype))
4580 *ptype = debug_make_pointer_type (minfo->dhandle, *ptype);
4584 /* A reference type. */
4586 if (! stab_demangle_type (minfo, pp, ptype))
4589 *ptype = debug_make_reference_type (minfo->dhandle, *ptype);
4599 while (**pp != '\0' && **pp != '_')
4601 if (! ISDIGIT (**pp))
4603 stab_bad_demangle (orig);
4612 stab_bad_demangle (orig);
4617 if (! stab_demangle_type (minfo, pp, ptype))
4621 debug_type int_type;
4623 int_type = debug_find_named_type (minfo->dhandle, "int");
4624 if (int_type == NULL)
4625 int_type = debug_make_int_type (minfo->dhandle, 4, FALSE);
4626 *ptype = debug_make_array_type (minfo->dhandle, *ptype, int_type,
4633 /* A back reference to a remembered type. */
4639 if (! stab_demangle_get_count (pp, &i))
4641 stab_bad_demangle (orig);
4644 if (i >= minfo->typestring_count)
4646 stab_bad_demangle (orig);
4649 p = minfo->typestrings[i].typestring;
4650 if (! stab_demangle_type (minfo, &p, ptype))
4659 bfd_boolean varargs;
4662 if (! stab_demangle_args (minfo, pp,
4664 ? (debug_type **) NULL
4667 ? (bfd_boolean *) NULL
4672 /* cplus_demangle will accept a function without a return
4673 type, but I don't know when that will happen, or what
4674 to do if it does. */
4675 stab_bad_demangle (orig);
4679 if (! stab_demangle_type (minfo, pp, ptype))
4682 *ptype = debug_make_function_type (minfo->dhandle, *ptype, args,
4691 bfd_boolean memberp;
4692 debug_type class_type = DEBUG_TYPE_NULL;
4694 bfd_boolean varargs;
4698 memberp = **pp == 'M';
4705 n = stab_demangle_count (pp);
4706 if (strlen (*pp) < n)
4708 stab_bad_demangle (orig);
4716 class_type = stab_find_tagged_type (minfo->dhandle,
4720 if (class_type == DEBUG_TYPE_NULL)
4724 else if (**pp == 'Q')
4726 if (! stab_demangle_qualified (minfo, pp,
4728 ? (debug_type *) NULL
4734 stab_bad_demangle (orig);
4744 else if (**pp == 'V')
4750 stab_bad_demangle (orig);
4754 if (! stab_demangle_args (minfo, pp,
4756 ? (debug_type **) NULL
4759 ? (bfd_boolean *) NULL
4766 stab_bad_demangle (orig);
4771 if (! stab_demangle_type (minfo, pp, ptype))
4777 *ptype = debug_make_offset_type (minfo->dhandle, class_type,
4781 /* FIXME: We have no way to record constp or
4783 *ptype = debug_make_method_type (minfo->dhandle, *ptype,
4784 class_type, args, varargs);
4792 if (! stab_demangle_type (minfo, pp, ptype))
4798 if (! stab_demangle_type (minfo, pp, ptype))
4801 *ptype = debug_make_const_type (minfo->dhandle, *ptype);
4806 if (! stab_demangle_qualified (minfo, pp, ptype))
4812 if (! stab_demangle_fund_type (minfo, pp, ptype))
4820 /* Demangle a fundamental type. If the ptype argument is not NULL,
4821 *ptype is set to the newly allocated type. */
4824 stab_demangle_fund_type (struct stab_demangle_info *minfo, const char **pp,
4828 bfd_boolean constp, volatilep, unsignedp, signedp;
4873 /* cplus_demangle permits this, but I don't know what it means. */
4874 stab_bad_demangle (orig);
4877 case 'v': /* void */
4880 *ptype = debug_find_named_type (minfo->dhandle, "void");
4881 if (*ptype == DEBUG_TYPE_NULL)
4882 *ptype = debug_make_void_type (minfo->dhandle);
4887 case 'x': /* long long */
4890 *ptype = debug_find_named_type (minfo->dhandle,
4892 ? "long long unsigned int"
4893 : "long long int"));
4894 if (*ptype == DEBUG_TYPE_NULL)
4895 *ptype = debug_make_int_type (minfo->dhandle, 8, unsignedp);
4900 case 'l': /* long */
4903 *ptype = debug_find_named_type (minfo->dhandle,
4905 ? "long unsigned int"
4907 if (*ptype == DEBUG_TYPE_NULL)
4908 *ptype = debug_make_int_type (minfo->dhandle, 4, unsignedp);
4916 *ptype = debug_find_named_type (minfo->dhandle,
4920 if (*ptype == DEBUG_TYPE_NULL)
4921 *ptype = debug_make_int_type (minfo->dhandle, 4, unsignedp);
4926 case 's': /* short */
4929 *ptype = debug_find_named_type (minfo->dhandle,
4931 ? "short unsigned int"
4933 if (*ptype == DEBUG_TYPE_NULL)
4934 *ptype = debug_make_int_type (minfo->dhandle, 2, unsignedp);
4939 case 'b': /* bool */
4942 *ptype = debug_find_named_type (minfo->dhandle, "bool");
4943 if (*ptype == DEBUG_TYPE_NULL)
4944 *ptype = debug_make_bool_type (minfo->dhandle, 4);
4949 case 'c': /* char */
4952 *ptype = debug_find_named_type (minfo->dhandle,
4958 if (*ptype == DEBUG_TYPE_NULL)
4959 *ptype = debug_make_int_type (minfo->dhandle, 1, unsignedp);
4964 case 'w': /* wchar_t */
4967 *ptype = debug_find_named_type (minfo->dhandle, "__wchar_t");
4968 if (*ptype == DEBUG_TYPE_NULL)
4969 *ptype = debug_make_int_type (minfo->dhandle, 2, TRUE);
4974 case 'r': /* long double */
4977 *ptype = debug_find_named_type (minfo->dhandle, "long double");
4978 if (*ptype == DEBUG_TYPE_NULL)
4979 *ptype = debug_make_float_type (minfo->dhandle, 8);
4984 case 'd': /* double */
4987 *ptype = debug_find_named_type (minfo->dhandle, "double");
4988 if (*ptype == DEBUG_TYPE_NULL)
4989 *ptype = debug_make_float_type (minfo->dhandle, 8);
4994 case 'f': /* float */
4997 *ptype = debug_find_named_type (minfo->dhandle, "float");
4998 if (*ptype == DEBUG_TYPE_NULL)
4999 *ptype = debug_make_float_type (minfo->dhandle, 4);
5006 if (! ISDIGIT (**pp))
5008 stab_bad_demangle (orig);
5012 case '0': case '1': case '2': case '3': case '4':
5013 case '5': case '6': case '7': case '8': case '9':
5017 if (! stab_demangle_class (minfo, pp, &hold))
5023 name = savestring (hold, *pp - hold);
5024 *ptype = debug_find_named_type (minfo->dhandle, name);
5026 if (*ptype == DEBUG_TYPE_NULL)
5028 /* FIXME: It is probably incorrect to assume that
5029 undefined types are tagged types. */
5030 *ptype = stab_find_tagged_type (minfo->dhandle, minfo->info,
5032 DEBUG_KIND_ILLEGAL);
5033 if (*ptype == DEBUG_TYPE_NULL)
5044 if (! stab_demangle_template (minfo, pp,
5045 ptype != NULL ? &name : NULL))
5049 *ptype = stab_find_tagged_type (minfo->dhandle, minfo->info,
5050 name, strlen (name),
5053 if (*ptype == DEBUG_TYPE_NULL)
5060 stab_bad_demangle (orig);
5067 *ptype = debug_make_const_type (minfo->dhandle, *ptype);
5069 *ptype = debug_make_volatile_type (minfo->dhandle, *ptype);
5075 /* Remember a type string in a demangled string. */
5078 stab_demangle_remember_type (struct stab_demangle_info *minfo,
5079 const char *p, int len)
5081 if (minfo->typestring_count >= minfo->typestring_alloc)
5083 minfo->typestring_alloc += 10;
5084 minfo->typestrings = ((struct stab_demangle_typestring *)
5085 xrealloc (minfo->typestrings,
5086 (minfo->typestring_alloc
5087 * sizeof *minfo->typestrings)));
5090 minfo->typestrings[minfo->typestring_count].typestring = p;
5091 minfo->typestrings[minfo->typestring_count].len = (unsigned int) len;
5092 ++minfo->typestring_count;
5097 /* Demangle names encoded using the g++ V3 ABI. The newer versions of
5098 g++ which use this ABI do not encode ordinary method argument types
5099 in a mangled name; they simply output the argument types. However,
5100 for a static method, g++ simply outputs the return type and the
5101 physical name. So in that case we need to demangle the name here.
5102 Here PHYSNAME is the physical name of the function, and we set the
5103 variable pointed at by PVARARGS to indicate whether this function
5104 is varargs. This returns NULL, or a NULL terminated array of
5108 stab_demangle_v3_argtypes (void *dhandle, struct stab_handle *info,
5109 const char *physname, bfd_boolean *pvarargs)
5111 struct demangle_component *dc;
5115 dc = cplus_demangle_v3_components (physname, DMGL_PARAMS | DMGL_ANSI, &mem);
5118 stab_bad_demangle (physname);
5122 /* We expect to see TYPED_NAME, and the right subtree describes the
5124 if (dc->type != DEMANGLE_COMPONENT_TYPED_NAME
5125 || dc->u.s_binary.right->type != DEMANGLE_COMPONENT_FUNCTION_TYPE)
5127 fprintf (stderr, _("Demangled name is not a function\n"));
5132 pargs = stab_demangle_v3_arglist (dhandle, info,
5133 dc->u.s_binary.right->u.s_binary.right,
5141 /* Demangle an argument list in a struct demangle_component tree.
5142 Returns a DEBUG_TYPE_NULL terminated array of argument types, and
5143 sets *PVARARGS to indicate whether this is a varargs function. */
5146 stab_demangle_v3_arglist (void *dhandle, struct stab_handle *info,
5147 struct demangle_component *arglist,
5148 bfd_boolean *pvarargs)
5150 struct demangle_component *dc;
5151 unsigned int alloc, count;
5155 pargs = (debug_type *) xmalloc (alloc * sizeof *pargs);
5162 dc = dc->u.s_binary.right)
5165 bfd_boolean varargs;
5167 if (dc->type != DEMANGLE_COMPONENT_ARGLIST)
5169 fprintf (stderr, _("Unexpected type in v3 arglist demangling\n"));
5174 /* PR 13925: Cope if the demangler returns an empty
5175 context for a function with no arguments. */
5176 if (dc->u.s_binary.left == NULL)
5179 arg = stab_demangle_v3_arg (dhandle, info, dc->u.s_binary.left,
5192 if (count + 1 >= alloc)
5195 pargs = (debug_type *) xrealloc (pargs, alloc * sizeof *pargs);
5202 pargs[count] = DEBUG_TYPE_NULL;
5207 /* Convert a struct demangle_component tree describing an argument
5208 type into a debug_type. */
5211 stab_demangle_v3_arg (void *dhandle, struct stab_handle *info,
5212 struct demangle_component *dc, debug_type context,
5213 bfd_boolean *pvarargs)
5217 if (pvarargs != NULL)
5222 /* FIXME: These are demangle component types which we probably
5223 need to handle one way or another. */
5224 case DEMANGLE_COMPONENT_LOCAL_NAME:
5225 case DEMANGLE_COMPONENT_TYPED_NAME:
5226 case DEMANGLE_COMPONENT_TEMPLATE_PARAM:
5227 case DEMANGLE_COMPONENT_CTOR:
5228 case DEMANGLE_COMPONENT_DTOR:
5229 case DEMANGLE_COMPONENT_JAVA_CLASS:
5230 case DEMANGLE_COMPONENT_RESTRICT_THIS:
5231 case DEMANGLE_COMPONENT_VOLATILE_THIS:
5232 case DEMANGLE_COMPONENT_CONST_THIS:
5233 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL:
5234 case DEMANGLE_COMPONENT_COMPLEX:
5235 case DEMANGLE_COMPONENT_IMAGINARY:
5236 case DEMANGLE_COMPONENT_VENDOR_TYPE:
5237 case DEMANGLE_COMPONENT_ARRAY_TYPE:
5238 case DEMANGLE_COMPONENT_PTRMEM_TYPE:
5239 case DEMANGLE_COMPONENT_ARGLIST:
5241 fprintf (stderr, _("Unrecognized demangle component %d\n"),
5245 case DEMANGLE_COMPONENT_NAME:
5246 if (context != NULL)
5248 const debug_field *fields;
5250 fields = debug_get_fields (dhandle, context);
5253 /* Try to find this type by looking through the context
5255 for (; *fields != DEBUG_FIELD_NULL; fields++)
5260 ft = debug_get_field_type (dhandle, *fields);
5263 dn = debug_get_type_name (dhandle, ft);
5265 && (int) strlen (dn) == dc->u.s_name.len
5266 && strncmp (dn, dc->u.s_name.s, dc->u.s_name.len) == 0)
5271 return stab_find_tagged_type (dhandle, info, dc->u.s_name.s,
5272 dc->u.s_name.len, DEBUG_KIND_ILLEGAL);
5274 case DEMANGLE_COMPONENT_QUAL_NAME:
5275 context = stab_demangle_v3_arg (dhandle, info, dc->u.s_binary.left,
5277 if (context == NULL)
5279 return stab_demangle_v3_arg (dhandle, info, dc->u.s_binary.right,
5282 case DEMANGLE_COMPONENT_TEMPLATE:
5287 /* We print this component to get a class name which we can
5288 use. FIXME: This probably won't work if the template uses
5289 template parameters which refer to an outer template. */
5290 p = cplus_demangle_print (DMGL_PARAMS | DMGL_ANSI, dc, 20, &alc);
5293 fprintf (stderr, _("Failed to print demangled template\n"));
5296 dt = stab_find_tagged_type (dhandle, info, p, strlen (p),
5302 case DEMANGLE_COMPONENT_SUB_STD:
5303 return stab_find_tagged_type (dhandle, info, dc->u.s_string.string,
5304 dc->u.s_string.len, DEBUG_KIND_ILLEGAL);
5306 case DEMANGLE_COMPONENT_RESTRICT:
5307 case DEMANGLE_COMPONENT_VOLATILE:
5308 case DEMANGLE_COMPONENT_CONST:
5309 case DEMANGLE_COMPONENT_POINTER:
5310 case DEMANGLE_COMPONENT_REFERENCE:
5311 dt = stab_demangle_v3_arg (dhandle, info, dc->u.s_binary.left, NULL,
5320 case DEMANGLE_COMPONENT_RESTRICT:
5321 /* FIXME: We have no way to represent restrict. */
5323 case DEMANGLE_COMPONENT_VOLATILE:
5324 return debug_make_volatile_type (dhandle, dt);
5325 case DEMANGLE_COMPONENT_CONST:
5326 return debug_make_const_type (dhandle, dt);
5327 case DEMANGLE_COMPONENT_POINTER:
5328 return debug_make_pointer_type (dhandle, dt);
5329 case DEMANGLE_COMPONENT_REFERENCE:
5330 return debug_make_reference_type (dhandle, dt);
5333 case DEMANGLE_COMPONENT_FUNCTION_TYPE:
5336 bfd_boolean varargs;
5338 if (dc->u.s_binary.left == NULL)
5340 /* In this case the return type is actually unknown.
5341 However, I'm not sure this will ever arise in practice;
5342 normally an unknown return type would only appear at
5343 the top level, which is handled above. */
5344 dt = debug_make_void_type (dhandle);
5347 dt = stab_demangle_v3_arg (dhandle, info, dc->u.s_binary.left, NULL,
5352 pargs = stab_demangle_v3_arglist (dhandle, info,
5353 dc->u.s_binary.right,
5358 return debug_make_function_type (dhandle, dt, pargs, varargs);
5361 case DEMANGLE_COMPONENT_BUILTIN_TYPE:
5367 /* We print this component in order to find out the type name.
5368 FIXME: Should we instead expose the
5369 demangle_builtin_type_info structure? */
5370 p = cplus_demangle_print (DMGL_PARAMS | DMGL_ANSI, dc, 20, &alc);
5373 fprintf (stderr, _("Couldn't get demangled builtin type\n"));
5377 /* The mangling is based on the type, but does not itself
5378 indicate what the sizes are. So we have to guess. */
5379 if (strcmp (p, "signed char") == 0)
5380 ret = debug_make_int_type (dhandle, 1, FALSE);
5381 else if (strcmp (p, "bool") == 0)
5382 ret = debug_make_bool_type (dhandle, 1);
5383 else if (strcmp (p, "char") == 0)
5384 ret = debug_make_int_type (dhandle, 1, FALSE);
5385 else if (strcmp (p, "double") == 0)
5386 ret = debug_make_float_type (dhandle, 8);
5387 else if (strcmp (p, "long double") == 0)
5388 ret = debug_make_float_type (dhandle, 8);
5389 else if (strcmp (p, "float") == 0)
5390 ret = debug_make_float_type (dhandle, 4);
5391 else if (strcmp (p, "__float128") == 0)
5392 ret = debug_make_float_type (dhandle, 16);
5393 else if (strcmp (p, "unsigned char") == 0)
5394 ret = debug_make_int_type (dhandle, 1, TRUE);
5395 else if (strcmp (p, "int") == 0)
5396 ret = debug_make_int_type (dhandle, 4, FALSE);
5397 else if (strcmp (p, "unsigned int") == 0)
5398 ret = debug_make_int_type (dhandle, 4, TRUE);
5399 else if (strcmp (p, "long") == 0)
5400 ret = debug_make_int_type (dhandle, 4, FALSE);
5401 else if (strcmp (p, "unsigned long") == 0)
5402 ret = debug_make_int_type (dhandle, 4, TRUE);
5403 else if (strcmp (p, "__int128") == 0)
5404 ret = debug_make_int_type (dhandle, 16, FALSE);
5405 else if (strcmp (p, "unsigned __int128") == 0)
5406 ret = debug_make_int_type (dhandle, 16, TRUE);
5407 else if (strcmp (p, "short") == 0)
5408 ret = debug_make_int_type (dhandle, 2, FALSE);
5409 else if (strcmp (p, "unsigned short") == 0)
5410 ret = debug_make_int_type (dhandle, 2, TRUE);
5411 else if (strcmp (p, "void") == 0)
5412 ret = debug_make_void_type (dhandle);
5413 else if (strcmp (p, "wchar_t") == 0)
5414 ret = debug_make_int_type (dhandle, 4, TRUE);
5415 else if (strcmp (p, "long long") == 0)
5416 ret = debug_make_int_type (dhandle, 8, FALSE);
5417 else if (strcmp (p, "unsigned long long") == 0)
5418 ret = debug_make_int_type (dhandle, 8, TRUE);
5419 else if (strcmp (p, "...") == 0)
5421 if (pvarargs == NULL)
5422 fprintf (stderr, _("Unexpected demangled varargs\n"));
5429 fprintf (stderr, _("Unrecognized demangled builtin type\n"));