+Thu Mar 19 13:54:11 1992 Fred Fish (fnf@cygnus.com)
+
+ * coffread.c, mipsread.c, xcoffread.c, coffread.c, dbxread.c,
+ elfread.c (coff_symfile_finish): Add function, prototype, and
+ add to the xxxx_sym_fns struct for each file type. Also reformat
+ the xxxx_sym_fns vector to a standard format and add comments.
+ * coffread.c, mipsread.c, xcoffread.c, coffread.c, dbxread.c,
+ elfread.c (xxx_symfile_new_init, xxx_symfile_init, xxx_symfile_read):
+ Pass pointer to struct objfile rather than pointer to sym_fns.
+ Change references inside each function accordingly. Allocate any
+ symbol file specific info in the per-objfile memory region.
+ * dbxread.c (free_and_init_header_files): Break function into
+ free_header_files(), called from dbx_symfile_finish(), and
+ init_header_files(), called from dbx_new_init().
+ * dbxread.c (dbx_new_init): Move deallocation things to new
+ dbx_symfile_finish function.
+ * elfread.c (elf_new_init): Call buildsym_new_init().
+ * objfiles.c (free_objfile): Call the appropriate symfile_finish()
+ routine for the objfile before deallocating other stuff.
+ * sparc-tdep.c (get_longjmp_target): Cast target_read_memory arg.
+ * symfile.h: Move struct sym_fns to before struct objfile def.
+ Add sym_finish function pointer and change prototypes of other
+ function pointers to reflect passing struct objfile pointer rather
+ than struct sym_fns pointer.
+ * symfile.c: Remove now obsolete symtab_fns pointer.
+ * symfile.c (symfile_init): Renamed to find_sym_fns, and now only
+ locates the correct sym_fns struct for the given objfile.
+ * symfile.c (syms_from_objfile, symbol_file_add): Restructured
+ for better support of mapped symbol tables.
+ * symfile.c (symbol_file_command): Remove obsolete code using
+ symfile_fns.
+ * symfile.h: Remove duplicate declarations for symfile_objfile,
+ entry_point, and object_files.
+ * target.c (target_info): Compare symfile_objfile to NULL.
+ * xcoffread.c (aixcoff_new_init): Move deallocation stuff to
+ aixcoff_symfile_finish().
+
Wed Mar 18 18:22:46 1992 Fred Fish (fnf@cygnus.com)
* infrun.c (IN_SOLIB_TRAMPOLINE): Add default definition.
read_coff_symtab PARAMS ((int, int, struct objfile *));
static void
-coff_new_init PARAMS ((void));
+find_linenos PARAMS ((bfd *, sec_ptr, PTR));
static void
-coff_symfile_read PARAMS ((struct sym_fns *, CORE_ADDR, int));
+coff_symfile_init PARAMS ((struct objfile *));
static void
-find_linenos PARAMS ((bfd *, sec_ptr, PTR));
+coff_new_init PARAMS ((struct objfile *));
static void
-coff_symfile_init PARAMS ((struct sym_fns *));
+coff_symfile_read PARAMS ((struct objfile *, CORE_ADDR, int));
+
+static void
+coff_symfile_finish PARAMS ((struct objfile *));
static void
record_minimal_symbol PARAMS ((char *, CORE_ADDR));
static int text_bfd_scnum;
static void
-coff_symfile_init (sf)
- struct sym_fns *sf;
+coff_symfile_init (objfile)
+ struct objfile *objfile;
{
asection *section;
- bfd *abfd = sf->sym_bfd;
+ bfd *abfd = objfile->obfd;
/* Allocate struct to keep track of the symfile */
- /* FIXME memory leak */
- sf->sym_private = xmalloc (sizeof (struct coff_symfile_info));
+ objfile -> sym_private = xmmalloc (objfile -> md,
+ sizeof (struct coff_symfile_info));
/* Save startup file's range of PC addresses to help blockframe.c
decide where the bottom of the stack is. */
/* ARGSUSED */
static void
-coff_symfile_read (sf, addr, mainline)
- struct sym_fns *sf;
+coff_symfile_read (objfile, addr, mainline)
+ struct objfile *objfile;
CORE_ADDR addr;
int mainline;
{
- struct coff_symfile_info *info = (struct coff_symfile_info *)sf->sym_private;
- bfd *abfd = sf->objfile->obfd;
+ struct coff_symfile_info *info;
+ bfd *abfd = objfile->obfd;
coff_data_type *cdata = coff_data (abfd);
char *name = bfd_get_filename (abfd);
int desc;
int symtab_offset;
int stringtab_offset;
+ info = (struct coff_symfile_info *) objfile -> sym_private;
symfile_bfd = abfd; /* Kludge for swap routines */
/* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
/* Now that the executable file is positioned at symbol table,
process it and define symbols accordingly. */
- read_coff_symtab (desc, num_symbols, sf->objfile);
+ read_coff_symtab (desc, num_symbols, objfile);
iterate_over_symtabs (patch_opaque_types, (PTR) NULL, (PTR) NULL,
(PTR) NULL);
/* Install any minimal symbols that have been collected as the current
minimal symbols for this objfile. */
- install_minimal_symbols (sf -> objfile);
+ install_minimal_symbols (objfile);
}
static void
-coff_new_init ()
+coff_new_init (objfile)
+ struct objfile *objfile;
{
/* Nothin' to do */
}
+
+/* Perform any local cleanups required when we are done with a particular
+ objfile. I.E, we are in the process of discarding all symbol information
+ for an objfile, freeing up all memory held for it, and unlinking the
+ objfile struct from the global list of known objfiles. */
+
+static void
+coff_symfile_finish (objfile)
+ struct objfile *objfile;
+{
+ if (objfile -> sym_private != NULL)
+ {
+ mfree (objfile -> md, objfile -> sym_private);
+ }
+}
+
\f
/* Given pointers to a symbol table in coff style exec file,
analyze them and create struct symtab's describing the symbols.
static struct sym_fns coff_sym_fns =
{
- "coff", 4,
- coff_new_init, coff_symfile_init, coff_symfile_read,
+ "coff", /* sym_name: name or name prefix of BFD target type */
+ 4, /* sym_namelen: number of significant sym_name chars */
+ coff_new_init, /* sym_new_init: init anything gbl to entire symtab */
+ coff_symfile_init, /* sym_init: read initial info, setup for sym_read() */
+ coff_symfile_read, /* sym_read: read a symbol file into symtab */
+ coff_symfile_finish, /* sym_finish: finished with file, cleanup */
+ NULL /* next: pointer to next struct sym_fns */
};
void
/* Information is passed among various dbxread routines for accessing
symbol files. A pointer to this structure is kept in the sym_private
- field of the struct sym_fns passed in by symfile.h. */
+ field of the objfile struct passed in by symfile.h. */
struct dbx_symfile_info {
asection *text_sect; /* Text section accessor */
/* Local function prototypes */
static void
-free_and_init_header_files PARAMS ((void));
+free_header_files PARAMS ((void));
+
+static void
+init_header_files PARAMS ((void));
static struct pending *
copy_pending PARAMS ((struct pending *, int, struct pending *));
fill_symbuf PARAMS ((bfd *));
static void
-dbx_symfile_init PARAMS ((struct sym_fns *));
+dbx_symfile_init PARAMS ((struct objfile *));
+
+static void
+dbx_new_init PARAMS ((struct objfile *));
static void
-dbx_new_init PARAMS ((void));
+dbx_symfile_read PARAMS ((struct objfile *, CORE_ADDR, int));
static void
-dbx_symfile_read PARAMS ((struct sym_fns *, CORE_ADDR, int));
+dbx_symfile_finish PARAMS ((struct objfile *));
static void
record_minimal_symbol PARAMS ((char *, CORE_ADDR, int, struct objfile *));
static void
add_this_object_header_file PARAMS ((int));
-/* Free up old header file tables, and allocate new ones.
- We're reading a new symbol file now. */
+/* Free up old header file tables */
static void
-free_and_init_header_files ()
+free_header_files ()
{
register int i;
- for (i = 0; i < n_header_files; i++)
- free (header_files[i].name);
- if (header_files) /* First time null */
- free (header_files);
- if (this_object_header_files) /* First time null */
- free (this_object_header_files);
- n_allocated_header_files = 10;
- header_files = (struct header_file *) xmalloc (10 * sizeof (struct header_file));
+ if (header_files != NULL)
+ {
+ for (i = 0; i < n_header_files; i++)
+ {
+ free (header_files[i].name);
+ }
+ free (header_files);
+ header_files = NULL;
+ n_header_files = 0;
+ }
+ if (this_object_header_files)
+ {
+ free (this_object_header_files);
+ this_object_header_files = NULL;
+ }
+ n_allocated_header_files = 0;
+ n_allocated_this_object_header_files = 0;
+}
+
+/* Allocate new header file tables */
+
+static void
+init_header_files ()
+{
n_header_files = 0;
+ n_allocated_header_files = 10;
+ header_files = (struct header_file *)
+ xmalloc (10 * sizeof (struct header_file));
n_allocated_this_object_header_files = 10;
this_object_header_files = (int *) xmalloc (10 * sizeof (int));
table (as opposed to a shared lib or dynamically loaded file). */
static void
-dbx_symfile_read (sf, addr, mainline)
- struct sym_fns *sf;
+dbx_symfile_read (objfile, addr, mainline)
+ struct objfile *objfile;
CORE_ADDR addr;
int mainline; /* FIXME comments above */
{
- struct dbx_symfile_info *info = (struct dbx_symfile_info *) (sf->sym_private);
- bfd *sym_bfd = sf->objfile->obfd;
+ struct dbx_symfile_info *info;
+ bfd *sym_bfd;
int val;
- val = bfd_seek (sf->objfile->obfd, info->symtab_offset, L_SET);
+ sym_bfd = objfile->obfd;
+ info = (struct dbx_symfile_info *) (objfile -> sym_private);
+ val = bfd_seek (objfile->obfd, info->symtab_offset, L_SET);
if (val < 0)
- perror_with_name (sf->objfile->name);
+ perror_with_name (objfile->name);
/* If mainline, set global string table pointers, and reinitialize global
partial symbol list. */
}
/* If we are reinitializing, or if we have never loaded syms yet, init */
- if (mainline || sf->objfile->global_psymbols.size == 0 || sf->objfile->static_psymbols.size == 0)
- init_psymbol_list (info->symcount, sf->objfile);
+ if (mainline || objfile->global_psymbols.size == 0 || objfile->static_psymbols.size == 0)
+ init_psymbol_list (info->symcount, objfile);
/* FIXME POKING INSIDE BFD DATA STRUCTURES */
symbol_size = obj_symbol_entry_size (sym_bfd);
process them and define symbols accordingly. */
read_dbx_symtab (addr - bfd_section_vma (sym_bfd, info->text_sect), /*offset*/
- sf->objfile, info->stringtab, info->stringtab_size,
+ objfile, info->stringtab, info->stringtab_size,
info->symcount,
bfd_section_vma (sym_bfd, info->text_sect),
bfd_section_size (sym_bfd, info->text_sect));
/* Install any minimal symbols that have been collected as the current
minimal symbols for this objfile. */
- install_minimal_symbols (sf -> objfile);
+ install_minimal_symbols (objfile);
/* Free up any memory we allocated for ourselves. */
if (!mainline) {
- mfree (sf->objfile->md, info->stringtab); /* Stringtab is only saved for mainline */
+ mfree (objfile->md, info->stringtab); /* Stringtab is only saved for mainline */
}
- mfree (sf->objfile->md, info);
- sf->sym_private = NULL; /* Zap pointer to our (now gone) info struct */
-
+ mfree (objfile->md, info);
+ /* Zap pointer to our (now gone) info struct */
+ objfile -> sym_private = NULL;
if (!have_partial_symbols ()) {
wrap_here ("");
printf_filtered ("(no debugging symbols found)...");
file, e.g. a shared library). */
static void
-dbx_new_init ()
+dbx_new_init (objfile)
+ struct objfile *objfile;
{
buildsym_new_init ();
-
- /* Don't put these on the cleanup chain; they need to stick around
- until the next call to dbx_new_init. *Then* we'll free them. */
- if (symfile_string_table)
- {
- free (symfile_string_table);
- symfile_string_table = 0;
- symfile_string_table_size = 0;
- }
- free_and_init_header_files ();
+ init_header_files ();
}
/* dbx_symfile_init ()
is the dbx-specific initialization routine for reading symbols.
- It is passed a struct sym_fns which contains, among other things,
+ It is passed a struct objfile which contains, among other things,
the BFD for the file whose symbols are being read, and a slot for a pointer
to "private data" which we fill with goodies.
FIXME, there should be a cleaner peephole into the BFD environment here. */
static void
-dbx_symfile_init (sf)
- struct sym_fns *sf;
+dbx_symfile_init (objfile)
+ struct objfile *objfile;
{
int val;
- bfd *sym_bfd = sf->objfile->obfd;
+ bfd *sym_bfd = objfile->obfd;
char *name = bfd_get_filename (sym_bfd);
struct dbx_symfile_info *info;
unsigned char size_temp[4];
/* Allocate struct to keep track of the symfile */
- sf->sym_private = xmmalloc (sf->objfile->md, sizeof (*info));
- info = (struct dbx_symfile_info *)sf->sym_private;
+ objfile-> sym_private = xmmalloc (objfile -> md, sizeof (*info));
+ info = (struct dbx_symfile_info *) objfile -> sym_private;
/* FIXME POKING INSIDE BFD DATA STRUCTURES */
#define STRING_TABLE_OFFSET (sym_bfd->origin + obj_str_filepos (sym_bfd))
if (info->stringtab_size >= 0)
{
/* Yes, this should be malloc, not xmalloc. We check its result. */
- info->stringtab = (char *) mmalloc (sf->objfile->md, info->stringtab_size);
+ info->stringtab = (char *) mmalloc (objfile->md, info->stringtab_size);
/* Caller is responsible for freeing the string table. No cleanup. */
}
else
info->symtab_offset = SYMBOL_TABLE_OFFSET;
}
+
+/* Perform any local cleanups required when we are done with a particular
+ objfile. I.E, we are in the process of discarding all symbol information
+ for an objfile, freeing up all memory held for it, and unlinking the
+ objfile struct from the global list of known objfiles. */
+
+static void
+dbx_symfile_finish (objfile)
+ struct objfile *objfile;
+{
+ if (objfile -> sym_private != NULL)
+ {
+ mfree (objfile -> md, objfile -> sym_private);
+ }
+ if (symfile_string_table)
+ {
+ free (symfile_string_table);
+ symfile_string_table = 0;
+ symfile_string_table_size = 0;
+ }
+ free_header_files ();
+}
+
\f
/* Buffer for reading the symbol table entries. */
static struct internal_nlist symbuf[4096];
\f
/* Register our willingness to decode symbols for SunOS and a.out and
b.out files handled by BFD... */
-static struct sym_fns sunos_sym_fns = {"sunOs", 6,
- dbx_new_init, dbx_symfile_init, dbx_symfile_read};
+static struct sym_fns sunos_sym_fns =
+{
+ "sunOs", /* sym_name: name or name prefix of BFD target type */
+ 6, /* sym_namelen: number of significant sym_name chars */
+ dbx_new_init, /* sym_new_init: init anything gbl to entire symtab */
+ dbx_symfile_init, /* sym_init: read initial info, setup for sym_read() */
+ dbx_symfile_read, /* sym_read: read a symbol file into symtab */
+ dbx_symfile_finish, /* sym_finish: finished with file, cleanup */
+ NULL /* next: pointer to next struct sym_fns */
+};
-static struct sym_fns aout_sym_fns = {"a.out", 5,
- dbx_new_init, dbx_symfile_init, dbx_symfile_read};
+static struct sym_fns aout_sym_fns =
+{
+ "a.out", /* sym_name: name or name prefix of BFD target type */
+ 5, /* sym_namelen: number of significant sym_name chars */
+ dbx_new_init, /* sym_new_init: init anything gbl to entire symtab */
+ dbx_symfile_init, /* sym_init: read initial info, setup for sym_read() */
+ dbx_symfile_read, /* sym_read: read a symbol file into symtab */
+ dbx_symfile_finish, /* sym_finish: finished with file, cleanup */
+ NULL /* next: pointer to next struct sym_fns */
+};
-static struct sym_fns bout_sym_fns = {"b.out", 5,
- dbx_new_init, dbx_symfile_init, dbx_symfile_read};
+static struct sym_fns bout_sym_fns =
+{
+ "b.out", /* sym_name: name or name prefix of BFD target type */
+ 5, /* sym_namelen: number of significant sym_name chars */
+ dbx_new_init, /* sym_new_init: init anything gbl to entire symtab */
+ dbx_symfile_init, /* sym_init: read initial info, setup for sym_read() */
+ dbx_symfile_read, /* sym_read: read a symbol file into symtab */
+ dbx_symfile_finish, /* sym_finish: finished with file, cleanup */
+ NULL /* next: pointer to next struct sym_fns */
+};
void
_initialize_dbxread ()
};
static void
-elf_symfile_init PARAMS ((struct sym_fns *));
+elf_symfile_init PARAMS ((struct objfile *));
static void
-elf_new_init PARAMS ((void));
+elf_new_init PARAMS ((struct objfile *));
static void
-elf_symfile_read PARAMS ((struct sym_fns *, CORE_ADDR, int));
+elf_symfile_read PARAMS ((struct objfile *, CORE_ADDR, int));
+
+static void
+elf_symfile_finish PARAMS ((struct objfile *));
static void
elf_symtab_read PARAMS ((bfd *, CORE_ADDR, int, struct objfile *));
*/
static void
-elf_symfile_read (sf, addr, mainline)
- struct sym_fns *sf;
+elf_symfile_read (objfile, addr, mainline)
+ struct objfile *objfile;
CORE_ADDR addr;
int mainline;
{
- bfd *abfd = sf->objfile->obfd;
+ bfd *abfd = objfile->obfd;
struct elfinfo ei;
struct cleanup *back_to;
/* Process the normal ELF symbol table first. */
- elf_symtab_read (abfd, addr, mainline, sf->objfile);
+ elf_symtab_read (abfd, addr, mainline, objfile);
/* Now process the DWARF debugging information, which is contained in
special ELF sections. We first have to find them... */
bfd_get_filename (abfd),
addr, mainline,
ei.dboffset, ei.dbsize,
- ei.lnoffset, ei.lnsize, sf->objfile);
+ ei.lnoffset, ei.lnsize, objfile);
}
if (!have_partial_symbols ())
/* Install any minimal symbols that have been collected as the current
minimal symbols for this objfile. */
- install_minimal_symbols (sf -> objfile);
+ install_minimal_symbols (objfile);
do_cleanups (back_to);
}
just a stub. */
static void
-elf_new_init ()
+elf_new_init (objfile)
+ struct objfile *objfile;
+{
+ buildsym_new_init ();
+}
+
+/* Perform any local cleanups required when we are done with a particular
+ objfile. I.E, we are in the process of discarding all symbol information
+ for an objfile, freeing up all memory held for it, and unlinking the
+ objfile struct from the global list of known objfiles. */
+
+static void
+elf_symfile_finish (objfile)
+ struct objfile *objfile;
{
+ if (objfile -> sym_private != NULL)
+ {
+ mfree (objfile -> md, objfile -> sym_private);
+ }
}
/* ELF specific initialization routine for reading symbols.
just a stub. */
static void
-elf_symfile_init (sf)
- struct sym_fns *sf;
+elf_symfile_init (objfile)
+ struct objfile *objfile;
{
}
use "elf" in the same sense as "a.out" or "coff", to imply both the ELF
object file format and the DWARF debugging format. */
-static struct sym_fns elf_sym_fns = {
+static struct sym_fns elf_sym_fns =
+{
"elf", /* sym_name: name or name prefix of BFD target type */
3, /* sym_namelen: number of significant sym_name chars */
elf_new_init, /* sym_new_init: init anything gbl to entire symtab */
elf_symfile_init, /* sym_init: read initial info, setup for sym_read() */
elf_symfile_read, /* sym_read: read a symbol file into symtab */
- NULL, /* sym_bfd: accessor for symbol file being read */
- NULL, /* sym_private: sym_init & sym_read shared info */
+ elf_symfile_finish, /* sym_finish: finished with file, cleanup */
NULL /* next: pointer to next struct sym_fns */
};
extern CORE_ADDR startup_file_end; /* From blockframe.c */
void
-mipscoff_new_init()
+mipscoff_new_init (objfile)
+ struct objfile *objfile;
{
- /* If we have a file symbol header lying around, blow it away. */
- if (cur_hdr)
- free ((char *)cur_hdr);
- cur_hdr = 0;
}
void
-mipscoff_symfile_init (sf)
- struct sym_fns *sf;
+mipscoff_symfile_init (objfile)
+ struct objfile *objfile;
{
- sf->sym_private = NULL;
+ if (objfile -> sym_private != NULL)
+ {
+ mfree (objfile -> md, objfile -> sym_private);
+ }
+ objfile -> sym_private = NULL;
}
void
-mipscoff_symfile_read(sf, addr, mainline)
- struct sym_fns *sf;
+mipscoff_symfile_read (objfile, addr, mainline)
+ struct objfile *objfile;
CORE_ADDR addr;
int mainline;
{
- bfd *abfd = sf->objfile->obfd;
+ bfd *abfd = objfile -> obfd;
int desc;
/* WARNING WILL ROBINSON! ACCESSING BFD-PRIVATE DATA HERE! FIXME! */
/* Now that the executable file is positioned at symbol table,
process it and define symbols accordingly. */
- read_mips_symtab(sf->objfile, desc);
+ read_mips_symtab(objfile, desc);
/* Install any minimal symbols that have been collected as the current
minimal symbols for this objfile. */
- install_minimal_symbols (sf -> objfile);
+ install_minimal_symbols (objfile);
}
+/* Perform any local cleanups required when we are done with a particular
+ objfile. I.E, we are in the process of discarding all symbol information
+ for an objfile, freeing up all memory held for it, and unlinking the
+ objfile struct from the global list of known objfiles. */
+
+static void
+mipscoff_symfile_finish (objfile)
+ struct objfile *objfile;
+{
+ if (objfile -> sym_private != NULL)
+ {
+ mfree (objfile -> md, objfile -> sym_private);
+ }
+
+ /* If we have a file symbol header lying around, blow it away. */
+
+ if (cur_hdr)
+ {
+ free ((char *)cur_hdr);
+ }
+ cur_hdr = 0;
+}
+
/* Allocate zeroed memory */
static char *
\f
/* Initialization */
-static struct sym_fns ecoff_sym_fns = {"ecoff", 5,
- mipscoff_new_init, mipscoff_symfile_init,
- mipscoff_symfile_read};
+static struct sym_fns ecoff_sym_fns =
+{
+ "ecoff", /* sym_name: name or name prefix of BFD target type */
+ 5, /* sym_namelen: number of significant sym_name chars */
+ mipscoff_new_init, /* sym_new_init: init anything gbl to entire symtab */
+ mipscoff_symfile_init,/* sym_init: read initial info, setup for sym_read() */
+ mipscoff_symfile_read,/* sym_read: read a symbol file into symtab */
+ mipscoff_symfile_finish,/* sym_finish: finished with file, cleanup */
+ NULL /* next: pointer to next struct sym_fns */
+};
+
_initialize_mipsread ()
{
/* Destroy an objfile and all the symtabs and psymtabs under it. Note
that as much as possible is allocated on the symbol_obstack and
- psymbol_obstack, so that the memory can be efficiently freed. */
+ psymbol_obstack, so that the memory can be efficiently freed.
+
+ Things which we do NOT free because they are not in malloc'd memory
+ or not in memory specific to the objfile include:
+
+ objfile -> sf
+
+ */
void
free_objfile (objfile)
{
struct objfile *ofp;
- if (objfile -> name)
+ if (objfile -> sf != NULL)
+ {
+ (*objfile -> sf -> sym_finish) (objfile);
+ }
+ if (objfile -> name != NULL)
{
mfree (objfile -> md, objfile -> name);
}
- if (objfile -> obfd)
+ if (objfile -> obfd != NULL)
{
bfd_close (objfile -> obfd);
}
/* Global variables owned by this file */
CORE_ADDR entry_point; /* Where execution starts in symfile */
-struct sym_fns *symtab_fns = NULL; /* List of all available sym_fns. */
-int readnow_symbol_files; /* Read full symbols immediately */
+int readnow_symbol_files; /* Read full symbols immediately */
/* External variables and functions referenced. */
static bfd *
symfile_bfd_open PARAMS ((char *));
-static struct sym_fns *
-symfile_init PARAMS ((struct objfile *));
+static void
+find_sym_fns PARAMS ((struct objfile *));
static void
clear_symtab_users_once PARAMS ((void));
-/* Saves the sym_fns of the current symbol table, so we can call
- the right XXX_new_init function when we free it. FIXME. This
- should be extended to calling the new_init function for each
- existing symtab or psymtab, since the main symbol file and
- subsequent added symbol files can have different types. */
+/* List of all available sym_fns. On gdb startup, each object file reader
+ calls add_symtab_fns() to register information on each format it is
+ prepared to read. */
-static struct sym_fns *symfile_fns;
+static struct sym_fns *symtab_fns = NULL;
/* When we need to allocate a new type, we need to know which type_obstack
to allocate the type on, since there is one for each objfile. The places
int verbo;
{
asection *text_sect;
- struct sym_fns *sf;
/* There is a distinction between having no symbol table
(we refuse to read the file, leaving the old set of symbols around)
/* Save startup file's range of PC addresses to help blockframe.c
decide where the bottom of the stack is. */
+
if (bfd_get_file_flags (objfile -> obfd) & EXEC_P)
{
/* Executable file -- record its entry point so we'll recognize
startup_file_end = 0;
}
- sf = symfile_init (objfile);
+ find_sym_fns (objfile);
if (mainline)
{
/* Since no error yet, throw away the old symbol table. */
- if (symfile_objfile)
- free_objfile (symfile_objfile);
- symfile_objfile = NULL;
+ if (symfile_objfile != NULL)
+ {
+ free_objfile (symfile_objfile);
+ symfile_objfile = NULL;
+ }
- (*sf->sym_new_init) ();
+ (*objfile -> sf -> sym_new_init) (objfile);
/* For mainline, caller didn't know the specified address of the
text section. We fix that here. */
+
text_sect = bfd_get_section_by_name (objfile -> obfd, ".text");
addr = bfd_section_vma (objfile -> obfd, text_sect);
}
- /* Allow complaints to appear for this new file, and record how
- verbose to be. */
+ /* Initialize symbol reading routines for this objfile, allow complaints to
+ appear for this new file, and record how verbose to be, then do the
+ initial symbol reading for this file. */
- clear_complaints(1, verbo);
-
- (*sf->sym_read) (sf, addr, mainline);
+ (*objfile -> sf -> sym_init) (objfile);
+ clear_complaints (1, verbo);
+ (*objfile -> sf -> sym_read) (objfile, addr, mainline);
/* Don't allow char * to have a typename (else would get caddr_t.) */
/* Ditto void *. FIXME should do this for all the builtin types. */
{
/* OK, make it the "real" symbol file. */
symfile_objfile = objfile;
- symfile_fns = sf;
}
/* If we have wiped out any old symbol tables, clean up. */
clear_symtab_users_once ();
/* We're done reading the symbol file; finish off complaints. */
- clear_complaints(0, verbo);
+ clear_complaints (0, verbo);
/* Fixup all the breakpoints that may have been redefined by this
symbol file. */
{
struct objfile *objfile;
struct partial_symtab *psymtab;
+ bfd *abfd;
+ int mapped_it;
- /* Open a bfd for the file, then allocate a new objfile. */
-
- objfile = allocate_objfile (symfile_bfd_open (name), mapped);
-
- /* There is a distinction between having no symbol table
+ /* Open a bfd for the file and then check to see if the file has a
+ symbol table. There is a distinction between having no symbol table
(we refuse to read the file, leaving the old set of symbols around)
- and having no debugging symbols in your symbol table (we read
- the file and end up with a mostly empty symbol table, but with lots
- of stuff in the minimal symbol table). */
-
- if (!(bfd_get_file_flags (objfile -> obfd) & HAS_SYMS))
+ and having no debugging symbols in the symbol table (we read the file
+ and end up with a mostly empty symbol table, but with lots of stuff in
+ the minimal symbol table). We need to make the decision about whether
+ to continue with the file before allocating and building a objfile.
+
+ FIXME: This strategy works correctly when the debugging symbols are
+ intermixed with "normal" symbols. However, when the debugging symbols
+ are separate, such as with ELF/DWARF, it is perfectly plausible for
+ the symbol table to be missing but still have all the DWARF info
+ intact. Thus in general it is wrong to assume that having no symbol
+ table implies no debugging information. */
+
+ abfd = symfile_bfd_open (name);
+ if (!(bfd_get_file_flags (abfd) & HAS_SYMS))
{
error ("%s has no symbol-table", name);
}
+ if ((have_full_symbols () || have_partial_symbols ())
+ && mainline
+ && from_tty
+ && !query ("Load new symbol table from \"%s\"? ", name))
+ error ("Not confirmed.");
+
+ objfile = allocate_objfile (abfd, mapped);
+
/* If the objfile uses a mapped symbol file, and we have a psymtab for
it, then skip reading any symbols at this time. */
- if ((objfile -> psymtabs != NULL) && (objfile -> flags & OBJF_MAPPED))
+ if ((objfile -> flags & OBJF_MAPPED) && (objfile -> psymtabs != NULL))
{
+ /* We mapped in an existing symbol table file that already has had
+ the psymbols read in. So we can skip that part. Notify the user
+ that instead of reading the symbols, they have been mapped. */
if (from_tty || info_verbose)
{
- printf_filtered ("Mapped symbols for %s.\n", name);
+ printf_filtered ("Mapped symbols for %s...", name);
+ wrap_here ("");
fflush (stdout);
}
}
else
{
- if ((have_full_symbols () || have_partial_symbols ())
- && mainline
- && from_tty
- && !query ("Load new symbol table from \"%s\"? ", name))
- error ("Not confirmed.");
-
+ /* We either created a new mapped symbol table, mapped an existing
+ symbol table file with no partial symbols, or need to read an
+ unmapped symbol table. */
if (from_tty || info_verbose)
{
printf_filtered ("Reading symbols from %s...", name);
wrap_here ("");
fflush (stdout);
}
-
syms_from_objfile (objfile, addr, mainline, from_tty);
-
- readnow |= readnow_symbol_files;
- if (readnow)
- {
- if (from_tty || info_verbose)
- {
- printf_filtered ("expanding to full symbols...");
- wrap_here ("");
- fflush (stdout);
- }
-
- for (psymtab = objfile -> psymtabs;
- psymtab != NULL;
- psymtab = psymtab -> next)
- {
- (void) psymtab_to_symtab (psymtab);
- }
- }
+ }
+
+ /* We now have at least a partial symbol table. Check to see if the
+ user requested that all symbols be read on initial access via either
+ the gdb startup command line or on a per symbol file basis. Expand
+ all partial symbol tables for this objfile if so. */
+ readnow |= readnow_symbol_files;
+ if (readnow)
+ {
if (from_tty || info_verbose)
{
- printf_filtered ("done.\n");
+ printf_filtered ("expanding to full symbols...");
+ wrap_here ("");
fflush (stdout);
}
+
+ for (psymtab = objfile -> psymtabs;
+ psymtab != NULL;
+ psymtab = psymtab -> next)
+ {
+ (void) psymtab_to_symtab (psymtab);
+ }
+ }
+
+ if (from_tty || info_verbose)
+ {
+ printf_filtered ("done.\n");
+ fflush (stdout);
}
+
return (objfile);
}
error ("Not confirmed.");
free_all_objfiles ();
symfile_objfile = NULL;
- /* FIXME, this does not account for the main file and subsequent
- files (shared libs, dynloads, etc) having different formats.
- It only calls the cleanup routine for the main file's format. */
- if (symfile_fns)
- {
- (*symfile_fns -> sym_new_init) ();
- free (symfile_fns);
- symfile_fns = 0;
- }
}
else
{
return (sym_bfd);
}
-/* Link a new symtab_fns into the global symtab_fns list.
- Called by various _initialize routines. */
+/* Link a new symtab_fns into the global symtab_fns list. Called on gdb
+ startup by the _initialize routine in each object file format reader,
+ to register information about each format the the reader is prepared
+ to handle. */
void
add_symtab_fns (sf)
/* Initialize to read symbols from the symbol file sym_bfd. It either
- returns or calls error(). The result is a malloc'd struct sym_fns
- that contains cached information about the symbol file. */
+ returns or calls error(). The result is an initialized struct sym_fns
+ in the objfile structure, that contains cached information about the
+ symbol file. */
-static struct sym_fns *
-symfile_init (objfile)
+static void
+find_sym_fns (objfile)
struct objfile *objfile;
{
struct sym_fns *sf, *sf2;
- for (sf = symtab_fns; sf != NULL; sf = sf->next)
+ for (sf = symtab_fns; sf != NULL; sf = sf -> next)
{
- if (!strncmp (bfd_get_target (objfile -> obfd), sf->sym_name, sf->sym_namelen))
+ if (strncmp (bfd_get_target (objfile -> obfd),
+ sf -> sym_name, sf -> sym_namelen) == 0)
{
- sf2 = (struct sym_fns *)xmalloc (sizeof (*sf2));
- /* FIXME, who frees this? */
- *sf2 = *sf;
- sf2->objfile = objfile;
- sf2->sym_bfd = objfile -> obfd;
- sf2->sym_private = 0; /* Not alloc'd yet */
- (*sf2->sym_init) (sf2);
- return sf2;
+ objfile -> sf = sf;
+ return;
}
}
error ("I'm sorry, Dave, I can't do that. Symbol format `%s' unknown.",
bfd_get_target (objfile -> obfd));
- return 0; /* Appease lint. */
}
\f
/* This function runs the load command of our current target. */
int size;
};
+/* Structure to keep track of symbol reading functions for various
+ object file types. */
+
+struct sym_fns {
+
+ /* is the name, or name prefix, of the BFD "target type" that this
+ set of functions handles. E.g. "a.out" or "sunOs" or "coff" or "elf". */
+
+ char *sym_name;
+
+ /* counts how many bytes of sym_name should be checked against the
+ BFD target type of the file being read. If an exact match is
+ desired, specify the number of characters in sym_name plus 1 for the
+ NUL. If a prefix match is desired, specify the number of characters in
+ sym_name. */
+
+ int sym_namelen;
+
+ /* Initializes anything that is global to the entire symbol table. It is
+ called during symbol_file_add, when we begin debugging an entirely new
+ program. */
+
+ void (*sym_new_init) PARAMS ((struct objfile *));
+
+ /* Reads any initial information from a symbol file, and initializes the
+ struct sym_fns SF in preparation for sym_read(). It is called every
+ time we read a symbol file for any reason. */
+
+ void (*sym_init) PARAMS ((struct objfile *));
+
+ /* sym_read (objfile, addr, mainline)
+ Reads a symbol file into a psymtab (or possibly a symtab).
+ OBJFILE is the objfile struct for the file we are reading. ADDR
+ is the offset between the file's specified start address and
+ its true address in memory. MAINLINE is 1 if this is the
+ main symbol table being read, and 0 if a secondary
+ symbol file (e.g. shared library or dynamically loaded file)
+ is being read. */
+
+ void (*sym_read) PARAMS ((struct objfile *, CORE_ADDR, int));
+
+ /* Called when we are finished with an objfile. Should do all cleanup
+ that is specific to the object file format for the particular objfile. */
+
+ void (*sym_finish) PARAMS ((struct objfile *));
+
+ /* Finds the next struct sym_fns. They are allocated and initialized
+ in whatever module implements the functions pointed to; an
+ initializer calls add_symtab_fns to add them to the global chain. */
+
+ struct sym_fns *next;
+
+};
+
/* Master structure for keeping track of each input file from which
gdb reads symbols. One of these is allocated for each such file we
access, e.g. the exec_file, symbol_file, and any shared library object
the memory mapped malloc() package to manage storage for this objfile's
data. NULL if we are not. */
- void *md;
+ PTR md;
+
+ /* Structure which keeps track of functions that manipulate objfile's
+ of the same type as this objfile. I.E. the function to read partial
+ symbols for example. Note that this structure is in statically
+ allocated memory, and is shared by all objfiles that use the
+ object module reader of this type. */
+
+ struct sym_fns *sf;
+
+ /* Hook for information which is shared by sym_init and sym_read for
+ this objfile. It is typically a pointer to malloc'd memory. */
+
+ PTR sym_private;
};
#define OBJF_MAPPED (1 << 0) /* Objfile data is mmap'd */
-/* Structure to keep track of symbol reading functions for various
- object file types. */
-
-struct sym_fns {
-
- /* is the name, or name prefix, of the BFD "target type" that this
- set of functions handles. E.g. "a.out" or "sunOs" or "coff" or "elf". */
-
- char *sym_name;
-
- /* counts how many bytes of sym_name should be checked against the
- BFD target type of the file being read. If an exact match is
- desired, specify the number of characters in sym_name plus 1 for the
- NUL. If a prefix match is desired, specify the number of characters in
- sym_name. */
-
- int sym_namelen;
-
- /* initializes anything that is global to the entire
- symbol table. It is called during symbol_file_add, when
- we begin debugging an entirely new program. */
-
- void (*sym_new_init) PARAMS ((void));
-
- /* sym_init (sf)
- reads any initial information from a symbol file, and
- initializes the struct sym_fns SF in preparation for sym_read().
- It is called every time we read a symbol file for any reason. */
-
- void (*sym_init) PARAMS ((struct sym_fns *));
-
- /* sym_read (sf, addr, mainline)
- reads a symbol file into a psymtab (or possibly a symtab).
- SF is the struct sym_fns that sym_init initialized. ADDR
- is the offset between the file's specified start address and
- its true address in memory. MAINLINE is 1 if this is the
- main symbol table being read, and 0 if a secondary
- symbol file (e.g. shared library or dynamically loaded file)
- is being read. */
-
- void (*sym_read) PARAMS ((struct sym_fns *, CORE_ADDR, int));
-
- /* is the accessor for the symbol file being read. */
-
- bfd *sym_bfd;
-
- /* is where information can be shared among sym_init and sym_read.
- It is typically a pointer to malloc'd memory. */
-
- char *sym_private; /* Should be void * */
-
- /* is the "struct objfile" for the object file being read. */
-
- struct objfile *objfile;
-
- /* finds the next struct sym_fns. They are allocated and initialized
- in whatever module implements the functions pointed to; an
- initializer calls add_symtab_fns to add them to the global chain. */
-
- struct sym_fns *next;
-
-};
-
extern void
extend_psymbol_list PARAMS ((struct psymbol_allocation_list *,
struct objfile *));
extern struct complaint complaint_root[1];
-/* Externally visible variables defined in symfile.c */
-
-/* The object file that the main symbol table was loaded from (e.g. the
- argument to the "symbol-file" or "file" command). */
-
-extern struct objfile *symfile_objfile;
-
-/* Where execution starts in symfile */
-
-extern CORE_ADDR entry_point;
-
-/* Root of object file struct chain. */
-
-extern struct objfile *object_files;
-
/* Functions that handle complaints. (in symfile.c) */
extern void
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
-#include <stdio.h>
+#include "defs.h"
#include <errno.h>
#include <ctype.h>
-#include "defs.h"
#include "target.h"
#include "gdbcmd.h"
#include "symtab.h"
static int
nosymbol PARAMS ((char *, CORE_ADDR *));
-static void
-noprocess PARAMS ((void));
-
static void
tcomplain PARAMS ((void));
static void
ignore PARAMS ((void));
-
static void
target_command PARAMS ((char *, int));
current_target->to_shortname);
}
-static void
+void
noprocess ()
{
error ("You can't do that without a process to debug");
struct target_ops *t;
int has_all_mem = 0;
- if (symfile_objfile != 0)
+ if (symfile_objfile != NULL)
printf ("Symbols from \"%s\".\n", symfile_objfile->name);
#ifdef FILES_INFO_HOOK
enter_line_range PARAMS ((struct subfile *, unsigned, unsigned,
CORE_ADDR, CORE_ADDR, unsigned *));
-static void
-aixcoff_symfile_read PARAMS ((struct sym_fns *, CORE_ADDR, int));
-
static void
free_debugsection PARAMS ((void));
init_stringtab PARAMS ((bfd *, long, struct objfile *));
static void
-aixcoff_symfile_init PARAMS ((struct sym_fns *));
+aixcoff_symfile_init PARAMS ((struct objfile *));
+
+static void
+aixcoff_new_init PARAMS ((struct objfile *));
+
+static void
+aixcoff_symfile_read PARAMS ((struct sym_fns *, CORE_ADDR, int));
static void
-aixcoff_new_init PARAMS ((void));
+aixcoff_symfile_finish PARAMS ((struct objfile *));
static int
init_lineno PARAMS ((bfd *, long, int));
#endif
static void
-aixcoff_new_init ()
+aixcoff_new_init (objfile)
+ struct objfile *objfile;
{
- /* This routine is executed once per executable. We should start with a
- fresh include table per executable. */
-
- if (inclTable) {
- free (inclTable);
- inclTable = NULL;
- }
- inclIndx = inclLength = inclDepth = NULL;
}
static void
-aixcoff_symfile_init (sf)
-struct sym_fns *sf;
+aixcoff_symfile_init (objfile)
+ struct objfile *objfile;
{
- bfd *abfd = sf->sym_bfd;
+ bfd *abfd = objfile->obfd;
/* Allocate struct to keep track of the symfile */
- /* FIXME memory leak */
- sf->sym_private = xmalloc(sizeof (struct coff_symfile_info));
+ objfile -> sym_private = xmmalloc (objfile -> md,
+ sizeof (struct coff_symfile_info));
/*
* Save startup file's range of PC addresses to help
}
}
+/* Perform any local cleanups required when we are done with a particular
+ objfile. I.E, we are in the process of discarding all symbol information
+ for an objfile, freeing up all memory held for it, and unlinking the
+ objfile struct from the global list of known objfiles. */
+
+static void
+aixcoff_symfile_finish (objfile)
+ struct objfile *objfile;
+{
+ if (objfile -> sym_private != NULL)
+ {
+ mfree (objfile -> md, objfile -> sym_private);
+ }
+
+ /* Start with a fresh include table for the next objfile. */
+
+ if (inclTable)
+ {
+ free (inclTable);
+ inclTable = NULL;
+ }
+ inclIndx = inclLength = inclDepth = 0;
+}
+
static int
init_stringtab(abfd, offset, objfile)
/* aixcoff version of symbol file read. */
static void
-aixcoff_symfile_read (sf, addr, mainline)
- struct sym_fns *sf;
+aixcoff_symfile_read (objfile, addr, mainline)
+ struct objfile *objfile;
CORE_ADDR addr;
int mainline;
{
int stringtab_offset; /* string table file offsets */
int val;
bfd *abfd;
- struct coff_symfile_info *info = (void*) sf->sym_private;
+ struct coff_symfile_info *info;
char *name;
- symfile_bfd = abfd = sf->objfile->obfd;
- name = sf->objfile->name;
+ info = (struct coff_symfile_info *) objfile -> sym_private;
+ symfile_bfd = abfd = objfile->obfd;
+ name = objfile->name;
num_symbols = bfd_get_symcount (abfd); /* # of symbols */
symtab_offset = obj_sym_filepos (abfd); /* symbol table file offset */
error("\"%s\": error reading line numbers\n", name);
}
- val = init_stringtab(abfd, stringtab_offset, sf->objfile);
+ val = init_stringtab(abfd, stringtab_offset, objfile);
if (val < 0) {
error ("\"%s\": can't get string table", name);
}
/* Now that the executable file is positioned at symbol table,
process it and define symbols accordingly. */
- read_xcoff_symtab(sf->objfile, num_symbols);
+ read_xcoff_symtab(objfile, num_symbols);
make_cleanup (free_debugsection, 0);
/* Install any minimal symbols that have been collected as the current
minimal symbols for this objfile. */
- install_minimal_symbols (sf -> objfile);
+ install_minimal_symbols (objfile);
/* Make a default for file to list. */
select_source_symtab (0);
static struct sym_fns aixcoff_sym_fns =
{
- "aixcoff-rs6000", 15,
- aixcoff_new_init, aixcoff_symfile_init,
- aixcoff_symfile_read,
+ "aixcoff-rs6000", /* sym_name: name or name prefix of BFD target type */
+ 15, /* sym_namelen: number of significant sym_name chars */
+ aixcoff_new_init, /* sym_new_init: init anything gbl to entire symtab */
+ aixcoff_symfile_init, /* sym_init: read initial info, setup for sym_read() */
+ aixcoff_symfile_read, /* sym_read: read a symbol file into symtab */
+ aixcoff_symfile_finish, /* sym_finish: finished with file, cleanup */
+ NULL /* next: pointer to next struct sym_fns */
};
void