From: Tom Tromey <tromey@redhat.com>
To: Jan Kratochvil <jan.kratochvil@redhat.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH 01/10] change gdb to refcount bfd everywhere
Date: Tue, 24 Jul 2012 19:52:00 -0000 [thread overview]
Message-ID: <87eho1ndi4.fsf@fleche.redhat.com> (raw)
In-Reply-To: <20120724131720.GB24427@host2.jankratochvil.net> (Jan Kratochvil's message of "Tue, 24 Jul 2012 15:17:20 +0200")
>>>>> "Jan" == Jan Kratochvil <jan.kratochvil@redhat.com> writes:
Jan> I think there should be 'maint info bfds' now when you even already
Jan> track bfds in gdb_bfd_cache, otherwise it may be difficult to track
Jan> down all such leaks. (Maybe it was obvious.)
It wasn't obvious to me -- nice idea.
Here's a patch. It needs a doc review.
Tom
* NEWS: Mention maint info bfd.
* gdb_bfd.c (all_bfds): New global.
(gdb_bfd_ref, gdb_bfd_unref): Update all_bfds.
(print_one_bfd, maintenance_info_bfd, _initialize_gdb_bfd):
New functions.
* gdb.texinfo (Maintenance Commands): Document maint info bfd.
---
gdb/NEWS | 5 +++
gdb/doc/gdb.texinfo | 5 +++
gdb/gdb_bfd.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 83 insertions(+), 0 deletions(-)
diff --git a/gdb/NEWS b/gdb/NEWS
index 3333810..91415e2 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -3,6 +3,11 @@
*** Changes since GDB 7.5
+* New commands (for set/show, see "New options" below)
+
+maint info bfd
+ List the BFDs known to GDB.
+
*** Changes in GDB 7.5
* GDB now supports x32 ABI. Visit <http://sites.google.com/site/x32abi/>
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 68ea817..e08838e 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -34536,6 +34536,11 @@ Shared library events.
@end table
+@kindex maint info bfd
+@item maint info bfd
+This prints information about each @code{bfd} object that is known to
+@value{GDBN}.
+
@kindex set displaced-stepping
@kindex show displaced-stepping
@cindex displaced stepping support
diff --git a/gdb/gdb_bfd.c b/gdb/gdb_bfd.c
index aa222b9..c0470ba 100644
--- a/gdb/gdb_bfd.c
+++ b/gdb/gdb_bfd.c
@@ -22,6 +22,8 @@
#include "gdb_bfd.h"
#include "gdb_assert.h"
#include "gdb_string.h"
+#include "ui-out.h"
+#include "gdbcmd.h"
#include "hashtab.h"
#ifdef HAVE_ZLIB_H
#include <zlib.h>
@@ -48,6 +50,13 @@ struct gdb_bfd_section_data
void *map_addr;
};
+/* A hash table holding every BFD that gdb knows about. This is not
+ to be confused with 'gdb_bfd_cache', which is used for sharing
+ BFDs; in contrast, this hash is used just to implement
+ "maint info bfd". */
+
+static htab_t all_bfds;
+
/* See gdb_bfd.h. */
void
@@ -224,6 +233,7 @@ void
gdb_bfd_ref (struct bfd *abfd)
{
struct gdb_bfd_data *gdata;
+ void **slot;
if (abfd == NULL)
return;
@@ -240,6 +250,11 @@ gdb_bfd_ref (struct bfd *abfd)
gdata->refc = 1;
gdata->mtime = bfd_get_mtime (abfd);
bfd_usrdata (abfd) = gdata;
+
+ /* This is the first we've seen it, so add it to the hash table. */
+ slot = htab_find_slot (all_bfds, abfd, INSERT);
+ gdb_assert (slot && !*slot);
+ *slot = abfd;
}
/* See gdb_bfd.h. */
@@ -249,6 +264,7 @@ gdb_bfd_unref (struct bfd *abfd)
{
struct gdb_bfd_data *gdata;
struct gdb_bfd_cache_search search;
+ void **slot;
if (abfd == NULL)
return;
@@ -277,6 +293,8 @@ gdb_bfd_unref (struct bfd *abfd)
bfd_usrdata (abfd) = NULL; /* Paranoia. */
+ htab_remove_elt (all_bfds, abfd);
+
gdb_bfd_close_or_warn (abfd);
}
@@ -595,3 +613,58 @@ gdb_bfd_fdopenr (const char *filename, const char *target, int fd)
return result;
}
+
+\f
+
+/* A callback for htab_traverse that prints a single BFD. */
+
+static int
+print_one_bfd (void **slot, void *data)
+{
+ bfd *abfd = *slot;
+ struct gdb_bfd_data *gdata = bfd_usrdata (abfd);
+ struct ui_out *uiout = data;
+ struct cleanup *inner;
+
+ inner = make_cleanup_ui_out_tuple_begin_end (uiout, NULL);
+ ui_out_field_int (uiout, "refcount", gdata->refc);
+ ui_out_field_string (uiout, "addr", host_address_to_string (abfd));
+ ui_out_field_string (uiout, "filename", bfd_get_filename (abfd));
+ ui_out_text (uiout, "\n");
+ do_cleanups (inner);
+
+ return 1;
+}
+
+/* Implement the 'maint info bfd' command. */
+
+static void
+maintenance_info_bfd (char *arg, int from_tty)
+{
+ struct cleanup *cleanup;
+ struct ui_out *uiout = current_uiout;
+
+ cleanup = make_cleanup_ui_out_table_begin_end (uiout, 3, -1, "bfds");
+ ui_out_table_header (uiout, 10, ui_left, "refcount", "Refcount");
+ ui_out_table_header (uiout, 10, ui_left, "addr", "Address");
+ ui_out_table_header (uiout, 40, ui_left, "filename", "Filename");
+
+ ui_out_table_body (uiout);
+ htab_traverse (all_bfds, print_one_bfd, uiout);
+
+ do_cleanups (cleanup);
+}
+
+/* -Wmissing-prototypes */
+extern initialize_file_ftype _initialize_gdb_bfd;
+
+void
+_initialize_gdb_bfd (void)
+{
+ all_bfds = htab_create_alloc (10, htab_hash_pointer, htab_eq_pointer,
+ NULL, xcalloc, xfree);
+
+ add_cmd ("bfd", class_maintenance, maintenance_info_bfd, _("\
+List the BFDs that are currently open."),
+ &maintenanceinfolist);
+}
--
1.7.7.6
next prev parent reply other threads:[~2012-07-24 19:52 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-18 19:32 Tom Tromey
2012-07-19 14:18 ` Jan Kratochvil
2012-07-19 20:58 ` Tom Tromey
2012-07-20 16:37 ` Tom Tromey
2012-07-20 18:11 ` Jan Kratochvil
2012-07-20 16:37 ` Tom Tromey
2012-07-23 8:54 ` Jan Kratochvil
2012-07-23 9:06 ` Jan Kratochvil
2012-07-23 15:23 ` Tom Tromey
2012-07-23 15:25 ` Tom Tromey
2012-07-24 13:17 ` Jan Kratochvil
2012-07-24 19:52 ` Tom Tromey [this message]
2012-07-24 20:27 ` Eli Zaretskii
2012-07-25 14:25 ` Tom Tromey
2012-07-25 14:29 ` Jan Kratochvil
2012-07-25 14:52 ` Tom Tromey
2012-07-25 14:55 ` Jan Kratochvil
2012-07-25 15:44 ` Tom Tromey
2012-07-25 15:37 ` Eli Zaretskii
2012-07-25 11:57 ` Jan Kratochvil
2012-07-23 14:52 ` Tom Tromey
2012-07-23 18:54 ` Tom Tromey
2012-07-23 19:02 ` Jan Kratochvil
2012-07-23 19:08 ` Tom Tromey
2012-07-22 19:00 ` Jan Kratochvil
2012-07-23 14:49 ` Tom Tromey
2012-07-23 15:01 ` Tom Tromey
2012-07-23 15:03 ` Tom Tromey
2012-07-20 16:31 ` Tom Tromey
2012-07-20 18:10 ` Jan Kratochvil
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=87eho1ndi4.fsf@fleche.redhat.com \
--to=tromey@redhat.com \
--cc=gdb-patches@sourceware.org \
--cc=jan.kratochvil@redhat.com \
/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