1 /* stabs.c -- Parse stabs debugging information
2 Copyright (C) 1995, 1996 Free Software Foundation, Inc.
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. */
54 /* True if this is stabs in sections. */
56 /* The symbol table. */
58 /* The number of symbols. */
60 /* The accumulated file name string. */
62 /* The value of the last N_SO symbol. */
64 /* The value of the start of the file, so that we can handle file
65 relative N_LBRAC and N_RBRAC symbols. */
66 bfd_vma file_start_offset;
67 /* The offset of the start of the function, so that we can handle
68 function relative N_LBRAC and N_RBRAC symbols. */
69 bfd_vma function_start_offset;
70 /* The version number of gcc which compiled the current compilation
71 unit, 0 if not compiled by gcc. */
73 /* Whether an N_OPT symbol was seen that was not generated by gcc,
74 so that we can detect the SunPRO compiler. */
76 /* The main file name. */
78 /* A stack of N_BINCL files. */
79 struct bincl_file *bincl_stack;
80 /* Whether we are inside a function or not. */
81 boolean within_function;
82 /* The address of the end of the function, used if we have seen an
83 N_FUN symbol while in a function. This is -1 if we have not seen
84 an N_FUN (the normal case). */
86 /* The depth of block nesting. */
88 /* List of pending variable definitions. */
89 struct stab_pending_var *pending;
90 /* Number of files for which we have types. */
92 /* Lists of types per file. */
93 struct stab_types **file_types;
94 /* Predefined XCOFF types. */
95 debug_type xcoff_types[XCOFF_TYPE_COUNT];
97 struct stab_tag *tags;
100 /* A list of these structures is used to hold pending variable
101 definitions seen before the N_LBRAC of a block. */
103 struct stab_pending_var
105 /* Next pending variable definition. */
106 struct stab_pending_var *next;
112 enum debug_var_kind kind;
117 /* A list of these structures is used to hold the types for a single
122 /* Next set of slots for this file. */
123 struct stab_types *next;
124 /* Types indexed by type number. */
125 #define STAB_TYPES_SLOTS (16)
126 debug_type types[STAB_TYPES_SLOTS];
129 /* We keep a list of undefined tags that we encounter, so that we can
130 fill them in if the tag is later defined. */
134 /* Next undefined tag. */
135 struct stab_tag *next;
139 enum debug_type_kind kind;
140 /* Slot to hold real type when we discover it. If we don't, we fill
141 in an undefined tag type. */
143 /* Indirect type we have created to point at slot. */
147 static char *savestring PARAMS ((const char *, int));
148 static bfd_vma parse_number PARAMS ((const char **, boolean *));
149 static void bad_stab PARAMS ((const char *));
150 static void warn_stab PARAMS ((const char *, const char *));
151 static boolean parse_stab_string
152 PARAMS ((PTR, struct stab_handle *, int, int, bfd_vma, const char *));
153 static debug_type parse_stab_type
154 PARAMS ((PTR, struct stab_handle *, const char *, const char **,
156 static boolean parse_stab_type_number
157 PARAMS ((const char **, int *));
158 static debug_type parse_stab_range_type
159 PARAMS ((PTR, struct stab_handle *, const char *, const char **,
161 static debug_type parse_stab_sun_builtin_type PARAMS ((PTR, const char **));
162 static debug_type parse_stab_sun_floating_type
163 PARAMS ((PTR, const char **));
164 static debug_type parse_stab_enum_type PARAMS ((PTR, const char **));
165 static debug_type parse_stab_struct_type
166 PARAMS ((PTR, struct stab_handle *, const char *, const char **, boolean,
168 static boolean parse_stab_baseclasses
169 PARAMS ((PTR, struct stab_handle *, const char **, debug_baseclass **));
170 static boolean parse_stab_struct_fields
171 PARAMS ((PTR, struct stab_handle *, const char **, debug_field **,
173 static boolean parse_stab_cpp_abbrev
174 PARAMS ((PTR, struct stab_handle *, const char **, debug_field *));
175 static boolean parse_stab_one_struct_field
176 PARAMS ((PTR, struct stab_handle *, const char **, const char *,
177 debug_field *, boolean *));
178 static boolean parse_stab_members
179 PARAMS ((PTR, struct stab_handle *, const char *, const char **,
180 const int *, debug_method **));
181 static debug_type parse_stab_argtypes
182 PARAMS ((PTR, struct stab_handle *, debug_type, const char *, const char *,
183 debug_type, const char *, boolean, boolean, const char **));
184 static boolean parse_stab_tilde_field
185 PARAMS ((PTR, struct stab_handle *, const char **, const int *,
186 debug_type *, boolean *));
187 static debug_type parse_stab_array_type
188 PARAMS ((PTR, struct stab_handle *, const char **, boolean));
189 static void push_bincl PARAMS ((struct stab_handle *, const char *));
190 static const char *pop_bincl PARAMS ((struct stab_handle *));
191 static boolean stab_record_variable
192 PARAMS ((PTR, struct stab_handle *, const char *, debug_type,
193 enum debug_var_kind, bfd_vma));
194 static boolean stab_emit_pending_vars PARAMS ((PTR, struct stab_handle *));
195 static debug_type *stab_find_slot
196 PARAMS ((struct stab_handle *, const int *));
197 static debug_type stab_find_type
198 PARAMS ((PTR, struct stab_handle *, const int *));
199 static boolean stab_record_type
200 PARAMS ((PTR, struct stab_handle *, const int *, debug_type));
201 static debug_type stab_xcoff_builtin_type
202 PARAMS ((PTR, struct stab_handle *, int));
203 static debug_type stab_find_tagged_type
204 PARAMS ((PTR, struct stab_handle *, const char *, int,
205 enum debug_type_kind));
206 static debug_type *stab_demangle_argtypes
207 PARAMS ((PTR, struct stab_handle *, const char *, boolean *));
209 /* Save a string in memory. */
212 savestring (start, len)
218 ret = (char *) xmalloc (len + 1);
219 memcpy (ret, start, len);
224 /* Read a number from a string. */
227 parse_number (pp, poverflow)
234 if (poverflow != NULL)
240 ul = strtoul (*pp, (char **) pp, 0);
241 if (ul + 1 != 0 || errno == 0)
244 /* Note that even though strtoul overflowed, it should have set *pp
245 to the end of the number, which is where we want it. */
247 if (sizeof (bfd_vma) > sizeof (unsigned long))
252 bfd_vma over, lastdig;
256 /* Our own version of strtoul, for a bfd_vma. */
272 if (p[1] == 'x' || p[1] == 'X')
284 over = ((bfd_vma) (bfd_signed_vma) -1) / (bfd_vma) base;
285 lastdig = ((bfd_vma) (bfd_signed_vma) -1) % (bfd_vma) base;
294 if (isdigit ((unsigned char) d))
296 else if (isupper ((unsigned char) d))
298 else if (islower ((unsigned char) d))
306 if (v > over || (v == over && (bfd_vma) d > lastdig))
321 /* If we get here, the number is too large to represent in a
324 if (poverflow != NULL)
327 warn_stab (orig, "numeric overflow");
332 /* Give an error for a bad stab string. */
338 fprintf (stderr, "Bad stab: %s\n", p);
341 /* Warn about something in a stab string. */
348 fprintf (stderr, "Warning: %s: %s\n", err, p);
351 /* Create a handle to parse stabs symbols with. */
355 start_stab (dhandle, abfd, sections, syms, symcount)
362 struct stab_handle *ret;
364 ret = (struct stab_handle *) xmalloc (sizeof *ret);
365 memset (ret, 0, sizeof *ret);
367 ret->sections = sections;
369 ret->symcount = symcount;
371 ret->file_types = (struct stab_types **) xmalloc (sizeof *ret->file_types);
372 ret->file_types[0] = NULL;
373 ret->function_end = (bfd_vma) -1;
377 /* When we have processed all the stabs information, we need to go
378 through and fill in all the undefined tags. */
381 finish_stab (dhandle, handle)
385 struct stab_handle *info = (struct stab_handle *) handle;
388 if (info->within_function)
390 if (! stab_emit_pending_vars (dhandle, info)
391 || ! debug_end_function (dhandle, info->function_end))
393 info->within_function = false;
394 info->function_end = (bfd_vma) -1;
397 for (st = info->tags; st != NULL; st = st->next)
399 enum debug_type_kind kind;
402 if (kind == DEBUG_KIND_ILLEGAL)
403 kind = DEBUG_KIND_STRUCT;
404 st->slot = debug_make_undefined_tagged_type (dhandle, st->name, kind);
405 if (st->slot == DEBUG_TYPE_NULL)
412 /* Handle a single stabs symbol. */
415 parse_stab (dhandle, handle, type, desc, value, string)
423 struct stab_handle *info = (struct stab_handle *) handle;
425 /* gcc will emit two N_SO strings per compilation unit, one for the
426 directory name and one for the file name. We just collect N_SO
427 strings as we see them, and start the new compilation unit when
428 we see a non N_SO symbol. */
429 if (info->so_string != NULL
430 && (type != N_SO || *string == '\0' || value != info->so_value))
432 if (! debug_set_filename (dhandle, info->so_string))
434 info->main_filename = info->so_string;
436 info->gcc_compiled = 0;
437 info->n_opt_found = false;
439 /* Generally, for stabs in the symbol table, the N_LBRAC and
440 N_RBRAC symbols are relative to the N_SO symbol value. */
441 if (! info->sections)
442 info->file_start_offset = info->so_value;
444 /* We need to reset the mapping from type numbers to types. We
445 can't free the old mapping, because of the use of
446 debug_make_indirect_type. */
448 info->file_types = ((struct stab_types **)
449 xmalloc (sizeof *info->file_types));
450 info->file_types[0] = NULL;
452 info->so_string = NULL;
454 /* Now process whatever type we just got. */
464 /* Ignore extra outermost context from SunPRO cc and acc. */
465 if (info->n_opt_found && desc == 1)
468 if (! info->within_function)
470 fprintf (stderr, "N_LBRAC not within function\n");
474 /* Start an inner lexical block. */
475 if (! debug_start_block (dhandle,
477 + info->file_start_offset
478 + info->function_start_offset)))
481 /* Emit any pending variable definitions. */
482 if (! stab_emit_pending_vars (dhandle, info))
489 /* Ignore extra outermost context from SunPRO cc and acc. */
490 if (info->n_opt_found && desc == 1)
493 /* We shouldn't have any pending variable definitions here, but,
494 if we do, we probably need to emit them before closing the
496 if (! stab_emit_pending_vars (dhandle, info))
499 /* End an inner lexical block. */
500 if (! debug_end_block (dhandle,
502 + info->file_start_offset
503 + info->function_start_offset)))
507 if (info->block_depth < 0)
509 fprintf (stderr, "Too many N_RBRACs\n");
515 /* This always ends a function. */
516 if (info->within_function)
522 && info->function_end != (bfd_vma) -1
523 && info->function_end < endval)
524 endval = info->function_end;
525 if (! stab_emit_pending_vars (dhandle, info)
526 || ! debug_end_function (dhandle, endval))
528 info->within_function = false;
529 info->function_end = (bfd_vma) -1;
532 /* An empty string is emitted by gcc at the end of a compilation
537 /* Just accumulate strings until we see a non N_SO symbol. If
538 the string starts with '/', we discard the previously
539 accumulated strings. */
540 if (info->so_string == NULL)
541 info->so_string = xstrdup (string);
548 info->so_string = xstrdup (string);
550 info->so_string = concat (info->so_string, string,
551 (const char *) NULL);
555 info->so_value = value;
560 /* Start an include file. */
561 if (! debug_start_source (dhandle, string))
566 /* Start an include file which may be replaced. */
567 push_bincl (info, string);
568 if (! debug_start_source (dhandle, string))
573 /* End an N_BINCL include. */
574 if (! debug_start_source (dhandle, pop_bincl (info)))
579 /* This is a duplicate of a header file named by N_BINCL which
580 was eliminated by the linker. */
582 info->file_types = ((struct stab_types **)
583 xrealloc ((PTR) info->file_types,
585 * sizeof *info->file_types)));
586 info->file_types[info->files - 1] = NULL;
590 if (! debug_record_line (dhandle, desc,
591 value + info->function_start_offset))
596 if (! debug_start_common_block (dhandle, string))
601 if (! debug_end_common_block (dhandle, string))
608 if (info->within_function)
610 /* This always marks the end of a function; we don't
611 need to worry about info->function_end. */
613 value += info->function_start_offset;
614 if (! stab_emit_pending_vars (dhandle, info)
615 || ! debug_end_function (dhandle, value))
617 info->within_function = false;
618 info->function_end = (bfd_vma) -1;
623 /* A const static symbol in the .text section will have an N_FUN
624 entry. We need to use these to mark the end of the function,
625 in case we are looking at gcc output before it was changed to
626 always emit an empty N_FUN. We can't call debug_end_function
627 here, because it might be a local static symbol. */
628 if (info->within_function
629 && (info->function_end == (bfd_vma) -1
630 || value < info->function_end))
631 info->function_end = value;
634 /* FIXME: gdb checks the string for N_STSYM, N_LCSYM or N_ROSYM
635 symbols, and if it does not start with :S, gdb relocates the
636 value to the start of the section. gcc always seems to use
637 :S, so we don't worry about this. */
643 colon = strchr (string, ':');
645 && (colon[1] == 'f' || colon[1] == 'F'))
647 if (info->within_function)
652 if (info->function_end != (bfd_vma) -1
653 && info->function_end < endval)
654 endval = info->function_end;
655 if (! stab_emit_pending_vars (dhandle, info)
656 || ! debug_end_function (dhandle, endval))
658 info->function_end = (bfd_vma) -1;
660 /* For stabs in sections, line numbers and block addresses
661 are offsets from the start of the function. */
663 info->function_start_offset = value;
664 info->within_function = true;
667 if (! parse_stab_string (dhandle, info, type, desc, value, string))
673 if (string != NULL && strcmp (string, "gcc2_compiled.") == 0)
674 info->gcc_compiled = 2;
675 else if (string != NULL && strcmp (string, "gcc_compiled.") == 0)
676 info->gcc_compiled = 1;
678 info->n_opt_found = true;
690 /* Parse the stabs string. */
693 parse_stab_string (dhandle, info, stabtype, desc, value, string)
695 struct stab_handle *info;
709 p = strchr (string, ':');
724 /* GCC 2.x puts the line number in desc. SunOS apparently puts in
725 the number of bytes occupied by a type or object, which we
727 if (info->gcc_compiled >= 2)
732 /* FIXME: Sometimes the special C++ names start with '.'. */
734 if (string[0] == '$')
742 /* Was: name = "vptr"; */
748 /* This was an anonymous type that was never fixed up. */
751 /* SunPRO (3.0 at least) static variable encoding. */
754 warn_stab (string, "unknown C++ encoded name");
761 if (p == string || (string[0] == ' ' && p == string + 1))
764 name = savestring (string, p - string);
768 if (isdigit ((unsigned char) *p) || *p == '(' || *p == '-')
776 /* c is a special case, not followed by a type-number.
777 SYMBOL:c=iVALUE for an integer constant symbol.
778 SYMBOL:c=rVALUE for a floating constant symbol.
779 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
780 e.g. "b:c=e6,0" for "const b = blob1"
781 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
791 /* Floating point constant. */
792 if (! debug_record_float_const (dhandle, name, atof (p)))
796 /* Integer constant. */
797 /* Defining integer constants this way is kind of silly,
798 since 'e' constants allows the compiler to give not only
799 the value, but the type as well. C has at least int,
800 long, unsigned int, and long long as constant types;
801 other languages probably should have at least unsigned as
802 well as signed constants. */
803 if (! debug_record_int_const (dhandle, name, atoi (p)))
807 /* SYMBOL:c=eTYPE,INTVALUE for a constant symbol whose value
808 can be represented as integral.
809 e.g. "b:c=e6,0" for "const b = blob1"
810 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
811 dtype = parse_stab_type (dhandle, info, (const char *) NULL,
812 &p, (debug_type **) NULL);
813 if (dtype == DEBUG_TYPE_NULL)
820 if (! debug_record_typed_const (dhandle, name, dtype, atoi (p)))
831 /* The name of a caught exception. */
832 dtype = parse_stab_type (dhandle, info, (const char *) NULL,
833 &p, (debug_type **) NULL);
834 if (dtype == DEBUG_TYPE_NULL)
836 if (! debug_record_label (dhandle, name, dtype, value))
842 /* A function definition. */
843 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
844 (debug_type **) NULL);
845 if (dtype == DEBUG_TYPE_NULL)
847 if (! debug_record_function (dhandle, name, dtype, type == 'F', value))
850 /* Sun acc puts declared types of arguments here. We don't care
851 about their actual types (FIXME -- we should remember the whole
852 function prototype), but the list may define some new types
853 that we have to remember, so we must scan it now. */
857 if (parse_stab_type (dhandle, info, (const char *) NULL, &p,
858 (debug_type **) NULL)
871 /* A global symbol. The value must be extracted from the
873 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
874 (debug_type **) NULL);
875 if (dtype == DEBUG_TYPE_NULL)
877 leading = bfd_get_symbol_leading_char (info->abfd);
878 for (c = info->symcount, ps = info->syms; c > 0; --c, ++ps)
882 n = bfd_asymbol_name (*ps);
883 if (leading != '\0' && *n == leading)
885 if (*n == *name && strcmp (n, name) == 0)
889 value = bfd_asymbol_value (*ps);
890 if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_GLOBAL,
896 /* This case is faked by a conditional above, when there is no
897 code letter in the dbx data. Dbx data never actually
901 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
902 (debug_type **) NULL);
903 if (dtype == DEBUG_TYPE_NULL)
905 if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_LOCAL,
911 /* A function parameter. */
913 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
914 (debug_type **) NULL);
917 /* pF is a two-letter code that means a function parameter in
918 Fortran. The type-number specifies the type of the return
919 value. Translate it into a pointer-to-function type. */
921 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
922 (debug_type **) NULL);
923 if (dtype != DEBUG_TYPE_NULL)
927 ftype = debug_make_function_type (dhandle, dtype,
928 (debug_type *) NULL, false);
929 dtype = debug_make_pointer_type (dhandle, ftype);
932 if (dtype == DEBUG_TYPE_NULL)
934 if (! debug_record_parameter (dhandle, name, dtype, DEBUG_PARM_STACK,
938 /* FIXME: At this point gdb considers rearranging the parameter
939 address on a big endian machine if it is smaller than an int.
940 We have no way to do that, since we don't really know much
946 if (stabtype == N_FUN)
948 /* Prototype of a function referenced by this file. */
952 if (parse_stab_type (dhandle, info, (const char *) NULL, &p,
953 (debug_type **) NULL)
961 /* Parameter which is in a register. */
962 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
963 (debug_type **) NULL);
964 if (dtype == DEBUG_TYPE_NULL)
966 if (! debug_record_parameter (dhandle, name, dtype, DEBUG_PARM_REG,
972 /* Register variable (either global or local). */
973 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
974 (debug_type **) NULL);
975 if (dtype == DEBUG_TYPE_NULL)
977 if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_REGISTER,
981 /* FIXME: At this point gdb checks to combine pairs of 'p' and
982 'r' stabs into a single 'P' stab. */
987 /* Static symbol at top level of file */
988 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
989 (debug_type **) NULL);
990 if (dtype == DEBUG_TYPE_NULL)
992 if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_STATIC,
999 dtype = parse_stab_type (dhandle, info, name, &p, &slot);
1000 if (dtype == DEBUG_TYPE_NULL)
1004 /* A nameless type. Nothing to do. */
1008 dtype = debug_name_type (dhandle, name, dtype);
1009 if (dtype == DEBUG_TYPE_NULL)
1018 /* Struct, union, or enum tag. For GNU C++, this can be be followed
1019 by 't' which means we are typedef'ing it as well. */
1023 /* FIXME: gdb sets synonym to true if the current language
1032 dtype = parse_stab_type (dhandle, info, name, &p, &slot);
1033 if (dtype == DEBUG_TYPE_NULL)
1038 dtype = debug_tag_type (dhandle, name, dtype);
1039 if (dtype == DEBUG_TYPE_NULL)
1044 /* See if we have a cross reference to this tag which we can now
1047 register struct stab_tag **pst;
1049 for (pst = &info->tags; *pst != NULL; pst = &(*pst)->next)
1051 if ((*pst)->name[0] == name[0]
1052 && strcmp ((*pst)->name, name) == 0)
1054 (*pst)->slot = dtype;
1055 *pst = (*pst)->next;
1063 dtype = debug_name_type (dhandle, name, dtype);
1064 if (dtype == DEBUG_TYPE_NULL)
1074 /* Static symbol of local scope */
1075 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
1076 (debug_type **) NULL);
1077 if (dtype == DEBUG_TYPE_NULL)
1079 /* FIXME: gdb checks os9k_stabs here. */
1080 if (! stab_record_variable (dhandle, info, name, dtype,
1081 DEBUG_LOCAL_STATIC, value))
1086 /* Reference parameter. */
1087 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
1088 (debug_type **) NULL);
1089 if (dtype == DEBUG_TYPE_NULL)
1091 if (! debug_record_parameter (dhandle, name, dtype, DEBUG_PARM_REFERENCE,
1097 /* Reference parameter which is in a register. */
1098 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
1099 (debug_type **) NULL);
1100 if (dtype == DEBUG_TYPE_NULL)
1102 if (! debug_record_parameter (dhandle, name, dtype, DEBUG_PARM_REF_REG,
1108 /* This is used by Sun FORTRAN for "function result value".
1109 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
1110 that Pascal uses it too, but when I tried it Pascal used
1111 "x:3" (local symbol) instead. */
1112 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
1113 (debug_type **) NULL);
1114 if (dtype == DEBUG_TYPE_NULL)
1116 if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_LOCAL,
1126 /* FIXME: gdb converts structure values to structure pointers in a
1127 couple of cases, depending upon the target. */
1132 /* Parse a stabs type. The typename argument is non-NULL if this is a
1133 typedef or a tag definition. The pp argument points to the stab
1134 string, and is updated. The slotp argument points to a place to
1135 store the slot used if the type is being defined. */
1138 parse_stab_type (dhandle, info, typename, pp, slotp)
1140 struct stab_handle *info;
1141 const char *typename;
1160 /* Read type number if present. The type number may be omitted.
1161 for instance in a two-dimensional array declared with type
1162 "ar1;1;10;ar1;1;10;4". */
1163 if (! isdigit ((unsigned char) **pp) && **pp != '(' && **pp != '-')
1165 /* 'typenums=' not present, type is anonymous. Read and return
1166 the definition, but don't put it in the type vector. */
1167 typenums[0] = typenums[1] = -1;
1171 if (! parse_stab_type_number (pp, typenums))
1172 return DEBUG_TYPE_NULL;
1176 /* Type is not being defined here. Either it already
1177 exists, or this is a forward reference to it. */
1178 return stab_find_type (dhandle, info, typenums);
1181 /* Only set the slot if the type is being defined. This means
1182 that the mapping from type numbers to types will only record
1183 the name of the typedef which defines a type. If we don't do
1184 this, then something like
1187 will record that i is of type foo. Unfortunately, stabs
1188 information is ambiguous about variable types. For this code,
1192 the stabs information records both i and j as having the same
1193 type. This could be fixed by patching the compiler. */
1194 if (slotp != NULL && typenums[0] >= 0 && typenums[1] >= 0)
1195 *slotp = stab_find_slot (info, typenums);
1197 /* Type is being defined here. */
1203 const char *p = *pp + 1;
1206 if (isdigit ((unsigned char) *p) || *p == '(' || *p == '-')
1212 /* Type attributes. */
1215 for (; *p != ';'; ++p)
1220 return DEBUG_TYPE_NULL;
1228 size = atoi (attr + 1);
1238 /* Ignore unrecognized type attributes, so future
1239 compilers can invent new ones. */
1252 enum debug_type_kind code;
1253 const char *q1, *q2, *p;
1255 /* A cross reference to another type. */
1260 code = DEBUG_KIND_STRUCT;
1263 code = DEBUG_KIND_UNION;
1266 code = DEBUG_KIND_ENUM;
1269 /* Complain and keep going, so compilers can invent new
1270 cross-reference types. */
1271 warn_stab (orig, "unrecognized cross reference type");
1272 code = DEBUG_KIND_STRUCT;
1277 q1 = strchr (*pp, '<');
1278 p = strchr (*pp, ':');
1282 return DEBUG_TYPE_NULL;
1284 while (q1 != NULL && p > q1 && p[1] == ':')
1286 q2 = strchr (q1, '>');
1287 if (q2 == NULL || q2 < p)
1290 p = strchr (p, ':');
1294 return DEBUG_TYPE_NULL;
1298 dtype = stab_find_tagged_type (dhandle, info, *pp, p - *pp, code);
1320 /* This type is defined as another type. */
1325 /* Peek ahead at the number to detect void. */
1326 if (! parse_stab_type_number (pp, xtypenums))
1327 return DEBUG_TYPE_NULL;
1329 if (typenums[0] == xtypenums[0] && typenums[1] == xtypenums[1])
1331 /* This type is being defined as itself, which means that
1333 dtype = debug_make_void_type (dhandle);
1339 /* Go back to the number and have parse_stab_type get it.
1340 This means that we can deal with something like
1341 t(1,2)=(3,4)=... which the Lucid compiler uses. */
1342 dtype = parse_stab_type (dhandle, info, (const char *) NULL,
1343 pp, (debug_type **) NULL);
1344 if (dtype == DEBUG_TYPE_NULL)
1345 return DEBUG_TYPE_NULL;
1348 if (typenums[0] != -1)
1350 if (! stab_record_type (dhandle, info, typenums, dtype))
1351 return DEBUG_TYPE_NULL;
1358 dtype = debug_make_pointer_type (dhandle,
1359 parse_stab_type (dhandle, info,
1360 (const char *) NULL,
1362 (debug_type **) NULL));
1366 /* Reference to another type. */
1367 dtype = (debug_make_reference_type
1369 parse_stab_type (dhandle, info, (const char *) NULL, pp,
1370 (debug_type **) NULL)));
1374 /* Function returning another type. */
1375 /* FIXME: gdb checks os9k_stabs here. */
1376 dtype = (debug_make_function_type
1378 parse_stab_type (dhandle, info, (const char *) NULL, pp,
1379 (debug_type **) NULL),
1380 (debug_type *) NULL, false));
1384 /* Const qualifier on some type (Sun). */
1385 /* FIXME: gdb accepts 'c' here if os9k_stabs. */
1386 dtype = debug_make_const_type (dhandle,
1387 parse_stab_type (dhandle, info,
1388 (const char *) NULL,
1390 (debug_type **) NULL));
1394 /* Volatile qual on some type (Sun). */
1395 /* FIXME: gdb accepts 'i' here if os9k_stabs. */
1396 dtype = (debug_make_volatile_type
1398 parse_stab_type (dhandle, info, (const char *) NULL, pp,
1399 (debug_type **) NULL)));
1403 /* Offset (class & variable) type. This is used for a pointer
1404 relative to an object. */
1411 domain = parse_stab_type (dhandle, info, (const char *) NULL, pp,
1412 (debug_type **) NULL);
1413 if (domain == DEBUG_TYPE_NULL)
1414 return DEBUG_TYPE_NULL;
1419 return DEBUG_TYPE_NULL;
1423 memtype = parse_stab_type (dhandle, info, (const char *) NULL, pp,
1424 (debug_type **) NULL);
1425 if (memtype == DEBUG_TYPE_NULL)
1426 return DEBUG_TYPE_NULL;
1428 dtype = debug_make_offset_type (dhandle, domain, memtype);
1433 /* Method (class & fn) type. */
1436 debug_type return_type;
1439 return_type = parse_stab_type (dhandle, info, (const char *) NULL,
1440 pp, (debug_type **) NULL);
1441 if (return_type == DEBUG_TYPE_NULL)
1442 return DEBUG_TYPE_NULL;
1446 return DEBUG_TYPE_NULL;
1449 dtype = debug_make_method_type (dhandle, return_type,
1451 (debug_type *) NULL, false);
1456 debug_type return_type;
1462 domain = parse_stab_type (dhandle, info, (const char *) NULL,
1463 pp, (debug_type **) NULL);
1464 if (domain == DEBUG_TYPE_NULL)
1465 return DEBUG_TYPE_NULL;
1470 return DEBUG_TYPE_NULL;
1474 return_type = parse_stab_type (dhandle, info, (const char *) NULL,
1475 pp, (debug_type **) NULL);
1476 if (return_type == DEBUG_TYPE_NULL)
1477 return DEBUG_TYPE_NULL;
1480 args = (debug_type *) xmalloc (alloc * sizeof *args);
1487 return DEBUG_TYPE_NULL;
1494 args = ((debug_type *)
1495 xrealloc ((PTR) args, alloc * sizeof *args));
1498 args[n] = parse_stab_type (dhandle, info, (const char *) NULL,
1499 pp, (debug_type **) NULL);
1500 if (args[n] == DEBUG_TYPE_NULL)
1501 return DEBUG_TYPE_NULL;
1506 /* If the last type is not void, then this function takes a
1507 variable number of arguments. Otherwise, we must strip
1510 || debug_get_type_kind (dhandle, args[n - 1]) != DEBUG_KIND_VOID)
1518 args[n] = DEBUG_TYPE_NULL;
1520 dtype = debug_make_method_type (dhandle, return_type, domain, args,
1527 dtype = parse_stab_range_type (dhandle, info, typename, pp, typenums);
1531 /* FIXME: gdb checks os9k_stabs here. */
1532 /* Sun ACC builtin int type. */
1533 dtype = parse_stab_sun_builtin_type (dhandle, pp);
1537 /* Sun ACC builtin float type. */
1538 dtype = parse_stab_sun_floating_type (dhandle, pp);
1542 /* Enumeration type. */
1543 dtype = parse_stab_enum_type (dhandle, pp);
1548 /* Struct or union type. */
1549 dtype = parse_stab_struct_type (dhandle, info, typename, pp,
1550 descriptor == 's', typenums);
1558 return DEBUG_TYPE_NULL;
1562 dtype = parse_stab_array_type (dhandle, info, pp, stringp);
1566 dtype = debug_make_set_type (dhandle,
1567 parse_stab_type (dhandle, info,
1568 (const char *) NULL,
1570 (debug_type **) NULL),
1576 return DEBUG_TYPE_NULL;
1579 if (dtype == DEBUG_TYPE_NULL)
1580 return DEBUG_TYPE_NULL;
1582 if (typenums[0] != -1)
1584 if (! stab_record_type (dhandle, info, typenums, dtype))
1585 return DEBUG_TYPE_NULL;
1590 if (! debug_record_type_size (dhandle, dtype, (unsigned int) size))
1597 /* Read a number by which a type is referred to in dbx data, or
1598 perhaps read a pair (FILENUM, TYPENUM) in parentheses. Just a
1599 single number N is equivalent to (0,N). Return the two numbers by
1600 storing them in the vector TYPENUMS. */
1603 parse_stab_type_number (pp, typenums)
1614 typenums[1] = (int) parse_number (pp, (boolean *) NULL);
1619 typenums[0] = (int) parse_number (pp, (boolean *) NULL);
1626 typenums[1] = (int) parse_number (pp, (boolean *) NULL);
1638 /* Parse a range type. */
1641 parse_stab_range_type (dhandle, info, typename, pp, typenums)
1643 struct stab_handle *info;
1644 const char *typename;
1646 const int *typenums;
1650 boolean self_subrange;
1651 debug_type index_type;
1652 const char *s2, *s3;
1653 bfd_signed_vma n2, n3;
1658 index_type = DEBUG_TYPE_NULL;
1660 /* First comes a type we are a subrange of.
1661 In C it is usually 0, 1 or the type being defined. */
1662 if (! parse_stab_type_number (pp, rangenums))
1663 return DEBUG_TYPE_NULL;
1665 self_subrange = (rangenums[0] == typenums[0]
1666 && rangenums[1] == typenums[1]);
1671 index_type = parse_stab_type (dhandle, info, (const char *) NULL,
1672 pp, (debug_type **) NULL);
1673 if (index_type == DEBUG_TYPE_NULL)
1674 return DEBUG_TYPE_NULL;
1680 /* The remaining two operands are usually lower and upper bounds of
1681 the range. But in some special cases they mean something else. */
1683 n2 = parse_number (pp, &ov2);
1687 return DEBUG_TYPE_NULL;
1692 n3 = parse_number (pp, &ov3);
1696 return DEBUG_TYPE_NULL;
1702 /* gcc will emit range stabs for long long types. Handle this
1703 as a special case. FIXME: This needs to be more general. */
1704 #define LLLOW "01000000000000000000000;"
1705 #define LLHIGH "0777777777777777777777;"
1706 #define ULLHIGH "01777777777777777777777;"
1707 if (index_type == DEBUG_TYPE_NULL)
1709 if (strncmp (s2, LLLOW, sizeof LLLOW - 1) == 0
1710 && strncmp (s3, LLHIGH, sizeof LLHIGH - 1) == 0)
1711 return debug_make_int_type (dhandle, 8, false);
1714 && strncmp (s3, ULLHIGH, sizeof ULLHIGH - 1) == 0)
1715 return debug_make_int_type (dhandle, 8, true);
1718 warn_stab (orig, "numeric overflow");
1721 if (index_type == DEBUG_TYPE_NULL)
1723 /* A type defined as a subrange of itself, with both bounds 0,
1725 if (self_subrange && n2 == 0 && n3 == 0)
1726 return debug_make_void_type (dhandle);
1728 /* A type defined as a subrange of itself, with n2 positive and
1729 n3 zero, is a complex type, and n2 is the number of bytes. */
1730 if (self_subrange && n3 == 0 && n2 > 0)
1731 return debug_make_complex_type (dhandle, n2);
1733 /* If n3 is zero and n2 is positive, this is a floating point
1734 type, and n2 is the number of bytes. */
1735 if (n3 == 0 && n2 > 0)
1736 return debug_make_float_type (dhandle, n2);
1738 /* If the upper bound is -1, this is an unsigned int. */
1739 if (n2 == 0 && n3 == -1)
1741 /* When gcc is used with -gstabs, but not -gstabs+, it will emit
1742 long long int:t6=r1;0;-1;
1743 long long unsigned int:t7=r1;0;-1;
1744 We hack here to handle this reasonably. */
1745 if (typename != NULL)
1747 if (strcmp (typename, "long long int") == 0)
1748 return debug_make_int_type (dhandle, 8, false);
1749 else if (strcmp (typename, "long long unsigned int") == 0)
1750 return debug_make_int_type (dhandle, 8, true);
1752 /* FIXME: The size here really depends upon the target. */
1753 return debug_make_int_type (dhandle, 4, true);
1756 /* A range of 0 to 127 is char. */
1757 if (self_subrange && n2 == 0 && n3 == 127)
1758 return debug_make_int_type (dhandle, 1, false);
1760 /* FIXME: gdb checks for the language CHILL here. */
1765 return debug_make_int_type (dhandle, - n3, true);
1766 else if (n3 == 0xff)
1767 return debug_make_int_type (dhandle, 1, true);
1768 else if (n3 == 0xffff)
1769 return debug_make_int_type (dhandle, 2, true);
1770 /* -1 is used for the upper bound of (4 byte) "unsigned int"
1771 and "unsigned long", and we already checked for that, so
1772 don't need to test for it here. */
1776 && (self_subrange || n2 == -8))
1777 return debug_make_int_type (dhandle, - n2, true);
1778 else if (n2 == - n3 - 1)
1781 return debug_make_int_type (dhandle, 1, false);
1782 else if (n3 == 0x7fff)
1783 return debug_make_int_type (dhandle, 2, false);
1784 else if (n3 == 0x7fffffff)
1785 return debug_make_int_type (dhandle, 4, false);
1789 /* At this point I don't have the faintest idea how to deal with a
1790 self_subrange type; I'm going to assume that this is used as an
1791 idiom, and that all of them are special cases. So . . . */
1795 return DEBUG_TYPE_NULL;
1798 index_type = stab_find_type (dhandle, info, rangenums);
1799 if (index_type == DEBUG_TYPE_NULL)
1801 /* Does this actually ever happen? Is that why we are worrying
1802 about dealing with it rather than just calling error_type? */
1803 warn_stab (orig, "missing index type");
1804 index_type = debug_make_int_type (dhandle, 4, false);
1807 return debug_make_range_type (dhandle, index_type, n2, n3);
1810 /* Sun's ACC uses a somewhat saner method for specifying the builtin
1811 typedefs in every file (for int, long, etc):
1813 type = b <signed> <width>; <offset>; <nbits>
1814 signed = u or s. Possible c in addition to u or s (for char?).
1815 offset = offset from high order bit to start bit of type.
1816 width is # bytes in object of this type, nbits is # bits in type.
1818 The width/offset stuff appears to be for small objects stored in
1819 larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
1823 parse_stab_sun_builtin_type (dhandle, pp)
1843 return DEBUG_TYPE_NULL;
1847 /* For some odd reason, all forms of char put a c here. This is strange
1848 because no other type has this honor. We can safely ignore this because
1849 we actually determine 'char'acterness by the number of bits specified in
1854 /* The first number appears to be the number of bytes occupied
1855 by this type, except that unsigned short is 4 instead of 2.
1856 Since this information is redundant with the third number,
1857 we will ignore it. */
1858 (void) parse_number (pp, (boolean *) NULL);
1862 return DEBUG_TYPE_NULL;
1866 /* The second number is always 0, so ignore it too. */
1867 (void) parse_number (pp, (boolean *) NULL);
1871 return DEBUG_TYPE_NULL;
1875 /* The third number is the number of bits for this type. */
1876 bits = parse_number (pp, (boolean *) NULL);
1878 /* The type *should* end with a semicolon. If it are embedded
1879 in a larger type the semicolon may be the only way to know where
1880 the type ends. If this type is at the end of the stabstring we
1881 can deal with the omitted semicolon (but we don't have to like
1882 it). Don't bother to complain(), Sun's compiler omits the semicolon
1888 return debug_make_void_type (dhandle);
1890 return debug_make_int_type (dhandle, bits / 8, unsignedp);
1893 /* Parse a builtin floating type generated by the Sun compiler. */
1896 parse_stab_sun_floating_type (dhandle, pp)
1906 /* The first number has more details about the type, for example
1908 details = parse_number (pp, (boolean *) NULL);
1912 return DEBUG_TYPE_NULL;
1915 /* The second number is the number of bytes occupied by this type */
1916 bytes = parse_number (pp, (boolean *) NULL);
1920 return DEBUG_TYPE_NULL;
1923 if (details == NF_COMPLEX
1924 || details == NF_COMPLEX16
1925 || details == NF_COMPLEX32)
1926 return debug_make_complex_type (dhandle, bytes);
1928 return debug_make_float_type (dhandle, bytes);
1931 /* Handle an enum type. */
1934 parse_stab_enum_type (dhandle, pp)
1940 bfd_signed_vma *values;
1946 /* FIXME: gdb checks os9k_stabs here. */
1948 /* The aix4 compiler emits an extra field before the enum members;
1949 my guess is it's a type of some sort. Just ignore it. */
1957 /* Read the value-names and their values.
1958 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
1959 A semicolon or comma instead of a NAME means the end. */
1961 names = (const char **) xmalloc (alloc * sizeof *names);
1962 values = (bfd_signed_vma *) xmalloc (alloc * sizeof *values);
1964 while (**pp != '\0' && **pp != ';' && **pp != ',')
1974 name = savestring (*pp, p - *pp);
1977 val = (bfd_signed_vma) parse_number (pp, (boolean *) NULL);
1981 return DEBUG_TYPE_NULL;
1988 names = ((const char **)
1989 xrealloc ((PTR) names, alloc * sizeof *names));
1990 values = ((bfd_signed_vma *)
1991 xrealloc ((PTR) values, alloc * sizeof *values));
2005 return debug_make_enum_type (dhandle, names, values);
2008 /* Read the description of a structure (or union type) and return an object
2009 describing the type.
2011 PP points to a character pointer that points to the next unconsumed token
2012 in the the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;",
2013 *PP will point to "4a:1,0,32;;". */
2016 parse_stab_struct_type (dhandle, info, tagname, pp, structp, typenums)
2018 struct stab_handle *info;
2019 const char *tagname;
2022 const int *typenums;
2026 debug_baseclass *baseclasses;
2027 debug_field *fields;
2029 debug_method *methods;
2030 debug_type vptrbase;
2036 size = parse_number (pp, (boolean *) NULL);
2038 /* Get the other information. */
2039 if (! parse_stab_baseclasses (dhandle, info, pp, &baseclasses)
2040 || ! parse_stab_struct_fields (dhandle, info, pp, &fields, &statics)
2041 || ! parse_stab_members (dhandle, info, tagname, pp, typenums, &methods)
2042 || ! parse_stab_tilde_field (dhandle, info, pp, typenums, &vptrbase,
2044 return DEBUG_TYPE_NULL;
2047 && baseclasses == NULL
2049 && vptrbase == DEBUG_TYPE_NULL
2051 return debug_make_struct_type (dhandle, structp, size, fields);
2053 return debug_make_object_type (dhandle, structp, size, fields, baseclasses,
2054 methods, vptrbase, ownvptr);
2057 /* The stabs for C++ derived classes contain baseclass information which
2058 is marked by a '!' character after the total size. This function is
2059 called when we encounter the baseclass marker, and slurps up all the
2060 baseclass information.
2062 Immediately following the '!' marker is the number of base classes that
2063 the class is derived from, followed by information for each base class.
2064 For each base class, there are two visibility specifiers, a bit offset
2065 to the base class information within the derived class, a reference to
2066 the type for the base class, and a terminating semicolon.
2068 A typical example, with two base classes, would be "!2,020,19;0264,21;".
2070 Baseclass information marker __________________|| | | | | | |
2071 Number of baseclasses __________________________| | | | | | |
2072 Visibility specifiers (2) ________________________| | | | | |
2073 Offset in bits from start of class _________________| | | | |
2074 Type number for base class ___________________________| | | |
2075 Visibility specifiers (2) _______________________________| | |
2076 Offset in bits from start of class ________________________| |
2077 Type number of base class ____________________________________|
2079 Return true for success, false for failure. */
2082 parse_stab_baseclasses (dhandle, info, pp, retp)
2084 struct stab_handle *info;
2086 debug_baseclass **retp;
2090 debug_baseclass *classes;
2098 /* No base classes. */
2103 c = (unsigned int) parse_number (pp, (boolean *) NULL);
2112 classes = (debug_baseclass *) xmalloc ((c + 1) * sizeof (**retp));
2114 for (i = 0; i < c; i++)
2117 enum debug_visibility visibility;
2130 warn_stab (orig, "unknown virtual character for baseclass");
2139 visibility = DEBUG_VISIBILITY_PRIVATE;
2142 visibility = DEBUG_VISIBILITY_PROTECTED;
2145 visibility = DEBUG_VISIBILITY_PUBLIC;
2148 warn_stab (orig, "unknown visibility character for baseclass");
2149 visibility = DEBUG_VISIBILITY_PUBLIC;
2154 /* The remaining value is the bit offset of the portion of the
2155 object corresponding to this baseclass. Always zero in the
2156 absence of multiple inheritance. */
2157 bitpos = parse_number (pp, (boolean *) NULL);
2165 type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
2166 (debug_type **) NULL);
2167 if (type == DEBUG_TYPE_NULL)
2170 classes[i] = debug_make_baseclass (dhandle, type, bitpos, virtual,
2172 if (classes[i] == DEBUG_BASECLASS_NULL)
2180 classes[i] = DEBUG_BASECLASS_NULL;
2187 /* Read struct or class data fields. They have the form:
2189 NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
2191 At the end, we see a semicolon instead of a field.
2193 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
2196 The optional VISIBILITY is one of:
2198 '/0' (VISIBILITY_PRIVATE)
2199 '/1' (VISIBILITY_PROTECTED)
2200 '/2' (VISIBILITY_PUBLIC)
2201 '/9' (VISIBILITY_IGNORE)
2203 or nothing, for C style fields with public visibility.
2205 Returns 1 for success, 0 for failure. */
2208 parse_stab_struct_fields (dhandle, info, pp, retp, staticsp)
2210 struct stab_handle *info;
2217 debug_field *fields;
2228 fields = (debug_field *) xmalloc (alloc * sizeof *fields);
2231 /* FIXME: gdb checks os9k_stabs here. */
2235 /* Add 1 to c to leave room for NULL pointer at end. */
2239 fields = ((debug_field *)
2240 xrealloc ((PTR) fields, alloc * sizeof *fields));
2243 /* If it starts with CPLUS_MARKER it is a special abbreviation,
2244 unless the CPLUS_MARKER is followed by an underscore, in
2245 which case it is just the name of an anonymous type, which we
2246 should handle like any other type name. We accept either '$'
2247 or '.', because a field name can never contain one of these
2248 characters except as a CPLUS_MARKER. */
2250 if ((*p == '$' || *p == '.') && p[1] != '_')
2253 if (! parse_stab_cpp_abbrev (dhandle, info, pp, fields + c))
2259 /* Look for the ':' that separates the field name from the field
2260 values. Data members are delimited by a single ':', while member
2261 functions are delimited by a pair of ':'s. When we hit the member
2262 functions (if any), terminate scan loop and return. */
2264 p = strchr (p, ':');
2274 if (! parse_stab_one_struct_field (dhandle, info, pp, p, fields + c,
2281 fields[c] = DEBUG_FIELD_NULL;
2288 /* Special GNU C++ name. */
2291 parse_stab_cpp_abbrev (dhandle, info, pp, retp)
2293 struct stab_handle *info;
2301 const char *typename;
2305 *retp = DEBUG_FIELD_NULL;
2319 /* At this point, *pp points to something like "22:23=*22...", where
2320 the type number before the ':' is the "context" and everything
2321 after is a regular type definition. Lookup the type, find it's
2322 name, and construct the field name. */
2324 context = parse_stab_type (dhandle, info, (const char *) NULL, pp,
2325 (debug_type **) NULL);
2326 if (context == DEBUG_TYPE_NULL)
2332 /* $vf -- a virtual function table pointer. */
2336 /* $vb -- a virtual bsomethingorother */
2337 typename = debug_get_type_name (dhandle, context);
2338 if (typename == NULL)
2340 warn_stab (orig, "unnamed $vb type");
2343 name = concat ("_vb$", typename, (const char *) NULL);
2346 warn_stab (orig, "unrecognized C++ abbreviation");
2347 name = "INVALID_CPLUSPLUS_ABBREV";
2358 type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
2359 (debug_type **) NULL);
2367 bitpos = parse_number (pp, (boolean *) NULL);
2375 *retp = debug_make_field (dhandle, name, type, bitpos, 0,
2376 DEBUG_VISIBILITY_PRIVATE);
2377 if (*retp == DEBUG_FIELD_NULL)
2383 /* Parse a single field in a struct or union. */
2386 parse_stab_one_struct_field (dhandle, info, pp, p, retp, staticsp)
2388 struct stab_handle *info;
2396 enum debug_visibility visibility;
2403 /* FIXME: gdb checks ARM_DEMANGLING here. */
2405 name = savestring (*pp, p - *pp);
2410 visibility = DEBUG_VISIBILITY_PUBLIC;
2417 visibility = DEBUG_VISIBILITY_PRIVATE;
2420 visibility = DEBUG_VISIBILITY_PROTECTED;
2423 visibility = DEBUG_VISIBILITY_PUBLIC;
2426 warn_stab (orig, "unknown visibility character for field");
2427 visibility = DEBUG_VISIBILITY_PUBLIC;
2433 type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
2434 (debug_type **) NULL);
2435 if (type == DEBUG_TYPE_NULL)
2442 /* This is a static class member. */
2444 p = strchr (*pp, ';');
2451 varname = savestring (*pp, p - *pp);
2455 *retp = debug_make_static_member (dhandle, name, type, varname,
2469 bitpos = parse_number (pp, (boolean *) NULL);
2477 bitsize = parse_number (pp, (boolean *) NULL);
2485 if (bitpos == 0 && bitsize == 0)
2487 /* This can happen in two cases: (1) at least for gcc 2.4.5 or
2488 so, it is a field which has been optimized out. The correct
2489 stab for this case is to use VISIBILITY_IGNORE, but that is a
2490 recent invention. (2) It is a 0-size array. For example
2491 union { int num; char str[0]; } foo. Printing "<no value>"
2492 for str in "p foo" is OK, since foo.str (and thus foo.str[3])
2493 will continue to work, and a 0-size array as a whole doesn't
2494 have any contents to print.
2496 I suspect this probably could also happen with gcc -gstabs
2497 (not -gstabs+) for static fields, and perhaps other C++
2498 extensions. Hopefully few people use -gstabs with gdb, since
2499 it is intended for dbx compatibility. */
2500 visibility = DEBUG_VISIBILITY_IGNORE;
2503 /* FIXME: gdb does some stuff here to mark fields as unpacked. */
2505 *retp = debug_make_field (dhandle, name, type, bitpos, bitsize, visibility);
2510 /* Read member function stabs info for C++ classes. The form of each member
2513 NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;
2515 An example with two member functions is:
2517 afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;
2519 For the case of overloaded operators, the format is op$::*.funcs, where
2520 $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
2521 name (such as `+=') and `.' marks the end of the operator name. */
2524 parse_stab_members (dhandle, info, tagname, pp, typenums, retp)
2526 struct stab_handle *info;
2527 const char *tagname;
2529 const int *typenums;
2530 debug_method **retp;
2533 debug_method *methods;
2549 debug_method_variant *variants;
2551 unsigned int allocvars;
2552 debug_type look_ahead_type;
2554 p = strchr (*pp, ':');
2555 if (p == NULL || p[1] != ':')
2558 /* FIXME: Some systems use something other than '$' here. */
2559 if ((*pp)[0] != 'o' || (*pp)[1] != 'p' || (*pp)[2] != '$')
2561 name = savestring (*pp, p - *pp);
2566 /* This is a completely wierd case. In order to stuff in the
2567 names that might contain colons (the usual name delimiter),
2568 Mike Tiemann defined a different name format which is
2569 signalled if the identifier is "op$". In that case, the
2570 format is "op$::XXXX." where XXXX is the name. This is
2571 used for names like "+" or "=". YUUUUUUUK! FIXME! */
2573 for (p = *pp; *p != '.' && *p != '\0'; p++)
2580 name = savestring (*pp, p - *pp);
2585 variants = ((debug_method_variant *)
2586 xmalloc (allocvars * sizeof *variants));
2589 look_ahead_type = DEBUG_TYPE_NULL;
2596 enum debug_visibility visibility;
2597 boolean constp, volatilep, staticp;
2600 const char *physname;
2603 if (look_ahead_type != DEBUG_TYPE_NULL)
2605 /* g++ version 1 kludge */
2606 type = look_ahead_type;
2607 look_ahead_type = DEBUG_TYPE_NULL;
2611 type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
2612 (debug_type **) NULL);
2613 if (type == DEBUG_TYPE_NULL)
2623 p = strchr (*pp, ';');
2631 if (debug_get_type_kind (dhandle, type) == DEBUG_KIND_METHOD
2632 && debug_get_parameter_types (dhandle, type, &varargs) == NULL)
2635 argtypes = savestring (*pp, p - *pp);
2641 visibility = DEBUG_VISIBILITY_PRIVATE;
2644 visibility = DEBUG_VISIBILITY_PROTECTED;
2647 visibility = DEBUG_VISIBILITY_PUBLIC;
2657 /* Normal function. */
2661 /* const member function. */
2666 /* volatile member function. */
2671 /* const volatile member function. */
2679 /* File compiled with g++ version 1; no information. */
2682 warn_stab (orig, "const/volatile indicator missing");
2690 /* virtual member function, followed by index. The sign
2691 bit is supposedly set to distinguish
2692 pointers-to-methods from virtual function indicies. */
2694 voffset = parse_number (pp, (boolean *) NULL);
2701 voffset &= 0x7fffffff;
2703 if (**pp == ';' || *pp == '\0')
2705 /* Must be g++ version 1. */
2706 context = DEBUG_TYPE_NULL;
2710 /* Figure out from whence this virtual function
2711 came. It may belong to virtual function table of
2712 one of its baseclasses. */
2713 look_ahead_type = parse_stab_type (dhandle, info,
2714 (const char *) NULL,
2716 (debug_type **) NULL);
2719 /* g++ version 1 overloaded methods. */
2720 context = DEBUG_TYPE_NULL;
2724 context = look_ahead_type;
2725 look_ahead_type = DEBUG_TYPE_NULL;
2737 /* static member function. */
2741 context = DEBUG_TYPE_NULL;
2742 if (strncmp (argtypes, name, strlen (name)) != 0)
2747 warn_stab (orig, "member function type missing");
2749 context = DEBUG_TYPE_NULL;
2755 context = DEBUG_TYPE_NULL;
2759 /* If the type is not a stub, then the argtypes string is
2760 the physical name of the function. Otherwise the
2761 argtypes string is the mangled form of the argument
2762 types, and the full type and the physical name must be
2763 extracted from them. */
2765 physname = argtypes;
2768 debug_type class_type, return_type;
2770 class_type = stab_find_type (dhandle, info, typenums);
2771 if (class_type == DEBUG_TYPE_NULL)
2773 return_type = debug_get_return_type (dhandle, type);
2774 if (return_type == DEBUG_TYPE_NULL)
2779 type = parse_stab_argtypes (dhandle, info, class_type, name,
2780 tagname, return_type, argtypes,
2781 constp, volatilep, &physname);
2782 if (type == DEBUG_TYPE_NULL)
2786 if (cvars + 1 >= allocvars)
2789 variants = ((debug_method_variant *)
2790 xrealloc ((PTR) variants,
2791 allocvars * sizeof *variants));
2795 variants[cvars] = debug_make_method_variant (dhandle, physname,
2800 variants[cvars] = debug_make_static_method_variant (dhandle,
2806 if (variants[cvars] == DEBUG_METHOD_VARIANT_NULL)
2811 while (**pp != ';' && **pp != '\0');
2813 variants[cvars] = DEBUG_METHOD_VARIANT_NULL;
2821 methods = ((debug_method *)
2822 xrealloc ((PTR) methods, alloc * sizeof *methods));
2825 methods[c] = debug_make_method (dhandle, name, variants);
2830 if (methods != NULL)
2831 methods[c] = DEBUG_METHOD_NULL;
2838 /* Parse a string representing argument types for a method. Stabs
2839 tries to save space by packing argument types into a mangled
2840 string. This string should give us enough information to extract
2841 both argument types and the physical name of the function, given
2845 parse_stab_argtypes (dhandle, info, class_type, fieldname, tagname,
2846 return_type, argtypes, constp, volatilep, pphysname)
2848 struct stab_handle *info;
2849 debug_type class_type;
2850 const char *fieldname;
2851 const char *tagname;
2852 debug_type return_type;
2853 const char *argtypes;
2856 const char **pphysname;
2858 boolean is_full_physname_constructor;
2859 boolean is_constructor;
2860 boolean is_destructor;
2864 /* Constructors are sometimes handled specially. */
2865 is_full_physname_constructor = ((argtypes[0] == '_'
2866 && argtypes[1] == '_'
2867 && (isdigit ((unsigned char) argtypes[2])
2868 || argtypes[2] == 'Q'
2869 || argtypes[2] == 't'))
2870 || strncmp (argtypes, "__ct", 4) == 0);
2872 is_constructor = (is_full_physname_constructor
2874 && strcmp (fieldname, tagname) == 0));
2875 is_destructor = ((argtypes[0] == '_'
2876 && (argtypes[1] == '$' || argtypes[1] == '.')
2877 && argtypes[2] == '_')
2878 || strncmp (argtypes, "__dt", 4) == 0);
2880 if (is_destructor || is_full_physname_constructor)
2881 *pphysname = argtypes;
2885 const char *const_prefix;
2886 const char *volatile_prefix;
2888 unsigned int mangled_name_len;
2891 len = tagname == NULL ? 0 : strlen (tagname);
2892 const_prefix = constp ? "C" : "";
2893 volatile_prefix = volatilep ? "V" : "";
2896 sprintf (buf, "__%s%s", const_prefix, volatile_prefix);
2897 else if (tagname != NULL && strchr (tagname, '<') != NULL)
2899 /* Template methods are fully mangled. */
2900 sprintf (buf, "__%s%s", const_prefix, volatile_prefix);
2905 sprintf (buf, "__%s%s%d", const_prefix, volatile_prefix, len);
2907 mangled_name_len = ((is_constructor ? 0 : strlen (fieldname))
2913 if (fieldname[0] == 'o'
2914 && fieldname[1] == 'p'
2915 && (fieldname[2] == '$' || fieldname[2] == '.'))
2919 opname = cplus_mangle_opname (fieldname + 3, 0);
2922 fprintf (stderr, "No mangling for \"%s\"\n", fieldname);
2923 return DEBUG_TYPE_NULL;
2925 mangled_name_len += strlen (opname);
2926 physname = (char *) xmalloc (mangled_name_len);
2927 strncpy (physname, fieldname, 3);
2928 strcpy (physname + 3, opname);
2932 physname = (char *) xmalloc (mangled_name_len);
2936 strcpy (physname, fieldname);
2939 strcat (physname, buf);
2940 if (tagname != NULL)
2941 strcat (physname, tagname);
2942 strcat (physname, argtypes);
2944 *pphysname = physname;
2947 if (*argtypes == '\0')
2949 args = (debug_type *) xmalloc (sizeof *args);
2951 return debug_make_method_type (dhandle, return_type, class_type, args,
2955 args = stab_demangle_argtypes (dhandle, info, *pphysname, &varargs);
2957 return DEBUG_TYPE_NULL;
2959 return debug_make_method_type (dhandle, return_type, class_type, args,
2963 /* The tail end of stabs for C++ classes that contain a virtual function
2964 pointer contains a tilde, a %, and a type number.
2965 The type number refers to the base class (possibly this class itself) which
2966 contains the vtable pointer for the current class.
2968 This function is called when we have parsed all the method declarations,
2969 so we can look for the vptr base class info. */
2972 parse_stab_tilde_field (dhandle, info, pp, typenums, retvptrbase, retownvptr)
2974 struct stab_handle *info;
2976 const int *typenums;
2977 debug_type *retvptrbase;
2978 boolean *retownvptr;
2984 *retvptrbase = DEBUG_TYPE_NULL;
2985 *retownvptr = false;
2989 /* If we are positioned at a ';', then skip it. */
2998 if (**pp == '=' || **pp == '+' || **pp == '-')
3000 /* Obsolete flags that used to indicate the presence of
3001 constructors and/or destructors. */
3012 /* The next number is the type number of the base class (possibly
3013 our own class) which supplies the vtable for this class. */
3014 if (! parse_stab_type_number (pp, vtypenums))
3017 if (vtypenums[0] == typenums[0]
3018 && vtypenums[1] == typenums[1])
3027 vtype = parse_stab_type (dhandle, info, (const char *) NULL, pp,
3028 (debug_type **) NULL);
3029 for (p = *pp; *p != ';' && *p != '\0'; p++)
3037 *retvptrbase = vtype;
3045 /* Read a definition of an array type. */
3048 parse_stab_array_type (dhandle, info, pp, stringp)
3050 struct stab_handle *info;
3057 debug_type index_type;
3059 bfd_signed_vma lower, upper;
3060 debug_type element_type;
3062 /* Format of an array type:
3063 "ar<index type>;lower;upper;<array_contents_type>".
3064 OS9000: "arlower,upper;<array_contents_type>".
3066 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
3067 for these, produce a type like float[][]. */
3071 /* FIXME: gdb checks os9k_stabs here. */
3073 /* If the index type is type 0, we take it as int. */
3075 if (! parse_stab_type_number (&p, typenums))
3077 if (typenums[0] == 0 && typenums[1] == 0 && **pp != '=')
3079 index_type = debug_find_named_type (dhandle, "int");
3080 if (index_type == DEBUG_TYPE_NULL)
3082 index_type = debug_make_int_type (dhandle, 4, false);
3083 if (index_type == DEBUG_TYPE_NULL)
3090 index_type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
3091 (debug_type **) NULL);
3097 return DEBUG_TYPE_NULL;
3103 if (! isdigit ((unsigned char) **pp) && **pp != '-')
3109 lower = (bfd_signed_vma) parse_number (pp, (boolean *) NULL);
3117 if (! isdigit ((unsigned char) **pp) && **pp != '-')
3123 upper = (bfd_signed_vma) parse_number (pp, (boolean *) NULL);
3131 element_type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
3132 (debug_type **) NULL);
3133 if (element_type == DEBUG_TYPE_NULL)
3142 return debug_make_array_type (dhandle, element_type, index_type, lower,
3146 /* Keep a stack of N_BINCL include files. */
3150 struct bincl_file *next;
3154 /* Start a new N_BINCL file, pushing it onto the stack. */
3157 push_bincl (info, name)
3158 struct stab_handle *info;
3161 struct bincl_file *n;
3163 n = (struct bincl_file *) xmalloc (sizeof *n);
3164 n->next = info->bincl_stack;
3166 info->bincl_stack = n;
3169 info->file_types = ((struct stab_types **)
3170 xrealloc ((PTR) info->file_types,
3172 * sizeof *info->file_types)));
3173 info->file_types[info->files - 1] = NULL;
3176 /* Finish an N_BINCL file, at an N_EINCL, popping the name off the
3181 struct stab_handle *info;
3183 struct bincl_file *o;
3185 o = info->bincl_stack;
3187 return info->main_filename;
3188 info->bincl_stack = o->next;
3190 if (info->bincl_stack == NULL)
3191 return info->main_filename;
3192 return info->bincl_stack->name;
3195 /* Handle a variable definition. gcc emits variable definitions for a
3196 block before the N_LBRAC, so we must hold onto them until we see
3197 it. The SunPRO compiler emits variable definitions after the
3198 N_LBRAC, so we can call debug_record_variable immediately. */
3201 stab_record_variable (dhandle, info, name, type, kind, val)
3203 struct stab_handle *info;
3206 enum debug_var_kind kind;
3209 struct stab_pending_var *v;
3211 if ((kind == DEBUG_GLOBAL || kind == DEBUG_STATIC)
3212 || ! info->within_function
3213 || (info->gcc_compiled == 0 && info->n_opt_found))
3214 return debug_record_variable (dhandle, name, type, kind, val);
3216 v = (struct stab_pending_var *) xmalloc (sizeof *v);
3217 memset (v, 0, sizeof *v);
3219 v->next = info->pending;
3229 /* Emit pending variable definitions. This is called after we see the
3230 N_LBRAC that starts the block. */
3233 stab_emit_pending_vars (dhandle, info)
3235 struct stab_handle *info;
3237 struct stab_pending_var *v;
3242 struct stab_pending_var *next;
3244 if (! debug_record_variable (dhandle, v->name, v->type, v->kind, v->val))
3252 info->pending = NULL;
3257 /* Find the slot for a type in the database. */
3260 stab_find_slot (info, typenums)
3261 struct stab_handle *info;
3262 const int *typenums;
3266 struct stab_types **ps;
3268 filenum = typenums[0];
3269 index = typenums[1];
3271 if (filenum < 0 || (unsigned int) filenum >= info->files)
3273 fprintf (stderr, "Type file number %d out of range\n", filenum);
3278 fprintf (stderr, "Type index number %d out of range\n", index);
3282 ps = info->file_types + filenum;
3284 while (index >= STAB_TYPES_SLOTS)
3288 *ps = (struct stab_types *) xmalloc (sizeof **ps);
3289 memset (*ps, 0, sizeof **ps);
3292 index -= STAB_TYPES_SLOTS;
3296 *ps = (struct stab_types *) xmalloc (sizeof **ps);
3297 memset (*ps, 0, sizeof **ps);
3300 return (*ps)->types + index;
3303 /* Find a type given a type number. If the type has not been
3304 allocated yet, create an indirect type. */
3307 stab_find_type (dhandle, info, typenums)
3309 struct stab_handle *info;
3310 const int *typenums;
3314 if (typenums[0] == 0 && typenums[1] < 0)
3316 /* A negative type number indicates an XCOFF builtin type. */
3317 return stab_xcoff_builtin_type (dhandle, info, typenums[1]);
3320 slot = stab_find_slot (info, typenums);
3322 return DEBUG_TYPE_NULL;
3324 if (*slot == DEBUG_TYPE_NULL)
3325 return debug_make_indirect_type (dhandle, slot, (const char *) NULL);
3330 /* Record that a given type number refers to a given type. */
3333 stab_record_type (dhandle, info, typenums, type)
3335 struct stab_handle *info;
3336 const int *typenums;
3341 slot = stab_find_slot (info, typenums);
3345 /* gdb appears to ignore type redefinitions, so we do as well. */
3352 /* Return an XCOFF builtin type. */
3355 stab_xcoff_builtin_type (dhandle, info, typenum)
3357 struct stab_handle *info;
3363 if (typenum >= 0 || typenum < -XCOFF_TYPE_COUNT)
3365 fprintf (stderr, "Unrecognized XCOFF type %d\n", typenum);
3366 return DEBUG_TYPE_NULL;
3368 if (info->xcoff_types[-typenum] != NULL)
3369 return info->xcoff_types[-typenum];
3374 /* The size of this and all the other types are fixed, defined
3375 by the debugging format. */
3377 rettype = debug_make_int_type (dhandle, 4, false);
3381 rettype = debug_make_int_type (dhandle, 1, false);
3385 rettype = debug_make_int_type (dhandle, 2, false);
3389 rettype = debug_make_int_type (dhandle, 4, false);
3392 name = "unsigned char";
3393 rettype = debug_make_int_type (dhandle, 1, true);
3396 name = "signed char";
3397 rettype = debug_make_int_type (dhandle, 1, false);
3400 name = "unsigned short";
3401 rettype = debug_make_int_type (dhandle, 2, true);
3404 name = "unsigned int";
3405 rettype = debug_make_int_type (dhandle, 4, true);
3409 rettype = debug_make_int_type (dhandle, 4, true);
3411 name = "unsigned long";
3412 rettype = debug_make_int_type (dhandle, 4, true);
3416 rettype = debug_make_void_type (dhandle);
3419 /* IEEE single precision (32 bit). */
3421 rettype = debug_make_float_type (dhandle, 4);
3424 /* IEEE double precision (64 bit). */
3426 rettype = debug_make_float_type (dhandle, 8);
3429 /* This is an IEEE double on the RS/6000, and different machines
3430 with different sizes for "long double" should use different
3431 negative type numbers. See stabs.texinfo. */
3432 name = "long double";
3433 rettype = debug_make_float_type (dhandle, 8);
3437 rettype = debug_make_int_type (dhandle, 4, false);
3441 rettype = debug_make_bool_type (dhandle, 4);
3444 name = "short real";
3445 rettype = debug_make_float_type (dhandle, 4);
3449 rettype = debug_make_float_type (dhandle, 8);
3459 rettype = debug_make_int_type (dhandle, 1, true);
3463 rettype = debug_make_bool_type (dhandle, 1);
3467 rettype = debug_make_bool_type (dhandle, 2);
3471 rettype = debug_make_bool_type (dhandle, 4);
3475 rettype = debug_make_bool_type (dhandle, 4);
3478 /* Complex type consisting of two IEEE single precision values. */
3480 rettype = debug_make_complex_type (dhandle, 8);
3483 /* Complex type consisting of two IEEE double precision values. */
3484 name = "double complex";
3485 rettype = debug_make_complex_type (dhandle, 16);
3489 rettype = debug_make_int_type (dhandle, 1, false);
3493 rettype = debug_make_int_type (dhandle, 2, false);
3497 rettype = debug_make_int_type (dhandle, 4, false);
3502 rettype = debug_make_int_type (dhandle, 2, false);
3506 rettype = debug_make_int_type (dhandle, 8, false);
3509 name = "unsigned long long";
3510 rettype = debug_make_int_type (dhandle, 8, true);
3514 rettype = debug_make_bool_type (dhandle, 8);
3518 rettype = debug_make_int_type (dhandle, 8, false);
3524 rettype = debug_name_type (dhandle, name, rettype);
3526 info->xcoff_types[-typenum] = rettype;
3531 /* Find or create a tagged type. */
3534 stab_find_tagged_type (dhandle, info, p, len, kind)
3536 struct stab_handle *info;
3539 enum debug_type_kind kind;
3543 struct stab_tag *st;
3545 name = savestring (p, len);
3547 /* We pass DEBUG_KIND_ILLEGAL because we want all tags in the same
3548 namespace. This is right for C, and I don't know how to handle
3549 other languages. FIXME. */
3550 dtype = debug_find_tagged_type (dhandle, name, DEBUG_KIND_ILLEGAL);
3551 if (dtype != DEBUG_TYPE_NULL)
3557 /* We need to allocate an entry on the undefined tag list. */
3558 for (st = info->tags; st != NULL; st = st->next)
3560 if (st->name[0] == name[0]
3561 && strcmp (st->name, name) == 0)
3563 if (st->kind == DEBUG_KIND_ILLEGAL)
3571 st = (struct stab_tag *) xmalloc (sizeof *st);
3572 memset (st, 0, sizeof *st);
3574 st->next = info->tags;
3577 st->slot = DEBUG_TYPE_NULL;
3578 st->type = debug_make_indirect_type (dhandle, &st->slot, name);
3585 /* In order to get the correct argument types for a stubbed method, we
3586 need to extract the argument types from a C++ mangled string.
3587 Since the argument types can refer back to the return type, this
3588 means that we must demangle the entire physical name. In gdb this
3589 is done by calling cplus_demangle and running the results back
3590 through the C++ expression parser. Since we have no expression
3591 parser, we must duplicate much of the work of cplus_demangle here.
3593 We assume that GNU style demangling is used, since this is only
3594 done for method stubs, and only g++ should output that form of
3595 debugging information. */
3597 /* This structure is used to hold a pointer to type information which
3598 demangling a string. */
3600 struct stab_demangle_typestring
3602 /* The start of the type. This is not null terminated. */
3603 const char *typestring;
3604 /* The length of the type. */
3608 /* This structure is used to hold information while demangling a
3611 struct stab_demangle_info
3613 /* The debugging information handle. */
3615 /* The stab information handle. */
3616 struct stab_handle *info;
3617 /* The array of arguments we are building. */
3619 /* Whether the method takes a variable number of arguments. */
3621 /* The array of types we have remembered. */
3622 struct stab_demangle_typestring *typestrings;
3623 /* The number of typestrings. */
3624 unsigned int typestring_count;
3625 /* The number of typestring slots we have allocated. */
3626 unsigned int typestring_alloc;
3629 static void stab_bad_demangle PARAMS ((const char *));
3630 static unsigned int stab_demangle_count PARAMS ((const char **));
3631 static boolean stab_demangle_get_count
3632 PARAMS ((const char **, unsigned int *));
3633 static boolean stab_demangle_prefix
3634 PARAMS ((struct stab_demangle_info *, const char **));
3635 static boolean stab_demangle_function_name
3636 PARAMS ((struct stab_demangle_info *, const char **, const char *));
3637 static boolean stab_demangle_signature
3638 PARAMS ((struct stab_demangle_info *, const char **));
3639 static boolean stab_demangle_qualified
3640 PARAMS ((struct stab_demangle_info *, const char **, debug_type *));
3641 static boolean stab_demangle_template
3642 PARAMS ((struct stab_demangle_info *, const char **));
3643 static boolean stab_demangle_class
3644 PARAMS ((struct stab_demangle_info *, const char **, const char **));
3645 static boolean stab_demangle_args
3646 PARAMS ((struct stab_demangle_info *, const char **, debug_type **,
3648 static boolean stab_demangle_arg
3649 PARAMS ((struct stab_demangle_info *, const char **, debug_type **,
3650 unsigned int *, unsigned int *));
3651 static boolean stab_demangle_type
3652 PARAMS ((struct stab_demangle_info *, const char **, debug_type *));
3653 static boolean stab_demangle_fund_type
3654 PARAMS ((struct stab_demangle_info *, const char **, debug_type *));
3655 static boolean stab_demangle_remember_type
3656 PARAMS ((struct stab_demangle_info *, const char *, int));
3658 /* Warn about a bad demangling. */
3661 stab_bad_demangle (s)
3664 fprintf (stderr, "bad mangled name `%s'\n", s);
3667 /* Get a count from a stab string. */
3670 stab_demangle_count (pp)
3676 while (isdigit ((unsigned char) **pp))
3679 count += **pp - '0';
3685 /* Require a count in a string. The count may be multiple digits, in
3686 which case it must end in an underscore. */
3689 stab_demangle_get_count (pp, pi)
3693 if (! isdigit ((unsigned char) **pp))
3698 if (isdigit ((unsigned char) **pp))
3711 while (isdigit ((unsigned char) *p));
3722 /* This function demangles a physical name, returning a NULL
3723 terminated array of argument types. */
3726 stab_demangle_argtypes (dhandle, info, physname, pvarargs)
3728 struct stab_handle *info;
3729 const char *physname;
3732 struct stab_demangle_info minfo;
3734 minfo.dhandle = dhandle;
3737 minfo.varargs = false;
3738 minfo.typestring_alloc = 10;
3739 minfo.typestrings = ((struct stab_demangle_typestring *)
3740 xmalloc (minfo.typestring_alloc
3741 * sizeof *minfo.typestrings));
3742 minfo.typestring_count = 0;
3744 /* cplus_demangle checks for special GNU mangled forms, but we can't
3745 see any of them in mangled method argument types. */
3747 if (! stab_demangle_prefix (&minfo, &physname))
3750 if (*physname != '\0')
3752 if (! stab_demangle_signature (&minfo, &physname))
3756 free (minfo.typestrings);
3757 minfo.typestrings = NULL;
3759 if (minfo.args == NULL)
3760 fprintf (stderr, "no argument types in mangled string\n");
3762 *pvarargs = minfo.varargs;
3766 if (minfo.typestrings != NULL)
3767 free (minfo.typestrings);
3771 /* Demangle the prefix of the mangled name. */
3774 stab_demangle_prefix (minfo, pp)
3775 struct stab_demangle_info *minfo;
3781 /* cplus_demangle checks for global constructors and destructors,
3782 but we can't see them in mangled argument types. */
3784 /* Look for `__'. */
3788 scan = strchr (scan, '_');
3790 while (scan != NULL && *++scan != '_');
3794 stab_bad_demangle (*pp);
3800 /* We found `__'; move ahead to the last contiguous `__' pair. */
3801 i = strspn (scan, "_");
3806 && (isdigit ((unsigned char) scan[2])
3810 /* This is a GNU style constructor name. */
3814 else if (scan == *pp
3815 && ! isdigit ((unsigned char) scan[2])
3818 /* Look for the `__' that separates the prefix from the
3820 while (*scan == '_')
3822 scan = strstr (scan, "__");
3823 if (scan == NULL || scan[2] == '\0')
3825 stab_bad_demangle (*pp);
3829 return stab_demangle_function_name (minfo, pp, scan);
3831 else if (scan[2] != '\0')
3833 /* The name doesn't start with `__', but it does contain `__'. */
3834 return stab_demangle_function_name (minfo, pp, scan);
3838 stab_bad_demangle (*pp);
3844 /* Demangle a function name prefix. The scan argument points to the
3845 double underscore which separates the function name from the
3849 stab_demangle_function_name (minfo, pp, scan)
3850 struct stab_demangle_info *minfo;
3856 /* The string from *pp to scan is the name of the function. We
3857 don't care about the name, since we just looking for argument
3858 types. However, for conversion operators, the name may include a
3859 type which we must remember in order to handle backreferences. */
3865 && strncmp (name, "type", 4) == 0
3866 && (name[4] == '$' || name[4] == '.'))
3870 /* This is a type conversion operator. */
3872 if (! stab_demangle_type (minfo, &tem, (debug_type *) NULL))
3875 else if (name[0] == '_'
3882 /* This is a type conversion operator. */
3884 if (! stab_demangle_type (minfo, &tem, (debug_type *) NULL))
3891 /* Demangle the signature. This is where the argument types are
3895 stab_demangle_signature (minfo, pp)
3896 struct stab_demangle_info *minfo;
3900 boolean expect_func, func_done;
3905 expect_func = false;
3909 while (**pp != '\0')
3915 if (! stab_demangle_qualified (minfo, pp, (debug_type *) NULL)
3916 || ! stab_demangle_remember_type (minfo, hold, *pp - hold))
3923 /* Static member function. FIXME: Can this happen? */
3930 /* Const member function. */
3936 case '0': case '1': case '2': case '3': case '4':
3937 case '5': case '6': case '7': case '8': case '9':
3940 if (! stab_demangle_class (minfo, pp, (const char **) NULL)
3941 || ! stab_demangle_remember_type (minfo, hold, *pp - hold))
3948 /* Function. I don't know if this actually happens with g++
3953 if (! stab_demangle_args (minfo, pp, &minfo->args, &minfo->varargs))
3961 if (! stab_demangle_template (minfo, pp)
3962 || ! stab_demangle_remember_type (minfo, hold, *pp - hold))
3969 /* At the outermost level, we cannot have a return type
3970 specified, so if we run into another '_' at this point we
3971 are dealing with a mangled name that is either bogus, or
3972 has been mangled by some algorithm we don't know how to
3973 deal with. So just reject the entire demangling. */
3974 stab_bad_demangle (orig);
3978 /* Assume we have stumbled onto the first outermost function
3979 argument token, and start processing args. */
3981 if (! stab_demangle_args (minfo, pp, &minfo->args, &minfo->varargs))
3989 if (! stab_demangle_args (minfo, pp, &minfo->args, &minfo->varargs))
3996 /* With GNU style demangling, bar__3foo is 'foo::bar(void)', and
3997 bar__3fooi is 'foo::bar(int)'. We get here when we find the
3998 first case, and need to ensure that the '(void)' gets added
3999 to the current declp. */
4000 if (! stab_demangle_args (minfo, pp, &minfo->args, &minfo->varargs))
4007 /* Demangle a qualified name, such as "Q25Outer5Inner" which is the
4008 mangled form of "Outer::Inner". */
4011 stab_demangle_qualified (minfo, pp, ptype)
4012 struct stab_demangle_info *minfo;
4018 unsigned int qualifiers;
4026 /* GNU mangled name with more than 9 classes. The count is
4027 preceded by an underscore (to distinguish it from the <= 9
4028 case) and followed by an underscore. */
4030 if (! isdigit ((unsigned char) *p) || *p == '0')
4032 stab_bad_demangle (orig);
4035 qualifiers = atoi (p);
4036 while (isdigit ((unsigned char) *p))
4040 stab_bad_demangle (orig);
4046 case '1': case '2': case '3': case '4': case '5':
4047 case '6': case '7': case '8': case '9':
4048 qualifiers = (*pp)[1] - '0';
4049 /* Skip an optional underscore after the count. */
4050 if ((*pp)[2] == '_')
4057 stab_bad_demangle (orig);
4061 context = DEBUG_TYPE_NULL;
4063 /* Pick off the names. */
4064 while (qualifiers-- > 0)
4070 /* FIXME: I don't know how to handle the ptype != NULL case
4072 if (! stab_demangle_template (minfo, pp))
4079 len = stab_demangle_count (pp);
4080 if (strlen (*pp) < len)
4082 stab_bad_demangle (orig);
4088 const debug_field *fields;
4091 if (context != DEBUG_TYPE_NULL)
4092 fields = debug_get_fields (minfo->dhandle, context);
4094 context = DEBUG_TYPE_NULL;
4100 /* Try to find the type by looking through the
4101 fields of context until we find a field with the
4102 same type. This ought to work for a class
4103 defined within a class, but it won't work for,
4104 e.g., an enum defined within a class. stabs does
4105 not give us enough information to figure out the
4108 name = savestring (*pp, len);
4110 for (; *fields != DEBUG_FIELD_NULL; fields++)
4115 ft = debug_get_field_type (minfo->dhandle, *fields);
4118 dn = debug_get_type_name (minfo->dhandle, ft);
4119 if (dn != NULL && strcmp (dn, name) == 0)
4129 if (context == DEBUG_TYPE_NULL)
4131 /* We have to fall back on finding the type by name.
4132 If there are more types to come, then this must
4133 be a class. Otherwise, it could be anything. */
4135 if (qualifiers == 0)
4139 name = savestring (*pp, len);
4140 context = debug_find_named_type (minfo->dhandle,
4145 if (context == DEBUG_TYPE_NULL)
4147 context = stab_find_tagged_type (minfo->dhandle,
4151 ? DEBUG_KIND_ILLEGAL
4152 : DEBUG_KIND_CLASS));
4153 if (context == DEBUG_TYPE_NULL)
4169 /* Demangle a template. */
4172 stab_demangle_template (minfo, pp)
4173 struct stab_demangle_info *minfo;
4183 /* Skip the template name. */
4184 r = stab_demangle_count (pp);
4185 if (r == 0 || strlen (*pp) < r)
4187 stab_bad_demangle (orig);
4192 /* Get the size of the parameter list. */
4193 if (stab_demangle_get_count (pp, &r) == 0)
4195 stab_bad_demangle (orig);
4199 for (i = 0; i < r; i++)
4203 /* This is a type parameter. */
4205 if (! stab_demangle_type (minfo, pp, (debug_type *) NULL))
4211 boolean pointerp, realp, integralp, charp, boolp;
4222 /* This is a value parameter. */
4224 if (! stab_demangle_type (minfo, pp, (debug_type *) NULL))
4227 while (*old_p != '\0' && ! done)
4237 case 'C': /* Const. */
4238 case 'S': /* Signed. */
4239 case 'U': /* Unsigned. */
4240 case 'V': /* Volatile. */
4241 case 'F': /* Function. */
4242 case 'M': /* Member function. */
4246 case 'Q': /* Qualified name. */
4250 case 'T': /* Remembered type. */
4252 case 'v': /* Void. */
4254 case 'x': /* Long long. */
4255 case 'l': /* Long. */
4256 case 'i': /* Int. */
4257 case 's': /* Short. */
4258 case 'w': /* Wchar_t. */
4262 case 'b': /* Bool. */
4266 case 'c': /* Char. */
4270 case 'r': /* Long double. */
4271 case 'd': /* Double. */
4272 case 'f': /* Float. */
4277 /* Assume it's a user defined integral type. */
4288 while (isdigit ((unsigned char) **pp))
4297 val = stab_demangle_count (pp);
4300 stab_bad_demangle (orig);
4308 val = stab_demangle_count (pp);
4309 if (val != 0 && val != 1)
4311 stab_bad_demangle (orig);
4319 while (isdigit ((unsigned char) **pp))
4324 while (isdigit ((unsigned char) **pp))
4330 while (isdigit ((unsigned char) **pp))
4338 if (! stab_demangle_get_count (pp, &len))
4340 stab_bad_demangle (orig);
4351 /* Demangle a class name. */
4354 stab_demangle_class (minfo, pp, pstart)
4355 struct stab_demangle_info *minfo;
4357 const char **pstart;
4364 n = stab_demangle_count (pp);
4365 if (strlen (*pp) < n)
4367 stab_bad_demangle (orig);
4379 /* Demangle function arguments. If the pargs argument is not NULL, it
4380 is set to a NULL terminated array holding the arguments. */
4383 stab_demangle_args (minfo, pp, pargs, pvarargs)
4384 struct stab_demangle_info *minfo;
4390 unsigned int alloc, count;
4397 *pargs = (debug_type *) xmalloc (alloc * sizeof **pargs);
4402 while (**pp != '_' && **pp != '\0' && **pp != 'e')
4404 if (**pp == 'N' || **pp == 'T')
4412 if (temptype == 'T')
4416 if (! stab_demangle_get_count (pp, &r))
4418 stab_bad_demangle (orig);
4423 if (! stab_demangle_get_count (pp, &t))
4425 stab_bad_demangle (orig);
4429 if (t >= minfo->typestring_count)
4431 stab_bad_demangle (orig);
4438 tem = minfo->typestrings[t].typestring;
4439 if (! stab_demangle_arg (minfo, &tem, pargs, &count, &alloc))
4445 if (! stab_demangle_arg (minfo, pp, pargs, &count, &alloc))
4451 (*pargs)[count] = DEBUG_TYPE_NULL;
4463 /* Demangle a single argument. */
4466 stab_demangle_arg (minfo, pp, pargs, pcount, palloc)
4467 struct stab_demangle_info *minfo;
4470 unsigned int *pcount;
4471 unsigned int *palloc;
4477 if (! stab_demangle_type (minfo, pp,
4478 pargs == NULL ? (debug_type *) NULL : &type)
4479 || ! stab_demangle_remember_type (minfo, start, *pp - start))
4484 if (type == DEBUG_TYPE_NULL)
4487 if (*pcount + 1 >= *palloc)
4490 *pargs = ((debug_type *)
4491 xrealloc (*pargs, *palloc * sizeof **pargs));
4493 (*pargs)[*pcount] = type;
4500 /* Demangle a type. If the ptype argument is not NULL, *ptype is set
4501 to the newly allocated type. */
4504 stab_demangle_type (minfo, pp, ptype)
4505 struct stab_demangle_info *minfo;
4517 /* A pointer type. */
4519 if (! stab_demangle_type (minfo, pp, ptype))
4522 *ptype = debug_make_pointer_type (minfo->dhandle, *ptype);
4526 /* A reference type. */
4528 if (! stab_demangle_type (minfo, pp, ptype))
4531 *ptype = debug_make_reference_type (minfo->dhandle, *ptype);
4541 while (**pp != '\0' && **pp != '_')
4543 if (! isdigit ((unsigned char) **pp))
4545 stab_bad_demangle (orig);
4554 stab_bad_demangle (orig);
4559 if (! stab_demangle_type (minfo, pp, ptype))
4563 debug_type int_type;
4565 int_type = debug_find_named_type (minfo->dhandle, "int");
4566 if (int_type == NULL)
4567 int_type = debug_make_int_type (minfo->dhandle, 4, false);
4568 *ptype = debug_make_array_type (minfo->dhandle, *ptype, int_type,
4575 /* A back reference to a remembered type. */
4581 if (! stab_demangle_get_count (pp, &i))
4583 stab_bad_demangle (orig);
4586 if (i >= minfo->typestring_count)
4588 stab_bad_demangle (orig);
4591 p = minfo->typestrings[i].typestring;
4592 if (! stab_demangle_type (minfo, &p, ptype))
4604 if (! stab_demangle_args (minfo, pp,
4606 ? (debug_type **) NULL
4614 /* cplus_demangle will accept a function without a return
4615 type, but I don't know when that will happen, or what
4616 to do if it does. */
4617 stab_bad_demangle (orig);
4621 if (! stab_demangle_type (minfo, pp, ptype))
4624 *ptype = debug_make_function_type (minfo->dhandle, *ptype, args,
4633 boolean memberp, constp, volatilep;
4639 memberp = **pp == 'M';
4646 if (! isdigit ((unsigned char) **pp))
4648 stab_bad_demangle (orig);
4651 n = stab_demangle_count (pp);
4652 if (strlen (*pp) < n)
4654 stab_bad_demangle (orig);
4667 else if (**pp == 'V')
4674 stab_bad_demangle (orig);
4678 if (! stab_demangle_args (minfo, pp,
4680 ? (debug_type **) NULL
4690 stab_bad_demangle (orig);
4695 if (! stab_demangle_type (minfo, pp, ptype))
4700 debug_type class_type;
4702 class_type = stab_find_tagged_type (minfo->dhandle, minfo->info,
4705 if (class_type == DEBUG_TYPE_NULL)
4709 *ptype = debug_make_offset_type (minfo->dhandle, class_type,
4713 /* FIXME: We have no way to record constp or
4715 *ptype = debug_make_method_type (minfo->dhandle, *ptype,
4716 class_type, args, varargs);
4724 if (! stab_demangle_type (minfo, pp, ptype))
4730 if (! stab_demangle_type (minfo, pp, ptype))
4733 *ptype = debug_make_const_type (minfo->dhandle, *ptype);
4741 if (! stab_demangle_qualified (minfo, pp, ptype))
4747 if (! stab_demangle_fund_type (minfo, pp, ptype))
4755 /* Demangle a fundamental type. If the ptype argument is not NULL,
4756 *ptype is set to the newly allocated type. */
4759 stab_demangle_fund_type (minfo, pp, ptype)
4760 struct stab_demangle_info *minfo;
4765 boolean constp, volatilep, unsignedp, signedp;
4810 /* cplus_demangle permits this, but I don't know what it means. */
4811 stab_bad_demangle (orig);
4814 case 'v': /* void */
4817 *ptype = debug_find_named_type (minfo->dhandle, "void");
4818 if (*ptype == DEBUG_TYPE_NULL)
4819 *ptype = debug_make_void_type (minfo->dhandle);
4824 case 'x': /* long long */
4827 *ptype = debug_find_named_type (minfo->dhandle,
4829 ? "long long unsigned int"
4830 : "long long int"));
4831 if (*ptype == DEBUG_TYPE_NULL)
4832 *ptype = debug_make_int_type (minfo->dhandle, 8, unsignedp);
4837 case 'l': /* long */
4840 *ptype = debug_find_named_type (minfo->dhandle,
4842 ? "long unsigned int"
4844 if (*ptype == DEBUG_TYPE_NULL)
4845 *ptype = debug_make_int_type (minfo->dhandle, 4, unsignedp);
4853 *ptype = debug_find_named_type (minfo->dhandle,
4857 if (*ptype == DEBUG_TYPE_NULL)
4858 *ptype = debug_make_int_type (minfo->dhandle, 4, unsignedp);
4863 case 's': /* short */
4866 *ptype = debug_find_named_type (minfo->dhandle,
4868 ? "short unsigned int"
4870 if (*ptype == DEBUG_TYPE_NULL)
4871 *ptype = debug_make_int_type (minfo->dhandle, 2, unsignedp);
4876 case 'b': /* bool */
4879 *ptype = debug_find_named_type (minfo->dhandle, "bool");
4880 if (*ptype == DEBUG_TYPE_NULL)
4881 *ptype = debug_make_bool_type (minfo->dhandle, 4);
4886 case 'c': /* char */
4889 *ptype = debug_find_named_type (minfo->dhandle,
4895 if (*ptype == DEBUG_TYPE_NULL)
4896 *ptype = debug_make_int_type (minfo->dhandle, 1, unsignedp);
4901 case 'w': /* wchar_t */
4904 *ptype = debug_find_named_type (minfo->dhandle, "__wchar_t");
4905 if (*ptype == DEBUG_TYPE_NULL)
4906 *ptype = debug_make_int_type (minfo->dhandle, 2, true);
4911 case 'r': /* long double */
4914 *ptype = debug_find_named_type (minfo->dhandle, "long double");
4915 if (*ptype == DEBUG_TYPE_NULL)
4916 *ptype = debug_make_float_type (minfo->dhandle, 8);
4921 case 'd': /* double */
4924 *ptype = debug_find_named_type (minfo->dhandle, "double");
4925 if (*ptype == DEBUG_TYPE_NULL)
4926 *ptype = debug_make_float_type (minfo->dhandle, 8);
4931 case 'f': /* float */
4934 *ptype = debug_find_named_type (minfo->dhandle, "float");
4935 if (*ptype == DEBUG_TYPE_NULL)
4936 *ptype = debug_make_float_type (minfo->dhandle, 4);
4943 if (! isdigit ((unsigned char) **pp))
4945 stab_bad_demangle (orig);
4949 case '0': case '1': case '2': case '3': case '4':
4950 case '5': case '6': case '7': case '8': case '9':
4954 if (! stab_demangle_class (minfo, pp, &hold))
4960 name = savestring (hold, *pp - hold);
4961 *ptype = debug_find_named_type (minfo->dhandle, name);
4962 if (*ptype == DEBUG_TYPE_NULL)
4964 /* FIXME: It is probably incorrect to assume that
4965 undefined types are tagged types. */
4966 *ptype = stab_find_tagged_type (minfo->dhandle, minfo->info,
4968 DEBUG_KIND_ILLEGAL);
4976 if (! stab_demangle_template (minfo, pp))
4982 /* FIXME: I really don't know how a template should be
4983 represented in the current type system. Perhaps the
4984 template should be demangled into a string, and the type
4985 should be represented as a named type. However, I don't
4986 know what the base type of the named type should be. */
4987 t = debug_make_void_type (minfo->dhandle);
4988 t = debug_make_pointer_type (minfo->dhandle, t);
4989 t = debug_name_type (minfo->dhandle, "TEMPLATE", t);
4995 stab_bad_demangle (orig);
5002 *ptype = debug_make_const_type (minfo->dhandle, *ptype);
5004 *ptype = debug_make_volatile_type (minfo->dhandle, *ptype);
5010 /* Remember a type string in a demangled string. */
5013 stab_demangle_remember_type (minfo, p, len)
5014 struct stab_demangle_info *minfo;
5018 if (minfo->typestring_count >= minfo->typestring_alloc)
5020 minfo->typestring_alloc += 10;
5021 minfo->typestrings = ((struct stab_demangle_typestring *)
5022 xrealloc (minfo->typestrings,
5023 (minfo->typestring_alloc
5024 * sizeof *minfo->typestrings)));
5027 minfo->typestrings[minfo->typestring_count].typestring = p;
5028 minfo->typestrings[minfo->typestring_count].len = (unsigned int) len;
5029 ++minfo->typestring_count;