+ struct symbol *function = BLOCK_FUNCTION (block);
+ struct symbol *result;
+
+ if (symbol_lookup_debug)
+ {
+ fprintf_unfiltered (gdb_stdlog,
+ "cp_lookup_symbol_imports_or_template"
+ " (%s, %s, %s, %s)\n",
+ scope, name, host_address_to_string (block),
+ domain_name (domain));
+ }
+
+ if (function != NULL && SYMBOL_LANGUAGE (function) == language_cplus)
+ {
+ /* Search the function's template parameters. */
+ if (SYMBOL_IS_CPLUS_TEMPLATE_FUNCTION (function))
+ {
+ struct template_symbol *templ
+ = (struct template_symbol *) function;
+
+ result = search_symbol_list (name,
+ templ->n_template_arguments,
+ templ->template_arguments);
+ if (result != NULL)
+ {
+ if (symbol_lookup_debug)
+ {
+ fprintf_unfiltered (gdb_stdlog,
+ "cp_lookup_symbol_imports_or_template"
+ " (...) = %s\n",
+ host_address_to_string (result));
+ }
+ return result;
+ }
+ }
+
+ /* Search the template parameters of the function's defining
+ context. */
+ if (SYMBOL_NATURAL_NAME (function))
+ {
+ struct type *context;
+ char *name_copy = xstrdup (SYMBOL_NATURAL_NAME (function));
+ struct cleanup *cleanups = make_cleanup (xfree, name_copy);
+ const struct language_defn *lang = language_def (language_cplus);
+ struct gdbarch *arch = symbol_arch (function);
+ const struct block *parent = BLOCK_SUPERBLOCK (block);
+
+ while (1)
+ {
+ unsigned int prefix_len = cp_entire_prefix_len (name_copy);
+
+ if (prefix_len == 0)
+ context = NULL;
+ else
+ {
+ name_copy[prefix_len] = '\0';
+ context = lookup_typename (lang, arch,
+ name_copy,
+ parent, 1);
+ }
+
+ if (context == NULL)
+ break;
+
+ result
+ = search_symbol_list (name,
+ TYPE_N_TEMPLATE_ARGUMENTS (context),
+ TYPE_TEMPLATE_ARGUMENTS (context));
+ if (result != NULL)
+ {
+ do_cleanups (cleanups);
+ if (symbol_lookup_debug)
+ {
+ fprintf_unfiltered (gdb_stdlog,
+ "cp_lookup_symbol_imports_or_template"
+ " (...) = %s\n",
+ host_address_to_string (result));
+ }
+ return result;
+ }
+ }
+
+ do_cleanups (cleanups);
+ }
+ }
+
+ result = cp_lookup_symbol_via_imports (scope, name, block, domain, 0, 1, 1);
+ if (symbol_lookup_debug)
+ {
+ fprintf_unfiltered (gdb_stdlog,
+ "cp_lookup_symbol_imports_or_template (...) = %s\n",
+ result != NULL
+ ? host_address_to_string (result) : "NULL");
+ }
+ return result;
+}
+
+/* Search for NAME by applying relevant import statements belonging to BLOCK
+ and its parents. SCOPE is the namespace scope of the context in which the
+ search is being evaluated. */
+
+static struct symbol *
+cp_lookup_symbol_via_all_imports (const char *scope, const char *name,
+ const struct block *block,
+ const domain_enum domain)
+{
+ struct symbol *sym;
+
+ while (block != NULL)
+ {
+ sym = cp_lookup_symbol_via_imports (scope, name, block, domain, 0, 0, 1);
+ if (sym)
+ return sym;
+
+ block = BLOCK_SUPERBLOCK (block);
+ }
+
+ return NULL;
+}
+
+/* Searches for NAME in the current namespace, and by applying
+ relevant import statements belonging to BLOCK and its parents.
+ SCOPE is the namespace scope of the context in which the search is
+ being evaluated. */
+
+struct symbol *
+cp_lookup_symbol_namespace (const char *scope,
+ const char *name,
+ const struct block *block,
+ const domain_enum domain)
+{
+ struct symbol *sym;
+
+ if (symbol_lookup_debug)
+ {
+ fprintf_unfiltered (gdb_stdlog,
+ "cp_lookup_symbol_namespace (%s, %s, %s, %s)\n",
+ scope, name, host_address_to_string (block),
+ domain_name (domain));
+ }
+
+ /* First, try to find the symbol in the given namespace. */
+ sym = cp_lookup_symbol_in_namespace (scope, name, block, domain, 1);
+
+ /* Search for name in namespaces imported to this and parent blocks. */
+ if (sym == NULL)
+ sym = cp_lookup_symbol_via_all_imports (scope, name, block, domain);
+
+ if (symbol_lookup_debug)
+ {
+ fprintf_unfiltered (gdb_stdlog,
+ "cp_lookup_symbol_namespace (...) = %s\n",
+ sym != NULL ? host_address_to_string (sym) : "NULL");
+ }
+ return sym;