1 /* Support routines for decoding "stabs" debugging information format.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
3 1996, 1997, 1998, 1999, 2000, 2001, 2002
4 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
23 /* Support routines for reading and decoding debugging information in
24 the "stabs" format. This format is used with many systems that use
25 the a.out object file format, as well as some systems that use
26 COFF or ELF where the stabs data is placed in a special section.
27 Avoid placing any object file format specific code in this file. */
30 #include "gdb_string.h"
32 #include "gdb_obstack.h"
35 #include "expression.h"
38 #include "aout/stab_gnu.h" /* We always use GNU stabs, not native */
40 #include "aout/aout64.h"
41 #include "gdb-stabs.h"
43 #include "complaints.h"
48 #include "cp-support.h"
52 /* Ask stabsread.h to define the vars it normally declares `extern'. */
55 #include "stabsread.h" /* Our own declarations */
58 extern void _initialize_stabsread (void);
60 /* The routines that read and process a complete stabs for a C struct or
61 C++ class pass lists of data member fields and lists of member function
62 fields in an instance of a field_info structure, as defined below.
63 This is part of some reorganization of low level C++ support and is
64 expected to eventually go away... (FIXME) */
70 struct nextfield *next;
72 /* This is the raw visibility from the stab. It is not checked
73 for being one of the visibilities we recognize, so code which
74 examines this field better be able to deal. */
80 struct next_fnfieldlist
82 struct next_fnfieldlist *next;
83 struct fn_fieldlist fn_fieldlist;
89 read_one_struct_field (struct field_info *, char **, char *,
90 struct type *, struct objfile *);
92 static char *get_substring (char **, int);
94 static struct type *dbx_alloc_type (int[2], struct objfile *);
96 static long read_huge_number (char **, int, int *);
98 static struct type *error_type (char **, struct objfile *);
101 patch_block_stabs (struct pending *, struct pending_stabs *,
104 static void fix_common_block (struct symbol *, int);
106 static int read_type_number (char **, int *);
108 static struct type *read_range_type (char **, int[2], struct objfile *);
110 static struct type *read_sun_builtin_type (char **, int[2], struct objfile *);
112 static struct type *read_sun_floating_type (char **, int[2],
115 static struct type *read_enum_type (char **, struct type *, struct objfile *);
117 static struct type *rs6000_builtin_type (int);
120 read_member_functions (struct field_info *, char **, struct type *,
124 read_struct_fields (struct field_info *, char **, struct type *,
128 read_baseclasses (struct field_info *, char **, struct type *,
132 read_tilde_fields (struct field_info *, char **, struct type *,
135 static int attach_fn_fields_to_type (struct field_info *, struct type *);
138 attach_fields_to_type (struct field_info *, struct type *, struct objfile *);
140 static struct type *read_struct_type (char **, struct type *,
144 static struct type *read_array_type (char **, struct type *,
147 static struct field *read_args (char **, int, struct objfile *, int *, int *);
150 read_cpp_abbrev (struct field_info *, char **, struct type *,
153 /* new functions added for cfront support */
156 copy_cfront_struct_fields (struct field_info *, struct type *,
159 static char *get_cfront_method_physname (char *);
162 read_cfront_baseclasses (struct field_info *, char **,
163 struct type *, struct objfile *);
166 read_cfront_static_fields (struct field_info *, char **,
167 struct type *, struct objfile *);
169 read_cfront_member_functions (struct field_info *, char **,
170 struct type *, struct objfile *);
172 /* end new functions added for cfront support */
175 add_live_range (struct objfile *, struct symbol *, CORE_ADDR, CORE_ADDR);
177 static int resolve_live_range (struct objfile *, struct symbol *, char *);
179 static int process_reference (char **string);
181 static CORE_ADDR ref_search_value (int refnum);
184 resolve_symbol_reference (struct objfile *, struct symbol *, char *);
186 void stabsread_clear_cache (void);
188 static const char vptr_name[] =
189 {'_', 'v', 'p', 't', 'r', CPLUS_MARKER, '\0'};
190 static const char vb_name[] =
191 {'_', 'v', 'b', CPLUS_MARKER, '\0'};
193 /* Define this as 1 if a pcc declaration of a char or short argument
194 gives the correct address. Otherwise assume pcc gives the
195 address of the corresponding int, which is not the same on a
196 big-endian machine. */
198 #if !defined (BELIEVE_PCC_PROMOTION)
199 #define BELIEVE_PCC_PROMOTION 0
201 #if !defined (BELIEVE_PCC_PROMOTION_TYPE)
202 #define BELIEVE_PCC_PROMOTION_TYPE 0
205 static struct complaint invalid_cpp_abbrev_complaint =
206 {"invalid C++ abbreviation `%s'", 0, 0};
208 static struct complaint invalid_cpp_type_complaint =
209 {"C++ abbreviated type name unknown at symtab pos %d", 0, 0};
211 static struct complaint member_fn_complaint =
212 {"member function type missing, got '%c'", 0, 0};
214 static struct complaint const_vol_complaint =
215 {"const/volatile indicator missing, got '%c'", 0, 0};
217 static struct complaint error_type_complaint =
218 {"couldn't parse type; debugger out of date?", 0, 0};
220 static struct complaint invalid_member_complaint =
221 {"invalid (minimal) member type data format at symtab pos %d.", 0, 0};
223 static struct complaint range_type_base_complaint =
224 {"base type %d of range type is not defined", 0, 0};
226 static struct complaint reg_value_complaint =
227 {"register number %d too large (max %d) in symbol %s", 0, 0};
229 static struct complaint vtbl_notfound_complaint =
230 {"virtual function table pointer not found when defining class `%s'", 0, 0};
232 static struct complaint unrecognized_cplus_name_complaint =
233 {"Unknown C++ symbol name `%s'", 0, 0};
235 static struct complaint rs6000_builtin_complaint =
236 {"Unknown builtin type %d", 0, 0};
238 static struct complaint unresolved_sym_chain_complaint =
239 {"%s: common block `%s' from global_sym_chain unresolved", 0, 0};
241 static struct complaint stabs_general_complaint =
244 static struct complaint lrs_general_complaint =
247 /* Make a list of forward references which haven't been defined. */
249 static struct type **undef_types;
250 static int undef_types_allocated;
251 static int undef_types_length;
252 static struct symbol *current_symbol = NULL;
254 /* Check for and handle cretinous stabs symbol name continuation! */
255 #define STABS_CONTINUE(pp,objfile) \
257 if (**(pp) == '\\' || (**(pp) == '?' && (*(pp))[1] == '\0')) \
258 *(pp) = next_symbol_text (objfile); \
261 #if 0 /* OBSOLETE OS9K */
262 // OBSOLETE /* FIXME: These probably should be our own types (like rs6000_builtin_type
263 // OBSOLETE has its own types) rather than builtin_type_*. */
264 // OBSOLETE static struct type **os9k_type_vector[] =
267 // OBSOLETE &builtin_type_int,
268 // OBSOLETE &builtin_type_char,
269 // OBSOLETE &builtin_type_long,
270 // OBSOLETE &builtin_type_short,
271 // OBSOLETE &builtin_type_unsigned_char,
272 // OBSOLETE &builtin_type_unsigned_short,
273 // OBSOLETE &builtin_type_unsigned_long,
274 // OBSOLETE &builtin_type_unsigned_int,
275 // OBSOLETE &builtin_type_float,
276 // OBSOLETE &builtin_type_double,
277 // OBSOLETE &builtin_type_void,
278 // OBSOLETE &builtin_type_long_double
281 // OBSOLETE static void os9k_init_type_vector (struct type **);
283 // OBSOLETE static void
284 // OBSOLETE os9k_init_type_vector (struct type **tv)
286 // OBSOLETE unsigned int i;
287 // OBSOLETE for (i = 0; i < sizeof (os9k_type_vector) / sizeof (struct type **); i++)
288 // OBSOLETE tv[i] = (os9k_type_vector[i] == 0 ? 0 : *(os9k_type_vector[i]));
290 #endif /* OBSOLETE OS9K */
292 /* Look up a dbx type-number pair. Return the address of the slot
293 where the type for that number-pair is stored.
294 The number-pair is in TYPENUMS.
296 This can be used for finding the type associated with that pair
297 or for associating a new type with the pair. */
300 dbx_lookup_type (int typenums[2])
302 register int filenum = typenums[0];
303 register int index = typenums[1];
305 register int real_filenum;
306 register struct header_file *f;
309 if (filenum == -1) /* -1,-1 is for temporary types. */
312 if (filenum < 0 || filenum >= n_this_object_header_files)
314 static struct complaint msg =
316 Invalid symbol data: type number (%d,%d) out of range at symtab pos %d.",
318 complain (&msg, filenum, index, symnum);
326 /* Caller wants address of address of type. We think
327 that negative (rs6k builtin) types will never appear as
328 "lvalues", (nor should they), so we stuff the real type
329 pointer into a temp, and return its address. If referenced,
330 this will do the right thing. */
331 static struct type *temp_type;
333 temp_type = rs6000_builtin_type (index);
337 /* Type is defined outside of header files.
338 Find it in this object file's type vector. */
339 if (index >= type_vector_length)
341 old_len = type_vector_length;
344 type_vector_length = INITIAL_TYPE_VECTOR_LENGTH;
345 type_vector = (struct type **)
346 xmalloc (type_vector_length * sizeof (struct type *));
348 while (index >= type_vector_length)
350 type_vector_length *= 2;
352 type_vector = (struct type **)
353 xrealloc ((char *) type_vector,
354 (type_vector_length * sizeof (struct type *)));
355 memset (&type_vector[old_len], 0,
356 (type_vector_length - old_len) * sizeof (struct type *));
358 #if 0 /* OBSOLETE OS9K */
359 // OBSOLETE if (os9k_stabs)
360 // OBSOLETE /* Deal with OS9000 fundamental types. */
361 // OBSOLETE os9k_init_type_vector (type_vector);
362 #endif /* OBSOLETE OS9K */
364 return (&type_vector[index]);
368 real_filenum = this_object_header_files[filenum];
370 if (real_filenum >= N_HEADER_FILES (current_objfile))
372 struct type *temp_type;
373 struct type **temp_type_p;
375 warning ("GDB internal error: bad real_filenum");
378 temp_type = init_type (TYPE_CODE_ERROR, 0, 0, NULL, NULL);
379 temp_type_p = (struct type **) xmalloc (sizeof (struct type *));
380 *temp_type_p = temp_type;
384 f = HEADER_FILES (current_objfile) + real_filenum;
386 f_orig_length = f->length;
387 if (index >= f_orig_length)
389 while (index >= f->length)
393 f->vector = (struct type **)
394 xrealloc ((char *) f->vector, f->length * sizeof (struct type *));
395 memset (&f->vector[f_orig_length], 0,
396 (f->length - f_orig_length) * sizeof (struct type *));
398 return (&f->vector[index]);
402 /* Make sure there is a type allocated for type numbers TYPENUMS
403 and return the type object.
404 This can create an empty (zeroed) type object.
405 TYPENUMS may be (-1, -1) to return a new type object that is not
406 put into the type vector, and so may not be referred to by number. */
409 dbx_alloc_type (int typenums[2], struct objfile *objfile)
411 register struct type **type_addr;
413 if (typenums[0] == -1)
415 return (alloc_type (objfile));
418 type_addr = dbx_lookup_type (typenums);
420 /* If we are referring to a type not known at all yet,
421 allocate an empty type for it.
422 We will fill it in later if we find out how. */
425 *type_addr = alloc_type (objfile);
431 /* for all the stabs in a given stab vector, build appropriate types
432 and fix their symbols in given symbol vector. */
435 patch_block_stabs (struct pending *symbols, struct pending_stabs *stabs,
436 struct objfile *objfile)
446 /* for all the stab entries, find their corresponding symbols and
447 patch their types! */
449 for (ii = 0; ii < stabs->count; ++ii)
451 name = stabs->stab[ii];
452 pp = (char *) strchr (name, ':');
456 pp = (char *) strchr (pp, ':');
458 sym = find_symbol_in_list (symbols, name, pp - name);
461 /* FIXME-maybe: it would be nice if we noticed whether
462 the variable was defined *anywhere*, not just whether
463 it is defined in this compilation unit. But neither
464 xlc or GCC seem to need such a definition, and until
465 we do psymtabs (so that the minimal symbols from all
466 compilation units are available now), I'm not sure
467 how to get the information. */
469 /* On xcoff, if a global is defined and never referenced,
470 ld will remove it from the executable. There is then
471 a N_GSYM stab for it, but no regular (C_EXT) symbol. */
472 sym = (struct symbol *)
473 obstack_alloc (&objfile->symbol_obstack,
474 sizeof (struct symbol));
476 memset (sym, 0, sizeof (struct symbol));
477 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
478 SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
480 obsavestring (name, pp - name, &objfile->symbol_obstack);
482 if (*(pp - 1) == 'F' || *(pp - 1) == 'f')
484 /* I don't think the linker does this with functions,
485 so as far as I know this is never executed.
486 But it doesn't hurt to check. */
488 lookup_function_type (read_type (&pp, objfile));
492 SYMBOL_TYPE (sym) = read_type (&pp, objfile);
494 add_symbol_to_list (sym, &global_symbols);
499 if (*(pp - 1) == 'F' || *(pp - 1) == 'f')
502 lookup_function_type (read_type (&pp, objfile));
506 SYMBOL_TYPE (sym) = read_type (&pp, objfile);
514 /* Read a number by which a type is referred to in dbx data,
515 or perhaps read a pair (FILENUM, TYPENUM) in parentheses.
516 Just a single number N is equivalent to (0,N).
517 Return the two numbers by storing them in the vector TYPENUMS.
518 TYPENUMS will then be used as an argument to dbx_lookup_type.
520 Returns 0 for success, -1 for error. */
523 read_type_number (register char **pp, register int *typenums)
529 typenums[0] = read_huge_number (pp, ',', &nbits);
532 typenums[1] = read_huge_number (pp, ')', &nbits);
539 typenums[1] = read_huge_number (pp, 0, &nbits);
547 #define VISIBILITY_PRIVATE '0' /* Stabs character for private field */
548 #define VISIBILITY_PROTECTED '1' /* Stabs character for protected fld */
549 #define VISIBILITY_PUBLIC '2' /* Stabs character for public field */
550 #define VISIBILITY_IGNORE '9' /* Optimized out or zero length */
552 #define CFRONT_VISIBILITY_PRIVATE '2' /* Stabs character for private field */
553 #define CFRONT_VISIBILITY_PUBLIC '1' /* Stabs character for public field */
555 /* This code added to support parsing of ARM/Cfront stabs strings */
557 /* Get substring from string up to char c, advance string pointer past
561 get_substring (char **p, int c)
576 /* Physname gets strcat'd onto sname in order to recreate the mangled
577 name (see funtion gdb_mangle_name in gdbtypes.c). For cfront, make
578 the physname look like that of g++ - take out the initial mangling
579 eg: for sname="a" and fname="foo__1aFPFs_i" return "FPFs_i" */
582 get_cfront_method_physname (char *fname)
585 /* FIXME would like to make this generic for g++ too, but
586 that is already handled in read_member_funcctions */
589 /* search ahead to find the start of the mangled suffix */
590 if (*p == '_' && *(p + 1) == '_') /* compiler generated; probably a ctor/dtor */
592 while (p && (unsigned) ((p + 1) - fname) < strlen (fname) && *(p + 1) != '_')
594 if (!(p && *p == '_' && *(p + 1) == '_'))
595 error ("Invalid mangled function name %s", fname);
596 p += 2; /* advance past '__' */
598 /* struct name length and name of type should come next; advance past it */
601 len = len * 10 + (*p - '0');
609 /* Read base classes within cfront class definition.
610 eg: A:ZcA;1@Bpub v2@Bvirpri;__ct__1AFv func__1AFv *sfunc__1AFv ;as__1A ;;
613 A:ZcA;;foopri__1AFv foopro__1AFv __ct__1AFv __ct__1AFRC1A foopub__1AFv ;;;
618 read_cfront_baseclasses (struct field_info *fip, char **pp, struct type *type,
619 struct objfile *objfile)
621 static struct complaint msg_unknown =
623 Unsupported token in stabs string %s.\n",
625 static struct complaint msg_notfound =
627 Unable to find base type for %s.\n",
632 struct nextfield *new;
634 if (**pp == ';') /* no base classes; return */
640 /* first count base classes so we can allocate space before parsing */
641 for (p = *pp; p && *p && *p != ';'; p++)
646 bnum++; /* add one more for last one */
648 /* now parse the base classes until we get to the start of the methods
649 (code extracted and munged from read_baseclasses) */
650 ALLOCATE_CPLUS_STRUCT_TYPE (type);
651 TYPE_N_BASECLASSES (type) = bnum;
655 int num_bytes = B_BYTES (TYPE_N_BASECLASSES (type));
658 pointer = (char *) TYPE_ALLOC (type, num_bytes);
659 TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *) pointer;
661 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), TYPE_N_BASECLASSES (type));
663 for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
665 new = (struct nextfield *) xmalloc (sizeof (struct nextfield));
666 make_cleanup (xfree, new);
667 memset (new, 0, sizeof (struct nextfield));
668 new->next = fip->list;
670 FIELD_BITSIZE (new->field) = 0; /* this should be an unpacked field! */
672 STABS_CONTINUE (pp, objfile);
674 /* virtual? eg: v2@Bvir */
677 SET_TYPE_FIELD_VIRTUAL (type, i);
681 /* access? eg: 2@Bvir */
682 /* Note: protected inheritance not supported in cfront */
685 case CFRONT_VISIBILITY_PRIVATE:
686 new->visibility = VISIBILITY_PRIVATE;
688 case CFRONT_VISIBILITY_PUBLIC:
689 new->visibility = VISIBILITY_PUBLIC;
692 /* Bad visibility format. Complain and treat it as
695 static struct complaint msg =
697 "Unknown visibility `%c' for baseclass", 0, 0};
698 complain (&msg, new->visibility);
699 new->visibility = VISIBILITY_PUBLIC;
703 /* "@" comes next - eg: @Bvir */
706 complain (&msg_unknown, *pp);
712 /* Set the bit offset of the portion of the object corresponding
713 to this baseclass. Always zero in the absence of
714 multiple inheritance. */
715 /* Unable to read bit position from stabs;
716 Assuming no multiple inheritance for now FIXME! */
717 /* We may have read this in the structure definition;
718 now we should fixup the members to be the actual base classes */
719 FIELD_BITPOS (new->field) = 0;
721 /* Get the base class name and type */
723 char *bname; /* base class name */
724 struct symbol *bsym; /* base class */
726 p1 = strchr (*pp, ' ');
727 p2 = strchr (*pp, ';');
729 bname = get_substring (pp, ' ');
731 bname = get_substring (pp, ';');
732 if (!bname || !*bname)
734 complain (&msg_unknown, *pp);
737 /* FIXME! attach base info to type */
738 bsym = lookup_symbol (bname, 0, STRUCT_NAMESPACE, 0, 0); /*demangled_name */
741 new->field.type = SYMBOL_TYPE (bsym);
742 new->field.name = type_name_no_tag (new->field.type);
746 complain (&msg_notfound, *pp);
751 /* If more base classes to parse, loop again.
752 We ate the last ' ' or ';' in get_substring,
753 so on exit we will have skipped the trailing ';' */
754 /* if invalid, return 0; add code to detect - FIXME! */
759 /* read cfront member functions.
760 pp points to string starting with list of functions
761 eg: A:ZcA;1@Bpub v2@Bvirpri;__ct__1AFv func__1AFv *sfunc__1AFv ;as__1A ;;
762 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
763 A:ZcA;;foopri__1AFv foopro__1AFv __ct__1AFv __ct__1AFRC1A foopub__1AFv ;;;
764 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
768 read_cfront_member_functions (struct field_info *fip, char **pp,
769 struct type *type, struct objfile *objfile)
771 /* This code extracted from read_member_functions
772 so as to do the similar thing for our funcs */
776 /* Total number of member functions defined in this class. If the class
777 defines two `f' functions, and one `g' function, then this will have
779 int total_length = 0;
783 struct next_fnfield *next;
784 struct fn_field fn_field;
787 struct type *look_ahead_type;
788 struct next_fnfieldlist *new_fnlist;
789 struct next_fnfield *new_sublist;
792 struct symbol *ref_func = 0;
794 /* Process each list until we find the end of the member functions.
795 eg: p = "__ct__1AFv foo__1AFv ;;;" */
797 STABS_CONTINUE (pp, objfile); /* handle \\ */
799 while (**pp != ';' && (fname = get_substring (pp, ' '), fname))
802 int sublist_count = 0;
804 if (fname[0] == '*') /* static member */
810 ref_func = lookup_symbol (fname, 0, VAR_NAMESPACE, 0, 0); /* demangled name */
813 static struct complaint msg =
815 Unable to find function symbol for %s\n",
817 complain (&msg, fname);
821 look_ahead_type = NULL;
824 new_fnlist = (struct next_fnfieldlist *)
825 xmalloc (sizeof (struct next_fnfieldlist));
826 make_cleanup (xfree, new_fnlist);
827 memset (new_fnlist, 0, sizeof (struct next_fnfieldlist));
829 /* The following is code to work around cfront generated stabs.
830 The stabs contains full mangled name for each field.
831 We try to demangle the name and extract the field name out of it. */
833 char *dem, *dem_p, *dem_args;
835 dem = cplus_demangle (fname, DMGL_ANSI | DMGL_PARAMS);
838 dem_p = strrchr (dem, ':');
839 if (dem_p != 0 && *(dem_p - 1) == ':')
841 /* get rid of args */
842 dem_args = strchr (dem_p, '(');
843 if (dem_args == NULL)
844 dem_len = strlen (dem_p);
846 dem_len = dem_args - dem_p;
848 obsavestring (dem_p, dem_len, &objfile->type_obstack);
853 obsavestring (fname, strlen (fname), &objfile->type_obstack);
855 } /* end of code for cfront work around */
857 new_fnlist->fn_fieldlist.name = main_fn_name;
859 /*-------------------------------------------------*/
860 /* Set up the sublists
861 Sublists are stuff like args, static, visibility, etc.
862 so in ARM, we have to set that info some other way.
863 Multiple sublists happen if overloading
864 eg: foo::26=##1;:;2A.;
865 In g++, we'd loop here thru all the sublists... */
868 (struct next_fnfield *) xmalloc (sizeof (struct next_fnfield));
869 make_cleanup (xfree, new_sublist);
870 memset (new_sublist, 0, sizeof (struct next_fnfield));
872 /* eat 1; from :;2A.; */
873 new_sublist->fn_field.type = SYMBOL_TYPE (ref_func); /* normally takes a read_type */
874 /* Make this type look like a method stub for gdb */
875 TYPE_FLAGS (new_sublist->fn_field.type) |= TYPE_FLAG_STUB;
876 TYPE_CODE (new_sublist->fn_field.type) = TYPE_CODE_METHOD;
878 /* If this is just a stub, then we don't have the real name here. */
879 if (TYPE_STUB (new_sublist->fn_field.type))
881 if (!TYPE_DOMAIN_TYPE (new_sublist->fn_field.type))
882 TYPE_DOMAIN_TYPE (new_sublist->fn_field.type) = type;
883 new_sublist->fn_field.is_stub = 1;
886 /* physname used later in mangling; eg PFs_i,5 for foo__1aFPFs_i
887 physname gets strcat'd in order to recreate the onto mangled name */
888 pname = get_cfront_method_physname (fname);
889 new_sublist->fn_field.physname = savestring (pname, strlen (pname));
892 /* Set this member function's visibility fields.
893 Unable to distinguish access from stabs definition!
894 Assuming public for now. FIXME!
895 (for private, set new_sublist->fn_field.is_private = 1,
896 for public, set new_sublist->fn_field.is_protected = 1) */
898 /* Unable to distinguish const/volatile from stabs definition!
899 Assuming normal for now. FIXME! */
901 new_sublist->fn_field.is_const = 0;
902 new_sublist->fn_field.is_volatile = 0; /* volatile not implemented in cfront */
904 /* Set virtual/static function info
905 How to get vtable offsets ?
906 Assuming normal for now FIXME!!
907 For vtables, figure out from whence this virtual function came.
908 It may belong to virtual function table of
909 one of its baseclasses.
911 new_sublist -> fn_field.voffset = vtable offset,
912 new_sublist -> fn_field.fcontext = look_ahead_type;
913 where look_ahead_type is type of baseclass */
915 new_sublist->fn_field.voffset = VOFFSET_STATIC;
916 else /* normal member function. */
917 new_sublist->fn_field.voffset = 0;
918 new_sublist->fn_field.fcontext = 0;
921 /* Prepare new sublist */
922 new_sublist->next = sublist;
923 sublist = new_sublist;
926 /* In g++, we loop thu sublists - now we set from functions. */
927 new_fnlist->fn_fieldlist.fn_fields = (struct fn_field *)
928 obstack_alloc (&objfile->type_obstack,
929 sizeof (struct fn_field) * length);
930 memset (new_fnlist->fn_fieldlist.fn_fields, 0,
931 sizeof (struct fn_field) * length);
932 for (i = length; (i--, sublist); sublist = sublist->next)
934 new_fnlist->fn_fieldlist.fn_fields[i] = sublist->fn_field;
937 new_fnlist->fn_fieldlist.length = length;
938 new_fnlist->next = fip->fnlist;
939 fip->fnlist = new_fnlist;
941 total_length += length;
942 STABS_CONTINUE (pp, objfile); /* handle \\ */
947 /* type should already have space */
948 TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
949 TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * nfn_fields);
950 memset (TYPE_FN_FIELDLISTS (type), 0,
951 sizeof (struct fn_fieldlist) * nfn_fields);
952 TYPE_NFN_FIELDS (type) = nfn_fields;
953 TYPE_NFN_FIELDS_TOTAL (type) = total_length;
956 /* end of scope for reading member func */
960 /* Skip trailing ';' and bump count of number of fields seen */
968 /* This routine fixes up partial cfront types that were created
969 while parsing the stabs. The main need for this function is
970 to add information such as methods to classes.
971 Examples of "p": "sA;;__ct__1AFv foo__1AFv ;;;" */
973 resolve_cfront_continuation (struct objfile *objfile, struct symbol *sym,
976 struct symbol *ref_sym = 0;
978 /* snarfed from read_struct_type */
979 struct field_info fi;
981 struct cleanup *back_to;
983 /* Need to make sure that fi isn't gunna conflict with struct
984 in case struct already had some fnfs */
987 back_to = make_cleanup (null_cleanup, 0);
989 /* We only accept structs, classes and unions at the moment.
990 Other continuation types include t (typedef), r (long dbl), ...
991 We may want to add support for them as well;
992 right now they are handled by duplicating the symbol information
993 into the type information (see define_symbol) */
994 if (*p != 's' /* structs */
995 && *p != 'c' /* class */
996 && *p != 'u') /* union */
997 return 0; /* only handle C++ types */
1000 /* Get symbol typs name and validate
1001 eg: p = "A;;__ct__1AFv foo__1AFv ;;;" */
1002 sname = get_substring (&p, ';');
1003 if (!sname || strcmp (sname, SYMBOL_NAME (sym)))
1004 error ("Internal error: base symbol type name does not match\n");
1006 /* Find symbol's internal gdb reference using demangled_name.
1007 This is the real sym that we want;
1008 sym was a temp hack to make debugger happy */
1009 ref_sym = lookup_symbol (SYMBOL_NAME (sym), 0, STRUCT_NAMESPACE, 0, 0);
1010 type = SYMBOL_TYPE (ref_sym);
1013 /* Now read the baseclasses, if any, read the regular C struct or C++
1014 class member fields, attach the fields to the type, read the C++
1015 member functions, attach them to the type, and then read any tilde
1016 field (baseclass specifier for the class holding the main vtable). */
1018 if (!read_cfront_baseclasses (&fi, &p, type, objfile)
1019 /* g++ does this next, but cfront already did this:
1020 || !read_struct_fields (&fi, &p, type, objfile) */
1021 || !copy_cfront_struct_fields (&fi, type, objfile)
1022 || !read_cfront_member_functions (&fi, &p, type, objfile)
1023 || !read_cfront_static_fields (&fi, &p, type, objfile)
1024 || !attach_fields_to_type (&fi, type, objfile)
1025 || !attach_fn_fields_to_type (&fi, type)
1026 /* g++ does this next, but cfront doesn't seem to have this:
1027 || !read_tilde_fields (&fi, &p, type, objfile) */
1030 type = error_type (&p, objfile);
1033 do_cleanups (back_to);
1036 /* End of code added to support parsing of ARM/Cfront stabs strings */
1039 /* This routine fixes up symbol references/aliases to point to the original
1040 symbol definition. Returns 0 on failure, non-zero on success. */
1043 resolve_symbol_reference (struct objfile *objfile, struct symbol *sym, char *p)
1046 struct symbol *ref_sym = 0;
1047 struct alias_list *alias;
1049 /* If this is not a symbol reference return now. */
1053 /* Use "#<num>" as the name; we'll fix the name later.
1054 We stored the original symbol name as "#<id>=<name>"
1055 so we can now search for "#<id>" to resolving the reference.
1056 We'll fix the names later by removing the "#<id>" or "#<id>=" */
1058 /*---------------------------------------------------------*/
1059 /* Get the reference id number, and
1060 advance p past the names so we can parse the rest.
1061 eg: id=2 for p : "2=", "2=z:r(0,1)" "2:r(0,1);l(#5,#6),l(#7,#4)" */
1062 /*---------------------------------------------------------*/
1064 /* This gets reference name from string. sym may not have a name. */
1066 /* Get the reference number associated with the reference id in the
1067 gdb stab string. From that reference number, get the main/primary
1068 symbol for this alias. */
1069 refnum = process_reference (&p);
1070 ref_sym = ref_search (refnum);
1073 complain (&lrs_general_complaint, "symbol for reference not found");
1077 /* Parse the stab of the referencing symbol
1078 now that we have the referenced symbol.
1079 Add it as a new symbol and a link back to the referenced symbol.
1080 eg: p : "=", "=z:r(0,1)" ":r(0,1);l(#5,#6),l(#7,#4)" */
1083 /* If the stab symbol table and string contain:
1084 RSYM 0 5 00000000 868 #15=z:r(0,1)
1085 LBRAC 0 0 00000000 899 #5=
1086 SLINE 0 16 00000003 923 #6=
1087 Then the same symbols can be later referenced by:
1088 RSYM 0 5 00000000 927 #15:r(0,1);l(#5,#6)
1089 This is used in live range splitting to:
1090 1) specify that a symbol (#15) is actually just a new storage
1091 class for a symbol (#15=z) which was previously defined.
1092 2) specify that the beginning and ending ranges for a symbol
1093 (#15) are the values of the beginning (#5) and ending (#6)
1096 /* Read number as reference id.
1097 eg: p : "=", "=z:r(0,1)" ":r(0,1);l(#5,#6),l(#7,#4)" */
1098 /* FIXME! Might I want to use SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
1099 in case of "l(0,0)"? */
1101 /*--------------------------------------------------*/
1102 /* Add this symbol to the reference list. */
1103 /*--------------------------------------------------*/
1105 alias = (struct alias_list *) obstack_alloc (&objfile->type_obstack,
1106 sizeof (struct alias_list));
1109 complain (&lrs_general_complaint, "Unable to allocate alias list memory");
1116 if (!SYMBOL_ALIASES (ref_sym))
1118 SYMBOL_ALIASES (ref_sym) = alias;
1122 struct alias_list *temp;
1124 /* Get to the end of the list. */
1125 for (temp = SYMBOL_ALIASES (ref_sym);
1132 /* Want to fix up name so that other functions (eg. valops)
1133 will correctly print the name.
1134 Don't add_symbol_to_list so that lookup_symbol won't find it.
1135 nope... needed for fixups. */
1136 SYMBOL_NAME (sym) = SYMBOL_NAME (ref_sym);
1142 /* Structure for storing pointers to reference definitions for fast lookup
1143 during "process_later". */
1152 #define MAX_CHUNK_REFS 100
1153 #define REF_CHUNK_SIZE (MAX_CHUNK_REFS * sizeof (struct ref_map))
1154 #define REF_MAP_SIZE(ref_chunk) ((ref_chunk) * REF_CHUNK_SIZE)
1156 static struct ref_map *ref_map;
1158 /* Ptr to free cell in chunk's linked list. */
1159 static int ref_count = 0;
1161 /* Number of chunks malloced. */
1162 static int ref_chunk = 0;
1164 /* This file maintains a cache of stabs aliases found in the symbol
1165 table. If the symbol table changes, this cache must be cleared
1166 or we are left holding onto data in invalid obstacks. */
1168 stabsread_clear_cache (void)
1174 /* Create array of pointers mapping refids to symbols and stab strings.
1175 Add pointers to reference definition symbols and/or their values as we
1176 find them, using their reference numbers as our index.
1177 These will be used later when we resolve references. */
1179 ref_add (int refnum, struct symbol *sym, char *stabs, CORE_ADDR value)
1183 if (refnum >= ref_count)
1184 ref_count = refnum + 1;
1185 if (ref_count > ref_chunk * MAX_CHUNK_REFS)
1187 int new_slots = ref_count - ref_chunk * MAX_CHUNK_REFS;
1188 int new_chunks = new_slots / MAX_CHUNK_REFS + 1;
1189 ref_map = (struct ref_map *)
1190 xrealloc (ref_map, REF_MAP_SIZE (ref_chunk + new_chunks));
1191 memset (ref_map + ref_chunk * MAX_CHUNK_REFS, 0, new_chunks * REF_CHUNK_SIZE);
1192 ref_chunk += new_chunks;
1194 ref_map[refnum].stabs = stabs;
1195 ref_map[refnum].sym = sym;
1196 ref_map[refnum].value = value;
1199 /* Return defined sym for the reference REFNUM. */
1201 ref_search (int refnum)
1203 if (refnum < 0 || refnum > ref_count)
1205 return ref_map[refnum].sym;
1208 /* Return value for the reference REFNUM. */
1211 ref_search_value (int refnum)
1213 if (refnum < 0 || refnum > ref_count)
1215 return ref_map[refnum].value;
1218 /* Parse a reference id in STRING and return the resulting
1219 reference number. Move STRING beyond the reference id. */
1222 process_reference (char **string)
1227 if (**string != '#')
1230 /* Advance beyond the initial '#'. */
1233 /* Read number as reference id. */
1234 while (*p && isdigit (*p))
1236 refnum = refnum * 10 + *p - '0';
1243 /* If STRING defines a reference, store away a pointer to the reference
1244 definition for later use. Return the reference number. */
1247 symbol_reference_defined (char **string)
1252 refnum = process_reference (&p);
1254 /* Defining symbols end in '=' */
1257 /* Symbol is being defined here. */
1263 /* Must be a reference. Either the symbol has already been defined,
1264 or this is a forward reference to it. */
1271 objc_find_colon (name)
1275 if (s[0] == '-' || *s == '+')
1279 error ("invalid symbol name \"%s\"", name);
1281 s = strchr (s, ']');
1284 error ("invalid symbol name \"%s\"", name);
1286 return strchr (s, ':');
1290 return strchr (s, ':');
1296 define_symbol (CORE_ADDR valu, char *string, int desc, int type,
1297 struct objfile *objfile)
1299 register struct symbol *sym;
1300 char *p = (char *) objc_find_colon (string);
1305 /* We would like to eliminate nameless symbols, but keep their types.
1306 E.g. stab entry ":t10=*2" should produce a type 10, which is a pointer
1307 to type 2, but, should not create a symbol to address that type. Since
1308 the symbol will be nameless, there is no way any user can refer to it. */
1312 /* Ignore syms with empty names. */
1316 /* Ignore old-style symbols from cc -go */
1323 p = strchr (p, ':');
1326 /* If a nameless stab entry, all we need is the type, not the symbol.
1327 e.g. ":t10=*2" or a nameless enum like " :T16=ered:0,green:1,blue:2,;" */
1328 nameless = (p == string || ((string[0] == ' ') && (string[1] == ':')));
1330 current_symbol = sym = (struct symbol *)
1331 obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol));
1332 memset (sym, 0, sizeof (struct symbol));
1334 switch (type & N_TYPE)
1337 SYMBOL_SECTION (sym) = SECT_OFF_TEXT (objfile);
1340 SYMBOL_SECTION (sym) = SECT_OFF_DATA (objfile);
1343 SYMBOL_SECTION (sym) = SECT_OFF_BSS (objfile);
1347 if (processing_gcc_compilation)
1349 /* GCC 2.x puts the line number in desc. SunOS apparently puts in the
1350 number of bytes occupied by a type or object, which we ignore. */
1351 SYMBOL_LINE (sym) = desc;
1355 SYMBOL_LINE (sym) = 0; /* unknown */
1358 if (is_cplus_marker (string[0]))
1360 /* Special GNU C++ names. */
1364 SYMBOL_NAME (sym) = obsavestring ("this", strlen ("this"),
1365 &objfile->symbol_obstack);
1368 case 'v': /* $vtbl_ptr_type */
1369 /* Was: SYMBOL_NAME (sym) = "vptr"; */
1373 SYMBOL_NAME (sym) = obsavestring ("eh_throw", strlen ("eh_throw"),
1374 &objfile->symbol_obstack);
1378 /* This was an anonymous type that was never fixed up. */
1381 #ifdef STATIC_TRANSFORM_NAME
1383 /* SunPRO (3.0 at least) static variable encoding. */
1388 complain (&unrecognized_cplus_name_complaint, string);
1389 goto normal; /* Do *something* with it */
1392 else if (string[0] == '#')
1394 /* Special GNU C extension for referencing symbols. */
1398 /* If STRING defines a new reference id, then add it to the
1399 reference map. Else it must be referring to a previously
1400 defined symbol, so add it to the alias list of the previously
1403 refnum = symbol_reference_defined (&s);
1405 ref_add (refnum, sym, string, SYMBOL_VALUE (sym));
1406 else if (!resolve_symbol_reference (objfile, sym, string))
1409 /* S..P contains the name of the symbol. We need to store
1410 the correct name into SYMBOL_NAME. */
1416 SYMBOL_NAME (sym) = (char *)
1417 obstack_alloc (&objfile->symbol_obstack, nlen);
1418 strncpy (SYMBOL_NAME (sym), s, nlen);
1419 SYMBOL_NAME (sym)[nlen] = '\0';
1420 SYMBOL_INIT_DEMANGLED_NAME (sym, &objfile->symbol_obstack);
1423 /* FIXME! Want SYMBOL_NAME (sym) = 0;
1424 Get error if leave name 0. So give it something. */
1427 SYMBOL_NAME (sym) = (char *)
1428 obstack_alloc (&objfile->symbol_obstack, nlen);
1429 strncpy (SYMBOL_NAME (sym), string, nlen);
1430 SYMBOL_NAME (sym)[nlen] = '\0';
1431 SYMBOL_INIT_DEMANGLED_NAME (sym, &objfile->symbol_obstack);
1434 /* Advance STRING beyond the reference id. */
1440 SYMBOL_LANGUAGE (sym) = current_subfile->language;
1441 SYMBOL_NAME (sym) = (char *)
1442 obstack_alloc (&objfile->symbol_obstack, ((p - string) + 1));
1443 /* Open-coded memcpy--saves function call time. */
1444 /* FIXME: Does it really? Try replacing with simple strcpy and
1445 try it on an executable with a large symbol table. */
1446 /* FIXME: considering that gcc can open code memcpy anyway, I
1447 doubt it. xoxorich. */
1449 register char *p1 = string;
1450 register char *p2 = SYMBOL_NAME (sym);
1458 /* If this symbol is from a C++ compilation, then attempt to cache the
1459 demangled form for future reference. This is a typical time versus
1460 space tradeoff, that was decided in favor of time because it sped up
1461 C++ symbol lookups by a factor of about 20. */
1463 SYMBOL_INIT_DEMANGLED_NAME (sym, &objfile->symbol_obstack);
1467 /* Determine the type of name being defined. */
1469 /* Getting GDB to correctly skip the symbol on an undefined symbol
1470 descriptor and not ever dump core is a very dodgy proposition if
1471 we do things this way. I say the acorn RISC machine can just
1472 fix their compiler. */
1473 /* The Acorn RISC machine's compiler can put out locals that don't
1474 start with "234=" or "(3,4)=", so assume anything other than the
1475 deftypes we know how to handle is a local. */
1476 if (!strchr ("cfFGpPrStTvVXCR", *p))
1478 if (isdigit (*p) || *p == '(' || *p == '-')
1487 /* c is a special case, not followed by a type-number.
1488 SYMBOL:c=iVALUE for an integer constant symbol.
1489 SYMBOL:c=rVALUE for a floating constant symbol.
1490 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
1491 e.g. "b:c=e6,0" for "const b = blob1"
1492 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
1495 SYMBOL_CLASS (sym) = LOC_CONST;
1496 SYMBOL_TYPE (sym) = error_type (&p, objfile);
1497 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1498 add_symbol_to_list (sym, &file_symbols);
1506 double d = atof (p);
1509 /* FIXME-if-picky-about-floating-accuracy: Should be using
1510 target arithmetic to get the value. real.c in GCC
1511 probably has the necessary code. */
1513 /* FIXME: lookup_fundamental_type is a hack. We should be
1514 creating a type especially for the type of float constants.
1515 Problem is, what type should it be?
1517 Also, what should the name of this type be? Should we
1518 be using 'S' constants (see stabs.texinfo) instead? */
1520 SYMBOL_TYPE (sym) = lookup_fundamental_type (objfile,
1523 obstack_alloc (&objfile->symbol_obstack,
1524 TYPE_LENGTH (SYMBOL_TYPE (sym)));
1525 store_typed_floating (dbl_valu, SYMBOL_TYPE (sym), d);
1526 SYMBOL_VALUE_BYTES (sym) = dbl_valu;
1527 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
1532 /* Defining integer constants this way is kind of silly,
1533 since 'e' constants allows the compiler to give not
1534 only the value, but the type as well. C has at least
1535 int, long, unsigned int, and long long as constant
1536 types; other languages probably should have at least
1537 unsigned as well as signed constants. */
1539 /* We just need one int constant type for all objfiles.
1540 It doesn't depend on languages or anything (arguably its
1541 name should be a language-specific name for a type of
1542 that size, but I'm inclined to say that if the compiler
1543 wants a nice name for the type, it can use 'e'). */
1544 static struct type *int_const_type;
1546 /* Yes, this is as long as a *host* int. That is because we
1548 if (int_const_type == NULL)
1550 init_type (TYPE_CODE_INT,
1551 sizeof (int) * HOST_CHAR_BIT / TARGET_CHAR_BIT, 0,
1553 (struct objfile *) NULL);
1554 SYMBOL_TYPE (sym) = int_const_type;
1555 SYMBOL_VALUE (sym) = atoi (p);
1556 SYMBOL_CLASS (sym) = LOC_CONST;
1560 /* SYMBOL:c=eTYPE,INTVALUE for a constant symbol whose value
1561 can be represented as integral.
1562 e.g. "b:c=e6,0" for "const b = blob1"
1563 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
1565 SYMBOL_CLASS (sym) = LOC_CONST;
1566 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1570 SYMBOL_TYPE (sym) = error_type (&p, objfile);
1575 /* If the value is too big to fit in an int (perhaps because
1576 it is unsigned), or something like that, we silently get
1577 a bogus value. The type and everything else about it is
1578 correct. Ideally, we should be using whatever we have
1579 available for parsing unsigned and long long values,
1581 SYMBOL_VALUE (sym) = atoi (p);
1586 SYMBOL_CLASS (sym) = LOC_CONST;
1587 SYMBOL_TYPE (sym) = error_type (&p, objfile);
1590 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1591 add_symbol_to_list (sym, &file_symbols);
1595 /* The name of a caught exception. */
1596 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1597 SYMBOL_CLASS (sym) = LOC_LABEL;
1598 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1599 SYMBOL_VALUE_ADDRESS (sym) = valu;
1600 add_symbol_to_list (sym, &local_symbols);
1604 /* A static function definition. */
1605 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1606 SYMBOL_CLASS (sym) = LOC_BLOCK;
1607 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1608 add_symbol_to_list (sym, &file_symbols);
1609 /* fall into process_function_types. */
1611 process_function_types:
1612 /* Function result types are described as the result type in stabs.
1613 We need to convert this to the function-returning-type-X type
1614 in GDB. E.g. "int" is converted to "function returning int". */
1615 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_FUNC)
1616 SYMBOL_TYPE (sym) = lookup_function_type (SYMBOL_TYPE (sym));
1618 /* All functions in C++ have prototypes. */
1619 if (SYMBOL_LANGUAGE (sym) == language_cplus)
1620 TYPE_FLAGS (SYMBOL_TYPE (sym)) |= TYPE_FLAG_PROTOTYPED;
1622 /* fall into process_prototype_types */
1624 process_prototype_types:
1625 /* Sun acc puts declared types of arguments here. */
1628 struct type *ftype = SYMBOL_TYPE (sym);
1633 /* Obtain a worst case guess for the number of arguments
1634 by counting the semicolons. */
1641 /* Allocate parameter information fields and fill them in. */
1642 TYPE_FIELDS (ftype) = (struct field *)
1643 TYPE_ALLOC (ftype, nsemi * sizeof (struct field));
1648 /* A type number of zero indicates the start of varargs.
1649 FIXME: GDB currently ignores vararg functions. */
1650 if (p[0] == '0' && p[1] == '\0')
1652 ptype = read_type (&p, objfile);
1654 /* The Sun compilers mark integer arguments, which should
1655 be promoted to the width of the calling conventions, with
1656 a type which references itself. This type is turned into
1657 a TYPE_CODE_VOID type by read_type, and we have to turn
1658 it back into builtin_type_int here.
1659 FIXME: Do we need a new builtin_type_promoted_int_arg ? */
1660 if (TYPE_CODE (ptype) == TYPE_CODE_VOID)
1661 ptype = builtin_type_int;
1662 TYPE_FIELD_TYPE (ftype, nparams) = ptype;
1663 TYPE_FIELD_ARTIFICIAL (ftype, nparams++) = 0;
1665 TYPE_NFIELDS (ftype) = nparams;
1666 TYPE_FLAGS (ftype) |= TYPE_FLAG_PROTOTYPED;
1671 /* A global function definition. */
1672 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1673 SYMBOL_CLASS (sym) = LOC_BLOCK;
1674 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1675 add_symbol_to_list (sym, &global_symbols);
1676 goto process_function_types;
1679 /* For a class G (global) symbol, it appears that the
1680 value is not correct. It is necessary to search for the
1681 corresponding linker definition to find the value.
1682 These definitions appear at the end of the namelist. */
1683 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1684 SYMBOL_CLASS (sym) = LOC_STATIC;
1685 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1686 /* Don't add symbol references to global_sym_chain.
1687 Symbol references don't have valid names and wont't match up with
1688 minimal symbols when the global_sym_chain is relocated.
1689 We'll fixup symbol references when we fixup the defining symbol. */
1690 if (SYMBOL_NAME (sym) && SYMBOL_NAME (sym)[0] != '#')
1692 i = hashname (SYMBOL_NAME (sym));
1693 SYMBOL_VALUE_CHAIN (sym) = global_sym_chain[i];
1694 global_sym_chain[i] = sym;
1696 add_symbol_to_list (sym, &global_symbols);
1699 /* This case is faked by a conditional above,
1700 when there is no code letter in the dbx data.
1701 Dbx data never actually contains 'l'. */
1704 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1705 SYMBOL_CLASS (sym) = LOC_LOCAL;
1706 SYMBOL_VALUE (sym) = valu;
1707 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1708 add_symbol_to_list (sym, &local_symbols);
1713 /* pF is a two-letter code that means a function parameter in Fortran.
1714 The type-number specifies the type of the return value.
1715 Translate it into a pointer-to-function type. */
1719 = lookup_pointer_type
1720 (lookup_function_type (read_type (&p, objfile)));
1723 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1725 /* Normally this is a parameter, a LOC_ARG. On the i960, it
1726 can also be a LOC_LOCAL_ARG depending on symbol type. */
1727 #ifndef DBX_PARM_SYMBOL_CLASS
1728 #define DBX_PARM_SYMBOL_CLASS(type) LOC_ARG
1731 SYMBOL_CLASS (sym) = DBX_PARM_SYMBOL_CLASS (type);
1732 SYMBOL_VALUE (sym) = valu;
1733 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1734 add_symbol_to_list (sym, &local_symbols);
1736 if (TARGET_BYTE_ORDER != BFD_ENDIAN_BIG)
1738 /* On little-endian machines, this crud is never necessary,
1739 and, if the extra bytes contain garbage, is harmful. */
1743 /* If it's gcc-compiled, if it says `short', believe it. */
1744 if (processing_gcc_compilation || BELIEVE_PCC_PROMOTION)
1747 if (!BELIEVE_PCC_PROMOTION)
1749 /* This is the signed type which arguments get promoted to. */
1750 static struct type *pcc_promotion_type;
1751 /* This is the unsigned type which arguments get promoted to. */
1752 static struct type *pcc_unsigned_promotion_type;
1754 /* Call it "int" because this is mainly C lossage. */
1755 if (pcc_promotion_type == NULL)
1756 pcc_promotion_type =
1757 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
1760 if (pcc_unsigned_promotion_type == NULL)
1761 pcc_unsigned_promotion_type =
1762 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
1763 TYPE_FLAG_UNSIGNED, "unsigned int", NULL);
1765 if (BELIEVE_PCC_PROMOTION_TYPE)
1767 /* This is defined on machines (e.g. sparc) where we
1768 should believe the type of a PCC 'short' argument,
1769 but shouldn't believe the address (the address is the
1770 address of the corresponding int).
1772 My guess is that this correction, as opposed to
1773 changing the parameter to an 'int' (as done below,
1774 for PCC on most machines), is the right thing to do
1775 on all machines, but I don't want to risk breaking
1776 something that already works. On most PCC machines,
1777 the sparc problem doesn't come up because the calling
1778 function has to zero the top bytes (not knowing
1779 whether the called function wants an int or a short),
1780 so there is little practical difference between an
1781 int and a short (except perhaps what happens when the
1782 GDB user types "print short_arg = 0x10000;").
1784 Hacked for SunOS 4.1 by gnu@cygnus.com. In 4.1, the
1785 compiler actually produces the correct address (we
1786 don't need to fix it up). I made this code adapt so
1787 that it will offset the symbol if it was pointing at
1788 an int-aligned location and not otherwise. This way
1789 you can use the same gdb for 4.0.x and 4.1 systems.
1791 If the parameter is shorter than an int, and is
1792 integral (e.g. char, short, or unsigned equivalent),
1793 and is claimed to be passed on an integer boundary,
1794 don't believe it! Offset the parameter's address to
1795 the tail-end of that integer. */
1797 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) < TYPE_LENGTH (pcc_promotion_type)
1798 && TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_INT
1799 && 0 == SYMBOL_VALUE (sym) % TYPE_LENGTH (pcc_promotion_type))
1801 SYMBOL_VALUE (sym) += TYPE_LENGTH (pcc_promotion_type)
1802 - TYPE_LENGTH (SYMBOL_TYPE (sym));
1808 /* If PCC says a parameter is a short or a char,
1809 it is really an int. */
1810 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) < TYPE_LENGTH (pcc_promotion_type)
1811 && TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_INT)
1814 TYPE_UNSIGNED (SYMBOL_TYPE (sym))
1815 ? pcc_unsigned_promotion_type
1816 : pcc_promotion_type;
1823 /* acc seems to use P to declare the prototypes of functions that
1824 are referenced by this file. gdb is not prepared to deal
1825 with this extra information. FIXME, it ought to. */
1828 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1829 goto process_prototype_types;
1834 /* Parameter which is in a register. */
1835 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1836 SYMBOL_CLASS (sym) = LOC_REGPARM;
1837 SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu);
1838 if (SYMBOL_VALUE (sym) >= NUM_REGS + NUM_PSEUDO_REGS)
1840 complain (®_value_complaint, SYMBOL_VALUE (sym),
1841 NUM_REGS + NUM_PSEUDO_REGS,
1842 SYMBOL_SOURCE_NAME (sym));
1843 SYMBOL_VALUE (sym) = SP_REGNUM; /* Known safe, though useless */
1845 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1846 add_symbol_to_list (sym, &local_symbols);
1850 /* Register variable (either global or local). */
1851 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1852 SYMBOL_CLASS (sym) = LOC_REGISTER;
1853 SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu);
1854 if (SYMBOL_VALUE (sym) >= NUM_REGS + NUM_PSEUDO_REGS)
1856 complain (®_value_complaint, SYMBOL_VALUE (sym),
1857 NUM_REGS + NUM_PSEUDO_REGS,
1858 SYMBOL_SOURCE_NAME (sym));
1859 SYMBOL_VALUE (sym) = SP_REGNUM; /* Known safe, though useless */
1861 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1862 if (within_function)
1864 /* Sun cc uses a pair of symbols, one 'p' and one 'r' with the same
1865 name to represent an argument passed in a register.
1866 GCC uses 'P' for the same case. So if we find such a symbol pair
1867 we combine it into one 'P' symbol. For Sun cc we need to do this
1868 regardless of REG_STRUCT_HAS_ADDR, because the compiler puts out
1869 the 'p' symbol even if it never saves the argument onto the stack.
1871 On most machines, we want to preserve both symbols, so that
1872 we can still get information about what is going on with the
1873 stack (VAX for computing args_printed, using stack slots instead
1874 of saved registers in backtraces, etc.).
1876 Note that this code illegally combines
1877 main(argc) struct foo argc; { register struct foo argc; }
1878 but this case is considered pathological and causes a warning
1879 from a decent compiler. */
1882 && local_symbols->nsyms > 0
1883 #ifndef USE_REGISTER_NOT_ARG
1884 && REG_STRUCT_HAS_ADDR_P ()
1885 && REG_STRUCT_HAS_ADDR (processing_gcc_compilation,
1887 && (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT
1888 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION
1889 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_SET
1890 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_BITSTRING)
1894 struct symbol *prev_sym;
1895 prev_sym = local_symbols->symbol[local_symbols->nsyms - 1];
1896 if ((SYMBOL_CLASS (prev_sym) == LOC_REF_ARG
1897 || SYMBOL_CLASS (prev_sym) == LOC_ARG)
1898 && STREQ (SYMBOL_NAME (prev_sym), SYMBOL_NAME (sym)))
1900 SYMBOL_CLASS (prev_sym) = LOC_REGPARM;
1901 /* Use the type from the LOC_REGISTER; that is the type
1902 that is actually in that register. */
1903 SYMBOL_TYPE (prev_sym) = SYMBOL_TYPE (sym);
1904 SYMBOL_VALUE (prev_sym) = SYMBOL_VALUE (sym);
1909 add_symbol_to_list (sym, &local_symbols);
1912 add_symbol_to_list (sym, &file_symbols);
1916 /* Static symbol at top level of file */
1917 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1918 SYMBOL_CLASS (sym) = LOC_STATIC;
1919 SYMBOL_VALUE_ADDRESS (sym) = valu;
1920 #ifdef STATIC_TRANSFORM_NAME
1921 if (IS_STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym)))
1923 struct minimal_symbol *msym;
1924 msym = lookup_minimal_symbol (SYMBOL_NAME (sym), NULL, objfile);
1927 SYMBOL_NAME (sym) = STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym));
1928 SYMBOL_VALUE_ADDRESS (sym) = SYMBOL_VALUE_ADDRESS (msym);
1932 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1933 add_symbol_to_list (sym, &file_symbols);
1938 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1940 /* For a nameless type, we don't want a create a symbol, thus we
1941 did not use `sym'. Return without further processing. */
1945 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
1946 SYMBOL_VALUE (sym) = valu;
1947 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1948 /* C++ vagaries: we may have a type which is derived from
1949 a base type which did not have its name defined when the
1950 derived class was output. We fill in the derived class's
1951 base part member's name here in that case. */
1952 if (TYPE_NAME (SYMBOL_TYPE (sym)) != NULL)
1953 if ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT
1954 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION)
1955 && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)))
1958 for (j = TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)) - 1; j >= 0; j--)
1959 if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) == 0)
1960 TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) =
1961 type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym), j));
1964 if (TYPE_NAME (SYMBOL_TYPE (sym)) == NULL)
1966 /* gcc-2.6 or later (when using -fvtable-thunks)
1967 emits a unique named type for a vtable entry.
1968 Some gdb code depends on that specific name. */
1969 extern const char vtbl_ptr_name[];
1971 if ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_PTR
1972 && strcmp (SYMBOL_NAME (sym), vtbl_ptr_name))
1973 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_FUNC)
1975 /* If we are giving a name to a type such as "pointer to
1976 foo" or "function returning foo", we better not set
1977 the TYPE_NAME. If the program contains "typedef char
1978 *caddr_t;", we don't want all variables of type char
1979 * to print as caddr_t. This is not just a
1980 consequence of GDB's type management; PCC and GCC (at
1981 least through version 2.4) both output variables of
1982 either type char * or caddr_t with the type number
1983 defined in the 't' symbol for caddr_t. If a future
1984 compiler cleans this up it GDB is not ready for it
1985 yet, but if it becomes ready we somehow need to
1986 disable this check (without breaking the PCC/GCC2.4
1991 Fortunately, this check seems not to be necessary
1992 for anything except pointers or functions. */
1993 /* ezannoni: 2000-10-26. This seems to apply for
1994 versions of gcc older than 2.8. This was the original
1995 problem: with the following code gdb would tell that
1996 the type for name1 is caddr_t, and func is char()
1997 typedef char *caddr_t;
2009 /* Pascal accepts names for pointer types. */
2010 if (current_subfile->language == language_pascal)
2012 TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_NAME (sym);
2016 TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_NAME (sym);
2019 add_symbol_to_list (sym, &file_symbols);
2023 /* Struct, union, or enum tag. For GNU C++, this can be be followed
2024 by 't' which means we are typedef'ing it as well. */
2025 synonym = *p == 't';
2029 /* The semantics of C++ state that "struct foo { ... }" also defines
2030 a typedef for "foo". Unfortunately, cfront never makes the typedef
2031 when translating C++ into C. We make the typedef here so that
2032 "ptype foo" works as expected for cfront translated code. */
2033 else if ((current_subfile->language == language_cplus)
2034 || (current_subfile->language == language_objc))
2037 SYMBOL_TYPE (sym) = read_type (&p, objfile);
2039 /* For a nameless type, we don't want a create a symbol, thus we
2040 did not use `sym'. Return without further processing. */
2044 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
2045 SYMBOL_VALUE (sym) = valu;
2046 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
2047 if (TYPE_TAG_NAME (SYMBOL_TYPE (sym)) == 0)
2048 TYPE_TAG_NAME (SYMBOL_TYPE (sym))
2049 = obconcat (&objfile->type_obstack, "", "", SYMBOL_NAME (sym));
2050 add_symbol_to_list (sym, &file_symbols);
2054 /* Clone the sym and then modify it. */
2055 register struct symbol *typedef_sym = (struct symbol *)
2056 obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol));
2057 *typedef_sym = *sym;
2058 SYMBOL_CLASS (typedef_sym) = LOC_TYPEDEF;
2059 SYMBOL_VALUE (typedef_sym) = valu;
2060 SYMBOL_NAMESPACE (typedef_sym) = VAR_NAMESPACE;
2061 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
2062 TYPE_NAME (SYMBOL_TYPE (sym))
2063 = obconcat (&objfile->type_obstack, "", "", SYMBOL_NAME (sym));
2064 add_symbol_to_list (typedef_sym, &file_symbols);
2069 /* Static symbol of local scope */
2070 SYMBOL_TYPE (sym) = read_type (&p, objfile);
2071 SYMBOL_CLASS (sym) = LOC_STATIC;
2072 SYMBOL_VALUE_ADDRESS (sym) = valu;
2073 #ifdef STATIC_TRANSFORM_NAME
2074 if (IS_STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym)))
2076 struct minimal_symbol *msym;
2077 msym = lookup_minimal_symbol (SYMBOL_NAME (sym), NULL, objfile);
2080 SYMBOL_NAME (sym) = STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym));
2081 SYMBOL_VALUE_ADDRESS (sym) = SYMBOL_VALUE_ADDRESS (msym);
2085 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2086 #if 0 /* OBSOLETE OS9K */
2087 // OBSOLETE if (os9k_stabs)
2088 // OBSOLETE add_symbol_to_list (sym, &global_symbols);
2090 #endif /* OBSOLETE OS9K */
2091 add_symbol_to_list (sym, &local_symbols);
2095 /* Reference parameter */
2096 SYMBOL_TYPE (sym) = read_type (&p, objfile);
2097 SYMBOL_CLASS (sym) = LOC_REF_ARG;
2098 SYMBOL_VALUE (sym) = valu;
2099 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2100 add_symbol_to_list (sym, &local_symbols);
2104 /* Reference parameter which is in a register. */
2105 SYMBOL_TYPE (sym) = read_type (&p, objfile);
2106 SYMBOL_CLASS (sym) = LOC_REGPARM_ADDR;
2107 SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu);
2108 if (SYMBOL_VALUE (sym) >= NUM_REGS + NUM_PSEUDO_REGS)
2110 complain (®_value_complaint, SYMBOL_VALUE (sym),
2111 NUM_REGS + NUM_PSEUDO_REGS,
2112 SYMBOL_SOURCE_NAME (sym));
2113 SYMBOL_VALUE (sym) = SP_REGNUM; /* Known safe, though useless */
2115 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2116 add_symbol_to_list (sym, &local_symbols);
2120 /* This is used by Sun FORTRAN for "function result value".
2121 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
2122 that Pascal uses it too, but when I tried it Pascal used
2123 "x:3" (local symbol) instead. */
2124 SYMBOL_TYPE (sym) = read_type (&p, objfile);
2125 SYMBOL_CLASS (sym) = LOC_LOCAL;
2126 SYMBOL_VALUE (sym) = valu;
2127 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2128 add_symbol_to_list (sym, &local_symbols);
2131 /* New code added to support cfront stabs strings.
2132 Note: case 'P' already handled above */
2134 /* Cfront type continuation coming up!
2135 Find the original definition and add to it.
2136 We'll have to do this for the typedef too,
2137 since we cloned the symbol to define a type in read_type.
2138 Stabs info examples:
2140 foo__1CFv :ZtF (first def foo__1CFv:F(0,3);(0,24))
2141 C:ZsC;;__ct__1CFv func1__1CFv func2__1CFv ... ;;;
2142 where C is the name of the class.
2143 Unfortunately, we can't lookup the original symbol yet 'cuz
2144 we haven't finished reading all the symbols.
2145 Instead, we save it for processing later */
2146 process_later (sym, p, resolve_cfront_continuation);
2147 SYMBOL_TYPE (sym) = error_type (&p, objfile); /* FIXME! change later */
2148 SYMBOL_CLASS (sym) = LOC_CONST;
2149 SYMBOL_VALUE (sym) = 0;
2150 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2151 /* Don't add to list - we'll delete it later when
2152 we add the continuation to the real sym */
2154 /* End of new code added to support cfront stabs strings */
2157 SYMBOL_TYPE (sym) = error_type (&p, objfile);
2158 SYMBOL_CLASS (sym) = LOC_CONST;
2159 SYMBOL_VALUE (sym) = 0;
2160 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2161 add_symbol_to_list (sym, &file_symbols);
2165 /* When passing structures to a function, some systems sometimes pass
2166 the address in a register, not the structure itself. */
2168 if (REG_STRUCT_HAS_ADDR_P ()
2169 && REG_STRUCT_HAS_ADDR (processing_gcc_compilation, SYMBOL_TYPE (sym))
2170 && (SYMBOL_CLASS (sym) == LOC_REGPARM || SYMBOL_CLASS (sym) == LOC_ARG))
2172 struct type *symbol_type = check_typedef (SYMBOL_TYPE (sym));
2174 if ((TYPE_CODE (symbol_type) == TYPE_CODE_STRUCT)
2175 || (TYPE_CODE (symbol_type) == TYPE_CODE_UNION)
2176 || (TYPE_CODE (symbol_type) == TYPE_CODE_BITSTRING)
2177 || (TYPE_CODE (symbol_type) == TYPE_CODE_SET))
2179 /* If REG_STRUCT_HAS_ADDR yields non-zero we have to convert
2180 LOC_REGPARM to LOC_REGPARM_ADDR for structures and unions. */
2181 if (SYMBOL_CLASS (sym) == LOC_REGPARM)
2182 SYMBOL_CLASS (sym) = LOC_REGPARM_ADDR;
2183 /* Likewise for converting LOC_ARG to LOC_REF_ARG (for the 7th
2184 and subsequent arguments on the sparc, for example). */
2185 else if (SYMBOL_CLASS (sym) == LOC_ARG)
2186 SYMBOL_CLASS (sym) = LOC_REF_ARG;
2190 /* Is there more to parse? For example LRS/alias information? */
2191 while (*p && *p == ';')
2194 if (*p && p[0] == 'l' && p[1] == '(')
2196 /* GNU extensions for live range splitting may be appended to
2197 the end of the stab string. eg. "l(#1,#2);l(#3,#5)" */
2199 /* Resolve the live range and add it to SYM's live range list. */
2200 if (!resolve_live_range (objfile, sym, p))
2203 /* Find end of live range info. */
2204 p = strchr (p, ')');
2205 if (!*p || *p != ')')
2207 complain (&lrs_general_complaint, "live range format not recognized");
2216 /* Add the live range found in P to the symbol SYM in objfile OBJFILE. Returns
2217 non-zero on success, zero otherwise. */
2220 resolve_live_range (struct objfile *objfile, struct symbol *sym, char *p)
2223 CORE_ADDR start, end;
2225 /* Sanity check the beginning of the stabs string. */
2226 if (!*p || *p != 'l')
2228 complain (&lrs_general_complaint, "live range string 1");
2233 if (!*p || *p != '(')
2235 complain (&lrs_general_complaint, "live range string 2");
2240 /* Get starting value of range and advance P past the reference id.
2242 ?!? In theory, the process_reference should never fail, but we should
2243 catch that case just in case the compiler scrogged the stabs. */
2244 refnum = process_reference (&p);
2245 start = ref_search_value (refnum);
2248 complain (&lrs_general_complaint, "Live range symbol not found 1");
2252 if (!*p || *p != ',')
2254 complain (&lrs_general_complaint, "live range string 3");
2259 /* Get ending value of range and advance P past the reference id.
2261 ?!? In theory, the process_reference should never fail, but we should
2262 catch that case just in case the compiler scrogged the stabs. */
2263 refnum = process_reference (&p);
2264 end = ref_search_value (refnum);
2267 complain (&lrs_general_complaint, "Live range symbol not found 2");
2271 if (!*p || *p != ')')
2273 complain (&lrs_general_complaint, "live range string 4");
2277 /* Now that we know the bounds of the range, add it to the
2279 add_live_range (objfile, sym, start, end);
2284 /* Add a new live range defined by START and END to the symbol SYM
2285 in objfile OBJFILE. */
2288 add_live_range (struct objfile *objfile, struct symbol *sym, CORE_ADDR start,
2291 struct range_list *r, *rs;
2295 complain (&lrs_general_complaint, "end of live range follows start");
2299 /* Alloc new live range structure. */
2300 r = (struct range_list *)
2301 obstack_alloc (&objfile->type_obstack,
2302 sizeof (struct range_list));
2307 /* Append this range to the symbol's range list. */
2308 if (!SYMBOL_RANGES (sym))
2309 SYMBOL_RANGES (sym) = r;
2312 /* Get the last range for the symbol. */
2313 for (rs = SYMBOL_RANGES (sym); rs->next; rs = rs->next)
2320 /* Skip rest of this symbol and return an error type.
2322 General notes on error recovery: error_type always skips to the
2323 end of the symbol (modulo cretinous dbx symbol name continuation).
2324 Thus code like this:
2326 if (*(*pp)++ != ';')
2327 return error_type (pp, objfile);
2329 is wrong because if *pp starts out pointing at '\0' (typically as the
2330 result of an earlier error), it will be incremented to point to the
2331 start of the next symbol, which might produce strange results, at least
2332 if you run off the end of the string table. Instead use
2335 return error_type (pp, objfile);
2341 foo = error_type (pp, objfile);
2345 And in case it isn't obvious, the point of all this hair is so the compiler
2346 can define new types and new syntaxes, and old versions of the
2347 debugger will be able to read the new symbol tables. */
2349 static struct type *
2350 error_type (char **pp, struct objfile *objfile)
2352 complain (&error_type_complaint);
2355 /* Skip to end of symbol. */
2356 while (**pp != '\0')
2361 /* Check for and handle cretinous dbx symbol name continuation! */
2362 if ((*pp)[-1] == '\\' || (*pp)[-1] == '?')
2364 *pp = next_symbol_text (objfile);
2371 return (builtin_type_error);
2375 /* Read type information or a type definition; return the type. Even
2376 though this routine accepts either type information or a type
2377 definition, the distinction is relevant--some parts of stabsread.c
2378 assume that type information starts with a digit, '-', or '(' in
2379 deciding whether to call read_type. */
2382 read_type (register char **pp, struct objfile *objfile)
2384 register struct type *type = 0;
2387 char type_descriptor;
2389 /* Size in bits of type if specified by a type attribute, or -1 if
2390 there is no size attribute. */
2393 /* Used to distinguish string and bitstring from char-array and set. */
2396 /* Used to distinguish vector from array. */
2399 /* Read type number if present. The type number may be omitted.
2400 for instance in a two-dimensional array declared with type
2401 "ar1;1;10;ar1;1;10;4". */
2402 if ((**pp >= '0' && **pp <= '9')
2406 if (read_type_number (pp, typenums) != 0)
2407 return error_type (pp, objfile);
2409 /* Type is not being defined here. Either it already exists,
2410 or this is a forward reference to it. dbx_alloc_type handles
2413 return dbx_alloc_type (typenums, objfile);
2415 /* Type is being defined here. */
2417 Also skip the type descriptor - we get it below with (*pp)[-1]. */
2422 /* 'typenums=' not present, type is anonymous. Read and return
2423 the definition, but don't put it in the type vector. */
2424 typenums[0] = typenums[1] = -1;
2429 type_descriptor = (*pp)[-1];
2430 switch (type_descriptor)
2434 enum type_code code;
2436 /* Used to index through file_symbols. */
2437 struct pending *ppt;
2440 /* Name including "struct", etc. */
2444 char *from, *to, *p, *q1, *q2;
2446 /* Set the type code according to the following letter. */
2450 code = TYPE_CODE_STRUCT;
2453 code = TYPE_CODE_UNION;
2456 code = TYPE_CODE_ENUM;
2460 /* Complain and keep going, so compilers can invent new
2461 cross-reference types. */
2462 static struct complaint msg =
2463 {"Unrecognized cross-reference type `%c'", 0, 0};
2464 complain (&msg, (*pp)[0]);
2465 code = TYPE_CODE_STRUCT;
2470 q1 = strchr (*pp, '<');
2471 p = strchr (*pp, ':');
2473 return error_type (pp, objfile);
2474 if (q1 && p > q1 && p[1] == ':')
2476 int nesting_level = 0;
2477 for (q2 = q1; *q2; q2++)
2481 else if (*q2 == '>')
2483 else if (*q2 == ':' && nesting_level == 0)
2488 return error_type (pp, objfile);
2491 (char *) obstack_alloc (&objfile->type_obstack, p - *pp + 1);
2493 /* Copy the name. */
2499 /* Set the pointer ahead of the name which we just read, and
2504 /* Now check to see whether the type has already been
2505 declared. This was written for arrays of cross-referenced
2506 types before we had TYPE_CODE_TARGET_STUBBED, so I'm pretty
2507 sure it is not necessary anymore. But it might be a good
2508 idea, to save a little memory. */
2510 for (ppt = file_symbols; ppt; ppt = ppt->next)
2511 for (i = 0; i < ppt->nsyms; i++)
2513 struct symbol *sym = ppt->symbol[i];
2515 if (SYMBOL_CLASS (sym) == LOC_TYPEDEF
2516 && SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE
2517 && (TYPE_CODE (SYMBOL_TYPE (sym)) == code)
2518 && STREQ (SYMBOL_NAME (sym), type_name))
2520 obstack_free (&objfile->type_obstack, type_name);
2521 type = SYMBOL_TYPE (sym);
2526 /* Didn't find the type to which this refers, so we must
2527 be dealing with a forward reference. Allocate a type
2528 structure for it, and keep track of it so we can
2529 fill in the rest of the fields when we get the full
2531 type = dbx_alloc_type (typenums, objfile);
2532 TYPE_CODE (type) = code;
2533 TYPE_TAG_NAME (type) = type_name;
2534 INIT_CPLUS_SPECIFIC (type);
2535 TYPE_FLAGS (type) |= TYPE_FLAG_STUB;
2537 add_undefined_type (type);
2541 case '-': /* RS/6000 built-in type */
2555 /* We deal with something like t(1,2)=(3,4)=... which
2556 the Lucid compiler and recent gcc versions (post 2.7.3) use. */
2558 /* Allocate and enter the typedef type first.
2559 This handles recursive types. */
2560 type = dbx_alloc_type (typenums, objfile);
2561 TYPE_CODE (type) = TYPE_CODE_TYPEDEF;
2563 struct type *xtype = read_type (pp, objfile);
2566 /* It's being defined as itself. That means it is "void". */
2567 TYPE_CODE (type) = TYPE_CODE_VOID;
2568 TYPE_LENGTH (type) = 1;
2570 else if (type_size >= 0 || is_string)
2572 /* This is the absolute wrong way to construct types. Every
2573 other debug format has found a way around this problem and
2574 the related problems with unnecessarily stubbed types;
2575 someone motivated should attempt to clean up the issue
2576 here as well. Once a type pointed to has been created it
2577 should not be modified.
2579 Well, it's not *absolutely* wrong. Constructing recursive
2580 types (trees, linked lists) necessarily entails modifying
2581 types after creating them. Constructing any loop structure
2582 entails side effects. The Dwarf 2 reader does handle this
2583 more gracefully (it never constructs more than once
2584 instance of a type object, so it doesn't have to copy type
2585 objects wholesale), but it still mutates type objects after
2586 other folks have references to them.
2588 Keep in mind that this circularity/mutation issue shows up
2589 at the source language level, too: C's "incomplete types",
2590 for example. So the proper cleanup, I think, would be to
2591 limit GDB's type smashing to match exactly those required
2592 by the source language. So GDB could have a
2593 "complete_this_type" function, but never create unnecessary
2594 copies of a type otherwise. */
2595 replace_type (type, xtype);
2596 TYPE_NAME (type) = NULL;
2597 TYPE_TAG_NAME (type) = NULL;
2601 TYPE_FLAGS (type) |= TYPE_FLAG_TARGET_STUB;
2602 TYPE_TARGET_TYPE (type) = xtype;
2607 /* In the following types, we must be sure to overwrite any existing
2608 type that the typenums refer to, rather than allocating a new one
2609 and making the typenums point to the new one. This is because there
2610 may already be pointers to the existing type (if it had been
2611 forward-referenced), and we must change it to a pointer, function,
2612 reference, or whatever, *in-place*. */
2614 case '*': /* Pointer to another type */
2615 type1 = read_type (pp, objfile);
2616 type = make_pointer_type (type1, dbx_lookup_type (typenums));
2619 case '&': /* Reference to another type */
2620 type1 = read_type (pp, objfile);
2621 type = make_reference_type (type1, dbx_lookup_type (typenums));
2624 case 'f': /* Function returning another type */
2625 #if 0 /* OBSOLETE OS9K */
2626 // OBSOLETE if (os9k_stabs && **pp == '(')
2628 // OBSOLETE /* Function prototype; parse it.
2629 // OBSOLETE We must conditionalize this on os9k_stabs because otherwise
2630 // OBSOLETE it could be confused with a Sun-style (1,3) typenumber
2631 // OBSOLETE (I think). */
2632 // OBSOLETE struct type *t;
2634 // OBSOLETE while (**pp != ')')
2636 // OBSOLETE t = read_type (pp, objfile);
2637 // OBSOLETE if (**pp == ',')
2638 // OBSOLETE ++ * pp;
2641 #endif /* OBSOLETE OS9K */
2643 type1 = read_type (pp, objfile);
2644 type = make_function_type (type1, dbx_lookup_type (typenums));
2647 case 'g': /* Prototyped function. (Sun) */
2649 /* Unresolved questions:
2651 - According to Sun's ``STABS Interface Manual'', for 'f'
2652 and 'F' symbol descriptors, a `0' in the argument type list
2653 indicates a varargs function. But it doesn't say how 'g'
2654 type descriptors represent that info. Someone with access
2655 to Sun's toolchain should try it out.
2657 - According to the comment in define_symbol (search for
2658 `process_prototype_types:'), Sun emits integer arguments as
2659 types which ref themselves --- like `void' types. Do we
2660 have to deal with that here, too? Again, someone with
2661 access to Sun's toolchain should try it out and let us
2664 const char *type_start = (*pp) - 1;
2665 struct type *return_type = read_type (pp, objfile);
2666 struct type *func_type
2667 = make_function_type (return_type, dbx_lookup_type (typenums));
2670 struct type_list *next;
2674 while (**pp && **pp != '#')
2676 struct type *arg_type = read_type (pp, objfile);
2677 struct type_list *new = alloca (sizeof (*new));
2678 new->type = arg_type;
2679 new->next = arg_types;
2687 static struct complaint msg = {
2688 "Prototyped function type didn't end arguments with `#':\n%s",
2691 complain (&msg, type_start);
2694 /* If there is just one argument whose type is `void', then
2695 that's just an empty argument list. */
2697 && ! arg_types->next
2698 && TYPE_CODE (arg_types->type) == TYPE_CODE_VOID)
2701 TYPE_FIELDS (func_type)
2702 = (struct field *) TYPE_ALLOC (func_type,
2703 num_args * sizeof (struct field));
2704 memset (TYPE_FIELDS (func_type), 0, num_args * sizeof (struct field));
2707 struct type_list *t;
2709 /* We stuck each argument type onto the front of the list
2710 when we read it, so the list is reversed. Build the
2711 fields array right-to-left. */
2712 for (t = arg_types, i = num_args - 1; t; t = t->next, i--)
2713 TYPE_FIELD_TYPE (func_type, i) = t->type;
2715 TYPE_NFIELDS (func_type) = num_args;
2716 TYPE_FLAGS (func_type) |= TYPE_FLAG_PROTOTYPED;
2722 case 'k': /* Const qualifier on some type (Sun) */
2723 #if 0 /* OBSOLETE OS9K */
2724 // OBSOLETE /* ezannoni 2002-07-16: This can be safely deleted, because 'c'
2725 // OBSOLETE means complex type in AIX stabs, while it means const qualifier
2726 // OBSOLETE in os9k stabs. Obviously we were supporting only the os9k meaning.
2727 // OBSOLETE We were erroring out if we were reading AIX stabs. Right now the
2728 // OBSOLETE erroring out will happen in the default clause of the switch. */
2729 // OBSOLETE case 'c': /* Const qualifier on some type (OS9000) */
2730 // OBSOLETE /* Because 'c' means other things to AIX and 'k' is perfectly good,
2731 // OBSOLETE only accept 'c' in the os9k_stabs case. */
2732 // OBSOLETE if (type_descriptor == 'c' && !os9k_stabs)
2733 // OBSOLETE return error_type (pp, objfile);
2734 #endif /* OBSOLETE OS9K */
2735 type = read_type (pp, objfile);
2736 type = make_cv_type (1, TYPE_VOLATILE (type), type,
2737 dbx_lookup_type (typenums));
2740 case 'B': /* Volatile qual on some type (Sun) */
2741 #if 0 /* OBSOLETE OS9K */
2742 // OBSOLETE /* ezannoni 2002-07-16: This can be safely deleted, because 'i'
2743 // OBSOLETE means imported type in AIX stabs, while it means volatile qualifier
2744 // OBSOLETE in os9k stabs. Obviously we were supporting only the os9k meaning.
2745 // OBSOLETE We were erroring out if we were reading AIX stabs. Right now the
2746 // OBSOLETE erroring out will happen in the default clause of the switch. */
2747 // OBSOLETE case 'i': /* Volatile qual on some type (OS9000) */
2748 // OBSOLETE /* Because 'i' means other things to AIX and 'B' is perfectly good,
2749 // OBSOLETE only accept 'i' in the os9k_stabs case. */
2750 // OBSOLETE if (type_descriptor == 'i' && !os9k_stabs)
2751 // OBSOLETE return error_type (pp, objfile);
2752 #endif /* OBSOLETE OS9K */
2753 type = read_type (pp, objfile);
2754 type = make_cv_type (TYPE_CONST (type), 1, type,
2755 dbx_lookup_type (typenums));
2759 if (isdigit (**pp) || **pp == '(' || **pp == '-')
2760 { /* Member (class & variable) type */
2761 /* FIXME -- we should be doing smash_to_XXX types here. */
2763 struct type *domain = read_type (pp, objfile);
2764 struct type *memtype;
2767 /* Invalid member type data format. */
2768 return error_type (pp, objfile);
2771 memtype = read_type (pp, objfile);
2772 type = dbx_alloc_type (typenums, objfile);
2773 smash_to_member_type (type, domain, memtype);
2776 /* type attribute */
2779 /* Skip to the semicolon. */
2780 while (**pp != ';' && **pp != '\0')
2783 return error_type (pp, objfile);
2785 ++ * pp; /* Skip the semicolon. */
2789 case 's': /* Size attribute */
2790 type_size = atoi (attr + 1);
2795 case 'S': /* String attribute */
2796 /* FIXME: check to see if following type is array? */
2800 case 'V': /* Vector attribute */
2801 /* FIXME: check to see if following type is array? */
2806 /* Ignore unrecognized type attributes, so future compilers
2807 can invent new ones. */
2815 case '#': /* Method (class & fn) type */
2816 if ((*pp)[0] == '#')
2818 /* We'll get the parameter types from the name. */
2819 struct type *return_type;
2822 return_type = read_type (pp, objfile);
2823 if (*(*pp)++ != ';')
2824 complain (&invalid_member_complaint, symnum);
2825 type = allocate_stub_method (return_type);
2826 if (typenums[0] != -1)
2827 *dbx_lookup_type (typenums) = type;
2831 struct type *domain = read_type (pp, objfile);
2832 struct type *return_type;
2837 /* Invalid member type data format. */
2838 return error_type (pp, objfile);
2842 return_type = read_type (pp, objfile);
2843 args = read_args (pp, ';', objfile, &nargs, &varargs);
2844 type = dbx_alloc_type (typenums, objfile);
2845 smash_to_method_type (type, domain, return_type, args,
2850 case 'r': /* Range type */
2851 type = read_range_type (pp, typenums, objfile);
2852 if (typenums[0] != -1)
2853 *dbx_lookup_type (typenums) = type;
2857 #if 0 /* OBSOLETE OS9K */
2858 // OBSOLETE if (os9k_stabs)
2859 // OBSOLETE /* Const and volatile qualified type. */
2860 // OBSOLETE type = read_type (pp, objfile);
2862 #endif /* OBSOLETE OS9K */
2864 /* Sun ACC builtin int type */
2865 type = read_sun_builtin_type (pp, typenums, objfile);
2866 if (typenums[0] != -1)
2867 *dbx_lookup_type (typenums) = type;
2871 case 'R': /* Sun ACC builtin float type */
2872 type = read_sun_floating_type (pp, typenums, objfile);
2873 if (typenums[0] != -1)
2874 *dbx_lookup_type (typenums) = type;
2877 case 'e': /* Enumeration type */
2878 type = dbx_alloc_type (typenums, objfile);
2879 type = read_enum_type (pp, type, objfile);
2880 if (typenums[0] != -1)
2881 *dbx_lookup_type (typenums) = type;
2884 case 's': /* Struct type */
2885 case 'u': /* Union type */
2887 enum type_code type_code = TYPE_CODE_UNDEF;
2888 type = dbx_alloc_type (typenums, objfile);
2889 switch (type_descriptor)
2892 type_code = TYPE_CODE_STRUCT;
2895 type_code = TYPE_CODE_UNION;
2898 type = read_struct_type (pp, type, type_code, objfile);
2902 case 'a': /* Array type */
2904 return error_type (pp, objfile);
2907 type = dbx_alloc_type (typenums, objfile);
2908 type = read_array_type (pp, type, objfile);
2910 TYPE_CODE (type) = TYPE_CODE_STRING;
2912 TYPE_FLAGS (type) |= TYPE_FLAG_VECTOR;
2915 case 'S': /* Set or bitstring type */
2916 type1 = read_type (pp, objfile);
2917 type = create_set_type ((struct type *) NULL, type1);
2919 TYPE_CODE (type) = TYPE_CODE_BITSTRING;
2920 if (typenums[0] != -1)
2921 *dbx_lookup_type (typenums) = type;
2925 --*pp; /* Go back to the symbol in error */
2926 /* Particularly important if it was \0! */
2927 return error_type (pp, objfile);
2932 warning ("GDB internal error, type is NULL in stabsread.c\n");
2933 return error_type (pp, objfile);
2936 /* Size specified in a type attribute overrides any other size. */
2937 if (type_size != -1)
2938 TYPE_LENGTH (type) = (type_size + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT;
2943 /* RS/6000 xlc/dbx combination uses a set of builtin types, starting from -1.
2944 Return the proper type node for a given builtin type number. */
2946 static struct type *
2947 rs6000_builtin_type (int typenum)
2949 /* We recognize types numbered from -NUMBER_RECOGNIZED to -1. */
2950 #define NUMBER_RECOGNIZED 34
2951 /* This includes an empty slot for type number -0. */
2952 static struct type *negative_types[NUMBER_RECOGNIZED + 1];
2953 struct type *rettype = NULL;
2955 if (typenum >= 0 || typenum < -NUMBER_RECOGNIZED)
2957 complain (&rs6000_builtin_complaint, typenum);
2958 return builtin_type_error;
2960 if (negative_types[-typenum] != NULL)
2961 return negative_types[-typenum];
2963 #if TARGET_CHAR_BIT != 8
2964 #error This code wrong for TARGET_CHAR_BIT not 8
2965 /* These definitions all assume that TARGET_CHAR_BIT is 8. I think
2966 that if that ever becomes not true, the correct fix will be to
2967 make the size in the struct type to be in bits, not in units of
2974 /* The size of this and all the other types are fixed, defined
2975 by the debugging format. If there is a type called "int" which
2976 is other than 32 bits, then it should use a new negative type
2977 number (or avoid negative type numbers for that case).
2978 See stabs.texinfo. */
2979 rettype = init_type (TYPE_CODE_INT, 4, 0, "int", NULL);
2982 rettype = init_type (TYPE_CODE_INT, 1, 0, "char", NULL);
2985 rettype = init_type (TYPE_CODE_INT, 2, 0, "short", NULL);
2988 rettype = init_type (TYPE_CODE_INT, 4, 0, "long", NULL);
2991 rettype = init_type (TYPE_CODE_INT, 1, TYPE_FLAG_UNSIGNED,
2992 "unsigned char", NULL);
2995 rettype = init_type (TYPE_CODE_INT, 1, 0, "signed char", NULL);
2998 rettype = init_type (TYPE_CODE_INT, 2, TYPE_FLAG_UNSIGNED,
2999 "unsigned short", NULL);
3002 rettype = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED,
3003 "unsigned int", NULL);
3006 rettype = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED,
3009 rettype = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED,
3010 "unsigned long", NULL);
3013 rettype = init_type (TYPE_CODE_VOID, 1, 0, "void", NULL);
3016 /* IEEE single precision (32 bit). */
3017 rettype = init_type (TYPE_CODE_FLT, 4, 0, "float", NULL);
3020 /* IEEE double precision (64 bit). */
3021 rettype = init_type (TYPE_CODE_FLT, 8, 0, "double", NULL);
3024 /* This is an IEEE double on the RS/6000, and different machines with
3025 different sizes for "long double" should use different negative
3026 type numbers. See stabs.texinfo. */
3027 rettype = init_type (TYPE_CODE_FLT, 8, 0, "long double", NULL);
3030 rettype = init_type (TYPE_CODE_INT, 4, 0, "integer", NULL);
3033 rettype = init_type (TYPE_CODE_BOOL, 4, TYPE_FLAG_UNSIGNED,
3037 rettype = init_type (TYPE_CODE_FLT, 4, 0, "short real", NULL);
3040 rettype = init_type (TYPE_CODE_FLT, 8, 0, "real", NULL);
3043 rettype = init_type (TYPE_CODE_ERROR, 0, 0, "stringptr", NULL);
3046 rettype = init_type (TYPE_CODE_CHAR, 1, TYPE_FLAG_UNSIGNED,
3050 rettype = init_type (TYPE_CODE_BOOL, 1, TYPE_FLAG_UNSIGNED,
3054 rettype = init_type (TYPE_CODE_BOOL, 2, TYPE_FLAG_UNSIGNED,
3058 rettype = init_type (TYPE_CODE_BOOL, 4, TYPE_FLAG_UNSIGNED,
3062 rettype = init_type (TYPE_CODE_BOOL, 4, TYPE_FLAG_UNSIGNED,
3066 /* Complex type consisting of two IEEE single precision values. */
3067 rettype = init_type (TYPE_CODE_COMPLEX, 8, 0, "complex", NULL);
3068 TYPE_TARGET_TYPE (rettype) = init_type (TYPE_CODE_FLT, 4, 0, "float",
3072 /* Complex type consisting of two IEEE double precision values. */
3073 rettype = init_type (TYPE_CODE_COMPLEX, 16, 0, "double complex", NULL);
3074 TYPE_TARGET_TYPE (rettype) = init_type (TYPE_CODE_FLT, 8, 0, "double",
3078 rettype = init_type (TYPE_CODE_INT, 1, 0, "integer*1", NULL);
3081 rettype = init_type (TYPE_CODE_INT, 2, 0, "integer*2", NULL);
3084 rettype = init_type (TYPE_CODE_INT, 4, 0, "integer*4", NULL);
3087 rettype = init_type (TYPE_CODE_CHAR, 2, 0, "wchar", NULL);
3090 rettype = init_type (TYPE_CODE_INT, 8, 0, "long long", NULL);
3093 rettype = init_type (TYPE_CODE_INT, 8, TYPE_FLAG_UNSIGNED,
3094 "unsigned long long", NULL);
3097 rettype = init_type (TYPE_CODE_INT, 8, TYPE_FLAG_UNSIGNED,
3101 rettype = init_type (TYPE_CODE_INT, 8, 0, "integer*8", NULL);
3104 negative_types[-typenum] = rettype;
3108 /* This page contains subroutines of read_type. */
3110 /* Replace *OLD_NAME with the method name portion of PHYSNAME. */
3113 update_method_name_from_physname (char **old_name, char *physname)
3117 method_name = method_name_from_physname (physname);
3119 if (method_name == NULL)
3120 error ("bad physname %s\n", physname);
3122 if (strcmp (*old_name, method_name) != 0)
3125 *old_name = method_name;
3128 xfree (method_name);
3131 /* Read member function stabs info for C++ classes. The form of each member
3134 NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;
3136 An example with two member functions is:
3138 afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;
3140 For the case of overloaded operators, the format is op$::*.funcs, where
3141 $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
3142 name (such as `+=') and `.' marks the end of the operator name.
3144 Returns 1 for success, 0 for failure. */
3147 read_member_functions (struct field_info *fip, char **pp, struct type *type,
3148 struct objfile *objfile)
3152 /* Total number of member functions defined in this class. If the class
3153 defines two `f' functions, and one `g' function, then this will have
3155 int total_length = 0;
3159 struct next_fnfield *next;
3160 struct fn_field fn_field;
3163 struct type *look_ahead_type;
3164 struct next_fnfieldlist *new_fnlist;
3165 struct next_fnfield *new_sublist;
3169 /* Process each list until we find something that is not a member function
3170 or find the end of the functions. */
3174 /* We should be positioned at the start of the function name.
3175 Scan forward to find the first ':' and if it is not the
3176 first of a "::" delimiter, then this is not a member function. */
3188 look_ahead_type = NULL;
3191 new_fnlist = (struct next_fnfieldlist *)
3192 xmalloc (sizeof (struct next_fnfieldlist));
3193 make_cleanup (xfree, new_fnlist);
3194 memset (new_fnlist, 0, sizeof (struct next_fnfieldlist));
3196 if ((*pp)[0] == 'o' && (*pp)[1] == 'p' && is_cplus_marker ((*pp)[2]))
3198 /* This is a completely wierd case. In order to stuff in the
3199 names that might contain colons (the usual name delimiter),
3200 Mike Tiemann defined a different name format which is
3201 signalled if the identifier is "op$". In that case, the
3202 format is "op$::XXXX." where XXXX is the name. This is
3203 used for names like "+" or "=". YUUUUUUUK! FIXME! */
3204 /* This lets the user type "break operator+".
3205 We could just put in "+" as the name, but that wouldn't
3207 static char opname[32] =
3208 {'o', 'p', CPLUS_MARKER};
3209 char *o = opname + 3;
3211 /* Skip past '::'. */
3214 STABS_CONTINUE (pp, objfile);
3220 main_fn_name = savestring (opname, o - opname);
3226 main_fn_name = savestring (*pp, p - *pp);
3227 /* Skip past '::'. */
3230 new_fnlist->fn_fieldlist.name = main_fn_name;
3235 (struct next_fnfield *) xmalloc (sizeof (struct next_fnfield));
3236 make_cleanup (xfree, new_sublist);
3237 memset (new_sublist, 0, sizeof (struct next_fnfield));
3239 /* Check for and handle cretinous dbx symbol name continuation! */
3240 if (look_ahead_type == NULL)
3243 STABS_CONTINUE (pp, objfile);
3245 new_sublist->fn_field.type = read_type (pp, objfile);
3248 /* Invalid symtab info for member function. */
3254 /* g++ version 1 kludge */
3255 new_sublist->fn_field.type = look_ahead_type;
3256 look_ahead_type = NULL;
3266 /* If this is just a stub, then we don't have the real name here. */
3268 if (TYPE_STUB (new_sublist->fn_field.type))
3270 if (!TYPE_DOMAIN_TYPE (new_sublist->fn_field.type))
3271 TYPE_DOMAIN_TYPE (new_sublist->fn_field.type) = type;
3272 new_sublist->fn_field.is_stub = 1;
3274 new_sublist->fn_field.physname = savestring (*pp, p - *pp);
3277 /* Set this member function's visibility fields. */
3280 case VISIBILITY_PRIVATE:
3281 new_sublist->fn_field.is_private = 1;
3283 case VISIBILITY_PROTECTED:
3284 new_sublist->fn_field.is_protected = 1;
3288 STABS_CONTINUE (pp, objfile);
3291 case 'A': /* Normal functions. */
3292 new_sublist->fn_field.is_const = 0;
3293 new_sublist->fn_field.is_volatile = 0;
3296 case 'B': /* `const' member functions. */
3297 new_sublist->fn_field.is_const = 1;
3298 new_sublist->fn_field.is_volatile = 0;
3301 case 'C': /* `volatile' member function. */
3302 new_sublist->fn_field.is_const = 0;
3303 new_sublist->fn_field.is_volatile = 1;
3306 case 'D': /* `const volatile' member function. */
3307 new_sublist->fn_field.is_const = 1;
3308 new_sublist->fn_field.is_volatile = 1;
3311 case '*': /* File compiled with g++ version 1 -- no info */
3316 complain (&const_vol_complaint, **pp);
3325 /* virtual member function, followed by index.
3326 The sign bit is set to distinguish pointers-to-methods
3327 from virtual function indicies. Since the array is
3328 in words, the quantity must be shifted left by 1
3329 on 16 bit machine, and by 2 on 32 bit machine, forcing
3330 the sign bit out, and usable as a valid index into
3331 the array. Remove the sign bit here. */
3332 new_sublist->fn_field.voffset =
3333 (0x7fffffff & read_huge_number (pp, ';', &nbits)) + 2;
3337 STABS_CONTINUE (pp, objfile);
3338 if (**pp == ';' || **pp == '\0')
3340 /* Must be g++ version 1. */
3341 new_sublist->fn_field.fcontext = 0;
3345 /* Figure out from whence this virtual function came.
3346 It may belong to virtual function table of
3347 one of its baseclasses. */
3348 look_ahead_type = read_type (pp, objfile);
3351 /* g++ version 1 overloaded methods. */
3355 new_sublist->fn_field.fcontext = look_ahead_type;
3364 look_ahead_type = NULL;
3370 /* static member function. */
3372 int slen = strlen (main_fn_name);
3374 new_sublist->fn_field.voffset = VOFFSET_STATIC;
3376 /* For static member functions, we can't tell if they
3377 are stubbed, as they are put out as functions, and not as
3379 GCC v2 emits the fully mangled name if
3380 dbxout.c:flag_minimal_debug is not set, so we have to
3381 detect a fully mangled physname here and set is_stub
3382 accordingly. Fully mangled physnames in v2 start with
3383 the member function name, followed by two underscores.
3384 GCC v3 currently always emits stubbed member functions,
3385 but with fully mangled physnames, which start with _Z. */
3386 if (!(strncmp (new_sublist->fn_field.physname,
3387 main_fn_name, slen) == 0
3388 && new_sublist->fn_field.physname[slen] == '_'
3389 && new_sublist->fn_field.physname[slen + 1] == '_'))
3391 new_sublist->fn_field.is_stub = 1;
3398 complain (&member_fn_complaint, (*pp)[-1]);
3399 /* Fall through into normal member function. */
3402 /* normal member function. */
3403 new_sublist->fn_field.voffset = 0;
3404 new_sublist->fn_field.fcontext = 0;
3408 new_sublist->next = sublist;
3409 sublist = new_sublist;
3411 STABS_CONTINUE (pp, objfile);
3413 while (**pp != ';' && **pp != '\0');
3416 STABS_CONTINUE (pp, objfile);
3418 /* Skip GCC 3.X member functions which are duplicates of the callable
3419 constructor/destructor. */
3420 if (strcmp (main_fn_name, "__base_ctor") == 0
3421 || strcmp (main_fn_name, "__base_dtor") == 0
3422 || strcmp (main_fn_name, "__deleting_dtor") == 0)
3424 xfree (main_fn_name);
3429 int has_destructor = 0, has_other = 0;
3431 struct next_fnfield *tmp_sublist;
3433 /* Various versions of GCC emit various mostly-useless
3434 strings in the name field for special member functions.
3436 For stub methods, we need to defer correcting the name
3437 until we are ready to unstub the method, because the current
3438 name string is used by gdb_mangle_name. The only stub methods
3439 of concern here are GNU v2 operators; other methods have their
3440 names correct (see caveat below).
3442 For non-stub methods, in GNU v3, we have a complete physname.
3443 Therefore we can safely correct the name now. This primarily
3444 affects constructors and destructors, whose name will be
3445 __comp_ctor or __comp_dtor instead of Foo or ~Foo. Cast
3446 operators will also have incorrect names; for instance,
3447 "operator int" will be named "operator i" (i.e. the type is
3450 For non-stub methods in GNU v2, we have no easy way to
3451 know if we have a complete physname or not. For most
3452 methods the result depends on the platform (if CPLUS_MARKER
3453 can be `$' or `.', it will use minimal debug information, or
3454 otherwise the full physname will be included).
3456 Rather than dealing with this, we take a different approach.
3457 For v3 mangled names, we can use the full physname; for v2,
3458 we use cplus_demangle_opname (which is actually v2 specific),
3459 because the only interesting names are all operators - once again
3460 barring the caveat below. Skip this process if any method in the
3461 group is a stub, to prevent our fouling up the workings of
3464 The caveat: GCC 2.95.x (and earlier?) put constructors and
3465 destructors in the same method group. We need to split this
3466 into two groups, because they should have different names.
3467 So for each method group we check whether it contains both
3468 routines whose physname appears to be a destructor (the physnames
3469 for and destructors are always provided, due to quirks in v2
3470 mangling) and routines whose physname does not appear to be a
3471 destructor. If so then we break up the list into two halves.
3472 Even if the constructors and destructors aren't in the same group
3473 the destructor will still lack the leading tilde, so that also
3476 So, to summarize what we expect and handle here:
3478 Given Given Real Real Action
3479 method name physname physname method name
3481 __opi [none] __opi__3Foo operator int opname
3483 Foo _._3Foo _._3Foo ~Foo separate and
3485 operator i _ZN3FoocviEv _ZN3FoocviEv operator int demangle
3486 __comp_ctor _ZN3FooC1ERKS_ _ZN3FooC1ERKS_ Foo demangle
3489 tmp_sublist = sublist;
3490 while (tmp_sublist != NULL)
3492 if (tmp_sublist->fn_field.is_stub)
3494 if (tmp_sublist->fn_field.physname[0] == '_'
3495 && tmp_sublist->fn_field.physname[1] == 'Z')
3498 if (is_destructor_name (tmp_sublist->fn_field.physname))
3503 tmp_sublist = tmp_sublist->next;
3506 if (has_destructor && has_other)
3508 struct next_fnfieldlist *destr_fnlist;
3509 struct next_fnfield *last_sublist;
3511 /* Create a new fn_fieldlist for the destructors. */
3513 destr_fnlist = (struct next_fnfieldlist *)
3514 xmalloc (sizeof (struct next_fnfieldlist));
3515 make_cleanup (xfree, destr_fnlist);
3516 memset (destr_fnlist, 0, sizeof (struct next_fnfieldlist));
3517 destr_fnlist->fn_fieldlist.name
3518 = obconcat (&objfile->type_obstack, "", "~",
3519 new_fnlist->fn_fieldlist.name);
3521 destr_fnlist->fn_fieldlist.fn_fields = (struct fn_field *)
3522 obstack_alloc (&objfile->type_obstack,
3523 sizeof (struct fn_field) * has_destructor);
3524 memset (destr_fnlist->fn_fieldlist.fn_fields, 0,
3525 sizeof (struct fn_field) * has_destructor);
3526 tmp_sublist = sublist;
3527 last_sublist = NULL;
3529 while (tmp_sublist != NULL)
3531 if (!is_destructor_name (tmp_sublist->fn_field.physname))
3533 tmp_sublist = tmp_sublist->next;
3537 destr_fnlist->fn_fieldlist.fn_fields[i++]
3538 = tmp_sublist->fn_field;
3540 last_sublist->next = tmp_sublist->next;
3542 sublist = tmp_sublist->next;
3543 last_sublist = tmp_sublist;
3544 tmp_sublist = tmp_sublist->next;
3547 destr_fnlist->fn_fieldlist.length = has_destructor;
3548 destr_fnlist->next = fip->fnlist;
3549 fip->fnlist = destr_fnlist;
3551 total_length += has_destructor;
3552 length -= has_destructor;
3556 /* v3 mangling prevents the use of abbreviated physnames,
3557 so we can do this here. There are stubbed methods in v3
3559 - in -gstabs instead of -gstabs+
3560 - or for static methods, which are output as a function type
3561 instead of a method type. */
3563 update_method_name_from_physname (&new_fnlist->fn_fieldlist.name,
3564 sublist->fn_field.physname);
3566 else if (has_destructor && new_fnlist->fn_fieldlist.name[0] != '~')
3568 new_fnlist->fn_fieldlist.name = concat ("~", main_fn_name, NULL);
3569 xfree (main_fn_name);
3573 char dem_opname[256];
3575 ret = cplus_demangle_opname (new_fnlist->fn_fieldlist.name,
3576 dem_opname, DMGL_ANSI);
3578 ret = cplus_demangle_opname (new_fnlist->fn_fieldlist.name,
3581 new_fnlist->fn_fieldlist.name
3582 = obsavestring (dem_opname, strlen (dem_opname),
3583 &objfile->type_obstack);
3586 new_fnlist->fn_fieldlist.fn_fields = (struct fn_field *)
3587 obstack_alloc (&objfile->type_obstack,
3588 sizeof (struct fn_field) * length);
3589 memset (new_fnlist->fn_fieldlist.fn_fields, 0,
3590 sizeof (struct fn_field) * length);
3591 for (i = length; (i--, sublist); sublist = sublist->next)
3593 new_fnlist->fn_fieldlist.fn_fields[i] = sublist->fn_field;
3596 new_fnlist->fn_fieldlist.length = length;
3597 new_fnlist->next = fip->fnlist;
3598 fip->fnlist = new_fnlist;
3600 total_length += length;
3606 ALLOCATE_CPLUS_STRUCT_TYPE (type);
3607 TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
3608 TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * nfn_fields);
3609 memset (TYPE_FN_FIELDLISTS (type), 0,
3610 sizeof (struct fn_fieldlist) * nfn_fields);
3611 TYPE_NFN_FIELDS (type) = nfn_fields;
3612 TYPE_NFN_FIELDS_TOTAL (type) = total_length;
3618 /* Special GNU C++ name.
3620 Returns 1 for success, 0 for failure. "failure" means that we can't
3621 keep parsing and it's time for error_type(). */
3624 read_cpp_abbrev (struct field_info *fip, char **pp, struct type *type,
3625 struct objfile *objfile)
3630 struct type *context;
3640 /* At this point, *pp points to something like "22:23=*22...",
3641 where the type number before the ':' is the "context" and
3642 everything after is a regular type definition. Lookup the
3643 type, find it's name, and construct the field name. */
3645 context = read_type (pp, objfile);
3649 case 'f': /* $vf -- a virtual function table pointer */
3650 name = type_name_no_tag (context);
3655 fip->list->field.name =
3656 obconcat (&objfile->type_obstack, vptr_name, name, "");
3659 case 'b': /* $vb -- a virtual bsomethingorother */
3660 name = type_name_no_tag (context);
3663 complain (&invalid_cpp_type_complaint, symnum);
3666 fip->list->field.name =
3667 obconcat (&objfile->type_obstack, vb_name, name, "");
3671 complain (&invalid_cpp_abbrev_complaint, *pp);
3672 fip->list->field.name =
3673 obconcat (&objfile->type_obstack,
3674 "INVALID_CPLUSPLUS_ABBREV", "", "");
3678 /* At this point, *pp points to the ':'. Skip it and read the
3684 complain (&invalid_cpp_abbrev_complaint, *pp);
3687 fip->list->field.type = read_type (pp, objfile);
3689 (*pp)++; /* Skip the comma. */
3695 FIELD_BITPOS (fip->list->field) = read_huge_number (pp, ';', &nbits);
3699 /* This field is unpacked. */
3700 FIELD_BITSIZE (fip->list->field) = 0;
3701 fip->list->visibility = VISIBILITY_PRIVATE;
3705 complain (&invalid_cpp_abbrev_complaint, *pp);
3706 /* We have no idea what syntax an unrecognized abbrev would have, so
3707 better return 0. If we returned 1, we would need to at least advance
3708 *pp to avoid an infinite loop. */
3715 read_one_struct_field (struct field_info *fip, char **pp, char *p,
3716 struct type *type, struct objfile *objfile)
3718 /* The following is code to work around cfront generated stabs.
3719 The stabs contains full mangled name for each field.
3720 We try to demangle the name and extract the field name out of it.
3722 if (ARM_DEMANGLING && current_subfile->language == language_cplus)
3728 dem = cplus_demangle (*pp, DMGL_ANSI | DMGL_PARAMS);
3731 dem_p = strrchr (dem, ':');
3732 if (dem_p != 0 && *(dem_p - 1) == ':')
3734 FIELD_NAME (fip->list->field) =
3735 obsavestring (dem_p, strlen (dem_p), &objfile->type_obstack);
3739 FIELD_NAME (fip->list->field) =
3740 obsavestring (*pp, p - *pp, &objfile->type_obstack);
3744 /* end of code for cfront work around */
3747 fip->list->field.name =
3748 obsavestring (*pp, p - *pp, &objfile->type_obstack);
3751 /* This means we have a visibility for a field coming. */
3755 fip->list->visibility = *(*pp)++;
3759 /* normal dbx-style format, no explicit visibility */
3760 fip->list->visibility = VISIBILITY_PUBLIC;
3763 fip->list->field.type = read_type (pp, objfile);
3768 /* Possible future hook for nested types. */
3771 fip->list->field.bitpos = (long) -2; /* nested type */
3781 /* Static class member. */
3782 SET_FIELD_PHYSNAME (fip->list->field, savestring (*pp, p - *pp));
3786 else if (**pp != ',')
3788 /* Bad structure-type format. */
3789 complain (&stabs_general_complaint, "bad structure-type format");
3793 (*pp)++; /* Skip the comma. */
3797 FIELD_BITPOS (fip->list->field) = read_huge_number (pp, ',', &nbits);
3800 complain (&stabs_general_complaint, "bad structure-type format");
3803 FIELD_BITSIZE (fip->list->field) = read_huge_number (pp, ';', &nbits);
3806 complain (&stabs_general_complaint, "bad structure-type format");
3811 if (FIELD_BITPOS (fip->list->field) == 0
3812 && FIELD_BITSIZE (fip->list->field) == 0)
3814 /* This can happen in two cases: (1) at least for gcc 2.4.5 or so,
3815 it is a field which has been optimized out. The correct stab for
3816 this case is to use VISIBILITY_IGNORE, but that is a recent
3817 invention. (2) It is a 0-size array. For example
3818 union { int num; char str[0]; } foo. Printing "<no value>" for
3819 str in "p foo" is OK, since foo.str (and thus foo.str[3])
3820 will continue to work, and a 0-size array as a whole doesn't
3821 have any contents to print.
3823 I suspect this probably could also happen with gcc -gstabs (not
3824 -gstabs+) for static fields, and perhaps other C++ extensions.
3825 Hopefully few people use -gstabs with gdb, since it is intended
3826 for dbx compatibility. */
3828 /* Ignore this field. */
3829 fip->list->visibility = VISIBILITY_IGNORE;
3833 /* Detect an unpacked field and mark it as such.
3834 dbx gives a bit size for all fields.
3835 Note that forward refs cannot be packed,
3836 and treat enums as if they had the width of ints. */
3838 struct type *field_type = check_typedef (FIELD_TYPE (fip->list->field));
3840 if (TYPE_CODE (field_type) != TYPE_CODE_INT
3841 && TYPE_CODE (field_type) != TYPE_CODE_RANGE
3842 && TYPE_CODE (field_type) != TYPE_CODE_BOOL
3843 && TYPE_CODE (field_type) != TYPE_CODE_ENUM)
3845 FIELD_BITSIZE (fip->list->field) = 0;
3847 if ((FIELD_BITSIZE (fip->list->field)
3848 == TARGET_CHAR_BIT * TYPE_LENGTH (field_type)
3849 || (TYPE_CODE (field_type) == TYPE_CODE_ENUM
3850 && FIELD_BITSIZE (fip->list->field) == TARGET_INT_BIT)
3853 FIELD_BITPOS (fip->list->field) % 8 == 0)
3855 FIELD_BITSIZE (fip->list->field) = 0;
3861 /* Read struct or class data fields. They have the form:
3863 NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
3865 At the end, we see a semicolon instead of a field.
3867 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
3870 The optional VISIBILITY is one of:
3872 '/0' (VISIBILITY_PRIVATE)
3873 '/1' (VISIBILITY_PROTECTED)
3874 '/2' (VISIBILITY_PUBLIC)
3875 '/9' (VISIBILITY_IGNORE)
3877 or nothing, for C style fields with public visibility.
3879 Returns 1 for success, 0 for failure. */
3882 read_struct_fields (struct field_info *fip, char **pp, struct type *type,
3883 struct objfile *objfile)
3886 struct nextfield *new;
3888 /* We better set p right now, in case there are no fields at all... */
3892 /* Read each data member type until we find the terminating ';' at the end of
3893 the data member list, or break for some other reason such as finding the
3894 start of the member function list. */
3895 /* Stab string for structure/union does not end with two ';' in
3896 SUN C compiler 5.3 i.e. F6U2, hence check for end of string. */
3898 while (**pp != ';' && **pp != '\0')
3900 #if 0 /* OBSOLETE OS9K */
3901 // OBSOLETE if (os9k_stabs && **pp == ',')
3903 #endif /* OBSOLETE OS9K */
3904 STABS_CONTINUE (pp, objfile);
3905 /* Get space to record the next field's data. */
3906 new = (struct nextfield *) xmalloc (sizeof (struct nextfield));
3907 make_cleanup (xfree, new);
3908 memset (new, 0, sizeof (struct nextfield));
3909 new->next = fip->list;
3912 /* Get the field name. */
3915 /* If is starts with CPLUS_MARKER it is a special abbreviation,
3916 unless the CPLUS_MARKER is followed by an underscore, in
3917 which case it is just the name of an anonymous type, which we
3918 should handle like any other type name. */
3920 if (is_cplus_marker (p[0]) && p[1] != '_')
3922 if (!read_cpp_abbrev (fip, pp, type, objfile))
3927 /* Look for the ':' that separates the field name from the field
3928 values. Data members are delimited by a single ':', while member
3929 functions are delimited by a pair of ':'s. When we hit the member
3930 functions (if any), terminate scan loop and return. */
3932 while (*p != ':' && *p != '\0')
3939 /* Check to see if we have hit the member functions yet. */
3944 read_one_struct_field (fip, pp, p, type, objfile);
3946 if (p[0] == ':' && p[1] == ':')
3948 /* (OBSOLETE) chill (OBSOLETE) the list of fields: the last
3949 entry (at the head) is a partially constructed entry which we
3951 fip->list = fip->list->next;
3956 /* The stabs for C++ derived classes contain baseclass information which
3957 is marked by a '!' character after the total size. This function is
3958 called when we encounter the baseclass marker, and slurps up all the
3959 baseclass information.
3961 Immediately following the '!' marker is the number of base classes that
3962 the class is derived from, followed by information for each base class.
3963 For each base class, there are two visibility specifiers, a bit offset
3964 to the base class information within the derived class, a reference to
3965 the type for the base class, and a terminating semicolon.
3967 A typical example, with two base classes, would be "!2,020,19;0264,21;".
3969 Baseclass information marker __________________|| | | | | | |
3970 Number of baseclasses __________________________| | | | | | |
3971 Visibility specifiers (2) ________________________| | | | | |
3972 Offset in bits from start of class _________________| | | | |
3973 Type number for base class ___________________________| | | |
3974 Visibility specifiers (2) _______________________________| | |
3975 Offset in bits from start of class ________________________| |
3976 Type number of base class ____________________________________|
3978 Return 1 for success, 0 for (error-type-inducing) failure. */
3984 read_baseclasses (struct field_info *fip, char **pp, struct type *type,
3985 struct objfile *objfile)
3988 struct nextfield *new;
3996 /* Skip the '!' baseclass information marker. */
4000 ALLOCATE_CPLUS_STRUCT_TYPE (type);
4003 TYPE_N_BASECLASSES (type) = read_huge_number (pp, ',', &nbits);
4009 /* Some stupid compilers have trouble with the following, so break
4010 it up into simpler expressions. */
4011 TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *)
4012 TYPE_ALLOC (type, B_BYTES (TYPE_N_BASECLASSES (type)));
4015 int num_bytes = B_BYTES (TYPE_N_BASECLASSES (type));
4018 pointer = (char *) TYPE_ALLOC (type, num_bytes);
4019 TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *) pointer;
4023 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), TYPE_N_BASECLASSES (type));
4025 for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
4027 new = (struct nextfield *) xmalloc (sizeof (struct nextfield));
4028 make_cleanup (xfree, new);
4029 memset (new, 0, sizeof (struct nextfield));
4030 new->next = fip->list;
4032 FIELD_BITSIZE (new->field) = 0; /* this should be an unpacked field! */
4034 STABS_CONTINUE (pp, objfile);
4038 /* Nothing to do. */
4041 SET_TYPE_FIELD_VIRTUAL (type, i);
4044 /* Unknown character. Complain and treat it as non-virtual. */
4046 static struct complaint msg =
4048 "Unknown virtual character `%c' for baseclass", 0, 0};
4049 complain (&msg, **pp);
4054 new->visibility = *(*pp)++;
4055 switch (new->visibility)
4057 case VISIBILITY_PRIVATE:
4058 case VISIBILITY_PROTECTED:
4059 case VISIBILITY_PUBLIC:
4062 /* Bad visibility format. Complain and treat it as
4065 static struct complaint msg =
4067 "Unknown visibility `%c' for baseclass", 0, 0
4069 complain (&msg, new->visibility);
4070 new->visibility = VISIBILITY_PUBLIC;
4077 /* The remaining value is the bit offset of the portion of the object
4078 corresponding to this baseclass. Always zero in the absence of
4079 multiple inheritance. */
4081 FIELD_BITPOS (new->field) = read_huge_number (pp, ',', &nbits);
4086 /* The last piece of baseclass information is the type of the
4087 base class. Read it, and remember it's type name as this
4090 new->field.type = read_type (pp, objfile);
4091 new->field.name = type_name_no_tag (new->field.type);
4093 /* skip trailing ';' and bump count of number of fields seen */
4102 /* The tail end of stabs for C++ classes that contain a virtual function
4103 pointer contains a tilde, a %, and a type number.
4104 The type number refers to the base class (possibly this class itself) which
4105 contains the vtable pointer for the current class.
4107 This function is called when we have parsed all the method declarations,
4108 so we can look for the vptr base class info. */
4111 read_tilde_fields (struct field_info *fip, char **pp, struct type *type,
4112 struct objfile *objfile)
4116 STABS_CONTINUE (pp, objfile);
4118 /* If we are positioned at a ';', then skip it. */
4128 if (**pp == '=' || **pp == '+' || **pp == '-')
4130 /* Obsolete flags that used to indicate the presence
4131 of constructors and/or destructors. */
4135 /* Read either a '%' or the final ';'. */
4136 if (*(*pp)++ == '%')
4138 /* The next number is the type number of the base class
4139 (possibly our own class) which supplies the vtable for
4140 this class. Parse it out, and search that class to find
4141 its vtable pointer, and install those into TYPE_VPTR_BASETYPE
4142 and TYPE_VPTR_FIELDNO. */
4147 t = read_type (pp, objfile);
4149 while (*p != '\0' && *p != ';')
4155 /* Premature end of symbol. */
4159 TYPE_VPTR_BASETYPE (type) = t;
4160 if (type == t) /* Our own class provides vtbl ptr */
4162 for (i = TYPE_NFIELDS (t) - 1;
4163 i >= TYPE_N_BASECLASSES (t);
4166 if (!strncmp (TYPE_FIELD_NAME (t, i), vptr_name,
4167 sizeof (vptr_name) - 1))
4169 TYPE_VPTR_FIELDNO (type) = i;
4173 /* Virtual function table field not found. */
4174 complain (&vtbl_notfound_complaint, TYPE_NAME (type));
4179 TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t);
4190 attach_fn_fields_to_type (struct field_info *fip, register struct type *type)
4194 for (n = TYPE_NFN_FIELDS (type);
4195 fip->fnlist != NULL;
4196 fip->fnlist = fip->fnlist->next)
4198 --n; /* Circumvent Sun3 compiler bug */
4199 TYPE_FN_FIELDLISTS (type)[n] = fip->fnlist->fn_fieldlist;
4204 /* read cfront class static data.
4205 pp points to string starting with the list of static data
4206 eg: A:ZcA;1@Bpub v2@Bvirpri;__ct__1AFv func__1AFv *sfunc__1AFv ;as__1A ;;
4209 A:ZcA;;foopri__1AFv foopro__1AFv __ct__1AFv __ct__1AFRC1A foopub__1AFv ;;;
4214 read_cfront_static_fields (struct field_info *fip, char **pp, struct type *type,
4215 struct objfile *objfile)
4217 struct nextfield *new;
4220 struct symbol *ref_static = 0;
4222 if (**pp == ';') /* no static data; return */
4228 /* Process each field in the list until we find the terminating ";" */
4230 /* eg: p = "as__1A ;;;" */
4231 STABS_CONTINUE (pp, objfile); /* handle \\ */
4232 while (**pp != ';' && (sname = get_substring (pp, ' '), sname))
4234 ref_static = lookup_symbol (sname, 0, VAR_NAMESPACE, 0, 0); /*demangled_name */
4237 static struct complaint msg =
4239 Unable to find symbol for static data field %s\n",
4241 complain (&msg, sname);
4244 stype = SYMBOL_TYPE (ref_static);
4246 /* allocate a new fip */
4247 new = (struct nextfield *) xmalloc (sizeof (struct nextfield));
4248 make_cleanup (xfree, new);
4249 memset (new, 0, sizeof (struct nextfield));
4250 new->next = fip->list;
4253 /* set visibility */
4254 /* FIXME! no way to tell visibility from stabs??? */
4255 new->visibility = VISIBILITY_PUBLIC;
4257 /* set field info into fip */
4258 fip->list->field.type = stype;
4260 /* set bitpos & bitsize */
4261 SET_FIELD_PHYSNAME (fip->list->field, savestring (sname, strlen (sname)));
4263 /* set name field */
4264 /* The following is code to work around cfront generated stabs.
4265 The stabs contains full mangled name for each field.
4266 We try to demangle the name and extract the field name out of it.
4271 dem = cplus_demangle (sname, DMGL_ANSI | DMGL_PARAMS);
4274 dem_p = strrchr (dem, ':');
4275 if (dem_p != 0 && *(dem_p - 1) == ':')
4277 fip->list->field.name =
4278 obsavestring (dem_p, strlen (dem_p), &objfile->type_obstack);
4282 fip->list->field.name =
4283 obsavestring (sname, strlen (sname), &objfile->type_obstack);
4285 } /* end of code for cfront work around */
4286 } /* loop again for next static field */
4290 /* Copy structure fields to fip so attach_fields_to_type will work.
4291 type has already been created with the initial instance data fields.
4292 Now we want to be able to add the other members to the class,
4293 so we want to add them back to the fip and reattach them again
4294 once we have collected all the class members. */
4297 copy_cfront_struct_fields (struct field_info *fip, struct type *type,
4298 struct objfile *objfile)
4300 int nfields = TYPE_NFIELDS (type);
4302 struct nextfield *new;
4304 /* Copy the fields into the list of fips and reset the types
4305 to remove the old fields */
4307 for (i = 0; i < nfields; i++)
4309 /* allocate a new fip */
4310 new = (struct nextfield *) xmalloc (sizeof (struct nextfield));
4311 make_cleanup (xfree, new);
4312 memset (new, 0, sizeof (struct nextfield));
4313 new->next = fip->list;
4316 /* copy field info into fip */
4317 new->field = TYPE_FIELD (type, i);
4318 /* set visibility */
4319 if (TYPE_FIELD_PROTECTED (type, i))
4320 new->visibility = VISIBILITY_PROTECTED;
4321 else if (TYPE_FIELD_PRIVATE (type, i))
4322 new->visibility = VISIBILITY_PRIVATE;
4324 new->visibility = VISIBILITY_PUBLIC;
4326 /* Now delete the fields from the type since we will be
4327 allocing new space once we get the rest of the fields
4328 in attach_fields_to_type.
4329 The pointer TYPE_FIELDS(type) is left dangling but should
4330 be freed later by objstack_free */
4331 TYPE_FIELDS (type) = 0;
4332 TYPE_NFIELDS (type) = 0;
4337 /* Create the vector of fields, and record how big it is.
4338 We need this info to record proper virtual function table information
4339 for this class's virtual functions. */
4342 attach_fields_to_type (struct field_info *fip, register struct type *type,
4343 struct objfile *objfile)
4345 register int nfields = 0;
4346 register int non_public_fields = 0;
4347 register struct nextfield *scan;
4349 /* Count up the number of fields that we have, as well as taking note of
4350 whether or not there are any non-public fields, which requires us to
4351 allocate and build the private_field_bits and protected_field_bits
4354 for (scan = fip->list; scan != NULL; scan = scan->next)
4357 if (scan->visibility != VISIBILITY_PUBLIC)
4359 non_public_fields++;
4363 /* Now we know how many fields there are, and whether or not there are any
4364 non-public fields. Record the field count, allocate space for the
4365 array of fields, and create blank visibility bitfields if necessary. */
4367 TYPE_NFIELDS (type) = nfields;
4368 TYPE_FIELDS (type) = (struct field *)
4369 TYPE_ALLOC (type, sizeof (struct field) * nfields);
4370 memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields);
4372 if (non_public_fields)
4374 ALLOCATE_CPLUS_STRUCT_TYPE (type);
4376 TYPE_FIELD_PRIVATE_BITS (type) =
4377 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
4378 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields);
4380 TYPE_FIELD_PROTECTED_BITS (type) =
4381 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
4382 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields);
4384 TYPE_FIELD_IGNORE_BITS (type) =
4385 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
4386 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields);
4389 /* Copy the saved-up fields into the field vector. Start from the head
4390 of the list, adding to the tail of the field array, so that they end
4391 up in the same order in the array in which they were added to the list. */
4393 while (nfields-- > 0)
4395 TYPE_FIELD (type, nfields) = fip->list->field;
4396 switch (fip->list->visibility)
4398 case VISIBILITY_PRIVATE:
4399 SET_TYPE_FIELD_PRIVATE (type, nfields);
4402 case VISIBILITY_PROTECTED:
4403 SET_TYPE_FIELD_PROTECTED (type, nfields);
4406 case VISIBILITY_IGNORE:
4407 SET_TYPE_FIELD_IGNORE (type, nfields);
4410 case VISIBILITY_PUBLIC:
4414 /* Unknown visibility. Complain and treat it as public. */
4416 static struct complaint msg =
4418 "Unknown visibility `%c' for field", 0, 0};
4419 complain (&msg, fip->list->visibility);
4423 fip->list = fip->list->next;
4429 static struct complaint multiply_defined_struct =
4430 {"struct/union type gets multiply defined: %s%s", 0, 0};
4433 /* Complain that the compiler has emitted more than one definition for the
4434 structure type TYPE. */
4436 complain_about_struct_wipeout (struct type *type)
4441 if (TYPE_TAG_NAME (type))
4443 name = TYPE_TAG_NAME (type);
4444 switch (TYPE_CODE (type))
4446 case TYPE_CODE_STRUCT: kind = "struct "; break;
4447 case TYPE_CODE_UNION: kind = "union "; break;
4448 case TYPE_CODE_ENUM: kind = "enum "; break;
4452 else if (TYPE_NAME (type))
4454 name = TYPE_NAME (type);
4463 complain (&multiply_defined_struct, kind, name);
4467 /* Read the description of a structure (or union type) and return an object
4468 describing the type.
4470 PP points to a character pointer that points to the next unconsumed token
4471 in the the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;",
4472 *PP will point to "4a:1,0,32;;".
4474 TYPE points to an incomplete type that needs to be filled in.
4476 OBJFILE points to the current objfile from which the stabs information is
4477 being read. (Note that it is redundant in that TYPE also contains a pointer
4478 to this same objfile, so it might be a good idea to eliminate it. FIXME).
4481 static struct type *
4482 read_struct_type (char **pp, struct type *type, enum type_code type_code,
4483 struct objfile *objfile)
4485 struct cleanup *back_to;
4486 struct field_info fi;
4491 /* When describing struct/union/class types in stabs, G++ always drops
4492 all qualifications from the name. So if you've got:
4493 struct A { ... struct B { ... }; ... };
4494 then G++ will emit stabs for `struct A::B' that call it simply
4495 `struct B'. Obviously, if you've got a real top-level definition for
4496 `struct B', or other nested definitions, this is going to cause
4499 Obviously, GDB can't fix this by itself, but it can at least avoid
4500 scribbling on existing structure type objects when new definitions
4502 if (! (TYPE_CODE (type) == TYPE_CODE_UNDEF
4503 || TYPE_STUB (type)))
4505 complain_about_struct_wipeout (type);
4507 /* It's probably best to return the type unchanged. */
4511 back_to = make_cleanup (null_cleanup, 0);
4513 INIT_CPLUS_SPECIFIC (type);
4514 TYPE_CODE (type) = type_code;
4515 TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
4517 /* First comes the total size in bytes. */
4521 TYPE_LENGTH (type) = read_huge_number (pp, 0, &nbits);
4523 return error_type (pp, objfile);
4526 /* Now read the baseclasses, if any, read the regular C struct or C++
4527 class member fields, attach the fields to the type, read the C++
4528 member functions, attach them to the type, and then read any tilde
4529 field (baseclass specifier for the class holding the main vtable). */
4531 if (!read_baseclasses (&fi, pp, type, objfile)
4532 || !read_struct_fields (&fi, pp, type, objfile)
4533 || !attach_fields_to_type (&fi, type, objfile)
4534 || !read_member_functions (&fi, pp, type, objfile)
4535 || !attach_fn_fields_to_type (&fi, type)
4536 || !read_tilde_fields (&fi, pp, type, objfile))
4538 type = error_type (pp, objfile);
4541 do_cleanups (back_to);
4545 /* Read a definition of an array type,
4546 and create and return a suitable type object.
4547 Also creates a range type which represents the bounds of that
4550 static struct type *
4551 read_array_type (register char **pp, register struct type *type,
4552 struct objfile *objfile)
4554 struct type *index_type, *element_type, *range_type;
4559 /* Format of an array type:
4560 "ar<index type>;lower;upper;<array_contents_type>".
4561 OS9000: "arlower,upper;<array_contents_type>".
4563 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
4564 for these, produce a type like float[][]. */
4566 #if 0 /* OBSOLETE OS9K */
4567 // OBSOLETE if (os9k_stabs)
4568 // OBSOLETE index_type = builtin_type_int;
4570 #endif /* OBSOLETE OS9K */
4572 index_type = read_type (pp, objfile);
4574 /* Improper format of array type decl. */
4575 return error_type (pp, objfile);
4579 if (!(**pp >= '0' && **pp <= '9') && **pp != '-')
4584 #if 0 /* OBSOLETE OS9K */
4585 // OBSOLETE lower = read_huge_number (pp, os9k_stabs ? ',' : ';', &nbits);
4586 #else /* OBSOLETE OS9K */
4587 lower = read_huge_number (pp, ';', &nbits);
4588 #endif /* OBSOLETE OS9K */
4591 return error_type (pp, objfile);
4593 if (!(**pp >= '0' && **pp <= '9') && **pp != '-')
4598 upper = read_huge_number (pp, ';', &nbits);
4600 return error_type (pp, objfile);
4602 element_type = read_type (pp, objfile);
4611 create_range_type ((struct type *) NULL, index_type, lower, upper);
4612 type = create_array_type (type, element_type, range_type);
4618 /* Read a definition of an enumeration type,
4619 and create and return a suitable type object.
4620 Also defines the symbols that represent the values of the type. */
4622 static struct type *
4623 read_enum_type (register char **pp, register struct type *type,
4624 struct objfile *objfile)
4629 register struct symbol *sym;
4631 struct pending **symlist;
4632 struct pending *osyms, *syms;
4635 int unsigned_enum = 1;
4638 /* FIXME! The stabs produced by Sun CC merrily define things that ought
4639 to be file-scope, between N_FN entries, using N_LSYM. What's a mother
4640 to do? For now, force all enum values to file scope. */
4641 if (within_function)
4642 symlist = &local_symbols;
4645 symlist = &file_symbols;
4647 o_nsyms = osyms ? osyms->nsyms : 0;
4649 #if 0 /* OBSOLETE OS9K */
4650 // OBSOLETE if (os9k_stabs)
4652 // OBSOLETE /* Size. Perhaps this does not have to be conditionalized on
4653 // OBSOLETE os9k_stabs (assuming the name of an enum constant can't start
4654 // OBSOLETE with a digit). */
4655 // OBSOLETE read_huge_number (pp, 0, &nbits);
4656 // OBSOLETE if (nbits != 0)
4657 // OBSOLETE return error_type (pp, objfile);
4659 #endif /* OBSOLETE OS9K */
4661 /* The aix4 compiler emits an extra field before the enum members;
4662 my guess is it's a type of some sort. Just ignore it. */
4665 /* Skip over the type. */
4669 /* Skip over the colon. */
4673 /* Read the value-names and their values.
4674 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
4675 A semicolon or comma instead of a NAME means the end. */
4676 while (**pp && **pp != ';' && **pp != ',')
4678 STABS_CONTINUE (pp, objfile);
4682 name = obsavestring (*pp, p - *pp, &objfile->symbol_obstack);
4684 n = read_huge_number (pp, ',', &nbits);
4686 return error_type (pp, objfile);
4688 sym = (struct symbol *)
4689 obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol));
4690 memset (sym, 0, sizeof (struct symbol));
4691 SYMBOL_NAME (sym) = name;
4692 SYMBOL_LANGUAGE (sym) = current_subfile->language;
4693 SYMBOL_CLASS (sym) = LOC_CONST;
4694 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
4695 SYMBOL_VALUE (sym) = n;
4698 add_symbol_to_list (sym, symlist);
4703 (*pp)++; /* Skip the semicolon. */
4705 /* Now fill in the fields of the type-structure. */
4707 TYPE_LENGTH (type) = TARGET_INT_BIT / HOST_CHAR_BIT;
4708 TYPE_CODE (type) = TYPE_CODE_ENUM;
4709 TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
4711 TYPE_FLAGS (type) |= TYPE_FLAG_UNSIGNED;
4712 TYPE_NFIELDS (type) = nsyms;
4713 TYPE_FIELDS (type) = (struct field *)
4714 TYPE_ALLOC (type, sizeof (struct field) * nsyms);
4715 memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nsyms);
4717 /* Find the symbols for the values and put them into the type.
4718 The symbols can be found in the symlist that we put them on
4719 to cause them to be defined. osyms contains the old value
4720 of that symlist; everything up to there was defined by us. */
4721 /* Note that we preserve the order of the enum constants, so
4722 that in something like "enum {FOO, LAST_THING=FOO}" we print
4723 FOO, not LAST_THING. */
4725 for (syms = *symlist, n = nsyms - 1; syms; syms = syms->next)
4727 int last = syms == osyms ? o_nsyms : 0;
4728 int j = syms->nsyms;
4729 for (; --j >= last; --n)
4731 struct symbol *xsym = syms->symbol[j];
4732 SYMBOL_TYPE (xsym) = type;
4733 TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym);
4734 TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (xsym);
4735 TYPE_FIELD_BITSIZE (type, n) = 0;
4744 /* Sun's ACC uses a somewhat saner method for specifying the builtin
4745 typedefs in every file (for int, long, etc):
4747 type = b <signed> <width> <format type>; <offset>; <nbits>
4749 optional format type = c or b for char or boolean.
4750 offset = offset from high order bit to start bit of type.
4751 width is # bytes in object of this type, nbits is # bits in type.
4753 The width/offset stuff appears to be for small objects stored in
4754 larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
4757 static struct type *
4758 read_sun_builtin_type (char **pp, int typenums[2], struct objfile *objfile)
4763 enum type_code code = TYPE_CODE_INT;
4774 return error_type (pp, objfile);
4778 /* For some odd reason, all forms of char put a c here. This is strange
4779 because no other type has this honor. We can safely ignore this because
4780 we actually determine 'char'acterness by the number of bits specified in
4782 Boolean forms, e.g Fortran logical*X, put a b here. */
4786 else if (**pp == 'b')
4788 code = TYPE_CODE_BOOL;
4792 /* The first number appears to be the number of bytes occupied
4793 by this type, except that unsigned short is 4 instead of 2.
4794 Since this information is redundant with the third number,
4795 we will ignore it. */
4796 read_huge_number (pp, ';', &nbits);
4798 return error_type (pp, objfile);
4800 /* The second number is always 0, so ignore it too. */
4801 read_huge_number (pp, ';', &nbits);
4803 return error_type (pp, objfile);
4805 /* The third number is the number of bits for this type. */
4806 type_bits = read_huge_number (pp, 0, &nbits);
4808 return error_type (pp, objfile);
4809 /* The type *should* end with a semicolon. If it are embedded
4810 in a larger type the semicolon may be the only way to know where
4811 the type ends. If this type is at the end of the stabstring we
4812 can deal with the omitted semicolon (but we don't have to like
4813 it). Don't bother to complain(), Sun's compiler omits the semicolon
4819 return init_type (TYPE_CODE_VOID, 1,
4820 signed_type ? 0 : TYPE_FLAG_UNSIGNED, (char *) NULL,
4823 return init_type (code,
4824 type_bits / TARGET_CHAR_BIT,
4825 signed_type ? 0 : TYPE_FLAG_UNSIGNED, (char *) NULL,
4829 static struct type *
4830 read_sun_floating_type (char **pp, int typenums[2], struct objfile *objfile)
4835 struct type *rettype;
4837 /* The first number has more details about the type, for example
4839 details = read_huge_number (pp, ';', &nbits);
4841 return error_type (pp, objfile);
4843 /* The second number is the number of bytes occupied by this type */
4844 nbytes = read_huge_number (pp, ';', &nbits);
4846 return error_type (pp, objfile);
4848 if (details == NF_COMPLEX || details == NF_COMPLEX16
4849 || details == NF_COMPLEX32)
4851 rettype = init_type (TYPE_CODE_COMPLEX, nbytes, 0, NULL, objfile);
4852 TYPE_TARGET_TYPE (rettype)
4853 = init_type (TYPE_CODE_FLT, nbytes / 2, 0, NULL, objfile);
4857 return init_type (TYPE_CODE_FLT, nbytes, 0, NULL, objfile);
4860 /* Read a number from the string pointed to by *PP.
4861 The value of *PP is advanced over the number.
4862 If END is nonzero, the character that ends the
4863 number must match END, or an error happens;
4864 and that character is skipped if it does match.
4865 If END is zero, *PP is left pointing to that character.
4867 If the number fits in a long, set *BITS to 0 and return the value.
4868 If not, set *BITS to be the number of bits in the number and return 0.
4870 If encounter garbage, set *BITS to -1 and return 0. */
4873 read_huge_number (char **pp, int end, int *bits)
4890 /* Leading zero means octal. GCC uses this to output values larger
4891 than an int (because that would be hard in decimal). */
4898 #if 0 /* OBSOLETE OS9K */
4899 // OBSOLETE if (os9k_stabs)
4900 // OBSOLETE upper_limit = ULONG_MAX / radix;
4902 #endif /* OBSOLETE OS9K */
4903 upper_limit = LONG_MAX / radix;
4905 while ((c = *p++) >= '0' && c < ('0' + radix))
4907 if (n <= upper_limit)
4910 n += c - '0'; /* FIXME this overflows anyway */
4915 /* This depends on large values being output in octal, which is
4922 /* Ignore leading zeroes. */
4926 else if (c == '2' || c == '3')
4952 /* Large decimal constants are an error (because it is hard to
4953 count how many bits are in them). */
4959 /* -0x7f is the same as 0x80. So deal with it by adding one to
4960 the number of bits. */
4972 /* It's *BITS which has the interesting information. */
4976 static struct type *
4977 read_range_type (char **pp, int typenums[2], struct objfile *objfile)
4979 char *orig_pp = *pp;
4984 struct type *result_type;
4985 struct type *index_type = NULL;
4987 /* First comes a type we are a subrange of.
4988 In C it is usually 0, 1 or the type being defined. */
4989 if (read_type_number (pp, rangenums) != 0)
4990 return error_type (pp, objfile);
4991 self_subrange = (rangenums[0] == typenums[0] &&
4992 rangenums[1] == typenums[1]);
4997 index_type = read_type (pp, objfile);
5000 /* A semicolon should now follow; skip it. */
5004 /* The remaining two operands are usually lower and upper bounds
5005 of the range. But in some special cases they mean something else. */
5006 n2 = read_huge_number (pp, ';', &n2bits);
5007 n3 = read_huge_number (pp, ';', &n3bits);
5009 if (n2bits == -1 || n3bits == -1)
5010 return error_type (pp, objfile);
5013 goto handle_true_range;
5015 /* If limits are huge, must be large integral type. */
5016 if (n2bits != 0 || n3bits != 0)
5018 char got_signed = 0;
5019 char got_unsigned = 0;
5020 /* Number of bits in the type. */
5023 /* Range from 0 to <large number> is an unsigned large integral type. */
5024 if ((n2bits == 0 && n2 == 0) && n3bits != 0)
5029 /* Range from <large number> to <large number>-1 is a large signed
5030 integral type. Take care of the case where <large number> doesn't
5031 fit in a long but <large number>-1 does. */
5032 else if ((n2bits != 0 && n3bits != 0 && n2bits == n3bits + 1)
5033 || (n2bits != 0 && n3bits == 0
5034 && (n2bits == sizeof (long) * HOST_CHAR_BIT)
5041 if (got_signed || got_unsigned)
5043 return init_type (TYPE_CODE_INT, nbits / TARGET_CHAR_BIT,
5044 got_unsigned ? TYPE_FLAG_UNSIGNED : 0, NULL,
5048 return error_type (pp, objfile);
5051 /* A type defined as a subrange of itself, with bounds both 0, is void. */
5052 if (self_subrange && n2 == 0 && n3 == 0)
5053 return init_type (TYPE_CODE_VOID, 1, 0, NULL, objfile);
5055 /* If n3 is zero and n2 is positive, we want a floating type, and n2
5056 is the width in bytes.
5058 Fortran programs appear to use this for complex types also. To
5059 distinguish between floats and complex, g77 (and others?) seem
5060 to use self-subranges for the complexes, and subranges of int for
5063 Also note that for complexes, g77 sets n2 to the size of one of
5064 the member floats, not the whole complex beast. My guess is that
5065 this was to work well with pre-COMPLEX versions of gdb. */
5067 if (n3 == 0 && n2 > 0)
5069 struct type *float_type
5070 = init_type (TYPE_CODE_FLT, n2, 0, NULL, objfile);
5074 struct type *complex_type =
5075 init_type (TYPE_CODE_COMPLEX, 2 * n2, 0, NULL, objfile);
5076 TYPE_TARGET_TYPE (complex_type) = float_type;
5077 return complex_type;
5083 /* If the upper bound is -1, it must really be an unsigned int. */
5085 else if (n2 == 0 && n3 == -1)
5087 /* It is unsigned int or unsigned long. */
5088 /* GCC 2.3.3 uses this for long long too, but that is just a GDB 3.5
5089 compatibility hack. */
5090 return init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
5091 TYPE_FLAG_UNSIGNED, NULL, objfile);
5094 /* Special case: char is defined (Who knows why) as a subrange of
5095 itself with range 0-127. */
5096 else if (self_subrange && n2 == 0 && n3 == 127)
5097 return init_type (TYPE_CODE_INT, 1, 0, NULL, objfile);
5100 /* OBSOLETE else if (current_symbol && SYMBOL_LANGUAGE (current_symbol) == language_chill */
5101 /* OBSOLETE && !self_subrange) */
5102 /* OBSOLETE goto handle_true_range; */
5105 /* We used to do this only for subrange of self or subrange of int. */
5108 /* -1 is used for the upper bound of (4 byte) "unsigned int" and
5109 "unsigned long", and we already checked for that,
5110 so don't need to test for it here. */
5113 /* n3 actually gives the size. */
5114 return init_type (TYPE_CODE_INT, -n3, TYPE_FLAG_UNSIGNED,
5117 /* Is n3 == 2**(8n)-1 for some integer n? Then it's an
5118 unsigned n-byte integer. But do require n to be a power of
5119 two; we don't want 3- and 5-byte integers flying around. */
5125 for (bytes = 0; (bits & 0xff) == 0xff; bytes++)
5128 && ((bytes - 1) & bytes) == 0) /* "bytes is a power of two" */
5129 return init_type (TYPE_CODE_INT, bytes, TYPE_FLAG_UNSIGNED, NULL,
5133 /* I think this is for Convex "long long". Since I don't know whether
5134 Convex sets self_subrange, I also accept that particular size regardless
5135 of self_subrange. */
5136 else if (n3 == 0 && n2 < 0
5138 || n2 == -TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT))
5139 return init_type (TYPE_CODE_INT, -n2, 0, NULL, objfile);
5140 else if (n2 == -n3 - 1)
5143 return init_type (TYPE_CODE_INT, 1, 0, NULL, objfile);
5145 return init_type (TYPE_CODE_INT, 2, 0, NULL, objfile);
5146 if (n3 == 0x7fffffff)
5147 return init_type (TYPE_CODE_INT, 4, 0, NULL, objfile);
5150 /* We have a real range type on our hands. Allocate space and
5151 return a real pointer. */
5155 index_type = builtin_type_int;
5157 index_type = *dbx_lookup_type (rangenums);
5158 if (index_type == NULL)
5160 /* Does this actually ever happen? Is that why we are worrying
5161 about dealing with it rather than just calling error_type? */
5163 static struct type *range_type_index;
5165 complain (&range_type_base_complaint, rangenums[1]);
5166 if (range_type_index == NULL)
5168 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
5169 0, "range type index type", NULL);
5170 index_type = range_type_index;
5173 result_type = create_range_type ((struct type *) NULL, index_type, n2, n3);
5174 return (result_type);
5177 /* Read in an argument list. This is a list of types, separated by commas
5178 and terminated with END. Return the list of types read in, or (struct type
5179 **)-1 if there is an error. */
5181 static struct field *
5182 read_args (char **pp, int end, struct objfile *objfile, int *nargsp,
5185 /* FIXME! Remove this arbitrary limit! */
5186 struct type *types[1024]; /* allow for fns of 1023 parameters */
5193 /* Invalid argument list: no ','. */
5194 return (struct field *) -1;
5196 STABS_CONTINUE (pp, objfile);
5197 types[n++] = read_type (pp, objfile);
5199 (*pp)++; /* get past `end' (the ':' character) */
5201 if (TYPE_CODE (types[n - 1]) != TYPE_CODE_VOID)
5209 rval = (struct field *) xmalloc (n * sizeof (struct field));
5210 memset (rval, 0, n * sizeof (struct field));
5211 for (i = 0; i < n; i++)
5212 rval[i].type = types[i];
5217 /* Common block handling. */
5219 /* List of symbols declared since the last BCOMM. This list is a tail
5220 of local_symbols. When ECOMM is seen, the symbols on the list
5221 are noted so their proper addresses can be filled in later,
5222 using the common block base address gotten from the assembler
5225 static struct pending *common_block;
5226 static int common_block_i;
5228 /* Name of the current common block. We get it from the BCOMM instead of the
5229 ECOMM to match IBM documentation (even though IBM puts the name both places
5230 like everyone else). */
5231 static char *common_block_name;
5233 /* Process a N_BCOMM symbol. The storage for NAME is not guaranteed
5234 to remain after this function returns. */
5237 common_block_start (char *name, struct objfile *objfile)
5239 if (common_block_name != NULL)
5241 static struct complaint msg =
5243 "Invalid symbol data: common block within common block",
5247 common_block = local_symbols;
5248 common_block_i = local_symbols ? local_symbols->nsyms : 0;
5249 common_block_name = obsavestring (name, strlen (name),
5250 &objfile->symbol_obstack);
5253 /* Process a N_ECOMM symbol. */
5256 common_block_end (struct objfile *objfile)
5258 /* Symbols declared since the BCOMM are to have the common block
5259 start address added in when we know it. common_block and
5260 common_block_i point to the first symbol after the BCOMM in
5261 the local_symbols list; copy the list and hang it off the
5262 symbol for the common block name for later fixup. */
5265 struct pending *new = 0;
5266 struct pending *next;
5269 if (common_block_name == NULL)
5271 static struct complaint msg =
5272 {"ECOMM symbol unmatched by BCOMM", 0, 0};
5277 sym = (struct symbol *)
5278 obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol));
5279 memset (sym, 0, sizeof (struct symbol));
5280 /* Note: common_block_name already saved on symbol_obstack */
5281 SYMBOL_NAME (sym) = common_block_name;
5282 SYMBOL_CLASS (sym) = LOC_BLOCK;
5284 /* Now we copy all the symbols which have been defined since the BCOMM. */
5286 /* Copy all the struct pendings before common_block. */
5287 for (next = local_symbols;
5288 next != NULL && next != common_block;
5291 for (j = 0; j < next->nsyms; j++)
5292 add_symbol_to_list (next->symbol[j], &new);
5295 /* Copy however much of COMMON_BLOCK we need. If COMMON_BLOCK is
5296 NULL, it means copy all the local symbols (which we already did
5299 if (common_block != NULL)
5300 for (j = common_block_i; j < common_block->nsyms; j++)
5301 add_symbol_to_list (common_block->symbol[j], &new);
5303 SYMBOL_TYPE (sym) = (struct type *) new;
5305 /* Should we be putting local_symbols back to what it was?
5308 i = hashname (SYMBOL_NAME (sym));
5309 SYMBOL_VALUE_CHAIN (sym) = global_sym_chain[i];
5310 global_sym_chain[i] = sym;
5311 common_block_name = NULL;
5314 /* Add a common block's start address to the offset of each symbol
5315 declared to be in it (by being between a BCOMM/ECOMM pair that uses
5316 the common block name). */
5319 fix_common_block (struct symbol *sym, int valu)
5321 struct pending *next = (struct pending *) SYMBOL_TYPE (sym);
5322 for (; next; next = next->next)
5325 for (j = next->nsyms - 1; j >= 0; j--)
5326 SYMBOL_VALUE_ADDRESS (next->symbol[j]) += valu;
5332 /* What about types defined as forward references inside of a small lexical
5334 /* Add a type to the list of undefined types to be checked through
5335 once this file has been read in. */
5338 add_undefined_type (struct type *type)
5340 if (undef_types_length == undef_types_allocated)
5342 undef_types_allocated *= 2;
5343 undef_types = (struct type **)
5344 xrealloc ((char *) undef_types,
5345 undef_types_allocated * sizeof (struct type *));
5347 undef_types[undef_types_length++] = type;
5350 /* Go through each undefined type, see if it's still undefined, and fix it
5351 up if possible. We have two kinds of undefined types:
5353 TYPE_CODE_ARRAY: Array whose target type wasn't defined yet.
5354 Fix: update array length using the element bounds
5355 and the target type's length.
5356 TYPE_CODE_STRUCT, TYPE_CODE_UNION: Structure whose fields were not
5357 yet defined at the time a pointer to it was made.
5358 Fix: Do a full lookup on the struct/union tag. */
5360 cleanup_undefined_types (void)
5364 for (type = undef_types; type < undef_types + undef_types_length; type++)
5366 switch (TYPE_CODE (*type))
5369 case TYPE_CODE_STRUCT:
5370 case TYPE_CODE_UNION:
5371 case TYPE_CODE_ENUM:
5373 /* Check if it has been defined since. Need to do this here
5374 as well as in check_typedef to deal with the (legitimate in
5375 C though not C++) case of several types with the same name
5376 in different source files. */
5377 if (TYPE_STUB (*type))
5379 struct pending *ppt;
5381 /* Name of the type, without "struct" or "union" */
5382 char *typename = TYPE_TAG_NAME (*type);
5384 if (typename == NULL)
5386 static struct complaint msg =
5387 {"need a type name", 0, 0};
5391 for (ppt = file_symbols; ppt; ppt = ppt->next)
5393 for (i = 0; i < ppt->nsyms; i++)
5395 struct symbol *sym = ppt->symbol[i];
5397 if (SYMBOL_CLASS (sym) == LOC_TYPEDEF
5398 && SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE
5399 && (TYPE_CODE (SYMBOL_TYPE (sym)) ==
5401 && STREQ (SYMBOL_NAME (sym), typename))
5402 replace_type (*type, SYMBOL_TYPE (sym));
5411 static struct complaint msg =
5413 GDB internal error. cleanup_undefined_types with bad type %d.", 0, 0};
5414 complain (&msg, TYPE_CODE (*type));
5420 undef_types_length = 0;
5423 /* Scan through all of the global symbols defined in the object file,
5424 assigning values to the debugging symbols that need to be assigned
5425 to. Get these symbols from the minimal symbol table. */
5428 scan_file_globals (struct objfile *objfile)
5431 struct minimal_symbol *msymbol;
5432 struct symbol *sym, *prev, *rsym;
5433 struct objfile *resolve_objfile;
5435 /* SVR4 based linkers copy referenced global symbols from shared
5436 libraries to the main executable.
5437 If we are scanning the symbols for a shared library, try to resolve
5438 them from the minimal symbols of the main executable first. */
5440 if (symfile_objfile && objfile != symfile_objfile)
5441 resolve_objfile = symfile_objfile;
5443 resolve_objfile = objfile;
5447 /* Avoid expensive loop through all minimal symbols if there are
5448 no unresolved symbols. */
5449 for (hash = 0; hash < HASHSIZE; hash++)
5451 if (global_sym_chain[hash])
5454 if (hash >= HASHSIZE)
5457 for (msymbol = resolve_objfile->msymbols;
5458 msymbol && SYMBOL_NAME (msymbol) != NULL;
5463 /* Skip static symbols. */
5464 switch (MSYMBOL_TYPE (msymbol))
5476 /* Get the hash index and check all the symbols
5477 under that hash index. */
5479 hash = hashname (SYMBOL_NAME (msymbol));
5481 for (sym = global_sym_chain[hash]; sym;)
5483 if (SYMBOL_NAME (msymbol)[0] == SYMBOL_NAME (sym)[0] &&
5484 STREQ (SYMBOL_NAME (msymbol) + 1, SYMBOL_NAME (sym) + 1))
5487 struct alias_list *aliases;
5489 /* Splice this symbol out of the hash chain and
5490 assign the value we have to it. */
5493 SYMBOL_VALUE_CHAIN (prev) = SYMBOL_VALUE_CHAIN (sym);
5497 global_sym_chain[hash] = SYMBOL_VALUE_CHAIN (sym);
5500 /* Check to see whether we need to fix up a common block. */
5501 /* Note: this code might be executed several times for
5502 the same symbol if there are multiple references. */
5504 /* If symbol has aliases, do minimal symbol fixups for each.
5505 These live aliases/references weren't added to
5506 global_sym_chain hash but may also need to be fixed up. */
5507 /* FIXME: Maybe should have added aliases to the global chain, resolved symbol name, then treated aliases as normal
5508 symbols? Still, we wouldn't want to add_to_list. */
5509 /* Now do the same for each alias of this symbol */
5511 aliases = SYMBOL_ALIASES (sym);
5514 if (SYMBOL_CLASS (rsym) == LOC_BLOCK)
5516 fix_common_block (rsym,
5517 SYMBOL_VALUE_ADDRESS (msymbol));
5521 SYMBOL_VALUE_ADDRESS (rsym)
5522 = SYMBOL_VALUE_ADDRESS (msymbol);
5524 SYMBOL_SECTION (rsym) = SYMBOL_SECTION (msymbol);
5527 rsym = aliases->sym;
5528 aliases = aliases->next;
5537 sym = SYMBOL_VALUE_CHAIN (prev);
5541 sym = global_sym_chain[hash];
5547 sym = SYMBOL_VALUE_CHAIN (sym);
5551 if (resolve_objfile == objfile)
5553 resolve_objfile = objfile;
5556 /* Change the storage class of any remaining unresolved globals to
5557 LOC_UNRESOLVED and remove them from the chain. */
5558 for (hash = 0; hash < HASHSIZE; hash++)
5560 sym = global_sym_chain[hash];
5564 sym = SYMBOL_VALUE_CHAIN (sym);
5566 /* Change the symbol address from the misleading chain value
5568 SYMBOL_VALUE_ADDRESS (prev) = 0;
5570 /* Complain about unresolved common block symbols. */
5571 if (SYMBOL_CLASS (prev) == LOC_STATIC)
5572 SYMBOL_CLASS (prev) = LOC_UNRESOLVED;
5574 complain (&unresolved_sym_chain_complaint,
5575 objfile->name, SYMBOL_NAME (prev));
5578 memset (global_sym_chain, 0, sizeof (global_sym_chain));
5581 /* Initialize anything that needs initializing when starting to read
5582 a fresh piece of a symbol file, e.g. reading in the stuff corresponding
5586 stabsread_init (void)
5590 /* Initialize anything that needs initializing when a completely new
5591 symbol file is specified (not just adding some symbols from another
5592 file, e.g. a shared library). */
5595 stabsread_new_init (void)
5597 /* Empty the hash table of global syms looking for values. */
5598 memset (global_sym_chain, 0, sizeof (global_sym_chain));
5601 /* Initialize anything that needs initializing at the same time as
5602 start_symtab() is called. */
5607 global_stabs = NULL; /* AIX COFF */
5608 /* Leave FILENUM of 0 free for builtin types and this file's types. */
5609 n_this_object_header_files = 1;
5610 type_vector_length = 0;
5611 type_vector = (struct type **) 0;
5613 /* FIXME: If common_block_name is not already NULL, we should complain(). */
5614 common_block_name = NULL;
5616 #if 0 /* OBSOLETE OS9K */
5617 // OBSOLETE os9k_stabs = 0;
5618 #endif /* OBSOLETE OS9K */
5621 /* Call after end_symtab() */
5628 xfree (type_vector);
5631 type_vector_length = 0;
5632 previous_stab_code = 0;
5636 finish_global_stabs (struct objfile *objfile)
5640 patch_block_stabs (global_symbols, global_stabs, objfile);
5641 xfree (global_stabs);
5642 global_stabs = NULL;
5646 /* Initializer for this module */
5649 _initialize_stabsread (void)
5651 undef_types_allocated = 20;
5652 undef_types_length = 0;
5653 undef_types = (struct type **)
5654 xmalloc (undef_types_allocated * sizeof (struct type *));