stabs.c revision 77298
133965Sjdp/* stabs.c -- Parse stabs debugging information 277298Sobrien Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001 377298Sobrien Free Software Foundation, Inc. 433965Sjdp Written by Ian Lance Taylor <ian@cygnus.com>. 533965Sjdp 633965Sjdp This file is part of GNU Binutils. 733965Sjdp 833965Sjdp This program is free software; you can redistribute it and/or modify 933965Sjdp it under the terms of the GNU General Public License as published by 1033965Sjdp the Free Software Foundation; either version 2 of the License, or 1133965Sjdp (at your option) any later version. 1233965Sjdp 1333965Sjdp This program is distributed in the hope that it will be useful, 1433965Sjdp but WITHOUT ANY WARRANTY; without even the implied warranty of 1533965Sjdp MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1633965Sjdp GNU General Public License for more details. 1733965Sjdp 1833965Sjdp You should have received a copy of the GNU General Public License 1933965Sjdp along with this program; if not, write to the Free Software 2033965Sjdp Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 2133965Sjdp 02111-1307, USA. */ 2233965Sjdp 2333965Sjdp/* This file contains code which parses stabs debugging information. 2433965Sjdp The organization of this code is based on the gdb stabs reading 2533965Sjdp code. The job it does is somewhat different, because it is not 2633965Sjdp trying to identify the correct address for anything. */ 2733965Sjdp 2833965Sjdp#include <stdio.h> 2933965Sjdp#include <ctype.h> 3033965Sjdp 3133965Sjdp#include "bfd.h" 3233965Sjdp#include "bucomm.h" 3333965Sjdp#include "libiberty.h" 3433965Sjdp#include "demangle.h" 3533965Sjdp#include "debug.h" 3633965Sjdp#include "budbg.h" 3777298Sobrien#include "filenames.h" 3833965Sjdp 3933965Sjdp/* Meaningless definition needs by aout64.h. FIXME. */ 4033965Sjdp#define BYTES_IN_WORD 4 4133965Sjdp 4233965Sjdp#include "aout/aout64.h" 4333965Sjdp#include "aout/stab_gnu.h" 4433965Sjdp 4533965Sjdp/* The number of predefined XCOFF types. */ 4633965Sjdp 4733965Sjdp#define XCOFF_TYPE_COUNT 34 4833965Sjdp 4933965Sjdp/* This structure is used as a handle so that the stab parsing doesn't 5033965Sjdp need to use any static variables. */ 5133965Sjdp 5233965Sjdpstruct stab_handle 5333965Sjdp{ 5433965Sjdp /* The BFD. */ 5533965Sjdp bfd *abfd; 5633965Sjdp /* True if this is stabs in sections. */ 5733965Sjdp boolean sections; 5833965Sjdp /* The symbol table. */ 5933965Sjdp asymbol **syms; 6033965Sjdp /* The number of symbols. */ 6133965Sjdp long symcount; 6233965Sjdp /* The accumulated file name string. */ 6333965Sjdp char *so_string; 6433965Sjdp /* The value of the last N_SO symbol. */ 6533965Sjdp bfd_vma so_value; 6633965Sjdp /* The value of the start of the file, so that we can handle file 6733965Sjdp relative N_LBRAC and N_RBRAC symbols. */ 6833965Sjdp bfd_vma file_start_offset; 6933965Sjdp /* The offset of the start of the function, so that we can handle 7033965Sjdp function relative N_LBRAC and N_RBRAC symbols. */ 7133965Sjdp bfd_vma function_start_offset; 7233965Sjdp /* The version number of gcc which compiled the current compilation 7333965Sjdp unit, 0 if not compiled by gcc. */ 7433965Sjdp int gcc_compiled; 7533965Sjdp /* Whether an N_OPT symbol was seen that was not generated by gcc, 7633965Sjdp so that we can detect the SunPRO compiler. */ 7733965Sjdp boolean n_opt_found; 7833965Sjdp /* The main file name. */ 7933965Sjdp char *main_filename; 8033965Sjdp /* A stack of unfinished N_BINCL files. */ 8133965Sjdp struct bincl_file *bincl_stack; 8233965Sjdp /* A list of finished N_BINCL files. */ 8333965Sjdp struct bincl_file *bincl_list; 8433965Sjdp /* Whether we are inside a function or not. */ 8533965Sjdp boolean within_function; 8633965Sjdp /* The address of the end of the function, used if we have seen an 8733965Sjdp N_FUN symbol while in a function. This is -1 if we have not seen 8833965Sjdp an N_FUN (the normal case). */ 8933965Sjdp bfd_vma function_end; 9033965Sjdp /* The depth of block nesting. */ 9133965Sjdp int block_depth; 9233965Sjdp /* List of pending variable definitions. */ 9333965Sjdp struct stab_pending_var *pending; 9433965Sjdp /* Number of files for which we have types. */ 9533965Sjdp unsigned int files; 9633965Sjdp /* Lists of types per file. */ 9733965Sjdp struct stab_types **file_types; 9833965Sjdp /* Predefined XCOFF types. */ 9933965Sjdp debug_type xcoff_types[XCOFF_TYPE_COUNT]; 10033965Sjdp /* Undefined tags. */ 10133965Sjdp struct stab_tag *tags; 10260484Sobrien /* Set by parse_stab_type if it sees a structure defined as a cross 10360484Sobrien reference to itself. Reset by parse_stab_type otherwise. */ 10460484Sobrien boolean self_crossref; 10533965Sjdp}; 10633965Sjdp 10733965Sjdp/* A list of these structures is used to hold pending variable 10833965Sjdp definitions seen before the N_LBRAC of a block. */ 10933965Sjdp 11033965Sjdpstruct stab_pending_var 11133965Sjdp{ 11233965Sjdp /* Next pending variable definition. */ 11333965Sjdp struct stab_pending_var *next; 11433965Sjdp /* Name. */ 11533965Sjdp const char *name; 11633965Sjdp /* Type. */ 11733965Sjdp debug_type type; 11833965Sjdp /* Kind. */ 11933965Sjdp enum debug_var_kind kind; 12033965Sjdp /* Value. */ 12133965Sjdp bfd_vma val; 12233965Sjdp}; 12333965Sjdp 12433965Sjdp/* A list of these structures is used to hold the types for a single 12533965Sjdp file. */ 12633965Sjdp 12733965Sjdpstruct stab_types 12833965Sjdp{ 12933965Sjdp /* Next set of slots for this file. */ 13033965Sjdp struct stab_types *next; 13133965Sjdp /* Types indexed by type number. */ 13233965Sjdp#define STAB_TYPES_SLOTS (16) 13333965Sjdp debug_type types[STAB_TYPES_SLOTS]; 13433965Sjdp}; 13533965Sjdp 13633965Sjdp/* We keep a list of undefined tags that we encounter, so that we can 13733965Sjdp fill them in if the tag is later defined. */ 13833965Sjdp 13933965Sjdpstruct stab_tag 14033965Sjdp{ 14133965Sjdp /* Next undefined tag. */ 14233965Sjdp struct stab_tag *next; 14333965Sjdp /* Tag name. */ 14433965Sjdp const char *name; 14533965Sjdp /* Type kind. */ 14633965Sjdp enum debug_type_kind kind; 14733965Sjdp /* Slot to hold real type when we discover it. If we don't, we fill 14833965Sjdp in an undefined tag type. */ 14933965Sjdp debug_type slot; 15033965Sjdp /* Indirect type we have created to point at slot. */ 15133965Sjdp debug_type type; 15233965Sjdp}; 15333965Sjdp 15433965Sjdpstatic char *savestring PARAMS ((const char *, int)); 15533965Sjdpstatic bfd_vma parse_number PARAMS ((const char **, boolean *)); 15633965Sjdpstatic void bad_stab PARAMS ((const char *)); 15733965Sjdpstatic void warn_stab PARAMS ((const char *, const char *)); 15833965Sjdpstatic boolean parse_stab_string 15933965Sjdp PARAMS ((PTR, struct stab_handle *, int, int, bfd_vma, const char *)); 16033965Sjdpstatic debug_type parse_stab_type 16133965Sjdp PARAMS ((PTR, struct stab_handle *, const char *, const char **, 16233965Sjdp debug_type **)); 16333965Sjdpstatic boolean parse_stab_type_number 16433965Sjdp PARAMS ((const char **, int *)); 16533965Sjdpstatic debug_type parse_stab_range_type 16633965Sjdp PARAMS ((PTR, struct stab_handle *, const char *, const char **, 16733965Sjdp const int *)); 16833965Sjdpstatic debug_type parse_stab_sun_builtin_type PARAMS ((PTR, const char **)); 16933965Sjdpstatic debug_type parse_stab_sun_floating_type 17033965Sjdp PARAMS ((PTR, const char **)); 17133965Sjdpstatic debug_type parse_stab_enum_type PARAMS ((PTR, const char **)); 17233965Sjdpstatic debug_type parse_stab_struct_type 17333965Sjdp PARAMS ((PTR, struct stab_handle *, const char *, const char **, boolean, 17433965Sjdp const int *)); 17533965Sjdpstatic boolean parse_stab_baseclasses 17633965Sjdp PARAMS ((PTR, struct stab_handle *, const char **, debug_baseclass **)); 17733965Sjdpstatic boolean parse_stab_struct_fields 17833965Sjdp PARAMS ((PTR, struct stab_handle *, const char **, debug_field **, 17933965Sjdp boolean *)); 18033965Sjdpstatic boolean parse_stab_cpp_abbrev 18133965Sjdp PARAMS ((PTR, struct stab_handle *, const char **, debug_field *)); 18233965Sjdpstatic boolean parse_stab_one_struct_field 18333965Sjdp PARAMS ((PTR, struct stab_handle *, const char **, const char *, 18433965Sjdp debug_field *, boolean *)); 18533965Sjdpstatic boolean parse_stab_members 18633965Sjdp PARAMS ((PTR, struct stab_handle *, const char *, const char **, 18733965Sjdp const int *, debug_method **)); 18833965Sjdpstatic debug_type parse_stab_argtypes 18933965Sjdp PARAMS ((PTR, struct stab_handle *, debug_type, const char *, const char *, 19033965Sjdp debug_type, const char *, boolean, boolean, const char **)); 19133965Sjdpstatic boolean parse_stab_tilde_field 19233965Sjdp PARAMS ((PTR, struct stab_handle *, const char **, const int *, 19333965Sjdp debug_type *, boolean *)); 19433965Sjdpstatic debug_type parse_stab_array_type 19533965Sjdp PARAMS ((PTR, struct stab_handle *, const char **, boolean)); 19633965Sjdpstatic void push_bincl PARAMS ((struct stab_handle *, const char *, bfd_vma)); 19733965Sjdpstatic const char *pop_bincl PARAMS ((struct stab_handle *)); 19833965Sjdpstatic boolean find_excl 19933965Sjdp PARAMS ((struct stab_handle *, const char *, bfd_vma)); 20033965Sjdpstatic boolean stab_record_variable 20133965Sjdp PARAMS ((PTR, struct stab_handle *, const char *, debug_type, 20233965Sjdp enum debug_var_kind, bfd_vma)); 20333965Sjdpstatic boolean stab_emit_pending_vars PARAMS ((PTR, struct stab_handle *)); 20433965Sjdpstatic debug_type *stab_find_slot 20533965Sjdp PARAMS ((struct stab_handle *, const int *)); 20633965Sjdpstatic debug_type stab_find_type 20733965Sjdp PARAMS ((PTR, struct stab_handle *, const int *)); 20833965Sjdpstatic boolean stab_record_type 20933965Sjdp PARAMS ((PTR, struct stab_handle *, const int *, debug_type)); 21033965Sjdpstatic debug_type stab_xcoff_builtin_type 21133965Sjdp PARAMS ((PTR, struct stab_handle *, int)); 21233965Sjdpstatic debug_type stab_find_tagged_type 21333965Sjdp PARAMS ((PTR, struct stab_handle *, const char *, int, 21433965Sjdp enum debug_type_kind)); 21533965Sjdpstatic debug_type *stab_demangle_argtypes 21633965Sjdp PARAMS ((PTR, struct stab_handle *, const char *, boolean *)); 21733965Sjdp 21833965Sjdp/* Save a string in memory. */ 21933965Sjdp 22033965Sjdpstatic char * 22133965Sjdpsavestring (start, len) 22233965Sjdp const char *start; 22333965Sjdp int len; 22433965Sjdp{ 22533965Sjdp char *ret; 22633965Sjdp 22733965Sjdp ret = (char *) xmalloc (len + 1); 22833965Sjdp memcpy (ret, start, len); 22933965Sjdp ret[len] = '\0'; 23033965Sjdp return ret; 23133965Sjdp} 23233965Sjdp 23333965Sjdp/* Read a number from a string. */ 23433965Sjdp 23533965Sjdpstatic bfd_vma 23633965Sjdpparse_number (pp, poverflow) 23733965Sjdp const char **pp; 23833965Sjdp boolean *poverflow; 23933965Sjdp{ 24033965Sjdp unsigned long ul; 24133965Sjdp const char *orig; 24233965Sjdp 24333965Sjdp if (poverflow != NULL) 24433965Sjdp *poverflow = false; 24533965Sjdp 24633965Sjdp orig = *pp; 24733965Sjdp 24833965Sjdp errno = 0; 24933965Sjdp ul = strtoul (*pp, (char **) pp, 0); 25033965Sjdp if (ul + 1 != 0 || errno == 0) 25160484Sobrien { 25260484Sobrien /* If bfd_vma is larger than unsigned long, and the number is 25360484Sobrien meant to be negative, we have to make sure that we sign 25460484Sobrien extend properly. */ 25560484Sobrien if (*orig == '-') 25660484Sobrien return (bfd_vma) (bfd_signed_vma) (long) ul; 25760484Sobrien return (bfd_vma) ul; 25860484Sobrien } 25933965Sjdp 26033965Sjdp /* Note that even though strtoul overflowed, it should have set *pp 26133965Sjdp to the end of the number, which is where we want it. */ 26233965Sjdp 26333965Sjdp if (sizeof (bfd_vma) > sizeof (unsigned long)) 26433965Sjdp { 26533965Sjdp const char *p; 26633965Sjdp boolean neg; 26733965Sjdp int base; 26833965Sjdp bfd_vma over, lastdig; 26933965Sjdp boolean overflow; 27033965Sjdp bfd_vma v; 27133965Sjdp 27233965Sjdp /* Our own version of strtoul, for a bfd_vma. */ 27333965Sjdp 27433965Sjdp p = orig; 27533965Sjdp 27633965Sjdp neg = false; 27733965Sjdp if (*p == '+') 27833965Sjdp ++p; 27933965Sjdp else if (*p == '-') 28033965Sjdp { 28133965Sjdp neg = true; 28233965Sjdp ++p; 28333965Sjdp } 28433965Sjdp 28533965Sjdp base = 10; 28633965Sjdp if (*p == '0') 28733965Sjdp { 28833965Sjdp if (p[1] == 'x' || p[1] == 'X') 28933965Sjdp { 29033965Sjdp base = 16; 29133965Sjdp p += 2; 29233965Sjdp } 29333965Sjdp else 29433965Sjdp { 29533965Sjdp base = 8; 29633965Sjdp ++p; 29733965Sjdp } 29833965Sjdp } 29933965Sjdp 30033965Sjdp over = ((bfd_vma) (bfd_signed_vma) -1) / (bfd_vma) base; 30133965Sjdp lastdig = ((bfd_vma) (bfd_signed_vma) -1) % (bfd_vma) base; 30233965Sjdp 30333965Sjdp overflow = false; 30433965Sjdp v = 0; 30533965Sjdp while (1) 30633965Sjdp { 30733965Sjdp int d; 30833965Sjdp 30933965Sjdp d = *p++; 31033965Sjdp if (isdigit ((unsigned char) d)) 31133965Sjdp d -= '0'; 31233965Sjdp else if (isupper ((unsigned char) d)) 31333965Sjdp d -= 'A'; 31433965Sjdp else if (islower ((unsigned char) d)) 31533965Sjdp d -= 'a'; 31633965Sjdp else 31733965Sjdp break; 31833965Sjdp 31933965Sjdp if (d >= base) 32033965Sjdp break; 32133965Sjdp 32233965Sjdp if (v > over || (v == over && (bfd_vma) d > lastdig)) 32333965Sjdp { 32433965Sjdp overflow = true; 32533965Sjdp break; 32633965Sjdp } 32733965Sjdp } 32833965Sjdp 32933965Sjdp if (! overflow) 33033965Sjdp { 33133965Sjdp if (neg) 33233965Sjdp v = - v; 33333965Sjdp return v; 33433965Sjdp } 33533965Sjdp } 33633965Sjdp 33733965Sjdp /* If we get here, the number is too large to represent in a 33833965Sjdp bfd_vma. */ 33933965Sjdp 34033965Sjdp if (poverflow != NULL) 34133965Sjdp *poverflow = true; 34233965Sjdp else 34360484Sobrien warn_stab (orig, _("numeric overflow")); 34433965Sjdp 34533965Sjdp return 0; 34633965Sjdp} 34733965Sjdp 34833965Sjdp/* Give an error for a bad stab string. */ 34933965Sjdp 35033965Sjdpstatic void 35133965Sjdpbad_stab (p) 35233965Sjdp const char *p; 35333965Sjdp{ 35460484Sobrien fprintf (stderr, _("Bad stab: %s\n"), p); 35533965Sjdp} 35633965Sjdp 35733965Sjdp/* Warn about something in a stab string. */ 35833965Sjdp 35933965Sjdpstatic void 36033965Sjdpwarn_stab (p, err) 36133965Sjdp const char *p; 36233965Sjdp const char *err; 36333965Sjdp{ 36460484Sobrien fprintf (stderr, _("Warning: %s: %s\n"), err, p); 36533965Sjdp} 36633965Sjdp 36733965Sjdp/* Create a handle to parse stabs symbols with. */ 36833965Sjdp 36933965Sjdp/*ARGSUSED*/ 37033965SjdpPTR 37133965Sjdpstart_stab (dhandle, abfd, sections, syms, symcount) 37260484Sobrien PTR dhandle ATTRIBUTE_UNUSED; 37333965Sjdp bfd *abfd; 37433965Sjdp boolean sections; 37533965Sjdp asymbol **syms; 37633965Sjdp long symcount; 37733965Sjdp{ 37833965Sjdp struct stab_handle *ret; 37933965Sjdp 38033965Sjdp ret = (struct stab_handle *) xmalloc (sizeof *ret); 38133965Sjdp memset (ret, 0, sizeof *ret); 38233965Sjdp ret->abfd = abfd; 38333965Sjdp ret->sections = sections; 38433965Sjdp ret->syms = syms; 38533965Sjdp ret->symcount = symcount; 38633965Sjdp ret->files = 1; 38733965Sjdp ret->file_types = (struct stab_types **) xmalloc (sizeof *ret->file_types); 38833965Sjdp ret->file_types[0] = NULL; 38933965Sjdp ret->function_end = (bfd_vma) -1; 39033965Sjdp return (PTR) ret; 39133965Sjdp} 39233965Sjdp 39333965Sjdp/* When we have processed all the stabs information, we need to go 39433965Sjdp through and fill in all the undefined tags. */ 39533965Sjdp 39633965Sjdpboolean 39733965Sjdpfinish_stab (dhandle, handle) 39833965Sjdp PTR dhandle; 39933965Sjdp PTR handle; 40033965Sjdp{ 40133965Sjdp struct stab_handle *info = (struct stab_handle *) handle; 40233965Sjdp struct stab_tag *st; 40333965Sjdp 40433965Sjdp if (info->within_function) 40533965Sjdp { 40633965Sjdp if (! stab_emit_pending_vars (dhandle, info) 40733965Sjdp || ! debug_end_function (dhandle, info->function_end)) 40833965Sjdp return false; 40933965Sjdp info->within_function = false; 41033965Sjdp info->function_end = (bfd_vma) -1; 41133965Sjdp } 41233965Sjdp 41333965Sjdp for (st = info->tags; st != NULL; st = st->next) 41433965Sjdp { 41533965Sjdp enum debug_type_kind kind; 41633965Sjdp 41733965Sjdp kind = st->kind; 41833965Sjdp if (kind == DEBUG_KIND_ILLEGAL) 41933965Sjdp kind = DEBUG_KIND_STRUCT; 42033965Sjdp st->slot = debug_make_undefined_tagged_type (dhandle, st->name, kind); 42133965Sjdp if (st->slot == DEBUG_TYPE_NULL) 42233965Sjdp return false; 42333965Sjdp } 42433965Sjdp 42533965Sjdp return true; 42633965Sjdp} 42733965Sjdp 42833965Sjdp/* Handle a single stabs symbol. */ 42933965Sjdp 43033965Sjdpboolean 43133965Sjdpparse_stab (dhandle, handle, type, desc, value, string) 43233965Sjdp PTR dhandle; 43333965Sjdp PTR handle; 43433965Sjdp int type; 43533965Sjdp int desc; 43633965Sjdp bfd_vma value; 43733965Sjdp const char *string; 43833965Sjdp{ 43933965Sjdp struct stab_handle *info = (struct stab_handle *) handle; 44033965Sjdp 44133965Sjdp /* gcc will emit two N_SO strings per compilation unit, one for the 44233965Sjdp directory name and one for the file name. We just collect N_SO 44333965Sjdp strings as we see them, and start the new compilation unit when 44433965Sjdp we see a non N_SO symbol. */ 44533965Sjdp if (info->so_string != NULL 44633965Sjdp && (type != N_SO || *string == '\0' || value != info->so_value)) 44733965Sjdp { 44833965Sjdp if (! debug_set_filename (dhandle, info->so_string)) 44933965Sjdp return false; 45033965Sjdp info->main_filename = info->so_string; 45133965Sjdp 45233965Sjdp info->gcc_compiled = 0; 45333965Sjdp info->n_opt_found = false; 45433965Sjdp 45533965Sjdp /* Generally, for stabs in the symbol table, the N_LBRAC and 45633965Sjdp N_RBRAC symbols are relative to the N_SO symbol value. */ 45733965Sjdp if (! info->sections) 45833965Sjdp info->file_start_offset = info->so_value; 45933965Sjdp 46033965Sjdp /* We need to reset the mapping from type numbers to types. We 46133965Sjdp can't free the old mapping, because of the use of 46233965Sjdp debug_make_indirect_type. */ 46333965Sjdp info->files = 1; 46433965Sjdp info->file_types = ((struct stab_types **) 46533965Sjdp xmalloc (sizeof *info->file_types)); 46633965Sjdp info->file_types[0] = NULL; 46733965Sjdp 46833965Sjdp info->so_string = NULL; 46933965Sjdp 47033965Sjdp /* Now process whatever type we just got. */ 47133965Sjdp } 47233965Sjdp 47333965Sjdp switch (type) 47433965Sjdp { 47533965Sjdp case N_FN: 47633965Sjdp case N_FN_SEQ: 47733965Sjdp break; 47833965Sjdp 47933965Sjdp case N_LBRAC: 48033965Sjdp /* Ignore extra outermost context from SunPRO cc and acc. */ 48133965Sjdp if (info->n_opt_found && desc == 1) 48233965Sjdp break; 48333965Sjdp 48433965Sjdp if (! info->within_function) 48533965Sjdp { 48660484Sobrien fprintf (stderr, _("N_LBRAC not within function\n")); 48733965Sjdp return false; 48833965Sjdp } 48933965Sjdp 49033965Sjdp /* Start an inner lexical block. */ 49133965Sjdp if (! debug_start_block (dhandle, 49233965Sjdp (value 49333965Sjdp + info->file_start_offset 49433965Sjdp + info->function_start_offset))) 49533965Sjdp return false; 49633965Sjdp 49733965Sjdp /* Emit any pending variable definitions. */ 49833965Sjdp if (! stab_emit_pending_vars (dhandle, info)) 49933965Sjdp return false; 50033965Sjdp 50133965Sjdp ++info->block_depth; 50233965Sjdp break; 50333965Sjdp 50433965Sjdp case N_RBRAC: 50533965Sjdp /* Ignore extra outermost context from SunPRO cc and acc. */ 50633965Sjdp if (info->n_opt_found && desc == 1) 50733965Sjdp break; 50833965Sjdp 50933965Sjdp /* We shouldn't have any pending variable definitions here, but, 51033965Sjdp if we do, we probably need to emit them before closing the 51133965Sjdp block. */ 51233965Sjdp if (! stab_emit_pending_vars (dhandle, info)) 51333965Sjdp return false; 51433965Sjdp 51533965Sjdp /* End an inner lexical block. */ 51633965Sjdp if (! debug_end_block (dhandle, 51733965Sjdp (value 51833965Sjdp + info->file_start_offset 51933965Sjdp + info->function_start_offset))) 52033965Sjdp return false; 52133965Sjdp 52233965Sjdp --info->block_depth; 52333965Sjdp if (info->block_depth < 0) 52433965Sjdp { 52560484Sobrien fprintf (stderr, _("Too many N_RBRACs\n")); 52633965Sjdp return false; 52733965Sjdp } 52833965Sjdp break; 52933965Sjdp 53033965Sjdp case N_SO: 53133965Sjdp /* This always ends a function. */ 53233965Sjdp if (info->within_function) 53333965Sjdp { 53433965Sjdp bfd_vma endval; 53533965Sjdp 53633965Sjdp endval = value; 53733965Sjdp if (*string != '\0' 53833965Sjdp && info->function_end != (bfd_vma) -1 53933965Sjdp && info->function_end < endval) 54033965Sjdp endval = info->function_end; 54133965Sjdp if (! stab_emit_pending_vars (dhandle, info) 54233965Sjdp || ! debug_end_function (dhandle, endval)) 54333965Sjdp return false; 54433965Sjdp info->within_function = false; 54533965Sjdp info->function_end = (bfd_vma) -1; 54633965Sjdp } 54733965Sjdp 54833965Sjdp /* An empty string is emitted by gcc at the end of a compilation 54933965Sjdp unit. */ 55033965Sjdp if (*string == '\0') 55133965Sjdp return true; 55233965Sjdp 55333965Sjdp /* Just accumulate strings until we see a non N_SO symbol. If 55460484Sobrien the string starts with a directory separator or some other 55560484Sobrien form of absolute path specification, we discard the previously 55633965Sjdp accumulated strings. */ 55733965Sjdp if (info->so_string == NULL) 55833965Sjdp info->so_string = xstrdup (string); 55933965Sjdp else 56033965Sjdp { 56133965Sjdp char *f; 56233965Sjdp 56333965Sjdp f = info->so_string; 56460484Sobrien 56577298Sobrien if (IS_ABSOLUTE_PATH (string)) 56633965Sjdp info->so_string = xstrdup (string); 56733965Sjdp else 56833965Sjdp info->so_string = concat (info->so_string, string, 56933965Sjdp (const char *) NULL); 57033965Sjdp free (f); 57133965Sjdp } 57233965Sjdp 57333965Sjdp info->so_value = value; 57433965Sjdp 57533965Sjdp break; 57633965Sjdp 57733965Sjdp case N_SOL: 57833965Sjdp /* Start an include file. */ 57933965Sjdp if (! debug_start_source (dhandle, string)) 58033965Sjdp return false; 58133965Sjdp break; 58233965Sjdp 58333965Sjdp case N_BINCL: 58433965Sjdp /* Start an include file which may be replaced. */ 58533965Sjdp push_bincl (info, string, value); 58633965Sjdp if (! debug_start_source (dhandle, string)) 58733965Sjdp return false; 58833965Sjdp break; 58933965Sjdp 59033965Sjdp case N_EINCL: 59133965Sjdp /* End an N_BINCL include. */ 59233965Sjdp if (! debug_start_source (dhandle, pop_bincl (info))) 59333965Sjdp return false; 59433965Sjdp break; 59533965Sjdp 59633965Sjdp case N_EXCL: 59733965Sjdp /* This is a duplicate of a header file named by N_BINCL which 59833965Sjdp was eliminated by the linker. */ 59933965Sjdp if (! find_excl (info, string, value)) 60033965Sjdp return false; 60133965Sjdp break; 60233965Sjdp 60333965Sjdp case N_SLINE: 60433965Sjdp if (! debug_record_line (dhandle, desc, 60533965Sjdp value + info->function_start_offset)) 60633965Sjdp return false; 60733965Sjdp break; 60833965Sjdp 60933965Sjdp case N_BCOMM: 61033965Sjdp if (! debug_start_common_block (dhandle, string)) 61133965Sjdp return false; 61233965Sjdp break; 61333965Sjdp 61433965Sjdp case N_ECOMM: 61533965Sjdp if (! debug_end_common_block (dhandle, string)) 61633965Sjdp return false; 61733965Sjdp break; 61833965Sjdp 61933965Sjdp case N_FUN: 62033965Sjdp if (*string == '\0') 62133965Sjdp { 62233965Sjdp if (info->within_function) 62333965Sjdp { 62433965Sjdp /* This always marks the end of a function; we don't 62533965Sjdp need to worry about info->function_end. */ 62633965Sjdp if (info->sections) 62733965Sjdp value += info->function_start_offset; 62833965Sjdp if (! stab_emit_pending_vars (dhandle, info) 62933965Sjdp || ! debug_end_function (dhandle, value)) 63033965Sjdp return false; 63133965Sjdp info->within_function = false; 63233965Sjdp info->function_end = (bfd_vma) -1; 63333965Sjdp } 63433965Sjdp break; 63533965Sjdp } 63633965Sjdp 63733965Sjdp /* A const static symbol in the .text section will have an N_FUN 63833965Sjdp entry. We need to use these to mark the end of the function, 63933965Sjdp in case we are looking at gcc output before it was changed to 64033965Sjdp always emit an empty N_FUN. We can't call debug_end_function 64133965Sjdp here, because it might be a local static symbol. */ 64233965Sjdp if (info->within_function 64333965Sjdp && (info->function_end == (bfd_vma) -1 64433965Sjdp || value < info->function_end)) 64533965Sjdp info->function_end = value; 64633965Sjdp 64733965Sjdp /* Fall through. */ 64833965Sjdp /* FIXME: gdb checks the string for N_STSYM, N_LCSYM or N_ROSYM 64933965Sjdp symbols, and if it does not start with :S, gdb relocates the 65033965Sjdp value to the start of the section. gcc always seems to use 65133965Sjdp :S, so we don't worry about this. */ 65233965Sjdp /* Fall through. */ 65333965Sjdp default: 65433965Sjdp { 65533965Sjdp const char *colon; 65633965Sjdp 65733965Sjdp colon = strchr (string, ':'); 65833965Sjdp if (colon != NULL 65933965Sjdp && (colon[1] == 'f' || colon[1] == 'F')) 66033965Sjdp { 66133965Sjdp if (info->within_function) 66233965Sjdp { 66333965Sjdp bfd_vma endval; 66433965Sjdp 66533965Sjdp endval = value; 66633965Sjdp if (info->function_end != (bfd_vma) -1 66733965Sjdp && info->function_end < endval) 66833965Sjdp endval = info->function_end; 66933965Sjdp if (! stab_emit_pending_vars (dhandle, info) 67033965Sjdp || ! debug_end_function (dhandle, endval)) 67133965Sjdp return false; 67233965Sjdp info->function_end = (bfd_vma) -1; 67333965Sjdp } 67433965Sjdp /* For stabs in sections, line numbers and block addresses 67533965Sjdp are offsets from the start of the function. */ 67633965Sjdp if (info->sections) 67733965Sjdp info->function_start_offset = value; 67833965Sjdp info->within_function = true; 67933965Sjdp } 68033965Sjdp 68133965Sjdp if (! parse_stab_string (dhandle, info, type, desc, value, string)) 68233965Sjdp return false; 68333965Sjdp } 68433965Sjdp break; 68533965Sjdp 68633965Sjdp case N_OPT: 68733965Sjdp if (string != NULL && strcmp (string, "gcc2_compiled.") == 0) 68833965Sjdp info->gcc_compiled = 2; 68933965Sjdp else if (string != NULL && strcmp (string, "gcc_compiled.") == 0) 69033965Sjdp info->gcc_compiled = 1; 69133965Sjdp else 69233965Sjdp info->n_opt_found = true; 69333965Sjdp break; 69433965Sjdp 69533965Sjdp case N_OBJ: 69633965Sjdp case N_ENDM: 69733965Sjdp case N_MAIN: 69877298Sobrien case N_WARNING: 69933965Sjdp break; 70033965Sjdp } 70133965Sjdp 70233965Sjdp return true; 70333965Sjdp} 70433965Sjdp 70533965Sjdp/* Parse the stabs string. */ 70633965Sjdp 70733965Sjdpstatic boolean 70833965Sjdpparse_stab_string (dhandle, info, stabtype, desc, value, string) 70933965Sjdp PTR dhandle; 71033965Sjdp struct stab_handle *info; 71133965Sjdp int stabtype; 71233965Sjdp int desc; 71333965Sjdp bfd_vma value; 71433965Sjdp const char *string; 71533965Sjdp{ 71633965Sjdp const char *p; 71733965Sjdp char *name; 71833965Sjdp int type; 71933965Sjdp debug_type dtype; 72033965Sjdp boolean synonym; 72160484Sobrien boolean self_crossref; 72233965Sjdp unsigned int lineno; 72333965Sjdp debug_type *slot; 72433965Sjdp 72533965Sjdp p = strchr (string, ':'); 72633965Sjdp if (p == NULL) 72733965Sjdp return true; 72833965Sjdp 72933965Sjdp while (p[1] == ':') 73033965Sjdp { 73133965Sjdp p += 2; 73233965Sjdp p = strchr (p, ':'); 73333965Sjdp if (p == NULL) 73433965Sjdp { 73533965Sjdp bad_stab (string); 73633965Sjdp return false; 73733965Sjdp } 73833965Sjdp } 73933965Sjdp 74033965Sjdp /* GCC 2.x puts the line number in desc. SunOS apparently puts in 74133965Sjdp the number of bytes occupied by a type or object, which we 74233965Sjdp ignore. */ 74333965Sjdp if (info->gcc_compiled >= 2) 74433965Sjdp lineno = desc; 74533965Sjdp else 74633965Sjdp lineno = 0; 74733965Sjdp 74833965Sjdp /* FIXME: Sometimes the special C++ names start with '.'. */ 74933965Sjdp name = NULL; 75033965Sjdp if (string[0] == '$') 75133965Sjdp { 75233965Sjdp switch (string[1]) 75333965Sjdp { 75433965Sjdp case 't': 75533965Sjdp name = "this"; 75633965Sjdp break; 75733965Sjdp case 'v': 75833965Sjdp /* Was: name = "vptr"; */ 75933965Sjdp break; 76033965Sjdp case 'e': 76133965Sjdp name = "eh_throw"; 76233965Sjdp break; 76333965Sjdp case '_': 76433965Sjdp /* This was an anonymous type that was never fixed up. */ 76533965Sjdp break; 76633965Sjdp case 'X': 76733965Sjdp /* SunPRO (3.0 at least) static variable encoding. */ 76833965Sjdp break; 76933965Sjdp default: 77060484Sobrien warn_stab (string, _("unknown C++ encoded name")); 77133965Sjdp break; 77233965Sjdp } 77333965Sjdp } 77433965Sjdp 77533965Sjdp if (name == NULL) 77633965Sjdp { 77733965Sjdp if (p == string || (string[0] == ' ' && p == string + 1)) 77833965Sjdp name = NULL; 77933965Sjdp else 78033965Sjdp name = savestring (string, p - string); 78133965Sjdp } 78233965Sjdp 78333965Sjdp ++p; 78433965Sjdp if (isdigit ((unsigned char) *p) || *p == '(' || *p == '-') 78533965Sjdp type = 'l'; 78633965Sjdp else 78733965Sjdp type = *p++; 78833965Sjdp 78933965Sjdp switch (type) 79033965Sjdp { 79133965Sjdp case 'c': 79233965Sjdp /* c is a special case, not followed by a type-number. 79333965Sjdp SYMBOL:c=iVALUE for an integer constant symbol. 79433965Sjdp SYMBOL:c=rVALUE for a floating constant symbol. 79533965Sjdp SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol. 79633965Sjdp e.g. "b:c=e6,0" for "const b = blob1" 79733965Sjdp (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */ 79833965Sjdp if (*p != '=') 79933965Sjdp { 80033965Sjdp bad_stab (string); 80133965Sjdp return false; 80233965Sjdp } 80333965Sjdp ++p; 80433965Sjdp switch (*p++) 80533965Sjdp { 80633965Sjdp case 'r': 80733965Sjdp /* Floating point constant. */ 80833965Sjdp if (! debug_record_float_const (dhandle, name, atof (p))) 80933965Sjdp return false; 81033965Sjdp break; 81133965Sjdp case 'i': 81233965Sjdp /* Integer constant. */ 81333965Sjdp /* Defining integer constants this way is kind of silly, 81433965Sjdp since 'e' constants allows the compiler to give not only 81533965Sjdp the value, but the type as well. C has at least int, 81633965Sjdp long, unsigned int, and long long as constant types; 81733965Sjdp other languages probably should have at least unsigned as 81833965Sjdp well as signed constants. */ 81933965Sjdp if (! debug_record_int_const (dhandle, name, atoi (p))) 82033965Sjdp return false; 82133965Sjdp break; 82233965Sjdp case 'e': 82333965Sjdp /* SYMBOL:c=eTYPE,INTVALUE for a constant symbol whose value 82433965Sjdp can be represented as integral. 82533965Sjdp e.g. "b:c=e6,0" for "const b = blob1" 82633965Sjdp (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */ 82733965Sjdp dtype = parse_stab_type (dhandle, info, (const char *) NULL, 82833965Sjdp &p, (debug_type **) NULL); 82933965Sjdp if (dtype == DEBUG_TYPE_NULL) 83033965Sjdp return false; 83133965Sjdp if (*p != ',') 83233965Sjdp { 83333965Sjdp bad_stab (string); 83433965Sjdp return false; 83533965Sjdp } 83633965Sjdp if (! debug_record_typed_const (dhandle, name, dtype, atoi (p))) 83733965Sjdp return false; 83833965Sjdp break; 83933965Sjdp default: 84033965Sjdp bad_stab (string); 84133965Sjdp return false; 84233965Sjdp } 84333965Sjdp 84433965Sjdp break; 84533965Sjdp 84633965Sjdp case 'C': 84733965Sjdp /* The name of a caught exception. */ 84833965Sjdp dtype = parse_stab_type (dhandle, info, (const char *) NULL, 84933965Sjdp &p, (debug_type **) NULL); 85033965Sjdp if (dtype == DEBUG_TYPE_NULL) 85133965Sjdp return false; 85233965Sjdp if (! debug_record_label (dhandle, name, dtype, value)) 85333965Sjdp return false; 85433965Sjdp break; 85533965Sjdp 85633965Sjdp case 'f': 85733965Sjdp case 'F': 85833965Sjdp /* A function definition. */ 85933965Sjdp dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p, 86033965Sjdp (debug_type **) NULL); 86133965Sjdp if (dtype == DEBUG_TYPE_NULL) 86233965Sjdp return false; 86333965Sjdp if (! debug_record_function (dhandle, name, dtype, type == 'F', value)) 86433965Sjdp return false; 86533965Sjdp 86633965Sjdp /* Sun acc puts declared types of arguments here. We don't care 86733965Sjdp about their actual types (FIXME -- we should remember the whole 86833965Sjdp function prototype), but the list may define some new types 86933965Sjdp that we have to remember, so we must scan it now. */ 87033965Sjdp while (*p == ';') 87133965Sjdp { 87233965Sjdp ++p; 87333965Sjdp if (parse_stab_type (dhandle, info, (const char *) NULL, &p, 87433965Sjdp (debug_type **) NULL) 87533965Sjdp == DEBUG_TYPE_NULL) 87633965Sjdp return false; 87733965Sjdp } 87833965Sjdp 87933965Sjdp break; 88033965Sjdp 88133965Sjdp case 'G': 88233965Sjdp { 88333965Sjdp char leading; 88433965Sjdp long c; 88533965Sjdp asymbol **ps; 88633965Sjdp 88733965Sjdp /* A global symbol. The value must be extracted from the 88833965Sjdp symbol table. */ 88933965Sjdp dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p, 89033965Sjdp (debug_type **) NULL); 89133965Sjdp if (dtype == DEBUG_TYPE_NULL) 89233965Sjdp return false; 89333965Sjdp leading = bfd_get_symbol_leading_char (info->abfd); 89433965Sjdp for (c = info->symcount, ps = info->syms; c > 0; --c, ++ps) 89533965Sjdp { 89633965Sjdp const char *n; 89733965Sjdp 89833965Sjdp n = bfd_asymbol_name (*ps); 89933965Sjdp if (leading != '\0' && *n == leading) 90033965Sjdp ++n; 90133965Sjdp if (*n == *name && strcmp (n, name) == 0) 90233965Sjdp break; 90333965Sjdp } 90433965Sjdp if (c > 0) 90533965Sjdp value = bfd_asymbol_value (*ps); 90633965Sjdp if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_GLOBAL, 90733965Sjdp value)) 90833965Sjdp return false; 90933965Sjdp } 91033965Sjdp break; 91133965Sjdp 91233965Sjdp /* This case is faked by a conditional above, when there is no 91333965Sjdp code letter in the dbx data. Dbx data never actually 91433965Sjdp contains 'l'. */ 91533965Sjdp case 'l': 91633965Sjdp case 's': 91733965Sjdp dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p, 91833965Sjdp (debug_type **) NULL); 91933965Sjdp if (dtype == DEBUG_TYPE_NULL) 92033965Sjdp return false; 92133965Sjdp if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_LOCAL, 92233965Sjdp value)) 92333965Sjdp return false; 92433965Sjdp break; 92533965Sjdp 92633965Sjdp case 'p': 92733965Sjdp /* A function parameter. */ 92833965Sjdp if (*p != 'F') 92933965Sjdp dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p, 93033965Sjdp (debug_type **) NULL); 93133965Sjdp else 93233965Sjdp { 93333965Sjdp /* pF is a two-letter code that means a function parameter in 93433965Sjdp Fortran. The type-number specifies the type of the return 93533965Sjdp value. Translate it into a pointer-to-function type. */ 93633965Sjdp ++p; 93733965Sjdp dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p, 93833965Sjdp (debug_type **) NULL); 93933965Sjdp if (dtype != DEBUG_TYPE_NULL) 94033965Sjdp { 94133965Sjdp debug_type ftype; 94233965Sjdp 94333965Sjdp ftype = debug_make_function_type (dhandle, dtype, 94433965Sjdp (debug_type *) NULL, false); 94533965Sjdp dtype = debug_make_pointer_type (dhandle, ftype); 94633965Sjdp } 94733965Sjdp } 94833965Sjdp if (dtype == DEBUG_TYPE_NULL) 94933965Sjdp return false; 95033965Sjdp if (! debug_record_parameter (dhandle, name, dtype, DEBUG_PARM_STACK, 95133965Sjdp value)) 95233965Sjdp return false; 95333965Sjdp 95433965Sjdp /* FIXME: At this point gdb considers rearranging the parameter 95533965Sjdp address on a big endian machine if it is smaller than an int. 95633965Sjdp We have no way to do that, since we don't really know much 95733965Sjdp about the target. */ 95833965Sjdp 95933965Sjdp break; 96033965Sjdp 96133965Sjdp case 'P': 96233965Sjdp if (stabtype == N_FUN) 96333965Sjdp { 96433965Sjdp /* Prototype of a function referenced by this file. */ 96533965Sjdp while (*p == ';') 96633965Sjdp { 96733965Sjdp ++p; 96833965Sjdp if (parse_stab_type (dhandle, info, (const char *) NULL, &p, 96933965Sjdp (debug_type **) NULL) 97033965Sjdp == DEBUG_TYPE_NULL) 97133965Sjdp return false; 97233965Sjdp } 97333965Sjdp break; 97433965Sjdp } 97533965Sjdp /* Fall through. */ 97633965Sjdp case 'R': 97733965Sjdp /* Parameter which is in a register. */ 97833965Sjdp dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p, 97933965Sjdp (debug_type **) NULL); 98033965Sjdp if (dtype == DEBUG_TYPE_NULL) 98133965Sjdp return false; 98233965Sjdp if (! debug_record_parameter (dhandle, name, dtype, DEBUG_PARM_REG, 98333965Sjdp value)) 98433965Sjdp return false; 98533965Sjdp break; 98633965Sjdp 98733965Sjdp case 'r': 98833965Sjdp /* Register variable (either global or local). */ 98933965Sjdp dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p, 99033965Sjdp (debug_type **) NULL); 99133965Sjdp if (dtype == DEBUG_TYPE_NULL) 99233965Sjdp return false; 99333965Sjdp if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_REGISTER, 99433965Sjdp value)) 99533965Sjdp return false; 99633965Sjdp 99733965Sjdp /* FIXME: At this point gdb checks to combine pairs of 'p' and 99833965Sjdp 'r' stabs into a single 'P' stab. */ 99933965Sjdp 100033965Sjdp break; 100133965Sjdp 100233965Sjdp case 'S': 100333965Sjdp /* Static symbol at top level of file */ 100433965Sjdp dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p, 100533965Sjdp (debug_type **) NULL); 100633965Sjdp if (dtype == DEBUG_TYPE_NULL) 100733965Sjdp return false; 100833965Sjdp if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_STATIC, 100933965Sjdp value)) 101033965Sjdp return false; 101133965Sjdp break; 101233965Sjdp 101333965Sjdp case 't': 101433965Sjdp /* A typedef. */ 101533965Sjdp dtype = parse_stab_type (dhandle, info, name, &p, &slot); 101633965Sjdp if (dtype == DEBUG_TYPE_NULL) 101733965Sjdp return false; 101833965Sjdp if (name == NULL) 101933965Sjdp { 102033965Sjdp /* A nameless type. Nothing to do. */ 102133965Sjdp return true; 102233965Sjdp } 102333965Sjdp 102433965Sjdp dtype = debug_name_type (dhandle, name, dtype); 102533965Sjdp if (dtype == DEBUG_TYPE_NULL) 102633965Sjdp return false; 102733965Sjdp 102833965Sjdp if (slot != NULL) 102933965Sjdp *slot = dtype; 103033965Sjdp 103133965Sjdp break; 103233965Sjdp 103333965Sjdp case 'T': 103433965Sjdp /* Struct, union, or enum tag. For GNU C++, this can be be followed 103533965Sjdp by 't' which means we are typedef'ing it as well. */ 103633965Sjdp if (*p != 't') 103733965Sjdp { 103833965Sjdp synonym = false; 103933965Sjdp /* FIXME: gdb sets synonym to true if the current language 104033965Sjdp is C++. */ 104133965Sjdp } 104233965Sjdp else 104333965Sjdp { 104433965Sjdp synonym = true; 104533965Sjdp ++p; 104633965Sjdp } 104733965Sjdp 104833965Sjdp dtype = parse_stab_type (dhandle, info, name, &p, &slot); 104933965Sjdp if (dtype == DEBUG_TYPE_NULL) 105033965Sjdp return false; 105133965Sjdp if (name == NULL) 105233965Sjdp return true; 105333965Sjdp 105460484Sobrien /* INFO->SELF_CROSSREF is set by parse_stab_type if this type is 105560484Sobrien a cross reference to itself. These are generated by some 105660484Sobrien versions of g++. */ 105760484Sobrien self_crossref = info->self_crossref; 105860484Sobrien 105933965Sjdp dtype = debug_tag_type (dhandle, name, dtype); 106033965Sjdp if (dtype == DEBUG_TYPE_NULL) 106133965Sjdp return false; 106233965Sjdp if (slot != NULL) 106333965Sjdp *slot = dtype; 106433965Sjdp 106533965Sjdp /* See if we have a cross reference to this tag which we can now 106660484Sobrien fill in. Avoid filling in a cross reference to ourselves, 106760484Sobrien because that would lead to circular debugging information. */ 106860484Sobrien if (! self_crossref) 106960484Sobrien { 107060484Sobrien register struct stab_tag **pst; 107133965Sjdp 107260484Sobrien for (pst = &info->tags; *pst != NULL; pst = &(*pst)->next) 107360484Sobrien { 107460484Sobrien if ((*pst)->name[0] == name[0] 107560484Sobrien && strcmp ((*pst)->name, name) == 0) 107660484Sobrien { 107760484Sobrien (*pst)->slot = dtype; 107860484Sobrien *pst = (*pst)->next; 107960484Sobrien break; 108060484Sobrien } 108160484Sobrien } 108260484Sobrien } 108333965Sjdp 108433965Sjdp if (synonym) 108533965Sjdp { 108633965Sjdp dtype = debug_name_type (dhandle, name, dtype); 108733965Sjdp if (dtype == DEBUG_TYPE_NULL) 108833965Sjdp return false; 108933965Sjdp 109033965Sjdp if (slot != NULL) 109133965Sjdp *slot = dtype; 109233965Sjdp } 109333965Sjdp 109433965Sjdp break; 109533965Sjdp 109633965Sjdp case 'V': 109733965Sjdp /* Static symbol of local scope */ 109833965Sjdp dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p, 109933965Sjdp (debug_type **) NULL); 110033965Sjdp if (dtype == DEBUG_TYPE_NULL) 110133965Sjdp return false; 110233965Sjdp /* FIXME: gdb checks os9k_stabs here. */ 110333965Sjdp if (! stab_record_variable (dhandle, info, name, dtype, 110433965Sjdp DEBUG_LOCAL_STATIC, value)) 110533965Sjdp return false; 110633965Sjdp break; 110733965Sjdp 110833965Sjdp case 'v': 110933965Sjdp /* Reference parameter. */ 111033965Sjdp dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p, 111133965Sjdp (debug_type **) NULL); 111233965Sjdp if (dtype == DEBUG_TYPE_NULL) 111333965Sjdp return false; 111433965Sjdp if (! debug_record_parameter (dhandle, name, dtype, DEBUG_PARM_REFERENCE, 111533965Sjdp value)) 111633965Sjdp return false; 111733965Sjdp break; 111833965Sjdp 111933965Sjdp case 'a': 112033965Sjdp /* Reference parameter which is in a register. */ 112133965Sjdp dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p, 112233965Sjdp (debug_type **) NULL); 112333965Sjdp if (dtype == DEBUG_TYPE_NULL) 112433965Sjdp return false; 112533965Sjdp if (! debug_record_parameter (dhandle, name, dtype, DEBUG_PARM_REF_REG, 112633965Sjdp value)) 112733965Sjdp return false; 112833965Sjdp break; 112933965Sjdp 113033965Sjdp case 'X': 113133965Sjdp /* This is used by Sun FORTRAN for "function result value". 113233965Sjdp Sun claims ("dbx and dbxtool interfaces", 2nd ed) 113333965Sjdp that Pascal uses it too, but when I tried it Pascal used 113433965Sjdp "x:3" (local symbol) instead. */ 113533965Sjdp dtype = parse_stab_type (dhandle, info, (const char *) NULL, &p, 113633965Sjdp (debug_type **) NULL); 113733965Sjdp if (dtype == DEBUG_TYPE_NULL) 113833965Sjdp return false; 113933965Sjdp if (! stab_record_variable (dhandle, info, name, dtype, DEBUG_LOCAL, 114033965Sjdp value)) 114133965Sjdp return false; 114233965Sjdp break; 114333965Sjdp 114433965Sjdp default: 114533965Sjdp bad_stab (string); 114633965Sjdp return false; 114733965Sjdp } 114833965Sjdp 114933965Sjdp /* FIXME: gdb converts structure values to structure pointers in a 115033965Sjdp couple of cases, depending upon the target. */ 115133965Sjdp 115233965Sjdp return true; 115333965Sjdp} 115433965Sjdp 115533965Sjdp/* Parse a stabs type. The typename argument is non-NULL if this is a 115633965Sjdp typedef or a tag definition. The pp argument points to the stab 115733965Sjdp string, and is updated. The slotp argument points to a place to 115833965Sjdp store the slot used if the type is being defined. */ 115933965Sjdp 116033965Sjdpstatic debug_type 116133965Sjdpparse_stab_type (dhandle, info, typename, pp, slotp) 116233965Sjdp PTR dhandle; 116333965Sjdp struct stab_handle *info; 116433965Sjdp const char *typename; 116533965Sjdp const char **pp; 116633965Sjdp debug_type **slotp; 116733965Sjdp{ 116833965Sjdp const char *orig; 116933965Sjdp int typenums[2]; 117033965Sjdp int size; 117133965Sjdp boolean stringp; 117233965Sjdp int descriptor; 117333965Sjdp debug_type dtype; 117433965Sjdp 117533965Sjdp if (slotp != NULL) 117633965Sjdp *slotp = NULL; 117733965Sjdp 117833965Sjdp orig = *pp; 117933965Sjdp 118033965Sjdp size = -1; 118133965Sjdp stringp = false; 118233965Sjdp 118360484Sobrien info->self_crossref = false; 118460484Sobrien 118533965Sjdp /* Read type number if present. The type number may be omitted. 118633965Sjdp for instance in a two-dimensional array declared with type 118733965Sjdp "ar1;1;10;ar1;1;10;4". */ 118833965Sjdp if (! isdigit ((unsigned char) **pp) && **pp != '(' && **pp != '-') 118933965Sjdp { 119033965Sjdp /* 'typenums=' not present, type is anonymous. Read and return 119133965Sjdp the definition, but don't put it in the type vector. */ 119233965Sjdp typenums[0] = typenums[1] = -1; 119333965Sjdp } 119433965Sjdp else 119533965Sjdp { 119633965Sjdp if (! parse_stab_type_number (pp, typenums)) 119733965Sjdp return DEBUG_TYPE_NULL; 119833965Sjdp 119933965Sjdp if (**pp != '=') 120033965Sjdp { 120133965Sjdp /* Type is not being defined here. Either it already 120233965Sjdp exists, or this is a forward reference to it. */ 120333965Sjdp return stab_find_type (dhandle, info, typenums); 120433965Sjdp } 120533965Sjdp 120633965Sjdp /* Only set the slot if the type is being defined. This means 120733965Sjdp that the mapping from type numbers to types will only record 120833965Sjdp the name of the typedef which defines a type. If we don't do 120933965Sjdp this, then something like 121033965Sjdp typedef int foo; 121133965Sjdp int i; 121233965Sjdp will record that i is of type foo. Unfortunately, stabs 121333965Sjdp information is ambiguous about variable types. For this code, 121433965Sjdp typedef int foo; 121533965Sjdp int i; 121633965Sjdp foo j; 121733965Sjdp the stabs information records both i and j as having the same 121833965Sjdp type. This could be fixed by patching the compiler. */ 121933965Sjdp if (slotp != NULL && typenums[0] >= 0 && typenums[1] >= 0) 122033965Sjdp *slotp = stab_find_slot (info, typenums); 122133965Sjdp 122233965Sjdp /* Type is being defined here. */ 122333965Sjdp /* Skip the '='. */ 122433965Sjdp ++*pp; 122533965Sjdp 122633965Sjdp while (**pp == '@') 122733965Sjdp { 122833965Sjdp const char *p = *pp + 1; 122933965Sjdp const char *attr; 123033965Sjdp 123133965Sjdp if (isdigit ((unsigned char) *p) || *p == '(' || *p == '-') 123233965Sjdp { 123333965Sjdp /* Member type. */ 123433965Sjdp break; 123533965Sjdp } 123633965Sjdp 123733965Sjdp /* Type attributes. */ 123833965Sjdp attr = p; 123933965Sjdp 124033965Sjdp for (; *p != ';'; ++p) 124133965Sjdp { 124233965Sjdp if (*p == '\0') 124333965Sjdp { 124433965Sjdp bad_stab (orig); 124533965Sjdp return DEBUG_TYPE_NULL; 124633965Sjdp } 124733965Sjdp } 124833965Sjdp *pp = p + 1; 124933965Sjdp 125033965Sjdp switch (*attr) 125133965Sjdp { 125233965Sjdp case 's': 125333965Sjdp size = atoi (attr + 1); 125468765Sobrien size /= 8; /* Size is in bits. We store it in bytes. */ 125533965Sjdp if (size <= 0) 125633965Sjdp size = -1; 125733965Sjdp break; 125833965Sjdp 125933965Sjdp case 'S': 126033965Sjdp stringp = true; 126133965Sjdp break; 126233965Sjdp 126333965Sjdp default: 126433965Sjdp /* Ignore unrecognized type attributes, so future 126533965Sjdp compilers can invent new ones. */ 126633965Sjdp break; 126733965Sjdp } 126833965Sjdp } 126933965Sjdp } 127033965Sjdp 127133965Sjdp descriptor = **pp; 127233965Sjdp ++*pp; 127333965Sjdp 127433965Sjdp switch (descriptor) 127533965Sjdp { 127633965Sjdp case 'x': 127733965Sjdp { 127833965Sjdp enum debug_type_kind code; 127933965Sjdp const char *q1, *q2, *p; 128033965Sjdp 128133965Sjdp /* A cross reference to another type. */ 128233965Sjdp 128333965Sjdp switch (**pp) 128433965Sjdp { 128533965Sjdp case 's': 128633965Sjdp code = DEBUG_KIND_STRUCT; 128733965Sjdp break; 128833965Sjdp case 'u': 128933965Sjdp code = DEBUG_KIND_UNION; 129033965Sjdp break; 129133965Sjdp case 'e': 129233965Sjdp code = DEBUG_KIND_ENUM; 129333965Sjdp break; 129433965Sjdp default: 129533965Sjdp /* Complain and keep going, so compilers can invent new 129633965Sjdp cross-reference types. */ 129760484Sobrien warn_stab (orig, _("unrecognized cross reference type")); 129833965Sjdp code = DEBUG_KIND_STRUCT; 129933965Sjdp break; 130033965Sjdp } 130133965Sjdp ++*pp; 130233965Sjdp 130333965Sjdp q1 = strchr (*pp, '<'); 130433965Sjdp p = strchr (*pp, ':'); 130533965Sjdp if (p == NULL) 130633965Sjdp { 130733965Sjdp bad_stab (orig); 130833965Sjdp return DEBUG_TYPE_NULL; 130933965Sjdp } 131060484Sobrien if (q1 != NULL && p > q1 && p[1] == ':') 131133965Sjdp { 131260484Sobrien int nest = 0; 131360484Sobrien 131460484Sobrien for (q2 = q1; *q2 != '\0'; ++q2) 131533965Sjdp { 131660484Sobrien if (*q2 == '<') 131760484Sobrien ++nest; 131860484Sobrien else if (*q2 == '>') 131960484Sobrien --nest; 132060484Sobrien else if (*q2 == ':' && nest == 0) 132160484Sobrien break; 132260484Sobrien } 132360484Sobrien p = q2; 132460484Sobrien if (*p != ':') 132560484Sobrien { 132633965Sjdp bad_stab (orig); 132733965Sjdp return DEBUG_TYPE_NULL; 132833965Sjdp } 132933965Sjdp } 133033965Sjdp 133160484Sobrien /* Some versions of g++ can emit stabs like 133260484Sobrien fleep:T20=xsfleep: 133360484Sobrien which define structures in terms of themselves. We need to 133460484Sobrien tell the caller to avoid building a circular structure. */ 133560484Sobrien if (typename != NULL 133660484Sobrien && strncmp (typename, *pp, p - *pp) == 0 133760484Sobrien && typename[p - *pp] == '\0') 133860484Sobrien info->self_crossref = true; 133960484Sobrien 134033965Sjdp dtype = stab_find_tagged_type (dhandle, info, *pp, p - *pp, code); 134133965Sjdp 134233965Sjdp *pp = p + 1; 134333965Sjdp } 134433965Sjdp break; 134533965Sjdp 134633965Sjdp case '-': 134733965Sjdp case '0': 134833965Sjdp case '1': 134933965Sjdp case '2': 135033965Sjdp case '3': 135133965Sjdp case '4': 135233965Sjdp case '5': 135333965Sjdp case '6': 135433965Sjdp case '7': 135533965Sjdp case '8': 135633965Sjdp case '9': 135733965Sjdp case '(': 135833965Sjdp { 135933965Sjdp const char *hold; 136033965Sjdp int xtypenums[2]; 136133965Sjdp 136233965Sjdp /* This type is defined as another type. */ 136333965Sjdp 136433965Sjdp (*pp)--; 136533965Sjdp hold = *pp; 136633965Sjdp 136733965Sjdp /* Peek ahead at the number to detect void. */ 136833965Sjdp if (! parse_stab_type_number (pp, xtypenums)) 136933965Sjdp return DEBUG_TYPE_NULL; 137033965Sjdp 137133965Sjdp if (typenums[0] == xtypenums[0] && typenums[1] == xtypenums[1]) 137233965Sjdp { 137333965Sjdp /* This type is being defined as itself, which means that 137433965Sjdp it is void. */ 137533965Sjdp dtype = debug_make_void_type (dhandle); 137633965Sjdp } 137733965Sjdp else 137833965Sjdp { 137933965Sjdp *pp = hold; 138033965Sjdp 138133965Sjdp /* Go back to the number and have parse_stab_type get it. 138233965Sjdp This means that we can deal with something like 138333965Sjdp t(1,2)=(3,4)=... which the Lucid compiler uses. */ 138433965Sjdp dtype = parse_stab_type (dhandle, info, (const char *) NULL, 138533965Sjdp pp, (debug_type **) NULL); 138633965Sjdp if (dtype == DEBUG_TYPE_NULL) 138733965Sjdp return DEBUG_TYPE_NULL; 138833965Sjdp } 138933965Sjdp 139033965Sjdp if (typenums[0] != -1) 139133965Sjdp { 139233965Sjdp if (! stab_record_type (dhandle, info, typenums, dtype)) 139333965Sjdp return DEBUG_TYPE_NULL; 139433965Sjdp } 139533965Sjdp 139633965Sjdp break; 139733965Sjdp } 139833965Sjdp 139933965Sjdp case '*': 140033965Sjdp dtype = debug_make_pointer_type (dhandle, 140133965Sjdp parse_stab_type (dhandle, info, 140233965Sjdp (const char *) NULL, 140333965Sjdp pp, 140433965Sjdp (debug_type **) NULL)); 140533965Sjdp break; 140633965Sjdp 140733965Sjdp case '&': 140833965Sjdp /* Reference to another type. */ 140933965Sjdp dtype = (debug_make_reference_type 141033965Sjdp (dhandle, 141133965Sjdp parse_stab_type (dhandle, info, (const char *) NULL, pp, 141233965Sjdp (debug_type **) NULL))); 141333965Sjdp break; 141433965Sjdp 141533965Sjdp case 'f': 141633965Sjdp /* Function returning another type. */ 141733965Sjdp /* FIXME: gdb checks os9k_stabs here. */ 141833965Sjdp dtype = (debug_make_function_type 141933965Sjdp (dhandle, 142033965Sjdp parse_stab_type (dhandle, info, (const char *) NULL, pp, 142133965Sjdp (debug_type **) NULL), 142233965Sjdp (debug_type *) NULL, false)); 142333965Sjdp break; 142433965Sjdp 142533965Sjdp case 'k': 142633965Sjdp /* Const qualifier on some type (Sun). */ 142733965Sjdp /* FIXME: gdb accepts 'c' here if os9k_stabs. */ 142833965Sjdp dtype = debug_make_const_type (dhandle, 142933965Sjdp parse_stab_type (dhandle, info, 143033965Sjdp (const char *) NULL, 143133965Sjdp pp, 143233965Sjdp (debug_type **) NULL)); 143333965Sjdp break; 143433965Sjdp 143533965Sjdp case 'B': 143633965Sjdp /* Volatile qual on some type (Sun). */ 143733965Sjdp /* FIXME: gdb accepts 'i' here if os9k_stabs. */ 143833965Sjdp dtype = (debug_make_volatile_type 143933965Sjdp (dhandle, 144033965Sjdp parse_stab_type (dhandle, info, (const char *) NULL, pp, 144133965Sjdp (debug_type **) NULL))); 144233965Sjdp break; 144333965Sjdp 144433965Sjdp case '@': 144533965Sjdp /* Offset (class & variable) type. This is used for a pointer 144633965Sjdp relative to an object. */ 144733965Sjdp { 144833965Sjdp debug_type domain; 144933965Sjdp debug_type memtype; 145033965Sjdp 145133965Sjdp /* Member type. */ 145233965Sjdp 145333965Sjdp domain = parse_stab_type (dhandle, info, (const char *) NULL, pp, 145433965Sjdp (debug_type **) NULL); 145533965Sjdp if (domain == DEBUG_TYPE_NULL) 145633965Sjdp return DEBUG_TYPE_NULL; 145733965Sjdp 145833965Sjdp if (**pp != ',') 145933965Sjdp { 146033965Sjdp bad_stab (orig); 146133965Sjdp return DEBUG_TYPE_NULL; 146233965Sjdp } 146333965Sjdp ++*pp; 146433965Sjdp 146533965Sjdp memtype = parse_stab_type (dhandle, info, (const char *) NULL, pp, 146633965Sjdp (debug_type **) NULL); 146733965Sjdp if (memtype == DEBUG_TYPE_NULL) 146833965Sjdp return DEBUG_TYPE_NULL; 146933965Sjdp 147033965Sjdp dtype = debug_make_offset_type (dhandle, domain, memtype); 147133965Sjdp } 147233965Sjdp break; 147333965Sjdp 147433965Sjdp case '#': 147533965Sjdp /* Method (class & fn) type. */ 147633965Sjdp if (**pp == '#') 147733965Sjdp { 147833965Sjdp debug_type return_type; 147933965Sjdp 148033965Sjdp ++*pp; 148133965Sjdp return_type = parse_stab_type (dhandle, info, (const char *) NULL, 148233965Sjdp pp, (debug_type **) NULL); 148333965Sjdp if (return_type == DEBUG_TYPE_NULL) 148433965Sjdp return DEBUG_TYPE_NULL; 148533965Sjdp if (**pp != ';') 148633965Sjdp { 148733965Sjdp bad_stab (orig); 148833965Sjdp return DEBUG_TYPE_NULL; 148933965Sjdp } 149033965Sjdp ++*pp; 149133965Sjdp dtype = debug_make_method_type (dhandle, return_type, 149233965Sjdp DEBUG_TYPE_NULL, 149333965Sjdp (debug_type *) NULL, false); 149433965Sjdp } 149533965Sjdp else 149633965Sjdp { 149733965Sjdp debug_type domain; 149833965Sjdp debug_type return_type; 149933965Sjdp debug_type *args; 150033965Sjdp unsigned int n; 150133965Sjdp unsigned int alloc; 150233965Sjdp boolean varargs; 150333965Sjdp 150433965Sjdp domain = parse_stab_type (dhandle, info, (const char *) NULL, 150533965Sjdp pp, (debug_type **) NULL); 150633965Sjdp if (domain == DEBUG_TYPE_NULL) 150733965Sjdp return DEBUG_TYPE_NULL; 150833965Sjdp 150933965Sjdp if (**pp != ',') 151033965Sjdp { 151133965Sjdp bad_stab (orig); 151233965Sjdp return DEBUG_TYPE_NULL; 151333965Sjdp } 151433965Sjdp ++*pp; 151533965Sjdp 151633965Sjdp return_type = parse_stab_type (dhandle, info, (const char *) NULL, 151733965Sjdp pp, (debug_type **) NULL); 151833965Sjdp if (return_type == DEBUG_TYPE_NULL) 151933965Sjdp return DEBUG_TYPE_NULL; 152033965Sjdp 152133965Sjdp alloc = 10; 152233965Sjdp args = (debug_type *) xmalloc (alloc * sizeof *args); 152333965Sjdp n = 0; 152433965Sjdp while (**pp != ';') 152533965Sjdp { 152633965Sjdp if (**pp != ',') 152733965Sjdp { 152833965Sjdp bad_stab (orig); 152933965Sjdp return DEBUG_TYPE_NULL; 153033965Sjdp } 153133965Sjdp ++*pp; 153233965Sjdp 153333965Sjdp if (n + 1 >= alloc) 153433965Sjdp { 153533965Sjdp alloc += 10; 153633965Sjdp args = ((debug_type *) 153733965Sjdp xrealloc ((PTR) args, alloc * sizeof *args)); 153833965Sjdp } 153933965Sjdp 154033965Sjdp args[n] = parse_stab_type (dhandle, info, (const char *) NULL, 154133965Sjdp pp, (debug_type **) NULL); 154233965Sjdp if (args[n] == DEBUG_TYPE_NULL) 154333965Sjdp return DEBUG_TYPE_NULL; 154433965Sjdp ++n; 154533965Sjdp } 154633965Sjdp ++*pp; 154733965Sjdp 154833965Sjdp /* If the last type is not void, then this function takes a 154933965Sjdp variable number of arguments. Otherwise, we must strip 155033965Sjdp the void type. */ 155133965Sjdp if (n == 0 155233965Sjdp || debug_get_type_kind (dhandle, args[n - 1]) != DEBUG_KIND_VOID) 155333965Sjdp varargs = true; 155433965Sjdp else 155533965Sjdp { 155633965Sjdp --n; 155733965Sjdp varargs = false; 155833965Sjdp } 155933965Sjdp 156033965Sjdp args[n] = DEBUG_TYPE_NULL; 156133965Sjdp 156233965Sjdp dtype = debug_make_method_type (dhandle, return_type, domain, args, 156333965Sjdp varargs); 156433965Sjdp } 156533965Sjdp break; 156633965Sjdp 156733965Sjdp case 'r': 156833965Sjdp /* Range type. */ 156933965Sjdp dtype = parse_stab_range_type (dhandle, info, typename, pp, typenums); 157033965Sjdp break; 157133965Sjdp 157233965Sjdp case 'b': 157333965Sjdp /* FIXME: gdb checks os9k_stabs here. */ 157433965Sjdp /* Sun ACC builtin int type. */ 157533965Sjdp dtype = parse_stab_sun_builtin_type (dhandle, pp); 157633965Sjdp break; 157733965Sjdp 157833965Sjdp case 'R': 157933965Sjdp /* Sun ACC builtin float type. */ 158033965Sjdp dtype = parse_stab_sun_floating_type (dhandle, pp); 158133965Sjdp break; 158233965Sjdp 158333965Sjdp case 'e': 158433965Sjdp /* Enumeration type. */ 158533965Sjdp dtype = parse_stab_enum_type (dhandle, pp); 158633965Sjdp break; 158733965Sjdp 158833965Sjdp case 's': 158933965Sjdp case 'u': 159033965Sjdp /* Struct or union type. */ 159133965Sjdp dtype = parse_stab_struct_type (dhandle, info, typename, pp, 159233965Sjdp descriptor == 's', typenums); 159333965Sjdp break; 159433965Sjdp 159533965Sjdp case 'a': 159633965Sjdp /* Array type. */ 159733965Sjdp if (**pp != 'r') 159833965Sjdp { 159933965Sjdp bad_stab (orig); 160033965Sjdp return DEBUG_TYPE_NULL; 160133965Sjdp } 160233965Sjdp ++*pp; 160333965Sjdp 160433965Sjdp dtype = parse_stab_array_type (dhandle, info, pp, stringp); 160533965Sjdp break; 160633965Sjdp 160733965Sjdp case 'S': 160833965Sjdp dtype = debug_make_set_type (dhandle, 160933965Sjdp parse_stab_type (dhandle, info, 161033965Sjdp (const char *) NULL, 161133965Sjdp pp, 161233965Sjdp (debug_type **) NULL), 161333965Sjdp stringp); 161433965Sjdp break; 161533965Sjdp 161633965Sjdp default: 161733965Sjdp bad_stab (orig); 161833965Sjdp return DEBUG_TYPE_NULL; 161933965Sjdp } 162033965Sjdp 162133965Sjdp if (dtype == DEBUG_TYPE_NULL) 162233965Sjdp return DEBUG_TYPE_NULL; 162333965Sjdp 162433965Sjdp if (typenums[0] != -1) 162533965Sjdp { 162633965Sjdp if (! stab_record_type (dhandle, info, typenums, dtype)) 162733965Sjdp return DEBUG_TYPE_NULL; 162833965Sjdp } 162933965Sjdp 163033965Sjdp if (size != -1) 163133965Sjdp { 163233965Sjdp if (! debug_record_type_size (dhandle, dtype, (unsigned int) size)) 163360484Sobrien return DEBUG_TYPE_NULL; 163433965Sjdp } 163533965Sjdp 163633965Sjdp return dtype; 163733965Sjdp} 163833965Sjdp 163933965Sjdp/* Read a number by which a type is referred to in dbx data, or 164033965Sjdp perhaps read a pair (FILENUM, TYPENUM) in parentheses. Just a 164133965Sjdp single number N is equivalent to (0,N). Return the two numbers by 164233965Sjdp storing them in the vector TYPENUMS. */ 164333965Sjdp 164433965Sjdpstatic boolean 164533965Sjdpparse_stab_type_number (pp, typenums) 164633965Sjdp const char **pp; 164733965Sjdp int *typenums; 164833965Sjdp{ 164933965Sjdp const char *orig; 165033965Sjdp 165133965Sjdp orig = *pp; 165233965Sjdp 165333965Sjdp if (**pp != '(') 165433965Sjdp { 165533965Sjdp typenums[0] = 0; 165633965Sjdp typenums[1] = (int) parse_number (pp, (boolean *) NULL); 165733965Sjdp } 165833965Sjdp else 165933965Sjdp { 166033965Sjdp ++*pp; 166133965Sjdp typenums[0] = (int) parse_number (pp, (boolean *) NULL); 166233965Sjdp if (**pp != ',') 166333965Sjdp { 166433965Sjdp bad_stab (orig); 166533965Sjdp return false; 166633965Sjdp } 166733965Sjdp ++*pp; 166833965Sjdp typenums[1] = (int) parse_number (pp, (boolean *) NULL); 166933965Sjdp if (**pp != ')') 167033965Sjdp { 167133965Sjdp bad_stab (orig); 167233965Sjdp return false; 167333965Sjdp } 167433965Sjdp ++*pp; 167533965Sjdp } 167633965Sjdp 167733965Sjdp return true; 167833965Sjdp} 167933965Sjdp 168033965Sjdp/* Parse a range type. */ 168133965Sjdp 168233965Sjdpstatic debug_type 168333965Sjdpparse_stab_range_type (dhandle, info, typename, pp, typenums) 168433965Sjdp PTR dhandle; 168533965Sjdp struct stab_handle *info; 168633965Sjdp const char *typename; 168733965Sjdp const char **pp; 168833965Sjdp const int *typenums; 168933965Sjdp{ 169033965Sjdp const char *orig; 169133965Sjdp int rangenums[2]; 169233965Sjdp boolean self_subrange; 169333965Sjdp debug_type index_type; 169433965Sjdp const char *s2, *s3; 169533965Sjdp bfd_signed_vma n2, n3; 169633965Sjdp boolean ov2, ov3; 169733965Sjdp 169833965Sjdp orig = *pp; 169933965Sjdp 170033965Sjdp index_type = DEBUG_TYPE_NULL; 170133965Sjdp 170233965Sjdp /* First comes a type we are a subrange of. 170333965Sjdp In C it is usually 0, 1 or the type being defined. */ 170433965Sjdp if (! parse_stab_type_number (pp, rangenums)) 170533965Sjdp return DEBUG_TYPE_NULL; 170633965Sjdp 170733965Sjdp self_subrange = (rangenums[0] == typenums[0] 170833965Sjdp && rangenums[1] == typenums[1]); 170933965Sjdp 171033965Sjdp if (**pp == '=') 171133965Sjdp { 171233965Sjdp *pp = orig; 171333965Sjdp index_type = parse_stab_type (dhandle, info, (const char *) NULL, 171433965Sjdp pp, (debug_type **) NULL); 171533965Sjdp if (index_type == DEBUG_TYPE_NULL) 171633965Sjdp return DEBUG_TYPE_NULL; 171733965Sjdp } 171833965Sjdp 171933965Sjdp if (**pp == ';') 172033965Sjdp ++*pp; 172133965Sjdp 172233965Sjdp /* The remaining two operands are usually lower and upper bounds of 172333965Sjdp the range. But in some special cases they mean something else. */ 172433965Sjdp s2 = *pp; 172533965Sjdp n2 = parse_number (pp, &ov2); 172633965Sjdp if (**pp != ';') 172733965Sjdp { 172833965Sjdp bad_stab (orig); 172933965Sjdp return DEBUG_TYPE_NULL; 173033965Sjdp } 173133965Sjdp ++*pp; 173233965Sjdp 173333965Sjdp s3 = *pp; 173433965Sjdp n3 = parse_number (pp, &ov3); 173533965Sjdp if (**pp != ';') 173633965Sjdp { 173733965Sjdp bad_stab (orig); 173833965Sjdp return DEBUG_TYPE_NULL; 173933965Sjdp } 174033965Sjdp ++*pp; 174133965Sjdp 174233965Sjdp if (ov2 || ov3) 174333965Sjdp { 174433965Sjdp /* gcc will emit range stabs for long long types. Handle this 174533965Sjdp as a special case. FIXME: This needs to be more general. */ 174633965Sjdp#define LLLOW "01000000000000000000000;" 174733965Sjdp#define LLHIGH "0777777777777777777777;" 174833965Sjdp#define ULLHIGH "01777777777777777777777;" 174933965Sjdp if (index_type == DEBUG_TYPE_NULL) 175033965Sjdp { 175133965Sjdp if (strncmp (s2, LLLOW, sizeof LLLOW - 1) == 0 175233965Sjdp && strncmp (s3, LLHIGH, sizeof LLHIGH - 1) == 0) 175333965Sjdp return debug_make_int_type (dhandle, 8, false); 175433965Sjdp if (! ov2 175533965Sjdp && n2 == 0 175633965Sjdp && strncmp (s3, ULLHIGH, sizeof ULLHIGH - 1) == 0) 175733965Sjdp return debug_make_int_type (dhandle, 8, true); 175833965Sjdp } 175933965Sjdp 176060484Sobrien warn_stab (orig, _("numeric overflow")); 176133965Sjdp } 176233965Sjdp 176333965Sjdp if (index_type == DEBUG_TYPE_NULL) 176433965Sjdp { 176533965Sjdp /* A type defined as a subrange of itself, with both bounds 0, 176633965Sjdp is void. */ 176733965Sjdp if (self_subrange && n2 == 0 && n3 == 0) 176833965Sjdp return debug_make_void_type (dhandle); 176933965Sjdp 177033965Sjdp /* A type defined as a subrange of itself, with n2 positive and 177133965Sjdp n3 zero, is a complex type, and n2 is the number of bytes. */ 177233965Sjdp if (self_subrange && n3 == 0 && n2 > 0) 177333965Sjdp return debug_make_complex_type (dhandle, n2); 177433965Sjdp 177533965Sjdp /* If n3 is zero and n2 is positive, this is a floating point 177633965Sjdp type, and n2 is the number of bytes. */ 177733965Sjdp if (n3 == 0 && n2 > 0) 177833965Sjdp return debug_make_float_type (dhandle, n2); 177933965Sjdp 178033965Sjdp /* If the upper bound is -1, this is an unsigned int. */ 178133965Sjdp if (n2 == 0 && n3 == -1) 178233965Sjdp { 178333965Sjdp /* When gcc is used with -gstabs, but not -gstabs+, it will emit 178433965Sjdp long long int:t6=r1;0;-1; 178533965Sjdp long long unsigned int:t7=r1;0;-1; 178633965Sjdp We hack here to handle this reasonably. */ 178733965Sjdp if (typename != NULL) 178833965Sjdp { 178933965Sjdp if (strcmp (typename, "long long int") == 0) 179033965Sjdp return debug_make_int_type (dhandle, 8, false); 179133965Sjdp else if (strcmp (typename, "long long unsigned int") == 0) 179233965Sjdp return debug_make_int_type (dhandle, 8, true); 179333965Sjdp } 179433965Sjdp /* FIXME: The size here really depends upon the target. */ 179533965Sjdp return debug_make_int_type (dhandle, 4, true); 179633965Sjdp } 179733965Sjdp 179833965Sjdp /* A range of 0 to 127 is char. */ 179933965Sjdp if (self_subrange && n2 == 0 && n3 == 127) 180033965Sjdp return debug_make_int_type (dhandle, 1, false); 180133965Sjdp 180233965Sjdp /* FIXME: gdb checks for the language CHILL here. */ 180333965Sjdp 180433965Sjdp if (n2 == 0) 180533965Sjdp { 180633965Sjdp if (n3 < 0) 180733965Sjdp return debug_make_int_type (dhandle, - n3, true); 180833965Sjdp else if (n3 == 0xff) 180933965Sjdp return debug_make_int_type (dhandle, 1, true); 181033965Sjdp else if (n3 == 0xffff) 181133965Sjdp return debug_make_int_type (dhandle, 2, true); 181260484Sobrien else if (n3 == (bfd_signed_vma) 0xffffffff) 181360484Sobrien return debug_make_int_type (dhandle, 4, true); 181460484Sobrien#ifdef BFD64 181577298Sobrien else if (n3 == ((((bfd_signed_vma) 0xffffffff) << 32) | 0xffffffff)) 181660484Sobrien return debug_make_int_type (dhandle, 8, true); 181760484Sobrien#endif 181833965Sjdp } 181933965Sjdp else if (n3 == 0 182033965Sjdp && n2 < 0 182133965Sjdp && (self_subrange || n2 == -8)) 182233965Sjdp return debug_make_int_type (dhandle, - n2, true); 182360484Sobrien else if (n2 == - n3 - 1 || n2 == n3 + 1) 182433965Sjdp { 182533965Sjdp if (n3 == 0x7f) 182633965Sjdp return debug_make_int_type (dhandle, 1, false); 182733965Sjdp else if (n3 == 0x7fff) 182833965Sjdp return debug_make_int_type (dhandle, 2, false); 182933965Sjdp else if (n3 == 0x7fffffff) 183033965Sjdp return debug_make_int_type (dhandle, 4, false); 183160484Sobrien#ifdef BFD64 183260484Sobrien else if (n3 == ((((bfd_vma) 0x7fffffff) << 32) | 0xffffffff)) 183360484Sobrien return debug_make_int_type (dhandle, 8, false); 183460484Sobrien#endif 183533965Sjdp } 183633965Sjdp } 183733965Sjdp 183833965Sjdp /* At this point I don't have the faintest idea how to deal with a 183933965Sjdp self_subrange type; I'm going to assume that this is used as an 184033965Sjdp idiom, and that all of them are special cases. So . . . */ 184133965Sjdp if (self_subrange) 184233965Sjdp { 184333965Sjdp bad_stab (orig); 184433965Sjdp return DEBUG_TYPE_NULL; 184533965Sjdp } 184633965Sjdp 184733965Sjdp index_type = stab_find_type (dhandle, info, rangenums); 184833965Sjdp if (index_type == DEBUG_TYPE_NULL) 184933965Sjdp { 185033965Sjdp /* Does this actually ever happen? Is that why we are worrying 185133965Sjdp about dealing with it rather than just calling error_type? */ 185260484Sobrien warn_stab (orig, _("missing index type")); 185333965Sjdp index_type = debug_make_int_type (dhandle, 4, false); 185433965Sjdp } 185533965Sjdp 185633965Sjdp return debug_make_range_type (dhandle, index_type, n2, n3); 185733965Sjdp} 185833965Sjdp 185933965Sjdp/* Sun's ACC uses a somewhat saner method for specifying the builtin 186033965Sjdp typedefs in every file (for int, long, etc): 186133965Sjdp 186233965Sjdp type = b <signed> <width>; <offset>; <nbits> 186333965Sjdp signed = u or s. Possible c in addition to u or s (for char?). 186433965Sjdp offset = offset from high order bit to start bit of type. 186533965Sjdp width is # bytes in object of this type, nbits is # bits in type. 186633965Sjdp 186733965Sjdp The width/offset stuff appears to be for small objects stored in 186833965Sjdp larger ones (e.g. `shorts' in `int' registers). We ignore it for now, 186933965Sjdp FIXME. */ 187033965Sjdp 187133965Sjdpstatic debug_type 187233965Sjdpparse_stab_sun_builtin_type (dhandle, pp) 187333965Sjdp PTR dhandle; 187433965Sjdp const char **pp; 187533965Sjdp{ 187633965Sjdp const char *orig; 187733965Sjdp boolean unsignedp; 187833965Sjdp bfd_vma bits; 187933965Sjdp 188033965Sjdp orig = *pp; 188133965Sjdp 188233965Sjdp switch (**pp) 188333965Sjdp { 188433965Sjdp case 's': 188533965Sjdp unsignedp = false; 188633965Sjdp break; 188733965Sjdp case 'u': 188833965Sjdp unsignedp = true; 188933965Sjdp break; 189033965Sjdp default: 189133965Sjdp bad_stab (orig); 189233965Sjdp return DEBUG_TYPE_NULL; 189333965Sjdp } 189433965Sjdp ++*pp; 189533965Sjdp 189633965Sjdp /* For some odd reason, all forms of char put a c here. This is strange 189733965Sjdp because no other type has this honor. We can safely ignore this because 189833965Sjdp we actually determine 'char'acterness by the number of bits specified in 189933965Sjdp the descriptor. */ 190033965Sjdp if (**pp == 'c') 190133965Sjdp ++*pp; 190233965Sjdp 190333965Sjdp /* The first number appears to be the number of bytes occupied 190433965Sjdp by this type, except that unsigned short is 4 instead of 2. 190533965Sjdp Since this information is redundant with the third number, 190633965Sjdp we will ignore it. */ 190733965Sjdp (void) parse_number (pp, (boolean *) NULL); 190833965Sjdp if (**pp != ';') 190933965Sjdp { 191033965Sjdp bad_stab (orig); 191133965Sjdp return DEBUG_TYPE_NULL; 191233965Sjdp } 191333965Sjdp ++*pp; 191433965Sjdp 191533965Sjdp /* The second number is always 0, so ignore it too. */ 191633965Sjdp (void) parse_number (pp, (boolean *) NULL); 191733965Sjdp if (**pp != ';') 191833965Sjdp { 191933965Sjdp bad_stab (orig); 192033965Sjdp return DEBUG_TYPE_NULL; 192133965Sjdp } 192233965Sjdp ++*pp; 192333965Sjdp 192433965Sjdp /* The third number is the number of bits for this type. */ 192533965Sjdp bits = parse_number (pp, (boolean *) NULL); 192633965Sjdp 192733965Sjdp /* The type *should* end with a semicolon. If it are embedded 192833965Sjdp in a larger type the semicolon may be the only way to know where 192933965Sjdp the type ends. If this type is at the end of the stabstring we 193033965Sjdp can deal with the omitted semicolon (but we don't have to like 193133965Sjdp it). Don't bother to complain(), Sun's compiler omits the semicolon 193233965Sjdp for "void". */ 193333965Sjdp if (**pp == ';') 193433965Sjdp ++*pp; 193533965Sjdp 193633965Sjdp if (bits == 0) 193733965Sjdp return debug_make_void_type (dhandle); 193833965Sjdp 193933965Sjdp return debug_make_int_type (dhandle, bits / 8, unsignedp); 194033965Sjdp} 194133965Sjdp 194233965Sjdp/* Parse a builtin floating type generated by the Sun compiler. */ 194333965Sjdp 194433965Sjdpstatic debug_type 194533965Sjdpparse_stab_sun_floating_type (dhandle, pp) 194633965Sjdp PTR dhandle; 194733965Sjdp const char **pp; 194833965Sjdp{ 194933965Sjdp const char *orig; 195033965Sjdp bfd_vma details; 195133965Sjdp bfd_vma bytes; 195233965Sjdp 195333965Sjdp orig = *pp; 195433965Sjdp 195533965Sjdp /* The first number has more details about the type, for example 195633965Sjdp FN_COMPLEX. */ 195733965Sjdp details = parse_number (pp, (boolean *) NULL); 195833965Sjdp if (**pp != ';') 195933965Sjdp { 196033965Sjdp bad_stab (orig); 196133965Sjdp return DEBUG_TYPE_NULL; 196233965Sjdp } 196333965Sjdp 196433965Sjdp /* The second number is the number of bytes occupied by this type */ 196533965Sjdp bytes = parse_number (pp, (boolean *) NULL); 196633965Sjdp if (**pp != ';') 196733965Sjdp { 196833965Sjdp bad_stab (orig); 196933965Sjdp return DEBUG_TYPE_NULL; 197033965Sjdp } 197133965Sjdp 197233965Sjdp if (details == NF_COMPLEX 197333965Sjdp || details == NF_COMPLEX16 197433965Sjdp || details == NF_COMPLEX32) 197533965Sjdp return debug_make_complex_type (dhandle, bytes); 197633965Sjdp 197733965Sjdp return debug_make_float_type (dhandle, bytes); 197833965Sjdp} 197933965Sjdp 198033965Sjdp/* Handle an enum type. */ 198133965Sjdp 198233965Sjdpstatic debug_type 198333965Sjdpparse_stab_enum_type (dhandle, pp) 198433965Sjdp PTR dhandle; 198533965Sjdp const char **pp; 198633965Sjdp{ 198733965Sjdp const char *orig; 198833965Sjdp const char **names; 198933965Sjdp bfd_signed_vma *values; 199033965Sjdp unsigned int n; 199133965Sjdp unsigned int alloc; 199233965Sjdp 199333965Sjdp orig = *pp; 199433965Sjdp 199533965Sjdp /* FIXME: gdb checks os9k_stabs here. */ 199633965Sjdp 199733965Sjdp /* The aix4 compiler emits an extra field before the enum members; 199833965Sjdp my guess is it's a type of some sort. Just ignore it. */ 199933965Sjdp if (**pp == '-') 200033965Sjdp { 200133965Sjdp while (**pp != ':') 200233965Sjdp ++*pp; 200333965Sjdp ++*pp; 200433965Sjdp } 200533965Sjdp 200633965Sjdp /* Read the value-names and their values. 200733965Sjdp The input syntax is NAME:VALUE,NAME:VALUE, and so on. 200833965Sjdp A semicolon or comma instead of a NAME means the end. */ 200933965Sjdp alloc = 10; 201033965Sjdp names = (const char **) xmalloc (alloc * sizeof *names); 201133965Sjdp values = (bfd_signed_vma *) xmalloc (alloc * sizeof *values); 201233965Sjdp n = 0; 201333965Sjdp while (**pp != '\0' && **pp != ';' && **pp != ',') 201433965Sjdp { 201533965Sjdp const char *p; 201633965Sjdp char *name; 201733965Sjdp bfd_signed_vma val; 201833965Sjdp 201933965Sjdp p = *pp; 202033965Sjdp while (*p != ':') 202133965Sjdp ++p; 202233965Sjdp 202333965Sjdp name = savestring (*pp, p - *pp); 202433965Sjdp 202533965Sjdp *pp = p + 1; 202633965Sjdp val = (bfd_signed_vma) parse_number (pp, (boolean *) NULL); 202733965Sjdp if (**pp != ',') 202833965Sjdp { 202933965Sjdp bad_stab (orig); 203033965Sjdp return DEBUG_TYPE_NULL; 203133965Sjdp } 203233965Sjdp ++*pp; 203333965Sjdp 203433965Sjdp if (n + 1 >= alloc) 203533965Sjdp { 203633965Sjdp alloc += 10; 203733965Sjdp names = ((const char **) 203833965Sjdp xrealloc ((PTR) names, alloc * sizeof *names)); 203933965Sjdp values = ((bfd_signed_vma *) 204033965Sjdp xrealloc ((PTR) values, alloc * sizeof *values)); 204133965Sjdp } 204233965Sjdp 204333965Sjdp names[n] = name; 204433965Sjdp values[n] = val; 204533965Sjdp ++n; 204633965Sjdp } 204733965Sjdp 204833965Sjdp names[n] = NULL; 204933965Sjdp values[n] = 0; 205033965Sjdp 205133965Sjdp if (**pp == ';') 205233965Sjdp ++*pp; 205333965Sjdp 205433965Sjdp return debug_make_enum_type (dhandle, names, values); 205533965Sjdp} 205633965Sjdp 205733965Sjdp/* Read the description of a structure (or union type) and return an object 205833965Sjdp describing the type. 205933965Sjdp 206033965Sjdp PP points to a character pointer that points to the next unconsumed token 206133965Sjdp in the the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;", 206233965Sjdp *PP will point to "4a:1,0,32;;". */ 206333965Sjdp 206433965Sjdpstatic debug_type 206533965Sjdpparse_stab_struct_type (dhandle, info, tagname, pp, structp, typenums) 206633965Sjdp PTR dhandle; 206733965Sjdp struct stab_handle *info; 206833965Sjdp const char *tagname; 206933965Sjdp const char **pp; 207033965Sjdp boolean structp; 207133965Sjdp const int *typenums; 207233965Sjdp{ 207333965Sjdp const char *orig; 207433965Sjdp bfd_vma size; 207533965Sjdp debug_baseclass *baseclasses; 207633965Sjdp debug_field *fields; 207733965Sjdp boolean statics; 207833965Sjdp debug_method *methods; 207933965Sjdp debug_type vptrbase; 208033965Sjdp boolean ownvptr; 208133965Sjdp 208233965Sjdp orig = *pp; 208333965Sjdp 208433965Sjdp /* Get the size. */ 208533965Sjdp size = parse_number (pp, (boolean *) NULL); 208633965Sjdp 208733965Sjdp /* Get the other information. */ 208833965Sjdp if (! parse_stab_baseclasses (dhandle, info, pp, &baseclasses) 208933965Sjdp || ! parse_stab_struct_fields (dhandle, info, pp, &fields, &statics) 209033965Sjdp || ! parse_stab_members (dhandle, info, tagname, pp, typenums, &methods) 209133965Sjdp || ! parse_stab_tilde_field (dhandle, info, pp, typenums, &vptrbase, 209233965Sjdp &ownvptr)) 209333965Sjdp return DEBUG_TYPE_NULL; 209433965Sjdp 209533965Sjdp if (! statics 209633965Sjdp && baseclasses == NULL 209733965Sjdp && methods == NULL 209833965Sjdp && vptrbase == DEBUG_TYPE_NULL 209933965Sjdp && ! ownvptr) 210033965Sjdp return debug_make_struct_type (dhandle, structp, size, fields); 210133965Sjdp 210233965Sjdp return debug_make_object_type (dhandle, structp, size, fields, baseclasses, 210333965Sjdp methods, vptrbase, ownvptr); 210433965Sjdp} 210533965Sjdp 210633965Sjdp/* The stabs for C++ derived classes contain baseclass information which 210733965Sjdp is marked by a '!' character after the total size. This function is 210833965Sjdp called when we encounter the baseclass marker, and slurps up all the 210933965Sjdp baseclass information. 211033965Sjdp 211133965Sjdp Immediately following the '!' marker is the number of base classes that 211233965Sjdp the class is derived from, followed by information for each base class. 211333965Sjdp For each base class, there are two visibility specifiers, a bit offset 211433965Sjdp to the base class information within the derived class, a reference to 211533965Sjdp the type for the base class, and a terminating semicolon. 211633965Sjdp 211733965Sjdp A typical example, with two base classes, would be "!2,020,19;0264,21;". 211833965Sjdp ^^ ^ ^ ^ ^ ^ ^ 211933965Sjdp Baseclass information marker __________________|| | | | | | | 212033965Sjdp Number of baseclasses __________________________| | | | | | | 212133965Sjdp Visibility specifiers (2) ________________________| | | | | | 212233965Sjdp Offset in bits from start of class _________________| | | | | 212333965Sjdp Type number for base class ___________________________| | | | 212433965Sjdp Visibility specifiers (2) _______________________________| | | 212533965Sjdp Offset in bits from start of class ________________________| | 212633965Sjdp Type number of base class ____________________________________| 212733965Sjdp 212833965Sjdp Return true for success, false for failure. */ 212933965Sjdp 213033965Sjdpstatic boolean 213133965Sjdpparse_stab_baseclasses (dhandle, info, pp, retp) 213233965Sjdp PTR dhandle; 213333965Sjdp struct stab_handle *info; 213433965Sjdp const char **pp; 213533965Sjdp debug_baseclass **retp; 213633965Sjdp{ 213733965Sjdp const char *orig; 213833965Sjdp unsigned int c, i; 213933965Sjdp debug_baseclass *classes; 214033965Sjdp 214133965Sjdp *retp = NULL; 214233965Sjdp 214333965Sjdp orig = *pp; 214433965Sjdp 214533965Sjdp if (**pp != '!') 214633965Sjdp { 214733965Sjdp /* No base classes. */ 214833965Sjdp return true; 214933965Sjdp } 215033965Sjdp ++*pp; 215133965Sjdp 215233965Sjdp c = (unsigned int) parse_number (pp, (boolean *) NULL); 215333965Sjdp 215433965Sjdp if (**pp != ',') 215533965Sjdp { 215633965Sjdp bad_stab (orig); 215733965Sjdp return false; 215833965Sjdp } 215933965Sjdp ++*pp; 216033965Sjdp 216133965Sjdp classes = (debug_baseclass *) xmalloc ((c + 1) * sizeof (**retp)); 216233965Sjdp 216333965Sjdp for (i = 0; i < c; i++) 216433965Sjdp { 216533965Sjdp boolean virtual; 216633965Sjdp enum debug_visibility visibility; 216733965Sjdp bfd_vma bitpos; 216833965Sjdp debug_type type; 216933965Sjdp 217033965Sjdp switch (**pp) 217133965Sjdp { 217233965Sjdp case '0': 217333965Sjdp virtual = false; 217433965Sjdp break; 217533965Sjdp case '1': 217633965Sjdp virtual = true; 217733965Sjdp break; 217833965Sjdp default: 217960484Sobrien warn_stab (orig, _("unknown virtual character for baseclass")); 218033965Sjdp virtual = false; 218133965Sjdp break; 218233965Sjdp } 218333965Sjdp ++*pp; 218433965Sjdp 218533965Sjdp switch (**pp) 218633965Sjdp { 218733965Sjdp case '0': 218833965Sjdp visibility = DEBUG_VISIBILITY_PRIVATE; 218933965Sjdp break; 219033965Sjdp case '1': 219133965Sjdp visibility = DEBUG_VISIBILITY_PROTECTED; 219233965Sjdp break; 219333965Sjdp case '2': 219433965Sjdp visibility = DEBUG_VISIBILITY_PUBLIC; 219533965Sjdp break; 219633965Sjdp default: 219760484Sobrien warn_stab (orig, _("unknown visibility character for baseclass")); 219833965Sjdp visibility = DEBUG_VISIBILITY_PUBLIC; 219933965Sjdp break; 220033965Sjdp } 220133965Sjdp ++*pp; 220233965Sjdp 220333965Sjdp /* The remaining value is the bit offset of the portion of the 220433965Sjdp object corresponding to this baseclass. Always zero in the 220533965Sjdp absence of multiple inheritance. */ 220633965Sjdp bitpos = parse_number (pp, (boolean *) NULL); 220733965Sjdp if (**pp != ',') 220833965Sjdp { 220933965Sjdp bad_stab (orig); 221033965Sjdp return false; 221133965Sjdp } 221233965Sjdp ++*pp; 221333965Sjdp 221433965Sjdp type = parse_stab_type (dhandle, info, (const char *) NULL, pp, 221533965Sjdp (debug_type **) NULL); 221633965Sjdp if (type == DEBUG_TYPE_NULL) 221733965Sjdp return false; 221833965Sjdp 221933965Sjdp classes[i] = debug_make_baseclass (dhandle, type, bitpos, virtual, 222033965Sjdp visibility); 222133965Sjdp if (classes[i] == DEBUG_BASECLASS_NULL) 222233965Sjdp return false; 222333965Sjdp 222433965Sjdp if (**pp != ';') 222533965Sjdp return false; 222633965Sjdp ++*pp; 222733965Sjdp } 222833965Sjdp 222933965Sjdp classes[i] = DEBUG_BASECLASS_NULL; 223033965Sjdp 223133965Sjdp *retp = classes; 223233965Sjdp 223333965Sjdp return true; 223433965Sjdp} 223533965Sjdp 223633965Sjdp/* Read struct or class data fields. They have the form: 223733965Sjdp 223833965Sjdp NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ; 223933965Sjdp 224033965Sjdp At the end, we see a semicolon instead of a field. 224133965Sjdp 224233965Sjdp In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for 224333965Sjdp a static field. 224433965Sjdp 224533965Sjdp The optional VISIBILITY is one of: 224633965Sjdp 224733965Sjdp '/0' (VISIBILITY_PRIVATE) 224833965Sjdp '/1' (VISIBILITY_PROTECTED) 224933965Sjdp '/2' (VISIBILITY_PUBLIC) 225033965Sjdp '/9' (VISIBILITY_IGNORE) 225133965Sjdp 225233965Sjdp or nothing, for C style fields with public visibility. 225333965Sjdp 225433965Sjdp Returns 1 for success, 0 for failure. */ 225533965Sjdp 225633965Sjdpstatic boolean 225733965Sjdpparse_stab_struct_fields (dhandle, info, pp, retp, staticsp) 225833965Sjdp PTR dhandle; 225933965Sjdp struct stab_handle *info; 226033965Sjdp const char **pp; 226133965Sjdp debug_field **retp; 226233965Sjdp boolean *staticsp; 226333965Sjdp{ 226433965Sjdp const char *orig; 226533965Sjdp const char *p; 226633965Sjdp debug_field *fields; 226733965Sjdp unsigned int c; 226833965Sjdp unsigned int alloc; 226933965Sjdp 227033965Sjdp *retp = NULL; 227133965Sjdp *staticsp = false; 227233965Sjdp 227333965Sjdp orig = *pp; 227433965Sjdp 227533965Sjdp c = 0; 227633965Sjdp alloc = 10; 227733965Sjdp fields = (debug_field *) xmalloc (alloc * sizeof *fields); 227833965Sjdp while (**pp != ';') 227933965Sjdp { 228033965Sjdp /* FIXME: gdb checks os9k_stabs here. */ 228133965Sjdp 228233965Sjdp p = *pp; 228333965Sjdp 228433965Sjdp /* Add 1 to c to leave room for NULL pointer at end. */ 228533965Sjdp if (c + 1 >= alloc) 228633965Sjdp { 228733965Sjdp alloc += 10; 228833965Sjdp fields = ((debug_field *) 228933965Sjdp xrealloc ((PTR) fields, alloc * sizeof *fields)); 229033965Sjdp } 229133965Sjdp 229233965Sjdp /* If it starts with CPLUS_MARKER it is a special abbreviation, 229333965Sjdp unless the CPLUS_MARKER is followed by an underscore, in 229433965Sjdp which case it is just the name of an anonymous type, which we 229533965Sjdp should handle like any other type name. We accept either '$' 229633965Sjdp or '.', because a field name can never contain one of these 229733965Sjdp characters except as a CPLUS_MARKER. */ 229833965Sjdp 229933965Sjdp if ((*p == '$' || *p == '.') && p[1] != '_') 230033965Sjdp { 230133965Sjdp ++*pp; 230233965Sjdp if (! parse_stab_cpp_abbrev (dhandle, info, pp, fields + c)) 230333965Sjdp return false; 230433965Sjdp ++c; 230533965Sjdp continue; 230633965Sjdp } 230733965Sjdp 230833965Sjdp /* Look for the ':' that separates the field name from the field 230933965Sjdp values. Data members are delimited by a single ':', while member 231033965Sjdp functions are delimited by a pair of ':'s. When we hit the member 231133965Sjdp functions (if any), terminate scan loop and return. */ 231233965Sjdp 231333965Sjdp p = strchr (p, ':'); 231433965Sjdp if (p == NULL) 231533965Sjdp { 231633965Sjdp bad_stab (orig); 231733965Sjdp return false; 231833965Sjdp } 231933965Sjdp 232033965Sjdp if (p[1] == ':') 232133965Sjdp break; 232233965Sjdp 232333965Sjdp if (! parse_stab_one_struct_field (dhandle, info, pp, p, fields + c, 232433965Sjdp staticsp)) 232533965Sjdp return false; 232633965Sjdp 232733965Sjdp ++c; 232833965Sjdp } 232933965Sjdp 233033965Sjdp fields[c] = DEBUG_FIELD_NULL; 233133965Sjdp 233233965Sjdp *retp = fields; 233333965Sjdp 233433965Sjdp return true; 233533965Sjdp} 233633965Sjdp 233733965Sjdp/* Special GNU C++ name. */ 233833965Sjdp 233933965Sjdpstatic boolean 234033965Sjdpparse_stab_cpp_abbrev (dhandle, info, pp, retp) 234133965Sjdp PTR dhandle; 234233965Sjdp struct stab_handle *info; 234333965Sjdp const char **pp; 234433965Sjdp debug_field *retp; 234533965Sjdp{ 234633965Sjdp const char *orig; 234733965Sjdp int cpp_abbrev; 234833965Sjdp debug_type context; 234933965Sjdp const char *name; 235033965Sjdp const char *typename; 235133965Sjdp debug_type type; 235233965Sjdp bfd_vma bitpos; 235333965Sjdp 235433965Sjdp *retp = DEBUG_FIELD_NULL; 235533965Sjdp 235633965Sjdp orig = *pp; 235733965Sjdp 235833965Sjdp if (**pp != 'v') 235933965Sjdp { 236033965Sjdp bad_stab (*pp); 236133965Sjdp return false; 236233965Sjdp } 236333965Sjdp ++*pp; 236433965Sjdp 236533965Sjdp cpp_abbrev = **pp; 236633965Sjdp ++*pp; 236733965Sjdp 236833965Sjdp /* At this point, *pp points to something like "22:23=*22...", where 236933965Sjdp the type number before the ':' is the "context" and everything 237033965Sjdp after is a regular type definition. Lookup the type, find it's 237133965Sjdp name, and construct the field name. */ 237233965Sjdp 237333965Sjdp context = parse_stab_type (dhandle, info, (const char *) NULL, pp, 237433965Sjdp (debug_type **) NULL); 237533965Sjdp if (context == DEBUG_TYPE_NULL) 237633965Sjdp return false; 237733965Sjdp 237833965Sjdp switch (cpp_abbrev) 237933965Sjdp { 238033965Sjdp case 'f': 238133965Sjdp /* $vf -- a virtual function table pointer. */ 238233965Sjdp name = "_vptr$"; 238333965Sjdp break; 238433965Sjdp case 'b': 238533965Sjdp /* $vb -- a virtual bsomethingorother */ 238633965Sjdp typename = debug_get_type_name (dhandle, context); 238733965Sjdp if (typename == NULL) 238833965Sjdp { 238960484Sobrien warn_stab (orig, _("unnamed $vb type")); 239033965Sjdp typename = "FOO"; 239133965Sjdp } 239233965Sjdp name = concat ("_vb$", typename, (const char *) NULL); 239333965Sjdp break; 239433965Sjdp default: 239560484Sobrien warn_stab (orig, _("unrecognized C++ abbreviation")); 239633965Sjdp name = "INVALID_CPLUSPLUS_ABBREV"; 239733965Sjdp break; 239833965Sjdp } 239933965Sjdp 240033965Sjdp if (**pp != ':') 240133965Sjdp { 240233965Sjdp bad_stab (orig); 240333965Sjdp return false; 240433965Sjdp } 240533965Sjdp ++*pp; 240633965Sjdp 240733965Sjdp type = parse_stab_type (dhandle, info, (const char *) NULL, pp, 240833965Sjdp (debug_type **) NULL); 240933965Sjdp if (**pp != ',') 241033965Sjdp { 241133965Sjdp bad_stab (orig); 241233965Sjdp return false; 241333965Sjdp } 241433965Sjdp ++*pp; 241533965Sjdp 241633965Sjdp bitpos = parse_number (pp, (boolean *) NULL); 241733965Sjdp if (**pp != ';') 241833965Sjdp { 241933965Sjdp bad_stab (orig); 242033965Sjdp return false; 242133965Sjdp } 242233965Sjdp ++*pp; 242333965Sjdp 242433965Sjdp *retp = debug_make_field (dhandle, name, type, bitpos, 0, 242533965Sjdp DEBUG_VISIBILITY_PRIVATE); 242633965Sjdp if (*retp == DEBUG_FIELD_NULL) 242733965Sjdp return false; 242833965Sjdp 242933965Sjdp return true; 243033965Sjdp} 243133965Sjdp 243233965Sjdp/* Parse a single field in a struct or union. */ 243333965Sjdp 243433965Sjdpstatic boolean 243533965Sjdpparse_stab_one_struct_field (dhandle, info, pp, p, retp, staticsp) 243633965Sjdp PTR dhandle; 243733965Sjdp struct stab_handle *info; 243833965Sjdp const char **pp; 243933965Sjdp const char *p; 244033965Sjdp debug_field *retp; 244133965Sjdp boolean *staticsp; 244233965Sjdp{ 244333965Sjdp const char *orig; 244433965Sjdp char *name; 244533965Sjdp enum debug_visibility visibility; 244633965Sjdp debug_type type; 244733965Sjdp bfd_vma bitpos; 244833965Sjdp bfd_vma bitsize; 244933965Sjdp 245033965Sjdp orig = *pp; 245133965Sjdp 245233965Sjdp /* FIXME: gdb checks ARM_DEMANGLING here. */ 245333965Sjdp 245433965Sjdp name = savestring (*pp, p - *pp); 245533965Sjdp 245633965Sjdp *pp = p + 1; 245733965Sjdp 245833965Sjdp if (**pp != '/') 245933965Sjdp visibility = DEBUG_VISIBILITY_PUBLIC; 246033965Sjdp else 246133965Sjdp { 246233965Sjdp ++*pp; 246333965Sjdp switch (**pp) 246433965Sjdp { 246533965Sjdp case '0': 246633965Sjdp visibility = DEBUG_VISIBILITY_PRIVATE; 246733965Sjdp break; 246833965Sjdp case '1': 246933965Sjdp visibility = DEBUG_VISIBILITY_PROTECTED; 247033965Sjdp break; 247133965Sjdp case '2': 247233965Sjdp visibility = DEBUG_VISIBILITY_PUBLIC; 247333965Sjdp break; 247433965Sjdp default: 247560484Sobrien warn_stab (orig, _("unknown visibility character for field")); 247633965Sjdp visibility = DEBUG_VISIBILITY_PUBLIC; 247733965Sjdp break; 247833965Sjdp } 247933965Sjdp ++*pp; 248033965Sjdp } 248133965Sjdp 248233965Sjdp type = parse_stab_type (dhandle, info, (const char *) NULL, pp, 248333965Sjdp (debug_type **) NULL); 248433965Sjdp if (type == DEBUG_TYPE_NULL) 248533965Sjdp return false; 248633965Sjdp 248733965Sjdp if (**pp == ':') 248833965Sjdp { 248933965Sjdp char *varname; 249033965Sjdp 249133965Sjdp /* This is a static class member. */ 249233965Sjdp ++*pp; 249333965Sjdp p = strchr (*pp, ';'); 249433965Sjdp if (p == NULL) 249533965Sjdp { 249633965Sjdp bad_stab (orig); 249733965Sjdp return false; 249833965Sjdp } 249933965Sjdp 250033965Sjdp varname = savestring (*pp, p - *pp); 250133965Sjdp 250233965Sjdp *pp = p + 1; 250333965Sjdp 250433965Sjdp *retp = debug_make_static_member (dhandle, name, type, varname, 250533965Sjdp visibility); 250633965Sjdp *staticsp = true; 250733965Sjdp 250833965Sjdp return true; 250933965Sjdp } 251033965Sjdp 251133965Sjdp if (**pp != ',') 251233965Sjdp { 251333965Sjdp bad_stab (orig); 251433965Sjdp return false; 251533965Sjdp } 251633965Sjdp ++*pp; 251733965Sjdp 251833965Sjdp bitpos = parse_number (pp, (boolean *) NULL); 251933965Sjdp if (**pp != ',') 252033965Sjdp { 252133965Sjdp bad_stab (orig); 252233965Sjdp return false; 252333965Sjdp } 252433965Sjdp ++*pp; 252533965Sjdp 252633965Sjdp bitsize = parse_number (pp, (boolean *) NULL); 252733965Sjdp if (**pp != ';') 252833965Sjdp { 252933965Sjdp bad_stab (orig); 253033965Sjdp return false; 253133965Sjdp } 253233965Sjdp ++*pp; 253333965Sjdp 253433965Sjdp if (bitpos == 0 && bitsize == 0) 253533965Sjdp { 253633965Sjdp /* This can happen in two cases: (1) at least for gcc 2.4.5 or 253733965Sjdp so, it is a field which has been optimized out. The correct 253833965Sjdp stab for this case is to use VISIBILITY_IGNORE, but that is a 253933965Sjdp recent invention. (2) It is a 0-size array. For example 254033965Sjdp union { int num; char str[0]; } foo. Printing "<no value>" 254133965Sjdp for str in "p foo" is OK, since foo.str (and thus foo.str[3]) 254233965Sjdp will continue to work, and a 0-size array as a whole doesn't 254333965Sjdp have any contents to print. 254433965Sjdp 254533965Sjdp I suspect this probably could also happen with gcc -gstabs 254633965Sjdp (not -gstabs+) for static fields, and perhaps other C++ 254733965Sjdp extensions. Hopefully few people use -gstabs with gdb, since 254833965Sjdp it is intended for dbx compatibility. */ 254933965Sjdp visibility = DEBUG_VISIBILITY_IGNORE; 255033965Sjdp } 255133965Sjdp 255233965Sjdp /* FIXME: gdb does some stuff here to mark fields as unpacked. */ 255333965Sjdp 255433965Sjdp *retp = debug_make_field (dhandle, name, type, bitpos, bitsize, visibility); 255533965Sjdp 255633965Sjdp return true; 255733965Sjdp} 255833965Sjdp 255933965Sjdp/* Read member function stabs info for C++ classes. The form of each member 256033965Sjdp function data is: 256133965Sjdp 256233965Sjdp NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ; 256333965Sjdp 256433965Sjdp An example with two member functions is: 256533965Sjdp 256633965Sjdp afunc1::20=##15;:i;2A.;afunc2::20:i;2A.; 256733965Sjdp 256833965Sjdp For the case of overloaded operators, the format is op$::*.funcs, where 256933965Sjdp $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator 257033965Sjdp name (such as `+=') and `.' marks the end of the operator name. */ 257133965Sjdp 257233965Sjdpstatic boolean 257333965Sjdpparse_stab_members (dhandle, info, tagname, pp, typenums, retp) 257433965Sjdp PTR dhandle; 257533965Sjdp struct stab_handle *info; 257633965Sjdp const char *tagname; 257733965Sjdp const char **pp; 257833965Sjdp const int *typenums; 257933965Sjdp debug_method **retp; 258033965Sjdp{ 258133965Sjdp const char *orig; 258233965Sjdp debug_method *methods; 258333965Sjdp unsigned int c; 258433965Sjdp unsigned int alloc; 258533965Sjdp 258633965Sjdp *retp = NULL; 258733965Sjdp 258833965Sjdp orig = *pp; 258933965Sjdp 259033965Sjdp alloc = 0; 259133965Sjdp methods = NULL; 259233965Sjdp c = 0; 259333965Sjdp 259433965Sjdp while (**pp != ';') 259533965Sjdp { 259633965Sjdp const char *p; 259733965Sjdp char *name; 259833965Sjdp debug_method_variant *variants; 259933965Sjdp unsigned int cvars; 260033965Sjdp unsigned int allocvars; 260133965Sjdp debug_type look_ahead_type; 260233965Sjdp 260333965Sjdp p = strchr (*pp, ':'); 260433965Sjdp if (p == NULL || p[1] != ':') 260533965Sjdp break; 260633965Sjdp 260733965Sjdp /* FIXME: Some systems use something other than '$' here. */ 260833965Sjdp if ((*pp)[0] != 'o' || (*pp)[1] != 'p' || (*pp)[2] != '$') 260933965Sjdp { 261033965Sjdp name = savestring (*pp, p - *pp); 261133965Sjdp *pp = p + 2; 261233965Sjdp } 261333965Sjdp else 261433965Sjdp { 261533965Sjdp /* This is a completely wierd case. In order to stuff in the 261633965Sjdp names that might contain colons (the usual name delimiter), 261733965Sjdp Mike Tiemann defined a different name format which is 261833965Sjdp signalled if the identifier is "op$". In that case, the 261933965Sjdp format is "op$::XXXX." where XXXX is the name. This is 262033965Sjdp used for names like "+" or "=". YUUUUUUUK! FIXME! */ 262133965Sjdp *pp = p + 2; 262233965Sjdp for (p = *pp; *p != '.' && *p != '\0'; p++) 262333965Sjdp ; 262433965Sjdp if (*p != '.') 262533965Sjdp { 262633965Sjdp bad_stab (orig); 262733965Sjdp return false; 262833965Sjdp } 262933965Sjdp name = savestring (*pp, p - *pp); 263033965Sjdp *pp = p + 1; 263133965Sjdp } 263233965Sjdp 263333965Sjdp allocvars = 10; 263433965Sjdp variants = ((debug_method_variant *) 263533965Sjdp xmalloc (allocvars * sizeof *variants)); 263633965Sjdp cvars = 0; 263733965Sjdp 263833965Sjdp look_ahead_type = DEBUG_TYPE_NULL; 263933965Sjdp 264033965Sjdp do 264133965Sjdp { 264233965Sjdp debug_type type; 264333965Sjdp boolean stub; 264433965Sjdp char *argtypes; 264533965Sjdp enum debug_visibility visibility; 264633965Sjdp boolean constp, volatilep, staticp; 264733965Sjdp bfd_vma voffset; 264833965Sjdp debug_type context; 264933965Sjdp const char *physname; 265033965Sjdp boolean varargs; 265133965Sjdp 265233965Sjdp if (look_ahead_type != DEBUG_TYPE_NULL) 265333965Sjdp { 265433965Sjdp /* g++ version 1 kludge */ 265533965Sjdp type = look_ahead_type; 265633965Sjdp look_ahead_type = DEBUG_TYPE_NULL; 265733965Sjdp } 265833965Sjdp else 265933965Sjdp { 266033965Sjdp type = parse_stab_type (dhandle, info, (const char *) NULL, pp, 266133965Sjdp (debug_type **) NULL); 266233965Sjdp if (type == DEBUG_TYPE_NULL) 266333965Sjdp return false; 266433965Sjdp if (**pp != ':') 266533965Sjdp { 266633965Sjdp bad_stab (orig); 266733965Sjdp return false; 266833965Sjdp } 266933965Sjdp } 267033965Sjdp 267133965Sjdp ++*pp; 267233965Sjdp p = strchr (*pp, ';'); 267333965Sjdp if (p == NULL) 267433965Sjdp { 267533965Sjdp bad_stab (orig); 267633965Sjdp return false; 267733965Sjdp } 267833965Sjdp 267933965Sjdp stub = false; 268033965Sjdp if (debug_get_type_kind (dhandle, type) == DEBUG_KIND_METHOD 268133965Sjdp && debug_get_parameter_types (dhandle, type, &varargs) == NULL) 268233965Sjdp stub = true; 268333965Sjdp 268433965Sjdp argtypes = savestring (*pp, p - *pp); 268533965Sjdp *pp = p + 1; 268633965Sjdp 268733965Sjdp switch (**pp) 268833965Sjdp { 268933965Sjdp case '0': 269033965Sjdp visibility = DEBUG_VISIBILITY_PRIVATE; 269133965Sjdp break; 269233965Sjdp case '1': 269333965Sjdp visibility = DEBUG_VISIBILITY_PROTECTED; 269433965Sjdp break; 269533965Sjdp default: 269633965Sjdp visibility = DEBUG_VISIBILITY_PUBLIC; 269733965Sjdp break; 269833965Sjdp } 269933965Sjdp ++*pp; 270033965Sjdp 270133965Sjdp constp = false; 270233965Sjdp volatilep = false; 270333965Sjdp switch (**pp) 270433965Sjdp { 270533965Sjdp case 'A': 270633965Sjdp /* Normal function. */ 270733965Sjdp ++*pp; 270833965Sjdp break; 270933965Sjdp case 'B': 271033965Sjdp /* const member function. */ 271133965Sjdp constp = true; 271233965Sjdp ++*pp; 271333965Sjdp break; 271433965Sjdp case 'C': 271533965Sjdp /* volatile member function. */ 271633965Sjdp volatilep = true; 271733965Sjdp ++*pp; 271833965Sjdp break; 271933965Sjdp case 'D': 272033965Sjdp /* const volatile member function. */ 272133965Sjdp constp = true; 272233965Sjdp volatilep = true; 272333965Sjdp ++*pp; 272433965Sjdp break; 272533965Sjdp case '*': 272633965Sjdp case '?': 272733965Sjdp case '.': 272833965Sjdp /* File compiled with g++ version 1; no information. */ 272933965Sjdp break; 273033965Sjdp default: 273160484Sobrien warn_stab (orig, _("const/volatile indicator missing")); 273233965Sjdp break; 273333965Sjdp } 273433965Sjdp 273533965Sjdp staticp = false; 273633965Sjdp switch (**pp) 273733965Sjdp { 273833965Sjdp case '*': 273933965Sjdp /* virtual member function, followed by index. The sign 274033965Sjdp bit is supposedly set to distinguish 274133965Sjdp pointers-to-methods from virtual function indicies. */ 274233965Sjdp ++*pp; 274333965Sjdp voffset = parse_number (pp, (boolean *) NULL); 274433965Sjdp if (**pp != ';') 274533965Sjdp { 274633965Sjdp bad_stab (orig); 274733965Sjdp return false; 274833965Sjdp } 274933965Sjdp ++*pp; 275033965Sjdp voffset &= 0x7fffffff; 275133965Sjdp 275233965Sjdp if (**pp == ';' || *pp == '\0') 275333965Sjdp { 275433965Sjdp /* Must be g++ version 1. */ 275533965Sjdp context = DEBUG_TYPE_NULL; 275633965Sjdp } 275733965Sjdp else 275833965Sjdp { 275933965Sjdp /* Figure out from whence this virtual function 276033965Sjdp came. It may belong to virtual function table of 276133965Sjdp one of its baseclasses. */ 276233965Sjdp look_ahead_type = parse_stab_type (dhandle, info, 276333965Sjdp (const char *) NULL, 276433965Sjdp pp, 276533965Sjdp (debug_type **) NULL); 276633965Sjdp if (**pp == ':') 276733965Sjdp { 276833965Sjdp /* g++ version 1 overloaded methods. */ 276933965Sjdp context = DEBUG_TYPE_NULL; 277033965Sjdp } 277133965Sjdp else 277233965Sjdp { 277333965Sjdp context = look_ahead_type; 277433965Sjdp look_ahead_type = DEBUG_TYPE_NULL; 277533965Sjdp if (**pp != ';') 277633965Sjdp { 277733965Sjdp bad_stab (orig); 277833965Sjdp return false; 277933965Sjdp } 278033965Sjdp ++*pp; 278133965Sjdp } 278233965Sjdp } 278333965Sjdp break; 278433965Sjdp 278533965Sjdp case '?': 278633965Sjdp /* static member function. */ 278733965Sjdp ++*pp; 278833965Sjdp staticp = true; 278933965Sjdp voffset = 0; 279033965Sjdp context = DEBUG_TYPE_NULL; 279133965Sjdp if (strncmp (argtypes, name, strlen (name)) != 0) 279233965Sjdp stub = true; 279333965Sjdp break; 279433965Sjdp 279533965Sjdp default: 279633965Sjdp warn_stab (orig, "member function type missing"); 279733965Sjdp voffset = 0; 279833965Sjdp context = DEBUG_TYPE_NULL; 279933965Sjdp break; 280033965Sjdp 280133965Sjdp case '.': 280233965Sjdp ++*pp; 280333965Sjdp voffset = 0; 280433965Sjdp context = DEBUG_TYPE_NULL; 280533965Sjdp break; 280633965Sjdp } 280733965Sjdp 280833965Sjdp /* If the type is not a stub, then the argtypes string is 280933965Sjdp the physical name of the function. Otherwise the 281033965Sjdp argtypes string is the mangled form of the argument 281133965Sjdp types, and the full type and the physical name must be 281233965Sjdp extracted from them. */ 281333965Sjdp if (! stub) 281433965Sjdp physname = argtypes; 281533965Sjdp else 281633965Sjdp { 281733965Sjdp debug_type class_type, return_type; 281833965Sjdp 281933965Sjdp class_type = stab_find_type (dhandle, info, typenums); 282033965Sjdp if (class_type == DEBUG_TYPE_NULL) 282133965Sjdp return false; 282233965Sjdp return_type = debug_get_return_type (dhandle, type); 282333965Sjdp if (return_type == DEBUG_TYPE_NULL) 282433965Sjdp { 282533965Sjdp bad_stab (orig); 282633965Sjdp return false; 282733965Sjdp } 282833965Sjdp type = parse_stab_argtypes (dhandle, info, class_type, name, 282933965Sjdp tagname, return_type, argtypes, 283033965Sjdp constp, volatilep, &physname); 283133965Sjdp if (type == DEBUG_TYPE_NULL) 283233965Sjdp return false; 283333965Sjdp } 283433965Sjdp 283533965Sjdp if (cvars + 1 >= allocvars) 283633965Sjdp { 283733965Sjdp allocvars += 10; 283833965Sjdp variants = ((debug_method_variant *) 283933965Sjdp xrealloc ((PTR) variants, 284033965Sjdp allocvars * sizeof *variants)); 284133965Sjdp } 284233965Sjdp 284333965Sjdp if (! staticp) 284433965Sjdp variants[cvars] = debug_make_method_variant (dhandle, physname, 284533965Sjdp type, visibility, 284633965Sjdp constp, volatilep, 284733965Sjdp voffset, context); 284833965Sjdp else 284933965Sjdp variants[cvars] = debug_make_static_method_variant (dhandle, 285033965Sjdp physname, 285133965Sjdp type, 285233965Sjdp visibility, 285333965Sjdp constp, 285433965Sjdp volatilep); 285533965Sjdp if (variants[cvars] == DEBUG_METHOD_VARIANT_NULL) 285633965Sjdp return false; 285733965Sjdp 285833965Sjdp ++cvars; 285933965Sjdp } 286033965Sjdp while (**pp != ';' && **pp != '\0'); 286133965Sjdp 286233965Sjdp variants[cvars] = DEBUG_METHOD_VARIANT_NULL; 286333965Sjdp 286433965Sjdp if (**pp != '\0') 286533965Sjdp ++*pp; 286633965Sjdp 286733965Sjdp if (c + 1 >= alloc) 286833965Sjdp { 286933965Sjdp alloc += 10; 287033965Sjdp methods = ((debug_method *) 287133965Sjdp xrealloc ((PTR) methods, alloc * sizeof *methods)); 287233965Sjdp } 287333965Sjdp 287433965Sjdp methods[c] = debug_make_method (dhandle, name, variants); 287533965Sjdp 287633965Sjdp ++c; 287733965Sjdp } 287833965Sjdp 287933965Sjdp if (methods != NULL) 288033965Sjdp methods[c] = DEBUG_METHOD_NULL; 288133965Sjdp 288233965Sjdp *retp = methods; 288333965Sjdp 288433965Sjdp return true; 288533965Sjdp} 288633965Sjdp 288733965Sjdp/* Parse a string representing argument types for a method. Stabs 288833965Sjdp tries to save space by packing argument types into a mangled 288933965Sjdp string. This string should give us enough information to extract 289033965Sjdp both argument types and the physical name of the function, given 289133965Sjdp the tag name. */ 289233965Sjdp 289333965Sjdpstatic debug_type 289433965Sjdpparse_stab_argtypes (dhandle, info, class_type, fieldname, tagname, 289533965Sjdp return_type, argtypes, constp, volatilep, pphysname) 289633965Sjdp PTR dhandle; 289733965Sjdp struct stab_handle *info; 289833965Sjdp debug_type class_type; 289933965Sjdp const char *fieldname; 290033965Sjdp const char *tagname; 290133965Sjdp debug_type return_type; 290233965Sjdp const char *argtypes; 290333965Sjdp boolean constp; 290433965Sjdp boolean volatilep; 290533965Sjdp const char **pphysname; 290633965Sjdp{ 290733965Sjdp boolean is_full_physname_constructor; 290833965Sjdp boolean is_constructor; 290933965Sjdp boolean is_destructor; 291033965Sjdp debug_type *args; 291133965Sjdp boolean varargs; 291233965Sjdp 291333965Sjdp /* Constructors are sometimes handled specially. */ 291433965Sjdp is_full_physname_constructor = ((argtypes[0] == '_' 291533965Sjdp && argtypes[1] == '_' 291633965Sjdp && (isdigit ((unsigned char) argtypes[2]) 291733965Sjdp || argtypes[2] == 'Q' 291833965Sjdp || argtypes[2] == 't')) 291933965Sjdp || strncmp (argtypes, "__ct", 4) == 0); 292033965Sjdp 292133965Sjdp is_constructor = (is_full_physname_constructor 292233965Sjdp || (tagname != NULL 292333965Sjdp && strcmp (fieldname, tagname) == 0)); 292433965Sjdp is_destructor = ((argtypes[0] == '_' 292533965Sjdp && (argtypes[1] == '$' || argtypes[1] == '.') 292633965Sjdp && argtypes[2] == '_') 292733965Sjdp || strncmp (argtypes, "__dt", 4) == 0); 292833965Sjdp 292933965Sjdp if (is_destructor || is_full_physname_constructor) 293033965Sjdp *pphysname = argtypes; 293133965Sjdp else 293233965Sjdp { 293333965Sjdp unsigned int len; 293433965Sjdp const char *const_prefix; 293533965Sjdp const char *volatile_prefix; 293633965Sjdp char buf[20]; 293733965Sjdp unsigned int mangled_name_len; 293833965Sjdp char *physname; 293933965Sjdp 294033965Sjdp len = tagname == NULL ? 0 : strlen (tagname); 294133965Sjdp const_prefix = constp ? "C" : ""; 294233965Sjdp volatile_prefix = volatilep ? "V" : ""; 294333965Sjdp 294433965Sjdp if (len == 0) 294533965Sjdp sprintf (buf, "__%s%s", const_prefix, volatile_prefix); 294633965Sjdp else if (tagname != NULL && strchr (tagname, '<') != NULL) 294733965Sjdp { 294833965Sjdp /* Template methods are fully mangled. */ 294933965Sjdp sprintf (buf, "__%s%s", const_prefix, volatile_prefix); 295033965Sjdp tagname = NULL; 295133965Sjdp len = 0; 295233965Sjdp } 295333965Sjdp else 295433965Sjdp sprintf (buf, "__%s%s%d", const_prefix, volatile_prefix, len); 295533965Sjdp 295633965Sjdp mangled_name_len = ((is_constructor ? 0 : strlen (fieldname)) 295733965Sjdp + strlen (buf) 295833965Sjdp + len 295933965Sjdp + strlen (argtypes) 296033965Sjdp + 1); 296133965Sjdp 296233965Sjdp if (fieldname[0] == 'o' 296333965Sjdp && fieldname[1] == 'p' 296433965Sjdp && (fieldname[2] == '$' || fieldname[2] == '.')) 296533965Sjdp { 296633965Sjdp const char *opname; 296733965Sjdp 296833965Sjdp opname = cplus_mangle_opname (fieldname + 3, 0); 296933965Sjdp if (opname == NULL) 297033965Sjdp { 297160484Sobrien fprintf (stderr, _("No mangling for \"%s\"\n"), fieldname); 297233965Sjdp return DEBUG_TYPE_NULL; 297333965Sjdp } 297433965Sjdp mangled_name_len += strlen (opname); 297533965Sjdp physname = (char *) xmalloc (mangled_name_len); 297633965Sjdp strncpy (physname, fieldname, 3); 297733965Sjdp strcpy (physname + 3, opname); 297833965Sjdp } 297933965Sjdp else 298033965Sjdp { 298133965Sjdp physname = (char *) xmalloc (mangled_name_len); 298233965Sjdp if (is_constructor) 298333965Sjdp physname[0] = '\0'; 298433965Sjdp else 298533965Sjdp strcpy (physname, fieldname); 298633965Sjdp } 298733965Sjdp 298833965Sjdp strcat (physname, buf); 298933965Sjdp if (tagname != NULL) 299033965Sjdp strcat (physname, tagname); 299133965Sjdp strcat (physname, argtypes); 299233965Sjdp 299333965Sjdp *pphysname = physname; 299433965Sjdp } 299533965Sjdp 299638889Sjdp if (*argtypes == '\0' || is_destructor) 299733965Sjdp { 299833965Sjdp args = (debug_type *) xmalloc (sizeof *args); 299933965Sjdp *args = NULL; 300033965Sjdp return debug_make_method_type (dhandle, return_type, class_type, args, 300133965Sjdp false); 300233965Sjdp } 300333965Sjdp 300433965Sjdp args = stab_demangle_argtypes (dhandle, info, *pphysname, &varargs); 300533965Sjdp if (args == NULL) 300633965Sjdp return DEBUG_TYPE_NULL; 300733965Sjdp 300833965Sjdp return debug_make_method_type (dhandle, return_type, class_type, args, 300933965Sjdp varargs); 301033965Sjdp} 301133965Sjdp 301233965Sjdp/* The tail end of stabs for C++ classes that contain a virtual function 301333965Sjdp pointer contains a tilde, a %, and a type number. 301433965Sjdp The type number refers to the base class (possibly this class itself) which 301533965Sjdp contains the vtable pointer for the current class. 301633965Sjdp 301733965Sjdp This function is called when we have parsed all the method declarations, 301833965Sjdp so we can look for the vptr base class info. */ 301933965Sjdp 302033965Sjdpstatic boolean 302133965Sjdpparse_stab_tilde_field (dhandle, info, pp, typenums, retvptrbase, retownvptr) 302233965Sjdp PTR dhandle; 302333965Sjdp struct stab_handle *info; 302433965Sjdp const char **pp; 302533965Sjdp const int *typenums; 302633965Sjdp debug_type *retvptrbase; 302733965Sjdp boolean *retownvptr; 302833965Sjdp{ 302933965Sjdp const char *orig; 303033965Sjdp const char *hold; 303133965Sjdp int vtypenums[2]; 303233965Sjdp 303333965Sjdp *retvptrbase = DEBUG_TYPE_NULL; 303433965Sjdp *retownvptr = false; 303533965Sjdp 303633965Sjdp orig = *pp; 303733965Sjdp 303833965Sjdp /* If we are positioned at a ';', then skip it. */ 303933965Sjdp if (**pp == ';') 304033965Sjdp ++*pp; 304133965Sjdp 304233965Sjdp if (**pp != '~') 304333965Sjdp return true; 304433965Sjdp 304533965Sjdp ++*pp; 304633965Sjdp 304733965Sjdp if (**pp == '=' || **pp == '+' || **pp == '-') 304833965Sjdp { 304933965Sjdp /* Obsolete flags that used to indicate the presence of 305033965Sjdp constructors and/or destructors. */ 305133965Sjdp ++*pp; 305233965Sjdp } 305333965Sjdp 305433965Sjdp if (**pp != '%') 305533965Sjdp return true; 305633965Sjdp 305733965Sjdp ++*pp; 305833965Sjdp 305933965Sjdp hold = *pp; 306033965Sjdp 306133965Sjdp /* The next number is the type number of the base class (possibly 306233965Sjdp our own class) which supplies the vtable for this class. */ 306333965Sjdp if (! parse_stab_type_number (pp, vtypenums)) 306433965Sjdp return false; 306533965Sjdp 306633965Sjdp if (vtypenums[0] == typenums[0] 306733965Sjdp && vtypenums[1] == typenums[1]) 306833965Sjdp *retownvptr = true; 306933965Sjdp else 307033965Sjdp { 307133965Sjdp debug_type vtype; 307233965Sjdp const char *p; 307333965Sjdp 307433965Sjdp *pp = hold; 307533965Sjdp 307633965Sjdp vtype = parse_stab_type (dhandle, info, (const char *) NULL, pp, 307733965Sjdp (debug_type **) NULL); 307833965Sjdp for (p = *pp; *p != ';' && *p != '\0'; p++) 307933965Sjdp ; 308033965Sjdp if (*p != ';') 308133965Sjdp { 308233965Sjdp bad_stab (orig); 308333965Sjdp return false; 308433965Sjdp } 308533965Sjdp 308633965Sjdp *retvptrbase = vtype; 308733965Sjdp 308833965Sjdp *pp = p + 1; 308933965Sjdp } 309033965Sjdp 309133965Sjdp return true; 309233965Sjdp} 309333965Sjdp 309433965Sjdp/* Read a definition of an array type. */ 309533965Sjdp 309633965Sjdpstatic debug_type 309733965Sjdpparse_stab_array_type (dhandle, info, pp, stringp) 309833965Sjdp PTR dhandle; 309933965Sjdp struct stab_handle *info; 310033965Sjdp const char **pp; 310133965Sjdp boolean stringp; 310233965Sjdp{ 310333965Sjdp const char *orig; 310433965Sjdp const char *p; 310533965Sjdp int typenums[2]; 310633965Sjdp debug_type index_type; 310733965Sjdp boolean adjustable; 310833965Sjdp bfd_signed_vma lower, upper; 310933965Sjdp debug_type element_type; 311033965Sjdp 311133965Sjdp /* Format of an array type: 311233965Sjdp "ar<index type>;lower;upper;<array_contents_type>". 311333965Sjdp OS9000: "arlower,upper;<array_contents_type>". 311433965Sjdp 311533965Sjdp Fortran adjustable arrays use Adigits or Tdigits for lower or upper; 311633965Sjdp for these, produce a type like float[][]. */ 311733965Sjdp 311833965Sjdp orig = *pp; 311933965Sjdp 312033965Sjdp /* FIXME: gdb checks os9k_stabs here. */ 312133965Sjdp 312233965Sjdp /* If the index type is type 0, we take it as int. */ 312333965Sjdp p = *pp; 312433965Sjdp if (! parse_stab_type_number (&p, typenums)) 312560484Sobrien return DEBUG_TYPE_NULL; 312633965Sjdp if (typenums[0] == 0 && typenums[1] == 0 && **pp != '=') 312733965Sjdp { 312833965Sjdp index_type = debug_find_named_type (dhandle, "int"); 312933965Sjdp if (index_type == DEBUG_TYPE_NULL) 313033965Sjdp { 313133965Sjdp index_type = debug_make_int_type (dhandle, 4, false); 313233965Sjdp if (index_type == DEBUG_TYPE_NULL) 313360484Sobrien return DEBUG_TYPE_NULL; 313433965Sjdp } 313533965Sjdp *pp = p; 313633965Sjdp } 313733965Sjdp else 313833965Sjdp { 313933965Sjdp index_type = parse_stab_type (dhandle, info, (const char *) NULL, pp, 314033965Sjdp (debug_type **) NULL); 314133965Sjdp } 314233965Sjdp 314333965Sjdp if (**pp != ';') 314433965Sjdp { 314533965Sjdp bad_stab (orig); 314633965Sjdp return DEBUG_TYPE_NULL; 314733965Sjdp } 314833965Sjdp ++*pp; 314933965Sjdp 315033965Sjdp adjustable = false; 315133965Sjdp 315233965Sjdp if (! isdigit ((unsigned char) **pp) && **pp != '-') 315333965Sjdp { 315433965Sjdp ++*pp; 315533965Sjdp adjustable = true; 315633965Sjdp } 315733965Sjdp 315833965Sjdp lower = (bfd_signed_vma) parse_number (pp, (boolean *) NULL); 315933965Sjdp if (**pp != ';') 316033965Sjdp { 316133965Sjdp bad_stab (orig); 316260484Sobrien return DEBUG_TYPE_NULL; 316333965Sjdp } 316433965Sjdp ++*pp; 316533965Sjdp 316633965Sjdp if (! isdigit ((unsigned char) **pp) && **pp != '-') 316733965Sjdp { 316833965Sjdp ++*pp; 316933965Sjdp adjustable = true; 317033965Sjdp } 317133965Sjdp 317233965Sjdp upper = (bfd_signed_vma) parse_number (pp, (boolean *) NULL); 317333965Sjdp if (**pp != ';') 317433965Sjdp { 317533965Sjdp bad_stab (orig); 317660484Sobrien return DEBUG_TYPE_NULL; 317733965Sjdp } 317833965Sjdp ++*pp; 317933965Sjdp 318033965Sjdp element_type = parse_stab_type (dhandle, info, (const char *) NULL, pp, 318133965Sjdp (debug_type **) NULL); 318233965Sjdp if (element_type == DEBUG_TYPE_NULL) 318360484Sobrien return DEBUG_TYPE_NULL; 318433965Sjdp 318533965Sjdp if (adjustable) 318633965Sjdp { 318733965Sjdp lower = 0; 318833965Sjdp upper = -1; 318933965Sjdp } 319033965Sjdp 319133965Sjdp return debug_make_array_type (dhandle, element_type, index_type, lower, 319233965Sjdp upper, stringp); 319333965Sjdp} 319433965Sjdp 319533965Sjdp/* This struct holds information about files we have seen using 319633965Sjdp N_BINCL. */ 319733965Sjdp 319833965Sjdpstruct bincl_file 319933965Sjdp{ 320033965Sjdp /* The next N_BINCL file. */ 320133965Sjdp struct bincl_file *next; 320233965Sjdp /* The next N_BINCL on the stack. */ 320333965Sjdp struct bincl_file *next_stack; 320433965Sjdp /* The file name. */ 320533965Sjdp const char *name; 320633965Sjdp /* The hash value. */ 320733965Sjdp bfd_vma hash; 320833965Sjdp /* The file index. */ 320933965Sjdp unsigned int file; 321033965Sjdp /* The list of types defined in this file. */ 321133965Sjdp struct stab_types *file_types; 321233965Sjdp}; 321333965Sjdp 321433965Sjdp/* Start a new N_BINCL file, pushing it onto the stack. */ 321533965Sjdp 321633965Sjdpstatic void 321733965Sjdppush_bincl (info, name, hash) 321833965Sjdp struct stab_handle *info; 321933965Sjdp const char *name; 322033965Sjdp bfd_vma hash; 322133965Sjdp{ 322233965Sjdp struct bincl_file *n; 322333965Sjdp 322433965Sjdp n = (struct bincl_file *) xmalloc (sizeof *n); 322533965Sjdp n->next = info->bincl_list; 322633965Sjdp n->next_stack = info->bincl_stack; 322733965Sjdp n->name = name; 322833965Sjdp n->hash = hash; 322933965Sjdp n->file = info->files; 323033965Sjdp n->file_types = NULL; 323133965Sjdp info->bincl_list = n; 323233965Sjdp info->bincl_stack = n; 323333965Sjdp 323433965Sjdp ++info->files; 323533965Sjdp info->file_types = ((struct stab_types **) 323633965Sjdp xrealloc ((PTR) info->file_types, 323733965Sjdp (info->files 323833965Sjdp * sizeof *info->file_types))); 323933965Sjdp info->file_types[n->file] = NULL; 324033965Sjdp} 324133965Sjdp 324233965Sjdp/* Finish an N_BINCL file, at an N_EINCL, popping the name off the 324333965Sjdp stack. */ 324433965Sjdp 324533965Sjdpstatic const char * 324633965Sjdppop_bincl (info) 324733965Sjdp struct stab_handle *info; 324833965Sjdp{ 324933965Sjdp struct bincl_file *o; 325033965Sjdp 325133965Sjdp o = info->bincl_stack; 325233965Sjdp if (o == NULL) 325333965Sjdp return info->main_filename; 325433965Sjdp info->bincl_stack = o->next_stack; 325533965Sjdp 325633965Sjdp o->file_types = info->file_types[o->file]; 325733965Sjdp 325833965Sjdp if (info->bincl_stack == NULL) 325933965Sjdp return info->main_filename; 326033965Sjdp return info->bincl_stack->name; 326133965Sjdp} 326233965Sjdp 326333965Sjdp/* Handle an N_EXCL: get the types from the corresponding N_BINCL. */ 326433965Sjdp 326533965Sjdpstatic boolean 326633965Sjdpfind_excl (info, name, hash) 326733965Sjdp struct stab_handle *info; 326833965Sjdp const char *name; 326933965Sjdp bfd_vma hash; 327033965Sjdp{ 327133965Sjdp struct bincl_file *l; 327233965Sjdp 327333965Sjdp ++info->files; 327433965Sjdp info->file_types = ((struct stab_types **) 327533965Sjdp xrealloc ((PTR) info->file_types, 327633965Sjdp (info->files 327733965Sjdp * sizeof *info->file_types))); 327833965Sjdp 327933965Sjdp for (l = info->bincl_list; l != NULL; l = l->next) 328033965Sjdp if (l->hash == hash && strcmp (l->name, name) == 0) 328133965Sjdp break; 328233965Sjdp if (l == NULL) 328333965Sjdp { 328460484Sobrien warn_stab (name, _("Undefined N_EXCL")); 328533965Sjdp info->file_types[info->files - 1] = NULL; 328633965Sjdp return true; 328733965Sjdp } 328833965Sjdp 328933965Sjdp info->file_types[info->files - 1] = l->file_types; 329033965Sjdp 329133965Sjdp return true; 329233965Sjdp} 329333965Sjdp 329433965Sjdp/* Handle a variable definition. gcc emits variable definitions for a 329533965Sjdp block before the N_LBRAC, so we must hold onto them until we see 329633965Sjdp it. The SunPRO compiler emits variable definitions after the 329733965Sjdp N_LBRAC, so we can call debug_record_variable immediately. */ 329833965Sjdp 329933965Sjdpstatic boolean 330033965Sjdpstab_record_variable (dhandle, info, name, type, kind, val) 330133965Sjdp PTR dhandle; 330233965Sjdp struct stab_handle *info; 330333965Sjdp const char *name; 330433965Sjdp debug_type type; 330533965Sjdp enum debug_var_kind kind; 330633965Sjdp bfd_vma val; 330733965Sjdp{ 330833965Sjdp struct stab_pending_var *v; 330933965Sjdp 331033965Sjdp if ((kind == DEBUG_GLOBAL || kind == DEBUG_STATIC) 331133965Sjdp || ! info->within_function 331233965Sjdp || (info->gcc_compiled == 0 && info->n_opt_found)) 331333965Sjdp return debug_record_variable (dhandle, name, type, kind, val); 331433965Sjdp 331533965Sjdp v = (struct stab_pending_var *) xmalloc (sizeof *v); 331633965Sjdp memset (v, 0, sizeof *v); 331733965Sjdp 331833965Sjdp v->next = info->pending; 331933965Sjdp v->name = name; 332033965Sjdp v->type = type; 332133965Sjdp v->kind = kind; 332233965Sjdp v->val = val; 332333965Sjdp info->pending = v; 332433965Sjdp 332533965Sjdp return true; 332633965Sjdp} 332733965Sjdp 332833965Sjdp/* Emit pending variable definitions. This is called after we see the 332933965Sjdp N_LBRAC that starts the block. */ 333033965Sjdp 333133965Sjdpstatic boolean 333233965Sjdpstab_emit_pending_vars (dhandle, info) 333333965Sjdp PTR dhandle; 333433965Sjdp struct stab_handle *info; 333533965Sjdp{ 333633965Sjdp struct stab_pending_var *v; 333733965Sjdp 333833965Sjdp v = info->pending; 333933965Sjdp while (v != NULL) 334033965Sjdp { 334133965Sjdp struct stab_pending_var *next; 334233965Sjdp 334333965Sjdp if (! debug_record_variable (dhandle, v->name, v->type, v->kind, v->val)) 334433965Sjdp return false; 334533965Sjdp 334633965Sjdp next = v->next; 334733965Sjdp free (v); 334833965Sjdp v = next; 334933965Sjdp } 335033965Sjdp 335133965Sjdp info->pending = NULL; 335233965Sjdp 335333965Sjdp return true; 335433965Sjdp} 335533965Sjdp 335633965Sjdp/* Find the slot for a type in the database. */ 335733965Sjdp 335833965Sjdpstatic debug_type * 335933965Sjdpstab_find_slot (info, typenums) 336033965Sjdp struct stab_handle *info; 336133965Sjdp const int *typenums; 336233965Sjdp{ 336333965Sjdp int filenum; 336433965Sjdp int index; 336533965Sjdp struct stab_types **ps; 336633965Sjdp 336733965Sjdp filenum = typenums[0]; 336833965Sjdp index = typenums[1]; 336933965Sjdp 337033965Sjdp if (filenum < 0 || (unsigned int) filenum >= info->files) 337133965Sjdp { 337260484Sobrien fprintf (stderr, _("Type file number %d out of range\n"), filenum); 337333965Sjdp return NULL; 337433965Sjdp } 337533965Sjdp if (index < 0) 337633965Sjdp { 337760484Sobrien fprintf (stderr, _("Type index number %d out of range\n"), index); 337833965Sjdp return NULL; 337933965Sjdp } 338033965Sjdp 338133965Sjdp ps = info->file_types + filenum; 338233965Sjdp 338333965Sjdp while (index >= STAB_TYPES_SLOTS) 338433965Sjdp { 338533965Sjdp if (*ps == NULL) 338633965Sjdp { 338733965Sjdp *ps = (struct stab_types *) xmalloc (sizeof **ps); 338833965Sjdp memset (*ps, 0, sizeof **ps); 338933965Sjdp } 339033965Sjdp ps = &(*ps)->next; 339133965Sjdp index -= STAB_TYPES_SLOTS; 339233965Sjdp } 339333965Sjdp if (*ps == NULL) 339433965Sjdp { 339533965Sjdp *ps = (struct stab_types *) xmalloc (sizeof **ps); 339633965Sjdp memset (*ps, 0, sizeof **ps); 339733965Sjdp } 339833965Sjdp 339933965Sjdp return (*ps)->types + index; 340033965Sjdp} 340133965Sjdp 340233965Sjdp/* Find a type given a type number. If the type has not been 340333965Sjdp allocated yet, create an indirect type. */ 340433965Sjdp 340533965Sjdpstatic debug_type 340633965Sjdpstab_find_type (dhandle, info, typenums) 340733965Sjdp PTR dhandle; 340833965Sjdp struct stab_handle *info; 340933965Sjdp const int *typenums; 341033965Sjdp{ 341133965Sjdp debug_type *slot; 341233965Sjdp 341333965Sjdp if (typenums[0] == 0 && typenums[1] < 0) 341433965Sjdp { 341533965Sjdp /* A negative type number indicates an XCOFF builtin type. */ 341633965Sjdp return stab_xcoff_builtin_type (dhandle, info, typenums[1]); 341733965Sjdp } 341833965Sjdp 341933965Sjdp slot = stab_find_slot (info, typenums); 342033965Sjdp if (slot == NULL) 342133965Sjdp return DEBUG_TYPE_NULL; 342233965Sjdp 342333965Sjdp if (*slot == DEBUG_TYPE_NULL) 342433965Sjdp return debug_make_indirect_type (dhandle, slot, (const char *) NULL); 342533965Sjdp 342633965Sjdp return *slot; 342733965Sjdp} 342833965Sjdp 342933965Sjdp/* Record that a given type number refers to a given type. */ 343033965Sjdp 343133965Sjdpstatic boolean 343233965Sjdpstab_record_type (dhandle, info, typenums, type) 343360484Sobrien PTR dhandle ATTRIBUTE_UNUSED; 343433965Sjdp struct stab_handle *info; 343533965Sjdp const int *typenums; 343633965Sjdp debug_type type; 343733965Sjdp{ 343833965Sjdp debug_type *slot; 343933965Sjdp 344033965Sjdp slot = stab_find_slot (info, typenums); 344133965Sjdp if (slot == NULL) 344233965Sjdp return false; 344333965Sjdp 344433965Sjdp /* gdb appears to ignore type redefinitions, so we do as well. */ 344533965Sjdp 344633965Sjdp *slot = type; 344733965Sjdp 344833965Sjdp return true; 344933965Sjdp} 345033965Sjdp 345133965Sjdp/* Return an XCOFF builtin type. */ 345233965Sjdp 345333965Sjdpstatic debug_type 345433965Sjdpstab_xcoff_builtin_type (dhandle, info, typenum) 345533965Sjdp PTR dhandle; 345633965Sjdp struct stab_handle *info; 345733965Sjdp int typenum; 345833965Sjdp{ 345933965Sjdp debug_type rettype; 346033965Sjdp const char *name; 346133965Sjdp 346233965Sjdp if (typenum >= 0 || typenum < -XCOFF_TYPE_COUNT) 346333965Sjdp { 346460484Sobrien fprintf (stderr, _("Unrecognized XCOFF type %d\n"), typenum); 346533965Sjdp return DEBUG_TYPE_NULL; 346633965Sjdp } 346733965Sjdp if (info->xcoff_types[-typenum] != NULL) 346833965Sjdp return info->xcoff_types[-typenum]; 346933965Sjdp 347033965Sjdp switch (-typenum) 347133965Sjdp { 347233965Sjdp case 1: 347333965Sjdp /* The size of this and all the other types are fixed, defined 347433965Sjdp by the debugging format. */ 347533965Sjdp name = "int"; 347633965Sjdp rettype = debug_make_int_type (dhandle, 4, false); 347733965Sjdp break; 347833965Sjdp case 2: 347933965Sjdp name = "char"; 348033965Sjdp rettype = debug_make_int_type (dhandle, 1, false); 348133965Sjdp break; 348233965Sjdp case 3: 348333965Sjdp name = "short"; 348433965Sjdp rettype = debug_make_int_type (dhandle, 2, false); 348533965Sjdp break; 348633965Sjdp case 4: 348733965Sjdp name = "long"; 348833965Sjdp rettype = debug_make_int_type (dhandle, 4, false); 348933965Sjdp break; 349033965Sjdp case 5: 349133965Sjdp name = "unsigned char"; 349233965Sjdp rettype = debug_make_int_type (dhandle, 1, true); 349333965Sjdp break; 349433965Sjdp case 6: 349533965Sjdp name = "signed char"; 349633965Sjdp rettype = debug_make_int_type (dhandle, 1, false); 349733965Sjdp break; 349833965Sjdp case 7: 349933965Sjdp name = "unsigned short"; 350033965Sjdp rettype = debug_make_int_type (dhandle, 2, true); 350133965Sjdp break; 350233965Sjdp case 8: 350333965Sjdp name = "unsigned int"; 350433965Sjdp rettype = debug_make_int_type (dhandle, 4, true); 350533965Sjdp break; 350633965Sjdp case 9: 350733965Sjdp name = "unsigned"; 350833965Sjdp rettype = debug_make_int_type (dhandle, 4, true); 350933965Sjdp case 10: 351033965Sjdp name = "unsigned long"; 351133965Sjdp rettype = debug_make_int_type (dhandle, 4, true); 351233965Sjdp break; 351333965Sjdp case 11: 351433965Sjdp name = "void"; 351533965Sjdp rettype = debug_make_void_type (dhandle); 351633965Sjdp break; 351733965Sjdp case 12: 351833965Sjdp /* IEEE single precision (32 bit). */ 351933965Sjdp name = "float"; 352033965Sjdp rettype = debug_make_float_type (dhandle, 4); 352133965Sjdp break; 352233965Sjdp case 13: 352333965Sjdp /* IEEE double precision (64 bit). */ 352433965Sjdp name = "double"; 352533965Sjdp rettype = debug_make_float_type (dhandle, 8); 352633965Sjdp break; 352733965Sjdp case 14: 352833965Sjdp /* This is an IEEE double on the RS/6000, and different machines 352933965Sjdp with different sizes for "long double" should use different 353033965Sjdp negative type numbers. See stabs.texinfo. */ 353133965Sjdp name = "long double"; 353233965Sjdp rettype = debug_make_float_type (dhandle, 8); 353333965Sjdp break; 353433965Sjdp case 15: 353533965Sjdp name = "integer"; 353633965Sjdp rettype = debug_make_int_type (dhandle, 4, false); 353733965Sjdp break; 353833965Sjdp case 16: 353933965Sjdp name = "boolean"; 354033965Sjdp rettype = debug_make_bool_type (dhandle, 4); 354133965Sjdp break; 354233965Sjdp case 17: 354333965Sjdp name = "short real"; 354433965Sjdp rettype = debug_make_float_type (dhandle, 4); 354533965Sjdp break; 354633965Sjdp case 18: 354733965Sjdp name = "real"; 354833965Sjdp rettype = debug_make_float_type (dhandle, 8); 354933965Sjdp break; 355033965Sjdp case 19: 355133965Sjdp /* FIXME */ 355233965Sjdp name = "stringptr"; 355333965Sjdp rettype = NULL; 355433965Sjdp break; 355533965Sjdp case 20: 355633965Sjdp /* FIXME */ 355733965Sjdp name = "character"; 355833965Sjdp rettype = debug_make_int_type (dhandle, 1, true); 355933965Sjdp break; 356033965Sjdp case 21: 356133965Sjdp name = "logical*1"; 356233965Sjdp rettype = debug_make_bool_type (dhandle, 1); 356333965Sjdp break; 356433965Sjdp case 22: 356533965Sjdp name = "logical*2"; 356633965Sjdp rettype = debug_make_bool_type (dhandle, 2); 356733965Sjdp break; 356833965Sjdp case 23: 356933965Sjdp name = "logical*4"; 357033965Sjdp rettype = debug_make_bool_type (dhandle, 4); 357133965Sjdp break; 357233965Sjdp case 24: 357333965Sjdp name = "logical"; 357433965Sjdp rettype = debug_make_bool_type (dhandle, 4); 357533965Sjdp break; 357633965Sjdp case 25: 357733965Sjdp /* Complex type consisting of two IEEE single precision values. */ 357833965Sjdp name = "complex"; 357933965Sjdp rettype = debug_make_complex_type (dhandle, 8); 358033965Sjdp break; 358133965Sjdp case 26: 358233965Sjdp /* Complex type consisting of two IEEE double precision values. */ 358333965Sjdp name = "double complex"; 358433965Sjdp rettype = debug_make_complex_type (dhandle, 16); 358533965Sjdp break; 358633965Sjdp case 27: 358733965Sjdp name = "integer*1"; 358833965Sjdp rettype = debug_make_int_type (dhandle, 1, false); 358933965Sjdp break; 359033965Sjdp case 28: 359133965Sjdp name = "integer*2"; 359233965Sjdp rettype = debug_make_int_type (dhandle, 2, false); 359333965Sjdp break; 359433965Sjdp case 29: 359533965Sjdp name = "integer*4"; 359633965Sjdp rettype = debug_make_int_type (dhandle, 4, false); 359733965Sjdp break; 359833965Sjdp case 30: 359933965Sjdp /* FIXME */ 360033965Sjdp name = "wchar"; 360133965Sjdp rettype = debug_make_int_type (dhandle, 2, false); 360233965Sjdp break; 360333965Sjdp case 31: 360433965Sjdp name = "long long"; 360533965Sjdp rettype = debug_make_int_type (dhandle, 8, false); 360633965Sjdp break; 360733965Sjdp case 32: 360833965Sjdp name = "unsigned long long"; 360933965Sjdp rettype = debug_make_int_type (dhandle, 8, true); 361033965Sjdp break; 361133965Sjdp case 33: 361233965Sjdp name = "logical*8"; 361333965Sjdp rettype = debug_make_bool_type (dhandle, 8); 361433965Sjdp break; 361533965Sjdp case 34: 361633965Sjdp name = "integer*8"; 361733965Sjdp rettype = debug_make_int_type (dhandle, 8, false); 361833965Sjdp break; 361933965Sjdp default: 362033965Sjdp abort (); 362133965Sjdp } 362233965Sjdp 362333965Sjdp rettype = debug_name_type (dhandle, name, rettype); 362433965Sjdp 362533965Sjdp info->xcoff_types[-typenum] = rettype; 362633965Sjdp 362733965Sjdp return rettype; 362833965Sjdp} 362933965Sjdp 363033965Sjdp/* Find or create a tagged type. */ 363133965Sjdp 363233965Sjdpstatic debug_type 363333965Sjdpstab_find_tagged_type (dhandle, info, p, len, kind) 363433965Sjdp PTR dhandle; 363533965Sjdp struct stab_handle *info; 363633965Sjdp const char *p; 363733965Sjdp int len; 363833965Sjdp enum debug_type_kind kind; 363933965Sjdp{ 364033965Sjdp char *name; 364133965Sjdp debug_type dtype; 364233965Sjdp struct stab_tag *st; 364333965Sjdp 364433965Sjdp name = savestring (p, len); 364533965Sjdp 364633965Sjdp /* We pass DEBUG_KIND_ILLEGAL because we want all tags in the same 364733965Sjdp namespace. This is right for C, and I don't know how to handle 364833965Sjdp other languages. FIXME. */ 364933965Sjdp dtype = debug_find_tagged_type (dhandle, name, DEBUG_KIND_ILLEGAL); 365033965Sjdp if (dtype != DEBUG_TYPE_NULL) 365133965Sjdp { 365233965Sjdp free (name); 365333965Sjdp return dtype; 365433965Sjdp } 365533965Sjdp 365633965Sjdp /* We need to allocate an entry on the undefined tag list. */ 365733965Sjdp for (st = info->tags; st != NULL; st = st->next) 365833965Sjdp { 365933965Sjdp if (st->name[0] == name[0] 366033965Sjdp && strcmp (st->name, name) == 0) 366133965Sjdp { 366233965Sjdp if (st->kind == DEBUG_KIND_ILLEGAL) 366333965Sjdp st->kind = kind; 366433965Sjdp free (name); 366533965Sjdp break; 366633965Sjdp } 366733965Sjdp } 366833965Sjdp if (st == NULL) 366933965Sjdp { 367033965Sjdp st = (struct stab_tag *) xmalloc (sizeof *st); 367133965Sjdp memset (st, 0, sizeof *st); 367233965Sjdp 367333965Sjdp st->next = info->tags; 367433965Sjdp st->name = name; 367533965Sjdp st->kind = kind; 367633965Sjdp st->slot = DEBUG_TYPE_NULL; 367733965Sjdp st->type = debug_make_indirect_type (dhandle, &st->slot, name); 367833965Sjdp info->tags = st; 367933965Sjdp } 368033965Sjdp 368133965Sjdp return st->type; 368233965Sjdp} 368333965Sjdp 368433965Sjdp/* In order to get the correct argument types for a stubbed method, we 368533965Sjdp need to extract the argument types from a C++ mangled string. 368633965Sjdp Since the argument types can refer back to the return type, this 368733965Sjdp means that we must demangle the entire physical name. In gdb this 368833965Sjdp is done by calling cplus_demangle and running the results back 368933965Sjdp through the C++ expression parser. Since we have no expression 369033965Sjdp parser, we must duplicate much of the work of cplus_demangle here. 369133965Sjdp 369233965Sjdp We assume that GNU style demangling is used, since this is only 369333965Sjdp done for method stubs, and only g++ should output that form of 369433965Sjdp debugging information. */ 369533965Sjdp 369633965Sjdp/* This structure is used to hold a pointer to type information which 369733965Sjdp demangling a string. */ 369833965Sjdp 369933965Sjdpstruct stab_demangle_typestring 370033965Sjdp{ 370133965Sjdp /* The start of the type. This is not null terminated. */ 370233965Sjdp const char *typestring; 370333965Sjdp /* The length of the type. */ 370433965Sjdp unsigned int len; 370533965Sjdp}; 370633965Sjdp 370733965Sjdp/* This structure is used to hold information while demangling a 370833965Sjdp string. */ 370933965Sjdp 371033965Sjdpstruct stab_demangle_info 371133965Sjdp{ 371233965Sjdp /* The debugging information handle. */ 371333965Sjdp PTR dhandle; 371433965Sjdp /* The stab information handle. */ 371533965Sjdp struct stab_handle *info; 371633965Sjdp /* The array of arguments we are building. */ 371733965Sjdp debug_type *args; 371833965Sjdp /* Whether the method takes a variable number of arguments. */ 371933965Sjdp boolean varargs; 372033965Sjdp /* The array of types we have remembered. */ 372133965Sjdp struct stab_demangle_typestring *typestrings; 372233965Sjdp /* The number of typestrings. */ 372333965Sjdp unsigned int typestring_count; 372433965Sjdp /* The number of typestring slots we have allocated. */ 372533965Sjdp unsigned int typestring_alloc; 372633965Sjdp}; 372733965Sjdp 372833965Sjdpstatic void stab_bad_demangle PARAMS ((const char *)); 372933965Sjdpstatic unsigned int stab_demangle_count PARAMS ((const char **)); 373033965Sjdpstatic boolean stab_demangle_get_count 373133965Sjdp PARAMS ((const char **, unsigned int *)); 373233965Sjdpstatic boolean stab_demangle_prefix 373333965Sjdp PARAMS ((struct stab_demangle_info *, const char **)); 373433965Sjdpstatic boolean stab_demangle_function_name 373533965Sjdp PARAMS ((struct stab_demangle_info *, const char **, const char *)); 373633965Sjdpstatic boolean stab_demangle_signature 373733965Sjdp PARAMS ((struct stab_demangle_info *, const char **)); 373833965Sjdpstatic boolean stab_demangle_qualified 373933965Sjdp PARAMS ((struct stab_demangle_info *, const char **, debug_type *)); 374033965Sjdpstatic boolean stab_demangle_template 374160484Sobrien PARAMS ((struct stab_demangle_info *, const char **, char **)); 374233965Sjdpstatic boolean stab_demangle_class 374333965Sjdp PARAMS ((struct stab_demangle_info *, const char **, const char **)); 374433965Sjdpstatic boolean stab_demangle_args 374533965Sjdp PARAMS ((struct stab_demangle_info *, const char **, debug_type **, 374633965Sjdp boolean *)); 374733965Sjdpstatic boolean stab_demangle_arg 374833965Sjdp PARAMS ((struct stab_demangle_info *, const char **, debug_type **, 374933965Sjdp unsigned int *, unsigned int *)); 375033965Sjdpstatic boolean stab_demangle_type 375133965Sjdp PARAMS ((struct stab_demangle_info *, const char **, debug_type *)); 375233965Sjdpstatic boolean stab_demangle_fund_type 375333965Sjdp PARAMS ((struct stab_demangle_info *, const char **, debug_type *)); 375433965Sjdpstatic boolean stab_demangle_remember_type 375533965Sjdp PARAMS ((struct stab_demangle_info *, const char *, int)); 375633965Sjdp 375733965Sjdp/* Warn about a bad demangling. */ 375833965Sjdp 375933965Sjdpstatic void 376033965Sjdpstab_bad_demangle (s) 376133965Sjdp const char *s; 376233965Sjdp{ 376360484Sobrien fprintf (stderr, _("bad mangled name `%s'\n"), s); 376433965Sjdp} 376533965Sjdp 376633965Sjdp/* Get a count from a stab string. */ 376733965Sjdp 376833965Sjdpstatic unsigned int 376933965Sjdpstab_demangle_count (pp) 377033965Sjdp const char **pp; 377133965Sjdp{ 377233965Sjdp unsigned int count; 377333965Sjdp 377433965Sjdp count = 0; 377533965Sjdp while (isdigit ((unsigned char) **pp)) 377633965Sjdp { 377733965Sjdp count *= 10; 377833965Sjdp count += **pp - '0'; 377933965Sjdp ++*pp; 378033965Sjdp } 378133965Sjdp return count; 378233965Sjdp} 378333965Sjdp 378433965Sjdp/* Require a count in a string. The count may be multiple digits, in 378533965Sjdp which case it must end in an underscore. */ 378633965Sjdp 378733965Sjdpstatic boolean 378833965Sjdpstab_demangle_get_count (pp, pi) 378933965Sjdp const char **pp; 379033965Sjdp unsigned int *pi; 379133965Sjdp{ 379233965Sjdp if (! isdigit ((unsigned char) **pp)) 379333965Sjdp return false; 379433965Sjdp 379533965Sjdp *pi = **pp - '0'; 379633965Sjdp ++*pp; 379733965Sjdp if (isdigit ((unsigned char) **pp)) 379833965Sjdp { 379933965Sjdp unsigned int count; 380033965Sjdp const char *p; 380133965Sjdp 380233965Sjdp count = *pi; 380333965Sjdp p = *pp; 380433965Sjdp do 380533965Sjdp { 380633965Sjdp count *= 10; 380733965Sjdp count += *p - '0'; 380833965Sjdp ++p; 380933965Sjdp } 381033965Sjdp while (isdigit ((unsigned char) *p)); 381133965Sjdp if (*p == '_') 381233965Sjdp { 381333965Sjdp *pp = p + 1; 381433965Sjdp *pi = count; 381533965Sjdp } 381633965Sjdp } 381733965Sjdp 381833965Sjdp return true; 381933965Sjdp} 382033965Sjdp 382133965Sjdp/* This function demangles a physical name, returning a NULL 382233965Sjdp terminated array of argument types. */ 382333965Sjdp 382433965Sjdpstatic debug_type * 382533965Sjdpstab_demangle_argtypes (dhandle, info, physname, pvarargs) 382633965Sjdp PTR dhandle; 382733965Sjdp struct stab_handle *info; 382833965Sjdp const char *physname; 382933965Sjdp boolean *pvarargs; 383033965Sjdp{ 383133965Sjdp struct stab_demangle_info minfo; 383233965Sjdp 383333965Sjdp minfo.dhandle = dhandle; 383433965Sjdp minfo.info = info; 383533965Sjdp minfo.args = NULL; 383633965Sjdp minfo.varargs = false; 383733965Sjdp minfo.typestring_alloc = 10; 383833965Sjdp minfo.typestrings = ((struct stab_demangle_typestring *) 383933965Sjdp xmalloc (minfo.typestring_alloc 384033965Sjdp * sizeof *minfo.typestrings)); 384133965Sjdp minfo.typestring_count = 0; 384233965Sjdp 384333965Sjdp /* cplus_demangle checks for special GNU mangled forms, but we can't 384433965Sjdp see any of them in mangled method argument types. */ 384533965Sjdp 384633965Sjdp if (! stab_demangle_prefix (&minfo, &physname)) 384733965Sjdp goto error_return; 384833965Sjdp 384933965Sjdp if (*physname != '\0') 385033965Sjdp { 385133965Sjdp if (! stab_demangle_signature (&minfo, &physname)) 385233965Sjdp goto error_return; 385333965Sjdp } 385433965Sjdp 385533965Sjdp free (minfo.typestrings); 385633965Sjdp minfo.typestrings = NULL; 385733965Sjdp 385833965Sjdp if (minfo.args == NULL) 385960484Sobrien fprintf (stderr, _("no argument types in mangled string\n")); 386033965Sjdp 386133965Sjdp *pvarargs = minfo.varargs; 386233965Sjdp return minfo.args; 386333965Sjdp 386433965Sjdp error_return: 386533965Sjdp if (minfo.typestrings != NULL) 386633965Sjdp free (minfo.typestrings); 386733965Sjdp return NULL; 386833965Sjdp} 386933965Sjdp 387033965Sjdp/* Demangle the prefix of the mangled name. */ 387133965Sjdp 387233965Sjdpstatic boolean 387333965Sjdpstab_demangle_prefix (minfo, pp) 387433965Sjdp struct stab_demangle_info *minfo; 387533965Sjdp const char **pp; 387633965Sjdp{ 387733965Sjdp const char *scan; 387833965Sjdp unsigned int i; 387933965Sjdp 388033965Sjdp /* cplus_demangle checks for global constructors and destructors, 388133965Sjdp but we can't see them in mangled argument types. */ 388233965Sjdp 388333965Sjdp /* Look for `__'. */ 388433965Sjdp scan = *pp; 388533965Sjdp do 388633965Sjdp { 388733965Sjdp scan = strchr (scan, '_'); 388833965Sjdp } 388933965Sjdp while (scan != NULL && *++scan != '_'); 389033965Sjdp 389133965Sjdp if (scan == NULL) 389233965Sjdp { 389333965Sjdp stab_bad_demangle (*pp); 389433965Sjdp return false; 389533965Sjdp } 389633965Sjdp 389733965Sjdp --scan; 389833965Sjdp 389933965Sjdp /* We found `__'; move ahead to the last contiguous `__' pair. */ 390033965Sjdp i = strspn (scan, "_"); 390133965Sjdp if (i > 2) 390233965Sjdp scan += i - 2; 390333965Sjdp 390433965Sjdp if (scan == *pp 390533965Sjdp && (isdigit ((unsigned char) scan[2]) 390633965Sjdp || scan[2] == 'Q' 390733965Sjdp || scan[2] == 't')) 390833965Sjdp { 390933965Sjdp /* This is a GNU style constructor name. */ 391033965Sjdp *pp = scan + 2; 391133965Sjdp return true; 391233965Sjdp } 391333965Sjdp else if (scan == *pp 391433965Sjdp && ! isdigit ((unsigned char) scan[2]) 391533965Sjdp && scan[2] != 't') 391633965Sjdp { 391733965Sjdp /* Look for the `__' that separates the prefix from the 391833965Sjdp signature. */ 391933965Sjdp while (*scan == '_') 392033965Sjdp ++scan; 392133965Sjdp scan = strstr (scan, "__"); 392233965Sjdp if (scan == NULL || scan[2] == '\0') 392333965Sjdp { 392433965Sjdp stab_bad_demangle (*pp); 392533965Sjdp return false; 392633965Sjdp } 392733965Sjdp 392833965Sjdp return stab_demangle_function_name (minfo, pp, scan); 392933965Sjdp } 393033965Sjdp else if (scan[2] != '\0') 393133965Sjdp { 393233965Sjdp /* The name doesn't start with `__', but it does contain `__'. */ 393333965Sjdp return stab_demangle_function_name (minfo, pp, scan); 393433965Sjdp } 393533965Sjdp else 393633965Sjdp { 393733965Sjdp stab_bad_demangle (*pp); 393833965Sjdp return false; 393933965Sjdp } 394033965Sjdp /*NOTREACHED*/ 394133965Sjdp} 394233965Sjdp 394333965Sjdp/* Demangle a function name prefix. The scan argument points to the 394433965Sjdp double underscore which separates the function name from the 394533965Sjdp signature. */ 394633965Sjdp 394733965Sjdpstatic boolean 394833965Sjdpstab_demangle_function_name (minfo, pp, scan) 394933965Sjdp struct stab_demangle_info *minfo; 395033965Sjdp const char **pp; 395133965Sjdp const char *scan; 395233965Sjdp{ 395333965Sjdp const char *name; 395433965Sjdp 395533965Sjdp /* The string from *pp to scan is the name of the function. We 395633965Sjdp don't care about the name, since we just looking for argument 395733965Sjdp types. However, for conversion operators, the name may include a 395833965Sjdp type which we must remember in order to handle backreferences. */ 395933965Sjdp 396033965Sjdp name = *pp; 396133965Sjdp *pp = scan + 2; 396233965Sjdp 396333965Sjdp if (*pp - name >= 5 396433965Sjdp && strncmp (name, "type", 4) == 0 396533965Sjdp && (name[4] == '$' || name[4] == '.')) 396633965Sjdp { 396733965Sjdp const char *tem; 396833965Sjdp 396933965Sjdp /* This is a type conversion operator. */ 397033965Sjdp tem = name + 5; 397133965Sjdp if (! stab_demangle_type (minfo, &tem, (debug_type *) NULL)) 397233965Sjdp return false; 397333965Sjdp } 397433965Sjdp else if (name[0] == '_' 397533965Sjdp && name[1] == '_' 397633965Sjdp && name[2] == 'o' 397733965Sjdp && name[3] == 'p') 397833965Sjdp { 397933965Sjdp const char *tem; 398033965Sjdp 398133965Sjdp /* This is a type conversion operator. */ 398233965Sjdp tem = name + 4; 398333965Sjdp if (! stab_demangle_type (minfo, &tem, (debug_type *) NULL)) 398433965Sjdp return false; 398533965Sjdp } 398633965Sjdp 398733965Sjdp return true; 398833965Sjdp} 398933965Sjdp 399033965Sjdp/* Demangle the signature. This is where the argument types are 399133965Sjdp found. */ 399233965Sjdp 399333965Sjdpstatic boolean 399433965Sjdpstab_demangle_signature (minfo, pp) 399533965Sjdp struct stab_demangle_info *minfo; 399633965Sjdp const char **pp; 399733965Sjdp{ 399833965Sjdp const char *orig; 399933965Sjdp boolean expect_func, func_done; 400033965Sjdp const char *hold; 400133965Sjdp 400233965Sjdp orig = *pp; 400333965Sjdp 400433965Sjdp expect_func = false; 400533965Sjdp func_done = false; 400633965Sjdp hold = NULL; 400733965Sjdp 400833965Sjdp while (**pp != '\0') 400933965Sjdp { 401033965Sjdp switch (**pp) 401133965Sjdp { 401233965Sjdp case 'Q': 401333965Sjdp hold = *pp; 401433965Sjdp if (! stab_demangle_qualified (minfo, pp, (debug_type *) NULL) 401533965Sjdp || ! stab_demangle_remember_type (minfo, hold, *pp - hold)) 401633965Sjdp return false; 401733965Sjdp expect_func = true; 401833965Sjdp hold = NULL; 401933965Sjdp break; 402033965Sjdp 402133965Sjdp case 'S': 402233965Sjdp /* Static member function. FIXME: Can this happen? */ 402333965Sjdp if (hold == NULL) 402433965Sjdp hold = *pp; 402533965Sjdp ++*pp; 402633965Sjdp break; 402733965Sjdp 402833965Sjdp case 'C': 402933965Sjdp /* Const member function. */ 403033965Sjdp if (hold == NULL) 403133965Sjdp hold = *pp; 403233965Sjdp ++*pp; 403333965Sjdp break; 403433965Sjdp 403533965Sjdp case '0': case '1': case '2': case '3': case '4': 403633965Sjdp case '5': case '6': case '7': case '8': case '9': 403733965Sjdp if (hold == NULL) 403833965Sjdp hold = *pp; 403933965Sjdp if (! stab_demangle_class (minfo, pp, (const char **) NULL) 404033965Sjdp || ! stab_demangle_remember_type (minfo, hold, *pp - hold)) 404133965Sjdp return false; 404233965Sjdp expect_func = true; 404333965Sjdp hold = NULL; 404433965Sjdp break; 404533965Sjdp 404633965Sjdp case 'F': 404733965Sjdp /* Function. I don't know if this actually happens with g++ 404833965Sjdp output. */ 404933965Sjdp hold = NULL; 405033965Sjdp func_done = true; 405133965Sjdp ++*pp; 405233965Sjdp if (! stab_demangle_args (minfo, pp, &minfo->args, &minfo->varargs)) 405333965Sjdp return false; 405433965Sjdp break; 405533965Sjdp 405633965Sjdp case 't': 405733965Sjdp /* Template. */ 405833965Sjdp if (hold == NULL) 405933965Sjdp hold = *pp; 406060484Sobrien if (! stab_demangle_template (minfo, pp, (char **) NULL) 406133965Sjdp || ! stab_demangle_remember_type (minfo, hold, *pp - hold)) 406233965Sjdp return false; 406333965Sjdp hold = NULL; 406433965Sjdp expect_func = true; 406533965Sjdp break; 406633965Sjdp 406733965Sjdp case '_': 406833965Sjdp /* At the outermost level, we cannot have a return type 406933965Sjdp specified, so if we run into another '_' at this point we 407033965Sjdp are dealing with a mangled name that is either bogus, or 407133965Sjdp has been mangled by some algorithm we don't know how to 407233965Sjdp deal with. So just reject the entire demangling. */ 407333965Sjdp stab_bad_demangle (orig); 407433965Sjdp return false; 407533965Sjdp 407633965Sjdp default: 407733965Sjdp /* Assume we have stumbled onto the first outermost function 407833965Sjdp argument token, and start processing args. */ 407933965Sjdp func_done = true; 408033965Sjdp if (! stab_demangle_args (minfo, pp, &minfo->args, &minfo->varargs)) 408133965Sjdp return false; 408233965Sjdp break; 408333965Sjdp } 408433965Sjdp 408533965Sjdp if (expect_func) 408633965Sjdp { 408733965Sjdp func_done = true; 408833965Sjdp if (! stab_demangle_args (minfo, pp, &minfo->args, &minfo->varargs)) 408933965Sjdp return false; 409033965Sjdp } 409133965Sjdp } 409233965Sjdp 409333965Sjdp if (! func_done) 409433965Sjdp { 409533965Sjdp /* With GNU style demangling, bar__3foo is 'foo::bar(void)', and 409633965Sjdp bar__3fooi is 'foo::bar(int)'. We get here when we find the 409733965Sjdp first case, and need to ensure that the '(void)' gets added 409833965Sjdp to the current declp. */ 409933965Sjdp if (! stab_demangle_args (minfo, pp, &minfo->args, &minfo->varargs)) 410033965Sjdp return false; 410133965Sjdp } 410233965Sjdp 410333965Sjdp return true; 410433965Sjdp} 410533965Sjdp 410633965Sjdp/* Demangle a qualified name, such as "Q25Outer5Inner" which is the 410733965Sjdp mangled form of "Outer::Inner". */ 410833965Sjdp 410933965Sjdpstatic boolean 411033965Sjdpstab_demangle_qualified (minfo, pp, ptype) 411133965Sjdp struct stab_demangle_info *minfo; 411233965Sjdp const char **pp; 411333965Sjdp debug_type *ptype; 411433965Sjdp{ 411533965Sjdp const char *orig; 411633965Sjdp const char *p; 411733965Sjdp unsigned int qualifiers; 411833965Sjdp debug_type context; 411933965Sjdp 412033965Sjdp orig = *pp; 412133965Sjdp 412233965Sjdp switch ((*pp)[1]) 412333965Sjdp { 412433965Sjdp case '_': 412533965Sjdp /* GNU mangled name with more than 9 classes. The count is 412633965Sjdp preceded by an underscore (to distinguish it from the <= 9 412733965Sjdp case) and followed by an underscore. */ 412833965Sjdp p = *pp + 2; 412933965Sjdp if (! isdigit ((unsigned char) *p) || *p == '0') 413033965Sjdp { 413133965Sjdp stab_bad_demangle (orig); 413233965Sjdp return false; 413333965Sjdp } 413433965Sjdp qualifiers = atoi (p); 413533965Sjdp while (isdigit ((unsigned char) *p)) 413633965Sjdp ++p; 413733965Sjdp if (*p != '_') 413833965Sjdp { 413933965Sjdp stab_bad_demangle (orig); 414033965Sjdp return false; 414133965Sjdp } 414233965Sjdp *pp = p + 1; 414333965Sjdp break; 414433965Sjdp 414533965Sjdp case '1': case '2': case '3': case '4': case '5': 414633965Sjdp case '6': case '7': case '8': case '9': 414733965Sjdp qualifiers = (*pp)[1] - '0'; 414833965Sjdp /* Skip an optional underscore after the count. */ 414933965Sjdp if ((*pp)[2] == '_') 415033965Sjdp ++*pp; 415133965Sjdp *pp += 2; 415233965Sjdp break; 415333965Sjdp 415433965Sjdp case '0': 415533965Sjdp default: 415633965Sjdp stab_bad_demangle (orig); 415733965Sjdp return false; 415833965Sjdp } 415933965Sjdp 416033965Sjdp context = DEBUG_TYPE_NULL; 416133965Sjdp 416233965Sjdp /* Pick off the names. */ 416333965Sjdp while (qualifiers-- > 0) 416433965Sjdp { 416533965Sjdp if (**pp == '_') 416633965Sjdp ++*pp; 416733965Sjdp if (**pp == 't') 416833965Sjdp { 416960484Sobrien char *name; 417060484Sobrien 417160484Sobrien if (! stab_demangle_template (minfo, pp, 417260484Sobrien ptype != NULL ? &name : NULL)) 417333965Sjdp return false; 417460484Sobrien 417560484Sobrien if (ptype != NULL) 417660484Sobrien { 417760484Sobrien context = stab_find_tagged_type (minfo->dhandle, minfo->info, 417860484Sobrien name, strlen (name), 417960484Sobrien DEBUG_KIND_CLASS); 418060484Sobrien free (name); 418160484Sobrien if (context == DEBUG_TYPE_NULL) 418260484Sobrien return false; 418360484Sobrien } 418433965Sjdp } 418533965Sjdp else 418633965Sjdp { 418733965Sjdp unsigned int len; 418833965Sjdp 418933965Sjdp len = stab_demangle_count (pp); 419033965Sjdp if (strlen (*pp) < len) 419133965Sjdp { 419233965Sjdp stab_bad_demangle (orig); 419333965Sjdp return false; 419433965Sjdp } 419533965Sjdp 419633965Sjdp if (ptype != NULL) 419733965Sjdp { 419833965Sjdp const debug_field *fields; 419933965Sjdp 420033965Sjdp fields = NULL; 420133965Sjdp if (context != DEBUG_TYPE_NULL) 420233965Sjdp fields = debug_get_fields (minfo->dhandle, context); 420333965Sjdp 420433965Sjdp context = DEBUG_TYPE_NULL; 420533965Sjdp 420633965Sjdp if (fields != NULL) 420733965Sjdp { 420833965Sjdp char *name; 420933965Sjdp 421033965Sjdp /* Try to find the type by looking through the 421133965Sjdp fields of context until we find a field with the 421233965Sjdp same type. This ought to work for a class 421333965Sjdp defined within a class, but it won't work for, 421433965Sjdp e.g., an enum defined within a class. stabs does 421533965Sjdp not give us enough information to figure out the 421633965Sjdp latter case. */ 421733965Sjdp 421833965Sjdp name = savestring (*pp, len); 421933965Sjdp 422033965Sjdp for (; *fields != DEBUG_FIELD_NULL; fields++) 422133965Sjdp { 422233965Sjdp debug_type ft; 422333965Sjdp const char *dn; 422433965Sjdp 422533965Sjdp ft = debug_get_field_type (minfo->dhandle, *fields); 422633965Sjdp if (ft == NULL) 422733965Sjdp return false; 422833965Sjdp dn = debug_get_type_name (minfo->dhandle, ft); 422933965Sjdp if (dn != NULL && strcmp (dn, name) == 0) 423033965Sjdp { 423133965Sjdp context = ft; 423233965Sjdp break; 423333965Sjdp } 423433965Sjdp } 423533965Sjdp 423633965Sjdp free (name); 423733965Sjdp } 423833965Sjdp 423933965Sjdp if (context == DEBUG_TYPE_NULL) 424033965Sjdp { 424160484Sobrien /* We have to fall back on finding the type by name. 424233965Sjdp If there are more types to come, then this must 424333965Sjdp be a class. Otherwise, it could be anything. */ 424433965Sjdp 424533965Sjdp if (qualifiers == 0) 424633965Sjdp { 424733965Sjdp char *name; 424833965Sjdp 424933965Sjdp name = savestring (*pp, len); 425033965Sjdp context = debug_find_named_type (minfo->dhandle, 425133965Sjdp name); 425233965Sjdp free (name); 425333965Sjdp } 425433965Sjdp 425533965Sjdp if (context == DEBUG_TYPE_NULL) 425633965Sjdp { 425733965Sjdp context = stab_find_tagged_type (minfo->dhandle, 425833965Sjdp minfo->info, 425933965Sjdp *pp, len, 426033965Sjdp (qualifiers == 0 426133965Sjdp ? DEBUG_KIND_ILLEGAL 426233965Sjdp : DEBUG_KIND_CLASS)); 426333965Sjdp if (context == DEBUG_TYPE_NULL) 426433965Sjdp return false; 426533965Sjdp } 426633965Sjdp } 426733965Sjdp } 426833965Sjdp 426933965Sjdp *pp += len; 427033965Sjdp } 427133965Sjdp } 427233965Sjdp 427333965Sjdp if (ptype != NULL) 427433965Sjdp *ptype = context; 427533965Sjdp 427633965Sjdp return true; 427733965Sjdp} 427833965Sjdp 427960484Sobrien/* Demangle a template. If PNAME is not NULL, this sets *PNAME to a 428060484Sobrien string representation of the template. */ 428133965Sjdp 428233965Sjdpstatic boolean 428360484Sobrienstab_demangle_template (minfo, pp, pname) 428433965Sjdp struct stab_demangle_info *minfo; 428533965Sjdp const char **pp; 428660484Sobrien char **pname; 428733965Sjdp{ 428833965Sjdp const char *orig; 428933965Sjdp unsigned int r, i; 429033965Sjdp 429133965Sjdp orig = *pp; 429233965Sjdp 429333965Sjdp ++*pp; 429433965Sjdp 429533965Sjdp /* Skip the template name. */ 429633965Sjdp r = stab_demangle_count (pp); 429733965Sjdp if (r == 0 || strlen (*pp) < r) 429833965Sjdp { 429933965Sjdp stab_bad_demangle (orig); 430033965Sjdp return false; 430133965Sjdp } 430233965Sjdp *pp += r; 430333965Sjdp 430433965Sjdp /* Get the size of the parameter list. */ 430533965Sjdp if (stab_demangle_get_count (pp, &r) == 0) 430633965Sjdp { 430733965Sjdp stab_bad_demangle (orig); 430833965Sjdp return false; 430933965Sjdp } 431033965Sjdp 431133965Sjdp for (i = 0; i < r; i++) 431233965Sjdp { 431333965Sjdp if (**pp == 'Z') 431433965Sjdp { 431533965Sjdp /* This is a type parameter. */ 431633965Sjdp ++*pp; 431733965Sjdp if (! stab_demangle_type (minfo, pp, (debug_type *) NULL)) 431833965Sjdp return false; 431933965Sjdp } 432033965Sjdp else 432133965Sjdp { 432233965Sjdp const char *old_p; 432333965Sjdp boolean pointerp, realp, integralp, charp, boolp; 432433965Sjdp boolean done; 432533965Sjdp 432633965Sjdp old_p = *pp; 432733965Sjdp pointerp = false; 432833965Sjdp realp = false; 432933965Sjdp integralp = false; 433033965Sjdp charp = false; 433133965Sjdp boolp = false; 433233965Sjdp done = false; 433333965Sjdp 433433965Sjdp /* This is a value parameter. */ 433533965Sjdp 433633965Sjdp if (! stab_demangle_type (minfo, pp, (debug_type *) NULL)) 433733965Sjdp return false; 433833965Sjdp 433933965Sjdp while (*old_p != '\0' && ! done) 434033965Sjdp { 434133965Sjdp switch (*old_p) 434233965Sjdp { 434333965Sjdp case 'P': 434433965Sjdp case 'p': 434533965Sjdp case 'R': 434633965Sjdp pointerp = true; 434733965Sjdp done = true; 434833965Sjdp break; 434933965Sjdp case 'C': /* Const. */ 435033965Sjdp case 'S': /* Signed. */ 435133965Sjdp case 'U': /* Unsigned. */ 435233965Sjdp case 'V': /* Volatile. */ 435333965Sjdp case 'F': /* Function. */ 435433965Sjdp case 'M': /* Member function. */ 435533965Sjdp case 'O': /* ??? */ 435633965Sjdp ++old_p; 435733965Sjdp break; 435833965Sjdp case 'Q': /* Qualified name. */ 435933965Sjdp integralp = true; 436033965Sjdp done = true; 436133965Sjdp break; 436233965Sjdp case 'T': /* Remembered type. */ 436333965Sjdp abort (); 436433965Sjdp case 'v': /* Void. */ 436533965Sjdp abort (); 436633965Sjdp case 'x': /* Long long. */ 436733965Sjdp case 'l': /* Long. */ 436833965Sjdp case 'i': /* Int. */ 436933965Sjdp case 's': /* Short. */ 437033965Sjdp case 'w': /* Wchar_t. */ 437133965Sjdp integralp = true; 437233965Sjdp done = true; 437333965Sjdp break; 437433965Sjdp case 'b': /* Bool. */ 437533965Sjdp boolp = true; 437633965Sjdp done = true; 437733965Sjdp break; 437833965Sjdp case 'c': /* Char. */ 437933965Sjdp charp = true; 438033965Sjdp done = true; 438133965Sjdp break; 438233965Sjdp case 'r': /* Long double. */ 438333965Sjdp case 'd': /* Double. */ 438433965Sjdp case 'f': /* Float. */ 438533965Sjdp realp = true; 438633965Sjdp done = true; 438733965Sjdp break; 438833965Sjdp default: 438933965Sjdp /* Assume it's a user defined integral type. */ 439033965Sjdp integralp = true; 439133965Sjdp done = true; 439233965Sjdp break; 439333965Sjdp } 439433965Sjdp } 439533965Sjdp 439633965Sjdp if (integralp) 439733965Sjdp { 439833965Sjdp if (**pp == 'm') 439933965Sjdp ++*pp; 440033965Sjdp while (isdigit ((unsigned char) **pp)) 440133965Sjdp ++*pp; 440233965Sjdp } 440333965Sjdp else if (charp) 440433965Sjdp { 440533965Sjdp unsigned int val; 440633965Sjdp 440733965Sjdp if (**pp == 'm') 440833965Sjdp ++*pp; 440933965Sjdp val = stab_demangle_count (pp); 441033965Sjdp if (val == 0) 441133965Sjdp { 441233965Sjdp stab_bad_demangle (orig); 441333965Sjdp return false; 441433965Sjdp } 441533965Sjdp } 441633965Sjdp else if (boolp) 441733965Sjdp { 441833965Sjdp unsigned int val; 441933965Sjdp 442033965Sjdp val = stab_demangle_count (pp); 442133965Sjdp if (val != 0 && val != 1) 442233965Sjdp { 442333965Sjdp stab_bad_demangle (orig); 442433965Sjdp return false; 442533965Sjdp } 442633965Sjdp } 442733965Sjdp else if (realp) 442833965Sjdp { 442933965Sjdp if (**pp == 'm') 443033965Sjdp ++*pp; 443133965Sjdp while (isdigit ((unsigned char) **pp)) 443233965Sjdp ++*pp; 443333965Sjdp if (**pp == '.') 443433965Sjdp { 443533965Sjdp ++*pp; 443633965Sjdp while (isdigit ((unsigned char) **pp)) 443733965Sjdp ++*pp; 443833965Sjdp } 443933965Sjdp if (**pp == 'e') 444033965Sjdp { 444133965Sjdp ++*pp; 444233965Sjdp while (isdigit ((unsigned char) **pp)) 444333965Sjdp ++*pp; 444433965Sjdp } 444533965Sjdp } 444633965Sjdp else if (pointerp) 444733965Sjdp { 444833965Sjdp unsigned int len; 444933965Sjdp 445033965Sjdp if (! stab_demangle_get_count (pp, &len)) 445133965Sjdp { 445233965Sjdp stab_bad_demangle (orig); 445333965Sjdp return false; 445433965Sjdp } 445533965Sjdp *pp += len; 445633965Sjdp } 445733965Sjdp } 445833965Sjdp } 445933965Sjdp 446060484Sobrien /* We can translate this to a string fairly easily by invoking the 446160484Sobrien regular demangling routine. */ 446260484Sobrien if (pname != NULL) 446360484Sobrien { 446460484Sobrien char *s1, *s2, *s3, *s4; 446560484Sobrien char *from, *to; 446660484Sobrien 446760484Sobrien s1 = savestring (orig, *pp - orig); 446860484Sobrien 446960484Sobrien s2 = concat ("NoSuchStrinG__", s1, (const char *) NULL); 447060484Sobrien 447160484Sobrien free (s1); 447260484Sobrien 447360484Sobrien s3 = cplus_demangle (s2, DMGL_ANSI); 447460484Sobrien 447560484Sobrien free (s2); 447660484Sobrien 447760484Sobrien if (s3 != NULL) 447860484Sobrien s4 = strstr (s3, "::NoSuchStrinG"); 447960484Sobrien if (s3 == NULL || s4 == NULL) 448060484Sobrien { 448160484Sobrien stab_bad_demangle (orig); 448260484Sobrien if (s3 != NULL) 448360484Sobrien free (s3); 448460484Sobrien return false; 448560484Sobrien } 448660484Sobrien 448760484Sobrien /* Eliminating all spaces, except those between > characters, 448860484Sobrien makes it more likely that the demangled name will match the 448960484Sobrien name which g++ used as the structure name. */ 449060484Sobrien for (from = to = s3; from != s4; ++from) 449160484Sobrien if (*from != ' ' 449260484Sobrien || (from[1] == '>' && from > s3 && from[-1] == '>')) 449360484Sobrien *to++ = *from; 449460484Sobrien 449560484Sobrien *pname = savestring (s3, to - s3); 449660484Sobrien 449760484Sobrien free (s3); 449860484Sobrien } 449960484Sobrien 450033965Sjdp return true; 450133965Sjdp} 450233965Sjdp 450333965Sjdp/* Demangle a class name. */ 450433965Sjdp 450533965Sjdpstatic boolean 450633965Sjdpstab_demangle_class (minfo, pp, pstart) 450760484Sobrien struct stab_demangle_info *minfo ATTRIBUTE_UNUSED; 450833965Sjdp const char **pp; 450933965Sjdp const char **pstart; 451033965Sjdp{ 451133965Sjdp const char *orig; 451233965Sjdp unsigned int n; 451333965Sjdp 451433965Sjdp orig = *pp; 451533965Sjdp 451633965Sjdp n = stab_demangle_count (pp); 451733965Sjdp if (strlen (*pp) < n) 451833965Sjdp { 451933965Sjdp stab_bad_demangle (orig); 452033965Sjdp return false; 452133965Sjdp } 452233965Sjdp 452333965Sjdp if (pstart != NULL) 452433965Sjdp *pstart = *pp; 452533965Sjdp 452633965Sjdp *pp += n; 452733965Sjdp 452833965Sjdp return true; 452933965Sjdp} 453033965Sjdp 453133965Sjdp/* Demangle function arguments. If the pargs argument is not NULL, it 453233965Sjdp is set to a NULL terminated array holding the arguments. */ 453333965Sjdp 453433965Sjdpstatic boolean 453533965Sjdpstab_demangle_args (minfo, pp, pargs, pvarargs) 453633965Sjdp struct stab_demangle_info *minfo; 453733965Sjdp const char **pp; 453833965Sjdp debug_type **pargs; 453933965Sjdp boolean *pvarargs; 454033965Sjdp{ 454133965Sjdp const char *orig; 454233965Sjdp unsigned int alloc, count; 454333965Sjdp 454433965Sjdp orig = *pp; 454533965Sjdp 454633965Sjdp alloc = 10; 454733965Sjdp if (pargs != NULL) 454833965Sjdp { 454933965Sjdp *pargs = (debug_type *) xmalloc (alloc * sizeof **pargs); 455033965Sjdp *pvarargs = false; 455133965Sjdp } 455233965Sjdp count = 0; 455333965Sjdp 455433965Sjdp while (**pp != '_' && **pp != '\0' && **pp != 'e') 455533965Sjdp { 455633965Sjdp if (**pp == 'N' || **pp == 'T') 455733965Sjdp { 455833965Sjdp char temptype; 455933965Sjdp unsigned int r, t; 456033965Sjdp 456133965Sjdp temptype = **pp; 456233965Sjdp ++*pp; 456333965Sjdp 456433965Sjdp if (temptype == 'T') 456533965Sjdp r = 1; 456633965Sjdp else 456733965Sjdp { 456833965Sjdp if (! stab_demangle_get_count (pp, &r)) 456933965Sjdp { 457033965Sjdp stab_bad_demangle (orig); 457133965Sjdp return false; 457233965Sjdp } 457333965Sjdp } 457433965Sjdp 457533965Sjdp if (! stab_demangle_get_count (pp, &t)) 457633965Sjdp { 457733965Sjdp stab_bad_demangle (orig); 457833965Sjdp return false; 457933965Sjdp } 458033965Sjdp 458133965Sjdp if (t >= minfo->typestring_count) 458233965Sjdp { 458333965Sjdp stab_bad_demangle (orig); 458433965Sjdp return false; 458533965Sjdp } 458633965Sjdp while (r-- > 0) 458733965Sjdp { 458833965Sjdp const char *tem; 458933965Sjdp 459033965Sjdp tem = minfo->typestrings[t].typestring; 459133965Sjdp if (! stab_demangle_arg (minfo, &tem, pargs, &count, &alloc)) 459233965Sjdp return false; 459333965Sjdp } 459433965Sjdp } 459533965Sjdp else 459633965Sjdp { 459733965Sjdp if (! stab_demangle_arg (minfo, pp, pargs, &count, &alloc)) 459833965Sjdp return false; 459933965Sjdp } 460033965Sjdp } 460133965Sjdp 460233965Sjdp if (pargs != NULL) 460333965Sjdp (*pargs)[count] = DEBUG_TYPE_NULL; 460433965Sjdp 460533965Sjdp if (**pp == 'e') 460633965Sjdp { 460733965Sjdp if (pargs != NULL) 460833965Sjdp *pvarargs = true; 460933965Sjdp ++*pp; 461033965Sjdp } 461133965Sjdp 461233965Sjdp return true; 461333965Sjdp} 461433965Sjdp 461533965Sjdp/* Demangle a single argument. */ 461633965Sjdp 461733965Sjdpstatic boolean 461833965Sjdpstab_demangle_arg (minfo, pp, pargs, pcount, palloc) 461933965Sjdp struct stab_demangle_info *minfo; 462033965Sjdp const char **pp; 462133965Sjdp debug_type **pargs; 462233965Sjdp unsigned int *pcount; 462333965Sjdp unsigned int *palloc; 462433965Sjdp{ 462533965Sjdp const char *start; 462633965Sjdp debug_type type; 462733965Sjdp 462833965Sjdp start = *pp; 462933965Sjdp if (! stab_demangle_type (minfo, pp, 463033965Sjdp pargs == NULL ? (debug_type *) NULL : &type) 463133965Sjdp || ! stab_demangle_remember_type (minfo, start, *pp - start)) 463233965Sjdp return false; 463333965Sjdp 463433965Sjdp if (pargs != NULL) 463533965Sjdp { 463633965Sjdp if (type == DEBUG_TYPE_NULL) 463733965Sjdp return false; 463833965Sjdp 463933965Sjdp if (*pcount + 1 >= *palloc) 464033965Sjdp { 464133965Sjdp *palloc += 10; 464233965Sjdp *pargs = ((debug_type *) 464333965Sjdp xrealloc (*pargs, *palloc * sizeof **pargs)); 464433965Sjdp } 464533965Sjdp (*pargs)[*pcount] = type; 464633965Sjdp ++*pcount; 464733965Sjdp } 464833965Sjdp 464933965Sjdp return true; 465033965Sjdp} 465133965Sjdp 465233965Sjdp/* Demangle a type. If the ptype argument is not NULL, *ptype is set 465333965Sjdp to the newly allocated type. */ 465433965Sjdp 465533965Sjdpstatic boolean 465633965Sjdpstab_demangle_type (minfo, pp, ptype) 465733965Sjdp struct stab_demangle_info *minfo; 465833965Sjdp const char **pp; 465933965Sjdp debug_type *ptype; 466033965Sjdp{ 466133965Sjdp const char *orig; 466233965Sjdp 466333965Sjdp orig = *pp; 466433965Sjdp 466533965Sjdp switch (**pp) 466633965Sjdp { 466733965Sjdp case 'P': 466833965Sjdp case 'p': 466933965Sjdp /* A pointer type. */ 467033965Sjdp ++*pp; 467133965Sjdp if (! stab_demangle_type (minfo, pp, ptype)) 467233965Sjdp return false; 467333965Sjdp if (ptype != NULL) 467433965Sjdp *ptype = debug_make_pointer_type (minfo->dhandle, *ptype); 467533965Sjdp break; 467633965Sjdp 467733965Sjdp case 'R': 467833965Sjdp /* A reference type. */ 467933965Sjdp ++*pp; 468033965Sjdp if (! stab_demangle_type (minfo, pp, ptype)) 468133965Sjdp return false; 468233965Sjdp if (ptype != NULL) 468333965Sjdp *ptype = debug_make_reference_type (minfo->dhandle, *ptype); 468433965Sjdp break; 468533965Sjdp 468633965Sjdp case 'A': 468733965Sjdp /* An array. */ 468833965Sjdp { 468933965Sjdp unsigned long high; 469033965Sjdp 469133965Sjdp ++*pp; 469233965Sjdp high = 0; 469333965Sjdp while (**pp != '\0' && **pp != '_') 469433965Sjdp { 469533965Sjdp if (! isdigit ((unsigned char) **pp)) 469633965Sjdp { 469733965Sjdp stab_bad_demangle (orig); 469833965Sjdp return false; 469933965Sjdp } 470033965Sjdp high *= 10; 470133965Sjdp high += **pp - '0'; 470233965Sjdp ++*pp; 470333965Sjdp } 470433965Sjdp if (**pp != '_') 470533965Sjdp { 470633965Sjdp stab_bad_demangle (orig); 470733965Sjdp return false; 470833965Sjdp } 470933965Sjdp ++*pp; 471033965Sjdp 471133965Sjdp if (! stab_demangle_type (minfo, pp, ptype)) 471233965Sjdp return false; 471333965Sjdp if (ptype != NULL) 471433965Sjdp { 471533965Sjdp debug_type int_type; 471633965Sjdp 471733965Sjdp int_type = debug_find_named_type (minfo->dhandle, "int"); 471833965Sjdp if (int_type == NULL) 471933965Sjdp int_type = debug_make_int_type (minfo->dhandle, 4, false); 472033965Sjdp *ptype = debug_make_array_type (minfo->dhandle, *ptype, int_type, 472133965Sjdp 0, high, false); 472233965Sjdp } 472333965Sjdp } 472433965Sjdp break; 472533965Sjdp 472633965Sjdp case 'T': 472733965Sjdp /* A back reference to a remembered type. */ 472833965Sjdp { 472933965Sjdp unsigned int i; 473033965Sjdp const char *p; 473133965Sjdp 473233965Sjdp ++*pp; 473333965Sjdp if (! stab_demangle_get_count (pp, &i)) 473433965Sjdp { 473533965Sjdp stab_bad_demangle (orig); 473633965Sjdp return false; 473733965Sjdp } 473833965Sjdp if (i >= minfo->typestring_count) 473933965Sjdp { 474033965Sjdp stab_bad_demangle (orig); 474133965Sjdp return false; 474233965Sjdp } 474333965Sjdp p = minfo->typestrings[i].typestring; 474433965Sjdp if (! stab_demangle_type (minfo, &p, ptype)) 474533965Sjdp return false; 474633965Sjdp } 474733965Sjdp break; 474833965Sjdp 474933965Sjdp case 'F': 475033965Sjdp /* A function. */ 475133965Sjdp { 475233965Sjdp debug_type *args; 475333965Sjdp boolean varargs; 475433965Sjdp 475533965Sjdp ++*pp; 475633965Sjdp if (! stab_demangle_args (minfo, pp, 475733965Sjdp (ptype == NULL 475833965Sjdp ? (debug_type **) NULL 475933965Sjdp : &args), 476033965Sjdp (ptype == NULL 476133965Sjdp ? (boolean *) NULL 476233965Sjdp : &varargs))) 476333965Sjdp return false; 476433965Sjdp if (**pp != '_') 476533965Sjdp { 476633965Sjdp /* cplus_demangle will accept a function without a return 476733965Sjdp type, but I don't know when that will happen, or what 476833965Sjdp to do if it does. */ 476933965Sjdp stab_bad_demangle (orig); 477033965Sjdp return false; 477133965Sjdp } 477233965Sjdp ++*pp; 477333965Sjdp if (! stab_demangle_type (minfo, pp, ptype)) 477433965Sjdp return false; 477533965Sjdp if (ptype != NULL) 477633965Sjdp *ptype = debug_make_function_type (minfo->dhandle, *ptype, args, 477733965Sjdp varargs); 477833965Sjdp 477933965Sjdp } 478033965Sjdp break; 478133965Sjdp 478233965Sjdp case 'M': 478333965Sjdp case 'O': 478433965Sjdp { 478533965Sjdp boolean memberp, constp, volatilep; 478660484Sobrien debug_type class_type = DEBUG_TYPE_NULL; 478733965Sjdp debug_type *args; 478833965Sjdp boolean varargs; 478933965Sjdp unsigned int n; 479033965Sjdp const char *name; 479133965Sjdp 479233965Sjdp memberp = **pp == 'M'; 479333965Sjdp constp = false; 479433965Sjdp volatilep = false; 479533965Sjdp args = NULL; 479633965Sjdp varargs = false; 479733965Sjdp 479833965Sjdp ++*pp; 479960484Sobrien if (isdigit ((unsigned char) **pp)) 480033965Sjdp { 480160484Sobrien n = stab_demangle_count (pp); 480260484Sobrien if (strlen (*pp) < n) 480360484Sobrien { 480460484Sobrien stab_bad_demangle (orig); 480560484Sobrien return false; 480660484Sobrien } 480760484Sobrien name = *pp; 480860484Sobrien *pp += n; 480960484Sobrien 481060484Sobrien if (ptype != NULL) 481160484Sobrien { 481260484Sobrien class_type = stab_find_tagged_type (minfo->dhandle, 481360484Sobrien minfo->info, 481460484Sobrien name, (int) n, 481560484Sobrien DEBUG_KIND_CLASS); 481660484Sobrien if (class_type == DEBUG_TYPE_NULL) 481760484Sobrien return false; 481860484Sobrien } 481933965Sjdp } 482060484Sobrien else if (**pp == 'Q') 482133965Sjdp { 482260484Sobrien if (! stab_demangle_qualified (minfo, pp, 482360484Sobrien (ptype == NULL 482460484Sobrien ? (debug_type *) NULL 482560484Sobrien : &class_type))) 482660484Sobrien return false; 482760484Sobrien } 482860484Sobrien else 482960484Sobrien { 483033965Sjdp stab_bad_demangle (orig); 483133965Sjdp return false; 483233965Sjdp } 483333965Sjdp 483433965Sjdp if (memberp) 483533965Sjdp { 483633965Sjdp if (**pp == 'C') 483733965Sjdp { 483833965Sjdp constp = true; 483933965Sjdp ++*pp; 484033965Sjdp } 484133965Sjdp else if (**pp == 'V') 484233965Sjdp { 484333965Sjdp volatilep = true; 484433965Sjdp ++*pp; 484533965Sjdp } 484633965Sjdp if (**pp != 'F') 484733965Sjdp { 484833965Sjdp stab_bad_demangle (orig); 484933965Sjdp return false; 485033965Sjdp } 485133965Sjdp ++*pp; 485233965Sjdp if (! stab_demangle_args (minfo, pp, 485333965Sjdp (ptype == NULL 485433965Sjdp ? (debug_type **) NULL 485533965Sjdp : &args), 485633965Sjdp (ptype == NULL 485733965Sjdp ? (boolean *) NULL 485833965Sjdp : &varargs))) 485933965Sjdp return false; 486033965Sjdp } 486133965Sjdp 486233965Sjdp if (**pp != '_') 486333965Sjdp { 486433965Sjdp stab_bad_demangle (orig); 486533965Sjdp return false; 486633965Sjdp } 486733965Sjdp ++*pp; 486833965Sjdp 486933965Sjdp if (! stab_demangle_type (minfo, pp, ptype)) 487033965Sjdp return false; 487133965Sjdp 487233965Sjdp if (ptype != NULL) 487333965Sjdp { 487433965Sjdp if (! memberp) 487533965Sjdp *ptype = debug_make_offset_type (minfo->dhandle, class_type, 487633965Sjdp *ptype); 487733965Sjdp else 487833965Sjdp { 487933965Sjdp /* FIXME: We have no way to record constp or 488033965Sjdp volatilep. */ 488133965Sjdp *ptype = debug_make_method_type (minfo->dhandle, *ptype, 488233965Sjdp class_type, args, varargs); 488333965Sjdp } 488433965Sjdp } 488533965Sjdp } 488633965Sjdp break; 488733965Sjdp 488833965Sjdp case 'G': 488933965Sjdp ++*pp; 489033965Sjdp if (! stab_demangle_type (minfo, pp, ptype)) 489133965Sjdp return false; 489233965Sjdp break; 489333965Sjdp 489433965Sjdp case 'C': 489533965Sjdp ++*pp; 489633965Sjdp if (! stab_demangle_type (minfo, pp, ptype)) 489733965Sjdp return false; 489833965Sjdp if (ptype != NULL) 489933965Sjdp *ptype = debug_make_const_type (minfo->dhandle, *ptype); 490033965Sjdp break; 490133965Sjdp 490233965Sjdp case 'Q': 490333965Sjdp { 490433965Sjdp const char *hold; 490533965Sjdp 490633965Sjdp hold = *pp; 490733965Sjdp if (! stab_demangle_qualified (minfo, pp, ptype)) 490833965Sjdp return false; 490933965Sjdp } 491033965Sjdp break; 491133965Sjdp 491233965Sjdp default: 491333965Sjdp if (! stab_demangle_fund_type (minfo, pp, ptype)) 491433965Sjdp return false; 491533965Sjdp break; 491633965Sjdp } 491733965Sjdp 491833965Sjdp return true; 491933965Sjdp} 492033965Sjdp 492133965Sjdp/* Demangle a fundamental type. If the ptype argument is not NULL, 492233965Sjdp *ptype is set to the newly allocated type. */ 492333965Sjdp 492433965Sjdpstatic boolean 492533965Sjdpstab_demangle_fund_type (minfo, pp, ptype) 492633965Sjdp struct stab_demangle_info *minfo; 492733965Sjdp const char **pp; 492833965Sjdp debug_type *ptype; 492933965Sjdp{ 493033965Sjdp const char *orig; 493133965Sjdp boolean constp, volatilep, unsignedp, signedp; 493233965Sjdp boolean done; 493333965Sjdp 493433965Sjdp orig = *pp; 493533965Sjdp 493633965Sjdp constp = false; 493733965Sjdp volatilep = false; 493833965Sjdp unsignedp = false; 493933965Sjdp signedp = false; 494033965Sjdp 494133965Sjdp done = false; 494233965Sjdp while (! done) 494333965Sjdp { 494433965Sjdp switch (**pp) 494533965Sjdp { 494633965Sjdp case 'C': 494733965Sjdp constp = true; 494833965Sjdp ++*pp; 494933965Sjdp break; 495033965Sjdp 495133965Sjdp case 'U': 495233965Sjdp unsignedp = true; 495333965Sjdp ++*pp; 495433965Sjdp break; 495533965Sjdp 495633965Sjdp case 'S': 495733965Sjdp signedp = true; 495833965Sjdp ++*pp; 495933965Sjdp break; 496033965Sjdp 496133965Sjdp case 'V': 496233965Sjdp volatilep = true; 496333965Sjdp ++*pp; 496433965Sjdp break; 496533965Sjdp 496633965Sjdp default: 496733965Sjdp done = true; 496833965Sjdp break; 496933965Sjdp } 497033965Sjdp } 497133965Sjdp 497233965Sjdp switch (**pp) 497333965Sjdp { 497433965Sjdp case '\0': 497533965Sjdp case '_': 497633965Sjdp /* cplus_demangle permits this, but I don't know what it means. */ 497733965Sjdp stab_bad_demangle (orig); 497833965Sjdp break; 497933965Sjdp 498033965Sjdp case 'v': /* void */ 498133965Sjdp if (ptype != NULL) 498233965Sjdp { 498333965Sjdp *ptype = debug_find_named_type (minfo->dhandle, "void"); 498433965Sjdp if (*ptype == DEBUG_TYPE_NULL) 498533965Sjdp *ptype = debug_make_void_type (minfo->dhandle); 498633965Sjdp } 498733965Sjdp ++*pp; 498833965Sjdp break; 498933965Sjdp 499033965Sjdp case 'x': /* long long */ 499133965Sjdp if (ptype != NULL) 499233965Sjdp { 499333965Sjdp *ptype = debug_find_named_type (minfo->dhandle, 499433965Sjdp (unsignedp 499533965Sjdp ? "long long unsigned int" 499633965Sjdp : "long long int")); 499733965Sjdp if (*ptype == DEBUG_TYPE_NULL) 499833965Sjdp *ptype = debug_make_int_type (minfo->dhandle, 8, unsignedp); 499933965Sjdp } 500033965Sjdp ++*pp; 500133965Sjdp break; 500233965Sjdp 500333965Sjdp case 'l': /* long */ 500433965Sjdp if (ptype != NULL) 500533965Sjdp { 500633965Sjdp *ptype = debug_find_named_type (minfo->dhandle, 500733965Sjdp (unsignedp 500833965Sjdp ? "long unsigned int" 500933965Sjdp : "long int")); 501033965Sjdp if (*ptype == DEBUG_TYPE_NULL) 501133965Sjdp *ptype = debug_make_int_type (minfo->dhandle, 4, unsignedp); 501233965Sjdp } 501333965Sjdp ++*pp; 501433965Sjdp break; 501533965Sjdp 501633965Sjdp case 'i': /* int */ 501733965Sjdp if (ptype != NULL) 501833965Sjdp { 501933965Sjdp *ptype = debug_find_named_type (minfo->dhandle, 502033965Sjdp (unsignedp 502133965Sjdp ? "unsigned int" 502233965Sjdp : "int")); 502333965Sjdp if (*ptype == DEBUG_TYPE_NULL) 502433965Sjdp *ptype = debug_make_int_type (minfo->dhandle, 4, unsignedp); 502533965Sjdp } 502633965Sjdp ++*pp; 502733965Sjdp break; 502833965Sjdp 502933965Sjdp case 's': /* short */ 503033965Sjdp if (ptype != NULL) 503133965Sjdp { 503233965Sjdp *ptype = debug_find_named_type (minfo->dhandle, 503333965Sjdp (unsignedp 503433965Sjdp ? "short unsigned int" 503533965Sjdp : "short int")); 503633965Sjdp if (*ptype == DEBUG_TYPE_NULL) 503733965Sjdp *ptype = debug_make_int_type (minfo->dhandle, 2, unsignedp); 503833965Sjdp } 503933965Sjdp ++*pp; 504033965Sjdp break; 504133965Sjdp 504233965Sjdp case 'b': /* bool */ 504333965Sjdp if (ptype != NULL) 504433965Sjdp { 504533965Sjdp *ptype = debug_find_named_type (minfo->dhandle, "bool"); 504633965Sjdp if (*ptype == DEBUG_TYPE_NULL) 504733965Sjdp *ptype = debug_make_bool_type (minfo->dhandle, 4); 504833965Sjdp } 504933965Sjdp ++*pp; 505033965Sjdp break; 505133965Sjdp 505233965Sjdp case 'c': /* char */ 505333965Sjdp if (ptype != NULL) 505433965Sjdp { 505533965Sjdp *ptype = debug_find_named_type (minfo->dhandle, 505633965Sjdp (unsignedp 505733965Sjdp ? "unsigned char" 505833965Sjdp : (signedp 505933965Sjdp ? "signed char" 506033965Sjdp : "char"))); 506133965Sjdp if (*ptype == DEBUG_TYPE_NULL) 506233965Sjdp *ptype = debug_make_int_type (minfo->dhandle, 1, unsignedp); 506333965Sjdp } 506433965Sjdp ++*pp; 506533965Sjdp break; 506633965Sjdp 506733965Sjdp case 'w': /* wchar_t */ 506833965Sjdp if (ptype != NULL) 506933965Sjdp { 507033965Sjdp *ptype = debug_find_named_type (minfo->dhandle, "__wchar_t"); 507133965Sjdp if (*ptype == DEBUG_TYPE_NULL) 507233965Sjdp *ptype = debug_make_int_type (minfo->dhandle, 2, true); 507333965Sjdp } 507433965Sjdp ++*pp; 507533965Sjdp break; 507633965Sjdp 507733965Sjdp case 'r': /* long double */ 507833965Sjdp if (ptype != NULL) 507933965Sjdp { 508033965Sjdp *ptype = debug_find_named_type (minfo->dhandle, "long double"); 508133965Sjdp if (*ptype == DEBUG_TYPE_NULL) 508233965Sjdp *ptype = debug_make_float_type (minfo->dhandle, 8); 508333965Sjdp } 508433965Sjdp ++*pp; 508533965Sjdp break; 508633965Sjdp 508733965Sjdp case 'd': /* double */ 508833965Sjdp if (ptype != NULL) 508933965Sjdp { 509033965Sjdp *ptype = debug_find_named_type (minfo->dhandle, "double"); 509133965Sjdp if (*ptype == DEBUG_TYPE_NULL) 509233965Sjdp *ptype = debug_make_float_type (minfo->dhandle, 8); 509333965Sjdp } 509433965Sjdp ++*pp; 509533965Sjdp break; 509633965Sjdp 509733965Sjdp case 'f': /* float */ 509833965Sjdp if (ptype != NULL) 509933965Sjdp { 510033965Sjdp *ptype = debug_find_named_type (minfo->dhandle, "float"); 510133965Sjdp if (*ptype == DEBUG_TYPE_NULL) 510233965Sjdp *ptype = debug_make_float_type (minfo->dhandle, 4); 510333965Sjdp } 510433965Sjdp ++*pp; 510533965Sjdp break; 510633965Sjdp 510733965Sjdp case 'G': 510833965Sjdp ++*pp; 510933965Sjdp if (! isdigit ((unsigned char) **pp)) 511033965Sjdp { 511133965Sjdp stab_bad_demangle (orig); 511233965Sjdp return false; 511333965Sjdp } 511433965Sjdp /* Fall through. */ 511533965Sjdp case '0': case '1': case '2': case '3': case '4': 511633965Sjdp case '5': case '6': case '7': case '8': case '9': 511733965Sjdp { 511833965Sjdp const char *hold; 511933965Sjdp 512033965Sjdp if (! stab_demangle_class (minfo, pp, &hold)) 512133965Sjdp return false; 512233965Sjdp if (ptype != NULL) 512333965Sjdp { 512433965Sjdp char *name; 512533965Sjdp 512633965Sjdp name = savestring (hold, *pp - hold); 512733965Sjdp *ptype = debug_find_named_type (minfo->dhandle, name); 512860484Sobrien free (name); 512933965Sjdp if (*ptype == DEBUG_TYPE_NULL) 513033965Sjdp { 513133965Sjdp /* FIXME: It is probably incorrect to assume that 513233965Sjdp undefined types are tagged types. */ 513333965Sjdp *ptype = stab_find_tagged_type (minfo->dhandle, minfo->info, 513433965Sjdp hold, *pp - hold, 513533965Sjdp DEBUG_KIND_ILLEGAL); 513660484Sobrien if (*ptype == DEBUG_TYPE_NULL) 513760484Sobrien return false; 513833965Sjdp } 513933965Sjdp } 514033965Sjdp } 514133965Sjdp break; 514233965Sjdp 514333965Sjdp case 't': 514460484Sobrien { 514560484Sobrien char *name; 514633965Sjdp 514760484Sobrien if (! stab_demangle_template (minfo, pp, 514860484Sobrien ptype != NULL ? &name : NULL)) 514960484Sobrien return false; 515060484Sobrien if (ptype != NULL) 515160484Sobrien { 515260484Sobrien *ptype = stab_find_tagged_type (minfo->dhandle, minfo->info, 515360484Sobrien name, strlen (name), 515460484Sobrien DEBUG_KIND_CLASS); 515560484Sobrien free (name); 515660484Sobrien if (*ptype == DEBUG_TYPE_NULL) 515760484Sobrien return false; 515860484Sobrien } 515960484Sobrien } 516033965Sjdp break; 516133965Sjdp 516233965Sjdp default: 516333965Sjdp stab_bad_demangle (orig); 516433965Sjdp return false; 516533965Sjdp } 516633965Sjdp 516733965Sjdp if (ptype != NULL) 516833965Sjdp { 516933965Sjdp if (constp) 517033965Sjdp *ptype = debug_make_const_type (minfo->dhandle, *ptype); 517133965Sjdp if (volatilep) 517233965Sjdp *ptype = debug_make_volatile_type (minfo->dhandle, *ptype); 517333965Sjdp } 517433965Sjdp 517533965Sjdp return true; 517633965Sjdp} 517733965Sjdp 517833965Sjdp/* Remember a type string in a demangled string. */ 517933965Sjdp 518033965Sjdpstatic boolean 518133965Sjdpstab_demangle_remember_type (minfo, p, len) 518233965Sjdp struct stab_demangle_info *minfo; 518333965Sjdp const char *p; 518433965Sjdp int len; 518533965Sjdp{ 518633965Sjdp if (minfo->typestring_count >= minfo->typestring_alloc) 518733965Sjdp { 518833965Sjdp minfo->typestring_alloc += 10; 518933965Sjdp minfo->typestrings = ((struct stab_demangle_typestring *) 519033965Sjdp xrealloc (minfo->typestrings, 519133965Sjdp (minfo->typestring_alloc 519233965Sjdp * sizeof *minfo->typestrings))); 519333965Sjdp } 519433965Sjdp 519533965Sjdp minfo->typestrings[minfo->typestring_count].typestring = p; 519633965Sjdp minfo->typestrings[minfo->typestring_count].len = (unsigned int) len; 519733965Sjdp ++minfo->typestring_count; 519833965Sjdp 519933965Sjdp return true; 520033965Sjdp} 5201