From patchwork Fri May 3 23:12:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 32512 Received: (qmail 130218 invoked by alias); 3 May 2019 23:12:39 -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 130104 invoked by uid 89); 3 May 2019 23:12:38 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-18.0 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=*abfd, objfilesh, UD:objfiles.h, objfiles.h X-HELO: gateway20.websitewelcome.com Received: from gateway20.websitewelcome.com (HELO gateway20.websitewelcome.com) (192.185.54.2) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 03 May 2019 23:12:36 +0000 Received: from cm11.websitewelcome.com (cm11.websitewelcome.com [100.42.49.5]) by gateway20.websitewelcome.com (Postfix) with ESMTP id 443C2400C3F79 for ; Fri, 3 May 2019 18:12:35 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id MhM3hcYNVdnCeMhM3hMCO1; 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=yEARsb+vrCAX2CzwUt5quQcg6Bl2yEXl8QBwlztzHRM=; b=NIxpOGgQn1VHyazZwDt9qTpKsR nRgGyWwTKwjoKsSPCK8VPQOHOHeKvLao+28IGOwomrAcAB55vfBVQwMhHLBsvQ+F5sdiWQAz2VN/s WhAVD5IRnZLVM5AHMYGmCLxvB; 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-1H; Fri, 03 May 2019 18:12:35 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH v2 07/31] Convert objfiles.c to type-safe registry API Date: Fri, 3 May 2019 17:12:07 -0600 Message-Id: <20190503231231.8954-8-tom@tromey.com> In-Reply-To: <20190503231231.8954-1-tom@tromey.com> References: <20190503231231.8954-1-tom@tromey.com> This changes objfiles.c to use the type-safe registry API. 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); -}