From patchwork Tue Apr 23 02:09:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 32378 Received: (qmail 54415 invoked by alias); 23 Apr 2019 02:13:45 -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 54355 invoked by uid 89); 23 Apr 2019 02:13:44 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-21.1 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=MUST X-HELO: gateway31.websitewelcome.com Received: from gateway31.websitewelcome.com (HELO gateway31.websitewelcome.com) (192.185.144.94) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 23 Apr 2019 02:13:43 +0000 Received: from cm17.websitewelcome.com (cm17.websitewelcome.com [100.42.49.20]) by gateway31.websitewelcome.com (Postfix) with ESMTP id 4BCAE4886 for ; Mon, 22 Apr 2019 21:10:00 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id IksihEdVw90onIksihOe9H; Mon, 22 Apr 2019 21:10:00 -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=YEU8HXby/Nlt6aqPz7/TvzybdrIVs5k8dslPoSYbWBs=; b=O2YidaLcQUP8e1HFfGGG7ReZrU w1xU1dbQSoYRX6SQlVO16Y6WhgqfnT+kvD/L/VbVOpqFvTXnEnNLTBPfM5jQcdmpxBdFP47qZM4Hz K2GH4ixaQXqSyBfnxmgomWuNa; Received: from 97-122-168-123.hlrn.qwest.net ([97.122.168.123]:43470 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1hIksi-000jpC-3P; Mon, 22 Apr 2019 21:10:00 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 07/14] Convert objfiles.c to type-safe registry API Date: Mon, 22 Apr 2019 20:09:48 -0600 Message-Id: <20190423020955.17356-8-tom@tromey.com> In-Reply-To: <20190423020955.17356-1-tom@tromey.com> References: <20190423020955.17356-1-tom@tromey.com> This changes objfiles.c to use the type-safe registry API. gdb/ChangeLog 2019-04-22 Tom Tromey * objfiles.c (objfile_pspace_info): Add destructor and initializers. (objfiles_pspace_data): Change type. (~objfile_pspace_info): Rename from objfiles_pspace_data_cleanup. (get_objfile_pspace_data): Update. (objfiles_bfd_data): Change type. (get_objfile_bfd_data): Update. (objfile_bfd_data_free, _initialize_objfiles): Remove. --- gdb/ChangeLog | 11 ++++++++++ gdb/objfiles.c | 59 +++++++++++++++----------------------------------- 2 files changed, 28 insertions(+), 42 deletions(-) diff --git a/gdb/objfiles.c b/gdb/objfiles.c index 1b0ea29980d..0f5c7381aa6 100644 --- a/gdb/objfiles.c +++ b/gdb/objfiles.c @@ -66,30 +66,30 @@ DEFINE_REGISTRY (objfile, REGISTRY_ACCESS_FIELD) struct objfile_pspace_info { - struct obj_section **sections; - int num_sections; + objfile_pspace_info () = default; + ~objfile_pspace_info (); + + struct obj_section **sections = nullptr; + int num_sections = 0; /* Nonzero if object files have been added since the section map was last updated. */ - int new_objfiles_available; + int new_objfiles_available = 0; /* Nonzero if the section map MUST be updated before use. */ - int section_map_dirty; + int section_map_dirty = 0; /* Nonzero if section map updates should be inhibited if possible. */ - int inhibit_updates; + int inhibit_updates = 0; }; /* Per-program-space data key. */ -static const struct program_space_data *objfiles_pspace_data; +static const struct program_space_key + objfiles_pspace_data; -static void -objfiles_pspace_data_cleanup (struct program_space *pspace, void *arg) +objfile_pspace_info::~objfile_pspace_info () { - struct objfile_pspace_info *info = (struct objfile_pspace_info *) arg; - - xfree (info->sections); - xfree (info); + xfree (sections); } /* Get the current svr4 data. If none is found yet, add it now. This @@ -100,13 +100,9 @@ get_objfile_pspace_data (struct program_space *pspace) { struct objfile_pspace_info *info; - info = ((struct objfile_pspace_info *) - program_space_data (pspace, objfiles_pspace_data)); + info = objfiles_pspace_data.get (pspace); if (info == NULL) - { - info = XCNEW (struct objfile_pspace_info); - set_program_space_data (pspace, objfiles_pspace_data, info); - } + info = objfiles_pspace_data.emplace (pspace); return info; } @@ -115,7 +111,7 @@ get_objfile_pspace_data (struct program_space *pspace) /* Per-BFD data key. */ -static const struct bfd_data *objfiles_bfd_data; +static const struct bfd_key objfiles_bfd_data; objfile_per_bfd_storage::~objfile_per_bfd_storage () { @@ -133,8 +129,7 @@ get_objfile_bfd_data (struct objfile *objfile, struct bfd *abfd) struct objfile_per_bfd_storage *storage = NULL; if (abfd != NULL) - storage = ((struct objfile_per_bfd_storage *) - bfd_data (abfd, objfiles_bfd_data)); + storage = objfiles_bfd_data.get (abfd); if (storage == NULL) { @@ -143,7 +138,7 @@ get_objfile_bfd_data (struct objfile *objfile, struct bfd *abfd) back to not sharing data across users. These cases are rare enough that this seems reasonable. */ if (abfd != NULL && !gdb_bfd_requires_relocations (abfd)) - set_bfd_data (abfd, objfiles_bfd_data, storage); + objfiles_bfd_data.set (abfd, storage); /* Look up the gdbarch associated with the BFD. */ if (abfd != NULL) @@ -153,15 +148,6 @@ get_objfile_bfd_data (struct objfile *objfile, struct bfd *abfd) return storage; } -/* A deleter for objfile_per_bfd_storage that can be passed as a - cleanup function to the BFD registry. */ - -static void -objfile_bfd_data_free (struct bfd *unused, void *d) -{ - delete (struct objfile_per_bfd_storage *) d; -} - /* See objfiles.h. */ void @@ -1511,14 +1497,3 @@ objfile_flavour_name (struct objfile *objfile) return bfd_flavour_name (bfd_get_flavour (objfile->obfd)); return NULL; } - -void -_initialize_objfiles (void) -{ - objfiles_pspace_data - = register_program_space_data_with_cleanup (NULL, - objfiles_pspace_data_cleanup); - - objfiles_bfd_data = register_bfd_data_with_cleanup (NULL, - objfile_bfd_data_free); -}