gdb: Add debug tracing for bfd cache activity.
authorAndrew Burgess <andrew.burgess@embecosm.com>
Mon, 13 Apr 2015 15:56:23 +0000 (16:56 +0100)
committerAndrew Burgess <andrew.burgess@embecosm.com>
Tue, 18 Aug 2015 13:03:14 +0000 (14:03 +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.

gdb/ChangeLog:

* gdb_bfd.c (debug_bfd_cache): New variable.
(show_bfd_cache_debug): New function.
(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/ChangeLog:

* gdb.texinfo (File Caching): Document "set/show debug bfd-cache".

gdb/ChangeLog
gdb/NEWS
gdb/doc/ChangeLog
gdb/doc/gdb.texinfo
gdb/gdb_bfd.c

index b2860488e22be1fbd743caa23bd82b7ffc0166f8..51bae8702e863cf062ad3a2c685873ca3e51c363 100644 (file)
@@ -1,3 +1,13 @@
+2015-08-18  Andrew Burgess  <andrew.burgess@embecosm.com>
+
+       * gdb_bfd.c (debug_bfd_cache): New variable.
+       (show_bfd_cache_debug): New function.
+       (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-18  Andrew Burgess  <andrew.burgess@embecosm.com>
 
        * gdb_bfd.c (bfd_sharing): New variable.
index 7a24e234429b65f61c11898292e326443c14d004..2cedccd336b3db7761a457f05a7b42daca963565 100644 (file)
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -24,6 +24,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.
+
 * The "disassemble" command accepts a new modifier: /s.
   It prints mixed source+disassembly like /m with two differences:
   - disassembled instructions are now printed in program order, and
index 7716917d7d6f2f7dd63d994903d5978d6cb05431..b3dbc5955c0dbd3244a42fef621e645329969cf1 100644 (file)
@@ -1,3 +1,7 @@
+2015-08-18  Andrew Burgess  <andrew.burgess@embecosm.com>
+
+       * gdb.texinfo (File Caching): Document "set/show debug bfd-cache".
+
 2015-08-18  Andrew Burgess  <andrew.burgess@embecosm.com>
 
        * gdb.texinfo (Maintenance Commands): Move documentation of "main
index bd6b8e4a428a3c5ad5aedbfaee28f70724480cc0..9322a526d104462a9a5a272480b42f92d02bd193 100644 (file)
@@ -18371,6 +18371,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 does 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
index 847177524c2932e40b67707cd6742c903a94e144..eb53766fd7bcd9bb5ef5eff58051e12156c5d902 100644 (file)
@@ -122,6 +122,16 @@ show_bfd_sharing  (struct ui_file *file, int from_tty,
   fprintf_filtered (file, _("BFD sharing is %s.\n"), value);
 }
 
+/* When non-zero debugging of the bfd caches is enabled.  */
+
+static unsigned int debug_bfd_cache;
+static void
+show_bfd_cache_debug (struct ui_file *file, int from_tty,
+                     struct cmd_list_element *c, const char *value)
+{
+  fprintf_filtered (file, _("BFD cache debugging is %s.\n"), value);
+}
+
 /* 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.  */
@@ -407,6 +417,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;
@@ -416,6 +431,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);
@@ -484,6 +505,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;
@@ -537,7 +564,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);
@@ -968,4 +1008,13 @@ filename, file size, file modification time, and file inode."),
                           &show_bfd_sharing,
                           &maintenance_set_cmdlist,
                           &maintenance_show_cmdlist);
+
+  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,
+                            &show_bfd_cache_debug,
+                            &setdebuglist, &showdebuglist);
 }
This page took 0.057994 seconds and 4 git commands to generate.