From patchwork Fri May 3 23:12:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 32530 Received: (qmail 1398 invoked by alias); 3 May 2019 23:12:51 -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 478 invoked by uid 89); 3 May 2019 23:12:45 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-19.5 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=tagged 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:40 +0000 Received: from cm10.websitewelcome.com (cm10.websitewelcome.com [100.42.49.4]) by gateway22.websitewelcome.com (Postfix) with ESMTP id 172D65D70 for ; Fri, 3 May 2019 18:12:39 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id MhM7htJza2PzOMhM7hMXbs; Fri, 03 May 2019 18:12:39 -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=0q4ChRJm9xcMgEuYcuFwkMKm5FnR8LpDgTKGs69BBKk=; b=f6GKhODfIOpwmcHyRmV2jCf5RM BzMPnxiQQnI+uatXpfrkAW3et0foXjbD8D+XC017sB64TrMh4K2lxMarzZNKRDSxfq23oT04OP3VC 96qEFffQPGeXWgas3owsY38nx; 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-TO; Fri, 03 May 2019 18:12:38 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH v2 21/31] Convert ada-lang.c to type-safe registry API Date: Fri, 3 May 2019 17:12:21 -0600 Message-Id: <20190503231231.8954-22-tom@tromey.com> In-Reply-To: <20190503231231.8954-1-tom@tromey.com> References: <20190503231231.8954-1-tom@tromey.com> This changes ada-lang.c to use the type-safe registry API. 2019-05-01 Tom Tromey * ada-lang.c (struct ada_inferior_data): Add initializers. (ada_inferior_data): Change type. (ada_inferior_data_cleanup): Remove. (get_ada_inferior_data, ada_inferior_exit) (struct ada_pspace_data): Add initializers, destructor. (ada_pspace_data_handle): Change type. (get_ada_pspace_data): Update. (ada_pspace_data_cleanup): Remove. --- gdb/ChangeLog | 11 +++++++++ gdb/ada-lang.c | 63 +++++++++++++------------------------------------- 2 files changed, 27 insertions(+), 47 deletions(-) diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 1a566635b2d..0efe7ddb065 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -378,27 +378,16 @@ struct ada_inferior_data tagged types. With older versions of GNAT, this type was directly accessible through a component ("tsd") in the object tag. But this is no longer the case, so we cache it for each inferior. */ - struct type *tsd_type; + struct type *tsd_type = nullptr; /* The exception_support_info data. This data is used to determine how to implement support for Ada exception catchpoints in a given inferior. */ - const struct exception_support_info *exception_info; + const struct exception_support_info *exception_info = nullptr; }; /* Our key to this module's inferior data. */ -static const struct inferior_data *ada_inferior_data; - -/* A cleanup routine for our inferior data. */ -static void -ada_inferior_data_cleanup (struct inferior *inf, void *arg) -{ - struct ada_inferior_data *data; - - data = (struct ada_inferior_data *) inferior_data (inf, ada_inferior_data); - if (data != NULL) - xfree (data); -} +static const struct inferior_key ada_inferior_data; /* Return our inferior data for the given inferior (INF). @@ -413,12 +402,9 @@ get_ada_inferior_data (struct inferior *inf) { struct ada_inferior_data *data; - data = (struct ada_inferior_data *) inferior_data (inf, ada_inferior_data); + data = ada_inferior_data.get (inf); if (data == NULL) - { - data = XCNEW (struct ada_inferior_data); - set_inferior_data (inf, ada_inferior_data, data); - } + data = ada_inferior_data.emplace (inf); return data; } @@ -429,8 +415,7 @@ get_ada_inferior_data (struct inferior *inf) static void ada_inferior_exit (struct inferior *inf) { - ada_inferior_data_cleanup (inf, NULL); - set_inferior_data (inf, ada_inferior_data, NULL); + ada_inferior_data.clear (inf); } @@ -439,12 +424,18 @@ ada_inferior_exit (struct inferior *inf) /* This module's per-program-space data. */ struct ada_pspace_data { + ~ada_pspace_data () + { + if (sym_cache != NULL) + ada_free_symbol_cache (sym_cache); + } + /* The Ada symbol cache. */ - struct ada_symbol_cache *sym_cache; + struct ada_symbol_cache *sym_cache = nullptr; }; /* Key to our per-program-space data. */ -static const struct program_space_data *ada_pspace_data_handle; +static const struct program_space_key ada_pspace_data_handle; /* Return this module's data for the given program space (PSPACE). If not is found, add a zero'ed one now. @@ -456,29 +447,13 @@ get_ada_pspace_data (struct program_space *pspace) { struct ada_pspace_data *data; - data = ((struct ada_pspace_data *) - program_space_data (pspace, ada_pspace_data_handle)); + data = ada_pspace_data_handle.get (pspace); if (data == NULL) - { - data = XCNEW (struct ada_pspace_data); - set_program_space_data (pspace, ada_pspace_data_handle, data); - } + data = ada_pspace_data_handle.emplace (pspace); return data; } -/* The cleanup callback for this module's per-program-space data. */ - -static void -ada_pspace_data_cleanup (struct program_space *pspace, void *data) -{ - struct ada_pspace_data *pspace_data = (struct ada_pspace_data *) data; - - if (pspace_data->sym_cache != NULL) - ada_free_symbol_cache (pspace_data->sym_cache); - xfree (pspace_data); -} - /* Utilities */ /* If TYPE is a TYPE_CODE_TYPEDEF type, return the target type after @@ -14648,10 +14623,4 @@ DWARF attribute."), gdb::observers::new_objfile.attach (ada_new_objfile_observer); gdb::observers::free_objfile.attach (ada_free_objfile_observer); gdb::observers::inferior_exit.attach (ada_inferior_exit); - - /* Setup various context-specific data. */ - ada_inferior_data - = register_inferior_data_with_cleanup (NULL, ada_inferior_data_cleanup); - ada_pspace_data_handle - = register_program_space_data_with_cleanup (NULL, ada_pspace_data_cleanup); }