loaded file.
ABFD is a BFD already open on the file, as from symfile_bfd_open.
- This BFD will be closed on error, and is always consumed by this function.
+ A new reference is acquired by this function.
ADD_FLAGS encodes verbosity, whether this is main symbol file or
extra, such as dynamically loaded code, and what to do with breakpoins.
int flags, struct objfile *parent)
{
struct objfile *objfile;
- struct cleanup *my_cleanups;
const char *name = bfd_get_filename (abfd);
const int from_tty = add_flags & SYMFILE_VERBOSE;
const int mainline = add_flags & SYMFILE_MAINLINE;
add_flags &= ~SYMFILE_NO_READ;
}
- my_cleanups = make_cleanup_bfd_close (abfd);
-
/* Give user a chance to burp if we'd be
interactively wiping out any existing symbols. */
error (_("Not confirmed."));
objfile = allocate_objfile (abfd, flags | (mainline ? OBJF_MAINLINE : 0));
- discard_cleanups (my_cleanups);
if (parent)
add_separate_debug_objfile (objfile, parent);
symbol_file_add (char *name, int add_flags, struct section_addr_info *addrs,
int flags)
{
- return symbol_file_add_from_bfd (symfile_bfd_open (name), add_flags, addrs,
- flags, NULL);
+ bfd *bfd = symfile_bfd_open (name);
+ struct cleanup *cleanup = make_cleanup_bfd_unref (bfd);
+ struct objfile *objf;
+
+ objf = symbol_file_add_from_bfd (bfd, add_flags, addrs, flags, NULL);
+ do_cleanups (cleanup);
+ return objf;
}
if (filename_cmp (name, parent_objfile->name) == 0)
return 0;
- abfd = bfd_open_maybe_remote (name);
+ abfd = gdb_bfd_open_maybe_remote (name);
if (!abfd)
return 0;
returns NULL with the BFD error set. */
bfd *
-bfd_open_maybe_remote (const char *name)
+gdb_bfd_open_maybe_remote (const char *name)
{
+ bfd *result;
+
if (remote_filename_p (name))
- return gdb_bfd_ref (remote_bfd_open (name, gnutarget));
+ result = remote_bfd_open (name, gnutarget);
else
- return gdb_bfd_ref (bfd_openr (name, gnutarget));
+ result = gdb_bfd_openr (name, gnutarget);
+
+ return result;
}
if (remote_filename_p (name))
{
- name = xstrdup (name);
- sym_bfd = gdb_bfd_ref (remote_bfd_open (name, gnutarget));
+ sym_bfd = remote_bfd_open (name, gnutarget);
if (!sym_bfd)
- {
- make_cleanup (xfree, name);
- error (_("`%s': can't open to read symbols: %s."), name,
- bfd_errmsg (bfd_get_error ()));
- }
+ error (_("`%s': can't open to read symbols: %s."), name,
+ bfd_errmsg (bfd_get_error ()));
if (!bfd_check_format (sym_bfd, bfd_object))
{
- gdb_bfd_unref (sym_bfd);
- make_cleanup (xfree, name);
+ make_cleanup_bfd_unref (sym_bfd);
error (_("`%s': can't read symbols: %s."), name,
bfd_errmsg (bfd_get_error ()));
}
perror_with_name (name);
}
- /* Free 1st new malloc'd copy, but keep the 2nd malloc'd copy in
- bfd. It'll be freed in free_objfile(). */
xfree (name);
name = absolute_name;
+ make_cleanup (xfree, name);
- sym_bfd = gdb_bfd_ref (bfd_fopen (name, gnutarget, FOPEN_RB, desc));
+ sym_bfd = gdb_bfd_fopen (name, gnutarget, FOPEN_RB, desc);
if (!sym_bfd)
{
make_cleanup (xfree, name);
if (!bfd_check_format (sym_bfd, bfd_object))
{
- make_cleanup_bfd_close (sym_bfd);
- make_cleanup (xfree, name);
+ make_cleanup_bfd_unref (sym_bfd);
error (_("`%s': can't read symbols: %s."), name,
bfd_errmsg (bfd_get_error ()));
}
}
/* Open the file for loading. */
- loadfile_bfd = gdb_bfd_ref (bfd_openr (filename, gnutarget));
+ loadfile_bfd = gdb_bfd_openr (filename, gnutarget);
if (loadfile_bfd == NULL)
{
perror_with_name (filename);
return;
}
- make_cleanup_bfd_close (loadfile_bfd);
+ make_cleanup_bfd_unref (loadfile_bfd);
if (!bfd_check_format (loadfile_bfd, bfd_object))
{
/* Clean up any state BFD has sitting around. We don't need
to close the descriptor but BFD lacks a way of closing the
BFD without closing the descriptor. */
- obfd_filename = bfd_get_filename (objfile->obfd);
- gdb_bfd_unref (objfile->obfd);
- objfile->obfd = bfd_open_maybe_remote (obfd_filename);
+ {
+ struct bfd *obfd = objfile->obfd;
+
+ obfd_filename = bfd_get_filename (objfile->obfd);
+ /* Open the new BFD before freeing the old one, so that
+ the filename remains live. */
+ objfile->obfd = gdb_bfd_open_maybe_remote (obfd_filename);
+ gdb_bfd_unref (obfd);
+ }
+
if (objfile->obfd == NULL)
error (_("Can't open %s to read symbols."), objfile->name);
/* bfd_openr sets cacheable to true, which is what we want. */
/* Free the obstacks for non-reusable objfiles. */
psymbol_bcache_free (objfile->psymbol_cache);
objfile->psymbol_cache = psymbol_bcache_init ();
- bcache_xfree (objfile->macro_cache);
- objfile->macro_cache = bcache_xmalloc (NULL, NULL);
- bcache_xfree (objfile->filename_cache);
- objfile->filename_cache = bcache_xmalloc (NULL,NULL);
if (objfile->demangled_names_hash != NULL)
{
htab_delete (objfile->demangled_names_hash);
memset (&objfile->msymbol_demangled_hash, 0,
sizeof (objfile->msymbol_demangled_hash));
+ set_objfile_per_bfd (objfile);
+
/* obstack_init also initializes the obstack so it is
empty. We could use obstack_specify_allocation but
gdb_obstack.h specifies the alloc/dealloc functions. */
obstack_alloc (&objfile->objfile_obstack, sizeof (struct symtab));
memset (symtab, 0, sizeof (*symtab));
symtab->filename = (char *) bcache (filename, strlen (filename) + 1,
- objfile->filename_cache);
+ objfile->per_bfd->filename_cache);
symtab->fullname = NULL;
symtab->language = deduce_language_from_filename (filename);
symtab->debugformat = "unknown";
last_objfile_name);
}
fprintf_unfiltered (gdb_stdlog,
- "Created symtab 0x%lx for module %s.\n",
- (long) symtab, filename);
+ "Created symtab %s for module %s.\n",
+ host_address_to_string (symtab), filename);
}
return (symtab);
A place-holder for a mis-typed command. */
/* Command list chain containing all defined "overlay" subcommands. */
-struct cmd_list_element *overlaylist;
+static struct cmd_list_element *overlaylist;
static void
overlay_command (char *args, int from_tty)