From patchwork Fri May 18 15:37:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 27325 Received: (qmail 72430 invoked by alias); 18 May 2018 15:37:30 -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 72417 invoked by uid 89); 18 May 2018 15:37:29 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.8 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=ugly X-HELO: gateway21.websitewelcome.com Received: from gateway21.websitewelcome.com (HELO gateway21.websitewelcome.com) (192.185.45.228) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 18 May 2018 15:37:27 +0000 Received: from cm12.websitewelcome.com (cm12.websitewelcome.com [100.42.49.8]) by gateway21.websitewelcome.com (Postfix) with ESMTP id 4A24440103B9C for ; Fri, 18 May 2018 10:37:26 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id JhRefgwNmlAdrJhRefCieK; Fri, 18 May 2018 10:37:26 -0500 X-Authority-Reason: nr=8 Received: from 174-29-44-154.hlrn.qwest.net ([174.29.44.154]:34848 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89_1) (envelope-from ) id 1fJhRd-002fo5-M5; Fri, 18 May 2018 10:37:26 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA] Use new to allocate mapped_index Date: Fri, 18 May 2018 09:37:22 -0600 Message-Id: <20180518153722.5696-1-tom@tromey.com> X-BWhitelist: no X-Source-L: No X-Exim-ID: 1fJhRd-002fo5-M5 X-Source-Sender: 174-29-44-154.hlrn.qwest.net (bapiya.Home) [174.29.44.154]:34848 X-Source-Auth: tom+tromey.com X-Email-Count: 3 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes This changes struct mapped_index to be allocated with new. This simplifies the creation a bit (see dwarf2_read_index) and also removes a somewhat ugly explicit destructor call from ~dwarf2_per_objfile. Tested by the buildbot. gdb/ChangeLog 2018-05-17 Tom Tromey * dwarf2read.c (dwarf2_per_objfile): Update. (struct mapped_index): Add initializers. (dwarf2_read_index): Use new. (dw2_symtab_iter_init): Update. * dwarf2read.h (struct dwarf2_per_objfile) : Now a unique_ptr. --- gdb/ChangeLog | 9 +++++++++ gdb/dwarf2read.c | 25 +++++++++---------------- gdb/dwarf2read.h | 2 +- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index b2ecadf89b..1df9635137 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -195,10 +195,10 @@ struct mapped_index final : public mapped_index_base }; /* Index data format version. */ - int version; + int version = 0; /* The total length of the buffer. */ - off_t total_size; + off_t total_size = 0; /* The address table data. */ gdb::array_view address_table; @@ -207,7 +207,7 @@ struct mapped_index final : public mapped_index_base gdb::array_view symbol_table; /* A pointer to the constant pool. */ - const char *constant_pool; + const char *constant_pool = nullptr; bool symbol_name_slot_invalid (offset_type idx) const override { @@ -2153,9 +2153,6 @@ dwarf2_per_objfile::~dwarf2_per_objfile () if (dwz_file != NULL && dwz_file->dwz_bfd) gdb_bfd_unref (dwz_file->dwz_bfd); - if (index_table != NULL) - index_table->~mapped_index (); - /* Everything else should be on the objfile obstack. */ } @@ -3541,21 +3538,21 @@ to use the section anyway."), static int dwarf2_read_index (struct dwarf2_per_objfile *dwarf2_per_objfile) { - struct mapped_index local_map, *map; const gdb_byte *cu_list, *types_list, *dwz_list = NULL; offset_type cu_list_elements, types_list_elements, dwz_list_elements = 0; struct dwz_file *dwz; struct objfile *objfile = dwarf2_per_objfile->objfile; + std::unique_ptr map (new struct mapped_index); if (!read_index_from_section (objfile, objfile_name (objfile), use_deprecated_index_sections, - &dwarf2_per_objfile->gdb_index, &local_map, + &dwarf2_per_objfile->gdb_index, map.get (), &cu_list, &cu_list_elements, &types_list, &types_list_elements)) return 0; /* Don't use the index if it's empty. */ - if (local_map.symbol_table.empty ()) + if (map->symbol_table.empty ()) return 0; /* If there is a .dwz file, read it so we can get its CU list as @@ -3599,13 +3596,9 @@ dwarf2_read_index (struct dwarf2_per_objfile *dwarf2_per_objfile) types_list, types_list_elements); } - create_addrmap_from_index (dwarf2_per_objfile, &local_map); - - map = XOBNEW (&objfile->objfile_obstack, struct mapped_index); - map = new (map) mapped_index (); - *map = local_map; + create_addrmap_from_index (dwarf2_per_objfile, map.get ()); - dwarf2_per_objfile->index_table = map; + dwarf2_per_objfile->index_table = std::move (map); dwarf2_per_objfile->using_index = 1; dwarf2_per_objfile->quick_file_names_table = create_quick_file_names_table (dwarf2_per_objfile->all_comp_units.size ()); @@ -3920,7 +3913,7 @@ dw2_symtab_iter_init (struct dw2_symtab_iterator *iter, iter->next = 0; iter->global_seen = 0; - mapped_index *index = dwarf2_per_objfile->index_table; + mapped_index *index = dwarf2_per_objfile->index_table.get (); /* index is NULL if OBJF_READNOW. */ if (index != NULL && find_slot_in_mapped_hash (index, name, &iter->vec)) diff --git a/gdb/dwarf2read.h b/gdb/dwarf2read.h index 8e6c41dc09..f36d039e7b 100644 --- a/gdb/dwarf2read.h +++ b/gdb/dwarf2read.h @@ -209,7 +209,7 @@ public: bool using_index = false; /* The mapped index, or NULL if .gdb_index is missing or not being used. */ - mapped_index *index_table = NULL; + std::unique_ptr index_table; /* The mapped index, or NULL if .debug_names is missing or not being used. */ std::unique_ptr debug_names_table;