public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Subject: [PATCH v2 11/31] Use block_symbol::address in ada-lang.c
Date: Sun, 05 Nov 2023 11:11:49 -0700	[thread overview]
Message-ID: <20231105-split-objfile-2023-bound-sym-october-v2-11-dbd2d158bbc3@tromey.com> (raw)
In-Reply-To: <20231105-split-objfile-2023-bound-sym-october-v2-0-dbd2d158bbc3@tromey.com>

This changes ada-lang.c to use block_symbol::address.
---
 gdb/ada-lang.c | 98 ++++++++++++++++++++++++++--------------------------------
 1 file changed, 43 insertions(+), 55 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 3391aaeccb3..03f405778e6 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -108,8 +108,7 @@ static void ada_add_all_symbols (std::vector<struct block_symbol> &,
 static int is_nonfunction (const std::vector<struct block_symbol> &);
 
 static void add_defn_to_vec (std::vector<struct block_symbol> &,
-			     struct symbol *,
-			     const struct block *);
+			     block_symbol);
 
 static int possible_user_operator_p (enum exp_opcode, struct value **);
 
@@ -160,8 +159,6 @@ static struct value *value_subscript_packed (struct value *, int,
 static struct value *coerce_unspec_val_to_type (struct value *,
 						struct type *);
 
-static int lesseq_defined_than (struct symbol *, struct symbol *);
-
 static int equiv_types (struct type *, struct type *);
 
 static int is_name_suffix (const char *);
@@ -336,12 +333,9 @@ struct cache_entry
   std::string name;
   /* The namespace used during the lookup.  */
   domain_enum domain = UNDEF_DOMAIN;
-  /* The symbol returned by the lookup, or NULL if no matching symbol
-     was found.  */
-  struct symbol *sym = nullptr;
-  /* The block where the symbol was found, or NULL if no matching
-     symbol was found.  */
-  const struct block *block = nullptr;
+  /* The symbol returned by the lookup.  The 'symbol' field will be
+     NULL if no matching symbol was found.  */
+  block_symbol sym = {};
 };
 
 /* The symbol cache uses this type when searching.  */
@@ -4685,8 +4679,7 @@ ada_clear_symbol_cache (program_space *pspace)
    SYM.  Same principle for BLOCK if not NULL.  */
 
 static int
