From patchwork Fri May 3 23:12:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 32524 Received: (qmail 738 invoked by alias); 3 May 2019 23:12:47 -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 130979 invoked by uid 89); 3 May 2019 23:12:44 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-19.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= X-HELO: gateway22.websitewelcome.com Received: from gateway22.websitewelcome.com (HELO gateway22.websitewelcome.com) (192.185.46.126) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 03 May 2019 23:12:39 +0000 Received: from cm11.websitewelcome.com (cm11.websitewelcome.com [100.42.49.5]) by gateway22.websitewelcome.com (Postfix) with ESMTP id 47DD85649 for ; Fri, 3 May 2019 18:12:38 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id MhM6hcYPvdnCeMhM6hMCQR; Fri, 03 May 2019 18:12:38 -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=QtEZRL1iBfSF2qqHisDFxLlReLvjiJTooDcZOKeoEY8=; b=m+dqft6EDnq3Oq2nYPd4/syJf6 AMxMBAfZ2E28CTlsUS9ha8xrsd0XO5qUYAWZp/s+N8ZfaqCSo6fUUIybmT07TAL9rN010PphM8yZB 7fsUftTpJ9wu7buWvwJP/IC/X; 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 1hMhM6-003AAO-34; Fri, 03 May 2019 18:12:38 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH v2 18/31] Convert ada-tasks.c to type-safe registry API Date: Fri, 3 May 2019 17:12:18 -0600 Message-Id: <20190503231231.8954-19-tom@tromey.com> In-Reply-To: <20190503231231.8954-1-tom@tromey.com> References: <20190503231231.8954-1-tom@tromey.com> This changes ada-tasks.c to use the type-safe registry API. 2019-05-01 Tom Tromey * ada-tasks.c (ada_tasks_pspace_data_handle): Change type. (get_ada_tasks_pspace_data): Update. (ada_tasks_pspace_data_cleanup): Remove. (_initialize_tasks): Update. (ada_tasks_inferior_data_handle): Change type. (get_ada_tasks_inferior_data): Update. (ada_tasks_inferior_data_cleanup): Remove. (struct ada_tasks_pspace_data): Add initializers. --- gdb/ChangeLog | 11 +++++++++ gdb/ada-tasks.c | 59 ++++++++++++------------------------------------- 2 files changed, 25 insertions(+), 45 deletions(-) diff --git a/gdb/ada-tasks.c b/gdb/ada-tasks.c index ccabc631040..762fb868e75 100644 --- a/gdb/ada-tasks.c +++ b/gdb/ada-tasks.c @@ -142,35 +142,27 @@ struct ada_tasks_pspace_data /* Nonzero if the data has been initialized. If set to zero, it means that the data has either not been initialized, or has potentially become stale. */ - int initialized_p; + int initialized_p = 0; /* The ATCB record type. */ - struct type *atcb_type; + struct type *atcb_type = nullptr; /* The ATCB "Common" component type. */ - struct type *atcb_common_type; + struct type *atcb_common_type = nullptr; /* The type of the "ll" field, from the atcb_common_type. */ - struct type *atcb_ll_type; + struct type *atcb_ll_type = nullptr; /* The type of the "call" field, from the atcb_common_type. */ - struct type *atcb_call_type; + struct type *atcb_call_type = nullptr; /* The index of various fields in the ATCB record and sub-records. */ - struct atcb_fieldnos atcb_fieldno; + struct atcb_fieldnos atcb_fieldno {}; }; /* Key to our per-program-space data. */ -static const struct program_space_data *ada_tasks_pspace_data_handle; - -/* A cleanup routine for our per-program-space data. */ -static void -ada_tasks_pspace_data_cleanup (struct program_space *pspace, void *arg) -{ - struct ada_tasks_pspace_data *data - = (struct ada_tasks_pspace_data *) arg; - xfree (data); -} +static const struct program_space_key + ada_tasks_pspace_data_handle; /* The kind of data structure used by the runtime to store the list of Ada tasks. */ @@ -245,7 +237,8 @@ struct ada_tasks_inferior_data }; /* Key to our per-inferior data. */ -static const struct inferior_data *ada_tasks_inferior_data_handle; +static const struct inferior_key + ada_tasks_inferior_data_handle; /* Return the ada-tasks module's data for the given program space (PSPACE). If none is found, add a zero'ed one now. @@ -257,13 +250,9 @@ get_ada_tasks_pspace_data (struct program_space *pspace) { struct ada_tasks_pspace_data *data; - data = ((struct ada_tasks_pspace_data *) - program_space_data (pspace, ada_tasks_pspace_data_handle)); + data = ada_tasks_pspace_data_handle.get (pspace); if (data == NULL) - { - data = XCNEW (struct ada_tasks_pspace_data); - set_program_space_data (pspace, ada_tasks_pspace_data_handle, data); - } + data = ada_tasks_pspace_data_handle.emplace (pspace); return data; } @@ -285,26 +274,13 @@ get_ada_tasks_inferior_data (struct inferior *inf) { struct ada_tasks_inferior_data *data; - data = ((struct ada_tasks_inferior_data *) - inferior_data (inf, ada_tasks_inferior_data_handle)); + data = ada_tasks_inferior_data_handle.get (inf); if (data == NULL) - { - data = new ada_tasks_inferior_data; - set_inferior_data (inf, ada_tasks_inferior_data_handle, data); - } + data = ada_tasks_inferior_data_handle.emplace (inf); return data; } -/* A cleanup routine for our per-inferior data. */ -static void -ada_tasks_inferior_data_cleanup (struct inferior *inf, void *arg) -{ - struct ada_tasks_inferior_data *data - = (struct ada_tasks_inferior_data *) arg; - delete data; -} - /* Return the task number of the task whose thread is THREAD, or zero if the task could not be found. */ @@ -1431,13 +1407,6 @@ ada_tasks_new_objfile_observer (struct objfile *objfile) void _initialize_tasks (void) { - ada_tasks_pspace_data_handle - = register_program_space_data_with_cleanup (NULL, - ada_tasks_pspace_data_cleanup); - ada_tasks_inferior_data_handle - = register_inferior_data_with_cleanup (NULL, - ada_tasks_inferior_data_cleanup); - /* Attach various observers. */ gdb::observers::normal_stop.attach (ada_tasks_normal_stop_observer); gdb::observers::new_objfile.attach (ada_tasks_new_objfile_observer);