/* Read a symbol table in ECOFF format (Third-Eye).
- Copyright (C) 1986-2015 Free Software Foundation, Inc.
+ Copyright (C) 1986-2018 Free Software Foundation, Inc.
Original version contributed by Alessandro Forin (af@cs.cmu.edu) at
CMU. Major work by Per Bothner, John Gilmore and Ian Lance Taylor
#include "expression.h"
-extern void _initialize_mdebugread (void);
-
/* Provide a way to test if we have both ECOFF and ELF symbol tables.
We use this define in order to know whether we should override a
symbol's ECOFF section with its ELF section. This is necessary in
/* Forward declarations. */
static int upgrade_type (int, struct type **, int, union aux_ext *,
- int, char *);
+ int, const char *);
-static void parse_partial_symbols (struct objfile *);
+static void parse_partial_symbols (minimal_symbol_reader &,
+ struct objfile *);
static int has_opaque_xref (FDR *, SYMR *);
static int cross_ref (int, union aux_ext *, struct type **, enum type_code,
- char **, int, char *);
+ const char **, int, const char *);
-static struct symbol *new_symbol (char *);
+static struct symbol *new_symbol (const char *);
static struct type *new_type (char *);
enum block_type { FUNCTION_BLOCK, NON_FUNCTION_BLOCK };
-static struct block *new_block (enum block_type);
+static struct block *new_block (enum block_type, enum language);
static struct compunit_symtab *new_symtab (const char *, int, struct objfile *);
static struct blockvector *new_bvect (int);
static struct type *parse_type (int, union aux_ext *, unsigned int, int *,
- int, char *);
+ int, const char *);
-static struct symbol *mylookup_symbol (char *, const struct block *,
+static struct symbol *mylookup_symbol (const char *, const struct block *,
domain_enum, enum address_class);
static void sort_blocks (struct symtab *);
-static struct partial_symtab *new_psymtab (char *, struct objfile *);
+static struct partial_symtab *new_psymtab (const char *, struct objfile *);
static void psymtab_to_symtab_1 (struct objfile *objfile,
struct partial_symtab *, const char *);
static void handle_psymbol_enumerators (struct objfile *, FDR *, int,
CORE_ADDR);
-static char *mdebug_next_symbol_text (struct objfile *);
+static const char *mdebug_next_symbol_text (struct objfile *);
\f
/* Exported procedure: Builds a symtab from the partial symtab SELF.
Restores the environment in effect when SELF was created, delegates
/* Return a safer print NAME for a file descriptor. */
-static char *
+static const char *
fdr_name (FDR *f)
{
if (f->rss == -1)
different sections are relocated via the SECTION_OFFSETS. */
void
-mdebug_build_psymtabs (struct objfile *objfile,
+mdebug_build_psymtabs (minimal_symbol_reader &reader,
+ struct objfile *objfile,
const struct ecoff_debug_swap *swap,
struct ecoff_debug_info *info)
{
(*swap->swap_fdr_in) (objfile->obfd, fdr_src, fdr_ptr);
}
- parse_partial_symbols (objfile);
+ parse_partial_symbols (reader, objfile);
#if 0
/* Check to make sure file was compiled with -g. If not, warn the
static void
add_data_symbol (SYMR *sh, union aux_ext *ax, int bigend,
struct symbol *s, int aclass_index, struct block *b,
- struct objfile *objfile, char *name)
+ struct objfile *objfile, const char *name)
{
SYMBOL_DOMAIN (s) = VAR_DOMAIN;
SYMBOL_ACLASS_INDEX (s) = aclass_index;
struct gdbarch *gdbarch = get_objfile_arch (objfile);
const bfd_size_type external_sym_size = debug_swap->external_sym_size;
void (*const swap_sym_in) (bfd *, void *, SYMR *) = debug_swap->swap_sym_in;
- char *name;
+ const char *name;
struct symbol *s;
struct block *b;
struct mdebug_pending *pend;
TYPE_PROTOTYPED (SYMBOL_TYPE (s)) = 1;
/* Create and enter a new lexical context. */
- b = new_block (FUNCTION_BLOCK);
+ b = new_block (FUNCTION_BLOCK, SYMBOL_LANGUAGE (s));
SYMBOL_BLOCK_VALUE (s) = b;
BLOCK_FUNCTION (b) = s;
BLOCK_START (b) = BLOCK_END (b) = sh->value;
}
top_stack->blocktype = stBlock;
- b = new_block (NON_FUNCTION_BLOCK);
+ b = new_block (NON_FUNCTION_BLOCK, psymtab_language);
BLOCK_START (b) = sh->value + top_stack->procadr;
BLOCK_SUPERBLOCK (b) = top_stack->cur_block;
top_stack->cur_block = b;
break;
case btAdr:
- tp = init_type (TYPE_CODE_PTR, 4, TYPE_FLAG_UNSIGNED,
- "adr_32", objfile);
- TYPE_TARGET_TYPE (tp) = objfile_type (objfile)->builtin_void;
+ tp = init_pointer_type (objfile, 32, "adr_32",
+ objfile_type (objfile)->builtin_void);
break;
case btChar:
- tp = init_type (TYPE_CODE_INT, 1, 0,
- "char", objfile);
+ tp = init_integer_type (objfile, 8, 0, "char");
+ TYPE_NOSIGN (tp) = 1;
break;
case btUChar:
- tp = init_type (TYPE_CODE_INT, 1, TYPE_FLAG_UNSIGNED,
- "unsigned char", objfile);
+ tp = init_integer_type (objfile, 8, 1, "unsigned char");
break;
case btShort:
- tp = init_type (TYPE_CODE_INT, 2, 0,
- "short", objfile);
+ tp = init_integer_type (objfile, 16, 0, "short");
break;
case btUShort:
- tp = init_type (TYPE_CODE_INT, 2, TYPE_FLAG_UNSIGNED,
- "unsigned short", objfile);
+ tp = init_integer_type (objfile, 16, 1, "unsigned short");
break;
case btInt:
- tp = init_type (TYPE_CODE_INT, 4, 0,
- "int", objfile);
+ tp = init_integer_type (objfile, 32, 0, "int");
break;
case btUInt:
- tp = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED,
- "unsigned int", objfile);
+ tp = init_integer_type (objfile, 32, 1, "unsigned int");
break;
case btLong:
- tp = init_type (TYPE_CODE_INT, 4, 0,
- "long", objfile);
+ tp = init_integer_type (objfile, 32, 0, "long");
break;
case btULong:
- tp = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED,
- "unsigned long", objfile);
+ tp = init_integer_type (objfile, 32, 1, "unsigned long");
break;
case btFloat:
- tp = init_type (TYPE_CODE_FLT,
- gdbarch_float_bit (gdbarch) / TARGET_CHAR_BIT, 0,
- "float", objfile);
+ tp = init_float_type (objfile, gdbarch_float_bit (gdbarch),
+ "float", gdbarch_float_format (gdbarch));
break;
case btDouble:
- tp = init_type (TYPE_CODE_FLT,
- gdbarch_double_bit (gdbarch) / TARGET_CHAR_BIT, 0,
- "double", objfile);
+ tp = init_float_type (objfile, gdbarch_double_bit (gdbarch),
+ "double", gdbarch_double_format (gdbarch));
break;
case btComplex:
- tp = init_type (TYPE_CODE_COMPLEX,
- 2 * gdbarch_float_bit (gdbarch) / TARGET_CHAR_BIT, 0,
- "complex", objfile);
- TYPE_TARGET_TYPE (tp) = basic_type (btFloat, objfile);
+ tp = init_complex_type (objfile, "complex",
+ basic_type (btFloat, objfile));
break;
case btDComplex:
- tp = init_type (TYPE_CODE_COMPLEX,
- 2 * gdbarch_double_bit (gdbarch) / TARGET_CHAR_BIT, 0,
- "double complex", objfile);
- TYPE_TARGET_TYPE (tp) = basic_type (btDouble, objfile);
+ tp = init_complex_type (objfile, "double complex",
+ basic_type (btFloat, objfile));
break;
case btFixedDec:
/* We use TYPE_CODE_INT to print these as integers. Does this do any
good? Would we be better off with TYPE_CODE_ERROR? Should
TYPE_CODE_ERROR print things in hex if it knows the size? */
- tp = init_type (TYPE_CODE_INT,
- gdbarch_int_bit (gdbarch) / TARGET_CHAR_BIT, 0,
- "fixed decimal", objfile);
+ tp = init_integer_type (objfile, gdbarch_int_bit (gdbarch), 0,
+ "fixed decimal");
break;
case btFloatDec:
- tp = init_type (TYPE_CODE_ERROR,
- gdbarch_double_bit (gdbarch) / TARGET_CHAR_BIT, 0,
- "floating decimal", objfile);
+ tp = init_type (objfile, TYPE_CODE_ERROR,
+ gdbarch_double_bit (gdbarch), "floating decimal");
break;
case btString:
/* Is a "string" the way btString means it the same as TYPE_CODE_STRING?
FIXME. */
- tp = init_type (TYPE_CODE_STRING, 1, 0,
- "string", objfile);
+ tp = init_type (objfile, TYPE_CODE_STRING, TARGET_CHAR_BIT, "string");
break;
case btVoid:
break;
case btLong64:
- tp = init_type (TYPE_CODE_INT, 8, 0,
- "long", objfile);
+ tp = init_integer_type (objfile, 64, 0, "long");
break;
case btULong64:
- tp = init_type (TYPE_CODE_INT, 8, TYPE_FLAG_UNSIGNED,
- "unsigned long", objfile);
+ tp = init_integer_type (objfile, 64, 1, "unsigned long");
break;
case btLongLong64:
- tp = init_type (TYPE_CODE_INT, 8, 0,
- "long long", objfile);
+ tp = init_integer_type (objfile, 64, 0, "long long");
break;
case btULongLong64:
- tp = init_type (TYPE_CODE_INT, 8, TYPE_FLAG_UNSIGNED,
- "unsigned long long", objfile);
+ tp = init_integer_type (objfile, 64, 1, "unsigned long long");
break;
case btAdr64:
- tp = init_type (TYPE_CODE_PTR, 8, TYPE_FLAG_UNSIGNED,
- "adr_64", objfile);
- TYPE_TARGET_TYPE (tp) = objfile_type (objfile)->builtin_void;
+ tp = init_pointer_type (objfile, 64, "adr_64",
+ objfile_type (objfile)->builtin_void);
break;
case btInt64:
- tp = init_type (TYPE_CODE_INT, 8, 0,
- "int", objfile);
+ tp = init_integer_type (objfile, 64, 0, "int");
break;
case btUInt64:
- tp = init_type (TYPE_CODE_INT, 8, TYPE_FLAG_UNSIGNED,
- "unsigned int", objfile);
+ tp = init_integer_type (objfile, 64, 1, "unsigned int");
break;
default:
static struct type *
parse_type (int fd, union aux_ext *ax, unsigned int aux_index, int *bs,
- int bigend, char *sym_name)
+ int bigend, const char *sym_name)
{
TIR t[1];
struct type *tp = 0;
name. This apparently is a MIPS extension for C sets. */
t->bt == btSet)
{
- char *name;
+ const char *name;
/* Try to cross reference this type, build new type on failure. */
ax += cross_ref (fd, ax, &tp, type_code, &name, bigend, sym_name);
if (tp == (struct type *) NULL)
- tp = init_type (type_code, 0, 0, (char *) NULL, mdebugread_objfile);
+ tp = init_type (mdebugread_objfile, type_code, 0, NULL);
/* DEC c89 produces cross references to qualified aggregate types,
dereference them. */
FIXME: We are not doing any guessing on range types. */
if (t->bt == btRange)
{
- char *name;
+ const char *name;
/* Try to cross reference this type, build new type on failure. */
ax += cross_ref (fd, ax, &tp, type_code, &name, bigend, sym_name);
if (tp == (struct type *) NULL)
- tp = init_type (type_code, 0, 0, (char *) NULL, mdebugread_objfile);
+ tp = init_type (mdebugread_objfile, type_code, 0, NULL);
/* Make sure that TYPE_CODE(tp) has an expected type code.
Any type may be returned from cross_ref if file indirect entries
}
if (t->bt == btTypedef)
{
- char *name;
+ const char *name;
/* Try to cross reference this type, it should succeed. */
ax += cross_ref (fd, ax, &tp, type_code, &name, bigend, sym_name);
static int
upgrade_type (int fd, struct type **tpp, int tq, union aux_ext *ax, int bigend,
- char *sym_name)
+ const char *sym_name)
{
int off;
struct type *t;
/* Reading .o files */
if (SC_IS_UNDEF (es->asym.sc) || es->asym.sc == scNil)
{
- char *what;
+ const char *what;
switch (es->asym.st)
{
case stNil:
belongs to, and then records this new minimal symbol. */
static void
-record_minimal_symbol (const char *name, const CORE_ADDR address,
+record_minimal_symbol (minimal_symbol_reader &reader,
+ const char *name, const CORE_ADDR address,
enum minimal_symbol_type ms_type, int storage_class,
struct objfile *objfile)
{
section = -1;
}
- prim_record_minimal_symbol_and_info (name, address, ms_type,
- section, objfile);
+ reader.record_with_info (name, address, ms_type, section);
}
/* Master parsing procedure for first-pass reading of file symbols
into a partial_symtab. */
static void
-parse_partial_symbols (struct objfile *objfile)
+parse_partial_symbols (minimal_symbol_reader &reader,
+ struct objfile *objfile)
{
struct gdbarch *gdbarch = get_objfile_arch (objfile);
const bfd_size_type external_sym_size = debug_swap->external_sym_size;
SYMR sh;
struct partial_symtab *pst;
int textlow_not_set = 1;
- int past_first_source_file = 0;
/* List of current psymtab's include files. */
const char **psymtab_include_list;
unknown_ext_complaint (name);
}
if (!ECOFF_IN_ELF (cur_bfd))
- record_minimal_symbol (name, svalue, ms_type, ext_in->asym.sc,
+ record_minimal_symbol (reader, name, svalue, ms_type, ext_in->asym.sc,
objfile);
}
pst = start_psymtab_common (objfile,
fdr_name (fh),
textlow,
- objfile->global_psymbols.next,
- objfile->static_psymbols.next);
+ objfile->global_psymbols,
+ objfile->static_psymbols);
pst->read_symtab_private = obstack_alloc (&objfile->objfile_obstack,
sizeof (struct symloc));
memset (pst->read_symtab_private, 0, sizeof (struct symloc));
if (sh.st == stStaticProc)
{
namestring = debug_info->ss + fh->issBase + sh.iss;
- record_minimal_symbol (namestring, sh.value,
+ record_minimal_symbol (reader, namestring, sh.value,
mst_file_text, sh.sc,
objfile);
}
case scPData:
case scXData:
namestring = debug_info->ss + fh->issBase + sh.iss;
- record_minimal_symbol (namestring, sh.value,
+ record_minimal_symbol (reader, namestring, sh.value,
mst_file_data, sh.sc,
objfile);
sh.value += ANOFFSET (objfile->section_offsets,
/* FIXME! Shouldn't this use cases for bss,
then have the default be abs? */
namestring = debug_info->ss + fh->issBase + sh.iss;
- record_minimal_symbol (namestring, sh.value,
+ record_minimal_symbol (reader, namestring, sh.value,
mst_file_bss, sh.sc,
objfile);
sh.value += ANOFFSET (objfile->section_offsets,
switch (type_code)
{
- char *p;
+ const char *p;
/* Standard, external, non-debugger, symbols. */
case N_SO:
{
- CORE_ADDR valu;
static int prev_so_symnum = -10;
- static int first_so_symnum;
const char *p;
- int prev_textlow_not_set;
-
- valu = sh.value + ANOFFSET (objfile->section_offsets,
- SECT_OFF_TEXT (objfile));
-
- prev_textlow_not_set = textlow_not_set;
/* A zero value is probably an indication for the
SunPRO 3.0 compiler. dbx_end_psymtab explicitly tests
if (sh.value == 0
&& gdbarch_sofun_address_maybe_missing (gdbarch))
- {
- textlow_not_set = 1;
- valu = 0;
- }
+ textlow_not_set = 1;
else
textlow_not_set = 0;
- past_first_source_file = 1;
-
if (prev_so_symnum != symnum - 1)
{ /* Here if prev stab wasn't N_SO. */
- first_so_symnum = symnum;
-
if (pst)
{
pst = (struct partial_symtab *) 0;
Accept either. */
while (*p && *p != ';' && *p != ',')
{
- char *q;
+ const char *q;
/* Check for and handle cretinous dbx
symbol name continuation! */
int new_sdx;
case stStaticProc:
- prim_record_minimal_symbol_and_info (name, minsym_value,
- mst_file_text,
- SECT_OFF_TEXT (objfile),
- objfile);
+ reader.record_with_info (name, minsym_value,
+ mst_file_text,
+ SECT_OFF_TEXT (objfile));
/* FALLTHROUGH */
case stStatic: /* Variable */
if (SC_IS_DATA (sh.sc))
- prim_record_minimal_symbol_and_info (name, minsym_value,
- mst_file_data,
- SECT_OFF_DATA (objfile),
- objfile);
+ reader.record_with_info (name, minsym_value,
+ mst_file_data,
+ SECT_OFF_DATA (objfile));
else
- prim_record_minimal_symbol_and_info (name, minsym_value,
- mst_file_bss,
- SECT_OFF_BSS (objfile),
- objfile);
+ reader.record_with_info (name, minsym_value,
+ mst_file_bss,
+ SECT_OFF_BSS (objfile));
theclass = LOC_STATIC;
break;
/* Get the next symbol. OBJFILE is unused. */
-static char *
+static const char *
mdebug_next_symbol_text (struct objfile *objfile)
{
SYMR sh;
if (ECOFF_IS_STAB (&sh) || (name[0] == '#'))
{
int type_code = ECOFF_UNMARK_STAB (sh.index);
+ enum language language = PST_PRIVATE (pst)->pst_language;
/* We should never get non N_STAB symbols here, but they
should be harmless, so keep process_one_symbol from
{
last_symtab_ended = 0;
process_one_symbol (type_code, 0, valu, name,
- section_offsets, objfile);
+ section_offsets, objfile, language);
}
}
/* Similarly a hack. */
else if (name[0] == '#')
{
process_one_symbol (N_SLINE, 0, valu, name,
- section_offsets, objfile);
+ section_offsets, objfile, language);
}
if (type_code == N_FUN)
{
cross_ref (int fd, union aux_ext *ax, struct type **tpp,
enum type_code type_code,
/* Use to alloc new type if none is found. */
- char **pname, int bigend, char *sym_name)
+ const char **pname, int bigend, const char *sym_name)
{
RNDXR rn[1];
unsigned int rf;
}
/* mips cc uses a rf of -1 for opaque struct definitions.
- Set TYPE_FLAG_STUB for these types so that check_typedef will
+ Set TYPE_STUB for these types so that check_typedef will
resolve them if the struct gets defined in another compilation unit. */
if (rf == -1)
{
*pname = "<undefined>";
- *tpp = init_type (type_code, 0, TYPE_FLAG_STUB,
- (char *) NULL, mdebugread_objfile);
+ *tpp = init_type (mdebugread_objfile, type_code, 0, NULL);
+ TYPE_STUB (*tpp) = 1;
return result;
}
switch (tir.bt)
{
case btVoid:
- *tpp = init_type (type_code, 0, 0, (char *) NULL,
- mdebugread_objfile);
+ *tpp = init_type (mdebugread_objfile, type_code, 0, NULL);
*pname = "<undefined>";
break;
complaint (&symfile_complaints,
_("illegal bt %d in forward typedef for %s"), tir.bt,
sym_name);
- *tpp = init_type (type_code, 0, 0, (char *) NULL,
- mdebugread_objfile);
+ *tpp = init_type (mdebugread_objfile, type_code, 0, NULL);
break;
}
return result;
has not been parsed yet.
Initialize the type only, it will be filled in when
it's definition is parsed. */
- *tpp = init_type (type_code, 0, 0, (char *) NULL, mdebugread_objfile);
+ *tpp = init_type (mdebugread_objfile, type_code, 0, NULL);
}
add_pending (fh, esh, *tpp);
}
keeping the symtab sorted. */
static struct symbol *
-mylookup_symbol (char *name, const struct block *block,
+mylookup_symbol (const char *name, const struct block *block,
domain_enum domain, enum address_class theclass)
{
struct block_iterator iter;
struct compunit_symtab *cust = allocate_compunit_symtab (objfile, name);
struct symtab *symtab;
struct blockvector *bv;
+ enum language lang;
add_compunit_symtab_to_objfile (cust);
symtab = allocate_symtab (cust, name);
SYMTAB_LINETABLE (symtab) = new_linetable (maxlines);
+ lang = compunit_language (cust);
/* All symtabs must have at least two blocks. */
bv = new_bvect (2);
- BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK) = new_block (NON_FUNCTION_BLOCK);
- BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK) = new_block (NON_FUNCTION_BLOCK);
+ BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK) = new_block (NON_FUNCTION_BLOCK, lang);
+ BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK) = new_block (NON_FUNCTION_BLOCK, lang);
BLOCK_SUPERBLOCK (BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK)) =
BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
COMPUNIT_BLOCKVECTOR (cust) = bv;
/* Allocate a new partial_symtab NAME. */
static struct partial_symtab *
-new_psymtab (char *name, struct objfile *objfile)
+new_psymtab (const char *name, struct objfile *objfile)
{
struct partial_symtab *psymtab;
return bv;
}
-/* Allocate and zero a new block, and set its BLOCK_DICT. If function
- is non-zero, assume the block is associated to a function, and make
- sure that the symbols are stored linearly; otherwise, store them
- hashed. */
+/* Allocate and zero a new block of language LANGUAGE, and set its
+ BLOCK_DICT. If function is non-zero, assume the block is
+ associated to a function, and make sure that the symbols are stored
+ linearly; otherwise, store them hashed. */
static struct block *
-new_block (enum block_type type)
+new_block (enum block_type type, enum language language)
{
/* FIXME: carlton/2003-09-11: This should use allocate_block to
allocate the block. Which, in turn, suggests that the block
struct block *retval = XCNEW (struct block);
if (type == FUNCTION_BLOCK)
- BLOCK_DICT (retval) = dict_create_linear_expandable ();
+ BLOCK_DICT (retval) = dict_create_linear_expandable (language);
else
- BLOCK_DICT (retval) = dict_create_hashed_expandable ();
+ BLOCK_DICT (retval) = dict_create_hashed_expandable (language);
return retval;
}
/* Create a new symbol with printname NAME. */
static struct symbol *
-new_symbol (char *name)
+new_symbol (const char *name)
{
struct symbol *s = allocate_symbol (mdebugread_objfile);
{
bfd *abfd = objfile->obfd;
struct ecoff_debug_info *info;
- struct cleanup *back_to;
/* FIXME: It's not clear whether we should be getting minimal symbol
information from .mdebug in an ELF file, or whether we will.
Re-initialize the minimal symbol reader in case we do. */
- init_minimal_symbol_collection ();
- back_to = make_cleanup_discard_minimal_symbols ();
+ minimal_symbol_reader reader (objfile);
info = ((struct ecoff_debug_info *)
obstack_alloc (&objfile->objfile_obstack,
error (_("Error reading ECOFF debugging information: %s"),
bfd_errmsg (bfd_get_error ()));
- mdebug_build_psymtabs (objfile, swap, info);
+ mdebug_build_psymtabs (reader, objfile, swap, info);
- install_minimal_symbols (objfile);
- do_cleanups (back_to);
+ reader.install ();
}
void