1 /* Legacy support routines for building symbol tables in GDB's internal format.
2 Copyright (C) 1986-2024 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/>. */
19 #include "buildsym-legacy.h"
22 /* The work-in-progress of the compunit we are building.
23 This is created first, before any subfiles by start_compunit_symtab. */
25 static struct buildsym_compunit
*buildsym_compunit
;
28 record_debugformat (const char *format
)
30 buildsym_compunit
->record_debugformat (format
);
34 record_producer (const char *producer
)
36 buildsym_compunit
->record_producer (producer
);
44 set_last_source_file (const char *name
)
46 gdb_assert (buildsym_compunit
!= nullptr || name
== nullptr);
47 if (buildsym_compunit
!= nullptr)
48 buildsym_compunit
->set_last_source_file (name
);
54 get_last_source_file ()
56 if (buildsym_compunit
== nullptr)
58 return buildsym_compunit
->get_last_source_file ();
64 set_last_source_start_addr (CORE_ADDR addr
)
66 gdb_assert (buildsym_compunit
!= nullptr);
67 buildsym_compunit
->set_last_source_start_addr (addr
);
73 get_last_source_start_addr ()
75 gdb_assert (buildsym_compunit
!= nullptr);
76 return buildsym_compunit
->get_last_source_start_addr ();
82 outermost_context_p ()
84 gdb_assert (buildsym_compunit
!= nullptr);
85 return buildsym_compunit
->outermost_context_p ();
91 get_context_stack_depth ()
93 gdb_assert (buildsym_compunit
!= nullptr);
94 return buildsym_compunit
->get_context_stack_depth ();
100 get_current_subfile ()
102 gdb_assert (buildsym_compunit
!= nullptr);
103 return buildsym_compunit
->get_current_subfile ();
106 /* See buildsym.h. */
111 gdb_assert (buildsym_compunit
!= nullptr);
112 return buildsym_compunit
->get_local_symbols ();
115 /* See buildsym.h. */
120 gdb_assert (buildsym_compunit
!= nullptr);
121 return buildsym_compunit
->get_file_symbols ();
124 /* See buildsym.h. */
127 get_global_symbols ()
129 gdb_assert (buildsym_compunit
!= nullptr);
130 return buildsym_compunit
->get_global_symbols ();
134 start_subfile (const char *name
)
136 gdb_assert (buildsym_compunit
!= nullptr);
137 buildsym_compunit
->start_subfile (name
);
141 patch_subfile_names (struct subfile
*subfile
, const char *name
)
143 gdb_assert (buildsym_compunit
!= nullptr);
144 buildsym_compunit
->patch_subfile_names (subfile
, name
);
150 gdb_assert (buildsym_compunit
!= nullptr);
151 buildsym_compunit
->push_subfile ();
157 gdb_assert (buildsym_compunit
!= nullptr);
158 return buildsym_compunit
->pop_subfile ();
161 /* Delete the buildsym compunit. */
164 free_buildsym_compunit (void)
166 if (buildsym_compunit
== NULL
)
168 delete buildsym_compunit
;
169 buildsym_compunit
= NULL
;
172 struct compunit_symtab
*
173 end_compunit_symtab (CORE_ADDR end_addr
)
175 gdb_assert (buildsym_compunit
!= nullptr);
176 struct compunit_symtab
*result
177 = buildsym_compunit
->end_compunit_symtab (end_addr
);
178 free_buildsym_compunit ();
182 struct context_stack
*
183 push_context (int desc
, CORE_ADDR valu
)
185 gdb_assert (buildsym_compunit
!= nullptr);
186 return buildsym_compunit
->push_context (desc
, valu
);
192 gdb_assert (buildsym_compunit
!= nullptr);
193 return buildsym_compunit
->pop_context ();
197 finish_block (struct symbol
*symbol
, struct pending_block
*old_blocks
,
198 const struct dynamic_prop
*static_link
,
199 CORE_ADDR start
, CORE_ADDR end
)
201 gdb_assert (buildsym_compunit
!= nullptr);
202 return buildsym_compunit
->finish_block (symbol
, old_blocks
, static_link
,
207 record_line (struct subfile
*subfile
, int line
, unrelocated_addr pc
)
209 gdb_assert (buildsym_compunit
!= nullptr);
210 /* Assume every line entry is a statement start, that is a good place to
211 put a breakpoint for that line number. */
212 buildsym_compunit
->record_line (subfile
, line
, pc
, LEF_IS_STMT
);
215 /* Start a new compunit_symtab for a new source file in OBJFILE. Called, for
216 example, when a stabs symbol of type N_SO is seen, or when a DWARF
217 DW_TAG_compile_unit DIE is seen. It indicates the start of data for one
218 original source file.
220 NAME is the name of the file (cannot be NULL). COMP_DIR is the
221 directory in which the file was compiled (or NULL if not known).
222 START_ADDR is the lowest address of objects in the file (or 0 if
223 not known). LANGUAGE is the language of the source file, or
224 language_unknown if not known, in which case it'll be deduced from
227 struct compunit_symtab
*
228 start_compunit_symtab (struct objfile
*objfile
, const char *name
,
229 const char *comp_dir
, CORE_ADDR start_addr
,
230 enum language language
)
232 /* These should have been reset either by successful completion of building
233 a symtab, or by the scoped_free_pendings destructor. */
234 gdb_assert (buildsym_compunit
== nullptr);
236 buildsym_compunit
= new struct buildsym_compunit (objfile
, name
, comp_dir
,
237 language
, start_addr
);
239 return buildsym_compunit
->get_compunit_symtab ();
242 /* At end of reading syms, or in case of quit, ensure everything
243 associated with building symtabs is freed.
245 N.B. This is *not* intended to be used when building psymtabs. Some debug
246 info readers call this anyway, which is harmless if confusing. */
248 scoped_free_pendings::~scoped_free_pendings ()
250 free_buildsym_compunit ();
253 /* See buildsym-legacy.h. */
255 struct buildsym_compunit
*
256 get_buildsym_compunit ()
258 gdb_assert (buildsym_compunit
!= nullptr);
259 return buildsym_compunit
;