1 /* Legacy support routines for building symbol tables in GDB's internal format.
2 Copyright (C) 1986-2020 Free Software Foundation, Inc.
4 This file is part of GDB.
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.
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.
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/>. */
20 #include "buildsym-legacy.h"
23 /* The work-in-progress of the compunit we are building.
24 This is created first, before any subfiles by start_symtab. */
26 static struct buildsym_compunit
*buildsym_compunit
;
29 record_debugformat (const char *format
)
31 buildsym_compunit
->record_debugformat (format
);
35 record_producer (const char *producer
)
37 buildsym_compunit
->record_producer (producer
);
45 set_last_source_file (const char *name
)
47 gdb_assert (buildsym_compunit
!= nullptr || name
== nullptr);
48 if (buildsym_compunit
!= nullptr)
49 buildsym_compunit
->set_last_source_file (name
);
55 get_last_source_file ()
57 if (buildsym_compunit
== nullptr)
59 return buildsym_compunit
->get_last_source_file ();
65 set_last_source_start_addr (CORE_ADDR addr
)
67 gdb_assert (buildsym_compunit
!= nullptr);
68 buildsym_compunit
->set_last_source_start_addr (addr
);
74 get_last_source_start_addr ()
76 gdb_assert (buildsym_compunit
!= nullptr);
77 return buildsym_compunit
->get_last_source_start_addr ();
82 struct using_direct
**
83 get_local_using_directives ()
85 gdb_assert (buildsym_compunit
!= nullptr);
86 return buildsym_compunit
->get_local_using_directives ();
92 set_local_using_directives (struct using_direct
*new_local
)
94 gdb_assert (buildsym_compunit
!= nullptr);
95 buildsym_compunit
->set_local_using_directives (new_local
);
100 struct using_direct
**
101 get_global_using_directives ()
103 gdb_assert (buildsym_compunit
!= nullptr);
104 return buildsym_compunit
->get_global_using_directives ();
107 /* See buildsym.h. */
110 outermost_context_p ()
112 gdb_assert (buildsym_compunit
!= nullptr);
113 return buildsym_compunit
->outermost_context_p ();
116 /* See buildsym.h. */
118 struct context_stack
*
119 get_current_context_stack ()
121 gdb_assert (buildsym_compunit
!= nullptr);
122 return buildsym_compunit
->get_current_context_stack ();
125 /* See buildsym.h. */
128 get_context_stack_depth ()
130 gdb_assert (buildsym_compunit
!= nullptr);
131 return buildsym_compunit
->get_context_stack_depth ();
134 /* See buildsym.h. */
137 get_current_subfile ()
139 gdb_assert (buildsym_compunit
!= nullptr);
140 return buildsym_compunit
->get_current_subfile ();
143 /* See buildsym.h. */
148 gdb_assert (buildsym_compunit
!= nullptr);
149 return buildsym_compunit
->get_local_symbols ();
152 /* See buildsym.h. */
157 gdb_assert (buildsym_compunit
!= nullptr);
158 return buildsym_compunit
->get_file_symbols ();
161 /* See buildsym.h. */
164 get_global_symbols ()
166 gdb_assert (buildsym_compunit
!= nullptr);
167 return buildsym_compunit
->get_global_symbols ();
171 start_subfile (const char *name
)
173 gdb_assert (buildsym_compunit
!= nullptr);
174 buildsym_compunit
->start_subfile (name
);
178 patch_subfile_names (struct subfile
*subfile
, const char *name
)
180 gdb_assert (buildsym_compunit
!= nullptr);
181 buildsym_compunit
->patch_subfile_names (subfile
, name
);
187 gdb_assert (buildsym_compunit
!= nullptr);
188 buildsym_compunit
->push_subfile ();
194 gdb_assert (buildsym_compunit
!= nullptr);
195 return buildsym_compunit
->pop_subfile ();
198 /* Delete the buildsym compunit. */
201 free_buildsym_compunit (void)
203 if (buildsym_compunit
== NULL
)
205 delete buildsym_compunit
;
206 buildsym_compunit
= NULL
;
209 struct compunit_symtab
*
210 end_symtab (CORE_ADDR end_addr
, int section
)
212 gdb_assert (buildsym_compunit
!= nullptr);
213 struct compunit_symtab
*result
214 = buildsym_compunit
->end_symtab (end_addr
, section
);
215 free_buildsym_compunit ();
219 struct context_stack
*
220 push_context (int desc
, CORE_ADDR valu
)
222 gdb_assert (buildsym_compunit
!= nullptr);
223 return buildsym_compunit
->push_context (desc
, valu
);
229 gdb_assert (buildsym_compunit
!= nullptr);
230 return buildsym_compunit
->pop_context ();
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
)
238 gdb_assert (buildsym_compunit
!= nullptr);
239 return buildsym_compunit
->finish_block (symbol
, old_blocks
, static_link
,
244 record_block_range (struct block
*block
, CORE_ADDR start
,
245 CORE_ADDR end_inclusive
)
247 gdb_assert (buildsym_compunit
!= nullptr);
248 buildsym_compunit
->record_block_range (block
, start
, end_inclusive
);
252 record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
254 gdb_assert (buildsym_compunit
!= nullptr);
255 buildsym_compunit
->record_line (subfile
, line
, pc
);
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.
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
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
)
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);
278 buildsym_compunit
= new struct buildsym_compunit (objfile
, name
, comp_dir
,
279 language
, start_addr
);
281 return buildsym_compunit
->get_compunit_symtab ();
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.
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. */
294 restart_symtab (struct compunit_symtab
*cust
,
295 const char *name
, CORE_ADDR start_addr
)
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);
302 = new struct buildsym_compunit (COMPUNIT_OBJFILE (cust
),
304 COMPUNIT_DIRNAME (cust
),
305 compunit_language (cust
),
310 /* See buildsym.h. */
312 struct compunit_symtab
*
313 buildsym_compunit_symtab (void)
315 gdb_assert (buildsym_compunit
!= NULL
);
317 return buildsym_compunit
->get_compunit_symtab ();
320 /* See buildsym.h. */
323 get_macro_table (void)
325 gdb_assert (buildsym_compunit
!= NULL
);
326 return buildsym_compunit
->get_macro_table ();
329 /* At end of reading syms, or in case of quit, ensure everything
330 associated with building symtabs is freed.
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. */
335 scoped_free_pendings::~scoped_free_pendings ()
337 free_buildsym_compunit ();
340 /* See buildsym-legacy.h. */
342 struct buildsym_compunit
*
343 get_buildsym_compunit ()
345 gdb_assert (buildsym_compunit
!= nullptr);
346 return buildsym_compunit
;