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"
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"
50 /* Ask stabsread.h to define the vars it normally declares `extern'. */
53 #include "stabsread.h" /* Our own declarations */
56 extern void _initialize_stabsread (void);
58 /* The routines that read and process a complete stabs for a C struct or
59 C++ class pass lists of data member fields and lists of member function
60 fields in an instance of a field_info structure, as defined below.
61 This is part of some reorganization of low level C++ support and is
62 expected to eventually go away... (FIXME) */
68 struct nextfield *next;
70 /* This is the raw visibility from the stab. It is not checked
71 for being one of the visibilities we recognize, so code which
72 examines this field better be able to deal. */
78 struct next_fnfieldlist
80 struct next_fnfieldlist *next;
81 struct fn_fieldlist fn_fieldlist;
87 read_one_struct_field (struct field_info *, char **, char *,
88 struct type *, struct objfile *);
90 static char *get_substring (char **, int);
92 static struct type *dbx_alloc_type (int[2], struct objfile *);
94 static long read_huge_number (char **, int, int *);
96 static struct type *error_type (char **, struct objfile *);
99 patch_block_stabs (struct pending *, struct pending_stabs *,
102 static void fix_common_block (struct symbol *, int);
104 static int read_type_number (char **, int *);
106 static struct type *read_range_type (char **, int[2], struct objfile *);
108 static struct type *read_sun_builtin_type (char **, int[2], struct objfile *);
110 static struct type *read_sun_floating_type (char **, int[2],
113 static struct type *read_enum_type (char **, struct type *, struct objfile *);
115 static struct type *rs6000_builtin_type (int);
118 read_member_functions (struct field_info *, char **, struct type *,
122 read_struct_fields (struct field_info *, char **, struct type *,
126 read_baseclasses (struct field_info *, char **, struct type *,
130 read_tilde_fields (struct field_info *, char **, struct type *,
133 static int attach_fn_fields_to_type (struct field_info *, struct type *);
136 attach_fields_to_type (struct field_info *, struct type *, struct objfile *);
138 static struct type *read_struct_type (char **, struct type *,
142 static struct type *read_array_type (char **, struct type *,
145 static struct type **read_args (char **, int, struct objfile *);
148 read_cpp_abbrev (struct field_info *, char **, struct type *,
151 /* new functions added for cfront support */
154 copy_cfront_struct_fields (struct field_info *, struct type *,
157 static char *get_cfront_method_physname (char *);
160 read_cfront_baseclasses (struct field_info *, char **,
161 struct type *, struct objfile *);
164 read_cfront_static_fields (struct field_info *, char **,
165 struct type *, struct objfile *);
167 read_cfront_member_functions (struct field_info *, char **,
168 struct type *, struct objfile *);
170 /* end new functions added for cfront support */
173 add_live_range (struct objfile *, struct symbol *, CORE_ADDR, CORE_ADDR);
175 static int resolve_live_range (struct objfile *, struct symbol *, char *);
177 static int process_reference (char **string);
179 static CORE_ADDR ref_search_value (int refnum);
182 resolve_symbol_reference (struct objfile *, struct symbol *, char *);
184 void stabsread_clear_cache (void);
186 static const char vptr_name[] =
187 {'_', 'v', 'p', 't', 'r', CPLUS_MARKER, '\0'};
188 static const char vb_name[] =
189 {'_', 'v', 'b', CPLUS_MARKER, '\0'};
191 /* Define this as 1 if a pcc declaration of a char or short argument
192 gives the correct address. Otherwise assume pcc gives the
193 address of the corresponding int, which is not the same on a
194 big-endian machine. */
196 #if !defined (BELIEVE_PCC_PROMOTION)
197 #define BELIEVE_PCC_PROMOTION 0
199 #if !defined (BELIEVE_PCC_PROMOTION_TYPE)
200 #define BELIEVE_PCC_PROMOTION_TYPE 0
203 static struct complaint invalid_cpp_abbrev_complaint =
204 {"invalid C++ abbreviation `%s'", 0, 0};
206 static struct complaint invalid_cpp_type_complaint =
207 {"C++ abbreviated type name unknown at symtab pos %d", 0, 0};
209 static struct complaint member_fn_complaint =
210 {"member function type missing, got '%c'", 0, 0};
212 static struct complaint const_vol_complaint =
213 {"const/volatile indicator missing, got '%c'", 0, 0};
215 static struct complaint error_type_complaint =
216 {"couldn't parse type; debugger out of date?", 0, 0};
218 static struct complaint invalid_member_complaint =
219 {"invalid (minimal) member type data format at symtab pos %d.", 0, 0};
221 static struct complaint range_type_base_complaint =
222 {"base type %d of range type is not defined", 0, 0};
224 static struct complaint reg_value_complaint =
225 {"register number %d too large (max %d) in symbol %s", 0, 0};
227 static struct complaint vtbl_notfound_complaint =
228 {"virtual function table pointer not found when defining class `%s'", 0, 0};
230 static struct complaint unrecognized_cplus_name_complaint =
231 {"Unknown C++ symbol name `%s'", 0, 0};
233 static struct complaint rs6000_builtin_complaint =
234 {"Unknown builtin type %d", 0, 0};
236 static struct complaint unresolved_sym_chain_complaint =
237 {"%s: common block `%s' from global_sym_chain unresolved", 0, 0};
239 static struct complaint stabs_general_complaint =
242 static struct complaint lrs_general_complaint =
245 /* Make a list of forward references which haven't been defined. */
247 static struct type **undef_types;
248 static int undef_types_allocated;
249 static int undef_types_length;
250 static struct symbol *current_symbol = NULL;
252 /* Check for and handle cretinous stabs symbol name continuation! */
253 #define STABS_CONTINUE(pp,objfile) \
255 if (**(pp) == '\\' || (**(pp) == '?' && (*(pp))[1] == '\0')) \
256 *(pp) = next_symbol_text (objfile); \
259 /* FIXME: These probably should be our own types (like rs6000_builtin_type
260 has its own types) rather than builtin_type_*. */
261 static struct type **os9k_type_vector[] =
268 &builtin_type_unsigned_char,
269 &builtin_type_unsigned_short,
270 &builtin_type_unsigned_long,
271 &builtin_type_unsigned_int,
273 &builtin_type_double,
275 &builtin_type_long_double
278 static void os9k_init_type_vector (struct type **);
281 os9k_init_type_vector (struct type **tv)
284 for (i = 0; i < sizeof (os9k_type_vector) / sizeof (struct type **); i++)
285 tv[i] = (os9k_type_vector[i] == 0 ? 0 : *(os9k_type_vector[i]));
288 /* Look up a dbx type-number pair. Return the address of the slot
289 where the type for that number-pair is stored.
290 The number-pair is in TYPENUMS.
292 This can be used for finding the type associated with that pair
293 or for associating a new type with the pair. */
296 dbx_lookup_type (int typenums[2])
298 register int filenum = typenums[0];
299 register int index = typenums[1];
301 register int real_filenum;
302 register struct header_file *f;
305 if (filenum == -1) /* -1,-1 is for temporary types. */
308 if (filenum < 0 || filenum >= n_this_object_header_files)
310 static struct complaint msg =
312 Invalid symbol data: type number (%d,%d) out of range at symtab pos %d.",
314 complain (&msg, filenum, index, symnum);
322 /* Caller wants address of address of type. We think
323 that negative (rs6k builtin) types will never appear as
324 "lvalues", (nor should they), so we stuff the real type
325 pointer into a temp, and return its address. If referenced,
326 this will do the right thing. */
327 static struct type *temp_type;
329 temp_type = rs6000_builtin_type (index);
333 /* Type is defined outside of header files.
334 Find it in this object file's type vector. */
335 if (index >= type_vector_length)
337 old_len = type_vector_length;
340 type_vector_length = INITIAL_TYPE_VECTOR_LENGTH;
341 type_vector = (struct type **)
342 xmalloc (type_vector_length * sizeof (struct type *));
344 while (index >= type_vector_length)
346 type_vector_length *= 2;
348 type_vector = (struct type **)
349 xrealloc ((char *) type_vector,
350 (type_vector_length * sizeof (struct type *)));
351 memset (&type_vector[old_len], 0,
352 (type_vector_length - old_len) * sizeof (struct type *));
355 /* Deal with OS9000 fundamental types. */
356 os9k_init_type_vector (type_vector);
358 return (&type_vector[index]);
362 real_filenum = this_object_header_files[filenum];
364 if (real_filenum >= N_HEADER_FILES (current_objfile))
366 struct type *temp_type;
367 struct type **temp_type_p;
369 warning ("GDB internal error: bad real_filenum");
372 temp_type = init_type (TYPE_CODE_ERROR, 0, 0, NULL, NULL);
373 temp_type_p = (struct type **) xmalloc (sizeof (struct type *));
374 *temp_type_p = temp_type;
378 f = HEADER_FILES (current_objfile) + real_filenum;
380 f_orig_length = f->length;
381 if (index >= f_orig_length)
383 while (index >= f->length)
387 f->vector = (struct type **)
388 xrealloc ((char *) f->vector, f->length * sizeof (struct type *));
389 memset (&f->vector[f_orig_length], 0,
390 (f->length - f_orig_length) * sizeof (struct type *));
392 return (&f->vector[index]);
396 /* Make sure there is a type allocated for type numbers TYPENUMS
397 and return the type object.
398 This can create an empty (zeroed) type object.
399 TYPENUMS may be (-1, -1) to return a new type object that is not
400 put into the type vector, and so may not be referred to by number. */
403 dbx_alloc_type (int typenums[2], struct objfile *objfile)
405 register struct type **type_addr;
407 if (typenums[0] == -1)
409 return (alloc_type (objfile));
412 type_addr = dbx_lookup_type (typenums);
414 /* If we are referring to a type not known at all yet,
415 allocate an empty type for it.
416 We will fill it in later if we find out how. */
419 *type_addr = alloc_type (objfile);
425 /* for all the stabs in a given stab vector, build appropriate types
426 and fix their symbols in given symbol vector. */
429 patch_block_stabs (struct pending *symbols, struct pending_stabs *stabs,
430 struct objfile *objfile)
440 /* for all the stab entries, find their corresponding symbols and
441 patch their types! */
443 for (ii = 0; ii < stabs->count; ++ii)
445 name = stabs->stab[ii];
446 pp = (char *) strchr (name, ':');
450 pp = (char *) strchr (pp, ':');
452 sym = find_symbol_in_list (symbols, name, pp - name);
455 /* FIXME-maybe: it would be nice if we noticed whether
456 the variable was defined *anywhere*, not just whether
457 it is defined in this compilation unit. But neither
458 xlc or GCC seem to need such a definition, and until
459 we do psymtabs (so that the minimal symbols from all
460 compilation units are available now), I'm not sure
461 how to get the information. */
463 /* On xcoff, if a global is defined and never referenced,
464 ld will remove it from the executable. There is then
465 a N_GSYM stab for it, but no regular (C_EXT) symbol. */
466 sym = (struct symbol *)
467 obstack_alloc (&objfile->symbol_obstack,
468 sizeof (struct symbol));
470 memset (sym, 0, sizeof (struct symbol));
471 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
472 SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
474 obsavestring (name, pp - name, &objfile->symbol_obstack);
476 if (*(pp - 1) == 'F' || *(pp - 1) == 'f')
478 /* I don't think the linker does this with functions,
479 so as far as I know this is never executed.
480 But it doesn't hurt to check. */
482 lookup_function_type (read_type (&pp, objfile));
486 SYMBOL_TYPE (sym) = read_type (&pp, objfile);
488 add_symbol_to_list (sym, &global_symbols);
493 if (*(pp - 1) == 'F' || *(pp - 1) == 'f')
496 lookup_function_type (read_type (&pp, objfile));
500 SYMBOL_TYPE (sym) = read_type (&pp, objfile);
508 /* Read a number by which a type is referred to in dbx data,
509 or perhaps read a pair (FILENUM, TYPENUM) in parentheses.
510 Just a single number N is equivalent to (0,N).
511 Return the two numbers by storing them in the vector TYPENUMS.
512 TYPENUMS will then be used as an argument to dbx_lookup_type.
514 Returns 0 for success, -1 for error. */
517 read_type_number (register char **pp, register int *typenums)
523 typenums[0] = read_huge_number (pp, ',', &nbits);
526 typenums[1] = read_huge_number (pp, ')', &nbits);
533 typenums[1] = read_huge_number (pp, 0, &nbits);
541 #define VISIBILITY_PRIVATE '0' /* Stabs character for private field */
542 #define VISIBILITY_PROTECTED '1' /* Stabs character for protected fld */
543 #define VISIBILITY_PUBLIC '2' /* Stabs character for public field */
544 #define VISIBILITY_IGNORE '9' /* Optimized out or zero length */
546 #define CFRONT_VISIBILITY_PRIVATE '2' /* Stabs character for private field */
547 #define CFRONT_VISIBILITY_PUBLIC '1' /* Stabs character for public field */
549 /* This code added to support parsing of ARM/Cfront stabs strings */
551 /* Get substring from string up to char c, advance string pointer past
555 get_substring (char **p, int c)
570 /* Physname gets strcat'd onto sname in order to recreate the mangled
571 name (see funtion gdb_mangle_name in gdbtypes.c). For cfront, make
572 the physname look like that of g++ - take out the initial mangling
573 eg: for sname="a" and fname="foo__1aFPFs_i" return "FPFs_i" */
576 get_cfront_method_physname (char *fname)
579 /* FIXME would like to make this generic for g++ too, but
580 that is already handled in read_member_funcctions */
583 /* search ahead to find the start of the mangled suffix */
584 if (*p == '_' && *(p + 1) == '_') /* compiler generated; probably a ctor/dtor */
586 while (p && (unsigned) ((p + 1) - fname) < strlen (fname) && *(p + 1) != '_')
588 if (!(p && *p == '_' && *(p + 1) == '_'))
589 error ("Invalid mangled function name %s", fname);
590 p += 2; /* advance past '__' */
592 /* struct name length and name of type should come next; advance past it */
595 len = len * 10 + (*p - '0');
603 /* Read base classes within cfront class definition.
604 eg: A:ZcA;1@Bpub v2@Bvirpri;__ct__1AFv func__1AFv *sfunc__1AFv ;as__1A ;;
607 A:ZcA;;foopri__1AFv foopro__1AFv __ct__1AFv __ct__1AFRC1A foopub__1AFv ;;;
612 read_cfront_baseclasses (struct field_info *fip, char **pp, struct type *type,
613 struct objfile *objfile)
615 static struct complaint msg_unknown =
617 Unsupported token in stabs string %s.\n",
619 static struct complaint msg_notfound =
621 Unable to find base type for %s.\n",
626 struct nextfield *new;
628 if (**pp == ';') /* no base classes; return */
634 /* first count base classes so we can allocate space before parsing */
635 for (p = *pp; p && *p && *p != ';'; p++)
640 bnum++; /* add one more for last one */
642 /* now parse the base classes until we get to the start of the methods
643 (code extracted and munged from read_baseclasses) */
644 ALLOCATE_CPLUS_STRUCT_TYPE (type);
645 TYPE_N_BASECLASSES (type) = bnum;
649 int num_bytes = B_BYTES (TYPE_N_BASECLASSES (type));
652 pointer = (char *) TYPE_ALLOC (type, num_bytes);
653 TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *) pointer;
655 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), TYPE_N_BASECLASSES (type));
657 for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
659 new = (struct nextfield *) xmalloc (sizeof (struct nextfield));
660 make_cleanup (xfree, new);
661 memset (new, 0, sizeof (struct nextfield));
662 new->next = fip->list;
664 FIELD_BITSIZE (new->field) = 0; /* this should be an unpacked field! */
666 STABS_CONTINUE (pp, objfile);
668 /* virtual? eg: v2@Bvir */
671 SET_TYPE_FIELD_VIRTUAL (type, i);
675 /* access? eg: 2@Bvir */
676 /* Note: protected inheritance not supported in cfront */
679 case CFRONT_VISIBILITY_PRIVATE:
680 new->visibility = VISIBILITY_PRIVATE;
682 case CFRONT_VISIBILITY_PUBLIC:
683 new->visibility = VISIBILITY_PUBLIC;
686 /* Bad visibility format. Complain and treat it as
689 static struct complaint msg =
691 "Unknown visibility `%c' for baseclass", 0, 0};
692 complain (&msg, new->visibility);
693 new->visibility = VISIBILITY_PUBLIC;
697 /* "@" comes next - eg: @Bvir */
700 complain (&msg_unknown, *pp);
706 /* Set the bit offset of the portion of the object corresponding
707 to this baseclass. Always zero in the absence of
708 multiple inheritance. */
709 /* Unable to read bit position from stabs;
710 Assuming no multiple inheritance for now FIXME! */
711 /* We may have read this in the structure definition;
712 now we should fixup the members to be the actual base classes */
713 FIELD_BITPOS (new->field) = 0;
715 /* Get the base class name and type */
717 char *bname; /* base class name */
718 struct symbol *bsym; /* base class */
720 p1 = strchr (*pp, ' ');
721 p2 = strchr (*pp, ';');
723 bname = get_substring (pp, ' ');
725 bname = get_substring (pp, ';');
726 if (!bname || !*bname)
728 complain (&msg_unknown, *pp);
731 /* FIXME! attach base info to type */
732 bsym = lookup_symbol (bname, 0, STRUCT_NAMESPACE, 0, 0); /*demangled_name */
735 new->field.type = SYMBOL_TYPE (bsym);
736 new->field.name = type_name_no_tag (new->field.type);
740 complain (&msg_notfound, *pp);
745 /* If more base classes to parse, loop again.
746 We ate the last ' ' or ';' in get_substring,
747 so on exit we will have skipped the trailing ';' */
748 /* if invalid, return 0; add code to detect - FIXME! */
753 /* read cfront member functions.
754 pp points to string starting with list of functions
755 eg: A:ZcA;1@Bpub v2@Bvirpri;__ct__1AFv func__1AFv *sfunc__1AFv ;as__1A ;;
756 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
757 A:ZcA;;foopri__1AFv foopro__1AFv __ct__1AFv __ct__1AFRC1A foopub__1AFv ;;;
758 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
762 read_cfront_member_functions (struct field_info *fip, char **pp,
763 struct type *type, struct objfile *objfile)
765 /* This code extracted from read_member_functions
766 so as to do the similar thing for our funcs */
770 /* Total number of member functions defined in this class. If the class
771 defines two `f' functions, and one `g' function, then this will have
773 int total_length = 0;
777 struct next_fnfield *next;
778 struct fn_field fn_field;
781 struct type *look_ahead_type;
782 struct next_fnfieldlist *new_fnlist;
783 struct next_fnfield *new_sublist;
786 struct symbol *ref_func = 0;
788 /* Process each list until we find the end of the member functions.
789 eg: p = "__ct__1AFv foo__1AFv ;;;" */
791 STABS_CONTINUE (pp, objfile); /* handle \\ */
793 while (**pp != ';' && (fname = get_substring (pp, ' '), fname))
796 int sublist_count = 0;
798 if (fname[0] == '*') /* static member */
804 ref_func = lookup_symbol (fname, 0, VAR_NAMESPACE, 0, 0); /* demangled name */
807 static struct complaint msg =
809 Unable to find function symbol for %s\n",
811 complain (&msg, fname);
815 look_ahead_type = NULL;
818 new_fnlist = (struct next_fnfieldlist *)
819 xmalloc (sizeof (struct next_fnfieldlist));
820 make_cleanup (xfree, new_fnlist);
821 memset (new_fnlist, 0, sizeof (struct next_fnfieldlist));
823 /* The following is code to work around cfront generated stabs.
824 The stabs contains full mangled name for each field.
825 We try to demangle the name and extract the field name out of it. */
827 char *dem, *dem_p, *dem_args;
829 dem = cplus_demangle (fname, DMGL_ANSI | DMGL_PARAMS);
832 dem_p = strrchr (dem, ':');
833 if (dem_p != 0 && *(dem_p - 1) == ':')
835 /* get rid of args */
836 dem_args = strchr (dem_p, '(');
837 if (dem_args == NULL)
838 dem_len = strlen (dem_p);
840 dem_len = dem_args - dem_p;
842 obsavestring (dem_p, dem_len, &objfile->type_obstack);
847 obsavestring (fname, strlen (fname), &objfile->type_obstack);
849 } /* end of code for cfront work around */
851 new_fnlist->fn_fieldlist.name = main_fn_name;
853 /*-------------------------------------------------*/
854 /* Set up the sublists
855 Sublists are stuff like args, static, visibility, etc.
856 so in ARM, we have to set that info some other way.
857 Multiple sublists happen if overloading
858 eg: foo::26=##1;:;2A.;
859 In g++, we'd loop here thru all the sublists... */
862 (struct next_fnfield *) xmalloc (sizeof (struct next_fnfield));
863 make_cleanup (xfree, new_sublist);
864 memset (new_sublist, 0, sizeof (struct next_fnfield));
866 /* eat 1; from :;2A.; */
867 new_sublist->fn_field.type = SYMBOL_TYPE (ref_func); /* normally takes a read_type */
868 /* Make this type look like a method stub for gdb */
869 TYPE_FLAGS (new_sublist->fn_field.type) |= TYPE_FLAG_STUB;
870 TYPE_CODE (new_sublist->fn_field.type) = TYPE_CODE_METHOD;
872 /* If this is just a stub, then we don't have the real name here. */
873 if (TYPE_STUB (new_sublist->fn_field.type))
875 if (!TYPE_DOMAIN_TYPE (new_sublist->fn_field.type))
876 TYPE_DOMAIN_TYPE (new_sublist->fn_field.type) = type;
877 new_sublist->fn_field.is_stub = 1;
880 /* physname used later in mangling; eg PFs_i,5 for foo__1aFPFs_i
881 physname gets strcat'd in order to recreate the onto mangled name */
882 pname = get_cfront_method_physname (fname);
883 new_sublist->fn_field.physname = savestring (pname, strlen (pname));
886 /* Set this member function's visibility fields.
887 Unable to distinguish access from stabs definition!
888 Assuming public for now. FIXME!
889 (for private, set new_sublist->fn_field.is_private = 1,
890 for public, set new_sublist->fn_field.is_protected = 1) */
892 /* Unable to distinguish const/volatile from stabs definition!
893 Assuming normal for now. FIXME! */
895 new_sublist->fn_field.is_const = 0;
896 new_sublist->fn_field.is_volatile = 0; /* volatile not implemented in cfront */
898 /* Set virtual/static function info
899 How to get vtable offsets ?
900 Assuming normal for now FIXME!!
901 For vtables, figure out from whence this virtual function came.
902 It may belong to virtual function table of
903 one of its baseclasses.
905 new_sublist -> fn_field.voffset = vtable offset,
906 new_sublist -> fn_field.fcontext = look_ahead_type;
907 where look_ahead_type is type of baseclass */
909 new_sublist->fn_field.voffset = VOFFSET_STATIC;
910 else /* normal member function. */
911 new_sublist->fn_field.voffset = 0;
912 new_sublist->fn_field.fcontext = 0;
915 /* Prepare new sublist */
916 new_sublist->next = sublist;
917 sublist = new_sublist;
920 /* In g++, we loop thu sublists - now we set from functions. */
921 new_fnlist->fn_fieldlist.fn_fields = (struct fn_field *)
922 obstack_alloc (&objfile->type_obstack,
923 sizeof (struct fn_field) * length);
924 memset (new_fnlist->fn_fieldlist.fn_fields, 0,
925 sizeof (struct fn_field) * length);
926 for (i = length; (i--, sublist); sublist = sublist->next)
928 new_fnlist->fn_fieldlist.fn_fields[i] = sublist->fn_field;
931 new_fnlist->fn_fieldlist.length = length;
932 new_fnlist->next = fip->fnlist;
933 fip->fnlist = new_fnlist;
935 total_length += length;
936 STABS_CONTINUE (pp, objfile); /* handle \\ */
941 /* type should already have space */
942 TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
943 TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * nfn_fields);
944 memset (TYPE_FN_FIELDLISTS (type), 0,
945 sizeof (struct fn_fieldlist) * nfn_fields);
946 TYPE_NFN_FIELDS (type) = nfn_fields;
947 TYPE_NFN_FIELDS_TOTAL (type) = total_length;
950 /* end of scope for reading member func */
954 /* Skip trailing ';' and bump count of number of fields seen */
962 /* This routine fixes up partial cfront types that were created
963 while parsing the stabs. The main need for this function is
964 to add information such as methods to classes.
965 Examples of "p": "sA;;__ct__1AFv foo__1AFv ;;;" */
967 resolve_cfront_continuation (struct objfile *objfile, struct symbol *sym,
970 struct symbol *ref_sym = 0;
972 /* snarfed from read_struct_type */
973 struct field_info fi;
975 struct cleanup *back_to;
977 /* Need to make sure that fi isn't gunna conflict with struct
978 in case struct already had some fnfs */
981 back_to = make_cleanup (null_cleanup, 0);
983 /* We only accept structs, classes and unions at the moment.
984 Other continuation types include t (typedef), r (long dbl), ...
985 We may want to add support for them as well;
986 right now they are handled by duplicating the symbol information
987 into the type information (see define_symbol) */
988 if (*p != 's' /* structs */
989 && *p != 'c' /* class */
990 && *p != 'u') /* union */
991 return 0; /* only handle C++ types */
994 /* Get symbol typs name and validate
995 eg: p = "A;;__ct__1AFv foo__1AFv ;;;" */
996 sname = get_substring (&p, ';');
997 if (!sname || strcmp (sname, SYMBOL_NAME (sym)))
998 error ("Internal error: base symbol type name does not match\n");
1000 /* Find symbol's internal gdb reference using demangled_name.
1001 This is the real sym that we want;
1002 sym was a temp hack to make debugger happy */
1003 ref_sym = lookup_symbol (SYMBOL_NAME (sym), 0, STRUCT_NAMESPACE, 0, 0);
1004 type = SYMBOL_TYPE (ref_sym);
1007 /* Now read the baseclasses, if any, read the regular C struct or C++
1008 class member fields, attach the fields to the type, read the C++
1009 member functions, attach them to the type, and then read any tilde
1010 field (baseclass specifier for the class holding the main vtable). */
1012 if (!read_cfront_baseclasses (&fi, &p, type, objfile)
1013 /* g++ does this next, but cfront already did this:
1014 || !read_struct_fields (&fi, &p, type, objfile) */
1015 || !copy_cfront_struct_fields (&fi, type, objfile)
1016 || !read_cfront_member_functions (&fi, &p, type, objfile)
1017 || !read_cfront_static_fields (&fi, &p, type, objfile)
1018 || !attach_fields_to_type (&fi, type, objfile)
1019 || !attach_fn_fields_to_type (&fi, type)
1020 /* g++ does this next, but cfront doesn't seem to have this:
1021 || !read_tilde_fields (&fi, &p, type, objfile) */
1024 type = error_type (&p, objfile);
1027 do_cleanups (back_to);
1030 /* End of code added to support parsing of ARM/Cfront stabs strings */
1033 /* This routine fixes up symbol references/aliases to point to the original
1034 symbol definition. Returns 0 on failure, non-zero on success. */
1037 resolve_symbol_reference (struct objfile *objfile, struct symbol *sym, char *p)
1040 struct symbol *ref_sym = 0;
1041 struct alias_list *alias;
1043 /* If this is not a symbol reference return now. */
1047 /* Use "#<num>" as the name; we'll fix the name later.
1048 We stored the original symbol name as "#<id>=<name>"
1049 so we can now search for "#<id>" to resolving the reference.
1050 We'll fix the names later by removing the "#<id>" or "#<id>=" */
1052 /*---------------------------------------------------------*/
1053 /* Get the reference id number, and
1054 advance p past the names so we can parse the rest.
1055 eg: id=2 for p : "2=", "2=z:r(0,1)" "2:r(0,1);l(#5,#6),l(#7,#4)" */
1056 /*---------------------------------------------------------*/
1058 /* This gets reference name from string. sym may not have a name. */
1060 /* Get the reference number associated with the reference id in the
1061 gdb stab string. From that reference number, get the main/primary
1062 symbol for this alias. */
1063 refnum = process_reference (&p);
1064 ref_sym = ref_search (refnum);
1067 complain (&lrs_general_complaint, "symbol for reference not found");
1071 /* Parse the stab of the referencing symbol
1072 now that we have the referenced symbol.
1073 Add it as a new symbol and a link back to the referenced symbol.
1074 eg: p : "=", "=z:r(0,1)" ":r(0,1);l(#5,#6),l(#7,#4)" */
1077 /* If the stab symbol table and string contain:
1078 RSYM 0 5 00000000 868 #15=z:r(0,1)
1079 LBRAC 0 0 00000000 899 #5=
1080 SLINE 0 16 00000003 923 #6=
1081 Then the same symbols can be later referenced by:
1082 RSYM 0 5 00000000 927 #15:r(0,1);l(#5,#6)
1083 This is used in live range splitting to:
1084 1) specify that a symbol (#15) is actually just a new storage
1085 class for a symbol (#15=z) which was previously defined.
1086 2) specify that the beginning and ending ranges for a symbol
1087 (#15) are the values of the beginning (#5) and ending (#6)
1090 /* Read number as reference id.
1091 eg: p : "=", "=z:r(0,1)" ":r(0,1);l(#5,#6),l(#7,#4)" */
1092 /* FIXME! Might I want to use SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
1093 in case of "l(0,0)"? */
1095 /*--------------------------------------------------*/
1096 /* Add this symbol to the reference list. */
1097 /*--------------------------------------------------*/
1099 alias = (struct alias_list *) obstack_alloc (&objfile->type_obstack,
1100 sizeof (struct alias_list));
1103 complain (&lrs_general_complaint, "Unable to allocate alias list memory");
1110 if (!SYMBOL_ALIASES (ref_sym))
1112 SYMBOL_ALIASES (ref_sym) = alias;
1116 struct alias_list *temp;
1118 /* Get to the end of the list. */
1119 for (temp = SYMBOL_ALIASES (ref_sym);
1126 /* Want to fix up name so that other functions (eg. valops)
1127 will correctly print the name.
1128 Don't add_symbol_to_list so that lookup_symbol won't find it.
1129 nope... needed for fixups. */
1130 SYMBOL_NAME (sym) = SYMBOL_NAME (ref_sym);
1136 /* Structure for storing pointers to reference definitions for fast lookup
1137 during "process_later". */
1146 #define MAX_CHUNK_REFS 100
1147 #define REF_CHUNK_SIZE (MAX_CHUNK_REFS * sizeof (struct ref_map))
1148 #define REF_MAP_SIZE(ref_chunk) ((ref_chunk) * REF_CHUNK_SIZE)
1150 static struct ref_map *ref_map;
1152 /* Ptr to free cell in chunk's linked list. */
1153 static int ref_count = 0;
1155 /* Number of chunks malloced. */
1156 static int ref_chunk = 0;
1158 /* This file maintains a cache of stabs aliases found in the symbol
1159 table. If the symbol table changes, this cache must be cleared
1160 or we are left holding onto data in invalid obstacks. */
1162 stabsread_clear_cache (void)
1168 /* Create array of pointers mapping refids to symbols and stab strings.
1169 Add pointers to reference definition symbols and/or their values as we
1170 find them, using their reference numbers as our index.
1171 These will be used later when we resolve references. */
1173 ref_add (int refnum, struct symbol *sym, char *stabs, CORE_ADDR value)
1177 if (refnum >= ref_count)
1178 ref_count = refnum + 1;
1179 if (ref_count > ref_chunk * MAX_CHUNK_REFS)
1181 int new_slots = ref_count - ref_chunk * MAX_CHUNK_REFS;
1182 int new_chunks = new_slots / MAX_CHUNK_REFS + 1;
1183 ref_map = (struct ref_map *)
1184 xrealloc (ref_map, REF_MAP_SIZE (ref_chunk + new_chunks));
1185 memset (ref_map + ref_chunk * MAX_CHUNK_REFS, 0, new_chunks * REF_CHUNK_SIZE);
1186 ref_chunk += new_chunks;
1188 ref_map[refnum].stabs = stabs;
1189 ref_map[refnum].sym = sym;
1190 ref_map[refnum].value = value;
1193 /* Return defined sym for the reference REFNUM. */
1195 ref_search (int refnum)
1197 if (refnum < 0 || refnum > ref_count)
1199 return ref_map[refnum].sym;
1202 /* Return value for the reference REFNUM. */
1205 ref_search_value (int refnum)
1207 if (refnum < 0 || refnum > ref_count)
1209 return ref_map[refnum].value;
1212 /* Parse a reference id in STRING and return the resulting
1213 reference number. Move STRING beyond the reference id. */
1216 process_reference (char **string)
1221 if (**string != '#')
1224 /* Advance beyond the initial '#'. */
1227 /* Read number as reference id. */
1228 while (*p && isdigit (*p))
1230 refnum = refnum * 10 + *p - '0';
1237 /* If STRING defines a reference, store away a pointer to the reference
1238 definition for later use. Return the reference number. */
1241 symbol_reference_defined (char **string)
1246 refnum = process_reference (&p);
1248 /* Defining symbols end in '=' */
1251 /* Symbol is being defined here. */
1257 /* Must be a reference. Either the symbol has already been defined,
1258 or this is a forward reference to it. */
1266 define_symbol (CORE_ADDR valu, char *string, int desc, int type,
1267 struct objfile *objfile)
1269 register struct symbol *sym;
1270 char *p = (char *) strchr (string, ':');
1275 /* We would like to eliminate nameless symbols, but keep their types.
1276 E.g. stab entry ":t10=*2" should produce a type 10, which is a pointer
1277 to type 2, but, should not create a symbol to address that type. Since
1278 the symbol will be nameless, there is no way any user can refer to it. */
1282 /* Ignore syms with empty names. */
1286 /* Ignore old-style symbols from cc -go */
1293 p = strchr (p, ':');
1296 /* If a nameless stab entry, all we need is the type, not the symbol.
1297 e.g. ":t10=*2" or a nameless enum like " :T16=ered:0,green:1,blue:2,;" */
1298 nameless = (p == string || ((string[0] == ' ') && (string[1] == ':')));
1300 current_symbol = sym = (struct symbol *)
1301 obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol));
1302 memset (sym, 0, sizeof (struct symbol));
1304 switch (type & N_TYPE)
1307 SYMBOL_SECTION (sym) = SECT_OFF_TEXT (objfile);
1310 SYMBOL_SECTION (sym) = SECT_OFF_DATA (objfile);
1313 SYMBOL_SECTION (sym) = SECT_OFF_BSS (objfile);
1317 if (processing_gcc_compilation)
1319 /* GCC 2.x puts the line number in desc. SunOS apparently puts in the
1320 number of bytes occupied by a type or object, which we ignore. */
1321 SYMBOL_LINE (sym) = desc;
1325 SYMBOL_LINE (sym) = 0; /* unknown */
1328 if (is_cplus_marker (string[0]))
1330 /* Special GNU C++ names. */
1334 SYMBOL_NAME (sym) = obsavestring ("this", strlen ("this"),
1335 &objfile->symbol_obstack);
1338 case 'v': /* $vtbl_ptr_type */
1339 /* Was: SYMBOL_NAME (sym) = "vptr"; */
1343 SYMBOL_NAME (sym) = obsavestring ("eh_throw", strlen ("eh_throw"),
1344 &objfile->symbol_obstack);
1348 /* This was an anonymous type that was never fixed up. */
1351 #ifdef STATIC_TRANSFORM_NAME
1353 /* SunPRO (3.0 at least) static variable encoding. */
1358 complain (&unrecognized_cplus_name_complaint, string);
1359 goto normal; /* Do *something* with it */
1362 else if (string[0] == '#')
1364 /* Special GNU C extension for referencing symbols. */
1368 /* If STRING defines a new reference id, then add it to the
1369 reference map. Else it must be referring to a previously
1370 defined symbol, so add it to the alias list of the previously
1373 refnum = symbol_reference_defined (&s);
1375 ref_add (refnum, sym, string, SYMBOL_VALUE (sym));
1376 else if (!resolve_symbol_reference (objfile, sym, string))
1379 /* S..P contains the name of the symbol. We need to store
1380 the correct name into SYMBOL_NAME. */
1386 SYMBOL_NAME (sym) = (char *)
1387 obstack_alloc (&objfile->symbol_obstack, nlen);
1388 strncpy (SYMBOL_NAME (sym), s, nlen);
1389 SYMBOL_NAME (sym)[nlen] = '\0';
1390 SYMBOL_INIT_DEMANGLED_NAME (sym, &objfile->symbol_obstack);
1393 /* FIXME! Want SYMBOL_NAME (sym) = 0;
1394 Get error if leave name 0. So give it something. */
1397 SYMBOL_NAME (sym) = (char *)
1398 obstack_alloc (&objfile->symbol_obstack, nlen);
1399 strncpy (SYMBOL_NAME (sym), string, nlen);
1400 SYMBOL_NAME (sym)[nlen] = '\0';
1401 SYMBOL_INIT_DEMANGLED_NAME (sym, &objfile->symbol_obstack);
1404 /* Advance STRING beyond the reference id. */
1410 SYMBOL_LANGUAGE (sym) = current_subfile->language;
1411 SYMBOL_NAME (sym) = (char *)
1412 obstack_alloc (&objfile->symbol_obstack, ((p - string) + 1));
1413 /* Open-coded memcpy--saves function call time. */
1414 /* FIXME: Does it really? Try replacing with simple strcpy and
1415 try it on an executable with a large symbol table. */
1416 /* FIXME: considering that gcc can open code memcpy anyway, I
1417 doubt it. xoxorich. */
1419 register char *p1 = string;
1420 register char *p2 = SYMBOL_NAME (sym);
1428 /* If this symbol is from a C++ compilation, then attempt to cache the
1429 demangled form for future reference. This is a typical time versus
1430 space tradeoff, that was decided in favor of time because it sped up
1431 C++ symbol lookups by a factor of about 20. */
1433 SYMBOL_INIT_DEMANGLED_NAME (sym, &objfile->symbol_obstack);
1437 /* Determine the type of name being defined. */
1439 /* Getting GDB to correctly skip the symbol on an undefined symbol
1440 descriptor and not ever dump core is a very dodgy proposition if
1441 we do things this way. I say the acorn RISC machine can just
1442 fix their compiler. */
1443 /* The Acorn RISC machine's compiler can put out locals that don't
1444 start with "234=" or "(3,4)=", so assume anything other than the
1445 deftypes we know how to handle is a local. */
1446 if (!strchr ("cfFGpPrStTvVXCR", *p))
1448 if (isdigit (*p) || *p == '(' || *p == '-')
1457 /* c is a special case, not followed by a type-number.
1458 SYMBOL:c=iVALUE for an integer constant symbol.
1459 SYMBOL:c=rVALUE for a floating constant symbol.
1460 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
1461 e.g. "b:c=e6,0" for "const b = blob1"
1462 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
1465 SYMBOL_CLASS (sym) = LOC_CONST;
1466 SYMBOL_TYPE (sym) = error_type (&p, objfile);
1467 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1468 add_symbol_to_list (sym, &file_symbols);
1476 double d = atof (p);
1479 /* FIXME-if-picky-about-floating-accuracy: Should be using
1480 target arithmetic to get the value. real.c in GCC
1481 probably has the necessary code. */
1483 /* FIXME: lookup_fundamental_type is a hack. We should be
1484 creating a type especially for the type of float constants.
1485 Problem is, what type should it be?
1487 Also, what should the name of this type be? Should we
1488 be using 'S' constants (see stabs.texinfo) instead? */
1490 SYMBOL_TYPE (sym) = lookup_fundamental_type (objfile,
1493 obstack_alloc (&objfile->symbol_obstack,
1494 TYPE_LENGTH (SYMBOL_TYPE (sym)));
1495 store_typed_floating (dbl_valu, SYMBOL_TYPE (sym), d);
1496 SYMBOL_VALUE_BYTES (sym) = dbl_valu;
1497 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
1502 /* Defining integer constants this way is kind of silly,
1503 since 'e' constants allows the compiler to give not
1504 only the value, but the type as well. C has at least
1505 int, long, unsigned int, and long long as constant
1506 types; other languages probably should have at least
1507 unsigned as well as signed constants. */
1509 /* We just need one int constant type for all objfiles.
1510 It doesn't depend on languages or anything (arguably its
1511 name should be a language-specific name for a type of
1512 that size, but I'm inclined to say that if the compiler
1513 wants a nice name for the type, it can use 'e'). */
1514 static struct type *int_const_type;
1516 /* Yes, this is as long as a *host* int. That is because we
1518 if (int_const_type == NULL)
1520 init_type (TYPE_CODE_INT,
1521 sizeof (int) * HOST_CHAR_BIT / TARGET_CHAR_BIT, 0,
1523 (struct objfile *) NULL);
1524 SYMBOL_TYPE (sym) = int_const_type;
1525 SYMBOL_VALUE (sym) = atoi (p);
1526 SYMBOL_CLASS (sym) = LOC_CONST;
1530 /* SYMBOL:c=eTYPE,INTVALUE for a constant symbol whose value
1531 can be represented as integral.
1532 e.g. "b:c=e6,0" for "const b = blob1"
1533 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
1535 SYMBOL_CLASS (sym) = LOC_CONST;
1536 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1540 SYMBOL_TYPE (sym) = error_type (&p, objfile);
1545 /* If the value is too big to fit in an int (perhaps because
1546 it is unsigned), or something like that, we silently get
1547 a bogus value. The type and everything else about it is
1548 correct. Ideally, we should be using whatever we have
1549 available for parsing unsigned and long long values,
1551 SYMBOL_VALUE (sym) = atoi (p);
1556 SYMBOL_CLASS (sym) = LOC_CONST;
1557 SYMBOL_TYPE (sym) = error_type (&p, objfile);
1560 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1561 add_symbol_to_list (sym, &file_symbols);
1565 /* The name of a caught exception. */
1566 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1567 SYMBOL_CLASS (sym) = LOC_LABEL;
1568 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1569 SYMBOL_VALUE_ADDRESS (sym) = valu;
1570 add_symbol_to_list (sym, &local_symbols);
1574 /* A static function definition. */
1575 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1576 SYMBOL_CLASS (sym) = LOC_BLOCK;
1577 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1578 add_symbol_to_list (sym, &file_symbols);
1579 /* fall into process_function_types. */
1581 process_function_types:
1582 /* Function result types are described as the result type in stabs.
1583 We need to convert this to the function-returning-type-X type
1584 in GDB. E.g. "int" is converted to "function returning int". */
1585 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_FUNC)
1586 SYMBOL_TYPE (sym) = lookup_function_type (SYMBOL_TYPE (sym));
1588 /* All functions in C++ have prototypes. */
1589 if (SYMBOL_LANGUAGE (sym) == language_cplus)
1590 TYPE_FLAGS (SYMBOL_TYPE (sym)) |= TYPE_FLAG_PROTOTYPED;
1592 /* fall into process_prototype_types */
1594 process_prototype_types:
1595 /* Sun acc puts declared types of arguments here. */
1598 struct type *ftype = SYMBOL_TYPE (sym);
1603 /* Obtain a worst case guess for the number of arguments
1604 by counting the semicolons. */
1611 /* Allocate parameter information fields and fill them in. */
1612 TYPE_FIELDS (ftype) = (struct field *)
1613 TYPE_ALLOC (ftype, nsemi * sizeof (struct field));
1618 /* A type number of zero indicates the start of varargs.
1619 FIXME: GDB currently ignores vararg functions. */
1620 if (p[0] == '0' && p[1] == '\0')
1622 ptype = read_type (&p, objfile);
1624 /* The Sun compilers mark integer arguments, which should
1625 be promoted to the width of the calling conventions, with
1626 a type which references itself. This type is turned into
1627 a TYPE_CODE_VOID type by read_type, and we have to turn
1628 it back into builtin_type_int here.
1629 FIXME: Do we need a new builtin_type_promoted_int_arg ? */
1630 if (TYPE_CODE (ptype) == TYPE_CODE_VOID)
1631 ptype = builtin_type_int;
1632 TYPE_FIELD_TYPE (ftype, nparams) = ptype;
1633 TYPE_FIELD_ARTIFICIAL (ftype, nparams++) = 0;
1635 TYPE_NFIELDS (ftype) = nparams;
1636 TYPE_FLAGS (ftype) |= TYPE_FLAG_PROTOTYPED;
1641 /* A global function definition. */
1642 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1643 SYMBOL_CLASS (sym) = LOC_BLOCK;
1644 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1645 add_symbol_to_list (sym, &global_symbols);
1646 goto process_function_types;
1649 /* For a class G (global) symbol, it appears that the
1650 value is not correct. It is necessary to search for the
1651 corresponding linker definition to find the value.
1652 These definitions appear at the end of the namelist. */
1653 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1654 SYMBOL_CLASS (sym) = LOC_STATIC;
1655 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1656 /* Don't add symbol references to global_sym_chain.
1657 Symbol references don't have valid names and wont't match up with
1658 minimal symbols when the global_sym_chain is relocated.
1659 We'll fixup symbol references when we fixup the defining symbol. */
1660 if (SYMBOL_NAME (sym) && SYMBOL_NAME (sym)[0] != '#')
1662 i = hashname (SYMBOL_NAME (sym));
1663 SYMBOL_VALUE_CHAIN (sym) = global_sym_chain[i];
1664 global_sym_chain[i] = sym;
1666 add_symbol_to_list (sym, &global_symbols);
1669 /* This case is faked by a conditional above,
1670 when there is no code letter in the dbx data.
1671 Dbx data never actually contains 'l'. */
1674 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1675 SYMBOL_CLASS (sym) = LOC_LOCAL;
1676 SYMBOL_VALUE (sym) = valu;
1677 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1678 add_symbol_to_list (sym, &local_symbols);
1683 /* pF is a two-letter code that means a function parameter in Fortran.
1684 The type-number specifies the type of the return value.
1685 Translate it into a pointer-to-function type. */
1689 = lookup_pointer_type
1690 (lookup_function_type (read_type (&p, objfile)));
1693 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1695 /* Normally this is a parameter, a LOC_ARG. On the i960, it
1696 can also be a LOC_LOCAL_ARG depending on symbol type. */
1697 #ifndef DBX_PARM_SYMBOL_CLASS
1698 #define DBX_PARM_SYMBOL_CLASS(type) LOC_ARG
1701 SYMBOL_CLASS (sym) = DBX_PARM_SYMBOL_CLASS (type);
1702 SYMBOL_VALUE (sym) = valu;
1703 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1704 add_symbol_to_list (sym, &local_symbols);
1706 if (TARGET_BYTE_ORDER != BFD_ENDIAN_BIG)
1708 /* On little-endian machines, this crud is never necessary,
1709 and, if the extra bytes contain garbage, is harmful. */
1713 /* If it's gcc-compiled, if it says `short', believe it. */
1714 if (processing_gcc_compilation || BELIEVE_PCC_PROMOTION)
1717 if (!BELIEVE_PCC_PROMOTION)
1719 /* This is the signed type which arguments get promoted to. */
1720 static struct type *pcc_promotion_type;
1721 /* This is the unsigned type which arguments get promoted to. */
1722 static struct type *pcc_unsigned_promotion_type;
1724 /* Call it "int" because this is mainly C lossage. */
1725 if (pcc_promotion_type == NULL)
1726 pcc_promotion_type =
1727 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
1730 if (pcc_unsigned_promotion_type == NULL)
1731 pcc_unsigned_promotion_type =
1732 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
1733 TYPE_FLAG_UNSIGNED, "unsigned int", NULL);
1735 if (BELIEVE_PCC_PROMOTION_TYPE)
1737 /* This is defined on machines (e.g. sparc) where we
1738 should believe the type of a PCC 'short' argument,
1739 but shouldn't believe the address (the address is the
1740 address of the corresponding int).
1742 My guess is that this correction, as opposed to
1743 changing the parameter to an 'int' (as done below,
1744 for PCC on most machines), is the right thing to do
1745 on all machines, but I don't want to risk breaking
1746 something that already works. On most PCC machines,
1747 the sparc problem doesn't come up because the calling
1748 function has to zero the top bytes (not knowing
1749 whether the called function wants an int or a short),
1750 so there is little practical difference between an
1751 int and a short (except perhaps what happens when the
1752 GDB user types "print short_arg = 0x10000;").
1754 Hacked for SunOS 4.1 by gnu@cygnus.com. In 4.1, the
1755 compiler actually produces the correct address (we
1756 don't need to fix it up). I made this code adapt so
1757 that it will offset the symbol if it was pointing at
1758 an int-aligned location and not otherwise. This way
1759 you can use the same gdb for 4.0.x and 4.1 systems.
1761 If the parameter is shorter than an int, and is
1762 integral (e.g. char, short, or unsigned equivalent),
1763 and is claimed to be passed on an integer boundary,
1764 don't believe it! Offset the parameter's address to
1765 the tail-end of that integer. */
1767 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) < TYPE_LENGTH (pcc_promotion_type)
1768 && TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_INT
1769 && 0 == SYMBOL_VALUE (sym) % TYPE_LENGTH (pcc_promotion_type))
1771 SYMBOL_VALUE (sym) += TYPE_LENGTH (pcc_promotion_type)
1772 - TYPE_LENGTH (SYMBOL_TYPE (sym));
1778 /* If PCC says a parameter is a short or a char,
1779 it is really an int. */
1780 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) < TYPE_LENGTH (pcc_promotion_type)
1781 && TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_INT)
1784 TYPE_UNSIGNED (SYMBOL_TYPE (sym))
1785 ? pcc_unsigned_promotion_type
1786 : pcc_promotion_type;
1793 /* acc seems to use P to declare the prototypes of functions that
1794 are referenced by this file. gdb is not prepared to deal
1795 with this extra information. FIXME, it ought to. */
1798 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1799 goto process_prototype_types;
1804 /* Parameter which is in a register. */
1805 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1806 SYMBOL_CLASS (sym) = LOC_REGPARM;
1807 SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu);
1808 if (SYMBOL_VALUE (sym) >= NUM_REGS + NUM_PSEUDO_REGS)
1810 complain (®_value_complaint, SYMBOL_VALUE (sym),
1811 NUM_REGS + NUM_PSEUDO_REGS,
1812 SYMBOL_SOURCE_NAME (sym));
1813 SYMBOL_VALUE (sym) = SP_REGNUM; /* Known safe, though useless */
1815 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1816 add_symbol_to_list (sym, &local_symbols);
1820 /* Register variable (either global or local). */
1821 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1822 SYMBOL_CLASS (sym) = LOC_REGISTER;
1823 SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu);
1824 if (SYMBOL_VALUE (sym) >= NUM_REGS + NUM_PSEUDO_REGS)
1826 complain (®_value_complaint, SYMBOL_VALUE (sym),
1827 NUM_REGS + NUM_PSEUDO_REGS,
1828 SYMBOL_SOURCE_NAME (sym));
1829 SYMBOL_VALUE (sym) = SP_REGNUM; /* Known safe, though useless */
1831 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1832 if (within_function)
1834 /* Sun cc uses a pair of symbols, one 'p' and one 'r' with the same
1835 name to represent an argument passed in a register.
1836 GCC uses 'P' for the same case. So if we find such a symbol pair
1837 we combine it into one 'P' symbol. For Sun cc we need to do this
1838 regardless of REG_STRUCT_HAS_ADDR, because the compiler puts out
1839 the 'p' symbol even if it never saves the argument onto the stack.
1841 On most machines, we want to preserve both symbols, so that
1842 we can still get information about what is going on with the
1843 stack (VAX for computing args_printed, using stack slots instead
1844 of saved registers in backtraces, etc.).
1846 Note that this code illegally combines
1847 main(argc) struct foo argc; { register struct foo argc; }
1848 but this case is considered pathological and causes a warning
1849 from a decent compiler. */
1852 && local_symbols->nsyms > 0
1853 #ifndef USE_REGISTER_NOT_ARG
1854 && REG_STRUCT_HAS_ADDR_P ()
1855 && REG_STRUCT_HAS_ADDR (processing_gcc_compilation,
1857 && (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT
1858 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION
1859 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_SET
1860 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_BITSTRING)
1864 struct symbol *prev_sym;
1865 prev_sym = local_symbols->symbol[local_symbols->nsyms - 1];
1866 if ((SYMBOL_CLASS (prev_sym) == LOC_REF_ARG
1867 || SYMBOL_CLASS (prev_sym) == LOC_ARG)
1868 && STREQ (SYMBOL_NAME (prev_sym), SYMBOL_NAME (sym)))
1870 SYMBOL_CLASS (prev_sym) = LOC_REGPARM;
1871 /* Use the type from the LOC_REGISTER; that is the type
1872 that is actually in that register. */
1873 SYMBOL_TYPE (prev_sym) = SYMBOL_TYPE (sym);
1874 SYMBOL_VALUE (prev_sym) = SYMBOL_VALUE (sym);
1879 add_symbol_to_list (sym, &local_symbols);
1882 add_symbol_to_list (sym, &file_symbols);
1886 /* Static symbol at top level of file */
1887 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1888 SYMBOL_CLASS (sym) = LOC_STATIC;
1889 SYMBOL_VALUE_ADDRESS (sym) = valu;
1890 #ifdef STATIC_TRANSFORM_NAME
1891 if (IS_STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym)))
1893 struct minimal_symbol *msym;
1894 msym = lookup_minimal_symbol (SYMBOL_NAME (sym), NULL, objfile);
1897 SYMBOL_NAME (sym) = STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym));
1898 SYMBOL_VALUE_ADDRESS (sym) = SYMBOL_VALUE_ADDRESS (msym);
1902 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1903 add_symbol_to_list (sym, &file_symbols);
1907 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1909 /* For a nameless type, we don't want a create a symbol, thus we
1910 did not use `sym'. Return without further processing. */
1914 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
1915 SYMBOL_VALUE (sym) = valu;
1916 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1917 /* C++ vagaries: we may have a type which is derived from
1918 a base type which did not have its name defined when the
1919 derived class was output. We fill in the derived class's
1920 base part member's name here in that case. */
1921 if (TYPE_NAME (SYMBOL_TYPE (sym)) != NULL)
1922 if ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT
1923 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION)
1924 && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)))
1927 for (j = TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)) - 1; j >= 0; j--)
1928 if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) == 0)
1929 TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) =
1930 type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym), j));
1933 if (TYPE_NAME (SYMBOL_TYPE (sym)) == NULL)
1935 /* gcc-2.6 or later (when using -fvtable-thunks)
1936 emits a unique named type for a vtable entry.
1937 Some gdb code depends on that specific name. */
1938 extern const char vtbl_ptr_name[];
1940 if ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_PTR
1941 && strcmp (SYMBOL_NAME (sym), vtbl_ptr_name))
1942 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_FUNC)
1944 /* If we are giving a name to a type such as "pointer to
1945 foo" or "function returning foo", we better not set
1946 the TYPE_NAME. If the program contains "typedef char
1947 *caddr_t;", we don't want all variables of type char
1948 * to print as caddr_t. This is not just a
1949 consequence of GDB's type management; PCC and GCC (at
1950 least through version 2.4) both output variables of
1951 either type char * or caddr_t with the type number
1952 defined in the 't' symbol for caddr_t. If a future
1953 compiler cleans this up it GDB is not ready for it
1954 yet, but if it becomes ready we somehow need to
1955 disable this check (without breaking the PCC/GCC2.4
1960 Fortunately, this check seems not to be necessary
1961 for anything except pointers or functions. */
1962 /* ezannoni: 2000-10-26. This seems to apply for
1963 versions of gcc older than 2.8. This was the original
1964 problem: with the following code gdb would tell that
1965 the type for name1 is caddr_t, and func is char()
1966 typedef char *caddr_t;
1978 /* Pascal accepts names for pointer types. */
1979 if (current_subfile->language == language_pascal)
1981 TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_NAME (sym);
1985 TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_NAME (sym);
1988 add_symbol_to_list (sym, &file_symbols);
1992 /* Struct, union, or enum tag. For GNU C++, this can be be followed
1993 by 't' which means we are typedef'ing it as well. */
1994 synonym = *p == 't';
1998 /* The semantics of C++ state that "struct foo { ... }" also defines
1999 a typedef for "foo". Unfortunately, cfront never makes the typedef
2000 when translating C++ into C. We make the typedef here so that
2001 "ptype foo" works as expected for cfront translated code. */
2002 else if (current_subfile->language == language_cplus)
2005 SYMBOL_TYPE (sym) = read_type (&p, objfile);
2007 /* For a nameless type, we don't want a create a symbol, thus we
2008 did not use `sym'. Return without further processing. */
2012 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
2013 SYMBOL_VALUE (sym) = valu;
2014 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
2015 if (TYPE_TAG_NAME (SYMBOL_TYPE (sym)) == 0)
2016 TYPE_TAG_NAME (SYMBOL_TYPE (sym))
2017 = obconcat (&objfile->type_obstack, "", "", SYMBOL_NAME (sym));
2018 add_symbol_to_list (sym, &file_symbols);
2022 /* Clone the sym and then modify it. */
2023 register struct symbol *typedef_sym = (struct symbol *)
2024 obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol));
2025 *typedef_sym = *sym;
2026 SYMBOL_CLASS (typedef_sym) = LOC_TYPEDEF;
2027 SYMBOL_VALUE (typedef_sym) = valu;
2028 SYMBOL_NAMESPACE (typedef_sym) = VAR_NAMESPACE;
2029 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
2030 TYPE_NAME (SYMBOL_TYPE (sym))
2031 = obconcat (&objfile->type_obstack, "", "", SYMBOL_NAME (sym));
2032 add_symbol_to_list (typedef_sym, &file_symbols);
2037 /* Static symbol of local scope */
2038 SYMBOL_TYPE (sym) = read_type (&p, objfile);
2039 SYMBOL_CLASS (sym) = LOC_STATIC;
2040 SYMBOL_VALUE_ADDRESS (sym) = valu;
2041 #ifdef STATIC_TRANSFORM_NAME
2042 if (IS_STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym)))
2044 struct minimal_symbol *msym;
2045 msym = lookup_minimal_symbol (SYMBOL_NAME (sym), NULL, objfile);
2048 SYMBOL_NAME (sym) = STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym));
2049 SYMBOL_VALUE_ADDRESS (sym) = SYMBOL_VALUE_ADDRESS (msym);
2053 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2055 add_symbol_to_list (sym, &global_symbols);
2057 add_symbol_to_list (sym, &local_symbols);
2061 /* Reference parameter */
2062 SYMBOL_TYPE (sym) = read_type (&p, objfile);
2063 SYMBOL_CLASS (sym) = LOC_REF_ARG;
2064 SYMBOL_VALUE (sym) = valu;
2065 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2066 add_symbol_to_list (sym, &local_symbols);
2070 /* Reference parameter which is in a register. */
2071 SYMBOL_TYPE (sym) = read_type (&p, objfile);
2072 SYMBOL_CLASS (sym) = LOC_REGPARM_ADDR;
2073 SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu);
2074 if (SYMBOL_VALUE (sym) >= NUM_REGS + NUM_PSEUDO_REGS)
2076 complain (®_value_complaint, SYMBOL_VALUE (sym),
2077 NUM_REGS + NUM_PSEUDO_REGS,
2078 SYMBOL_SOURCE_NAME (sym));
2079 SYMBOL_VALUE (sym) = SP_REGNUM; /* Known safe, though useless */
2081 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2082 add_symbol_to_list (sym, &local_symbols);
2086 /* This is used by Sun FORTRAN for "function result value".
2087 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
2088 that Pascal uses it too, but when I tried it Pascal used
2089 "x:3" (local symbol) instead. */
2090 SYMBOL_TYPE (sym) = read_type (&p, objfile);
2091 SYMBOL_CLASS (sym) = LOC_LOCAL;
2092 SYMBOL_VALUE (sym) = valu;
2093 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2094 add_symbol_to_list (sym, &local_symbols);
2097 /* New code added to support cfront stabs strings.
2098 Note: case 'P' already handled above */
2100 /* Cfront type continuation coming up!
2101 Find the original definition and add to it.
2102 We'll have to do this for the typedef too,
2103 since we cloned the symbol to define a type in read_type.
2104 Stabs info examples:
2106 foo__1CFv :ZtF (first def foo__1CFv:F(0,3);(0,24))
2107 C:ZsC;;__ct__1CFv func1__1CFv func2__1CFv ... ;;;
2108 where C is the name of the class.
2109 Unfortunately, we can't lookup the original symbol yet 'cuz
2110 we haven't finished reading all the symbols.
2111 Instead, we save it for processing later */
2112 process_later (sym, p, resolve_cfront_continuation);
2113 SYMBOL_TYPE (sym) = error_type (&p, objfile); /* FIXME! change later */
2114 SYMBOL_CLASS (sym) = LOC_CONST;
2115 SYMBOL_VALUE (sym) = 0;
2116 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2117 /* Don't add to list - we'll delete it later when
2118 we add the continuation to the real sym */
2120 /* End of new code added to support cfront stabs strings */
2123 SYMBOL_TYPE (sym) = error_type (&p, objfile);
2124 SYMBOL_CLASS (sym) = LOC_CONST;
2125 SYMBOL_VALUE (sym) = 0;
2126 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2127 add_symbol_to_list (sym, &file_symbols);
2131 /* When passing structures to a function, some systems sometimes pass
2132 the address in a register, not the structure itself. */
2134 if (REG_STRUCT_HAS_ADDR_P ()
2135 && REG_STRUCT_HAS_ADDR (processing_gcc_compilation, SYMBOL_TYPE (sym))
2136 && (SYMBOL_CLASS (sym) == LOC_REGPARM || SYMBOL_CLASS (sym) == LOC_ARG))
2138 struct type *symbol_type = check_typedef (SYMBOL_TYPE (sym));
2140 if ((TYPE_CODE (symbol_type) == TYPE_CODE_STRUCT)
2141 || (TYPE_CODE (symbol_type) == TYPE_CODE_UNION)
2142 || (TYPE_CODE (symbol_type) == TYPE_CODE_BITSTRING)
2143 || (TYPE_CODE (symbol_type) == TYPE_CODE_SET))
2145 /* If REG_STRUCT_HAS_ADDR yields non-zero we have to convert
2146 LOC_REGPARM to LOC_REGPARM_ADDR for structures and unions. */
2147 if (SYMBOL_CLASS (sym) == LOC_REGPARM)
2148 SYMBOL_CLASS (sym) = LOC_REGPARM_ADDR;
2149 /* Likewise for converting LOC_ARG to LOC_REF_ARG (for the 7th
2150 and subsequent arguments on the sparc, for example). */
2151 else if (SYMBOL_CLASS (sym) == LOC_ARG)
2152 SYMBOL_CLASS (sym) = LOC_REF_ARG;
2156 /* Is there more to parse? For example LRS/alias information? */
2157 while (*p && *p == ';')
2160 if (*p && p[0] == 'l' && p[1] == '(')
2162 /* GNU extensions for live range splitting may be appended to
2163 the end of the stab string. eg. "l(#1,#2);l(#3,#5)" */
2165 /* Resolve the live range and add it to SYM's live range list. */
2166 if (!resolve_live_range (objfile, sym, p))
2169 /* Find end of live range info. */
2170 p = strchr (p, ')');
2171 if (!*p || *p != ')')
2173 complain (&lrs_general_complaint, "live range format not recognized");
2182 /* Add the live range found in P to the symbol SYM in objfile OBJFILE. Returns
2183 non-zero on success, zero otherwise. */
2186 resolve_live_range (struct objfile *objfile, struct symbol *sym, char *p)
2189 CORE_ADDR start, end;
2191 /* Sanity check the beginning of the stabs string. */
2192 if (!*p || *p != 'l')
2194 complain (&lrs_general_complaint, "live range string 1");
2199 if (!*p || *p != '(')
2201 complain (&lrs_general_complaint, "live range string 2");
2206 /* Get starting value of range and advance P past the reference id.
2208 ?!? In theory, the process_reference should never fail, but we should
2209 catch that case just in case the compiler scrogged the stabs. */
2210 refnum = process_reference (&p);
2211 start = ref_search_value (refnum);
2214 complain (&lrs_general_complaint, "Live range symbol not found 1");
2218 if (!*p || *p != ',')
2220 complain (&lrs_general_complaint, "live range string 3");
2225 /* Get ending value of range and advance P past the reference id.
2227 ?!? In theory, the process_reference should never fail, but we should
2228 catch that case just in case the compiler scrogged the stabs. */
2229 refnum = process_reference (&p);
2230 end = ref_search_value (refnum);
2233 complain (&lrs_general_complaint, "Live range symbol not found 2");
2237 if (!*p || *p != ')')
2239 complain (&lrs_general_complaint, "live range string 4");
2243 /* Now that we know the bounds of the range, add it to the
2245 add_live_range (objfile, sym, start, end);
2250 /* Add a new live range defined by START and END to the symbol SYM
2251 in objfile OBJFILE. */
2254 add_live_range (struct objfile *objfile, struct symbol *sym, CORE_ADDR start,
2257 struct range_list *r, *rs;
2261 complain (&lrs_general_complaint, "end of live range follows start");
2265 /* Alloc new live range structure. */
2266 r = (struct range_list *)
2267 obstack_alloc (&objfile->type_obstack,
2268 sizeof (struct range_list));
2273 /* Append this range to the symbol's range list. */
2274 if (!SYMBOL_RANGES (sym))
2275 SYMBOL_RANGES (sym) = r;
2278 /* Get the last range for the symbol. */
2279 for (rs = SYMBOL_RANGES (sym); rs->next; rs = rs->next)
2286 /* Skip rest of this symbol and return an error type.
2288 General notes on error recovery: error_type always skips to the
2289 end of the symbol (modulo cretinous dbx symbol name continuation).
2290 Thus code like this:
2292 if (*(*pp)++ != ';')
2293 return error_type (pp, objfile);
2295 is wrong because if *pp starts out pointing at '\0' (typically as the
2296 result of an earlier error), it will be incremented to point to the
2297 start of the next symbol, which might produce strange results, at least
2298 if you run off the end of the string table. Instead use
2301 return error_type (pp, objfile);
2307 foo = error_type (pp, objfile);
2311 And in case it isn't obvious, the point of all this hair is so the compiler
2312 can define new types and new syntaxes, and old versions of the
2313 debugger will be able to read the new symbol tables. */
2315 static struct type *
2316 error_type (char **pp, struct objfile *objfile)
2318 complain (&error_type_complaint);
2321 /* Skip to end of symbol. */
2322 while (**pp != '\0')
2327 /* Check for and handle cretinous dbx symbol name continuation! */
2328 if ((*pp)[-1] == '\\' || (*pp)[-1] == '?')
2330 *pp = next_symbol_text (objfile);
2337 return (builtin_type_error);
2341 /* Read type information or a type definition; return the type. Even
2342 though this routine accepts either type information or a type
2343 definition, the distinction is relevant--some parts of stabsread.c
2344 assume that type information starts with a digit, '-', or '(' in
2345 deciding whether to call read_type. */
2348 read_type (register char **pp, struct objfile *objfile)
2350 register struct type *type = 0;
2353 char type_descriptor;
2355 /* Size in bits of type if specified by a type attribute, or -1 if
2356 there is no size attribute. */
2359 /* Used to distinguish string and bitstring from char-array and set. */
2362 /* Read type number if present. The type number may be omitted.
2363 for instance in a two-dimensional array declared with type
2364 "ar1;1;10;ar1;1;10;4". */
2365 if ((**pp >= '0' && **pp <= '9')
2369 if (read_type_number (pp, typenums) != 0)
2370 return error_type (pp, objfile);
2372 /* Type is not being defined here. Either it already exists,
2373 or this is a forward reference to it. dbx_alloc_type handles
2376 return dbx_alloc_type (typenums, objfile);
2378 /* Type is being defined here. */
2380 Also skip the type descriptor - we get it below with (*pp)[-1]. */
2385 /* 'typenums=' not present, type is anonymous. Read and return
2386 the definition, but don't put it in the type vector. */
2387 typenums[0] = typenums[1] = -1;
2392 type_descriptor = (*pp)[-1];
2393 switch (type_descriptor)
2397 enum type_code code;
2399 /* Used to index through file_symbols. */
2400 struct pending *ppt;
2403 /* Name including "struct", etc. */
2407 char *from, *to, *p, *q1, *q2;
2409 /* Set the type code according to the following letter. */
2413 code = TYPE_CODE_STRUCT;
2416 code = TYPE_CODE_UNION;
2419 code = TYPE_CODE_ENUM;
2423 /* Complain and keep going, so compilers can invent new
2424 cross-reference types. */
2425 static struct complaint msg =
2426 {"Unrecognized cross-reference type `%c'", 0, 0};
2427 complain (&msg, (*pp)[0]);
2428 code = TYPE_CODE_STRUCT;
2433 q1 = strchr (*pp, '<');
2434 p = strchr (*pp, ':');
2436 return error_type (pp, objfile);
2437 if (q1 && p > q1 && p[1] == ':')
2439 int nesting_level = 0;
2440 for (q2 = q1; *q2; q2++)
2444 else if (*q2 == '>')
2446 else if (*q2 == ':' && nesting_level == 0)
2451 return error_type (pp, objfile);
2454 (char *) obstack_alloc (&objfile->type_obstack, p - *pp + 1);
2456 /* Copy the name. */
2462 /* Set the pointer ahead of the name which we just read, and
2467 /* Now check to see whether the type has already been
2468 declared. This was written for arrays of cross-referenced
2469 types before we had TYPE_CODE_TARGET_STUBBED, so I'm pretty
2470 sure it is not necessary anymore. But it might be a good
2471 idea, to save a little memory. */
2473 for (ppt = file_symbols; ppt; ppt = ppt->next)
2474 for (i = 0; i < ppt->nsyms; i++)
2476 struct symbol *sym = ppt->symbol[i];
2478 if (SYMBOL_CLASS (sym) == LOC_TYPEDEF
2479 && SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE
2480 && (TYPE_CODE (SYMBOL_TYPE (sym)) == code)
2481 && STREQ (SYMBOL_NAME (sym), type_name))
2483 obstack_free (&objfile->type_obstack, type_name);
2484 type = SYMBOL_TYPE (sym);
2489 /* Didn't find the type to which this refers, so we must
2490 be dealing with a forward reference. Allocate a type
2491 structure for it, and keep track of it so we can
2492 fill in the rest of the fields when we get the full
2494 type = dbx_alloc_type (typenums, objfile);
2495 TYPE_CODE (type) = code;
2496 TYPE_TAG_NAME (type) = type_name;
2497 INIT_CPLUS_SPECIFIC (type);
2498 TYPE_FLAGS (type) |= TYPE_FLAG_STUB;
2500 add_undefined_type (type);
2504 case '-': /* RS/6000 built-in type */
2518 /* We deal with something like t(1,2)=(3,4)=... which
2519 the Lucid compiler and recent gcc versions (post 2.7.3) use. */
2521 /* Allocate and enter the typedef type first.
2522 This handles recursive types. */
2523 type = dbx_alloc_type (typenums, objfile);
2524 TYPE_CODE (type) = TYPE_CODE_TYPEDEF;
2526 struct type *xtype = read_type (pp, objfile);
2529 /* It's being defined as itself. That means it is "void". */
2530 TYPE_CODE (type) = TYPE_CODE_VOID;
2531 TYPE_LENGTH (type) = 1;
2533 else if (type_size >= 0 || is_string)
2535 /* This is the absolute wrong way to construct types. Every
2536 other debug format has found a way around this problem and
2537 the related problems with unnecessarily stubbed types;
2538 someone motivated should attempt to clean up the issue
2539 here as well. Once a type pointed to has been created it
2540 should not be modified. */
2541 replace_type (type, xtype);
2542 TYPE_NAME (type) = NULL;
2543 TYPE_TAG_NAME (type) = NULL;
2547 TYPE_FLAGS (type) |= TYPE_FLAG_TARGET_STUB;
2548 TYPE_TARGET_TYPE (type) = xtype;
2553 /* In the following types, we must be sure to overwrite any existing
2554 type that the typenums refer to, rather than allocating a new one
2555 and making the typenums point to the new one. This is because there
2556 may already be pointers to the existing type (if it had been
2557 forward-referenced), and we must change it to a pointer, function,
2558 reference, or whatever, *in-place*. */
2561 type1 = read_type (pp, objfile);
2562 type = make_pointer_type (type1, dbx_lookup_type (typenums));
2565 case '&': /* Reference to another type */
2566 type1 = read_type (pp, objfile);
2567 type = make_reference_type (type1, dbx_lookup_type (typenums));
2570 case 'f': /* Function returning another type */
2571 if (os9k_stabs && **pp == '(')
2573 /* Function prototype; parse it.
2574 We must conditionalize this on os9k_stabs because otherwise
2575 it could be confused with a Sun-style (1,3) typenumber
2581 t = read_type (pp, objfile);
2586 type1 = read_type (pp, objfile);
2587 type = make_function_type (type1, dbx_lookup_type (typenums));
2590 case 'g': /* Prototyped function. (Sun) */
2592 /* Unresolved questions:
2594 - According to Sun's ``STABS Interface Manual'', for 'f'
2595 and 'F' symbol descriptors, a `0' in the argument type list
2596 indicates a varargs function. But it doesn't say how 'g'
2597 type descriptors represent that info. Someone with access
2598 to Sun's toolchain should try it out.
2600 - According to the comment in define_symbol (search for
2601 `process_prototype_types:'), Sun emits integer arguments as
2602 types which ref themselves --- like `void' types. Do we
2603 have to deal with that here, too? Again, someone with
2604 access to Sun's toolchain should try it out and let us
2607 const char *type_start = (*pp) - 1;
2608 struct type *return_type = read_type (pp, objfile);
2609 struct type *func_type
2610 = make_function_type (return_type, dbx_lookup_type (typenums));
2613 struct type_list *next;
2617 while (**pp && **pp != '#')
2619 struct type *arg_type = read_type (pp, objfile);
2620 struct type_list *new = alloca (sizeof (*new));
2621 new->type = arg_type;
2622 new->next = arg_types;
2630 static struct complaint msg = {
2631 "Prototyped function type didn't end arguments with `#':\n%s",
2634 complain (&msg, type_start);
2637 /* If there is just one argument whose type is `void', then
2638 that's just an empty argument list. */
2640 && ! arg_types->next
2641 && TYPE_CODE (arg_types->type) == TYPE_CODE_VOID)
2644 TYPE_FIELDS (func_type)
2645 = (struct field *) TYPE_ALLOC (func_type,
2646 num_args * sizeof (struct field));
2647 memset (TYPE_FIELDS (func_type), 0, num_args * sizeof (struct field));
2650 struct type_list *t;
2652 /* We stuck each argument type onto the front of the list
2653 when we read it, so the list is reversed. Build the
2654 fields array right-to-left. */
2655 for (t = arg_types, i = num_args - 1; t; t = t->next, i--)
2656 TYPE_FIELD_TYPE (func_type, i) = t->type;
2658 TYPE_NFIELDS (func_type) = num_args;
2659 TYPE_FLAGS (func_type) |= TYPE_FLAG_PROTOTYPED;
2665 case 'k': /* Const qualifier on some type (Sun) */
2666 case 'c': /* Const qualifier on some type (OS9000) */
2667 /* Because 'c' means other things to AIX and 'k' is perfectly good,
2668 only accept 'c' in the os9k_stabs case. */
2669 if (type_descriptor == 'c' && !os9k_stabs)
2670 return error_type (pp, objfile);
2671 type = read_type (pp, objfile);
2672 type = make_cv_type (1, TYPE_VOLATILE (type), type,
2673 dbx_lookup_type (typenums));
2676 case 'B': /* Volatile qual on some type (Sun) */
2677 case 'i': /* Volatile qual on some type (OS9000) */
2678 /* Because 'i' means other things to AIX and 'B' is perfectly good,
2679 only accept 'i' in the os9k_stabs case. */
2680 if (type_descriptor == 'i' && !os9k_stabs)
2681 return error_type (pp, objfile);
2682 type = read_type (pp, objfile);
2683 type = make_cv_type (TYPE_CONST (type), 1, type,
2684 dbx_lookup_type (typenums));
2688 if (isdigit (**pp) || **pp == '(' || **pp == '-')
2689 { /* Member (class & variable) type */
2690 /* FIXME -- we should be doing smash_to_XXX types here. */
2692 struct type *domain = read_type (pp, objfile);
2693 struct type *memtype;
2696 /* Invalid member type data format. */
2697 return error_type (pp, objfile);
2700 memtype = read_type (pp, objfile);
2701 type = dbx_alloc_type (typenums, objfile);
2702 smash_to_member_type (type, domain, memtype);
2705 /* type attribute */
2708 /* Skip to the semicolon. */
2709 while (**pp != ';' && **pp != '\0')
2712 return error_type (pp, objfile);
2714 ++ * pp; /* Skip the semicolon. */
2719 type_size = atoi (attr + 1);
2729 /* Ignore unrecognized type attributes, so future compilers
2730 can invent new ones. */
2738 case '#': /* Method (class & fn) type */
2739 if ((*pp)[0] == '#')
2741 /* We'll get the parameter types from the name. */
2742 struct type *return_type;
2745 return_type = read_type (pp, objfile);
2746 if (*(*pp)++ != ';')
2747 complain (&invalid_member_complaint, symnum);
2748 type = allocate_stub_method (return_type);
2749 if (typenums[0] != -1)
2750 *dbx_lookup_type (typenums) = type;
2754 struct type *domain = read_type (pp, objfile);
2755 struct type *return_type;
2759 /* Invalid member type data format. */
2760 return error_type (pp, objfile);
2764 return_type = read_type (pp, objfile);
2765 args = read_args (pp, ';', objfile);
2766 type = dbx_alloc_type (typenums, objfile);
2767 smash_to_method_type (type, domain, return_type, args);
2771 case 'r': /* Range type */
2772 type = read_range_type (pp, typenums, objfile);
2773 if (typenums[0] != -1)
2774 *dbx_lookup_type (typenums) = type;
2779 /* Const and volatile qualified type. */
2780 type = read_type (pp, objfile);
2783 /* Sun ACC builtin int type */
2784 type = read_sun_builtin_type (pp, typenums, objfile);
2785 if (typenums[0] != -1)
2786 *dbx_lookup_type (typenums) = type;
2790 case 'R': /* Sun ACC builtin float type */
2791 type = read_sun_floating_type (pp, typenums, objfile);
2792 if (typenums[0] != -1)
2793 *dbx_lookup_type (typenums) = type;
2796 case 'e': /* Enumeration type */
2797 type = dbx_alloc_type (typenums, objfile);
2798 type = read_enum_type (pp, type, objfile);
2799 if (typenums[0] != -1)
2800 *dbx_lookup_type (typenums) = type;
2803 case 's': /* Struct type */
2804 case 'u': /* Union type */
2806 enum type_code type_code = TYPE_CODE_UNDEF;
2807 type = dbx_alloc_type (typenums, objfile);
2808 switch (type_descriptor)
2811 type_code = TYPE_CODE_STRUCT;
2814 type_code = TYPE_CODE_UNION;
2817 type = read_struct_type (pp, type, type_code, objfile);
2821 case 'a': /* Array type */
2823 return error_type (pp, objfile);
2826 type = dbx_alloc_type (typenums, objfile);
2827 type = read_array_type (pp, type, objfile);
2829 TYPE_CODE (type) = TYPE_CODE_STRING;
2833 type1 = read_type (pp, objfile);
2834 type = create_set_type ((struct type *) NULL, type1);
2836 TYPE_CODE (type) = TYPE_CODE_BITSTRING;
2837 if (typenums[0] != -1)
2838 *dbx_lookup_type (typenums) = type;
2842 --*pp; /* Go back to the symbol in error */
2843 /* Particularly important if it was \0! */
2844 return error_type (pp, objfile);
2849 warning ("GDB internal error, type is NULL in stabsread.c\n");
2850 return error_type (pp, objfile);
2853 /* Size specified in a type attribute overrides any other size. */
2854 if (type_size != -1)
2855 TYPE_LENGTH (type) = (type_size + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT;
2860 /* RS/6000 xlc/dbx combination uses a set of builtin types, starting from -1.
2861 Return the proper type node for a given builtin type number. */
2863 static struct type *
2864 rs6000_builtin_type (int typenum)
2866 /* We recognize types numbered from -NUMBER_RECOGNIZED to -1. */
2867 #define NUMBER_RECOGNIZED 34
2868 /* This includes an empty slot for type number -0. */
2869 static struct type *negative_types[NUMBER_RECOGNIZED + 1];
2870 struct type *rettype = NULL;
2872 if (typenum >= 0 || typenum < -NUMBER_RECOGNIZED)
2874 complain (&rs6000_builtin_complaint, typenum);
2875 return builtin_type_error;
2877 if (negative_types[-typenum] != NULL)
2878 return negative_types[-typenum];
2880 #if TARGET_CHAR_BIT != 8
2881 #error This code wrong for TARGET_CHAR_BIT not 8
2882 /* These definitions all assume that TARGET_CHAR_BIT is 8. I think
2883 that if that ever becomes not true, the correct fix will be to
2884 make the size in the struct type to be in bits, not in units of
2891 /* The size of this and all the other types are fixed, defined
2892 by the debugging format. If there is a type called "int" which
2893 is other than 32 bits, then it should use a new negative type
2894 number (or avoid negative type numbers for that case).
2895 See stabs.texinfo. */
2896 rettype = init_type (TYPE_CODE_INT, 4, 0, "int", NULL);
2899 rettype = init_type (TYPE_CODE_INT, 1, 0, "char", NULL);
2902 rettype = init_type (TYPE_CODE_INT, 2, 0, "short", NULL);
2905 rettype = init_type (TYPE_CODE_INT, 4, 0, "long", NULL);
2908 rettype = init_type (TYPE_CODE_INT, 1, TYPE_FLAG_UNSIGNED,
2909 "unsigned char", NULL);
2912 rettype = init_type (TYPE_CODE_INT, 1, 0, "signed char", NULL);
2915 rettype = init_type (TYPE_CODE_INT, 2, TYPE_FLAG_UNSIGNED,
2916 "unsigned short", NULL);
2919 rettype = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED,
2920 "unsigned int", NULL);
2923 rettype = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED,
2926 rettype = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED,
2927 "unsigned long", NULL);
2930 rettype = init_type (TYPE_CODE_VOID, 1, 0, "void", NULL);
2933 /* IEEE single precision (32 bit). */
2934 rettype = init_type (TYPE_CODE_FLT, 4, 0, "float", NULL);
2937 /* IEEE double precision (64 bit). */
2938 rettype = init_type (TYPE_CODE_FLT, 8, 0, "double", NULL);
2941 /* This is an IEEE double on the RS/6000, and different machines with
2942 different sizes for "long double" should use different negative
2943 type numbers. See stabs.texinfo. */
2944 rettype = init_type (TYPE_CODE_FLT, 8, 0, "long double", NULL);
2947 rettype = init_type (TYPE_CODE_INT, 4, 0, "integer", NULL);
2950 rettype = init_type (TYPE_CODE_BOOL, 4, TYPE_FLAG_UNSIGNED,
2954 rettype = init_type (TYPE_CODE_FLT, 4, 0, "short real", NULL);
2957 rettype = init_type (TYPE_CODE_FLT, 8, 0, "real", NULL);
2960 rettype = init_type (TYPE_CODE_ERROR, 0, 0, "stringptr", NULL);
2963 rettype = init_type (TYPE_CODE_CHAR, 1, TYPE_FLAG_UNSIGNED,
2967 rettype = init_type (TYPE_CODE_BOOL, 1, TYPE_FLAG_UNSIGNED,
2971 rettype = init_type (TYPE_CODE_BOOL, 2, TYPE_FLAG_UNSIGNED,
2975 rettype = init_type (TYPE_CODE_BOOL, 4, TYPE_FLAG_UNSIGNED,
2979 rettype = init_type (TYPE_CODE_BOOL, 4, TYPE_FLAG_UNSIGNED,
2983 /* Complex type consisting of two IEEE single precision values. */
2984 rettype = init_type (TYPE_CODE_COMPLEX, 8, 0, "complex", NULL);
2985 TYPE_TARGET_TYPE (rettype) = init_type (TYPE_CODE_FLT, 4, 0, "float",
2989 /* Complex type consisting of two IEEE double precision values. */
2990 rettype = init_type (TYPE_CODE_COMPLEX, 16, 0, "double complex", NULL);
2991 TYPE_TARGET_TYPE (rettype) = init_type (TYPE_CODE_FLT, 8, 0, "double",
2995 rettype = init_type (TYPE_CODE_INT, 1, 0, "integer*1", NULL);
2998 rettype = init_type (TYPE_CODE_INT, 2, 0, "integer*2", NULL);
3001 rettype = init_type (TYPE_CODE_INT, 4, 0, "integer*4", NULL);
3004 rettype = init_type (TYPE_CODE_CHAR, 2, 0, "wchar", NULL);
3007 rettype = init_type (TYPE_CODE_INT, 8, 0, "long long", NULL);
3010 rettype = init_type (TYPE_CODE_INT, 8, TYPE_FLAG_UNSIGNED,
3011 "unsigned long long", NULL);
3014 rettype = init_type (TYPE_CODE_INT, 8, TYPE_FLAG_UNSIGNED,
3018 rettype = init_type (TYPE_CODE_INT, 8, 0, "integer*8", NULL);
3021 negative_types[-typenum] = rettype;
3025 /* This page contains subroutines of read_type. */
3027 /* Read member function stabs info for C++ classes. The form of each member
3030 NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;
3032 An example with two member functions is:
3034 afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;
3036 For the case of overloaded operators, the format is op$::*.funcs, where
3037 $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
3038 name (such as `+=') and `.' marks the end of the operator name.
3040 Returns 1 for success, 0 for failure. */
3043 read_member_functions (struct field_info *fip, char **pp, struct type *type,
3044 struct objfile *objfile)
3048 /* Total number of member functions defined in this class. If the class
3049 defines two `f' functions, and one `g' function, then this will have
3051 int total_length = 0;
3055 struct next_fnfield *next;
3056 struct fn_field fn_field;
3059 struct type *look_ahead_type;
3060 struct next_fnfieldlist *new_fnlist;
3061 struct next_fnfield *new_sublist;
3065 /* Process each list until we find something that is not a member function
3066 or find the end of the functions. */
3070 /* We should be positioned at the start of the function name.
3071 Scan forward to find the first ':' and if it is not the
3072 first of a "::" delimiter, then this is not a member function. */
3084 look_ahead_type = NULL;
3087 new_fnlist = (struct next_fnfieldlist *)
3088 xmalloc (sizeof (struct next_fnfieldlist));
3089 make_cleanup (xfree, new_fnlist);
3090 memset (new_fnlist, 0, sizeof (struct next_fnfieldlist));
3092 if ((*pp)[0] == 'o' && (*pp)[1] == 'p' && is_cplus_marker ((*pp)[2]))
3094 /* This is a completely wierd case. In order to stuff in the
3095 names that might contain colons (the usual name delimiter),
3096 Mike Tiemann defined a different name format which is
3097 signalled if the identifier is "op$". In that case, the
3098 format is "op$::XXXX." where XXXX is the name. This is
3099 used for names like "+" or "=". YUUUUUUUK! FIXME! */
3100 /* This lets the user type "break operator+".
3101 We could just put in "+" as the name, but that wouldn't
3103 static char opname[32] =
3104 {'o', 'p', CPLUS_MARKER};
3105 char *o = opname + 3;
3107 /* Skip past '::'. */
3110 STABS_CONTINUE (pp, objfile);
3116 main_fn_name = savestring (opname, o - opname);
3122 main_fn_name = savestring (*pp, p - *pp);
3123 /* Skip past '::'. */
3126 new_fnlist->fn_fieldlist.name = main_fn_name;
3131 (struct next_fnfield *) xmalloc (sizeof (struct next_fnfield));
3132 make_cleanup (xfree, new_sublist);
3133 memset (new_sublist, 0, sizeof (struct next_fnfield));
3135 /* Check for and handle cretinous dbx symbol name continuation! */
3136 if (look_ahead_type == NULL)
3139 STABS_CONTINUE (pp, objfile);
3141 new_sublist->fn_field.type = read_type (pp, objfile);
3144 /* Invalid symtab info for member function. */
3150 /* g++ version 1 kludge */
3151 new_sublist->fn_field.type = look_ahead_type;
3152 look_ahead_type = NULL;
3162 /* If this is just a stub, then we don't have the real name here. */
3164 if (TYPE_STUB (new_sublist->fn_field.type))
3166 if (!TYPE_DOMAIN_TYPE (new_sublist->fn_field.type))
3167 TYPE_DOMAIN_TYPE (new_sublist->fn_field.type) = type;
3168 new_sublist->fn_field.is_stub = 1;
3170 new_sublist->fn_field.physname = savestring (*pp, p - *pp);
3173 /* Set this member function's visibility fields. */
3176 case VISIBILITY_PRIVATE:
3177 new_sublist->fn_field.is_private = 1;
3179 case VISIBILITY_PROTECTED:
3180 new_sublist->fn_field.is_protected = 1;
3184 STABS_CONTINUE (pp, objfile);
3187 case 'A': /* Normal functions. */
3188 new_sublist->fn_field.is_const = 0;
3189 new_sublist->fn_field.is_volatile = 0;
3192 case 'B': /* `const' member functions. */
3193 new_sublist->fn_field.is_const = 1;
3194 new_sublist->fn_field.is_volatile = 0;
3197 case 'C': /* `volatile' member function. */
3198 new_sublist->fn_field.is_const = 0;
3199 new_sublist->fn_field.is_volatile = 1;
3202 case 'D': /* `const volatile' member function. */
3203 new_sublist->fn_field.is_const = 1;
3204 new_sublist->fn_field.is_volatile = 1;
3207 case '*': /* File compiled with g++ version 1 -- no info */
3212 complain (&const_vol_complaint, **pp);
3221 /* virtual member function, followed by index.
3222 The sign bit is set to distinguish pointers-to-methods
3223 from virtual function indicies. Since the array is
3224 in words, the quantity must be shifted left by 1
3225 on 16 bit machine, and by 2 on 32 bit machine, forcing
3226 the sign bit out, and usable as a valid index into
3227 the array. Remove the sign bit here. */
3228 new_sublist->fn_field.voffset =
3229 (0x7fffffff & read_huge_number (pp, ';', &nbits)) + 2;
3233 STABS_CONTINUE (pp, objfile);
3234 if (**pp == ';' || **pp == '\0')
3236 /* Must be g++ version 1. */
3237 new_sublist->fn_field.fcontext = 0;
3241 /* Figure out from whence this virtual function came.
3242 It may belong to virtual function table of
3243 one of its baseclasses. */
3244 look_ahead_type = read_type (pp, objfile);
3247 /* g++ version 1 overloaded methods. */
3251 new_sublist->fn_field.fcontext = look_ahead_type;
3260 look_ahead_type = NULL;
3266 /* static member function. */
3268 int slen = strlen (main_fn_name);
3270 new_sublist->fn_field.voffset = VOFFSET_STATIC;
3272 /* For static member functions, we can't tell if they
3273 are stubbed, as they are put out as functions, and not as
3275 GCC v2 emits the fully mangled name if
3276 dbxout.c:flag_minimal_debug is not set, so we have to
3277 detect a fully mangled physname here and set is_stub
3278 accordingly. Fully mangled physnames in v2 start with
3279 the member function name, followed by two underscores.
3280 GCC v3 currently always emits stubbed member functions,
3281 but with fully mangled physnames, which start with _Z. */
3282 if (!(strncmp (new_sublist->fn_field.physname,
3283 main_fn_name, slen) == 0
3284 && new_sublist->fn_field.physname[slen] == '_'
3285 && new_sublist->fn_field.physname[slen + 1] == '_'))
3287 new_sublist->fn_field.is_stub = 1;
3294 complain (&member_fn_complaint, (*pp)[-1]);
3295 /* Fall through into normal member function. */
3298 /* normal member function. */
3299 new_sublist->fn_field.voffset = 0;
3300 new_sublist->fn_field.fcontext = 0;
3304 new_sublist->next = sublist;
3305 sublist = new_sublist;
3307 STABS_CONTINUE (pp, objfile);
3309 while (**pp != ';' && **pp != '\0');
3312 STABS_CONTINUE (pp, objfile);
3314 /* Skip GCC 3.X member functions which are duplicates of the callable
3315 constructor/destructor. */
3316 if (strcmp (main_fn_name, "__base_ctor") == 0
3317 || strcmp (main_fn_name, "__base_dtor") == 0
3318 || strcmp (main_fn_name, "__deleting_dtor") == 0)
3320 xfree (main_fn_name);
3324 new_fnlist->fn_fieldlist.fn_fields = (struct fn_field *)
3325 obstack_alloc (&objfile->type_obstack,
3326 sizeof (struct fn_field) * length);
3327 memset (new_fnlist->fn_fieldlist.fn_fields, 0,
3328 sizeof (struct fn_field) * length);
3329 for (i = length; (i--, sublist); sublist = sublist->next)
3331 new_fnlist->fn_fieldlist.fn_fields[i] = sublist->fn_field;
3334 new_fnlist->fn_fieldlist.length = length;
3335 new_fnlist->next = fip->fnlist;
3336 fip->fnlist = new_fnlist;
3338 total_length += length;
3344 ALLOCATE_CPLUS_STRUCT_TYPE (type);
3345 TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
3346 TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * nfn_fields);
3347 memset (TYPE_FN_FIELDLISTS (type), 0,
3348 sizeof (struct fn_fieldlist) * nfn_fields);
3349 TYPE_NFN_FIELDS (type) = nfn_fields;
3350 TYPE_NFN_FIELDS_TOTAL (type) = total_length;
3356 /* Special GNU C++ name.
3358 Returns 1 for success, 0 for failure. "failure" means that we can't
3359 keep parsing and it's time for error_type(). */
3362 read_cpp_abbrev (struct field_info *fip, char **pp, struct type *type,
3363 struct objfile *objfile)
3368 struct type *context;
3378 /* At this point, *pp points to something like "22:23=*22...",
3379 where the type number before the ':' is the "context" and
3380 everything after is a regular type definition. Lookup the
3381 type, find it's name, and construct the field name. */
3383 context = read_type (pp, objfile);
3387 case 'f': /* $vf -- a virtual function table pointer */
3388 name = type_name_no_tag (context);
3393 fip->list->field.name =
3394 obconcat (&objfile->type_obstack, vptr_name, name, "");
3397 case 'b': /* $vb -- a virtual bsomethingorother */
3398 name = type_name_no_tag (context);
3401 complain (&invalid_cpp_type_complaint, symnum);
3404 fip->list->field.name =
3405 obconcat (&objfile->type_obstack, vb_name, name, "");
3409 complain (&invalid_cpp_abbrev_complaint, *pp);
3410 fip->list->field.name =
3411 obconcat (&objfile->type_obstack,
3412 "INVALID_CPLUSPLUS_ABBREV", "", "");
3416 /* At this point, *pp points to the ':'. Skip it and read the
3422 complain (&invalid_cpp_abbrev_complaint, *pp);
3425 fip->list->field.type = read_type (pp, objfile);
3427 (*pp)++; /* Skip the comma. */
3433 FIELD_BITPOS (fip->list->field) = read_huge_number (pp, ';', &nbits);
3437 /* This field is unpacked. */
3438 FIELD_BITSIZE (fip->list->field) = 0;
3439 fip->list->visibility = VISIBILITY_PRIVATE;
3443 complain (&invalid_cpp_abbrev_complaint, *pp);
3444 /* We have no idea what syntax an unrecognized abbrev would have, so
3445 better return 0. If we returned 1, we would need to at least advance
3446 *pp to avoid an infinite loop. */
3453 read_one_struct_field (struct field_info *fip, char **pp, char *p,
3454 struct type *type, struct objfile *objfile)
3456 /* The following is code to work around cfront generated stabs.
3457 The stabs contains full mangled name for each field.
3458 We try to demangle the name and extract the field name out of it.
3460 if (ARM_DEMANGLING && current_subfile->language == language_cplus)
3466 dem = cplus_demangle (*pp, DMGL_ANSI | DMGL_PARAMS);
3469 dem_p = strrchr (dem, ':');
3470 if (dem_p != 0 && *(dem_p - 1) == ':')
3472 FIELD_NAME (fip->list->field) =
3473 obsavestring (dem_p, strlen (dem_p), &objfile->type_obstack);
3477 FIELD_NAME (fip->list->field) =
3478 obsavestring (*pp, p - *pp, &objfile->type_obstack);
3482 /* end of code for cfront work around */
3485 fip->list->field.name =
3486 obsavestring (*pp, p - *pp, &objfile->type_obstack);
3489 /* This means we have a visibility for a field coming. */
3493 fip->list->visibility = *(*pp)++;
3497 /* normal dbx-style format, no explicit visibility */
3498 fip->list->visibility = VISIBILITY_PUBLIC;
3501 fip->list->field.type = read_type (pp, objfile);
3506 /* Possible future hook for nested types. */
3509 fip->list->field.bitpos = (long) -2; /* nested type */
3519 /* Static class member. */
3520 SET_FIELD_PHYSNAME (fip->list->field, savestring (*pp, p - *pp));
3524 else if (**pp != ',')
3526 /* Bad structure-type format. */
3527 complain (&stabs_general_complaint, "bad structure-type format");
3531 (*pp)++; /* Skip the comma. */
3535 FIELD_BITPOS (fip->list->field) = read_huge_number (pp, ',', &nbits);
3538 complain (&stabs_general_complaint, "bad structure-type format");
3541 FIELD_BITSIZE (fip->list->field) = read_huge_number (pp, ';', &nbits);
3544 complain (&stabs_general_complaint, "bad structure-type format");
3549 if (FIELD_BITPOS (fip->list->field) == 0
3550 && FIELD_BITSIZE (fip->list->field) == 0)
3552 /* This can happen in two cases: (1) at least for gcc 2.4.5 or so,
3553 it is a field which has been optimized out. The correct stab for
3554 this case is to use VISIBILITY_IGNORE, but that is a recent
3555 invention. (2) It is a 0-size array. For example
3556 union { int num; char str[0]; } foo. Printing "<no value>" for
3557 str in "p foo" is OK, since foo.str (and thus foo.str[3])
3558 will continue to work, and a 0-size array as a whole doesn't
3559 have any contents to print.
3561 I suspect this probably could also happen with gcc -gstabs (not
3562 -gstabs+) for static fields, and perhaps other C++ extensions.
3563 Hopefully few people use -gstabs with gdb, since it is intended
3564 for dbx compatibility. */
3566 /* Ignore this field. */
3567 fip->list->visibility = VISIBILITY_IGNORE;
3571 /* Detect an unpacked field and mark it as such.
3572 dbx gives a bit size for all fields.
3573 Note that forward refs cannot be packed,
3574 and treat enums as if they had the width of ints. */
3576 struct type *field_type = check_typedef (FIELD_TYPE (fip->list->field));
3578 if (TYPE_CODE (field_type) != TYPE_CODE_INT
3579 && TYPE_CODE (field_type) != TYPE_CODE_RANGE
3580 && TYPE_CODE (field_type) != TYPE_CODE_BOOL
3581 && TYPE_CODE (field_type) != TYPE_CODE_ENUM)
3583 FIELD_BITSIZE (fip->list->field) = 0;
3585 if ((FIELD_BITSIZE (fip->list->field)
3586 == TARGET_CHAR_BIT * TYPE_LENGTH (field_type)
3587 || (TYPE_CODE (field_type) == TYPE_CODE_ENUM
3588 && FIELD_BITSIZE (fip->list->field) == TARGET_INT_BIT)
3591 FIELD_BITPOS (fip->list->field) % 8 == 0)
3593 FIELD_BITSIZE (fip->list->field) = 0;
3599 /* Read struct or class data fields. They have the form:
3601 NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
3603 At the end, we see a semicolon instead of a field.
3605 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
3608 The optional VISIBILITY is one of:
3610 '/0' (VISIBILITY_PRIVATE)
3611 '/1' (VISIBILITY_PROTECTED)
3612 '/2' (VISIBILITY_PUBLIC)
3613 '/9' (VISIBILITY_IGNORE)
3615 or nothing, for C style fields with public visibility.
3617 Returns 1 for success, 0 for failure. */
3620 read_struct_fields (struct field_info *fip, char **pp, struct type *type,
3621 struct objfile *objfile)
3624 struct nextfield *new;
3626 /* We better set p right now, in case there are no fields at all... */
3630 /* Read each data member type until we find the terminating ';' at the end of
3631 the data member list, or break for some other reason such as finding the
3632 start of the member function list. */
3633 /* Stab string for structure/union does not end with two ';' in
3634 SUN C compiler 5.3 i.e. F6U2, hence check for end of string. */
3636 while (**pp != ';' && **pp != '\0')
3638 if (os9k_stabs && **pp == ',')
3640 STABS_CONTINUE (pp, objfile);
3641 /* Get space to record the next field's data. */
3642 new = (struct nextfield *) xmalloc (sizeof (struct nextfield));
3643 make_cleanup (xfree, new);
3644 memset (new, 0, sizeof (struct nextfield));
3645 new->next = fip->list;
3648 /* Get the field name. */
3651 /* If is starts with CPLUS_MARKER it is a special abbreviation,
3652 unless the CPLUS_MARKER is followed by an underscore, in
3653 which case it is just the name of an anonymous type, which we
3654 should handle like any other type name. */
3656 if (is_cplus_marker (p[0]) && p[1] != '_')
3658 if (!read_cpp_abbrev (fip, pp, type, objfile))
3663 /* Look for the ':' that separates the field name from the field
3664 values. Data members are delimited by a single ':', while member
3665 functions are delimited by a pair of ':'s. When we hit the member
3666 functions (if any), terminate scan loop and return. */
3668 while (*p != ':' && *p != '\0')
3675 /* Check to see if we have hit the member functions yet. */
3680 read_one_struct_field (fip, pp, p, type, objfile);
3682 if (p[0] == ':' && p[1] == ':')
3684 /* chill the list of fields: the last entry (at the head) is a
3685 partially constructed entry which we now scrub. */
3686 fip->list = fip->list->next;
3691 /* The stabs for C++ derived classes contain baseclass information which
3692 is marked by a '!' character after the total size. This function is
3693 called when we encounter the baseclass marker, and slurps up all the
3694 baseclass information.
3696 Immediately following the '!' marker is the number of base classes that
3697 the class is derived from, followed by information for each base class.
3698 For each base class, there are two visibility specifiers, a bit offset
3699 to the base class information within the derived class, a reference to
3700 the type for the base class, and a terminating semicolon.
3702 A typical example, with two base classes, would be "!2,020,19;0264,21;".
3704 Baseclass information marker __________________|| | | | | | |
3705 Number of baseclasses __________________________| | | | | | |
3706 Visibility specifiers (2) ________________________| | | | | |
3707 Offset in bits from start of class _________________| | | | |
3708 Type number for base class ___________________________| | | |
3709 Visibility specifiers (2) _______________________________| | |
3710 Offset in bits from start of class ________________________| |
3711 Type number of base class ____________________________________|
3713 Return 1 for success, 0 for (error-type-inducing) failure. */
3719 read_baseclasses (struct field_info *fip, char **pp, struct type *type,
3720 struct objfile *objfile)
3723 struct nextfield *new;
3731 /* Skip the '!' baseclass information marker. */
3735 ALLOCATE_CPLUS_STRUCT_TYPE (type);
3738 TYPE_N_BASECLASSES (type) = read_huge_number (pp, ',', &nbits);
3744 /* Some stupid compilers have trouble with the following, so break
3745 it up into simpler expressions. */
3746 TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *)
3747 TYPE_ALLOC (type, B_BYTES (TYPE_N_BASECLASSES (type)));
3750 int num_bytes = B_BYTES (TYPE_N_BASECLASSES (type));
3753 pointer = (char *) TYPE_ALLOC (type, num_bytes);
3754 TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *) pointer;
3758 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), TYPE_N_BASECLASSES (type));
3760 for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
3762 new = (struct nextfield *) xmalloc (sizeof (struct nextfield));
3763 make_cleanup (xfree, new);
3764 memset (new, 0, sizeof (struct nextfield));
3765 new->next = fip->list;
3767 FIELD_BITSIZE (new->field) = 0; /* this should be an unpacked field! */
3769 STABS_CONTINUE (pp, objfile);
3773 /* Nothing to do. */
3776 SET_TYPE_FIELD_VIRTUAL (type, i);
3779 /* Unknown character. Complain and treat it as non-virtual. */
3781 static struct complaint msg =
3783 "Unknown virtual character `%c' for baseclass", 0, 0};
3784 complain (&msg, **pp);
3789 new->visibility = *(*pp)++;
3790 switch (new->visibility)
3792 case VISIBILITY_PRIVATE:
3793 case VISIBILITY_PROTECTED:
3794 case VISIBILITY_PUBLIC:
3797 /* Bad visibility format. Complain and treat it as
3800 static struct complaint msg =
3802 "Unknown visibility `%c' for baseclass", 0, 0
3804 complain (&msg, new->visibility);
3805 new->visibility = VISIBILITY_PUBLIC;
3812 /* The remaining value is the bit offset of the portion of the object
3813 corresponding to this baseclass. Always zero in the absence of
3814 multiple inheritance. */
3816 FIELD_BITPOS (new->field) = read_huge_number (pp, ',', &nbits);
3821 /* The last piece of baseclass information is the type of the
3822 base class. Read it, and remember it's type name as this
3825 new->field.type = read_type (pp, objfile);
3826 new->field.name = type_name_no_tag (new->field.type);
3828 /* skip trailing ';' and bump count of number of fields seen */
3837 /* The tail end of stabs for C++ classes that contain a virtual function
3838 pointer contains a tilde, a %, and a type number.
3839 The type number refers to the base class (possibly this class itself) which
3840 contains the vtable pointer for the current class.
3842 This function is called when we have parsed all the method declarations,
3843 so we can look for the vptr base class info. */
3846 read_tilde_fields (struct field_info *fip, char **pp, struct type *type,
3847 struct objfile *objfile)
3851 STABS_CONTINUE (pp, objfile);
3853 /* If we are positioned at a ';', then skip it. */
3863 if (**pp == '=' || **pp == '+' || **pp == '-')
3865 /* Obsolete flags that used to indicate the presence
3866 of constructors and/or destructors. */
3870 /* Read either a '%' or the final ';'. */
3871 if (*(*pp)++ == '%')
3873 /* The next number is the type number of the base class
3874 (possibly our own class) which supplies the vtable for
3875 this class. Parse it out, and search that class to find
3876 its vtable pointer, and install those into TYPE_VPTR_BASETYPE
3877 and TYPE_VPTR_FIELDNO. */
3882 t = read_type (pp, objfile);
3884 while (*p != '\0' && *p != ';')
3890 /* Premature end of symbol. */
3894 TYPE_VPTR_BASETYPE (type) = t;
3895 if (type == t) /* Our own class provides vtbl ptr */
3897 for (i = TYPE_NFIELDS (t) - 1;
3898 i >= TYPE_N_BASECLASSES (t);
3901 if (!strncmp (TYPE_FIELD_NAME (t, i), vptr_name,
3902 sizeof (vptr_name) - 1))
3904 TYPE_VPTR_FIELDNO (type) = i;
3908 /* Virtual function table field not found. */
3909 complain (&vtbl_notfound_complaint, TYPE_NAME (type));
3914 TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t);
3925 attach_fn_fields_to_type (struct field_info *fip, register struct type *type)
3929 for (n = TYPE_NFN_FIELDS (type);
3930 fip->fnlist != NULL;
3931 fip->fnlist = fip->fnlist->next)
3933 --n; /* Circumvent Sun3 compiler bug */
3934 TYPE_FN_FIELDLISTS (type)[n] = fip->fnlist->fn_fieldlist;
3939 /* read cfront class static data.
3940 pp points to string starting with the list of static data
3941 eg: A:ZcA;1@Bpub v2@Bvirpri;__ct__1AFv func__1AFv *sfunc__1AFv ;as__1A ;;
3944 A:ZcA;;foopri__1AFv foopro__1AFv __ct__1AFv __ct__1AFRC1A foopub__1AFv ;;;
3949 read_cfront_static_fields (struct field_info *fip, char **pp, struct type *type,
3950 struct objfile *objfile)
3952 struct nextfield *new;
3955 struct symbol *ref_static = 0;
3957 if (**pp == ';') /* no static data; return */
3963 /* Process each field in the list until we find the terminating ";" */
3965 /* eg: p = "as__1A ;;;" */
3966 STABS_CONTINUE (pp, objfile); /* handle \\ */
3967 while (**pp != ';' && (sname = get_substring (pp, ' '), sname))
3969 ref_static = lookup_symbol (sname, 0, VAR_NAMESPACE, 0, 0); /*demangled_name */
3972 static struct complaint msg =
3974 Unable to find symbol for static data field %s\n",
3976 complain (&msg, sname);
3979 stype = SYMBOL_TYPE (ref_static);
3981 /* allocate a new fip */
3982 new = (struct nextfield *) xmalloc (sizeof (struct nextfield));
3983 make_cleanup (xfree, new);
3984 memset (new, 0, sizeof (struct nextfield));
3985 new->next = fip->list;
3988 /* set visibility */
3989 /* FIXME! no way to tell visibility from stabs??? */
3990 new->visibility = VISIBILITY_PUBLIC;
3992 /* set field info into fip */
3993 fip->list->field.type = stype;
3995 /* set bitpos & bitsize */
3996 SET_FIELD_PHYSNAME (fip->list->field, savestring (sname, strlen (sname)));
3998 /* set name field */
3999 /* The following is code to work around cfront generated stabs.
4000 The stabs contains full mangled name for each field.
4001 We try to demangle the name and extract the field name out of it.
4006 dem = cplus_demangle (sname, DMGL_ANSI | DMGL_PARAMS);
4009 dem_p = strrchr (dem, ':');
4010 if (dem_p != 0 && *(dem_p - 1) == ':')
4012 fip->list->field.name =
4013 obsavestring (dem_p, strlen (dem_p), &objfile->type_obstack);
4017 fip->list->field.name =
4018 obsavestring (sname, strlen (sname), &objfile->type_obstack);
4020 } /* end of code for cfront work around */
4021 } /* loop again for next static field */
4025 /* Copy structure fields to fip so attach_fields_to_type will work.
4026 type has already been created with the initial instance data fields.
4027 Now we want to be able to add the other members to the class,
4028 so we want to add them back to the fip and reattach them again
4029 once we have collected all the class members. */
4032 copy_cfront_struct_fields (struct field_info *fip, struct type *type,
4033 struct objfile *objfile)
4035 int nfields = TYPE_NFIELDS (type);
4037 struct nextfield *new;
4039 /* Copy the fields into the list of fips and reset the types
4040 to remove the old fields */
4042 for (i = 0; i < nfields; i++)
4044 /* allocate a new fip */
4045 new = (struct nextfield *) xmalloc (sizeof (struct nextfield));
4046 make_cleanup (xfree, new);
4047 memset (new, 0, sizeof (struct nextfield));
4048 new->next = fip->list;
4051 /* copy field info into fip */
4052 new->field = TYPE_FIELD (type, i);
4053 /* set visibility */
4054 if (TYPE_FIELD_PROTECTED (type, i))
4055 new->visibility = VISIBILITY_PROTECTED;
4056 else if (TYPE_FIELD_PRIVATE (type, i))
4057 new->visibility = VISIBILITY_PRIVATE;
4059 new->visibility = VISIBILITY_PUBLIC;
4061 /* Now delete the fields from the type since we will be
4062 allocing new space once we get the rest of the fields
4063 in attach_fields_to_type.
4064 The pointer TYPE_FIELDS(type) is left dangling but should
4065 be freed later by objstack_free */
4066 TYPE_FIELDS (type) = 0;
4067 TYPE_NFIELDS (type) = 0;
4072 /* Create the vector of fields, and record how big it is.
4073 We need this info to record proper virtual function table information
4074 for this class's virtual functions. */
4077 attach_fields_to_type (struct field_info *fip, register struct type *type,
4078 struct objfile *objfile)
4080 register int nfields = 0;
4081 register int non_public_fields = 0;
4082 register struct nextfield *scan;
4084 /* Count up the number of fields that we have, as well as taking note of
4085 whether or not there are any non-public fields, which requires us to
4086 allocate and build the private_field_bits and protected_field_bits
4089 for (scan = fip->list; scan != NULL; scan = scan->next)
4092 if (scan->visibility != VISIBILITY_PUBLIC)
4094 non_public_fields++;
4098 /* Now we know how many fields there are, and whether or not there are any
4099 non-public fields. Record the field count, allocate space for the
4100 array of fields, and create blank visibility bitfields if necessary. */
4102 TYPE_NFIELDS (type) = nfields;
4103 TYPE_FIELDS (type) = (struct field *)
4104 TYPE_ALLOC (type, sizeof (struct field) * nfields);
4105 memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields);
4107 if (non_public_fields)
4109 ALLOCATE_CPLUS_STRUCT_TYPE (type);
4111 TYPE_FIELD_PRIVATE_BITS (type) =
4112 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
4113 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields);
4115 TYPE_FIELD_PROTECTED_BITS (type) =
4116 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
4117 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields);
4119 TYPE_FIELD_IGNORE_BITS (type) =
4120 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
4121 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields);
4124 /* Copy the saved-up fields into the field vector. Start from the head
4125 of the list, adding to the tail of the field array, so that they end
4126 up in the same order in the array in which they were added to the list. */
4128 while (nfields-- > 0)
4130 TYPE_FIELD (type, nfields) = fip->list->field;
4131 switch (fip->list->visibility)
4133 case VISIBILITY_PRIVATE:
4134 SET_TYPE_FIELD_PRIVATE (type, nfields);
4137 case VISIBILITY_PROTECTED:
4138 SET_TYPE_FIELD_PROTECTED (type, nfields);
4141 case VISIBILITY_IGNORE:
4142 SET_TYPE_FIELD_IGNORE (type, nfields);
4145 case VISIBILITY_PUBLIC:
4149 /* Unknown visibility. Complain and treat it as public. */
4151 static struct complaint msg =
4153 "Unknown visibility `%c' for field", 0, 0};
4154 complain (&msg, fip->list->visibility);
4158 fip->list = fip->list->next;
4164 static struct complaint multiply_defined_struct =
4165 {"struct/union type gets multiply defined: %s%s", 0, 0};
4168 /* Complain that the compiler has emitted more than one definition for the
4169 structure type TYPE. */
4171 complain_about_struct_wipeout (struct type *type)
4176 if (TYPE_TAG_NAME (type))
4178 name = TYPE_TAG_NAME (type);
4179 switch (TYPE_CODE (type))
4181 case TYPE_CODE_STRUCT: kind = "struct "; break;
4182 case TYPE_CODE_UNION: kind = "union "; break;
4183 case TYPE_CODE_ENUM: kind = "enum "; break;
4187 else if (TYPE_NAME (type))
4189 name = TYPE_NAME (type);
4198 complain (&multiply_defined_struct, kind, name);
4202 /* Read the description of a structure (or union type) and return an object
4203 describing the type.
4205 PP points to a character pointer that points to the next unconsumed token
4206 in the the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;",
4207 *PP will point to "4a:1,0,32;;".
4209 TYPE points to an incomplete type that needs to be filled in.
4211 OBJFILE points to the current objfile from which the stabs information is
4212 being read. (Note that it is redundant in that TYPE also contains a pointer
4213 to this same objfile, so it might be a good idea to eliminate it. FIXME).
4216 static struct type *
4217 read_struct_type (char **pp, struct type *type, enum type_code type_code,
4218 struct objfile *objfile)
4220 struct cleanup *back_to;
4221 struct field_info fi;
4226 /* When describing struct/union/class types in stabs, G++ always drops
4227 all qualifications from the name. So if you've got:
4228 struct A { ... struct B { ... }; ... };
4229 then G++ will emit stabs for `struct A::B' that call it simply
4230 `struct B'. Obviously, if you've got a real top-level definition for
4231 `struct B', or other nested definitions, this is going to cause
4234 Obviously, GDB can't fix this by itself, but it can at least avoid
4235 scribbling on existing structure type objects when new definitions
4237 if (! (TYPE_CODE (type) == TYPE_CODE_UNDEF
4238 || TYPE_STUB (type)))
4240 complain_about_struct_wipeout (type);
4242 /* It's probably best to return the type unchanged. */
4246 back_to = make_cleanup (null_cleanup, 0);
4248 INIT_CPLUS_SPECIFIC (type);
4249 TYPE_CODE (type) = type_code;
4250 TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
4252 /* First comes the total size in bytes. */
4256 TYPE_LENGTH (type) = read_huge_number (pp, 0, &nbits);
4258 return error_type (pp, objfile);
4261 /* Now read the baseclasses, if any, read the regular C struct or C++
4262 class member fields, attach the fields to the type, read the C++
4263 member functions, attach them to the type, and then read any tilde
4264 field (baseclass specifier for the class holding the main vtable). */
4266 if (!read_baseclasses (&fi, pp, type, objfile)
4267 || !read_struct_fields (&fi, pp, type, objfile)
4268 || !attach_fields_to_type (&fi, type, objfile)
4269 || !read_member_functions (&fi, pp, type, objfile)
4270 || !attach_fn_fields_to_type (&fi, type)
4271 || !read_tilde_fields (&fi, pp, type, objfile))
4273 type = error_type (pp, objfile);
4276 /* Fix up any cv-qualified versions of this type. */
4277 finish_cv_type (type);
4278 do_cleanups (back_to);
4282 /* Read a definition of an array type,
4283 and create and return a suitable type object.
4284 Also creates a range type which represents the bounds of that
4287 static struct type *
4288 read_array_type (register char **pp, register struct type *type,
4289 struct objfile *objfile)
4291 struct type *index_type, *element_type, *range_type;
4296 /* Format of an array type:
4297 "ar<index type>;lower;upper;<array_contents_type>".
4298 OS9000: "arlower,upper;<array_contents_type>".
4300 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
4301 for these, produce a type like float[][]. */
4304 index_type = builtin_type_int;
4307 index_type = read_type (pp, objfile);
4309 /* Improper format of array type decl. */
4310 return error_type (pp, objfile);
4314 if (!(**pp >= '0' && **pp <= '9') && **pp != '-')
4319 lower = read_huge_number (pp, os9k_stabs ? ',' : ';', &nbits);
4321 return error_type (pp, objfile);
4323 if (!(**pp >= '0' && **pp <= '9') && **pp != '-')
4328 upper = read_huge_number (pp, ';', &nbits);
4330 return error_type (pp, objfile);
4332 element_type = read_type (pp, objfile);
4341 create_range_type ((struct type *) NULL, index_type, lower, upper);
4342 type = create_array_type (type, element_type, range_type);
4348 /* Read a definition of an enumeration type,
4349 and create and return a suitable type object.
4350 Also defines the symbols that represent the values of the type. */
4352 static struct type *
4353 read_enum_type (register char **pp, register struct type *type,
4354 struct objfile *objfile)
4359 register struct symbol *sym;
4361 struct pending **symlist;
4362 struct pending *osyms, *syms;
4365 int unsigned_enum = 1;
4368 /* FIXME! The stabs produced by Sun CC merrily define things that ought
4369 to be file-scope, between N_FN entries, using N_LSYM. What's a mother
4370 to do? For now, force all enum values to file scope. */
4371 if (within_function)
4372 symlist = &local_symbols;
4375 symlist = &file_symbols;
4377 o_nsyms = osyms ? osyms->nsyms : 0;
4381 /* Size. Perhaps this does not have to be conditionalized on
4382 os9k_stabs (assuming the name of an enum constant can't start
4384 read_huge_number (pp, 0, &nbits);
4386 return error_type (pp, objfile);
4389 /* The aix4 compiler emits an extra field before the enum members;
4390 my guess is it's a type of some sort. Just ignore it. */
4393 /* Skip over the type. */
4397 /* Skip over the colon. */
4401 /* Read the value-names and their values.
4402 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
4403 A semicolon or comma instead of a NAME means the end. */
4404 while (**pp && **pp != ';' && **pp != ',')
4406 STABS_CONTINUE (pp, objfile);
4410 name = obsavestring (*pp, p - *pp, &objfile->symbol_obstack);
4412 n = read_huge_number (pp, ',', &nbits);
4414 return error_type (pp, objfile);
4416 sym = (struct symbol *)
4417 obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol));
4418 memset (sym, 0, sizeof (struct symbol));
4419 SYMBOL_NAME (sym) = name;
4420 SYMBOL_LANGUAGE (sym) = current_subfile->language;
4421 SYMBOL_CLASS (sym) = LOC_CONST;
4422 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
4423 SYMBOL_VALUE (sym) = n;
4426 add_symbol_to_list (sym, symlist);
4431 (*pp)++; /* Skip the semicolon. */
4433 /* Now fill in the fields of the type-structure. */
4435 TYPE_LENGTH (type) = TARGET_INT_BIT / HOST_CHAR_BIT;
4436 TYPE_CODE (type) = TYPE_CODE_ENUM;
4437 TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
4439 TYPE_FLAGS (type) |= TYPE_FLAG_UNSIGNED;
4440 TYPE_NFIELDS (type) = nsyms;
4441 TYPE_FIELDS (type) = (struct field *)
4442 TYPE_ALLOC (type, sizeof (struct field) * nsyms);
4443 memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nsyms);
4445 /* Find the symbols for the values and put them into the type.
4446 The symbols can be found in the symlist that we put them on
4447 to cause them to be defined. osyms contains the old value
4448 of that symlist; everything up to there was defined by us. */
4449 /* Note that we preserve the order of the enum constants, so
4450 that in something like "enum {FOO, LAST_THING=FOO}" we print
4451 FOO, not LAST_THING. */
4453 for (syms = *symlist, n = nsyms - 1; syms; syms = syms->next)
4455 int last = syms == osyms ? o_nsyms : 0;
4456 int j = syms->nsyms;
4457 for (; --j >= last; --n)
4459 struct symbol *xsym = syms->symbol[j];
4460 SYMBOL_TYPE (xsym) = type;
4461 TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym);
4462 TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (xsym);
4463 TYPE_FIELD_BITSIZE (type, n) = 0;
4472 /* Sun's ACC uses a somewhat saner method for specifying the builtin
4473 typedefs in every file (for int, long, etc):
4475 type = b <signed> <width> <format type>; <offset>; <nbits>
4477 optional format type = c or b for char or boolean.
4478 offset = offset from high order bit to start bit of type.
4479 width is # bytes in object of this type, nbits is # bits in type.
4481 The width/offset stuff appears to be for small objects stored in
4482 larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
4485 static struct type *
4486 read_sun_builtin_type (char **pp, int typenums[2], struct objfile *objfile)
4491 enum type_code code = TYPE_CODE_INT;
4502 return error_type (pp, objfile);
4506 /* For some odd reason, all forms of char put a c here. This is strange
4507 because no other type has this honor. We can safely ignore this because
4508 we actually determine 'char'acterness by the number of bits specified in
4510 Boolean forms, e.g Fortran logical*X, put a b here. */
4514 else if (**pp == 'b')
4516 code = TYPE_CODE_BOOL;
4520 /* The first number appears to be the number of bytes occupied
4521 by this type, except that unsigned short is 4 instead of 2.
4522 Since this information is redundant with the third number,
4523 we will ignore it. */
4524 read_huge_number (pp, ';', &nbits);
4526 return error_type (pp, objfile);
4528 /* The second number is always 0, so ignore it too. */
4529 read_huge_number (pp, ';', &nbits);
4531 return error_type (pp, objfile);
4533 /* The third number is the number of bits for this type. */
4534 type_bits = read_huge_number (pp, 0, &nbits);
4536 return error_type (pp, objfile);
4537 /* The type *should* end with a semicolon. If it are embedded
4538 in a larger type the semicolon may be the only way to know where
4539 the type ends. If this type is at the end of the stabstring we
4540 can deal with the omitted semicolon (but we don't have to like
4541 it). Don't bother to complain(), Sun's compiler omits the semicolon
4547 return init_type (TYPE_CODE_VOID, 1,
4548 signed_type ? 0 : TYPE_FLAG_UNSIGNED, (char *) NULL,
4551 return init_type (code,
4552 type_bits / TARGET_CHAR_BIT,
4553 signed_type ? 0 : TYPE_FLAG_UNSIGNED, (char *) NULL,
4557 static struct type *
4558 read_sun_floating_type (char **pp, int typenums[2], struct objfile *objfile)
4563 struct type *rettype;
4565 /* The first number has more details about the type, for example
4567 details = read_huge_number (pp, ';', &nbits);
4569 return error_type (pp, objfile);
4571 /* The second number is the number of bytes occupied by this type */
4572 nbytes = read_huge_number (pp, ';', &nbits);
4574 return error_type (pp, objfile);
4576 if (details == NF_COMPLEX || details == NF_COMPLEX16
4577 || details == NF_COMPLEX32)
4579 rettype = init_type (TYPE_CODE_COMPLEX, nbytes, 0, NULL, objfile);
4580 TYPE_TARGET_TYPE (rettype)
4581 = init_type (TYPE_CODE_FLT, nbytes / 2, 0, NULL, objfile);
4585 return init_type (TYPE_CODE_FLT, nbytes, 0, NULL, objfile);
4588 /* Read a number from the string pointed to by *PP.
4589 The value of *PP is advanced over the number.
4590 If END is nonzero, the character that ends the
4591 number must match END, or an error happens;
4592 and that character is skipped if it does match.
4593 If END is zero, *PP is left pointing to that character.
4595 If the number fits in a long, set *BITS to 0 and return the value.
4596 If not, set *BITS to be the number of bits in the number and return 0.
4598 If encounter garbage, set *BITS to -1 and return 0. */
4601 read_huge_number (char **pp, int end, int *bits)
4618 /* Leading zero means octal. GCC uses this to output values larger
4619 than an int (because that would be hard in decimal). */
4627 upper_limit = ULONG_MAX / radix;
4629 upper_limit = LONG_MAX / radix;
4631 while ((c = *p++) >= '0' && c < ('0' + radix))
4633 if (n <= upper_limit)
4636 n += c - '0'; /* FIXME this overflows anyway */
4641 /* This depends on large values being output in octal, which is
4648 /* Ignore leading zeroes. */
4652 else if (c == '2' || c == '3')
4678 /* Large decimal constants are an error (because it is hard to
4679 count how many bits are in them). */
4685 /* -0x7f is the same as 0x80. So deal with it by adding one to
4686 the number of bits. */
4698 /* It's *BITS which has the interesting information. */
4702 static struct type *
4703 read_range_type (char **pp, int typenums[2], struct objfile *objfile)
4705 char *orig_pp = *pp;
4710 struct type *result_type;
4711 struct type *index_type = NULL;
4713 /* First comes a type we are a subrange of.
4714 In C it is usually 0, 1 or the type being defined. */
4715 if (read_type_number (pp, rangenums) != 0)
4716 return error_type (pp, objfile);
4717 self_subrange = (rangenums[0] == typenums[0] &&
4718 rangenums[1] == typenums[1]);
4723 index_type = read_type (pp, objfile);
4726 /* A semicolon should now follow; skip it. */
4730 /* The remaining two operands are usually lower and upper bounds
4731 of the range. But in some special cases they mean something else. */
4732 n2 = read_huge_number (pp, ';', &n2bits);
4733 n3 = read_huge_number (pp, ';', &n3bits);
4735 if (n2bits == -1 || n3bits == -1)
4736 return error_type (pp, objfile);
4739 goto handle_true_range;
4741 /* If limits are huge, must be large integral type. */
4742 if (n2bits != 0 || n3bits != 0)
4744 char got_signed = 0;
4745 char got_unsigned = 0;
4746 /* Number of bits in the type. */
4749 /* Range from 0 to <large number> is an unsigned large integral type. */
4750 if ((n2bits == 0 && n2 == 0) && n3bits != 0)
4755 /* Range from <large number> to <large number>-1 is a large signed
4756 integral type. Take care of the case where <large number> doesn't
4757 fit in a long but <large number>-1 does. */
4758 else if ((n2bits != 0 && n3bits != 0 && n2bits == n3bits + 1)
4759 || (n2bits != 0 && n3bits == 0
4760 && (n2bits == sizeof (long) * HOST_CHAR_BIT)
4767 if (got_signed || got_unsigned)
4769 return init_type (TYPE_CODE_INT, nbits / TARGET_CHAR_BIT,
4770 got_unsigned ? TYPE_FLAG_UNSIGNED : 0, NULL,
4774 return error_type (pp, objfile);
4777 /* A type defined as a subrange of itself, with bounds both 0, is void. */
4778 if (self_subrange && n2 == 0 && n3 == 0)
4779 return init_type (TYPE_CODE_VOID, 1, 0, NULL, objfile);
4781 /* If n3 is zero and n2 is positive, we want a floating type, and n2
4782 is the width in bytes.
4784 Fortran programs appear to use this for complex types also. To
4785 distinguish between floats and complex, g77 (and others?) seem
4786 to use self-subranges for the complexes, and subranges of int for
4789 Also note that for complexes, g77 sets n2 to the size of one of
4790 the member floats, not the whole complex beast. My guess is that
4791 this was to work well with pre-COMPLEX versions of gdb. */
4793 if (n3 == 0 && n2 > 0)
4795 struct type *float_type
4796 = init_type (TYPE_CODE_FLT, n2, 0, NULL, objfile);
4800 struct type *complex_type =
4801 init_type (TYPE_CODE_COMPLEX, 2 * n2, 0, NULL, objfile);
4802 TYPE_TARGET_TYPE (complex_type) = float_type;
4803 return complex_type;
4809 /* If the upper bound is -1, it must really be an unsigned int. */
4811 else if (n2 == 0 && n3 == -1)
4813 /* It is unsigned int or unsigned long. */
4814 /* GCC 2.3.3 uses this for long long too, but that is just a GDB 3.5
4815 compatibility hack. */
4816 return init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
4817 TYPE_FLAG_UNSIGNED, NULL, objfile);
4820 /* Special case: char is defined (Who knows why) as a subrange of
4821 itself with range 0-127. */
4822 else if (self_subrange && n2 == 0 && n3 == 127)
4823 return init_type (TYPE_CODE_INT, 1, 0, NULL, objfile);
4825 else if (current_symbol && SYMBOL_LANGUAGE (current_symbol) == language_chill
4827 goto handle_true_range;
4829 /* We used to do this only for subrange of self or subrange of int. */
4832 /* -1 is used for the upper bound of (4 byte) "unsigned int" and
4833 "unsigned long", and we already checked for that,
4834 so don't need to test for it here. */
4837 /* n3 actually gives the size. */
4838 return init_type (TYPE_CODE_INT, -n3, TYPE_FLAG_UNSIGNED,
4841 /* Is n3 == 2**(8n)-1 for some integer n? Then it's an
4842 unsigned n-byte integer. But do require n to be a power of
4843 two; we don't want 3- and 5-byte integers flying around. */
4849 for (bytes = 0; (bits & 0xff) == 0xff; bytes++)
4852 && ((bytes - 1) & bytes) == 0) /* "bytes is a power of two" */
4853 return init_type (TYPE_CODE_INT, bytes, TYPE_FLAG_UNSIGNED, NULL,
4857 /* I think this is for Convex "long long". Since I don't know whether
4858 Convex sets self_subrange, I also accept that particular size regardless
4859 of self_subrange. */
4860 else if (n3 == 0 && n2 < 0
4862 || n2 == -TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT))
4863 return init_type (TYPE_CODE_INT, -n2, 0, NULL, objfile);
4864 else if (n2 == -n3 - 1)
4867 return init_type (TYPE_CODE_INT, 1, 0, NULL, objfile);
4869 return init_type (TYPE_CODE_INT, 2, 0, NULL, objfile);
4870 if (n3 == 0x7fffffff)
4871 return init_type (TYPE_CODE_INT, 4, 0, NULL, objfile);
4874 /* We have a real range type on our hands. Allocate space and
4875 return a real pointer. */
4879 index_type = builtin_type_int;
4881 index_type = *dbx_lookup_type (rangenums);
4882 if (index_type == NULL)
4884 /* Does this actually ever happen? Is that why we are worrying
4885 about dealing with it rather than just calling error_type? */
4887 static struct type *range_type_index;
4889 complain (&range_type_base_complaint, rangenums[1]);
4890 if (range_type_index == NULL)
4892 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
4893 0, "range type index type", NULL);
4894 index_type = range_type_index;
4897 result_type = create_range_type ((struct type *) NULL, index_type, n2, n3);
4898 return (result_type);
4901 /* Read in an argument list. This is a list of types, separated by commas
4902 and terminated with END. Return the list of types read in, or (struct type
4903 **)-1 if there is an error. */
4905 static struct type **
4906 read_args (char **pp, int end, struct objfile *objfile)
4908 /* FIXME! Remove this arbitrary limit! */
4909 struct type *types[1024], **rval; /* allow for fns of 1023 parameters */
4915 /* Invalid argument list: no ','. */
4916 return (struct type **) -1;
4918 STABS_CONTINUE (pp, objfile);
4919 types[n++] = read_type (pp, objfile);
4921 (*pp)++; /* get past `end' (the ':' character) */
4925 rval = (struct type **) xmalloc (2 * sizeof (struct type *));
4927 else if (TYPE_CODE (types[n - 1]) != TYPE_CODE_VOID)
4929 rval = (struct type **) xmalloc ((n + 1) * sizeof (struct type *));
4930 memset (rval + n, 0, sizeof (struct type *));
4934 rval = (struct type **) xmalloc (n * sizeof (struct type *));
4936 memcpy (rval, types, n * sizeof (struct type *));
4940 /* Common block handling. */
4942 /* List of symbols declared since the last BCOMM. This list is a tail
4943 of local_symbols. When ECOMM is seen, the symbols on the list
4944 are noted so their proper addresses can be filled in later,
4945 using the common block base address gotten from the assembler
4948 static struct pending *common_block;
4949 static int common_block_i;
4951 /* Name of the current common block. We get it from the BCOMM instead of the
4952 ECOMM to match IBM documentation (even though IBM puts the name both places
4953 like everyone else). */
4954 static char *common_block_name;
4956 /* Process a N_BCOMM symbol. The storage for NAME is not guaranteed
4957 to remain after this function returns. */
4960 common_block_start (char *name, struct objfile *objfile)
4962 if (common_block_name != NULL)
4964 static struct complaint msg =
4966 "Invalid symbol data: common block within common block",
4970 common_block = local_symbols;
4971 common_block_i = local_symbols ? local_symbols->nsyms : 0;
4972 common_block_name = obsavestring (name, strlen (name),
4973 &objfile->symbol_obstack);
4976 /* Process a N_ECOMM symbol. */
4979 common_block_end (struct objfile *objfile)
4981 /* Symbols declared since the BCOMM are to have the common block
4982 start address added in when we know it. common_block and
4983 common_block_i point to the first symbol after the BCOMM in
4984 the local_symbols list; copy the list and hang it off the
4985 symbol for the common block name for later fixup. */
4988 struct pending *new = 0;
4989 struct pending *next;
4992 if (common_block_name == NULL)
4994 static struct complaint msg =
4995 {"ECOMM symbol unmatched by BCOMM", 0, 0};
5000 sym = (struct symbol *)
5001 obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol));
5002 memset (sym, 0, sizeof (struct symbol));
5003 /* Note: common_block_name already saved on symbol_obstack */
5004 SYMBOL_NAME (sym) = common_block_name;
5005 SYMBOL_CLASS (sym) = LOC_BLOCK;
5007 /* Now we copy all the symbols which have been defined since the BCOMM. */
5009 /* Copy all the struct pendings before common_block. */
5010 for (next = local_symbols;
5011 next != NULL && next != common_block;
5014 for (j = 0; j < next->nsyms; j++)
5015 add_symbol_to_list (next->symbol[j], &new);
5018 /* Copy however much of COMMON_BLOCK we need. If COMMON_BLOCK is
5019 NULL, it means copy all the local symbols (which we already did
5022 if (common_block != NULL)
5023 for (j = common_block_i; j < common_block->nsyms; j++)
5024 add_symbol_to_list (common_block->symbol[j], &new);
5026 SYMBOL_TYPE (sym) = (struct type *) new;
5028 /* Should we be putting local_symbols back to what it was?
5031 i = hashname (SYMBOL_NAME (sym));
5032 SYMBOL_VALUE_CHAIN (sym) = global_sym_chain[i];
5033 global_sym_chain[i] = sym;
5034 common_block_name = NULL;
5037 /* Add a common block's start address to the offset of each symbol
5038 declared to be in it (by being between a BCOMM/ECOMM pair that uses
5039 the common block name). */
5042 fix_common_block (struct symbol *sym, int valu)
5044 struct pending *next = (struct pending *) SYMBOL_TYPE (sym);
5045 for (; next; next = next->next)
5048 for (j = next->nsyms - 1; j >= 0; j--)
5049 SYMBOL_VALUE_ADDRESS (next->symbol[j]) += valu;
5055 /* What about types defined as forward references inside of a small lexical
5057 /* Add a type to the list of undefined types to be checked through
5058 once this file has been read in. */
5061 add_undefined_type (struct type *type)
5063 if (undef_types_length == undef_types_allocated)
5065 undef_types_allocated *= 2;
5066 undef_types = (struct type **)
5067 xrealloc ((char *) undef_types,
5068 undef_types_allocated * sizeof (struct type *));
5070 undef_types[undef_types_length++] = type;
5073 /* Go through each undefined type, see if it's still undefined, and fix it
5074 up if possible. We have two kinds of undefined types:
5076 TYPE_CODE_ARRAY: Array whose target type wasn't defined yet.
5077 Fix: update array length using the element bounds
5078 and the target type's length.
5079 TYPE_CODE_STRUCT, TYPE_CODE_UNION: Structure whose fields were not
5080 yet defined at the time a pointer to it was made.
5081 Fix: Do a full lookup on the struct/union tag. */
5083 cleanup_undefined_types (void)
5087 for (type = undef_types; type < undef_types + undef_types_length; type++)
5089 switch (TYPE_CODE (*type))
5092 case TYPE_CODE_STRUCT:
5093 case TYPE_CODE_UNION:
5094 case TYPE_CODE_ENUM:
5096 /* Check if it has been defined since. Need to do this here
5097 as well as in check_typedef to deal with the (legitimate in
5098 C though not C++) case of several types with the same name
5099 in different source files. */
5100 if (TYPE_STUB (*type))
5102 struct pending *ppt;
5104 /* Name of the type, without "struct" or "union" */
5105 char *typename = TYPE_TAG_NAME (*type);
5107 if (typename == NULL)
5109 static struct complaint msg =
5110 {"need a type name", 0, 0};
5114 for (ppt = file_symbols; ppt; ppt = ppt->next)
5116 for (i = 0; i < ppt->nsyms; i++)
5118 struct symbol *sym = ppt->symbol[i];
5120 if (SYMBOL_CLASS (sym) == LOC_TYPEDEF
5121 && SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE
5122 && (TYPE_CODE (SYMBOL_TYPE (sym)) ==
5124 && STREQ (SYMBOL_NAME (sym), typename))
5126 memcpy (*type, SYMBOL_TYPE (sym),
5127 sizeof (struct type));
5137 static struct complaint msg =
5139 GDB internal error. cleanup_undefined_types with bad type %d.", 0, 0};
5140 complain (&msg, TYPE_CODE (*type));
5146 undef_types_length = 0;
5149 /* Scan through all of the global symbols defined in the object file,
5150 assigning values to the debugging symbols that need to be assigned
5151 to. Get these symbols from the minimal symbol table. */
5154 scan_file_globals (struct objfile *objfile)
5157 struct minimal_symbol *msymbol;
5158 struct symbol *sym, *prev, *rsym;
5159 struct objfile *resolve_objfile;
5161 /* SVR4 based linkers copy referenced global symbols from shared
5162 libraries to the main executable.
5163 If we are scanning the symbols for a shared library, try to resolve
5164 them from the minimal symbols of the main executable first. */
5166 if (symfile_objfile && objfile != symfile_objfile)
5167 resolve_objfile = symfile_objfile;
5169 resolve_objfile = objfile;
5173 /* Avoid expensive loop through all minimal symbols if there are
5174 no unresolved symbols. */
5175 for (hash = 0; hash < HASHSIZE; hash++)
5177 if (global_sym_chain[hash])
5180 if (hash >= HASHSIZE)
5183 for (msymbol = resolve_objfile->msymbols;
5184 msymbol && SYMBOL_NAME (msymbol) != NULL;
5189 /* Skip static symbols. */
5190 switch (MSYMBOL_TYPE (msymbol))
5202 /* Get the hash index and check all the symbols
5203 under that hash index. */
5205 hash = hashname (SYMBOL_NAME (msymbol));
5207 for (sym = global_sym_chain[hash]; sym;)
5209 if (SYMBOL_NAME (msymbol)[0] == SYMBOL_NAME (sym)[0] &&
5210 STREQ (SYMBOL_NAME (msymbol) + 1, SYMBOL_NAME (sym) + 1))
5213 struct alias_list *aliases;
5215 /* Splice this symbol out of the hash chain and
5216 assign the value we have to it. */
5219 SYMBOL_VALUE_CHAIN (prev) = SYMBOL_VALUE_CHAIN (sym);
5223 global_sym_chain[hash] = SYMBOL_VALUE_CHAIN (sym);
5226 /* Check to see whether we need to fix up a common block. */
5227 /* Note: this code might be executed several times for
5228 the same symbol if there are multiple references. */
5230 /* If symbol has aliases, do minimal symbol fixups for each.
5231 These live aliases/references weren't added to
5232 global_sym_chain hash but may also need to be fixed up. */
5233 /* FIXME: Maybe should have added aliases to the global chain, resolved symbol name, then treated aliases as normal
5234 symbols? Still, we wouldn't want to add_to_list. */
5235 /* Now do the same for each alias of this symbol */
5237 aliases = SYMBOL_ALIASES (sym);
5240 if (SYMBOL_CLASS (rsym) == LOC_BLOCK)
5242 fix_common_block (rsym,
5243 SYMBOL_VALUE_ADDRESS (msymbol));
5247 SYMBOL_VALUE_ADDRESS (rsym)
5248 = SYMBOL_VALUE_ADDRESS (msymbol);
5250 SYMBOL_SECTION (rsym) = SYMBOL_SECTION (msymbol);
5253 rsym = aliases->sym;
5254 aliases = aliases->next;
5263 sym = SYMBOL_VALUE_CHAIN (prev);
5267 sym = global_sym_chain[hash];
5273 sym = SYMBOL_VALUE_CHAIN (sym);
5277 if (resolve_objfile == objfile)
5279 resolve_objfile = objfile;
5282 /* Change the storage class of any remaining unresolved globals to
5283 LOC_UNRESOLVED and remove them from the chain. */
5284 for (hash = 0; hash < HASHSIZE; hash++)
5286 sym = global_sym_chain[hash];
5290 sym = SYMBOL_VALUE_CHAIN (sym);
5292 /* Change the symbol address from the misleading chain value
5294 SYMBOL_VALUE_ADDRESS (prev) = 0;
5296 /* Complain about unresolved common block symbols. */
5297 if (SYMBOL_CLASS (prev) == LOC_STATIC)
5298 SYMBOL_CLASS (prev) = LOC_UNRESOLVED;
5300 complain (&unresolved_sym_chain_complaint,
5301 objfile->name, SYMBOL_NAME (prev));
5304 memset (global_sym_chain, 0, sizeof (global_sym_chain));
5307 /* Initialize anything that needs initializing when starting to read
5308 a fresh piece of a symbol file, e.g. reading in the stuff corresponding
5312 stabsread_init (void)
5316 /* Initialize anything that needs initializing when a completely new
5317 symbol file is specified (not just adding some symbols from another
5318 file, e.g. a shared library). */
5321 stabsread_new_init (void)
5323 /* Empty the hash table of global syms looking for values. */
5324 memset (global_sym_chain, 0, sizeof (global_sym_chain));
5327 /* Initialize anything that needs initializing at the same time as
5328 start_symtab() is called. */
5333 global_stabs = NULL; /* AIX COFF */
5334 /* Leave FILENUM of 0 free for builtin types and this file's types. */
5335 n_this_object_header_files = 1;
5336 type_vector_length = 0;
5337 type_vector = (struct type **) 0;
5339 /* FIXME: If common_block_name is not already NULL, we should complain(). */
5340 common_block_name = NULL;
5345 /* Call after end_symtab() */
5352 xfree (type_vector);
5355 type_vector_length = 0;
5356 previous_stab_code = 0;
5360 finish_global_stabs (struct objfile *objfile)
5364 patch_block_stabs (global_symbols, global_stabs, objfile);
5365 xfree (global_stabs);
5366 global_stabs = NULL;
5370 /* Initializer for this module */
5373 _initialize_stabsread (void)
5375 undef_types_allocated = 20;
5376 undef_types_length = 0;
5377 undef_types = (struct type **)
5378 xmalloc (undef_types_allocated * sizeof (struct type *));