gdb/block.c - gdb

Data types defined

Functions defined

Source code

  1. /* Block-related functions for the GNU debugger, GDB.

  2.    Copyright (C) 2003-2015 Free Software Foundation, Inc.

  3.    This file is part of GDB.

  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 3 of the License, or
  7.    (at your option) any later version.

  8.    This program is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.    GNU General Public License for more details.

  12.    You should have received a copy of the GNU General Public License
  13.    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

  14. #include "defs.h"
  15. #include "block.h"
  16. #include "symtab.h"
  17. #include "symfile.h"
  18. #include "gdb_obstack.h"
  19. #include "cp-support.h"
  20. #include "addrmap.h"
  21. #include "gdbtypes.h"
  22. #include "objfiles.h"

  23. /* This is used by struct block to store namespace-related info for
  24.    C++ files, namely using declarations and the current namespace in
  25.    scope.  */

  26. struct block_namespace_info
  27. {
  28.   const char *scope;
  29.   struct using_direct *using;
  30. };

  31. static void block_initialize_namespace (struct block *block,
  32.                                         struct obstack *obstack);

  33. /* See block.h.  */

  34. struct objfile *
  35. block_objfile (const struct block *block)
  36. {
  37.   const struct global_block *global_block;

  38.   if (BLOCK_FUNCTION (block) != NULL)
  39.     return symbol_objfile (BLOCK_FUNCTION (block));

  40.   global_block = (struct global_block *) block_global_block (block);
  41.   return COMPUNIT_OBJFILE (global_block->compunit_symtab);
  42. }

  43. /* See block.  */

  44. struct gdbarch *
  45. block_gdbarch (const struct block *block)
  46. {
  47.   if (BLOCK_FUNCTION (block) != NULL)
  48.     return symbol_arch (BLOCK_FUNCTION (block));

  49.   return get_objfile_arch (block_objfile (block));
  50. }

  51. /* Return Nonzero if block a is lexically nested within block b,
  52.    or if a and b have the same pc range.
  53.    Return zero otherwise.  */

  54. int
  55. contained_in (const struct block *a, const struct block *b)
  56. {
  57.   if (!a || !b)
  58.     return 0;

  59.   do
  60.     {
  61.       if (a == b)
  62.         return 1;
  63.       /* If A is a function block, then A cannot be contained in B,
  64.          except if A was inlined.  */
  65.       if (BLOCK_FUNCTION (a) != NULL && !block_inlined_p (a))
  66.         return 0;
  67.       a = BLOCK_SUPERBLOCK (a);
  68.     }
  69.   while (a != NULL);

  70.   return 0;
  71. }


  72. /* Return the symbol for the function which contains a specified
  73.    lexical block, described by a struct block BL.  The return value
  74.    will not be an inlined function; the containing function will be
  75.    returned instead.  */

  76. struct symbol *
  77. block_linkage_function (const struct block *bl)
  78. {
  79.   while ((BLOCK_FUNCTION (bl) == NULL || block_inlined_p (bl))
  80.          && BLOCK_SUPERBLOCK (bl) != NULL)
  81.     bl = BLOCK_SUPERBLOCK (bl);

  82.   return BLOCK_FUNCTION (bl);
  83. }

  84. /* Return the symbol for the function which contains a specified
  85.    block, described by a struct block BL.  The return value will be
  86.    the closest enclosing function, which might be an inline
  87.    function.  */

  88. struct symbol *
  89. block_containing_function (const struct block *bl)
  90. {
  91.   while (BLOCK_FUNCTION (bl) == NULL && BLOCK_SUPERBLOCK (bl) != NULL)
  92.     bl = BLOCK_SUPERBLOCK (bl);

  93.   return BLOCK_FUNCTION (bl);
  94. }

  95. /* Return one if BL represents an inlined function.  */

  96. int
  97. block_inlined_p (const struct block *bl)
  98. {
  99.   return BLOCK_FUNCTION (bl) != NULL && SYMBOL_INLINED (BLOCK_FUNCTION (bl));
  100. }

  101. /* A helper function that checks whether PC is in the blockvector BL.
  102.    It returns the containing block if there is one, or else NULL.  */

  103. static struct block *
  104. find_block_in_blockvector (const struct blockvector *bl, CORE_ADDR pc)
  105. {
  106.   struct block *b;
  107.   int bot, top, half;

  108.   /* If we have an addrmap mapping code addresses to blocks, then use
  109.      that.  */
  110.   if (BLOCKVECTOR_MAP (bl))
  111.     return addrmap_find (BLOCKVECTOR_MAP (bl), pc);

  112.   /* Otherwise, use binary search to find the last block that starts
  113.      before PC.
  114.      Note: GLOBAL_BLOCK is block 0, STATIC_BLOCK is block 1.
  115.      They both have the same START,END values.
  116.      Historically this code would choose STATIC_BLOCK over GLOBAL_BLOCK but the
  117.      fact that this choice was made was subtle, now we make it explicit.  */
  118.   gdb_assert (BLOCKVECTOR_NBLOCKS (bl) >= 2);
  119.   bot = STATIC_BLOCK;
  120.   top = BLOCKVECTOR_NBLOCKS (bl);

  121.   while (top - bot > 1)
  122.     {
  123.       half = (top - bot + 1) >> 1;
  124.       b = BLOCKVECTOR_BLOCK (bl, bot + half);
  125.       if (BLOCK_START (b) <= pc)
  126.         bot += half;
  127.       else
  128.         top = bot + half;
  129.     }

  130.   /* Now search backward for a block that ends after PC.  */

  131.   while (bot >= STATIC_BLOCK)
  132.     {
  133.       b = BLOCKVECTOR_BLOCK (bl, bot);
  134.       if (BLOCK_END (b) > pc)
  135.         return b;
  136.       bot--;
  137.     }

  138.   return NULL;
  139. }

  140. /* Return the blockvector immediately containing the innermost lexical
  141.    block containing the specified pc value and section, or 0 if there
  142.    is none.  PBLOCK is a pointer to the block.  If PBLOCK is NULL, we
  143.    don't pass this information back to the caller.  */

  144. const struct blockvector *
  145. blockvector_for_pc_sect (CORE_ADDR pc, struct obj_section *section,
  146.                          const struct block **pblock,
  147.                          struct compunit_symtab *cust)
  148. {
  149.   const struct blockvector *bl;
  150.   struct block *b;

  151.   if (cust == NULL)
  152.     {
  153.       /* First search all symtabs for one whose file contains our pc */
  154.       cust = find_pc_sect_compunit_symtab (pc, section);
  155.       if (cust == NULL)
  156.         return 0;
  157.     }

  158.   bl = COMPUNIT_BLOCKVECTOR (cust);

  159.   /* Then search that symtab for the smallest block that wins.  */
  160.   b = find_block_in_blockvector (bl, pc);
  161.   if (b == NULL)
  162.     return NULL;

  163.   if (pblock)
  164.     *pblock = b;
  165.   return bl;
  166. }

  167. /* Return true if the blockvector BV contains PC, false otherwise.  */

  168. int
  169. blockvector_contains_pc (const struct blockvector *bv, CORE_ADDR pc)
  170. {
  171.   return find_block_in_blockvector (bv, pc) != NULL;
  172. }

  173. /* Return call_site for specified PC in GDBARCH.  PC must match exactly, it
  174.    must be the next instruction after call (or after tail call jump).  Throw
  175.    NO_ENTRY_VALUE_ERROR otherwise.  This function never returns NULL.  */

  176. struct call_site *
  177. call_site_for_pc (struct gdbarch *gdbarch, CORE_ADDR pc)
  178. {
  179.   struct compunit_symtab *cust;
  180.   void **slot = NULL;

  181.   /* -1 as tail call PC can be already after the compilation unit range.  */
  182.   cust = find_pc_compunit_symtab (pc - 1);

  183.   if (cust != NULL && COMPUNIT_CALL_SITE_HTAB (cust) != NULL)
  184.     slot = htab_find_slot (COMPUNIT_CALL_SITE_HTAB (cust), &pc, NO_INSERT);

  185.   if (slot == NULL)
  186.     {
  187.       struct bound_minimal_symbol msym = lookup_minimal_symbol_by_pc (pc);

  188.       /* DW_TAG_gnu_call_site will be missing just if GCC could not determine
  189.          the call target.  */
  190.       throw_error (NO_ENTRY_VALUE_ERROR,
  191.                    _("DW_OP_GNU_entry_value resolving cannot find "
  192.                      "DW_TAG_GNU_call_site %s in %s"),
  193.                    paddress (gdbarch, pc),
  194.                    (msym.minsym == NULL ? "???"
  195.                     : MSYMBOL_PRINT_NAME (msym.minsym)));
  196.     }

  197.   return *slot;
  198. }

  199. /* Return the blockvector immediately containing the innermost lexical block
  200.    containing the specified pc value, or 0 if there is none.
  201.    Backward compatibility, no section.  */

  202. const struct blockvector *
  203. blockvector_for_pc (CORE_ADDR pc, const struct block **pblock)
  204. {
  205.   return blockvector_for_pc_sect (pc, find_pc_mapped_section (pc),
  206.                                   pblock, NULL);
  207. }

  208. /* Return the innermost lexical block containing the specified pc value
  209.    in the specified section, or 0 if there is none.  */

  210. const struct block *
  211. block_for_pc_sect (CORE_ADDR pc, struct obj_section *section)
  212. {
  213.   const struct blockvector *bl;
  214.   const struct block *b;

  215.   bl = blockvector_for_pc_sect (pc, section, &b, NULL);
  216.   if (bl)
  217.     return b;
  218.   return 0;
  219. }

  220. /* Return the innermost lexical block containing the specified pc value,
  221.    or 0 if there is none.  Backward compatibility, no section.  */

  222. const struct block *
  223. block_for_pc (CORE_ADDR pc)
  224. {
  225.   return block_for_pc_sect (pc, find_pc_mapped_section (pc));
  226. }

  227. /* Now come some functions designed to deal with C++ namespace issues.
  228.    The accessors are safe to use even in the non-C++ case.  */

  229. /* This returns the namespace that BLOCK is enclosed in, or "" if it
  230.    isn't enclosed in a namespace at all.  This travels the chain of
  231.    superblocks looking for a scope, if necessary.  */

  232. const char *
  233. block_scope (const struct block *block)
  234. {
  235.   for (; block != NULL; block = BLOCK_SUPERBLOCK (block))
  236.     {
  237.       if (BLOCK_NAMESPACE (block) != NULL
  238.           && BLOCK_NAMESPACE (block)->scope != NULL)
  239.         return BLOCK_NAMESPACE (block)->scope;
  240.     }

  241.   return "";
  242. }

  243. /* Set BLOCK's scope member to SCOPE; if needed, allocate memory via
  244.    OBSTACK.  (It won't make a copy of SCOPE, however, so that already
  245.    has to be allocated correctly.)  */

  246. void
  247. block_set_scope (struct block *block, const char *scope,
  248.                  struct obstack *obstack)
  249. {
  250.   block_initialize_namespace (block, obstack);

  251.   BLOCK_NAMESPACE (block)->scope = scope;
  252. }

  253. /* This returns the using directives list associated with BLOCK, if
  254.    any.  */

  255. struct using_direct *
  256. block_using (const struct block *block)
  257. {
  258.   if (block == NULL || BLOCK_NAMESPACE (block) == NULL)
  259.     return NULL;
  260.   else
  261.     return BLOCK_NAMESPACE (block)->using;
  262. }

  263. /* Set BLOCK's using member to USING; if needed, allocate memory via
  264.    OBSTACK.  (It won't make a copy of USING, however, so that already
  265.    has to be allocated correctly.)  */

  266. void
  267. block_set_using (struct block *block,
  268.                  struct using_direct *using,
  269.                  struct obstack *obstack)
  270. {
  271.   block_initialize_namespace (block, obstack);

  272.   BLOCK_NAMESPACE (block)->using = using;
  273. }

  274. /* If BLOCK_NAMESPACE (block) is NULL, allocate it via OBSTACK and
  275.    ititialize its members to zero.  */

  276. static void
  277. block_initialize_namespace (struct block *block, struct obstack *obstack)
  278. {
  279.   if (BLOCK_NAMESPACE (block) == NULL)
  280.     {
  281.       BLOCK_NAMESPACE (block)
  282.         = obstack_alloc (obstack, sizeof (struct block_namespace_info));
  283.       BLOCK_NAMESPACE (block)->scope = NULL;
  284.       BLOCK_NAMESPACE (block)->using = NULL;
  285.     }
  286. }

  287. /* Return the static block associated to BLOCK.  Return NULL if block
  288.    is NULL or if block is a global block.  */

  289. const struct block *
  290. block_static_block (const struct block *block)
  291. {
  292.   if (block == NULL || BLOCK_SUPERBLOCK (block) == NULL)
  293.     return NULL;

  294.   while (BLOCK_SUPERBLOCK (BLOCK_SUPERBLOCK (block)) != NULL)
  295.     block = BLOCK_SUPERBLOCK (block);

  296.   return block;
  297. }

  298. /* Return the static block associated to BLOCK.  Return NULL if block
  299.    is NULL.  */

  300. const struct block *
  301. block_global_block (const struct block *block)
  302. {
  303.   if (block == NULL)
  304.     return NULL;

  305.   while (BLOCK_SUPERBLOCK (block) != NULL)
  306.     block = BLOCK_SUPERBLOCK (block);

  307.   return block;
  308. }

  309. /* Allocate a block on OBSTACK, and initialize its elements to
  310.    zero/NULL.  This is useful for creating "dummy" blocks that don't
  311.    correspond to actual source files.

  312.    Warning: it sets the block's BLOCK_DICT to NULL, which isn't a
  313.    valid value.  If you really don't want the block to have a
  314.    dictionary, then you should subsequently set its BLOCK_DICT to
  315.    dict_create_linear (obstack, NULL).  */

  316. struct block *
  317. allocate_block (struct obstack *obstack)
  318. {
  319.   struct block *bl = OBSTACK_ZALLOC (obstack, struct block);

  320.   return bl;
  321. }

  322. /* Allocate a global block.  */

  323. struct block *
  324. allocate_global_block (struct obstack *obstack)
  325. {
  326.   struct global_block *bl = OBSTACK_ZALLOC (obstack, struct global_block);

  327.   return &bl->block;
  328. }

  329. /* Set the compunit of the global block.  */

  330. void
  331. set_block_compunit_symtab (struct block *block, struct compunit_symtab *cu)
  332. {
  333.   struct global_block *gb;

  334.   gdb_assert (BLOCK_SUPERBLOCK (block) == NULL);
  335.   gb = (struct global_block *) block;
  336.   gdb_assert (gb->compunit_symtab == NULL);
  337.   gb->compunit_symtab = cu;
  338. }

  339. /* Return the compunit of the global block.  */

  340. static struct compunit_symtab *
  341. get_block_compunit_symtab (const struct block *block)
  342. {
  343.   struct global_block *gb;

  344.   gdb_assert (BLOCK_SUPERBLOCK (block) == NULL);
  345.   gb = (struct global_block *) block;
  346.   gdb_assert (gb->compunit_symtab != NULL);
  347.   return gb->compunit_symtab;
  348. }



  349. /* Initialize a block iterator, either to iterate over a single block,
  350.    or, for static and global blocks, all the included symtabs as
  351.    well.  */

  352. static void
  353. initialize_block_iterator (const struct block *block,
  354.                            struct block_iterator *iter)
  355. {
  356.   enum block_enum which;
  357.   struct compunit_symtab *cu;

  358.   iter->idx = -1;

  359.   if (BLOCK_SUPERBLOCK (block) == NULL)
  360.     {
  361.       which = GLOBAL_BLOCK;
  362.       cu = get_block_compunit_symtab (block);
  363.     }
  364.   else if (BLOCK_SUPERBLOCK (BLOCK_SUPERBLOCK (block)) == NULL)
  365.     {
  366.       which = STATIC_BLOCK;
  367.       cu = get_block_compunit_symtab (BLOCK_SUPERBLOCK (block));
  368.     }
  369.   else
  370.     {
  371.       iter->d.block = block;
  372.       /* A signal value meaning that we're iterating over a single
  373.          block.  */
  374.       iter->which = FIRST_LOCAL_BLOCK;
  375.       return;
  376.     }

  377.   /* If this is an included symtab, find the canonical includer and
  378.      use it instead.  */
  379.   while (cu->user != NULL)
  380.     cu = cu->user;

  381.   /* Putting this check here simplifies the logic of the iterator
  382.      functions.  If there are no included symtabs, we only need to
  383.      search a single block, so we might as well just do that
  384.      directly.  */
  385.   if (cu->includes == NULL)
  386.     {
  387.       iter->d.block = block;
  388.       /* A signal value meaning that we're iterating over a single
  389.          block.  */
  390.       iter->which = FIRST_LOCAL_BLOCK;
  391.     }
  392.   else
  393.     {
  394.       iter->d.compunit_symtab = cu;
  395.       iter->which = which;
  396.     }
  397. }

  398. /* A helper function that finds the current compunit over whose static
  399.    or global block we should iterate.  */

  400. static struct compunit_symtab *
  401. find_iterator_compunit_symtab (struct block_iterator *iterator)
  402. {
  403.   if (iterator->idx == -1)
  404.     return iterator->d.compunit_symtab;
  405.   return iterator->d.compunit_symtab->includes[iterator->idx];
  406. }

  407. /* Perform a single step for a plain block iterator, iterating across
  408.    symbol tables as needed.  Returns the next symbol, or NULL when
  409.    iteration is complete.  */

  410. static struct symbol *
  411. block_iterator_step (struct block_iterator *iterator, int first)
  412. {
  413.   struct symbol *sym;

  414.   gdb_assert (iterator->which != FIRST_LOCAL_BLOCK);

  415.   while (1)
  416.     {
  417.       if (first)
  418.         {
  419.           struct compunit_symtab *cust
  420.             = find_iterator_compunit_symtab (iterator);
  421.           const struct block *block;

  422.           /* Iteration is complete.  */
  423.           if (cust == NULL)
  424.             return  NULL;

  425.           block = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust),
  426.                                      iterator->which);
  427.           sym = dict_iterator_first (BLOCK_DICT (block), &iterator->dict_iter);
  428.         }
  429.       else
  430.         sym = dict_iterator_next (&iterator->dict_iter);

  431.       if (sym != NULL)
  432.         return sym;

  433.       /* We have finished iterating the appropriate block of one
  434.          symtab.  Now advance to the next symtab and begin iteration
  435.          there.  */
  436.       ++iterator->idx;
  437.       first = 1;
  438.     }
  439. }

  440. /* See block.h.  */

  441. struct symbol *
  442. block_iterator_first (const struct block *block,
  443.                       struct block_iterator *iterator)
  444. {
  445.   initialize_block_iterator (block, iterator);

  446.   if (iterator->which == FIRST_LOCAL_BLOCK)
  447.     return dict_iterator_first (block->dict, &iterator->dict_iter);

  448.   return block_iterator_step (iterator, 1);
  449. }

  450. /* See block.h.  */

  451. struct symbol *
  452. block_iterator_next (struct block_iterator *iterator)
  453. {
  454.   if (iterator->which == FIRST_LOCAL_BLOCK)
  455.     return dict_iterator_next (&iterator->dict_iter);

  456.   return block_iterator_step (iterator, 0);
  457. }

  458. /* Perform a single step for a "name" block iterator, iterating across
  459.    symbol tables as needed.  Returns the next symbol, or NULL when
  460.    iteration is complete.  */

  461. static struct symbol *
  462. block_iter_name_step (struct block_iterator *iterator, const char *name,
  463.                       int first)
  464. {
  465.   struct symbol *sym;

  466.   gdb_assert (iterator->which != FIRST_LOCAL_BLOCK);

  467.   while (1)
  468.     {
  469.       if (first)
  470.         {
  471.           struct compunit_symtab *cust
  472.             = find_iterator_compunit_symtab (iterator);
  473.           const struct block *block;

  474.           /* Iteration is complete.  */
  475.           if (cust == NULL)
  476.             return  NULL;

  477.           block = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust),
  478.                                      iterator->which);
  479.           sym = dict_iter_name_first (BLOCK_DICT (block), name,
  480.                                       &iterator->dict_iter);
  481.         }
  482.       else
  483.         sym = dict_iter_name_next (name, &iterator->dict_iter);

  484.       if (sym != NULL)
  485.         return sym;

  486.       /* We have finished iterating the appropriate block of one
  487.          symtab.  Now advance to the next symtab and begin iteration
  488.          there.  */
  489.       ++iterator->idx;
  490.       first = 1;
  491.     }
  492. }

  493. /* See block.h.  */

  494. struct symbol *
  495. block_iter_name_first (const struct block *block,
  496.                        const char *name,
  497.                        struct block_iterator *iterator)
  498. {
  499.   initialize_block_iterator (block, iterator);

  500.   if (iterator->which == FIRST_LOCAL_BLOCK)
  501.     return dict_iter_name_first (block->dict, name, &iterator->dict_iter);

  502.   return block_iter_name_step (iterator, name, 1);
  503. }

  504. /* See block.h.  */

  505. struct symbol *
  506. block_iter_name_next (const char *name, struct block_iterator *iterator)
  507. {
  508.   if (iterator->which == FIRST_LOCAL_BLOCK)
  509.     return dict_iter_name_next (name, &iterator->dict_iter);

  510.   return block_iter_name_step (iterator, name, 0);
  511. }

  512. /* Perform a single step for a "match" block iterator, iterating
  513.    across symbol tables as needed.  Returns the next symbol, or NULL
  514.    when iteration is complete.  */

  515. static struct symbol *
  516. block_iter_match_step (struct block_iterator *iterator,
  517.                        const char *name,
  518.                        symbol_compare_ftype *compare,
  519.                        int first)
  520. {
  521.   struct symbol *sym;

  522.   gdb_assert (iterator->which != FIRST_LOCAL_BLOCK);

  523.   while (1)
  524.     {
  525.       if (first)
  526.         {
  527.           struct compunit_symtab *cust
  528.             = find_iterator_compunit_symtab (iterator);
  529.           const struct block *block;

  530.           /* Iteration is complete.  */
  531.           if (cust == NULL)
  532.             return  NULL;

  533.           block = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust),
  534.                                      iterator->which);
  535.           sym = dict_iter_match_first (BLOCK_DICT (block), name,
  536.                                        compare, &iterator->dict_iter);
  537.         }
  538.       else
  539.         sym = dict_iter_match_next (name, compare, &iterator->dict_iter);

  540.       if (sym != NULL)
  541.         return sym;

  542.       /* We have finished iterating the appropriate block of one
  543.          symtab.  Now advance to the next symtab and begin iteration
  544.          there.  */
  545.       ++iterator->idx;
  546.       first = 1;
  547.     }
  548. }

  549. /* See block.h.  */

  550. struct symbol *
  551. block_iter_match_first (const struct block *block,
  552.                         const char *name,
  553.                         symbol_compare_ftype *compare,
  554.                         struct block_iterator *iterator)
  555. {
  556.   initialize_block_iterator (block, iterator);

  557.   if (iterator->which == FIRST_LOCAL_BLOCK)
  558.     return dict_iter_match_first (block->dict, name, compare,
  559.                                   &iterator->dict_iter);

  560.   return block_iter_match_step (iterator, name, compare, 1);
  561. }

  562. /* See block.h.  */

  563. struct symbol *
  564. block_iter_match_next (const char *name,
  565.                        symbol_compare_ftype *compare,
  566.                        struct block_iterator *iterator)
  567. {
  568.   if (iterator->which == FIRST_LOCAL_BLOCK)
  569.     return dict_iter_match_next (name, compare, &iterator->dict_iter);

  570.   return block_iter_match_step (iterator, name, compare, 0);
  571. }

  572. /* See block.h.

  573.    Note that if NAME is the demangled form of a C++ symbol, we will fail
  574.    to find a match during the binary search of the non-encoded names, but
  575.    for now we don't worry about the slight inefficiency of looking for
  576.    a match we'll never find, since it will go pretty quick.  Once the
  577.    binary search terminates, we drop through and do a straight linear
  578.    search on the symbols.  Each symbol which is marked as being a ObjC/C++
  579.    symbol (language_cplus or language_objc set) has both the encoded and
  580.    non-encoded names tested for a match.  */

  581. struct symbol *
  582. block_lookup_symbol (const struct block *block, const char *name,
  583.                      const domain_enum domain)
  584. {
  585.   struct block_iterator iter;
  586.   struct symbol *sym;

  587.   if (!BLOCK_FUNCTION (block))
  588.     {
  589.       ALL_BLOCK_SYMBOLS_WITH_NAME (block, name, iter, sym)
  590.         {
  591.           if (symbol_matches_domain (SYMBOL_LANGUAGE (sym),
  592.                                      SYMBOL_DOMAIN (sym), domain))
  593.             return sym;
  594.         }
  595.       return NULL;
  596.     }
  597.   else
  598.     {
  599.       /* Note that parameter symbols do not always show up last in the
  600.          list; this loop makes sure to take anything else other than
  601.          parameter symbols first; it only uses parameter symbols as a
  602.          last resort.  Note that this only takes up extra computation
  603.          time on a match.  */

  604.       struct symbol *sym_found = NULL;

  605.       ALL_BLOCK_SYMBOLS_WITH_NAME (block, name, iter, sym)
  606.         {
  607.           if (symbol_matches_domain (SYMBOL_LANGUAGE (sym),
  608.                                      SYMBOL_DOMAIN (sym), domain))
  609.             {
  610.               sym_found = sym;
  611.               if (!SYMBOL_IS_ARGUMENT (sym))
  612.                 {
  613.                   break;
  614.                 }
  615.             }
  616.         }
  617.       return (sym_found);        /* Will be NULL if not found.  */
  618.     }
  619. }

  620. /* See block.h.  */

  621. struct symbol *
  622. block_lookup_symbol_primary (const struct block *block, const char *name,
  623.                              const domain_enum domain)
  624. {
  625.   struct symbol *sym;
  626.   struct dict_iterator dict_iter;

  627.   /* Verify BLOCK is STATIC_BLOCK or GLOBAL_BLOCK.  */
  628.   gdb_assert (BLOCK_SUPERBLOCK (block) == NULL
  629.               || BLOCK_SUPERBLOCK (BLOCK_SUPERBLOCK (block)) == NULL);

  630.   for (sym = dict_iter_name_first (block->dict, name, &dict_iter);
  631.        sym != NULL;
  632.        sym = dict_iter_name_next (name, &dict_iter))
  633.     {
  634.       if (symbol_matches_domain (SYMBOL_LANGUAGE (sym),
  635.                                  SYMBOL_DOMAIN (sym), domain))
  636.         return sym;
  637.     }

  638.   return NULL;
  639. }