From patchwork Sat Sep 15 22:24:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 29399 Received: (qmail 36246 invoked by alias); 15 Sep 2018 22:24:48 -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 35914 invoked by uid 89); 15 Sep 2018 22:24:30 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-24.6 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_RP_RNBL, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=relocate, UD:next, FALSE X-HELO: gateway20.websitewelcome.com Received: from gateway20.websitewelcome.com (HELO gateway20.websitewelcome.com) (192.185.63.14) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 15 Sep 2018 22:24:25 +0000 Received: from cm17.websitewelcome.com (cm17.websitewelcome.com [100.42.49.20]) by gateway20.websitewelcome.com (Postfix) with ESMTP id 4A2D7400D4550 for ; Sat, 15 Sep 2018 17:24:14 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id 1Iz8gqrFOPvAd1Iz8gkx5I; Sat, 15 Sep 2018 17:24:14 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=BAIFUnCNkZqudy9n6wFvKRXpDU/JYKcaNgWLxBBNYsU=; b=kFo4nL7e2YEUSQ9tlcpHY8F2Ux HcOmhv/n+v/n1n9rOlxEy72EouK3Ty6QDDvJ89FvU7iO4Mj/JEnyqq+UlpZr8dMD44piEuh43fT4t mjvTPRlIB3aGa6HXH/9qgzPIL; Received: from 97-122-190-66.hlrn.qwest.net ([97.122.190.66]:44280 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1g1Iz8-000qVN-2F; Sat, 15 Sep 2018 17:24:14 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 2/2] Remove remaining cleanups from compile-object-load.c Date: Sat, 15 Sep 2018 16:24:11 -0600 Message-Id: <20180915222411.24764-3-tom@tromey.com> In-Reply-To: <20180915222411.24764-1-tom@tromey.com> References: <20180915222411.24764-1-tom@tromey.com> This removes the remaining cleanups from compile-object-load.c. gdb/ChangeLog 2018-09-15 Tom Tromey * compile/compile-object-load.c (struct link_hash_table_cleanup_data): Add constructor and destructor. Use DISABLE_COPY_AND_ASSIGN. (~link_hash_table_cleanup_data): Rename from link_hash_table_free. Now a destructor. (copy_sections): Use gdb::unique_xmalloc_ptr. Remove cleanups. --- gdb/ChangeLog | 9 ++++++ gdb/compile/compile-object-load.c | 51 +++++++++++++++---------------- 2 files changed, 34 insertions(+), 26 deletions(-) diff --git a/gdb/compile/compile-object-load.c b/gdb/compile/compile-object-load.c index db792792327..d1982cf51d4 100644 --- a/gdb/compile/compile-object-load.c +++ b/gdb/compile/compile-object-load.c @@ -282,22 +282,26 @@ static const struct bfd_link_callbacks link_callbacks = struct link_hash_table_cleanup_data { - bfd *abfd; - bfd *link_next; -}; + explicit link_hash_table_cleanup_data (bfd *abfd_) + : abfd (abfd_), + link_next (abfd->link.next) + { + } -/* Cleanup callback for struct bfd_link_info. */ + ~link_hash_table_cleanup_data () + { + if (abfd->is_linker_output) + (*abfd->link.hash->hash_table_free) (abfd); + abfd->link.next = link_next; + } -static void -link_hash_table_free (void *d) -{ - struct link_hash_table_cleanup_data *data - = (struct link_hash_table_cleanup_data *) d; + DISABLE_COPY_AND_ASSIGN (link_hash_table_cleanup_data); - if (data->abfd->is_linker_output) - (*data->abfd->link.hash->hash_table_free) (data->abfd); - data->abfd->link.next = data->link_next; -} +private: + + bfd *abfd; + bfd *link_next; +}; /* Relocate and store into inferior memory each section SECT of ABFD. */ @@ -305,12 +309,10 @@ static void copy_sections (bfd *abfd, asection *sect, void *data) { asymbol **symbol_table = (asymbol **) data; - bfd_byte *sect_data, *sect_data_got; - struct cleanup *cleanups; + bfd_byte *sect_data_got; struct bfd_link_info link_info; struct bfd_link_order link_order; CORE_ADDR inferior_addr; - struct link_hash_table_cleanup_data cleanup_data; if ((bfd_get_section_flags (abfd, sect) & (SEC_ALLOC | SEC_LOAD)) != (SEC_ALLOC | SEC_LOAD)) @@ -326,13 +328,11 @@ copy_sections (bfd *abfd, asection *sect, void *data) link_info.input_bfds = abfd; link_info.input_bfds_tail = &abfd->link.next; - cleanup_data.abfd = abfd; - cleanup_data.link_next = abfd->link.next; + struct link_hash_table_cleanup_data cleanup_data (abfd); abfd->link.next = NULL; link_info.hash = bfd_link_hash_table_create (abfd); - cleanups = make_cleanup (link_hash_table_free, &cleanup_data); link_info.callbacks = &link_callbacks; memset (&link_order, 0, sizeof (link_order)); @@ -342,21 +342,22 @@ copy_sections (bfd *abfd, asection *sect, void *data) link_order.size = bfd_get_section_size (sect); link_order.u.indirect.section = sect; - sect_data = (bfd_byte *) xmalloc (bfd_get_section_size (sect)); - make_cleanup (xfree, sect_data); + gdb::unique_xmalloc_ptr sect_data + ((bfd_byte *) xmalloc (bfd_get_section_size (sect))); sect_data_got = bfd_get_relocated_section_contents (abfd, &link_info, - &link_order, sect_data, + &link_order, + sect_data.get (), FALSE, symbol_table); if (sect_data_got == NULL) error (_("Cannot map compiled module \"%s\" section \"%s\": %s"), bfd_get_filename (abfd), bfd_get_section_name (abfd, sect), bfd_errmsg (bfd_get_error ())); - gdb_assert (sect_data_got == sect_data); + gdb_assert (sect_data_got == sect_data.get ()); inferior_addr = bfd_get_section_vma (abfd, sect); - if (0 != target_write_memory (inferior_addr, sect_data, + if (0 != target_write_memory (inferior_addr, sect_data.get (), bfd_get_section_size (sect))) error (_("Cannot write compiled module \"%s\" section \"%s\" " "to inferior memory range %s-%s."), @@ -364,8 +365,6 @@ copy_sections (bfd *abfd, asection *sect, void *data) paddress (target_gdbarch (), inferior_addr), paddress (target_gdbarch (), inferior_addr + bfd_get_section_size (sect))); - - do_cleanups (cleanups); } /* Fetch the type of COMPILE_I_EXPR_PTR_TYPE and COMPILE_I_EXPR_VAL