133965Sjdp/* stabs.c -- Parse stabs debugging information 2218822Sdim Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 3218822Sdim 2006, 2007 Free Software Foundation, Inc. 433965Sjdp Written by Ian Lance Taylor <ian@cygnus.com>. 533965Sjdp 633965Sjdp This file is part of GNU Binutils. 733965Sjdp 833965Sjdp This program is free software; you can redistribute it and/or modify 933965Sjdp it under the terms of the GNU General Public License as published by 1033965Sjdp the Free Software Foundation; either version 2 of the License, or 1133965Sjdp (at your option) any later version. 1233965Sjdp 1333965Sjdp This program is distributed in the hope that it will be useful, 1433965Sjdp but WITHOUT ANY WARRANTY; without even the implied warranty of 1533965Sjdp MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1633965Sjdp GNU General Public License for more details. 1733965Sjdp 1833965Sjdp You should have received a copy of the GNU General Public License 1933965Sjdp along with this program; if not, write to the Free Software 20218822Sdim Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 21218822Sdim 02110-1301, USA. */ 2233965Sjdp 2333965Sjdp/* This file contains code which parses stabs debugging information. 2433965Sjdp The organization of this code is based on the gdb stabs reading 2533965Sjdp code. The job it does is somewhat different, because it is not 2633965Sjdp trying to identify the correct address for anything. */ 2733965Sjdp 28218822Sdim#include "sysdep.h" 2933965Sjdp#include "bfd.h" 3033965Sjdp#include "libiberty.h" 3189857Sobrien#include "safe-ctype.h" 3233965Sjdp#include "demangle.h" 3333965Sjdp#include "debug.h" 3433965Sjdp#include "budbg.h" 3577298Sobrien#include "filenames.h" 3633965Sjdp#include "aout/aout64.h" 3733965Sjdp#include "aout/stab_gnu.h" 3833965Sjdp 3933965Sjdp/* The number of predefined XCOFF types. */ 4033965Sjdp 4133965Sjdp#define XCOFF_TYPE_COUNT 34 4233965Sjdp 4333965Sjdp/* This structure is used as a handle so that the stab parsing doesn't 4433965Sjdp need to use any static variables. */ 4533965Sjdp 4633965Sjdpstruct stab_handle 4733965Sjdp{ 4833965Sjdp /* The BFD. */ 4933965Sjdp bfd *abfd; 50130561Sobrien /* TRUE if this is stabs in sections. */ 51130561Sobrien bfd_boolean sections; 5233965Sjdp /* The symbol table. */ 5333965Sjdp asymbol **syms; 5433965Sjdp /* The number of symbols. */ 5533965Sjdp long symcount; 5633965Sjdp /* The accumulated file name string. */ 5733965Sjdp char *so_string; 5833965Sjdp /* The value of the last N_SO symbol. */ 5933965Sjdp bfd_vma so_value; 6033965Sjdp /* The value of the start of the file, so that we can handle file 6133965Sjdp relative N_LBRAC and N_RBRAC symbols. */ 6233965Sjdp bfd_vma file_start_offset; 6333965Sjdp /* The offset of the start of the function, so that we can handle 6433965Sjdp function relative N_LBRAC and N_RBRAC symbols. */ 6533965Sjdp bfd_vma function_start_offset; 6633965Sjdp /* The version number of gcc which compiled the current compilation 6733965Sjdp unit, 0 if not compiled by gcc. */ 6833965Sjdp int gcc_compiled; 6933965Sjdp /* Whether an N_OPT symbol was seen that was not generated by gcc, 7033965Sjdp so that we can detect the SunPRO compiler. */ 71130561Sobrien bfd_boolean n_opt_found; 7233965Sjdp /* The main file name. */ 7333965Sjdp char *main_filename; 7433965Sjdp /* A stack of unfinished N_BINCL files. */ 7533965Sjdp struct bincl_file *bincl_stack; 7633965Sjdp /* A list of finished N_BINCL files. */ 7733965Sjdp struct bincl_file *bincl_list; 7833965Sjdp /* Whether we are inside a function or not. */ 79130561Sobrien bfd_boolean within_function; 8033965Sjdp /* The address of the end of the function, used if we have seen an 8133965Sjdp N_FUN symbol while in a function. This is -1 if we have not seen 8233965Sjdp an N_FUN (the normal case). */ 8333965Sjdp bfd_vma function_end; 8433965Sjdp /* The depth of block nesting. */ 8533965Sjdp int block_depth; 8633965Sjdp /* List of pending variable definitions. */ 8733965Sjdp struct stab_pending_var *pending; 8833965Sjdp /* Number of files for which we have types. */ 8933965Sjdp unsigned int files; 9033965Sjdp /* Lists of types per file. */ 9133965Sjdp struct stab_types **file_types; 9233965Sjdp /* Predefined XCOFF types. */ 9333965Sjdp debug_type xcoff_types[XCOFF_TYPE_COUNT]; 9433965Sjdp /* Undefined tags. */ 9533965Sjdp struct stab_tag *tags; 9660484Sobrien /* Set by parse_stab_type if it sees a structure defined as a cross 9760484Sobrien reference to itself. Reset by parse_stab_type otherwise. */ 98130561Sobrien bfd_boolean self_crossref; 9933965Sjdp}; 10033965Sjdp 10133965Sjdp/* A list of these structures is used to hold pending variable 10233965Sjdp definitions seen before the N_LBRAC of a block. */ 10333965Sjdp 10433965Sjdpstruct stab_pending_var 10533965Sjdp{ 10633965Sjdp /* Next pending variable definition. */ 10733965Sjdp struct stab_pending_var *next; 10833965Sjdp /* Name. */ 10933965Sjdp const char *name; 11033965Sjdp /* Type. */ 11133965Sjdp debug_type type; 11233965Sjdp /* Kind. */ 11333965Sjdp enum debug_var_kind kind; 11433965Sjdp /* Value. */ 11533965Sjdp bfd_vma val; 11633965Sjdp}; 11733965Sjdp 11833965Sjdp/* A list of these structures is used to hold the types for a single 11933965Sjdp file. */ 12033965Sjdp 12133965Sjdpstruct stab_types 12233965Sjdp{ 12333965Sjdp /* Next set of slots for this file. */ 12433965Sjdp struct stab_types *next; 12533965Sjdp /* Types indexed by type number. */ 12633965Sjdp#define STAB_TYPES_SLOTS (16) 12733965Sjdp debug_type types[STAB_TYPES_SLOTS]; 12833965Sjdp}; 12933965Sjdp 13033965Sjdp/* We keep a list of undefined tags that we encounter, so that we can 13133965Sjdp fill them in if the tag is later defined. */ 13233965Sjdp 13333965Sjdpstruct stab_tag 13433965Sjdp{ 13533965Sjdp /* Next undefined tag. */ 13633965Sjdp struct stab_tag *next; 13733965Sjdp /* Tag name. */ 13833965Sjdp const char *name; 13933965Sjdp /* Type kind. */ 14033965Sjdp enum debug_type_kind kind; 14133965Sjdp /* Slot to hold real type when we discover it. If we don't, we fill 14233965Sjdp in an undefined tag type. */ 14333965Sjdp debug_type slot; 14433965Sjdp /* Indirect type we have created to point at slot. */ 14533965Sjdp debug_type type; 14633965Sjdp}; 14733965Sjdp 148130561Sobrienstatic char *savestring (const char *, int); 149130561Sobrienstatic bfd_vma parse_number (const char **, bfd_boolean *); 150130561Sobrienstatic void bad_stab (const char *); 151130561Sobrienstatic void warn_stab (const char *, const char *); 152130561Sobrienstatic bfd_boolean parse_stab_string 153130561Sobrien (void *, struct stab_handle *, int, int, bfd_vma, const char *); 15433965Sjdpstatic debug_type parse_stab_type 155130561Sobrien (void *, struct stab_handle *, const char *, const char **, debug_type **); 156130561Sobrienstatic bfd_boolean parse_stab_type_number (const char **, int *); 15733965Sjdpstatic debug_type parse_stab_range_type 158130561Sobrien (void *, struct stab_handle *, const char *, const char **, const int *); 159130561Sobrienstatic debug_type parse_stab_sun_builtin_type (void *, const char **); 160130561Sobrienstatic debug_type parse_stab_sun_floating_type (void *, const char **); 161130561Sobrienstatic debug_type parse_stab_enum_type (void *, const char **); 16233965Sjdpstatic debug_type parse_stab_struct_type 163130561Sobrien (void *, struct stab_handle *, const char *, const char **, 164130561Sobrien bfd_boolean, const int *); 165130561Sobrienstatic bfd_boolean parse_stab_baseclasses 166130561Sobrien (void *, struct stab_handle *, const char **, debug_baseclass **); 167130561Sobrienstatic bfd_boolean parse_stab_struct_fields 168130561Sobrien (void *, struct stab_handle *, const char **, debug_field **, bfd_boolean *); 169130561Sobrienstatic bfd_boolean parse_stab_cpp_abbrev 170130561Sobrien (void *, struct stab_handle *, const char **, debug_field *); 171130561Sobrienstatic bfd_boolean parse_stab_one_struct_field 172130561Sobrien (void *, struct stab_handle *, const char **, const char *, 173130561Sobrien debug_field *, bfd_boolean *); 174130561Sobrienstatic bfd_boolean parse_stab_members 175130561Sobrien (void *, struct stab_handle *, const char *, const char **, const int *, 176130561Sobrien debug_method **); 17733965Sjdpstatic debug_type parse_stab_argtypes 178130561Sobrien (void *, struct stab_handle *, debug_type, const char *, const char *, 179130561Sobrien debug_type, const char *, bfd_boolean, bfd_boolean, const char **); 180130561Sobrienstatic bfd_boolean parse_stab_tilde_field 181130561Sobrien (void *, struct stab_handle *, const char **, const int *, debug_type *, 182130561Sobrien bfd_boolean *); 18333965Sjdpstatic debug_type parse_stab_array_type 184130561Sobrien (void *, struct stab_handle *, const char **, bfd_boolean); 185130561Sobrienstatic void push_bincl (struct stab_handle *, const char *, bfd_vma); 186130561Sobrienstatic const char *pop_bincl (struct stab_handle *); 187130561Sobrienstatic bfd_boolean find_excl (struct stab_handle *, const char *, bfd_vma); 188130561Sobrienstatic bfd_boolean stab_record_variable 189130561Sobrien (void *, struct stab_handle *, const char *, debug_type, 190130561Sobrien enum debug_var_kind, bfd_vma); 191130561Sobrienstatic bfd_boolean stab_emit_pending_vars (void *, struct stab_handle *); 192130561Sobrienstatic debug_type *stab_find_slot (struct stab_handle *, const int *); 193130561Sobrienstatic debug_type stab_find_type (void *, struct stab_handle *, const int *); 194130561Sobrienstatic bfd_boolean stab_record_type 195130561Sobrien (void *, struct stab_handle *, const int *, debug_type); 19633965Sjdpstatic debug_type stab_xcoff_builtin_type 197130561Sobrien (void *, struct stab_handle *, int); 19833965Sjdpstatic debug_type stab_find_tagged_type 199130561Sobrien (void *, struct stab_handle *, const char *, int, enum debug_type_kind); 20033965Sjdpstatic debug_type *stab_demangle_argtypes 201130561Sobrien (void *, struct stab_handle *, const char *, bfd_boolean *, unsigned int); 202130561Sobrienstatic debug_type *stab_demangle_v3_argtypes 203130561Sobrien (void *, struct stab_handle *, const char *, bfd_boolean *); 204218822Sdimstatic debug_type *stab_demangle_v3_arglist 205218822Sdim (void *, struct stab_handle *, struct demangle_component *, bfd_boolean *); 206130561Sobrienstatic debug_type stab_demangle_v3_arg 207130561Sobrien (void *, struct stab_handle *, struct demangle_component *, debug_type, 208130561Sobrien bfd_boolean *); 20933965Sjdp 21033965Sjdp/* Save a string in memory. */ 21133965Sjdp 21233965Sjdpstatic char * 213130561Sobriensavestring (const char *start, int len) 21433965Sjdp{ 21533965Sjdp char *ret; 21633965Sjdp 21733965Sjdp ret = (char *) xmalloc (len + 1); 21833965Sjdp memcpy (ret, start, len); 21933965Sjdp ret[len] = '\0'; 22033965Sjdp return ret; 22133965Sjdp} 22233965Sjdp 22333965Sjdp/* Read a number from a string. */ 22433965Sjdp 22533965Sjdpstatic bfd_vma 226130561Sobrienparse_number (const char **pp, bfd_boolean *poverflow) 22733965Sjdp{ 22833965Sjdp unsigned long ul; 22933965Sjdp const char *orig; 23033965Sjdp 23133965Sjdp if (poverflow != NULL) 232130561Sobrien *poverflow = FALSE; 23333965Sjdp 23433965Sjdp orig = *pp; 23533965Sjdp 23633965Sjdp errno = 0; 23733965Sjdp ul = strtoul (*pp, (char **) pp, 0); 23833965Sjdp if (ul + 1 != 0 || errno == 0) 23960484Sobrien { 24060484Sobrien /* If bfd_vma is larger than unsigned long, and the number is 24160484Sobrien meant to be negative, we have to make sure that we sign 24260484Sobrien extend properly. */ 24360484Sobrien if (*orig == '-') 24460484Sobrien return (bfd_vma) (bfd_signed_vma) (long) ul; 24560484Sobrien return (bfd_vma) ul; 24660484Sobrien } 24733965Sjdp 24833965Sjdp /* Note that even though strtoul overflowed, it should have set *pp 24933965Sjdp to the end of the number, which is where we want it. */ 25033965Sjdp if (sizeof (bfd_vma) > sizeof (unsigned long)) 25133965Sjdp { 25233965Sjdp const char *p; 253130561Sobrien bfd_boolean neg; 25433965Sjdp int base; 25533965Sjdp bfd_vma over, lastdig; 256130561Sobrien bfd_boolean overflow; 25733965Sjdp bfd_vma v; 25833965Sjdp 25933965Sjdp /* Our own version of strtoul, for a bfd_vma. */ 26033965Sjdp p = orig; 26133965Sjdp 262130561Sobrien neg = FALSE; 26333965Sjdp if (*p == '+') 26433965Sjdp ++p; 26533965Sjdp else if (*p == '-') 26633965Sjdp { 267130561Sobrien neg = TRUE; 26833965Sjdp ++p; 26933965Sjdp } 27033965Sjdp 27133965Sjdp base = 10; 27233965Sjdp if (*p == '0') 27333965Sjdp { 27433965Sjdp if (p[1] == 'x' || p[1] == 'X') 27533965Sjdp { 27633965Sjdp base = 16; 27733965Sjdp p += 2; 27833965Sjdp } 27933965Sjdp else 28033965Sjdp { 28133965Sjdp base = 8; 28233965Sjdp ++p; 28333965Sjdp } 28433965Sjdp } 28533965Sjdp 28633965Sjdp over = ((bfd_vma) (bfd_signed_vma) -1) / (bfd_vma) base; 28733965Sjdp lastdig = ((bfd_vma) (bfd_signed_vma) -1) % (bfd_vma) base; 28833965Sjdp 289130561Sobrien overflow = FALSE; 29033965Sjdp v = 0; 29133965Sjdp while (1) 29233965Sjdp { 29333965Sjdp int d; 29433965Sjdp 29533965Sjdp d = *p++; 29689857Sobrien if (ISDIGIT (d)) 29733965Sjdp d -= '0'; 29889857Sobrien else if (ISUPPER (d)) 29933965Sjdp d -= 'A'; 30089857Sobrien else if (ISLOWER (d)) 30133965Sjdp d -= 'a'; 30233965Sjdp else 30333965Sjdp break; 30433965Sjdp 30533965Sjdp if (d >= base) 30633965Sjdp break; 30733965Sjdp 30833965Sjdp if (v > over || (v == over && (bfd_vma) d > lastdig)) 30933965Sjdp { 310130561Sobrien overflow = TRUE; 31133965Sjdp break; 31233965Sjdp } 31333965Sjdp } 31433965Sjdp 31533965Sjdp if (! overflow) 31633965Sjdp { 31733965Sjdp if (neg) 31833965Sjdp v = - v; 31933965Sjdp return v; 32033965Sjdp } 32133965Sjdp } 32233965Sjdp 32333965Sjdp /* If we get here, the number is too large to represent in a 32433965Sjdp bfd_vma. */ 32533965Sjdp if (poverflow != NULL) 326130561Sobrien *poverflow = TRUE; 32733965Sjdp else 32860484Sobrien warn_stab (orig, _("numeric overflow")); 32933965Sjdp 33033965Sjdp return 0; 33133965Sjdp} 33233965Sjdp 33333965Sjdp/* Give an error for a bad stab string. */ 33433965Sjdp 33533965Sjdpstatic void 336130561Sobrienbad_stab (const char *p) 33733965Sjdp{ 33860484Sobrien fprintf (stderr, _("Bad stab: %s\n"), p); 33933965Sjdp} 34033965Sjdp 34133965Sjdp/* Warn about something in a stab string. */ 34233965Sjdp 34333965Sjdpstatic void 344130561Sobrienwarn_stab (const char *p, const char *err) 34533965Sjdp{ 34660484Sobrien fprintf (stderr, _("Warning: %s: %s\n"), err, p); 34733965Sjdp} 34833965Sjdp 34933965Sjdp/* Create a handle to parse stabs symbols with. */ 35033965Sjdp 351130561Sobrienvoid * 352130561Sobrienstart_stab (void *dhandle ATTRIBUTE_UNUSED, bfd *abfd, bfd_boolean sections, 353130561Sobrien asymbol **syms, long symcount) 35433965Sjdp{ 35533965Sjdp struct stab_handle *ret; 35633965Sjdp 35733965Sjdp ret = (struct stab_handle *) xmalloc (sizeof *ret); 35833965Sjdp memset (ret, 0, sizeof *ret); 35933965Sjdp ret->abfd = abfd; 36033965Sjdp ret->sections = sections; 36133965Sjdp ret->syms = syms; 36233965Sjdp ret->symcount = symcount; 36333965Sjdp ret->files = 1; 36433965Sjdp ret->file_types = (struct stab_types **) xmalloc (sizeof *ret->file_types); 36533965Sjdp ret->file_types[0] = NULL; 36633965Sjdp ret->function_end = (bfd_vma) -1; 367130561Sobrien return (void *) ret; 36833965Sjdp} 36933965Sjdp 37033965Sjdp/* When we have processed all the stabs information, we need to go 37133965Sjdp through and fill in all the undefined tags. */ 37233965Sjdp 373130561Sobrienbfd_boolean 374130561Sobrienfinish_stab (void *dhandle, void *handle) 37533965Sjdp{ 37633965Sjdp struct stab_handle *info = (struct stab_handle *) handle; 37733965Sjdp struct stab_tag *st; 37833965Sjdp 37933965Sjdp if (info->within_function) 38033965Sjdp { 38133965Sjdp if (! stab_emit_pending_vars (dhandle, info) 38233965Sjdp || ! debug_end_function (dhandle, info->function_end)) 383130561Sobrien return FALSE; 384130561Sobrien info->within_function = FALSE; 38533965Sjdp info->function_end = (bfd_vma) -1; 38633965Sjdp } 38733965Sjdp 38833965Sjdp for (st = info->tags; st != NULL; st = st->next) 38933965Sjdp { 39033965Sjdp enum debug_type_kind kind; 39133965Sjdp 39233965Sjdp kind = st->kind; 39333965Sjdp if (kind == DEBUG_KIND_ILLEGAL) 39433965Sjdp kind = DEBUG_KIND_STRUCT; 39533965Sjdp st->slot = debug_make_undefined_tagged_type (dhandle, st->name, kind); 39633965Sjdp if (st->slot == DEBUG_TYPE_NULL) 397130561Sobrien return FALSE; 39833965Sjdp } 39933965Sjdp 400130561Sobrien return TRUE; 40133965Sjdp} 40233965Sjdp 40333965Sjdp/* Handle a single stabs symbol. */ 40433965Sjdp 405130561Sobrienbfd_boolean 406130561Sobrienparse_stab (void *dhandle, void *handle, int type, int desc, bfd_vma value, 407130561Sobrien const char *string) 40833965Sjdp{ 40933965Sjdp struct stab_handle *info = (struct stab_handle *) handle; 41033965Sjdp 41133965Sjdp /* gcc will emit two N_SO strings per compilation unit, one for the 41233965Sjdp directory name and one for the file name. We just collect N_SO 41333965Sjdp strings as we see them, and start the new compilation unit when 41433965Sjdp we see a non N_SO symbol. */ 41533965Sjdp if (info->so_string != NULL 41633965Sjdp && (type != N_SO || *string == '\0' || value != info->so_value)) 41733965Sjdp { 41833965Sjdp if (! debug_set_filename (dhandle, info->so_string)) 419130561Sobrien return FALSE; 42033965Sjdp info->main_filename = info->so_string; 42133965Sjdp 42233965Sjdp info->gcc_compiled = 0; 423130561Sobrien info->n_opt_found = FALSE; 42433965Sjdp 42533965Sjdp /* Generally, for stabs in the symbol table, the N_LBRAC and 42633965Sjdp N_RBRAC symbols are relative to the N_SO symbol value. */ 42733965Sjdp if (! info->sections) 42833965Sjdp info->file_start_offset = info->so_value; 42933965Sjdp 43033965Sjdp /* We need to reset the mapping from type numbers to types. We 43133965Sjdp can't free the old mapping, because of the use of 43233965Sjdp debug_make_indirect_type. */ 43333965Sjdp info->files = 1; 43433965Sjdp info->file_types = ((struct stab_types **) 43533965Sjdp xmalloc (sizeof *info->file_types)); 43633965Sjdp info->file_types[0] = NULL; 43733965Sjdp 43833965Sjdp info->so_string = NULL; 43933965Sjdp 44033965Sjdp /* Now process whatever type we just got. */ 44133965Sjdp } 44233965Sjdp 44333965Sjdp switch (type) 44433965Sjdp { 44533965Sjdp case N_FN: 44633965Sjdp case N_FN_SEQ: 44733965Sjdp break; 44833965Sjdp 44933965Sjdp case N_LBRAC: 45033965Sjdp /* Ignore extra outermost context from SunPRO cc and acc. */ 45133965Sjdp if (info->n_opt_found && desc == 1) 45233965Sjdp break; 45333965Sjdp 45433965Sjdp if (! info->within_function) 45533965Sjdp { 45660484Sobrien fprintf (stderr, _("N_LBRAC not within function\n")); 457130561Sobrien return FALSE; 45833965Sjdp } 45933965Sjdp 46033965Sjdp /* Start an inner lexical block. */ 46133965Sjdp if (! debug_start_block (dhandle, 46233965Sjdp (value 46333965Sjdp + info->file_start_offset 46433965Sjdp + info->function_start_offset))) 465130561Sobrien return FALSE; 46633965Sjdp 46733965Sjdp /* Emit any pending variable definitions. */ 46833965Sjdp if (! stab_emit_pending_vars (dhandle, info)) 469130561Sobrien return FALSE; 47033965Sjdp 47133965Sjdp ++info->block_depth; 47233965Sjdp break; 47333965Sjdp 47433965Sjdp case N_RBRAC: 47533965Sjdp /* Ignore extra outermost context from SunPRO cc and acc. */ 47633965Sjdp if (info->n_opt_found && desc == 1) 47733965Sjdp break; 47833965Sjdp 47933965Sjdp /* We shouldn't have any pending variable definitions here, but, 48033965Sjdp if we do, we probably need to emit them before closing the 48133965Sjdp block. */ 48233965Sjdp if (! stab_emit_pending_vars (dhandle, info)) 483130561Sobrien return FALSE; 48433965Sjdp 48533965Sjdp /* End an inner lexical block. */ 48633965Sjdp if (! debug_end_block (dhandle, 48733965Sjdp (value 48833965Sjdp + info->file_start_offset 48933965Sjdp + info->function_start_offset))) 490130561Sobrien return FALSE; 49133965Sjdp 49233965Sjdp --info->block_depth; 49333965Sjdp if (info->block_depth < 0) 49433965Sjdp { 49560484Sobrien fprintf (stderr, _("Too many N_RBRACs\n")); 496130561Sobrien return FALSE; 49733965Sjdp } 49833965Sjdp break; 49933965Sjdp 50033965Sjdp case N_SO: 50133965Sjdp /* This always ends a function. */ 50233965Sjdp if (info->within_function) 50333965Sjdp { 50433965Sjdp bfd_vma endval; 50533965Sjdp 50633965Sjdp endval = value; 50733965Sjdp if (*string != '\0' 50833965Sjdp && info->function_end != (bfd_vma) -1 50933965Sjdp && info->function_end < endval) 51033965Sjdp endval = info->function_end; 51133965Sjdp if (! stab_emit_pending_vars (dhandle, info) 51233965Sjdp || ! debug_end_function (dhandle, endval)) 513130561Sobrien return FALSE; 514130561Sobrien info->within_function = FALSE; 51533965Sjdp info->function_end = (bfd_vma) -1; 51633965Sjdp } 51733965Sjdp 51833965Sjdp /* An empty string is emitted by gcc at the end of a compilation 51933965Sjdp unit. */ 52033965Sjdp if (*string == '\0') 521130561Sobrien return TRUE; 52233965Sjdp 52333965Sjdp /* Just accumulate strings until we see a non N_SO symbol. If 52460484Sobrien the string starts with a directory separator or some other 52560484Sobrien form of absolute path specification, we discard the previously 52633965Sjdp accumulated strings. */ 52733965Sjdp if (info->so_string == NULL) 52833965Sjdp info->so_string = xstrdup (string); 52933965Sjdp else 53033965Sjdp { 53133965Sjdp char *f; 53233965Sjdp 53333965Sjdp f = info->so_string; 53460484Sobrien 535104834Sobrien if (IS_ABSOLUTE_PATH (string)) 53633965Sjdp info->so_string = xstrdup (string); 53733965Sjdp else 53833965Sjdp info->so_string = concat (info->so_string, string, 53933965Sjdp (const char *) NULL); 54033965Sjdp free (f); 54133965Sjdp } 54233965Sjdp 54333965Sjdp info->so_value = value; 54433965Sjdp 54533965Sjdp break; 54633965Sjdp 54733965Sjdp case N_SOL: 54833965Sjdp /* Start an include file. */ 54933965Sjdp if (! debug_start_source (dhandle, string)) 550130561Sobrien return FALSE; 55133965Sjdp break; 55233965Sjdp 55333965Sjdp case N_BINCL: 55433965Sjdp /* Start an include file which may be replaced. */ 55533965Sjdp push_bincl (info, string, value); 55633965Sjdp if (! debug_start_source (dhandle, string)) 557130561Sobrien return FALSE; 55833965Sjdp break; 55933965Sjdp 56033965Sjdp case N_EINCL: 56133965Sjdp /* End an N_BINCL include. */ 56233965Sjdp if (! debug_start_source (dhandle, pop_bincl (info))) 563130561Sobrien return FALSE; 56433965Sjdp break; 56533965Sjdp 56633965Sjdp case N_EXCL: 56733965Sjdp /* This is a duplicate of a header file named by N_BINCL which 56833965Sjdp was eliminated by the linker. */ 56933965Sjdp if (! find_excl (info, string, value)) 570130561Sobrien return FALSE; 57133965Sjdp break; 57233965Sjdp 57333965Sjdp case N_SLINE: 57433965Sjdp if (! debug_record_line (dhandle, desc, 575130561Sobrien value + (info->within_function 576130561Sobrien ? info->function_start_offset : 0))) 577130561Sobrien return FALSE; 57833965Sjdp break; 57933965Sjdp 58033965Sjdp case N_BCOMM: 58133965Sjdp if (! debug_start_common_block (dhandle, string)) 582130561Sobrien return FALSE; 58333965Sjdp break; 58433965Sjdp 58533965Sjdp case N_ECOMM: 58633965Sjdp if (! debug_end_common_block (dhandle, string)) 587130561Sobrien return FALSE; 58833965Sjdp break; 58933965Sjdp 59033965Sjdp case N_FUN: 59133965Sjdp if (*string == '\0') 59233965Sjdp { 59333965Sjdp if (info->within_function) 59433965Sjdp { 59533965Sjdp /* This always marks the end of a function; we don't 59633965Sjdp need to worry about info->function_end. */ 59733965Sjdp if (info->sections) 59833965Sjdp value += info->function_start_offset; 59933965Sjdp if (! stab_emit_pending_vars (dhandle, info) 60033965Sjdp || ! debug_end_function (dhandle, value)) 601130561Sobrien return FALSE; 602130561Sobrien info->within_function = FALSE; 60333965Sjdp info->function_end = (bfd_vma) -1; 60433965Sjdp } 60533965Sjdp break; 60633965Sjdp } 60733965Sjdp 60833965Sjdp /* A const static symbol in the .text section will have an N_FUN 60933965Sjdp entry. We need to use these to mark the end of the function, 61033965Sjdp in case we are looking at gcc output before it was changed to 61133965Sjdp always emit an empty N_FUN. We can't call debug_end_function 61233965Sjdp here, because it might be a local static symbol. */ 61333965Sjdp if (info->within_function 61433965Sjdp && (info->function_end == (bfd_vma) -1 61533965Sjdp || value < info->function_end)) 61633965Sjdp info->function_end = value; 61733965Sjdp 61833965Sjdp /* Fall through. */ 61933965Sjdp /* FIXME: gdb checks the string for N_STSYM, N_LCSYM or N_ROSYM 62033965Sjdp symbols, and if it does not start with :S, gdb relocates the 62133965Sjdp value to the start of the section. gcc always seems to use 62233965Sjdp :S, so we don't worry about this. */ 62333965Sjdp /* Fall through. */ 62433965Sjdp default: 62533965Sjdp { 62633965Sjdp const char *colon; 62733965Sjdp 62833965Sjdp colon = strchr (string, ':'); 62933965Sjdp if (colon != NULL 63033965Sjdp && (colon[1] == 'f' || colon[1] == 'F')) 63133965Sjdp { 63233965Sjdp if (info->within_function) 63333965Sjdp { 63433965Sjdp bfd_vma endval; 63533965Sjdp 63633965Sjdp endval = value; 63733965Sjdp if (info->function_end != (bfd_vma) -1 63833965Sjdp && info->function_end < endval) 63933965Sjdp endval = info->function_end; 64033965Sjdp if (! stab_emit_pending_vars (dhandle, info) 64133965Sjdp || ! debug_end_function (dhandle, endval)) 642130561Sobrien return FALSE; 64333965Sjdp info->function_end = (bfd_vma) -1; 64433965Sjdp } 64533965Sjdp /* For stabs in sections, line numbers and block addresses 64633965Sjdp are offsets from the start of the function. */ 64733965Sjdp if (info->sections) 64833965Sjdp info->function_start_offset = value; 649130561Sobrien info->within_function = TRUE; 65033965Sjdp } 65133965Sjdp 65233965Sjdp if (! parse_stab_string (dhandle, info, type, desc, value, string)) 653130561Sobrien return FALSE; 65433965Sjdp } 65533965Sjdp break; 65633965Sjdp 65733965Sjdp case N_OPT: 65833965Sjdp if (string != NULL && strcmp (string, "gcc2_compiled.") == 0) 65933965Sjdp info->gcc_compiled = 2; 66033965Sjdp else if (string != NULL && strcmp (string, "gcc_compiled.") == 0) 66133965Sjdp info->gcc_compiled = 1; 66233965Sjdp else 663130561Sobrien info->n_opt_found = TRUE; 66433965Sjdp break; 66533965Sjdp 66633965Sjdp case N_OBJ: 66733965Sjdp case N_ENDM: 66833965Sjdp case N_MAIN: 66977298Sobrien case N_WARNING: 67033965Sjdp break; 67133965Sjdp } 67233965Sjdp 673130561Sobrien return TRUE; 67433965Sjdp} 67533965Sjdp 67633965Sjdp/* Parse the stabs string. */ 67733965Sjdp 678130561Sobrienstatic bfd_boolean 679130561Sobrienparse_stab_string (void *dhandle, struct stab_handle *info, int stabtype, 680130561Sobrien int desc, bfd_vma value, const char *string) 68133965Sjdp{ 68233965Sjdp const char *p; 68333965Sjdp char *name; 68433965Sjdp int type; 68533965Sjdp debug_type dtype; 686130561Sobrien bfd_boolean synonym; 687130561Sobrien bfd_boolean self_crossref; 68833965Sjdp unsigned int lineno; 68933965Sjdp debug_type *slot; 69033965Sjdp 69133965Sjdp p = strchr (string, ':'); 69233965Sjdp if (p == NULL) 693130561Sobrien return TRUE; 69433965Sjdp 69533965Sjdp while (p[1] == ':') 69633965Sjdp { 69733965Sjdp p += 2; 69833965Sjdp p = strchr (p, ':'); 69933965Sjdp if (p == NULL) 70033965Sjdp { 70133965Sjdp bad_stab (string); 702130561Sobrien return FALSE; 70333965Sjdp } 70433965Sjdp } 70533965Sjdp 70633965Sjdp /* GCC 2.x puts the line number in desc. SunOS apparently puts in 70733965Sjdp the number of bytes occupied by a type or object, which we 70833965Sjdp ignore. */ 70933965Sjdp if (info->gcc_compiled >= 2) 71033965Sjdp lineno = desc; 71133965Sjdp else 71233965Sjdp lineno = 0; 71333965Sjdp 71433965Sjdp /* FIXME: Sometimes the special C++ names start with '.'. */ 71533965Sjdp name = NULL; 71633965Sjdp if (string[0] == '$') 71733965Sjdp { 71833965Sjdp switch (string[1]) 71933965Sjdp { 72033965Sjdp case 't': 72133965Sjdp name = "this"; 72233965Sjdp break; 72333965Sjdp case 'v': 72433965Sjdp /* Was: name = "vptr"; */ 72533965Sjdp break; 72633965Sjdp case 'e': 72733965Sjdp name = "eh_throw"; 72833965Sjdp break; 72933965Sjdp case '_': 73033965Sjdp /* This was an anonymous type that was never fixed up. */ 73133965Sjdp break; 73233965Sjdp case 'X': 73333965Sjdp /* SunPRO (3.0 at least) static variable encoding. */ 73433965Sjdp break; 73533965Sjdp default: 73660484Sobrien warn_stab (string, _("unknown C++ encoded name")); 73733965Sjdp break; 73833965Sjdp } 73933965Sjdp } 74033965Sjdp 74133965Sjdp if (name == NULL) 74233965Sjdp { 74333965Sjdp if (p == string || (string[0] == ' ' && p == string + 1)) 74433965Sjdp name = NULL; 74533965Sjdp else 74633965Sjdp name = savestring (string, p - string); 74733965Sjdp } 74833965Sjdp 74933965Sjdp ++p; 75089857Sobrien if (ISDIGIT (*p) || *p == '(' || *p == '-') 75133965Sjdp type = 'l'; 75233965Sjdp else 75333965Sjdp type = *p++; 75433965Sjdp 75533965Sjdp switch (type) 75633965Sjdp { 75733965Sjdp case 'c': 75833965Sjdp /* c is a special case, not followed by a type-number. 75933965Sjdp SYMBOL:c=iVALUE for an integer constant symbol. 76033965Sjdp SYMBOL:c=rVALUE for a floating constant symbol. 76133965Sjdp SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol. 76233965Sjdp e.g. "b:c=e6,0" for "const b = blob1" 76333965Sjdp (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */ 76433965Sjdp if (*p != '=') 76533965Sjdp { 76633965Sjdp bad_stab (string); 767130561Sobrien return FALSE; 76833965Sjdp } 76933965Sjdp ++p; 77033965Sjdp switch (*p++) 77133965Sjdp { 77233965Sjdp case 'r': 77333965Sjdp /* Floating point constant. */ 77433965Sjdp if (! debug_record_float_const (dhandle, name, atof (p))) 775130561Sobrien return FALSE; 77633965Sjdp break; 77733965Sjdp case 'i': 77833965Sjdp /* Integer constant. */ 77933965Sjdp /* Defining integer constants this way is kind of silly, 78033965Sjdp since 'e' constants allows the compiler to give not only 78133965Sjdp the value, but the type as well. C has at least int, 78233965Sjdp long, unsigned int, and long long as constant types; 78333965Sjdp other languages probably should have at least unsigned as 78433965Sjdp well as signed constants. */ 78533965Sjdp if (! debug_record_int_const (dhandle, name, atoi (p))) 786130561Sobrien return FALSE; 78733965Sjdp break; 78833965Sjdp case 'e': 78933965Sjdp /* SYMBOL:c=eTYPE,INTVALUE for a constant symbol whose value 79033965Sjdp can be represented as integral. 79133965Sjdp e.g. "b:c=e6,0" for "const b = blob1" 79233965Sjdp (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */ 79333965Sjdp dtype = parse_stab_type (dhandle, info, (const char *) NULL, 79433965Sjdp &p, (debug_type **) NULL); 79533965Sjdp if (dtype == DEBUG_TYPE_NULL) 796130561Sobrien return FALSE; 79733965Sjdp if (*p != ',') 79833965Sjdp { 79933965Sjdp bad_stab (string); 800130561Sobrien return FALSE; 80133965Sjdp } 80233965Sjdp if (! debug_record_typed_const (dhandle, name, dtype, atoi (p))) 803130561Sobrien return FALSE; 80433965Sjdp break; 80533965Sjdp default: 80633965Sjdp bad_stab (string); 807130561Sobrien return FALSE; 80833965Sjdp } 80933965Sjdp 81033965Sjdp break; 81133965Sjdp 81233965Sjdp case 'C': 81333965Sjdp /* The name of a caught exception. */ 81433965Sjdp dtype = parse_stab_type (dhandle, info, (const char *) NULL, 81533965Sjdp &p, (debug_type **) NULL); 81633965Sjdp if (dtype == DEBUG_TYPE_NULL) 817130561Sobrien return FALSE; 81833965Sjdp if (! debug_record_label (dhandle, name, dtype, value)) 819130561Sobrien return FALSE; 82033965Sjdp break; 82133965Sjdp 82233965Sjdp case 'f': 82333965Sjdp case 'F': 82433965Sjdp /* A function definition. */ 82533965Sjdp dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p, 82633965Sjdp (debug_type **) NULL); 82733965Sjdp if (dtype == DEBUG_TYPE_NULL) 828130561Sobrien return FALSE; 82933965Sjdp if (! debug_record_function (dhandle, name, dtype, type == 'F', value)) 830130561Sobrien return FALSE; 83133965Sjdp 83233965Sjdp /* Sun acc puts declared types of arguments here. We don't care 83333965Sjdp about their actual types (FIXME -- we should remember the whole 83433965Sjdp function prototype), but the list may define some new types 83533965Sjdp that we have to remember, so we must scan it now. */ 83633965Sjdp while (*p == ';') 83733965Sjdp { 83833965Sjdp ++p; 83933965Sjdp if (parse_stab_type (dhandle, info, (const char *) NULL, &p, 84033965Sjdp (debug_type **) NULL) 84133965Sjdp == DEBUG_TYPE_NULL) 842130561Sobrien return FALSE; 84333965Sjdp } 84433965Sjdp 84533965Sjdp break; 84633965Sjdp 84733965Sjdp case 'G': 84833965Sjdp { 84933965Sjdp char leading; 85033965Sjdp long c; 85133965Sjdp asymbol **ps; 85233965Sjdp 85333965Sjdp /* A global symbol. The value must be extracted from the 85433965Sjdp symbol table. */ 85533965Sjdp dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p, 85633965Sjdp (debug_type **) NULL); 85733965Sjdp if (dtype == DEBUG_TYPE_NULL) 858130561Sobrien return FALSE; 85933965Sjdp leading = bfd_get_symbol_leading_char (info->abfd); 86033965Sjdp for (c = info->symcount, ps = info->syms; c > 0; --c, ++ps) 86133965Sjdp { 86233965Sjdp const char *n; 86333965Sjdp 86433965Sjdp n = bfd_asymbol_name (*ps); 86533965Sjdp if (leading != '\0' && *n == leading) 86633965Sjdp ++n; 86733965Sjdp if (*n == *name && strcmp (n, name) == 0) 86833965Sjdp break; 86933965Sjdp } 87033965Sjdp if (c > 0) 87133965Sjdp value = bfd_asymbol_value (*ps); 87233965Sjdp if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_GLOBAL, 87333965Sjdp value)) 874130561Sobrien return FALSE; 87533965Sjdp } 87633965Sjdp break; 87733965Sjdp 87833965Sjdp /* This case is faked by a conditional above, when there is no 87933965Sjdp code letter in the dbx data. Dbx data never actually 88033965Sjdp contains 'l'. */ 88133965Sjdp case 'l': 88233965Sjdp case 's': 88333965Sjdp dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p, 88433965Sjdp (debug_type **) NULL); 88533965Sjdp if (dtype == DEBUG_TYPE_NULL) 886130561Sobrien return FALSE; 88733965Sjdp if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_LOCAL, 88833965Sjdp value)) 889130561Sobrien return FALSE; 89033965Sjdp break; 89133965Sjdp 89233965Sjdp case 'p': 89333965Sjdp /* A function parameter. */ 89433965Sjdp if (*p != 'F') 89533965Sjdp dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p, 89633965Sjdp (debug_type **) NULL); 89733965Sjdp else 89833965Sjdp { 89933965Sjdp /* pF is a two-letter code that means a function parameter in 90033965Sjdp Fortran. The type-number specifies the type of the return 90133965Sjdp value. Translate it into a pointer-to-function type. */ 90233965Sjdp ++p; 90333965Sjdp dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p, 90433965Sjdp (debug_type **) NULL); 90533965Sjdp if (dtype != DEBUG_TYPE_NULL) 90633965Sjdp { 90733965Sjdp debug_type ftype; 90833965Sjdp 90933965Sjdp ftype = debug_make_function_type (dhandle, dtype, 910130561Sobrien (debug_type *) NULL, FALSE); 91133965Sjdp dtype = debug_make_pointer_type (dhandle, ftype); 91233965Sjdp } 91333965Sjdp } 91433965Sjdp if (dtype == DEBUG_TYPE_NULL) 915130561Sobrien return FALSE; 91633965Sjdp if (! debug_record_parameter (dhandle, name, dtype, DEBUG_PARM_STACK, 91733965Sjdp value)) 918130561Sobrien return FALSE; 91933965Sjdp 92033965Sjdp /* FIXME: At this point gdb considers rearranging the parameter 92133965Sjdp address on a big endian machine if it is smaller than an int. 92233965Sjdp We have no way to do that, since we don't really know much 92333965Sjdp about the target. */ 92433965Sjdp break; 92533965Sjdp 92633965Sjdp case 'P': 92733965Sjdp if (stabtype == N_FUN) 92833965Sjdp { 92933965Sjdp /* Prototype of a function referenced by this file. */ 93033965Sjdp while (*p == ';') 93133965Sjdp { 93233965Sjdp ++p; 93333965Sjdp if (parse_stab_type (dhandle, info, (const char *) NULL, &p, 93433965Sjdp (debug_type **) NULL) 93533965Sjdp == DEBUG_TYPE_NULL) 936130561Sobrien return FALSE; 93733965Sjdp } 93833965Sjdp break; 93933965Sjdp } 94033965Sjdp /* Fall through. */ 94133965Sjdp case 'R': 94233965Sjdp /* Parameter which is in a register. */ 94333965Sjdp dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p, 94433965Sjdp (debug_type **) NULL); 94533965Sjdp if (dtype == DEBUG_TYPE_NULL) 946130561Sobrien return FALSE; 94733965Sjdp if (! debug_record_parameter (dhandle, name, dtype, DEBUG_PARM_REG, 94833965Sjdp value)) 949130561Sobrien return FALSE; 95033965Sjdp break; 95133965Sjdp 95233965Sjdp case 'r': 95333965Sjdp /* Register variable (either global or local). */ 95433965Sjdp dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p, 95533965Sjdp (debug_type **) NULL); 95633965Sjdp if (dtype == DEBUG_TYPE_NULL) 957130561Sobrien return FALSE; 95833965Sjdp if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_REGISTER, 95933965Sjdp value)) 960130561Sobrien return FALSE; 96133965Sjdp 96233965Sjdp /* FIXME: At this point gdb checks to combine pairs of 'p' and 96333965Sjdp 'r' stabs into a single 'P' stab. */ 96433965Sjdp break; 96533965Sjdp 96633965Sjdp case 'S': 967130561Sobrien /* Static symbol at top level of file. */ 96833965Sjdp dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p, 96933965Sjdp (debug_type **) NULL); 97033965Sjdp if (dtype == DEBUG_TYPE_NULL) 971130561Sobrien return FALSE; 97233965Sjdp if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_STATIC, 97333965Sjdp value)) 974130561Sobrien return FALSE; 97533965Sjdp break; 97633965Sjdp 97733965Sjdp case 't': 97833965Sjdp /* A typedef. */ 97933965Sjdp dtype = parse_stab_type (dhandle, info, name, &p, &slot); 98033965Sjdp if (dtype == DEBUG_TYPE_NULL) 981130561Sobrien return FALSE; 98233965Sjdp if (name == NULL) 98333965Sjdp { 98433965Sjdp /* A nameless type. Nothing to do. */ 985130561Sobrien return TRUE; 98633965Sjdp } 98733965Sjdp 98833965Sjdp dtype = debug_name_type (dhandle, name, dtype); 98933965Sjdp if (dtype == DEBUG_TYPE_NULL) 990130561Sobrien return FALSE; 99133965Sjdp 99233965Sjdp if (slot != NULL) 99333965Sjdp *slot = dtype; 99433965Sjdp 99533965Sjdp break; 99633965Sjdp 99733965Sjdp case 'T': 99833965Sjdp /* Struct, union, or enum tag. For GNU C++, this can be be followed 99933965Sjdp by 't' which means we are typedef'ing it as well. */ 100033965Sjdp if (*p != 't') 100133965Sjdp { 1002130561Sobrien synonym = FALSE; 1003130561Sobrien /* FIXME: gdb sets synonym to TRUE if the current language 100433965Sjdp is C++. */ 100533965Sjdp } 100633965Sjdp else 100733965Sjdp { 1008130561Sobrien synonym = TRUE; 100933965Sjdp ++p; 101033965Sjdp } 101133965Sjdp 101233965Sjdp dtype = parse_stab_type (dhandle, info, name, &p, &slot); 101333965Sjdp if (dtype == DEBUG_TYPE_NULL) 1014130561Sobrien return FALSE; 101533965Sjdp if (name == NULL) 1016130561Sobrien return TRUE; 101733965Sjdp 101860484Sobrien /* INFO->SELF_CROSSREF is set by parse_stab_type if this type is 101960484Sobrien a cross reference to itself. These are generated by some 102060484Sobrien versions of g++. */ 102160484Sobrien self_crossref = info->self_crossref; 102260484Sobrien 102333965Sjdp dtype = debug_tag_type (dhandle, name, dtype); 102433965Sjdp if (dtype == DEBUG_TYPE_NULL) 1025130561Sobrien return FALSE; 102633965Sjdp if (slot != NULL) 102733965Sjdp *slot = dtype; 102833965Sjdp 102933965Sjdp /* See if we have a cross reference to this tag which we can now 103060484Sobrien fill in. Avoid filling in a cross reference to ourselves, 103160484Sobrien because that would lead to circular debugging information. */ 103260484Sobrien if (! self_crossref) 103360484Sobrien { 103460484Sobrien register struct stab_tag **pst; 103533965Sjdp 103660484Sobrien for (pst = &info->tags; *pst != NULL; pst = &(*pst)->next) 103760484Sobrien { 103860484Sobrien if ((*pst)->name[0] == name[0] 103960484Sobrien && strcmp ((*pst)->name, name) == 0) 104060484Sobrien { 104160484Sobrien (*pst)->slot = dtype; 104260484Sobrien *pst = (*pst)->next; 104360484Sobrien break; 104460484Sobrien } 104560484Sobrien } 104660484Sobrien } 104733965Sjdp 104833965Sjdp if (synonym) 104933965Sjdp { 105033965Sjdp dtype = debug_name_type (dhandle, name, dtype); 105133965Sjdp if (dtype == DEBUG_TYPE_NULL) 1052130561Sobrien return FALSE; 105333965Sjdp 105433965Sjdp if (slot != NULL) 105533965Sjdp *slot = dtype; 105633965Sjdp } 105733965Sjdp 105833965Sjdp break; 105933965Sjdp 106033965Sjdp case 'V': 106133965Sjdp /* Static symbol of local scope */ 106233965Sjdp dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p, 106333965Sjdp (debug_type **) NULL); 106433965Sjdp if (dtype == DEBUG_TYPE_NULL) 1065130561Sobrien return FALSE; 106633965Sjdp /* FIXME: gdb checks os9k_stabs here. */ 106733965Sjdp if (! stab_record_variable (dhandle, info, name, dtype, 106833965Sjdp DEBUG_LOCAL_STATIC, value)) 1069130561Sobrien return FALSE; 107033965Sjdp break; 107133965Sjdp 107233965Sjdp case 'v': 107333965Sjdp /* Reference parameter. */ 107433965Sjdp dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p, 107533965Sjdp (debug_type **) NULL); 107633965Sjdp if (dtype == DEBUG_TYPE_NULL) 1077130561Sobrien return FALSE; 107833965Sjdp if (! debug_record_parameter (dhandle, name, dtype, DEBUG_PARM_REFERENCE, 107933965Sjdp value)) 1080130561Sobrien return FALSE; 108133965Sjdp break; 108233965Sjdp 108333965Sjdp case 'a': 108433965Sjdp /* Reference parameter which is in a register. */ 108533965Sjdp dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p, 108633965Sjdp (debug_type **) NULL); 108733965Sjdp if (dtype == DEBUG_TYPE_NULL) 1088130561Sobrien return FALSE; 108933965Sjdp if (! debug_record_parameter (dhandle, name, dtype, DEBUG_PARM_REF_REG, 109033965Sjdp value)) 1091130561Sobrien return FALSE; 109233965Sjdp break; 109333965Sjdp 109433965Sjdp case 'X': 109533965Sjdp /* This is used by Sun FORTRAN for "function result value". 109633965Sjdp Sun claims ("dbx and dbxtool interfaces", 2nd ed) 109733965Sjdp that Pascal uses it too, but when I tried it Pascal used 109833965Sjdp "x:3" (local symbol) instead. */ 109933965Sjdp dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p, 110033965Sjdp (debug_type **) NULL); 110133965Sjdp if (dtype == DEBUG_TYPE_NULL) 1102130561Sobrien return FALSE; 110333965Sjdp if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_LOCAL, 110433965Sjdp value)) 1105130561Sobrien return FALSE; 110633965Sjdp break; 110733965Sjdp 110833965Sjdp default: 110933965Sjdp bad_stab (string); 1110130561Sobrien return FALSE; 111133965Sjdp } 111233965Sjdp 111333965Sjdp /* FIXME: gdb converts structure values to structure pointers in a 111433965Sjdp couple of cases, depending upon the target. */ 111533965Sjdp 1116130561Sobrien return TRUE; 111733965Sjdp} 111833965Sjdp 111933965Sjdp/* Parse a stabs type. The typename argument is non-NULL if this is a 112033965Sjdp typedef or a tag definition. The pp argument points to the stab 112133965Sjdp string, and is updated. The slotp argument points to a place to 112233965Sjdp store the slot used if the type is being defined. */ 112333965Sjdp 112433965Sjdpstatic debug_type 1125130561Sobrienparse_stab_type (void *dhandle, struct stab_handle *info, const char *typename, const char **pp, debug_type **slotp) 112633965Sjdp{ 112733965Sjdp const char *orig; 112833965Sjdp int typenums[2]; 112933965Sjdp int size; 1130130561Sobrien bfd_boolean stringp; 113133965Sjdp int descriptor; 113233965Sjdp debug_type dtype; 113333965Sjdp 113433965Sjdp if (slotp != NULL) 113533965Sjdp *slotp = NULL; 113633965Sjdp 113733965Sjdp orig = *pp; 113833965Sjdp 113933965Sjdp size = -1; 1140130561Sobrien stringp = FALSE; 114133965Sjdp 1142130561Sobrien info->self_crossref = FALSE; 114360484Sobrien 114433965Sjdp /* Read type number if present. The type number may be omitted. 114533965Sjdp for instance in a two-dimensional array declared with type 114633965Sjdp "ar1;1;10;ar1;1;10;4". */ 114789857Sobrien if (! ISDIGIT (**pp) && **pp != '(' && **pp != '-') 114833965Sjdp { 114933965Sjdp /* 'typenums=' not present, type is anonymous. Read and return 115033965Sjdp the definition, but don't put it in the type vector. */ 115133965Sjdp typenums[0] = typenums[1] = -1; 115233965Sjdp } 115333965Sjdp else 115433965Sjdp { 115533965Sjdp if (! parse_stab_type_number (pp, typenums)) 115633965Sjdp return DEBUG_TYPE_NULL; 115733965Sjdp 115833965Sjdp if (**pp != '=') 1159130561Sobrien /* Type is not being defined here. Either it already 1160130561Sobrien exists, or this is a forward reference to it. */ 1161130561Sobrien return stab_find_type (dhandle, info, typenums); 116233965Sjdp 116333965Sjdp /* Only set the slot if the type is being defined. This means 116433965Sjdp that the mapping from type numbers to types will only record 116533965Sjdp the name of the typedef which defines a type. If we don't do 116633965Sjdp this, then something like 116733965Sjdp typedef int foo; 116833965Sjdp int i; 116933965Sjdp will record that i is of type foo. Unfortunately, stabs 117033965Sjdp information is ambiguous about variable types. For this code, 117133965Sjdp typedef int foo; 117233965Sjdp int i; 117333965Sjdp foo j; 117433965Sjdp the stabs information records both i and j as having the same 117533965Sjdp type. This could be fixed by patching the compiler. */ 117633965Sjdp if (slotp != NULL && typenums[0] >= 0 && typenums[1] >= 0) 117733965Sjdp *slotp = stab_find_slot (info, typenums); 117833965Sjdp 117933965Sjdp /* Type is being defined here. */ 118033965Sjdp /* Skip the '='. */ 118133965Sjdp ++*pp; 118233965Sjdp 118333965Sjdp while (**pp == '@') 118433965Sjdp { 118533965Sjdp const char *p = *pp + 1; 118633965Sjdp const char *attr; 118733965Sjdp 118889857Sobrien if (ISDIGIT (*p) || *p == '(' || *p == '-') 1189130561Sobrien /* Member type. */ 1190130561Sobrien break; 119133965Sjdp 119233965Sjdp /* Type attributes. */ 119333965Sjdp attr = p; 119433965Sjdp 119533965Sjdp for (; *p != ';'; ++p) 119633965Sjdp { 119733965Sjdp if (*p == '\0') 119833965Sjdp { 119933965Sjdp bad_stab (orig); 120033965Sjdp return DEBUG_TYPE_NULL; 120133965Sjdp } 120233965Sjdp } 120333965Sjdp *pp = p + 1; 120433965Sjdp 120533965Sjdp switch (*attr) 120633965Sjdp { 120733965Sjdp case 's': 120833965Sjdp size = atoi (attr + 1); 120968765Sobrien size /= 8; /* Size is in bits. We store it in bytes. */ 121033965Sjdp if (size <= 0) 121133965Sjdp size = -1; 121233965Sjdp break; 121333965Sjdp 121433965Sjdp case 'S': 1215130561Sobrien stringp = TRUE; 121633965Sjdp break; 121733965Sjdp 121833965Sjdp default: 121933965Sjdp /* Ignore unrecognized type attributes, so future 122033965Sjdp compilers can invent new ones. */ 122133965Sjdp break; 122233965Sjdp } 122333965Sjdp } 122433965Sjdp } 122533965Sjdp 122633965Sjdp descriptor = **pp; 122733965Sjdp ++*pp; 122833965Sjdp 122933965Sjdp switch (descriptor) 123033965Sjdp { 123133965Sjdp case 'x': 123233965Sjdp { 123333965Sjdp enum debug_type_kind code; 123433965Sjdp const char *q1, *q2, *p; 123533965Sjdp 123633965Sjdp /* A cross reference to another type. */ 123733965Sjdp switch (**pp) 123833965Sjdp { 123933965Sjdp case 's': 124033965Sjdp code = DEBUG_KIND_STRUCT; 124133965Sjdp break; 124233965Sjdp case 'u': 124333965Sjdp code = DEBUG_KIND_UNION; 124433965Sjdp break; 124533965Sjdp case 'e': 124633965Sjdp code = DEBUG_KIND_ENUM; 124733965Sjdp break; 124833965Sjdp default: 124933965Sjdp /* Complain and keep going, so compilers can invent new 125033965Sjdp cross-reference types. */ 125160484Sobrien warn_stab (orig, _("unrecognized cross reference type")); 125233965Sjdp code = DEBUG_KIND_STRUCT; 125333965Sjdp break; 125433965Sjdp } 125533965Sjdp ++*pp; 125633965Sjdp 125733965Sjdp q1 = strchr (*pp, '<'); 125833965Sjdp p = strchr (*pp, ':'); 125933965Sjdp if (p == NULL) 126033965Sjdp { 126133965Sjdp bad_stab (orig); 126233965Sjdp return DEBUG_TYPE_NULL; 126333965Sjdp } 126460484Sobrien if (q1 != NULL && p > q1 && p[1] == ':') 126533965Sjdp { 126660484Sobrien int nest = 0; 126760484Sobrien 126860484Sobrien for (q2 = q1; *q2 != '\0'; ++q2) 126933965Sjdp { 127060484Sobrien if (*q2 == '<') 127160484Sobrien ++nest; 127260484Sobrien else if (*q2 == '>') 127360484Sobrien --nest; 127460484Sobrien else if (*q2 == ':' && nest == 0) 127560484Sobrien break; 127660484Sobrien } 127760484Sobrien p = q2; 127860484Sobrien if (*p != ':') 127960484Sobrien { 128033965Sjdp bad_stab (orig); 128133965Sjdp return DEBUG_TYPE_NULL; 128233965Sjdp } 128333965Sjdp } 128433965Sjdp 128560484Sobrien /* Some versions of g++ can emit stabs like 128660484Sobrien fleep:T20=xsfleep: 128760484Sobrien which define structures in terms of themselves. We need to 128860484Sobrien tell the caller to avoid building a circular structure. */ 128960484Sobrien if (typename != NULL 129060484Sobrien && strncmp (typename, *pp, p - *pp) == 0 129160484Sobrien && typename[p - *pp] == '\0') 1292130561Sobrien info->self_crossref = TRUE; 129360484Sobrien 129433965Sjdp dtype = stab_find_tagged_type (dhandle, info, *pp, p - *pp, code); 129533965Sjdp 129633965Sjdp *pp = p + 1; 129733965Sjdp } 129833965Sjdp break; 129933965Sjdp 130033965Sjdp case '-': 130133965Sjdp case '0': 130233965Sjdp case '1': 130333965Sjdp case '2': 130433965Sjdp case '3': 130533965Sjdp case '4': 130633965Sjdp case '5': 130733965Sjdp case '6': 130833965Sjdp case '7': 130933965Sjdp case '8': 131033965Sjdp case '9': 131133965Sjdp case '(': 131233965Sjdp { 131333965Sjdp const char *hold; 131433965Sjdp int xtypenums[2]; 131533965Sjdp 131633965Sjdp /* This type is defined as another type. */ 131733965Sjdp (*pp)--; 131833965Sjdp hold = *pp; 131933965Sjdp 132033965Sjdp /* Peek ahead at the number to detect void. */ 132133965Sjdp if (! parse_stab_type_number (pp, xtypenums)) 132233965Sjdp return DEBUG_TYPE_NULL; 132333965Sjdp 132433965Sjdp if (typenums[0] == xtypenums[0] && typenums[1] == xtypenums[1]) 132533965Sjdp { 132633965Sjdp /* This type is being defined as itself, which means that 132733965Sjdp it is void. */ 132833965Sjdp dtype = debug_make_void_type (dhandle); 132933965Sjdp } 133033965Sjdp else 133133965Sjdp { 133233965Sjdp *pp = hold; 133333965Sjdp 133433965Sjdp /* Go back to the number and have parse_stab_type get it. 133533965Sjdp This means that we can deal with something like 133633965Sjdp t(1,2)=(3,4)=... which the Lucid compiler uses. */ 133733965Sjdp dtype = parse_stab_type (dhandle, info, (const char *) NULL, 133833965Sjdp pp, (debug_type **) NULL); 133933965Sjdp if (dtype == DEBUG_TYPE_NULL) 134033965Sjdp return DEBUG_TYPE_NULL; 134133965Sjdp } 134233965Sjdp 134333965Sjdp if (typenums[0] != -1) 134433965Sjdp { 134533965Sjdp if (! stab_record_type (dhandle, info, typenums, dtype)) 134633965Sjdp return DEBUG_TYPE_NULL; 134733965Sjdp } 134833965Sjdp 134933965Sjdp break; 135033965Sjdp } 135133965Sjdp 135233965Sjdp case '*': 135333965Sjdp dtype = debug_make_pointer_type (dhandle, 135433965Sjdp parse_stab_type (dhandle, info, 135533965Sjdp (const char *) NULL, 135633965Sjdp pp, 135733965Sjdp (debug_type **) NULL)); 135833965Sjdp break; 135933965Sjdp 136033965Sjdp case '&': 136133965Sjdp /* Reference to another type. */ 136233965Sjdp dtype = (debug_make_reference_type 136333965Sjdp (dhandle, 136433965Sjdp parse_stab_type (dhandle, info, (const char *) NULL, pp, 136533965Sjdp (debug_type **) NULL))); 136633965Sjdp break; 136733965Sjdp 136833965Sjdp case 'f': 136933965Sjdp /* Function returning another type. */ 137033965Sjdp /* FIXME: gdb checks os9k_stabs here. */ 137133965Sjdp dtype = (debug_make_function_type 137233965Sjdp (dhandle, 137333965Sjdp parse_stab_type (dhandle, info, (const char *) NULL, pp, 137433965Sjdp (debug_type **) NULL), 1375130561Sobrien (debug_type *) NULL, FALSE)); 137633965Sjdp break; 137733965Sjdp 137833965Sjdp case 'k': 137933965Sjdp /* Const qualifier on some type (Sun). */ 138033965Sjdp /* FIXME: gdb accepts 'c' here if os9k_stabs. */ 138133965Sjdp dtype = debug_make_const_type (dhandle, 138233965Sjdp parse_stab_type (dhandle, info, 138333965Sjdp (const char *) NULL, 138433965Sjdp pp, 138533965Sjdp (debug_type **) NULL)); 138633965Sjdp break; 138733965Sjdp 138833965Sjdp case 'B': 138933965Sjdp /* Volatile qual on some type (Sun). */ 139033965Sjdp /* FIXME: gdb accepts 'i' here if os9k_stabs. */ 139133965Sjdp dtype = (debug_make_volatile_type 139233965Sjdp (dhandle, 139333965Sjdp parse_stab_type (dhandle, info, (const char *) NULL, pp, 139433965Sjdp (debug_type **) NULL))); 139533965Sjdp break; 139633965Sjdp 139733965Sjdp case '@': 139833965Sjdp /* Offset (class & variable) type. This is used for a pointer 139933965Sjdp relative to an object. */ 140033965Sjdp { 140133965Sjdp debug_type domain; 140233965Sjdp debug_type memtype; 140333965Sjdp 140433965Sjdp /* Member type. */ 140533965Sjdp 140633965Sjdp domain = parse_stab_type (dhandle, info, (const char *) NULL, pp, 140733965Sjdp (debug_type **) NULL); 140833965Sjdp if (domain == DEBUG_TYPE_NULL) 140933965Sjdp return DEBUG_TYPE_NULL; 141033965Sjdp 141133965Sjdp if (**pp != ',') 141233965Sjdp { 141333965Sjdp bad_stab (orig); 141433965Sjdp return DEBUG_TYPE_NULL; 141533965Sjdp } 141633965Sjdp ++*pp; 141733965Sjdp 141833965Sjdp memtype = parse_stab_type (dhandle, info, (const char *) NULL, pp, 141933965Sjdp (debug_type **) NULL); 142033965Sjdp if (memtype == DEBUG_TYPE_NULL) 142133965Sjdp return DEBUG_TYPE_NULL; 142233965Sjdp 142333965Sjdp dtype = debug_make_offset_type (dhandle, domain, memtype); 142433965Sjdp } 142533965Sjdp break; 142633965Sjdp 142733965Sjdp case '#': 142833965Sjdp /* Method (class & fn) type. */ 142933965Sjdp if (**pp == '#') 143033965Sjdp { 143133965Sjdp debug_type return_type; 143233965Sjdp 143333965Sjdp ++*pp; 143433965Sjdp return_type = parse_stab_type (dhandle, info, (const char *) NULL, 143533965Sjdp pp, (debug_type **) NULL); 143633965Sjdp if (return_type == DEBUG_TYPE_NULL) 143733965Sjdp return DEBUG_TYPE_NULL; 143833965Sjdp if (**pp != ';') 143933965Sjdp { 144033965Sjdp bad_stab (orig); 144133965Sjdp return DEBUG_TYPE_NULL; 144233965Sjdp } 144333965Sjdp ++*pp; 144433965Sjdp dtype = debug_make_method_type (dhandle, return_type, 144533965Sjdp DEBUG_TYPE_NULL, 1446130561Sobrien (debug_type *) NULL, FALSE); 144733965Sjdp } 144833965Sjdp else 144933965Sjdp { 145033965Sjdp debug_type domain; 145133965Sjdp debug_type return_type; 145233965Sjdp debug_type *args; 145333965Sjdp unsigned int n; 145433965Sjdp unsigned int alloc; 1455130561Sobrien bfd_boolean varargs; 145633965Sjdp 145733965Sjdp domain = parse_stab_type (dhandle, info, (const char *) NULL, 145833965Sjdp pp, (debug_type **) NULL); 145933965Sjdp if (domain == DEBUG_TYPE_NULL) 146033965Sjdp return DEBUG_TYPE_NULL; 146133965Sjdp 146233965Sjdp if (**pp != ',') 146333965Sjdp { 146433965Sjdp bad_stab (orig); 146533965Sjdp return DEBUG_TYPE_NULL; 146633965Sjdp } 146733965Sjdp ++*pp; 146833965Sjdp 146933965Sjdp return_type = parse_stab_type (dhandle, info, (const char *) NULL, 147033965Sjdp pp, (debug_type **) NULL); 147133965Sjdp if (return_type == DEBUG_TYPE_NULL) 147233965Sjdp return DEBUG_TYPE_NULL; 147333965Sjdp 147433965Sjdp alloc = 10; 147533965Sjdp args = (debug_type *) xmalloc (alloc * sizeof *args); 147633965Sjdp n = 0; 147733965Sjdp while (**pp != ';') 147833965Sjdp { 147933965Sjdp if (**pp != ',') 148033965Sjdp { 148133965Sjdp bad_stab (orig); 148233965Sjdp return DEBUG_TYPE_NULL; 148333965Sjdp } 148433965Sjdp ++*pp; 148533965Sjdp 148633965Sjdp if (n + 1 >= alloc) 148733965Sjdp { 148833965Sjdp alloc += 10; 148933965Sjdp args = ((debug_type *) 1490130561Sobrien xrealloc (args, alloc * sizeof *args)); 149133965Sjdp } 149233965Sjdp 149333965Sjdp args[n] = parse_stab_type (dhandle, info, (const char *) NULL, 149433965Sjdp pp, (debug_type **) NULL); 149533965Sjdp if (args[n] == DEBUG_TYPE_NULL) 149633965Sjdp return DEBUG_TYPE_NULL; 149733965Sjdp ++n; 149833965Sjdp } 149933965Sjdp ++*pp; 150033965Sjdp 150133965Sjdp /* If the last type is not void, then this function takes a 150233965Sjdp variable number of arguments. Otherwise, we must strip 150333965Sjdp the void type. */ 150433965Sjdp if (n == 0 150533965Sjdp || debug_get_type_kind (dhandle, args[n - 1]) != DEBUG_KIND_VOID) 1506130561Sobrien varargs = TRUE; 150733965Sjdp else 150833965Sjdp { 150933965Sjdp --n; 1510130561Sobrien varargs = FALSE; 151133965Sjdp } 151233965Sjdp 151333965Sjdp args[n] = DEBUG_TYPE_NULL; 151433965Sjdp 151533965Sjdp dtype = debug_make_method_type (dhandle, return_type, domain, args, 151633965Sjdp varargs); 151733965Sjdp } 151833965Sjdp break; 151933965Sjdp 152033965Sjdp case 'r': 152133965Sjdp /* Range type. */ 152233965Sjdp dtype = parse_stab_range_type (dhandle, info, typename, pp, typenums); 152333965Sjdp break; 152433965Sjdp 152533965Sjdp case 'b': 152633965Sjdp /* FIXME: gdb checks os9k_stabs here. */ 152733965Sjdp /* Sun ACC builtin int type. */ 152833965Sjdp dtype = parse_stab_sun_builtin_type (dhandle, pp); 152933965Sjdp break; 153033965Sjdp 153133965Sjdp case 'R': 153233965Sjdp /* Sun ACC builtin float type. */ 153333965Sjdp dtype = parse_stab_sun_floating_type (dhandle, pp); 153433965Sjdp break; 153533965Sjdp 153633965Sjdp case 'e': 153733965Sjdp /* Enumeration type. */ 153833965Sjdp dtype = parse_stab_enum_type (dhandle, pp); 153933965Sjdp break; 154033965Sjdp 154133965Sjdp case 's': 154233965Sjdp case 'u': 154333965Sjdp /* Struct or union type. */ 154433965Sjdp dtype = parse_stab_struct_type (dhandle, info, typename, pp, 154533965Sjdp descriptor == 's', typenums); 154633965Sjdp break; 154733965Sjdp 154833965Sjdp case 'a': 154933965Sjdp /* Array type. */ 155033965Sjdp if (**pp != 'r') 155133965Sjdp { 155233965Sjdp bad_stab (orig); 155333965Sjdp return DEBUG_TYPE_NULL; 155433965Sjdp } 155533965Sjdp ++*pp; 155633965Sjdp 155733965Sjdp dtype = parse_stab_array_type (dhandle, info, pp, stringp); 155833965Sjdp break; 155933965Sjdp 156033965Sjdp case 'S': 156133965Sjdp dtype = debug_make_set_type (dhandle, 156233965Sjdp parse_stab_type (dhandle, info, 156333965Sjdp (const char *) NULL, 156433965Sjdp pp, 156533965Sjdp (debug_type **) NULL), 156633965Sjdp stringp); 156733965Sjdp break; 156833965Sjdp 156933965Sjdp default: 157033965Sjdp bad_stab (orig); 157133965Sjdp return DEBUG_TYPE_NULL; 157233965Sjdp } 157333965Sjdp 157433965Sjdp if (dtype == DEBUG_TYPE_NULL) 157533965Sjdp return DEBUG_TYPE_NULL; 157633965Sjdp 157733965Sjdp if (typenums[0] != -1) 157833965Sjdp { 157933965Sjdp if (! stab_record_type (dhandle, info, typenums, dtype)) 158033965Sjdp return DEBUG_TYPE_NULL; 158133965Sjdp } 158233965Sjdp 158333965Sjdp if (size != -1) 158433965Sjdp { 158533965Sjdp if (! debug_record_type_size (dhandle, dtype, (unsigned int) size)) 158660484Sobrien return DEBUG_TYPE_NULL; 158733965Sjdp } 158833965Sjdp 158933965Sjdp return dtype; 159033965Sjdp} 159133965Sjdp 159233965Sjdp/* Read a number by which a type is referred to in dbx data, or 159333965Sjdp perhaps read a pair (FILENUM, TYPENUM) in parentheses. Just a 159433965Sjdp single number N is equivalent to (0,N). Return the two numbers by 159533965Sjdp storing them in the vector TYPENUMS. */ 159633965Sjdp 1597130561Sobrienstatic bfd_boolean 1598130561Sobrienparse_stab_type_number (const char **pp, int *typenums) 159933965Sjdp{ 160033965Sjdp const char *orig; 160133965Sjdp 160233965Sjdp orig = *pp; 160333965Sjdp 160433965Sjdp if (**pp != '(') 160533965Sjdp { 160633965Sjdp typenums[0] = 0; 1607130561Sobrien typenums[1] = (int) parse_number (pp, (bfd_boolean *) NULL); 160833965Sjdp } 160933965Sjdp else 161033965Sjdp { 161133965Sjdp ++*pp; 1612130561Sobrien typenums[0] = (int) parse_number (pp, (bfd_boolean *) NULL); 161333965Sjdp if (**pp != ',') 161433965Sjdp { 161533965Sjdp bad_stab (orig); 1616130561Sobrien return FALSE; 161733965Sjdp } 161833965Sjdp ++*pp; 1619130561Sobrien typenums[1] = (int) parse_number (pp, (bfd_boolean *) NULL); 162033965Sjdp if (**pp != ')') 162133965Sjdp { 162233965Sjdp bad_stab (orig); 1623130561Sobrien return FALSE; 162433965Sjdp } 162533965Sjdp ++*pp; 162633965Sjdp } 162733965Sjdp 1628130561Sobrien return TRUE; 162933965Sjdp} 163033965Sjdp 163133965Sjdp/* Parse a range type. */ 163233965Sjdp 163333965Sjdpstatic debug_type 1634130561Sobrienparse_stab_range_type (void *dhandle, struct stab_handle *info, const char *typename, const char **pp, const int *typenums) 163533965Sjdp{ 163633965Sjdp const char *orig; 163733965Sjdp int rangenums[2]; 1638130561Sobrien bfd_boolean self_subrange; 163933965Sjdp debug_type index_type; 164033965Sjdp const char *s2, *s3; 164133965Sjdp bfd_signed_vma n2, n3; 1642130561Sobrien bfd_boolean ov2, ov3; 164333965Sjdp 164433965Sjdp orig = *pp; 164533965Sjdp 164633965Sjdp index_type = DEBUG_TYPE_NULL; 164733965Sjdp 164833965Sjdp /* First comes a type we are a subrange of. 164933965Sjdp In C it is usually 0, 1 or the type being defined. */ 165033965Sjdp if (! parse_stab_type_number (pp, rangenums)) 165133965Sjdp return DEBUG_TYPE_NULL; 165233965Sjdp 165333965Sjdp self_subrange = (rangenums[0] == typenums[0] 165433965Sjdp && rangenums[1] == typenums[1]); 165533965Sjdp 165633965Sjdp if (**pp == '=') 165733965Sjdp { 165833965Sjdp *pp = orig; 165933965Sjdp index_type = parse_stab_type (dhandle, info, (const char *) NULL, 166033965Sjdp pp, (debug_type **) NULL); 166133965Sjdp if (index_type == DEBUG_TYPE_NULL) 166233965Sjdp return DEBUG_TYPE_NULL; 166333965Sjdp } 166433965Sjdp 166533965Sjdp if (**pp == ';') 166633965Sjdp ++*pp; 166733965Sjdp 166833965Sjdp /* The remaining two operands are usually lower and upper bounds of 166933965Sjdp the range. But in some special cases they mean something else. */ 167033965Sjdp s2 = *pp; 167133965Sjdp n2 = parse_number (pp, &ov2); 167233965Sjdp if (**pp != ';') 167333965Sjdp { 167433965Sjdp bad_stab (orig); 167533965Sjdp return DEBUG_TYPE_NULL; 167633965Sjdp } 167733965Sjdp ++*pp; 167833965Sjdp 167933965Sjdp s3 = *pp; 168033965Sjdp n3 = parse_number (pp, &ov3); 168133965Sjdp if (**pp != ';') 168233965Sjdp { 168333965Sjdp bad_stab (orig); 168433965Sjdp return DEBUG_TYPE_NULL; 168533965Sjdp } 168633965Sjdp ++*pp; 168733965Sjdp 168833965Sjdp if (ov2 || ov3) 168933965Sjdp { 169033965Sjdp /* gcc will emit range stabs for long long types. Handle this 169133965Sjdp as a special case. FIXME: This needs to be more general. */ 1692130561Sobrien#define LLLOW "01000000000000000000000;" 1693130561Sobrien#define LLHIGH "0777777777777777777777;" 169433965Sjdp#define ULLHIGH "01777777777777777777777;" 169533965Sjdp if (index_type == DEBUG_TYPE_NULL) 169633965Sjdp { 1697218822Sdim if (CONST_STRNEQ (s2, LLLOW) 1698218822Sdim && CONST_STRNEQ (s3, LLHIGH)) 1699130561Sobrien return debug_make_int_type (dhandle, 8, FALSE); 170033965Sjdp if (! ov2 170133965Sjdp && n2 == 0 1702218822Sdim && CONST_STRNEQ (s3, ULLHIGH)) 1703130561Sobrien return debug_make_int_type (dhandle, 8, TRUE); 170433965Sjdp } 170533965Sjdp 170660484Sobrien warn_stab (orig, _("numeric overflow")); 170733965Sjdp } 170833965Sjdp 170933965Sjdp if (index_type == DEBUG_TYPE_NULL) 171033965Sjdp { 171133965Sjdp /* A type defined as a subrange of itself, with both bounds 0, 171233965Sjdp is void. */ 171333965Sjdp if (self_subrange && n2 == 0 && n3 == 0) 171433965Sjdp return debug_make_void_type (dhandle); 171533965Sjdp 171633965Sjdp /* A type defined as a subrange of itself, with n2 positive and 171733965Sjdp n3 zero, is a complex type, and n2 is the number of bytes. */ 171833965Sjdp if (self_subrange && n3 == 0 && n2 > 0) 171933965Sjdp return debug_make_complex_type (dhandle, n2); 172033965Sjdp 172133965Sjdp /* If n3 is zero and n2 is positive, this is a floating point 172233965Sjdp type, and n2 is the number of bytes. */ 172333965Sjdp if (n3 == 0 && n2 > 0) 172433965Sjdp return debug_make_float_type (dhandle, n2); 172533965Sjdp 172633965Sjdp /* If the upper bound is -1, this is an unsigned int. */ 172733965Sjdp if (n2 == 0 && n3 == -1) 172833965Sjdp { 172933965Sjdp /* When gcc is used with -gstabs, but not -gstabs+, it will emit 173033965Sjdp long long int:t6=r1;0;-1; 173133965Sjdp long long unsigned int:t7=r1;0;-1; 173233965Sjdp We hack here to handle this reasonably. */ 173333965Sjdp if (typename != NULL) 173433965Sjdp { 173533965Sjdp if (strcmp (typename, "long long int") == 0) 1736130561Sobrien return debug_make_int_type (dhandle, 8, FALSE); 173733965Sjdp else if (strcmp (typename, "long long unsigned int") == 0) 1738130561Sobrien return debug_make_int_type (dhandle, 8, TRUE); 173933965Sjdp } 174033965Sjdp /* FIXME: The size here really depends upon the target. */ 1741130561Sobrien return debug_make_int_type (dhandle, 4, TRUE); 174233965Sjdp } 174333965Sjdp 174433965Sjdp /* A range of 0 to 127 is char. */ 174533965Sjdp if (self_subrange && n2 == 0 && n3 == 127) 1746130561Sobrien return debug_make_int_type (dhandle, 1, FALSE); 174733965Sjdp 174833965Sjdp /* FIXME: gdb checks for the language CHILL here. */ 174933965Sjdp 175033965Sjdp if (n2 == 0) 175133965Sjdp { 175233965Sjdp if (n3 < 0) 1753130561Sobrien return debug_make_int_type (dhandle, - n3, TRUE); 175433965Sjdp else if (n3 == 0xff) 1755130561Sobrien return debug_make_int_type (dhandle, 1, TRUE); 175633965Sjdp else if (n3 == 0xffff) 1757130561Sobrien return debug_make_int_type (dhandle, 2, TRUE); 175860484Sobrien else if (n3 == (bfd_signed_vma) 0xffffffff) 1759130561Sobrien return debug_make_int_type (dhandle, 4, TRUE); 176060484Sobrien#ifdef BFD64 176177298Sobrien else if (n3 == ((((bfd_signed_vma) 0xffffffff) << 32) | 0xffffffff)) 1762130561Sobrien return debug_make_int_type (dhandle, 8, TRUE); 176360484Sobrien#endif 176433965Sjdp } 176533965Sjdp else if (n3 == 0 176633965Sjdp && n2 < 0 176733965Sjdp && (self_subrange || n2 == -8)) 1768130561Sobrien return debug_make_int_type (dhandle, - n2, TRUE); 176960484Sobrien else if (n2 == - n3 - 1 || n2 == n3 + 1) 177033965Sjdp { 177133965Sjdp if (n3 == 0x7f) 1772130561Sobrien return debug_make_int_type (dhandle, 1, FALSE); 177333965Sjdp else if (n3 == 0x7fff) 1774130561Sobrien return debug_make_int_type (dhandle, 2, FALSE); 177533965Sjdp else if (n3 == 0x7fffffff) 1776130561Sobrien return debug_make_int_type (dhandle, 4, FALSE); 177760484Sobrien#ifdef BFD64 177860484Sobrien else if (n3 == ((((bfd_vma) 0x7fffffff) << 32) | 0xffffffff)) 1779130561Sobrien return debug_make_int_type (dhandle, 8, FALSE); 178060484Sobrien#endif 178133965Sjdp } 178233965Sjdp } 178333965Sjdp 178433965Sjdp /* At this point I don't have the faintest idea how to deal with a 178533965Sjdp self_subrange type; I'm going to assume that this is used as an 178633965Sjdp idiom, and that all of them are special cases. So . . . */ 178733965Sjdp if (self_subrange) 178833965Sjdp { 178933965Sjdp bad_stab (orig); 179033965Sjdp return DEBUG_TYPE_NULL; 179133965Sjdp } 179233965Sjdp 179333965Sjdp index_type = stab_find_type (dhandle, info, rangenums); 179433965Sjdp if (index_type == DEBUG_TYPE_NULL) 179533965Sjdp { 179633965Sjdp /* Does this actually ever happen? Is that why we are worrying 179733965Sjdp about dealing with it rather than just calling error_type? */ 179860484Sobrien warn_stab (orig, _("missing index type")); 1799130561Sobrien index_type = debug_make_int_type (dhandle, 4, FALSE); 180033965Sjdp } 180133965Sjdp 180233965Sjdp return debug_make_range_type (dhandle, index_type, n2, n3); 180333965Sjdp} 180433965Sjdp 180533965Sjdp/* Sun's ACC uses a somewhat saner method for specifying the builtin 180633965Sjdp typedefs in every file (for int, long, etc): 180733965Sjdp 180833965Sjdp type = b <signed> <width>; <offset>; <nbits> 180933965Sjdp signed = u or s. Possible c in addition to u or s (for char?). 181033965Sjdp offset = offset from high order bit to start bit of type. 181133965Sjdp width is # bytes in object of this type, nbits is # bits in type. 181233965Sjdp 181333965Sjdp The width/offset stuff appears to be for small objects stored in 181433965Sjdp larger ones (e.g. `shorts' in `int' registers). We ignore it for now, 181533965Sjdp FIXME. */ 181633965Sjdp 181733965Sjdpstatic debug_type 1818130561Sobrienparse_stab_sun_builtin_type (void *dhandle, const char **pp) 181933965Sjdp{ 182033965Sjdp const char *orig; 1821130561Sobrien bfd_boolean unsignedp; 182233965Sjdp bfd_vma bits; 182333965Sjdp 182433965Sjdp orig = *pp; 182533965Sjdp 182633965Sjdp switch (**pp) 182733965Sjdp { 182833965Sjdp case 's': 1829130561Sobrien unsignedp = FALSE; 183033965Sjdp break; 183133965Sjdp case 'u': 1832130561Sobrien unsignedp = TRUE; 183333965Sjdp break; 183433965Sjdp default: 183533965Sjdp bad_stab (orig); 183633965Sjdp return DEBUG_TYPE_NULL; 183733965Sjdp } 183833965Sjdp ++*pp; 183933965Sjdp 184033965Sjdp /* For some odd reason, all forms of char put a c here. This is strange 184133965Sjdp because no other type has this honor. We can safely ignore this because 184233965Sjdp we actually determine 'char'acterness by the number of bits specified in 184333965Sjdp the descriptor. */ 184433965Sjdp if (**pp == 'c') 184533965Sjdp ++*pp; 184633965Sjdp 184733965Sjdp /* The first number appears to be the number of bytes occupied 184833965Sjdp by this type, except that unsigned short is 4 instead of 2. 184933965Sjdp Since this information is redundant with the third number, 185033965Sjdp we will ignore it. */ 1851130561Sobrien (void) parse_number (pp, (bfd_boolean *) NULL); 185233965Sjdp if (**pp != ';') 185333965Sjdp { 185433965Sjdp bad_stab (orig); 185533965Sjdp return DEBUG_TYPE_NULL; 185633965Sjdp } 185733965Sjdp ++*pp; 185833965Sjdp 1859104834Sobrien /* The second number is always 0, so ignore it too. */ 1860130561Sobrien (void) parse_number (pp, (bfd_boolean *) NULL); 186133965Sjdp if (**pp != ';') 186233965Sjdp { 186333965Sjdp bad_stab (orig); 186433965Sjdp return DEBUG_TYPE_NULL; 186533965Sjdp } 186633965Sjdp ++*pp; 186733965Sjdp 1868104834Sobrien /* The third number is the number of bits for this type. */ 1869130561Sobrien bits = parse_number (pp, (bfd_boolean *) NULL); 187033965Sjdp 187133965Sjdp /* The type *should* end with a semicolon. If it are embedded 187233965Sjdp in a larger type the semicolon may be the only way to know where 187333965Sjdp the type ends. If this type is at the end of the stabstring we 187433965Sjdp can deal with the omitted semicolon (but we don't have to like 187533965Sjdp it). Don't bother to complain(), Sun's compiler omits the semicolon 187633965Sjdp for "void". */ 187733965Sjdp if (**pp == ';') 187833965Sjdp ++*pp; 187933965Sjdp 188033965Sjdp if (bits == 0) 188133965Sjdp return debug_make_void_type (dhandle); 188233965Sjdp 188333965Sjdp return debug_make_int_type (dhandle, bits / 8, unsignedp); 188433965Sjdp} 188533965Sjdp 188633965Sjdp/* Parse a builtin floating type generated by the Sun compiler. */ 188733965Sjdp 188833965Sjdpstatic debug_type 1889130561Sobrienparse_stab_sun_floating_type (void *dhandle, const char **pp) 189033965Sjdp{ 189133965Sjdp const char *orig; 189233965Sjdp bfd_vma details; 189333965Sjdp bfd_vma bytes; 189433965Sjdp 189533965Sjdp orig = *pp; 189633965Sjdp 189733965Sjdp /* The first number has more details about the type, for example 189833965Sjdp FN_COMPLEX. */ 1899130561Sobrien details = parse_number (pp, (bfd_boolean *) NULL); 190033965Sjdp if (**pp != ';') 190133965Sjdp { 190233965Sjdp bad_stab (orig); 190333965Sjdp return DEBUG_TYPE_NULL; 190433965Sjdp } 190533965Sjdp 190633965Sjdp /* The second number is the number of bytes occupied by this type */ 1907130561Sobrien bytes = parse_number (pp, (bfd_boolean *) NULL); 190833965Sjdp if (**pp != ';') 190933965Sjdp { 191033965Sjdp bad_stab (orig); 191133965Sjdp return DEBUG_TYPE_NULL; 191233965Sjdp } 191333965Sjdp 191433965Sjdp if (details == NF_COMPLEX 191533965Sjdp || details == NF_COMPLEX16 191633965Sjdp || details == NF_COMPLEX32) 191733965Sjdp return debug_make_complex_type (dhandle, bytes); 191833965Sjdp 1919104834Sobrien return debug_make_float_type (dhandle, bytes); 192033965Sjdp} 192133965Sjdp 192233965Sjdp/* Handle an enum type. */ 192333965Sjdp 192433965Sjdpstatic debug_type 1925130561Sobrienparse_stab_enum_type (void *dhandle, const char **pp) 192633965Sjdp{ 192733965Sjdp const char *orig; 192833965Sjdp const char **names; 192933965Sjdp bfd_signed_vma *values; 193033965Sjdp unsigned int n; 193133965Sjdp unsigned int alloc; 193233965Sjdp 193333965Sjdp orig = *pp; 193433965Sjdp 193533965Sjdp /* FIXME: gdb checks os9k_stabs here. */ 193633965Sjdp 193733965Sjdp /* The aix4 compiler emits an extra field before the enum members; 193833965Sjdp my guess is it's a type of some sort. Just ignore it. */ 193933965Sjdp if (**pp == '-') 194033965Sjdp { 194133965Sjdp while (**pp != ':') 194233965Sjdp ++*pp; 194333965Sjdp ++*pp; 194433965Sjdp } 194533965Sjdp 194633965Sjdp /* Read the value-names and their values. 194733965Sjdp The input syntax is NAME:VALUE,NAME:VALUE, and so on. 194833965Sjdp A semicolon or comma instead of a NAME means the end. */ 194933965Sjdp alloc = 10; 195033965Sjdp names = (const char **) xmalloc (alloc * sizeof *names); 195133965Sjdp values = (bfd_signed_vma *) xmalloc (alloc * sizeof *values); 195233965Sjdp n = 0; 195333965Sjdp while (**pp != '\0' && **pp != ';' && **pp != ',') 195433965Sjdp { 195533965Sjdp const char *p; 195633965Sjdp char *name; 195733965Sjdp bfd_signed_vma val; 195833965Sjdp 195933965Sjdp p = *pp; 196033965Sjdp while (*p != ':') 196133965Sjdp ++p; 196233965Sjdp 196333965Sjdp name = savestring (*pp, p - *pp); 196433965Sjdp 196533965Sjdp *pp = p + 1; 1966130561Sobrien val = (bfd_signed_vma) parse_number (pp, (bfd_boolean *) NULL); 196733965Sjdp if (**pp != ',') 196833965Sjdp { 196933965Sjdp bad_stab (orig); 197033965Sjdp return DEBUG_TYPE_NULL; 197133965Sjdp } 197233965Sjdp ++*pp; 197333965Sjdp 197433965Sjdp if (n + 1 >= alloc) 197533965Sjdp { 197633965Sjdp alloc += 10; 197733965Sjdp names = ((const char **) 1978130561Sobrien xrealloc (names, alloc * sizeof *names)); 197933965Sjdp values = ((bfd_signed_vma *) 1980130561Sobrien xrealloc (values, alloc * sizeof *values)); 198133965Sjdp } 198233965Sjdp 198333965Sjdp names[n] = name; 198433965Sjdp values[n] = val; 198533965Sjdp ++n; 198633965Sjdp } 198733965Sjdp 198833965Sjdp names[n] = NULL; 198933965Sjdp values[n] = 0; 199033965Sjdp 199133965Sjdp if (**pp == ';') 199233965Sjdp ++*pp; 199333965Sjdp 199433965Sjdp return debug_make_enum_type (dhandle, names, values); 199533965Sjdp} 199633965Sjdp 199733965Sjdp/* Read the description of a structure (or union type) and return an object 199833965Sjdp describing the type. 199933965Sjdp 200033965Sjdp PP points to a character pointer that points to the next unconsumed token 2001130561Sobrien in the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;", 200233965Sjdp *PP will point to "4a:1,0,32;;". */ 200333965Sjdp 200433965Sjdpstatic debug_type 2005130561Sobrienparse_stab_struct_type (void *dhandle, struct stab_handle *info, 2006130561Sobrien const char *tagname, const char **pp, 2007130561Sobrien bfd_boolean structp, const int *typenums) 200833965Sjdp{ 200933965Sjdp const char *orig; 201033965Sjdp bfd_vma size; 201133965Sjdp debug_baseclass *baseclasses; 201233965Sjdp debug_field *fields; 2013130561Sobrien bfd_boolean statics; 201433965Sjdp debug_method *methods; 201533965Sjdp debug_type vptrbase; 2016130561Sobrien bfd_boolean ownvptr; 201733965Sjdp 201833965Sjdp orig = *pp; 201933965Sjdp 202033965Sjdp /* Get the size. */ 2021130561Sobrien size = parse_number (pp, (bfd_boolean *) NULL); 202233965Sjdp 202333965Sjdp /* Get the other information. */ 202433965Sjdp if (! parse_stab_baseclasses (dhandle, info, pp, &baseclasses) 202533965Sjdp || ! parse_stab_struct_fields (dhandle, info, pp, &fields, &statics) 202633965Sjdp || ! parse_stab_members (dhandle, info, tagname, pp, typenums, &methods) 202733965Sjdp || ! parse_stab_tilde_field (dhandle, info, pp, typenums, &vptrbase, 202833965Sjdp &ownvptr)) 202933965Sjdp return DEBUG_TYPE_NULL; 203033965Sjdp 203133965Sjdp if (! statics 203233965Sjdp && baseclasses == NULL 203333965Sjdp && methods == NULL 203433965Sjdp && vptrbase == DEBUG_TYPE_NULL 203533965Sjdp && ! ownvptr) 203633965Sjdp return debug_make_struct_type (dhandle, structp, size, fields); 203733965Sjdp 203833965Sjdp return debug_make_object_type (dhandle, structp, size, fields, baseclasses, 203933965Sjdp methods, vptrbase, ownvptr); 204033965Sjdp} 204133965Sjdp 204233965Sjdp/* The stabs for C++ derived classes contain baseclass information which 204333965Sjdp is marked by a '!' character after the total size. This function is 204433965Sjdp called when we encounter the baseclass marker, and slurps up all the 204533965Sjdp baseclass information. 204633965Sjdp 204733965Sjdp Immediately following the '!' marker is the number of base classes that 204833965Sjdp the class is derived from, followed by information for each base class. 204933965Sjdp For each base class, there are two visibility specifiers, a bit offset 205033965Sjdp to the base class information within the derived class, a reference to 205133965Sjdp the type for the base class, and a terminating semicolon. 205233965Sjdp 205333965Sjdp A typical example, with two base classes, would be "!2,020,19;0264,21;". 2054130561Sobrien ^^ ^ ^ ^ ^ ^ ^ 205533965Sjdp Baseclass information marker __________________|| | | | | | | 205633965Sjdp Number of baseclasses __________________________| | | | | | | 205733965Sjdp Visibility specifiers (2) ________________________| | | | | | 205833965Sjdp Offset in bits from start of class _________________| | | | | 205933965Sjdp Type number for base class ___________________________| | | | 206033965Sjdp Visibility specifiers (2) _______________________________| | | 206133965Sjdp Offset in bits from start of class ________________________| | 206233965Sjdp Type number of base class ____________________________________| 206333965Sjdp 2064130561Sobrien Return TRUE for success, FALSE for failure. */ 206533965Sjdp 2066130561Sobrienstatic bfd_boolean 2067130561Sobrienparse_stab_baseclasses (void *dhandle, struct stab_handle *info, 2068130561Sobrien const char **pp, debug_baseclass **retp) 206933965Sjdp{ 207033965Sjdp const char *orig; 207133965Sjdp unsigned int c, i; 207233965Sjdp debug_baseclass *classes; 207333965Sjdp 207433965Sjdp *retp = NULL; 207533965Sjdp 207633965Sjdp orig = *pp; 207733965Sjdp 207833965Sjdp if (**pp != '!') 207933965Sjdp { 208033965Sjdp /* No base classes. */ 2081130561Sobrien return TRUE; 208233965Sjdp } 208333965Sjdp ++*pp; 208433965Sjdp 2085130561Sobrien c = (unsigned int) parse_number (pp, (bfd_boolean *) NULL); 208633965Sjdp 208733965Sjdp if (**pp != ',') 208833965Sjdp { 208933965Sjdp bad_stab (orig); 2090130561Sobrien return FALSE; 209133965Sjdp } 209233965Sjdp ++*pp; 209333965Sjdp 209433965Sjdp classes = (debug_baseclass *) xmalloc ((c + 1) * sizeof (**retp)); 209533965Sjdp 209633965Sjdp for (i = 0; i < c; i++) 209733965Sjdp { 2098130561Sobrien bfd_boolean virtual; 209933965Sjdp enum debug_visibility visibility; 210033965Sjdp bfd_vma bitpos; 210133965Sjdp debug_type type; 210233965Sjdp 210333965Sjdp switch (**pp) 210433965Sjdp { 210533965Sjdp case '0': 2106130561Sobrien virtual = FALSE; 210733965Sjdp break; 210833965Sjdp case '1': 2109130561Sobrien virtual = TRUE; 211033965Sjdp break; 211133965Sjdp default: 211260484Sobrien warn_stab (orig, _("unknown virtual character for baseclass")); 2113130561Sobrien virtual = FALSE; 211433965Sjdp break; 211533965Sjdp } 211633965Sjdp ++*pp; 211733965Sjdp 211833965Sjdp switch (**pp) 211933965Sjdp { 212033965Sjdp case '0': 212133965Sjdp visibility = DEBUG_VISIBILITY_PRIVATE; 212233965Sjdp break; 212333965Sjdp case '1': 212433965Sjdp visibility = DEBUG_VISIBILITY_PROTECTED; 212533965Sjdp break; 212633965Sjdp case '2': 212733965Sjdp visibility = DEBUG_VISIBILITY_PUBLIC; 212833965Sjdp break; 212933965Sjdp default: 213060484Sobrien warn_stab (orig, _("unknown visibility character for baseclass")); 213133965Sjdp visibility = DEBUG_VISIBILITY_PUBLIC; 213233965Sjdp break; 213333965Sjdp } 213433965Sjdp ++*pp; 213533965Sjdp 213633965Sjdp /* The remaining value is the bit offset of the portion of the 213733965Sjdp object corresponding to this baseclass. Always zero in the 213833965Sjdp absence of multiple inheritance. */ 2139130561Sobrien bitpos = parse_number (pp, (bfd_boolean *) NULL); 214033965Sjdp if (**pp != ',') 214133965Sjdp { 214233965Sjdp bad_stab (orig); 2143130561Sobrien return FALSE; 214433965Sjdp } 214533965Sjdp ++*pp; 214633965Sjdp 214733965Sjdp type = parse_stab_type (dhandle, info, (const char *) NULL, pp, 214833965Sjdp (debug_type **) NULL); 214933965Sjdp if (type == DEBUG_TYPE_NULL) 2150130561Sobrien return FALSE; 215133965Sjdp 215233965Sjdp classes[i] = debug_make_baseclass (dhandle, type, bitpos, virtual, 215333965Sjdp visibility); 215433965Sjdp if (classes[i] == DEBUG_BASECLASS_NULL) 2155130561Sobrien return FALSE; 215633965Sjdp 215733965Sjdp if (**pp != ';') 2158130561Sobrien return FALSE; 215933965Sjdp ++*pp; 216033965Sjdp } 216133965Sjdp 216233965Sjdp classes[i] = DEBUG_BASECLASS_NULL; 216333965Sjdp 216433965Sjdp *retp = classes; 216533965Sjdp 2166130561Sobrien return TRUE; 216733965Sjdp} 216833965Sjdp 216933965Sjdp/* Read struct or class data fields. They have the form: 217033965Sjdp 2171130561Sobrien NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ; 217233965Sjdp 217333965Sjdp At the end, we see a semicolon instead of a field. 217433965Sjdp 217533965Sjdp In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for 217633965Sjdp a static field. 217733965Sjdp 217833965Sjdp The optional VISIBILITY is one of: 217933965Sjdp 2180130561Sobrien '/0' (VISIBILITY_PRIVATE) 218133965Sjdp '/1' (VISIBILITY_PROTECTED) 218233965Sjdp '/2' (VISIBILITY_PUBLIC) 218333965Sjdp '/9' (VISIBILITY_IGNORE) 218433965Sjdp 218533965Sjdp or nothing, for C style fields with public visibility. 218633965Sjdp 218733965Sjdp Returns 1 for success, 0 for failure. */ 218833965Sjdp 2189130561Sobrienstatic bfd_boolean 2190130561Sobrienparse_stab_struct_fields (void *dhandle, struct stab_handle *info, 2191130561Sobrien const char **pp, debug_field **retp, 2192130561Sobrien bfd_boolean *staticsp) 219333965Sjdp{ 219433965Sjdp const char *orig; 219533965Sjdp const char *p; 219633965Sjdp debug_field *fields; 219733965Sjdp unsigned int c; 219833965Sjdp unsigned int alloc; 219933965Sjdp 220033965Sjdp *retp = NULL; 2201130561Sobrien *staticsp = FALSE; 220233965Sjdp 220333965Sjdp orig = *pp; 220433965Sjdp 220533965Sjdp c = 0; 220633965Sjdp alloc = 10; 220733965Sjdp fields = (debug_field *) xmalloc (alloc * sizeof *fields); 220833965Sjdp while (**pp != ';') 220933965Sjdp { 221033965Sjdp /* FIXME: gdb checks os9k_stabs here. */ 221133965Sjdp 221233965Sjdp p = *pp; 221333965Sjdp 221433965Sjdp /* Add 1 to c to leave room for NULL pointer at end. */ 221533965Sjdp if (c + 1 >= alloc) 221633965Sjdp { 221733965Sjdp alloc += 10; 221833965Sjdp fields = ((debug_field *) 2219130561Sobrien xrealloc (fields, alloc * sizeof *fields)); 222033965Sjdp } 222133965Sjdp 222233965Sjdp /* If it starts with CPLUS_MARKER it is a special abbreviation, 222333965Sjdp unless the CPLUS_MARKER is followed by an underscore, in 222433965Sjdp which case it is just the name of an anonymous type, which we 222533965Sjdp should handle like any other type name. We accept either '$' 222633965Sjdp or '.', because a field name can never contain one of these 222733965Sjdp characters except as a CPLUS_MARKER. */ 222833965Sjdp 222933965Sjdp if ((*p == '$' || *p == '.') && p[1] != '_') 223033965Sjdp { 223133965Sjdp ++*pp; 223233965Sjdp if (! parse_stab_cpp_abbrev (dhandle, info, pp, fields + c)) 2233130561Sobrien return FALSE; 223433965Sjdp ++c; 223533965Sjdp continue; 223633965Sjdp } 223733965Sjdp 223833965Sjdp /* Look for the ':' that separates the field name from the field 223933965Sjdp values. Data members are delimited by a single ':', while member 224033965Sjdp functions are delimited by a pair of ':'s. When we hit the member 2241104834Sobrien functions (if any), terminate scan loop and return. */ 224233965Sjdp 224333965Sjdp p = strchr (p, ':'); 224433965Sjdp if (p == NULL) 224533965Sjdp { 224633965Sjdp bad_stab (orig); 2247130561Sobrien return FALSE; 224833965Sjdp } 224933965Sjdp 225033965Sjdp if (p[1] == ':') 225133965Sjdp break; 225233965Sjdp 225333965Sjdp if (! parse_stab_one_struct_field (dhandle, info, pp, p, fields + c, 225433965Sjdp staticsp)) 2255130561Sobrien return FALSE; 225633965Sjdp 225733965Sjdp ++c; 225833965Sjdp } 225933965Sjdp 226033965Sjdp fields[c] = DEBUG_FIELD_NULL; 226133965Sjdp 226233965Sjdp *retp = fields; 226333965Sjdp 2264130561Sobrien return TRUE; 226533965Sjdp} 226633965Sjdp 226733965Sjdp/* Special GNU C++ name. */ 226833965Sjdp 2269130561Sobrienstatic bfd_boolean 2270130561Sobrienparse_stab_cpp_abbrev (void *dhandle, struct stab_handle *info, 2271130561Sobrien const char **pp, debug_field *retp) 227233965Sjdp{ 227333965Sjdp const char *orig; 227433965Sjdp int cpp_abbrev; 227533965Sjdp debug_type context; 227633965Sjdp const char *name; 227733965Sjdp const char *typename; 227833965Sjdp debug_type type; 227933965Sjdp bfd_vma bitpos; 228033965Sjdp 228133965Sjdp *retp = DEBUG_FIELD_NULL; 228233965Sjdp 228333965Sjdp orig = *pp; 228433965Sjdp 228533965Sjdp if (**pp != 'v') 228633965Sjdp { 228733965Sjdp bad_stab (*pp); 2288130561Sobrien return FALSE; 228933965Sjdp } 229033965Sjdp ++*pp; 229133965Sjdp 229233965Sjdp cpp_abbrev = **pp; 229333965Sjdp ++*pp; 229433965Sjdp 229533965Sjdp /* At this point, *pp points to something like "22:23=*22...", where 229633965Sjdp the type number before the ':' is the "context" and everything 229733965Sjdp after is a regular type definition. Lookup the type, find it's 229833965Sjdp name, and construct the field name. */ 229933965Sjdp 230033965Sjdp context = parse_stab_type (dhandle, info, (const char *) NULL, pp, 230133965Sjdp (debug_type **) NULL); 230233965Sjdp if (context == DEBUG_TYPE_NULL) 2303130561Sobrien return FALSE; 230433965Sjdp 230533965Sjdp switch (cpp_abbrev) 230633965Sjdp { 230733965Sjdp case 'f': 230833965Sjdp /* $vf -- a virtual function table pointer. */ 230933965Sjdp name = "_vptr$"; 231033965Sjdp break; 231133965Sjdp case 'b': 231233965Sjdp /* $vb -- a virtual bsomethingorother */ 231333965Sjdp typename = debug_get_type_name (dhandle, context); 231433965Sjdp if (typename == NULL) 231533965Sjdp { 231660484Sobrien warn_stab (orig, _("unnamed $vb type")); 231733965Sjdp typename = "FOO"; 231833965Sjdp } 231933965Sjdp name = concat ("_vb$", typename, (const char *) NULL); 232033965Sjdp break; 232133965Sjdp default: 232260484Sobrien warn_stab (orig, _("unrecognized C++ abbreviation")); 232333965Sjdp name = "INVALID_CPLUSPLUS_ABBREV"; 232433965Sjdp break; 232533965Sjdp } 232633965Sjdp 232733965Sjdp if (**pp != ':') 232833965Sjdp { 232933965Sjdp bad_stab (orig); 2330130561Sobrien return FALSE; 233133965Sjdp } 233233965Sjdp ++*pp; 233333965Sjdp 233433965Sjdp type = parse_stab_type (dhandle, info, (const char *) NULL, pp, 233533965Sjdp (debug_type **) NULL); 233633965Sjdp if (**pp != ',') 233733965Sjdp { 233833965Sjdp bad_stab (orig); 2339130561Sobrien return FALSE; 234033965Sjdp } 234133965Sjdp ++*pp; 234233965Sjdp 2343130561Sobrien bitpos = parse_number (pp, (bfd_boolean *) NULL); 234433965Sjdp if (**pp != ';') 234533965Sjdp { 234633965Sjdp bad_stab (orig); 2347130561Sobrien return FALSE; 234833965Sjdp } 234933965Sjdp ++*pp; 235033965Sjdp 235133965Sjdp *retp = debug_make_field (dhandle, name, type, bitpos, 0, 235233965Sjdp DEBUG_VISIBILITY_PRIVATE); 235333965Sjdp if (*retp == DEBUG_FIELD_NULL) 2354130561Sobrien return FALSE; 235533965Sjdp 2356130561Sobrien return TRUE; 235733965Sjdp} 235833965Sjdp 235933965Sjdp/* Parse a single field in a struct or union. */ 236033965Sjdp 2361130561Sobrienstatic bfd_boolean 2362130561Sobrienparse_stab_one_struct_field (void *dhandle, struct stab_handle *info, 2363130561Sobrien const char **pp, const char *p, 2364130561Sobrien debug_field *retp, bfd_boolean *staticsp) 236533965Sjdp{ 236633965Sjdp const char *orig; 236733965Sjdp char *name; 236833965Sjdp enum debug_visibility visibility; 236933965Sjdp debug_type type; 237033965Sjdp bfd_vma bitpos; 237133965Sjdp bfd_vma bitsize; 237233965Sjdp 237333965Sjdp orig = *pp; 237433965Sjdp 237533965Sjdp /* FIXME: gdb checks ARM_DEMANGLING here. */ 237633965Sjdp 237733965Sjdp name = savestring (*pp, p - *pp); 237833965Sjdp 237933965Sjdp *pp = p + 1; 238033965Sjdp 238133965Sjdp if (**pp != '/') 238233965Sjdp visibility = DEBUG_VISIBILITY_PUBLIC; 238333965Sjdp else 238433965Sjdp { 238533965Sjdp ++*pp; 238633965Sjdp switch (**pp) 238733965Sjdp { 238833965Sjdp case '0': 238933965Sjdp visibility = DEBUG_VISIBILITY_PRIVATE; 239033965Sjdp break; 239133965Sjdp case '1': 239233965Sjdp visibility = DEBUG_VISIBILITY_PROTECTED; 239333965Sjdp break; 239433965Sjdp case '2': 239533965Sjdp visibility = DEBUG_VISIBILITY_PUBLIC; 239633965Sjdp break; 239733965Sjdp default: 239860484Sobrien warn_stab (orig, _("unknown visibility character for field")); 239933965Sjdp visibility = DEBUG_VISIBILITY_PUBLIC; 240033965Sjdp break; 240133965Sjdp } 240233965Sjdp ++*pp; 240333965Sjdp } 240433965Sjdp 240533965Sjdp type = parse_stab_type (dhandle, info, (const char *) NULL, pp, 240633965Sjdp (debug_type **) NULL); 240733965Sjdp if (type == DEBUG_TYPE_NULL) 2408130561Sobrien return FALSE; 240933965Sjdp 241033965Sjdp if (**pp == ':') 241133965Sjdp { 241233965Sjdp char *varname; 241333965Sjdp 241433965Sjdp /* This is a static class member. */ 241533965Sjdp ++*pp; 241633965Sjdp p = strchr (*pp, ';'); 241733965Sjdp if (p == NULL) 241833965Sjdp { 241933965Sjdp bad_stab (orig); 2420130561Sobrien return FALSE; 242133965Sjdp } 242233965Sjdp 242333965Sjdp varname = savestring (*pp, p - *pp); 242433965Sjdp 242533965Sjdp *pp = p + 1; 242633965Sjdp 242733965Sjdp *retp = debug_make_static_member (dhandle, name, type, varname, 242833965Sjdp visibility); 2429130561Sobrien *staticsp = TRUE; 243033965Sjdp 2431130561Sobrien return TRUE; 243233965Sjdp } 243333965Sjdp 243433965Sjdp if (**pp != ',') 243533965Sjdp { 243633965Sjdp bad_stab (orig); 2437130561Sobrien return FALSE; 243833965Sjdp } 243933965Sjdp ++*pp; 244033965Sjdp 2441130561Sobrien bitpos = parse_number (pp, (bfd_boolean *) NULL); 244233965Sjdp if (**pp != ',') 244333965Sjdp { 244433965Sjdp bad_stab (orig); 2445130561Sobrien return FALSE; 244633965Sjdp } 244733965Sjdp ++*pp; 244833965Sjdp 2449130561Sobrien bitsize = parse_number (pp, (bfd_boolean *) NULL); 245033965Sjdp if (**pp != ';') 245133965Sjdp { 245233965Sjdp bad_stab (orig); 2453130561Sobrien return FALSE; 245433965Sjdp } 245533965Sjdp ++*pp; 245633965Sjdp 245733965Sjdp if (bitpos == 0 && bitsize == 0) 245833965Sjdp { 245933965Sjdp /* This can happen in two cases: (1) at least for gcc 2.4.5 or 246033965Sjdp so, it is a field which has been optimized out. The correct 246133965Sjdp stab for this case is to use VISIBILITY_IGNORE, but that is a 246233965Sjdp recent invention. (2) It is a 0-size array. For example 246333965Sjdp union { int num; char str[0]; } foo. Printing "<no value>" 246433965Sjdp for str in "p foo" is OK, since foo.str (and thus foo.str[3]) 246533965Sjdp will continue to work, and a 0-size array as a whole doesn't 246633965Sjdp have any contents to print. 246733965Sjdp 246833965Sjdp I suspect this probably could also happen with gcc -gstabs 246933965Sjdp (not -gstabs+) for static fields, and perhaps other C++ 247033965Sjdp extensions. Hopefully few people use -gstabs with gdb, since 247133965Sjdp it is intended for dbx compatibility. */ 247233965Sjdp visibility = DEBUG_VISIBILITY_IGNORE; 247333965Sjdp } 247433965Sjdp 247533965Sjdp /* FIXME: gdb does some stuff here to mark fields as unpacked. */ 247633965Sjdp 247733965Sjdp *retp = debug_make_field (dhandle, name, type, bitpos, bitsize, visibility); 247833965Sjdp 2479130561Sobrien return TRUE; 248033965Sjdp} 248133965Sjdp 248233965Sjdp/* Read member function stabs info for C++ classes. The form of each member 248333965Sjdp function data is: 248433965Sjdp 248533965Sjdp NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ; 248633965Sjdp 248733965Sjdp An example with two member functions is: 248833965Sjdp 248933965Sjdp afunc1::20=##15;:i;2A.;afunc2::20:i;2A.; 249033965Sjdp 249133965Sjdp For the case of overloaded operators, the format is op$::*.funcs, where 249233965Sjdp $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator 249333965Sjdp name (such as `+=') and `.' marks the end of the operator name. */ 249433965Sjdp 2495130561Sobrienstatic bfd_boolean 2496130561Sobrienparse_stab_members (void *dhandle, struct stab_handle *info, 2497130561Sobrien const char *tagname, const char **pp, 2498130561Sobrien const int *typenums, debug_method **retp) 249933965Sjdp{ 250033965Sjdp const char *orig; 250133965Sjdp debug_method *methods; 250233965Sjdp unsigned int c; 250333965Sjdp unsigned int alloc; 250433965Sjdp 250533965Sjdp *retp = NULL; 250633965Sjdp 250733965Sjdp orig = *pp; 250833965Sjdp 250933965Sjdp alloc = 0; 251033965Sjdp methods = NULL; 251133965Sjdp c = 0; 251233965Sjdp 251333965Sjdp while (**pp != ';') 251433965Sjdp { 251533965Sjdp const char *p; 251633965Sjdp char *name; 251733965Sjdp debug_method_variant *variants; 251833965Sjdp unsigned int cvars; 251933965Sjdp unsigned int allocvars; 252033965Sjdp debug_type look_ahead_type; 252133965Sjdp 252233965Sjdp p = strchr (*pp, ':'); 252333965Sjdp if (p == NULL || p[1] != ':') 252433965Sjdp break; 252533965Sjdp 252633965Sjdp /* FIXME: Some systems use something other than '$' here. */ 252733965Sjdp if ((*pp)[0] != 'o' || (*pp)[1] != 'p' || (*pp)[2] != '$') 252833965Sjdp { 252933965Sjdp name = savestring (*pp, p - *pp); 253033965Sjdp *pp = p + 2; 253133965Sjdp } 253233965Sjdp else 253333965Sjdp { 2534130561Sobrien /* This is a completely weird case. In order to stuff in the 253533965Sjdp names that might contain colons (the usual name delimiter), 253633965Sjdp Mike Tiemann defined a different name format which is 253733965Sjdp signalled if the identifier is "op$". In that case, the 253833965Sjdp format is "op$::XXXX." where XXXX is the name. This is 253933965Sjdp used for names like "+" or "=". YUUUUUUUK! FIXME! */ 254033965Sjdp *pp = p + 2; 254133965Sjdp for (p = *pp; *p != '.' && *p != '\0'; p++) 254233965Sjdp ; 254333965Sjdp if (*p != '.') 254433965Sjdp { 254533965Sjdp bad_stab (orig); 2546130561Sobrien return FALSE; 254733965Sjdp } 254833965Sjdp name = savestring (*pp, p - *pp); 254933965Sjdp *pp = p + 1; 255033965Sjdp } 255133965Sjdp 255233965Sjdp allocvars = 10; 255333965Sjdp variants = ((debug_method_variant *) 255433965Sjdp xmalloc (allocvars * sizeof *variants)); 255533965Sjdp cvars = 0; 255633965Sjdp 255733965Sjdp look_ahead_type = DEBUG_TYPE_NULL; 255833965Sjdp 255933965Sjdp do 256033965Sjdp { 256133965Sjdp debug_type type; 2562130561Sobrien bfd_boolean stub; 256333965Sjdp char *argtypes; 256433965Sjdp enum debug_visibility visibility; 2565130561Sobrien bfd_boolean constp, volatilep, staticp; 256633965Sjdp bfd_vma voffset; 256733965Sjdp debug_type context; 256833965Sjdp const char *physname; 2569130561Sobrien bfd_boolean varargs; 257033965Sjdp 257133965Sjdp if (look_ahead_type != DEBUG_TYPE_NULL) 257233965Sjdp { 257333965Sjdp /* g++ version 1 kludge */ 257433965Sjdp type = look_ahead_type; 257533965Sjdp look_ahead_type = DEBUG_TYPE_NULL; 257633965Sjdp } 257733965Sjdp else 257833965Sjdp { 257933965Sjdp type = parse_stab_type (dhandle, info, (const char *) NULL, pp, 258033965Sjdp (debug_type **) NULL); 258133965Sjdp if (type == DEBUG_TYPE_NULL) 2582130561Sobrien return FALSE; 258333965Sjdp if (**pp != ':') 258433965Sjdp { 258533965Sjdp bad_stab (orig); 2586130561Sobrien return FALSE; 258733965Sjdp } 258833965Sjdp } 258933965Sjdp 259033965Sjdp ++*pp; 259133965Sjdp p = strchr (*pp, ';'); 259233965Sjdp if (p == NULL) 259333965Sjdp { 259433965Sjdp bad_stab (orig); 2595130561Sobrien return FALSE; 259633965Sjdp } 259733965Sjdp 2598130561Sobrien stub = FALSE; 259933965Sjdp if (debug_get_type_kind (dhandle, type) == DEBUG_KIND_METHOD 260033965Sjdp && debug_get_parameter_types (dhandle, type, &varargs) == NULL) 2601130561Sobrien stub = TRUE; 260233965Sjdp 260333965Sjdp argtypes = savestring (*pp, p - *pp); 260433965Sjdp *pp = p + 1; 260533965Sjdp 260633965Sjdp switch (**pp) 260733965Sjdp { 260833965Sjdp case '0': 260933965Sjdp visibility = DEBUG_VISIBILITY_PRIVATE; 261033965Sjdp break; 261133965Sjdp case '1': 261233965Sjdp visibility = DEBUG_VISIBILITY_PROTECTED; 261333965Sjdp break; 261433965Sjdp default: 261533965Sjdp visibility = DEBUG_VISIBILITY_PUBLIC; 261633965Sjdp break; 261733965Sjdp } 261833965Sjdp ++*pp; 261933965Sjdp 2620130561Sobrien constp = FALSE; 2621130561Sobrien volatilep = FALSE; 262233965Sjdp switch (**pp) 262333965Sjdp { 262433965Sjdp case 'A': 262533965Sjdp /* Normal function. */ 262633965Sjdp ++*pp; 262733965Sjdp break; 262833965Sjdp case 'B': 262933965Sjdp /* const member function. */ 2630130561Sobrien constp = TRUE; 263133965Sjdp ++*pp; 263233965Sjdp break; 263333965Sjdp case 'C': 263433965Sjdp /* volatile member function. */ 2635130561Sobrien volatilep = TRUE; 263633965Sjdp ++*pp; 263733965Sjdp break; 263833965Sjdp case 'D': 263933965Sjdp /* const volatile member function. */ 2640130561Sobrien constp = TRUE; 2641130561Sobrien volatilep = TRUE; 264233965Sjdp ++*pp; 264333965Sjdp break; 264433965Sjdp case '*': 264533965Sjdp case '?': 264633965Sjdp case '.': 264733965Sjdp /* File compiled with g++ version 1; no information. */ 264833965Sjdp break; 264933965Sjdp default: 265060484Sobrien warn_stab (orig, _("const/volatile indicator missing")); 265133965Sjdp break; 265233965Sjdp } 265333965Sjdp 2654130561Sobrien staticp = FALSE; 265533965Sjdp switch (**pp) 265633965Sjdp { 265733965Sjdp case '*': 265833965Sjdp /* virtual member function, followed by index. The sign 265933965Sjdp bit is supposedly set to distinguish 266033965Sjdp pointers-to-methods from virtual function indicies. */ 266133965Sjdp ++*pp; 2662130561Sobrien voffset = parse_number (pp, (bfd_boolean *) NULL); 266333965Sjdp if (**pp != ';') 266433965Sjdp { 266533965Sjdp bad_stab (orig); 2666130561Sobrien return FALSE; 266733965Sjdp } 266833965Sjdp ++*pp; 266933965Sjdp voffset &= 0x7fffffff; 267033965Sjdp 267133965Sjdp if (**pp == ';' || *pp == '\0') 267233965Sjdp { 267333965Sjdp /* Must be g++ version 1. */ 267433965Sjdp context = DEBUG_TYPE_NULL; 267533965Sjdp } 267633965Sjdp else 267733965Sjdp { 267833965Sjdp /* Figure out from whence this virtual function 267933965Sjdp came. It may belong to virtual function table of 268033965Sjdp one of its baseclasses. */ 2681104834Sobrien look_ahead_type = parse_stab_type (dhandle, info, 2682104834Sobrien (const char *) NULL, 2683104834Sobrien pp, 2684104834Sobrien (debug_type **) NULL); 2685104834Sobrien if (**pp == ':') 2686104834Sobrien { 2687104834Sobrien /* g++ version 1 overloaded methods. */ 2688104834Sobrien context = DEBUG_TYPE_NULL; 2689104834Sobrien } 2690104834Sobrien else 2691104834Sobrien { 2692104834Sobrien context = look_ahead_type; 2693104834Sobrien look_ahead_type = DEBUG_TYPE_NULL; 2694104834Sobrien if (**pp != ';') 2695104834Sobrien { 2696104834Sobrien bad_stab (orig); 2697130561Sobrien return FALSE; 2698104834Sobrien } 2699104834Sobrien ++*pp; 2700104834Sobrien } 2701104834Sobrien } 270233965Sjdp break; 270333965Sjdp 270433965Sjdp case '?': 270533965Sjdp /* static member function. */ 270633965Sjdp ++*pp; 2707130561Sobrien staticp = TRUE; 270833965Sjdp voffset = 0; 270933965Sjdp context = DEBUG_TYPE_NULL; 271033965Sjdp if (strncmp (argtypes, name, strlen (name)) != 0) 2711130561Sobrien stub = TRUE; 271233965Sjdp break; 271333965Sjdp 271433965Sjdp default: 271533965Sjdp warn_stab (orig, "member function type missing"); 271633965Sjdp voffset = 0; 271733965Sjdp context = DEBUG_TYPE_NULL; 271833965Sjdp break; 271933965Sjdp 272033965Sjdp case '.': 272133965Sjdp ++*pp; 272233965Sjdp voffset = 0; 272333965Sjdp context = DEBUG_TYPE_NULL; 272433965Sjdp break; 272533965Sjdp } 272633965Sjdp 272733965Sjdp /* If the type is not a stub, then the argtypes string is 272833965Sjdp the physical name of the function. Otherwise the 272933965Sjdp argtypes string is the mangled form of the argument 273033965Sjdp types, and the full type and the physical name must be 273133965Sjdp extracted from them. */ 273233965Sjdp if (! stub) 273333965Sjdp physname = argtypes; 273433965Sjdp else 273533965Sjdp { 273633965Sjdp debug_type class_type, return_type; 273733965Sjdp 273833965Sjdp class_type = stab_find_type (dhandle, info, typenums); 273933965Sjdp if (class_type == DEBUG_TYPE_NULL) 2740130561Sobrien return FALSE; 274133965Sjdp return_type = debug_get_return_type (dhandle, type); 274233965Sjdp if (return_type == DEBUG_TYPE_NULL) 274333965Sjdp { 274433965Sjdp bad_stab (orig); 2745130561Sobrien return FALSE; 274633965Sjdp } 274733965Sjdp type = parse_stab_argtypes (dhandle, info, class_type, name, 274833965Sjdp tagname, return_type, argtypes, 274933965Sjdp constp, volatilep, &physname); 275033965Sjdp if (type == DEBUG_TYPE_NULL) 2751130561Sobrien return FALSE; 275233965Sjdp } 275333965Sjdp 275433965Sjdp if (cvars + 1 >= allocvars) 275533965Sjdp { 275633965Sjdp allocvars += 10; 275733965Sjdp variants = ((debug_method_variant *) 2758130561Sobrien xrealloc (variants, 275933965Sjdp allocvars * sizeof *variants)); 276033965Sjdp } 276133965Sjdp 276233965Sjdp if (! staticp) 276333965Sjdp variants[cvars] = debug_make_method_variant (dhandle, physname, 276433965Sjdp type, visibility, 276533965Sjdp constp, volatilep, 276633965Sjdp voffset, context); 276733965Sjdp else 276833965Sjdp variants[cvars] = debug_make_static_method_variant (dhandle, 276933965Sjdp physname, 277033965Sjdp type, 277133965Sjdp visibility, 277233965Sjdp constp, 277333965Sjdp volatilep); 277433965Sjdp if (variants[cvars] == DEBUG_METHOD_VARIANT_NULL) 2775130561Sobrien return FALSE; 277633965Sjdp 277733965Sjdp ++cvars; 277833965Sjdp } 277933965Sjdp while (**pp != ';' && **pp != '\0'); 278033965Sjdp 278133965Sjdp variants[cvars] = DEBUG_METHOD_VARIANT_NULL; 278233965Sjdp 278333965Sjdp if (**pp != '\0') 278433965Sjdp ++*pp; 278533965Sjdp 278633965Sjdp if (c + 1 >= alloc) 278733965Sjdp { 278833965Sjdp alloc += 10; 278933965Sjdp methods = ((debug_method *) 2790130561Sobrien xrealloc (methods, alloc * sizeof *methods)); 279133965Sjdp } 279233965Sjdp 279333965Sjdp methods[c] = debug_make_method (dhandle, name, variants); 279433965Sjdp 279533965Sjdp ++c; 279633965Sjdp } 279733965Sjdp 279833965Sjdp if (methods != NULL) 279933965Sjdp methods[c] = DEBUG_METHOD_NULL; 280033965Sjdp 280133965Sjdp *retp = methods; 280233965Sjdp 2803130561Sobrien return TRUE; 280433965Sjdp} 280533965Sjdp 280633965Sjdp/* Parse a string representing argument types for a method. Stabs 280733965Sjdp tries to save space by packing argument types into a mangled 280833965Sjdp string. This string should give us enough information to extract 280933965Sjdp both argument types and the physical name of the function, given 281033965Sjdp the tag name. */ 281133965Sjdp 281233965Sjdpstatic debug_type 2813130561Sobrienparse_stab_argtypes (void *dhandle, struct stab_handle *info, 2814130561Sobrien debug_type class_type, const char *fieldname, 2815130561Sobrien const char *tagname, debug_type return_type, 2816130561Sobrien const char *argtypes, bfd_boolean constp, 2817130561Sobrien bfd_boolean volatilep, const char **pphysname) 281833965Sjdp{ 2819130561Sobrien bfd_boolean is_full_physname_constructor; 2820130561Sobrien bfd_boolean is_constructor; 2821130561Sobrien bfd_boolean is_destructor; 2822130561Sobrien bfd_boolean is_v3; 282333965Sjdp debug_type *args; 2824130561Sobrien bfd_boolean varargs; 2825130561Sobrien unsigned int physname_len = 0; 282633965Sjdp 282733965Sjdp /* Constructors are sometimes handled specially. */ 282833965Sjdp is_full_physname_constructor = ((argtypes[0] == '_' 282933965Sjdp && argtypes[1] == '_' 283089857Sobrien && (ISDIGIT (argtypes[2]) 283133965Sjdp || argtypes[2] == 'Q' 283233965Sjdp || argtypes[2] == 't')) 2833218822Sdim || CONST_STRNEQ (argtypes, "__ct")); 283433965Sjdp 283533965Sjdp is_constructor = (is_full_physname_constructor 283633965Sjdp || (tagname != NULL 283733965Sjdp && strcmp (fieldname, tagname) == 0)); 283833965Sjdp is_destructor = ((argtypes[0] == '_' 283933965Sjdp && (argtypes[1] == '$' || argtypes[1] == '.') 284033965Sjdp && argtypes[2] == '_') 2841218822Sdim || CONST_STRNEQ (argtypes, "__dt")); 2842130561Sobrien is_v3 = argtypes[0] == '_' && argtypes[1] == 'Z'; 284333965Sjdp 2844130561Sobrien if (is_destructor || is_full_physname_constructor || is_v3) 284533965Sjdp *pphysname = argtypes; 284633965Sjdp else 284733965Sjdp { 284833965Sjdp unsigned int len; 284933965Sjdp const char *const_prefix; 285033965Sjdp const char *volatile_prefix; 285133965Sjdp char buf[20]; 285233965Sjdp unsigned int mangled_name_len; 285333965Sjdp char *physname; 285433965Sjdp 285533965Sjdp len = tagname == NULL ? 0 : strlen (tagname); 285633965Sjdp const_prefix = constp ? "C" : ""; 285733965Sjdp volatile_prefix = volatilep ? "V" : ""; 285833965Sjdp 285933965Sjdp if (len == 0) 286033965Sjdp sprintf (buf, "__%s%s", const_prefix, volatile_prefix); 286133965Sjdp else if (tagname != NULL && strchr (tagname, '<') != NULL) 286233965Sjdp { 286333965Sjdp /* Template methods are fully mangled. */ 286433965Sjdp sprintf (buf, "__%s%s", const_prefix, volatile_prefix); 286533965Sjdp tagname = NULL; 286633965Sjdp len = 0; 286733965Sjdp } 286833965Sjdp else 286933965Sjdp sprintf (buf, "__%s%s%d", const_prefix, volatile_prefix, len); 287033965Sjdp 287133965Sjdp mangled_name_len = ((is_constructor ? 0 : strlen (fieldname)) 287233965Sjdp + strlen (buf) 287333965Sjdp + len 287433965Sjdp + strlen (argtypes) 287533965Sjdp + 1); 287633965Sjdp 287733965Sjdp if (fieldname[0] == 'o' 287833965Sjdp && fieldname[1] == 'p' 287933965Sjdp && (fieldname[2] == '$' || fieldname[2] == '.')) 288033965Sjdp { 288133965Sjdp const char *opname; 288233965Sjdp 288333965Sjdp opname = cplus_mangle_opname (fieldname + 3, 0); 288433965Sjdp if (opname == NULL) 288533965Sjdp { 288660484Sobrien fprintf (stderr, _("No mangling for \"%s\"\n"), fieldname); 288733965Sjdp return DEBUG_TYPE_NULL; 288833965Sjdp } 288933965Sjdp mangled_name_len += strlen (opname); 289033965Sjdp physname = (char *) xmalloc (mangled_name_len); 289133965Sjdp strncpy (physname, fieldname, 3); 289233965Sjdp strcpy (physname + 3, opname); 289333965Sjdp } 289433965Sjdp else 289533965Sjdp { 289633965Sjdp physname = (char *) xmalloc (mangled_name_len); 289733965Sjdp if (is_constructor) 289833965Sjdp physname[0] = '\0'; 289933965Sjdp else 290033965Sjdp strcpy (physname, fieldname); 290133965Sjdp } 290233965Sjdp 2903130561Sobrien physname_len = strlen (physname); 290433965Sjdp strcat (physname, buf); 290533965Sjdp if (tagname != NULL) 290633965Sjdp strcat (physname, tagname); 290733965Sjdp strcat (physname, argtypes); 290833965Sjdp 290933965Sjdp *pphysname = physname; 291033965Sjdp } 291133965Sjdp 291238889Sjdp if (*argtypes == '\0' || is_destructor) 291333965Sjdp { 291433965Sjdp args = (debug_type *) xmalloc (sizeof *args); 291533965Sjdp *args = NULL; 291633965Sjdp return debug_make_method_type (dhandle, return_type, class_type, args, 2917130561Sobrien FALSE); 291833965Sjdp } 291933965Sjdp 2920130561Sobrien args = stab_demangle_argtypes (dhandle, info, *pphysname, &varargs, physname_len); 292133965Sjdp if (args == NULL) 292233965Sjdp return DEBUG_TYPE_NULL; 292333965Sjdp 292433965Sjdp return debug_make_method_type (dhandle, return_type, class_type, args, 292533965Sjdp varargs); 292633965Sjdp} 292733965Sjdp 292833965Sjdp/* The tail end of stabs for C++ classes that contain a virtual function 292933965Sjdp pointer contains a tilde, a %, and a type number. 293033965Sjdp The type number refers to the base class (possibly this class itself) which 293133965Sjdp contains the vtable pointer for the current class. 293233965Sjdp 293333965Sjdp This function is called when we have parsed all the method declarations, 293433965Sjdp so we can look for the vptr base class info. */ 293533965Sjdp 2936130561Sobrienstatic bfd_boolean 2937130561Sobrienparse_stab_tilde_field (void *dhandle, struct stab_handle *info, 2938130561Sobrien const char **pp, const int *typenums, 2939130561Sobrien debug_type *retvptrbase, bfd_boolean *retownvptr) 294033965Sjdp{ 294133965Sjdp const char *orig; 294233965Sjdp const char *hold; 294333965Sjdp int vtypenums[2]; 294433965Sjdp 294533965Sjdp *retvptrbase = DEBUG_TYPE_NULL; 2946130561Sobrien *retownvptr = FALSE; 294733965Sjdp 294833965Sjdp orig = *pp; 294933965Sjdp 2950104834Sobrien /* If we are positioned at a ';', then skip it. */ 295133965Sjdp if (**pp == ';') 295233965Sjdp ++*pp; 295333965Sjdp 295433965Sjdp if (**pp != '~') 2955130561Sobrien return TRUE; 295633965Sjdp 295733965Sjdp ++*pp; 295833965Sjdp 295933965Sjdp if (**pp == '=' || **pp == '+' || **pp == '-') 296033965Sjdp { 296133965Sjdp /* Obsolete flags that used to indicate the presence of 2962104834Sobrien constructors and/or destructors. */ 296333965Sjdp ++*pp; 296433965Sjdp } 296533965Sjdp 296633965Sjdp if (**pp != '%') 2967130561Sobrien return TRUE; 296833965Sjdp 296933965Sjdp ++*pp; 297033965Sjdp 297133965Sjdp hold = *pp; 297233965Sjdp 297333965Sjdp /* The next number is the type number of the base class (possibly 297433965Sjdp our own class) which supplies the vtable for this class. */ 297533965Sjdp if (! parse_stab_type_number (pp, vtypenums)) 2976130561Sobrien return FALSE; 297733965Sjdp 297833965Sjdp if (vtypenums[0] == typenums[0] 297933965Sjdp && vtypenums[1] == typenums[1]) 2980130561Sobrien *retownvptr = TRUE; 298133965Sjdp else 298233965Sjdp { 298333965Sjdp debug_type vtype; 298433965Sjdp const char *p; 298533965Sjdp 298633965Sjdp *pp = hold; 298733965Sjdp 298833965Sjdp vtype = parse_stab_type (dhandle, info, (const char *) NULL, pp, 298933965Sjdp (debug_type **) NULL); 299033965Sjdp for (p = *pp; *p != ';' && *p != '\0'; p++) 299133965Sjdp ; 299233965Sjdp if (*p != ';') 299333965Sjdp { 299433965Sjdp bad_stab (orig); 2995130561Sobrien return FALSE; 299633965Sjdp } 299733965Sjdp 299833965Sjdp *retvptrbase = vtype; 299933965Sjdp 300033965Sjdp *pp = p + 1; 300133965Sjdp } 300233965Sjdp 3003130561Sobrien return TRUE; 300433965Sjdp} 300533965Sjdp 300633965Sjdp/* Read a definition of an array type. */ 300733965Sjdp 300833965Sjdpstatic debug_type 3009130561Sobrienparse_stab_array_type (void *dhandle, struct stab_handle *info, 3010130561Sobrien const char **pp, bfd_boolean stringp) 301133965Sjdp{ 301233965Sjdp const char *orig; 301333965Sjdp const char *p; 301433965Sjdp int typenums[2]; 301533965Sjdp debug_type index_type; 3016130561Sobrien bfd_boolean adjustable; 301733965Sjdp bfd_signed_vma lower, upper; 301833965Sjdp debug_type element_type; 301933965Sjdp 302033965Sjdp /* Format of an array type: 302133965Sjdp "ar<index type>;lower;upper;<array_contents_type>". 302233965Sjdp OS9000: "arlower,upper;<array_contents_type>". 302333965Sjdp 302433965Sjdp Fortran adjustable arrays use Adigits or Tdigits for lower or upper; 302533965Sjdp for these, produce a type like float[][]. */ 302633965Sjdp 302733965Sjdp orig = *pp; 302833965Sjdp 302933965Sjdp /* FIXME: gdb checks os9k_stabs here. */ 303033965Sjdp 303133965Sjdp /* If the index type is type 0, we take it as int. */ 303233965Sjdp p = *pp; 303333965Sjdp if (! parse_stab_type_number (&p, typenums)) 303460484Sobrien return DEBUG_TYPE_NULL; 303533965Sjdp if (typenums[0] == 0 && typenums[1] == 0 && **pp != '=') 303633965Sjdp { 303733965Sjdp index_type = debug_find_named_type (dhandle, "int"); 303833965Sjdp if (index_type == DEBUG_TYPE_NULL) 303933965Sjdp { 3040130561Sobrien index_type = debug_make_int_type (dhandle, 4, FALSE); 304133965Sjdp if (index_type == DEBUG_TYPE_NULL) 304260484Sobrien return DEBUG_TYPE_NULL; 304333965Sjdp } 304433965Sjdp *pp = p; 304533965Sjdp } 304633965Sjdp else 304733965Sjdp { 304833965Sjdp index_type = parse_stab_type (dhandle, info, (const char *) NULL, pp, 304933965Sjdp (debug_type **) NULL); 305033965Sjdp } 305133965Sjdp 305233965Sjdp if (**pp != ';') 305333965Sjdp { 305433965Sjdp bad_stab (orig); 305533965Sjdp return DEBUG_TYPE_NULL; 305633965Sjdp } 305733965Sjdp ++*pp; 305833965Sjdp 3059130561Sobrien adjustable = FALSE; 306033965Sjdp 306189857Sobrien if (! ISDIGIT (**pp) && **pp != '-') 306233965Sjdp { 306333965Sjdp ++*pp; 3064130561Sobrien adjustable = TRUE; 306533965Sjdp } 306633965Sjdp 3067130561Sobrien lower = (bfd_signed_vma) parse_number (pp, (bfd_boolean *) NULL); 306833965Sjdp if (**pp != ';') 306933965Sjdp { 307033965Sjdp bad_stab (orig); 307160484Sobrien return DEBUG_TYPE_NULL; 307233965Sjdp } 307333965Sjdp ++*pp; 307433965Sjdp 307589857Sobrien if (! ISDIGIT (**pp) && **pp != '-') 307633965Sjdp { 307733965Sjdp ++*pp; 3078130561Sobrien adjustable = TRUE; 307933965Sjdp } 308033965Sjdp 3081130561Sobrien upper = (bfd_signed_vma) parse_number (pp, (bfd_boolean *) NULL); 308233965Sjdp if (**pp != ';') 308333965Sjdp { 308433965Sjdp bad_stab (orig); 308560484Sobrien return DEBUG_TYPE_NULL; 308633965Sjdp } 308733965Sjdp ++*pp; 308833965Sjdp 308933965Sjdp element_type = parse_stab_type (dhandle, info, (const char *) NULL, pp, 309033965Sjdp (debug_type **) NULL); 309133965Sjdp if (element_type == DEBUG_TYPE_NULL) 309260484Sobrien return DEBUG_TYPE_NULL; 309333965Sjdp 309433965Sjdp if (adjustable) 309533965Sjdp { 309633965Sjdp lower = 0; 309733965Sjdp upper = -1; 309833965Sjdp } 309933965Sjdp 310033965Sjdp return debug_make_array_type (dhandle, element_type, index_type, lower, 310133965Sjdp upper, stringp); 310233965Sjdp} 310333965Sjdp 310433965Sjdp/* This struct holds information about files we have seen using 310533965Sjdp N_BINCL. */ 310633965Sjdp 310733965Sjdpstruct bincl_file 310833965Sjdp{ 310933965Sjdp /* The next N_BINCL file. */ 311033965Sjdp struct bincl_file *next; 311133965Sjdp /* The next N_BINCL on the stack. */ 311233965Sjdp struct bincl_file *next_stack; 311333965Sjdp /* The file name. */ 311433965Sjdp const char *name; 311533965Sjdp /* The hash value. */ 311633965Sjdp bfd_vma hash; 311733965Sjdp /* The file index. */ 311833965Sjdp unsigned int file; 311933965Sjdp /* The list of types defined in this file. */ 312033965Sjdp struct stab_types *file_types; 312133965Sjdp}; 312233965Sjdp 312333965Sjdp/* Start a new N_BINCL file, pushing it onto the stack. */ 312433965Sjdp 312533965Sjdpstatic void 3126130561Sobrienpush_bincl (struct stab_handle *info, const char *name, bfd_vma hash) 312733965Sjdp{ 312833965Sjdp struct bincl_file *n; 312933965Sjdp 313033965Sjdp n = (struct bincl_file *) xmalloc (sizeof *n); 313133965Sjdp n->next = info->bincl_list; 313233965Sjdp n->next_stack = info->bincl_stack; 313333965Sjdp n->name = name; 313433965Sjdp n->hash = hash; 313533965Sjdp n->file = info->files; 313633965Sjdp n->file_types = NULL; 313733965Sjdp info->bincl_list = n; 313833965Sjdp info->bincl_stack = n; 313933965Sjdp 314033965Sjdp ++info->files; 314133965Sjdp info->file_types = ((struct stab_types **) 3142130561Sobrien xrealloc (info->file_types, 314333965Sjdp (info->files 314433965Sjdp * sizeof *info->file_types))); 314533965Sjdp info->file_types[n->file] = NULL; 314633965Sjdp} 314733965Sjdp 314833965Sjdp/* Finish an N_BINCL file, at an N_EINCL, popping the name off the 314933965Sjdp stack. */ 315033965Sjdp 315133965Sjdpstatic const char * 3152130561Sobrienpop_bincl (struct stab_handle *info) 315333965Sjdp{ 315433965Sjdp struct bincl_file *o; 315533965Sjdp 315633965Sjdp o = info->bincl_stack; 315733965Sjdp if (o == NULL) 315833965Sjdp return info->main_filename; 315933965Sjdp info->bincl_stack = o->next_stack; 316033965Sjdp 316133965Sjdp o->file_types = info->file_types[o->file]; 316233965Sjdp 316333965Sjdp if (info->bincl_stack == NULL) 316433965Sjdp return info->main_filename; 316533965Sjdp return info->bincl_stack->name; 316633965Sjdp} 316733965Sjdp 316833965Sjdp/* Handle an N_EXCL: get the types from the corresponding N_BINCL. */ 316933965Sjdp 3170130561Sobrienstatic bfd_boolean 3171130561Sobrienfind_excl (struct stab_handle *info, const char *name, bfd_vma hash) 317233965Sjdp{ 317333965Sjdp struct bincl_file *l; 317433965Sjdp 317533965Sjdp ++info->files; 317633965Sjdp info->file_types = ((struct stab_types **) 3177130561Sobrien xrealloc (info->file_types, 317833965Sjdp (info->files 317933965Sjdp * sizeof *info->file_types))); 318033965Sjdp 318133965Sjdp for (l = info->bincl_list; l != NULL; l = l->next) 318233965Sjdp if (l->hash == hash && strcmp (l->name, name) == 0) 318333965Sjdp break; 318433965Sjdp if (l == NULL) 318533965Sjdp { 318660484Sobrien warn_stab (name, _("Undefined N_EXCL")); 318733965Sjdp info->file_types[info->files - 1] = NULL; 3188130561Sobrien return TRUE; 318933965Sjdp } 319033965Sjdp 319133965Sjdp info->file_types[info->files - 1] = l->file_types; 319233965Sjdp 3193130561Sobrien return TRUE; 319433965Sjdp} 319533965Sjdp 319633965Sjdp/* Handle a variable definition. gcc emits variable definitions for a 319733965Sjdp block before the N_LBRAC, so we must hold onto them until we see 319833965Sjdp it. The SunPRO compiler emits variable definitions after the 319933965Sjdp N_LBRAC, so we can call debug_record_variable immediately. */ 320033965Sjdp 3201130561Sobrienstatic bfd_boolean 3202130561Sobrienstab_record_variable (void *dhandle, struct stab_handle *info, 3203130561Sobrien const char *name, debug_type type, 3204130561Sobrien enum debug_var_kind kind, bfd_vma val) 320533965Sjdp{ 320633965Sjdp struct stab_pending_var *v; 320733965Sjdp 320833965Sjdp if ((kind == DEBUG_GLOBAL || kind == DEBUG_STATIC) 320933965Sjdp || ! info->within_function 321033965Sjdp || (info->gcc_compiled == 0 && info->n_opt_found)) 321133965Sjdp return debug_record_variable (dhandle, name, type, kind, val); 321233965Sjdp 321333965Sjdp v = (struct stab_pending_var *) xmalloc (sizeof *v); 321433965Sjdp memset (v, 0, sizeof *v); 321533965Sjdp 321633965Sjdp v->next = info->pending; 321733965Sjdp v->name = name; 321833965Sjdp v->type = type; 321933965Sjdp v->kind = kind; 322033965Sjdp v->val = val; 322133965Sjdp info->pending = v; 322233965Sjdp 3223130561Sobrien return TRUE; 322433965Sjdp} 322533965Sjdp 322633965Sjdp/* Emit pending variable definitions. This is called after we see the 322733965Sjdp N_LBRAC that starts the block. */ 322833965Sjdp 3229130561Sobrienstatic bfd_boolean 3230130561Sobrienstab_emit_pending_vars (void *dhandle, struct stab_handle *info) 323133965Sjdp{ 323233965Sjdp struct stab_pending_var *v; 323333965Sjdp 323433965Sjdp v = info->pending; 323533965Sjdp while (v != NULL) 323633965Sjdp { 323733965Sjdp struct stab_pending_var *next; 323833965Sjdp 323933965Sjdp if (! debug_record_variable (dhandle, v->name, v->type, v->kind, v->val)) 3240130561Sobrien return FALSE; 324133965Sjdp 324233965Sjdp next = v->next; 324333965Sjdp free (v); 324433965Sjdp v = next; 324533965Sjdp } 324633965Sjdp 324733965Sjdp info->pending = NULL; 324833965Sjdp 3249130561Sobrien return TRUE; 325033965Sjdp} 325133965Sjdp 325233965Sjdp/* Find the slot for a type in the database. */ 325333965Sjdp 325433965Sjdpstatic debug_type * 3255130561Sobrienstab_find_slot (struct stab_handle *info, const int *typenums) 325633965Sjdp{ 325733965Sjdp int filenum; 325833965Sjdp int index; 325933965Sjdp struct stab_types **ps; 326033965Sjdp 326133965Sjdp filenum = typenums[0]; 326233965Sjdp index = typenums[1]; 326333965Sjdp 326433965Sjdp if (filenum < 0 || (unsigned int) filenum >= info->files) 326533965Sjdp { 326660484Sobrien fprintf (stderr, _("Type file number %d out of range\n"), filenum); 326733965Sjdp return NULL; 326833965Sjdp } 326933965Sjdp if (index < 0) 327033965Sjdp { 327160484Sobrien fprintf (stderr, _("Type index number %d out of range\n"), index); 327233965Sjdp return NULL; 327333965Sjdp } 327433965Sjdp 327533965Sjdp ps = info->file_types + filenum; 327633965Sjdp 327733965Sjdp while (index >= STAB_TYPES_SLOTS) 327833965Sjdp { 327933965Sjdp if (*ps == NULL) 328033965Sjdp { 328133965Sjdp *ps = (struct stab_types *) xmalloc (sizeof **ps); 328233965Sjdp memset (*ps, 0, sizeof **ps); 328333965Sjdp } 328433965Sjdp ps = &(*ps)->next; 328533965Sjdp index -= STAB_TYPES_SLOTS; 328633965Sjdp } 328733965Sjdp if (*ps == NULL) 328833965Sjdp { 328933965Sjdp *ps = (struct stab_types *) xmalloc (sizeof **ps); 329033965Sjdp memset (*ps, 0, sizeof **ps); 329133965Sjdp } 329233965Sjdp 329333965Sjdp return (*ps)->types + index; 329433965Sjdp} 329533965Sjdp 329633965Sjdp/* Find a type given a type number. If the type has not been 329733965Sjdp allocated yet, create an indirect type. */ 329833965Sjdp 329933965Sjdpstatic debug_type 3300130561Sobrienstab_find_type (void *dhandle, struct stab_handle *info, const int *typenums) 330133965Sjdp{ 330233965Sjdp debug_type *slot; 330333965Sjdp 330433965Sjdp if (typenums[0] == 0 && typenums[1] < 0) 330533965Sjdp { 330633965Sjdp /* A negative type number indicates an XCOFF builtin type. */ 330733965Sjdp return stab_xcoff_builtin_type (dhandle, info, typenums[1]); 330833965Sjdp } 330933965Sjdp 331033965Sjdp slot = stab_find_slot (info, typenums); 331133965Sjdp if (slot == NULL) 331233965Sjdp return DEBUG_TYPE_NULL; 331333965Sjdp 331433965Sjdp if (*slot == DEBUG_TYPE_NULL) 331533965Sjdp return debug_make_indirect_type (dhandle, slot, (const char *) NULL); 331633965Sjdp 331733965Sjdp return *slot; 331833965Sjdp} 331933965Sjdp 332033965Sjdp/* Record that a given type number refers to a given type. */ 332133965Sjdp 3322130561Sobrienstatic bfd_boolean 3323130561Sobrienstab_record_type (void *dhandle ATTRIBUTE_UNUSED, struct stab_handle *info, 3324130561Sobrien const int *typenums, debug_type type) 332533965Sjdp{ 332633965Sjdp debug_type *slot; 332733965Sjdp 332833965Sjdp slot = stab_find_slot (info, typenums); 332933965Sjdp if (slot == NULL) 3330130561Sobrien return FALSE; 333133965Sjdp 333233965Sjdp /* gdb appears to ignore type redefinitions, so we do as well. */ 333333965Sjdp 333433965Sjdp *slot = type; 333533965Sjdp 3336130561Sobrien return TRUE; 333733965Sjdp} 333833965Sjdp 333933965Sjdp/* Return an XCOFF builtin type. */ 334033965Sjdp 334133965Sjdpstatic debug_type 3342130561Sobrienstab_xcoff_builtin_type (void *dhandle, struct stab_handle *info, 3343130561Sobrien int typenum) 334433965Sjdp{ 334533965Sjdp debug_type rettype; 334633965Sjdp const char *name; 334733965Sjdp 334833965Sjdp if (typenum >= 0 || typenum < -XCOFF_TYPE_COUNT) 334933965Sjdp { 335060484Sobrien fprintf (stderr, _("Unrecognized XCOFF type %d\n"), typenum); 335133965Sjdp return DEBUG_TYPE_NULL; 335233965Sjdp } 335333965Sjdp if (info->xcoff_types[-typenum] != NULL) 335433965Sjdp return info->xcoff_types[-typenum]; 335533965Sjdp 335633965Sjdp switch (-typenum) 335733965Sjdp { 335833965Sjdp case 1: 335933965Sjdp /* The size of this and all the other types are fixed, defined 336033965Sjdp by the debugging format. */ 336133965Sjdp name = "int"; 3362130561Sobrien rettype = debug_make_int_type (dhandle, 4, FALSE); 336333965Sjdp break; 336433965Sjdp case 2: 336533965Sjdp name = "char"; 3366130561Sobrien rettype = debug_make_int_type (dhandle, 1, FALSE); 336733965Sjdp break; 336833965Sjdp case 3: 336933965Sjdp name = "short"; 3370130561Sobrien rettype = debug_make_int_type (dhandle, 2, FALSE); 337133965Sjdp break; 337233965Sjdp case 4: 337333965Sjdp name = "long"; 3374130561Sobrien rettype = debug_make_int_type (dhandle, 4, FALSE); 337533965Sjdp break; 337633965Sjdp case 5: 337733965Sjdp name = "unsigned char"; 3378130561Sobrien rettype = debug_make_int_type (dhandle, 1, TRUE); 337933965Sjdp break; 338033965Sjdp case 6: 338133965Sjdp name = "signed char"; 3382130561Sobrien rettype = debug_make_int_type (dhandle, 1, FALSE); 338333965Sjdp break; 338433965Sjdp case 7: 338533965Sjdp name = "unsigned short"; 3386130561Sobrien rettype = debug_make_int_type (dhandle, 2, TRUE); 338733965Sjdp break; 338833965Sjdp case 8: 338933965Sjdp name = "unsigned int"; 3390130561Sobrien rettype = debug_make_int_type (dhandle, 4, TRUE); 339133965Sjdp break; 339233965Sjdp case 9: 339333965Sjdp name = "unsigned"; 3394130561Sobrien rettype = debug_make_int_type (dhandle, 4, TRUE); 339533965Sjdp case 10: 339633965Sjdp name = "unsigned long"; 3397130561Sobrien rettype = debug_make_int_type (dhandle, 4, TRUE); 339833965Sjdp break; 339933965Sjdp case 11: 340033965Sjdp name = "void"; 340133965Sjdp rettype = debug_make_void_type (dhandle); 340233965Sjdp break; 340333965Sjdp case 12: 340433965Sjdp /* IEEE single precision (32 bit). */ 340533965Sjdp name = "float"; 340633965Sjdp rettype = debug_make_float_type (dhandle, 4); 340733965Sjdp break; 340833965Sjdp case 13: 340933965Sjdp /* IEEE double precision (64 bit). */ 341033965Sjdp name = "double"; 341133965Sjdp rettype = debug_make_float_type (dhandle, 8); 341233965Sjdp break; 341333965Sjdp case 14: 341433965Sjdp /* This is an IEEE double on the RS/6000, and different machines 341533965Sjdp with different sizes for "long double" should use different 341633965Sjdp negative type numbers. See stabs.texinfo. */ 341733965Sjdp name = "long double"; 341833965Sjdp rettype = debug_make_float_type (dhandle, 8); 341933965Sjdp break; 342033965Sjdp case 15: 342133965Sjdp name = "integer"; 3422130561Sobrien rettype = debug_make_int_type (dhandle, 4, FALSE); 342333965Sjdp break; 342433965Sjdp case 16: 342533965Sjdp name = "boolean"; 342633965Sjdp rettype = debug_make_bool_type (dhandle, 4); 342733965Sjdp break; 342833965Sjdp case 17: 342933965Sjdp name = "short real"; 343033965Sjdp rettype = debug_make_float_type (dhandle, 4); 343133965Sjdp break; 343233965Sjdp case 18: 343333965Sjdp name = "real"; 343433965Sjdp rettype = debug_make_float_type (dhandle, 8); 343533965Sjdp break; 343633965Sjdp case 19: 343733965Sjdp /* FIXME */ 343833965Sjdp name = "stringptr"; 343933965Sjdp rettype = NULL; 344033965Sjdp break; 344133965Sjdp case 20: 344233965Sjdp /* FIXME */ 344333965Sjdp name = "character"; 3444130561Sobrien rettype = debug_make_int_type (dhandle, 1, TRUE); 344533965Sjdp break; 344633965Sjdp case 21: 344733965Sjdp name = "logical*1"; 344833965Sjdp rettype = debug_make_bool_type (dhandle, 1); 344933965Sjdp break; 345033965Sjdp case 22: 345133965Sjdp name = "logical*2"; 345233965Sjdp rettype = debug_make_bool_type (dhandle, 2); 345333965Sjdp break; 345433965Sjdp case 23: 345533965Sjdp name = "logical*4"; 345633965Sjdp rettype = debug_make_bool_type (dhandle, 4); 345733965Sjdp break; 345833965Sjdp case 24: 345933965Sjdp name = "logical"; 346033965Sjdp rettype = debug_make_bool_type (dhandle, 4); 346133965Sjdp break; 346233965Sjdp case 25: 346333965Sjdp /* Complex type consisting of two IEEE single precision values. */ 346433965Sjdp name = "complex"; 346533965Sjdp rettype = debug_make_complex_type (dhandle, 8); 346633965Sjdp break; 346733965Sjdp case 26: 346833965Sjdp /* Complex type consisting of two IEEE double precision values. */ 346933965Sjdp name = "double complex"; 347033965Sjdp rettype = debug_make_complex_type (dhandle, 16); 347133965Sjdp break; 347233965Sjdp case 27: 347333965Sjdp name = "integer*1"; 3474130561Sobrien rettype = debug_make_int_type (dhandle, 1, FALSE); 347533965Sjdp break; 347633965Sjdp case 28: 347733965Sjdp name = "integer*2"; 3478130561Sobrien rettype = debug_make_int_type (dhandle, 2, FALSE); 347933965Sjdp break; 348033965Sjdp case 29: 348133965Sjdp name = "integer*4"; 3482130561Sobrien rettype = debug_make_int_type (dhandle, 4, FALSE); 348333965Sjdp break; 348433965Sjdp case 30: 348533965Sjdp /* FIXME */ 348633965Sjdp name = "wchar"; 3487130561Sobrien rettype = debug_make_int_type (dhandle, 2, FALSE); 348833965Sjdp break; 348933965Sjdp case 31: 349033965Sjdp name = "long long"; 3491130561Sobrien rettype = debug_make_int_type (dhandle, 8, FALSE); 349233965Sjdp break; 349333965Sjdp case 32: 349433965Sjdp name = "unsigned long long"; 3495130561Sobrien rettype = debug_make_int_type (dhandle, 8, TRUE); 349633965Sjdp break; 349733965Sjdp case 33: 349833965Sjdp name = "logical*8"; 349933965Sjdp rettype = debug_make_bool_type (dhandle, 8); 350033965Sjdp break; 350133965Sjdp case 34: 350233965Sjdp name = "integer*8"; 3503130561Sobrien rettype = debug_make_int_type (dhandle, 8, FALSE); 350433965Sjdp break; 350533965Sjdp default: 350633965Sjdp abort (); 350733965Sjdp } 350833965Sjdp 350933965Sjdp rettype = debug_name_type (dhandle, name, rettype); 351033965Sjdp 351133965Sjdp info->xcoff_types[-typenum] = rettype; 351233965Sjdp 351333965Sjdp return rettype; 351433965Sjdp} 351533965Sjdp 351633965Sjdp/* Find or create a tagged type. */ 351733965Sjdp 351833965Sjdpstatic debug_type 3519130561Sobrienstab_find_tagged_type (void *dhandle, struct stab_handle *info, 3520130561Sobrien const char *p, int len, enum debug_type_kind kind) 352133965Sjdp{ 352233965Sjdp char *name; 352333965Sjdp debug_type dtype; 352433965Sjdp struct stab_tag *st; 352533965Sjdp 352633965Sjdp name = savestring (p, len); 352733965Sjdp 352833965Sjdp /* We pass DEBUG_KIND_ILLEGAL because we want all tags in the same 352933965Sjdp namespace. This is right for C, and I don't know how to handle 353033965Sjdp other languages. FIXME. */ 353133965Sjdp dtype = debug_find_tagged_type (dhandle, name, DEBUG_KIND_ILLEGAL); 353233965Sjdp if (dtype != DEBUG_TYPE_NULL) 353333965Sjdp { 353433965Sjdp free (name); 353533965Sjdp return dtype; 353633965Sjdp } 353733965Sjdp 353833965Sjdp /* We need to allocate an entry on the undefined tag list. */ 353933965Sjdp for (st = info->tags; st != NULL; st = st->next) 354033965Sjdp { 354133965Sjdp if (st->name[0] == name[0] 354233965Sjdp && strcmp (st->name, name) == 0) 354333965Sjdp { 354433965Sjdp if (st->kind == DEBUG_KIND_ILLEGAL) 354533965Sjdp st->kind = kind; 354633965Sjdp free (name); 354733965Sjdp break; 354833965Sjdp } 354933965Sjdp } 355033965Sjdp if (st == NULL) 355133965Sjdp { 355233965Sjdp st = (struct stab_tag *) xmalloc (sizeof *st); 355333965Sjdp memset (st, 0, sizeof *st); 355433965Sjdp 355533965Sjdp st->next = info->tags; 355633965Sjdp st->name = name; 355733965Sjdp st->kind = kind; 355833965Sjdp st->slot = DEBUG_TYPE_NULL; 355933965Sjdp st->type = debug_make_indirect_type (dhandle, &st->slot, name); 356033965Sjdp info->tags = st; 356133965Sjdp } 356233965Sjdp 356333965Sjdp return st->type; 356433965Sjdp} 356533965Sjdp 356633965Sjdp/* In order to get the correct argument types for a stubbed method, we 356733965Sjdp need to extract the argument types from a C++ mangled string. 356833965Sjdp Since the argument types can refer back to the return type, this 356933965Sjdp means that we must demangle the entire physical name. In gdb this 357033965Sjdp is done by calling cplus_demangle and running the results back 357133965Sjdp through the C++ expression parser. Since we have no expression 357233965Sjdp parser, we must duplicate much of the work of cplus_demangle here. 357333965Sjdp 357433965Sjdp We assume that GNU style demangling is used, since this is only 357533965Sjdp done for method stubs, and only g++ should output that form of 357633965Sjdp debugging information. */ 357733965Sjdp 357833965Sjdp/* This structure is used to hold a pointer to type information which 357933965Sjdp demangling a string. */ 358033965Sjdp 358133965Sjdpstruct stab_demangle_typestring 358233965Sjdp{ 358333965Sjdp /* The start of the type. This is not null terminated. */ 358433965Sjdp const char *typestring; 358533965Sjdp /* The length of the type. */ 358633965Sjdp unsigned int len; 358733965Sjdp}; 358833965Sjdp 358933965Sjdp/* This structure is used to hold information while demangling a 359033965Sjdp string. */ 359133965Sjdp 359233965Sjdpstruct stab_demangle_info 359333965Sjdp{ 359433965Sjdp /* The debugging information handle. */ 3595130561Sobrien void *dhandle; 359633965Sjdp /* The stab information handle. */ 359733965Sjdp struct stab_handle *info; 359833965Sjdp /* The array of arguments we are building. */ 359933965Sjdp debug_type *args; 360033965Sjdp /* Whether the method takes a variable number of arguments. */ 3601130561Sobrien bfd_boolean varargs; 360233965Sjdp /* The array of types we have remembered. */ 360333965Sjdp struct stab_demangle_typestring *typestrings; 360433965Sjdp /* The number of typestrings. */ 360533965Sjdp unsigned int typestring_count; 360633965Sjdp /* The number of typestring slots we have allocated. */ 360733965Sjdp unsigned int typestring_alloc; 360833965Sjdp}; 360933965Sjdp 3610130561Sobrienstatic void stab_bad_demangle (const char *); 3611130561Sobrienstatic unsigned int stab_demangle_count (const char **); 3612130561Sobrienstatic bfd_boolean stab_demangle_get_count (const char **, unsigned int *); 3613130561Sobrienstatic bfd_boolean stab_demangle_prefix 3614130561Sobrien (struct stab_demangle_info *, const char **, unsigned int); 3615130561Sobrienstatic bfd_boolean stab_demangle_function_name 3616130561Sobrien (struct stab_demangle_info *, const char **, const char *); 3617130561Sobrienstatic bfd_boolean stab_demangle_signature 3618130561Sobrien (struct stab_demangle_info *, const char **); 3619130561Sobrienstatic bfd_boolean stab_demangle_qualified 3620130561Sobrien (struct stab_demangle_info *, const char **, debug_type *); 3621130561Sobrienstatic bfd_boolean stab_demangle_template 3622130561Sobrien (struct stab_demangle_info *, const char **, char **); 3623130561Sobrienstatic bfd_boolean stab_demangle_class 3624130561Sobrien (struct stab_demangle_info *, const char **, const char **); 3625130561Sobrienstatic bfd_boolean stab_demangle_args 3626130561Sobrien (struct stab_demangle_info *, const char **, debug_type **, bfd_boolean *); 3627130561Sobrienstatic bfd_boolean stab_demangle_arg 3628130561Sobrien (struct stab_demangle_info *, const char **, debug_type **, 3629130561Sobrien unsigned int *, unsigned int *); 3630130561Sobrienstatic bfd_boolean stab_demangle_type 3631130561Sobrien (struct stab_demangle_info *, const char **, debug_type *); 3632130561Sobrienstatic bfd_boolean stab_demangle_fund_type 3633130561Sobrien (struct stab_demangle_info *, const char **, debug_type *); 3634130561Sobrienstatic bfd_boolean stab_demangle_remember_type 3635130561Sobrien (struct stab_demangle_info *, const char *, int); 363633965Sjdp 363733965Sjdp/* Warn about a bad demangling. */ 363833965Sjdp 363933965Sjdpstatic void 3640130561Sobrienstab_bad_demangle (const char *s) 364133965Sjdp{ 364260484Sobrien fprintf (stderr, _("bad mangled name `%s'\n"), s); 364333965Sjdp} 364433965Sjdp 364533965Sjdp/* Get a count from a stab string. */ 364633965Sjdp 364733965Sjdpstatic unsigned int 3648130561Sobrienstab_demangle_count (const char **pp) 364933965Sjdp{ 365033965Sjdp unsigned int count; 365133965Sjdp 365233965Sjdp count = 0; 365389857Sobrien while (ISDIGIT (**pp)) 365433965Sjdp { 365533965Sjdp count *= 10; 365633965Sjdp count += **pp - '0'; 365733965Sjdp ++*pp; 365833965Sjdp } 365933965Sjdp return count; 366033965Sjdp} 366133965Sjdp 366233965Sjdp/* Require a count in a string. The count may be multiple digits, in 366333965Sjdp which case it must end in an underscore. */ 366433965Sjdp 3665130561Sobrienstatic bfd_boolean 3666130561Sobrienstab_demangle_get_count (const char **pp, unsigned int *pi) 366733965Sjdp{ 366889857Sobrien if (! ISDIGIT (**pp)) 3669130561Sobrien return FALSE; 367033965Sjdp 367133965Sjdp *pi = **pp - '0'; 367233965Sjdp ++*pp; 367389857Sobrien if (ISDIGIT (**pp)) 367433965Sjdp { 367533965Sjdp unsigned int count; 367633965Sjdp const char *p; 367733965Sjdp 367833965Sjdp count = *pi; 367933965Sjdp p = *pp; 368033965Sjdp do 368133965Sjdp { 368233965Sjdp count *= 10; 368333965Sjdp count += *p - '0'; 368433965Sjdp ++p; 368533965Sjdp } 368689857Sobrien while (ISDIGIT (*p)); 368733965Sjdp if (*p == '_') 368833965Sjdp { 368933965Sjdp *pp = p + 1; 369033965Sjdp *pi = count; 369133965Sjdp } 369233965Sjdp } 369333965Sjdp 3694130561Sobrien return TRUE; 369533965Sjdp} 369633965Sjdp 369733965Sjdp/* This function demangles a physical name, returning a NULL 369833965Sjdp terminated array of argument types. */ 369933965Sjdp 370033965Sjdpstatic debug_type * 3701130561Sobrienstab_demangle_argtypes (void *dhandle, struct stab_handle *info, 3702130561Sobrien const char *physname, bfd_boolean *pvarargs, 3703130561Sobrien unsigned int physname_len) 370433965Sjdp{ 370533965Sjdp struct stab_demangle_info minfo; 370633965Sjdp 3707130561Sobrien /* Check for the g++ V3 ABI. */ 3708130561Sobrien if (physname[0] == '_' && physname[1] == 'Z') 3709130561Sobrien return stab_demangle_v3_argtypes (dhandle, info, physname, pvarargs); 3710130561Sobrien 371133965Sjdp minfo.dhandle = dhandle; 371233965Sjdp minfo.info = info; 371333965Sjdp minfo.args = NULL; 3714130561Sobrien minfo.varargs = FALSE; 371533965Sjdp minfo.typestring_alloc = 10; 371633965Sjdp minfo.typestrings = ((struct stab_demangle_typestring *) 371733965Sjdp xmalloc (minfo.typestring_alloc 371833965Sjdp * sizeof *minfo.typestrings)); 371933965Sjdp minfo.typestring_count = 0; 372033965Sjdp 372133965Sjdp /* cplus_demangle checks for special GNU mangled forms, but we can't 372233965Sjdp see any of them in mangled method argument types. */ 372333965Sjdp 3724130561Sobrien if (! stab_demangle_prefix (&minfo, &physname, physname_len)) 372533965Sjdp goto error_return; 372633965Sjdp 372733965Sjdp if (*physname != '\0') 372833965Sjdp { 372933965Sjdp if (! stab_demangle_signature (&minfo, &physname)) 373033965Sjdp goto error_return; 373133965Sjdp } 373233965Sjdp 373333965Sjdp free (minfo.typestrings); 373433965Sjdp minfo.typestrings = NULL; 373533965Sjdp 373633965Sjdp if (minfo.args == NULL) 373760484Sobrien fprintf (stderr, _("no argument types in mangled string\n")); 373833965Sjdp 373933965Sjdp *pvarargs = minfo.varargs; 374033965Sjdp return minfo.args; 374133965Sjdp 374233965Sjdp error_return: 374333965Sjdp if (minfo.typestrings != NULL) 374433965Sjdp free (minfo.typestrings); 374533965Sjdp return NULL; 374633965Sjdp} 374733965Sjdp 374833965Sjdp/* Demangle the prefix of the mangled name. */ 374933965Sjdp 3750130561Sobrienstatic bfd_boolean 3751130561Sobrienstab_demangle_prefix (struct stab_demangle_info *minfo, const char **pp, 3752130561Sobrien unsigned int physname_len) 375333965Sjdp{ 375433965Sjdp const char *scan; 375533965Sjdp unsigned int i; 375633965Sjdp 375733965Sjdp /* cplus_demangle checks for global constructors and destructors, 375833965Sjdp but we can't see them in mangled argument types. */ 375933965Sjdp 3760130561Sobrien if (physname_len) 3761130561Sobrien scan = *pp + physname_len; 3762130561Sobrien else 376333965Sjdp { 3764130561Sobrien /* Look for `__'. */ 3765130561Sobrien scan = *pp; 3766130561Sobrien do 3767130561Sobrien scan = strchr (scan, '_'); 3768130561Sobrien while (scan != NULL && *++scan != '_'); 376933965Sjdp 3770130561Sobrien if (scan == NULL) 3771130561Sobrien { 3772130561Sobrien stab_bad_demangle (*pp); 3773130561Sobrien return FALSE; 3774130561Sobrien } 377533965Sjdp 3776130561Sobrien --scan; 377733965Sjdp 3778130561Sobrien /* We found `__'; move ahead to the last contiguous `__' pair. */ 3779130561Sobrien i = strspn (scan, "_"); 3780130561Sobrien if (i > 2) 3781130561Sobrien scan += i - 2; 3782130561Sobrien } 378333965Sjdp 378433965Sjdp if (scan == *pp 378589857Sobrien && (ISDIGIT (scan[2]) 378633965Sjdp || scan[2] == 'Q' 378733965Sjdp || scan[2] == 't')) 378833965Sjdp { 378933965Sjdp /* This is a GNU style constructor name. */ 379033965Sjdp *pp = scan + 2; 3791130561Sobrien return TRUE; 379233965Sjdp } 379333965Sjdp else if (scan == *pp 379489857Sobrien && ! ISDIGIT (scan[2]) 379533965Sjdp && scan[2] != 't') 379633965Sjdp { 379733965Sjdp /* Look for the `__' that separates the prefix from the 379833965Sjdp signature. */ 379933965Sjdp while (*scan == '_') 380033965Sjdp ++scan; 380133965Sjdp scan = strstr (scan, "__"); 380233965Sjdp if (scan == NULL || scan[2] == '\0') 380333965Sjdp { 380433965Sjdp stab_bad_demangle (*pp); 3805130561Sobrien return FALSE; 380633965Sjdp } 380733965Sjdp 380833965Sjdp return stab_demangle_function_name (minfo, pp, scan); 380933965Sjdp } 381033965Sjdp else if (scan[2] != '\0') 381133965Sjdp { 381233965Sjdp /* The name doesn't start with `__', but it does contain `__'. */ 381333965Sjdp return stab_demangle_function_name (minfo, pp, scan); 381433965Sjdp } 381533965Sjdp else 381633965Sjdp { 381733965Sjdp stab_bad_demangle (*pp); 3818130561Sobrien return FALSE; 381933965Sjdp } 382033965Sjdp /*NOTREACHED*/ 382133965Sjdp} 382233965Sjdp 382333965Sjdp/* Demangle a function name prefix. The scan argument points to the 382433965Sjdp double underscore which separates the function name from the 382533965Sjdp signature. */ 382633965Sjdp 3827130561Sobrienstatic bfd_boolean 3828130561Sobrienstab_demangle_function_name (struct stab_demangle_info *minfo, 3829130561Sobrien const char **pp, const char *scan) 383033965Sjdp{ 383133965Sjdp const char *name; 383233965Sjdp 383333965Sjdp /* The string from *pp to scan is the name of the function. We 383433965Sjdp don't care about the name, since we just looking for argument 383533965Sjdp types. However, for conversion operators, the name may include a 383633965Sjdp type which we must remember in order to handle backreferences. */ 383733965Sjdp 383833965Sjdp name = *pp; 383933965Sjdp *pp = scan + 2; 384033965Sjdp 384133965Sjdp if (*pp - name >= 5 3842218822Sdim && CONST_STRNEQ (name, "type") 384333965Sjdp && (name[4] == '$' || name[4] == '.')) 384433965Sjdp { 384533965Sjdp const char *tem; 384633965Sjdp 384733965Sjdp /* This is a type conversion operator. */ 384833965Sjdp tem = name + 5; 384933965Sjdp if (! stab_demangle_type (minfo, &tem, (debug_type *) NULL)) 3850130561Sobrien return FALSE; 385133965Sjdp } 385233965Sjdp else if (name[0] == '_' 385333965Sjdp && name[1] == '_' 385433965Sjdp && name[2] == 'o' 385533965Sjdp && name[3] == 'p') 385633965Sjdp { 385733965Sjdp const char *tem; 385833965Sjdp 385933965Sjdp /* This is a type conversion operator. */ 386033965Sjdp tem = name + 4; 386133965Sjdp if (! stab_demangle_type (minfo, &tem, (debug_type *) NULL)) 3862130561Sobrien return FALSE; 386333965Sjdp } 386433965Sjdp 3865130561Sobrien return TRUE; 386633965Sjdp} 386733965Sjdp 386833965Sjdp/* Demangle the signature. This is where the argument types are 386933965Sjdp found. */ 387033965Sjdp 3871130561Sobrienstatic bfd_boolean 3872130561Sobrienstab_demangle_signature (struct stab_demangle_info *minfo, const char **pp) 387333965Sjdp{ 387433965Sjdp const char *orig; 3875130561Sobrien bfd_boolean expect_func, func_done; 387633965Sjdp const char *hold; 387733965Sjdp 387833965Sjdp orig = *pp; 387933965Sjdp 3880130561Sobrien expect_func = FALSE; 3881130561Sobrien func_done = FALSE; 388233965Sjdp hold = NULL; 388333965Sjdp 388433965Sjdp while (**pp != '\0') 388533965Sjdp { 388633965Sjdp switch (**pp) 388733965Sjdp { 388833965Sjdp case 'Q': 388933965Sjdp hold = *pp; 389033965Sjdp if (! stab_demangle_qualified (minfo, pp, (debug_type *) NULL) 389133965Sjdp || ! stab_demangle_remember_type (minfo, hold, *pp - hold)) 3892130561Sobrien return FALSE; 3893130561Sobrien expect_func = TRUE; 389433965Sjdp hold = NULL; 389533965Sjdp break; 389633965Sjdp 389733965Sjdp case 'S': 389833965Sjdp /* Static member function. FIXME: Can this happen? */ 389933965Sjdp if (hold == NULL) 390033965Sjdp hold = *pp; 390133965Sjdp ++*pp; 390233965Sjdp break; 390333965Sjdp 390433965Sjdp case 'C': 390533965Sjdp /* Const member function. */ 390633965Sjdp if (hold == NULL) 390733965Sjdp hold = *pp; 390833965Sjdp ++*pp; 390933965Sjdp break; 391033965Sjdp 391133965Sjdp case '0': case '1': case '2': case '3': case '4': 391233965Sjdp case '5': case '6': case '7': case '8': case '9': 391333965Sjdp if (hold == NULL) 391433965Sjdp hold = *pp; 391533965Sjdp if (! stab_demangle_class (minfo, pp, (const char **) NULL) 391633965Sjdp || ! stab_demangle_remember_type (minfo, hold, *pp - hold)) 3917130561Sobrien return FALSE; 3918130561Sobrien expect_func = TRUE; 391933965Sjdp hold = NULL; 392033965Sjdp break; 392133965Sjdp 392233965Sjdp case 'F': 392333965Sjdp /* Function. I don't know if this actually happens with g++ 392433965Sjdp output. */ 392533965Sjdp hold = NULL; 3926130561Sobrien func_done = TRUE; 392733965Sjdp ++*pp; 392833965Sjdp if (! stab_demangle_args (minfo, pp, &minfo->args, &minfo->varargs)) 3929130561Sobrien return FALSE; 393033965Sjdp break; 393133965Sjdp 393233965Sjdp case 't': 393333965Sjdp /* Template. */ 393433965Sjdp if (hold == NULL) 393533965Sjdp hold = *pp; 393660484Sobrien if (! stab_demangle_template (minfo, pp, (char **) NULL) 393733965Sjdp || ! stab_demangle_remember_type (minfo, hold, *pp - hold)) 3938130561Sobrien return FALSE; 393933965Sjdp hold = NULL; 3940130561Sobrien expect_func = TRUE; 394133965Sjdp break; 394233965Sjdp 394333965Sjdp case '_': 394433965Sjdp /* At the outermost level, we cannot have a return type 394533965Sjdp specified, so if we run into another '_' at this point we 394633965Sjdp are dealing with a mangled name that is either bogus, or 394733965Sjdp has been mangled by some algorithm we don't know how to 394833965Sjdp deal with. So just reject the entire demangling. */ 394933965Sjdp stab_bad_demangle (orig); 3950130561Sobrien return FALSE; 395133965Sjdp 395233965Sjdp default: 395333965Sjdp /* Assume we have stumbled onto the first outermost function 395433965Sjdp argument token, and start processing args. */ 3955130561Sobrien func_done = TRUE; 395633965Sjdp if (! stab_demangle_args (minfo, pp, &minfo->args, &minfo->varargs)) 3957130561Sobrien return FALSE; 395833965Sjdp break; 395933965Sjdp } 396033965Sjdp 396133965Sjdp if (expect_func) 396233965Sjdp { 3963130561Sobrien func_done = TRUE; 396433965Sjdp if (! stab_demangle_args (minfo, pp, &minfo->args, &minfo->varargs)) 3965130561Sobrien return FALSE; 396633965Sjdp } 396733965Sjdp } 396833965Sjdp 396933965Sjdp if (! func_done) 397033965Sjdp { 397133965Sjdp /* With GNU style demangling, bar__3foo is 'foo::bar(void)', and 397233965Sjdp bar__3fooi is 'foo::bar(int)'. We get here when we find the 397333965Sjdp first case, and need to ensure that the '(void)' gets added 397433965Sjdp to the current declp. */ 397533965Sjdp if (! stab_demangle_args (minfo, pp, &minfo->args, &minfo->varargs)) 3976130561Sobrien return FALSE; 397733965Sjdp } 397833965Sjdp 3979130561Sobrien return TRUE; 398033965Sjdp} 398133965Sjdp 398233965Sjdp/* Demangle a qualified name, such as "Q25Outer5Inner" which is the 398333965Sjdp mangled form of "Outer::Inner". */ 398433965Sjdp 3985130561Sobrienstatic bfd_boolean 3986130561Sobrienstab_demangle_qualified (struct stab_demangle_info *minfo, const char **pp, 3987130561Sobrien debug_type *ptype) 398833965Sjdp{ 398933965Sjdp const char *orig; 399033965Sjdp const char *p; 399133965Sjdp unsigned int qualifiers; 399233965Sjdp debug_type context; 399333965Sjdp 399433965Sjdp orig = *pp; 399533965Sjdp 399633965Sjdp switch ((*pp)[1]) 399733965Sjdp { 399833965Sjdp case '_': 399933965Sjdp /* GNU mangled name with more than 9 classes. The count is 400033965Sjdp preceded by an underscore (to distinguish it from the <= 9 400133965Sjdp case) and followed by an underscore. */ 400233965Sjdp p = *pp + 2; 400389857Sobrien if (! ISDIGIT (*p) || *p == '0') 400433965Sjdp { 400533965Sjdp stab_bad_demangle (orig); 4006130561Sobrien return FALSE; 400733965Sjdp } 400833965Sjdp qualifiers = atoi (p); 400989857Sobrien while (ISDIGIT (*p)) 401033965Sjdp ++p; 401133965Sjdp if (*p != '_') 401233965Sjdp { 401333965Sjdp stab_bad_demangle (orig); 4014130561Sobrien return FALSE; 401533965Sjdp } 401633965Sjdp *pp = p + 1; 401733965Sjdp break; 401833965Sjdp 401933965Sjdp case '1': case '2': case '3': case '4': case '5': 402033965Sjdp case '6': case '7': case '8': case '9': 402133965Sjdp qualifiers = (*pp)[1] - '0'; 402233965Sjdp /* Skip an optional underscore after the count. */ 402333965Sjdp if ((*pp)[2] == '_') 402433965Sjdp ++*pp; 402533965Sjdp *pp += 2; 402633965Sjdp break; 402733965Sjdp 402833965Sjdp case '0': 402933965Sjdp default: 403033965Sjdp stab_bad_demangle (orig); 4031130561Sobrien return FALSE; 403233965Sjdp } 403333965Sjdp 403433965Sjdp context = DEBUG_TYPE_NULL; 403533965Sjdp 403633965Sjdp /* Pick off the names. */ 403733965Sjdp while (qualifiers-- > 0) 403833965Sjdp { 403933965Sjdp if (**pp == '_') 404033965Sjdp ++*pp; 404133965Sjdp if (**pp == 't') 404233965Sjdp { 404360484Sobrien char *name; 404460484Sobrien 404560484Sobrien if (! stab_demangle_template (minfo, pp, 404660484Sobrien ptype != NULL ? &name : NULL)) 4047130561Sobrien return FALSE; 404860484Sobrien 404960484Sobrien if (ptype != NULL) 405060484Sobrien { 405160484Sobrien context = stab_find_tagged_type (minfo->dhandle, minfo->info, 405260484Sobrien name, strlen (name), 405360484Sobrien DEBUG_KIND_CLASS); 405460484Sobrien free (name); 405560484Sobrien if (context == DEBUG_TYPE_NULL) 4056130561Sobrien return FALSE; 405760484Sobrien } 405833965Sjdp } 405933965Sjdp else 406033965Sjdp { 406133965Sjdp unsigned int len; 406233965Sjdp 406333965Sjdp len = stab_demangle_count (pp); 406433965Sjdp if (strlen (*pp) < len) 406533965Sjdp { 406633965Sjdp stab_bad_demangle (orig); 4067130561Sobrien return FALSE; 406833965Sjdp } 406933965Sjdp 407033965Sjdp if (ptype != NULL) 407133965Sjdp { 407233965Sjdp const debug_field *fields; 407333965Sjdp 407433965Sjdp fields = NULL; 407533965Sjdp if (context != DEBUG_TYPE_NULL) 407633965Sjdp fields = debug_get_fields (minfo->dhandle, context); 407733965Sjdp 407833965Sjdp context = DEBUG_TYPE_NULL; 407933965Sjdp 408033965Sjdp if (fields != NULL) 408133965Sjdp { 408233965Sjdp char *name; 408333965Sjdp 408433965Sjdp /* Try to find the type by looking through the 408533965Sjdp fields of context until we find a field with the 408633965Sjdp same type. This ought to work for a class 408733965Sjdp defined within a class, but it won't work for, 408833965Sjdp e.g., an enum defined within a class. stabs does 408933965Sjdp not give us enough information to figure out the 409033965Sjdp latter case. */ 409133965Sjdp 409233965Sjdp name = savestring (*pp, len); 409333965Sjdp 409433965Sjdp for (; *fields != DEBUG_FIELD_NULL; fields++) 409533965Sjdp { 409633965Sjdp debug_type ft; 409733965Sjdp const char *dn; 409833965Sjdp 409933965Sjdp ft = debug_get_field_type (minfo->dhandle, *fields); 410033965Sjdp if (ft == NULL) 4101130561Sobrien return FALSE; 410233965Sjdp dn = debug_get_type_name (minfo->dhandle, ft); 410333965Sjdp if (dn != NULL && strcmp (dn, name) == 0) 410433965Sjdp { 410533965Sjdp context = ft; 410633965Sjdp break; 410733965Sjdp } 410833965Sjdp } 410933965Sjdp 411033965Sjdp free (name); 411133965Sjdp } 411233965Sjdp 411333965Sjdp if (context == DEBUG_TYPE_NULL) 411433965Sjdp { 411560484Sobrien /* We have to fall back on finding the type by name. 411633965Sjdp If there are more types to come, then this must 411733965Sjdp be a class. Otherwise, it could be anything. */ 411833965Sjdp 411933965Sjdp if (qualifiers == 0) 412033965Sjdp { 412133965Sjdp char *name; 412233965Sjdp 412333965Sjdp name = savestring (*pp, len); 412433965Sjdp context = debug_find_named_type (minfo->dhandle, 412533965Sjdp name); 412633965Sjdp free (name); 412733965Sjdp } 412833965Sjdp 412933965Sjdp if (context == DEBUG_TYPE_NULL) 413033965Sjdp { 413133965Sjdp context = stab_find_tagged_type (minfo->dhandle, 413233965Sjdp minfo->info, 413333965Sjdp *pp, len, 413433965Sjdp (qualifiers == 0 413533965Sjdp ? DEBUG_KIND_ILLEGAL 413633965Sjdp : DEBUG_KIND_CLASS)); 413733965Sjdp if (context == DEBUG_TYPE_NULL) 4138130561Sobrien return FALSE; 413933965Sjdp } 414033965Sjdp } 414133965Sjdp } 414233965Sjdp 414333965Sjdp *pp += len; 414433965Sjdp } 414533965Sjdp } 414633965Sjdp 414733965Sjdp if (ptype != NULL) 414833965Sjdp *ptype = context; 414933965Sjdp 4150130561Sobrien return TRUE; 415133965Sjdp} 415233965Sjdp 415360484Sobrien/* Demangle a template. If PNAME is not NULL, this sets *PNAME to a 415460484Sobrien string representation of the template. */ 415533965Sjdp 4156130561Sobrienstatic bfd_boolean 4157130561Sobrienstab_demangle_template (struct stab_demangle_info *minfo, const char **pp, 4158130561Sobrien char **pname) 415933965Sjdp{ 416033965Sjdp const char *orig; 416133965Sjdp unsigned int r, i; 416233965Sjdp 416333965Sjdp orig = *pp; 416433965Sjdp 416533965Sjdp ++*pp; 416633965Sjdp 416733965Sjdp /* Skip the template name. */ 416833965Sjdp r = stab_demangle_count (pp); 416933965Sjdp if (r == 0 || strlen (*pp) < r) 417033965Sjdp { 417133965Sjdp stab_bad_demangle (orig); 4172130561Sobrien return FALSE; 417333965Sjdp } 417433965Sjdp *pp += r; 417533965Sjdp 417633965Sjdp /* Get the size of the parameter list. */ 417733965Sjdp if (stab_demangle_get_count (pp, &r) == 0) 417833965Sjdp { 417933965Sjdp stab_bad_demangle (orig); 4180130561Sobrien return FALSE; 418133965Sjdp } 418233965Sjdp 418333965Sjdp for (i = 0; i < r; i++) 418433965Sjdp { 418533965Sjdp if (**pp == 'Z') 418633965Sjdp { 418733965Sjdp /* This is a type parameter. */ 418833965Sjdp ++*pp; 418933965Sjdp if (! stab_demangle_type (minfo, pp, (debug_type *) NULL)) 4190130561Sobrien return FALSE; 419133965Sjdp } 419233965Sjdp else 419333965Sjdp { 419433965Sjdp const char *old_p; 4195130561Sobrien bfd_boolean pointerp, realp, integralp, charp, boolp; 4196130561Sobrien bfd_boolean done; 419733965Sjdp 419833965Sjdp old_p = *pp; 4199130561Sobrien pointerp = FALSE; 4200130561Sobrien realp = FALSE; 4201130561Sobrien integralp = FALSE; 4202130561Sobrien charp = FALSE; 4203130561Sobrien boolp = FALSE; 4204130561Sobrien done = FALSE; 420533965Sjdp 420633965Sjdp /* This is a value parameter. */ 420733965Sjdp 420833965Sjdp if (! stab_demangle_type (minfo, pp, (debug_type *) NULL)) 4209130561Sobrien return FALSE; 421033965Sjdp 421133965Sjdp while (*old_p != '\0' && ! done) 421233965Sjdp { 421333965Sjdp switch (*old_p) 421433965Sjdp { 421533965Sjdp case 'P': 421633965Sjdp case 'p': 421733965Sjdp case 'R': 4218130561Sobrien pointerp = TRUE; 4219130561Sobrien done = TRUE; 422033965Sjdp break; 422133965Sjdp case 'C': /* Const. */ 422233965Sjdp case 'S': /* Signed. */ 422333965Sjdp case 'U': /* Unsigned. */ 422433965Sjdp case 'V': /* Volatile. */ 422533965Sjdp case 'F': /* Function. */ 422633965Sjdp case 'M': /* Member function. */ 422733965Sjdp case 'O': /* ??? */ 422833965Sjdp ++old_p; 422933965Sjdp break; 423033965Sjdp case 'Q': /* Qualified name. */ 4231130561Sobrien integralp = TRUE; 4232130561Sobrien done = TRUE; 423333965Sjdp break; 423433965Sjdp case 'T': /* Remembered type. */ 423533965Sjdp abort (); 423633965Sjdp case 'v': /* Void. */ 423733965Sjdp abort (); 423833965Sjdp case 'x': /* Long long. */ 423933965Sjdp case 'l': /* Long. */ 424033965Sjdp case 'i': /* Int. */ 424133965Sjdp case 's': /* Short. */ 424233965Sjdp case 'w': /* Wchar_t. */ 4243130561Sobrien integralp = TRUE; 4244130561Sobrien done = TRUE; 424533965Sjdp break; 424633965Sjdp case 'b': /* Bool. */ 4247130561Sobrien boolp = TRUE; 4248130561Sobrien done = TRUE; 424933965Sjdp break; 425033965Sjdp case 'c': /* Char. */ 4251130561Sobrien charp = TRUE; 4252130561Sobrien done = TRUE; 425333965Sjdp break; 425433965Sjdp case 'r': /* Long double. */ 425533965Sjdp case 'd': /* Double. */ 425633965Sjdp case 'f': /* Float. */ 4257130561Sobrien realp = TRUE; 4258130561Sobrien done = TRUE; 425933965Sjdp break; 426033965Sjdp default: 426133965Sjdp /* Assume it's a user defined integral type. */ 4262130561Sobrien integralp = TRUE; 4263130561Sobrien done = TRUE; 426433965Sjdp break; 426533965Sjdp } 426633965Sjdp } 426733965Sjdp 426833965Sjdp if (integralp) 426933965Sjdp { 427033965Sjdp if (**pp == 'm') 427133965Sjdp ++*pp; 427289857Sobrien while (ISDIGIT (**pp)) 427333965Sjdp ++*pp; 427433965Sjdp } 427533965Sjdp else if (charp) 427633965Sjdp { 427733965Sjdp unsigned int val; 427833965Sjdp 427933965Sjdp if (**pp == 'm') 428033965Sjdp ++*pp; 428133965Sjdp val = stab_demangle_count (pp); 428233965Sjdp if (val == 0) 428333965Sjdp { 428433965Sjdp stab_bad_demangle (orig); 4285130561Sobrien return FALSE; 428633965Sjdp } 428733965Sjdp } 428833965Sjdp else if (boolp) 428933965Sjdp { 429033965Sjdp unsigned int val; 429133965Sjdp 429233965Sjdp val = stab_demangle_count (pp); 429333965Sjdp if (val != 0 && val != 1) 429433965Sjdp { 429533965Sjdp stab_bad_demangle (orig); 4296130561Sobrien return FALSE; 429733965Sjdp } 429833965Sjdp } 429933965Sjdp else if (realp) 430033965Sjdp { 430133965Sjdp if (**pp == 'm') 430233965Sjdp ++*pp; 430389857Sobrien while (ISDIGIT (**pp)) 430433965Sjdp ++*pp; 430533965Sjdp if (**pp == '.') 430633965Sjdp { 430733965Sjdp ++*pp; 430889857Sobrien while (ISDIGIT (**pp)) 430933965Sjdp ++*pp; 431033965Sjdp } 431133965Sjdp if (**pp == 'e') 431233965Sjdp { 431333965Sjdp ++*pp; 431489857Sobrien while (ISDIGIT (**pp)) 431533965Sjdp ++*pp; 431633965Sjdp } 431733965Sjdp } 431833965Sjdp else if (pointerp) 431933965Sjdp { 432033965Sjdp unsigned int len; 432133965Sjdp 4322218822Sdim len = stab_demangle_count (pp); 4323218822Sdim if (len == 0) 432433965Sjdp { 432533965Sjdp stab_bad_demangle (orig); 4326130561Sobrien return FALSE; 432733965Sjdp } 432833965Sjdp *pp += len; 432933965Sjdp } 433033965Sjdp } 433133965Sjdp } 433233965Sjdp 433360484Sobrien /* We can translate this to a string fairly easily by invoking the 433460484Sobrien regular demangling routine. */ 433560484Sobrien if (pname != NULL) 433660484Sobrien { 433789857Sobrien char *s1, *s2, *s3, *s4 = NULL; 433860484Sobrien char *from, *to; 433960484Sobrien 434060484Sobrien s1 = savestring (orig, *pp - orig); 434160484Sobrien 434260484Sobrien s2 = concat ("NoSuchStrinG__", s1, (const char *) NULL); 434360484Sobrien 434460484Sobrien free (s1); 434560484Sobrien 434660484Sobrien s3 = cplus_demangle (s2, DMGL_ANSI); 434760484Sobrien 434860484Sobrien free (s2); 434960484Sobrien 435060484Sobrien if (s3 != NULL) 435160484Sobrien s4 = strstr (s3, "::NoSuchStrinG"); 435260484Sobrien if (s3 == NULL || s4 == NULL) 435360484Sobrien { 435460484Sobrien stab_bad_demangle (orig); 435560484Sobrien if (s3 != NULL) 435660484Sobrien free (s3); 4357130561Sobrien return FALSE; 435860484Sobrien } 435960484Sobrien 436060484Sobrien /* Eliminating all spaces, except those between > characters, 436160484Sobrien makes it more likely that the demangled name will match the 436260484Sobrien name which g++ used as the structure name. */ 436360484Sobrien for (from = to = s3; from != s4; ++from) 436460484Sobrien if (*from != ' ' 436560484Sobrien || (from[1] == '>' && from > s3 && from[-1] == '>')) 436660484Sobrien *to++ = *from; 436760484Sobrien 436860484Sobrien *pname = savestring (s3, to - s3); 436960484Sobrien 437060484Sobrien free (s3); 437160484Sobrien } 437260484Sobrien 4373130561Sobrien return TRUE; 437433965Sjdp} 437533965Sjdp 437633965Sjdp/* Demangle a class name. */ 437733965Sjdp 4378130561Sobrienstatic bfd_boolean 4379130561Sobrienstab_demangle_class (struct stab_demangle_info *minfo ATTRIBUTE_UNUSED, 4380130561Sobrien const char **pp, const char **pstart) 438133965Sjdp{ 438233965Sjdp const char *orig; 438333965Sjdp unsigned int n; 438433965Sjdp 438533965Sjdp orig = *pp; 438633965Sjdp 438733965Sjdp n = stab_demangle_count (pp); 438833965Sjdp if (strlen (*pp) < n) 438933965Sjdp { 439033965Sjdp stab_bad_demangle (orig); 4391130561Sobrien return FALSE; 439233965Sjdp } 439333965Sjdp 439433965Sjdp if (pstart != NULL) 439533965Sjdp *pstart = *pp; 439633965Sjdp 439733965Sjdp *pp += n; 439833965Sjdp 4399130561Sobrien return TRUE; 440033965Sjdp} 440133965Sjdp 440233965Sjdp/* Demangle function arguments. If the pargs argument is not NULL, it 440333965Sjdp is set to a NULL terminated array holding the arguments. */ 440433965Sjdp 4405130561Sobrienstatic bfd_boolean 4406130561Sobrienstab_demangle_args (struct stab_demangle_info *minfo, const char **pp, 4407130561Sobrien debug_type **pargs, bfd_boolean *pvarargs) 440833965Sjdp{ 440933965Sjdp const char *orig; 441033965Sjdp unsigned int alloc, count; 441133965Sjdp 441233965Sjdp orig = *pp; 441333965Sjdp 441433965Sjdp alloc = 10; 441533965Sjdp if (pargs != NULL) 441633965Sjdp { 441733965Sjdp *pargs = (debug_type *) xmalloc (alloc * sizeof **pargs); 4418130561Sobrien *pvarargs = FALSE; 441933965Sjdp } 442033965Sjdp count = 0; 442133965Sjdp 442233965Sjdp while (**pp != '_' && **pp != '\0' && **pp != 'e') 442333965Sjdp { 442433965Sjdp if (**pp == 'N' || **pp == 'T') 442533965Sjdp { 442633965Sjdp char temptype; 442733965Sjdp unsigned int r, t; 442833965Sjdp 442933965Sjdp temptype = **pp; 443033965Sjdp ++*pp; 443133965Sjdp 443233965Sjdp if (temptype == 'T') 443333965Sjdp r = 1; 443433965Sjdp else 443533965Sjdp { 443633965Sjdp if (! stab_demangle_get_count (pp, &r)) 443733965Sjdp { 443833965Sjdp stab_bad_demangle (orig); 4439130561Sobrien return FALSE; 444033965Sjdp } 444133965Sjdp } 444233965Sjdp 444333965Sjdp if (! stab_demangle_get_count (pp, &t)) 444433965Sjdp { 444533965Sjdp stab_bad_demangle (orig); 4446130561Sobrien return FALSE; 444733965Sjdp } 444833965Sjdp 444933965Sjdp if (t >= minfo->typestring_count) 445033965Sjdp { 445133965Sjdp stab_bad_demangle (orig); 4452130561Sobrien return FALSE; 445333965Sjdp } 445433965Sjdp while (r-- > 0) 445533965Sjdp { 445633965Sjdp const char *tem; 445733965Sjdp 445833965Sjdp tem = minfo->typestrings[t].typestring; 445933965Sjdp if (! stab_demangle_arg (minfo, &tem, pargs, &count, &alloc)) 4460130561Sobrien return FALSE; 446133965Sjdp } 446233965Sjdp } 446333965Sjdp else 446433965Sjdp { 446533965Sjdp if (! stab_demangle_arg (minfo, pp, pargs, &count, &alloc)) 4466130561Sobrien return FALSE; 446733965Sjdp } 446833965Sjdp } 446933965Sjdp 447033965Sjdp if (pargs != NULL) 447133965Sjdp (*pargs)[count] = DEBUG_TYPE_NULL; 447233965Sjdp 447333965Sjdp if (**pp == 'e') 447433965Sjdp { 447533965Sjdp if (pargs != NULL) 4476130561Sobrien *pvarargs = TRUE; 447733965Sjdp ++*pp; 447833965Sjdp } 447933965Sjdp 4480130561Sobrien return TRUE; 448133965Sjdp} 448233965Sjdp 448333965Sjdp/* Demangle a single argument. */ 448433965Sjdp 4485130561Sobrienstatic bfd_boolean 4486130561Sobrienstab_demangle_arg (struct stab_demangle_info *minfo, const char **pp, 4487130561Sobrien debug_type **pargs, unsigned int *pcount, 4488130561Sobrien unsigned int *palloc) 448933965Sjdp{ 449033965Sjdp const char *start; 449133965Sjdp debug_type type; 449233965Sjdp 449333965Sjdp start = *pp; 449433965Sjdp if (! stab_demangle_type (minfo, pp, 449533965Sjdp pargs == NULL ? (debug_type *) NULL : &type) 449633965Sjdp || ! stab_demangle_remember_type (minfo, start, *pp - start)) 4497130561Sobrien return FALSE; 449833965Sjdp 449933965Sjdp if (pargs != NULL) 450033965Sjdp { 450133965Sjdp if (type == DEBUG_TYPE_NULL) 4502130561Sobrien return FALSE; 450333965Sjdp 450433965Sjdp if (*pcount + 1 >= *palloc) 450533965Sjdp { 450633965Sjdp *palloc += 10; 450733965Sjdp *pargs = ((debug_type *) 450833965Sjdp xrealloc (*pargs, *palloc * sizeof **pargs)); 450933965Sjdp } 451033965Sjdp (*pargs)[*pcount] = type; 451133965Sjdp ++*pcount; 451233965Sjdp } 451333965Sjdp 4514130561Sobrien return TRUE; 451533965Sjdp} 451633965Sjdp 451733965Sjdp/* Demangle a type. If the ptype argument is not NULL, *ptype is set 451833965Sjdp to the newly allocated type. */ 451933965Sjdp 4520130561Sobrienstatic bfd_boolean 4521130561Sobrienstab_demangle_type (struct stab_demangle_info *minfo, const char **pp, 4522130561Sobrien debug_type *ptype) 452333965Sjdp{ 452433965Sjdp const char *orig; 452533965Sjdp 452633965Sjdp orig = *pp; 452733965Sjdp 452833965Sjdp switch (**pp) 452933965Sjdp { 453033965Sjdp case 'P': 453133965Sjdp case 'p': 453233965Sjdp /* A pointer type. */ 453333965Sjdp ++*pp; 453433965Sjdp if (! stab_demangle_type (minfo, pp, ptype)) 4535130561Sobrien return FALSE; 453633965Sjdp if (ptype != NULL) 453733965Sjdp *ptype = debug_make_pointer_type (minfo->dhandle, *ptype); 453833965Sjdp break; 453933965Sjdp 454033965Sjdp case 'R': 454133965Sjdp /* A reference type. */ 454233965Sjdp ++*pp; 454333965Sjdp if (! stab_demangle_type (minfo, pp, ptype)) 4544130561Sobrien return FALSE; 454533965Sjdp if (ptype != NULL) 454633965Sjdp *ptype = debug_make_reference_type (minfo->dhandle, *ptype); 454733965Sjdp break; 454833965Sjdp 454933965Sjdp case 'A': 455033965Sjdp /* An array. */ 455133965Sjdp { 455233965Sjdp unsigned long high; 455333965Sjdp 455433965Sjdp ++*pp; 455533965Sjdp high = 0; 455633965Sjdp while (**pp != '\0' && **pp != '_') 455733965Sjdp { 455889857Sobrien if (! ISDIGIT (**pp)) 455933965Sjdp { 456033965Sjdp stab_bad_demangle (orig); 4561130561Sobrien return FALSE; 456233965Sjdp } 456333965Sjdp high *= 10; 456433965Sjdp high += **pp - '0'; 456533965Sjdp ++*pp; 456633965Sjdp } 456733965Sjdp if (**pp != '_') 456833965Sjdp { 456933965Sjdp stab_bad_demangle (orig); 4570130561Sobrien return FALSE; 457133965Sjdp } 457233965Sjdp ++*pp; 457333965Sjdp 457433965Sjdp if (! stab_demangle_type (minfo, pp, ptype)) 4575130561Sobrien return FALSE; 457633965Sjdp if (ptype != NULL) 457733965Sjdp { 457833965Sjdp debug_type int_type; 457933965Sjdp 458033965Sjdp int_type = debug_find_named_type (minfo->dhandle, "int"); 458133965Sjdp if (int_type == NULL) 4582130561Sobrien int_type = debug_make_int_type (minfo->dhandle, 4, FALSE); 458333965Sjdp *ptype = debug_make_array_type (minfo->dhandle, *ptype, int_type, 4584130561Sobrien 0, high, FALSE); 458533965Sjdp } 458633965Sjdp } 458733965Sjdp break; 458833965Sjdp 458933965Sjdp case 'T': 459033965Sjdp /* A back reference to a remembered type. */ 459133965Sjdp { 459233965Sjdp unsigned int i; 459333965Sjdp const char *p; 459433965Sjdp 459533965Sjdp ++*pp; 459633965Sjdp if (! stab_demangle_get_count (pp, &i)) 459733965Sjdp { 459833965Sjdp stab_bad_demangle (orig); 4599130561Sobrien return FALSE; 460033965Sjdp } 460133965Sjdp if (i >= minfo->typestring_count) 460233965Sjdp { 460333965Sjdp stab_bad_demangle (orig); 4604130561Sobrien return FALSE; 460533965Sjdp } 460633965Sjdp p = minfo->typestrings[i].typestring; 460733965Sjdp if (! stab_demangle_type (minfo, &p, ptype)) 4608130561Sobrien return FALSE; 460933965Sjdp } 461033965Sjdp break; 461133965Sjdp 461233965Sjdp case 'F': 461333965Sjdp /* A function. */ 461433965Sjdp { 461533965Sjdp debug_type *args; 4616130561Sobrien bfd_boolean varargs; 461733965Sjdp 461833965Sjdp ++*pp; 461933965Sjdp if (! stab_demangle_args (minfo, pp, 462033965Sjdp (ptype == NULL 462133965Sjdp ? (debug_type **) NULL 462233965Sjdp : &args), 462333965Sjdp (ptype == NULL 4624130561Sobrien ? (bfd_boolean *) NULL 462533965Sjdp : &varargs))) 4626130561Sobrien return FALSE; 462733965Sjdp if (**pp != '_') 462833965Sjdp { 462933965Sjdp /* cplus_demangle will accept a function without a return 463033965Sjdp type, but I don't know when that will happen, or what 463133965Sjdp to do if it does. */ 463233965Sjdp stab_bad_demangle (orig); 4633130561Sobrien return FALSE; 463433965Sjdp } 463533965Sjdp ++*pp; 463633965Sjdp if (! stab_demangle_type (minfo, pp, ptype)) 4637130561Sobrien return FALSE; 463833965Sjdp if (ptype != NULL) 463933965Sjdp *ptype = debug_make_function_type (minfo->dhandle, *ptype, args, 464033965Sjdp varargs); 464133965Sjdp 464233965Sjdp } 464333965Sjdp break; 464433965Sjdp 464533965Sjdp case 'M': 464633965Sjdp case 'O': 464733965Sjdp { 4648130561Sobrien bfd_boolean memberp, constp, volatilep; 464960484Sobrien debug_type class_type = DEBUG_TYPE_NULL; 465033965Sjdp debug_type *args; 4651130561Sobrien bfd_boolean varargs; 465233965Sjdp unsigned int n; 465333965Sjdp const char *name; 465433965Sjdp 465533965Sjdp memberp = **pp == 'M'; 4656130561Sobrien constp = FALSE; 4657130561Sobrien volatilep = FALSE; 465833965Sjdp args = NULL; 4659130561Sobrien varargs = FALSE; 466033965Sjdp 466133965Sjdp ++*pp; 466289857Sobrien if (ISDIGIT (**pp)) 466333965Sjdp { 466460484Sobrien n = stab_demangle_count (pp); 466560484Sobrien if (strlen (*pp) < n) 466660484Sobrien { 466760484Sobrien stab_bad_demangle (orig); 4668130561Sobrien return FALSE; 466960484Sobrien } 467060484Sobrien name = *pp; 467160484Sobrien *pp += n; 467260484Sobrien 467360484Sobrien if (ptype != NULL) 467460484Sobrien { 467560484Sobrien class_type = stab_find_tagged_type (minfo->dhandle, 467660484Sobrien minfo->info, 467760484Sobrien name, (int) n, 467860484Sobrien DEBUG_KIND_CLASS); 467960484Sobrien if (class_type == DEBUG_TYPE_NULL) 4680130561Sobrien return FALSE; 468160484Sobrien } 468233965Sjdp } 468360484Sobrien else if (**pp == 'Q') 468433965Sjdp { 468560484Sobrien if (! stab_demangle_qualified (minfo, pp, 468660484Sobrien (ptype == NULL 468760484Sobrien ? (debug_type *) NULL 468860484Sobrien : &class_type))) 4689130561Sobrien return FALSE; 469060484Sobrien } 469160484Sobrien else 469260484Sobrien { 469333965Sjdp stab_bad_demangle (orig); 4694130561Sobrien return FALSE; 469533965Sjdp } 469633965Sjdp 469733965Sjdp if (memberp) 469833965Sjdp { 469933965Sjdp if (**pp == 'C') 470033965Sjdp { 4701130561Sobrien constp = TRUE; 470233965Sjdp ++*pp; 470333965Sjdp } 470433965Sjdp else if (**pp == 'V') 470533965Sjdp { 4706130561Sobrien volatilep = TRUE; 470733965Sjdp ++*pp; 470833965Sjdp } 470933965Sjdp if (**pp != 'F') 471033965Sjdp { 471133965Sjdp stab_bad_demangle (orig); 4712130561Sobrien return FALSE; 471333965Sjdp } 471433965Sjdp ++*pp; 471533965Sjdp if (! stab_demangle_args (minfo, pp, 471633965Sjdp (ptype == NULL 471733965Sjdp ? (debug_type **) NULL 471833965Sjdp : &args), 471933965Sjdp (ptype == NULL 4720130561Sobrien ? (bfd_boolean *) NULL 472133965Sjdp : &varargs))) 4722130561Sobrien return FALSE; 472333965Sjdp } 472433965Sjdp 472533965Sjdp if (**pp != '_') 472633965Sjdp { 472733965Sjdp stab_bad_demangle (orig); 4728130561Sobrien return FALSE; 472933965Sjdp } 473033965Sjdp ++*pp; 473133965Sjdp 473233965Sjdp if (! stab_demangle_type (minfo, pp, ptype)) 4733130561Sobrien return FALSE; 473433965Sjdp 473533965Sjdp if (ptype != NULL) 473633965Sjdp { 473733965Sjdp if (! memberp) 473833965Sjdp *ptype = debug_make_offset_type (minfo->dhandle, class_type, 473933965Sjdp *ptype); 474033965Sjdp else 474133965Sjdp { 474233965Sjdp /* FIXME: We have no way to record constp or 474333965Sjdp volatilep. */ 474433965Sjdp *ptype = debug_make_method_type (minfo->dhandle, *ptype, 474533965Sjdp class_type, args, varargs); 474633965Sjdp } 474733965Sjdp } 474833965Sjdp } 474933965Sjdp break; 475033965Sjdp 475133965Sjdp case 'G': 475233965Sjdp ++*pp; 475333965Sjdp if (! stab_demangle_type (minfo, pp, ptype)) 4754130561Sobrien return FALSE; 475533965Sjdp break; 475633965Sjdp 475733965Sjdp case 'C': 475833965Sjdp ++*pp; 475933965Sjdp if (! stab_demangle_type (minfo, pp, ptype)) 4760130561Sobrien return FALSE; 476133965Sjdp if (ptype != NULL) 476233965Sjdp *ptype = debug_make_const_type (minfo->dhandle, *ptype); 476333965Sjdp break; 476433965Sjdp 476533965Sjdp case 'Q': 476633965Sjdp { 476733965Sjdp const char *hold; 476833965Sjdp 476933965Sjdp hold = *pp; 477033965Sjdp if (! stab_demangle_qualified (minfo, pp, ptype)) 4771130561Sobrien return FALSE; 477233965Sjdp } 477333965Sjdp break; 477433965Sjdp 477533965Sjdp default: 477633965Sjdp if (! stab_demangle_fund_type (minfo, pp, ptype)) 4777130561Sobrien return FALSE; 477833965Sjdp break; 477933965Sjdp } 478033965Sjdp 4781130561Sobrien return TRUE; 478233965Sjdp} 478333965Sjdp 478433965Sjdp/* Demangle a fundamental type. If the ptype argument is not NULL, 478533965Sjdp *ptype is set to the newly allocated type. */ 478633965Sjdp 4787130561Sobrienstatic bfd_boolean 4788130561Sobrienstab_demangle_fund_type (struct stab_demangle_info *minfo, const char **pp, 4789130561Sobrien debug_type *ptype) 479033965Sjdp{ 479133965Sjdp const char *orig; 4792130561Sobrien bfd_boolean constp, volatilep, unsignedp, signedp; 4793130561Sobrien bfd_boolean done; 479433965Sjdp 479533965Sjdp orig = *pp; 479633965Sjdp 4797130561Sobrien constp = FALSE; 4798130561Sobrien volatilep = FALSE; 4799130561Sobrien unsignedp = FALSE; 4800130561Sobrien signedp = FALSE; 480133965Sjdp 4802130561Sobrien done = FALSE; 480333965Sjdp while (! done) 480433965Sjdp { 480533965Sjdp switch (**pp) 480633965Sjdp { 480733965Sjdp case 'C': 4808130561Sobrien constp = TRUE; 480933965Sjdp ++*pp; 481033965Sjdp break; 481133965Sjdp 481233965Sjdp case 'U': 4813130561Sobrien unsignedp = TRUE; 481433965Sjdp ++*pp; 481533965Sjdp break; 481633965Sjdp 481733965Sjdp case 'S': 4818130561Sobrien signedp = TRUE; 481933965Sjdp ++*pp; 482033965Sjdp break; 482133965Sjdp 482233965Sjdp case 'V': 4823130561Sobrien volatilep = TRUE; 482433965Sjdp ++*pp; 482533965Sjdp break; 482633965Sjdp 482733965Sjdp default: 4828130561Sobrien done = TRUE; 482933965Sjdp break; 483033965Sjdp } 483133965Sjdp } 483233965Sjdp 483333965Sjdp switch (**pp) 483433965Sjdp { 483533965Sjdp case '\0': 483633965Sjdp case '_': 483733965Sjdp /* cplus_demangle permits this, but I don't know what it means. */ 483833965Sjdp stab_bad_demangle (orig); 483933965Sjdp break; 484033965Sjdp 484133965Sjdp case 'v': /* void */ 484233965Sjdp if (ptype != NULL) 484333965Sjdp { 484433965Sjdp *ptype = debug_find_named_type (minfo->dhandle, "void"); 484533965Sjdp if (*ptype == DEBUG_TYPE_NULL) 484633965Sjdp *ptype = debug_make_void_type (minfo->dhandle); 484733965Sjdp } 484833965Sjdp ++*pp; 484933965Sjdp break; 485033965Sjdp 485133965Sjdp case 'x': /* long long */ 485233965Sjdp if (ptype != NULL) 485333965Sjdp { 485433965Sjdp *ptype = debug_find_named_type (minfo->dhandle, 485533965Sjdp (unsignedp 485633965Sjdp ? "long long unsigned int" 485733965Sjdp : "long long int")); 485833965Sjdp if (*ptype == DEBUG_TYPE_NULL) 485933965Sjdp *ptype = debug_make_int_type (minfo->dhandle, 8, unsignedp); 486033965Sjdp } 486133965Sjdp ++*pp; 486233965Sjdp break; 486333965Sjdp 486433965Sjdp case 'l': /* long */ 486533965Sjdp if (ptype != NULL) 486633965Sjdp { 486733965Sjdp *ptype = debug_find_named_type (minfo->dhandle, 486833965Sjdp (unsignedp 486933965Sjdp ? "long unsigned int" 487033965Sjdp : "long int")); 487133965Sjdp if (*ptype == DEBUG_TYPE_NULL) 487233965Sjdp *ptype = debug_make_int_type (minfo->dhandle, 4, unsignedp); 487333965Sjdp } 487433965Sjdp ++*pp; 487533965Sjdp break; 487633965Sjdp 487733965Sjdp case 'i': /* int */ 487833965Sjdp if (ptype != NULL) 487933965Sjdp { 488033965Sjdp *ptype = debug_find_named_type (minfo->dhandle, 488133965Sjdp (unsignedp 488233965Sjdp ? "unsigned int" 488333965Sjdp : "int")); 488433965Sjdp if (*ptype == DEBUG_TYPE_NULL) 488533965Sjdp *ptype = debug_make_int_type (minfo->dhandle, 4, unsignedp); 488633965Sjdp } 488733965Sjdp ++*pp; 488833965Sjdp break; 488933965Sjdp 489033965Sjdp case 's': /* short */ 489133965Sjdp if (ptype != NULL) 489233965Sjdp { 489333965Sjdp *ptype = debug_find_named_type (minfo->dhandle, 489433965Sjdp (unsignedp 489533965Sjdp ? "short unsigned int" 489633965Sjdp : "short int")); 489733965Sjdp if (*ptype == DEBUG_TYPE_NULL) 489833965Sjdp *ptype = debug_make_int_type (minfo->dhandle, 2, unsignedp); 489933965Sjdp } 490033965Sjdp ++*pp; 490133965Sjdp break; 490233965Sjdp 490333965Sjdp case 'b': /* bool */ 490433965Sjdp if (ptype != NULL) 490533965Sjdp { 490633965Sjdp *ptype = debug_find_named_type (minfo->dhandle, "bool"); 490733965Sjdp if (*ptype == DEBUG_TYPE_NULL) 490833965Sjdp *ptype = debug_make_bool_type (minfo->dhandle, 4); 490933965Sjdp } 491033965Sjdp ++*pp; 491133965Sjdp break; 491233965Sjdp 491333965Sjdp case 'c': /* char */ 491433965Sjdp if (ptype != NULL) 491533965Sjdp { 491633965Sjdp *ptype = debug_find_named_type (minfo->dhandle, 491733965Sjdp (unsignedp 491833965Sjdp ? "unsigned char" 491933965Sjdp : (signedp 492033965Sjdp ? "signed char" 492133965Sjdp : "char"))); 492233965Sjdp if (*ptype == DEBUG_TYPE_NULL) 492333965Sjdp *ptype = debug_make_int_type (minfo->dhandle, 1, unsignedp); 492433965Sjdp } 492533965Sjdp ++*pp; 492633965Sjdp break; 492733965Sjdp 492833965Sjdp case 'w': /* wchar_t */ 492933965Sjdp if (ptype != NULL) 493033965Sjdp { 493133965Sjdp *ptype = debug_find_named_type (minfo->dhandle, "__wchar_t"); 493233965Sjdp if (*ptype == DEBUG_TYPE_NULL) 4933130561Sobrien *ptype = debug_make_int_type (minfo->dhandle, 2, TRUE); 493433965Sjdp } 493533965Sjdp ++*pp; 493633965Sjdp break; 493733965Sjdp 493833965Sjdp case 'r': /* long double */ 493933965Sjdp if (ptype != NULL) 494033965Sjdp { 494133965Sjdp *ptype = debug_find_named_type (minfo->dhandle, "long double"); 494233965Sjdp if (*ptype == DEBUG_TYPE_NULL) 494333965Sjdp *ptype = debug_make_float_type (minfo->dhandle, 8); 494433965Sjdp } 494533965Sjdp ++*pp; 494633965Sjdp break; 494733965Sjdp 494833965Sjdp case 'd': /* double */ 494933965Sjdp if (ptype != NULL) 495033965Sjdp { 495133965Sjdp *ptype = debug_find_named_type (minfo->dhandle, "double"); 495233965Sjdp if (*ptype == DEBUG_TYPE_NULL) 495333965Sjdp *ptype = debug_make_float_type (minfo->dhandle, 8); 495433965Sjdp } 495533965Sjdp ++*pp; 495633965Sjdp break; 495733965Sjdp 495833965Sjdp case 'f': /* float */ 495933965Sjdp if (ptype != NULL) 496033965Sjdp { 496133965Sjdp *ptype = debug_find_named_type (minfo->dhandle, "float"); 496233965Sjdp if (*ptype == DEBUG_TYPE_NULL) 496333965Sjdp *ptype = debug_make_float_type (minfo->dhandle, 4); 496433965Sjdp } 496533965Sjdp ++*pp; 496633965Sjdp break; 496733965Sjdp 496833965Sjdp case 'G': 496933965Sjdp ++*pp; 497089857Sobrien if (! ISDIGIT (**pp)) 497133965Sjdp { 497233965Sjdp stab_bad_demangle (orig); 4973130561Sobrien return FALSE; 497433965Sjdp } 497533965Sjdp /* Fall through. */ 497633965Sjdp case '0': case '1': case '2': case '3': case '4': 497733965Sjdp case '5': case '6': case '7': case '8': case '9': 497833965Sjdp { 497933965Sjdp const char *hold; 498033965Sjdp 498133965Sjdp if (! stab_demangle_class (minfo, pp, &hold)) 4982130561Sobrien return FALSE; 498333965Sjdp if (ptype != NULL) 498433965Sjdp { 498533965Sjdp char *name; 498633965Sjdp 498733965Sjdp name = savestring (hold, *pp - hold); 498833965Sjdp *ptype = debug_find_named_type (minfo->dhandle, name); 498960484Sobrien free (name); 499033965Sjdp if (*ptype == DEBUG_TYPE_NULL) 499133965Sjdp { 499233965Sjdp /* FIXME: It is probably incorrect to assume that 499333965Sjdp undefined types are tagged types. */ 499433965Sjdp *ptype = stab_find_tagged_type (minfo->dhandle, minfo->info, 499533965Sjdp hold, *pp - hold, 499633965Sjdp DEBUG_KIND_ILLEGAL); 499760484Sobrien if (*ptype == DEBUG_TYPE_NULL) 4998130561Sobrien return FALSE; 499933965Sjdp } 500033965Sjdp } 500133965Sjdp } 500233965Sjdp break; 500333965Sjdp 500433965Sjdp case 't': 500560484Sobrien { 500660484Sobrien char *name; 500733965Sjdp 500860484Sobrien if (! stab_demangle_template (minfo, pp, 500960484Sobrien ptype != NULL ? &name : NULL)) 5010130561Sobrien return FALSE; 501160484Sobrien if (ptype != NULL) 501260484Sobrien { 501360484Sobrien *ptype = stab_find_tagged_type (minfo->dhandle, minfo->info, 501460484Sobrien name, strlen (name), 501560484Sobrien DEBUG_KIND_CLASS); 501660484Sobrien free (name); 501760484Sobrien if (*ptype == DEBUG_TYPE_NULL) 5018130561Sobrien return FALSE; 501960484Sobrien } 502060484Sobrien } 502133965Sjdp break; 502233965Sjdp 502333965Sjdp default: 502433965Sjdp stab_bad_demangle (orig); 5025130561Sobrien return FALSE; 502633965Sjdp } 502733965Sjdp 502833965Sjdp if (ptype != NULL) 502933965Sjdp { 503033965Sjdp if (constp) 503133965Sjdp *ptype = debug_make_const_type (minfo->dhandle, *ptype); 503233965Sjdp if (volatilep) 503333965Sjdp *ptype = debug_make_volatile_type (minfo->dhandle, *ptype); 503433965Sjdp } 503533965Sjdp 5036130561Sobrien return TRUE; 503733965Sjdp} 503833965Sjdp 503933965Sjdp/* Remember a type string in a demangled string. */ 504033965Sjdp 5041130561Sobrienstatic bfd_boolean 5042130561Sobrienstab_demangle_remember_type (struct stab_demangle_info *minfo, 5043130561Sobrien const char *p, int len) 504433965Sjdp{ 504533965Sjdp if (minfo->typestring_count >= minfo->typestring_alloc) 504633965Sjdp { 504733965Sjdp minfo->typestring_alloc += 10; 504833965Sjdp minfo->typestrings = ((struct stab_demangle_typestring *) 504933965Sjdp xrealloc (minfo->typestrings, 505033965Sjdp (minfo->typestring_alloc 505133965Sjdp * sizeof *minfo->typestrings))); 505233965Sjdp } 505333965Sjdp 505433965Sjdp minfo->typestrings[minfo->typestring_count].typestring = p; 505533965Sjdp minfo->typestrings[minfo->typestring_count].len = (unsigned int) len; 505633965Sjdp ++minfo->typestring_count; 505733965Sjdp 5058130561Sobrien return TRUE; 505933965Sjdp} 5060130561Sobrien 5061130561Sobrien/* Demangle names encoded using the g++ V3 ABI. The newer versions of 5062130561Sobrien g++ which use this ABI do not encode ordinary method argument types 5063130561Sobrien in a mangled name; they simply output the argument types. However, 5064130561Sobrien for a static method, g++ simply outputs the return type and the 5065130561Sobrien physical name. So in that case we need to demangle the name here. 5066130561Sobrien Here PHYSNAME is the physical name of the function, and we set the 5067130561Sobrien variable pointed at by PVARARGS to indicate whether this function 5068130561Sobrien is varargs. This returns NULL, or a NULL terminated array of 5069130561Sobrien argument types. */ 5070130561Sobrien 5071130561Sobrienstatic debug_type * 5072130561Sobrienstab_demangle_v3_argtypes (void *dhandle, struct stab_handle *info, 5073130561Sobrien const char *physname, bfd_boolean *pvarargs) 5074130561Sobrien{ 5075130561Sobrien struct demangle_component *dc; 5076130561Sobrien void *mem; 5077130561Sobrien debug_type *pargs; 5078130561Sobrien 5079130561Sobrien dc = cplus_demangle_v3_components (physname, DMGL_PARAMS | DMGL_ANSI, &mem); 5080130561Sobrien if (dc == NULL) 5081130561Sobrien { 5082130561Sobrien stab_bad_demangle (physname); 5083130561Sobrien return NULL; 5084130561Sobrien } 5085130561Sobrien 5086130561Sobrien /* We expect to see TYPED_NAME, and the right subtree describes the 5087130561Sobrien function type. */ 5088130561Sobrien if (dc->type != DEMANGLE_COMPONENT_TYPED_NAME 5089130561Sobrien || dc->u.s_binary.right->type != DEMANGLE_COMPONENT_FUNCTION_TYPE) 5090130561Sobrien { 5091130561Sobrien fprintf (stderr, _("Demangled name is not a function\n")); 5092130561Sobrien free (mem); 5093130561Sobrien return NULL; 5094130561Sobrien } 5095130561Sobrien 5096218822Sdim pargs = stab_demangle_v3_arglist (dhandle, info, 5097218822Sdim dc->u.s_binary.right->u.s_binary.right, 5098218822Sdim pvarargs); 5099218822Sdim 5100218822Sdim free (mem); 5101218822Sdim 5102218822Sdim return pargs; 5103218822Sdim} 5104218822Sdim 5105218822Sdim/* Demangle an argument list in a struct demangle_component tree. 5106218822Sdim Returns a DEBUG_TYPE_NULL terminated array of argument types, and 5107218822Sdim sets *PVARARGS to indicate whether this is a varargs function. */ 5108218822Sdim 5109218822Sdimstatic debug_type * 5110218822Sdimstab_demangle_v3_arglist (void *dhandle, struct stab_handle *info, 5111218822Sdim struct demangle_component *arglist, 5112218822Sdim bfd_boolean *pvarargs) 5113218822Sdim{ 5114218822Sdim struct demangle_component *dc; 5115218822Sdim unsigned int alloc, count; 5116218822Sdim debug_type *pargs; 5117218822Sdim 5118130561Sobrien alloc = 10; 5119130561Sobrien pargs = (debug_type *) xmalloc (alloc * sizeof *pargs); 5120130561Sobrien *pvarargs = FALSE; 5121130561Sobrien 5122130561Sobrien count = 0; 5123130561Sobrien 5124218822Sdim for (dc = arglist; 5125130561Sobrien dc != NULL; 5126130561Sobrien dc = dc->u.s_binary.right) 5127130561Sobrien { 5128130561Sobrien debug_type arg; 5129130561Sobrien bfd_boolean varargs; 5130130561Sobrien 5131130561Sobrien if (dc->type != DEMANGLE_COMPONENT_ARGLIST) 5132130561Sobrien { 5133218822Sdim fprintf (stderr, _("Unexpected type in v3 arglist demangling\n")); 5134218822Sdim free (pargs); 5135130561Sobrien return NULL; 5136130561Sobrien } 5137130561Sobrien 5138130561Sobrien arg = stab_demangle_v3_arg (dhandle, info, dc->u.s_binary.left, 5139130561Sobrien NULL, &varargs); 5140130561Sobrien if (arg == NULL) 5141130561Sobrien { 5142130561Sobrien if (varargs) 5143130561Sobrien { 5144130561Sobrien *pvarargs = TRUE; 5145130561Sobrien continue; 5146130561Sobrien } 5147218822Sdim free (pargs); 5148130561Sobrien return NULL; 5149130561Sobrien } 5150130561Sobrien 5151130561Sobrien if (count + 1 >= alloc) 5152130561Sobrien { 5153130561Sobrien alloc += 10; 5154130561Sobrien pargs = (debug_type *) xrealloc (pargs, alloc * sizeof *pargs); 5155130561Sobrien } 5156130561Sobrien 5157130561Sobrien pargs[count] = arg; 5158130561Sobrien ++count; 5159130561Sobrien } 5160130561Sobrien 5161130561Sobrien pargs[count] = DEBUG_TYPE_NULL; 5162130561Sobrien 5163130561Sobrien return pargs; 5164130561Sobrien} 5165130561Sobrien 5166130561Sobrien/* Convert a struct demangle_component tree describing an argument 5167130561Sobrien type into a debug_type. */ 5168130561Sobrien 5169130561Sobrienstatic debug_type 5170130561Sobrienstab_demangle_v3_arg (void *dhandle, struct stab_handle *info, 5171130561Sobrien struct demangle_component *dc, debug_type context, 5172130561Sobrien bfd_boolean *pvarargs) 5173130561Sobrien{ 5174130561Sobrien debug_type dt; 5175130561Sobrien 5176130561Sobrien if (pvarargs != NULL) 5177130561Sobrien *pvarargs = FALSE; 5178130561Sobrien 5179130561Sobrien switch (dc->type) 5180130561Sobrien { 5181130561Sobrien /* FIXME: These are demangle component types which we probably 5182130561Sobrien need to handle one way or another. */ 5183130561Sobrien case DEMANGLE_COMPONENT_LOCAL_NAME: 5184130561Sobrien case DEMANGLE_COMPONENT_TYPED_NAME: 5185130561Sobrien case DEMANGLE_COMPONENT_TEMPLATE_PARAM: 5186130561Sobrien case DEMANGLE_COMPONENT_CTOR: 5187130561Sobrien case DEMANGLE_COMPONENT_DTOR: 5188130561Sobrien case DEMANGLE_COMPONENT_JAVA_CLASS: 5189130561Sobrien case DEMANGLE_COMPONENT_RESTRICT_THIS: 5190130561Sobrien case DEMANGLE_COMPONENT_VOLATILE_THIS: 5191130561Sobrien case DEMANGLE_COMPONENT_CONST_THIS: 5192130561Sobrien case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL: 5193130561Sobrien case DEMANGLE_COMPONENT_COMPLEX: 5194130561Sobrien case DEMANGLE_COMPONENT_IMAGINARY: 5195130561Sobrien case DEMANGLE_COMPONENT_VENDOR_TYPE: 5196130561Sobrien case DEMANGLE_COMPONENT_ARRAY_TYPE: 5197130561Sobrien case DEMANGLE_COMPONENT_PTRMEM_TYPE: 5198130561Sobrien case DEMANGLE_COMPONENT_ARGLIST: 5199130561Sobrien default: 5200218822Sdim fprintf (stderr, _("Unrecognized demangle component %d\n"), 5201218822Sdim (int) dc->type); 5202130561Sobrien return NULL; 5203130561Sobrien 5204130561Sobrien case DEMANGLE_COMPONENT_NAME: 5205130561Sobrien if (context != NULL) 5206130561Sobrien { 5207130561Sobrien const debug_field *fields; 5208130561Sobrien 5209130561Sobrien fields = debug_get_fields (dhandle, context); 5210130561Sobrien if (fields != NULL) 5211130561Sobrien { 5212130561Sobrien /* Try to find this type by looking through the context 5213130561Sobrien class. */ 5214130561Sobrien for (; *fields != DEBUG_FIELD_NULL; fields++) 5215130561Sobrien { 5216130561Sobrien debug_type ft; 5217130561Sobrien const char *dn; 5218130561Sobrien 5219130561Sobrien ft = debug_get_field_type (dhandle, *fields); 5220130561Sobrien if (ft == NULL) 5221130561Sobrien return NULL; 5222130561Sobrien dn = debug_get_type_name (dhandle, ft); 5223130561Sobrien if (dn != NULL 5224130561Sobrien && (int) strlen (dn) == dc->u.s_name.len 5225130561Sobrien && strncmp (dn, dc->u.s_name.s, dc->u.s_name.len) == 0) 5226130561Sobrien return ft; 5227130561Sobrien } 5228130561Sobrien } 5229130561Sobrien } 5230130561Sobrien return stab_find_tagged_type (dhandle, info, dc->u.s_name.s, 5231130561Sobrien dc->u.s_name.len, DEBUG_KIND_ILLEGAL); 5232130561Sobrien 5233130561Sobrien case DEMANGLE_COMPONENT_QUAL_NAME: 5234130561Sobrien context = stab_demangle_v3_arg (dhandle, info, dc->u.s_binary.left, 5235130561Sobrien context, NULL); 5236130561Sobrien if (context == NULL) 5237130561Sobrien return NULL; 5238130561Sobrien return stab_demangle_v3_arg (dhandle, info, dc->u.s_binary.right, 5239130561Sobrien context, NULL); 5240130561Sobrien 5241130561Sobrien case DEMANGLE_COMPONENT_TEMPLATE: 5242130561Sobrien { 5243130561Sobrien char *p; 5244130561Sobrien size_t alc; 5245130561Sobrien 5246130561Sobrien /* We print this component to get a class name which we can 5247130561Sobrien use. FIXME: This probably won't work if the template uses 5248130561Sobrien template parameters which refer to an outer template. */ 5249130561Sobrien p = cplus_demangle_print (DMGL_PARAMS | DMGL_ANSI, dc, 20, &alc); 5250130561Sobrien if (p == NULL) 5251130561Sobrien { 5252130561Sobrien fprintf (stderr, _("Failed to print demangled template\n")); 5253130561Sobrien return NULL; 5254130561Sobrien } 5255130561Sobrien dt = stab_find_tagged_type (dhandle, info, p, strlen (p), 5256130561Sobrien DEBUG_KIND_CLASS); 5257130561Sobrien free (p); 5258130561Sobrien return dt; 5259130561Sobrien } 5260130561Sobrien 5261130561Sobrien case DEMANGLE_COMPONENT_SUB_STD: 5262130561Sobrien return stab_find_tagged_type (dhandle, info, dc->u.s_string.string, 5263130561Sobrien dc->u.s_string.len, DEBUG_KIND_ILLEGAL); 5264130561Sobrien 5265130561Sobrien case DEMANGLE_COMPONENT_RESTRICT: 5266130561Sobrien case DEMANGLE_COMPONENT_VOLATILE: 5267130561Sobrien case DEMANGLE_COMPONENT_CONST: 5268130561Sobrien case DEMANGLE_COMPONENT_POINTER: 5269130561Sobrien case DEMANGLE_COMPONENT_REFERENCE: 5270130561Sobrien dt = stab_demangle_v3_arg (dhandle, info, dc->u.s_binary.left, NULL, 5271130561Sobrien NULL); 5272130561Sobrien if (dt == NULL) 5273130561Sobrien return NULL; 5274130561Sobrien 5275130561Sobrien switch (dc->type) 5276130561Sobrien { 5277130561Sobrien default: 5278130561Sobrien abort (); 5279130561Sobrien case DEMANGLE_COMPONENT_RESTRICT: 5280130561Sobrien /* FIXME: We have no way to represent restrict. */ 5281130561Sobrien return dt; 5282130561Sobrien case DEMANGLE_COMPONENT_VOLATILE: 5283130561Sobrien return debug_make_volatile_type (dhandle, dt); 5284130561Sobrien case DEMANGLE_COMPONENT_CONST: 5285130561Sobrien return debug_make_const_type (dhandle, dt); 5286130561Sobrien case DEMANGLE_COMPONENT_POINTER: 5287130561Sobrien return debug_make_pointer_type (dhandle, dt); 5288130561Sobrien case DEMANGLE_COMPONENT_REFERENCE: 5289130561Sobrien return debug_make_reference_type (dhandle, dt); 5290130561Sobrien } 5291130561Sobrien 5292218822Sdim case DEMANGLE_COMPONENT_FUNCTION_TYPE: 5293218822Sdim { 5294218822Sdim debug_type *pargs; 5295218822Sdim bfd_boolean varargs; 5296218822Sdim 5297218822Sdim if (dc->u.s_binary.left == NULL) 5298218822Sdim { 5299218822Sdim /* In this case the return type is actually unknown. 5300218822Sdim However, I'm not sure this will ever arise in practice; 5301218822Sdim normally an unknown return type would only appear at 5302218822Sdim the top level, which is handled above. */ 5303218822Sdim dt = debug_make_void_type (dhandle); 5304218822Sdim } 5305218822Sdim else 5306218822Sdim dt = stab_demangle_v3_arg (dhandle, info, dc->u.s_binary.left, NULL, 5307218822Sdim NULL); 5308218822Sdim if (dt == NULL) 5309218822Sdim return NULL; 5310218822Sdim 5311218822Sdim pargs = stab_demangle_v3_arglist (dhandle, info, 5312218822Sdim dc->u.s_binary.right, 5313218822Sdim &varargs); 5314218822Sdim if (pargs == NULL) 5315218822Sdim return NULL; 5316218822Sdim 5317218822Sdim return debug_make_function_type (dhandle, dt, pargs, varargs); 5318218822Sdim } 5319218822Sdim 5320130561Sobrien case DEMANGLE_COMPONENT_BUILTIN_TYPE: 5321130561Sobrien { 5322130561Sobrien char *p; 5323130561Sobrien size_t alc; 5324130561Sobrien debug_type ret; 5325130561Sobrien 5326130561Sobrien /* We print this component in order to find out the type name. 5327130561Sobrien FIXME: Should we instead expose the 5328130561Sobrien demangle_builtin_type_info structure? */ 5329130561Sobrien p = cplus_demangle_print (DMGL_PARAMS | DMGL_ANSI, dc, 20, &alc); 5330130561Sobrien if (p == NULL) 5331130561Sobrien { 5332130561Sobrien fprintf (stderr, _("Couldn't get demangled builtin type\n")); 5333130561Sobrien return NULL; 5334130561Sobrien } 5335130561Sobrien 5336130561Sobrien /* The mangling is based on the type, but does not itself 5337130561Sobrien indicate what the sizes are. So we have to guess. */ 5338130561Sobrien if (strcmp (p, "signed char") == 0) 5339130561Sobrien ret = debug_make_int_type (dhandle, 1, FALSE); 5340130561Sobrien else if (strcmp (p, "bool") == 0) 5341130561Sobrien ret = debug_make_bool_type (dhandle, 1); 5342130561Sobrien else if (strcmp (p, "char") == 0) 5343130561Sobrien ret = debug_make_int_type (dhandle, 1, FALSE); 5344130561Sobrien else if (strcmp (p, "double") == 0) 5345130561Sobrien ret = debug_make_float_type (dhandle, 8); 5346130561Sobrien else if (strcmp (p, "long double") == 0) 5347130561Sobrien ret = debug_make_float_type (dhandle, 8); 5348130561Sobrien else if (strcmp (p, "float") == 0) 5349130561Sobrien ret = debug_make_float_type (dhandle, 4); 5350130561Sobrien else if (strcmp (p, "__float128") == 0) 5351130561Sobrien ret = debug_make_float_type (dhandle, 16); 5352130561Sobrien else if (strcmp (p, "unsigned char") == 0) 5353130561Sobrien ret = debug_make_int_type (dhandle, 1, TRUE); 5354130561Sobrien else if (strcmp (p, "int") == 0) 5355130561Sobrien ret = debug_make_int_type (dhandle, 4, FALSE); 5356130561Sobrien else if (strcmp (p, "unsigned int") == 0) 5357130561Sobrien ret = debug_make_int_type (dhandle, 4, TRUE); 5358130561Sobrien else if (strcmp (p, "long") == 0) 5359130561Sobrien ret = debug_make_int_type (dhandle, 4, FALSE); 5360130561Sobrien else if (strcmp (p, "unsigned long") == 0) 5361130561Sobrien ret = debug_make_int_type (dhandle, 4, TRUE); 5362130561Sobrien else if (strcmp (p, "__int128") == 0) 5363130561Sobrien ret = debug_make_int_type (dhandle, 16, FALSE); 5364130561Sobrien else if (strcmp (p, "unsigned __int128") == 0) 5365130561Sobrien ret = debug_make_int_type (dhandle, 16, TRUE); 5366130561Sobrien else if (strcmp (p, "short") == 0) 5367130561Sobrien ret = debug_make_int_type (dhandle, 2, FALSE); 5368130561Sobrien else if (strcmp (p, "unsigned short") == 0) 5369130561Sobrien ret = debug_make_int_type (dhandle, 2, TRUE); 5370130561Sobrien else if (strcmp (p, "void") == 0) 5371130561Sobrien ret = debug_make_void_type (dhandle); 5372130561Sobrien else if (strcmp (p, "wchar_t") == 0) 5373130561Sobrien ret = debug_make_int_type (dhandle, 4, TRUE); 5374130561Sobrien else if (strcmp (p, "long long") == 0) 5375130561Sobrien ret = debug_make_int_type (dhandle, 8, FALSE); 5376130561Sobrien else if (strcmp (p, "unsigned long long") == 0) 5377130561Sobrien ret = debug_make_int_type (dhandle, 8, TRUE); 5378130561Sobrien else if (strcmp (p, "...") == 0) 5379130561Sobrien { 5380130561Sobrien if (pvarargs == NULL) 5381130561Sobrien fprintf (stderr, _("Unexpected demangled varargs\n")); 5382130561Sobrien else 5383130561Sobrien *pvarargs = TRUE; 5384130561Sobrien ret = NULL; 5385130561Sobrien } 5386130561Sobrien else 5387130561Sobrien { 5388130561Sobrien fprintf (stderr, _("Unrecognized demangled builtin type\n")); 5389130561Sobrien ret = NULL; 5390130561Sobrien } 5391130561Sobrien 5392130561Sobrien free (p); 5393130561Sobrien 5394130561Sobrien return ret; 5395130561Sobrien } 5396130561Sobrien } 5397130561Sobrien} 5398