/* Read coff symbol tables and convert to internal format, for GDB.
- Copyright (C) 1987-2018 Free Software Foundation, Inc.
+ Copyright (C) 1987-2019 Free Software Foundation, Inc.
Contributed by David D. Johnson, Brown University (ddj@cs.brown.edu).
This file is part of GDB.
#include "coff/internal.h" /* Internal format of COFF symbols in BFD */
#include "libcoff.h" /* FIXME secret internal data from BFD */
#include "objfiles.h"
-#include "buildsym.h"
+#include "buildsym-legacy.h"
#include "gdb-stabs.h"
#include "stabsread.h"
#include "complaints.h"
static void
coff_start_symtab (struct objfile *objfile, const char *name)
{
+ within_function = 0;
start_symtab (objfile,
/* We fill in the filename later. start_symtab puts this pointer
into last_source_file and we put it in subfiles->name, which
xstrdup (name),
/* We never know the directory name for COFF. */
NULL,
- /* The start address is irrelevant, since we set
- last_source_start_addr in coff_end_symtab. */
+ /* The start address is irrelevant, since we call
+ set_last_source_start_addr in coff_end_symtab. */
0,
/* Let buildsym.c deduce the language for this symtab. */
language_unknown);
static void
coff_end_symtab (struct objfile *objfile)
{
- last_source_start_addr = current_source_start_addr;
+ set_last_source_start_addr (current_source_start_addr);
end_symtab (current_source_end_addr, SECT_OFF_TEXT (objfile));
struct coff_symfile_info *info;
bfd *abfd = objfile->obfd;
coff_data_type *cdata = coff_data (abfd);
- char *name = bfd_get_filename (abfd);
+ char *filename = bfd_get_filename (abfd);
int val;
unsigned int num_symbols;
int symtab_offset;
val = init_lineno (abfd, info->min_lineno_offset,
info->max_lineno_offset - info->min_lineno_offset);
if (val < 0)
- error (_("\"%s\": error reading line numbers."), name);
+ error (_("\"%s\": error reading line numbers."), filename);
}
/* Now read the string table, all at once. */
make_cleanup (free_stringtab_cleanup, 0 /*ignore*/);
val = init_stringtab (abfd, stringtab_offset);
if (val < 0)
- error (_("\"%s\": can't get string table"), name);
+ error (_("\"%s\": can't get string table"), filename);
minimal_symbol_reader reader (objfile);
if (pe_file)
{
- struct minimal_symbol *msym;
-
- ALL_OBJFILE_MSYMBOLS (objfile, msym)
+ for (minimal_symbol *msym : objfile_msymbols (objfile))
{
const char *name = MSYMBOL_LINKAGE_NAME (msym);
{
error (_("The debugging information in `%s' is corrupted.\nThe "
"file has a `.stabs' section, but no `.stabstr' section."),
- name);
+ filename);
}
/* FIXME: dubious. Why can't we use something normal like
if (!debugfile.empty ())
{
- gdb_bfd_ref_ptr abfd (symfile_bfd_open (debugfile.c_str ()));
+ gdb_bfd_ref_ptr debug_bfd (symfile_bfd_open (debugfile.c_str ()));
- symbol_file_add_separate (abfd.get (), debugfile.c_str (),
+ symbol_file_add_separate (debug_bfd.get (), debugfile.c_str (),
symfile_flags, objfile);
}
}
struct objfile *objfile)
{
struct gdbarch *gdbarch = get_objfile_arch (objfile);
- struct context_stack *newobj;
+ struct context_stack *newobj = nullptr;
struct coff_symbol coff_symbol;
struct coff_symbol *cs = &coff_symbol;
static struct internal_syment main_sym;
CORE_ADDR tmpaddr;
struct minimal_symbol *msym;
+ scoped_free_pendings free_pending;
+
/* Work around a stdio bug in SunOS4.1.1 (this makes me nervous....
it's hard to know I've really worked around it. The fix should
be harmless, anyway). The symptom of the bug is that the first
language_unknown, since such a ``file name'' is not
recognized. Override that with the minimal language to
allow printing values in this symtab. */
- current_subfile->language = language_minimal;
+ get_current_subfile ()->language = language_minimal;
complete_symtab ("_globals_", 0, 0);
/* Done with all files, everything from here on out is
globals. */
int section = cs_to_section (cs, objfile);
tmpaddr = cs->c_value;
- record_minimal_symbol (reader, cs, tmpaddr, mst_text,
- section, objfile);
+ /* Don't record unresolved symbols. */
+ if (!(cs->c_secnum <= 0 && cs->c_value == 0))
+ record_minimal_symbol (reader, cs, tmpaddr, mst_text,
+ section, objfile);
fcn_line_ptr = main_aux.x_sym.x_fcnary.x_fcn.x_lnnoptr;
fcn_start_addr = tmpaddr;
/* { main_aux.x_sym.x_misc.x_lnsz.x_lnno
contains number of lines to '}' */
- if (context_stack_depth <= 0)
+ if (outermost_context_p ())
{ /* We attempted to pop an empty context stack. */
complaint (_("`.ef' symbol without matching `.bf' "
"symbol ignored starting at symnum %d"),
break;
}
- newobj = pop_context ();
+ struct context_stack cstk = pop_context ();
/* Stack must be empty now. */
- if (context_stack_depth > 0 || newobj == NULL)
+ if (!outermost_context_p () || newobj == NULL)
{
complaint (_("Unmatched .ef symbol(s) ignored "
"starting at symnum %d"),
of the closing '}', and for which we do not have any
other statement-line-number. */
if (fcn_last_line == 1)
- record_line (current_subfile, fcn_first_line,
+ record_line (get_current_subfile (), fcn_first_line,
gdbarch_addr_bits_remove (gdbarch,
fcn_first_line_addr));
else
enter_linenos (fcn_line_ptr, fcn_first_line,
fcn_last_line, objfile);
- finish_block (newobj->name, &local_symbols, newobj->old_blocks,
- NULL, newobj->start_addr,
+ finish_block (cstk.name, cstk.old_blocks,
+ NULL, cstk.start_addr,
fcn_cs_saved.c_value
+ fcn_aux_saved.x_sym.x_misc.x_fsize
+ ANOFFSET (objfile->section_offsets,
}
else if (strcmp (cs->c_name, ".eb") == 0)
{
- if (context_stack_depth <= 0)
+ if (outermost_context_p ())
{ /* We attempted to pop an empty context stack. */
complaint (_("`.eb' symbol without matching `.bb' "
"symbol ignored starting at symnum %d"),
break;
}
- newobj = pop_context ();
- if (depth-- != newobj->depth)
+ struct context_stack cstk = pop_context ();
+ if (depth-- != cstk.depth)
{
complaint (_("Mismatched .eb symbol ignored "
"starting at symnum %d"),
symnum);
break;
}
- if (local_symbols && context_stack_depth > 0)
+ if (*get_local_symbols () && !outermost_context_p ())
{
tmpaddr =
cs->c_value + ANOFFSET (objfile->section_offsets,
SECT_OFF_TEXT (objfile));
/* Make a block for the local symbols within. */
- finish_block (0, &local_symbols, newobj->old_blocks, NULL,
- newobj->start_addr, tmpaddr);
+ finish_block (0, cstk.old_blocks, NULL,
+ cstk.start_addr, tmpaddr);
}
/* Now pop locals of block just finished. */
- local_symbols = newobj->locals;
+ *get_local_symbols () = cstk.locals;
}
break;
/* Patch up any opaque types (references to types that are not defined
in the file where they are referenced, e.g. "struct foo *bar"). */
{
- struct compunit_symtab *cu;
- struct symtab *s;
-
- ALL_OBJFILE_FILETABS (objfile, cu, s)
- patch_opaque_types (s);
+ for (compunit_symtab *cu : objfile_compunits (objfile))
+ {
+ for (symtab *s : compunit_filetabs (cu))
+ patch_opaque_types (s);
+ }
}
coffread_objfile = NULL;
CORE_ADDR addr = lptr.l_addr.l_paddr;
addr += ANOFFSET (objfile->section_offsets,
SECT_OFF_TEXT (objfile));
- record_line (current_subfile,
+ record_line (get_current_subfile (),
first_line + L_LNNO32 (&lptr),
gdbarch_addr_bits_remove (gdbarch, addr));
}
name = cs->c_name;
name = EXTERNAL_NAME (name, objfile->obfd);
- SYMBOL_SET_LANGUAGE (sym, current_subfile->language,
+ SYMBOL_SET_LANGUAGE (sym, get_current_subfile ()->language,
&objfile->objfile_obstack);
SYMBOL_SET_NAMES (sym, name, strlen (name), 1, objfile);
SYMBOL_ACLASS_INDEX (sym) = LOC_BLOCK;
if (cs->c_sclass == C_STAT || cs->c_sclass == C_THUMBSTAT
|| cs->c_sclass == C_THUMBSTATFUNC)
- add_symbol_to_list (sym, &file_symbols);
+ add_symbol_to_list (sym, get_file_symbols ());
else if (cs->c_sclass == C_EXT || cs->c_sclass == C_THUMBEXT
|| cs->c_sclass == C_THUMBEXTFUNC)
- add_symbol_to_list (sym, &global_symbols);
+ add_symbol_to_list (sym, get_global_symbols ());
}
else
{
case C_AUTO:
SYMBOL_ACLASS_INDEX (sym) = LOC_LOCAL;
- add_symbol_to_list (sym, &local_symbols);
+ add_symbol_to_list (sym, get_local_symbols ());
break;
case C_THUMBEXT:
SYMBOL_VALUE_ADDRESS (sym) = (CORE_ADDR) cs->c_value;
SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (objfile->section_offsets,
SECT_OFF_TEXT (objfile));
- add_symbol_to_list (sym, &global_symbols);
+ add_symbol_to_list (sym, get_global_symbols ());
break;
case C_THUMBSTAT:
if (within_function)
{
/* Static symbol of local scope. */
- add_symbol_to_list (sym, &local_symbols);
+ add_symbol_to_list (sym, get_local_symbols ());
}
else
{
/* Static symbol at top level of file. */
- add_symbol_to_list (sym, &file_symbols);
+ add_symbol_to_list (sym, get_file_symbols ());
}
break;
case C_REG:
SYMBOL_ACLASS_INDEX (sym) = coff_register_index;
SYMBOL_VALUE (sym) = cs->c_value;
- add_symbol_to_list (sym, &local_symbols);
+ add_symbol_to_list (sym, get_local_symbols ());
break;
case C_THUMBLABEL:
case C_ARG:
SYMBOL_ACLASS_INDEX (sym) = LOC_ARG;
SYMBOL_IS_ARGUMENT (sym) = 1;
- add_symbol_to_list (sym, &local_symbols);
+ add_symbol_to_list (sym, get_local_symbols ());
break;
case C_REGPARM:
SYMBOL_ACLASS_INDEX (sym) = coff_register_index;
SYMBOL_IS_ARGUMENT (sym) = 1;
SYMBOL_VALUE (sym) = cs->c_value;
- add_symbol_to_list (sym, &local_symbols);
+ add_symbol_to_list (sym, get_local_symbols ());
break;
case C_TPDEF:
SYMBOL_VALUE_CHAIN (sym) = opaque_type_chain[i];
opaque_type_chain[i] = sym;
}
- add_symbol_to_list (sym, &file_symbols);
+ add_symbol_to_list (sym, get_file_symbols ());
break;
case C_STRTAG:
TYPE_NAME (SYMBOL_TYPE (sym)) =
concat (SYMBOL_LINKAGE_NAME (sym), (char *)NULL);
- add_symbol_to_list (sym, &file_symbols);
+ add_symbol_to_list (sym, get_file_symbols ());
break;
default:
type = coff_alloc_type (index);
if (within_function)
- symlist = &local_symbols;
+ symlist = get_local_symbols ();
else
- symlist = &file_symbols;
+ symlist = get_file_symbols ();
osyms = *symlist;
o_nsyms = osyms ? osyms->nsyms : 0;