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

Message ID 20978b0a40cbc4fd2a82039f2a36463cb7c6cb83.1439454670.git.andrew.burgess@embecosm.com
State New, archived
Headers

Commit Message

Andrew Burgess Aug. 13, 2015, 12:45 p.m. UTC
  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.

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/doc/ChngeLog:

	* gdb.texinfo (File Caching): Document "set/show debug bfd-cache".
---
 gdb/ChangeLog       |  9 +++++++++
 gdb/NEWS            |  4 ++++
 gdb/doc/ChangeLog   |  4 ++++
 gdb/doc/gdb.texinfo | 10 ++++++++++
 gdb/gdb_bfd.c       | 45 ++++++++++++++++++++++++++++++++++++++++++++-
 5 files changed, 71 insertions(+), 1 deletion(-)
  

Comments

Pedro Alves Aug. 17, 2015, 5:34 p.m. UTC | #1
On 08/13/2015 01:45 PM, Andrew Burgess wrote:

> gdb/doc/ChngeLog:

( typo on commit log )

> +  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,

Add show hook, for i18n.

Otherwise LGTM.

Thanks,
Pedro Alves
  

Patch

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 0f73f08..3ef6d0e 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,14 @@ 
 2015-08-11  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-08-11  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 87fc14e..2451ac3 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -20,6 +20,10 @@  maint set bfd-sharing
 maint show bfd-sharing
   Control the reuse of bfd objects.
 
+set debug bfd-cache
+show debug bfd-cache
+  Control display of debugging info regarding bfd caching.
+
 *** Changes in GDB 7.10
 
 * Support for process record-replay and reverse debugging on aarch64*-linux*
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index 9d553db..2fe1dd9 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,5 +1,9 @@ 
 2015-08-11  Andrew Burgess  <andrew.burgess@embecosm.com>
 
+	* gdb.texinfo (File Caching): Document "set/show debug bfd-cache".
+
+2015-08-11  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
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 3cfb1a7..0a7ced4 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -18218,6 +18218,16 @@  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 will not cause multiple existing @code{bfd}
 objects to be collapsed into a single shared @code{bfd} object.
+
+@kindex set debug bfd-cache @var{level}
+@kindex bfd caching
+@item set debug bfd-cache @var{level}
+Turns on debugging of the bfd cache, setting the level to @var{level}.
+
+@kindex show debug bfd-cache
+@kindex bfd caching
+@item show debug bfd-cache
+Show the current debugging level of the bfd cache.
 @end table
 
 @node Separate Debug Files
diff --git a/gdb/gdb_bfd.c b/gdb/gdb_bfd.c
index 14fdf43..e252999 100644
--- a/gdb/gdb_bfd.c
+++ b/gdb/gdb_bfd.c
@@ -116,6 +116,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.  */
@@ -401,6 +405,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;
@@ -410,6 +419,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);
@@ -478,6 +493,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;
@@ -531,7 +552,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);
@@ -963,4 +997,13 @@  filename, file size, file modification time, and file inode."),
 			   &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);
 }