GDB (xrefs)
/tmp/gdb-7.10/gdb/block.h
Go to the documentation of this file.
1 /* Code dealing with blocks for GDB.
2 
3  Copyright (C) 2003-2015 Free Software Foundation, Inc.
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
9  the Free Software Foundation; either version 3 of the License, or
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
18  along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 
20 #ifndef BLOCK_H
21 #define BLOCK_H
22 
23 #include "dictionary.h"
24 
25 /* Opaque declarations. */
26 
27 struct symbol;
28 struct compunit_symtab;
30 struct using_direct;
31 struct obstack;
32 struct addrmap;
33 
34 /* All of the name-scope contours of the program
35  are represented by `struct block' objects.
36  All of these objects are pointed to by the blockvector.
37 
38  Each block represents one name scope.
39  Each lexical context has its own block.
40 
41  The blockvector begins with some special blocks.
42  The GLOBAL_BLOCK contains all the symbols defined in this compilation
43  whose scope is the entire program linked together.
44  The STATIC_BLOCK contains all the symbols whose scope is the
45  entire compilation excluding other separate compilations.
46  Blocks starting with the FIRST_LOCAL_BLOCK are not special.
47 
48  Each block records a range of core addresses for the code that
49  is in the scope of the block. The STATIC_BLOCK and GLOBAL_BLOCK
50  give, for the range of code, the entire range of code produced
51  by the compilation that the symbol segment belongs to.
52 
53  The blocks appear in the blockvector
54  in order of increasing starting-address,
55  and, within that, in order of decreasing ending-address.
56 
57  This implies that within the body of one function
58  the blocks appear in the order of a depth-first tree walk. */
59 
60 struct block
61 {
62 
63  /* Addresses in the executable code that are in this block. */
64 
67 
68  /* The symbol that names this block, if the block is the body of a
69  function (real or inlined); otherwise, zero. */
70 
71  struct symbol *function;
72 
73  /* The `struct block' for the containing block, or 0 if none.
74 
75  The superblock of a top-level local block (i.e. a function in the
76  case of C) is the STATIC_BLOCK. The superblock of the
77  STATIC_BLOCK is the GLOBAL_BLOCK. */
78 
79  struct block *superblock;
80 
81  /* This is used to store the symbols in the block. */
82 
83  struct dictionary *dict;
84 
85  /* Used for language-specific info. */
86 
87  union
88  {
89  struct
90  {
91  /* Contains information about namespace-related info relevant to
92  this block: using directives and the current namespace
93  scope. */
94 
96  }
98  }
100 };
101 
102 /* The global block is singled out so that we can provide a back-link
103  to the compunit symtab. */
104 
106 {
107  /* The block. */
108 
109  struct block block;
110 
111  /* This holds a pointer to the compunit symtab holding this block. */
112 
114 };
115 
116 #define BLOCK_START(bl) (bl)->startaddr
117 #define BLOCK_END(bl) (bl)->endaddr
118 #define BLOCK_FUNCTION(bl) (bl)->function
119 #define BLOCK_SUPERBLOCK(bl) (bl)->superblock
120 #define BLOCK_DICT(bl) (bl)->dict
121 #define BLOCK_NAMESPACE(bl) (bl)->language_specific.cplus_specific.the_namespace
122 
124 {
125  /* Number of blocks in the list. */
126  int nblocks;
127  /* An address map mapping addresses to blocks in this blockvector.
128  This pointer is zero if the blocks' start and end addresses are
129  enough. */
130  struct addrmap *map;
131  /* The blocks themselves. */
132  struct block *block[1];
133 };
134 
135 #define BLOCKVECTOR_NBLOCKS(blocklist) (blocklist)->nblocks
136 #define BLOCKVECTOR_BLOCK(blocklist,n) (blocklist)->block[n]
137 #define BLOCKVECTOR_MAP(blocklist) ((blocklist)->map)
138 
139 /* Return the objfile of BLOCK, which must be non-NULL. */
140 
141 extern struct objfile *block_objfile (const struct block *block);
142 
143 /* Return the architecture of BLOCK, which must be non-NULL. */
144 
145 extern struct gdbarch *block_gdbarch (const struct block *block);
146 
147 extern struct symbol *block_linkage_function (const struct block *);
148 
149 extern struct symbol *block_containing_function (const struct block *);
150 
151 extern int block_inlined_p (const struct block *block);
152 
153 extern int contained_in (const struct block *, const struct block *);
154 
155 extern const struct blockvector *blockvector_for_pc (CORE_ADDR,
156  const struct block **);
157 
158 extern const struct blockvector *
160  const struct block **, struct compunit_symtab *);
161 
162 extern int blockvector_contains_pc (const struct blockvector *bv, CORE_ADDR pc);
163 
164 extern struct call_site *call_site_for_pc (struct gdbarch *gdbarch,
165  CORE_ADDR pc);
166 
167 extern const struct block *block_for_pc (CORE_ADDR);
168 
169 extern const struct block *block_for_pc_sect (CORE_ADDR, struct obj_section *);
170 
171 extern const char *block_scope (const struct block *block);
172 
173 extern void block_set_scope (struct block *block, const char *scope,
174  struct obstack *obstack);
175 
176 extern struct using_direct *block_using (const struct block *block);
177 
178 extern void block_set_using (struct block *block,
179  struct using_direct *using_decl,
180  struct obstack *obstack);
181 
182 extern const struct block *block_static_block (const struct block *block);
183 
184 extern const struct block *block_global_block (const struct block *block);
185 
186 extern struct block *allocate_block (struct obstack *obstack);
187 
188 extern struct block *allocate_global_block (struct obstack *obstack);
189 
190 extern void set_block_compunit_symtab (struct block *,
191  struct compunit_symtab *);
192 
193 /* A block iterator. This structure should be treated as though it
194  were opaque; it is only defined here because we want to support
195  stack allocation of iterators. */
196 
198 {
199  /* If we're iterating over a single block, this holds the block.
200  Otherwise, it holds the canonical compunit. */
201 
202  union
203  {
205  const struct block *block;
206  } d;
207 
208  /* If we're iterating over a single block, this is always -1.
209  Otherwise, it holds the index of the current "included" symtab in
210  the canonical symtab (that is, d.symtab->includes[idx]), with -1
211  meaning the canonical symtab itself. */
212 
213  int idx;
214 
215  /* Which block, either static or global, to iterate over. If this
216  is FIRST_LOCAL_BLOCK, then we are iterating over a single block.
217  This is used to select which field of 'd' is in use. */
218 
220 
221  /* The underlying dictionary iterator. */
222 
224 };
225 
226 /* Initialize ITERATOR to point at the first symbol in BLOCK, and
227  return that first symbol, or NULL if BLOCK is empty. */
228 
229 extern struct symbol *block_iterator_first (const struct block *block,
230  struct block_iterator *iterator);
231 
232 /* Advance ITERATOR, and return the next symbol, or NULL if there are
233  no more symbols. Don't call this if you've previously received
234  NULL from block_iterator_first or block_iterator_next on this
235  iteration. */
236 
237 extern struct symbol *block_iterator_next (struct block_iterator *iterator);
238 
239 /* Initialize ITERATOR to point at the first symbol in BLOCK whose
240  SYMBOL_SEARCH_NAME is NAME (as tested using strcmp_iw), and return
241  that first symbol, or NULL if there are no such symbols. */
242 
243 extern struct symbol *block_iter_name_first (const struct block *block,
244  const char *name,
245  struct block_iterator *iterator);
246 
247 /* Advance ITERATOR to point at the next symbol in BLOCK whose
248  SYMBOL_SEARCH_NAME is NAME (as tested using strcmp_iw), or NULL if
249  there are no more such symbols. Don't call this if you've
250  previously received NULL from block_iterator_first or
251  block_iterator_next on this iteration. And don't call it unless
252  ITERATOR was created by a previous call to block_iter_name_first
253  with the same NAME. */
254 
255 extern struct symbol *block_iter_name_next (const char *name,
256  struct block_iterator *iterator);
257 
258 /* Initialize ITERATOR to point at the first symbol in BLOCK whose
259  SYMBOL_SEARCH_NAME is NAME, as tested using COMPARE (which must use
260  the same conventions as strcmp_iw and be compatible with any
261  block hashing function), and return that first symbol, or NULL
262  if there are no such symbols. */
263 
264 extern struct symbol *block_iter_match_first (const struct block *block,
265  const char *name,
266  symbol_compare_ftype *compare,
267  struct block_iterator *iterator);
268 
269 /* Advance ITERATOR to point at the next symbol in BLOCK whose
270  SYMBOL_SEARCH_NAME is NAME, as tested using COMPARE (see
271  block_iter_match_first), or NULL if there are no more such symbols.
272  Don't call this if you've previously received NULL from
273  block_iterator_match_first or block_iterator_match_next on this
274  iteration. And don't call it unless ITERATOR was created by a
275  previous call to block_iter_match_first with the same NAME and COMPARE. */
276 
277 extern struct symbol *block_iter_match_next (const char *name,
278  symbol_compare_ftype *compare,
279  struct block_iterator *iterator);
280 
281 /* Search BLOCK for symbol NAME in DOMAIN. */
282 
283 extern struct symbol *block_lookup_symbol (const struct block *block,
284  const char *name,
285  const domain_enum domain);
286 
287 /* Search BLOCK for symbol NAME in DOMAIN but only in primary symbol table of
288  BLOCK. BLOCK must be STATIC_BLOCK or GLOBAL_BLOCK. Function is useful if
289  one iterates all global/static blocks of an objfile. */
290 
291 extern struct symbol *block_lookup_symbol_primary (const struct block *block,
292  const char *name,
293  const domain_enum domain);
294 
295 /* The type of the MATCHER argument to block_find_symbol. */
296 
297 typedef int (block_symbol_matcher_ftype) (struct symbol *, void *);
298 
299 /* Find symbol NAME in BLOCK and in DOMAIN that satisfies MATCHER.
300  DATA is passed unchanged to MATCHER.
301  BLOCK must be STATIC_BLOCK or GLOBAL_BLOCK. */
302 
303 extern struct symbol *block_find_symbol (const struct block *block,
304  const char *name,
305  const domain_enum domain,
307  void *data);
308 
309 /* A matcher function for block_find_symbol to find only symbols with
310  non-opaque types. */
311 
312 extern int block_find_non_opaque_type (struct symbol *sym, void *data);
313 
314 /* A matcher function for block_find_symbol to prefer symbols with
315  non-opaque types. The way to use this function is as follows:
316 
317  struct symbol *with_opaque = NULL;
318  struct symbol *sym
319  = block_find_symbol (block, name, domain,
320  block_find_non_opaque_type_preferred, &with_opaque);
321 
322  At this point if SYM is non-NULL then a non-opaque type has been found.
323  Otherwise, if WITH_OPAQUE is non-NULL then an opaque type has been found.
324  Otherwise, the symbol was not found. */
325 
326 extern int block_find_non_opaque_type_preferred (struct symbol *sym,
327  void *data);
328 
329 /* Macro to loop through all symbols in BLOCK, in no particular
330  order. ITER helps keep track of the iteration, and must be a
331  struct block_iterator. SYM points to the current symbol. */
332 
333 #define ALL_BLOCK_SYMBOLS(block, iter, sym) \
334  for ((sym) = block_iterator_first ((block), &(iter)); \
335  (sym); \
336  (sym) = block_iterator_next (&(iter)))
337 
338 /* Macro to loop through all symbols with name NAME in BLOCK,
339  in no particular order. ITER helps keep track of the iteration, and
340  must be a struct block_iterator. SYM points to the current symbol. */
341 
342 #define ALL_BLOCK_SYMBOLS_WITH_NAME(block, name, iter, sym) \
343  for ((sym) = block_iter_name_first ((block), (name), &(iter)); \
344  (sym) != NULL; \
345  (sym) = block_iter_name_next ((name), &(iter)))
346 
347 #endif /* BLOCK_H */
struct objfile * block_objfile(const struct block *block)
Definition: block.c:46
int block_inlined_p(const struct block *block)
Definition: block.c:126
struct compunit_symtab * compunit_symtab
Definition: block.h:113
const struct block * block
Definition: block.h:205
bfd_vma CORE_ADDR
Definition: common-types.h:41
struct symbol * block_find_symbol(const struct block *block, const char *name, const domain_enum domain, block_symbol_matcher_ftype *matcher, void *data)
Definition: block.c:823
struct block * allocate_block(struct obstack *obstack)
Definition: block.c:401
struct compunit_symtab * compunit_symtab
Definition: block.h:204
void block_set_scope(struct block *block, const char *scope, struct obstack *obstack)
Definition: block.c:312
enum domain_enum_tag domain_enum
CORE_ADDR endaddr
Definition: block.h:66
const struct blockvector * blockvector_for_pc(CORE_ADDR, const struct block **)
Definition: block.c:257
const struct block * block_for_pc(CORE_ADDR)
Definition: block.c:282
struct call_site * call_site_for_pc(struct gdbarch *gdbarch, CORE_ADDR pc)
Definition: block.c:224
struct symbol * block_iterator_next(struct block_iterator *iterator)
Definition: block.c:570
struct symbol * block_linkage_function(const struct block *)
Definition: block.c:100
struct addrmap * map
Definition: block.h:130
struct block * allocate_global_block(struct obstack *obstack)
Definition: block.c:411
struct dictionary * dict
Definition: block.h:83
struct gdbarch * block_gdbarch(const struct block *block)
Definition: block.c:60
struct symbol * block_iter_match_first(const struct block *block, const char *name, symbol_compare_ftype *compare, struct block_iterator *iterator)
Definition: block.c:695
struct symbol * block_lookup_symbol(const struct block *block, const char *name, const domain_enum domain)
Definition: block.c:734
const char *const name
Definition: aarch64-tdep.c:68
const struct block * block_global_block(const struct block *block)
Definition: block.c:380
union block_iterator::@31 d
struct symbol * block_iter_match_next(const char *name, symbol_compare_ftype *compare, struct block_iterator *iterator)
Definition: block.c:712
struct dict_iterator dict_iter
Definition: block.h:223
CORE_ADDR pc
Definition: gdbtypes.h:1163
int nblocks
Definition: block.h:126
union block::@29 language_specific
const struct block * block_static_block(const struct block *block)
Definition: block.c:365
struct symbol * block_lookup_symbol_primary(const struct block *block, const char *name, const domain_enum domain)
Definition: block.c:790
void block_set_using(struct block *block, struct using_direct *using_decl, struct obstack *obstack)
Definition: block.c:337
struct symbol * block_iter_name_first(const struct block *block, const char *name, struct block_iterator *iterator)
Definition: block.c:624
struct block::@29::@30 cplus_specific
Definition: block.h:60
block_enum
Definition: defs.h:680
struct symbol * block_iterator_first(const struct block *block, struct block_iterator *iterator)
Definition: block.c:556
struct symbol * block_iter_name_next(const char *name, struct block_iterator *iterator)
Definition: block.c:639
int block_find_non_opaque_type_preferred(struct symbol *sym, void *data)
Definition: block.c:857
struct block_namespace_info * the_namespace
Definition: block.h:95
const char const char int
Definition: command.h:229
int( symbol_compare_ftype)(const char *string1, const char *string2)
Definition: symfile.h:41
struct symbol * block_containing_function(const struct block *)
Definition: block.c:115
struct using_direct * block_using(const struct block *block)
Definition: block.c:324
void set_block_compunit_symtab(struct block *, struct compunit_symtab *)
Definition: block.c:421
const char * block_scope(const struct block *block)
Definition: block.c:295
const struct blockvector * blockvector_for_pc_sect(CORE_ADDR, struct obj_section *, const struct block **, struct compunit_symtab *)
Definition: block.c:184
int contained_in(const struct block *, const struct block *)
Definition: block.c:73
CORE_ADDR startaddr
Definition: block.h:65
Definition: symtab.h:703
int blockvector_contains_pc(const struct blockvector *bv, CORE_ADDR pc)
Definition: block.c:214
const struct block * block_for_pc_sect(CORE_ADDR, struct obj_section *)
Definition: block.c:267
int( block_symbol_matcher_ftype)(struct symbol *, void *)
Definition: block.h:297
enum block_enum which
Definition: block.h:219
struct block * superblock
Definition: block.h:79
int block_find_non_opaque_type(struct symbol *sym, void *data)
Definition: block.c:849
__extension__ enum domain_enum_tag domain
Definition: symtab.h:730