summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2017-10-15 11:13:29 -0600
committerTom Tromey <tom@tromey.com>2017-10-20 09:01:03 -0600
commit2712ce2e659f82168154d4533f53d2963ae82571 (patch)
tree99edd1b85f5c282622f27a25a5411abeb657c7ef
parent15763a09d4aea85fc3153d6746c040dd48565637 (diff)
downloadbinutils-gdb-2712ce2e659f82168154d4533f53d2963ae82571.tar.gz
Introduce new_bfd_ref
This introduces a helper function, new_bfd_ref, that calls gdb_bfd_ref and returns a gdb_bfd_ref_ptr. Then it updates several places to use this. ChangeLog 2017-10-20 Tom Tromey <tom@tromey.com> * exec.c (exec_file_attach): Use new_bfd_ref. * symfile-mem.c (symbol_file_add_from_memory): Use new_bfd_ref. * gdb_bfd.c (gdb_bfd_open, gdb_bfd_fopen, gdb_bfd_openr) (gdb_bfd_openw, gdb_bfd_openr_iovec, gdb_bfd_fdopenr): Use new_bfd_ref. * gdb_bfd.h (new_bfd_ref): New function.
-rw-r--r--gdb/ChangeLog9
-rw-r--r--gdb/exec.c3
-rw-r--r--gdb/gdb_bfd.c31
-rw-r--r--gdb/gdb_bfd.h10
-rw-r--r--gdb/symfile-mem.c3
5 files changed, 28 insertions, 28 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index a5107f7fb65..81b70c15f7b 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,12 @@
+2017-10-20 Tom Tromey <tom@tromey.com>
+
+ * exec.c (exec_file_attach): Use new_bfd_ref.
+ * symfile-mem.c (symbol_file_add_from_memory): Use new_bfd_ref.
+ * gdb_bfd.c (gdb_bfd_open, gdb_bfd_fopen, gdb_bfd_openr)
+ (gdb_bfd_openw, gdb_bfd_openr_iovec, gdb_bfd_fdopenr): Use
+ new_bfd_ref.
+ * gdb_bfd.h (new_bfd_ref): New function.
+
2017-10-20 Pedro Alves <palves@redhat.com>
* main.c (captured_command_loop): Add attribute noinline.
diff --git a/gdb/exec.c b/gdb/exec.c
index 2fa543b7a42..326cfffe496 100644
--- a/gdb/exec.c
+++ b/gdb/exec.c
@@ -248,8 +248,7 @@ exec_file_attach (const char *filename, int from_tty)
/* First, acquire a reference to the current exec_bfd. We release
this at the end of the function; but acquiring it now lets the
BFD cache return it if this call refers to the same file. */
- gdb_bfd_ref (exec_bfd);
- gdb_bfd_ref_ptr exec_bfd_holder (exec_bfd);
+ gdb_bfd_ref_ptr exec_bfd_holder = new_bfd_ref (exec_bfd);
/* Remove any previous exec file. */
exec_close ();
diff --git a/gdb/gdb_bfd.c b/gdb/gdb_bfd.c
index 29080b852a5..5ba03c17df3 100644
--- a/gdb/gdb_bfd.c
+++ b/gdb/gdb_bfd.c
@@ -427,8 +427,7 @@ gdb_bfd_open (const char *name, const char *target, int fd)
host_address_to_string (abfd),
bfd_get_filename (abfd));
close (fd);
- gdb_bfd_ref (abfd);
- return gdb_bfd_ref_ptr (abfd);
+ return new_bfd_ref (abfd);
}
abfd = bfd_fopen (name, target, FOPEN_RB, fd);
@@ -448,8 +447,7 @@ gdb_bfd_open (const char *name, const char *target, int fd)
*slot = abfd;
}
- gdb_bfd_ref (abfd);
- return gdb_bfd_ref_ptr (abfd);
+ return new_bfd_ref (abfd);
}
/* A helper function that releases any section data attached to the
@@ -778,10 +776,7 @@ gdb_bfd_fopen (const char *filename, const char *target, const char *mode,
{
bfd *result = bfd_fopen (filename, target, mode, fd);
- if (result)
- gdb_bfd_ref (result);
-
- return gdb_bfd_ref_ptr (result);
+ return new_bfd_ref (result);
}
/* See gdb_bfd.h. */
@@ -791,10 +786,7 @@ gdb_bfd_openr (const char *filename, const char *target)
{
bfd *result = bfd_openr (filename, target);
- if (result)
- gdb_bfd_ref (result);
-
- return gdb_bfd_ref_ptr (result);
+ return new_bfd_ref (result);
}
/* See gdb_bfd.h. */
@@ -804,10 +796,7 @@ gdb_bfd_openw (const char *filename, const char *target)
{
bfd *result = bfd_openw (filename, target);
- if (result)
- gdb_bfd_ref (result);
-
- return gdb_bfd_ref_ptr (result);
+ return new_bfd_ref (result);
}
/* See gdb_bfd.h. */
@@ -832,10 +821,7 @@ gdb_bfd_openr_iovec (const char *filename, const char *target,
open_func, open_closure,
pread_func, close_func, stat_func);
- if (result)
- gdb_bfd_ref (result);
-
- return gdb_bfd_ref_ptr (result);
+ return new_bfd_ref (result);
}
/* See gdb_bfd.h. */
@@ -891,10 +877,7 @@ gdb_bfd_fdopenr (const char *filename, const char *target, int fd)
{
bfd *result = bfd_fdopenr (filename, target, fd);
- if (result)
- gdb_bfd_ref (result);
-
- return gdb_bfd_ref_ptr (result);
+ return new_bfd_ref (result);
}
diff --git a/gdb/gdb_bfd.h b/gdb/gdb_bfd.h
index a36d7821b96..b1ff857d6dc 100644
--- a/gdb/gdb_bfd.h
+++ b/gdb/gdb_bfd.h
@@ -68,6 +68,16 @@ struct gdb_bfd_ref_policy
/* A gdb::ref_ptr that has been specialized for BFD objects. */
typedef gdb::ref_ptr<struct bfd, gdb_bfd_ref_policy> gdb_bfd_ref_ptr;
+/* A helper function that calls gdb_bfd_ref and returns a
+ gdb_bfd_ref_ptr. */
+
+static inline gdb_bfd_ref_ptr
+new_bfd_ref (struct bfd *abfd)
+{
+ gdb_bfd_ref (abfd);
+ return gdb_bfd_ref_ptr (abfd);
+}
+
/* Open a read-only (FOPEN_RB) BFD given arguments like bfd_fopen.
If NAME starts with TARGET_SYSROOT_PREFIX then the BFD will be
opened using target fileio operations if necessary. Returns NULL
diff --git a/gdb/symfile-mem.c b/gdb/symfile-mem.c
index 5338bdb174e..4ce315d35e2 100644
--- a/gdb/symfile-mem.c
+++ b/gdb/symfile-mem.c
@@ -101,9 +101,8 @@ symbol_file_add_from_memory (struct bfd *templ, CORE_ADDR addr,
if (nbfd == NULL)
error (_("Failed to read a valid object file image from memory."));
- gdb_bfd_ref (nbfd);
/* Manage the new reference for the duration of this function. */
- gdb_bfd_ref_ptr nbfd_holder (nbfd);
+ gdb_bfd_ref_ptr nbfd_holder = new_bfd_ref (nbfd);
xfree (bfd_get_filename (nbfd));
if (name == NULL)