GDB (API)
|
00001 /* Code dealing with blocks for GDB. 00002 00003 Copyright (C) 2003-2013 Free Software Foundation, Inc. 00004 00005 This file is part of GDB. 00006 00007 This program is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License as published by 00009 the Free Software Foundation; either version 3 of the License, or 00010 (at your option) any later version. 00011 00012 This program is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 00019 00020 #ifndef BLOCK_H 00021 #define BLOCK_H 00022 00023 #include "dictionary.h" 00024 00025 /* Opaque declarations. */ 00026 00027 struct symbol; 00028 struct symtab; 00029 struct block_namespace_info; 00030 struct using_direct; 00031 struct obstack; 00032 struct addrmap; 00033 00034 /* All of the name-scope contours of the program 00035 are represented by `struct block' objects. 00036 All of these objects are pointed to by the blockvector. 00037 00038 Each block represents one name scope. 00039 Each lexical context has its own block. 00040 00041 The blockvector begins with some special blocks. 00042 The GLOBAL_BLOCK contains all the symbols defined in this compilation 00043 whose scope is the entire program linked together. 00044 The STATIC_BLOCK contains all the symbols whose scope is the 00045 entire compilation excluding other separate compilations. 00046 Blocks starting with the FIRST_LOCAL_BLOCK are not special. 00047 00048 Each block records a range of core addresses for the code that 00049 is in the scope of the block. The STATIC_BLOCK and GLOBAL_BLOCK 00050 give, for the range of code, the entire range of code produced 00051 by the compilation that the symbol segment belongs to. 00052 00053 The blocks appear in the blockvector 00054 in order of increasing starting-address, 00055 and, within that, in order of decreasing ending-address. 00056 00057 This implies that within the body of one function 00058 the blocks appear in the order of a depth-first tree walk. */ 00059 00060 struct block 00061 { 00062 00063 /* Addresses in the executable code that are in this block. */ 00064 00065 CORE_ADDR startaddr; 00066 CORE_ADDR endaddr; 00067 00068 /* The symbol that names this block, if the block is the body of a 00069 function (real or inlined); otherwise, zero. */ 00070 00071 struct symbol *function; 00072 00073 /* The `struct block' for the containing block, or 0 if none. 00074 00075 The superblock of a top-level local block (i.e. a function in the 00076 case of C) is the STATIC_BLOCK. The superblock of the 00077 STATIC_BLOCK is the GLOBAL_BLOCK. */ 00078 00079 struct block *superblock; 00080 00081 /* This is used to store the symbols in the block. */ 00082 00083 struct dictionary *dict; 00084 00085 /* Used for language-specific info. */ 00086 00087 union 00088 { 00089 struct 00090 { 00091 /* Contains information about namespace-related info relevant to 00092 this block: using directives and the current namespace 00093 scope. */ 00094 00095 struct block_namespace_info *namespace; 00096 } 00097 cplus_specific; 00098 } 00099 language_specific; 00100 }; 00101 00102 /* The global block is singled out so that we can provide a back-link 00103 to the primary symtab. */ 00104 00105 struct global_block 00106 { 00107 /* The block. */ 00108 00109 struct block block; 00110 00111 /* This holds a pointer to the primary symtab holding this 00112 block. */ 00113 00114 struct symtab *symtab; 00115 }; 00116 00117 #define BLOCK_START(bl) (bl)->startaddr 00118 #define BLOCK_END(bl) (bl)->endaddr 00119 #define BLOCK_FUNCTION(bl) (bl)->function 00120 #define BLOCK_SUPERBLOCK(bl) (bl)->superblock 00121 #define BLOCK_DICT(bl) (bl)->dict 00122 #define BLOCK_NAMESPACE(bl) (bl)->language_specific.cplus_specific.namespace 00123 00124 struct blockvector 00125 { 00126 /* Number of blocks in the list. */ 00127 int nblocks; 00128 /* An address map mapping addresses to blocks in this blockvector. 00129 This pointer is zero if the blocks' start and end addresses are 00130 enough. */ 00131 struct addrmap *map; 00132 /* The blocks themselves. */ 00133 struct block *block[1]; 00134 }; 00135 00136 #define BLOCKVECTOR_NBLOCKS(blocklist) (blocklist)->nblocks 00137 #define BLOCKVECTOR_BLOCK(blocklist,n) (blocklist)->block[n] 00138 #define BLOCKVECTOR_MAP(blocklist) ((blocklist)->map) 00139 00140 extern struct symbol *block_linkage_function (const struct block *); 00141 00142 extern struct symbol *block_containing_function (const struct block *); 00143 00144 extern int block_inlined_p (const struct block *block); 00145 00146 extern int contained_in (const struct block *, const struct block *); 00147 00148 extern struct blockvector *blockvector_for_pc (CORE_ADDR, struct block **); 00149 00150 extern struct blockvector *blockvector_for_pc_sect (CORE_ADDR, 00151 struct obj_section *, 00152 struct block **, 00153 struct symtab *); 00154 00155 extern int blockvector_contains_pc (struct blockvector *bv, CORE_ADDR pc); 00156 00157 extern struct call_site *call_site_for_pc (struct gdbarch *gdbarch, 00158 CORE_ADDR pc); 00159 00160 extern struct block *block_for_pc (CORE_ADDR); 00161 00162 extern struct block *block_for_pc_sect (CORE_ADDR, struct obj_section *); 00163 00164 extern const char *block_scope (const struct block *block); 00165 00166 extern void block_set_scope (struct block *block, const char *scope, 00167 struct obstack *obstack); 00168 00169 extern struct using_direct *block_using (const struct block *block); 00170 00171 extern void block_set_using (struct block *block, 00172 struct using_direct *using, 00173 struct obstack *obstack); 00174 00175 extern const struct block *block_static_block (const struct block *block); 00176 00177 extern const struct block *block_global_block (const struct block *block); 00178 00179 extern struct block *allocate_block (struct obstack *obstack); 00180 00181 extern struct block *allocate_global_block (struct obstack *obstack); 00182 00183 extern void set_block_symtab (struct block *, struct symtab *); 00184 00185 /* A block iterator. This structure should be treated as though it 00186 were opaque; it is only defined here because we want to support 00187 stack allocation of iterators. */ 00188 00189 struct block_iterator 00190 { 00191 /* If we're iterating over a single block, this holds the block. 00192 Otherwise, it holds the canonical symtab. */ 00193 00194 union 00195 { 00196 struct symtab *symtab; 00197 const struct block *block; 00198 } d; 00199 00200 /* If we're iterating over a single block, this is always -1. 00201 Otherwise, it holds the index of the current "included" symtab in 00202 the canonical symtab (that is, d.symtab->includes[idx]), with -1 00203 meaning the canonical symtab itself. */ 00204 00205 int idx; 00206 00207 /* Which block, either static or global, to iterate over. If this 00208 is FIRST_LOCAL_BLOCK, then we are iterating over a single block. 00209 This is used to select which field of 'd' is in use. */ 00210 00211 enum block_enum which; 00212 00213 /* The underlying dictionary iterator. */ 00214 00215 struct dict_iterator dict_iter; 00216 }; 00217 00218 /* Initialize ITERATOR to point at the first symbol in BLOCK, and 00219 return that first symbol, or NULL if BLOCK is empty. */ 00220 00221 extern struct symbol *block_iterator_first (const struct block *block, 00222 struct block_iterator *iterator); 00223 00224 /* Advance ITERATOR, and return the next symbol, or NULL if there are 00225 no more symbols. Don't call this if you've previously received 00226 NULL from block_iterator_first or block_iterator_next on this 00227 iteration. */ 00228 00229 extern struct symbol *block_iterator_next (struct block_iterator *iterator); 00230 00231 /* Initialize ITERATOR to point at the first symbol in BLOCK whose 00232 SYMBOL_SEARCH_NAME is NAME (as tested using strcmp_iw), and return 00233 that first symbol, or NULL if there are no such symbols. */ 00234 00235 extern struct symbol *block_iter_name_first (const struct block *block, 00236 const char *name, 00237 struct block_iterator *iterator); 00238 00239 /* Advance ITERATOR to point at the next symbol in BLOCK whose 00240 SYMBOL_SEARCH_NAME is NAME (as tested using strcmp_iw), or NULL if 00241 there are no more such symbols. Don't call this if you've 00242 previously received NULL from block_iterator_first or 00243 block_iterator_next on this iteration. And don't call it unless 00244 ITERATOR was created by a previous call to block_iter_name_first 00245 with the same NAME. */ 00246 00247 extern struct symbol *block_iter_name_next (const char *name, 00248 struct block_iterator *iterator); 00249 00250 /* Initialize ITERATOR to point at the first symbol in BLOCK whose 00251 SYMBOL_SEARCH_NAME is NAME, as tested using COMPARE (which must use 00252 the same conventions as strcmp_iw and be compatible with any 00253 block hashing function), and return that first symbol, or NULL 00254 if there are no such symbols. */ 00255 00256 extern struct symbol *block_iter_match_first (const struct block *block, 00257 const char *name, 00258 symbol_compare_ftype *compare, 00259 struct block_iterator *iterator); 00260 00261 /* Advance ITERATOR to point at the next symbol in BLOCK whose 00262 SYMBOL_SEARCH_NAME is NAME, as tested using COMPARE (see 00263 block_iter_match_first), or NULL if there are no more such symbols. 00264 Don't call this if you've previously received NULL from 00265 block_iterator_match_first or block_iterator_match_next on this 00266 iteration. And don't call it unless ITERATOR was created by a 00267 previous call to block_iter_match_first with the same NAME and COMPARE. */ 00268 00269 extern struct symbol *block_iter_match_next (const char *name, 00270 symbol_compare_ftype *compare, 00271 struct block_iterator *iterator); 00272 00273 /* Macro to loop through all symbols in a block BL, in no particular 00274 order. ITER helps keep track of the iteration, and should be a 00275 struct block_iterator. SYM points to the current symbol. */ 00276 00277 #define ALL_BLOCK_SYMBOLS(block, iter, sym) \ 00278 for ((sym) = block_iterator_first ((block), &(iter)); \ 00279 (sym); \ 00280 (sym) = block_iterator_next (&(iter))) 00281 00282 #endif /* BLOCK_H */