* coffread.c (coff_symfile_read): Make a cleanup for 'debugfile'

and 'abfd'.
	* elfread.c (elf_symfile_read): Make a cleanup for 'debugfile'
	and 'abfd'.
	* jit.c (jit_bfd_try_read_symtab): Make a cleanup for 'nbfd'.
	* machoread.c (macho_add_oso_symfile): Make a cleanup for
	'abfd'.
	(macho_symfile_read): Make a cleanup for 'dsym_bfd'.
	* objfiles.c (allocate_objfile): Acquire a new reference.
	* rs6000-nat.c (add_vmap): Don't acquire a BFD reference.
	* solib.c (solib_read_symbols): Don't acquire a BFD reference.
	* spu-linux-nat.c (spu_symbol_file_add_from_memory): Make
	a cleanup for 'nbfd'.
	* symfile-mem.c (symbol_file_add_from_memory): Make a cleanup
	for 'nbfd'.
	* symfile.c (symbol_file_add_with_addrs_or_offsets): Don't
	make a cleanup for 'abfd'.
	(symbol_file_add): Make a BFD cleanup.
This commit is contained in:
Tom Tromey 2012-07-23 14:58:44 +00:00
parent 64c311498e
commit 8ac244b433
11 changed files with 56 additions and 20 deletions

View File

@ -1,3 +1,24 @@
2012-07-23 Tom Tromey <tromey@redhat.com>
* coffread.c (coff_symfile_read): Make a cleanup for 'debugfile'
and 'abfd'.
* elfread.c (elf_symfile_read): Make a cleanup for 'debugfile'
and 'abfd'.
* jit.c (jit_bfd_try_read_symtab): Make a cleanup for 'nbfd'.
* machoread.c (macho_add_oso_symfile): Make a cleanup for
'abfd'.
(macho_symfile_read): Make a cleanup for 'dsym_bfd'.
* objfiles.c (allocate_objfile): Acquire a new reference.
* rs6000-nat.c (add_vmap): Don't acquire a BFD reference.
* solib.c (solib_read_symbols): Don't acquire a BFD reference.
* spu-linux-nat.c (spu_symbol_file_add_from_memory): Make
a cleanup for 'nbfd'.
* symfile-mem.c (symbol_file_add_from_memory): Make a cleanup
for 'nbfd'.
* symfile.c (symbol_file_add_with_addrs_or_offsets): Don't
make a cleanup for 'abfd'.
(symbol_file_add): Make a BFD cleanup.
2012-07-23 Tom Tromey <tromey@redhat.com> 2012-07-23 Tom Tromey <tromey@redhat.com>
* cli/cli-dump.c (bfd_openr_with_cleanup): Use gdb_bfd_openr. * cli/cli-dump.c (bfd_openr_with_cleanup): Use gdb_bfd_openr.

View File

@ -653,13 +653,14 @@ coff_symfile_read (struct objfile *objfile, int symfile_flags)
char *debugfile; char *debugfile;
debugfile = find_separate_debug_file_by_debuglink (objfile); debugfile = find_separate_debug_file_by_debuglink (objfile);
make_cleanup (xfree, debugfile);
if (debugfile) if (debugfile)
{ {
bfd *abfd = symfile_bfd_open (debugfile); bfd *abfd = symfile_bfd_open (debugfile);
make_cleanup_bfd_unref (abfd);
symbol_file_add_separate (abfd, symfile_flags, objfile); symbol_file_add_separate (abfd, symfile_flags, objfile);
xfree (debugfile);
} }
} }

View File

@ -1445,10 +1445,12 @@ elf_symfile_read (struct objfile *objfile, int symfile_flags)
if (debugfile) if (debugfile)
{ {
struct cleanup *cleanup = make_cleanup (xfree, debugfile);
bfd *abfd = symfile_bfd_open (debugfile); bfd *abfd = symfile_bfd_open (debugfile);
make_cleanup_bfd_unref (abfd);
symbol_file_add_separate (abfd, symfile_flags, objfile); symbol_file_add_separate (abfd, symfile_flags, objfile);
xfree (debugfile); do_cleanups (cleanup);
} }
} }

View File

@ -896,7 +896,8 @@ JITed symbol file is not an object file, ignoring it.\n"));
++i; ++i;
} }
/* This call takes ownership of NBFD. It does not take ownership of SAI. */ /* This call does not take ownership of SAI. */
make_cleanup_bfd_unref (nbfd);
objfile = symbol_file_add_from_bfd (nbfd, 0, sai, OBJF_SHARED, NULL); objfile = symbol_file_add_from_bfd (nbfd, 0, sai, OBJF_SHARED, NULL);
do_cleanups (old_cleanups); do_cleanups (old_cleanups);

