[3/3] gdb: Add debug tracing for bfd cache activity.
Commit Message
This patch adds a new debug flag bfd-cache, which when set to non-zero
produces debugging log messages relating to gdb's bfd cache.
OK to apply?
Thanks,
Andrew
gdb/ChangeLog:
* gdb_bfd.c (debug_bfd_cache): New variable.
(gdb_bfd_open): Add debug logging.
(gdb_bfd_ref): Likewise.
(gdb_bfd_unref): Likewise.
(_initialize_gdb_bfd): Add new set/show command.
* NEWS: Mention new command.
---
gdb/ChangeLog | 9 +++++++++
gdb/NEWS | 4 ++++
gdb/gdb_bfd.c | 45 ++++++++++++++++++++++++++++++++++++++++++++-
3 files changed, 57 insertions(+), 1 deletion(-)
Comments
> From: Andrew Burgess <andrew.burgess@embecosm.com>
> Cc: Andrew Burgess <andrew.burgess@embecosm.com>
> Date: Mon, 13 Apr 2015 18:30:09 +0100
>
> This patch adds a new debug flag bfd-cache, which when set to non-zero
> produces debugging log messages relating to gdb's bfd cache.
>
> OK to apply?
The new command should be in gdb.texinfo as well. Otherwise OK,
thanks.
@@ -1,5 +1,14 @@
2015-04-13 Andrew Burgess <andrew.burgess@embecosm.com>
+ * gdb_bfd.c (debug_bfd_cache): New variable.
+ (gdb_bfd_open): Add debug logging.
+ (gdb_bfd_ref): Likewise.
+ (gdb_bfd_unref): Likewise.
+ (_initialize_gdb_bfd): Add new set/show command.
+ * NEWS: Mention new command.
+
+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.
@@ -55,6 +55,10 @@ record bts
* New options
+set debug bfd-cache
+show debug bfd-cache
+ Control display of debugging info regarding bfd caching.
+
set max-completions
show max-completions
Set the maximum number of candidates to be considered during
@@ -109,6 +109,10 @@ static htab_t gdb_bfd_cache;
static int bfd_sharing;
+/* When non-zero debugging of the bfd caches is enabled. */
+
+static unsigned int debug_bfd_cache;
+
/* 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. */
@@ -396,6 +400,11 @@ gdb_bfd_open (const char *name, const char *target, int fd)
abfd = htab_find_with_hash (gdb_bfd_cache, &search, hash);
if (bfd_sharing && abfd != NULL)
{
+ if (debug_bfd_cache)
+ fprintf_unfiltered (gdb_stdlog,
+ "Reusing cached bfd %s for %s\n",
+ host_address_to_string (abfd),
+ bfd_get_filename (abfd));
close (fd);
gdb_bfd_ref (abfd);
return abfd;
@@ -405,6 +414,12 @@ gdb_bfd_open (const char *name, const char *target, int fd)
if (abfd == NULL)
return NULL;
+ if (debug_bfd_cache)
+ fprintf_unfiltered (gdb_stdlog,
+ "Creating new bfd %s for %s\n",
+ host_address_to_string (abfd),
+ bfd_get_filename (abfd));
+
if (bfd_sharing)
{
slot = htab_find_slot_with_hash (gdb_bfd_cache, &search, hash, INSERT);
@@ -472,6 +487,12 @@ gdb_bfd_ref (struct bfd *abfd)
gdata = bfd_usrdata (abfd);
+ if (debug_bfd_cache)
+ fprintf_unfiltered (gdb_stdlog,
+ "Increase reference count on bfd %s (%s)\n",
+ host_address_to_string (abfd),
+ bfd_get_filename (abfd));
+
if (gdata != NULL)
{
gdata->refc += 1;
@@ -514,7 +535,20 @@ gdb_bfd_unref (struct bfd *abfd)
gdata->refc -= 1;
if (gdata->refc > 0)
- return;
+ {
+ if (debug_bfd_cache)
+ fprintf_unfiltered (gdb_stdlog,
+ "Decrease reference count on bfd %s (%s)\n",
+ host_address_to_string (abfd),
+ bfd_get_filename (abfd));
+ return;
+ }
+
+ if (debug_bfd_cache)
+ fprintf_unfiltered (gdb_stdlog,
+ "Delete final reference count on bfd %s (%s)\n",
+ host_address_to_string (abfd),
+ bfd_get_filename (abfd));
archive_bfd = gdata->archive_bfd;
search.filename = bfd_get_filename (abfd);
@@ -944,4 +978,13 @@ disc has changed."),
&maintenance_set_cmdlist,
&maintenance_show_cmdlist);
bfd_sharing = 1;
+
+ add_setshow_zuinteger_cmd ("bfd-cache", class_maintenance,
+ &debug_bfd_cache, _("\
+Set bfd cache debugging."), _("\
+Show bfd cache debugging."), _("\
+When non-zero, bfd cache specific debugging is enabled."),
+ NULL,
+ NULL,
+ &setdebuglist, &showdebuglist);
}