1 /* Definitions for BFD wrappers used by GDB.
4 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 #include "gdb_assert.h"
25 /* Close ABFD, and warn if that fails. */
28 gdb_bfd_close_or_warn (struct bfd *abfd)
31 char *name = bfd_get_filename (abfd);
33 ret = bfd_close (abfd);
36 warning (_("cannot close \"%s\": %s"),
37 name, bfd_errmsg (bfd_get_error ()));
42 /* Add reference to ABFD. Returns ABFD. */
45 gdb_bfd_ref (struct bfd *abfd)
52 p_refcount = bfd_usrdata (abfd);
54 if (p_refcount != NULL)
60 p_refcount = xmalloc (sizeof (*p_refcount));
62 bfd_usrdata (abfd) = p_refcount;
67 /* Unreference and possibly close ABFD. */
70 gdb_bfd_unref (struct bfd *abfd)
78 p_refcount = bfd_usrdata (abfd);
79 gdb_assert (*p_refcount >= 1);
86 bfd_usrdata (abfd) = NULL; /* Paranoia. */
88 name = bfd_get_filename (abfd);
89 gdb_bfd_close_or_warn (abfd);