From patchwork Tue Apr 23 02:09:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 32376 Received: (qmail 17677 invoked by alias); 23 Apr 2019 02:10:10 -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 17139 invoked by uid 89); 23 Apr 2019 02:10:06 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-20.6 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=caching, 25226 X-HELO: gateway36.websitewelcome.com Received: from gateway36.websitewelcome.com (HELO gateway36.websitewelcome.com) (192.185.185.36) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 23 Apr 2019 02:10:04 +0000 Received: from cm10.websitewelcome.com (cm10.websitewelcome.com [100.42.49.4]) by gateway36.websitewelcome.com (Postfix) with ESMTP id A9FC0400C6F0C for ; Mon, 22 Apr 2019 20:28:18 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id IksjhnBp12PzOIksjhJOz5; Mon, 22 Apr 2019 21:10:01 -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=YCpPYNLY3/OfW4ibafgz34cSOXCCvBlZfjApCqWxQPA=; b=x+nIkL1yusE50T5ab6h5O8aGDo I4dLT+Hy6L22oCDkof6riKGQVbGERjYtgY1JxI3zUDYEvH3dWSr6h0WfHs78mf82kutSDEqVUpJh7 I8THBzI+DuPkjpqqrcY0zqQfw; 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 1hIksj-000jpC-FM; Mon, 22 Apr 2019 21:10:01 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 12/14] Convert linux-tdep.c to type-safe registry API Date: Mon, 22 Apr 2019 20:09:53 -0600 Message-Id: <20190423020955.17356-13-tom@tromey.com> In-Reply-To: <20190423020955.17356-1-tom@tromey.com> References: <20190423020955.17356-1-tom@tromey.com> This changes linux-tdep.c to use the type-safe registry API. gdb/ChangeLog 2019-04-22 Tom Tromey * linux-tdep.c (struct linux_info): Add initializers. (linux_inferior_data): Move. Change type. (invalidate_linux_cache_inf): Update. (linux_inferior_data_cleanup): Remove. (get_linux_inferior_data, _initialize_linux_tdep): Update. --- gdb/ChangeLog | 8 ++++++++ gdb/linux-tdep.c | 36 ++++++++++-------------------------- 2 files changed, 18 insertions(+), 26 deletions(-) diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c index 5de985def39..fe0073a5939 100644 --- a/gdb/linux-tdep.c +++ b/gdb/linux-tdep.c @@ -183,9 +183,6 @@ get_linux_gdbarch_data (struct gdbarch *gdbarch) gdbarch_data (gdbarch, linux_gdbarch_data_handle)); } -/* Per-inferior data key. */ -static const struct inferior_data *linux_inferior_data; - /* Linux-specific cached data. This is used by GDB for caching purposes for each inferior. This helps reduce the overhead of transfering data from a remote target to the local host. */ @@ -196,14 +193,17 @@ struct linux_info at this info requires an auxv lookup (which is itself cached), and looking through the inferior's mappings (which change throughout execution and therefore cannot be cached). */ - struct mem_range vsyscall_range; + struct mem_range vsyscall_range {}; /* Zero if we haven't tried looking up the vsyscall's range before yet. Positive if we tried looking it up, and found it. Negative if we tried looking it up but failed. */ - int vsyscall_range_p; + int vsyscall_range_p = 0; }; +/* Per-inferior data key. */ +static const struct inferior_key linux_inferior_data; + /* Frees whatever allocated space there is to be freed and sets INF's linux cache data pointer to NULL. */ @@ -212,24 +212,14 @@ invalidate_linux_cache_inf (struct inferior *inf) { struct linux_info *info; - info = (struct linux_info *) inferior_data (inf, linux_inferior_data); + info = linux_inferior_data.get (inf); if (info != NULL) { - xfree (info); - set_inferior_data (inf, linux_inferior_data, NULL); + delete info; + linux_inferior_data.set (inf, NULL); } } -/* Handles the cleanup of the linux cache for inferior INF. ARG is - ignored. Callback for the inferior_appeared and inferior_exit - events. */ - -static void -linux_inferior_data_cleanup (struct inferior *inf, void *arg) -{ - invalidate_linux_cache_inf (inf); -} - /* Fetch the linux cache info for INF. This function always returns a valid INFO pointer. */ @@ -239,12 +229,9 @@ get_linux_inferior_data (void) struct linux_info *info; struct inferior *inf = current_inferior (); - info = (struct linux_info *) inferior_data (inf, linux_inferior_data); + info = linux_inferior_data.get (inf); if (info == NULL) - { - info = XCNEW (struct linux_info); - set_inferior_data (inf, linux_inferior_data, info); - } + info = linux_inferior_data.emplace (inf); return info; } @@ -2535,9 +2522,6 @@ _initialize_linux_tdep (void) linux_gdbarch_data_handle = gdbarch_data_register_post_init (init_linux_gdbarch_data); - /* Set a cache per-inferior. */ - linux_inferior_data - = register_inferior_data_with_cleanup (NULL, linux_inferior_data_cleanup); /* Observers used to invalidate the cache when needed. */ gdb::observers::inferior_exit.attach (invalidate_linux_cache_inf); gdb::observers::inferior_appeared.attach (invalidate_linux_cache_inf);