1 /* stabs.c -- Parse stabs debugging information
2 Copyright (C) 1995, 1996 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 2 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., 59 Temple Place - Suite 330, 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. */
32 #include "libiberty.h"
37 /* Meaningless definition needs by aout64.h. FIXME. */
38 #define BYTES_IN_WORD 4
40 #include "aout/aout64.h"
41 #include "aout/stab_gnu.h"
43 /* The number of predefined XCOFF types. */
45 #define XCOFF_TYPE_COUNT 34
47 /* This structure is used as a handle so that the stab parsing doesn't
48 need to use any static variables. */
52 /* True if this is stabs in sections. */
54 /* The symbol table. */
56 /* The number of symbols. */
58 /* The accumulated file name string. */
60 /* The value of the last N_SO symbol. */
62 /* The value of the start of the file, so that we can handle file
63 relative N_LBRAC and N_RBRAC symbols. */
64 bfd_vma file_start_offset;
65 /* The offset of the start of the function, so that we can handle
66 function relative N_LBRAC and N_RBRAC symbols. */
67 bfd_vma function_start_offset;
68 /* The version number of gcc which compiled the current compilation
69 unit, 0 if not compiled by gcc. */
71 /* Whether an N_OPT symbol was seen that was not generated by gcc,
72 so that we can detect the SunPRO compiler. */
74 /* The main file name. */
76 /* A stack of N_BINCL files. */
77 struct bincl_file *bincl_stack;
78 /* Whether we are inside a function or not. */
79 boolean within_function;
80 /* The depth of block nesting. */
82 /* List of pending variable definitions. */
83 struct stab_pending_var *pending;
84 /* Number of files for which we have types. */
86 /* Lists of types per file. */
87 struct stab_types **file_types;
88 /* Predefined XCOFF types. */
89 debug_type xcoff_types[XCOFF_TYPE_COUNT];
91 struct stab_tag *tags;
94 /* A list of these structures is used to hold pending variable
95 definitions seen before the N_LBRAC of a block. */
97 struct stab_pending_var
99 /* Next pending variable definition. */
100 struct stab_pending_var *next;
106 enum debug_var_kind kind;
111 /* A list of these structures is used to hold the types for a single
116 /* Next set of slots for this file. */
117 struct stab_types *next;
118 /* Types indexed by type number. */
119 #define STAB_TYPES_SLOTS (16)
120 debug_type types[STAB_TYPES_SLOTS];
123 /* We keep a list of undefined tags that we encounter, so that we can
124 fill them in if the tag is later defined. */
128 /* Next undefined tag. */
129 struct stab_tag *next;
133 enum debug_type_kind kind;
134 /* Slot to hold real type when we discover it. If we don't, we fill
135 in an undefined tag type. */
137 /* Indirect type we have created to point at slot. */
141 static char *savestring PARAMS ((const char *, int));
142 static bfd_vma parse_number PARAMS ((const char **, boolean *));
143 static void bad_stab PARAMS ((const char *));
144 static void warn_stab PARAMS ((const char *, const char *));
145 static boolean parse_stab_string
146 PARAMS ((PTR, struct stab_handle *, int, int, bfd_vma, const char *));
147 static debug_type parse_stab_type
148 PARAMS ((PTR, struct stab_handle *, const char *, const char **,
150 static boolean parse_stab_type_number
151 PARAMS ((const char **, int *));
152 static debug_type parse_stab_range_type
153 PARAMS ((PTR, struct stab_handle *, const char *, const char **,
155 static debug_type parse_stab_sun_builtin_type PARAMS ((PTR, const char **));
156 static debug_type parse_stab_sun_floating_type
157 PARAMS ((PTR, const char **));
158 static debug_type parse_stab_enum_type PARAMS ((PTR, const char **));
159 static debug_type parse_stab_struct_type
160 PARAMS ((PTR, struct stab_handle *, const char *, const char **, boolean,
162 static boolean parse_stab_baseclasses
163 PARAMS ((PTR, struct stab_handle *, const char **, debug_baseclass **));
164 static boolean parse_stab_struct_fields
165 PARAMS ((PTR, struct stab_handle *, const char **, debug_field **,
167 static boolean parse_stab_cpp_abbrev
168 PARAMS ((PTR, struct stab_handle *, const char **, debug_field *));
169 static boolean parse_stab_one_struct_field
170 PARAMS ((PTR, struct stab_handle *, const char **, const char *,
171 debug_field *, boolean *));
172 static boolean parse_stab_members
173 PARAMS ((PTR, struct stab_handle *, const char *, const char **,
174 const int *, debug_method **));
175 static debug_type parse_stab_argtypes
176 PARAMS ((PTR, struct stab_handle *, debug_type, const char *, const char *,
177 debug_type, const char *, boolean, boolean, const char **));
178 static boolean parse_stab_tilde_field
179 PARAMS ((PTR, struct stab_handle *, const char **, const int *,
180 debug_type *, boolean *));
181 static debug_type parse_stab_array_type
182 PARAMS ((PTR, struct stab_handle *, const char **, boolean));
183 static void push_bincl PARAMS ((struct stab_handle *, const char *));
184 static const char *pop_bincl PARAMS ((struct stab_handle *));
185 static boolean stab_record_variable
186 PARAMS ((PTR, struct stab_handle *, const char *, debug_type,
187 enum debug_var_kind, bfd_vma));
188 static boolean stab_emit_pending_vars PARAMS ((PTR, struct stab_handle *));
189 static debug_type *stab_find_slot
190 PARAMS ((struct stab_handle *, const int *));
191 static debug_type stab_find_type
192 PARAMS ((PTR, struct stab_handle *, const int *));
193 static boolean stab_record_type
194 PARAMS ((PTR, struct stab_handle *, const int *, debug_type));
195 static debug_type stab_xcoff_builtin_type
196 PARAMS ((PTR, struct stab_handle *, int));
197 static debug_type stab_find_tagged_type
198 PARAMS ((PTR, struct stab_handle *, const char *, int,
199 enum debug_type_kind));
200 static debug_type *stab_demangle_argtypes
201 PARAMS ((PTR, struct stab_handle *, const char *, boolean *));
203 /* Save a string in memory. */
206 savestring (start, len)
212 ret = (char *) xmalloc (len + 1);
213 memcpy (ret, start, len);
218 /* Read a number from a string. */
221 parse_number (pp, poverflow)
228 if (poverflow != NULL)
234 ul = strtoul (*pp, (char **) pp, 0);
235 if (ul + 1 != 0 || errno == 0)
238 /* Note that even though strtoul overflowed, it should have set *pp
239 to the end of the number, which is where we want it. */
241 if (sizeof (bfd_vma) > sizeof (unsigned long))
246 bfd_vma over, lastdig;
250 /* Our own version of strtoul, for a bfd_vma. */
266 if (p[1] == 'x' || p[1] == 'X')
278 over = ((bfd_vma) (bfd_signed_vma) -1) / (bfd_vma) base;
279 lastdig = ((bfd_vma) (bfd_signed_vma) -1) % (bfd_vma) base;
288 if (isdigit ((unsigned char) d))
290 else if (isupper ((unsigned char) d))
292 else if (islower ((unsigned char) d))
300 if (v > over || (v == over && (bfd_vma) d > lastdig))
315 /* If we get here, the number is too large to represent in a
318 if (poverflow != NULL)
321 warn_stab (orig, "numeric overflow");
326 /* Give an error for a bad stab string. */
332 fprintf (stderr, "Bad stab: %s\n", p);
335 /* Warn about something in a stab string. */
342 fprintf (stderr, "Warning: %s: %s\n", err, p);
345 /* Create a handle to parse stabs symbols with. */
349 start_stab (dhandle, sections, syms, symcount)
355 struct stab_handle *ret;
357 ret = (struct stab_handle *) xmalloc (sizeof *ret);
358 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;
368 /* When we have processed all the stabs information, we need to go
369 through and fill in all the undefined tags. */
372 finish_stab (dhandle, handle)
376 struct stab_handle *info = (struct stab_handle *) handle;
379 if (info->within_function)
381 if (! stab_emit_pending_vars (dhandle, info)
382 || ! debug_end_function (dhandle, (bfd_vma) -1))
384 info->within_function = false;
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 (dhandle, handle, type, desc, value, string)
413 struct stab_handle *info = (struct stab_handle *) handle;
415 /* gcc will emit two N_SO strings per compilation unit, one for the
416 directory name and one for the file name. We just collect N_SO
417 strings as we see them, and start the new compilation unit when
418 we see a non N_SO symbol. */
419 if (info->so_string != NULL
420 && (type != N_SO || *string == '\0' || value != info->so_value))
422 if (! debug_set_filename (dhandle, info->so_string))
424 info->main_filename = info->so_string;
426 info->gcc_compiled = 0;
427 info->n_opt_found = false;
429 /* Generally, for stabs in the symbol table, the N_LBRAC and
430 N_RBRAC symbols are relative to the N_SO symbol value. */
431 if (! info->sections)
432 info->file_start_offset = info->so_value;
434 /* We need to reset the mapping from type numbers to types. We
435 can't free the old mapping, because of the use of
436 debug_make_indirect_type. */
438 info->file_types = ((struct stab_types **)
439 xmalloc (sizeof *info->file_types));
440 info->file_types[0] = NULL;
442 info->so_string = NULL;
444 /* Now process whatever type we just got. */
454 /* Ignore extra outermost context from SunPRO cc and acc. */
455 if (info->n_opt_found && desc == 1)
458 if (! info->within_function)
460 fprintf (stderr, "N_LBRAC not within function\n");
464 /* Start an inner lexical block. */
465 if (! debug_start_block (dhandle,
467 + info->file_start_offset
468 + info->function_start_offset)))
471 /* Emit any pending variable definitions. */
472 if (! stab_emit_pending_vars (dhandle, info))
479 /* Ignore extra outermost context from SunPRO cc and acc. */
480 if (info->n_opt_found && desc == 1)
483 /* We shouldn't have any pending variable definitions here, but,
484 if we do, we probably need to emit them before closing the
486 if (! stab_emit_pending_vars (dhandle, info))
489 /* End an inner lexical block. */
490 if (! debug_end_block (dhandle,
492 + info->file_start_offset
493 + info->function_start_offset)))
497 if (info->block_depth < 0)
499 fprintf (stderr, "Too many N_RBRACs\n");
505 /* This always ends a function. */
506 if (info->within_function)
508 if (! stab_emit_pending_vars (dhandle, info)
509 || ! debug_end_function (dhandle, value))
511 info->within_function = false;
514 /* An empty string is emitted by gcc at the end of a compilation
519 /* Just accumulate strings until we see a non N_SO symbol. If
520 the string starts with '/', we discard the previously
521 accumulated strings. */
522 if (info->so_string == NULL)
523 info->so_string = xstrdup (string);
530 info->so_string = xstrdup (string);
532 info->so_string = concat (info->so_string, string,
533 (const char *) NULL);
537 info->so_value = value;
542 /* Start an include file. */
543 if (! debug_start_source (dhandle, string))
548 /* Start an include file which may be replaced. */
549 push_bincl (info, string);
550 if (! debug_start_source (dhandle, string))
555 /* End an N_BINCL include. */
556 if (! debug_start_source (dhandle, pop_bincl (info)))
561 /* This is a duplicate of a header file named by N_BINCL which
562 was eliminated by the linker. */
564 info->file_types = ((struct stab_types **)
565 xrealloc ((PTR) info->file_types,
567 * sizeof *info->file_types)));
568 info->file_types[info->files - 1] = NULL;
572 if (! debug_record_line (dhandle, desc,
573 value + info->function_start_offset))
578 if (! debug_start_common_block (dhandle, string))
583 if (! debug_end_common_block (dhandle, string))
587 /* FIXME: gdb checks the string for N_STSYM, N_LCSYM or N_ROSYM
588 symbols, and if it does not start with :S, gdb relocates the
589 value to the start of the section. gcc always seems to use
590 :S, so we don't worry about this. */
595 colon = strchr (string, ':');
597 && (colon[1] == 'f' || colon[1] == 'F'))
599 if (info->within_function)
601 if (! stab_emit_pending_vars (dhandle, info)
602 || ! debug_end_function (dhandle, value))
605 /* For stabs in sections, line numbers and block addresses
606 are offsets from the start of the function. */
608 info->function_start_offset = value;
609 info->within_function = true;
612 if (! parse_stab_string (dhandle, info, type, desc, value, string))
618 if (string != NULL && strcmp (string, "gcc2_compiled.") == 0)
619 info->gcc_compiled = 2;
620 else if (string != NULL && strcmp (string, "gcc_compiled.") == 0)
621 info->gcc_compiled = 1;
623 info->n_opt_found = true;
635 /* Parse the stabs string. */
638 parse_stab_string (dhandle, info, stabtype, desc, value, string)
640 struct stab_handle *info;
654 p = strchr (string, ':');
669 /* GCC 2.x puts the line number in desc. SunOS apparently puts in
670 the number of bytes occupied by a type or object, which we
672 if (info->gcc_compiled >= 2)
677 /* FIXME: Sometimes the special C++ names start with '.'. */
679 if (string[0] == '$')
687 /* Was: name = "vptr"; */
693 /* This was an anonymous type that was never fixed up. */
696 /* SunPRO (3.0 at least) static variable encoding. */
699 warn_stab (string, "unknown C++ encoded name");
706 if (p == string || (string[0] == ' ' && p == string + 1))
709 name = savestring (string, p - string);
713 if (isdigit ((unsigned char) *p) || *p == '(' || *p == '-')
721 /* c is a special case, not followed by a type-number.
722 SYMBOL:c=iVALUE for an integer constant symbol.
723 SYMBOL:c=rVALUE for a floating constant symbol.
724 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
725 e.g. "b:c=e6,0" for "const b = blob1"
726 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
736 /* Floating point constant. */
737 if (! debug_record_float_const (dhandle, name, atof (p)))
741 /* Integer constant. */
742 /* Defining integer constants this way is kind of silly,
743 since 'e' constants allows the compiler to give not only
744 the value, but the type as well. C has at least int,
745 long, unsigned int, and long long as constant types;
746 other languages probably should have at least unsigned as
747 well as signed constants. */
748 if (! debug_record_int_const (dhandle, name, atoi (p)))
752 /* SYMBOL:c=eTYPE,INTVALUE for a constant symbol whose value
753 can be represented as integral.
754 e.g. "b:c=e6,0" for "const b = blob1"
755 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
756 dtype = parse_stab_type (dhandle, info, (const char *) NULL,
757 &p, (debug_type **) NULL);
758 if (dtype == DEBUG_TYPE_NULL)
765 if (! debug_record_typed_const (dhandle, name, dtype, atoi (p)))
776 /* The name of a caught exception. */
777 dtype = parse_stab_type (dhandle, info, (const char *) NULL,
778 &p, (debug_type **) NULL);
779 if (dtype == DEBUG_TYPE_NULL)
781 if (! debug_record_label (dhandle, name, dtype, value))
787 /* A function definition. */
788 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
789 (debug_type **) NULL);
790 if (dtype == DEBUG_TYPE_NULL)
792 if (! debug_record_function (dhandle, name, dtype, type == 'F', value))
795 /* Sun acc puts declared types of arguments here. We don't care
796 about their actual types (FIXME -- we should remember the whole
797 function prototype), but the list may define some new types
798 that we have to remember, so we must scan it now. */
802 if (parse_stab_type (dhandle, info, (const char *) NULL, &p,
803 (debug_type **) NULL)
815 /* A global symbol. The value must be extracted from the
817 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
818 (debug_type **) NULL);
819 if (dtype == DEBUG_TYPE_NULL)
821 for (c = info->symcount, ps = info->syms; c > 0; --c, ++ps)
825 n = bfd_asymbol_name (*ps);
826 if (*n == *name && strcmp (n, name) == 0)
830 value = bfd_asymbol_value (*ps);
831 if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_GLOBAL,
837 /* This case is faked by a conditional above, when there is no
838 code letter in the dbx data. Dbx data never actually
842 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
843 (debug_type **) NULL);
844 if (dtype == DEBUG_TYPE_NULL)
846 if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_LOCAL,
852 /* A function parameter. */
854 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
855 (debug_type **) NULL);
858 /* pF is a two-letter code that means a function parameter in
859 Fortran. The type-number specifies the type of the return
860 value. Translate it into a pointer-to-function type. */
862 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
863 (debug_type **) NULL);
864 if (dtype != DEBUG_TYPE_NULL)
868 ftype = debug_make_function_type (dhandle, dtype,
869 (debug_type *) NULL, false);
870 dtype = debug_make_pointer_type (dhandle, ftype);
873 if (dtype == DEBUG_TYPE_NULL)
875 if (! debug_record_parameter (dhandle, name, dtype, DEBUG_PARM_STACK,
879 /* FIXME: At this point gdb considers rearranging the parameter
880 address on a big endian machine if it is smaller than an int.
881 We have no way to do that, since we don't really know much
887 if (stabtype == N_FUN)
889 /* Prototype of a function referenced by this file. */
893 if (parse_stab_type (dhandle, info, (const char *) NULL, &p,
894 (debug_type **) NULL)
902 /* Parameter which is in a register. */
903 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
904 (debug_type **) NULL);
905 if (dtype == DEBUG_TYPE_NULL)
907 if (! debug_record_parameter (dhandle, name, dtype, DEBUG_PARM_REG,
913 /* Register variable (either global or local). */
914 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
915 (debug_type **) NULL);
916 if (dtype == DEBUG_TYPE_NULL)
918 if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_REGISTER,
922 /* FIXME: At this point gdb checks to combine pairs of 'p' and
923 'r' stabs into a single 'P' stab. */
928 /* Static symbol at top level of file */
929 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
930 (debug_type **) NULL);
931 if (dtype == DEBUG_TYPE_NULL)
933 if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_STATIC,
940 dtype = parse_stab_type (dhandle, info, name, &p, &slot);
941 if (dtype == DEBUG_TYPE_NULL)
945 /* A nameless type. Nothing to do. */
949 dtype = debug_name_type (dhandle, name, dtype);
950 if (dtype == DEBUG_TYPE_NULL)
959 /* Struct, union, or enum tag. For GNU C++, this can be be followed
960 by 't' which means we are typedef'ing it as well. */
964 /* FIXME: gdb sets synonym to true if the current language
973 dtype = parse_stab_type (dhandle, info, name, &p, &slot);
974 if (dtype == DEBUG_TYPE_NULL)
979 dtype = debug_tag_type (dhandle, name, dtype);
980 if (dtype == DEBUG_TYPE_NULL)
985 /* See if we have a cross reference to this tag which we can now
988 register struct stab_tag **pst;
990 for (pst = &info->tags; *pst != NULL; pst = &(*pst)->next)
992 if ((*pst)->name[0] == name[0]
993 && strcmp ((*pst)->name, name) == 0)
995 (*pst)->slot = dtype;
1004 dtype = debug_name_type (dhandle, name, dtype);
1005 if (dtype == DEBUG_TYPE_NULL)
1015 /* Static symbol of local scope */
1016 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
1017 (debug_type **) NULL);
1018 if (dtype == DEBUG_TYPE_NULL)
1020 /* FIXME: gdb checks os9k_stabs here. */
1021 if (! stab_record_variable (dhandle, info, name, dtype,
1022 DEBUG_LOCAL_STATIC, value))
1027 /* Reference parameter. */
1028 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
1029 (debug_type **) NULL);
1030 if (dtype == DEBUG_TYPE_NULL)
1032 if (! debug_record_parameter (dhandle, name, dtype, DEBUG_PARM_REFERENCE,
1038 /* Reference parameter which is in a register. */
1039 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
1040 (debug_type **) NULL);
1041 if (dtype == DEBUG_TYPE_NULL)
1043 if (! debug_record_parameter (dhandle, name, dtype, DEBUG_PARM_REF_REG,
1049 /* This is used by Sun FORTRAN for "function result value".
1050 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
1051 that Pascal uses it too, but when I tried it Pascal used
1052 "x:3" (local symbol) instead. */
1053 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
1054 (debug_type **) NULL);
1055 if (dtype == DEBUG_TYPE_NULL)
1057 if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_LOCAL,
1067 /* FIXME: gdb converts structure values to structure pointers in a
1068 couple of cases, depending upon the target. */
1073 /* Parse a stabs type. The typename argument is non-NULL if this is a
1074 typedef or a tag definition. The pp argument points to the stab
1075 string, and is updated. The slotp argument points to a place to
1076 store the slot used if the type is being defined. */
1079 parse_stab_type (dhandle, info, typename, pp, slotp)
1081 struct stab_handle *info;
1082 const char *typename;
1101 /* Read type number if present. The type number may be omitted.
1102 for instance in a two-dimensional array declared with type
1103 "ar1;1;10;ar1;1;10;4". */
1104 if (! isdigit ((unsigned char) **pp) && **pp != '(' && **pp != '-')
1106 /* 'typenums=' not present, type is anonymous. Read and return
1107 the definition, but don't put it in the type vector. */
1108 typenums[0] = typenums[1] = -1;
1112 if (! parse_stab_type_number (pp, typenums))
1113 return DEBUG_TYPE_NULL;
1117 /* Type is not being defined here. Either it already
1118 exists, or this is a forward reference to it. */
1119 return stab_find_type (dhandle, info, typenums);
1122 /* Only set the slot if the type is being defined. This means
1123 that the mapping from type numbers to types will only record
1124 the name of the typedef which defines a type. If we don't do
1125 this, then something like
1128 will record that i is of type foo. Unfortunately, stabs
1129 information is ambiguous about variable types. For this code,
1133 the stabs information records both i and j as having the same
1134 type. This could be fixed by patching the compiler. */
1135 if (slotp != NULL && typenums[0] >= 0 && typenums[1] >= 0)
1136 *slotp = stab_find_slot (info, typenums);
1138 /* Type is being defined here. */
1144 const char *p = *pp + 1;
1147 if (isdigit ((unsigned char) *p) || *p == '(' || *p == '-')
1153 /* Type attributes. */
1156 for (; *p != ';'; ++p)
1161 return DEBUG_TYPE_NULL;
1169 size = atoi (attr + 1);
1179 /* Ignore unrecognized type attributes, so future
1180 compilers can invent new ones. */
1193 enum debug_type_kind code;
1194 const char *q1, *q2, *p;
1196 /* A cross reference to another type. */
1201 code = DEBUG_KIND_STRUCT;
1204 code = DEBUG_KIND_UNION;
1207 code = DEBUG_KIND_ENUM;
1210 /* Complain and keep going, so compilers can invent new
1211 cross-reference types. */
1212 warn_stab (orig, "unrecognized cross reference type");
1213 code = DEBUG_KIND_STRUCT;
1218 q1 = strchr (*pp, '<');
1219 p = strchr (*pp, ':');
1223 return DEBUG_TYPE_NULL;
1225 while (q1 != NULL && p > q1 && p[1] == ':')
1227 q2 = strchr (q1, '>');
1228 if (q2 == NULL || q2 < p)
1231 p = strchr (p, ':');
1235 return DEBUG_TYPE_NULL;
1239 dtype = stab_find_tagged_type (dhandle, info, *pp, p - *pp, code);
1261 /* This type is defined as another type. */
1266 /* Peek ahead at the number to detect void. */
1267 if (! parse_stab_type_number (pp, xtypenums))
1268 return DEBUG_TYPE_NULL;
1270 if (typenums[0] == xtypenums[0] && typenums[1] == xtypenums[1])
1272 /* This type is being defined as itself, which means that
1274 dtype = debug_make_void_type (dhandle);
1280 /* Go back to the number and have parse_stab_type get it.
1281 This means that we can deal with something like
1282 t(1,2)=(3,4)=... which the Lucid compiler uses. */
1283 dtype = parse_stab_type (dhandle, info, (const char *) NULL,
1284 pp, (debug_type **) NULL);
1285 if (dtype == DEBUG_TYPE_NULL)
1286 return DEBUG_TYPE_NULL;
1289 if (typenums[0] != -1)
1291 if (! stab_record_type (dhandle, info, typenums, dtype))
1292 return DEBUG_TYPE_NULL;
1299 dtype = debug_make_pointer_type (dhandle,
1300 parse_stab_type (dhandle, info,
1301 (const char *) NULL,
1303 (debug_type **) NULL));
1307 /* Reference to another type. */
1308 dtype = (debug_make_reference_type
1310 parse_stab_type (dhandle, info, (const char *) NULL, pp,
1311 (debug_type **) NULL)));
1315 /* Function returning another type. */
1316 /* FIXME: gdb checks os9k_stabs here. */
1317 dtype = (debug_make_function_type
1319 parse_stab_type (dhandle, info, (const char *) NULL, pp,
1320 (debug_type **) NULL),
1321 (debug_type *) NULL, false));
1325 /* Const qualifier on some type (Sun). */
1326 /* FIXME: gdb accepts 'c' here if os9k_stabs. */
1327 dtype = debug_make_const_type (dhandle,
1328 parse_stab_type (dhandle, info,
1329 (const char *) NULL,
1331 (debug_type **) NULL));
1335 /* Volatile qual on some type (Sun). */
1336 /* FIXME: gdb accepts 'i' here if os9k_stabs. */
1337 dtype = (debug_make_volatile_type
1339 parse_stab_type (dhandle, info, (const char *) NULL, pp,
1340 (debug_type **) NULL)));
1344 /* Offset (class & variable) type. This is used for a pointer
1345 relative to an object. */
1352 domain = parse_stab_type (dhandle, info, (const char *) NULL, pp,
1353 (debug_type **) NULL);
1354 if (domain == DEBUG_TYPE_NULL)
1355 return DEBUG_TYPE_NULL;
1360 return DEBUG_TYPE_NULL;
1364 memtype = parse_stab_type (dhandle, info, (const char *) NULL, pp,
1365 (debug_type **) NULL);
1366 if (memtype == DEBUG_TYPE_NULL)
1367 return DEBUG_TYPE_NULL;
1369 dtype = debug_make_offset_type (dhandle, domain, memtype);
1374 /* Method (class & fn) type. */
1377 debug_type return_type;
1380 return_type = parse_stab_type (dhandle, info, (const char *) NULL,
1381 pp, (debug_type **) NULL);
1382 if (return_type == DEBUG_TYPE_NULL)
1383 return DEBUG_TYPE_NULL;
1387 return DEBUG_TYPE_NULL;
1390 dtype = debug_make_method_type (dhandle, return_type,
1392 (debug_type *) NULL, false);
1397 debug_type return_type;
1403 domain = parse_stab_type (dhandle, info, (const char *) NULL,
1404 pp, (debug_type **) NULL);
1405 if (domain == DEBUG_TYPE_NULL)
1406 return DEBUG_TYPE_NULL;
1411 return DEBUG_TYPE_NULL;
1415 return_type = parse_stab_type (dhandle, info, (const char *) NULL,
1416 pp, (debug_type **) NULL);
1417 if (return_type == DEBUG_TYPE_NULL)
1418 return DEBUG_TYPE_NULL;
1421 args = (debug_type *) xmalloc (alloc * sizeof *args);
1428 return DEBUG_TYPE_NULL;
1435 args = ((debug_type *)
1436 xrealloc ((PTR) args, alloc * sizeof *args));
1439 args[n] = parse_stab_type (dhandle, info, (const char *) NULL,
1440 pp, (debug_type **) NULL);
1441 if (args[n] == DEBUG_TYPE_NULL)
1442 return DEBUG_TYPE_NULL;
1447 /* If the last type is not void, then this function takes a
1448 variable number of arguments. Otherwise, we must strip
1451 || debug_get_type_kind (dhandle, args[n - 1]) != DEBUG_KIND_VOID)
1459 args[n] = DEBUG_TYPE_NULL;
1461 dtype = debug_make_method_type (dhandle, return_type, domain, args,
1468 dtype = parse_stab_range_type (dhandle, info, typename, pp, typenums);
1472 /* FIXME: gdb checks os9k_stabs here. */
1473 /* Sun ACC builtin int type. */
1474 dtype = parse_stab_sun_builtin_type (dhandle, pp);
1478 /* Sun ACC builtin float type. */
1479 dtype = parse_stab_sun_floating_type (dhandle, pp);
1483 /* Enumeration type. */
1484 dtype = parse_stab_enum_type (dhandle, pp);
1489 /* Struct or union type. */
1490 dtype = parse_stab_struct_type (dhandle, info, typename, pp,
1491 descriptor == 's', typenums);
1499 return DEBUG_TYPE_NULL;
1503 dtype = parse_stab_array_type (dhandle, info, pp, stringp);
1507 dtype = debug_make_set_type (dhandle,
1508 parse_stab_type (dhandle, info,
1509 (const char *) NULL,
1511 (debug_type **) NULL),
1517 return DEBUG_TYPE_NULL;
1520 if (dtype == DEBUG_TYPE_NULL)
1521 return DEBUG_TYPE_NULL;
1523 if (typenums[0] != -1)
1525 if (! stab_record_type (dhandle, info, typenums, dtype))
1526 return DEBUG_TYPE_NULL;
1531 if (! debug_record_type_size (dhandle, dtype, (unsigned int) size))
1538 /* Read a number by which a type is referred to in dbx data, or
1539 perhaps read a pair (FILENUM, TYPENUM) in parentheses. Just a
1540 single number N is equivalent to (0,N). Return the two numbers by
1541 storing them in the vector TYPENUMS. */
1544 parse_stab_type_number (pp, typenums)
1555 typenums[1] = (int) parse_number (pp, (boolean *) NULL);
1560 typenums[0] = (int) parse_number (pp, (boolean *) NULL);
1567 typenums[1] = (int) parse_number (pp, (boolean *) NULL);
1579 /* Parse a range type. */
1582 parse_stab_range_type (dhandle, info, typename, pp, typenums)
1584 struct stab_handle *info;
1585 const char *typename;
1587 const int *typenums;
1591 boolean self_subrange;
1592 debug_type index_type;
1593 const char *s2, *s3;
1594 bfd_signed_vma n2, n3;
1599 index_type = DEBUG_TYPE_NULL;
1601 /* First comes a type we are a subrange of.
1602 In C it is usually 0, 1 or the type being defined. */
1603 if (! parse_stab_type_number (pp, rangenums))
1604 return DEBUG_TYPE_NULL;
1606 self_subrange = (rangenums[0] == typenums[0]
1607 && rangenums[1] == typenums[1]);
1612 index_type = parse_stab_type (dhandle, info, (const char *) NULL,
1613 pp, (debug_type **) NULL);
1614 if (index_type == DEBUG_TYPE_NULL)
1615 return DEBUG_TYPE_NULL;
1621 /* The remaining two operands are usually lower and upper bounds of
1622 the range. But in some special cases they mean something else. */
1624 n2 = parse_number (pp, &ov2);
1628 return DEBUG_TYPE_NULL;
1633 n3 = parse_number (pp, &ov3);
1637 return DEBUG_TYPE_NULL;
1643 /* gcc will emit range stabs for long long types. Handle this
1644 as a special case. FIXME: This needs to be more general. */
1645 #define LLLOW "01000000000000000000000;"
1646 #define LLHIGH "0777777777777777777777;"
1647 #define ULLHIGH "01777777777777777777777;"
1648 if (index_type == DEBUG_TYPE_NULL)
1650 if (strncmp (s2, LLLOW, sizeof LLLOW - 1) == 0
1651 && strncmp (s3, LLHIGH, sizeof LLHIGH - 1) == 0)
1652 return debug_make_int_type (dhandle, 8, false);
1655 && strncmp (s3, ULLHIGH, sizeof ULLHIGH - 1) == 0)
1656 return debug_make_int_type (dhandle, 8, true);
1659 warn_stab (orig, "numeric overflow");
1662 if (index_type == DEBUG_TYPE_NULL)
1664 /* A type defined as a subrange of itself, with both bounds 0,
1666 if (self_subrange && n2 == 0 && n3 == 0)
1667 return debug_make_void_type (dhandle);
1669 /* A type defined as a subrange of itself, with n2 positive and
1670 n3 zero, is a complex type, and n2 is the number of bytes. */
1671 if (self_subrange && n3 == 0 && n2 > 0)
1672 return debug_make_complex_type (dhandle, n2);
1674 /* If n3 is zero and n2 is positive, this is a floating point
1675 type, and n2 is the number of bytes. */
1676 if (n3 == 0 && n2 > 0)
1677 return debug_make_float_type (dhandle, n2);
1679 /* If the upper bound is -1, this is an unsigned int. */
1680 if (n2 == 0 && n3 == -1)
1682 /* When gcc is used with -gstabs, but not -gstabs+, it will emit
1683 long long int:t6=r1;0;-1;
1684 long long unsigned int:t7=r1;0;-1;
1685 We hack here to handle this reasonably. */
1686 if (typename != NULL)
1688 if (strcmp (typename, "long long int") == 0)
1689 return debug_make_int_type (dhandle, 8, false);
1690 else if (strcmp (typename, "long long unsigned int") == 0)
1691 return debug_make_int_type (dhandle, 8, true);
1693 /* FIXME: The size here really depends upon the target. */
1694 return debug_make_int_type (dhandle, 4, true);
1697 /* A range of 0 to 127 is char. */
1698 if (self_subrange && n2 == 0 && n3 == 127)
1699 return debug_make_int_type (dhandle, 1, false);
1701 /* FIXME: gdb checks for the language CHILL here. */
1706 return debug_make_int_type (dhandle, - n3, true);
1707 else if (n3 == 0xff)
1708 return debug_make_int_type (dhandle, 1, true);
1709 else if (n3 == 0xffff)
1710 return debug_make_int_type (dhandle, 2, true);
1711 /* -1 is used for the upper bound of (4 byte) "unsigned int"
1712 and "unsigned long", and we already checked for that, so
1713 don't need to test for it here. */
1717 && (self_subrange || n2 == -8))
1718 return debug_make_int_type (dhandle, - n2, true);
1719 else if (n2 == - n3 - 1)
1722 return debug_make_int_type (dhandle, 1, false);
1723 else if (n3 == 0x7fff)
1724 return debug_make_int_type (dhandle, 2, false);
1725 else if (n3 == 0x7fffffff)
1726 return debug_make_int_type (dhandle, 4, false);
1730 /* At this point I don't have the faintest idea how to deal with a
1731 self_subrange type; I'm going to assume that this is used as an
1732 idiom, and that all of them are special cases. So . . . */
1736 return DEBUG_TYPE_NULL;
1739 index_type = stab_find_type (dhandle, info, rangenums);
1740 if (index_type == DEBUG_TYPE_NULL)
1742 /* Does this actually ever happen? Is that why we are worrying
1743 about dealing with it rather than just calling error_type? */
1744 warn_stab (orig, "missing index type");
1745 index_type = debug_make_int_type (dhandle, 4, false);
1748 return debug_make_range_type (dhandle, index_type, n2, n3);
1751 /* Sun's ACC uses a somewhat saner method for specifying the builtin
1752 typedefs in every file (for int, long, etc):
1754 type = b <signed> <width>; <offset>; <nbits>
1755 signed = u or s. Possible c in addition to u or s (for char?).
1756 offset = offset from high order bit to start bit of type.
1757 width is # bytes in object of this type, nbits is # bits in type.
1759 The width/offset stuff appears to be for small objects stored in
1760 larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
1764 parse_stab_sun_builtin_type (dhandle, pp)
1784 return DEBUG_TYPE_NULL;
1788 /* For some odd reason, all forms of char put a c here. This is strange
1789 because no other type has this honor. We can safely ignore this because
1790 we actually determine 'char'acterness by the number of bits specified in
1795 /* The first number appears to be the number of bytes occupied
1796 by this type, except that unsigned short is 4 instead of 2.
1797 Since this information is redundant with the third number,
1798 we will ignore it. */
1799 (void) parse_number (pp, (boolean *) NULL);
1803 return DEBUG_TYPE_NULL;
1807 /* The second number is always 0, so ignore it too. */
1808 (void) parse_number (pp, (boolean *) NULL);
1812 return DEBUG_TYPE_NULL;
1816 /* The third number is the number of bits for this type. */
1817 bits = parse_number (pp, (boolean *) NULL);
1819 /* The type *should* end with a semicolon. If it are embedded
1820 in a larger type the semicolon may be the only way to know where
1821 the type ends. If this type is at the end of the stabstring we
1822 can deal with the omitted semicolon (but we don't have to like
1823 it). Don't bother to complain(), Sun's compiler omits the semicolon
1829 return debug_make_void_type (dhandle);
1831 return debug_make_int_type (dhandle, bits / 8, unsignedp);
1834 /* Parse a builtin floating type generated by the Sun compiler. */
1837 parse_stab_sun_floating_type (dhandle, pp)
1847 /* The first number has more details about the type, for example
1849 details = parse_number (pp, (boolean *) NULL);
1853 return DEBUG_TYPE_NULL;
1856 /* The second number is the number of bytes occupied by this type */
1857 bytes = parse_number (pp, (boolean *) NULL);
1861 return DEBUG_TYPE_NULL;
1864 if (details == NF_COMPLEX
1865 || details == NF_COMPLEX16
1866 || details == NF_COMPLEX32)
1867 return debug_make_complex_type (dhandle, bytes);
1869 return debug_make_float_type (dhandle, bytes);
1872 /* Handle an enum type. */
1875 parse_stab_enum_type (dhandle, pp)
1881 bfd_signed_vma *values;
1887 /* FIXME: gdb checks os9k_stabs here. */
1889 /* The aix4 compiler emits an extra field before the enum members;
1890 my guess is it's a type of some sort. Just ignore it. */
1898 /* Read the value-names and their values.
1899 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
1900 A semicolon or comma instead of a NAME means the end. */
1902 names = (const char **) xmalloc (alloc * sizeof *names);
1903 values = (bfd_signed_vma *) xmalloc (alloc * sizeof *values);
1905 while (**pp != '\0' && **pp != ';' && **pp != ',')
1915 name = savestring (*pp, p - *pp);
1918 val = (bfd_signed_vma) parse_number (pp, (boolean *) NULL);
1922 return DEBUG_TYPE_NULL;
1929 names = ((const char **)
1930 xrealloc ((PTR) names, alloc * sizeof *names));
1931 values = ((bfd_signed_vma *)
1932 xrealloc ((PTR) values, alloc * sizeof *values));
1946 return debug_make_enum_type (dhandle, names, values);
1949 /* Read the description of a structure (or union type) and return an object
1950 describing the type.
1952 PP points to a character pointer that points to the next unconsumed token
1953 in the the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;",
1954 *PP will point to "4a:1,0,32;;". */
1957 parse_stab_struct_type (dhandle, info, tagname, pp, structp, typenums)
1959 struct stab_handle *info;
1960 const char *tagname;
1963 const int *typenums;
1967 debug_baseclass *baseclasses;
1968 debug_field *fields;
1970 debug_method *methods;
1971 debug_type vptrbase;
1977 size = parse_number (pp, (boolean *) NULL);
1979 /* Get the other information. */
1980 if (! parse_stab_baseclasses (dhandle, info, pp, &baseclasses)
1981 || ! parse_stab_struct_fields (dhandle, info, pp, &fields, &statics)
1982 || ! parse_stab_members (dhandle, info, tagname, pp, typenums, &methods)
1983 || ! parse_stab_tilde_field (dhandle, info, pp, typenums, &vptrbase,
1985 return DEBUG_TYPE_NULL;
1988 && baseclasses == NULL
1990 && vptrbase == DEBUG_TYPE_NULL
1992 return debug_make_struct_type (dhandle, structp, size, fields);
1994 return debug_make_object_type (dhandle, structp, size, fields, baseclasses,
1995 methods, vptrbase, ownvptr);
1998 /* The stabs for C++ derived classes contain baseclass information which
1999 is marked by a '!' character after the total size. This function is
2000 called when we encounter the baseclass marker, and slurps up all the
2001 baseclass information.
2003 Immediately following the '!' marker is the number of base classes that
2004 the class is derived from, followed by information for each base class.
2005 For each base class, there are two visibility specifiers, a bit offset
2006 to the base class information within the derived class, a reference to
2007 the type for the base class, and a terminating semicolon.
2009 A typical example, with two base classes, would be "!2,020,19;0264,21;".
2011 Baseclass information marker __________________|| | | | | | |
2012 Number of baseclasses __________________________| | | | | | |
2013 Visibility specifiers (2) ________________________| | | | | |
2014 Offset in bits from start of class _________________| | | | |
2015 Type number for base class ___________________________| | | |
2016 Visibility specifiers (2) _______________________________| | |
2017 Offset in bits from start of class ________________________| |
2018 Type number of base class ____________________________________|
2020 Return true for success, false for failure. */
2023 parse_stab_baseclasses (dhandle, info, pp, retp)
2025 struct stab_handle *info;
2027 debug_baseclass **retp;
2031 debug_baseclass *classes;
2039 /* No base classes. */
2044 c = (unsigned int) parse_number (pp, (boolean *) NULL);
2053 classes = (debug_baseclass *) xmalloc ((c + 1) * sizeof (**retp));
2055 for (i = 0; i < c; i++)
2058 enum debug_visibility visibility;
2071 warn_stab (orig, "unknown virtual character for baseclass");
2080 visibility = DEBUG_VISIBILITY_PRIVATE;
2083 visibility = DEBUG_VISIBILITY_PROTECTED;
2086 visibility = DEBUG_VISIBILITY_PUBLIC;
2089 warn_stab (orig, "unknown visibility character for baseclass");
2090 visibility = DEBUG_VISIBILITY_PUBLIC;
2095 /* The remaining value is the bit offset of the portion of the
2096 object corresponding to this baseclass. Always zero in the
2097 absence of multiple inheritance. */
2098 bitpos = parse_number (pp, (boolean *) NULL);
2106 type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
2107 (debug_type **) NULL);
2108 if (type == DEBUG_TYPE_NULL)
2111 classes[i] = debug_make_baseclass (dhandle, type, bitpos, virtual,
2113 if (classes[i] == DEBUG_BASECLASS_NULL)
2121 classes[i] = DEBUG_BASECLASS_NULL;
2128 /* Read struct or class data fields. They have the form:
2130 NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
2132 At the end, we see a semicolon instead of a field.
2134 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
2137 The optional VISIBILITY is one of:
2139 '/0' (VISIBILITY_PRIVATE)
2140 '/1' (VISIBILITY_PROTECTED)
2141 '/2' (VISIBILITY_PUBLIC)
2142 '/9' (VISIBILITY_IGNORE)
2144 or nothing, for C style fields with public visibility.
2146 Returns 1 for success, 0 for failure. */
2149 parse_stab_struct_fields (dhandle, info, pp, retp, staticsp)
2151 struct stab_handle *info;
2158 debug_field *fields;
2169 fields = (debug_field *) xmalloc (alloc * sizeof *fields);
2172 /* FIXME: gdb checks os9k_stabs here. */
2176 /* Add 1 to c to leave room for NULL pointer at end. */
2180 fields = ((debug_field *)
2181 xrealloc ((PTR) fields, alloc * sizeof *fields));
2184 /* If it starts with CPLUS_MARKER it is a special abbreviation,
2185 unless the CPLUS_MARKER is followed by an underscore, in
2186 which case it is just the name of an anonymous type, which we
2187 should handle like any other type name. We accept either '$'
2188 or '.', because a field name can never contain one of these
2189 characters except as a CPLUS_MARKER. */
2191 if ((*p == '$' || *p == '.') && p[1] != '_')
2194 if (! parse_stab_cpp_abbrev (dhandle, info, pp, fields + c))
2200 /* Look for the ':' that separates the field name from the field
2201 values. Data members are delimited by a single ':', while member
2202 functions are delimited by a pair of ':'s. When we hit the member
2203 functions (if any), terminate scan loop and return. */
2205 p = strchr (p, ':');
2215 if (! parse_stab_one_struct_field (dhandle, info, pp, p, fields + c,
2222 fields[c] = DEBUG_FIELD_NULL;
2229 /* Special GNU C++ name. */
2232 parse_stab_cpp_abbrev (dhandle, info, pp, retp)
2234 struct stab_handle *info;
2242 const char *typename;
2246 *retp = DEBUG_FIELD_NULL;
2260 /* At this point, *pp points to something like "22:23=*22...", where
2261 the type number before the ':' is the "context" and everything
2262 after is a regular type definition. Lookup the type, find it's
2263 name, and construct the field name. */
2265 context = parse_stab_type (dhandle, info, (const char *) NULL, pp,
2266 (debug_type **) NULL);
2267 if (context == DEBUG_TYPE_NULL)
2273 /* $vf -- a virtual function table pointer. */
2277 /* $vb -- a virtual bsomethingorother */
2278 typename = debug_get_type_name (dhandle, context);
2279 if (typename == NULL)
2281 warn_stab (orig, "unnamed $vb type");
2284 name = concat ("_vb$", typename, (const char *) NULL);
2287 warn_stab (orig, "unrecognized C++ abbreviation");
2288 name = "INVALID_CPLUSPLUS_ABBREV";
2299 type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
2300 (debug_type **) NULL);
2308 bitpos = parse_number (pp, (boolean *) NULL);
2316 *retp = debug_make_field (dhandle, name, type, bitpos, 0,
2317 DEBUG_VISIBILITY_PRIVATE);
2318 if (*retp == DEBUG_FIELD_NULL)
2324 /* Parse a single field in a struct or union. */
2327 parse_stab_one_struct_field (dhandle, info, pp, p, retp, staticsp)
2329 struct stab_handle *info;
2337 enum debug_visibility visibility;
2344 /* FIXME: gdb checks ARM_DEMANGLING here. */
2346 name = savestring (*pp, p - *pp);
2351 visibility = DEBUG_VISIBILITY_PUBLIC;
2358 visibility = DEBUG_VISIBILITY_PRIVATE;
2361 visibility = DEBUG_VISIBILITY_PROTECTED;
2364 visibility = DEBUG_VISIBILITY_PUBLIC;
2367 warn_stab (orig, "unknown visibility character for field");
2368 visibility = DEBUG_VISIBILITY_PUBLIC;
2374 type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
2375 (debug_type **) NULL);
2376 if (type == DEBUG_TYPE_NULL)
2383 /* This is a static class member. */
2385 p = strchr (*pp, ';');
2392 varname = savestring (*pp, p - *pp);
2396 *retp = debug_make_static_member (dhandle, name, type, varname,
2410 bitpos = parse_number (pp, (boolean *) NULL);
2418 bitsize = parse_number (pp, (boolean *) NULL);
2426 if (bitpos == 0 && bitsize == 0)
2428 /* This can happen in two cases: (1) at least for gcc 2.4.5 or
2429 so, it is a field which has been optimized out. The correct
2430 stab for this case is to use VISIBILITY_IGNORE, but that is a
2431 recent invention. (2) It is a 0-size array. For example
2432 union { int num; char str[0]; } foo. Printing "<no value>"
2433 for str in "p foo" is OK, since foo.str (and thus foo.str[3])
2434 will continue to work, and a 0-size array as a whole doesn't
2435 have any contents to print.
2437 I suspect this probably could also happen with gcc -gstabs
2438 (not -gstabs+) for static fields, and perhaps other C++
2439 extensions. Hopefully few people use -gstabs with gdb, since
2440 it is intended for dbx compatibility. */
2441 visibility = DEBUG_VISIBILITY_IGNORE;
2444 /* FIXME: gdb does some stuff here to mark fields as unpacked. */
2446 *retp = debug_make_field (dhandle, name, type, bitpos, bitsize, visibility);
2451 /* Read member function stabs info for C++ classes. The form of each member
2454 NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;
2456 An example with two member functions is:
2458 afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;
2460 For the case of overloaded operators, the format is op$::*.funcs, where
2461 $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
2462 name (such as `+=') and `.' marks the end of the operator name. */
2465 parse_stab_members (dhandle, info, tagname, pp, typenums, retp)
2467 struct stab_handle *info;
2468 const char *tagname;
2470 const int *typenums;
2471 debug_method **retp;
2474 debug_method *methods;
2490 debug_method_variant *variants;
2492 unsigned int allocvars;
2493 debug_type look_ahead_type;
2495 p = strchr (*pp, ':');
2496 if (p == NULL || p[1] != ':')
2499 /* FIXME: Some systems use something other than '$' here. */
2500 if ((*pp)[0] != 'o' || (*pp)[1] != 'p' || (*pp)[2] != '$')
2502 name = savestring (*pp, p - *pp);
2507 /* This is a completely wierd case. In order to stuff in the
2508 names that might contain colons (the usual name delimiter),
2509 Mike Tiemann defined a different name format which is
2510 signalled if the identifier is "op$". In that case, the
2511 format is "op$::XXXX." where XXXX is the name. This is
2512 used for names like "+" or "=". YUUUUUUUK! FIXME! */
2514 for (p = *pp; *p != '.' && *p != '\0'; p++)
2521 name = savestring (*pp, p - *pp);
2526 variants = ((debug_method_variant *)
2527 xmalloc (allocvars * sizeof *variants));
2530 look_ahead_type = DEBUG_TYPE_NULL;
2536 enum debug_visibility visibility;
2537 boolean constp, volatilep, staticp;
2540 const char *physname;
2543 if (look_ahead_type != DEBUG_TYPE_NULL)
2545 /* g++ version 1 kludge */
2546 type = look_ahead_type;
2547 look_ahead_type = DEBUG_TYPE_NULL;
2551 type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
2552 (debug_type **) NULL);
2553 if (type == DEBUG_TYPE_NULL)
2563 p = strchr (*pp, ';');
2570 argtypes = savestring (*pp, p - *pp);
2576 visibility = DEBUG_VISIBILITY_PRIVATE;
2579 visibility = DEBUG_VISIBILITY_PROTECTED;
2582 visibility = DEBUG_VISIBILITY_PUBLIC;
2592 /* Normal function. */
2596 /* const member function. */
2601 /* volatile member function. */
2606 /* const volatile member function. */
2614 /* File compiled with g++ version 1; no information. */
2617 warn_stab (orig, "const/volatile indicator missing");
2625 /* virtual member function, followed by index. The sign
2626 bit is supposedly set to distinguish
2627 pointers-to-methods from virtual function indicies. */
2629 voffset = parse_number (pp, (boolean *) NULL);
2636 voffset &= 0x7fffffff;
2638 if (**pp == ';' || *pp == '\0')
2640 /* Must be g++ version 1. */
2641 context = DEBUG_TYPE_NULL;
2645 /* Figure out from whence this virtual function
2646 came. It may belong to virtual function table of
2647 one of its baseclasses. */
2648 look_ahead_type = parse_stab_type (dhandle, info,
2649 (const char *) NULL,
2651 (debug_type **) NULL);
2654 /* g++ version 1 overloaded methods. */
2658 context = look_ahead_type;
2659 look_ahead_type = DEBUG_TYPE_NULL;
2671 /* static member function. */
2675 context = DEBUG_TYPE_NULL;
2679 warn_stab (orig, "member function type missing");
2681 context = DEBUG_TYPE_NULL;
2687 context = DEBUG_TYPE_NULL;
2691 /* If this is a method type which is not a stub--that is,
2692 the argument types are fully specified--then the argtypes
2693 string is actually the physical name of the function.
2694 Otherwise, the argtypes string is the mangled from of the
2695 argument types, and the physical name of the function,
2696 and the argument types, must be deduced from it. */
2698 if (debug_get_type_kind (dhandle, type) == DEBUG_KIND_METHOD
2699 && debug_get_parameter_types (dhandle, type, &varargs) != NULL)
2700 physname = argtypes;
2703 debug_type class_type, return_type;
2705 class_type = stab_find_type (dhandle, info, typenums);
2706 if (class_type == DEBUG_TYPE_NULL)
2708 return_type = debug_get_return_type (dhandle, type);
2709 if (return_type == DEBUG_TYPE_NULL)
2714 type = parse_stab_argtypes (dhandle, info, class_type, name,
2715 tagname, return_type, argtypes,
2716 constp, volatilep, &physname);
2717 if (type == DEBUG_TYPE_NULL)
2721 if (cvars + 1 >= allocvars)
2724 variants = ((debug_method_variant *)
2725 xrealloc ((PTR) variants,
2726 allocvars * sizeof *variants));
2730 variants[cvars] = debug_make_method_variant (dhandle, physname,
2735 variants[cvars] = debug_make_static_method_variant (dhandle,
2741 if (variants[cvars] == DEBUG_METHOD_VARIANT_NULL)
2746 while (**pp != ';' && **pp != '\0');
2748 variants[cvars] = DEBUG_METHOD_VARIANT_NULL;
2756 methods = ((debug_method *)
2757 xrealloc ((PTR) methods, alloc * sizeof *methods));
2760 methods[c] = debug_make_method (dhandle, name, variants);
2765 if (methods != NULL)
2766 methods[c] = DEBUG_METHOD_NULL;
2773 /* Parse a string representing argument types for a method. Stabs
2774 tries to save space by packing argument types into a mangled
2775 string. This string should give us enough information to extract
2776 both argument types and the physical name of the function, given
2780 parse_stab_argtypes (dhandle, info, class_type, fieldname, tagname,
2781 return_type, argtypes, constp, volatilep, pphysname)
2783 struct stab_handle *info;
2784 debug_type class_type;
2785 const char *fieldname;
2786 const char *tagname;
2787 debug_type return_type;
2788 const char *argtypes;
2791 const char **pphysname;
2793 boolean is_full_physname_constructor;
2794 boolean is_constructor;
2795 boolean is_destructor;
2799 /* Constructors are sometimes handled specially. */
2800 is_full_physname_constructor = ((argtypes[0] == '_'
2801 && argtypes[1] == '_'
2802 && (isdigit ((unsigned char) argtypes[2])
2803 || argtypes[2] == 'Q'
2804 || argtypes[2] == 't'))
2805 || strncmp (argtypes, "__ct", 4) == 0);
2807 is_constructor = (is_full_physname_constructor
2809 && strcmp (fieldname, tagname) == 0));
2810 is_destructor = ((argtypes[0] == '_'
2811 && (argtypes[1] == '$' || argtypes[1] == '.')
2812 && argtypes[2] == '_')
2813 || strncmp (argtypes, "__dt", 4) == 0);
2815 if (is_destructor || is_full_physname_constructor)
2816 *pphysname = argtypes;
2820 const char *const_prefix;
2821 const char *volatile_prefix;
2823 unsigned int mangled_name_len;
2826 len = tagname == NULL ? 0 : strlen (tagname);
2827 const_prefix = constp ? "C" : "";
2828 volatile_prefix = volatilep ? "V" : "";
2831 sprintf (buf, "__%s%s", const_prefix, volatile_prefix);
2832 else if (tagname != NULL && strchr (tagname, '<') != NULL)
2834 /* Template methods are fully mangled. */
2835 sprintf (buf, "__%s%s", const_prefix, volatile_prefix);
2840 sprintf (buf, "__%s%s%d", const_prefix, volatile_prefix, len);
2842 mangled_name_len = ((is_constructor ? 0 : strlen (fieldname))
2848 if (fieldname[0] == 'o'
2849 && fieldname[1] == 'p'
2850 && (fieldname[2] == '$' || fieldname[2] == '.'))
2854 opname = cplus_mangle_opname (fieldname + 3, 0);
2857 fprintf (stderr, "No mangling for \"%s\"\n", fieldname);
2858 return DEBUG_TYPE_NULL;
2860 mangled_name_len += strlen (opname);
2861 physname = (char *) xmalloc (mangled_name_len);
2862 strncpy (physname, fieldname, 3);
2863 strcpy (physname + 3, opname);
2867 physname = (char *) xmalloc (mangled_name_len);
2871 strcpy (physname, fieldname);
2874 strcat (physname, buf);
2875 if (tagname != NULL)
2876 strcat (physname, tagname);
2877 strcat (physname, argtypes);
2879 *pphysname = physname;
2882 if (*argtypes == '\0')
2884 args = (debug_type *) xmalloc (sizeof *args);
2886 return debug_make_method_type (dhandle, return_type, class_type, args,
2890 args = stab_demangle_argtypes (dhandle, info, *pphysname, &varargs);
2892 return DEBUG_TYPE_NULL;
2894 return debug_make_method_type (dhandle, return_type, class_type, args,
2898 /* The tail end of stabs for C++ classes that contain a virtual function
2899 pointer contains a tilde, a %, and a type number.
2900 The type number refers to the base class (possibly this class itself) which
2901 contains the vtable pointer for the current class.
2903 This function is called when we have parsed all the method declarations,
2904 so we can look for the vptr base class info. */
2907 parse_stab_tilde_field (dhandle, info, pp, typenums, retvptrbase, retownvptr)
2909 struct stab_handle *info;
2911 const int *typenums;
2912 debug_type *retvptrbase;
2913 boolean *retownvptr;
2919 *retvptrbase = DEBUG_TYPE_NULL;
2920 *retownvptr = false;
2924 /* If we are positioned at a ';', then skip it. */
2933 if (**pp == '=' || **pp == '+' || **pp == '-')
2935 /* Obsolete flags that used to indicate the presence of
2936 constructors and/or destructors. */
2947 /* The next number is the type number of the base class (possibly
2948 our own class) which supplies the vtable for this class. */
2949 if (! parse_stab_type_number (pp, vtypenums))
2952 if (vtypenums[0] == typenums[0]
2953 && vtypenums[1] == typenums[1])
2962 vtype = parse_stab_type (dhandle, info, (const char *) NULL, pp,
2963 (debug_type **) NULL);
2964 for (p = *pp; *p != ';' && *p != '\0'; p++)
2972 *retvptrbase = vtype;
2980 /* Read a definition of an array type. */
2983 parse_stab_array_type (dhandle, info, pp, stringp)
2985 struct stab_handle *info;
2992 debug_type index_type;
2994 bfd_signed_vma lower, upper;
2995 debug_type element_type;
2997 /* Format of an array type:
2998 "ar<index type>;lower;upper;<array_contents_type>".
2999 OS9000: "arlower,upper;<array_contents_type>".
3001 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
3002 for these, produce a type like float[][]. */
3006 /* FIXME: gdb checks os9k_stabs here. */
3008 /* If the index type is type 0, we take it as int. */
3010 if (! parse_stab_type_number (&p, typenums))
3012 if (typenums[0] == 0 && typenums[1] == 0 && **pp != '=')
3014 index_type = debug_find_named_type (dhandle, "int");
3015 if (index_type == DEBUG_TYPE_NULL)
3017 index_type = debug_make_int_type (dhandle, 4, false);
3018 if (index_type == DEBUG_TYPE_NULL)
3025 index_type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
3026 (debug_type **) NULL);
3032 return DEBUG_TYPE_NULL;
3038 if (! isdigit ((unsigned char) **pp) && **pp != '-')
3044 lower = (bfd_signed_vma) parse_number (pp, (boolean *) NULL);
3052 if (! isdigit ((unsigned char) **pp) && **pp != '-')
3058 upper = (bfd_signed_vma) parse_number (pp, (boolean *) NULL);
3066 element_type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
3067 (debug_type **) NULL);
3068 if (element_type == DEBUG_TYPE_NULL)
3077 return debug_make_array_type (dhandle, element_type, index_type, lower,
3081 /* Keep a stack of N_BINCL include files. */
3085 struct bincl_file *next;
3089 /* Start a new N_BINCL file, pushing it onto the stack. */
3092 push_bincl (info, name)
3093 struct stab_handle *info;
3096 struct bincl_file *n;
3098 n = (struct bincl_file *) xmalloc (sizeof *n);
3099 n->next = info->bincl_stack;
3101 info->bincl_stack = n;
3104 info->file_types = ((struct stab_types **)
3105 xrealloc ((PTR) info->file_types,
3107 * sizeof *info->file_types)));
3108 info->file_types[info->files - 1] = NULL;
3111 /* Finish an N_BINCL file, at an N_EINCL, popping the name off the
3116 struct stab_handle *info;
3118 struct bincl_file *o;
3120 o = info->bincl_stack;
3122 return info->main_filename;
3123 info->bincl_stack = o->next;
3125 if (info->bincl_stack == NULL)
3126 return info->main_filename;
3127 return info->bincl_stack->name;
3130 /* Handle a variable definition. gcc emits variable definitions for a
3131 block before the N_LBRAC, so we must hold onto them until we see
3132 it. The SunPRO compiler emits variable definitions after the
3133 N_LBRAC, so we can call debug_record_variable immediately. */
3136 stab_record_variable (dhandle, info, name, type, kind, val)
3138 struct stab_handle *info;
3141 enum debug_var_kind kind;
3144 struct stab_pending_var *v;
3146 if ((kind == DEBUG_GLOBAL || kind == DEBUG_STATIC)
3147 || ! info->within_function
3148 || (info->gcc_compiled == 0 && info->n_opt_found))
3149 return debug_record_variable (dhandle, name, type, kind, val);
3151 v = (struct stab_pending_var *) xmalloc (sizeof *v);
3152 memset (v, 0, sizeof *v);
3154 v->next = info->pending;
3164 /* Emit pending variable definitions. This is called after we see the
3165 N_LBRAC that starts the block. */
3168 stab_emit_pending_vars (dhandle, info)
3170 struct stab_handle *info;
3172 struct stab_pending_var *v;
3177 struct stab_pending_var *next;
3179 if (! debug_record_variable (dhandle, v->name, v->type, v->kind, v->val))
3187 info->pending = NULL;
3192 /* Find the slot for a type in the database. */
3195 stab_find_slot (info, typenums)
3196 struct stab_handle *info;
3197 const int *typenums;
3201 struct stab_types **ps;
3203 filenum = typenums[0];
3204 index = typenums[1];
3206 if (filenum < 0 || (unsigned int) filenum >= info->files)
3208 fprintf (stderr, "Type file number %d out of range\n", filenum);
3213 fprintf (stderr, "Type index number %d out of range\n", index);
3217 ps = info->file_types + filenum;
3219 while (index >= STAB_TYPES_SLOTS)
3223 *ps = (struct stab_types *) xmalloc (sizeof **ps);
3224 memset (*ps, 0, sizeof **ps);
3227 index -= STAB_TYPES_SLOTS;
3231 *ps = (struct stab_types *) xmalloc (sizeof **ps);
3232 memset (*ps, 0, sizeof **ps);
3235 return (*ps)->types + index;
3238 /* Find a type given a type number. If the type has not been
3239 allocated yet, create an indirect type. */
3242 stab_find_type (dhandle, info, typenums)
3244 struct stab_handle *info;
3245 const int *typenums;
3249 if (typenums[0] == 0 && typenums[1] < 0)
3251 /* A negative type number indicates an XCOFF builtin type. */
3252 return stab_xcoff_builtin_type (dhandle, info, typenums[1]);
3255 slot = stab_find_slot (info, typenums);
3257 return DEBUG_TYPE_NULL;
3259 if (*slot == DEBUG_TYPE_NULL)
3260 return debug_make_indirect_type (dhandle, slot, (const char *) NULL);
3265 /* Record that a given type number refers to a given type. */
3268 stab_record_type (dhandle, info, typenums, type)
3270 struct stab_handle *info;
3271 const int *typenums;
3276 slot = stab_find_slot (info, typenums);
3280 /* gdb appears to ignore type redefinitions, so we do as well. */
3287 /* Return an XCOFF builtin type. */
3290 stab_xcoff_builtin_type (dhandle, info, typenum)
3292 struct stab_handle *info;
3298 if (typenum >= 0 || typenum < -XCOFF_TYPE_COUNT)
3300 fprintf (stderr, "Unrecognized XCOFF type %d\n", typenum);
3301 return DEBUG_TYPE_NULL;
3303 if (info->xcoff_types[-typenum] != NULL)
3304 return info->xcoff_types[-typenum];
3309 /* The size of this and all the other types are fixed, defined
3310 by the debugging format. */
3312 rettype = debug_make_int_type (dhandle, 4, false);
3316 rettype = debug_make_int_type (dhandle, 1, false);
3320 rettype = debug_make_int_type (dhandle, 2, false);
3324 rettype = debug_make_int_type (dhandle, 4, false);
3327 name = "unsigned char";
3328 rettype = debug_make_int_type (dhandle, 1, true);
3331 name = "signed char";
3332 rettype = debug_make_int_type (dhandle, 1, false);
3335 name = "unsigned short";
3336 rettype = debug_make_int_type (dhandle, 2, true);
3339 name = "unsigned int";
3340 rettype = debug_make_int_type (dhandle, 4, true);
3344 rettype = debug_make_int_type (dhandle, 4, true);
3346 name = "unsigned long";
3347 rettype = debug_make_int_type (dhandle, 4, true);
3351 rettype = debug_make_void_type (dhandle);
3354 /* IEEE single precision (32 bit). */
3356 rettype = debug_make_float_type (dhandle, 4);
3359 /* IEEE double precision (64 bit). */
3361 rettype = debug_make_float_type (dhandle, 8);
3364 /* This is an IEEE double on the RS/6000, and different machines
3365 with different sizes for "long double" should use different
3366 negative type numbers. See stabs.texinfo. */
3367 name = "long double";
3368 rettype = debug_make_float_type (dhandle, 8);
3372 rettype = debug_make_int_type (dhandle, 4, false);
3376 rettype = debug_make_bool_type (dhandle, 4);
3379 name = "short real";
3380 rettype = debug_make_float_type (dhandle, 4);
3384 rettype = debug_make_float_type (dhandle, 8);
3394 rettype = debug_make_int_type (dhandle, 1, true);
3398 rettype = debug_make_bool_type (dhandle, 1);
3402 rettype = debug_make_bool_type (dhandle, 2);
3406 rettype = debug_make_bool_type (dhandle, 4);
3410 rettype = debug_make_bool_type (dhandle, 4);
3413 /* Complex type consisting of two IEEE single precision values. */
3415 rettype = debug_make_complex_type (dhandle, 8);
3418 /* Complex type consisting of two IEEE double precision values. */
3419 name = "double complex";
3420 rettype = debug_make_complex_type (dhandle, 16);
3424 rettype = debug_make_int_type (dhandle, 1, false);
3428 rettype = debug_make_int_type (dhandle, 2, false);
3432 rettype = debug_make_int_type (dhandle, 4, false);
3437 rettype = debug_make_int_type (dhandle, 2, false);
3441 rettype = debug_make_int_type (dhandle, 8, false);
3444 name = "unsigned long long";
3445 rettype = debug_make_int_type (dhandle, 8, true);
3449 rettype = debug_make_bool_type (dhandle, 8);
3453 rettype = debug_make_int_type (dhandle, 8, false);
3459 rettype = debug_name_type (dhandle, name, rettype);
3461 info->xcoff_types[-typenum] = rettype;
3466 /* Find or create a tagged type. */
3469 stab_find_tagged_type (dhandle, info, p, len, kind)
3471 struct stab_handle *info;
3474 enum debug_type_kind kind;
3478 struct stab_tag *st;
3480 name = savestring (p, len);
3482 /* We pass DEBUG_KIND_ILLEGAL because we want all tags in the same
3483 namespace. This is right for C, and I don't know how to handle
3484 other languages. FIXME. */
3485 dtype = debug_find_tagged_type (dhandle, name, DEBUG_KIND_ILLEGAL);
3486 if (dtype != DEBUG_TYPE_NULL)
3492 /* We need to allocate an entry on the undefined tag list. */
3493 for (st = info->tags; st != NULL; st = st->next)
3495 if (st->name[0] == name[0]
3496 && strcmp (st->name, name) == 0)
3498 if (st->kind == DEBUG_KIND_ILLEGAL)
3506 st = (struct stab_tag *) xmalloc (sizeof *st);
3507 memset (st, 0, sizeof *st);
3509 st->next = info->tags;
3512 st->slot = DEBUG_TYPE_NULL;
3513 st->type = debug_make_indirect_type (dhandle, &st->slot, name);
3520 /* In order to get the correct argument types for a stubbed method, we
3521 need to extract the argument types from a C++ mangled string.
3522 Since the argument types can refer back to the return type, this
3523 means that we must demangle the entire physical name. In gdb this
3524 is done by calling cplus_demangle and running the results back
3525 through the C++ expression parser. Since we have no expression
3526 parser, we must duplicate much of the work of cplus_demangle here.
3528 We assume that GNU style demangling is used, since this is only
3529 done for method stubs, and only g++ should output that form of
3530 debugging information. */
3532 /* This structure is used to hold a pointer to type information which
3533 demangling a string. */
3535 struct stab_demangle_typestring
3537 /* The start of the type. This is not null terminated. */
3538 const char *typestring;
3539 /* The length of the type. */
3543 /* This structure is used to hold information while demangling a
3546 struct stab_demangle_info
3548 /* The debugging information handle. */
3550 /* The stab information handle. */
3551 struct stab_handle *info;
3552 /* The array of arguments we are building. */
3554 /* Whether the method takes a variable number of arguments. */
3556 /* The array of types we have remembered. */
3557 struct stab_demangle_typestring *typestrings;
3558 /* The number of typestrings. */
3559 unsigned int typestring_count;
3560 /* The number of typestring slots we have allocated. */
3561 unsigned int typestring_alloc;
3564 static void stab_bad_demangle PARAMS ((const char *));
3565 static unsigned int stab_demangle_count PARAMS ((const char **));
3566 static boolean stab_demangle_get_count
3567 PARAMS ((const char **, unsigned int *));
3568 static boolean stab_demangle_prefix
3569 PARAMS ((struct stab_demangle_info *, const char **));
3570 static boolean stab_demangle_function_name
3571 PARAMS ((struct stab_demangle_info *, const char **, const char *));
3572 static boolean stab_demangle_signature
3573 PARAMS ((struct stab_demangle_info *, const char **));
3574 static boolean stab_demangle_qualified
3575 PARAMS ((struct stab_demangle_info *, const char **, debug_type *));
3576 static boolean stab_demangle_template
3577 PARAMS ((struct stab_demangle_info *, const char **));
3578 static boolean stab_demangle_class
3579 PARAMS ((struct stab_demangle_info *, const char **, const char **));
3580 static boolean stab_demangle_args
3581 PARAMS ((struct stab_demangle_info *, const char **, debug_type **,
3583 static boolean stab_demangle_arg
3584 PARAMS ((struct stab_demangle_info *, const char **, debug_type **,
3585 unsigned int *, unsigned int *));
3586 static boolean stab_demangle_type
3587 PARAMS ((struct stab_demangle_info *, const char **, debug_type *));
3588 static boolean stab_demangle_fund_type
3589 PARAMS ((struct stab_demangle_info *, const char **, debug_type *));
3590 static boolean stab_demangle_remember_type
3591 PARAMS ((struct stab_demangle_info *, const char *, int));
3593 /* Warn about a bad demangling. */
3596 stab_bad_demangle (s)
3599 fprintf (stderr, "bad mangled name `%s'\n", s);
3602 /* Get a count from a stab string. */
3605 stab_demangle_count (pp)
3611 while (isdigit ((unsigned char) **pp))
3614 count += **pp - '0';
3620 /* Require a count in a string. The count may be multiple digits, in
3621 which case it must end in an underscore. */
3624 stab_demangle_get_count (pp, pi)
3628 if (! isdigit ((unsigned char) **pp))
3633 if (isdigit ((unsigned char) **pp))
3646 while (isdigit ((unsigned char) *p));
3657 /* This function demangles a physical name, returning a NULL
3658 terminated array of argument types. */
3661 stab_demangle_argtypes (dhandle, info, physname, pvarargs)
3663 struct stab_handle *info;
3664 const char *physname;
3667 struct stab_demangle_info minfo;
3669 minfo.dhandle = dhandle;
3672 minfo.varargs = false;
3673 minfo.typestring_alloc = 10;
3674 minfo.typestrings = ((struct stab_demangle_typestring *)
3675 xmalloc (minfo.typestring_alloc
3676 * sizeof *minfo.typestrings));
3677 minfo.typestring_count = 0;
3679 /* cplus_demangle checks for special GNU mangled forms, but we can't
3680 see any of them in mangled method argument types. */
3682 if (! stab_demangle_prefix (&minfo, &physname))
3685 if (*physname != '\0')
3687 if (! stab_demangle_signature (&minfo, &physname))
3691 free (minfo.typestrings);
3692 minfo.typestrings = NULL;
3694 if (minfo.args == NULL)
3695 fprintf (stderr, "no argument types in mangled string\n");
3697 *pvarargs = minfo.varargs;
3701 if (minfo.typestrings != NULL)
3702 free (minfo.typestrings);
3706 /* Demangle the prefix of the mangled name. */
3709 stab_demangle_prefix (minfo, pp)
3710 struct stab_demangle_info *minfo;
3716 /* cplus_demangle checks for global constructors and destructors,
3717 but we can't see them in mangled argument types. */
3719 /* Look for `__'. */
3723 scan = strchr (scan, '_');
3725 while (scan != NULL && *++scan != '_');
3729 stab_bad_demangle (*pp);
3735 /* We found `__'; move ahead to the last contiguous `__' pair. */
3736 i = strspn (scan, "_");
3741 && (isdigit ((unsigned char) scan[2])
3745 /* This is a GNU style constructor name. */
3749 else if (scan == *pp
3750 && ! isdigit ((unsigned char) scan[2])
3753 /* Look for the `__' that separates the prefix from the
3755 while (*scan == '_')
3757 scan = strstr (scan, "__");
3758 if (scan == NULL || scan[2] == '\0')
3760 stab_bad_demangle (*pp);
3764 return stab_demangle_function_name (minfo, pp, scan);
3766 else if (scan[2] != '\0')
3768 /* The name doesn't start with `__', but it does contain `__'. */
3769 return stab_demangle_function_name (minfo, pp, scan);
3773 stab_bad_demangle (*pp);
3779 /* Demangle a function name prefix. The scan argument points to the
3780 double underscore which separates the function name from the
3784 stab_demangle_function_name (minfo, pp, scan)
3785 struct stab_demangle_info *minfo;
3791 /* The string from *pp to scan is the name of the function. We
3792 don't care about the name, since we just looking for argument
3793 types. However, for conversion operators, the name may include a
3794 type which we must remember in order to handle backreferences. */
3800 && strncmp (name, "type", 4) == 0
3801 && (name[4] == '$' || name[4] == '.'))
3805 /* This is a type conversion operator. */
3807 if (! stab_demangle_type (minfo, &tem, (debug_type *) NULL))
3810 else if (name[0] == '_'
3817 /* This is a type conversion operator. */
3819 if (! stab_demangle_type (minfo, &tem, (debug_type *) NULL))
3826 /* Demangle the signature. This is where the argument types are
3830 stab_demangle_signature (minfo, pp)
3831 struct stab_demangle_info *minfo;
3835 boolean expect_func, func_done;
3840 expect_func = false;
3844 while (**pp != '\0')
3850 if (! stab_demangle_qualified (minfo, pp, (debug_type *) NULL)
3851 || ! stab_demangle_remember_type (minfo, hold, *pp - hold))
3858 /* Static member function. FIXME: Can this happen? */
3865 /* Const member function. */
3871 case '0': case '1': case '2': case '3': case '4':
3872 case '5': case '6': case '7': case '8': case '9':
3875 if (! stab_demangle_class (minfo, pp, (const char **) NULL)
3876 || ! stab_demangle_remember_type (minfo, hold, *pp - hold))
3883 /* Function. I don't know if this actually happens with g++
3888 if (! stab_demangle_args (minfo, pp, &minfo->args, &minfo->varargs))
3896 if (! stab_demangle_template (minfo, pp)
3897 || ! stab_demangle_remember_type (minfo, hold, *pp - hold))
3904 /* At the outermost level, we cannot have a return type
3905 specified, so if we run into another '_' at this point we
3906 are dealing with a mangled name that is either bogus, or
3907 has been mangled by some algorithm we don't know how to
3908 deal with. So just reject the entire demangling. */
3909 stab_bad_demangle (orig);
3913 /* Assume we have stumbled onto the first outermost function
3914 argument token, and start processing args. */
3916 if (! stab_demangle_args (minfo, pp, &minfo->args, &minfo->varargs))
3924 if (! stab_demangle_args (minfo, pp, &minfo->args, &minfo->varargs))
3931 /* With GNU style demangling, bar__3foo is 'foo::bar(void)', and
3932 bar__3fooi is 'foo::bar(int)'. We get here when we find the
3933 first case, and need to ensure that the '(void)' gets added
3934 to the current declp. */
3935 if (! stab_demangle_args (minfo, pp, &minfo->args, &minfo->varargs))
3942 /* Demangle a qualified name, such as "Q25Outer5Inner" which is the
3943 mangled form of "Outer::Inner". */
3946 stab_demangle_qualified (minfo, pp, ptype)
3947 struct stab_demangle_info *minfo;
3953 unsigned int qualifiers;
3961 /* GNU mangled name with more than 9 classes. The count is
3962 preceded by an underscore (to distinguish it from the <= 9
3963 case) and followed by an underscore. */
3965 if (! isdigit ((unsigned char) *p) || *p == '0')
3967 stab_bad_demangle (orig);
3970 qualifiers = atoi (p);
3971 while (isdigit ((unsigned char) *p))
3975 stab_bad_demangle (orig);
3981 case '1': case '2': case '3': case '4': case '5':
3982 case '6': case '7': case '8': case '9':
3983 qualifiers = (*pp)[1] - '0';
3984 /* Skip an optional underscore after the count. */
3985 if ((*pp)[2] == '_')
3992 stab_bad_demangle (orig);
3996 context = DEBUG_TYPE_NULL;
3998 /* Pick off the names. */
3999 while (qualifiers-- > 0)
4005 /* FIXME: I don't know how to handle the ptype != NULL case
4007 if (! stab_demangle_template (minfo, pp))
4014 len = stab_demangle_count (pp);
4015 if (strlen (*pp) < len)
4017 stab_bad_demangle (orig);
4023 const debug_field *fields;
4026 if (context != DEBUG_TYPE_NULL)
4027 fields = debug_get_fields (minfo->dhandle, context);
4029 context = DEBUG_TYPE_NULL;
4035 /* Try to find the type by looking through the
4036 fields of context until we find a field with the
4037 same type. This ought to work for a class
4038 defined within a class, but it won't work for,
4039 e.g., an enum defined within a class. stabs does
4040 not give us enough information to figure out the
4043 name = savestring (*pp, len);
4045 for (; *fields != DEBUG_FIELD_NULL; fields++)
4050 ft = debug_get_field_type (minfo->dhandle, *fields);
4053 dn = debug_get_type_name (minfo->dhandle, ft);
4054 if (dn != NULL && strcmp (dn, name) == 0)
4064 if (context == DEBUG_TYPE_NULL)
4066 /* We have to fall back on finding the type by name.
4067 If there are more types to come, then this must
4068 be a class. Otherwise, it could be anything. */
4070 if (qualifiers == 0)
4074 name = savestring (*pp, len);
4075 context = debug_find_named_type (minfo->dhandle,
4080 if (context == DEBUG_TYPE_NULL)
4082 context = stab_find_tagged_type (minfo->dhandle,
4086 ? DEBUG_KIND_ILLEGAL
4087 : DEBUG_KIND_CLASS));
4088 if (context == DEBUG_TYPE_NULL)
4104 /* Demangle a template. */
4107 stab_demangle_template (minfo, pp)
4108 struct stab_demangle_info *minfo;
4118 /* Skip the template name. */
4119 r = stab_demangle_count (pp);
4120 if (r == 0 || strlen (*pp) < r)
4122 stab_bad_demangle (orig);
4127 /* Get the size of the parameter list. */
4128 if (stab_demangle_get_count (pp, &r) == 0)
4130 stab_bad_demangle (orig);
4134 for (i = 0; i < r; i++)
4138 /* This is a type parameter. */
4140 if (! stab_demangle_type (minfo, pp, (debug_type *) NULL))
4146 boolean pointerp, realp, integralp, charp, boolp;
4157 /* This is a value parameter. */
4159 if (! stab_demangle_type (minfo, pp, (debug_type *) NULL))
4162 while (*old_p != '\0' && ! done)
4172 case 'C': /* Const. */
4173 case 'S': /* Signed. */
4174 case 'U': /* Unsigned. */
4175 case 'V': /* Volatile. */
4176 case 'F': /* Function. */
4177 case 'M': /* Member function. */
4181 case 'Q': /* Qualified name. */
4185 case 'T': /* Remembered type. */
4187 case 'v': /* Void. */
4189 case 'x': /* Long long. */
4190 case 'l': /* Long. */
4191 case 'i': /* Int. */
4192 case 's': /* Short. */
4193 case 'w': /* Wchar_t. */
4197 case 'b': /* Bool. */
4201 case 'c': /* Char. */
4205 case 'r': /* Long double. */
4206 case 'd': /* Double. */
4207 case 'f': /* Float. */
4212 /* Assume it's a uder defined integral type. */
4223 while (isdigit ((unsigned char) **pp))
4232 val = stab_demangle_count (pp);
4235 stab_bad_demangle (orig);
4243 val = stab_demangle_count (pp);
4244 if (val != 0 && val != 1)
4246 stab_bad_demangle (orig);
4254 while (isdigit ((unsigned char) **pp))
4259 while (isdigit ((unsigned char) **pp))
4265 while (isdigit ((unsigned char) **pp))
4273 if (! stab_demangle_get_count (pp, &len))
4275 stab_bad_demangle (orig);
4286 /* Demangle a class name. */
4289 stab_demangle_class (minfo, pp, pstart)
4290 struct stab_demangle_info *minfo;
4292 const char **pstart;
4299 n = stab_demangle_count (pp);
4300 if (strlen (*pp) < n)
4302 stab_bad_demangle (orig);
4314 /* Demangle function arguments. If the pargs argument is not NULL, it
4315 is set to a NULL terminated array holding the arguments. */
4318 stab_demangle_args (minfo, pp, pargs, pvarargs)
4319 struct stab_demangle_info *minfo;
4325 unsigned int alloc, count;
4332 *pargs = (debug_type *) xmalloc (alloc * sizeof **pargs);
4337 while (**pp != '_' && **pp != '\0' && **pp != 'e')
4339 if (**pp == 'N' || **pp == 'T')
4347 if (temptype == 'T')
4351 if (! stab_demangle_get_count (pp, &r))
4353 stab_bad_demangle (orig);
4358 if (! stab_demangle_get_count (pp, &t))
4360 stab_bad_demangle (orig);
4364 if (t >= minfo->typestring_count)
4366 stab_bad_demangle (orig);
4373 tem = minfo->typestrings[t].typestring;
4374 if (! stab_demangle_arg (minfo, &tem, pargs, &count, &alloc))
4380 if (! stab_demangle_arg (minfo, pp, pargs, &count, &alloc))
4386 (*pargs)[count] = DEBUG_TYPE_NULL;
4398 /* Demangle a single argument. */
4401 stab_demangle_arg (minfo, pp, pargs, pcount, palloc)
4402 struct stab_demangle_info *minfo;
4405 unsigned int *pcount;
4406 unsigned int *palloc;
4412 if (! stab_demangle_type (minfo, pp,
4413 pargs == NULL ? (debug_type *) NULL : &type)
4414 || ! stab_demangle_remember_type (minfo, start, *pp - start))
4419 if (type == DEBUG_TYPE_NULL)
4422 if (*pcount + 1 >= *palloc)
4425 *pargs = ((debug_type *)
4426 xrealloc (*pargs, *palloc * sizeof **pargs));
4428 (*pargs)[*pcount] = type;
4435 /* Demangle a type. If the ptype argument is not NULL, *ptype is set
4436 to the newly allocated type. */
4439 stab_demangle_type (minfo, pp, ptype)
4440 struct stab_demangle_info *minfo;
4452 /* A pointer type. */
4454 if (! stab_demangle_type (minfo, pp, ptype))
4457 *ptype = debug_make_pointer_type (minfo->dhandle, *ptype);
4461 /* A reference type. */
4463 if (! stab_demangle_type (minfo, pp, ptype))
4466 *ptype = debug_make_reference_type (minfo->dhandle, *ptype);
4476 while (**pp != '\0' && **pp != '_')
4478 if (! isdigit ((unsigned char) **pp))
4480 stab_bad_demangle (orig);
4489 stab_bad_demangle (orig);
4494 if (! stab_demangle_type (minfo, pp, ptype))
4498 debug_type int_type;
4500 int_type = debug_find_named_type (minfo->dhandle, "int");
4501 if (int_type == NULL)
4502 int_type = debug_make_int_type (minfo->dhandle, 4, false);
4503 *ptype = debug_make_array_type (minfo->dhandle, *ptype, int_type,
4510 /* A back reference to a remembered type. */
4516 if (! stab_demangle_get_count (pp, &i))
4518 stab_bad_demangle (orig);
4521 if (i >= minfo->typestring_count)
4523 stab_bad_demangle (orig);
4526 p = minfo->typestrings[i].typestring;
4527 if (! stab_demangle_type (minfo, &p, ptype))
4539 if (! stab_demangle_args (minfo, pp,
4541 ? (debug_type **) NULL
4549 /* cplus_demangle will accept a function without a return
4550 type, but I don't know when that will happen, or what
4551 to do if it does. */
4552 stab_bad_demangle (orig);
4556 if (! stab_demangle_type (minfo, pp, ptype))
4559 *ptype = debug_make_function_type (minfo->dhandle, *ptype, args,
4568 boolean memberp, constp, volatilep;
4574 memberp = **pp == 'M';
4581 if (! isdigit ((unsigned char) **pp))
4583 stab_bad_demangle (orig);
4586 n = stab_demangle_count (pp);
4587 if (strlen (*pp) < n)
4589 stab_bad_demangle (orig);
4602 else if (**pp == 'V')
4609 stab_bad_demangle (orig);
4613 if (! stab_demangle_args (minfo, pp,
4615 ? (debug_type **) NULL
4625 stab_bad_demangle (orig);
4630 if (! stab_demangle_type (minfo, pp, ptype))
4635 debug_type class_type;
4637 class_type = stab_find_tagged_type (minfo->dhandle, minfo->info,
4640 if (class_type == DEBUG_TYPE_NULL)
4644 *ptype = debug_make_offset_type (minfo->dhandle, class_type,
4648 /* FIXME: We have no way to record constp or
4650 *ptype = debug_make_method_type (minfo->dhandle, *ptype,
4651 class_type, args, varargs);
4659 if (! stab_demangle_type (minfo, pp, ptype))
4665 if (! stab_demangle_type (minfo, pp, ptype))
4668 *ptype = debug_make_const_type (minfo->dhandle, *ptype);
4676 if (! stab_demangle_qualified (minfo, pp, ptype))
4682 if (! stab_demangle_fund_type (minfo, pp, ptype))
4690 /* Demangle a fundamental type. If the ptype argument is not NULL,
4691 *ptype is set to the newly allocated type. */
4694 stab_demangle_fund_type (minfo, pp, ptype)
4695 struct stab_demangle_info *minfo;
4700 boolean constp, volatilep, unsignedp, signedp;
4745 /* cplus_demangle permits this, but I don't know what it means. */
4746 stab_bad_demangle (orig);
4749 case 'v': /* void */
4752 *ptype = debug_find_named_type (minfo->dhandle, "void");
4753 if (*ptype == DEBUG_TYPE_NULL)
4754 *ptype = debug_make_void_type (minfo->dhandle);
4759 case 'x': /* long long */
4762 *ptype = debug_find_named_type (minfo->dhandle,
4764 ? "long long unsigned int"
4765 : "long long int"));
4766 if (*ptype == DEBUG_TYPE_NULL)
4767 *ptype = debug_make_int_type (minfo->dhandle, 8, unsignedp);
4772 case 'l': /* long */
4775 *ptype = debug_find_named_type (minfo->dhandle,
4777 ? "long unsigned int"
4779 if (*ptype == DEBUG_TYPE_NULL)
4780 *ptype = debug_make_int_type (minfo->dhandle, 4, unsignedp);
4788 *ptype = debug_find_named_type (minfo->dhandle,
4792 if (*ptype == DEBUG_TYPE_NULL)
4793 *ptype = debug_make_int_type (minfo->dhandle, 4, unsignedp);
4798 case 's': /* short */
4801 *ptype = debug_find_named_type (minfo->dhandle,
4803 ? "short unsigned int"
4805 if (*ptype == DEBUG_TYPE_NULL)
4806 *ptype = debug_make_int_type (minfo->dhandle, 2, unsignedp);
4811 case 'b': /* bool */
4814 *ptype = debug_find_named_type (minfo->dhandle, "bool");
4815 if (*ptype == DEBUG_TYPE_NULL)
4816 *ptype = debug_make_bool_type (minfo->dhandle, 4);
4821 case 'c': /* char */
4824 *ptype = debug_find_named_type (minfo->dhandle,
4830 if (*ptype == DEBUG_TYPE_NULL)
4831 *ptype = debug_make_int_type (minfo->dhandle, 1, unsignedp);
4836 case 'w': /* wchar_t */
4839 *ptype = debug_find_named_type (minfo->dhandle, "__wchar_t");
4840 if (*ptype == DEBUG_TYPE_NULL)
4841 *ptype = debug_make_int_type (minfo->dhandle, 2, true);
4846 case 'r': /* long double */
4849 *ptype = debug_find_named_type (minfo->dhandle, "long double");
4850 if (*ptype == DEBUG_TYPE_NULL)
4851 *ptype = debug_make_float_type (minfo->dhandle, 8);
4856 case 'd': /* double */
4859 *ptype = debug_find_named_type (minfo->dhandle, "double");
4860 if (*ptype == DEBUG_TYPE_NULL)
4861 *ptype = debug_make_float_type (minfo->dhandle, 8);
4866 case 'f': /* float */
4869 *ptype = debug_find_named_type (minfo->dhandle, "float");
4870 if (*ptype == DEBUG_TYPE_NULL)
4871 *ptype = debug_make_float_type (minfo->dhandle, 4);
4878 if (! isdigit ((unsigned char) **pp))
4880 stab_bad_demangle (orig);
4884 case '0': case '1': case '2': case '3': case '4':
4885 case '5': case '6': case '7': case '8': case '9':
4889 if (! stab_demangle_class (minfo, pp, &hold))
4895 name = savestring (hold, *pp - hold);
4896 *ptype = debug_find_named_type (minfo->dhandle, name);
4897 if (*ptype == DEBUG_TYPE_NULL)
4899 /* FIXME: It is probably incorrect to assume that
4900 undefined types are tagged types. */
4901 *ptype = stab_find_tagged_type (minfo->dhandle, minfo->info,
4903 DEBUG_KIND_ILLEGAL);
4911 if (! stab_demangle_template (minfo, pp))
4917 stab_bad_demangle (orig);
4924 *ptype = debug_make_const_type (minfo->dhandle, *ptype);
4926 *ptype = debug_make_volatile_type (minfo->dhandle, *ptype);
4932 /* Remember a type string in a demangled string. */
4935 stab_demangle_remember_type (minfo, p, len)
4936 struct stab_demangle_info *minfo;
4940 if (minfo->typestring_count >= minfo->typestring_alloc)
4942 minfo->typestring_alloc += 10;
4943 minfo->typestrings = ((struct stab_demangle_typestring *)
4944 xrealloc (minfo->typestrings,
4945 (minfo->typestring_alloc
4946 * sizeof *minfo->typestrings)));
4949 minfo->typestrings[minfo->typestring_count].typestring = p;
4950 minfo->typestrings[minfo->typestring_count].len = (unsigned int) len;
4951 ++minfo->typestring_count;