]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/block.c
Rearrange block.c to avoid a forward declaration
[thirdparty/binutils-gdb.git] / gdb / block.c
1 /* Block-related functions for the GNU debugger, GDB.
2
3 Copyright (C) 2003-2023 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
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.
11
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.
16
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/>. */
19
20 #include "defs.h"
21 #include "block.h"
22 #include "symtab.h"
23 #include "symfile.h"
24 #include "gdbsupport/gdb_obstack.h"
25 #include "cp-support.h"
26 #include "addrmap.h"
27 #include "gdbtypes.h"
28 #include "objfiles.h"
29
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. */
33
34 struct block_namespace_info : public allocate_on_obstack
35 {
36 const char *scope = nullptr;
37 struct using_direct *using_decl = nullptr;
38 };
39
40 /* See block.h. */
41
42 struct objfile *
43 block_objfile (const struct block *block)
44 {
45 const struct global_block *global_block;
46
47 if (block->function () != nullptr)
48 return block->function ()->objfile ();
49
50 global_block = (struct global_block *) block_global_block (block);
51 return global_block->compunit_symtab->objfile ();
52 }
53
54 /* See block. */
55
56 struct gdbarch *
57 block_gdbarch (const struct block *block)
58 {
59 if (block->function () != nullptr)
60 return block->function ()->arch ();
61
62 return block_objfile (block)->arch ();
63 }
64
65 /* See block.h. */
66
67 bool
68 contained_in (const struct block *a, const struct block *b,
69 bool allow_nested)
70 {
71 if (!a || !b)
72 return false;
73
74 do
75 {
76 if (a == b)
77 return true;
78 /* If A is a function block, then A cannot be contained in B,
79 except if A was inlined. */
80 if (!allow_nested && a->function () != NULL && !block_inlined_p (a))
81 return false;
82 a = a->superblock ();
83 }
84 while (a != NULL);
85
86 return false;
87 }
88
89
90 /* Return the symbol for the function which contains a specified
91 lexical block, described by a struct block BL. The return value
92 will not be an inlined function; the containing function will be
93 returned instead. */
94
95 struct symbol *
96 block_linkage_function (const struct block *bl)
97 {
98 while ((bl->function () == NULL || block_inlined_p (bl))
99 && bl->superblock () != NULL)
100 bl = bl->superblock ();
101
102 return bl->function ();
103 }
104
105 /* Return the symbol for the function which contains a specified
106 block, described by a struct block BL. The return value will be
107 the closest enclosing function, which might be an inline
108 function. */
109
110 struct symbol *
111 block_containing_function (const struct block *bl)
112 {
113 while (bl->function () == NULL && bl->superblock () != NULL)
114 bl = bl->superblock ();
115
116 return bl->function ();
117 }
118
119 /* Return one if BL represents an inlined function. */
120
121 int
122 block_inlined_p (const struct block *bl)
123 {
124 return bl->function () != NULL && bl->function ()->is_inlined ();
125 }
126
127 /* A helper function that checks whether PC is in the blockvector BL.
128 It returns the containing block if there is one, or else NULL. */
129
130 static const struct block *
131 find_block_in_blockvector (const struct blockvector *bl, CORE_ADDR pc)
132 {
133 const struct block *b;
134 int bot, top, half;
135
136 /* If we have an addrmap mapping code addresses to blocks, then use
137 that. */
138 if (bl->map ())
139 return (const struct block *) bl->map ()->find (pc);
140
141 /* Otherwise, use binary search to find the last block that starts
142 before PC.
143 Note: GLOBAL_BLOCK is block 0, STATIC_BLOCK is block 1.
144 They both have the same START,END values.
145 Historically this code would choose STATIC_BLOCK over GLOBAL_BLOCK but the
146 fact that this choice was made was subtle, now we make it explicit. */
147 gdb_assert (bl->blocks ().size () >= 2);
148 bot = STATIC_BLOCK;
149 top = bl->blocks ().size ();
150
151 while (top - bot > 1)
152 {
153 half = (top - bot + 1) >> 1;
154 b = bl->block (bot + half);
155 if (b->start () <= pc)
156 bot += half;
157 else
158 top = bot + half;
159 }
160
161 /* Now search backward for a block that ends after PC. */
162
163 while (bot >= STATIC_BLOCK)
164 {
165 b = bl->block (bot);
166 if (!(b->start () <= pc))
167 return NULL;
168 if (b->end () > pc)
169 return b;
170 bot--;
171 }
172
173 return NULL;
174 }
175
176 /* Return the blockvector immediately containing the innermost lexical
177 block containing the specified pc value and section, or 0 if there
178 is none. PBLOCK is a pointer to the block. If PBLOCK is NULL, we
179 don't pass this information back to the caller. */
180
181 const struct blockvector *
182 blockvector_for_pc_sect (CORE_ADDR pc, struct obj_section *section,
183 const struct block **pblock,
184 struct compunit_symtab *cust)
185 {
186 const struct blockvector *bl;
187 const struct block *b;
188
189 if (cust == NULL)
190 {
191 /* First search all symtabs for one whose file contains our pc */
192 cust = find_pc_sect_compunit_symtab (pc, section);
193 if (cust == NULL)
194 return 0;
195 }
196
197 bl = cust->blockvector ();
198
199 /* Then search that symtab for the smallest block that wins. */
200 b = find_block_in_blockvector (bl, pc);
201 if (b == NULL)
202 return NULL;
203
204 if (pblock)
205 *pblock = b;
206 return bl;
207 }
208
209 /* Return true if the blockvector BV contains PC, false otherwise. */
210
211 int
212 blockvector_contains_pc (const struct blockvector *bv, CORE_ADDR pc)
213 {
214 return find_block_in_blockvector (bv, pc) != NULL;
215 }
216
217 /* Return call_site for specified PC in GDBARCH. PC must match exactly, it
218 must be the next instruction after call (or after tail call jump). Throw
219 NO_ENTRY_VALUE_ERROR otherwise. This function never returns NULL. */
220
221 struct call_site *
222 call_site_for_pc (struct gdbarch *gdbarch, CORE_ADDR pc)
223 {
224 struct compunit_symtab *cust;
225 call_site *cs = nullptr;
226
227 /* -1 as tail call PC can be already after the compilation unit range. */
228 cust = find_pc_compunit_symtab (pc - 1);
229
230 if (cust != nullptr)
231 cs = cust->find_call_site (pc);
232
233 if (cs == nullptr)
234 {
235 struct bound_minimal_symbol msym = lookup_minimal_symbol_by_pc (pc);
236
237 /* DW_TAG_gnu_call_site will be missing just if GCC could not determine
238 the call target. */
239 throw_error (NO_ENTRY_VALUE_ERROR,
240 _("DW_OP_entry_value resolving cannot find "
241 "DW_TAG_call_site %s in %s"),
242 paddress (gdbarch, pc),
243 (msym.minsym == NULL ? "???"
244 : msym.minsym->print_name ()));
245 }
246
247 return cs;
248 }
249
250 /* Return the blockvector immediately containing the innermost lexical block
251 containing the specified pc value, or 0 if there is none.
252 Backward compatibility, no section. */
253
254 const struct blockvector *
255 blockvector_for_pc (CORE_ADDR pc, const struct block **pblock)
256 {
257 return blockvector_for_pc_sect (pc, find_pc_mapped_section (pc),
258 pblock, NULL);
259 }
260
261 /* Return the innermost lexical block containing the specified pc value
262 in the specified section, or 0 if there is none. */
263
264 const struct block *
265 block_for_pc_sect (CORE_ADDR pc, struct obj_section *section)
266 {
267 const struct blockvector *bl;
268 const struct block *b;
269
270 bl = blockvector_for_pc_sect (pc, section, &b, NULL);
271 if (bl)
272 return b;
273 return 0;
274 }
275
276 /* Return the innermost lexical block containing the specified pc value,
277 or 0 if there is none. Backward compatibility, no section. */
278
279 const struct block *
280 block_for_pc (CORE_ADDR pc)
281 {
282 return block_for_pc_sect (pc, find_pc_mapped_section (pc));
283 }
284
285 /* Now come some functions designed to deal with C++ namespace issues.
286 The accessors are safe to use even in the non-C++ case. */
287
288 /* This returns the namespace that BLOCK is enclosed in, or "" if it
289 isn't enclosed in a namespace at all. This travels the chain of
290 superblocks looking for a scope, if necessary. */
291
292 const char *
293 block_scope (const struct block *block)
294 {
295 for (; block != NULL; block = block->superblock ())
296 {
297 if (block->namespace_info () != NULL
298 && block->namespace_info ()->scope != NULL)
299 return block->namespace_info ()->scope;
300 }
301
302 return "";
303 }
304
305 /* If block->namespace_info () is NULL, allocate it via OBSTACK and
306 initialize its members to zero. */
307
308 static void
309 block_initialize_namespace (struct block *block, struct obstack *obstack)
310 {
311 if (block->namespace_info () == NULL)
312 block->set_namespace_info (new (obstack) struct block_namespace_info ());
313 }
314
315 /* Set BLOCK's scope member to SCOPE; if needed, allocate memory via
316 OBSTACK. (It won't make a copy of SCOPE, however, so that already
317 has to be allocated correctly.) */
318
319 void
320 block_set_scope (struct block *block, const char *scope,
321 struct obstack *obstack)
322 {
323 block_initialize_namespace (block, obstack);
324
325 block->namespace_info ()->scope = scope;
326 }
327
328 /* This returns the using directives list associated with BLOCK, if
329 any. */
330
331 struct using_direct *
332 block_using (const struct block *block)
333 {
334 if (block == NULL || block->namespace_info () == NULL)
335 return NULL;
336 else
337 return block->namespace_info ()->using_decl;
338 }
339
340 /* Set BLOCK's using member to USING; if needed, allocate memory via
341 OBSTACK. (It won't make a copy of USING, however, so that already
342 has to be allocated correctly.) */
343
344 void
345 block_set_using (struct block *block,
346 struct using_direct *using_decl,
347 struct obstack *obstack)
348 {
349 block_initialize_namespace (block, obstack);
350
351 block->namespace_info ()->using_decl = using_decl;
352 }
353
354 /* Return the static block associated to BLOCK. Return NULL if block
355 is NULL or if block is a global block. */
356
357 const struct block *
358 block_static_block (const struct block *block)
359 {
360 if (block == NULL || block->superblock () == NULL)
361 return NULL;
362
363 while (block->superblock ()->superblock () != NULL)
364 block = block->superblock ();
365
366 return block;
367 }
368
369 /* Return the static block associated to BLOCK. Return NULL if block
370 is NULL. */
371
372 const struct block *
373 block_global_block (const struct block *block)
374 {
375 if (block == NULL)
376 return NULL;
377
378 while (block->superblock () != NULL)
379 block = block->superblock ();
380
381 return block;
382 }
383
384 /* Allocate a block on OBSTACK, and initialize its elements to
385 zero/NULL. This is useful for creating "dummy" blocks that don't
386 correspond to actual source files.
387
388 Warning: it sets the block's BLOCK_MULTIDICT to NULL, which isn't a
389 valid value. If you really don't want the block to have a
390 dictionary, then you should subsequently set its BLOCK_MULTIDICT to
391 dict_create_linear (obstack, NULL). */
392
393 struct block *
394 allocate_block (struct obstack *obstack)
395 {
396 struct block *bl = OBSTACK_ZALLOC (obstack, struct block);
397
398 return bl;
399 }
400
401 /* Allocate a global block. */
402
403 struct block *
404 allocate_global_block (struct obstack *obstack)
405 {
406 struct global_block *bl = OBSTACK_ZALLOC (obstack, struct global_block);
407
408 return &bl->block;
409 }
410
411 /* Set the compunit of the global block. */
412
413 void
414 set_block_compunit_symtab (struct block *block, struct compunit_symtab *cu)
415 {
416 struct global_block *gb;
417
418 gdb_assert (block->superblock () == NULL);
419 gb = (struct global_block *) block;
420 gdb_assert (gb->compunit_symtab == NULL);
421 gb->compunit_symtab = cu;
422 }
423
424 /* See block.h. */
425
426 struct dynamic_prop *
427 block_static_link (const struct block *block)
428 {
429 struct objfile *objfile = block_objfile (block);
430
431 /* Only objfile-owned blocks that materialize top function scopes can have
432 static links. */
433 if (objfile == NULL || block->function () == NULL)
434 return NULL;
435
436 return (struct dynamic_prop *) objfile_lookup_static_link (objfile, block);
437 }
438
439 /* Return the compunit of the global block. */
440
441 static struct compunit_symtab *
442 get_block_compunit_symtab (const struct block *block)
443 {
444 struct global_block *gb;
445
446 gdb_assert (block->superblock () == NULL);
447 gb = (struct global_block *) block;
448 gdb_assert (gb->compunit_symtab != NULL);
449 return gb->compunit_symtab;
450 }
451
452 \f
453
454 /* Initialize a block iterator, either to iterate over a single block,
455 or, for static and global blocks, all the included symtabs as
456 well. */
457
458 static void
459 initialize_block_iterator (const struct block *block,
460 struct block_iterator *iter)
461 {
462 enum block_enum which;
463 struct compunit_symtab *cu;
464
465 iter->idx = -1;
466
467 if (block->superblock () == NULL)
468 {
469 which = GLOBAL_BLOCK;
470 cu = get_block_compunit_symtab (block);
471 }
472 else if (block->superblock ()->superblock () == NULL)
473 {
474 which = STATIC_BLOCK;
475 cu = get_block_compunit_symtab (block->superblock ());
476 }
477 else
478 {
479 iter->d.block = block;
480 /* A signal value meaning that we're iterating over a single
481 block. */
482 iter->which = FIRST_LOCAL_BLOCK;
483 return;
484 }
485
486 /* If this is an included symtab, find the canonical includer and
487 use it instead. */
488 while (cu->user != NULL)
489 cu = cu->user;
490
491 /* Putting this check here simplifies the logic of the iterator
492 functions. If there are no included symtabs, we only need to
493 search a single block, so we might as well just do that
494 directly. */
495 if (cu->includes == NULL)
496 {
497 iter->d.block = block;
498 /* A signal value meaning that we're iterating over a single
499 block. */
500 iter->which = FIRST_LOCAL_BLOCK;
501 }
502 else
503 {
504 iter->d.compunit_symtab = cu;
505 iter->which = which;
506 }
507 }
508
509 /* A helper function that finds the current compunit over whose static
510 or global block we should iterate. */
511
512 static struct compunit_symtab *
513 find_iterator_compunit_symtab (struct block_iterator *iterator)
514 {
515 if (iterator->idx == -1)
516 return iterator->d.compunit_symtab;
517 return iterator->d.compunit_symtab->includes[iterator->idx];
518 }
519
520 /* Perform a single step for a plain block iterator, iterating across
521 symbol tables as needed. Returns the next symbol, or NULL when
522 iteration is complete. */
523
524 static struct symbol *
525 block_iterator_step (struct block_iterator *iterator, int first)
526 {
527 struct symbol *sym;
528
529 gdb_assert (iterator->which != FIRST_LOCAL_BLOCK);
530
531 while (1)
532 {
533 if (first)
534 {
535 struct compunit_symtab *cust
536 = find_iterator_compunit_symtab (iterator);
537 const struct block *block;
538
539 /* Iteration is complete. */
540 if (cust == NULL)
541 return NULL;
542
543 block = cust->blockvector ()->block (iterator->which);
544 sym = mdict_iterator_first (block->multidict (),
545 &iterator->mdict_iter);
546 }
547 else
548 sym = mdict_iterator_next (&iterator->mdict_iter);
549
550 if (sym != NULL)
551 return sym;
552
553 /* We have finished iterating the appropriate block of one
554 symtab. Now advance to the next symtab and begin iteration
555 there. */
556 ++iterator->idx;
557 first = 1;
558 }
559 }
560
561 /* See block.h. */
562
563 struct symbol *
564 block_iterator_first (const struct block *block,
565 struct block_iterator *iterator)
566 {
567 initialize_block_iterator (block, iterator);
568
569 if (iterator->which == FIRST_LOCAL_BLOCK)
570 return mdict_iterator_first (block->multidict (), &iterator->mdict_iter);
571
572 return block_iterator_step (iterator, 1);
573 }
574
575 /* See block.h. */
576
577 struct symbol *
578 block_iterator_next (struct block_iterator *iterator)
579 {
580 if (iterator->which == FIRST_LOCAL_BLOCK)
581 return mdict_iterator_next (&iterator->mdict_iter);
582
583 return block_iterator_step (iterator, 0);
584 }
585
586 /* Perform a single step for a "match" block iterator, iterating
587 across symbol tables as needed. Returns the next symbol, or NULL
588 when iteration is complete. */
589
590 static struct symbol *
591 block_iter_match_step (struct block_iterator *iterator,
592 const lookup_name_info &name,
593 int first)
594 {
595 struct symbol *sym;
596
597 gdb_assert (iterator->which != FIRST_LOCAL_BLOCK);
598
599 while (1)
600 {
601 if (first)
602 {
603 struct compunit_symtab *cust
604 = find_iterator_compunit_symtab (iterator);
605 const struct block *block;
606
607 /* Iteration is complete. */
608 if (cust == NULL)
609 return NULL;
610
611 block = cust->blockvector ()->block (iterator->which);
612 sym = mdict_iter_match_first (block->multidict (), name,
613 &iterator->mdict_iter);
614 }
615 else
616 sym = mdict_iter_match_next (name, &iterator->mdict_iter);
617
618 if (sym != NULL)
619 return sym;
620
621 /* We have finished iterating the appropriate block of one
622 symtab. Now advance to the next symtab and begin iteration
623 there. */
624 ++iterator->idx;
625 first = 1;
626 }
627 }
628
629 /* See block.h. */
630
631 struct symbol *
632 block_iter_match_first (const struct block *block,
633 const lookup_name_info &name,
634 struct block_iterator *iterator)
635 {
636 initialize_block_iterator (block, iterator);
637
638 if (iterator->which == FIRST_LOCAL_BLOCK)
639 return mdict_iter_match_first (block->multidict (), name,
640 &iterator->mdict_iter);
641
642 return block_iter_match_step (iterator, name, 1);
643 }
644
645 /* See block.h. */
646
647 struct symbol *
648 block_iter_match_next (const lookup_name_info &name,
649 struct block_iterator *iterator)
650 {
651 if (iterator->which == FIRST_LOCAL_BLOCK)
652 return mdict_iter_match_next (name, &iterator->mdict_iter);
653
654 return block_iter_match_step (iterator, name, 0);
655 }
656
657 /* See block.h. */
658
659 bool
660 best_symbol (struct symbol *a, const domain_enum domain)
661 {
662 return (a->domain () == domain
663 && a->aclass () != LOC_UNRESOLVED);
664 }
665
666 /* See block.h. */
667
668 struct symbol *
669 better_symbol (struct symbol *a, struct symbol *b, const domain_enum domain)
670 {
671 if (a == NULL)
672 return b;
673 if (b == NULL)
674 return a;
675
676 if (a->domain () == domain && b->domain () != domain)
677 return a;
678
679 if (b->domain () == domain && a->domain () != domain)
680 return b;
681
682 if (a->aclass () != LOC_UNRESOLVED && b->aclass () == LOC_UNRESOLVED)
683 return a;
684
685 if (b->aclass () != LOC_UNRESOLVED && a->aclass () == LOC_UNRESOLVED)
686 return b;
687
688 return a;
689 }
690
691 /* See block.h.
692
693 Note that if NAME is the demangled form of a C++ symbol, we will fail
694 to find a match during the binary search of the non-encoded names, but
695 for now we don't worry about the slight inefficiency of looking for
696 a match we'll never find, since it will go pretty quick. Once the
697 binary search terminates, we drop through and do a straight linear
698 search on the symbols. Each symbol which is marked as being a ObjC/C++
699 symbol (language_cplus or language_objc set) has both the encoded and
700 non-encoded names tested for a match. */
701
702 struct symbol *
703 block_lookup_symbol (const struct block *block, const char *name,
704 symbol_name_match_type match_type,
705 const domain_enum domain)
706 {
707 struct block_iterator iter;
708 struct symbol *sym;
709
710 lookup_name_info lookup_name (name, match_type);
711
712 if (!block->function ())
713 {
714 struct symbol *other = NULL;
715
716 ALL_BLOCK_SYMBOLS_WITH_NAME (block, lookup_name, iter, sym)
717 {
718 /* See comment related to PR gcc/debug/91507 in
719 block_lookup_symbol_primary. */
720 if (best_symbol (sym, domain))
721 return sym;
722 /* This is a bit of a hack, but symbol_matches_domain might ignore
723 STRUCT vs VAR domain symbols. So if a matching symbol is found,
724 make sure there is no "better" matching symbol, i.e., one with
725 exactly the same domain. PR 16253. */
726 if (symbol_matches_domain (sym->language (),
727 sym->domain (), domain))
728 other = better_symbol (other, sym, domain);
729 }
730 return other;
731 }
732 else
733 {
734 /* Note that parameter symbols do not always show up last in the
735 list; this loop makes sure to take anything else other than
736 parameter symbols first; it only uses parameter symbols as a
737 last resort. Note that this only takes up extra computation
738 time on a match.
739 It's hard to define types in the parameter list (at least in
740 C/C++) so we don't do the same PR 16253 hack here that is done
741 for the !BLOCK_FUNCTION case. */
742
743 struct symbol *sym_found = NULL;
744
745 ALL_BLOCK_SYMBOLS_WITH_NAME (block, lookup_name, iter, sym)
746 {
747 if (symbol_matches_domain (sym->language (),
748 sym->domain (), domain))
749 {
750 sym_found = sym;
751 if (!sym->is_argument ())
752 {
753 break;
754 }
755 }
756 }
757 return (sym_found); /* Will be NULL if not found. */
758 }
759 }
760
761 /* See block.h. */
762
763 struct symbol *
764 block_lookup_symbol_primary (const struct block *block, const char *name,
765 const domain_enum domain)
766 {
767 struct symbol *sym, *other;
768 struct mdict_iterator mdict_iter;
769
770 lookup_name_info lookup_name (name, symbol_name_match_type::FULL);
771
772 /* Verify BLOCK is STATIC_BLOCK or GLOBAL_BLOCK. */
773 gdb_assert (block->superblock () == NULL
774 || block->superblock ()->superblock () == NULL);
775
776 other = NULL;
777 for (sym = mdict_iter_match_first (block->multidict (), lookup_name,
778 &mdict_iter);
779 sym != NULL;
780 sym = mdict_iter_match_next (lookup_name, &mdict_iter))
781 {
782 /* With the fix for PR gcc/debug/91507, we get for:
783 ...
784 extern char *zzz[];
785 char *zzz[ ] = {
786 "abc",
787 "cde"
788 };
789 ...
790 DWARF which will result in two entries in the symbol table, a decl
791 with type char *[] and a def with type char *[2].
792
793 If we return the decl here, we don't get the value of zzz:
794 ...
795 $ gdb a.spec.out -batch -ex "p zzz"
796 $1 = 0x601030 <zzz>
797 ...
798 because we're returning the symbol without location information, and
799 because the fallback that uses the address from the minimal symbols
800 doesn't work either because the type of the decl does not specify a
801 size.
802
803 To fix this, we prefer def over decl in best_symbol and
804 better_symbol.
805
806 In absence of the gcc fix, both def and decl have type char *[], so
807 the only option to make this work is improve the fallback to use the
808 size of the minimal symbol. Filed as PR exp/24989. */
809 if (best_symbol (sym, domain))
810 return sym;
811
812 /* This is a bit of a hack, but symbol_matches_domain might ignore
813 STRUCT vs VAR domain symbols. So if a matching symbol is found,
814 make sure there is no "better" matching symbol, i.e., one with
815 exactly the same domain. PR 16253. */
816 if (symbol_matches_domain (sym->language (), sym->domain (), domain))
817 other = better_symbol (other, sym, domain);
818 }
819
820 return other;
821 }
822
823 /* See block.h. */
824
825 struct symbol *
826 block_find_symbol (const struct block *block, const char *name,
827 const domain_enum domain,
828 block_symbol_matcher_ftype *matcher, void *data)
829 {
830 struct block_iterator iter;
831 struct symbol *sym;
832
833 lookup_name_info lookup_name (name, symbol_name_match_type::FULL);
834
835 /* Verify BLOCK is STATIC_BLOCK or GLOBAL_BLOCK. */
836 gdb_assert (block->superblock () == NULL
837 || block->superblock ()->superblock () == NULL);
838
839 ALL_BLOCK_SYMBOLS_WITH_NAME (block, lookup_name, iter, sym)
840 {
841 /* MATCHER is deliberately called second here so that it never sees
842 a non-domain-matching symbol. */
843 if (symbol_matches_domain (sym->language (), sym->domain (), domain)
844 && matcher (sym, data))
845 return sym;
846 }
847 return NULL;
848 }
849
850 /* See block.h. */
851
852 int
853 block_find_non_opaque_type (struct symbol *sym, void *data)
854 {
855 return !TYPE_IS_OPAQUE (sym->type ());
856 }
857
858 /* See block.h. */
859
860 int
861 block_find_non_opaque_type_preferred (struct symbol *sym, void *data)
862 {
863 struct symbol **best = (struct symbol **) data;
864
865 if (!TYPE_IS_OPAQUE (sym->type ()))
866 return 1;
867 *best = sym;
868 return 0;
869 }
870
871 /* See block.h. */
872
873 struct blockranges *
874 make_blockranges (struct objfile *objfile,
875 const std::vector<blockrange> &rangevec)
876 {
877 struct blockranges *blr;
878 size_t n = rangevec.size();
879
880 blr = (struct blockranges *)
881 obstack_alloc (&objfile->objfile_obstack,
882 sizeof (struct blockranges)
883 + (n - 1) * sizeof (struct blockrange));
884
885 blr->nranges = n;
886 for (int i = 0; i < n; i++)
887 blr->range[i] = rangevec[i];
888 return blr;
889 }
890