119370Spst/* Support routines for decoding "stabs" debugging information format. 219370Spst 3130803Smarcel Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 4130803Smarcel 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free 5130803Smarcel Software Foundation, Inc. 6130803Smarcel 798944Sobrien This file is part of GDB. 819370Spst 998944Sobrien This program is free software; you can redistribute it and/or modify 1098944Sobrien it under the terms of the GNU General Public License as published by 1198944Sobrien the Free Software Foundation; either version 2 of the License, or 1298944Sobrien (at your option) any later version. 1319370Spst 1498944Sobrien This program is distributed in the hope that it will be useful, 1598944Sobrien but WITHOUT ANY WARRANTY; without even the implied warranty of 1698944Sobrien MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1798944Sobrien GNU General Public License for more details. 1819370Spst 1998944Sobrien You should have received a copy of the GNU General Public License 2098944Sobrien along with this program; if not, write to the Free Software 2198944Sobrien Foundation, Inc., 59 Temple Place - Suite 330, 2298944Sobrien Boston, MA 02111-1307, USA. */ 2319370Spst 2419370Spst/* Support routines for reading and decoding debugging information in 2519370Spst the "stabs" format. This format is used with many systems that use 2619370Spst the a.out object file format, as well as some systems that use 2719370Spst COFF or ELF where the stabs data is placed in a special section. 2819370Spst Avoid placing any object file format specific code in this file. */ 2919370Spst 3019370Spst#include "defs.h" 3119370Spst#include "gdb_string.h" 3219370Spst#include "bfd.h" 33130803Smarcel#include "gdb_obstack.h" 3419370Spst#include "symtab.h" 3519370Spst#include "gdbtypes.h" 3619370Spst#include "expression.h" 3719370Spst#include "symfile.h" 3819370Spst#include "objfiles.h" 3919370Spst#include "aout/stab_gnu.h" /* We always use GNU stabs, not native */ 4019370Spst#include "libaout.h" 4119370Spst#include "aout/aout64.h" 4219370Spst#include "gdb-stabs.h" 4319370Spst#include "buildsym.h" 4419370Spst#include "complaints.h" 4519370Spst#include "demangle.h" 4619370Spst#include "language.h" 4798944Sobrien#include "doublest.h" 48130803Smarcel#include "cp-abi.h" 49130803Smarcel#include "cp-support.h" 5019370Spst 5119370Spst#include <ctype.h> 5219370Spst 5319370Spst/* Ask stabsread.h to define the vars it normally declares `extern'. */ 5498944Sobrien#define EXTERN 5598944Sobrien/**/ 5619370Spst#include "stabsread.h" /* Our own declarations */ 5719370Spst#undef EXTERN 5819370Spst 5998944Sobrienextern void _initialize_stabsread (void); 6098944Sobrien 6119370Spst/* The routines that read and process a complete stabs for a C struct or 6219370Spst C++ class pass lists of data member fields and lists of member function 6319370Spst fields in an instance of a field_info structure, as defined below. 6419370Spst This is part of some reorganization of low level C++ support and is 6519370Spst expected to eventually go away... (FIXME) */ 6619370Spst 6719370Spststruct field_info 6898944Sobrien { 6998944Sobrien struct nextfield 7098944Sobrien { 7198944Sobrien struct nextfield *next; 7219370Spst 7398944Sobrien /* This is the raw visibility from the stab. It is not checked 7498944Sobrien for being one of the visibilities we recognize, so code which 7598944Sobrien examines this field better be able to deal. */ 7698944Sobrien int visibility; 7719370Spst 7898944Sobrien struct field field; 7998944Sobrien } 8098944Sobrien *list; 8198944Sobrien struct next_fnfieldlist 8298944Sobrien { 8398944Sobrien struct next_fnfieldlist *next; 8498944Sobrien struct fn_fieldlist fn_fieldlist; 8598944Sobrien } 8698944Sobrien *fnlist; 8798944Sobrien }; 8819370Spst 8946283Sdfrstatic void 9098944Sobrienread_one_struct_field (struct field_info *, char **, char *, 9198944Sobrien struct type *, struct objfile *); 9246283Sdfr 9398944Sobrienstatic struct type *dbx_alloc_type (int[2], struct objfile *); 9419370Spst 9598944Sobrienstatic long read_huge_number (char **, int, int *); 9619370Spst 9798944Sobrienstatic struct type *error_type (char **, struct objfile *); 9819370Spst 9919370Spststatic void 10098944Sobrienpatch_block_stabs (struct pending *, struct pending_stabs *, 10198944Sobrien struct objfile *); 10219370Spst 10398944Sobrienstatic void fix_common_block (struct symbol *, int); 10419370Spst 10598944Sobrienstatic int read_type_number (char **, int *); 10619370Spst 107130803Smarcelstatic struct type *read_type (char **, struct objfile *); 108130803Smarcel 10998944Sobrienstatic struct type *read_range_type (char **, int[2], struct objfile *); 11019370Spst 11198944Sobrienstatic struct type *read_sun_builtin_type (char **, int[2], struct objfile *); 11219370Spst 11398944Sobrienstatic struct type *read_sun_floating_type (char **, int[2], 11498944Sobrien struct objfile *); 11519370Spst 11698944Sobrienstatic struct type *read_enum_type (char **, struct type *, struct objfile *); 11719370Spst 11898944Sobrienstatic struct type *rs6000_builtin_type (int); 11919370Spst 12019370Spststatic int 12198944Sobrienread_member_functions (struct field_info *, char **, struct type *, 12298944Sobrien struct objfile *); 12319370Spst 12419370Spststatic int 12598944Sobrienread_struct_fields (struct field_info *, char **, struct type *, 12698944Sobrien struct objfile *); 12719370Spst 12819370Spststatic int 12998944Sobrienread_baseclasses (struct field_info *, char **, struct type *, 13098944Sobrien struct objfile *); 13119370Spst 13219370Spststatic int 13398944Sobrienread_tilde_fields (struct field_info *, char **, struct type *, 13498944Sobrien struct objfile *); 13519370Spst 13698944Sobrienstatic int attach_fn_fields_to_type (struct field_info *, struct type *); 13719370Spst 138130803Smarcelstatic int attach_fields_to_type (struct field_info *, struct type *, 139130803Smarcel struct objfile *); 14019370Spst 14198944Sobrienstatic struct type *read_struct_type (char **, struct type *, 142130803Smarcel enum type_code, 14398944Sobrien struct objfile *); 14419370Spst 14598944Sobrienstatic struct type *read_array_type (char **, struct type *, 14698944Sobrien struct objfile *); 14719370Spst 148130803Smarcelstatic struct field *read_args (char **, int, struct objfile *, int *, int *); 14919370Spst 150130803Smarcelstatic void add_undefined_type (struct type *); 151130803Smarcel 15219370Spststatic int 15398944Sobrienread_cpp_abbrev (struct field_info *, char **, struct type *, 15498944Sobrien struct objfile *); 15519370Spst 156130803Smarcelstatic char *find_name_end (char *name); 15746283Sdfr 15898944Sobrienstatic int process_reference (char **string); 15946283Sdfr 16098944Sobrienvoid stabsread_clear_cache (void); 16119370Spst 162130803Smarcelstatic const char vptr_name[] = "_vptr$"; 163130803Smarcelstatic const char vb_name[] = "_vb$"; 16498944Sobrien 16519370Spst/* Define this as 1 if a pcc declaration of a char or short argument 16619370Spst gives the correct address. Otherwise assume pcc gives the 16719370Spst address of the corresponding int, which is not the same on a 16819370Spst big-endian machine. */ 16919370Spst 17098944Sobrien#if !defined (BELIEVE_PCC_PROMOTION) 17119370Spst#define BELIEVE_PCC_PROMOTION 0 17219370Spst#endif 17319370Spst 174130803Smarcelstatic void 175130803Smarcelinvalid_cpp_abbrev_complaint (const char *arg1) 176130803Smarcel{ 177130803Smarcel complaint (&symfile_complaints, "invalid C++ abbreviation `%s'", arg1); 178130803Smarcel} 17919370Spst 180130803Smarcelstatic void 181130803Smarcelreg_value_complaint (int arg1, int arg2, const char *arg3) 182130803Smarcel{ 183130803Smarcel complaint (&symfile_complaints, 184130803Smarcel "register number %d too large (max %d) in symbol %s", arg1, arg2, 185130803Smarcel arg3); 186130803Smarcel} 18719370Spst 188130803Smarcelstatic void 189130803Smarcelstabs_general_complaint (const char *arg1) 190130803Smarcel{ 191130803Smarcel complaint (&symfile_complaints, "%s", arg1); 192130803Smarcel} 19319370Spst 19419370Spst/* Make a list of forward references which haven't been defined. */ 19519370Spst 19619370Spststatic struct type **undef_types; 19719370Spststatic int undef_types_allocated; 19819370Spststatic int undef_types_length; 19919370Spststatic struct symbol *current_symbol = NULL; 20019370Spst 20119370Spst/* Check for and handle cretinous stabs symbol name continuation! */ 20219370Spst#define STABS_CONTINUE(pp,objfile) \ 20319370Spst do { \ 20419370Spst if (**(pp) == '\\' || (**(pp) == '?' && (*(pp))[1] == '\0')) \ 20519370Spst *(pp) = next_symbol_text (objfile); \ 20619370Spst } while (0) 20719370Spst 20819370Spst 20919370Spst/* Look up a dbx type-number pair. Return the address of the slot 21019370Spst where the type for that number-pair is stored. 21119370Spst The number-pair is in TYPENUMS. 21219370Spst 21319370Spst This can be used for finding the type associated with that pair 21419370Spst or for associating a new type with the pair. */ 21519370Spst 216130803Smarcelstatic struct type ** 21798944Sobriendbx_lookup_type (int typenums[2]) 21819370Spst{ 219130803Smarcel int filenum = typenums[0]; 220130803Smarcel int index = typenums[1]; 22119370Spst unsigned old_len; 222130803Smarcel int real_filenum; 223130803Smarcel struct header_file *f; 22419370Spst int f_orig_length; 22519370Spst 22619370Spst if (filenum == -1) /* -1,-1 is for temporary types. */ 22719370Spst return 0; 22819370Spst 22919370Spst if (filenum < 0 || filenum >= n_this_object_header_files) 23019370Spst { 231130803Smarcel complaint (&symfile_complaints, 232130803Smarcel "Invalid symbol data: type number (%d,%d) out of range at symtab pos %d.", 233130803Smarcel filenum, index, symnum); 23419370Spst goto error_return; 23519370Spst } 23619370Spst 23719370Spst if (filenum == 0) 23819370Spst { 23919370Spst if (index < 0) 24019370Spst { 24119370Spst /* Caller wants address of address of type. We think 24219370Spst that negative (rs6k builtin) types will never appear as 24319370Spst "lvalues", (nor should they), so we stuff the real type 24419370Spst pointer into a temp, and return its address. If referenced, 24519370Spst this will do the right thing. */ 24619370Spst static struct type *temp_type; 24719370Spst 24898944Sobrien temp_type = rs6000_builtin_type (index); 24919370Spst return &temp_type; 25019370Spst } 25119370Spst 25219370Spst /* Type is defined outside of header files. 25398944Sobrien Find it in this object file's type vector. */ 25419370Spst if (index >= type_vector_length) 25519370Spst { 25619370Spst old_len = type_vector_length; 25719370Spst if (old_len == 0) 25819370Spst { 25919370Spst type_vector_length = INITIAL_TYPE_VECTOR_LENGTH; 26019370Spst type_vector = (struct type **) 26119370Spst xmalloc (type_vector_length * sizeof (struct type *)); 26219370Spst } 26319370Spst while (index >= type_vector_length) 26419370Spst { 26519370Spst type_vector_length *= 2; 26619370Spst } 26719370Spst type_vector = (struct type **) 26819370Spst xrealloc ((char *) type_vector, 26919370Spst (type_vector_length * sizeof (struct type *))); 27019370Spst memset (&type_vector[old_len], 0, 27119370Spst (type_vector_length - old_len) * sizeof (struct type *)); 27219370Spst } 27319370Spst return (&type_vector[index]); 27419370Spst } 27519370Spst else 27619370Spst { 27719370Spst real_filenum = this_object_header_files[filenum]; 27819370Spst 27946283Sdfr if (real_filenum >= N_HEADER_FILES (current_objfile)) 28019370Spst { 28119370Spst struct type *temp_type; 28219370Spst struct type **temp_type_p; 28319370Spst 28419370Spst warning ("GDB internal error: bad real_filenum"); 28519370Spst 28619370Spst error_return: 28719370Spst temp_type = init_type (TYPE_CODE_ERROR, 0, 0, NULL, NULL); 28819370Spst temp_type_p = (struct type **) xmalloc (sizeof (struct type *)); 28919370Spst *temp_type_p = temp_type; 29019370Spst return temp_type_p; 29119370Spst } 29219370Spst 29346283Sdfr f = HEADER_FILES (current_objfile) + real_filenum; 29419370Spst 29519370Spst f_orig_length = f->length; 29619370Spst if (index >= f_orig_length) 29719370Spst { 29819370Spst while (index >= f->length) 29919370Spst { 30019370Spst f->length *= 2; 30119370Spst } 30219370Spst f->vector = (struct type **) 30319370Spst xrealloc ((char *) f->vector, f->length * sizeof (struct type *)); 30419370Spst memset (&f->vector[f_orig_length], 0, 30519370Spst (f->length - f_orig_length) * sizeof (struct type *)); 30619370Spst } 30719370Spst return (&f->vector[index]); 30819370Spst } 30919370Spst} 31019370Spst 31119370Spst/* Make sure there is a type allocated for type numbers TYPENUMS 31219370Spst and return the type object. 31319370Spst This can create an empty (zeroed) type object. 31419370Spst TYPENUMS may be (-1, -1) to return a new type object that is not 31519370Spst put into the type vector, and so may not be referred to by number. */ 31619370Spst 31719370Spststatic struct type * 31898944Sobriendbx_alloc_type (int typenums[2], struct objfile *objfile) 31919370Spst{ 320130803Smarcel struct type **type_addr; 32119370Spst 32219370Spst if (typenums[0] == -1) 32319370Spst { 32419370Spst return (alloc_type (objfile)); 32519370Spst } 32619370Spst 32719370Spst type_addr = dbx_lookup_type (typenums); 32819370Spst 32919370Spst /* If we are referring to a type not known at all yet, 33019370Spst allocate an empty type for it. 33119370Spst We will fill it in later if we find out how. */ 33219370Spst if (*type_addr == 0) 33319370Spst { 33419370Spst *type_addr = alloc_type (objfile); 33519370Spst } 33619370Spst 33719370Spst return (*type_addr); 33819370Spst} 33919370Spst 34019370Spst/* for all the stabs in a given stab vector, build appropriate types 34119370Spst and fix their symbols in given symbol vector. */ 34219370Spst 34319370Spststatic void 34498944Sobrienpatch_block_stabs (struct pending *symbols, struct pending_stabs *stabs, 34598944Sobrien struct objfile *objfile) 34619370Spst{ 34719370Spst int ii; 34819370Spst char *name; 34919370Spst char *pp; 35019370Spst struct symbol *sym; 35119370Spst 35219370Spst if (stabs) 35319370Spst { 35498944Sobrien 35519370Spst /* for all the stab entries, find their corresponding symbols and 35698944Sobrien patch their types! */ 35798944Sobrien 35819370Spst for (ii = 0; ii < stabs->count; ++ii) 35919370Spst { 36019370Spst name = stabs->stab[ii]; 36198944Sobrien pp = (char *) strchr (name, ':'); 36219370Spst while (pp[1] == ':') 36319370Spst { 36498944Sobrien pp += 2; 36598944Sobrien pp = (char *) strchr (pp, ':'); 36619370Spst } 36798944Sobrien sym = find_symbol_in_list (symbols, name, pp - name); 36819370Spst if (!sym) 36919370Spst { 37019370Spst /* FIXME-maybe: it would be nice if we noticed whether 37198944Sobrien the variable was defined *anywhere*, not just whether 37298944Sobrien it is defined in this compilation unit. But neither 37398944Sobrien xlc or GCC seem to need such a definition, and until 37498944Sobrien we do psymtabs (so that the minimal symbols from all 37598944Sobrien compilation units are available now), I'm not sure 37698944Sobrien how to get the information. */ 37719370Spst 37819370Spst /* On xcoff, if a global is defined and never referenced, 37998944Sobrien ld will remove it from the executable. There is then 38098944Sobrien a N_GSYM stab for it, but no regular (C_EXT) symbol. */ 38119370Spst sym = (struct symbol *) 382130803Smarcel obstack_alloc (&objfile->objfile_obstack, 38319370Spst sizeof (struct symbol)); 38419370Spst 38519370Spst memset (sym, 0, sizeof (struct symbol)); 386130803Smarcel SYMBOL_DOMAIN (sym) = VAR_DOMAIN; 38719370Spst SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT; 388130803Smarcel DEPRECATED_SYMBOL_NAME (sym) = 389130803Smarcel obsavestring (name, pp - name, &objfile->objfile_obstack); 39019370Spst pp += 2; 39198944Sobrien if (*(pp - 1) == 'F' || *(pp - 1) == 'f') 39219370Spst { 39319370Spst /* I don't think the linker does this with functions, 39419370Spst so as far as I know this is never executed. 39519370Spst But it doesn't hurt to check. */ 39619370Spst SYMBOL_TYPE (sym) = 39719370Spst lookup_function_type (read_type (&pp, objfile)); 39819370Spst } 39919370Spst else 40019370Spst { 40119370Spst SYMBOL_TYPE (sym) = read_type (&pp, objfile); 40219370Spst } 40319370Spst add_symbol_to_list (sym, &global_symbols); 40419370Spst } 40519370Spst else 40619370Spst { 40719370Spst pp += 2; 40898944Sobrien if (*(pp - 1) == 'F' || *(pp - 1) == 'f') 40919370Spst { 41019370Spst SYMBOL_TYPE (sym) = 41119370Spst lookup_function_type (read_type (&pp, objfile)); 41219370Spst } 41319370Spst else 41419370Spst { 41519370Spst SYMBOL_TYPE (sym) = read_type (&pp, objfile); 41619370Spst } 41719370Spst } 41819370Spst } 41919370Spst } 42019370Spst} 42198944Sobrien 42219370Spst 42319370Spst/* Read a number by which a type is referred to in dbx data, 42419370Spst or perhaps read a pair (FILENUM, TYPENUM) in parentheses. 42519370Spst Just a single number N is equivalent to (0,N). 42619370Spst Return the two numbers by storing them in the vector TYPENUMS. 42719370Spst TYPENUMS will then be used as an argument to dbx_lookup_type. 42819370Spst 42919370Spst Returns 0 for success, -1 for error. */ 43019370Spst 43119370Spststatic int 432130803Smarcelread_type_number (char **pp, int *typenums) 43319370Spst{ 43419370Spst int nbits; 43519370Spst if (**pp == '(') 43619370Spst { 43719370Spst (*pp)++; 43819370Spst typenums[0] = read_huge_number (pp, ',', &nbits); 43998944Sobrien if (nbits != 0) 44098944Sobrien return -1; 44119370Spst typenums[1] = read_huge_number (pp, ')', &nbits); 44298944Sobrien if (nbits != 0) 44398944Sobrien return -1; 44419370Spst } 44519370Spst else 44619370Spst { 44719370Spst typenums[0] = 0; 44819370Spst typenums[1] = read_huge_number (pp, 0, &nbits); 44998944Sobrien if (nbits != 0) 45098944Sobrien return -1; 45119370Spst } 45219370Spst return 0; 45319370Spst} 45419370Spst 45519370Spst 45646283Sdfr#define VISIBILITY_PRIVATE '0' /* Stabs character for private field */ 45746283Sdfr#define VISIBILITY_PROTECTED '1' /* Stabs character for protected fld */ 45846283Sdfr#define VISIBILITY_PUBLIC '2' /* Stabs character for public field */ 45946283Sdfr#define VISIBILITY_IGNORE '9' /* Optimized out or zero length */ 46046283Sdfr 46146283Sdfr/* Structure for storing pointers to reference definitions for fast lookup 46246283Sdfr during "process_later". */ 46346283Sdfr 46446283Sdfrstruct ref_map 46546283Sdfr{ 46646283Sdfr char *stabs; 46746283Sdfr CORE_ADDR value; 46846283Sdfr struct symbol *sym; 46946283Sdfr}; 47046283Sdfr 47146283Sdfr#define MAX_CHUNK_REFS 100 47246283Sdfr#define REF_CHUNK_SIZE (MAX_CHUNK_REFS * sizeof (struct ref_map)) 47346283Sdfr#define REF_MAP_SIZE(ref_chunk) ((ref_chunk) * REF_CHUNK_SIZE) 47446283Sdfr 47598944Sobrienstatic struct ref_map *ref_map; 47646283Sdfr 47746283Sdfr/* Ptr to free cell in chunk's linked list. */ 47898944Sobrienstatic int ref_count = 0; 47946283Sdfr 48046283Sdfr/* Number of chunks malloced. */ 48146283Sdfrstatic int ref_chunk = 0; 48246283Sdfr 48398944Sobrien/* This file maintains a cache of stabs aliases found in the symbol 48498944Sobrien table. If the symbol table changes, this cache must be cleared 48598944Sobrien or we are left holding onto data in invalid obstacks. */ 48698944Sobrienvoid 48798944Sobrienstabsread_clear_cache (void) 48898944Sobrien{ 48998944Sobrien ref_count = 0; 49098944Sobrien ref_chunk = 0; 49198944Sobrien} 49298944Sobrien 49346283Sdfr/* Create array of pointers mapping refids to symbols and stab strings. 49446283Sdfr Add pointers to reference definition symbols and/or their values as we 49546283Sdfr find them, using their reference numbers as our index. 49646283Sdfr These will be used later when we resolve references. */ 49746283Sdfrvoid 49898944Sobrienref_add (int refnum, struct symbol *sym, char *stabs, CORE_ADDR value) 49946283Sdfr{ 50046283Sdfr if (ref_count == 0) 50146283Sdfr ref_chunk = 0; 50246283Sdfr if (refnum >= ref_count) 50346283Sdfr ref_count = refnum + 1; 50446283Sdfr if (ref_count > ref_chunk * MAX_CHUNK_REFS) 50546283Sdfr { 50698944Sobrien int new_slots = ref_count - ref_chunk * MAX_CHUNK_REFS; 50746283Sdfr int new_chunks = new_slots / MAX_CHUNK_REFS + 1; 50846283Sdfr ref_map = (struct ref_map *) 50946283Sdfr xrealloc (ref_map, REF_MAP_SIZE (ref_chunk + new_chunks)); 51046283Sdfr memset (ref_map + ref_chunk * MAX_CHUNK_REFS, 0, new_chunks * REF_CHUNK_SIZE); 51146283Sdfr ref_chunk += new_chunks; 51246283Sdfr } 51346283Sdfr ref_map[refnum].stabs = stabs; 51446283Sdfr ref_map[refnum].sym = sym; 51546283Sdfr ref_map[refnum].value = value; 51646283Sdfr} 51746283Sdfr 51846283Sdfr/* Return defined sym for the reference REFNUM. */ 51946283Sdfrstruct symbol * 52098944Sobrienref_search (int refnum) 52146283Sdfr{ 52246283Sdfr if (refnum < 0 || refnum > ref_count) 52346283Sdfr return 0; 52446283Sdfr return ref_map[refnum].sym; 52546283Sdfr} 52646283Sdfr 52746283Sdfr/* Parse a reference id in STRING and return the resulting 52846283Sdfr reference number. Move STRING beyond the reference id. */ 52946283Sdfr 53098944Sobrienstatic int 53198944Sobrienprocess_reference (char **string) 53246283Sdfr{ 53346283Sdfr char *p; 53446283Sdfr int refnum = 0; 53546283Sdfr 53698944Sobrien if (**string != '#') 53798944Sobrien return 0; 53898944Sobrien 53946283Sdfr /* Advance beyond the initial '#'. */ 54046283Sdfr p = *string + 1; 54146283Sdfr 54246283Sdfr /* Read number as reference id. */ 54346283Sdfr while (*p && isdigit (*p)) 54446283Sdfr { 54546283Sdfr refnum = refnum * 10 + *p - '0'; 54646283Sdfr p++; 54746283Sdfr } 54846283Sdfr *string = p; 54946283Sdfr return refnum; 55046283Sdfr} 55146283Sdfr 55246283Sdfr/* If STRING defines a reference, store away a pointer to the reference 55346283Sdfr definition for later use. Return the reference number. */ 55446283Sdfr 55546283Sdfrint 55698944Sobriensymbol_reference_defined (char **string) 55746283Sdfr{ 55846283Sdfr char *p = *string; 55946283Sdfr int refnum = 0; 56046283Sdfr 56146283Sdfr refnum = process_reference (&p); 56246283Sdfr 56346283Sdfr /* Defining symbols end in '=' */ 56498944Sobrien if (*p == '=') 56546283Sdfr { 56698944Sobrien /* Symbol is being defined here. */ 56746283Sdfr *string = p + 1; 56846283Sdfr return refnum; 56946283Sdfr } 57046283Sdfr else 57146283Sdfr { 57246283Sdfr /* Must be a reference. Either the symbol has already been defined, 57346283Sdfr or this is a forward reference to it. */ 57446283Sdfr *string = p; 57546283Sdfr return -1; 57646283Sdfr } 57746283Sdfr} 57846283Sdfr 57919370Spststruct symbol * 58098944Sobriendefine_symbol (CORE_ADDR valu, char *string, int desc, int type, 58198944Sobrien struct objfile *objfile) 58219370Spst{ 583130803Smarcel struct symbol *sym; 584130803Smarcel char *p = (char *) find_name_end (string); 58519370Spst int deftype; 58619370Spst int synonym = 0; 587130803Smarcel int i; 58819370Spst 58919370Spst /* We would like to eliminate nameless symbols, but keep their types. 59019370Spst E.g. stab entry ":t10=*2" should produce a type 10, which is a pointer 59119370Spst to type 2, but, should not create a symbol to address that type. Since 59219370Spst the symbol will be nameless, there is no way any user can refer to it. */ 59319370Spst 59419370Spst int nameless; 59519370Spst 59619370Spst /* Ignore syms with empty names. */ 59719370Spst if (string[0] == 0) 59819370Spst return 0; 59919370Spst 60019370Spst /* Ignore old-style symbols from cc -go */ 60119370Spst if (p == 0) 60219370Spst return 0; 60319370Spst 60419370Spst while (p[1] == ':') 60519370Spst { 60698944Sobrien p += 2; 60798944Sobrien p = strchr (p, ':'); 60819370Spst } 60919370Spst 61019370Spst /* If a nameless stab entry, all we need is the type, not the symbol. 61119370Spst e.g. ":t10=*2" or a nameless enum like " :T16=ered:0,green:1,blue:2,;" */ 61219370Spst nameless = (p == string || ((string[0] == ' ') && (string[1] == ':'))); 61319370Spst 61498944Sobrien current_symbol = sym = (struct symbol *) 615130803Smarcel obstack_alloc (&objfile->objfile_obstack, sizeof (struct symbol)); 61619370Spst memset (sym, 0, sizeof (struct symbol)); 61719370Spst 61819370Spst switch (type & N_TYPE) 61919370Spst { 62019370Spst case N_TEXT: 62198944Sobrien SYMBOL_SECTION (sym) = SECT_OFF_TEXT (objfile); 62219370Spst break; 62319370Spst case N_DATA: 62498944Sobrien SYMBOL_SECTION (sym) = SECT_OFF_DATA (objfile); 62519370Spst break; 62619370Spst case N_BSS: 62798944Sobrien SYMBOL_SECTION (sym) = SECT_OFF_BSS (objfile); 62819370Spst break; 62919370Spst } 63019370Spst 63119370Spst if (processing_gcc_compilation) 63219370Spst { 63319370Spst /* GCC 2.x puts the line number in desc. SunOS apparently puts in the 63498944Sobrien number of bytes occupied by a type or object, which we ignore. */ 63598944Sobrien SYMBOL_LINE (sym) = desc; 63619370Spst } 63719370Spst else 63819370Spst { 63998944Sobrien SYMBOL_LINE (sym) = 0; /* unknown */ 64019370Spst } 64119370Spst 64219370Spst if (is_cplus_marker (string[0])) 64319370Spst { 64419370Spst /* Special GNU C++ names. */ 64519370Spst switch (string[1]) 64619370Spst { 64798944Sobrien case 't': 648130803Smarcel DEPRECATED_SYMBOL_NAME (sym) = obsavestring ("this", strlen ("this"), 649130803Smarcel &objfile->objfile_obstack); 65098944Sobrien break; 65119370Spst 65298944Sobrien case 'v': /* $vtbl_ptr_type */ 653130803Smarcel /* Was: DEPRECATED_SYMBOL_NAME (sym) = "vptr"; */ 65498944Sobrien goto normal; 65519370Spst 65698944Sobrien case 'e': 657130803Smarcel DEPRECATED_SYMBOL_NAME (sym) = obsavestring ("eh_throw", strlen ("eh_throw"), 658130803Smarcel &objfile->objfile_obstack); 65998944Sobrien break; 66019370Spst 66198944Sobrien case '_': 66298944Sobrien /* This was an anonymous type that was never fixed up. */ 66398944Sobrien goto normal; 66419370Spst 66519370Spst#ifdef STATIC_TRANSFORM_NAME 66698944Sobrien case 'X': 66798944Sobrien /* SunPRO (3.0 at least) static variable encoding. */ 66898944Sobrien goto normal; 66919370Spst#endif 67019370Spst 67198944Sobrien default: 672130803Smarcel complaint (&symfile_complaints, "Unknown C++ symbol name `%s'", 673130803Smarcel string); 67498944Sobrien goto normal; /* Do *something* with it */ 67519370Spst } 67619370Spst } 67719370Spst else 67819370Spst { 67919370Spst normal: 68098944Sobrien SYMBOL_LANGUAGE (sym) = current_subfile->language; 681130803Smarcel SYMBOL_SET_NAMES (sym, string, p - string, objfile); 68219370Spst } 68319370Spst p++; 68419370Spst 68519370Spst /* Determine the type of name being defined. */ 68619370Spst#if 0 68719370Spst /* Getting GDB to correctly skip the symbol on an undefined symbol 68819370Spst descriptor and not ever dump core is a very dodgy proposition if 68919370Spst we do things this way. I say the acorn RISC machine can just 69019370Spst fix their compiler. */ 69119370Spst /* The Acorn RISC machine's compiler can put out locals that don't 69219370Spst start with "234=" or "(3,4)=", so assume anything other than the 69319370Spst deftypes we know how to handle is a local. */ 69419370Spst if (!strchr ("cfFGpPrStTvVXCR", *p)) 69519370Spst#else 69619370Spst if (isdigit (*p) || *p == '(' || *p == '-') 69719370Spst#endif 69819370Spst deftype = 'l'; 69919370Spst else 70019370Spst deftype = *p++; 70119370Spst 70219370Spst switch (deftype) 70319370Spst { 70419370Spst case 'c': 70519370Spst /* c is a special case, not followed by a type-number. 70698944Sobrien SYMBOL:c=iVALUE for an integer constant symbol. 70798944Sobrien SYMBOL:c=rVALUE for a floating constant symbol. 70898944Sobrien SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol. 70998944Sobrien e.g. "b:c=e6,0" for "const b = blob1" 71098944Sobrien (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */ 71119370Spst if (*p != '=') 71219370Spst { 71319370Spst SYMBOL_CLASS (sym) = LOC_CONST; 71419370Spst SYMBOL_TYPE (sym) = error_type (&p, objfile); 715130803Smarcel SYMBOL_DOMAIN (sym) = VAR_DOMAIN; 71619370Spst add_symbol_to_list (sym, &file_symbols); 71719370Spst return sym; 71819370Spst } 71919370Spst ++p; 72019370Spst switch (*p++) 72119370Spst { 72219370Spst case 'r': 72319370Spst { 72419370Spst double d = atof (p); 72519370Spst char *dbl_valu; 72619370Spst 72719370Spst /* FIXME-if-picky-about-floating-accuracy: Should be using 72819370Spst target arithmetic to get the value. real.c in GCC 72919370Spst probably has the necessary code. */ 73019370Spst 73119370Spst /* FIXME: lookup_fundamental_type is a hack. We should be 73219370Spst creating a type especially for the type of float constants. 73319370Spst Problem is, what type should it be? 73419370Spst 73519370Spst Also, what should the name of this type be? Should we 73619370Spst be using 'S' constants (see stabs.texinfo) instead? */ 73719370Spst 73819370Spst SYMBOL_TYPE (sym) = lookup_fundamental_type (objfile, 73919370Spst FT_DBL_PREC_FLOAT); 74019370Spst dbl_valu = (char *) 741130803Smarcel obstack_alloc (&objfile->objfile_obstack, 74219370Spst TYPE_LENGTH (SYMBOL_TYPE (sym))); 74398944Sobrien store_typed_floating (dbl_valu, SYMBOL_TYPE (sym), d); 74419370Spst SYMBOL_VALUE_BYTES (sym) = dbl_valu; 74519370Spst SYMBOL_CLASS (sym) = LOC_CONST_BYTES; 74619370Spst } 74719370Spst break; 74819370Spst case 'i': 74919370Spst { 75019370Spst /* Defining integer constants this way is kind of silly, 75119370Spst since 'e' constants allows the compiler to give not 75219370Spst only the value, but the type as well. C has at least 75319370Spst int, long, unsigned int, and long long as constant 75419370Spst types; other languages probably should have at least 75519370Spst unsigned as well as signed constants. */ 75619370Spst 75719370Spst /* We just need one int constant type for all objfiles. 75819370Spst It doesn't depend on languages or anything (arguably its 75919370Spst name should be a language-specific name for a type of 76019370Spst that size, but I'm inclined to say that if the compiler 76119370Spst wants a nice name for the type, it can use 'e'). */ 76219370Spst static struct type *int_const_type; 76319370Spst 76419370Spst /* Yes, this is as long as a *host* int. That is because we 76519370Spst use atoi. */ 76619370Spst if (int_const_type == NULL) 76719370Spst int_const_type = 76819370Spst init_type (TYPE_CODE_INT, 76919370Spst sizeof (int) * HOST_CHAR_BIT / TARGET_CHAR_BIT, 0, 77019370Spst "integer constant", 77198944Sobrien (struct objfile *) NULL); 77219370Spst SYMBOL_TYPE (sym) = int_const_type; 77319370Spst SYMBOL_VALUE (sym) = atoi (p); 77419370Spst SYMBOL_CLASS (sym) = LOC_CONST; 77519370Spst } 77619370Spst break; 77719370Spst case 'e': 77819370Spst /* SYMBOL:c=eTYPE,INTVALUE for a constant symbol whose value 77919370Spst can be represented as integral. 78019370Spst e.g. "b:c=e6,0" for "const b = blob1" 78119370Spst (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */ 78219370Spst { 78319370Spst SYMBOL_CLASS (sym) = LOC_CONST; 78419370Spst SYMBOL_TYPE (sym) = read_type (&p, objfile); 78519370Spst 78619370Spst if (*p != ',') 78719370Spst { 78819370Spst SYMBOL_TYPE (sym) = error_type (&p, objfile); 78919370Spst break; 79019370Spst } 79119370Spst ++p; 79219370Spst 79319370Spst /* If the value is too big to fit in an int (perhaps because 79419370Spst it is unsigned), or something like that, we silently get 79519370Spst a bogus value. The type and everything else about it is 79619370Spst correct. Ideally, we should be using whatever we have 79719370Spst available for parsing unsigned and long long values, 79819370Spst however. */ 79919370Spst SYMBOL_VALUE (sym) = atoi (p); 80019370Spst } 80119370Spst break; 80219370Spst default: 80319370Spst { 80419370Spst SYMBOL_CLASS (sym) = LOC_CONST; 80519370Spst SYMBOL_TYPE (sym) = error_type (&p, objfile); 80619370Spst } 80719370Spst } 808130803Smarcel SYMBOL_DOMAIN (sym) = VAR_DOMAIN; 80919370Spst add_symbol_to_list (sym, &file_symbols); 81019370Spst return sym; 81119370Spst 81219370Spst case 'C': 81319370Spst /* The name of a caught exception. */ 81419370Spst SYMBOL_TYPE (sym) = read_type (&p, objfile); 81519370Spst SYMBOL_CLASS (sym) = LOC_LABEL; 816130803Smarcel SYMBOL_DOMAIN (sym) = VAR_DOMAIN; 81719370Spst SYMBOL_VALUE_ADDRESS (sym) = valu; 81819370Spst add_symbol_to_list (sym, &local_symbols); 81919370Spst break; 82019370Spst 82119370Spst case 'f': 82219370Spst /* A static function definition. */ 82319370Spst SYMBOL_TYPE (sym) = read_type (&p, objfile); 82419370Spst SYMBOL_CLASS (sym) = LOC_BLOCK; 825130803Smarcel SYMBOL_DOMAIN (sym) = VAR_DOMAIN; 82619370Spst add_symbol_to_list (sym, &file_symbols); 82719370Spst /* fall into process_function_types. */ 82819370Spst 82919370Spst process_function_types: 83019370Spst /* Function result types are described as the result type in stabs. 83198944Sobrien We need to convert this to the function-returning-type-X type 83298944Sobrien in GDB. E.g. "int" is converted to "function returning int". */ 83319370Spst if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_FUNC) 83419370Spst SYMBOL_TYPE (sym) = lookup_function_type (SYMBOL_TYPE (sym)); 83546283Sdfr 836130803Smarcel /* All functions in C++ have prototypes. Stabs does not offer an 837130803Smarcel explicit way to identify prototyped or unprototyped functions, 838130803Smarcel but both GCC and Sun CC emit stabs for the "call-as" type rather 839130803Smarcel than the "declared-as" type for unprototyped functions, so 840130803Smarcel we treat all functions as if they were prototyped. This is used 841130803Smarcel primarily for promotion when calling the function from GDB. */ 842130803Smarcel TYPE_FLAGS (SYMBOL_TYPE (sym)) |= TYPE_FLAG_PROTOTYPED; 84346283Sdfr 84419370Spst /* fall into process_prototype_types */ 84519370Spst 84619370Spst process_prototype_types: 84746283Sdfr /* Sun acc puts declared types of arguments here. */ 84846283Sdfr if (*p == ';') 84946283Sdfr { 85046283Sdfr struct type *ftype = SYMBOL_TYPE (sym); 85146283Sdfr int nsemi = 0; 85246283Sdfr int nparams = 0; 85346283Sdfr char *p1 = p; 85446283Sdfr 85546283Sdfr /* Obtain a worst case guess for the number of arguments 85646283Sdfr by counting the semicolons. */ 85746283Sdfr while (*p1) 85846283Sdfr { 85946283Sdfr if (*p1++ == ';') 86046283Sdfr nsemi++; 86146283Sdfr } 86246283Sdfr 86346283Sdfr /* Allocate parameter information fields and fill them in. */ 86446283Sdfr TYPE_FIELDS (ftype) = (struct field *) 86546283Sdfr TYPE_ALLOC (ftype, nsemi * sizeof (struct field)); 86646283Sdfr while (*p++ == ';') 86746283Sdfr { 86846283Sdfr struct type *ptype; 86946283Sdfr 87046283Sdfr /* A type number of zero indicates the start of varargs. 87198944Sobrien FIXME: GDB currently ignores vararg functions. */ 87246283Sdfr if (p[0] == '0' && p[1] == '\0') 87346283Sdfr break; 87446283Sdfr ptype = read_type (&p, objfile); 87546283Sdfr 87646283Sdfr /* The Sun compilers mark integer arguments, which should 87798944Sobrien be promoted to the width of the calling conventions, with 87898944Sobrien a type which references itself. This type is turned into 87998944Sobrien a TYPE_CODE_VOID type by read_type, and we have to turn 88098944Sobrien it back into builtin_type_int here. 88198944Sobrien FIXME: Do we need a new builtin_type_promoted_int_arg ? */ 88246283Sdfr if (TYPE_CODE (ptype) == TYPE_CODE_VOID) 88346283Sdfr ptype = builtin_type_int; 88498944Sobrien TYPE_FIELD_TYPE (ftype, nparams) = ptype; 88598944Sobrien TYPE_FIELD_ARTIFICIAL (ftype, nparams++) = 0; 88646283Sdfr } 88746283Sdfr TYPE_NFIELDS (ftype) = nparams; 88846283Sdfr TYPE_FLAGS (ftype) |= TYPE_FLAG_PROTOTYPED; 88946283Sdfr } 89019370Spst break; 89119370Spst 89219370Spst case 'F': 89319370Spst /* A global function definition. */ 89419370Spst SYMBOL_TYPE (sym) = read_type (&p, objfile); 89519370Spst SYMBOL_CLASS (sym) = LOC_BLOCK; 896130803Smarcel SYMBOL_DOMAIN (sym) = VAR_DOMAIN; 89719370Spst add_symbol_to_list (sym, &global_symbols); 89819370Spst goto process_function_types; 89919370Spst 90019370Spst case 'G': 90119370Spst /* For a class G (global) symbol, it appears that the 90298944Sobrien value is not correct. It is necessary to search for the 90398944Sobrien corresponding linker definition to find the value. 90498944Sobrien These definitions appear at the end of the namelist. */ 90519370Spst SYMBOL_TYPE (sym) = read_type (&p, objfile); 90619370Spst SYMBOL_CLASS (sym) = LOC_STATIC; 907130803Smarcel SYMBOL_DOMAIN (sym) = VAR_DOMAIN; 90846283Sdfr /* Don't add symbol references to global_sym_chain. 90998944Sobrien Symbol references don't have valid names and wont't match up with 91098944Sobrien minimal symbols when the global_sym_chain is relocated. 91198944Sobrien We'll fixup symbol references when we fixup the defining symbol. */ 912130803Smarcel if (DEPRECATED_SYMBOL_NAME (sym) && DEPRECATED_SYMBOL_NAME (sym)[0] != '#') 91346283Sdfr { 914130803Smarcel i = hashname (DEPRECATED_SYMBOL_NAME (sym)); 91598944Sobrien SYMBOL_VALUE_CHAIN (sym) = global_sym_chain[i]; 91698944Sobrien global_sym_chain[i] = sym; 91746283Sdfr } 91819370Spst add_symbol_to_list (sym, &global_symbols); 91919370Spst break; 92019370Spst 92119370Spst /* This case is faked by a conditional above, 92298944Sobrien when there is no code letter in the dbx data. 92398944Sobrien Dbx data never actually contains 'l'. */ 92419370Spst case 's': 92519370Spst case 'l': 92619370Spst SYMBOL_TYPE (sym) = read_type (&p, objfile); 92719370Spst SYMBOL_CLASS (sym) = LOC_LOCAL; 92819370Spst SYMBOL_VALUE (sym) = valu; 929130803Smarcel SYMBOL_DOMAIN (sym) = VAR_DOMAIN; 93019370Spst add_symbol_to_list (sym, &local_symbols); 93119370Spst break; 93219370Spst 93319370Spst case 'p': 93419370Spst if (*p == 'F') 93519370Spst /* pF is a two-letter code that means a function parameter in Fortran. 93619370Spst The type-number specifies the type of the return value. 93719370Spst Translate it into a pointer-to-function type. */ 93819370Spst { 93919370Spst p++; 94019370Spst SYMBOL_TYPE (sym) 94119370Spst = lookup_pointer_type 94298944Sobrien (lookup_function_type (read_type (&p, objfile))); 94319370Spst } 94419370Spst else 94519370Spst SYMBOL_TYPE (sym) = read_type (&p, objfile); 94619370Spst 947130803Smarcel SYMBOL_CLASS (sym) = LOC_ARG; 94819370Spst SYMBOL_VALUE (sym) = valu; 949130803Smarcel SYMBOL_DOMAIN (sym) = VAR_DOMAIN; 95019370Spst add_symbol_to_list (sym, &local_symbols); 95119370Spst 95298944Sobrien if (TARGET_BYTE_ORDER != BFD_ENDIAN_BIG) 95319370Spst { 95419370Spst /* On little-endian machines, this crud is never necessary, 95519370Spst and, if the extra bytes contain garbage, is harmful. */ 95619370Spst break; 95719370Spst } 95819370Spst 95919370Spst /* If it's gcc-compiled, if it says `short', believe it. */ 96019370Spst if (processing_gcc_compilation || BELIEVE_PCC_PROMOTION) 96119370Spst break; 96219370Spst 96398944Sobrien if (!BELIEVE_PCC_PROMOTION) 96498944Sobrien { 96598944Sobrien /* This is the signed type which arguments get promoted to. */ 96698944Sobrien static struct type *pcc_promotion_type; 96798944Sobrien /* This is the unsigned type which arguments get promoted to. */ 96898944Sobrien static struct type *pcc_unsigned_promotion_type; 96919370Spst 97098944Sobrien /* Call it "int" because this is mainly C lossage. */ 97198944Sobrien if (pcc_promotion_type == NULL) 97298944Sobrien pcc_promotion_type = 97398944Sobrien init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT, 97498944Sobrien 0, "int", NULL); 97519370Spst 97698944Sobrien if (pcc_unsigned_promotion_type == NULL) 97798944Sobrien pcc_unsigned_promotion_type = 97898944Sobrien init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT, 97998944Sobrien TYPE_FLAG_UNSIGNED, "unsigned int", NULL); 98019370Spst 98198944Sobrien if (BELIEVE_PCC_PROMOTION_TYPE) 98298944Sobrien { 98398944Sobrien /* This is defined on machines (e.g. sparc) where we 98498944Sobrien should believe the type of a PCC 'short' argument, 98598944Sobrien but shouldn't believe the address (the address is the 98698944Sobrien address of the corresponding int). 98719370Spst 98898944Sobrien My guess is that this correction, as opposed to 98998944Sobrien changing the parameter to an 'int' (as done below, 99098944Sobrien for PCC on most machines), is the right thing to do 99198944Sobrien on all machines, but I don't want to risk breaking 99298944Sobrien something that already works. On most PCC machines, 99398944Sobrien the sparc problem doesn't come up because the calling 99498944Sobrien function has to zero the top bytes (not knowing 99598944Sobrien whether the called function wants an int or a short), 99698944Sobrien so there is little practical difference between an 99798944Sobrien int and a short (except perhaps what happens when the 99898944Sobrien GDB user types "print short_arg = 0x10000;"). 99919370Spst 100098944Sobrien Hacked for SunOS 4.1 by gnu@cygnus.com. In 4.1, the 100198944Sobrien compiler actually produces the correct address (we 100298944Sobrien don't need to fix it up). I made this code adapt so 100398944Sobrien that it will offset the symbol if it was pointing at 100498944Sobrien an int-aligned location and not otherwise. This way 100598944Sobrien you can use the same gdb for 4.0.x and 4.1 systems. 100619370Spst 100798944Sobrien If the parameter is shorter than an int, and is 100898944Sobrien integral (e.g. char, short, or unsigned equivalent), 100998944Sobrien and is claimed to be passed on an integer boundary, 101098944Sobrien don't believe it! Offset the parameter's address to 101198944Sobrien the tail-end of that integer. */ 101298944Sobrien 101398944Sobrien if (TYPE_LENGTH (SYMBOL_TYPE (sym)) < TYPE_LENGTH (pcc_promotion_type) 101498944Sobrien && TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_INT 101598944Sobrien && 0 == SYMBOL_VALUE (sym) % TYPE_LENGTH (pcc_promotion_type)) 101698944Sobrien { 101798944Sobrien SYMBOL_VALUE (sym) += TYPE_LENGTH (pcc_promotion_type) 101898944Sobrien - TYPE_LENGTH (SYMBOL_TYPE (sym)); 101998944Sobrien } 102098944Sobrien break; 102198944Sobrien } 102298944Sobrien else 102398944Sobrien { 102498944Sobrien /* If PCC says a parameter is a short or a char, 102598944Sobrien it is really an int. */ 102698944Sobrien if (TYPE_LENGTH (SYMBOL_TYPE (sym)) < TYPE_LENGTH (pcc_promotion_type) 102798944Sobrien && TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_INT) 102898944Sobrien { 102998944Sobrien SYMBOL_TYPE (sym) = 103098944Sobrien TYPE_UNSIGNED (SYMBOL_TYPE (sym)) 103198944Sobrien ? pcc_unsigned_promotion_type 103298944Sobrien : pcc_promotion_type; 103398944Sobrien } 103498944Sobrien break; 103598944Sobrien } 103698944Sobrien } 103798944Sobrien 103819370Spst case 'P': 103919370Spst /* acc seems to use P to declare the prototypes of functions that 104019370Spst are referenced by this file. gdb is not prepared to deal 104119370Spst with this extra information. FIXME, it ought to. */ 104219370Spst if (type == N_FUN) 104319370Spst { 104419370Spst SYMBOL_TYPE (sym) = read_type (&p, objfile); 104519370Spst goto process_prototype_types; 104619370Spst } 104798944Sobrien /*FALLTHROUGH */ 104819370Spst 104919370Spst case 'R': 105019370Spst /* Parameter which is in a register. */ 105119370Spst SYMBOL_TYPE (sym) = read_type (&p, objfile); 105219370Spst SYMBOL_CLASS (sym) = LOC_REGPARM; 105319370Spst SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu); 105498944Sobrien if (SYMBOL_VALUE (sym) >= NUM_REGS + NUM_PSEUDO_REGS) 105519370Spst { 1056130803Smarcel reg_value_complaint (SYMBOL_VALUE (sym), 1057130803Smarcel NUM_REGS + NUM_PSEUDO_REGS, 1058130803Smarcel SYMBOL_PRINT_NAME (sym)); 105998944Sobrien SYMBOL_VALUE (sym) = SP_REGNUM; /* Known safe, though useless */ 106019370Spst } 1061130803Smarcel SYMBOL_DOMAIN (sym) = VAR_DOMAIN; 106219370Spst add_symbol_to_list (sym, &local_symbols); 106319370Spst break; 106419370Spst 106519370Spst case 'r': 106619370Spst /* Register variable (either global or local). */ 106719370Spst SYMBOL_TYPE (sym) = read_type (&p, objfile); 106819370Spst SYMBOL_CLASS (sym) = LOC_REGISTER; 106919370Spst SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu); 107098944Sobrien if (SYMBOL_VALUE (sym) >= NUM_REGS + NUM_PSEUDO_REGS) 107119370Spst { 1072130803Smarcel reg_value_complaint (SYMBOL_VALUE (sym), 1073130803Smarcel NUM_REGS + NUM_PSEUDO_REGS, 1074130803Smarcel SYMBOL_PRINT_NAME (sym)); 107598944Sobrien SYMBOL_VALUE (sym) = SP_REGNUM; /* Known safe, though useless */ 107619370Spst } 1077130803Smarcel SYMBOL_DOMAIN (sym) = VAR_DOMAIN; 107819370Spst if (within_function) 107919370Spst { 1080130803Smarcel /* Sun cc uses a pair of symbols, one 'p' and one 'r', with 1081130803Smarcel the same name to represent an argument passed in a 1082130803Smarcel register. GCC uses 'P' for the same case. So if we find 1083130803Smarcel such a symbol pair we combine it into one 'P' symbol. 1084130803Smarcel For Sun cc we need to do this regardless of 1085130803Smarcel stabs_argument_has_addr, because the compiler puts out 1086130803Smarcel the 'p' symbol even if it never saves the argument onto 1087130803Smarcel the stack. 108819370Spst 1089130803Smarcel On most machines, we want to preserve both symbols, so 1090130803Smarcel that we can still get information about what is going on 1091130803Smarcel with the stack (VAX for computing args_printed, using 1092130803Smarcel stack slots instead of saved registers in backtraces, 1093130803Smarcel etc.). 109419370Spst 109519370Spst Note that this code illegally combines 109698944Sobrien main(argc) struct foo argc; { register struct foo argc; } 109719370Spst but this case is considered pathological and causes a warning 109819370Spst from a decent compiler. */ 109919370Spst 110019370Spst if (local_symbols 110119370Spst && local_symbols->nsyms > 0 1102130803Smarcel && gdbarch_stabs_argument_has_addr (current_gdbarch, 1103130803Smarcel SYMBOL_TYPE (sym))) 110419370Spst { 110519370Spst struct symbol *prev_sym; 110619370Spst prev_sym = local_symbols->symbol[local_symbols->nsyms - 1]; 110719370Spst if ((SYMBOL_CLASS (prev_sym) == LOC_REF_ARG 110819370Spst || SYMBOL_CLASS (prev_sym) == LOC_ARG) 1109130803Smarcel && strcmp (DEPRECATED_SYMBOL_NAME (prev_sym), 1110130803Smarcel DEPRECATED_SYMBOL_NAME (sym)) == 0) 111119370Spst { 111219370Spst SYMBOL_CLASS (prev_sym) = LOC_REGPARM; 111319370Spst /* Use the type from the LOC_REGISTER; that is the type 111419370Spst that is actually in that register. */ 111519370Spst SYMBOL_TYPE (prev_sym) = SYMBOL_TYPE (sym); 111619370Spst SYMBOL_VALUE (prev_sym) = SYMBOL_VALUE (sym); 111719370Spst sym = prev_sym; 111819370Spst break; 111919370Spst } 112019370Spst } 112198944Sobrien add_symbol_to_list (sym, &local_symbols); 112219370Spst } 112319370Spst else 112498944Sobrien add_symbol_to_list (sym, &file_symbols); 112519370Spst break; 112619370Spst 112719370Spst case 'S': 112819370Spst /* Static symbol at top level of file */ 112919370Spst SYMBOL_TYPE (sym) = read_type (&p, objfile); 113019370Spst SYMBOL_CLASS (sym) = LOC_STATIC; 113119370Spst SYMBOL_VALUE_ADDRESS (sym) = valu; 113219370Spst#ifdef STATIC_TRANSFORM_NAME 1133130803Smarcel if (IS_STATIC_TRANSFORM_NAME (DEPRECATED_SYMBOL_NAME (sym))) 113498944Sobrien { 113598944Sobrien struct minimal_symbol *msym; 1136130803Smarcel msym = lookup_minimal_symbol (DEPRECATED_SYMBOL_NAME (sym), NULL, objfile); 113798944Sobrien if (msym != NULL) 113898944Sobrien { 1139130803Smarcel DEPRECATED_SYMBOL_NAME (sym) = STATIC_TRANSFORM_NAME (DEPRECATED_SYMBOL_NAME (sym)); 114098944Sobrien SYMBOL_VALUE_ADDRESS (sym) = SYMBOL_VALUE_ADDRESS (msym); 114198944Sobrien } 114298944Sobrien } 114319370Spst#endif 1144130803Smarcel SYMBOL_DOMAIN (sym) = VAR_DOMAIN; 114519370Spst add_symbol_to_list (sym, &file_symbols); 114619370Spst break; 114719370Spst 114819370Spst case 't': 1149130803Smarcel /* Typedef */ 115019370Spst SYMBOL_TYPE (sym) = read_type (&p, objfile); 115119370Spst 115219370Spst /* For a nameless type, we don't want a create a symbol, thus we 115398944Sobrien did not use `sym'. Return without further processing. */ 115498944Sobrien if (nameless) 115598944Sobrien return NULL; 115619370Spst 115719370Spst SYMBOL_CLASS (sym) = LOC_TYPEDEF; 115819370Spst SYMBOL_VALUE (sym) = valu; 1159130803Smarcel SYMBOL_DOMAIN (sym) = VAR_DOMAIN; 116019370Spst /* C++ vagaries: we may have a type which is derived from 116198944Sobrien a base type which did not have its name defined when the 116298944Sobrien derived class was output. We fill in the derived class's 116398944Sobrien base part member's name here in that case. */ 116419370Spst if (TYPE_NAME (SYMBOL_TYPE (sym)) != NULL) 116519370Spst if ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT 116619370Spst || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION) 116719370Spst && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym))) 116819370Spst { 116919370Spst int j; 117019370Spst for (j = TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)) - 1; j >= 0; j--) 117119370Spst if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) == 0) 117219370Spst TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) = 117319370Spst type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym), j)); 117419370Spst } 117519370Spst 117619370Spst if (TYPE_NAME (SYMBOL_TYPE (sym)) == NULL) 117719370Spst { 117819370Spst /* gcc-2.6 or later (when using -fvtable-thunks) 117919370Spst emits a unique named type for a vtable entry. 118019370Spst Some gdb code depends on that specific name. */ 118119370Spst extern const char vtbl_ptr_name[]; 118219370Spst 118319370Spst if ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_PTR 1184130803Smarcel && strcmp (DEPRECATED_SYMBOL_NAME (sym), vtbl_ptr_name)) 118519370Spst || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_FUNC) 118619370Spst { 118719370Spst /* If we are giving a name to a type such as "pointer to 118898944Sobrien foo" or "function returning foo", we better not set 118998944Sobrien the TYPE_NAME. If the program contains "typedef char 119098944Sobrien *caddr_t;", we don't want all variables of type char 119198944Sobrien * to print as caddr_t. This is not just a 119298944Sobrien consequence of GDB's type management; PCC and GCC (at 119398944Sobrien least through version 2.4) both output variables of 119498944Sobrien either type char * or caddr_t with the type number 119598944Sobrien defined in the 't' symbol for caddr_t. If a future 119698944Sobrien compiler cleans this up it GDB is not ready for it 119798944Sobrien yet, but if it becomes ready we somehow need to 119898944Sobrien disable this check (without breaking the PCC/GCC2.4 119998944Sobrien case). 120019370Spst 120198944Sobrien Sigh. 120219370Spst 120398944Sobrien Fortunately, this check seems not to be necessary 120498944Sobrien for anything except pointers or functions. */ 120598944Sobrien /* ezannoni: 2000-10-26. This seems to apply for 120698944Sobrien versions of gcc older than 2.8. This was the original 120798944Sobrien problem: with the following code gdb would tell that 120898944Sobrien the type for name1 is caddr_t, and func is char() 120998944Sobrien typedef char *caddr_t; 121098944Sobrien char *name2; 121198944Sobrien struct x 121298944Sobrien { 121398944Sobrien char *name1; 121498944Sobrien } xx; 121598944Sobrien char *func() 121698944Sobrien { 121798944Sobrien } 121898944Sobrien main () {} 121998944Sobrien */ 122098944Sobrien 122198944Sobrien /* Pascal accepts names for pointer types. */ 122298944Sobrien if (current_subfile->language == language_pascal) 122398944Sobrien { 1224130803Smarcel TYPE_NAME (SYMBOL_TYPE (sym)) = DEPRECATED_SYMBOL_NAME (sym); 122598944Sobrien } 122619370Spst } 122719370Spst else 1228130803Smarcel TYPE_NAME (SYMBOL_TYPE (sym)) = DEPRECATED_SYMBOL_NAME (sym); 122919370Spst } 123019370Spst 123119370Spst add_symbol_to_list (sym, &file_symbols); 123219370Spst break; 123319370Spst 123419370Spst case 'T': 123519370Spst /* Struct, union, or enum tag. For GNU C++, this can be be followed 123698944Sobrien by 't' which means we are typedef'ing it as well. */ 123719370Spst synonym = *p == 't'; 123819370Spst 123919370Spst if (synonym) 124019370Spst p++; 124119370Spst 124219370Spst SYMBOL_TYPE (sym) = read_type (&p, objfile); 1243130803Smarcel 124419370Spst /* For a nameless type, we don't want a create a symbol, thus we 124598944Sobrien did not use `sym'. Return without further processing. */ 124698944Sobrien if (nameless) 124798944Sobrien return NULL; 124819370Spst 124919370Spst SYMBOL_CLASS (sym) = LOC_TYPEDEF; 125019370Spst SYMBOL_VALUE (sym) = valu; 1251130803Smarcel SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN; 125219370Spst if (TYPE_TAG_NAME (SYMBOL_TYPE (sym)) == 0) 125319370Spst TYPE_TAG_NAME (SYMBOL_TYPE (sym)) 1254130803Smarcel = obconcat (&objfile->objfile_obstack, "", "", DEPRECATED_SYMBOL_NAME (sym)); 125519370Spst add_symbol_to_list (sym, &file_symbols); 125619370Spst 125719370Spst if (synonym) 125819370Spst { 125919370Spst /* Clone the sym and then modify it. */ 1260130803Smarcel struct symbol *typedef_sym = (struct symbol *) 1261130803Smarcel obstack_alloc (&objfile->objfile_obstack, sizeof (struct symbol)); 126219370Spst *typedef_sym = *sym; 126319370Spst SYMBOL_CLASS (typedef_sym) = LOC_TYPEDEF; 126419370Spst SYMBOL_VALUE (typedef_sym) = valu; 1265130803Smarcel SYMBOL_DOMAIN (typedef_sym) = VAR_DOMAIN; 126619370Spst if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0) 126719370Spst TYPE_NAME (SYMBOL_TYPE (sym)) 1268130803Smarcel = obconcat (&objfile->objfile_obstack, "", "", DEPRECATED_SYMBOL_NAME (sym)); 126919370Spst add_symbol_to_list (typedef_sym, &file_symbols); 127019370Spst } 127119370Spst break; 127219370Spst 127319370Spst case 'V': 127419370Spst /* Static symbol of local scope */ 127519370Spst SYMBOL_TYPE (sym) = read_type (&p, objfile); 127619370Spst SYMBOL_CLASS (sym) = LOC_STATIC; 127719370Spst SYMBOL_VALUE_ADDRESS (sym) = valu; 127819370Spst#ifdef STATIC_TRANSFORM_NAME 1279130803Smarcel if (IS_STATIC_TRANSFORM_NAME (DEPRECATED_SYMBOL_NAME (sym))) 128098944Sobrien { 128198944Sobrien struct minimal_symbol *msym; 1282130803Smarcel msym = lookup_minimal_symbol (DEPRECATED_SYMBOL_NAME (sym), NULL, objfile); 128398944Sobrien if (msym != NULL) 128498944Sobrien { 1285130803Smarcel DEPRECATED_SYMBOL_NAME (sym) = STATIC_TRANSFORM_NAME (DEPRECATED_SYMBOL_NAME (sym)); 128698944Sobrien SYMBOL_VALUE_ADDRESS (sym) = SYMBOL_VALUE_ADDRESS (msym); 128798944Sobrien } 128898944Sobrien } 128919370Spst#endif 1290130803Smarcel SYMBOL_DOMAIN (sym) = VAR_DOMAIN; 129119370Spst add_symbol_to_list (sym, &local_symbols); 129219370Spst break; 129319370Spst 129419370Spst case 'v': 129519370Spst /* Reference parameter */ 129619370Spst SYMBOL_TYPE (sym) = read_type (&p, objfile); 129719370Spst SYMBOL_CLASS (sym) = LOC_REF_ARG; 129819370Spst SYMBOL_VALUE (sym) = valu; 1299130803Smarcel SYMBOL_DOMAIN (sym) = VAR_DOMAIN; 130019370Spst add_symbol_to_list (sym, &local_symbols); 130119370Spst break; 130219370Spst 130319370Spst case 'a': 130419370Spst /* Reference parameter which is in a register. */ 130519370Spst SYMBOL_TYPE (sym) = read_type (&p, objfile); 130619370Spst SYMBOL_CLASS (sym) = LOC_REGPARM_ADDR; 130719370Spst SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu); 130898944Sobrien if (SYMBOL_VALUE (sym) >= NUM_REGS + NUM_PSEUDO_REGS) 130919370Spst { 1310130803Smarcel reg_value_complaint (SYMBOL_VALUE (sym), 1311130803Smarcel NUM_REGS + NUM_PSEUDO_REGS, 1312130803Smarcel SYMBOL_PRINT_NAME (sym)); 131398944Sobrien SYMBOL_VALUE (sym) = SP_REGNUM; /* Known safe, though useless */ 131419370Spst } 1315130803Smarcel SYMBOL_DOMAIN (sym) = VAR_DOMAIN; 131619370Spst add_symbol_to_list (sym, &local_symbols); 131719370Spst break; 131819370Spst 131919370Spst case 'X': 132019370Spst /* This is used by Sun FORTRAN for "function result value". 132198944Sobrien Sun claims ("dbx and dbxtool interfaces", 2nd ed) 132298944Sobrien that Pascal uses it too, but when I tried it Pascal used 132398944Sobrien "x:3" (local symbol) instead. */ 132419370Spst SYMBOL_TYPE (sym) = read_type (&p, objfile); 132519370Spst SYMBOL_CLASS (sym) = LOC_LOCAL; 132619370Spst SYMBOL_VALUE (sym) = valu; 1327130803Smarcel SYMBOL_DOMAIN (sym) = VAR_DOMAIN; 132819370Spst add_symbol_to_list (sym, &local_symbols); 132919370Spst break; 133019370Spst 133119370Spst default: 133219370Spst SYMBOL_TYPE (sym) = error_type (&p, objfile); 133319370Spst SYMBOL_CLASS (sym) = LOC_CONST; 133419370Spst SYMBOL_VALUE (sym) = 0; 1335130803Smarcel SYMBOL_DOMAIN (sym) = VAR_DOMAIN; 133619370Spst add_symbol_to_list (sym, &file_symbols); 133719370Spst break; 133819370Spst } 133919370Spst 1340130803Smarcel /* Some systems pass variables of certain types by reference instead 1341130803Smarcel of by value, i.e. they will pass the address of a structure (in a 1342130803Smarcel register or on the stack) instead of the structure itself. */ 134319370Spst 1344130803Smarcel if (gdbarch_stabs_argument_has_addr (current_gdbarch, SYMBOL_TYPE (sym)) 134546283Sdfr && (SYMBOL_CLASS (sym) == LOC_REGPARM || SYMBOL_CLASS (sym) == LOC_ARG)) 134619370Spst { 1347130803Smarcel /* We have to convert LOC_REGPARM to LOC_REGPARM_ADDR (for 1348130803Smarcel variables passed in a register). */ 1349130803Smarcel if (SYMBOL_CLASS (sym) == LOC_REGPARM) 1350130803Smarcel SYMBOL_CLASS (sym) = LOC_REGPARM_ADDR; 1351130803Smarcel /* Likewise for converting LOC_ARG to LOC_REF_ARG (for the 7th 1352130803Smarcel and subsequent arguments on SPARC, for example). */ 1353130803Smarcel else if (SYMBOL_CLASS (sym) == LOC_ARG) 1354130803Smarcel SYMBOL_CLASS (sym) = LOC_REF_ARG; 135519370Spst } 135619370Spst 135719370Spst return sym; 135819370Spst} 135919370Spst 136019370Spst/* Skip rest of this symbol and return an error type. 136119370Spst 136219370Spst General notes on error recovery: error_type always skips to the 136319370Spst end of the symbol (modulo cretinous dbx symbol name continuation). 136419370Spst Thus code like this: 136519370Spst 136619370Spst if (*(*pp)++ != ';') 136798944Sobrien return error_type (pp, objfile); 136819370Spst 136919370Spst is wrong because if *pp starts out pointing at '\0' (typically as the 137019370Spst result of an earlier error), it will be incremented to point to the 137119370Spst start of the next symbol, which might produce strange results, at least 137219370Spst if you run off the end of the string table. Instead use 137319370Spst 137419370Spst if (**pp != ';') 137598944Sobrien return error_type (pp, objfile); 137619370Spst ++*pp; 137719370Spst 137819370Spst or 137919370Spst 138019370Spst if (**pp != ';') 138198944Sobrien foo = error_type (pp, objfile); 138219370Spst else 138398944Sobrien ++*pp; 138419370Spst 138519370Spst And in case it isn't obvious, the point of all this hair is so the compiler 138619370Spst can define new types and new syntaxes, and old versions of the 138719370Spst debugger will be able to read the new symbol tables. */ 138819370Spst 138919370Spststatic struct type * 139098944Sobrienerror_type (char **pp, struct objfile *objfile) 139119370Spst{ 1392130803Smarcel complaint (&symfile_complaints, "couldn't parse type; debugger out of date?"); 139319370Spst while (1) 139419370Spst { 139519370Spst /* Skip to end of symbol. */ 139619370Spst while (**pp != '\0') 139719370Spst { 139819370Spst (*pp)++; 139919370Spst } 140019370Spst 140119370Spst /* Check for and handle cretinous dbx symbol name continuation! */ 140219370Spst if ((*pp)[-1] == '\\' || (*pp)[-1] == '?') 140319370Spst { 140419370Spst *pp = next_symbol_text (objfile); 140519370Spst } 140619370Spst else 140719370Spst { 140819370Spst break; 140919370Spst } 141019370Spst } 141119370Spst return (builtin_type_error); 141219370Spst} 141398944Sobrien 141419370Spst 141519370Spst/* Read type information or a type definition; return the type. Even 141619370Spst though this routine accepts either type information or a type 141719370Spst definition, the distinction is relevant--some parts of stabsread.c 141819370Spst assume that type information starts with a digit, '-', or '(' in 141919370Spst deciding whether to call read_type. */ 142019370Spst 1421130803Smarcelstatic struct type * 1422130803Smarcelread_type (char **pp, struct objfile *objfile) 142319370Spst{ 1424130803Smarcel struct type *type = 0; 142519370Spst struct type *type1; 142619370Spst int typenums[2]; 142719370Spst char type_descriptor; 142819370Spst 142919370Spst /* Size in bits of type if specified by a type attribute, or -1 if 143019370Spst there is no size attribute. */ 143119370Spst int type_size = -1; 143219370Spst 143319370Spst /* Used to distinguish string and bitstring from char-array and set. */ 143419370Spst int is_string = 0; 143519370Spst 1436130803Smarcel /* Used to distinguish vector from array. */ 1437130803Smarcel int is_vector = 0; 1438130803Smarcel 143919370Spst /* Read type number if present. The type number may be omitted. 144019370Spst for instance in a two-dimensional array declared with type 144119370Spst "ar1;1;10;ar1;1;10;4". */ 144219370Spst if ((**pp >= '0' && **pp <= '9') 144319370Spst || **pp == '(' 144419370Spst || **pp == '-') 144519370Spst { 144619370Spst if (read_type_number (pp, typenums) != 0) 144719370Spst return error_type (pp, objfile); 144898944Sobrien 144919370Spst if (**pp != '=') 1450130803Smarcel { 1451130803Smarcel /* Type is not being defined here. Either it already 1452130803Smarcel exists, or this is a forward reference to it. 1453130803Smarcel dbx_alloc_type handles both cases. */ 1454130803Smarcel type = dbx_alloc_type (typenums, objfile); 145519370Spst 1456130803Smarcel /* If this is a forward reference, arrange to complain if it 1457130803Smarcel doesn't get patched up by the time we're done 1458130803Smarcel reading. */ 1459130803Smarcel if (TYPE_CODE (type) == TYPE_CODE_UNDEF) 1460130803Smarcel add_undefined_type (type); 1461130803Smarcel 1462130803Smarcel return type; 1463130803Smarcel } 1464130803Smarcel 146519370Spst /* Type is being defined here. */ 146646283Sdfr /* Skip the '='. 146798944Sobrien Also skip the type descriptor - we get it below with (*pp)[-1]. */ 146898944Sobrien (*pp) += 2; 146919370Spst } 147019370Spst else 147119370Spst { 147219370Spst /* 'typenums=' not present, type is anonymous. Read and return 147398944Sobrien the definition, but don't put it in the type vector. */ 147419370Spst typenums[0] = typenums[1] = -1; 147519370Spst (*pp)++; 147619370Spst } 147719370Spst 147898944Sobrienagain: 147919370Spst type_descriptor = (*pp)[-1]; 148019370Spst switch (type_descriptor) 148119370Spst { 148219370Spst case 'x': 148319370Spst { 148419370Spst enum type_code code; 148519370Spst 148619370Spst /* Used to index through file_symbols. */ 148719370Spst struct pending *ppt; 148819370Spst int i; 148998944Sobrien 149019370Spst /* Name including "struct", etc. */ 149119370Spst char *type_name; 149298944Sobrien 149319370Spst { 149419370Spst char *from, *to, *p, *q1, *q2; 149598944Sobrien 149619370Spst /* Set the type code according to the following letter. */ 149719370Spst switch ((*pp)[0]) 149819370Spst { 149919370Spst case 's': 150019370Spst code = TYPE_CODE_STRUCT; 150119370Spst break; 150219370Spst case 'u': 150319370Spst code = TYPE_CODE_UNION; 150419370Spst break; 150519370Spst case 'e': 150619370Spst code = TYPE_CODE_ENUM; 150719370Spst break; 150819370Spst default: 150919370Spst { 151019370Spst /* Complain and keep going, so compilers can invent new 151119370Spst cross-reference types. */ 1512130803Smarcel complaint (&symfile_complaints, 1513130803Smarcel "Unrecognized cross-reference type `%c'", (*pp)[0]); 151419370Spst code = TYPE_CODE_STRUCT; 151519370Spst break; 151619370Spst } 151719370Spst } 151898944Sobrien 151946283Sdfr q1 = strchr (*pp, '<'); 152046283Sdfr p = strchr (*pp, ':'); 152119370Spst if (p == NULL) 152219370Spst return error_type (pp, objfile); 152346283Sdfr if (q1 && p > q1 && p[1] == ':') 152419370Spst { 152546283Sdfr int nesting_level = 0; 152646283Sdfr for (q2 = q1; *q2; q2++) 152746283Sdfr { 152846283Sdfr if (*q2 == '<') 152946283Sdfr nesting_level++; 153046283Sdfr else if (*q2 == '>') 153146283Sdfr nesting_level--; 153246283Sdfr else if (*q2 == ':' && nesting_level == 0) 153346283Sdfr break; 153446283Sdfr } 153546283Sdfr p = q2; 153646283Sdfr if (*p != ':') 153746283Sdfr return error_type (pp, objfile); 153819370Spst } 153998944Sobrien to = type_name = 1540130803Smarcel (char *) obstack_alloc (&objfile->objfile_obstack, p - *pp + 1); 154198944Sobrien 154219370Spst /* Copy the name. */ 154319370Spst from = *pp + 1; 154498944Sobrien while (from < p) 154519370Spst *to++ = *from++; 154619370Spst *to = '\0'; 154798944Sobrien 154819370Spst /* Set the pointer ahead of the name which we just read, and 154919370Spst the colon. */ 155019370Spst *pp = from + 1; 155119370Spst } 155219370Spst 1553130803Smarcel /* If this type has already been declared, then reuse the same 1554130803Smarcel type, rather than allocating a new one. This saves some 1555130803Smarcel memory. */ 155619370Spst 155719370Spst for (ppt = file_symbols; ppt; ppt = ppt->next) 155819370Spst for (i = 0; i < ppt->nsyms; i++) 155919370Spst { 156019370Spst struct symbol *sym = ppt->symbol[i]; 156119370Spst 156219370Spst if (SYMBOL_CLASS (sym) == LOC_TYPEDEF 1563130803Smarcel && SYMBOL_DOMAIN (sym) == STRUCT_DOMAIN 156419370Spst && (TYPE_CODE (SYMBOL_TYPE (sym)) == code) 1565130803Smarcel && strcmp (DEPRECATED_SYMBOL_NAME (sym), type_name) == 0) 156619370Spst { 1567130803Smarcel obstack_free (&objfile->objfile_obstack, type_name); 156819370Spst type = SYMBOL_TYPE (sym); 1569130803Smarcel if (typenums[0] != -1) 1570130803Smarcel *dbx_lookup_type (typenums) = type; 157119370Spst return type; 157219370Spst } 157319370Spst } 157419370Spst 157519370Spst /* Didn't find the type to which this refers, so we must 157619370Spst be dealing with a forward reference. Allocate a type 157719370Spst structure for it, and keep track of it so we can 157819370Spst fill in the rest of the fields when we get the full 157919370Spst type. */ 158019370Spst type = dbx_alloc_type (typenums, objfile); 158119370Spst TYPE_CODE (type) = code; 158219370Spst TYPE_TAG_NAME (type) = type_name; 158398944Sobrien INIT_CPLUS_SPECIFIC (type); 158419370Spst TYPE_FLAGS (type) |= TYPE_FLAG_STUB; 158519370Spst 158619370Spst add_undefined_type (type); 158719370Spst return type; 158819370Spst } 158919370Spst 159098944Sobrien case '-': /* RS/6000 built-in type */ 159119370Spst case '0': 159219370Spst case '1': 159319370Spst case '2': 159419370Spst case '3': 159519370Spst case '4': 159619370Spst case '5': 159719370Spst case '6': 159819370Spst case '7': 159919370Spst case '8': 160019370Spst case '9': 160119370Spst case '(': 160246283Sdfr (*pp)--; 160319370Spst 160446283Sdfr /* We deal with something like t(1,2)=(3,4)=... which 160598944Sobrien the Lucid compiler and recent gcc versions (post 2.7.3) use. */ 160619370Spst 160746283Sdfr /* Allocate and enter the typedef type first. 160898944Sobrien This handles recursive types. */ 160946283Sdfr type = dbx_alloc_type (typenums, objfile); 161046283Sdfr TYPE_CODE (type) = TYPE_CODE_TYPEDEF; 161198944Sobrien { 161298944Sobrien struct type *xtype = read_type (pp, objfile); 161346283Sdfr if (type == xtype) 161446283Sdfr { 161546283Sdfr /* It's being defined as itself. That means it is "void". */ 161646283Sdfr TYPE_CODE (type) = TYPE_CODE_VOID; 161746283Sdfr TYPE_LENGTH (type) = 1; 161846283Sdfr } 161946283Sdfr else if (type_size >= 0 || is_string) 162046283Sdfr { 162198944Sobrien /* This is the absolute wrong way to construct types. Every 162298944Sobrien other debug format has found a way around this problem and 162398944Sobrien the related problems with unnecessarily stubbed types; 162498944Sobrien someone motivated should attempt to clean up the issue 162598944Sobrien here as well. Once a type pointed to has been created it 1626130803Smarcel should not be modified. 1627130803Smarcel 1628130803Smarcel Well, it's not *absolutely* wrong. Constructing recursive 1629130803Smarcel types (trees, linked lists) necessarily entails modifying 1630130803Smarcel types after creating them. Constructing any loop structure 1631130803Smarcel entails side effects. The Dwarf 2 reader does handle this 1632130803Smarcel more gracefully (it never constructs more than once 1633130803Smarcel instance of a type object, so it doesn't have to copy type 1634130803Smarcel objects wholesale), but it still mutates type objects after 1635130803Smarcel other folks have references to them. 1636130803Smarcel 1637130803Smarcel Keep in mind that this circularity/mutation issue shows up 1638130803Smarcel at the source language level, too: C's "incomplete types", 1639130803Smarcel for example. So the proper cleanup, I think, would be to 1640130803Smarcel limit GDB's type smashing to match exactly those required 1641130803Smarcel by the source language. So GDB could have a 1642130803Smarcel "complete_this_type" function, but never create unnecessary 1643130803Smarcel copies of a type otherwise. */ 164498944Sobrien replace_type (type, xtype); 164546283Sdfr TYPE_NAME (type) = NULL; 164646283Sdfr TYPE_TAG_NAME (type) = NULL; 164746283Sdfr } 164819370Spst else 164919370Spst { 165046283Sdfr TYPE_FLAGS (type) |= TYPE_FLAG_TARGET_STUB; 165146283Sdfr TYPE_TARGET_TYPE (type) = xtype; 165219370Spst } 165319370Spst } 165446283Sdfr break; 165519370Spst 165698944Sobrien /* In the following types, we must be sure to overwrite any existing 165798944Sobrien type that the typenums refer to, rather than allocating a new one 165898944Sobrien and making the typenums point to the new one. This is because there 165998944Sobrien may already be pointers to the existing type (if it had been 166098944Sobrien forward-referenced), and we must change it to a pointer, function, 166198944Sobrien reference, or whatever, *in-place*. */ 166219370Spst 1663130803Smarcel case '*': /* Pointer to another type */ 166419370Spst type1 = read_type (pp, objfile); 166519370Spst type = make_pointer_type (type1, dbx_lookup_type (typenums)); 166619370Spst break; 166719370Spst 166898944Sobrien case '&': /* Reference to another type */ 166919370Spst type1 = read_type (pp, objfile); 167019370Spst type = make_reference_type (type1, dbx_lookup_type (typenums)); 167119370Spst break; 167219370Spst 167398944Sobrien case 'f': /* Function returning another type */ 167419370Spst type1 = read_type (pp, objfile); 167519370Spst type = make_function_type (type1, dbx_lookup_type (typenums)); 167619370Spst break; 167719370Spst 167898944Sobrien case 'g': /* Prototyped function. (Sun) */ 167998944Sobrien { 168098944Sobrien /* Unresolved questions: 168198944Sobrien 168298944Sobrien - According to Sun's ``STABS Interface Manual'', for 'f' 168398944Sobrien and 'F' symbol descriptors, a `0' in the argument type list 168498944Sobrien indicates a varargs function. But it doesn't say how 'g' 168598944Sobrien type descriptors represent that info. Someone with access 168698944Sobrien to Sun's toolchain should try it out. 168798944Sobrien 168898944Sobrien - According to the comment in define_symbol (search for 168998944Sobrien `process_prototype_types:'), Sun emits integer arguments as 169098944Sobrien types which ref themselves --- like `void' types. Do we 169198944Sobrien have to deal with that here, too? Again, someone with 169298944Sobrien access to Sun's toolchain should try it out and let us 169398944Sobrien know. */ 169498944Sobrien 169598944Sobrien const char *type_start = (*pp) - 1; 169698944Sobrien struct type *return_type = read_type (pp, objfile); 169798944Sobrien struct type *func_type 169898944Sobrien = make_function_type (return_type, dbx_lookup_type (typenums)); 169998944Sobrien struct type_list { 170098944Sobrien struct type *type; 170198944Sobrien struct type_list *next; 170298944Sobrien } *arg_types = 0; 170398944Sobrien int num_args = 0; 170498944Sobrien 170598944Sobrien while (**pp && **pp != '#') 170698944Sobrien { 170798944Sobrien struct type *arg_type = read_type (pp, objfile); 170898944Sobrien struct type_list *new = alloca (sizeof (*new)); 170998944Sobrien new->type = arg_type; 171098944Sobrien new->next = arg_types; 171198944Sobrien arg_types = new; 171298944Sobrien num_args++; 171398944Sobrien } 171498944Sobrien if (**pp == '#') 171598944Sobrien ++*pp; 171698944Sobrien else 171798944Sobrien { 1718130803Smarcel complaint (&symfile_complaints, 1719130803Smarcel "Prototyped function type didn't end arguments with `#':\n%s", 1720130803Smarcel type_start); 172198944Sobrien } 172298944Sobrien 172398944Sobrien /* If there is just one argument whose type is `void', then 172498944Sobrien that's just an empty argument list. */ 172598944Sobrien if (arg_types 172698944Sobrien && ! arg_types->next 172798944Sobrien && TYPE_CODE (arg_types->type) == TYPE_CODE_VOID) 172898944Sobrien num_args = 0; 172998944Sobrien 173098944Sobrien TYPE_FIELDS (func_type) 173198944Sobrien = (struct field *) TYPE_ALLOC (func_type, 173298944Sobrien num_args * sizeof (struct field)); 173398944Sobrien memset (TYPE_FIELDS (func_type), 0, num_args * sizeof (struct field)); 173498944Sobrien { 173598944Sobrien int i; 173698944Sobrien struct type_list *t; 173798944Sobrien 173898944Sobrien /* We stuck each argument type onto the front of the list 173998944Sobrien when we read it, so the list is reversed. Build the 174098944Sobrien fields array right-to-left. */ 174198944Sobrien for (t = arg_types, i = num_args - 1; t; t = t->next, i--) 174298944Sobrien TYPE_FIELD_TYPE (func_type, i) = t->type; 174398944Sobrien } 174498944Sobrien TYPE_NFIELDS (func_type) = num_args; 174598944Sobrien TYPE_FLAGS (func_type) |= TYPE_FLAG_PROTOTYPED; 174698944Sobrien 174798944Sobrien type = func_type; 174898944Sobrien break; 174998944Sobrien } 175098944Sobrien 175198944Sobrien case 'k': /* Const qualifier on some type (Sun) */ 175219370Spst type = read_type (pp, objfile); 1753256851Semaste type = make_cvr_type (1, TYPE_VOLATILE (type), TYPE_RESTRICT(type), type, 175498944Sobrien dbx_lookup_type (typenums)); 175519370Spst break; 175619370Spst 175798944Sobrien case 'B': /* Volatile qual on some type (Sun) */ 175819370Spst type = read_type (pp, objfile); 1759256851Semaste type = make_cvr_type (TYPE_CONST (type), 1, TYPE_RESTRICT(type), type, 176098944Sobrien dbx_lookup_type (typenums)); 176119370Spst break; 176219370Spst 176346283Sdfr case '@': 176498944Sobrien if (isdigit (**pp) || **pp == '(' || **pp == '-') 176598944Sobrien { /* Member (class & variable) type */ 176646283Sdfr /* FIXME -- we should be doing smash_to_XXX types here. */ 176719370Spst 176846283Sdfr struct type *domain = read_type (pp, objfile); 176946283Sdfr struct type *memtype; 177019370Spst 177146283Sdfr if (**pp != ',') 177246283Sdfr /* Invalid member type data format. */ 177346283Sdfr return error_type (pp, objfile); 177446283Sdfr ++*pp; 177546283Sdfr 177646283Sdfr memtype = read_type (pp, objfile); 177746283Sdfr type = dbx_alloc_type (typenums, objfile); 177846283Sdfr smash_to_member_type (type, domain, memtype); 177946283Sdfr } 178098944Sobrien else 178198944Sobrien /* type attribute */ 178246283Sdfr { 178346283Sdfr char *attr = *pp; 178446283Sdfr /* Skip to the semicolon. */ 178546283Sdfr while (**pp != ';' && **pp != '\0') 178646283Sdfr ++(*pp); 178746283Sdfr if (**pp == '\0') 178846283Sdfr return error_type (pp, objfile); 178946283Sdfr else 179098944Sobrien ++ * pp; /* Skip the semicolon. */ 179146283Sdfr 179246283Sdfr switch (*attr) 179346283Sdfr { 1794130803Smarcel case 's': /* Size attribute */ 179546283Sdfr type_size = atoi (attr + 1); 179646283Sdfr if (type_size <= 0) 179746283Sdfr type_size = -1; 179846283Sdfr break; 179946283Sdfr 1800130803Smarcel case 'S': /* String attribute */ 1801130803Smarcel /* FIXME: check to see if following type is array? */ 180246283Sdfr is_string = 1; 180346283Sdfr break; 180446283Sdfr 1805130803Smarcel case 'V': /* Vector attribute */ 1806130803Smarcel /* FIXME: check to see if following type is array? */ 1807130803Smarcel is_vector = 1; 1808130803Smarcel break; 1809130803Smarcel 181046283Sdfr default: 181146283Sdfr /* Ignore unrecognized type attributes, so future compilers 181298944Sobrien can invent new ones. */ 181346283Sdfr break; 181446283Sdfr } 181546283Sdfr ++*pp; 181646283Sdfr goto again; 181746283Sdfr } 181819370Spst break; 181919370Spst 182098944Sobrien case '#': /* Method (class & fn) type */ 182119370Spst if ((*pp)[0] == '#') 182219370Spst { 182319370Spst /* We'll get the parameter types from the name. */ 182419370Spst struct type *return_type; 182519370Spst 182619370Spst (*pp)++; 182719370Spst return_type = read_type (pp, objfile); 182819370Spst if (*(*pp)++ != ';') 1829130803Smarcel complaint (&symfile_complaints, 1830130803Smarcel "invalid (minimal) member type data format at symtab pos %d.", 1831130803Smarcel symnum); 183219370Spst type = allocate_stub_method (return_type); 183319370Spst if (typenums[0] != -1) 183419370Spst *dbx_lookup_type (typenums) = type; 183519370Spst } 183619370Spst else 183719370Spst { 183819370Spst struct type *domain = read_type (pp, objfile); 183919370Spst struct type *return_type; 1840130803Smarcel struct field *args; 1841130803Smarcel int nargs, varargs; 184219370Spst 184319370Spst if (**pp != ',') 184419370Spst /* Invalid member type data format. */ 184519370Spst return error_type (pp, objfile); 184619370Spst else 184719370Spst ++(*pp); 184819370Spst 184919370Spst return_type = read_type (pp, objfile); 1850130803Smarcel args = read_args (pp, ';', objfile, &nargs, &varargs); 185119370Spst type = dbx_alloc_type (typenums, objfile); 1852130803Smarcel smash_to_method_type (type, domain, return_type, args, 1853130803Smarcel nargs, varargs); 185419370Spst } 185519370Spst break; 185619370Spst 185798944Sobrien case 'r': /* Range type */ 185819370Spst type = read_range_type (pp, typenums, objfile); 185919370Spst if (typenums[0] != -1) 186019370Spst *dbx_lookup_type (typenums) = type; 186119370Spst break; 186219370Spst 186319370Spst case 'b': 186419370Spst { 186519370Spst /* Sun ACC builtin int type */ 186619370Spst type = read_sun_builtin_type (pp, typenums, objfile); 186719370Spst if (typenums[0] != -1) 186819370Spst *dbx_lookup_type (typenums) = type; 186919370Spst } 187019370Spst break; 187119370Spst 187298944Sobrien case 'R': /* Sun ACC builtin float type */ 187319370Spst type = read_sun_floating_type (pp, typenums, objfile); 187419370Spst if (typenums[0] != -1) 187519370Spst *dbx_lookup_type (typenums) = type; 187619370Spst break; 187798944Sobrien 187898944Sobrien case 'e': /* Enumeration type */ 187919370Spst type = dbx_alloc_type (typenums, objfile); 188019370Spst type = read_enum_type (pp, type, objfile); 188119370Spst if (typenums[0] != -1) 188219370Spst *dbx_lookup_type (typenums) = type; 188319370Spst break; 188419370Spst 188598944Sobrien case 's': /* Struct type */ 188698944Sobrien case 'u': /* Union type */ 1887130803Smarcel { 1888130803Smarcel enum type_code type_code = TYPE_CODE_UNDEF; 1889130803Smarcel type = dbx_alloc_type (typenums, objfile); 1890130803Smarcel switch (type_descriptor) 1891130803Smarcel { 1892130803Smarcel case 's': 1893130803Smarcel type_code = TYPE_CODE_STRUCT; 1894130803Smarcel break; 1895130803Smarcel case 'u': 1896130803Smarcel type_code = TYPE_CODE_UNION; 1897130803Smarcel break; 1898130803Smarcel } 1899130803Smarcel type = read_struct_type (pp, type, type_code, objfile); 1900130803Smarcel break; 1901130803Smarcel } 190219370Spst 190398944Sobrien case 'a': /* Array type */ 190419370Spst if (**pp != 'r') 190519370Spst return error_type (pp, objfile); 190619370Spst ++*pp; 190798944Sobrien 190819370Spst type = dbx_alloc_type (typenums, objfile); 190919370Spst type = read_array_type (pp, type, objfile); 191019370Spst if (is_string) 191119370Spst TYPE_CODE (type) = TYPE_CODE_STRING; 1912130803Smarcel if (is_vector) 1913130803Smarcel TYPE_FLAGS (type) |= TYPE_FLAG_VECTOR; 191419370Spst break; 191519370Spst 1916130803Smarcel case 'S': /* Set or bitstring type */ 191719370Spst type1 = read_type (pp, objfile); 191898944Sobrien type = create_set_type ((struct type *) NULL, type1); 191919370Spst if (is_string) 192019370Spst TYPE_CODE (type) = TYPE_CODE_BITSTRING; 192119370Spst if (typenums[0] != -1) 192219370Spst *dbx_lookup_type (typenums) = type; 192319370Spst break; 192419370Spst 192519370Spst default: 192619370Spst --*pp; /* Go back to the symbol in error */ 192798944Sobrien /* Particularly important if it was \0! */ 192819370Spst return error_type (pp, objfile); 192919370Spst } 193019370Spst 193119370Spst if (type == 0) 193219370Spst { 193319370Spst warning ("GDB internal error, type is NULL in stabsread.c\n"); 193419370Spst return error_type (pp, objfile); 193519370Spst } 193619370Spst 193719370Spst /* Size specified in a type attribute overrides any other size. */ 193819370Spst if (type_size != -1) 193919370Spst TYPE_LENGTH (type) = (type_size + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT; 194019370Spst 194119370Spst return type; 194219370Spst} 194319370Spst 194419370Spst/* RS/6000 xlc/dbx combination uses a set of builtin types, starting from -1. 194519370Spst Return the proper type node for a given builtin type number. */ 194619370Spst 194719370Spststatic struct type * 194898944Sobrienrs6000_builtin_type (int typenum) 194919370Spst{ 195019370Spst /* We recognize types numbered from -NUMBER_RECOGNIZED to -1. */ 195119370Spst#define NUMBER_RECOGNIZED 34 195219370Spst /* This includes an empty slot for type number -0. */ 195319370Spst static struct type *negative_types[NUMBER_RECOGNIZED + 1]; 195419370Spst struct type *rettype = NULL; 195519370Spst 195619370Spst if (typenum >= 0 || typenum < -NUMBER_RECOGNIZED) 195719370Spst { 1958130803Smarcel complaint (&symfile_complaints, "Unknown builtin type %d", typenum); 195919370Spst return builtin_type_error; 196019370Spst } 196119370Spst if (negative_types[-typenum] != NULL) 196219370Spst return negative_types[-typenum]; 196319370Spst 196419370Spst#if TARGET_CHAR_BIT != 8 196598944Sobrien#error This code wrong for TARGET_CHAR_BIT not 8 196619370Spst /* These definitions all assume that TARGET_CHAR_BIT is 8. I think 196719370Spst that if that ever becomes not true, the correct fix will be to 196819370Spst make the size in the struct type to be in bits, not in units of 196919370Spst TARGET_CHAR_BIT. */ 197019370Spst#endif 197119370Spst 197219370Spst switch (-typenum) 197319370Spst { 197419370Spst case 1: 197519370Spst /* The size of this and all the other types are fixed, defined 197698944Sobrien by the debugging format. If there is a type called "int" which 197798944Sobrien is other than 32 bits, then it should use a new negative type 197898944Sobrien number (or avoid negative type numbers for that case). 197998944Sobrien See stabs.texinfo. */ 198019370Spst rettype = init_type (TYPE_CODE_INT, 4, 0, "int", NULL); 198119370Spst break; 198219370Spst case 2: 198319370Spst rettype = init_type (TYPE_CODE_INT, 1, 0, "char", NULL); 198419370Spst break; 198519370Spst case 3: 198619370Spst rettype = init_type (TYPE_CODE_INT, 2, 0, "short", NULL); 198719370Spst break; 198819370Spst case 4: 198919370Spst rettype = init_type (TYPE_CODE_INT, 4, 0, "long", NULL); 199019370Spst break; 199119370Spst case 5: 199219370Spst rettype = init_type (TYPE_CODE_INT, 1, TYPE_FLAG_UNSIGNED, 199319370Spst "unsigned char", NULL); 199419370Spst break; 199519370Spst case 6: 199619370Spst rettype = init_type (TYPE_CODE_INT, 1, 0, "signed char", NULL); 199719370Spst break; 199819370Spst case 7: 199919370Spst rettype = init_type (TYPE_CODE_INT, 2, TYPE_FLAG_UNSIGNED, 200019370Spst "unsigned short", NULL); 200119370Spst break; 200219370Spst case 8: 200319370Spst rettype = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED, 200419370Spst "unsigned int", NULL); 200519370Spst break; 200619370Spst case 9: 200719370Spst rettype = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED, 200819370Spst "unsigned", NULL); 200919370Spst case 10: 201019370Spst rettype = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED, 201119370Spst "unsigned long", NULL); 201219370Spst break; 201319370Spst case 11: 201419370Spst rettype = init_type (TYPE_CODE_VOID, 1, 0, "void", NULL); 201519370Spst break; 201619370Spst case 12: 201719370Spst /* IEEE single precision (32 bit). */ 201819370Spst rettype = init_type (TYPE_CODE_FLT, 4, 0, "float", NULL); 201919370Spst break; 202019370Spst case 13: 202119370Spst /* IEEE double precision (64 bit). */ 202219370Spst rettype = init_type (TYPE_CODE_FLT, 8, 0, "double", NULL); 202319370Spst break; 202419370Spst case 14: 202519370Spst /* This is an IEEE double on the RS/6000, and different machines with 202698944Sobrien different sizes for "long double" should use different negative 202798944Sobrien type numbers. See stabs.texinfo. */ 202819370Spst rettype = init_type (TYPE_CODE_FLT, 8, 0, "long double", NULL); 202919370Spst break; 203019370Spst case 15: 203119370Spst rettype = init_type (TYPE_CODE_INT, 4, 0, "integer", NULL); 203219370Spst break; 203319370Spst case 16: 203419370Spst rettype = init_type (TYPE_CODE_BOOL, 4, TYPE_FLAG_UNSIGNED, 203519370Spst "boolean", NULL); 203619370Spst break; 203719370Spst case 17: 203819370Spst rettype = init_type (TYPE_CODE_FLT, 4, 0, "short real", NULL); 203919370Spst break; 204019370Spst case 18: 204119370Spst rettype = init_type (TYPE_CODE_FLT, 8, 0, "real", NULL); 204219370Spst break; 204319370Spst case 19: 204419370Spst rettype = init_type (TYPE_CODE_ERROR, 0, 0, "stringptr", NULL); 204519370Spst break; 204619370Spst case 20: 204719370Spst rettype = init_type (TYPE_CODE_CHAR, 1, TYPE_FLAG_UNSIGNED, 204819370Spst "character", NULL); 204919370Spst break; 205019370Spst case 21: 205119370Spst rettype = init_type (TYPE_CODE_BOOL, 1, TYPE_FLAG_UNSIGNED, 205219370Spst "logical*1", NULL); 205319370Spst break; 205419370Spst case 22: 205519370Spst rettype = init_type (TYPE_CODE_BOOL, 2, TYPE_FLAG_UNSIGNED, 205619370Spst "logical*2", NULL); 205719370Spst break; 205819370Spst case 23: 205919370Spst rettype = init_type (TYPE_CODE_BOOL, 4, TYPE_FLAG_UNSIGNED, 206019370Spst "logical*4", NULL); 206119370Spst break; 206219370Spst case 24: 206319370Spst rettype = init_type (TYPE_CODE_BOOL, 4, TYPE_FLAG_UNSIGNED, 206419370Spst "logical", NULL); 206519370Spst break; 206619370Spst case 25: 206719370Spst /* Complex type consisting of two IEEE single precision values. */ 206846283Sdfr rettype = init_type (TYPE_CODE_COMPLEX, 8, 0, "complex", NULL); 2069130803Smarcel TYPE_TARGET_TYPE (rettype) = init_type (TYPE_CODE_FLT, 4, 0, "float", 2070130803Smarcel NULL); 207119370Spst break; 207219370Spst case 26: 207319370Spst /* Complex type consisting of two IEEE double precision values. */ 207446283Sdfr rettype = init_type (TYPE_CODE_COMPLEX, 16, 0, "double complex", NULL); 2075130803Smarcel TYPE_TARGET_TYPE (rettype) = init_type (TYPE_CODE_FLT, 8, 0, "double", 2076130803Smarcel NULL); 207719370Spst break; 207819370Spst case 27: 207919370Spst rettype = init_type (TYPE_CODE_INT, 1, 0, "integer*1", NULL); 208019370Spst break; 208119370Spst case 28: 208219370Spst rettype = init_type (TYPE_CODE_INT, 2, 0, "integer*2", NULL); 208319370Spst break; 208419370Spst case 29: 208519370Spst rettype = init_type (TYPE_CODE_INT, 4, 0, "integer*4", NULL); 208619370Spst break; 208719370Spst case 30: 208819370Spst rettype = init_type (TYPE_CODE_CHAR, 2, 0, "wchar", NULL); 208919370Spst break; 209019370Spst case 31: 209119370Spst rettype = init_type (TYPE_CODE_INT, 8, 0, "long long", NULL); 209219370Spst break; 209319370Spst case 32: 209419370Spst rettype = init_type (TYPE_CODE_INT, 8, TYPE_FLAG_UNSIGNED, 209519370Spst "unsigned long long", NULL); 209619370Spst break; 209719370Spst case 33: 209819370Spst rettype = init_type (TYPE_CODE_INT, 8, TYPE_FLAG_UNSIGNED, 209919370Spst "logical*8", NULL); 210019370Spst break; 210119370Spst case 34: 210219370Spst rettype = init_type (TYPE_CODE_INT, 8, 0, "integer*8", NULL); 210319370Spst break; 210419370Spst } 210519370Spst negative_types[-typenum] = rettype; 210619370Spst return rettype; 210719370Spst} 210819370Spst 210919370Spst/* This page contains subroutines of read_type. */ 211019370Spst 2111130803Smarcel/* Replace *OLD_NAME with the method name portion of PHYSNAME. */ 2112130803Smarcel 2113130803Smarcelstatic void 2114130803Smarcelupdate_method_name_from_physname (char **old_name, char *physname) 2115130803Smarcel{ 2116130803Smarcel char *method_name; 2117130803Smarcel 2118130803Smarcel method_name = method_name_from_physname (physname); 2119130803Smarcel 2120130803Smarcel if (method_name == NULL) 2121130803Smarcel { 2122130803Smarcel complaint (&symfile_complaints, 2123130803Smarcel "Method has bad physname %s\n", physname); 2124130803Smarcel return; 2125130803Smarcel } 2126130803Smarcel 2127130803Smarcel if (strcmp (*old_name, method_name) != 0) 2128130803Smarcel { 2129130803Smarcel xfree (*old_name); 2130130803Smarcel *old_name = method_name; 2131130803Smarcel } 2132130803Smarcel else 2133130803Smarcel xfree (method_name); 2134130803Smarcel} 2135130803Smarcel 213619370Spst/* Read member function stabs info for C++ classes. The form of each member 213719370Spst function data is: 213819370Spst 213998944Sobrien NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ; 214019370Spst 214119370Spst An example with two member functions is: 214219370Spst 214398944Sobrien afunc1::20=##15;:i;2A.;afunc2::20:i;2A.; 214419370Spst 214519370Spst For the case of overloaded operators, the format is op$::*.funcs, where 214619370Spst $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator 214719370Spst name (such as `+=') and `.' marks the end of the operator name. 214819370Spst 214919370Spst Returns 1 for success, 0 for failure. */ 215019370Spst 215119370Spststatic int 215298944Sobrienread_member_functions (struct field_info *fip, char **pp, struct type *type, 215398944Sobrien struct objfile *objfile) 215419370Spst{ 215519370Spst int nfn_fields = 0; 215619370Spst int length = 0; 215719370Spst /* Total number of member functions defined in this class. If the class 215819370Spst defines two `f' functions, and one `g' function, then this will have 215919370Spst the value 3. */ 216019370Spst int total_length = 0; 216119370Spst int i; 216219370Spst struct next_fnfield 216319370Spst { 216419370Spst struct next_fnfield *next; 216519370Spst struct fn_field fn_field; 216698944Sobrien } 216798944Sobrien *sublist; 216819370Spst struct type *look_ahead_type; 216919370Spst struct next_fnfieldlist *new_fnlist; 217019370Spst struct next_fnfield *new_sublist; 217119370Spst char *main_fn_name; 2172130803Smarcel char *p; 217398944Sobrien 217419370Spst /* Process each list until we find something that is not a member function 217519370Spst or find the end of the functions. */ 217619370Spst 217719370Spst while (**pp != ';') 217819370Spst { 217919370Spst /* We should be positioned at the start of the function name. 218098944Sobrien Scan forward to find the first ':' and if it is not the 218198944Sobrien first of a "::" delimiter, then this is not a member function. */ 218219370Spst p = *pp; 218319370Spst while (*p != ':') 218419370Spst { 218519370Spst p++; 218619370Spst } 218719370Spst if (p[1] != ':') 218819370Spst { 218919370Spst break; 219019370Spst } 219119370Spst 219219370Spst sublist = NULL; 219319370Spst look_ahead_type = NULL; 219419370Spst length = 0; 219598944Sobrien 219619370Spst new_fnlist = (struct next_fnfieldlist *) 219719370Spst xmalloc (sizeof (struct next_fnfieldlist)); 219898944Sobrien make_cleanup (xfree, new_fnlist); 219919370Spst memset (new_fnlist, 0, sizeof (struct next_fnfieldlist)); 220098944Sobrien 220119370Spst if ((*pp)[0] == 'o' && (*pp)[1] == 'p' && is_cplus_marker ((*pp)[2])) 220219370Spst { 220319370Spst /* This is a completely wierd case. In order to stuff in the 220419370Spst names that might contain colons (the usual name delimiter), 220519370Spst Mike Tiemann defined a different name format which is 220619370Spst signalled if the identifier is "op$". In that case, the 220719370Spst format is "op$::XXXX." where XXXX is the name. This is 220819370Spst used for names like "+" or "=". YUUUUUUUK! FIXME! */ 220919370Spst /* This lets the user type "break operator+". 221019370Spst We could just put in "+" as the name, but that wouldn't 221119370Spst work for "*". */ 2212130803Smarcel static char opname[32] = "op$"; 221319370Spst char *o = opname + 3; 221498944Sobrien 221519370Spst /* Skip past '::'. */ 221619370Spst *pp = p + 2; 221719370Spst 221819370Spst STABS_CONTINUE (pp, objfile); 221919370Spst p = *pp; 222019370Spst while (*p != '.') 222119370Spst { 222219370Spst *o++ = *p++; 222319370Spst } 222419370Spst main_fn_name = savestring (opname, o - opname); 222519370Spst /* Skip past '.' */ 222619370Spst *pp = p + 1; 222719370Spst } 222819370Spst else 222919370Spst { 223019370Spst main_fn_name = savestring (*pp, p - *pp); 223119370Spst /* Skip past '::'. */ 223219370Spst *pp = p + 2; 223319370Spst } 223498944Sobrien new_fnlist->fn_fieldlist.name = main_fn_name; 223598944Sobrien 223619370Spst do 223719370Spst { 223819370Spst new_sublist = 223919370Spst (struct next_fnfield *) xmalloc (sizeof (struct next_fnfield)); 224098944Sobrien make_cleanup (xfree, new_sublist); 224119370Spst memset (new_sublist, 0, sizeof (struct next_fnfield)); 224298944Sobrien 224319370Spst /* Check for and handle cretinous dbx symbol name continuation! */ 224419370Spst if (look_ahead_type == NULL) 224519370Spst { 224619370Spst /* Normal case. */ 224719370Spst STABS_CONTINUE (pp, objfile); 224898944Sobrien 224998944Sobrien new_sublist->fn_field.type = read_type (pp, objfile); 225019370Spst if (**pp != ':') 225119370Spst { 225219370Spst /* Invalid symtab info for member function. */ 225319370Spst return 0; 225419370Spst } 225519370Spst } 225619370Spst else 225719370Spst { 225819370Spst /* g++ version 1 kludge */ 225998944Sobrien new_sublist->fn_field.type = look_ahead_type; 226019370Spst look_ahead_type = NULL; 226119370Spst } 226298944Sobrien 226319370Spst (*pp)++; 226419370Spst p = *pp; 226519370Spst while (*p != ';') 226619370Spst { 226719370Spst p++; 226819370Spst } 226998944Sobrien 227019370Spst /* If this is just a stub, then we don't have the real name here. */ 227119370Spst 227298944Sobrien if (TYPE_STUB (new_sublist->fn_field.type)) 227319370Spst { 227498944Sobrien if (!TYPE_DOMAIN_TYPE (new_sublist->fn_field.type)) 227598944Sobrien TYPE_DOMAIN_TYPE (new_sublist->fn_field.type) = type; 227698944Sobrien new_sublist->fn_field.is_stub = 1; 227719370Spst } 227898944Sobrien new_sublist->fn_field.physname = savestring (*pp, p - *pp); 227919370Spst *pp = p + 1; 228098944Sobrien 228119370Spst /* Set this member function's visibility fields. */ 228219370Spst switch (*(*pp)++) 228319370Spst { 228498944Sobrien case VISIBILITY_PRIVATE: 228598944Sobrien new_sublist->fn_field.is_private = 1; 228698944Sobrien break; 228798944Sobrien case VISIBILITY_PROTECTED: 228898944Sobrien new_sublist->fn_field.is_protected = 1; 228998944Sobrien break; 229019370Spst } 229198944Sobrien 229219370Spst STABS_CONTINUE (pp, objfile); 229319370Spst switch (**pp) 229419370Spst { 229598944Sobrien case 'A': /* Normal functions. */ 229698944Sobrien new_sublist->fn_field.is_const = 0; 229798944Sobrien new_sublist->fn_field.is_volatile = 0; 229898944Sobrien (*pp)++; 229998944Sobrien break; 230098944Sobrien case 'B': /* `const' member functions. */ 230198944Sobrien new_sublist->fn_field.is_const = 1; 230298944Sobrien new_sublist->fn_field.is_volatile = 0; 230398944Sobrien (*pp)++; 230498944Sobrien break; 230598944Sobrien case 'C': /* `volatile' member function. */ 230698944Sobrien new_sublist->fn_field.is_const = 0; 230798944Sobrien new_sublist->fn_field.is_volatile = 1; 230898944Sobrien (*pp)++; 230998944Sobrien break; 231098944Sobrien case 'D': /* `const volatile' member function. */ 231198944Sobrien new_sublist->fn_field.is_const = 1; 231298944Sobrien new_sublist->fn_field.is_volatile = 1; 231398944Sobrien (*pp)++; 231498944Sobrien break; 231598944Sobrien case '*': /* File compiled with g++ version 1 -- no info */ 231698944Sobrien case '?': 231798944Sobrien case '.': 231898944Sobrien break; 231998944Sobrien default: 2320130803Smarcel complaint (&symfile_complaints, 2321130803Smarcel "const/volatile indicator missing, got '%c'", **pp); 232298944Sobrien break; 232319370Spst } 232498944Sobrien 232519370Spst switch (*(*pp)++) 232619370Spst { 232798944Sobrien case '*': 232819370Spst { 232919370Spst int nbits; 233098944Sobrien /* virtual member function, followed by index. 233119370Spst The sign bit is set to distinguish pointers-to-methods 233219370Spst from virtual function indicies. Since the array is 233319370Spst in words, the quantity must be shifted left by 1 233419370Spst on 16 bit machine, and by 2 on 32 bit machine, forcing 233519370Spst the sign bit out, and usable as a valid index into 233619370Spst the array. Remove the sign bit here. */ 233798944Sobrien new_sublist->fn_field.voffset = 233819370Spst (0x7fffffff & read_huge_number (pp, ';', &nbits)) + 2; 233919370Spst if (nbits != 0) 234019370Spst return 0; 234198944Sobrien 234219370Spst STABS_CONTINUE (pp, objfile); 234319370Spst if (**pp == ';' || **pp == '\0') 234419370Spst { 234519370Spst /* Must be g++ version 1. */ 234698944Sobrien new_sublist->fn_field.fcontext = 0; 234719370Spst } 234819370Spst else 234919370Spst { 235019370Spst /* Figure out from whence this virtual function came. 235119370Spst It may belong to virtual function table of 235219370Spst one of its baseclasses. */ 235319370Spst look_ahead_type = read_type (pp, objfile); 235419370Spst if (**pp == ':') 235519370Spst { 235619370Spst /* g++ version 1 overloaded methods. */ 235719370Spst } 235819370Spst else 235919370Spst { 236098944Sobrien new_sublist->fn_field.fcontext = look_ahead_type; 236119370Spst if (**pp != ';') 236219370Spst { 236319370Spst return 0; 236419370Spst } 236519370Spst else 236619370Spst { 236719370Spst ++*pp; 236819370Spst } 236919370Spst look_ahead_type = NULL; 237019370Spst } 237119370Spst } 237219370Spst break; 237319370Spst } 237498944Sobrien case '?': 237598944Sobrien /* static member function. */ 2376130803Smarcel { 2377130803Smarcel int slen = strlen (main_fn_name); 237898944Sobrien 2379130803Smarcel new_sublist->fn_field.voffset = VOFFSET_STATIC; 2380130803Smarcel 2381130803Smarcel /* For static member functions, we can't tell if they 2382130803Smarcel are stubbed, as they are put out as functions, and not as 2383130803Smarcel methods. 2384130803Smarcel GCC v2 emits the fully mangled name if 2385130803Smarcel dbxout.c:flag_minimal_debug is not set, so we have to 2386130803Smarcel detect a fully mangled physname here and set is_stub 2387130803Smarcel accordingly. Fully mangled physnames in v2 start with 2388130803Smarcel the member function name, followed by two underscores. 2389130803Smarcel GCC v3 currently always emits stubbed member functions, 2390130803Smarcel but with fully mangled physnames, which start with _Z. */ 2391130803Smarcel if (!(strncmp (new_sublist->fn_field.physname, 2392130803Smarcel main_fn_name, slen) == 0 2393130803Smarcel && new_sublist->fn_field.physname[slen] == '_' 2394130803Smarcel && new_sublist->fn_field.physname[slen + 1] == '_')) 2395130803Smarcel { 2396130803Smarcel new_sublist->fn_field.is_stub = 1; 2397130803Smarcel } 2398130803Smarcel break; 2399130803Smarcel } 2400130803Smarcel 240198944Sobrien default: 240298944Sobrien /* error */ 2403130803Smarcel complaint (&symfile_complaints, 2404130803Smarcel "member function type missing, got '%c'", (*pp)[-1]); 240598944Sobrien /* Fall through into normal member function. */ 240698944Sobrien 240798944Sobrien case '.': 240898944Sobrien /* normal member function. */ 240998944Sobrien new_sublist->fn_field.voffset = 0; 241098944Sobrien new_sublist->fn_field.fcontext = 0; 241198944Sobrien break; 241219370Spst } 241398944Sobrien 241498944Sobrien new_sublist->next = sublist; 241519370Spst sublist = new_sublist; 241619370Spst length++; 241719370Spst STABS_CONTINUE (pp, objfile); 241819370Spst } 241919370Spst while (**pp != ';' && **pp != '\0'); 242098944Sobrien 242119370Spst (*pp)++; 2422130803Smarcel STABS_CONTINUE (pp, objfile); 242398944Sobrien 2424130803Smarcel /* Skip GCC 3.X member functions which are duplicates of the callable 2425130803Smarcel constructor/destructor. */ 2426130803Smarcel if (strcmp (main_fn_name, "__base_ctor") == 0 2427130803Smarcel || strcmp (main_fn_name, "__base_dtor") == 0 2428130803Smarcel || strcmp (main_fn_name, "__deleting_dtor") == 0) 242919370Spst { 2430130803Smarcel xfree (main_fn_name); 243119370Spst } 2432130803Smarcel else 2433130803Smarcel { 2434130803Smarcel int has_stub = 0; 2435130803Smarcel int has_destructor = 0, has_other = 0; 2436130803Smarcel int is_v3 = 0; 2437130803Smarcel struct next_fnfield *tmp_sublist; 243898944Sobrien 2439130803Smarcel /* Various versions of GCC emit various mostly-useless 2440130803Smarcel strings in the name field for special member functions. 2441130803Smarcel 2442130803Smarcel For stub methods, we need to defer correcting the name 2443130803Smarcel until we are ready to unstub the method, because the current 2444130803Smarcel name string is used by gdb_mangle_name. The only stub methods 2445130803Smarcel of concern here are GNU v2 operators; other methods have their 2446130803Smarcel names correct (see caveat below). 2447130803Smarcel 2448130803Smarcel For non-stub methods, in GNU v3, we have a complete physname. 2449130803Smarcel Therefore we can safely correct the name now. This primarily 2450130803Smarcel affects constructors and destructors, whose name will be 2451130803Smarcel __comp_ctor or __comp_dtor instead of Foo or ~Foo. Cast 2452130803Smarcel operators will also have incorrect names; for instance, 2453130803Smarcel "operator int" will be named "operator i" (i.e. the type is 2454130803Smarcel mangled). 2455130803Smarcel 2456130803Smarcel For non-stub methods in GNU v2, we have no easy way to 2457130803Smarcel know if we have a complete physname or not. For most 2458130803Smarcel methods the result depends on the platform (if CPLUS_MARKER 2459130803Smarcel can be `$' or `.', it will use minimal debug information, or 2460130803Smarcel otherwise the full physname will be included). 2461130803Smarcel 2462130803Smarcel Rather than dealing with this, we take a different approach. 2463130803Smarcel For v3 mangled names, we can use the full physname; for v2, 2464130803Smarcel we use cplus_demangle_opname (which is actually v2 specific), 2465130803Smarcel because the only interesting names are all operators - once again 2466130803Smarcel barring the caveat below. Skip this process if any method in the 2467130803Smarcel group is a stub, to prevent our fouling up the workings of 2468130803Smarcel gdb_mangle_name. 2469130803Smarcel 2470130803Smarcel The caveat: GCC 2.95.x (and earlier?) put constructors and 2471130803Smarcel destructors in the same method group. We need to split this 2472130803Smarcel into two groups, because they should have different names. 2473130803Smarcel So for each method group we check whether it contains both 2474130803Smarcel routines whose physname appears to be a destructor (the physnames 2475130803Smarcel for and destructors are always provided, due to quirks in v2 2476130803Smarcel mangling) and routines whose physname does not appear to be a 2477130803Smarcel destructor. If so then we break up the list into two halves. 2478130803Smarcel Even if the constructors and destructors aren't in the same group 2479130803Smarcel the destructor will still lack the leading tilde, so that also 2480130803Smarcel needs to be fixed. 2481130803Smarcel 2482130803Smarcel So, to summarize what we expect and handle here: 2483130803Smarcel 2484130803Smarcel Given Given Real Real Action 2485130803Smarcel method name physname physname method name 2486130803Smarcel 2487130803Smarcel __opi [none] __opi__3Foo operator int opname 2488130803Smarcel [now or later] 2489130803Smarcel Foo _._3Foo _._3Foo ~Foo separate and 2490130803Smarcel rename 2491130803Smarcel operator i _ZN3FoocviEv _ZN3FoocviEv operator int demangle 2492130803Smarcel __comp_ctor _ZN3FooC1ERKS_ _ZN3FooC1ERKS_ Foo demangle 2493130803Smarcel */ 2494130803Smarcel 2495130803Smarcel tmp_sublist = sublist; 2496130803Smarcel while (tmp_sublist != NULL) 2497130803Smarcel { 2498130803Smarcel if (tmp_sublist->fn_field.is_stub) 2499130803Smarcel has_stub = 1; 2500130803Smarcel if (tmp_sublist->fn_field.physname[0] == '_' 2501130803Smarcel && tmp_sublist->fn_field.physname[1] == 'Z') 2502130803Smarcel is_v3 = 1; 2503130803Smarcel 2504130803Smarcel if (is_destructor_name (tmp_sublist->fn_field.physname)) 2505130803Smarcel has_destructor++; 2506130803Smarcel else 2507130803Smarcel has_other++; 2508130803Smarcel 2509130803Smarcel tmp_sublist = tmp_sublist->next; 2510130803Smarcel } 2511130803Smarcel 2512130803Smarcel if (has_destructor && has_other) 2513130803Smarcel { 2514130803Smarcel struct next_fnfieldlist *destr_fnlist; 2515130803Smarcel struct next_fnfield *last_sublist; 2516130803Smarcel 2517130803Smarcel /* Create a new fn_fieldlist for the destructors. */ 2518130803Smarcel 2519130803Smarcel destr_fnlist = (struct next_fnfieldlist *) 2520130803Smarcel xmalloc (sizeof (struct next_fnfieldlist)); 2521130803Smarcel make_cleanup (xfree, destr_fnlist); 2522130803Smarcel memset (destr_fnlist, 0, sizeof (struct next_fnfieldlist)); 2523130803Smarcel destr_fnlist->fn_fieldlist.name 2524130803Smarcel = obconcat (&objfile->objfile_obstack, "", "~", 2525130803Smarcel new_fnlist->fn_fieldlist.name); 2526130803Smarcel 2527130803Smarcel destr_fnlist->fn_fieldlist.fn_fields = (struct fn_field *) 2528130803Smarcel obstack_alloc (&objfile->objfile_obstack, 2529130803Smarcel sizeof (struct fn_field) * has_destructor); 2530130803Smarcel memset (destr_fnlist->fn_fieldlist.fn_fields, 0, 2531130803Smarcel sizeof (struct fn_field) * has_destructor); 2532130803Smarcel tmp_sublist = sublist; 2533130803Smarcel last_sublist = NULL; 2534130803Smarcel i = 0; 2535130803Smarcel while (tmp_sublist != NULL) 2536130803Smarcel { 2537130803Smarcel if (!is_destructor_name (tmp_sublist->fn_field.physname)) 2538130803Smarcel { 2539130803Smarcel tmp_sublist = tmp_sublist->next; 2540130803Smarcel continue; 2541130803Smarcel } 2542130803Smarcel 2543130803Smarcel destr_fnlist->fn_fieldlist.fn_fields[i++] 2544130803Smarcel = tmp_sublist->fn_field; 2545130803Smarcel if (last_sublist) 2546130803Smarcel last_sublist->next = tmp_sublist->next; 2547130803Smarcel else 2548130803Smarcel sublist = tmp_sublist->next; 2549130803Smarcel last_sublist = tmp_sublist; 2550130803Smarcel tmp_sublist = tmp_sublist->next; 2551130803Smarcel } 2552130803Smarcel 2553130803Smarcel destr_fnlist->fn_fieldlist.length = has_destructor; 2554130803Smarcel destr_fnlist->next = fip->fnlist; 2555130803Smarcel fip->fnlist = destr_fnlist; 2556130803Smarcel nfn_fields++; 2557130803Smarcel total_length += has_destructor; 2558130803Smarcel length -= has_destructor; 2559130803Smarcel } 2560130803Smarcel else if (is_v3) 2561130803Smarcel { 2562130803Smarcel /* v3 mangling prevents the use of abbreviated physnames, 2563130803Smarcel so we can do this here. There are stubbed methods in v3 2564130803Smarcel only: 2565130803Smarcel - in -gstabs instead of -gstabs+ 2566130803Smarcel - or for static methods, which are output as a function type 2567130803Smarcel instead of a method type. */ 2568130803Smarcel 2569130803Smarcel update_method_name_from_physname (&new_fnlist->fn_fieldlist.name, 2570130803Smarcel sublist->fn_field.physname); 2571130803Smarcel } 2572130803Smarcel else if (has_destructor && new_fnlist->fn_fieldlist.name[0] != '~') 2573130803Smarcel { 2574130803Smarcel new_fnlist->fn_fieldlist.name = concat ("~", main_fn_name, NULL); 2575130803Smarcel xfree (main_fn_name); 2576130803Smarcel } 2577130803Smarcel else if (!has_stub) 2578130803Smarcel { 2579130803Smarcel char dem_opname[256]; 2580130803Smarcel int ret; 2581130803Smarcel ret = cplus_demangle_opname (new_fnlist->fn_fieldlist.name, 2582130803Smarcel dem_opname, DMGL_ANSI); 2583130803Smarcel if (!ret) 2584130803Smarcel ret = cplus_demangle_opname (new_fnlist->fn_fieldlist.name, 2585130803Smarcel dem_opname, 0); 2586130803Smarcel if (ret) 2587130803Smarcel new_fnlist->fn_fieldlist.name 2588130803Smarcel = obsavestring (dem_opname, strlen (dem_opname), 2589130803Smarcel &objfile->objfile_obstack); 2590130803Smarcel } 2591130803Smarcel 2592130803Smarcel new_fnlist->fn_fieldlist.fn_fields = (struct fn_field *) 2593130803Smarcel obstack_alloc (&objfile->objfile_obstack, 2594130803Smarcel sizeof (struct fn_field) * length); 2595130803Smarcel memset (new_fnlist->fn_fieldlist.fn_fields, 0, 2596130803Smarcel sizeof (struct fn_field) * length); 2597130803Smarcel for (i = length; (i--, sublist); sublist = sublist->next) 2598130803Smarcel { 2599130803Smarcel new_fnlist->fn_fieldlist.fn_fields[i] = sublist->fn_field; 2600130803Smarcel } 2601130803Smarcel 2602130803Smarcel new_fnlist->fn_fieldlist.length = length; 2603130803Smarcel new_fnlist->next = fip->fnlist; 2604130803Smarcel fip->fnlist = new_fnlist; 2605130803Smarcel nfn_fields++; 2606130803Smarcel total_length += length; 2607130803Smarcel } 260819370Spst } 260919370Spst 261019370Spst if (nfn_fields) 261119370Spst { 261219370Spst ALLOCATE_CPLUS_STRUCT_TYPE (type); 261319370Spst TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *) 261419370Spst TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * nfn_fields); 261519370Spst memset (TYPE_FN_FIELDLISTS (type), 0, 261619370Spst sizeof (struct fn_fieldlist) * nfn_fields); 261719370Spst TYPE_NFN_FIELDS (type) = nfn_fields; 261819370Spst TYPE_NFN_FIELDS_TOTAL (type) = total_length; 261919370Spst } 262019370Spst 262119370Spst return 1; 262219370Spst} 262319370Spst 262419370Spst/* Special GNU C++ name. 262519370Spst 262619370Spst Returns 1 for success, 0 for failure. "failure" means that we can't 262719370Spst keep parsing and it's time for error_type(). */ 262819370Spst 262919370Spststatic int 263098944Sobrienread_cpp_abbrev (struct field_info *fip, char **pp, struct type *type, 263198944Sobrien struct objfile *objfile) 263219370Spst{ 2633130803Smarcel char *p; 263419370Spst char *name; 263519370Spst char cpp_abbrev; 263619370Spst struct type *context; 263719370Spst 263819370Spst p = *pp; 263919370Spst if (*++p == 'v') 264019370Spst { 264119370Spst name = NULL; 264219370Spst cpp_abbrev = *++p; 264319370Spst 264419370Spst *pp = p + 1; 264519370Spst 264619370Spst /* At this point, *pp points to something like "22:23=*22...", 264798944Sobrien where the type number before the ':' is the "context" and 264898944Sobrien everything after is a regular type definition. Lookup the 264998944Sobrien type, find it's name, and construct the field name. */ 265019370Spst 265119370Spst context = read_type (pp, objfile); 265219370Spst 265319370Spst switch (cpp_abbrev) 265419370Spst { 265598944Sobrien case 'f': /* $vf -- a virtual function table pointer */ 265698944Sobrien name = type_name_no_tag (context); 265798944Sobrien if (name == NULL) 265898944Sobrien { 265998944Sobrien name = ""; 266098944Sobrien } 266198944Sobrien fip->list->field.name = 2662130803Smarcel obconcat (&objfile->objfile_obstack, vptr_name, name, ""); 266398944Sobrien break; 266419370Spst 266598944Sobrien case 'b': /* $vb -- a virtual bsomethingorother */ 266698944Sobrien name = type_name_no_tag (context); 266798944Sobrien if (name == NULL) 266898944Sobrien { 2669130803Smarcel complaint (&symfile_complaints, 2670130803Smarcel "C++ abbreviated type name unknown at symtab pos %d", 2671130803Smarcel symnum); 267298944Sobrien name = "FOO"; 267398944Sobrien } 267498944Sobrien fip->list->field.name = 2675130803Smarcel obconcat (&objfile->objfile_obstack, vb_name, name, ""); 267698944Sobrien break; 267719370Spst 267898944Sobrien default: 2679130803Smarcel invalid_cpp_abbrev_complaint (*pp); 268098944Sobrien fip->list->field.name = 2681130803Smarcel obconcat (&objfile->objfile_obstack, 268298944Sobrien "INVALID_CPLUSPLUS_ABBREV", "", ""); 268398944Sobrien break; 268419370Spst } 268519370Spst 268619370Spst /* At this point, *pp points to the ':'. Skip it and read the 268798944Sobrien field type. */ 268819370Spst 268919370Spst p = ++(*pp); 269019370Spst if (p[-1] != ':') 269119370Spst { 2692130803Smarcel invalid_cpp_abbrev_complaint (*pp); 269319370Spst return 0; 269419370Spst } 269519370Spst fip->list->field.type = read_type (pp, objfile); 269619370Spst if (**pp == ',') 269798944Sobrien (*pp)++; /* Skip the comma. */ 269819370Spst else 269919370Spst return 0; 270019370Spst 270119370Spst { 270219370Spst int nbits; 270346283Sdfr FIELD_BITPOS (fip->list->field) = read_huge_number (pp, ';', &nbits); 270419370Spst if (nbits != 0) 270519370Spst return 0; 270619370Spst } 270719370Spst /* This field is unpacked. */ 270846283Sdfr FIELD_BITSIZE (fip->list->field) = 0; 270919370Spst fip->list->visibility = VISIBILITY_PRIVATE; 271019370Spst } 271119370Spst else 271219370Spst { 2713130803Smarcel invalid_cpp_abbrev_complaint (*pp); 271419370Spst /* We have no idea what syntax an unrecognized abbrev would have, so 271598944Sobrien better return 0. If we returned 1, we would need to at least advance 271698944Sobrien *pp to avoid an infinite loop. */ 271719370Spst return 0; 271819370Spst } 271919370Spst return 1; 272019370Spst} 272119370Spst 272219370Spststatic void 272398944Sobrienread_one_struct_field (struct field_info *fip, char **pp, char *p, 272498944Sobrien struct type *type, struct objfile *objfile) 272519370Spst{ 2726130803Smarcel fip->list->field.name = 2727130803Smarcel obsavestring (*pp, p - *pp, &objfile->objfile_obstack); 272819370Spst *pp = p + 1; 272919370Spst 273019370Spst /* This means we have a visibility for a field coming. */ 273119370Spst if (**pp == '/') 273219370Spst { 273319370Spst (*pp)++; 273498944Sobrien fip->list->visibility = *(*pp)++; 273519370Spst } 273619370Spst else 273719370Spst { 273819370Spst /* normal dbx-style format, no explicit visibility */ 273998944Sobrien fip->list->visibility = VISIBILITY_PUBLIC; 274019370Spst } 274119370Spst 274298944Sobrien fip->list->field.type = read_type (pp, objfile); 274319370Spst if (**pp == ':') 274419370Spst { 274519370Spst p = ++(*pp); 274619370Spst#if 0 274719370Spst /* Possible future hook for nested types. */ 274819370Spst if (**pp == '!') 274919370Spst { 275098944Sobrien fip->list->field.bitpos = (long) -2; /* nested type */ 275119370Spst p = ++(*pp); 275219370Spst } 275398944Sobrien else 275498944Sobrien ...; 275519370Spst#endif 275698944Sobrien while (*p != ';') 275719370Spst { 275819370Spst p++; 275919370Spst } 276046283Sdfr /* Static class member. */ 276146283Sdfr SET_FIELD_PHYSNAME (fip->list->field, savestring (*pp, p - *pp)); 276219370Spst *pp = p + 1; 276319370Spst return; 276419370Spst } 276519370Spst else if (**pp != ',') 276619370Spst { 276719370Spst /* Bad structure-type format. */ 2768130803Smarcel stabs_general_complaint ("bad structure-type format"); 276919370Spst return; 277019370Spst } 277119370Spst 277219370Spst (*pp)++; /* Skip the comma. */ 277319370Spst 277419370Spst { 277519370Spst int nbits; 277646283Sdfr FIELD_BITPOS (fip->list->field) = read_huge_number (pp, ',', &nbits); 277719370Spst if (nbits != 0) 277819370Spst { 2779130803Smarcel stabs_general_complaint ("bad structure-type format"); 278019370Spst return; 278119370Spst } 278246283Sdfr FIELD_BITSIZE (fip->list->field) = read_huge_number (pp, ';', &nbits); 278319370Spst if (nbits != 0) 278419370Spst { 2785130803Smarcel stabs_general_complaint ("bad structure-type format"); 278619370Spst return; 278719370Spst } 278819370Spst } 278919370Spst 279046283Sdfr if (FIELD_BITPOS (fip->list->field) == 0 279146283Sdfr && FIELD_BITSIZE (fip->list->field) == 0) 279219370Spst { 279319370Spst /* This can happen in two cases: (1) at least for gcc 2.4.5 or so, 279498944Sobrien it is a field which has been optimized out. The correct stab for 279598944Sobrien this case is to use VISIBILITY_IGNORE, but that is a recent 279698944Sobrien invention. (2) It is a 0-size array. For example 279798944Sobrien union { int num; char str[0]; } foo. Printing "<no value>" for 279898944Sobrien str in "p foo" is OK, since foo.str (and thus foo.str[3]) 279998944Sobrien will continue to work, and a 0-size array as a whole doesn't 280098944Sobrien have any contents to print. 280119370Spst 280298944Sobrien I suspect this probably could also happen with gcc -gstabs (not 280398944Sobrien -gstabs+) for static fields, and perhaps other C++ extensions. 280498944Sobrien Hopefully few people use -gstabs with gdb, since it is intended 280598944Sobrien for dbx compatibility. */ 280619370Spst 280719370Spst /* Ignore this field. */ 280898944Sobrien fip->list->visibility = VISIBILITY_IGNORE; 280919370Spst } 281019370Spst else 281119370Spst { 281219370Spst /* Detect an unpacked field and mark it as such. 281398944Sobrien dbx gives a bit size for all fields. 281498944Sobrien Note that forward refs cannot be packed, 281598944Sobrien and treat enums as if they had the width of ints. */ 281619370Spst 281746283Sdfr struct type *field_type = check_typedef (FIELD_TYPE (fip->list->field)); 281846283Sdfr 281946283Sdfr if (TYPE_CODE (field_type) != TYPE_CODE_INT 282046283Sdfr && TYPE_CODE (field_type) != TYPE_CODE_RANGE 282146283Sdfr && TYPE_CODE (field_type) != TYPE_CODE_BOOL 282246283Sdfr && TYPE_CODE (field_type) != TYPE_CODE_ENUM) 282319370Spst { 282446283Sdfr FIELD_BITSIZE (fip->list->field) = 0; 282519370Spst } 282698944Sobrien if ((FIELD_BITSIZE (fip->list->field) 282746283Sdfr == TARGET_CHAR_BIT * TYPE_LENGTH (field_type) 282846283Sdfr || (TYPE_CODE (field_type) == TYPE_CODE_ENUM 282998944Sobrien && FIELD_BITSIZE (fip->list->field) == TARGET_INT_BIT) 283098944Sobrien ) 283119370Spst && 283246283Sdfr FIELD_BITPOS (fip->list->field) % 8 == 0) 283319370Spst { 283446283Sdfr FIELD_BITSIZE (fip->list->field) = 0; 283519370Spst } 283619370Spst } 283719370Spst} 283819370Spst 283919370Spst 284019370Spst/* Read struct or class data fields. They have the form: 284119370Spst 284298944Sobrien NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ; 284319370Spst 284419370Spst At the end, we see a semicolon instead of a field. 284519370Spst 284619370Spst In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for 284719370Spst a static field. 284819370Spst 284919370Spst The optional VISIBILITY is one of: 285019370Spst 285198944Sobrien '/0' (VISIBILITY_PRIVATE) 285298944Sobrien '/1' (VISIBILITY_PROTECTED) 285398944Sobrien '/2' (VISIBILITY_PUBLIC) 285498944Sobrien '/9' (VISIBILITY_IGNORE) 285519370Spst 285619370Spst or nothing, for C style fields with public visibility. 285719370Spst 285819370Spst Returns 1 for success, 0 for failure. */ 285919370Spst 286019370Spststatic int 286198944Sobrienread_struct_fields (struct field_info *fip, char **pp, struct type *type, 286298944Sobrien struct objfile *objfile) 286319370Spst{ 2864130803Smarcel char *p; 286519370Spst struct nextfield *new; 286619370Spst 286719370Spst /* We better set p right now, in case there are no fields at all... */ 286819370Spst 286919370Spst p = *pp; 287019370Spst 287119370Spst /* Read each data member type until we find the terminating ';' at the end of 287219370Spst the data member list, or break for some other reason such as finding the 287319370Spst start of the member function list. */ 287498944Sobrien /* Stab string for structure/union does not end with two ';' in 287598944Sobrien SUN C compiler 5.3 i.e. F6U2, hence check for end of string. */ 287619370Spst 287798944Sobrien while (**pp != ';' && **pp != '\0') 287819370Spst { 287919370Spst STABS_CONTINUE (pp, objfile); 288019370Spst /* Get space to record the next field's data. */ 288119370Spst new = (struct nextfield *) xmalloc (sizeof (struct nextfield)); 288298944Sobrien make_cleanup (xfree, new); 288319370Spst memset (new, 0, sizeof (struct nextfield)); 288498944Sobrien new->next = fip->list; 288598944Sobrien fip->list = new; 288619370Spst 288719370Spst /* Get the field name. */ 288819370Spst p = *pp; 288919370Spst 289019370Spst /* If is starts with CPLUS_MARKER it is a special abbreviation, 289198944Sobrien unless the CPLUS_MARKER is followed by an underscore, in 289298944Sobrien which case it is just the name of an anonymous type, which we 289398944Sobrien should handle like any other type name. */ 289419370Spst 289519370Spst if (is_cplus_marker (p[0]) && p[1] != '_') 289619370Spst { 289719370Spst if (!read_cpp_abbrev (fip, pp, type, objfile)) 289819370Spst return 0; 289919370Spst continue; 290019370Spst } 290119370Spst 290219370Spst /* Look for the ':' that separates the field name from the field 290398944Sobrien values. Data members are delimited by a single ':', while member 290498944Sobrien functions are delimited by a pair of ':'s. When we hit the member 290598944Sobrien functions (if any), terminate scan loop and return. */ 290619370Spst 290798944Sobrien while (*p != ':' && *p != '\0') 290819370Spst { 290919370Spst p++; 291019370Spst } 291119370Spst if (*p == '\0') 291219370Spst return 0; 291319370Spst 291419370Spst /* Check to see if we have hit the member functions yet. */ 291519370Spst if (p[1] == ':') 291619370Spst { 291719370Spst break; 291819370Spst } 291919370Spst read_one_struct_field (fip, pp, p, type, objfile); 292019370Spst } 292119370Spst if (p[0] == ':' && p[1] == ':') 292219370Spst { 2923130803Smarcel /* (the deleted) chill the list of fields: the last entry (at 2924130803Smarcel the head) is a partially constructed entry which we now 2925130803Smarcel scrub. */ 292698944Sobrien fip->list = fip->list->next; 292719370Spst } 292819370Spst return 1; 292919370Spst} 293098944Sobrien/* *INDENT-OFF* */ 293119370Spst/* The stabs for C++ derived classes contain baseclass information which 293219370Spst is marked by a '!' character after the total size. This function is 293319370Spst called when we encounter the baseclass marker, and slurps up all the 293419370Spst baseclass information. 293519370Spst 293619370Spst Immediately following the '!' marker is the number of base classes that 293719370Spst the class is derived from, followed by information for each base class. 293819370Spst For each base class, there are two visibility specifiers, a bit offset 293919370Spst to the base class information within the derived class, a reference to 294019370Spst the type for the base class, and a terminating semicolon. 294119370Spst 294219370Spst A typical example, with two base classes, would be "!2,020,19;0264,21;". 294319370Spst ^^ ^ ^ ^ ^ ^ ^ 294419370Spst Baseclass information marker __________________|| | | | | | | 294519370Spst Number of baseclasses __________________________| | | | | | | 294619370Spst Visibility specifiers (2) ________________________| | | | | | 294719370Spst Offset in bits from start of class _________________| | | | | 294819370Spst Type number for base class ___________________________| | | | 294919370Spst Visibility specifiers (2) _______________________________| | | 295019370Spst Offset in bits from start of class ________________________| | 295119370Spst Type number of base class ____________________________________| 295219370Spst 295319370Spst Return 1 for success, 0 for (error-type-inducing) failure. */ 295498944Sobrien/* *INDENT-ON* */ 295519370Spst 295698944Sobrien 295798944Sobrien 295819370Spststatic int 295998944Sobrienread_baseclasses (struct field_info *fip, char **pp, struct type *type, 296098944Sobrien struct objfile *objfile) 296119370Spst{ 296219370Spst int i; 296319370Spst struct nextfield *new; 296419370Spst 296519370Spst if (**pp != '!') 296619370Spst { 296719370Spst return 1; 296819370Spst } 296919370Spst else 297019370Spst { 297119370Spst /* Skip the '!' baseclass information marker. */ 297219370Spst (*pp)++; 297319370Spst } 297419370Spst 297519370Spst ALLOCATE_CPLUS_STRUCT_TYPE (type); 297619370Spst { 297719370Spst int nbits; 297819370Spst TYPE_N_BASECLASSES (type) = read_huge_number (pp, ',', &nbits); 297919370Spst if (nbits != 0) 298019370Spst return 0; 298119370Spst } 298219370Spst 298319370Spst#if 0 298419370Spst /* Some stupid compilers have trouble with the following, so break 298519370Spst it up into simpler expressions. */ 298619370Spst TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *) 298719370Spst TYPE_ALLOC (type, B_BYTES (TYPE_N_BASECLASSES (type))); 298819370Spst#else 298919370Spst { 299019370Spst int num_bytes = B_BYTES (TYPE_N_BASECLASSES (type)); 299119370Spst char *pointer; 299219370Spst 299319370Spst pointer = (char *) TYPE_ALLOC (type, num_bytes); 299419370Spst TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *) pointer; 299519370Spst } 299619370Spst#endif /* 0 */ 299719370Spst 299819370Spst B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), TYPE_N_BASECLASSES (type)); 299919370Spst 300019370Spst for (i = 0; i < TYPE_N_BASECLASSES (type); i++) 300119370Spst { 300219370Spst new = (struct nextfield *) xmalloc (sizeof (struct nextfield)); 300398944Sobrien make_cleanup (xfree, new); 300419370Spst memset (new, 0, sizeof (struct nextfield)); 300598944Sobrien new->next = fip->list; 300698944Sobrien fip->list = new; 300746283Sdfr FIELD_BITSIZE (new->field) = 0; /* this should be an unpacked field! */ 300819370Spst 300919370Spst STABS_CONTINUE (pp, objfile); 301019370Spst switch (**pp) 301119370Spst { 301298944Sobrien case '0': 301398944Sobrien /* Nothing to do. */ 301498944Sobrien break; 301598944Sobrien case '1': 301698944Sobrien SET_TYPE_FIELD_VIRTUAL (type, i); 301798944Sobrien break; 301898944Sobrien default: 301998944Sobrien /* Unknown character. Complain and treat it as non-virtual. */ 302098944Sobrien { 3021130803Smarcel complaint (&symfile_complaints, 3022130803Smarcel "Unknown virtual character `%c' for baseclass", **pp); 302398944Sobrien } 302419370Spst } 302519370Spst ++(*pp); 302619370Spst 302798944Sobrien new->visibility = *(*pp)++; 302898944Sobrien switch (new->visibility) 302919370Spst { 303098944Sobrien case VISIBILITY_PRIVATE: 303198944Sobrien case VISIBILITY_PROTECTED: 303298944Sobrien case VISIBILITY_PUBLIC: 303398944Sobrien break; 303498944Sobrien default: 303598944Sobrien /* Bad visibility format. Complain and treat it as 303698944Sobrien public. */ 303798944Sobrien { 3038130803Smarcel complaint (&symfile_complaints, 3039130803Smarcel "Unknown visibility `%c' for baseclass", 3040130803Smarcel new->visibility); 304198944Sobrien new->visibility = VISIBILITY_PUBLIC; 304298944Sobrien } 304319370Spst } 304419370Spst 304519370Spst { 304619370Spst int nbits; 304798944Sobrien 304819370Spst /* The remaining value is the bit offset of the portion of the object 304919370Spst corresponding to this baseclass. Always zero in the absence of 305019370Spst multiple inheritance. */ 305119370Spst 305246283Sdfr FIELD_BITPOS (new->field) = read_huge_number (pp, ',', &nbits); 305319370Spst if (nbits != 0) 305419370Spst return 0; 305519370Spst } 305619370Spst 305719370Spst /* The last piece of baseclass information is the type of the 305898944Sobrien base class. Read it, and remember it's type name as this 305998944Sobrien field's name. */ 306019370Spst 306198944Sobrien new->field.type = read_type (pp, objfile); 306298944Sobrien new->field.name = type_name_no_tag (new->field.type); 306319370Spst 306419370Spst /* skip trailing ';' and bump count of number of fields seen */ 306519370Spst if (**pp == ';') 306619370Spst (*pp)++; 306719370Spst else 306819370Spst return 0; 306919370Spst } 307019370Spst return 1; 307119370Spst} 307219370Spst 307319370Spst/* The tail end of stabs for C++ classes that contain a virtual function 307419370Spst pointer contains a tilde, a %, and a type number. 307519370Spst The type number refers to the base class (possibly this class itself) which 307619370Spst contains the vtable pointer for the current class. 307719370Spst 307819370Spst This function is called when we have parsed all the method declarations, 307919370Spst so we can look for the vptr base class info. */ 308019370Spst 308119370Spststatic int 308298944Sobrienread_tilde_fields (struct field_info *fip, char **pp, struct type *type, 308398944Sobrien struct objfile *objfile) 308419370Spst{ 3085130803Smarcel char *p; 308619370Spst 308719370Spst STABS_CONTINUE (pp, objfile); 308819370Spst 308919370Spst /* If we are positioned at a ';', then skip it. */ 309019370Spst if (**pp == ';') 309119370Spst { 309219370Spst (*pp)++; 309319370Spst } 309419370Spst 309519370Spst if (**pp == '~') 309619370Spst { 309719370Spst (*pp)++; 309819370Spst 309919370Spst if (**pp == '=' || **pp == '+' || **pp == '-') 310019370Spst { 310119370Spst /* Obsolete flags that used to indicate the presence 310219370Spst of constructors and/or destructors. */ 310319370Spst (*pp)++; 310419370Spst } 310519370Spst 310619370Spst /* Read either a '%' or the final ';'. */ 310719370Spst if (*(*pp)++ == '%') 310819370Spst { 310919370Spst /* The next number is the type number of the base class 311019370Spst (possibly our own class) which supplies the vtable for 311119370Spst this class. Parse it out, and search that class to find 311219370Spst its vtable pointer, and install those into TYPE_VPTR_BASETYPE 311319370Spst and TYPE_VPTR_FIELDNO. */ 311419370Spst 311519370Spst struct type *t; 311619370Spst int i; 311719370Spst 311819370Spst t = read_type (pp, objfile); 311919370Spst p = (*pp)++; 312019370Spst while (*p != '\0' && *p != ';') 312119370Spst { 312219370Spst p++; 312319370Spst } 312419370Spst if (*p == '\0') 312519370Spst { 312619370Spst /* Premature end of symbol. */ 312719370Spst return 0; 312819370Spst } 312998944Sobrien 313019370Spst TYPE_VPTR_BASETYPE (type) = t; 313198944Sobrien if (type == t) /* Our own class provides vtbl ptr */ 313219370Spst { 313319370Spst for (i = TYPE_NFIELDS (t) - 1; 313419370Spst i >= TYPE_N_BASECLASSES (t); 313519370Spst --i) 313619370Spst { 3137130803Smarcel char *name = TYPE_FIELD_NAME (t, i); 3138130803Smarcel if (!strncmp (name, vptr_name, sizeof (vptr_name) - 2) 3139130803Smarcel && is_cplus_marker (name[sizeof (vptr_name) - 2])) 314019370Spst { 314119370Spst TYPE_VPTR_FIELDNO (type) = i; 314219370Spst goto gotit; 314319370Spst } 314419370Spst } 314519370Spst /* Virtual function table field not found. */ 3146130803Smarcel complaint (&symfile_complaints, 3147130803Smarcel "virtual function table pointer not found when defining class `%s'", 3148130803Smarcel TYPE_NAME (type)); 314919370Spst return 0; 315019370Spst } 315119370Spst else 315219370Spst { 315319370Spst TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t); 315419370Spst } 315519370Spst 315698944Sobrien gotit: 315719370Spst *pp = p + 1; 315819370Spst } 315919370Spst } 316019370Spst return 1; 316119370Spst} 316219370Spst 316319370Spststatic int 3164130803Smarcelattach_fn_fields_to_type (struct field_info *fip, struct type *type) 316519370Spst{ 3166130803Smarcel int n; 316719370Spst 316819370Spst for (n = TYPE_NFN_FIELDS (type); 316998944Sobrien fip->fnlist != NULL; 317098944Sobrien fip->fnlist = fip->fnlist->next) 317119370Spst { 317298944Sobrien --n; /* Circumvent Sun3 compiler bug */ 317398944Sobrien TYPE_FN_FIELDLISTS (type)[n] = fip->fnlist->fn_fieldlist; 317419370Spst } 317519370Spst return 1; 317619370Spst} 317719370Spst 317819370Spst/* Create the vector of fields, and record how big it is. 317919370Spst We need this info to record proper virtual function table information 318019370Spst for this class's virtual functions. */ 318119370Spst 318219370Spststatic int 3183130803Smarcelattach_fields_to_type (struct field_info *fip, struct type *type, 318498944Sobrien struct objfile *objfile) 318519370Spst{ 3186130803Smarcel int nfields = 0; 3187130803Smarcel int non_public_fields = 0; 3188130803Smarcel struct nextfield *scan; 318919370Spst 319019370Spst /* Count up the number of fields that we have, as well as taking note of 319119370Spst whether or not there are any non-public fields, which requires us to 319219370Spst allocate and build the private_field_bits and protected_field_bits 319319370Spst bitfields. */ 319419370Spst 319598944Sobrien for (scan = fip->list; scan != NULL; scan = scan->next) 319619370Spst { 319719370Spst nfields++; 319898944Sobrien if (scan->visibility != VISIBILITY_PUBLIC) 319919370Spst { 320019370Spst non_public_fields++; 320119370Spst } 320219370Spst } 320319370Spst 320419370Spst /* Now we know how many fields there are, and whether or not there are any 320519370Spst non-public fields. Record the field count, allocate space for the 320619370Spst array of fields, and create blank visibility bitfields if necessary. */ 320719370Spst 320819370Spst TYPE_NFIELDS (type) = nfields; 320919370Spst TYPE_FIELDS (type) = (struct field *) 321019370Spst TYPE_ALLOC (type, sizeof (struct field) * nfields); 321119370Spst memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields); 321219370Spst 321319370Spst if (non_public_fields) 321419370Spst { 321519370Spst ALLOCATE_CPLUS_STRUCT_TYPE (type); 321619370Spst 321719370Spst TYPE_FIELD_PRIVATE_BITS (type) = 321819370Spst (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); 321919370Spst B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields); 322019370Spst 322119370Spst TYPE_FIELD_PROTECTED_BITS (type) = 322219370Spst (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); 322319370Spst B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields); 322419370Spst 322519370Spst TYPE_FIELD_IGNORE_BITS (type) = 322619370Spst (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); 322719370Spst B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields); 322819370Spst } 322919370Spst 323019370Spst /* Copy the saved-up fields into the field vector. Start from the head 323119370Spst of the list, adding to the tail of the field array, so that they end 323219370Spst up in the same order in the array in which they were added to the list. */ 323319370Spst 323419370Spst while (nfields-- > 0) 323519370Spst { 323698944Sobrien TYPE_FIELD (type, nfields) = fip->list->field; 323798944Sobrien switch (fip->list->visibility) 323819370Spst { 323998944Sobrien case VISIBILITY_PRIVATE: 324098944Sobrien SET_TYPE_FIELD_PRIVATE (type, nfields); 324198944Sobrien break; 324219370Spst 324398944Sobrien case VISIBILITY_PROTECTED: 324498944Sobrien SET_TYPE_FIELD_PROTECTED (type, nfields); 324598944Sobrien break; 324619370Spst 324798944Sobrien case VISIBILITY_IGNORE: 324898944Sobrien SET_TYPE_FIELD_IGNORE (type, nfields); 324998944Sobrien break; 325019370Spst 325198944Sobrien case VISIBILITY_PUBLIC: 325298944Sobrien break; 325319370Spst 325498944Sobrien default: 325598944Sobrien /* Unknown visibility. Complain and treat it as public. */ 325698944Sobrien { 3257130803Smarcel complaint (&symfile_complaints, "Unknown visibility `%c' for field", 3258130803Smarcel fip->list->visibility); 325998944Sobrien } 326098944Sobrien break; 326119370Spst } 326298944Sobrien fip->list = fip->list->next; 326319370Spst } 326419370Spst return 1; 326519370Spst} 326619370Spst 3267130803Smarcel 3268130803Smarcel/* Complain that the compiler has emitted more than one definition for the 3269130803Smarcel structure type TYPE. */ 3270130803Smarcelstatic void 3271130803Smarcelcomplain_about_struct_wipeout (struct type *type) 3272130803Smarcel{ 3273130803Smarcel char *name = ""; 3274130803Smarcel char *kind = ""; 3275130803Smarcel 3276130803Smarcel if (TYPE_TAG_NAME (type)) 3277130803Smarcel { 3278130803Smarcel name = TYPE_TAG_NAME (type); 3279130803Smarcel switch (TYPE_CODE (type)) 3280130803Smarcel { 3281130803Smarcel case TYPE_CODE_STRUCT: kind = "struct "; break; 3282130803Smarcel case TYPE_CODE_UNION: kind = "union "; break; 3283130803Smarcel case TYPE_CODE_ENUM: kind = "enum "; break; 3284130803Smarcel default: kind = ""; 3285130803Smarcel } 3286130803Smarcel } 3287130803Smarcel else if (TYPE_NAME (type)) 3288130803Smarcel { 3289130803Smarcel name = TYPE_NAME (type); 3290130803Smarcel kind = ""; 3291130803Smarcel } 3292130803Smarcel else 3293130803Smarcel { 3294130803Smarcel name = "<unknown>"; 3295130803Smarcel kind = ""; 3296130803Smarcel } 3297130803Smarcel 3298130803Smarcel complaint (&symfile_complaints, 3299130803Smarcel "struct/union type gets multiply defined: %s%s", kind, name); 3300130803Smarcel} 3301130803Smarcel 3302130803Smarcel 330319370Spst/* Read the description of a structure (or union type) and return an object 330419370Spst describing the type. 330519370Spst 330619370Spst PP points to a character pointer that points to the next unconsumed token 330719370Spst in the the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;", 330819370Spst *PP will point to "4a:1,0,32;;". 330919370Spst 331019370Spst TYPE points to an incomplete type that needs to be filled in. 331119370Spst 331219370Spst OBJFILE points to the current objfile from which the stabs information is 331319370Spst being read. (Note that it is redundant in that TYPE also contains a pointer 331419370Spst to this same objfile, so it might be a good idea to eliminate it. FIXME). 331598944Sobrien */ 331619370Spst 331719370Spststatic struct type * 3318130803Smarcelread_struct_type (char **pp, struct type *type, enum type_code type_code, 3319130803Smarcel struct objfile *objfile) 332019370Spst{ 332119370Spst struct cleanup *back_to; 332219370Spst struct field_info fi; 332319370Spst 332419370Spst fi.list = NULL; 332519370Spst fi.fnlist = NULL; 332619370Spst 3327130803Smarcel /* When describing struct/union/class types in stabs, G++ always drops 3328130803Smarcel all qualifications from the name. So if you've got: 3329130803Smarcel struct A { ... struct B { ... }; ... }; 3330130803Smarcel then G++ will emit stabs for `struct A::B' that call it simply 3331130803Smarcel `struct B'. Obviously, if you've got a real top-level definition for 3332130803Smarcel `struct B', or other nested definitions, this is going to cause 3333130803Smarcel problems. 3334130803Smarcel 3335130803Smarcel Obviously, GDB can't fix this by itself, but it can at least avoid 3336130803Smarcel scribbling on existing structure type objects when new definitions 3337130803Smarcel appear. */ 3338130803Smarcel if (! (TYPE_CODE (type) == TYPE_CODE_UNDEF 3339130803Smarcel || TYPE_STUB (type))) 3340130803Smarcel { 3341130803Smarcel complain_about_struct_wipeout (type); 3342130803Smarcel 3343130803Smarcel /* It's probably best to return the type unchanged. */ 3344130803Smarcel return type; 3345130803Smarcel } 3346130803Smarcel 334719370Spst back_to = make_cleanup (null_cleanup, 0); 334819370Spst 334919370Spst INIT_CPLUS_SPECIFIC (type); 3350130803Smarcel TYPE_CODE (type) = type_code; 335119370Spst TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB; 335219370Spst 335319370Spst /* First comes the total size in bytes. */ 335419370Spst 335519370Spst { 335619370Spst int nbits; 335719370Spst TYPE_LENGTH (type) = read_huge_number (pp, 0, &nbits); 335819370Spst if (nbits != 0) 335919370Spst return error_type (pp, objfile); 336019370Spst } 336119370Spst 336219370Spst /* Now read the baseclasses, if any, read the regular C struct or C++ 336319370Spst class member fields, attach the fields to the type, read the C++ 336419370Spst member functions, attach them to the type, and then read any tilde 336519370Spst field (baseclass specifier for the class holding the main vtable). */ 336619370Spst 336719370Spst if (!read_baseclasses (&fi, pp, type, objfile) 336819370Spst || !read_struct_fields (&fi, pp, type, objfile) 336919370Spst || !attach_fields_to_type (&fi, type, objfile) 337019370Spst || !read_member_functions (&fi, pp, type, objfile) 337119370Spst || !attach_fn_fields_to_type (&fi, type) 337219370Spst || !read_tilde_fields (&fi, pp, type, objfile)) 337319370Spst { 337419370Spst type = error_type (pp, objfile); 337519370Spst } 337619370Spst 337719370Spst do_cleanups (back_to); 337819370Spst return (type); 337919370Spst} 338019370Spst 338119370Spst/* Read a definition of an array type, 338219370Spst and create and return a suitable type object. 338319370Spst Also creates a range type which represents the bounds of that 338419370Spst array. */ 338519370Spst 338619370Spststatic struct type * 3387130803Smarcelread_array_type (char **pp, struct type *type, 338898944Sobrien struct objfile *objfile) 338919370Spst{ 339019370Spst struct type *index_type, *element_type, *range_type; 339119370Spst int lower, upper; 339219370Spst int adjustable = 0; 339319370Spst int nbits; 339419370Spst 339519370Spst /* Format of an array type: 339619370Spst "ar<index type>;lower;upper;<array_contents_type>". 339719370Spst OS9000: "arlower,upper;<array_contents_type>". 339819370Spst 339919370Spst Fortran adjustable arrays use Adigits or Tdigits for lower or upper; 340019370Spst for these, produce a type like float[][]. */ 340119370Spst 340219370Spst { 340319370Spst index_type = read_type (pp, objfile); 340419370Spst if (**pp != ';') 340519370Spst /* Improper format of array type decl. */ 340619370Spst return error_type (pp, objfile); 340719370Spst ++*pp; 340819370Spst } 340919370Spst 341019370Spst if (!(**pp >= '0' && **pp <= '9') && **pp != '-') 341119370Spst { 341219370Spst (*pp)++; 341319370Spst adjustable = 1; 341419370Spst } 3415130803Smarcel lower = read_huge_number (pp, ';', &nbits); 3416130803Smarcel 341719370Spst if (nbits != 0) 341819370Spst return error_type (pp, objfile); 341919370Spst 342019370Spst if (!(**pp >= '0' && **pp <= '9') && **pp != '-') 342119370Spst { 342219370Spst (*pp)++; 342319370Spst adjustable = 1; 342419370Spst } 342519370Spst upper = read_huge_number (pp, ';', &nbits); 342619370Spst if (nbits != 0) 342719370Spst return error_type (pp, objfile); 342898944Sobrien 342919370Spst element_type = read_type (pp, objfile); 343019370Spst 343119370Spst if (adjustable) 343219370Spst { 343319370Spst lower = 0; 343419370Spst upper = -1; 343519370Spst } 343619370Spst 343719370Spst range_type = 343819370Spst create_range_type ((struct type *) NULL, index_type, lower, upper); 343919370Spst type = create_array_type (type, element_type, range_type); 344019370Spst 344119370Spst return type; 344219370Spst} 344319370Spst 344419370Spst 344519370Spst/* Read a definition of an enumeration type, 344619370Spst and create and return a suitable type object. 344719370Spst Also defines the symbols that represent the values of the type. */ 344819370Spst 344919370Spststatic struct type * 3450130803Smarcelread_enum_type (char **pp, struct type *type, 345198944Sobrien struct objfile *objfile) 345219370Spst{ 3453130803Smarcel char *p; 345419370Spst char *name; 3455130803Smarcel long n; 3456130803Smarcel struct symbol *sym; 345719370Spst int nsyms = 0; 345819370Spst struct pending **symlist; 345919370Spst struct pending *osyms, *syms; 346019370Spst int o_nsyms; 346119370Spst int nbits; 346219370Spst int unsigned_enum = 1; 346319370Spst 346419370Spst#if 0 346519370Spst /* FIXME! The stabs produced by Sun CC merrily define things that ought 346619370Spst to be file-scope, between N_FN entries, using N_LSYM. What's a mother 346719370Spst to do? For now, force all enum values to file scope. */ 346819370Spst if (within_function) 346919370Spst symlist = &local_symbols; 347019370Spst else 347119370Spst#endif 347219370Spst symlist = &file_symbols; 347319370Spst osyms = *symlist; 347419370Spst o_nsyms = osyms ? osyms->nsyms : 0; 347519370Spst 347619370Spst /* The aix4 compiler emits an extra field before the enum members; 347719370Spst my guess is it's a type of some sort. Just ignore it. */ 347819370Spst if (**pp == '-') 347919370Spst { 348019370Spst /* Skip over the type. */ 348119370Spst while (**pp != ':') 348298944Sobrien (*pp)++; 348319370Spst 348419370Spst /* Skip over the colon. */ 348519370Spst (*pp)++; 348619370Spst } 348719370Spst 348819370Spst /* Read the value-names and their values. 348919370Spst The input syntax is NAME:VALUE,NAME:VALUE, and so on. 349019370Spst A semicolon or comma instead of a NAME means the end. */ 349119370Spst while (**pp && **pp != ';' && **pp != ',') 349219370Spst { 349319370Spst STABS_CONTINUE (pp, objfile); 349419370Spst p = *pp; 349598944Sobrien while (*p != ':') 349698944Sobrien p++; 3497130803Smarcel name = obsavestring (*pp, p - *pp, &objfile->objfile_obstack); 349819370Spst *pp = p + 1; 349919370Spst n = read_huge_number (pp, ',', &nbits); 350019370Spst if (nbits != 0) 350119370Spst return error_type (pp, objfile); 350219370Spst 350319370Spst sym = (struct symbol *) 3504130803Smarcel obstack_alloc (&objfile->objfile_obstack, sizeof (struct symbol)); 350519370Spst memset (sym, 0, sizeof (struct symbol)); 3506130803Smarcel DEPRECATED_SYMBOL_NAME (sym) = name; 350798944Sobrien SYMBOL_LANGUAGE (sym) = current_subfile->language; 350819370Spst SYMBOL_CLASS (sym) = LOC_CONST; 3509130803Smarcel SYMBOL_DOMAIN (sym) = VAR_DOMAIN; 351019370Spst SYMBOL_VALUE (sym) = n; 351119370Spst if (n < 0) 351219370Spst unsigned_enum = 0; 351319370Spst add_symbol_to_list (sym, symlist); 351419370Spst nsyms++; 351519370Spst } 351619370Spst 351719370Spst if (**pp == ';') 351819370Spst (*pp)++; /* Skip the semicolon. */ 351919370Spst 352019370Spst /* Now fill in the fields of the type-structure. */ 352119370Spst 352219370Spst TYPE_LENGTH (type) = TARGET_INT_BIT / HOST_CHAR_BIT; 352319370Spst TYPE_CODE (type) = TYPE_CODE_ENUM; 352419370Spst TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB; 352519370Spst if (unsigned_enum) 352619370Spst TYPE_FLAGS (type) |= TYPE_FLAG_UNSIGNED; 352719370Spst TYPE_NFIELDS (type) = nsyms; 352819370Spst TYPE_FIELDS (type) = (struct field *) 352919370Spst TYPE_ALLOC (type, sizeof (struct field) * nsyms); 353019370Spst memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nsyms); 353119370Spst 353219370Spst /* Find the symbols for the values and put them into the type. 353319370Spst The symbols can be found in the symlist that we put them on 353419370Spst to cause them to be defined. osyms contains the old value 353519370Spst of that symlist; everything up to there was defined by us. */ 353619370Spst /* Note that we preserve the order of the enum constants, so 353719370Spst that in something like "enum {FOO, LAST_THING=FOO}" we print 353819370Spst FOO, not LAST_THING. */ 353919370Spst 354019370Spst for (syms = *symlist, n = nsyms - 1; syms; syms = syms->next) 354119370Spst { 354219370Spst int last = syms == osyms ? o_nsyms : 0; 354319370Spst int j = syms->nsyms; 354419370Spst for (; --j >= last; --n) 354519370Spst { 354619370Spst struct symbol *xsym = syms->symbol[j]; 354719370Spst SYMBOL_TYPE (xsym) = type; 3548130803Smarcel TYPE_FIELD_NAME (type, n) = DEPRECATED_SYMBOL_NAME (xsym); 354919370Spst TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (xsym); 355019370Spst TYPE_FIELD_BITSIZE (type, n) = 0; 355119370Spst } 355219370Spst if (syms == osyms) 355319370Spst break; 355419370Spst } 355519370Spst 355619370Spst return type; 355719370Spst} 355819370Spst 355919370Spst/* Sun's ACC uses a somewhat saner method for specifying the builtin 356019370Spst typedefs in every file (for int, long, etc): 356119370Spst 356298944Sobrien type = b <signed> <width> <format type>; <offset>; <nbits> 356398944Sobrien signed = u or s. 356498944Sobrien optional format type = c or b for char or boolean. 356598944Sobrien offset = offset from high order bit to start bit of type. 356698944Sobrien width is # bytes in object of this type, nbits is # bits in type. 356719370Spst 356819370Spst The width/offset stuff appears to be for small objects stored in 356919370Spst larger ones (e.g. `shorts' in `int' registers). We ignore it for now, 357019370Spst FIXME. */ 357119370Spst 357219370Spststatic struct type * 357398944Sobrienread_sun_builtin_type (char **pp, int typenums[2], struct objfile *objfile) 357419370Spst{ 357519370Spst int type_bits; 357619370Spst int nbits; 357719370Spst int signed_type; 357846283Sdfr enum type_code code = TYPE_CODE_INT; 357919370Spst 358019370Spst switch (**pp) 358119370Spst { 358298944Sobrien case 's': 358398944Sobrien signed_type = 1; 358498944Sobrien break; 358598944Sobrien case 'u': 358698944Sobrien signed_type = 0; 358798944Sobrien break; 358898944Sobrien default: 358998944Sobrien return error_type (pp, objfile); 359019370Spst } 359119370Spst (*pp)++; 359219370Spst 359319370Spst /* For some odd reason, all forms of char put a c here. This is strange 359419370Spst because no other type has this honor. We can safely ignore this because 359519370Spst we actually determine 'char'acterness by the number of bits specified in 359646283Sdfr the descriptor. 359746283Sdfr Boolean forms, e.g Fortran logical*X, put a b here. */ 359819370Spst 359919370Spst if (**pp == 'c') 360019370Spst (*pp)++; 360146283Sdfr else if (**pp == 'b') 360246283Sdfr { 360346283Sdfr code = TYPE_CODE_BOOL; 360446283Sdfr (*pp)++; 360546283Sdfr } 360619370Spst 360719370Spst /* The first number appears to be the number of bytes occupied 360819370Spst by this type, except that unsigned short is 4 instead of 2. 360919370Spst Since this information is redundant with the third number, 361019370Spst we will ignore it. */ 361119370Spst read_huge_number (pp, ';', &nbits); 361219370Spst if (nbits != 0) 361319370Spst return error_type (pp, objfile); 361419370Spst 361519370Spst /* The second number is always 0, so ignore it too. */ 361619370Spst read_huge_number (pp, ';', &nbits); 361719370Spst if (nbits != 0) 361819370Spst return error_type (pp, objfile); 361919370Spst 362019370Spst /* The third number is the number of bits for this type. */ 362119370Spst type_bits = read_huge_number (pp, 0, &nbits); 362219370Spst if (nbits != 0) 362319370Spst return error_type (pp, objfile); 362419370Spst /* The type *should* end with a semicolon. If it are embedded 362519370Spst in a larger type the semicolon may be the only way to know where 362619370Spst the type ends. If this type is at the end of the stabstring we 362719370Spst can deal with the omitted semicolon (but we don't have to like 362819370Spst it). Don't bother to complain(), Sun's compiler omits the semicolon 362919370Spst for "void". */ 363019370Spst if (**pp == ';') 363119370Spst ++(*pp); 363219370Spst 363319370Spst if (type_bits == 0) 363419370Spst return init_type (TYPE_CODE_VOID, 1, 363598944Sobrien signed_type ? 0 : TYPE_FLAG_UNSIGNED, (char *) NULL, 363619370Spst objfile); 363719370Spst else 363846283Sdfr return init_type (code, 363919370Spst type_bits / TARGET_CHAR_BIT, 364098944Sobrien signed_type ? 0 : TYPE_FLAG_UNSIGNED, (char *) NULL, 364119370Spst objfile); 364219370Spst} 364319370Spst 364419370Spststatic struct type * 364598944Sobrienread_sun_floating_type (char **pp, int typenums[2], struct objfile *objfile) 364619370Spst{ 364719370Spst int nbits; 364819370Spst int details; 364919370Spst int nbytes; 3650130803Smarcel struct type *rettype; 365119370Spst 365219370Spst /* The first number has more details about the type, for example 365319370Spst FN_COMPLEX. */ 365419370Spst details = read_huge_number (pp, ';', &nbits); 365519370Spst if (nbits != 0) 365619370Spst return error_type (pp, objfile); 365719370Spst 365819370Spst /* The second number is the number of bytes occupied by this type */ 365919370Spst nbytes = read_huge_number (pp, ';', &nbits); 366019370Spst if (nbits != 0) 366119370Spst return error_type (pp, objfile); 366219370Spst 366319370Spst if (details == NF_COMPLEX || details == NF_COMPLEX16 366419370Spst || details == NF_COMPLEX32) 3665130803Smarcel { 3666130803Smarcel rettype = init_type (TYPE_CODE_COMPLEX, nbytes, 0, NULL, objfile); 3667130803Smarcel TYPE_TARGET_TYPE (rettype) 3668130803Smarcel = init_type (TYPE_CODE_FLT, nbytes / 2, 0, NULL, objfile); 3669130803Smarcel return rettype; 3670130803Smarcel } 367119370Spst 367219370Spst return init_type (TYPE_CODE_FLT, nbytes, 0, NULL, objfile); 367319370Spst} 367419370Spst 367519370Spst/* Read a number from the string pointed to by *PP. 367619370Spst The value of *PP is advanced over the number. 367719370Spst If END is nonzero, the character that ends the 367819370Spst number must match END, or an error happens; 367919370Spst and that character is skipped if it does match. 368019370Spst If END is zero, *PP is left pointing to that character. 368119370Spst 368219370Spst If the number fits in a long, set *BITS to 0 and return the value. 368319370Spst If not, set *BITS to be the number of bits in the number and return 0. 368419370Spst 368519370Spst If encounter garbage, set *BITS to -1 and return 0. */ 368619370Spst 368719370Spststatic long 368898944Sobrienread_huge_number (char **pp, int end, int *bits) 368919370Spst{ 369019370Spst char *p = *pp; 369119370Spst int sign = 1; 369219370Spst long n = 0; 369319370Spst int radix = 10; 369419370Spst char overflow = 0; 369519370Spst int nbits = 0; 369619370Spst int c; 369719370Spst long upper_limit; 369898944Sobrien 369919370Spst if (*p == '-') 370019370Spst { 370119370Spst sign = -1; 370219370Spst p++; 370319370Spst } 370419370Spst 370519370Spst /* Leading zero means octal. GCC uses this to output values larger 370619370Spst than an int (because that would be hard in decimal). */ 370719370Spst if (*p == '0') 370819370Spst { 370919370Spst radix = 8; 371019370Spst p++; 371119370Spst } 371219370Spst 3713130803Smarcel upper_limit = LONG_MAX / radix; 371419370Spst 371519370Spst while ((c = *p++) >= '0' && c < ('0' + radix)) 371619370Spst { 371719370Spst if (n <= upper_limit) 371819370Spst { 371919370Spst n *= radix; 372019370Spst n += c - '0'; /* FIXME this overflows anyway */ 372119370Spst } 372219370Spst else 372319370Spst overflow = 1; 372498944Sobrien 372519370Spst /* This depends on large values being output in octal, which is 372698944Sobrien what GCC does. */ 372719370Spst if (radix == 8) 372819370Spst { 372919370Spst if (nbits == 0) 373019370Spst { 373119370Spst if (c == '0') 373219370Spst /* Ignore leading zeroes. */ 373319370Spst ; 373419370Spst else if (c == '1') 373519370Spst nbits = 1; 373619370Spst else if (c == '2' || c == '3') 373719370Spst nbits = 2; 373819370Spst else 373919370Spst nbits = 3; 374019370Spst } 374119370Spst else 374219370Spst nbits += 3; 374319370Spst } 374419370Spst } 374519370Spst if (end) 374619370Spst { 374719370Spst if (c && c != end) 374819370Spst { 374919370Spst if (bits != NULL) 375019370Spst *bits = -1; 375119370Spst return 0; 375219370Spst } 375319370Spst } 375419370Spst else 375519370Spst --p; 375619370Spst 375719370Spst *pp = p; 375819370Spst if (overflow) 375919370Spst { 376019370Spst if (nbits == 0) 376119370Spst { 376219370Spst /* Large decimal constants are an error (because it is hard to 376319370Spst count how many bits are in them). */ 376419370Spst if (bits != NULL) 376519370Spst *bits = -1; 376619370Spst return 0; 376719370Spst } 376898944Sobrien 376919370Spst /* -0x7f is the same as 0x80. So deal with it by adding one to 377098944Sobrien the number of bits. */ 377119370Spst if (sign == -1) 377219370Spst ++nbits; 377319370Spst if (bits) 377419370Spst *bits = nbits; 377519370Spst } 377619370Spst else 377719370Spst { 377819370Spst if (bits) 377919370Spst *bits = 0; 378019370Spst return n * sign; 378119370Spst } 378219370Spst /* It's *BITS which has the interesting information. */ 378319370Spst return 0; 378419370Spst} 378519370Spst 378619370Spststatic struct type * 378798944Sobrienread_range_type (char **pp, int typenums[2], struct objfile *objfile) 378819370Spst{ 378919370Spst char *orig_pp = *pp; 379019370Spst int rangenums[2]; 379119370Spst long n2, n3; 379219370Spst int n2bits, n3bits; 379319370Spst int self_subrange; 379419370Spst struct type *result_type; 379519370Spst struct type *index_type = NULL; 379619370Spst 379719370Spst /* First comes a type we are a subrange of. 379819370Spst In C it is usually 0, 1 or the type being defined. */ 379919370Spst if (read_type_number (pp, rangenums) != 0) 380019370Spst return error_type (pp, objfile); 380119370Spst self_subrange = (rangenums[0] == typenums[0] && 380219370Spst rangenums[1] == typenums[1]); 380319370Spst 380419370Spst if (**pp == '=') 380519370Spst { 380619370Spst *pp = orig_pp; 380719370Spst index_type = read_type (pp, objfile); 380819370Spst } 380919370Spst 381019370Spst /* A semicolon should now follow; skip it. */ 381119370Spst if (**pp == ';') 381219370Spst (*pp)++; 381319370Spst 381419370Spst /* The remaining two operands are usually lower and upper bounds 381519370Spst of the range. But in some special cases they mean something else. */ 381619370Spst n2 = read_huge_number (pp, ';', &n2bits); 381719370Spst n3 = read_huge_number (pp, ';', &n3bits); 381819370Spst 381919370Spst if (n2bits == -1 || n3bits == -1) 382019370Spst return error_type (pp, objfile); 382119370Spst 382219370Spst if (index_type) 382319370Spst goto handle_true_range; 382419370Spst 382519370Spst /* If limits are huge, must be large integral type. */ 382619370Spst if (n2bits != 0 || n3bits != 0) 382719370Spst { 382819370Spst char got_signed = 0; 382919370Spst char got_unsigned = 0; 383019370Spst /* Number of bits in the type. */ 383119370Spst int nbits = 0; 383219370Spst 383319370Spst /* Range from 0 to <large number> is an unsigned large integral type. */ 383419370Spst if ((n2bits == 0 && n2 == 0) && n3bits != 0) 383519370Spst { 383619370Spst got_unsigned = 1; 383719370Spst nbits = n3bits; 383819370Spst } 383919370Spst /* Range from <large number> to <large number>-1 is a large signed 384098944Sobrien integral type. Take care of the case where <large number> doesn't 384198944Sobrien fit in a long but <large number>-1 does. */ 384219370Spst else if ((n2bits != 0 && n3bits != 0 && n2bits == n3bits + 1) 384319370Spst || (n2bits != 0 && n3bits == 0 384419370Spst && (n2bits == sizeof (long) * HOST_CHAR_BIT) 384519370Spst && n3 == LONG_MAX)) 384619370Spst { 384719370Spst got_signed = 1; 384819370Spst nbits = n2bits; 384919370Spst } 385019370Spst 385119370Spst if (got_signed || got_unsigned) 385219370Spst { 385319370Spst return init_type (TYPE_CODE_INT, nbits / TARGET_CHAR_BIT, 385419370Spst got_unsigned ? TYPE_FLAG_UNSIGNED : 0, NULL, 385519370Spst objfile); 385619370Spst } 385719370Spst else 385819370Spst return error_type (pp, objfile); 385919370Spst } 386019370Spst 386119370Spst /* A type defined as a subrange of itself, with bounds both 0, is void. */ 386219370Spst if (self_subrange && n2 == 0 && n3 == 0) 386319370Spst return init_type (TYPE_CODE_VOID, 1, 0, NULL, objfile); 386419370Spst 386546283Sdfr /* If n3 is zero and n2 is positive, we want a floating type, and n2 386646283Sdfr is the width in bytes. 386719370Spst 386846283Sdfr Fortran programs appear to use this for complex types also. To 386946283Sdfr distinguish between floats and complex, g77 (and others?) seem 387046283Sdfr to use self-subranges for the complexes, and subranges of int for 387146283Sdfr the floats. 387219370Spst 387346283Sdfr Also note that for complexes, g77 sets n2 to the size of one of 387446283Sdfr the member floats, not the whole complex beast. My guess is that 387546283Sdfr this was to work well with pre-COMPLEX versions of gdb. */ 387619370Spst 387719370Spst if (n3 == 0 && n2 > 0) 387819370Spst { 387998944Sobrien struct type *float_type 388098944Sobrien = init_type (TYPE_CODE_FLT, n2, 0, NULL, objfile); 388198944Sobrien 388246283Sdfr if (self_subrange) 388346283Sdfr { 388498944Sobrien struct type *complex_type = 388598944Sobrien init_type (TYPE_CODE_COMPLEX, 2 * n2, 0, NULL, objfile); 388698944Sobrien TYPE_TARGET_TYPE (complex_type) = float_type; 388798944Sobrien return complex_type; 388846283Sdfr } 388946283Sdfr else 389098944Sobrien return float_type; 389119370Spst } 389219370Spst 389319370Spst /* If the upper bound is -1, it must really be an unsigned int. */ 389419370Spst 389519370Spst else if (n2 == 0 && n3 == -1) 389619370Spst { 389719370Spst /* It is unsigned int or unsigned long. */ 389819370Spst /* GCC 2.3.3 uses this for long long too, but that is just a GDB 3.5 389998944Sobrien compatibility hack. */ 390019370Spst return init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT, 390119370Spst TYPE_FLAG_UNSIGNED, NULL, objfile); 390219370Spst } 390319370Spst 390419370Spst /* Special case: char is defined (Who knows why) as a subrange of 390519370Spst itself with range 0-127. */ 390619370Spst else if (self_subrange && n2 == 0 && n3 == 127) 3907130803Smarcel return init_type (TYPE_CODE_INT, 1, TYPE_FLAG_NOSIGN, NULL, objfile); 390819370Spst 390919370Spst /* We used to do this only for subrange of self or subrange of int. */ 391019370Spst else if (n2 == 0) 391119370Spst { 391298944Sobrien /* -1 is used for the upper bound of (4 byte) "unsigned int" and 391398944Sobrien "unsigned long", and we already checked for that, 391498944Sobrien so don't need to test for it here. */ 391598944Sobrien 391619370Spst if (n3 < 0) 391719370Spst /* n3 actually gives the size. */ 391898944Sobrien return init_type (TYPE_CODE_INT, -n3, TYPE_FLAG_UNSIGNED, 391919370Spst NULL, objfile); 392019370Spst 392198944Sobrien /* Is n3 == 2**(8n)-1 for some integer n? Then it's an 392298944Sobrien unsigned n-byte integer. But do require n to be a power of 392398944Sobrien two; we don't want 3- and 5-byte integers flying around. */ 392498944Sobrien { 392598944Sobrien int bytes; 392698944Sobrien unsigned long bits; 392798944Sobrien 392898944Sobrien bits = n3; 392998944Sobrien for (bytes = 0; (bits & 0xff) == 0xff; bytes++) 393098944Sobrien bits >>= 8; 393198944Sobrien if (bits == 0 393298944Sobrien && ((bytes - 1) & bytes) == 0) /* "bytes is a power of two" */ 393398944Sobrien return init_type (TYPE_CODE_INT, bytes, TYPE_FLAG_UNSIGNED, NULL, 393498944Sobrien objfile); 393598944Sobrien } 393619370Spst } 393719370Spst /* I think this is for Convex "long long". Since I don't know whether 393819370Spst Convex sets self_subrange, I also accept that particular size regardless 393919370Spst of self_subrange. */ 394019370Spst else if (n3 == 0 && n2 < 0 394119370Spst && (self_subrange 394298944Sobrien || n2 == -TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT)) 394398944Sobrien return init_type (TYPE_CODE_INT, -n2, 0, NULL, objfile); 394498944Sobrien else if (n2 == -n3 - 1) 394519370Spst { 394619370Spst if (n3 == 0x7f) 394719370Spst return init_type (TYPE_CODE_INT, 1, 0, NULL, objfile); 394819370Spst if (n3 == 0x7fff) 394919370Spst return init_type (TYPE_CODE_INT, 2, 0, NULL, objfile); 395019370Spst if (n3 == 0x7fffffff) 395119370Spst return init_type (TYPE_CODE_INT, 4, 0, NULL, objfile); 395219370Spst } 395319370Spst 395419370Spst /* We have a real range type on our hands. Allocate space and 395519370Spst return a real pointer. */ 395698944Sobrienhandle_true_range: 395719370Spst 395819370Spst if (self_subrange) 395919370Spst index_type = builtin_type_int; 396019370Spst else 396119370Spst index_type = *dbx_lookup_type (rangenums); 396219370Spst if (index_type == NULL) 396319370Spst { 396419370Spst /* Does this actually ever happen? Is that why we are worrying 396519370Spst about dealing with it rather than just calling error_type? */ 396619370Spst 396719370Spst static struct type *range_type_index; 396819370Spst 3969130803Smarcel complaint (&symfile_complaints, 3970130803Smarcel "base type %d of range type is not defined", rangenums[1]); 397119370Spst if (range_type_index == NULL) 397219370Spst range_type_index = 397319370Spst init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT, 397419370Spst 0, "range type index type", NULL); 397519370Spst index_type = range_type_index; 397619370Spst } 397719370Spst 397819370Spst result_type = create_range_type ((struct type *) NULL, index_type, n2, n3); 397919370Spst return (result_type); 398019370Spst} 398119370Spst 398219370Spst/* Read in an argument list. This is a list of types, separated by commas 398319370Spst and terminated with END. Return the list of types read in, or (struct type 398419370Spst **)-1 if there is an error. */ 398519370Spst 3986130803Smarcelstatic struct field * 3987130803Smarcelread_args (char **pp, int end, struct objfile *objfile, int *nargsp, 3988130803Smarcel int *varargsp) 398919370Spst{ 399019370Spst /* FIXME! Remove this arbitrary limit! */ 3991130803Smarcel struct type *types[1024]; /* allow for fns of 1023 parameters */ 3992130803Smarcel int n = 0, i; 3993130803Smarcel struct field *rval; 399419370Spst 399519370Spst while (**pp != end) 399619370Spst { 399719370Spst if (**pp != ',') 399819370Spst /* Invalid argument list: no ','. */ 3999130803Smarcel return (struct field *) -1; 400019370Spst (*pp)++; 400119370Spst STABS_CONTINUE (pp, objfile); 400219370Spst types[n++] = read_type (pp, objfile); 400319370Spst } 400419370Spst (*pp)++; /* get past `end' (the ':' character) */ 400519370Spst 4006130803Smarcel if (TYPE_CODE (types[n - 1]) != TYPE_CODE_VOID) 4007130803Smarcel *varargsp = 1; 400819370Spst else 400919370Spst { 4010130803Smarcel n--; 4011130803Smarcel *varargsp = 0; 401219370Spst } 4013130803Smarcel 4014130803Smarcel rval = (struct field *) xmalloc (n * sizeof (struct field)); 4015130803Smarcel memset (rval, 0, n * sizeof (struct field)); 4016130803Smarcel for (i = 0; i < n; i++) 4017130803Smarcel rval[i].type = types[i]; 4018130803Smarcel *nargsp = n; 401919370Spst return rval; 402019370Spst} 402119370Spst 402219370Spst/* Common block handling. */ 402319370Spst 402419370Spst/* List of symbols declared since the last BCOMM. This list is a tail 402519370Spst of local_symbols. When ECOMM is seen, the symbols on the list 402619370Spst are noted so their proper addresses can be filled in later, 402719370Spst using the common block base address gotten from the assembler 402819370Spst stabs. */ 402919370Spst 403019370Spststatic struct pending *common_block; 403119370Spststatic int common_block_i; 403219370Spst 403319370Spst/* Name of the current common block. We get it from the BCOMM instead of the 403419370Spst ECOMM to match IBM documentation (even though IBM puts the name both places 403519370Spst like everyone else). */ 403619370Spststatic char *common_block_name; 403719370Spst 403819370Spst/* Process a N_BCOMM symbol. The storage for NAME is not guaranteed 403919370Spst to remain after this function returns. */ 404019370Spst 404119370Spstvoid 404298944Sobriencommon_block_start (char *name, struct objfile *objfile) 404319370Spst{ 404419370Spst if (common_block_name != NULL) 404519370Spst { 4046130803Smarcel complaint (&symfile_complaints, 4047130803Smarcel "Invalid symbol data: common block within common block"); 404819370Spst } 404919370Spst common_block = local_symbols; 405019370Spst common_block_i = local_symbols ? local_symbols->nsyms : 0; 405119370Spst common_block_name = obsavestring (name, strlen (name), 4052130803Smarcel &objfile->objfile_obstack); 405319370Spst} 405419370Spst 405519370Spst/* Process a N_ECOMM symbol. */ 405619370Spst 405719370Spstvoid 405898944Sobriencommon_block_end (struct objfile *objfile) 405919370Spst{ 406019370Spst /* Symbols declared since the BCOMM are to have the common block 406119370Spst start address added in when we know it. common_block and 406219370Spst common_block_i point to the first symbol after the BCOMM in 406319370Spst the local_symbols list; copy the list and hang it off the 406419370Spst symbol for the common block name for later fixup. */ 406519370Spst int i; 406619370Spst struct symbol *sym; 406719370Spst struct pending *new = 0; 406819370Spst struct pending *next; 406919370Spst int j; 407019370Spst 407119370Spst if (common_block_name == NULL) 407219370Spst { 4073130803Smarcel complaint (&symfile_complaints, "ECOMM symbol unmatched by BCOMM"); 407419370Spst return; 407519370Spst } 407619370Spst 407798944Sobrien sym = (struct symbol *) 4078130803Smarcel obstack_alloc (&objfile->objfile_obstack, sizeof (struct symbol)); 407919370Spst memset (sym, 0, sizeof (struct symbol)); 4080130803Smarcel /* Note: common_block_name already saved on objfile_obstack */ 4081130803Smarcel DEPRECATED_SYMBOL_NAME (sym) = common_block_name; 408219370Spst SYMBOL_CLASS (sym) = LOC_BLOCK; 408319370Spst 408419370Spst /* Now we copy all the symbols which have been defined since the BCOMM. */ 408519370Spst 408619370Spst /* Copy all the struct pendings before common_block. */ 408719370Spst for (next = local_symbols; 408819370Spst next != NULL && next != common_block; 408919370Spst next = next->next) 409019370Spst { 409119370Spst for (j = 0; j < next->nsyms; j++) 409219370Spst add_symbol_to_list (next->symbol[j], &new); 409319370Spst } 409419370Spst 409519370Spst /* Copy however much of COMMON_BLOCK we need. If COMMON_BLOCK is 409619370Spst NULL, it means copy all the local symbols (which we already did 409719370Spst above). */ 409819370Spst 409919370Spst if (common_block != NULL) 410019370Spst for (j = common_block_i; j < common_block->nsyms; j++) 410119370Spst add_symbol_to_list (common_block->symbol[j], &new); 410219370Spst 410319370Spst SYMBOL_TYPE (sym) = (struct type *) new; 410419370Spst 410519370Spst /* Should we be putting local_symbols back to what it was? 410619370Spst Does it matter? */ 410719370Spst 4108130803Smarcel i = hashname (DEPRECATED_SYMBOL_NAME (sym)); 410919370Spst SYMBOL_VALUE_CHAIN (sym) = global_sym_chain[i]; 411019370Spst global_sym_chain[i] = sym; 411119370Spst common_block_name = NULL; 411219370Spst} 411319370Spst 411419370Spst/* Add a common block's start address to the offset of each symbol 411519370Spst declared to be in it (by being between a BCOMM/ECOMM pair that uses 411619370Spst the common block name). */ 411719370Spst 411819370Spststatic void 411998944Sobrienfix_common_block (struct symbol *sym, int valu) 412019370Spst{ 412119370Spst struct pending *next = (struct pending *) SYMBOL_TYPE (sym); 412298944Sobrien for (; next; next = next->next) 412319370Spst { 4124130803Smarcel int j; 412519370Spst for (j = next->nsyms - 1; j >= 0; j--) 412619370Spst SYMBOL_VALUE_ADDRESS (next->symbol[j]) += valu; 412719370Spst } 412819370Spst} 412998944Sobrien 413019370Spst 413119370Spst 413219370Spst/* What about types defined as forward references inside of a small lexical 413319370Spst scope? */ 413419370Spst/* Add a type to the list of undefined types to be checked through 413519370Spst once this file has been read in. */ 413619370Spst 4137130803Smarcelstatic void 413898944Sobrienadd_undefined_type (struct type *type) 413919370Spst{ 414019370Spst if (undef_types_length == undef_types_allocated) 414119370Spst { 414219370Spst undef_types_allocated *= 2; 414319370Spst undef_types = (struct type **) 414419370Spst xrealloc ((char *) undef_types, 414519370Spst undef_types_allocated * sizeof (struct type *)); 414619370Spst } 414719370Spst undef_types[undef_types_length++] = type; 414819370Spst} 414919370Spst 415019370Spst/* Go through each undefined type, see if it's still undefined, and fix it 415119370Spst up if possible. We have two kinds of undefined types: 415219370Spst 415319370Spst TYPE_CODE_ARRAY: Array whose target type wasn't defined yet. 415498944Sobrien Fix: update array length using the element bounds 415598944Sobrien and the target type's length. 415619370Spst TYPE_CODE_STRUCT, TYPE_CODE_UNION: Structure whose fields were not 415798944Sobrien yet defined at the time a pointer to it was made. 415898944Sobrien Fix: Do a full lookup on the struct/union tag. */ 415919370Spstvoid 416098944Sobriencleanup_undefined_types (void) 416119370Spst{ 416219370Spst struct type **type; 416319370Spst 416419370Spst for (type = undef_types; type < undef_types + undef_types_length; type++) 416519370Spst { 416619370Spst switch (TYPE_CODE (*type)) 416719370Spst { 416819370Spst 416998944Sobrien case TYPE_CODE_STRUCT: 417098944Sobrien case TYPE_CODE_UNION: 417198944Sobrien case TYPE_CODE_ENUM: 417219370Spst { 417319370Spst /* Check if it has been defined since. Need to do this here 417419370Spst as well as in check_typedef to deal with the (legitimate in 417519370Spst C though not C++) case of several types with the same name 417619370Spst in different source files. */ 417798944Sobrien if (TYPE_STUB (*type)) 417819370Spst { 417919370Spst struct pending *ppt; 418019370Spst int i; 418119370Spst /* Name of the type, without "struct" or "union" */ 418219370Spst char *typename = TYPE_TAG_NAME (*type); 418319370Spst 418419370Spst if (typename == NULL) 418519370Spst { 4186130803Smarcel complaint (&symfile_complaints, "need a type name"); 418719370Spst break; 418819370Spst } 418919370Spst for (ppt = file_symbols; ppt; ppt = ppt->next) 419019370Spst { 419119370Spst for (i = 0; i < ppt->nsyms; i++) 419219370Spst { 419319370Spst struct symbol *sym = ppt->symbol[i]; 419498944Sobrien 419519370Spst if (SYMBOL_CLASS (sym) == LOC_TYPEDEF 4196130803Smarcel && SYMBOL_DOMAIN (sym) == STRUCT_DOMAIN 419719370Spst && (TYPE_CODE (SYMBOL_TYPE (sym)) == 419819370Spst TYPE_CODE (*type)) 4199130803Smarcel && strcmp (DEPRECATED_SYMBOL_NAME (sym), typename) == 0) 4200130803Smarcel replace_type (*type, SYMBOL_TYPE (sym)); 420119370Spst } 420219370Spst } 420319370Spst } 420419370Spst } 420519370Spst break; 420619370Spst 420719370Spst default: 420819370Spst { 4209130803Smarcel complaint (&symfile_complaints, 4210130803Smarcel "forward-referenced types left unresolved, " 4211130803Smarcel "type code %d.", 4212130803Smarcel TYPE_CODE (*type)); 421319370Spst } 421419370Spst break; 421519370Spst } 421619370Spst } 421719370Spst 421819370Spst undef_types_length = 0; 421919370Spst} 422019370Spst 422119370Spst/* Scan through all of the global symbols defined in the object file, 422219370Spst assigning values to the debugging symbols that need to be assigned 422319370Spst to. Get these symbols from the minimal symbol table. */ 422419370Spst 422519370Spstvoid 422698944Sobrienscan_file_globals (struct objfile *objfile) 422719370Spst{ 422819370Spst int hash; 422919370Spst struct minimal_symbol *msymbol; 4230130803Smarcel struct symbol *sym, *prev; 423146283Sdfr struct objfile *resolve_objfile; 423219370Spst 423346283Sdfr /* SVR4 based linkers copy referenced global symbols from shared 423446283Sdfr libraries to the main executable. 423546283Sdfr If we are scanning the symbols for a shared library, try to resolve 423646283Sdfr them from the minimal symbols of the main executable first. */ 423719370Spst 423846283Sdfr if (symfile_objfile && objfile != symfile_objfile) 423946283Sdfr resolve_objfile = symfile_objfile; 424046283Sdfr else 424146283Sdfr resolve_objfile = objfile; 424246283Sdfr 424346283Sdfr while (1) 424419370Spst { 424546283Sdfr /* Avoid expensive loop through all minimal symbols if there are 424698944Sobrien no unresolved symbols. */ 424746283Sdfr for (hash = 0; hash < HASHSIZE; hash++) 424819370Spst { 424946283Sdfr if (global_sym_chain[hash]) 425046283Sdfr break; 425119370Spst } 425246283Sdfr if (hash >= HASHSIZE) 425346283Sdfr return; 425419370Spst 425598944Sobrien for (msymbol = resolve_objfile->msymbols; 4256130803Smarcel msymbol && DEPRECATED_SYMBOL_NAME (msymbol) != NULL; 425746283Sdfr msymbol++) 425846283Sdfr { 425946283Sdfr QUIT; 426019370Spst 426146283Sdfr /* Skip static symbols. */ 426246283Sdfr switch (MSYMBOL_TYPE (msymbol)) 426346283Sdfr { 426446283Sdfr case mst_file_text: 426546283Sdfr case mst_file_data: 426646283Sdfr case mst_file_bss: 426746283Sdfr continue; 426846283Sdfr default: 426946283Sdfr break; 427046283Sdfr } 427119370Spst 427246283Sdfr prev = NULL; 427319370Spst 427446283Sdfr /* Get the hash index and check all the symbols 427546283Sdfr under that hash index. */ 427646283Sdfr 4277130803Smarcel hash = hashname (DEPRECATED_SYMBOL_NAME (msymbol)); 427846283Sdfr 427946283Sdfr for (sym = global_sym_chain[hash]; sym;) 428019370Spst { 4281130803Smarcel if (DEPRECATED_SYMBOL_NAME (msymbol)[0] == DEPRECATED_SYMBOL_NAME (sym)[0] && 4282130803Smarcel strcmp (DEPRECATED_SYMBOL_NAME (msymbol) + 1, DEPRECATED_SYMBOL_NAME (sym) + 1) == 0) 428319370Spst { 428446283Sdfr /* Splice this symbol out of the hash chain and 428546283Sdfr assign the value we have to it. */ 428646283Sdfr if (prev) 428746283Sdfr { 428846283Sdfr SYMBOL_VALUE_CHAIN (prev) = SYMBOL_VALUE_CHAIN (sym); 428946283Sdfr } 429046283Sdfr else 429146283Sdfr { 429246283Sdfr global_sym_chain[hash] = SYMBOL_VALUE_CHAIN (sym); 429346283Sdfr } 429498944Sobrien 429546283Sdfr /* Check to see whether we need to fix up a common block. */ 429646283Sdfr /* Note: this code might be executed several times for 429746283Sdfr the same symbol if there are multiple references. */ 4298130803Smarcel if (sym) 429946283Sdfr { 4300130803Smarcel if (SYMBOL_CLASS (sym) == LOC_BLOCK) 430146283Sdfr { 4302130803Smarcel fix_common_block (sym, 430346283Sdfr SYMBOL_VALUE_ADDRESS (msymbol)); 430446283Sdfr } 430546283Sdfr else 430646283Sdfr { 4307130803Smarcel SYMBOL_VALUE_ADDRESS (sym) 430846283Sdfr = SYMBOL_VALUE_ADDRESS (msymbol); 430946283Sdfr } 4310130803Smarcel SYMBOL_SECTION (sym) = SYMBOL_SECTION (msymbol); 431146283Sdfr } 431246283Sdfr 431346283Sdfr if (prev) 431446283Sdfr { 431546283Sdfr sym = SYMBOL_VALUE_CHAIN (prev); 431646283Sdfr } 431746283Sdfr else 431846283Sdfr { 431946283Sdfr sym = global_sym_chain[hash]; 432046283Sdfr } 432119370Spst } 432219370Spst else 432319370Spst { 432446283Sdfr prev = sym; 432546283Sdfr sym = SYMBOL_VALUE_CHAIN (sym); 432619370Spst } 432719370Spst } 432819370Spst } 432946283Sdfr if (resolve_objfile == objfile) 433046283Sdfr break; 433146283Sdfr resolve_objfile = objfile; 433219370Spst } 433319370Spst 433419370Spst /* Change the storage class of any remaining unresolved globals to 433519370Spst LOC_UNRESOLVED and remove them from the chain. */ 433619370Spst for (hash = 0; hash < HASHSIZE; hash++) 433719370Spst { 433819370Spst sym = global_sym_chain[hash]; 433919370Spst while (sym) 434019370Spst { 434119370Spst prev = sym; 434219370Spst sym = SYMBOL_VALUE_CHAIN (sym); 434319370Spst 434419370Spst /* Change the symbol address from the misleading chain value 434519370Spst to address zero. */ 434619370Spst SYMBOL_VALUE_ADDRESS (prev) = 0; 434719370Spst 434819370Spst /* Complain about unresolved common block symbols. */ 434919370Spst if (SYMBOL_CLASS (prev) == LOC_STATIC) 435019370Spst SYMBOL_CLASS (prev) = LOC_UNRESOLVED; 435119370Spst else 4352130803Smarcel complaint (&symfile_complaints, 4353130803Smarcel "%s: common block `%s' from global_sym_chain unresolved", 4354130803Smarcel objfile->name, DEPRECATED_SYMBOL_NAME (prev)); 435519370Spst } 435619370Spst } 435719370Spst memset (global_sym_chain, 0, sizeof (global_sym_chain)); 435819370Spst} 435919370Spst 436019370Spst/* Initialize anything that needs initializing when starting to read 436119370Spst a fresh piece of a symbol file, e.g. reading in the stuff corresponding 436219370Spst to a psymtab. */ 436319370Spst 436419370Spstvoid 436598944Sobrienstabsread_init (void) 436619370Spst{ 436719370Spst} 436819370Spst 436919370Spst/* Initialize anything that needs initializing when a completely new 437019370Spst symbol file is specified (not just adding some symbols from another 437119370Spst file, e.g. a shared library). */ 437219370Spst 437319370Spstvoid 437498944Sobrienstabsread_new_init (void) 437519370Spst{ 437619370Spst /* Empty the hash table of global syms looking for values. */ 437719370Spst memset (global_sym_chain, 0, sizeof (global_sym_chain)); 437819370Spst} 437919370Spst 438019370Spst/* Initialize anything that needs initializing at the same time as 438119370Spst start_symtab() is called. */ 438219370Spst 438398944Sobrienvoid 438498944Sobrienstart_stabs (void) 438519370Spst{ 438619370Spst global_stabs = NULL; /* AIX COFF */ 438719370Spst /* Leave FILENUM of 0 free for builtin types and this file's types. */ 438819370Spst n_this_object_header_files = 1; 438919370Spst type_vector_length = 0; 439019370Spst type_vector = (struct type **) 0; 439119370Spst 439219370Spst /* FIXME: If common_block_name is not already NULL, we should complain(). */ 439319370Spst common_block_name = NULL; 439419370Spst} 439519370Spst 439619370Spst/* Call after end_symtab() */ 439719370Spst 439898944Sobrienvoid 439998944Sobrienend_stabs (void) 440019370Spst{ 440119370Spst if (type_vector) 440219370Spst { 440398944Sobrien xfree (type_vector); 440419370Spst } 440519370Spst type_vector = 0; 440619370Spst type_vector_length = 0; 440719370Spst previous_stab_code = 0; 440819370Spst} 440919370Spst 441019370Spstvoid 441198944Sobrienfinish_global_stabs (struct objfile *objfile) 441219370Spst{ 441319370Spst if (global_stabs) 441419370Spst { 441519370Spst patch_block_stabs (global_symbols, global_stabs, objfile); 441698944Sobrien xfree (global_stabs); 441719370Spst global_stabs = NULL; 441819370Spst } 441919370Spst} 442019370Spst 4421130803Smarcel/* Find the end of the name, delimited by a ':', but don't match 4422130803Smarcel ObjC symbols which look like -[Foo bar::]:bla. */ 4423130803Smarcelstatic char * 4424130803Smarcelfind_name_end (char *name) 4425130803Smarcel{ 4426130803Smarcel char *s = name; 4427130803Smarcel if (s[0] == '-' || *s == '+') 4428130803Smarcel { 4429130803Smarcel /* Must be an ObjC method symbol. */ 4430130803Smarcel if (s[1] != '[') 4431130803Smarcel { 4432130803Smarcel error ("invalid symbol name \"%s\"", name); 4433130803Smarcel } 4434130803Smarcel s = strchr (s, ']'); 4435130803Smarcel if (s == NULL) 4436130803Smarcel { 4437130803Smarcel error ("invalid symbol name \"%s\"", name); 4438130803Smarcel } 4439130803Smarcel return strchr (s, ':'); 4440130803Smarcel } 4441130803Smarcel else 4442130803Smarcel { 4443130803Smarcel return strchr (s, ':'); 4444130803Smarcel } 4445130803Smarcel} 4446130803Smarcel 444719370Spst/* Initializer for this module */ 444819370Spst 444919370Spstvoid 445098944Sobrien_initialize_stabsread (void) 445119370Spst{ 445219370Spst undef_types_allocated = 20; 445319370Spst undef_types_length = 0; 445419370Spst undef_types = (struct type **) 445519370Spst xmalloc (undef_types_allocated * sizeof (struct type *)); 445619370Spst} 4457