[2/3] gdb: New maintenance command to disable bfd sharing.
Commit Message
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(-)
Comments
> 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.
@@ -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.
@@ -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.
@@ -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;
}