15796c8dcSSimon Schubert /* Support routines for decoding "stabs" debugging information format.
25796c8dcSSimon Schubert
3*ef5ccd6cSJohn Marino Copyright (C) 1986-2013 Free Software Foundation, Inc.
45796c8dcSSimon Schubert
55796c8dcSSimon Schubert This file is part of GDB.
65796c8dcSSimon Schubert
75796c8dcSSimon Schubert This program is free software; you can redistribute it and/or modify
85796c8dcSSimon Schubert it under the terms of the GNU General Public License as published by
95796c8dcSSimon Schubert the Free Software Foundation; either version 3 of the License, or
105796c8dcSSimon Schubert (at your option) any later version.
115796c8dcSSimon Schubert
125796c8dcSSimon Schubert This program is distributed in the hope that it will be useful,
135796c8dcSSimon Schubert but WITHOUT ANY WARRANTY; without even the implied warranty of
145796c8dcSSimon Schubert MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
155796c8dcSSimon Schubert GNU General Public License for more details.
165796c8dcSSimon Schubert
175796c8dcSSimon Schubert You should have received a copy of the GNU General Public License
185796c8dcSSimon Schubert along with this program. If not, see <http://www.gnu.org/licenses/>. */
195796c8dcSSimon Schubert
205796c8dcSSimon Schubert /* Support routines for reading and decoding debugging information in
215796c8dcSSimon Schubert the "stabs" format. This format is used with many systems that use
225796c8dcSSimon Schubert the a.out object file format, as well as some systems that use
235796c8dcSSimon Schubert COFF or ELF where the stabs data is placed in a special section.
245796c8dcSSimon Schubert Avoid placing any object file format specific code in this file. */
255796c8dcSSimon Schubert
265796c8dcSSimon Schubert #include "defs.h"
275796c8dcSSimon Schubert #include "gdb_string.h"
285796c8dcSSimon Schubert #include "bfd.h"
295796c8dcSSimon Schubert #include "gdb_obstack.h"
305796c8dcSSimon Schubert #include "symtab.h"
315796c8dcSSimon Schubert #include "gdbtypes.h"
325796c8dcSSimon Schubert #include "expression.h"
335796c8dcSSimon Schubert #include "symfile.h"
345796c8dcSSimon Schubert #include "objfiles.h"
35c50c785cSJohn Marino #include "aout/stab_gnu.h" /* We always use GNU stabs, not native. */
365796c8dcSSimon Schubert #include "libaout.h"
375796c8dcSSimon Schubert #include "aout/aout64.h"
385796c8dcSSimon Schubert #include "gdb-stabs.h"
395796c8dcSSimon Schubert #include "buildsym.h"
405796c8dcSSimon Schubert #include "complaints.h"
415796c8dcSSimon Schubert #include "demangle.h"
42a45ae5f8SJohn Marino #include "gdb-demangle.h"
435796c8dcSSimon Schubert #include "language.h"
445796c8dcSSimon Schubert #include "doublest.h"
455796c8dcSSimon Schubert #include "cp-abi.h"
465796c8dcSSimon Schubert #include "cp-support.h"
475796c8dcSSimon Schubert #include "gdb_assert.h"
485796c8dcSSimon Schubert
495796c8dcSSimon Schubert #include <ctype.h>
505796c8dcSSimon Schubert
515796c8dcSSimon Schubert /* Ask stabsread.h to define the vars it normally declares `extern'. */
525796c8dcSSimon Schubert #define EXTERN
535796c8dcSSimon Schubert /**/
545796c8dcSSimon Schubert #include "stabsread.h" /* Our own declarations */
555796c8dcSSimon Schubert #undef EXTERN
565796c8dcSSimon Schubert
575796c8dcSSimon Schubert extern void _initialize_stabsread (void);
585796c8dcSSimon Schubert
595796c8dcSSimon Schubert /* The routines that read and process a complete stabs for a C struct or
605796c8dcSSimon Schubert C++ class pass lists of data member fields and lists of member function
615796c8dcSSimon Schubert fields in an instance of a field_info structure, as defined below.
625796c8dcSSimon Schubert This is part of some reorganization of low level C++ support and is
635796c8dcSSimon Schubert expected to eventually go away... (FIXME) */
645796c8dcSSimon Schubert
655796c8dcSSimon Schubert struct field_info
665796c8dcSSimon Schubert {
675796c8dcSSimon Schubert struct nextfield
685796c8dcSSimon Schubert {
695796c8dcSSimon Schubert struct nextfield *next;
705796c8dcSSimon Schubert
715796c8dcSSimon Schubert /* This is the raw visibility from the stab. It is not checked
725796c8dcSSimon Schubert for being one of the visibilities we recognize, so code which
735796c8dcSSimon Schubert examines this field better be able to deal. */
745796c8dcSSimon Schubert int visibility;
755796c8dcSSimon Schubert
765796c8dcSSimon Schubert struct field field;
775796c8dcSSimon Schubert }
785796c8dcSSimon Schubert *list;
795796c8dcSSimon Schubert struct next_fnfieldlist
805796c8dcSSimon Schubert {
815796c8dcSSimon Schubert struct next_fnfieldlist *next;
825796c8dcSSimon Schubert struct fn_fieldlist fn_fieldlist;
835796c8dcSSimon Schubert }
845796c8dcSSimon Schubert *fnlist;
855796c8dcSSimon Schubert };
865796c8dcSSimon Schubert
875796c8dcSSimon Schubert static void
885796c8dcSSimon Schubert read_one_struct_field (struct field_info *, char **, char *,
895796c8dcSSimon Schubert struct type *, struct objfile *);
905796c8dcSSimon Schubert
915796c8dcSSimon Schubert static struct type *dbx_alloc_type (int[2], struct objfile *);
925796c8dcSSimon Schubert
935796c8dcSSimon Schubert static long read_huge_number (char **, int, int *, int);
945796c8dcSSimon Schubert
955796c8dcSSimon Schubert static struct type *error_type (char **, struct objfile *);
965796c8dcSSimon Schubert
975796c8dcSSimon Schubert static void
985796c8dcSSimon Schubert patch_block_stabs (struct pending *, struct pending_stabs *,
995796c8dcSSimon Schubert struct objfile *);
1005796c8dcSSimon Schubert
101*ef5ccd6cSJohn Marino static void fix_common_block (struct symbol *, CORE_ADDR);
1025796c8dcSSimon Schubert
1035796c8dcSSimon Schubert static int read_type_number (char **, int *);
1045796c8dcSSimon Schubert
1055796c8dcSSimon Schubert static struct type *read_type (char **, struct objfile *);
1065796c8dcSSimon Schubert
1075796c8dcSSimon Schubert static struct type *read_range_type (char **, int[2], int, struct objfile *);
1085796c8dcSSimon Schubert
1095796c8dcSSimon Schubert static struct type *read_sun_builtin_type (char **, int[2], struct objfile *);
1105796c8dcSSimon Schubert
1115796c8dcSSimon Schubert static struct type *read_sun_floating_type (char **, int[2],
1125796c8dcSSimon Schubert struct objfile *);
1135796c8dcSSimon Schubert
1145796c8dcSSimon Schubert static struct type *read_enum_type (char **, struct type *, struct objfile *);
1155796c8dcSSimon Schubert
1165796c8dcSSimon Schubert static struct type *rs6000_builtin_type (int, struct objfile *);
1175796c8dcSSimon Schubert
1185796c8dcSSimon Schubert static int
1195796c8dcSSimon Schubert read_member_functions (struct field_info *, char **, struct type *,
1205796c8dcSSimon Schubert struct objfile *);
1215796c8dcSSimon Schubert
1225796c8dcSSimon Schubert static int
1235796c8dcSSimon Schubert read_struct_fields (struct field_info *, char **, struct type *,
1245796c8dcSSimon Schubert struct objfile *);
1255796c8dcSSimon Schubert
1265796c8dcSSimon Schubert static int
1275796c8dcSSimon Schubert read_baseclasses (struct field_info *, char **, struct type *,
1285796c8dcSSimon Schubert struct objfile *);
1295796c8dcSSimon Schubert
1305796c8dcSSimon Schubert static int
1315796c8dcSSimon Schubert read_tilde_fields (struct field_info *, char **, struct type *,
1325796c8dcSSimon Schubert struct objfile *);
1335796c8dcSSimon Schubert
1345796c8dcSSimon Schubert static int attach_fn_fields_to_type (struct field_info *, struct type *);
1355796c8dcSSimon Schubert
1365796c8dcSSimon Schubert static int attach_fields_to_type (struct field_info *, struct type *,
1375796c8dcSSimon Schubert struct objfile *);
1385796c8dcSSimon Schubert
1395796c8dcSSimon Schubert static struct type *read_struct_type (char **, struct type *,
1405796c8dcSSimon Schubert enum type_code,
1415796c8dcSSimon Schubert struct objfile *);
1425796c8dcSSimon Schubert
1435796c8dcSSimon Schubert static struct type *read_array_type (char **, struct type *,
1445796c8dcSSimon Schubert struct objfile *);
1455796c8dcSSimon Schubert
1465796c8dcSSimon Schubert static struct field *read_args (char **, int, struct objfile *, int *, int *);
1475796c8dcSSimon Schubert
1485796c8dcSSimon Schubert static void add_undefined_type (struct type *, int[2]);
1495796c8dcSSimon Schubert
1505796c8dcSSimon Schubert static int
1515796c8dcSSimon Schubert read_cpp_abbrev (struct field_info *, char **, struct type *,
1525796c8dcSSimon Schubert struct objfile *);
1535796c8dcSSimon Schubert
1545796c8dcSSimon Schubert static char *find_name_end (char *name);
1555796c8dcSSimon Schubert
1565796c8dcSSimon Schubert static int process_reference (char **string);
1575796c8dcSSimon Schubert
1585796c8dcSSimon Schubert void stabsread_clear_cache (void);
1595796c8dcSSimon Schubert
1605796c8dcSSimon Schubert static const char vptr_name[] = "_vptr$";
1615796c8dcSSimon Schubert static const char vb_name[] = "_vb$";
1625796c8dcSSimon Schubert
1635796c8dcSSimon Schubert static void
invalid_cpp_abbrev_complaint(const char * arg1)1645796c8dcSSimon Schubert invalid_cpp_abbrev_complaint (const char *arg1)
1655796c8dcSSimon Schubert {
1665796c8dcSSimon Schubert complaint (&symfile_complaints, _("invalid C++ abbreviation `%s'"), arg1);
1675796c8dcSSimon Schubert }
1685796c8dcSSimon Schubert
1695796c8dcSSimon Schubert static void
reg_value_complaint(int regnum,int num_regs,const char * sym)1705796c8dcSSimon Schubert reg_value_complaint (int regnum, int num_regs, const char *sym)
1715796c8dcSSimon Schubert {
1725796c8dcSSimon Schubert complaint (&symfile_complaints,
1735796c8dcSSimon Schubert _("register number %d too large (max %d) in symbol %s"),
1745796c8dcSSimon Schubert regnum, num_regs - 1, sym);
1755796c8dcSSimon Schubert }
1765796c8dcSSimon Schubert
1775796c8dcSSimon Schubert static void
stabs_general_complaint(const char * arg1)1785796c8dcSSimon Schubert stabs_general_complaint (const char *arg1)
1795796c8dcSSimon Schubert {
1805796c8dcSSimon Schubert complaint (&symfile_complaints, "%s", arg1);
1815796c8dcSSimon Schubert }
1825796c8dcSSimon Schubert
1835796c8dcSSimon Schubert /* Make a list of forward references which haven't been defined. */
1845796c8dcSSimon Schubert
1855796c8dcSSimon Schubert static struct type **undef_types;
1865796c8dcSSimon Schubert static int undef_types_allocated;
1875796c8dcSSimon Schubert static int undef_types_length;
1885796c8dcSSimon Schubert static struct symbol *current_symbol = NULL;
1895796c8dcSSimon Schubert
1905796c8dcSSimon Schubert /* Make a list of nameless types that are undefined.
1915796c8dcSSimon Schubert This happens when another type is referenced by its number
1925796c8dcSSimon Schubert before this type is actually defined. For instance "t(0,1)=k(0,2)"
1935796c8dcSSimon Schubert and type (0,2) is defined only later. */
1945796c8dcSSimon Schubert
1955796c8dcSSimon Schubert struct nat
1965796c8dcSSimon Schubert {
1975796c8dcSSimon Schubert int typenums[2];
1985796c8dcSSimon Schubert struct type *type;
1995796c8dcSSimon Schubert };
2005796c8dcSSimon Schubert static struct nat *noname_undefs;
2015796c8dcSSimon Schubert static int noname_undefs_allocated;
2025796c8dcSSimon Schubert static int noname_undefs_length;
2035796c8dcSSimon Schubert
2045796c8dcSSimon Schubert /* Check for and handle cretinous stabs symbol name continuation! */
2055796c8dcSSimon Schubert #define STABS_CONTINUE(pp,objfile) \
2065796c8dcSSimon Schubert do { \
2075796c8dcSSimon Schubert if (**(pp) == '\\' || (**(pp) == '?' && (*(pp))[1] == '\0')) \
2085796c8dcSSimon Schubert *(pp) = next_symbol_text (objfile); \
2095796c8dcSSimon Schubert } while (0)
2105796c8dcSSimon Schubert
2115796c8dcSSimon Schubert
2125796c8dcSSimon Schubert /* Look up a dbx type-number pair. Return the address of the slot
2135796c8dcSSimon Schubert where the type for that number-pair is stored.
2145796c8dcSSimon Schubert The number-pair is in TYPENUMS.
2155796c8dcSSimon Schubert
2165796c8dcSSimon Schubert This can be used for finding the type associated with that pair
2175796c8dcSSimon Schubert or for associating a new type with the pair. */
2185796c8dcSSimon Schubert
2195796c8dcSSimon Schubert static struct type **
dbx_lookup_type(int typenums[2],struct objfile * objfile)2205796c8dcSSimon Schubert dbx_lookup_type (int typenums[2], struct objfile *objfile)
2215796c8dcSSimon Schubert {
2225796c8dcSSimon Schubert int filenum = typenums[0];
2235796c8dcSSimon Schubert int index = typenums[1];
2245796c8dcSSimon Schubert unsigned old_len;
2255796c8dcSSimon Schubert int real_filenum;
2265796c8dcSSimon Schubert struct header_file *f;
2275796c8dcSSimon Schubert int f_orig_length;
2285796c8dcSSimon Schubert
2295796c8dcSSimon Schubert if (filenum == -1) /* -1,-1 is for temporary types. */
2305796c8dcSSimon Schubert return 0;
2315796c8dcSSimon Schubert
2325796c8dcSSimon Schubert if (filenum < 0 || filenum >= n_this_object_header_files)
2335796c8dcSSimon Schubert {
2345796c8dcSSimon Schubert complaint (&symfile_complaints,
235c50c785cSJohn Marino _("Invalid symbol data: type number "
236c50c785cSJohn Marino "(%d,%d) out of range at symtab pos %d."),
2375796c8dcSSimon Schubert filenum, index, symnum);
2385796c8dcSSimon Schubert goto error_return;
2395796c8dcSSimon Schubert }
2405796c8dcSSimon Schubert
2415796c8dcSSimon Schubert if (filenum == 0)
2425796c8dcSSimon Schubert {
2435796c8dcSSimon Schubert if (index < 0)
2445796c8dcSSimon Schubert {
2455796c8dcSSimon Schubert /* Caller wants address of address of type. We think
2465796c8dcSSimon Schubert that negative (rs6k builtin) types will never appear as
2475796c8dcSSimon Schubert "lvalues", (nor should they), so we stuff the real type
2485796c8dcSSimon Schubert pointer into a temp, and return its address. If referenced,
2495796c8dcSSimon Schubert this will do the right thing. */
2505796c8dcSSimon Schubert static struct type *temp_type;
2515796c8dcSSimon Schubert
2525796c8dcSSimon Schubert temp_type = rs6000_builtin_type (index, objfile);
2535796c8dcSSimon Schubert return &temp_type;
2545796c8dcSSimon Schubert }
2555796c8dcSSimon Schubert
2565796c8dcSSimon Schubert /* Type is defined outside of header files.
2575796c8dcSSimon Schubert Find it in this object file's type vector. */
2585796c8dcSSimon Schubert if (index >= type_vector_length)
2595796c8dcSSimon Schubert {
2605796c8dcSSimon Schubert old_len = type_vector_length;
2615796c8dcSSimon Schubert if (old_len == 0)
2625796c8dcSSimon Schubert {
2635796c8dcSSimon Schubert type_vector_length = INITIAL_TYPE_VECTOR_LENGTH;
2645796c8dcSSimon Schubert type_vector = (struct type **)
2655796c8dcSSimon Schubert xmalloc (type_vector_length * sizeof (struct type *));
2665796c8dcSSimon Schubert }
2675796c8dcSSimon Schubert while (index >= type_vector_length)
2685796c8dcSSimon Schubert {
2695796c8dcSSimon Schubert type_vector_length *= 2;
2705796c8dcSSimon Schubert }
2715796c8dcSSimon Schubert type_vector = (struct type **)
2725796c8dcSSimon Schubert xrealloc ((char *) type_vector,
2735796c8dcSSimon Schubert (type_vector_length * sizeof (struct type *)));
2745796c8dcSSimon Schubert memset (&type_vector[old_len], 0,
2755796c8dcSSimon Schubert (type_vector_length - old_len) * sizeof (struct type *));
2765796c8dcSSimon Schubert }
2775796c8dcSSimon Schubert return (&type_vector[index]);
2785796c8dcSSimon Schubert }
2795796c8dcSSimon Schubert else
2805796c8dcSSimon Schubert {
2815796c8dcSSimon Schubert real_filenum = this_object_header_files[filenum];
2825796c8dcSSimon Schubert
2835796c8dcSSimon Schubert if (real_filenum >= N_HEADER_FILES (objfile))
2845796c8dcSSimon Schubert {
2855796c8dcSSimon Schubert static struct type *temp_type;
2865796c8dcSSimon Schubert
2875796c8dcSSimon Schubert warning (_("GDB internal error: bad real_filenum"));
2885796c8dcSSimon Schubert
2895796c8dcSSimon Schubert error_return:
2905796c8dcSSimon Schubert temp_type = objfile_type (objfile)->builtin_error;
2915796c8dcSSimon Schubert return &temp_type;
2925796c8dcSSimon Schubert }
2935796c8dcSSimon Schubert
2945796c8dcSSimon Schubert f = HEADER_FILES (objfile) + real_filenum;
2955796c8dcSSimon Schubert
2965796c8dcSSimon Schubert f_orig_length = f->length;
2975796c8dcSSimon Schubert if (index >= f_orig_length)
2985796c8dcSSimon Schubert {
2995796c8dcSSimon Schubert while (index >= f->length)
3005796c8dcSSimon Schubert {
3015796c8dcSSimon Schubert f->length *= 2;
3025796c8dcSSimon Schubert }
3035796c8dcSSimon Schubert f->vector = (struct type **)
3045796c8dcSSimon Schubert xrealloc ((char *) f->vector, f->length * sizeof (struct type *));
3055796c8dcSSimon Schubert memset (&f->vector[f_orig_length], 0,
3065796c8dcSSimon Schubert (f->length - f_orig_length) * sizeof (struct type *));
3075796c8dcSSimon Schubert }
3085796c8dcSSimon Schubert return (&f->vector[index]);
3095796c8dcSSimon Schubert }
3105796c8dcSSimon Schubert }
3115796c8dcSSimon Schubert
3125796c8dcSSimon Schubert /* Make sure there is a type allocated for type numbers TYPENUMS
3135796c8dcSSimon Schubert and return the type object.
3145796c8dcSSimon Schubert This can create an empty (zeroed) type object.
3155796c8dcSSimon Schubert TYPENUMS may be (-1, -1) to return a new type object that is not
3165796c8dcSSimon Schubert put into the type vector, and so may not be referred to by number. */
3175796c8dcSSimon Schubert
3185796c8dcSSimon Schubert static struct type *
dbx_alloc_type(int typenums[2],struct objfile * objfile)3195796c8dcSSimon Schubert dbx_alloc_type (int typenums[2], struct objfile *objfile)
3205796c8dcSSimon Schubert {
3215796c8dcSSimon Schubert struct type **type_addr;
3225796c8dcSSimon Schubert
3235796c8dcSSimon Schubert if (typenums[0] == -1)
3245796c8dcSSimon Schubert {
3255796c8dcSSimon Schubert return (alloc_type (objfile));
3265796c8dcSSimon Schubert }
3275796c8dcSSimon Schubert
3285796c8dcSSimon Schubert type_addr = dbx_lookup_type (typenums, objfile);
3295796c8dcSSimon Schubert
3305796c8dcSSimon Schubert /* If we are referring to a type not known at all yet,
3315796c8dcSSimon Schubert allocate an empty type for it.
3325796c8dcSSimon Schubert We will fill it in later if we find out how. */
3335796c8dcSSimon Schubert if (*type_addr == 0)
3345796c8dcSSimon Schubert {
3355796c8dcSSimon Schubert *type_addr = alloc_type (objfile);
3365796c8dcSSimon Schubert }
3375796c8dcSSimon Schubert
3385796c8dcSSimon Schubert return (*type_addr);
3395796c8dcSSimon Schubert }
3405796c8dcSSimon Schubert
3415796c8dcSSimon Schubert /* for all the stabs in a given stab vector, build appropriate types
3425796c8dcSSimon Schubert and fix their symbols in given symbol vector. */
3435796c8dcSSimon Schubert
3445796c8dcSSimon Schubert static void
patch_block_stabs(struct pending * symbols,struct pending_stabs * stabs,struct objfile * objfile)3455796c8dcSSimon Schubert patch_block_stabs (struct pending *symbols, struct pending_stabs *stabs,
3465796c8dcSSimon Schubert struct objfile *objfile)
3475796c8dcSSimon Schubert {
3485796c8dcSSimon Schubert int ii;
3495796c8dcSSimon Schubert char *name;
3505796c8dcSSimon Schubert char *pp;
3515796c8dcSSimon Schubert struct symbol *sym;
3525796c8dcSSimon Schubert
3535796c8dcSSimon Schubert if (stabs)
3545796c8dcSSimon Schubert {
3555796c8dcSSimon Schubert /* for all the stab entries, find their corresponding symbols and
3565796c8dcSSimon Schubert patch their types! */
3575796c8dcSSimon Schubert
3585796c8dcSSimon Schubert for (ii = 0; ii < stabs->count; ++ii)
3595796c8dcSSimon Schubert {
3605796c8dcSSimon Schubert name = stabs->stab[ii];
3615796c8dcSSimon Schubert pp = (char *) strchr (name, ':');
3625796c8dcSSimon Schubert gdb_assert (pp); /* Must find a ':' or game's over. */
3635796c8dcSSimon Schubert while (pp[1] == ':')
3645796c8dcSSimon Schubert {
3655796c8dcSSimon Schubert pp += 2;
3665796c8dcSSimon Schubert pp = (char *) strchr (pp, ':');
3675796c8dcSSimon Schubert }
3685796c8dcSSimon Schubert sym = find_symbol_in_list (symbols, name, pp - name);
3695796c8dcSSimon Schubert if (!sym)
3705796c8dcSSimon Schubert {
3715796c8dcSSimon Schubert /* FIXME-maybe: it would be nice if we noticed whether
3725796c8dcSSimon Schubert the variable was defined *anywhere*, not just whether
3735796c8dcSSimon Schubert it is defined in this compilation unit. But neither
3745796c8dcSSimon Schubert xlc or GCC seem to need such a definition, and until
3755796c8dcSSimon Schubert we do psymtabs (so that the minimal symbols from all
3765796c8dcSSimon Schubert compilation units are available now), I'm not sure
3775796c8dcSSimon Schubert how to get the information. */
3785796c8dcSSimon Schubert
3795796c8dcSSimon Schubert /* On xcoff, if a global is defined and never referenced,
3805796c8dcSSimon Schubert ld will remove it from the executable. There is then
3815796c8dcSSimon Schubert a N_GSYM stab for it, but no regular (C_EXT) symbol. */
3825796c8dcSSimon Schubert sym = (struct symbol *)
3835796c8dcSSimon Schubert obstack_alloc (&objfile->objfile_obstack,
3845796c8dcSSimon Schubert sizeof (struct symbol));
3855796c8dcSSimon Schubert
3865796c8dcSSimon Schubert memset (sym, 0, sizeof (struct symbol));
3875796c8dcSSimon Schubert SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
3885796c8dcSSimon Schubert SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
3895796c8dcSSimon Schubert SYMBOL_SET_LINKAGE_NAME
390*ef5ccd6cSJohn Marino (sym, obstack_copy0 (&objfile->objfile_obstack,
391*ef5ccd6cSJohn Marino name, pp - name));
3925796c8dcSSimon Schubert pp += 2;
3935796c8dcSSimon Schubert if (*(pp - 1) == 'F' || *(pp - 1) == 'f')
3945796c8dcSSimon Schubert {
3955796c8dcSSimon Schubert /* I don't think the linker does this with functions,
3965796c8dcSSimon Schubert so as far as I know this is never executed.
3975796c8dcSSimon Schubert But it doesn't hurt to check. */
3985796c8dcSSimon Schubert SYMBOL_TYPE (sym) =
3995796c8dcSSimon Schubert lookup_function_type (read_type (&pp, objfile));
4005796c8dcSSimon Schubert }
4015796c8dcSSimon Schubert else
4025796c8dcSSimon Schubert {
4035796c8dcSSimon Schubert SYMBOL_TYPE (sym) = read_type (&pp, objfile);
4045796c8dcSSimon Schubert }
4055796c8dcSSimon Schubert add_symbol_to_list (sym, &global_symbols);
4065796c8dcSSimon Schubert }
4075796c8dcSSimon Schubert else
4085796c8dcSSimon Schubert {
4095796c8dcSSimon Schubert pp += 2;
4105796c8dcSSimon Schubert if (*(pp - 1) == 'F' || *(pp - 1) == 'f')
4115796c8dcSSimon Schubert {
4125796c8dcSSimon Schubert SYMBOL_TYPE (sym) =
4135796c8dcSSimon Schubert lookup_function_type (read_type (&pp, objfile));
4145796c8dcSSimon Schubert }
4155796c8dcSSimon Schubert else
4165796c8dcSSimon Schubert {
4175796c8dcSSimon Schubert SYMBOL_TYPE (sym) = read_type (&pp, objfile);
4185796c8dcSSimon Schubert }
4195796c8dcSSimon Schubert }
4205796c8dcSSimon Schubert }
4215796c8dcSSimon Schubert }
4225796c8dcSSimon Schubert }
4235796c8dcSSimon Schubert
4245796c8dcSSimon Schubert
4255796c8dcSSimon Schubert /* Read a number by which a type is referred to in dbx data,
4265796c8dcSSimon Schubert or perhaps read a pair (FILENUM, TYPENUM) in parentheses.
4275796c8dcSSimon Schubert Just a single number N is equivalent to (0,N).
4285796c8dcSSimon Schubert Return the two numbers by storing them in the vector TYPENUMS.
4295796c8dcSSimon Schubert TYPENUMS will then be used as an argument to dbx_lookup_type.
4305796c8dcSSimon Schubert
4315796c8dcSSimon Schubert Returns 0 for success, -1 for error. */
4325796c8dcSSimon Schubert
4335796c8dcSSimon Schubert static int
read_type_number(char ** pp,int * typenums)4345796c8dcSSimon Schubert read_type_number (char **pp, int *typenums)
4355796c8dcSSimon Schubert {
4365796c8dcSSimon Schubert int nbits;
437cf7f2e2dSJohn Marino
4385796c8dcSSimon Schubert if (**pp == '(')
4395796c8dcSSimon Schubert {
4405796c8dcSSimon Schubert (*pp)++;
4415796c8dcSSimon Schubert typenums[0] = read_huge_number (pp, ',', &nbits, 0);
4425796c8dcSSimon Schubert if (nbits != 0)
4435796c8dcSSimon Schubert return -1;
4445796c8dcSSimon Schubert typenums[1] = read_huge_number (pp, ')', &nbits, 0);
4455796c8dcSSimon Schubert if (nbits != 0)
4465796c8dcSSimon Schubert return -1;
4475796c8dcSSimon Schubert }
4485796c8dcSSimon Schubert else
4495796c8dcSSimon Schubert {
4505796c8dcSSimon Schubert typenums[0] = 0;
4515796c8dcSSimon Schubert typenums[1] = read_huge_number (pp, 0, &nbits, 0);
4525796c8dcSSimon Schubert if (nbits != 0)
4535796c8dcSSimon Schubert return -1;
4545796c8dcSSimon Schubert }
4555796c8dcSSimon Schubert return 0;
4565796c8dcSSimon Schubert }
4575796c8dcSSimon Schubert
4585796c8dcSSimon Schubert
4595796c8dcSSimon Schubert #define VISIBILITY_PRIVATE '0' /* Stabs character for private field */
4605796c8dcSSimon Schubert #define VISIBILITY_PROTECTED '1' /* Stabs character for protected fld */
4615796c8dcSSimon Schubert #define VISIBILITY_PUBLIC '2' /* Stabs character for public field */
4625796c8dcSSimon Schubert #define VISIBILITY_IGNORE '9' /* Optimized out or zero length */
4635796c8dcSSimon Schubert
4645796c8dcSSimon Schubert /* Structure for storing pointers to reference definitions for fast lookup
4655796c8dcSSimon Schubert during "process_later". */
4665796c8dcSSimon Schubert
4675796c8dcSSimon Schubert struct ref_map
4685796c8dcSSimon Schubert {
4695796c8dcSSimon Schubert char *stabs;
4705796c8dcSSimon Schubert CORE_ADDR value;
4715796c8dcSSimon Schubert struct symbol *sym;
4725796c8dcSSimon Schubert };
4735796c8dcSSimon Schubert
4745796c8dcSSimon Schubert #define MAX_CHUNK_REFS 100
4755796c8dcSSimon Schubert #define REF_CHUNK_SIZE (MAX_CHUNK_REFS * sizeof (struct ref_map))
4765796c8dcSSimon Schubert #define REF_MAP_SIZE(ref_chunk) ((ref_chunk) * REF_CHUNK_SIZE)
4775796c8dcSSimon Schubert
4785796c8dcSSimon Schubert static struct ref_map *ref_map;
4795796c8dcSSimon Schubert
4805796c8dcSSimon Schubert /* Ptr to free cell in chunk's linked list. */
4815796c8dcSSimon Schubert static int ref_count = 0;
4825796c8dcSSimon Schubert
4835796c8dcSSimon Schubert /* Number of chunks malloced. */
4845796c8dcSSimon Schubert static int ref_chunk = 0;
4855796c8dcSSimon Schubert
4865796c8dcSSimon Schubert /* This file maintains a cache of stabs aliases found in the symbol
4875796c8dcSSimon Schubert table. If the symbol table changes, this cache must be cleared
4885796c8dcSSimon Schubert or we are left holding onto data in invalid obstacks. */
4895796c8dcSSimon Schubert void
stabsread_clear_cache(void)4905796c8dcSSimon Schubert stabsread_clear_cache (void)
4915796c8dcSSimon Schubert {
4925796c8dcSSimon Schubert ref_count = 0;
4935796c8dcSSimon Schubert ref_chunk = 0;
4945796c8dcSSimon Schubert }
4955796c8dcSSimon Schubert
4965796c8dcSSimon Schubert /* Create array of pointers mapping refids to symbols and stab strings.
4975796c8dcSSimon Schubert Add pointers to reference definition symbols and/or their values as we
4985796c8dcSSimon Schubert find them, using their reference numbers as our index.
4995796c8dcSSimon Schubert These will be used later when we resolve references. */
5005796c8dcSSimon Schubert void
ref_add(int refnum,struct symbol * sym,char * stabs,CORE_ADDR value)5015796c8dcSSimon Schubert ref_add (int refnum, struct symbol *sym, char *stabs, CORE_ADDR value)
5025796c8dcSSimon Schubert {
5035796c8dcSSimon Schubert if (ref_count == 0)
5045796c8dcSSimon Schubert ref_chunk = 0;
5055796c8dcSSimon Schubert if (refnum >= ref_count)
5065796c8dcSSimon Schubert ref_count = refnum + 1;
5075796c8dcSSimon Schubert if (ref_count > ref_chunk * MAX_CHUNK_REFS)
5085796c8dcSSimon Schubert {
5095796c8dcSSimon Schubert int new_slots = ref_count - ref_chunk * MAX_CHUNK_REFS;
5105796c8dcSSimon Schubert int new_chunks = new_slots / MAX_CHUNK_REFS + 1;
511cf7f2e2dSJohn Marino
5125796c8dcSSimon Schubert ref_map = (struct ref_map *)
5135796c8dcSSimon Schubert xrealloc (ref_map, REF_MAP_SIZE (ref_chunk + new_chunks));
514cf7f2e2dSJohn Marino memset (ref_map + ref_chunk * MAX_CHUNK_REFS, 0,
515cf7f2e2dSJohn Marino new_chunks * REF_CHUNK_SIZE);
5165796c8dcSSimon Schubert ref_chunk += new_chunks;
5175796c8dcSSimon Schubert }
5185796c8dcSSimon Schubert ref_map[refnum].stabs = stabs;
5195796c8dcSSimon Schubert ref_map[refnum].sym = sym;
5205796c8dcSSimon Schubert ref_map[refnum].value = value;
5215796c8dcSSimon Schubert }
5225796c8dcSSimon Schubert
5235796c8dcSSimon Schubert /* Return defined sym for the reference REFNUM. */
5245796c8dcSSimon Schubert struct symbol *
ref_search(int refnum)5255796c8dcSSimon Schubert ref_search (int refnum)
5265796c8dcSSimon Schubert {
5275796c8dcSSimon Schubert if (refnum < 0 || refnum > ref_count)
5285796c8dcSSimon Schubert return 0;
5295796c8dcSSimon Schubert return ref_map[refnum].sym;
5305796c8dcSSimon Schubert }
5315796c8dcSSimon Schubert
5325796c8dcSSimon Schubert /* Parse a reference id in STRING and return the resulting
5335796c8dcSSimon Schubert reference number. Move STRING beyond the reference id. */
5345796c8dcSSimon Schubert
5355796c8dcSSimon Schubert static int
process_reference(char ** string)5365796c8dcSSimon Schubert process_reference (char **string)
5375796c8dcSSimon Schubert {
5385796c8dcSSimon Schubert char *p;
5395796c8dcSSimon Schubert int refnum = 0;
5405796c8dcSSimon Schubert
5415796c8dcSSimon Schubert if (**string != '#')
5425796c8dcSSimon Schubert return 0;
5435796c8dcSSimon Schubert
5445796c8dcSSimon Schubert /* Advance beyond the initial '#'. */
5455796c8dcSSimon Schubert p = *string + 1;
5465796c8dcSSimon Schubert
5475796c8dcSSimon Schubert /* Read number as reference id. */
5485796c8dcSSimon Schubert while (*p && isdigit (*p))
5495796c8dcSSimon Schubert {
5505796c8dcSSimon Schubert refnum = refnum * 10 + *p - '0';
5515796c8dcSSimon Schubert p++;
5525796c8dcSSimon Schubert }
5535796c8dcSSimon Schubert *string = p;
5545796c8dcSSimon Schubert return refnum;
5555796c8dcSSimon Schubert }
5565796c8dcSSimon Schubert
5575796c8dcSSimon Schubert /* If STRING defines a reference, store away a pointer to the reference
5585796c8dcSSimon Schubert definition for later use. Return the reference number. */
5595796c8dcSSimon Schubert
5605796c8dcSSimon Schubert int
symbol_reference_defined(char ** string)5615796c8dcSSimon Schubert symbol_reference_defined (char **string)
5625796c8dcSSimon Schubert {
5635796c8dcSSimon Schubert char *p = *string;
5645796c8dcSSimon Schubert int refnum = 0;
5655796c8dcSSimon Schubert
5665796c8dcSSimon Schubert refnum = process_reference (&p);
5675796c8dcSSimon Schubert
568c50c785cSJohn Marino /* Defining symbols end in '='. */
5695796c8dcSSimon Schubert if (*p == '=')
5705796c8dcSSimon Schubert {
5715796c8dcSSimon Schubert /* Symbol is being defined here. */
5725796c8dcSSimon Schubert *string = p + 1;
5735796c8dcSSimon Schubert return refnum;
5745796c8dcSSimon Schubert }
5755796c8dcSSimon Schubert else
5765796c8dcSSimon Schubert {
5775796c8dcSSimon Schubert /* Must be a reference. Either the symbol has already been defined,
5785796c8dcSSimon Schubert or this is a forward reference to it. */
5795796c8dcSSimon Schubert *string = p;
5805796c8dcSSimon Schubert return -1;
5815796c8dcSSimon Schubert }
5825796c8dcSSimon Schubert }
5835796c8dcSSimon Schubert
5845796c8dcSSimon Schubert static int
stab_reg_to_regnum(struct symbol * sym,struct gdbarch * gdbarch)5855796c8dcSSimon Schubert stab_reg_to_regnum (struct symbol *sym, struct gdbarch *gdbarch)
5865796c8dcSSimon Schubert {
5875796c8dcSSimon Schubert int regno = gdbarch_stab_reg_to_regnum (gdbarch, SYMBOL_VALUE (sym));
5885796c8dcSSimon Schubert
5895796c8dcSSimon Schubert if (regno >= gdbarch_num_regs (gdbarch)
5905796c8dcSSimon Schubert + gdbarch_num_pseudo_regs (gdbarch))
5915796c8dcSSimon Schubert {
5925796c8dcSSimon Schubert reg_value_complaint (regno,
5935796c8dcSSimon Schubert gdbarch_num_regs (gdbarch)
5945796c8dcSSimon Schubert + gdbarch_num_pseudo_regs (gdbarch),
5955796c8dcSSimon Schubert SYMBOL_PRINT_NAME (sym));
5965796c8dcSSimon Schubert
597c50c785cSJohn Marino regno = gdbarch_sp_regnum (gdbarch); /* Known safe, though useless. */
5985796c8dcSSimon Schubert }
5995796c8dcSSimon Schubert
6005796c8dcSSimon Schubert return regno;
6015796c8dcSSimon Schubert }
6025796c8dcSSimon Schubert
6035796c8dcSSimon Schubert static const struct symbol_register_ops stab_register_funcs = {
6045796c8dcSSimon Schubert stab_reg_to_regnum
6055796c8dcSSimon Schubert };
6065796c8dcSSimon Schubert
6075796c8dcSSimon Schubert struct symbol *
define_symbol(CORE_ADDR valu,char * string,int desc,int type,struct objfile * objfile)6085796c8dcSSimon Schubert define_symbol (CORE_ADDR valu, char *string, int desc, int type,
6095796c8dcSSimon Schubert struct objfile *objfile)
6105796c8dcSSimon Schubert {
6115796c8dcSSimon Schubert struct gdbarch *gdbarch = get_objfile_arch (objfile);
6125796c8dcSSimon Schubert struct symbol *sym;
6135796c8dcSSimon Schubert char *p = (char *) find_name_end (string);
6145796c8dcSSimon Schubert int deftype;
6155796c8dcSSimon Schubert int synonym = 0;
6165796c8dcSSimon Schubert int i;
6175796c8dcSSimon Schubert char *new_name = NULL;
6185796c8dcSSimon Schubert
6195796c8dcSSimon Schubert /* We would like to eliminate nameless symbols, but keep their types.
6205796c8dcSSimon Schubert E.g. stab entry ":t10=*2" should produce a type 10, which is a pointer
6215796c8dcSSimon Schubert to type 2, but, should not create a symbol to address that type. Since
6225796c8dcSSimon Schubert the symbol will be nameless, there is no way any user can refer to it. */
6235796c8dcSSimon Schubert
6245796c8dcSSimon Schubert int nameless;
6255796c8dcSSimon Schubert
6265796c8dcSSimon Schubert /* Ignore syms with empty names. */
6275796c8dcSSimon Schubert if (string[0] == 0)
6285796c8dcSSimon Schubert return 0;
6295796c8dcSSimon Schubert
630c50c785cSJohn Marino /* Ignore old-style symbols from cc -go. */
6315796c8dcSSimon Schubert if (p == 0)
6325796c8dcSSimon Schubert return 0;
6335796c8dcSSimon Schubert
6345796c8dcSSimon Schubert while (p[1] == ':')
6355796c8dcSSimon Schubert {
6365796c8dcSSimon Schubert p += 2;
6375796c8dcSSimon Schubert p = strchr (p, ':');
638c50c785cSJohn Marino if (p == NULL)
639c50c785cSJohn Marino {
640c50c785cSJohn Marino complaint (&symfile_complaints,
641c50c785cSJohn Marino _("Bad stabs string '%s'"), string);
642c50c785cSJohn Marino return NULL;
643c50c785cSJohn Marino }
6445796c8dcSSimon Schubert }
6455796c8dcSSimon Schubert
6465796c8dcSSimon Schubert /* If a nameless stab entry, all we need is the type, not the symbol.
6475796c8dcSSimon Schubert e.g. ":t10=*2" or a nameless enum like " :T16=ered:0,green:1,blue:2,;" */
6485796c8dcSSimon Schubert nameless = (p == string || ((string[0] == ' ') && (string[1] == ':')));
6495796c8dcSSimon Schubert
6505796c8dcSSimon Schubert current_symbol = sym = (struct symbol *)
6515796c8dcSSimon Schubert obstack_alloc (&objfile->objfile_obstack, sizeof (struct symbol));
6525796c8dcSSimon Schubert memset (sym, 0, sizeof (struct symbol));
6535796c8dcSSimon Schubert
6545796c8dcSSimon Schubert switch (type & N_TYPE)
6555796c8dcSSimon Schubert {
6565796c8dcSSimon Schubert case N_TEXT:
6575796c8dcSSimon Schubert SYMBOL_SECTION (sym) = SECT_OFF_TEXT (objfile);
6585796c8dcSSimon Schubert break;
6595796c8dcSSimon Schubert case N_DATA:
6605796c8dcSSimon Schubert SYMBOL_SECTION (sym) = SECT_OFF_DATA (objfile);
6615796c8dcSSimon Schubert break;
6625796c8dcSSimon Schubert case N_BSS:
6635796c8dcSSimon Schubert SYMBOL_SECTION (sym) = SECT_OFF_BSS (objfile);
6645796c8dcSSimon Schubert break;
6655796c8dcSSimon Schubert }
6665796c8dcSSimon Schubert
6675796c8dcSSimon Schubert if (processing_gcc_compilation)
6685796c8dcSSimon Schubert {
6695796c8dcSSimon Schubert /* GCC 2.x puts the line number in desc. SunOS apparently puts in the
6705796c8dcSSimon Schubert number of bytes occupied by a type or object, which we ignore. */
6715796c8dcSSimon Schubert SYMBOL_LINE (sym) = desc;
6725796c8dcSSimon Schubert }
6735796c8dcSSimon Schubert else
6745796c8dcSSimon Schubert {
6755796c8dcSSimon Schubert SYMBOL_LINE (sym) = 0; /* unknown */
6765796c8dcSSimon Schubert }
6775796c8dcSSimon Schubert
6785796c8dcSSimon Schubert if (is_cplus_marker (string[0]))
6795796c8dcSSimon Schubert {
6805796c8dcSSimon Schubert /* Special GNU C++ names. */
6815796c8dcSSimon Schubert switch (string[1])
6825796c8dcSSimon Schubert {
6835796c8dcSSimon Schubert case 't':
684cf7f2e2dSJohn Marino SYMBOL_SET_LINKAGE_NAME (sym, "this");
6855796c8dcSSimon Schubert break;
6865796c8dcSSimon Schubert
6875796c8dcSSimon Schubert case 'v': /* $vtbl_ptr_type */
6885796c8dcSSimon Schubert goto normal;
6895796c8dcSSimon Schubert
6905796c8dcSSimon Schubert case 'e':
691cf7f2e2dSJohn Marino SYMBOL_SET_LINKAGE_NAME (sym, "eh_throw");
6925796c8dcSSimon Schubert break;
6935796c8dcSSimon Schubert
6945796c8dcSSimon Schubert case '_':
6955796c8dcSSimon Schubert /* This was an anonymous type that was never fixed up. */
6965796c8dcSSimon Schubert goto normal;
6975796c8dcSSimon Schubert
6985796c8dcSSimon Schubert case 'X':
6995796c8dcSSimon Schubert /* SunPRO (3.0 at least) static variable encoding. */
7005796c8dcSSimon Schubert if (gdbarch_static_transform_name_p (gdbarch))
7015796c8dcSSimon Schubert goto normal;
7025796c8dcSSimon Schubert /* ... fall through ... */
7035796c8dcSSimon Schubert
7045796c8dcSSimon Schubert default:
7055796c8dcSSimon Schubert complaint (&symfile_complaints, _("Unknown C++ symbol name `%s'"),
7065796c8dcSSimon Schubert string);
707c50c785cSJohn Marino goto normal; /* Do *something* with it. */
7085796c8dcSSimon Schubert }
7095796c8dcSSimon Schubert }
7105796c8dcSSimon Schubert else
7115796c8dcSSimon Schubert {
7125796c8dcSSimon Schubert normal:
713c50c785cSJohn Marino SYMBOL_SET_LANGUAGE (sym, current_subfile->language);
7145796c8dcSSimon Schubert if (SYMBOL_LANGUAGE (sym) == language_cplus)
7155796c8dcSSimon Schubert {
7165796c8dcSSimon Schubert char *name = alloca (p - string + 1);
717cf7f2e2dSJohn Marino
7185796c8dcSSimon Schubert memcpy (name, string, p - string);
7195796c8dcSSimon Schubert name[p - string] = '\0';
7205796c8dcSSimon Schubert new_name = cp_canonicalize_string (name);
7215796c8dcSSimon Schubert }
7225796c8dcSSimon Schubert if (new_name != NULL)
7235796c8dcSSimon Schubert {
724cf7f2e2dSJohn Marino SYMBOL_SET_NAMES (sym, new_name, strlen (new_name), 1, objfile);
7255796c8dcSSimon Schubert xfree (new_name);
7265796c8dcSSimon Schubert }
7275796c8dcSSimon Schubert else
728cf7f2e2dSJohn Marino SYMBOL_SET_NAMES (sym, string, p - string, 1, objfile);
729c50c785cSJohn Marino
730c50c785cSJohn Marino if (SYMBOL_LANGUAGE (sym) == language_cplus)
731a45ae5f8SJohn Marino cp_scan_for_anonymous_namespaces (sym, objfile);
732c50c785cSJohn Marino
7335796c8dcSSimon Schubert }
7345796c8dcSSimon Schubert p++;
7355796c8dcSSimon Schubert
7365796c8dcSSimon Schubert /* Determine the type of name being defined. */
7375796c8dcSSimon Schubert #if 0
7385796c8dcSSimon Schubert /* Getting GDB to correctly skip the symbol on an undefined symbol
7395796c8dcSSimon Schubert descriptor and not ever dump core is a very dodgy proposition if
7405796c8dcSSimon Schubert we do things this way. I say the acorn RISC machine can just
7415796c8dcSSimon Schubert fix their compiler. */
7425796c8dcSSimon Schubert /* The Acorn RISC machine's compiler can put out locals that don't
7435796c8dcSSimon Schubert start with "234=" or "(3,4)=", so assume anything other than the
7445796c8dcSSimon Schubert deftypes we know how to handle is a local. */
7455796c8dcSSimon Schubert if (!strchr ("cfFGpPrStTvVXCR", *p))
7465796c8dcSSimon Schubert #else
7475796c8dcSSimon Schubert if (isdigit (*p) || *p == '(' || *p == '-')
7485796c8dcSSimon Schubert #endif
7495796c8dcSSimon Schubert deftype = 'l';
7505796c8dcSSimon Schubert else
7515796c8dcSSimon Schubert deftype = *p++;
7525796c8dcSSimon Schubert
7535796c8dcSSimon Schubert switch (deftype)
7545796c8dcSSimon Schubert {
7555796c8dcSSimon Schubert case 'c':
7565796c8dcSSimon Schubert /* c is a special case, not followed by a type-number.
7575796c8dcSSimon Schubert SYMBOL:c=iVALUE for an integer constant symbol.
7585796c8dcSSimon Schubert SYMBOL:c=rVALUE for a floating constant symbol.
7595796c8dcSSimon Schubert SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
7605796c8dcSSimon Schubert e.g. "b:c=e6,0" for "const b = blob1"
7615796c8dcSSimon Schubert (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
7625796c8dcSSimon Schubert if (*p != '=')
7635796c8dcSSimon Schubert {
7645796c8dcSSimon Schubert SYMBOL_CLASS (sym) = LOC_CONST;
7655796c8dcSSimon Schubert SYMBOL_TYPE (sym) = error_type (&p, objfile);
7665796c8dcSSimon Schubert SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
7675796c8dcSSimon Schubert add_symbol_to_list (sym, &file_symbols);
7685796c8dcSSimon Schubert return sym;
7695796c8dcSSimon Schubert }
7705796c8dcSSimon Schubert ++p;
7715796c8dcSSimon Schubert switch (*p++)
7725796c8dcSSimon Schubert {
7735796c8dcSSimon Schubert case 'r':
7745796c8dcSSimon Schubert {
7755796c8dcSSimon Schubert double d = atof (p);
7765796c8dcSSimon Schubert gdb_byte *dbl_valu;
7775796c8dcSSimon Schubert struct type *dbl_type;
7785796c8dcSSimon Schubert
7795796c8dcSSimon Schubert /* FIXME-if-picky-about-floating-accuracy: Should be using
7805796c8dcSSimon Schubert target arithmetic to get the value. real.c in GCC
7815796c8dcSSimon Schubert probably has the necessary code. */
7825796c8dcSSimon Schubert
7835796c8dcSSimon Schubert dbl_type = objfile_type (objfile)->builtin_double;
7845796c8dcSSimon Schubert dbl_valu =
7855796c8dcSSimon Schubert obstack_alloc (&objfile->objfile_obstack,
7865796c8dcSSimon Schubert TYPE_LENGTH (dbl_type));
7875796c8dcSSimon Schubert store_typed_floating (dbl_valu, dbl_type, d);
7885796c8dcSSimon Schubert
7895796c8dcSSimon Schubert SYMBOL_TYPE (sym) = dbl_type;
7905796c8dcSSimon Schubert SYMBOL_VALUE_BYTES (sym) = dbl_valu;
7915796c8dcSSimon Schubert SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
7925796c8dcSSimon Schubert }
7935796c8dcSSimon Schubert break;
7945796c8dcSSimon Schubert case 'i':
7955796c8dcSSimon Schubert {
7965796c8dcSSimon Schubert /* Defining integer constants this way is kind of silly,
7975796c8dcSSimon Schubert since 'e' constants allows the compiler to give not
7985796c8dcSSimon Schubert only the value, but the type as well. C has at least
7995796c8dcSSimon Schubert int, long, unsigned int, and long long as constant
8005796c8dcSSimon Schubert types; other languages probably should have at least
8015796c8dcSSimon Schubert unsigned as well as signed constants. */
8025796c8dcSSimon Schubert
8035796c8dcSSimon Schubert SYMBOL_TYPE (sym) = objfile_type (objfile)->builtin_long;
8045796c8dcSSimon Schubert SYMBOL_VALUE (sym) = atoi (p);
8055796c8dcSSimon Schubert SYMBOL_CLASS (sym) = LOC_CONST;
8065796c8dcSSimon Schubert }
8075796c8dcSSimon Schubert break;
808cf7f2e2dSJohn Marino
809cf7f2e2dSJohn Marino case 'c':
810cf7f2e2dSJohn Marino {
811cf7f2e2dSJohn Marino SYMBOL_TYPE (sym) = objfile_type (objfile)->builtin_char;
812cf7f2e2dSJohn Marino SYMBOL_VALUE (sym) = atoi (p);
813cf7f2e2dSJohn Marino SYMBOL_CLASS (sym) = LOC_CONST;
814cf7f2e2dSJohn Marino }
815cf7f2e2dSJohn Marino break;
816cf7f2e2dSJohn Marino
817cf7f2e2dSJohn Marino case 's':
818cf7f2e2dSJohn Marino {
819cf7f2e2dSJohn Marino struct type *range_type;
820cf7f2e2dSJohn Marino int ind = 0;
821cf7f2e2dSJohn Marino char quote = *p++;
822cf7f2e2dSJohn Marino gdb_byte *string_local = (gdb_byte *) alloca (strlen (p));
823cf7f2e2dSJohn Marino gdb_byte *string_value;
824cf7f2e2dSJohn Marino
825cf7f2e2dSJohn Marino if (quote != '\'' && quote != '"')
826cf7f2e2dSJohn Marino {
827cf7f2e2dSJohn Marino SYMBOL_CLASS (sym) = LOC_CONST;
828cf7f2e2dSJohn Marino SYMBOL_TYPE (sym) = error_type (&p, objfile);
829cf7f2e2dSJohn Marino SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
830cf7f2e2dSJohn Marino add_symbol_to_list (sym, &file_symbols);
831cf7f2e2dSJohn Marino return sym;
832cf7f2e2dSJohn Marino }
833cf7f2e2dSJohn Marino
834cf7f2e2dSJohn Marino /* Find matching quote, rejecting escaped quotes. */
835cf7f2e2dSJohn Marino while (*p && *p != quote)
836cf7f2e2dSJohn Marino {
837cf7f2e2dSJohn Marino if (*p == '\\' && p[1] == quote)
838cf7f2e2dSJohn Marino {
839cf7f2e2dSJohn Marino string_local[ind] = (gdb_byte) quote;
840cf7f2e2dSJohn Marino ind++;
841cf7f2e2dSJohn Marino p += 2;
842cf7f2e2dSJohn Marino }
843cf7f2e2dSJohn Marino else if (*p)
844cf7f2e2dSJohn Marino {
845cf7f2e2dSJohn Marino string_local[ind] = (gdb_byte) (*p);
846cf7f2e2dSJohn Marino ind++;
847cf7f2e2dSJohn Marino p++;
848cf7f2e2dSJohn Marino }
849cf7f2e2dSJohn Marino }
850cf7f2e2dSJohn Marino if (*p != quote)
851cf7f2e2dSJohn Marino {
852cf7f2e2dSJohn Marino SYMBOL_CLASS (sym) = LOC_CONST;
853cf7f2e2dSJohn Marino SYMBOL_TYPE (sym) = error_type (&p, objfile);
854cf7f2e2dSJohn Marino SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
855cf7f2e2dSJohn Marino add_symbol_to_list (sym, &file_symbols);
856cf7f2e2dSJohn Marino return sym;
857cf7f2e2dSJohn Marino }
858cf7f2e2dSJohn Marino
859cf7f2e2dSJohn Marino /* NULL terminate the string. */
860cf7f2e2dSJohn Marino string_local[ind] = 0;
861c50c785cSJohn Marino range_type
862c50c785cSJohn Marino = create_range_type (NULL,
863cf7f2e2dSJohn Marino objfile_type (objfile)->builtin_int,
864cf7f2e2dSJohn Marino 0, ind);
865cf7f2e2dSJohn Marino SYMBOL_TYPE (sym) = create_array_type (NULL,
866cf7f2e2dSJohn Marino objfile_type (objfile)->builtin_char,
867cf7f2e2dSJohn Marino range_type);
868cf7f2e2dSJohn Marino string_value = obstack_alloc (&objfile->objfile_obstack, ind + 1);
869cf7f2e2dSJohn Marino memcpy (string_value, string_local, ind + 1);
870cf7f2e2dSJohn Marino p++;
871cf7f2e2dSJohn Marino
872cf7f2e2dSJohn Marino SYMBOL_VALUE_BYTES (sym) = string_value;
873cf7f2e2dSJohn Marino SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
874cf7f2e2dSJohn Marino }
875cf7f2e2dSJohn Marino break;
876cf7f2e2dSJohn Marino
8775796c8dcSSimon Schubert case 'e':
8785796c8dcSSimon Schubert /* SYMBOL:c=eTYPE,INTVALUE for a constant symbol whose value
8795796c8dcSSimon Schubert can be represented as integral.
8805796c8dcSSimon Schubert e.g. "b:c=e6,0" for "const b = blob1"
8815796c8dcSSimon Schubert (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
8825796c8dcSSimon Schubert {
8835796c8dcSSimon Schubert SYMBOL_CLASS (sym) = LOC_CONST;
8845796c8dcSSimon Schubert SYMBOL_TYPE (sym) = read_type (&p, objfile);
8855796c8dcSSimon Schubert
8865796c8dcSSimon Schubert if (*p != ',')
8875796c8dcSSimon Schubert {
8885796c8dcSSimon Schubert SYMBOL_TYPE (sym) = error_type (&p, objfile);
8895796c8dcSSimon Schubert break;
8905796c8dcSSimon Schubert }
8915796c8dcSSimon Schubert ++p;
8925796c8dcSSimon Schubert
8935796c8dcSSimon Schubert /* If the value is too big to fit in an int (perhaps because
8945796c8dcSSimon Schubert it is unsigned), or something like that, we silently get
8955796c8dcSSimon Schubert a bogus value. The type and everything else about it is
8965796c8dcSSimon Schubert correct. Ideally, we should be using whatever we have
8975796c8dcSSimon Schubert available for parsing unsigned and long long values,
8985796c8dcSSimon Schubert however. */
8995796c8dcSSimon Schubert SYMBOL_VALUE (sym) = atoi (p);
9005796c8dcSSimon Schubert }
9015796c8dcSSimon Schubert break;
9025796c8dcSSimon Schubert default:
9035796c8dcSSimon Schubert {
9045796c8dcSSimon Schubert SYMBOL_CLASS (sym) = LOC_CONST;
9055796c8dcSSimon Schubert SYMBOL_TYPE (sym) = error_type (&p, objfile);
9065796c8dcSSimon Schubert }
9075796c8dcSSimon Schubert }
9085796c8dcSSimon Schubert SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
9095796c8dcSSimon Schubert add_symbol_to_list (sym, &file_symbols);
9105796c8dcSSimon Schubert return sym;
9115796c8dcSSimon Schubert
9125796c8dcSSimon Schubert case 'C':
9135796c8dcSSimon Schubert /* The name of a caught exception. */
9145796c8dcSSimon Schubert SYMBOL_TYPE (sym) = read_type (&p, objfile);
9155796c8dcSSimon Schubert SYMBOL_CLASS (sym) = LOC_LABEL;
9165796c8dcSSimon Schubert SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
9175796c8dcSSimon Schubert SYMBOL_VALUE_ADDRESS (sym) = valu;
9185796c8dcSSimon Schubert add_symbol_to_list (sym, &local_symbols);
9195796c8dcSSimon Schubert break;
9205796c8dcSSimon Schubert
9215796c8dcSSimon Schubert case 'f':
9225796c8dcSSimon Schubert /* A static function definition. */
9235796c8dcSSimon Schubert SYMBOL_TYPE (sym) = read_type (&p, objfile);
9245796c8dcSSimon Schubert SYMBOL_CLASS (sym) = LOC_BLOCK;
9255796c8dcSSimon Schubert SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
9265796c8dcSSimon Schubert add_symbol_to_list (sym, &file_symbols);
9275796c8dcSSimon Schubert /* fall into process_function_types. */
9285796c8dcSSimon Schubert
9295796c8dcSSimon Schubert process_function_types:
9305796c8dcSSimon Schubert /* Function result types are described as the result type in stabs.
9315796c8dcSSimon Schubert We need to convert this to the function-returning-type-X type
9325796c8dcSSimon Schubert in GDB. E.g. "int" is converted to "function returning int". */
9335796c8dcSSimon Schubert if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_FUNC)
9345796c8dcSSimon Schubert SYMBOL_TYPE (sym) = lookup_function_type (SYMBOL_TYPE (sym));
9355796c8dcSSimon Schubert
9365796c8dcSSimon Schubert /* All functions in C++ have prototypes. Stabs does not offer an
9375796c8dcSSimon Schubert explicit way to identify prototyped or unprototyped functions,
9385796c8dcSSimon Schubert but both GCC and Sun CC emit stabs for the "call-as" type rather
9395796c8dcSSimon Schubert than the "declared-as" type for unprototyped functions, so
9405796c8dcSSimon Schubert we treat all functions as if they were prototyped. This is used
9415796c8dcSSimon Schubert primarily for promotion when calling the function from GDB. */
9425796c8dcSSimon Schubert TYPE_PROTOTYPED (SYMBOL_TYPE (sym)) = 1;
9435796c8dcSSimon Schubert
944c50c785cSJohn Marino /* fall into process_prototype_types. */
9455796c8dcSSimon Schubert
9465796c8dcSSimon Schubert process_prototype_types:
9475796c8dcSSimon Schubert /* Sun acc puts declared types of arguments here. */
9485796c8dcSSimon Schubert if (*p == ';')
9495796c8dcSSimon Schubert {
9505796c8dcSSimon Schubert struct type *ftype = SYMBOL_TYPE (sym);
9515796c8dcSSimon Schubert int nsemi = 0;
9525796c8dcSSimon Schubert int nparams = 0;
9535796c8dcSSimon Schubert char *p1 = p;
9545796c8dcSSimon Schubert
9555796c8dcSSimon Schubert /* Obtain a worst case guess for the number of arguments
9565796c8dcSSimon Schubert by counting the semicolons. */
9575796c8dcSSimon Schubert while (*p1)
9585796c8dcSSimon Schubert {
9595796c8dcSSimon Schubert if (*p1++ == ';')
9605796c8dcSSimon Schubert nsemi++;
9615796c8dcSSimon Schubert }
9625796c8dcSSimon Schubert
9635796c8dcSSimon Schubert /* Allocate parameter information fields and fill them in. */
9645796c8dcSSimon Schubert TYPE_FIELDS (ftype) = (struct field *)
9655796c8dcSSimon Schubert TYPE_ALLOC (ftype, nsemi * sizeof (struct field));
9665796c8dcSSimon Schubert while (*p++ == ';')
9675796c8dcSSimon Schubert {
9685796c8dcSSimon Schubert struct type *ptype;
9695796c8dcSSimon Schubert
9705796c8dcSSimon Schubert /* A type number of zero indicates the start of varargs.
9715796c8dcSSimon Schubert FIXME: GDB currently ignores vararg functions. */
9725796c8dcSSimon Schubert if (p[0] == '0' && p[1] == '\0')
9735796c8dcSSimon Schubert break;
9745796c8dcSSimon Schubert ptype = read_type (&p, objfile);
9755796c8dcSSimon Schubert
9765796c8dcSSimon Schubert /* The Sun compilers mark integer arguments, which should
9775796c8dcSSimon Schubert be promoted to the width of the calling conventions, with
9785796c8dcSSimon Schubert a type which references itself. This type is turned into
9795796c8dcSSimon Schubert a TYPE_CODE_VOID type by read_type, and we have to turn
9805796c8dcSSimon Schubert it back into builtin_int here.
9815796c8dcSSimon Schubert FIXME: Do we need a new builtin_promoted_int_arg ? */
9825796c8dcSSimon Schubert if (TYPE_CODE (ptype) == TYPE_CODE_VOID)
9835796c8dcSSimon Schubert ptype = objfile_type (objfile)->builtin_int;
9845796c8dcSSimon Schubert TYPE_FIELD_TYPE (ftype, nparams) = ptype;
9855796c8dcSSimon Schubert TYPE_FIELD_ARTIFICIAL (ftype, nparams++) = 0;
9865796c8dcSSimon Schubert }
9875796c8dcSSimon Schubert TYPE_NFIELDS (ftype) = nparams;
9885796c8dcSSimon Schubert TYPE_PROTOTYPED (ftype) = 1;
9895796c8dcSSimon Schubert }
9905796c8dcSSimon Schubert break;
9915796c8dcSSimon Schubert
9925796c8dcSSimon Schubert case 'F':
9935796c8dcSSimon Schubert /* A global function definition. */
9945796c8dcSSimon Schubert SYMBOL_TYPE (sym) = read_type (&p, objfile);
9955796c8dcSSimon Schubert SYMBOL_CLASS (sym) = LOC_BLOCK;
9965796c8dcSSimon Schubert SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
9975796c8dcSSimon Schubert add_symbol_to_list (sym, &global_symbols);
9985796c8dcSSimon Schubert goto process_function_types;
9995796c8dcSSimon Schubert
10005796c8dcSSimon Schubert case 'G':
10015796c8dcSSimon Schubert /* For a class G (global) symbol, it appears that the
10025796c8dcSSimon Schubert value is not correct. It is necessary to search for the
10035796c8dcSSimon Schubert corresponding linker definition to find the value.
10045796c8dcSSimon Schubert These definitions appear at the end of the namelist. */
10055796c8dcSSimon Schubert SYMBOL_TYPE (sym) = read_type (&p, objfile);
10065796c8dcSSimon Schubert SYMBOL_CLASS (sym) = LOC_STATIC;
10075796c8dcSSimon Schubert SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
10085796c8dcSSimon Schubert /* Don't add symbol references to global_sym_chain.
10095796c8dcSSimon Schubert Symbol references don't have valid names and wont't match up with
10105796c8dcSSimon Schubert minimal symbols when the global_sym_chain is relocated.
10115796c8dcSSimon Schubert We'll fixup symbol references when we fixup the defining symbol. */
10125796c8dcSSimon Schubert if (SYMBOL_LINKAGE_NAME (sym) && SYMBOL_LINKAGE_NAME (sym)[0] != '#')
10135796c8dcSSimon Schubert {
10145796c8dcSSimon Schubert i = hashname (SYMBOL_LINKAGE_NAME (sym));
10155796c8dcSSimon Schubert SYMBOL_VALUE_CHAIN (sym) = global_sym_chain[i];
10165796c8dcSSimon Schubert global_sym_chain[i] = sym;
10175796c8dcSSimon Schubert }
10185796c8dcSSimon Schubert add_symbol_to_list (sym, &global_symbols);
10195796c8dcSSimon Schubert break;
10205796c8dcSSimon Schubert
10215796c8dcSSimon Schubert /* This case is faked by a conditional above,
10225796c8dcSSimon Schubert when there is no code letter in the dbx data.
10235796c8dcSSimon Schubert Dbx data never actually contains 'l'. */
10245796c8dcSSimon Schubert case 's':
10255796c8dcSSimon Schubert case 'l':
10265796c8dcSSimon Schubert SYMBOL_TYPE (sym) = read_type (&p, objfile);
10275796c8dcSSimon Schubert SYMBOL_CLASS (sym) = LOC_LOCAL;
10285796c8dcSSimon Schubert SYMBOL_VALUE (sym) = valu;
10295796c8dcSSimon Schubert SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
10305796c8dcSSimon Schubert add_symbol_to_list (sym, &local_symbols);
10315796c8dcSSimon Schubert break;
10325796c8dcSSimon Schubert
10335796c8dcSSimon Schubert case 'p':
10345796c8dcSSimon Schubert if (*p == 'F')
10355796c8dcSSimon Schubert /* pF is a two-letter code that means a function parameter in Fortran.
10365796c8dcSSimon Schubert The type-number specifies the type of the return value.
10375796c8dcSSimon Schubert Translate it into a pointer-to-function type. */
10385796c8dcSSimon Schubert {
10395796c8dcSSimon Schubert p++;
10405796c8dcSSimon Schubert SYMBOL_TYPE (sym)
10415796c8dcSSimon Schubert = lookup_pointer_type
10425796c8dcSSimon Schubert (lookup_function_type (read_type (&p, objfile)));
10435796c8dcSSimon Schubert }
10445796c8dcSSimon Schubert else
10455796c8dcSSimon Schubert SYMBOL_TYPE (sym) = read_type (&p, objfile);
10465796c8dcSSimon Schubert
10475796c8dcSSimon Schubert SYMBOL_CLASS (sym) = LOC_ARG;
10485796c8dcSSimon Schubert SYMBOL_VALUE (sym) = valu;
10495796c8dcSSimon Schubert SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
10505796c8dcSSimon Schubert SYMBOL_IS_ARGUMENT (sym) = 1;
10515796c8dcSSimon Schubert add_symbol_to_list (sym, &local_symbols);
10525796c8dcSSimon Schubert
10535796c8dcSSimon Schubert if (gdbarch_byte_order (gdbarch) != BFD_ENDIAN_BIG)
10545796c8dcSSimon Schubert {
10555796c8dcSSimon Schubert /* On little-endian machines, this crud is never necessary,
10565796c8dcSSimon Schubert and, if the extra bytes contain garbage, is harmful. */
10575796c8dcSSimon Schubert break;
10585796c8dcSSimon Schubert }
10595796c8dcSSimon Schubert
10605796c8dcSSimon Schubert /* If it's gcc-compiled, if it says `short', believe it. */
10615796c8dcSSimon Schubert if (processing_gcc_compilation
10625796c8dcSSimon Schubert || gdbarch_believe_pcc_promotion (gdbarch))
10635796c8dcSSimon Schubert break;
10645796c8dcSSimon Schubert
10655796c8dcSSimon Schubert if (!gdbarch_believe_pcc_promotion (gdbarch))
10665796c8dcSSimon Schubert {
10675796c8dcSSimon Schubert /* If PCC says a parameter is a short or a char, it is
10685796c8dcSSimon Schubert really an int. */
10695796c8dcSSimon Schubert if (TYPE_LENGTH (SYMBOL_TYPE (sym))
10705796c8dcSSimon Schubert < gdbarch_int_bit (gdbarch) / TARGET_CHAR_BIT
10715796c8dcSSimon Schubert && TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_INT)
10725796c8dcSSimon Schubert {
10735796c8dcSSimon Schubert SYMBOL_TYPE (sym) =
10745796c8dcSSimon Schubert TYPE_UNSIGNED (SYMBOL_TYPE (sym))
10755796c8dcSSimon Schubert ? objfile_type (objfile)->builtin_unsigned_int
10765796c8dcSSimon Schubert : objfile_type (objfile)->builtin_int;
10775796c8dcSSimon Schubert }
10785796c8dcSSimon Schubert break;
10795796c8dcSSimon Schubert }
10805796c8dcSSimon Schubert
10815796c8dcSSimon Schubert case 'P':
10825796c8dcSSimon Schubert /* acc seems to use P to declare the prototypes of functions that
10835796c8dcSSimon Schubert are referenced by this file. gdb is not prepared to deal
10845796c8dcSSimon Schubert with this extra information. FIXME, it ought to. */
10855796c8dcSSimon Schubert if (type == N_FUN)
10865796c8dcSSimon Schubert {
10875796c8dcSSimon Schubert SYMBOL_TYPE (sym) = read_type (&p, objfile);
10885796c8dcSSimon Schubert goto process_prototype_types;
10895796c8dcSSimon Schubert }
10905796c8dcSSimon Schubert /*FALLTHROUGH */
10915796c8dcSSimon Schubert
10925796c8dcSSimon Schubert case 'R':
10935796c8dcSSimon Schubert /* Parameter which is in a register. */
10945796c8dcSSimon Schubert SYMBOL_TYPE (sym) = read_type (&p, objfile);
10955796c8dcSSimon Schubert SYMBOL_CLASS (sym) = LOC_REGISTER;
10965796c8dcSSimon Schubert SYMBOL_REGISTER_OPS (sym) = &stab_register_funcs;
10975796c8dcSSimon Schubert SYMBOL_IS_ARGUMENT (sym) = 1;
10985796c8dcSSimon Schubert SYMBOL_VALUE (sym) = valu;
10995796c8dcSSimon Schubert SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
11005796c8dcSSimon Schubert add_symbol_to_list (sym, &local_symbols);
11015796c8dcSSimon Schubert break;
11025796c8dcSSimon Schubert
11035796c8dcSSimon Schubert case 'r':
11045796c8dcSSimon Schubert /* Register variable (either global or local). */
11055796c8dcSSimon Schubert SYMBOL_TYPE (sym) = read_type (&p, objfile);
11065796c8dcSSimon Schubert SYMBOL_CLASS (sym) = LOC_REGISTER;
11075796c8dcSSimon Schubert SYMBOL_REGISTER_OPS (sym) = &stab_register_funcs;
11085796c8dcSSimon Schubert SYMBOL_VALUE (sym) = valu;
11095796c8dcSSimon Schubert SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
11105796c8dcSSimon Schubert if (within_function)
11115796c8dcSSimon Schubert {
11125796c8dcSSimon Schubert /* Sun cc uses a pair of symbols, one 'p' and one 'r', with
11135796c8dcSSimon Schubert the same name to represent an argument passed in a
11145796c8dcSSimon Schubert register. GCC uses 'P' for the same case. So if we find
11155796c8dcSSimon Schubert such a symbol pair we combine it into one 'P' symbol.
11165796c8dcSSimon Schubert For Sun cc we need to do this regardless of
11175796c8dcSSimon Schubert stabs_argument_has_addr, because the compiler puts out
11185796c8dcSSimon Schubert the 'p' symbol even if it never saves the argument onto
11195796c8dcSSimon Schubert the stack.
11205796c8dcSSimon Schubert
11215796c8dcSSimon Schubert On most machines, we want to preserve both symbols, so
11225796c8dcSSimon Schubert that we can still get information about what is going on
11235796c8dcSSimon Schubert with the stack (VAX for computing args_printed, using
11245796c8dcSSimon Schubert stack slots instead of saved registers in backtraces,
11255796c8dcSSimon Schubert etc.).
11265796c8dcSSimon Schubert
11275796c8dcSSimon Schubert Note that this code illegally combines
11285796c8dcSSimon Schubert main(argc) struct foo argc; { register struct foo argc; }
11295796c8dcSSimon Schubert but this case is considered pathological and causes a warning
11305796c8dcSSimon Schubert from a decent compiler. */
11315796c8dcSSimon Schubert
11325796c8dcSSimon Schubert if (local_symbols
11335796c8dcSSimon Schubert && local_symbols->nsyms > 0
11345796c8dcSSimon Schubert && gdbarch_stabs_argument_has_addr (gdbarch, SYMBOL_TYPE (sym)))
11355796c8dcSSimon Schubert {
11365796c8dcSSimon Schubert struct symbol *prev_sym;
1137cf7f2e2dSJohn Marino
11385796c8dcSSimon Schubert prev_sym = local_symbols->symbol[local_symbols->nsyms - 1];
11395796c8dcSSimon Schubert if ((SYMBOL_CLASS (prev_sym) == LOC_REF_ARG
11405796c8dcSSimon Schubert || SYMBOL_CLASS (prev_sym) == LOC_ARG)
11415796c8dcSSimon Schubert && strcmp (SYMBOL_LINKAGE_NAME (prev_sym),
11425796c8dcSSimon Schubert SYMBOL_LINKAGE_NAME (sym)) == 0)
11435796c8dcSSimon Schubert {
11445796c8dcSSimon Schubert SYMBOL_CLASS (prev_sym) = LOC_REGISTER;
11455796c8dcSSimon Schubert SYMBOL_REGISTER_OPS (prev_sym) = &stab_register_funcs;
11465796c8dcSSimon Schubert /* Use the type from the LOC_REGISTER; that is the type
11475796c8dcSSimon Schubert that is actually in that register. */
11485796c8dcSSimon Schubert SYMBOL_TYPE (prev_sym) = SYMBOL_TYPE (sym);
11495796c8dcSSimon Schubert SYMBOL_VALUE (prev_sym) = SYMBOL_VALUE (sym);
11505796c8dcSSimon Schubert sym = prev_sym;
11515796c8dcSSimon Schubert break;
11525796c8dcSSimon Schubert }
11535796c8dcSSimon Schubert }
11545796c8dcSSimon Schubert add_symbol_to_list (sym, &local_symbols);
11555796c8dcSSimon Schubert }
11565796c8dcSSimon Schubert else
11575796c8dcSSimon Schubert add_symbol_to_list (sym, &file_symbols);
11585796c8dcSSimon Schubert break;
11595796c8dcSSimon Schubert
11605796c8dcSSimon Schubert case 'S':
1161c50c785cSJohn Marino /* Static symbol at top level of file. */
11625796c8dcSSimon Schubert SYMBOL_TYPE (sym) = read_type (&p, objfile);
11635796c8dcSSimon Schubert SYMBOL_CLASS (sym) = LOC_STATIC;
11645796c8dcSSimon Schubert SYMBOL_VALUE_ADDRESS (sym) = valu;
11655796c8dcSSimon Schubert if (gdbarch_static_transform_name_p (gdbarch)
11665796c8dcSSimon Schubert && gdbarch_static_transform_name (gdbarch,
11675796c8dcSSimon Schubert SYMBOL_LINKAGE_NAME (sym))
11685796c8dcSSimon Schubert != SYMBOL_LINKAGE_NAME (sym))
11695796c8dcSSimon Schubert {
11705796c8dcSSimon Schubert struct minimal_symbol *msym;
1171cf7f2e2dSJohn Marino
1172c50c785cSJohn Marino msym = lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (sym),
1173c50c785cSJohn Marino NULL, objfile);
11745796c8dcSSimon Schubert if (msym != NULL)
11755796c8dcSSimon Schubert {
1176*ef5ccd6cSJohn Marino const char *new_name = gdbarch_static_transform_name
11775796c8dcSSimon Schubert (gdbarch, SYMBOL_LINKAGE_NAME (sym));
1178cf7f2e2dSJohn Marino
11795796c8dcSSimon Schubert SYMBOL_SET_LINKAGE_NAME (sym, new_name);
11805796c8dcSSimon Schubert SYMBOL_VALUE_ADDRESS (sym) = SYMBOL_VALUE_ADDRESS (msym);
11815796c8dcSSimon Schubert }
11825796c8dcSSimon Schubert }
11835796c8dcSSimon Schubert SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
11845796c8dcSSimon Schubert add_symbol_to_list (sym, &file_symbols);
11855796c8dcSSimon Schubert break;
11865796c8dcSSimon Schubert
11875796c8dcSSimon Schubert case 't':
11885796c8dcSSimon Schubert /* In Ada, there is no distinction between typedef and non-typedef;
11895796c8dcSSimon Schubert any type declaration implicitly has the equivalent of a typedef,
11905796c8dcSSimon Schubert and thus 't' is in fact equivalent to 'Tt'.
11915796c8dcSSimon Schubert
11925796c8dcSSimon Schubert Therefore, for Ada units, we check the character immediately
11935796c8dcSSimon Schubert before the 't', and if we do not find a 'T', then make sure to
11945796c8dcSSimon Schubert create the associated symbol in the STRUCT_DOMAIN ('t' definitions
11955796c8dcSSimon Schubert will be stored in the VAR_DOMAIN). If the symbol was indeed
11965796c8dcSSimon Schubert defined as 'Tt' then the STRUCT_DOMAIN symbol will be created
11975796c8dcSSimon Schubert elsewhere, so we don't need to take care of that.
11985796c8dcSSimon Schubert
11995796c8dcSSimon Schubert This is important to do, because of forward references:
12005796c8dcSSimon Schubert The cleanup of undefined types stored in undef_types only uses
12015796c8dcSSimon Schubert STRUCT_DOMAIN symbols to perform the replacement. */
12025796c8dcSSimon Schubert synonym = (SYMBOL_LANGUAGE (sym) == language_ada && p[-2] != 'T');
12035796c8dcSSimon Schubert
12045796c8dcSSimon Schubert /* Typedef */
12055796c8dcSSimon Schubert SYMBOL_TYPE (sym) = read_type (&p, objfile);
12065796c8dcSSimon Schubert
12075796c8dcSSimon Schubert /* For a nameless type, we don't want a create a symbol, thus we
12085796c8dcSSimon Schubert did not use `sym'. Return without further processing. */
12095796c8dcSSimon Schubert if (nameless)
12105796c8dcSSimon Schubert return NULL;
12115796c8dcSSimon Schubert
12125796c8dcSSimon Schubert SYMBOL_CLASS (sym) = LOC_TYPEDEF;
12135796c8dcSSimon Schubert SYMBOL_VALUE (sym) = valu;
12145796c8dcSSimon Schubert SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
12155796c8dcSSimon Schubert /* C++ vagaries: we may have a type which is derived from
12165796c8dcSSimon Schubert a base type which did not have its name defined when the
12175796c8dcSSimon Schubert derived class was output. We fill in the derived class's
12185796c8dcSSimon Schubert base part member's name here in that case. */
12195796c8dcSSimon Schubert if (TYPE_NAME (SYMBOL_TYPE (sym)) != NULL)
12205796c8dcSSimon Schubert if ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT
12215796c8dcSSimon Schubert || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION)
12225796c8dcSSimon Schubert && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)))
12235796c8dcSSimon Schubert {
12245796c8dcSSimon Schubert int j;
1225cf7f2e2dSJohn Marino
12265796c8dcSSimon Schubert for (j = TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)) - 1; j >= 0; j--)
12275796c8dcSSimon Schubert if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) == 0)
12285796c8dcSSimon Schubert TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) =
12295796c8dcSSimon Schubert type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym), j));
12305796c8dcSSimon Schubert }
12315796c8dcSSimon Schubert
12325796c8dcSSimon Schubert if (TYPE_NAME (SYMBOL_TYPE (sym)) == NULL)
12335796c8dcSSimon Schubert {
12345796c8dcSSimon Schubert /* gcc-2.6 or later (when using -fvtable-thunks)
12355796c8dcSSimon Schubert emits a unique named type for a vtable entry.
12365796c8dcSSimon Schubert Some gdb code depends on that specific name. */
12375796c8dcSSimon Schubert extern const char vtbl_ptr_name[];
12385796c8dcSSimon Schubert
12395796c8dcSSimon Schubert if ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_PTR
12405796c8dcSSimon Schubert && strcmp (SYMBOL_LINKAGE_NAME (sym), vtbl_ptr_name))
12415796c8dcSSimon Schubert || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_FUNC)
12425796c8dcSSimon Schubert {
12435796c8dcSSimon Schubert /* If we are giving a name to a type such as "pointer to
12445796c8dcSSimon Schubert foo" or "function returning foo", we better not set
12455796c8dcSSimon Schubert the TYPE_NAME. If the program contains "typedef char
12465796c8dcSSimon Schubert *caddr_t;", we don't want all variables of type char
12475796c8dcSSimon Schubert * to print as caddr_t. This is not just a
12485796c8dcSSimon Schubert consequence of GDB's type management; PCC and GCC (at
12495796c8dcSSimon Schubert least through version 2.4) both output variables of
12505796c8dcSSimon Schubert either type char * or caddr_t with the type number
12515796c8dcSSimon Schubert defined in the 't' symbol for caddr_t. If a future
12525796c8dcSSimon Schubert compiler cleans this up it GDB is not ready for it
12535796c8dcSSimon Schubert yet, but if it becomes ready we somehow need to
12545796c8dcSSimon Schubert disable this check (without breaking the PCC/GCC2.4
12555796c8dcSSimon Schubert case).
12565796c8dcSSimon Schubert
12575796c8dcSSimon Schubert Sigh.
12585796c8dcSSimon Schubert
12595796c8dcSSimon Schubert Fortunately, this check seems not to be necessary
12605796c8dcSSimon Schubert for anything except pointers or functions. */
12615796c8dcSSimon Schubert /* ezannoni: 2000-10-26. This seems to apply for
12625796c8dcSSimon Schubert versions of gcc older than 2.8. This was the original
12635796c8dcSSimon Schubert problem: with the following code gdb would tell that
1264c50c785cSJohn Marino the type for name1 is caddr_t, and func is char().
1265c50c785cSJohn Marino
12665796c8dcSSimon Schubert typedef char *caddr_t;
12675796c8dcSSimon Schubert char *name2;
12685796c8dcSSimon Schubert struct x
12695796c8dcSSimon Schubert {
12705796c8dcSSimon Schubert char *name1;
12715796c8dcSSimon Schubert } xx;
12725796c8dcSSimon Schubert char *func()
12735796c8dcSSimon Schubert {
12745796c8dcSSimon Schubert }
12755796c8dcSSimon Schubert main () {}
12765796c8dcSSimon Schubert */
12775796c8dcSSimon Schubert
12785796c8dcSSimon Schubert /* Pascal accepts names for pointer types. */
12795796c8dcSSimon Schubert if (current_subfile->language == language_pascal)
12805796c8dcSSimon Schubert {
12815796c8dcSSimon Schubert TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_LINKAGE_NAME (sym);
12825796c8dcSSimon Schubert }
12835796c8dcSSimon Schubert }
12845796c8dcSSimon Schubert else
12855796c8dcSSimon Schubert TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_LINKAGE_NAME (sym);
12865796c8dcSSimon Schubert }
12875796c8dcSSimon Schubert
12885796c8dcSSimon Schubert add_symbol_to_list (sym, &file_symbols);
12895796c8dcSSimon Schubert
12905796c8dcSSimon Schubert if (synonym)
12915796c8dcSSimon Schubert {
12925796c8dcSSimon Schubert /* Create the STRUCT_DOMAIN clone. */
12935796c8dcSSimon Schubert struct symbol *struct_sym = (struct symbol *)
12945796c8dcSSimon Schubert obstack_alloc (&objfile->objfile_obstack, sizeof (struct symbol));
12955796c8dcSSimon Schubert
12965796c8dcSSimon Schubert *struct_sym = *sym;
12975796c8dcSSimon Schubert SYMBOL_CLASS (struct_sym) = LOC_TYPEDEF;
12985796c8dcSSimon Schubert SYMBOL_VALUE (struct_sym) = valu;
12995796c8dcSSimon Schubert SYMBOL_DOMAIN (struct_sym) = STRUCT_DOMAIN;
13005796c8dcSSimon Schubert if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
1301c50c785cSJohn Marino TYPE_NAME (SYMBOL_TYPE (sym))
1302c50c785cSJohn Marino = obconcat (&objfile->objfile_obstack,
1303cf7f2e2dSJohn Marino SYMBOL_LINKAGE_NAME (sym),
1304cf7f2e2dSJohn Marino (char *) NULL);
13055796c8dcSSimon Schubert add_symbol_to_list (struct_sym, &file_symbols);
13065796c8dcSSimon Schubert }
13075796c8dcSSimon Schubert
13085796c8dcSSimon Schubert break;
13095796c8dcSSimon Schubert
13105796c8dcSSimon Schubert case 'T':
13115796c8dcSSimon Schubert /* Struct, union, or enum tag. For GNU C++, this can be be followed
13125796c8dcSSimon Schubert by 't' which means we are typedef'ing it as well. */
13135796c8dcSSimon Schubert synonym = *p == 't';
13145796c8dcSSimon Schubert
13155796c8dcSSimon Schubert if (synonym)
13165796c8dcSSimon Schubert p++;
13175796c8dcSSimon Schubert
13185796c8dcSSimon Schubert SYMBOL_TYPE (sym) = read_type (&p, objfile);
13195796c8dcSSimon Schubert
13205796c8dcSSimon Schubert /* For a nameless type, we don't want a create a symbol, thus we
13215796c8dcSSimon Schubert did not use `sym'. Return without further processing. */
13225796c8dcSSimon Schubert if (nameless)
13235796c8dcSSimon Schubert return NULL;
13245796c8dcSSimon Schubert
13255796c8dcSSimon Schubert SYMBOL_CLASS (sym) = LOC_TYPEDEF;
13265796c8dcSSimon Schubert SYMBOL_VALUE (sym) = valu;
13275796c8dcSSimon Schubert SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN;
13285796c8dcSSimon Schubert if (TYPE_TAG_NAME (SYMBOL_TYPE (sym)) == 0)
1329c50c785cSJohn Marino TYPE_TAG_NAME (SYMBOL_TYPE (sym))
1330c50c785cSJohn Marino = obconcat (&objfile->objfile_obstack,
1331cf7f2e2dSJohn Marino SYMBOL_LINKAGE_NAME (sym),
1332cf7f2e2dSJohn Marino (char *) NULL);
13335796c8dcSSimon Schubert add_symbol_to_list (sym, &file_symbols);
13345796c8dcSSimon Schubert
13355796c8dcSSimon Schubert if (synonym)
13365796c8dcSSimon Schubert {
13375796c8dcSSimon Schubert /* Clone the sym and then modify it. */
13385796c8dcSSimon Schubert struct symbol *typedef_sym = (struct symbol *)
13395796c8dcSSimon Schubert obstack_alloc (&objfile->objfile_obstack, sizeof (struct symbol));
1340cf7f2e2dSJohn Marino
13415796c8dcSSimon Schubert *typedef_sym = *sym;
13425796c8dcSSimon Schubert SYMBOL_CLASS (typedef_sym) = LOC_TYPEDEF;
13435796c8dcSSimon Schubert SYMBOL_VALUE (typedef_sym) = valu;
13445796c8dcSSimon Schubert SYMBOL_DOMAIN (typedef_sym) = VAR_DOMAIN;
13455796c8dcSSimon Schubert if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
1346c50c785cSJohn Marino TYPE_NAME (SYMBOL_TYPE (sym))
1347c50c785cSJohn Marino = obconcat (&objfile->objfile_obstack,
1348cf7f2e2dSJohn Marino SYMBOL_LINKAGE_NAME (sym),
1349cf7f2e2dSJohn Marino (char *) NULL);
13505796c8dcSSimon Schubert add_symbol_to_list (typedef_sym, &file_symbols);
13515796c8dcSSimon Schubert }
13525796c8dcSSimon Schubert break;
13535796c8dcSSimon Schubert
13545796c8dcSSimon Schubert case 'V':
1355c50c785cSJohn Marino /* Static symbol of local scope. */
13565796c8dcSSimon Schubert SYMBOL_TYPE (sym) = read_type (&p, objfile);
13575796c8dcSSimon Schubert SYMBOL_CLASS (sym) = LOC_STATIC;
13585796c8dcSSimon Schubert SYMBOL_VALUE_ADDRESS (sym) = valu;
13595796c8dcSSimon Schubert if (gdbarch_static_transform_name_p (gdbarch)
13605796c8dcSSimon Schubert && gdbarch_static_transform_name (gdbarch,
13615796c8dcSSimon Schubert SYMBOL_LINKAGE_NAME (sym))
13625796c8dcSSimon Schubert != SYMBOL_LINKAGE_NAME (sym))
13635796c8dcSSimon Schubert {
13645796c8dcSSimon Schubert struct minimal_symbol *msym;
1365cf7f2e2dSJohn Marino
1366cf7f2e2dSJohn Marino msym = lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (sym),
1367cf7f2e2dSJohn Marino NULL, objfile);
13685796c8dcSSimon Schubert if (msym != NULL)
13695796c8dcSSimon Schubert {
1370*ef5ccd6cSJohn Marino const char *new_name = gdbarch_static_transform_name
13715796c8dcSSimon Schubert (gdbarch, SYMBOL_LINKAGE_NAME (sym));
1372cf7f2e2dSJohn Marino
13735796c8dcSSimon Schubert SYMBOL_SET_LINKAGE_NAME (sym, new_name);
13745796c8dcSSimon Schubert SYMBOL_VALUE_ADDRESS (sym) = SYMBOL_VALUE_ADDRESS (msym);
13755796c8dcSSimon Schubert }
13765796c8dcSSimon Schubert }
13775796c8dcSSimon Schubert SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
13785796c8dcSSimon Schubert add_symbol_to_list (sym, &local_symbols);
13795796c8dcSSimon Schubert break;
13805796c8dcSSimon Schubert
13815796c8dcSSimon Schubert case 'v':
13825796c8dcSSimon Schubert /* Reference parameter */
13835796c8dcSSimon Schubert SYMBOL_TYPE (sym) = read_type (&p, objfile);
13845796c8dcSSimon Schubert SYMBOL_CLASS (sym) = LOC_REF_ARG;
13855796c8dcSSimon Schubert SYMBOL_IS_ARGUMENT (sym) = 1;
13865796c8dcSSimon Schubert SYMBOL_VALUE (sym) = valu;
13875796c8dcSSimon Schubert SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
13885796c8dcSSimon Schubert add_symbol_to_list (sym, &local_symbols);
13895796c8dcSSimon Schubert break;
13905796c8dcSSimon Schubert
13915796c8dcSSimon Schubert case 'a':
13925796c8dcSSimon Schubert /* Reference parameter which is in a register. */
13935796c8dcSSimon Schubert SYMBOL_TYPE (sym) = read_type (&p, objfile);
13945796c8dcSSimon Schubert SYMBOL_CLASS (sym) = LOC_REGPARM_ADDR;
13955796c8dcSSimon Schubert SYMBOL_REGISTER_OPS (sym) = &stab_register_funcs;
13965796c8dcSSimon Schubert SYMBOL_IS_ARGUMENT (sym) = 1;
13975796c8dcSSimon Schubert SYMBOL_VALUE (sym) = valu;
13985796c8dcSSimon Schubert SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
13995796c8dcSSimon Schubert add_symbol_to_list (sym, &local_symbols);
14005796c8dcSSimon Schubert break;
14015796c8dcSSimon Schubert
14025796c8dcSSimon Schubert case 'X':
14035796c8dcSSimon Schubert /* This is used by Sun FORTRAN for "function result value".
14045796c8dcSSimon Schubert Sun claims ("dbx and dbxtool interfaces", 2nd ed)
14055796c8dcSSimon Schubert that Pascal uses it too, but when I tried it Pascal used
14065796c8dcSSimon Schubert "x:3" (local symbol) instead. */
14075796c8dcSSimon Schubert SYMBOL_TYPE (sym) = read_type (&p, objfile);
14085796c8dcSSimon Schubert SYMBOL_CLASS (sym) = LOC_LOCAL;
14095796c8dcSSimon Schubert SYMBOL_VALUE (sym) = valu;
14105796c8dcSSimon Schubert SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
14115796c8dcSSimon Schubert add_symbol_to_list (sym, &local_symbols);
14125796c8dcSSimon Schubert break;
14135796c8dcSSimon Schubert
14145796c8dcSSimon Schubert default:
14155796c8dcSSimon Schubert SYMBOL_TYPE (sym) = error_type (&p, objfile);
14165796c8dcSSimon Schubert SYMBOL_CLASS (sym) = LOC_CONST;
14175796c8dcSSimon Schubert SYMBOL_VALUE (sym) = 0;
14185796c8dcSSimon Schubert SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
14195796c8dcSSimon Schubert add_symbol_to_list (sym, &file_symbols);
14205796c8dcSSimon Schubert break;
14215796c8dcSSimon Schubert }
14225796c8dcSSimon Schubert
14235796c8dcSSimon Schubert /* Some systems pass variables of certain types by reference instead
14245796c8dcSSimon Schubert of by value, i.e. they will pass the address of a structure (in a
14255796c8dcSSimon Schubert register or on the stack) instead of the structure itself. */
14265796c8dcSSimon Schubert
14275796c8dcSSimon Schubert if (gdbarch_stabs_argument_has_addr (gdbarch, SYMBOL_TYPE (sym))
14285796c8dcSSimon Schubert && SYMBOL_IS_ARGUMENT (sym))
14295796c8dcSSimon Schubert {
14305796c8dcSSimon Schubert /* We have to convert LOC_REGISTER to LOC_REGPARM_ADDR (for
14315796c8dcSSimon Schubert variables passed in a register). */
14325796c8dcSSimon Schubert if (SYMBOL_CLASS (sym) == LOC_REGISTER)
14335796c8dcSSimon Schubert SYMBOL_CLASS (sym) = LOC_REGPARM_ADDR;
14345796c8dcSSimon Schubert /* Likewise for converting LOC_ARG to LOC_REF_ARG (for the 7th
14355796c8dcSSimon Schubert and subsequent arguments on SPARC, for example). */
14365796c8dcSSimon Schubert else if (SYMBOL_CLASS (sym) == LOC_ARG)
14375796c8dcSSimon Schubert SYMBOL_CLASS (sym) = LOC_REF_ARG;
14385796c8dcSSimon Schubert }
14395796c8dcSSimon Schubert
14405796c8dcSSimon Schubert return sym;
14415796c8dcSSimon Schubert }
14425796c8dcSSimon Schubert
14435796c8dcSSimon Schubert /* Skip rest of this symbol and return an error type.
14445796c8dcSSimon Schubert
14455796c8dcSSimon Schubert General notes on error recovery: error_type always skips to the
14465796c8dcSSimon Schubert end of the symbol (modulo cretinous dbx symbol name continuation).
14475796c8dcSSimon Schubert Thus code like this:
14485796c8dcSSimon Schubert
14495796c8dcSSimon Schubert if (*(*pp)++ != ';')
14505796c8dcSSimon Schubert return error_type (pp, objfile);
14515796c8dcSSimon Schubert
14525796c8dcSSimon Schubert is wrong because if *pp starts out pointing at '\0' (typically as the
14535796c8dcSSimon Schubert result of an earlier error), it will be incremented to point to the
14545796c8dcSSimon Schubert start of the next symbol, which might produce strange results, at least
14555796c8dcSSimon Schubert if you run off the end of the string table. Instead use
14565796c8dcSSimon Schubert
14575796c8dcSSimon Schubert if (**pp != ';')
14585796c8dcSSimon Schubert return error_type (pp, objfile);
14595796c8dcSSimon Schubert ++*pp;
14605796c8dcSSimon Schubert
14615796c8dcSSimon Schubert or
14625796c8dcSSimon Schubert
14635796c8dcSSimon Schubert if (**pp != ';')
14645796c8dcSSimon Schubert foo = error_type (pp, objfile);
14655796c8dcSSimon Schubert else
14665796c8dcSSimon Schubert ++*pp;
14675796c8dcSSimon Schubert
14685796c8dcSSimon Schubert And in case it isn't obvious, the point of all this hair is so the compiler
14695796c8dcSSimon Schubert can define new types and new syntaxes, and old versions of the
14705796c8dcSSimon Schubert debugger will be able to read the new symbol tables. */
14715796c8dcSSimon Schubert
14725796c8dcSSimon Schubert static struct type *
error_type(char ** pp,struct objfile * objfile)14735796c8dcSSimon Schubert error_type (char **pp, struct objfile *objfile)
14745796c8dcSSimon Schubert {
1475c50c785cSJohn Marino complaint (&symfile_complaints,
1476c50c785cSJohn Marino _("couldn't parse type; debugger out of date?"));
14775796c8dcSSimon Schubert while (1)
14785796c8dcSSimon Schubert {
14795796c8dcSSimon Schubert /* Skip to end of symbol. */
14805796c8dcSSimon Schubert while (**pp != '\0')
14815796c8dcSSimon Schubert {
14825796c8dcSSimon Schubert (*pp)++;
14835796c8dcSSimon Schubert }
14845796c8dcSSimon Schubert
14855796c8dcSSimon Schubert /* Check for and handle cretinous dbx symbol name continuation! */
14865796c8dcSSimon Schubert if ((*pp)[-1] == '\\' || (*pp)[-1] == '?')
14875796c8dcSSimon Schubert {
14885796c8dcSSimon Schubert *pp = next_symbol_text (objfile);
14895796c8dcSSimon Schubert }
14905796c8dcSSimon Schubert else
14915796c8dcSSimon Schubert {
14925796c8dcSSimon Schubert break;
14935796c8dcSSimon Schubert }
14945796c8dcSSimon Schubert }
14955796c8dcSSimon Schubert return objfile_type (objfile)->builtin_error;
14965796c8dcSSimon Schubert }
14975796c8dcSSimon Schubert
14985796c8dcSSimon Schubert
14995796c8dcSSimon Schubert /* Read type information or a type definition; return the type. Even
15005796c8dcSSimon Schubert though this routine accepts either type information or a type
15015796c8dcSSimon Schubert definition, the distinction is relevant--some parts of stabsread.c
15025796c8dcSSimon Schubert assume that type information starts with a digit, '-', or '(' in
15035796c8dcSSimon Schubert deciding whether to call read_type. */
15045796c8dcSSimon Schubert
15055796c8dcSSimon Schubert static struct type *
read_type(char ** pp,struct objfile * objfile)15065796c8dcSSimon Schubert read_type (char **pp, struct objfile *objfile)
15075796c8dcSSimon Schubert {
15085796c8dcSSimon Schubert struct type *type = 0;
15095796c8dcSSimon Schubert struct type *type1;
15105796c8dcSSimon Schubert int typenums[2];
15115796c8dcSSimon Schubert char type_descriptor;
15125796c8dcSSimon Schubert
15135796c8dcSSimon Schubert /* Size in bits of type if specified by a type attribute, or -1 if
15145796c8dcSSimon Schubert there is no size attribute. */
15155796c8dcSSimon Schubert int type_size = -1;
15165796c8dcSSimon Schubert
15175796c8dcSSimon Schubert /* Used to distinguish string and bitstring from char-array and set. */
15185796c8dcSSimon Schubert int is_string = 0;
15195796c8dcSSimon Schubert
15205796c8dcSSimon Schubert /* Used to distinguish vector from array. */
15215796c8dcSSimon Schubert int is_vector = 0;
15225796c8dcSSimon Schubert
15235796c8dcSSimon Schubert /* Read type number if present. The type number may be omitted.
15245796c8dcSSimon Schubert for instance in a two-dimensional array declared with type
15255796c8dcSSimon Schubert "ar1;1;10;ar1;1;10;4". */
15265796c8dcSSimon Schubert if ((**pp >= '0' && **pp <= '9')
15275796c8dcSSimon Schubert || **pp == '('
15285796c8dcSSimon Schubert || **pp == '-')
15295796c8dcSSimon Schubert {
15305796c8dcSSimon Schubert if (read_type_number (pp, typenums) != 0)
15315796c8dcSSimon Schubert return error_type (pp, objfile);
15325796c8dcSSimon Schubert
15335796c8dcSSimon Schubert if (**pp != '=')
15345796c8dcSSimon Schubert {
15355796c8dcSSimon Schubert /* Type is not being defined here. Either it already
15365796c8dcSSimon Schubert exists, or this is a forward reference to it.
15375796c8dcSSimon Schubert dbx_alloc_type handles both cases. */
15385796c8dcSSimon Schubert type = dbx_alloc_type (typenums, objfile);
15395796c8dcSSimon Schubert
15405796c8dcSSimon Schubert /* If this is a forward reference, arrange to complain if it
15415796c8dcSSimon Schubert doesn't get patched up by the time we're done
15425796c8dcSSimon Schubert reading. */
15435796c8dcSSimon Schubert if (TYPE_CODE (type) == TYPE_CODE_UNDEF)
15445796c8dcSSimon Schubert add_undefined_type (type, typenums);
15455796c8dcSSimon Schubert
15465796c8dcSSimon Schubert return type;
15475796c8dcSSimon Schubert }
15485796c8dcSSimon Schubert
15495796c8dcSSimon Schubert /* Type is being defined here. */
15505796c8dcSSimon Schubert /* Skip the '='.
15515796c8dcSSimon Schubert Also skip the type descriptor - we get it below with (*pp)[-1]. */
15525796c8dcSSimon Schubert (*pp) += 2;
15535796c8dcSSimon Schubert }
15545796c8dcSSimon Schubert else
15555796c8dcSSimon Schubert {
15565796c8dcSSimon Schubert /* 'typenums=' not present, type is anonymous. Read and return
15575796c8dcSSimon Schubert the definition, but don't put it in the type vector. */
15585796c8dcSSimon Schubert typenums[0] = typenums[1] = -1;
15595796c8dcSSimon Schubert (*pp)++;
15605796c8dcSSimon Schubert }
15615796c8dcSSimon Schubert
15625796c8dcSSimon Schubert again:
15635796c8dcSSimon Schubert type_descriptor = (*pp)[-1];
15645796c8dcSSimon Schubert switch (type_descriptor)
15655796c8dcSSimon Schubert {
15665796c8dcSSimon Schubert case 'x':
15675796c8dcSSimon Schubert {
15685796c8dcSSimon Schubert enum type_code code;
15695796c8dcSSimon Schubert
15705796c8dcSSimon Schubert /* Used to index through file_symbols. */
15715796c8dcSSimon Schubert struct pending *ppt;
15725796c8dcSSimon Schubert int i;
15735796c8dcSSimon Schubert
15745796c8dcSSimon Schubert /* Name including "struct", etc. */
15755796c8dcSSimon Schubert char *type_name;
15765796c8dcSSimon Schubert
15775796c8dcSSimon Schubert {
15785796c8dcSSimon Schubert char *from, *to, *p, *q1, *q2;
15795796c8dcSSimon Schubert
15805796c8dcSSimon Schubert /* Set the type code according to the following letter. */
15815796c8dcSSimon Schubert switch ((*pp)[0])
15825796c8dcSSimon Schubert {
15835796c8dcSSimon Schubert case 's':
15845796c8dcSSimon Schubert code = TYPE_CODE_STRUCT;
15855796c8dcSSimon Schubert break;
15865796c8dcSSimon Schubert case 'u':
15875796c8dcSSimon Schubert code = TYPE_CODE_UNION;
15885796c8dcSSimon Schubert break;
15895796c8dcSSimon Schubert case 'e':
15905796c8dcSSimon Schubert code = TYPE_CODE_ENUM;
15915796c8dcSSimon Schubert break;
15925796c8dcSSimon Schubert default:
15935796c8dcSSimon Schubert {
15945796c8dcSSimon Schubert /* Complain and keep going, so compilers can invent new
15955796c8dcSSimon Schubert cross-reference types. */
15965796c8dcSSimon Schubert complaint (&symfile_complaints,
1597c50c785cSJohn Marino _("Unrecognized cross-reference type `%c'"),
1598c50c785cSJohn Marino (*pp)[0]);
15995796c8dcSSimon Schubert code = TYPE_CODE_STRUCT;
16005796c8dcSSimon Schubert break;
16015796c8dcSSimon Schubert }
16025796c8dcSSimon Schubert }
16035796c8dcSSimon Schubert
16045796c8dcSSimon Schubert q1 = strchr (*pp, '<');
16055796c8dcSSimon Schubert p = strchr (*pp, ':');
16065796c8dcSSimon Schubert if (p == NULL)
16075796c8dcSSimon Schubert return error_type (pp, objfile);
16085796c8dcSSimon Schubert if (q1 && p > q1 && p[1] == ':')
16095796c8dcSSimon Schubert {
16105796c8dcSSimon Schubert int nesting_level = 0;
1611cf7f2e2dSJohn Marino
16125796c8dcSSimon Schubert for (q2 = q1; *q2; q2++)
16135796c8dcSSimon Schubert {
16145796c8dcSSimon Schubert if (*q2 == '<')
16155796c8dcSSimon Schubert nesting_level++;
16165796c8dcSSimon Schubert else if (*q2 == '>')
16175796c8dcSSimon Schubert nesting_level--;
16185796c8dcSSimon Schubert else if (*q2 == ':' && nesting_level == 0)
16195796c8dcSSimon Schubert break;
16205796c8dcSSimon Schubert }
16215796c8dcSSimon Schubert p = q2;
16225796c8dcSSimon Schubert if (*p != ':')
16235796c8dcSSimon Schubert return error_type (pp, objfile);
16245796c8dcSSimon Schubert }
16255796c8dcSSimon Schubert type_name = NULL;
16265796c8dcSSimon Schubert if (current_subfile->language == language_cplus)
16275796c8dcSSimon Schubert {
16285796c8dcSSimon Schubert char *new_name, *name = alloca (p - *pp + 1);
1629cf7f2e2dSJohn Marino
16305796c8dcSSimon Schubert memcpy (name, *pp, p - *pp);
16315796c8dcSSimon Schubert name[p - *pp] = '\0';
16325796c8dcSSimon Schubert new_name = cp_canonicalize_string (name);
16335796c8dcSSimon Schubert if (new_name != NULL)
16345796c8dcSSimon Schubert {
1635*ef5ccd6cSJohn Marino type_name = obstack_copy0 (&objfile->objfile_obstack,
1636*ef5ccd6cSJohn Marino new_name, strlen (new_name));
16375796c8dcSSimon Schubert xfree (new_name);
16385796c8dcSSimon Schubert }
16395796c8dcSSimon Schubert }
16405796c8dcSSimon Schubert if (type_name == NULL)
16415796c8dcSSimon Schubert {
1642c50c785cSJohn Marino to = type_name = (char *)
1643c50c785cSJohn Marino obstack_alloc (&objfile->objfile_obstack, p - *pp + 1);
16445796c8dcSSimon Schubert
16455796c8dcSSimon Schubert /* Copy the name. */
16465796c8dcSSimon Schubert from = *pp + 1;
16475796c8dcSSimon Schubert while (from < p)
16485796c8dcSSimon Schubert *to++ = *from++;
16495796c8dcSSimon Schubert *to = '\0';
16505796c8dcSSimon Schubert }
16515796c8dcSSimon Schubert
16525796c8dcSSimon Schubert /* Set the pointer ahead of the name which we just read, and
16535796c8dcSSimon Schubert the colon. */
16545796c8dcSSimon Schubert *pp = p + 1;
16555796c8dcSSimon Schubert }
16565796c8dcSSimon Schubert
16575796c8dcSSimon Schubert /* If this type has already been declared, then reuse the same
16585796c8dcSSimon Schubert type, rather than allocating a new one. This saves some
16595796c8dcSSimon Schubert memory. */
16605796c8dcSSimon Schubert
16615796c8dcSSimon Schubert for (ppt = file_symbols; ppt; ppt = ppt->next)
16625796c8dcSSimon Schubert for (i = 0; i < ppt->nsyms; i++)
16635796c8dcSSimon Schubert {
16645796c8dcSSimon Schubert struct symbol *sym = ppt->symbol[i];
16655796c8dcSSimon Schubert
16665796c8dcSSimon Schubert if (SYMBOL_CLASS (sym) == LOC_TYPEDEF
16675796c8dcSSimon Schubert && SYMBOL_DOMAIN (sym) == STRUCT_DOMAIN
16685796c8dcSSimon Schubert && (TYPE_CODE (SYMBOL_TYPE (sym)) == code)
16695796c8dcSSimon Schubert && strcmp (SYMBOL_LINKAGE_NAME (sym), type_name) == 0)
16705796c8dcSSimon Schubert {
16715796c8dcSSimon Schubert obstack_free (&objfile->objfile_obstack, type_name);
16725796c8dcSSimon Schubert type = SYMBOL_TYPE (sym);
16735796c8dcSSimon Schubert if (typenums[0] != -1)
16745796c8dcSSimon Schubert *dbx_lookup_type (typenums, objfile) = type;
16755796c8dcSSimon Schubert return type;
16765796c8dcSSimon Schubert }
16775796c8dcSSimon Schubert }
16785796c8dcSSimon Schubert
16795796c8dcSSimon Schubert /* Didn't find the type to which this refers, so we must
16805796c8dcSSimon Schubert be dealing with a forward reference. Allocate a type
16815796c8dcSSimon Schubert structure for it, and keep track of it so we can
16825796c8dcSSimon Schubert fill in the rest of the fields when we get the full
16835796c8dcSSimon Schubert type. */
16845796c8dcSSimon Schubert type = dbx_alloc_type (typenums, objfile);
16855796c8dcSSimon Schubert TYPE_CODE (type) = code;
16865796c8dcSSimon Schubert TYPE_TAG_NAME (type) = type_name;
16875796c8dcSSimon Schubert INIT_CPLUS_SPECIFIC (type);
16885796c8dcSSimon Schubert TYPE_STUB (type) = 1;
16895796c8dcSSimon Schubert
16905796c8dcSSimon Schubert add_undefined_type (type, typenums);
16915796c8dcSSimon Schubert return type;
16925796c8dcSSimon Schubert }
16935796c8dcSSimon Schubert
16945796c8dcSSimon Schubert case '-': /* RS/6000 built-in type */
16955796c8dcSSimon Schubert case '0':
16965796c8dcSSimon Schubert case '1':
16975796c8dcSSimon Schubert case '2':
16985796c8dcSSimon Schubert case '3':
16995796c8dcSSimon Schubert case '4':
17005796c8dcSSimon Schubert case '5':
17015796c8dcSSimon Schubert case '6':
17025796c8dcSSimon Schubert case '7':
17035796c8dcSSimon Schubert case '8':
17045796c8dcSSimon Schubert case '9':
17055796c8dcSSimon Schubert case '(':
17065796c8dcSSimon Schubert (*pp)--;
17075796c8dcSSimon Schubert
17085796c8dcSSimon Schubert /* We deal with something like t(1,2)=(3,4)=... which
17095796c8dcSSimon Schubert the Lucid compiler and recent gcc versions (post 2.7.3) use. */
17105796c8dcSSimon Schubert
17115796c8dcSSimon Schubert /* Allocate and enter the typedef type first.
17125796c8dcSSimon Schubert This handles recursive types. */
17135796c8dcSSimon Schubert type = dbx_alloc_type (typenums, objfile);
17145796c8dcSSimon Schubert TYPE_CODE (type) = TYPE_CODE_TYPEDEF;
17155796c8dcSSimon Schubert {
17165796c8dcSSimon Schubert struct type *xtype = read_type (pp, objfile);
1717cf7f2e2dSJohn Marino
17185796c8dcSSimon Schubert if (type == xtype)
17195796c8dcSSimon Schubert {
17205796c8dcSSimon Schubert /* It's being defined as itself. That means it is "void". */
17215796c8dcSSimon Schubert TYPE_CODE (type) = TYPE_CODE_VOID;
17225796c8dcSSimon Schubert TYPE_LENGTH (type) = 1;
17235796c8dcSSimon Schubert }
17245796c8dcSSimon Schubert else if (type_size >= 0 || is_string)
17255796c8dcSSimon Schubert {
17265796c8dcSSimon Schubert /* This is the absolute wrong way to construct types. Every
17275796c8dcSSimon Schubert other debug format has found a way around this problem and
17285796c8dcSSimon Schubert the related problems with unnecessarily stubbed types;
17295796c8dcSSimon Schubert someone motivated should attempt to clean up the issue
17305796c8dcSSimon Schubert here as well. Once a type pointed to has been created it
17315796c8dcSSimon Schubert should not be modified.
17325796c8dcSSimon Schubert
17335796c8dcSSimon Schubert Well, it's not *absolutely* wrong. Constructing recursive
17345796c8dcSSimon Schubert types (trees, linked lists) necessarily entails modifying
17355796c8dcSSimon Schubert types after creating them. Constructing any loop structure
17365796c8dcSSimon Schubert entails side effects. The Dwarf 2 reader does handle this
17375796c8dcSSimon Schubert more gracefully (it never constructs more than once
17385796c8dcSSimon Schubert instance of a type object, so it doesn't have to copy type
17395796c8dcSSimon Schubert objects wholesale), but it still mutates type objects after
17405796c8dcSSimon Schubert other folks have references to them.
17415796c8dcSSimon Schubert
17425796c8dcSSimon Schubert Keep in mind that this circularity/mutation issue shows up
17435796c8dcSSimon Schubert at the source language level, too: C's "incomplete types",
17445796c8dcSSimon Schubert for example. So the proper cleanup, I think, would be to
17455796c8dcSSimon Schubert limit GDB's type smashing to match exactly those required
17465796c8dcSSimon Schubert by the source language. So GDB could have a
17475796c8dcSSimon Schubert "complete_this_type" function, but never create unnecessary
17485796c8dcSSimon Schubert copies of a type otherwise. */
17495796c8dcSSimon Schubert replace_type (type, xtype);
17505796c8dcSSimon Schubert TYPE_NAME (type) = NULL;
17515796c8dcSSimon Schubert TYPE_TAG_NAME (type) = NULL;
17525796c8dcSSimon Schubert }
17535796c8dcSSimon Schubert else
17545796c8dcSSimon Schubert {
17555796c8dcSSimon Schubert TYPE_TARGET_STUB (type) = 1;
17565796c8dcSSimon Schubert TYPE_TARGET_TYPE (type) = xtype;
17575796c8dcSSimon Schubert }
17585796c8dcSSimon Schubert }
17595796c8dcSSimon Schubert break;
17605796c8dcSSimon Schubert
17615796c8dcSSimon Schubert /* In the following types, we must be sure to overwrite any existing
17625796c8dcSSimon Schubert type that the typenums refer to, rather than allocating a new one
17635796c8dcSSimon Schubert and making the typenums point to the new one. This is because there
17645796c8dcSSimon Schubert may already be pointers to the existing type (if it had been
17655796c8dcSSimon Schubert forward-referenced), and we must change it to a pointer, function,
17665796c8dcSSimon Schubert reference, or whatever, *in-place*. */
17675796c8dcSSimon Schubert
17685796c8dcSSimon Schubert case '*': /* Pointer to another type */
17695796c8dcSSimon Schubert type1 = read_type (pp, objfile);
17705796c8dcSSimon Schubert type = make_pointer_type (type1, dbx_lookup_type (typenums, objfile));
17715796c8dcSSimon Schubert break;
17725796c8dcSSimon Schubert
17735796c8dcSSimon Schubert case '&': /* Reference to another type */
17745796c8dcSSimon Schubert type1 = read_type (pp, objfile);
17755796c8dcSSimon Schubert type = make_reference_type (type1, dbx_lookup_type (typenums, objfile));
17765796c8dcSSimon Schubert break;
17775796c8dcSSimon Schubert
17785796c8dcSSimon Schubert case 'f': /* Function returning another type */
17795796c8dcSSimon Schubert type1 = read_type (pp, objfile);
17805796c8dcSSimon Schubert type = make_function_type (type1, dbx_lookup_type (typenums, objfile));
17815796c8dcSSimon Schubert break;
17825796c8dcSSimon Schubert
17835796c8dcSSimon Schubert case 'g': /* Prototyped function. (Sun) */
17845796c8dcSSimon Schubert {
17855796c8dcSSimon Schubert /* Unresolved questions:
17865796c8dcSSimon Schubert
17875796c8dcSSimon Schubert - According to Sun's ``STABS Interface Manual'', for 'f'
17885796c8dcSSimon Schubert and 'F' symbol descriptors, a `0' in the argument type list
17895796c8dcSSimon Schubert indicates a varargs function. But it doesn't say how 'g'
17905796c8dcSSimon Schubert type descriptors represent that info. Someone with access
17915796c8dcSSimon Schubert to Sun's toolchain should try it out.
17925796c8dcSSimon Schubert
17935796c8dcSSimon Schubert - According to the comment in define_symbol (search for
17945796c8dcSSimon Schubert `process_prototype_types:'), Sun emits integer arguments as
17955796c8dcSSimon Schubert types which ref themselves --- like `void' types. Do we
17965796c8dcSSimon Schubert have to deal with that here, too? Again, someone with
17975796c8dcSSimon Schubert access to Sun's toolchain should try it out and let us
17985796c8dcSSimon Schubert know. */
17995796c8dcSSimon Schubert
18005796c8dcSSimon Schubert const char *type_start = (*pp) - 1;
18015796c8dcSSimon Schubert struct type *return_type = read_type (pp, objfile);
18025796c8dcSSimon Schubert struct type *func_type
18035796c8dcSSimon Schubert = make_function_type (return_type,
18045796c8dcSSimon Schubert dbx_lookup_type (typenums, objfile));
18055796c8dcSSimon Schubert struct type_list {
18065796c8dcSSimon Schubert struct type *type;
18075796c8dcSSimon Schubert struct type_list *next;
18085796c8dcSSimon Schubert } *arg_types = 0;
18095796c8dcSSimon Schubert int num_args = 0;
18105796c8dcSSimon Schubert
18115796c8dcSSimon Schubert while (**pp && **pp != '#')
18125796c8dcSSimon Schubert {
18135796c8dcSSimon Schubert struct type *arg_type = read_type (pp, objfile);
18145796c8dcSSimon Schubert struct type_list *new = alloca (sizeof (*new));
18155796c8dcSSimon Schubert new->type = arg_type;
18165796c8dcSSimon Schubert new->next = arg_types;
18175796c8dcSSimon Schubert arg_types = new;
18185796c8dcSSimon Schubert num_args++;
18195796c8dcSSimon Schubert }
18205796c8dcSSimon Schubert if (**pp == '#')
18215796c8dcSSimon Schubert ++*pp;
18225796c8dcSSimon Schubert else
18235796c8dcSSimon Schubert {
18245796c8dcSSimon Schubert complaint (&symfile_complaints,
1825c50c785cSJohn Marino _("Prototyped function type didn't "
1826c50c785cSJohn Marino "end arguments with `#':\n%s"),
18275796c8dcSSimon Schubert type_start);
18285796c8dcSSimon Schubert }
18295796c8dcSSimon Schubert
18305796c8dcSSimon Schubert /* If there is just one argument whose type is `void', then
18315796c8dcSSimon Schubert that's just an empty argument list. */
18325796c8dcSSimon Schubert if (arg_types
18335796c8dcSSimon Schubert && ! arg_types->next
18345796c8dcSSimon Schubert && TYPE_CODE (arg_types->type) == TYPE_CODE_VOID)
18355796c8dcSSimon Schubert num_args = 0;
18365796c8dcSSimon Schubert
18375796c8dcSSimon Schubert TYPE_FIELDS (func_type)
18385796c8dcSSimon Schubert = (struct field *) TYPE_ALLOC (func_type,
18395796c8dcSSimon Schubert num_args * sizeof (struct field));
18405796c8dcSSimon Schubert memset (TYPE_FIELDS (func_type), 0, num_args * sizeof (struct field));
18415796c8dcSSimon Schubert {
18425796c8dcSSimon Schubert int i;
18435796c8dcSSimon Schubert struct type_list *t;
18445796c8dcSSimon Schubert
18455796c8dcSSimon Schubert /* We stuck each argument type onto the front of the list
18465796c8dcSSimon Schubert when we read it, so the list is reversed. Build the
18475796c8dcSSimon Schubert fields array right-to-left. */
18485796c8dcSSimon Schubert for (t = arg_types, i = num_args - 1; t; t = t->next, i--)
18495796c8dcSSimon Schubert TYPE_FIELD_TYPE (func_type, i) = t->type;
18505796c8dcSSimon Schubert }
18515796c8dcSSimon Schubert TYPE_NFIELDS (func_type) = num_args;
18525796c8dcSSimon Schubert TYPE_PROTOTYPED (func_type) = 1;
18535796c8dcSSimon Schubert
18545796c8dcSSimon Schubert type = func_type;
18555796c8dcSSimon Schubert break;
18565796c8dcSSimon Schubert }
18575796c8dcSSimon Schubert
18585796c8dcSSimon Schubert case 'k': /* Const qualifier on some type (Sun) */
18595796c8dcSSimon Schubert type = read_type (pp, objfile);
18605796c8dcSSimon Schubert type = make_cv_type (1, TYPE_VOLATILE (type), type,
18615796c8dcSSimon Schubert dbx_lookup_type (typenums, objfile));
18625796c8dcSSimon Schubert break;
18635796c8dcSSimon Schubert
18645796c8dcSSimon Schubert case 'B': /* Volatile qual on some type (Sun) */
18655796c8dcSSimon Schubert type = read_type (pp, objfile);
18665796c8dcSSimon Schubert type = make_cv_type (TYPE_CONST (type), 1, type,
18675796c8dcSSimon Schubert dbx_lookup_type (typenums, objfile));
18685796c8dcSSimon Schubert break;
18695796c8dcSSimon Schubert
18705796c8dcSSimon Schubert case '@':
18715796c8dcSSimon Schubert if (isdigit (**pp) || **pp == '(' || **pp == '-')
18725796c8dcSSimon Schubert { /* Member (class & variable) type */
18735796c8dcSSimon Schubert /* FIXME -- we should be doing smash_to_XXX types here. */
18745796c8dcSSimon Schubert
18755796c8dcSSimon Schubert struct type *domain = read_type (pp, objfile);
18765796c8dcSSimon Schubert struct type *memtype;
18775796c8dcSSimon Schubert
18785796c8dcSSimon Schubert if (**pp != ',')
18795796c8dcSSimon Schubert /* Invalid member type data format. */
18805796c8dcSSimon Schubert return error_type (pp, objfile);
18815796c8dcSSimon Schubert ++*pp;
18825796c8dcSSimon Schubert
18835796c8dcSSimon Schubert memtype = read_type (pp, objfile);
18845796c8dcSSimon Schubert type = dbx_alloc_type (typenums, objfile);
18855796c8dcSSimon Schubert smash_to_memberptr_type (type, domain, memtype);
18865796c8dcSSimon Schubert }
18875796c8dcSSimon Schubert else
18885796c8dcSSimon Schubert /* type attribute */
18895796c8dcSSimon Schubert {
18905796c8dcSSimon Schubert char *attr = *pp;
1891cf7f2e2dSJohn Marino
18925796c8dcSSimon Schubert /* Skip to the semicolon. */
18935796c8dcSSimon Schubert while (**pp != ';' && **pp != '\0')
18945796c8dcSSimon Schubert ++(*pp);
18955796c8dcSSimon Schubert if (**pp == '\0')
18965796c8dcSSimon Schubert return error_type (pp, objfile);
18975796c8dcSSimon Schubert else
18985796c8dcSSimon Schubert ++ * pp; /* Skip the semicolon. */
18995796c8dcSSimon Schubert
19005796c8dcSSimon Schubert switch (*attr)
19015796c8dcSSimon Schubert {
19025796c8dcSSimon Schubert case 's': /* Size attribute */
19035796c8dcSSimon Schubert type_size = atoi (attr + 1);
19045796c8dcSSimon Schubert if (type_size <= 0)
19055796c8dcSSimon Schubert type_size = -1;
19065796c8dcSSimon Schubert break;
19075796c8dcSSimon Schubert
19085796c8dcSSimon Schubert case 'S': /* String attribute */
19095796c8dcSSimon Schubert /* FIXME: check to see if following type is array? */
19105796c8dcSSimon Schubert is_string = 1;
19115796c8dcSSimon Schubert break;
19125796c8dcSSimon Schubert
19135796c8dcSSimon Schubert case 'V': /* Vector attribute */
19145796c8dcSSimon Schubert /* FIXME: check to see if following type is array? */
19155796c8dcSSimon Schubert is_vector = 1;
19165796c8dcSSimon Schubert break;
19175796c8dcSSimon Schubert
19185796c8dcSSimon Schubert default:
19195796c8dcSSimon Schubert /* Ignore unrecognized type attributes, so future compilers
19205796c8dcSSimon Schubert can invent new ones. */
19215796c8dcSSimon Schubert break;
19225796c8dcSSimon Schubert }
19235796c8dcSSimon Schubert ++*pp;
19245796c8dcSSimon Schubert goto again;
19255796c8dcSSimon Schubert }
19265796c8dcSSimon Schubert break;
19275796c8dcSSimon Schubert
19285796c8dcSSimon Schubert case '#': /* Method (class & fn) type */
19295796c8dcSSimon Schubert if ((*pp)[0] == '#')
19305796c8dcSSimon Schubert {
19315796c8dcSSimon Schubert /* We'll get the parameter types from the name. */
19325796c8dcSSimon Schubert struct type *return_type;
19335796c8dcSSimon Schubert
19345796c8dcSSimon Schubert (*pp)++;
19355796c8dcSSimon Schubert return_type = read_type (pp, objfile);
19365796c8dcSSimon Schubert if (*(*pp)++ != ';')
19375796c8dcSSimon Schubert complaint (&symfile_complaints,
1938c50c785cSJohn Marino _("invalid (minimal) member type "
1939c50c785cSJohn Marino "data format at symtab pos %d."),
19405796c8dcSSimon Schubert symnum);
19415796c8dcSSimon Schubert type = allocate_stub_method (return_type);
19425796c8dcSSimon Schubert if (typenums[0] != -1)
19435796c8dcSSimon Schubert *dbx_lookup_type (typenums, objfile) = type;
19445796c8dcSSimon Schubert }
19455796c8dcSSimon Schubert else
19465796c8dcSSimon Schubert {
19475796c8dcSSimon Schubert struct type *domain = read_type (pp, objfile);
19485796c8dcSSimon Schubert struct type *return_type;
19495796c8dcSSimon Schubert struct field *args;
19505796c8dcSSimon Schubert int nargs, varargs;
19515796c8dcSSimon Schubert
19525796c8dcSSimon Schubert if (**pp != ',')
19535796c8dcSSimon Schubert /* Invalid member type data format. */
19545796c8dcSSimon Schubert return error_type (pp, objfile);
19555796c8dcSSimon Schubert else
19565796c8dcSSimon Schubert ++(*pp);
19575796c8dcSSimon Schubert
19585796c8dcSSimon Schubert return_type = read_type (pp, objfile);
19595796c8dcSSimon Schubert args = read_args (pp, ';', objfile, &nargs, &varargs);
19605796c8dcSSimon Schubert if (args == NULL)
19615796c8dcSSimon Schubert return error_type (pp, objfile);
19625796c8dcSSimon Schubert type = dbx_alloc_type (typenums, objfile);
19635796c8dcSSimon Schubert smash_to_method_type (type, domain, return_type, args,
19645796c8dcSSimon Schubert nargs, varargs);
19655796c8dcSSimon Schubert }
19665796c8dcSSimon Schubert break;
19675796c8dcSSimon Schubert
19685796c8dcSSimon Schubert case 'r': /* Range type */
19695796c8dcSSimon Schubert type = read_range_type (pp, typenums, type_size, objfile);
19705796c8dcSSimon Schubert if (typenums[0] != -1)
19715796c8dcSSimon Schubert *dbx_lookup_type (typenums, objfile) = type;
19725796c8dcSSimon Schubert break;
19735796c8dcSSimon Schubert
19745796c8dcSSimon Schubert case 'b':
19755796c8dcSSimon Schubert {
19765796c8dcSSimon Schubert /* Sun ACC builtin int type */
19775796c8dcSSimon Schubert type = read_sun_builtin_type (pp, typenums, objfile);
19785796c8dcSSimon Schubert if (typenums[0] != -1)
19795796c8dcSSimon Schubert *dbx_lookup_type (typenums, objfile) = type;
19805796c8dcSSimon Schubert }
19815796c8dcSSimon Schubert break;
19825796c8dcSSimon Schubert
19835796c8dcSSimon Schubert case 'R': /* Sun ACC builtin float type */
19845796c8dcSSimon Schubert type = read_sun_floating_type (pp, typenums, objfile);
19855796c8dcSSimon Schubert if (typenums[0] != -1)
19865796c8dcSSimon Schubert *dbx_lookup_type (typenums, objfile) = type;
19875796c8dcSSimon Schubert break;
19885796c8dcSSimon Schubert
19895796c8dcSSimon Schubert case 'e': /* Enumeration type */
19905796c8dcSSimon Schubert type = dbx_alloc_type (typenums, objfile);
19915796c8dcSSimon Schubert type = read_enum_type (pp, type, objfile);
19925796c8dcSSimon Schubert if (typenums[0] != -1)
19935796c8dcSSimon Schubert *dbx_lookup_type (typenums, objfile) = type;
19945796c8dcSSimon Schubert break;
19955796c8dcSSimon Schubert
19965796c8dcSSimon Schubert case 's': /* Struct type */
19975796c8dcSSimon Schubert case 'u': /* Union type */
19985796c8dcSSimon Schubert {
19995796c8dcSSimon Schubert enum type_code type_code = TYPE_CODE_UNDEF;
20005796c8dcSSimon Schubert type = dbx_alloc_type (typenums, objfile);
20015796c8dcSSimon Schubert switch (type_descriptor)
20025796c8dcSSimon Schubert {
20035796c8dcSSimon Schubert case 's':
20045796c8dcSSimon Schubert type_code = TYPE_CODE_STRUCT;
20055796c8dcSSimon Schubert break;
20065796c8dcSSimon Schubert case 'u':
20075796c8dcSSimon Schubert type_code = TYPE_CODE_UNION;
20085796c8dcSSimon Schubert break;
20095796c8dcSSimon Schubert }
20105796c8dcSSimon Schubert type = read_struct_type (pp, type, type_code, objfile);
20115796c8dcSSimon Schubert break;
20125796c8dcSSimon Schubert }
20135796c8dcSSimon Schubert
20145796c8dcSSimon Schubert case 'a': /* Array type */
20155796c8dcSSimon Schubert if (**pp != 'r')
20165796c8dcSSimon Schubert return error_type (pp, objfile);
20175796c8dcSSimon Schubert ++*pp;
20185796c8dcSSimon Schubert
20195796c8dcSSimon Schubert type = dbx_alloc_type (typenums, objfile);
20205796c8dcSSimon Schubert type = read_array_type (pp, type, objfile);
20215796c8dcSSimon Schubert if (is_string)
20225796c8dcSSimon Schubert TYPE_CODE (type) = TYPE_CODE_STRING;
20235796c8dcSSimon Schubert if (is_vector)
20245796c8dcSSimon Schubert make_vector_type (type);
20255796c8dcSSimon Schubert break;
20265796c8dcSSimon Schubert
2027*ef5ccd6cSJohn Marino case 'S': /* Set type */
20285796c8dcSSimon Schubert type1 = read_type (pp, objfile);
20295796c8dcSSimon Schubert type = create_set_type ((struct type *) NULL, type1);
20305796c8dcSSimon Schubert if (typenums[0] != -1)
20315796c8dcSSimon Schubert *dbx_lookup_type (typenums, objfile) = type;
20325796c8dcSSimon Schubert break;
20335796c8dcSSimon Schubert
20345796c8dcSSimon Schubert default:
2035c50c785cSJohn Marino --*pp; /* Go back to the symbol in error. */
20365796c8dcSSimon Schubert /* Particularly important if it was \0! */
20375796c8dcSSimon Schubert return error_type (pp, objfile);
20385796c8dcSSimon Schubert }
20395796c8dcSSimon Schubert
20405796c8dcSSimon Schubert if (type == 0)
20415796c8dcSSimon Schubert {
20425796c8dcSSimon Schubert warning (_("GDB internal error, type is NULL in stabsread.c."));
20435796c8dcSSimon Schubert return error_type (pp, objfile);
20445796c8dcSSimon Schubert }
20455796c8dcSSimon Schubert
20465796c8dcSSimon Schubert /* Size specified in a type attribute overrides any other size. */
20475796c8dcSSimon Schubert if (type_size != -1)
20485796c8dcSSimon Schubert TYPE_LENGTH (type) = (type_size + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT;
20495796c8dcSSimon Schubert
20505796c8dcSSimon Schubert return type;
20515796c8dcSSimon Schubert }
20525796c8dcSSimon Schubert
20535796c8dcSSimon Schubert /* RS/6000 xlc/dbx combination uses a set of builtin types, starting from -1.
20545796c8dcSSimon Schubert Return the proper type node for a given builtin type number. */
20555796c8dcSSimon Schubert
20565796c8dcSSimon Schubert static const struct objfile_data *rs6000_builtin_type_data;
20575796c8dcSSimon Schubert
20585796c8dcSSimon Schubert static struct type *
rs6000_builtin_type(int typenum,struct objfile * objfile)20595796c8dcSSimon Schubert rs6000_builtin_type (int typenum, struct objfile *objfile)
20605796c8dcSSimon Schubert {
2061c50c785cSJohn Marino struct type **negative_types = objfile_data (objfile,
2062c50c785cSJohn Marino rs6000_builtin_type_data);
20635796c8dcSSimon Schubert
20645796c8dcSSimon Schubert /* We recognize types numbered from -NUMBER_RECOGNIZED to -1. */
20655796c8dcSSimon Schubert #define NUMBER_RECOGNIZED 34
20665796c8dcSSimon Schubert struct type *rettype = NULL;
20675796c8dcSSimon Schubert
20685796c8dcSSimon Schubert if (typenum >= 0 || typenum < -NUMBER_RECOGNIZED)
20695796c8dcSSimon Schubert {
20705796c8dcSSimon Schubert complaint (&symfile_complaints, _("Unknown builtin type %d"), typenum);
20715796c8dcSSimon Schubert return objfile_type (objfile)->builtin_error;
20725796c8dcSSimon Schubert }
20735796c8dcSSimon Schubert
20745796c8dcSSimon Schubert if (!negative_types)
20755796c8dcSSimon Schubert {
20765796c8dcSSimon Schubert /* This includes an empty slot for type number -0. */
20775796c8dcSSimon Schubert negative_types = OBSTACK_CALLOC (&objfile->objfile_obstack,
20785796c8dcSSimon Schubert NUMBER_RECOGNIZED + 1, struct type *);
20795796c8dcSSimon Schubert set_objfile_data (objfile, rs6000_builtin_type_data, negative_types);
20805796c8dcSSimon Schubert }
20815796c8dcSSimon Schubert
20825796c8dcSSimon Schubert if (negative_types[-typenum] != NULL)
20835796c8dcSSimon Schubert return negative_types[-typenum];
20845796c8dcSSimon Schubert
20855796c8dcSSimon Schubert #if TARGET_CHAR_BIT != 8
20865796c8dcSSimon Schubert #error This code wrong for TARGET_CHAR_BIT not 8
20875796c8dcSSimon Schubert /* These definitions all assume that TARGET_CHAR_BIT is 8. I think
20885796c8dcSSimon Schubert that if that ever becomes not true, the correct fix will be to
20895796c8dcSSimon Schubert make the size in the struct type to be in bits, not in units of
20905796c8dcSSimon Schubert TARGET_CHAR_BIT. */
20915796c8dcSSimon Schubert #endif
20925796c8dcSSimon Schubert
20935796c8dcSSimon Schubert switch (-typenum)
20945796c8dcSSimon Schubert {
20955796c8dcSSimon Schubert case 1:
20965796c8dcSSimon Schubert /* The size of this and all the other types are fixed, defined
20975796c8dcSSimon Schubert by the debugging format. If there is a type called "int" which
20985796c8dcSSimon Schubert is other than 32 bits, then it should use a new negative type
20995796c8dcSSimon Schubert number (or avoid negative type numbers for that case).
21005796c8dcSSimon Schubert See stabs.texinfo. */
21015796c8dcSSimon Schubert rettype = init_type (TYPE_CODE_INT, 4, 0, "int", objfile);
21025796c8dcSSimon Schubert break;
21035796c8dcSSimon Schubert case 2:
21045796c8dcSSimon Schubert rettype = init_type (TYPE_CODE_INT, 1, 0, "char", objfile);
21055796c8dcSSimon Schubert break;
21065796c8dcSSimon Schubert case 3:
21075796c8dcSSimon Schubert rettype = init_type (TYPE_CODE_INT, 2, 0, "short", objfile);
21085796c8dcSSimon Schubert break;
21095796c8dcSSimon Schubert case 4:
21105796c8dcSSimon Schubert rettype = init_type (TYPE_CODE_INT, 4, 0, "long", objfile);
21115796c8dcSSimon Schubert break;
21125796c8dcSSimon Schubert case 5:
21135796c8dcSSimon Schubert rettype = init_type (TYPE_CODE_INT, 1, TYPE_FLAG_UNSIGNED,
21145796c8dcSSimon Schubert "unsigned char", objfile);
21155796c8dcSSimon Schubert break;
21165796c8dcSSimon Schubert case 6:
21175796c8dcSSimon Schubert rettype = init_type (TYPE_CODE_INT, 1, 0, "signed char", objfile);
21185796c8dcSSimon Schubert break;
21195796c8dcSSimon Schubert case 7:
21205796c8dcSSimon Schubert rettype = init_type (TYPE_CODE_INT, 2, TYPE_FLAG_UNSIGNED,
21215796c8dcSSimon Schubert "unsigned short", objfile);
21225796c8dcSSimon Schubert break;
21235796c8dcSSimon Schubert case 8:
21245796c8dcSSimon Schubert rettype = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED,
21255796c8dcSSimon Schubert "unsigned int", objfile);
21265796c8dcSSimon Schubert break;
21275796c8dcSSimon Schubert case 9:
21285796c8dcSSimon Schubert rettype = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED,
21295796c8dcSSimon Schubert "unsigned", objfile);
2130c50c785cSJohn Marino break;
21315796c8dcSSimon Schubert case 10:
21325796c8dcSSimon Schubert rettype = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED,
21335796c8dcSSimon Schubert "unsigned long", objfile);
21345796c8dcSSimon Schubert break;
21355796c8dcSSimon Schubert case 11:
21365796c8dcSSimon Schubert rettype = init_type (TYPE_CODE_VOID, 1, 0, "void", objfile);
21375796c8dcSSimon Schubert break;
21385796c8dcSSimon Schubert case 12:
21395796c8dcSSimon Schubert /* IEEE single precision (32 bit). */
21405796c8dcSSimon Schubert rettype = init_type (TYPE_CODE_FLT, 4, 0, "float", objfile);
21415796c8dcSSimon Schubert break;
21425796c8dcSSimon Schubert case 13:
21435796c8dcSSimon Schubert /* IEEE double precision (64 bit). */
21445796c8dcSSimon Schubert rettype = init_type (TYPE_CODE_FLT, 8, 0, "double", objfile);
21455796c8dcSSimon Schubert break;
21465796c8dcSSimon Schubert case 14:
21475796c8dcSSimon Schubert /* This is an IEEE double on the RS/6000, and different machines with
21485796c8dcSSimon Schubert different sizes for "long double" should use different negative
21495796c8dcSSimon Schubert type numbers. See stabs.texinfo. */
21505796c8dcSSimon Schubert rettype = init_type (TYPE_CODE_FLT, 8, 0, "long double", objfile);
21515796c8dcSSimon Schubert break;
21525796c8dcSSimon Schubert case 15:
21535796c8dcSSimon Schubert rettype = init_type (TYPE_CODE_INT, 4, 0, "integer", objfile);
21545796c8dcSSimon Schubert break;
21555796c8dcSSimon Schubert case 16:
21565796c8dcSSimon Schubert rettype = init_type (TYPE_CODE_BOOL, 4, TYPE_FLAG_UNSIGNED,
21575796c8dcSSimon Schubert "boolean", objfile);
21585796c8dcSSimon Schubert break;
21595796c8dcSSimon Schubert case 17:
21605796c8dcSSimon Schubert rettype = init_type (TYPE_CODE_FLT, 4, 0, "short real", objfile);
21615796c8dcSSimon Schubert break;
21625796c8dcSSimon Schubert case 18:
21635796c8dcSSimon Schubert rettype = init_type (TYPE_CODE_FLT, 8, 0, "real", objfile);
21645796c8dcSSimon Schubert break;
21655796c8dcSSimon Schubert case 19:
21665796c8dcSSimon Schubert rettype = init_type (TYPE_CODE_ERROR, 0, 0, "stringptr", objfile);
21675796c8dcSSimon Schubert break;
21685796c8dcSSimon Schubert case 20:
21695796c8dcSSimon Schubert rettype = init_type (TYPE_CODE_CHAR, 1, TYPE_FLAG_UNSIGNED,
21705796c8dcSSimon Schubert "character", objfile);
21715796c8dcSSimon Schubert break;
21725796c8dcSSimon Schubert case 21:
21735796c8dcSSimon Schubert rettype = init_type (TYPE_CODE_BOOL, 1, TYPE_FLAG_UNSIGNED,
21745796c8dcSSimon Schubert "logical*1", objfile);
21755796c8dcSSimon Schubert break;
21765796c8dcSSimon Schubert case 22:
21775796c8dcSSimon Schubert rettype = init_type (TYPE_CODE_BOOL, 2, TYPE_FLAG_UNSIGNED,
21785796c8dcSSimon Schubert "logical*2", objfile);
21795796c8dcSSimon Schubert break;
21805796c8dcSSimon Schubert case 23:
21815796c8dcSSimon Schubert rettype = init_type (TYPE_CODE_BOOL, 4, TYPE_FLAG_UNSIGNED,
21825796c8dcSSimon Schubert "logical*4", objfile);
21835796c8dcSSimon Schubert break;
21845796c8dcSSimon Schubert case 24:
21855796c8dcSSimon Schubert rettype = init_type (TYPE_CODE_BOOL, 4, TYPE_FLAG_UNSIGNED,
21865796c8dcSSimon Schubert "logical", objfile);
21875796c8dcSSimon Schubert break;
21885796c8dcSSimon Schubert case 25:
21895796c8dcSSimon Schubert /* Complex type consisting of two IEEE single precision values. */
21905796c8dcSSimon Schubert rettype = init_type (TYPE_CODE_COMPLEX, 8, 0, "complex", objfile);
21915796c8dcSSimon Schubert TYPE_TARGET_TYPE (rettype) = init_type (TYPE_CODE_FLT, 4, 0, "float",
21925796c8dcSSimon Schubert objfile);
21935796c8dcSSimon Schubert break;
21945796c8dcSSimon Schubert case 26:
21955796c8dcSSimon Schubert /* Complex type consisting of two IEEE double precision values. */
21965796c8dcSSimon Schubert rettype = init_type (TYPE_CODE_COMPLEX, 16, 0, "double complex", NULL);
21975796c8dcSSimon Schubert TYPE_TARGET_TYPE (rettype) = init_type (TYPE_CODE_FLT, 8, 0, "double",
21985796c8dcSSimon Schubert objfile);
21995796c8dcSSimon Schubert break;
22005796c8dcSSimon Schubert case 27:
22015796c8dcSSimon Schubert rettype = init_type (TYPE_CODE_INT, 1, 0, "integer*1", objfile);
22025796c8dcSSimon Schubert break;
22035796c8dcSSimon Schubert case 28:
22045796c8dcSSimon Schubert rettype = init_type (TYPE_CODE_INT, 2, 0, "integer*2", objfile);
22055796c8dcSSimon Schubert break;
22065796c8dcSSimon Schubert case 29:
22075796c8dcSSimon Schubert rettype = init_type (TYPE_CODE_INT, 4, 0, "integer*4", objfile);
22085796c8dcSSimon Schubert break;
22095796c8dcSSimon Schubert case 30:
22105796c8dcSSimon Schubert rettype = init_type (TYPE_CODE_CHAR, 2, 0, "wchar", objfile);
22115796c8dcSSimon Schubert break;
22125796c8dcSSimon Schubert case 31:
22135796c8dcSSimon Schubert rettype = init_type (TYPE_CODE_INT, 8, 0, "long long", objfile);
22145796c8dcSSimon Schubert break;
22155796c8dcSSimon Schubert case 32:
22165796c8dcSSimon Schubert rettype = init_type (TYPE_CODE_INT, 8, TYPE_FLAG_UNSIGNED,
22175796c8dcSSimon Schubert "unsigned long long", objfile);
22185796c8dcSSimon Schubert break;
22195796c8dcSSimon Schubert case 33:
22205796c8dcSSimon Schubert rettype = init_type (TYPE_CODE_INT, 8, TYPE_FLAG_UNSIGNED,
22215796c8dcSSimon Schubert "logical*8", objfile);
22225796c8dcSSimon Schubert break;
22235796c8dcSSimon Schubert case 34:
22245796c8dcSSimon Schubert rettype = init_type (TYPE_CODE_INT, 8, 0, "integer*8", objfile);
22255796c8dcSSimon Schubert break;
22265796c8dcSSimon Schubert }
22275796c8dcSSimon Schubert negative_types[-typenum] = rettype;
22285796c8dcSSimon Schubert return rettype;
22295796c8dcSSimon Schubert }
22305796c8dcSSimon Schubert
22315796c8dcSSimon Schubert /* This page contains subroutines of read_type. */
22325796c8dcSSimon Schubert
2233*ef5ccd6cSJohn Marino /* Wrapper around method_name_from_physname to flag a complaint
2234*ef5ccd6cSJohn Marino if there is an error. */
22355796c8dcSSimon Schubert
2236*ef5ccd6cSJohn Marino static char *
stabs_method_name_from_physname(const char * physname)2237*ef5ccd6cSJohn Marino stabs_method_name_from_physname (const char *physname)
22385796c8dcSSimon Schubert {
22395796c8dcSSimon Schubert char *method_name;
22405796c8dcSSimon Schubert
22415796c8dcSSimon Schubert method_name = method_name_from_physname (physname);
22425796c8dcSSimon Schubert
22435796c8dcSSimon Schubert if (method_name == NULL)
22445796c8dcSSimon Schubert {
22455796c8dcSSimon Schubert complaint (&symfile_complaints,
22465796c8dcSSimon Schubert _("Method has bad physname %s\n"), physname);
2247*ef5ccd6cSJohn Marino return NULL;
22485796c8dcSSimon Schubert }
22495796c8dcSSimon Schubert
2250*ef5ccd6cSJohn Marino return method_name;
22515796c8dcSSimon Schubert }
22525796c8dcSSimon Schubert
22535796c8dcSSimon Schubert /* Read member function stabs info for C++ classes. The form of each member
22545796c8dcSSimon Schubert function data is:
22555796c8dcSSimon Schubert
22565796c8dcSSimon Schubert NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;
22575796c8dcSSimon Schubert
22585796c8dcSSimon Schubert An example with two member functions is:
22595796c8dcSSimon Schubert
22605796c8dcSSimon Schubert afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;
22615796c8dcSSimon Schubert
22625796c8dcSSimon Schubert For the case of overloaded operators, the format is op$::*.funcs, where
22635796c8dcSSimon Schubert $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
22645796c8dcSSimon Schubert name (such as `+=') and `.' marks the end of the operator name.
22655796c8dcSSimon Schubert
22665796c8dcSSimon Schubert Returns 1 for success, 0 for failure. */
22675796c8dcSSimon Schubert
22685796c8dcSSimon Schubert static int
read_member_functions(struct field_info * fip,char ** pp,struct type * type,struct objfile * objfile)22695796c8dcSSimon Schubert read_member_functions (struct field_info *fip, char **pp, struct type *type,
22705796c8dcSSimon Schubert struct objfile *objfile)
22715796c8dcSSimon Schubert {
22725796c8dcSSimon Schubert int nfn_fields = 0;
22735796c8dcSSimon Schubert int length = 0;
22745796c8dcSSimon Schubert int i;
22755796c8dcSSimon Schubert struct next_fnfield
22765796c8dcSSimon Schubert {
22775796c8dcSSimon Schubert struct next_fnfield *next;
22785796c8dcSSimon Schubert struct fn_field fn_field;
22795796c8dcSSimon Schubert }
22805796c8dcSSimon Schubert *sublist;
22815796c8dcSSimon Schubert struct type *look_ahead_type;
22825796c8dcSSimon Schubert struct next_fnfieldlist *new_fnlist;
22835796c8dcSSimon Schubert struct next_fnfield *new_sublist;
22845796c8dcSSimon Schubert char *main_fn_name;
22855796c8dcSSimon Schubert char *p;
22865796c8dcSSimon Schubert
22875796c8dcSSimon Schubert /* Process each list until we find something that is not a member function
22885796c8dcSSimon Schubert or find the end of the functions. */
22895796c8dcSSimon Schubert
22905796c8dcSSimon Schubert while (**pp != ';')
22915796c8dcSSimon Schubert {
22925796c8dcSSimon Schubert /* We should be positioned at the start of the function name.
22935796c8dcSSimon Schubert Scan forward to find the first ':' and if it is not the
22945796c8dcSSimon Schubert first of a "::" delimiter, then this is not a member function. */
22955796c8dcSSimon Schubert p = *pp;
22965796c8dcSSimon Schubert while (*p != ':')
22975796c8dcSSimon Schubert {
22985796c8dcSSimon Schubert p++;
22995796c8dcSSimon Schubert }
23005796c8dcSSimon Schubert if (p[1] != ':')
23015796c8dcSSimon Schubert {
23025796c8dcSSimon Schubert break;
23035796c8dcSSimon Schubert }
23045796c8dcSSimon Schubert
23055796c8dcSSimon Schubert sublist = NULL;
23065796c8dcSSimon Schubert look_ahead_type = NULL;
23075796c8dcSSimon Schubert length = 0;
23085796c8dcSSimon Schubert
23095796c8dcSSimon Schubert new_fnlist = (struct next_fnfieldlist *)
23105796c8dcSSimon Schubert xmalloc (sizeof (struct next_fnfieldlist));
23115796c8dcSSimon Schubert make_cleanup (xfree, new_fnlist);
23125796c8dcSSimon Schubert memset (new_fnlist, 0, sizeof (struct next_fnfieldlist));
23135796c8dcSSimon Schubert
23145796c8dcSSimon Schubert if ((*pp)[0] == 'o' && (*pp)[1] == 'p' && is_cplus_marker ((*pp)[2]))
23155796c8dcSSimon Schubert {
23165796c8dcSSimon Schubert /* This is a completely wierd case. In order to stuff in the
23175796c8dcSSimon Schubert names that might contain colons (the usual name delimiter),
23185796c8dcSSimon Schubert Mike Tiemann defined a different name format which is
23195796c8dcSSimon Schubert signalled if the identifier is "op$". In that case, the
23205796c8dcSSimon Schubert format is "op$::XXXX." where XXXX is the name. This is
23215796c8dcSSimon Schubert used for names like "+" or "=". YUUUUUUUK! FIXME! */
23225796c8dcSSimon Schubert /* This lets the user type "break operator+".
23235796c8dcSSimon Schubert We could just put in "+" as the name, but that wouldn't
23245796c8dcSSimon Schubert work for "*". */
23255796c8dcSSimon Schubert static char opname[32] = "op$";
23265796c8dcSSimon Schubert char *o = opname + 3;
23275796c8dcSSimon Schubert
23285796c8dcSSimon Schubert /* Skip past '::'. */
23295796c8dcSSimon Schubert *pp = p + 2;
23305796c8dcSSimon Schubert
23315796c8dcSSimon Schubert STABS_CONTINUE (pp, objfile);
23325796c8dcSSimon Schubert p = *pp;
23335796c8dcSSimon Schubert while (*p != '.')
23345796c8dcSSimon Schubert {
23355796c8dcSSimon Schubert *o++ = *p++;
23365796c8dcSSimon Schubert }
23375796c8dcSSimon Schubert main_fn_name = savestring (opname, o - opname);
23385796c8dcSSimon Schubert /* Skip past '.' */
23395796c8dcSSimon Schubert *pp = p + 1;
23405796c8dcSSimon Schubert }
23415796c8dcSSimon Schubert else
23425796c8dcSSimon Schubert {
23435796c8dcSSimon Schubert main_fn_name = savestring (*pp, p - *pp);
23445796c8dcSSimon Schubert /* Skip past '::'. */
23455796c8dcSSimon Schubert *pp = p + 2;
23465796c8dcSSimon Schubert }
23475796c8dcSSimon Schubert new_fnlist->fn_fieldlist.name = main_fn_name;
23485796c8dcSSimon Schubert
23495796c8dcSSimon Schubert do
23505796c8dcSSimon Schubert {
23515796c8dcSSimon Schubert new_sublist =
23525796c8dcSSimon Schubert (struct next_fnfield *) xmalloc (sizeof (struct next_fnfield));
23535796c8dcSSimon Schubert make_cleanup (xfree, new_sublist);
23545796c8dcSSimon Schubert memset (new_sublist, 0, sizeof (struct next_fnfield));
23555796c8dcSSimon Schubert
23565796c8dcSSimon Schubert /* Check for and handle cretinous dbx symbol name continuation! */
23575796c8dcSSimon Schubert if (look_ahead_type == NULL)
23585796c8dcSSimon Schubert {
23595796c8dcSSimon Schubert /* Normal case. */
23605796c8dcSSimon Schubert STABS_CONTINUE (pp, objfile);
23615796c8dcSSimon Schubert
23625796c8dcSSimon Schubert new_sublist->fn_field.type = read_type (pp, objfile);
23635796c8dcSSimon Schubert if (**pp != ':')
23645796c8dcSSimon Schubert {
23655796c8dcSSimon Schubert /* Invalid symtab info for member function. */
23665796c8dcSSimon Schubert return 0;
23675796c8dcSSimon Schubert }
23685796c8dcSSimon Schubert }
23695796c8dcSSimon Schubert else
23705796c8dcSSimon Schubert {
23715796c8dcSSimon Schubert /* g++ version 1 kludge */
23725796c8dcSSimon Schubert new_sublist->fn_field.type = look_ahead_type;
23735796c8dcSSimon Schubert look_ahead_type = NULL;
23745796c8dcSSimon Schubert }
23755796c8dcSSimon Schubert
23765796c8dcSSimon Schubert (*pp)++;
23775796c8dcSSimon Schubert p = *pp;
23785796c8dcSSimon Schubert while (*p != ';')
23795796c8dcSSimon Schubert {
23805796c8dcSSimon Schubert p++;
23815796c8dcSSimon Schubert }
23825796c8dcSSimon Schubert
23835796c8dcSSimon Schubert /* If this is just a stub, then we don't have the real name here. */
23845796c8dcSSimon Schubert
23855796c8dcSSimon Schubert if (TYPE_STUB (new_sublist->fn_field.type))
23865796c8dcSSimon Schubert {
23875796c8dcSSimon Schubert if (!TYPE_DOMAIN_TYPE (new_sublist->fn_field.type))
23885796c8dcSSimon Schubert TYPE_DOMAIN_TYPE (new_sublist->fn_field.type) = type;
23895796c8dcSSimon Schubert new_sublist->fn_field.is_stub = 1;
23905796c8dcSSimon Schubert }
23915796c8dcSSimon Schubert new_sublist->fn_field.physname = savestring (*pp, p - *pp);
23925796c8dcSSimon Schubert *pp = p + 1;
23935796c8dcSSimon Schubert
23945796c8dcSSimon Schubert /* Set this member function's visibility fields. */
23955796c8dcSSimon Schubert switch (*(*pp)++)
23965796c8dcSSimon Schubert {
23975796c8dcSSimon Schubert case VISIBILITY_PRIVATE:
23985796c8dcSSimon Schubert new_sublist->fn_field.is_private = 1;
23995796c8dcSSimon Schubert break;
24005796c8dcSSimon Schubert case VISIBILITY_PROTECTED:
24015796c8dcSSimon Schubert new_sublist->fn_field.is_protected = 1;
24025796c8dcSSimon Schubert break;
24035796c8dcSSimon Schubert }
24045796c8dcSSimon Schubert
24055796c8dcSSimon Schubert STABS_CONTINUE (pp, objfile);
24065796c8dcSSimon Schubert switch (**pp)
24075796c8dcSSimon Schubert {
24085796c8dcSSimon Schubert case 'A': /* Normal functions. */
24095796c8dcSSimon Schubert new_sublist->fn_field.is_const = 0;
24105796c8dcSSimon Schubert new_sublist->fn_field.is_volatile = 0;
24115796c8dcSSimon Schubert (*pp)++;
24125796c8dcSSimon Schubert break;
24135796c8dcSSimon Schubert case 'B': /* `const' member functions. */
24145796c8dcSSimon Schubert new_sublist->fn_field.is_const = 1;
24155796c8dcSSimon Schubert new_sublist->fn_field.is_volatile = 0;
24165796c8dcSSimon Schubert (*pp)++;
24175796c8dcSSimon Schubert break;
24185796c8dcSSimon Schubert case 'C': /* `volatile' member function. */
24195796c8dcSSimon Schubert new_sublist->fn_field.is_const = 0;
24205796c8dcSSimon Schubert new_sublist->fn_field.is_volatile = 1;
24215796c8dcSSimon Schubert (*pp)++;
24225796c8dcSSimon Schubert break;
24235796c8dcSSimon Schubert case 'D': /* `const volatile' member function. */
24245796c8dcSSimon Schubert new_sublist->fn_field.is_const = 1;
24255796c8dcSSimon Schubert new_sublist->fn_field.is_volatile = 1;
24265796c8dcSSimon Schubert (*pp)++;
24275796c8dcSSimon Schubert break;
2428c50c785cSJohn Marino case '*': /* File compiled with g++ version 1 --
2429c50c785cSJohn Marino no info. */
24305796c8dcSSimon Schubert case '?':
24315796c8dcSSimon Schubert case '.':
24325796c8dcSSimon Schubert break;
24335796c8dcSSimon Schubert default:
24345796c8dcSSimon Schubert complaint (&symfile_complaints,
2435c50c785cSJohn Marino _("const/volatile indicator missing, got '%c'"),
2436c50c785cSJohn Marino **pp);
24375796c8dcSSimon Schubert break;
24385796c8dcSSimon Schubert }
24395796c8dcSSimon Schubert
24405796c8dcSSimon Schubert switch (*(*pp)++)
24415796c8dcSSimon Schubert {
24425796c8dcSSimon Schubert case '*':
24435796c8dcSSimon Schubert {
24445796c8dcSSimon Schubert int nbits;
24455796c8dcSSimon Schubert /* virtual member function, followed by index.
24465796c8dcSSimon Schubert The sign bit is set to distinguish pointers-to-methods
24475796c8dcSSimon Schubert from virtual function indicies. Since the array is
24485796c8dcSSimon Schubert in words, the quantity must be shifted left by 1
24495796c8dcSSimon Schubert on 16 bit machine, and by 2 on 32 bit machine, forcing
24505796c8dcSSimon Schubert the sign bit out, and usable as a valid index into
24515796c8dcSSimon Schubert the array. Remove the sign bit here. */
24525796c8dcSSimon Schubert new_sublist->fn_field.voffset =
24535796c8dcSSimon Schubert (0x7fffffff & read_huge_number (pp, ';', &nbits, 0)) + 2;
24545796c8dcSSimon Schubert if (nbits != 0)
24555796c8dcSSimon Schubert return 0;
24565796c8dcSSimon Schubert
24575796c8dcSSimon Schubert STABS_CONTINUE (pp, objfile);
24585796c8dcSSimon Schubert if (**pp == ';' || **pp == '\0')
24595796c8dcSSimon Schubert {
24605796c8dcSSimon Schubert /* Must be g++ version 1. */
24615796c8dcSSimon Schubert new_sublist->fn_field.fcontext = 0;
24625796c8dcSSimon Schubert }
24635796c8dcSSimon Schubert else
24645796c8dcSSimon Schubert {
24655796c8dcSSimon Schubert /* Figure out from whence this virtual function came.
24665796c8dcSSimon Schubert It may belong to virtual function table of
24675796c8dcSSimon Schubert one of its baseclasses. */
24685796c8dcSSimon Schubert look_ahead_type = read_type (pp, objfile);
24695796c8dcSSimon Schubert if (**pp == ':')
24705796c8dcSSimon Schubert {
24715796c8dcSSimon Schubert /* g++ version 1 overloaded methods. */
24725796c8dcSSimon Schubert }
24735796c8dcSSimon Schubert else
24745796c8dcSSimon Schubert {
24755796c8dcSSimon Schubert new_sublist->fn_field.fcontext = look_ahead_type;
24765796c8dcSSimon Schubert if (**pp != ';')
24775796c8dcSSimon Schubert {
24785796c8dcSSimon Schubert return 0;
24795796c8dcSSimon Schubert }
24805796c8dcSSimon Schubert else
24815796c8dcSSimon Schubert {
24825796c8dcSSimon Schubert ++*pp;
24835796c8dcSSimon Schubert }
24845796c8dcSSimon Schubert look_ahead_type = NULL;
24855796c8dcSSimon Schubert }
24865796c8dcSSimon Schubert }
24875796c8dcSSimon Schubert break;
24885796c8dcSSimon Schubert }
24895796c8dcSSimon Schubert case '?':
24905796c8dcSSimon Schubert /* static member function. */
24915796c8dcSSimon Schubert {
24925796c8dcSSimon Schubert int slen = strlen (main_fn_name);
24935796c8dcSSimon Schubert
24945796c8dcSSimon Schubert new_sublist->fn_field.voffset = VOFFSET_STATIC;
24955796c8dcSSimon Schubert
24965796c8dcSSimon Schubert /* For static member functions, we can't tell if they
24975796c8dcSSimon Schubert are stubbed, as they are put out as functions, and not as
24985796c8dcSSimon Schubert methods.
24995796c8dcSSimon Schubert GCC v2 emits the fully mangled name if
25005796c8dcSSimon Schubert dbxout.c:flag_minimal_debug is not set, so we have to
25015796c8dcSSimon Schubert detect a fully mangled physname here and set is_stub
25025796c8dcSSimon Schubert accordingly. Fully mangled physnames in v2 start with
25035796c8dcSSimon Schubert the member function name, followed by two underscores.
25045796c8dcSSimon Schubert GCC v3 currently always emits stubbed member functions,
25055796c8dcSSimon Schubert but with fully mangled physnames, which start with _Z. */
25065796c8dcSSimon Schubert if (!(strncmp (new_sublist->fn_field.physname,
25075796c8dcSSimon Schubert main_fn_name, slen) == 0
25085796c8dcSSimon Schubert && new_sublist->fn_field.physname[slen] == '_'
25095796c8dcSSimon Schubert && new_sublist->fn_field.physname[slen + 1] == '_'))
25105796c8dcSSimon Schubert {
25115796c8dcSSimon Schubert new_sublist->fn_field.is_stub = 1;
25125796c8dcSSimon Schubert }
25135796c8dcSSimon Schubert break;
25145796c8dcSSimon Schubert }
25155796c8dcSSimon Schubert
25165796c8dcSSimon Schubert default:
25175796c8dcSSimon Schubert /* error */
25185796c8dcSSimon Schubert complaint (&symfile_complaints,
2519c50c785cSJohn Marino _("member function type missing, got '%c'"),
2520c50c785cSJohn Marino (*pp)[-1]);
25215796c8dcSSimon Schubert /* Fall through into normal member function. */
25225796c8dcSSimon Schubert
25235796c8dcSSimon Schubert case '.':
25245796c8dcSSimon Schubert /* normal member function. */
25255796c8dcSSimon Schubert new_sublist->fn_field.voffset = 0;
25265796c8dcSSimon Schubert new_sublist->fn_field.fcontext = 0;
25275796c8dcSSimon Schubert break;
25285796c8dcSSimon Schubert }
25295796c8dcSSimon Schubert
25305796c8dcSSimon Schubert new_sublist->next = sublist;
25315796c8dcSSimon Schubert sublist = new_sublist;
25325796c8dcSSimon Schubert length++;
25335796c8dcSSimon Schubert STABS_CONTINUE (pp, objfile);
25345796c8dcSSimon Schubert }
25355796c8dcSSimon Schubert while (**pp != ';' && **pp != '\0');
25365796c8dcSSimon Schubert
25375796c8dcSSimon Schubert (*pp)++;
25385796c8dcSSimon Schubert STABS_CONTINUE (pp, objfile);
25395796c8dcSSimon Schubert
25405796c8dcSSimon Schubert /* Skip GCC 3.X member functions which are duplicates of the callable
25415796c8dcSSimon Schubert constructor/destructor. */
25425796c8dcSSimon Schubert if (strcmp_iw (main_fn_name, "__base_ctor ") == 0
25435796c8dcSSimon Schubert || strcmp_iw (main_fn_name, "__base_dtor ") == 0
25445796c8dcSSimon Schubert || strcmp (main_fn_name, "__deleting_dtor") == 0)
25455796c8dcSSimon Schubert {
25465796c8dcSSimon Schubert xfree (main_fn_name);
25475796c8dcSSimon Schubert }
25485796c8dcSSimon Schubert else
25495796c8dcSSimon Schubert {
25505796c8dcSSimon Schubert int has_stub = 0;
25515796c8dcSSimon Schubert int has_destructor = 0, has_other = 0;
25525796c8dcSSimon Schubert int is_v3 = 0;
25535796c8dcSSimon Schubert struct next_fnfield *tmp_sublist;
25545796c8dcSSimon Schubert
25555796c8dcSSimon Schubert /* Various versions of GCC emit various mostly-useless
25565796c8dcSSimon Schubert strings in the name field for special member functions.
25575796c8dcSSimon Schubert
25585796c8dcSSimon Schubert For stub methods, we need to defer correcting the name
25595796c8dcSSimon Schubert until we are ready to unstub the method, because the current
25605796c8dcSSimon Schubert name string is used by gdb_mangle_name. The only stub methods
25615796c8dcSSimon Schubert of concern here are GNU v2 operators; other methods have their
25625796c8dcSSimon Schubert names correct (see caveat below).
25635796c8dcSSimon Schubert
25645796c8dcSSimon Schubert For non-stub methods, in GNU v3, we have a complete physname.
25655796c8dcSSimon Schubert Therefore we can safely correct the name now. This primarily
25665796c8dcSSimon Schubert affects constructors and destructors, whose name will be
25675796c8dcSSimon Schubert __comp_ctor or __comp_dtor instead of Foo or ~Foo. Cast
25685796c8dcSSimon Schubert operators will also have incorrect names; for instance,
25695796c8dcSSimon Schubert "operator int" will be named "operator i" (i.e. the type is
25705796c8dcSSimon Schubert mangled).
25715796c8dcSSimon Schubert
25725796c8dcSSimon Schubert For non-stub methods in GNU v2, we have no easy way to
25735796c8dcSSimon Schubert know if we have a complete physname or not. For most
25745796c8dcSSimon Schubert methods the result depends on the platform (if CPLUS_MARKER
25755796c8dcSSimon Schubert can be `$' or `.', it will use minimal debug information, or
25765796c8dcSSimon Schubert otherwise the full physname will be included).
25775796c8dcSSimon Schubert
25785796c8dcSSimon Schubert Rather than dealing with this, we take a different approach.
25795796c8dcSSimon Schubert For v3 mangled names, we can use the full physname; for v2,
25805796c8dcSSimon Schubert we use cplus_demangle_opname (which is actually v2 specific),
25815796c8dcSSimon Schubert because the only interesting names are all operators - once again
25825796c8dcSSimon Schubert barring the caveat below. Skip this process if any method in the
25835796c8dcSSimon Schubert group is a stub, to prevent our fouling up the workings of
25845796c8dcSSimon Schubert gdb_mangle_name.
25855796c8dcSSimon Schubert
25865796c8dcSSimon Schubert The caveat: GCC 2.95.x (and earlier?) put constructors and
25875796c8dcSSimon Schubert destructors in the same method group. We need to split this
25885796c8dcSSimon Schubert into two groups, because they should have different names.
25895796c8dcSSimon Schubert So for each method group we check whether it contains both
25905796c8dcSSimon Schubert routines whose physname appears to be a destructor (the physnames
25915796c8dcSSimon Schubert for and destructors are always provided, due to quirks in v2
25925796c8dcSSimon Schubert mangling) and routines whose physname does not appear to be a
25935796c8dcSSimon Schubert destructor. If so then we break up the list into two halves.
25945796c8dcSSimon Schubert Even if the constructors and destructors aren't in the same group
25955796c8dcSSimon Schubert the destructor will still lack the leading tilde, so that also
25965796c8dcSSimon Schubert needs to be fixed.
25975796c8dcSSimon Schubert
25985796c8dcSSimon Schubert So, to summarize what we expect and handle here:
25995796c8dcSSimon Schubert
26005796c8dcSSimon Schubert Given Given Real Real Action
26015796c8dcSSimon Schubert method name physname physname method name
26025796c8dcSSimon Schubert
26035796c8dcSSimon Schubert __opi [none] __opi__3Foo operator int opname
26045796c8dcSSimon Schubert [now or later]
26055796c8dcSSimon Schubert Foo _._3Foo _._3Foo ~Foo separate and
26065796c8dcSSimon Schubert rename
26075796c8dcSSimon Schubert operator i _ZN3FoocviEv _ZN3FoocviEv operator int demangle
26085796c8dcSSimon Schubert __comp_ctor _ZN3FooC1ERKS_ _ZN3FooC1ERKS_ Foo demangle
26095796c8dcSSimon Schubert */
26105796c8dcSSimon Schubert
26115796c8dcSSimon Schubert tmp_sublist = sublist;
26125796c8dcSSimon Schubert while (tmp_sublist != NULL)
26135796c8dcSSimon Schubert {
26145796c8dcSSimon Schubert if (tmp_sublist->fn_field.is_stub)
26155796c8dcSSimon Schubert has_stub = 1;
26165796c8dcSSimon Schubert if (tmp_sublist->fn_field.physname[0] == '_'
26175796c8dcSSimon Schubert && tmp_sublist->fn_field.physname[1] == 'Z')
26185796c8dcSSimon Schubert is_v3 = 1;
26195796c8dcSSimon Schubert
26205796c8dcSSimon Schubert if (is_destructor_name (tmp_sublist->fn_field.physname))
26215796c8dcSSimon Schubert has_destructor++;
26225796c8dcSSimon Schubert else
26235796c8dcSSimon Schubert has_other++;
26245796c8dcSSimon Schubert
26255796c8dcSSimon Schubert tmp_sublist = tmp_sublist->next;
26265796c8dcSSimon Schubert }
26275796c8dcSSimon Schubert
26285796c8dcSSimon Schubert if (has_destructor && has_other)
26295796c8dcSSimon Schubert {
26305796c8dcSSimon Schubert struct next_fnfieldlist *destr_fnlist;
26315796c8dcSSimon Schubert struct next_fnfield *last_sublist;
26325796c8dcSSimon Schubert
26335796c8dcSSimon Schubert /* Create a new fn_fieldlist for the destructors. */
26345796c8dcSSimon Schubert
26355796c8dcSSimon Schubert destr_fnlist = (struct next_fnfieldlist *)
26365796c8dcSSimon Schubert xmalloc (sizeof (struct next_fnfieldlist));
26375796c8dcSSimon Schubert make_cleanup (xfree, destr_fnlist);
26385796c8dcSSimon Schubert memset (destr_fnlist, 0, sizeof (struct next_fnfieldlist));
26395796c8dcSSimon Schubert destr_fnlist->fn_fieldlist.name
2640cf7f2e2dSJohn Marino = obconcat (&objfile->objfile_obstack, "~",
2641cf7f2e2dSJohn Marino new_fnlist->fn_fieldlist.name, (char *) NULL);
26425796c8dcSSimon Schubert
26435796c8dcSSimon Schubert destr_fnlist->fn_fieldlist.fn_fields = (struct fn_field *)
26445796c8dcSSimon Schubert obstack_alloc (&objfile->objfile_obstack,
26455796c8dcSSimon Schubert sizeof (struct fn_field) * has_destructor);
26465796c8dcSSimon Schubert memset (destr_fnlist->fn_fieldlist.fn_fields, 0,
26475796c8dcSSimon Schubert sizeof (struct fn_field) * has_destructor);
26485796c8dcSSimon Schubert tmp_sublist = sublist;
26495796c8dcSSimon Schubert last_sublist = NULL;
26505796c8dcSSimon Schubert i = 0;
26515796c8dcSSimon Schubert while (tmp_sublist != NULL)
26525796c8dcSSimon Schubert {
26535796c8dcSSimon Schubert if (!is_destructor_name (tmp_sublist->fn_field.physname))
26545796c8dcSSimon Schubert {
26555796c8dcSSimon Schubert tmp_sublist = tmp_sublist->next;
26565796c8dcSSimon Schubert continue;
26575796c8dcSSimon Schubert }
26585796c8dcSSimon Schubert
26595796c8dcSSimon Schubert destr_fnlist->fn_fieldlist.fn_fields[i++]
26605796c8dcSSimon Schubert = tmp_sublist->fn_field;
26615796c8dcSSimon Schubert if (last_sublist)
26625796c8dcSSimon Schubert last_sublist->next = tmp_sublist->next;
26635796c8dcSSimon Schubert else
26645796c8dcSSimon Schubert sublist = tmp_sublist->next;
26655796c8dcSSimon Schubert last_sublist = tmp_sublist;
26665796c8dcSSimon Schubert tmp_sublist = tmp_sublist->next;
26675796c8dcSSimon Schubert }
26685796c8dcSSimon Schubert
26695796c8dcSSimon Schubert destr_fnlist->fn_fieldlist.length = has_destructor;
26705796c8dcSSimon Schubert destr_fnlist->next = fip->fnlist;
26715796c8dcSSimon Schubert fip->fnlist = destr_fnlist;
26725796c8dcSSimon Schubert nfn_fields++;
26735796c8dcSSimon Schubert length -= has_destructor;
26745796c8dcSSimon Schubert }
26755796c8dcSSimon Schubert else if (is_v3)
26765796c8dcSSimon Schubert {
26775796c8dcSSimon Schubert /* v3 mangling prevents the use of abbreviated physnames,
26785796c8dcSSimon Schubert so we can do this here. There are stubbed methods in v3
26795796c8dcSSimon Schubert only:
26805796c8dcSSimon Schubert - in -gstabs instead of -gstabs+
26815796c8dcSSimon Schubert - or for static methods, which are output as a function type
26825796c8dcSSimon Schubert instead of a method type. */
2683*ef5ccd6cSJohn Marino char *new_method_name =
2684*ef5ccd6cSJohn Marino stabs_method_name_from_physname (sublist->fn_field.physname);
26855796c8dcSSimon Schubert
2686*ef5ccd6cSJohn Marino if (new_method_name != NULL
2687*ef5ccd6cSJohn Marino && strcmp (new_method_name,
2688*ef5ccd6cSJohn Marino new_fnlist->fn_fieldlist.name) != 0)
2689*ef5ccd6cSJohn Marino {
2690*ef5ccd6cSJohn Marino new_fnlist->fn_fieldlist.name = new_method_name;
2691*ef5ccd6cSJohn Marino xfree (main_fn_name);
2692*ef5ccd6cSJohn Marino }
2693*ef5ccd6cSJohn Marino else
2694*ef5ccd6cSJohn Marino xfree (new_method_name);
26955796c8dcSSimon Schubert }
26965796c8dcSSimon Schubert else if (has_destructor && new_fnlist->fn_fieldlist.name[0] != '~')
26975796c8dcSSimon Schubert {
26985796c8dcSSimon Schubert new_fnlist->fn_fieldlist.name =
2699*ef5ccd6cSJohn Marino obconcat (&objfile->objfile_obstack,
2700*ef5ccd6cSJohn Marino "~", main_fn_name, (char *)NULL);
27015796c8dcSSimon Schubert xfree (main_fn_name);
27025796c8dcSSimon Schubert }
27035796c8dcSSimon Schubert else if (!has_stub)
27045796c8dcSSimon Schubert {
27055796c8dcSSimon Schubert char dem_opname[256];
27065796c8dcSSimon Schubert int ret;
2707cf7f2e2dSJohn Marino
27085796c8dcSSimon Schubert ret = cplus_demangle_opname (new_fnlist->fn_fieldlist.name,
27095796c8dcSSimon Schubert dem_opname, DMGL_ANSI);
27105796c8dcSSimon Schubert if (!ret)
27115796c8dcSSimon Schubert ret = cplus_demangle_opname (new_fnlist->fn_fieldlist.name,
27125796c8dcSSimon Schubert dem_opname, 0);
27135796c8dcSSimon Schubert if (ret)
27145796c8dcSSimon Schubert new_fnlist->fn_fieldlist.name
2715*ef5ccd6cSJohn Marino = obstack_copy0 (&objfile->objfile_obstack,
2716*ef5ccd6cSJohn Marino dem_opname, strlen (dem_opname));
2717*ef5ccd6cSJohn Marino xfree (main_fn_name);
27185796c8dcSSimon Schubert }
27195796c8dcSSimon Schubert
27205796c8dcSSimon Schubert new_fnlist->fn_fieldlist.fn_fields = (struct fn_field *)
27215796c8dcSSimon Schubert obstack_alloc (&objfile->objfile_obstack,
27225796c8dcSSimon Schubert sizeof (struct fn_field) * length);
27235796c8dcSSimon Schubert memset (new_fnlist->fn_fieldlist.fn_fields, 0,
27245796c8dcSSimon Schubert sizeof (struct fn_field) * length);
27255796c8dcSSimon Schubert for (i = length; (i--, sublist); sublist = sublist->next)
27265796c8dcSSimon Schubert {
27275796c8dcSSimon Schubert new_fnlist->fn_fieldlist.fn_fields[i] = sublist->fn_field;
27285796c8dcSSimon Schubert }
27295796c8dcSSimon Schubert
27305796c8dcSSimon Schubert new_fnlist->fn_fieldlist.length = length;
27315796c8dcSSimon Schubert new_fnlist->next = fip->fnlist;
27325796c8dcSSimon Schubert fip->fnlist = new_fnlist;
27335796c8dcSSimon Schubert nfn_fields++;
27345796c8dcSSimon Schubert }
27355796c8dcSSimon Schubert }
27365796c8dcSSimon Schubert
27375796c8dcSSimon Schubert if (nfn_fields)
27385796c8dcSSimon Schubert {
27395796c8dcSSimon Schubert ALLOCATE_CPLUS_STRUCT_TYPE (type);
27405796c8dcSSimon Schubert TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
27415796c8dcSSimon Schubert TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * nfn_fields);
27425796c8dcSSimon Schubert memset (TYPE_FN_FIELDLISTS (type), 0,
27435796c8dcSSimon Schubert sizeof (struct fn_fieldlist) * nfn_fields);
27445796c8dcSSimon Schubert TYPE_NFN_FIELDS (type) = nfn_fields;
27455796c8dcSSimon Schubert }
27465796c8dcSSimon Schubert
27475796c8dcSSimon Schubert return 1;
27485796c8dcSSimon Schubert }
27495796c8dcSSimon Schubert
27505796c8dcSSimon Schubert /* Special GNU C++ name.
27515796c8dcSSimon Schubert
27525796c8dcSSimon Schubert Returns 1 for success, 0 for failure. "failure" means that we can't
27535796c8dcSSimon Schubert keep parsing and it's time for error_type(). */
27545796c8dcSSimon Schubert
27555796c8dcSSimon Schubert static int
read_cpp_abbrev(struct field_info * fip,char ** pp,struct type * type,struct objfile * objfile)27565796c8dcSSimon Schubert read_cpp_abbrev (struct field_info *fip, char **pp, struct type *type,
27575796c8dcSSimon Schubert struct objfile *objfile)
27585796c8dcSSimon Schubert {
27595796c8dcSSimon Schubert char *p;
2760*ef5ccd6cSJohn Marino const char *name;
27615796c8dcSSimon Schubert char cpp_abbrev;
27625796c8dcSSimon Schubert struct type *context;
27635796c8dcSSimon Schubert
27645796c8dcSSimon Schubert p = *pp;
27655796c8dcSSimon Schubert if (*++p == 'v')
27665796c8dcSSimon Schubert {
27675796c8dcSSimon Schubert name = NULL;
27685796c8dcSSimon Schubert cpp_abbrev = *++p;
27695796c8dcSSimon Schubert
27705796c8dcSSimon Schubert *pp = p + 1;
27715796c8dcSSimon Schubert
27725796c8dcSSimon Schubert /* At this point, *pp points to something like "22:23=*22...",
27735796c8dcSSimon Schubert where the type number before the ':' is the "context" and
27745796c8dcSSimon Schubert everything after is a regular type definition. Lookup the
27755796c8dcSSimon Schubert type, find it's name, and construct the field name. */
27765796c8dcSSimon Schubert
27775796c8dcSSimon Schubert context = read_type (pp, objfile);
27785796c8dcSSimon Schubert
27795796c8dcSSimon Schubert switch (cpp_abbrev)
27805796c8dcSSimon Schubert {
27815796c8dcSSimon Schubert case 'f': /* $vf -- a virtual function table pointer */
27825796c8dcSSimon Schubert name = type_name_no_tag (context);
27835796c8dcSSimon Schubert if (name == NULL)
27845796c8dcSSimon Schubert {
27855796c8dcSSimon Schubert name = "";
27865796c8dcSSimon Schubert }
2787cf7f2e2dSJohn Marino fip->list->field.name = obconcat (&objfile->objfile_obstack,
2788cf7f2e2dSJohn Marino vptr_name, name, (char *) NULL);
27895796c8dcSSimon Schubert break;
27905796c8dcSSimon Schubert
27915796c8dcSSimon Schubert case 'b': /* $vb -- a virtual bsomethingorother */
27925796c8dcSSimon Schubert name = type_name_no_tag (context);
27935796c8dcSSimon Schubert if (name == NULL)
27945796c8dcSSimon Schubert {
27955796c8dcSSimon Schubert complaint (&symfile_complaints,
2796c50c785cSJohn Marino _("C++ abbreviated type name "
2797c50c785cSJohn Marino "unknown at symtab pos %d"),
27985796c8dcSSimon Schubert symnum);
27995796c8dcSSimon Schubert name = "FOO";
28005796c8dcSSimon Schubert }
2801cf7f2e2dSJohn Marino fip->list->field.name = obconcat (&objfile->objfile_obstack, vb_name,
2802cf7f2e2dSJohn Marino name, (char *) NULL);
28035796c8dcSSimon Schubert break;
28045796c8dcSSimon Schubert
28055796c8dcSSimon Schubert default:
28065796c8dcSSimon Schubert invalid_cpp_abbrev_complaint (*pp);
2807cf7f2e2dSJohn Marino fip->list->field.name = obconcat (&objfile->objfile_obstack,
2808cf7f2e2dSJohn Marino "INVALID_CPLUSPLUS_ABBREV",
2809cf7f2e2dSJohn Marino (char *) NULL);
28105796c8dcSSimon Schubert break;
28115796c8dcSSimon Schubert }
28125796c8dcSSimon Schubert
28135796c8dcSSimon Schubert /* At this point, *pp points to the ':'. Skip it and read the
28145796c8dcSSimon Schubert field type. */
28155796c8dcSSimon Schubert
28165796c8dcSSimon Schubert p = ++(*pp);
28175796c8dcSSimon Schubert if (p[-1] != ':')
28185796c8dcSSimon Schubert {
28195796c8dcSSimon Schubert invalid_cpp_abbrev_complaint (*pp);
28205796c8dcSSimon Schubert return 0;
28215796c8dcSSimon Schubert }
28225796c8dcSSimon Schubert fip->list->field.type = read_type (pp, objfile);
28235796c8dcSSimon Schubert if (**pp == ',')
28245796c8dcSSimon Schubert (*pp)++; /* Skip the comma. */
28255796c8dcSSimon Schubert else
28265796c8dcSSimon Schubert return 0;
28275796c8dcSSimon Schubert
28285796c8dcSSimon Schubert {
28295796c8dcSSimon Schubert int nbits;
2830cf7f2e2dSJohn Marino
2831*ef5ccd6cSJohn Marino SET_FIELD_BITPOS (fip->list->field,
2832*ef5ccd6cSJohn Marino read_huge_number (pp, ';', &nbits, 0));
28335796c8dcSSimon Schubert if (nbits != 0)
28345796c8dcSSimon Schubert return 0;
28355796c8dcSSimon Schubert }
28365796c8dcSSimon Schubert /* This field is unpacked. */
28375796c8dcSSimon Schubert FIELD_BITSIZE (fip->list->field) = 0;
28385796c8dcSSimon Schubert fip->list->visibility = VISIBILITY_PRIVATE;
28395796c8dcSSimon Schubert }
28405796c8dcSSimon Schubert else
28415796c8dcSSimon Schubert {
28425796c8dcSSimon Schubert invalid_cpp_abbrev_complaint (*pp);
28435796c8dcSSimon Schubert /* We have no idea what syntax an unrecognized abbrev would have, so
28445796c8dcSSimon Schubert better return 0. If we returned 1, we would need to at least advance
28455796c8dcSSimon Schubert *pp to avoid an infinite loop. */
28465796c8dcSSimon Schubert return 0;
28475796c8dcSSimon Schubert }
28485796c8dcSSimon Schubert return 1;
28495796c8dcSSimon Schubert }
28505796c8dcSSimon Schubert
28515796c8dcSSimon Schubert static void
read_one_struct_field(struct field_info * fip,char ** pp,char * p,struct type * type,struct objfile * objfile)28525796c8dcSSimon Schubert read_one_struct_field (struct field_info *fip, char **pp, char *p,
28535796c8dcSSimon Schubert struct type *type, struct objfile *objfile)
28545796c8dcSSimon Schubert {
28555796c8dcSSimon Schubert struct gdbarch *gdbarch = get_objfile_arch (objfile);
28565796c8dcSSimon Schubert
28575796c8dcSSimon Schubert fip->list->field.name =
2858*ef5ccd6cSJohn Marino obstack_copy0 (&objfile->objfile_obstack, *pp, p - *pp);
28595796c8dcSSimon Schubert *pp = p + 1;
28605796c8dcSSimon Schubert
28615796c8dcSSimon Schubert /* This means we have a visibility for a field coming. */
28625796c8dcSSimon Schubert if (**pp == '/')
28635796c8dcSSimon Schubert {
28645796c8dcSSimon Schubert (*pp)++;
28655796c8dcSSimon Schubert fip->list->visibility = *(*pp)++;
28665796c8dcSSimon Schubert }
28675796c8dcSSimon Schubert else
28685796c8dcSSimon Schubert {
28695796c8dcSSimon Schubert /* normal dbx-style format, no explicit visibility */
28705796c8dcSSimon Schubert fip->list->visibility = VISIBILITY_PUBLIC;
28715796c8dcSSimon Schubert }
28725796c8dcSSimon Schubert
28735796c8dcSSimon Schubert fip->list->field.type = read_type (pp, objfile);
28745796c8dcSSimon Schubert if (**pp == ':')
28755796c8dcSSimon Schubert {
28765796c8dcSSimon Schubert p = ++(*pp);
28775796c8dcSSimon Schubert #if 0
28785796c8dcSSimon Schubert /* Possible future hook for nested types. */
28795796c8dcSSimon Schubert if (**pp == '!')
28805796c8dcSSimon Schubert {
28815796c8dcSSimon Schubert fip->list->field.bitpos = (long) -2; /* nested type */
28825796c8dcSSimon Schubert p = ++(*pp);
28835796c8dcSSimon Schubert }
28845796c8dcSSimon Schubert else
28855796c8dcSSimon Schubert ...;
28865796c8dcSSimon Schubert #endif
28875796c8dcSSimon Schubert while (*p != ';')
28885796c8dcSSimon Schubert {
28895796c8dcSSimon Schubert p++;
28905796c8dcSSimon Schubert }
28915796c8dcSSimon Schubert /* Static class member. */
28925796c8dcSSimon Schubert SET_FIELD_PHYSNAME (fip->list->field, savestring (*pp, p - *pp));
28935796c8dcSSimon Schubert *pp = p + 1;
28945796c8dcSSimon Schubert return;
28955796c8dcSSimon Schubert }
28965796c8dcSSimon Schubert else if (**pp != ',')
28975796c8dcSSimon Schubert {
28985796c8dcSSimon Schubert /* Bad structure-type format. */
28995796c8dcSSimon Schubert stabs_general_complaint ("bad structure-type format");
29005796c8dcSSimon Schubert return;
29015796c8dcSSimon Schubert }
29025796c8dcSSimon Schubert
29035796c8dcSSimon Schubert (*pp)++; /* Skip the comma. */
29045796c8dcSSimon Schubert
29055796c8dcSSimon Schubert {
29065796c8dcSSimon Schubert int nbits;
2907cf7f2e2dSJohn Marino
2908*ef5ccd6cSJohn Marino SET_FIELD_BITPOS (fip->list->field,
2909*ef5ccd6cSJohn Marino read_huge_number (pp, ',', &nbits, 0));
29105796c8dcSSimon Schubert if (nbits != 0)
29115796c8dcSSimon Schubert {
29125796c8dcSSimon Schubert stabs_general_complaint ("bad structure-type format");
29135796c8dcSSimon Schubert return;
29145796c8dcSSimon Schubert }
29155796c8dcSSimon Schubert FIELD_BITSIZE (fip->list->field) = read_huge_number (pp, ';', &nbits, 0);
29165796c8dcSSimon Schubert if (nbits != 0)
29175796c8dcSSimon Schubert {
29185796c8dcSSimon Schubert stabs_general_complaint ("bad structure-type format");
29195796c8dcSSimon Schubert return;
29205796c8dcSSimon Schubert }
29215796c8dcSSimon Schubert }
29225796c8dcSSimon Schubert
29235796c8dcSSimon Schubert if (FIELD_BITPOS (fip->list->field) == 0
29245796c8dcSSimon Schubert && FIELD_BITSIZE (fip->list->field) == 0)
29255796c8dcSSimon Schubert {
29265796c8dcSSimon Schubert /* This can happen in two cases: (1) at least for gcc 2.4.5 or so,
29275796c8dcSSimon Schubert it is a field which has been optimized out. The correct stab for
29285796c8dcSSimon Schubert this case is to use VISIBILITY_IGNORE, but that is a recent
29295796c8dcSSimon Schubert invention. (2) It is a 0-size array. For example
29305796c8dcSSimon Schubert union { int num; char str[0]; } foo. Printing _("<no value>" for
29315796c8dcSSimon Schubert str in "p foo" is OK, since foo.str (and thus foo.str[3])
29325796c8dcSSimon Schubert will continue to work, and a 0-size array as a whole doesn't
29335796c8dcSSimon Schubert have any contents to print.
29345796c8dcSSimon Schubert
29355796c8dcSSimon Schubert I suspect this probably could also happen with gcc -gstabs (not
29365796c8dcSSimon Schubert -gstabs+) for static fields, and perhaps other C++ extensions.
29375796c8dcSSimon Schubert Hopefully few people use -gstabs with gdb, since it is intended
29385796c8dcSSimon Schubert for dbx compatibility. */
29395796c8dcSSimon Schubert
29405796c8dcSSimon Schubert /* Ignore this field. */
29415796c8dcSSimon Schubert fip->list->visibility = VISIBILITY_IGNORE;
29425796c8dcSSimon Schubert }
29435796c8dcSSimon Schubert else
29445796c8dcSSimon Schubert {
29455796c8dcSSimon Schubert /* Detect an unpacked field and mark it as such.
29465796c8dcSSimon Schubert dbx gives a bit size for all fields.
29475796c8dcSSimon Schubert Note that forward refs cannot be packed,
29485796c8dcSSimon Schubert and treat enums as if they had the width of ints. */
29495796c8dcSSimon Schubert
29505796c8dcSSimon Schubert struct type *field_type = check_typedef (FIELD_TYPE (fip->list->field));
29515796c8dcSSimon Schubert
29525796c8dcSSimon Schubert if (TYPE_CODE (field_type) != TYPE_CODE_INT
29535796c8dcSSimon Schubert && TYPE_CODE (field_type) != TYPE_CODE_RANGE
29545796c8dcSSimon Schubert && TYPE_CODE (field_type) != TYPE_CODE_BOOL
29555796c8dcSSimon Schubert && TYPE_CODE (field_type) != TYPE_CODE_ENUM)
29565796c8dcSSimon Schubert {
29575796c8dcSSimon Schubert FIELD_BITSIZE (fip->list->field) = 0;
29585796c8dcSSimon Schubert }
29595796c8dcSSimon Schubert if ((FIELD_BITSIZE (fip->list->field)
29605796c8dcSSimon Schubert == TARGET_CHAR_BIT * TYPE_LENGTH (field_type)
29615796c8dcSSimon Schubert || (TYPE_CODE (field_type) == TYPE_CODE_ENUM
29625796c8dcSSimon Schubert && FIELD_BITSIZE (fip->list->field)
29635796c8dcSSimon Schubert == gdbarch_int_bit (gdbarch))
29645796c8dcSSimon Schubert )
29655796c8dcSSimon Schubert &&
29665796c8dcSSimon Schubert FIELD_BITPOS (fip->list->field) % 8 == 0)
29675796c8dcSSimon Schubert {
29685796c8dcSSimon Schubert FIELD_BITSIZE (fip->list->field) = 0;
29695796c8dcSSimon Schubert }
29705796c8dcSSimon Schubert }
29715796c8dcSSimon Schubert }
29725796c8dcSSimon Schubert
29735796c8dcSSimon Schubert
29745796c8dcSSimon Schubert /* Read struct or class data fields. They have the form:
29755796c8dcSSimon Schubert
29765796c8dcSSimon Schubert NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
29775796c8dcSSimon Schubert
29785796c8dcSSimon Schubert At the end, we see a semicolon instead of a field.
29795796c8dcSSimon Schubert
29805796c8dcSSimon Schubert In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
29815796c8dcSSimon Schubert a static field.
29825796c8dcSSimon Schubert
29835796c8dcSSimon Schubert The optional VISIBILITY is one of:
29845796c8dcSSimon Schubert
29855796c8dcSSimon Schubert '/0' (VISIBILITY_PRIVATE)
29865796c8dcSSimon Schubert '/1' (VISIBILITY_PROTECTED)
29875796c8dcSSimon Schubert '/2' (VISIBILITY_PUBLIC)
29885796c8dcSSimon Schubert '/9' (VISIBILITY_IGNORE)
29895796c8dcSSimon Schubert
29905796c8dcSSimon Schubert or nothing, for C style fields with public visibility.
29915796c8dcSSimon Schubert
29925796c8dcSSimon Schubert Returns 1 for success, 0 for failure. */
29935796c8dcSSimon Schubert
29945796c8dcSSimon Schubert static int
read_struct_fields(struct field_info * fip,char ** pp,struct type * type,struct objfile * objfile)29955796c8dcSSimon Schubert read_struct_fields (struct field_info *fip, char **pp, struct type *type,
29965796c8dcSSimon Schubert struct objfile *objfile)
29975796c8dcSSimon Schubert {
29985796c8dcSSimon Schubert char *p;
29995796c8dcSSimon Schubert struct nextfield *new;
30005796c8dcSSimon Schubert
30015796c8dcSSimon Schubert /* We better set p right now, in case there are no fields at all... */
30025796c8dcSSimon Schubert
30035796c8dcSSimon Schubert p = *pp;
30045796c8dcSSimon Schubert
30055796c8dcSSimon Schubert /* Read each data member type until we find the terminating ';' at the end of
30065796c8dcSSimon Schubert the data member list, or break for some other reason such as finding the
30075796c8dcSSimon Schubert start of the member function list. */
30085796c8dcSSimon Schubert /* Stab string for structure/union does not end with two ';' in
30095796c8dcSSimon Schubert SUN C compiler 5.3 i.e. F6U2, hence check for end of string. */
30105796c8dcSSimon Schubert
30115796c8dcSSimon Schubert while (**pp != ';' && **pp != '\0')
30125796c8dcSSimon Schubert {
30135796c8dcSSimon Schubert STABS_CONTINUE (pp, objfile);
30145796c8dcSSimon Schubert /* Get space to record the next field's data. */
30155796c8dcSSimon Schubert new = (struct nextfield *) xmalloc (sizeof (struct nextfield));
30165796c8dcSSimon Schubert make_cleanup (xfree, new);
30175796c8dcSSimon Schubert memset (new, 0, sizeof (struct nextfield));
30185796c8dcSSimon Schubert new->next = fip->list;
30195796c8dcSSimon Schubert fip->list = new;
30205796c8dcSSimon Schubert
30215796c8dcSSimon Schubert /* Get the field name. */
30225796c8dcSSimon Schubert p = *pp;
30235796c8dcSSimon Schubert
30245796c8dcSSimon Schubert /* If is starts with CPLUS_MARKER it is a special abbreviation,
30255796c8dcSSimon Schubert unless the CPLUS_MARKER is followed by an underscore, in
30265796c8dcSSimon Schubert which case it is just the name of an anonymous type, which we
30275796c8dcSSimon Schubert should handle like any other type name. */
30285796c8dcSSimon Schubert
30295796c8dcSSimon Schubert if (is_cplus_marker (p[0]) && p[1] != '_')
30305796c8dcSSimon Schubert {
30315796c8dcSSimon Schubert if (!read_cpp_abbrev (fip, pp, type, objfile))
30325796c8dcSSimon Schubert return 0;
30335796c8dcSSimon Schubert continue;
30345796c8dcSSimon Schubert }
30355796c8dcSSimon Schubert
30365796c8dcSSimon Schubert /* Look for the ':' that separates the field name from the field
30375796c8dcSSimon Schubert values. Data members are delimited by a single ':', while member
30385796c8dcSSimon Schubert functions are delimited by a pair of ':'s. When we hit the member
30395796c8dcSSimon Schubert functions (if any), terminate scan loop and return. */
30405796c8dcSSimon Schubert
30415796c8dcSSimon Schubert while (*p != ':' && *p != '\0')
30425796c8dcSSimon Schubert {
30435796c8dcSSimon Schubert p++;
30445796c8dcSSimon Schubert }
30455796c8dcSSimon Schubert if (*p == '\0')
30465796c8dcSSimon Schubert return 0;
30475796c8dcSSimon Schubert
30485796c8dcSSimon Schubert /* Check to see if we have hit the member functions yet. */
30495796c8dcSSimon Schubert if (p[1] == ':')
30505796c8dcSSimon Schubert {
30515796c8dcSSimon Schubert break;
30525796c8dcSSimon Schubert }
30535796c8dcSSimon Schubert read_one_struct_field (fip, pp, p, type, objfile);
30545796c8dcSSimon Schubert }
30555796c8dcSSimon Schubert if (p[0] == ':' && p[1] == ':')
30565796c8dcSSimon Schubert {
30575796c8dcSSimon Schubert /* (the deleted) chill the list of fields: the last entry (at
30585796c8dcSSimon Schubert the head) is a partially constructed entry which we now
30595796c8dcSSimon Schubert scrub. */
30605796c8dcSSimon Schubert fip->list = fip->list->next;
30615796c8dcSSimon Schubert }
30625796c8dcSSimon Schubert return 1;
30635796c8dcSSimon Schubert }
30645796c8dcSSimon Schubert /* *INDENT-OFF* */
30655796c8dcSSimon Schubert /* The stabs for C++ derived classes contain baseclass information which
30665796c8dcSSimon Schubert is marked by a '!' character after the total size. This function is
30675796c8dcSSimon Schubert called when we encounter the baseclass marker, and slurps up all the
30685796c8dcSSimon Schubert baseclass information.
30695796c8dcSSimon Schubert
30705796c8dcSSimon Schubert Immediately following the '!' marker is the number of base classes that
30715796c8dcSSimon Schubert the class is derived from, followed by information for each base class.
30725796c8dcSSimon Schubert For each base class, there are two visibility specifiers, a bit offset
30735796c8dcSSimon Schubert to the base class information within the derived class, a reference to
30745796c8dcSSimon Schubert the type for the base class, and a terminating semicolon.
30755796c8dcSSimon Schubert
30765796c8dcSSimon Schubert A typical example, with two base classes, would be "!2,020,19;0264,21;".
30775796c8dcSSimon Schubert ^^ ^ ^ ^ ^ ^ ^
30785796c8dcSSimon Schubert Baseclass information marker __________________|| | | | | | |
30795796c8dcSSimon Schubert Number of baseclasses __________________________| | | | | | |
30805796c8dcSSimon Schubert Visibility specifiers (2) ________________________| | | | | |
30815796c8dcSSimon Schubert Offset in bits from start of class _________________| | | | |
30825796c8dcSSimon Schubert Type number for base class ___________________________| | | |
30835796c8dcSSimon Schubert Visibility specifiers (2) _______________________________| | |
30845796c8dcSSimon Schubert Offset in bits from start of class ________________________| |
30855796c8dcSSimon Schubert Type number of base class ____________________________________|
30865796c8dcSSimon Schubert
30875796c8dcSSimon Schubert Return 1 for success, 0 for (error-type-inducing) failure. */
30885796c8dcSSimon Schubert /* *INDENT-ON* */
30895796c8dcSSimon Schubert
30905796c8dcSSimon Schubert
30915796c8dcSSimon Schubert
30925796c8dcSSimon Schubert static int
read_baseclasses(struct field_info * fip,char ** pp,struct type * type,struct objfile * objfile)30935796c8dcSSimon Schubert read_baseclasses (struct field_info *fip, char **pp, struct type *type,
30945796c8dcSSimon Schubert struct objfile *objfile)
30955796c8dcSSimon Schubert {
30965796c8dcSSimon Schubert int i;
30975796c8dcSSimon Schubert struct nextfield *new;
30985796c8dcSSimon Schubert
30995796c8dcSSimon Schubert if (**pp != '!')
31005796c8dcSSimon Schubert {
31015796c8dcSSimon Schubert return 1;
31025796c8dcSSimon Schubert }
31035796c8dcSSimon Schubert else
31045796c8dcSSimon Schubert {
31055796c8dcSSimon Schubert /* Skip the '!' baseclass information marker. */
31065796c8dcSSimon Schubert (*pp)++;
31075796c8dcSSimon Schubert }
31085796c8dcSSimon Schubert
31095796c8dcSSimon Schubert ALLOCATE_CPLUS_STRUCT_TYPE (type);
31105796c8dcSSimon Schubert {
31115796c8dcSSimon Schubert int nbits;
3112cf7f2e2dSJohn Marino
31135796c8dcSSimon Schubert TYPE_N_BASECLASSES (type) = read_huge_number (pp, ',', &nbits, 0);
31145796c8dcSSimon Schubert if (nbits != 0)
31155796c8dcSSimon Schubert return 0;
31165796c8dcSSimon Schubert }
31175796c8dcSSimon Schubert
31185796c8dcSSimon Schubert #if 0
31195796c8dcSSimon Schubert /* Some stupid compilers have trouble with the following, so break
31205796c8dcSSimon Schubert it up into simpler expressions. */
31215796c8dcSSimon Schubert TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *)
31225796c8dcSSimon Schubert TYPE_ALLOC (type, B_BYTES (TYPE_N_BASECLASSES (type)));
31235796c8dcSSimon Schubert #else
31245796c8dcSSimon Schubert {
31255796c8dcSSimon Schubert int num_bytes = B_BYTES (TYPE_N_BASECLASSES (type));
31265796c8dcSSimon Schubert char *pointer;
31275796c8dcSSimon Schubert
31285796c8dcSSimon Schubert pointer = (char *) TYPE_ALLOC (type, num_bytes);
31295796c8dcSSimon Schubert TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *) pointer;
31305796c8dcSSimon Schubert }
31315796c8dcSSimon Schubert #endif /* 0 */
31325796c8dcSSimon Schubert
31335796c8dcSSimon Schubert B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), TYPE_N_BASECLASSES (type));
31345796c8dcSSimon Schubert
31355796c8dcSSimon Schubert for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
31365796c8dcSSimon Schubert {
31375796c8dcSSimon Schubert new = (struct nextfield *) xmalloc (sizeof (struct nextfield));
31385796c8dcSSimon Schubert make_cleanup (xfree, new);
31395796c8dcSSimon Schubert memset (new, 0, sizeof (struct nextfield));
31405796c8dcSSimon Schubert new->next = fip->list;
31415796c8dcSSimon Schubert fip->list = new;
3142c50c785cSJohn Marino FIELD_BITSIZE (new->field) = 0; /* This should be an unpacked
3143c50c785cSJohn Marino field! */
31445796c8dcSSimon Schubert
31455796c8dcSSimon Schubert STABS_CONTINUE (pp, objfile);
31465796c8dcSSimon Schubert switch (**pp)
31475796c8dcSSimon Schubert {
31485796c8dcSSimon Schubert case '0':
31495796c8dcSSimon Schubert /* Nothing to do. */
31505796c8dcSSimon Schubert break;
31515796c8dcSSimon Schubert case '1':
31525796c8dcSSimon Schubert SET_TYPE_FIELD_VIRTUAL (type, i);
31535796c8dcSSimon Schubert break;
31545796c8dcSSimon Schubert default:
31555796c8dcSSimon Schubert /* Unknown character. Complain and treat it as non-virtual. */
31565796c8dcSSimon Schubert {
31575796c8dcSSimon Schubert complaint (&symfile_complaints,
3158c50c785cSJohn Marino _("Unknown virtual character `%c' for baseclass"),
3159c50c785cSJohn Marino **pp);
31605796c8dcSSimon Schubert }
31615796c8dcSSimon Schubert }
31625796c8dcSSimon Schubert ++(*pp);
31635796c8dcSSimon Schubert
31645796c8dcSSimon Schubert new->visibility = *(*pp)++;
31655796c8dcSSimon Schubert switch (new->visibility)
31665796c8dcSSimon Schubert {
31675796c8dcSSimon Schubert case VISIBILITY_PRIVATE:
31685796c8dcSSimon Schubert case VISIBILITY_PROTECTED:
31695796c8dcSSimon Schubert case VISIBILITY_PUBLIC:
31705796c8dcSSimon Schubert break;
31715796c8dcSSimon Schubert default:
31725796c8dcSSimon Schubert /* Bad visibility format. Complain and treat it as
31735796c8dcSSimon Schubert public. */
31745796c8dcSSimon Schubert {
31755796c8dcSSimon Schubert complaint (&symfile_complaints,
31765796c8dcSSimon Schubert _("Unknown visibility `%c' for baseclass"),
31775796c8dcSSimon Schubert new->visibility);
31785796c8dcSSimon Schubert new->visibility = VISIBILITY_PUBLIC;
31795796c8dcSSimon Schubert }
31805796c8dcSSimon Schubert }
31815796c8dcSSimon Schubert
31825796c8dcSSimon Schubert {
31835796c8dcSSimon Schubert int nbits;
31845796c8dcSSimon Schubert
31855796c8dcSSimon Schubert /* The remaining value is the bit offset of the portion of the object
31865796c8dcSSimon Schubert corresponding to this baseclass. Always zero in the absence of
31875796c8dcSSimon Schubert multiple inheritance. */
31885796c8dcSSimon Schubert
3189*ef5ccd6cSJohn Marino SET_FIELD_BITPOS (new->field, read_huge_number (pp, ',', &nbits, 0));
31905796c8dcSSimon Schubert if (nbits != 0)
31915796c8dcSSimon Schubert return 0;
31925796c8dcSSimon Schubert }
31935796c8dcSSimon Schubert
31945796c8dcSSimon Schubert /* The last piece of baseclass information is the type of the
31955796c8dcSSimon Schubert base class. Read it, and remember it's type name as this
31965796c8dcSSimon Schubert field's name. */
31975796c8dcSSimon Schubert
31985796c8dcSSimon Schubert new->field.type = read_type (pp, objfile);
31995796c8dcSSimon Schubert new->field.name = type_name_no_tag (new->field.type);
32005796c8dcSSimon Schubert
3201c50c785cSJohn Marino /* Skip trailing ';' and bump count of number of fields seen. */
32025796c8dcSSimon Schubert if (**pp == ';')
32035796c8dcSSimon Schubert (*pp)++;
32045796c8dcSSimon Schubert else
32055796c8dcSSimon Schubert return 0;
32065796c8dcSSimon Schubert }
32075796c8dcSSimon Schubert return 1;
32085796c8dcSSimon Schubert }
32095796c8dcSSimon Schubert
32105796c8dcSSimon Schubert /* The tail end of stabs for C++ classes that contain a virtual function
32115796c8dcSSimon Schubert pointer contains a tilde, a %, and a type number.
32125796c8dcSSimon Schubert The type number refers to the base class (possibly this class itself) which
32135796c8dcSSimon Schubert contains the vtable pointer for the current class.
32145796c8dcSSimon Schubert
32155796c8dcSSimon Schubert This function is called when we have parsed all the method declarations,
32165796c8dcSSimon Schubert so we can look for the vptr base class info. */
32175796c8dcSSimon Schubert
32185796c8dcSSimon Schubert static int
read_tilde_fields(struct field_info * fip,char ** pp,struct type * type,struct objfile * objfile)32195796c8dcSSimon Schubert read_tilde_fields (struct field_info *fip, char **pp, struct type *type,
32205796c8dcSSimon Schubert struct objfile *objfile)
32215796c8dcSSimon Schubert {
32225796c8dcSSimon Schubert char *p;
32235796c8dcSSimon Schubert
32245796c8dcSSimon Schubert STABS_CONTINUE (pp, objfile);
32255796c8dcSSimon Schubert
32265796c8dcSSimon Schubert /* If we are positioned at a ';', then skip it. */
32275796c8dcSSimon Schubert if (**pp == ';')
32285796c8dcSSimon Schubert {
32295796c8dcSSimon Schubert (*pp)++;
32305796c8dcSSimon Schubert }
32315796c8dcSSimon Schubert
32325796c8dcSSimon Schubert if (**pp == '~')
32335796c8dcSSimon Schubert {
32345796c8dcSSimon Schubert (*pp)++;
32355796c8dcSSimon Schubert
32365796c8dcSSimon Schubert if (**pp == '=' || **pp == '+' || **pp == '-')
32375796c8dcSSimon Schubert {
32385796c8dcSSimon Schubert /* Obsolete flags that used to indicate the presence
32395796c8dcSSimon Schubert of constructors and/or destructors. */
32405796c8dcSSimon Schubert (*pp)++;
32415796c8dcSSimon Schubert }
32425796c8dcSSimon Schubert
32435796c8dcSSimon Schubert /* Read either a '%' or the final ';'. */
32445796c8dcSSimon Schubert if (*(*pp)++ == '%')
32455796c8dcSSimon Schubert {
32465796c8dcSSimon Schubert /* The next number is the type number of the base class
32475796c8dcSSimon Schubert (possibly our own class) which supplies the vtable for
32485796c8dcSSimon Schubert this class. Parse it out, and search that class to find
32495796c8dcSSimon Schubert its vtable pointer, and install those into TYPE_VPTR_BASETYPE
32505796c8dcSSimon Schubert and TYPE_VPTR_FIELDNO. */
32515796c8dcSSimon Schubert
32525796c8dcSSimon Schubert struct type *t;
32535796c8dcSSimon Schubert int i;
32545796c8dcSSimon Schubert
32555796c8dcSSimon Schubert t = read_type (pp, objfile);
32565796c8dcSSimon Schubert p = (*pp)++;
32575796c8dcSSimon Schubert while (*p != '\0' && *p != ';')
32585796c8dcSSimon Schubert {
32595796c8dcSSimon Schubert p++;
32605796c8dcSSimon Schubert }
32615796c8dcSSimon Schubert if (*p == '\0')
32625796c8dcSSimon Schubert {
32635796c8dcSSimon Schubert /* Premature end of symbol. */
32645796c8dcSSimon Schubert return 0;
32655796c8dcSSimon Schubert }
32665796c8dcSSimon Schubert
32675796c8dcSSimon Schubert TYPE_VPTR_BASETYPE (type) = t;
3268c50c785cSJohn Marino if (type == t) /* Our own class provides vtbl ptr. */
32695796c8dcSSimon Schubert {
32705796c8dcSSimon Schubert for (i = TYPE_NFIELDS (t) - 1;
32715796c8dcSSimon Schubert i >= TYPE_N_BASECLASSES (t);
32725796c8dcSSimon Schubert --i)
32735796c8dcSSimon Schubert {
3274*ef5ccd6cSJohn Marino const char *name = TYPE_FIELD_NAME (t, i);
3275cf7f2e2dSJohn Marino
32765796c8dcSSimon Schubert if (!strncmp (name, vptr_name, sizeof (vptr_name) - 2)
32775796c8dcSSimon Schubert && is_cplus_marker (name[sizeof (vptr_name) - 2]))
32785796c8dcSSimon Schubert {
32795796c8dcSSimon Schubert TYPE_VPTR_FIELDNO (type) = i;
32805796c8dcSSimon Schubert goto gotit;
32815796c8dcSSimon Schubert }
32825796c8dcSSimon Schubert }
32835796c8dcSSimon Schubert /* Virtual function table field not found. */
32845796c8dcSSimon Schubert complaint (&symfile_complaints,
3285c50c785cSJohn Marino _("virtual function table pointer "
3286c50c785cSJohn Marino "not found when defining class `%s'"),
32875796c8dcSSimon Schubert TYPE_NAME (type));
32885796c8dcSSimon Schubert return 0;
32895796c8dcSSimon Schubert }
32905796c8dcSSimon Schubert else
32915796c8dcSSimon Schubert {
32925796c8dcSSimon Schubert TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t);
32935796c8dcSSimon Schubert }
32945796c8dcSSimon Schubert
32955796c8dcSSimon Schubert gotit:
32965796c8dcSSimon Schubert *pp = p + 1;
32975796c8dcSSimon Schubert }
32985796c8dcSSimon Schubert }
32995796c8dcSSimon Schubert return 1;
33005796c8dcSSimon Schubert }
33015796c8dcSSimon Schubert
33025796c8dcSSimon Schubert static int
attach_fn_fields_to_type(struct field_info * fip,struct type * type)33035796c8dcSSimon Schubert attach_fn_fields_to_type (struct field_info *fip, struct type *type)
33045796c8dcSSimon Schubert {
33055796c8dcSSimon Schubert int n;
33065796c8dcSSimon Schubert
33075796c8dcSSimon Schubert for (n = TYPE_NFN_FIELDS (type);
33085796c8dcSSimon Schubert fip->fnlist != NULL;
33095796c8dcSSimon Schubert fip->fnlist = fip->fnlist->next)
33105796c8dcSSimon Schubert {
3311c50c785cSJohn Marino --n; /* Circumvent Sun3 compiler bug. */
33125796c8dcSSimon Schubert TYPE_FN_FIELDLISTS (type)[n] = fip->fnlist->fn_fieldlist;
33135796c8dcSSimon Schubert }
33145796c8dcSSimon Schubert return 1;
33155796c8dcSSimon Schubert }
33165796c8dcSSimon Schubert
33175796c8dcSSimon Schubert /* Create the vector of fields, and record how big it is.
33185796c8dcSSimon Schubert We need this info to record proper virtual function table information
33195796c8dcSSimon Schubert for this class's virtual functions. */
33205796c8dcSSimon Schubert
33215796c8dcSSimon Schubert static int
attach_fields_to_type(struct field_info * fip,struct type * type,struct objfile * objfile)33225796c8dcSSimon Schubert attach_fields_to_type (struct field_info *fip, struct type *type,
33235796c8dcSSimon Schubert struct objfile *objfile)
33245796c8dcSSimon Schubert {
33255796c8dcSSimon Schubert int nfields = 0;
33265796c8dcSSimon Schubert int non_public_fields = 0;
33275796c8dcSSimon Schubert struct nextfield *scan;
33285796c8dcSSimon Schubert
33295796c8dcSSimon Schubert /* Count up the number of fields that we have, as well as taking note of
33305796c8dcSSimon Schubert whether or not there are any non-public fields, which requires us to
33315796c8dcSSimon Schubert allocate and build the private_field_bits and protected_field_bits
33325796c8dcSSimon Schubert bitfields. */
33335796c8dcSSimon Schubert
33345796c8dcSSimon Schubert for (scan = fip->list; scan != NULL; scan = scan->next)
33355796c8dcSSimon Schubert {
33365796c8dcSSimon Schubert nfields++;
33375796c8dcSSimon Schubert if (scan->visibility != VISIBILITY_PUBLIC)
33385796c8dcSSimon Schubert {
33395796c8dcSSimon Schubert non_public_fields++;
33405796c8dcSSimon Schubert }
33415796c8dcSSimon Schubert }
33425796c8dcSSimon Schubert
33435796c8dcSSimon Schubert /* Now we know how many fields there are, and whether or not there are any
33445796c8dcSSimon Schubert non-public fields. Record the field count, allocate space for the
33455796c8dcSSimon Schubert array of fields, and create blank visibility bitfields if necessary. */
33465796c8dcSSimon Schubert
33475796c8dcSSimon Schubert TYPE_NFIELDS (type) = nfields;
33485796c8dcSSimon Schubert TYPE_FIELDS (type) = (struct field *)
33495796c8dcSSimon Schubert TYPE_ALLOC (type, sizeof (struct field) * nfields);
33505796c8dcSSimon Schubert memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields);
33515796c8dcSSimon Schubert
33525796c8dcSSimon Schubert if (non_public_fields)
33535796c8dcSSimon Schubert {
33545796c8dcSSimon Schubert ALLOCATE_CPLUS_STRUCT_TYPE (type);
33555796c8dcSSimon Schubert
33565796c8dcSSimon Schubert TYPE_FIELD_PRIVATE_BITS (type) =
33575796c8dcSSimon Schubert (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
33585796c8dcSSimon Schubert B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields);
33595796c8dcSSimon Schubert
33605796c8dcSSimon Schubert TYPE_FIELD_PROTECTED_BITS (type) =
33615796c8dcSSimon Schubert (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
33625796c8dcSSimon Schubert B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields);
33635796c8dcSSimon Schubert
33645796c8dcSSimon Schubert TYPE_FIELD_IGNORE_BITS (type) =
33655796c8dcSSimon Schubert (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
33665796c8dcSSimon Schubert B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields);
33675796c8dcSSimon Schubert }
33685796c8dcSSimon Schubert
3369c50c785cSJohn Marino /* Copy the saved-up fields into the field vector. Start from the
3370c50c785cSJohn Marino head of the list, adding to the tail of the field array, so that
3371c50c785cSJohn Marino they end up in the same order in the array in which they were
3372c50c785cSJohn Marino added to the list. */
33735796c8dcSSimon Schubert
33745796c8dcSSimon Schubert while (nfields-- > 0)
33755796c8dcSSimon Schubert {
33765796c8dcSSimon Schubert TYPE_FIELD (type, nfields) = fip->list->field;
33775796c8dcSSimon Schubert switch (fip->list->visibility)
33785796c8dcSSimon Schubert {
33795796c8dcSSimon Schubert case VISIBILITY_PRIVATE:
33805796c8dcSSimon Schubert SET_TYPE_FIELD_PRIVATE (type, nfields);
33815796c8dcSSimon Schubert break;
33825796c8dcSSimon Schubert
33835796c8dcSSimon Schubert case VISIBILITY_PROTECTED:
33845796c8dcSSimon Schubert SET_TYPE_FIELD_PROTECTED (type, nfields);
33855796c8dcSSimon Schubert break;
33865796c8dcSSimon Schubert
33875796c8dcSSimon Schubert case VISIBILITY_IGNORE:
33885796c8dcSSimon Schubert SET_TYPE_FIELD_IGNORE (type, nfields);
33895796c8dcSSimon Schubert break;
33905796c8dcSSimon Schubert
33915796c8dcSSimon Schubert case VISIBILITY_PUBLIC:
33925796c8dcSSimon Schubert break;
33935796c8dcSSimon Schubert
33945796c8dcSSimon Schubert default:
33955796c8dcSSimon Schubert /* Unknown visibility. Complain and treat it as public. */
33965796c8dcSSimon Schubert {
3397c50c785cSJohn Marino complaint (&symfile_complaints,
3398c50c785cSJohn Marino _("Unknown visibility `%c' for field"),
33995796c8dcSSimon Schubert fip->list->visibility);
34005796c8dcSSimon Schubert }
34015796c8dcSSimon Schubert break;
34025796c8dcSSimon Schubert }
34035796c8dcSSimon Schubert fip->list = fip->list->next;
34045796c8dcSSimon Schubert }
34055796c8dcSSimon Schubert return 1;
34065796c8dcSSimon Schubert }
34075796c8dcSSimon Schubert
34085796c8dcSSimon Schubert
34095796c8dcSSimon Schubert /* Complain that the compiler has emitted more than one definition for the
34105796c8dcSSimon Schubert structure type TYPE. */
34115796c8dcSSimon Schubert static void
complain_about_struct_wipeout(struct type * type)34125796c8dcSSimon Schubert complain_about_struct_wipeout (struct type *type)
34135796c8dcSSimon Schubert {
3414*ef5ccd6cSJohn Marino const char *name = "";
3415*ef5ccd6cSJohn Marino const char *kind = "";
34165796c8dcSSimon Schubert
34175796c8dcSSimon Schubert if (TYPE_TAG_NAME (type))
34185796c8dcSSimon Schubert {
34195796c8dcSSimon Schubert name = TYPE_TAG_NAME (type);
34205796c8dcSSimon Schubert switch (TYPE_CODE (type))
34215796c8dcSSimon Schubert {
34225796c8dcSSimon Schubert case TYPE_CODE_STRUCT: kind = "struct "; break;
34235796c8dcSSimon Schubert case TYPE_CODE_UNION: kind = "union "; break;
34245796c8dcSSimon Schubert case TYPE_CODE_ENUM: kind = "enum "; break;
34255796c8dcSSimon Schubert default: kind = "";
34265796c8dcSSimon Schubert }
34275796c8dcSSimon Schubert }
34285796c8dcSSimon Schubert else if (TYPE_NAME (type))
34295796c8dcSSimon Schubert {
34305796c8dcSSimon Schubert name = TYPE_NAME (type);
34315796c8dcSSimon Schubert kind = "";
34325796c8dcSSimon Schubert }
34335796c8dcSSimon Schubert else
34345796c8dcSSimon Schubert {
34355796c8dcSSimon Schubert name = "<unknown>";
34365796c8dcSSimon Schubert kind = "";
34375796c8dcSSimon Schubert }
34385796c8dcSSimon Schubert
34395796c8dcSSimon Schubert complaint (&symfile_complaints,
34405796c8dcSSimon Schubert _("struct/union type gets multiply defined: %s%s"), kind, name);
34415796c8dcSSimon Schubert }
34425796c8dcSSimon Schubert
3443cf7f2e2dSJohn Marino /* Set the length for all variants of a same main_type, which are
3444cf7f2e2dSJohn Marino connected in the closed chain.
3445cf7f2e2dSJohn Marino
3446cf7f2e2dSJohn Marino This is something that needs to be done when a type is defined *after*
3447cf7f2e2dSJohn Marino some cross references to this type have already been read. Consider
3448cf7f2e2dSJohn Marino for instance the following scenario where we have the following two
3449cf7f2e2dSJohn Marino stabs entries:
3450cf7f2e2dSJohn Marino
3451cf7f2e2dSJohn Marino .stabs "t:p(0,21)=*(0,22)=k(0,23)=xsdummy:",160,0,28,-24
3452cf7f2e2dSJohn Marino .stabs "dummy:T(0,23)=s16x:(0,1),0,3[...]"
3453cf7f2e2dSJohn Marino
3454cf7f2e2dSJohn Marino A stubbed version of type dummy is created while processing the first
3455cf7f2e2dSJohn Marino stabs entry. The length of that type is initially set to zero, since
3456cf7f2e2dSJohn Marino it is unknown at this point. Also, a "constant" variation of type
3457cf7f2e2dSJohn Marino "dummy" is created as well (this is the "(0,22)=k(0,23)" section of
3458cf7f2e2dSJohn Marino the stabs line).
3459cf7f2e2dSJohn Marino
3460cf7f2e2dSJohn Marino The second stabs entry allows us to replace the stubbed definition
3461cf7f2e2dSJohn Marino with the real definition. However, we still need to adjust the length
3462cf7f2e2dSJohn Marino of the "constant" variation of that type, as its length was left
3463cf7f2e2dSJohn Marino untouched during the main type replacement... */
3464cf7f2e2dSJohn Marino
3465cf7f2e2dSJohn Marino static void
set_length_in_type_chain(struct type * type)3466cf7f2e2dSJohn Marino set_length_in_type_chain (struct type *type)
3467cf7f2e2dSJohn Marino {
3468cf7f2e2dSJohn Marino struct type *ntype = TYPE_CHAIN (type);
3469cf7f2e2dSJohn Marino
3470cf7f2e2dSJohn Marino while (ntype != type)
3471cf7f2e2dSJohn Marino {
3472cf7f2e2dSJohn Marino if (TYPE_LENGTH(ntype) == 0)
3473cf7f2e2dSJohn Marino TYPE_LENGTH (ntype) = TYPE_LENGTH (type);
3474cf7f2e2dSJohn Marino else
3475cf7f2e2dSJohn Marino complain_about_struct_wipeout (ntype);
3476cf7f2e2dSJohn Marino ntype = TYPE_CHAIN (ntype);
3477cf7f2e2dSJohn Marino }
3478cf7f2e2dSJohn Marino }
34795796c8dcSSimon Schubert
34805796c8dcSSimon Schubert /* Read the description of a structure (or union type) and return an object
34815796c8dcSSimon Schubert describing the type.
34825796c8dcSSimon Schubert
34835796c8dcSSimon Schubert PP points to a character pointer that points to the next unconsumed token
3484c50c785cSJohn Marino in the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;",
34855796c8dcSSimon Schubert *PP will point to "4a:1,0,32;;".
34865796c8dcSSimon Schubert
34875796c8dcSSimon Schubert TYPE points to an incomplete type that needs to be filled in.
34885796c8dcSSimon Schubert
34895796c8dcSSimon Schubert OBJFILE points to the current objfile from which the stabs information is
34905796c8dcSSimon Schubert being read. (Note that it is redundant in that TYPE also contains a pointer
34915796c8dcSSimon Schubert to this same objfile, so it might be a good idea to eliminate it. FIXME).
34925796c8dcSSimon Schubert */
34935796c8dcSSimon Schubert
34945796c8dcSSimon Schubert static struct type *
read_struct_type(char ** pp,struct type * type,enum type_code type_code,struct objfile * objfile)34955796c8dcSSimon Schubert read_struct_type (char **pp, struct type *type, enum type_code type_code,
34965796c8dcSSimon Schubert struct objfile *objfile)
34975796c8dcSSimon Schubert {
34985796c8dcSSimon Schubert struct cleanup *back_to;
34995796c8dcSSimon Schubert struct field_info fi;
35005796c8dcSSimon Schubert
35015796c8dcSSimon Schubert fi.list = NULL;
35025796c8dcSSimon Schubert fi.fnlist = NULL;
35035796c8dcSSimon Schubert
35045796c8dcSSimon Schubert /* When describing struct/union/class types in stabs, G++ always drops
35055796c8dcSSimon Schubert all qualifications from the name. So if you've got:
35065796c8dcSSimon Schubert struct A { ... struct B { ... }; ... };
35075796c8dcSSimon Schubert then G++ will emit stabs for `struct A::B' that call it simply
35085796c8dcSSimon Schubert `struct B'. Obviously, if you've got a real top-level definition for
35095796c8dcSSimon Schubert `struct B', or other nested definitions, this is going to cause
35105796c8dcSSimon Schubert problems.
35115796c8dcSSimon Schubert
35125796c8dcSSimon Schubert Obviously, GDB can't fix this by itself, but it can at least avoid
35135796c8dcSSimon Schubert scribbling on existing structure type objects when new definitions
35145796c8dcSSimon Schubert appear. */
35155796c8dcSSimon Schubert if (! (TYPE_CODE (type) == TYPE_CODE_UNDEF
35165796c8dcSSimon Schubert || TYPE_STUB (type)))
35175796c8dcSSimon Schubert {
35185796c8dcSSimon Schubert complain_about_struct_wipeout (type);
35195796c8dcSSimon Schubert
35205796c8dcSSimon Schubert /* It's probably best to return the type unchanged. */
35215796c8dcSSimon Schubert return type;
35225796c8dcSSimon Schubert }
35235796c8dcSSimon Schubert
35245796c8dcSSimon Schubert back_to = make_cleanup (null_cleanup, 0);
35255796c8dcSSimon Schubert
35265796c8dcSSimon Schubert INIT_CPLUS_SPECIFIC (type);
35275796c8dcSSimon Schubert TYPE_CODE (type) = type_code;
35285796c8dcSSimon Schubert TYPE_STUB (type) = 0;
35295796c8dcSSimon Schubert
35305796c8dcSSimon Schubert /* First comes the total size in bytes. */
35315796c8dcSSimon Schubert
35325796c8dcSSimon Schubert {
35335796c8dcSSimon Schubert int nbits;
3534cf7f2e2dSJohn Marino
35355796c8dcSSimon Schubert TYPE_LENGTH (type) = read_huge_number (pp, 0, &nbits, 0);
35365796c8dcSSimon Schubert if (nbits != 0)
35375796c8dcSSimon Schubert return error_type (pp, objfile);
3538cf7f2e2dSJohn Marino set_length_in_type_chain (type);
35395796c8dcSSimon Schubert }
35405796c8dcSSimon Schubert
35415796c8dcSSimon Schubert /* Now read the baseclasses, if any, read the regular C struct or C++
35425796c8dcSSimon Schubert class member fields, attach the fields to the type, read the C++
35435796c8dcSSimon Schubert member functions, attach them to the type, and then read any tilde
35445796c8dcSSimon Schubert field (baseclass specifier for the class holding the main vtable). */
35455796c8dcSSimon Schubert
35465796c8dcSSimon Schubert if (!read_baseclasses (&fi, pp, type, objfile)
35475796c8dcSSimon Schubert || !read_struct_fields (&fi, pp, type, objfile)
35485796c8dcSSimon Schubert || !attach_fields_to_type (&fi, type, objfile)
35495796c8dcSSimon Schubert || !read_member_functions (&fi, pp, type, objfile)
35505796c8dcSSimon Schubert || !attach_fn_fields_to_type (&fi, type)
35515796c8dcSSimon Schubert || !read_tilde_fields (&fi, pp, type, objfile))
35525796c8dcSSimon Schubert {
35535796c8dcSSimon Schubert type = error_type (pp, objfile);
35545796c8dcSSimon Schubert }
35555796c8dcSSimon Schubert
35565796c8dcSSimon Schubert do_cleanups (back_to);
35575796c8dcSSimon Schubert return (type);
35585796c8dcSSimon Schubert }
35595796c8dcSSimon Schubert
35605796c8dcSSimon Schubert /* Read a definition of an array type,
35615796c8dcSSimon Schubert and create and return a suitable type object.
35625796c8dcSSimon Schubert Also creates a range type which represents the bounds of that
35635796c8dcSSimon Schubert array. */
35645796c8dcSSimon Schubert
35655796c8dcSSimon Schubert static struct type *
read_array_type(char ** pp,struct type * type,struct objfile * objfile)35665796c8dcSSimon Schubert read_array_type (char **pp, struct type *type,
35675796c8dcSSimon Schubert struct objfile *objfile)
35685796c8dcSSimon Schubert {
35695796c8dcSSimon Schubert struct type *index_type, *element_type, *range_type;
35705796c8dcSSimon Schubert int lower, upper;
35715796c8dcSSimon Schubert int adjustable = 0;
35725796c8dcSSimon Schubert int nbits;
35735796c8dcSSimon Schubert
35745796c8dcSSimon Schubert /* Format of an array type:
35755796c8dcSSimon Schubert "ar<index type>;lower;upper;<array_contents_type>".
35765796c8dcSSimon Schubert OS9000: "arlower,upper;<array_contents_type>".
35775796c8dcSSimon Schubert
35785796c8dcSSimon Schubert Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
35795796c8dcSSimon Schubert for these, produce a type like float[][]. */
35805796c8dcSSimon Schubert
35815796c8dcSSimon Schubert {
35825796c8dcSSimon Schubert index_type = read_type (pp, objfile);
35835796c8dcSSimon Schubert if (**pp != ';')
35845796c8dcSSimon Schubert /* Improper format of array type decl. */
35855796c8dcSSimon Schubert return error_type (pp, objfile);
35865796c8dcSSimon Schubert ++*pp;
35875796c8dcSSimon Schubert }
35885796c8dcSSimon Schubert
35895796c8dcSSimon Schubert if (!(**pp >= '0' && **pp <= '9') && **pp != '-')
35905796c8dcSSimon Schubert {
35915796c8dcSSimon Schubert (*pp)++;
35925796c8dcSSimon Schubert adjustable = 1;
35935796c8dcSSimon Schubert }
35945796c8dcSSimon Schubert lower = read_huge_number (pp, ';', &nbits, 0);
35955796c8dcSSimon Schubert
35965796c8dcSSimon Schubert if (nbits != 0)
35975796c8dcSSimon Schubert return error_type (pp, objfile);
35985796c8dcSSimon Schubert
35995796c8dcSSimon Schubert if (!(**pp >= '0' && **pp <= '9') && **pp != '-')
36005796c8dcSSimon Schubert {
36015796c8dcSSimon Schubert (*pp)++;
36025796c8dcSSimon Schubert adjustable = 1;
36035796c8dcSSimon Schubert }
36045796c8dcSSimon Schubert upper = read_huge_number (pp, ';', &nbits, 0);
36055796c8dcSSimon Schubert if (nbits != 0)
36065796c8dcSSimon Schubert return error_type (pp, objfile);
36075796c8dcSSimon Schubert
36085796c8dcSSimon Schubert element_type = read_type (pp, objfile);
36095796c8dcSSimon Schubert
36105796c8dcSSimon Schubert if (adjustable)
36115796c8dcSSimon Schubert {
36125796c8dcSSimon Schubert lower = 0;
36135796c8dcSSimon Schubert upper = -1;
36145796c8dcSSimon Schubert }
36155796c8dcSSimon Schubert
36165796c8dcSSimon Schubert range_type =
36175796c8dcSSimon Schubert create_range_type ((struct type *) NULL, index_type, lower, upper);
36185796c8dcSSimon Schubert type = create_array_type (type, element_type, range_type);
36195796c8dcSSimon Schubert
36205796c8dcSSimon Schubert return type;
36215796c8dcSSimon Schubert }
36225796c8dcSSimon Schubert
36235796c8dcSSimon Schubert
36245796c8dcSSimon Schubert /* Read a definition of an enumeration type,
36255796c8dcSSimon Schubert and create and return a suitable type object.
36265796c8dcSSimon Schubert Also defines the symbols that represent the values of the type. */
36275796c8dcSSimon Schubert
36285796c8dcSSimon Schubert static struct type *
read_enum_type(char ** pp,struct type * type,struct objfile * objfile)36295796c8dcSSimon Schubert read_enum_type (char **pp, struct type *type,
36305796c8dcSSimon Schubert struct objfile *objfile)
36315796c8dcSSimon Schubert {
36325796c8dcSSimon Schubert struct gdbarch *gdbarch = get_objfile_arch (objfile);
36335796c8dcSSimon Schubert char *p;
36345796c8dcSSimon Schubert char *name;
36355796c8dcSSimon Schubert long n;
36365796c8dcSSimon Schubert struct symbol *sym;
36375796c8dcSSimon Schubert int nsyms = 0;
36385796c8dcSSimon Schubert struct pending **symlist;
36395796c8dcSSimon Schubert struct pending *osyms, *syms;
36405796c8dcSSimon Schubert int o_nsyms;
36415796c8dcSSimon Schubert int nbits;
36425796c8dcSSimon Schubert int unsigned_enum = 1;
36435796c8dcSSimon Schubert
36445796c8dcSSimon Schubert #if 0
36455796c8dcSSimon Schubert /* FIXME! The stabs produced by Sun CC merrily define things that ought
36465796c8dcSSimon Schubert to be file-scope, between N_FN entries, using N_LSYM. What's a mother
36475796c8dcSSimon Schubert to do? For now, force all enum values to file scope. */
36485796c8dcSSimon Schubert if (within_function)
36495796c8dcSSimon Schubert symlist = &local_symbols;
36505796c8dcSSimon Schubert else
36515796c8dcSSimon Schubert #endif
36525796c8dcSSimon Schubert symlist = &file_symbols;
36535796c8dcSSimon Schubert osyms = *symlist;
36545796c8dcSSimon Schubert o_nsyms = osyms ? osyms->nsyms : 0;
36555796c8dcSSimon Schubert
36565796c8dcSSimon Schubert /* The aix4 compiler emits an extra field before the enum members;
36575796c8dcSSimon Schubert my guess is it's a type of some sort. Just ignore it. */
36585796c8dcSSimon Schubert if (**pp == '-')
36595796c8dcSSimon Schubert {
36605796c8dcSSimon Schubert /* Skip over the type. */
36615796c8dcSSimon Schubert while (**pp != ':')
36625796c8dcSSimon Schubert (*pp)++;
36635796c8dcSSimon Schubert
36645796c8dcSSimon Schubert /* Skip over the colon. */
36655796c8dcSSimon Schubert (*pp)++;
36665796c8dcSSimon Schubert }
36675796c8dcSSimon Schubert
36685796c8dcSSimon Schubert /* Read the value-names and their values.
36695796c8dcSSimon Schubert The input syntax is NAME:VALUE,NAME:VALUE, and so on.
36705796c8dcSSimon Schubert A semicolon or comma instead of a NAME means the end. */
36715796c8dcSSimon Schubert while (**pp && **pp != ';' && **pp != ',')
36725796c8dcSSimon Schubert {
36735796c8dcSSimon Schubert STABS_CONTINUE (pp, objfile);
36745796c8dcSSimon Schubert p = *pp;
36755796c8dcSSimon Schubert while (*p != ':')
36765796c8dcSSimon Schubert p++;
3677*ef5ccd6cSJohn Marino name = obstack_copy0 (&objfile->objfile_obstack, *pp, p - *pp);
36785796c8dcSSimon Schubert *pp = p + 1;
36795796c8dcSSimon Schubert n = read_huge_number (pp, ',', &nbits, 0);
36805796c8dcSSimon Schubert if (nbits != 0)
36815796c8dcSSimon Schubert return error_type (pp, objfile);
36825796c8dcSSimon Schubert
36835796c8dcSSimon Schubert sym = (struct symbol *)
36845796c8dcSSimon Schubert obstack_alloc (&objfile->objfile_obstack, sizeof (struct symbol));
36855796c8dcSSimon Schubert memset (sym, 0, sizeof (struct symbol));
36865796c8dcSSimon Schubert SYMBOL_SET_LINKAGE_NAME (sym, name);
3687c50c785cSJohn Marino SYMBOL_SET_LANGUAGE (sym, current_subfile->language);
36885796c8dcSSimon Schubert SYMBOL_CLASS (sym) = LOC_CONST;
36895796c8dcSSimon Schubert SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
36905796c8dcSSimon Schubert SYMBOL_VALUE (sym) = n;
36915796c8dcSSimon Schubert if (n < 0)
36925796c8dcSSimon Schubert unsigned_enum = 0;
36935796c8dcSSimon Schubert add_symbol_to_list (sym, symlist);
36945796c8dcSSimon Schubert nsyms++;
36955796c8dcSSimon Schubert }
36965796c8dcSSimon Schubert
36975796c8dcSSimon Schubert if (**pp == ';')
36985796c8dcSSimon Schubert (*pp)++; /* Skip the semicolon. */
36995796c8dcSSimon Schubert
37005796c8dcSSimon Schubert /* Now fill in the fields of the type-structure. */
37015796c8dcSSimon Schubert
37025796c8dcSSimon Schubert TYPE_LENGTH (type) = gdbarch_int_bit (gdbarch) / HOST_CHAR_BIT;
3703cf7f2e2dSJohn Marino set_length_in_type_chain (type);
37045796c8dcSSimon Schubert TYPE_CODE (type) = TYPE_CODE_ENUM;
37055796c8dcSSimon Schubert TYPE_STUB (type) = 0;
37065796c8dcSSimon Schubert if (unsigned_enum)
37075796c8dcSSimon Schubert TYPE_UNSIGNED (type) = 1;
37085796c8dcSSimon Schubert TYPE_NFIELDS (type) = nsyms;
37095796c8dcSSimon Schubert TYPE_FIELDS (type) = (struct field *)
37105796c8dcSSimon Schubert TYPE_ALLOC (type, sizeof (struct field) * nsyms);
37115796c8dcSSimon Schubert memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nsyms);
37125796c8dcSSimon Schubert
37135796c8dcSSimon Schubert /* Find the symbols for the values and put them into the type.
37145796c8dcSSimon Schubert The symbols can be found in the symlist that we put them on
37155796c8dcSSimon Schubert to cause them to be defined. osyms contains the old value
37165796c8dcSSimon Schubert of that symlist; everything up to there was defined by us. */
37175796c8dcSSimon Schubert /* Note that we preserve the order of the enum constants, so
37185796c8dcSSimon Schubert that in something like "enum {FOO, LAST_THING=FOO}" we print
37195796c8dcSSimon Schubert FOO, not LAST_THING. */
37205796c8dcSSimon Schubert
37215796c8dcSSimon Schubert for (syms = *symlist, n = nsyms - 1; syms; syms = syms->next)
37225796c8dcSSimon Schubert {
37235796c8dcSSimon Schubert int last = syms == osyms ? o_nsyms : 0;
37245796c8dcSSimon Schubert int j = syms->nsyms;
3725cf7f2e2dSJohn Marino
37265796c8dcSSimon Schubert for (; --j >= last; --n)
37275796c8dcSSimon Schubert {
37285796c8dcSSimon Schubert struct symbol *xsym = syms->symbol[j];
3729cf7f2e2dSJohn Marino
37305796c8dcSSimon Schubert SYMBOL_TYPE (xsym) = type;
37315796c8dcSSimon Schubert TYPE_FIELD_NAME (type, n) = SYMBOL_LINKAGE_NAME (xsym);
3732*ef5ccd6cSJohn Marino SET_FIELD_ENUMVAL (TYPE_FIELD (type, n), SYMBOL_VALUE (xsym));
37335796c8dcSSimon Schubert TYPE_FIELD_BITSIZE (type, n) = 0;
37345796c8dcSSimon Schubert }
37355796c8dcSSimon Schubert if (syms == osyms)
37365796c8dcSSimon Schubert break;
37375796c8dcSSimon Schubert }
37385796c8dcSSimon Schubert
37395796c8dcSSimon Schubert return type;
37405796c8dcSSimon Schubert }
37415796c8dcSSimon Schubert
37425796c8dcSSimon Schubert /* Sun's ACC uses a somewhat saner method for specifying the builtin
37435796c8dcSSimon Schubert typedefs in every file (for int, long, etc):
37445796c8dcSSimon Schubert
37455796c8dcSSimon Schubert type = b <signed> <width> <format type>; <offset>; <nbits>
37465796c8dcSSimon Schubert signed = u or s.
37475796c8dcSSimon Schubert optional format type = c or b for char or boolean.
37485796c8dcSSimon Schubert offset = offset from high order bit to start bit of type.
37495796c8dcSSimon Schubert width is # bytes in object of this type, nbits is # bits in type.
37505796c8dcSSimon Schubert
37515796c8dcSSimon Schubert The width/offset stuff appears to be for small objects stored in
37525796c8dcSSimon Schubert larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
37535796c8dcSSimon Schubert FIXME. */
37545796c8dcSSimon Schubert
37555796c8dcSSimon Schubert static struct type *
read_sun_builtin_type(char ** pp,int typenums[2],struct objfile * objfile)37565796c8dcSSimon Schubert read_sun_builtin_type (char **pp, int typenums[2], struct objfile *objfile)
37575796c8dcSSimon Schubert {
37585796c8dcSSimon Schubert int type_bits;
37595796c8dcSSimon Schubert int nbits;
37605796c8dcSSimon Schubert int signed_type;
37615796c8dcSSimon Schubert enum type_code code = TYPE_CODE_INT;
37625796c8dcSSimon Schubert
37635796c8dcSSimon Schubert switch (**pp)
37645796c8dcSSimon Schubert {
37655796c8dcSSimon Schubert case 's':
37665796c8dcSSimon Schubert signed_type = 1;
37675796c8dcSSimon Schubert break;
37685796c8dcSSimon Schubert case 'u':
37695796c8dcSSimon Schubert signed_type = 0;
37705796c8dcSSimon Schubert break;
37715796c8dcSSimon Schubert default:
37725796c8dcSSimon Schubert return error_type (pp, objfile);
37735796c8dcSSimon Schubert }
37745796c8dcSSimon Schubert (*pp)++;
37755796c8dcSSimon Schubert
37765796c8dcSSimon Schubert /* For some odd reason, all forms of char put a c here. This is strange
37775796c8dcSSimon Schubert because no other type has this honor. We can safely ignore this because
37785796c8dcSSimon Schubert we actually determine 'char'acterness by the number of bits specified in
37795796c8dcSSimon Schubert the descriptor.
37805796c8dcSSimon Schubert Boolean forms, e.g Fortran logical*X, put a b here. */
37815796c8dcSSimon Schubert
37825796c8dcSSimon Schubert if (**pp == 'c')
37835796c8dcSSimon Schubert (*pp)++;
37845796c8dcSSimon Schubert else if (**pp == 'b')
37855796c8dcSSimon Schubert {
37865796c8dcSSimon Schubert code = TYPE_CODE_BOOL;
37875796c8dcSSimon Schubert (*pp)++;
37885796c8dcSSimon Schubert }
37895796c8dcSSimon Schubert
37905796c8dcSSimon Schubert /* The first number appears to be the number of bytes occupied
37915796c8dcSSimon Schubert by this type, except that unsigned short is 4 instead of 2.
37925796c8dcSSimon Schubert Since this information is redundant with the third number,
37935796c8dcSSimon Schubert we will ignore it. */
37945796c8dcSSimon Schubert read_huge_number (pp, ';', &nbits, 0);
37955796c8dcSSimon Schubert if (nbits != 0)
37965796c8dcSSimon Schubert return error_type (pp, objfile);
37975796c8dcSSimon Schubert
37985796c8dcSSimon Schubert /* The second number is always 0, so ignore it too. */
37995796c8dcSSimon Schubert read_huge_number (pp, ';', &nbits, 0);
38005796c8dcSSimon Schubert if (nbits != 0)
38015796c8dcSSimon Schubert return error_type (pp, objfile);
38025796c8dcSSimon Schubert
38035796c8dcSSimon Schubert /* The third number is the number of bits for this type. */
38045796c8dcSSimon Schubert type_bits = read_huge_number (pp, 0, &nbits, 0);
38055796c8dcSSimon Schubert if (nbits != 0)
38065796c8dcSSimon Schubert return error_type (pp, objfile);
38075796c8dcSSimon Schubert /* The type *should* end with a semicolon. If it are embedded
38085796c8dcSSimon Schubert in a larger type the semicolon may be the only way to know where
38095796c8dcSSimon Schubert the type ends. If this type is at the end of the stabstring we
38105796c8dcSSimon Schubert can deal with the omitted semicolon (but we don't have to like
38115796c8dcSSimon Schubert it). Don't bother to complain(), Sun's compiler omits the semicolon
38125796c8dcSSimon Schubert for "void". */
38135796c8dcSSimon Schubert if (**pp == ';')
38145796c8dcSSimon Schubert ++(*pp);
38155796c8dcSSimon Schubert
38165796c8dcSSimon Schubert if (type_bits == 0)
38175796c8dcSSimon Schubert return init_type (TYPE_CODE_VOID, 1,
38185796c8dcSSimon Schubert signed_type ? 0 : TYPE_FLAG_UNSIGNED, (char *) NULL,
38195796c8dcSSimon Schubert objfile);
38205796c8dcSSimon Schubert else
38215796c8dcSSimon Schubert return init_type (code,
38225796c8dcSSimon Schubert type_bits / TARGET_CHAR_BIT,
38235796c8dcSSimon Schubert signed_type ? 0 : TYPE_FLAG_UNSIGNED, (char *) NULL,
38245796c8dcSSimon Schubert objfile);
38255796c8dcSSimon Schubert }
38265796c8dcSSimon Schubert
38275796c8dcSSimon Schubert static struct type *
read_sun_floating_type(char ** pp,int typenums[2],struct objfile * objfile)38285796c8dcSSimon Schubert read_sun_floating_type (char **pp, int typenums[2], struct objfile *objfile)
38295796c8dcSSimon Schubert {
38305796c8dcSSimon Schubert int nbits;
38315796c8dcSSimon Schubert int details;
38325796c8dcSSimon Schubert int nbytes;
38335796c8dcSSimon Schubert struct type *rettype;
38345796c8dcSSimon Schubert
38355796c8dcSSimon Schubert /* The first number has more details about the type, for example
38365796c8dcSSimon Schubert FN_COMPLEX. */
38375796c8dcSSimon Schubert details = read_huge_number (pp, ';', &nbits, 0);
38385796c8dcSSimon Schubert if (nbits != 0)
38395796c8dcSSimon Schubert return error_type (pp, objfile);
38405796c8dcSSimon Schubert
3841c50c785cSJohn Marino /* The second number is the number of bytes occupied by this type. */
38425796c8dcSSimon Schubert nbytes = read_huge_number (pp, ';', &nbits, 0);
38435796c8dcSSimon Schubert if (nbits != 0)
38445796c8dcSSimon Schubert return error_type (pp, objfile);
38455796c8dcSSimon Schubert
38465796c8dcSSimon Schubert if (details == NF_COMPLEX || details == NF_COMPLEX16
38475796c8dcSSimon Schubert || details == NF_COMPLEX32)
38485796c8dcSSimon Schubert {
38495796c8dcSSimon Schubert rettype = init_type (TYPE_CODE_COMPLEX, nbytes, 0, NULL, objfile);
38505796c8dcSSimon Schubert TYPE_TARGET_TYPE (rettype)
38515796c8dcSSimon Schubert = init_type (TYPE_CODE_FLT, nbytes / 2, 0, NULL, objfile);
38525796c8dcSSimon Schubert return rettype;
38535796c8dcSSimon Schubert }
38545796c8dcSSimon Schubert
38555796c8dcSSimon Schubert return init_type (TYPE_CODE_FLT, nbytes, 0, NULL, objfile);
38565796c8dcSSimon Schubert }
38575796c8dcSSimon Schubert
38585796c8dcSSimon Schubert /* Read a number from the string pointed to by *PP.
38595796c8dcSSimon Schubert The value of *PP is advanced over the number.
38605796c8dcSSimon Schubert If END is nonzero, the character that ends the
38615796c8dcSSimon Schubert number must match END, or an error happens;
38625796c8dcSSimon Schubert and that character is skipped if it does match.
38635796c8dcSSimon Schubert If END is zero, *PP is left pointing to that character.
38645796c8dcSSimon Schubert
38655796c8dcSSimon Schubert If TWOS_COMPLEMENT_BITS is set to a strictly positive value and if
38665796c8dcSSimon Schubert the number is represented in an octal representation, assume that
38675796c8dcSSimon Schubert it is represented in a 2's complement representation with a size of
38685796c8dcSSimon Schubert TWOS_COMPLEMENT_BITS.
38695796c8dcSSimon Schubert
38705796c8dcSSimon Schubert If the number fits in a long, set *BITS to 0 and return the value.
38715796c8dcSSimon Schubert If not, set *BITS to be the number of bits in the number and return 0.
38725796c8dcSSimon Schubert
38735796c8dcSSimon Schubert If encounter garbage, set *BITS to -1 and return 0. */
38745796c8dcSSimon Schubert
38755796c8dcSSimon Schubert static long
read_huge_number(char ** pp,int end,int * bits,int twos_complement_bits)38765796c8dcSSimon Schubert read_huge_number (char **pp, int end, int *bits, int twos_complement_bits)
38775796c8dcSSimon Schubert {
38785796c8dcSSimon Schubert char *p = *pp;
38795796c8dcSSimon Schubert int sign = 1;
38805796c8dcSSimon Schubert int sign_bit = 0;
38815796c8dcSSimon Schubert long n = 0;
38825796c8dcSSimon Schubert int radix = 10;
38835796c8dcSSimon Schubert char overflow = 0;
38845796c8dcSSimon Schubert int nbits = 0;
38855796c8dcSSimon Schubert int c;
38865796c8dcSSimon Schubert long upper_limit;
38875796c8dcSSimon Schubert int twos_complement_representation = 0;
38885796c8dcSSimon Schubert
38895796c8dcSSimon Schubert if (*p == '-')
38905796c8dcSSimon Schubert {
38915796c8dcSSimon Schubert sign = -1;
38925796c8dcSSimon Schubert p++;
38935796c8dcSSimon Schubert }
38945796c8dcSSimon Schubert
38955796c8dcSSimon Schubert /* Leading zero means octal. GCC uses this to output values larger
38965796c8dcSSimon Schubert than an int (because that would be hard in decimal). */
38975796c8dcSSimon Schubert if (*p == '0')
38985796c8dcSSimon Schubert {
38995796c8dcSSimon Schubert radix = 8;
39005796c8dcSSimon Schubert p++;
39015796c8dcSSimon Schubert }
39025796c8dcSSimon Schubert
39035796c8dcSSimon Schubert /* Skip extra zeros. */
39045796c8dcSSimon Schubert while (*p == '0')
39055796c8dcSSimon Schubert p++;
39065796c8dcSSimon Schubert
39075796c8dcSSimon Schubert if (sign > 0 && radix == 8 && twos_complement_bits > 0)
39085796c8dcSSimon Schubert {
39095796c8dcSSimon Schubert /* Octal, possibly signed. Check if we have enough chars for a
39105796c8dcSSimon Schubert negative number. */
39115796c8dcSSimon Schubert
39125796c8dcSSimon Schubert size_t len;
39135796c8dcSSimon Schubert char *p1 = p;
3914cf7f2e2dSJohn Marino
39155796c8dcSSimon Schubert while ((c = *p1) >= '0' && c < '8')
39165796c8dcSSimon Schubert p1++;
39175796c8dcSSimon Schubert
39185796c8dcSSimon Schubert len = p1 - p;
39195796c8dcSSimon Schubert if (len > twos_complement_bits / 3
3920c50c785cSJohn Marino || (twos_complement_bits % 3 == 0
3921c50c785cSJohn Marino && len == twos_complement_bits / 3))
39225796c8dcSSimon Schubert {
39235796c8dcSSimon Schubert /* Ok, we have enough characters for a signed value, check
39245796c8dcSSimon Schubert for signness by testing if the sign bit is set. */
39255796c8dcSSimon Schubert sign_bit = (twos_complement_bits % 3 + 2) % 3;
39265796c8dcSSimon Schubert c = *p - '0';
39275796c8dcSSimon Schubert if (c & (1 << sign_bit))
39285796c8dcSSimon Schubert {
39295796c8dcSSimon Schubert /* Definitely signed. */
39305796c8dcSSimon Schubert twos_complement_representation = 1;
39315796c8dcSSimon Schubert sign = -1;
39325796c8dcSSimon Schubert }
39335796c8dcSSimon Schubert }
39345796c8dcSSimon Schubert }
39355796c8dcSSimon Schubert
39365796c8dcSSimon Schubert upper_limit = LONG_MAX / radix;
39375796c8dcSSimon Schubert
39385796c8dcSSimon Schubert while ((c = *p++) >= '0' && c < ('0' + radix))
39395796c8dcSSimon Schubert {
39405796c8dcSSimon Schubert if (n <= upper_limit)
39415796c8dcSSimon Schubert {
39425796c8dcSSimon Schubert if (twos_complement_representation)
39435796c8dcSSimon Schubert {
39445796c8dcSSimon Schubert /* Octal, signed, twos complement representation. In
39455796c8dcSSimon Schubert this case, n is the corresponding absolute value. */
39465796c8dcSSimon Schubert if (n == 0)
39475796c8dcSSimon Schubert {
39485796c8dcSSimon Schubert long sn = c - '0' - ((2 * (c - '0')) | (2 << sign_bit));
3949cf7f2e2dSJohn Marino
39505796c8dcSSimon Schubert n = -sn;
39515796c8dcSSimon Schubert }
39525796c8dcSSimon Schubert else
39535796c8dcSSimon Schubert {
39545796c8dcSSimon Schubert n *= radix;
39555796c8dcSSimon Schubert n -= c - '0';
39565796c8dcSSimon Schubert }
39575796c8dcSSimon Schubert }
39585796c8dcSSimon Schubert else
39595796c8dcSSimon Schubert {
39605796c8dcSSimon Schubert /* unsigned representation */
39615796c8dcSSimon Schubert n *= radix;
3962c50c785cSJohn Marino n += c - '0'; /* FIXME this overflows anyway. */
39635796c8dcSSimon Schubert }
39645796c8dcSSimon Schubert }
39655796c8dcSSimon Schubert else
39665796c8dcSSimon Schubert overflow = 1;
39675796c8dcSSimon Schubert
39685796c8dcSSimon Schubert /* This depends on large values being output in octal, which is
39695796c8dcSSimon Schubert what GCC does. */
39705796c8dcSSimon Schubert if (radix == 8)
39715796c8dcSSimon Schubert {
39725796c8dcSSimon Schubert if (nbits == 0)
39735796c8dcSSimon Schubert {
39745796c8dcSSimon Schubert if (c == '0')
39755796c8dcSSimon Schubert /* Ignore leading zeroes. */
39765796c8dcSSimon Schubert ;
39775796c8dcSSimon Schubert else if (c == '1')
39785796c8dcSSimon Schubert nbits = 1;
39795796c8dcSSimon Schubert else if (c == '2' || c == '3')
39805796c8dcSSimon Schubert nbits = 2;
39815796c8dcSSimon Schubert else
39825796c8dcSSimon Schubert nbits = 3;
39835796c8dcSSimon Schubert }
39845796c8dcSSimon Schubert else
39855796c8dcSSimon Schubert nbits += 3;
39865796c8dcSSimon Schubert }
39875796c8dcSSimon Schubert }
39885796c8dcSSimon Schubert if (end)
39895796c8dcSSimon Schubert {
39905796c8dcSSimon Schubert if (c && c != end)
39915796c8dcSSimon Schubert {
39925796c8dcSSimon Schubert if (bits != NULL)
39935796c8dcSSimon Schubert *bits = -1;
39945796c8dcSSimon Schubert return 0;
39955796c8dcSSimon Schubert }
39965796c8dcSSimon Schubert }
39975796c8dcSSimon Schubert else
39985796c8dcSSimon Schubert --p;
39995796c8dcSSimon Schubert
40005796c8dcSSimon Schubert if (radix == 8 && twos_complement_bits > 0 && nbits > twos_complement_bits)
40015796c8dcSSimon Schubert {
40025796c8dcSSimon Schubert /* We were supposed to parse a number with maximum
40035796c8dcSSimon Schubert TWOS_COMPLEMENT_BITS bits, but something went wrong. */
40045796c8dcSSimon Schubert if (bits != NULL)
40055796c8dcSSimon Schubert *bits = -1;
40065796c8dcSSimon Schubert return 0;
40075796c8dcSSimon Schubert }
40085796c8dcSSimon Schubert
40095796c8dcSSimon Schubert *pp = p;
40105796c8dcSSimon Schubert if (overflow)
40115796c8dcSSimon Schubert {
40125796c8dcSSimon Schubert if (nbits == 0)
40135796c8dcSSimon Schubert {
40145796c8dcSSimon Schubert /* Large decimal constants are an error (because it is hard to
40155796c8dcSSimon Schubert count how many bits are in them). */
40165796c8dcSSimon Schubert if (bits != NULL)
40175796c8dcSSimon Schubert *bits = -1;
40185796c8dcSSimon Schubert return 0;
40195796c8dcSSimon Schubert }
40205796c8dcSSimon Schubert
40215796c8dcSSimon Schubert /* -0x7f is the same as 0x80. So deal with it by adding one to
40225796c8dcSSimon Schubert the number of bits. Two's complement represention octals
40235796c8dcSSimon Schubert can't have a '-' in front. */
40245796c8dcSSimon Schubert if (sign == -1 && !twos_complement_representation)
40255796c8dcSSimon Schubert ++nbits;
40265796c8dcSSimon Schubert if (bits)
40275796c8dcSSimon Schubert *bits = nbits;
40285796c8dcSSimon Schubert }
40295796c8dcSSimon Schubert else
40305796c8dcSSimon Schubert {
40315796c8dcSSimon Schubert if (bits)
40325796c8dcSSimon Schubert *bits = 0;
40335796c8dcSSimon Schubert return n * sign;
40345796c8dcSSimon Schubert }
40355796c8dcSSimon Schubert /* It's *BITS which has the interesting information. */
40365796c8dcSSimon Schubert return 0;
40375796c8dcSSimon Schubert }
40385796c8dcSSimon Schubert
40395796c8dcSSimon Schubert static struct type *
read_range_type(char ** pp,int typenums[2],int type_size,struct objfile * objfile)40405796c8dcSSimon Schubert read_range_type (char **pp, int typenums[2], int type_size,
40415796c8dcSSimon Schubert struct objfile *objfile)
40425796c8dcSSimon Schubert {
40435796c8dcSSimon Schubert struct gdbarch *gdbarch = get_objfile_arch (objfile);
40445796c8dcSSimon Schubert char *orig_pp = *pp;
40455796c8dcSSimon Schubert int rangenums[2];
40465796c8dcSSimon Schubert long n2, n3;
40475796c8dcSSimon Schubert int n2bits, n3bits;
40485796c8dcSSimon Schubert int self_subrange;
40495796c8dcSSimon Schubert struct type *result_type;
40505796c8dcSSimon Schubert struct type *index_type = NULL;
40515796c8dcSSimon Schubert
40525796c8dcSSimon Schubert /* First comes a type we are a subrange of.
40535796c8dcSSimon Schubert In C it is usually 0, 1 or the type being defined. */
40545796c8dcSSimon Schubert if (read_type_number (pp, rangenums) != 0)
40555796c8dcSSimon Schubert return error_type (pp, objfile);
40565796c8dcSSimon Schubert self_subrange = (rangenums[0] == typenums[0] &&
40575796c8dcSSimon Schubert rangenums[1] == typenums[1]);
40585796c8dcSSimon Schubert
40595796c8dcSSimon Schubert if (**pp == '=')
40605796c8dcSSimon Schubert {
40615796c8dcSSimon Schubert *pp = orig_pp;
40625796c8dcSSimon Schubert index_type = read_type (pp, objfile);
40635796c8dcSSimon Schubert }
40645796c8dcSSimon Schubert
40655796c8dcSSimon Schubert /* A semicolon should now follow; skip it. */
40665796c8dcSSimon Schubert if (**pp == ';')
40675796c8dcSSimon Schubert (*pp)++;
40685796c8dcSSimon Schubert
40695796c8dcSSimon Schubert /* The remaining two operands are usually lower and upper bounds
40705796c8dcSSimon Schubert of the range. But in some special cases they mean something else. */
40715796c8dcSSimon Schubert n2 = read_huge_number (pp, ';', &n2bits, type_size);
40725796c8dcSSimon Schubert n3 = read_huge_number (pp, ';', &n3bits, type_size);
40735796c8dcSSimon Schubert
40745796c8dcSSimon Schubert if (n2bits == -1 || n3bits == -1)
40755796c8dcSSimon Schubert return error_type (pp, objfile);
40765796c8dcSSimon Schubert
40775796c8dcSSimon Schubert if (index_type)
40785796c8dcSSimon Schubert goto handle_true_range;
40795796c8dcSSimon Schubert
40805796c8dcSSimon Schubert /* If limits are huge, must be large integral type. */
40815796c8dcSSimon Schubert if (n2bits != 0 || n3bits != 0)
40825796c8dcSSimon Schubert {
40835796c8dcSSimon Schubert char got_signed = 0;
40845796c8dcSSimon Schubert char got_unsigned = 0;
40855796c8dcSSimon Schubert /* Number of bits in the type. */
40865796c8dcSSimon Schubert int nbits = 0;
40875796c8dcSSimon Schubert
40885796c8dcSSimon Schubert /* If a type size attribute has been specified, the bounds of
40895796c8dcSSimon Schubert the range should fit in this size. If the lower bounds needs
40905796c8dcSSimon Schubert more bits than the upper bound, then the type is signed. */
40915796c8dcSSimon Schubert if (n2bits <= type_size && n3bits <= type_size)
40925796c8dcSSimon Schubert {
40935796c8dcSSimon Schubert if (n2bits == type_size && n2bits > n3bits)
40945796c8dcSSimon Schubert got_signed = 1;
40955796c8dcSSimon Schubert else
40965796c8dcSSimon Schubert got_unsigned = 1;
40975796c8dcSSimon Schubert nbits = type_size;
40985796c8dcSSimon Schubert }
40995796c8dcSSimon Schubert /* Range from 0 to <large number> is an unsigned large integral type. */
41005796c8dcSSimon Schubert else if ((n2bits == 0 && n2 == 0) && n3bits != 0)
41015796c8dcSSimon Schubert {
41025796c8dcSSimon Schubert got_unsigned = 1;
41035796c8dcSSimon Schubert nbits = n3bits;
41045796c8dcSSimon Schubert }
41055796c8dcSSimon Schubert /* Range from <large number> to <large number>-1 is a large signed
41065796c8dcSSimon Schubert integral type. Take care of the case where <large number> doesn't
41075796c8dcSSimon Schubert fit in a long but <large number>-1 does. */
41085796c8dcSSimon Schubert else if ((n2bits != 0 && n3bits != 0 && n2bits == n3bits + 1)
41095796c8dcSSimon Schubert || (n2bits != 0 && n3bits == 0
41105796c8dcSSimon Schubert && (n2bits == sizeof (long) * HOST_CHAR_BIT)
41115796c8dcSSimon Schubert && n3 == LONG_MAX))
41125796c8dcSSimon Schubert {
41135796c8dcSSimon Schubert got_signed = 1;
41145796c8dcSSimon Schubert nbits = n2bits;
41155796c8dcSSimon Schubert }
41165796c8dcSSimon Schubert
41175796c8dcSSimon Schubert if (got_signed || got_unsigned)
41185796c8dcSSimon Schubert {
41195796c8dcSSimon Schubert return init_type (TYPE_CODE_INT, nbits / TARGET_CHAR_BIT,
41205796c8dcSSimon Schubert got_unsigned ? TYPE_FLAG_UNSIGNED : 0, NULL,
41215796c8dcSSimon Schubert objfile);
41225796c8dcSSimon Schubert }
41235796c8dcSSimon Schubert else
41245796c8dcSSimon Schubert return error_type (pp, objfile);
41255796c8dcSSimon Schubert }
41265796c8dcSSimon Schubert
41275796c8dcSSimon Schubert /* A type defined as a subrange of itself, with bounds both 0, is void. */
41285796c8dcSSimon Schubert if (self_subrange && n2 == 0 && n3 == 0)
41295796c8dcSSimon Schubert return init_type (TYPE_CODE_VOID, 1, 0, NULL, objfile);
41305796c8dcSSimon Schubert
41315796c8dcSSimon Schubert /* If n3 is zero and n2 is positive, we want a floating type, and n2
41325796c8dcSSimon Schubert is the width in bytes.
41335796c8dcSSimon Schubert
41345796c8dcSSimon Schubert Fortran programs appear to use this for complex types also. To
41355796c8dcSSimon Schubert distinguish between floats and complex, g77 (and others?) seem
41365796c8dcSSimon Schubert to use self-subranges for the complexes, and subranges of int for
41375796c8dcSSimon Schubert the floats.
41385796c8dcSSimon Schubert
41395796c8dcSSimon Schubert Also note that for complexes, g77 sets n2 to the size of one of
41405796c8dcSSimon Schubert the member floats, not the whole complex beast. My guess is that
41415796c8dcSSimon Schubert this was to work well with pre-COMPLEX versions of gdb. */
41425796c8dcSSimon Schubert
41435796c8dcSSimon Schubert if (n3 == 0 && n2 > 0)
41445796c8dcSSimon Schubert {
41455796c8dcSSimon Schubert struct type *float_type
41465796c8dcSSimon Schubert = init_type (TYPE_CODE_FLT, n2, 0, NULL, objfile);
41475796c8dcSSimon Schubert
41485796c8dcSSimon Schubert if (self_subrange)
41495796c8dcSSimon Schubert {
41505796c8dcSSimon Schubert struct type *complex_type =
41515796c8dcSSimon Schubert init_type (TYPE_CODE_COMPLEX, 2 * n2, 0, NULL, objfile);
4152cf7f2e2dSJohn Marino
41535796c8dcSSimon Schubert TYPE_TARGET_TYPE (complex_type) = float_type;
41545796c8dcSSimon Schubert return complex_type;
41555796c8dcSSimon Schubert }
41565796c8dcSSimon Schubert else
41575796c8dcSSimon Schubert return float_type;
41585796c8dcSSimon Schubert }
41595796c8dcSSimon Schubert
41605796c8dcSSimon Schubert /* If the upper bound is -1, it must really be an unsigned integral. */
41615796c8dcSSimon Schubert
41625796c8dcSSimon Schubert else if (n2 == 0 && n3 == -1)
41635796c8dcSSimon Schubert {
41645796c8dcSSimon Schubert int bits = type_size;
4165cf7f2e2dSJohn Marino
41665796c8dcSSimon Schubert if (bits <= 0)
41675796c8dcSSimon Schubert {
41685796c8dcSSimon Schubert /* We don't know its size. It is unsigned int or unsigned
41695796c8dcSSimon Schubert long. GCC 2.3.3 uses this for long long too, but that is
41705796c8dcSSimon Schubert just a GDB 3.5 compatibility hack. */
41715796c8dcSSimon Schubert bits = gdbarch_int_bit (gdbarch);
41725796c8dcSSimon Schubert }
41735796c8dcSSimon Schubert
41745796c8dcSSimon Schubert return init_type (TYPE_CODE_INT, bits / TARGET_CHAR_BIT,
41755796c8dcSSimon Schubert TYPE_FLAG_UNSIGNED, NULL, objfile);
41765796c8dcSSimon Schubert }
41775796c8dcSSimon Schubert
41785796c8dcSSimon Schubert /* Special case: char is defined (Who knows why) as a subrange of
41795796c8dcSSimon Schubert itself with range 0-127. */
41805796c8dcSSimon Schubert else if (self_subrange && n2 == 0 && n3 == 127)
41815796c8dcSSimon Schubert return init_type (TYPE_CODE_INT, 1, TYPE_FLAG_NOSIGN, NULL, objfile);
41825796c8dcSSimon Schubert
41835796c8dcSSimon Schubert /* We used to do this only for subrange of self or subrange of int. */
41845796c8dcSSimon Schubert else if (n2 == 0)
41855796c8dcSSimon Schubert {
41865796c8dcSSimon Schubert /* -1 is used for the upper bound of (4 byte) "unsigned int" and
41875796c8dcSSimon Schubert "unsigned long", and we already checked for that,
41885796c8dcSSimon Schubert so don't need to test for it here. */
41895796c8dcSSimon Schubert
41905796c8dcSSimon Schubert if (n3 < 0)
41915796c8dcSSimon Schubert /* n3 actually gives the size. */
41925796c8dcSSimon Schubert return init_type (TYPE_CODE_INT, -n3, TYPE_FLAG_UNSIGNED,
41935796c8dcSSimon Schubert NULL, objfile);
41945796c8dcSSimon Schubert
41955796c8dcSSimon Schubert /* Is n3 == 2**(8n)-1 for some integer n? Then it's an
41965796c8dcSSimon Schubert unsigned n-byte integer. But do require n to be a power of
41975796c8dcSSimon Schubert two; we don't want 3- and 5-byte integers flying around. */
41985796c8dcSSimon Schubert {
41995796c8dcSSimon Schubert int bytes;
42005796c8dcSSimon Schubert unsigned long bits;
42015796c8dcSSimon Schubert
42025796c8dcSSimon Schubert bits = n3;
42035796c8dcSSimon Schubert for (bytes = 0; (bits & 0xff) == 0xff; bytes++)
42045796c8dcSSimon Schubert bits >>= 8;
42055796c8dcSSimon Schubert if (bits == 0
42065796c8dcSSimon Schubert && ((bytes - 1) & bytes) == 0) /* "bytes is a power of two" */
42075796c8dcSSimon Schubert return init_type (TYPE_CODE_INT, bytes, TYPE_FLAG_UNSIGNED, NULL,
42085796c8dcSSimon Schubert objfile);
42095796c8dcSSimon Schubert }
42105796c8dcSSimon Schubert }
42115796c8dcSSimon Schubert /* I think this is for Convex "long long". Since I don't know whether
42125796c8dcSSimon Schubert Convex sets self_subrange, I also accept that particular size regardless
42135796c8dcSSimon Schubert of self_subrange. */
42145796c8dcSSimon Schubert else if (n3 == 0 && n2 < 0
42155796c8dcSSimon Schubert && (self_subrange
42165796c8dcSSimon Schubert || n2 == -gdbarch_long_long_bit
42175796c8dcSSimon Schubert (gdbarch) / TARGET_CHAR_BIT))
42185796c8dcSSimon Schubert return init_type (TYPE_CODE_INT, -n2, 0, NULL, objfile);
42195796c8dcSSimon Schubert else if (n2 == -n3 - 1)
42205796c8dcSSimon Schubert {
42215796c8dcSSimon Schubert if (n3 == 0x7f)
42225796c8dcSSimon Schubert return init_type (TYPE_CODE_INT, 1, 0, NULL, objfile);
42235796c8dcSSimon Schubert if (n3 == 0x7fff)
42245796c8dcSSimon Schubert return init_type (TYPE_CODE_INT, 2, 0, NULL, objfile);
42255796c8dcSSimon Schubert if (n3 == 0x7fffffff)
42265796c8dcSSimon Schubert return init_type (TYPE_CODE_INT, 4, 0, NULL, objfile);
42275796c8dcSSimon Schubert }
42285796c8dcSSimon Schubert
42295796c8dcSSimon Schubert /* We have a real range type on our hands. Allocate space and
42305796c8dcSSimon Schubert return a real pointer. */
42315796c8dcSSimon Schubert handle_true_range:
42325796c8dcSSimon Schubert
42335796c8dcSSimon Schubert if (self_subrange)
42345796c8dcSSimon Schubert index_type = objfile_type (objfile)->builtin_int;
42355796c8dcSSimon Schubert else
42365796c8dcSSimon Schubert index_type = *dbx_lookup_type (rangenums, objfile);
42375796c8dcSSimon Schubert if (index_type == NULL)
42385796c8dcSSimon Schubert {
42395796c8dcSSimon Schubert /* Does this actually ever happen? Is that why we are worrying
42405796c8dcSSimon Schubert about dealing with it rather than just calling error_type? */
42415796c8dcSSimon Schubert
42425796c8dcSSimon Schubert complaint (&symfile_complaints,
42435796c8dcSSimon Schubert _("base type %d of range type is not defined"), rangenums[1]);
42445796c8dcSSimon Schubert
42455796c8dcSSimon Schubert index_type = objfile_type (objfile)->builtin_int;
42465796c8dcSSimon Schubert }
42475796c8dcSSimon Schubert
42485796c8dcSSimon Schubert result_type = create_range_type ((struct type *) NULL, index_type, n2, n3);
42495796c8dcSSimon Schubert return (result_type);
42505796c8dcSSimon Schubert }
42515796c8dcSSimon Schubert
42525796c8dcSSimon Schubert /* Read in an argument list. This is a list of types, separated by commas
42535796c8dcSSimon Schubert and terminated with END. Return the list of types read in, or NULL
42545796c8dcSSimon Schubert if there is an error. */
42555796c8dcSSimon Schubert
42565796c8dcSSimon Schubert static struct field *
read_args(char ** pp,int end,struct objfile * objfile,int * nargsp,int * varargsp)42575796c8dcSSimon Schubert read_args (char **pp, int end, struct objfile *objfile, int *nargsp,
42585796c8dcSSimon Schubert int *varargsp)
42595796c8dcSSimon Schubert {
42605796c8dcSSimon Schubert /* FIXME! Remove this arbitrary limit! */
4261c50c785cSJohn Marino struct type *types[1024]; /* Allow for fns of 1023 parameters. */
42625796c8dcSSimon Schubert int n = 0, i;
42635796c8dcSSimon Schubert struct field *rval;
42645796c8dcSSimon Schubert
42655796c8dcSSimon Schubert while (**pp != end)
42665796c8dcSSimon Schubert {
42675796c8dcSSimon Schubert if (**pp != ',')
42685796c8dcSSimon Schubert /* Invalid argument list: no ','. */
42695796c8dcSSimon Schubert return NULL;
42705796c8dcSSimon Schubert (*pp)++;
42715796c8dcSSimon Schubert STABS_CONTINUE (pp, objfile);
42725796c8dcSSimon Schubert types[n++] = read_type (pp, objfile);
42735796c8dcSSimon Schubert }
4274c50c785cSJohn Marino (*pp)++; /* get past `end' (the ':' character). */
42755796c8dcSSimon Schubert
4276cf7f2e2dSJohn Marino if (n == 0)
4277cf7f2e2dSJohn Marino {
4278cf7f2e2dSJohn Marino /* We should read at least the THIS parameter here. Some broken stabs
4279cf7f2e2dSJohn Marino output contained `(0,41),(0,42)=@s8;-16;,(0,43),(0,1);' where should
4280cf7f2e2dSJohn Marino have been present ";-16,(0,43)" reference instead. This way the
4281cf7f2e2dSJohn Marino excessive ";" marker prematurely stops the parameters parsing. */
4282cf7f2e2dSJohn Marino
4283cf7f2e2dSJohn Marino complaint (&symfile_complaints, _("Invalid (empty) method arguments"));
4284cf7f2e2dSJohn Marino *varargsp = 0;
4285cf7f2e2dSJohn Marino }
4286cf7f2e2dSJohn Marino else if (TYPE_CODE (types[n - 1]) != TYPE_CODE_VOID)
42875796c8dcSSimon Schubert *varargsp = 1;
42885796c8dcSSimon Schubert else
42895796c8dcSSimon Schubert {
42905796c8dcSSimon Schubert n--;
42915796c8dcSSimon Schubert *varargsp = 0;
42925796c8dcSSimon Schubert }
42935796c8dcSSimon Schubert
42945796c8dcSSimon Schubert rval = (struct field *) xmalloc (n * sizeof (struct field));
42955796c8dcSSimon Schubert memset (rval, 0, n * sizeof (struct field));
42965796c8dcSSimon Schubert for (i = 0; i < n; i++)
42975796c8dcSSimon Schubert rval[i].type = types[i];
42985796c8dcSSimon Schubert *nargsp = n;
42995796c8dcSSimon Schubert return rval;
43005796c8dcSSimon Schubert }
43015796c8dcSSimon Schubert
43025796c8dcSSimon Schubert /* Common block handling. */
43035796c8dcSSimon Schubert
43045796c8dcSSimon Schubert /* List of symbols declared since the last BCOMM. This list is a tail
43055796c8dcSSimon Schubert of local_symbols. When ECOMM is seen, the symbols on the list
43065796c8dcSSimon Schubert are noted so their proper addresses can be filled in later,
43075796c8dcSSimon Schubert using the common block base address gotten from the assembler
43085796c8dcSSimon Schubert stabs. */
43095796c8dcSSimon Schubert
43105796c8dcSSimon Schubert static struct pending *common_block;
43115796c8dcSSimon Schubert static int common_block_i;
43125796c8dcSSimon Schubert
43135796c8dcSSimon Schubert /* Name of the current common block. We get it from the BCOMM instead of the
43145796c8dcSSimon Schubert ECOMM to match IBM documentation (even though IBM puts the name both places
43155796c8dcSSimon Schubert like everyone else). */
43165796c8dcSSimon Schubert static char *common_block_name;
43175796c8dcSSimon Schubert
43185796c8dcSSimon Schubert /* Process a N_BCOMM symbol. The storage for NAME is not guaranteed
43195796c8dcSSimon Schubert to remain after this function returns. */
43205796c8dcSSimon Schubert
43215796c8dcSSimon Schubert void
common_block_start(char * name,struct objfile * objfile)43225796c8dcSSimon Schubert common_block_start (char *name, struct objfile *objfile)
43235796c8dcSSimon Schubert {
43245796c8dcSSimon Schubert if (common_block_name != NULL)
43255796c8dcSSimon Schubert {
43265796c8dcSSimon Schubert complaint (&symfile_complaints,
43275796c8dcSSimon Schubert _("Invalid symbol data: common block within common block"));
43285796c8dcSSimon Schubert }
43295796c8dcSSimon Schubert common_block = local_symbols;
43305796c8dcSSimon Schubert common_block_i = local_symbols ? local_symbols->nsyms : 0;
4331*ef5ccd6cSJohn Marino common_block_name = obstack_copy0 (&objfile->objfile_obstack,
4332*ef5ccd6cSJohn Marino name, strlen (name));
43335796c8dcSSimon Schubert }
43345796c8dcSSimon Schubert
43355796c8dcSSimon Schubert /* Process a N_ECOMM symbol. */
43365796c8dcSSimon Schubert
43375796c8dcSSimon Schubert void
common_block_end(struct objfile * objfile)43385796c8dcSSimon Schubert common_block_end (struct objfile *objfile)
43395796c8dcSSimon Schubert {
43405796c8dcSSimon Schubert /* Symbols declared since the BCOMM are to have the common block
43415796c8dcSSimon Schubert start address added in when we know it. common_block and
43425796c8dcSSimon Schubert common_block_i point to the first symbol after the BCOMM in
43435796c8dcSSimon Schubert the local_symbols list; copy the list and hang it off the
43445796c8dcSSimon Schubert symbol for the common block name for later fixup. */
43455796c8dcSSimon Schubert int i;
43465796c8dcSSimon Schubert struct symbol *sym;
43475796c8dcSSimon Schubert struct pending *new = 0;
43485796c8dcSSimon Schubert struct pending *next;
43495796c8dcSSimon Schubert int j;
43505796c8dcSSimon Schubert
43515796c8dcSSimon Schubert if (common_block_name == NULL)
43525796c8dcSSimon Schubert {
43535796c8dcSSimon Schubert complaint (&symfile_complaints, _("ECOMM symbol unmatched by BCOMM"));
43545796c8dcSSimon Schubert return;
43555796c8dcSSimon Schubert }
43565796c8dcSSimon Schubert
43575796c8dcSSimon Schubert sym = (struct symbol *)
43585796c8dcSSimon Schubert obstack_alloc (&objfile->objfile_obstack, sizeof (struct symbol));
43595796c8dcSSimon Schubert memset (sym, 0, sizeof (struct symbol));
4360c50c785cSJohn Marino /* Note: common_block_name already saved on objfile_obstack. */
43615796c8dcSSimon Schubert SYMBOL_SET_LINKAGE_NAME (sym, common_block_name);
43625796c8dcSSimon Schubert SYMBOL_CLASS (sym) = LOC_BLOCK;
43635796c8dcSSimon Schubert
43645796c8dcSSimon Schubert /* Now we copy all the symbols which have been defined since the BCOMM. */
43655796c8dcSSimon Schubert
43665796c8dcSSimon Schubert /* Copy all the struct pendings before common_block. */
43675796c8dcSSimon Schubert for (next = local_symbols;
43685796c8dcSSimon Schubert next != NULL && next != common_block;
43695796c8dcSSimon Schubert next = next->next)
43705796c8dcSSimon Schubert {
43715796c8dcSSimon Schubert for (j = 0; j < next->nsyms; j++)
43725796c8dcSSimon Schubert add_symbol_to_list (next->symbol[j], &new);
43735796c8dcSSimon Schubert }
43745796c8dcSSimon Schubert
43755796c8dcSSimon Schubert /* Copy however much of COMMON_BLOCK we need. If COMMON_BLOCK is
43765796c8dcSSimon Schubert NULL, it means copy all the local symbols (which we already did
43775796c8dcSSimon Schubert above). */
43785796c8dcSSimon Schubert
43795796c8dcSSimon Schubert if (common_block != NULL)
43805796c8dcSSimon Schubert for (j = common_block_i; j < common_block->nsyms; j++)
43815796c8dcSSimon Schubert add_symbol_to_list (common_block->symbol[j], &new);
43825796c8dcSSimon Schubert
43835796c8dcSSimon Schubert SYMBOL_TYPE (sym) = (struct type *) new;
43845796c8dcSSimon Schubert
43855796c8dcSSimon Schubert /* Should we be putting local_symbols back to what it was?
43865796c8dcSSimon Schubert Does it matter? */
43875796c8dcSSimon Schubert
43885796c8dcSSimon Schubert i = hashname (SYMBOL_LINKAGE_NAME (sym));
43895796c8dcSSimon Schubert SYMBOL_VALUE_CHAIN (sym) = global_sym_chain[i];
43905796c8dcSSimon Schubert global_sym_chain[i] = sym;
43915796c8dcSSimon Schubert common_block_name = NULL;
43925796c8dcSSimon Schubert }
43935796c8dcSSimon Schubert
43945796c8dcSSimon Schubert /* Add a common block's start address to the offset of each symbol
43955796c8dcSSimon Schubert declared to be in it (by being between a BCOMM/ECOMM pair that uses
43965796c8dcSSimon Schubert the common block name). */
43975796c8dcSSimon Schubert
43985796c8dcSSimon Schubert static void
fix_common_block(struct symbol * sym,CORE_ADDR valu)4399*ef5ccd6cSJohn Marino fix_common_block (struct symbol *sym, CORE_ADDR valu)
44005796c8dcSSimon Schubert {
44015796c8dcSSimon Schubert struct pending *next = (struct pending *) SYMBOL_TYPE (sym);
4402cf7f2e2dSJohn Marino
44035796c8dcSSimon Schubert for (; next; next = next->next)
44045796c8dcSSimon Schubert {
44055796c8dcSSimon Schubert int j;
4406cf7f2e2dSJohn Marino
44075796c8dcSSimon Schubert for (j = next->nsyms - 1; j >= 0; j--)
44085796c8dcSSimon Schubert SYMBOL_VALUE_ADDRESS (next->symbol[j]) += valu;
44095796c8dcSSimon Schubert }
44105796c8dcSSimon Schubert }
44115796c8dcSSimon Schubert
44125796c8dcSSimon Schubert
44135796c8dcSSimon Schubert
44145796c8dcSSimon Schubert /* Add {TYPE, TYPENUMS} to the NONAME_UNDEFS vector.
44155796c8dcSSimon Schubert See add_undefined_type for more details. */
44165796c8dcSSimon Schubert
44175796c8dcSSimon Schubert static void
add_undefined_type_noname(struct type * type,int typenums[2])44185796c8dcSSimon Schubert add_undefined_type_noname (struct type *type, int typenums[2])
44195796c8dcSSimon Schubert {
44205796c8dcSSimon Schubert struct nat nat;
44215796c8dcSSimon Schubert
44225796c8dcSSimon Schubert nat.typenums[0] = typenums [0];
44235796c8dcSSimon Schubert nat.typenums[1] = typenums [1];
44245796c8dcSSimon Schubert nat.type = type;
44255796c8dcSSimon Schubert
44265796c8dcSSimon Schubert if (noname_undefs_length == noname_undefs_allocated)
44275796c8dcSSimon Schubert {
44285796c8dcSSimon Schubert noname_undefs_allocated *= 2;
44295796c8dcSSimon Schubert noname_undefs = (struct nat *)
44305796c8dcSSimon Schubert xrealloc ((char *) noname_undefs,
44315796c8dcSSimon Schubert noname_undefs_allocated * sizeof (struct nat));
44325796c8dcSSimon Schubert }
44335796c8dcSSimon Schubert noname_undefs[noname_undefs_length++] = nat;
44345796c8dcSSimon Schubert }
44355796c8dcSSimon Schubert
44365796c8dcSSimon Schubert /* Add TYPE to the UNDEF_TYPES vector.
44375796c8dcSSimon Schubert See add_undefined_type for more details. */
44385796c8dcSSimon Schubert
44395796c8dcSSimon Schubert static void
add_undefined_type_1(struct type * type)44405796c8dcSSimon Schubert add_undefined_type_1 (struct type *type)
44415796c8dcSSimon Schubert {
44425796c8dcSSimon Schubert if (undef_types_length == undef_types_allocated)
44435796c8dcSSimon Schubert {
44445796c8dcSSimon Schubert undef_types_allocated *= 2;
44455796c8dcSSimon Schubert undef_types = (struct type **)
44465796c8dcSSimon Schubert xrealloc ((char *) undef_types,
44475796c8dcSSimon Schubert undef_types_allocated * sizeof (struct type *));
44485796c8dcSSimon Schubert }
44495796c8dcSSimon Schubert undef_types[undef_types_length++] = type;
44505796c8dcSSimon Schubert }
44515796c8dcSSimon Schubert
44525796c8dcSSimon Schubert /* What about types defined as forward references inside of a small lexical
44535796c8dcSSimon Schubert scope? */
44545796c8dcSSimon Schubert /* Add a type to the list of undefined types to be checked through
44555796c8dcSSimon Schubert once this file has been read in.
44565796c8dcSSimon Schubert
44575796c8dcSSimon Schubert In practice, we actually maintain two such lists: The first list
44585796c8dcSSimon Schubert (UNDEF_TYPES) is used for types whose name has been provided, and
44595796c8dcSSimon Schubert concerns forward references (eg 'xs' or 'xu' forward references);
44605796c8dcSSimon Schubert the second list (NONAME_UNDEFS) is used for types whose name is
44615796c8dcSSimon Schubert unknown at creation time, because they were referenced through
44625796c8dcSSimon Schubert their type number before the actual type was declared.
44635796c8dcSSimon Schubert This function actually adds the given type to the proper list. */
44645796c8dcSSimon Schubert
44655796c8dcSSimon Schubert static void
add_undefined_type(struct type * type,int typenums[2])44665796c8dcSSimon Schubert add_undefined_type (struct type *type, int typenums[2])
44675796c8dcSSimon Schubert {
44685796c8dcSSimon Schubert if (TYPE_TAG_NAME (type) == NULL)
44695796c8dcSSimon Schubert add_undefined_type_noname (type, typenums);
44705796c8dcSSimon Schubert else
44715796c8dcSSimon Schubert add_undefined_type_1 (type);
44725796c8dcSSimon Schubert }
44735796c8dcSSimon Schubert
44745796c8dcSSimon Schubert /* Try to fix all undefined types pushed on the UNDEF_TYPES vector. */
44755796c8dcSSimon Schubert
44765796c8dcSSimon Schubert static void
cleanup_undefined_types_noname(struct objfile * objfile)44775796c8dcSSimon Schubert cleanup_undefined_types_noname (struct objfile *objfile)
44785796c8dcSSimon Schubert {
44795796c8dcSSimon Schubert int i;
44805796c8dcSSimon Schubert
44815796c8dcSSimon Schubert for (i = 0; i < noname_undefs_length; i++)
44825796c8dcSSimon Schubert {
44835796c8dcSSimon Schubert struct nat nat = noname_undefs[i];
44845796c8dcSSimon Schubert struct type **type;
44855796c8dcSSimon Schubert
44865796c8dcSSimon Schubert type = dbx_lookup_type (nat.typenums, objfile);
44875796c8dcSSimon Schubert if (nat.type != *type && TYPE_CODE (*type) != TYPE_CODE_UNDEF)
44885796c8dcSSimon Schubert {
44895796c8dcSSimon Schubert /* The instance flags of the undefined type are still unset,
44905796c8dcSSimon Schubert and needs to be copied over from the reference type.
44915796c8dcSSimon Schubert Since replace_type expects them to be identical, we need
44925796c8dcSSimon Schubert to set these flags manually before hand. */
44935796c8dcSSimon Schubert TYPE_INSTANCE_FLAGS (nat.type) = TYPE_INSTANCE_FLAGS (*type);
44945796c8dcSSimon Schubert replace_type (nat.type, *type);
44955796c8dcSSimon Schubert }
44965796c8dcSSimon Schubert }
44975796c8dcSSimon Schubert
44985796c8dcSSimon Schubert noname_undefs_length = 0;
44995796c8dcSSimon Schubert }
45005796c8dcSSimon Schubert
45015796c8dcSSimon Schubert /* Go through each undefined type, see if it's still undefined, and fix it
45025796c8dcSSimon Schubert up if possible. We have two kinds of undefined types:
45035796c8dcSSimon Schubert
45045796c8dcSSimon Schubert TYPE_CODE_ARRAY: Array whose target type wasn't defined yet.
45055796c8dcSSimon Schubert Fix: update array length using the element bounds
45065796c8dcSSimon Schubert and the target type's length.
45075796c8dcSSimon Schubert TYPE_CODE_STRUCT, TYPE_CODE_UNION: Structure whose fields were not
45085796c8dcSSimon Schubert yet defined at the time a pointer to it was made.
45095796c8dcSSimon Schubert Fix: Do a full lookup on the struct/union tag. */
45105796c8dcSSimon Schubert
45115796c8dcSSimon Schubert static void
cleanup_undefined_types_1(void)45125796c8dcSSimon Schubert cleanup_undefined_types_1 (void)
45135796c8dcSSimon Schubert {
45145796c8dcSSimon Schubert struct type **type;
45155796c8dcSSimon Schubert
45165796c8dcSSimon Schubert /* Iterate over every undefined type, and look for a symbol whose type
45175796c8dcSSimon Schubert matches our undefined type. The symbol matches if:
45185796c8dcSSimon Schubert 1. It is a typedef in the STRUCT domain;
45195796c8dcSSimon Schubert 2. It has the same name, and same type code;
45205796c8dcSSimon Schubert 3. The instance flags are identical.
45215796c8dcSSimon Schubert
45225796c8dcSSimon Schubert It is important to check the instance flags, because we have seen
45235796c8dcSSimon Schubert examples where the debug info contained definitions such as:
45245796c8dcSSimon Schubert
45255796c8dcSSimon Schubert "foo_t:t30=B31=xefoo_t:"
45265796c8dcSSimon Schubert
45275796c8dcSSimon Schubert In this case, we have created an undefined type named "foo_t" whose
45285796c8dcSSimon Schubert instance flags is null (when processing "xefoo_t"), and then created
45295796c8dcSSimon Schubert another type with the same name, but with different instance flags
45305796c8dcSSimon Schubert ('B' means volatile). I think that the definition above is wrong,
45315796c8dcSSimon Schubert since the same type cannot be volatile and non-volatile at the same
45325796c8dcSSimon Schubert time, but we need to be able to cope with it when it happens. The
45335796c8dcSSimon Schubert approach taken here is to treat these two types as different. */
45345796c8dcSSimon Schubert
45355796c8dcSSimon Schubert for (type = undef_types; type < undef_types + undef_types_length; type++)
45365796c8dcSSimon Schubert {
45375796c8dcSSimon Schubert switch (TYPE_CODE (*type))
45385796c8dcSSimon Schubert {
45395796c8dcSSimon Schubert
45405796c8dcSSimon Schubert case TYPE_CODE_STRUCT:
45415796c8dcSSimon Schubert case TYPE_CODE_UNION:
45425796c8dcSSimon Schubert case TYPE_CODE_ENUM:
45435796c8dcSSimon Schubert {
45445796c8dcSSimon Schubert /* Check if it has been defined since. Need to do this here
45455796c8dcSSimon Schubert as well as in check_typedef to deal with the (legitimate in
45465796c8dcSSimon Schubert C though not C++) case of several types with the same name
45475796c8dcSSimon Schubert in different source files. */
45485796c8dcSSimon Schubert if (TYPE_STUB (*type))
45495796c8dcSSimon Schubert {
45505796c8dcSSimon Schubert struct pending *ppt;
45515796c8dcSSimon Schubert int i;
4552c50c785cSJohn Marino /* Name of the type, without "struct" or "union". */
4553*ef5ccd6cSJohn Marino const char *typename = TYPE_TAG_NAME (*type);
45545796c8dcSSimon Schubert
45555796c8dcSSimon Schubert if (typename == NULL)
45565796c8dcSSimon Schubert {
45575796c8dcSSimon Schubert complaint (&symfile_complaints, _("need a type name"));
45585796c8dcSSimon Schubert break;
45595796c8dcSSimon Schubert }
45605796c8dcSSimon Schubert for (ppt = file_symbols; ppt; ppt = ppt->next)
45615796c8dcSSimon Schubert {
45625796c8dcSSimon Schubert for (i = 0; i < ppt->nsyms; i++)
45635796c8dcSSimon Schubert {
45645796c8dcSSimon Schubert struct symbol *sym = ppt->symbol[i];
45655796c8dcSSimon Schubert
45665796c8dcSSimon Schubert if (SYMBOL_CLASS (sym) == LOC_TYPEDEF
45675796c8dcSSimon Schubert && SYMBOL_DOMAIN (sym) == STRUCT_DOMAIN
45685796c8dcSSimon Schubert && (TYPE_CODE (SYMBOL_TYPE (sym)) ==
45695796c8dcSSimon Schubert TYPE_CODE (*type))
45705796c8dcSSimon Schubert && (TYPE_INSTANCE_FLAGS (*type) ==
45715796c8dcSSimon Schubert TYPE_INSTANCE_FLAGS (SYMBOL_TYPE (sym)))
45725796c8dcSSimon Schubert && strcmp (SYMBOL_LINKAGE_NAME (sym),
45735796c8dcSSimon Schubert typename) == 0)
45745796c8dcSSimon Schubert replace_type (*type, SYMBOL_TYPE (sym));
45755796c8dcSSimon Schubert }
45765796c8dcSSimon Schubert }
45775796c8dcSSimon Schubert }
45785796c8dcSSimon Schubert }
45795796c8dcSSimon Schubert break;
45805796c8dcSSimon Schubert
45815796c8dcSSimon Schubert default:
45825796c8dcSSimon Schubert {
45835796c8dcSSimon Schubert complaint (&symfile_complaints,
45845796c8dcSSimon Schubert _("forward-referenced types left unresolved, "
45855796c8dcSSimon Schubert "type code %d."),
45865796c8dcSSimon Schubert TYPE_CODE (*type));
45875796c8dcSSimon Schubert }
45885796c8dcSSimon Schubert break;
45895796c8dcSSimon Schubert }
45905796c8dcSSimon Schubert }
45915796c8dcSSimon Schubert
45925796c8dcSSimon Schubert undef_types_length = 0;
45935796c8dcSSimon Schubert }
45945796c8dcSSimon Schubert
45955796c8dcSSimon Schubert /* Try to fix all the undefined types we ecountered while processing
45965796c8dcSSimon Schubert this unit. */
45975796c8dcSSimon Schubert
45985796c8dcSSimon Schubert void
cleanup_undefined_stabs_types(struct objfile * objfile)4599*ef5ccd6cSJohn Marino cleanup_undefined_stabs_types (struct objfile *objfile)
46005796c8dcSSimon Schubert {
46015796c8dcSSimon Schubert cleanup_undefined_types_1 ();
46025796c8dcSSimon Schubert cleanup_undefined_types_noname (objfile);
46035796c8dcSSimon Schubert }
46045796c8dcSSimon Schubert
46055796c8dcSSimon Schubert /* Scan through all of the global symbols defined in the object file,
46065796c8dcSSimon Schubert assigning values to the debugging symbols that need to be assigned
46075796c8dcSSimon Schubert to. Get these symbols from the minimal symbol table. */
46085796c8dcSSimon Schubert
46095796c8dcSSimon Schubert void
scan_file_globals(struct objfile * objfile)46105796c8dcSSimon Schubert scan_file_globals (struct objfile *objfile)
46115796c8dcSSimon Schubert {
46125796c8dcSSimon Schubert int hash;
46135796c8dcSSimon Schubert struct minimal_symbol *msymbol;
46145796c8dcSSimon Schubert struct symbol *sym, *prev;
46155796c8dcSSimon Schubert struct objfile *resolve_objfile;
46165796c8dcSSimon Schubert
46175796c8dcSSimon Schubert /* SVR4 based linkers copy referenced global symbols from shared
46185796c8dcSSimon Schubert libraries to the main executable.
46195796c8dcSSimon Schubert If we are scanning the symbols for a shared library, try to resolve
46205796c8dcSSimon Schubert them from the minimal symbols of the main executable first. */
46215796c8dcSSimon Schubert
46225796c8dcSSimon Schubert if (symfile_objfile && objfile != symfile_objfile)
46235796c8dcSSimon Schubert resolve_objfile = symfile_objfile;
46245796c8dcSSimon Schubert else
46255796c8dcSSimon Schubert resolve_objfile = objfile;
46265796c8dcSSimon Schubert
46275796c8dcSSimon Schubert while (1)
46285796c8dcSSimon Schubert {
46295796c8dcSSimon Schubert /* Avoid expensive loop through all minimal symbols if there are
46305796c8dcSSimon Schubert no unresolved symbols. */
46315796c8dcSSimon Schubert for (hash = 0; hash < HASHSIZE; hash++)
46325796c8dcSSimon Schubert {
46335796c8dcSSimon Schubert if (global_sym_chain[hash])
46345796c8dcSSimon Schubert break;
46355796c8dcSSimon Schubert }
46365796c8dcSSimon Schubert if (hash >= HASHSIZE)
46375796c8dcSSimon Schubert return;
46385796c8dcSSimon Schubert
46395796c8dcSSimon Schubert ALL_OBJFILE_MSYMBOLS (resolve_objfile, msymbol)
46405796c8dcSSimon Schubert {
46415796c8dcSSimon Schubert QUIT;
46425796c8dcSSimon Schubert
46435796c8dcSSimon Schubert /* Skip static symbols. */
46445796c8dcSSimon Schubert switch (MSYMBOL_TYPE (msymbol))
46455796c8dcSSimon Schubert {
46465796c8dcSSimon Schubert case mst_file_text:
46475796c8dcSSimon Schubert case mst_file_data:
46485796c8dcSSimon Schubert case mst_file_bss:
46495796c8dcSSimon Schubert continue;
46505796c8dcSSimon Schubert default:
46515796c8dcSSimon Schubert break;
46525796c8dcSSimon Schubert }
46535796c8dcSSimon Schubert
46545796c8dcSSimon Schubert prev = NULL;
46555796c8dcSSimon Schubert
46565796c8dcSSimon Schubert /* Get the hash index and check all the symbols
46575796c8dcSSimon Schubert under that hash index. */
46585796c8dcSSimon Schubert
46595796c8dcSSimon Schubert hash = hashname (SYMBOL_LINKAGE_NAME (msymbol));
46605796c8dcSSimon Schubert
46615796c8dcSSimon Schubert for (sym = global_sym_chain[hash]; sym;)
46625796c8dcSSimon Schubert {
46635796c8dcSSimon Schubert if (strcmp (SYMBOL_LINKAGE_NAME (msymbol),
46645796c8dcSSimon Schubert SYMBOL_LINKAGE_NAME (sym)) == 0)
46655796c8dcSSimon Schubert {
46665796c8dcSSimon Schubert /* Splice this symbol out of the hash chain and
46675796c8dcSSimon Schubert assign the value we have to it. */
46685796c8dcSSimon Schubert if (prev)
46695796c8dcSSimon Schubert {
46705796c8dcSSimon Schubert SYMBOL_VALUE_CHAIN (prev) = SYMBOL_VALUE_CHAIN (sym);
46715796c8dcSSimon Schubert }
46725796c8dcSSimon Schubert else
46735796c8dcSSimon Schubert {
46745796c8dcSSimon Schubert global_sym_chain[hash] = SYMBOL_VALUE_CHAIN (sym);
46755796c8dcSSimon Schubert }
46765796c8dcSSimon Schubert
46775796c8dcSSimon Schubert /* Check to see whether we need to fix up a common block. */
46785796c8dcSSimon Schubert /* Note: this code might be executed several times for
46795796c8dcSSimon Schubert the same symbol if there are multiple references. */
46805796c8dcSSimon Schubert if (sym)
46815796c8dcSSimon Schubert {
46825796c8dcSSimon Schubert if (SYMBOL_CLASS (sym) == LOC_BLOCK)
46835796c8dcSSimon Schubert {
46845796c8dcSSimon Schubert fix_common_block (sym,
46855796c8dcSSimon Schubert SYMBOL_VALUE_ADDRESS (msymbol));
46865796c8dcSSimon Schubert }
46875796c8dcSSimon Schubert else
46885796c8dcSSimon Schubert {
46895796c8dcSSimon Schubert SYMBOL_VALUE_ADDRESS (sym)
46905796c8dcSSimon Schubert = SYMBOL_VALUE_ADDRESS (msymbol);
46915796c8dcSSimon Schubert }
46925796c8dcSSimon Schubert SYMBOL_SECTION (sym) = SYMBOL_SECTION (msymbol);
46935796c8dcSSimon Schubert }
46945796c8dcSSimon Schubert
46955796c8dcSSimon Schubert if (prev)
46965796c8dcSSimon Schubert {
46975796c8dcSSimon Schubert sym = SYMBOL_VALUE_CHAIN (prev);
46985796c8dcSSimon Schubert }
46995796c8dcSSimon Schubert else
47005796c8dcSSimon Schubert {
47015796c8dcSSimon Schubert sym = global_sym_chain[hash];
47025796c8dcSSimon Schubert }
47035796c8dcSSimon Schubert }
47045796c8dcSSimon Schubert else
47055796c8dcSSimon Schubert {
47065796c8dcSSimon Schubert prev = sym;
47075796c8dcSSimon Schubert sym = SYMBOL_VALUE_CHAIN (sym);
47085796c8dcSSimon Schubert }
47095796c8dcSSimon Schubert }
47105796c8dcSSimon Schubert }
47115796c8dcSSimon Schubert if (resolve_objfile == objfile)
47125796c8dcSSimon Schubert break;
47135796c8dcSSimon Schubert resolve_objfile = objfile;
47145796c8dcSSimon Schubert }
47155796c8dcSSimon Schubert
47165796c8dcSSimon Schubert /* Change the storage class of any remaining unresolved globals to
47175796c8dcSSimon Schubert LOC_UNRESOLVED and remove them from the chain. */
47185796c8dcSSimon Schubert for (hash = 0; hash < HASHSIZE; hash++)
47195796c8dcSSimon Schubert {
47205796c8dcSSimon Schubert sym = global_sym_chain[hash];
47215796c8dcSSimon Schubert while (sym)
47225796c8dcSSimon Schubert {
47235796c8dcSSimon Schubert prev = sym;
47245796c8dcSSimon Schubert sym = SYMBOL_VALUE_CHAIN (sym);
47255796c8dcSSimon Schubert
47265796c8dcSSimon Schubert /* Change the symbol address from the misleading chain value
47275796c8dcSSimon Schubert to address zero. */
47285796c8dcSSimon Schubert SYMBOL_VALUE_ADDRESS (prev) = 0;
47295796c8dcSSimon Schubert
47305796c8dcSSimon Schubert /* Complain about unresolved common block symbols. */
47315796c8dcSSimon Schubert if (SYMBOL_CLASS (prev) == LOC_STATIC)
47325796c8dcSSimon Schubert SYMBOL_CLASS (prev) = LOC_UNRESOLVED;
47335796c8dcSSimon Schubert else
47345796c8dcSSimon Schubert complaint (&symfile_complaints,
4735c50c785cSJohn Marino _("%s: common block `%s' from "
4736c50c785cSJohn Marino "global_sym_chain unresolved"),
47375796c8dcSSimon Schubert objfile->name, SYMBOL_PRINT_NAME (prev));
47385796c8dcSSimon Schubert }
47395796c8dcSSimon Schubert }
47405796c8dcSSimon Schubert memset (global_sym_chain, 0, sizeof (global_sym_chain));
47415796c8dcSSimon Schubert }
47425796c8dcSSimon Schubert
47435796c8dcSSimon Schubert /* Initialize anything that needs initializing when starting to read
47445796c8dcSSimon Schubert a fresh piece of a symbol file, e.g. reading in the stuff corresponding
47455796c8dcSSimon Schubert to a psymtab. */
47465796c8dcSSimon Schubert
47475796c8dcSSimon Schubert void
stabsread_init(void)47485796c8dcSSimon Schubert stabsread_init (void)
47495796c8dcSSimon Schubert {
47505796c8dcSSimon Schubert }
47515796c8dcSSimon Schubert
47525796c8dcSSimon Schubert /* Initialize anything that needs initializing when a completely new
47535796c8dcSSimon Schubert symbol file is specified (not just adding some symbols from another
47545796c8dcSSimon Schubert file, e.g. a shared library). */
47555796c8dcSSimon Schubert
47565796c8dcSSimon Schubert void
stabsread_new_init(void)47575796c8dcSSimon Schubert stabsread_new_init (void)
47585796c8dcSSimon Schubert {
47595796c8dcSSimon Schubert /* Empty the hash table of global syms looking for values. */
47605796c8dcSSimon Schubert memset (global_sym_chain, 0, sizeof (global_sym_chain));
47615796c8dcSSimon Schubert }
47625796c8dcSSimon Schubert
47635796c8dcSSimon Schubert /* Initialize anything that needs initializing at the same time as
47645796c8dcSSimon Schubert start_symtab() is called. */
47655796c8dcSSimon Schubert
47665796c8dcSSimon Schubert void
start_stabs(void)47675796c8dcSSimon Schubert start_stabs (void)
47685796c8dcSSimon Schubert {
47695796c8dcSSimon Schubert global_stabs = NULL; /* AIX COFF */
47705796c8dcSSimon Schubert /* Leave FILENUM of 0 free for builtin types and this file's types. */
47715796c8dcSSimon Schubert n_this_object_header_files = 1;
47725796c8dcSSimon Schubert type_vector_length = 0;
47735796c8dcSSimon Schubert type_vector = (struct type **) 0;
47745796c8dcSSimon Schubert
47755796c8dcSSimon Schubert /* FIXME: If common_block_name is not already NULL, we should complain(). */
47765796c8dcSSimon Schubert common_block_name = NULL;
47775796c8dcSSimon Schubert }
47785796c8dcSSimon Schubert
4779c50c785cSJohn Marino /* Call after end_symtab(). */
47805796c8dcSSimon Schubert
47815796c8dcSSimon Schubert void
end_stabs(void)47825796c8dcSSimon Schubert end_stabs (void)
47835796c8dcSSimon Schubert {
47845796c8dcSSimon Schubert if (type_vector)
47855796c8dcSSimon Schubert {
47865796c8dcSSimon Schubert xfree (type_vector);
47875796c8dcSSimon Schubert }
47885796c8dcSSimon Schubert type_vector = 0;
47895796c8dcSSimon Schubert type_vector_length = 0;
47905796c8dcSSimon Schubert previous_stab_code = 0;
47915796c8dcSSimon Schubert }
47925796c8dcSSimon Schubert
47935796c8dcSSimon Schubert void
finish_global_stabs(struct objfile * objfile)47945796c8dcSSimon Schubert finish_global_stabs (struct objfile *objfile)
47955796c8dcSSimon Schubert {
47965796c8dcSSimon Schubert if (global_stabs)
47975796c8dcSSimon Schubert {
47985796c8dcSSimon Schubert patch_block_stabs (global_symbols, global_stabs, objfile);
47995796c8dcSSimon Schubert xfree (global_stabs);
48005796c8dcSSimon Schubert global_stabs = NULL;
48015796c8dcSSimon Schubert }
48025796c8dcSSimon Schubert }
48035796c8dcSSimon Schubert
48045796c8dcSSimon Schubert /* Find the end of the name, delimited by a ':', but don't match
48055796c8dcSSimon Schubert ObjC symbols which look like -[Foo bar::]:bla. */
48065796c8dcSSimon Schubert static char *
find_name_end(char * name)48075796c8dcSSimon Schubert find_name_end (char *name)
48085796c8dcSSimon Schubert {
48095796c8dcSSimon Schubert char *s = name;
4810cf7f2e2dSJohn Marino
48115796c8dcSSimon Schubert if (s[0] == '-' || *s == '+')
48125796c8dcSSimon Schubert {
48135796c8dcSSimon Schubert /* Must be an ObjC method symbol. */
48145796c8dcSSimon Schubert if (s[1] != '[')
48155796c8dcSSimon Schubert {
48165796c8dcSSimon Schubert error (_("invalid symbol name \"%s\""), name);
48175796c8dcSSimon Schubert }
48185796c8dcSSimon Schubert s = strchr (s, ']');
48195796c8dcSSimon Schubert if (s == NULL)
48205796c8dcSSimon Schubert {
48215796c8dcSSimon Schubert error (_("invalid symbol name \"%s\""), name);
48225796c8dcSSimon Schubert }
48235796c8dcSSimon Schubert return strchr (s, ':');
48245796c8dcSSimon Schubert }
48255796c8dcSSimon Schubert else
48265796c8dcSSimon Schubert {
48275796c8dcSSimon Schubert return strchr (s, ':');
48285796c8dcSSimon Schubert }
48295796c8dcSSimon Schubert }
48305796c8dcSSimon Schubert
4831c50c785cSJohn Marino /* Initializer for this module. */
48325796c8dcSSimon Schubert
48335796c8dcSSimon Schubert void
_initialize_stabsread(void)48345796c8dcSSimon Schubert _initialize_stabsread (void)
48355796c8dcSSimon Schubert {
48365796c8dcSSimon Schubert rs6000_builtin_type_data = register_objfile_data ();
48375796c8dcSSimon Schubert
48385796c8dcSSimon Schubert undef_types_allocated = 20;
48395796c8dcSSimon Schubert undef_types_length = 0;
48405796c8dcSSimon Schubert undef_types = (struct type **)
48415796c8dcSSimon Schubert xmalloc (undef_types_allocated * sizeof (struct type *));
48425796c8dcSSimon Schubert
48435796c8dcSSimon Schubert noname_undefs_allocated = 20;
48445796c8dcSSimon Schubert noname_undefs_length = 0;
48455796c8dcSSimon Schubert noname_undefs = (struct nat *)
48465796c8dcSSimon Schubert xmalloc (noname_undefs_allocated * sizeof (struct nat));
48475796c8dcSSimon Schubert }
4848