gdb: New maintenance command to disable bfd sharing.
authorAndrew Burgess <andrew.burgess@embecosm.com>
Mon, 13 Apr 2015 15:31:21 +0000 (16:31 +0100)
committerAndrew Burgess <andrew.burgess@embecosm.com>
Tue, 18 Aug 2015 13:03:14 +0000 (14:03 +0100)
In some rare maintainer cases it is desirable to be able to disable bfd
sharing.  This patch adds new commands maintenance set/show commands for
bfd-sharing, allowing gdb's bfd cache to be turned off.

gdb/ChangeLog:

* gdb_bfd.c (bfd_sharing): New variable.
(show_bfd_sharing): New function.
(gdb_bfd_open): Check bfd_sharing variable.
(_initialize_gdb_bfd): Add new set/show command.
* NEWS: Mention new command.

gdb/doc/ChangeLog:

* gdb.texinfo (Maintenance Commands): Move documentation of "main
info bfds" to...
(File Caching): A New section.  Outline bfd caching, and add new
description for "main set/show bfd-sharing".

gdb/ChangeLog
gdb/NEWS
gdb/doc/ChangeLog
gdb/doc/gdb.texinfo
gdb/gdb_bfd.c

index 8967bc571ac76efc1d9e7b465f5609f633f4ed9f..b2860488e22be1fbd743caa23bd82b7ffc0166f8 100644 (file)
@@ -1,3 +1,11 @@
+2015-08-18  Andrew Burgess  <andrew.burgess@embecosm.com>
+
+       * gdb_bfd.c (bfd_sharing): New variable.
+       (show_bfd_sharing): New function.
+       (gdb_bfd_open): Check bfd_sharing variable.
+       (_initialize_gdb_bfd): Add new set/show command.
+       * NEWS: Mention new command.
+
 2015-08-18  Andrew Burgess  <andrew.burgess@embecosm.com>
 
        * gdb_bfd.c (struct gdb_bfd_data): Add size, inode, and device id
index 174924f119d6ab229f56ede517b57f549f29c44f..7a24e234429b65f61c11898292e326443c14d004 100644 (file)
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -20,6 +20,10 @@ maint show target-non-stop
   "set non-stop" is "off".  The default is "auto", meaning non-stop
   mode is enabled if supported by the target.
 
+maint set bfd-sharing
+maint show bfd-sharing
+  Control the reuse of bfd objects.
+
 * The "disassemble" command accepts a new modifier: /s.
   It prints mixed source+disassembly like /m with two differences:
   - disassembled instructions are now printed in program order, and
index 806dac4b4f3c0453ad4c5f208897f8a3596c8363..7716917d7d6f2f7dd63d994903d5978d6cb05431 100644 (file)
@@ -1,3 +1,10 @@
+2015-08-18  Andrew Burgess  <andrew.burgess@embecosm.com>
+
+       * gdb.texinfo (Maintenance Commands): Move documentation of "main
+       info bfds" to...
+       (File Caching): A New section.  Outline bfd caching, and add new
+       description for "main set/show bfd-sharing".
+
 2015-08-14  Doug Evans  <xdje42@gmail.com>
 
        * gdb.texinfo (Machine Code): Update docs for mixed source/assembly
index c876ed6266d2d44e3d048fb5ee8a42db783154a5..bd6b8e4a428a3c5ad5aedbfaee28f70724480cc0 100644 (file)
@@ -18343,6 +18343,36 @@ Set whether a source file may have multiple base names.
 Show whether a source file may have multiple base names.
 @end table
 
