gdb_bfd_stash_filename. (load_command): Open the new BFD before freeing the old. (bfd_open_maybe_remote): Call gdb_bfd_stash_filename. * symfile-mem.c (symbol_file_add_from_memory): Don't copy name. Call gdb_bfd_stash_filename. * spu-linux-nat.c (spu_bfd_open): Don't copy name. * solib-spu.c (spu_bfd_fopen): Don't copy name. Call gdb_bfd_stash_filename. * solib-darwin.c (darwin_solib_get_all_image_info_addr_at_init): Free found_pathname. * rs6000-nat.c (add_vmap): Don't copy filename. Call gdb_bfd_stash_filename. * remote.c (remote_bfd_open): Call gdb_bfd_stash_filename. * machoread.c (macho_add_oso_symfile): Call gdb_bfd_stash_filename. (macho_symfile_read_all_oso): Arrange to free archive_name. Call gdb_bfd_stash_filename. (macho_check_dsym): Don't copy filename. Call gdb_bfd_stash_filename. * jit.c (bfd_open_from_target_memory): Don't copy the filename. * gdb_bfd.c (gdb_bfd_stash_filename): New function. * gdb_bfd.h (gdb_bfd_stash_filename): Declare. * gcore.c (create_gcore_bfd): Call gdb_bfd_stash_filename. * exec.c (exec_close): Don't free the BFD's filename. (exec_file_attach): Don't copy the filename. Call gdb_bfd_stash_filename. * corelow.c (core_close): Don't free the BFD's filename. (core_open): Call gdb_bfd_stash_filename. * corefile.c (reopen_exec_file): Remove #if 0 code. * solib.c (solib_bfd_fopen): Call gdb_bfd_stash_filename. Free pathname. * dwarf2read.c (try_open_dwo_file): Call gdb_bfd_stash_filename.
107 lines
2.2 KiB
C
107 lines
2.2 KiB
C
/* Definitions for BFD wrappers used by GDB.
|
|
|
|
Copyright (C) 2011
|
|
Free Software Foundation, Inc.
|
|
|
|
This file is part of GDB.
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
|
|
#include "defs.h"
|
|
#include "gdb_bfd.h"
|
|
#include "gdb_assert.h"
|
|
#include "gdb_string.h"
|
|
|
|
/* See gdb_bfd.h. */
|
|
|
|
void
|
|
gdb_bfd_stash_filename (struct bfd *abfd)
|
|
{
|
|
char *name = bfd_get_filename (abfd);
|
|
char *data;
|
|
|
|
data = bfd_alloc (abfd, strlen (name) + 1);
|
|
strcpy (data, name);
|
|
|
|
/* Unwarranted chumminess with BFD. */
|
|
abfd->filename = data;
|
|
}
|
|
|
|
/* Close ABFD, and warn if that fails. */
|
|
|
|
static int
|
|
gdb_bfd_close_or_warn (struct bfd *abfd)
|
|
{
|
|
int ret;
|
|
char *name = bfd_get_filename (abfd);
|
|
|
|
ret = bfd_close (abfd);
|
|
|
|
if (!ret)
|
|
warning (_("cannot close \"%s\": %s"),
|
|
name, bfd_errmsg (bfd_get_error ()));
|
|
|
|
return ret;
|
|
}
|
|
|
|
/* Add reference to ABFD. Returns ABFD. */
|
|
|
|
struct bfd *
|
|
gdb_bfd_ref (struct bfd *abfd)
|
|
{
|
|
int *p_refcount;
|
|
|
|
if (abfd == NULL)
|
|
return NULL;
|
|
|
|
p_refcount = bfd_usrdata (abfd);
|
|
|
|
if (p_refcount != NULL)
|
|
{
|
|
*p_refcount += 1;
|
|
return abfd;
|
|
}
|
|
|
|
p_refcount = xmalloc (sizeof (*p_refcount));
|
|
*p_refcount = 1;
|
|
bfd_usrdata (abfd) = p_refcount;
|
|
|
|
return abfd;
|
|
}
|
|
|
|
/* Unreference and possibly close ABFD. */
|
|
|
|
void
|
|
gdb_bfd_unref (struct bfd *abfd)
|
|
{
|
|
int *p_refcount;
|
|
char *name;
|
|
|
|
if (abfd == NULL)
|
|
return;
|
|
|
|
p_refcount = bfd_usrdata (abfd);
|
|
gdb_assert (*p_refcount >= 1);
|
|
|
|
*p_refcount -= 1;
|
|
if (*p_refcount > 0)
|
|
return;
|
|
|
|
xfree (p_refcount);
|
|
bfd_usrdata (abfd) = NULL; /* Paranoia. */
|
|
|
|
name = bfd_get_filename (abfd);
|
|
gdb_bfd_close_or_warn (abfd);
|
|
}
|