View File

@ -454,6 +454,7 @@ macho_add_oso_symfile (oso_el *oso, bfd *abfd,
asymbol **symp; asymbol **symp;
struct bfd_hash_table table; struct bfd_hash_table table;
int nbr_sections; int nbr_sections;
struct cleanup *cleanup;
/* Per section flag to mark which section have been rebased. */ /* Per section flag to mark which section have been rebased. */
unsigned char *sections_rebased; unsigned char *sections_rebased;
@ -631,11 +632,13 @@ macho_add_oso_symfile (oso_el *oso, bfd *abfd,
/* We need to clear SYMFILE_MAINLINE to avoid interractive question /* We need to clear SYMFILE_MAINLINE to avoid interractive question
from symfile.c:symbol_file_add_with_addrs_or_offsets. */ from symfile.c:symbol_file_add_with_addrs_or_offsets. */
cleanup = make_cleanup_bfd_unref (abfd);
symbol_file_add_from_bfd symbol_file_add_from_bfd
(abfd, symfile_flags & ~(SYMFILE_MAINLINE | SYMFILE_VERBOSE), NULL, (abfd, symfile_flags & ~(SYMFILE_MAINLINE | SYMFILE_VERBOSE), NULL,
main_objfile->flags & (OBJF_REORDERED | OBJF_SHARED main_objfile->flags & (OBJF_REORDERED | OBJF_SHARED
| OBJF_READNOW | OBJF_USERLOADED), | OBJF_READNOW | OBJF_USERLOADED),
main_objfile); main_objfile);
do_cleanups (cleanup);
} }
/* Read symbols from the vector of oso files. */ /* Read symbols from the vector of oso files. */
@ -897,6 +900,7 @@ macho_symfile_read (struct objfile *objfile, int symfile_flags)
int ix; int ix;
oso_el *oso; oso_el *oso;
struct bfd_section *asect, *dsect; struct bfd_section *asect, *dsect;
struct cleanup *cleanup;
if (mach_o_debug_level > 0) if (mach_o_debug_level > 0)
printf_unfiltered (_("dsym file found\n")); printf_unfiltered (_("dsym file found\n"));
@ -917,7 +921,9 @@ macho_symfile_read (struct objfile *objfile, int symfile_flags)
} }
/* Add the dsym file as a separate file. */ /* Add the dsym file as a separate file. */
cleanup = make_cleanup_bfd_unref (dsym_bfd);
symbol_file_add_separate (dsym_bfd, symfile_flags, objfile); symbol_file_add_separate (dsym_bfd, symfile_flags, objfile);
do_cleanups (cleanup);
/* Don't try to read dwarf2 from main file or shared libraries. */ /* Don't try to read dwarf2 from main file or shared libraries. */
return; return;

View File

@ -194,9 +194,10 @@ allocate_objfile (bfd *abfd, int flags)
/* Update the per-objfile information that comes from the bfd, ensuring /* Update the per-objfile information that comes from the bfd, ensuring
that any data that is reference is saved in the per-objfile data that any data that is reference is saved in the per-objfile data
region. Note that we steal a reference to ABFD. */ region. */
objfile->obfd = abfd; objfile->obfd = abfd;
gdb_bfd_ref (abfd);
if (abfd != NULL) if (abfd != NULL)
{ {
/* Look up the gdbarch associated with the BFD. */ /* Look up the gdbarch associated with the BFD. */

View File

@ -798,7 +798,6 @@ add_vmap (LdInfo *ldi)
gdb_bfd_unref (abfd); gdb_bfd_unref (abfd);
return NULL; return NULL;
} }
gdb_bfd_ref (vp->bfd);
obj = allocate_objfile (vp->bfd, 0); obj = allocate_objfile (vp->bfd, 0);
vp->objfile = obj; vp->objfile = obj;

View File

@ -610,7 +610,6 @@ solib_read_symbols (struct so_list *so, int flags)
sap = build_section_addr_info_from_section_table (so->sections, sap = build_section_addr_info_from_section_table (so->sections,
so->sections_end); so->sections_end);
gdb_bfd_ref (so->abfd);
so->objfile = symbol_file_add_from_bfd (so->abfd, so->objfile = symbol_file_add_from_bfd (so->abfd,
flags, sap, OBJF_SHARED, flags, sap, OBJF_SHARED,
NULL); NULL);

View File

