OLD | NEW |
1 /* Code dealing with blocks for GDB. | 1 /* Code dealing with blocks for GDB. |
2 | 2 |
3 Copyright (C) 2003, 2007-2012 Free Software Foundation, Inc. | 3 Copyright (C) 2003, 2007-2012 Free Software Foundation, Inc. |
4 | 4 |
5 This file is part of GDB. | 5 This file is part of GDB. |
6 | 6 |
7 This program is free software; you can redistribute it and/or modify | 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 | 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 | 9 the Free Software Foundation; either version 3 of the License, or |
10 (at your option) any later version. | 10 (at your option) any later version. |
11 | 11 |
12 This program is distributed in the hope that it will be useful, | 12 This program is distributed in the hope that it will be useful, |
13 but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 GNU General Public License for more details. | 15 GNU General Public License for more details. |
16 | 16 |
17 You should have received a copy of the GNU General Public License | 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/>. */ | 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
19 | 19 |
20 #ifndef BLOCK_H | 20 #ifndef BLOCK_H |
21 #define BLOCK_H | 21 #define BLOCK_H |
22 | 22 |
| 23 #include "dictionary.h" |
| 24 |
23 /* Opaque declarations. */ | 25 /* Opaque declarations. */ |
24 | 26 |
25 struct symbol; | 27 struct symbol; |
26 struct symtab; | 28 struct symtab; |
27 struct block_namespace_info; | 29 struct block_namespace_info; |
28 struct using_direct; | 30 struct using_direct; |
29 struct obstack; | 31 struct obstack; |
30 struct dictionary; | |
31 struct addrmap; | 32 struct addrmap; |
32 | 33 |
33 /* All of the name-scope contours of the program | 34 /* All of the name-scope contours of the program |
34 are represented by `struct block' objects. | 35 are represented by `struct block' objects. |
35 All of these objects are pointed to by the blockvector. | 36 All of these objects are pointed to by the blockvector. |
36 | 37 |
37 Each block represents one name scope. | 38 Each block represents one name scope. |
38 Each lexical context has its own block. | 39 Each lexical context has its own block. |
39 | 40 |
40 The blockvector begins with some special blocks. | 41 The blockvector begins with some special blocks. |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 this block: using directives and the current namespace | 92 this block: using directives and the current namespace |
92 scope. */ | 93 scope. */ |
93 | 94 |
94 struct block_namespace_info *namespace; | 95 struct block_namespace_info *namespace; |
95 } | 96 } |
96 cplus_specific; | 97 cplus_specific; |
97 } | 98 } |
98 language_specific; | 99 language_specific; |
99 }; | 100 }; |
100 | 101 |
| 102 /* The global block is singled out so that we can provide a back-link |
| 103 to the primary symtab. */ |
| 104 |
| 105 struct global_block |
| 106 { |
| 107 /* The block. */ |
| 108 |
| 109 struct block block; |
| 110 |
| 111 /* This holds a pointer to the primary symtab holding this |
| 112 block. */ |
| 113 |
| 114 struct symtab *symtab; |
| 115 }; |
| 116 |
101 #define BLOCK_START(bl) (bl)->startaddr | 117 #define BLOCK_START(bl) (bl)->startaddr |
102 #define BLOCK_END(bl) (bl)->endaddr | 118 #define BLOCK_END(bl) (bl)->endaddr |
103 #define BLOCK_FUNCTION(bl) (bl)->function | 119 #define BLOCK_FUNCTION(bl) (bl)->function |
104 #define BLOCK_SUPERBLOCK(bl) (bl)->superblock | 120 #define BLOCK_SUPERBLOCK(bl) (bl)->superblock |
105 #define BLOCK_DICT(bl) (bl)->dict | 121 #define BLOCK_DICT(bl) (bl)->dict |
106 #define BLOCK_NAMESPACE(bl) (bl)->language_specific.cplus_specific.namespace | 122 #define BLOCK_NAMESPACE(bl) (bl)->language_specific.cplus_specific.namespace |
107 | 123 |
108 /* Macro to loop through all symbols in a block BL, in no particular | |
109 order. ITER helps keep track of the iteration, and should be a | |
110 struct dict_iterator. SYM points to the current symbol. */ | |
111 | |
112 #define ALL_BLOCK_SYMBOLS(block, iter, sym) \ | |
113 ALL_DICT_SYMBOLS (BLOCK_DICT (block), iter, sym) | |
114 | |
115 struct blockvector | 124 struct blockvector |
116 { | 125 { |
117 /* Number of blocks in the list. */ | 126 /* Number of blocks in the list. */ |
118 int nblocks; | 127 int nblocks; |
119 /* An address map mapping addresses to blocks in this blockvector. | 128 /* An address map mapping addresses to blocks in this blockvector. |
120 This pointer is zero if the blocks' start and end addresses are | 129 This pointer is zero if the blocks' start and end addresses are |
121 enough. */ | 130 enough. */ |
122 struct addrmap *map; | 131 struct addrmap *map; |
123 /* The blocks themselves. */ | 132 /* The blocks themselves. */ |
124 struct block *block[1]; | 133 struct block *block[1]; |
(...skipping 11 matching lines...) Expand all Loading... |
136 | 145 |
137 extern int contained_in (const struct block *, const struct block *); | 146 extern int contained_in (const struct block *, const struct block *); |
138 | 147 |
139 extern struct blockvector *blockvector_for_pc (CORE_ADDR, struct block **); | 148 extern struct blockvector *blockvector_for_pc (CORE_ADDR, struct block **); |
140 | 149 |
141 extern struct blockvector *blockvector_for_pc_sect (CORE_ADDR, | 150 extern struct blockvector *blockvector_for_pc_sect (CORE_ADDR, |
142 struct obj_section *, | 151 struct obj_section *, |
143 struct block **, | 152 struct block **, |
144 struct symtab *); | 153 struct symtab *); |
145 | 154 |
| 155 extern int blockvector_contains_pc (struct blockvector *bv, CORE_ADDR pc); |
| 156 |
146 extern struct call_site *call_site_for_pc (struct gdbarch *gdbarch, | 157 extern struct call_site *call_site_for_pc (struct gdbarch *gdbarch, |
147 CORE_ADDR pc); | 158 CORE_ADDR pc); |
148 | 159 |
149 extern struct block *block_for_pc (CORE_ADDR); | 160 extern struct block *block_for_pc (CORE_ADDR); |
150 | 161 |
151 extern struct block *block_for_pc_sect (CORE_ADDR, struct obj_section *); | 162 extern struct block *block_for_pc_sect (CORE_ADDR, struct obj_section *); |
152 | 163 |
153 extern const char *block_scope (const struct block *block); | 164 extern const char *block_scope (const struct block *block); |
154 | 165 |
155 extern void block_set_scope (struct block *block, const char *scope, | 166 extern void block_set_scope (struct block *block, const char *scope, |
156 struct obstack *obstack); | 167 struct obstack *obstack); |
157 | 168 |
158 extern struct using_direct *block_using (const struct block *block); | 169 extern struct using_direct *block_using (const struct block *block); |
159 | 170 |
160 extern void block_set_using (struct block *block, | 171 extern void block_set_using (struct block *block, |
161 struct using_direct *using, | 172 struct using_direct *using, |
162 struct obstack *obstack); | 173 struct obstack *obstack); |
163 | 174 |
164 extern const struct block *block_static_block (const struct block *block); | 175 extern const struct block *block_static_block (const struct block *block); |
165 | 176 |
166 extern const struct block *block_global_block (const struct block *block); | 177 extern const struct block *block_global_block (const struct block *block); |
167 | 178 |
168 extern struct block *allocate_block (struct obstack *obstack); | 179 extern struct block *allocate_block (struct obstack *obstack); |
169 | 180 |
| 181 extern struct block *allocate_global_block (struct obstack *obstack); |
| 182 |
| 183 extern void set_block_symtab (struct block *, struct symtab *); |
| 184 |
| 185 /* A block iterator. This structure should be treated as though it |
| 186 were opaque; it is only defined here because we want to support |
| 187 stack allocation of iterators. */ |
| 188 |
| 189 struct block_iterator |
| 190 { |
| 191 /* If we're iterating over a single block, this holds the block. |
| 192 Otherwise, it holds the canonical symtab. */ |
| 193 |
| 194 union |
| 195 { |
| 196 struct symtab *symtab; |
| 197 const struct block *block; |
| 198 } d; |
| 199 |
| 200 /* If we're iterating over a single block, this is always -1. |
| 201 Otherwise, it holds the index of the current "included" symtab in |
| 202 the canonical symtab (that is, d.symtab->includes[idx]), with -1 |
| 203 meaning the canonical symtab itself. */ |
| 204 |
| 205 int idx; |
| 206 |
| 207 /* Which block, either static or global, to iterate over. If this |
| 208 is FIRST_LOCAL_BLOCK, then we are iterating over a single block. |
| 209 This is used to select which field of 'd' is in use. */ |
| 210 |
| 211 enum block_enum which; |
| 212 |
| 213 /* The underlying dictionary iterator. */ |
| 214 |
| 215 struct dict_iterator dict_iter; |
| 216 }; |
| 217 |
| 218 /* Initialize ITERATOR to point at the first symbol in BLOCK, and |
| 219 return that first symbol, or NULL if BLOCK is empty. */ |
| 220 |
| 221 extern struct symbol *block_iterator_first (const struct block *block, |
| 222 struct block_iterator *iterator); |
| 223 |
| 224 /* Advance ITERATOR, and return the next symbol, or NULL if there are |
| 225 no more symbols. Don't call this if you've previously received |
| 226 NULL from block_iterator_first or block_iterator_next on this |
| 227 iteration. */ |
| 228 |
| 229 extern struct symbol *block_iterator_next (struct block_iterator *iterator); |
| 230 |
| 231 /* Initialize ITERATOR to point at the first symbol in BLOCK whose |
| 232 SYMBOL_SEARCH_NAME is NAME (as tested using strcmp_iw), and return |
| 233 that first symbol, or NULL if there are no such symbols. */ |
| 234 |
| 235 extern struct symbol *block_iter_name_first (const struct block *block, |
| 236 const char *name, |
| 237 struct block_iterator *iterator); |
| 238 |
| 239 /* Advance ITERATOR to point at the next symbol in BLOCK whose |
| 240 SYMBOL_SEARCH_NAME is NAME (as tested using strcmp_iw), or NULL if |
| 241 there are no more such symbols. Don't call this if you've |
| 242 previously received NULL from block_iterator_first or |
| 243 block_iterator_next on this iteration. And don't call it unless |
| 244 ITERATOR was created by a previous call to block_iter_name_first |
| 245 with the same NAME. */ |
| 246 |
| 247 extern struct symbol *block_iter_name_next (const char *name, |
| 248 struct block_iterator *iterator); |
| 249 |
| 250 /* Initialize ITERATOR to point at the first symbol in BLOCK whose |
| 251 SYMBOL_SEARCH_NAME is NAME, as tested using COMPARE (which must use |
| 252 the same conventions as strcmp_iw and be compatible with any |
| 253 block hashing function), and return that first symbol, or NULL |
| 254 if there are no such symbols. */ |
| 255 |
| 256 extern struct symbol *block_iter_match_first (const struct block *block, |
| 257 const char *name, |
| 258 symbol_compare_ftype *compare, |
| 259 struct block_iterator *iterator); |
| 260 |
| 261 /* Advance ITERATOR to point at the next symbol in BLOCK whose |
| 262 SYMBOL_SEARCH_NAME is NAME, as tested using COMPARE (see |
| 263 block_iter_match_first), or NULL if there are no more such symbols. |
| 264 Don't call this if you've previously received NULL from |
| 265 block_iterator_match_first or block_iterator_match_next on this |
| 266 iteration. And don't call it unless ITERATOR was created by a |
| 267 previous call to block_iter_match_first with the same NAME and COMPARE. */ |
| 268 |
| 269 extern struct symbol *block_iter_match_next (const char *name, |
| 270 symbol_compare_ftype *compare, |
| 271 struct block_iterator *iterator); |
| 272 |
| 273 /* Macro to loop through all symbols in a block BL, in no particular |
| 274 order. ITER helps keep track of the iteration, and should be a |
| 275 struct block_iterator. SYM points to the current symbol. */ |
| 276 |
| 277 #define ALL_BLOCK_SYMBOLS(block, iter, sym) \ |
| 278 for ((sym) = block_iterator_first ((block), &(iter)); \ |
| 279 (sym); \ |
| 280 (sym) = block_iterator_next (&(iter))) |
| 281 |
170 #endif /* BLOCK_H */ | 282 #endif /* BLOCK_H */ |
OLD | NEW |