Patchwork [3/3] gdb: Add debug tracing for bfd cache activity.

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

Comments

Andrew Burgess - April 13, 2015, 5:30 p.m.
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(-)
Eli Zaretskii - April 13, 2015, 8:15 p.m.
> 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.

Patch

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 291c1be..16af460 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -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.
diff --git a/gdb/NEWS b/gdb/NEWS
index 673aca4..07017ec 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -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
diff --git a/gdb/gdb_bfd.c b/gdb/gdb_bfd.c
index 48838cc..ba4f74f 100644
--- a/gdb/gdb_bfd.c
+++ b/gdb/gdb_bfd.c
@@ -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);
 }