]>
Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Build symbol tables in GDB's internal format. |
213516ef | 2 | Copyright (C) 1986-2023 Free Software Foundation, Inc. |
c906108c | 3 | |
c5aa993b JM |
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 | |
a9762ec7 | 8 | the Free Software Foundation; either version 3 of the License, or |
c5aa993b JM |
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 | |
a9762ec7 | 17 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
18 | |
19 | #if !defined (BUILDSYM_H) | |
20 | #define BUILDSYM_H 1 | |
21 | ||
bf31fd38 | 22 | #include "gdbsupport/gdb_obstack.h" |
558802e4 | 23 | #include "symtab.h" |
93b527ef | 24 | #include "addrmap.h" |
0d12e84c | 25 | |
da3331ec AC |
26 | struct objfile; |
27 | struct symbol; | |
801e3a5b | 28 | struct addrmap; |
43f3e411 | 29 | struct compunit_symtab; |
5ffa0793 | 30 | enum language; |
da3331ec | 31 | |
c906108c SS |
32 | /* This module provides definitions used for creating and adding to |
33 | the symbol table. These routines are called from various symbol- | |
34 | file-reading routines. | |
35 | ||
36 | They originated in dbxread.c of gdb-4.2, and were split out to | |
b80a981d | 37 | make xcoffread.c more maintainable by sharing code. */ |
c906108c | 38 | |
fe898f56 | 39 | struct block; |
93eed41f | 40 | struct pending_block; |
fe898f56 | 41 | |
63e43d3a PMR |
42 | struct dynamic_prop; |
43 | ||
c906108c SS |
44 | /* The list of sub-source-files within the current individual |
45 | compilation. Each file gets its own symtab with its own linetable | |
46 | and associated info, but they all share one blockvector. */ | |
47 | ||
48 | struct subfile | |
43f3e411 | 49 | { |
71bc95ed SM |
50 | subfile () = default; |
51 | ||
52 | /* There's nothing wrong with copying a subfile, but we don't need to, so use | |
53 | this to avoid copying one by mistake. */ | |
54 | DISABLE_COPY_AND_ASSIGN (subfile); | |
55 | ||
56 | struct subfile *next = nullptr; | |
ebd4e6d0 | 57 | std::string name; |
f71ad555 SM |
58 | |
59 | /* This field is analoguous in function to symtab::filename_for_id. | |
60 | ||
61 | It is used to look up existing subfiles in calls to start_subfile. */ | |
62 | std::string name_for_id; | |
63 | ||
558802e4 | 64 | std::vector<linetable_entry> line_vector_entries; |
71bc95ed SM |
65 | enum language language = language_unknown; |
66 | struct symtab *symtab = nullptr; | |
43f3e411 | 67 | }; |
c906108c | 68 | |
71bc95ed SM |
69 | using subfile_up = std::unique_ptr<subfile>; |
70 | ||
c906108c SS |
71 | /* Record the symbols defined for each context in a list. We don't |
72 | create a struct block for the context until we know how long to | |
73 | make it. */ | |
74 | ||
75 | #define PENDINGSIZE 100 | |
76 | ||
77 | struct pending | |
78 | { | |
79 | struct pending *next; | |
80 | int nsyms; | |
81 | struct symbol *symbol[PENDINGSIZE]; | |
82 | }; | |
83 | ||
c906108c SS |
84 | /* Stack representing unclosed lexical contexts (that will become |
85 | blocks, eventually). */ | |
86 | ||
87 | struct context_stack | |
88 | { | |
89 | /* Outer locals at the time we entered */ | |
90 | ||
91 | struct pending *locals; | |
92 | ||
27aa8d6a SW |
93 | /* Pending using directives at the time we entered. */ |
94 | ||
22cee43f | 95 | struct using_direct *local_using_directives; |
27aa8d6a | 96 | |
c906108c SS |
97 | /* Pointer into blocklist as of entry */ |
98 | ||
99 | struct pending_block *old_blocks; | |
100 | ||
101 | /* Name of function, if any, defining context */ | |
102 | ||
103 | struct symbol *name; | |
104 | ||
63e43d3a PMR |
105 | /* Expression that computes the frame base of the lexically enclosing |
106 | function, if any. NULL otherwise. */ | |
107 | ||
108 | struct dynamic_prop *static_link; | |
109 | ||
c906108c SS |
110 | /* PC where this context starts */ |
111 | ||
112 | CORE_ADDR start_addr; | |
113 | ||
0e2de366 | 114 | /* Temp slot for exception handling. */ |
c906108c SS |
115 | |
116 | CORE_ADDR end_addr; | |
117 | ||
118 | /* For error-checking matching push/pop */ | |
119 | ||
120 | int depth; | |
121 | ||
122 | }; | |
123 | ||
6cacd78b LS |
124 | /* Flags associated with a linetable entry. */ |
125 | ||
126 | enum linetable_entry_flag : unsigned | |
127 | { | |
128 | /* Indicates this PC is a good location to place a breakpoint at LINE. */ | |
129 | LEF_IS_STMT = 1 << 1, | |
cc96ae7f LS |
130 | |
131 | /* Indicates this PC is a good location to place a breakpoint at the first | |
132 | instruction past a function prologue. */ | |
133 | LEF_PROLOGUE_END = 1 << 2, | |
6cacd78b LS |
134 | }; |
135 | DEF_ENUM_FLAGS_TYPE (enum linetable_entry_flag, linetable_entry_flags); | |
136 | ||
137 | ||
ab209f6f TT |
138 | /* Buildsym's counterpart to struct compunit_symtab. */ |
139 | ||
140 | struct buildsym_compunit | |
141 | { | |
142 | /* Start recording information about a primary source file (IOW, not an | |
143 | included source file). | |
f71ad555 | 144 | |
ab209f6f | 145 | COMP_DIR is the directory in which the compilation unit was compiled |
f71ad555 SM |
146 | (or NULL if not known). |
147 | ||
148 | NAME and NAME_FOR_ID have the same purpose as for the start_subfile | |
149 | method. */ | |
150 | ||
151 | buildsym_compunit (struct objfile *objfile_, const char *name, | |
152 | const char *comp_dir_, const char *name_for_id, | |
153 | enum language language_, CORE_ADDR last_addr); | |
154 | ||
155 | /* Same as above, but passes NAME for NAME_FOR_ID. */ | |
ab209f6f TT |
156 | |
157 | buildsym_compunit (struct objfile *objfile_, const char *name, | |
158 | const char *comp_dir_, enum language language_, | |
f71ad555 SM |
159 | CORE_ADDR last_addr) |
160 | : buildsym_compunit (objfile_, name, comp_dir_, name, language_, last_addr) | |
161 | {} | |
ab209f6f TT |
162 | |
163 | /* Reopen an existing compunit_symtab so that additional symbols can | |
164 | be added to it. Arguments are as for the main constructor. CUST | |
165 | is the expandable compunit_symtab to be reopened. */ | |
166 | ||
167 | buildsym_compunit (struct objfile *objfile_, const char *name, | |
168 | const char *comp_dir_, enum language language_, | |
169 | CORE_ADDR last_addr, struct compunit_symtab *cust) | |
cbb09508 | 170 | : m_objfile (objfile_), |
ab209f6f | 171 | m_last_source_file (name == nullptr ? nullptr : xstrdup (name)), |
ebd4e6d0 | 172 | m_comp_dir (comp_dir_ == nullptr ? "" : comp_dir_), |
cbb09508 KS |
173 | m_compunit_symtab (cust), |
174 | m_language (language_), | |
ab209f6f TT |
175 | m_last_source_start_addr (last_addr) |
176 | { | |
177 | } | |
178 | ||
179 | ~buildsym_compunit (); | |
180 | ||
181 | DISABLE_COPY_AND_ASSIGN (buildsym_compunit); | |
182 | ||
183 | void set_last_source_file (const char *name) | |
184 | { | |
185 | char *new_name = name == NULL ? NULL : xstrdup (name); | |
186 | m_last_source_file.reset (new_name); | |
187 | } | |
188 | ||
189 | const char *get_last_source_file () | |
190 | { | |
191 | return m_last_source_file.get (); | |
192 | } | |
193 | ||
194 | struct macro_table *get_macro_table (); | |
195 | ||
196 | struct macro_table *release_macros () | |
197 | { | |
198 | struct macro_table *result = m_pending_macros; | |
199 | m_pending_macros = nullptr; | |
200 | return result; | |
201 | } | |
202 | ||
203 | /* This function is called to discard any pending blocks. */ | |
204 | ||
205 | void free_pending_blocks () | |
206 | { | |
207 | m_pending_block_obstack.clear (); | |
208 | m_pending_blocks = nullptr; | |
209 | } | |
210 | ||
211 | struct block *finish_block (struct symbol *symbol, | |
212 | struct pending_block *old_blocks, | |
213 | const struct dynamic_prop *static_link, | |
214 | CORE_ADDR start, CORE_ADDR end); | |
215 | ||
216 | void record_block_range (struct block *block, | |
217 | CORE_ADDR start, CORE_ADDR end_inclusive); | |
218 | ||
f71ad555 SM |
219 | /* Start recording information about source code that comes from a source |
220 | file. This sets the current subfile, creating it if necessary. | |
221 | ||
222 | NAME is the user-visible name of the subfile. | |
223 | ||
224 | NAME_FOR_ID is a name that must be stable between the different calls to | |
225 | start_subfile referring to the same file (it is used for looking up | |
226 | existing subfiles). It can be equal to NAME if NAME follows that rule. */ | |
227 | void start_subfile (const char *name, const char *name_for_id); | |
228 | ||
229 | /* Same as above, but passes NAME for NAME_FOR_ID. */ | |
230 | ||
231 | void start_subfile (const char *name) | |
232 | { | |
233 | return start_subfile (name, name); | |
234 | } | |
ab209f6f TT |
235 | |
236 | void patch_subfile_names (struct subfile *subfile, const char *name); | |
237 | ||
238 | void push_subfile (); | |
239 | ||
240 | const char *pop_subfile (); | |
241 | ||
8c95582d | 242 | void record_line (struct subfile *subfile, int line, CORE_ADDR pc, |
6cacd78b | 243 | linetable_entry_flags flags); |
ab209f6f TT |
244 | |
245 | struct compunit_symtab *get_compunit_symtab () | |
246 | { | |
cbb09508 | 247 | return m_compunit_symtab; |
ab209f6f TT |
248 | } |
249 | ||
250 | void set_last_source_start_addr (CORE_ADDR addr) | |
251 | { | |
252 | m_last_source_start_addr = addr; | |
253 | } | |
254 | ||
255 | CORE_ADDR get_last_source_start_addr () | |
256 | { | |
257 | return m_last_source_start_addr; | |
258 | } | |
259 | ||
260 | struct using_direct **get_local_using_directives () | |
261 | { | |
262 | return &m_local_using_directives; | |
263 | } | |
264 | ||
265 | void set_local_using_directives (struct using_direct *new_local) | |
266 | { | |
267 | m_local_using_directives = new_local; | |
268 | } | |
269 | ||
270 | struct using_direct **get_global_using_directives () | |
271 | { | |
272 | return &m_global_using_directives; | |
273 | } | |
274 | ||
275 | bool outermost_context_p () const | |
276 | { | |
277 | return m_context_stack.empty (); | |
278 | } | |
279 | ||
280 | struct context_stack *get_current_context_stack () | |
281 | { | |
282 | if (m_context_stack.empty ()) | |
283 | return nullptr; | |
284 | return &m_context_stack.back (); | |
285 | } | |
286 | ||
287 | int get_context_stack_depth () const | |
288 | { | |
289 | return m_context_stack.size (); | |
290 | } | |
291 | ||
292 | struct subfile *get_current_subfile () | |
293 | { | |
294 | return m_current_subfile; | |
295 | } | |
296 | ||
297 | struct pending **get_local_symbols () | |
298 | { | |
299 | return &m_local_symbols; | |
300 | } | |
301 | ||
302 | struct pending **get_file_symbols () | |
303 | { | |
304 | return &m_file_symbols; | |
305 | } | |
306 | ||
307 | struct pending **get_global_symbols () | |
308 | { | |
309 | return &m_global_symbols; | |
310 | } | |
311 | ||
312 | void record_debugformat (const char *format) | |
313 | { | |
cbb09508 | 314 | m_debugformat = format; |
ab209f6f TT |
315 | } |
316 | ||
317 | void record_producer (const char *producer) | |
318 | { | |
cbb09508 | 319 | m_producer = producer; |
ab209f6f TT |
320 | } |
321 | ||
322 | struct context_stack *push_context (int desc, CORE_ADDR valu); | |
323 | ||
324 | struct context_stack pop_context (); | |
325 | ||
59dfe8ad SM |
326 | struct block *end_compunit_symtab_get_static_block |
327 | (CORE_ADDR end_addr, int expandable, int required); | |
ab209f6f | 328 | |
59dfe8ad SM |
329 | struct compunit_symtab *end_compunit_symtab_from_static_block |
330 | (struct block *static_block, int section, int expandable); | |
ab209f6f | 331 | |
59dfe8ad | 332 | struct compunit_symtab *end_compunit_symtab (CORE_ADDR end_addr, int section); |
ab209f6f TT |
333 | |
334 | struct compunit_symtab *end_expandable_symtab (CORE_ADDR end_addr, | |
335 | int section); | |
336 | ||
337 | void augment_type_symtab (); | |
338 | ||
339 | private: | |
340 | ||
341 | void record_pending_block (struct block *block, struct pending_block *opblock); | |
342 | ||
343 | struct block *finish_block_internal (struct symbol *symbol, | |
344 | struct pending **listhead, | |
345 | struct pending_block *old_blocks, | |
346 | const struct dynamic_prop *static_link, | |
347 | CORE_ADDR start, CORE_ADDR end, | |
348 | int is_global, int expandable); | |
349 | ||
350 | struct blockvector *make_blockvector (); | |
351 | ||
352 | void watch_main_source_file_lossage (); | |
353 | ||
59dfe8ad SM |
354 | struct compunit_symtab *end_compunit_symtab_with_blockvector |
355 | (struct block *static_block, int section, int expandable); | |
ab209f6f TT |
356 | |
357 | /* The objfile we're reading debug info from. */ | |
cbb09508 | 358 | struct objfile *m_objfile; |
ab209f6f TT |
359 | |
360 | /* List of subfiles (source files). | |
361 | Files are added to the front of the list. | |
362 | This is important mostly for the language determination hacks we use, | |
363 | which iterate over previously added files. */ | |
cbb09508 | 364 | struct subfile *m_subfiles = nullptr; |
ab209f6f TT |
365 | |
366 | /* The subfile of the main source file. */ | |
cbb09508 | 367 | struct subfile *m_main_subfile = nullptr; |
ab209f6f TT |
368 | |
369 | /* Name of source file whose symbol data we are now processing. This | |
370 | comes from a symbol of type N_SO for stabs. For DWARF it comes | |
371 | from the DW_AT_name attribute of a DW_TAG_compile_unit DIE. */ | |
372 | gdb::unique_xmalloc_ptr<char> m_last_source_file; | |
373 | ||
374 | /* E.g., DW_AT_comp_dir if DWARF. Space for this is malloc'd. */ | |
ebd4e6d0 | 375 | std::string m_comp_dir; |
ab209f6f TT |
376 | |
377 | /* Space for this is not malloc'd, and is assumed to have at least | |
378 | the same lifetime as objfile. */ | |
cbb09508 | 379 | const char *m_producer = nullptr; |
ab209f6f TT |
380 | |
381 | /* Space for this is not malloc'd, and is assumed to have at least | |
382 | the same lifetime as objfile. */ | |
cbb09508 | 383 | const char *m_debugformat = nullptr; |
ab209f6f TT |
384 | |
385 | /* The compunit we are building. */ | |
cbb09508 | 386 | struct compunit_symtab *m_compunit_symtab = nullptr; |
ab209f6f TT |
387 | |
388 | /* Language of this compunit_symtab. */ | |
cbb09508 | 389 | enum language m_language; |
ab209f6f TT |
390 | |
391 | /* The macro table for the compilation unit whose symbols we're | |
392 | currently reading. */ | |
393 | struct macro_table *m_pending_macros = nullptr; | |
394 | ||
395 | /* True if symtab has line number info. This prevents an otherwise | |
396 | empty symtab from being tossed. */ | |
397 | bool m_have_line_numbers = false; | |
398 | ||
399 | /* Core address of start of text of current source file. This too | |
400 | comes from the N_SO symbol. For Dwarf it typically comes from the | |
401 | DW_AT_low_pc attribute of a DW_TAG_compile_unit DIE. */ | |
402 | CORE_ADDR m_last_source_start_addr; | |
403 | ||
404 | /* Stack of subfile names. */ | |
405 | std::vector<const char *> m_subfile_stack; | |
406 | ||
407 | /* The "using" directives local to lexical context. */ | |
408 | struct using_direct *m_local_using_directives = nullptr; | |
409 | ||
410 | /* Global "using" directives. */ | |
411 | struct using_direct *m_global_using_directives = nullptr; | |
412 | ||
413 | /* The stack of contexts that are pushed by push_context and popped | |
414 | by pop_context. */ | |
415 | std::vector<struct context_stack> m_context_stack; | |
416 | ||
417 | struct subfile *m_current_subfile = nullptr; | |
418 | ||
419 | /* The mutable address map for the compilation unit whose symbols | |
420 | we're currently reading. The symtabs' shared blockvector will | |
421 | point to a fixed copy of this. */ | |
93b527ef | 422 | struct addrmap_mutable m_pending_addrmap; |
ab209f6f TT |
423 | |
424 | /* True if we recorded any ranges in the addrmap that are different | |
425 | from those in the blockvector already. We set this to false when | |
426 | we start processing a symfile, and if it's still false at the | |
427 | end, then we just toss the addrmap. */ | |
428 | bool m_pending_addrmap_interesting = false; | |
429 | ||
430 | /* An obstack used for allocating pending blocks. */ | |
431 | auto_obstack m_pending_block_obstack; | |
432 | ||
433 | /* Pointer to the head of a linked list of symbol blocks which have | |
434 | already been finalized (lexical contexts already closed) and which | |
435 | are just waiting to be built into a blockvector when finalizing the | |
436 | associated symtab. */ | |
437 | struct pending_block *m_pending_blocks = nullptr; | |
438 | ||
439 | /* Pending static symbols and types at the top level. */ | |
440 | struct pending *m_file_symbols = nullptr; | |
441 | ||
442 | /* Pending global functions and variables. */ | |
443 | struct pending *m_global_symbols = nullptr; | |
444 | ||
445 | /* Pending symbols that are local to the lexical context. */ | |
446 | struct pending *m_local_symbols = nullptr; | |
447 | }; | |
448 | ||
c906108c SS |
449 | \f |
450 | ||
c906108c SS |
451 | extern void add_symbol_to_list (struct symbol *symbol, |
452 | struct pending **listhead); | |
453 | ||
454 | extern struct symbol *find_symbol_in_list (struct pending *list, | |
455 | char *name, int length); | |
456 | ||
c906108c | 457 | #endif /* defined (BUILDSYM_H) */ |