gdb/block.h - gdb

Data types defined

Macros defined

Source code

  1. /* Code dealing with blocks for 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. #ifndef BLOCK_H
  15. #define BLOCK_H

  16. #include "dictionary.h"

  17. /* Opaque declarations.  */

  18. struct symbol;
  19. struct compunit_symtab;
  20. struct block_namespace_info;
  21. struct using_direct;
  22. struct obstack;
  23. struct addrmap;

  24. /* All of the name-scope contours of the program
  25.    are represented by `struct block' objects.
  26.    All of these objects are pointed to by the blockvector.

  27.    Each block represents one name scope.
  28.    Each lexical context has its own block.

  29.    The blockvector begins with some special blocks.
  30.    The GLOBAL_BLOCK contains all the symbols defined in this compilation
  31.    whose scope is the entire program linked together.
  32.    The STATIC_BLOCK contains all the symbols whose scope is the
  33.    entire compilation excluding other separate compilations.
  34.    Blocks starting with the FIRST_LOCAL_BLOCK are not special.

  35.    Each block records a range of core addresses for the code that
  36.    is in the scope of the block.  The STATIC_BLOCK and GLOBAL_BLOCK
  37.    give, for the range of code, the entire range of code produced
  38.    by the compilation that the symbol segment belongs to.

  39.    The blocks appear in the blockvector
  40.    in order of increasing starting-address,
  41.    and, within that, in order of decreasing ending-address.

  42.    This implies that within the body of one function
  43.    the blocks appear in the order of a depth-first tree walk.  */

  44. struct block
  45. {

  46.   /* Addresses in the executable code that are in this block.  */

  47.   CORE_ADDR startaddr;
  48.   CORE_ADDR endaddr;

  49.   /* The symbol that names this block, if the block is the body of a
  50.      function (real or inlined); otherwise, zero.  */

  51.   struct symbol *function;

  52.   /* The `struct block' for the containing block, or 0 if none.

  53.      The superblock of a top-level local block (i.e. a function in the
  54.      case of C) is the STATIC_BLOCK.  The superblock of the
  55.      STATIC_BLOCK is the GLOBAL_BLOCK.  */

  56.   struct block *superblock;

  57.   /* This is used to store the symbols in the block.  */

  58.   struct dictionary *dict;

  59.   /* Used for language-specific info.  */

  60.   union
  61.   {
  62.     struct
  63.     {
  64.       /* Contains information about namespace-related info relevant to
  65.          this block: using directives and the current namespace
  66.          scope.  */

  67.       struct block_namespace_info *namespace;
  68.     }
  69.     cplus_specific;
  70.   }
  71.   language_specific;
  72. };

  73. /* The global block is singled out so that we can provide a back-link
  74.    to the compunit symtab.  */

  75. struct global_block
  76. {
  77.   /* The block.  */

  78.   struct block block;

  79.   /* This holds a pointer to the compunit symtab holding this block.  */

  80.   struct compunit_symtab *compunit_symtab;
  81. };

  82. #define BLOCK_START(bl)                (bl)->startaddr
  83. #define BLOCK_END(bl)                (bl)->endaddr
  84. #define BLOCK_FUNCTION(bl)        (bl)->function
  85. #define BLOCK_SUPERBLOCK(bl)        (bl)->superblock
  86. #define BLOCK_DICT(bl)                (bl)->dict
  87. #define BLOCK_NAMESPACE(bl)   (bl)->language_specific.cplus_specific.namespace

  88. struct blockvector
  89. {
  90.   /* Number of blocks in the list.  */
  91.   int nblocks;
  92.   /* An address map mapping addresses to blocks in this blockvector.
  93.      This pointer is zero if the blocks' start and end addresses are
  94.      enough.  */
  95.   struct addrmap *map;
  96.   /* The blocks themselves.  */
  97.   struct block *block[1];
  98. };

  99. #define BLOCKVECTOR_NBLOCKS(blocklist) (blocklist)->nblocks
  100. #define BLOCKVECTOR_BLOCK(blocklist,n) (blocklist)->block[n]
  101. #define BLOCKVECTOR_MAP(blocklist) ((blocklist)->map)

  102. /* Return the objfile of BLOCK, which must be non-NULL.  */

  103. extern struct objfile *block_objfile (const struct block *block);

  104. /* Return the architecture of BLOCK, which must be non-NULL.  */

  105. extern struct gdbarch *block_gdbarch (const struct block *block);

  106. extern struct symbol *block_linkage_function (const struct block *);

  107. extern struct symbol *block_containing_function (const struct block *);

  108. extern int block_inlined_p (const struct block *block);

  109. extern int contained_in (const struct block *, const struct block *);

  110. extern const struct blockvector *blockvector_for_pc (CORE_ADDR,
  111.                                                const struct block **);

  112. extern const struct blockvector *
  113.   blockvector_for_pc_sect (CORE_ADDR, struct obj_section *,
  114.                            const struct block **, struct compunit_symtab *);

  115. extern int blockvector_contains_pc (const struct blockvector *bv, CORE_ADDR pc);

  116. extern struct call_site *call_site_for_pc (struct gdbarch *gdbarch,
  117.                                            CORE_ADDR pc);

  118. extern const struct block *block_for_pc (CORE_ADDR);

  119. extern const struct block *block_for_pc_sect (CORE_ADDR, struct obj_section *);

  120. extern const char *block_scope (const struct block *block);

  121. extern void block_set_scope (struct block *block, const char *scope,
  122.                              struct obstack *obstack);

  123. extern struct using_direct *block_using (const struct block *block);

  124. extern void block_set_using (struct block *block,
  125.                              struct using_direct *using,
  126.                              struct obstack *obstack);

  127. extern const struct block *block_static_block (const struct block *block);

  128. extern const struct block *block_global_block (const struct block *block);

  129. extern struct block *allocate_block (struct obstack *obstack);

  130. extern struct block *allocate_global_block (struct obstack *obstack);

  131. extern void set_block_compunit_symtab (struct block *,
  132.                                        struct compunit_symtab *);

  133. /* A block iterator.  This structure should be treated as though it
  134.    were opaque; it is only defined here because we want to support
  135.    stack allocation of iterators.  */

  136. struct block_iterator
  137. {
  138.   /* If we're iterating over a single block, this holds the block.
  139.      Otherwise, it holds the canonical compunit.  */

  140.   union
  141.   {
  142.     struct compunit_symtab *compunit_symtab;
  143.     const struct block *block;
  144.   } d;

  145.   /* If we're iterating over a single block, this is always -1.
  146.      Otherwise, it holds the index of the current "included" symtab in
  147.      the canonical symtab (that is, d.symtab->includes[idx]), with -1
  148.      meaning the canonical symtab itself.  */

  149.   int idx;

  150.   /* Which block, either static or global, to iterate over.  If this
  151.      is FIRST_LOCAL_BLOCK, then we are iterating over a single block.
  152.      This is used to select which field of 'd' is in use.  */

  153.   enum block_enum which;

  154.   /* The underlying dictionary iterator.  */

  155.   struct dict_iterator dict_iter;
  156. };

  157. /* Initialize ITERATOR to point at the first symbol in BLOCK, and
  158.    return that first symbol, or NULL if BLOCK is empty.  */

  159. extern struct symbol *block_iterator_first (const struct block *block,
  160.                                             struct block_iterator *iterator);

  161. /* Advance ITERATOR, and return the next symbol, or NULL if there are
  162.    no more symbols.  Don't call this if you've previously received
  163.    NULL from block_iterator_first or block_iterator_next on this
  164.    iteration.  */

  165. extern struct symbol *block_iterator_next (struct block_iterator *iterator);

  166. /* Initialize ITERATOR to point at the first symbol in BLOCK whose
  167.    SYMBOL_SEARCH_NAME is NAME (as tested using strcmp_iw), and return
  168.    that first symbol, or NULL if there are no such symbols.  */

  169. extern struct symbol *block_iter_name_first (const struct block *block,
  170.                                              const char *name,
  171.                                              struct block_iterator *iterator);

  172. /* Advance ITERATOR to point at the next symbol in BLOCK whose
  173.    SYMBOL_SEARCH_NAME is NAME (as tested using strcmp_iw), or NULL if
  174.    there are no more such symbols.  Don't call this if you've
  175.    previously received NULL from block_iterator_first or
  176.    block_iterator_next on this iteration.  And don't call it unless
  177.    ITERATOR was created by a previous call to block_iter_name_first
  178.    with the same NAME.  */

  179. extern struct symbol *block_iter_name_next (const char *name,
  180.                                             struct block_iterator *iterator);

  181. /* Initialize ITERATOR to point at the first symbol in BLOCK whose
  182.    SYMBOL_SEARCH_NAME is NAME, as tested using COMPARE (which must use
  183.    the same conventions as strcmp_iw and be compatible with any
  184.    block hashing function), and return that first symbol, or NULL
  185.    if there are no such symbols.  */

  186. extern struct symbol *block_iter_match_first (const struct block *block,
  187.                                               const char *name,
  188.                                               symbol_compare_ftype *compare,
  189.                                               struct block_iterator *iterator);

  190. /* Advance ITERATOR to point at the next symbol in BLOCK whose
  191.    SYMBOL_SEARCH_NAME is NAME, as tested using COMPARE (see
  192.    block_iter_match_first), or NULL if there are no more such symbols.
  193.    Don't call this if you've previously received NULL from
  194.    block_iterator_match_first or block_iterator_match_next on this
  195.    iteration.  And don't call it unless ITERATOR was created by a
  196.    previous call to block_iter_match_first with the same NAME and COMPARE.  */

  197. extern struct symbol *block_iter_match_next (const char *name,
  198.                                              symbol_compare_ftype *compare,
  199.                                              struct block_iterator *iterator);

  200. /* Search BLOCK for symbol NAME in DOMAIN.  */

  201. extern struct symbol *block_lookup_symbol (const struct block *block,
  202.                                            const char *name,
  203.                                            const domain_enum domain);

  204. /* Search BLOCK for symbol NAME in DOMAIN but only in primary symbol table of
  205.    BLOCK.  BLOCK must be STATIC_BLOCK or GLOBAL_BLOCK.  Function is useful if
  206.    one iterates all global/static blocks of an objfile.  */

  207. extern struct symbol *block_lookup_symbol_primary (const struct block *block,
  208.                                                    const char *name,
  209.                                                    const domain_enum domain);

  210. /* Macro to loop through all symbols in BLOCK, in no particular
  211.    order.  ITER helps keep track of the iteration, and must be a
  212.    struct block_iterator.  SYM points to the current symbol.  */

  213. #define ALL_BLOCK_SYMBOLS(block, iter, sym)                \
  214.   for ((sym) = block_iterator_first ((block), &(iter));        \
  215.        (sym);                                                \
  216.        (sym) = block_iterator_next (&(iter)))

  217. /* Macro to loop through all symbols with name NAME in BLOCK,
  218.    in no particular order.  ITER helps keep track of the iteration, and
  219.    must be a struct block_iterator.  SYM points to the current symbol.  */

  220. #define ALL_BLOCK_SYMBOLS_WITH_NAME(block, name, iter, sym)                \
  221.   for ((sym) = block_iter_name_first ((block), (name), &(iter));        \
  222.        (sym) != NULL;                                                        \
  223.        (sym) = block_iter_name_next ((name), &(iter)))

  224. #endif /* BLOCK_H */