summaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorTom Tromey <tromey@redhat.com>2013-10-17 12:03:06 -0600
committerTom Tromey <tromey@redhat.com>2014-02-26 12:11:18 -0700
commit9b333ba3405066be10f4fc1c497b7fb1a7cafd53 (patch)
treee7b0d723883d105815fbd2c81ecbb25b22858b8b /gdb
parent5f6cac4085c95c5339b9549dc06d4f9184184fa6 (diff)
downloadbinutils-gdb-9b333ba3405066be10f4fc1c497b7fb1a7cafd53.tar.gz
make "file" use the BFD cache better
Right now the "file" command will discard the exec_bfd and then possibly open a new one. If this ends up reopening the same file, it can cause needless work by gdb -- destroying all the per-BFD data just to re-read it again. This patch changes the code to hold a reference to the old exec_bfd while opening the new one. The possible downside of this is a higher peak memory use. 2014-02-26 Tom Tromey <tromey@redhat.com> * exec.c (exec_file_attach): Hold a reference to exec_bfd.
Diffstat (limited to 'gdb')
-rw-r--r--gdb/ChangeLog4
-rw-r--r--gdb/exec.c16
2 files changed, 16 insertions, 4 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index f5df2f2724c..71723e9a5b3 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,9 @@
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
minimal symbols have already been read. Add "ei" parameter.
(elf_symfile_read): Call elf_read_minimal_symbols earlier.
diff --git a/gdb/exec.c b/gdb/exec.c
index 44dddc1ef56..908858ec883 100644
--- a/gdb/exec.c
+++ b/gdb/exec.c
@@ -168,6 +168,14 @@ exec_file_clear (int from_tty)
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 ();
@@ -182,7 +190,6 @@ exec_file_attach (char *filename, int from_tty)
}
else
{
- struct cleanup *cleanups;
char *scratch_pathname, *canonical_pathname;
int scratch_chan;
struct target_section *sections = NULL, *sections_end = NULL;
@@ -205,7 +212,7 @@ exec_file_attach (char *filename, int from_tty)
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. */
@@ -261,9 +268,10 @@ exec_file_attach (char *filename, int from_tty)
/* 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 ();
}