Support lexical blocks and function bodies that occupy
[external/binutils.git] / gdb / buildsym.h
1 /* Build symbol tables in GDB's internal format.
2    Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1995, 1996,
3    1997, 1998, 1999, 2000, 2002, 2003, 2007 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 3 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, see <http://www.gnu.org/licenses/>.  */
19
20 #if !defined (BUILDSYM_H)
21 #define BUILDSYM_H 1
22
23 struct objfile;
24 struct symbol;
25 struct addrmap;
26
27 /* This module provides definitions used for creating and adding to
28    the symbol table.  These routines are called from various symbol-
29    file-reading routines.
30
31    They originated in dbxread.c of gdb-4.2, and were split out to
32    make xcoffread.c more maintainable by sharing code.
33
34    Variables declared in this file can be defined by #define-ing the
35    name EXTERN to null.  It is used to declare variables that are
36    normally extern, but which get defined in a single module using
37    this technique.  */
38
39 struct block;
40
41 #ifndef EXTERN
42 #define EXTERN extern
43 #endif
44
45 #define HASHSIZE 127            /* Size of things hashed via
46                                    hashname() */
47
48 /* Name of source file whose symbol data we are now processing.  This
49    comes from a symbol of type N_SO. */
50
51 EXTERN char *last_source_file;
52
53 /* Core address of start of text of current source file.  This too
54    comes from the N_SO symbol. */
55
56 EXTERN CORE_ADDR last_source_start_addr;
57
58 /* The list of sub-source-files within the current individual
59    compilation.  Each file gets its own symtab with its own linetable
60    and associated info, but they all share one blockvector.  */
61
62 struct subfile
63   {
64     struct subfile *next;
65     char *name;
66     char *dirname;
67     struct linetable *line_vector;
68     int line_vector_length;
69     enum language language;
70     char *producer;
71     char *debugformat;
72     struct symtab *symtab;
73   };
74
75 EXTERN struct subfile *current_subfile;
76
77 /* Global variable which, when set, indicates that we are processing a
78    .o file compiled with gcc */
79
80 EXTERN unsigned char processing_gcc_compilation;
81
82 /* When set, we are processing a .o file compiled by sun acc.  This is
83    misnamed; it refers to all stabs-in-elf implementations which use
84    N_UNDF the way Sun does, including Solaris gcc.  Hopefully all
85    stabs-in-elf implementations ever invented will choose to be
86    compatible.  */
87
88 EXTERN unsigned char processing_acc_compilation;
89
90 /* Count symbols as they are processed, for error messages.  */
91
92 EXTERN unsigned int symnum;
93
94 /* Record the symbols defined for each context in a list.  We don't
95    create a struct block for the context until we know how long to
96    make it.  */
97
98 #define PENDINGSIZE 100
99
100 struct pending
101   {
102     struct pending *next;
103     int nsyms;
104     struct symbol *symbol[PENDINGSIZE];
105   };
106
107 /* Here are the three lists that symbols are put on.  */
108
109 /* static at top level, and types */
110
111 EXTERN struct pending *file_symbols;
112
113 /* global functions and variables */
114
115 EXTERN struct pending *global_symbols;
116
117 /* everything local to lexical context */
118
119 EXTERN struct pending *local_symbols;
120
121 /* func params local to lexical  context */
122
123 EXTERN struct pending *param_symbols;
124
125 /* Stack representing unclosed lexical contexts (that will become
126    blocks, eventually).  */
127
128 struct context_stack
129   {
130     /* Outer locals at the time we entered */
131
132     struct pending *locals;
133
134     /* Pending func params at the time we entered */
135
136     struct pending *params;
137
138     /* Pointer into blocklist as of entry */
139
140     struct pending_block *old_blocks;
141
142     /* Name of function, if any, defining context */
143
144     struct symbol *name;
145
146     /* PC where this context starts */
147
148     CORE_ADDR start_addr;
149
150     /* Temp slot for exception handling. */
151
152     CORE_ADDR end_addr;
153
154     /* For error-checking matching push/pop */
155
156     int depth;
157
158   };
159
160 EXTERN struct context_stack *context_stack;
161
162 /* Index of first unused entry in context stack.  */
163
164 EXTERN int context_stack_depth;
165
166 /* Currently allocated size of context stack.  */
167
168 EXTERN int context_stack_size;
169
170 /* Non-zero if the context stack is empty.  */
171 #define outermost_context_p() (context_stack_depth == 0)
172
173 /* Nonzero if within a function (so symbols should be local, if
174    nothing says specifically).  */
175
176 EXTERN int within_function;
177
178 /* List of blocks already made (lexical contexts already closed).
179    This is used at the end to make the blockvector.  */
180
181 struct pending_block
182   {
183     struct pending_block *next;
184     struct block *block;
185   };
186
187 /* Pointer to the head of a linked list of symbol blocks which have
188    already been finalized (lexical contexts already closed) and which
189    are just waiting to be built into a blockvector when finalizing the
190    associated symtab. */
191
192 EXTERN struct pending_block *pending_blocks;
193 \f
194
195 struct subfile_stack
196   {
197     struct subfile_stack *next;
198     char *name;
199   };
200
201 EXTERN struct subfile_stack *subfile_stack;
202
203 #define next_symbol_text(objfile) (*next_symbol_text_func)(objfile)
204
205 /* Function to invoke get the next symbol.  Return the symbol name. */
206
207 EXTERN char *(*next_symbol_text_func) (struct objfile *);
208
209 /* Vector of types defined so far, indexed by their type numbers.
210    Used for both stabs and coff.  (In newer sun systems, dbx uses a
211    pair of numbers in parens, as in "(SUBFILENUM,NUMWITHINSUBFILE)".
212    Then these numbers must be translated through the type_translations
213    hash table to get the index into the type vector.)  */
214
215 EXTERN struct type **type_vector;
216
217 /* Number of elements allocated for type_vector currently.  */
218
219 EXTERN int type_vector_length;
220
221 /* Initial size of type vector.  Is realloc'd larger if needed, and
222    realloc'd down to the size actually used, when completed.  */
223
224 #define INITIAL_TYPE_VECTOR_LENGTH      160
225
226 extern void add_free_pendings (struct pending *list);
227
228 extern void add_symbol_to_list (struct symbol *symbol,
229                                 struct pending **listhead);
230
231 extern struct symbol *find_symbol_in_list (struct pending *list,
232                                            char *name, int length);
233
234 extern struct block *finish_block (struct symbol *symbol,
235                                    struct pending **listhead,
236                                    struct pending_block *old_blocks,
237                                    CORE_ADDR start, CORE_ADDR end,
238                                    struct objfile *objfile);
239
240 extern void record_block_range (struct block *,
241                                 CORE_ADDR start, CORE_ADDR end_inclusive);
242
243 extern void really_free_pendings (void *dummy);
244
245 extern void start_subfile (char *name, char *dirname);
246
247 extern void patch_subfile_names (struct subfile *subfile, char *name);
248
249 extern void push_subfile (void);
250
251 extern char *pop_subfile (void);
252
253 extern struct symtab *end_symtab (CORE_ADDR end_addr,
254                                   struct objfile *objfile, int section);
255
256 /* Defined in stabsread.c.  */
257
258 extern void scan_file_globals (struct objfile *objfile);
259
260 extern void buildsym_new_init (void);
261
262 extern void buildsym_init (void);
263
264 extern struct context_stack *push_context (int desc, CORE_ADDR valu);
265
266 extern struct context_stack *pop_context (void);
267
268 extern void record_line (struct subfile *subfile, int line, CORE_ADDR pc);
269
270 extern void start_symtab (char *name, char *dirname, CORE_ADDR start_addr);
271
272 extern int hashname (char *name);
273
274 extern void free_pending_blocks (void);
275
276 /* FIXME: Note that this is used only in buildsym.c and dstread.c,
277    which should be fixed to not need direct access to
278    record_pending_block. */
279
280 extern void record_pending_block (struct objfile *objfile,
281                                   struct block *block,
282                                   struct pending_block *opblock);
283
284 extern void record_debugformat (char *format);
285
286 extern void record_producer (const char *producer);
287
288 extern void merge_symbol_lists (struct pending **srclist,
289                                 struct pending **targetlist);
290
291 /* The macro table for the compilation unit whose symbols we're
292    currently reading.  All the symtabs for this CU will point to this.  */
293 EXTERN struct macro_table *pending_macros;
294
295 #undef EXTERN
296
297 #endif /* defined (BUILDSYM_H) */