From: Andrew Burgess <andrew.burgess@embecosm.com>
To: gdb-patches@sourceware.org
Cc: Andrew Burgess <andrew.burgess@embecosm.com>
Subject: [PATCH v2 3/3] gdb: Add debug tracing for bfd cache activity.
Date: Thu, 13 Aug 2015 12:45:00 -0000 [thread overview]
Message-ID: <20978b0a40cbc4fd2a82039f2a36463cb7c6cb83.1439454670.git.andrew.burgess@embecosm.com> (raw)
In-Reply-To: <cover.1439454669.git.andrew.burgess@embecosm.com>
In-Reply-To: <cover.1439454669.git.andrew.burgess@embecosm.com>
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(-)
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);
}
--
2.4.0
next prev parent reply other threads:[~2015-08-13 12:45 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-13 12:45 [PATCH v2 0/3] bfd cache: tighten match criteria and debug commands Andrew Burgess
2015-08-13 12:45 ` [PATCH v2 2/3] gdb: New maintenance command to disable bfd sharing Andrew Burgess
2015-08-13 14:24 ` Eli Zaretskii
2015-08-17 17:34 ` Pedro Alves
2015-08-13 12:45 ` [PATCH v2 1/3] gdb: Improve cache matching criteria for the bfd cache Andrew Burgess
2015-08-17 17:34 ` Pedro Alves
2015-08-13 12:45 ` Andrew Burgess [this message]
2015-08-17 17:34 ` [PATCH v2 3/3] gdb: Add debug tracing for bfd cache activity Pedro Alves
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20978b0a40cbc4fd2a82039f2a36463cb7c6cb83.1439454670.git.andrew.burgess@embecosm.com \
--to=andrew.burgess@embecosm.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox