x86: refine when to trigger optimizations
[deliverable/binutils-gdb.git] / gdb / buildsym-legacy.c
1 /* Legacy support routines for building symbol tables in GDB's internal format.
2 Copyright (C) 1986-2020 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 #include "defs.h"
20 #include "buildsym-legacy.h"
21 #include "symtab.h"
22
23 /* The work-in-progress of the compunit we are building.
24 This is created first, before any subfiles by start_symtab. */
25
26 static struct buildsym_compunit *buildsym_compunit;
27
28 void
29 record_debugformat (const char *format)
30 {
31 buildsym_compunit->record_debugformat (format);
32 }
33
34 void
35 record_producer (const char *producer)
36 {
37 buildsym_compunit->record_producer (producer);
38 }
39
40 \f
41
42 /* See buildsym.h. */
43
44 void
45 set_last_source_file (const char *name)
46 {
47 gdb_assert (buildsym_compunit != nullptr || name == nullptr);
48 if (buildsym_compunit != nullptr)
49 buildsym_compunit->set_last_source_file (name);
50 }
51
52 /* See buildsym.h. */
53
54 const char *
55 get_last_source_file ()
56 {
57 if (buildsym_compunit == nullptr)
58 return nullptr;
59 return buildsym_compunit->get_last_source_file ();
60 }
61
62 /* See buildsym.h. */
63
64 void
65 set_last_source_start_addr (CORE_ADDR addr)
66 {
67 gdb_assert (buildsym_compunit != nullptr);
68 buildsym_compunit->set_last_source_start_addr (addr);
69 }
70
71 /* See buildsym.h. */
72
73 CORE_ADDR
74 get_last_source_start_addr ()
75 {
76 gdb_assert (buildsym_compunit != nullptr);
77 return buildsym_compunit->get_last_source_start_addr ();
78 }
79
80 /* See buildsym.h. */
81
82 struct using_direct **
83 get_local_using_directives ()
84 {
85 gdb_assert (buildsym_compunit != nullptr);
86 return buildsym_compunit->get_local_using_directives ();
87 }
88
89 /* See buildsym.h. */
90
91 void
92 set_local_using_directives (struct using_direct *new_local)
93 {
94 gdb_assert (buildsym_compunit != nullptr);
95 buildsym_compunit->set_local_using_directives (new_local);
96 }
97
98 /* See buildsym.h. */
99
100 struct using_direct **
101 get_global_using_directives ()
102 {
103 gdb_assert (buildsym_compunit != nullptr);
104 return buildsym_compunit->get_global_using_directives ();
105 }
106
107 /* See buildsym.h. */
108
109 bool
110 outermost_context_p ()
111 {
112 gdb_assert (buildsym_compunit != nullptr);
113 return buildsym_compunit->outermost_context_p ();
114 }
115
116 /* See buildsym.h. */
117
118 struct context_stack *
119 get_current_context_stack ()
120 {
121 gdb_assert (buildsym_compunit != nullptr);
122 return buildsym_compunit->get_current_context_stack ();
123 }
124
125 /* See buildsym.h. */
126
127 int
128 get_context_stack_depth ()
129 {
130 gdb_assert (buildsym_compunit != nullptr);
131 return buildsym_compunit->get_context_stack_depth ();
132 }
133
134 /* See buildsym.h. */
135
136 struct subfile *
137 get_current_subfile ()
138 {
139 gdb_assert (buildsym_compunit != nullptr);
140 return buildsym_compunit->get_current_subfile ();
141 }
142
143 /* See buildsym.h. */
144
145 struct pending **
146 get_local_symbols ()
147 {
148 gdb_assert (buildsym_compunit != nullptr);
149 return buildsym_compunit->get_local_symbols ();
150 }
151
152 /* See buildsym.h. */
153
154 struct pending **
155 get_file_symbols ()
156 {
157 gdb_assert (buildsym_compunit != nullptr);
158 return buildsym_compunit->get_file_symbols ();
159 }
160
161 /* See buildsym.h. */
162
163 struct pending **
164 get_global_symbols ()
165 {
166 gdb_assert (buildsym_compunit != nullptr);
167 return buildsym_compunit->get_global_symbols ();
168 }
169
170 void
171 start_subfile (const char *name)
172 {
173 gdb_assert (buildsym_compunit != nullptr);
174 buildsym_compunit->start_subfile (name);
175 }
176
177 void
178 patch_subfile_names (struct subfile *subfile, const char *name)
179 {
180 gdb_assert (buildsym_compunit != nullptr);
181 buildsym_compunit->patch_subfile_names (subfile, name);
182 }
183
184 void
185 push_subfile ()
186 {
187 gdb_assert (buildsym_compunit != nullptr);
188 buildsym_compunit->push_subfile ();
189 }
190
191 const char *
192 pop_subfile ()
193 {
194 gdb_assert (buildsym_compunit != nullptr);
195 return buildsym_compunit->pop_subfile ();
196 }
197
198 /* Delete the buildsym compunit. */
199
200 static void
201 free_buildsym_compunit (void)
202 {
203 if (buildsym_compunit == NULL)
204 return;
205 delete buildsym_compunit;
206 buildsym_compunit = NULL;
207 }
208
209 struct compunit_symtab *
210 end_symtab (CORE_ADDR end_addr, int section)
211 {
212 gdb_assert (buildsym_compunit != nullptr);
213 struct compunit_symtab *result
214 = buildsym_compunit->end_symtab (end_addr, section);
215 free_buildsym_compunit ();
216 return result;
217 }
218
219 struct context_stack *
220 push_context (int desc, CORE_ADDR valu)
221 {
222 gdb_assert (buildsym_compunit != nullptr);
223 return buildsym_compunit->push_context (desc, valu);
224 }
225
226 struct context_stack
227 pop_context ()
228 {
229 gdb_assert (buildsym_compunit != nullptr);
230 return buildsym_compunit->pop_context ();
231 }
232
233 struct block *
234 finish_block (struct symbol *symbol, struct pending_block *old_blocks,
235 const struct dynamic_prop *static_link,
236 CORE_ADDR start, CORE_ADDR end)
237 {
238 gdb_assert (buildsym_compunit != nullptr);
239 return buildsym_compunit->finish_block (symbol, old_blocks, static_link,
240 start, end);
241 }
242
243 void
244 record_block_range (struct block *block, CORE_ADDR start,
245 CORE_ADDR end_inclusive)
246 {
247 gdb_assert (buildsym_compunit != nullptr);
248 buildsym_compunit->record_block_range (block, start, end_inclusive);
249 }
250
251 void
252 record_line (struct subfile *subfile, int line, CORE_ADDR pc)
253 {
254 gdb_assert (buildsym_compunit != nullptr);
255 buildsym_compunit->record_line (subfile, line, pc);
256 }
257
258 /* Start a new symtab for a new source file in OBJFILE. Called, for example,
259 when a stabs symbol of type N_SO is seen, or when a DWARF
260 TAG_compile_unit DIE is seen. It indicates the start of data for
261 one original source file.
262
263 NAME is the name of the file (cannot be NULL). COMP_DIR is the
264 directory in which the file was compiled (or NULL if not known).
265 START_ADDR is the lowest address of objects in the file (or 0 if
266 not known). LANGUAGE is the language of the source file, or
267 language_unknown if not known, in which case it'll be deduced from
268 the filename. */
269
270 struct compunit_symtab *
271 start_symtab (struct objfile *objfile, const char *name, const char *comp_dir,
272 CORE_ADDR start_addr, enum language language)
273 {
274 /* These should have been reset either by successful completion of building
275 a symtab, or by the scoped_free_pendings destructor. */
276 gdb_assert (buildsym_compunit == nullptr);
277
278 buildsym_compunit = new struct buildsym_compunit (objfile, name, comp_dir,
279 language, start_addr);
280
281 return buildsym_compunit->get_compunit_symtab ();
282 }
283
284 /* Restart compilation for a symtab.
285 CUST is the result of end_expandable_symtab.
286 NAME, START_ADDR are the source file we are resuming with.
287
288 This is used when a symtab is built from multiple sources.
289 The symtab is first built with start_symtab/end_expandable_symtab
290 and then for each additional piece call restart_symtab/augment_*_symtab.
291 Note: At the moment there is only augment_type_symtab. */
292
293 void
294 restart_symtab (struct compunit_symtab *cust,
295 const char *name, CORE_ADDR start_addr)
296 {
297 /* These should have been reset either by successful completion of building
298 a symtab, or by the scoped_free_pendings destructor. */
299 gdb_assert (buildsym_compunit == nullptr);
300
301 buildsym_compunit
302 = new struct buildsym_compunit (COMPUNIT_OBJFILE (cust),
303 name,
304 COMPUNIT_DIRNAME (cust),
305 compunit_language (cust),
306 start_addr,
307 cust);
308 }
309
310 /* See buildsym.h. */
311
312 struct compunit_symtab *
313 buildsym_compunit_symtab (void)
314 {
315 gdb_assert (buildsym_compunit != NULL);
316
317 return buildsym_compunit->get_compunit_symtab ();
318 }
319
320 /* See buildsym.h. */
321
322 struct macro_table *
323 get_macro_table (void)
324 {
325 gdb_assert (buildsym_compunit != NULL);
326 return buildsym_compunit->get_macro_table ();
327 }
328
329 /* At end of reading syms, or in case of quit, ensure everything
330 associated with building symtabs is freed.
331
332 N.B. This is *not* intended to be used when building psymtabs. Some debug
333 info readers call this anyway, which is harmless if confusing. */
334
335 scoped_free_pendings::~scoped_free_pendings ()
336 {
337 free_buildsym_compunit ();
338 }
339
340 /* See buildsym-legacy.h. */
341
342 struct buildsym_compunit *
343 get_buildsym_compunit ()
344 {
345 gdb_assert (buildsym_compunit != nullptr);
346 return buildsym_compunit;
347 }
This page took 0.035307 seconds and 4 git commands to generate.