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