x86: Move x86-specific linker options to elf_linker_x86_params
[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"
d55e5aa6
TT
21
22/* Local non-gdb includes. */
23#include "addrmap.h"
fe898f56 24#include "block.h"
9219021c 25#include "cp-support.h"
d55e5aa6 26#include "gdb_obstack.h"
8e3b41a9 27#include "gdbtypes.h"
1994afbf 28#include "objfiles.h"
d55e5aa6
TT
29#include "symfile.h"
30#include "symtab.h"
9219021c
DC
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
fd90ace4 36struct block_namespace_info : public allocate_on_obstack
9219021c 37{
fd90ace4
YQ
38 const char *scope = nullptr;
39 struct using_direct *using_decl = nullptr;
9219021c
DC
40};
41
42static void block_initialize_namespace (struct block *block,
43 struct obstack *obstack);
fe898f56 44
1994afbf
DE
45/* See block.h. */
46
47struct objfile *
48block_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
61struct gdbarch *
62block_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
fe898f56
DC
70/* Return Nonzero if block a is lexically nested within block b,
71 or if a and b have the same pc range.
4a64f543 72 Return zero otherwise. */
fe898f56
DC
73
74int
0cf566ec 75contained_in (const struct block *a, const struct block *b)
fe898f56
DC
76{
77 if (!a || !b)
78 return 0;
edb3359d
DJ
79
80 do
81 {
82 if (a == b)
83 return 1;
49e794ac
JB
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;
edb3359d
DJ
88 a = BLOCK_SUPERBLOCK (a);
89 }
90 while (a != NULL);
91
92 return 0;
fe898f56
DC
93}
94
95
96/* Return the symbol for the function which contains a specified
7f0df278
DJ
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. */
fe898f56
DC
100
101struct symbol *
7f0df278 102block_linkage_function (const struct block *bl)
fe898f56 103{
edb3359d
DJ
104 while ((BLOCK_FUNCTION (bl) == NULL || block_inlined_p (bl))
105 && BLOCK_SUPERBLOCK (bl) != NULL)
fe898f56
DC
106 bl = BLOCK_SUPERBLOCK (bl);
107
108 return BLOCK_FUNCTION (bl);
109}
110
f8eba3c6
TT
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
116struct symbol *
117block_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
edb3359d
DJ
125/* Return one if BL represents an inlined function. */
126
127int
128block_inlined_p (const struct block *bl)
129{
130 return BLOCK_FUNCTION (bl) != NULL && SYMBOL_INLINED (BLOCK_FUNCTION (bl));
131}
132
9703b513
TT
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. */
fe898f56 135
582942f4 136static const struct block *
346d1dfe 137find_block_in_blockvector (const struct blockvector *bl, CORE_ADDR pc)
fe898f56 138{
582942f4 139 const struct block *b;
b59661bd 140 int bot, top, half;
fe898f56 141
801e3a5b
JB
142 /* If we have an addrmap mapping code addresses to blocks, then use
143 that. */
144 if (BLOCKVECTOR_MAP (bl))
582942f4 145 return (const struct block *) addrmap_find (BLOCKVECTOR_MAP (bl), pc);
801e3a5b
JB
146
147 /* Otherwise, use binary search to find the last block that starts
6ac9ef80
DE
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;
fe898f56
DC
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
6ac9ef80 169 while (bot >= STATIC_BLOCK)
fe898f56
DC
170 {
171 b = BLOCKVECTOR_BLOCK (bl, bot);
172 if (BLOCK_END (b) > pc)
9703b513 173 return b;
fe898f56
DC
174 bot--;
175 }
9703b513
TT
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
346d1dfe 185const struct blockvector *
9703b513 186blockvector_for_pc_sect (CORE_ADDR pc, struct obj_section *section,
43f3e411
DE
187 const struct block **pblock,
188 struct compunit_symtab *cust)
9703b513 189{
346d1dfe 190 const struct blockvector *bl;
582942f4 191 const struct block *b;
9703b513 192
43f3e411 193 if (cust == NULL)
9703b513
TT
194 {
195 /* First search all symtabs for one whose file contains our pc */
43f3e411
DE
196 cust = find_pc_sect_compunit_symtab (pc, section);
197 if (cust == NULL)
9703b513
TT
198 return 0;
199 }
200
43f3e411 201 bl = COMPUNIT_BLOCKVECTOR (cust);
9703b513
TT
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
215int
346d1dfe 216blockvector_contains_pc (const struct blockvector *bv, CORE_ADDR pc)
9703b513
TT
217{
218 return find_block_in_blockvector (bv, pc) != NULL;
fe898f56
DC
219}
220
8e3b41a9
JK
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
225struct call_site *
226call_site_for_pc (struct gdbarch *gdbarch, CORE_ADDR pc)
227{
43f3e411 228 struct compunit_symtab *cust;
8e3b41a9
JK
229 void **slot = NULL;
230
231 /* -1 as tail call PC can be already after the compilation unit range. */
43f3e411 232 cust = find_pc_compunit_symtab (pc - 1);
8e3b41a9 233
43f3e411
DE
234 if (cust != NULL && COMPUNIT_CALL_SITE_HTAB (cust) != NULL)
235 slot = htab_find_slot (COMPUNIT_CALL_SITE_HTAB (cust), &pc, NO_INSERT);
8e3b41a9
JK
236
237 if (slot == NULL)
238 {
7cbd4a93 239 struct bound_minimal_symbol msym = lookup_minimal_symbol_by_pc (pc);
8e3b41a9
JK
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,
216f72a1
JK
244 _("DW_OP_entry_value resolving cannot find "
245 "DW_TAG_call_site %s in %s"),
8e3b41a9 246 paddress (gdbarch, pc),
7cbd4a93 247 (msym.minsym == NULL ? "???"
efd66ac6 248 : MSYMBOL_PRINT_NAME (msym.minsym)));
8e3b41a9
JK
249 }
250
9a3c8263 251 return (struct call_site *) *slot;
8e3b41a9
JK
252}
253
fe898f56
DC
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
346d1dfe 258const struct blockvector *
3977b71f 259blockvector_for_pc (CORE_ADDR pc, const struct block **pblock)
fe898f56
DC
260{
261 return blockvector_for_pc_sect (pc, find_pc_mapped_section (pc),
801e3a5b 262 pblock, NULL);
fe898f56
DC
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
3977b71f 268const struct block *
714835d5 269block_for_pc_sect (CORE_ADDR pc, struct obj_section *section)
fe898f56 270{
346d1dfe 271 const struct blockvector *bl;
3977b71f 272 const struct block *b;
fe898f56 273
801e3a5b 274 bl = blockvector_for_pc_sect (pc, section, &b, NULL);
fe898f56 275 if (bl)
801e3a5b 276 return b;
fe898f56
DC
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
3977b71f 283const struct block *
b59661bd 284block_for_pc (CORE_ADDR pc)
fe898f56
DC
285{
286 return block_for_pc_sect (pc, find_pc_mapped_section (pc));
287}
9219021c 288
1fcb5155
DC
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
296const char *
297block_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}
9219021c
DC
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
313void
314block_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
27aa8d6a 322/* This returns the using directives list associated with BLOCK, if
1fcb5155
DC
323 any. */
324
1fcb5155
DC
325struct using_direct *
326block_using (const struct block *block)
327{
27aa8d6a 328 if (block == NULL || BLOCK_NAMESPACE (block) == NULL)
1fcb5155
DC
329 return NULL;
330 else
fe978cb0 331 return BLOCK_NAMESPACE (block)->using_decl;
1fcb5155
DC
332}
333
9219021c
DC
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
338void
339block_set_using (struct block *block,
fe978cb0 340 struct using_direct *using_decl,
9219021c
DC
341 struct obstack *obstack)
342{
343 block_initialize_namespace (block, obstack);
344
fe978cb0 345 BLOCK_NAMESPACE (block)->using_decl = using_decl;
9219021c
DC
346}
347
348/* If BLOCK_NAMESPACE (block) is NULL, allocate it via OBSTACK and
349 ititialize its members to zero. */
350
351static void
352block_initialize_namespace (struct block *block, struct obstack *obstack)
353{
354 if (BLOCK_NAMESPACE (block) == NULL)
fd90ace4 355 BLOCK_NAMESPACE (block) = new (obstack) struct block_namespace_info ();
9219021c 356}
89a9d1b1
DC
357
358/* Return the static block associated to BLOCK. Return NULL if block
359 is NULL or if block is a global block. */
360
361const struct block *
362block_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}
1fcb5155
DC
372
373/* Return the static block associated to BLOCK. Return NULL if block
374 is NULL. */
375
376const struct block *
377block_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}
5c4e30ca
DC
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
b026f593 392 Warning: it sets the block's BLOCK_MULTIDICT to NULL, which isn't a
5c4e30ca 393 valid value. If you really don't want the block to have a
b026f593 394 dictionary, then you should subsequently set its BLOCK_MULTIDICT to
5c4e30ca
DC
395 dict_create_linear (obstack, NULL). */
396
397struct block *
398allocate_block (struct obstack *obstack)
399{
4c35218e 400 struct block *bl = OBSTACK_ZALLOC (obstack, struct block);
5c4e30ca
DC
401
402 return bl;
403}
8157b174 404
84a146c9
TT
405/* Allocate a global block. */
406
407struct block *
408allocate_global_block (struct obstack *obstack)
409{
410 struct global_block *bl = OBSTACK_ZALLOC (obstack, struct global_block);
411
412 return &bl->block;
413}
414
43f3e411 415/* Set the compunit of the global block. */
84a146c9
TT
416
417void
43f3e411 418set_block_compunit_symtab (struct block *block, struct compunit_symtab *cu)
84a146c9
TT
419{
420 struct global_block *gb;
421
422 gdb_assert (BLOCK_SUPERBLOCK (block) == NULL);
423 gb = (struct global_block *) block;
43f3e411
DE
424 gdb_assert (gb->compunit_symtab == NULL);
425 gb->compunit_symtab = cu;
84a146c9
TT
426}
427
63e43d3a
PMR
428/* See block.h. */
429
430struct dynamic_prop *
431block_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
43f3e411 443/* Return the compunit of the global block. */
b5b04b5b 444
43f3e411
DE
445static struct compunit_symtab *
446get_block_compunit_symtab (const struct block *block)
b5b04b5b
TT
447{
448 struct global_block *gb;
449
450 gdb_assert (BLOCK_SUPERBLOCK (block) == NULL);
451 gb = (struct global_block *) block;
43f3e411
DE
452 gdb_assert (gb->compunit_symtab != NULL);
453 return gb->compunit_symtab;
b5b04b5b
TT
454}
455
8157b174
TT
456\f
457
b5b04b5b
TT
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
462static void
463initialize_block_iterator (const struct block *block,
464 struct block_iterator *iter)
465{
466 enum block_enum which;
43f3e411 467 struct compunit_symtab *cu;
b5b04b5b
TT
468
469 iter->idx = -1;
470
471 if (BLOCK_SUPERBLOCK (block) == NULL)
472 {
473 which = GLOBAL_BLOCK;
43f3e411 474 cu = get_block_compunit_symtab (block);
b5b04b5b
TT
475 }
476 else if (BLOCK_SUPERBLOCK (BLOCK_SUPERBLOCK (block)) == NULL)
477 {
478 which = STATIC_BLOCK;
43f3e411 479 cu = get_block_compunit_symtab (BLOCK_SUPERBLOCK (block));
b5b04b5b
TT
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. */
43f3e411
DE
492 while (cu->user != NULL)
493 cu = cu->user;
b5b04b5b
TT
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. */
43f3e411 499 if (cu->includes == NULL)
b5b04b5b
TT
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 {
43f3e411 508 iter->d.compunit_symtab = cu;
b5b04b5b
TT
509 iter->which = which;
510 }
511}
512
43f3e411 513/* A helper function that finds the current compunit over whose static
b5b04b5b
TT
514 or global block we should iterate. */
515
43f3e411
DE
516static struct compunit_symtab *
517find_iterator_compunit_symtab (struct block_iterator *iterator)
b5b04b5b
TT
518{
519 if (iterator->idx == -1)
43f3e411
DE
520 return iterator->d.compunit_symtab;
521 return iterator->d.compunit_symtab->includes[iterator->idx];
b5b04b5b
TT
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
528static struct symbol *
529block_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 {
43f3e411
DE
539 struct compunit_symtab *cust
540 = find_iterator_compunit_symtab (iterator);
b5b04b5b
TT
541 const struct block *block;
542
543 /* Iteration is complete. */
43f3e411 544 if (cust == NULL)
b5b04b5b
TT
545 return NULL;
546
43f3e411 547 block = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust),
439247b6 548 iterator->which);
b026f593
KS
549 sym = mdict_iterator_first (BLOCK_MULTIDICT (block),
550 &iterator->mdict_iter);
b5b04b5b
TT
551 }
552 else
b026f593 553 sym = mdict_iterator_next (&iterator->mdict_iter);
b5b04b5b
TT
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
8157b174
TT
566/* See block.h. */
567
568struct symbol *
569block_iterator_first (const struct block *block,
570 struct block_iterator *iterator)
571{
b5b04b5b
TT
572 initialize_block_iterator (block, iterator);
573
574 if (iterator->which == FIRST_LOCAL_BLOCK)
b026f593 575 return mdict_iterator_first (block->multidict, &iterator->mdict_iter);
b5b04b5b
TT
576
577 return block_iterator_step (iterator, 1);
8157b174
TT
578}
579
580/* See block.h. */
581
582struct symbol *
583block_iterator_next (struct block_iterator *iterator)
584{
b5b04b5b 585 if (iterator->which == FIRST_LOCAL_BLOCK)
b026f593 586 return mdict_iterator_next (&iterator->mdict_iter);
b5b04b5b
TT
587
588 return block_iterator_step (iterator, 0);
589}
590
b5b04b5b
TT
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
595static struct symbol *
596block_iter_match_step (struct block_iterator *iterator,
b5ec771e 597 const lookup_name_info &name,
b5b04b5b
TT
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 {
43f3e411
DE
608 struct compunit_symtab *cust
609 = find_iterator_compunit_symtab (iterator);
b5b04b5b
TT
610 const struct block *block;
611
612 /* Iteration is complete. */
43f3e411 613 if (cust == NULL)
b5b04b5b
TT
614 return NULL;
615
43f3e411 616 block = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust),
439247b6 617 iterator->which);
b026f593
KS
618 sym = mdict_iter_match_first (BLOCK_MULTIDICT (block), name,
619 &iterator->mdict_iter);
b5b04b5b
TT
620 }
621 else
b026f593 622 sym = mdict_iter_match_next (name, &iterator->mdict_iter);
b5b04b5b
TT
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 }
8157b174
TT
633}
634
635/* See block.h. */
636
637struct symbol *
638block_iter_match_first (const struct block *block,
b5ec771e 639 const lookup_name_info &name,
8157b174
TT
640 struct block_iterator *iterator)
641{
b5b04b5b
TT
642 initialize_block_iterator (block, iterator);
643
644 if (iterator->which == FIRST_LOCAL_BLOCK)
b026f593
KS
645 return mdict_iter_match_first (block->multidict, name,
646 &iterator->mdict_iter);
b5b04b5b 647
b5ec771e 648 return block_iter_match_step (iterator, name, 1);
8157b174
TT
649}
650
651/* See block.h. */
652
653struct symbol *
b5ec771e 654block_iter_match_next (const lookup_name_info &name,
8157b174
TT
655 struct block_iterator *iterator)
656{
b5b04b5b 657 if (iterator->which == FIRST_LOCAL_BLOCK)
b026f593 658 return mdict_iter_match_next (name, &iterator->mdict_iter);
b5b04b5b 659
b5ec771e 660 return block_iter_match_step (iterator, name, 0);
8157b174 661}
16b2eaa1
DE
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
674struct symbol *
675block_lookup_symbol (const struct block *block, const char *name,
de63c46b 676 symbol_name_match_type match_type,
16b2eaa1
DE
677 const domain_enum domain)
678{
679 struct block_iterator iter;
680 struct symbol *sym;
681
de63c46b 682 lookup_name_info lookup_name (name, match_type);
b5ec771e 683
16b2eaa1
DE
684 if (!BLOCK_FUNCTION (block))
685 {
ee93cd5e
KS
686 struct symbol *other = NULL;
687
b5ec771e 688 ALL_BLOCK_SYMBOLS_WITH_NAME (block, lookup_name, iter, sym)
16b2eaa1 689 {
ee93cd5e
KS
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. */
16b2eaa1
DE
696 if (symbol_matches_domain (SYMBOL_LANGUAGE (sym),
697 SYMBOL_DOMAIN (sym), domain))
ee93cd5e 698 other = sym;
16b2eaa1 699 }
ee93cd5e 700 return other;
16b2eaa1
DE
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
ee93cd5e
KS
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. */
16b2eaa1
DE
712
713 struct symbol *sym_found = NULL;
714
b5ec771e 715 ALL_BLOCK_SYMBOLS_WITH_NAME (block, lookup_name, iter, sym)
16b2eaa1
DE
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}
ba715d7f
JK
730
731/* See block.h. */
732
733struct symbol *
734block_lookup_symbol_primary (const struct block *block, const char *name,
735 const domain_enum domain)
736{
ee93cd5e 737 struct symbol *sym, *other;
b026f593 738 struct mdict_iterator mdict_iter;
ba715d7f 739
b5ec771e
PA
740 lookup_name_info lookup_name (name, symbol_name_match_type::FULL);
741
ba715d7f
JK
742 /* Verify BLOCK is STATIC_BLOCK or GLOBAL_BLOCK. */
743 gdb_assert (BLOCK_SUPERBLOCK (block) == NULL
744 || BLOCK_SUPERBLOCK (BLOCK_SUPERBLOCK (block)) == NULL);
745
ee93cd5e 746 other = NULL;
b026f593
KS
747 for (sym
748 = mdict_iter_match_first (block->multidict, lookup_name, &mdict_iter);
ba715d7f 749 sym != NULL;
b026f593 750 sym = mdict_iter_match_next (lookup_name, &mdict_iter))
ba715d7f 751 {
ee93cd5e
KS
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. */
ba715d7f
JK
759 if (symbol_matches_domain (SYMBOL_LANGUAGE (sym),
760 SYMBOL_DOMAIN (sym), domain))
ee93cd5e 761 other = sym;
ba715d7f
JK
762 }
763
ee93cd5e 764 return other;
ba715d7f 765}
b2e2f908
DE
766
767/* See block.h. */
768
769struct symbol *
770block_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
b5ec771e
PA
777 lookup_name_info lookup_name (name, symbol_name_match_type::FULL);
778
b2e2f908
DE
779 /* Verify BLOCK is STATIC_BLOCK or GLOBAL_BLOCK. */
780 gdb_assert (BLOCK_SUPERBLOCK (block) == NULL
781 || BLOCK_SUPERBLOCK (BLOCK_SUPERBLOCK (block)) == NULL);
782
b5ec771e 783 ALL_BLOCK_SYMBOLS_WITH_NAME (block, lookup_name, iter, sym)
b2e2f908
DE
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
797int
798block_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
805int
806block_find_non_opaque_type_preferred (struct symbol *sym, void *data)
807{
9a3c8263 808 struct symbol **best = (struct symbol **) data;
b2e2f908
DE
809
810 if (!TYPE_IS_OPAQUE (SYMBOL_TYPE (sym)))
811 return 1;
812 *best = sym;
813 return 0;
814}
26457a9c
KB
815
816/* See block.h. */
817
818struct blockranges *
819make_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 1.355456 seconds and 4 git commands to generate.