From patchwork Tue Apr 23 02:09:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 32366 Received: (qmail 16611 invoked by alias); 23 Apr 2019 02:10:04 -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 16549 invoked by uid 89); 23 Apr 2019 02:10:02 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-17.2 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=adapter, 2172 X-HELO: gateway33.websitewelcome.com Received: from gateway33.websitewelcome.com (HELO gateway33.websitewelcome.com) (192.185.146.21) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 23 Apr 2019 02:10:01 +0000 Received: from cm10.websitewelcome.com (cm10.websitewelcome.com [100.42.49.4]) by gateway33.websitewelcome.com (Postfix) with ESMTP id E65759CC69 for ; Mon, 22 Apr 2019 21:09:59 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id IkshhnBmx2PzOIkshhJOx5; Mon, 22 Apr 2019 21:09:59 -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=ka9y5yPmDwOHaBkZGbIWcrgZ3+jS7eBS02XtIYuyTqc=; b=d+2lTmX8P0Z4qKat6ohzeLYdMA PRCBEEYgcJ3UVx34J9u+ApmdpB/inskHNETJBeRksbbT7qQEKOcfVfcyYT9rE7H4iYyu0K8XlE13S OxpMiFMe/z2yxchFx0h6nuULy; 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 1hIksh-000jpC-95; Mon, 22 Apr 2019 21:09:59 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 04/14] Convert target dcache to type-safe registry API Date: Mon, 22 Apr 2019 20:09:45 -0600 Message-Id: <20190423020955.17356-5-tom@tromey.com> In-Reply-To: <20190423020955.17356-1-tom@tromey.com> References: <20190423020955.17356-1-tom@tromey.com> This changes the target dcache to use the type-safe registry API. gdb/ChangeLog 2019-04-22 Tom Tromey * target-dcache.c (target_dcache_cleanup): Remove. (target_dcache_aspace_key): Change type. (target_dcache_init_p, target_dcache_invalidate) (target_dcache_get, target_dcache_get_or_init) (_initialize_target_dcache): Update. * dcache.h (struct dcache_deleter): New. --- gdb/ChangeLog | 9 +++++++++ gdb/dcache.h | 9 +++++++++ gdb/target-dcache.c | 34 +++++++--------------------------- 3 files changed, 25 insertions(+), 27 deletions(-) diff --git a/gdb/dcache.h b/gdb/dcache.h index 9c29074c919..a58ac840d12 100644 --- a/gdb/dcache.h +++ b/gdb/dcache.h @@ -34,6 +34,15 @@ DCACHE *dcache_init (void); /* Free a DCACHE. */ void dcache_free (DCACHE *); +/* A deletion adapter that calls dcache_free. */ +struct dcache_deleter +{ + void operator() (DCACHE *d) const + { + dcache_free (d); + } +}; + enum target_xfer_status dcache_read_memory_partial (struct target_ops *ops, DCACHE *dcache, CORE_ADDR memaddr, gdb_byte *myaddr, diff --git a/gdb/target-dcache.c b/gdb/target-dcache.c index 3fab9845bc3..98d5c1f83b6 100644 --- a/gdb/target-dcache.c +++ b/gdb/target-dcache.c @@ -23,16 +23,8 @@ /* The target dcache is kept per-address-space. This key lets us associate the cache with the address space. */ -static const struct address_space_data *target_dcache_aspace_key; - -/* Clean up dcache, represented by ARG, which is associated with - ASPACE. */ - -static void -target_dcache_cleanup (struct address_space *aspace, void *arg) -{ - dcache_free ((DCACHE *) arg); -} +static const struct address_space_key + target_dcache_aspace_key; /* Target dcache is initialized or not. */ @@ -40,8 +32,7 @@ int target_dcache_init_p (void) { DCACHE *dcache - = (DCACHE *) address_space_data (current_program_space->aspace, - target_dcache_aspace_key); + = target_dcache_aspace_key.get (current_program_space->aspace); return (dcache != NULL); } @@ -52,8 +43,7 @@ void target_dcache_invalidate (void) { DCACHE *dcache - = (DCACHE *) address_space_data (current_program_space->aspace, - target_dcache_aspace_key); + = target_dcache_aspace_key.get (current_program_space->aspace); if (dcache != NULL) dcache_invalidate (dcache); @@ -65,11 +55,7 @@ target_dcache_invalidate (void) DCACHE * target_dcache_get (void) { - DCACHE *dcache - = (DCACHE *) address_space_data (current_program_space->aspace, - target_dcache_aspace_key); - - return dcache; + return target_dcache_aspace_key.get (current_program_space->aspace); } /* Return the target dcache. If it is not initialized yet, initialize @@ -79,14 +65,12 @@ DCACHE * target_dcache_get_or_init (void) { DCACHE *dcache - = (DCACHE *) address_space_data (current_program_space->aspace, - target_dcache_aspace_key); + = target_dcache_aspace_key.get (current_program_space->aspace); if (dcache == NULL) { dcache = dcache_init (); - set_address_space_data (current_program_space->aspace, - target_dcache_aspace_key, dcache); + target_dcache_aspace_key.set (current_program_space->aspace, dcache); } return dcache; @@ -193,8 +177,4 @@ access is on."), set_code_cache, show_code_cache, &setlist, &showlist); - - target_dcache_aspace_key - = register_address_space_data_with_cleanup (NULL, - target_dcache_cleanup); }