From patchwork Fri Oct 20 04:18:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 23721 Received: (qmail 51622 invoked by alias); 20 Oct 2017 04:18:27 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 51439 invoked by uid 89); 20 Oct 2017 04:18:27 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=H*MI:sk:2017102 X-HELO: gproxy4-pub.mail.unifiedlayer.com Received: from gproxy4-pub.mail.unifiedlayer.com (HELO gproxy4-pub.mail.unifiedlayer.com) (69.89.23.142) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 20 Oct 2017 04:18:25 +0000 Received: from CMOut01 (unknown [10.0.90.82]) by gproxy4.mail.unifiedlayer.com (Postfix) with ESMTP id 3909F175D47 for ; Thu, 19 Oct 2017 22:18:24 -0600 (MDT) Received: from box522.bluehost.com ([74.220.219.122]) by CMOut01 with id PgJM1w0062f2jeq01gJQqd; Thu, 19 Oct 2017 22:18:24 -0600 X-Authority-Analysis: v=2.2 cv=K4VSJ2eI c=1 sm=1 tr=0 a=GsOEXm/OWkKvwdLVJsfwcA==:117 a=GsOEXm/OWkKvwdLVJsfwcA==:17 a=02M-m0pO-4AA:10 a=zstS-IiYAAAA:8 a=C-__pKnv_h5MfOYM_ssA:9 a=4G6NA9xxw8l3yy4pmD5M:22 Received: from 71-218-90-63.hlrn.qwest.net ([71.218.90.63]:60108 helo=bapiya.localdomain) by box522.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.87) (envelope-from ) id 1e5OlI-004ECG-T7; Thu, 19 Oct 2017 22:18:20 -0600 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA v2 1/3] Introduce new_bfd_ref Date: Thu, 19 Oct 2017 22:18:13 -0600 Message-Id: <20171020041815.20291-2-tom@tromey.com> In-Reply-To: <20171020041815.20291-1-tom@tromey.com> References: <20171020041815.20291-1-tom@tromey.com> X-BWhitelist: no X-Exim-ID: 1e5OlI-004ECG-T7 X-Source-Sender: 71-218-90-63.hlrn.qwest.net (bapiya.localdomain) [71.218.90.63]:60108 X-Source-Auth: tom+tromey.com X-Email-Count: 2 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTIyLmJsdWVob3N0LmNvbQ== X-Local-Domain: yes 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-19 Tom Tromey * 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. --- gdb/ChangeLog | 9 +++++++++ gdb/exec.c | 3 +-- gdb/gdb_bfd.c | 31 +++++++------------------------ gdb/gdb_bfd.h | 10 ++++++++++ gdb/symfile-mem.c | 3 +-- 5 files changed, 28 insertions(+), 28 deletions(-) diff --git a/gdb/exec.c b/gdb/exec.c index 2fa543b7a4..326cfffe49 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 29080b852a..5ba03c17df 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 a36d7821b9..b1ff857d6d 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 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 5338bdb174..4ce315d35e 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)