1*a9fa9459Szrj /* stabs.c -- Parse stabs debugging information 2*a9fa9459Szrj Copyright (C) 1995-2016 Free Software Foundation, Inc. 3*a9fa9459Szrj Written by Ian Lance Taylor <ian@cygnus.com>. 4*a9fa9459Szrj 5*a9fa9459Szrj This file is part of GNU Binutils. 6*a9fa9459Szrj 7*a9fa9459Szrj This program is free software; you can redistribute it and/or modify 8*a9fa9459Szrj it under the terms of the GNU General Public License as published by 9*a9fa9459Szrj the Free Software Foundation; either version 3 of the License, or 10*a9fa9459Szrj (at your option) any later version. 11*a9fa9459Szrj 12*a9fa9459Szrj This program is distributed in the hope that it will be useful, 13*a9fa9459Szrj but WITHOUT ANY WARRANTY; without even the implied warranty of 14*a9fa9459Szrj MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15*a9fa9459Szrj GNU General Public License for more details. 16*a9fa9459Szrj 17*a9fa9459Szrj You should have received a copy of the GNU General Public License 18*a9fa9459Szrj along with this program; if not, write to the Free Software 19*a9fa9459Szrj Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 20*a9fa9459Szrj 02110-1301, USA. */ 21*a9fa9459Szrj 22*a9fa9459Szrj /* This file contains code which parses stabs debugging information. 23*a9fa9459Szrj The organization of this code is based on the gdb stabs reading 24*a9fa9459Szrj code. The job it does is somewhat different, because it is not 25*a9fa9459Szrj trying to identify the correct address for anything. */ 26*a9fa9459Szrj 27*a9fa9459Szrj #include "sysdep.h" 28*a9fa9459Szrj #include "bfd.h" 29*a9fa9459Szrj #include "libiberty.h" 30*a9fa9459Szrj #include "safe-ctype.h" 31*a9fa9459Szrj #include "demangle.h" 32*a9fa9459Szrj #include "debug.h" 33*a9fa9459Szrj #include "budbg.h" 34*a9fa9459Szrj #include "filenames.h" 35*a9fa9459Szrj #include "aout/aout64.h" 36*a9fa9459Szrj #include "aout/stab_gnu.h" 37*a9fa9459Szrj 38*a9fa9459Szrj /* The number of predefined XCOFF types. */ 39*a9fa9459Szrj 40*a9fa9459Szrj #define XCOFF_TYPE_COUNT 34 41*a9fa9459Szrj 42*a9fa9459Szrj /* This structure is used as a handle so that the stab parsing doesn't 43*a9fa9459Szrj need to use any static variables. */ 44*a9fa9459Szrj 45*a9fa9459Szrj struct stab_handle 46*a9fa9459Szrj { 47*a9fa9459Szrj /* The BFD. */ 48*a9fa9459Szrj bfd *abfd; 49*a9fa9459Szrj /* TRUE if this is stabs in sections. */ 50*a9fa9459Szrj bfd_boolean sections; 51*a9fa9459Szrj /* The symbol table. */ 52*a9fa9459Szrj asymbol **syms; 53*a9fa9459Szrj /* The number of symbols. */ 54*a9fa9459Szrj long symcount; 55*a9fa9459Szrj /* The accumulated file name string. */ 56*a9fa9459Szrj char *so_string; 57*a9fa9459Szrj /* The value of the last N_SO symbol. */ 58*a9fa9459Szrj bfd_vma so_value; 59*a9fa9459Szrj /* The value of the start of the file, so that we can handle file 60*a9fa9459Szrj relative N_LBRAC and N_RBRAC symbols. */ 61*a9fa9459Szrj bfd_vma file_start_offset; 62*a9fa9459Szrj /* The offset of the start of the function, so that we can handle 63*a9fa9459Szrj function relative N_LBRAC and N_RBRAC symbols. */ 64*a9fa9459Szrj bfd_vma function_start_offset; 65*a9fa9459Szrj /* The version number of gcc which compiled the current compilation 66*a9fa9459Szrj unit, 0 if not compiled by gcc. */ 67*a9fa9459Szrj int gcc_compiled; 68*a9fa9459Szrj /* Whether an N_OPT symbol was seen that was not generated by gcc, 69*a9fa9459Szrj so that we can detect the SunPRO compiler. */ 70*a9fa9459Szrj bfd_boolean n_opt_found; 71*a9fa9459Szrj /* The main file name. */ 72*a9fa9459Szrj char *main_filename; 73*a9fa9459Szrj /* A stack of unfinished N_BINCL files. */ 74*a9fa9459Szrj struct bincl_file *bincl_stack; 75*a9fa9459Szrj /* A list of finished N_BINCL files. */ 76*a9fa9459Szrj struct bincl_file *bincl_list; 77*a9fa9459Szrj /* Whether we are inside a function or not. */ 78*a9fa9459Szrj bfd_boolean within_function; 79*a9fa9459Szrj /* The address of the end of the function, used if we have seen an 80*a9fa9459Szrj N_FUN symbol while in a function. This is -1 if we have not seen 81*a9fa9459Szrj an N_FUN (the normal case). */ 82*a9fa9459Szrj bfd_vma function_end; 83*a9fa9459Szrj /* The depth of block nesting. */ 84*a9fa9459Szrj int block_depth; 85*a9fa9459Szrj /* List of pending variable definitions. */ 86*a9fa9459Szrj struct stab_pending_var *pending; 87*a9fa9459Szrj /* Number of files for which we have types. */ 88*a9fa9459Szrj unsigned int files; 89*a9fa9459Szrj /* Lists of types per file. */ 90*a9fa9459Szrj struct stab_types **file_types; 91*a9fa9459Szrj /* Predefined XCOFF types. */ 92*a9fa9459Szrj debug_type xcoff_types[XCOFF_TYPE_COUNT]; 93*a9fa9459Szrj /* Undefined tags. */ 94*a9fa9459Szrj struct stab_tag *tags; 95*a9fa9459Szrj /* Set by parse_stab_type if it sees a structure defined as a cross 96*a9fa9459Szrj reference to itself. Reset by parse_stab_type otherwise. */ 97*a9fa9459Szrj bfd_boolean self_crossref; 98*a9fa9459Szrj }; 99*a9fa9459Szrj 100*a9fa9459Szrj /* A list of these structures is used to hold pending variable 101*a9fa9459Szrj definitions seen before the N_LBRAC of a block. */ 102*a9fa9459Szrj 103*a9fa9459Szrj struct stab_pending_var 104*a9fa9459Szrj { 105*a9fa9459Szrj /* Next pending variable definition. */ 106*a9fa9459Szrj struct stab_pending_var *next; 107*a9fa9459Szrj /* Name. */ 108*a9fa9459Szrj const char *name; 109*a9fa9459Szrj /* Type. */ 110*a9fa9459Szrj debug_type type; 111*a9fa9459Szrj /* Kind. */ 112*a9fa9459Szrj enum debug_var_kind kind; 113*a9fa9459Szrj /* Value. */ 114*a9fa9459Szrj bfd_vma val; 115*a9fa9459Szrj }; 116*a9fa9459Szrj 117*a9fa9459Szrj /* A list of these structures is used to hold the types for a single 118*a9fa9459Szrj file. */ 119*a9fa9459Szrj 120*a9fa9459Szrj struct stab_types 121*a9fa9459Szrj { 122*a9fa9459Szrj /* Next set of slots for this file. */ 123*a9fa9459Szrj struct stab_types *next; 124*a9fa9459Szrj /* Types indexed by type number. */ 125*a9fa9459Szrj #define STAB_TYPES_SLOTS (16) 126*a9fa9459Szrj debug_type types[STAB_TYPES_SLOTS]; 127*a9fa9459Szrj }; 128*a9fa9459Szrj 129*a9fa9459Szrj /* We keep a list of undefined tags that we encounter, so that we can 130*a9fa9459Szrj fill them in if the tag is later defined. */ 131*a9fa9459Szrj 132*a9fa9459Szrj struct stab_tag 133*a9fa9459Szrj { 134*a9fa9459Szrj /* Next undefined tag. */ 135*a9fa9459Szrj struct stab_tag *next; 136*a9fa9459Szrj /* Tag name. */ 137*a9fa9459Szrj const char *name; 138*a9fa9459Szrj /* Type kind. */ 139*a9fa9459Szrj enum debug_type_kind kind; 140*a9fa9459Szrj /* Slot to hold real type when we discover it. If we don't, we fill 141*a9fa9459Szrj in an undefined tag type. */ 142*a9fa9459Szrj debug_type slot; 143*a9fa9459Szrj /* Indirect type we have created to point at slot. */ 144*a9fa9459Szrj debug_type type; 145*a9fa9459Szrj }; 146*a9fa9459Szrj 147*a9fa9459Szrj static char *savestring (const char *, int); 148*a9fa9459Szrj static bfd_vma parse_number (const char **, bfd_boolean *); 149*a9fa9459Szrj static void bad_stab (const char *); 150*a9fa9459Szrj static void warn_stab (const char *, const char *); 151*a9fa9459Szrj static bfd_boolean parse_stab_string 152*a9fa9459Szrj (void *, struct stab_handle *, int, int, bfd_vma, const char *); 153*a9fa9459Szrj static debug_type parse_stab_type 154*a9fa9459Szrj (void *, struct stab_handle *, const char *, const char **, debug_type **); 155*a9fa9459Szrj static bfd_boolean parse_stab_type_number (const char **, int *); 156*a9fa9459Szrj static debug_type parse_stab_range_type 157*a9fa9459Szrj (void *, struct stab_handle *, const char *, const char **, const int *); 158*a9fa9459Szrj static debug_type parse_stab_sun_builtin_type (void *, const char **); 159*a9fa9459Szrj static debug_type parse_stab_sun_floating_type (void *, const char **); 160*a9fa9459Szrj static debug_type parse_stab_enum_type (void *, const char **); 161*a9fa9459Szrj static debug_type parse_stab_struct_type 162*a9fa9459Szrj (void *, struct stab_handle *, const char *, const char **, 163*a9fa9459Szrj bfd_boolean, const int *); 164*a9fa9459Szrj static bfd_boolean parse_stab_baseclasses 165*a9fa9459Szrj (void *, struct stab_handle *, const char **, debug_baseclass **); 166*a9fa9459Szrj static bfd_boolean parse_stab_struct_fields 167*a9fa9459Szrj (void *, struct stab_handle *, const char **, debug_field **, bfd_boolean *); 168*a9fa9459Szrj static bfd_boolean parse_stab_cpp_abbrev 169*a9fa9459Szrj (void *, struct stab_handle *, const char **, debug_field *); 170*a9fa9459Szrj static bfd_boolean parse_stab_one_struct_field 171*a9fa9459Szrj (void *, struct stab_handle *, const char **, const char *, 172*a9fa9459Szrj debug_field *, bfd_boolean *); 173*a9fa9459Szrj static bfd_boolean parse_stab_members 174*a9fa9459Szrj (void *, struct stab_handle *, const char *, const char **, const int *, 175*a9fa9459Szrj debug_method **); 176*a9fa9459Szrj static debug_type parse_stab_argtypes 177*a9fa9459Szrj (void *, struct stab_handle *, debug_type, const char *, const char *, 178*a9fa9459Szrj debug_type, const char *, bfd_boolean, bfd_boolean, const char **); 179*a9fa9459Szrj static bfd_boolean parse_stab_tilde_field 180*a9fa9459Szrj (void *, struct stab_handle *, const char **, const int *, debug_type *, 181*a9fa9459Szrj bfd_boolean *); 182*a9fa9459Szrj static debug_type parse_stab_array_type 183*a9fa9459Szrj (void *, struct stab_handle *, const char **, bfd_boolean); 184*a9fa9459Szrj static void push_bincl (struct stab_handle *, const char *, bfd_vma); 185*a9fa9459Szrj static const char *pop_bincl (struct stab_handle *); 186*a9fa9459Szrj static bfd_boolean find_excl (struct stab_handle *, const char *, bfd_vma); 187*a9fa9459Szrj static bfd_boolean stab_record_variable 188*a9fa9459Szrj (void *, struct stab_handle *, const char *, debug_type, 189*a9fa9459Szrj enum debug_var_kind, bfd_vma); 190*a9fa9459Szrj static bfd_boolean stab_emit_pending_vars (void *, struct stab_handle *); 191*a9fa9459Szrj static debug_type *stab_find_slot (struct stab_handle *, const int *); 192*a9fa9459Szrj static debug_type stab_find_type (void *, struct stab_handle *, const int *); 193*a9fa9459Szrj static bfd_boolean stab_record_type 194*a9fa9459Szrj (void *, struct stab_handle *, const int *, debug_type); 195*a9fa9459Szrj static debug_type stab_xcoff_builtin_type 196*a9fa9459Szrj (void *, struct stab_handle *, int); 197*a9fa9459Szrj static debug_type stab_find_tagged_type 198*a9fa9459Szrj (void *, struct stab_handle *, const char *, int, enum debug_type_kind); 199*a9fa9459Szrj static debug_type *stab_demangle_argtypes 200*a9fa9459Szrj (void *, struct stab_handle *, const char *, bfd_boolean *, unsigned int); 201*a9fa9459Szrj static debug_type *stab_demangle_v3_argtypes 202*a9fa9459Szrj (void *, struct stab_handle *, const char *, bfd_boolean *); 203*a9fa9459Szrj static debug_type *stab_demangle_v3_arglist 204*a9fa9459Szrj (void *, struct stab_handle *, struct demangle_component *, bfd_boolean *); 205*a9fa9459Szrj static debug_type stab_demangle_v3_arg 206*a9fa9459Szrj (void *, struct stab_handle *, struct demangle_component *, debug_type, 207*a9fa9459Szrj bfd_boolean *); 208*a9fa9459Szrj 209*a9fa9459Szrj /* Save a string in memory. */ 210*a9fa9459Szrj 211*a9fa9459Szrj static char * 212*a9fa9459Szrj savestring (const char *start, int len) 213*a9fa9459Szrj { 214*a9fa9459Szrj char *ret; 215*a9fa9459Szrj 216*a9fa9459Szrj ret = (char *) xmalloc (len + 1); 217*a9fa9459Szrj memcpy (ret, start, len); 218*a9fa9459Szrj ret[len] = '\0'; 219*a9fa9459Szrj return ret; 220*a9fa9459Szrj } 221*a9fa9459Szrj 222*a9fa9459Szrj /* Read a number from a string. */ 223*a9fa9459Szrj 224*a9fa9459Szrj static bfd_vma 225*a9fa9459Szrj parse_number (const char **pp, bfd_boolean *poverflow) 226*a9fa9459Szrj { 227*a9fa9459Szrj unsigned long ul; 228*a9fa9459Szrj const char *orig; 229*a9fa9459Szrj 230*a9fa9459Szrj if (poverflow != NULL) 231*a9fa9459Szrj *poverflow = FALSE; 232*a9fa9459Szrj 233*a9fa9459Szrj orig = *pp; 234*a9fa9459Szrj 235*a9fa9459Szrj errno = 0; 236*a9fa9459Szrj ul = strtoul (*pp, (char **) pp, 0); 237*a9fa9459Szrj if (ul + 1 != 0 || errno == 0) 238*a9fa9459Szrj { 239*a9fa9459Szrj /* If bfd_vma is larger than unsigned long, and the number is 240*a9fa9459Szrj meant to be negative, we have to make sure that we sign 241*a9fa9459Szrj extend properly. */ 242*a9fa9459Szrj if (*orig == '-') 243*a9fa9459Szrj return (bfd_vma) (bfd_signed_vma) (long) ul; 244*a9fa9459Szrj return (bfd_vma) ul; 245*a9fa9459Szrj } 246*a9fa9459Szrj 247*a9fa9459Szrj /* Note that even though strtoul overflowed, it should have set *pp 248*a9fa9459Szrj to the end of the number, which is where we want it. */ 249*a9fa9459Szrj if (sizeof (bfd_vma) > sizeof (unsigned long)) 250*a9fa9459Szrj { 251*a9fa9459Szrj const char *p; 252*a9fa9459Szrj bfd_boolean neg; 253*a9fa9459Szrj int base; 254*a9fa9459Szrj bfd_vma over, lastdig; 255*a9fa9459Szrj bfd_boolean overflow; 256*a9fa9459Szrj bfd_vma v; 257*a9fa9459Szrj 258*a9fa9459Szrj /* Our own version of strtoul, for a bfd_vma. */ 259*a9fa9459Szrj p = orig; 260*a9fa9459Szrj 261*a9fa9459Szrj neg = FALSE; 262*a9fa9459Szrj if (*p == '+') 263*a9fa9459Szrj ++p; 264*a9fa9459Szrj else if (*p == '-') 265*a9fa9459Szrj { 266*a9fa9459Szrj neg = TRUE; 267*a9fa9459Szrj ++p; 268*a9fa9459Szrj } 269*a9fa9459Szrj 270*a9fa9459Szrj base = 10; 271*a9fa9459Szrj if (*p == '0') 272*a9fa9459Szrj { 273*a9fa9459Szrj if (p[1] == 'x' || p[1] == 'X') 274*a9fa9459Szrj { 275*a9fa9459Szrj base = 16; 276*a9fa9459Szrj p += 2; 277*a9fa9459Szrj } 278*a9fa9459Szrj else 279*a9fa9459Szrj { 280*a9fa9459Szrj base = 8; 281*a9fa9459Szrj ++p; 282*a9fa9459Szrj } 283*a9fa9459Szrj } 284*a9fa9459Szrj 285*a9fa9459Szrj over = ((bfd_vma) (bfd_signed_vma) -1) / (bfd_vma) base; 286*a9fa9459Szrj lastdig = ((bfd_vma) (bfd_signed_vma) -1) % (bfd_vma) base; 287*a9fa9459Szrj 288*a9fa9459Szrj overflow = FALSE; 289*a9fa9459Szrj v = 0; 290*a9fa9459Szrj while (1) 291*a9fa9459Szrj { 292*a9fa9459Szrj int d; 293*a9fa9459Szrj 294*a9fa9459Szrj d = *p++; 295*a9fa9459Szrj if (ISDIGIT (d)) 296*a9fa9459Szrj d -= '0'; 297*a9fa9459Szrj else if (ISUPPER (d)) 298*a9fa9459Szrj d -= 'A'; 299*a9fa9459Szrj else if (ISLOWER (d)) 300*a9fa9459Szrj d -= 'a'; 301*a9fa9459Szrj else 302*a9fa9459Szrj break; 303*a9fa9459Szrj 304*a9fa9459Szrj if (d >= base) 305*a9fa9459Szrj break; 306*a9fa9459Szrj 307*a9fa9459Szrj if (v > over || (v == over && (bfd_vma) d > lastdig)) 308*a9fa9459Szrj { 309*a9fa9459Szrj overflow = TRUE; 310*a9fa9459Szrj break; 311*a9fa9459Szrj } 312*a9fa9459Szrj } 313*a9fa9459Szrj 314*a9fa9459Szrj if (! overflow) 315*a9fa9459Szrj { 316*a9fa9459Szrj if (neg) 317*a9fa9459Szrj v = - v; 318*a9fa9459Szrj return v; 319*a9fa9459Szrj } 320*a9fa9459Szrj } 321*a9fa9459Szrj 322*a9fa9459Szrj /* If we get here, the number is too large to represent in a 323*a9fa9459Szrj bfd_vma. */ 324*a9fa9459Szrj if (poverflow != NULL) 325*a9fa9459Szrj *poverflow = TRUE; 326*a9fa9459Szrj else 327*a9fa9459Szrj warn_stab (orig, _("numeric overflow")); 328*a9fa9459Szrj 329*a9fa9459Szrj return 0; 330*a9fa9459Szrj } 331*a9fa9459Szrj 332*a9fa9459Szrj /* Give an error for a bad stab string. */ 333*a9fa9459Szrj 334*a9fa9459Szrj static void 335*a9fa9459Szrj bad_stab (const char *p) 336*a9fa9459Szrj { 337*a9fa9459Szrj fprintf (stderr, _("Bad stab: %s\n"), p); 338*a9fa9459Szrj } 339*a9fa9459Szrj 340*a9fa9459Szrj /* Warn about something in a stab string. */ 341*a9fa9459Szrj 342*a9fa9459Szrj static void 343*a9fa9459Szrj warn_stab (const char *p, const char *err) 344*a9fa9459Szrj { 345*a9fa9459Szrj fprintf (stderr, _("Warning: %s: %s\n"), err, p); 346*a9fa9459Szrj } 347*a9fa9459Szrj 348*a9fa9459Szrj /* Create a handle to parse stabs symbols with. */ 349*a9fa9459Szrj 350*a9fa9459Szrj void * 351*a9fa9459Szrj start_stab (void *dhandle ATTRIBUTE_UNUSED, bfd *abfd, bfd_boolean sections, 352*a9fa9459Szrj asymbol **syms, long symcount) 353*a9fa9459Szrj { 354*a9fa9459Szrj struct stab_handle *ret; 355*a9fa9459Szrj 356*a9fa9459Szrj ret = (struct stab_handle *) xmalloc (sizeof *ret); 357*a9fa9459Szrj memset (ret, 0, sizeof *ret); 358*a9fa9459Szrj ret->abfd = abfd; 359*a9fa9459Szrj ret->sections = sections; 360*a9fa9459Szrj ret->syms = syms; 361*a9fa9459Szrj ret->symcount = symcount; 362*a9fa9459Szrj ret->files = 1; 363*a9fa9459Szrj ret->file_types = (struct stab_types **) xmalloc (sizeof *ret->file_types); 364*a9fa9459Szrj ret->file_types[0] = NULL; 365*a9fa9459Szrj ret->function_end = (bfd_vma) -1; 366*a9fa9459Szrj return (void *) ret; 367*a9fa9459Szrj } 368*a9fa9459Szrj 369*a9fa9459Szrj /* When we have processed all the stabs information, we need to go 370*a9fa9459Szrj through and fill in all the undefined tags. */ 371*a9fa9459Szrj 372*a9fa9459Szrj bfd_boolean 373*a9fa9459Szrj finish_stab (void *dhandle, void *handle) 374*a9fa9459Szrj { 375*a9fa9459Szrj struct stab_handle *info = (struct stab_handle *) handle; 376*a9fa9459Szrj struct stab_tag *st; 377*a9fa9459Szrj 378*a9fa9459Szrj if (info->within_function) 379*a9fa9459Szrj { 380*a9fa9459Szrj if (! stab_emit_pending_vars (dhandle, info) 381*a9fa9459Szrj || ! debug_end_function (dhandle, info->function_end)) 382*a9fa9459Szrj return FALSE; 383*a9fa9459Szrj info->within_function = FALSE; 384*a9fa9459Szrj info->function_end = (bfd_vma) -1; 385*a9fa9459Szrj } 386*a9fa9459Szrj 387*a9fa9459Szrj for (st = info->tags; st != NULL; st = st->next) 388*a9fa9459Szrj { 389*a9fa9459Szrj enum debug_type_kind kind; 390*a9fa9459Szrj 391*a9fa9459Szrj kind = st->kind; 392*a9fa9459Szrj if (kind == DEBUG_KIND_ILLEGAL) 393*a9fa9459Szrj kind = DEBUG_KIND_STRUCT; 394*a9fa9459Szrj st->slot = debug_make_undefined_tagged_type (dhandle, st->name, kind); 395*a9fa9459Szrj if (st->slot == DEBUG_TYPE_NULL) 396*a9fa9459Szrj return FALSE; 397*a9fa9459Szrj } 398*a9fa9459Szrj 399*a9fa9459Szrj return TRUE; 400*a9fa9459Szrj } 401*a9fa9459Szrj 402*a9fa9459Szrj /* Handle a single stabs symbol. */ 403*a9fa9459Szrj 404*a9fa9459Szrj bfd_boolean 405*a9fa9459Szrj parse_stab (void *dhandle, void *handle, int type, int desc, bfd_vma value, 406*a9fa9459Szrj const char *string) 407*a9fa9459Szrj { 408*a9fa9459Szrj struct stab_handle *info = (struct stab_handle *) handle; 409*a9fa9459Szrj 410*a9fa9459Szrj /* gcc will emit two N_SO strings per compilation unit, one for the 411*a9fa9459Szrj directory name and one for the file name. We just collect N_SO 412*a9fa9459Szrj strings as we see them, and start the new compilation unit when 413*a9fa9459Szrj we see a non N_SO symbol. */ 414*a9fa9459Szrj if (info->so_string != NULL 415*a9fa9459Szrj && (type != N_SO || *string == '\0' || value != info->so_value)) 416*a9fa9459Szrj { 417*a9fa9459Szrj if (! debug_set_filename (dhandle, info->so_string)) 418*a9fa9459Szrj return FALSE; 419*a9fa9459Szrj info->main_filename = info->so_string; 420*a9fa9459Szrj 421*a9fa9459Szrj info->gcc_compiled = 0; 422*a9fa9459Szrj info->n_opt_found = FALSE; 423*a9fa9459Szrj 424*a9fa9459Szrj /* Generally, for stabs in the symbol table, the N_LBRAC and 425*a9fa9459Szrj N_RBRAC symbols are relative to the N_SO symbol value. */ 426*a9fa9459Szrj if (! info->sections) 427*a9fa9459Szrj info->file_start_offset = info->so_value; 428*a9fa9459Szrj 429*a9fa9459Szrj /* We need to reset the mapping from type numbers to types. We 430*a9fa9459Szrj can't free the old mapping, because of the use of 431*a9fa9459Szrj debug_make_indirect_type. */ 432*a9fa9459Szrj info->files = 1; 433*a9fa9459Szrj info->file_types = ((struct stab_types **) 434*a9fa9459Szrj xmalloc (sizeof *info->file_types)); 435*a9fa9459Szrj info->file_types[0] = NULL; 436*a9fa9459Szrj 437*a9fa9459Szrj info->so_string = NULL; 438*a9fa9459Szrj 439*a9fa9459Szrj /* Now process whatever type we just got. */ 440*a9fa9459Szrj } 441*a9fa9459Szrj 442*a9fa9459Szrj switch (type) 443*a9fa9459Szrj { 444*a9fa9459Szrj case N_FN: 445*a9fa9459Szrj case N_FN_SEQ: 446*a9fa9459Szrj break; 447*a9fa9459Szrj 448*a9fa9459Szrj case N_LBRAC: 449*a9fa9459Szrj /* Ignore extra outermost context from SunPRO cc and acc. */ 450*a9fa9459Szrj if (info->n_opt_found && desc == 1) 451*a9fa9459Szrj break; 452*a9fa9459Szrj 453*a9fa9459Szrj if (! info->within_function) 454*a9fa9459Szrj { 455*a9fa9459Szrj fprintf (stderr, _("N_LBRAC not within function\n")); 456*a9fa9459Szrj return FALSE; 457*a9fa9459Szrj } 458*a9fa9459Szrj 459*a9fa9459Szrj /* Start an inner lexical block. */ 460*a9fa9459Szrj if (! debug_start_block (dhandle, 461*a9fa9459Szrj (value 462*a9fa9459Szrj + info->file_start_offset 463*a9fa9459Szrj + info->function_start_offset))) 464*a9fa9459Szrj return FALSE; 465*a9fa9459Szrj 466*a9fa9459Szrj /* Emit any pending variable definitions. */ 467*a9fa9459Szrj if (! stab_emit_pending_vars (dhandle, info)) 468*a9fa9459Szrj return FALSE; 469*a9fa9459Szrj 470*a9fa9459Szrj ++info->block_depth; 471*a9fa9459Szrj break; 472*a9fa9459Szrj 473*a9fa9459Szrj case N_RBRAC: 474*a9fa9459Szrj /* Ignore extra outermost context from SunPRO cc and acc. */ 475*a9fa9459Szrj if (info->n_opt_found && desc == 1) 476*a9fa9459Szrj break; 477*a9fa9459Szrj 478*a9fa9459Szrj /* We shouldn't have any pending variable definitions here, but, 479*a9fa9459Szrj if we do, we probably need to emit them before closing the 480*a9fa9459Szrj block. */ 481*a9fa9459Szrj if (! stab_emit_pending_vars (dhandle, info)) 482*a9fa9459Szrj return FALSE; 483*a9fa9459Szrj 484*a9fa9459Szrj /* End an inner lexical block. */ 485*a9fa9459Szrj if (! debug_end_block (dhandle, 486*a9fa9459Szrj (value 487*a9fa9459Szrj + info->file_start_offset 488*a9fa9459Szrj + info->function_start_offset))) 489*a9fa9459Szrj return FALSE; 490*a9fa9459Szrj 491*a9fa9459Szrj --info->block_depth; 492*a9fa9459Szrj if (info->block_depth < 0) 493*a9fa9459Szrj { 494*a9fa9459Szrj fprintf (stderr, _("Too many N_RBRACs\n")); 495*a9fa9459Szrj return FALSE; 496*a9fa9459Szrj } 497*a9fa9459Szrj break; 498*a9fa9459Szrj 499*a9fa9459Szrj case N_SO: 500*a9fa9459Szrj /* This always ends a function. */ 501*a9fa9459Szrj if (info->within_function) 502*a9fa9459Szrj { 503*a9fa9459Szrj bfd_vma endval; 504*a9fa9459Szrj 505*a9fa9459Szrj endval = value; 506*a9fa9459Szrj if (*string != '\0' 507*a9fa9459Szrj && info->function_end != (bfd_vma) -1 508*a9fa9459Szrj && info->function_end < endval) 509*a9fa9459Szrj endval = info->function_end; 510*a9fa9459Szrj if (! stab_emit_pending_vars (dhandle, info) 511*a9fa9459Szrj || ! debug_end_function (dhandle, endval)) 512*a9fa9459Szrj return FALSE; 513*a9fa9459Szrj info->within_function = FALSE; 514*a9fa9459Szrj info->function_end = (bfd_vma) -1; 515*a9fa9459Szrj } 516*a9fa9459Szrj 517*a9fa9459Szrj /* An empty string is emitted by gcc at the end of a compilation 518*a9fa9459Szrj unit. */ 519*a9fa9459Szrj if (*string == '\0') 520*a9fa9459Szrj return TRUE; 521*a9fa9459Szrj 522*a9fa9459Szrj /* Just accumulate strings until we see a non N_SO symbol. If 523*a9fa9459Szrj the string starts with a directory separator or some other 524*a9fa9459Szrj form of absolute path specification, we discard the previously 525*a9fa9459Szrj accumulated strings. */ 526*a9fa9459Szrj if (info->so_string == NULL) 527*a9fa9459Szrj info->so_string = xstrdup (string); 528*a9fa9459Szrj else 529*a9fa9459Szrj { 530*a9fa9459Szrj char *f; 531*a9fa9459Szrj 532*a9fa9459Szrj f = info->so_string; 533*a9fa9459Szrj 534*a9fa9459Szrj if (IS_ABSOLUTE_PATH (string)) 535*a9fa9459Szrj info->so_string = xstrdup (string); 536*a9fa9459Szrj else 537*a9fa9459Szrj info->so_string = concat (info->so_string, string, 538*a9fa9459Szrj (const char *) NULL); 539*a9fa9459Szrj free (f); 540*a9fa9459Szrj } 541*a9fa9459Szrj 542*a9fa9459Szrj info->so_value = value; 543*a9fa9459Szrj 544*a9fa9459Szrj break; 545*a9fa9459Szrj 546*a9fa9459Szrj case N_SOL: 547*a9fa9459Szrj /* Start an include file. */ 548*a9fa9459Szrj if (! debug_start_source (dhandle, string)) 549*a9fa9459Szrj return FALSE; 550*a9fa9459Szrj break; 551*a9fa9459Szrj 552*a9fa9459Szrj case N_BINCL: 553*a9fa9459Szrj /* Start an include file which may be replaced. */ 554*a9fa9459Szrj push_bincl (info, string, value); 555*a9fa9459Szrj if (! debug_start_source (dhandle, string)) 556*a9fa9459Szrj return FALSE; 557*a9fa9459Szrj break; 558*a9fa9459Szrj 559*a9fa9459Szrj case N_EINCL: 560*a9fa9459Szrj /* End an N_BINCL include. */ 561*a9fa9459Szrj if (! debug_start_source (dhandle, pop_bincl (info))) 562*a9fa9459Szrj return FALSE; 563*a9fa9459Szrj break; 564*a9fa9459Szrj 565*a9fa9459Szrj case N_EXCL: 566*a9fa9459Szrj /* This is a duplicate of a header file named by N_BINCL which 567*a9fa9459Szrj was eliminated by the linker. */ 568*a9fa9459Szrj if (! find_excl (info, string, value)) 569*a9fa9459Szrj return FALSE; 570*a9fa9459Szrj break; 571*a9fa9459Szrj 572*a9fa9459Szrj case N_SLINE: 573*a9fa9459Szrj if (! debug_record_line (dhandle, desc, 574*a9fa9459Szrj value + (info->within_function 575*a9fa9459Szrj ? info->function_start_offset : 0))) 576*a9fa9459Szrj return FALSE; 577*a9fa9459Szrj break; 578*a9fa9459Szrj 579*a9fa9459Szrj case N_BCOMM: 580*a9fa9459Szrj if (! debug_start_common_block (dhandle, string)) 581*a9fa9459Szrj return FALSE; 582*a9fa9459Szrj break; 583*a9fa9459Szrj 584*a9fa9459Szrj case N_ECOMM: 585*a9fa9459Szrj if (! debug_end_common_block (dhandle, string)) 586*a9fa9459Szrj return FALSE; 587*a9fa9459Szrj break; 588*a9fa9459Szrj 589*a9fa9459Szrj case N_FUN: 590*a9fa9459Szrj if (*string == '\0') 591*a9fa9459Szrj { 592*a9fa9459Szrj if (info->within_function) 593*a9fa9459Szrj { 594*a9fa9459Szrj /* This always marks the end of a function; we don't 595*a9fa9459Szrj need to worry about info->function_end. */ 596*a9fa9459Szrj if (info->sections) 597*a9fa9459Szrj value += info->function_start_offset; 598*a9fa9459Szrj if (! stab_emit_pending_vars (dhandle, info) 599*a9fa9459Szrj || ! debug_end_function (dhandle, value)) 600*a9fa9459Szrj return FALSE; 601*a9fa9459Szrj info->within_function = FALSE; 602*a9fa9459Szrj info->function_end = (bfd_vma) -1; 603*a9fa9459Szrj } 604*a9fa9459Szrj break; 605*a9fa9459Szrj } 606*a9fa9459Szrj 607*a9fa9459Szrj /* A const static symbol in the .text section will have an N_FUN 608*a9fa9459Szrj entry. We need to use these to mark the end of the function, 609*a9fa9459Szrj in case we are looking at gcc output before it was changed to 610*a9fa9459Szrj always emit an empty N_FUN. We can't call debug_end_function 611*a9fa9459Szrj here, because it might be a local static symbol. */ 612*a9fa9459Szrj if (info->within_function 613*a9fa9459Szrj && (info->function_end == (bfd_vma) -1 614*a9fa9459Szrj || value < info->function_end)) 615*a9fa9459Szrj info->function_end = value; 616*a9fa9459Szrj 617*a9fa9459Szrj /* Fall through. */ 618*a9fa9459Szrj /* FIXME: gdb checks the string for N_STSYM, N_LCSYM or N_ROSYM 619*a9fa9459Szrj symbols, and if it does not start with :S, gdb relocates the 620*a9fa9459Szrj value to the start of the section. gcc always seems to use 621*a9fa9459Szrj :S, so we don't worry about this. */ 622*a9fa9459Szrj /* Fall through. */ 623*a9fa9459Szrj default: 624*a9fa9459Szrj { 625*a9fa9459Szrj const char *colon; 626*a9fa9459Szrj 627*a9fa9459Szrj colon = strchr (string, ':'); 628*a9fa9459Szrj if (colon != NULL 629*a9fa9459Szrj && (colon[1] == 'f' || colon[1] == 'F')) 630*a9fa9459Szrj { 631*a9fa9459Szrj if (info->within_function) 632*a9fa9459Szrj { 633*a9fa9459Szrj bfd_vma endval; 634*a9fa9459Szrj 635*a9fa9459Szrj endval = value; 636*a9fa9459Szrj if (info->function_end != (bfd_vma) -1 637*a9fa9459Szrj && info->function_end < endval) 638*a9fa9459Szrj endval = info->function_end; 639*a9fa9459Szrj if (! stab_emit_pending_vars (dhandle, info) 640*a9fa9459Szrj || ! debug_end_function (dhandle, endval)) 641*a9fa9459Szrj return FALSE; 642*a9fa9459Szrj info->function_end = (bfd_vma) -1; 643*a9fa9459Szrj } 644*a9fa9459Szrj /* For stabs in sections, line numbers and block addresses 645*a9fa9459Szrj are offsets from the start of the function. */ 646*a9fa9459Szrj if (info->sections) 647*a9fa9459Szrj info->function_start_offset = value; 648*a9fa9459Szrj info->within_function = TRUE; 649*a9fa9459Szrj } 650*a9fa9459Szrj 651*a9fa9459Szrj if (! parse_stab_string (dhandle, info, type, desc, value, string)) 652*a9fa9459Szrj return FALSE; 653*a9fa9459Szrj } 654*a9fa9459Szrj break; 655*a9fa9459Szrj 656*a9fa9459Szrj case N_OPT: 657*a9fa9459Szrj if (string != NULL && strcmp (string, "gcc2_compiled.") == 0) 658*a9fa9459Szrj info->gcc_compiled = 2; 659*a9fa9459Szrj else if (string != NULL && strcmp (string, "gcc_compiled.") == 0) 660*a9fa9459Szrj info->gcc_compiled = 1; 661*a9fa9459Szrj else 662*a9fa9459Szrj info->n_opt_found = TRUE; 663*a9fa9459Szrj break; 664*a9fa9459Szrj 665*a9fa9459Szrj case N_OBJ: 666*a9fa9459Szrj case N_ENDM: 667*a9fa9459Szrj case N_MAIN: 668*a9fa9459Szrj case N_WARNING: 669*a9fa9459Szrj break; 670*a9fa9459Szrj } 671*a9fa9459Szrj 672*a9fa9459Szrj return TRUE; 673*a9fa9459Szrj } 674*a9fa9459Szrj 675*a9fa9459Szrj /* Parse the stabs string. */ 676*a9fa9459Szrj 677*a9fa9459Szrj static bfd_boolean 678*a9fa9459Szrj parse_stab_string (void *dhandle, struct stab_handle *info, int stabtype, 679*a9fa9459Szrj int desc ATTRIBUTE_UNUSED, bfd_vma value, const char *string) 680*a9fa9459Szrj { 681*a9fa9459Szrj const char *p; 682*a9fa9459Szrj char *name; 683*a9fa9459Szrj int type; 684*a9fa9459Szrj debug_type dtype; 685*a9fa9459Szrj bfd_boolean synonym; 686*a9fa9459Szrj bfd_boolean self_crossref; 687*a9fa9459Szrj debug_type *slot; 688*a9fa9459Szrj 689*a9fa9459Szrj p = strchr (string, ':'); 690*a9fa9459Szrj if (p == NULL) 691*a9fa9459Szrj return TRUE; 692*a9fa9459Szrj 693*a9fa9459Szrj while (p[1] == ':') 694*a9fa9459Szrj { 695*a9fa9459Szrj p += 2; 696*a9fa9459Szrj p = strchr (p, ':'); 697*a9fa9459Szrj if (p == NULL) 698*a9fa9459Szrj { 699*a9fa9459Szrj bad_stab (string); 700*a9fa9459Szrj return FALSE; 701*a9fa9459Szrj } 702*a9fa9459Szrj } 703*a9fa9459Szrj 704*a9fa9459Szrj /* FIXME: Sometimes the special C++ names start with '.'. */ 705*a9fa9459Szrj name = NULL; 706*a9fa9459Szrj if (string[0] == '$') 707*a9fa9459Szrj { 708*a9fa9459Szrj switch (string[1]) 709*a9fa9459Szrj { 710*a9fa9459Szrj case 't': 711*a9fa9459Szrj name = "this"; 712*a9fa9459Szrj break; 713*a9fa9459Szrj case 'v': 714*a9fa9459Szrj /* Was: name = "vptr"; */ 715*a9fa9459Szrj break; 716*a9fa9459Szrj case 'e': 717*a9fa9459Szrj name = "eh_throw"; 718*a9fa9459Szrj break; 719*a9fa9459Szrj case '_': 720*a9fa9459Szrj /* This was an anonymous type that was never fixed up. */ 721*a9fa9459Szrj break; 722*a9fa9459Szrj case 'X': 723*a9fa9459Szrj /* SunPRO (3.0 at least) static variable encoding. */ 724*a9fa9459Szrj break; 725*a9fa9459Szrj default: 726*a9fa9459Szrj warn_stab (string, _("unknown C++ encoded name")); 727*a9fa9459Szrj break; 728*a9fa9459Szrj } 729*a9fa9459Szrj } 730*a9fa9459Szrj 731*a9fa9459Szrj if (name == NULL) 732*a9fa9459Szrj { 733*a9fa9459Szrj if (p == string || (string[0] == ' ' && p == string + 1)) 734*a9fa9459Szrj name = NULL; 735*a9fa9459Szrj else 736*a9fa9459Szrj name = savestring (string, p - string); 737*a9fa9459Szrj } 738*a9fa9459Szrj 739*a9fa9459Szrj ++p; 740*a9fa9459Szrj if (ISDIGIT (*p) || *p == '(' || *p == '-') 741*a9fa9459Szrj type = 'l'; 742*a9fa9459Szrj else 743*a9fa9459Szrj type = *p++; 744*a9fa9459Szrj 745*a9fa9459Szrj switch (type) 746*a9fa9459Szrj { 747*a9fa9459Szrj case 'c': 748*a9fa9459Szrj /* c is a special case, not followed by a type-number. 749*a9fa9459Szrj SYMBOL:c=iVALUE for an integer constant symbol. 750*a9fa9459Szrj SYMBOL:c=rVALUE for a floating constant symbol. 751*a9fa9459Szrj SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol. 752*a9fa9459Szrj e.g. "b:c=e6,0" for "const b = blob1" 753*a9fa9459Szrj (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */ 754*a9fa9459Szrj if (*p != '=') 755*a9fa9459Szrj { 756*a9fa9459Szrj bad_stab (string); 757*a9fa9459Szrj return FALSE; 758*a9fa9459Szrj } 759*a9fa9459Szrj ++p; 760*a9fa9459Szrj switch (*p++) 761*a9fa9459Szrj { 762*a9fa9459Szrj case 'r': 763*a9fa9459Szrj /* Floating point constant. */ 764*a9fa9459Szrj if (! debug_record_float_const (dhandle, name, atof (p))) 765*a9fa9459Szrj return FALSE; 766*a9fa9459Szrj break; 767*a9fa9459Szrj case 'i': 768*a9fa9459Szrj /* Integer constant. */ 769*a9fa9459Szrj /* Defining integer constants this way is kind of silly, 770*a9fa9459Szrj since 'e' constants allows the compiler to give not only 771*a9fa9459Szrj the value, but the type as well. C has at least int, 772*a9fa9459Szrj long, unsigned int, and long long as constant types; 773*a9fa9459Szrj other languages probably should have at least unsigned as 774*a9fa9459Szrj well as signed constants. */ 775*a9fa9459Szrj if (! debug_record_int_const (dhandle, name, atoi (p))) 776*a9fa9459Szrj return FALSE; 777*a9fa9459Szrj break; 778*a9fa9459Szrj case 'e': 779*a9fa9459Szrj /* SYMBOL:c=eTYPE,INTVALUE for a constant symbol whose value 780*a9fa9459Szrj can be represented as integral. 781*a9fa9459Szrj e.g. "b:c=e6,0" for "const b = blob1" 782*a9fa9459Szrj (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */ 783*a9fa9459Szrj dtype = parse_stab_type (dhandle, info, (const char *) NULL, 784*a9fa9459Szrj &p, (debug_type **) NULL); 785*a9fa9459Szrj if (dtype == DEBUG_TYPE_NULL) 786*a9fa9459Szrj return FALSE; 787*a9fa9459Szrj if (*p != ',') 788*a9fa9459Szrj { 789*a9fa9459Szrj bad_stab (string); 790*a9fa9459Szrj return FALSE; 791*a9fa9459Szrj } 792*a9fa9459Szrj if (! debug_record_typed_const (dhandle, name, dtype, atoi (p))) 793*a9fa9459Szrj return FALSE; 794*a9fa9459Szrj break; 795*a9fa9459Szrj default: 796*a9fa9459Szrj bad_stab (string); 797*a9fa9459Szrj return FALSE; 798*a9fa9459Szrj } 799*a9fa9459Szrj 800*a9fa9459Szrj break; 801*a9fa9459Szrj 802*a9fa9459Szrj case 'C': 803*a9fa9459Szrj /* The name of a caught exception. */ 804*a9fa9459Szrj dtype = parse_stab_type (dhandle, info, (const char *) NULL, 805*a9fa9459Szrj &p, (debug_type **) NULL); 806*a9fa9459Szrj if (dtype == DEBUG_TYPE_NULL) 807*a9fa9459Szrj return FALSE; 808*a9fa9459Szrj if (! debug_record_label (dhandle, name, dtype, value)) 809*a9fa9459Szrj return FALSE; 810*a9fa9459Szrj break; 811*a9fa9459Szrj 812*a9fa9459Szrj case 'f': 813*a9fa9459Szrj case 'F': 814*a9fa9459Szrj /* A function definition. */ 815*a9fa9459Szrj dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p, 816*a9fa9459Szrj (debug_type **) NULL); 817*a9fa9459Szrj if (dtype == DEBUG_TYPE_NULL) 818*a9fa9459Szrj return FALSE; 819*a9fa9459Szrj if (! debug_record_function (dhandle, name, dtype, type == 'F', value)) 820*a9fa9459Szrj return FALSE; 821*a9fa9459Szrj 822*a9fa9459Szrj /* Sun acc puts declared types of arguments here. We don't care 823*a9fa9459Szrj about their actual types (FIXME -- we should remember the whole 824*a9fa9459Szrj function prototype), but the list may define some new types 825*a9fa9459Szrj that we have to remember, so we must scan it now. */ 826*a9fa9459Szrj while (*p == ';') 827*a9fa9459Szrj { 828*a9fa9459Szrj ++p; 829*a9fa9459Szrj if (parse_stab_type (dhandle, info, (const char *) NULL, &p, 830*a9fa9459Szrj (debug_type **) NULL) 831*a9fa9459Szrj == DEBUG_TYPE_NULL) 832*a9fa9459Szrj return FALSE; 833*a9fa9459Szrj } 834*a9fa9459Szrj 835*a9fa9459Szrj break; 836*a9fa9459Szrj 837*a9fa9459Szrj case 'G': 838*a9fa9459Szrj { 839*a9fa9459Szrj asymbol **ps; 840*a9fa9459Szrj 841*a9fa9459Szrj /* A global symbol. The value must be extracted from the 842*a9fa9459Szrj symbol table. */ 843*a9fa9459Szrj dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p, 844*a9fa9459Szrj (debug_type **) NULL); 845*a9fa9459Szrj if (dtype == DEBUG_TYPE_NULL) 846*a9fa9459Szrj return FALSE; 847*a9fa9459Szrj if (name != NULL) 848*a9fa9459Szrj { 849*a9fa9459Szrj char leading; 850*a9fa9459Szrj long c; 851*a9fa9459Szrj 852*a9fa9459Szrj leading = bfd_get_symbol_leading_char (info->abfd); 853*a9fa9459Szrj for (c = info->symcount, ps = info->syms; c > 0; --c, ++ps) 854*a9fa9459Szrj { 855*a9fa9459Szrj const char *n; 856*a9fa9459Szrj 857*a9fa9459Szrj n = bfd_asymbol_name (*ps); 858*a9fa9459Szrj if (leading != '\0' && *n == leading) 859*a9fa9459Szrj ++n; 860*a9fa9459Szrj if (*n == *name && strcmp (n, name) == 0) 861*a9fa9459Szrj break; 862*a9fa9459Szrj } 863*a9fa9459Szrj 864*a9fa9459Szrj if (c > 0) 865*a9fa9459Szrj value = bfd_asymbol_value (*ps); 866*a9fa9459Szrj } 867*a9fa9459Szrj 868*a9fa9459Szrj if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_GLOBAL, 869*a9fa9459Szrj value)) 870*a9fa9459Szrj return FALSE; 871*a9fa9459Szrj } 872*a9fa9459Szrj break; 873*a9fa9459Szrj 874*a9fa9459Szrj /* This case is faked by a conditional above, when there is no 875*a9fa9459Szrj code letter in the dbx data. Dbx data never actually 876*a9fa9459Szrj contains 'l'. */ 877*a9fa9459Szrj case 'l': 878*a9fa9459Szrj case 's': 879*a9fa9459Szrj dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p, 880*a9fa9459Szrj (debug_type **) NULL); 881*a9fa9459Szrj if (dtype == DEBUG_TYPE_NULL) 882*a9fa9459Szrj return FALSE; 883*a9fa9459Szrj if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_LOCAL, 884*a9fa9459Szrj value)) 885*a9fa9459Szrj return FALSE; 886*a9fa9459Szrj break; 887*a9fa9459Szrj 888*a9fa9459Szrj case 'p': 889*a9fa9459Szrj /* A function parameter. */ 890*a9fa9459Szrj if (*p != 'F') 891*a9fa9459Szrj dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p, 892*a9fa9459Szrj (debug_type **) NULL); 893*a9fa9459Szrj else 894*a9fa9459Szrj { 895*a9fa9459Szrj /* pF is a two-letter code that means a function parameter in 896*a9fa9459Szrj Fortran. The type-number specifies the type of the return 897*a9fa9459Szrj value. Translate it into a pointer-to-function type. */ 898*a9fa9459Szrj ++p; 899*a9fa9459Szrj dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p, 900*a9fa9459Szrj (debug_type **) NULL); 901*a9fa9459Szrj if (dtype != DEBUG_TYPE_NULL) 902*a9fa9459Szrj { 903*a9fa9459Szrj debug_type ftype; 904*a9fa9459Szrj 905*a9fa9459Szrj ftype = debug_make_function_type (dhandle, dtype, 906*a9fa9459Szrj (debug_type *) NULL, FALSE); 907*a9fa9459Szrj dtype = debug_make_pointer_type (dhandle, ftype); 908*a9fa9459Szrj } 909*a9fa9459Szrj } 910*a9fa9459Szrj if (dtype == DEBUG_TYPE_NULL) 911*a9fa9459Szrj return FALSE; 912*a9fa9459Szrj if (! debug_record_parameter (dhandle, name, dtype, DEBUG_PARM_STACK, 913*a9fa9459Szrj value)) 914*a9fa9459Szrj return FALSE; 915*a9fa9459Szrj 916*a9fa9459Szrj /* FIXME: At this point gdb considers rearranging the parameter 917*a9fa9459Szrj address on a big endian machine if it is smaller than an int. 918*a9fa9459Szrj We have no way to do that, since we don't really know much 919*a9fa9459Szrj about the target. */ 920*a9fa9459Szrj break; 921*a9fa9459Szrj 922*a9fa9459Szrj case 'P': 923*a9fa9459Szrj if (stabtype == N_FUN) 924*a9fa9459Szrj { 925*a9fa9459Szrj /* Prototype of a function referenced by this file. */ 926*a9fa9459Szrj while (*p == ';') 927*a9fa9459Szrj { 928*a9fa9459Szrj ++p; 929*a9fa9459Szrj if (parse_stab_type (dhandle, info, (const char *) NULL, &p, 930*a9fa9459Szrj (debug_type **) NULL) 931*a9fa9459Szrj == DEBUG_TYPE_NULL) 932*a9fa9459Szrj return FALSE; 933*a9fa9459Szrj } 934*a9fa9459Szrj break; 935*a9fa9459Szrj } 936*a9fa9459Szrj /* Fall through. */ 937*a9fa9459Szrj case 'R': 938*a9fa9459Szrj /* Parameter which is in a register. */ 939*a9fa9459Szrj dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p, 940*a9fa9459Szrj (debug_type **) NULL); 941*a9fa9459Szrj if (dtype == DEBUG_TYPE_NULL) 942*a9fa9459Szrj return FALSE; 943*a9fa9459Szrj if (! debug_record_parameter (dhandle, name, dtype, DEBUG_PARM_REG, 944*a9fa9459Szrj value)) 945*a9fa9459Szrj return FALSE; 946*a9fa9459Szrj break; 947*a9fa9459Szrj 948*a9fa9459Szrj case 'r': 949*a9fa9459Szrj /* Register variable (either global or local). */ 950*a9fa9459Szrj dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p, 951*a9fa9459Szrj (debug_type **) NULL); 952*a9fa9459Szrj if (dtype == DEBUG_TYPE_NULL) 953*a9fa9459Szrj return FALSE; 954*a9fa9459Szrj if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_REGISTER, 955*a9fa9459Szrj value)) 956*a9fa9459Szrj return FALSE; 957*a9fa9459Szrj 958*a9fa9459Szrj /* FIXME: At this point gdb checks to combine pairs of 'p' and 959*a9fa9459Szrj 'r' stabs into a single 'P' stab. */ 960*a9fa9459Szrj break; 961*a9fa9459Szrj 962*a9fa9459Szrj case 'S': 963*a9fa9459Szrj /* Static symbol at top level of file. */ 964*a9fa9459Szrj dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p, 965*a9fa9459Szrj (debug_type **) NULL); 966*a9fa9459Szrj if (dtype == DEBUG_TYPE_NULL) 967*a9fa9459Szrj return FALSE; 968*a9fa9459Szrj if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_STATIC, 969*a9fa9459Szrj value)) 970*a9fa9459Szrj return FALSE; 971*a9fa9459Szrj break; 972*a9fa9459Szrj 973*a9fa9459Szrj case 't': 974*a9fa9459Szrj /* A typedef. */ 975*a9fa9459Szrj dtype = parse_stab_type (dhandle, info, name, &p, &slot); 976*a9fa9459Szrj if (dtype == DEBUG_TYPE_NULL) 977*a9fa9459Szrj return FALSE; 978*a9fa9459Szrj if (name == NULL) 979*a9fa9459Szrj { 980*a9fa9459Szrj /* A nameless type. Nothing to do. */ 981*a9fa9459Szrj return TRUE; 982*a9fa9459Szrj } 983*a9fa9459Szrj 984*a9fa9459Szrj dtype = debug_name_type (dhandle, name, dtype); 985*a9fa9459Szrj if (dtype == DEBUG_TYPE_NULL) 986*a9fa9459Szrj return FALSE; 987*a9fa9459Szrj 988*a9fa9459Szrj if (slot != NULL) 989*a9fa9459Szrj *slot = dtype; 990*a9fa9459Szrj 991*a9fa9459Szrj break; 992*a9fa9459Szrj 993*a9fa9459Szrj case 'T': 994*a9fa9459Szrj /* Struct, union, or enum tag. For GNU C++, this can be be followed 995*a9fa9459Szrj by 't' which means we are typedef'ing it as well. */ 996*a9fa9459Szrj if (*p != 't') 997*a9fa9459Szrj { 998*a9fa9459Szrj synonym = FALSE; 999*a9fa9459Szrj /* FIXME: gdb sets synonym to TRUE if the current language 1000*a9fa9459Szrj is C++. */ 1001*a9fa9459Szrj } 1002*a9fa9459Szrj else 1003*a9fa9459Szrj { 1004*a9fa9459Szrj synonym = TRUE; 1005*a9fa9459Szrj ++p; 1006*a9fa9459Szrj } 1007*a9fa9459Szrj 1008*a9fa9459Szrj dtype = parse_stab_type (dhandle, info, name, &p, &slot); 1009*a9fa9459Szrj if (dtype == DEBUG_TYPE_NULL) 1010*a9fa9459Szrj return FALSE; 1011*a9fa9459Szrj if (name == NULL) 1012*a9fa9459Szrj return TRUE; 1013*a9fa9459Szrj 1014*a9fa9459Szrj /* INFO->SELF_CROSSREF is set by parse_stab_type if this type is 1015*a9fa9459Szrj a cross reference to itself. These are generated by some 1016*a9fa9459Szrj versions of g++. */ 1017*a9fa9459Szrj self_crossref = info->self_crossref; 1018*a9fa9459Szrj 1019*a9fa9459Szrj dtype = debug_tag_type (dhandle, name, dtype); 1020*a9fa9459Szrj if (dtype == DEBUG_TYPE_NULL) 1021*a9fa9459Szrj return FALSE; 1022*a9fa9459Szrj if (slot != NULL) 1023*a9fa9459Szrj *slot = dtype; 1024*a9fa9459Szrj 1025*a9fa9459Szrj /* See if we have a cross reference to this tag which we can now 1026*a9fa9459Szrj fill in. Avoid filling in a cross reference to ourselves, 1027*a9fa9459Szrj because that would lead to circular debugging information. */ 1028*a9fa9459Szrj if (! self_crossref) 1029*a9fa9459Szrj { 1030*a9fa9459Szrj register struct stab_tag **pst; 1031*a9fa9459Szrj 1032*a9fa9459Szrj for (pst = &info->tags; *pst != NULL; pst = &(*pst)->next) 1033*a9fa9459Szrj { 1034*a9fa9459Szrj if ((*pst)->name[0] == name[0] 1035*a9fa9459Szrj && strcmp ((*pst)->name, name) == 0) 1036*a9fa9459Szrj { 1037*a9fa9459Szrj (*pst)->slot = dtype; 1038*a9fa9459Szrj *pst = (*pst)->next; 1039*a9fa9459Szrj break; 1040*a9fa9459Szrj } 1041*a9fa9459Szrj } 1042*a9fa9459Szrj } 1043*a9fa9459Szrj 1044*a9fa9459Szrj if (synonym) 1045*a9fa9459Szrj { 1046*a9fa9459Szrj dtype = debug_name_type (dhandle, name, dtype); 1047*a9fa9459Szrj if (dtype == DEBUG_TYPE_NULL) 1048*a9fa9459Szrj return FALSE; 1049*a9fa9459Szrj 1050*a9fa9459Szrj if (slot != NULL) 1051*a9fa9459Szrj *slot = dtype; 1052*a9fa9459Szrj } 1053*a9fa9459Szrj 1054*a9fa9459Szrj break; 1055*a9fa9459Szrj 1056*a9fa9459Szrj case 'V': 1057*a9fa9459Szrj /* Static symbol of local scope */ 1058*a9fa9459Szrj dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p, 1059*a9fa9459Szrj (debug_type **) NULL); 1060*a9fa9459Szrj if (dtype == DEBUG_TYPE_NULL) 1061*a9fa9459Szrj return FALSE; 1062*a9fa9459Szrj /* FIXME: gdb checks os9k_stabs here. */ 1063*a9fa9459Szrj if (! stab_record_variable (dhandle, info, name, dtype, 1064*a9fa9459Szrj DEBUG_LOCAL_STATIC, value)) 1065*a9fa9459Szrj return FALSE; 1066*a9fa9459Szrj break; 1067*a9fa9459Szrj 1068*a9fa9459Szrj case 'v': 1069*a9fa9459Szrj /* Reference parameter. */ 1070*a9fa9459Szrj dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p, 1071*a9fa9459Szrj (debug_type **) NULL); 1072*a9fa9459Szrj if (dtype == DEBUG_TYPE_NULL) 1073*a9fa9459Szrj return FALSE; 1074*a9fa9459Szrj if (! debug_record_parameter (dhandle, name, dtype, DEBUG_PARM_REFERENCE, 1075*a9fa9459Szrj value)) 1076*a9fa9459Szrj return FALSE; 1077*a9fa9459Szrj break; 1078*a9fa9459Szrj 1079*a9fa9459Szrj case 'a': 1080*a9fa9459Szrj /* Reference parameter which is in a register. */ 1081*a9fa9459Szrj dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p, 1082*a9fa9459Szrj (debug_type **) NULL); 1083*a9fa9459Szrj if (dtype == DEBUG_TYPE_NULL) 1084*a9fa9459Szrj return FALSE; 1085*a9fa9459Szrj if (! debug_record_parameter (dhandle, name, dtype, DEBUG_PARM_REF_REG, 1086*a9fa9459Szrj value)) 1087*a9fa9459Szrj return FALSE; 1088*a9fa9459Szrj break; 1089*a9fa9459Szrj 1090*a9fa9459Szrj case 'X': 1091*a9fa9459Szrj /* This is used by Sun FORTRAN for "function result value". 1092*a9fa9459Szrj Sun claims ("dbx and dbxtool interfaces", 2nd ed) 1093*a9fa9459Szrj that Pascal uses it too, but when I tried it Pascal used 1094*a9fa9459Szrj "x:3" (local symbol) instead. */ 1095*a9fa9459Szrj dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p, 1096*a9fa9459Szrj (debug_type **) NULL); 1097*a9fa9459Szrj if (dtype == DEBUG_TYPE_NULL) 1098*a9fa9459Szrj return FALSE; 1099*a9fa9459Szrj if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_LOCAL, 1100*a9fa9459Szrj value)) 1101*a9fa9459Szrj return FALSE; 1102*a9fa9459Szrj break; 1103*a9fa9459Szrj 1104*a9fa9459Szrj case 'Y': 1105*a9fa9459Szrj /* SUNPro C++ Namespace =Yn0. */ 1106*a9fa9459Szrj /* Skip the namespace mapping, as it is not used now. */ 1107*a9fa9459Szrj if (*(++p) == 'n' && *(++p) == '0') 1108*a9fa9459Szrj { 1109*a9fa9459Szrj /* =Yn0name; */ 1110*a9fa9459Szrj while (*p != ';') 1111*a9fa9459Szrj ++p; 1112*a9fa9459Szrj ++p; 1113*a9fa9459Szrj return TRUE; 1114*a9fa9459Szrj } 1115*a9fa9459Szrj /* TODO SUNPro C++ support: 1116*a9fa9459Szrj Support default arguments after F,P parameters 1117*a9fa9459Szrj Ya = Anonymous unions 1118*a9fa9459Szrj YM,YD = Pointers to class members 1119*a9fa9459Szrj YT,YI = Templates 1120*a9fa9459Szrj YR = Run-time type information (RTTI) */ 1121*a9fa9459Szrj 1122*a9fa9459Szrj /* Fall through. */ 1123*a9fa9459Szrj 1124*a9fa9459Szrj default: 1125*a9fa9459Szrj bad_stab (string); 1126*a9fa9459Szrj return FALSE; 1127*a9fa9459Szrj } 1128*a9fa9459Szrj 1129*a9fa9459Szrj /* FIXME: gdb converts structure values to structure pointers in a 1130*a9fa9459Szrj couple of cases, depending upon the target. */ 1131*a9fa9459Szrj 1132*a9fa9459Szrj return TRUE; 1133*a9fa9459Szrj } 1134*a9fa9459Szrj 1135*a9fa9459Szrj /* Parse a stabs type. The typename argument is non-NULL if this is a 1136*a9fa9459Szrj typedef or a tag definition. The pp argument points to the stab 1137*a9fa9459Szrj string, and is updated. The slotp argument points to a place to 1138*a9fa9459Szrj store the slot used if the type is being defined. */ 1139*a9fa9459Szrj 1140*a9fa9459Szrj static debug_type 1141*a9fa9459Szrj parse_stab_type (void *dhandle, struct stab_handle *info, const char *type_name, const char **pp, debug_type **slotp) 1142*a9fa9459Szrj { 1143*a9fa9459Szrj const char *orig; 1144*a9fa9459Szrj int typenums[2]; 1145*a9fa9459Szrj int size; 1146*a9fa9459Szrj bfd_boolean stringp; 1147*a9fa9459Szrj int descriptor; 1148*a9fa9459Szrj debug_type dtype; 1149*a9fa9459Szrj 1150*a9fa9459Szrj if (slotp != NULL) 1151*a9fa9459Szrj *slotp = NULL; 1152*a9fa9459Szrj 1153*a9fa9459Szrj orig = *pp; 1154*a9fa9459Szrj 1155*a9fa9459Szrj size = -1; 1156*a9fa9459Szrj stringp = FALSE; 1157*a9fa9459Szrj 1158*a9fa9459Szrj info->self_crossref = FALSE; 1159*a9fa9459Szrj 1160*a9fa9459Szrj /* Read type number if present. The type number may be omitted. 1161*a9fa9459Szrj for instance in a two-dimensional array declared with type 1162*a9fa9459Szrj "ar1;1;10;ar1;1;10;4". */ 1163*a9fa9459Szrj if (! ISDIGIT (**pp) && **pp != '(' && **pp != '-') 1164*a9fa9459Szrj { 1165*a9fa9459Szrj /* 'typenums=' not present, type is anonymous. Read and return 1166*a9fa9459Szrj the definition, but don't put it in the type vector. */ 1167*a9fa9459Szrj typenums[0] = typenums[1] = -1; 1168*a9fa9459Szrj } 1169*a9fa9459Szrj else 1170*a9fa9459Szrj { 1171*a9fa9459Szrj if (! parse_stab_type_number (pp, typenums)) 1172*a9fa9459Szrj return DEBUG_TYPE_NULL; 1173*a9fa9459Szrj 1174*a9fa9459Szrj if (**pp != '=') 1175*a9fa9459Szrj /* Type is not being defined here. Either it already 1176*a9fa9459Szrj exists, or this is a forward reference to it. */ 1177*a9fa9459Szrj return stab_find_type (dhandle, info, typenums); 1178*a9fa9459Szrj 1179*a9fa9459Szrj /* Only set the slot if the type is being defined. This means 1180*a9fa9459Szrj that the mapping from type numbers to types will only record 1181*a9fa9459Szrj the name of the typedef which defines a type. If we don't do 1182*a9fa9459Szrj this, then something like 1183*a9fa9459Szrj typedef int foo; 1184*a9fa9459Szrj int i; 1185*a9fa9459Szrj will record that i is of type foo. Unfortunately, stabs 1186*a9fa9459Szrj information is ambiguous about variable types. For this code, 1187*a9fa9459Szrj typedef int foo; 1188*a9fa9459Szrj int i; 1189*a9fa9459Szrj foo j; 1190*a9fa9459Szrj the stabs information records both i and j as having the same 1191*a9fa9459Szrj type. This could be fixed by patching the compiler. */ 1192*a9fa9459Szrj if (slotp != NULL && typenums[0] >= 0 && typenums[1] >= 0) 1193*a9fa9459Szrj *slotp = stab_find_slot (info, typenums); 1194*a9fa9459Szrj 1195*a9fa9459Szrj /* Type is being defined here. */ 1196*a9fa9459Szrj /* Skip the '='. */ 1197*a9fa9459Szrj ++*pp; 1198*a9fa9459Szrj 1199*a9fa9459Szrj while (**pp == '@') 1200*a9fa9459Szrj { 1201*a9fa9459Szrj const char *p = *pp + 1; 1202*a9fa9459Szrj const char *attr; 1203*a9fa9459Szrj 1204*a9fa9459Szrj if (ISDIGIT (*p) || *p == '(' || *p == '-') 1205*a9fa9459Szrj /* Member type. */ 1206*a9fa9459Szrj break; 1207*a9fa9459Szrj 1208*a9fa9459Szrj /* Type attributes. */ 1209*a9fa9459Szrj attr = p; 1210*a9fa9459Szrj 1211*a9fa9459Szrj for (; *p != ';'; ++p) 1212*a9fa9459Szrj { 1213*a9fa9459Szrj if (*p == '\0') 1214*a9fa9459Szrj { 1215*a9fa9459Szrj bad_stab (orig); 1216*a9fa9459Szrj return DEBUG_TYPE_NULL; 1217*a9fa9459Szrj } 1218*a9fa9459Szrj } 1219*a9fa9459Szrj *pp = p + 1; 1220*a9fa9459Szrj 1221*a9fa9459Szrj switch (*attr) 1222*a9fa9459Szrj { 1223*a9fa9459Szrj case 's': 1224*a9fa9459Szrj size = atoi (attr + 1); 1225*a9fa9459Szrj size /= 8; /* Size is in bits. We store it in bytes. */ 1226*a9fa9459Szrj if (size <= 0) 1227*a9fa9459Szrj size = -1; 1228*a9fa9459Szrj break; 1229*a9fa9459Szrj 1230*a9fa9459Szrj case 'S': 1231*a9fa9459Szrj stringp = TRUE; 1232*a9fa9459Szrj break; 1233*a9fa9459Szrj 1234*a9fa9459Szrj default: 1235*a9fa9459Szrj /* Ignore unrecognized type attributes, so future 1236*a9fa9459Szrj compilers can invent new ones. */ 1237*a9fa9459Szrj break; 1238*a9fa9459Szrj } 1239*a9fa9459Szrj } 1240*a9fa9459Szrj } 1241*a9fa9459Szrj 1242*a9fa9459Szrj descriptor = **pp; 1243*a9fa9459Szrj ++*pp; 1244*a9fa9459Szrj 1245*a9fa9459Szrj switch (descriptor) 1246*a9fa9459Szrj { 1247*a9fa9459Szrj case 'x': 1248*a9fa9459Szrj { 1249*a9fa9459Szrj enum debug_type_kind code; 1250*a9fa9459Szrj const char *q1, *q2, *p; 1251*a9fa9459Szrj 1252*a9fa9459Szrj /* A cross reference to another type. */ 1253*a9fa9459Szrj switch (**pp) 1254*a9fa9459Szrj { 1255*a9fa9459Szrj case 's': 1256*a9fa9459Szrj code = DEBUG_KIND_STRUCT; 1257*a9fa9459Szrj break; 1258*a9fa9459Szrj case 'u': 1259*a9fa9459Szrj code = DEBUG_KIND_UNION; 1260*a9fa9459Szrj break; 1261*a9fa9459Szrj case 'e': 1262*a9fa9459Szrj code = DEBUG_KIND_ENUM; 1263*a9fa9459Szrj break; 1264*a9fa9459Szrj default: 1265*a9fa9459Szrj /* Complain and keep going, so compilers can invent new 1266*a9fa9459Szrj cross-reference types. */ 1267*a9fa9459Szrj warn_stab (orig, _("unrecognized cross reference type")); 1268*a9fa9459Szrj code = DEBUG_KIND_STRUCT; 1269*a9fa9459Szrj break; 1270*a9fa9459Szrj } 1271*a9fa9459Szrj ++*pp; 1272*a9fa9459Szrj 1273*a9fa9459Szrj q1 = strchr (*pp, '<'); 1274*a9fa9459Szrj p = strchr (*pp, ':'); 1275*a9fa9459Szrj if (p == NULL) 1276*a9fa9459Szrj { 1277*a9fa9459Szrj bad_stab (orig); 1278*a9fa9459Szrj return DEBUG_TYPE_NULL; 1279*a9fa9459Szrj } 1280*a9fa9459Szrj if (q1 != NULL && p > q1 && p[1] == ':') 1281*a9fa9459Szrj { 1282*a9fa9459Szrj int nest = 0; 1283*a9fa9459Szrj 1284*a9fa9459Szrj for (q2 = q1; *q2 != '\0'; ++q2) 1285*a9fa9459Szrj { 1286*a9fa9459Szrj if (*q2 == '<') 1287*a9fa9459Szrj ++nest; 1288*a9fa9459Szrj else if (*q2 == '>') 1289*a9fa9459Szrj --nest; 1290*a9fa9459Szrj else if (*q2 == ':' && nest == 0) 1291*a9fa9459Szrj break; 1292*a9fa9459Szrj } 1293*a9fa9459Szrj p = q2; 1294*a9fa9459Szrj if (*p != ':') 1295*a9fa9459Szrj { 1296*a9fa9459Szrj bad_stab (orig); 1297*a9fa9459Szrj return DEBUG_TYPE_NULL; 1298*a9fa9459Szrj } 1299*a9fa9459Szrj } 1300*a9fa9459Szrj 1301*a9fa9459Szrj /* Some versions of g++ can emit stabs like 1302*a9fa9459Szrj fleep:T20=xsfleep: 1303*a9fa9459Szrj which define structures in terms of themselves. We need to 1304*a9fa9459Szrj tell the caller to avoid building a circular structure. */ 1305*a9fa9459Szrj if (type_name != NULL 1306*a9fa9459Szrj && strncmp (type_name, *pp, p - *pp) == 0 1307*a9fa9459Szrj && type_name[p - *pp] == '\0') 1308*a9fa9459Szrj info->self_crossref = TRUE; 1309*a9fa9459Szrj 1310*a9fa9459Szrj dtype = stab_find_tagged_type (dhandle, info, *pp, p - *pp, code); 1311*a9fa9459Szrj 1312*a9fa9459Szrj *pp = p + 1; 1313*a9fa9459Szrj } 1314*a9fa9459Szrj break; 1315*a9fa9459Szrj 1316*a9fa9459Szrj case '-': 1317*a9fa9459Szrj case '0': 1318*a9fa9459Szrj case '1': 1319*a9fa9459Szrj case '2': 1320*a9fa9459Szrj case '3': 1321*a9fa9459Szrj case '4': 1322*a9fa9459Szrj case '5': 1323*a9fa9459Szrj case '6': 1324*a9fa9459Szrj case '7': 1325*a9fa9459Szrj case '8': 1326*a9fa9459Szrj case '9': 1327*a9fa9459Szrj case '(': 1328*a9fa9459Szrj { 1329*a9fa9459Szrj const char *hold; 1330*a9fa9459Szrj int xtypenums[2]; 1331*a9fa9459Szrj 1332*a9fa9459Szrj /* This type is defined as another type. */ 1333*a9fa9459Szrj (*pp)--; 1334*a9fa9459Szrj hold = *pp; 1335*a9fa9459Szrj 1336*a9fa9459Szrj /* Peek ahead at the number to detect void. */ 1337*a9fa9459Szrj if (! parse_stab_type_number (pp, xtypenums)) 1338*a9fa9459Szrj return DEBUG_TYPE_NULL; 1339*a9fa9459Szrj 1340*a9fa9459Szrj if (typenums[0] == xtypenums[0] && typenums[1] == xtypenums[1]) 1341*a9fa9459Szrj { 1342*a9fa9459Szrj /* This type is being defined as itself, which means that 1343*a9fa9459Szrj it is void. */ 1344*a9fa9459Szrj dtype = debug_make_void_type (dhandle); 1345*a9fa9459Szrj } 1346*a9fa9459Szrj else 1347*a9fa9459Szrj { 1348*a9fa9459Szrj *pp = hold; 1349*a9fa9459Szrj 1350*a9fa9459Szrj /* Go back to the number and have parse_stab_type get it. 1351*a9fa9459Szrj This means that we can deal with something like 1352*a9fa9459Szrj t(1,2)=(3,4)=... which the Lucid compiler uses. */ 1353*a9fa9459Szrj dtype = parse_stab_type (dhandle, info, (const char *) NULL, 1354*a9fa9459Szrj pp, (debug_type **) NULL); 1355*a9fa9459Szrj if (dtype == DEBUG_TYPE_NULL) 1356*a9fa9459Szrj return DEBUG_TYPE_NULL; 1357*a9fa9459Szrj } 1358*a9fa9459Szrj 1359*a9fa9459Szrj if (typenums[0] != -1) 1360*a9fa9459Szrj { 1361*a9fa9459Szrj if (! stab_record_type (dhandle, info, typenums, dtype)) 1362*a9fa9459Szrj return DEBUG_TYPE_NULL; 1363*a9fa9459Szrj } 1364*a9fa9459Szrj 1365*a9fa9459Szrj break; 1366*a9fa9459Szrj } 1367*a9fa9459Szrj 1368*a9fa9459Szrj case '*': 1369*a9fa9459Szrj dtype = debug_make_pointer_type (dhandle, 1370*a9fa9459Szrj parse_stab_type (dhandle, info, 1371*a9fa9459Szrj (const char *) NULL, 1372*a9fa9459Szrj pp, 1373*a9fa9459Szrj (debug_type **) NULL)); 1374*a9fa9459Szrj break; 1375*a9fa9459Szrj 1376*a9fa9459Szrj case '&': 1377*a9fa9459Szrj /* Reference to another type. */ 1378*a9fa9459Szrj dtype = (debug_make_reference_type 1379*a9fa9459Szrj (dhandle, 1380*a9fa9459Szrj parse_stab_type (dhandle, info, (const char *) NULL, pp, 1381*a9fa9459Szrj (debug_type **) NULL))); 1382*a9fa9459Szrj break; 1383*a9fa9459Szrj 1384*a9fa9459Szrj case 'f': 1385*a9fa9459Szrj /* Function returning another type. */ 1386*a9fa9459Szrj /* FIXME: gdb checks os9k_stabs here. */ 1387*a9fa9459Szrj dtype = (debug_make_function_type 1388*a9fa9459Szrj (dhandle, 1389*a9fa9459Szrj parse_stab_type (dhandle, info, (const char *) NULL, pp, 1390*a9fa9459Szrj (debug_type **) NULL), 1391*a9fa9459Szrj (debug_type *) NULL, FALSE)); 1392*a9fa9459Szrj break; 1393*a9fa9459Szrj 1394*a9fa9459Szrj case 'k': 1395*a9fa9459Szrj /* Const qualifier on some type (Sun). */ 1396*a9fa9459Szrj /* FIXME: gdb accepts 'c' here if os9k_stabs. */ 1397*a9fa9459Szrj dtype = debug_make_const_type (dhandle, 1398*a9fa9459Szrj parse_stab_type (dhandle, info, 1399*a9fa9459Szrj (const char *) NULL, 1400*a9fa9459Szrj pp, 1401*a9fa9459Szrj (debug_type **) NULL)); 1402*a9fa9459Szrj break; 1403*a9fa9459Szrj 1404*a9fa9459Szrj case 'B': 1405*a9fa9459Szrj /* Volatile qual on some type (Sun). */ 1406*a9fa9459Szrj /* FIXME: gdb accepts 'i' here if os9k_stabs. */ 1407*a9fa9459Szrj dtype = (debug_make_volatile_type 1408*a9fa9459Szrj (dhandle, 1409*a9fa9459Szrj parse_stab_type (dhandle, info, (const char *) NULL, pp, 1410*a9fa9459Szrj (debug_type **) NULL))); 1411*a9fa9459Szrj break; 1412*a9fa9459Szrj 1413*a9fa9459Szrj case '@': 1414*a9fa9459Szrj /* Offset (class & variable) type. This is used for a pointer 1415*a9fa9459Szrj relative to an object. */ 1416*a9fa9459Szrj { 1417*a9fa9459Szrj debug_type domain; 1418*a9fa9459Szrj debug_type memtype; 1419*a9fa9459Szrj 1420*a9fa9459Szrj /* Member type. */ 1421*a9fa9459Szrj 1422*a9fa9459Szrj domain = parse_stab_type (dhandle, info, (const char *) NULL, pp, 1423*a9fa9459Szrj (debug_type **) NULL); 1424*a9fa9459Szrj if (domain == DEBUG_TYPE_NULL) 1425*a9fa9459Szrj return DEBUG_TYPE_NULL; 1426*a9fa9459Szrj 1427*a9fa9459Szrj if (**pp != ',') 1428*a9fa9459Szrj { 1429*a9fa9459Szrj bad_stab (orig); 1430*a9fa9459Szrj return DEBUG_TYPE_NULL; 1431*a9fa9459Szrj } 1432*a9fa9459Szrj ++*pp; 1433*a9fa9459Szrj 1434*a9fa9459Szrj memtype = parse_stab_type (dhandle, info, (const char *) NULL, pp, 1435*a9fa9459Szrj (debug_type **) NULL); 1436*a9fa9459Szrj if (memtype == DEBUG_TYPE_NULL) 1437*a9fa9459Szrj return DEBUG_TYPE_NULL; 1438*a9fa9459Szrj 1439*a9fa9459Szrj dtype = debug_make_offset_type (dhandle, domain, memtype); 1440*a9fa9459Szrj } 1441*a9fa9459Szrj break; 1442*a9fa9459Szrj 1443*a9fa9459Szrj case '#': 1444*a9fa9459Szrj /* Method (class & fn) type. */ 1445*a9fa9459Szrj if (**pp == '#') 1446*a9fa9459Szrj { 1447*a9fa9459Szrj debug_type return_type; 1448*a9fa9459Szrj 1449*a9fa9459Szrj ++*pp; 1450*a9fa9459Szrj return_type = parse_stab_type (dhandle, info, (const char *) NULL, 1451*a9fa9459Szrj pp, (debug_type **) NULL); 1452*a9fa9459Szrj if (return_type == DEBUG_TYPE_NULL) 1453*a9fa9459Szrj return DEBUG_TYPE_NULL; 1454*a9fa9459Szrj if (**pp != ';') 1455*a9fa9459Szrj { 1456*a9fa9459Szrj bad_stab (orig); 1457*a9fa9459Szrj return DEBUG_TYPE_NULL; 1458*a9fa9459Szrj } 1459*a9fa9459Szrj ++*pp; 1460*a9fa9459Szrj dtype = debug_make_method_type (dhandle, return_type, 1461*a9fa9459Szrj DEBUG_TYPE_NULL, 1462*a9fa9459Szrj (debug_type *) NULL, FALSE); 1463*a9fa9459Szrj } 1464*a9fa9459Szrj else 1465*a9fa9459Szrj { 1466*a9fa9459Szrj debug_type domain; 1467*a9fa9459Szrj debug_type return_type; 1468*a9fa9459Szrj debug_type *args; 1469*a9fa9459Szrj unsigned int n; 1470*a9fa9459Szrj unsigned int alloc; 1471*a9fa9459Szrj bfd_boolean varargs; 1472*a9fa9459Szrj 1473*a9fa9459Szrj domain = parse_stab_type (dhandle, info, (const char *) NULL, 1474*a9fa9459Szrj pp, (debug_type **) NULL); 1475*a9fa9459Szrj if (domain == DEBUG_TYPE_NULL) 1476*a9fa9459Szrj return DEBUG_TYPE_NULL; 1477*a9fa9459Szrj 1478*a9fa9459Szrj if (**pp != ',') 1479*a9fa9459Szrj { 1480*a9fa9459Szrj bad_stab (orig); 1481*a9fa9459Szrj return DEBUG_TYPE_NULL; 1482*a9fa9459Szrj } 1483*a9fa9459Szrj ++*pp; 1484*a9fa9459Szrj 1485*a9fa9459Szrj return_type = parse_stab_type (dhandle, info, (const char *) NULL, 1486*a9fa9459Szrj pp, (debug_type **) NULL); 1487*a9fa9459Szrj if (return_type == DEBUG_TYPE_NULL) 1488*a9fa9459Szrj return DEBUG_TYPE_NULL; 1489*a9fa9459Szrj 1490*a9fa9459Szrj alloc = 10; 1491*a9fa9459Szrj args = (debug_type *) xmalloc (alloc * sizeof *args); 1492*a9fa9459Szrj n = 0; 1493*a9fa9459Szrj while (**pp != ';') 1494*a9fa9459Szrj { 1495*a9fa9459Szrj if (**pp != ',') 1496*a9fa9459Szrj { 1497*a9fa9459Szrj bad_stab (orig); 1498*a9fa9459Szrj return DEBUG_TYPE_NULL; 1499*a9fa9459Szrj } 1500*a9fa9459Szrj ++*pp; 1501*a9fa9459Szrj 1502*a9fa9459Szrj if (n + 1 >= alloc) 1503*a9fa9459Szrj { 1504*a9fa9459Szrj alloc += 10; 1505*a9fa9459Szrj args = ((debug_type *) 1506*a9fa9459Szrj xrealloc (args, alloc * sizeof *args)); 1507*a9fa9459Szrj } 1508*a9fa9459Szrj 1509*a9fa9459Szrj args[n] = parse_stab_type (dhandle, info, (const char *) NULL, 1510*a9fa9459Szrj pp, (debug_type **) NULL); 1511*a9fa9459Szrj if (args[n] == DEBUG_TYPE_NULL) 1512*a9fa9459Szrj return DEBUG_TYPE_NULL; 1513*a9fa9459Szrj ++n; 1514*a9fa9459Szrj } 1515*a9fa9459Szrj ++*pp; 1516*a9fa9459Szrj 1517*a9fa9459Szrj /* If the last type is not void, then this function takes a 1518*a9fa9459Szrj variable number of arguments. Otherwise, we must strip 1519*a9fa9459Szrj the void type. */ 1520*a9fa9459Szrj if (n == 0 1521*a9fa9459Szrj || debug_get_type_kind (dhandle, args[n - 1]) != DEBUG_KIND_VOID) 1522*a9fa9459Szrj varargs = TRUE; 1523*a9fa9459Szrj else 1524*a9fa9459Szrj { 1525*a9fa9459Szrj --n; 1526*a9fa9459Szrj varargs = FALSE; 1527*a9fa9459Szrj } 1528*a9fa9459Szrj 1529*a9fa9459Szrj args[n] = DEBUG_TYPE_NULL; 1530*a9fa9459Szrj 1531*a9fa9459Szrj dtype = debug_make_method_type (dhandle, return_type, domain, args, 1532*a9fa9459Szrj varargs); 1533*a9fa9459Szrj } 1534*a9fa9459Szrj break; 1535*a9fa9459Szrj 1536*a9fa9459Szrj case 'r': 1537*a9fa9459Szrj /* Range type. */ 1538*a9fa9459Szrj dtype = parse_stab_range_type (dhandle, info, type_name, pp, typenums); 1539*a9fa9459Szrj break; 1540*a9fa9459Szrj 1541*a9fa9459Szrj case 'b': 1542*a9fa9459Szrj /* FIXME: gdb checks os9k_stabs here. */ 1543*a9fa9459Szrj /* Sun ACC builtin int type. */ 1544*a9fa9459Szrj dtype = parse_stab_sun_builtin_type (dhandle, pp); 1545*a9fa9459Szrj break; 1546*a9fa9459Szrj 1547*a9fa9459Szrj case 'R': 1548*a9fa9459Szrj /* Sun ACC builtin float type. */ 1549*a9fa9459Szrj dtype = parse_stab_sun_floating_type (dhandle, pp); 1550*a9fa9459Szrj break; 1551*a9fa9459Szrj 1552*a9fa9459Szrj case 'e': 1553*a9fa9459Szrj /* Enumeration type. */ 1554*a9fa9459Szrj dtype = parse_stab_enum_type (dhandle, pp); 1555*a9fa9459Szrj break; 1556*a9fa9459Szrj 1557*a9fa9459Szrj case 's': 1558*a9fa9459Szrj case 'u': 1559*a9fa9459Szrj /* Struct or union type. */ 1560*a9fa9459Szrj dtype = parse_stab_struct_type (dhandle, info, type_name, pp, 1561*a9fa9459Szrj descriptor == 's', typenums); 1562*a9fa9459Szrj break; 1563*a9fa9459Szrj 1564*a9fa9459Szrj case 'a': 1565*a9fa9459Szrj /* Array type. */ 1566*a9fa9459Szrj if (**pp != 'r') 1567*a9fa9459Szrj { 1568*a9fa9459Szrj bad_stab (orig); 1569*a9fa9459Szrj return DEBUG_TYPE_NULL; 1570*a9fa9459Szrj } 1571*a9fa9459Szrj ++*pp; 1572*a9fa9459Szrj 1573*a9fa9459Szrj dtype = parse_stab_array_type (dhandle, info, pp, stringp); 1574*a9fa9459Szrj break; 1575*a9fa9459Szrj 1576*a9fa9459Szrj case 'S': 1577*a9fa9459Szrj dtype = debug_make_set_type (dhandle, 1578*a9fa9459Szrj parse_stab_type (dhandle, info, 1579*a9fa9459Szrj (const char *) NULL, 1580*a9fa9459Szrj pp, 1581*a9fa9459Szrj (debug_type **) NULL), 1582*a9fa9459Szrj stringp); 1583*a9fa9459Szrj break; 1584*a9fa9459Szrj 1585*a9fa9459Szrj default: 1586*a9fa9459Szrj bad_stab (orig); 1587*a9fa9459Szrj return DEBUG_TYPE_NULL; 1588*a9fa9459Szrj } 1589*a9fa9459Szrj 1590*a9fa9459Szrj if (dtype == DEBUG_TYPE_NULL) 1591*a9fa9459Szrj return DEBUG_TYPE_NULL; 1592*a9fa9459Szrj 1593*a9fa9459Szrj if (typenums[0] != -1) 1594*a9fa9459Szrj { 1595*a9fa9459Szrj if (! stab_record_type (dhandle, info, typenums, dtype)) 1596*a9fa9459Szrj return DEBUG_TYPE_NULL; 1597*a9fa9459Szrj } 1598*a9fa9459Szrj 1599*a9fa9459Szrj if (size != -1) 1600*a9fa9459Szrj { 1601*a9fa9459Szrj if (! debug_record_type_size (dhandle, dtype, (unsigned int) size)) 1602*a9fa9459Szrj return DEBUG_TYPE_NULL; 1603*a9fa9459Szrj } 1604*a9fa9459Szrj 1605*a9fa9459Szrj return dtype; 1606*a9fa9459Szrj } 1607*a9fa9459Szrj 1608*a9fa9459Szrj /* Read a number by which a type is referred to in dbx data, or 1609*a9fa9459Szrj perhaps read a pair (FILENUM, TYPENUM) in parentheses. Just a 1610*a9fa9459Szrj single number N is equivalent to (0,N). Return the two numbers by 1611*a9fa9459Szrj storing them in the vector TYPENUMS. */ 1612*a9fa9459Szrj 1613*a9fa9459Szrj static bfd_boolean 1614*a9fa9459Szrj parse_stab_type_number (const char **pp, int *typenums) 1615*a9fa9459Szrj { 1616*a9fa9459Szrj const char *orig; 1617*a9fa9459Szrj 1618*a9fa9459Szrj orig = *pp; 1619*a9fa9459Szrj 1620*a9fa9459Szrj if (**pp != '(') 1621*a9fa9459Szrj { 1622*a9fa9459Szrj typenums[0] = 0; 1623*a9fa9459Szrj typenums[1] = (int) parse_number (pp, (bfd_boolean *) NULL); 1624*a9fa9459Szrj } 1625*a9fa9459Szrj else 1626*a9fa9459Szrj { 1627*a9fa9459Szrj ++*pp; 1628*a9fa9459Szrj typenums[0] = (int) parse_number (pp, (bfd_boolean *) NULL); 1629*a9fa9459Szrj if (**pp != ',') 1630*a9fa9459Szrj { 1631*a9fa9459Szrj bad_stab (orig); 1632*a9fa9459Szrj return FALSE; 1633*a9fa9459Szrj } 1634*a9fa9459Szrj ++*pp; 1635*a9fa9459Szrj typenums[1] = (int) parse_number (pp, (bfd_boolean *) NULL); 1636*a9fa9459Szrj if (**pp != ')') 1637*a9fa9459Szrj { 1638*a9fa9459Szrj bad_stab (orig); 1639*a9fa9459Szrj return FALSE; 1640*a9fa9459Szrj } 1641*a9fa9459Szrj ++*pp; 1642*a9fa9459Szrj } 1643*a9fa9459Szrj 1644*a9fa9459Szrj return TRUE; 1645*a9fa9459Szrj } 1646*a9fa9459Szrj 1647*a9fa9459Szrj /* Parse a range type. */ 1648*a9fa9459Szrj 1649*a9fa9459Szrj static debug_type 1650*a9fa9459Szrj parse_stab_range_type (void *dhandle, struct stab_handle *info, const char *type_name, const char **pp, const int *typenums) 1651*a9fa9459Szrj { 1652*a9fa9459Szrj const char *orig; 1653*a9fa9459Szrj int rangenums[2]; 1654*a9fa9459Szrj bfd_boolean self_subrange; 1655*a9fa9459Szrj debug_type index_type; 1656*a9fa9459Szrj const char *s2, *s3; 1657*a9fa9459Szrj bfd_signed_vma n2, n3; 1658*a9fa9459Szrj bfd_boolean ov2, ov3; 1659*a9fa9459Szrj 1660*a9fa9459Szrj orig = *pp; 1661*a9fa9459Szrj 1662*a9fa9459Szrj index_type = DEBUG_TYPE_NULL; 1663*a9fa9459Szrj 1664*a9fa9459Szrj /* First comes a type we are a subrange of. 1665*a9fa9459Szrj In C it is usually 0, 1 or the type being defined. */ 1666*a9fa9459Szrj if (! parse_stab_type_number (pp, rangenums)) 1667*a9fa9459Szrj return DEBUG_TYPE_NULL; 1668*a9fa9459Szrj 1669*a9fa9459Szrj self_subrange = (rangenums[0] == typenums[0] 1670*a9fa9459Szrj && rangenums[1] == typenums[1]); 1671*a9fa9459Szrj 1672*a9fa9459Szrj if (**pp == '=') 1673*a9fa9459Szrj { 1674*a9fa9459Szrj *pp = orig; 1675*a9fa9459Szrj index_type = parse_stab_type (dhandle, info, (const char *) NULL, 1676*a9fa9459Szrj pp, (debug_type **) NULL); 1677*a9fa9459Szrj if (index_type == DEBUG_TYPE_NULL) 1678*a9fa9459Szrj return DEBUG_TYPE_NULL; 1679*a9fa9459Szrj } 1680*a9fa9459Szrj 1681*a9fa9459Szrj if (**pp == ';') 1682*a9fa9459Szrj ++*pp; 1683*a9fa9459Szrj 1684*a9fa9459Szrj /* The remaining two operands are usually lower and upper bounds of 1685*a9fa9459Szrj the range. But in some special cases they mean something else. */ 1686*a9fa9459Szrj s2 = *pp; 1687*a9fa9459Szrj n2 = parse_number (pp, &ov2); 1688*a9fa9459Szrj if (**pp != ';') 1689*a9fa9459Szrj { 1690*a9fa9459Szrj bad_stab (orig); 1691*a9fa9459Szrj return DEBUG_TYPE_NULL; 1692*a9fa9459Szrj } 1693*a9fa9459Szrj ++*pp; 1694*a9fa9459Szrj 1695*a9fa9459Szrj s3 = *pp; 1696*a9fa9459Szrj n3 = parse_number (pp, &ov3); 1697*a9fa9459Szrj if (**pp != ';') 1698*a9fa9459Szrj { 1699*a9fa9459Szrj bad_stab (orig); 1700*a9fa9459Szrj return DEBUG_TYPE_NULL; 1701*a9fa9459Szrj } 1702*a9fa9459Szrj ++*pp; 1703*a9fa9459Szrj 1704*a9fa9459Szrj if (ov2 || ov3) 1705*a9fa9459Szrj { 1706*a9fa9459Szrj /* gcc will emit range stabs for long long types. Handle this 1707*a9fa9459Szrj as a special case. FIXME: This needs to be more general. */ 1708*a9fa9459Szrj #define LLLOW "01000000000000000000000;" 1709*a9fa9459Szrj #define LLHIGH "0777777777777777777777;" 1710*a9fa9459Szrj #define ULLHIGH "01777777777777777777777;" 1711*a9fa9459Szrj if (index_type == DEBUG_TYPE_NULL) 1712*a9fa9459Szrj { 1713*a9fa9459Szrj if (CONST_STRNEQ (s2, LLLOW) 1714*a9fa9459Szrj && CONST_STRNEQ (s3, LLHIGH)) 1715*a9fa9459Szrj return debug_make_int_type (dhandle, 8, FALSE); 1716*a9fa9459Szrj if (! ov2 1717*a9fa9459Szrj && n2 == 0 1718*a9fa9459Szrj && CONST_STRNEQ (s3, ULLHIGH)) 1719*a9fa9459Szrj return debug_make_int_type (dhandle, 8, TRUE); 1720*a9fa9459Szrj } 1721*a9fa9459Szrj 1722*a9fa9459Szrj warn_stab (orig, _("numeric overflow")); 1723*a9fa9459Szrj } 1724*a9fa9459Szrj 1725*a9fa9459Szrj if (index_type == DEBUG_TYPE_NULL) 1726*a9fa9459Szrj { 1727*a9fa9459Szrj /* A type defined as a subrange of itself, with both bounds 0, 1728*a9fa9459Szrj is void. */ 1729*a9fa9459Szrj if (self_subrange && n2 == 0 && n3 == 0) 1730*a9fa9459Szrj return debug_make_void_type (dhandle); 1731*a9fa9459Szrj 1732*a9fa9459Szrj /* A type defined as a subrange of itself, with n2 positive and 1733*a9fa9459Szrj n3 zero, is a complex type, and n2 is the number of bytes. */ 1734*a9fa9459Szrj if (self_subrange && n3 == 0 && n2 > 0) 1735*a9fa9459Szrj return debug_make_complex_type (dhandle, n2); 1736*a9fa9459Szrj 1737*a9fa9459Szrj /* If n3 is zero and n2 is positive, this is a floating point 1738*a9fa9459Szrj type, and n2 is the number of bytes. */ 1739*a9fa9459Szrj if (n3 == 0 && n2 > 0) 1740*a9fa9459Szrj return debug_make_float_type (dhandle, n2); 1741*a9fa9459Szrj 1742*a9fa9459Szrj /* If the upper bound is -1, this is an unsigned int. */ 1743*a9fa9459Szrj if (n2 == 0 && n3 == -1) 1744*a9fa9459Szrj { 1745*a9fa9459Szrj /* When gcc is used with -gstabs, but not -gstabs+, it will emit 1746*a9fa9459Szrj long long int:t6=r1;0;-1; 1747*a9fa9459Szrj long long unsigned int:t7=r1;0;-1; 1748*a9fa9459Szrj We hack here to handle this reasonably. */ 1749*a9fa9459Szrj if (type_name != NULL) 1750*a9fa9459Szrj { 1751*a9fa9459Szrj if (strcmp (type_name, "long long int") == 0) 1752*a9fa9459Szrj return debug_make_int_type (dhandle, 8, FALSE); 1753*a9fa9459Szrj else if (strcmp (type_name, "long long unsigned int") == 0) 1754*a9fa9459Szrj return debug_make_int_type (dhandle, 8, TRUE); 1755*a9fa9459Szrj } 1756*a9fa9459Szrj /* FIXME: The size here really depends upon the target. */ 1757*a9fa9459Szrj return debug_make_int_type (dhandle, 4, TRUE); 1758*a9fa9459Szrj } 1759*a9fa9459Szrj 1760*a9fa9459Szrj /* A range of 0 to 127 is char. */ 1761*a9fa9459Szrj if (self_subrange && n2 == 0 && n3 == 127) 1762*a9fa9459Szrj return debug_make_int_type (dhandle, 1, FALSE); 1763*a9fa9459Szrj 1764*a9fa9459Szrj /* FIXME: gdb checks for the language CHILL here. */ 1765*a9fa9459Szrj 1766*a9fa9459Szrj if (n2 == 0) 1767*a9fa9459Szrj { 1768*a9fa9459Szrj if (n3 < 0) 1769*a9fa9459Szrj return debug_make_int_type (dhandle, - n3, TRUE); 1770*a9fa9459Szrj else if (n3 == 0xff) 1771*a9fa9459Szrj return debug_make_int_type (dhandle, 1, TRUE); 1772*a9fa9459Szrj else if (n3 == 0xffff) 1773*a9fa9459Szrj return debug_make_int_type (dhandle, 2, TRUE); 1774*a9fa9459Szrj else if (n3 == (bfd_signed_vma) 0xffffffff) 1775*a9fa9459Szrj return debug_make_int_type (dhandle, 4, TRUE); 1776*a9fa9459Szrj #ifdef BFD64 1777*a9fa9459Szrj else if (n3 == (bfd_signed_vma) 0xffffffffffffffffLL) 1778*a9fa9459Szrj return debug_make_int_type (dhandle, 8, TRUE); 1779*a9fa9459Szrj #endif 1780*a9fa9459Szrj } 1781*a9fa9459Szrj else if (n3 == 0 1782*a9fa9459Szrj && n2 < 0 1783*a9fa9459Szrj && (self_subrange || n2 == -8)) 1784*a9fa9459Szrj return debug_make_int_type (dhandle, - n2, TRUE); 1785*a9fa9459Szrj else if (n2 == - n3 - 1 || n2 == n3 + 1) 1786*a9fa9459Szrj { 1787*a9fa9459Szrj if (n3 == 0x7f) 1788*a9fa9459Szrj return debug_make_int_type (dhandle, 1, FALSE); 1789*a9fa9459Szrj else if (n3 == 0x7fff) 1790*a9fa9459Szrj return debug_make_int_type (dhandle, 2, FALSE); 1791*a9fa9459Szrj else if (n3 == 0x7fffffff) 1792*a9fa9459Szrj return debug_make_int_type (dhandle, 4, FALSE); 1793*a9fa9459Szrj #ifdef BFD64 1794*a9fa9459Szrj else if (n3 == ((((bfd_vma) 0x7fffffff) << 32) | 0xffffffff)) 1795*a9fa9459Szrj return debug_make_int_type (dhandle, 8, FALSE); 1796*a9fa9459Szrj #endif 1797*a9fa9459Szrj } 1798*a9fa9459Szrj } 1799*a9fa9459Szrj 1800*a9fa9459Szrj /* At this point I don't have the faintest idea how to deal with a 1801*a9fa9459Szrj self_subrange type; I'm going to assume that this is used as an 1802*a9fa9459Szrj idiom, and that all of them are special cases. So . . . */ 1803*a9fa9459Szrj if (self_subrange) 1804*a9fa9459Szrj { 1805*a9fa9459Szrj bad_stab (orig); 1806*a9fa9459Szrj return DEBUG_TYPE_NULL; 1807*a9fa9459Szrj } 1808*a9fa9459Szrj 1809*a9fa9459Szrj index_type = stab_find_type (dhandle, info, rangenums); 1810*a9fa9459Szrj if (index_type == DEBUG_TYPE_NULL) 1811*a9fa9459Szrj { 1812*a9fa9459Szrj /* Does this actually ever happen? Is that why we are worrying 1813*a9fa9459Szrj about dealing with it rather than just calling error_type? */ 1814*a9fa9459Szrj warn_stab (orig, _("missing index type")); 1815*a9fa9459Szrj index_type = debug_make_int_type (dhandle, 4, FALSE); 1816*a9fa9459Szrj } 1817*a9fa9459Szrj 1818*a9fa9459Szrj return debug_make_range_type (dhandle, index_type, n2, n3); 1819*a9fa9459Szrj } 1820*a9fa9459Szrj 1821*a9fa9459Szrj /* Sun's ACC uses a somewhat saner method for specifying the builtin 1822*a9fa9459Szrj typedefs in every file (for int, long, etc): 1823*a9fa9459Szrj 1824*a9fa9459Szrj type = b <signed> <width>; <offset>; <nbits> 1825*a9fa9459Szrj signed = u or s. Possible c in addition to u or s (for char?). 1826*a9fa9459Szrj offset = offset from high order bit to start bit of type. 1827*a9fa9459Szrj width is # bytes in object of this type, nbits is # bits in type. 1828*a9fa9459Szrj 1829*a9fa9459Szrj The width/offset stuff appears to be for small objects stored in 1830*a9fa9459Szrj larger ones (e.g. `shorts' in `int' registers). We ignore it for now, 1831*a9fa9459Szrj FIXME. */ 1832*a9fa9459Szrj 1833*a9fa9459Szrj static debug_type 1834*a9fa9459Szrj parse_stab_sun_builtin_type (void *dhandle, const char **pp) 1835*a9fa9459Szrj { 1836*a9fa9459Szrj const char *orig; 1837*a9fa9459Szrj bfd_boolean unsignedp; 1838*a9fa9459Szrj bfd_vma bits; 1839*a9fa9459Szrj 1840*a9fa9459Szrj orig = *pp; 1841*a9fa9459Szrj 1842*a9fa9459Szrj switch (**pp) 1843*a9fa9459Szrj { 1844*a9fa9459Szrj case 's': 1845*a9fa9459Szrj unsignedp = FALSE; 1846*a9fa9459Szrj break; 1847*a9fa9459Szrj case 'u': 1848*a9fa9459Szrj unsignedp = TRUE; 1849*a9fa9459Szrj break; 1850*a9fa9459Szrj default: 1851*a9fa9459Szrj bad_stab (orig); 1852*a9fa9459Szrj return DEBUG_TYPE_NULL; 1853*a9fa9459Szrj } 1854*a9fa9459Szrj ++*pp; 1855*a9fa9459Szrj 1856*a9fa9459Szrj /* OpenSolaris source code indicates that one of "cbv" characters 1857*a9fa9459Szrj can come next and specify the intrinsic 'iformat' encoding. 1858*a9fa9459Szrj 'c' is character encoding, 'b' is boolean encoding, and 'v' is 1859*a9fa9459Szrj varargs encoding. This field can be safely ignored because 1860*a9fa9459Szrj the type of the field is determined from the bitwidth extracted 1861*a9fa9459Szrj below. */ 1862*a9fa9459Szrj if (**pp == 'c' || **pp == 'b' || **pp == 'v') 1863*a9fa9459Szrj ++*pp; 1864*a9fa9459Szrj 1865*a9fa9459Szrj /* The first number appears to be the number of bytes occupied 1866*a9fa9459Szrj by this type, except that unsigned short is 4 instead of 2. 1867*a9fa9459Szrj Since this information is redundant with the third number, 1868*a9fa9459Szrj we will ignore it. */ 1869*a9fa9459Szrj (void) parse_number (pp, (bfd_boolean *) NULL); 1870*a9fa9459Szrj if (**pp != ';') 1871*a9fa9459Szrj { 1872*a9fa9459Szrj bad_stab (orig); 1873*a9fa9459Szrj return DEBUG_TYPE_NULL; 1874*a9fa9459Szrj } 1875*a9fa9459Szrj ++*pp; 1876*a9fa9459Szrj 1877*a9fa9459Szrj /* The second number is always 0, so ignore it too. */ 1878*a9fa9459Szrj (void) parse_number (pp, (bfd_boolean *) NULL); 1879*a9fa9459Szrj if (**pp != ';') 1880*a9fa9459Szrj { 1881*a9fa9459Szrj bad_stab (orig); 1882*a9fa9459Szrj return DEBUG_TYPE_NULL; 1883*a9fa9459Szrj } 1884*a9fa9459Szrj ++*pp; 1885*a9fa9459Szrj 1886*a9fa9459Szrj /* The third number is the number of bits for this type. */ 1887*a9fa9459Szrj bits = parse_number (pp, (bfd_boolean *) NULL); 1888*a9fa9459Szrj 1889*a9fa9459Szrj /* The type *should* end with a semicolon. If it are embedded 1890*a9fa9459Szrj in a larger type the semicolon may be the only way to know where 1891*a9fa9459Szrj the type ends. If this type is at the end of the stabstring we 1892*a9fa9459Szrj can deal with the omitted semicolon (but we don't have to like 1893*a9fa9459Szrj it). Don't bother to complain(), Sun's compiler omits the semicolon 1894*a9fa9459Szrj for "void". */ 1895*a9fa9459Szrj if (**pp == ';') 1896*a9fa9459Szrj ++*pp; 1897*a9fa9459Szrj 1898*a9fa9459Szrj if (bits == 0) 1899*a9fa9459Szrj return debug_make_void_type (dhandle); 1900*a9fa9459Szrj 1901*a9fa9459Szrj return debug_make_int_type (dhandle, bits / 8, unsignedp); 1902*a9fa9459Szrj } 1903*a9fa9459Szrj 1904*a9fa9459Szrj /* Parse a builtin floating type generated by the Sun compiler. */ 1905*a9fa9459Szrj 1906*a9fa9459Szrj static debug_type 1907*a9fa9459Szrj parse_stab_sun_floating_type (void *dhandle, const char **pp) 1908*a9fa9459Szrj { 1909*a9fa9459Szrj const char *orig; 1910*a9fa9459Szrj bfd_vma details; 1911*a9fa9459Szrj bfd_vma bytes; 1912*a9fa9459Szrj 1913*a9fa9459Szrj orig = *pp; 1914*a9fa9459Szrj 1915*a9fa9459Szrj /* The first number has more details about the type, for example 1916*a9fa9459Szrj FN_COMPLEX. */ 1917*a9fa9459Szrj details = parse_number (pp, (bfd_boolean *) NULL); 1918*a9fa9459Szrj if (**pp != ';') 1919*a9fa9459Szrj { 1920*a9fa9459Szrj bad_stab (orig); 1921*a9fa9459Szrj return DEBUG_TYPE_NULL; 1922*a9fa9459Szrj } 1923*a9fa9459Szrj 1924*a9fa9459Szrj /* The second number is the number of bytes occupied by this type */ 1925*a9fa9459Szrj bytes = parse_number (pp, (bfd_boolean *) NULL); 1926*a9fa9459Szrj if (**pp != ';') 1927*a9fa9459Szrj { 1928*a9fa9459Szrj bad_stab (orig); 1929*a9fa9459Szrj return DEBUG_TYPE_NULL; 1930*a9fa9459Szrj } 1931*a9fa9459Szrj 1932*a9fa9459Szrj if (details == NF_COMPLEX 1933*a9fa9459Szrj || details == NF_COMPLEX16 1934*a9fa9459Szrj || details == NF_COMPLEX32) 1935*a9fa9459Szrj return debug_make_complex_type (dhandle, bytes); 1936*a9fa9459Szrj 1937*a9fa9459Szrj return debug_make_float_type (dhandle, bytes); 1938*a9fa9459Szrj } 1939*a9fa9459Szrj 1940*a9fa9459Szrj /* Handle an enum type. */ 1941*a9fa9459Szrj 1942*a9fa9459Szrj static debug_type 1943*a9fa9459Szrj parse_stab_enum_type (void *dhandle, const char **pp) 1944*a9fa9459Szrj { 1945*a9fa9459Szrj const char *orig; 1946*a9fa9459Szrj const char **names; 1947*a9fa9459Szrj bfd_signed_vma *values; 1948*a9fa9459Szrj unsigned int n; 1949*a9fa9459Szrj unsigned int alloc; 1950*a9fa9459Szrj 1951*a9fa9459Szrj orig = *pp; 1952*a9fa9459Szrj 1953*a9fa9459Szrj /* FIXME: gdb checks os9k_stabs here. */ 1954*a9fa9459Szrj 1955*a9fa9459Szrj /* The aix4 compiler emits an extra field before the enum members; 1956*a9fa9459Szrj my guess is it's a type of some sort. Just ignore it. */ 1957*a9fa9459Szrj if (**pp == '-') 1958*a9fa9459Szrj { 1959*a9fa9459Szrj while (**pp != ':') 1960*a9fa9459Szrj ++*pp; 1961*a9fa9459Szrj ++*pp; 1962*a9fa9459Szrj } 1963*a9fa9459Szrj 1964*a9fa9459Szrj /* Read the value-names and their values. 1965*a9fa9459Szrj The input syntax is NAME:VALUE,NAME:VALUE, and so on. 1966*a9fa9459Szrj A semicolon or comma instead of a NAME means the end. */ 1967*a9fa9459Szrj alloc = 10; 1968*a9fa9459Szrj names = (const char **) xmalloc (alloc * sizeof *names); 1969*a9fa9459Szrj values = (bfd_signed_vma *) xmalloc (alloc * sizeof *values); 1970*a9fa9459Szrj n = 0; 1971*a9fa9459Szrj while (**pp != '\0' && **pp != ';' && **pp != ',') 1972*a9fa9459Szrj { 1973*a9fa9459Szrj const char *p; 1974*a9fa9459Szrj char *name; 1975*a9fa9459Szrj bfd_signed_vma val; 1976*a9fa9459Szrj 1977*a9fa9459Szrj p = *pp; 1978*a9fa9459Szrj while (*p != ':') 1979*a9fa9459Szrj ++p; 1980*a9fa9459Szrj 1981*a9fa9459Szrj name = savestring (*pp, p - *pp); 1982*a9fa9459Szrj 1983*a9fa9459Szrj *pp = p + 1; 1984*a9fa9459Szrj val = (bfd_signed_vma) parse_number (pp, (bfd_boolean *) NULL); 1985*a9fa9459Szrj if (**pp != ',') 1986*a9fa9459Szrj { 1987*a9fa9459Szrj bad_stab (orig); 1988*a9fa9459Szrj free (name); 1989*a9fa9459Szrj free (names); 1990*a9fa9459Szrj free (values); 1991*a9fa9459Szrj return DEBUG_TYPE_NULL; 1992*a9fa9459Szrj } 1993*a9fa9459Szrj ++*pp; 1994*a9fa9459Szrj 1995*a9fa9459Szrj if (n + 1 >= alloc) 1996*a9fa9459Szrj { 1997*a9fa9459Szrj alloc += 10; 1998*a9fa9459Szrj names = ((const char **) 1999*a9fa9459Szrj xrealloc (names, alloc * sizeof *names)); 2000*a9fa9459Szrj values = ((bfd_signed_vma *) 2001*a9fa9459Szrj xrealloc (values, alloc * sizeof *values)); 2002*a9fa9459Szrj } 2003*a9fa9459Szrj 2004*a9fa9459Szrj names[n] = name; 2005*a9fa9459Szrj values[n] = val; 2006*a9fa9459Szrj ++n; 2007*a9fa9459Szrj } 2008*a9fa9459Szrj 2009*a9fa9459Szrj names[n] = NULL; 2010*a9fa9459Szrj values[n] = 0; 2011*a9fa9459Szrj 2012*a9fa9459Szrj if (**pp == ';') 2013*a9fa9459Szrj ++*pp; 2014*a9fa9459Szrj 2015*a9fa9459Szrj return debug_make_enum_type (dhandle, names, values); 2016*a9fa9459Szrj } 2017*a9fa9459Szrj 2018*a9fa9459Szrj /* Read the description of a structure (or union type) and return an object 2019*a9fa9459Szrj describing the type. 2020*a9fa9459Szrj 2021*a9fa9459Szrj PP points to a character pointer that points to the next unconsumed token 2022*a9fa9459Szrj in the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;", 2023*a9fa9459Szrj *PP will point to "4a:1,0,32;;". */ 2024*a9fa9459Szrj 2025*a9fa9459Szrj static debug_type 2026*a9fa9459Szrj parse_stab_struct_type (void *dhandle, struct stab_handle *info, 2027*a9fa9459Szrj const char *tagname, const char **pp, 2028*a9fa9459Szrj bfd_boolean structp, const int *typenums) 2029*a9fa9459Szrj { 2030*a9fa9459Szrj bfd_vma size; 2031*a9fa9459Szrj debug_baseclass *baseclasses; 2032*a9fa9459Szrj debug_field *fields = NULL; 2033*a9fa9459Szrj bfd_boolean statics; 2034*a9fa9459Szrj debug_method *methods; 2035*a9fa9459Szrj debug_type vptrbase; 2036*a9fa9459Szrj bfd_boolean ownvptr; 2037*a9fa9459Szrj 2038*a9fa9459Szrj /* Get the size. */ 2039*a9fa9459Szrj size = parse_number (pp, (bfd_boolean *) NULL); 2040*a9fa9459Szrj 2041*a9fa9459Szrj /* Get the other information. */ 2042*a9fa9459Szrj if (! parse_stab_baseclasses (dhandle, info, pp, &baseclasses) 2043*a9fa9459Szrj || ! parse_stab_struct_fields (dhandle, info, pp, &fields, &statics) 2044*a9fa9459Szrj || ! parse_stab_members (dhandle, info, tagname, pp, typenums, &methods) 2045*a9fa9459Szrj || ! parse_stab_tilde_field (dhandle, info, pp, typenums, &vptrbase, 2046*a9fa9459Szrj &ownvptr)) 2047*a9fa9459Szrj { 2048*a9fa9459Szrj if (fields != NULL) 2049*a9fa9459Szrj free (fields); 2050*a9fa9459Szrj return DEBUG_TYPE_NULL; 2051*a9fa9459Szrj } 2052*a9fa9459Szrj 2053*a9fa9459Szrj if (! statics 2054*a9fa9459Szrj && baseclasses == NULL 2055*a9fa9459Szrj && methods == NULL 2056*a9fa9459Szrj && vptrbase == DEBUG_TYPE_NULL 2057*a9fa9459Szrj && ! ownvptr) 2058*a9fa9459Szrj return debug_make_struct_type (dhandle, structp, size, fields); 2059*a9fa9459Szrj 2060*a9fa9459Szrj return debug_make_object_type (dhandle, structp, size, fields, baseclasses, 2061*a9fa9459Szrj methods, vptrbase, ownvptr); 2062*a9fa9459Szrj } 2063*a9fa9459Szrj 2064*a9fa9459Szrj /* The stabs for C++ derived classes contain baseclass information which 2065*a9fa9459Szrj is marked by a '!' character after the total size. This function is 2066*a9fa9459Szrj called when we encounter the baseclass marker, and slurps up all the 2067*a9fa9459Szrj baseclass information. 2068*a9fa9459Szrj 2069*a9fa9459Szrj Immediately following the '!' marker is the number of base classes that 2070*a9fa9459Szrj the class is derived from, followed by information for each base class. 2071*a9fa9459Szrj For each base class, there are two visibility specifiers, a bit offset 2072*a9fa9459Szrj to the base class information within the derived class, a reference to 2073*a9fa9459Szrj the type for the base class, and a terminating semicolon. 2074*a9fa9459Szrj 2075*a9fa9459Szrj A typical example, with two base classes, would be "!2,020,19;0264,21;". 2076*a9fa9459Szrj ^^ ^ ^ ^ ^ ^ ^ 2077*a9fa9459Szrj Baseclass information marker __________________|| | | | | | | 2078*a9fa9459Szrj Number of baseclasses __________________________| | | | | | | 2079*a9fa9459Szrj Visibility specifiers (2) ________________________| | | | | | 2080*a9fa9459Szrj Offset in bits from start of class _________________| | | | | 2081*a9fa9459Szrj Type number for base class ___________________________| | | | 2082*a9fa9459Szrj Visibility specifiers (2) _______________________________| | | 2083*a9fa9459Szrj Offset in bits from start of class ________________________| | 2084*a9fa9459Szrj Type number of base class ____________________________________| 2085*a9fa9459Szrj 2086*a9fa9459Szrj Return TRUE for success, FALSE for failure. */ 2087*a9fa9459Szrj 2088*a9fa9459Szrj static bfd_boolean 2089*a9fa9459Szrj parse_stab_baseclasses (void *dhandle, struct stab_handle *info, 2090*a9fa9459Szrj const char **pp, debug_baseclass **retp) 2091*a9fa9459Szrj { 2092*a9fa9459Szrj const char *orig; 2093*a9fa9459Szrj unsigned int c, i; 2094*a9fa9459Szrj debug_baseclass *classes; 2095*a9fa9459Szrj 2096*a9fa9459Szrj *retp = NULL; 2097*a9fa9459Szrj 2098*a9fa9459Szrj orig = *pp; 2099*a9fa9459Szrj 2100*a9fa9459Szrj if (**pp != '!') 2101*a9fa9459Szrj { 2102*a9fa9459Szrj /* No base classes. */ 2103*a9fa9459Szrj return TRUE; 2104*a9fa9459Szrj } 2105*a9fa9459Szrj ++*pp; 2106*a9fa9459Szrj 2107*a9fa9459Szrj c = (unsigned int) parse_number (pp, (bfd_boolean *) NULL); 2108*a9fa9459Szrj 2109*a9fa9459Szrj if (**pp != ',') 2110*a9fa9459Szrj { 2111*a9fa9459Szrj bad_stab (orig); 2112*a9fa9459Szrj return FALSE; 2113*a9fa9459Szrj } 2114*a9fa9459Szrj ++*pp; 2115*a9fa9459Szrj 2116*a9fa9459Szrj classes = (debug_baseclass *) xmalloc ((c + 1) * sizeof (**retp)); 2117*a9fa9459Szrj 2118*a9fa9459Szrj for (i = 0; i < c; i++) 2119*a9fa9459Szrj { 2120*a9fa9459Szrj bfd_boolean is_virtual; 2121*a9fa9459Szrj enum debug_visibility visibility; 2122*a9fa9459Szrj bfd_vma bitpos; 2123*a9fa9459Szrj debug_type type; 2124*a9fa9459Szrj 2125*a9fa9459Szrj switch (**pp) 2126*a9fa9459Szrj { 2127*a9fa9459Szrj case '0': 2128*a9fa9459Szrj is_virtual = FALSE; 2129*a9fa9459Szrj break; 2130*a9fa9459Szrj case '1': 2131*a9fa9459Szrj is_virtual = TRUE; 2132*a9fa9459Szrj break; 2133*a9fa9459Szrj default: 2134*a9fa9459Szrj warn_stab (orig, _("unknown virtual character for baseclass")); 2135*a9fa9459Szrj is_virtual = FALSE; 2136*a9fa9459Szrj break; 2137*a9fa9459Szrj } 2138*a9fa9459Szrj ++*pp; 2139*a9fa9459Szrj 2140*a9fa9459Szrj switch (**pp) 2141*a9fa9459Szrj { 2142*a9fa9459Szrj case '0': 2143*a9fa9459Szrj visibility = DEBUG_VISIBILITY_PRIVATE; 2144*a9fa9459Szrj break; 2145*a9fa9459Szrj case '1': 2146*a9fa9459Szrj visibility = DEBUG_VISIBILITY_PROTECTED; 2147*a9fa9459Szrj break; 2148*a9fa9459Szrj case '2': 2149*a9fa9459Szrj visibility = DEBUG_VISIBILITY_PUBLIC; 2150*a9fa9459Szrj break; 2151*a9fa9459Szrj default: 2152*a9fa9459Szrj warn_stab (orig, _("unknown visibility character for baseclass")); 2153*a9fa9459Szrj visibility = DEBUG_VISIBILITY_PUBLIC; 2154*a9fa9459Szrj break; 2155*a9fa9459Szrj } 2156*a9fa9459Szrj ++*pp; 2157*a9fa9459Szrj 2158*a9fa9459Szrj /* The remaining value is the bit offset of the portion of the 2159*a9fa9459Szrj object corresponding to this baseclass. Always zero in the 2160*a9fa9459Szrj absence of multiple inheritance. */ 2161*a9fa9459Szrj bitpos = parse_number (pp, (bfd_boolean *) NULL); 2162*a9fa9459Szrj if (**pp != ',') 2163*a9fa9459Szrj { 2164*a9fa9459Szrj bad_stab (orig); 2165*a9fa9459Szrj return FALSE; 2166*a9fa9459Szrj } 2167*a9fa9459Szrj ++*pp; 2168*a9fa9459Szrj 2169*a9fa9459Szrj type = parse_stab_type (dhandle, info, (const char *) NULL, pp, 2170*a9fa9459Szrj (debug_type **) NULL); 2171*a9fa9459Szrj if (type == DEBUG_TYPE_NULL) 2172*a9fa9459Szrj return FALSE; 2173*a9fa9459Szrj 2174*a9fa9459Szrj classes[i] = debug_make_baseclass (dhandle, type, bitpos, is_virtual, 2175*a9fa9459Szrj visibility); 2176*a9fa9459Szrj if (classes[i] == DEBUG_BASECLASS_NULL) 2177*a9fa9459Szrj return FALSE; 2178*a9fa9459Szrj 2179*a9fa9459Szrj if (**pp != ';') 2180*a9fa9459Szrj return FALSE; 2181*a9fa9459Szrj ++*pp; 2182*a9fa9459Szrj } 2183*a9fa9459Szrj 2184*a9fa9459Szrj classes[i] = DEBUG_BASECLASS_NULL; 2185*a9fa9459Szrj 2186*a9fa9459Szrj *retp = classes; 2187*a9fa9459Szrj 2188*a9fa9459Szrj return TRUE; 2189*a9fa9459Szrj } 2190*a9fa9459Szrj 2191*a9fa9459Szrj /* Read struct or class data fields. They have the form: 2192*a9fa9459Szrj 2193*a9fa9459Szrj NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ; 2194*a9fa9459Szrj 2195*a9fa9459Szrj At the end, we see a semicolon instead of a field. 2196*a9fa9459Szrj 2197*a9fa9459Szrj In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for 2198*a9fa9459Szrj a static field. 2199*a9fa9459Szrj 2200*a9fa9459Szrj The optional VISIBILITY is one of: 2201*a9fa9459Szrj 2202*a9fa9459Szrj '/0' (VISIBILITY_PRIVATE) 2203*a9fa9459Szrj '/1' (VISIBILITY_PROTECTED) 2204*a9fa9459Szrj '/2' (VISIBILITY_PUBLIC) 2205*a9fa9459Szrj '/9' (VISIBILITY_IGNORE) 2206*a9fa9459Szrj 2207*a9fa9459Szrj or nothing, for C style fields with public visibility. 2208*a9fa9459Szrj 2209*a9fa9459Szrj Returns 1 for success, 0 for failure. */ 2210*a9fa9459Szrj 2211*a9fa9459Szrj static bfd_boolean 2212*a9fa9459Szrj parse_stab_struct_fields (void *dhandle, struct stab_handle *info, 2213*a9fa9459Szrj const char **pp, debug_field **retp, 2214*a9fa9459Szrj bfd_boolean *staticsp) 2215*a9fa9459Szrj { 2216*a9fa9459Szrj const char *orig; 2217*a9fa9459Szrj const char *p; 2218*a9fa9459Szrj debug_field *fields; 2219*a9fa9459Szrj unsigned int c; 2220*a9fa9459Szrj unsigned int alloc; 2221*a9fa9459Szrj 2222*a9fa9459Szrj *retp = NULL; 2223*a9fa9459Szrj *staticsp = FALSE; 2224*a9fa9459Szrj 2225*a9fa9459Szrj orig = *pp; 2226*a9fa9459Szrj 2227*a9fa9459Szrj c = 0; 2228*a9fa9459Szrj alloc = 10; 2229*a9fa9459Szrj fields = (debug_field *) xmalloc (alloc * sizeof *fields); 2230*a9fa9459Szrj while (**pp != ';') 2231*a9fa9459Szrj { 2232*a9fa9459Szrj /* FIXME: gdb checks os9k_stabs here. */ 2233*a9fa9459Szrj 2234*a9fa9459Szrj p = *pp; 2235*a9fa9459Szrj 2236*a9fa9459Szrj /* Add 1 to c to leave room for NULL pointer at end. */ 2237*a9fa9459Szrj if (c + 1 >= alloc) 2238*a9fa9459Szrj { 2239*a9fa9459Szrj alloc += 10; 2240*a9fa9459Szrj fields = ((debug_field *) 2241*a9fa9459Szrj xrealloc (fields, alloc * sizeof *fields)); 2242*a9fa9459Szrj } 2243*a9fa9459Szrj 2244*a9fa9459Szrj /* If it starts with CPLUS_MARKER it is a special abbreviation, 2245*a9fa9459Szrj unless the CPLUS_MARKER is followed by an underscore, in 2246*a9fa9459Szrj which case it is just the name of an anonymous type, which we 2247*a9fa9459Szrj should handle like any other type name. We accept either '$' 2248*a9fa9459Szrj or '.', because a field name can never contain one of these 2249*a9fa9459Szrj characters except as a CPLUS_MARKER. */ 2250*a9fa9459Szrj 2251*a9fa9459Szrj if ((*p == '$' || *p == '.') && p[1] != '_') 2252*a9fa9459Szrj { 2253*a9fa9459Szrj ++*pp; 2254*a9fa9459Szrj if (! parse_stab_cpp_abbrev (dhandle, info, pp, fields + c)) 2255*a9fa9459Szrj { 2256*a9fa9459Szrj free (fields); 2257*a9fa9459Szrj return FALSE; 2258*a9fa9459Szrj } 2259*a9fa9459Szrj ++c; 2260*a9fa9459Szrj continue; 2261*a9fa9459Szrj } 2262*a9fa9459Szrj 2263*a9fa9459Szrj /* Look for the ':' that separates the field name from the field 2264*a9fa9459Szrj values. Data members are delimited by a single ':', while member 2265*a9fa9459Szrj functions are delimited by a pair of ':'s. When we hit the member 2266*a9fa9459Szrj functions (if any), terminate scan loop and return. */ 2267*a9fa9459Szrj 2268*a9fa9459Szrj p = strchr (p, ':'); 2269*a9fa9459Szrj if (p == NULL) 2270*a9fa9459Szrj { 2271*a9fa9459Szrj bad_stab (orig); 2272*a9fa9459Szrj free (fields); 2273*a9fa9459Szrj return FALSE; 2274*a9fa9459Szrj } 2275*a9fa9459Szrj 2276*a9fa9459Szrj if (p[1] == ':') 2277*a9fa9459Szrj break; 2278*a9fa9459Szrj 2279*a9fa9459Szrj if (! parse_stab_one_struct_field (dhandle, info, pp, p, fields + c, 2280*a9fa9459Szrj staticsp)) 2281*a9fa9459Szrj return FALSE; 2282*a9fa9459Szrj 2283*a9fa9459Szrj ++c; 2284*a9fa9459Szrj } 2285*a9fa9459Szrj 2286*a9fa9459Szrj fields[c] = DEBUG_FIELD_NULL; 2287*a9fa9459Szrj 2288*a9fa9459Szrj *retp = fields; 2289*a9fa9459Szrj 2290*a9fa9459Szrj return TRUE; 2291*a9fa9459Szrj } 2292*a9fa9459Szrj 2293*a9fa9459Szrj /* Special GNU C++ name. */ 2294*a9fa9459Szrj 2295*a9fa9459Szrj static bfd_boolean 2296*a9fa9459Szrj parse_stab_cpp_abbrev (void *dhandle, struct stab_handle *info, 2297*a9fa9459Szrj const char **pp, debug_field *retp) 2298*a9fa9459Szrj { 2299*a9fa9459Szrj const char *orig; 2300*a9fa9459Szrj int cpp_abbrev; 2301*a9fa9459Szrj debug_type context; 2302*a9fa9459Szrj const char *name; 2303*a9fa9459Szrj const char *type_name; 2304*a9fa9459Szrj debug_type type; 2305*a9fa9459Szrj bfd_vma bitpos; 2306*a9fa9459Szrj 2307*a9fa9459Szrj *retp = DEBUG_FIELD_NULL; 2308*a9fa9459Szrj 2309*a9fa9459Szrj orig = *pp; 2310*a9fa9459Szrj 2311*a9fa9459Szrj if (**pp != 'v') 2312*a9fa9459Szrj { 2313*a9fa9459Szrj bad_stab (*pp); 2314*a9fa9459Szrj return FALSE; 2315*a9fa9459Szrj } 2316*a9fa9459Szrj ++*pp; 2317*a9fa9459Szrj 2318*a9fa9459Szrj cpp_abbrev = **pp; 2319*a9fa9459Szrj ++*pp; 2320*a9fa9459Szrj 2321*a9fa9459Szrj /* At this point, *pp points to something like "22:23=*22...", where 2322*a9fa9459Szrj the type number before the ':' is the "context" and everything 2323*a9fa9459Szrj after is a regular type definition. Lookup the type, find it's 2324*a9fa9459Szrj name, and construct the field name. */ 2325*a9fa9459Szrj 2326*a9fa9459Szrj context = parse_stab_type (dhandle, info, (const char *) NULL, pp, 2327*a9fa9459Szrj (debug_type **) NULL); 2328*a9fa9459Szrj if (context == DEBUG_TYPE_NULL) 2329*a9fa9459Szrj return FALSE; 2330*a9fa9459Szrj 2331*a9fa9459Szrj switch (cpp_abbrev) 2332*a9fa9459Szrj { 2333*a9fa9459Szrj case 'f': 2334*a9fa9459Szrj /* $vf -- a virtual function table pointer. */ 2335*a9fa9459Szrj name = "_vptr$"; 2336*a9fa9459Szrj break; 2337*a9fa9459Szrj case 'b': 2338*a9fa9459Szrj /* $vb -- a virtual bsomethingorother */ 2339*a9fa9459Szrj type_name = debug_get_type_name (dhandle, context); 2340*a9fa9459Szrj if (type_name == NULL) 2341*a9fa9459Szrj { 2342*a9fa9459Szrj warn_stab (orig, _("unnamed $vb type")); 2343*a9fa9459Szrj type_name = "FOO"; 2344*a9fa9459Szrj } 2345*a9fa9459Szrj name = concat ("_vb$", type_name, (const char *) NULL); 2346*a9fa9459Szrj break; 2347*a9fa9459Szrj default: 2348*a9fa9459Szrj warn_stab (orig, _("unrecognized C++ abbreviation")); 2349*a9fa9459Szrj name = "INVALID_CPLUSPLUS_ABBREV"; 2350*a9fa9459Szrj break; 2351*a9fa9459Szrj } 2352*a9fa9459Szrj 2353*a9fa9459Szrj if (**pp != ':') 2354*a9fa9459Szrj { 2355*a9fa9459Szrj bad_stab (orig); 2356*a9fa9459Szrj return FALSE; 2357*a9fa9459Szrj } 2358*a9fa9459Szrj ++*pp; 2359*a9fa9459Szrj 2360*a9fa9459Szrj type = parse_stab_type (dhandle, info, (const char *) NULL, pp, 2361*a9fa9459Szrj (debug_type **) NULL); 2362*a9fa9459Szrj if (**pp != ',') 2363*a9fa9459Szrj { 2364*a9fa9459Szrj bad_stab (orig); 2365*a9fa9459Szrj return FALSE; 2366*a9fa9459Szrj } 2367*a9fa9459Szrj ++*pp; 2368*a9fa9459Szrj 2369*a9fa9459Szrj bitpos = parse_number (pp, (bfd_boolean *) NULL); 2370*a9fa9459Szrj if (**pp != ';') 2371*a9fa9459Szrj { 2372*a9fa9459Szrj bad_stab (orig); 2373*a9fa9459Szrj return FALSE; 2374*a9fa9459Szrj } 2375*a9fa9459Szrj ++*pp; 2376*a9fa9459Szrj 2377*a9fa9459Szrj *retp = debug_make_field (dhandle, name, type, bitpos, 0, 2378*a9fa9459Szrj DEBUG_VISIBILITY_PRIVATE); 2379*a9fa9459Szrj if (*retp == DEBUG_FIELD_NULL) 2380*a9fa9459Szrj return FALSE; 2381*a9fa9459Szrj 2382*a9fa9459Szrj return TRUE; 2383*a9fa9459Szrj } 2384*a9fa9459Szrj 2385*a9fa9459Szrj /* Parse a single field in a struct or union. */ 2386*a9fa9459Szrj 2387*a9fa9459Szrj static bfd_boolean 2388*a9fa9459Szrj parse_stab_one_struct_field (void *dhandle, struct stab_handle *info, 2389*a9fa9459Szrj const char **pp, const char *p, 2390*a9fa9459Szrj debug_field *retp, bfd_boolean *staticsp) 2391*a9fa9459Szrj { 2392*a9fa9459Szrj const char *orig; 2393*a9fa9459Szrj char *name; 2394*a9fa9459Szrj enum debug_visibility visibility; 2395*a9fa9459Szrj debug_type type; 2396*a9fa9459Szrj bfd_vma bitpos; 2397*a9fa9459Szrj bfd_vma bitsize; 2398*a9fa9459Szrj 2399*a9fa9459Szrj orig = *pp; 2400*a9fa9459Szrj 2401*a9fa9459Szrj /* FIXME: gdb checks ARM_DEMANGLING here. */ 2402*a9fa9459Szrj 2403*a9fa9459Szrj name = savestring (*pp, p - *pp); 2404*a9fa9459Szrj 2405*a9fa9459Szrj *pp = p + 1; 2406*a9fa9459Szrj 2407*a9fa9459Szrj if (**pp != '/') 2408*a9fa9459Szrj visibility = DEBUG_VISIBILITY_PUBLIC; 2409*a9fa9459Szrj else 2410*a9fa9459Szrj { 2411*a9fa9459Szrj ++*pp; 2412*a9fa9459Szrj switch (**pp) 2413*a9fa9459Szrj { 2414*a9fa9459Szrj case '0': 2415*a9fa9459Szrj visibility = DEBUG_VISIBILITY_PRIVATE; 2416*a9fa9459Szrj break; 2417*a9fa9459Szrj case '1': 2418*a9fa9459Szrj visibility = DEBUG_VISIBILITY_PROTECTED; 2419*a9fa9459Szrj break; 2420*a9fa9459Szrj case '2': 2421*a9fa9459Szrj visibility = DEBUG_VISIBILITY_PUBLIC; 2422*a9fa9459Szrj break; 2423*a9fa9459Szrj default: 2424*a9fa9459Szrj warn_stab (orig, _("unknown visibility character for field")); 2425*a9fa9459Szrj visibility = DEBUG_VISIBILITY_PUBLIC; 2426*a9fa9459Szrj break; 2427*a9fa9459Szrj } 2428*a9fa9459Szrj ++*pp; 2429*a9fa9459Szrj } 2430*a9fa9459Szrj 2431*a9fa9459Szrj type = parse_stab_type (dhandle, info, (const char *) NULL, pp, 2432*a9fa9459Szrj (debug_type **) NULL); 2433*a9fa9459Szrj if (type == DEBUG_TYPE_NULL) 2434*a9fa9459Szrj { 2435*a9fa9459Szrj free (name); 2436*a9fa9459Szrj return FALSE; 2437*a9fa9459Szrj } 2438*a9fa9459Szrj 2439*a9fa9459Szrj if (**pp == ':') 2440*a9fa9459Szrj { 2441*a9fa9459Szrj char *varname; 2442*a9fa9459Szrj 2443*a9fa9459Szrj /* This is a static class member. */ 2444*a9fa9459Szrj ++*pp; 2445*a9fa9459Szrj p = strchr (*pp, ';'); 2446*a9fa9459Szrj if (p == NULL) 2447*a9fa9459Szrj { 2448*a9fa9459Szrj bad_stab (orig); 2449*a9fa9459Szrj free (name); 2450*a9fa9459Szrj return FALSE; 2451*a9fa9459Szrj } 2452*a9fa9459Szrj 2453*a9fa9459Szrj varname = savestring (*pp, p - *pp); 2454*a9fa9459Szrj 2455*a9fa9459Szrj *pp = p + 1; 2456*a9fa9459Szrj 2457*a9fa9459Szrj *retp = debug_make_static_member (dhandle, name, type, varname, 2458*a9fa9459Szrj visibility); 2459*a9fa9459Szrj *staticsp = TRUE; 2460*a9fa9459Szrj 2461*a9fa9459Szrj return TRUE; 2462*a9fa9459Szrj } 2463*a9fa9459Szrj 2464*a9fa9459Szrj if (**pp != ',') 2465*a9fa9459Szrj { 2466*a9fa9459Szrj bad_stab (orig); 2467*a9fa9459Szrj free (name); 2468*a9fa9459Szrj return FALSE; 2469*a9fa9459Szrj } 2470*a9fa9459Szrj ++*pp; 2471*a9fa9459Szrj 2472*a9fa9459Szrj bitpos = parse_number (pp, (bfd_boolean *) NULL); 2473*a9fa9459Szrj if (**pp != ',') 2474*a9fa9459Szrj { 2475*a9fa9459Szrj bad_stab (orig); 2476*a9fa9459Szrj free (name); 2477*a9fa9459Szrj return FALSE; 2478*a9fa9459Szrj } 2479*a9fa9459Szrj ++*pp; 2480*a9fa9459Szrj 2481*a9fa9459Szrj bitsize = parse_number (pp, (bfd_boolean *) NULL); 2482*a9fa9459Szrj if (**pp != ';') 2483*a9fa9459Szrj { 2484*a9fa9459Szrj bad_stab (orig); 2485*a9fa9459Szrj free (name); 2486*a9fa9459Szrj return FALSE; 2487*a9fa9459Szrj } 2488*a9fa9459Szrj ++*pp; 2489*a9fa9459Szrj 2490*a9fa9459Szrj if (bitpos == 0 && bitsize == 0) 2491*a9fa9459Szrj { 2492*a9fa9459Szrj /* This can happen in two cases: (1) at least for gcc 2.4.5 or 2493*a9fa9459Szrj so, it is a field which has been optimized out. The correct 2494*a9fa9459Szrj stab for this case is to use VISIBILITY_IGNORE, but that is a 2495*a9fa9459Szrj recent invention. (2) It is a 0-size array. For example 2496*a9fa9459Szrj union { int num; char str[0]; } foo. Printing "<no value>" 2497*a9fa9459Szrj for str in "p foo" is OK, since foo.str (and thus foo.str[3]) 2498*a9fa9459Szrj will continue to work, and a 0-size array as a whole doesn't 2499*a9fa9459Szrj have any contents to print. 2500*a9fa9459Szrj 2501*a9fa9459Szrj I suspect this probably could also happen with gcc -gstabs 2502*a9fa9459Szrj (not -gstabs+) for static fields, and perhaps other C++ 2503*a9fa9459Szrj extensions. Hopefully few people use -gstabs with gdb, since 2504*a9fa9459Szrj it is intended for dbx compatibility. */ 2505*a9fa9459Szrj visibility = DEBUG_VISIBILITY_IGNORE; 2506*a9fa9459Szrj } 2507*a9fa9459Szrj 2508*a9fa9459Szrj /* FIXME: gdb does some stuff here to mark fields as unpacked. */ 2509*a9fa9459Szrj 2510*a9fa9459Szrj *retp = debug_make_field (dhandle, name, type, bitpos, bitsize, visibility); 2511*a9fa9459Szrj 2512*a9fa9459Szrj return TRUE; 2513*a9fa9459Szrj } 2514*a9fa9459Szrj 2515*a9fa9459Szrj /* Read member function stabs info for C++ classes. The form of each member 2516*a9fa9459Szrj function data is: 2517*a9fa9459Szrj 2518*a9fa9459Szrj NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ; 2519*a9fa9459Szrj 2520*a9fa9459Szrj An example with two member functions is: 2521*a9fa9459Szrj 2522*a9fa9459Szrj afunc1::20=##15;:i;2A.;afunc2::20:i;2A.; 2523*a9fa9459Szrj 2524*a9fa9459Szrj For the case of overloaded operators, the format is op$::*.funcs, where 2525*a9fa9459Szrj $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator 2526*a9fa9459Szrj name (such as `+=') and `.' marks the end of the operator name. */ 2527*a9fa9459Szrj 2528*a9fa9459Szrj static bfd_boolean 2529*a9fa9459Szrj parse_stab_members (void *dhandle, struct stab_handle *info, 2530*a9fa9459Szrj const char *tagname, const char **pp, 2531*a9fa9459Szrj const int *typenums, debug_method **retp) 2532*a9fa9459Szrj { 2533*a9fa9459Szrj const char *orig; 2534*a9fa9459Szrj debug_method *methods; 2535*a9fa9459Szrj unsigned int c; 2536*a9fa9459Szrj unsigned int alloc; 2537*a9fa9459Szrj char *name = NULL; 2538*a9fa9459Szrj debug_method_variant *variants = NULL; 2539*a9fa9459Szrj char *argtypes = NULL; 2540*a9fa9459Szrj 2541*a9fa9459Szrj *retp = NULL; 2542*a9fa9459Szrj 2543*a9fa9459Szrj orig = *pp; 2544*a9fa9459Szrj 2545*a9fa9459Szrj alloc = 0; 2546*a9fa9459Szrj methods = NULL; 2547*a9fa9459Szrj c = 0; 2548*a9fa9459Szrj 2549*a9fa9459Szrj while (**pp != ';') 2550*a9fa9459Szrj { 2551*a9fa9459Szrj const char *p; 2552*a9fa9459Szrj unsigned int cvars; 2553*a9fa9459Szrj unsigned int allocvars; 2554*a9fa9459Szrj debug_type look_ahead_type; 2555*a9fa9459Szrj 2556*a9fa9459Szrj p = strchr (*pp, ':'); 2557*a9fa9459Szrj if (p == NULL || p[1] != ':') 2558*a9fa9459Szrj break; 2559*a9fa9459Szrj 2560*a9fa9459Szrj /* FIXME: Some systems use something other than '$' here. */ 2561*a9fa9459Szrj if ((*pp)[0] != 'o' || (*pp)[1] != 'p' || (*pp)[2] != '$') 2562*a9fa9459Szrj { 2563*a9fa9459Szrj name = savestring (*pp, p - *pp); 2564*a9fa9459Szrj *pp = p + 2; 2565*a9fa9459Szrj } 2566*a9fa9459Szrj else 2567*a9fa9459Szrj { 2568*a9fa9459Szrj /* This is a completely weird case. In order to stuff in the 2569*a9fa9459Szrj names that might contain colons (the usual name delimiter), 2570*a9fa9459Szrj Mike Tiemann defined a different name format which is 2571*a9fa9459Szrj signalled if the identifier is "op$". In that case, the 2572*a9fa9459Szrj format is "op$::XXXX." where XXXX is the name. This is 2573*a9fa9459Szrj used for names like "+" or "=". YUUUUUUUK! FIXME! */ 2574*a9fa9459Szrj *pp = p + 2; 2575*a9fa9459Szrj for (p = *pp; *p != '.' && *p != '\0'; p++) 2576*a9fa9459Szrj ; 2577*a9fa9459Szrj if (*p != '.') 2578*a9fa9459Szrj { 2579*a9fa9459Szrj bad_stab (orig); 2580*a9fa9459Szrj goto fail; 2581*a9fa9459Szrj } 2582*a9fa9459Szrj name = savestring (*pp, p - *pp); 2583*a9fa9459Szrj *pp = p + 1; 2584*a9fa9459Szrj } 2585*a9fa9459Szrj 2586*a9fa9459Szrj allocvars = 10; 2587*a9fa9459Szrj variants = ((debug_method_variant *) 2588*a9fa9459Szrj xmalloc (allocvars * sizeof *variants)); 2589*a9fa9459Szrj cvars = 0; 2590*a9fa9459Szrj 2591*a9fa9459Szrj look_ahead_type = DEBUG_TYPE_NULL; 2592*a9fa9459Szrj 2593*a9fa9459Szrj do 2594*a9fa9459Szrj { 2595*a9fa9459Szrj debug_type type; 2596*a9fa9459Szrj bfd_boolean stub; 2597*a9fa9459Szrj enum debug_visibility visibility; 2598*a9fa9459Szrj bfd_boolean constp, volatilep, staticp; 2599*a9fa9459Szrj bfd_vma voffset; 2600*a9fa9459Szrj debug_type context; 2601*a9fa9459Szrj const char *physname; 2602*a9fa9459Szrj bfd_boolean varargs; 2603*a9fa9459Szrj 2604*a9fa9459Szrj if (look_ahead_type != DEBUG_TYPE_NULL) 2605*a9fa9459Szrj { 2606*a9fa9459Szrj /* g++ version 1 kludge */ 2607*a9fa9459Szrj type = look_ahead_type; 2608*a9fa9459Szrj look_ahead_type = DEBUG_TYPE_NULL; 2609*a9fa9459Szrj } 2610*a9fa9459Szrj else 2611*a9fa9459Szrj { 2612*a9fa9459Szrj type = parse_stab_type (dhandle, info, (const char *) NULL, pp, 2613*a9fa9459Szrj (debug_type **) NULL); 2614*a9fa9459Szrj if (type == DEBUG_TYPE_NULL) 2615*a9fa9459Szrj goto fail; 2616*a9fa9459Szrj 2617*a9fa9459Szrj if (**pp != ':') 2618*a9fa9459Szrj { 2619*a9fa9459Szrj bad_stab (orig); 2620*a9fa9459Szrj goto fail; 2621*a9fa9459Szrj } 2622*a9fa9459Szrj } 2623*a9fa9459Szrj 2624*a9fa9459Szrj ++*pp; 2625*a9fa9459Szrj p = strchr (*pp, ';'); 2626*a9fa9459Szrj if (p == NULL) 2627*a9fa9459Szrj { 2628*a9fa9459Szrj bad_stab (orig); 2629*a9fa9459Szrj goto fail; 2630*a9fa9459Szrj } 2631*a9fa9459Szrj 2632*a9fa9459Szrj stub = FALSE; 2633*a9fa9459Szrj if (debug_get_type_kind (dhandle, type) == DEBUG_KIND_METHOD 2634*a9fa9459Szrj && debug_get_parameter_types (dhandle, type, &varargs) == NULL) 2635*a9fa9459Szrj stub = TRUE; 2636*a9fa9459Szrj 2637*a9fa9459Szrj argtypes = savestring (*pp, p - *pp); 2638*a9fa9459Szrj *pp = p + 1; 2639*a9fa9459Szrj 2640*a9fa9459Szrj switch (**pp) 2641*a9fa9459Szrj { 2642*a9fa9459Szrj case '0': 2643*a9fa9459Szrj visibility = DEBUG_VISIBILITY_PRIVATE; 2644*a9fa9459Szrj break; 2645*a9fa9459Szrj case '1': 2646*a9fa9459Szrj visibility = DEBUG_VISIBILITY_PROTECTED; 2647*a9fa9459Szrj break; 2648*a9fa9459Szrj default: 2649*a9fa9459Szrj visibility = DEBUG_VISIBILITY_PUBLIC; 2650*a9fa9459Szrj break; 2651*a9fa9459Szrj } 2652*a9fa9459Szrj ++*pp; 2653*a9fa9459Szrj 2654*a9fa9459Szrj constp = FALSE; 2655*a9fa9459Szrj volatilep = FALSE; 2656*a9fa9459Szrj switch (**pp) 2657*a9fa9459Szrj { 2658*a9fa9459Szrj case 'A': 2659*a9fa9459Szrj /* Normal function. */ 2660*a9fa9459Szrj ++*pp; 2661*a9fa9459Szrj break; 2662*a9fa9459Szrj case 'B': 2663*a9fa9459Szrj /* const member function. */ 2664*a9fa9459Szrj constp = TRUE; 2665*a9fa9459Szrj ++*pp; 2666*a9fa9459Szrj break; 2667*a9fa9459Szrj case 'C': 2668*a9fa9459Szrj /* volatile member function. */ 2669*a9fa9459Szrj volatilep = TRUE; 2670*a9fa9459Szrj ++*pp; 2671*a9fa9459Szrj break; 2672*a9fa9459Szrj case 'D': 2673*a9fa9459Szrj /* const volatile member function. */ 2674*a9fa9459Szrj constp = TRUE; 2675*a9fa9459Szrj volatilep = TRUE; 2676*a9fa9459Szrj ++*pp; 2677*a9fa9459Szrj break; 2678*a9fa9459Szrj case '*': 2679*a9fa9459Szrj case '?': 2680*a9fa9459Szrj case '.': 2681*a9fa9459Szrj /* File compiled with g++ version 1; no information. */ 2682*a9fa9459Szrj break; 2683*a9fa9459Szrj default: 2684*a9fa9459Szrj warn_stab (orig, _("const/volatile indicator missing")); 2685*a9fa9459Szrj break; 2686*a9fa9459Szrj } 2687*a9fa9459Szrj 2688*a9fa9459Szrj staticp = FALSE; 2689*a9fa9459Szrj switch (**pp) 2690*a9fa9459Szrj { 2691*a9fa9459Szrj case '*': 2692*a9fa9459Szrj /* virtual member function, followed by index. The sign 2693*a9fa9459Szrj bit is supposedly set to distinguish 2694*a9fa9459Szrj pointers-to-methods from virtual function indicies. */ 2695*a9fa9459Szrj ++*pp; 2696*a9fa9459Szrj voffset = parse_number (pp, (bfd_boolean *) NULL); 2697*a9fa9459Szrj if (**pp != ';') 2698*a9fa9459Szrj { 2699*a9fa9459Szrj bad_stab (orig); 2700*a9fa9459Szrj goto fail; 2701*a9fa9459Szrj } 2702*a9fa9459Szrj ++*pp; 2703*a9fa9459Szrj voffset &= 0x7fffffff; 2704*a9fa9459Szrj 2705*a9fa9459Szrj if (**pp == ';' || *pp == '\0') 2706*a9fa9459Szrj { 2707*a9fa9459Szrj /* Must be g++ version 1. */ 2708*a9fa9459Szrj context = DEBUG_TYPE_NULL; 2709*a9fa9459Szrj } 2710*a9fa9459Szrj else 2711*a9fa9459Szrj { 2712*a9fa9459Szrj /* Figure out from whence this virtual function 2713*a9fa9459Szrj came. It may belong to virtual function table of 2714*a9fa9459Szrj one of its baseclasses. */ 2715*a9fa9459Szrj look_ahead_type = parse_stab_type (dhandle, info, 2716*a9fa9459Szrj (const char *) NULL, 2717*a9fa9459Szrj pp, 2718*a9fa9459Szrj (debug_type **) NULL); 2719*a9fa9459Szrj if (**pp == ':') 2720*a9fa9459Szrj { 2721*a9fa9459Szrj /* g++ version 1 overloaded methods. */ 2722*a9fa9459Szrj context = DEBUG_TYPE_NULL; 2723*a9fa9459Szrj } 2724*a9fa9459Szrj else 2725*a9fa9459Szrj { 2726*a9fa9459Szrj context = look_ahead_type; 2727*a9fa9459Szrj look_ahead_type = DEBUG_TYPE_NULL; 2728*a9fa9459Szrj if (**pp != ';') 2729*a9fa9459Szrj { 2730*a9fa9459Szrj bad_stab (orig); 2731*a9fa9459Szrj goto fail; 2732*a9fa9459Szrj } 2733*a9fa9459Szrj ++*pp; 2734*a9fa9459Szrj } 2735*a9fa9459Szrj } 2736*a9fa9459Szrj break; 2737*a9fa9459Szrj 2738*a9fa9459Szrj case '?': 2739*a9fa9459Szrj /* static member function. */ 2740*a9fa9459Szrj ++*pp; 2741*a9fa9459Szrj staticp = TRUE; 2742*a9fa9459Szrj voffset = 0; 2743*a9fa9459Szrj context = DEBUG_TYPE_NULL; 2744*a9fa9459Szrj if (strncmp (argtypes, name, strlen (name)) != 0) 2745*a9fa9459Szrj stub = TRUE; 2746*a9fa9459Szrj break; 2747*a9fa9459Szrj 2748*a9fa9459Szrj default: 2749*a9fa9459Szrj warn_stab (orig, "member function type missing"); 2750*a9fa9459Szrj voffset = 0; 2751*a9fa9459Szrj context = DEBUG_TYPE_NULL; 2752*a9fa9459Szrj break; 2753*a9fa9459Szrj 2754*a9fa9459Szrj case '.': 2755*a9fa9459Szrj ++*pp; 2756*a9fa9459Szrj voffset = 0; 2757*a9fa9459Szrj context = DEBUG_TYPE_NULL; 2758*a9fa9459Szrj break; 2759*a9fa9459Szrj } 2760*a9fa9459Szrj 2761*a9fa9459Szrj /* If the type is not a stub, then the argtypes string is 2762*a9fa9459Szrj the physical name of the function. Otherwise the 2763*a9fa9459Szrj argtypes string is the mangled form of the argument 2764*a9fa9459Szrj types, and the full type and the physical name must be 2765*a9fa9459Szrj extracted from them. */ 2766*a9fa9459Szrj physname = argtypes; 2767*a9fa9459Szrj if (stub) 2768*a9fa9459Szrj { 2769*a9fa9459Szrj debug_type class_type, return_type; 2770*a9fa9459Szrj 2771*a9fa9459Szrj class_type = stab_find_type (dhandle, info, typenums); 2772*a9fa9459Szrj if (class_type == DEBUG_TYPE_NULL) 2773*a9fa9459Szrj goto fail; 2774*a9fa9459Szrj return_type = debug_get_return_type (dhandle, type); 2775*a9fa9459Szrj if (return_type == DEBUG_TYPE_NULL) 2776*a9fa9459Szrj { 2777*a9fa9459Szrj bad_stab (orig); 2778*a9fa9459Szrj goto fail; 2779*a9fa9459Szrj } 2780*a9fa9459Szrj type = parse_stab_argtypes (dhandle, info, class_type, name, 2781*a9fa9459Szrj tagname, return_type, argtypes, 2782*a9fa9459Szrj constp, volatilep, &physname); 2783*a9fa9459Szrj if (type == DEBUG_TYPE_NULL) 2784*a9fa9459Szrj goto fail; 2785*a9fa9459Szrj } 2786*a9fa9459Szrj 2787*a9fa9459Szrj if (cvars + 1 >= allocvars) 2788*a9fa9459Szrj { 2789*a9fa9459Szrj allocvars += 10; 2790*a9fa9459Szrj variants = ((debug_method_variant *) 2791*a9fa9459Szrj xrealloc (variants, 2792*a9fa9459Szrj allocvars * sizeof *variants)); 2793*a9fa9459Szrj } 2794*a9fa9459Szrj 2795*a9fa9459Szrj if (! staticp) 2796*a9fa9459Szrj variants[cvars] = debug_make_method_variant (dhandle, physname, 2797*a9fa9459Szrj type, visibility, 2798*a9fa9459Szrj constp, volatilep, 2799*a9fa9459Szrj voffset, context); 2800*a9fa9459Szrj else 2801*a9fa9459Szrj variants[cvars] = debug_make_static_method_variant (dhandle, 2802*a9fa9459Szrj physname, 2803*a9fa9459Szrj type, 2804*a9fa9459Szrj visibility, 2805*a9fa9459Szrj constp, 2806*a9fa9459Szrj volatilep); 2807*a9fa9459Szrj if (variants[cvars] == DEBUG_METHOD_VARIANT_NULL) 2808*a9fa9459Szrj goto fail; 2809*a9fa9459Szrj 2810*a9fa9459Szrj ++cvars; 2811*a9fa9459Szrj } 2812*a9fa9459Szrj while (**pp != ';' && **pp != '\0'); 2813*a9fa9459Szrj 2814*a9fa9459Szrj variants[cvars] = DEBUG_METHOD_VARIANT_NULL; 2815*a9fa9459Szrj 2816*a9fa9459Szrj if (**pp != '\0') 2817*a9fa9459Szrj ++*pp; 2818*a9fa9459Szrj 2819*a9fa9459Szrj if (c + 1 >= alloc) 2820*a9fa9459Szrj { 2821*a9fa9459Szrj alloc += 10; 2822*a9fa9459Szrj methods = ((debug_method *) 2823*a9fa9459Szrj xrealloc (methods, alloc * sizeof *methods)); 2824*a9fa9459Szrj } 2825*a9fa9459Szrj 2826*a9fa9459Szrj methods[c] = debug_make_method (dhandle, name, variants); 2827*a9fa9459Szrj 2828*a9fa9459Szrj ++c; 2829*a9fa9459Szrj } 2830*a9fa9459Szrj 2831*a9fa9459Szrj if (methods != NULL) 2832*a9fa9459Szrj methods[c] = DEBUG_METHOD_NULL; 2833*a9fa9459Szrj 2834*a9fa9459Szrj *retp = methods; 2835*a9fa9459Szrj 2836*a9fa9459Szrj return TRUE; 2837*a9fa9459Szrj 2838*a9fa9459Szrj fail: 2839*a9fa9459Szrj if (name != NULL) 2840*a9fa9459Szrj free (name); 2841*a9fa9459Szrj if (variants != NULL) 2842*a9fa9459Szrj free (variants); 2843*a9fa9459Szrj if (argtypes != NULL) 2844*a9fa9459Szrj free (argtypes); 2845*a9fa9459Szrj return FALSE; 2846*a9fa9459Szrj } 2847*a9fa9459Szrj 2848*a9fa9459Szrj /* Parse a string representing argument types for a method. Stabs 2849*a9fa9459Szrj tries to save space by packing argument types into a mangled 2850*a9fa9459Szrj string. This string should give us enough information to extract 2851*a9fa9459Szrj both argument types and the physical name of the function, given 2852*a9fa9459Szrj the tag name. */ 2853*a9fa9459Szrj 2854*a9fa9459Szrj static debug_type 2855*a9fa9459Szrj parse_stab_argtypes (void *dhandle, struct stab_handle *info, 2856*a9fa9459Szrj debug_type class_type, const char *fieldname, 2857*a9fa9459Szrj const char *tagname, debug_type return_type, 2858*a9fa9459Szrj const char *argtypes, bfd_boolean constp, 2859*a9fa9459Szrj bfd_boolean volatilep, const char **pphysname) 2860*a9fa9459Szrj { 2861*a9fa9459Szrj bfd_boolean is_full_physname_constructor; 2862*a9fa9459Szrj bfd_boolean is_constructor; 2863*a9fa9459Szrj bfd_boolean is_destructor; 2864*a9fa9459Szrj bfd_boolean is_v3; 2865*a9fa9459Szrj debug_type *args; 2866*a9fa9459Szrj bfd_boolean varargs; 2867*a9fa9459Szrj unsigned int physname_len = 0; 2868*a9fa9459Szrj 2869*a9fa9459Szrj /* Constructors are sometimes handled specially. */ 2870*a9fa9459Szrj is_full_physname_constructor = ((argtypes[0] == '_' 2871*a9fa9459Szrj && argtypes[1] == '_' 2872*a9fa9459Szrj && (ISDIGIT (argtypes[2]) 2873*a9fa9459Szrj || argtypes[2] == 'Q' 2874*a9fa9459Szrj || argtypes[2] == 't')) 2875*a9fa9459Szrj || CONST_STRNEQ (argtypes, "__ct")); 2876*a9fa9459Szrj 2877*a9fa9459Szrj is_constructor = (is_full_physname_constructor 2878*a9fa9459Szrj || (tagname != NULL 2879*a9fa9459Szrj && strcmp (fieldname, tagname) == 0)); 2880*a9fa9459Szrj is_destructor = ((argtypes[0] == '_' 2881*a9fa9459Szrj && (argtypes[1] == '$' || argtypes[1] == '.') 2882*a9fa9459Szrj && argtypes[2] == '_') 2883*a9fa9459Szrj || CONST_STRNEQ (argtypes, "__dt")); 2884*a9fa9459Szrj is_v3 = argtypes[0] == '_' && argtypes[1] == 'Z'; 2885*a9fa9459Szrj 2886*a9fa9459Szrj if (!(is_destructor || is_full_physname_constructor || is_v3)) 2887*a9fa9459Szrj { 2888*a9fa9459Szrj unsigned int len; 2889*a9fa9459Szrj const char *const_prefix; 2890*a9fa9459Szrj const char *volatile_prefix; 2891*a9fa9459Szrj char buf[20]; 2892*a9fa9459Szrj unsigned int mangled_name_len; 2893*a9fa9459Szrj char *physname; 2894*a9fa9459Szrj 2895*a9fa9459Szrj len = tagname == NULL ? 0 : strlen (tagname); 2896*a9fa9459Szrj const_prefix = constp ? "C" : ""; 2897*a9fa9459Szrj volatile_prefix = volatilep ? "V" : ""; 2898*a9fa9459Szrj 2899*a9fa9459Szrj if (len == 0) 2900*a9fa9459Szrj sprintf (buf, "__%s%s", const_prefix, volatile_prefix); 2901*a9fa9459Szrj else if (tagname != NULL && strchr (tagname, '<') != NULL) 2902*a9fa9459Szrj { 2903*a9fa9459Szrj /* Template methods are fully mangled. */ 2904*a9fa9459Szrj sprintf (buf, "__%s%s", const_prefix, volatile_prefix); 2905*a9fa9459Szrj tagname = NULL; 2906*a9fa9459Szrj len = 0; 2907*a9fa9459Szrj } 2908*a9fa9459Szrj else 2909*a9fa9459Szrj sprintf (buf, "__%s%s%d", const_prefix, volatile_prefix, len); 2910*a9fa9459Szrj 2911*a9fa9459Szrj mangled_name_len = ((is_constructor ? 0 : strlen (fieldname)) 2912*a9fa9459Szrj + strlen (buf) 2913*a9fa9459Szrj + len 2914*a9fa9459Szrj + strlen (argtypes) 2915*a9fa9459Szrj + 1); 2916*a9fa9459Szrj 2917*a9fa9459Szrj if (fieldname[0] == 'o' 2918*a9fa9459Szrj && fieldname[1] == 'p' 2919*a9fa9459Szrj && (fieldname[2] == '$' || fieldname[2] == '.')) 2920*a9fa9459Szrj { 2921*a9fa9459Szrj const char *opname; 2922*a9fa9459Szrj 2923*a9fa9459Szrj opname = cplus_mangle_opname (fieldname + 3, 0); 2924*a9fa9459Szrj if (opname == NULL) 2925*a9fa9459Szrj { 2926*a9fa9459Szrj fprintf (stderr, _("No mangling for \"%s\"\n"), fieldname); 2927*a9fa9459Szrj return DEBUG_TYPE_NULL; 2928*a9fa9459Szrj } 2929*a9fa9459Szrj mangled_name_len += strlen (opname); 2930*a9fa9459Szrj physname = (char *) xmalloc (mangled_name_len); 2931*a9fa9459Szrj strncpy (physname, fieldname, 3); 2932*a9fa9459Szrj strcpy (physname + 3, opname); 2933*a9fa9459Szrj } 2934*a9fa9459Szrj else 2935*a9fa9459Szrj { 2936*a9fa9459Szrj physname = (char *) xmalloc (mangled_name_len); 2937*a9fa9459Szrj if (is_constructor) 2938*a9fa9459Szrj physname[0] = '\0'; 2939*a9fa9459Szrj else 2940*a9fa9459Szrj strcpy (physname, fieldname); 2941*a9fa9459Szrj } 2942*a9fa9459Szrj 2943*a9fa9459Szrj physname_len = strlen (physname); 2944*a9fa9459Szrj strcat (physname, buf); 2945*a9fa9459Szrj if (tagname != NULL) 2946*a9fa9459Szrj strcat (physname, tagname); 2947*a9fa9459Szrj strcat (physname, argtypes); 2948*a9fa9459Szrj 2949*a9fa9459Szrj *pphysname = physname; 2950*a9fa9459Szrj } 2951*a9fa9459Szrj 2952*a9fa9459Szrj if (*argtypes == '\0' || is_destructor) 2953*a9fa9459Szrj { 2954*a9fa9459Szrj args = (debug_type *) xmalloc (sizeof *args); 2955*a9fa9459Szrj *args = NULL; 2956*a9fa9459Szrj return debug_make_method_type (dhandle, return_type, class_type, args, 2957*a9fa9459Szrj FALSE); 2958*a9fa9459Szrj } 2959*a9fa9459Szrj 2960*a9fa9459Szrj args = stab_demangle_argtypes (dhandle, info, *pphysname, &varargs, physname_len); 2961*a9fa9459Szrj if (args == NULL) 2962*a9fa9459Szrj return DEBUG_TYPE_NULL; 2963*a9fa9459Szrj 2964*a9fa9459Szrj return debug_make_method_type (dhandle, return_type, class_type, args, 2965*a9fa9459Szrj varargs); 2966*a9fa9459Szrj } 2967*a9fa9459Szrj 2968*a9fa9459Szrj /* The tail end of stabs for C++ classes that contain a virtual function 2969*a9fa9459Szrj pointer contains a tilde, a %, and a type number. 2970*a9fa9459Szrj The type number refers to the base class (possibly this class itself) which 2971*a9fa9459Szrj contains the vtable pointer for the current class. 2972*a9fa9459Szrj 2973*a9fa9459Szrj This function is called when we have parsed all the method declarations, 2974*a9fa9459Szrj so we can look for the vptr base class info. */ 2975*a9fa9459Szrj 2976*a9fa9459Szrj static bfd_boolean 2977*a9fa9459Szrj parse_stab_tilde_field (void *dhandle, struct stab_handle *info, 2978*a9fa9459Szrj const char **pp, const int *typenums, 2979*a9fa9459Szrj debug_type *retvptrbase, bfd_boolean *retownvptr) 2980*a9fa9459Szrj { 2981*a9fa9459Szrj const char *orig; 2982*a9fa9459Szrj const char *hold; 2983*a9fa9459Szrj int vtypenums[2]; 2984*a9fa9459Szrj 2985*a9fa9459Szrj *retvptrbase = DEBUG_TYPE_NULL; 2986*a9fa9459Szrj *retownvptr = FALSE; 2987*a9fa9459Szrj 2988*a9fa9459Szrj orig = *pp; 2989*a9fa9459Szrj 2990*a9fa9459Szrj /* If we are positioned at a ';', then skip it. */ 2991*a9fa9459Szrj if (**pp == ';') 2992*a9fa9459Szrj ++*pp; 2993*a9fa9459Szrj 2994*a9fa9459Szrj if (**pp != '~') 2995*a9fa9459Szrj return TRUE; 2996*a9fa9459Szrj 2997*a9fa9459Szrj ++*pp; 2998*a9fa9459Szrj 2999*a9fa9459Szrj if (**pp == '=' || **pp == '+' || **pp == '-') 3000*a9fa9459Szrj { 3001*a9fa9459Szrj /* Obsolete flags that used to indicate the presence of 3002*a9fa9459Szrj constructors and/or destructors. */ 3003*a9fa9459Szrj ++*pp; 3004*a9fa9459Szrj } 3005*a9fa9459Szrj 3006*a9fa9459Szrj if (**pp != '%') 3007*a9fa9459Szrj return TRUE; 3008*a9fa9459Szrj 3009*a9fa9459Szrj ++*pp; 3010*a9fa9459Szrj 3011*a9fa9459Szrj hold = *pp; 3012*a9fa9459Szrj 3013*a9fa9459Szrj /* The next number is the type number of the base class (possibly 3014*a9fa9459Szrj our own class) which supplies the vtable for this class. */ 3015*a9fa9459Szrj if (! parse_stab_type_number (pp, vtypenums)) 3016*a9fa9459Szrj return FALSE; 3017*a9fa9459Szrj 3018*a9fa9459Szrj if (vtypenums[0] == typenums[0] 3019*a9fa9459Szrj && vtypenums[1] == typenums[1]) 3020*a9fa9459Szrj *retownvptr = TRUE; 3021*a9fa9459Szrj else 3022*a9fa9459Szrj { 3023*a9fa9459Szrj debug_type vtype; 3024*a9fa9459Szrj const char *p; 3025*a9fa9459Szrj 3026*a9fa9459Szrj *pp = hold; 3027*a9fa9459Szrj 3028*a9fa9459Szrj vtype = parse_stab_type (dhandle, info, (const char *) NULL, pp, 3029*a9fa9459Szrj (debug_type **) NULL); 3030*a9fa9459Szrj for (p = *pp; *p != ';' && *p != '\0'; p++) 3031*a9fa9459Szrj ; 3032*a9fa9459Szrj if (*p != ';') 3033*a9fa9459Szrj { 3034*a9fa9459Szrj bad_stab (orig); 3035*a9fa9459Szrj return FALSE; 3036*a9fa9459Szrj } 3037*a9fa9459Szrj 3038*a9fa9459Szrj *retvptrbase = vtype; 3039*a9fa9459Szrj 3040*a9fa9459Szrj *pp = p + 1; 3041*a9fa9459Szrj } 3042*a9fa9459Szrj 3043*a9fa9459Szrj return TRUE; 3044*a9fa9459Szrj } 3045*a9fa9459Szrj 3046*a9fa9459Szrj /* Read a definition of an array type. */ 3047*a9fa9459Szrj 3048*a9fa9459Szrj static debug_type 3049*a9fa9459Szrj parse_stab_array_type (void *dhandle, struct stab_handle *info, 3050*a9fa9459Szrj const char **pp, bfd_boolean stringp) 3051*a9fa9459Szrj { 3052*a9fa9459Szrj const char *orig; 3053*a9fa9459Szrj const char *p; 3054*a9fa9459Szrj int typenums[2]; 3055*a9fa9459Szrj debug_type index_type; 3056*a9fa9459Szrj bfd_boolean adjustable; 3057*a9fa9459Szrj bfd_signed_vma lower, upper; 3058*a9fa9459Szrj debug_type element_type; 3059*a9fa9459Szrj 3060*a9fa9459Szrj /* Format of an array type: 3061*a9fa9459Szrj "ar<index type>;lower;upper;<array_contents_type>". 3062*a9fa9459Szrj OS9000: "arlower,upper;<array_contents_type>". 3063*a9fa9459Szrj 3064*a9fa9459Szrj Fortran adjustable arrays use Adigits or Tdigits for lower or upper; 3065*a9fa9459Szrj for these, produce a type like float[][]. */ 3066*a9fa9459Szrj 3067*a9fa9459Szrj orig = *pp; 3068*a9fa9459Szrj 3069*a9fa9459Szrj /* FIXME: gdb checks os9k_stabs here. */ 3070*a9fa9459Szrj 3071*a9fa9459Szrj /* If the index type is type 0, we take it as int. */ 3072*a9fa9459Szrj p = *pp; 3073*a9fa9459Szrj if (! parse_stab_type_number (&p, typenums)) 3074*a9fa9459Szrj return DEBUG_TYPE_NULL; 3075*a9fa9459Szrj if (typenums[0] == 0 && typenums[1] == 0 && **pp != '=') 3076*a9fa9459Szrj { 3077*a9fa9459Szrj index_type = debug_find_named_type (dhandle, "int"); 3078*a9fa9459Szrj if (index_type == DEBUG_TYPE_NULL) 3079*a9fa9459Szrj { 3080*a9fa9459Szrj index_type = debug_make_int_type (dhandle, 4, FALSE); 3081*a9fa9459Szrj if (index_type == DEBUG_TYPE_NULL) 3082*a9fa9459Szrj return DEBUG_TYPE_NULL; 3083*a9fa9459Szrj } 3084*a9fa9459Szrj *pp = p; 3085*a9fa9459Szrj } 3086*a9fa9459Szrj else 3087*a9fa9459Szrj { 3088*a9fa9459Szrj index_type = parse_stab_type (dhandle, info, (const char *) NULL, pp, 3089*a9fa9459Szrj (debug_type **) NULL); 3090*a9fa9459Szrj } 3091*a9fa9459Szrj 3092*a9fa9459Szrj if (**pp != ';') 3093*a9fa9459Szrj { 3094*a9fa9459Szrj bad_stab (orig); 3095*a9fa9459Szrj return DEBUG_TYPE_NULL; 3096*a9fa9459Szrj } 3097*a9fa9459Szrj ++*pp; 3098*a9fa9459Szrj 3099*a9fa9459Szrj adjustable = FALSE; 3100*a9fa9459Szrj 3101*a9fa9459Szrj if (! ISDIGIT (**pp) && **pp != '-') 3102*a9fa9459Szrj { 3103*a9fa9459Szrj ++*pp; 3104*a9fa9459Szrj adjustable = TRUE; 3105*a9fa9459Szrj } 3106*a9fa9459Szrj 3107*a9fa9459Szrj lower = (bfd_signed_vma) parse_number (pp, (bfd_boolean *) NULL); 3108*a9fa9459Szrj if (**pp != ';') 3109*a9fa9459Szrj { 3110*a9fa9459Szrj bad_stab (orig); 3111*a9fa9459Szrj return DEBUG_TYPE_NULL; 3112*a9fa9459Szrj } 3113*a9fa9459Szrj ++*pp; 3114*a9fa9459Szrj 3115*a9fa9459Szrj if (! ISDIGIT (**pp) && **pp != '-') 3116*a9fa9459Szrj { 3117*a9fa9459Szrj ++*pp; 3118*a9fa9459Szrj adjustable = TRUE; 3119*a9fa9459Szrj } 3120*a9fa9459Szrj 3121*a9fa9459Szrj upper = (bfd_signed_vma) parse_number (pp, (bfd_boolean *) NULL); 3122*a9fa9459Szrj if (**pp != ';') 3123*a9fa9459Szrj { 3124*a9fa9459Szrj bad_stab (orig); 3125*a9fa9459Szrj return DEBUG_TYPE_NULL; 3126*a9fa9459Szrj } 3127*a9fa9459Szrj ++*pp; 3128*a9fa9459Szrj 3129*a9fa9459Szrj element_type = parse_stab_type (dhandle, info, (const char *) NULL, pp, 3130*a9fa9459Szrj (debug_type **) NULL); 3131*a9fa9459Szrj if (element_type == DEBUG_TYPE_NULL) 3132*a9fa9459Szrj return DEBUG_TYPE_NULL; 3133*a9fa9459Szrj 3134*a9fa9459Szrj if (adjustable) 3135*a9fa9459Szrj { 3136*a9fa9459Szrj lower = 0; 3137*a9fa9459Szrj upper = -1; 3138*a9fa9459Szrj } 3139*a9fa9459Szrj 3140*a9fa9459Szrj return debug_make_array_type (dhandle, element_type, index_type, lower, 3141*a9fa9459Szrj upper, stringp); 3142*a9fa9459Szrj } 3143*a9fa9459Szrj 3144*a9fa9459Szrj /* This struct holds information about files we have seen using 3145*a9fa9459Szrj N_BINCL. */ 3146*a9fa9459Szrj 3147*a9fa9459Szrj struct bincl_file 3148*a9fa9459Szrj { 3149*a9fa9459Szrj /* The next N_BINCL file. */ 3150*a9fa9459Szrj struct bincl_file *next; 3151*a9fa9459Szrj /* The next N_BINCL on the stack. */ 3152*a9fa9459Szrj struct bincl_file *next_stack; 3153*a9fa9459Szrj /* The file name. */ 3154*a9fa9459Szrj const char *name; 3155*a9fa9459Szrj /* The hash value. */ 3156*a9fa9459Szrj bfd_vma hash; 3157*a9fa9459Szrj /* The file index. */ 3158*a9fa9459Szrj unsigned int file; 3159*a9fa9459Szrj /* The list of types defined in this file. */ 3160*a9fa9459Szrj struct stab_types *file_types; 3161*a9fa9459Szrj }; 3162*a9fa9459Szrj 3163*a9fa9459Szrj /* Start a new N_BINCL file, pushing it onto the stack. */ 3164*a9fa9459Szrj 3165*a9fa9459Szrj static void 3166*a9fa9459Szrj push_bincl (struct stab_handle *info, const char *name, bfd_vma hash) 3167*a9fa9459Szrj { 3168*a9fa9459Szrj struct bincl_file *n; 3169*a9fa9459Szrj 3170*a9fa9459Szrj n = (struct bincl_file *) xmalloc (sizeof *n); 3171*a9fa9459Szrj n->next = info->bincl_list; 3172*a9fa9459Szrj n->next_stack = info->bincl_stack; 3173*a9fa9459Szrj n->name = name; 3174*a9fa9459Szrj n->hash = hash; 3175*a9fa9459Szrj n->file = info->files; 3176*a9fa9459Szrj n->file_types = NULL; 3177*a9fa9459Szrj info->bincl_list = n; 3178*a9fa9459Szrj info->bincl_stack = n; 3179*a9fa9459Szrj 3180*a9fa9459Szrj ++info->files; 3181*a9fa9459Szrj info->file_types = ((struct stab_types **) 3182*a9fa9459Szrj xrealloc (info->file_types, 3183*a9fa9459Szrj (info->files 3184*a9fa9459Szrj * sizeof *info->file_types))); 3185*a9fa9459Szrj info->file_types[n->file] = NULL; 3186*a9fa9459Szrj } 3187*a9fa9459Szrj 3188*a9fa9459Szrj /* Finish an N_BINCL file, at an N_EINCL, popping the name off the 3189*a9fa9459Szrj stack. */ 3190*a9fa9459Szrj 3191*a9fa9459Szrj static const char * 3192*a9fa9459Szrj pop_bincl (struct stab_handle *info) 3193*a9fa9459Szrj { 3194*a9fa9459Szrj struct bincl_file *o; 3195*a9fa9459Szrj 3196*a9fa9459Szrj o = info->bincl_stack; 3197*a9fa9459Szrj if (o == NULL) 3198*a9fa9459Szrj return info->main_filename; 3199*a9fa9459Szrj info->bincl_stack = o->next_stack; 3200*a9fa9459Szrj 3201*a9fa9459Szrj o->file_types = info->file_types[o->file]; 3202*a9fa9459Szrj 3203*a9fa9459Szrj if (info->bincl_stack == NULL) 3204*a9fa9459Szrj return info->main_filename; 3205*a9fa9459Szrj return info->bincl_stack->name; 3206*a9fa9459Szrj } 3207*a9fa9459Szrj 3208*a9fa9459Szrj /* Handle an N_EXCL: get the types from the corresponding N_BINCL. */ 3209*a9fa9459Szrj 3210*a9fa9459Szrj static bfd_boolean 3211*a9fa9459Szrj find_excl (struct stab_handle *info, const char *name, bfd_vma hash) 3212*a9fa9459Szrj { 3213*a9fa9459Szrj struct bincl_file *l; 3214*a9fa9459Szrj 3215*a9fa9459Szrj ++info->files; 3216*a9fa9459Szrj info->file_types = ((struct stab_types **) 3217*a9fa9459Szrj xrealloc (info->file_types, 3218*a9fa9459Szrj (info->files 3219*a9fa9459Szrj * sizeof *info->file_types))); 3220*a9fa9459Szrj 3221*a9fa9459Szrj for (l = info->bincl_list; l != NULL; l = l->next) 3222*a9fa9459Szrj if (l->hash == hash && strcmp (l->name, name) == 0) 3223*a9fa9459Szrj break; 3224*a9fa9459Szrj if (l == NULL) 3225*a9fa9459Szrj { 3226*a9fa9459Szrj warn_stab (name, _("Undefined N_EXCL")); 3227*a9fa9459Szrj info->file_types[info->files - 1] = NULL; 3228*a9fa9459Szrj return TRUE; 3229*a9fa9459Szrj } 3230*a9fa9459Szrj 3231*a9fa9459Szrj info->file_types[info->files - 1] = l->file_types; 3232*a9fa9459Szrj 3233*a9fa9459Szrj return TRUE; 3234*a9fa9459Szrj } 3235*a9fa9459Szrj 3236*a9fa9459Szrj /* Handle a variable definition. gcc emits variable definitions for a 3237*a9fa9459Szrj block before the N_LBRAC, so we must hold onto them until we see 3238*a9fa9459Szrj it. The SunPRO compiler emits variable definitions after the 3239*a9fa9459Szrj N_LBRAC, so we can call debug_record_variable immediately. */ 3240*a9fa9459Szrj 3241*a9fa9459Szrj static bfd_boolean 3242*a9fa9459Szrj stab_record_variable (void *dhandle, struct stab_handle *info, 3243*a9fa9459Szrj const char *name, debug_type type, 3244*a9fa9459Szrj enum debug_var_kind kind, bfd_vma val) 3245*a9fa9459Szrj { 3246*a9fa9459Szrj struct stab_pending_var *v; 3247*a9fa9459Szrj 3248*a9fa9459Szrj if ((kind == DEBUG_GLOBAL || kind == DEBUG_STATIC) 3249*a9fa9459Szrj || ! info->within_function 3250*a9fa9459Szrj || (info->gcc_compiled == 0 && info->n_opt_found)) 3251*a9fa9459Szrj return debug_record_variable (dhandle, name, type, kind, val); 3252*a9fa9459Szrj 3253*a9fa9459Szrj v = (struct stab_pending_var *) xmalloc (sizeof *v); 3254*a9fa9459Szrj memset (v, 0, sizeof *v); 3255*a9fa9459Szrj 3256*a9fa9459Szrj v->next = info->pending; 3257*a9fa9459Szrj v->name = name; 3258*a9fa9459Szrj v->type = type; 3259*a9fa9459Szrj v->kind = kind; 3260*a9fa9459Szrj v->val = val; 3261*a9fa9459Szrj info->pending = v; 3262*a9fa9459Szrj 3263*a9fa9459Szrj return TRUE; 3264*a9fa9459Szrj } 3265*a9fa9459Szrj 3266*a9fa9459Szrj /* Emit pending variable definitions. This is called after we see the 3267*a9fa9459Szrj N_LBRAC that starts the block. */ 3268*a9fa9459Szrj 3269*a9fa9459Szrj static bfd_boolean 3270*a9fa9459Szrj stab_emit_pending_vars (void *dhandle, struct stab_handle *info) 3271*a9fa9459Szrj { 3272*a9fa9459Szrj struct stab_pending_var *v; 3273*a9fa9459Szrj 3274*a9fa9459Szrj v = info->pending; 3275*a9fa9459Szrj while (v != NULL) 3276*a9fa9459Szrj { 3277*a9fa9459Szrj struct stab_pending_var *next; 3278*a9fa9459Szrj 3279*a9fa9459Szrj if (! debug_record_variable (dhandle, v->name, v->type, v->kind, v->val)) 3280*a9fa9459Szrj return FALSE; 3281*a9fa9459Szrj 3282*a9fa9459Szrj next = v->next; 3283*a9fa9459Szrj free (v); 3284*a9fa9459Szrj v = next; 3285*a9fa9459Szrj } 3286*a9fa9459Szrj 3287*a9fa9459Szrj info->pending = NULL; 3288*a9fa9459Szrj 3289*a9fa9459Szrj return TRUE; 3290*a9fa9459Szrj } 3291*a9fa9459Szrj 3292*a9fa9459Szrj /* Find the slot for a type in the database. */ 3293*a9fa9459Szrj 3294*a9fa9459Szrj static debug_type * 3295*a9fa9459Szrj stab_find_slot (struct stab_handle *info, const int *typenums) 3296*a9fa9459Szrj { 3297*a9fa9459Szrj int filenum; 3298*a9fa9459Szrj int tindex; 3299*a9fa9459Szrj struct stab_types **ps; 3300*a9fa9459Szrj 3301*a9fa9459Szrj filenum = typenums[0]; 3302*a9fa9459Szrj tindex = typenums[1]; 3303*a9fa9459Szrj 3304*a9fa9459Szrj if (filenum < 0 || (unsigned int) filenum >= info->files) 3305*a9fa9459Szrj { 3306*a9fa9459Szrj fprintf (stderr, _("Type file number %d out of range\n"), filenum); 3307*a9fa9459Szrj return NULL; 3308*a9fa9459Szrj } 3309*a9fa9459Szrj if (tindex < 0) 3310*a9fa9459Szrj { 3311*a9fa9459Szrj fprintf (stderr, _("Type index number %d out of range\n"), tindex); 3312*a9fa9459Szrj return NULL; 3313*a9fa9459Szrj } 3314*a9fa9459Szrj 3315*a9fa9459Szrj ps = info->file_types + filenum; 3316*a9fa9459Szrj 3317*a9fa9459Szrj while (tindex >= STAB_TYPES_SLOTS) 3318*a9fa9459Szrj { 3319*a9fa9459Szrj if (*ps == NULL) 3320*a9fa9459Szrj { 3321*a9fa9459Szrj *ps = (struct stab_types *) xmalloc (sizeof **ps); 3322*a9fa9459Szrj memset (*ps, 0, sizeof **ps); 3323*a9fa9459Szrj } 3324*a9fa9459Szrj ps = &(*ps)->next; 3325*a9fa9459Szrj tindex -= STAB_TYPES_SLOTS; 3326*a9fa9459Szrj } 3327*a9fa9459Szrj if (*ps == NULL) 3328*a9fa9459Szrj { 3329*a9fa9459Szrj *ps = (struct stab_types *) xmalloc (sizeof **ps); 3330*a9fa9459Szrj memset (*ps, 0, sizeof **ps); 3331*a9fa9459Szrj } 3332*a9fa9459Szrj 3333*a9fa9459Szrj return (*ps)->types + tindex; 3334*a9fa9459Szrj } 3335*a9fa9459Szrj 3336*a9fa9459Szrj /* Find a type given a type number. If the type has not been 3337*a9fa9459Szrj allocated yet, create an indirect type. */ 3338*a9fa9459Szrj 3339*a9fa9459Szrj static debug_type 3340*a9fa9459Szrj stab_find_type (void *dhandle, struct stab_handle *info, const int *typenums) 3341*a9fa9459Szrj { 3342*a9fa9459Szrj debug_type *slot; 3343*a9fa9459Szrj 3344*a9fa9459Szrj if (typenums[0] == 0 && typenums[1] < 0) 3345*a9fa9459Szrj { 3346*a9fa9459Szrj /* A negative type number indicates an XCOFF builtin type. */ 3347*a9fa9459Szrj return stab_xcoff_builtin_type (dhandle, info, typenums[1]); 3348*a9fa9459Szrj } 3349*a9fa9459Szrj 3350*a9fa9459Szrj slot = stab_find_slot (info, typenums); 3351*a9fa9459Szrj if (slot == NULL) 3352*a9fa9459Szrj return DEBUG_TYPE_NULL; 3353*a9fa9459Szrj 3354*a9fa9459Szrj if (*slot == DEBUG_TYPE_NULL) 3355*a9fa9459Szrj return debug_make_indirect_type (dhandle, slot, (const char *) NULL); 3356*a9fa9459Szrj 3357*a9fa9459Szrj return *slot; 3358*a9fa9459Szrj } 3359*a9fa9459Szrj 3360*a9fa9459Szrj /* Record that a given type number refers to a given type. */ 3361*a9fa9459Szrj 3362*a9fa9459Szrj static bfd_boolean 3363*a9fa9459Szrj stab_record_type (void *dhandle ATTRIBUTE_UNUSED, struct stab_handle *info, 3364*a9fa9459Szrj const int *typenums, debug_type type) 3365*a9fa9459Szrj { 3366*a9fa9459Szrj debug_type *slot; 3367*a9fa9459Szrj 3368*a9fa9459Szrj slot = stab_find_slot (info, typenums); 3369*a9fa9459Szrj if (slot == NULL) 3370*a9fa9459Szrj return FALSE; 3371*a9fa9459Szrj 3372*a9fa9459Szrj /* gdb appears to ignore type redefinitions, so we do as well. */ 3373*a9fa9459Szrj 3374*a9fa9459Szrj *slot = type; 3375*a9fa9459Szrj 3376*a9fa9459Szrj return TRUE; 3377*a9fa9459Szrj } 3378*a9fa9459Szrj 3379*a9fa9459Szrj /* Return an XCOFF builtin type. */ 3380*a9fa9459Szrj 3381*a9fa9459Szrj static debug_type 3382*a9fa9459Szrj stab_xcoff_builtin_type (void *dhandle, struct stab_handle *info, 3383*a9fa9459Szrj int typenum) 3384*a9fa9459Szrj { 3385*a9fa9459Szrj debug_type rettype; 3386*a9fa9459Szrj const char *name; 3387*a9fa9459Szrj 3388*a9fa9459Szrj if (typenum >= 0 || typenum < -XCOFF_TYPE_COUNT) 3389*a9fa9459Szrj { 3390*a9fa9459Szrj fprintf (stderr, _("Unrecognized XCOFF type %d\n"), typenum); 3391*a9fa9459Szrj return DEBUG_TYPE_NULL; 3392*a9fa9459Szrj } 3393*a9fa9459Szrj if (info->xcoff_types[-typenum] != NULL) 3394*a9fa9459Szrj return info->xcoff_types[-typenum]; 3395*a9fa9459Szrj 3396*a9fa9459Szrj switch (-typenum) 3397*a9fa9459Szrj { 3398*a9fa9459Szrj case 1: 3399*a9fa9459Szrj /* The size of this and all the other types are fixed, defined 3400*a9fa9459Szrj by the debugging format. */ 3401*a9fa9459Szrj name = "int"; 3402*a9fa9459Szrj rettype = debug_make_int_type (dhandle, 4, FALSE); 3403*a9fa9459Szrj break; 3404*a9fa9459Szrj case 2: 3405*a9fa9459Szrj name = "char"; 3406*a9fa9459Szrj rettype = debug_make_int_type (dhandle, 1, FALSE); 3407*a9fa9459Szrj break; 3408*a9fa9459Szrj case 3: 3409*a9fa9459Szrj name = "short"; 3410*a9fa9459Szrj rettype = debug_make_int_type (dhandle, 2, FALSE); 3411*a9fa9459Szrj break; 3412*a9fa9459Szrj case 4: 3413*a9fa9459Szrj name = "long"; 3414*a9fa9459Szrj rettype = debug_make_int_type (dhandle, 4, FALSE); 3415*a9fa9459Szrj break; 3416*a9fa9459Szrj case 5: 3417*a9fa9459Szrj name = "unsigned char"; 3418*a9fa9459Szrj rettype = debug_make_int_type (dhandle, 1, TRUE); 3419*a9fa9459Szrj break; 3420*a9fa9459Szrj case 6: 3421*a9fa9459Szrj name = "signed char"; 3422*a9fa9459Szrj rettype = debug_make_int_type (dhandle, 1, FALSE); 3423*a9fa9459Szrj break; 3424*a9fa9459Szrj case 7: 3425*a9fa9459Szrj name = "unsigned short"; 3426*a9fa9459Szrj rettype = debug_make_int_type (dhandle, 2, TRUE); 3427*a9fa9459Szrj break; 3428*a9fa9459Szrj case 8: 3429*a9fa9459Szrj name = "unsigned int"; 3430*a9fa9459Szrj rettype = debug_make_int_type (dhandle, 4, TRUE); 3431*a9fa9459Szrj break; 3432*a9fa9459Szrj case 9: 3433*a9fa9459Szrj name = "unsigned"; 3434*a9fa9459Szrj rettype = debug_make_int_type (dhandle, 4, TRUE); 3435*a9fa9459Szrj case 10: 3436*a9fa9459Szrj name = "unsigned long"; 3437*a9fa9459Szrj rettype = debug_make_int_type (dhandle, 4, TRUE); 3438*a9fa9459Szrj break; 3439*a9fa9459Szrj case 11: 3440*a9fa9459Szrj name = "void"; 3441*a9fa9459Szrj rettype = debug_make_void_type (dhandle); 3442*a9fa9459Szrj break; 3443*a9fa9459Szrj case 12: 3444*a9fa9459Szrj /* IEEE single precision (32 bit). */ 3445*a9fa9459Szrj name = "float"; 3446*a9fa9459Szrj rettype = debug_make_float_type (dhandle, 4); 3447*a9fa9459Szrj break; 3448*a9fa9459Szrj case 13: 3449*a9fa9459Szrj /* IEEE double precision (64 bit). */ 3450*a9fa9459Szrj name = "double"; 3451*a9fa9459Szrj rettype = debug_make_float_type (dhandle, 8); 3452*a9fa9459Szrj break; 3453*a9fa9459Szrj case 14: 3454*a9fa9459Szrj /* This is an IEEE double on the RS/6000, and different machines 3455*a9fa9459Szrj with different sizes for "long double" should use different 3456*a9fa9459Szrj negative type numbers. See stabs.texinfo. */ 3457*a9fa9459Szrj name = "long double"; 3458*a9fa9459Szrj rettype = debug_make_float_type (dhandle, 8); 3459*a9fa9459Szrj break; 3460*a9fa9459Szrj case 15: 3461*a9fa9459Szrj name = "integer"; 3462*a9fa9459Szrj rettype = debug_make_int_type (dhandle, 4, FALSE); 3463*a9fa9459Szrj break; 3464*a9fa9459Szrj case 16: 3465*a9fa9459Szrj name = "boolean"; 3466*a9fa9459Szrj rettype = debug_make_bool_type (dhandle, 4); 3467*a9fa9459Szrj break; 3468*a9fa9459Szrj case 17: 3469*a9fa9459Szrj name = "short real"; 3470*a9fa9459Szrj rettype = debug_make_float_type (dhandle, 4); 3471*a9fa9459Szrj break; 3472*a9fa9459Szrj case 18: 3473*a9fa9459Szrj name = "real"; 3474*a9fa9459Szrj rettype = debug_make_float_type (dhandle, 8); 3475*a9fa9459Szrj break; 3476*a9fa9459Szrj case 19: 3477*a9fa9459Szrj /* FIXME */ 3478*a9fa9459Szrj name = "stringptr"; 3479*a9fa9459Szrj rettype = NULL; 3480*a9fa9459Szrj break; 3481*a9fa9459Szrj case 20: 3482*a9fa9459Szrj /* FIXME */ 3483*a9fa9459Szrj name = "character"; 3484*a9fa9459Szrj rettype = debug_make_int_type (dhandle, 1, TRUE); 3485*a9fa9459Szrj break; 3486*a9fa9459Szrj case 21: 3487*a9fa9459Szrj name = "logical*1"; 3488*a9fa9459Szrj rettype = debug_make_bool_type (dhandle, 1); 3489*a9fa9459Szrj break; 3490*a9fa9459Szrj case 22: 3491*a9fa9459Szrj name = "logical*2"; 3492*a9fa9459Szrj rettype = debug_make_bool_type (dhandle, 2); 3493*a9fa9459Szrj break; 3494*a9fa9459Szrj case 23: 3495*a9fa9459Szrj name = "logical*4"; 3496*a9fa9459Szrj rettype = debug_make_bool_type (dhandle, 4); 3497*a9fa9459Szrj break; 3498*a9fa9459Szrj case 24: 3499*a9fa9459Szrj name = "logical"; 3500*a9fa9459Szrj rettype = debug_make_bool_type (dhandle, 4); 3501*a9fa9459Szrj break; 3502*a9fa9459Szrj case 25: 3503*a9fa9459Szrj /* Complex type consisting of two IEEE single precision values. */ 3504*a9fa9459Szrj name = "complex"; 3505*a9fa9459Szrj rettype = debug_make_complex_type (dhandle, 8); 3506*a9fa9459Szrj break; 3507*a9fa9459Szrj case 26: 3508*a9fa9459Szrj /* Complex type consisting of two IEEE double precision values. */ 3509*a9fa9459Szrj name = "double complex"; 3510*a9fa9459Szrj rettype = debug_make_complex_type (dhandle, 16); 3511*a9fa9459Szrj break; 3512*a9fa9459Szrj case 27: 3513*a9fa9459Szrj name = "integer*1"; 3514*a9fa9459Szrj rettype = debug_make_int_type (dhandle, 1, FALSE); 3515*a9fa9459Szrj break; 3516*a9fa9459Szrj case 28: 3517*a9fa9459Szrj name = "integer*2"; 3518*a9fa9459Szrj rettype = debug_make_int_type (dhandle, 2, FALSE); 3519*a9fa9459Szrj break; 3520*a9fa9459Szrj case 29: 3521*a9fa9459Szrj name = "integer*4"; 3522*a9fa9459Szrj rettype = debug_make_int_type (dhandle, 4, FALSE); 3523*a9fa9459Szrj break; 3524*a9fa9459Szrj case 30: 3525*a9fa9459Szrj /* FIXME */ 3526*a9fa9459Szrj name = "wchar"; 3527*a9fa9459Szrj rettype = debug_make_int_type (dhandle, 2, FALSE); 3528*a9fa9459Szrj break; 3529*a9fa9459Szrj case 31: 3530*a9fa9459Szrj name = "long long"; 3531*a9fa9459Szrj rettype = debug_make_int_type (dhandle, 8, FALSE); 3532*a9fa9459Szrj break; 3533*a9fa9459Szrj case 32: 3534*a9fa9459Szrj name = "unsigned long long"; 3535*a9fa9459Szrj rettype = debug_make_int_type (dhandle, 8, TRUE); 3536*a9fa9459Szrj break; 3537*a9fa9459Szrj case 33: 3538*a9fa9459Szrj name = "logical*8"; 3539*a9fa9459Szrj rettype = debug_make_bool_type (dhandle, 8); 3540*a9fa9459Szrj break; 3541*a9fa9459Szrj case 34: 3542*a9fa9459Szrj name = "integer*8"; 3543*a9fa9459Szrj rettype = debug_make_int_type (dhandle, 8, FALSE); 3544*a9fa9459Szrj break; 3545*a9fa9459Szrj default: 3546*a9fa9459Szrj abort (); 3547*a9fa9459Szrj } 3548*a9fa9459Szrj 3549*a9fa9459Szrj rettype = debug_name_type (dhandle, name, rettype); 3550*a9fa9459Szrj 3551*a9fa9459Szrj info->xcoff_types[-typenum] = rettype; 3552*a9fa9459Szrj 3553*a9fa9459Szrj return rettype; 3554*a9fa9459Szrj } 3555*a9fa9459Szrj 3556*a9fa9459Szrj /* Find or create a tagged type. */ 3557*a9fa9459Szrj 3558*a9fa9459Szrj static debug_type 3559*a9fa9459Szrj stab_find_tagged_type (void *dhandle, struct stab_handle *info, 3560*a9fa9459Szrj const char *p, int len, enum debug_type_kind kind) 3561*a9fa9459Szrj { 3562*a9fa9459Szrj char *name; 3563*a9fa9459Szrj debug_type dtype; 3564*a9fa9459Szrj struct stab_tag *st; 3565*a9fa9459Szrj 3566*a9fa9459Szrj name = savestring (p, len); 3567*a9fa9459Szrj 3568*a9fa9459Szrj /* We pass DEBUG_KIND_ILLEGAL because we want all tags in the same 3569*a9fa9459Szrj namespace. This is right for C, and I don't know how to handle 3570*a9fa9459Szrj other languages. FIXME. */ 3571*a9fa9459Szrj dtype = debug_find_tagged_type (dhandle, name, DEBUG_KIND_ILLEGAL); 3572*a9fa9459Szrj if (dtype != DEBUG_TYPE_NULL) 3573*a9fa9459Szrj { 3574*a9fa9459Szrj free (name); 3575*a9fa9459Szrj return dtype; 3576*a9fa9459Szrj } 3577*a9fa9459Szrj 3578*a9fa9459Szrj /* We need to allocate an entry on the undefined tag list. */ 3579*a9fa9459Szrj for (st = info->tags; st != NULL; st = st->next) 3580*a9fa9459Szrj { 3581*a9fa9459Szrj if (st->name[0] == name[0] 3582*a9fa9459Szrj && strcmp (st->name, name) == 0) 3583*a9fa9459Szrj { 3584*a9fa9459Szrj if (st->kind == DEBUG_KIND_ILLEGAL) 3585*a9fa9459Szrj st->kind = kind; 3586*a9fa9459Szrj free (name); 3587*a9fa9459Szrj break; 3588*a9fa9459Szrj } 3589*a9fa9459Szrj } 3590*a9fa9459Szrj if (st == NULL) 3591*a9fa9459Szrj { 3592*a9fa9459Szrj st = (struct stab_tag *) xmalloc (sizeof *st); 3593*a9fa9459Szrj memset (st, 0, sizeof *st); 3594*a9fa9459Szrj 3595*a9fa9459Szrj st->next = info->tags; 3596*a9fa9459Szrj st->name = name; 3597*a9fa9459Szrj st->kind = kind; 3598*a9fa9459Szrj st->slot = DEBUG_TYPE_NULL; 3599*a9fa9459Szrj st->type = debug_make_indirect_type (dhandle, &st->slot, name); 3600*a9fa9459Szrj info->tags = st; 3601*a9fa9459Szrj } 3602*a9fa9459Szrj 3603*a9fa9459Szrj return st->type; 3604*a9fa9459Szrj } 3605*a9fa9459Szrj 3606*a9fa9459Szrj /* In order to get the correct argument types for a stubbed method, we 3607*a9fa9459Szrj need to extract the argument types from a C++ mangled string. 3608*a9fa9459Szrj Since the argument types can refer back to the return type, this 3609*a9fa9459Szrj means that we must demangle the entire physical name. In gdb this 3610*a9fa9459Szrj is done by calling cplus_demangle and running the results back 3611*a9fa9459Szrj through the C++ expression parser. Since we have no expression 3612*a9fa9459Szrj parser, we must duplicate much of the work of cplus_demangle here. 3613*a9fa9459Szrj 3614*a9fa9459Szrj We assume that GNU style demangling is used, since this is only 3615*a9fa9459Szrj done for method stubs, and only g++ should output that form of 3616*a9fa9459Szrj debugging information. */ 3617*a9fa9459Szrj 3618*a9fa9459Szrj /* This structure is used to hold a pointer to type information which 3619*a9fa9459Szrj demangling a string. */ 3620*a9fa9459Szrj 3621*a9fa9459Szrj struct stab_demangle_typestring 3622*a9fa9459Szrj { 3623*a9fa9459Szrj /* The start of the type. This is not null terminated. */ 3624*a9fa9459Szrj const char *typestring; 3625*a9fa9459Szrj /* The length of the type. */ 3626*a9fa9459Szrj unsigned int len; 3627*a9fa9459Szrj }; 3628*a9fa9459Szrj 3629*a9fa9459Szrj /* This structure is used to hold information while demangling a 3630*a9fa9459Szrj string. */ 3631*a9fa9459Szrj 3632*a9fa9459Szrj struct stab_demangle_info 3633*a9fa9459Szrj { 3634*a9fa9459Szrj /* The debugging information handle. */ 3635*a9fa9459Szrj void *dhandle; 3636*a9fa9459Szrj /* The stab information handle. */ 3637*a9fa9459Szrj struct stab_handle *info; 3638*a9fa9459Szrj /* The array of arguments we are building. */ 3639*a9fa9459Szrj debug_type *args; 3640*a9fa9459Szrj /* Whether the method takes a variable number of arguments. */ 3641*a9fa9459Szrj bfd_boolean varargs; 3642*a9fa9459Szrj /* The array of types we have remembered. */ 3643*a9fa9459Szrj struct stab_demangle_typestring *typestrings; 3644*a9fa9459Szrj /* The number of typestrings. */ 3645*a9fa9459Szrj unsigned int typestring_count; 3646*a9fa9459Szrj /* The number of typestring slots we have allocated. */ 3647*a9fa9459Szrj unsigned int typestring_alloc; 3648*a9fa9459Szrj }; 3649*a9fa9459Szrj 3650*a9fa9459Szrj static void stab_bad_demangle (const char *); 3651*a9fa9459Szrj static unsigned int stab_demangle_count (const char **); 3652*a9fa9459Szrj static bfd_boolean stab_demangle_get_count (const char **, unsigned int *); 3653*a9fa9459Szrj static bfd_boolean stab_demangle_prefix 3654*a9fa9459Szrj (struct stab_demangle_info *, const char **, unsigned int); 3655*a9fa9459Szrj static bfd_boolean stab_demangle_function_name 3656*a9fa9459Szrj (struct stab_demangle_info *, const char **, const char *); 3657*a9fa9459Szrj static bfd_boolean stab_demangle_signature 3658*a9fa9459Szrj (struct stab_demangle_info *, const char **); 3659*a9fa9459Szrj static bfd_boolean stab_demangle_qualified 3660*a9fa9459Szrj (struct stab_demangle_info *, const char **, debug_type *); 3661*a9fa9459Szrj static bfd_boolean stab_demangle_template 3662*a9fa9459Szrj (struct stab_demangle_info *, const char **, char **); 3663*a9fa9459Szrj static bfd_boolean stab_demangle_class 3664*a9fa9459Szrj (struct stab_demangle_info *, const char **, const char **); 3665*a9fa9459Szrj static bfd_boolean stab_demangle_args 3666*a9fa9459Szrj (struct stab_demangle_info *, const char **, debug_type **, bfd_boolean *); 3667*a9fa9459Szrj static bfd_boolean stab_demangle_arg 3668*a9fa9459Szrj (struct stab_demangle_info *, const char **, debug_type **, 3669*a9fa9459Szrj unsigned int *, unsigned int *); 3670*a9fa9459Szrj static bfd_boolean stab_demangle_type 3671*a9fa9459Szrj (struct stab_demangle_info *, const char **, debug_type *); 3672*a9fa9459Szrj static bfd_boolean stab_demangle_fund_type 3673*a9fa9459Szrj (struct stab_demangle_info *, const char **, debug_type *); 3674*a9fa9459Szrj static bfd_boolean stab_demangle_remember_type 3675*a9fa9459Szrj (struct stab_demangle_info *, const char *, int); 3676*a9fa9459Szrj 3677*a9fa9459Szrj /* Warn about a bad demangling. */ 3678*a9fa9459Szrj 3679*a9fa9459Szrj static void 3680*a9fa9459Szrj stab_bad_demangle (const char *s) 3681*a9fa9459Szrj { 3682*a9fa9459Szrj fprintf (stderr, _("bad mangled name `%s'\n"), s); 3683*a9fa9459Szrj } 3684*a9fa9459Szrj 3685*a9fa9459Szrj /* Get a count from a stab string. */ 3686*a9fa9459Szrj 3687*a9fa9459Szrj static unsigned int 3688*a9fa9459Szrj stab_demangle_count (const char **pp) 3689*a9fa9459Szrj { 3690*a9fa9459Szrj unsigned int count; 3691*a9fa9459Szrj 3692*a9fa9459Szrj count = 0; 3693*a9fa9459Szrj while (ISDIGIT (**pp)) 3694*a9fa9459Szrj { 3695*a9fa9459Szrj count *= 10; 3696*a9fa9459Szrj count += **pp - '0'; 3697*a9fa9459Szrj ++*pp; 3698*a9fa9459Szrj } 3699*a9fa9459Szrj return count; 3700*a9fa9459Szrj } 3701*a9fa9459Szrj 3702*a9fa9459Szrj /* Require a count in a string. The count may be multiple digits, in 3703*a9fa9459Szrj which case it must end in an underscore. */ 3704*a9fa9459Szrj 3705*a9fa9459Szrj static bfd_boolean 3706*a9fa9459Szrj stab_demangle_get_count (const char **pp, unsigned int *pi) 3707*a9fa9459Szrj { 3708*a9fa9459Szrj if (! ISDIGIT (**pp)) 3709*a9fa9459Szrj return FALSE; 3710*a9fa9459Szrj 3711*a9fa9459Szrj *pi = **pp - '0'; 3712*a9fa9459Szrj ++*pp; 3713*a9fa9459Szrj if (ISDIGIT (**pp)) 3714*a9fa9459Szrj { 3715*a9fa9459Szrj unsigned int count; 3716*a9fa9459Szrj const char *p; 3717*a9fa9459Szrj 3718*a9fa9459Szrj count = *pi; 3719*a9fa9459Szrj p = *pp; 3720*a9fa9459Szrj do 3721*a9fa9459Szrj { 3722*a9fa9459Szrj count *= 10; 3723*a9fa9459Szrj count += *p - '0'; 3724*a9fa9459Szrj ++p; 3725*a9fa9459Szrj } 3726*a9fa9459Szrj while (ISDIGIT (*p)); 3727*a9fa9459Szrj if (*p == '_') 3728*a9fa9459Szrj { 3729*a9fa9459Szrj *pp = p + 1; 3730*a9fa9459Szrj *pi = count; 3731*a9fa9459Szrj } 3732*a9fa9459Szrj } 3733*a9fa9459Szrj 3734*a9fa9459Szrj return TRUE; 3735*a9fa9459Szrj } 3736*a9fa9459Szrj 3737*a9fa9459Szrj /* This function demangles a physical name, returning a NULL 3738*a9fa9459Szrj terminated array of argument types. */ 3739*a9fa9459Szrj 3740*a9fa9459Szrj static debug_type * 3741*a9fa9459Szrj stab_demangle_argtypes (void *dhandle, struct stab_handle *info, 3742*a9fa9459Szrj const char *physname, bfd_boolean *pvarargs, 3743*a9fa9459Szrj unsigned int physname_len) 3744*a9fa9459Szrj { 3745*a9fa9459Szrj struct stab_demangle_info minfo; 3746*a9fa9459Szrj 3747*a9fa9459Szrj /* Check for the g++ V3 ABI. */ 3748*a9fa9459Szrj if (physname[0] == '_' && physname[1] == 'Z') 3749*a9fa9459Szrj return stab_demangle_v3_argtypes (dhandle, info, physname, pvarargs); 3750*a9fa9459Szrj 3751*a9fa9459Szrj minfo.dhandle = dhandle; 3752*a9fa9459Szrj minfo.info = info; 3753*a9fa9459Szrj minfo.args = NULL; 3754*a9fa9459Szrj minfo.varargs = FALSE; 3755*a9fa9459Szrj minfo.typestring_alloc = 10; 3756*a9fa9459Szrj minfo.typestrings = ((struct stab_demangle_typestring *) 3757*a9fa9459Szrj xmalloc (minfo.typestring_alloc 3758*a9fa9459Szrj * sizeof *minfo.typestrings)); 3759*a9fa9459Szrj minfo.typestring_count = 0; 3760*a9fa9459Szrj 3761*a9fa9459Szrj /* cplus_demangle checks for special GNU mangled forms, but we can't 3762*a9fa9459Szrj see any of them in mangled method argument types. */ 3763*a9fa9459Szrj 3764*a9fa9459Szrj if (! stab_demangle_prefix (&minfo, &physname, physname_len)) 3765*a9fa9459Szrj goto error_return; 3766*a9fa9459Szrj 3767*a9fa9459Szrj if (*physname != '\0') 3768*a9fa9459Szrj { 3769*a9fa9459Szrj if (! stab_demangle_signature (&minfo, &physname)) 3770*a9fa9459Szrj goto error_return; 3771*a9fa9459Szrj } 3772*a9fa9459Szrj 3773*a9fa9459Szrj free (minfo.typestrings); 3774*a9fa9459Szrj minfo.typestrings = NULL; 3775*a9fa9459Szrj 3776*a9fa9459Szrj if (minfo.args == NULL) 3777*a9fa9459Szrj fprintf (stderr, _("no argument types in mangled string\n")); 3778*a9fa9459Szrj 3779*a9fa9459Szrj *pvarargs = minfo.varargs; 3780*a9fa9459Szrj return minfo.args; 3781*a9fa9459Szrj 3782*a9fa9459Szrj error_return: 3783*a9fa9459Szrj if (minfo.typestrings != NULL) 3784*a9fa9459Szrj free (minfo.typestrings); 3785*a9fa9459Szrj return NULL; 3786*a9fa9459Szrj } 3787*a9fa9459Szrj 3788*a9fa9459Szrj /* Demangle the prefix of the mangled name. */ 3789*a9fa9459Szrj 3790*a9fa9459Szrj static bfd_boolean 3791*a9fa9459Szrj stab_demangle_prefix (struct stab_demangle_info *minfo, const char **pp, 3792*a9fa9459Szrj unsigned int physname_len) 3793*a9fa9459Szrj { 3794*a9fa9459Szrj const char *scan; 3795*a9fa9459Szrj unsigned int i; 3796*a9fa9459Szrj 3797*a9fa9459Szrj /* cplus_demangle checks for global constructors and destructors, 3798*a9fa9459Szrj but we can't see them in mangled argument types. */ 3799*a9fa9459Szrj 3800*a9fa9459Szrj if (physname_len) 3801*a9fa9459Szrj scan = *pp + physname_len; 3802*a9fa9459Szrj else 3803*a9fa9459Szrj { 3804*a9fa9459Szrj /* Look for `__'. */ 3805*a9fa9459Szrj scan = *pp; 3806*a9fa9459Szrj do 3807*a9fa9459Szrj scan = strchr (scan, '_'); 3808*a9fa9459Szrj while (scan != NULL && *++scan != '_'); 3809*a9fa9459Szrj 3810*a9fa9459Szrj if (scan == NULL) 3811*a9fa9459Szrj { 3812*a9fa9459Szrj stab_bad_demangle (*pp); 3813*a9fa9459Szrj return FALSE; 3814*a9fa9459Szrj } 3815*a9fa9459Szrj 3816*a9fa9459Szrj --scan; 3817*a9fa9459Szrj 3818*a9fa9459Szrj /* We found `__'; move ahead to the last contiguous `__' pair. */ 3819*a9fa9459Szrj i = strspn (scan, "_"); 3820*a9fa9459Szrj if (i > 2) 3821*a9fa9459Szrj scan += i - 2; 3822*a9fa9459Szrj } 3823*a9fa9459Szrj 3824*a9fa9459Szrj if (scan == *pp 3825*a9fa9459Szrj && (ISDIGIT (scan[2]) 3826*a9fa9459Szrj || scan[2] == 'Q' 3827*a9fa9459Szrj || scan[2] == 't')) 3828*a9fa9459Szrj { 3829*a9fa9459Szrj /* This is a GNU style constructor name. */ 3830*a9fa9459Szrj *pp = scan + 2; 3831*a9fa9459Szrj return TRUE; 3832*a9fa9459Szrj } 3833*a9fa9459Szrj else if (scan == *pp 3834*a9fa9459Szrj && ! ISDIGIT (scan[2]) 3835*a9fa9459Szrj && scan[2] != 't') 3836*a9fa9459Szrj { 3837*a9fa9459Szrj /* Look for the `__' that separates the prefix from the 3838*a9fa9459Szrj signature. */ 3839*a9fa9459Szrj while (*scan == '_') 3840*a9fa9459Szrj ++scan; 3841*a9fa9459Szrj scan = strstr (scan, "__"); 3842*a9fa9459Szrj if (scan == NULL || scan[2] == '\0') 3843*a9fa9459Szrj { 3844*a9fa9459Szrj stab_bad_demangle (*pp); 3845*a9fa9459Szrj return FALSE; 3846*a9fa9459Szrj } 3847*a9fa9459Szrj 3848*a9fa9459Szrj return stab_demangle_function_name (minfo, pp, scan); 3849*a9fa9459Szrj } 3850*a9fa9459Szrj else if (scan[2] != '\0') 3851*a9fa9459Szrj { 3852*a9fa9459Szrj /* The name doesn't start with `__', but it does contain `__'. */ 3853*a9fa9459Szrj return stab_demangle_function_name (minfo, pp, scan); 3854*a9fa9459Szrj } 3855*a9fa9459Szrj else 3856*a9fa9459Szrj { 3857*a9fa9459Szrj stab_bad_demangle (*pp); 3858*a9fa9459Szrj return FALSE; 3859*a9fa9459Szrj } 3860*a9fa9459Szrj /*NOTREACHED*/ 3861*a9fa9459Szrj } 3862*a9fa9459Szrj 3863*a9fa9459Szrj /* Demangle a function name prefix. The scan argument points to the 3864*a9fa9459Szrj double underscore which separates the function name from the 3865*a9fa9459Szrj signature. */ 3866*a9fa9459Szrj 3867*a9fa9459Szrj static bfd_boolean 3868*a9fa9459Szrj stab_demangle_function_name (struct stab_demangle_info *minfo, 3869*a9fa9459Szrj const char **pp, const char *scan) 3870*a9fa9459Szrj { 3871*a9fa9459Szrj const char *name; 3872*a9fa9459Szrj 3873*a9fa9459Szrj /* The string from *pp to scan is the name of the function. We 3874*a9fa9459Szrj don't care about the name, since we just looking for argument 3875*a9fa9459Szrj types. However, for conversion operators, the name may include a 3876*a9fa9459Szrj type which we must remember in order to handle backreferences. */ 3877*a9fa9459Szrj 3878*a9fa9459Szrj name = *pp; 3879*a9fa9459Szrj *pp = scan + 2; 3880*a9fa9459Szrj 3881*a9fa9459Szrj if (*pp - name >= 5 3882*a9fa9459Szrj && CONST_STRNEQ (name, "type") 3883*a9fa9459Szrj && (name[4] == '$' || name[4] == '.')) 3884*a9fa9459Szrj { 3885*a9fa9459Szrj const char *tem; 3886*a9fa9459Szrj 3887*a9fa9459Szrj /* This is a type conversion operator. */ 3888*a9fa9459Szrj tem = name + 5; 3889*a9fa9459Szrj if (! stab_demangle_type (minfo, &tem, (debug_type *) NULL)) 3890*a9fa9459Szrj return FALSE; 3891*a9fa9459Szrj } 3892*a9fa9459Szrj else if (name[0] == '_' 3893*a9fa9459Szrj && name[1] == '_' 3894*a9fa9459Szrj && name[2] == 'o' 3895*a9fa9459Szrj && name[3] == 'p') 3896*a9fa9459Szrj { 3897*a9fa9459Szrj const char *tem; 3898*a9fa9459Szrj 3899*a9fa9459Szrj /* This is a type conversion operator. */ 3900*a9fa9459Szrj tem = name + 4; 3901*a9fa9459Szrj if (! stab_demangle_type (minfo, &tem, (debug_type *) NULL)) 3902*a9fa9459Szrj return FALSE; 3903*a9fa9459Szrj } 3904*a9fa9459Szrj 3905*a9fa9459Szrj return TRUE; 3906*a9fa9459Szrj } 3907*a9fa9459Szrj 3908*a9fa9459Szrj /* Demangle the signature. This is where the argument types are 3909*a9fa9459Szrj found. */ 3910*a9fa9459Szrj 3911*a9fa9459Szrj static bfd_boolean 3912*a9fa9459Szrj stab_demangle_signature (struct stab_demangle_info *minfo, const char **pp) 3913*a9fa9459Szrj { 3914*a9fa9459Szrj const char *orig; 3915*a9fa9459Szrj bfd_boolean expect_func, func_done; 3916*a9fa9459Szrj const char *hold; 3917*a9fa9459Szrj 3918*a9fa9459Szrj orig = *pp; 3919*a9fa9459Szrj 3920*a9fa9459Szrj expect_func = FALSE; 3921*a9fa9459Szrj func_done = FALSE; 3922*a9fa9459Szrj hold = NULL; 3923*a9fa9459Szrj 3924*a9fa9459Szrj while (**pp != '\0') 3925*a9fa9459Szrj { 3926*a9fa9459Szrj switch (**pp) 3927*a9fa9459Szrj { 3928*a9fa9459Szrj case 'Q': 3929*a9fa9459Szrj hold = *pp; 3930*a9fa9459Szrj if (! stab_demangle_qualified (minfo, pp, (debug_type *) NULL) 3931*a9fa9459Szrj || ! stab_demangle_remember_type (minfo, hold, *pp - hold)) 3932*a9fa9459Szrj return FALSE; 3933*a9fa9459Szrj expect_func = TRUE; 3934*a9fa9459Szrj hold = NULL; 3935*a9fa9459Szrj break; 3936*a9fa9459Szrj 3937*a9fa9459Szrj case 'S': 3938*a9fa9459Szrj /* Static member function. FIXME: Can this happen? */ 3939*a9fa9459Szrj if (hold == NULL) 3940*a9fa9459Szrj hold = *pp; 3941*a9fa9459Szrj ++*pp; 3942*a9fa9459Szrj break; 3943*a9fa9459Szrj 3944*a9fa9459Szrj case 'C': 3945*a9fa9459Szrj /* Const member function. */ 3946*a9fa9459Szrj if (hold == NULL) 3947*a9fa9459Szrj hold = *pp; 3948*a9fa9459Szrj ++*pp; 3949*a9fa9459Szrj break; 3950*a9fa9459Szrj 3951*a9fa9459Szrj case '0': case '1': case '2': case '3': case '4': 3952*a9fa9459Szrj case '5': case '6': case '7': case '8': case '9': 3953*a9fa9459Szrj if (hold == NULL) 3954*a9fa9459Szrj hold = *pp; 3955*a9fa9459Szrj if (! stab_demangle_class (minfo, pp, (const char **) NULL) 3956*a9fa9459Szrj || ! stab_demangle_remember_type (minfo, hold, *pp - hold)) 3957*a9fa9459Szrj return FALSE; 3958*a9fa9459Szrj expect_func = TRUE; 3959*a9fa9459Szrj hold = NULL; 3960*a9fa9459Szrj break; 3961*a9fa9459Szrj 3962*a9fa9459Szrj case 'F': 3963*a9fa9459Szrj /* Function. I don't know if this actually happens with g++ 3964*a9fa9459Szrj output. */ 3965*a9fa9459Szrj hold = NULL; 3966*a9fa9459Szrj func_done = TRUE; 3967*a9fa9459Szrj ++*pp; 3968*a9fa9459Szrj if (! stab_demangle_args (minfo, pp, &minfo->args, &minfo->varargs)) 3969*a9fa9459Szrj return FALSE; 3970*a9fa9459Szrj break; 3971*a9fa9459Szrj 3972*a9fa9459Szrj case 't': 3973*a9fa9459Szrj /* Template. */ 3974*a9fa9459Szrj if (hold == NULL) 3975*a9fa9459Szrj hold = *pp; 3976*a9fa9459Szrj if (! stab_demangle_template (minfo, pp, (char **) NULL) 3977*a9fa9459Szrj || ! stab_demangle_remember_type (minfo, hold, *pp - hold)) 3978*a9fa9459Szrj return FALSE; 3979*a9fa9459Szrj hold = NULL; 3980*a9fa9459Szrj expect_func = TRUE; 3981*a9fa9459Szrj break; 3982*a9fa9459Szrj 3983*a9fa9459Szrj case '_': 3984*a9fa9459Szrj /* At the outermost level, we cannot have a return type 3985*a9fa9459Szrj specified, so if we run into another '_' at this point we 3986*a9fa9459Szrj are dealing with a mangled name that is either bogus, or 3987*a9fa9459Szrj has been mangled by some algorithm we don't know how to 3988*a9fa9459Szrj deal with. So just reject the entire demangling. */ 3989*a9fa9459Szrj stab_bad_demangle (orig); 3990*a9fa9459Szrj return FALSE; 3991*a9fa9459Szrj 3992*a9fa9459Szrj default: 3993*a9fa9459Szrj /* Assume we have stumbled onto the first outermost function 3994*a9fa9459Szrj argument token, and start processing args. */ 3995*a9fa9459Szrj func_done = TRUE; 3996*a9fa9459Szrj if (! stab_demangle_args (minfo, pp, &minfo->args, &minfo->varargs)) 3997*a9fa9459Szrj return FALSE; 3998*a9fa9459Szrj break; 3999*a9fa9459Szrj } 4000*a9fa9459Szrj 4001*a9fa9459Szrj if (expect_func) 4002*a9fa9459Szrj { 4003*a9fa9459Szrj func_done = TRUE; 4004*a9fa9459Szrj if (! stab_demangle_args (minfo, pp, &minfo->args, &minfo->varargs)) 4005*a9fa9459Szrj return FALSE; 4006*a9fa9459Szrj } 4007*a9fa9459Szrj } 4008*a9fa9459Szrj 4009*a9fa9459Szrj if (! func_done) 4010*a9fa9459Szrj { 4011*a9fa9459Szrj /* With GNU style demangling, bar__3foo is 'foo::bar(void)', and 4012*a9fa9459Szrj bar__3fooi is 'foo::bar(int)'. We get here when we find the 4013*a9fa9459Szrj first case, and need to ensure that the '(void)' gets added 4014*a9fa9459Szrj to the current declp. */ 4015*a9fa9459Szrj if (! stab_demangle_args (minfo, pp, &minfo->args, &minfo->varargs)) 4016*a9fa9459Szrj return FALSE; 4017*a9fa9459Szrj } 4018*a9fa9459Szrj 4019*a9fa9459Szrj return TRUE; 4020*a9fa9459Szrj } 4021*a9fa9459Szrj 4022*a9fa9459Szrj /* Demangle a qualified name, such as "Q25Outer5Inner" which is the 4023*a9fa9459Szrj mangled form of "Outer::Inner". */ 4024*a9fa9459Szrj 4025*a9fa9459Szrj static bfd_boolean 4026*a9fa9459Szrj stab_demangle_qualified (struct stab_demangle_info *minfo, const char **pp, 4027*a9fa9459Szrj debug_type *ptype) 4028*a9fa9459Szrj { 4029*a9fa9459Szrj const char *orig; 4030*a9fa9459Szrj const char *p; 4031*a9fa9459Szrj unsigned int qualifiers; 4032*a9fa9459Szrj debug_type context; 4033*a9fa9459Szrj 4034*a9fa9459Szrj orig = *pp; 4035*a9fa9459Szrj 4036*a9fa9459Szrj switch ((*pp)[1]) 4037*a9fa9459Szrj { 4038*a9fa9459Szrj case '_': 4039*a9fa9459Szrj /* GNU mangled name with more than 9 classes. The count is 4040*a9fa9459Szrj preceded by an underscore (to distinguish it from the <= 9 4041*a9fa9459Szrj case) and followed by an underscore. */ 4042*a9fa9459Szrj p = *pp + 2; 4043*a9fa9459Szrj if (! ISDIGIT (*p) || *p == '0') 4044*a9fa9459Szrj { 4045*a9fa9459Szrj stab_bad_demangle (orig); 4046*a9fa9459Szrj return FALSE; 4047*a9fa9459Szrj } 4048*a9fa9459Szrj qualifiers = atoi (p); 4049*a9fa9459Szrj while (ISDIGIT (*p)) 4050*a9fa9459Szrj ++p; 4051*a9fa9459Szrj if (*p != '_') 4052*a9fa9459Szrj { 4053*a9fa9459Szrj stab_bad_demangle (orig); 4054*a9fa9459Szrj return FALSE; 4055*a9fa9459Szrj } 4056*a9fa9459Szrj *pp = p + 1; 4057*a9fa9459Szrj break; 4058*a9fa9459Szrj 4059*a9fa9459Szrj case '1': case '2': case '3': case '4': case '5': 4060*a9fa9459Szrj case '6': case '7': case '8': case '9': 4061*a9fa9459Szrj qualifiers = (*pp)[1] - '0'; 4062*a9fa9459Szrj /* Skip an optional underscore after the count. */ 4063*a9fa9459Szrj if ((*pp)[2] == '_') 4064*a9fa9459Szrj ++*pp; 4065*a9fa9459Szrj *pp += 2; 4066*a9fa9459Szrj break; 4067*a9fa9459Szrj 4068*a9fa9459Szrj case '0': 4069*a9fa9459Szrj default: 4070*a9fa9459Szrj stab_bad_demangle (orig); 4071*a9fa9459Szrj return FALSE; 4072*a9fa9459Szrj } 4073*a9fa9459Szrj 4074*a9fa9459Szrj context = DEBUG_TYPE_NULL; 4075*a9fa9459Szrj 4076*a9fa9459Szrj /* Pick off the names. */ 4077*a9fa9459Szrj while (qualifiers-- > 0) 4078*a9fa9459Szrj { 4079*a9fa9459Szrj if (**pp == '_') 4080*a9fa9459Szrj ++*pp; 4081*a9fa9459Szrj if (**pp == 't') 4082*a9fa9459Szrj { 4083*a9fa9459Szrj char *name; 4084*a9fa9459Szrj 4085*a9fa9459Szrj if (! stab_demangle_template (minfo, pp, 4086*a9fa9459Szrj ptype != NULL ? &name : NULL)) 4087*a9fa9459Szrj return FALSE; 4088*a9fa9459Szrj 4089*a9fa9459Szrj if (ptype != NULL) 4090*a9fa9459Szrj { 4091*a9fa9459Szrj context = stab_find_tagged_type (minfo->dhandle, minfo->info, 4092*a9fa9459Szrj name, strlen (name), 4093*a9fa9459Szrj DEBUG_KIND_CLASS); 4094*a9fa9459Szrj free (name); 4095*a9fa9459Szrj if (context == DEBUG_TYPE_NULL) 4096*a9fa9459Szrj return FALSE; 4097*a9fa9459Szrj } 4098*a9fa9459Szrj } 4099*a9fa9459Szrj else 4100*a9fa9459Szrj { 4101*a9fa9459Szrj unsigned int len; 4102*a9fa9459Szrj 4103*a9fa9459Szrj len = stab_demangle_count (pp); 4104*a9fa9459Szrj if (strlen (*pp) < len) 4105*a9fa9459Szrj { 4106*a9fa9459Szrj stab_bad_demangle (orig); 4107*a9fa9459Szrj return FALSE; 4108*a9fa9459Szrj } 4109*a9fa9459Szrj 4110*a9fa9459Szrj if (ptype != NULL) 4111*a9fa9459Szrj { 4112*a9fa9459Szrj const debug_field *fields; 4113*a9fa9459Szrj 4114*a9fa9459Szrj fields = NULL; 4115*a9fa9459Szrj if (context != DEBUG_TYPE_NULL) 4116*a9fa9459Szrj fields = debug_get_fields (minfo->dhandle, context); 4117*a9fa9459Szrj 4118*a9fa9459Szrj context = DEBUG_TYPE_NULL; 4119*a9fa9459Szrj 4120*a9fa9459Szrj if (fields != NULL) 4121*a9fa9459Szrj { 4122*a9fa9459Szrj char *name; 4123*a9fa9459Szrj 4124*a9fa9459Szrj /* Try to find the type by looking through the 4125*a9fa9459Szrj fields of context until we find a field with the 4126*a9fa9459Szrj same type. This ought to work for a class 4127*a9fa9459Szrj defined within a class, but it won't work for, 4128*a9fa9459Szrj e.g., an enum defined within a class. stabs does 4129*a9fa9459Szrj not give us enough information to figure out the 4130*a9fa9459Szrj latter case. */ 4131*a9fa9459Szrj 4132*a9fa9459Szrj name = savestring (*pp, len); 4133*a9fa9459Szrj 4134*a9fa9459Szrj for (; *fields != DEBUG_FIELD_NULL; fields++) 4135*a9fa9459Szrj { 4136*a9fa9459Szrj debug_type ft; 4137*a9fa9459Szrj const char *dn; 4138*a9fa9459Szrj 4139*a9fa9459Szrj ft = debug_get_field_type (minfo->dhandle, *fields); 4140*a9fa9459Szrj if (ft == NULL) 4141*a9fa9459Szrj { 4142*a9fa9459Szrj free (name); 4143*a9fa9459Szrj return FALSE; 4144*a9fa9459Szrj } 4145*a9fa9459Szrj dn = debug_get_type_name (minfo->dhandle, ft); 4146*a9fa9459Szrj if (dn != NULL && strcmp (dn, name) == 0) 4147*a9fa9459Szrj { 4148*a9fa9459Szrj context = ft; 4149*a9fa9459Szrj break; 4150*a9fa9459Szrj } 4151*a9fa9459Szrj } 4152*a9fa9459Szrj 4153*a9fa9459Szrj free (name); 4154*a9fa9459Szrj } 4155*a9fa9459Szrj 4156*a9fa9459Szrj if (context == DEBUG_TYPE_NULL) 4157*a9fa9459Szrj { 4158*a9fa9459Szrj /* We have to fall back on finding the type by name. 4159*a9fa9459Szrj If there are more types to come, then this must 4160*a9fa9459Szrj be a class. Otherwise, it could be anything. */ 4161*a9fa9459Szrj 4162*a9fa9459Szrj if (qualifiers == 0) 4163*a9fa9459Szrj { 4164*a9fa9459Szrj char *name; 4165*a9fa9459Szrj 4166*a9fa9459Szrj name = savestring (*pp, len); 4167*a9fa9459Szrj context = debug_find_named_type (minfo->dhandle, 4168*a9fa9459Szrj name); 4169*a9fa9459Szrj free (name); 4170*a9fa9459Szrj } 4171*a9fa9459Szrj 4172*a9fa9459Szrj if (context == DEBUG_TYPE_NULL) 4173*a9fa9459Szrj { 4174*a9fa9459Szrj context = stab_find_tagged_type (minfo->dhandle, 4175*a9fa9459Szrj minfo->info, 4176*a9fa9459Szrj *pp, len, 4177*a9fa9459Szrj (qualifiers == 0 4178*a9fa9459Szrj ? DEBUG_KIND_ILLEGAL 4179*a9fa9459Szrj : DEBUG_KIND_CLASS)); 4180*a9fa9459Szrj if (context == DEBUG_TYPE_NULL) 4181*a9fa9459Szrj return FALSE; 4182*a9fa9459Szrj } 4183*a9fa9459Szrj } 4184*a9fa9459Szrj } 4185*a9fa9459Szrj 4186*a9fa9459Szrj *pp += len; 4187*a9fa9459Szrj } 4188*a9fa9459Szrj } 4189*a9fa9459Szrj 4190*a9fa9459Szrj if (ptype != NULL) 4191*a9fa9459Szrj *ptype = context; 4192*a9fa9459Szrj 4193*a9fa9459Szrj return TRUE; 4194*a9fa9459Szrj } 4195*a9fa9459Szrj 4196*a9fa9459Szrj /* Demangle a template. If PNAME is not NULL, this sets *PNAME to a 4197*a9fa9459Szrj string representation of the template. */ 4198*a9fa9459Szrj 4199*a9fa9459Szrj static bfd_boolean 4200*a9fa9459Szrj stab_demangle_template (struct stab_demangle_info *minfo, const char **pp, 4201*a9fa9459Szrj char **pname) 4202*a9fa9459Szrj { 4203*a9fa9459Szrj const char *orig; 4204*a9fa9459Szrj unsigned int r, i; 4205*a9fa9459Szrj 4206*a9fa9459Szrj orig = *pp; 4207*a9fa9459Szrj 4208*a9fa9459Szrj ++*pp; 4209*a9fa9459Szrj 4210*a9fa9459Szrj /* Skip the template name. */ 4211*a9fa9459Szrj r = stab_demangle_count (pp); 4212*a9fa9459Szrj if (r == 0 || strlen (*pp) < r) 4213*a9fa9459Szrj { 4214*a9fa9459Szrj stab_bad_demangle (orig); 4215*a9fa9459Szrj return FALSE; 4216*a9fa9459Szrj } 4217*a9fa9459Szrj *pp += r; 4218*a9fa9459Szrj 4219*a9fa9459Szrj /* Get the size of the parameter list. */ 4220*a9fa9459Szrj if (stab_demangle_get_count (pp, &r) == 0) 4221*a9fa9459Szrj { 4222*a9fa9459Szrj stab_bad_demangle (orig); 4223*a9fa9459Szrj return FALSE; 4224*a9fa9459Szrj } 4225*a9fa9459Szrj 4226*a9fa9459Szrj for (i = 0; i < r; i++) 4227*a9fa9459Szrj { 4228*a9fa9459Szrj if (**pp == 'Z') 4229*a9fa9459Szrj { 4230*a9fa9459Szrj /* This is a type parameter. */ 4231*a9fa9459Szrj ++*pp; 4232*a9fa9459Szrj if (! stab_demangle_type (minfo, pp, (debug_type *) NULL)) 4233*a9fa9459Szrj return FALSE; 4234*a9fa9459Szrj } 4235*a9fa9459Szrj else 4236*a9fa9459Szrj { 4237*a9fa9459Szrj const char *old_p; 4238*a9fa9459Szrj bfd_boolean pointerp, realp, integralp, charp, boolp; 4239*a9fa9459Szrj bfd_boolean done; 4240*a9fa9459Szrj 4241*a9fa9459Szrj old_p = *pp; 4242*a9fa9459Szrj pointerp = FALSE; 4243*a9fa9459Szrj realp = FALSE; 4244*a9fa9459Szrj integralp = FALSE; 4245*a9fa9459Szrj charp = FALSE; 4246*a9fa9459Szrj boolp = FALSE; 4247*a9fa9459Szrj done = FALSE; 4248*a9fa9459Szrj 4249*a9fa9459Szrj /* This is a value parameter. */ 4250*a9fa9459Szrj 4251*a9fa9459Szrj if (! stab_demangle_type (minfo, pp, (debug_type *) NULL)) 4252*a9fa9459Szrj return FALSE; 4253*a9fa9459Szrj 4254*a9fa9459Szrj while (*old_p != '\0' && ! done) 4255*a9fa9459Szrj { 4256*a9fa9459Szrj switch (*old_p) 4257*a9fa9459Szrj { 4258*a9fa9459Szrj case 'P': 4259*a9fa9459Szrj case 'p': 4260*a9fa9459Szrj case 'R': 4261*a9fa9459Szrj pointerp = TRUE; 4262*a9fa9459Szrj done = TRUE; 4263*a9fa9459Szrj break; 4264*a9fa9459Szrj case 'C': /* Const. */ 4265*a9fa9459Szrj case 'S': /* Signed. */ 4266*a9fa9459Szrj case 'U': /* Unsigned. */ 4267*a9fa9459Szrj case 'V': /* Volatile. */ 4268*a9fa9459Szrj case 'F': /* Function. */ 4269*a9fa9459Szrj case 'M': /* Member function. */ 4270*a9fa9459Szrj case 'O': /* ??? */ 4271*a9fa9459Szrj ++old_p; 4272*a9fa9459Szrj break; 4273*a9fa9459Szrj case 'Q': /* Qualified name. */ 4274*a9fa9459Szrj integralp = TRUE; 4275*a9fa9459Szrj done = TRUE; 4276*a9fa9459Szrj break; 4277*a9fa9459Szrj case 'T': /* Remembered type. */ 4278*a9fa9459Szrj abort (); 4279*a9fa9459Szrj case 'v': /* Void. */ 4280*a9fa9459Szrj abort (); 4281*a9fa9459Szrj case 'x': /* Long long. */ 4282*a9fa9459Szrj case 'l': /* Long. */ 4283*a9fa9459Szrj case 'i': /* Int. */ 4284*a9fa9459Szrj case 's': /* Short. */ 4285*a9fa9459Szrj case 'w': /* Wchar_t. */ 4286*a9fa9459Szrj integralp = TRUE; 4287*a9fa9459Szrj done = TRUE; 4288*a9fa9459Szrj break; 4289*a9fa9459Szrj case 'b': /* Bool. */ 4290*a9fa9459Szrj boolp = TRUE; 4291*a9fa9459Szrj done = TRUE; 4292*a9fa9459Szrj break; 4293*a9fa9459Szrj case 'c': /* Char. */ 4294*a9fa9459Szrj charp = TRUE; 4295*a9fa9459Szrj done = TRUE; 4296*a9fa9459Szrj break; 4297*a9fa9459Szrj case 'r': /* Long double. */ 4298*a9fa9459Szrj case 'd': /* Double. */ 4299*a9fa9459Szrj case 'f': /* Float. */ 4300*a9fa9459Szrj realp = TRUE; 4301*a9fa9459Szrj done = TRUE; 4302*a9fa9459Szrj break; 4303*a9fa9459Szrj default: 4304*a9fa9459Szrj /* Assume it's a user defined integral type. */ 4305*a9fa9459Szrj integralp = TRUE; 4306*a9fa9459Szrj done = TRUE; 4307*a9fa9459Szrj break; 4308*a9fa9459Szrj } 4309*a9fa9459Szrj } 4310*a9fa9459Szrj 4311*a9fa9459Szrj if (integralp) 4312*a9fa9459Szrj { 4313*a9fa9459Szrj if (**pp == 'm') 4314*a9fa9459Szrj ++*pp; 4315*a9fa9459Szrj while (ISDIGIT (**pp)) 4316*a9fa9459Szrj ++*pp; 4317*a9fa9459Szrj } 4318*a9fa9459Szrj else if (charp) 4319*a9fa9459Szrj { 4320*a9fa9459Szrj unsigned int val; 4321*a9fa9459Szrj 4322*a9fa9459Szrj if (**pp == 'm') 4323*a9fa9459Szrj ++*pp; 4324*a9fa9459Szrj val = stab_demangle_count (pp); 4325*a9fa9459Szrj if (val == 0) 4326*a9fa9459Szrj { 4327*a9fa9459Szrj stab_bad_demangle (orig); 4328*a9fa9459Szrj return FALSE; 4329*a9fa9459Szrj } 4330*a9fa9459Szrj } 4331*a9fa9459Szrj else if (boolp) 4332*a9fa9459Szrj { 4333*a9fa9459Szrj unsigned int val; 4334*a9fa9459Szrj 4335*a9fa9459Szrj val = stab_demangle_count (pp); 4336*a9fa9459Szrj if (val != 0 && val != 1) 4337*a9fa9459Szrj { 4338*a9fa9459Szrj stab_bad_demangle (orig); 4339*a9fa9459Szrj return FALSE; 4340*a9fa9459Szrj } 4341*a9fa9459Szrj } 4342*a9fa9459Szrj else if (realp) 4343*a9fa9459Szrj { 4344*a9fa9459Szrj if (**pp == 'm') 4345*a9fa9459Szrj ++*pp; 4346*a9fa9459Szrj while (ISDIGIT (**pp)) 4347*a9fa9459Szrj ++*pp; 4348*a9fa9459Szrj if (**pp == '.') 4349*a9fa9459Szrj { 4350*a9fa9459Szrj ++*pp; 4351*a9fa9459Szrj while (ISDIGIT (**pp)) 4352*a9fa9459Szrj ++*pp; 4353*a9fa9459Szrj } 4354*a9fa9459Szrj if (**pp == 'e') 4355*a9fa9459Szrj { 4356*a9fa9459Szrj ++*pp; 4357*a9fa9459Szrj while (ISDIGIT (**pp)) 4358*a9fa9459Szrj ++*pp; 4359*a9fa9459Szrj } 4360*a9fa9459Szrj } 4361*a9fa9459Szrj else if (pointerp) 4362*a9fa9459Szrj { 4363*a9fa9459Szrj unsigned int len; 4364*a9fa9459Szrj 4365*a9fa9459Szrj len = stab_demangle_count (pp); 4366*a9fa9459Szrj if (len == 0) 4367*a9fa9459Szrj { 4368*a9fa9459Szrj stab_bad_demangle (orig); 4369*a9fa9459Szrj return FALSE; 4370*a9fa9459Szrj } 4371*a9fa9459Szrj *pp += len; 4372*a9fa9459Szrj } 4373*a9fa9459Szrj } 4374*a9fa9459Szrj } 4375*a9fa9459Szrj 4376*a9fa9459Szrj /* We can translate this to a string fairly easily by invoking the 4377*a9fa9459Szrj regular demangling routine. */ 4378*a9fa9459Szrj if (pname != NULL) 4379*a9fa9459Szrj { 4380*a9fa9459Szrj char *s1, *s2, *s3, *s4 = NULL; 4381*a9fa9459Szrj char *from, *to; 4382*a9fa9459Szrj 4383*a9fa9459Szrj s1 = savestring (orig, *pp - orig); 4384*a9fa9459Szrj 4385*a9fa9459Szrj s2 = concat ("NoSuchStrinG__", s1, (const char *) NULL); 4386*a9fa9459Szrj 4387*a9fa9459Szrj free (s1); 4388*a9fa9459Szrj 4389*a9fa9459Szrj s3 = cplus_demangle (s2, DMGL_ANSI); 4390*a9fa9459Szrj 4391*a9fa9459Szrj free (s2); 4392*a9fa9459Szrj 4393*a9fa9459Szrj if (s3 != NULL) 4394*a9fa9459Szrj s4 = strstr (s3, "::NoSuchStrinG"); 4395*a9fa9459Szrj if (s3 == NULL || s4 == NULL) 4396*a9fa9459Szrj { 4397*a9fa9459Szrj stab_bad_demangle (orig); 4398*a9fa9459Szrj if (s3 != NULL) 4399*a9fa9459Szrj free (s3); 4400*a9fa9459Szrj return FALSE; 4401*a9fa9459Szrj } 4402*a9fa9459Szrj 4403*a9fa9459Szrj /* Eliminating all spaces, except those between > characters, 4404*a9fa9459Szrj makes it more likely that the demangled name will match the 4405*a9fa9459Szrj name which g++ used as the structure name. */ 4406*a9fa9459Szrj for (from = to = s3; from != s4; ++from) 4407*a9fa9459Szrj if (*from != ' ' 4408*a9fa9459Szrj || (from[1] == '>' && from > s3 && from[-1] == '>')) 4409*a9fa9459Szrj *to++ = *from; 4410*a9fa9459Szrj 4411*a9fa9459Szrj *pname = savestring (s3, to - s3); 4412*a9fa9459Szrj 4413*a9fa9459Szrj free (s3); 4414*a9fa9459Szrj } 4415*a9fa9459Szrj 4416*a9fa9459Szrj return TRUE; 4417*a9fa9459Szrj } 4418*a9fa9459Szrj 4419*a9fa9459Szrj /* Demangle a class name. */ 4420*a9fa9459Szrj 4421*a9fa9459Szrj static bfd_boolean 4422*a9fa9459Szrj stab_demangle_class (struct stab_demangle_info *minfo ATTRIBUTE_UNUSED, 4423*a9fa9459Szrj const char **pp, const char **pstart) 4424*a9fa9459Szrj { 4425*a9fa9459Szrj const char *orig; 4426*a9fa9459Szrj unsigned int n; 4427*a9fa9459Szrj 4428*a9fa9459Szrj orig = *pp; 4429*a9fa9459Szrj 4430*a9fa9459Szrj n = stab_demangle_count (pp); 4431*a9fa9459Szrj if (strlen (*pp) < n) 4432*a9fa9459Szrj { 4433*a9fa9459Szrj stab_bad_demangle (orig); 4434*a9fa9459Szrj return FALSE; 4435*a9fa9459Szrj } 4436*a9fa9459Szrj 4437*a9fa9459Szrj if (pstart != NULL) 4438*a9fa9459Szrj *pstart = *pp; 4439*a9fa9459Szrj 4440*a9fa9459Szrj *pp += n; 4441*a9fa9459Szrj 4442*a9fa9459Szrj return TRUE; 4443*a9fa9459Szrj } 4444*a9fa9459Szrj 4445*a9fa9459Szrj /* Demangle function arguments. If the pargs argument is not NULL, it 4446*a9fa9459Szrj is set to a NULL terminated array holding the arguments. */ 4447*a9fa9459Szrj 4448*a9fa9459Szrj static bfd_boolean 4449*a9fa9459Szrj stab_demangle_args (struct stab_demangle_info *minfo, const char **pp, 4450*a9fa9459Szrj debug_type **pargs, bfd_boolean *pvarargs) 4451*a9fa9459Szrj { 4452*a9fa9459Szrj const char *orig; 4453*a9fa9459Szrj unsigned int alloc, count; 4454*a9fa9459Szrj 4455*a9fa9459Szrj orig = *pp; 4456*a9fa9459Szrj 4457*a9fa9459Szrj alloc = 10; 4458*a9fa9459Szrj if (pargs != NULL) 4459*a9fa9459Szrj { 4460*a9fa9459Szrj *pargs = (debug_type *) xmalloc (alloc * sizeof **pargs); 4461*a9fa9459Szrj *pvarargs = FALSE; 4462*a9fa9459Szrj } 4463*a9fa9459Szrj count = 0; 4464*a9fa9459Szrj 4465*a9fa9459Szrj while (**pp != '_' && **pp != '\0' && **pp != 'e') 4466*a9fa9459Szrj { 4467*a9fa9459Szrj if (**pp == 'N' || **pp == 'T') 4468*a9fa9459Szrj { 4469*a9fa9459Szrj char temptype; 4470*a9fa9459Szrj unsigned int r, t; 4471*a9fa9459Szrj 4472*a9fa9459Szrj temptype = **pp; 4473*a9fa9459Szrj ++*pp; 4474*a9fa9459Szrj 4475*a9fa9459Szrj if (temptype == 'T') 4476*a9fa9459Szrj r = 1; 4477*a9fa9459Szrj else 4478*a9fa9459Szrj { 4479*a9fa9459Szrj if (! stab_demangle_get_count (pp, &r)) 4480*a9fa9459Szrj { 4481*a9fa9459Szrj stab_bad_demangle (orig); 4482*a9fa9459Szrj return FALSE; 4483*a9fa9459Szrj } 4484*a9fa9459Szrj } 4485*a9fa9459Szrj 4486*a9fa9459Szrj if (! stab_demangle_get_count (pp, &t)) 4487*a9fa9459Szrj { 4488*a9fa9459Szrj stab_bad_demangle (orig); 4489*a9fa9459Szrj return FALSE; 4490*a9fa9459Szrj } 4491*a9fa9459Szrj 4492*a9fa9459Szrj if (t >= minfo->typestring_count) 4493*a9fa9459Szrj { 4494*a9fa9459Szrj stab_bad_demangle (orig); 4495*a9fa9459Szrj return FALSE; 4496*a9fa9459Szrj } 4497*a9fa9459Szrj while (r-- > 0) 4498*a9fa9459Szrj { 4499*a9fa9459Szrj const char *tem; 4500*a9fa9459Szrj 4501*a9fa9459Szrj tem = minfo->typestrings[t].typestring; 4502*a9fa9459Szrj if (! stab_demangle_arg (minfo, &tem, pargs, &count, &alloc)) 4503*a9fa9459Szrj return FALSE; 4504*a9fa9459Szrj } 4505*a9fa9459Szrj } 4506*a9fa9459Szrj else 4507*a9fa9459Szrj { 4508*a9fa9459Szrj if (! stab_demangle_arg (minfo, pp, pargs, &count, &alloc)) 4509*a9fa9459Szrj return FALSE; 4510*a9fa9459Szrj } 4511*a9fa9459Szrj } 4512*a9fa9459Szrj 4513*a9fa9459Szrj if (pargs != NULL) 4514*a9fa9459Szrj (*pargs)[count] = DEBUG_TYPE_NULL; 4515*a9fa9459Szrj 4516*a9fa9459Szrj if (**pp == 'e') 4517*a9fa9459Szrj { 4518*a9fa9459Szrj if (pargs != NULL) 4519*a9fa9459Szrj *pvarargs = TRUE; 4520*a9fa9459Szrj ++*pp; 4521*a9fa9459Szrj } 4522*a9fa9459Szrj 4523*a9fa9459Szrj return TRUE; 4524*a9fa9459Szrj } 4525*a9fa9459Szrj 4526*a9fa9459Szrj /* Demangle a single argument. */ 4527*a9fa9459Szrj 4528*a9fa9459Szrj static bfd_boolean 4529*a9fa9459Szrj stab_demangle_arg (struct stab_demangle_info *minfo, const char **pp, 4530*a9fa9459Szrj debug_type **pargs, unsigned int *pcount, 4531*a9fa9459Szrj unsigned int *palloc) 4532*a9fa9459Szrj { 4533*a9fa9459Szrj const char *start; 4534*a9fa9459Szrj debug_type type; 4535*a9fa9459Szrj 4536*a9fa9459Szrj start = *pp; 4537*a9fa9459Szrj if (! stab_demangle_type (minfo, pp, 4538*a9fa9459Szrj pargs == NULL ? (debug_type *) NULL : &type) 4539*a9fa9459Szrj || ! stab_demangle_remember_type (minfo, start, *pp - start)) 4540*a9fa9459Szrj return FALSE; 4541*a9fa9459Szrj 4542*a9fa9459Szrj if (pargs != NULL) 4543*a9fa9459Szrj { 4544*a9fa9459Szrj if (type == DEBUG_TYPE_NULL) 4545*a9fa9459Szrj return FALSE; 4546*a9fa9459Szrj 4547*a9fa9459Szrj if (*pcount + 1 >= *palloc) 4548*a9fa9459Szrj { 4549*a9fa9459Szrj *palloc += 10; 4550*a9fa9459Szrj *pargs = ((debug_type *) 4551*a9fa9459Szrj xrealloc (*pargs, *palloc * sizeof **pargs)); 4552*a9fa9459Szrj } 4553*a9fa9459Szrj (*pargs)[*pcount] = type; 4554*a9fa9459Szrj ++*pcount; 4555*a9fa9459Szrj } 4556*a9fa9459Szrj 4557*a9fa9459Szrj return TRUE; 4558*a9fa9459Szrj } 4559*a9fa9459Szrj 4560*a9fa9459Szrj /* Demangle a type. If the ptype argument is not NULL, *ptype is set 4561*a9fa9459Szrj to the newly allocated type. */ 4562*a9fa9459Szrj 4563*a9fa9459Szrj static bfd_boolean 4564*a9fa9459Szrj stab_demangle_type (struct stab_demangle_info *minfo, const char **pp, 4565*a9fa9459Szrj debug_type *ptype) 4566*a9fa9459Szrj { 4567*a9fa9459Szrj const char *orig; 4568*a9fa9459Szrj 4569*a9fa9459Szrj orig = *pp; 4570*a9fa9459Szrj 4571*a9fa9459Szrj switch (**pp) 4572*a9fa9459Szrj { 4573*a9fa9459Szrj case 'P': 4574*a9fa9459Szrj case 'p': 4575*a9fa9459Szrj /* A pointer type. */ 4576*a9fa9459Szrj ++*pp; 4577*a9fa9459Szrj if (! stab_demangle_type (minfo, pp, ptype)) 4578*a9fa9459Szrj return FALSE; 4579*a9fa9459Szrj if (ptype != NULL) 4580*a9fa9459Szrj *ptype = debug_make_pointer_type (minfo->dhandle, *ptype); 4581*a9fa9459Szrj break; 4582*a9fa9459Szrj 4583*a9fa9459Szrj case 'R': 4584*a9fa9459Szrj /* A reference type. */ 4585*a9fa9459Szrj ++*pp; 4586*a9fa9459Szrj if (! stab_demangle_type (minfo, pp, ptype)) 4587*a9fa9459Szrj return FALSE; 4588*a9fa9459Szrj if (ptype != NULL) 4589*a9fa9459Szrj *ptype = debug_make_reference_type (minfo->dhandle, *ptype); 4590*a9fa9459Szrj break; 4591*a9fa9459Szrj 4592*a9fa9459Szrj case 'A': 4593*a9fa9459Szrj /* An array. */ 4594*a9fa9459Szrj { 4595*a9fa9459Szrj unsigned long high; 4596*a9fa9459Szrj 4597*a9fa9459Szrj ++*pp; 4598*a9fa9459Szrj high = 0; 4599*a9fa9459Szrj while (**pp != '\0' && **pp != '_') 4600*a9fa9459Szrj { 4601*a9fa9459Szrj if (! ISDIGIT (**pp)) 4602*a9fa9459Szrj { 4603*a9fa9459Szrj stab_bad_demangle (orig); 4604*a9fa9459Szrj return FALSE; 4605*a9fa9459Szrj } 4606*a9fa9459Szrj high *= 10; 4607*a9fa9459Szrj high += **pp - '0'; 4608*a9fa9459Szrj ++*pp; 4609*a9fa9459Szrj } 4610*a9fa9459Szrj if (**pp != '_') 4611*a9fa9459Szrj { 4612*a9fa9459Szrj stab_bad_demangle (orig); 4613*a9fa9459Szrj return FALSE; 4614*a9fa9459Szrj } 4615*a9fa9459Szrj ++*pp; 4616*a9fa9459Szrj 4617*a9fa9459Szrj if (! stab_demangle_type (minfo, pp, ptype)) 4618*a9fa9459Szrj return FALSE; 4619*a9fa9459Szrj if (ptype != NULL) 4620*a9fa9459Szrj { 4621*a9fa9459Szrj debug_type int_type; 4622*a9fa9459Szrj 4623*a9fa9459Szrj int_type = debug_find_named_type (minfo->dhandle, "int"); 4624*a9fa9459Szrj if (int_type == NULL) 4625*a9fa9459Szrj int_type = debug_make_int_type (minfo->dhandle, 4, FALSE); 4626*a9fa9459Szrj *ptype = debug_make_array_type (minfo->dhandle, *ptype, int_type, 4627*a9fa9459Szrj 0, high, FALSE); 4628*a9fa9459Szrj } 4629*a9fa9459Szrj } 4630*a9fa9459Szrj break; 4631*a9fa9459Szrj 4632*a9fa9459Szrj case 'T': 4633*a9fa9459Szrj /* A back reference to a remembered type. */ 4634*a9fa9459Szrj { 4635*a9fa9459Szrj unsigned int i; 4636*a9fa9459Szrj const char *p; 4637*a9fa9459Szrj 4638*a9fa9459Szrj ++*pp; 4639*a9fa9459Szrj if (! stab_demangle_get_count (pp, &i)) 4640*a9fa9459Szrj { 4641*a9fa9459Szrj stab_bad_demangle (orig); 4642*a9fa9459Szrj return FALSE; 4643*a9fa9459Szrj } 4644*a9fa9459Szrj if (i >= minfo->typestring_count) 4645*a9fa9459Szrj { 4646*a9fa9459Szrj stab_bad_demangle (orig); 4647*a9fa9459Szrj return FALSE; 4648*a9fa9459Szrj } 4649*a9fa9459Szrj p = minfo->typestrings[i].typestring; 4650*a9fa9459Szrj if (! stab_demangle_type (minfo, &p, ptype)) 4651*a9fa9459Szrj return FALSE; 4652*a9fa9459Szrj } 4653*a9fa9459Szrj break; 4654*a9fa9459Szrj 4655*a9fa9459Szrj case 'F': 4656*a9fa9459Szrj /* A function. */ 4657*a9fa9459Szrj { 4658*a9fa9459Szrj debug_type *args; 4659*a9fa9459Szrj bfd_boolean varargs; 4660*a9fa9459Szrj 4661*a9fa9459Szrj ++*pp; 4662*a9fa9459Szrj if (! stab_demangle_args (minfo, pp, 4663*a9fa9459Szrj (ptype == NULL 4664*a9fa9459Szrj ? (debug_type **) NULL 4665*a9fa9459Szrj : &args), 4666*a9fa9459Szrj (ptype == NULL 4667*a9fa9459Szrj ? (bfd_boolean *) NULL 4668*a9fa9459Szrj : &varargs))) 4669*a9fa9459Szrj return FALSE; 4670*a9fa9459Szrj if (**pp != '_') 4671*a9fa9459Szrj { 4672*a9fa9459Szrj /* cplus_demangle will accept a function without a return 4673*a9fa9459Szrj type, but I don't know when that will happen, or what 4674*a9fa9459Szrj to do if it does. */ 4675*a9fa9459Szrj stab_bad_demangle (orig); 4676*a9fa9459Szrj return FALSE; 4677*a9fa9459Szrj } 4678*a9fa9459Szrj ++*pp; 4679*a9fa9459Szrj if (! stab_demangle_type (minfo, pp, ptype)) 4680*a9fa9459Szrj return FALSE; 4681*a9fa9459Szrj if (ptype != NULL) 4682*a9fa9459Szrj *ptype = debug_make_function_type (minfo->dhandle, *ptype, args, 4683*a9fa9459Szrj varargs); 4684*a9fa9459Szrj 4685*a9fa9459Szrj } 4686*a9fa9459Szrj break; 4687*a9fa9459Szrj 4688*a9fa9459Szrj case 'M': 4689*a9fa9459Szrj case 'O': 4690*a9fa9459Szrj { 4691*a9fa9459Szrj bfd_boolean memberp; 4692*a9fa9459Szrj debug_type class_type = DEBUG_TYPE_NULL; 4693*a9fa9459Szrj debug_type *args; 4694*a9fa9459Szrj bfd_boolean varargs; 4695*a9fa9459Szrj unsigned int n; 4696*a9fa9459Szrj const char *name; 4697*a9fa9459Szrj 4698*a9fa9459Szrj memberp = **pp == 'M'; 4699*a9fa9459Szrj args = NULL; 4700*a9fa9459Szrj varargs = FALSE; 4701*a9fa9459Szrj 4702*a9fa9459Szrj ++*pp; 4703*a9fa9459Szrj if (ISDIGIT (**pp)) 4704*a9fa9459Szrj { 4705*a9fa9459Szrj n = stab_demangle_count (pp); 4706*a9fa9459Szrj if (strlen (*pp) < n) 4707*a9fa9459Szrj { 4708*a9fa9459Szrj stab_bad_demangle (orig); 4709*a9fa9459Szrj return FALSE; 4710*a9fa9459Szrj } 4711*a9fa9459Szrj name = *pp; 4712*a9fa9459Szrj *pp += n; 4713*a9fa9459Szrj 4714*a9fa9459Szrj if (ptype != NULL) 4715*a9fa9459Szrj { 4716*a9fa9459Szrj class_type = stab_find_tagged_type (minfo->dhandle, 4717*a9fa9459Szrj minfo->info, 4718*a9fa9459Szrj name, (int) n, 4719*a9fa9459Szrj DEBUG_KIND_CLASS); 4720*a9fa9459Szrj if (class_type == DEBUG_TYPE_NULL) 4721*a9fa9459Szrj return FALSE; 4722*a9fa9459Szrj } 4723*a9fa9459Szrj } 4724*a9fa9459Szrj else if (**pp == 'Q') 4725*a9fa9459Szrj { 4726*a9fa9459Szrj if (! stab_demangle_qualified (minfo, pp, 4727*a9fa9459Szrj (ptype == NULL 4728*a9fa9459Szrj ? (debug_type *) NULL 4729*a9fa9459Szrj : &class_type))) 4730*a9fa9459Szrj return FALSE; 4731*a9fa9459Szrj } 4732*a9fa9459Szrj else 4733*a9fa9459Szrj { 4734*a9fa9459Szrj stab_bad_demangle (orig); 4735*a9fa9459Szrj return FALSE; 4736*a9fa9459Szrj } 4737*a9fa9459Szrj 4738*a9fa9459Szrj if (memberp) 4739*a9fa9459Szrj { 4740*a9fa9459Szrj if (**pp == 'C') 4741*a9fa9459Szrj { 4742*a9fa9459Szrj ++*pp; 4743*a9fa9459Szrj } 4744*a9fa9459Szrj else if (**pp == 'V') 4745*a9fa9459Szrj { 4746*a9fa9459Szrj ++*pp; 4747*a9fa9459Szrj } 4748*a9fa9459Szrj if (**pp != 'F') 4749*a9fa9459Szrj { 4750*a9fa9459Szrj stab_bad_demangle (orig); 4751*a9fa9459Szrj return FALSE; 4752*a9fa9459Szrj } 4753*a9fa9459Szrj ++*pp; 4754*a9fa9459Szrj if (! stab_demangle_args (minfo, pp, 4755*a9fa9459Szrj (ptype == NULL 4756*a9fa9459Szrj ? (debug_type **) NULL 4757*a9fa9459Szrj : &args), 4758*a9fa9459Szrj (ptype == NULL 4759*a9fa9459Szrj ? (bfd_boolean *) NULL 4760*a9fa9459Szrj : &varargs))) 4761*a9fa9459Szrj return FALSE; 4762*a9fa9459Szrj } 4763*a9fa9459Szrj 4764*a9fa9459Szrj if (**pp != '_') 4765*a9fa9459Szrj { 4766*a9fa9459Szrj stab_bad_demangle (orig); 4767*a9fa9459Szrj return FALSE; 4768*a9fa9459Szrj } 4769*a9fa9459Szrj ++*pp; 4770*a9fa9459Szrj 4771*a9fa9459Szrj if (! stab_demangle_type (minfo, pp, ptype)) 4772*a9fa9459Szrj return FALSE; 4773*a9fa9459Szrj 4774*a9fa9459Szrj if (ptype != NULL) 4775*a9fa9459Szrj { 4776*a9fa9459Szrj if (! memberp) 4777*a9fa9459Szrj *ptype = debug_make_offset_type (minfo->dhandle, class_type, 4778*a9fa9459Szrj *ptype); 4779*a9fa9459Szrj else 4780*a9fa9459Szrj { 4781*a9fa9459Szrj /* FIXME: We have no way to record constp or 4782*a9fa9459Szrj volatilep. */ 4783*a9fa9459Szrj *ptype = debug_make_method_type (minfo->dhandle, *ptype, 4784*a9fa9459Szrj class_type, args, varargs); 4785*a9fa9459Szrj } 4786*a9fa9459Szrj } 4787*a9fa9459Szrj } 4788*a9fa9459Szrj break; 4789*a9fa9459Szrj 4790*a9fa9459Szrj case 'G': 4791*a9fa9459Szrj ++*pp; 4792*a9fa9459Szrj if (! stab_demangle_type (minfo, pp, ptype)) 4793*a9fa9459Szrj return FALSE; 4794*a9fa9459Szrj break; 4795*a9fa9459Szrj 4796*a9fa9459Szrj case 'C': 4797*a9fa9459Szrj ++*pp; 4798*a9fa9459Szrj if (! stab_demangle_type (minfo, pp, ptype)) 4799*a9fa9459Szrj return FALSE; 4800*a9fa9459Szrj if (ptype != NULL) 4801*a9fa9459Szrj *ptype = debug_make_const_type (minfo->dhandle, *ptype); 4802*a9fa9459Szrj break; 4803*a9fa9459Szrj 4804*a9fa9459Szrj case 'Q': 4805*a9fa9459Szrj { 4806*a9fa9459Szrj if (! stab_demangle_qualified (minfo, pp, ptype)) 4807*a9fa9459Szrj return FALSE; 4808*a9fa9459Szrj } 4809*a9fa9459Szrj break; 4810*a9fa9459Szrj 4811*a9fa9459Szrj default: 4812*a9fa9459Szrj if (! stab_demangle_fund_type (minfo, pp, ptype)) 4813*a9fa9459Szrj return FALSE; 4814*a9fa9459Szrj break; 4815*a9fa9459Szrj } 4816*a9fa9459Szrj 4817*a9fa9459Szrj return TRUE; 4818*a9fa9459Szrj } 4819*a9fa9459Szrj 4820*a9fa9459Szrj /* Demangle a fundamental type. If the ptype argument is not NULL, 4821*a9fa9459Szrj *ptype is set to the newly allocated type. */ 4822*a9fa9459Szrj 4823*a9fa9459Szrj static bfd_boolean 4824*a9fa9459Szrj stab_demangle_fund_type (struct stab_demangle_info *minfo, const char **pp, 4825*a9fa9459Szrj debug_type *ptype) 4826*a9fa9459Szrj { 4827*a9fa9459Szrj const char *orig; 4828*a9fa9459Szrj bfd_boolean constp, volatilep, unsignedp, signedp; 4829*a9fa9459Szrj bfd_boolean done; 4830*a9fa9459Szrj 4831*a9fa9459Szrj orig = *pp; 4832*a9fa9459Szrj 4833*a9fa9459Szrj constp = FALSE; 4834*a9fa9459Szrj volatilep = FALSE; 4835*a9fa9459Szrj unsignedp = FALSE; 4836*a9fa9459Szrj signedp = FALSE; 4837*a9fa9459Szrj 4838*a9fa9459Szrj done = FALSE; 4839*a9fa9459Szrj while (! done) 4840*a9fa9459Szrj { 4841*a9fa9459Szrj switch (**pp) 4842*a9fa9459Szrj { 4843*a9fa9459Szrj case 'C': 4844*a9fa9459Szrj constp = TRUE; 4845*a9fa9459Szrj ++*pp; 4846*a9fa9459Szrj break; 4847*a9fa9459Szrj 4848*a9fa9459Szrj case 'U': 4849*a9fa9459Szrj unsignedp = TRUE; 4850*a9fa9459Szrj ++*pp; 4851*a9fa9459Szrj break; 4852*a9fa9459Szrj 4853*a9fa9459Szrj case 'S': 4854*a9fa9459Szrj signedp = TRUE; 4855*a9fa9459Szrj ++*pp; 4856*a9fa9459Szrj break; 4857*a9fa9459Szrj 4858*a9fa9459Szrj case 'V': 4859*a9fa9459Szrj volatilep = TRUE; 4860*a9fa9459Szrj ++*pp; 4861*a9fa9459Szrj break; 4862*a9fa9459Szrj 4863*a9fa9459Szrj default: 4864*a9fa9459Szrj done = TRUE; 4865*a9fa9459Szrj break; 4866*a9fa9459Szrj } 4867*a9fa9459Szrj } 4868*a9fa9459Szrj 4869*a9fa9459Szrj switch (**pp) 4870*a9fa9459Szrj { 4871*a9fa9459Szrj case '\0': 4872*a9fa9459Szrj case '_': 4873*a9fa9459Szrj /* cplus_demangle permits this, but I don't know what it means. */ 4874*a9fa9459Szrj stab_bad_demangle (orig); 4875*a9fa9459Szrj break; 4876*a9fa9459Szrj 4877*a9fa9459Szrj case 'v': /* void */ 4878*a9fa9459Szrj if (ptype != NULL) 4879*a9fa9459Szrj { 4880*a9fa9459Szrj *ptype = debug_find_named_type (minfo->dhandle, "void"); 4881*a9fa9459Szrj if (*ptype == DEBUG_TYPE_NULL) 4882*a9fa9459Szrj *ptype = debug_make_void_type (minfo->dhandle); 4883*a9fa9459Szrj } 4884*a9fa9459Szrj ++*pp; 4885*a9fa9459Szrj break; 4886*a9fa9459Szrj 4887*a9fa9459Szrj case 'x': /* long long */ 4888*a9fa9459Szrj if (ptype != NULL) 4889*a9fa9459Szrj { 4890*a9fa9459Szrj *ptype = debug_find_named_type (minfo->dhandle, 4891*a9fa9459Szrj (unsignedp 4892*a9fa9459Szrj ? "long long unsigned int" 4893*a9fa9459Szrj : "long long int")); 4894*a9fa9459Szrj if (*ptype == DEBUG_TYPE_NULL) 4895*a9fa9459Szrj *ptype = debug_make_int_type (minfo->dhandle, 8, unsignedp); 4896*a9fa9459Szrj } 4897*a9fa9459Szrj ++*pp; 4898*a9fa9459Szrj break; 4899*a9fa9459Szrj 4900*a9fa9459Szrj case 'l': /* long */ 4901*a9fa9459Szrj if (ptype != NULL) 4902*a9fa9459Szrj { 4903*a9fa9459Szrj *ptype = debug_find_named_type (minfo->dhandle, 4904*a9fa9459Szrj (unsignedp 4905*a9fa9459Szrj ? "long unsigned int" 4906*a9fa9459Szrj : "long int")); 4907*a9fa9459Szrj if (*ptype == DEBUG_TYPE_NULL) 4908*a9fa9459Szrj *ptype = debug_make_int_type (minfo->dhandle, 4, unsignedp); 4909*a9fa9459Szrj } 4910*a9fa9459Szrj ++*pp; 4911*a9fa9459Szrj break; 4912*a9fa9459Szrj 4913*a9fa9459Szrj case 'i': /* int */ 4914*a9fa9459Szrj if (ptype != NULL) 4915*a9fa9459Szrj { 4916*a9fa9459Szrj *ptype = debug_find_named_type (minfo->dhandle, 4917*a9fa9459Szrj (unsignedp 4918*a9fa9459Szrj ? "unsigned int" 4919*a9fa9459Szrj : "int")); 4920*a9fa9459Szrj if (*ptype == DEBUG_TYPE_NULL) 4921*a9fa9459Szrj *ptype = debug_make_int_type (minfo->dhandle, 4, unsignedp); 4922*a9fa9459Szrj } 4923*a9fa9459Szrj ++*pp; 4924*a9fa9459Szrj break; 4925*a9fa9459Szrj 4926*a9fa9459Szrj case 's': /* short */ 4927*a9fa9459Szrj if (ptype != NULL) 4928*a9fa9459Szrj { 4929*a9fa9459Szrj *ptype = debug_find_named_type (minfo->dhandle, 4930*a9fa9459Szrj (unsignedp 4931*a9fa9459Szrj ? "short unsigned int" 4932*a9fa9459Szrj : "short int")); 4933*a9fa9459Szrj if (*ptype == DEBUG_TYPE_NULL) 4934*a9fa9459Szrj *ptype = debug_make_int_type (minfo->dhandle, 2, unsignedp); 4935*a9fa9459Szrj } 4936*a9fa9459Szrj ++*pp; 4937*a9fa9459Szrj break; 4938*a9fa9459Szrj 4939*a9fa9459Szrj case 'b': /* bool */ 4940*a9fa9459Szrj if (ptype != NULL) 4941*a9fa9459Szrj { 4942*a9fa9459Szrj *ptype = debug_find_named_type (minfo->dhandle, "bool"); 4943*a9fa9459Szrj if (*ptype == DEBUG_TYPE_NULL) 4944*a9fa9459Szrj *ptype = debug_make_bool_type (minfo->dhandle, 4); 4945*a9fa9459Szrj } 4946*a9fa9459Szrj ++*pp; 4947*a9fa9459Szrj break; 4948*a9fa9459Szrj 4949*a9fa9459Szrj case 'c': /* char */ 4950*a9fa9459Szrj if (ptype != NULL) 4951*a9fa9459Szrj { 4952*a9fa9459Szrj *ptype = debug_find_named_type (minfo->dhandle, 4953*a9fa9459Szrj (unsignedp 4954*a9fa9459Szrj ? "unsigned char" 4955*a9fa9459Szrj : (signedp 4956*a9fa9459Szrj ? "signed char" 4957*a9fa9459Szrj : "char"))); 4958*a9fa9459Szrj if (*ptype == DEBUG_TYPE_NULL) 4959*a9fa9459Szrj *ptype = debug_make_int_type (minfo->dhandle, 1, unsignedp); 4960*a9fa9459Szrj } 4961*a9fa9459Szrj ++*pp; 4962*a9fa9459Szrj break; 4963*a9fa9459Szrj 4964*a9fa9459Szrj case 'w': /* wchar_t */ 4965*a9fa9459Szrj if (ptype != NULL) 4966*a9fa9459Szrj { 4967*a9fa9459Szrj *ptype = debug_find_named_type (minfo->dhandle, "__wchar_t"); 4968*a9fa9459Szrj if (*ptype == DEBUG_TYPE_NULL) 4969*a9fa9459Szrj *ptype = debug_make_int_type (minfo->dhandle, 2, TRUE); 4970*a9fa9459Szrj } 4971*a9fa9459Szrj ++*pp; 4972*a9fa9459Szrj break; 4973*a9fa9459Szrj 4974*a9fa9459Szrj case 'r': /* long double */ 4975*a9fa9459Szrj if (ptype != NULL) 4976*a9fa9459Szrj { 4977*a9fa9459Szrj *ptype = debug_find_named_type (minfo->dhandle, "long double"); 4978*a9fa9459Szrj if (*ptype == DEBUG_TYPE_NULL) 4979*a9fa9459Szrj *ptype = debug_make_float_type (minfo->dhandle, 8); 4980*a9fa9459Szrj } 4981*a9fa9459Szrj ++*pp; 4982*a9fa9459Szrj break; 4983*a9fa9459Szrj 4984*a9fa9459Szrj case 'd': /* double */ 4985*a9fa9459Szrj if (ptype != NULL) 4986*a9fa9459Szrj { 4987*a9fa9459Szrj *ptype = debug_find_named_type (minfo->dhandle, "double"); 4988*a9fa9459Szrj if (*ptype == DEBUG_TYPE_NULL) 4989*a9fa9459Szrj *ptype = debug_make_float_type (minfo->dhandle, 8); 4990*a9fa9459Szrj } 4991*a9fa9459Szrj ++*pp; 4992*a9fa9459Szrj break; 4993*a9fa9459Szrj 4994*a9fa9459Szrj case 'f': /* float */ 4995*a9fa9459Szrj if (ptype != NULL) 4996*a9fa9459Szrj { 4997*a9fa9459Szrj *ptype = debug_find_named_type (minfo->dhandle, "float"); 4998*a9fa9459Szrj if (*ptype == DEBUG_TYPE_NULL) 4999*a9fa9459Szrj *ptype = debug_make_float_type (minfo->dhandle, 4); 5000*a9fa9459Szrj } 5001*a9fa9459Szrj ++*pp; 5002*a9fa9459Szrj break; 5003*a9fa9459Szrj 5004*a9fa9459Szrj case 'G': 5005*a9fa9459Szrj ++*pp; 5006*a9fa9459Szrj if (! ISDIGIT (**pp)) 5007*a9fa9459Szrj { 5008*a9fa9459Szrj stab_bad_demangle (orig); 5009*a9fa9459Szrj return FALSE; 5010*a9fa9459Szrj } 5011*a9fa9459Szrj /* Fall through. */ 5012*a9fa9459Szrj case '0': case '1': case '2': case '3': case '4': 5013*a9fa9459Szrj case '5': case '6': case '7': case '8': case '9': 5014*a9fa9459Szrj { 5015*a9fa9459Szrj const char *hold; 5016*a9fa9459Szrj 5017*a9fa9459Szrj if (! stab_demangle_class (minfo, pp, &hold)) 5018*a9fa9459Szrj return FALSE; 5019*a9fa9459Szrj if (ptype != NULL) 5020*a9fa9459Szrj { 5021*a9fa9459Szrj char *name; 5022*a9fa9459Szrj 5023*a9fa9459Szrj name = savestring (hold, *pp - hold); 5024*a9fa9459Szrj *ptype = debug_find_named_type (minfo->dhandle, name); 5025*a9fa9459Szrj free (name); 5026*a9fa9459Szrj if (*ptype == DEBUG_TYPE_NULL) 5027*a9fa9459Szrj { 5028*a9fa9459Szrj /* FIXME: It is probably incorrect to assume that 5029*a9fa9459Szrj undefined types are tagged types. */ 5030*a9fa9459Szrj *ptype = stab_find_tagged_type (minfo->dhandle, minfo->info, 5031*a9fa9459Szrj hold, *pp - hold, 5032*a9fa9459Szrj DEBUG_KIND_ILLEGAL); 5033*a9fa9459Szrj if (*ptype == DEBUG_TYPE_NULL) 5034*a9fa9459Szrj return FALSE; 5035*a9fa9459Szrj } 5036*a9fa9459Szrj } 5037*a9fa9459Szrj } 5038*a9fa9459Szrj break; 5039*a9fa9459Szrj 5040*a9fa9459Szrj case 't': 5041*a9fa9459Szrj { 5042*a9fa9459Szrj char *name; 5043*a9fa9459Szrj 5044*a9fa9459Szrj if (! stab_demangle_template (minfo, pp, 5045*a9fa9459Szrj ptype != NULL ? &name : NULL)) 5046*a9fa9459Szrj return FALSE; 5047*a9fa9459Szrj if (ptype != NULL) 5048*a9fa9459Szrj { 5049*a9fa9459Szrj *ptype = stab_find_tagged_type (minfo->dhandle, minfo->info, 5050*a9fa9459Szrj name, strlen (name), 5051*a9fa9459Szrj DEBUG_KIND_CLASS); 5052*a9fa9459Szrj free (name); 5053*a9fa9459Szrj if (*ptype == DEBUG_TYPE_NULL) 5054*a9fa9459Szrj return FALSE; 5055*a9fa9459Szrj } 5056*a9fa9459Szrj } 5057*a9fa9459Szrj break; 5058*a9fa9459Szrj 5059*a9fa9459Szrj default: 5060*a9fa9459Szrj stab_bad_demangle (orig); 5061*a9fa9459Szrj return FALSE; 5062*a9fa9459Szrj } 5063*a9fa9459Szrj 5064*a9fa9459Szrj if (ptype != NULL) 5065*a9fa9459Szrj { 5066*a9fa9459Szrj if (constp) 5067*a9fa9459Szrj *ptype = debug_make_const_type (minfo->dhandle, *ptype); 5068*a9fa9459Szrj if (volatilep) 5069*a9fa9459Szrj *ptype = debug_make_volatile_type (minfo->dhandle, *ptype); 5070*a9fa9459Szrj } 5071*a9fa9459Szrj 5072*a9fa9459Szrj return TRUE; 5073*a9fa9459Szrj } 5074*a9fa9459Szrj 5075*a9fa9459Szrj /* Remember a type string in a demangled string. */ 5076*a9fa9459Szrj 5077*a9fa9459Szrj static bfd_boolean 5078*a9fa9459Szrj stab_demangle_remember_type (struct stab_demangle_info *minfo, 5079*a9fa9459Szrj const char *p, int len) 5080*a9fa9459Szrj { 5081*a9fa9459Szrj if (minfo->typestring_count >= minfo->typestring_alloc) 5082*a9fa9459Szrj { 5083*a9fa9459Szrj minfo->typestring_alloc += 10; 5084*a9fa9459Szrj minfo->typestrings = ((struct stab_demangle_typestring *) 5085*a9fa9459Szrj xrealloc (minfo->typestrings, 5086*a9fa9459Szrj (minfo->typestring_alloc 5087*a9fa9459Szrj * sizeof *minfo->typestrings))); 5088*a9fa9459Szrj } 5089*a9fa9459Szrj 5090*a9fa9459Szrj minfo->typestrings[minfo->typestring_count].typestring = p; 5091*a9fa9459Szrj minfo->typestrings[minfo->typestring_count].len = (unsigned int) len; 5092*a9fa9459Szrj ++minfo->typestring_count; 5093*a9fa9459Szrj 5094*a9fa9459Szrj return TRUE; 5095*a9fa9459Szrj } 5096*a9fa9459Szrj 5097*a9fa9459Szrj /* Demangle names encoded using the g++ V3 ABI. The newer versions of 5098*a9fa9459Szrj g++ which use this ABI do not encode ordinary method argument types 5099*a9fa9459Szrj in a mangled name; they simply output the argument types. However, 5100*a9fa9459Szrj for a static method, g++ simply outputs the return type and the 5101*a9fa9459Szrj physical name. So in that case we need to demangle the name here. 5102*a9fa9459Szrj Here PHYSNAME is the physical name of the function, and we set the 5103*a9fa9459Szrj variable pointed at by PVARARGS to indicate whether this function 5104*a9fa9459Szrj is varargs. This returns NULL, or a NULL terminated array of 5105*a9fa9459Szrj argument types. */ 5106*a9fa9459Szrj 5107*a9fa9459Szrj static debug_type * 5108*a9fa9459Szrj stab_demangle_v3_argtypes (void *dhandle, struct stab_handle *info, 5109*a9fa9459Szrj const char *physname, bfd_boolean *pvarargs) 5110*a9fa9459Szrj { 5111*a9fa9459Szrj struct demangle_component *dc; 5112*a9fa9459Szrj void *mem; 5113*a9fa9459Szrj debug_type *pargs; 5114*a9fa9459Szrj 5115*a9fa9459Szrj dc = cplus_demangle_v3_components (physname, DMGL_PARAMS | DMGL_ANSI, &mem); 5116*a9fa9459Szrj if (dc == NULL) 5117*a9fa9459Szrj { 5118*a9fa9459Szrj stab_bad_demangle (physname); 5119*a9fa9459Szrj return NULL; 5120*a9fa9459Szrj } 5121*a9fa9459Szrj 5122*a9fa9459Szrj /* We expect to see TYPED_NAME, and the right subtree describes the 5123*a9fa9459Szrj function type. */ 5124*a9fa9459Szrj if (dc->type != DEMANGLE_COMPONENT_TYPED_NAME 5125*a9fa9459Szrj || dc->u.s_binary.right->type != DEMANGLE_COMPONENT_FUNCTION_TYPE) 5126*a9fa9459Szrj { 5127*a9fa9459Szrj fprintf (stderr, _("Demangled name is not a function\n")); 5128*a9fa9459Szrj free (mem); 5129*a9fa9459Szrj return NULL; 5130*a9fa9459Szrj } 5131*a9fa9459Szrj 5132*a9fa9459Szrj pargs = stab_demangle_v3_arglist (dhandle, info, 5133*a9fa9459Szrj dc->u.s_binary.right->u.s_binary.right, 5134*a9fa9459Szrj pvarargs); 5135*a9fa9459Szrj 5136*a9fa9459Szrj free (mem); 5137*a9fa9459Szrj 5138*a9fa9459Szrj return pargs; 5139*a9fa9459Szrj } 5140*a9fa9459Szrj 5141*a9fa9459Szrj /* Demangle an argument list in a struct demangle_component tree. 5142*a9fa9459Szrj Returns a DEBUG_TYPE_NULL terminated array of argument types, and 5143*a9fa9459Szrj sets *PVARARGS to indicate whether this is a varargs function. */ 5144*a9fa9459Szrj 5145*a9fa9459Szrj static debug_type * 5146*a9fa9459Szrj stab_demangle_v3_arglist (void *dhandle, struct stab_handle *info, 5147*a9fa9459Szrj struct demangle_component *arglist, 5148*a9fa9459Szrj bfd_boolean *pvarargs) 5149*a9fa9459Szrj { 5150*a9fa9459Szrj struct demangle_component *dc; 5151*a9fa9459Szrj unsigned int alloc, count; 5152*a9fa9459Szrj debug_type *pargs; 5153*a9fa9459Szrj 5154*a9fa9459Szrj alloc = 10; 5155*a9fa9459Szrj pargs = (debug_type *) xmalloc (alloc * sizeof *pargs); 5156*a9fa9459Szrj *pvarargs = FALSE; 5157*a9fa9459Szrj 5158*a9fa9459Szrj count = 0; 5159*a9fa9459Szrj 5160*a9fa9459Szrj for (dc = arglist; 5161*a9fa9459Szrj dc != NULL; 5162*a9fa9459Szrj dc = dc->u.s_binary.right) 5163*a9fa9459Szrj { 5164*a9fa9459Szrj debug_type arg; 5165*a9fa9459Szrj bfd_boolean varargs; 5166*a9fa9459Szrj 5167*a9fa9459Szrj if (dc->type != DEMANGLE_COMPONENT_ARGLIST) 5168*a9fa9459Szrj { 5169*a9fa9459Szrj fprintf (stderr, _("Unexpected type in v3 arglist demangling\n")); 5170*a9fa9459Szrj free (pargs); 5171*a9fa9459Szrj return NULL; 5172*a9fa9459Szrj } 5173*a9fa9459Szrj 5174*a9fa9459Szrj /* PR 13925: Cope if the demangler returns an empty 5175*a9fa9459Szrj context for a function with no arguments. */ 5176*a9fa9459Szrj if (dc->u.s_binary.left == NULL) 5177*a9fa9459Szrj break; 5178*a9fa9459Szrj 5179*a9fa9459Szrj arg = stab_demangle_v3_arg (dhandle, info, dc->u.s_binary.left, 5180*a9fa9459Szrj NULL, &varargs); 5181*a9fa9459Szrj if (arg == NULL) 5182*a9fa9459Szrj { 5183*a9fa9459Szrj if (varargs) 5184*a9fa9459Szrj { 5185*a9fa9459Szrj *pvarargs = TRUE; 5186*a9fa9459Szrj continue; 5187*a9fa9459Szrj } 5188*a9fa9459Szrj free (pargs); 5189*a9fa9459Szrj return NULL; 5190*a9fa9459Szrj } 5191*a9fa9459Szrj 5192*a9fa9459Szrj if (count + 1 >= alloc) 5193*a9fa9459Szrj { 5194*a9fa9459Szrj alloc += 10; 5195*a9fa9459Szrj pargs = (debug_type *) xrealloc (pargs, alloc * sizeof *pargs); 5196*a9fa9459Szrj } 5197*a9fa9459Szrj 5198*a9fa9459Szrj pargs[count] = arg; 5199*a9fa9459Szrj ++count; 5200*a9fa9459Szrj } 5201*a9fa9459Szrj 5202*a9fa9459Szrj pargs[count] = DEBUG_TYPE_NULL; 5203*a9fa9459Szrj 5204*a9fa9459Szrj return pargs; 5205*a9fa9459Szrj } 5206*a9fa9459Szrj 5207*a9fa9459Szrj /* Convert a struct demangle_component tree describing an argument 5208*a9fa9459Szrj type into a debug_type. */ 5209*a9fa9459Szrj 5210*a9fa9459Szrj static debug_type 5211*a9fa9459Szrj stab_demangle_v3_arg (void *dhandle, struct stab_handle *info, 5212*a9fa9459Szrj struct demangle_component *dc, debug_type context, 5213*a9fa9459Szrj bfd_boolean *pvarargs) 5214*a9fa9459Szrj { 5215*a9fa9459Szrj debug_type dt; 5216*a9fa9459Szrj 5217*a9fa9459Szrj if (pvarargs != NULL) 5218*a9fa9459Szrj *pvarargs = FALSE; 5219*a9fa9459Szrj 5220*a9fa9459Szrj switch (dc->type) 5221*a9fa9459Szrj { 5222*a9fa9459Szrj /* FIXME: These are demangle component types which we probably 5223*a9fa9459Szrj need to handle one way or another. */ 5224*a9fa9459Szrj case DEMANGLE_COMPONENT_LOCAL_NAME: 5225*a9fa9459Szrj case DEMANGLE_COMPONENT_TYPED_NAME: 5226*a9fa9459Szrj case DEMANGLE_COMPONENT_TEMPLATE_PARAM: 5227*a9fa9459Szrj case DEMANGLE_COMPONENT_CTOR: 5228*a9fa9459Szrj case DEMANGLE_COMPONENT_DTOR: 5229*a9fa9459Szrj case DEMANGLE_COMPONENT_JAVA_CLASS: 5230*a9fa9459Szrj case DEMANGLE_COMPONENT_RESTRICT_THIS: 5231*a9fa9459Szrj case DEMANGLE_COMPONENT_VOLATILE_THIS: 5232*a9fa9459Szrj case DEMANGLE_COMPONENT_CONST_THIS: 5233*a9fa9459Szrj case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL: 5234*a9fa9459Szrj case DEMANGLE_COMPONENT_COMPLEX: 5235*a9fa9459Szrj case DEMANGLE_COMPONENT_IMAGINARY: 5236*a9fa9459Szrj case DEMANGLE_COMPONENT_VENDOR_TYPE: 5237*a9fa9459Szrj case DEMANGLE_COMPONENT_ARRAY_TYPE: 5238*a9fa9459Szrj case DEMANGLE_COMPONENT_PTRMEM_TYPE: 5239*a9fa9459Szrj case DEMANGLE_COMPONENT_ARGLIST: 5240*a9fa9459Szrj default: 5241*a9fa9459Szrj fprintf (stderr, _("Unrecognized demangle component %d\n"), 5242*a9fa9459Szrj (int) dc->type); 5243*a9fa9459Szrj return NULL; 5244*a9fa9459Szrj 5245*a9fa9459Szrj case DEMANGLE_COMPONENT_NAME: 5246*a9fa9459Szrj if (context != NULL) 5247*a9fa9459Szrj { 5248*a9fa9459Szrj const debug_field *fields; 5249*a9fa9459Szrj 5250*a9fa9459Szrj fields = debug_get_fields (dhandle, context); 5251*a9fa9459Szrj if (fields != NULL) 5252*a9fa9459Szrj { 5253*a9fa9459Szrj /* Try to find this type by looking through the context 5254*a9fa9459Szrj class. */ 5255*a9fa9459Szrj for (; *fields != DEBUG_FIELD_NULL; fields++) 5256*a9fa9459Szrj { 5257*a9fa9459Szrj debug_type ft; 5258*a9fa9459Szrj const char *dn; 5259*a9fa9459Szrj 5260*a9fa9459Szrj ft = debug_get_field_type (dhandle, *fields); 5261*a9fa9459Szrj if (ft == NULL) 5262*a9fa9459Szrj return NULL; 5263*a9fa9459Szrj dn = debug_get_type_name (dhandle, ft); 5264*a9fa9459Szrj if (dn != NULL 5265*a9fa9459Szrj && (int) strlen (dn) == dc->u.s_name.len 5266*a9fa9459Szrj && strncmp (dn, dc->u.s_name.s, dc->u.s_name.len) == 0) 5267*a9fa9459Szrj return ft; 5268*a9fa9459Szrj } 5269*a9fa9459Szrj } 5270*a9fa9459Szrj } 5271*a9fa9459Szrj return stab_find_tagged_type (dhandle, info, dc->u.s_name.s, 5272*a9fa9459Szrj dc->u.s_name.len, DEBUG_KIND_ILLEGAL); 5273*a9fa9459Szrj 5274*a9fa9459Szrj case DEMANGLE_COMPONENT_QUAL_NAME: 5275*a9fa9459Szrj context = stab_demangle_v3_arg (dhandle, info, dc->u.s_binary.left, 5276*a9fa9459Szrj context, NULL); 5277*a9fa9459Szrj if (context == NULL) 5278*a9fa9459Szrj return NULL; 5279*a9fa9459Szrj return stab_demangle_v3_arg (dhandle, info, dc->u.s_binary.right, 5280*a9fa9459Szrj context, NULL); 5281*a9fa9459Szrj 5282*a9fa9459Szrj case DEMANGLE_COMPONENT_TEMPLATE: 5283*a9fa9459Szrj { 5284*a9fa9459Szrj char *p; 5285*a9fa9459Szrj size_t alc; 5286*a9fa9459Szrj 5287*a9fa9459Szrj /* We print this component to get a class name which we can 5288*a9fa9459Szrj use. FIXME: This probably won't work if the template uses 5289*a9fa9459Szrj template parameters which refer to an outer template. */ 5290*a9fa9459Szrj p = cplus_demangle_print (DMGL_PARAMS | DMGL_ANSI, dc, 20, &alc); 5291*a9fa9459Szrj if (p == NULL) 5292*a9fa9459Szrj { 5293*a9fa9459Szrj fprintf (stderr, _("Failed to print demangled template\n")); 5294*a9fa9459Szrj return NULL; 5295*a9fa9459Szrj } 5296*a9fa9459Szrj dt = stab_find_tagged_type (dhandle, info, p, strlen (p), 5297*a9fa9459Szrj DEBUG_KIND_CLASS); 5298*a9fa9459Szrj free (p); 5299*a9fa9459Szrj return dt; 5300*a9fa9459Szrj } 5301*a9fa9459Szrj 5302*a9fa9459Szrj case DEMANGLE_COMPONENT_SUB_STD: 5303*a9fa9459Szrj return stab_find_tagged_type (dhandle, info, dc->u.s_string.string, 5304*a9fa9459Szrj dc->u.s_string.len, DEBUG_KIND_ILLEGAL); 5305*a9fa9459Szrj 5306*a9fa9459Szrj case DEMANGLE_COMPONENT_RESTRICT: 5307*a9fa9459Szrj case DEMANGLE_COMPONENT_VOLATILE: 5308*a9fa9459Szrj case DEMANGLE_COMPONENT_CONST: 5309*a9fa9459Szrj case DEMANGLE_COMPONENT_POINTER: 5310*a9fa9459Szrj case DEMANGLE_COMPONENT_REFERENCE: 5311*a9fa9459Szrj dt = stab_demangle_v3_arg (dhandle, info, dc->u.s_binary.left, NULL, 5312*a9fa9459Szrj NULL); 5313*a9fa9459Szrj if (dt == NULL) 5314*a9fa9459Szrj return NULL; 5315*a9fa9459Szrj 5316*a9fa9459Szrj switch (dc->type) 5317*a9fa9459Szrj { 5318*a9fa9459Szrj default: 5319*a9fa9459Szrj abort (); 5320*a9fa9459Szrj case DEMANGLE_COMPONENT_RESTRICT: 5321*a9fa9459Szrj /* FIXME: We have no way to represent restrict. */ 5322*a9fa9459Szrj return dt; 5323*a9fa9459Szrj case DEMANGLE_COMPONENT_VOLATILE: 5324*a9fa9459Szrj return debug_make_volatile_type (dhandle, dt); 5325*a9fa9459Szrj case DEMANGLE_COMPONENT_CONST: 5326*a9fa9459Szrj return debug_make_const_type (dhandle, dt); 5327*a9fa9459Szrj case DEMANGLE_COMPONENT_POINTER: 5328*a9fa9459Szrj return debug_make_pointer_type (dhandle, dt); 5329*a9fa9459Szrj case DEMANGLE_COMPONENT_REFERENCE: 5330*a9fa9459Szrj return debug_make_reference_type (dhandle, dt); 5331*a9fa9459Szrj } 5332*a9fa9459Szrj 5333*a9fa9459Szrj case DEMANGLE_COMPONENT_FUNCTION_TYPE: 5334*a9fa9459Szrj { 5335*a9fa9459Szrj debug_type *pargs; 5336*a9fa9459Szrj bfd_boolean varargs; 5337*a9fa9459Szrj 5338*a9fa9459Szrj if (dc->u.s_binary.left == NULL) 5339*a9fa9459Szrj { 5340*a9fa9459Szrj /* In this case the return type is actually unknown. 5341*a9fa9459Szrj However, I'm not sure this will ever arise in practice; 5342*a9fa9459Szrj normally an unknown return type would only appear at 5343*a9fa9459Szrj the top level, which is handled above. */ 5344*a9fa9459Szrj dt = debug_make_void_type (dhandle); 5345*a9fa9459Szrj } 5346*a9fa9459Szrj else 5347*a9fa9459Szrj dt = stab_demangle_v3_arg (dhandle, info, dc->u.s_binary.left, NULL, 5348*a9fa9459Szrj NULL); 5349*a9fa9459Szrj if (dt == NULL) 5350*a9fa9459Szrj return NULL; 5351*a9fa9459Szrj 5352*a9fa9459Szrj pargs = stab_demangle_v3_arglist (dhandle, info, 5353*a9fa9459Szrj dc->u.s_binary.right, 5354*a9fa9459Szrj &varargs); 5355*a9fa9459Szrj if (pargs == NULL) 5356*a9fa9459Szrj return NULL; 5357*a9fa9459Szrj 5358*a9fa9459Szrj return debug_make_function_type (dhandle, dt, pargs, varargs); 5359*a9fa9459Szrj } 5360*a9fa9459Szrj 5361*a9fa9459Szrj case DEMANGLE_COMPONENT_BUILTIN_TYPE: 5362*a9fa9459Szrj { 5363*a9fa9459Szrj char *p; 5364*a9fa9459Szrj size_t alc; 5365*a9fa9459Szrj debug_type ret; 5366*a9fa9459Szrj 5367*a9fa9459Szrj /* We print this component in order to find out the type name. 5368*a9fa9459Szrj FIXME: Should we instead expose the 5369*a9fa9459Szrj demangle_builtin_type_info structure? */ 5370*a9fa9459Szrj p = cplus_demangle_print (DMGL_PARAMS | DMGL_ANSI, dc, 20, &alc); 5371*a9fa9459Szrj if (p == NULL) 5372*a9fa9459Szrj { 5373*a9fa9459Szrj fprintf (stderr, _("Couldn't get demangled builtin type\n")); 5374*a9fa9459Szrj return NULL; 5375*a9fa9459Szrj } 5376*a9fa9459Szrj 5377*a9fa9459Szrj /* The mangling is based on the type, but does not itself 5378*a9fa9459Szrj indicate what the sizes are. So we have to guess. */ 5379*a9fa9459Szrj if (strcmp (p, "signed char") == 0) 5380*a9fa9459Szrj ret = debug_make_int_type (dhandle, 1, FALSE); 5381*a9fa9459Szrj else if (strcmp (p, "bool") == 0) 5382*a9fa9459Szrj ret = debug_make_bool_type (dhandle, 1); 5383*a9fa9459Szrj else if (strcmp (p, "char") == 0) 5384*a9fa9459Szrj ret = debug_make_int_type (dhandle, 1, FALSE); 5385*a9fa9459Szrj else if (strcmp (p, "double") == 0) 5386*a9fa9459Szrj ret = debug_make_float_type (dhandle, 8); 5387*a9fa9459Szrj else if (strcmp (p, "long double") == 0) 5388*a9fa9459Szrj ret = debug_make_float_type (dhandle, 8); 5389*a9fa9459Szrj else if (strcmp (p, "float") == 0) 5390*a9fa9459Szrj ret = debug_make_float_type (dhandle, 4); 5391*a9fa9459Szrj else if (strcmp (p, "__float128") == 0) 5392*a9fa9459Szrj ret = debug_make_float_type (dhandle, 16); 5393*a9fa9459Szrj else if (strcmp (p, "unsigned char") == 0) 5394*a9fa9459Szrj ret = debug_make_int_type (dhandle, 1, TRUE); 5395*a9fa9459Szrj else if (strcmp (p, "int") == 0) 5396*a9fa9459Szrj ret = debug_make_int_type (dhandle, 4, FALSE); 5397*a9fa9459Szrj else if (strcmp (p, "unsigned int") == 0) 5398*a9fa9459Szrj ret = debug_make_int_type (dhandle, 4, TRUE); 5399*a9fa9459Szrj else if (strcmp (p, "long") == 0) 5400*a9fa9459Szrj ret = debug_make_int_type (dhandle, 4, FALSE); 5401*a9fa9459Szrj else if (strcmp (p, "unsigned long") == 0) 5402*a9fa9459Szrj ret = debug_make_int_type (dhandle, 4, TRUE); 5403*a9fa9459Szrj else if (strcmp (p, "__int128") == 0) 5404*a9fa9459Szrj ret = debug_make_int_type (dhandle, 16, FALSE); 5405*a9fa9459Szrj else if (strcmp (p, "unsigned __int128") == 0) 5406*a9fa9459Szrj ret = debug_make_int_type (dhandle, 16, TRUE); 5407*a9fa9459Szrj else if (strcmp (p, "short") == 0) 5408*a9fa9459Szrj ret = debug_make_int_type (dhandle, 2, FALSE); 5409*a9fa9459Szrj else if (strcmp (p, "unsigned short") == 0) 5410*a9fa9459Szrj ret = debug_make_int_type (dhandle, 2, TRUE); 5411*a9fa9459Szrj else if (strcmp (p, "void") == 0) 5412*a9fa9459Szrj ret = debug_make_void_type (dhandle); 5413*a9fa9459Szrj else if (strcmp (p, "wchar_t") == 0) 5414*a9fa9459Szrj ret = debug_make_int_type (dhandle, 4, TRUE); 5415*a9fa9459Szrj else if (strcmp (p, "long long") == 0) 5416*a9fa9459Szrj ret = debug_make_int_type (dhandle, 8, FALSE); 5417*a9fa9459Szrj else if (strcmp (p, "unsigned long long") == 0) 5418*a9fa9459Szrj ret = debug_make_int_type (dhandle, 8, TRUE); 5419*a9fa9459Szrj else if (strcmp (p, "...") == 0) 5420*a9fa9459Szrj { 5421*a9fa9459Szrj if (pvarargs == NULL) 5422*a9fa9459Szrj fprintf (stderr, _("Unexpected demangled varargs\n")); 5423*a9fa9459Szrj else 5424*a9fa9459Szrj *pvarargs = TRUE; 5425*a9fa9459Szrj ret = NULL; 5426*a9fa9459Szrj } 5427*a9fa9459Szrj else 5428*a9fa9459Szrj { 5429*a9fa9459Szrj fprintf (stderr, _("Unrecognized demangled builtin type\n")); 5430*a9fa9459Szrj ret = NULL; 5431*a9fa9459Szrj } 5432*a9fa9459Szrj 5433*a9fa9459Szrj free (p); 5434*a9fa9459Szrj 5435*a9fa9459Szrj return ret; 5436*a9fa9459Szrj } 5437*a9fa9459Szrj } 5438*a9fa9459Szrj } 5439