xref: /dragonfly/contrib/gdb-7/gdb/block.h (revision 6e278935)
1 /* Code dealing with blocks for GDB.
2 
3    Copyright (C) 2003, 2007, 2008, 2009, 2010, 2011
4    Free Software Foundation, Inc.
5 
6    This file is part of GDB.
7 
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 3 of the License, or
11    (at your option) any later version.
12 
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17 
18    You should have received a copy of the GNU General Public License
19    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
20 
21 #ifndef BLOCK_H
22 #define BLOCK_H
23 
24 /* Opaque declarations.  */
25 
26 struct symbol;
27 struct symtab;
28 struct block_namespace_info;
29 struct using_direct;
30 struct obstack;
31 struct dictionary;
32 struct addrmap;
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
69      function (real or inlined); otherwise, zero.  */
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 
81   /* This is used to store the symbols in the block.  */
82 
83   struct dictionary *dict;
84 
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;
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
106 #define BLOCK_DICT(bl)		(bl)->dict
107 #define BLOCK_NAMESPACE(bl)   (bl)->language_specific.cplus_specific.namespace
108 
109 /* Macro to loop through all symbols in a block BL, in no particular
110    order.  ITER helps keep track of the iteration, and should be a
111    struct dict_iterator.  SYM points to the current symbol.  */
112 
113 #define ALL_BLOCK_SYMBOLS(block, iter, sym)			\
114 	ALL_DICT_SYMBOLS (BLOCK_DICT (block), iter, sym)
115 
116 struct blockvector
117 {
118   /* Number of blocks in the list.  */
119   int nblocks;
120   /* An address map mapping addresses to blocks in this blockvector.
121      This pointer is zero if the blocks' start and end addresses are
122      enough.  */
123   struct addrmap *map;
124   /* The blocks themselves.  */
125   struct block *block[1];
126 };
127 
128 #define BLOCKVECTOR_NBLOCKS(blocklist) (blocklist)->nblocks
129 #define BLOCKVECTOR_BLOCK(blocklist,n) (blocklist)->block[n]
130 #define BLOCKVECTOR_MAP(blocklist) ((blocklist)->map)
131 
132 /* Special block numbers */
133 
134 enum { GLOBAL_BLOCK = 0, STATIC_BLOCK = 1, FIRST_LOCAL_BLOCK = 2 };
135 
136 extern struct symbol *block_linkage_function (const struct block *);
137 
138 extern int block_inlined_p (const struct block *block);
139 
140 extern int contained_in (const struct block *, const struct block *);
141 
142 extern struct blockvector *blockvector_for_pc (CORE_ADDR, struct block **);
143 
144 extern struct blockvector *blockvector_for_pc_sect (CORE_ADDR,
145 						    struct obj_section *,
146 						    struct block **,
147                                                     struct symtab *);
148 
149 extern struct block *block_for_pc (CORE_ADDR);
150 
151 extern struct block *block_for_pc_sect (CORE_ADDR, struct obj_section *);
152 
153 extern const char *block_scope (const struct block *block);
154 
155 extern void block_set_scope (struct block *block, const char *scope,
156 			     struct obstack *obstack);
157 
158 extern struct using_direct *block_using (const struct block *block);
159 
160 extern void block_set_using (struct block *block,
161 			     struct using_direct *using,
162 			     struct obstack *obstack);
163 
164 extern const struct block *block_static_block (const struct block *block);
165 
166 extern const struct block *block_global_block (const struct block *block);
167 
168 extern struct block *allocate_block (struct obstack *obstack);
169 
170 #endif /* BLOCK_H */
171