From patchwork Thu May 17 13:23:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 27314 Received: (qmail 119681 invoked by alias); 17 May 2018 13:23: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 119672 invoked by uid 89); 17 May 2018 13:23:13 -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=management X-HELO: gateway32.websitewelcome.com Received: from gateway32.websitewelcome.com (HELO gateway32.websitewelcome.com) (192.185.145.182) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 17 May 2018 13:23:11 +0000 Received: from cm17.websitewelcome.com (cm17.websitewelcome.com [100.42.49.20]) by gateway32.websitewelcome.com (Postfix) with ESMTP id 3D1EA21FDF8 for ; Thu, 17 May 2018 08:23:05 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id JIs4fdLx4y2aLJIs5fvEwe; Thu, 17 May 2018 08:23:05 -0500 X-Authority-Reason: nr=8 Received: from 174-29-44-154.hlrn.qwest.net ([174.29.44.154]:60208 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89_1) (envelope-from ) id 1fJIs4-002Mfz-MK; Thu, 17 May 2018 08:23:04 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA] Allocate dwp_file with new Date: Thu, 17 May 2018 07:23:02 -0600 Message-Id: <20180517132302.2410-1-tom@tromey.com> X-BWhitelist: no X-Source-L: No X-Exim-ID: 1fJIs4-002Mfz-MK X-Source-Sender: 174-29-44-154.hlrn.qwest.net (bapiya.Home) [174.29.44.154]:60208 X-Source-Auth: tom+tromey.com X-Email-Count: 1 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes This adds a constructor and initializer to dwp_file and changes it to be allocated with "new". This removes a bit of manual refcount management. Tested by the buildbot. gdb/ChangeLog 2018-05-17 Tom Tromey * dwarf2read.h (struct dwarf2_per_objfile) : Now a unique_ptr. * dwarf2read.c (struct dwp_file): Add constructor and initializers. (open_and_init_dwp_file): Return a unique_ptr. (dwarf2_per_objfile, create_dwp_hash_table) (create_dwo_unit_in_dwp_v1, create_dwo_unit_in_dwp_v2) (lookup_dwo_unit_in_dwp): Update. (open_and_init_dwp_file, get_dwp_file): Update. --- gdb/ChangeLog | 12 +++++++++++ gdb/dwarf2read.c | 64 +++++++++++++++++++++++++++++++------------------------- gdb/dwarf2read.h | 2 +- 3 files changed, 49 insertions(+), 29 deletions(-) diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index 575d316cdd..f11f19904b 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -810,32 +810,38 @@ struct dwp_hash_table struct dwp_file { + dwp_file (const char *name_, gdb_bfd_ref_ptr &&abfd) + : name (name_), + dbfd (std::move (abfd)) + { + } + /* Name of the file. */ const char *name; /* File format version. */ - int version; + int version = 0; /* The bfd. */ - bfd *dbfd; + gdb_bfd_ref_ptr dbfd; /* Section info for this file. */ - struct dwp_sections sections; + struct dwp_sections sections {}; /* Table of CUs in the file. */ - const struct dwp_hash_table *cus; + const struct dwp_hash_table *cus = nullptr; /* Table of TUs in the file. */ - const struct dwp_hash_table *tus; + const struct dwp_hash_table *tus = nullptr; /* Tables of loaded CUs/TUs. Each entry is a struct dwo_unit *. */ - htab_t loaded_cus; - htab_t loaded_tus; + htab_t loaded_cus {}; + htab_t loaded_tus {}; /* Table to map ELF section numbers to their sections. This is only needed for the DWP V1 file format. */ - unsigned int num_sections; - asection **elf_sections; + unsigned int num_sections = 0; + asection **elf_sections = nullptr; }; /* This represents a '.dwz' file. */ @@ -2147,8 +2153,6 @@ dwarf2_per_objfile::~dwarf2_per_objfile () if (dwo_files != NULL) free_dwo_files (dwo_files, 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); @@ -12038,7 +12042,7 @@ create_dwp_hash_table (struct dwarf2_per_objfile *dwarf2_per_objfile, struct dwp_file *dwp_file, int is_debug_types) { struct objfile *objfile = dwarf2_per_objfile->objfile; - bfd *dbfd = dwp_file->dbfd; + bfd *dbfd = dwp_file->dbfd.get (); const gdb_byte *index_ptr, *index_end; struct dwarf2_section_info *index; uint32_t version, nr_columns, nr_units, nr_slots; @@ -12281,7 +12285,7 @@ create_dwo_unit_in_dwp_v1 (struct dwarf2_per_objfile *dwarf2_per_objfile, struct objfile *objfile = dwarf2_per_objfile->objfile; const struct dwp_hash_table *dwp_htab = is_debug_types ? dwp_file->tus : dwp_file->cus; - bfd *dbfd = dwp_file->dbfd; + bfd *dbfd = dwp_file->dbfd.get (); const char *kind = is_debug_types ? "TU" : "CU"; struct dwo_file *dwo_file; struct dwo_unit *dwo_unit; @@ -12483,7 +12487,7 @@ create_dwo_unit_in_dwp_v2 (struct dwarf2_per_objfile *dwarf2_per_objfile, struct objfile *objfile = dwarf2_per_objfile->objfile; const struct dwp_hash_table *dwp_htab = is_debug_types ? dwp_file->tus : dwp_file->cus; - bfd *dbfd = dwp_file->dbfd; + bfd *dbfd = dwp_file->dbfd.get (); const char *kind = is_debug_types ? "TU" : "CU"; struct dwo_file *dwo_file; struct dwo_unit *dwo_unit; @@ -12653,7 +12657,7 @@ lookup_dwo_unit_in_dwp (struct dwarf2_per_objfile *dwarf2_per_objfile, { const struct dwp_hash_table *dwp_htab = is_debug_types ? dwp_file->tus : dwp_file->cus; - bfd *dbfd = dwp_file->dbfd; + bfd *dbfd = dwp_file->dbfd.get (); uint32_t mask = dwp_htab->nr_slots - 1; uint32_t hash = signature & mask; uint32_t hash2 = ((signature >> 32) & mask) | 1; @@ -13095,11 +13099,10 @@ open_dwp_file (struct dwarf2_per_objfile *dwarf2_per_objfile, By convention the name of the DWP file is ${objfile}.dwp. The result is NULL if it can't be found. */ -static struct dwp_file * +static std::unique_ptr open_and_init_dwp_file (struct dwarf2_per_objfile *dwarf2_per_objfile) { struct objfile *objfile = dwarf2_per_objfile->objfile; - struct dwp_file *dwp_file; /* Try to find first .dwp for the binary file before any symbolic links resolving. */ @@ -13133,11 +13136,12 @@ open_and_init_dwp_file (struct dwarf2_per_objfile *dwarf2_per_objfile) { if (dwarf_read_debug) fprintf_unfiltered (gdb_stdlog, "DWP file not found: %s\n", dwp_name.c_str ()); - return NULL; + return std::unique_ptr (); } - dwp_file = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct dwp_file); - dwp_file->name = bfd_get_filename (dbfd.get ()); - dwp_file->dbfd = dbfd.release (); + + const char *name = bfd_get_filename (dbfd.get ()); + std::unique_ptr dwp_file + (new struct dwp_file (name, std::move (dbfd))); /* +1: section 0 is unused */ dwp_file->num_sections = bfd_count_sections (dwp_file->dbfd) + 1; @@ -13145,12 +13149,15 @@ open_and_init_dwp_file (struct dwarf2_per_objfile *dwarf2_per_objfile) OBSTACK_CALLOC (&objfile->objfile_obstack, dwp_file->num_sections, asection *); - bfd_map_over_sections (dwp_file->dbfd, dwarf2_locate_common_dwp_sections, - dwp_file); + bfd_map_over_sections (dwp_file->dbfd.get (), + dwarf2_locate_common_dwp_sections, + dwp_file.get ()); - dwp_file->cus = create_dwp_hash_table (dwarf2_per_objfile, dwp_file, 0); + dwp_file->cus = create_dwp_hash_table (dwarf2_per_objfile, dwp_file.get (), + 0); - dwp_file->tus = create_dwp_hash_table (dwarf2_per_objfile, dwp_file, 1); + dwp_file->tus = create_dwp_hash_table (dwarf2_per_objfile, dwp_file.get (), + 1); /* The DWP file version is stored in the hash table. Oh well. */ if (dwp_file->cus && dwp_file->tus @@ -13173,8 +13180,9 @@ open_and_init_dwp_file (struct dwarf2_per_objfile *dwarf2_per_objfile) dwp_file->version = 2; if (dwp_file->version == 2) - bfd_map_over_sections (dwp_file->dbfd, dwarf2_locate_v2_dwp_sections, - dwp_file); + bfd_map_over_sections (dwp_file->dbfd.get (), + dwarf2_locate_v2_dwp_sections, + dwp_file.get ()); dwp_file->loaded_cus = allocate_dwp_loaded_cutus_table (objfile); dwp_file->loaded_tus = allocate_dwp_loaded_cutus_table (objfile); @@ -13202,7 +13210,7 @@ get_dwp_file (struct dwarf2_per_objfile *dwarf2_per_objfile) = open_and_init_dwp_file (dwarf2_per_objfile); dwarf2_per_objfile->dwp_checked = 1; } - return dwarf2_per_objfile->dwp_file; + return dwarf2_per_objfile->dwp_file.get (); } /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit. diff --git a/gdb/dwarf2read.h b/gdb/dwarf2read.h index 8e6c41dc09..dadfd9fbb8 100644 --- a/gdb/dwarf2read.h +++ b/gdb/dwarf2read.h @@ -194,7 +194,7 @@ public: bool dwp_checked = false; /* The DWP file if there is one, or NULL. */ - struct dwp_file *dwp_file = NULL; + std::unique_ptr dwp_file; /* The shared '.dwz' file, if one exists. This is used when the original data was compressed using 'dwz -m'. */