Move some code from buildsym to stabsread
[external/binutils.git] / gdb / buildsym.h
1 /* Build symbol tables in GDB's internal format.
2    Copyright (C) 1986-2018 Free Software Foundation, Inc.
3
4    This file is part of GDB.
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 3 of the License, or
9    (at your option) any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
18
19 #if !defined (BUILDSYM_H)
20 #define BUILDSYM_H 1
21
22 struct objfile;
23 struct symbol;
24 struct addrmap;
25 struct compunit_symtab;
26 enum language;
27
28 /* This module provides definitions used for creating and adding to
29    the symbol table.  These routines are called from various symbol-
30    file-reading routines.
31
32    They originated in dbxread.c of gdb-4.2, and were split out to
33    make xcoffread.c more maintainable by sharing code.
34
35    Variables declared in this file can be defined by #define-ing the
36    name EXTERN to null.  It is used to declare variables that are
37    normally extern, but which get defined in a single module using
38    this technique.  */
39
40 struct block;
41 struct pending_block;
42
43 struct dynamic_prop;
44
45 #ifndef EXTERN
46 #define EXTERN extern
47 #endif
48
49 /* The list of sub-source-files within the current individual
50    compilation.  Each file gets its own symtab with its own linetable
51    and associated info, but they all share one blockvector.  */
52
53 struct subfile
54 {
55   struct subfile *next;
56   /* Space for this is malloc'd.  */
57   char *name;
58   /* Space for this is malloc'd.  */
59   struct linetable *line_vector;
60   int line_vector_length;
61   /* The "containing" compunit.  */
62   struct buildsym_compunit *buildsym_compunit;
63   enum language language;
64   struct symtab *symtab;
65 };
66
67 EXTERN struct subfile *current_subfile;
68
69 /* Global variable which, when set, indicates that we are processing a
70    .o file compiled with gcc */
71
72 EXTERN unsigned char processing_gcc_compilation;
73
74 /* Record the symbols defined for each context in a list.  We don't
75    create a struct block for the context until we know how long to
76    make it.  */
77
78 #define PENDINGSIZE 100
79
80 struct pending
81   {
82     struct pending *next;
83     int nsyms;
84     struct symbol *symbol[PENDINGSIZE];
85   };
86
87 /* Here are the three lists that symbols are put on.  */
88
89 /* static at top level, and types */
90
91 EXTERN struct pending *file_symbols;
92
93 /* global functions and variables */
94
95 EXTERN struct pending *global_symbols;
96
97 /* everything local to lexical context */
98
99 EXTERN struct pending *local_symbols;
100
101 /* "using" directives local to lexical context.  */
102
103 EXTERN struct using_direct *local_using_directives;
104
105 /* global "using" directives.  */
106
107 EXTERN struct using_direct *global_using_directives;
108
109 /* Stack representing unclosed lexical contexts (that will become
110    blocks, eventually).  */
111
112 struct context_stack
113   {
114     /* Outer locals at the time we entered */
115
116     struct pending *locals;
117
118     /* Pending using directives at the time we entered.  */
119
120     struct using_direct *local_using_directives;
121
122     /* Pointer into blocklist as of entry */
123
124     struct pending_block *old_blocks;
125
126     /* Name of function, if any, defining context */
127
128     struct symbol *name;
129
130     /* Expression that computes the frame base of the lexically enclosing
131        function, if any.  NULL otherwise.  */
132
133     struct dynamic_prop *static_link;
134
135     /* PC where this context starts */
136
137     CORE_ADDR start_addr;
138
139     /* Temp slot for exception handling.  */
140
141     CORE_ADDR end_addr;
142
143     /* For error-checking matching push/pop */
144
145     int depth;
146
147   };
148
149 EXTERN struct context_stack *context_stack;
150
151 /* Index of first unused entry in context stack.  */
152
153 EXTERN int context_stack_depth;
154
155 /* Non-zero if the context stack is empty.  */
156 #define outermost_context_p() (context_stack_depth == 0)
157
158 /* Nonzero if within a function (so symbols should be local, if
159    nothing says specifically).  */
160
161 EXTERN int within_function;
162
163 /* The type of the record_line function.  */
164 typedef void (record_line_ftype) (struct subfile *subfile, int line,
165                                   CORE_ADDR pc);
166
167 \f
168
169 extern void add_symbol_to_list (struct symbol *symbol,
170                                 struct pending **listhead);
171
172 extern struct symbol *find_symbol_in_list (struct pending *list,
173                                            char *name, int length);
174
175 extern struct block *finish_block (struct symbol *symbol,
176                                    struct pending **listhead,
177                                    struct pending_block *old_blocks,
178                                    const struct dynamic_prop *static_link,
179                                    CORE_ADDR start,
180                                    CORE_ADDR end);
181
182 extern void record_block_range (struct block *,
183                                 CORE_ADDR start, CORE_ADDR end_inclusive);
184
185 class scoped_free_pendings
186 {
187 public:
188
189   scoped_free_pendings () = default;
190   ~scoped_free_pendings ();
191
192   DISABLE_COPY_AND_ASSIGN (scoped_free_pendings);
193 };
194
195 extern void start_subfile (const char *name);
196
197 extern void patch_subfile_names (struct subfile *subfile, const char *name);
198
199 extern void push_subfile (void);
200
201 extern char *pop_subfile (void);
202
203 extern struct block *end_symtab_get_static_block (CORE_ADDR end_addr,
204                                                   int expandable,
205                                                   int required);
206
207 extern struct compunit_symtab *
208   end_symtab_from_static_block (struct block *static_block,
209                                 int section, int expandable);
210
211 extern struct compunit_symtab *end_symtab (CORE_ADDR end_addr, int section);
212
213 extern struct compunit_symtab *end_expandable_symtab (CORE_ADDR end_addr,
214                                                       int section);
215
216 extern void augment_type_symtab (void);
217
218 /* Defined in stabsread.c.  */
219
220 extern void scan_file_globals (struct objfile *objfile);
221
222 extern void buildsym_new_init (void);
223
224 extern void buildsym_init (void);
225
226 extern struct context_stack *push_context (int desc, CORE_ADDR valu);
227
228 extern struct context_stack *pop_context (void);
229
230 extern record_line_ftype record_line;
231
232 extern struct compunit_symtab *start_symtab (struct objfile *objfile,
233                                              const char *name,
234                                              const char *comp_dir,
235                                              CORE_ADDR start_addr,
236                                              enum language language);
237
238 extern void restart_symtab (struct compunit_symtab *cust,
239                             const char *name, CORE_ADDR start_addr);
240
241 extern void free_pending_blocks (void);
242
243 /* Record the name of the debug format in the current pending symbol
244    table.  FORMAT must be a string with a lifetime at least as long as
245    the symtab's objfile.  */
246
247 extern void record_debugformat (const char *format);
248
249 /* Record the name of the debuginfo producer (usually the compiler) in
250    the current pending symbol table.  PRODUCER must be a string with a
251    lifetime at least as long as the symtab's objfile.  */
252
253 extern void record_producer (const char *producer);
254
255 extern void merge_symbol_lists (struct pending **srclist,
256                                 struct pending **targetlist);
257
258 /* Set the name of the last source file.  NAME is copied by this
259    function.  */
260
261 extern void set_last_source_file (const char *name);
262
263 /* Fetch the name of the last source file.  */
264
265 extern const char *get_last_source_file (void);
266
267 /* Return the compunit symtab object.
268    It is only valid to call this between calls to start_symtab and the
269    end_symtab* functions.  */
270
271 extern struct compunit_symtab *buildsym_compunit_symtab (void);
272
273 /* Return the macro table.
274    Initialize it if this is the first use.
275    It is only valid to call this between calls to start_symtab and the
276    end_symtab* functions.  */
277
278 extern struct macro_table *get_macro_table (void);
279
280 /* Set the last source start address.  Can only be used between
281    start_symtab and end_symtab* calls.  */
282
283 extern void set_last_source_start_addr (CORE_ADDR addr);
284
285 /* Get the last source start address.  Can only be used between
286    start_symtab and end_symtab* calls.  */
287
288 extern CORE_ADDR get_last_source_start_addr ();
289
290 #undef EXTERN
291
292 #endif /* defined (BUILDSYM_H) */