public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH v2 03/31] Convert symbol_cache to type-safe registry API
Date: Fri, 03 May 2019 23:12:00 -0000	[thread overview]
Message-ID: <20190503231231.8954-4-tom@tromey.com> (raw)
In-Reply-To: <20190503231231.8954-1-tom@tromey.com>

This changes the symbol_cache to use the type-safe registry API.

2019-04-22  Tom Tromey  <tom@tromey.com>

	* 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_info> 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> 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 ("  <empty>\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\
-- 
2.17.2

  parent reply	other threads:[~2019-05-03 23:12 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-03 23:12 [PATCH v2 00/31] Add a type-safe API to registries Tom Tromey
2019-05-03 23:12 ` [PATCH v2 01/31] Add a type-safe C++ interface to a registry Tom Tromey
2019-05-03 23:12 ` [PATCH v2 24/31] Convert mdebugread.c to type-safe registry API Tom Tromey
2019-05-03 23:12 ` [PATCH v2 07/31] Convert objfiles.c " Tom Tromey
2019-05-03 23:12 ` [PATCH v2 10/31] Convert symfile-debug.c " Tom Tromey
2019-05-03 23:12 ` [PATCH v2 19/31] Convert fbsd-tdep.c " Tom Tromey
2019-05-06 20:56   ` John Baldwin
2019-05-08 17:58     ` Tom Tromey
2019-05-08 22:06       ` Tom Tromey
2019-05-03 23:12 ` [PATCH v2 12/31] Convert linux-tdep.c " Tom Tromey
2019-05-03 23:12 ` [PATCH v2 13/31] Convert breakpoint.c " Tom Tromey
2019-05-03 23:12 ` [PATCH v2 08/31] Convert auto-load.c " Tom Tromey
2019-05-03 23:12 ` [PATCH v2 18/31] Convert ada-tasks.c " Tom Tromey
2019-05-03 23:12 ` [PATCH v2 20/31] Convert coffread.c " Tom Tromey
2019-05-03 23:12 ` [PATCH v2 04/31] Convert target dcache " Tom Tromey
2019-05-03 23:12 ` [PATCH v2 16/31] Convert xcoffread.c " Tom Tromey
2019-05-03 23:12 ` [PATCH v2 25/31] Convert elfread.c " Tom Tromey
2019-05-03 23:12 ` [PATCH v2 21/31] Convert ada-lang.c " Tom Tromey
2019-05-03 23:12 ` [PATCH v2 06/31] Convert break-catch-syscall.c " Tom Tromey
2019-05-03 23:12 ` [PATCH v2 17/31] Convert probes " Tom Tromey
2019-05-03 23:12 ` Tom Tromey [this message]
2019-05-03 23:12 ` [PATCH v2 05/31] Convert inflow " Tom Tromey
2019-05-03 23:12 ` [PATCH v2 15/31] Convert solib-svr4.c " Tom Tromey
2019-05-03 23:12 ` [PATCH v2 23/31] Add a noop deleter Tom Tromey
2019-05-03 23:13 ` [PATCH v2 29/31] Convert objc-lang.c to type-safe registry API Tom Tromey
2019-05-03 23:13 ` [PATCH v2 26/31] Convert hppa-tdep.c " Tom Tromey
2019-05-03 23:13 ` [PATCH v2 14/31] Convert remote.c " Tom Tromey
2019-05-03 23:13 ` [PATCH v2 22/31] Convert nto-tdep.c " Tom Tromey
2019-05-03 23:13 ` [PATCH v2 09/31] Convert dwarf2_per_objfile " Tom Tromey
2019-05-03 23:13 ` [PATCH v2 11/31] Convert auxv.c " Tom Tromey
2019-05-03 23:13 ` [PATCH v2 28/31] Convert stabsread.c " Tom Tromey
2019-05-03 23:13 ` [PATCH v2 02/31] Convert main_info " Tom Tromey
2019-05-03 23:13 ` [PATCH v2 27/31] Remove mips_pdr_data Tom Tromey
2019-05-03 23:31 ` [PATCH v2 31/31] Convert gdbtypes.c to type-safe registry API Tom Tromey
2019-05-03 23:31 ` [PATCH v2 30/31] Convert dwarf2-frame.c " Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190503231231.8954-4-tom@tromey.com \
    --to=tom@tromey.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).