Commit | Line | Data |
---|---|---|
fe898f56 DC |
1 | /* Code dealing with blocks for GDB. |
2 | ||
0fb0cc75 | 3 | Copyright (C) 2003, 2007, 2008, 2009 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 | ||
23 | /* Opaque declarations. */ | |
24 | ||
25 | struct symbol; | |
26 | struct symtab; | |
9219021c DC |
27 | struct block_namespace_info; |
28 | struct using_direct; | |
29 | struct obstack; | |
de4f826b | 30 | struct dictionary; |
801e3a5b | 31 | struct addrmap; |
fe898f56 DC |
32 | |
33 | /* All of the name-scope contours of the program | |
34 | are represented by `struct block' objects. | |
35 | All of these objects are pointed to by the blockvector. | |
36 | ||
37 | Each block represents one name scope. | |
38 | Each lexical context has its own block. | |
39 | ||
40 | The blockvector begins with some special blocks. | |
41 | The GLOBAL_BLOCK contains all the symbols defined in this compilation | |
42 | whose scope is the entire program linked together. | |
43 | The STATIC_BLOCK contains all the symbols whose scope is the | |
44 | entire compilation excluding other separate compilations. | |
45 | Blocks starting with the FIRST_LOCAL_BLOCK are not special. | |
46 | ||
47 | Each block records a range of core addresses for the code that | |
48 | is in the scope of the block. The STATIC_BLOCK and GLOBAL_BLOCK | |
49 | give, for the range of code, the entire range of code produced | |
50 | by the compilation that the symbol segment belongs to. | |
51 | ||
52 | The blocks appear in the blockvector | |
53 | in order of increasing starting-address, | |
54 | and, within that, in order of decreasing ending-address. | |
55 | ||
56 | This implies that within the body of one function | |
57 | the blocks appear in the order of a depth-first tree walk. */ | |
58 | ||
59 | struct block | |
60 | { | |
61 | ||
62 | /* Addresses in the executable code that are in this block. */ | |
63 | ||
64 | CORE_ADDR startaddr; | |
65 | CORE_ADDR endaddr; | |
66 | ||
67 | /* The symbol that names this block, if the block is the body of a | |
68 | function; otherwise, zero. */ | |
69 | ||
70 | struct symbol *function; | |
71 | ||
72 | /* The `struct block' for the containing block, or 0 if none. | |
73 | ||
74 | The superblock of a top-level local block (i.e. a function in the | |
75 | case of C) is the STATIC_BLOCK. The superblock of the | |
76 | STATIC_BLOCK is the GLOBAL_BLOCK. */ | |
77 | ||
78 | struct block *superblock; | |
79 | ||
de4f826b DC |
80 | /* This is used to store the symbols in the block. */ |
81 | ||
82 | struct dictionary *dict; | |
83 | ||
9219021c DC |
84 | /* Used for language-specific info. */ |
85 | ||
86 | union | |
87 | { | |
88 | struct | |
89 | { | |
90 | /* Contains information about namespace-related info relevant to | |
91 | this block: using directives and the current namespace | |
92 | scope. */ | |
93 | ||
94 | struct block_namespace_info *namespace; | |
95 | } | |
96 | cplus_specific; | |
97 | } | |
98 | language_specific; | |
fe898f56 DC |
99 | }; |
100 | ||
101 | #define BLOCK_START(bl) (bl)->startaddr | |
102 | #define BLOCK_END(bl) (bl)->endaddr | |
103 | #define BLOCK_FUNCTION(bl) (bl)->function | |
104 | #define BLOCK_SUPERBLOCK(bl) (bl)->superblock | |
de4f826b | 105 | #define BLOCK_DICT(bl) (bl)->dict |
9219021c | 106 | #define BLOCK_NAMESPACE(bl) (bl)->language_specific.cplus_specific.namespace |
fe898f56 | 107 | |
de4f826b DC |
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. */ | |
fe898f56 | 111 | |
de4f826b DC |
112 | #define ALL_BLOCK_SYMBOLS(block, iter, sym) \ |
113 | ALL_DICT_SYMBOLS (BLOCK_DICT (block), iter, sym) | |
fe898f56 | 114 | |
fe898f56 DC |
115 | struct blockvector |
116 | { | |
117 | /* Number of blocks in the list. */ | |
118 | int nblocks; | |
801e3a5b JB |
119 | /* An address map mapping addresses to blocks in this blockvector. |
120 | This pointer is zero if the blocks' start and end addresses are | |
121 | enough. */ | |
122 | struct addrmap *map; | |
fe898f56 DC |
123 | /* The blocks themselves. */ |
124 | struct block *block[1]; | |
125 | }; | |
126 | ||
127 | #define BLOCKVECTOR_NBLOCKS(blocklist) (blocklist)->nblocks | |
128 | #define BLOCKVECTOR_BLOCK(blocklist,n) (blocklist)->block[n] | |
801e3a5b | 129 | #define BLOCKVECTOR_MAP(blocklist) ((blocklist)->map) |
fe898f56 DC |
130 | |
131 | /* Special block numbers */ | |
132 | ||
887432a5 | 133 | enum { GLOBAL_BLOCK = 0, STATIC_BLOCK = 1, FIRST_LOCAL_BLOCK = 2 }; |
fe898f56 | 134 | |
7f0df278 | 135 | extern struct symbol *block_linkage_function (const struct block *); |
fe898f56 | 136 | |
0cf566ec | 137 | extern int contained_in (const struct block *, const struct block *); |
fe898f56 | 138 | |
801e3a5b | 139 | extern struct blockvector *blockvector_for_pc (CORE_ADDR, struct block **); |
fe898f56 | 140 | |
714835d5 UW |
141 | extern struct blockvector *blockvector_for_pc_sect (CORE_ADDR, |
142 | struct obj_section *, | |
801e3a5b JB |
143 | struct block **, |
144 | struct symtab *); | |
fe898f56 DC |
145 | |
146 | extern struct block *block_for_pc (CORE_ADDR); | |
147 | ||
714835d5 | 148 | extern struct block *block_for_pc_sect (CORE_ADDR, struct obj_section *); |
fe898f56 | 149 | |
1fcb5155 DC |
150 | extern const char *block_scope (const struct block *block); |
151 | ||
9219021c DC |
152 | extern void block_set_scope (struct block *block, const char *scope, |
153 | struct obstack *obstack); | |
154 | ||
1fcb5155 DC |
155 | extern struct using_direct *block_using (const struct block *block); |
156 | ||
9219021c DC |
157 | extern void block_set_using (struct block *block, |
158 | struct using_direct *using, | |
159 | struct obstack *obstack); | |
160 | ||
89a9d1b1 DC |
161 | extern const struct block *block_static_block (const struct block *block); |
162 | ||
1fcb5155 DC |
163 | extern const struct block *block_global_block (const struct block *block); |
164 | ||
5c4e30ca DC |
165 | extern struct block *allocate_block (struct obstack *obstack); |
166 | ||
fe898f56 | 167 | #endif /* BLOCK_H */ |