+2012-07-23 Tom Tromey <tromey@redhat.com>
+
+ * bfd-target.c (target_bfd_reopen): Update.
+ * cli/cli-dump.c (bfd_openr_with_cleanup)
+ (bfd_openw_with_cleanup): Update.
+ * corelow.c (core_open): Update.
+ * dsrec.c (load_srec): Update.
+ * exec.c (exec_file_attach): Update.
+ * gcore.c (create_gcore_bfd): Update.
+ * gdb_bfd.c (gdb_bfd_ref): Return void.
+ (gdb_bfd_open): Update.
+ * gdb_bfd.h (gdb_bfd_ref): Return void.
+ Update comments.
+ * jit.c (jit_bfd_try_read_symtab): Update.
+ * m32r-rom.c (m32r_load, m32r_upload_command): Update.
+ * machoread.c (macho_symfile_read_all_oso): Update.
+ (macho_check_dsym): Update.
+ * procfs.c (insert_dbx_link_bpt_in_file): Update.
+ * remote-m32r-sdi.c (m32r_load): Update.
+ * remote-mips.c (mips_load_srec, pmon_load_fast): Update.
+ * rs6000-nat.c (add_vmap): Update.
+ * solib-darwin.c (darwin_solib_get_all_image_info_addr_at_init):
+ Update.
+ * solib-pa64.c (pa64_solib_create_inferior_hook): Update.
+ * solib-spu.c (spu_bfd_open): Update.
+ * solib.c (solib_bfd_fopen, solib_read_symbols): Update.
+ * spu-linux-nat.c (spu_bfd_open): Update.
+ * symfile.c (bfd_open_maybe_remote, symfile_bfd_open)
+ (generic_load): Update.
+ * windows-nat.c (windows_make_so): Update.
+
2012-07-22 Siddhesh Poyarekar <siddhesh@redhat.com>
* sh-tdep.c (sh_treat_as_flt_p): Remove unused variable LEN.
struct target_bfd_data *data;
data = XZALLOC (struct target_bfd_data);
- data->bfd = gdb_bfd_ref (abfd);
+ data->bfd = abfd;
+ gdb_bfd_ref (abfd);
build_section_table (abfd, &data->table.sections, &data->table.sections_end);
t = XZALLOC (struct target_ops);
{
bfd *ibfd;
- ibfd = gdb_bfd_ref (bfd_openr (filename, target));
+ ibfd = bfd_openr (filename, target);
+ gdb_bfd_ref (ibfd);
if (ibfd == NULL)
error (_("Failed to open %s: %s."), filename,
bfd_errmsg (bfd_get_error ()));
if (*mode == 'w') /* Write: create new file */
{
- obfd = gdb_bfd_ref (bfd_openw (filename, target));
+ obfd = bfd_openw (filename, target);
+ gdb_bfd_ref (obfd);
if (obfd == NULL)
error (_("Failed to open %s: %s."), filename,
bfd_errmsg (bfd_get_error ()));
if (scratch_chan < 0)
perror_with_name (filename);
- temp_bfd = gdb_bfd_ref (bfd_fopen (filename, gnutarget,
- write_files ? FOPEN_RUB : FOPEN_RB,
- scratch_chan));
+ temp_bfd = bfd_fopen (filename, gnutarget,
+ write_files ? FOPEN_RUB : FOPEN_RB,
+ scratch_chan);
+ gdb_bfd_ref (temp_bfd);
if (temp_bfd == NULL)
perror_with_name (filename);
srec = (char *) alloca (maxrecsize + 1);
- abfd = gdb_bfd_ref (bfd_openr (file, 0));
+ abfd = bfd_openr (file, 0);
+ gdb_bfd_ref (abfd);
if (!abfd)
{
printf_filtered (_("Unable to open file %s\n"), file);
if (scratch_chan < 0)
perror_with_name (filename);
- exec_bfd = gdb_bfd_ref (bfd_fopen (scratch_pathname, gnutarget,
- write_files ? FOPEN_RUB : FOPEN_RB,
- scratch_chan));
+ exec_bfd = bfd_fopen (scratch_pathname, gnutarget,
+ write_files ? FOPEN_RUB : FOPEN_RB,
+ scratch_chan);
+ gdb_bfd_ref (exec_bfd);
if (!exec_bfd)
{
bfd *
create_gcore_bfd (char *filename)
{
- bfd *obfd = gdb_bfd_ref (bfd_openw (filename, default_gcore_target ()));
+ bfd *obfd = bfd_openw (filename, default_gcore_target ());
+ gdb_bfd_ref (obfd);
if (!obfd)
error (_("Failed to open '%s' for output."), filename);
gdb_bfd_stash_filename (obfd);
if (abfd != NULL)
{
close (fd);
- return gdb_bfd_ref (abfd);
+ gdb_bfd_ref (abfd);
+ return abfd;
}
abfd = bfd_fopen (name, target, FOPEN_RB, fd);
*slot = abfd;
gdb_bfd_stash_filename (abfd);
- return gdb_bfd_ref (abfd);
+ gdb_bfd_ref (abfd);
+ return abfd;
}
/* A helper function that releases any section data attached to the
/* Add reference to ABFD. Returns ABFD. */
-struct bfd *
+void
gdb_bfd_ref (struct bfd *abfd)
{
struct gdb_bfd_data *gdata;
if (abfd == NULL)
- return NULL;
+ return;
gdata = bfd_usrdata (abfd);
if (gdata != NULL)
{
gdata->refc += 1;
- return abfd;
+ return;
}
gdata = bfd_zalloc (abfd, sizeof (struct gdb_bfd_data));
gdata->refc = 1;
gdata->mtime = bfd_get_mtime (abfd);
bfd_usrdata (abfd) = gdata;
-
- return abfd;
}
/* Unreference and possibly close ABFD. */
struct bfd *gdb_bfd_open (const char *name, const char *target, int fd);
-/* Acquire a new reference to ABFD. Returns ABFD for convenience.
- It is fine for ABFD to be NULL; in this case the function does
- nothing and returns NULL. */
+/* Increment the reference count of ABFD. It is fine for ABFD to be
+ NULL; in this case the function does nothing. */
-struct bfd *gdb_bfd_ref (struct bfd *abfd);
+void gdb_bfd_ref (struct bfd *abfd);
-/* Release a reference to ABFD. If this is the last reference, ABFD
- will be freed. If ABFD is NULL, this function does nothing. */
+/* Decrement the reference count of ABFD. If this is the last
+ reference, ABFD will be freed. If ABFD is NULL, this function does
+ nothing. */
void gdb_bfd_unref (struct bfd *abfd);
puts_unfiltered (_("Error opening JITed symbol file, ignoring it.\n"));
return;
}
- nbfd = gdb_bfd_ref (nbfd);
+ gdb_bfd_ref (nbfd);
/* Check the format. NOTE: This initializes important data that GDB uses!
We would segfault later without this line. */
if (filename == NULL || filename[0] == 0)
filename = get_exec_file (1);
- abfd = gdb_bfd_ref (bfd_openr (filename, 0));
+ abfd = bfd_openr (filename, 0);
+ gdb_bfd_ref (abfd);
if (!abfd)
error (_("Unable to open file %s."), filename);
cleanup = make_cleanup_bfd_unref (abfd);
printf_filtered (" -- Ethernet load complete.\n");
gettimeofday (&end_time, NULL);
- abfd = gdb_bfd_ref (bfd_openr (args, 0));
+ abfd = bfd_openr (args, 0);
+ gdb_bfd_ref (abfd);
cleanup = make_cleanup_bfd_unref (abfd);
if (abfd != NULL)
{ /* Download is done -- print section statistics. */
}
/* Open the archive and check the format. */
- archive_bfd = gdb_bfd_ref (bfd_openr (archive_name, gnutarget));
+ archive_bfd = bfd_openr (archive_name, gnutarget);
+ gdb_bfd_ref (archive_bfd);
if (archive_bfd == NULL)
{
warning (_("Could not open OSO archive file \"%s\""),
gdb_bfd_stash_filename (archive_bfd);
- member_bfd = gdb_bfd_ref (bfd_openr_next_archived_file (archive_bfd,
- NULL));
+ member_bfd = bfd_openr_next_archived_file (archive_bfd, NULL);
+ gdb_bfd_ref (member_bfd);
if (member_bfd == NULL)
{
}
prev = member_bfd;
- member_bfd
- = gdb_bfd_ref (bfd_openr_next_archived_file (archive_bfd,
- member_bfd));
+ member_bfd = bfd_openr_next_archived_file (archive_bfd,
+ member_bfd);
+ gdb_bfd_ref (member_bfd);
/* Free previous member if not referenced by an oso. */
if (ix2 >= last_ix)
{
bfd *abfd;
- abfd = gdb_bfd_ref (bfd_openr (oso->name, gnutarget));
+ abfd = bfd_openr (oso->name, gnutarget);
+ gdb_bfd_ref (abfd);
if (!abfd)
warning (_("`%s': can't open to read symbols: %s."), oso->name,
bfd_errmsg (bfd_get_error ()));
warning (_("can't find UUID in %s"), objfile->name);
return NULL;
}
- dsym_bfd = gdb_bfd_ref (bfd_openr (dsym_filename, gnutarget));
+ dsym_bfd = bfd_openr (dsym_filename, gnutarget);
+ gdb_bfd_ref (dsym_bfd);
if (dsym_bfd == NULL)
{
warning (_("can't open dsym file %s"), dsym_filename);
long storage_needed;
CORE_ADDR sym_addr;
- abfd = gdb_bfd_ref (bfd_fdopenr ("unamed", 0, fd));
+ abfd = bfd_fdopenr ("unamed", 0, fd);
+ gdb_bfd_ref (abfd);
if (abfd == NULL)
{
warning (_("Failed to create a bfd: %s."), bfd_errmsg (bfd_get_error ()));
if (!filename)
filename = get_exec_file (1);
- pbfd = gdb_bfd_ref (bfd_openr (filename, gnutarget));
+ pbfd = bfd_openr (filename, gnutarget);
+ gdb_bfd_ref (pbfd);
if (pbfd == NULL)
{
perror_with_name (filename);
buffer = alloca (srec_frame * 2 + 256);
- abfd = gdb_bfd_ref (bfd_openr (args, 0));
+ abfd = bfd_openr (args, 0);
+ gdb_bfd_ref (abfd);
if (!abfd)
{
printf_filtered ("Unable to open file %s\n", args);
buffer = (char *) xmalloc (MAXRECSIZE + 1);
binbuf = (unsigned char *) xmalloc (BINCHUNK);
- abfd = gdb_bfd_ref (bfd_openr (file, 0));
+ abfd = bfd_openr (file, 0);
+ gdb_bfd_ref (abfd);
if (!abfd)
{
printf_filtered ("Unable to open file %s\n", file);
abfd = bfd_openr (filename, gnutarget);
else
abfd = bfd_fdopenr (filename, gnutarget, fd);
- abfd = gdb_bfd_ref (abfd);
+ gdb_bfd_ref (abfd);
if (!abfd)
{
warning (_("Could not open `%s' as an executable file: %s"),
{
last = 0;
/* FIXME??? am I tossing BFDs? bfd? */
- while ((last = gdb_bfd_ref (bfd_openr_next_archived_file (abfd, last))))
- if (strcmp (mem, last->filename) == 0)
- break;
+ while ((last = bfd_openr_next_archived_file (abfd, last)))
+ {
+ gdb_bfd_ref (last);
+ if (strcmp (mem, last->filename) == 0)
+ break;
+ }
if (!last)
{
gdb_bfd_unref (abfd);
return NULL;
}
- obj = allocate_objfile (gdb_bfd_ref (vp->bfd), 0);
+ gdb_bfd_ref (vp->bfd);
+ obj = allocate_objfile (vp->bfd, 0);
vp->objfile = obj;
/* Always add symbols for the main objfile. */
cleanup = make_cleanup (null_cleanup, NULL);
/* Create a bfd for the interpreter. */
- dyld_bfd = gdb_bfd_ref (bfd_openr (interp_name, gnutarget));
+ dyld_bfd = bfd_openr (interp_name, gnutarget);
+ gdb_bfd_ref (dyld_bfd);
if (dyld_bfd)
{
bfd *sub;
gdbarch_bfd_arch_info (target_gdbarch));
if (sub)
{
- dyld_bfd = gdb_bfd_ref (sub);
+ dyld_bfd = sub;
+ gdb_bfd_ref (sub);
make_cleanup_bfd_unref (sub);
}
else
to find any magic formula to find it for Solaris (appears to
be trivial on GNU/Linux). Therefore, we have to try an alternate
mechanism to find the dynamic linker's base address. */
- tmp_bfd = gdb_bfd_ref (bfd_openr (buf, gnutarget));
+ tmp_bfd = bfd_openr (buf, gnutarget);
+ gdb_bfd_ref (tmp_bfd);
if (tmp_bfd == NULL)
return;
CORE_ADDR *open_closure = xmalloc (sizeof (CORE_ADDR));
*open_closure = addr;
- nbfd = gdb_bfd_ref (bfd_openr_iovec (name, "elf32-spu",
- spu_bfd_iovec_open, open_closure,
- spu_bfd_iovec_pread, spu_bfd_iovec_close,
- spu_bfd_iovec_stat));
+ nbfd = bfd_openr_iovec (name, "elf32-spu",
+ spu_bfd_iovec_open, open_closure,
+ spu_bfd_iovec_pread, spu_bfd_iovec_close,
+ spu_bfd_iovec_stat);
+ gdb_bfd_ref (nbfd);
if (!nbfd)
return NULL;
gdb_bfd_stash_filename (abfd);
xfree (pathname);
- return gdb_bfd_ref (abfd);
+ gdb_bfd_ref (abfd);
+ return abfd;
}
/* Find shared library PATHNAME and open a BFD for it. */
sap = build_section_addr_info_from_section_table (so->sections,
so->sections_end);
- so->objfile = symbol_file_add_from_bfd (gdb_bfd_ref (so->abfd),
+ gdb_bfd_ref (so->abfd);
+ so->objfile = symbol_file_add_from_bfd (so->abfd,
flags, sap, OBJF_SHARED,
NULL);
so->objfile->addr_low = so->addr_low;
spu_bfd_iovec_stat);
if (!nbfd)
return NULL;
- nbfd = gdb_bfd_ref (nbfd);
+ gdb_bfd_ref (nbfd);
if (!bfd_check_format (nbfd, bfd_object))
{
bfd *
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
{
- bfd *result = gdb_bfd_ref (bfd_openr (name, gnutarget));
-
+ result = bfd_openr (name, gnutarget);
if (result != NULL)
gdb_bfd_stash_filename (result);
- return result;
}
+
+ gdb_bfd_ref (result);
+ return result;
}
if (remote_filename_p (name))
{
- sym_bfd = gdb_bfd_ref (remote_bfd_open (name, gnutarget));
+ sym_bfd = remote_bfd_open (name, gnutarget);
+ gdb_bfd_ref (sym_bfd);
if (!sym_bfd)
error (_("`%s': can't open to read symbols: %s."), name,
bfd_errmsg (bfd_get_error ()));
name = absolute_name;
make_cleanup (xfree, name);
- sym_bfd = gdb_bfd_ref (bfd_fopen (name, gnutarget, FOPEN_RB, desc));
+ sym_bfd = bfd_fopen (name, gnutarget, FOPEN_RB, desc);
+ gdb_bfd_ref (sym_bfd);
if (!sym_bfd)
{
make_cleanup (xfree, name);
}
/* Open the file for loading. */
- loadfile_bfd = gdb_bfd_ref (bfd_openr (filename, gnutarget));
+ loadfile_bfd = bfd_openr (filename, gnutarget);
+ gdb_bfd_ref (loadfile_bfd);
if (loadfile_bfd == NULL)
{
perror_with_name (filename);
asection *text = NULL;
CORE_ADDR text_vma;
- abfd = gdb_bfd_ref (bfd_openr (so->so_name, "pei-i386"));
+ abfd = bfd_openr (so->so_name, "pei-i386");
+ gdb_bfd_ref (abfd);
if (!abfd)
return so;