[v2,17/30] Use domain_search_flags in lookup_symbol et al

Message ID 20240118-submit-domain-hacks-2-v2-17-aecab29fa104@tromey.com
State New
Headers
Series Restructure symbol domains |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 fail Patch failed to apply
linaro-tcwg-bot/tcwg_gdb_build--master-arm fail Patch failed to apply

Commit Message

Tom Tromey Jan. 18, 2024, 8:32 p.m. UTC
  This changes lookup_symbol and associated APIs to accept
domain_search_flags rather than a domain_enum.

Note that this introduces some new constants to Python and Guile.  I
chose to break out the documentation patch for this, because the
internals here do not change until a later patch, and it seemed
simpler to patch the docs just once, rather than twice.
---
 gdb/ada-lang.c                      |  10 +--
 gdb/ada-tasks.c                     |  17 +++--
 gdb/alpha-mdebug-tdep.c             |   2 +-
 gdb/ax-gdb.c                        |   5 +-
 gdb/block.c                         |  24 ++++---
 gdb/block.h                         |  15 ++--
 gdb/c-exp.y                         |  19 ++---
 gdb/c-lang.c                        |   2 +-
 gdb/c-valprint.c                    |   2 +-
 gdb/compile/compile-c-symbols.c     |  17 ++---
 gdb/compile/compile-cplus-symbols.c |  13 ++--
 gdb/compile/compile-cplus-types.c   |   8 +--
 gdb/compile/compile-object-load.c   |   6 +-
 gdb/cp-namespace.c                  |  51 ++++++-------
 gdb/cp-support.c                    |   6 +-
 gdb/cp-support.h                    |   8 +--
 gdb/d-exp.y                         |  12 ++--
 gdb/d-lang.c                        |   2 +-
 gdb/d-lang.h                        |   9 +--
 gdb/d-namespace.c                   |  24 +++----
 gdb/dwarf2/ada-imported.c           |   2 +-
 gdb/dwarf2/loc.c                    |   2 +-
 gdb/eval.c                          |   5 +-
 gdb/f-exp.y                         |   8 +--
 gdb/f-lang.c                        |   2 +-
 gdb/f-lang.h                        |   2 +-
 gdb/f-valprint.c                    |   2 +-
 gdb/fbsd-tdep.c                     |   5 +-
 gdb/frame.c                         |   3 +-
 gdb/ft32-tdep.c                     |   3 +-
 gdb/gdbtypes.c                      |  17 +++--
 gdb/gnu-v3-abi.c                    |   2 +-
 gdb/go-exp.y                        |   9 +--
 gdb/guile/scm-frame.c               |   2 +-
 gdb/guile/scm-symbol.c              |  17 +++--
 gdb/infrun.c                        |   2 +-
 gdb/language.c                      |   3 +-
 gdb/language.h                      |   2 +-
 gdb/linespec.c                      |   4 +-
 gdb/m2-exp.y                        |  10 +--
 gdb/mi/mi-cmd-stack.c               |   5 +-
 gdb/moxie-tdep.c                    |   3 +-
 gdb/objc-lang.c                     |   4 +-
 gdb/objfiles.h                      |   2 +-
 gdb/p-exp.y                         |  19 ++---
 gdb/p-valprint.c                    |   2 +-
 gdb/parse.c                         |   3 +-
 gdb/printcmd.c                      |   2 +-
 gdb/psymtab.c                       |   4 +-
 gdb/python/py-frame.c               |   3 +-
 gdb/python/py-objfile.c             |   6 +-
 gdb/python/py-symbol.c              |  22 +++---
 gdb/rust-lang.c                     |   7 +-
 gdb/rust-lang.h                     |   2 +-
 gdb/rust-parse.c                    |   8 +--
 gdb/source.c                        |   5 +-
 gdb/stack.c                         |   4 +-
 gdb/symfile-debug.c                 |  11 ++-
 gdb/symfile.c                       |   4 +-
 gdb/symtab.c                        | 138 +++++++++++++++++-------------------
 gdb/symtab.h                        |  23 +++---
 gdb/valops.c                        |  14 ++--
 gdb/value.c                         |   6 +-
 gdb/xstormy16-tdep.c                |   3 +-
 64 files changed, 342 insertions(+), 312 deletions(-)
  

Patch

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index a1fac3e8ad3..a15ea7b725e 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -13675,19 +13675,15 @@  class ada_language : public language_defn
 
   struct block_symbol lookup_symbol_nonlocal
 	(const char *name, const struct block *block,
-	 const domain_enum domain) const override
+	 const domain_search_flags domain) const override
   {
     struct block_symbol sym;
 
-    domain_search_flags flags = to_search_flags (domain);
-    if (domain == VAR_DOMAIN)
-      flags |= SEARCH_TYPE_DOMAIN | SEARCH_FUNCTION_DOMAIN;
-
     sym = ada_lookup_symbol (name,
 			     (block == nullptr
 			      ? nullptr
 			      : block->static_block ()),
-			     flags);
+			     domain);
     if (sym.symbol != NULL)
       return sym;
 
@@ -13703,7 +13699,7 @@  class ada_language : public language_defn
        languages, we search the primitive types this late and only after
        having searched the global symbols without success.  */
 
-    if (domain == VAR_DOMAIN)
+    if ((domain & SEARCH_TYPE_DOMAIN) != 0)
       {
 	struct gdbarch *gdbarch;
 
diff --git a/gdb/ada-tasks.c b/gdb/ada-tasks.c
index e4aacaf4b6a..fd3f5d1ead9 100644
--- a/gdb/ada-tasks.c
+++ b/gdb/ada-tasks.c
@@ -520,16 +520,17 @@  ada_get_tcb_types_info (void)
      C-like) lookups to get the first match.  */
 
   struct symbol *atcb_sym =
