Make struct frame_arg self-managing
[external/binutils.git] / gdb / block.c
1 /* Block-related functions for the GNU debugger, GDB.
2
3    Copyright (C) 2003-2019 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 "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 static void block_initialize_namespace (struct block *block,
41                                         struct obstack *obstack);
42
43 /* See block.h.  */
44
45 struct objfile *
46 block_objfile (const struct block *block)
47 {
48   const struct global_block *global_block;
49
50   if (BLOCK_FUNCTION (block) != NULL)
51     return symbol_objfile (BLOCK_FUNCTION (block));
52
53   global_block = (struct global_block *) block_global_block (block);
54   return COMPUNIT_OBJFILE (global_block->compunit_symtab);
55 }
56
57 /* See block.  */
58
59 struct gdbarch *
60 block_gdbarch (const struct block *block)
61 {
62   if (BLOCK_FUNCTION (block) != NULL)
63     return symbol_arch (BLOCK_FUNCTION (block));
64
65   return get_objfile_arch (block_objfile (block));
66 }
67
68 /* Return Nonzero if block a is lexically nested within block b,
69    or if a and b have the same pc range.
70    Return zero otherwise.  */
71
72 int
73 contained_in (const struct block *a, const struct block *b)
74 {
75   if (!a || !b)
76     return 0;
77
78   do
79     {
80       if (a == b)
81         return 1;
82       a = BLOCK_SUPERBLOCK (a);
83     }
84   while (a != NULL);
85
86   return 0;
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 ((BLOCK_FUNCTION (bl) == NULL || block_inlined_p (bl))
99          && BLOCK_SUPERBLOCK (bl) != NULL)
100     bl = BLOCK_SUPERBLOCK (bl);
101
102   return BLOCK_FUNCTION (bl);
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 (BLOCK_FUNCTION (bl) == NULL && BLOCK_SUPERBLOCK (bl) != NULL)
114     bl = BLOCK_SUPERBLOCK (bl);
115
116   return BLOCK_FUNCTION (bl);
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 BLOCK_FUNCTION (bl) != NULL && SYMBOL_INLINED (BLOCK_FUNCTION (bl));
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 (BLOCKVECTOR_MAP (bl))
139     return (const struct block *) addrmap_find (BLOCKVECTOR_MAP (bl), 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 (BLOCKVECTOR_NBLOCKS (bl) >= 2);
148   bot = STATIC_BLOCK;
149   top = BLOCKVECTOR_NBLOCKS (bl);
150
151   while (top - bot > 1)
152     {
153       half = (top - bot + 1) >> 1;
154       b = BLOCKVECTOR_BLOCK (bl, bot + half);
155       if (BLOCK_START (b) <= 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 = BLOCKVECTOR_BLOCK (bl, bot);
166       if (BLOCK_END (b) > pc)
167         return b;
168       bot--;
169     }
170
171   return NULL;
172 }
173
174 /* Return the blockvector immediately containing the innermost lexical
175    block containing the specified pc value and section, or 0 if there
176    is none.  PBLOCK is a pointer to the block.  If PBLOCK is NULL, we
177    don't pass this information back to the caller.  */
178
179 const struct blockvector *
180 blockvector_for_pc_sect (CORE_ADDR pc, struct obj_section *section,
181                          const struct block **pblock,
182                          struct compunit_symtab *cust)
183 {
184   const struct blockvector *bl;
185   const struct block *b;
186
187   if (cust == NULL)
188     {
189       /* First search all symtabs for one whose file contains our pc */
190       cust = find_pc_sect_compunit_symtab (pc, section);
191       if (cust == NULL)
192         return 0;
193     }
194
195   bl = COMPUNIT_BLOCKVECTOR (cust);
196
197   /* Then search that symtab for the smallest block that wins.  */
198   b = find_block_in_blockvector (bl, pc);
199   if (b == NULL)
200     return NULL;
201
202   if (pblock)
203     *pblock = b;
204   return bl;
205 }
206
207 /* Return true if the blockvector BV contains PC, false otherwise.  */
208
209 int
210 blockvector_contains_pc (const struct blockvector *bv, CORE_ADDR pc)
211 {
212   return find_block_in_blockvector (bv, pc) != NULL;
213 }
214
215 /* Return call_site for specified PC in GDBARCH.  PC must match exactly, it
216    must be the next instruction after call (or after tail call jump).  Throw
217    NO_ENTRY_VALUE_ERROR otherwise.  This function never returns NULL.  */
218
219 struct call_site *
220 call_site_for_pc (struct gdbarch *gdbarch, CORE_ADDR pc)
221 {
222   struct compunit_symtab *cust;
223   void **slot = NULL;
224
225   /* -1 as tail call PC can be already after the compilation unit range.  */
226   cust = find_pc_compunit_symtab (pc - 1);
227
228   if (cust != NULL && COMPUNIT_CALL_SITE_HTAB (cust) != NULL)
229     slot = htab_find_slot (COMPUNIT_CALL_SITE_HTAB (cust), &pc, NO_INSERT);
230
231   if (slot == NULL)
232     {
233       struct bound_minimal_symbol msym = lookup_minimal_symbol_by_pc (pc);
234
235       /* DW_TAG_gnu_call_site will be missing just if GCC could not determine
236          the call target.  */
237       throw_error (NO_ENTRY_VALUE_ERROR,
238                    _("DW_OP_entry_value resolving cannot find "
239                      "DW_TAG_call_site %s in %s"),
240                    paddress (gdbarch, pc),
241                    (msym.minsym == NULL ? "???"
242                     : MSYMBOL_PRINT_NAME (msym.minsym)));
243     }
244
245   return (struct call_site *) *slot;
246 }
247
248 /* Return the blockvector immediately containing the innermost lexical block
249    containing the specified pc value, or 0 if there is none.
250    Backward compatibility, no section.  */
251
252 const struct blockvector *
253 blockvector_for_pc (CORE_ADDR pc, const struct block **pblock)
254 {
255   return blockvector_for_pc_sect (pc, find_pc_mapped_section (pc),
256                                   pblock, NULL);
257 }
258
259 /* Return the innermost lexical block containing the specified pc value
260    in the specified section, or 0 if there is none.  */
261
262 const struct block *
263 block_for_pc_sect (CORE_ADDR pc, struct obj_section *section)
264 {
265   const struct blockvector *bl;
266   const struct block *b;
267
268   bl = blockvector_for_pc_sect (pc, section, &b, NULL);
269   if (bl)
270     return b;
271   return 0;
272 }
273
274 /* Return the innermost lexical block containing the specified pc value,
275    or 0 if there is none.  Backward compatibility, no section.  */
276
277 const struct block *
278 block_for_pc (CORE_ADDR pc)
279 {
280   return block_for_pc_sect (pc, find_pc_mapped_section (pc));
281 }
282
283 /* Now come some functions designed to deal with C++ namespace issues.
284    The accessors are safe to use even in the non-C++ case.  */
285
286 /* This returns the namespace that BLOCK is enclosed in, or "" if it
287    isn't enclosed in a namespace at all.  This travels the chain of
288    superblocks looking for a scope, if necessary.  */
289
290 const char *
291 block_scope (const struct block *block)
292 {
293   for (; block != NULL; block = BLOCK_SUPERBLOCK (block))
294     {
295       if (BLOCK_NAMESPACE (block) != NULL
296           && BLOCK_NAMESPACE (block)->scope != NULL)
297         return BLOCK_NAMESPACE (block)->scope;
298     }
299
300   return "";
301 }
302
303 /* Set BLOCK's scope member to SCOPE; if needed, allocate memory via
304    OBSTACK.  (It won't make a copy of SCOPE, however, so that already
305    has to be allocated correctly.)  */
306
307 void
308 block_set_scope (struct block *block, const char *scope,
309                  struct obstack *obstack)
310 {
311   block_initialize_namespace (block, obstack);
312
313   BLOCK_NAMESPACE (block)->scope = scope;
314 }
315
316 /* This returns the using directives list associated with BLOCK, if
317    any.  */
318
319 struct using_direct *
320 block_using (const struct block *block)
321 {
322   if (block == NULL || BLOCK_NAMESPACE (block) == NULL)
323     return NULL;
324   else
325     return BLOCK_NAMESPACE (block)->using_decl;
326 }
327
328 /* Set BLOCK's using member to USING; if needed, allocate memory via
329    OBSTACK.  (It won't make a copy of USING, however, so that already
330    has to be allocated correctly.)  */
331
332 void
333 block_set_using (struct block *block,
334                  struct using_direct *using_decl,
335                  struct obstack *obstack)
336 {
337   block_initialize_namespace (block, obstack);
338
339   BLOCK_NAMESPACE (block)->using_decl = using_decl;
340 }
341
342 /* If BLOCK_NAMESPACE (block) is NULL, allocate it via OBSTACK and
343    ititialize its members to zero.  */
344
345 static void
346 block_initialize_namespace (struct block *block, struct obstack *obstack)
347 {
348   if (BLOCK_NAMESPACE (block) == NULL)
349     BLOCK_NAMESPACE (block) = new (obstack) struct block_namespace_info ();
350 }
351
352 /* Return the static block associated to BLOCK.  Return NULL if block
353    is NULL or if block is a global block.  */
354
355 const struct block *
356 block_static_block (const struct block *block)
357 {
358   if (block == NULL || BLOCK_SUPERBLOCK (block) == NULL)
359     return NULL;
360
361   while (BLOCK_SUPERBLOCK (BLOCK_SUPERBLOCK (block)) != NULL)
362     block = BLOCK_SUPERBLOCK (block);
363
364   return block;
365 }
366
367 /* Return the static block associated to BLOCK.  Return NULL if block
368    is NULL.  */
369
370 const struct block *
371 block_global_block (const struct block *block)
372 {
373   if (block == NULL)
374     return NULL;
375
376   while (BLOCK_SUPERBLOCK (block) != NULL)
377     block = BLOCK_SUPERBLOCK (block);
378
379   return block;
380 }
381
382 /* Allocate a block on OBSTACK, and initialize its elements to
383    zero/NULL.  This is useful for creating "dummy" blocks that don't
384    correspond to actual source files.
385
386    Warning: it sets the block's BLOCK_MULTIDICT to NULL, which isn't a
387    valid value.  If you really don't want the block to have a
388    dictionary, then you should subsequently set its BLOCK_MULTIDICT to
389    dict_create_linear (obstack, NULL).  */
390
391 struct block *
392 allocate_block (struct obstack *obstack)
393 {
394   struct block *bl = OBSTACK_ZALLOC (obstack, struct block);
395
396   return bl;
397 }
398
399 /* Allocate a global block.  */
400
401 struct block *
402 allocate_global_block (struct obstack *obstack)
403 {
404   struct global_block *bl = OBSTACK_ZALLOC (obstack, struct global_block);
405
406   return &bl->block;
407 }
408
409 /* Set the compunit of the global block.  */
410
411 void
412 set_block_compunit_symtab (struct block *block, struct compunit_symtab *cu)
413 {
414   struct global_block *gb;
415
416   gdb_assert (BLOCK_SUPERBLOCK (block) == NULL);
417   gb = (struct global_block *) block;
418   gdb_assert (gb->compunit_symtab == NULL);
419   gb->compunit_symtab = cu;
420 }
421
422 /* See block.h.  */
423
424 struct dynamic_prop *
425 block_static_link (const struct block *block)
426 {
427   struct objfile *objfile = block_objfile (block);
428
429   /* Only objfile-owned blocks that materialize top function scopes can have
430      static links.  */
431   if (objfile == NULL || BLOCK_FUNCTION (block) == NULL)
432     return NULL;
433
434   return (struct dynamic_prop *) objfile_lookup_static_link (objfile, block);
435 }
436
437 /* Return the compunit of the global block.  */
438
439 static struct compunit_symtab *
440 get_block_compunit_symtab (const struct block *block)
441 {
442   struct global_block *gb;
443
444   gdb_assert (BLOCK_SUPERBLOCK (block) == NULL);
445   gb = (struct global_block *) block;
446   gdb_assert (gb->compunit_symtab != NULL);
447   return gb->compunit_symtab;
448 }
449
450 \f
451
452 /* Initialize a block iterator, either to iterate over a single block,
453    or, for static and global blocks, all the included symtabs as
454    well.  */
455
456 static void
457 initialize_block_iterator (const struct block *block,
458                            struct block_iterator *iter)
459 {
460   enum block_enum which;
461   struct compunit_symtab *cu;
462
463   iter->idx = -1;
464
465   if (BLOCK_SUPERBLOCK (block) == NULL)
466     {
467       which = GLOBAL_BLOCK;
468       cu = get_block_compunit_symtab (block);
469     }
470   else if (BLOCK_SUPERBLOCK (BLOCK_SUPERBLOCK (block)) == NULL)
471     {
472       which = STATIC_BLOCK;
473       cu = get_block_compunit_symtab (BLOCK_SUPERBLOCK (block));
474     }
475   else
476     {
477       iter->d.block = block;
478       /* A signal value meaning that we're iterating over a single
479          block.  */
480       iter->which = FIRST_LOCAL_BLOCK;
481       return;
482     }
483
484   /* If this is an included symtab, find the canonical includer and
485      use it instead.  */
486   while (cu->user != NULL)
487     cu = cu->user;
488
489   /* Putting this check here simplifies the logic of the iterator
490      functions.  If there are no included symtabs, we only need to
491      search a single block, so we might as well just do that
492      directly.  */
493   if (cu->includes == NULL)
494     {
495       iter->d.block = block;
496       /* A signal value meaning that we're iterating over a single
497          block.  */
498       iter->which = FIRST_LOCAL_BLOCK;
499     }
500   else
501     {
502       iter->d.compunit_symtab = cu;
503       iter->which = which;
504     }
505 }
506
507 /* A helper function that finds the current compunit over whose static
508    or global block we should iterate.  */
509
510 static struct compunit_symtab *
511 find_iterator_compunit_symtab (struct block_iterator *iterator)
512 {
513   if (iterator->idx == -1)
514     return iterator->d.compunit_symtab;
515   return iterator->d.compunit_symtab->includes[iterator->idx];
516 }
517
518 /* Perform a single step for a plain block iterator, iterating across
519    symbol tables as needed.  Returns the next symbol, or NULL when
520    iteration is complete.  */
521
522 static struct symbol *
523 block_iterator_step (struct block_iterator *iterator, int first)
524 {
525   struct symbol *sym;
526
527   gdb_assert (iterator->which != FIRST_LOCAL_BLOCK);
528
529   while (1)
530     {
531       if (first)
532         {
533           struct compunit_symtab *cust
534             = find_iterator_compunit_symtab (iterator);
535           const struct block *block;
536
537           /* Iteration is complete.  */
538           if (cust == NULL)
539             return  NULL;
540
541           block = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust),
542                                      iterator->which);
543           sym = mdict_iterator_first (BLOCK_MULTIDICT (block),
544                                       &iterator->mdict_iter);
545         }
546       else
547         sym = mdict_iterator_next (&iterator->mdict_iter);
548
549       if (sym != NULL)
550         return sym;
551
552       /* We have finished iterating the appropriate block of one
553          symtab.  Now advance to the next symtab and begin iteration
554          there.  */
555       ++iterator->idx;
556       first = 1;
557     }
558 }
559
560 /* See block.h.  */
561
562 struct symbol *
563 block_iterator_first (const struct block *block,
564                       struct block_iterator *iterator)
565 {
566   initialize_block_iterator (block, iterator);
567
568   if (iterator->which == FIRST_LOCAL_BLOCK)
569     return mdict_iterator_first (block->multidict, &iterator->mdict_iter);
570
571   return block_iterator_step (iterator, 1);
572 }
573
574 /* See block.h.  */
575
576 struct symbol *
577 block_iterator_next (struct block_iterator *iterator)
578 {
579   if (iterator->which == FIRST_LOCAL_BLOCK)
580     return mdict_iterator_next (&iterator->mdict_iter);
581
582   return block_iterator_step (iterator, 0);
583 }
584
585 /* Perform a single step for a "match" block iterator, iterating
586    across symbol tables as needed.  Returns the next symbol, or NULL
587    when iteration is complete.  */
588
589 static struct symbol *
590 block_iter_match_step (struct block_iterator *iterator,
591                        const lookup_name_info &name,
592                        int first)
593 {
594   struct symbol *sym;
595
596   gdb_assert (iterator->which != FIRST_LOCAL_BLOCK);
597
598   while (1)
599     {
600       if (first)
601         {
602           struct compunit_symtab *cust
603             = find_iterator_compunit_symtab (iterator);
604           const struct block *block;
605
606           /* Iteration is complete.  */
607           if (cust == NULL)
608             return  NULL;
609
610           block = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust),
611                                      iterator->which);
612           sym = mdict_iter_match_first (BLOCK_MULTIDICT (block), 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    Note that if NAME is the demangled form of a C++ symbol, we will fail
660    to find a match during the binary search of the non-encoded names, but
661    for now we don't worry about the slight inefficiency of looking for
662    a match we'll never find, since it will go pretty quick.  Once the
663    binary search terminates, we drop through and do a straight linear
664    search on the symbols.  Each symbol which is marked as being a ObjC/C++
665    symbol (language_cplus or language_objc set) has both the encoded and
666    non-encoded names tested for a match.  */
667
668 struct symbol *
669 block_lookup_symbol (const struct block *block, const char *name,
670                      symbol_name_match_type match_type,
671                      const domain_enum domain)
672 {
673   struct block_iterator iter;
674   struct symbol *sym;
675
676   lookup_name_info lookup_name (name, match_type);
677
678   if (!BLOCK_FUNCTION (block))
679     {
680       struct symbol *other = NULL;
681
682       ALL_BLOCK_SYMBOLS_WITH_NAME (block, lookup_name, iter, sym)
683         {
684           if (SYMBOL_DOMAIN (sym) == domain)
685             return sym;
686           /* This is a bit of a hack, but symbol_matches_domain might ignore
687              STRUCT vs VAR domain symbols.  So if a matching symbol is found,
688              make sure there is no "better" matching symbol, i.e., one with
689              exactly the same domain.  PR 16253.  */
690           if (symbol_matches_domain (SYMBOL_LANGUAGE (sym),
691                                      SYMBOL_DOMAIN (sym), domain))
692             other = sym;
693         }
694       return other;
695     }
696   else
697     {
698       /* Note that parameter symbols do not always show up last in the
699          list; this loop makes sure to take anything else other than
700          parameter symbols first; it only uses parameter symbols as a
701          last resort.  Note that this only takes up extra computation
702          time on a match.
703          It's hard to define types in the parameter list (at least in
704          C/C++) so we don't do the same PR 16253 hack here that is done
705          for the !BLOCK_FUNCTION case.  */
706
707       struct symbol *sym_found = NULL;
708
709       ALL_BLOCK_SYMBOLS_WITH_NAME (block, lookup_name, iter, sym)
710         {
711           if (symbol_matches_domain (SYMBOL_LANGUAGE (sym),
712                                      SYMBOL_DOMAIN (sym), domain))
713             {
714               sym_found = sym;
715               if (!SYMBOL_IS_ARGUMENT (sym))
716                 {
717                   break;
718                 }
719             }
720         }
721       return (sym_found);       /* Will be NULL if not found.  */
722     }
723 }
724
725 /* See block.h.  */
726
727 struct symbol *
728 block_lookup_symbol_primary (const struct block *block, const char *name,
729                              const domain_enum domain)
730 {
731   struct symbol *sym, *other;
732   struct mdict_iterator mdict_iter;
733
734   lookup_name_info lookup_name (name, symbol_name_match_type::FULL);
735
736   /* Verify BLOCK is STATIC_BLOCK or GLOBAL_BLOCK.  */
737   gdb_assert (BLOCK_SUPERBLOCK (block) == NULL
738               || BLOCK_SUPERBLOCK (BLOCK_SUPERBLOCK (block)) == NULL);
739
740   other = NULL;
741   for (sym
742          = mdict_iter_match_first (block->multidict, lookup_name, &mdict_iter);
743        sym != NULL;
744        sym = mdict_iter_match_next (lookup_name, &mdict_iter))
745     {
746       if (SYMBOL_DOMAIN (sym) == domain)
747         return sym;
748
749       /* This is a bit of a hack, but symbol_matches_domain might ignore
750          STRUCT vs VAR domain symbols.  So if a matching symbol is found,
751          make sure there is no "better" matching symbol, i.e., one with
752          exactly the same domain.  PR 16253.  */
753       if (symbol_matches_domain (SYMBOL_LANGUAGE (sym),
754                                  SYMBOL_DOMAIN (sym), domain))
755         other = sym;
756     }
757
758   return other;
759 }
760
761 /* See block.h.  */
762
763 struct symbol *
764 block_find_symbol (const struct block *block, const char *name,
765                    const domain_enum domain,
766                    block_symbol_matcher_ftype *matcher, void *data)
767 {
768   struct block_iterator iter;
769   struct symbol *sym;
770
771   lookup_name_info lookup_name (name, symbol_name_match_type::FULL);
772
773   /* Verify BLOCK is STATIC_BLOCK or GLOBAL_BLOCK.  */
774   gdb_assert (BLOCK_SUPERBLOCK (block) == NULL
775               || BLOCK_SUPERBLOCK (BLOCK_SUPERBLOCK (block)) == NULL);
776
777   ALL_BLOCK_SYMBOLS_WITH_NAME (block, lookup_name, iter, sym)
778     {
779       /* MATCHER is deliberately called second here so that it never sees
780          a non-domain-matching symbol.  */
781       if (symbol_matches_domain (SYMBOL_LANGUAGE (sym),
782                                  SYMBOL_DOMAIN (sym), domain)
783           && matcher (sym, data))
784         return sym;
785     }
786   return NULL;
787 }
788
789 /* See block.h.  */
790
791 int
792 block_find_non_opaque_type (struct symbol *sym, void *data)
793 {
794   return !TYPE_IS_OPAQUE (SYMBOL_TYPE (sym));
795 }
796
797 /* See block.h.  */
798
799 int
800 block_find_non_opaque_type_preferred (struct symbol *sym, void *data)
801 {
802   struct symbol **best = (struct symbol **) data;
803
804   if (!TYPE_IS_OPAQUE (SYMBOL_TYPE (sym)))
805     return 1;
806   *best = sym;
807   return 0;
808 }
809
810 /* See block.h.  */
811
812 struct blockranges *
813 make_blockranges (struct objfile *objfile,
814                   const std::vector<blockrange> &rangevec)
815 {
816   struct blockranges *blr;
817   size_t n = rangevec.size();
818
819   blr = (struct blockranges *)
820     obstack_alloc (&objfile->objfile_obstack,
821                    sizeof (struct blockranges)
822                    + (n - 1) * sizeof (struct blockrange));
823
824   blr->nranges = n;
825   for (int i = 0; i < n; i++)
826     blr->range[i] = rangevec[i];
827   return blr;
828 }
829