From patchwork Fri May 11 21:49:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 27251 Received: (qmail 85600 invoked by alias); 11 May 2018 21:49:38 -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 85577 invoked by uid 89); 11 May 2018 21:49:34 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=counting, UD:release X-HELO: gateway31.websitewelcome.com Received: from gateway31.websitewelcome.com (HELO gateway31.websitewelcome.com) (192.185.143.38) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 11 May 2018 21:49:32 +0000 Received: from cm14.websitewelcome.com (cm14.websitewelcome.com [100.42.49.7]) by gateway31.websitewelcome.com (Postfix) with ESMTP id 8C8A529C01 for ; Fri, 11 May 2018 16:49:31 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id HFutfSSbZ5CKDHFutfxTOm; Fri, 11 May 2018 16:49:31 -0500 X-Authority-Reason: nr=8 Received: from 97-122-176-117.hlrn.qwest.net ([97.122.176.117]:33504 helo=pokyo.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89_1) (envelope-from ) id 1fHFut-001SsM-AL; Fri, 11 May 2018 16:49:31 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA] Make "cbfd" a gdb_bfd_ref_ptr Date: Fri, 11 May 2018 15:49:24 -0600 Message-Id: <20180511214924.26576-1-tom@tromey.com> X-BWhitelist: no X-Source-L: No X-Exim-ID: 1fHFut-001SsM-AL X-Source-Sender: 97-122-176-117.hlrn.qwest.net (pokyo.Home) [97.122.176.117]:33504 X-Source-Auth: tom+tromey.com X-Email-Count: 1 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes This changes program_space::cbfd to be a gdb_bfd_ref_ptr. This makes it somewhat less error-prone to use, because now it manages the reference counting automatically. Tested by the buildbot. 2018-05-11 Tom Tromey * gdbcore.h (core_bfd): Redefine. * corelow.c (core_target::close): Update. (core_target_open): Update. * progspace.h (struct program_space) : Now a gdb_bfd_ref_ptr. --- gdb/ChangeLog | 8 ++++++++ gdb/corelow.c | 5 ++--- gdb/gdbcore.h | 2 +- gdb/progspace.h | 3 ++- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index a3a133c036..08e26fc21d 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,11 @@ +2018-05-11 Tom Tromey + + * gdbcore.h (core_bfd): Redefine. + * corelow.c (core_target::close): Update. + (core_target_open): Update. + * progspace.h (struct program_space) : Now a + gdb_bfd_ref_ptr. + 2018-05-11 Max Filippov * configure.tgt (xtensa*-*-linux*): Drop gdb_target definition. diff --git a/gdb/corelow.c b/gdb/corelow.c index 439fe1338a..c6175279da 100644 --- a/gdb/corelow.c +++ b/gdb/corelow.c @@ -270,8 +270,7 @@ core_target::close () comments in clear_solib in solib.c. */ clear_solib (); - gdb_bfd_unref (core_bfd); - core_bfd = NULL; + current_program_space->cbfd.reset (nullptr); } /* Core targets are heap-allocated (see core_target_open), so here @@ -406,7 +405,7 @@ core_target_open (const char *arg, int from_tty) filename.get (), bfd_errmsg (bfd_get_error ())); } - core_bfd = temp_bfd.release (); + current_program_space->cbfd = std::move (temp_bfd); core_target *target = new core_target (); diff --git a/gdb/gdbcore.h b/gdb/gdbcore.h index 04a4b4767a..18ba0d7226 100644 --- a/gdb/gdbcore.h +++ b/gdb/gdbcore.h @@ -133,7 +133,7 @@ extern void specify_exec_file_hook (void (*hook) (const char *filename)); /* Binary File Diddler for the core file. */ -#define core_bfd (current_program_space->cbfd) +#define core_bfd (current_program_space->cbfd.get ()) /* Whether to open exec and core files read-only or read-write. */ diff --git a/gdb/progspace.h b/gdb/progspace.h index 835fcfdd5d..456911b29b 100644 --- a/gdb/progspace.h +++ b/gdb/progspace.h @@ -23,6 +23,7 @@ #include "target.h" #include "vec.h" +#include "gdb_bfd.h" #include "gdb_vecs.h" #include "registry.h" @@ -158,7 +159,7 @@ struct program_space char *pspace_exec_filename = NULL; /* Binary file diddling handle for the core file. */ - bfd *cbfd = NULL; + gdb_bfd_ref_ptr cbfd; /* The address space attached to this program space. More than one program space may be bound to the same address space. In the