@ -374,8 +374,13 @@ spu_symbol_file_add_from_memory (int inferior_fd)
/* Open BFD representing SPE executable and read its symbols. */ /* Open BFD representing SPE executable and read its symbols. */
nbfd = spu_bfd_open (addr); nbfd = spu_bfd_open (addr);
if (nbfd) if (nbfd)
{
struct cleanup *cleanup = make_cleanup_bfd_unref (nbfd);
symbol_file_add_from_bfd (nbfd, SYMFILE_VERBOSE | SYMFILE_MAINLINE, symbol_file_add_from_bfd (nbfd, SYMFILE_VERBOSE | SYMFILE_MAINLINE,
NULL, 0, NULL); NULL, 0, NULL);
do_cleanups (cleanup);
}
} }

View File

@ -111,15 +111,14 @@ symbol_file_add_from_memory (struct bfd *templ, CORE_ADDR addr, char *name,
xfree (name); xfree (name);
} }
cleanup = make_cleanup_bfd_unref (nbfd);
if (!bfd_check_format (nbfd, bfd_object)) if (!bfd_check_format (nbfd, bfd_object))
{
make_cleanup_bfd_unref (nbfd);
error (_("Got object file from memory but can't read symbols: %s."), error (_("Got object file from memory but can't read symbols: %s."),
bfd_errmsg (bfd_get_error ())); bfd_errmsg (bfd_get_error ()));
}
sai = alloc_section_addr_info (bfd_count_sections (nbfd)); sai = alloc_section_addr_info (bfd_count_sections (nbfd));
cleanup = make_cleanup (xfree, sai); make_cleanup (xfree, sai);
i = 0; i = 0;
for (sec = nbfd->sections; sec != NULL; sec = sec->next) for (sec = nbfd->sections; sec != NULL; sec = sec->next)
if ((bfd_get_section_flags (nbfd, sec) & (SEC_ALLOC|SEC_LOAD)) != 0) if ((bfd_get_section_flags (nbfd, sec) & (SEC_ALLOC|SEC_LOAD)) != 0)

View File

@ -1037,7 +1037,7 @@ new_symfile_objfile (struct objfile *objfile, int add_flags)
loaded file. loaded file.
ABFD is a BFD already open on the file, as from symfile_bfd_open. 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 ADD_FLAGS encodes verbosity, whether this is main symbol file or
extra, such as dynamically loaded code, and what to do with breakpoins. extra, such as dynamically loaded code, and what to do with breakpoins.
@ -1061,7 +1061,6 @@ symbol_file_add_with_addrs_or_offsets (bfd *abfd,
int flags, struct objfile *parent) int flags, struct objfile *parent)
{ {
struct objfile *objfile; struct objfile *objfile;
struct cleanup *my_cleanups;
const char *name = bfd_get_filename (abfd); const char *name = bfd_get_filename (abfd);
const int from_tty = add_flags & SYMFILE_VERBOSE; const int from_tty = add_flags & SYMFILE_VERBOSE;
const int mainline = add_flags & SYMFILE_MAINLINE; const int mainline = add_flags & SYMFILE_MAINLINE;
@ -1075,8 +1074,6 @@ symbol_file_add_with_addrs_or_offsets (bfd *abfd,
add_flags &= ~SYMFILE_NO_READ; add_flags &= ~SYMFILE_NO_READ;
} }
my_cleanups = make_cleanup_bfd_unref (abfd);
/* Give user a chance to burp if we'd be /* Give user a chance to burp if we'd be
interactively wiping out any existing symbols. */ interactively wiping out any existing symbols. */
@ -1087,7 +1084,6 @@ symbol_file_add_with_addrs_or_offsets (bfd *abfd,
error (_("Not confirmed.")); error (_("Not confirmed."));
objfile = allocate_objfile (abfd, flags | (mainline ? OBJF_MAINLINE : 0)); objfile = allocate_objfile (abfd, flags | (mainline ? OBJF_MAINLINE : 0));
discard_cleanups (my_cleanups);
if (parent) if (parent)
add_separate_debug_objfile (objfile, parent); add_separate_debug_objfile (objfile, parent);
@ -1208,8 +1204,14 @@ struct objfile *
symbol_file_add (char *name, int add_flags, struct section_addr_info *addrs, symbol_file_add (char *name, int add_flags, struct section_addr_info *addrs,
int flags) int flags)
{ {
return symbol_file_add_from_bfd (symfile_bfd_open (name), add_flags, addrs, bfd *bfd = symfile_bfd_open (name);
struct cleanup *cleanup = make_cleanup_bfd_unref (bfd);
struct objfile *objf;
objf = symbol_file_add_from_bfd (symfile_bfd_open (name), add_flags, addrs,
flags, NULL); flags, NULL);
do_cleanups (cleanup);
return objf;
} }