summaryrefslogtreecommitdiff
path: root/gdb/objfiles.c
diff options
context:
space:
mode:
authorPaul Pluzhnikov <ppluzhnikov@google.com>2009-08-04 18:46:03 +0000
committerPaul Pluzhnikov <ppluzhnikov@google.com>2009-08-04 18:46:03 +0000
commitb9cd7676d0e4aba49b2d3882c2e1481866e9b015 (patch)
tree92f41266d6904555e37e079e153b8b1abd72d8e4 /gdb/objfiles.c
parent2c60e316fafcedd7528db769b9e9b7a3841986e3 (diff)
downloadgdb-b9cd7676d0e4aba49b2d3882c2e1481866e9b015.tar.gz
2009-08-04 Paul Pluzhnikov <ppluzhnikov@google.com>
* objfiles.h (OBJF_KEEPBFD): Delete. (gdb_bfd_unref): New prototype. * objfiles.c (gdb_bfd_unref): New function. (free_objfile): Call gdb_bfd_unref. * solib.c (free_so): Likewise. (symbol_add_stub): Set refcount.
Diffstat (limited to 'gdb/objfiles.c')
-rw-r--r--gdb/objfiles.c43
1 files changed, 33 insertions, 10 deletions
diff --git a/gdb/objfiles.c b/gdb/objfiles.c
index c983b116135..43c5174518e 100644
--- a/gdb/objfiles.c
+++ b/gdb/objfiles.c
@@ -452,16 +452,7 @@ free_objfile (struct objfile *objfile)
/* Discard any data modules have associated with the objfile. */
objfile_free_data (objfile);
- /* We always close the bfd, unless the OBJF_KEEPBFD flag is set. */
-
- if (objfile->obfd != NULL && !(objfile->flags & OBJF_KEEPBFD))
- {
- char *name = bfd_get_filename (objfile->obfd);
- if (!bfd_close (objfile->obfd))
- warning (_("cannot close \"%s\": %s"),
- name, bfd_errmsg (bfd_get_error ()));
- xfree (name);
- }
+ gdb_bfd_unref (objfile->obfd);
/* Remove it from the chain of all objfiles. */
@@ -1020,3 +1011,35 @@ objfiles_changed (void)
{
objfiles_changed_p = 1; /* Rebuild section map next time we need it. */
}
+
+/* Unreference and possibly close abfd. */
+void
+gdb_bfd_unref (struct bfd *abfd)
+{
+ int *p_refcount;
+ char *name;
+
+ if (abfd == NULL)
+ return;
+
+ p_refcount = abfd->usrdata;
+
+ /* Valid range for p_refcount: NULL (single owner), or a pointer
+ to int counter, which has a value of 1 (single owner) or 2 (shared). */
+ gdb_assert (p_refcount == NULL || *p_refcount == 1 || *p_refcount == 2);
+
+ if (p_refcount != NULL)
+ {
+ *p_refcount -= 1;
+ if (*p_refcount > 0)
+ return;
+ }
+ xfree (p_refcount);
+ abfd->usrdata = NULL; /* Paranoia. */
+
+ name = bfd_get_filename (abfd);
+ if (!bfd_close (abfd))
+ warning (_("cannot close \"%s\": %s"),
+ name, bfd_errmsg (bfd_get_error ()));
+ xfree (name);
+}