8334a3bca124b68c8348b79e678abb073a8f2642
1 /* Code dealing with blocks for GDB.
3 Copyright 2003 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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. */
25 /* Opaque declarations. */
29 struct block_namespace_info
;
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.
37 Each block represents one name scope.
38 Each lexical context has its own block.
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.
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.
52 The blocks appear in the blockvector
53 in order of increasing starting-address,
54 and, within that, in order of decreasing ending-address.
56 This implies that within the body of one function
57 the blocks appear in the order of a depth-first tree walk. */
62 /* Addresses in the executable code that are in this block. */
67 /* The symbol that names this block, if the block is the body of a
68 function; otherwise, zero. */
70 struct symbol
*function
;
72 /* The `struct block' for the containing block, or 0 if none.
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. */
78 struct block
*superblock
;
80 /* Used for language-specific info. */
86 /* Contains information about namespace-related info relevant to
87 this block: using directives and the current namespace
90 struct block_namespace_info
*namespace;
96 /* Version of GCC used to compile the function corresponding
97 to this block, or 0 if not compiled with GCC. When possible,
98 GCC should be compatible with the native compiler, or if that
99 is not feasible, the differences should be fixed during symbol
100 reading. As of 16 Apr 93, this flag is never used to distinguish
101 between gcc2 and the native compiler.
103 If there is no function corresponding to this block, this meaning
104 of this flag is undefined. */
106 unsigned char gcc_compile_flag
;
108 /* The symbols for this block are either in a simple linear list or
109 in a simple hashtable. Blocks which correspond to a function
110 (which have a list of symbols corresponding to arguments) use
111 a linear list, as do some older symbol readers (currently only
112 mdebugread and dstread). Other blocks are hashed.
114 The hashtable uses the same hash function as the minsym hashtables,
115 found in minsyms.c:minsym_hash_iw. Symbols are hashed based on
116 their demangled name if appropriate, and on their name otherwise.
117 The hash function ignores space, and stops at the beginning of the
118 argument list if any.
120 The table is laid out in NSYMS/5 buckets and symbols are chained via
121 their hash_next field. */
123 /* If this is really a hashtable of the symbols, this flag is 1. */
125 unsigned char hashtable
;
127 /* Number of local symbols. */
131 /* The symbols. If some of them are arguments, then they must be
132 in the order in which we would like to print them. */
134 struct symbol
*sym
[1];
137 #define BLOCK_START(bl) (bl)->startaddr
138 #define BLOCK_END(bl) (bl)->endaddr
139 #define BLOCK_FUNCTION(bl) (bl)->function
140 #define BLOCK_SUPERBLOCK(bl) (bl)->superblock
141 #define BLOCK_GCC_COMPILED(bl) (bl)->gcc_compile_flag
142 #define BLOCK_NAMESPACE(bl) (bl)->language_specific.cplus_specific.namespace
143 #define BLOCK_HASHTABLE(bl) (bl)->hashtable
145 /* For blocks without a hashtable (BLOCK_HASHTABLE (bl) == 0) only. */
146 #define BLOCK_NSYMS(bl) (bl)->nsyms
147 #define BLOCK_SYM(bl, n) (bl)->sym[n]
149 /* For blocks with a hashtable, but these are valid for non-hashed blocks as
150 well - each symbol will appear to be one bucket by itself. */
151 #define BLOCK_BUCKETS(bl) (bl)->nsyms
152 #define BLOCK_BUCKET(bl, n) (bl)->sym[n]
154 /* Macro used to set the size of a hashtable for N symbols. */
155 #define BLOCK_HASHTABLE_SIZE(n) ((n)/5 + 1)
157 /* Macro to loop through all symbols in a block BL, in no particular order.
158 i counts which bucket we are in, and sym points to the current symbol. */
160 #define ALL_BLOCK_SYMBOLS(bl, i, sym) \
161 for ((i) = 0; (i) < BLOCK_BUCKETS ((bl)); (i)++) \
162 for ((sym) = BLOCK_BUCKET ((bl), (i)); (sym); \
163 (sym) = (sym)->hash_next)
165 /* Nonzero if symbols of block BL should be sorted alphabetically.
166 Don't sort a block which corresponds to a function. If we did the
167 sorting would have to preserve the order of the symbols for the
168 arguments. Also don't sort any block that we chose to hash. */
170 #define BLOCK_SHOULD_SORT(bl) (! BLOCK_HASHTABLE (bl) \
171 && BLOCK_FUNCTION (bl) == NULL)
175 /* Number of blocks in the list. */
177 /* The blocks themselves. */
178 struct block
*block
[1];
181 #define BLOCKVECTOR_NBLOCKS(blocklist) (blocklist)->nblocks
182 #define BLOCKVECTOR_BLOCK(blocklist,n) (blocklist)->block[n]
184 /* Special block numbers */
186 #define GLOBAL_BLOCK 0
187 #define STATIC_BLOCK 1
188 #define FIRST_LOCAL_BLOCK 2
190 extern struct symbol
*block_function (const struct block
*);
192 extern int contained_in (const struct block
*, const struct block
*);
194 extern struct blockvector
*blockvector_for_pc (CORE_ADDR
, int *);
196 extern struct blockvector
*blockvector_for_pc_sect (CORE_ADDR
, asection
*,
197 int *, struct symtab
*);
199 extern struct block
*block_for_pc (CORE_ADDR
);
201 extern struct block
*block_for_pc_sect (CORE_ADDR
, asection
*);
203 extern const char *block_scope (const struct block
*block
);
205 extern void block_set_scope (struct block
*block
, const char *scope
,
206 struct obstack
*obstack
);
208 extern struct using_direct
*block_using (const struct block
*block
);
210 extern void block_set_using (struct block
*block
,
211 struct using_direct
*using,
212 struct obstack
*obstack
);
214 extern const struct block
*block_static_block (const struct block
*block
);
216 extern const struct block
*block_global_block (const struct block
*block
);
This page took 0.033037 seconds and 4 git commands to generate.