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