Patchwork [2/3] gdb: New maintenance command to disable bfd sharing.

login
register
mail settings
Submitter Andrew Burgess
Date April 13, 2015, 5:30 p.m.
Message ID <f20bee016bff03711d3d8962606aabad1fee4a67.1428941320.git.andrew.burgess@embecosm.com>
Download mbox | patch
Permalink /patch/6187/
State New
Headers show

Comments

Andrew Burgess - April 13, 2015, 5:30 p.m.
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.

OK to apply?

Thanks,
Andrew

gdb/ChangeLog:

	* gdb_bfd.c (bfd_sharing): New variable.
	(gdb_bfd_open): Check bfd_sharing variable.
	(_initialize_gdb_bfd): Add new set/show command.
	* NEWS: Mention new command.
---
 gdb/ChangeLog |  7 +++++++
 gdb/NEWS      |  4 ++++
 gdb/gdb_bfd.c | 29 +++++++++++++++++++++++++----
 3 files changed, 36 insertions(+), 4 deletions(-)
Eli Zaretskii - April 13, 2015, 8:14 p.m.
> From: Andrew Burgess <andrew.burgess@embecosm.com>
> Cc: Andrew Burgess <andrew.burgess@embecosm.com>
> Date: Mon, 13 Apr 2015 18:30:08 +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.
> 
> OK to apply?

The documentation parts are okay, although...

> +  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."), _("\
> +Tells gdb whether to share bfds that appear to be the same file.  The\n\
> +modification time and file size are used to determine if a file on\n\
> +disc has changed."),

...there appears to be some redundancy in the doc string here.

Also, the new command should be in gdb.texinfo as well.

Thanks.

Patch

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index d79d8e3..291c1be 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,12 @@ 
 2015-04-13  Andrew Burgess  <andrew.burgess@embecosm.com>
 
+	* gdb_bfd.c (bfd_sharing): New variable.
+	(gdb_bfd_open): Check bfd_sharing variable.
+	(_initialize_gdb_bfd): Add new set/show command.
+	* NEWS: Mention new command.
+
+2015-04-13  Andrew Burgess  <andrew.burgess@embecosm.com>
+
 	* gdb_bfd.c (struct gdb_bfd_data): Add size field.
 	(struct gdb_bfd_cache_search): Likewise.
 	(eq_bfd): Compare the size fields.
diff --git a/gdb/NEWS b/gdb/NEWS
index c24195e..673aca4 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -62,6 +62,10 @@  show max-completions
   to avoid generating large completion lists, the computation of
   which can cause the debugger to become temporarily unresponsive.
 
+maint set bfd-sharing
+maint show bfd-sharing
+  Control the reuse of bfd objects.
+
 maint set symbol-cache-size
 maint show symbol-cache-size
   Control the size of the symbol cache.
diff --git a/gdb/gdb_bfd.c b/gdb/gdb_bfd.c
index 35c068f..48838cc 100644
--- a/gdb/gdb_bfd.c
+++ b/gdb/gdb_bfd.c
@@ -104,6 +104,11 @@  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;
+
 /* 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.  */
@@ -389,7 +394,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);
@@ -400,9 +405,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;
@@ -923,4 +931,17 @@  _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."), _("\
+Tells gdb whether to share bfds that appear to be the same file.  The\n\
+modification time and file size are used to determine if a file on\n\
+disc has changed."),
+			   NULL,
+			   NULL,
+			   &maintenance_set_cmdlist,
+			   &maintenance_show_cmdlist);
+  bfd_sharing = 1;
 }