+@node File Caching
+@section File Caching
+@cindex caching of opened files
+@cindex caching of bfd objects
+
+To speed up file loading, and reduce memory usage, @value{GDBN} will
+reuse the @code{bfd} objects used to track open files.  @xref{Top, ,
+BFD, bfd, The Binary File Descriptor Library}.  The following commands
+allow visibility and control of the caching behavior.
+
+@table @code
+@kindex maint info bfds
+@item maint info bfds
+This prints information about each @code{bfd} object that is known to
+@value{GDBN}.
+
+@kindex maint set bfd-sharing
+@kindex maint show bfd-sharing
+@kindex bfd caching
+@item maint set bfd-sharing
+@item maint show bfd-sharing
+Control whether @code{bfd} objects can be shared.  When sharing is
+enabled @value{GDBN} reuses already open @code{bfd} objects rather
+than reopening the same file.  Turning sharing off does not cause
+already shared @code{bfd} objects to be unshared, but all future files
+that are opened will create a new @code{bfd} object.  Similarly,
+re-enabling sharing does not cause multiple existing @code{bfd}
+objects to be collapsed into a single shared @code{bfd} object.
+@end table
+
 @node Separate Debug Files
 @section Debugging Information in Separate Files
 @cindex separate debugging information files
@@ -34162,11 +34192,6 @@ Shared library events.
 
 @end table
 
-@kindex maint info bfds
-@item maint info bfds
-This prints information about each @code{bfd} object that is known to
-@value{GDBN}.  @xref{Top, , BFD, bfd, The Binary File Descriptor Library}.
-
 @kindex maint info btrace
 @item maint info btrace
 Pint information about raw branch tracing data.
index ee2953117b330705d3fe1c0259e16aa42e4745d7..847177524c2932e40b67707cd6742c903a94e144 100644 (file)
@@ -111,6 +111,17 @@ DEFINE_REGISTRY (bfd, GDB_BFD_DATA_ACCESSOR)
 
 static htab_t gdb_bfd_cache;
 
+/* When true gdb will reuse an existing bfd object if the filename,
+   modification time, and file size all match.  */
+
+static int bfd_sharing = 1;
+static void
+show_bfd_sharing  (struct ui_file *file, int from_tty,
+                  struct cmd_list_element *c, const char *value)
+{
+  fprintf_filtered (file, _("BFD sharing is %s.\n"), value);
+}
+
 /* The type of an object being looked up in gdb_bfd_cache.  We use
    htab's capability of storing one kind of object (BFD in this case)
    and using a different sort of object for searching.  */
@@ -394,7 +405,7 @@ gdb_bfd_open (const char *name, const char *target, int fd)
      opening the BFD may fail; and this would violate hashtab
      invariants.  */
   abfd = htab_find_with_hash (gdb_bfd_cache, &search, hash);
-  if (abfd != NULL)
+  if (bfd_sharing && abfd != NULL)
     {
       close (fd);
       gdb_bfd_ref (abfd);
@@ -405,9 +416,12 @@ gdb_bfd_open (const char *name, const char *target, int fd)
   if (abfd == NULL)
     return NULL;
 
-  slot = htab_find_slot_with_hash (gdb_bfd_cache, &search, hash, INSERT);
-  gdb_assert (!*slot);
-  *slot = abfd;
+  if (bfd_sharing)
+    {
+      slot = htab_find_slot_with_hash (gdb_bfd_cache, &search, hash, INSERT);
+      gdb_assert (!*slot);
+      *slot = abfd;
+    }
 
   gdb_bfd_ref (abfd);
   return abfd;
@@ -942,4 +956,16 @@ _initialize_gdb_bfd (void)
   add_cmd ("bfds", class_maintenance, maintenance_info_bfds, _("\
 List the BFDs that are currently open."),
           &maintenanceinfolist);
+
+  add_setshow_boolean_cmd ("bfd-sharing", no_class,
+                          &bfd_sharing, _("\
+Set whether gdb will share bfds that appear to be the same file."), _("\
+Show whether gdb will share bfds that appear to be the same file."), _("\
+When enabled gdb will reuse existing bfds rather than reopening the\n\
+same file.  To decide if two files are the same then gdb compares the\n\
+filename, file size, file modification time, and file inode."),
+                          NULL,
+                          &show_bfd_sharing,
+                          &maintenance_set_cmdlist,
+                          &maintenance_show_cmdlist);
 }
This page took 0.053717 seconds and 4 git commands to generate.