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