-lookup_cached_symbol (const char *name, domain_enum domain,
-		      struct symbol **sym, const struct block **block)
+lookup_cached_symbol (const char *name, domain_enum domain, block_symbol *sym)
 {
   htab_t tab = get_ada_pspace_data (current_program_space);
   cache_entry_search search;
@@ -4699,18 +4692,17 @@ lookup_cached_symbol (const char *name, domain_enum domain,
     return 0;
   if (sym != nullptr)
     *sym = e->sym;
-  if (block != nullptr)
-    *block = e->block;
   return 1;
 }
 
-/* Assuming that (SYM, BLOCK) is the result of the lookup of NAME
+/* Assuming that SYM is the result of the lookup of NAME
    in domain DOMAIN, save this result in our symbol cache.  */
 
 static void
-cache_symbol (const char *name, domain_enum domain, struct symbol *sym,
-	      const struct block *block)
+cache_symbol (const char *name, domain_enum domain, block_symbol bsym)
 {
+  symbol *sym = bsym.symbol;
+
   /* Symbols for builtin types don't have a block.
      For now don't cache such symbols.  */
   if (sym != NULL && !sym->is_objfile_owned ())
@@ -4724,7 +4716,7 @@ cache_symbol (const char *name, domain_enum domain, struct symbol *sym,
     {
       const blockvector &bv = *sym->symtab ()->compunit ()->blockvector ();
 
-      if (bv.global_block () != block && bv.static_block () != block)
+      if (bv.global_block () != bsym.block && bv.static_block () != bsym.block)
 	return;
     }
 
@@ -4739,8 +4731,7 @@ cache_symbol (const char *name, domain_enum domain, struct symbol *sym,
   cache_entry *e = new cache_entry;
   e->name = name;
   e->domain = domain;
-  e->sym = sym;
-  e->block = block;
+  e->sym = bsym;
 
   *slot = e;
 }
@@ -4768,13 +4759,12 @@ static struct symbol *
 standard_lookup (const char *name, const struct block *block,
 		 domain_enum domain)
 {
-  /* Initialize it just to avoid a GCC false warning.  */
-  struct block_symbol sym = {};
+  struct block_symbol sym;
 
-  if (lookup_cached_symbol (name, domain, &sym.symbol, NULL))
+  if (lookup_cached_symbol (name, domain, &sym))
     return sym.symbol;
   ada_lookup_encoded_symbol (name, block, domain, &sym);
-  cache_symbol (name, domain, sym.symbol, sym.block);
+  cache_symbol (name, domain, sym);
   return sym.symbol;
 }
 
@@ -4814,12 +4804,15 @@ equiv_types (struct type *type0, struct type *type1)
   return 0;
 }
 
-/* True iff SYM0 represents the same entity as SYM1, or one that is
-   no more defined than that of SYM1.  */
+/* True iff BSYM0 represents the same entity as BSYM1, or one that is
+   no more defined than that of BSYM1.  */
 
 static int
-lesseq_defined_than (struct symbol *sym0, struct symbol *sym1)
+lesseq_defined_than (block_symbol bsym0, block_symbol bsym1)
 {
+  symbol *sym0 = bsym0.symbol;
+  symbol *sym1 = bsym1.symbol;
+
   if (sym0 == sym1)
     return 1;
   if (sym0->domain () != sym1->domain ()
@@ -4853,7 +4846,7 @@ lesseq_defined_than (struct symbol *sym0, struct symbol *sym1)
 	const char *name0 = sym0->linkage_name ();
 	const char *name1 = sym1->linkage_name ();
 	return (strcmp (name0, name1) == 0
-		&& sym0->value_address () == sym1->value_address ());
+		&& bsym0.address () == bsym1.address ());
       }
 
     default:
@@ -4866,8 +4859,7 @@ lesseq_defined_than (struct symbol *sym0, struct symbol *sym1)
 
 static void
 add_defn_to_vec (std::vector<struct block_symbol> &result,
-		 struct symbol *sym,
-		 const struct block *block)
+		 block_symbol info)
 {
   /* Do not try to complete stub types, as the debugger is probably
      already scanning all symbols matching a certain name at the
@@ -4880,19 +4872,15 @@ add_defn_to_vec (std::vector<struct block_symbol> &result,
 
   for (int i = result.size () - 1; i >= 0; i -= 1)
     {
-      if (lesseq_defined_than (sym, result[i].symbol))
+      if (lesseq_defined_than (info, result[i]))
 	return;
-      else if (lesseq_defined_than (result[i].symbol, sym))
+      else if (lesseq_defined_than (result[i], info))
 	{
-	  result[i].symbol = sym;
-	  result[i].block = block;
+	  result[i] = info;
 	  return;
 	}
     }
 
-  struct block_symbol info;
-  info.symbol = sym;
-  info.block = block;
   result.push_back (info);
 }
 
@@ -5382,13 +5370,12 @@ struct match_data
 bool
 match_data::operator() (struct block_symbol *bsym)
 {
-  const struct block *block = bsym->block;
   struct symbol *sym = bsym->symbol;
 
   if (sym == NULL)
     {
       if (!found_sym && arg_sym != NULL)
-	add_defn_to_vec (*resultp, arg_sym, block);
+	add_defn_to_vec (*resultp, { arg_sym, bsym->block });
       found_sym = false;
       arg_sym = NULL;
     }
@@ -5401,7 +5388,7 @@ match_data::operator() (struct block_symbol *bsym)
       else
 	{
 	  found_sym = true;
-	  add_defn_to_vec (*resultp, sym, block);
+	  add_defn_to_vec (*resultp, *bsym);
 	}
     }
   return true;
@@ -5651,8 +5638,6 @@ ada_add_all_symbols (std::vector<struct block_symbol> &result,
 		     int full_search,
 		     int *made_global_lookup_p)
 {
-  struct symbol *sym;
-
   if (made_global_lookup_p)
     *made_global_lookup_p = 0;
 
@@ -5687,11 +5672,11 @@ ada_add_all_symbols (std::vector<struct block_symbol> &result,
      already performed this search before.  If we have, then return
      the same result.  */
 
-  if (lookup_cached_symbol (ada_lookup_name (lookup_name),
-			    domain, &sym, &block))
+  block_symbol sym;
+  if (lookup_cached_symbol (ada_lookup_name (lookup_name), domain, &sym))
     {
-      if (sym != NULL)
-	add_defn_to_vec (result, sym, block);
+      if (sym.symbol != nullptr)
+	add_defn_to_vec (result, sym);
       return;
     }
 
@@ -5739,11 +5724,10 @@ ada_lookup_symbol_list_worker (const lookup_name_info &lookup_name,
   remove_extra_symbols (results);
 
   if (results.empty () && full_search && syms_from_global_search)
-    cache_symbol (ada_lookup_name (lookup_name), domain, NULL, NULL);
+    cache_symbol (ada_lookup_name (lookup_name), domain, {});
 
   if (results.size () == 1 && full_search && syms_from_global_search)
-    cache_symbol (ada_lookup_name (lookup_name), domain,
-		  results[0].symbol, results[0].block);
+    cache_symbol (ada_lookup_name (lookup_name), domain, results[0]);
 
   remove_irrelevant_renamings (&results, block);
   return results;
@@ -6087,7 +6071,7 @@ ada_add_block_symbols (std::vector<struct block_symbol> &result,
 	      else
 		{
 		  found_sym = true;
-		  add_defn_to_vec (result, sym, block);
+		  add_defn_to_vec (result, { sym, block });
 		}
 	    }
 	}
@@ -6100,7 +6084,7 @@ ada_add_block_symbols (std::vector<struct block_symbol> &result,
 
   if (!found_sym && arg_sym != NULL)
     {
-      add_defn_to_vec (result, arg_sym, block);
+      add_defn_to_vec (result, { arg_sym, block });
     }
 
   if (!lookup_name.ada ().wild_match_p ())
@@ -6136,7 +6120,7 @@ ada_add_block_symbols (std::vector<struct block_symbol> &result,
 		    else
 		      {
 			found_sym = true;
-			add_defn_to_vec (result, sym, block);
+			add_defn_to_vec (result, { sym, block });
 		      }
 		  }
 	      }
@@ -6147,7 +6131,7 @@ ada_add_block_symbols (std::vector<struct block_symbol> &result,
 	 They aren't parameters, right?  */
       if (!found_sym && arg_sym != NULL)
 	{
-	  add_defn_to_vec (result, arg_sym, block);
+	  add_defn_to_vec (result, { arg_sym, block });
 	}
     }
 }
@@ -12999,8 +12983,10 @@ ada_add_exceptions_from_frame (compiled_regex *preg,
 	    default:
 	      if (ada_is_exception_sym (sym))
 		{
+		  block_symbol bsym { sym, block };
+
 		  struct ada_exc_info info = {sym->print_name (),
-					      sym->value_address ()};
+					      bsym.address ()};
 
 		  exceptions->push_back (info);
 		}
@@ -13075,8 +13061,10 @@ ada_add_global_exceptions (compiled_regex *preg,
 		if (ada_is_non_standard_exception_sym (sym)
 		    && name_matches_regex (sym->natural_name (), preg))
 		  {
+		    block_symbol bsym { sym, b };
+
 		    struct ada_exc_info info
-		      = {sym->print_name (), sym->value_address ()};
+		      = {sym->print_name (), bsym.address ()};
 
 		    exceptions->push_back (info);
 		  }

-- 
2.41.0


  parent reply	other threads:[~2023-11-05 18:11 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-05 18:11 [PATCH v2 00/31] Baby step for objfile splitting Tom Tromey
2023-11-05 18:11 ` [PATCH v2 01/31] Introduce block-symbol.h Tom Tromey
2023-11-05 18:11 ` [PATCH v2 02/31] Add block_symbol::address Tom Tromey
2023-11-05 18:11 ` [PATCH v2 03/31] Add bound_symbol Tom Tromey
2023-11-05 18:11 ` [PATCH v2 04/31] Easy conversions to use block_symbol::address Tom Tromey
2023-11-05 18:11 ` [PATCH v2 05/31] Use block_symbol::address in ada-tasks.c Tom Tromey
2023-11-05 18:11 ` [PATCH v2 06/31] Use block_symbol::address in printcmd.c Tom Tromey
2023-11-05 18:11 ` [PATCH v2 07/31] Use bound_symbol::address in tracepoint.c Tom Tromey
2023-11-05 18:11 ` [PATCH v2 08/31] Use block_symbol::address " Tom Tromey
2023-11-05 18:11 ` [PATCH v2 09/31] Use block_symbol::address in ax-gdb.c Tom Tromey
2023-11-05 18:11 ` [PATCH v2 10/31] Use block_symbol::address in linespec.c Tom Tromey
2023-11-05 18:11 ` Tom Tromey [this message]
2023-11-05 18:11 ` [PATCH v2 12/31] Use bound_symbol::address in symmisc.c Tom Tromey
2023-11-05 18:11 ` [PATCH v2 13/31] Introduce read_var_value overload Tom Tromey
2023-11-05 18:11 ` [PATCH v2 14/31] Use read_var_value in gdb/compile Tom Tromey
2023-11-05 18:11 ` [PATCH v2 15/31] Return a block_symbol from find_pc_sect_function Tom Tromey
2023-11-05 18:11 ` [PATCH v2 16/31] Use read_var_value overload in finish_command_fsm Tom Tromey
2023-11-05 18:11 ` [PATCH v2 17/31] Use block_symbol in overload-handling code Tom Tromey
2023-11-05 18:11 ` [PATCH v2 18/31] Change evaluate_var_value to accept a block_symbol Tom Tromey
2023-11-05 18:11 ` [PATCH v2 19/31] Change value_of_variable to take " Tom Tromey
2023-11-05 18:11 ` [PATCH v2 20/31] Return a block_symbol from get_frame_function Tom Tromey
2023-11-05 18:11 ` [PATCH v2 21/31] Use read_var_value overload in return_command Tom Tromey
2023-11-05 18:12 ` [PATCH v2 22/31] Use read_var_value overload in py-finishbreakpoint.c Tom Tromey
2023-11-05 18:12 ` [PATCH v2 23/31] Use read_var_value overload in py-framefilter.c Tom Tromey
2023-11-05 18:12 ` [PATCH v2 24/31] Use read_var_value overload in Guile Tom Tromey
2023-11-05 18:12 ` [PATCH v2 25/31] Use read_var_value in read_frame_arg and read_frame_local Tom Tromey
2023-11-05 18:12 ` [PATCH v2 26/31] Change print_variable_and_value to take a block_symbol Tom Tromey
2023-11-05 18:12 ` [PATCH v2 27/31] Change find_frame_funname to return " Tom Tromey
2023-11-05 18:12 ` [PATCH v2 28/31] Change btrace_function::sym to " Tom Tromey
2023-11-05 18:12 ` [PATCH v2 29/31] Use read_var_value overload in Python Tom Tromey
2023-11-05 18:12 ` [PATCH v2 30/31] Remove the old read_var_value Tom Tromey
2023-11-05 18:12 ` [PATCH v2 31/31] Change language_defn::read_var_value to accept block_symbol Tom Tromey
2023-11-06 15:16 ` [PATCH v2 00/31] Baby step for objfile splitting Andrew Burgess
2023-11-07  3:36   ` Tom Tromey
2023-11-07 11:06     ` Andrew Burgess

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=20231105-split-objfile-2023-bound-sym-october-v2-11-dbd2d158bbc3@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).