+2014-02-26 Tom Tromey <tromey@redhat.com>
+
+ * exec.c (exec_file_attach): Hold a reference to exec_bfd.
+
2014-02-26 Tom Tromey <tromey@redhat.com>
* elfread.c (elf_read_minimal_symbols): Return early if
void
exec_file_attach (char *filename, int from_tty)
{
+ struct cleanup *cleanups;
+
+ /* First, acquire a reference to the current exec_bfd. We release
+ this at the end of the function; but acquiring it now lets the
+ BFD cache return it if this call refers to the same file. */
+ gdb_bfd_ref (exec_bfd);
+ cleanups = make_cleanup_bfd_unref (exec_bfd);
+
/* Remove any previous exec file. */
exec_close ();
}
else
{
- struct cleanup *cleanups;
char *scratch_pathname, *canonical_pathname;
int scratch_chan;
struct target_section *sections = NULL, *sections_end = NULL;
if (scratch_chan < 0)
perror_with_name (filename);
- cleanups = make_cleanup (xfree, scratch_pathname);
+ make_cleanup (xfree, scratch_pathname);
/* gdb_bfd_open (and its variants) prefers canonicalized pathname for
better BFD caching. */
/* Tell display code (if any) about the changed file name. */
if (deprecated_exec_file_display_hook)
(*deprecated_exec_file_display_hook) (filename);
-
- do_cleanups (cleanups);
}
+
+ do_cleanups (cleanups);
+
bfd_cache_close_all ();
observer_notify_executable_changed ();
}