Add end_psymtab_common, have all debug info readers call it.
[deliverable/binutils-gdb.git] / gdb / block.h
CommitLineData
fe898f56
DC
1/* Code dealing with blocks for GDB.
2
32d0add0 3 Copyright (C) 2003-2015 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#ifndef BLOCK_H
21#define BLOCK_H
22
8157b174
TT
23#include "dictionary.h"
24
fe898f56
DC
25/* Opaque declarations. */
26
27struct symbol;
43f3e411 28struct compunit_symtab;
9219021c
DC
29struct block_namespace_info;
30struct using_direct;
31struct obstack;
801e3a5b 32struct addrmap;
fe898f56
DC
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
60struct block
61{
62
63 /* Addresses in the executable code that are in this block. */
64
65 CORE_ADDR startaddr;
66 CORE_ADDR endaddr;
67
68 /* The symbol that names this block, if the block is the body of a
edb3359d 69 function (real or inlined); otherwise, zero. */
fe898f56
DC
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
de4f826b
DC
81 /* This is used to store the symbols in the block. */
82
83 struct dictionary *dict;
84
22cee43f
PMR
85 /* Contains information about namespace-related info relevant to this block:
86 using directives and the current namespace scope. */
87
88 struct block_namespace_info *namespace_info;
fe898f56
DC
89};
90
84a146c9 91/* The global block is singled out so that we can provide a back-link
43f3e411 92 to the compunit symtab. */
84a146c9
TT
93
94struct global_block
95{
96 /* The block. */
97
98 struct block block;
99
43f3e411 100 /* This holds a pointer to the compunit symtab holding this block. */
84a146c9 101
43f3e411 102 struct compunit_symtab *compunit_symtab;
84a146c9
TT
103};
104
fe898f56
DC
105#define BLOCK_START(bl) (bl)->startaddr
106#define BLOCK_END(bl) (bl)->endaddr
107#define BLOCK_FUNCTION(bl) (bl)->function
108#define BLOCK_SUPERBLOCK(bl) (bl)->superblock
de4f826b 109#define BLOCK_DICT(bl) (bl)->dict
22cee43f 110#define BLOCK_NAMESPACE(bl) (bl)->namespace_info
fe898f56 111
fe898f56
DC
112struct blockvector
113{
114 /* Number of blocks in the list. */
115 int nblocks;
801e3a5b
JB
116 /* An address map mapping addresses to blocks in this blockvector.
117 This pointer is zero if the blocks' start and end addresses are
118 enough. */
119 struct addrmap *map;
fe898f56
DC
120 /* The blocks themselves. */
121 struct block *block[1];
122};
123
124#define BLOCKVECTOR_NBLOCKS(blocklist) (blocklist)->nblocks
125#define BLOCKVECTOR_BLOCK(blocklist,n) (blocklist)->block[n]
801e3a5b 126#define BLOCKVECTOR_MAP(blocklist) ((blocklist)->map)
fe898f56 127
1994afbf
DE
128/* Return the objfile of BLOCK, which must be non-NULL. */
129
130extern struct objfile *block_objfile (const struct block *block);
131
132/* Return the architecture of BLOCK, which must be non-NULL. */
133
134extern struct gdbarch *block_gdbarch (const struct block *block);
135
7f0df278 136extern struct symbol *block_linkage_function (const struct block *);
fe898f56 137
f8eba3c6
TT
138extern struct symbol *block_containing_function (const struct block *);
139
edb3359d
DJ
140extern int block_inlined_p (const struct block *block);
141
0cf566ec 142extern int contained_in (const struct block *, const struct block *);
fe898f56 143
346d1dfe 144extern const struct blockvector *blockvector_for_pc (CORE_ADDR,
3977b71f 145 const struct block **);
fe898f56 146
43f3e411
DE
147extern const struct blockvector *
148 blockvector_for_pc_sect (CORE_ADDR, struct obj_section *,
149 const struct block **, struct compunit_symtab *);
fe898f56 150
346d1dfe 151extern int blockvector_contains_pc (const struct blockvector *bv, CORE_ADDR pc);
9703b513 152
8e3b41a9
JK
153extern struct call_site *call_site_for_pc (struct gdbarch *gdbarch,
154 CORE_ADDR pc);
155
3977b71f 156extern const struct block *block_for_pc (CORE_ADDR);
fe898f56 157
3977b71f 158extern const struct block *block_for_pc_sect (CORE_ADDR, struct obj_section *);
fe898f56 159
1fcb5155
DC
160extern const char *block_scope (const struct block *block);
161
9219021c
DC
162extern void block_set_scope (struct block *block, const char *scope,
163 struct obstack *obstack);
164
1fcb5155
DC
165extern struct using_direct *block_using (const struct block *block);
166
9219021c 167extern void block_set_using (struct block *block,
fe978cb0 168 struct using_direct *using_decl,
9219021c
DC
169 struct obstack *obstack);
170
89a9d1b1
DC
171extern const struct block *block_static_block (const struct block *block);
172
1fcb5155
DC
173extern const struct block *block_global_block (const struct block *block);
174
5c4e30ca
DC
175extern struct block *allocate_block (struct obstack *obstack);
176
84a146c9
TT
177extern struct block *allocate_global_block (struct obstack *obstack);
178
43f3e411
DE
179extern void set_block_compunit_symtab (struct block *,
180 struct compunit_symtab *);
8157b174
TT
181
182/* A block iterator. This structure should be treated as though it
183 were opaque; it is only defined here because we want to support
184 stack allocation of iterators. */
185
186struct block_iterator
187{
b5b04b5b 188 /* If we're iterating over a single block, this holds the block.
43f3e411 189 Otherwise, it holds the canonical compunit. */
b5b04b5b
TT
190
191 union
192 {
43f3e411 193 struct compunit_symtab *compunit_symtab;
b5b04b5b
TT
194 const struct block *block;
195 } d;
196
197 /* If we're iterating over a single block, this is always -1.
198 Otherwise, it holds the index of the current "included" symtab in
199 the canonical symtab (that is, d.symtab->includes[idx]), with -1
200 meaning the canonical symtab itself. */
201
202 int idx;
203
204 /* Which block, either static or global, to iterate over. If this
205 is FIRST_LOCAL_BLOCK, then we are iterating over a single block.
206 This is used to select which field of 'd' is in use. */
207
208 enum block_enum which;
209
8157b174
TT
210 /* The underlying dictionary iterator. */
211
212 struct dict_iterator dict_iter;
213};
214
215/* Initialize ITERATOR to point at the first symbol in BLOCK, and
216 return that first symbol, or NULL if BLOCK is empty. */
217
218extern struct symbol *block_iterator_first (const struct block *block,
219 struct block_iterator *iterator);
220
221/* Advance ITERATOR, and return the next symbol, or NULL if there are
222 no more symbols. Don't call this if you've previously received
223 NULL from block_iterator_first or block_iterator_next on this
224 iteration. */
225
226extern struct symbol *block_iterator_next (struct block_iterator *iterator);
227
228/* Initialize ITERATOR to point at the first symbol in BLOCK whose
229 SYMBOL_SEARCH_NAME is NAME (as tested using strcmp_iw), and return
230 that first symbol, or NULL if there are no such symbols. */
231
232extern struct symbol *block_iter_name_first (const struct block *block,
233 const char *name,
234 struct block_iterator *iterator);
235
236/* Advance ITERATOR to point at the next symbol in BLOCK whose
237 SYMBOL_SEARCH_NAME is NAME (as tested using strcmp_iw), or NULL if
238 there are no more such symbols. Don't call this if you've
239 previously received NULL from block_iterator_first or
240 block_iterator_next on this iteration. And don't call it unless
241 ITERATOR was created by a previous call to block_iter_name_first
242 with the same NAME. */
243
244extern struct symbol *block_iter_name_next (const char *name,
245 struct block_iterator *iterator);
246
247/* Initialize ITERATOR to point at the first symbol in BLOCK whose
248 SYMBOL_SEARCH_NAME is NAME, as tested using COMPARE (which must use
249 the same conventions as strcmp_iw and be compatible with any
250 block hashing function), and return that first symbol, or NULL
251 if there are no such symbols. */
252
253extern struct symbol *block_iter_match_first (const struct block *block,
254 const char *name,
255 symbol_compare_ftype *compare,
256 struct block_iterator *iterator);
257
258/* Advance ITERATOR to point at the next symbol in BLOCK whose
259 SYMBOL_SEARCH_NAME is NAME, as tested using COMPARE (see
260 block_iter_match_first), or NULL if there are no more such symbols.
261 Don't call this if you've previously received NULL from
262 block_iterator_match_first or block_iterator_match_next on this
263 iteration. And don't call it unless ITERATOR was created by a
264 previous call to block_iter_match_first with the same NAME and COMPARE. */
265
266extern struct symbol *block_iter_match_next (const char *name,
267 symbol_compare_ftype *compare,
268 struct block_iterator *iterator);
269
16b2eaa1
DE
270/* Search BLOCK for symbol NAME in DOMAIN. */
271
272extern struct symbol *block_lookup_symbol (const struct block *block,
273 const char *name,
274 const domain_enum domain);
275
ba715d7f
JK
276/* Search BLOCK for symbol NAME in DOMAIN but only in primary symbol table of
277 BLOCK. BLOCK must be STATIC_BLOCK or GLOBAL_BLOCK. Function is useful if
278 one iterates all global/static blocks of an objfile. */
279
280extern struct symbol *block_lookup_symbol_primary (const struct block *block,
281 const char *name,
282 const domain_enum domain);
283
b2e2f908
DE
284/* The type of the MATCHER argument to block_find_symbol. */
285
286typedef int (block_symbol_matcher_ftype) (struct symbol *, void *);
287
288/* Find symbol NAME in BLOCK and in DOMAIN that satisfies MATCHER.
289 DATA is passed unchanged to MATCHER.
290 BLOCK must be STATIC_BLOCK or GLOBAL_BLOCK. */
291
292extern struct symbol *block_find_symbol (const struct block *block,
293 const char *name,
294 const domain_enum domain,
295 block_symbol_matcher_ftype *matcher,
296 void *data);
297
298/* A matcher function for block_find_symbol to find only symbols with
299 non-opaque types. */
300
301extern int block_find_non_opaque_type (struct symbol *sym, void *data);
302
303/* A matcher function for block_find_symbol to prefer symbols with
304 non-opaque types. The way to use this function is as follows:
305
306 struct symbol *with_opaque = NULL;
307 struct symbol *sym
308 = block_find_symbol (block, name, domain,
309 block_find_non_opaque_type_preferred, &with_opaque);
310
311 At this point if SYM is non-NULL then a non-opaque type has been found.
312 Otherwise, if WITH_OPAQUE is non-NULL then an opaque type has been found.
313 Otherwise, the symbol was not found. */
314
315extern int block_find_non_opaque_type_preferred (struct symbol *sym,
316 void *data);
317
a023a30f
DE
318/* Macro to loop through all symbols in BLOCK, in no particular
319 order. ITER helps keep track of the iteration, and must be a
8157b174
TT
320 struct block_iterator. SYM points to the current symbol. */
321
322#define ALL_BLOCK_SYMBOLS(block, iter, sym) \
323 for ((sym) = block_iterator_first ((block), &(iter)); \
324 (sym); \
325 (sym) = block_iterator_next (&(iter)))
326
358d6ab3
DE
327/* Macro to loop through all symbols with name NAME in BLOCK,
328 in no particular order. ITER helps keep track of the iteration, and
329 must be a struct block_iterator. SYM points to the current symbol. */
330
331#define ALL_BLOCK_SYMBOLS_WITH_NAME(block, name, iter, sym) \
332 for ((sym) = block_iter_name_first ((block), (name), &(iter)); \
333 (sym) != NULL; \
334 (sym) = block_iter_name_next ((name), &(iter)))
335
fe898f56 336#endif /* BLOCK_H */
This page took 0.74547 seconds and 4 git commands to generate.