/* Read coff symbol tables and convert to internal format, for GDB.
- Copyright (C) 1987-2005, 2007-2012 Free Software Foundation, Inc.
+ Copyright (C) 1987-2013 Free Software Foundation, Inc.
Contributed by David D. Johnson, Brown University (ddj@cs.brown.edu).
This file is part of GDB.
extern void _initialize_coffread (void);
+/* Key for COFF-associated data. */
+
+static const struct objfile_data *coff_objfile_data_key;
+
/* The objfile we are currently reading. */
static struct objfile *coffread_objfile;
static void
complete_symtab (const char *name, CORE_ADDR start_addr, unsigned int size)
{
- if (last_source_file != NULL)
- xfree (last_source_file);
- last_source_file = xstrdup (name);
+ set_last_source_file (name);
current_source_start_addr = start_addr;
current_source_end_addr = start_addr + size;
}
SECT_OFF_TEXT (objfile));
/* Reinitialize for beginning of new file. */
- last_source_file = NULL;
+ set_last_source_file (NULL);
}
\f
static struct minimal_symbol *
coff_symfile_init (struct objfile *objfile)
{
struct dbx_symfile_info *dbx;
+ struct coff_symfile_info *coff;
/* Allocate struct to keep track of stab reading. */
dbx = XCNEW (struct dbx_symfile_info);
set_objfile_data (objfile, dbx_objfile_data_key, dbx);
/* Allocate struct to keep track of the symfile. */
- objfile->deprecated_sym_private
- = xmalloc (sizeof (struct coff_symfile_info));
-
- memset (objfile->deprecated_sym_private, 0,
- sizeof (struct coff_symfile_info));
+ coff = XCNEW (struct coff_symfile_info);
+ set_objfile_data (objfile, coff_objfile_data_key, coff);
/* COFF objects may be reordered, so set OBJF_REORDERED. If we
find this causes a significant slowdown in gdb then we could
set it in the debug symbol readers only when necessary. */
objfile->flags |= OBJF_REORDERED;
-
- init_entry_point_info (objfile);
}
/* This function is called for every section; it finds the outer
struct cleanup *back_to, *cleanup_minimal_symbols;
int stabstrsize;
- info = (struct coff_symfile_info *) objfile->deprecated_sym_private;
+ info = objfile_data (objfile, coff_objfile_data_key);
dbxinfo = DBX_SYMFILE_INFO (objfile);
symfile_bfd = abfd; /* Kludge for swap routines. */
static void
coff_symfile_finish (struct objfile *objfile)
{
- if (objfile->deprecated_sym_private != NULL)
- {
- xfree (objfile->deprecated_sym_private);
- }
-
/* Let stabs reader clean up. */
stabsread_clear_cache ();
coffread_objfile = objfile;
nlist_bfd_global = objfile->obfd;
nlist_nsyms_global = nsyms;
- last_source_file = NULL;
+ set_last_source_file (NULL);
memset (opaque_type_chain, 0, sizeof opaque_type_chain);
if (type_vector) /* Get rid of previous one. */
if (cs->c_symnum == next_file_symnum && cs->c_sclass != C_FILE)
{
- if (last_source_file)
+ if (get_last_source_file ())
coff_end_symtab (objfile);
coff_start_symtab ("_globals_");
/* Special case for file with type declarations only, no
text. */
- if (!last_source_file && SDB_TYPE (cs->c_type)
+ if (!get_last_source_file () && SDB_TYPE (cs->c_type)
&& cs->c_secnum == N_DEBUG)
complete_symtab (filestring, 0, 0);
/* Complete symbol table for last object file
containing debugging information. */
- if (last_source_file)
+ if (get_last_source_file ())
{
coff_end_symtab (objfile);
coff_start_symtab (filestring);
read_pe_exported_syms (objfile);
}
- if (last_source_file)
+ if (get_last_source_file ())
coff_end_symtab (objfile);
/* Patch up any opaque types (references to types that are not defined
list = new;
/* Save the data. */
- list->field.name = obsavestring (name, strlen (name),
- &objfile->objfile_obstack);
+ list->field.name = obstack_copy0 (&objfile->objfile_obstack,
+ name, strlen (name));
FIELD_TYPE (list->field) = decode_type (ms, ms->c_type,
&sub_aux, objfile);
SET_FIELD_BITPOS (list->field, 8 * ms->c_value);
list = new;
/* Save the data. */
- list->field.name = obsavestring (name, strlen (name),
- &objfile->objfile_obstack);
+ list->field.name = obstack_copy0 (&objfile->objfile_obstack,
+ name, strlen (name));
FIELD_TYPE (list->field) = decode_type (ms, ms->c_type,
&sub_aux, objfile);
SET_FIELD_BITPOS (list->field, ms->c_value);
memset (sym, 0, sizeof (struct symbol));
SYMBOL_SET_LINKAGE_NAME (sym,
- obsavestring (name, strlen (name),
- &objfile->objfile_obstack));
+ obstack_copy0 (&objfile->objfile_obstack,
+ name, strlen (name)));
SYMBOL_CLASS (sym) = LOC_CONST;
SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
SYMBOL_VALUE (sym) = ms->c_value;
&psym_functions
};
+/* Free the per-objfile COFF data. */
+
+static void
+coff_free_info (struct objfile *objfile, void *arg)
+{
+ xfree (arg);
+}
+
void
_initialize_coffread (void)
{
add_symtab_fns (&coff_sym_fns);
+
+ coff_objfile_data_key = register_objfile_data_with_cleanup (NULL,
+ coff_free_info);
}