From patchwork Fri May 3 23:12:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 32518 Received: (qmail 131065 invoked by alias); 3 May 2019 23:12:44 -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 130362 invoked by uid 89); 3 May 2019 23:12:40 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-18.4 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.1 spammy=hangs X-HELO: gateway24.websitewelcome.com Received: from gateway24.websitewelcome.com (HELO gateway24.websitewelcome.com) (192.185.50.91) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 03 May 2019 23:12:37 +0000 Received: from cm17.websitewelcome.com (cm17.websitewelcome.com [100.42.49.20]) by gateway24.websitewelcome.com (Postfix) with ESMTP id C9933CB6B for ; Fri, 3 May 2019 18:12:35 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id MhM3hJkWb90onMhM3hRenu; Fri, 03 May 2019 18:12:35 -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=xIPO0OtsnjXA3mZjP1AnctSncYn7C1/PQ379PGII/Yc=; b=NZusywiQh3AmmUq14Dq92uolxk i1fT8XqomkWW8L11ytwbBFiP1xGMdsPvrwxqlMoVcwiDmyYvtCupioQXnNdOB8PTvEAtmezUxjA8o CKRi2T9NYz5cqJ8f6ErZhmOT4; Received: from 97-122-168-123.hlrn.qwest.net ([97.122.168.123]:37502 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1hMhM3-003AAO-Kd; Fri, 03 May 2019 18:12:35 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH v2 09/31] Convert dwarf2_per_objfile to type-safe registry API Date: Fri, 3 May 2019 17:12:09 -0600 Message-Id: <20190503231231.8954-10-tom@tromey.com> In-Reply-To: <20190503231231.8954-1-tom@tromey.com> References: <20190503231231.8954-1-tom@tromey.com> This changes dwarf2_per_objfile to use the type-safe registry API. This also changes dwarf2_per_objfile not to be allocated on an obstack. It seemed clearer to me to simply allocate it on the heap; and I didn't see a drawback from doing so. 2019-04-22 Tom Tromey * dwarf2read.h (struct dwarf2_per_objfile): Don't inherit from allocate_on_obstack. * dwarf2read.c (dwarf2_objfile_data_key): Change type. (get_dwarf2_per_objfile): Update. (set_dwarf2_per_objfile): Remove. (dwarf2_has_info, dwarf2_get_section_info): Update. (dwarf2_free_objfile): Remove. (_initialize_dwarf2_read): Update. --- gdb/ChangeLog | 11 +++++++++++ gdb/dwarf2read.c | 43 ++++++------------------------------------- gdb/dwarf2read.h | 2 +- 3 files changed, 18 insertions(+), 38 deletions(-) diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index b0bdecf96fc..75d940c99a6 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -108,7 +108,7 @@ static int check_physname = 0; /* When non-zero, do not reject deprecated .gdb_index sections. */ static int use_deprecated_index_sections = 0; -static const struct objfile_data *dwarf2_objfile_data_key; +static const struct objfile_key dwarf2_objfile_data_key; /* The "aclass" indices for various kinds of computed DWARF symbols. */ @@ -281,18 +281,7 @@ struct mapped_debug_names final : public mapped_index_base dwarf2_per_objfile * get_dwarf2_per_objfile (struct objfile *objfile) { - return ((struct dwarf2_per_objfile *) - objfile_data (objfile, dwarf2_objfile_data_key)); -} - -/* Set the dwarf2_per_objfile associated to OBJFILE. */ - -void -set_dwarf2_per_objfile (struct objfile *objfile, - struct dwarf2_per_objfile *dwarf2_per_objfile) -{ - gdb_assert (get_dwarf2_per_objfile (objfile) == NULL); - set_objfile_data (objfile, dwarf2_objfile_data_key, dwarf2_per_objfile); + return dwarf2_objfile_data_key.get (objfile); } /* Default names of the debugging sections. */ @@ -2251,13 +2240,9 @@ dwarf2_has_info (struct objfile *objfile, = get_dwarf2_per_objfile (objfile); if (dwarf2_per_objfile == NULL) - { - /* Initialize per-objfile state. */ - dwarf2_per_objfile - = new (&objfile->objfile_obstack) struct dwarf2_per_objfile (objfile, - names); - set_dwarf2_per_objfile (objfile, dwarf2_per_objfile); - } + dwarf2_per_objfile = dwarf2_objfile_data_key.emplace (objfile, objfile, + names); + return (!dwarf2_per_objfile->info.is_virtual && dwarf2_per_objfile->info.s.section != NULL && !dwarf2_per_objfile->abbrev.is_virtual @@ -2589,9 +2574,7 @@ dwarf2_get_section_info (struct objfile *objfile, asection **sectp, const gdb_byte **bufp, bfd_size_type *sizep) { - struct dwarf2_per_objfile *data - = (struct dwarf2_per_objfile *) objfile_data (objfile, - dwarf2_objfile_data_key); + struct dwarf2_per_objfile *data = dwarf2_objfile_data_key.get (objfile); struct dwarf2_section_info *info; /* We may see an objfile without any DWARF, in which case we just @@ -25433,17 +25416,6 @@ free_one_cached_comp_unit (struct dwarf2_per_cu_data *target_per_cu) } } -/* Cleanup function for the dwarf2_per_objfile data. */ - -static void -dwarf2_free_objfile (struct objfile *objfile, void *datum) -{ - struct dwarf2_per_objfile *dwarf2_per_objfile - = static_cast (datum); - - delete dwarf2_per_objfile; -} - /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer. We store these in a hash table separate from the DIEs, and preserve them when the DIEs are flushed out of cache. @@ -25761,9 +25733,6 @@ show_check_physname (struct ui_file *file, int from_tty, void _initialize_dwarf2_read (void) { - dwarf2_objfile_data_key - = register_objfile_data_with_cleanup (nullptr, dwarf2_free_objfile); - add_prefix_cmd ("dwarf", class_maintenance, set_dwarf_cmd, _("\ Set DWARF specific variables.\n\ Configure DWARF variables such as the cache size"), diff --git a/gdb/dwarf2read.h b/gdb/dwarf2read.h index 34c66167b5b..9a316260be4 100644 --- a/gdb/dwarf2read.h +++ b/gdb/dwarf2read.h @@ -102,7 +102,7 @@ typedef struct die_info *die_info_ptr; /* Collection of data recorded per objfile. This hangs off of dwarf2_objfile_data_key. */ -struct dwarf2_per_objfile : public allocate_on_obstack +struct dwarf2_per_objfile { /* Construct a dwarf2_per_objfile for OBJFILE. NAMES points to the dwarf2 section names, or is NULL if the standard ELF names are