1 /* Support routines for decoding "stabs" debugging information format.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
3 1996, 1997, 1998, 1999, 2000, 2001, 2002
4 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
23 /* Support routines for reading and decoding debugging information in
24 the "stabs" format. This format is used with many systems that use
25 the a.out object file format, as well as some systems that use
26 COFF or ELF where the stabs data is placed in a special section.
27 Avoid placing any object file format specific code in this file. */
30 #include "gdb_string.h"
32 #include "gdb_obstack.h"
35 #include "expression.h"
38 #include "aout/stab_gnu.h" /* We always use GNU stabs, not native */
40 #include "aout/aout64.h"
41 #include "gdb-stabs.h"
43 #include "complaints.h"
48 #include "cp-support.h"
52 /* Ask stabsread.h to define the vars it normally declares `extern'. */
55 #include "stabsread.h" /* Our own declarations */
58 extern void _initialize_stabsread (void);
60 /* The routines that read and process a complete stabs for a C struct or
61 C++ class pass lists of data member fields and lists of member function
62 fields in an instance of a field_info structure, as defined below.
63 This is part of some reorganization of low level C++ support and is
64 expected to eventually go away... (FIXME) */
70 struct nextfield *next;
72 /* This is the raw visibility from the stab. It is not checked
73 for being one of the visibilities we recognize, so code which
74 examines this field better be able to deal. */
80 struct next_fnfieldlist
82 struct next_fnfieldlist *next;
83 struct fn_fieldlist fn_fieldlist;
89 read_one_struct_field (struct field_info *, char **, char *,
90 struct type *, struct objfile *);
92 static char *get_substring (char **, int);
94 static struct type *dbx_alloc_type (int[2], struct objfile *);
96 static long read_huge_number (char **, int, int *);
98 static struct type *error_type (char **, struct objfile *);
101 patch_block_stabs (struct pending *, struct pending_stabs *,
104 static void fix_common_block (struct symbol *, int);
106 static int read_type_number (char **, int *);
108 static struct type *read_range_type (char **, int[2], struct objfile *);
110 static struct type *read_sun_builtin_type (char **, int[2], struct objfile *);
112 static struct type *read_sun_floating_type (char **, int[2],
115 static struct type *read_enum_type (char **, struct type *, struct objfile *);
117 static struct type *rs6000_builtin_type (int);
120 read_member_functions (struct field_info *, char **, struct type *,
124 read_struct_fields (struct field_info *, char **, struct type *,
128 read_baseclasses (struct field_info *, char **, struct type *,
132 read_tilde_fields (struct field_info *, char **, struct type *,
135 static int attach_fn_fields_to_type (struct field_info *, struct type *);
138 attach_fields_to_type (struct field_info *, struct type *, struct objfile *);
140 static struct type *read_struct_type (char **, struct type *,
144 static struct type *read_array_type (char **, struct type *,
147 static struct field *read_args (char **, int, struct objfile *, int *, int *);
150 read_cpp_abbrev (struct field_info *, char **, struct type *,
153 /* new functions added for cfront support */
156 copy_cfront_struct_fields (struct field_info *, struct type *,
159 static char *get_cfront_method_physname (char *);
162 read_cfront_baseclasses (struct field_info *, char **,
163 struct type *, struct objfile *);
166 read_cfront_static_fields (struct field_info *, char **,
167 struct type *, struct objfile *);
169 read_cfront_member_functions (struct field_info *, char **,
170 struct type *, struct objfile *);
172 static char *find_name_end (char *name);
174 /* end new functions added for cfront support */
177 add_live_range (struct objfile *, struct symbol *, CORE_ADDR, CORE_ADDR);
179 static int resolve_live_range (struct objfile *, struct symbol *, char *);
181 static int process_reference (char **string);
183 static CORE_ADDR ref_search_value (int refnum);
186 resolve_symbol_reference (struct objfile *, struct symbol *, char *);
188 void stabsread_clear_cache (void);
190 static const char vptr_name[] = "_vptr$";
191 static const char vb_name[] = "_vb$";
193 /* Define this as 1 if a pcc declaration of a char or short argument
194 gives the correct address. Otherwise assume pcc gives the
195 address of the corresponding int, which is not the same on a
196 big-endian machine. */
198 #if !defined (BELIEVE_PCC_PROMOTION)
199 #define BELIEVE_PCC_PROMOTION 0
201 #if !defined (BELIEVE_PCC_PROMOTION_TYPE)
202 #define BELIEVE_PCC_PROMOTION_TYPE 0
206 invalid_cpp_abbrev_complaint (const char *arg1)
208 complaint (&symfile_complaints, "invalid C++ abbreviation `%s'", arg1);
212 reg_value_complaint (int arg1, int arg2, const char *arg3)
214 complaint (&symfile_complaints,
215 "register number %d too large (max %d) in symbol %s", arg1, arg2,
220 stabs_general_complaint (const char *arg1)
222 complaint (&symfile_complaints, "%s", arg1);
226 lrs_general_complaint (const char *arg1)
228 complaint (&symfile_complaints, "%s", arg1);
231 /* Make a list of forward references which haven't been defined. */
233 static struct type **undef_types;
234 static int undef_types_allocated;
235 static int undef_types_length;
236 static struct symbol *current_symbol = NULL;
238 /* Check for and handle cretinous stabs symbol name continuation! */
239 #define STABS_CONTINUE(pp,objfile) \
241 if (**(pp) == '\\' || (**(pp) == '?' && (*(pp))[1] == '\0')) \
242 *(pp) = next_symbol_text (objfile); \
245 #if 0 /* OBSOLETE OS9K */
246 // OBSOLETE /* FIXME: These probably should be our own types (like rs6000_builtin_type
247 // OBSOLETE has its own types) rather than builtin_type_*. */
248 // OBSOLETE static struct type **os9k_type_vector[] =
251 // OBSOLETE &builtin_type_int,
252 // OBSOLETE &builtin_type_char,
253 // OBSOLETE &builtin_type_long,
254 // OBSOLETE &builtin_type_short,
255 // OBSOLETE &builtin_type_unsigned_char,
256 // OBSOLETE &builtin_type_unsigned_short,
257 // OBSOLETE &builtin_type_unsigned_long,
258 // OBSOLETE &builtin_type_unsigned_int,
259 // OBSOLETE &builtin_type_float,
260 // OBSOLETE &builtin_type_double,
261 // OBSOLETE &builtin_type_void,
262 // OBSOLETE &builtin_type_long_double
265 // OBSOLETE static void os9k_init_type_vector (struct type **);
267 // OBSOLETE static void
268 // OBSOLETE os9k_init_type_vector (struct type **tv)
270 // OBSOLETE unsigned int i;
271 // OBSOLETE for (i = 0; i < sizeof (os9k_type_vector) / sizeof (struct type **); i++)
272 // OBSOLETE tv[i] = (os9k_type_vector[i] == 0 ? 0 : *(os9k_type_vector[i]));
274 #endif /* OBSOLETE OS9K */
276 /* Look up a dbx type-number pair. Return the address of the slot
277 where the type for that number-pair is stored.
278 The number-pair is in TYPENUMS.
280 This can be used for finding the type associated with that pair
281 or for associating a new type with the pair. */
284 dbx_lookup_type (int typenums[2])
286 register int filenum = typenums[0];
287 register int index = typenums[1];
289 register int real_filenum;
290 register struct header_file *f;
293 if (filenum == -1) /* -1,-1 is for temporary types. */
296 if (filenum < 0 || filenum >= n_this_object_header_files)
298 complaint (&symfile_complaints,
299 "Invalid symbol data: type number (%d,%d) out of range at symtab pos %d.",
300 filenum, index, symnum);
308 /* Caller wants address of address of type. We think
309 that negative (rs6k builtin) types will never appear as
310 "lvalues", (nor should they), so we stuff the real type
311 pointer into a temp, and return its address. If referenced,
312 this will do the right thing. */
313 static struct type *temp_type;
315 temp_type = rs6000_builtin_type (index);
319 /* Type is defined outside of header files.
320 Find it in this object file's type vector. */
321 if (index >= type_vector_length)
323 old_len = type_vector_length;
326 type_vector_length = INITIAL_TYPE_VECTOR_LENGTH;
327 type_vector = (struct type **)
328 xmalloc (type_vector_length * sizeof (struct type *));
330 while (index >= type_vector_length)
332 type_vector_length *= 2;
334 type_vector = (struct type **)
335 xrealloc ((char *) type_vector,
336 (type_vector_length * sizeof (struct type *)));
337 memset (&type_vector[old_len], 0,
338 (type_vector_length - old_len) * sizeof (struct type *));
340 #if 0 /* OBSOLETE OS9K */
341 // OBSOLETE if (os9k_stabs)
342 // OBSOLETE /* Deal with OS9000 fundamental types. */
343 // OBSOLETE os9k_init_type_vector (type_vector);
344 #endif /* OBSOLETE OS9K */
346 return (&type_vector[index]);
350 real_filenum = this_object_header_files[filenum];
352 if (real_filenum >= N_HEADER_FILES (current_objfile))
354 struct type *temp_type;
355 struct type **temp_type_p;
357 warning ("GDB internal error: bad real_filenum");
360 temp_type = init_type (TYPE_CODE_ERROR, 0, 0, NULL, NULL);
361 temp_type_p = (struct type **) xmalloc (sizeof (struct type *));
362 *temp_type_p = temp_type;
366 f = HEADER_FILES (current_objfile) + real_filenum;
368 f_orig_length = f->length;
369 if (index >= f_orig_length)
371 while (index >= f->length)
375 f->vector = (struct type **)
376 xrealloc ((char *) f->vector, f->length * sizeof (struct type *));
377 memset (&f->vector[f_orig_length], 0,
378 (f->length - f_orig_length) * sizeof (struct type *));
380 return (&f->vector[index]);
384 /* Make sure there is a type allocated for type numbers TYPENUMS
385 and return the type object.
386 This can create an empty (zeroed) type object.
387 TYPENUMS may be (-1, -1) to return a new type object that is not
388 put into the type vector, and so may not be referred to by number. */
391 dbx_alloc_type (int typenums[2], struct objfile *objfile)
393 register struct type **type_addr;
395 if (typenums[0] == -1)
397 return (alloc_type (objfile));
400 type_addr = dbx_lookup_type (typenums);
402 /* If we are referring to a type not known at all yet,
403 allocate an empty type for it.
404 We will fill it in later if we find out how. */
407 *type_addr = alloc_type (objfile);
413 /* for all the stabs in a given stab vector, build appropriate types
414 and fix their symbols in given symbol vector. */
417 patch_block_stabs (struct pending *symbols, struct pending_stabs *stabs,
418 struct objfile *objfile)
428 /* for all the stab entries, find their corresponding symbols and
429 patch their types! */
431 for (ii = 0; ii < stabs->count; ++ii)
433 name = stabs->stab[ii];
434 pp = (char *) strchr (name, ':');
438 pp = (char *) strchr (pp, ':');
440 sym = find_symbol_in_list (symbols, name, pp - name);
443 /* FIXME-maybe: it would be nice if we noticed whether
444 the variable was defined *anywhere*, not just whether
445 it is defined in this compilation unit. But neither
446 xlc or GCC seem to need such a definition, and until
447 we do psymtabs (so that the minimal symbols from all
448 compilation units are available now), I'm not sure
449 how to get the information. */
451 /* On xcoff, if a global is defined and never referenced,
452 ld will remove it from the executable. There is then
453 a N_GSYM stab for it, but no regular (C_EXT) symbol. */
454 sym = (struct symbol *)
455 obstack_alloc (&objfile->symbol_obstack,
456 sizeof (struct symbol));
458 memset (sym, 0, sizeof (struct symbol));
459 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
460 SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
462 obsavestring (name, pp - name, &objfile->symbol_obstack);
464 if (*(pp - 1) == 'F' || *(pp - 1) == 'f')
466 /* I don't think the linker does this with functions,
467 so as far as I know this is never executed.
468 But it doesn't hurt to check. */
470 lookup_function_type (read_type (&pp, objfile));
474 SYMBOL_TYPE (sym) = read_type (&pp, objfile);
476 add_symbol_to_list (sym, &global_symbols);
481 if (*(pp - 1) == 'F' || *(pp - 1) == 'f')
484 lookup_function_type (read_type (&pp, objfile));
488 SYMBOL_TYPE (sym) = read_type (&pp, objfile);
496 /* Read a number by which a type is referred to in dbx data,
497 or perhaps read a pair (FILENUM, TYPENUM) in parentheses.
498 Just a single number N is equivalent to (0,N).
499 Return the two numbers by storing them in the vector TYPENUMS.
500 TYPENUMS will then be used as an argument to dbx_lookup_type.
502 Returns 0 for success, -1 for error. */
505 read_type_number (register char **pp, register int *typenums)
511 typenums[0] = read_huge_number (pp, ',', &nbits);
514 typenums[1] = read_huge_number (pp, ')', &nbits);
521 typenums[1] = read_huge_number (pp, 0, &nbits);
529 #define VISIBILITY_PRIVATE '0' /* Stabs character for private field */
530 #define VISIBILITY_PROTECTED '1' /* Stabs character for protected fld */
531 #define VISIBILITY_PUBLIC '2' /* Stabs character for public field */
532 #define VISIBILITY_IGNORE '9' /* Optimized out or zero length */
534 #define CFRONT_VISIBILITY_PRIVATE '2' /* Stabs character for private field */
535 #define CFRONT_VISIBILITY_PUBLIC '1' /* Stabs character for public field */
537 /* This code added to support parsing of ARM/Cfront stabs strings */
539 /* Get substring from string up to char c, advance string pointer past
543 get_substring (char **p, int c)
558 /* Physname gets strcat'd onto sname in order to recreate the mangled
559 name (see funtion gdb_mangle_name in gdbtypes.c). For cfront, make
560 the physname look like that of g++ - take out the initial mangling
561 eg: for sname="a" and fname="foo__1aFPFs_i" return "FPFs_i" */
564 get_cfront_method_physname (char *fname)
567 /* FIXME would like to make this generic for g++ too, but
568 that is already handled in read_member_funcctions */
571 /* search ahead to find the start of the mangled suffix */
572 if (*p == '_' && *(p + 1) == '_') /* compiler generated; probably a ctor/dtor */
574 while (p && (unsigned) ((p + 1) - fname) < strlen (fname) && *(p + 1) != '_')
576 if (!(p && *p == '_' && *(p + 1) == '_'))
577 error ("Invalid mangled function name %s", fname);
578 p += 2; /* advance past '__' */
580 /* struct name length and name of type should come next; advance past it */
583 len = len * 10 + (*p - '0');
592 msg_unknown_complaint (const char *arg1)
594 complaint (&symfile_complaints, "Unsupported token in stabs string %s", arg1);
597 /* Read base classes within cfront class definition.
598 eg: A:ZcA;1@Bpub v2@Bvirpri;__ct__1AFv func__1AFv *sfunc__1AFv ;as__1A ;;
601 A:ZcA;;foopri__1AFv foopro__1AFv __ct__1AFv __ct__1AFRC1A foopub__1AFv ;;;
606 read_cfront_baseclasses (struct field_info *fip, char **pp, struct type *type,
607 struct objfile *objfile)
612 struct nextfield *new;
614 if (**pp == ';') /* no base classes; return */
620 /* first count base classes so we can allocate space before parsing */
621 for (p = *pp; p && *p && *p != ';'; p++)
626 bnum++; /* add one more for last one */
628 /* now parse the base classes until we get to the start of the methods
629 (code extracted and munged from read_baseclasses) */
630 ALLOCATE_CPLUS_STRUCT_TYPE (type);
631 TYPE_N_BASECLASSES (type) = bnum;
635 int num_bytes = B_BYTES (TYPE_N_BASECLASSES (type));
638 pointer = (char *) TYPE_ALLOC (type, num_bytes);
639 TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *) pointer;
641 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), TYPE_N_BASECLASSES (type));
643 for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
645 new = (struct nextfield *) xmalloc (sizeof (struct nextfield));
646 make_cleanup (xfree, new);
647 memset (new, 0, sizeof (struct nextfield));
648 new->next = fip->list;
650 FIELD_BITSIZE (new->field) = 0; /* this should be an unpacked field! */
652 STABS_CONTINUE (pp, objfile);
654 /* virtual? eg: v2@Bvir */
657 SET_TYPE_FIELD_VIRTUAL (type, i);
661 /* access? eg: 2@Bvir */
662 /* Note: protected inheritance not supported in cfront */
665 case CFRONT_VISIBILITY_PRIVATE:
666 new->visibility = VISIBILITY_PRIVATE;
668 case CFRONT_VISIBILITY_PUBLIC:
669 new->visibility = VISIBILITY_PUBLIC;
672 /* Bad visibility format. Complain and treat it as
675 complaint (&symfile_complaints,
676 "Unknown visibility `%c' for baseclass",
678 new->visibility = VISIBILITY_PUBLIC;
682 /* "@" comes next - eg: @Bvir */
685 msg_unknown_complaint (*pp);
691 /* Set the bit offset of the portion of the object corresponding
692 to this baseclass. Always zero in the absence of
693 multiple inheritance. */
694 /* Unable to read bit position from stabs;
695 Assuming no multiple inheritance for now FIXME! */
696 /* We may have read this in the structure definition;
697 now we should fixup the members to be the actual base classes */
698 FIELD_BITPOS (new->field) = 0;
700 /* Get the base class name and type */
702 char *bname; /* base class name */
703 struct symbol *bsym; /* base class */
705 p1 = strchr (*pp, ' ');
706 p2 = strchr (*pp, ';');
708 bname = get_substring (pp, ' ');
710 bname = get_substring (pp, ';');
711 if (!bname || !*bname)
713 msg_unknown_complaint (*pp);
716 /* FIXME! attach base info to type */
717 bsym = lookup_symbol (bname, 0, STRUCT_NAMESPACE, 0, 0); /*demangled_name */
720 new->field.type = SYMBOL_TYPE (bsym);
721 new->field.name = type_name_no_tag (new->field.type);
725 complaint (&symfile_complaints, "Unable to find base type for %s",
731 /* If more base classes to parse, loop again.
732 We ate the last ' ' or ';' in get_substring,
733 so on exit we will have skipped the trailing ';' */
734 /* if invalid, return 0; add code to detect - FIXME! */
739 /* read cfront member functions.
740 pp points to string starting with list of functions
741 eg: A:ZcA;1@Bpub v2@Bvirpri;__ct__1AFv func__1AFv *sfunc__1AFv ;as__1A ;;
742 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
743 A:ZcA;;foopri__1AFv foopro__1AFv __ct__1AFv __ct__1AFRC1A foopub__1AFv ;;;
744 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
748 read_cfront_member_functions (struct field_info *fip, char **pp,
749 struct type *type, struct objfile *objfile)
751 /* This code extracted from read_member_functions
752 so as to do the similar thing for our funcs */
756 /* Total number of member functions defined in this class. If the class
757 defines two `f' functions, and one `g' function, then this will have
759 int total_length = 0;
763 struct next_fnfield *next;
764 struct fn_field fn_field;
767 struct type *look_ahead_type;
768 struct next_fnfieldlist *new_fnlist;
769 struct next_fnfield *new_sublist;
772 struct symbol *ref_func = 0;
774 /* Process each list until we find the end of the member functions.
775 eg: p = "__ct__1AFv foo__1AFv ;;;" */
777 STABS_CONTINUE (pp, objfile); /* handle \\ */
779 while (**pp != ';' && (fname = get_substring (pp, ' '), fname))
782 int sublist_count = 0;
784 if (fname[0] == '*') /* static member */
790 ref_func = lookup_symbol (fname, 0, VAR_NAMESPACE, 0, 0); /* demangled name */
793 complaint (&symfile_complaints,
794 "Unable to find function symbol for %s", fname);
798 look_ahead_type = NULL;
801 new_fnlist = (struct next_fnfieldlist *)
802 xmalloc (sizeof (struct next_fnfieldlist));
803 make_cleanup (xfree, new_fnlist);
804 memset (new_fnlist, 0, sizeof (struct next_fnfieldlist));
806 /* The following is code to work around cfront generated stabs.
807 The stabs contains full mangled name for each field.
808 We try to demangle the name and extract the field name out of it. */
810 char *dem, *dem_p, *dem_args;
812 dem = cplus_demangle (fname, DMGL_ANSI | DMGL_PARAMS);
815 dem_p = strrchr (dem, ':');
816 if (dem_p != 0 && *(dem_p - 1) == ':')
818 /* get rid of args */
819 dem_args = strchr (dem_p, '(');
820 if (dem_args == NULL)
821 dem_len = strlen (dem_p);
823 dem_len = dem_args - dem_p;
825 obsavestring (dem_p, dem_len, &objfile->type_obstack);
830 obsavestring (fname, strlen (fname), &objfile->type_obstack);
832 } /* end of code for cfront work around */
834 new_fnlist->fn_fieldlist.name = main_fn_name;
836 /*-------------------------------------------------*/
837 /* Set up the sublists
838 Sublists are stuff like args, static, visibility, etc.
839 so in ARM, we have to set that info some other way.
840 Multiple sublists happen if overloading
841 eg: foo::26=##1;:;2A.;
842 In g++, we'd loop here thru all the sublists... */
845 (struct next_fnfield *) xmalloc (sizeof (struct next_fnfield));
846 make_cleanup (xfree, new_sublist);
847 memset (new_sublist, 0, sizeof (struct next_fnfield));
849 /* eat 1; from :;2A.; */
850 new_sublist->fn_field.type = SYMBOL_TYPE (ref_func); /* normally takes a read_type */
851 /* Make this type look like a method stub for gdb */
852 TYPE_FLAGS (new_sublist->fn_field.type) |= TYPE_FLAG_STUB;
853 TYPE_CODE (new_sublist->fn_field.type) = TYPE_CODE_METHOD;
855 /* If this is just a stub, then we don't have the real name here. */
856 if (TYPE_STUB (new_sublist->fn_field.type))
858 if (!TYPE_DOMAIN_TYPE (new_sublist->fn_field.type))
859 TYPE_DOMAIN_TYPE (new_sublist->fn_field.type) = type;
860 new_sublist->fn_field.is_stub = 1;
863 /* physname used later in mangling; eg PFs_i,5 for foo__1aFPFs_i
864 physname gets strcat'd in order to recreate the onto mangled name */
865 pname = get_cfront_method_physname (fname);
866 new_sublist->fn_field.physname = savestring (pname, strlen (pname));
869 /* Set this member function's visibility fields.
870 Unable to distinguish access from stabs definition!
871 Assuming public for now. FIXME!
872 (for private, set new_sublist->fn_field.is_private = 1,
873 for public, set new_sublist->fn_field.is_protected = 1) */
875 /* Unable to distinguish const/volatile from stabs definition!
876 Assuming normal for now. FIXME! */
878 new_sublist->fn_field.is_const = 0;
879 new_sublist->fn_field.is_volatile = 0; /* volatile not implemented in cfront */
881 /* Set virtual/static function info
882 How to get vtable offsets ?
883 Assuming normal for now FIXME!!
884 For vtables, figure out from whence this virtual function came.
885 It may belong to virtual function table of
886 one of its baseclasses.
888 new_sublist -> fn_field.voffset = vtable offset,
889 new_sublist -> fn_field.fcontext = look_ahead_type;
890 where look_ahead_type is type of baseclass */
892 new_sublist->fn_field.voffset = VOFFSET_STATIC;
893 else /* normal member function. */
894 new_sublist->fn_field.voffset = 0;
895 new_sublist->fn_field.fcontext = 0;
898 /* Prepare new sublist */
899 new_sublist->next = sublist;
900 sublist = new_sublist;
903 /* In g++, we loop thu sublists - now we set from functions. */
904 new_fnlist->fn_fieldlist.fn_fields = (struct fn_field *)
905 obstack_alloc (&objfile->type_obstack,
906 sizeof (struct fn_field) * length);
907 memset (new_fnlist->fn_fieldlist.fn_fields, 0,
908 sizeof (struct fn_field) * length);
909 for (i = length; (i--, sublist); sublist = sublist->next)
911 new_fnlist->fn_fieldlist.fn_fields[i] = sublist->fn_field;
914 new_fnlist->fn_fieldlist.length = length;
915 new_fnlist->next = fip->fnlist;
916 fip->fnlist = new_fnlist;
918 total_length += length;
919 STABS_CONTINUE (pp, objfile); /* handle \\ */
924 /* type should already have space */
925 TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
926 TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * nfn_fields);
927 memset (TYPE_FN_FIELDLISTS (type), 0,
928 sizeof (struct fn_fieldlist) * nfn_fields);
929 TYPE_NFN_FIELDS (type) = nfn_fields;
930 TYPE_NFN_FIELDS_TOTAL (type) = total_length;
933 /* end of scope for reading member func */
937 /* Skip trailing ';' and bump count of number of fields seen */
945 /* This routine fixes up partial cfront types that were created
946 while parsing the stabs. The main need for this function is
947 to add information such as methods to classes.
948 Examples of "p": "sA;;__ct__1AFv foo__1AFv ;;;" */
950 resolve_cfront_continuation (struct objfile *objfile, struct symbol *sym,
953 struct symbol *ref_sym = 0;
955 /* snarfed from read_struct_type */
956 struct field_info fi;
958 struct cleanup *back_to;
960 /* Need to make sure that fi isn't gunna conflict with struct
961 in case struct already had some fnfs */
964 back_to = make_cleanup (null_cleanup, 0);
966 /* We only accept structs, classes and unions at the moment.
967 Other continuation types include t (typedef), r (long dbl), ...
968 We may want to add support for them as well;
969 right now they are handled by duplicating the symbol information
970 into the type information (see define_symbol) */
971 if (*p != 's' /* structs */
972 && *p != 'c' /* class */
973 && *p != 'u') /* union */
974 return 0; /* only handle C++ types */
977 /* Get symbol typs name and validate
978 eg: p = "A;;__ct__1AFv foo__1AFv ;;;" */
979 sname = get_substring (&p, ';');
980 if (!sname || strcmp (sname, SYMBOL_NAME (sym)))
981 error ("Internal error: base symbol type name does not match\n");
983 /* Find symbol's internal gdb reference using demangled_name.
984 This is the real sym that we want;
985 sym was a temp hack to make debugger happy */
986 ref_sym = lookup_symbol (SYMBOL_NAME (sym), 0, STRUCT_NAMESPACE, 0, 0);
987 type = SYMBOL_TYPE (ref_sym);
990 /* Now read the baseclasses, if any, read the regular C struct or C++
991 class member fields, attach the fields to the type, read the C++
992 member functions, attach them to the type, and then read any tilde
993 field (baseclass specifier for the class holding the main vtable). */
995 if (!read_cfront_baseclasses (&fi, &p, type, objfile)
996 /* g++ does this next, but cfront already did this:
997 || !read_struct_fields (&fi, &p, type, objfile) */
998 || !copy_cfront_struct_fields (&fi, type, objfile)
999 || !read_cfront_member_functions (&fi, &p, type, objfile)
1000 || !read_cfront_static_fields (&fi, &p, type, objfile)
1001 || !attach_fields_to_type (&fi, type, objfile)
1002 || !attach_fn_fields_to_type (&fi, type)
1003 /* g++ does this next, but cfront doesn't seem to have this:
1004 || !read_tilde_fields (&fi, &p, type, objfile) */
1007 type = error_type (&p, objfile);
1010 do_cleanups (back_to);
1013 /* End of code added to support parsing of ARM/Cfront stabs strings */
1016 /* This routine fixes up symbol references/aliases to point to the original
1017 symbol definition. Returns 0 on failure, non-zero on success. */
1020 resolve_symbol_reference (struct objfile *objfile, struct symbol *sym, char *p)
1023 struct symbol *ref_sym = 0;
1024 struct alias_list *alias;
1026 /* If this is not a symbol reference return now. */
1030 /* Use "#<num>" as the name; we'll fix the name later.
1031 We stored the original symbol name as "#<id>=<name>"
1032 so we can now search for "#<id>" to resolving the reference.
1033 We'll fix the names later by removing the "#<id>" or "#<id>=" */
1035 /*---------------------------------------------------------*/
1036 /* Get the reference id number, and
1037 advance p past the names so we can parse the rest.
1038 eg: id=2 for p : "2=", "2=z:r(0,1)" "2:r(0,1);l(#5,#6),l(#7,#4)" */
1039 /*---------------------------------------------------------*/
1041 /* This gets reference name from string. sym may not have a name. */
1043 /* Get the reference number associated with the reference id in the
1044 gdb stab string. From that reference number, get the main/primary
1045 symbol for this alias. */
1046 refnum = process_reference (&p);
1047 ref_sym = ref_search (refnum);
1050 lrs_general_complaint ("symbol for reference not found");
1054 /* Parse the stab of the referencing symbol
1055 now that we have the referenced symbol.
1056 Add it as a new symbol and a link back to the referenced symbol.
1057 eg: p : "=", "=z:r(0,1)" ":r(0,1);l(#5,#6),l(#7,#4)" */
1060 /* If the stab symbol table and string contain:
1061 RSYM 0 5 00000000 868 #15=z:r(0,1)
1062 LBRAC 0 0 00000000 899 #5=
1063 SLINE 0 16 00000003 923 #6=
1064 Then the same symbols can be later referenced by:
1065 RSYM 0 5 00000000 927 #15:r(0,1);l(#5,#6)
1066 This is used in live range splitting to:
1067 1) specify that a symbol (#15) is actually just a new storage
1068 class for a symbol (#15=z) which was previously defined.
1069 2) specify that the beginning and ending ranges for a symbol
1070 (#15) are the values of the beginning (#5) and ending (#6)
1073 /* Read number as reference id.
1074 eg: p : "=", "=z:r(0,1)" ":r(0,1);l(#5,#6),l(#7,#4)" */
1075 /* FIXME! Might I want to use SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
1076 in case of "l(0,0)"? */
1078 /*--------------------------------------------------*/
1079 /* Add this symbol to the reference list. */
1080 /*--------------------------------------------------*/
1082 alias = (struct alias_list *) obstack_alloc (&objfile->type_obstack,
1083 sizeof (struct alias_list));
1086 lrs_general_complaint ("Unable to allocate alias list memory");
1093 if (!SYMBOL_ALIASES (ref_sym))
1095 SYMBOL_ALIASES (ref_sym) = alias;
1099 struct alias_list *temp;
1101 /* Get to the end of the list. */
1102 for (temp = SYMBOL_ALIASES (ref_sym);
1109 /* Want to fix up name so that other functions (eg. valops)
1110 will correctly print the name.
1111 Don't add_symbol_to_list so that lookup_symbol won't find it.
1112 nope... needed for fixups. */
1113 SYMBOL_NAME (sym) = SYMBOL_NAME (ref_sym);
1119 /* Structure for storing pointers to reference definitions for fast lookup
1120 during "process_later". */
1129 #define MAX_CHUNK_REFS 100
1130 #define REF_CHUNK_SIZE (MAX_CHUNK_REFS * sizeof (struct ref_map))
1131 #define REF_MAP_SIZE(ref_chunk) ((ref_chunk) * REF_CHUNK_SIZE)
1133 static struct ref_map *ref_map;
1135 /* Ptr to free cell in chunk's linked list. */
1136 static int ref_count = 0;
1138 /* Number of chunks malloced. */
1139 static int ref_chunk = 0;
1141 /* This file maintains a cache of stabs aliases found in the symbol
1142 table. If the symbol table changes, this cache must be cleared
1143 or we are left holding onto data in invalid obstacks. */
1145 stabsread_clear_cache (void)
1151 /* Create array of pointers mapping refids to symbols and stab strings.
1152 Add pointers to reference definition symbols and/or their values as we
1153 find them, using their reference numbers as our index.
1154 These will be used later when we resolve references. */
1156 ref_add (int refnum, struct symbol *sym, char *stabs, CORE_ADDR value)
1160 if (refnum >= ref_count)
1161 ref_count = refnum + 1;
1162 if (ref_count > ref_chunk * MAX_CHUNK_REFS)
1164 int new_slots = ref_count - ref_chunk * MAX_CHUNK_REFS;
1165 int new_chunks = new_slots / MAX_CHUNK_REFS + 1;
1166 ref_map = (struct ref_map *)
1167 xrealloc (ref_map, REF_MAP_SIZE (ref_chunk + new_chunks));
1168 memset (ref_map + ref_chunk * MAX_CHUNK_REFS, 0, new_chunks * REF_CHUNK_SIZE);
1169 ref_chunk += new_chunks;
1171 ref_map[refnum].stabs = stabs;
1172 ref_map[refnum].sym = sym;
1173 ref_map[refnum].value = value;
1176 /* Return defined sym for the reference REFNUM. */
1178 ref_search (int refnum)
1180 if (refnum < 0 || refnum > ref_count)
1182 return ref_map[refnum].sym;
1185 /* Return value for the reference REFNUM. */
1188 ref_search_value (int refnum)
1190 if (refnum < 0 || refnum > ref_count)
1192 return ref_map[refnum].value;
1195 /* Parse a reference id in STRING and return the resulting
1196 reference number. Move STRING beyond the reference id. */
1199 process_reference (char **string)
1204 if (**string != '#')
1207 /* Advance beyond the initial '#'. */
1210 /* Read number as reference id. */
1211 while (*p && isdigit (*p))
1213 refnum = refnum * 10 + *p - '0';
1220 /* If STRING defines a reference, store away a pointer to the reference
1221 definition for later use. Return the reference number. */
1224 symbol_reference_defined (char **string)
1229 refnum = process_reference (&p);
1231 /* Defining symbols end in '=' */
1234 /* Symbol is being defined here. */
1240 /* Must be a reference. Either the symbol has already been defined,
1241 or this is a forward reference to it. */
1249 define_symbol (CORE_ADDR valu, char *string, int desc, int type,
1250 struct objfile *objfile)
1252 register struct symbol *sym;
1253 char *p = (char *) find_name_end (string);
1258 /* We would like to eliminate nameless symbols, but keep their types.
1259 E.g. stab entry ":t10=*2" should produce a type 10, which is a pointer
1260 to type 2, but, should not create a symbol to address that type. Since
1261 the symbol will be nameless, there is no way any user can refer to it. */
1265 /* Ignore syms with empty names. */
1269 /* Ignore old-style symbols from cc -go */
1276 p = strchr (p, ':');
1279 /* If a nameless stab entry, all we need is the type, not the symbol.
1280 e.g. ":t10=*2" or a nameless enum like " :T16=ered:0,green:1,blue:2,;" */
1281 nameless = (p == string || ((string[0] == ' ') && (string[1] == ':')));
1283 current_symbol = sym = (struct symbol *)
1284 obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol));
1285 memset (sym, 0, sizeof (struct symbol));
1287 switch (type & N_TYPE)
1290 SYMBOL_SECTION (sym) = SECT_OFF_TEXT (objfile);
1293 SYMBOL_SECTION (sym) = SECT_OFF_DATA (objfile);
1296 SYMBOL_SECTION (sym) = SECT_OFF_BSS (objfile);
1300 if (processing_gcc_compilation)
1302 /* GCC 2.x puts the line number in desc. SunOS apparently puts in the
1303 number of bytes occupied by a type or object, which we ignore. */
1304 SYMBOL_LINE (sym) = desc;
1308 SYMBOL_LINE (sym) = 0; /* unknown */
1311 if (is_cplus_marker (string[0]))
1313 /* Special GNU C++ names. */
1317 SYMBOL_NAME (sym) = obsavestring ("this", strlen ("this"),
1318 &objfile->symbol_obstack);
1321 case 'v': /* $vtbl_ptr_type */
1322 /* Was: SYMBOL_NAME (sym) = "vptr"; */
1326 SYMBOL_NAME (sym) = obsavestring ("eh_throw", strlen ("eh_throw"),
1327 &objfile->symbol_obstack);
1331 /* This was an anonymous type that was never fixed up. */
1334 #ifdef STATIC_TRANSFORM_NAME
1336 /* SunPRO (3.0 at least) static variable encoding. */
1341 complaint (&symfile_complaints, "Unknown C++ symbol name `%s'",
1343 goto normal; /* Do *something* with it */
1346 else if (string[0] == '#')
1348 /* Special GNU C extension for referencing symbols. */
1352 /* If STRING defines a new reference id, then add it to the
1353 reference map. Else it must be referring to a previously
1354 defined symbol, so add it to the alias list of the previously
1357 refnum = symbol_reference_defined (&s);
1359 ref_add (refnum, sym, string, SYMBOL_VALUE (sym));
1360 else if (!resolve_symbol_reference (objfile, sym, string))
1363 /* S..P contains the name of the symbol. We need to store
1364 the correct name into SYMBOL_NAME. */
1370 SYMBOL_NAME (sym) = (char *)
1371 obstack_alloc (&objfile->symbol_obstack, nlen);
1372 strncpy (SYMBOL_NAME (sym), s, nlen);
1373 SYMBOL_NAME (sym)[nlen] = '\0';
1374 SYMBOL_INIT_DEMANGLED_NAME (sym, &objfile->symbol_obstack);
1377 /* FIXME! Want SYMBOL_NAME (sym) = 0;
1378 Get error if leave name 0. So give it something. */
1381 SYMBOL_NAME (sym) = (char *)
1382 obstack_alloc (&objfile->symbol_obstack, nlen);
1383 strncpy (SYMBOL_NAME (sym), string, nlen);
1384 SYMBOL_NAME (sym)[nlen] = '\0';
1385 SYMBOL_INIT_DEMANGLED_NAME (sym, &objfile->symbol_obstack);
1388 /* Advance STRING beyond the reference id. */
1394 SYMBOL_LANGUAGE (sym) = current_subfile->language;
1395 SYMBOL_NAME (sym) = (char *)
1396 obstack_alloc (&objfile->symbol_obstack, ((p - string) + 1));
1397 /* Open-coded memcpy--saves function call time. */
1398 /* FIXME: Does it really? Try replacing with simple strcpy and
1399 try it on an executable with a large symbol table. */
1400 /* FIXME: considering that gcc can open code memcpy anyway, I
1401 doubt it. xoxorich. */
1403 register char *p1 = string;
1404 register char *p2 = SYMBOL_NAME (sym);
1412 /* If this symbol is from a C++ compilation, then attempt to cache the
1413 demangled form for future reference. This is a typical time versus
1414 space tradeoff, that was decided in favor of time because it sped up
1415 C++ symbol lookups by a factor of about 20. */
1417 SYMBOL_INIT_DEMANGLED_NAME (sym, &objfile->symbol_obstack);
1421 /* Determine the type of name being defined. */
1423 /* Getting GDB to correctly skip the symbol on an undefined symbol
1424 descriptor and not ever dump core is a very dodgy proposition if
1425 we do things this way. I say the acorn RISC machine can just
1426 fix their compiler. */
1427 /* The Acorn RISC machine's compiler can put out locals that don't
1428 start with "234=" or "(3,4)=", so assume anything other than the
1429 deftypes we know how to handle is a local. */
1430 if (!strchr ("cfFGpPrStTvVXCR", *p))
1432 if (isdigit (*p) || *p == '(' || *p == '-')
1441 /* c is a special case, not followed by a type-number.
1442 SYMBOL:c=iVALUE for an integer constant symbol.
1443 SYMBOL:c=rVALUE for a floating constant symbol.
1444 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
1445 e.g. "b:c=e6,0" for "const b = blob1"
1446 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
1449 SYMBOL_CLASS (sym) = LOC_CONST;
1450 SYMBOL_TYPE (sym) = error_type (&p, objfile);
1451 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1452 add_symbol_to_list (sym, &file_symbols);
1460 double d = atof (p);
1463 /* FIXME-if-picky-about-floating-accuracy: Should be using
1464 target arithmetic to get the value. real.c in GCC
1465 probably has the necessary code. */
1467 /* FIXME: lookup_fundamental_type is a hack. We should be
1468 creating a type especially for the type of float constants.
1469 Problem is, what type should it be?
1471 Also, what should the name of this type be? Should we
1472 be using 'S' constants (see stabs.texinfo) instead? */
1474 SYMBOL_TYPE (sym) = lookup_fundamental_type (objfile,
1477 obstack_alloc (&objfile->symbol_obstack,
1478 TYPE_LENGTH (SYMBOL_TYPE (sym)));
1479 store_typed_floating (dbl_valu, SYMBOL_TYPE (sym), d);
1480 SYMBOL_VALUE_BYTES (sym) = dbl_valu;
1481 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
1486 /* Defining integer constants this way is kind of silly,
1487 since 'e' constants allows the compiler to give not
1488 only the value, but the type as well. C has at least
1489 int, long, unsigned int, and long long as constant
1490 types; other languages probably should have at least
1491 unsigned as well as signed constants. */
1493 /* We just need one int constant type for all objfiles.
1494 It doesn't depend on languages or anything (arguably its
1495 name should be a language-specific name for a type of
1496 that size, but I'm inclined to say that if the compiler
1497 wants a nice name for the type, it can use 'e'). */
1498 static struct type *int_const_type;
1500 /* Yes, this is as long as a *host* int. That is because we
1502 if (int_const_type == NULL)
1504 init_type (TYPE_CODE_INT,
1505 sizeof (int) * HOST_CHAR_BIT / TARGET_CHAR_BIT, 0,
1507 (struct objfile *) NULL);
1508 SYMBOL_TYPE (sym) = int_const_type;
1509 SYMBOL_VALUE (sym) = atoi (p);
1510 SYMBOL_CLASS (sym) = LOC_CONST;
1514 /* SYMBOL:c=eTYPE,INTVALUE for a constant symbol whose value
1515 can be represented as integral.
1516 e.g. "b:c=e6,0" for "const b = blob1"
1517 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
1519 SYMBOL_CLASS (sym) = LOC_CONST;
1520 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1524 SYMBOL_TYPE (sym) = error_type (&p, objfile);
1529 /* If the value is too big to fit in an int (perhaps because
1530 it is unsigned), or something like that, we silently get
1531 a bogus value. The type and everything else about it is
1532 correct. Ideally, we should be using whatever we have
1533 available for parsing unsigned and long long values,
1535 SYMBOL_VALUE (sym) = atoi (p);
1540 SYMBOL_CLASS (sym) = LOC_CONST;
1541 SYMBOL_TYPE (sym) = error_type (&p, objfile);
1544 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1545 add_symbol_to_list (sym, &file_symbols);
1549 /* The name of a caught exception. */
1550 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1551 SYMBOL_CLASS (sym) = LOC_LABEL;
1552 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1553 SYMBOL_VALUE_ADDRESS (sym) = valu;
1554 add_symbol_to_list (sym, &local_symbols);
1558 /* A static function definition. */
1559 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1560 SYMBOL_CLASS (sym) = LOC_BLOCK;
1561 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1562 add_symbol_to_list (sym, &file_symbols);
1563 /* fall into process_function_types. */
1565 process_function_types:
1566 /* Function result types are described as the result type in stabs.
1567 We need to convert this to the function-returning-type-X type
1568 in GDB. E.g. "int" is converted to "function returning int". */
1569 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_FUNC)
1570 SYMBOL_TYPE (sym) = lookup_function_type (SYMBOL_TYPE (sym));
1572 /* All functions in C++ have prototypes. */
1573 if (SYMBOL_LANGUAGE (sym) == language_cplus)
1574 TYPE_FLAGS (SYMBOL_TYPE (sym)) |= TYPE_FLAG_PROTOTYPED;
1576 /* fall into process_prototype_types */
1578 process_prototype_types:
1579 /* Sun acc puts declared types of arguments here. */
1582 struct type *ftype = SYMBOL_TYPE (sym);
1587 /* Obtain a worst case guess for the number of arguments
1588 by counting the semicolons. */
1595 /* Allocate parameter information fields and fill them in. */
1596 TYPE_FIELDS (ftype) = (struct field *)
1597 TYPE_ALLOC (ftype, nsemi * sizeof (struct field));
1602 /* A type number of zero indicates the start of varargs.
1603 FIXME: GDB currently ignores vararg functions. */
1604 if (p[0] == '0' && p[1] == '\0')
1606 ptype = read_type (&p, objfile);
1608 /* The Sun compilers mark integer arguments, which should
1609 be promoted to the width of the calling conventions, with
1610 a type which references itself. This type is turned into
1611 a TYPE_CODE_VOID type by read_type, and we have to turn
1612 it back into builtin_type_int here.
1613 FIXME: Do we need a new builtin_type_promoted_int_arg ? */
1614 if (TYPE_CODE (ptype) == TYPE_CODE_VOID)
1615 ptype = builtin_type_int;
1616 TYPE_FIELD_TYPE (ftype, nparams) = ptype;
1617 TYPE_FIELD_ARTIFICIAL (ftype, nparams++) = 0;
1619 TYPE_NFIELDS (ftype) = nparams;
1620 TYPE_FLAGS (ftype) |= TYPE_FLAG_PROTOTYPED;
1625 /* A global function definition. */
1626 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1627 SYMBOL_CLASS (sym) = LOC_BLOCK;
1628 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1629 add_symbol_to_list (sym, &global_symbols);
1630 goto process_function_types;
1633 /* For a class G (global) symbol, it appears that the
1634 value is not correct. It is necessary to search for the
1635 corresponding linker definition to find the value.
1636 These definitions appear at the end of the namelist. */
1637 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1638 SYMBOL_CLASS (sym) = LOC_STATIC;
1639 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1640 /* Don't add symbol references to global_sym_chain.
1641 Symbol references don't have valid names and wont't match up with
1642 minimal symbols when the global_sym_chain is relocated.
1643 We'll fixup symbol references when we fixup the defining symbol. */
1644 if (SYMBOL_NAME (sym) && SYMBOL_NAME (sym)[0] != '#')
1646 i = hashname (SYMBOL_NAME (sym));
1647 SYMBOL_VALUE_CHAIN (sym) = global_sym_chain[i];
1648 global_sym_chain[i] = sym;
1650 add_symbol_to_list (sym, &global_symbols);
1653 /* This case is faked by a conditional above,
1654 when there is no code letter in the dbx data.
1655 Dbx data never actually contains 'l'. */
1658 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1659 SYMBOL_CLASS (sym) = LOC_LOCAL;
1660 SYMBOL_VALUE (sym) = valu;
1661 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1662 add_symbol_to_list (sym, &local_symbols);
1667 /* pF is a two-letter code that means a function parameter in Fortran.
1668 The type-number specifies the type of the return value.
1669 Translate it into a pointer-to-function type. */
1673 = lookup_pointer_type
1674 (lookup_function_type (read_type (&p, objfile)));
1677 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1679 /* Normally this is a parameter, a LOC_ARG. On the i960, it
1680 can also be a LOC_LOCAL_ARG depending on symbol type. */
1681 #ifndef DBX_PARM_SYMBOL_CLASS
1682 #define DBX_PARM_SYMBOL_CLASS(type) LOC_ARG
1685 SYMBOL_CLASS (sym) = DBX_PARM_SYMBOL_CLASS (type);
1686 SYMBOL_VALUE (sym) = valu;
1687 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1688 add_symbol_to_list (sym, &local_symbols);
1690 if (TARGET_BYTE_ORDER != BFD_ENDIAN_BIG)
1692 /* On little-endian machines, this crud is never necessary,
1693 and, if the extra bytes contain garbage, is harmful. */
1697 /* If it's gcc-compiled, if it says `short', believe it. */
1698 if (processing_gcc_compilation || BELIEVE_PCC_PROMOTION)
1701 if (!BELIEVE_PCC_PROMOTION)
1703 /* This is the signed type which arguments get promoted to. */
1704 static struct type *pcc_promotion_type;
1705 /* This is the unsigned type which arguments get promoted to. */
1706 static struct type *pcc_unsigned_promotion_type;
1708 /* Call it "int" because this is mainly C lossage. */
1709 if (pcc_promotion_type == NULL)
1710 pcc_promotion_type =
1711 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
1714 if (pcc_unsigned_promotion_type == NULL)
1715 pcc_unsigned_promotion_type =
1716 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
1717 TYPE_FLAG_UNSIGNED, "unsigned int", NULL);
1719 if (BELIEVE_PCC_PROMOTION_TYPE)
1721 /* This is defined on machines (e.g. sparc) where we
1722 should believe the type of a PCC 'short' argument,
1723 but shouldn't believe the address (the address is the
1724 address of the corresponding int).
1726 My guess is that this correction, as opposed to
1727 changing the parameter to an 'int' (as done below,
1728 for PCC on most machines), is the right thing to do
1729 on all machines, but I don't want to risk breaking
1730 something that already works. On most PCC machines,
1731 the sparc problem doesn't come up because the calling
1732 function has to zero the top bytes (not knowing
1733 whether the called function wants an int or a short),
1734 so there is little practical difference between an
1735 int and a short (except perhaps what happens when the
1736 GDB user types "print short_arg = 0x10000;").
1738 Hacked for SunOS 4.1 by gnu@cygnus.com. In 4.1, the
1739 compiler actually produces the correct address (we
1740 don't need to fix it up). I made this code adapt so
1741 that it will offset the symbol if it was pointing at
1742 an int-aligned location and not otherwise. This way
1743 you can use the same gdb for 4.0.x and 4.1 systems.
1745 If the parameter is shorter than an int, and is
1746 integral (e.g. char, short, or unsigned equivalent),
1747 and is claimed to be passed on an integer boundary,
1748 don't believe it! Offset the parameter's address to
1749 the tail-end of that integer. */
1751 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) < TYPE_LENGTH (pcc_promotion_type)
1752 && TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_INT
1753 && 0 == SYMBOL_VALUE (sym) % TYPE_LENGTH (pcc_promotion_type))
1755 SYMBOL_VALUE (sym) += TYPE_LENGTH (pcc_promotion_type)
1756 - TYPE_LENGTH (SYMBOL_TYPE (sym));
1762 /* If PCC says a parameter is a short or a char,
1763 it is really an int. */
1764 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) < TYPE_LENGTH (pcc_promotion_type)
1765 && TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_INT)
1768 TYPE_UNSIGNED (SYMBOL_TYPE (sym))
1769 ? pcc_unsigned_promotion_type
1770 : pcc_promotion_type;
1777 /* acc seems to use P to declare the prototypes of functions that
1778 are referenced by this file. gdb is not prepared to deal
1779 with this extra information. FIXME, it ought to. */
1782 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1783 goto process_prototype_types;
1788 /* Parameter which is in a register. */
1789 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1790 SYMBOL_CLASS (sym) = LOC_REGPARM;
1791 SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu);
1792 if (SYMBOL_VALUE (sym) >= NUM_REGS + NUM_PSEUDO_REGS)
1794 reg_value_complaint (SYMBOL_VALUE (sym),
1795 NUM_REGS + NUM_PSEUDO_REGS,
1796 SYMBOL_SOURCE_NAME (sym));
1797 SYMBOL_VALUE (sym) = SP_REGNUM; /* Known safe, though useless */
1799 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1800 add_symbol_to_list (sym, &local_symbols);
1804 /* Register variable (either global or local). */
1805 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1806 SYMBOL_CLASS (sym) = LOC_REGISTER;
1807 SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu);
1808 if (SYMBOL_VALUE (sym) >= NUM_REGS + NUM_PSEUDO_REGS)
1810 reg_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 if (within_function)
1818 /* Sun cc uses a pair of symbols, one 'p' and one 'r' with the same
1819 name to represent an argument passed in a register.
1820 GCC uses 'P' for the same case. So if we find such a symbol pair
1821 we combine it into one 'P' symbol. For Sun cc we need to do this
1822 regardless of REG_STRUCT_HAS_ADDR, because the compiler puts out
1823 the 'p' symbol even if it never saves the argument onto the stack.
1825 On most machines, we want to preserve both symbols, so that
1826 we can still get information about what is going on with the
1827 stack (VAX for computing args_printed, using stack slots instead
1828 of saved registers in backtraces, etc.).
1830 Note that this code illegally combines
1831 main(argc) struct foo argc; { register struct foo argc; }
1832 but this case is considered pathological and causes a warning
1833 from a decent compiler. */
1836 && local_symbols->nsyms > 0
1837 #ifndef USE_REGISTER_NOT_ARG
1838 && REG_STRUCT_HAS_ADDR_P ()
1839 && REG_STRUCT_HAS_ADDR (processing_gcc_compilation,
1841 && (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT
1842 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION
1843 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_SET
1844 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_BITSTRING)
1848 struct symbol *prev_sym;
1849 prev_sym = local_symbols->symbol[local_symbols->nsyms - 1];
1850 if ((SYMBOL_CLASS (prev_sym) == LOC_REF_ARG
1851 || SYMBOL_CLASS (prev_sym) == LOC_ARG)
1852 && STREQ (SYMBOL_NAME (prev_sym), SYMBOL_NAME (sym)))
1854 SYMBOL_CLASS (prev_sym) = LOC_REGPARM;
1855 /* Use the type from the LOC_REGISTER; that is the type
1856 that is actually in that register. */
1857 SYMBOL_TYPE (prev_sym) = SYMBOL_TYPE (sym);
1858 SYMBOL_VALUE (prev_sym) = SYMBOL_VALUE (sym);
1863 add_symbol_to_list (sym, &local_symbols);
1866 add_symbol_to_list (sym, &file_symbols);
1870 /* Static symbol at top level of file */
1871 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1872 SYMBOL_CLASS (sym) = LOC_STATIC;
1873 SYMBOL_VALUE_ADDRESS (sym) = valu;
1874 #ifdef STATIC_TRANSFORM_NAME
1875 if (IS_STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym)))
1877 struct minimal_symbol *msym;
1878 msym = lookup_minimal_symbol (SYMBOL_NAME (sym), NULL, objfile);
1881 SYMBOL_NAME (sym) = STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym));
1882 SYMBOL_VALUE_ADDRESS (sym) = SYMBOL_VALUE_ADDRESS (msym);
1886 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1887 add_symbol_to_list (sym, &file_symbols);
1892 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1894 /* For a nameless type, we don't want a create a symbol, thus we
1895 did not use `sym'. Return without further processing. */
1899 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
1900 SYMBOL_VALUE (sym) = valu;
1901 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1902 /* C++ vagaries: we may have a type which is derived from
1903 a base type which did not have its name defined when the
1904 derived class was output. We fill in the derived class's
1905 base part member's name here in that case. */
1906 if (TYPE_NAME (SYMBOL_TYPE (sym)) != NULL)
1907 if ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT
1908 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION)
1909 && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)))
1912 for (j = TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)) - 1; j >= 0; j--)
1913 if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) == 0)
1914 TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) =
1915 type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym), j));
1918 if (TYPE_NAME (SYMBOL_TYPE (sym)) == NULL)
1920 /* gcc-2.6 or later (when using -fvtable-thunks)
1921 emits a unique named type for a vtable entry.
1922 Some gdb code depends on that specific name. */
1923 extern const char vtbl_ptr_name[];
1925 if ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_PTR
1926 && strcmp (SYMBOL_NAME (sym), vtbl_ptr_name))
1927 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_FUNC)
1929 /* If we are giving a name to a type such as "pointer to
1930 foo" or "function returning foo", we better not set
1931 the TYPE_NAME. If the program contains "typedef char
1932 *caddr_t;", we don't want all variables of type char
1933 * to print as caddr_t. This is not just a
1934 consequence of GDB's type management; PCC and GCC (at
1935 least through version 2.4) both output variables of
1936 either type char * or caddr_t with the type number
1937 defined in the 't' symbol for caddr_t. If a future
1938 compiler cleans this up it GDB is not ready for it
1939 yet, but if it becomes ready we somehow need to
1940 disable this check (without breaking the PCC/GCC2.4
1945 Fortunately, this check seems not to be necessary
1946 for anything except pointers or functions. */
1947 /* ezannoni: 2000-10-26. This seems to apply for
1948 versions of gcc older than 2.8. This was the original
1949 problem: with the following code gdb would tell that
1950 the type for name1 is caddr_t, and func is char()
1951 typedef char *caddr_t;
1963 /* Pascal accepts names for pointer types. */
1964 if (current_subfile->language == language_pascal)
1966 TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_NAME (sym);
1970 TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_NAME (sym);
1973 add_symbol_to_list (sym, &file_symbols);
1977 /* Struct, union, or enum tag. For GNU C++, this can be be followed
1978 by 't' which means we are typedef'ing it as well. */
1979 synonym = *p == 't';
1983 /* The semantics of C++ state that "struct foo { ... }" also defines
1984 a typedef for "foo". Unfortunately, cfront never makes the typedef
1985 when translating C++ into C. We make the typedef here so that
1986 "ptype foo" works as expected for cfront translated code. */
1987 else if ((current_subfile->language == language_cplus)
1988 || (current_subfile->language == language_objc))
1991 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1993 /* For a nameless type, we don't want a create a symbol, thus we
1994 did not use `sym'. Return without further processing. */
1998 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
1999 SYMBOL_VALUE (sym) = valu;
2000 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
2001 if (TYPE_TAG_NAME (SYMBOL_TYPE (sym)) == 0)
2002 TYPE_TAG_NAME (SYMBOL_TYPE (sym))
2003 = obconcat (&objfile->type_obstack, "", "", SYMBOL_NAME (sym));
2004 add_symbol_to_list (sym, &file_symbols);
2008 /* Clone the sym and then modify it. */
2009 register struct symbol *typedef_sym = (struct symbol *)
2010 obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol));
2011 *typedef_sym = *sym;
2012 SYMBOL_CLASS (typedef_sym) = LOC_TYPEDEF;
2013 SYMBOL_VALUE (typedef_sym) = valu;
2014 SYMBOL_NAMESPACE (typedef_sym) = VAR_NAMESPACE;
2015 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
2016 TYPE_NAME (SYMBOL_TYPE (sym))
2017 = obconcat (&objfile->type_obstack, "", "", SYMBOL_NAME (sym));
2018 add_symbol_to_list (typedef_sym, &file_symbols);
2023 /* Static symbol of local scope */
2024 SYMBOL_TYPE (sym) = read_type (&p, objfile);
2025 SYMBOL_CLASS (sym) = LOC_STATIC;
2026 SYMBOL_VALUE_ADDRESS (sym) = valu;
2027 #ifdef STATIC_TRANSFORM_NAME
2028 if (IS_STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym)))
2030 struct minimal_symbol *msym;
2031 msym = lookup_minimal_symbol (SYMBOL_NAME (sym), NULL, objfile);
2034 SYMBOL_NAME (sym) = STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym));
2035 SYMBOL_VALUE_ADDRESS (sym) = SYMBOL_VALUE_ADDRESS (msym);
2039 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2040 #if 0 /* OBSOLETE OS9K */
2041 // OBSOLETE if (os9k_stabs)
2042 // OBSOLETE add_symbol_to_list (sym, &global_symbols);
2044 #endif /* OBSOLETE OS9K */
2045 add_symbol_to_list (sym, &local_symbols);
2049 /* Reference parameter */
2050 SYMBOL_TYPE (sym) = read_type (&p, objfile);
2051 SYMBOL_CLASS (sym) = LOC_REF_ARG;
2052 SYMBOL_VALUE (sym) = valu;
2053 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2054 add_symbol_to_list (sym, &local_symbols);
2058 /* Reference parameter which is in a register. */
2059 SYMBOL_TYPE (sym) = read_type (&p, objfile);
2060 SYMBOL_CLASS (sym) = LOC_REGPARM_ADDR;
2061 SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu);
2062 if (SYMBOL_VALUE (sym) >= NUM_REGS + NUM_PSEUDO_REGS)
2064 reg_value_complaint (SYMBOL_VALUE (sym),
2065 NUM_REGS + NUM_PSEUDO_REGS,
2066 SYMBOL_SOURCE_NAME (sym));
2067 SYMBOL_VALUE (sym) = SP_REGNUM; /* Known safe, though useless */
2069 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2070 add_symbol_to_list (sym, &local_symbols);
2074 /* This is used by Sun FORTRAN for "function result value".
2075 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
2076 that Pascal uses it too, but when I tried it Pascal used
2077 "x:3" (local symbol) instead. */
2078 SYMBOL_TYPE (sym) = read_type (&p, objfile);
2079 SYMBOL_CLASS (sym) = LOC_LOCAL;
2080 SYMBOL_VALUE (sym) = valu;
2081 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2082 add_symbol_to_list (sym, &local_symbols);
2085 /* New code added to support cfront stabs strings.
2086 Note: case 'P' already handled above */
2088 /* Cfront type continuation coming up!
2089 Find the original definition and add to it.
2090 We'll have to do this for the typedef too,
2091 since we cloned the symbol to define a type in read_type.
2092 Stabs info examples:
2094 foo__1CFv :ZtF (first def foo__1CFv:F(0,3);(0,24))
2095 C:ZsC;;__ct__1CFv func1__1CFv func2__1CFv ... ;;;
2096 where C is the name of the class.
2097 Unfortunately, we can't lookup the original symbol yet 'cuz
2098 we haven't finished reading all the symbols.
2099 Instead, we save it for processing later */
2100 process_later (sym, p, resolve_cfront_continuation);
2101 SYMBOL_TYPE (sym) = error_type (&p, objfile); /* FIXME! change later */
2102 SYMBOL_CLASS (sym) = LOC_CONST;
2103 SYMBOL_VALUE (sym) = 0;
2104 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2105 /* Don't add to list - we'll delete it later when
2106 we add the continuation to the real sym */
2108 /* End of new code added to support cfront stabs strings */
2111 SYMBOL_TYPE (sym) = error_type (&p, objfile);
2112 SYMBOL_CLASS (sym) = LOC_CONST;
2113 SYMBOL_VALUE (sym) = 0;
2114 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2115 add_symbol_to_list (sym, &file_symbols);
2119 /* When passing structures to a function, some systems sometimes pass
2120 the address in a register, not the structure itself. */
2122 if (REG_STRUCT_HAS_ADDR_P ()
2123 && REG_STRUCT_HAS_ADDR (processing_gcc_compilation, SYMBOL_TYPE (sym))
2124 && (SYMBOL_CLASS (sym) == LOC_REGPARM || SYMBOL_CLASS (sym) == LOC_ARG))
2126 struct type *symbol_type = check_typedef (SYMBOL_TYPE (sym));
2128 if ((TYPE_CODE (symbol_type) == TYPE_CODE_STRUCT)
2129 || (TYPE_CODE (symbol_type) == TYPE_CODE_UNION)
2130 || (TYPE_CODE (symbol_type) == TYPE_CODE_BITSTRING)
2131 || (TYPE_CODE (symbol_type) == TYPE_CODE_SET))
2133 /* If REG_STRUCT_HAS_ADDR yields non-zero we have to convert
2134 LOC_REGPARM to LOC_REGPARM_ADDR for structures and unions. */
2135 if (SYMBOL_CLASS (sym) == LOC_REGPARM)
2136 SYMBOL_CLASS (sym) = LOC_REGPARM_ADDR;
2137 /* Likewise for converting LOC_ARG to LOC_REF_ARG (for the 7th
2138 and subsequent arguments on the sparc, for example). */
2139 else if (SYMBOL_CLASS (sym) == LOC_ARG)
2140 SYMBOL_CLASS (sym) = LOC_REF_ARG;
2144 /* Is there more to parse? For example LRS/alias information? */
2145 while (*p && *p == ';')
2148 if (*p && p[0] == 'l' && p[1] == '(')
2150 /* GNU extensions for live range splitting may be appended to
2151 the end of the stab string. eg. "l(#1,#2);l(#3,#5)" */
2153 /* Resolve the live range and add it to SYM's live range list. */
2154 if (!resolve_live_range (objfile, sym, p))
2157 /* Find end of live range info. */
2158 p = strchr (p, ')');
2159 if (!*p || *p != ')')
2161 lrs_general_complaint ("live range format not recognized");
2170 /* Add the live range found in P to the symbol SYM in objfile OBJFILE. Returns
2171 non-zero on success, zero otherwise. */
2174 resolve_live_range (struct objfile *objfile, struct symbol *sym, char *p)
2177 CORE_ADDR start, end;
2179 /* Sanity check the beginning of the stabs string. */
2180 if (!*p || *p != 'l')
2182 lrs_general_complaint ("live range string 1");
2187 if (!*p || *p != '(')
2189 lrs_general_complaint ("live range string 2");
2194 /* Get starting value of range and advance P past the reference id.
2196 ?!? In theory, the process_reference should never fail, but we should
2197 catch that case just in case the compiler scrogged the stabs. */
2198 refnum = process_reference (&p);
2199 start = ref_search_value (refnum);
2202 lrs_general_complaint ("Live range symbol not found 1");
2206 if (!*p || *p != ',')
2208 lrs_general_complaint ("live range string 3");
2213 /* Get ending value of range and advance P past the reference id.
2215 ?!? In theory, the process_reference should never fail, but we should
2216 catch that case just in case the compiler scrogged the stabs. */
2217 refnum = process_reference (&p);
2218 end = ref_search_value (refnum);
2221 lrs_general_complaint ("Live range symbol not found 2");
2225 if (!*p || *p != ')')
2227 lrs_general_complaint ("live range string 4");
2231 /* Now that we know the bounds of the range, add it to the
2233 add_live_range (objfile, sym, start, end);
2238 /* Add a new live range defined by START and END to the symbol SYM
2239 in objfile OBJFILE. */
2242 add_live_range (struct objfile *objfile, struct symbol *sym, CORE_ADDR start,
2245 struct range_list *r, *rs;
2249 lrs_general_complaint ("end of live range follows start");
2253 /* Alloc new live range structure. */
2254 r = (struct range_list *)
2255 obstack_alloc (&objfile->type_obstack,
2256 sizeof (struct range_list));
2261 /* Append this range to the symbol's range list. */
2262 if (!SYMBOL_RANGES (sym))
2263 SYMBOL_RANGES (sym) = r;
2266 /* Get the last range for the symbol. */
2267 for (rs = SYMBOL_RANGES (sym); rs->next; rs = rs->next)
2274 /* Skip rest of this symbol and return an error type.
2276 General notes on error recovery: error_type always skips to the
2277 end of the symbol (modulo cretinous dbx symbol name continuation).
2278 Thus code like this:
2280 if (*(*pp)++ != ';')
2281 return error_type (pp, objfile);
2283 is wrong because if *pp starts out pointing at '\0' (typically as the
2284 result of an earlier error), it will be incremented to point to the
2285 start of the next symbol, which might produce strange results, at least
2286 if you run off the end of the string table. Instead use
2289 return error_type (pp, objfile);
2295 foo = error_type (pp, objfile);
2299 And in case it isn't obvious, the point of all this hair is so the compiler
2300 can define new types and new syntaxes, and old versions of the
2301 debugger will be able to read the new symbol tables. */
2303 static struct type *
2304 error_type (char **pp, struct objfile *objfile)
2306 complaint (&symfile_complaints, "couldn't parse type; debugger out of date?");
2309 /* Skip to end of symbol. */
2310 while (**pp != '\0')
2315 /* Check for and handle cretinous dbx symbol name continuation! */
2316 if ((*pp)[-1] == '\\' || (*pp)[-1] == '?')
2318 *pp = next_symbol_text (objfile);
2325 return (builtin_type_error);
2329 /* Read type information or a type definition; return the type. Even
2330 though this routine accepts either type information or a type
2331 definition, the distinction is relevant--some parts of stabsread.c
2332 assume that type information starts with a digit, '-', or '(' in
2333 deciding whether to call read_type. */
2336 read_type (register char **pp, struct objfile *objfile)
2338 register struct type *type = 0;
2341 char type_descriptor;
2343 /* Size in bits of type if specified by a type attribute, or -1 if
2344 there is no size attribute. */
2347 /* Used to distinguish string and bitstring from char-array and set. */
2350 /* Used to distinguish vector from array. */
2353 /* Read type number if present. The type number may be omitted.
2354 for instance in a two-dimensional array declared with type
2355 "ar1;1;10;ar1;1;10;4". */
2356 if ((**pp >= '0' && **pp <= '9')
2360 if (read_type_number (pp, typenums) != 0)
2361 return error_type (pp, objfile);
2363 /* Type is not being defined here. Either it already exists,
2364 or this is a forward reference to it. dbx_alloc_type handles
2367 return dbx_alloc_type (typenums, objfile);
2369 /* Type is being defined here. */
2371 Also skip the type descriptor - we get it below with (*pp)[-1]. */
2376 /* 'typenums=' not present, type is anonymous. Read and return
2377 the definition, but don't put it in the type vector. */
2378 typenums[0] = typenums[1] = -1;
2383 type_descriptor = (*pp)[-1];
2384 switch (type_descriptor)
2388 enum type_code code;
2390 /* Used to index through file_symbols. */
2391 struct pending *ppt;
2394 /* Name including "struct", etc. */
2398 char *from, *to, *p, *q1, *q2;
2400 /* Set the type code according to the following letter. */
2404 code = TYPE_CODE_STRUCT;
2407 code = TYPE_CODE_UNION;
2410 code = TYPE_CODE_ENUM;
2414 /* Complain and keep going, so compilers can invent new
2415 cross-reference types. */
2416 complaint (&symfile_complaints,
2417 "Unrecognized cross-reference type `%c'", (*pp)[0]);
2418 code = TYPE_CODE_STRUCT;
2423 q1 = strchr (*pp, '<');
2424 p = strchr (*pp, ':');
2426 return error_type (pp, objfile);
2427 if (q1 && p > q1 && p[1] == ':')
2429 int nesting_level = 0;
2430 for (q2 = q1; *q2; q2++)
2434 else if (*q2 == '>')
2436 else if (*q2 == ':' && nesting_level == 0)
2441 return error_type (pp, objfile);
2444 (char *) obstack_alloc (&objfile->type_obstack, p - *pp + 1);
2446 /* Copy the name. */
2452 /* Set the pointer ahead of the name which we just read, and
2457 /* Now check to see whether the type has already been
2458 declared. This was written for arrays of cross-referenced
2459 types before we had TYPE_CODE_TARGET_STUBBED, so I'm pretty
2460 sure it is not necessary anymore. But it might be a good
2461 idea, to save a little memory. */
2463 for (ppt = file_symbols; ppt; ppt = ppt->next)
2464 for (i = 0; i < ppt->nsyms; i++)
2466 struct symbol *sym = ppt->symbol[i];
2468 if (SYMBOL_CLASS (sym) == LOC_TYPEDEF
2469 && SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE
2470 && (TYPE_CODE (SYMBOL_TYPE (sym)) == code)
2471 && STREQ (SYMBOL_NAME (sym), type_name))
2473 obstack_free (&objfile->type_obstack, type_name);
2474 type = SYMBOL_TYPE (sym);
2479 /* Didn't find the type to which this refers, so we must
2480 be dealing with a forward reference. Allocate a type
2481 structure for it, and keep track of it so we can
2482 fill in the rest of the fields when we get the full
2484 type = dbx_alloc_type (typenums, objfile);
2485 TYPE_CODE (type) = code;
2486 TYPE_TAG_NAME (type) = type_name;
2487 INIT_CPLUS_SPECIFIC (type);
2488 TYPE_FLAGS (type) |= TYPE_FLAG_STUB;
2490 add_undefined_type (type);
2494 case '-': /* RS/6000 built-in type */
2508 /* We deal with something like t(1,2)=(3,4)=... which
2509 the Lucid compiler and recent gcc versions (post 2.7.3) use. */
2511 /* Allocate and enter the typedef type first.
2512 This handles recursive types. */
2513 type = dbx_alloc_type (typenums, objfile);
2514 TYPE_CODE (type) = TYPE_CODE_TYPEDEF;
2516 struct type *xtype = read_type (pp, objfile);
2519 /* It's being defined as itself. That means it is "void". */
2520 TYPE_CODE (type) = TYPE_CODE_VOID;
2521 TYPE_LENGTH (type) = 1;
2523 else if (type_size >= 0 || is_string)
2525 /* This is the absolute wrong way to construct types. Every
2526 other debug format has found a way around this problem and
2527 the related problems with unnecessarily stubbed types;
2528 someone motivated should attempt to clean up the issue
2529 here as well. Once a type pointed to has been created it
2530 should not be modified.
2532 Well, it's not *absolutely* wrong. Constructing recursive
2533 types (trees, linked lists) necessarily entails modifying
2534 types after creating them. Constructing any loop structure
2535 entails side effects. The Dwarf 2 reader does handle this
2536 more gracefully (it never constructs more than once
2537 instance of a type object, so it doesn't have to copy type
2538 objects wholesale), but it still mutates type objects after
2539 other folks have references to them.
2541 Keep in mind that this circularity/mutation issue shows up
2542 at the source language level, too: C's "incomplete types",
2543 for example. So the proper cleanup, I think, would be to
2544 limit GDB's type smashing to match exactly those required
2545 by the source language. So GDB could have a
2546 "complete_this_type" function, but never create unnecessary
2547 copies of a type otherwise. */
2548 replace_type (type, xtype);
2549 TYPE_NAME (type) = NULL;
2550 TYPE_TAG_NAME (type) = NULL;
2554 TYPE_FLAGS (type) |= TYPE_FLAG_TARGET_STUB;
2555 TYPE_TARGET_TYPE (type) = xtype;
2560 /* In the following types, we must be sure to overwrite any existing
2561 type that the typenums refer to, rather than allocating a new one
2562 and making the typenums point to the new one. This is because there
2563 may already be pointers to the existing type (if it had been
2564 forward-referenced), and we must change it to a pointer, function,
2565 reference, or whatever, *in-place*. */
2567 case '*': /* Pointer to another type */
2568 type1 = read_type (pp, objfile);
2569 type = make_pointer_type (type1, dbx_lookup_type (typenums));
2572 case '&': /* Reference to another type */
2573 type1 = read_type (pp, objfile);
2574 type = make_reference_type (type1, dbx_lookup_type (typenums));
2577 case 'f': /* Function returning another type */
2578 #if 0 /* OBSOLETE OS9K */
2579 // OBSOLETE if (os9k_stabs && **pp == '(')
2581 // OBSOLETE /* Function prototype; parse it.
2582 // OBSOLETE We must conditionalize this on os9k_stabs because otherwise
2583 // OBSOLETE it could be confused with a Sun-style (1,3) typenumber
2584 // OBSOLETE (I think). */
2585 // OBSOLETE struct type *t;
2587 // OBSOLETE while (**pp != ')')
2589 // OBSOLETE t = read_type (pp, objfile);
2590 // OBSOLETE if (**pp == ',')
2591 // OBSOLETE ++ * pp;
2594 #endif /* OBSOLETE OS9K */
2596 type1 = read_type (pp, objfile);
2597 type = make_function_type (type1, dbx_lookup_type (typenums));
2600 case 'g': /* Prototyped function. (Sun) */
2602 /* Unresolved questions:
2604 - According to Sun's ``STABS Interface Manual'', for 'f'
2605 and 'F' symbol descriptors, a `0' in the argument type list
2606 indicates a varargs function. But it doesn't say how 'g'
2607 type descriptors represent that info. Someone with access
2608 to Sun's toolchain should try it out.
2610 - According to the comment in define_symbol (search for
2611 `process_prototype_types:'), Sun emits integer arguments as
2612 types which ref themselves --- like `void' types. Do we
2613 have to deal with that here, too? Again, someone with
2614 access to Sun's toolchain should try it out and let us
2617 const char *type_start = (*pp) - 1;
2618 struct type *return_type = read_type (pp, objfile);
2619 struct type *func_type
2620 = make_function_type (return_type, dbx_lookup_type (typenums));
2623 struct type_list *next;
2627 while (**pp && **pp != '#')
2629 struct type *arg_type = read_type (pp, objfile);
2630 struct type_list *new = alloca (sizeof (*new));
2631 new->type = arg_type;
2632 new->next = arg_types;
2640 complaint (&symfile_complaints,
2641 "Prototyped function type didn't end arguments with `#':\n%s",
2645 /* If there is just one argument whose type is `void', then
2646 that's just an empty argument list. */
2648 && ! arg_types->next
2649 && TYPE_CODE (arg_types->type) == TYPE_CODE_VOID)
2652 TYPE_FIELDS (func_type)
2653 = (struct field *) TYPE_ALLOC (func_type,
2654 num_args * sizeof (struct field));
2655 memset (TYPE_FIELDS (func_type), 0, num_args * sizeof (struct field));
2658 struct type_list *t;
2660 /* We stuck each argument type onto the front of the list
2661 when we read it, so the list is reversed. Build the
2662 fields array right-to-left. */
2663 for (t = arg_types, i = num_args - 1; t; t = t->next, i--)
2664 TYPE_FIELD_TYPE (func_type, i) = t->type;
2666 TYPE_NFIELDS (func_type) = num_args;
2667 TYPE_FLAGS (func_type) |= TYPE_FLAG_PROTOTYPED;
2673 case 'k': /* Const qualifier on some type (Sun) */
2674 #if 0 /* OBSOLETE OS9K */
2675 // OBSOLETE /* ezannoni 2002-07-16: This can be safely deleted, because 'c'
2676 // OBSOLETE means complex type in AIX stabs, while it means const qualifier
2677 // OBSOLETE in os9k stabs. Obviously we were supporting only the os9k meaning.
2678 // OBSOLETE We were erroring out if we were reading AIX stabs. Right now the
2679 // OBSOLETE erroring out will happen in the default clause of the switch. */
2680 // OBSOLETE case 'c': /* Const qualifier on some type (OS9000) */
2681 // OBSOLETE /* Because 'c' means other things to AIX and 'k' is perfectly good,
2682 // OBSOLETE only accept 'c' in the os9k_stabs case. */
2683 // OBSOLETE if (type_descriptor == 'c' && !os9k_stabs)
2684 // OBSOLETE return error_type (pp, objfile);
2685 #endif /* OBSOLETE OS9K */
2686 type = read_type (pp, objfile);
2687 type = make_cv_type (1, TYPE_VOLATILE (type), type,
2688 dbx_lookup_type (typenums));
2691 case 'B': /* Volatile qual on some type (Sun) */
2692 #if 0 /* OBSOLETE OS9K */
2693 // OBSOLETE /* ezannoni 2002-07-16: This can be safely deleted, because 'i'
2694 // OBSOLETE means imported type in AIX stabs, while it means volatile qualifier
2695 // OBSOLETE in os9k stabs. Obviously we were supporting only the os9k meaning.
2696 // OBSOLETE We were erroring out if we were reading AIX stabs. Right now the
2697 // OBSOLETE erroring out will happen in the default clause of the switch. */
2698 // OBSOLETE case 'i': /* Volatile qual on some type (OS9000) */
2699 // OBSOLETE /* Because 'i' means other things to AIX and 'B' is perfectly good,
2700 // OBSOLETE only accept 'i' in the os9k_stabs case. */
2701 // OBSOLETE if (type_descriptor == 'i' && !os9k_stabs)
2702 // OBSOLETE return error_type (pp, objfile);
2703 #endif /* OBSOLETE OS9K */
2704 type = read_type (pp, objfile);
2705 type = make_cv_type (TYPE_CONST (type), 1, type,
2706 dbx_lookup_type (typenums));
2710 if (isdigit (**pp) || **pp == '(' || **pp == '-')
2711 { /* Member (class & variable) type */
2712 /* FIXME -- we should be doing smash_to_XXX types here. */
2714 struct type *domain = read_type (pp, objfile);
2715 struct type *memtype;
2718 /* Invalid member type data format. */
2719 return error_type (pp, objfile);
2722 memtype = read_type (pp, objfile);
2723 type = dbx_alloc_type (typenums, objfile);
2724 smash_to_member_type (type, domain, memtype);
2727 /* type attribute */
2730 /* Skip to the semicolon. */
2731 while (**pp != ';' && **pp != '\0')
2734 return error_type (pp, objfile);
2736 ++ * pp; /* Skip the semicolon. */
2740 case 's': /* Size attribute */
2741 type_size = atoi (attr + 1);
2746 case 'S': /* String attribute */
2747 /* FIXME: check to see if following type is array? */
2751 case 'V': /* Vector attribute */
2752 /* FIXME: check to see if following type is array? */
2757 /* Ignore unrecognized type attributes, so future compilers
2758 can invent new ones. */
2766 case '#': /* Method (class & fn) type */
2767 if ((*pp)[0] == '#')
2769 /* We'll get the parameter types from the name. */
2770 struct type *return_type;
2773 return_type = read_type (pp, objfile);
2774 if (*(*pp)++ != ';')
2775 complaint (&symfile_complaints,
2776 "invalid (minimal) member type data format at symtab pos %d.",
2778 type = allocate_stub_method (return_type);
2779 if (typenums[0] != -1)
2780 *dbx_lookup_type (typenums) = type;
2784 struct type *domain = read_type (pp, objfile);
2785 struct type *return_type;
2790 /* Invalid member type data format. */
2791 return error_type (pp, objfile);
2795 return_type = read_type (pp, objfile);
2796 args = read_args (pp, ';', objfile, &nargs, &varargs);
2797 type = dbx_alloc_type (typenums, objfile);
2798 smash_to_method_type (type, domain, return_type, args,
2803 case 'r': /* Range type */
2804 type = read_range_type (pp, typenums, objfile);
2805 if (typenums[0] != -1)
2806 *dbx_lookup_type (typenums) = type;
2810 #if 0 /* OBSOLETE OS9K */
2811 // OBSOLETE if (os9k_stabs)
2812 // OBSOLETE /* Const and volatile qualified type. */
2813 // OBSOLETE type = read_type (pp, objfile);
2815 #endif /* OBSOLETE OS9K */
2817 /* Sun ACC builtin int type */
2818 type = read_sun_builtin_type (pp, typenums, objfile);
2819 if (typenums[0] != -1)
2820 *dbx_lookup_type (typenums) = type;
2824 case 'R': /* Sun ACC builtin float type */
2825 type = read_sun_floating_type (pp, typenums, objfile);
2826 if (typenums[0] != -1)
2827 *dbx_lookup_type (typenums) = type;
2830 case 'e': /* Enumeration type */
2831 type = dbx_alloc_type (typenums, objfile);
2832 type = read_enum_type (pp, type, objfile);
2833 if (typenums[0] != -1)
2834 *dbx_lookup_type (typenums) = type;
2837 case 's': /* Struct type */
2838 case 'u': /* Union type */
2840 enum type_code type_code = TYPE_CODE_UNDEF;
2841 type = dbx_alloc_type (typenums, objfile);
2842 switch (type_descriptor)
2845 type_code = TYPE_CODE_STRUCT;
2848 type_code = TYPE_CODE_UNION;
2851 type = read_struct_type (pp, type, type_code, objfile);
2855 case 'a': /* Array type */
2857 return error_type (pp, objfile);
2860 type = dbx_alloc_type (typenums, objfile);
2861 type = read_array_type (pp, type, objfile);
2863 TYPE_CODE (type) = TYPE_CODE_STRING;
2865 TYPE_FLAGS (type) |= TYPE_FLAG_VECTOR;
2868 case 'S': /* Set or bitstring type */
2869 type1 = read_type (pp, objfile);
2870 type = create_set_type ((struct type *) NULL, type1);
2872 TYPE_CODE (type) = TYPE_CODE_BITSTRING;
2873 if (typenums[0] != -1)
2874 *dbx_lookup_type (typenums) = type;
2878 --*pp; /* Go back to the symbol in error */
2879 /* Particularly important if it was \0! */
2880 return error_type (pp, objfile);
2885 warning ("GDB internal error, type is NULL in stabsread.c\n");
2886 return error_type (pp, objfile);
2889 /* Size specified in a type attribute overrides any other size. */
2890 if (type_size != -1)
2891 TYPE_LENGTH (type) = (type_size + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT;
2896 /* RS/6000 xlc/dbx combination uses a set of builtin types, starting from -1.
2897 Return the proper type node for a given builtin type number. */
2899 static struct type *
2900 rs6000_builtin_type (int typenum)
2902 /* We recognize types numbered from -NUMBER_RECOGNIZED to -1. */
2903 #define NUMBER_RECOGNIZED 34
2904 /* This includes an empty slot for type number -0. */
2905 static struct type *negative_types[NUMBER_RECOGNIZED + 1];
2906 struct type *rettype = NULL;
2908 if (typenum >= 0 || typenum < -NUMBER_RECOGNIZED)
2910 complaint (&symfile_complaints, "Unknown builtin type %d", typenum);
2911 return builtin_type_error;
2913 if (negative_types[-typenum] != NULL)
2914 return negative_types[-typenum];
2916 #if TARGET_CHAR_BIT != 8
2917 #error This code wrong for TARGET_CHAR_BIT not 8
2918 /* These definitions all assume that TARGET_CHAR_BIT is 8. I think
2919 that if that ever becomes not true, the correct fix will be to
2920 make the size in the struct type to be in bits, not in units of
2927 /* The size of this and all the other types are fixed, defined
2928 by the debugging format. If there is a type called "int" which
2929 is other than 32 bits, then it should use a new negative type
2930 number (or avoid negative type numbers for that case).
2931 See stabs.texinfo. */
2932 rettype = init_type (TYPE_CODE_INT, 4, 0, "int", NULL);
2935 rettype = init_type (TYPE_CODE_INT, 1, 0, "char", NULL);
2938 rettype = init_type (TYPE_CODE_INT, 2, 0, "short", NULL);
2941 rettype = init_type (TYPE_CODE_INT, 4, 0, "long", NULL);
2944 rettype = init_type (TYPE_CODE_INT, 1, TYPE_FLAG_UNSIGNED,
2945 "unsigned char", NULL);
2948 rettype = init_type (TYPE_CODE_INT, 1, 0, "signed char", NULL);
2951 rettype = init_type (TYPE_CODE_INT, 2, TYPE_FLAG_UNSIGNED,
2952 "unsigned short", NULL);
2955 rettype = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED,
2956 "unsigned int", NULL);
2959 rettype = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED,
2962 rettype = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED,
2963 "unsigned long", NULL);
2966 rettype = init_type (TYPE_CODE_VOID, 1, 0, "void", NULL);
2969 /* IEEE single precision (32 bit). */
2970 rettype = init_type (TYPE_CODE_FLT, 4, 0, "float", NULL);
2973 /* IEEE double precision (64 bit). */
2974 rettype = init_type (TYPE_CODE_FLT, 8, 0, "double", NULL);
2977 /* This is an IEEE double on the RS/6000, and different machines with
2978 different sizes for "long double" should use different negative
2979 type numbers. See stabs.texinfo. */
2980 rettype = init_type (TYPE_CODE_FLT, 8, 0, "long double", NULL);
2983 rettype = init_type (TYPE_CODE_INT, 4, 0, "integer", NULL);
2986 rettype = init_type (TYPE_CODE_BOOL, 4, TYPE_FLAG_UNSIGNED,
2990 rettype = init_type (TYPE_CODE_FLT, 4, 0, "short real", NULL);
2993 rettype = init_type (TYPE_CODE_FLT, 8, 0, "real", NULL);
2996 rettype = init_type (TYPE_CODE_ERROR, 0, 0, "stringptr", NULL);
2999 rettype = init_type (TYPE_CODE_CHAR, 1, TYPE_FLAG_UNSIGNED,
3003 rettype = init_type (TYPE_CODE_BOOL, 1, TYPE_FLAG_UNSIGNED,
3007 rettype = init_type (TYPE_CODE_BOOL, 2, TYPE_FLAG_UNSIGNED,
3011 rettype = init_type (TYPE_CODE_BOOL, 4, TYPE_FLAG_UNSIGNED,
3015 rettype = init_type (TYPE_CODE_BOOL, 4, TYPE_FLAG_UNSIGNED,
3019 /* Complex type consisting of two IEEE single precision values. */
3020 rettype = init_type (TYPE_CODE_COMPLEX, 8, 0, "complex", NULL);
3021 TYPE_TARGET_TYPE (rettype) = init_type (TYPE_CODE_FLT, 4, 0, "float",
3025 /* Complex type consisting of two IEEE double precision values. */
3026 rettype = init_type (TYPE_CODE_COMPLEX, 16, 0, "double complex", NULL);
3027 TYPE_TARGET_TYPE (rettype) = init_type (TYPE_CODE_FLT, 8, 0, "double",
3031 rettype = init_type (TYPE_CODE_INT, 1, 0, "integer*1", NULL);
3034 rettype = init_type (TYPE_CODE_INT, 2, 0, "integer*2", NULL);
3037 rettype = init_type (TYPE_CODE_INT, 4, 0, "integer*4", NULL);
3040 rettype = init_type (TYPE_CODE_CHAR, 2, 0, "wchar", NULL);
3043 rettype = init_type (TYPE_CODE_INT, 8, 0, "long long", NULL);
3046 rettype = init_type (TYPE_CODE_INT, 8, TYPE_FLAG_UNSIGNED,
3047 "unsigned long long", NULL);
3050 rettype = init_type (TYPE_CODE_INT, 8, TYPE_FLAG_UNSIGNED,
3054 rettype = init_type (TYPE_CODE_INT, 8, 0, "integer*8", NULL);
3057 negative_types[-typenum] = rettype;
3061 /* This page contains subroutines of read_type. */
3063 /* Replace *OLD_NAME with the method name portion of PHYSNAME. */
3066 update_method_name_from_physname (char **old_name, char *physname)
3070 method_name = method_name_from_physname (physname);
3072 if (method_name == NULL)
3073 error ("bad physname %s\n", physname);
3075 if (strcmp (*old_name, method_name) != 0)
3078 *old_name = method_name;
3081 xfree (method_name);
3084 /* Read member function stabs info for C++ classes. The form of each member
3087 NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;
3089 An example with two member functions is:
3091 afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;
3093 For the case of overloaded operators, the format is op$::*.funcs, where
3094 $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
3095 name (such as `+=') and `.' marks the end of the operator name.
3097 Returns 1 for success, 0 for failure. */
3100 read_member_functions (struct field_info *fip, char **pp, struct type *type,
3101 struct objfile *objfile)
3105 /* Total number of member functions defined in this class. If the class
3106 defines two `f' functions, and one `g' function, then this will have
3108 int total_length = 0;
3112 struct next_fnfield *next;
3113 struct fn_field fn_field;
3116 struct type *look_ahead_type;
3117 struct next_fnfieldlist *new_fnlist;
3118 struct next_fnfield *new_sublist;
3122 /* Process each list until we find something that is not a member function
3123 or find the end of the functions. */
3127 /* We should be positioned at the start of the function name.
3128 Scan forward to find the first ':' and if it is not the
3129 first of a "::" delimiter, then this is not a member function. */
3141 look_ahead_type = NULL;
3144 new_fnlist = (struct next_fnfieldlist *)
3145 xmalloc (sizeof (struct next_fnfieldlist));
3146 make_cleanup (xfree, new_fnlist);
3147 memset (new_fnlist, 0, sizeof (struct next_fnfieldlist));
3149 if ((*pp)[0] == 'o' && (*pp)[1] == 'p' && is_cplus_marker ((*pp)[2]))
3151 /* This is a completely wierd case. In order to stuff in the
3152 names that might contain colons (the usual name delimiter),
3153 Mike Tiemann defined a different name format which is
3154 signalled if the identifier is "op$". In that case, the
3155 format is "op$::XXXX." where XXXX is the name. This is
3156 used for names like "+" or "=". YUUUUUUUK! FIXME! */
3157 /* This lets the user type "break operator+".
3158 We could just put in "+" as the name, but that wouldn't
3160 static char opname[32] = "op$";
3161 char *o = opname + 3;
3163 /* Skip past '::'. */
3166 STABS_CONTINUE (pp, objfile);
3172 main_fn_name = savestring (opname, o - opname);
3178 main_fn_name = savestring (*pp, p - *pp);
3179 /* Skip past '::'. */
3182 new_fnlist->fn_fieldlist.name = main_fn_name;
3187 (struct next_fnfield *) xmalloc (sizeof (struct next_fnfield));
3188 make_cleanup (xfree, new_sublist);
3189 memset (new_sublist, 0, sizeof (struct next_fnfield));
3191 /* Check for and handle cretinous dbx symbol name continuation! */
3192 if (look_ahead_type == NULL)
3195 STABS_CONTINUE (pp, objfile);
3197 new_sublist->fn_field.type = read_type (pp, objfile);
3200 /* Invalid symtab info for member function. */
3206 /* g++ version 1 kludge */
3207 new_sublist->fn_field.type = look_ahead_type;
3208 look_ahead_type = NULL;
3218 /* If this is just a stub, then we don't have the real name here. */
3220 if (TYPE_STUB (new_sublist->fn_field.type))
3222 if (!TYPE_DOMAIN_TYPE (new_sublist->fn_field.type))
3223 TYPE_DOMAIN_TYPE (new_sublist->fn_field.type) = type;
3224 new_sublist->fn_field.is_stub = 1;
3226 new_sublist->fn_field.physname = savestring (*pp, p - *pp);
3229 /* Set this member function's visibility fields. */
3232 case VISIBILITY_PRIVATE:
3233 new_sublist->fn_field.is_private = 1;
3235 case VISIBILITY_PROTECTED:
3236 new_sublist->fn_field.is_protected = 1;
3240 STABS_CONTINUE (pp, objfile);
3243 case 'A': /* Normal functions. */
3244 new_sublist->fn_field.is_const = 0;
3245 new_sublist->fn_field.is_volatile = 0;
3248 case 'B': /* `const' member functions. */
3249 new_sublist->fn_field.is_const = 1;
3250 new_sublist->fn_field.is_volatile = 0;
3253 case 'C': /* `volatile' member function. */
3254 new_sublist->fn_field.is_const = 0;
3255 new_sublist->fn_field.is_volatile = 1;
3258 case 'D': /* `const volatile' member function. */
3259 new_sublist->fn_field.is_const = 1;
3260 new_sublist->fn_field.is_volatile = 1;
3263 case '*': /* File compiled with g++ version 1 -- no info */
3268 complaint (&symfile_complaints,
3269 "const/volatile indicator missing, got '%c'", **pp);
3278 /* virtual member function, followed by index.
3279 The sign bit is set to distinguish pointers-to-methods
3280 from virtual function indicies. Since the array is
3281 in words, the quantity must be shifted left by 1
3282 on 16 bit machine, and by 2 on 32 bit machine, forcing
3283 the sign bit out, and usable as a valid index into
3284 the array. Remove the sign bit here. */
3285 new_sublist->fn_field.voffset =
3286 (0x7fffffff & read_huge_number (pp, ';', &nbits)) + 2;
3290 STABS_CONTINUE (pp, objfile);
3291 if (**pp == ';' || **pp == '\0')
3293 /* Must be g++ version 1. */
3294 new_sublist->fn_field.fcontext = 0;
3298 /* Figure out from whence this virtual function came.
3299 It may belong to virtual function table of
3300 one of its baseclasses. */
3301 look_ahead_type = read_type (pp, objfile);
3304 /* g++ version 1 overloaded methods. */
3308 new_sublist->fn_field.fcontext = look_ahead_type;
3317 look_ahead_type = NULL;
3323 /* static member function. */
3325 int slen = strlen (main_fn_name);
3327 new_sublist->fn_field.voffset = VOFFSET_STATIC;
3329 /* For static member functions, we can't tell if they
3330 are stubbed, as they are put out as functions, and not as
3332 GCC v2 emits the fully mangled name if
3333 dbxout.c:flag_minimal_debug is not set, so we have to
3334 detect a fully mangled physname here and set is_stub
3335 accordingly. Fully mangled physnames in v2 start with
3336 the member function name, followed by two underscores.
3337 GCC v3 currently always emits stubbed member functions,
3338 but with fully mangled physnames, which start with _Z. */
3339 if (!(strncmp (new_sublist->fn_field.physname,
3340 main_fn_name, slen) == 0
3341 && new_sublist->fn_field.physname[slen] == '_'
3342 && new_sublist->fn_field.physname[slen + 1] == '_'))
3344 new_sublist->fn_field.is_stub = 1;
3351 complaint (&symfile_complaints,
3352 "member function type missing, got '%c'", (*pp)[-1]);
3353 /* Fall through into normal member function. */
3356 /* normal member function. */
3357 new_sublist->fn_field.voffset = 0;
3358 new_sublist->fn_field.fcontext = 0;
3362 new_sublist->next = sublist;
3363 sublist = new_sublist;
3365 STABS_CONTINUE (pp, objfile);
3367 while (**pp != ';' && **pp != '\0');
3370 STABS_CONTINUE (pp, objfile);
3372 /* Skip GCC 3.X member functions which are duplicates of the callable
3373 constructor/destructor. */
3374 if (strcmp (main_fn_name, "__base_ctor") == 0
3375 || strcmp (main_fn_name, "__base_dtor") == 0
3376 || strcmp (main_fn_name, "__deleting_dtor") == 0)
3378 xfree (main_fn_name);
3383 int has_destructor = 0, has_other = 0;
3385 struct next_fnfield *tmp_sublist;
3387 /* Various versions of GCC emit various mostly-useless
3388 strings in the name field for special member functions.
3390 For stub methods, we need to defer correcting the name
3391 until we are ready to unstub the method, because the current
3392 name string is used by gdb_mangle_name. The only stub methods
3393 of concern here are GNU v2 operators; other methods have their
3394 names correct (see caveat below).
3396 For non-stub methods, in GNU v3, we have a complete physname.
3397 Therefore we can safely correct the name now. This primarily
3398 affects constructors and destructors, whose name will be
3399 __comp_ctor or __comp_dtor instead of Foo or ~Foo. Cast
3400 operators will also have incorrect names; for instance,
3401 "operator int" will be named "operator i" (i.e. the type is
3404 For non-stub methods in GNU v2, we have no easy way to
3405 know if we have a complete physname or not. For most
3406 methods the result depends on the platform (if CPLUS_MARKER
3407 can be `$' or `.', it will use minimal debug information, or
3408 otherwise the full physname will be included).
3410 Rather than dealing with this, we take a different approach.
3411 For v3 mangled names, we can use the full physname; for v2,
3412 we use cplus_demangle_opname (which is actually v2 specific),
3413 because the only interesting names are all operators - once again
3414 barring the caveat below. Skip this process if any method in the
3415 group is a stub, to prevent our fouling up the workings of
3418 The caveat: GCC 2.95.x (and earlier?) put constructors and
3419 destructors in the same method group. We need to split this
3420 into two groups, because they should have different names.
3421 So for each method group we check whether it contains both
3422 routines whose physname appears to be a destructor (the physnames
3423 for and destructors are always provided, due to quirks in v2
3424 mangling) and routines whose physname does not appear to be a
3425 destructor. If so then we break up the list into two halves.
3426 Even if the constructors and destructors aren't in the same group
3427 the destructor will still lack the leading tilde, so that also
3430 So, to summarize what we expect and handle here:
3432 Given Given Real Real Action
3433 method name physname physname method name
3435 __opi [none] __opi__3Foo operator int opname
3437 Foo _._3Foo _._3Foo ~Foo separate and
3439 operator i _ZN3FoocviEv _ZN3FoocviEv operator int demangle
3440 __comp_ctor _ZN3FooC1ERKS_ _ZN3FooC1ERKS_ Foo demangle
3443 tmp_sublist = sublist;
3444 while (tmp_sublist != NULL)
3446 if (tmp_sublist->fn_field.is_stub)
3448 if (tmp_sublist->fn_field.physname[0] == '_'
3449 && tmp_sublist->fn_field.physname[1] == 'Z')
3452 if (is_destructor_name (tmp_sublist->fn_field.physname))
3457 tmp_sublist = tmp_sublist->next;
3460 if (has_destructor && has_other)
3462 struct next_fnfieldlist *destr_fnlist;
3463 struct next_fnfield *last_sublist;
3465 /* Create a new fn_fieldlist for the destructors. */
3467 destr_fnlist = (struct next_fnfieldlist *)
3468 xmalloc (sizeof (struct next_fnfieldlist));
3469 make_cleanup (xfree, destr_fnlist);
3470 memset (destr_fnlist, 0, sizeof (struct next_fnfieldlist));
3471 destr_fnlist->fn_fieldlist.name
3472 = obconcat (&objfile->type_obstack, "", "~",
3473 new_fnlist->fn_fieldlist.name);
3475 destr_fnlist->fn_fieldlist.fn_fields = (struct fn_field *)
3476 obstack_alloc (&objfile->type_obstack,
3477 sizeof (struct fn_field) * has_destructor);
3478 memset (destr_fnlist->fn_fieldlist.fn_fields, 0,
3479 sizeof (struct fn_field) * has_destructor);
3480 tmp_sublist = sublist;
3481 last_sublist = NULL;
3483 while (tmp_sublist != NULL)
3485 if (!is_destructor_name (tmp_sublist->fn_field.physname))
3487 tmp_sublist = tmp_sublist->next;
3491 destr_fnlist->fn_fieldlist.fn_fields[i++]
3492 = tmp_sublist->fn_field;
3494 last_sublist->next = tmp_sublist->next;
3496 sublist = tmp_sublist->next;
3497 last_sublist = tmp_sublist;
3498 tmp_sublist = tmp_sublist->next;
3501 destr_fnlist->fn_fieldlist.length = has_destructor;
3502 destr_fnlist->next = fip->fnlist;
3503 fip->fnlist = destr_fnlist;
3505 total_length += has_destructor;
3506 length -= has_destructor;
3510 /* v3 mangling prevents the use of abbreviated physnames,
3511 so we can do this here. There are stubbed methods in v3
3513 - in -gstabs instead of -gstabs+
3514 - or for static methods, which are output as a function type
3515 instead of a method type. */
3517 update_method_name_from_physname (&new_fnlist->fn_fieldlist.name,
3518 sublist->fn_field.physname);
3520 else if (has_destructor && new_fnlist->fn_fieldlist.name[0] != '~')
3522 new_fnlist->fn_fieldlist.name = concat ("~", main_fn_name, NULL);
3523 xfree (main_fn_name);
3527 char dem_opname[256];
3529 ret = cplus_demangle_opname (new_fnlist->fn_fieldlist.name,
3530 dem_opname, DMGL_ANSI);
3532 ret = cplus_demangle_opname (new_fnlist->fn_fieldlist.name,
3535 new_fnlist->fn_fieldlist.name
3536 = obsavestring (dem_opname, strlen (dem_opname),
3537 &objfile->type_obstack);
3540 new_fnlist->fn_fieldlist.fn_fields = (struct fn_field *)
3541 obstack_alloc (&objfile->type_obstack,
3542 sizeof (struct fn_field) * length);
3543 memset (new_fnlist->fn_fieldlist.fn_fields, 0,
3544 sizeof (struct fn_field) * length);
3545 for (i = length; (i--, sublist); sublist = sublist->next)
3547 new_fnlist->fn_fieldlist.fn_fields[i] = sublist->fn_field;
3550 new_fnlist->fn_fieldlist.length = length;
3551 new_fnlist->next = fip->fnlist;
3552 fip->fnlist = new_fnlist;
3554 total_length += length;
3560 ALLOCATE_CPLUS_STRUCT_TYPE (type);
3561 TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
3562 TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * nfn_fields);
3563 memset (TYPE_FN_FIELDLISTS (type), 0,
3564 sizeof (struct fn_fieldlist) * nfn_fields);
3565 TYPE_NFN_FIELDS (type) = nfn_fields;
3566 TYPE_NFN_FIELDS_TOTAL (type) = total_length;
3572 /* Special GNU C++ name.
3574 Returns 1 for success, 0 for failure. "failure" means that we can't
3575 keep parsing and it's time for error_type(). */
3578 read_cpp_abbrev (struct field_info *fip, char **pp, struct type *type,
3579 struct objfile *objfile)
3584 struct type *context;
3594 /* At this point, *pp points to something like "22:23=*22...",
3595 where the type number before the ':' is the "context" and
3596 everything after is a regular type definition. Lookup the
3597 type, find it's name, and construct the field name. */
3599 context = read_type (pp, objfile);
3603 case 'f': /* $vf -- a virtual function table pointer */
3604 name = type_name_no_tag (context);
3609 fip->list->field.name =
3610 obconcat (&objfile->type_obstack, vptr_name, name, "");
3613 case 'b': /* $vb -- a virtual bsomethingorother */
3614 name = type_name_no_tag (context);
3617 complaint (&symfile_complaints,
3618 "C++ abbreviated type name unknown at symtab pos %d",
3622 fip->list->field.name =
3623 obconcat (&objfile->type_obstack, vb_name, name, "");
3627 invalid_cpp_abbrev_complaint (*pp);
3628 fip->list->field.name =
3629 obconcat (&objfile->type_obstack,
3630 "INVALID_CPLUSPLUS_ABBREV", "", "");
3634 /* At this point, *pp points to the ':'. Skip it and read the
3640 invalid_cpp_abbrev_complaint (*pp);
3643 fip->list->field.type = read_type (pp, objfile);
3645 (*pp)++; /* Skip the comma. */
3651 FIELD_BITPOS (fip->list->field) = read_huge_number (pp, ';', &nbits);
3655 /* This field is unpacked. */
3656 FIELD_BITSIZE (fip->list->field) = 0;
3657 fip->list->visibility = VISIBILITY_PRIVATE;
3661 invalid_cpp_abbrev_complaint (*pp);
3662 /* We have no idea what syntax an unrecognized abbrev would have, so
3663 better return 0. If we returned 1, we would need to at least advance
3664 *pp to avoid an infinite loop. */
3671 read_one_struct_field (struct field_info *fip, char **pp, char *p,
3672 struct type *type, struct objfile *objfile)
3674 /* The following is code to work around cfront generated stabs.
3675 The stabs contains full mangled name for each field.
3676 We try to demangle the name and extract the field name out of it.
3678 if (ARM_DEMANGLING && current_subfile->language == language_cplus)
3684 dem = cplus_demangle (*pp, DMGL_ANSI | DMGL_PARAMS);
3687 dem_p = strrchr (dem, ':');
3688 if (dem_p != 0 && *(dem_p - 1) == ':')
3690 FIELD_NAME (fip->list->field) =
3691 obsavestring (dem_p, strlen (dem_p), &objfile->type_obstack);
3695 FIELD_NAME (fip->list->field) =
3696 obsavestring (*pp, p - *pp, &objfile->type_obstack);
3700 /* end of code for cfront work around */
3703 fip->list->field.name =
3704 obsavestring (*pp, p - *pp, &objfile->type_obstack);
3707 /* This means we have a visibility for a field coming. */
3711 fip->list->visibility = *(*pp)++;
3715 /* normal dbx-style format, no explicit visibility */
3716 fip->list->visibility = VISIBILITY_PUBLIC;
3719 fip->list->field.type = read_type (pp, objfile);
3724 /* Possible future hook for nested types. */
3727 fip->list->field.bitpos = (long) -2; /* nested type */
3737 /* Static class member. */
3738 SET_FIELD_PHYSNAME (fip->list->field, savestring (*pp, p - *pp));
3742 else if (**pp != ',')
3744 /* Bad structure-type format. */
3745 stabs_general_complaint ("bad structure-type format");
3749 (*pp)++; /* Skip the comma. */
3753 FIELD_BITPOS (fip->list->field) = read_huge_number (pp, ',', &nbits);
3756 stabs_general_complaint ("bad structure-type format");
3759 FIELD_BITSIZE (fip->list->field) = read_huge_number (pp, ';', &nbits);
3762 stabs_general_complaint ("bad structure-type format");
3767 if (FIELD_BITPOS (fip->list->field) == 0
3768 && FIELD_BITSIZE (fip->list->field) == 0)
3770 /* This can happen in two cases: (1) at least for gcc 2.4.5 or so,
3771 it is a field which has been optimized out. The correct stab for
3772 this case is to use VISIBILITY_IGNORE, but that is a recent
3773 invention. (2) It is a 0-size array. For example
3774 union { int num; char str[0]; } foo. Printing "<no value>" for
3775 str in "p foo" is OK, since foo.str (and thus foo.str[3])
3776 will continue to work, and a 0-size array as a whole doesn't
3777 have any contents to print.
3779 I suspect this probably could also happen with gcc -gstabs (not
3780 -gstabs+) for static fields, and perhaps other C++ extensions.
3781 Hopefully few people use -gstabs with gdb, since it is intended
3782 for dbx compatibility. */
3784 /* Ignore this field. */
3785 fip->list->visibility = VISIBILITY_IGNORE;
3789 /* Detect an unpacked field and mark it as such.
3790 dbx gives a bit size for all fields.
3791 Note that forward refs cannot be packed,
3792 and treat enums as if they had the width of ints. */
3794 struct type *field_type = check_typedef (FIELD_TYPE (fip->list->field));
3796 if (TYPE_CODE (field_type) != TYPE_CODE_INT
3797 && TYPE_CODE (field_type) != TYPE_CODE_RANGE
3798 && TYPE_CODE (field_type) != TYPE_CODE_BOOL
3799 && TYPE_CODE (field_type) != TYPE_CODE_ENUM)
3801 FIELD_BITSIZE (fip->list->field) = 0;
3803 if ((FIELD_BITSIZE (fip->list->field)
3804 == TARGET_CHAR_BIT * TYPE_LENGTH (field_type)
3805 || (TYPE_CODE (field_type) == TYPE_CODE_ENUM
3806 && FIELD_BITSIZE (fip->list->field) == TARGET_INT_BIT)
3809 FIELD_BITPOS (fip->list->field) % 8 == 0)
3811 FIELD_BITSIZE (fip->list->field) = 0;
3817 /* Read struct or class data fields. They have the form:
3819 NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
3821 At the end, we see a semicolon instead of a field.
3823 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
3826 The optional VISIBILITY is one of:
3828 '/0' (VISIBILITY_PRIVATE)
3829 '/1' (VISIBILITY_PROTECTED)
3830 '/2' (VISIBILITY_PUBLIC)
3831 '/9' (VISIBILITY_IGNORE)
3833 or nothing, for C style fields with public visibility.
3835 Returns 1 for success, 0 for failure. */
3838 read_struct_fields (struct field_info *fip, char **pp, struct type *type,
3839 struct objfile *objfile)
3842 struct nextfield *new;
3844 /* We better set p right now, in case there are no fields at all... */
3848 /* Read each data member type until we find the terminating ';' at the end of
3849 the data member list, or break for some other reason such as finding the
3850 start of the member function list. */
3851 /* Stab string for structure/union does not end with two ';' in
3852 SUN C compiler 5.3 i.e. F6U2, hence check for end of string. */
3854 while (**pp != ';' && **pp != '\0')
3856 #if 0 /* OBSOLETE OS9K */
3857 // OBSOLETE if (os9k_stabs && **pp == ',')
3859 #endif /* OBSOLETE OS9K */
3860 STABS_CONTINUE (pp, objfile);
3861 /* Get space to record the next field's data. */
3862 new = (struct nextfield *) xmalloc (sizeof (struct nextfield));
3863 make_cleanup (xfree, new);
3864 memset (new, 0, sizeof (struct nextfield));
3865 new->next = fip->list;
3868 /* Get the field name. */
3871 /* If is starts with CPLUS_MARKER it is a special abbreviation,
3872 unless the CPLUS_MARKER is followed by an underscore, in
3873 which case it is just the name of an anonymous type, which we
3874 should handle like any other type name. */
3876 if (is_cplus_marker (p[0]) && p[1] != '_')
3878 if (!read_cpp_abbrev (fip, pp, type, objfile))
3883 /* Look for the ':' that separates the field name from the field
3884 values. Data members are delimited by a single ':', while member
3885 functions are delimited by a pair of ':'s. When we hit the member
3886 functions (if any), terminate scan loop and return. */
3888 while (*p != ':' && *p != '\0')
3895 /* Check to see if we have hit the member functions yet. */
3900 read_one_struct_field (fip, pp, p, type, objfile);
3902 if (p[0] == ':' && p[1] == ':')
3904 /* (OBSOLETE) chill (OBSOLETE) the list of fields: the last
3905 entry (at the head) is a partially constructed entry which we
3907 fip->list = fip->list->next;
3912 /* The stabs for C++ derived classes contain baseclass information which
3913 is marked by a '!' character after the total size. This function is
3914 called when we encounter the baseclass marker, and slurps up all the
3915 baseclass information.
3917 Immediately following the '!' marker is the number of base classes that
3918 the class is derived from, followed by information for each base class.
3919 For each base class, there are two visibility specifiers, a bit offset
3920 to the base class information within the derived class, a reference to
3921 the type for the base class, and a terminating semicolon.
3923 A typical example, with two base classes, would be "!2,020,19;0264,21;".
3925 Baseclass information marker __________________|| | | | | | |
3926 Number of baseclasses __________________________| | | | | | |
3927 Visibility specifiers (2) ________________________| | | | | |
3928 Offset in bits from start of class _________________| | | | |
3929 Type number for base class ___________________________| | | |
3930 Visibility specifiers (2) _______________________________| | |
3931 Offset in bits from start of class ________________________| |
3932 Type number of base class ____________________________________|
3934 Return 1 for success, 0 for (error-type-inducing) failure. */
3940 read_baseclasses (struct field_info *fip, char **pp, struct type *type,
3941 struct objfile *objfile)
3944 struct nextfield *new;
3952 /* Skip the '!' baseclass information marker. */
3956 ALLOCATE_CPLUS_STRUCT_TYPE (type);
3959 TYPE_N_BASECLASSES (type) = read_huge_number (pp, ',', &nbits);
3965 /* Some stupid compilers have trouble with the following, so break
3966 it up into simpler expressions. */
3967 TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *)
3968 TYPE_ALLOC (type, B_BYTES (TYPE_N_BASECLASSES (type)));
3971 int num_bytes = B_BYTES (TYPE_N_BASECLASSES (type));
3974 pointer = (char *) TYPE_ALLOC (type, num_bytes);
3975 TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *) pointer;
3979 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), TYPE_N_BASECLASSES (type));
3981 for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
3983 new = (struct nextfield *) xmalloc (sizeof (struct nextfield));
3984 make_cleanup (xfree, new);
3985 memset (new, 0, sizeof (struct nextfield));
3986 new->next = fip->list;
3988 FIELD_BITSIZE (new->field) = 0; /* this should be an unpacked field! */
3990 STABS_CONTINUE (pp, objfile);
3994 /* Nothing to do. */
3997 SET_TYPE_FIELD_VIRTUAL (type, i);
4000 /* Unknown character. Complain and treat it as non-virtual. */
4002 complaint (&symfile_complaints,
4003 "Unknown virtual character `%c' for baseclass", **pp);
4008 new->visibility = *(*pp)++;
4009 switch (new->visibility)
4011 case VISIBILITY_PRIVATE:
4012 case VISIBILITY_PROTECTED:
4013 case VISIBILITY_PUBLIC:
4016 /* Bad visibility format. Complain and treat it as
4019 complaint (&symfile_complaints,
4020 "Unknown visibility `%c' for baseclass",
4022 new->visibility = VISIBILITY_PUBLIC;
4029 /* The remaining value is the bit offset of the portion of the object
4030 corresponding to this baseclass. Always zero in the absence of
4031 multiple inheritance. */
4033 FIELD_BITPOS (new->field) = read_huge_number (pp, ',', &nbits);
4038 /* The last piece of baseclass information is the type of the
4039 base class. Read it, and remember it's type name as this
4042 new->field.type = read_type (pp, objfile);
4043 new->field.name = type_name_no_tag (new->field.type);
4045 /* skip trailing ';' and bump count of number of fields seen */
4054 /* The tail end of stabs for C++ classes that contain a virtual function
4055 pointer contains a tilde, a %, and a type number.
4056 The type number refers to the base class (possibly this class itself) which
4057 contains the vtable pointer for the current class.
4059 This function is called when we have parsed all the method declarations,
4060 so we can look for the vptr base class info. */
4063 read_tilde_fields (struct field_info *fip, char **pp, struct type *type,
4064 struct objfile *objfile)
4068 STABS_CONTINUE (pp, objfile);
4070 /* If we are positioned at a ';', then skip it. */
4080 if (**pp == '=' || **pp == '+' || **pp == '-')
4082 /* Obsolete flags that used to indicate the presence
4083 of constructors and/or destructors. */
4087 /* Read either a '%' or the final ';'. */
4088 if (*(*pp)++ == '%')
4090 /* The next number is the type number of the base class
4091 (possibly our own class) which supplies the vtable for
4092 this class. Parse it out, and search that class to find
4093 its vtable pointer, and install those into TYPE_VPTR_BASETYPE
4094 and TYPE_VPTR_FIELDNO. */
4099 t = read_type (pp, objfile);
4101 while (*p != '\0' && *p != ';')
4107 /* Premature end of symbol. */
4111 TYPE_VPTR_BASETYPE (type) = t;
4112 if (type == t) /* Our own class provides vtbl ptr */
4114 for (i = TYPE_NFIELDS (t) - 1;
4115 i >= TYPE_N_BASECLASSES (t);
4118 char *name = TYPE_FIELD_NAME (t, i);
4119 if (!strncmp (name, vptr_name, sizeof (vptr_name) - 2)
4120 && is_cplus_marker (name[sizeof (vptr_name) - 2]))
4122 TYPE_VPTR_FIELDNO (type) = i;
4126 /* Virtual function table field not found. */
4127 complaint (&symfile_complaints,
4128 "virtual function table pointer not found when defining class `%s'",
4134 TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t);
4145 attach_fn_fields_to_type (struct field_info *fip, register struct type *type)
4149 for (n = TYPE_NFN_FIELDS (type);
4150 fip->fnlist != NULL;
4151 fip->fnlist = fip->fnlist->next)
4153 --n; /* Circumvent Sun3 compiler bug */
4154 TYPE_FN_FIELDLISTS (type)[n] = fip->fnlist->fn_fieldlist;
4159 /* read cfront class static data.
4160 pp points to string starting with the list of static data
4161 eg: A:ZcA;1@Bpub v2@Bvirpri;__ct__1AFv func__1AFv *sfunc__1AFv ;as__1A ;;
4164 A:ZcA;;foopri__1AFv foopro__1AFv __ct__1AFv __ct__1AFRC1A foopub__1AFv ;;;
4169 read_cfront_static_fields (struct field_info *fip, char **pp, struct type *type,
4170 struct objfile *objfile)
4172 struct nextfield *new;
4175 struct symbol *ref_static = 0;
4177 if (**pp == ';') /* no static data; return */
4183 /* Process each field in the list until we find the terminating ";" */
4185 /* eg: p = "as__1A ;;;" */
4186 STABS_CONTINUE (pp, objfile); /* handle \\ */
4187 while (**pp != ';' && (sname = get_substring (pp, ' '), sname))
4189 ref_static = lookup_symbol (sname, 0, VAR_NAMESPACE, 0, 0); /*demangled_name */
4192 complaint (&symfile_complaints,
4193 "Unable to find symbol for static data field %s", sname);
4196 stype = SYMBOL_TYPE (ref_static);
4198 /* allocate a new fip */
4199 new = (struct nextfield *) xmalloc (sizeof (struct nextfield));
4200 make_cleanup (xfree, new);
4201 memset (new, 0, sizeof (struct nextfield));
4202 new->next = fip->list;
4205 /* set visibility */
4206 /* FIXME! no way to tell visibility from stabs??? */
4207 new->visibility = VISIBILITY_PUBLIC;
4209 /* set field info into fip */
4210 fip->list->field.type = stype;
4212 /* set bitpos & bitsize */
4213 SET_FIELD_PHYSNAME (fip->list->field, savestring (sname, strlen (sname)));
4215 /* set name field */
4216 /* The following is code to work around cfront generated stabs.
4217 The stabs contains full mangled name for each field.
4218 We try to demangle the name and extract the field name out of it.
4223 dem = cplus_demangle (sname, DMGL_ANSI | DMGL_PARAMS);
4226 dem_p = strrchr (dem, ':');
4227 if (dem_p != 0 && *(dem_p - 1) == ':')
4229 fip->list->field.name =
4230 obsavestring (dem_p, strlen (dem_p), &objfile->type_obstack);
4234 fip->list->field.name =
4235 obsavestring (sname, strlen (sname), &objfile->type_obstack);
4237 } /* end of code for cfront work around */
4238 } /* loop again for next static field */
4242 /* Copy structure fields to fip so attach_fields_to_type will work.
4243 type has already been created with the initial instance data fields.
4244 Now we want to be able to add the other members to the class,
4245 so we want to add them back to the fip and reattach them again
4246 once we have collected all the class members. */
4249 copy_cfront_struct_fields (struct field_info *fip, struct type *type,
4250 struct objfile *objfile)
4252 int nfields = TYPE_NFIELDS (type);
4254 struct nextfield *new;
4256 /* Copy the fields into the list of fips and reset the types
4257 to remove the old fields */
4259 for (i = 0; i < nfields; i++)
4261 /* allocate a new fip */
4262 new = (struct nextfield *) xmalloc (sizeof (struct nextfield));
4263 make_cleanup (xfree, new);
4264 memset (new, 0, sizeof (struct nextfield));
4265 new->next = fip->list;
4268 /* copy field info into fip */
4269 new->field = TYPE_FIELD (type, i);
4270 /* set visibility */
4271 if (TYPE_FIELD_PROTECTED (type, i))
4272 new->visibility = VISIBILITY_PROTECTED;
4273 else if (TYPE_FIELD_PRIVATE (type, i))
4274 new->visibility = VISIBILITY_PRIVATE;
4276 new->visibility = VISIBILITY_PUBLIC;
4278 /* Now delete the fields from the type since we will be
4279 allocing new space once we get the rest of the fields
4280 in attach_fields_to_type.
4281 The pointer TYPE_FIELDS(type) is left dangling but should
4282 be freed later by objstack_free */
4283 TYPE_FIELDS (type) = 0;
4284 TYPE_NFIELDS (type) = 0;
4289 /* Create the vector of fields, and record how big it is.
4290 We need this info to record proper virtual function table information
4291 for this class's virtual functions. */
4294 attach_fields_to_type (struct field_info *fip, register struct type *type,
4295 struct objfile *objfile)
4297 register int nfields = 0;
4298 register int non_public_fields = 0;
4299 register struct nextfield *scan;
4301 /* Count up the number of fields that we have, as well as taking note of
4302 whether or not there are any non-public fields, which requires us to
4303 allocate and build the private_field_bits and protected_field_bits
4306 for (scan = fip->list; scan != NULL; scan = scan->next)
4309 if (scan->visibility != VISIBILITY_PUBLIC)
4311 non_public_fields++;
4315 /* Now we know how many fields there are, and whether or not there are any
4316 non-public fields. Record the field count, allocate space for the
4317 array of fields, and create blank visibility bitfields if necessary. */
4319 TYPE_NFIELDS (type) = nfields;
4320 TYPE_FIELDS (type) = (struct field *)
4321 TYPE_ALLOC (type, sizeof (struct field) * nfields);
4322 memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields);
4324 if (non_public_fields)
4326 ALLOCATE_CPLUS_STRUCT_TYPE (type);
4328 TYPE_FIELD_PRIVATE_BITS (type) =
4329 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
4330 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields);
4332 TYPE_FIELD_PROTECTED_BITS (type) =
4333 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
4334 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields);
4336 TYPE_FIELD_IGNORE_BITS (type) =
4337 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
4338 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields);
4341 /* Copy the saved-up fields into the field vector. Start from the head
4342 of the list, adding to the tail of the field array, so that they end
4343 up in the same order in the array in which they were added to the list. */
4345 while (nfields-- > 0)
4347 TYPE_FIELD (type, nfields) = fip->list->field;
4348 switch (fip->list->visibility)
4350 case VISIBILITY_PRIVATE:
4351 SET_TYPE_FIELD_PRIVATE (type, nfields);
4354 case VISIBILITY_PROTECTED:
4355 SET_TYPE_FIELD_PROTECTED (type, nfields);
4358 case VISIBILITY_IGNORE:
4359 SET_TYPE_FIELD_IGNORE (type, nfields);
4362 case VISIBILITY_PUBLIC:
4366 /* Unknown visibility. Complain and treat it as public. */
4368 complaint (&symfile_complaints, "Unknown visibility `%c' for field",
4369 fip->list->visibility);
4373 fip->list = fip->list->next;
4379 /* Complain that the compiler has emitted more than one definition for the
4380 structure type TYPE. */
4382 complain_about_struct_wipeout (struct type *type)
4387 if (TYPE_TAG_NAME (type))
4389 name = TYPE_TAG_NAME (type);
4390 switch (TYPE_CODE (type))
4392 case TYPE_CODE_STRUCT: kind = "struct "; break;
4393 case TYPE_CODE_UNION: kind = "union "; break;
4394 case TYPE_CODE_ENUM: kind = "enum "; break;
4398 else if (TYPE_NAME (type))
4400 name = TYPE_NAME (type);
4409 complaint (&symfile_complaints,
4410 "struct/union type gets multiply defined: %s%s", kind, name);
4414 /* Read the description of a structure (or union type) and return an object
4415 describing the type.
4417 PP points to a character pointer that points to the next unconsumed token
4418 in the the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;",
4419 *PP will point to "4a:1,0,32;;".
4421 TYPE points to an incomplete type that needs to be filled in.
4423 OBJFILE points to the current objfile from which the stabs information is
4424 being read. (Note that it is redundant in that TYPE also contains a pointer
4425 to this same objfile, so it might be a good idea to eliminate it. FIXME).
4428 static struct type *
4429 read_struct_type (char **pp, struct type *type, enum type_code type_code,
4430 struct objfile *objfile)
4432 struct cleanup *back_to;
4433 struct field_info fi;
4438 /* When describing struct/union/class types in stabs, G++ always drops
4439 all qualifications from the name. So if you've got:
4440 struct A { ... struct B { ... }; ... };
4441 then G++ will emit stabs for `struct A::B' that call it simply
4442 `struct B'. Obviously, if you've got a real top-level definition for
4443 `struct B', or other nested definitions, this is going to cause
4446 Obviously, GDB can't fix this by itself, but it can at least avoid
4447 scribbling on existing structure type objects when new definitions
4449 if (! (TYPE_CODE (type) == TYPE_CODE_UNDEF
4450 || TYPE_STUB (type)))
4452 complain_about_struct_wipeout (type);
4454 /* It's probably best to return the type unchanged. */
4458 back_to = make_cleanup (null_cleanup, 0);
4460 INIT_CPLUS_SPECIFIC (type);
4461 TYPE_CODE (type) = type_code;
4462 TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
4464 /* First comes the total size in bytes. */
4468 TYPE_LENGTH (type) = read_huge_number (pp, 0, &nbits);
4470 return error_type (pp, objfile);
4473 /* Now read the baseclasses, if any, read the regular C struct or C++
4474 class member fields, attach the fields to the type, read the C++
4475 member functions, attach them to the type, and then read any tilde
4476 field (baseclass specifier for the class holding the main vtable). */
4478 if (!read_baseclasses (&fi, pp, type, objfile)
4479 || !read_struct_fields (&fi, pp, type, objfile)
4480 || !attach_fields_to_type (&fi, type, objfile)
4481 || !read_member_functions (&fi, pp, type, objfile)
4482 || !attach_fn_fields_to_type (&fi, type)
4483 || !read_tilde_fields (&fi, pp, type, objfile))
4485 type = error_type (pp, objfile);
4488 do_cleanups (back_to);
4492 /* Read a definition of an array type,
4493 and create and return a suitable type object.
4494 Also creates a range type which represents the bounds of that
4497 static struct type *
4498 read_array_type (register char **pp, register struct type *type,
4499 struct objfile *objfile)
4501 struct type *index_type, *element_type, *range_type;
4506 /* Format of an array type:
4507 "ar<index type>;lower;upper;<array_contents_type>".
4508 OS9000: "arlower,upper;<array_contents_type>".
4510 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
4511 for these, produce a type like float[][]. */
4513 #if 0 /* OBSOLETE OS9K */
4514 // OBSOLETE if (os9k_stabs)
4515 // OBSOLETE index_type = builtin_type_int;
4517 #endif /* OBSOLETE OS9K */
4519 index_type = read_type (pp, objfile);
4521 /* Improper format of array type decl. */
4522 return error_type (pp, objfile);
4526 if (!(**pp >= '0' && **pp <= '9') && **pp != '-')
4531 #if 0 /* OBSOLETE OS9K */
4532 // OBSOLETE lower = read_huge_number (pp, os9k_stabs ? ',' : ';', &nbits);
4533 #else /* OBSOLETE OS9K */
4534 lower = read_huge_number (pp, ';', &nbits);
4535 #endif /* OBSOLETE OS9K */
4538 return error_type (pp, objfile);
4540 if (!(**pp >= '0' && **pp <= '9') && **pp != '-')
4545 upper = read_huge_number (pp, ';', &nbits);
4547 return error_type (pp, objfile);
4549 element_type = read_type (pp, objfile);
4558 create_range_type ((struct type *) NULL, index_type, lower, upper);
4559 type = create_array_type (type, element_type, range_type);
4565 /* Read a definition of an enumeration type,
4566 and create and return a suitable type object.
4567 Also defines the symbols that represent the values of the type. */
4569 static struct type *
4570 read_enum_type (register char **pp, register struct type *type,
4571 struct objfile *objfile)
4576 register struct symbol *sym;
4578 struct pending **symlist;
4579 struct pending *osyms, *syms;
4582 int unsigned_enum = 1;
4585 /* FIXME! The stabs produced by Sun CC merrily define things that ought
4586 to be file-scope, between N_FN entries, using N_LSYM. What's a mother
4587 to do? For now, force all enum values to file scope. */
4588 if (within_function)
4589 symlist = &local_symbols;
4592 symlist = &file_symbols;
4594 o_nsyms = osyms ? osyms->nsyms : 0;
4596 #if 0 /* OBSOLETE OS9K */
4597 // OBSOLETE if (os9k_stabs)
4599 // OBSOLETE /* Size. Perhaps this does not have to be conditionalized on
4600 // OBSOLETE os9k_stabs (assuming the name of an enum constant can't start
4601 // OBSOLETE with a digit). */
4602 // OBSOLETE read_huge_number (pp, 0, &nbits);
4603 // OBSOLETE if (nbits != 0)
4604 // OBSOLETE return error_type (pp, objfile);
4606 #endif /* OBSOLETE OS9K */
4608 /* The aix4 compiler emits an extra field before the enum members;
4609 my guess is it's a type of some sort. Just ignore it. */
4612 /* Skip over the type. */
4616 /* Skip over the colon. */
4620 /* Read the value-names and their values.
4621 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
4622 A semicolon or comma instead of a NAME means the end. */
4623 while (**pp && **pp != ';' && **pp != ',')
4625 STABS_CONTINUE (pp, objfile);
4629 name = obsavestring (*pp, p - *pp, &objfile->symbol_obstack);
4631 n = read_huge_number (pp, ',', &nbits);
4633 return error_type (pp, objfile);
4635 sym = (struct symbol *)
4636 obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol));
4637 memset (sym, 0, sizeof (struct symbol));
4638 SYMBOL_NAME (sym) = name;
4639 SYMBOL_LANGUAGE (sym) = current_subfile->language;
4640 SYMBOL_CLASS (sym) = LOC_CONST;
4641 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
4642 SYMBOL_VALUE (sym) = n;
4645 add_symbol_to_list (sym, symlist);
4650 (*pp)++; /* Skip the semicolon. */
4652 /* Now fill in the fields of the type-structure. */
4654 TYPE_LENGTH (type) = TARGET_INT_BIT / HOST_CHAR_BIT;
4655 TYPE_CODE (type) = TYPE_CODE_ENUM;
4656 TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
4658 TYPE_FLAGS (type) |= TYPE_FLAG_UNSIGNED;
4659 TYPE_NFIELDS (type) = nsyms;
4660 TYPE_FIELDS (type) = (struct field *)
4661 TYPE_ALLOC (type, sizeof (struct field) * nsyms);
4662 memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nsyms);
4664 /* Find the symbols for the values and put them into the type.
4665 The symbols can be found in the symlist that we put them on
4666 to cause them to be defined. osyms contains the old value
4667 of that symlist; everything up to there was defined by us. */
4668 /* Note that we preserve the order of the enum constants, so
4669 that in something like "enum {FOO, LAST_THING=FOO}" we print
4670 FOO, not LAST_THING. */
4672 for (syms = *symlist, n = nsyms - 1; syms; syms = syms->next)
4674 int last = syms == osyms ? o_nsyms : 0;
4675 int j = syms->nsyms;
4676 for (; --j >= last; --n)
4678 struct symbol *xsym = syms->symbol[j];
4679 SYMBOL_TYPE (xsym) = type;
4680 TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym);
4681 TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (xsym);
4682 TYPE_FIELD_BITSIZE (type, n) = 0;
4691 /* Sun's ACC uses a somewhat saner method for specifying the builtin
4692 typedefs in every file (for int, long, etc):
4694 type = b <signed> <width> <format type>; <offset>; <nbits>
4696 optional format type = c or b for char or boolean.
4697 offset = offset from high order bit to start bit of type.
4698 width is # bytes in object of this type, nbits is # bits in type.
4700 The width/offset stuff appears to be for small objects stored in
4701 larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
4704 static struct type *
4705 read_sun_builtin_type (char **pp, int typenums[2], struct objfile *objfile)
4710 enum type_code code = TYPE_CODE_INT;
4721 return error_type (pp, objfile);
4725 /* For some odd reason, all forms of char put a c here. This is strange
4726 because no other type has this honor. We can safely ignore this because
4727 we actually determine 'char'acterness by the number of bits specified in
4729 Boolean forms, e.g Fortran logical*X, put a b here. */
4733 else if (**pp == 'b')
4735 code = TYPE_CODE_BOOL;
4739 /* The first number appears to be the number of bytes occupied
4740 by this type, except that unsigned short is 4 instead of 2.
4741 Since this information is redundant with the third number,
4742 we will ignore it. */
4743 read_huge_number (pp, ';', &nbits);
4745 return error_type (pp, objfile);
4747 /* The second number is always 0, so ignore it too. */
4748 read_huge_number (pp, ';', &nbits);
4750 return error_type (pp, objfile);
4752 /* The third number is the number of bits for this type. */
4753 type_bits = read_huge_number (pp, 0, &nbits);
4755 return error_type (pp, objfile);
4756 /* The type *should* end with a semicolon. If it are embedded
4757 in a larger type the semicolon may be the only way to know where
4758 the type ends. If this type is at the end of the stabstring we
4759 can deal with the omitted semicolon (but we don't have to like
4760 it). Don't bother to complain(), Sun's compiler omits the semicolon
4766 return init_type (TYPE_CODE_VOID, 1,
4767 signed_type ? 0 : TYPE_FLAG_UNSIGNED, (char *) NULL,
4770 return init_type (code,
4771 type_bits / TARGET_CHAR_BIT,
4772 signed_type ? 0 : TYPE_FLAG_UNSIGNED, (char *) NULL,
4776 static struct type *
4777 read_sun_floating_type (char **pp, int typenums[2], struct objfile *objfile)
4782 struct type *rettype;
4784 /* The first number has more details about the type, for example
4786 details = read_huge_number (pp, ';', &nbits);
4788 return error_type (pp, objfile);
4790 /* The second number is the number of bytes occupied by this type */
4791 nbytes = read_huge_number (pp, ';', &nbits);
4793 return error_type (pp, objfile);
4795 if (details == NF_COMPLEX || details == NF_COMPLEX16
4796 || details == NF_COMPLEX32)
4798 rettype = init_type (TYPE_CODE_COMPLEX, nbytes, 0, NULL, objfile);
4799 TYPE_TARGET_TYPE (rettype)
4800 = init_type (TYPE_CODE_FLT, nbytes / 2, 0, NULL, objfile);
4804 return init_type (TYPE_CODE_FLT, nbytes, 0, NULL, objfile);
4807 /* Read a number from the string pointed to by *PP.
4808 The value of *PP is advanced over the number.
4809 If END is nonzero, the character that ends the
4810 number must match END, or an error happens;
4811 and that character is skipped if it does match.
4812 If END is zero, *PP is left pointing to that character.
4814 If the number fits in a long, set *BITS to 0 and return the value.
4815 If not, set *BITS to be the number of bits in the number and return 0.
4817 If encounter garbage, set *BITS to -1 and return 0. */
4820 read_huge_number (char **pp, int end, int *bits)
4837 /* Leading zero means octal. GCC uses this to output values larger
4838 than an int (because that would be hard in decimal). */
4845 #if 0 /* OBSOLETE OS9K */
4846 // OBSOLETE if (os9k_stabs)
4847 // OBSOLETE upper_limit = ULONG_MAX / radix;
4849 #endif /* OBSOLETE OS9K */
4850 upper_limit = LONG_MAX / radix;
4852 while ((c = *p++) >= '0' && c < ('0' + radix))
4854 if (n <= upper_limit)
4857 n += c - '0'; /* FIXME this overflows anyway */
4862 /* This depends on large values being output in octal, which is
4869 /* Ignore leading zeroes. */
4873 else if (c == '2' || c == '3')
4899 /* Large decimal constants are an error (because it is hard to
4900 count how many bits are in them). */
4906 /* -0x7f is the same as 0x80. So deal with it by adding one to
4907 the number of bits. */
4919 /* It's *BITS which has the interesting information. */
4923 static struct type *
4924 read_range_type (char **pp, int typenums[2], struct objfile *objfile)
4926 char *orig_pp = *pp;
4931 struct type *result_type;
4932 struct type *index_type = NULL;
4934 /* First comes a type we are a subrange of.
4935 In C it is usually 0, 1 or the type being defined. */
4936 if (read_type_number (pp, rangenums) != 0)
4937 return error_type (pp, objfile);
4938 self_subrange = (rangenums[0] == typenums[0] &&
4939 rangenums[1] == typenums[1]);
4944 index_type = read_type (pp, objfile);
4947 /* A semicolon should now follow; skip it. */
4951 /* The remaining two operands are usually lower and upper bounds
4952 of the range. But in some special cases they mean something else. */
4953 n2 = read_huge_number (pp, ';', &n2bits);
4954 n3 = read_huge_number (pp, ';', &n3bits);
4956 if (n2bits == -1 || n3bits == -1)
4957 return error_type (pp, objfile);
4960 goto handle_true_range;
4962 /* If limits are huge, must be large integral type. */
4963 if (n2bits != 0 || n3bits != 0)
4965 char got_signed = 0;
4966 char got_unsigned = 0;
4967 /* Number of bits in the type. */
4970 /* Range from 0 to <large number> is an unsigned large integral type. */
4971 if ((n2bits == 0 && n2 == 0) && n3bits != 0)
4976 /* Range from <large number> to <large number>-1 is a large signed
4977 integral type. Take care of the case where <large number> doesn't
4978 fit in a long but <large number>-1 does. */
4979 else if ((n2bits != 0 && n3bits != 0 && n2bits == n3bits + 1)
4980 || (n2bits != 0 && n3bits == 0
4981 && (n2bits == sizeof (long) * HOST_CHAR_BIT)
4988 if (got_signed || got_unsigned)
4990 return init_type (TYPE_CODE_INT, nbits / TARGET_CHAR_BIT,
4991 got_unsigned ? TYPE_FLAG_UNSIGNED : 0, NULL,
4995 return error_type (pp, objfile);
4998 /* A type defined as a subrange of itself, with bounds both 0, is void. */
4999 if (self_subrange && n2 == 0 && n3 == 0)
5000 return init_type (TYPE_CODE_VOID, 1, 0, NULL, objfile);
5002 /* If n3 is zero and n2 is positive, we want a floating type, and n2
5003 is the width in bytes.
5005 Fortran programs appear to use this for complex types also. To
5006 distinguish between floats and complex, g77 (and others?) seem
5007 to use self-subranges for the complexes, and subranges of int for
5010 Also note that for complexes, g77 sets n2 to the size of one of
5011 the member floats, not the whole complex beast. My guess is that
5012 this was to work well with pre-COMPLEX versions of gdb. */
5014 if (n3 == 0 && n2 > 0)
5016 struct type *float_type
5017 = init_type (TYPE_CODE_FLT, n2, 0, NULL, objfile);
5021 struct type *complex_type =
5022 init_type (TYPE_CODE_COMPLEX, 2 * n2, 0, NULL, objfile);
5023 TYPE_TARGET_TYPE (complex_type) = float_type;
5024 return complex_type;
5030 /* If the upper bound is -1, it must really be an unsigned int. */
5032 else if (n2 == 0 && n3 == -1)
5034 /* It is unsigned int or unsigned long. */
5035 /* GCC 2.3.3 uses this for long long too, but that is just a GDB 3.5
5036 compatibility hack. */
5037 return init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
5038 TYPE_FLAG_UNSIGNED, NULL, objfile);
5041 /* Special case: char is defined (Who knows why) as a subrange of
5042 itself with range 0-127. */
5043 else if (self_subrange && n2 == 0 && n3 == 127)
5044 return init_type (TYPE_CODE_INT, 1, 0, NULL, objfile);
5047 /* OBSOLETE else if (current_symbol && SYMBOL_LANGUAGE (current_symbol) == language_chill */
5048 /* OBSOLETE && !self_subrange) */
5049 /* OBSOLETE goto handle_true_range; */
5052 /* We used to do this only for subrange of self or subrange of int. */
5055 /* -1 is used for the upper bound of (4 byte) "unsigned int" and
5056 "unsigned long", and we already checked for that,
5057 so don't need to test for it here. */
5060 /* n3 actually gives the size. */
5061 return init_type (TYPE_CODE_INT, -n3, TYPE_FLAG_UNSIGNED,
5064 /* Is n3 == 2**(8n)-1 for some integer n? Then it's an
5065 unsigned n-byte integer. But do require n to be a power of
5066 two; we don't want 3- and 5-byte integers flying around. */
5072 for (bytes = 0; (bits & 0xff) == 0xff; bytes++)
5075 && ((bytes - 1) & bytes) == 0) /* "bytes is a power of two" */
5076 return init_type (TYPE_CODE_INT, bytes, TYPE_FLAG_UNSIGNED, NULL,
5080 /* I think this is for Convex "long long". Since I don't know whether
5081 Convex sets self_subrange, I also accept that particular size regardless
5082 of self_subrange. */
5083 else if (n3 == 0 && n2 < 0
5085 || n2 == -TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT))
5086 return init_type (TYPE_CODE_INT, -n2, 0, NULL, objfile);
5087 else if (n2 == -n3 - 1)
5090 return init_type (TYPE_CODE_INT, 1, 0, NULL, objfile);
5092 return init_type (TYPE_CODE_INT, 2, 0, NULL, objfile);
5093 if (n3 == 0x7fffffff)
5094 return init_type (TYPE_CODE_INT, 4, 0, NULL, objfile);
5097 /* We have a real range type on our hands. Allocate space and
5098 return a real pointer. */
5102 index_type = builtin_type_int;
5104 index_type = *dbx_lookup_type (rangenums);
5105 if (index_type == NULL)
5107 /* Does this actually ever happen? Is that why we are worrying
5108 about dealing with it rather than just calling error_type? */
5110 static struct type *range_type_index;
5112 complaint (&symfile_complaints,
5113 "base type %d of range type is not defined", rangenums[1]);
5114 if (range_type_index == NULL)
5116 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
5117 0, "range type index type", NULL);
5118 index_type = range_type_index;
5121 result_type = create_range_type ((struct type *) NULL, index_type, n2, n3);
5122 return (result_type);
5125 /* Read in an argument list. This is a list of types, separated by commas
5126 and terminated with END. Return the list of types read in, or (struct type
5127 **)-1 if there is an error. */
5129 static struct field *
5130 read_args (char **pp, int end, struct objfile *objfile, int *nargsp,
5133 /* FIXME! Remove this arbitrary limit! */
5134 struct type *types[1024]; /* allow for fns of 1023 parameters */
5141 /* Invalid argument list: no ','. */
5142 return (struct field *) -1;
5144 STABS_CONTINUE (pp, objfile);
5145 types[n++] = read_type (pp, objfile);
5147 (*pp)++; /* get past `end' (the ':' character) */
5149 if (TYPE_CODE (types[n - 1]) != TYPE_CODE_VOID)
5157 rval = (struct field *) xmalloc (n * sizeof (struct field));
5158 memset (rval, 0, n * sizeof (struct field));
5159 for (i = 0; i < n; i++)
5160 rval[i].type = types[i];
5165 /* Common block handling. */
5167 /* List of symbols declared since the last BCOMM. This list is a tail
5168 of local_symbols. When ECOMM is seen, the symbols on the list
5169 are noted so their proper addresses can be filled in later,
5170 using the common block base address gotten from the assembler
5173 static struct pending *common_block;
5174 static int common_block_i;
5176 /* Name of the current common block. We get it from the BCOMM instead of the
5177 ECOMM to match IBM documentation (even though IBM puts the name both places
5178 like everyone else). */
5179 static char *common_block_name;
5181 /* Process a N_BCOMM symbol. The storage for NAME is not guaranteed
5182 to remain after this function returns. */
5185 common_block_start (char *name, struct objfile *objfile)
5187 if (common_block_name != NULL)
5189 complaint (&symfile_complaints,
5190 "Invalid symbol data: common block within common block");
5192 common_block = local_symbols;
5193 common_block_i = local_symbols ? local_symbols->nsyms : 0;
5194 common_block_name = obsavestring (name, strlen (name),
5195 &objfile->symbol_obstack);
5198 /* Process a N_ECOMM symbol. */
5201 common_block_end (struct objfile *objfile)
5203 /* Symbols declared since the BCOMM are to have the common block
5204 start address added in when we know it. common_block and
5205 common_block_i point to the first symbol after the BCOMM in
5206 the local_symbols list; copy the list and hang it off the
5207 symbol for the common block name for later fixup. */
5210 struct pending *new = 0;
5211 struct pending *next;
5214 if (common_block_name == NULL)
5216 complaint (&symfile_complaints, "ECOMM symbol unmatched by BCOMM");
5220 sym = (struct symbol *)
5221 obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol));
5222 memset (sym, 0, sizeof (struct symbol));
5223 /* Note: common_block_name already saved on symbol_obstack */
5224 SYMBOL_NAME (sym) = common_block_name;
5225 SYMBOL_CLASS (sym) = LOC_BLOCK;
5227 /* Now we copy all the symbols which have been defined since the BCOMM. */
5229 /* Copy all the struct pendings before common_block. */
5230 for (next = local_symbols;
5231 next != NULL && next != common_block;
5234 for (j = 0; j < next->nsyms; j++)
5235 add_symbol_to_list (next->symbol[j], &new);
5238 /* Copy however much of COMMON_BLOCK we need. If COMMON_BLOCK is
5239 NULL, it means copy all the local symbols (which we already did
5242 if (common_block != NULL)
5243 for (j = common_block_i; j < common_block->nsyms; j++)
5244 add_symbol_to_list (common_block->symbol[j], &new);
5246 SYMBOL_TYPE (sym) = (struct type *) new;
5248 /* Should we be putting local_symbols back to what it was?
5251 i = hashname (SYMBOL_NAME (sym));
5252 SYMBOL_VALUE_CHAIN (sym) = global_sym_chain[i];
5253 global_sym_chain[i] = sym;
5254 common_block_name = NULL;
5257 /* Add a common block's start address to the offset of each symbol
5258 declared to be in it (by being between a BCOMM/ECOMM pair that uses
5259 the common block name). */
5262 fix_common_block (struct symbol *sym, int valu)
5264 struct pending *next = (struct pending *) SYMBOL_TYPE (sym);
5265 for (; next; next = next->next)
5268 for (j = next->nsyms - 1; j >= 0; j--)
5269 SYMBOL_VALUE_ADDRESS (next->symbol[j]) += valu;
5275 /* What about types defined as forward references inside of a small lexical
5277 /* Add a type to the list of undefined types to be checked through
5278 once this file has been read in. */
5281 add_undefined_type (struct type *type)
5283 if (undef_types_length == undef_types_allocated)
5285 undef_types_allocated *= 2;
5286 undef_types = (struct type **)
5287 xrealloc ((char *) undef_types,
5288 undef_types_allocated * sizeof (struct type *));
5290 undef_types[undef_types_length++] = type;
5293 /* Go through each undefined type, see if it's still undefined, and fix it
5294 up if possible. We have two kinds of undefined types:
5296 TYPE_CODE_ARRAY: Array whose target type wasn't defined yet.
5297 Fix: update array length using the element bounds
5298 and the target type's length.
5299 TYPE_CODE_STRUCT, TYPE_CODE_UNION: Structure whose fields were not
5300 yet defined at the time a pointer to it was made.
5301 Fix: Do a full lookup on the struct/union tag. */
5303 cleanup_undefined_types (void)
5307 for (type = undef_types; type < undef_types + undef_types_length; type++)
5309 switch (TYPE_CODE (*type))
5312 case TYPE_CODE_STRUCT:
5313 case TYPE_CODE_UNION:
5314 case TYPE_CODE_ENUM:
5316 /* Check if it has been defined since. Need to do this here
5317 as well as in check_typedef to deal with the (legitimate in
5318 C though not C++) case of several types with the same name
5319 in different source files. */
5320 if (TYPE_STUB (*type))
5322 struct pending *ppt;
5324 /* Name of the type, without "struct" or "union" */
5325 char *typename = TYPE_TAG_NAME (*type);
5327 if (typename == NULL)
5329 complaint (&symfile_complaints, "need a type name");
5332 for (ppt = file_symbols; ppt; ppt = ppt->next)
5334 for (i = 0; i < ppt->nsyms; i++)
5336 struct symbol *sym = ppt->symbol[i];
5338 if (SYMBOL_CLASS (sym) == LOC_TYPEDEF
5339 && SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE
5340 && (TYPE_CODE (SYMBOL_TYPE (sym)) ==
5342 && STREQ (SYMBOL_NAME (sym), typename))
5343 replace_type (*type, SYMBOL_TYPE (sym));
5352 complaint (&symfile_complaints,
5353 "GDB internal error. cleanup_undefined_types with bad type %d.",
5360 undef_types_length = 0;
5363 /* Scan through all of the global symbols defined in the object file,
5364 assigning values to the debugging symbols that need to be assigned
5365 to. Get these symbols from the minimal symbol table. */
5368 scan_file_globals (struct objfile *objfile)
5371 struct minimal_symbol *msymbol;
5372 struct symbol *sym, *prev, *rsym;
5373 struct objfile *resolve_objfile;
5375 /* SVR4 based linkers copy referenced global symbols from shared
5376 libraries to the main executable.
5377 If we are scanning the symbols for a shared library, try to resolve
5378 them from the minimal symbols of the main executable first. */
5380 if (symfile_objfile && objfile != symfile_objfile)
5381 resolve_objfile = symfile_objfile;
5383 resolve_objfile = objfile;
5387 /* Avoid expensive loop through all minimal symbols if there are
5388 no unresolved symbols. */
5389 for (hash = 0; hash < HASHSIZE; hash++)
5391 if (global_sym_chain[hash])
5394 if (hash >= HASHSIZE)
5397 for (msymbol = resolve_objfile->msymbols;
5398 msymbol && SYMBOL_NAME (msymbol) != NULL;
5403 /* Skip static symbols. */
5404 switch (MSYMBOL_TYPE (msymbol))
5416 /* Get the hash index and check all the symbols
5417 under that hash index. */
5419 hash = hashname (SYMBOL_NAME (msymbol));
5421 for (sym = global_sym_chain[hash]; sym;)
5423 if (SYMBOL_NAME (msymbol)[0] == SYMBOL_NAME (sym)[0] &&
5424 STREQ (SYMBOL_NAME (msymbol) + 1, SYMBOL_NAME (sym) + 1))
5427 struct alias_list *aliases;
5429 /* Splice this symbol out of the hash chain and
5430 assign the value we have to it. */
5433 SYMBOL_VALUE_CHAIN (prev) = SYMBOL_VALUE_CHAIN (sym);
5437 global_sym_chain[hash] = SYMBOL_VALUE_CHAIN (sym);
5440 /* Check to see whether we need to fix up a common block. */
5441 /* Note: this code might be executed several times for
5442 the same symbol if there are multiple references. */
5444 /* If symbol has aliases, do minimal symbol fixups for each.
5445 These live aliases/references weren't added to
5446 global_sym_chain hash but may also need to be fixed up. */
5447 /* FIXME: Maybe should have added aliases to the global chain, resolved symbol name, then treated aliases as normal
5448 symbols? Still, we wouldn't want to add_to_list. */
5449 /* Now do the same for each alias of this symbol */
5451 aliases = SYMBOL_ALIASES (sym);
5454 if (SYMBOL_CLASS (rsym) == LOC_BLOCK)
5456 fix_common_block (rsym,
5457 SYMBOL_VALUE_ADDRESS (msymbol));
5461 SYMBOL_VALUE_ADDRESS (rsym)
5462 = SYMBOL_VALUE_ADDRESS (msymbol);
5464 SYMBOL_SECTION (rsym) = SYMBOL_SECTION (msymbol);
5467 rsym = aliases->sym;
5468 aliases = aliases->next;
5477 sym = SYMBOL_VALUE_CHAIN (prev);
5481 sym = global_sym_chain[hash];
5487 sym = SYMBOL_VALUE_CHAIN (sym);
5491 if (resolve_objfile == objfile)
5493 resolve_objfile = objfile;
5496 /* Change the storage class of any remaining unresolved globals to
5497 LOC_UNRESOLVED and remove them from the chain. */
5498 for (hash = 0; hash < HASHSIZE; hash++)
5500 sym = global_sym_chain[hash];
5504 sym = SYMBOL_VALUE_CHAIN (sym);
5506 /* Change the symbol address from the misleading chain value
5508 SYMBOL_VALUE_ADDRESS (prev) = 0;
5510 /* Complain about unresolved common block symbols. */
5511 if (SYMBOL_CLASS (prev) == LOC_STATIC)
5512 SYMBOL_CLASS (prev) = LOC_UNRESOLVED;
5514 complaint (&symfile_complaints,
5515 "%s: common block `%s' from global_sym_chain unresolved",
5516 objfile->name, SYMBOL_NAME (prev));
5519 memset (global_sym_chain, 0, sizeof (global_sym_chain));
5522 /* Initialize anything that needs initializing when starting to read
5523 a fresh piece of a symbol file, e.g. reading in the stuff corresponding
5527 stabsread_init (void)
5531 /* Initialize anything that needs initializing when a completely new
5532 symbol file is specified (not just adding some symbols from another
5533 file, e.g. a shared library). */
5536 stabsread_new_init (void)
5538 /* Empty the hash table of global syms looking for values. */
5539 memset (global_sym_chain, 0, sizeof (global_sym_chain));
5542 /* Initialize anything that needs initializing at the same time as
5543 start_symtab() is called. */
5548 global_stabs = NULL; /* AIX COFF */
5549 /* Leave FILENUM of 0 free for builtin types and this file's types. */
5550 n_this_object_header_files = 1;
5551 type_vector_length = 0;
5552 type_vector = (struct type **) 0;
5554 /* FIXME: If common_block_name is not already NULL, we should complain(). */
5555 common_block_name = NULL;
5557 #if 0 /* OBSOLETE OS9K */
5558 // OBSOLETE os9k_stabs = 0;
5559 #endif /* OBSOLETE OS9K */
5562 /* Call after end_symtab() */
5569 xfree (type_vector);
5572 type_vector_length = 0;
5573 previous_stab_code = 0;
5577 finish_global_stabs (struct objfile *objfile)
5581 patch_block_stabs (global_symbols, global_stabs, objfile);
5582 xfree (global_stabs);
5583 global_stabs = NULL;
5587 /* Find the end of the name, delimited by a ':', but don't match
5588 ObjC symbols which look like -[Foo bar::]:bla. */
5590 find_name_end (char *name)
5593 if (s[0] == '-' || *s == '+')
5595 /* Must be an ObjC method symbol. */
5598 error ("invalid symbol name \"%s\"", name);
5600 s = strchr (s, ']');
5603 error ("invalid symbol name \"%s\"", name);
5605 return strchr (s, ':');
5609 return strchr (s, ':');
5613 /* Initializer for this module */
5616 _initialize_stabsread (void)
5618 undef_types_allocated = 20;
5619 undef_types_length = 0;
5620 undef_types = (struct type **)
5621 xmalloc (undef_types_allocated * sizeof (struct type *));