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