make "file" use the BFD cache better
authorTom Tromey <tromey@redhat.com>
Thu, 17 Oct 2013 18:03:06 +0000 (12:03 -0600)
committerTom Tromey <tromey@redhat.com>
Wed, 26 Feb 2014 19:11:18 +0000 (12:11 -0700)
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.

gdb/ChangeLog
gdb/exec.c

index f5df2f2724c48f9f7f5f8d7e655d1c65b7f0b952..71723e9a5b3cf4c08559c982da2f6039ad322f72 100644 (file)
@@ -1,3 +1,7 @@
+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
index 44dddc1ef5618c78cafc71dac3beee0c4bdfcb0b..908858ec8839d292279232a243e6563479eba176 100644 (file)
@@ -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 ();
 }
This page took 0.050985 seconds and 4 git commands to generate.