From patchwork Wed May 16 23:32:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 27309 Received: (qmail 26762 invoked by alias); 16 May 2018 23:32:14 -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 26747 invoked by uid 89); 16 May 2018 23:32:13 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.7 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=dwarf2readc, dwarf2read.c, UD:dwarf2read.c, management X-HELO: gateway21.websitewelcome.com Received: from gateway21.websitewelcome.com (HELO gateway21.websitewelcome.com) (192.185.45.38) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 16 May 2018 23:32:11 +0000 Received: from cm13.websitewelcome.com (cm13.websitewelcome.com [100.42.49.6]) by gateway21.websitewelcome.com (Postfix) with ESMTP id E316A400D5E56 for ; Wed, 16 May 2018 18:32:09 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id J5txfo3L9QUwqJ5txfV7cV; Wed, 16 May 2018 18:32:09 -0500 X-Authority-Reason: nr=8 Received: from 174-29-44-154.hlrn.qwest.net ([174.29.44.154]:59250 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89_1) (envelope-from ) id 1fJ5tx-004H2q-K3; Wed, 16 May 2018 18:32:09 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA] Allocate dwz_file with new Date: Wed, 16 May 2018 17:32:05 -0600 Message-Id: <20180516233205.22139-1-tom@tromey.com> X-BWhitelist: no X-Source-L: No X-Exim-ID: 1fJ5tx-004H2q-K3 X-Source-Sender: 174-29-44-154.hlrn.qwest.net (bapiya.Home) [174.29.44.154]:59250 X-Source-Auth: tom+tromey.com X-Email-Count: 1 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes This adds a constructor to struct dwz_file and arranges for it to be allocated with "new" and wrapped in a unique_ptr. This cuts down on the amount of manual memory management that must be done. Regression tested by the buildbot. gdb/ChangeLog 2018-05-16 Tom Tromey * dwarf2read.c (struct dwz_file): Add constructor, initializers. : Now a gdb_bfd_ref_ptr. (~dwarf2_per_objfile): Update (dwarf2_get_dwz_file): Use new. * dwarf2read.h (struct dwarf2_per_objfile) : Now a unique_ptr. --- gdb/ChangeLog | 9 +++++++++ gdb/dwarf2read.c | 42 ++++++++++++++++++++++-------------------- gdb/dwarf2read.h | 2 +- 3 files changed, 32 insertions(+), 21 deletions(-) diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index 575d316cdd..227ff71aa5 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -842,17 +842,22 @@ struct dwp_file struct dwz_file { + dwz_file (gdb_bfd_ref_ptr &&bfd) + : dwz_bfd (std::move (bfd)) + { + } + /* A dwz file can only contain a few sections. */ - struct dwarf2_section_info abbrev; - struct dwarf2_section_info info; - struct dwarf2_section_info str; - struct dwarf2_section_info line; - struct dwarf2_section_info macro; - struct dwarf2_section_info gdb_index; - struct dwarf2_section_info debug_names; + struct dwarf2_section_info abbrev {}; + struct dwarf2_section_info info {}; + struct dwarf2_section_info str {}; + struct dwarf2_section_info line {}; + struct dwarf2_section_info macro {}; + struct dwarf2_section_info gdb_index {}; + struct dwarf2_section_info debug_names {}; /* The dwz's BFD. */ - bfd *dwz_bfd; + gdb_bfd_ref_ptr dwz_bfd; }; /* Struct used to pass misc. parameters to read_die_and_children, et @@ -2150,9 +2155,6 @@ dwarf2_per_objfile::~dwarf2_per_objfile () if (dwp_file != NULL) gdb_bfd_unref (dwp_file->dbfd); - if (dwz_file != NULL && dwz_file->dwz_bfd) - gdb_bfd_unref (dwz_file->dwz_bfd); - if (index_table != NULL) index_table->~mapped_index (); @@ -2641,13 +2643,12 @@ static struct dwz_file * dwarf2_get_dwz_file (struct dwarf2_per_objfile *dwarf2_per_objfile) { const char *filename; - struct dwz_file *result; bfd_size_type buildid_len_arg; size_t buildid_len; bfd_byte *buildid; if (dwarf2_per_objfile->dwz_file != NULL) - return dwarf2_per_objfile->dwz_file; + return dwarf2_per_objfile->dwz_file.get (); bfd_set_error (bfd_error_no_error); gdb::unique_xmalloc_ptr data @@ -2693,15 +2694,16 @@ dwarf2_get_dwz_file (struct dwarf2_per_objfile *dwarf2_per_objfile) error (_("could not find '.gnu_debugaltlink' file for %s"), objfile_name (dwarf2_per_objfile->objfile)); - result = OBSTACK_ZALLOC (&dwarf2_per_objfile->objfile->objfile_obstack, - struct dwz_file); - result->dwz_bfd = dwz_bfd.release (); + std::unique_ptr result + (new struct dwz_file (std::move (dwz_bfd))); - bfd_map_over_sections (result->dwz_bfd, locate_dwz_sections, result); + bfd_map_over_sections (result->dwz_bfd.get (), locate_dwz_sections, + result.get ()); - gdb_bfd_record_inclusion (dwarf2_per_objfile->objfile->obfd, result->dwz_bfd); - dwarf2_per_objfile->dwz_file = result; - return result; + gdb_bfd_record_inclusion (dwarf2_per_objfile->objfile->obfd, + result->dwz_bfd.get ()); + dwarf2_per_objfile->dwz_file = std::move (result); + return dwarf2_per_objfile->dwz_file.get (); } /* DWARF quick_symbols_functions support. */ diff --git a/gdb/dwarf2read.h b/gdb/dwarf2read.h index 8e6c41dc09..a1891def6c 100644 --- a/gdb/dwarf2read.h +++ b/gdb/dwarf2read.h @@ -198,7 +198,7 @@ public: /* The shared '.dwz' file, if one exists. This is used when the original data was compressed using 'dwz -m'. */ - struct dwz_file *dwz_file = NULL; + std::unique_ptr dwz_file; /* A flag indicating whether this objfile has a section loaded at a VMA of 0. */