From patchwork Tue Apr 23 02:09:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 32367 Received: (qmail 16638 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 16552 invoked by uid 89); 23 Apr 2019 02:10:02 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-16.4 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=2172 X-HELO: gateway22.websitewelcome.com Received: from gateway22.websitewelcome.com (HELO gateway22.websitewelcome.com) (192.185.47.168) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 23 Apr 2019 02:10:00 +0000 Received: from cm12.websitewelcome.com (cm12.websitewelcome.com [100.42.49.8]) by gateway22.websitewelcome.com (Postfix) with ESMTP id 315475383 for ; Mon, 22 Apr 2019 21:09:59 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id IkshhkDhNiQerIkshhRYCS; 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=GDJyG9FbUIIb8LaMFE3ph2FM3YxL4lGhBfCB5YTpndQ=; b=tF9TrPCC7pD/tEBVIRMa4syi51 Dhx3Hift6NWkShUo4WfYWiL8erprYUwDSZ2tEnaiSA8jVE5SQa/g9UiZ7lW55p1YxGkWL6bn0pAjk QBao3LRls7F6njLcEeie7jwEj; 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-0L; Mon, 22 Apr 2019 21:09:59 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 03/14] Convert symbol_cache to type-safe registry API Date: Mon, 22 Apr 2019 20:09:44 -0600 Message-Id: <20190423020955.17356-4-tom@tromey.com> In-Reply-To: <20190423020955.17356-1-tom@tromey.com> References: <20190423020955.17356-1-tom@tromey.com> This changes the symbol_cache to use the type-safe registry API. gdb/ChangeLog 2019-04-22 Tom Tromey * symtab.c (struct symbol_cache): Add destructor and initializers. (symbol_cache_key): Move. Change type. (make_symbol_cache, free_symbol_cache): Remove. (get_symbol_cache): Update. (symbol_cache_cleanup): Remove. (ALL_PSPACES, symbol_cache_flush) (maintenance_print_symbol_cache) (maintenance_print_symbol_cache_statistics, _initialize_symtab): Update. --- gdb/ChangeLog | 13 +++++++++ gdb/symtab.c | 75 +++++++++++++++------------------------------------ 2 files changed, 34 insertions(+), 54 deletions(-) diff --git a/gdb/symtab.c b/gdb/symtab.c index cf97a1d18e2..2e5fbbedde2 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -119,10 +119,6 @@ struct main_info 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; - /* The default symbol cache size. There is no extra cpu cost for large N (except when flushing the cache, which is rare). The value here is just a first attempt. A better default @@ -214,10 +210,22 @@ struct block_symbol_cache struct symbol_cache { - struct block_symbol_cache *global_symbols; - struct block_symbol_cache *static_symbols; + symbol_cache () = default; + + ~symbol_cache () + { + xfree (global_symbols); + xfree (static_symbols); + } + + struct block_symbol_cache *global_symbols = nullptr; + struct block_symbol_cache *static_symbols = nullptr; }; +/* Program space key for finding its symbol cache. */ + +static const program_space_key symbol_cache_key; + /* When non-zero, print debugging messages related to symtab creation. */ unsigned int symtab_create_debug = 0; @@ -1226,57 +1234,23 @@ resize_symbol_cache (struct symbol_cache *cache, unsigned int new_size) } } -/* Make a symbol cache of size SIZE. */ - -static struct symbol_cache * -make_symbol_cache (unsigned int size) -{ - struct symbol_cache *cache; - - cache = XCNEW (struct symbol_cache); - resize_symbol_cache (cache, symbol_cache_size); - return cache; -} - -/* Free the space used by CACHE. */ - -static void -free_symbol_cache (struct symbol_cache *cache) -{ - xfree (cache->global_symbols); - xfree (cache->static_symbols); - xfree (cache); -} - /* Return the symbol cache of PSPACE. Create one if it doesn't exist yet. */ static struct symbol_cache * get_symbol_cache (struct program_space *pspace) { - struct symbol_cache *cache - = (struct symbol_cache *) program_space_data (pspace, symbol_cache_key); + struct symbol_cache *cache = symbol_cache_key.get (pspace); if (cache == NULL) { - cache = make_symbol_cache (symbol_cache_size); - set_program_space_data (pspace, symbol_cache_key, cache); + cache = symbol_cache_key.emplace (pspace); + resize_symbol_cache (cache, symbol_cache_size); } return cache; } -/* Delete the symbol cache of PSPACE. - Called when PSPACE is destroyed. */ - -static void -symbol_cache_cleanup (struct program_space *pspace, void *data) -{ - struct symbol_cache *cache = (struct symbol_cache *) data; - - free_symbol_cache (cache); -} - /* Set the size of the symbol cache in all program spaces. */ static void @@ -1286,8 +1260,7 @@ set_symbol_cache_size (unsigned int new_size) ALL_PSPACES (pspace) { - struct symbol_cache *cache - = (struct symbol_cache *) program_space_data (pspace, symbol_cache_key); + struct symbol_cache *cache = symbol_cache_key.get (pspace); /* The pspace could have been created but not have a cache yet. */ if (cache != NULL) @@ -1443,8 +1416,7 @@ symbol_cache_mark_not_found (struct block_symbol_cache *bsc, static void symbol_cache_flush (struct program_space *pspace) { - struct symbol_cache *cache - = (struct symbol_cache *) program_space_data (pspace, symbol_cache_key); + struct symbol_cache *cache = symbol_cache_key.get (pspace); int pass; if (cache == NULL) @@ -1558,8 +1530,7 @@ maintenance_print_symbol_cache (const char *args, int from_tty) : "(no object file)"); /* If the cache hasn't been created yet, avoid creating one. */ - cache - = (struct symbol_cache *) program_space_data (pspace, symbol_cache_key); + cache = symbol_cache_key.get (pspace); if (cache == NULL) printf_filtered (" \n"); else @@ -1630,8 +1601,7 @@ maintenance_print_symbol_cache_statistics (const char *args, int from_tty) : "(no object file)"); /* If the cache hasn't been created yet, avoid creating one. */ - cache - = (struct symbol_cache *) program_space_data (pspace, symbol_cache_key); + cache = symbol_cache_key.get (pspace); if (cache == NULL) printf_filtered (" empty, no stats available\n"); else @@ -6037,9 +6007,6 @@ _initialize_symtab (void) { initialize_ordinary_address_classes (); - symbol_cache_key - = register_program_space_data_with_cleanup (NULL, symbol_cache_cleanup); - add_info ("variables", info_variables_command, info_print_args_help (_("\ All global and static variable names or those matching REGEXPs.\n\