]>
Commit | Line | Data |
---|---|---|
fe898f56 DC |
1 | /* Code dealing with blocks for GDB. |
2 | ||
3 | Copyright 2003 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 2 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, write to the Free Software | |
19 | Foundation, Inc., 59 Temple Place - Suite 330, | |
20 | Boston, MA 02111-1307, USA. */ | |
21 | ||
22 | #ifndef BLOCK_H | |
23 | #define BLOCK_H | |
24 | ||
25 | /* Opaque declarations. */ | |
26 | ||
27 | struct symbol; | |
28 | struct symtab; | |
29 | ||
30 | /* All of the name-scope contours of the program | |
31 | are represented by `struct block' objects. | |
32 | All of these objects are pointed to by the blockvector. | |
33 | ||
34 | Each block represents one name scope. | |
35 | Each lexical context has its own block. | |
36 | ||
37 | The blockvector begins with some special blocks. | |
38 | The GLOBAL_BLOCK contains all the symbols defined in this compilation | |
39 | whose scope is the entire program linked together. | |
40 | The STATIC_BLOCK contains all the symbols whose scope is the | |
41 | entire compilation excluding other separate compilations. | |
42 | Blocks starting with the FIRST_LOCAL_BLOCK are not special. | |
43 | ||
44 | Each block records a range of core addresses for the code that | |
45 | is in the scope of the block. The STATIC_BLOCK and GLOBAL_BLOCK | |
46 | give, for the range of code, the entire range of code produced | |
47 | by the compilation that the symbol segment belongs to. | |
48 | ||
49 | The blocks appear in the blockvector | |
50 | in order of increasing starting-address, | |
51 | and, within that, in order of decreasing ending-address. | |
52 | ||
53 | This implies that within the body of one function | |
54 | the blocks appear in the order of a depth-first tree walk. */ | |
55 | ||
56 | struct block | |
57 | { | |
58 | ||
59 | /* Addresses in the executable code that are in this block. */ | |
60 | ||
61 | CORE_ADDR startaddr; | |
62 | CORE_ADDR endaddr; | |
63 | ||
64 | /* The symbol that names this block, if the block is the body of a | |
65 | function; otherwise, zero. */ | |
66 | ||
67 | struct symbol *function; | |
68 | ||
69 | /* The `struct block' for the containing block, or 0 if none. | |
70 | ||
71 | The superblock of a top-level local block (i.e. a function in the | |
72 | case of C) is the STATIC_BLOCK. The superblock of the | |
73 | STATIC_BLOCK is the GLOBAL_BLOCK. */ | |
74 | ||
75 | struct block *superblock; | |
76 | ||
77 | /* Version of GCC used to compile the function corresponding | |
78 | to this block, or 0 if not compiled with GCC. When possible, | |
79 | GCC should be compatible with the native compiler, or if that | |
80 | is not feasible, the differences should be fixed during symbol | |
81 | reading. As of 16 Apr 93, this flag is never used to distinguish | |
82 | between gcc2 and the native compiler. | |
83 | ||
84 | If there is no function corresponding to this block, this meaning | |
85 | of this flag is undefined. */ | |
86 | ||
87 | unsigned char gcc_compile_flag; | |
88 | ||
89 | /* The symbols for this block are either in a simple linear list or | |
90 | in a simple hashtable. Blocks which correspond to a function | |
91 | (which have a list of symbols corresponding to arguments) use | |
92 | a linear list, as do some older symbol readers (currently only | |
93 | mdebugread and dstread). Other blocks are hashed. | |
94 | ||
95 | The hashtable uses the same hash function as the minsym hashtables, | |
96 | found in minsyms.c:minsym_hash_iw. Symbols are hashed based on | |
97 | their demangled name if appropriate, and on their name otherwise. | |
98 | The hash function ignores space, and stops at the beginning of the | |
99 | argument list if any. | |
100 | ||
101 | The table is laid out in NSYMS/5 buckets and symbols are chained via | |
102 | their hash_next field. */ | |
103 | ||
104 | /* If this is really a hashtable of the symbols, this flag is 1. */ | |
105 | ||
106 | unsigned char hashtable; | |
107 | ||
108 | /* Number of local symbols. */ | |
109 | ||
110 | int nsyms; | |
111 | ||
112 | /* The symbols. If some of them are arguments, then they must be | |
113 | in the order in which we would like to print them. */ | |
114 | ||
115 | struct symbol *sym[1]; | |
116 | }; | |
117 | ||
118 | #define BLOCK_START(bl) (bl)->startaddr | |
119 | #define BLOCK_END(bl) (bl)->endaddr | |
120 | #define BLOCK_FUNCTION(bl) (bl)->function | |
121 | #define BLOCK_SUPERBLOCK(bl) (bl)->superblock | |
122 | #define BLOCK_GCC_COMPILED(bl) (bl)->gcc_compile_flag | |
123 | #define BLOCK_HASHTABLE(bl) (bl)->hashtable | |
124 | ||
125 | /* For blocks without a hashtable (BLOCK_HASHTABLE (bl) == 0) only. */ | |
126 | #define BLOCK_NSYMS(bl) (bl)->nsyms | |
127 | #define BLOCK_SYM(bl, n) (bl)->sym[n] | |
128 | ||
129 | /* For blocks with a hashtable, but these are valid for non-hashed blocks as | |
130 | well - each symbol will appear to be one bucket by itself. */ | |
131 | #define BLOCK_BUCKETS(bl) (bl)->nsyms | |
132 | #define BLOCK_BUCKET(bl, n) (bl)->sym[n] | |
133 | ||
134 | /* Macro used to set the size of a hashtable for N symbols. */ | |
135 | #define BLOCK_HASHTABLE_SIZE(n) ((n)/5 + 1) | |
136 | ||
137 | /* Macro to loop through all symbols in a block BL, in no particular order. | |
138 | i counts which bucket we are in, and sym points to the current symbol. */ | |
139 | ||
140 | #define ALL_BLOCK_SYMBOLS(bl, i, sym) \ | |
141 | for ((i) = 0; (i) < BLOCK_BUCKETS ((bl)); (i)++) \ | |
142 | for ((sym) = BLOCK_BUCKET ((bl), (i)); (sym); \ | |
143 | (sym) = (sym)->hash_next) | |
144 | ||
145 | /* Nonzero if symbols of block BL should be sorted alphabetically. | |
146 | Don't sort a block which corresponds to a function. If we did the | |
147 | sorting would have to preserve the order of the symbols for the | |
148 | arguments. Also don't sort any block that we chose to hash. */ | |
149 | ||
150 | #define BLOCK_SHOULD_SORT(bl) (! BLOCK_HASHTABLE (bl) \ | |
151 | && BLOCK_FUNCTION (bl) == NULL) | |
152 | ||
153 | struct blockvector | |
154 | { | |
155 | /* Number of blocks in the list. */ | |
156 | int nblocks; | |
157 | /* The blocks themselves. */ | |
158 | struct block *block[1]; | |
159 | }; | |
160 | ||
161 | #define BLOCKVECTOR_NBLOCKS(blocklist) (blocklist)->nblocks | |
162 | #define BLOCKVECTOR_BLOCK(blocklist,n) (blocklist)->block[n] | |
163 | ||
164 | /* Special block numbers */ | |
165 | ||
166 | #define GLOBAL_BLOCK 0 | |
167 | #define STATIC_BLOCK 1 | |
168 | #define FIRST_LOCAL_BLOCK 2 | |
169 | ||
170 | extern struct symbol *block_function (struct block *); | |
171 | ||
172 | extern int contained_in (struct block *, struct block *); | |
173 | ||
174 | extern struct blockvector *blockvector_for_pc (CORE_ADDR, int *); | |
175 | ||
176 | extern struct blockvector *blockvector_for_pc_sect (CORE_ADDR, asection *, | |
177 | int *, struct symtab *); | |
178 | ||
179 | extern struct block *block_for_pc (CORE_ADDR); | |
180 | ||
181 | extern struct block *block_for_pc_sect (CORE_ADDR, asection *); | |
182 | ||
183 | #endif /* BLOCK_H */ |