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>
+
+ * 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>
* cli/cli-dump.c (bfd_openr_with_cleanup): Use gdb_bfd_openr.
char *debugfile;
debugfile = find_separate_debug_file_by_debuglink (objfile);
+ make_cleanup (xfree, debugfile);
if (debugfile)
{
bfd *abfd = symfile_bfd_open (debugfile);
+ make_cleanup_bfd_unref (abfd);
symbol_file_add_separate (abfd, symfile_flags, objfile);
- xfree (debugfile);
}
}
if (debugfile)
{
+ struct cleanup *cleanup = make_cleanup (xfree, debugfile);
bfd *abfd = symfile_bfd_open (debugfile);
+ make_cleanup_bfd_unref (abfd);
symbol_file_add_separate (abfd, symfile_flags, objfile);
- xfree (debugfile);
+ do_cleanups (cleanup);
}
}
++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);
do_cleanups (old_cleanups);
asymbol **symp;
struct bfd_hash_table table;
int nbr_sections;
+ struct cleanup *cleanup;
/* Per section flag to mark which section have been rebased. */
unsigned char *sections_rebased;
/* We need to clear SYMFILE_MAINLINE to avoid interractive question
from symfile.c:symbol_file_add_with_addrs_or_offsets. */
+ cleanup = make_cleanup_bfd_unref (abfd);
symbol_file_add_from_bfd
(abfd, symfile_flags & ~(SYMFILE_MAINLINE | SYMFILE_VERBOSE), NULL,
main_objfile->flags & (OBJF_REORDERED | OBJF_SHARED
| OBJF_READNOW | OBJF_USERLOADED),
main_objfile);
+ do_cleanups (cleanup);
}
/* Read symbols from the vector of oso files. */
int ix;
oso_el *oso;
struct bfd_section *asect, *dsect;
+ struct cleanup *cleanup;
if (mach_o_debug_level > 0)
printf_unfiltered (_("dsym file found\n"));
}
/* Add the dsym file as a separate file. */
+ cleanup = make_cleanup_bfd_unref (dsym_bfd);
symbol_file_add_separate (dsym_bfd, symfile_flags, objfile);
+ do_cleanups (cleanup);
/* Don't try to read dwarf2 from main file or shared libraries. */
return;
/* Update the per-objfile information that comes from the bfd, ensuring
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;
+ gdb_bfd_ref (abfd);
if (abfd != NULL)
{
/* Look up the gdbarch associated with the BFD. */
gdb_bfd_unref (abfd);
return NULL;
}
- gdb_bfd_ref (vp->bfd);
obj = allocate_objfile (vp->bfd, 0);
vp->objfile = obj;
sap = build_section_addr_info_from_section_table (so->sections,
so->sections_end);
- gdb_bfd_ref (so->abfd);
so->objfile = symbol_file_add_from_bfd (so->abfd,
flags, sap, OBJF_SHARED,
NULL);
/* Open BFD representing SPE executable and read its symbols. */
nbfd = spu_bfd_open (addr);
if (nbfd)
- symbol_file_add_from_bfd (nbfd, SYMFILE_VERBOSE | SYMFILE_MAINLINE,
- NULL, 0, NULL);
+ {
+ struct cleanup *cleanup = make_cleanup_bfd_unref (nbfd);
+
+ symbol_file_add_from_bfd (nbfd, SYMFILE_VERBOSE | SYMFILE_MAINLINE,
+ NULL, 0, NULL);
+ do_cleanups (cleanup);
+ }
}
xfree (name);
}
+ cleanup = make_cleanup_bfd_unref (nbfd);
+
if (!bfd_check_format (nbfd, bfd_object))
- {
- make_cleanup_bfd_unref (nbfd);
- error (_("Got object file from memory but can't read symbols: %s."),
- bfd_errmsg (bfd_get_error ()));
- }
+ error (_("Got object file from memory but can't read symbols: %s."),
+ bfd_errmsg (bfd_get_error ()));
sai = alloc_section_addr_info (bfd_count_sections (nbfd));
- cleanup = make_cleanup (xfree, sai);
+ make_cleanup (xfree, sai);
i = 0;
for (sec = nbfd->sections; sec != NULL; sec = sec->next)
if ((bfd_get_section_flags (nbfd, sec) & (SEC_ALLOC|SEC_LOAD)) != 0)
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_unref (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,
+ 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);
+ do_cleanups (cleanup);
+ return objf;
}