-    lookup_symbol_in_language (atcb_name, NULL, STRUCT_DOMAIN,
+    lookup_symbol_in_language (atcb_name, NULL, SEARCH_STRUCT_DOMAIN,
 			       language_c, NULL).symbol;
   const struct symbol *common_atcb_sym =
-    lookup_symbol_in_language (common_atcb_name, NULL, STRUCT_DOMAIN,
+    lookup_symbol_in_language (common_atcb_name, NULL, SEARCH_STRUCT_DOMAIN,
 			       language_c, NULL).symbol;
   const struct symbol *private_data_sym =
-    lookup_symbol_in_language (private_data_name, NULL, STRUCT_DOMAIN,
+    lookup_symbol_in_language (private_data_name, NULL, SEARCH_STRUCT_DOMAIN,
 			       language_c, NULL).symbol;
   const struct symbol *entry_call_record_sym =
-    lookup_symbol_in_language (entry_call_record_name, NULL, STRUCT_DOMAIN,
+    lookup_symbol_in_language (entry_call_record_name, NULL,
+			       SEARCH_STRUCT_DOMAIN,
 			       language_c, NULL).symbol;
 
   if (atcb_sym == NULL || atcb_sym->type () == NULL)
@@ -537,7 +538,7 @@  ada_get_tcb_types_info (void)
       /* In Ravenscar run-time libs, the  ATCB does not have a dynamic
 	 size, so the symbol name differs.  */
       atcb_sym = lookup_symbol_in_language (atcb_name_fixed, NULL,
-					    STRUCT_DOMAIN, language_c,
+					    SEARCH_STRUCT_DOMAIN, language_c,
 					    NULL).symbol;
 
       if (atcb_sym == NULL || atcb_sym->type () == NULL)
@@ -929,7 +930,8 @@  ada_tasks_inferior_data_sniffer (struct ada_tasks_inferior_data *data)
       data->known_tasks_addr = msym.value_address ();
 
       /* Try to get pointer type and array length from the symtab.  */
-      sym = lookup_symbol_in_language (KNOWN_TASKS_NAME, NULL, VAR_DOMAIN,
+      sym = lookup_symbol_in_language (KNOWN_TASKS_NAME, NULL,
+				       SEARCH_VAR_DOMAIN,
 				       language_c, NULL).symbol;
       if (sym != NULL)
 	{
@@ -975,7 +977,8 @@  ada_tasks_inferior_data_sniffer (struct ada_tasks_inferior_data *data)
       data->known_tasks_addr = msym.value_address ();
       data->known_tasks_length = 1;
 
-      sym = lookup_symbol_in_language (KNOWN_TASKS_LIST, NULL, VAR_DOMAIN,
+      sym = lookup_symbol_in_language (KNOWN_TASKS_LIST, NULL,
+				       SEARCH_VAR_DOMAIN,
 				       language_c, NULL).symbol;
       if (sym != NULL && sym->value_address () != 0)
 	{
diff --git a/gdb/alpha-mdebug-tdep.c b/gdb/alpha-mdebug-tdep.c
index 1ba8e500e32..7691a53148a 100644
--- a/gdb/alpha-mdebug-tdep.c
+++ b/gdb/alpha-mdebug-tdep.c
@@ -106,7 +106,7 @@  find_proc_desc (CORE_ADDR pc)
 	   symbol reading.  */
 	sym = NULL;
       else
-	sym = lookup_symbol (MDEBUG_EFI_SYMBOL_NAME, b, LABEL_DOMAIN,
+	sym = lookup_symbol (MDEBUG_EFI_SYMBOL_NAME, b, SEARCH_LABEL_DOMAIN,
 			     0).symbol;
     }
 
diff --git a/gdb/ax-gdb.c b/gdb/ax-gdb.c
index deadbc1bc02..a08a5121527 100644
--- a/gdb/ax-gdb.c
+++ b/gdb/ax-gdb.c
@@ -1457,7 +1457,8 @@  gen_static_field (struct agent_expr *ax, struct axs_value *value,
   else
     {
       const char *phys_name = type->field (fieldno).loc_physname ();
-      struct symbol *sym = lookup_symbol (phys_name, 0, VAR_DOMAIN, 0).symbol;
+      struct symbol *sym = lookup_symbol (phys_name, 0,
+					  SEARCH_VAR_DOMAIN, 0).symbol;
 
       if (sym)
 	{
@@ -1548,7 +1549,7 @@  gen_maybe_namespace_elt (struct agent_expr *ax, struct axs_value *value,
 
   sym = cp_lookup_symbol_namespace (namespace_name, name,
 				    block_for_pc (ax->scope),
-				    VAR_DOMAIN);
+				    SEARCH_VAR_DOMAIN);
 
   if (sym.symbol == NULL)
     return 0;
diff --git a/gdb/block.c b/gdb/block.c
index 4b9307ea794..0bdd0f915c0 100644
--- a/gdb/block.c
+++ b/gdb/block.c
@@ -630,26 +630,32 @@  block_iterator_next (struct block_iterator *iterator)
 /* See block.h.  */
 
 bool
-best_symbol (struct symbol *a, const domain_enum domain)
+best_symbol (struct symbol *a, const domain_search_flags domain)
 {
-  return (a->domain () == domain
-	  && a->aclass () != LOC_UNRESOLVED);
+  if (a->aclass () == LOC_UNRESOLVED)
+    return false;
+
+  if ((domain & SEARCH_VAR_DOMAIN) != 0)
+    return a->domain () == VAR_DOMAIN;
+
+  return a->matches (domain);
 }
 
 /* See block.h.  */
 
 struct symbol *
-better_symbol (struct symbol *a, struct symbol *b, const domain_enum domain)
+better_symbol (struct symbol *a, struct symbol *b,
+	       const domain_search_flags domain)
 {
   if (a == NULL)
     return b;
   if (b == NULL)
     return a;
 
-  if (a->domain () == domain && b->domain () != domain)
+  if (a->matches (domain) && !b->matches (domain))
     return a;
 
-  if (b->domain () == domain && a->domain () != domain)
+  if (b->matches (domain) && !a->matches (domain))
     return b;
 
   if (a->aclass () != LOC_UNRESOLVED && b->aclass () == LOC_UNRESOLVED)
@@ -675,7 +681,7 @@  better_symbol (struct symbol *a, struct symbol *b, const domain_enum domain)
 struct symbol *
 block_lookup_symbol (const struct block *block, const char *name,
 		     symbol_name_match_type match_type,
-		     const domain_enum domain)
+		     const domain_search_flags domain)
 {
   lookup_name_info lookup_name (name, match_type);
 
@@ -730,7 +736,7 @@  block_lookup_symbol (const struct block *block, const char *name,
 
 struct symbol *
 block_lookup_symbol_primary (const struct block *block, const char *name,
-			     const domain_enum domain)
+			     const domain_search_flags domain)
 {
   struct symbol *sym, *other;
   struct mdict_iterator mdict_iter;
@@ -792,7 +798,7 @@  block_lookup_symbol_primary (const struct block *block, const char *name,
 
 struct symbol *
 block_find_symbol (const struct block *block, const lookup_name_info &name,
-		   const domain_enum domain, struct symbol **stub)
+		   const domain_search_flags domain, struct symbol **stub)
 {
   /* Verify BLOCK is STATIC_BLOCK or GLOBAL_BLOCK.  */
   gdb_assert (block->superblock () == NULL
diff --git a/gdb/block.h b/gdb/block.h
index 5c56518bfce..0c121941f05 100644
--- a/gdb/block.h
+++ b/gdb/block.h
@@ -554,28 +554,29 @@  typedef iterator_range<block_iterator_wrapper> block_iterator_range;
 
 /* Return true if symbol A is the best match possible for DOMAIN.  */
 
-extern bool best_symbol (struct symbol *a, const domain_enum domain);
+extern bool best_symbol (struct symbol *a, const domain_search_flags domain);
 
 /* Return symbol B if it is a better match than symbol A for DOMAIN.
    Otherwise return A.  */
 
 extern struct symbol *better_symbol (struct symbol *a, struct symbol *b,
-				     const domain_enum domain);
+				     const domain_search_flags domain);
 
 /* Search BLOCK for symbol NAME in DOMAIN.  */
 
 extern struct symbol *block_lookup_symbol (const struct block *block,
 					   const char *name,
 					   symbol_name_match_type match_type,
-					   const domain_enum domain);
+					   const domain_search_flags domain);
 
 /* Search BLOCK for symbol NAME in DOMAIN but only in primary symbol table of
    BLOCK.  BLOCK must be STATIC_BLOCK or GLOBAL_BLOCK.  Function is useful if
    one iterates all global/static blocks of an objfile.  */
 
-extern struct symbol *block_lookup_symbol_primary (const struct block *block,
-						   const char *name,
-						   const domain_enum domain);
+extern struct symbol *block_lookup_symbol_primary
+     (const struct block *block,
+      const char *name,
+      const domain_search_flags domain);
 
 /* Find symbol NAME in BLOCK and in DOMAIN.  This will return a
    matching symbol whose type is not a "opaque", see TYPE_IS_OPAQUE.
@@ -584,7 +585,7 @@  extern struct symbol *block_lookup_symbol_primary (const struct block *block,
 
 extern struct symbol *block_find_symbol (const struct block *block,
 					 const lookup_name_info &name,
-					 const domain_enum domain,
+					 const domain_search_flags domain,
 					 struct symbol **stub);
 
 /* Given a vector of pairs, allocate and build an obstack allocated
diff --git a/gdb/c-exp.y b/gdb/c-exp.y
index 8c0d86f68b5..fb85914805c 100644
--- a/gdb/c-exp.y
+++ b/gdb/c-exp.y
@@ -1087,9 +1087,10 @@  block	:	block COLONCOLON name
 			  std::string copy = copy_name ($3);
 			  struct symbol *tem
 			    = lookup_symbol (copy.c_str (), $1,
-					     VAR_DOMAIN, NULL).symbol;
+					     SEARCH_FUNCTION_DOMAIN,
+					     nullptr).symbol;
 
-			  if (!tem || tem->aclass () != LOC_BLOCK)
+			  if (tem == nullptr)
 			    error (_("No function \"%s\" in specified context."),
 				   copy.c_str ());
 			  $$ = tem->value_block (); }
@@ -1113,7 +1114,7 @@  variable:	block COLONCOLON name
 			  std::string copy = copy_name ($3);
 			  struct block_symbol sym
 			    = lookup_symbol (copy.c_str (), $1,
-					     VAR_DOMAIN, NULL);
+					     SEARCH_VFT, NULL);
 
 			  if (sym.symbol == 0)
 			    error (_("No symbol \"%s\" in specified context."),
@@ -1168,7 +1169,7 @@  variable:	qualified_name
 			  struct block_symbol sym
 			    = lookup_symbol (name.c_str (),
 					     (const struct block *) NULL,
-					     VAR_DOMAIN, NULL);
+					     SEARCH_VFT, NULL);
 			  pstate->push_symbol (name.c_str (), sym);
 			}
 	;
@@ -1833,7 +1834,7 @@  name_not_typename :	NAME
 			  $$.sym
 			    = lookup_symbol ($1.ptr,
 					     pstate->expression_context_block,
-					     VAR_DOMAIN,
+					     SEARCH_VFT,
 					     &is_a_field_of_this);
 			  $$.is_a_field_of_this
 			    = is_a_field_of_this.type != NULL;
@@ -2969,7 +2970,7 @@  lex_one_token (struct parser_state *par_state, bool *is_quoted_name)
 
 	    if (lookup_symbol (copy.c_str (),
 			       pstate->expression_context_block,
-			       VAR_DOMAIN,
+			       SEARCH_VFT,
 			       (par_state->language ()->la_language
 				== language_cplus ? &is_a_field_of_this
 				: NULL)).symbol
@@ -3037,7 +3038,7 @@  classify_name (struct parser_state *par_state, const struct block *block,
      we can refer to it unconditionally below.  */
   memset (&is_a_field_of_this, 0, sizeof (is_a_field_of_this));
 
-  bsym = lookup_symbol (copy.c_str (), block, VAR_DOMAIN,
+  bsym = lookup_symbol (copy.c_str (), block, SEARCH_VFT,
 			par_state->language ()->name_of_this ()
 			? &is_a_field_of_this : NULL);
 
@@ -3060,7 +3061,7 @@  classify_name (struct parser_state *par_state, const struct block *block,
 	{
 	  struct field_of_this_result inner_is_a_field_of_this;
 
-	  bsym = lookup_symbol (copy.c_str (), block, STRUCT_DOMAIN,
+	  bsym = lookup_symbol (copy.c_str (), block, SEARCH_STRUCT_DOMAIN,
 				&inner_is_a_field_of_this);
 	  if (bsym.symbol != NULL)
 	    {
@@ -3167,7 +3168,7 @@  classify_inner_name (struct parser_state *par_state,
   std::string copy = copy_name (yylval.ssym.stoken);
   /* N.B. We assume the symbol can only be in VAR_DOMAIN.  */
   yylval.ssym.sym = cp_lookup_nested_symbol (type, copy.c_str (), block,
-					     VAR_DOMAIN);
+					     SEARCH_VFT);
 
   /* If no symbol was found, search for a matching base class named
      COPY.  This will allow users to enter qualified names of class members
diff --git a/gdb/c-lang.c b/gdb/c-lang.c
index 2dfbd05c52f..ce711c4b4f6 100644
--- a/gdb/c-lang.c
+++ b/gdb/c-lang.c
@@ -1014,7 +1014,7 @@  class cplus_language : public language_defn
 
   struct block_symbol lookup_symbol_nonlocal
 	(const char *name, const struct block *block,
-	 const domain_enum domain) const override
+	 const domain_search_flags domain) const override
   {
     return cp_lookup_symbol_nonlocal (this, name, block, domain);
   }
diff --git a/gdb/c-valprint.c b/gdb/c-valprint.c
index 1731f0302a8..8911a169604 100644
--- a/gdb/c-valprint.c
+++ b/gdb/c-valprint.c
@@ -205,7 +205,7 @@  print_unpacked_pointer (struct type *type, struct type *elttype,
 	    {
 	      const char *search_name = msymbol.minsym->search_name ();
 	      wsym = lookup_symbol_search_name (search_name, NULL,
-						VAR_DOMAIN).symbol;
+						SEARCH_VAR_DOMAIN).symbol;
 	    }
 
 	  if (wsym)
diff --git a/gdb/compile/compile-c-symbols.c b/gdb/compile/compile-c-symbols.c
index f55438d9ccb..a8f4ca16225 100644
--- a/gdb/compile/compile-c-symbols.c
+++ b/gdb/compile/compile-c-symbols.c
@@ -210,7 +210,7 @@  convert_one_symbol (compile_c_instance *context,
 
 static void
 convert_symbol_sym (compile_c_instance *context, const char *identifier,
-		    struct block_symbol sym, domain_enum domain)
+		    struct block_symbol sym, domain_search_flags domain)
 {
   int is_local_symbol;
 
@@ -325,19 +325,19 @@  gcc_convert_symbol (void *datum,
 {
   compile_c_instance *context
     = static_cast<compile_c_instance *> (datum);
-  domain_enum domain;
+  domain_search_flags domain;
   int found = 0;
 
   switch (request)
     {
     case GCC_C_ORACLE_SYMBOL:
-      domain = VAR_DOMAIN;
+      domain = SEARCH_VFT;
       break;
     case GCC_C_ORACLE_TAG:
-      domain = STRUCT_DOMAIN;
+      domain = SEARCH_STRUCT_DOMAIN;
       break;
     case GCC_C_ORACLE_LABEL:
-      domain = LABEL_DOMAIN;
+      domain = SEARCH_LABEL_DOMAIN;
       break;
     default:
       gdb_assert_not_reached ("Unrecognized oracle request.");
@@ -355,7 +355,7 @@  gcc_convert_symbol (void *datum,
 	  convert_symbol_sym (context, identifier, sym, domain);
 	  found = 1;
 	}
-      else if (domain == VAR_DOMAIN)
+      else if (request == GCC_C_ORACLE_SYMBOL)
 	{
 	  struct bound_minimal_symbol bmsym;
 
@@ -398,8 +398,9 @@  gcc_symbol_address (void *datum, struct gcc_c_context *gcc_context,
       struct symbol *sym;
 
       /* We only need global functions here.  */
-      sym = lookup_symbol (identifier, NULL, VAR_DOMAIN, NULL).symbol;
-      if (sym != NULL && sym->aclass () == LOC_BLOCK)
+      sym = lookup_symbol (identifier, nullptr, SEARCH_FUNCTION_DOMAIN,
+			   nullptr).symbol;
+      if (sym != nullptr)
 	{
 	  if (compile_debug)
 	    gdb_printf (gdb_stdlog,
diff --git a/gdb/compile/compile-cplus-symbols.c b/gdb/compile/compile-cplus-symbols.c
index dbdabe94e1e..9d8e801ba3a 100644
--- a/gdb/compile/compile-cplus-symbols.c
+++ b/gdb/compile/compile-cplus-symbols.c
@@ -227,7 +227,7 @@  convert_one_symbol (compile_cplus_instance *instance,
 static void
 convert_symbol_sym (compile_cplus_instance *instance,
 		    const char *identifier, struct block_symbol sym,
-		    domain_enum domain)
+		    domain_search_flags domain)
 {
   /* If we found a symbol and it is not in the  static or global
      scope, then we should first convert any static or global scope
@@ -355,12 +355,12 @@  gcc_cplus_convert_symbol (void *datum,
 	 This will find variables in the current scope.  */
 
       struct block_symbol sym
-	= lookup_symbol (identifier, instance->block (), VAR_DOMAIN, nullptr);
+	= lookup_symbol (identifier, instance->block (), SEARCH_VFT, nullptr);
 
       if (sym.symbol != nullptr)
 	{
 	  found = true;
-	  convert_symbol_sym (instance, identifier, sym, VAR_DOMAIN);
+	  convert_symbol_sym (instance, identifier, sym, SEARCH_VFT);
 	}
 
       /* Then use linespec.c's multi-symbol search.  This should find
@@ -378,7 +378,7 @@  gcc_cplus_convert_symbol (void *datum,
 	    {
 	      found = true;
 	      convert_symbol_sym (instance, identifier, it,
-				  it.symbol->domain ());
+				  to_search_flags (it.symbol->domain ()));
 	    }
 	}
 
@@ -437,9 +437,10 @@  gcc_cplus_symbol_address (void *datum, struct gcc_cp_context *gcc_context,
   try
     {
       struct symbol *sym
-	= lookup_symbol (identifier, nullptr, VAR_DOMAIN, nullptr).symbol;
+	= lookup_symbol (identifier, nullptr, SEARCH_FUNCTION_DOMAIN,
+			 nullptr).symbol;
 
-      if (sym != nullptr && sym->aclass () == LOC_BLOCK)
+      if (sym != nullptr)
 	{
 	  if (compile_debug)
 	    gdb_printf (gdb_stdlog,
diff --git a/gdb/compile/compile-cplus-types.c b/gdb/compile/compile-cplus-types.c
index 90ce3f15e14..c8a25515359 100644
--- a/gdb/compile/compile-cplus-types.c
+++ b/gdb/compile/compile-cplus-types.c
@@ -154,7 +154,7 @@  type_name_to_scope (const char *type_name, const struct block *block)
 
       /* Look up the resulting name.  */
       struct block_symbol bsymbol
-	= lookup_symbol (lookup_name.c_str (), block, VAR_DOMAIN, nullptr);
+	= lookup_symbol (lookup_name.c_str (), block, SEARCH_VFT, nullptr);
 
       if (bsymbol.symbol != nullptr)
 	{
@@ -384,7 +384,7 @@  compile_cplus_instance::new_scope (const char *type_name, struct type *type)
 	  scope_component comp
 	    = {
 		decl_name (type->name ()).get (),
-		lookup_symbol (type->name (), block (), VAR_DOMAIN, nullptr)
+		lookup_symbol (type->name (), block (), SEARCH_VFT, nullptr)
 	      };
 	  scope.push_back (comp);
 	}
@@ -617,7 +617,7 @@  compile_cplus_convert_struct_or_union_members
 		const char *physname = type->field (i).loc_physname ();
 		struct block_symbol sym
 		  = lookup_symbol (physname, instance->block (),
-				   VAR_DOMAIN, nullptr);
+				   SEARCH_VFT, nullptr);
 
 		if (sym.symbol == nullptr)
 		  {
@@ -729,7 +729,7 @@  compile_cplus_convert_struct_or_union_methods (compile_cplus_instance *instance,
 	  gcc_type method_type;
 	  struct block_symbol sym
 	    = lookup_symbol (TYPE_FN_FIELD_PHYSNAME (methods, j),
-			     instance->block (), VAR_DOMAIN, nullptr);
+			     instance->block (), SEARCH_VFT, nullptr);
 
 	  if (sym.symbol == nullptr)
 	    {
diff --git a/gdb/compile/compile-object-load.c b/gdb/compile/compile-object-load.c
index b2cc3a1a042..e26f0f46048 100644
--- a/gdb/compile/compile-object-load.c
+++ b/gdb/compile/compile-object-load.c
@@ -437,7 +437,7 @@  get_out_value_type (struct symbol *func_sym, struct objfile *objfile,
       gdb_val_sym = block_lookup_symbol (block,
 					 COMPILE_I_EXPR_VAL,
 					 symbol_name_match_type::SEARCH_NAME,
-					 VAR_DOMAIN);
+					 SEARCH_VFT);
       if (gdb_val_sym == NULL)
 	continue;
 
@@ -463,7 +463,7 @@  get_out_value_type (struct symbol *func_sym, struct objfile *objfile,
 
   gdb_ptr_type_sym = block_lookup_symbol (block, COMPILE_I_EXPR_PTR_TYPE,
 					  symbol_name_match_type::SEARCH_NAME,
-					  VAR_DOMAIN);
+					  SEARCH_VFT);
   if (gdb_ptr_type_sym == NULL)
     error (_("No \"%s\" symbol found"), COMPILE_I_EXPR_PTR_TYPE);
   gdb_ptr_type = gdb_ptr_type_sym->type ();
@@ -652,7 +652,7 @@  compile_object_load (const compile_file_names &file_names,
   func_sym = lookup_global_symbol_from_objfile (objfile,
 						GLOBAL_BLOCK,
 						GCC_FE_WRAPPER_FUNCTION,
-						VAR_DOMAIN).symbol;
+						SEARCH_VFT).symbol;
   if (func_sym == NULL)
     error (_("Cannot find function \"%s\" in compiled module \"%s\"."),
 	   GCC_FE_WRAPPER_FUNCTION, objfile_name (objfile));
diff --git a/gdb/cp-namespace.c b/gdb/cp-namespace.c
index a573b1410d3..593340af350 100644
--- a/gdb/cp-namespace.c
+++ b/gdb/cp-namespace.c
@@ -42,7 +42,7 @@  static struct block_symbol
 			     const char *nested_name,
 			     const char *concatenated_name,
 			     const struct block *block,
-			     const domain_enum domain,
+			     const domain_search_flags domain,
 			     int basic_lookup, int is_in_anonymous);
 
 static struct type *cp_lookup_transparent_type_loop (const char *name,
@@ -129,7 +129,7 @@  cp_is_in_anonymous (const char *symbol_name)
 
 static struct block_symbol
 cp_basic_lookup_symbol (const char *name, const struct block *block,
-			const domain_enum domain, int is_in_anonymous)
+			const domain_search_flags domain, int is_in_anonymous)
 {
   struct block_symbol sym;
 
@@ -172,7 +172,7 @@  cp_basic_lookup_symbol (const char *name, const struct block *block,
 static struct block_symbol
 cp_lookup_bare_symbol (const struct language_defn *langdef,
 		       const char *name, const struct block *block,
-		       const domain_enum domain, int search)
+		       const domain_search_flags domain, int search)
 {
   struct block_symbol sym;
 
@@ -192,7 +192,7 @@  cp_lookup_bare_symbol (const struct language_defn *langdef,
      shared libraries we could search all of them only to find out the
      builtin type isn't defined in any of them.  This is common for types
      like "void".  */
-  if (langdef != NULL && domain == VAR_DOMAIN)
+  if (langdef != nullptr && (domain & SEARCH_TYPE_DOMAIN) != 0)
     {
       struct gdbarch *gdbarch;
 
@@ -251,7 +251,7 @@  cp_lookup_bare_symbol (const struct language_defn *langdef,
 static struct block_symbol
 cp_search_static_and_baseclasses (const char *name,
 				  const struct block *block,
-				  const domain_enum domain,
+				  const domain_search_flags domain,
 				  unsigned int prefix_len,
 				  int is_in_anonymous)
 {
@@ -273,9 +273,9 @@  cp_search_static_and_baseclasses (const char *name,
      symbol_matches_domain (which should be replaced with something
      else, but it's what we have today).  */
   block_symbol scope_sym = lookup_symbol_in_static_block (scope.c_str (),
-							  block, VAR_DOMAIN);
+							  block, SEARCH_VFT);
   if (scope_sym.symbol == NULL)
-    scope_sym = lookup_global_symbol (scope.c_str (), block, VAR_DOMAIN);
+    scope_sym = lookup_global_symbol (scope.c_str (), block, SEARCH_VFT);
   if (scope_sym.symbol == NULL)
     return {};
 
@@ -285,9 +285,9 @@  cp_search_static_and_baseclasses (const char *name,
      static variable.  E.g., "print 'function()::static_var'".  */
   if ((scope_type->code () == TYPE_CODE_FUNC
        || scope_type->code () == TYPE_CODE_METHOD)
-      && domain == VAR_DOMAIN)
+      && (domain & SEARCH_VAR_DOMAIN) != 0)
     return lookup_symbol (nested, scope_sym.symbol->value_block (),
-			  VAR_DOMAIN, NULL);
+			  domain, NULL);
 
   /* Look for a symbol named NESTED in this class/namespace.
      The caller is assumed to have already have done a basic lookup of NAME.
@@ -308,7 +308,7 @@  cp_search_static_and_baseclasses (const char *name,
 static struct block_symbol
 cp_lookup_symbol_in_namespace (const char *the_namespace, const char *name,
 			       const struct block *block,
-			       const domain_enum domain, int search)
+			       const domain_search_flags domain, int search)
 {
   char *concatenated_name = NULL;
   int is_in_anonymous;
@@ -382,7 +382,7 @@  static void
 cp_lookup_symbol_via_imports (const char *scope,
 			      const char *name,
 			      const struct block *block,
-			      const domain_enum domain,
+			      const domain_search_flags domain,
 			      const int search_scope_first,
 			      const int declaration_only,
 			      const int search_parents,
@@ -503,7 +503,7 @@  static struct block_symbol
 cp_lookup_symbol_via_imports (const char *scope,
 			      const char *name,
 			      const struct block *block,
-			      const domain_enum domain,
+			      const domain_search_flags domain,
 			      const int declaration_only,
 			      const int search_parents)
 {
@@ -560,13 +560,14 @@  struct block_symbol
 cp_lookup_symbol_imports_or_template (const char *scope,
 				      const char *name,
 				      const struct block *block,
-				      const domain_enum domain)
+				      const domain_search_flags domain)
 {
   struct symbol *function = block->function ();
 
   symbol_lookup_debug_printf
     ("cp_lookup_symbol_imports_or_template (%s, %s, %s, %s)",
-     scope, name, host_address_to_string (block), domain_name (domain));
+     scope, name, host_address_to_string (block),
+     domain_name (domain).c_str ());
 
   if (function != NULL && function->language () == language_cplus)
     {
@@ -646,7 +647,7 @@  cp_lookup_symbol_imports_or_template (const char *scope,
 static struct block_symbol
 cp_lookup_symbol_via_all_imports (const char *scope, const char *name,
 				  const struct block *block,
-				  const domain_enum domain)
+				  const domain_search_flags domain)
 {
   struct block_symbol sym;
 
@@ -671,13 +672,13 @@  struct block_symbol
 cp_lookup_symbol_namespace (const char *scope,
 			    const char *name,
 			    const struct block *block,
-			    const domain_enum domain)
+			    const domain_search_flags domain)
 {
   struct block_symbol sym;
 
   symbol_lookup_debug_printf ("cp_lookup_symbol_namespace (%s, %s, %s, %s)",
 			      scope, name, host_address_to_string (block),
-			      domain_name (domain));
+			      domain_name (domain).c_str ());
 
   /* First, try to find the symbol in the given namespace.  */
   sym = cp_lookup_symbol_in_namespace (scope, name, block, domain, 1);
@@ -711,7 +712,7 @@  static struct block_symbol
 lookup_namespace_scope (const struct language_defn *langdef,
 			const char *name,
 			const struct block *block,
-			const domain_enum domain,
+			const domain_search_flags domain,
 			const char *scope,
 			int scope_len)
 {
@@ -768,14 +769,15 @@  struct block_symbol
 cp_lookup_symbol_nonlocal (const struct language_defn *langdef,
 			   const char *name,
 			   const struct block *block,
-			   const domain_enum domain)
+			   const domain_search_flags domain)
 {
   struct block_symbol sym;
   const char *scope = block == nullptr ? "" : block->scope ();
 
   symbol_lookup_debug_printf
     ("cp_lookup_symbol_non_local (%s, %s (scope %s), %s)",
-     name, host_address_to_string (block), scope, domain_name (domain));
+     name, host_address_to_string (block), scope,
+     domain_name (domain).c_str ());
 
   /* First, try to find the symbol in the given namespace, and all
      containing namespaces.  */
@@ -826,7 +828,8 @@  cp_find_type_baseclass_by_name (struct type *parent_type, const char *name)
 
 static struct block_symbol
 find_symbol_in_baseclass (struct type *parent_type, const char *name,
-			  const struct block *block, const domain_enum domain,
+			  const struct block *block,
+			  const domain_search_flags domain,
 			  int is_in_anonymous)
 {
   int i;
@@ -869,7 +872,7 @@  cp_lookup_nested_symbol_1 (struct type *container_type,
 			   const char *nested_name,
 			   const char *concatenated_name,
 			   const struct block *block,
-			   const domain_enum domain,
+			   const domain_search_flags domain,
 			   int basic_lookup, int is_in_anonymous)
 {
   struct block_symbol sym;
@@ -933,7 +936,7 @@  struct block_symbol
 cp_lookup_nested_symbol (struct type *parent_type,
 			 const char *nested_name,
 			 const struct block *block,
-			 const domain_enum domain)
+			 const domain_search_flags domain)
 {
   /* type_name_or_error provides better error reporting using the
      original type.  */
@@ -948,7 +951,7 @@  cp_lookup_nested_symbol (struct type *parent_type,
       symbol_lookup_debug_printf ("cp_lookup_nested_symbol (%s, %s, %s, %s)",
 				  type_name != NULL ? type_name : "unnamed",
 				  nested_name, host_address_to_string (block),
-				  domain_name (domain));
+				  domain_name (domain).c_str ());
     }
 
   switch (parent_type->code ())
diff --git a/gdb/cp-support.c b/gdb/cp-support.c
index 3ce2f131b25..9a59d7632a1 100644
--- a/gdb/cp-support.c
+++ b/gdb/cp-support.c
@@ -151,7 +151,7 @@  inspect_type (struct demangle_parse_info *info,
 
   try
     {
-      sym = lookup_symbol (name, 0, VAR_DOMAIN, 0).symbol;
+      sym = lookup_symbol (name, 0, SEARCH_VFT, 0).symbol;
     }
   catch (const gdb_exception &except)
     {
@@ -505,7 +505,7 @@  replace_typedefs (struct demangle_parse_info *info,
 	      try
 		{
 		  sym = lookup_symbol (local_name.get (), 0,
-				       VAR_DOMAIN, 0).symbol;
+				       SEARCH_VFT, 0).symbol;
 		}
 	      catch (const gdb_exception &except)
 		{
@@ -1500,7 +1500,7 @@  cp_lookup_rtti_type (const char *name, const struct block *block)
 
   /* Use VAR_DOMAIN here as NAME may be a typedef.  PR 18141, 18417.
      Classes "live" in both STRUCT_DOMAIN and VAR_DOMAIN.  */
-  rtti_sym = lookup_symbol (name, block, VAR_DOMAIN, NULL).symbol;
+  rtti_sym = lookup_symbol (name, block, SEARCH_VFT, NULL).symbol;
 
   if (rtti_sym == NULL)
     {
diff --git a/gdb/cp-support.h b/gdb/cp-support.h
index a50b111bab8..f95b6f0f0e2 100644
--- a/gdb/cp-support.h
+++ b/gdb/cp-support.h
@@ -141,25 +141,25 @@  extern struct block_symbol cp_lookup_symbol_nonlocal
      (const struct language_defn *langdef,
       const char *name,
       const struct block *block,
-      const domain_enum domain);
+      const domain_search_flags domain);
 
 extern struct block_symbol
   cp_lookup_symbol_namespace (const char *the_namespace,
 			      const char *name,
 			      const struct block *block,
-			      const domain_enum domain);
+			      const domain_search_flags domain);
 
 extern struct block_symbol cp_lookup_symbol_imports_or_template
      (const char *scope,
       const char *name,
       const struct block *block,
-      const domain_enum domain);
+      const domain_search_flags domain);
 
 extern struct block_symbol
   cp_lookup_nested_symbol (struct type *parent_type,
 			   const char *nested_name,
 			   const struct block *block,
-			   const domain_enum domain);
+			   const domain_search_flags domain);
 
 struct type *cp_lookup_transparent_type (const char *name);
 
diff --git a/gdb/d-exp.y b/gdb/d-exp.y
index 6f7beae0dac..620d900709c 100644
--- a/gdb/d-exp.y
+++ b/gdb/d-exp.y
@@ -444,7 +444,7 @@  PrimaryExpression:
 		  /* Handle VAR, which could be local or global.  */
 		  sym = lookup_symbol (copy.c_str (),
 				       pstate->expression_context_block,
-				       VAR_DOMAIN, &is_a_field_of_this);
+				       SEARCH_VFT, &is_a_field_of_this);
 		  if (sym.symbol && sym.symbol->aclass () != LOC_TYPEDEF)
 		    {
 		      if (symbol_read_needs_frame (sym.symbol))
@@ -493,7 +493,7 @@  PrimaryExpression:
 			      sym =
 				lookup_symbol (name.c_str (),
 					       (const struct block *) NULL,
-					       VAR_DOMAIN, NULL);
+					       SEARCH_VFT, NULL);
 			      pstate->push_symbol (name.c_str (), sym);
 			    }
 			  else
@@ -1337,7 +1337,7 @@  classify_name (struct parser_state *par_state, const struct block *block)
 
   std::string copy = copy_name (yylval.sval);
 
-  sym = lookup_symbol (copy.c_str (), block, VAR_DOMAIN, &is_a_field_of_this);
+  sym = lookup_symbol (copy.c_str (), block, SEARCH_VFT, &is_a_field_of_this);
   if (sym.symbol && sym.symbol->aclass () == LOC_TYPEDEF)
     {
       yylval.tsym.type = sym.symbol->type ();
@@ -1346,9 +1346,11 @@  classify_name (struct parser_state *par_state, const struct block *block)
   else if (sym.symbol == NULL)
     {
       /* Look-up first for a module name, then a type.  */
-      sym = lookup_symbol (copy.c_str (), block, MODULE_DOMAIN, NULL);
+      sym = lookup_symbol (copy.c_str (), block, SEARCH_MODULE_DOMAIN,
+			   nullptr);
       if (sym.symbol == NULL)
-	sym = lookup_symbol (copy.c_str (), block, STRUCT_DOMAIN, NULL);
+	sym = lookup_symbol (copy.c_str (), block, SEARCH_STRUCT_DOMAIN,
+			     nullptr);
 
       if (sym.symbol != NULL)
 	{
diff --git a/gdb/d-lang.c b/gdb/d-lang.c
index 5b0307d44ac..6af57062ef9 100644
--- a/gdb/d-lang.c
+++ b/gdb/d-lang.c
@@ -171,7 +171,7 @@  class d_language : public language_defn
 
   struct block_symbol lookup_symbol_nonlocal
 	(const char *name, const struct block *block,
-	 const domain_enum domain) const override
+	 const domain_search_flags domain) const override
   {
     return d_lookup_symbol_nonlocal (this, name, block, domain);
   }
diff --git a/gdb/d-lang.h b/gdb/d-lang.h
index 1747ad90f24..ecf194d8155 100644
--- a/gdb/d-lang.h
+++ b/gdb/d-lang.h
@@ -69,10 +69,11 @@  extern const struct builtin_d_type *builtin_d_type (struct gdbarch *);
 
 /* Defined in d-namespace.c  */
 
-extern struct block_symbol d_lookup_symbol_nonlocal (const struct language_defn *,
-						     const char *,
-						     const struct block *,
-						     const domain_enum);
+extern struct block_symbol d_lookup_symbol_nonlocal
+     (const struct language_defn *,
+      const char *,
+      const struct block *,
+      const domain_search_flags);
 
 extern struct block_symbol d_lookup_nested_symbol (struct type *, const char *,
 						   const struct block *);
diff --git a/gdb/d-namespace.c b/gdb/d-namespace.c
index c110cbda057..3f8f7d8c24e 100644
--- a/gdb/d-namespace.c
+++ b/gdb/d-namespace.c
@@ -78,7 +78,7 @@  d_entire_prefix_len (const char *name)
 static struct block_symbol
 d_lookup_symbol (const struct language_defn *langdef,
 		 const char *name, const struct block *block,
-		 const domain_enum domain, int search)
+		 const domain_search_flags domain, int search)
 {
   struct block_symbol sym;
 
@@ -88,7 +88,7 @@  d_lookup_symbol (const struct language_defn *langdef,
 
   /* If we didn't find a definition for a builtin type in the static block,
      such as "ucent" which is a specialist type, search for it now.  */
-  if (langdef != NULL && domain == VAR_DOMAIN)
+  if (langdef != nullptr && (domain & SEARCH_TYPE_DOMAIN) != 0)
     {
       struct gdbarch *gdbarch;
 
@@ -166,7 +166,7 @@  d_lookup_symbol (const struct language_defn *langdef,
 static struct block_symbol
 d_lookup_symbol_in_module (const char *module, const char *name,
 			   const struct block *block,
-			   const domain_enum domain, int search)
+			   const domain_search_flags domain, int search)
 {
   char *concatenated_name = NULL;
 
@@ -198,7 +198,7 @@  d_lookup_symbol_in_module (const char *module, const char *name,
 static struct block_symbol
 lookup_module_scope (const struct language_defn *langdef,
 		     const char *name, const struct block *block,
-		     const domain_enum domain, const char *scope,
+		     const domain_search_flags domain, const char *scope,
 		     int scope_len)
 {
   char *module;
@@ -261,7 +261,7 @@  find_symbol_in_baseclass (struct type *parent_type, const char *name,
 
       /* Search this particular base class.  */
       sym = d_lookup_symbol_in_module (base_name, name, block,
-				       VAR_DOMAIN, 0);
+				       SEARCH_VFT, 0);
       if (sym.symbol != NULL)
 	break;
 
@@ -270,14 +270,14 @@  find_symbol_in_baseclass (struct type *parent_type, const char *name,
 	 what we want is possibly there.  */
       std::string concatenated_name = std::string (base_name) + "." + name;
       sym = lookup_symbol_in_static_block (concatenated_name.c_str (), block,
-					   VAR_DOMAIN);
+					   SEARCH_VFT);
       if (sym.symbol != NULL)
 	break;
 
       /* Nope.  We now have to search all static blocks in all objfiles,
 	 even if block != NULL, because there's no guarantees as to which
 	 symtab the symbol we want is in.  */
-      sym = lookup_static_symbol (concatenated_name.c_str (), VAR_DOMAIN);
+      sym = lookup_static_symbol (concatenated_name.c_str (), SEARCH_VFT);
       if (sym.symbol != NULL)
 	break;
 
@@ -320,7 +320,7 @@  d_lookup_nested_symbol (struct type *parent_type,
 	  const char *parent_name = type_name_or_error (saved_parent_type);
 	  struct block_symbol sym
 	    = d_lookup_symbol_in_module (parent_name, nested_name,
-					 block, VAR_DOMAIN, 0);
+					 block, SEARCH_VFT, 0);
 	  char *concatenated_name;
 
 	  if (sym.symbol != NULL)
@@ -337,7 +337,7 @@  d_lookup_nested_symbol (struct type *parent_type,
 	  xsnprintf (concatenated_name, size, "%s.%s",
 		     parent_name, nested_name);
 
-	  sym = lookup_static_symbol (concatenated_name, VAR_DOMAIN);
+	  sym = lookup_static_symbol (concatenated_name, SEARCH_VFT);
 	  if (sym.symbol != NULL)
 	    return sym;
 
@@ -361,7 +361,7 @@  d_lookup_nested_symbol (struct type *parent_type,
 static struct block_symbol
 d_lookup_symbol_imports (const char *scope, const char *name,
 			 const struct block *block,
-			 const domain_enum domain)
+			 const domain_search_flags domain)
 {
   struct using_direct *current;
   struct block_symbol sym;
@@ -473,7 +473,7 @@  d_lookup_symbol_imports (const char *scope, const char *name,
 static struct block_symbol
 d_lookup_symbol_module (const char *scope, const char *name,
 			const struct block *block,
-			const domain_enum domain)
+			const domain_search_flags domain)
 {
   struct block_symbol sym;
 
@@ -509,7 +509,7 @@  struct block_symbol
 d_lookup_symbol_nonlocal (const struct language_defn *langdef,
 			  const char *name,
 			  const struct block *block,
-			  const domain_enum domain)
+			  const domain_search_flags domain)
 {
   struct block_symbol sym;
   const char *scope = block == nullptr ? "" : block->scope ();
diff --git a/gdb/dwarf2/ada-imported.c b/gdb/dwarf2/ada-imported.c
index 7654c05742e..21f81bbcdea 100644
--- a/gdb/dwarf2/ada-imported.c
+++ b/gdb/dwarf2/ada-imported.c
@@ -103,7 +103,7 @@  ada_alias_get_block_value (const struct symbol *sym)
 {
   const char *name = get_imported_name (sym);
   block_symbol real_symbol = lookup_global_symbol (name, nullptr,
-						   VAR_DOMAIN);
+						   SEARCH_VFT);
   if (real_symbol.symbol == nullptr)
     error (_("could not find alias '%s' for function '%s'"),
 	   name, sym->print_name ());
diff --git a/gdb/dwarf2/loc.c b/gdb/dwarf2/loc.c
index 062bd12909f..f832507341a 100644
--- a/gdb/dwarf2/loc.c
+++ b/gdb/dwarf2/loc.c
@@ -625,7 +625,7 @@  func_get_frame_base_dwarf_block (struct symbol *framefunc, CORE_ADDR pc,
 value *
 compute_var_value (const char *name)
 {
-  struct block_symbol sym = lookup_symbol (name, nullptr, VAR_DOMAIN,
+  struct block_symbol sym = lookup_symbol (name, nullptr, SEARCH_VAR_DOMAIN,
 					   nullptr);
   if (sym.symbol != nullptr)
     return value_of_variable (sym.symbol, sym.block);
diff --git a/gdb/eval.c b/gdb/eval.c
index 495effe2d03..b25b10f342a 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -730,7 +730,7 @@  scope_operation::evaluate_funcall (struct type *expect_type,
       function = cp_lookup_symbol_namespace (type->name (),
 					     name.c_str (),
 					     get_selected_block (0),
-					     VAR_DOMAIN).symbol;
+					     SEARCH_FUNCTION_DOMAIN).symbol;
       if (function == NULL)
 	error (_("No symbol \"%s\" in namespace \"%s\"."),
 	       name.c_str (), type->name ());
@@ -1105,7 +1105,8 @@  eval_op_func_static_var (struct type *expect_type, struct expression *exp,
 {
   CORE_ADDR addr = func->address ();
   const block *blk = block_for_pc (addr);
-  struct block_symbol sym = lookup_symbol (var, blk, VAR_DOMAIN, NULL);
+  struct block_symbol sym = lookup_symbol (var, blk, SEARCH_VAR_DOMAIN,
+					   nullptr);
   if (sym.symbol == NULL)
     error (_("No symbol \"%s\" in specified context."), var);
   return evaluate_var_value (noside, sym.block, sym.symbol);
diff --git a/gdb/f-exp.y b/gdb/f-exp.y
index 7e45069c67e..faa53ba9dd0 100644
--- a/gdb/f-exp.y
+++ b/gdb/f-exp.y
@@ -1640,11 +1640,11 @@  yylex (void)
   {
     std::string tmp = copy_name (yylval.sval);
     struct block_symbol result;
-    const domain_enum lookup_domains[] =
+    const domain_search_flags lookup_domains[] =
     {
-      STRUCT_DOMAIN,
-      VAR_DOMAIN,
-      MODULE_DOMAIN
+      SEARCH_STRUCT_DOMAIN,
+      SEARCH_VFT,
+      SEARCH_MODULE_DOMAIN
     };
     int hextype;
 
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index c35c73a0eb7..d573c4f2fbb 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -1715,7 +1715,7 @@  f_language::search_name_hash (const char *name) const
 struct block_symbol
 f_language::lookup_symbol_nonlocal (const char *name,
 				    const struct block *block,
-				    const domain_enum domain) const
+				    const domain_search_flags domain) const
 {
   return cp_lookup_symbol_nonlocal (this, name, block, domain);
 }
diff --git a/gdb/f-lang.h b/gdb/f-lang.h
index 3126146c607..c2034258513 100644
--- a/gdb/f-lang.h
+++ b/gdb/f-lang.h
@@ -142,7 +142,7 @@  class f_language : public language_defn
 
   struct block_symbol lookup_symbol_nonlocal
 	(const char *name, const struct block *block,
-	 const domain_enum domain) const override;
+	 const domain_search_flags domain) const override;
 
   /* See language.h.  */
 
diff --git a/gdb/f-valprint.c b/gdb/f-valprint.c
index f15ae7e8fb6..19bcd746208 100644
--- a/gdb/f-valprint.c
+++ b/gdb/f-valprint.c
@@ -552,7 +552,7 @@  f_language::value_print_inner (struct value *val, struct ui_file *stream,
 		     value field before printing its value.  */
 		  struct block_symbol sym
 		    = lookup_symbol (field_name, get_selected_block (nullptr),
-				     VAR_DOMAIN, nullptr);
+				     SEARCH_VFT, nullptr);
 		  if (sym.symbol == nullptr)
 		    error (_("failed to find symbol for name list component %s"),
 			   field_name);
diff --git a/gdb/fbsd-tdep.c b/gdb/fbsd-tdep.c
index 5bcd5a744f1..d8fae0786f8 100644
--- a/gdb/fbsd-tdep.c
+++ b/gdb/fbsd-tdep.c
@@ -1960,8 +1960,9 @@  fbsd_fetch_rtld_offsets (struct gdbarch *gdbarch, struct fbsd_pspace_data *data)
     {
       /* Fetch offsets from debug symbols in rtld.  */
       struct symbol *obj_entry_sym
-	= lookup_symbol_in_language ("Struct_Obj_Entry", NULL, STRUCT_DOMAIN,
-				     language_c, NULL).symbol;
+	= lookup_symbol_in_language ("Struct_Obj_Entry", nullptr,
+				     SEARCH_STRUCT_DOMAIN,
+				     language_c, nullptr).symbol;
       if (obj_entry_sym == NULL)
 	error (_("Unable to find Struct_Obj_Entry symbol"));
       data->off_linkmap = lookup_struct_elt (obj_entry_sym->type (),
diff --git a/gdb/frame.c b/gdb/frame.c
index d95d63eb0f6..03f3c50cb8d 100644
--- a/gdb/frame.c
+++ b/gdb/frame.c
@@ -2559,7 +2559,8 @@  inside_main_func (frame_info_ptr this_frame)
       /* In some language (for example Fortran) there will be no minimal
 	 symbol with the name of the main function.  In this case we should
 	 search the full symbols to see if we can find a match.  */
-      struct block_symbol bs = lookup_symbol (name, NULL, VAR_DOMAIN, 0);
+      struct block_symbol bs = lookup_symbol (name, nullptr,
+					      SEARCH_VFT, nullptr);
 
       /* We might have found some unrelated symbol.  For example, the
 	 Rust compiler can emit both a subprogram and a namespace with
diff --git a/gdb/ft32-tdep.c b/gdb/ft32-tdep.c
index 9484f9e843f..069d40f56fb 100644
--- a/gdb/ft32-tdep.c
+++ b/gdb/ft32-tdep.c
@@ -297,7 +297,8 @@  ft32_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
 	  plg_end = ft32_analyze_prologue (func_addr,
 					   func_end, &cache, gdbarch);
 	  /* Found a function.  */
-	  sym = lookup_symbol (func_name, NULL, VAR_DOMAIN, NULL).symbol;
+	  sym = lookup_symbol (func_name, nullptr, SEARCH_FUNCTION_DOMAIN,
+			       nullptr).symbol;
 	  /* Don't use line number debug info for assembly source files.  */
 	  if ((sym != NULL) && sym->language () != language_asm)
 	    {
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 1dc68a99104..f4eff650799 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -1655,7 +1655,7 @@  lookup_typename (const struct language_defn *language,
 {
   struct symbol *sym;
 
-  sym = lookup_symbol_in_language (name, block, VAR_DOMAIN,
+  sym = lookup_symbol_in_language (name, block, SEARCH_VFT,
 				   language->la_language, NULL).symbol;
   if (sym != NULL && sym->aclass () == LOC_TYPEDEF)
     {
@@ -1699,7 +1699,7 @@  lookup_struct (const char *name, const struct block *block)
 {
   struct symbol *sym;
 
-  sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0).symbol;
+  sym = lookup_symbol (name, block, SEARCH_STRUCT_DOMAIN, 0).symbol;
 
   if (sym == NULL)
     {
@@ -1722,7 +1722,7 @@  lookup_union (const char *name, const struct block *block)
   struct symbol *sym;
   struct type *t;
 
-  sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0).symbol;
+  sym = lookup_symbol (name, block, SEARCH_STRUCT_DOMAIN, 0).symbol;
 
   if (sym == NULL)
     error (_("No union type named %s."), name);
@@ -1745,7 +1745,7 @@  lookup_enum (const char *name, const struct block *block)
 {
   struct symbol *sym;
 
-  sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0).symbol;
+  sym = lookup_symbol (name, block, SEARCH_STRUCT_DOMAIN, 0).symbol;
   if (sym == NULL)
     {
       error (_("No enum type named %s."), name);
@@ -1772,7 +1772,8 @@  lookup_template_type (const char *name, struct type *type,
   nam += type->name ();
   nam += " >"; /* FIXME, extra space still introduced in gcc?  */
 
-  symbol *sym = lookup_symbol (nam.c_str (), block, VAR_DOMAIN, 0).symbol;
+  symbol *sym = lookup_symbol (nam.c_str (), block,
+			       SEARCH_STRUCT_DOMAIN, 0).symbol;
 
   if (sym == NULL)
     {
@@ -2994,7 +2995,8 @@  check_typedef (struct type *type)
 	      stub_noname_complaint ();
 	      return make_qualified_type (type, instance_flags, NULL);
 	    }
-	  sym = lookup_symbol (name, 0, STRUCT_DOMAIN, 0).symbol;
+	  sym = lookup_symbol (name, nullptr, SEARCH_STRUCT_DOMAIN,
+			       nullptr).symbol;
 	  if (sym)
 	    type->set_target_type (sym->type ());
 	  else					/* TYPE_CODE_UNDEF */
@@ -3084,7 +3086,8 @@  check_typedef (struct type *type)
 	  stub_noname_complaint ();
 	  return make_qualified_type (type, instance_flags, NULL);
 	}
-      sym = lookup_symbol (name, 0, STRUCT_DOMAIN, 0).symbol;
+      sym = lookup_symbol (name, nullptr, SEARCH_STRUCT_DOMAIN,
+			   nullptr).symbol;
       if (sym)
 	{
 	  /* Same as above for opaque types, we can replace the stub
diff --git a/gdb/gnu-v3-abi.c b/gdb/gnu-v3-abi.c
index de6d21ae2c3..faefe925943 100644
--- a/gdb/gnu-v3-abi.c
+++ b/gdb/gnu-v3-abi.c
@@ -1079,7 +1079,7 @@  gnuv3_get_typeid_type (struct gdbarch *gdbarch)
   struct symbol *typeinfo;
   struct type *typeinfo_type;
 
-  typeinfo = lookup_symbol ("std::type_info", NULL, STRUCT_DOMAIN,
+  typeinfo = lookup_symbol ("std::type_info", NULL, SEARCH_STRUCT_DOMAIN,
 			    NULL).symbol;
   if (typeinfo == NULL)
     {
diff --git a/gdb/go-exp.y b/gdb/go-exp.y
index 0b17ea42ff3..a3afbbb8514 100644
--- a/gdb/go-exp.y
+++ b/gdb/go-exp.y
@@ -1293,7 +1293,8 @@  package_name_p (const char *name, const struct block *block)
   struct symbol *sym;
   struct field_of_this_result is_a_field_of_this;
 
-  sym = lookup_symbol (name, block, STRUCT_DOMAIN, &is_a_field_of_this).symbol;
+  sym = lookup_symbol (name, block, SEARCH_STRUCT_DOMAIN,
+		       &is_a_field_of_this).symbol;
 
   if (sym
       && sym->aclass () == LOC_TYPEDEF
@@ -1335,7 +1336,7 @@  classify_packaged_name (const struct block *block)
 
   std::string copy = copy_name (yylval.sval);
 
-  sym = lookup_symbol (copy.c_str (), block, VAR_DOMAIN, &is_a_field_of_this);
+  sym = lookup_symbol (copy.c_str (), block, SEARCH_VFT, &is_a_field_of_this);
 
   if (sym.symbol)
     {
@@ -1378,7 +1379,7 @@  classify_name (struct parser_state *par_state, const struct block *block)
 
   /* TODO: What about other types?  */
 
-  sym = lookup_symbol (copy.c_str (), block, VAR_DOMAIN, &is_a_field_of_this);
+  sym = lookup_symbol (copy.c_str (), block, SEARCH_VFT, &is_a_field_of_this);
 
   if (sym.symbol)
     {
@@ -1403,7 +1404,7 @@  classify_name (struct parser_state *par_state, const struct block *block)
 			       strlen (current_package_name.get ()),
 			       copy.c_str (), copy.size ());
 
-	sym = lookup_symbol (sval.ptr, block, VAR_DOMAIN,
+	sym = lookup_symbol (sval.ptr, block, SEARCH_VFT,
 			     &is_a_field_of_this);
 	if (sym.symbol)
 	  {
diff --git a/gdb/guile/scm-frame.c b/gdb/guile/scm-frame.c
index 60bacdd7320..b133e8de11d 100644
--- a/gdb/guile/scm-frame.c
+++ b/gdb/guile/scm-frame.c
@@ -937,7 +937,7 @@  gdbscm_frame_read_var (SCM self, SCM symbol_scm, SCM rest)
 
 	    if (block == NULL)
 	      block = get_frame_block (frame_info_ptr (frame), NULL);
-	    lookup_sym = lookup_symbol (var_name.get (), block, VAR_DOMAIN,
+	    lookup_sym = lookup_symbol (var_name.get (), block, SEARCH_VFT,
 					NULL);
 	    var = lookup_sym.symbol;
 	    block = lookup_sym.block;
diff --git a/gdb/guile/scm-symbol.c b/gdb/guile/scm-symbol.c
index bf5fe24f23d..7061ff58872 100644
--- a/gdb/guile/scm-symbol.c
+++ b/gdb/guile/scm-symbol.c
@@ -617,7 +617,8 @@  gdbscm_lookup_symbol (SCM name_scm, SCM rest)
   gdbscm_gdb_exception except {};
   try
     {
-      symbol = lookup_symbol (name, block, (domain_enum) domain,
+      domain_search_flags flags = from_scripting_domain (domain);
+      symbol = lookup_symbol (name, block, flags,
 			      &is_a_field_of_this).symbol;
     }
   catch (const gdb_exception &ex)
@@ -654,7 +655,8 @@  gdbscm_lookup_global_symbol (SCM name_scm, SCM rest)
 
   try
     {
-      symbol = lookup_global_symbol (name, NULL, (domain_enum) domain).symbol;
+      domain_search_flags flags = from_scripting_domain (domain);
+      symbol = lookup_global_symbol (name, NULL, flags).symbol;
     }
   catch (const gdb_exception &ex)
     {
@@ -696,14 +698,15 @@  static const scheme_integer_constant symbol_integer_constants[] =
 #undef X
 
 #define DOMAIN(X) \
-  { "SYMBOL_" #X "_DOMAIN", X ## _DOMAIN },
+  { "SYMBOL_" #X "_DOMAIN", to_scripting_domain (X ## _DOMAIN) },	\
+  { "SEARCH_" #X "_DOMAIN", to_scripting_domain (SEARCH_ ## X ## _DOMAIN) },
 #include "sym-domains.def"
 #undef DOMAIN
 
-  /* These were never correct.  */
-  { "SYMBOL_VARIABLES_DOMAIN", VAR_DOMAIN },
-  { "SYMBOL_FUNCTIONS_DOMAIN", VAR_DOMAIN },
-  { "SYMBOL_TYPES_DOMAIN", VAR_DOMAIN },
+  /* Historical.  */
+  { "SYMBOL_VARIABLES_DOMAIN", to_scripting_domain (SEARCH_VAR_DOMAIN) },
+  { "SYMBOL_FUNCTIONS_DOMAIN", to_scripting_domain (SEARCH_FUNCTION_DOMAIN) },
+  { "SYMBOL_TYPES_DOMAIN", to_scripting_domain (SEARCH_TYPE_DOMAIN) },
 
   END_INTEGER_CONSTANTS
 };
diff --git a/gdb/infrun.c b/gdb/infrun.c
index 3f0f69be098..87939579111 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -8799,7 +8799,7 @@  insert_exception_resume_breakpoint (struct thread_info *tp,
       struct breakpoint *bp;
 
       vsym = lookup_symbol_search_name (sym->search_name (),
-					b, VAR_DOMAIN);
+					b, SEARCH_VAR_DOMAIN);
       value = read_var_value (vsym.symbol, vsym.block, frame);
       /* If the value was optimized out, revert to the old behavior.  */
       if (! value->optimized_out ())
diff --git a/gdb/language.c b/gdb/language.c
index 038559a34bf..d6f6831c190 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -944,7 +944,8 @@  language_arch_info::bool_type () const
     {
       struct symbol *sym;
 
-      sym = lookup_symbol (m_bool_type_name, NULL, VAR_DOMAIN, NULL).symbol;
+      sym = lookup_symbol (m_bool_type_name, nullptr, SEARCH_TYPE_DOMAIN,
+			   nullptr).symbol;
       if (sym != nullptr)
 	{
 	  struct type *type = sym->type ();
diff --git a/gdb/language.h b/gdb/language.h
index 14a1ef6d472..5bef965c2c8 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -513,7 +513,7 @@  struct language_defn
   virtual struct block_symbol lookup_symbol_nonlocal
 	(const char *name,
 	 const struct block *block,
-	 const domain_enum domain) const;
+	 const domain_search_flags domain) const;
 
   /* Return an expression that can be used for a location
      watchpoint.  TYPE is a pointer type that points to the memory
diff --git a/gdb/linespec.c b/gdb/linespec.c
index b9aca3cc6ce..4e43bf28a67 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -3923,7 +3923,7 @@  find_label_symbols_in_block (const struct block *block,
 
       for (struct symbol *sym : block_iterator_range (block))
 	{
-	  if (sym->matches (LABEL_DOMAIN)
+	  if (sym->domain () == LABEL_DOMAIN
 	      && cmp (sym->search_name (), name, name_len) == 0)
 	    {
 	      result->push_back ({sym, block});
@@ -3934,7 +3934,7 @@  find_label_symbols_in_block (const struct block *block,
   else
     {
       struct block_symbol label_sym
-	= lookup_symbol (name, block, LABEL_DOMAIN, 0);
+	= lookup_symbol (name, block, SEARCH_LABEL_DOMAIN, 0);
 
       if (label_sym.symbol != NULL)
 	{
diff --git a/gdb/m2-exp.y b/gdb/m2-exp.y
index 67252ef5684..ce5a399477d 100644
--- a/gdb/m2-exp.y
+++ b/gdb/m2-exp.y
@@ -494,7 +494,7 @@  fblock	:	BLOCKNAME
 			{ struct symbol *sym
 			    = lookup_symbol (copy_name ($1).c_str (),
 					     pstate->expression_context_block,
-					     VAR_DOMAIN, 0).symbol;
+					     SEARCH_VFT, 0).symbol;
 			  $$ = sym;}
 	;
 			     
@@ -503,7 +503,7 @@  fblock	:	BLOCKNAME
 fblock	:	block COLONCOLON BLOCKNAME
 			{ struct symbol *tem
 			    = lookup_symbol (copy_name ($3).c_str (), $1,
-					     VAR_DOMAIN, 0).symbol;
+					     SEARCH_VFT, 0).symbol;
 			  if (!tem || tem->aclass () != LOC_BLOCK)
 			    error (_("No function \"%s\" in specified context."),
 				   copy_name ($3).c_str ());
@@ -528,7 +528,7 @@  variable:	DOLLAR_VARIABLE
 variable:	block COLONCOLON NAME
 			{ struct block_symbol sym
 			    = lookup_symbol (copy_name ($3).c_str (), $1,
-					     VAR_DOMAIN, 0);
+					     SEARCH_VFT, 0);
 
 			  if (sym.symbol == 0)
 			    error (_("No symbol \"%s\" in specified context."),
@@ -549,7 +549,7 @@  variable:	NAME
 			  sym
 			    = lookup_symbol (name.c_str (),
 					     pstate->expression_context_block,
-					     VAR_DOMAIN,
+					     SEARCH_VFT,
 					     &is_a_field_of_this);
 
 			  pstate->push_symbol (name.c_str (), sym);
@@ -927,7 +927,7 @@  yylex (void)
     if (lookup_symtab (tmp.c_str ()))
       return BLOCKNAME;
     sym = lookup_symbol (tmp.c_str (), pstate->expression_context_block,
-			 VAR_DOMAIN, 0).symbol;
+			 SEARCH_VFT, 0).symbol;
     if (sym && sym->aclass () == LOC_BLOCK)
       return BLOCKNAME;
     if (lookup_typename (pstate->language (),
diff --git a/gdb/mi/mi-cmd-stack.c b/gdb/mi/mi-cmd-stack.c
index 3cd9e097458..d80739b1f39 100644
--- a/gdb/mi/mi-cmd-stack.c
+++ b/gdb/mi/mi-cmd-stack.c
@@ -636,8 +636,9 @@  list_args_or_locals (const frame_print_options &fp_opts,
 	      struct frame_arg arg, entryarg;
 
 	      if (sym->is_argument ())
-		sym2 = lookup_symbol_search_name (sym->search_name (),
-						  block, VAR_DOMAIN).symbol;
+		sym2 = (lookup_symbol_search_name
+			(sym->search_name (),
+			 block, SEARCH_VAR_DOMAIN).symbol);
 	      else
 		sym2 = sym;
 	      gdb_assert (sym2 != NULL);
diff --git a/gdb/moxie-tdep.c b/gdb/moxie-tdep.c
index 223cf09a561..4a80355ada5 100644
--- a/gdb/moxie-tdep.c
+++ b/gdb/moxie-tdep.c
@@ -226,7 +226,8 @@  moxie_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
 	  plg_end = moxie_analyze_prologue (func_addr, 
 					    func_end, &cache, gdbarch);
 	  /* Found a function.  */
-	  sym = lookup_symbol (func_name, NULL, VAR_DOMAIN, NULL).symbol;
+	  sym = lookup_symbol (func_name, nullptr,
+			       SEARCH_FUNCTION_DOMAIN, nullptr).symbol;
 	  /* Don't use line number debug info for assembly source
 	     files.  */
 	  if (sym && sym->language () != language_asm)
diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
index 10eb73a95cb..2424e1e8530 100644
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -87,7 +87,7 @@  lookup_struct_typedef (const char *name, const struct block *block, int noerr)
 {
   struct symbol *sym;
 
-  sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0).symbol;
+  sym = lookup_symbol (name, block, SEARCH_STRUCT_DOMAIN, 0).symbol;
 
   if (sym == NULL)
     {
@@ -1129,7 +1129,7 @@  find_imps (const char *method, std::vector<const char *> *symbol_names)
      add the selector itself as a symbol, if it exists.  */
   if (selector_case && !symbol_names->empty ())
     {
-      struct symbol *sym = lookup_symbol (selector, NULL, VAR_DOMAIN,
+      struct symbol *sym = lookup_symbol (selector, NULL, SEARCH_VFT,
 					  0).symbol;
 
       if (sym != NULL) 
diff --git a/gdb/objfiles.h b/gdb/objfiles.h
index 64f2b5ef6be..98e2355f7a9 100644
--- a/gdb/objfiles.h
+++ b/gdb/objfiles.h
@@ -562,7 +562,7 @@  struct objfile
      contains !TYPE_OPAQUE symbol prefer its compunit.  If it contains
      only TYPE_OPAQUE symbol(s), return at least that compunit.  */
   struct compunit_symtab *lookup_symbol (block_enum kind, const char *name,
-					 domain_enum domain);
+					 domain_search_flags domain);
 
   /* See quick_symbol_functions.  */
   void print_stats (bool print_bcache);
diff --git a/gdb/p-exp.y b/gdb/p-exp.y
index 2b5eb6f3026..ea7eb8c8d7e 100644
--- a/gdb/p-exp.y
+++ b/gdb/p-exp.y
@@ -629,9 +629,10 @@  block	:	block COLONCOLON name
 			  std::string copy = copy_name ($3);
 			  struct symbol *tem
 			    = lookup_symbol (copy.c_str (), $1,
-					     VAR_DOMAIN, NULL).symbol;
+					     SEARCH_FUNCTION_DOMAIN,
+					     nullptr).symbol;
 
-			  if (!tem || tem->aclass () != LOC_BLOCK)
+			  if (tem == nullptr)
 			    error (_("No function \"%s\" in specified context."),
 				   copy.c_str ());
 			  $$ = tem->value_block (); }
@@ -642,7 +643,7 @@  variable:	block COLONCOLON name
 
 			  std::string copy = copy_name ($3);
 			  sym = lookup_symbol (copy.c_str (), $1,
-					       VAR_DOMAIN, NULL);
+					       SEARCH_VFT, NULL);
 			  if (sym.symbol == 0)
 			    error (_("No symbol \"%s\" in specified context."),
 				   copy.c_str ());
@@ -672,7 +673,7 @@  variable:	qualified_name
 
 			  struct block_symbol sym
 			    = lookup_symbol (name.c_str (), nullptr,
-					     VAR_DOMAIN, nullptr);
+					     SEARCH_VFT, nullptr);
 			  pstate->push_symbol (name.c_str (), sym);
 			}
 	;
@@ -1400,7 +1401,7 @@  yylex (void)
 	  static const char this_name[] = "this";
 
 	  if (lookup_symbol (this_name, pstate->expression_context_block,
-			     VAR_DOMAIN, NULL).symbol)
+			     SEARCH_VFT, NULL).symbol)
 	    {
 	      free (uptokstart);
 	      return THIS;
@@ -1440,7 +1441,7 @@  yylex (void)
       sym = NULL;
     else
       sym = lookup_symbol (tmp.c_str (), pstate->expression_context_block,
-			   VAR_DOMAIN, &is_a_field_of_this).symbol;
+			   SEARCH_VFT, &is_a_field_of_this).symbol;
     /* second chance uppercased (as Free Pascal does).  */
     if (!sym && is_a_field_of_this.type == NULL && !is_a_field)
       {
@@ -1456,7 +1457,7 @@  yylex (void)
 	 sym = NULL;
        else
 	 sym = lookup_symbol (tmp.c_str (), pstate->expression_context_block,
-			      VAR_DOMAIN, &is_a_field_of_this).symbol;
+			      SEARCH_VFT, &is_a_field_of_this).symbol;
       }
     /* Third chance Capitalized (as GPC does).  */
     if (!sym && is_a_field_of_this.type == NULL && !is_a_field)
@@ -1479,7 +1480,7 @@  yylex (void)
 	 sym = NULL;
        else
 	 sym = lookup_symbol (tmp.c_str (), pstate->expression_context_block,
-			      VAR_DOMAIN, &is_a_field_of_this).symbol;
+			      SEARCH_VFT, &is_a_field_of_this).symbol;
       }
 
     if (is_a_field || (is_a_field_of_this.type != NULL))
@@ -1576,7 +1577,7 @@  yylex (void)
 		      cur_sym
 			= lookup_symbol (ncopy,
 					 pstate->expression_context_block,
-					 VAR_DOMAIN, NULL).symbol;
+					 SEARCH_VFT, NULL).symbol;
 		      if (cur_sym)
 			{
 			  if (cur_sym->aclass () == LOC_TYPEDEF)
diff --git a/gdb/p-valprint.c b/gdb/p-valprint.c
index 076ee08ab6e..2372cdf83eb 100644
--- a/gdb/p-valprint.c
+++ b/gdb/p-valprint.c
@@ -253,7 +253,7 @@  pascal_language::value_print_inner (struct value *val,
 		{
 		  const char *search_name = msymbol.minsym->search_name ();
 		  wsym = lookup_symbol_search_name (search_name, NULL,
-						    VAR_DOMAIN).symbol;
+						    SEARCH_VFT).symbol;
 		}
 
 	      if (wsym)
diff --git a/gdb/parse.c b/gdb/parse.c
index 9209e3d8fa2..4b0eeaf5330 100644
--- a/gdb/parse.c
+++ b/gdb/parse.c
@@ -225,7 +225,8 @@  parser_state::push_dollar (struct stoken str)
   /* On some systems, such as HP-UX and hppa-linux, certain system routines
      have names beginning with $ or $$.  Check for those, first.  */
 
-  sym = lookup_symbol (copy.c_str (), NULL, VAR_DOMAIN, NULL);
+  sym = lookup_symbol (copy.c_str (), nullptr,
+		       SEARCH_VAR_DOMAIN | SEARCH_FUNCTION_DOMAIN, nullptr);
   if (sym.symbol)
     {
       push_new<expr::var_value_operation> (sym);
diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index 7a638ab8b89..813b5e642ef 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -1582,7 +1582,7 @@  info_address_command (const char *exp, int from_tty)
   if (exp == 0)
     error (_("Argument required."));
 
-  sym = lookup_symbol (exp, get_selected_block (&context_pc), VAR_DOMAIN,
+  sym = lookup_symbol (exp, get_selected_block (&context_pc), SEARCH_VFT,
 		       &is_a_field_of_this).symbol;
   if (sym == NULL)
     {
diff --git a/gdb/psymtab.c b/gdb/psymtab.c
index eb031d33f0d..cb7a397afb1 100644
--- a/gdb/psymtab.c
+++ b/gdb/psymtab.c
@@ -1507,7 +1507,7 @@  maintenance_check_psymtabs (const char *ignore, int from_tty)
 
 		  sym = block_lookup_symbol (b, psym->ginfo.search_name (),
 					     symbol_name_match_type::SEARCH_NAME,
-					     psym->domain);
+					     to_search_flags (psym->domain));
 		  if (!sym)
 		    {
 		      gdb_printf ("Static symbol `");
@@ -1522,7 +1522,7 @@  maintenance_check_psymtabs (const char *ignore, int from_tty)
 		{
 		  sym = block_lookup_symbol (b, psym->ginfo.search_name (),
 					     symbol_name_match_type::SEARCH_NAME,
-					     psym->domain);
+					     to_search_flags (psym->domain));
 		  if (!sym)
 		    {
 		      gdb_printf ("Global symbol `");
diff --git a/gdb/python/py-frame.c b/gdb/python/py-frame.c
index 95f15e00436..a1061fc0d72 100644
--- a/gdb/python/py-frame.c
+++ b/gdb/python/py-frame.c
@@ -532,7 +532,8 @@  frapy_read_var (PyObject *self, PyObject *args, PyObject *kw)
 
 	  if (!block)
 	    block = get_frame_block (frame, NULL);
-	  lookup_sym = lookup_symbol (var_name.get (), block, VAR_DOMAIN, NULL);
+	  lookup_sym = lookup_symbol (var_name.get (), block,
+				      SEARCH_VFT, nullptr);
 	  var = lookup_sym.symbol;
 	  block = lookup_sym.block;
 	}
diff --git a/gdb/python/py-objfile.c b/gdb/python/py-objfile.c
index a3e55ffa3eb..ffdb7be4a9a 100644
--- a/gdb/python/py-objfile.c
+++ b/gdb/python/py-objfile.c
@@ -479,8 +479,9 @@  objfpy_lookup_global_symbol (PyObject *self, PyObject *args, PyObject *kw)
 
   try
     {
+      domain_search_flags flags = from_scripting_domain (domain);
       struct symbol *sym = lookup_global_symbol_from_objfile
-	(obj->objfile, GLOBAL_BLOCK, symbol_name, (domain_enum) domain).symbol;
+	(obj->objfile, GLOBAL_BLOCK, symbol_name, flags).symbol;
       if (sym == nullptr)
 	Py_RETURN_NONE;
 
@@ -513,8 +514,9 @@  objfpy_lookup_static_symbol (PyObject *self, PyObject *args, PyObject *kw)
 
   try
     {
+      domain_search_flags flags = from_scripting_domain (domain);
       struct symbol *sym = lookup_global_symbol_from_objfile
-	(obj->objfile, STATIC_BLOCK, symbol_name, (domain_enum) domain).symbol;
+	(obj->objfile, STATIC_BLOCK, symbol_name, flags).symbol;
       if (sym == nullptr)
 	Py_RETURN_NONE;
 
diff --git a/gdb/python/py-symbol.c b/gdb/python/py-symbol.c
index a7d010f6d0c..2fb68377bad 100644
--- a/gdb/python/py-symbol.c
+++ b/gdb/python/py-symbol.c
@@ -432,8 +432,8 @@  gdbpy_lookup_symbol (PyObject *self, PyObject *args, PyObject *kw)
 
   try
     {
-      symbol = lookup_symbol (name, block, (domain_enum) domain,
-			      &is_a_field_of_this).symbol;
+      domain_search_flags flags = from_scripting_domain (domain);
+      symbol = lookup_symbol (name, block, flags, &is_a_field_of_this).symbol;
     }
   catch (const gdb_exception &except)
     {
@@ -481,7 +481,8 @@  gdbpy_lookup_global_symbol (PyObject *self, PyObject *args, PyObject *kw)
 
   try
     {
-      symbol = lookup_global_symbol (name, NULL, (domain_enum) domain).symbol;
+      domain_search_flags flags = from_scripting_domain (domain);
+      symbol = lookup_global_symbol (name, NULL, flags).symbol;
     }
   catch (const gdb_exception &except)
     {
@@ -542,13 +543,14 @@  gdbpy_lookup_static_symbol (PyObject *self, PyObject *args, PyObject *kw)
 
   try
     {
+      domain_search_flags flags = from_scripting_domain (domain);
+
       if (block != nullptr)
 	symbol
-	  = lookup_symbol_in_static_block (name, block,
-					   (domain_enum) domain).symbol;
+	  = lookup_symbol_in_static_block (name, block, flags).symbol;
 
       if (symbol == nullptr)
-	symbol = lookup_static_symbol (name, (domain_enum) domain).symbol;
+	symbol = lookup_static_symbol (name, flags).symbol;
     }
   catch (const gdb_exception &except)
     {
@@ -592,6 +594,8 @@  gdbpy_lookup_static_symbols (PyObject *self, PyObject *args, PyObject *kw)
 
   try
     {
+      domain_search_flags flags = from_scripting_domain (domain);
+
       /* Expand any symtabs that contain potentially matching symbols.  */
       lookup_name_info lookup_name (name, symbol_name_match_type::FULL);
       expand_symtabs_matching (NULL, lookup_name, NULL, NULL,
@@ -613,7 +617,7 @@  gdbpy_lookup_static_symbols (PyObject *self, PyObject *args, PyObject *kw)
 	      if (block != nullptr)
 		{
 		  symbol *symbol = lookup_symbol_in_static_block
-		    (name, block, (domain_enum) domain).symbol;
+		    (name, block, flags).symbol;
 
 		  if (symbol != nullptr)
 		    {
@@ -675,7 +679,9 @@  gdbpy_initialize_symbols (void)
 
 #define DOMAIN(X)							\
   if (PyModule_AddIntConstant (gdb_module, "SYMBOL_" #X "_DOMAIN",	\
-			       X ## _DOMAIN) < 0)			\
+			       to_scripting_domain (X ## _DOMAIN)) < 0	\
+      || PyModule_AddIntConstant (gdb_module, "SEARCH_" #X "_DOMAIN",	\
+				  to_scripting_domain (SEARCH_ ## X ## _DOMAIN)) < 0) \
     return -1;
 #include "sym-domains.def"
 #undef DOMAIN
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index ff1769c7296..11c7f13417d 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -1563,7 +1563,8 @@  rust_structop::evaluate_funcall (struct type *expect_type,
 
   const struct block *block = get_selected_block (0);
   struct block_symbol sym = lookup_symbol (name.c_str (), block,
-					   VAR_DOMAIN, NULL);
+					   SEARCH_VFT,
+					   nullptr);
   if (sym.symbol == NULL)
     error (_("Could not find function named '%s'"), name.c_str ());
 
@@ -1699,7 +1700,7 @@  rust_language::is_string_type_p (struct type *type) const
 struct block_symbol
 rust_language::lookup_symbol_nonlocal
      (const char *name, const struct block *block,
-      const domain_enum domain) const
+      const domain_search_flags domain) const
 {
   struct block_symbol result = {};
 
@@ -1707,7 +1708,7 @@  rust_language::lookup_symbol_nonlocal
   symbol_lookup_debug_printf
     ("rust_lookup_symbol_non_local (%s, %s (scope %s), %s)",
      name, host_address_to_string (block), scope,
-     domain_name (domain));
+     domain_name (domain).c_str ());
 
   /* Look up bare names in the block's scope.  */
   std::string scopedname;
diff --git a/gdb/rust-lang.h b/gdb/rust-lang.h
index d2270e66b4a..e76a63ee037 100644
--- a/gdb/rust-lang.h
+++ b/gdb/rust-lang.h
@@ -151,7 +151,7 @@  class rust_language : public language_defn
 
   struct block_symbol lookup_symbol_nonlocal
 	(const char *name, const struct block *block,
-	 const domain_enum domain) const override;
+	 const domain_search_flags domain) const override;
 
   /* See language.h.  */
 
diff --git a/gdb/rust-parse.c b/gdb/rust-parse.c
index 277a0793ea9..af1b76f738a 100644
--- a/gdb/rust-parse.c
+++ b/gdb/rust-parse.c
@@ -308,7 +308,7 @@  struct rust_parser
   void update_innermost_block (struct block_symbol sym);
   struct block_symbol lookup_symbol (const char *name,
 				     const struct block *block,
-				     const domain_enum domain);
+				     const domain_search_flags domain);
   struct type *rust_lookup_type (const char *name);
 
   /* Clear some state.  This is only used for testing.  */
@@ -431,7 +431,7 @@  munge_name_and_block (const char **name, const struct block **block)
 
 struct block_symbol
 rust_parser::lookup_symbol (const char *name, const struct block *block,
-			    const domain_enum domain)
+			    const domain_search_flags domain)
 {
   struct block_symbol result;
 
@@ -454,7 +454,7 @@  rust_parser::rust_lookup_type (const char *name)
   const struct block *block = pstate->expression_context_block;
   munge_name_and_block (&name, &block);
 
-  result = ::lookup_symbol (name, block, STRUCT_DOMAIN, NULL);
+  result = ::lookup_symbol (name, block, SEARCH_STRUCT_DOMAIN, NULL);
   if (result.symbol != NULL)
     {
       update_innermost_block (result);
@@ -1221,7 +1221,7 @@  rust_parser::name_to_operation (const std::string &name)
 {
   struct block_symbol sym = lookup_symbol (name.c_str (),
 					   pstate->expression_context_block,
-					   VAR_DOMAIN);
+					   SEARCH_VFT);
   if (sym.symbol != nullptr && sym.symbol->aclass () != LOC_TYPEDEF)
     return make_operation<var_value_operation> (sym);
 
diff --git a/gdb/source.c b/gdb/source.c
index 2c3bf91923b..2c465a1251f 100644
--- a/gdb/source.c
+++ b/gdb/source.c
@@ -316,8 +316,9 @@  select_source_symtab ()
 
   /* Make the default place to list be the function `main'
      if one exists.  */
-  block_symbol bsym = lookup_symbol (main_name (), 0, VAR_DOMAIN, 0);
-  if (bsym.symbol != nullptr && bsym.symbol->aclass () == LOC_BLOCK)
+  block_symbol bsym = lookup_symbol (main_name (), nullptr,
+				     SEARCH_FUNCTION_DOMAIN, nullptr);
+  if (bsym.symbol != nullptr)
     {
       symtab_and_line sal = find_function_start_sal (bsym.symbol, true);
       if (sal.symtab == NULL)
diff --git a/gdb/stack.c b/gdb/stack.c
index 2de3e361c61..fac0279472e 100644
--- a/gdb/stack.c
+++ b/gdb/stack.c
@@ -818,7 +818,7 @@  print_frame_args (const frame_print_options &fp_opts,
 	      struct symbol *nsym;
 
 	      nsym = lookup_symbol_search_name (sym->search_name (),
-						b, VAR_DOMAIN).symbol;
+						b, SEARCH_VAR_DOMAIN).symbol;
 	      gdb_assert (nsym != NULL);
 	      if (nsym->aclass () == LOC_REGISTER
 		  && !nsym->is_argument ())
@@ -2472,7 +2472,7 @@  iterate_over_block_arg_vars (const struct block *b,
 
 	  struct symbol *sym2
 	    = lookup_symbol_search_name (sym->search_name (),
-					 b, VAR_DOMAIN).symbol;
+					 b, SEARCH_VAR_DOMAIN).symbol;
 	  cb (sym->print_name (), sym2);
 	}
     }
diff --git a/gdb/symfile-debug.c b/gdb/symfile-debug.c
index 3f5df13a005..30b02531b9c 100644
--- a/gdb/symfile-debug.c
+++ b/gdb/symfile-debug.c
@@ -240,7 +240,8 @@  objfile::map_symtabs_matching_filename
 }
 
 struct compunit_symtab *
-objfile::lookup_symbol (block_enum kind, const char *name, domain_enum domain)
+objfile::lookup_symbol (block_enum kind, const char *name,
+			domain_search_flags domain)
 {
   struct compunit_symtab *retval = nullptr;
 
@@ -248,7 +249,7 @@  objfile::lookup_symbol (block_enum kind, const char *name, domain_enum domain)
     gdb_printf (gdb_stdlog,
 		"qf->lookup_symbol (%s, %d, \"%s\", %s)\n",
 		objfile_debug_name (this), kind, name,
-		domain_name (domain));
+		domain_name (domain).c_str ());
 
   lookup_name_info lookup_name (name, symbol_name_match_type::FULL);
 
@@ -277,10 +278,6 @@  objfile::lookup_symbol (block_enum kind, const char *name, domain_enum domain)
     return true;
   };
 
-  domain_search_flags flags = to_search_flags (domain);
-  if (domain == VAR_DOMAIN)
-    flags |= SEARCH_TYPE_DOMAIN | SEARCH_FUNCTION_DOMAIN;
-
   for (const auto &iter : qf)
     {
       if (!iter->expand_symtabs_matching (this,
@@ -291,7 +288,7 @@  objfile::lookup_symbol (block_enum kind, const char *name, domain_enum domain)
 					  kind == GLOBAL_BLOCK
 					  ? SEARCH_GLOBAL_BLOCK
 					  : SEARCH_STATIC_BLOCK,
-					  flags))
+					  domain))
 	break;
     }
 
diff --git a/gdb/symfile.c b/gdb/symfile.c
index 17e1a64e77d..9d5ce7f6ad2 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -1697,8 +1697,8 @@  set_initial_language_callback ()
     {
       const char *name = main_name ();
       struct symbol *sym
-	= lookup_symbol_in_language (name, NULL, VAR_DOMAIN, default_lang,
-				     NULL).symbol;
+	= lookup_symbol_in_language (name, nullptr, SEARCH_FUNCTION_DOMAIN,
+				     default_lang, nullptr).symbol;
 
       if (sym != NULL)
 	lang = sym->language ();
diff --git a/gdb/symtab.c b/gdb/symtab.c
index a973052f338..5735786ac44 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -85,7 +85,7 @@  static struct block_symbol
   lookup_symbol_aux (const char *name,
 		     symbol_name_match_type match_type,
 		     const struct block *block,
-		     const domain_enum domain,
+		     const domain_search_flags domain,
 		     enum language language,
 		     struct field_of_this_result *);
 
@@ -93,13 +93,14 @@  static
 struct block_symbol lookup_local_symbol (const char *name,
 					 symbol_name_match_type match_type,
 					 const struct block *block,
-					 const domain_enum domain,
+					 const domain_search_flags domain,
 					 enum language language);
 
 static struct block_symbol
   lookup_symbol_in_objfile (struct objfile *objfile,
 			    enum block_enum block_index,
-			    const char *name, const domain_enum domain);
+			    const char *name,
+			    const domain_search_flags domain);
 
 static void set_main_name (program_space *pspace, const char *name,
 			   language lang);
@@ -171,14 +172,14 @@  struct symbol_cache_slot
      lookup was saved in the cache, but cache space is pretty cheap.  */
   const struct objfile *objfile_context;
 
+  /* The domain that was searched for initially.  This must exactly
+     match.  */
+  domain_search_flags domain;
+
   union
   {
     struct block_symbol found;
-    struct
-    {
-      char *name;
-      domain_enum domain;
-    } not_found;
+    char *name;
   } value;
 };
 
@@ -188,7 +189,7 @@  static void
 symbol_cache_clear_slot (struct symbol_cache_slot *slot)
 {
   if (slot->state == SYMBOL_SLOT_NOT_FOUND)
-    xfree (slot->value.not_found.name);
+    xfree (slot->value.name);
   slot->state = SYMBOL_SLOT_UNUSED;
 }
 
@@ -1243,19 +1244,14 @@  matching_obj_sections (struct obj_section *obj_first,
 
 static unsigned int
 hash_symbol_entry (const struct objfile *objfile_context,
-		   const char *name, domain_enum domain)
+		   const char *name, domain_search_flags domain)
 {
   unsigned int hash = (uintptr_t) objfile_context;
 
   if (name != NULL)
     hash += htab_hash_string (name);
 
-  /* Because of symbol_matches_domain we need VAR_DOMAIN and STRUCT_DOMAIN
-     to map to the same slot.  */
-  if (domain == STRUCT_DOMAIN)
-    hash += VAR_DOMAIN * 7;
-  else
-    hash += domain * 7;
+  hash += domain * 7;
 
   return hash;
 }
@@ -1265,10 +1261,9 @@  hash_symbol_entry (const struct objfile *objfile_context,
 static int
 eq_symbol_entry (const struct symbol_cache_slot *slot,
 		 const struct objfile *objfile_context,
-		 const char *name, domain_enum domain)
+		 const char *name, domain_search_flags domain)
 {
   const char *slot_name;
-  domain_enum slot_domain;
 
   if (slot->state == SYMBOL_SLOT_UNUSED)
     return 0;
@@ -1276,16 +1271,11 @@  eq_symbol_entry (const struct symbol_cache_slot *slot,
   if (slot->objfile_context != objfile_context)
     return 0;
 
+  domain_search_flags slot_domain = slot->domain;
   if (slot->state == SYMBOL_SLOT_NOT_FOUND)
-    {
-      slot_name = slot->value.not_found.name;
-      slot_domain = slot->value.not_found.domain;
-    }
+    slot_name = slot->value.name;
   else
-    {
-      slot_name = slot->value.found.symbol->search_name ();
-      slot_domain = slot->value.found.symbol->domain ();
-    }
+    slot_name = slot->value.found.symbol->search_name ();
 
   /* NULL names match.  */
   if (slot_name == NULL && name == NULL)
@@ -1301,18 +1291,18 @@  eq_symbol_entry (const struct symbol_cache_slot *slot,
 	 the first time through.  If the slot records a found symbol,
 	 then this means using the symbol name comparison function of
 	 the symbol's language with symbol->search_name ().  See
-	 dictionary.c.  It also means using symbol_matches_domain for
-	 found symbols.  See block.c.
+	 dictionary.c.
 
 	 If the slot records a not-found symbol, then require a precise match.
 	 We could still be lax with whitespace like strcmp_iw though.  */
 
+      if (slot_domain != domain)
+	return 0;
+
       if (slot->state == SYMBOL_SLOT_NOT_FOUND)
 	{
 	  if (strcmp (slot_name, name) != 0)
 	    return 0;
-	  if (slot_domain != domain)
-	    return 0;
 	}
       else
 	{
@@ -1321,9 +1311,6 @@  eq_symbol_entry (const struct symbol_cache_slot *slot,
 
 	  if (!symbol_matches_search_name (sym, lookup_name))
 	    return 0;
-
-	  if (!symbol_matches_domain (sym->language (), slot_domain, domain))
-	    return 0;
 	}
     }
   else
@@ -1443,7 +1430,7 @@  set_symbol_cache_size_handler (const char *args, int from_tty,
 static struct block_symbol
 symbol_cache_lookup (struct symbol_cache *cache,
 		     struct objfile *objfile_context, enum block_enum block,
-		     const char *name, domain_enum domain,
+		     const char *name, domain_search_flags domain,
 		     struct block_symbol_cache **bsc_ptr,
 		     struct symbol_cache_slot **slot_ptr)
 {
@@ -1474,7 +1461,7 @@  symbol_cache_lookup (struct symbol_cache *cache,
 				  block == GLOBAL_BLOCK ? "Global" : "Static",
 				  slot->state == SYMBOL_SLOT_NOT_FOUND
 				  ? " (not found)" : "", name,
-				  domain_name (domain));
+				  domain_name (domain).c_str ());
       ++bsc->hits;
       if (slot->state == SYMBOL_SLOT_NOT_FOUND)
 	return SYMBOL_LOOKUP_FAILED;
@@ -1485,7 +1472,7 @@  symbol_cache_lookup (struct symbol_cache *cache,
 
   symbol_lookup_debug_printf ("%s block symbol cache miss for %s, %s",
 			      block == GLOBAL_BLOCK ? "Global" : "Static",
-			      name, domain_name (domain));
+			      name, domain_name (domain).c_str ());
   ++bsc->misses;
   return {};
 }
@@ -1500,7 +1487,8 @@  symbol_cache_mark_found (struct block_symbol_cache *bsc,
 			 struct symbol_cache_slot *slot,
 			 struct objfile *objfile_context,
 			 struct symbol *symbol,
-			 const struct block *block)
+			 const struct block *block,
+			 domain_search_flags domain)
 {
   if (bsc == NULL)
     return;
@@ -1513,6 +1501,7 @@  symbol_cache_mark_found (struct block_symbol_cache *bsc,
   slot->objfile_context = objfile_context;
   slot->value.found.symbol = symbol;
   slot->value.found.block = block;
+  slot->domain = domain;
 }
 
 /* Mark symbol NAME, DOMAIN as not found in SLOT.
@@ -1523,7 +1512,7 @@  static void
 symbol_cache_mark_not_found (struct block_symbol_cache *bsc,
 			     struct symbol_cache_slot *slot,
 			     struct objfile *objfile_context,
-			     const char *name, domain_enum domain)
+			     const char *name, domain_search_flags domain)
 {
   if (bsc == NULL)
     return;
@@ -1534,8 +1523,8 @@  symbol_cache_mark_not_found (struct block_symbol_cache *bsc,
     }
   slot->state = SYMBOL_SLOT_NOT_FOUND;
   slot->objfile_context = objfile_context;
-  slot->value.not_found.name = xstrdup (name);
-  slot->value.not_found.domain = domain;
+  slot->value.name = xstrdup (name);
+  slot->domain = domain;
 }
 
 /* Flush the symbol cache of PSPACE.  */
@@ -1620,8 +1609,8 @@  symbol_cache_dump (const struct symbol_cache *cache)
 	    case SYMBOL_SLOT_NOT_FOUND:
 	      gdb_printf ("  [%4u] = %s, %s %s (not found)\n", i,
 			  host_address_to_string (slot->objfile_context),
-			  slot->value.not_found.name,
-			  domain_name (slot->value.not_found.domain));
+			  slot->value.name,
+			  domain_name (slot->domain).c_str ());
 	      break;
 	    case SYMBOL_SLOT_FOUND:
 	      {
@@ -1984,7 +1973,8 @@  search_name_hash (enum language language, const char *search_name)
 
 struct block_symbol
 lookup_symbol_in_language (const char *name, const struct block *block,
-			   const domain_enum domain, enum language lang,
+			   const domain_search_flags domain,
+			   enum language lang,
 			   struct field_of_this_result *is_a_field_of_this)
 {
   SYMBOL_LOOKUP_SCOPED_DEBUG_ENTER_EXIT;
@@ -2002,7 +1992,7 @@  lookup_symbol_in_language (const char *name, const struct block *block,
 
 struct block_symbol
 lookup_symbol (const char *name, const struct block *block,
-	       domain_enum domain,
+	       domain_search_flags domain,
 	       struct field_of_this_result *is_a_field_of_this)
 {
   return lookup_symbol_in_language (name, block, domain,
@@ -2014,7 +2004,7 @@  lookup_symbol (const char *name, const struct block *block,
 
 struct block_symbol
 lookup_symbol_search_name (const char *search_name, const struct block *block,
-			   domain_enum domain)
+			   domain_search_flags domain)
 {
   return lookup_symbol_aux (search_name, symbol_name_match_type::SEARCH_NAME,
 			    block, domain, language_asm, NULL);
@@ -2039,7 +2029,7 @@  lookup_language_this (const struct language_defn *lang,
 
       sym = block_lookup_symbol (block, lang->name_of_this (),
 				 symbol_name_match_type::SEARCH_NAME,
-				 VAR_DOMAIN);
+				 SEARCH_VFT);
       if (sym != NULL)
 	{
 	  symbol_lookup_debug_printf_v
@@ -2108,7 +2098,7 @@  check_field (struct type *type, const char *name,
 static struct block_symbol
 lookup_symbol_aux (const char *name, symbol_name_match_type match_type,
 		   const struct block *block,
-		   const domain_enum domain, enum language language,
+		   const domain_search_flags domain, enum language language,
 		   struct field_of_this_result *is_a_field_of_this)
 {
   SYMBOL_LOOKUP_SCOPED_DEBUG_ENTER_EXIT;
@@ -2127,7 +2117,7 @@  lookup_symbol_aux (const char *name, symbol_name_match_type match_type,
 	 objfile != NULL ? objfile_debug_name (objfile) : "NULL");
       symbol_lookup_debug_printf
 	("domain name = \"%s\", language = \"%s\")",
-	 domain_name (domain), language_str (language));
+	 domain_name (domain).c_str (), language_str (language));
     }
 
   /* Make sure we do something sensible with is_a_field_of_this, since
@@ -2157,7 +2147,7 @@  lookup_symbol_aux (const char *name, symbol_name_match_type match_type,
   /* Don't do this check if we are searching for a struct.  It will
      not be found by check_field, but will be found by other
      means.  */
-  if (is_a_field_of_this != NULL && domain != STRUCT_DOMAIN)
+  if (is_a_field_of_this != NULL && (domain & SEARCH_STRUCT_DOMAIN) == 0)
     {
       result = lookup_language_this (langdef, block);
 
@@ -2213,7 +2203,7 @@  static struct block_symbol
 lookup_local_symbol (const char *name,
 		     symbol_name_match_type match_type,
 		     const struct block *block,
-		     const domain_enum domain,
+		     const domain_search_flags domain,
 		     enum language language)
 {
   if (block == nullptr)
@@ -2258,7 +2248,7 @@  lookup_local_symbol (const char *name,
 struct symbol *
 lookup_symbol_in_block (const char *name, symbol_name_match_type match_type,
 			const struct block *block,
-			const domain_enum domain)
+			const domain_search_flags domain)
 {
   struct symbol *sym;
 
@@ -2271,7 +2261,7 @@  lookup_symbol_in_block (const char *name, symbol_name_match_type match_type,
 	("lookup_symbol_in_block (%s, %s (objfile %s), %s)",
 	 name, host_address_to_string (block),
 	 objfile != nullptr ? objfile_debug_name (objfile) : "NULL",
-	 domain_name (domain));
+	 domain_name (domain).c_str ());
     }
 
   sym = block_lookup_symbol (block, name, match_type, domain);
@@ -2292,7 +2282,7 @@  struct block_symbol
 lookup_global_symbol_from_objfile (struct objfile *main_objfile,
 				   enum block_enum block_index,
 				   const char *name,
-				   const domain_enum domain)
+				   const domain_search_flags domain)
 {
   gdb_assert (block_index == GLOBAL_BLOCK || block_index == STATIC_BLOCK);
 
@@ -2316,7 +2306,7 @@  lookup_global_symbol_from_objfile (struct objfile *main_objfile,
 static struct block_symbol
 lookup_symbol_in_objfile_symtabs (struct objfile *objfile,
 				  enum block_enum block_index, const char *name,
-				  const domain_enum domain)
+				  const domain_search_flags domain)
 {
   gdb_assert (block_index == GLOBAL_BLOCK || block_index == STATIC_BLOCK);
 
@@ -2324,7 +2314,7 @@  lookup_symbol_in_objfile_symtabs (struct objfile *objfile,
     ("lookup_symbol_in_objfile_symtabs (%s, %s, %s, %s)",
      objfile_debug_name (objfile),
      block_index == GLOBAL_BLOCK ? "GLOBAL_BLOCK" : "STATIC_BLOCK",
-     name, domain_name (domain));
+     name, domain_name (domain).c_str ());
 
   struct block_symbol other;
   other.symbol = NULL;
@@ -2383,7 +2373,7 @@  lookup_symbol_in_objfile_symtabs (struct objfile *objfile,
 static struct block_symbol
 lookup_symbol_in_objfile_from_linkage_name (struct objfile *objfile,
 					    const char *linkage_name,
-					    domain_enum domain)
+					    domain_search_flags domain)
 {
   enum language lang = current_language->la_language;
   struct objfile *main_objfile;
@@ -2435,7 +2425,7 @@  Internal: %s symbol `%s' found in %s psymtab but not in symtab.\n\
 static struct block_symbol
 lookup_symbol_via_quick_fns (struct objfile *objfile,
 			     enum block_enum block_index, const char *name,
-			     const domain_enum domain)
+			     const domain_search_flags domain)
 {
   struct compunit_symtab *cust;
   const struct blockvector *bv;
@@ -2446,7 +2436,7 @@  lookup_symbol_via_quick_fns (struct objfile *objfile,
     ("lookup_symbol_via_quick_fns (%s, %s, %s, %s)",
      objfile_debug_name (objfile),
      block_index == GLOBAL_BLOCK ? "GLOBAL_BLOCK" : "STATIC_BLOCK",
-     name, domain_name (domain));
+     name, domain_name (domain).c_str ());
 
   cust = objfile->lookup_symbol (block_index, name, domain);
   if (cust == NULL)
@@ -2477,7 +2467,7 @@  lookup_symbol_via_quick_fns (struct objfile *objfile,
 struct block_symbol
 language_defn::lookup_symbol_nonlocal (const char *name,
 				       const struct block *block,
-				       const domain_enum domain) const
+				       const domain_search_flags domain) const
 {
   struct block_symbol result;
 
@@ -2495,7 +2485,7 @@  language_defn::lookup_symbol_nonlocal (const char *name,
      shared libraries we could search all of them only to find out the
      builtin type isn't defined in any of them.  This is common for types
      like "void".  */
-  if (domain == VAR_DOMAIN)
+  if ((domain & SEARCH_TYPE_DOMAIN) != 0)
     {
       struct gdbarch *gdbarch;
 
@@ -2518,7 +2508,7 @@  language_defn::lookup_symbol_nonlocal (const char *name,
 struct block_symbol
 lookup_symbol_in_static_block (const char *name,
 			       const struct block *block,
-			       const domain_enum domain)
+			       const domain_search_flags domain)
 {
   if (block == nullptr)
     return {};
@@ -2538,7 +2528,7 @@  lookup_symbol_in_static_block (const char *name,
 	("lookup_symbol_in_static_block (%s, %s (objfile %s), %s)",
 	 name, host_address_to_string (block),
 	 objfile != nullptr ? objfile_debug_name (objfile) : "NULL",
-	 domain_name (domain));
+	 domain_name (domain).c_str ());
     }
 
   sym = lookup_symbol_in_block (name,
@@ -2557,7 +2547,7 @@  lookup_symbol_in_static_block (const char *name,
 
 static struct block_symbol
 lookup_symbol_in_objfile (struct objfile *objfile, enum block_enum block_index,
-			  const char *name, const domain_enum domain)
+			  const char *name, const domain_search_flags domain)
 {
   struct block_symbol result;
 
@@ -2567,7 +2557,7 @@  lookup_symbol_in_objfile (struct objfile *objfile, enum block_enum block_index,
 			      objfile_debug_name (objfile),
 			      block_index == GLOBAL_BLOCK
 			      ? "GLOBAL_BLOCK" : "STATIC_BLOCK",
-			      name, domain_name (domain));
+			      name, domain_name (domain).c_str ());
 
   result = lookup_symbol_in_objfile_symtabs (objfile, block_index,
 					     name, domain);
@@ -2598,7 +2588,7 @@  static struct block_symbol
 lookup_global_or_static_symbol (const char *name,
 				enum block_enum block_index,
 				struct objfile *objfile,
-				const domain_enum domain)
+				const domain_search_flags domain)
 {
   struct symbol_cache *cache = get_symbol_cache (current_program_space);
   struct block_symbol result;
@@ -2632,7 +2622,8 @@  lookup_global_or_static_symbol (const char *name,
        objfile);
 
   if (result.symbol != NULL)
-    symbol_cache_mark_found (bsc, slot, objfile, result.symbol, result.block);
+    symbol_cache_mark_found (bsc, slot, objfile, result.symbol, result.block,
+			     domain);
   else
     symbol_cache_mark_not_found (bsc, slot, objfile, name, domain);
 
@@ -2642,7 +2633,7 @@  lookup_global_or_static_symbol (const char *name,
 /* See symtab.h.  */
 
 struct block_symbol
-lookup_static_symbol (const char *name, const domain_enum domain)
+lookup_static_symbol (const char *name, const domain_search_flags domain)
 {
   return lookup_global_or_static_symbol (name, STATIC_BLOCK, nullptr, domain);
 }
@@ -2652,7 +2643,7 @@  lookup_static_symbol (const char *name, const domain_enum domain)
 struct block_symbol
 lookup_global_symbol (const char *name,
 		      const struct block *block,
-		      const domain_enum domain)
+		      const domain_search_flags domain)
 {
   /* If a block was passed in, we want to search the corresponding
      global block first.  This yields "more expected" behavior, and is
@@ -2761,7 +2752,7 @@  basic_lookup_transparent_type_quick (struct objfile *objfile,
   const struct block *block;
   struct symbol *sym;
 
-  cust = objfile->lookup_symbol (block_index, name, STRUCT_DOMAIN);
+  cust = objfile->lookup_symbol (block_index, name, SEARCH_STRUCT_DOMAIN);
   if (cust == NULL)
     return NULL;
 
@@ -2769,7 +2760,7 @@  basic_lookup_transparent_type_quick (struct objfile *objfile,
   block = bv->block (block_index);
 
   lookup_name_info lookup_name (name, symbol_name_match_type::FULL);
-  sym = block_find_symbol (block, lookup_name, STRUCT_DOMAIN, nullptr);
+  sym = block_find_symbol (block, lookup_name, SEARCH_STRUCT_DOMAIN, nullptr);
   if (sym == nullptr)
     error_in_psymtab_expansion (block_index, name, cust);
   gdb_assert (!TYPE_IS_OPAQUE (sym->type ()));
@@ -2794,7 +2785,8 @@  basic_lookup_transparent_type_1 (struct objfile *objfile,
     {
       bv = cust->blockvector ();
       block = bv->block (block_index);
-      sym = block_find_symbol (block, lookup_name, STRUCT_DOMAIN, nullptr);
+      sym = block_find_symbol (block, lookup_name, SEARCH_STRUCT_DOMAIN,
+			       nullptr);
       if (sym != nullptr)
 	{
 	  gdb_assert (!TYPE_IS_OPAQUE (sym->type ()));
@@ -4888,7 +4880,7 @@  global_symbol_searcher::expand_symtabs
 			 (msymbol->value_address (objfile)) == NULL)
 		      : (lookup_symbol_in_objfile_from_linkage_name
 			 (objfile, msymbol->linkage_name (),
-			  VAR_DOMAIN)
+			  SEARCH_VFT)
 			 .symbol == NULL))
 		    found_msymbol = true;
 		}
@@ -5026,7 +5018,7 @@  global_symbol_searcher::add_matching_msymbols
 		{
 		  if (lookup_symbol_in_objfile_from_linkage_name
 		      (objfile, msymbol->linkage_name (),
-		       VAR_DOMAIN).symbol == NULL)
+		       SEARCH_VFT).symbol == NULL)
 		    {
 		      /* Matching msymbol, add it to the results list.  */
 		      if (results->size () < m_max_search_results)
diff --git a/gdb/symtab.h b/gdb/symtab.h
index 69e3c060213..340ad170ece 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -2099,7 +2099,7 @@  struct field_of_this_result
 extern struct block_symbol
   lookup_symbol_in_language (const char *,
 			     const struct block *,
-			     const domain_enum,
+			     const domain_search_flags,
 			     enum language,
 			     struct field_of_this_result *);
 
@@ -2107,7 +2107,7 @@  extern struct block_symbol
 
 extern struct block_symbol lookup_symbol (const char *,
 					  const struct block *,
-					  const domain_enum,
+					  const domain_search_flags,
 					  struct field_of_this_result *);
 
 /* Find the definition for a specified symbol search name in domain
@@ -2119,9 +2119,10 @@  extern struct block_symbol lookup_symbol (const char *,
    pointer, or NULL if no symbol is found.  The symbol's section is
    fixed up if necessary.  */
 
-extern struct block_symbol lookup_symbol_search_name (const char *search_name,
-						      const struct block *block,
-						      domain_enum domain);
+extern struct block_symbol lookup_symbol_search_name
+     (const char *search_name,
+      const struct block *block,
+      domain_search_flags domain);
 
 /* Some helper functions for languages that need to write their own
    lookup_symbol_nonlocal functions.  */
@@ -2133,13 +2134,13 @@  extern struct block_symbol lookup_symbol_search_name (const char *search_name,
 extern struct block_symbol
   lookup_symbol_in_static_block (const char *name,
 				 const struct block *block,
-				 const domain_enum domain);
+				 const domain_search_flags domain);
 
 /* Search all static file-level symbols for NAME from DOMAIN.
    Upon success fixes up the symbol's section if necessary.  */
 
-extern struct block_symbol lookup_static_symbol (const char *name,
-						 const domain_enum domain);
+extern struct block_symbol lookup_static_symbol
+     (const char *name, const domain_search_flags domain);
 
 /* Lookup a symbol in all files' global blocks.
 
@@ -2155,7 +2156,7 @@  extern struct block_symbol lookup_static_symbol (const char *name,
 extern struct block_symbol
   lookup_global_symbol (const char *name,
 			const struct block *block,
-			const domain_enum domain);
+			const domain_search_flags domain);
 
 /* Lookup a symbol in block BLOCK.
    Upon success fixes up the symbol's section if necessary.  */
@@ -2164,7 +2165,7 @@  extern struct symbol *
   lookup_symbol_in_block (const char *name,
 			  symbol_name_match_type match_type,
 			  const struct block *block,
-			  const domain_enum domain);
+			  const domain_search_flags domain);
 
 /* Look up the `this' symbol for LANG in BLOCK.  Return the symbol if
    found, or NULL if not found.  */
@@ -2711,7 +2712,7 @@  extern struct block_symbol
   lookup_global_symbol_from_objfile (struct objfile *main_objfile,
 				     enum block_enum block_index,
 				     const char *name,
-				     const domain_enum domain);
+				     const domain_search_flags domain);
 
 /* Return 1 if the supplied producer string matches the ARM RealView
    compiler (armcc).  */
diff --git a/gdb/valops.c b/gdb/valops.c
index 93e2dfedad0..e2694f0c32b 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -118,15 +118,9 @@  find_function_in_inferior (const char *name, struct objfile **objf_p)
 {
   struct block_symbol sym;
 
-  sym = lookup_symbol (name, 0, VAR_DOMAIN, 0);
+  sym = lookup_symbol (name, nullptr, SEARCH_TYPE_DOMAIN, nullptr);
   if (sym.symbol != NULL)
     {
-      if (sym.symbol->aclass () != LOC_BLOCK)
-	{
-	  error (_("\"%s\" exists in this program but is not a function."),
-		 name);
-	}
-
       if (objf_p)
 	*objf_p = sym.symbol->objfile ();
 
@@ -3708,7 +3702,7 @@  value_struct_elt_for_reference (struct type *domain, int offset,
 	    {
 	      struct symbol *s = 
 		lookup_symbol (TYPE_FN_FIELD_PHYSNAME (f, j),
-			       0, VAR_DOMAIN, 0).symbol;
+			       0, SEARCH_FUNCTION_DOMAIN, 0).symbol;
 
 	      if (s == NULL)
 		return NULL;
@@ -3739,7 +3733,7 @@  value_struct_elt_for_reference (struct type *domain, int offset,
 	    {
 	      struct symbol *s = 
 		lookup_symbol (TYPE_FN_FIELD_PHYSNAME (f, j),
-			       0, VAR_DOMAIN, 0).symbol;
+			       0, SEARCH_FUNCTION_DOMAIN, 0).symbol;
 
 	      if (s == NULL)
 		return NULL;
@@ -3819,7 +3813,7 @@  value_maybe_namespace_elt (const struct type *curtype,
   struct value *result;
 
   sym = cp_lookup_symbol_namespace (namespace_name, name,
-				    get_selected_block (0), VAR_DOMAIN);
+				    get_selected_block (0), SEARCH_VFT);
 
   if (sym.symbol == NULL)
     return NULL;
diff --git a/gdb/value.c b/gdb/value.c
index 4ec9babcce8..ccaef9fd80f 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -2922,7 +2922,8 @@  value_static_field (struct type *type, int fieldno)
     {
       const char *phys_name = type->field (fieldno).loc_physname ();
       /* type->field (fieldno).name (); */
-      struct block_symbol sym = lookup_symbol (phys_name, 0, VAR_DOMAIN, 0);
+      struct block_symbol sym = lookup_symbol (phys_name, nullptr,
+					       SEARCH_VAR_DOMAIN, nullptr);
 
       if (sym.symbol == NULL)
 	{
@@ -3113,7 +3114,8 @@  value_fn_field (struct value **arg1p, struct fn_field *f,
   struct symbol *sym;
   struct bound_minimal_symbol msym;
 
-  sym = lookup_symbol (physname, 0, VAR_DOMAIN, 0).symbol;
+  sym = lookup_symbol (physname, nullptr, SEARCH_FUNCTION_DOMAIN,
+		       nullptr).symbol;
   if (sym == nullptr)
     {
       msym = lookup_bound_minimal_symbol (physname);
diff --git a/gdb/xstormy16-tdep.c b/gdb/xstormy16-tdep.c
index 71339c502d2..b19c9491fd0 100644
--- a/gdb/xstormy16-tdep.c
+++ b/gdb/xstormy16-tdep.c
@@ -423,7 +423,8 @@  xstormy16_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
 	return plg_end;
 
       /* Found a function.  */
-      sym = lookup_symbol (func_name, NULL, VAR_DOMAIN, NULL).symbol;
+      sym = lookup_symbol (func_name, NULL, SEARCH_FUNCTION_DOMAIN,
+			   nullptr).symbol;
       /* Don't use line number debug info for assembly source files.  */
       if (sym && sym->language () != language_asm)
 	{