[PATCH 4/9] give a registry to BFD
Tom Tromey
tromey@redhat.com
Mon Jul 30 15:21:00 GMT 2012
This patch gives a registry to BFD, by attaching it to the BFD
user-data field that gdb claims. Nothing uses this yet, that is done
in a later patch.
* gdb_bfd.h: Include registry.h. Use DECLARE_REGISTRY.
* gdb_bfd.c: Use DEFINE_REGISTRY.
(struct gdb_bfd_data): Add REGISTRY_FIELDS.
(gdb_bfd_ref): Call bfd_alloc_data.
(gdb_bfd_unref): Call bfd_free_data.
---
gdb/gdb_bfd.c | 11 +++++++++++
gdb/gdb_bfd.h | 4 ++++
2 files changed, 15 insertions(+), 0 deletions(-)
diff --git a/gdb/gdb_bfd.c b/gdb/gdb_bfd.c
index 40e1c4d..879c29c 100644
--- a/gdb/gdb_bfd.c
+++ b/gdb/gdb_bfd.c
@@ -81,8 +81,16 @@ struct gdb_bfd_data
/* The mtime of the BFD at the point the cache entry was made. */
time_t mtime;
+
+ /* The registry. */
+ REGISTRY_FIELDS;
};
+#define GDB_BFD_DATA_ACCESSOR(ABFD) \
+ ((struct gdb_bfd_data *) bfd_usrdata (ABFD))
+
+DEFINE_REGISTRY (bfd, GDB_BFD_DATA_ACCESSOR)
+
/* A hash table storing all the BFDs maintained in the cache. */
static htab_t gdb_bfd_cache;
@@ -251,6 +259,8 @@ gdb_bfd_ref (struct bfd *abfd)
gdata->mtime = bfd_get_mtime (abfd);
bfd_usrdata (abfd) = gdata;
+ bfd_alloc_data (abfd);
+
/* 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);
@@ -291,6 +301,7 @@ gdb_bfd_unref (struct bfd *abfd)
htab_clear_slot (gdb_bfd_cache, slot);
}
+ bfd_free_data (abfd);
bfd_usrdata (abfd) = NULL; /* Paranoia. */
htab_remove_elt (all_bfds, abfd);
diff --git a/gdb/gdb_bfd.h b/gdb/gdb_bfd.h
index f131ba7..5fd361c 100644
--- a/gdb/gdb_bfd.h
+++ b/gdb/gdb_bfd.h
@@ -21,6 +21,10 @@
#ifndef GDB_BFD_H
#define GDB_BFD_H
+#include "registry.h"
+
+DECLARE_REGISTRY (bfd);
+
/* Make a copy ABFD's filename using bfd_alloc, and reassign it to the
BFD. This ensures that the BFD's filename has the same lifetime as
the BFD itself. */
--
1.7.7.6
More information about the Gdb-patches
mailing list