Update NEWS post GDB 10 branch creation.
[binutils-gdb.git] / gdb / block.c
blob597d6d5d875a9b7a12af20d9e9780b42deef4ef3
1 /* Block-related functions for the GNU debugger, GDB.
3 Copyright (C) 2003-2020 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #include "defs.h"
21 #include "block.h"
22 #include "symtab.h"
23 #include "symfile.h"
24 #include "gdb_obstack.h"
25 #include "cp-support.h"
26 #include "addrmap.h"
27 #include "gdbtypes.h"
28 #include "objfiles.h"
30 /* This is used by struct block to store namespace-related info for
31 C++ files, namely using declarations and the current namespace in
32 scope. */
34 struct block_namespace_info : public allocate_on_obstack
36 const char *scope = nullptr;
37 struct using_direct *using_decl = nullptr;
40 static void block_initialize_namespace (struct block *block,
41 struct obstack *obstack);
43 /* See block.h. */
45 struct objfile *
46 block_objfile (const struct block *block)
48 const struct global_block *global_block;
50 if (BLOCK_FUNCTION (block) != NULL)
51 return symbol_objfile (BLOCK_FUNCTION (block));
53 global_block = (struct global_block *) block_global_block (block);
54 return COMPUNIT_OBJFILE (global_block->compunit_symtab);
57 /* See block. */
59 struct gdbarch *
60 block_gdbarch (const struct block *block)
62 if (BLOCK_FUNCTION (block) != NULL)
63 return symbol_arch (BLOCK_FUNCTION (block));
65 return block_objfile (block)->arch ();
68 /* See block.h. */
70 bool
71 contained_in (const struct block *a, const struct block *b,
72 bool allow_nested)
74 if (!a || !b)
75 return false;
79 if (a == b)
80 return true;
81 /* If A is a function block, then A cannot be contained in B,
82 except if A was inlined. */
83 if (!allow_nested && BLOCK_FUNCTION (a) != NULL && !block_inlined_p (a))
84 return false;
85 a = BLOCK_SUPERBLOCK (a);
87 while (a != NULL);
89 return false;
93 /* Return the symbol for the function which contains a specified
94 lexical block, described by a struct block BL. The return value
95 will not be an inlined function; the containing function will be
96 returned instead. */
98 struct symbol *
99 block_linkage_function (const struct block *bl)
101 while ((BLOCK_FUNCTION (bl) == NULL || block_inlined_p (bl))
102 && BLOCK_SUPERBLOCK (bl) != NULL)
103 bl = BLOCK_SUPERBLOCK (bl);
105 return BLOCK_FUNCTION (bl);
108 /* Return the symbol for the function which contains a specified
109 block, described by a struct block BL. The return value will be
110 the closest enclosing function, which might be an inline
111 function. */
113 struct symbol *
114 block_containing_function (const struct block *bl)
116 while (BLOCK_FUNCTION (bl) == NULL && BLOCK_SUPERBLOCK (bl) != NULL)
117 bl = BLOCK_SUPERBLOCK (bl);
119 return BLOCK_FUNCTION (bl);
122 /* Return one if BL represents an inlined function. */
125 block_inlined_p (const struct block *bl)
127 return BLOCK_FUNCTION (bl) != NULL && SYMBOL_INLINED (BLOCK_FUNCTION (bl));
130 /* A helper function that checks whether PC is in the blockvector BL.
131 It returns the containing block if there is one, or else NULL. */
133 static const struct block *
134 find_block_in_blockvector (const struct blockvector *bl, CORE_ADDR pc)
136 const struct block *b;
137 int bot, top, half;
139 /* If we have an addrmap mapping code addresses to blocks, then use
140 that. */
141 if (BLOCKVECTOR_MAP (bl))
142 return (const struct block *) addrmap_find (BLOCKVECTOR_MAP (bl), pc);
144 /* Otherwise, use binary search to find the last block that starts
145 before PC.
146 Note: GLOBAL_BLOCK is block 0, STATIC_BLOCK is block 1.
147 They both have the same START,END values.
148 Historically this code would choose STATIC_BLOCK over GLOBAL_BLOCK but the
149 fact that this choice was made was subtle, now we make it explicit. */
150 gdb_assert (BLOCKVECTOR_NBLOCKS (bl) >= 2);
151 bot = STATIC_BLOCK;
152 top = BLOCKVECTOR_NBLOCKS (bl);
154 while (top - bot > 1)
156 half = (top - bot + 1) >> 1;
157 b = BLOCKVECTOR_BLOCK (bl, bot + half);
158 if (BLOCK_START (b) <= pc)
159 bot += half;
160 else
161 top = bot + half;
164 /* Now search backward for a block that ends after PC. */
166 while (bot >= STATIC_BLOCK)
168 b = BLOCKVECTOR_BLOCK (bl, bot);
169 if (BLOCK_END (b) > pc)
170 return b;
171 bot--;
174 return NULL;
177 /* Return the blockvector immediately containing the innermost lexical
178 block containing the specified pc value and section, or 0 if there
179 is none. PBLOCK is a pointer to the block. If PBLOCK is NULL, we
180 don't pass this information back to the caller. */
182 const struct blockvector *
183 blockvector_for_pc_sect (CORE_ADDR pc, struct obj_section *section,
184 const struct block **pblock,
185 struct compunit_symtab *cust)
187 const struct blockvector *bl;
188 const struct block *b;
190 if (cust == NULL)
192 /* First search all symtabs for one whose file contains our pc */
193 cust = find_pc_sect_compunit_symtab (pc, section);
194 if (cust == NULL)
195 return 0;
198 bl = COMPUNIT_BLOCKVECTOR (cust);
200 /* Then search that symtab for the smallest block that wins. */
201 b = find_block_in_blockvector (bl, pc);
202 if (b == NULL)
203 return NULL;
205 if (pblock)
206 *pblock = b;
207 return bl;
210 /* Return true if the blockvector BV contains PC, false otherwise. */
213 blockvector_contains_pc (const struct blockvector *bv, CORE_ADDR pc)
215 return find_block_in_blockvector (bv, pc) != NULL;
218 /* Return call_site for specified PC in GDBARCH. PC must match exactly, it
219 must be the next instruction after call (or after tail call jump). Throw
220 NO_ENTRY_VALUE_ERROR otherwise. This function never returns NULL. */
222 struct call_site *
223 call_site_for_pc (struct gdbarch *gdbarch, CORE_ADDR pc)
225 struct compunit_symtab *cust;
226 void **slot = NULL;
228 /* -1 as tail call PC can be already after the compilation unit range. */
229 cust = find_pc_compunit_symtab (pc - 1);
231 if (cust != NULL && COMPUNIT_CALL_SITE_HTAB (cust) != NULL)
232 slot = htab_find_slot (COMPUNIT_CALL_SITE_HTAB (cust), &pc, NO_INSERT);
234 if (slot == NULL)
236 struct bound_minimal_symbol msym = lookup_minimal_symbol_by_pc (pc);
238 /* DW_TAG_gnu_call_site will be missing just if GCC could not determine
239 the call target. */
240 throw_error (NO_ENTRY_VALUE_ERROR,
241 _("DW_OP_entry_value resolving cannot find "
242 "DW_TAG_call_site %s in %s"),
243 paddress (gdbarch, pc),
244 (msym.minsym == NULL ? "???"
245 : msym.minsym->print_name ()));
248 return (struct call_site *) *slot;
251 /* Return the blockvector immediately containing the innermost lexical block
252 containing the specified pc value, or 0 if there is none.
253 Backward compatibility, no section. */
255 const struct blockvector *
256 blockvector_for_pc (CORE_ADDR pc, const struct block **pblock)
258 return blockvector_for_pc_sect (pc, find_pc_mapped_section (pc),
259 pblock, NULL);
262 /* Return the innermost lexical block containing the specified pc value
263 in the specified section, or 0 if there is none. */
265 const struct block *
266 block_for_pc_sect (CORE_ADDR pc, struct obj_section *section)
268 const struct blockvector *bl;
269 const struct block *b;
271 bl = blockvector_for_pc_sect (pc, section, &b, NULL);
272 if (bl)
273 return b;
274 return 0;
277 /* Return the innermost lexical block containing the specified pc value,
278 or 0 if there is none. Backward compatibility, no section. */
280 const struct block *
281 block_for_pc (CORE_ADDR pc)
283 return block_for_pc_sect (pc, find_pc_mapped_section (pc));
286 /* Now come some functions designed to deal with C++ namespace issues.
287 The accessors are safe to use even in the non-C++ case. */
289 /* This returns the namespace that BLOCK is enclosed in, or "" if it
290 isn't enclosed in a namespace at all. This travels the chain of
291 superblocks looking for a scope, if necessary. */
293 const char *
294 block_scope (const struct block *block)
296 for (; block != NULL; block = BLOCK_SUPERBLOCK (block))
298 if (BLOCK_NAMESPACE (block) != NULL
299 && BLOCK_NAMESPACE (block)->scope != NULL)
300 return BLOCK_NAMESPACE (block)->scope;
303 return "";
306 /* Set BLOCK's scope member to SCOPE; if needed, allocate memory via
307 OBSTACK. (It won't make a copy of SCOPE, however, so that already
308 has to be allocated correctly.) */
310 void
311 block_set_scope (struct block *block, const char *scope,
312 struct obstack *obstack)
314 block_initialize_namespace (block, obstack);
316 BLOCK_NAMESPACE (block)->scope = scope;
319 /* This returns the using directives list associated with BLOCK, if
320 any. */
322 struct using_direct *
323 block_using (const struct block *block)
325 if (block == NULL || BLOCK_NAMESPACE (block) == NULL)
326 return NULL;
327 else
328 return BLOCK_NAMESPACE (block)->using_decl;
331 /* Set BLOCK's using member to USING; if needed, allocate memory via
332 OBSTACK. (It won't make a copy of USING, however, so that already
333 has to be allocated correctly.) */
335 void
336 block_set_using (struct block *block,
337 struct using_direct *using_decl,
338 struct obstack *obstack)
340 block_initialize_namespace (block, obstack);
342 BLOCK_NAMESPACE (block)->using_decl = using_decl;
345 /* If BLOCK_NAMESPACE (block) is NULL, allocate it via OBSTACK and
346 initialize its members to zero. */
348 static void
349 block_initialize_namespace (struct block *block, struct obstack *obstack)
351 if (BLOCK_NAMESPACE (block) == NULL)
352 BLOCK_NAMESPACE (block) = new (obstack) struct block_namespace_info ();
355 /* Return the static block associated to BLOCK. Return NULL if block
356 is NULL or if block is a global block. */
358 const struct block *
359 block_static_block (const struct block *block)
361 if (block == NULL || BLOCK_SUPERBLOCK (block) == NULL)
362 return NULL;
364 while (BLOCK_SUPERBLOCK (BLOCK_SUPERBLOCK (block)) != NULL)
365 block = BLOCK_SUPERBLOCK (block);
367 return block;
370 /* Return the static block associated to BLOCK. Return NULL if block
371 is NULL. */
373 const struct block *
374 block_global_block (const struct block *block)
376 if (block == NULL)
377 return NULL;
379 while (BLOCK_SUPERBLOCK (block) != NULL)
380 block = BLOCK_SUPERBLOCK (block);
382 return block;
385 /* Allocate a block on OBSTACK, and initialize its elements to
386 zero/NULL. This is useful for creating "dummy" blocks that don't
387 correspond to actual source files.
389 Warning: it sets the block's BLOCK_MULTIDICT to NULL, which isn't a
390 valid value. If you really don't want the block to have a
391 dictionary, then you should subsequently set its BLOCK_MULTIDICT to
392 dict_create_linear (obstack, NULL). */
394 struct block *
395 allocate_block (struct obstack *obstack)
397 struct block *bl = OBSTACK_ZALLOC (obstack, struct block);
399 return bl;
402 /* Allocate a global block. */
404 struct block *
405 allocate_global_block (struct obstack *obstack)
407 struct global_block *bl = OBSTACK_ZALLOC (obstack, struct global_block);
409 return &bl->block;
412 /* Set the compunit of the global block. */
414 void
415 set_block_compunit_symtab (struct block *block, struct compunit_symtab *cu)
417 struct global_block *gb;
419 gdb_assert (BLOCK_SUPERBLOCK (block) == NULL);
420 gb = (struct global_block *) block;
421 gdb_assert (gb->compunit_symtab == NULL);
422 gb->compunit_symtab = cu;
425 /* See block.h. */
427 struct dynamic_prop *
428 block_static_link (const struct block *block)
430 struct objfile *objfile = block_objfile (block);
432 /* Only objfile-owned blocks that materialize top function scopes can have
433 static links. */
434 if (objfile == NULL || BLOCK_FUNCTION (block) == NULL)
435 return NULL;
437 return (struct dynamic_prop *) objfile_lookup_static_link (objfile, block);
440 /* Return the compunit of the global block. */
442 static struct compunit_symtab *
443 get_block_compunit_symtab (const struct block *block)
445 struct global_block *gb;
447 gdb_assert (BLOCK_SUPERBLOCK (block) == NULL);
448 gb = (struct global_block *) block;
449 gdb_assert (gb->compunit_symtab != NULL);
450 return gb->compunit_symtab;
455 /* Initialize a block iterator, either to iterate over a single block,
456 or, for static and global blocks, all the included symtabs as
457 well. */
459 static void
460 initialize_block_iterator (const struct block *block,
461 struct block_iterator *iter)
463 enum block_enum which;
464 struct compunit_symtab *cu;
466 iter->idx = -1;
468 if (BLOCK_SUPERBLOCK (block) == NULL)
470 which = GLOBAL_BLOCK;
471 cu = get_block_compunit_symtab (block);
473 else if (BLOCK_SUPERBLOCK (BLOCK_SUPERBLOCK (block)) == NULL)
475 which = STATIC_BLOCK;
476 cu = get_block_compunit_symtab (BLOCK_SUPERBLOCK (block));
478 else
480 iter->d.block = block;
481 /* A signal value meaning that we're iterating over a single
482 block. */
483 iter->which = FIRST_LOCAL_BLOCK;
484 return;
487 /* If this is an included symtab, find the canonical includer and
488 use it instead. */
489 while (cu->user != NULL)
490 cu = cu->user;
492 /* Putting this check here simplifies the logic of the iterator
493 functions. If there are no included symtabs, we only need to
494 search a single block, so we might as well just do that
495 directly. */
496 if (cu->includes == NULL)
498 iter->d.block = block;
499 /* A signal value meaning that we're iterating over a single
500 block. */
501 iter->which = FIRST_LOCAL_BLOCK;
503 else
505 iter->d.compunit_symtab = cu;
506 iter->which = which;
510 /* A helper function that finds the current compunit over whose static
511 or global block we should iterate. */
513 static struct compunit_symtab *
514 find_iterator_compunit_symtab (struct block_iterator *iterator)
516 if (iterator->idx == -1)
517 return iterator->d.compunit_symtab;
518 return iterator->d.compunit_symtab->includes[iterator->idx];
521 /* Perform a single step for a plain block iterator, iterating across
522 symbol tables as needed. Returns the next symbol, or NULL when
523 iteration is complete. */
525 static struct symbol *
526 block_iterator_step (struct block_iterator *iterator, int first)
528 struct symbol *sym;
530 gdb_assert (iterator->which != FIRST_LOCAL_BLOCK);
532 while (1)
534 if (first)
536 struct compunit_symtab *cust
537 = find_iterator_compunit_symtab (iterator);
538 const struct block *block;
540 /* Iteration is complete. */
541 if (cust == NULL)
542 return NULL;
544 block = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust),
545 iterator->which);
546 sym = mdict_iterator_first (BLOCK_MULTIDICT (block),
547 &iterator->mdict_iter);
549 else
550 sym = mdict_iterator_next (&iterator->mdict_iter);
552 if (sym != NULL)
553 return sym;
555 /* We have finished iterating the appropriate block of one
556 symtab. Now advance to the next symtab and begin iteration
557 there. */
558 ++iterator->idx;
559 first = 1;
563 /* See block.h. */
565 struct symbol *
566 block_iterator_first (const struct block *block,
567 struct block_iterator *iterator)
569 initialize_block_iterator (block, iterator);
571 if (iterator->which == FIRST_LOCAL_BLOCK)
572 return mdict_iterator_first (block->multidict, &iterator->mdict_iter);
574 return block_iterator_step (iterator, 1);
577 /* See block.h. */
579 struct symbol *
580 block_iterator_next (struct block_iterator *iterator)
582 if (iterator->which == FIRST_LOCAL_BLOCK)
583 return mdict_iterator_next (&iterator->mdict_iter);
585 return block_iterator_step (iterator, 0);
588 /* Perform a single step for a "match" block iterator, iterating
589 across symbol tables as needed. Returns the next symbol, or NULL
590 when iteration is complete. */
592 static struct symbol *
593 block_iter_match_step (struct block_iterator *iterator,
594 const lookup_name_info &name,
595 int first)
597 struct symbol *sym;
599 gdb_assert (iterator->which != FIRST_LOCAL_BLOCK);
601 while (1)
603 if (first)
605 struct compunit_symtab *cust
606 = find_iterator_compunit_symtab (iterator);
607 const struct block *block;
609 /* Iteration is complete. */
610 if (cust == NULL)
611 return NULL;
613 block = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust),
614 iterator->which);
615 sym = mdict_iter_match_first (BLOCK_MULTIDICT (block), name,
616 &iterator->mdict_iter);
618 else
619 sym = mdict_iter_match_next (name, &iterator->mdict_iter);
621 if (sym != NULL)
622 return sym;
624 /* We have finished iterating the appropriate block of one
625 symtab. Now advance to the next symtab and begin iteration
626 there. */
627 ++iterator->idx;
628 first = 1;
632 /* See block.h. */
634 struct symbol *
635 block_iter_match_first (const struct block *block,
636 const lookup_name_info &name,
637 struct block_iterator *iterator)
639 initialize_block_iterator (block, iterator);
641 if (iterator->which == FIRST_LOCAL_BLOCK)
642 return mdict_iter_match_first (block->multidict, name,
643 &iterator->mdict_iter);
645 return block_iter_match_step (iterator, name, 1);
648 /* See block.h. */
650 struct symbol *
651 block_iter_match_next (const lookup_name_info &name,
652 struct block_iterator *iterator)
654 if (iterator->which == FIRST_LOCAL_BLOCK)
655 return mdict_iter_match_next (name, &iterator->mdict_iter);
657 return block_iter_match_step (iterator, name, 0);
660 /* See block.h. */
662 bool
663 best_symbol (struct symbol *a, const domain_enum domain)
665 return (SYMBOL_DOMAIN (a) == domain
666 && SYMBOL_CLASS (a) != LOC_UNRESOLVED);
669 /* See block.h. */
671 struct symbol *
672 better_symbol (struct symbol *a, struct symbol *b, const domain_enum domain)
674 if (a == NULL)
675 return b;
676 if (b == NULL)
677 return a;
679 if (SYMBOL_DOMAIN (a) == domain
680 && SYMBOL_DOMAIN (b) != domain)
681 return a;
682 if (SYMBOL_DOMAIN (b) == domain
683 && SYMBOL_DOMAIN (a) != domain)
684 return b;
686 if (SYMBOL_CLASS (a) != LOC_UNRESOLVED
687 && SYMBOL_CLASS (b) == LOC_UNRESOLVED)
688 return a;
689 if (SYMBOL_CLASS (b) != LOC_UNRESOLVED
690 && SYMBOL_CLASS (a) == LOC_UNRESOLVED)
691 return b;
693 return a;
696 /* See block.h.
698 Note that if NAME is the demangled form of a C++ symbol, we will fail
699 to find a match during the binary search of the non-encoded names, but
700 for now we don't worry about the slight inefficiency of looking for
701 a match we'll never find, since it will go pretty quick. Once the
702 binary search terminates, we drop through and do a straight linear
703 search on the symbols. Each symbol which is marked as being a ObjC/C++
704 symbol (language_cplus or language_objc set) has both the encoded and
705 non-encoded names tested for a match. */
707 struct symbol *
708 block_lookup_symbol (const struct block *block, const char *name,
709 symbol_name_match_type match_type,
710 const domain_enum domain)
712 struct block_iterator iter;
713 struct symbol *sym;
715 lookup_name_info lookup_name (name, match_type);
717 if (!BLOCK_FUNCTION (block))
719 struct symbol *other = NULL;
721 ALL_BLOCK_SYMBOLS_WITH_NAME (block, lookup_name, iter, sym)
723 /* See comment related to PR gcc/debug/91507 in
724 block_lookup_symbol_primary. */
725 if (best_symbol (sym, domain))
726 return sym;
727 /* This is a bit of a hack, but symbol_matches_domain might ignore
728 STRUCT vs VAR domain symbols. So if a matching symbol is found,
729 make sure there is no "better" matching symbol, i.e., one with
730 exactly the same domain. PR 16253. */
731 if (symbol_matches_domain (sym->language (),
732 SYMBOL_DOMAIN (sym), domain))
733 other = better_symbol (other, sym, domain);
735 return other;
737 else
739 /* Note that parameter symbols do not always show up last in the
740 list; this loop makes sure to take anything else other than
741 parameter symbols first; it only uses parameter symbols as a
742 last resort. Note that this only takes up extra computation
743 time on a match.
744 It's hard to define types in the parameter list (at least in
745 C/C++) so we don't do the same PR 16253 hack here that is done
746 for the !BLOCK_FUNCTION case. */
748 struct symbol *sym_found = NULL;
750 ALL_BLOCK_SYMBOLS_WITH_NAME (block, lookup_name, iter, sym)
752 if (symbol_matches_domain (sym->language (),
753 SYMBOL_DOMAIN (sym), domain))
755 sym_found = sym;
756 if (!SYMBOL_IS_ARGUMENT (sym))
758 break;
762 return (sym_found); /* Will be NULL if not found. */
766 /* See block.h. */
768 struct symbol *
769 block_lookup_symbol_primary (const struct block *block, const char *name,
770 const domain_enum domain)
772 struct symbol *sym, *other;
773 struct mdict_iterator mdict_iter;
775 lookup_name_info lookup_name (name, symbol_name_match_type::FULL);
777 /* Verify BLOCK is STATIC_BLOCK or GLOBAL_BLOCK. */
778 gdb_assert (BLOCK_SUPERBLOCK (block) == NULL
779 || BLOCK_SUPERBLOCK (BLOCK_SUPERBLOCK (block)) == NULL);
781 other = NULL;
782 for (sym
783 = mdict_iter_match_first (block->multidict, lookup_name, &mdict_iter);
784 sym != NULL;
785 sym = mdict_iter_match_next (lookup_name, &mdict_iter))
787 /* With the fix for PR gcc/debug/91507, we get for:
789 extern char *zzz[];
790 char *zzz[ ] = {
791 "abc",
792 "cde"
795 DWARF which will result in two entries in the symbol table, a decl
796 with type char *[] and a def with type char *[2].
798 If we return the decl here, we don't get the value of zzz:
800 $ gdb a.spec.out -batch -ex "p zzz"
801 $1 = 0x601030 <zzz>
803 because we're returning the symbol without location information, and
804 because the fallback that uses the address from the minimal symbols
805 doesn't work either because the type of the decl does not specify a
806 size.
808 To fix this, we prefer def over decl in best_symbol and
809 better_symbol.
811 In absence of the gcc fix, both def and decl have type char *[], so
812 the only option to make this work is improve the fallback to use the
813 size of the minimal symbol. Filed as PR exp/24989. */
814 if (best_symbol (sym, domain))
815 return sym;
817 /* This is a bit of a hack, but symbol_matches_domain might ignore
818 STRUCT vs VAR domain symbols. So if a matching symbol is found,
819 make sure there is no "better" matching symbol, i.e., one with
820 exactly the same domain. PR 16253. */
821 if (symbol_matches_domain (sym->language (), SYMBOL_DOMAIN (sym), domain))
822 other = better_symbol (other, sym, domain);
825 return other;
828 /* See block.h. */
830 struct symbol *
831 block_find_symbol (const struct block *block, const char *name,
832 const domain_enum domain,
833 block_symbol_matcher_ftype *matcher, void *data)
835 struct block_iterator iter;
836 struct symbol *sym;
838 lookup_name_info lookup_name (name, symbol_name_match_type::FULL);
840 /* Verify BLOCK is STATIC_BLOCK or GLOBAL_BLOCK. */
841 gdb_assert (BLOCK_SUPERBLOCK (block) == NULL
842 || BLOCK_SUPERBLOCK (BLOCK_SUPERBLOCK (block)) == NULL);
844 ALL_BLOCK_SYMBOLS_WITH_NAME (block, lookup_name, iter, sym)
846 /* MATCHER is deliberately called second here so that it never sees
847 a non-domain-matching symbol. */
848 if (symbol_matches_domain (sym->language (), SYMBOL_DOMAIN (sym), domain)
849 && matcher (sym, data))
850 return sym;
852 return NULL;
855 /* See block.h. */
858 block_find_non_opaque_type (struct symbol *sym, void *data)
860 return !TYPE_IS_OPAQUE (SYMBOL_TYPE (sym));
863 /* See block.h. */
866 block_find_non_opaque_type_preferred (struct symbol *sym, void *data)
868 struct symbol **best = (struct symbol **) data;
870 if (!TYPE_IS_OPAQUE (SYMBOL_TYPE (sym)))
871 return 1;
872 *best = sym;
873 return 0;
876 /* See block.h. */
878 struct blockranges *
879 make_blockranges (struct objfile *objfile,
880 const std::vector<blockrange> &rangevec)
882 struct blockranges *blr;
883 size_t n = rangevec.size();
885 blr = (struct blockranges *)
886 obstack_alloc (&objfile->objfile_obstack,
887 sizeof (struct blockranges)
888 + (n - 1) * sizeof (struct blockrange));
890 blr->nranges = n;
891 for (int i = 0; i < n; i++)
892 blr->range[i] = rangevec[i];
893 return blr;