diff options
author | Paul Pluzhnikov <ppluzhnikov@google.com> | 2009-08-04 18:46:05 +0000 |
---|---|---|
committer | Paul Pluzhnikov <ppluzhnikov@google.com> | 2009-08-04 18:46:05 +0000 |
commit | e3c69974ac166b09a48d5b0a971cf4833d293b90 (patch) | |
tree | 78801fae838b5f4b950e8d1632178b030f4f0b62 /gdb/objfiles.c | |
parent | afd0cd3fc15852600db10b246ff5ed1dbb48fc66 (diff) | |
download | gdb-e3c69974ac166b09a48d5b0a971cf4833d293b90.zip gdb-e3c69974ac166b09a48d5b0a971cf4833d293b90.tar.gz gdb-e3c69974ac166b09a48d5b0a971cf4833d293b90.tar.bz2 |
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.c | 43 |
1 files changed, 33 insertions, 10 deletions
diff --git a/gdb/objfiles.c b/gdb/objfiles.c index c983b11..43c5174 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); +} |