Commit | Line | Data |
---|---|---|
fe898f56 DC |
1 | /* Code dealing with blocks for GDB. |
2 | ||
0b302171 | 3 | Copyright (C) 2003, 2007-2012 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 | ||
27 | struct symbol; | |
28 | struct symtab; | |
9219021c DC |
29 | struct block_namespace_info; |
30 | struct using_direct; | |
31 | struct obstack; | |
801e3a5b | 32 | struct 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 | ||
60 | struct 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 | ||
9219021c DC |
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 | ||
95 | struct block_namespace_info *namespace; | |
96 | } | |
97 | cplus_specific; | |
98 | } | |
99 | language_specific; | |
fe898f56 DC |
100 | }; |
101 | ||
102 | #define BLOCK_START(bl) (bl)->startaddr | |
103 | #define BLOCK_END(bl) (bl)->endaddr | |
104 | #define BLOCK_FUNCTION(bl) (bl)->function | |
105 | #define BLOCK_SUPERBLOCK(bl) (bl)->superblock | |
de4f826b | 106 | #define BLOCK_DICT(bl) (bl)->dict |
9219021c | 107 | #define BLOCK_NAMESPACE(bl) (bl)->language_specific.cplus_specific.namespace |
fe898f56 | 108 | |
fe898f56 DC |
109 | struct blockvector |
110 | { | |
111 | /* Number of blocks in the list. */ | |
112 | int nblocks; | |
801e3a5b JB |
113 | /* An address map mapping addresses to blocks in this blockvector. |
114 | This pointer is zero if the blocks' start and end addresses are | |
115 | enough. */ | |
116 | struct addrmap *map; | |
fe898f56 DC |
117 | /* The blocks themselves. */ |
118 | struct block *block[1]; | |
119 | }; | |
120 | ||
121 | #define BLOCKVECTOR_NBLOCKS(blocklist) (blocklist)->nblocks | |
122 | #define BLOCKVECTOR_BLOCK(blocklist,n) (blocklist)->block[n] | |
801e3a5b | 123 | #define BLOCKVECTOR_MAP(blocklist) ((blocklist)->map) |
fe898f56 | 124 | |
7f0df278 | 125 | extern struct symbol *block_linkage_function (const struct block *); |
fe898f56 | 126 | |
f8eba3c6 TT |
127 | extern struct symbol *block_containing_function (const struct block *); |
128 | ||
edb3359d DJ |
129 | extern int block_inlined_p (const struct block *block); |
130 | ||
0cf566ec | 131 | extern int contained_in (const struct block *, const struct block *); |
fe898f56 | 132 | |
801e3a5b | 133 | extern struct blockvector *blockvector_for_pc (CORE_ADDR, struct block **); |
fe898f56 | 134 | |
714835d5 UW |
135 | extern struct blockvector *blockvector_for_pc_sect (CORE_ADDR, |
136 | struct obj_section *, | |
801e3a5b JB |
137 | struct block **, |
138 | struct symtab *); | |
fe898f56 | 139 | |
8e3b41a9 JK |
140 | extern struct call_site *call_site_for_pc (struct gdbarch *gdbarch, |
141 | CORE_ADDR pc); | |
142 | ||
fe898f56 DC |
143 | extern struct block *block_for_pc (CORE_ADDR); |
144 | ||
714835d5 | 145 | extern struct block *block_for_pc_sect (CORE_ADDR, struct obj_section *); |
fe898f56 | 146 | |
1fcb5155 DC |
147 | extern const char *block_scope (const struct block *block); |
148 | ||
9219021c DC |
149 | extern void block_set_scope (struct block *block, const char *scope, |
150 | struct obstack *obstack); | |
151 | ||
1fcb5155 DC |
152 | extern struct using_direct *block_using (const struct block *block); |
153 | ||
9219021c DC |
154 | extern void block_set_using (struct block *block, |
155 | struct using_direct *using, | |
156 | struct obstack *obstack); | |
157 | ||
89a9d1b1 DC |
158 | extern const struct block *block_static_block (const struct block *block); |
159 | ||
1fcb5155 DC |
160 | extern const struct block *block_global_block (const struct block *block); |
161 | ||
5c4e30ca DC |
162 | extern struct block *allocate_block (struct obstack *obstack); |
163 | ||
8157b174 TT |
164 | |
165 | /* A block iterator. This structure should be treated as though it | |
166 | were opaque; it is only defined here because we want to support | |
167 | stack allocation of iterators. */ | |
168 | ||
169 | struct block_iterator | |
170 | { | |
171 | /* The underlying dictionary iterator. */ | |
172 | ||
173 | struct dict_iterator dict_iter; | |
174 | }; | |
175 | ||
176 | /* Initialize ITERATOR to point at the first symbol in BLOCK, and | |
177 | return that first symbol, or NULL if BLOCK is empty. */ | |
178 | ||
179 | extern struct symbol *block_iterator_first (const struct block *block, | |
180 | struct block_iterator *iterator); | |
181 | ||
182 | /* Advance ITERATOR, and return the next symbol, or NULL if there are | |
183 | no more symbols. Don't call this if you've previously received | |
184 | NULL from block_iterator_first or block_iterator_next on this | |
185 | iteration. */ | |
186 | ||
187 | extern struct symbol *block_iterator_next (struct block_iterator *iterator); | |
188 | ||
189 | /* Initialize ITERATOR to point at the first symbol in BLOCK whose | |
190 | SYMBOL_SEARCH_NAME is NAME (as tested using strcmp_iw), and return | |
191 | that first symbol, or NULL if there are no such symbols. */ | |
192 | ||
193 | extern struct symbol *block_iter_name_first (const struct block *block, | |
194 | const char *name, | |
195 | struct block_iterator *iterator); | |
196 | ||
197 | /* Advance ITERATOR to point at the next symbol in BLOCK whose | |
198 | SYMBOL_SEARCH_NAME is NAME (as tested using strcmp_iw), or NULL if | |
199 | there are no more such symbols. Don't call this if you've | |
200 | previously received NULL from block_iterator_first or | |
201 | block_iterator_next on this iteration. And don't call it unless | |
202 | ITERATOR was created by a previous call to block_iter_name_first | |
203 | with the same NAME. */ | |
204 | ||
205 | extern struct symbol *block_iter_name_next (const char *name, | |
206 | struct block_iterator *iterator); | |
207 | ||
208 | /* Initialize ITERATOR to point at the first symbol in BLOCK whose | |
209 | SYMBOL_SEARCH_NAME is NAME, as tested using COMPARE (which must use | |
210 | the same conventions as strcmp_iw and be compatible with any | |
211 | block hashing function), and return that first symbol, or NULL | |
212 | if there are no such symbols. */ | |
213 | ||
214 | extern struct symbol *block_iter_match_first (const struct block *block, | |
215 | const char *name, | |
216 | symbol_compare_ftype *compare, | |
217 | struct block_iterator *iterator); | |
218 | ||
219 | /* Advance ITERATOR to point at the next symbol in BLOCK whose | |
220 | SYMBOL_SEARCH_NAME is NAME, as tested using COMPARE (see | |
221 | block_iter_match_first), or NULL if there are no more such symbols. | |
222 | Don't call this if you've previously received NULL from | |
223 | block_iterator_match_first or block_iterator_match_next on this | |
224 | iteration. And don't call it unless ITERATOR was created by a | |
225 | previous call to block_iter_match_first with the same NAME and COMPARE. */ | |
226 | ||
227 | extern struct symbol *block_iter_match_next (const char *name, | |
228 | symbol_compare_ftype *compare, | |
229 | struct block_iterator *iterator); | |
230 | ||
231 | /* Macro to loop through all symbols in a block BL, in no particular | |
232 | order. ITER helps keep track of the iteration, and should be a | |
233 | struct block_iterator. SYM points to the current symbol. */ | |
234 | ||
235 | #define ALL_BLOCK_SYMBOLS(block, iter, sym) \ | |
236 | for ((sym) = block_iterator_first ((block), &(iter)); \ | |
237 | (sym); \ | |
238 | (sym) = block_iterator_next (&(iter))) | |
239 | ||
fe898f56 | 240 | #endif /* BLOCK_H */ |