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"
36 /* Meaningless definition needs by aout64.h. FIXME. */
37 #define BYTES_IN_WORD 4
39 #include "aout/aout64.h"
40 #include "aout/stab_gnu.h"
42 /* The number of predefined XCOFF types. */
44 #define XCOFF_TYPE_COUNT 34
46 /* This structure is used as a handle so that the stab parsing doesn't
47 need to use any static variables. */
51 /* True if this is stabs in sections. */
53 /* The type of the last stab symbol, so that we can detect N_SO
56 /* The value of the start of the file, so that we can handle file
57 relative N_LBRAC and N_RBRAC symbols. */
58 bfd_vma file_start_offset;
59 /* The offset of the start of the function, so that we can handle
60 function relative N_LBRAC and N_RBRAC symbols. */
61 bfd_vma function_start_offset;
62 /* The version number of gcc which compiled the current compilation
63 unit, 0 if not compiled by gcc. */
65 /* Whether an N_OPT symbol was seen that was not generated by gcc,
66 so that we can detect the SunPRO compiler. */
68 /* The main file name. */
70 /* A stack of N_BINCL files. */
71 struct bincl_file *bincl_stack;
72 /* Whether we are inside a function or not. */
73 boolean within_function;
74 /* The depth of block nesting. */
76 /* List of pending variable definitions. */
77 struct stab_pending_var *pending;
78 /* Number of files for which we have types. */
80 /* Lists of types per file. */
81 struct stab_types **file_types;
82 /* Predefined XCOFF types. */
83 debug_type xcoff_types[XCOFF_TYPE_COUNT];
85 struct stab_tag *tags;
88 /* A list of these structures is used to hold pending variable
89 definitions seen before the N_LBRAC of a block. */
91 struct stab_pending_var
93 /* Next pending variable definition. */
94 struct stab_pending_var *next;
100 enum debug_var_kind kind;
105 /* A list of these structures is used to hold the types for a single
110 /* Next set of slots for this file. */
111 struct stab_types *next;
112 /* Types indexed by type number. */
113 #define STAB_TYPES_SLOTS (16)
114 debug_type types[STAB_TYPES_SLOTS];
117 /* We keep a list of undefined tags that we encounter, so that we can
118 fill them in if the tag is later defined. */
122 /* Next undefined tag. */
123 struct stab_tag *next;
127 enum debug_type_kind kind;
128 /* Slot to hold real type when we discover it. If we don't, we fill
129 in an undefined tag type. */
131 /* Indirect type we have created to point at slot. */
135 static char *savestring PARAMS ((const char *, int));
136 static bfd_vma parse_number PARAMS ((const char **, boolean *));
137 static void bad_stab PARAMS ((const char *));
138 static void warn_stab PARAMS ((const char *, const char *));
139 static boolean parse_stab_string
140 PARAMS ((PTR, struct stab_handle *, int, int, bfd_vma, const char *));
141 static debug_type parse_stab_type
142 PARAMS ((PTR, struct stab_handle *, const char *, const char **,
144 static boolean parse_stab_type_number
145 PARAMS ((const char **, int *));
146 static debug_type parse_stab_range_type
147 PARAMS ((PTR, struct stab_handle *, const char *, const char **,
149 static debug_type parse_stab_sun_builtin_type PARAMS ((PTR, const char **));
150 static debug_type parse_stab_sun_floating_type
151 PARAMS ((PTR, const char **));
152 static debug_type parse_stab_enum_type PARAMS ((PTR, const char **));
153 static debug_type parse_stab_struct_type
154 PARAMS ((PTR, struct stab_handle *, const char **, boolean, const int *));
155 static boolean parse_stab_baseclasses
156 PARAMS ((PTR, struct stab_handle *, const char **, debug_baseclass **));
157 static boolean parse_stab_struct_fields
158 PARAMS ((PTR, struct stab_handle *, const char **, debug_field **,
160 static boolean parse_stab_cpp_abbrev
161 PARAMS ((PTR, struct stab_handle *, const char **, debug_field *));
162 static boolean parse_stab_one_struct_field
163 PARAMS ((PTR, struct stab_handle *, const char **, const char *,
164 debug_field *, boolean *));
165 static boolean parse_stab_members
166 PARAMS ((PTR, struct stab_handle *, const char **, debug_method **));
167 static boolean parse_stab_tilde_field
168 PARAMS ((PTR, struct stab_handle *, const char **, const int *,
169 debug_type *, boolean *));
170 static debug_type parse_stab_array_type
171 PARAMS ((PTR, struct stab_handle *, const char **, boolean));
172 static void push_bincl PARAMS ((struct stab_handle *, const char *));
173 static const char *pop_bincl PARAMS ((struct stab_handle *));
174 static boolean stab_record_variable
175 PARAMS ((PTR, struct stab_handle *, const char *, debug_type,
176 enum debug_var_kind, bfd_vma));
177 static boolean stab_emit_pending_vars PARAMS ((PTR, struct stab_handle *));
178 static debug_type *stab_find_slot
179 PARAMS ((struct stab_handle *, const int *));
180 static debug_type stab_find_type
181 PARAMS ((PTR, struct stab_handle *, const int *));
182 static boolean stab_record_type
183 PARAMS ((PTR, struct stab_handle *, const int *, debug_type));
184 static debug_type stab_xcoff_builtin_type
185 PARAMS ((PTR, struct stab_handle *, int));
187 /* Save a string in memory. */
190 savestring (start, len)
196 ret = (char *) xmalloc (len + 1);
197 memcpy (ret, start, len);
202 /* Read a number from a string. */
205 parse_number (pp, poverflow)
212 if (poverflow != NULL)
218 ul = strtoul (*pp, (char **) pp, 0);
219 if (ul + 1 != 0 || errno == 0)
222 /* Note that even though strtoul overflowed, it should have set *pp
223 to the end of the number, which is where we want it. */
225 if (sizeof (bfd_vma) > sizeof (unsigned long))
230 bfd_vma over, lastdig;
234 /* Our own version of strtoul, for a bfd_vma. */
250 if (p[1] == 'x' || p[1] == 'X')
262 over = ((bfd_vma) (bfd_signed_vma) -1) / (bfd_vma) base;
263 lastdig = ((bfd_vma) (bfd_signed_vma) -1) % (bfd_vma) base;
272 if (isdigit ((unsigned char) d))
274 else if (isupper ((unsigned char) d))
276 else if (islower ((unsigned char) d))
284 if (v > over || (v == over && (bfd_vma) d > lastdig))
299 /* If we get here, the number is too large to represent in a
302 if (poverflow != NULL)
305 warn_stab (orig, "numeric overflow");
310 /* Give an error for a bad stab string. */
316 fprintf (stderr, "Bad stab: %s\n", p);
319 /* Warn about something in a stab string. */
326 fprintf (stderr, "Warning: %s: %s\n", err, p);
329 /* Create a handle to parse stabs symbols with. */
333 start_stab (dhandle, sections)
337 struct stab_handle *ret;
339 ret = (struct stab_handle *) xmalloc (sizeof *ret);
340 memset (ret, 0, sizeof *ret);
341 ret->sections = sections;
343 ret->file_types = (struct stab_types **) xmalloc (sizeof *ret->file_types);
344 ret->file_types[0] = NULL;
348 /* When we have processed all the stabs information, we need to go
349 through and fill in all the undefined tags. */
352 finish_stab (dhandle, handle)
356 struct stab_handle *info = (struct stab_handle *) handle;
359 if (info->within_function)
361 if (! debug_end_function (dhandle, (bfd_vma) -1))
363 info->within_function = false;
366 for (st = info->tags; st != NULL; st = st->next)
368 st->slot = debug_make_undefined_tagged_type (dhandle, st->name,
370 if (st->slot == DEBUG_TYPE_NULL)
377 /* Handle a single stabs symbol. */
380 parse_stab (dhandle, handle, type, desc, value, string)
388 struct stab_handle *info = (struct stab_handle *) handle;
397 /* Ignore extra outermost context from SunPRO cc and acc. */
398 if (info->n_opt_found && desc == 1)
401 if (! info->within_function)
403 fprintf (stderr, "N_LBRAC not within function\n");
407 /* Start an inner lexical block. */
408 if (! debug_start_block (dhandle,
410 + info->file_start_offset
411 + info->function_start_offset)))
414 /* Emit any pending variable definitions. */
415 if (! stab_emit_pending_vars (dhandle, info))
422 /* Ignore extra outermost context from SunPRO cc and acc. */
423 if (info->n_opt_found && desc == 1)
426 /* We shouldn't have any pending variable definitions here, but,
427 if we do, we probably need to emit them before closing the
429 if (! stab_emit_pending_vars (dhandle, info))
432 /* End an inner lexical block. */
433 if (! debug_end_block (dhandle,
435 + info->file_start_offset
436 + info->function_start_offset)))
440 if (info->block_depth == 0)
442 info->within_function = false;
443 if (! debug_end_function (dhandle,
445 + info->file_start_offset
446 + info->function_start_offset)))
452 /* Start a file. If we get two in a row, the first is the
453 directory name. An empty string is emitted by gcc at the end
454 of a compilation unit. */
457 if (info->within_function)
459 if (! debug_end_function (dhandle, (bfd_vma) -1))
461 info->within_function = false;
465 info->gcc_compiled = 0;
466 info->n_opt_found = false;
467 if (info->last_type == N_SO)
471 if (! debug_append_filename (dhandle, string))
473 o = info->main_filename;
474 info->main_filename = concat (o, string, (const char *) NULL);
479 if (info->within_function)
481 if (! debug_end_function (dhandle, (bfd_vma) -1))
483 info->within_function = false;
485 if (! debug_set_filename (dhandle, string))
487 if (info->main_filename != NULL)
488 free (info->main_filename);
489 info->main_filename = xstrdup (string);
491 /* Generally, for stabs in the symbol table, the N_LBRAC and
492 N_RBRAC symbols are relative to the N_SO symbol value. */
493 if (! info->sections)
494 info->file_start_offset = value;
496 /* We need to reset the mapping from type numbers to types.
497 We can't free the old mapping, because of the use of
498 debug_make_indirect_type. */
500 info->file_types = ((struct stab_types **)
501 xmalloc (sizeof *info->file_types));
502 info->file_types[0] = NULL;
507 /* Start an include file. */
508 if (! debug_start_source (dhandle, string))
513 /* Start an include file which may be replaced. */
514 push_bincl (info, string);
515 if (! debug_start_source (dhandle, string))
520 /* End an N_BINCL include. */
521 if (! debug_start_source (dhandle, pop_bincl (info)))
526 /* This is a duplicate of a header file named by N_BINCL which
527 was eliminated by the linker. */
529 info->file_types = ((struct stab_types **)
530 xrealloc ((PTR) info->file_types,
532 * sizeof *info->file_types)));
533 info->file_types[info->files - 1] = NULL;
537 if (! debug_record_line (dhandle, desc,
538 value + info->function_start_offset))
543 if (! debug_start_common_block (dhandle, string))
548 if (! debug_end_common_block (dhandle, string))
552 /* FIXME: gdb checks the string for N_STSYM, N_LCSYM or N_ROSYM
553 symbols, and if it does not start with :S, gdb relocates the
554 value to the start of the section. gcc always seems to use
555 :S, so we don't worry about this. */
560 colon = strchr (string, ':');
562 && (colon[1] == 'f' || colon[1] == 'F'))
564 if (info->within_function)
566 if (! debug_end_function (dhandle, (bfd_vma) -1))
569 /* For stabs in sections, line numbers and block addresses
570 are offsets from the start of the function. */
572 info->function_start_offset = value;
573 info->within_function = true;
576 if (! parse_stab_string (dhandle, info, type, desc, value, string))
582 if (string != NULL && strcmp (string, "gcc2_compiled.") == 0)
583 info->gcc_compiled = 2;
584 else if (string != NULL && strcmp (string, "gcc_compiled.") == 0)
585 info->gcc_compiled = 1;
587 info->n_opt_found = true;
596 info->last_type = type;
601 /* Parse the stabs string. */
604 parse_stab_string (dhandle, info, stabtype, desc, value, string)
606 struct stab_handle *info;
620 p = strchr (string, ':');
635 /* GCC 2.x puts the line number in desc. SunOS apparently puts in
636 the number of bytes occupied by a type or object, which we
638 if (info->gcc_compiled >= 2)
643 /* FIXME: Sometimes the special C++ names start with '.'. */
645 if (string[0] == '$')
653 /* Was: name = "vptr"; */
659 /* This was an anonymous type that was never fixed up. */
662 /* SunPRO (3.0 at least) static variable encoding. */
665 warn_stab (string, "unknown C++ encoded name");
672 if (p == string || (string[0] == ' ' && p == string + 1))
675 name = savestring (string, p - string);
679 if (isdigit ((unsigned char) *p) || *p == '(' || *p == '-')
687 /* c is a special case, not followed by a type-number.
688 SYMBOL:c=iVALUE for an integer constant symbol.
689 SYMBOL:c=rVALUE for a floating constant symbol.
690 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
691 e.g. "b:c=e6,0" for "const b = blob1"
692 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
702 /* Floating point constant. */
703 if (! debug_record_float_const (dhandle, name, atof (p)))
707 /* Integer constant. */
708 /* Defining integer constants this way is kind of silly,
709 since 'e' constants allows the compiler to give not only
710 the value, but the type as well. C has at least int,
711 long, unsigned int, and long long as constant types;
712 other languages probably should have at least unsigned as
713 well as signed constants. */
714 if (! debug_record_int_const (dhandle, name, atoi (p)))
718 /* SYMBOL:c=eTYPE,INTVALUE for a constant symbol whose value
719 can be represented as integral.
720 e.g. "b:c=e6,0" for "const b = blob1"
721 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
722 dtype = parse_stab_type (dhandle, info, (const char *) NULL,
723 &p, (debug_type **) NULL);
724 if (dtype == DEBUG_TYPE_NULL)
731 if (! debug_record_typed_const (dhandle, name, dtype, atoi (p)))
742 /* The name of a caught exception. */
743 dtype = parse_stab_type (dhandle, info, (const char *) NULL,
744 &p, (debug_type **) NULL);
745 if (dtype == DEBUG_TYPE_NULL)
747 if (! debug_record_label (dhandle, name, dtype, value))
753 /* A function definition. */
754 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
755 (debug_type **) NULL);
756 if (dtype == DEBUG_TYPE_NULL)
758 if (! debug_record_function (dhandle, name, dtype, type == 'F', value))
761 /* Sun acc puts declared types of arguments here. We don't care
762 about their actual types (FIXME -- we should remember the whole
763 function prototype), but the list may define some new types
764 that we have to remember, so we must scan it now. */
768 if (parse_stab_type (dhandle, info, (const char *) NULL, &p,
769 (debug_type **) NULL)
777 /* A global symbol. The value must be extracted from the symbol
779 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
780 (debug_type **) NULL);
781 if (dtype == DEBUG_TYPE_NULL)
783 if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_GLOBAL,
788 /* This case is faked by a conditional above, when there is no
789 code letter in the dbx data. Dbx data never actually
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_LOCAL,
803 /* A function parameter. */
805 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
806 (debug_type **) NULL);
809 /* pF is a two-letter code that means a function parameter in
810 Fortran. The type-number specifies the type of the return
811 value. Translate it into a pointer-to-function type. */
813 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
814 (debug_type **) NULL);
815 if (dtype != DEBUG_TYPE_NULL)
816 dtype = debug_make_pointer_type (dhandle,
817 debug_make_function_type (dhandle,
820 if (dtype == DEBUG_TYPE_NULL)
822 if (! debug_record_parameter (dhandle, name, dtype, DEBUG_PARM_STACK,
826 /* FIXME: At this point gdb considers rearranging the parameter
827 address on a big endian machine if it is smaller than an int.
828 We have no way to do that, since we don't really know much
834 if (stabtype == N_FUN)
836 /* Prototype of a function referenced by this file. */
840 if (parse_stab_type (dhandle, info, (const char *) NULL, &p,
841 (debug_type **) NULL)
849 /* Parameter which is in a register. */
850 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
851 (debug_type **) NULL);
852 if (dtype == DEBUG_TYPE_NULL)
854 if (! debug_record_parameter (dhandle, name, dtype, DEBUG_PARM_REG,
860 /* Register variable (either global or local). */
861 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
862 (debug_type **) NULL);
863 if (dtype == DEBUG_TYPE_NULL)
865 if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_REGISTER,
869 /* FIXME: At this point gdb checks to combine pairs of 'p' and
870 'r' stabs into a single 'P' stab. */
875 /* Static symbol at top level of file */
876 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
877 (debug_type **) NULL);
878 if (dtype == DEBUG_TYPE_NULL)
880 if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_STATIC,
887 dtype = parse_stab_type (dhandle, info, name, &p, &slot);
888 if (dtype == DEBUG_TYPE_NULL)
892 /* A nameless type. Nothing to do. */
896 dtype = debug_name_type (dhandle, name, dtype);
897 if (dtype == DEBUG_TYPE_NULL)
906 /* Struct, union, or enum tag. For GNU C++, this can be be followed
907 by 't' which means we are typedef'ing it as well. */
911 /* FIXME: gdb sets synonym to true if the current language
920 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p, &slot);
921 if (dtype == DEBUG_TYPE_NULL)
926 dtype = debug_tag_type (dhandle, name, dtype);
927 if (dtype == DEBUG_TYPE_NULL)
932 /* See if we have a cross reference to this tag which we can now
935 register struct stab_tag **pst;
937 for (pst = &info->tags; *pst != NULL; pst = &(*pst)->next)
939 if ((*pst)->name[0] == name[0]
940 && strcmp ((*pst)->name, name) == 0)
942 (*pst)->slot = dtype;
951 dtype = debug_name_type (dhandle, name, dtype);
952 if (dtype == DEBUG_TYPE_NULL)
962 /* Static symbol of local scope */
963 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
964 (debug_type **) NULL);
965 if (dtype == DEBUG_TYPE_NULL)
967 /* FIXME: gdb checks os9k_stabs here. */
968 if (! stab_record_variable (dhandle, info, name, dtype,
969 DEBUG_LOCAL_STATIC, value))
974 /* Reference parameter. */
975 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
976 (debug_type **) NULL);
977 if (dtype == DEBUG_TYPE_NULL)
979 if (! debug_record_parameter (dhandle, name, dtype, DEBUG_PARM_REFERENCE,
985 /* Reference parameter which is in a register. */
986 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
987 (debug_type **) NULL);
988 if (dtype == DEBUG_TYPE_NULL)
990 if (! debug_record_parameter (dhandle, name, dtype, DEBUG_PARM_REF_REG,
996 /* This is used by Sun FORTRAN for "function result value".
997 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
998 that Pascal uses it too, but when I tried it Pascal used
999 "x:3" (local symbol) instead. */
1000 dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p,
1001 (debug_type **) NULL);
1002 if (dtype == DEBUG_TYPE_NULL)
1004 if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_LOCAL,
1014 /* FIXME: gdb converts structure values to structure pointers in a
1015 couple of cases, depending upon the target. */
1020 /* Parse a stabs type. The typename argument is non-NULL if this is a
1021 typedef. The pp argument points to the stab string, and is
1022 updated. The slotp argument points to a place to store the slot
1023 used if the type is being defined. */
1026 parse_stab_type (dhandle, info, typename, pp, slotp)
1028 struct stab_handle *info;
1029 const char *typename;
1048 /* Read type number if present. The type number may be omitted.
1049 for instance in a two-dimensional array declared with type
1050 "ar1;1;10;ar1;1;10;4". */
1051 if (! isdigit ((unsigned char) **pp) && **pp != '(' && **pp != '-')
1053 /* 'typenums=' not present, type is anonymous. Read and return
1054 the definition, but don't put it in the type vector. */
1055 typenums[0] = typenums[1] = -1;
1059 if (! parse_stab_type_number (pp, typenums))
1060 return DEBUG_TYPE_NULL;
1064 /* Type is not being defined here. Either it already
1065 exists, or this is a forward reference to it. */
1066 return stab_find_type (dhandle, info, typenums);
1069 /* Only set the slot if the type is being defined. This means
1070 that the mapping from type numbers to types will only record
1071 the name of the typedef which defines a type. If we don't do
1072 this, then something like
1075 will record that i is of type foo. Unfortunately, stabs
1076 information is ambiguous about variable types. For this code,
1080 the stabs information records both i and j as having the same
1081 type. This could be fixed by patching the compiler. */
1082 if (slotp != NULL && typenums[0] >= 0 && typenums[1] >= 0)
1083 *slotp = stab_find_slot (info, typenums);
1085 /* Type is being defined here. */
1091 const char *p = *pp + 1;
1094 if (isdigit ((unsigned char) *p) || *p == '(' || *p == '-')
1100 /* Type attributes. */
1103 for (; *p != ';'; ++p)
1108 return DEBUG_TYPE_NULL;
1116 size = atoi (attr + 1);
1126 /* Ignore unrecognized type attributes, so future
1127 compilers can invent new ones. */
1140 enum debug_type_kind code;
1141 const char *q1, *q2, *p;
1143 struct stab_tag *st;
1145 /* A cross reference to another type. */
1150 code = DEBUG_KIND_STRUCT;
1153 code = DEBUG_KIND_UNION;
1156 code = DEBUG_KIND_ENUM;
1159 /* Complain and keep going, so compilers can invent new
1160 cross-reference types. */
1161 warn_stab (orig, "unrecognized cross reference type");
1162 code = DEBUG_KIND_STRUCT;
1167 q1 = strchr (*pp, '<');
1168 p = strchr (*pp, ':');
1172 return DEBUG_TYPE_NULL;
1174 while (q1 != NULL && p > q1 && p[1] == ':')
1176 q2 = strchr (q1, '>');
1177 if (q2 == NULL || q2 < p)
1180 p = strchr (p, ':');
1184 return DEBUG_TYPE_NULL;
1188 name = savestring (*pp, p - *pp);
1192 /* We pass DEBUG_KIND_VOID because we want all tags in the
1193 same namespace. This is right for C, and I don't know how
1194 to handle other languages. FIXME. */
1195 dtype = debug_find_tagged_type (dhandle, name, DEBUG_KIND_VOID);
1196 if (dtype != DEBUG_TYPE_NULL)
1199 if (typenums[0] != -1)
1201 if (! stab_record_type (dhandle, info, typenums, dtype))
1202 return DEBUG_TYPE_NULL;
1207 /* We need to allocate an entry on the undefined tag list. */
1208 for (st = info->tags; st != NULL; st = st->next)
1210 if (st->name[0] == name[0]
1211 && strcmp (st->name, name) == 0)
1216 st = (struct stab_tag *) xmalloc (sizeof *st);
1217 memset (st, 0, sizeof *st);
1219 st->next = info->tags;
1222 st->slot = DEBUG_TYPE_NULL;
1223 st->type = debug_make_indirect_type (dhandle, &st->slot, name);
1228 if (typenums[0] != -1)
1230 if (! stab_record_type (dhandle, info, typenums, dtype))
1231 return DEBUG_TYPE_NULL;
1253 /* This type is defined as another type. */
1258 /* Peek ahead at the number to detect void. */
1259 if (! parse_stab_type_number (pp, xtypenums))
1260 return DEBUG_TYPE_NULL;
1262 if (typenums[0] == xtypenums[0] && typenums[1] == xtypenums[1])
1264 /* This type is being defined as itself, which means that
1266 dtype = debug_make_void_type (dhandle);
1272 /* Go back to the number and have parse_stab_type get it.
1273 This means that we can deal with something like
1274 t(1,2)=(3,4)=... which the Lucid compiler uses. */
1275 dtype = parse_stab_type (dhandle, info, (const char *) NULL,
1276 pp, (debug_type **) NULL);
1277 if (dtype == DEBUG_TYPE_NULL)
1278 return DEBUG_TYPE_NULL;
1281 if (typenums[0] != -1)
1283 if (! stab_record_type (dhandle, info, typenums, dtype))
1284 return DEBUG_TYPE_NULL;
1291 dtype = debug_make_pointer_type (dhandle,
1292 parse_stab_type (dhandle, info,
1293 (const char *) NULL,
1295 (debug_type **) NULL));
1299 /* Reference to another type. */
1300 dtype = (debug_make_reference_type
1302 parse_stab_type (dhandle, info, (const char *) NULL, pp,
1303 (debug_type **) NULL)));
1307 /* Function returning another type. */
1308 /* FIXME: gdb checks os9k_stabs here. */
1309 dtype = (debug_make_function_type
1311 parse_stab_type (dhandle, info, (const char *) NULL, pp,
1312 (debug_type **) NULL)));
1316 /* Const qualifier on some type (Sun). */
1317 /* FIXME: gdb accepts 'c' here if os9k_stabs. */
1318 dtype = debug_make_const_type (dhandle,
1319 parse_stab_type (dhandle, info,
1320 (const char *) NULL,
1322 (debug_type **) NULL));
1326 /* Volatile qual on some type (Sun). */
1327 /* FIXME: gdb accepts 'i' here if os9k_stabs. */
1328 dtype = (debug_make_volatile_type
1330 parse_stab_type (dhandle, info, (const char *) NULL, pp,
1331 (debug_type **) NULL)));
1335 /* Offset (class & variable) type. This is used for a pointer
1336 relative to an object. */
1343 domain = parse_stab_type (dhandle, info, (const char *) NULL, pp,
1344 (debug_type **) NULL);
1345 if (domain == DEBUG_TYPE_NULL)
1346 return DEBUG_TYPE_NULL;
1351 return DEBUG_TYPE_NULL;
1355 memtype = parse_stab_type (dhandle, info, (const char *) NULL, pp,
1356 (debug_type **) NULL);
1357 if (memtype == DEBUG_TYPE_NULL)
1358 return DEBUG_TYPE_NULL;
1360 dtype = debug_make_offset_type (dhandle, domain, memtype);
1365 /* Method (class & fn) type. */
1368 debug_type return_type;
1371 return_type = parse_stab_type (dhandle, info, (const char *) NULL,
1372 pp, (debug_type **) NULL);
1373 if (return_type == DEBUG_TYPE_NULL)
1374 return DEBUG_TYPE_NULL;
1378 return DEBUG_TYPE_NULL;
1381 dtype = debug_make_method_type (dhandle, return_type,
1382 DEBUG_TYPE_NULL, NULL);
1387 debug_type return_type;
1392 domain = parse_stab_type (dhandle, info, (const char *) NULL,
1393 pp, (debug_type **) NULL);
1394 if (domain == DEBUG_TYPE_NULL)
1395 return DEBUG_TYPE_NULL;
1400 return DEBUG_TYPE_NULL;
1404 return_type = parse_stab_type (dhandle, info, (const char *) NULL,
1405 pp, (debug_type **) NULL);
1406 if (return_type == DEBUG_TYPE_NULL)
1407 return DEBUG_TYPE_NULL;
1410 args = (debug_type *) xmalloc (alloc * sizeof *args);
1417 return DEBUG_TYPE_NULL;
1424 args = ((debug_type *)
1425 xrealloc ((PTR) args, alloc * sizeof *args));
1428 args[n] = parse_stab_type (dhandle, info, (const char *) NULL,
1429 pp, (debug_type **) NULL);
1430 if (args[n] == DEBUG_TYPE_NULL)
1431 return DEBUG_TYPE_NULL;
1436 args[n] = DEBUG_TYPE_NULL;
1438 dtype = debug_make_method_type (dhandle, return_type, domain, args);
1444 dtype = parse_stab_range_type (dhandle, info, typename, pp, typenums);
1448 /* FIXME: gdb checks os9k_stabs here. */
1449 /* Sun ACC builtin int type. */
1450 dtype = parse_stab_sun_builtin_type (dhandle, pp);
1454 /* Sun ACC builtin float type. */
1455 dtype = parse_stab_sun_floating_type (dhandle, pp);
1459 /* Enumeration type. */
1460 dtype = parse_stab_enum_type (dhandle, pp);
1465 /* Struct or union type. */
1466 dtype = parse_stab_struct_type (dhandle, info, pp,
1467 descriptor == 's', typenums);
1475 return DEBUG_TYPE_NULL;
1479 dtype = parse_stab_array_type (dhandle, info, pp, stringp);
1483 dtype = debug_make_set_type (dhandle,
1484 parse_stab_type (dhandle, info,
1485 (const char *) NULL,
1487 (debug_type **) NULL),
1493 return DEBUG_TYPE_NULL;
1496 if (dtype == DEBUG_TYPE_NULL)
1497 return DEBUG_TYPE_NULL;
1499 if (typenums[0] != -1)
1501 if (! stab_record_type (dhandle, info, typenums, dtype))
1502 return DEBUG_TYPE_NULL;
1507 if (! debug_record_type_size (dhandle, dtype, (unsigned int) size))
1514 /* Read a number by which a type is referred to in dbx data, or
1515 perhaps read a pair (FILENUM, TYPENUM) in parentheses. Just a
1516 single number N is equivalent to (0,N). Return the two numbers by
1517 storing them in the vector TYPENUMS. */
1520 parse_stab_type_number (pp, typenums)
1531 typenums[1] = (int) parse_number (pp, (boolean *) NULL);
1536 typenums[0] = (int) parse_number (pp, (boolean *) NULL);
1543 typenums[1] = (int) parse_number (pp, (boolean *) NULL);
1555 /* Parse a range type. */
1558 parse_stab_range_type (dhandle, info, typename, pp, typenums)
1560 struct stab_handle *info;
1561 const char *typename;
1563 const int *typenums;
1567 boolean self_subrange;
1568 debug_type index_type;
1569 const char *s2, *s3;
1570 bfd_signed_vma n2, n3;
1575 index_type = DEBUG_TYPE_NULL;
1577 /* First comes a type we are a subrange of.
1578 In C it is usually 0, 1 or the type being defined. */
1579 if (! parse_stab_type_number (pp, rangenums))
1580 return DEBUG_TYPE_NULL;
1582 self_subrange = (rangenums[0] == typenums[0]
1583 && rangenums[1] == typenums[1]);
1588 index_type = parse_stab_type (dhandle, info, (const char *) NULL,
1589 pp, (debug_type **) NULL);
1590 if (index_type == DEBUG_TYPE_NULL)
1591 return DEBUG_TYPE_NULL;
1597 /* The remaining two operands are usually lower and upper bounds of
1598 the range. But in some special cases they mean something else. */
1600 n2 = parse_number (pp, &ov2);
1604 return DEBUG_TYPE_NULL;
1609 n3 = parse_number (pp, &ov3);
1613 return DEBUG_TYPE_NULL;
1619 /* gcc will emit range stabs for long long types. Handle this
1620 as a special case. FIXME: This needs to be more general. */
1621 #define LLLOW "01000000000000000000000;"
1622 #define LLHIGH "0777777777777777777777;"
1623 #define ULLHIGH "01777777777777777777777;"
1624 if (index_type == DEBUG_TYPE_NULL)
1626 if (strncmp (s2, LLLOW, sizeof LLLOW - 1) == 0
1627 && strncmp (s3, LLHIGH, sizeof LLHIGH - 1) == 0)
1628 return debug_make_int_type (dhandle, 8, false);
1631 && strncmp (s3, ULLHIGH, sizeof ULLHIGH - 1) == 0)
1632 return debug_make_int_type (dhandle, 8, true);
1635 warn_stab (orig, "numeric overflow");
1638 if (index_type == DEBUG_TYPE_NULL)
1640 /* A type defined as a subrange of itself, with both bounds 0,
1642 if (self_subrange && n2 == 0 && n3 == 0)
1643 return debug_make_void_type (dhandle);
1645 /* If n3 is zero and n2 is positive, this is a floating point
1646 type, and n2 is the number of bytes. */
1647 if (n3 == 0 && n2 > 0)
1648 return debug_make_float_type (dhandle, n2);
1650 /* If the upper bound is -1, this is an unsigned int. */
1651 if (n2 == 0 && n3 == -1)
1653 /* When gcc is used with -gstabs, but not -gstabs+, it will emit
1654 long long int:t6=r1;0;-1;
1655 long long unsigned int:t7=r1;0;-1;
1656 We hack here to handle this reasonably. */
1657 if (typename != NULL)
1659 if (strcmp (typename, "long long int") == 0)
1660 return debug_make_int_type (dhandle, 8, false);
1661 else if (strcmp (typename, "long long unsigned int") == 0)
1662 return debug_make_int_type (dhandle, 8, true);
1664 /* FIXME: The size here really depends upon the target. */
1665 return debug_make_int_type (dhandle, 4, true);
1668 /* A range of 0 to 127 is char. */
1669 if (self_subrange && n2 == 0 && n3 == 127)
1670 return debug_make_int_type (dhandle, 1, false);
1672 /* FIXME: gdb checks for the language CHILL here. */
1677 return debug_make_int_type (dhandle, - n3, true);
1678 else if (n3 == 0xff)
1679 return debug_make_int_type (dhandle, 1, true);
1680 else if (n3 == 0xffff)
1681 return debug_make_int_type (dhandle, 2, true);
1682 /* -1 is used for the upper bound of (4 byte) "unsigned int"
1683 and "unsigned long", and we already checked for that, so
1684 don't need to test for it here. */
1688 && (self_subrange || n2 == -8))
1689 return debug_make_int_type (dhandle, - n2, true);
1690 else if (n2 == - n3 - 1)
1693 return debug_make_int_type (dhandle, 1, false);
1694 else if (n3 == 0x7fff)
1695 return debug_make_int_type (dhandle, 2, false);
1696 else if (n3 == 0x7fffffff)
1697 return debug_make_int_type (dhandle, 4, false);
1701 /* At this point I don't have the faintest idea how to deal with a
1702 self_subrange type; I'm going to assume that this is used as an
1703 idiom, and that all of them are special cases. So . . . */
1707 return DEBUG_TYPE_NULL;
1710 index_type = stab_find_type (dhandle, info, rangenums);
1711 if (index_type == DEBUG_TYPE_NULL)
1713 /* Does this actually ever happen? Is that why we are worrying
1714 about dealing with it rather than just calling error_type? */
1715 warn_stab (orig, "missing index type");
1716 index_type = debug_make_int_type (dhandle, 4, false);
1719 return debug_make_range_type (dhandle, index_type, n2, n3);
1722 /* Sun's ACC uses a somewhat saner method for specifying the builtin
1723 typedefs in every file (for int, long, etc):
1725 type = b <signed> <width>; <offset>; <nbits>
1726 signed = u or s. Possible c in addition to u or s (for char?).
1727 offset = offset from high order bit to start bit of type.
1728 width is # bytes in object of this type, nbits is # bits in type.
1730 The width/offset stuff appears to be for small objects stored in
1731 larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
1735 parse_stab_sun_builtin_type (dhandle, pp)
1755 return DEBUG_TYPE_NULL;
1759 /* For some odd reason, all forms of char put a c here. This is strange
1760 because no other type has this honor. We can safely ignore this because
1761 we actually determine 'char'acterness by the number of bits specified in
1766 /* The first number appears to be the number of bytes occupied
1767 by this type, except that unsigned short is 4 instead of 2.
1768 Since this information is redundant with the third number,
1769 we will ignore it. */
1770 (void) parse_number (pp, (boolean *) NULL);
1774 return DEBUG_TYPE_NULL;
1778 /* The second number is always 0, so ignore it too. */
1779 (void) parse_number (pp, (boolean *) NULL);
1783 return DEBUG_TYPE_NULL;
1787 /* The third number is the number of bits for this type. */
1788 bits = parse_number (pp, (boolean *) NULL);
1790 /* The type *should* end with a semicolon. If it are embedded
1791 in a larger type the semicolon may be the only way to know where
1792 the type ends. If this type is at the end of the stabstring we
1793 can deal with the omitted semicolon (but we don't have to like
1794 it). Don't bother to complain(), Sun's compiler omits the semicolon
1800 return debug_make_void_type (dhandle);
1802 return debug_make_int_type (dhandle, bits / 8, unsignedp);
1805 /* Parse a builtin floating type generated by the Sun compiler. */
1808 parse_stab_sun_floating_type (dhandle, pp)
1818 /* The first number has more details about the type, for example
1820 details = parse_number (pp, (boolean *) NULL);
1824 return DEBUG_TYPE_NULL;
1827 /* The second number is the number of bytes occupied by this type */
1828 bytes = parse_number (pp, (boolean *) NULL);
1832 return DEBUG_TYPE_NULL;
1835 if (details == NF_COMPLEX
1836 || details == NF_COMPLEX16
1837 || details == NF_COMPLEX32)
1838 return debug_make_complex_type (dhandle, bytes);
1840 return debug_make_float_type (dhandle, bytes);
1843 /* Handle an enum type. */
1846 parse_stab_enum_type (dhandle, pp)
1852 bfd_signed_vma *values;
1858 /* FIXME: gdb checks os9k_stabs here. */
1860 /* The aix4 compiler emits an extra field before the enum members;
1861 my guess is it's a type of some sort. Just ignore it. */
1869 /* Read the value-names and their values.
1870 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
1871 A semicolon or comma instead of a NAME means the end. */
1873 names = (const char **) xmalloc (alloc * sizeof *names);
1874 values = (bfd_signed_vma *) xmalloc (alloc * sizeof *values);
1876 while (**pp != '\0' && **pp != ';' && **pp != ',')
1886 name = savestring (*pp, p - *pp);
1889 val = (bfd_signed_vma) parse_number (pp, (boolean *) NULL);
1893 return DEBUG_TYPE_NULL;
1900 names = ((const char **)
1901 xrealloc ((PTR) names, alloc * sizeof *names));
1902 values = ((bfd_signed_vma *)
1903 xrealloc ((PTR) values, alloc * sizeof *values));
1917 return debug_make_enum_type (dhandle, names, values);
1920 /* Read the description of a structure (or union type) and return an object
1921 describing the type.
1923 PP points to a character pointer that points to the next unconsumed token
1924 in the the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;",
1925 *PP will point to "4a:1,0,32;;". */
1928 parse_stab_struct_type (dhandle, info, pp, structp, typenums)
1930 struct stab_handle *info;
1933 const int *typenums;
1937 debug_baseclass *baseclasses;
1938 debug_field *fields;
1940 debug_method *methods;
1941 debug_type vptrbase;
1947 size = parse_number (pp, (boolean *) NULL);
1949 /* Get the other information. */
1950 if (! parse_stab_baseclasses (dhandle, info, pp, &baseclasses)
1951 || ! parse_stab_struct_fields (dhandle, info, pp, &fields, &statics)
1952 || ! parse_stab_members (dhandle, info, pp, &methods)
1953 || ! parse_stab_tilde_field (dhandle, info, pp, typenums, &vptrbase,
1955 return DEBUG_TYPE_NULL;
1958 && baseclasses == NULL
1960 && vptrbase == DEBUG_TYPE_NULL
1962 return debug_make_struct_type (dhandle, structp, size, fields);
1964 return debug_make_object_type (dhandle, structp, size, fields, baseclasses,
1965 methods, vptrbase, ownvptr);
1968 /* The stabs for C++ derived classes contain baseclass information which
1969 is marked by a '!' character after the total size. This function is
1970 called when we encounter the baseclass marker, and slurps up all the
1971 baseclass information.
1973 Immediately following the '!' marker is the number of base classes that
1974 the class is derived from, followed by information for each base class.
1975 For each base class, there are two visibility specifiers, a bit offset
1976 to the base class information within the derived class, a reference to
1977 the type for the base class, and a terminating semicolon.
1979 A typical example, with two base classes, would be "!2,020,19;0264,21;".
1981 Baseclass information marker __________________|| | | | | | |
1982 Number of baseclasses __________________________| | | | | | |
1983 Visibility specifiers (2) ________________________| | | | | |
1984 Offset in bits from start of class _________________| | | | |
1985 Type number for base class ___________________________| | | |
1986 Visibility specifiers (2) _______________________________| | |
1987 Offset in bits from start of class ________________________| |
1988 Type number of base class ____________________________________|
1990 Return true for success, false for failure. */
1993 parse_stab_baseclasses (dhandle, info, pp, retp)
1995 struct stab_handle *info;
1997 debug_baseclass **retp;
2001 debug_baseclass *classes;
2009 /* No base classes. */
2014 c = (unsigned int) parse_number (pp, (boolean *) NULL);
2023 classes = (debug_baseclass *) xmalloc ((c + 1) * sizeof (**retp));
2025 for (i = 0; i < c; i++)
2028 enum debug_visibility visibility;
2041 warn_stab (orig, "unknown virtual character for baseclass");
2050 visibility = DEBUG_VISIBILITY_PRIVATE;
2053 visibility = DEBUG_VISIBILITY_PROTECTED;
2056 visibility = DEBUG_VISIBILITY_PUBLIC;
2059 warn_stab (orig, "unknown visibility character for baseclass");
2060 visibility = DEBUG_VISIBILITY_PUBLIC;
2065 /* The remaining value is the bit offset of the portion of the
2066 object corresponding to this baseclass. Always zero in the
2067 absence of multiple inheritance. */
2068 bitpos = parse_number (pp, (boolean *) NULL);
2076 type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
2077 (debug_type **) NULL);
2078 if (type == DEBUG_TYPE_NULL)
2081 classes[i] = debug_make_baseclass (dhandle, type, bitpos, virtual,
2083 if (classes[i] == DEBUG_BASECLASS_NULL)
2091 classes[i] = DEBUG_BASECLASS_NULL;
2098 /* Read struct or class data fields. They have the form:
2100 NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
2102 At the end, we see a semicolon instead of a field.
2104 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
2107 The optional VISIBILITY is one of:
2109 '/0' (VISIBILITY_PRIVATE)
2110 '/1' (VISIBILITY_PROTECTED)
2111 '/2' (VISIBILITY_PUBLIC)
2112 '/9' (VISIBILITY_IGNORE)
2114 or nothing, for C style fields with public visibility.
2116 Returns 1 for success, 0 for failure. */
2119 parse_stab_struct_fields (dhandle, info, pp, retp, staticsp)
2121 struct stab_handle *info;
2128 debug_field *fields;
2139 fields = (debug_field *) xmalloc (alloc * sizeof *fields);
2142 /* FIXME: gdb checks os9k_stabs here. */
2146 /* Add 1 to c to leave room for NULL pointer at end. */
2150 fields = ((debug_field *)
2151 xrealloc ((PTR) fields, alloc * sizeof *fields));
2154 /* If it starts with CPLUS_MARKER it is a special abbreviation,
2155 unless the CPLUS_MARKER is followed by an underscore, in
2156 which case it is just the name of an anonymous type, which we
2157 should handle like any other type name. We accept either '$'
2158 or '.', because a field name can never contain one of these
2159 characters except as a CPLUS_MARKER. */
2161 if ((*p == '$' || *p == '.') && p[1] != '_')
2164 if (! parse_stab_cpp_abbrev (dhandle, info, pp, fields + c))
2170 /* Look for the ':' that separates the field name from the field
2171 values. Data members are delimited by a single ':', while member
2172 functions are delimited by a pair of ':'s. When we hit the member
2173 functions (if any), terminate scan loop and return. */
2175 p = strchr (p, ':');
2185 if (! parse_stab_one_struct_field (dhandle, info, pp, p, fields + c,
2192 fields[c] = DEBUG_FIELD_NULL;
2199 /* Special GNU C++ name. */
2202 parse_stab_cpp_abbrev (dhandle, info, pp, retp)
2204 struct stab_handle *info;
2212 const char *typename;
2216 *retp = DEBUG_FIELD_NULL;
2230 /* At this point, *pp points to something like "22:23=*22...", where
2231 the type number before the ':' is the "context" and everything
2232 after is a regular type definition. Lookup the type, find it's
2233 name, and construct the field name. */
2235 context = parse_stab_type (dhandle, info, (const char *) NULL, pp,
2236 (debug_type **) NULL);
2237 if (context == DEBUG_TYPE_NULL)
2243 /* $vf -- a virtual function table pointer. */
2247 /* $vb -- a virtual bsomethingorother */
2248 typename = debug_get_type_name (dhandle, context);
2249 if (typename == NULL)
2251 warn_stab (orig, "unnamed $vb type");
2254 name = concat ("_vb$", typename, (const char *) NULL);
2257 warn_stab (orig, "unrecognized C++ abbreviation");
2258 name = "INVALID_CPLUSPLUS_ABBREV";
2269 type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
2270 (debug_type **) NULL);
2278 bitpos = parse_number (pp, (boolean *) NULL);
2286 *retp = debug_make_field (dhandle, name, type, bitpos, 0,
2287 DEBUG_VISIBILITY_PRIVATE);
2288 if (*retp == DEBUG_FIELD_NULL)
2294 /* Parse a single field in a struct or union. */
2297 parse_stab_one_struct_field (dhandle, info, pp, p, retp, staticsp)
2299 struct stab_handle *info;
2307 enum debug_visibility visibility;
2314 /* FIXME: gdb checks ARM_DEMANGLING here. */
2316 name = savestring (*pp, p - *pp);
2321 visibility = DEBUG_VISIBILITY_PUBLIC;
2328 visibility = DEBUG_VISIBILITY_PRIVATE;
2331 visibility = DEBUG_VISIBILITY_PROTECTED;
2334 visibility = DEBUG_VISIBILITY_PUBLIC;
2337 warn_stab (orig, "unknown visibility character for field");
2338 visibility = DEBUG_VISIBILITY_PUBLIC;
2344 type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
2345 (debug_type **) NULL);
2346 if (type == DEBUG_TYPE_NULL)
2353 /* This is a static class member. */
2355 p = strchr (*pp, ';');
2362 varname = savestring (*pp, p - *pp);
2366 *retp = debug_make_static_member (dhandle, name, type, varname,
2380 bitpos = parse_number (pp, (boolean *) NULL);
2388 bitsize = parse_number (pp, (boolean *) NULL);
2396 if (bitpos == 0 && bitsize == 0)
2398 /* This can happen in two cases: (1) at least for gcc 2.4.5 or
2399 so, it is a field which has been optimized out. The correct
2400 stab for this case is to use VISIBILITY_IGNORE, but that is a
2401 recent invention. (2) It is a 0-size array. For example
2402 union { int num; char str[0]; } foo. Printing "<no value>"
2403 for str in "p foo" is OK, since foo.str (and thus foo.str[3])
2404 will continue to work, and a 0-size array as a whole doesn't
2405 have any contents to print.
2407 I suspect this probably could also happen with gcc -gstabs
2408 (not -gstabs+) for static fields, and perhaps other C++
2409 extensions. Hopefully few people use -gstabs with gdb, since
2410 it is intended for dbx compatibility. */
2411 visibility = DEBUG_VISIBILITY_IGNORE;
2414 /* FIXME: gdb does some stuff here to mark fields as unpacked. */
2416 *retp = debug_make_field (dhandle, name, type, bitpos, bitsize, visibility);
2421 /* Read member function stabs info for C++ classes. The form of each member
2424 NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;
2426 An example with two member functions is:
2428 afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;
2430 For the case of overloaded operators, the format is op$::*.funcs, where
2431 $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
2432 name (such as `+=') and `.' marks the end of the operator name. */
2435 parse_stab_members (dhandle, info, pp, retp)
2437 struct stab_handle *info;
2439 debug_method **retp;
2442 debug_method *methods;
2458 debug_method_variant *variants;
2460 unsigned int allocvars;
2461 debug_type look_ahead_type;
2463 p = strchr (*pp, ':');
2464 if (p == NULL || p[1] != ':')
2467 /* FIXME: Some systems use something other than '$' here. */
2468 if ((*pp)[0] != 'o' || (*pp)[1] != 'p' || (*pp)[2] != '$')
2470 name = savestring (*pp, p - *pp);
2475 /* This is a completely wierd case. In order to stuff in the
2476 names that might contain colons (the usual name delimiter),
2477 Mike Tiemann defined a different name format which is
2478 signalled if the identifier is "op$". In that case, the
2479 format is "op$::XXXX." where XXXX is the name. This is
2480 used for names like "+" or "=". YUUUUUUUK! FIXME! */
2482 for (p = *pp; *p != '.' && *p != '\0'; p++)
2489 name = savestring (*pp, p - *pp);
2494 variants = ((debug_method_variant *)
2495 xmalloc (allocvars * sizeof *variants));
2498 look_ahead_type = DEBUG_TYPE_NULL;
2504 enum debug_visibility visibility;
2505 boolean constp, volatilep, staticp;
2509 if (look_ahead_type != DEBUG_TYPE_NULL)
2511 /* g++ version 1 kludge */
2512 type = look_ahead_type;
2513 look_ahead_type = DEBUG_TYPE_NULL;
2517 type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
2518 (debug_type **) NULL);
2519 if (type == DEBUG_TYPE_NULL)
2529 p = strchr (*pp, ';');
2536 /* FIXME: gdb sets is_stub here. */
2538 argtypes = savestring (*pp, p - *pp);
2544 visibility = DEBUG_VISIBILITY_PRIVATE;
2547 visibility = DEBUG_VISIBILITY_PROTECTED;
2550 visibility = DEBUG_VISIBILITY_PUBLIC;
2560 /* Normal function. */
2564 /* const member function. */
2569 /* volatile member function. */
2574 /* const volatile member function. */
2582 /* File compiled with g++ version 1; no information. */
2585 warn_stab (orig, "const/volatile indicator missing");
2593 /* virtual member function, followed by index. The sign
2594 bit is set to distinguish pointers-to-methods from
2595 virtual function indicies. Since the array is in
2596 words, the quantity must be shifted left by 1 on 16
2597 bit machine, and by 2 on 32 bit machine, forcing the
2598 sign bit out, and usable as a valid index into the
2599 array. Remove the sign bit here. */
2601 voffset = parse_number (pp, (boolean *) NULL);
2608 voffset &= 0x7fffffff;
2611 if (**pp == ';' || *pp == '\0')
2613 /* Must be g++ version 1. */
2614 context = DEBUG_TYPE_NULL;
2618 /* Figure out from whence this virtual function
2619 came. It may belong to virtual function table of
2620 one of its baseclasses. */
2621 look_ahead_type = parse_stab_type (dhandle, info,
2622 (const char *) NULL,
2624 (debug_type **) NULL);
2627 /* g++ version 1 overloaded methods. */
2631 context = look_ahead_type;
2632 look_ahead_type = DEBUG_TYPE_NULL;
2644 /* static member function. */
2648 /* FIXME: gdb sets is_stub here. */
2649 context = DEBUG_TYPE_NULL;
2653 warn_stab (orig, "member function type missing");
2655 context = DEBUG_TYPE_NULL;
2661 context = DEBUG_TYPE_NULL;
2665 if (cvars + 1 >= allocvars)
2668 variants = ((debug_method_variant *)
2669 xrealloc ((PTR) variants,
2670 allocvars * sizeof *variants));
2674 variants[cvars] = debug_make_method_variant (dhandle, argtypes,
2679 variants[cvars] = debug_make_static_method_variant (dhandle,
2685 if (variants[cvars] == DEBUG_METHOD_VARIANT_NULL)
2690 while (**pp != ';' && **pp != '\0');
2692 variants[cvars] = DEBUG_METHOD_VARIANT_NULL;
2700 methods = ((debug_method *)
2701 xrealloc ((PTR) methods, alloc * sizeof *methods));
2704 methods[c] = debug_make_method (dhandle, name, variants);
2709 if (methods != NULL)
2710 methods[c] = DEBUG_METHOD_NULL;
2717 /* The tail end of stabs for C++ classes that contain a virtual function
2718 pointer contains a tilde, a %, and a type number.
2719 The type number refers to the base class (possibly this class itself) which
2720 contains the vtable pointer for the current class.
2722 This function is called when we have parsed all the method declarations,
2723 so we can look for the vptr base class info. */
2726 parse_stab_tilde_field (dhandle, info, pp, typenums, retvptrbase, retownvptr)
2728 struct stab_handle *info;
2730 const int *typenums;
2731 debug_type *retvptrbase;
2732 boolean *retownvptr;
2738 *retvptrbase = DEBUG_TYPE_NULL;
2739 *retownvptr = false;
2743 /* If we are positioned at a ';', then skip it. */
2752 if (**pp == '=' || **pp == '+' || **pp == '-')
2754 /* Obsolete flags that used to indicate the presence of
2755 constructors and/or destructors. */
2766 /* The next number is the type number of the base class (possibly
2767 our own class) which supplies the vtable for this class. */
2768 if (! parse_stab_type_number (pp, vtypenums))
2771 if (vtypenums[0] == typenums[0]
2772 && vtypenums[1] == typenums[1])
2781 vtype = parse_stab_type (dhandle, info, (const char *) NULL, pp,
2782 (debug_type **) NULL);
2783 for (p = *pp; *p != ';' && *p != '\0'; p++)
2791 *retvptrbase = vtype;
2799 /* Read a definition of an array type. */
2802 parse_stab_array_type (dhandle, info, pp, stringp)
2804 struct stab_handle *info;
2809 debug_type index_type;
2811 bfd_signed_vma lower, upper;
2812 debug_type element_type;
2814 /* Format of an array type:
2815 "ar<index type>;lower;upper;<array_contents_type>".
2816 OS9000: "arlower,upper;<array_contents_type>".
2818 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
2819 for these, produce a type like float[][]. */
2823 /* FIXME: gdb checks os9k_stabs here. */
2825 index_type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
2826 (debug_type **) NULL);
2830 return DEBUG_TYPE_NULL;
2836 if (! isdigit ((unsigned char) **pp) && **pp != '-')
2842 lower = (bfd_signed_vma) parse_number (pp, (boolean *) NULL);
2850 if (! isdigit ((unsigned char) **pp) && **pp != '-')
2856 upper = (bfd_signed_vma) parse_number (pp, (boolean *) NULL);
2864 element_type = parse_stab_type (dhandle, info, (const char *) NULL, pp,
2865 (debug_type **) NULL);
2866 if (element_type == DEBUG_TYPE_NULL)
2875 return debug_make_array_type (dhandle, element_type, index_type, lower,
2879 /* Keep a stack of N_BINCL include files. */
2883 struct bincl_file *next;
2887 /* Start a new N_BINCL file, pushing it onto the stack. */
2890 push_bincl (info, name)
2891 struct stab_handle *info;
2894 struct bincl_file *n;
2896 n = (struct bincl_file *) xmalloc (sizeof *n);
2897 n->next = info->bincl_stack;
2899 info->bincl_stack = n;
2902 info->file_types = ((struct stab_types **)
2903 xrealloc ((PTR) info->file_types,
2905 * sizeof *info->file_types)));
2906 info->file_types[info->files - 1] = NULL;
2909 /* Finish an N_BINCL file, at an N_EINCL, popping the name off the
2914 struct stab_handle *info;
2916 struct bincl_file *o;
2918 o = info->bincl_stack;
2920 return info->main_filename;
2921 info->bincl_stack = o->next;
2923 if (info->bincl_stack == NULL)
2924 return info->main_filename;
2925 return info->bincl_stack->name;
2928 /* Handle a variable definition. gcc emits variable definitions for a
2929 block before the N_LBRAC, so we must hold onto them until we see
2930 it. The SunPRO compiler emits variable definitions after the
2931 N_LBRAC, so we can call debug_record_variable immediately. */
2934 stab_record_variable (dhandle, info, name, type, kind, val)
2936 struct stab_handle *info;
2939 enum debug_var_kind kind;
2942 struct stab_pending_var *v;
2944 if (! info->within_function
2945 || (info->gcc_compiled == 0 && info->n_opt_found))
2946 return debug_record_variable (dhandle, name, type, kind, val);
2948 v = (struct stab_pending_var *) xmalloc (sizeof *v);
2949 memset (v, 0, sizeof *v);
2951 v->next = info->pending;
2961 /* Emit pending variable definitions. This is called after we see the
2962 N_LBRAC that starts the block. */
2965 stab_emit_pending_vars (dhandle, info)
2967 struct stab_handle *info;
2969 struct stab_pending_var *v;
2974 struct stab_pending_var *next;
2976 if (! debug_record_variable (dhandle, v->name, v->type, v->kind, v->val))
2984 info->pending = NULL;
2989 /* Find the slot for a type in the database. */
2992 stab_find_slot (info, typenums)
2993 struct stab_handle *info;
2994 const int *typenums;
2998 struct stab_types **ps;
3000 filenum = typenums[0];
3001 index = typenums[1];
3003 if (filenum < 0 || (unsigned int) filenum >= info->files)
3005 fprintf (stderr, "Type file number %d out of range\n", filenum);
3010 fprintf (stderr, "Type index number %d out of range\n", index);
3014 ps = info->file_types + filenum;
3016 while (index >= STAB_TYPES_SLOTS)
3020 *ps = (struct stab_types *) xmalloc (sizeof **ps);
3021 memset (*ps, 0, sizeof **ps);
3024 index -= STAB_TYPES_SLOTS;
3028 *ps = (struct stab_types *) xmalloc (sizeof **ps);
3029 memset (*ps, 0, sizeof **ps);
3032 return (*ps)->types + index;
3035 /* Find a type given a type number. If the type has not been
3036 allocated yet, create an indirect type. */
3039 stab_find_type (dhandle, info, typenums)
3041 struct stab_handle *info;
3042 const int *typenums;
3046 if (typenums[0] == 0 && typenums[1] < 0)
3048 /* A negative type number indicates an XCOFF builtin type. */
3049 return stab_xcoff_builtin_type (dhandle, info, typenums[1]);
3052 slot = stab_find_slot (info, typenums);
3054 return DEBUG_TYPE_NULL;
3056 if (*slot == DEBUG_TYPE_NULL)
3057 return debug_make_indirect_type (dhandle, slot, (const char *) NULL);
3062 /* Record that a given type number refers to a given type. */
3065 stab_record_type (dhandle, info, typenums, type)
3067 struct stab_handle *info;
3068 const int *typenums;
3073 slot = stab_find_slot (info, typenums);
3077 /* gdb appears to ignore type redefinitions, so we do as well. */
3084 /* Return an XCOFF builtin type. */
3087 stab_xcoff_builtin_type (dhandle, info, typenum)
3089 struct stab_handle *info;
3095 if (typenum >= 0 || typenum < -XCOFF_TYPE_COUNT)
3097 fprintf (stderr, "Unrecognized XCOFF type %d\n", typenum);
3098 return DEBUG_TYPE_NULL;
3100 if (info->xcoff_types[-typenum] != NULL)
3101 return info->xcoff_types[-typenum];
3106 /* The size of this and all the other types are fixed, defined
3107 by the debugging format. */
3109 rettype = debug_make_int_type (dhandle, 4, false);
3113 rettype = debug_make_int_type (dhandle, 1, false);
3117 rettype = debug_make_int_type (dhandle, 2, false);
3121 rettype = debug_make_int_type (dhandle, 4, false);
3124 name = "unsigned char";
3125 rettype = debug_make_int_type (dhandle, 1, true);
3128 name = "signed char";
3129 rettype = debug_make_int_type (dhandle, 1, false);
3132 name = "unsigned short";
3133 rettype = debug_make_int_type (dhandle, 2, true);
3136 name = "unsigned int";
3137 rettype = debug_make_int_type (dhandle, 4, true);
3141 rettype = debug_make_int_type (dhandle, 4, true);
3143 name = "unsigned long";
3144 rettype = debug_make_int_type (dhandle, 4, true);
3148 rettype = debug_make_void_type (dhandle);
3151 /* IEEE single precision (32 bit). */
3153 rettype = debug_make_float_type (dhandle, 4);
3156 /* IEEE double precision (64 bit). */
3158 rettype = debug_make_float_type (dhandle, 8);
3161 /* This is an IEEE double on the RS/6000, and different machines
3162 with different sizes for "long double" should use different
3163 negative type numbers. See stabs.texinfo. */
3164 name = "long double";
3165 rettype = debug_make_float_type (dhandle, 8);
3169 rettype = debug_make_int_type (dhandle, 4, false);
3173 rettype = debug_make_bool_type (dhandle, 4);
3176 name = "short real";
3177 rettype = debug_make_float_type (dhandle, 4);
3181 rettype = debug_make_float_type (dhandle, 8);
3191 rettype = debug_make_int_type (dhandle, 1, true);
3195 rettype = debug_make_bool_type (dhandle, 1);
3199 rettype = debug_make_bool_type (dhandle, 2);
3203 rettype = debug_make_bool_type (dhandle, 4);
3207 rettype = debug_make_bool_type (dhandle, 4);
3210 /* Complex type consisting of two IEEE single precision values. */
3212 rettype = debug_make_complex_type (dhandle, 8);
3215 /* Complex type consisting of two IEEE double precision values. */
3216 name = "double complex";
3217 rettype = debug_make_complex_type (dhandle, 16);
3221 rettype = debug_make_int_type (dhandle, 1, false);
3225 rettype = debug_make_int_type (dhandle, 2, false);
3229 rettype = debug_make_int_type (dhandle, 4, false);
3234 rettype = debug_make_int_type (dhandle, 2, false);
3238 rettype = debug_make_int_type (dhandle, 8, false);
3241 name = "unsigned long long";
3242 rettype = debug_make_int_type (dhandle, 8, true);
3246 rettype = debug_make_bool_type (dhandle, 8);
3250 rettype = debug_make_int_type (dhandle, 8, false);
3256 rettype = debug_name_type (dhandle, name, rettype);
3258 info->xcoff_types[-typenum] = rettype;