#include "solib.h"
#include "remote.h"
#include "stack.h"
+#include "gdb_bfd.h"
#include <sys/types.h>
#include <fcntl.h>
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;
if (abfd_stat.st_dev == parent_stat.st_dev
&& abfd_stat.st_ino == parent_stat.st_ino)
{
- bfd_close (abfd);
+ gdb_bfd_unref (abfd);
return 0;
}
verified_as_different = 1;
file_crc_p = get_file_crc (abfd, &file_crc);
- bfd_close (abfd);
+ gdb_bfd_unref (abfd);
if (!file_crc_p)
return 0;
return NULL;
}
+ cleanups = make_cleanup (xfree, debuglink);
dir = xstrdup (objfile->name);
- cleanups = make_cleanup (xfree, dir);
+ make_cleanup (xfree, dir);
terminate_after_last_dir_separator (dir);
canon_dir = lrealpath (dir);
}
/* If NAME is a remote name open the file using remote protocol, otherwise
- open it normally. */
+ open it normally. Returns a new reference to the BFD. On error,
+ 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 remote_bfd_open (name, gnutarget);
+ result = remote_bfd_open (name, gnutarget);
else
- return bfd_openr (name, gnutarget);
+ result = gdb_bfd_open (name, gnutarget, -1);
+
+ return result;
}
if (remote_filename_p (name))
{
- name = xstrdup (name);
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))
{
- 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 ()));
}
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 = bfd_fopen (name, gnutarget, FOPEN_RB, desc);
+ sym_bfd = gdb_bfd_open (name, gnutarget, desc);
if (!sym_bfd)
{
- close (desc);
make_cleanup (xfree, name);
error (_("`%s': can't open to read symbols: %s."), name,
bfd_errmsg (bfd_get_error ()));
if (!bfd_check_format (sym_bfd, bfd_object))
{
- /* FIXME: should be checking for errors from bfd_close (for one
- thing, on error it does not free all the storage associated
- with the bfd). */
- bfd_close (sym_bfd); /* This also closes desc. */
- make_cleanup (xfree, name);
+ make_cleanup_bfd_unref (sym_bfd);
error (_("`%s': can't read symbols: %s."), name,
bfd_errmsg (bfd_get_error ()));
}
- /* bfd_usrdata exists for applications and libbfd must not touch it. */
- gdb_assert (bfd_usrdata (sym_bfd) == NULL);
-
return sym_bfd;
}
this section. */
ui_out_message (current_uiout, 0, "Loading section %s, size %s lma %s\n",
args->section_name, hex_string (args->section_size),
- paddress (target_gdbarch, args->lma));
+ paddress (target_gdbarch (), args->lma));
return;
}
if (target_read_memory (args->lma, check, bytes) != 0)
error (_("Download verify read failed at %s"),
- paddress (target_gdbarch, args->lma));
+ paddress (target_gdbarch (), args->lma));
if (memcmp (args->buffer, check, bytes) != 0)
error (_("Download verify compare failed at %s"),
- paddress (target_gdbarch, args->lma));
+ paddress (target_gdbarch (), args->lma));
do_cleanups (verify_cleanups);
}
totals->data_count += bytes;
args->buffer += bytes;
totals->write_count += 1;
args->section_sent += bytes;
- if (quit_flag
+ if (check_quit_flag ()
|| (deprecated_ui_load_progress_hook != NULL
&& deprecated_ui_load_progress_hook (args->section_name,
args->section_sent)))
}
/* Open the file for loading. */
- loadfile_bfd = bfd_openr (filename, gnutarget);
+ loadfile_bfd = gdb_bfd_open (filename, gnutarget, -1);
if (loadfile_bfd == NULL)
{
perror_with_name (filename);
return;
}
- /* FIXME: should be checking for errors from bfd_close (for one thing,
- on error it does not free all the storage associated with the
- bfd). */
- make_cleanup_bfd_close (loadfile_bfd);
+ make_cleanup_bfd_unref (loadfile_bfd);
if (!bfd_check_format (loadfile_bfd, bfd_object))
{
entry = bfd_get_start_address (loadfile_bfd);
ui_out_text (uiout, "Start address ");
- ui_out_field_fmt (uiout, "address", "%s", paddress (target_gdbarch, entry));
+ ui_out_field_fmt (uiout, "address", "%s", paddress (target_gdbarch (), entry));
ui_out_text (uiout, ", load size ");
ui_out_field_fmt (uiout, "load-size", "%lu", total_progress.data_count);
ui_out_text (uiout, "\n");
clear_objfile_data (objfile);
- /* 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);
- if (!bfd_close (objfile->obfd))
- error (_("Can't close BFD for %s: %s"), objfile->name,
- bfd_errmsg (bfd_get_error ()));
- objfile->obfd = bfd_open_maybe_remote (obfd_filename);
- if (objfile->obfd == NULL)
- error (_("Can't open %s to read symbols."), objfile->name);
- else
- objfile->obfd = gdb_bfd_ref (objfile->obfd);
+ /* Clean up any state BFD has sitting around. */
+ {
+ 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);
+ if (objfile->obfd == NULL)
+ {
+ /* We have to make a cleanup and error here, rather
+ than erroring later, because once we unref OBFD,
+ OBFD_FILENAME will be freed. */
+ make_cleanup_bfd_unref (obfd);
+ error (_("Can't open %s to read symbols."), obfd_filename);
+ }
+ gdb_bfd_unref (obfd);
+ }
+
+ objfile->name = bfd_get_filename (objfile->obfd);
/* bfd_openr sets cacheable to true, which is what we want. */
if (!bfd_check_format (objfile->obfd, bfd_object))
error (_("Can't read symbols from %s: %s."), objfile->name,
/* 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";
symtab->next = objfile->symtabs;
objfile->symtabs = symtab;
+ if (symtab_create_debug)
+ {
+ /* Be a bit clever with debugging messages, and don't print objfile
+ every time, only when it changes. */
+ static char *last_objfile_name = NULL;
+
+ if (last_objfile_name == NULL
+ || strcmp (last_objfile_name, objfile->name) != 0)
+ {
+ xfree (last_objfile_name);
+ last_objfile_name = xstrdup (objfile->name);
+ fprintf_unfiltered (gdb_stdlog,
+ "Creating one or more symtabs for objfile %s ...\n",
+ last_objfile_name);
+ }
+ fprintf_unfiltered (gdb_stdlog,
+ "Created symtab %s for module %s.\n",
+ host_address_to_string (symtab), filename);
+ }
+
return (symtab);
}
\f
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)