From patchwork Fri May 3 23:12:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 32514 Received: (qmail 130295 invoked by alias); 3 May 2019 23:12:39 -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 130150 invoked by uid 89); 3 May 2019 23:12:38 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-18.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=hasn't, hasnt, rare X-HELO: gateway31.websitewelcome.com Received: from gateway31.websitewelcome.com (HELO gateway31.websitewelcome.com) (192.185.143.38) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 03 May 2019 23:12:36 +0000 Received: from cm16.websitewelcome.com (cm16.websitewelcome.com [100.42.49.19]) by gateway31.websitewelcome.com (Postfix) with ESMTP id 54E7DC394 for ; Fri, 3 May 2019 18:12:34 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id MhM2h1xym4FKpMhM2hS2k0; Fri, 03 May 2019 18:12:34 -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=SbudeMSPK8eEQuufscORwQyzcOJnkB5gHjR6/+oDsjU=; b=wY8FvFmqweA++MVKwZdfgl9pBD J1W2q5DpM+1VyNQobJrIh2x7c1bgL9Vgo+cZO5nUKNn7BFmRqT0+uFdJT0wA1qr9lNzuYRzPfShrt 1VldHcXYCWKjagBKBO3aAqHoE; 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-Su; Fri, 03 May 2019 18:12:33 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH v2 03/31] Convert symbol_cache to type-safe registry API Date: Fri, 3 May 2019 17:12:03 -0600 Message-Id: <20190503231231.8954-4-tom@tromey.com> In-Reply-To: <20190503231231.8954-1-tom@tromey.com> References: <20190503231231.8954-1-tom@tromey.com> This changes the symbol_cache to use the type-safe registry API. 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\