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 type of the last stab symbol, so that we can detect N_SO
57 /* The value of the start of the file, so that we can handle file
58 relative N_LBRAC and N_RBRAC symbols. */
59 bfd_vma file_start_offset;
60 /* The offset of the start of the function, so that we can handle
61 function relative N_LBRAC and N_RBRAC symbols. */
62 bfd_vma function_start_offset;
63 /* The version number of gcc which compiled the current compilation
64 unit, 0 if not compiled by gcc. */
66 /* Whether an N_OPT symbol was seen that was not generated by gcc,
67 so that we can detect the SunPRO compiler. */
69 /* The main file name. */
71 /* A stack of N_BINCL files. */
72 struct bincl_file *bincl_stack;
73 /* Whether we are inside a function or not. */
74 boolean within_function;
75 /* The depth of block nesting. */
77 /* List of pending variable definitions. */
78 struct stab_pending_var *pending;
79 /* Number of files for which we have types. */
81 /* Lists of types per file. */
82 struct stab_types **file_types;
83 /* Predefined XCOFF types. */
84 debug_type xcoff_types[XCOFF_TYPE_COUNT];
86 struct stab_tag *tags;
89 /* A list of these structures is used to hold pending variable
90 definitions seen before the N_LBRAC of a block. */
92 struct stab_pending_var
94 /* Next pending variable definition. */
95 struct stab_pending_var *next;
101 enum debug_var_kind kind;
106 /* A list of these structures is used to hold the types for a single
111 /* Next set of slots for this file. */
112 struct stab_types *next;
113 /* Types indexed by type number. */
114 #define STAB_TYPES_SLOTS (16)
115 debug_type types[STAB_TYPES_SLOTS];
118 /* We keep a list of undefined tags that we encounter, so that we can
119 fill them in if the tag is later defined. */
123 /* Next undefined tag. */
124 struct stab_tag *next;
128 enum debug_type_kind kind;
129 /* Slot to hold real type when we discover it. If we don't, we fill
130 in an undefined tag type. */
132 /* Indirect type we have created to point at slot. */
136 static char *savestring PARAMS ((const char *, int));
137 static bfd_vma parse_number PARAMS ((const char **, boolean *));
138 static void bad_stab PARAMS ((const char *));
139 static void warn_stab PARAMS ((const char *, const char *));
140 static boolean parse_stab_string
141 PARAMS ((PTR, struct stab_handle *, int, int, bfd_vma, const char *));
142 static debug_type parse_stab_type
143 PARAMS ((PTR, struct stab_handle *, const char *, const char **,
145 static boolean parse_stab_type_number
146 PARAMS ((const char **, int *));
147 static debug_type parse_stab_range_type
148 PARAMS ((PTR, struct stab_handle *, const char *, const char **,
150 static debug_type parse_stab_sun_builtin_type PARAMS ((PTR, const char **));
151 static debug_type parse_stab_sun_floating_type
152 PARAMS ((PTR, const char **));
153 static debug_type parse_stab_enum_type PARAMS ((PTR, const char **));
154 static debug_type parse_stab_struct_type
155 PARAMS ((PTR, struct stab_handle *, const char *, const char **, boolean,
157 static boolean parse_stab_baseclasses
158 PARAMS ((PTR, struct stab_handle *, const char **, debug_baseclass **));
159 static boolean parse_stab_struct_fields
160 PARAMS ((PTR, struct stab_handle *, const char **, debug_field **,
162 static boolean parse_stab_cpp_abbrev
163 PARAMS ((PTR, struct stab_handle *, const char **, debug_field *));
164 static boolean parse_stab_one_struct_field
165 PARAMS ((PTR, struct stab_handle *, const char **, const char *,
166 debug_field *, boolean *));
167 static boolean parse_stab_members
168 PARAMS ((PTR, struct stab_handle *, const char *, const char **,
169 const int *, debug_method **));
170 static debug_type parse_stab_argtypes
171 PARAMS ((PTR, struct stab_handle *, debug_type, const char *, const char *,
172 debug_type, const char *, boolean, boolean, const char **));
173 static boolean parse_stab_tilde_field
174 PARAMS ((PTR, struct stab_handle *, const char **, const int *,
175 debug_type *, boolean *));
176 static debug_type parse_stab_array_type
177 PARAMS ((PTR, struct stab_handle *, const char **, boolean));
178 static void push_bincl PARAMS ((struct stab_handle *, const char *));
179 static const char *pop_bincl PARAMS ((struct stab_handle *));
180 static boolean stab_record_variable
181 PARAMS ((PTR, struct stab_handle *, const char *, debug_type,
182 enum debug_var_kind, bfd_vma));
183 static boolean stab_emit_pending_vars PARAMS ((PTR, struct stab_handle *));
184 static debug_type *stab_find_slot
185 PARAMS ((struct stab_handle *, const int *));
186 static debug_type stab_find_type
187 PARAMS ((PTR, struct stab_handle *, const int *));
188 static boolean stab_record_type
189 PARAMS ((PTR, struct stab_handle *, const int *, debug_type));
190 static debug_type stab_xcoff_builtin_type
191 PARAMS ((PTR, struct stab_handle *, int));
192 static debug_type stab_find_tagged_type
193 PARAMS ((PTR, struct stab_handle *, const char *, int,
194 enum debug_type_kind));
195 static debug_type *stab_demangle_argtypes
196 PARAMS ((PTR, struct stab_handle *, const char *));
198 /* Save a string in memory. */
201 savestring (start, len)
207 ret = (char *) xmalloc (len + 1);
208 memcpy (ret, start, len);
213 /* Read a number from a string. */
216 parse_number (pp, poverflow)
223 if (poverflow != NULL)
229 ul = strtoul (*pp, (char **) pp, 0);
230 if (ul + 1 != 0 || errno == 0)
233 /* Note that even though strtoul overflowed, it should have set *pp
234 to the end of the number, which is where we want it. */
236 if (sizeof (bfd_vma) > sizeof (unsigned long))
241 bfd_vma over, lastdig;
245 /* Our own version of strtoul, for a bfd_vma. */
261 if (p[1] == 'x' || p[1] == 'X')
273 over = ((bfd_vma) (bfd_signed_vma) -1) / (bfd_vma) base;
274 lastdig = ((bfd_vma) (bfd_signed_vma) -1) % (bfd_vma) base;
283 if (isdigit ((unsigned char) d))
285 else if (isupper ((unsigned char) d))
287 else if (islower ((unsigned char) d))
295 if (v > over || (v == over && (bfd_vma) d > lastdig))
310 /* If we get here, the number is too large to represent in a
313 if (poverflow != NULL)
316 warn_stab (orig, "numeric overflow");
321 /* Give an error for a bad stab string. */
327 fprintf (stderr, "Bad stab: %s\n", p);
330 /* Warn about something in a stab string. */
337 fprintf (stderr, "Warning: %s: %s\n", err, p);
340 /* Create a handle to parse stabs symbols with. */
344 start_stab (dhandle, sections)
348 struct stab_handle *ret;
350 ret = (struct stab_handle *) xmalloc (sizeof *ret);
351 memset (ret, 0, sizeof *ret);
352 ret->sections = sections;
354 ret->file_types = (struct stab_types **) xmalloc (sizeof *ret->file_types);
355 ret->file_types[0] = NULL;
359 /* When we have processed all the stabs information, we need to go
360 through and fill in all the undefined tags. */
363 finish_stab (dhandle, handle)
367 struct stab_handle *info = (struct stab_handle *) handle;
370 if (info->within_function)
372 if (! debug_end_function (dhandle, (bfd_vma) -1))
374 info->within_function = false;
377 for (st = info->tags; st != NULL; st = st->next)
379 enum debug_type_kind kind;
382 if (kind == DEBUG_KIND_ILLEGAL)
383 kind = DEBUG_KIND_STRUCT;
384 st->slot = debug_make_undefined_tagged_type (dhandle, st->name, kind);
385 if (st->slot == DEBUG_TYPE_NULL)
390 fprintf (stderr, "Left over pending variables in stabs debugging\n");
395 /* Handle a single stabs symbol. */
398 parse_stab (dhandle, handle, type, desc, value, string)
406 struct stab_handle *info = (struct stab_handle *) handle;
415 /* Ignore extra outermost context from SunPRO cc and acc. */
416 if (info->n_opt_found && desc == 1)
419 if (! info->within_function)
421 fprintf (stderr, "N_LBRAC not within function\n");
425 /* Start an inner lexical block. */
426 if (! debug_start_block (dhandle,
428 + info->file_start_offset
429 + info->function_start_offset)))
432 /* Emit any pending variable definitions. */
433 if (! stab_emit_pending_vars (dhandle, info))
440 /* Ignore extra outermost context from SunPRO cc and acc. */
441 if (info->n_opt_found && desc == 1)
444 /* We shouldn't have any pending variable definitions here, but,
445 if we do, we probably need to emit them before closing the
447 if (! stab_emit_pending_vars (dhandle, info))
450 /* End an inner lexical block. */
451 if (! debug_end_block (dhandle,
453 + info->file_start_offset
454 + info->function_start_offset)))
458 if (info->block_depth < 0)
460 fprintf (stderr, "Too many N_RBRACs\n");
466 /* Start a file. If we get two in a row, the first is the
467 directory name. An empty string is emitted by gcc at the end
468 of a compilation unit. */
471 if (info->within_function)
473 if (! debug_end_function (dhandle, value))
475 info->within_function = false;
479 info->gcc_compiled = 0;
480 info->n_opt_found = false;
481 if (info->last_type == N_SO)
485 if (! debug_append_filename (dhandle, string))
487 o = info->main_filename;
488 info->main_filename = concat (o, string, (const char *) NULL);
493 if (info->within_function)
495 if (! debug_end_function (dhandle, value))
497 info->within_function = false;
499 if (! debug_set_filename (dhandle, string))
501 if (info->main_filename != NULL)
502 free (info->main_filename);
503 info->main_filename = xstrdup (string);
505 /* Generally, for stabs in the symbol table, the N_LBRAC and
506 N_RBRAC symbols are relative to the N_SO symbol value. */
507 if (! info->sections)
508 info->file_start_offset = value;
510 /* We need to reset the mapping from type numbers to types.
511 We can't free the old mapping, because of the use of
512 debug_make_indirect_type. */
514 info->file_types = ((struct stab_types **)
515 xmalloc (sizeof *info->file_types));
516 info->file_types[0] = NULL;
521 /* Start an include file. */
522 if (! debug_start_source (dhandle, string))
527 /* Start an include file which may be replaced. */
528 push_bincl (info, string);
529 if (! debug_start_source (dhandle, string))
534 /* End an N_BINCL include. */
535 if (! debug_start_source (dhandle, pop_bincl (info)))
540 /* This is a duplicate of a header file named by N_BINCL which
541 was eliminated by the linker. */
543 info->file_types = ((struct stab_types **)
544 xrealloc ((PTR) info->file_types,
546 * sizeof *info->file_types)));
547 info->file_types[info->files - 1] = NULL;
551 if (! debug_record_line (dhandle, desc,
552 value + info->function_start_offset))
557 if (! debug_start_common_block (dhandle, string))
562 if (! debug_end_common_block (dhandle, string))
566 /* FIXME: gdb checks the string for N_STSYM, N_LCSYM or N_ROSYM
567 symbols, and if it does not start with :S, gdb relocates the
568 value to the start of the section. gcc always seems to use
569 :S, so we don't worry about this. */
574 colon = strchr (string, ':');
576 && (colon[1] == 'f' || colon[1] == 'F'))
578 if (info->within_function)
580 if (! debug_end_function (dhandle, value))
583 /* For stabs in sections, line numbers and block addresses
584 are offsets from the start of the function. */
586 info->function_start_offset = value;
587 info->within_function = true;
590 if (! parse_stab_string (dhandle, info, type, desc, value, string))
596 if (string != NULL && strcmp (string, "gcc2_compiled.") == 0)
597 info->gcc_compiled = 2;
598 else if (string != NULL && strcmp (string, "gcc_compiled.") == 0)
599 info->gcc_compiled = 1;
601 info->n_opt_found = true;
610 info->last_type = type;
615 /* Parse the stabs string. */
618 parse_stab_string (dhandle, info, stabtype, desc, value, string)
620 struct stab_handle *info;
634 p = strchr (string, ':');
649 /* GCC 2.x puts the line number in desc. SunOS apparently puts in
650 the number of bytes occupied by a type or object, which we
652 if (info->gcc_compiled >= 2)
657 /* FIXME: Sometimes the special C++ names start with '.'. */
659 if (string[0] == '$')
667 /* Was: name = "vptr"; */
673 /* This was an anonymous type that was never fixed up. */
676 /* SunPRO (3.0 at least) static variable encoding. */
679 warn_stab (string, "unknown C++ encoded name");
686 if (p == string || (string[0] == ' ' && p == string + 1))
689 name = savestring (string, p - string);
693 if (isdigit ((unsigned char) *p) || *p == '(' || *p == '-')
701 /* c is a special case, not followed by a type-number.
702 SYMBOL:c=iVALUE for an integer constant symbol.
703 SYMBOL:c=rVALUE for a floating constant symbol.
704 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
705 e.g. "b:c=e6,0" for "const b = blob1"
706 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
716 /* Floating point constant. */
717 if (! debug_record_float_const (dhandle, name, atof (p)))
721 /* Integer constant. */
722 /* Defining integer constants this way is kind of silly,
723 since 'e' constants allows the compiler to give not only
724 the value, but the type as well. C has at least int,
725 long, unsigned int, and long long as constant types;
726 other languages probably should have at least unsigned as
727 well as signed constants. */
728 if (! debug_record_int_const (dhandle, name, atoi (p)))
732 /* SYMBOL:c=eTYPE,INTVALUE for a constant symbol whose value
733 can be represented as integral.
734 e.g. "b:c=e6,0" for "const b = blob1"
735 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
736 dtype = parse_stab_type (dhandle, info, (const char *) NULL,
737 &p, (debug_type **) NULL);
738 if (dtype == DEBUG_TYPE_NULL)
745 if (! debug_record_typed_const (dhandle, name, dtype, atoi (p)))
756 /* The name of a caught exception. */
757 dtype = parse_stab_type (dhandle, info, (const char *) NULL,
758 &p, (debug_type **) NULL);
759 if (dtype == DEBUG_TYPE_NULL)
761 if (! debug_record_label (dhandle, name, dtype, value))
767 /* A function definition. */
768 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
769 (debug_type **) NULL);
770 if (dtype == DEBUG_TYPE_NULL)
772 if (! debug_record_function (dhandle, name, dtype, type == 'F', value))
775 /* Sun acc puts declared types of arguments here. We don't care
776 about their actual types (FIXME -- we should remember the whole
777 function prototype), but the list may define some new types
778 that we have to remember, so we must scan it now. */
782 if (parse_stab_type (dhandle, info, (const char *) NULL, &p,
783 (debug_type **) NULL)
791 /* A global symbol. The value must be extracted from the symbol
793 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
794 (debug_type **) NULL);
795 if (dtype == DEBUG_TYPE_NULL)
797 if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_GLOBAL,
802 /* This case is faked by a conditional above, when there is no
803 code letter in the dbx data. Dbx data never actually
807 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
808 (debug_type **) NULL);
809 if (dtype == DEBUG_TYPE_NULL)
811 if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_LOCAL,
817 /* A function parameter. */
819 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
820 (debug_type **) NULL);
823 /* pF is a two-letter code that means a function parameter in
824 Fortran. The type-number specifies the type of the return
825 value. Translate it into a pointer-to-function type. */
827 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
828 (debug_type **) NULL);
829 if (dtype != DEBUG_TYPE_NULL)
830 dtype = debug_make_pointer_type (dhandle,
831 debug_make_function_type (dhandle,
834 if (dtype == DEBUG_TYPE_NULL)
836 if (! debug_record_parameter (dhandle, name, dtype, DEBUG_PARM_STACK,
840 /* FIXME: At this point gdb considers rearranging the parameter
841 address on a big endian machine if it is smaller than an int.
842 We have no way to do that, since we don't really know much
848 if (stabtype == N_FUN)
850 /* Prototype of a function referenced by this file. */
854 if (parse_stab_type (dhandle, info, (const char *) NULL, &p,
855 (debug_type **) NULL)
863 /* Parameter which is in a register. */
864 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
865 (debug_type **) NULL);
866 if (dtype == DEBUG_TYPE_NULL)
868 if (! debug_record_parameter (dhandle, name, dtype, DEBUG_PARM_REG,
874 /* Register variable (either global or local). */
875 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
876 (debug_type **) NULL);
877 if (dtype == DEBUG_TYPE_NULL)
879 if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_REGISTER,
883 /* FIXME: At this point gdb checks to combine pairs of 'p' and
884 'r' stabs into a single 'P' stab. */
889 /* Static symbol at top level of file */
890 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
891 (debug_type **) NULL);
892 if (dtype == DEBUG_TYPE_NULL)
894 if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_STATIC,
901 dtype = parse_stab_type (dhandle, info, name, &p, &slot);
902 if (dtype == DEBUG_TYPE_NULL)
906 /* A nameless type. Nothing to do. */
910 dtype = debug_name_type (dhandle, name, dtype);
911 if (dtype == DEBUG_TYPE_NULL)
920 /* Struct, union, or enum tag. For GNU C++, this can be be followed
921 by 't' which means we are typedef'ing it as well. */
925 /* FIXME: gdb sets synonym to true if the current language
934 dtype = parse_stab_type (dhandle, info, name, &p, &slot);
935 if (dtype == DEBUG_TYPE_NULL)
940 dtype = debug_tag_type (dhandle, name, dtype);
941 if (dtype == DEBUG_TYPE_NULL)
946 /* See if we have a cross reference to this tag which we can now
949 register struct stab_tag **pst;
951 for (pst = &info->tags; *pst != NULL; pst = &(*pst)->next)
953 if ((*pst)->name[0] == name[0]
954 && strcmp ((*pst)->name, name) == 0)
956 (*pst)->slot = dtype;
965 dtype = debug_name_type (dhandle, name, dtype);
966 if (dtype == DEBUG_TYPE_NULL)
976 /* Static symbol of local scope */
977 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
978 (debug_type **) NULL);
979 if (dtype == DEBUG_TYPE_NULL)
981 /* FIXME: gdb checks os9k_stabs here. */
982 if (! stab_record_variable (dhandle, info, name, dtype,
983 DEBUG_LOCAL_STATIC, value))
988 /* Reference parameter. */
989 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
990 (debug_type **) NULL);
991 if (dtype == DEBUG_TYPE_NULL)
993 if (! debug_record_parameter (dhandle, name, dtype, DEBUG_PARM_REFERENCE,
999 /* Reference parameter which is in a register. */
1000 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
1001 (debug_type **) NULL);
1002 if (dtype == DEBUG_TYPE_NULL)
1004 if (! debug_record_parameter (dhandle, name, dtype, DEBUG_PARM_REF_REG,
1010 /* This is used by Sun FORTRAN for "function result value".
1011 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
1012 that Pascal uses it too, but when I tried it Pascal used
1013 "x:3" (local symbol) instead. */
1014 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
1015 (debug_type **) NULL);
1016 if (dtype == DEBUG_TYPE_NULL)
1018 if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_LOCAL,
1028 /* FIXME: gdb converts structure values to structure pointers in a
1029 couple of cases, depending upon the target. */
1034 /* Parse a stabs type. The typename argument is non-NULL if this is a
1035 typedef or a tag definition. The pp argument points to the stab
1036 string, and is updated. The slotp argument points to a place to
1037 store the slot used if the type is being defined. */
1040 parse_stab_type (dhandle, info, typename, pp, slotp)
1042 struct stab_handle *info;
1043 const char *typename;
1062 /* Read type number if present. The type number may be omitted.
1063 for instance in a two-dimensional array declared with type
1064 "ar1;1;10;ar1;1;10;4". */
1065 if (! isdigit ((unsigned char) **pp) && **pp != '(' && **pp != '-')
1067 /* 'typenums=' not present, type is anonymous. Read and return
1068 the definition, but don't put it in the type vector. */
1069 typenums[0] = typenums[1] = -1;
1073 if (! parse_stab_type_number (pp, typenums))
1074 return DEBUG_TYPE_NULL;
1078 /* Type is not being defined here. Either it already
1079 exists, or this is a forward reference to it. */
1080 return stab_find_type (dhandle, info, typenums);
1083 /* Only set the slot if the type is being defined. This means
1084 that the mapping from type numbers to types will only record
1085 the name of the typedef which defines a type. If we don't do
1086 this, then something like
1089 will record that i is of type foo. Unfortunately, stabs
1090 information is ambiguous about variable types. For this code,
1094 the stabs information records both i and j as having the same
1095 type. This could be fixed by patching the compiler. */
1096 if (slotp != NULL && typenums[0] >= 0 && typenums[1] >= 0)
1097 *slotp = stab_find_slot (info, typenums);
1099 /* Type is being defined here. */
1105 const char *p = *pp + 1;
1108 if (isdigit ((unsigned char) *p) || *p == '(' || *p == '-')
1114 /* Type attributes. */
1117 for (; *p != ';'; ++p)
1122 return DEBUG_TYPE_NULL;
1130 size = atoi (attr + 1);
1140 /* Ignore unrecognized type attributes, so future
1141 compilers can invent new ones. */
1154 enum debug_type_kind code;
1155 const char *q1, *q2, *p;
1157 /* A cross reference to another type. */
1162 code = DEBUG_KIND_STRUCT;
1165 code = DEBUG_KIND_UNION;
1168 code = DEBUG_KIND_ENUM;
1171 /* Complain and keep going, so compilers can invent new
1172 cross-reference types. */
1173 warn_stab (orig, "unrecognized cross reference type");
1174 code = DEBUG_KIND_STRUCT;
1179 q1 = strchr (*pp, '<');
1180 p = strchr (*pp, ':');
1184 return DEBUG_TYPE_NULL;
1186 while (q1 != NULL && p > q1 && p[1] == ':')
1188 q2 = strchr (q1, '>');
1189 if (q2 == NULL || q2 < p)
1192 p = strchr (p, ':');
1196 return DEBUG_TYPE_NULL;
1200 dtype = stab_find_tagged_type (dhandle, info, *pp, p - *pp, code);
1222 /* This type is defined as another type. */
1227 /* Peek ahead at the number to detect void. */
1228 if (! parse_stab_type_number (pp, xtypenums))
1229 return DEBUG_TYPE_NULL;
1231 if (typenums[0] == xtypenums[0] && typenums[1] == xtypenums[1])
1233 /* This type is being defined as itself, which means that
1235 dtype = debug_make_void_type (dhandle);
1241 /* Go back to the number and have parse_stab_type get it.
1242 This means that we can deal with something like
1243 t(1,2)=(3,4)=... which the Lucid compiler uses. */
1244 dtype = parse_stab_type (dhandle, info, (const char *) NULL,
1245 pp, (debug_type **) NULL);
1246 if (dtype == DEBUG_TYPE_NULL)
1247 return DEBUG_TYPE_NULL;
1250 if (typenums[0] != -1)
1252 if (! stab_record_type (dhandle, info, typenums, dtype))
1253 return DEBUG_TYPE_NULL;
1260 dtype = debug_make_pointer_type (dhandle,
1261 parse_stab_type (dhandle, info,
1262 (const char *) NULL,
1264 (debug_type **) NULL));
1268 /* Reference to another type. */
1269 dtype = (debug_make_reference_type
1271 parse_stab_type (dhandle, info, (const char *) NULL, pp,
1272 (debug_type **) NULL)));
1276 /* Function returning another type. */
1277 /* FIXME: gdb checks os9k_stabs here. */
1278 dtype = (debug_make_function_type
1280 parse_stab_type (dhandle, info, (const char *) NULL, pp,
1281 (debug_type **) NULL)));
1285 /* Const qualifier on some type (Sun). */
1286 /* FIXME: gdb accepts 'c' here if os9k_stabs. */
1287 dtype = debug_make_const_type (dhandle,
1288 parse_stab_type (dhandle, info,
1289 (const char *) NULL,
1291 (debug_type **) NULL));
1295 /* Volatile qual on some type (Sun). */
1296 /* FIXME: gdb accepts 'i' here if os9k_stabs. */
1297 dtype = (debug_make_volatile_type
1299 parse_stab_type (dhandle, info, (const char *) NULL, pp,
1300 (debug_type **) NULL)));
1304 /* Offset (class & variable) type. This is used for a pointer
1305 relative to an object. */
1312 domain = parse_stab_type (dhandle, info, (const char *) NULL, pp,
1313 (debug_type **) NULL);
1314 if (domain == DEBUG_TYPE_NULL)
1315 return DEBUG_TYPE_NULL;
1320 return DEBUG_TYPE_NULL;
1324 memtype = parse_stab_type (dhandle, info, (const char *) NULL, pp,
1325 (debug_type **) NULL);
1326 if (memtype == DEBUG_TYPE_NULL)
1327 return DEBUG_TYPE_NULL;
1329 dtype = debug_make_offset_type (dhandle, domain, memtype);
1334 /* Method (class & fn) type. */
1337 debug_type return_type;
1340 return_type = parse_stab_type (dhandle, info, (const char *) NULL,
1341 pp, (debug_type **) NULL);
1342 if (return_type == DEBUG_TYPE_NULL)
1343 return DEBUG_TYPE_NULL;
1347 return DEBUG_TYPE_NULL;
1350 dtype = debug_make_method_type (dhandle, return_type,
1351 DEBUG_TYPE_NULL, NULL);
1356 debug_type return_type;
1361 domain = parse_stab_type (dhandle, info, (const char *) NULL,
1362 pp, (debug_type **) NULL);
1363 if (domain == DEBUG_TYPE_NULL)
1364 return DEBUG_TYPE_NULL;
1369 return DEBUG_TYPE_NULL;
1373 return_type = parse_stab_type (dhandle, info, (const char *) NULL,
1374 pp, (debug_type **) NULL);
1375 if (return_type == DEBUG_TYPE_NULL)
1376 return DEBUG_TYPE_NULL;
1379 args = (debug_type *) xmalloc (alloc * sizeof *args);
1386 return DEBUG_TYPE_NULL;
1393 args = ((debug_type *)
1394 xrealloc ((PTR) args, alloc * sizeof *args));
1397 args[n] = parse_stab_type (dhandle, info, (const char *) NULL,
1398 pp, (debug_type **) NULL);
1399 if (args[n] == DEBUG_TYPE_NULL)
1400 return DEBUG_TYPE_NULL;
1405 /* If the last type is void, then this function does not
1406 take a variable number of arguments. If the last is not
1407 void, then it does. */
1409 && debug_get_type_kind (dhandle, args[n - 1]) == DEBUG_KIND_VOID)
1416 args = ((debug_type *)
1417 xrealloc ((PTR) args, alloc * sizeof *args));
1420 args[n] = debug_make_ellipsis_type (dhandle);
1421 if (args[n] == DEBUG_TYPE_NULL)
1422 return DEBUG_TYPE_NULL;
1426 args[n] = DEBUG_TYPE_NULL;
1428 dtype = debug_make_method_type (dhandle, return_type, domain, args);
1434 dtype = parse_stab_range_type (dhandle, info, typename, pp, typenums);
1438 /* FIXME: gdb checks os9k_stabs here. */
1439 /* Sun ACC builtin int type. */
1440 dtype = parse_stab_sun_builtin_type (dhandle, pp);
1444 /* Sun ACC builtin float type. */
1445 dtype = parse_stab_sun_floating_type (dhandle, pp);
1449 /* Enumeration type. */
1450 dtype = parse_stab_enum_type (dhandle, pp);
1455 /* Struct or union type. */
1456 dtype = parse_stab_struct_type (dhandle, info, typename, pp,
1457 descriptor == 's', typenums);
1465 return DEBUG_TYPE_NULL;
1469 dtype = parse_stab_array_type (dhandle, info, pp, stringp);
1473 dtype = debug_make_set_type (dhandle,
1474 parse_stab_type (dhandle, info,
1475 (const char *) NULL,
1477 (debug_type **) NULL),
1483 return DEBUG_TYPE_NULL;
1486 if (dtype == DEBUG_TYPE_NULL)
1487 return DEBUG_TYPE_NULL;
1489 if (typenums[0] != -1)
1491 if (! stab_record_type (dhandle, info, typenums, dtype))
1492 return DEBUG_TYPE_NULL;
1497 if (! debug_record_type_size (dhandle, dtype, (unsigned int) size))
1504 /* Read a number by which a type is referred to in dbx data, or
1505 perhaps read a pair (FILENUM, TYPENUM) in parentheses. Just a
1506 single number N is equivalent to (0,N). Return the two numbers by
1507 storing them in the vector TYPENUMS. */
1510 parse_stab_type_number (pp, typenums)
1521 typenums[1] = (int) parse_number (pp, (boolean *) NULL);
1526 typenums[0] = (int) parse_number (pp, (boolean *) NULL);
1533 typenums[1] = (int) parse_number (pp, (boolean *) NULL);
1545 /* Parse a range type. */
1548 parse_stab_range_type (dhandle, info, typename, pp, typenums)
1550 struct stab_handle *info;
1551 const char *typename;
1553 const int *typenums;
1557 boolean self_subrange;
1558 debug_type index_type;
1559 const char *s2, *s3;
1560 bfd_signed_vma n2, n3;
1565 index_type = DEBUG_TYPE_NULL;
1567 /* First comes a type we are a subrange of.
1568 In C it is usually 0, 1 or the type being defined. */
1569 if (! parse_stab_type_number (pp, rangenums))
1570 return DEBUG_TYPE_NULL;
1572 self_subrange = (rangenums[0] == typenums[0]
1573 && rangenums[1] == typenums[1]);
1578 index_type = parse_stab_type (dhandle, info, (const char *) NULL,
1579 pp, (debug_type **) NULL);
1580 if (index_type == DEBUG_TYPE_NULL)
1581 return DEBUG_TYPE_NULL;
1587 /* The remaining two operands are usually lower and upper bounds of
1588 the range. But in some special cases they mean something else. */
1590 n2 = parse_number (pp, &ov2);
1594 return DEBUG_TYPE_NULL;
1599 n3 = parse_number (pp, &ov3);
1603 return DEBUG_TYPE_NULL;
1609 /* gcc will emit range stabs for long long types. Handle this
1610 as a special case. FIXME: This needs to be more general. */
1611 #define LLLOW "01000000000000000000000;"
1612 #define LLHIGH "0777777777777777777777;"
1613 #define ULLHIGH "01777777777777777777777;"
1614 if (index_type == DEBUG_TYPE_NULL)
1616 if (strncmp (s2, LLLOW, sizeof LLLOW - 1) == 0
1617 && strncmp (s3, LLHIGH, sizeof LLHIGH - 1) == 0)
1618 return debug_make_int_type (dhandle, 8, false);
1621 && strncmp (s3, ULLHIGH, sizeof ULLHIGH - 1) == 0)
1622 return debug_make_int_type (dhandle, 8, true);
1625 warn_stab (orig, "numeric overflow");
1628 if (index_type == DEBUG_TYPE_NULL)
1630 /* A type defined as a subrange of itself, with both bounds 0,
1632 if (self_subrange && n2 == 0 && n3 == 0)
1633 return debug_make_void_type (dhandle);
1635 /* If n3 is zero and n2 is positive, this is a floating point
1636 type, and n2 is the number of bytes. */
1637 if (n3 == 0 && n2 > 0)
1638 return debug_make_float_type (dhandle, n2);
1640 /* If the upper bound is -1, this is an unsigned int. */
1641 if (n2 == 0 && n3 == -1)
1643 /* When gcc is used with -gstabs, but not -gstabs+, it will emit
1644 long long int:t6=r1;0;-1;
1645 long long unsigned int:t7=r1;0;-1;
1646 We hack here to handle this reasonably. */
1647 if (typename != NULL)
1649 if (strcmp (typename, "long long int") == 0)
1650 return debug_make_int_type (dhandle, 8, false);
1651 else if (strcmp (typename, "long long unsigned int") == 0)
1652 return debug_make_int_type (dhandle, 8, true);
1654 /* FIXME: The size here really depends upon the target. */
1655 return debug_make_int_type (dhandle, 4, true);
1658 /* A range of 0 to 127 is char. */
1659 if (self_subrange && n2 == 0 && n3 == 127)
1660 return debug_make_int_type (dhandle, 1, false);
1662 /* FIXME: gdb checks for the language CHILL here. */
1667 return debug_make_int_type (dhandle, - n3, true);
1668 else if (n3 == 0xff)
1669 return debug_make_int_type (dhandle, 1, true);
1670 else if (n3 == 0xffff)
1671 return debug_make_int_type (dhandle, 2, true);
1672 /* -1 is used for the upper bound of (4 byte) "unsigned int"
1673 and "unsigned long", and we already checked for that, so
1674 don't need to test for it here. */
1678 && (self_subrange || n2 == -8))
1679 return debug_make_int_type (dhandle, - n2, true);
1680 else if (n2 == - n3 - 1)
1683 return debug_make_int_type (dhandle, 1, false);
1684 else if (n3 == 0x7fff)
1685 return debug_make_int_type (dhandle, 2, false);
1686 else if (n3 == 0x7fffffff)
1687 return debug_make_int_type (dhandle, 4, false);
1691 /* At this point I don't have the faintest idea how to deal with a
1692 self_subrange type; I'm going to assume that this is used as an
1693 idiom, and that all of them are special cases. So . . . */
1697 return DEBUG_TYPE_NULL;
1700 index_type = stab_find_type (dhandle, info, rangenums);
1701 if (index_type == DEBUG_TYPE_NULL)
1703 /* Does this actually ever happen? Is that why we are worrying
1704 about dealing with it rather than just calling error_type? */
1705 warn_stab (orig, "missing index type");
1706 index_type = debug_make_int_type (dhandle, 4, false);
1709 return debug_make_range_type (dhandle, index_type, n2, n3);
1712 /* Sun's ACC uses a somewhat saner method for specifying the builtin
1713 typedefs in every file (for int, long, etc):
1715 type = b <signed> <width>; <offset>; <nbits>
1716 signed = u or s. Possible c in addition to u or s (for char?).
1717 offset = offset from high order bit to start bit of type.
1718 width is # bytes in object of this type, nbits is # bits in type.
1720 The width/offset stuff appears to be for small objects stored in
1721 larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
1725 parse_stab_sun_builtin_type (dhandle, pp)
1745 return DEBUG_TYPE_NULL;
1749 /* For some odd reason, all forms of char put a c here. This is strange
1750 because no other type has this honor. We can safely ignore this because
1751 we actually determine 'char'acterness by the number of bits specified in
1756 /* The first number appears to be the number of bytes occupied
1757 by this type, except that unsigned short is 4 instead of 2.
1758 Since this information is redundant with the third number,
1759 we will ignore it. */
1760 (void) parse_number (pp, (boolean *) NULL);
1764 return DEBUG_TYPE_NULL;
1768 /* The second number is always 0, so ignore it too. */
1769 (void) parse_number (pp, (boolean *) NULL);
1773 return DEBUG_TYPE_NULL;
1777 /* The third number is the number of bits for this type. */
1778 bits = parse_number (pp, (boolean *) NULL);
1780 /* The type *should* end with a semicolon. If it are embedded
1781 in a larger type the semicolon may be the only way to know where
1782 the type ends. If this type is at the end of the stabstring we
1783 can deal with the omitted semicolon (but we don't have to like
1784 it). Don't bother to complain(), Sun's compiler omits the semicolon
1790 return debug_make_void_type (dhandle);
1792 return debug_make_int_type (dhandle, bits / 8, unsignedp);
1795 /* Parse a builtin floating type generated by the Sun compiler. */
1798 parse_stab_sun_floating_type (dhandle, pp)
1808 /* The first number has more details about the type, for example
1810 details = parse_number (pp, (boolean *) NULL);
1814 return DEBUG_TYPE_NULL;
1817 /* The second number is the number of bytes occupied by this type */
1818 bytes = parse_number (pp, (boolean *) NULL);
1822 return DEBUG_TYPE_NULL;
1825 if (details == NF_COMPLEX
1826 || details == NF_COMPLEX16
1827 || details == NF_COMPLEX32)
1828 return debug_make_complex_type (dhandle, bytes);
1830 return debug_make_float_type (dhandle, bytes);
1833 /* Handle an enum type. */
1836 parse_stab_enum_type (dhandle, pp)
1842 bfd_signed_vma *values;
1848 /* FIXME: gdb checks os9k_stabs here. */
1850 /* The aix4 compiler emits an extra field before the enum members;
1851 my guess is it's a type of some sort. Just ignore it. */
1859 /* Read the value-names and their values.
1860 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
1861 A semicolon or comma instead of a NAME means the end. */
1863 names = (const char **) xmalloc (alloc * sizeof *names);
1864 values = (bfd_signed_vma *) xmalloc (alloc * sizeof *values);
1866 while (**pp != '\0' && **pp != ';' && **pp != ',')
1876 name = savestring (*pp, p - *pp);
1879 val = (bfd_signed_vma) parse_number (pp, (boolean *) NULL);
1883 return DEBUG_TYPE_NULL;
1890 names = ((const char **)
1891 xrealloc ((PTR) names, alloc * sizeof *names));
1892 values = ((bfd_signed_vma *)
1893 xrealloc ((PTR) values, alloc * sizeof *values));
1907 return debug_make_enum_type (dhandle, names, values);
1910 /* Read the description of a structure (or union type) and return an object
1911 describing the type.
1913 PP points to a character pointer that points to the next unconsumed token
1914 in the the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;",
1915 *PP will point to "4a:1,0,32;;". */
1918 parse_stab_struct_type (dhandle, info, tagname, pp, structp, typenums)
1920 struct stab_handle *info;
1921 const char *tagname;
1924 const int *typenums;
1928 debug_baseclass *baseclasses;
1929 debug_field *fields;
1931 debug_method *methods;
1932 debug_type vptrbase;
1938 size = parse_number (pp, (boolean *) NULL);
1940 /* Get the other information. */
1941 if (! parse_stab_baseclasses (dhandle, info, pp, &baseclasses)
1942 || ! parse_stab_struct_fields (dhandle, info, pp, &fields, &statics)
1943 || ! parse_stab_members (dhandle, info, tagname, pp, typenums, &methods)
1944 || ! parse_stab_tilde_field (dhandle, info, pp, typenums, &vptrbase,
1946 return DEBUG_TYPE_NULL;
1949 && baseclasses == NULL
1951 && vptrbase == DEBUG_TYPE_NULL
1953 return debug_make_struct_type (dhandle, structp, size, fields);
1955 return debug_make_object_type (dhandle, structp, size, fields, baseclasses,
1956 methods, vptrbase, ownvptr);
1959 /* The stabs for C++ derived classes contain baseclass information which
1960 is marked by a '!' character after the total size. This function is
1961 called when we encounter the baseclass marker, and slurps up all the
1962 baseclass information.
1964 Immediately following the '!' marker is the number of base classes that
1965 the class is derived from, followed by information for each base class.
1966 For each base class, there are two visibility specifiers, a bit offset
1967 to the base class information within the derived class, a reference to
1968 the type for the base class, and a terminating semicolon.
1970 A typical example, with two base classes, would be "!2,020,19;0264,21;".
1972 Baseclass information marker __________________|| | | | | | |
1973 Number of baseclasses __________________________| | | | | | |
1974 Visibility specifiers (2) ________________________| | | | | |
1975 Offset in bits from start of class _________________| | | | |
1976 Type number for base class ___________________________| | | |
1977 Visibility specifiers (2) _______________________________| | |
1978 Offset in bits from start of class ________________________| |
1979 Type number of base class ____________________________________|
1981 Return true for success, false for failure. */
1984 parse_stab_baseclasses (dhandle, info, pp, retp)
1986 struct stab_handle *info;
1988 debug_baseclass **retp;
1992 debug_baseclass *classes;
2000 /* No base classes. */
2005 c = (unsigned int) parse_number (pp, (boolean *) NULL);
2014 classes = (debug_baseclass *) xmalloc ((c + 1) * sizeof (**retp));
2016 for (i = 0; i < c; i++)
2019 enum debug_visibility visibility;
2032 warn_stab (orig, "unknown virtual character for baseclass");
2041 visibility = DEBUG_VISIBILITY_PRIVATE;
2044 visibility = DEBUG_VISIBILITY_PROTECTED;
2047 visibility = DEBUG_VISIBILITY_PUBLIC;
2050 warn_stab (orig, "unknown visibility character for baseclass");
2051 visibility = DEBUG_VISIBILITY_PUBLIC;
2056 /* The remaining value is the bit offset of the portion of the
2057 object corresponding to this baseclass. Always zero in the
2058 absence of multiple inheritance. */
2059 bitpos = parse_number (pp, (boolean *) NULL);
2067 type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
2068 (debug_type **) NULL);
2069 if (type == DEBUG_TYPE_NULL)
2072 classes[i] = debug_make_baseclass (dhandle, type, bitpos, virtual,
2074 if (classes[i] == DEBUG_BASECLASS_NULL)
2082 classes[i] = DEBUG_BASECLASS_NULL;
2089 /* Read struct or class data fields. They have the form:
2091 NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
2093 At the end, we see a semicolon instead of a field.
2095 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
2098 The optional VISIBILITY is one of:
2100 '/0' (VISIBILITY_PRIVATE)
2101 '/1' (VISIBILITY_PROTECTED)
2102 '/2' (VISIBILITY_PUBLIC)
2103 '/9' (VISIBILITY_IGNORE)
2105 or nothing, for C style fields with public visibility.
2107 Returns 1 for success, 0 for failure. */
2110 parse_stab_struct_fields (dhandle, info, pp, retp, staticsp)
2112 struct stab_handle *info;
2119 debug_field *fields;
2130 fields = (debug_field *) xmalloc (alloc * sizeof *fields);
2133 /* FIXME: gdb checks os9k_stabs here. */
2137 /* Add 1 to c to leave room for NULL pointer at end. */
2141 fields = ((debug_field *)
2142 xrealloc ((PTR) fields, alloc * sizeof *fields));
2145 /* If it starts with CPLUS_MARKER it is a special abbreviation,
2146 unless the CPLUS_MARKER is followed by an underscore, in
2147 which case it is just the name of an anonymous type, which we
2148 should handle like any other type name. We accept either '$'
2149 or '.', because a field name can never contain one of these
2150 characters except as a CPLUS_MARKER. */
2152 if ((*p == '$' || *p == '.') && p[1] != '_')
2155 if (! parse_stab_cpp_abbrev (dhandle, info, pp, fields + c))
2161 /* Look for the ':' that separates the field name from the field
2162 values. Data members are delimited by a single ':', while member
2163 functions are delimited by a pair of ':'s. When we hit the member
2164 functions (if any), terminate scan loop and return. */
2166 p = strchr (p, ':');
2176 if (! parse_stab_one_struct_field (dhandle, info, pp, p, fields + c,
2183 fields[c] = DEBUG_FIELD_NULL;
2190 /* Special GNU C++ name. */
2193 parse_stab_cpp_abbrev (dhandle, info, pp, retp)
2195 struct stab_handle *info;
2203 const char *typename;
2207 *retp = DEBUG_FIELD_NULL;
2221 /* At this point, *pp points to something like "22:23=*22...", where
2222 the type number before the ':' is the "context" and everything
2223 after is a regular type definition. Lookup the type, find it's
2224 name, and construct the field name. */
2226 context = parse_stab_type (dhandle, info, (const char *) NULL, pp,
2227 (debug_type **) NULL);
2228 if (context == DEBUG_TYPE_NULL)
2234 /* $vf -- a virtual function table pointer. */
2238 /* $vb -- a virtual bsomethingorother */
2239 typename = debug_get_type_name (dhandle, context);
2240 if (typename == NULL)
2242 warn_stab (orig, "unnamed $vb type");
2245 name = concat ("_vb$", typename, (const char *) NULL);
2248 warn_stab (orig, "unrecognized C++ abbreviation");
2249 name = "INVALID_CPLUSPLUS_ABBREV";
2260 type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
2261 (debug_type **) NULL);
2269 bitpos = parse_number (pp, (boolean *) NULL);
2277 *retp = debug_make_field (dhandle, name, type, bitpos, 0,
2278 DEBUG_VISIBILITY_PRIVATE);
2279 if (*retp == DEBUG_FIELD_NULL)
2285 /* Parse a single field in a struct or union. */
2288 parse_stab_one_struct_field (dhandle, info, pp, p, retp, staticsp)
2290 struct stab_handle *info;
2298 enum debug_visibility visibility;
2305 /* FIXME: gdb checks ARM_DEMANGLING here. */
2307 name = savestring (*pp, p - *pp);
2312 visibility = DEBUG_VISIBILITY_PUBLIC;
2319 visibility = DEBUG_VISIBILITY_PRIVATE;
2322 visibility = DEBUG_VISIBILITY_PROTECTED;
2325 visibility = DEBUG_VISIBILITY_PUBLIC;
2328 warn_stab (orig, "unknown visibility character for field");
2329 visibility = DEBUG_VISIBILITY_PUBLIC;
2335 type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
2336 (debug_type **) NULL);
2337 if (type == DEBUG_TYPE_NULL)
2344 /* This is a static class member. */
2346 p = strchr (*pp, ';');
2353 varname = savestring (*pp, p - *pp);
2357 *retp = debug_make_static_member (dhandle, name, type, varname,
2371 bitpos = parse_number (pp, (boolean *) NULL);
2379 bitsize = parse_number (pp, (boolean *) NULL);
2387 if (bitpos == 0 && bitsize == 0)
2389 /* This can happen in two cases: (1) at least for gcc 2.4.5 or
2390 so, it is a field which has been optimized out. The correct
2391 stab for this case is to use VISIBILITY_IGNORE, but that is a
2392 recent invention. (2) It is a 0-size array. For example
2393 union { int num; char str[0]; } foo. Printing "<no value>"
2394 for str in "p foo" is OK, since foo.str (and thus foo.str[3])
2395 will continue to work, and a 0-size array as a whole doesn't
2396 have any contents to print.
2398 I suspect this probably could also happen with gcc -gstabs
2399 (not -gstabs+) for static fields, and perhaps other C++
2400 extensions. Hopefully few people use -gstabs with gdb, since
2401 it is intended for dbx compatibility. */
2402 visibility = DEBUG_VISIBILITY_IGNORE;
2405 /* FIXME: gdb does some stuff here to mark fields as unpacked. */
2407 *retp = debug_make_field (dhandle, name, type, bitpos, bitsize, visibility);
2412 /* Read member function stabs info for C++ classes. The form of each member
2415 NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;
2417 An example with two member functions is:
2419 afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;
2421 For the case of overloaded operators, the format is op$::*.funcs, where
2422 $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
2423 name (such as `+=') and `.' marks the end of the operator name. */
2426 parse_stab_members (dhandle, info, tagname, pp, typenums, retp)
2428 struct stab_handle *info;
2429 const char *tagname;
2431 const int *typenums;
2432 debug_method **retp;
2435 debug_method *methods;
2451 debug_method_variant *variants;
2453 unsigned int allocvars;
2454 debug_type look_ahead_type;
2456 p = strchr (*pp, ':');
2457 if (p == NULL || p[1] != ':')
2460 /* FIXME: Some systems use something other than '$' here. */
2461 if ((*pp)[0] != 'o' || (*pp)[1] != 'p' || (*pp)[2] != '$')
2463 name = savestring (*pp, p - *pp);
2468 /* This is a completely wierd case. In order to stuff in the
2469 names that might contain colons (the usual name delimiter),
2470 Mike Tiemann defined a different name format which is
2471 signalled if the identifier is "op$". In that case, the
2472 format is "op$::XXXX." where XXXX is the name. This is
2473 used for names like "+" or "=". YUUUUUUUK! FIXME! */
2475 for (p = *pp; *p != '.' && *p != '\0'; p++)
2482 name = savestring (*pp, p - *pp);
2487 variants = ((debug_method_variant *)
2488 xmalloc (allocvars * sizeof *variants));
2491 look_ahead_type = DEBUG_TYPE_NULL;
2497 enum debug_visibility visibility;
2498 boolean constp, volatilep, staticp;
2501 const char *physname;
2503 if (look_ahead_type != DEBUG_TYPE_NULL)
2505 /* g++ version 1 kludge */
2506 type = look_ahead_type;
2507 look_ahead_type = DEBUG_TYPE_NULL;
2511 type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
2512 (debug_type **) NULL);
2513 if (type == DEBUG_TYPE_NULL)
2523 p = strchr (*pp, ';');
2530 argtypes = savestring (*pp, p - *pp);
2536 visibility = DEBUG_VISIBILITY_PRIVATE;
2539 visibility = DEBUG_VISIBILITY_PROTECTED;
2542 visibility = DEBUG_VISIBILITY_PUBLIC;
2552 /* Normal function. */
2556 /* const member function. */
2561 /* volatile member function. */
2566 /* const volatile member function. */
2574 /* File compiled with g++ version 1; no information. */
2577 warn_stab (orig, "const/volatile indicator missing");
2585 /* virtual member function, followed by index. The sign
2586 bit is set to distinguish pointers-to-methods from
2587 virtual function indicies. Since the array is in
2588 words, the quantity must be shifted left by 1 on 16
2589 bit machine, and by 2 on 32 bit machine, forcing the
2590 sign bit out, and usable as a valid index into the
2591 array. Remove the sign bit here. */
2593 voffset = parse_number (pp, (boolean *) NULL);
2600 voffset &= 0x7fffffff;
2603 if (**pp == ';' || *pp == '\0')
2605 /* Must be g++ version 1. */
2606 context = DEBUG_TYPE_NULL;
2610 /* Figure out from whence this virtual function
2611 came. It may belong to virtual function table of
2612 one of its baseclasses. */
2613 look_ahead_type = parse_stab_type (dhandle, info,
2614 (const char *) NULL,
2616 (debug_type **) NULL);
2619 /* g++ version 1 overloaded methods. */
2623 context = look_ahead_type;
2624 look_ahead_type = DEBUG_TYPE_NULL;
2636 /* static member function. */
2640 context = DEBUG_TYPE_NULL;
2644 warn_stab (orig, "member function type missing");
2646 context = DEBUG_TYPE_NULL;
2652 context = DEBUG_TYPE_NULL;
2656 /* If this is a method type which is not a stub--that is,
2657 the argument types are fully specified--then the argtypes
2658 string is actually the physical name of the function.
2659 Otherwise, the argtypes string is the mangled from of the
2660 argument types, and the physical name of the function,
2661 and the argument types, must be deduced from it. */
2663 if (debug_get_type_kind (dhandle, type) == DEBUG_KIND_METHOD
2664 && debug_get_parameter_types (dhandle, type) != NULL)
2665 physname = argtypes;
2668 debug_type class_type, return_type;
2670 class_type = stab_find_type (dhandle, info, typenums);
2671 if (class_type == DEBUG_TYPE_NULL)
2673 return_type = debug_get_return_type (dhandle, type);
2674 if (return_type == DEBUG_TYPE_NULL)
2679 type = parse_stab_argtypes (dhandle, info, class_type, name,
2680 tagname, return_type, argtypes,
2681 constp, volatilep, &physname);
2682 if (type == DEBUG_TYPE_NULL)
2686 if (cvars + 1 >= allocvars)
2689 variants = ((debug_method_variant *)
2690 xrealloc ((PTR) variants,
2691 allocvars * sizeof *variants));
2695 variants[cvars] = debug_make_method_variant (dhandle, physname,
2700 variants[cvars] = debug_make_static_method_variant (dhandle,
2706 if (variants[cvars] == DEBUG_METHOD_VARIANT_NULL)
2711 while (**pp != ';' && **pp != '\0');
2713 variants[cvars] = DEBUG_METHOD_VARIANT_NULL;
2721 methods = ((debug_method *)
2722 xrealloc ((PTR) methods, alloc * sizeof *methods));
2725 methods[c] = debug_make_method (dhandle, name, variants);
2730 if (methods != NULL)
2731 methods[c] = DEBUG_METHOD_NULL;
2738 /* Parse a string representing argument types for a method. Stabs
2739 tries to save space by packing argument types into a mangled
2740 string. This string should give us enough information to extract
2741 both argument types and the physical name of the function, given
2745 parse_stab_argtypes (dhandle, info, class_type, fieldname, tagname,
2746 return_type, argtypes, constp, volatilep, pphysname)
2748 struct stab_handle *info;
2749 debug_type class_type;
2750 const char *fieldname;
2751 const char *tagname;
2752 debug_type return_type;
2753 const char *argtypes;
2756 const char **pphysname;
2758 boolean is_full_physname_constructor;
2759 boolean is_constructor;
2760 boolean is_destructor;
2763 /* Constructors are sometimes handled specially. */
2764 is_full_physname_constructor = ((argtypes[0] == '_'
2765 && argtypes[1] == '_'
2766 && (isdigit ((unsigned char) argtypes[2])
2767 || argtypes[2] == 'Q'
2768 || argtypes[2] == 't'))
2769 || strncmp (argtypes, "__ct", 4) == 0);
2771 is_constructor = (is_full_physname_constructor
2773 && strcmp (fieldname, tagname) == 0));
2774 is_destructor = ((argtypes[0] == '_'
2775 && (argtypes[1] == '$' || argtypes[1] == '.')
2776 && argtypes[2] == '_')
2777 || strncmp (argtypes, "__dt", 4) == 0);
2779 if (is_destructor || is_full_physname_constructor)
2780 *pphysname = argtypes;
2784 const char *const_prefix;
2785 const char *volatile_prefix;
2787 unsigned int mangled_name_len;
2790 len = tagname == NULL ? 0 : strlen (tagname);
2791 const_prefix = constp ? "C" : "";
2792 volatile_prefix = volatilep ? "V" : "";
2795 sprintf (buf, "__%s%s", const_prefix, volatile_prefix);
2796 else if (tagname != NULL && strchr (tagname, '<') != NULL)
2798 /* Template methods are fully mangled. */
2799 sprintf (buf, "__%s%s", const_prefix, volatile_prefix);
2804 sprintf (buf, "__%s%s%d", const_prefix, volatile_prefix, len);
2806 mangled_name_len = ((is_constructor ? 0 : strlen (fieldname))
2812 if (fieldname[0] == 'o'
2813 && fieldname[1] == 'p'
2814 && (fieldname[2] == '$' || fieldname[2] == '.'))
2818 opname = cplus_mangle_opname (fieldname + 3, 0);
2821 fprintf (stderr, "No mangling for \"%s\"\n", fieldname);
2822 return DEBUG_TYPE_NULL;
2824 mangled_name_len += strlen (opname);
2825 physname = (char *) xmalloc (mangled_name_len);
2826 strncpy (physname, fieldname, 3);
2827 strcpy (physname + 3, opname);
2831 physname = (char *) xmalloc (mangled_name_len);
2835 strcpy (physname, fieldname);
2838 strcat (physname, buf);
2839 if (tagname != NULL)
2840 strcat (physname, tagname);
2841 strcat (physname, argtypes);
2843 *pphysname = physname;
2846 if (*argtypes == '\0')
2848 args = (debug_type *) xmalloc (sizeof *args);
2850 return debug_make_method_type (dhandle, return_type, class_type, args);
2853 args = stab_demangle_argtypes (dhandle, info, *pphysname);
2855 return DEBUG_TYPE_NULL;
2857 return debug_make_method_type (dhandle, return_type, class_type, args);
2860 /* The tail end of stabs for C++ classes that contain a virtual function
2861 pointer contains a tilde, a %, and a type number.
2862 The type number refers to the base class (possibly this class itself) which
2863 contains the vtable pointer for the current class.
2865 This function is called when we have parsed all the method declarations,
2866 so we can look for the vptr base class info. */
2869 parse_stab_tilde_field (dhandle, info, pp, typenums, retvptrbase, retownvptr)
2871 struct stab_handle *info;
2873 const int *typenums;
2874 debug_type *retvptrbase;
2875 boolean *retownvptr;
2881 *retvptrbase = DEBUG_TYPE_NULL;
2882 *retownvptr = false;
2886 /* If we are positioned at a ';', then skip it. */
2895 if (**pp == '=' || **pp == '+' || **pp == '-')
2897 /* Obsolete flags that used to indicate the presence of
2898 constructors and/or destructors. */
2909 /* The next number is the type number of the base class (possibly
2910 our own class) which supplies the vtable for this class. */
2911 if (! parse_stab_type_number (pp, vtypenums))
2914 if (vtypenums[0] == typenums[0]
2915 && vtypenums[1] == typenums[1])
2924 vtype = parse_stab_type (dhandle, info, (const char *) NULL, pp,
2925 (debug_type **) NULL);
2926 for (p = *pp; *p != ';' && *p != '\0'; p++)
2934 *retvptrbase = vtype;
2942 /* Read a definition of an array type. */
2945 parse_stab_array_type (dhandle, info, pp, stringp)
2947 struct stab_handle *info;
2952 debug_type index_type;
2954 bfd_signed_vma lower, upper;
2955 debug_type element_type;
2957 /* Format of an array type:
2958 "ar<index type>;lower;upper;<array_contents_type>".
2959 OS9000: "arlower,upper;<array_contents_type>".
2961 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
2962 for these, produce a type like float[][]. */
2966 /* FIXME: gdb checks os9k_stabs here. */
2968 index_type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
2969 (debug_type **) NULL);
2973 return DEBUG_TYPE_NULL;
2979 if (! isdigit ((unsigned char) **pp) && **pp != '-')
2985 lower = (bfd_signed_vma) parse_number (pp, (boolean *) NULL);
2993 if (! isdigit ((unsigned char) **pp) && **pp != '-')
2999 upper = (bfd_signed_vma) parse_number (pp, (boolean *) NULL);
3007 element_type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
3008 (debug_type **) NULL);
3009 if (element_type == DEBUG_TYPE_NULL)
3018 return debug_make_array_type (dhandle, element_type, index_type, lower,
3022 /* Keep a stack of N_BINCL include files. */
3026 struct bincl_file *next;
3030 /* Start a new N_BINCL file, pushing it onto the stack. */
3033 push_bincl (info, name)
3034 struct stab_handle *info;
3037 struct bincl_file *n;
3039 n = (struct bincl_file *) xmalloc (sizeof *n);
3040 n->next = info->bincl_stack;
3042 info->bincl_stack = n;
3045 info->file_types = ((struct stab_types **)
3046 xrealloc ((PTR) info->file_types,
3048 * sizeof *info->file_types)));
3049 info->file_types[info->files - 1] = NULL;
3052 /* Finish an N_BINCL file, at an N_EINCL, popping the name off the
3057 struct stab_handle *info;
3059 struct bincl_file *o;
3061 o = info->bincl_stack;
3063 return info->main_filename;
3064 info->bincl_stack = o->next;
3066 if (info->bincl_stack == NULL)
3067 return info->main_filename;
3068 return info->bincl_stack->name;
3071 /* Handle a variable definition. gcc emits variable definitions for a
3072 block before the N_LBRAC, so we must hold onto them until we see
3073 it. The SunPRO compiler emits variable definitions after the
3074 N_LBRAC, so we can call debug_record_variable immediately. */
3077 stab_record_variable (dhandle, info, name, type, kind, val)
3079 struct stab_handle *info;
3082 enum debug_var_kind kind;
3085 struct stab_pending_var *v;
3087 if ((kind == DEBUG_GLOBAL || kind == DEBUG_STATIC)
3088 || ! info->within_function
3089 || (info->gcc_compiled == 0 && info->n_opt_found))
3090 return debug_record_variable (dhandle, name, type, kind, val);
3092 v = (struct stab_pending_var *) xmalloc (sizeof *v);
3093 memset (v, 0, sizeof *v);
3095 v->next = info->pending;
3105 /* Emit pending variable definitions. This is called after we see the
3106 N_LBRAC that starts the block. */
3109 stab_emit_pending_vars (dhandle, info)
3111 struct stab_handle *info;
3113 struct stab_pending_var *v;
3118 struct stab_pending_var *next;
3120 if (! debug_record_variable (dhandle, v->name, v->type, v->kind, v->val))
3128 info->pending = NULL;
3133 /* Find the slot for a type in the database. */
3136 stab_find_slot (info, typenums)
3137 struct stab_handle *info;
3138 const int *typenums;
3142 struct stab_types **ps;
3144 filenum = typenums[0];
3145 index = typenums[1];
3147 if (filenum < 0 || (unsigned int) filenum >= info->files)
3149 fprintf (stderr, "Type file number %d out of range\n", filenum);
3154 fprintf (stderr, "Type index number %d out of range\n", index);
3158 ps = info->file_types + filenum;
3160 while (index >= STAB_TYPES_SLOTS)
3164 *ps = (struct stab_types *) xmalloc (sizeof **ps);
3165 memset (*ps, 0, sizeof **ps);
3168 index -= STAB_TYPES_SLOTS;
3172 *ps = (struct stab_types *) xmalloc (sizeof **ps);
3173 memset (*ps, 0, sizeof **ps);
3176 return (*ps)->types + index;
3179 /* Find a type given a type number. If the type has not been
3180 allocated yet, create an indirect type. */
3183 stab_find_type (dhandle, info, typenums)
3185 struct stab_handle *info;
3186 const int *typenums;
3190 if (typenums[0] == 0 && typenums[1] < 0)
3192 /* A negative type number indicates an XCOFF builtin type. */
3193 return stab_xcoff_builtin_type (dhandle, info, typenums[1]);
3196 slot = stab_find_slot (info, typenums);
3198 return DEBUG_TYPE_NULL;
3200 if (*slot == DEBUG_TYPE_NULL)
3201 return debug_make_indirect_type (dhandle, slot, (const char *) NULL);
3206 /* Record that a given type number refers to a given type. */
3209 stab_record_type (dhandle, info, typenums, type)
3211 struct stab_handle *info;
3212 const int *typenums;
3217 slot = stab_find_slot (info, typenums);
3221 /* gdb appears to ignore type redefinitions, so we do as well. */
3228 /* Return an XCOFF builtin type. */
3231 stab_xcoff_builtin_type (dhandle, info, typenum)
3233 struct stab_handle *info;
3239 if (typenum >= 0 || typenum < -XCOFF_TYPE_COUNT)
3241 fprintf (stderr, "Unrecognized XCOFF type %d\n", typenum);
3242 return DEBUG_TYPE_NULL;
3244 if (info->xcoff_types[-typenum] != NULL)
3245 return info->xcoff_types[-typenum];
3250 /* The size of this and all the other types are fixed, defined
3251 by the debugging format. */
3253 rettype = debug_make_int_type (dhandle, 4, false);
3257 rettype = debug_make_int_type (dhandle, 1, false);
3261 rettype = debug_make_int_type (dhandle, 2, false);
3265 rettype = debug_make_int_type (dhandle, 4, false);
3268 name = "unsigned char";
3269 rettype = debug_make_int_type (dhandle, 1, true);
3272 name = "signed char";
3273 rettype = debug_make_int_type (dhandle, 1, false);
3276 name = "unsigned short";
3277 rettype = debug_make_int_type (dhandle, 2, true);
3280 name = "unsigned int";
3281 rettype = debug_make_int_type (dhandle, 4, true);
3285 rettype = debug_make_int_type (dhandle, 4, true);
3287 name = "unsigned long";
3288 rettype = debug_make_int_type (dhandle, 4, true);
3292 rettype = debug_make_void_type (dhandle);
3295 /* IEEE single precision (32 bit). */
3297 rettype = debug_make_float_type (dhandle, 4);
3300 /* IEEE double precision (64 bit). */
3302 rettype = debug_make_float_type (dhandle, 8);
3305 /* This is an IEEE double on the RS/6000, and different machines
3306 with different sizes for "long double" should use different
3307 negative type numbers. See stabs.texinfo. */
3308 name = "long double";
3309 rettype = debug_make_float_type (dhandle, 8);
3313 rettype = debug_make_int_type (dhandle, 4, false);
3317 rettype = debug_make_bool_type (dhandle, 4);
3320 name = "short real";
3321 rettype = debug_make_float_type (dhandle, 4);
3325 rettype = debug_make_float_type (dhandle, 8);
3335 rettype = debug_make_int_type (dhandle, 1, true);
3339 rettype = debug_make_bool_type (dhandle, 1);
3343 rettype = debug_make_bool_type (dhandle, 2);
3347 rettype = debug_make_bool_type (dhandle, 4);
3351 rettype = debug_make_bool_type (dhandle, 4);
3354 /* Complex type consisting of two IEEE single precision values. */
3356 rettype = debug_make_complex_type (dhandle, 8);
3359 /* Complex type consisting of two IEEE double precision values. */
3360 name = "double complex";
3361 rettype = debug_make_complex_type (dhandle, 16);
3365 rettype = debug_make_int_type (dhandle, 1, false);
3369 rettype = debug_make_int_type (dhandle, 2, false);
3373 rettype = debug_make_int_type (dhandle, 4, false);
3378 rettype = debug_make_int_type (dhandle, 2, false);
3382 rettype = debug_make_int_type (dhandle, 8, false);
3385 name = "unsigned long long";
3386 rettype = debug_make_int_type (dhandle, 8, true);
3390 rettype = debug_make_bool_type (dhandle, 8);
3394 rettype = debug_make_int_type (dhandle, 8, false);
3400 rettype = debug_name_type (dhandle, name, rettype);
3402 info->xcoff_types[-typenum] = rettype;
3407 /* Find or create a tagged type. */
3410 stab_find_tagged_type (dhandle, info, p, len, kind)
3412 struct stab_handle *info;
3415 enum debug_type_kind kind;
3419 struct stab_tag *st;
3421 name = savestring (p, len);
3423 /* We pass DEBUG_KIND_ILLEGAL because we want all tags in the same
3424 namespace. This is right for C, and I don't know how to handle
3425 other languages. FIXME. */
3426 dtype = debug_find_tagged_type (dhandle, name, DEBUG_KIND_ILLEGAL);
3427 if (dtype != DEBUG_TYPE_NULL)
3433 /* We need to allocate an entry on the undefined tag list. */
3434 for (st = info->tags; st != NULL; st = st->next)
3436 if (st->name[0] == name[0]
3437 && strcmp (st->name, name) == 0)
3439 if (st->kind == DEBUG_KIND_ILLEGAL)
3447 st = (struct stab_tag *) xmalloc (sizeof *st);
3448 memset (st, 0, sizeof *st);
3450 st->next = info->tags;
3453 st->slot = DEBUG_TYPE_NULL;
3454 st->type = debug_make_indirect_type (dhandle, &st->slot, name);
3461 /* In order to get the correct argument types for a stubbed method, we
3462 need to extract the argument types from a C++ mangled string.
3463 Since the argument types can refer back to the return type, this
3464 means that we must demangle the entire physical name. In gdb this
3465 is done by calling cplus_demangle and running the results back
3466 through the C++ expression parser. Since we have no expression
3467 parser, we must duplicate much of the work of cplus_demangle here.
3469 We assume that GNU style demangling is used, since this is only
3470 done for method stubs, and only g++ should output that form of
3471 debugging information. */
3473 /* This structure is used to hold a pointer to type information which
3474 demangling a string. */
3476 struct stab_demangle_typestring
3478 /* The start of the type. This is not null terminated. */
3479 const char *typestring;
3480 /* The length of the type. */
3484 /* This structure is used to hold information while demangling a
3487 struct stab_demangle_info
3489 /* The debugging information handle. */
3491 /* The stab information handle. */
3492 struct stab_handle *info;
3493 /* The array of arguments we are building. */
3495 /* The array of types we have remembered. */
3496 struct stab_demangle_typestring *typestrings;
3497 /* The number of typestrings. */
3498 unsigned int typestring_count;
3499 /* The number of typestring slots we have allocated. */
3500 unsigned int typestring_alloc;
3503 static void stab_bad_demangle PARAMS ((const char *));
3504 static unsigned int stab_demangle_count PARAMS ((const char **));
3505 static boolean stab_demangle_get_count
3506 PARAMS ((const char **, unsigned int *));
3507 static boolean stab_demangle_prefix
3508 PARAMS ((struct stab_demangle_info *, const char **));
3509 static boolean stab_demangle_function_name
3510 PARAMS ((struct stab_demangle_info *, const char **, const char *));
3511 static boolean stab_demangle_signature
3512 PARAMS ((struct stab_demangle_info *, const char **));
3513 static boolean stab_demangle_qualified
3514 PARAMS ((struct stab_demangle_info *, const char **, debug_type *));
3515 static boolean stab_demangle_template
3516 PARAMS ((struct stab_demangle_info *, const char **));
3517 static boolean stab_demangle_class
3518 PARAMS ((struct stab_demangle_info *, const char **, const char **));
3519 static boolean stab_demangle_args
3520 PARAMS ((struct stab_demangle_info *, const char **, debug_type **));
3521 static boolean stab_demangle_arg
3522 PARAMS ((struct stab_demangle_info *, const char **, debug_type **,
3523 unsigned int *, unsigned int *));
3524 static boolean stab_demangle_type
3525 PARAMS ((struct stab_demangle_info *, const char **, debug_type *));
3526 static boolean stab_demangle_fund_type
3527 PARAMS ((struct stab_demangle_info *, const char **, debug_type *));
3528 static boolean stab_demangle_remember_type
3529 PARAMS ((struct stab_demangle_info *, const char *, int));
3531 /* Warn about a bad demangling. */
3534 stab_bad_demangle (s)
3537 fprintf (stderr, "bad mangled name `%s'\n", s);
3540 /* Get a count from a stab string. */
3543 stab_demangle_count (pp)
3549 while (isdigit ((unsigned char) **pp))
3552 count += **pp - '0';
3558 /* Require a count in a string. The count may be multiple digits, in
3559 which case it must end in an underscore. */
3562 stab_demangle_get_count (pp, pi)
3566 if (! isdigit ((unsigned char) **pp))
3571 if (isdigit ((unsigned char) **pp))
3584 while (isdigit ((unsigned char) *p));
3595 /* This function demangles a physical name, returning a NULL
3596 terminated array of argument types. */
3599 stab_demangle_argtypes (dhandle, info, physname)
3601 struct stab_handle *info;
3602 const char *physname;
3604 struct stab_demangle_info minfo;
3606 minfo.dhandle = dhandle;
3609 minfo.typestring_alloc = 10;
3610 minfo.typestrings = ((struct stab_demangle_typestring *)
3611 xmalloc (minfo.typestring_alloc
3612 * sizeof *minfo.typestrings));
3613 minfo.typestring_count = 0;
3615 /* cplus_demangle checks for special GNU mangled forms, but we can't
3616 see any of them in mangled method argument types. */
3618 if (! stab_demangle_prefix (&minfo, &physname))
3621 if (*physname != '\0')
3623 if (! stab_demangle_signature (&minfo, &physname))
3627 free (minfo.typestrings);
3628 minfo.typestrings = NULL;
3630 if (minfo.args == NULL)
3631 fprintf (stderr, "no argument types in mangled string\n");
3636 if (minfo.typestrings != NULL)
3637 free (minfo.typestrings);
3641 /* Demangle the prefix of the mangled name. */
3644 stab_demangle_prefix (minfo, pp)
3645 struct stab_demangle_info *minfo;
3651 /* cplus_demangle checks for global constructors and destructors,
3652 but we can't see them in mangled argument types. */
3654 /* Look for `__'. */
3658 scan = strchr (scan, '_');
3660 while (scan != NULL && *++scan != '_');
3664 stab_bad_demangle (*pp);
3670 /* We found `__'; move ahead to the last contiguous `__' pair. */
3671 i = strspn (scan, "_");
3676 && (isdigit ((unsigned char) scan[2])
3680 /* This is a GNU style constructor name. */
3684 else if (scan == *pp
3685 && ! isdigit ((unsigned char) scan[2])
3688 /* Look for the `__' that separates the prefix from the
3690 while (*scan == '_')
3692 scan = strstr (scan, "__");
3693 if (scan == NULL || scan[2] == '\0')
3695 stab_bad_demangle (*pp);
3699 return stab_demangle_function_name (minfo, pp, scan);
3701 else if (scan[2] != '\0')
3703 /* The name doesn't start with `__', but it does contain `__'. */
3704 return stab_demangle_function_name (minfo, pp, scan);
3708 stab_bad_demangle (*pp);
3714 /* Demangle a function name prefix. The scan argument points to the
3715 double underscore which separates the function name from the
3719 stab_demangle_function_name (minfo, pp, scan)
3720 struct stab_demangle_info *minfo;
3726 /* The string from *pp to scan is the name of the function. We
3727 don't care about the name, since we just looking for argument
3728 types. However, for conversion operators, the name may include a
3729 type which we must remember in order to handle backreferences. */
3735 && strncmp (name, "type", 4) == 0
3736 && (name[4] == '$' || name[4] == '.'))
3740 /* This is a type conversion operator. */
3742 if (! stab_demangle_type (minfo, &tem, (debug_type *) NULL))
3745 else if (name[0] == '_'
3752 /* This is a type conversion operator. */
3754 if (! stab_demangle_type (minfo, &tem, (debug_type *) NULL))
3761 /* Demangle the signature. This is where the argument types are
3765 stab_demangle_signature (minfo, pp)
3766 struct stab_demangle_info *minfo;
3770 boolean expect_func, func_done;
3775 expect_func = false;
3779 while (**pp != '\0')
3785 if (! stab_demangle_qualified (minfo, pp, (debug_type *) NULL)
3786 || ! stab_demangle_remember_type (minfo, hold, *pp - hold))
3793 /* Static member function. FIXME: Can this happen? */
3800 /* Const member function. */
3806 case '0': case '1': case '2': case '3': case '4':
3807 case '5': case '6': case '7': case '8': case '9':
3810 if (! stab_demangle_class (minfo, pp, (const char **) NULL)
3811 || ! stab_demangle_remember_type (minfo, hold, *pp - hold))
3818 /* Function. I don't know if this actually happens with g++
3823 if (! stab_demangle_args (minfo, pp, &minfo->args))
3831 if (! stab_demangle_template (minfo, pp)
3832 || ! stab_demangle_remember_type (minfo, hold, *pp - hold))
3839 /* At the outermost level, we cannot have a return type
3840 specified, so if we run into another '_' at this point we
3841 are dealing with a mangled name that is either bogus, or
3842 has been mangled by some algorithm we don't know how to
3843 deal with. So just reject the entire demangling. */
3844 stab_bad_demangle (orig);
3848 /* Assume we have stumbled onto the first outermost function
3849 argument token, and start processing args. */
3851 if (! stab_demangle_args (minfo, pp, &minfo->args))
3859 if (! stab_demangle_args (minfo, pp, &minfo->args))
3866 /* With GNU style demangling, bar__3foo is 'foo::bar(void)', and
3867 bar__3fooi is 'foo::bar(int)'. We get here when we find the
3868 first case, and need to ensure that the '(void)' gets added
3869 to the current declp. */
3870 if (! stab_demangle_args (minfo, pp, &minfo->args))
3877 /* Demangle a qualified name, such as "Q25Outer5Inner" which is the
3878 mangled form of "Outer::Inner". */
3881 stab_demangle_qualified (minfo, pp, ptype)
3882 struct stab_demangle_info *minfo;
3888 unsigned int qualifiers;
3896 /* GNU mangled name with more than 9 classes. The count is
3897 preceded by an underscore (to distinguish it from the <= 9
3898 case) and followed by an underscore. */
3900 if (! isdigit ((unsigned char) *p) || *p == '0')
3902 stab_bad_demangle (orig);
3905 qualifiers = atoi (p);
3906 while (isdigit ((unsigned char) *p))
3910 stab_bad_demangle (orig);
3916 case '1': case '2': case '3': case '4': case '5':
3917 case '6': case '7': case '8': case '9':
3918 qualifiers = (*pp)[1] - '0';
3919 /* Skip an optional underscore after the count. */
3920 if ((*pp)[2] == '_')
3927 stab_bad_demangle (orig);
3931 context = DEBUG_TYPE_NULL;
3933 /* Pick off the names. */
3934 while (qualifiers-- > 0)
3940 /* FIXME: I don't know how to handle the ptype != NULL case
3942 if (! stab_demangle_template (minfo, pp))
3949 len = stab_demangle_count (pp);
3950 if (strlen (*pp) < len)
3952 stab_bad_demangle (orig);
3958 const debug_field *fields;
3961 if (context != DEBUG_TYPE_NULL)
3962 fields = debug_get_fields (minfo->dhandle, context);
3964 context = DEBUG_TYPE_NULL;
3970 /* Try to find the type by looking through the
3971 fields of context until we find a field with the
3972 same type. This ought to work for a class
3973 defined within a class, but it won't work for,
3974 e.g., an enum defined within a class. stabs does
3975 not give us enough information to figure out the
3978 name = savestring (*pp, len);
3980 for (; *fields != DEBUG_FIELD_NULL; fields++)
3985 ft = debug_get_field_type (minfo->dhandle, *fields);
3988 dn = debug_get_type_name (minfo->dhandle, ft);
3989 if (dn != NULL && strcmp (dn, name) == 0)
3999 if (context == DEBUG_TYPE_NULL)
4001 /* We have to fall back on finding the type by name.
4002 If there are more types to come, then this must
4003 be a class. Otherwise, it could be anything. */
4005 if (qualifiers == 0)
4009 name = savestring (*pp, len);
4010 context = debug_find_named_type (minfo->dhandle,
4015 if (context == DEBUG_TYPE_NULL)
4017 context = stab_find_tagged_type (minfo->dhandle,
4021 ? DEBUG_KIND_ILLEGAL
4022 : DEBUG_KIND_CLASS));
4023 if (context == DEBUG_TYPE_NULL)
4039 /* Demangle a template. */
4042 stab_demangle_template (minfo, pp)
4043 struct stab_demangle_info *minfo;
4053 /* Skip the template name. */
4054 r = stab_demangle_count (pp);
4055 if (r == 0 || strlen (*pp) < r)
4057 stab_bad_demangle (orig);
4062 /* Get the size of the parameter list. */
4063 if (stab_demangle_get_count (pp, &r) == 0)
4065 stab_bad_demangle (orig);
4069 for (i = 0; i < r; i++)
4073 /* This is a type parameter. */
4075 if (! stab_demangle_type (minfo, pp, (debug_type *) NULL))
4081 boolean pointerp, realp, integralp, charp, boolp;
4092 /* This is a value parameter. */
4094 if (! stab_demangle_type (minfo, pp, (debug_type *) NULL))
4097 while (*old_p != '\0' && ! done)
4107 case 'C': /* Const. */
4108 case 'S': /* Signed. */
4109 case 'U': /* Unsigned. */
4110 case 'V': /* Volatile. */
4111 case 'F': /* Function. */
4112 case 'M': /* Member function. */
4116 case 'Q': /* Qualified name. */
4120 case 'T': /* Remembered type. */
4122 case 'v': /* Void. */
4124 case 'x': /* Long long. */
4125 case 'l': /* Long. */
4126 case 'i': /* Int. */
4127 case 's': /* Short. */
4128 case 'w': /* Wchar_t. */
4132 case 'b': /* Bool. */
4136 case 'c': /* Char. */
4140 case 'r': /* Long double. */
4141 case 'd': /* Double. */
4142 case 'f': /* Float. */
4147 /* Assume it's a uder defined integral type. */
4158 while (isdigit ((unsigned char) **pp))
4167 val = stab_demangle_count (pp);
4170 stab_bad_demangle (orig);
4178 val = stab_demangle_count (pp);
4179 if (val != 0 && val != 1)
4181 stab_bad_demangle (orig);
4189 while (isdigit ((unsigned char) **pp))
4194 while (isdigit ((unsigned char) **pp))
4200 while (isdigit ((unsigned char) **pp))
4208 if (! stab_demangle_get_count (pp, &len))
4210 stab_bad_demangle (orig);
4221 /* Demangle a class name. */
4224 stab_demangle_class (minfo, pp, pstart)
4225 struct stab_demangle_info *minfo;
4227 const char **pstart;
4234 n = stab_demangle_count (pp);
4235 if (strlen (*pp) < n)
4237 stab_bad_demangle (orig);
4249 /* Demangle function arguments. If the pargs argument is not NULL, it
4250 is set to a NULL terminated array holding the arguments. */
4253 stab_demangle_args (minfo, pp, pargs)
4254 struct stab_demangle_info *minfo;
4259 unsigned int alloc, count;
4265 *pargs = (debug_type *) xmalloc (alloc * sizeof **pargs);
4268 while (**pp != '_' && **pp != '\0' && **pp != 'e')
4270 if (**pp == 'N' || **pp == 'T')
4278 if (temptype == 'T')
4282 if (! stab_demangle_get_count (pp, &r))
4284 stab_bad_demangle (orig);
4289 if (! stab_demangle_get_count (pp, &t))
4291 stab_bad_demangle (orig);
4295 if (t >= minfo->typestring_count)
4297 stab_bad_demangle (orig);
4304 tem = minfo->typestrings[t].typestring;
4305 if (! stab_demangle_arg (minfo, &tem, pargs, &count, &alloc))
4311 if (! stab_demangle_arg (minfo, pp, pargs, &count, &alloc))
4322 type = debug_make_ellipsis_type (minfo->dhandle);
4323 if (type == DEBUG_TYPE_NULL)
4326 if (count + 1 >= alloc)
4329 *pargs = ((debug_type *)
4330 xrealloc (*pargs, alloc * sizeof **pargs));
4332 (*pargs)[count] = type;
4340 (*pargs)[count] = DEBUG_TYPE_NULL;
4345 /* Demangle a single argument. */
4348 stab_demangle_arg (minfo, pp, pargs, pcount, palloc)
4349 struct stab_demangle_info *minfo;
4352 unsigned int *pcount;
4353 unsigned int *palloc;
4359 if (! stab_demangle_type (minfo, pp,
4360 pargs == NULL ? (debug_type *) NULL : &type)
4361 || ! stab_demangle_remember_type (minfo, start, *pp - start))
4366 if (type == DEBUG_TYPE_NULL)
4369 if (*pcount + 1 >= *palloc)
4372 *pargs = ((debug_type *)
4373 xrealloc (*pargs, *palloc * sizeof **pargs));
4375 (*pargs)[*pcount] = type;
4382 /* Demangle a type. If the ptype argument is not NULL, *ptype is set
4383 to the newly allocated type. */
4386 stab_demangle_type (minfo, pp, ptype)
4387 struct stab_demangle_info *minfo;
4399 /* A pointer type. */
4401 if (! stab_demangle_type (minfo, pp, ptype))
4404 *ptype = debug_make_pointer_type (minfo->dhandle, *ptype);
4408 /* A reference type. */
4410 if (! stab_demangle_type (minfo, pp, ptype))
4413 *ptype = debug_make_reference_type (minfo->dhandle, *ptype);
4423 while (**pp != '\0' && **pp != '_')
4425 if (! isdigit ((unsigned char) **pp))
4427 stab_bad_demangle (orig);
4436 stab_bad_demangle (orig);
4441 if (! stab_demangle_type (minfo, pp, ptype))
4445 debug_type int_type;
4447 int_type = debug_find_named_type (minfo->dhandle, "int");
4448 if (int_type == NULL)
4449 int_type = debug_make_int_type (minfo->dhandle, 4, false);
4450 *ptype = debug_make_array_type (minfo->dhandle, *ptype, int_type,
4457 /* A back reference to a remembered type. */
4463 if (! stab_demangle_get_count (pp, &i))
4465 stab_bad_demangle (orig);
4468 if (i >= minfo->typestring_count)
4470 stab_bad_demangle (orig);
4473 p = minfo->typestrings[i].typestring;
4474 if (! stab_demangle_type (minfo, &p, ptype))
4482 /* FIXME: We should pick up the argument types. */
4483 if (! stab_demangle_args (minfo, pp, (debug_type **) NULL))
4487 /* cplus_demangle will accept a function without a return
4488 type, but I don't know when that will happen, or what to
4490 stab_bad_demangle (orig);
4494 if (! stab_demangle_type (minfo, pp, ptype))
4497 *ptype = debug_make_function_type (minfo->dhandle, *ptype);
4503 boolean memberp, constp, volatilep;
4508 memberp = **pp == 'M';
4514 if (! isdigit ((unsigned char) **pp))
4516 stab_bad_demangle (orig);
4519 n = stab_demangle_count (pp);
4520 if (strlen (*pp) < n)
4522 stab_bad_demangle (orig);
4535 else if (**pp == 'V')
4542 stab_bad_demangle (orig);
4546 if (! stab_demangle_args (minfo, pp,
4548 ? (debug_type **) NULL
4555 stab_bad_demangle (orig);
4560 if (! stab_demangle_type (minfo, pp, ptype))
4565 debug_type class_type;
4567 class_type = stab_find_tagged_type (minfo->dhandle, minfo->info,
4570 if (class_type == DEBUG_TYPE_NULL)
4574 *ptype = debug_make_offset_type (minfo->dhandle, class_type,
4578 /* FIXME: We have no way to record constp or
4580 *ptype = debug_make_method_type (minfo->dhandle, *ptype,
4589 if (! stab_demangle_type (minfo, pp, ptype))
4595 if (! stab_demangle_type (minfo, pp, ptype))
4598 *ptype = debug_make_const_type (minfo->dhandle, *ptype);
4606 if (! stab_demangle_qualified (minfo, pp, ptype))
4612 if (! stab_demangle_fund_type (minfo, pp, ptype))
4620 /* Demangle a fundamental type. If the ptype argument is not NULL,
4621 *ptype is set to the newly allocated type. */
4624 stab_demangle_fund_type (minfo, pp, ptype)
4625 struct stab_demangle_info *minfo;
4630 boolean constp, volatilep, unsignedp, signedp;
4675 /* cplus_demangle permits this, but I don't know what it means. */
4676 stab_bad_demangle (orig);
4679 case 'v': /* void */
4682 *ptype = debug_find_named_type (minfo->dhandle, "void");
4683 if (*ptype == DEBUG_TYPE_NULL)
4684 *ptype = debug_make_void_type (minfo->dhandle);
4689 case 'x': /* long long */
4692 *ptype = debug_find_named_type (minfo->dhandle,
4694 ? "long long unsigned int"
4695 : "long long int"));
4696 if (*ptype == DEBUG_TYPE_NULL)
4697 *ptype = debug_make_int_type (minfo->dhandle, 8, unsignedp);
4702 case 'l': /* long */
4705 *ptype = debug_find_named_type (minfo->dhandle,
4707 ? "long unsigned int"
4709 if (*ptype == DEBUG_TYPE_NULL)
4710 *ptype = debug_make_int_type (minfo->dhandle, 4, unsignedp);
4718 *ptype = debug_find_named_type (minfo->dhandle,
4722 if (*ptype == DEBUG_TYPE_NULL)
4723 *ptype = debug_make_int_type (minfo->dhandle, 4, unsignedp);
4728 case 's': /* short */
4731 *ptype = debug_find_named_type (minfo->dhandle,
4733 ? "short unsigned int"
4735 if (*ptype == DEBUG_TYPE_NULL)
4736 *ptype = debug_make_int_type (minfo->dhandle, 2, unsignedp);
4741 case 'b': /* bool */
4744 *ptype = debug_find_named_type (minfo->dhandle, "bool");
4745 if (*ptype == DEBUG_TYPE_NULL)
4746 *ptype = debug_make_bool_type (minfo->dhandle, 4);
4751 case 'c': /* char */
4754 *ptype = debug_find_named_type (minfo->dhandle,
4760 if (*ptype == DEBUG_TYPE_NULL)
4761 *ptype = debug_make_int_type (minfo->dhandle, 1, unsignedp);
4766 case 'w': /* wchar_t */
4769 *ptype = debug_find_named_type (minfo->dhandle, "__wchar_t");
4770 if (*ptype == DEBUG_TYPE_NULL)
4771 *ptype = debug_make_int_type (minfo->dhandle, 2, true);
4776 case 'r': /* long double */
4779 *ptype = debug_find_named_type (minfo->dhandle, "long double");
4780 if (*ptype == DEBUG_TYPE_NULL)
4781 *ptype = debug_make_float_type (minfo->dhandle, 8);
4786 case 'd': /* double */
4789 *ptype = debug_find_named_type (minfo->dhandle, "double");
4790 if (*ptype == DEBUG_TYPE_NULL)
4791 *ptype = debug_make_float_type (minfo->dhandle, 8);
4796 case 'f': /* float */
4799 *ptype = debug_find_named_type (minfo->dhandle, "float");
4800 if (*ptype == DEBUG_TYPE_NULL)
4801 *ptype = debug_make_float_type (minfo->dhandle, 4);
4808 if (! isdigit ((unsigned char) **pp))
4810 stab_bad_demangle (orig);
4814 case '0': case '1': case '2': case '3': case '4':
4815 case '5': case '6': case '7': case '8': case '9':
4819 if (! stab_demangle_class (minfo, pp, &hold))
4825 name = savestring (hold, *pp - hold);
4826 *ptype = debug_find_named_type (minfo->dhandle, name);
4827 if (*ptype == DEBUG_TYPE_NULL)
4829 /* FIXME: It is probably incorrect to assume that
4830 undefined types are tagged types. */
4831 *ptype = stab_find_tagged_type (minfo->dhandle, minfo->info,
4833 DEBUG_KIND_ILLEGAL);
4841 if (! stab_demangle_template (minfo, pp))
4847 stab_bad_demangle (orig);
4854 *ptype = debug_make_const_type (minfo->dhandle, *ptype);
4856 *ptype = debug_make_volatile_type (minfo->dhandle, *ptype);
4862 /* Remember a type string in a demangled string. */
4865 stab_demangle_remember_type (minfo, p, len)
4866 struct stab_demangle_info *minfo;
4870 if (minfo->typestring_count >= minfo->typestring_alloc)
4872 minfo->typestring_alloc += 10;
4873 minfo->typestrings = ((struct stab_demangle_typestring *)
4874 xrealloc (minfo->typestrings,
4875 (minfo->typestring_alloc
4876 * sizeof *minfo->typestrings)));
4879 minfo->typestrings[minfo->typestring_count].typestring = p;
4880 minfo->typestrings[minfo->typestring_count].len = (unsigned int) len;
4881 ++minfo->typestring_count;