+
+/* See block.h. */
+
+struct symbol *
+block_lookup_symbol_primary (const struct block *block, const char *name,
+ const domain_enum domain)
+{
+ struct symbol *sym, *other;
+ struct mdict_iterator mdict_iter;
+
+ lookup_name_info lookup_name (name, symbol_name_match_type::FULL);
+
+ /* Verify BLOCK is STATIC_BLOCK or GLOBAL_BLOCK. */
+ gdb_assert (BLOCK_SUPERBLOCK (block) == NULL
+ || BLOCK_SUPERBLOCK (BLOCK_SUPERBLOCK (block)) == NULL);
+
+ other = NULL;
+ for (sym
+ = mdict_iter_match_first (block->multidict, lookup_name, &mdict_iter);
+ sym != NULL;
+ sym = mdict_iter_match_next (lookup_name, &mdict_iter))
+ {
+ /* With the fix for PR gcc/debug/91507, we get for:
+ ...
+ extern char *zzz[];
+ char *zzz[ ] = {
+ "abc",
+ "cde"
+ };
+ ...
+ DWARF which will result in two entries in the symbol table, a decl
+ with type char *[] and a def with type char *[2].
+
+ If we return the decl here, we don't get the value of zzz:
+ ...
+ $ gdb a.spec.out -batch -ex "p zzz"
+ $1 = 0x601030 <zzz>
+ ...
+ because we're returning the symbol without location information, and
+ because the fallback that uses the address from the minimal symbols
+ doesn't work either because the type of the decl does not specify a
+ size.
+
+ To fix this, we prefer def over decl in best_symbol and
+ better_symbol.
+
+ In absence of the gcc fix, both def and decl have type char *[], so
+ the only option to make this work is improve the fallback to use the
+ size of the minimal symbol. Filed as PR exp/24989. */
+ if (best_symbol (sym, domain))
+ return sym;
+
+ /* This is a bit of a hack, but symbol_matches_domain might ignore
+ STRUCT vs VAR domain symbols. So if a matching symbol is found,
+ make sure there is no "better" matching symbol, i.e., one with
+ exactly the same domain. PR 16253. */
+ if (symbol_matches_domain (sym->language (), SYMBOL_DOMAIN (sym), domain))
+ other = better_symbol (other, sym, domain);
+ }
+
+ return other;
+}
+
+/* See block.h. */
+
+struct symbol *
+block_find_symbol (const struct block *block, const char *name,
+ const domain_enum domain,
+ block_symbol_matcher_ftype *matcher, void *data)
+{
+ struct block_iterator iter;
+ struct symbol *sym;
+
+ lookup_name_info lookup_name (name, symbol_name_match_type::FULL);
+
+ /* Verify BLOCK is STATIC_BLOCK or GLOBAL_BLOCK. */
+ gdb_assert (BLOCK_SUPERBLOCK (block) == NULL
+ || BLOCK_SUPERBLOCK (BLOCK_SUPERBLOCK (block)) == NULL);
+
+ ALL_BLOCK_SYMBOLS_WITH_NAME (block, lookup_name, iter, sym)
+ {
+ /* MATCHER is deliberately called second here so that it never sees
+ a non-domain-matching symbol. */
+ if (symbol_matches_domain (sym->language (), SYMBOL_DOMAIN (sym), domain)
+ && matcher (sym, data))
+ return sym;
+ }
+ return NULL;
+}
+
+/* See block.h. */
+
+int
+block_find_non_opaque_type (struct symbol *sym, void *data)
+{
+ return !TYPE_IS_OPAQUE (SYMBOL_TYPE (sym));
+}
+
+/* See block.h. */
+
+int
+block_find_non_opaque_type_preferred (struct symbol *sym, void *data)
+{
+ struct symbol **best = (struct symbol **) data;
+
+ if (!TYPE_IS_OPAQUE (SYMBOL_TYPE (sym)))
+ return 1;
+ *best = sym;
+ return 0;
+}
+
+/* See block.h. */
+
+struct blockranges *
+make_blockranges (struct objfile *objfile,
+ const std::vector<blockrange> &rangevec)
+{
+ struct blockranges *blr;
+ size_t n = rangevec.size();
+
+ blr = (struct blockranges *)
+ obstack_alloc (&objfile->objfile_obstack,
+ sizeof (struct blockranges)
+ + (n - 1) * sizeof (struct blockrange));
+
+ blr->nranges = n;
+ for (int i = 0; i < n; i++)
+ blr->range[i] = rangevec[i];
+ return blr;
+}
+