From patchwork Thu Mar 29 15:27:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 26508 Received: (qmail 99348 invoked by alias); 29 Mar 2018 15:28:03 -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 98006 invoked by uid 89); 29 Mar 2018 15:28:02 -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=tus, sk:create_ X-HELO: gateway22.websitewelcome.com Received: from gateway22.websitewelcome.com (HELO gateway22.websitewelcome.com) (192.185.46.126) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 29 Mar 2018 15:28:01 +0000 Received: from cm17.websitewelcome.com (cm17.websitewelcome.com [100.42.49.20]) by gateway22.websitewelcome.com (Postfix) with ESMTP id 43C681155D for ; Thu, 29 Mar 2018 10:28:00 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id 1ZT6fK4aby2aL1ZT6fke1I; Thu, 29 Mar 2018 10:28:00 -0500 Received: from 174-29-48-109.hlrn.qwest.net ([174.29.48.109]:43322 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89_1) (envelope-from ) id 1f1ZT6-004CXX-2K; Thu, 29 Mar 2018 10:28:00 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 3/3] Remvoe free_dwo_file_cleanup Date: Thu, 29 Mar 2018 09:27:57 -0600 Message-Id: <20180329152757.9346-4-tom@tromey.com> In-Reply-To: <20180329152757.9346-1-tom@tromey.com> References: <20180329152757.9346-1-tom@tromey.com> X-BWhitelist: no X-Source-L: No X-Exim-ID: 1f1ZT6-004CXX-2K X-Source-Sender: 174-29-48-109.hlrn.qwest.net (bapiya.Home) [174.29.48.109]:43322 X-Source-Auth: tom+tromey.com X-Email-Count: 5 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes This removes free_dwo_file_cleanup, the last cleanup in dwarf2read.c. This is replaced with a unique_ptr; which, despite the fact that a dwo_file is obstack-allocated, seemed like the best fit. gdb/ChangeLog 2018-03-29 Tom Tromey * dwarf2read.c (struct free_dwo_file_cleanup_data): Remove. (struct dwo_file_deleter): New. (dwo_file_up): New typedef. (open_and_init_dwo_file): Use dwo_file_up. (free_dwo_file_cleanup): Remove. --- gdb/ChangeLog | 8 ++++++++ gdb/dwarf2read.c | 49 +++++++++++++++++++------------------------------ 2 files changed, 27 insertions(+), 30 deletions(-) diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index 1ab073804d..fd544a7f9b 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -1959,14 +1959,22 @@ static struct dwo_unit *lookup_dwo_type_unit static void queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data *); -static void free_dwo_file_cleanup (void *); +static void free_dwo_file (struct dwo_file *); -struct free_dwo_file_cleanup_data +/* A unique_ptr helper to free a dwo_file. */ + +struct dwo_file_deleter { - struct dwo_file *dwo_file; - struct dwarf2_per_objfile *dwarf2_per_objfile; + void operator() (struct dwo_file *df) const + { + free_dwo_file (df); + } }; +/* A unique pointer to a dwo_file. */ + +typedef std::unique_ptr dwo_file_up; + static void process_cu_includes (struct dwarf2_per_objfile *dwarf2_per_objfile); static void check_producer (struct dwarf2_cu *cu); @@ -12983,8 +12991,6 @@ open_and_init_dwo_file (struct dwarf2_per_cu_data *per_cu, { struct dwarf2_per_objfile *dwarf2_per_objfile = per_cu->dwarf2_per_objfile; struct objfile *objfile = dwarf2_per_objfile->objfile; - struct dwo_file *dwo_file; - struct cleanup *cleanups; gdb_bfd_ref_ptr dbfd (open_dwo_file (dwarf2_per_objfile, dwo_name, comp_dir)); if (dbfd == NULL) @@ -12993,32 +12999,28 @@ open_and_init_dwo_file (struct dwarf2_per_cu_data *per_cu, fprintf_unfiltered (gdb_stdlog, "DWO file not found: %s\n", dwo_name); return NULL; } - dwo_file = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct dwo_file); + + /* We use a unique pointer here, despite the obstack allocation, + because a dwo_file needs some cleanup if it is abandoned. */ + dwo_file_up dwo_file (OBSTACK_ZALLOC (&objfile->objfile_obstack, + struct dwo_file)); dwo_file->dwo_name = dwo_name; dwo_file->comp_dir = comp_dir; dwo_file->dbfd = dbfd.release (); - free_dwo_file_cleanup_data *cleanup_data = XNEW (free_dwo_file_cleanup_data); - cleanup_data->dwo_file = dwo_file; - cleanup_data->dwarf2_per_objfile = dwarf2_per_objfile; - - cleanups = make_cleanup (free_dwo_file_cleanup, cleanup_data); - bfd_map_over_sections (dwo_file->dbfd, dwarf2_locate_dwo_sections, &dwo_file->sections); create_cus_hash_table (dwarf2_per_objfile, *dwo_file, dwo_file->sections.info, dwo_file->cus); - create_debug_types_hash_table (dwarf2_per_objfile, dwo_file, + create_debug_types_hash_table (dwarf2_per_objfile, dwo_file.get (), dwo_file->sections.types, dwo_file->tus); - discard_cleanups (cleanups); - if (dwarf_read_debug) fprintf_unfiltered (gdb_stdlog, "DWO file found: %s\n", dwo_name); - return dwo_file; + return dwo_file.release (); } /* This function is mapped across the sections and remembers the offset and @@ -13524,19 +13526,6 @@ free_dwo_file (struct dwo_file *dwo_file) VEC_free (dwarf2_section_info_def, dwo_file->sections.types); } -/* Wrapper for free_dwo_file for use in cleanups. */ - -static void -free_dwo_file_cleanup (void *arg) -{ - struct free_dwo_file_cleanup_data *data - = (struct free_dwo_file_cleanup_data *) arg; - - free_dwo_file (data->dwo_file); - - xfree (data); -} - /* Traversal function for free_dwo_files. */ static int