From patchwork Fri May 3 23:12:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 32509 Received: (qmail 129886 invoked by alias); 3 May 2019 23:12:37 -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 129787 invoked by uid 89); 3 May 2019 23:12:36 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-17.7 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: gateway23.websitewelcome.com Received: from gateway23.websitewelcome.com (HELO gateway23.websitewelcome.com) (192.185.48.251) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 03 May 2019 23:12:35 +0000 Received: from cm13.websitewelcome.com (cm13.websitewelcome.com [100.42.49.6]) by gateway23.websitewelcome.com (Postfix) with ESMTP id C9E01455A for ; Fri, 3 May 2019 18:12:33 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id MhM1hZYezYTGMMhM1hdolZ; Fri, 03 May 2019 18:12:33 -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=ZzgxgeKbJFl/HWMVztLnbN7heuzIAARHZb4zs+50qR8=; b=KAOWL6xF3Gm6N8E8fADTQj2wA9 geDXw2eJm4MBEyUPPd+2MvrhXCozjrM0G1GElCtSSOHW6k00XPlqGFKrbCCp2/pJF8xvsiAv6qzbb AwIx59AbAKFHJJM6h3B3LFKbZ; 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 1hMhM1-003AAO-Jw; Fri, 03 May 2019 18:12:33 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH v2 02/31] Convert main_info to type-safe registry API Date: Fri, 3 May 2019 17:12:02 -0600 Message-Id: <20190503231231.8954-3-tom@tromey.com> In-Reply-To: <20190503231231.8954-1-tom@tromey.com> References: <20190503231231.8954-1-tom@tromey.com> This changes main_info to use the type-safe registry API. 2019-04-22 Tom Tromey * symtab.c (struct main_info): Add destructor and initializers. (main_progspace_key): Move. Change type. (get_main_info): Update. (main_info_cleanup): Remove. (_initialize_symtab): Update. --- gdb/ChangeLog | 8 ++++++++ gdb/symtab.c | 44 +++++++++++++++----------------------------- 2 files changed, 23 insertions(+), 29 deletions(-) diff --git a/gdb/symtab.c b/gdb/symtab.c index 16e641a830b..cf97a1d18e2 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -95,23 +95,30 @@ static struct block_symbol lookup_symbol_in_objfile (struct objfile *objfile, int block_index, const char *name, const domain_enum domain); -/* Program space key for finding name and language of "main". */ - -static const struct program_space_data *main_progspace_key; - /* Type of the data stored on the program space. */ struct main_info { + main_info () = default; + + ~main_info () + { + xfree (name_of_main); + } + /* Name of "main". */ - char *name_of_main; + char *name_of_main = nullptr; /* Language of "main". */ - enum language language_of_main; + enum language language_of_main = language_unknown; }; +/* Program space key for finding name and language of "main". */ + +static const program_space_key main_progspace_key; + /* Program space key for finding its symbol cache. */ static const struct program_space_data *symbol_cache_key; @@ -5665,9 +5672,7 @@ make_source_files_completion_list (const char *text, const char *word) static struct main_info * get_main_info (void) { - struct main_info *info - = (struct main_info *) program_space_data (current_program_space, - main_progspace_key); + struct main_info *info = main_progspace_key.get (current_program_space); if (info == NULL) { @@ -5677,28 +5682,12 @@ get_main_info (void) gdb returned "main" as the name even if no function named "main" was defined the program; and this approach lets us keep compatibility. */ - info = XCNEW (struct main_info); - info->language_of_main = language_unknown; - set_program_space_data (current_program_space, main_progspace_key, - info); + info = main_progspace_key.emplace (current_program_space); } return info; } -/* A cleanup to destroy a struct main_info when a progspace is - destroyed. */ - -static void -main_info_cleanup (struct program_space *pspace, void *data) -{ - struct main_info *info = (struct main_info *) data; - - if (info != NULL) - xfree (info->name_of_main); - xfree (info); -} - static void set_main_name (const char *name, enum language lang) { @@ -6048,9 +6037,6 @@ _initialize_symtab (void) { initialize_ordinary_address_classes (); - main_progspace_key - = register_program_space_data_with_cleanup (NULL, main_info_cleanup); - symbol_cache_key = register_program_space_data_with_cleanup (NULL, symbol_cache_cleanup);