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 *, boolean *));
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)
833 ftype = debug_make_function_type (dhandle, dtype,
834 (debug_type *) NULL, false);
835 dtype = debug_make_pointer_type (dhandle, ftype);
838 if (dtype == DEBUG_TYPE_NULL)
840 if (! debug_record_parameter (dhandle, name, dtype, DEBUG_PARM_STACK,
844 /* FIXME: At this point gdb considers rearranging the parameter
845 address on a big endian machine if it is smaller than an int.
846 We have no way to do that, since we don't really know much
852 if (stabtype == N_FUN)
854 /* Prototype of a function referenced by this file. */
858 if (parse_stab_type (dhandle, info, (const char *) NULL, &p,
859 (debug_type **) NULL)
867 /* Parameter which is in a register. */
868 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
869 (debug_type **) NULL);
870 if (dtype == DEBUG_TYPE_NULL)
872 if (! debug_record_parameter (dhandle, name, dtype, DEBUG_PARM_REG,
878 /* Register variable (either global or local). */
879 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
880 (debug_type **) NULL);
881 if (dtype == DEBUG_TYPE_NULL)
883 if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_REGISTER,
887 /* FIXME: At this point gdb checks to combine pairs of 'p' and
888 'r' stabs into a single 'P' stab. */
893 /* Static symbol at top level of file */
894 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
895 (debug_type **) NULL);
896 if (dtype == DEBUG_TYPE_NULL)
898 if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_STATIC,
905 dtype = parse_stab_type (dhandle, info, name, &p, &slot);
906 if (dtype == DEBUG_TYPE_NULL)
910 /* A nameless type. Nothing to do. */
914 dtype = debug_name_type (dhandle, name, dtype);
915 if (dtype == DEBUG_TYPE_NULL)
924 /* Struct, union, or enum tag. For GNU C++, this can be be followed
925 by 't' which means we are typedef'ing it as well. */
929 /* FIXME: gdb sets synonym to true if the current language
938 dtype = parse_stab_type (dhandle, info, name, &p, &slot);
939 if (dtype == DEBUG_TYPE_NULL)
944 dtype = debug_tag_type (dhandle, name, dtype);
945 if (dtype == DEBUG_TYPE_NULL)
950 /* See if we have a cross reference to this tag which we can now
953 register struct stab_tag **pst;
955 for (pst = &info->tags; *pst != NULL; pst = &(*pst)->next)
957 if ((*pst)->name[0] == name[0]
958 && strcmp ((*pst)->name, name) == 0)
960 (*pst)->slot = dtype;
969 dtype = debug_name_type (dhandle, name, dtype);
970 if (dtype == DEBUG_TYPE_NULL)
980 /* Static symbol of local scope */
981 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
982 (debug_type **) NULL);
983 if (dtype == DEBUG_TYPE_NULL)
985 /* FIXME: gdb checks os9k_stabs here. */
986 if (! stab_record_variable (dhandle, info, name, dtype,
987 DEBUG_LOCAL_STATIC, value))
992 /* Reference parameter. */
993 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
994 (debug_type **) NULL);
995 if (dtype == DEBUG_TYPE_NULL)
997 if (! debug_record_parameter (dhandle, name, dtype, DEBUG_PARM_REFERENCE,
1003 /* Reference parameter which is in a register. */
1004 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
1005 (debug_type **) NULL);
1006 if (dtype == DEBUG_TYPE_NULL)
1008 if (! debug_record_parameter (dhandle, name, dtype, DEBUG_PARM_REF_REG,
1014 /* This is used by Sun FORTRAN for "function result value".
1015 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
1016 that Pascal uses it too, but when I tried it Pascal used
1017 "x:3" (local symbol) instead. */
1018 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
1019 (debug_type **) NULL);
1020 if (dtype == DEBUG_TYPE_NULL)
1022 if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_LOCAL,
1032 /* FIXME: gdb converts structure values to structure pointers in a
1033 couple of cases, depending upon the target. */
1038 /* Parse a stabs type. The typename argument is non-NULL if this is a
1039 typedef or a tag definition. The pp argument points to the stab
1040 string, and is updated. The slotp argument points to a place to
1041 store the slot used if the type is being defined. */
1044 parse_stab_type (dhandle, info, typename, pp, slotp)
1046 struct stab_handle *info;
1047 const char *typename;
1066 /* Read type number if present. The type number may be omitted.
1067 for instance in a two-dimensional array declared with type
1068 "ar1;1;10;ar1;1;10;4". */
1069 if (! isdigit ((unsigned char) **pp) && **pp != '(' && **pp != '-')
1071 /* 'typenums=' not present, type is anonymous. Read and return
1072 the definition, but don't put it in the type vector. */
1073 typenums[0] = typenums[1] = -1;
1077 if (! parse_stab_type_number (pp, typenums))
1078 return DEBUG_TYPE_NULL;
1082 /* Type is not being defined here. Either it already
1083 exists, or this is a forward reference to it. */
1084 return stab_find_type (dhandle, info, typenums);
1087 /* Only set the slot if the type is being defined. This means
1088 that the mapping from type numbers to types will only record
1089 the name of the typedef which defines a type. If we don't do
1090 this, then something like
1093 will record that i is of type foo. Unfortunately, stabs
1094 information is ambiguous about variable types. For this code,
1098 the stabs information records both i and j as having the same
1099 type. This could be fixed by patching the compiler. */
1100 if (slotp != NULL && typenums[0] >= 0 && typenums[1] >= 0)
1101 *slotp = stab_find_slot (info, typenums);
1103 /* Type is being defined here. */
1109 const char *p = *pp + 1;
1112 if (isdigit ((unsigned char) *p) || *p == '(' || *p == '-')
1118 /* Type attributes. */
1121 for (; *p != ';'; ++p)
1126 return DEBUG_TYPE_NULL;
1134 size = atoi (attr + 1);
1144 /* Ignore unrecognized type attributes, so future
1145 compilers can invent new ones. */
1158 enum debug_type_kind code;
1159 const char *q1, *q2, *p;
1161 /* A cross reference to another type. */
1166 code = DEBUG_KIND_STRUCT;
1169 code = DEBUG_KIND_UNION;
1172 code = DEBUG_KIND_ENUM;
1175 /* Complain and keep going, so compilers can invent new
1176 cross-reference types. */
1177 warn_stab (orig, "unrecognized cross reference type");
1178 code = DEBUG_KIND_STRUCT;
1183 q1 = strchr (*pp, '<');
1184 p = strchr (*pp, ':');
1188 return DEBUG_TYPE_NULL;
1190 while (q1 != NULL && p > q1 && p[1] == ':')
1192 q2 = strchr (q1, '>');
1193 if (q2 == NULL || q2 < p)
1196 p = strchr (p, ':');
1200 return DEBUG_TYPE_NULL;
1204 dtype = stab_find_tagged_type (dhandle, info, *pp, p - *pp, code);
1226 /* This type is defined as another type. */
1231 /* Peek ahead at the number to detect void. */
1232 if (! parse_stab_type_number (pp, xtypenums))
1233 return DEBUG_TYPE_NULL;
1235 if (typenums[0] == xtypenums[0] && typenums[1] == xtypenums[1])
1237 /* This type is being defined as itself, which means that
1239 dtype = debug_make_void_type (dhandle);
1245 /* Go back to the number and have parse_stab_type get it.
1246 This means that we can deal with something like
1247 t(1,2)=(3,4)=... which the Lucid compiler uses. */
1248 dtype = parse_stab_type (dhandle, info, (const char *) NULL,
1249 pp, (debug_type **) NULL);
1250 if (dtype == DEBUG_TYPE_NULL)
1251 return DEBUG_TYPE_NULL;
1254 if (typenums[0] != -1)
1256 if (! stab_record_type (dhandle, info, typenums, dtype))
1257 return DEBUG_TYPE_NULL;
1264 dtype = debug_make_pointer_type (dhandle,
1265 parse_stab_type (dhandle, info,
1266 (const char *) NULL,
1268 (debug_type **) NULL));
1272 /* Reference to another type. */
1273 dtype = (debug_make_reference_type
1275 parse_stab_type (dhandle, info, (const char *) NULL, pp,
1276 (debug_type **) NULL)));
1280 /* Function returning another type. */
1281 /* FIXME: gdb checks os9k_stabs here. */
1282 dtype = (debug_make_function_type
1284 parse_stab_type (dhandle, info, (const char *) NULL, pp,
1285 (debug_type **) NULL),
1286 (debug_type *) NULL, false));
1290 /* Const qualifier on some type (Sun). */
1291 /* FIXME: gdb accepts 'c' here if os9k_stabs. */
1292 dtype = debug_make_const_type (dhandle,
1293 parse_stab_type (dhandle, info,
1294 (const char *) NULL,
1296 (debug_type **) NULL));
1300 /* Volatile qual on some type (Sun). */
1301 /* FIXME: gdb accepts 'i' here if os9k_stabs. */
1302 dtype = (debug_make_volatile_type
1304 parse_stab_type (dhandle, info, (const char *) NULL, pp,
1305 (debug_type **) NULL)));
1309 /* Offset (class & variable) type. This is used for a pointer
1310 relative to an object. */
1317 domain = parse_stab_type (dhandle, info, (const char *) NULL, pp,
1318 (debug_type **) NULL);
1319 if (domain == DEBUG_TYPE_NULL)
1320 return DEBUG_TYPE_NULL;
1325 return DEBUG_TYPE_NULL;
1329 memtype = parse_stab_type (dhandle, info, (const char *) NULL, pp,
1330 (debug_type **) NULL);
1331 if (memtype == DEBUG_TYPE_NULL)
1332 return DEBUG_TYPE_NULL;
1334 dtype = debug_make_offset_type (dhandle, domain, memtype);
1339 /* Method (class & fn) type. */
1342 debug_type return_type;
1345 return_type = parse_stab_type (dhandle, info, (const char *) NULL,
1346 pp, (debug_type **) NULL);
1347 if (return_type == DEBUG_TYPE_NULL)
1348 return DEBUG_TYPE_NULL;
1352 return DEBUG_TYPE_NULL;
1355 dtype = debug_make_method_type (dhandle, return_type,
1357 (debug_type *) NULL, false);
1362 debug_type return_type;
1368 domain = parse_stab_type (dhandle, info, (const char *) NULL,
1369 pp, (debug_type **) NULL);
1370 if (domain == DEBUG_TYPE_NULL)
1371 return DEBUG_TYPE_NULL;
1376 return DEBUG_TYPE_NULL;
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;
1386 args = (debug_type *) xmalloc (alloc * sizeof *args);
1393 return DEBUG_TYPE_NULL;
1400 args = ((debug_type *)
1401 xrealloc ((PTR) args, alloc * sizeof *args));
1404 args[n] = parse_stab_type (dhandle, info, (const char *) NULL,
1405 pp, (debug_type **) NULL);
1406 if (args[n] == DEBUG_TYPE_NULL)
1407 return DEBUG_TYPE_NULL;
1412 /* If the last type is not void, then this function takes a
1413 variable number of arguments. Otherwise, we must strip
1416 || debug_get_type_kind (dhandle, args[n - 1]) != DEBUG_KIND_VOID)
1424 args[n] = DEBUG_TYPE_NULL;
1426 dtype = debug_make_method_type (dhandle, return_type, domain, args,
1433 dtype = parse_stab_range_type (dhandle, info, typename, pp, typenums);
1437 /* FIXME: gdb checks os9k_stabs here. */
1438 /* Sun ACC builtin int type. */
1439 dtype = parse_stab_sun_builtin_type (dhandle, pp);
1443 /* Sun ACC builtin float type. */
1444 dtype = parse_stab_sun_floating_type (dhandle, pp);
1448 /* Enumeration type. */
1449 dtype = parse_stab_enum_type (dhandle, pp);
1454 /* Struct or union type. */
1455 dtype = parse_stab_struct_type (dhandle, info, typename, pp,
1456 descriptor == 's', typenums);
1464 return DEBUG_TYPE_NULL;
1468 dtype = parse_stab_array_type (dhandle, info, pp, stringp);
1472 dtype = debug_make_set_type (dhandle,
1473 parse_stab_type (dhandle, info,
1474 (const char *) NULL,
1476 (debug_type **) NULL),
1482 return DEBUG_TYPE_NULL;
1485 if (dtype == DEBUG_TYPE_NULL)
1486 return DEBUG_TYPE_NULL;
1488 if (typenums[0] != -1)
1490 if (! stab_record_type (dhandle, info, typenums, dtype))
1491 return DEBUG_TYPE_NULL;
1496 if (! debug_record_type_size (dhandle, dtype, (unsigned int) size))
1503 /* Read a number by which a type is referred to in dbx data, or
1504 perhaps read a pair (FILENUM, TYPENUM) in parentheses. Just a
1505 single number N is equivalent to (0,N). Return the two numbers by
1506 storing them in the vector TYPENUMS. */
1509 parse_stab_type_number (pp, typenums)
1520 typenums[1] = (int) parse_number (pp, (boolean *) NULL);
1525 typenums[0] = (int) parse_number (pp, (boolean *) NULL);
1532 typenums[1] = (int) parse_number (pp, (boolean *) NULL);
1544 /* Parse a range type. */
1547 parse_stab_range_type (dhandle, info, typename, pp, typenums)
1549 struct stab_handle *info;
1550 const char *typename;
1552 const int *typenums;
1556 boolean self_subrange;
1557 debug_type index_type;
1558 const char *s2, *s3;
1559 bfd_signed_vma n2, n3;
1564 index_type = DEBUG_TYPE_NULL;
1566 /* First comes a type we are a subrange of.
1567 In C it is usually 0, 1 or the type being defined. */
1568 if (! parse_stab_type_number (pp, rangenums))
1569 return DEBUG_TYPE_NULL;
1571 self_subrange = (rangenums[0] == typenums[0]
1572 && rangenums[1] == typenums[1]);
1577 index_type = parse_stab_type (dhandle, info, (const char *) NULL,
1578 pp, (debug_type **) NULL);
1579 if (index_type == DEBUG_TYPE_NULL)
1580 return DEBUG_TYPE_NULL;
1586 /* The remaining two operands are usually lower and upper bounds of
1587 the range. But in some special cases they mean something else. */
1589 n2 = parse_number (pp, &ov2);
1593 return DEBUG_TYPE_NULL;
1598 n3 = parse_number (pp, &ov3);
1602 return DEBUG_TYPE_NULL;
1608 /* gcc will emit range stabs for long long types. Handle this
1609 as a special case. FIXME: This needs to be more general. */
1610 #define LLLOW "01000000000000000000000;"
1611 #define LLHIGH "0777777777777777777777;"
1612 #define ULLHIGH "01777777777777777777777;"
1613 if (index_type == DEBUG_TYPE_NULL)
1615 if (strncmp (s2, LLLOW, sizeof LLLOW - 1) == 0
1616 && strncmp (s3, LLHIGH, sizeof LLHIGH - 1) == 0)
1617 return debug_make_int_type (dhandle, 8, false);
1620 && strncmp (s3, ULLHIGH, sizeof ULLHIGH - 1) == 0)
1621 return debug_make_int_type (dhandle, 8, true);
1624 warn_stab (orig, "numeric overflow");
1627 if (index_type == DEBUG_TYPE_NULL)
1629 /* A type defined as a subrange of itself, with both bounds 0,
1631 if (self_subrange && n2 == 0 && n3 == 0)
1632 return debug_make_void_type (dhandle);
1634 /* If n3 is zero and n2 is positive, this is a floating point
1635 type, and n2 is the number of bytes. */
1636 if (n3 == 0 && n2 > 0)
1637 return debug_make_float_type (dhandle, n2);
1639 /* If the upper bound is -1, this is an unsigned int. */
1640 if (n2 == 0 && n3 == -1)
1642 /* When gcc is used with -gstabs, but not -gstabs+, it will emit
1643 long long int:t6=r1;0;-1;
1644 long long unsigned int:t7=r1;0;-1;
1645 We hack here to handle this reasonably. */
1646 if (typename != NULL)
1648 if (strcmp (typename, "long long int") == 0)
1649 return debug_make_int_type (dhandle, 8, false);
1650 else if (strcmp (typename, "long long unsigned int") == 0)
1651 return debug_make_int_type (dhandle, 8, true);
1653 /* FIXME: The size here really depends upon the target. */
1654 return debug_make_int_type (dhandle, 4, true);
1657 /* A range of 0 to 127 is char. */
1658 if (self_subrange && n2 == 0 && n3 == 127)
1659 return debug_make_int_type (dhandle, 1, false);
1661 /* FIXME: gdb checks for the language CHILL here. */
1666 return debug_make_int_type (dhandle, - n3, true);
1667 else if (n3 == 0xff)
1668 return debug_make_int_type (dhandle, 1, true);
1669 else if (n3 == 0xffff)
1670 return debug_make_int_type (dhandle, 2, true);
1671 /* -1 is used for the upper bound of (4 byte) "unsigned int"
1672 and "unsigned long", and we already checked for that, so
1673 don't need to test for it here. */
1677 && (self_subrange || n2 == -8))
1678 return debug_make_int_type (dhandle, - n2, true);
1679 else if (n2 == - n3 - 1)
1682 return debug_make_int_type (dhandle, 1, false);
1683 else if (n3 == 0x7fff)
1684 return debug_make_int_type (dhandle, 2, false);
1685 else if (n3 == 0x7fffffff)
1686 return debug_make_int_type (dhandle, 4, false);
1690 /* At this point I don't have the faintest idea how to deal with a
1691 self_subrange type; I'm going to assume that this is used as an
1692 idiom, and that all of them are special cases. So . . . */
1696 return DEBUG_TYPE_NULL;
1699 index_type = stab_find_type (dhandle, info, rangenums);
1700 if (index_type == DEBUG_TYPE_NULL)
1702 /* Does this actually ever happen? Is that why we are worrying
1703 about dealing with it rather than just calling error_type? */
1704 warn_stab (orig, "missing index type");
1705 index_type = debug_make_int_type (dhandle, 4, false);
1708 return debug_make_range_type (dhandle, index_type, n2, n3);
1711 /* Sun's ACC uses a somewhat saner method for specifying the builtin
1712 typedefs in every file (for int, long, etc):
1714 type = b <signed> <width>; <offset>; <nbits>
1715 signed = u or s. Possible c in addition to u or s (for char?).
1716 offset = offset from high order bit to start bit of type.
1717 width is # bytes in object of this type, nbits is # bits in type.
1719 The width/offset stuff appears to be for small objects stored in
1720 larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
1724 parse_stab_sun_builtin_type (dhandle, pp)
1744 return DEBUG_TYPE_NULL;
1748 /* For some odd reason, all forms of char put a c here. This is strange
1749 because no other type has this honor. We can safely ignore this because
1750 we actually determine 'char'acterness by the number of bits specified in
1755 /* The first number appears to be the number of bytes occupied
1756 by this type, except that unsigned short is 4 instead of 2.
1757 Since this information is redundant with the third number,
1758 we will ignore it. */
1759 (void) parse_number (pp, (boolean *) NULL);
1763 return DEBUG_TYPE_NULL;
1767 /* The second number is always 0, so ignore it too. */
1768 (void) parse_number (pp, (boolean *) NULL);
1772 return DEBUG_TYPE_NULL;
1776 /* The third number is the number of bits for this type. */
1777 bits = parse_number (pp, (boolean *) NULL);
1779 /* The type *should* end with a semicolon. If it are embedded
1780 in a larger type the semicolon may be the only way to know where
1781 the type ends. If this type is at the end of the stabstring we
1782 can deal with the omitted semicolon (but we don't have to like
1783 it). Don't bother to complain(), Sun's compiler omits the semicolon
1789 return debug_make_void_type (dhandle);
1791 return debug_make_int_type (dhandle, bits / 8, unsignedp);
1794 /* Parse a builtin floating type generated by the Sun compiler. */
1797 parse_stab_sun_floating_type (dhandle, pp)
1807 /* The first number has more details about the type, for example
1809 details = parse_number (pp, (boolean *) NULL);
1813 return DEBUG_TYPE_NULL;
1816 /* The second number is the number of bytes occupied by this type */
1817 bytes = parse_number (pp, (boolean *) NULL);
1821 return DEBUG_TYPE_NULL;
1824 if (details == NF_COMPLEX
1825 || details == NF_COMPLEX16
1826 || details == NF_COMPLEX32)
1827 return debug_make_complex_type (dhandle, bytes);
1829 return debug_make_float_type (dhandle, bytes);
1832 /* Handle an enum type. */
1835 parse_stab_enum_type (dhandle, pp)
1841 bfd_signed_vma *values;
1847 /* FIXME: gdb checks os9k_stabs here. */
1849 /* The aix4 compiler emits an extra field before the enum members;
1850 my guess is it's a type of some sort. Just ignore it. */
1858 /* Read the value-names and their values.
1859 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
1860 A semicolon or comma instead of a NAME means the end. */
1862 names = (const char **) xmalloc (alloc * sizeof *names);
1863 values = (bfd_signed_vma *) xmalloc (alloc * sizeof *values);
1865 while (**pp != '\0' && **pp != ';' && **pp != ',')
1875 name = savestring (*pp, p - *pp);
1878 val = (bfd_signed_vma) parse_number (pp, (boolean *) NULL);
1882 return DEBUG_TYPE_NULL;
1889 names = ((const char **)
1890 xrealloc ((PTR) names, alloc * sizeof *names));
1891 values = ((bfd_signed_vma *)
1892 xrealloc ((PTR) values, alloc * sizeof *values));
1906 return debug_make_enum_type (dhandle, names, values);
1909 /* Read the description of a structure (or union type) and return an object
1910 describing the type.
1912 PP points to a character pointer that points to the next unconsumed token
1913 in the the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;",
1914 *PP will point to "4a:1,0,32;;". */
1917 parse_stab_struct_type (dhandle, info, tagname, pp, structp, typenums)
1919 struct stab_handle *info;
1920 const char *tagname;
1923 const int *typenums;
1927 debug_baseclass *baseclasses;
1928 debug_field *fields;
1930 debug_method *methods;
1931 debug_type vptrbase;
1937 size = parse_number (pp, (boolean *) NULL);
1939 /* Get the other information. */
1940 if (! parse_stab_baseclasses (dhandle, info, pp, &baseclasses)
1941 || ! parse_stab_struct_fields (dhandle, info, pp, &fields, &statics)
1942 || ! parse_stab_members (dhandle, info, tagname, pp, typenums, &methods)
1943 || ! parse_stab_tilde_field (dhandle, info, pp, typenums, &vptrbase,
1945 return DEBUG_TYPE_NULL;
1948 && baseclasses == NULL
1950 && vptrbase == DEBUG_TYPE_NULL
1952 return debug_make_struct_type (dhandle, structp, size, fields);
1954 return debug_make_object_type (dhandle, structp, size, fields, baseclasses,
1955 methods, vptrbase, ownvptr);
1958 /* The stabs for C++ derived classes contain baseclass information which
1959 is marked by a '!' character after the total size. This function is
1960 called when we encounter the baseclass marker, and slurps up all the
1961 baseclass information.
1963 Immediately following the '!' marker is the number of base classes that
1964 the class is derived from, followed by information for each base class.
1965 For each base class, there are two visibility specifiers, a bit offset
1966 to the base class information within the derived class, a reference to
1967 the type for the base class, and a terminating semicolon.
1969 A typical example, with two base classes, would be "!2,020,19;0264,21;".
1971 Baseclass information marker __________________|| | | | | | |
1972 Number of baseclasses __________________________| | | | | | |
1973 Visibility specifiers (2) ________________________| | | | | |
1974 Offset in bits from start of class _________________| | | | |
1975 Type number for base class ___________________________| | | |
1976 Visibility specifiers (2) _______________________________| | |
1977 Offset in bits from start of class ________________________| |
1978 Type number of base class ____________________________________|
1980 Return true for success, false for failure. */
1983 parse_stab_baseclasses (dhandle, info, pp, retp)
1985 struct stab_handle *info;
1987 debug_baseclass **retp;
1991 debug_baseclass *classes;
1999 /* No base classes. */
2004 c = (unsigned int) parse_number (pp, (boolean *) NULL);
2013 classes = (debug_baseclass *) xmalloc ((c + 1) * sizeof (**retp));
2015 for (i = 0; i < c; i++)
2018 enum debug_visibility visibility;
2031 warn_stab (orig, "unknown virtual character for baseclass");
2040 visibility = DEBUG_VISIBILITY_PRIVATE;
2043 visibility = DEBUG_VISIBILITY_PROTECTED;
2046 visibility = DEBUG_VISIBILITY_PUBLIC;
2049 warn_stab (orig, "unknown visibility character for baseclass");
2050 visibility = DEBUG_VISIBILITY_PUBLIC;
2055 /* The remaining value is the bit offset of the portion of the
2056 object corresponding to this baseclass. Always zero in the
2057 absence of multiple inheritance. */
2058 bitpos = parse_number (pp, (boolean *) NULL);
2066 type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
2067 (debug_type **) NULL);
2068 if (type == DEBUG_TYPE_NULL)
2071 classes[i] = debug_make_baseclass (dhandle, type, bitpos, virtual,
2073 if (classes[i] == DEBUG_BASECLASS_NULL)
2081 classes[i] = DEBUG_BASECLASS_NULL;
2088 /* Read struct or class data fields. They have the form:
2090 NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
2092 At the end, we see a semicolon instead of a field.
2094 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
2097 The optional VISIBILITY is one of:
2099 '/0' (VISIBILITY_PRIVATE)
2100 '/1' (VISIBILITY_PROTECTED)
2101 '/2' (VISIBILITY_PUBLIC)
2102 '/9' (VISIBILITY_IGNORE)
2104 or nothing, for C style fields with public visibility.
2106 Returns 1 for success, 0 for failure. */
2109 parse_stab_struct_fields (dhandle, info, pp, retp, staticsp)
2111 struct stab_handle *info;
2118 debug_field *fields;
2129 fields = (debug_field *) xmalloc (alloc * sizeof *fields);
2132 /* FIXME: gdb checks os9k_stabs here. */
2136 /* Add 1 to c to leave room for NULL pointer at end. */
2140 fields = ((debug_field *)
2141 xrealloc ((PTR) fields, alloc * sizeof *fields));
2144 /* If it starts with CPLUS_MARKER it is a special abbreviation,
2145 unless the CPLUS_MARKER is followed by an underscore, in
2146 which case it is just the name of an anonymous type, which we
2147 should handle like any other type name. We accept either '$'
2148 or '.', because a field name can never contain one of these
2149 characters except as a CPLUS_MARKER. */
2151 if ((*p == '$' || *p == '.') && p[1] != '_')
2154 if (! parse_stab_cpp_abbrev (dhandle, info, pp, fields + c))
2160 /* Look for the ':' that separates the field name from the field
2161 values. Data members are delimited by a single ':', while member
2162 functions are delimited by a pair of ':'s. When we hit the member
2163 functions (if any), terminate scan loop and return. */
2165 p = strchr (p, ':');
2175 if (! parse_stab_one_struct_field (dhandle, info, pp, p, fields + c,
2182 fields[c] = DEBUG_FIELD_NULL;
2189 /* Special GNU C++ name. */
2192 parse_stab_cpp_abbrev (dhandle, info, pp, retp)
2194 struct stab_handle *info;
2202 const char *typename;
2206 *retp = DEBUG_FIELD_NULL;
2220 /* At this point, *pp points to something like "22:23=*22...", where
2221 the type number before the ':' is the "context" and everything
2222 after is a regular type definition. Lookup the type, find it's
2223 name, and construct the field name. */
2225 context = parse_stab_type (dhandle, info, (const char *) NULL, pp,
2226 (debug_type **) NULL);
2227 if (context == DEBUG_TYPE_NULL)
2233 /* $vf -- a virtual function table pointer. */
2237 /* $vb -- a virtual bsomethingorother */
2238 typename = debug_get_type_name (dhandle, context);
2239 if (typename == NULL)
2241 warn_stab (orig, "unnamed $vb type");
2244 name = concat ("_vb$", typename, (const char *) NULL);
2247 warn_stab (orig, "unrecognized C++ abbreviation");
2248 name = "INVALID_CPLUSPLUS_ABBREV";
2259 type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
2260 (debug_type **) NULL);
2268 bitpos = parse_number (pp, (boolean *) NULL);
2276 *retp = debug_make_field (dhandle, name, type, bitpos, 0,
2277 DEBUG_VISIBILITY_PRIVATE);
2278 if (*retp == DEBUG_FIELD_NULL)
2284 /* Parse a single field in a struct or union. */
2287 parse_stab_one_struct_field (dhandle, info, pp, p, retp, staticsp)
2289 struct stab_handle *info;
2297 enum debug_visibility visibility;
2304 /* FIXME: gdb checks ARM_DEMANGLING here. */
2306 name = savestring (*pp, p - *pp);
2311 visibility = DEBUG_VISIBILITY_PUBLIC;
2318 visibility = DEBUG_VISIBILITY_PRIVATE;
2321 visibility = DEBUG_VISIBILITY_PROTECTED;
2324 visibility = DEBUG_VISIBILITY_PUBLIC;
2327 warn_stab (orig, "unknown visibility character for field");
2328 visibility = DEBUG_VISIBILITY_PUBLIC;
2334 type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
2335 (debug_type **) NULL);
2336 if (type == DEBUG_TYPE_NULL)
2343 /* This is a static class member. */
2345 p = strchr (*pp, ';');
2352 varname = savestring (*pp, p - *pp);
2356 *retp = debug_make_static_member (dhandle, name, type, varname,
2370 bitpos = parse_number (pp, (boolean *) NULL);
2378 bitsize = parse_number (pp, (boolean *) NULL);
2386 if (bitpos == 0 && bitsize == 0)
2388 /* This can happen in two cases: (1) at least for gcc 2.4.5 or
2389 so, it is a field which has been optimized out. The correct
2390 stab for this case is to use VISIBILITY_IGNORE, but that is a
2391 recent invention. (2) It is a 0-size array. For example
2392 union { int num; char str[0]; } foo. Printing "<no value>"
2393 for str in "p foo" is OK, since foo.str (and thus foo.str[3])
2394 will continue to work, and a 0-size array as a whole doesn't
2395 have any contents to print.
2397 I suspect this probably could also happen with gcc -gstabs
2398 (not -gstabs+) for static fields, and perhaps other C++
2399 extensions. Hopefully few people use -gstabs with gdb, since
2400 it is intended for dbx compatibility. */
2401 visibility = DEBUG_VISIBILITY_IGNORE;
2404 /* FIXME: gdb does some stuff here to mark fields as unpacked. */
2406 *retp = debug_make_field (dhandle, name, type, bitpos, bitsize, visibility);
2411 /* Read member function stabs info for C++ classes. The form of each member
2414 NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;
2416 An example with two member functions is:
2418 afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;
2420 For the case of overloaded operators, the format is op$::*.funcs, where
2421 $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
2422 name (such as `+=') and `.' marks the end of the operator name. */
2425 parse_stab_members (dhandle, info, tagname, pp, typenums, retp)
2427 struct stab_handle *info;
2428 const char *tagname;
2430 const int *typenums;
2431 debug_method **retp;
2434 debug_method *methods;
2450 debug_method_variant *variants;
2452 unsigned int allocvars;
2453 debug_type look_ahead_type;
2455 p = strchr (*pp, ':');
2456 if (p == NULL || p[1] != ':')
2459 /* FIXME: Some systems use something other than '$' here. */
2460 if ((*pp)[0] != 'o' || (*pp)[1] != 'p' || (*pp)[2] != '$')
2462 name = savestring (*pp, p - *pp);
2467 /* This is a completely wierd case. In order to stuff in the
2468 names that might contain colons (the usual name delimiter),
2469 Mike Tiemann defined a different name format which is
2470 signalled if the identifier is "op$". In that case, the
2471 format is "op$::XXXX." where XXXX is the name. This is
2472 used for names like "+" or "=". YUUUUUUUK! FIXME! */
2474 for (p = *pp; *p != '.' && *p != '\0'; p++)
2481 name = savestring (*pp, p - *pp);
2486 variants = ((debug_method_variant *)
2487 xmalloc (allocvars * sizeof *variants));
2490 look_ahead_type = DEBUG_TYPE_NULL;
2496 enum debug_visibility visibility;
2497 boolean constp, volatilep, staticp;
2500 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, &varargs) != 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;
2764 /* Constructors are sometimes handled specially. */
2765 is_full_physname_constructor = ((argtypes[0] == '_'
2766 && argtypes[1] == '_'
2767 && (isdigit ((unsigned char) argtypes[2])
2768 || argtypes[2] == 'Q'
2769 || argtypes[2] == 't'))
2770 || strncmp (argtypes, "__ct", 4) == 0);
2772 is_constructor = (is_full_physname_constructor
2774 && strcmp (fieldname, tagname) == 0));
2775 is_destructor = ((argtypes[0] == '_'
2776 && (argtypes[1] == '$' || argtypes[1] == '.')
2777 && argtypes[2] == '_')
2778 || strncmp (argtypes, "__dt", 4) == 0);
2780 if (is_destructor || is_full_physname_constructor)
2781 *pphysname = argtypes;
2785 const char *const_prefix;
2786 const char *volatile_prefix;
2788 unsigned int mangled_name_len;
2791 len = tagname == NULL ? 0 : strlen (tagname);
2792 const_prefix = constp ? "C" : "";
2793 volatile_prefix = volatilep ? "V" : "";
2796 sprintf (buf, "__%s%s", const_prefix, volatile_prefix);
2797 else if (tagname != NULL && strchr (tagname, '<') != NULL)
2799 /* Template methods are fully mangled. */
2800 sprintf (buf, "__%s%s", const_prefix, volatile_prefix);
2805 sprintf (buf, "__%s%s%d", const_prefix, volatile_prefix, len);
2807 mangled_name_len = ((is_constructor ? 0 : strlen (fieldname))
2813 if (fieldname[0] == 'o'
2814 && fieldname[1] == 'p'
2815 && (fieldname[2] == '$' || fieldname[2] == '.'))
2819 opname = cplus_mangle_opname (fieldname + 3, 0);
2822 fprintf (stderr, "No mangling for \"%s\"\n", fieldname);
2823 return DEBUG_TYPE_NULL;
2825 mangled_name_len += strlen (opname);
2826 physname = (char *) xmalloc (mangled_name_len);
2827 strncpy (physname, fieldname, 3);
2828 strcpy (physname + 3, opname);
2832 physname = (char *) xmalloc (mangled_name_len);
2836 strcpy (physname, fieldname);
2839 strcat (physname, buf);
2840 if (tagname != NULL)
2841 strcat (physname, tagname);
2842 strcat (physname, argtypes);
2844 *pphysname = physname;
2847 if (*argtypes == '\0')
2849 args = (debug_type *) xmalloc (sizeof *args);
2851 return debug_make_method_type (dhandle, return_type, class_type, args,
2855 args = stab_demangle_argtypes (dhandle, info, *pphysname, &varargs);
2857 return DEBUG_TYPE_NULL;
2859 return debug_make_method_type (dhandle, return_type, class_type, args,
2863 /* The tail end of stabs for C++ classes that contain a virtual function
2864 pointer contains a tilde, a %, and a type number.
2865 The type number refers to the base class (possibly this class itself) which
2866 contains the vtable pointer for the current class.
2868 This function is called when we have parsed all the method declarations,
2869 so we can look for the vptr base class info. */
2872 parse_stab_tilde_field (dhandle, info, pp, typenums, retvptrbase, retownvptr)
2874 struct stab_handle *info;
2876 const int *typenums;
2877 debug_type *retvptrbase;
2878 boolean *retownvptr;
2884 *retvptrbase = DEBUG_TYPE_NULL;
2885 *retownvptr = false;
2889 /* If we are positioned at a ';', then skip it. */
2898 if (**pp == '=' || **pp == '+' || **pp == '-')
2900 /* Obsolete flags that used to indicate the presence of
2901 constructors and/or destructors. */
2912 /* The next number is the type number of the base class (possibly
2913 our own class) which supplies the vtable for this class. */
2914 if (! parse_stab_type_number (pp, vtypenums))
2917 if (vtypenums[0] == typenums[0]
2918 && vtypenums[1] == typenums[1])
2927 vtype = parse_stab_type (dhandle, info, (const char *) NULL, pp,
2928 (debug_type **) NULL);
2929 for (p = *pp; *p != ';' && *p != '\0'; p++)
2937 *retvptrbase = vtype;
2945 /* Read a definition of an array type. */
2948 parse_stab_array_type (dhandle, info, pp, stringp)
2950 struct stab_handle *info;
2955 debug_type index_type;
2957 bfd_signed_vma lower, upper;
2958 debug_type element_type;
2960 /* Format of an array type:
2961 "ar<index type>;lower;upper;<array_contents_type>".
2962 OS9000: "arlower,upper;<array_contents_type>".
2964 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
2965 for these, produce a type like float[][]. */
2969 /* FIXME: gdb checks os9k_stabs here. */
2971 index_type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
2972 (debug_type **) NULL);
2976 return DEBUG_TYPE_NULL;
2982 if (! isdigit ((unsigned char) **pp) && **pp != '-')
2988 lower = (bfd_signed_vma) parse_number (pp, (boolean *) NULL);
2996 if (! isdigit ((unsigned char) **pp) && **pp != '-')
3002 upper = (bfd_signed_vma) parse_number (pp, (boolean *) NULL);
3010 element_type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
3011 (debug_type **) NULL);
3012 if (element_type == DEBUG_TYPE_NULL)
3021 return debug_make_array_type (dhandle, element_type, index_type, lower,
3025 /* Keep a stack of N_BINCL include files. */
3029 struct bincl_file *next;
3033 /* Start a new N_BINCL file, pushing it onto the stack. */
3036 push_bincl (info, name)
3037 struct stab_handle *info;
3040 struct bincl_file *n;
3042 n = (struct bincl_file *) xmalloc (sizeof *n);
3043 n->next = info->bincl_stack;
3045 info->bincl_stack = n;
3048 info->file_types = ((struct stab_types **)
3049 xrealloc ((PTR) info->file_types,
3051 * sizeof *info->file_types)));
3052 info->file_types[info->files - 1] = NULL;
3055 /* Finish an N_BINCL file, at an N_EINCL, popping the name off the
3060 struct stab_handle *info;
3062 struct bincl_file *o;
3064 o = info->bincl_stack;
3066 return info->main_filename;
3067 info->bincl_stack = o->next;
3069 if (info->bincl_stack == NULL)
3070 return info->main_filename;
3071 return info->bincl_stack->name;
3074 /* Handle a variable definition. gcc emits variable definitions for a
3075 block before the N_LBRAC, so we must hold onto them until we see
3076 it. The SunPRO compiler emits variable definitions after the
3077 N_LBRAC, so we can call debug_record_variable immediately. */
3080 stab_record_variable (dhandle, info, name, type, kind, val)
3082 struct stab_handle *info;
3085 enum debug_var_kind kind;
3088 struct stab_pending_var *v;
3090 if ((kind == DEBUG_GLOBAL || kind == DEBUG_STATIC)
3091 || ! info->within_function
3092 || (info->gcc_compiled == 0 && info->n_opt_found))
3093 return debug_record_variable (dhandle, name, type, kind, val);
3095 v = (struct stab_pending_var *) xmalloc (sizeof *v);
3096 memset (v, 0, sizeof *v);
3098 v->next = info->pending;
3108 /* Emit pending variable definitions. This is called after we see the
3109 N_LBRAC that starts the block. */
3112 stab_emit_pending_vars (dhandle, info)
3114 struct stab_handle *info;
3116 struct stab_pending_var *v;
3121 struct stab_pending_var *next;
3123 if (! debug_record_variable (dhandle, v->name, v->type, v->kind, v->val))
3131 info->pending = NULL;
3136 /* Find the slot for a type in the database. */
3139 stab_find_slot (info, typenums)
3140 struct stab_handle *info;
3141 const int *typenums;
3145 struct stab_types **ps;
3147 filenum = typenums[0];
3148 index = typenums[1];
3150 if (filenum < 0 || (unsigned int) filenum >= info->files)
3152 fprintf (stderr, "Type file number %d out of range\n", filenum);
3157 fprintf (stderr, "Type index number %d out of range\n", index);
3161 ps = info->file_types + filenum;
3163 while (index >= STAB_TYPES_SLOTS)
3167 *ps = (struct stab_types *) xmalloc (sizeof **ps);
3168 memset (*ps, 0, sizeof **ps);
3171 index -= STAB_TYPES_SLOTS;
3175 *ps = (struct stab_types *) xmalloc (sizeof **ps);
3176 memset (*ps, 0, sizeof **ps);
3179 return (*ps)->types + index;
3182 /* Find a type given a type number. If the type has not been
3183 allocated yet, create an indirect type. */
3186 stab_find_type (dhandle, info, typenums)
3188 struct stab_handle *info;
3189 const int *typenums;
3193 if (typenums[0] == 0 && typenums[1] < 0)
3195 /* A negative type number indicates an XCOFF builtin type. */
3196 return stab_xcoff_builtin_type (dhandle, info, typenums[1]);
3199 slot = stab_find_slot (info, typenums);
3201 return DEBUG_TYPE_NULL;
3203 if (*slot == DEBUG_TYPE_NULL)
3204 return debug_make_indirect_type (dhandle, slot, (const char *) NULL);
3209 /* Record that a given type number refers to a given type. */
3212 stab_record_type (dhandle, info, typenums, type)
3214 struct stab_handle *info;
3215 const int *typenums;
3220 slot = stab_find_slot (info, typenums);
3224 /* gdb appears to ignore type redefinitions, so we do as well. */
3231 /* Return an XCOFF builtin type. */
3234 stab_xcoff_builtin_type (dhandle, info, typenum)
3236 struct stab_handle *info;
3242 if (typenum >= 0 || typenum < -XCOFF_TYPE_COUNT)
3244 fprintf (stderr, "Unrecognized XCOFF type %d\n", typenum);
3245 return DEBUG_TYPE_NULL;
3247 if (info->xcoff_types[-typenum] != NULL)
3248 return info->xcoff_types[-typenum];
3253 /* The size of this and all the other types are fixed, defined
3254 by the debugging format. */
3256 rettype = debug_make_int_type (dhandle, 4, false);
3260 rettype = debug_make_int_type (dhandle, 1, false);
3264 rettype = debug_make_int_type (dhandle, 2, false);
3268 rettype = debug_make_int_type (dhandle, 4, false);
3271 name = "unsigned char";
3272 rettype = debug_make_int_type (dhandle, 1, true);
3275 name = "signed char";
3276 rettype = debug_make_int_type (dhandle, 1, false);
3279 name = "unsigned short";
3280 rettype = debug_make_int_type (dhandle, 2, true);
3283 name = "unsigned int";
3284 rettype = debug_make_int_type (dhandle, 4, true);
3288 rettype = debug_make_int_type (dhandle, 4, true);
3290 name = "unsigned long";
3291 rettype = debug_make_int_type (dhandle, 4, true);
3295 rettype = debug_make_void_type (dhandle);
3298 /* IEEE single precision (32 bit). */
3300 rettype = debug_make_float_type (dhandle, 4);
3303 /* IEEE double precision (64 bit). */
3305 rettype = debug_make_float_type (dhandle, 8);
3308 /* This is an IEEE double on the RS/6000, and different machines
3309 with different sizes for "long double" should use different
3310 negative type numbers. See stabs.texinfo. */
3311 name = "long double";
3312 rettype = debug_make_float_type (dhandle, 8);
3316 rettype = debug_make_int_type (dhandle, 4, false);
3320 rettype = debug_make_bool_type (dhandle, 4);
3323 name = "short real";
3324 rettype = debug_make_float_type (dhandle, 4);
3328 rettype = debug_make_float_type (dhandle, 8);
3338 rettype = debug_make_int_type (dhandle, 1, true);
3342 rettype = debug_make_bool_type (dhandle, 1);
3346 rettype = debug_make_bool_type (dhandle, 2);
3350 rettype = debug_make_bool_type (dhandle, 4);
3354 rettype = debug_make_bool_type (dhandle, 4);
3357 /* Complex type consisting of two IEEE single precision values. */
3359 rettype = debug_make_complex_type (dhandle, 8);
3362 /* Complex type consisting of two IEEE double precision values. */
3363 name = "double complex";
3364 rettype = debug_make_complex_type (dhandle, 16);
3368 rettype = debug_make_int_type (dhandle, 1, false);
3372 rettype = debug_make_int_type (dhandle, 2, false);
3376 rettype = debug_make_int_type (dhandle, 4, false);
3381 rettype = debug_make_int_type (dhandle, 2, false);
3385 rettype = debug_make_int_type (dhandle, 8, false);
3388 name = "unsigned long long";
3389 rettype = debug_make_int_type (dhandle, 8, true);
3393 rettype = debug_make_bool_type (dhandle, 8);
3397 rettype = debug_make_int_type (dhandle, 8, false);
3403 rettype = debug_name_type (dhandle, name, rettype);
3405 info->xcoff_types[-typenum] = rettype;
3410 /* Find or create a tagged type. */
3413 stab_find_tagged_type (dhandle, info, p, len, kind)
3415 struct stab_handle *info;
3418 enum debug_type_kind kind;
3422 struct stab_tag *st;
3424 name = savestring (p, len);
3426 /* We pass DEBUG_KIND_ILLEGAL because we want all tags in the same
3427 namespace. This is right for C, and I don't know how to handle
3428 other languages. FIXME. */
3429 dtype = debug_find_tagged_type (dhandle, name, DEBUG_KIND_ILLEGAL);
3430 if (dtype != DEBUG_TYPE_NULL)
3436 /* We need to allocate an entry on the undefined tag list. */
3437 for (st = info->tags; st != NULL; st = st->next)
3439 if (st->name[0] == name[0]
3440 && strcmp (st->name, name) == 0)
3442 if (st->kind == DEBUG_KIND_ILLEGAL)
3450 st = (struct stab_tag *) xmalloc (sizeof *st);
3451 memset (st, 0, sizeof *st);
3453 st->next = info->tags;
3456 st->slot = DEBUG_TYPE_NULL;
3457 st->type = debug_make_indirect_type (dhandle, &st->slot, name);
3464 /* In order to get the correct argument types for a stubbed method, we
3465 need to extract the argument types from a C++ mangled string.
3466 Since the argument types can refer back to the return type, this
3467 means that we must demangle the entire physical name. In gdb this
3468 is done by calling cplus_demangle and running the results back
3469 through the C++ expression parser. Since we have no expression
3470 parser, we must duplicate much of the work of cplus_demangle here.
3472 We assume that GNU style demangling is used, since this is only
3473 done for method stubs, and only g++ should output that form of
3474 debugging information. */
3476 /* This structure is used to hold a pointer to type information which
3477 demangling a string. */
3479 struct stab_demangle_typestring
3481 /* The start of the type. This is not null terminated. */
3482 const char *typestring;
3483 /* The length of the type. */
3487 /* This structure is used to hold information while demangling a
3490 struct stab_demangle_info
3492 /* The debugging information handle. */
3494 /* The stab information handle. */
3495 struct stab_handle *info;
3496 /* The array of arguments we are building. */
3498 /* Whether the method takes a variable number of arguments. */
3500 /* The array of types we have remembered. */
3501 struct stab_demangle_typestring *typestrings;
3502 /* The number of typestrings. */
3503 unsigned int typestring_count;
3504 /* The number of typestring slots we have allocated. */
3505 unsigned int typestring_alloc;
3508 static void stab_bad_demangle PARAMS ((const char *));
3509 static unsigned int stab_demangle_count PARAMS ((const char **));
3510 static boolean stab_demangle_get_count
3511 PARAMS ((const char **, unsigned int *));
3512 static boolean stab_demangle_prefix
3513 PARAMS ((struct stab_demangle_info *, const char **));
3514 static boolean stab_demangle_function_name
3515 PARAMS ((struct stab_demangle_info *, const char **, const char *));
3516 static boolean stab_demangle_signature
3517 PARAMS ((struct stab_demangle_info *, const char **));
3518 static boolean stab_demangle_qualified
3519 PARAMS ((struct stab_demangle_info *, const char **, debug_type *));
3520 static boolean stab_demangle_template
3521 PARAMS ((struct stab_demangle_info *, const char **));
3522 static boolean stab_demangle_class
3523 PARAMS ((struct stab_demangle_info *, const char **, const char **));
3524 static boolean stab_demangle_args
3525 PARAMS ((struct stab_demangle_info *, const char **, debug_type **,
3527 static boolean stab_demangle_arg
3528 PARAMS ((struct stab_demangle_info *, const char **, debug_type **,
3529 unsigned int *, unsigned int *));
3530 static boolean stab_demangle_type
3531 PARAMS ((struct stab_demangle_info *, const char **, debug_type *));
3532 static boolean stab_demangle_fund_type
3533 PARAMS ((struct stab_demangle_info *, const char **, debug_type *));
3534 static boolean stab_demangle_remember_type
3535 PARAMS ((struct stab_demangle_info *, const char *, int));
3537 /* Warn about a bad demangling. */
3540 stab_bad_demangle (s)
3543 fprintf (stderr, "bad mangled name `%s'\n", s);
3546 /* Get a count from a stab string. */
3549 stab_demangle_count (pp)
3555 while (isdigit ((unsigned char) **pp))
3558 count += **pp - '0';
3564 /* Require a count in a string. The count may be multiple digits, in
3565 which case it must end in an underscore. */
3568 stab_demangle_get_count (pp, pi)
3572 if (! isdigit ((unsigned char) **pp))
3577 if (isdigit ((unsigned char) **pp))
3590 while (isdigit ((unsigned char) *p));
3601 /* This function demangles a physical name, returning a NULL
3602 terminated array of argument types. */
3605 stab_demangle_argtypes (dhandle, info, physname, pvarargs)
3607 struct stab_handle *info;
3608 const char *physname;
3611 struct stab_demangle_info minfo;
3613 minfo.dhandle = dhandle;
3616 minfo.varargs = false;
3617 minfo.typestring_alloc = 10;
3618 minfo.typestrings = ((struct stab_demangle_typestring *)
3619 xmalloc (minfo.typestring_alloc
3620 * sizeof *minfo.typestrings));
3621 minfo.typestring_count = 0;
3623 /* cplus_demangle checks for special GNU mangled forms, but we can't
3624 see any of them in mangled method argument types. */
3626 if (! stab_demangle_prefix (&minfo, &physname))
3629 if (*physname != '\0')
3631 if (! stab_demangle_signature (&minfo, &physname))
3635 free (minfo.typestrings);
3636 minfo.typestrings = NULL;
3638 if (minfo.args == NULL)
3639 fprintf (stderr, "no argument types in mangled string\n");
3641 *pvarargs = minfo.varargs;
3645 if (minfo.typestrings != NULL)
3646 free (minfo.typestrings);
3650 /* Demangle the prefix of the mangled name. */
3653 stab_demangle_prefix (minfo, pp)
3654 struct stab_demangle_info *minfo;
3660 /* cplus_demangle checks for global constructors and destructors,
3661 but we can't see them in mangled argument types. */
3663 /* Look for `__'. */
3667 scan = strchr (scan, '_');
3669 while (scan != NULL && *++scan != '_');
3673 stab_bad_demangle (*pp);
3679 /* We found `__'; move ahead to the last contiguous `__' pair. */
3680 i = strspn (scan, "_");
3685 && (isdigit ((unsigned char) scan[2])
3689 /* This is a GNU style constructor name. */
3693 else if (scan == *pp
3694 && ! isdigit ((unsigned char) scan[2])
3697 /* Look for the `__' that separates the prefix from the
3699 while (*scan == '_')
3701 scan = strstr (scan, "__");
3702 if (scan == NULL || scan[2] == '\0')
3704 stab_bad_demangle (*pp);
3708 return stab_demangle_function_name (minfo, pp, scan);
3710 else if (scan[2] != '\0')
3712 /* The name doesn't start with `__', but it does contain `__'. */
3713 return stab_demangle_function_name (minfo, pp, scan);
3717 stab_bad_demangle (*pp);
3723 /* Demangle a function name prefix. The scan argument points to the
3724 double underscore which separates the function name from the
3728 stab_demangle_function_name (minfo, pp, scan)
3729 struct stab_demangle_info *minfo;
3735 /* The string from *pp to scan is the name of the function. We
3736 don't care about the name, since we just looking for argument
3737 types. However, for conversion operators, the name may include a
3738 type which we must remember in order to handle backreferences. */
3744 && strncmp (name, "type", 4) == 0
3745 && (name[4] == '$' || name[4] == '.'))
3749 /* This is a type conversion operator. */
3751 if (! stab_demangle_type (minfo, &tem, (debug_type *) NULL))
3754 else if (name[0] == '_'
3761 /* This is a type conversion operator. */
3763 if (! stab_demangle_type (minfo, &tem, (debug_type *) NULL))
3770 /* Demangle the signature. This is where the argument types are
3774 stab_demangle_signature (minfo, pp)
3775 struct stab_demangle_info *minfo;
3779 boolean expect_func, func_done;
3784 expect_func = false;
3788 while (**pp != '\0')
3794 if (! stab_demangle_qualified (minfo, pp, (debug_type *) NULL)
3795 || ! stab_demangle_remember_type (minfo, hold, *pp - hold))
3802 /* Static member function. FIXME: Can this happen? */
3809 /* Const member function. */
3815 case '0': case '1': case '2': case '3': case '4':
3816 case '5': case '6': case '7': case '8': case '9':
3819 if (! stab_demangle_class (minfo, pp, (const char **) NULL)
3820 || ! stab_demangle_remember_type (minfo, hold, *pp - hold))
3827 /* Function. I don't know if this actually happens with g++
3832 if (! stab_demangle_args (minfo, pp, &minfo->args, &minfo->varargs))
3840 if (! stab_demangle_template (minfo, pp)
3841 || ! stab_demangle_remember_type (minfo, hold, *pp - hold))
3848 /* At the outermost level, we cannot have a return type
3849 specified, so if we run into another '_' at this point we
3850 are dealing with a mangled name that is either bogus, or
3851 has been mangled by some algorithm we don't know how to
3852 deal with. So just reject the entire demangling. */
3853 stab_bad_demangle (orig);
3857 /* Assume we have stumbled onto the first outermost function
3858 argument token, and start processing args. */
3860 if (! stab_demangle_args (minfo, pp, &minfo->args, &minfo->varargs))
3868 if (! stab_demangle_args (minfo, pp, &minfo->args, &minfo->varargs))
3875 /* With GNU style demangling, bar__3foo is 'foo::bar(void)', and
3876 bar__3fooi is 'foo::bar(int)'. We get here when we find the
3877 first case, and need to ensure that the '(void)' gets added
3878 to the current declp. */
3879 if (! stab_demangle_args (minfo, pp, &minfo->args, &minfo->varargs))
3886 /* Demangle a qualified name, such as "Q25Outer5Inner" which is the
3887 mangled form of "Outer::Inner". */
3890 stab_demangle_qualified (minfo, pp, ptype)
3891 struct stab_demangle_info *minfo;
3897 unsigned int qualifiers;
3905 /* GNU mangled name with more than 9 classes. The count is
3906 preceded by an underscore (to distinguish it from the <= 9
3907 case) and followed by an underscore. */
3909 if (! isdigit ((unsigned char) *p) || *p == '0')
3911 stab_bad_demangle (orig);
3914 qualifiers = atoi (p);
3915 while (isdigit ((unsigned char) *p))
3919 stab_bad_demangle (orig);
3925 case '1': case '2': case '3': case '4': case '5':
3926 case '6': case '7': case '8': case '9':
3927 qualifiers = (*pp)[1] - '0';
3928 /* Skip an optional underscore after the count. */
3929 if ((*pp)[2] == '_')
3936 stab_bad_demangle (orig);
3940 context = DEBUG_TYPE_NULL;
3942 /* Pick off the names. */
3943 while (qualifiers-- > 0)
3949 /* FIXME: I don't know how to handle the ptype != NULL case
3951 if (! stab_demangle_template (minfo, pp))
3958 len = stab_demangle_count (pp);
3959 if (strlen (*pp) < len)
3961 stab_bad_demangle (orig);
3967 const debug_field *fields;
3970 if (context != DEBUG_TYPE_NULL)
3971 fields = debug_get_fields (minfo->dhandle, context);
3973 context = DEBUG_TYPE_NULL;
3979 /* Try to find the type by looking through the
3980 fields of context until we find a field with the
3981 same type. This ought to work for a class
3982 defined within a class, but it won't work for,
3983 e.g., an enum defined within a class. stabs does
3984 not give us enough information to figure out the
3987 name = savestring (*pp, len);
3989 for (; *fields != DEBUG_FIELD_NULL; fields++)
3994 ft = debug_get_field_type (minfo->dhandle, *fields);
3997 dn = debug_get_type_name (minfo->dhandle, ft);
3998 if (dn != NULL && strcmp (dn, name) == 0)
4008 if (context == DEBUG_TYPE_NULL)
4010 /* We have to fall back on finding the type by name.
4011 If there are more types to come, then this must
4012 be a class. Otherwise, it could be anything. */
4014 if (qualifiers == 0)
4018 name = savestring (*pp, len);
4019 context = debug_find_named_type (minfo->dhandle,
4024 if (context == DEBUG_TYPE_NULL)
4026 context = stab_find_tagged_type (minfo->dhandle,
4030 ? DEBUG_KIND_ILLEGAL
4031 : DEBUG_KIND_CLASS));
4032 if (context == DEBUG_TYPE_NULL)
4048 /* Demangle a template. */
4051 stab_demangle_template (minfo, pp)
4052 struct stab_demangle_info *minfo;
4062 /* Skip the template name. */
4063 r = stab_demangle_count (pp);
4064 if (r == 0 || strlen (*pp) < r)
4066 stab_bad_demangle (orig);
4071 /* Get the size of the parameter list. */
4072 if (stab_demangle_get_count (pp, &r) == 0)
4074 stab_bad_demangle (orig);
4078 for (i = 0; i < r; i++)
4082 /* This is a type parameter. */
4084 if (! stab_demangle_type (minfo, pp, (debug_type *) NULL))
4090 boolean pointerp, realp, integralp, charp, boolp;
4101 /* This is a value parameter. */
4103 if (! stab_demangle_type (minfo, pp, (debug_type *) NULL))
4106 while (*old_p != '\0' && ! done)
4116 case 'C': /* Const. */
4117 case 'S': /* Signed. */
4118 case 'U': /* Unsigned. */
4119 case 'V': /* Volatile. */
4120 case 'F': /* Function. */
4121 case 'M': /* Member function. */
4125 case 'Q': /* Qualified name. */
4129 case 'T': /* Remembered type. */
4131 case 'v': /* Void. */
4133 case 'x': /* Long long. */
4134 case 'l': /* Long. */
4135 case 'i': /* Int. */
4136 case 's': /* Short. */
4137 case 'w': /* Wchar_t. */
4141 case 'b': /* Bool. */
4145 case 'c': /* Char. */
4149 case 'r': /* Long double. */
4150 case 'd': /* Double. */
4151 case 'f': /* Float. */
4156 /* Assume it's a uder defined integral type. */
4167 while (isdigit ((unsigned char) **pp))
4176 val = stab_demangle_count (pp);
4179 stab_bad_demangle (orig);
4187 val = stab_demangle_count (pp);
4188 if (val != 0 && val != 1)
4190 stab_bad_demangle (orig);
4198 while (isdigit ((unsigned char) **pp))
4203 while (isdigit ((unsigned char) **pp))
4209 while (isdigit ((unsigned char) **pp))
4217 if (! stab_demangle_get_count (pp, &len))
4219 stab_bad_demangle (orig);
4230 /* Demangle a class name. */
4233 stab_demangle_class (minfo, pp, pstart)
4234 struct stab_demangle_info *minfo;
4236 const char **pstart;
4243 n = stab_demangle_count (pp);
4244 if (strlen (*pp) < n)
4246 stab_bad_demangle (orig);
4258 /* Demangle function arguments. If the pargs argument is not NULL, it
4259 is set to a NULL terminated array holding the arguments. */
4262 stab_demangle_args (minfo, pp, pargs, pvarargs)
4263 struct stab_demangle_info *minfo;
4269 unsigned int alloc, count;
4276 *pargs = (debug_type *) xmalloc (alloc * sizeof **pargs);
4281 while (**pp != '_' && **pp != '\0' && **pp != 'e')
4283 if (**pp == 'N' || **pp == 'T')
4291 if (temptype == 'T')
4295 if (! stab_demangle_get_count (pp, &r))
4297 stab_bad_demangle (orig);
4302 if (! stab_demangle_get_count (pp, &t))
4304 stab_bad_demangle (orig);
4308 if (t >= minfo->typestring_count)
4310 stab_bad_demangle (orig);
4317 tem = minfo->typestrings[t].typestring;
4318 if (! stab_demangle_arg (minfo, &tem, pargs, &count, &alloc))
4324 if (! stab_demangle_arg (minfo, pp, pargs, &count, &alloc))
4330 (*pargs)[count] = DEBUG_TYPE_NULL;
4342 /* Demangle a single argument. */
4345 stab_demangle_arg (minfo, pp, pargs, pcount, palloc)
4346 struct stab_demangle_info *minfo;
4349 unsigned int *pcount;
4350 unsigned int *palloc;
4356 if (! stab_demangle_type (minfo, pp,
4357 pargs == NULL ? (debug_type *) NULL : &type)
4358 || ! stab_demangle_remember_type (minfo, start, *pp - start))
4363 if (type == DEBUG_TYPE_NULL)
4366 if (*pcount + 1 >= *palloc)
4369 *pargs = ((debug_type *)
4370 xrealloc (*pargs, *palloc * sizeof **pargs));
4372 (*pargs)[*pcount] = type;
4379 /* Demangle a type. If the ptype argument is not NULL, *ptype is set
4380 to the newly allocated type. */
4383 stab_demangle_type (minfo, pp, ptype)
4384 struct stab_demangle_info *minfo;
4396 /* A pointer type. */
4398 if (! stab_demangle_type (minfo, pp, ptype))
4401 *ptype = debug_make_pointer_type (minfo->dhandle, *ptype);
4405 /* A reference type. */
4407 if (! stab_demangle_type (minfo, pp, ptype))
4410 *ptype = debug_make_reference_type (minfo->dhandle, *ptype);
4420 while (**pp != '\0' && **pp != '_')
4422 if (! isdigit ((unsigned char) **pp))
4424 stab_bad_demangle (orig);
4433 stab_bad_demangle (orig);
4438 if (! stab_demangle_type (minfo, pp, ptype))
4442 debug_type int_type;
4444 int_type = debug_find_named_type (minfo->dhandle, "int");
4445 if (int_type == NULL)
4446 int_type = debug_make_int_type (minfo->dhandle, 4, false);
4447 *ptype = debug_make_array_type (minfo->dhandle, *ptype, int_type,
4454 /* A back reference to a remembered type. */
4460 if (! stab_demangle_get_count (pp, &i))
4462 stab_bad_demangle (orig);
4465 if (i >= minfo->typestring_count)
4467 stab_bad_demangle (orig);
4470 p = minfo->typestrings[i].typestring;
4471 if (! stab_demangle_type (minfo, &p, ptype))
4483 if (! stab_demangle_args (minfo, pp,
4485 ? (debug_type **) NULL
4493 /* cplus_demangle will accept a function without a return
4494 type, but I don't know when that will happen, or what
4495 to do if it does. */
4496 stab_bad_demangle (orig);
4500 if (! stab_demangle_type (minfo, pp, ptype))
4503 *ptype = debug_make_function_type (minfo->dhandle, *ptype, args,
4512 boolean memberp, constp, volatilep;
4518 memberp = **pp == 'M';
4525 if (! isdigit ((unsigned char) **pp))
4527 stab_bad_demangle (orig);
4530 n = stab_demangle_count (pp);
4531 if (strlen (*pp) < n)
4533 stab_bad_demangle (orig);
4546 else if (**pp == 'V')
4553 stab_bad_demangle (orig);
4557 if (! stab_demangle_args (minfo, pp,
4559 ? (debug_type **) NULL
4569 stab_bad_demangle (orig);
4574 if (! stab_demangle_type (minfo, pp, ptype))
4579 debug_type class_type;
4581 class_type = stab_find_tagged_type (minfo->dhandle, minfo->info,
4584 if (class_type == DEBUG_TYPE_NULL)
4588 *ptype = debug_make_offset_type (minfo->dhandle, class_type,
4592 /* FIXME: We have no way to record constp or
4594 *ptype = debug_make_method_type (minfo->dhandle, *ptype,
4595 class_type, args, varargs);
4603 if (! stab_demangle_type (minfo, pp, ptype))
4609 if (! stab_demangle_type (minfo, pp, ptype))
4612 *ptype = debug_make_const_type (minfo->dhandle, *ptype);
4620 if (! stab_demangle_qualified (minfo, pp, ptype))
4626 if (! stab_demangle_fund_type (minfo, pp, ptype))
4634 /* Demangle a fundamental type. If the ptype argument is not NULL,
4635 *ptype is set to the newly allocated type. */
4638 stab_demangle_fund_type (minfo, pp, ptype)
4639 struct stab_demangle_info *minfo;
4644 boolean constp, volatilep, unsignedp, signedp;
4689 /* cplus_demangle permits this, but I don't know what it means. */
4690 stab_bad_demangle (orig);
4693 case 'v': /* void */
4696 *ptype = debug_find_named_type (minfo->dhandle, "void");
4697 if (*ptype == DEBUG_TYPE_NULL)
4698 *ptype = debug_make_void_type (minfo->dhandle);
4703 case 'x': /* long long */
4706 *ptype = debug_find_named_type (minfo->dhandle,
4708 ? "long long unsigned int"
4709 : "long long int"));
4710 if (*ptype == DEBUG_TYPE_NULL)
4711 *ptype = debug_make_int_type (minfo->dhandle, 8, unsignedp);
4716 case 'l': /* long */
4719 *ptype = debug_find_named_type (minfo->dhandle,
4721 ? "long unsigned int"
4723 if (*ptype == DEBUG_TYPE_NULL)
4724 *ptype = debug_make_int_type (minfo->dhandle, 4, unsignedp);
4732 *ptype = debug_find_named_type (minfo->dhandle,
4736 if (*ptype == DEBUG_TYPE_NULL)
4737 *ptype = debug_make_int_type (minfo->dhandle, 4, unsignedp);
4742 case 's': /* short */
4745 *ptype = debug_find_named_type (minfo->dhandle,
4747 ? "short unsigned int"
4749 if (*ptype == DEBUG_TYPE_NULL)
4750 *ptype = debug_make_int_type (minfo->dhandle, 2, unsignedp);
4755 case 'b': /* bool */
4758 *ptype = debug_find_named_type (minfo->dhandle, "bool");
4759 if (*ptype == DEBUG_TYPE_NULL)
4760 *ptype = debug_make_bool_type (minfo->dhandle, 4);
4765 case 'c': /* char */
4768 *ptype = debug_find_named_type (minfo->dhandle,
4774 if (*ptype == DEBUG_TYPE_NULL)
4775 *ptype = debug_make_int_type (minfo->dhandle, 1, unsignedp);
4780 case 'w': /* wchar_t */
4783 *ptype = debug_find_named_type (minfo->dhandle, "__wchar_t");
4784 if (*ptype == DEBUG_TYPE_NULL)
4785 *ptype = debug_make_int_type (minfo->dhandle, 2, true);
4790 case 'r': /* long double */
4793 *ptype = debug_find_named_type (minfo->dhandle, "long double");
4794 if (*ptype == DEBUG_TYPE_NULL)
4795 *ptype = debug_make_float_type (minfo->dhandle, 8);
4800 case 'd': /* double */
4803 *ptype = debug_find_named_type (minfo->dhandle, "double");
4804 if (*ptype == DEBUG_TYPE_NULL)
4805 *ptype = debug_make_float_type (minfo->dhandle, 8);
4810 case 'f': /* float */
4813 *ptype = debug_find_named_type (minfo->dhandle, "float");
4814 if (*ptype == DEBUG_TYPE_NULL)
4815 *ptype = debug_make_float_type (minfo->dhandle, 4);
4822 if (! isdigit ((unsigned char) **pp))
4824 stab_bad_demangle (orig);
4828 case '0': case '1': case '2': case '3': case '4':
4829 case '5': case '6': case '7': case '8': case '9':
4833 if (! stab_demangle_class (minfo, pp, &hold))
4839 name = savestring (hold, *pp - hold);
4840 *ptype = debug_find_named_type (minfo->dhandle, name);
4841 if (*ptype == DEBUG_TYPE_NULL)
4843 /* FIXME: It is probably incorrect to assume that
4844 undefined types are tagged types. */
4845 *ptype = stab_find_tagged_type (minfo->dhandle, minfo->info,
4847 DEBUG_KIND_ILLEGAL);
4855 if (! stab_demangle_template (minfo, pp))
4861 stab_bad_demangle (orig);
4868 *ptype = debug_make_const_type (minfo->dhandle, *ptype);
4870 *ptype = debug_make_volatile_type (minfo->dhandle, *ptype);
4876 /* Remember a type string in a demangled string. */
4879 stab_demangle_remember_type (minfo, p, len)
4880 struct stab_demangle_info *minfo;
4884 if (minfo->typestring_count >= minfo->typestring_alloc)
4886 minfo->typestring_alloc += 10;
4887 minfo->typestrings = ((struct stab_demangle_typestring *)
4888 xrealloc (minfo->typestrings,
4889 (minfo->typestring_alloc
4890 * sizeof *minfo->typestrings)));
4893 minfo->typestrings[minfo->typestring_count].typestring = p;
4894 minfo->typestrings[minfo->typestring_count].len = (unsigned int) len;
4895 ++minfo->typestring_count;