Automatic date update in version.in
[binutils-gdb.git] / gdb / buildsym.h
blob98dc8f028746d5e7dbbbea89accbc8841459dc0d
1 /* Build symbol tables in GDB's internal format.
2 Copyright (C) 1986-2023 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 #if !defined (BUILDSYM_H)
20 #define BUILDSYM_H 1
22 #include "gdbsupport/gdb_obstack.h"
23 #include "symtab.h"
24 #include "addrmap.h"
26 struct objfile;
27 struct symbol;
28 struct addrmap;
29 struct compunit_symtab;
30 enum language;
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.
36 They originated in dbxread.c of gdb-4.2, and were split out to
37 make xcoffread.c more maintainable by sharing code. */
39 struct block;
40 struct pending_block;
42 struct dynamic_prop;
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. */
48 struct subfile
50 subfile () = default;
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);
56 struct subfile *next = nullptr;
57 std::string name;
59 /* This field is analoguous in function to symtab::filename_for_id.
61 It is used to look up existing subfiles in calls to start_subfile. */
62 std::string name_for_id;
64 std::vector<linetable_entry> line_vector_entries;
65 enum language language = language_unknown;
66 struct symtab *symtab = nullptr;
69 using subfile_up = std::unique_ptr<subfile>;
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. */
75 #define PENDINGSIZE 100
77 struct pending
79 struct pending *next;
80 int nsyms;
81 struct symbol *symbol[PENDINGSIZE];
84 /* Stack representing unclosed lexical contexts (that will become
85 blocks, eventually). */
87 struct context_stack
89 /* Outer locals at the time we entered */
91 struct pending *locals;
93 /* Pending using directives at the time we entered. */
95 struct using_direct *local_using_directives;
97 /* Pointer into blocklist as of entry */
99 struct pending_block *old_blocks;
101 /* Name of function, if any, defining context */
103 struct symbol *name;
105 /* Expression that computes the frame base of the lexically enclosing
106 function, if any. NULL otherwise. */
108 struct dynamic_prop *static_link;
110 /* PC where this context starts */
112 CORE_ADDR start_addr;
114 /* Temp slot for exception handling. */
116 CORE_ADDR end_addr;
118 /* For error-checking matching push/pop */
120 int depth;
124 /* Flags associated with a linetable entry. */
126 enum linetable_entry_flag : unsigned
128 /* Indicates this PC is a good location to place a breakpoint at LINE. */
129 LEF_IS_STMT = 1 << 1,
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,
135 DEF_ENUM_FLAGS_TYPE (enum linetable_entry_flag, linetable_entry_flags);
138 /* Buildsym's counterpart to struct compunit_symtab. */
140 struct buildsym_compunit
142 /* Start recording information about a primary source file (IOW, not an
143 included source file).
145 COMP_DIR is the directory in which the compilation unit was compiled
146 (or NULL if not known).
148 NAME and NAME_FOR_ID have the same purpose as for the start_subfile
149 method. */
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);
155 /* Same as above, but passes NAME for NAME_FOR_ID. */
157 buildsym_compunit (struct objfile *objfile_, const char *name,
158 const char *comp_dir_, enum language language_,
159 CORE_ADDR last_addr)
160 : buildsym_compunit (objfile_, name, comp_dir_, name, language_, last_addr)
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. */
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)
170 : m_objfile (objfile_),
171 m_last_source_file (name == nullptr ? nullptr : xstrdup (name)),
172 m_comp_dir (comp_dir_ == nullptr ? "" : comp_dir_),
173 m_compunit_symtab (cust),
174 m_language (language_),
175 m_last_source_start_addr (last_addr)
179 ~buildsym_compunit ();
181 DISABLE_COPY_AND_ASSIGN (buildsym_compunit);
183 void set_last_source_file (const char *name)
185 char *new_name = name == NULL ? NULL : xstrdup (name);
186 m_last_source_file.reset (new_name);
189 const char *get_last_source_file ()
191 return m_last_source_file.get ();
194 struct macro_table *get_macro_table ();
196 struct macro_table *release_macros ()
198 struct macro_table *result = m_pending_macros;
199 m_pending_macros = nullptr;
200 return result;
203 /* This function is called to discard any pending blocks. */
205 void free_pending_blocks ()
207 m_pending_block_obstack.clear ();
208 m_pending_blocks = nullptr;
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);
216 void record_block_range (struct block *block,
217 CORE_ADDR start, CORE_ADDR end_inclusive);
219 /* Start recording information about source code that comes from a source
220 file. This sets the current subfile, creating it if necessary.
222 NAME is the user-visible name of the subfile.
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);
229 /* Same as above, but passes NAME for NAME_FOR_ID. */
231 void start_subfile (const char *name)
233 return start_subfile (name, name);
236 void patch_subfile_names (struct subfile *subfile, const char *name);
238 void push_subfile ();
240 const char *pop_subfile ();
242 void record_line (struct subfile *subfile, int line, unrelocated_addr pc,
243 linetable_entry_flags flags);
245 struct compunit_symtab *get_compunit_symtab ()
247 return m_compunit_symtab;
250 void set_last_source_start_addr (CORE_ADDR addr)
252 m_last_source_start_addr = addr;
255 CORE_ADDR get_last_source_start_addr ()
257 return m_last_source_start_addr;
260 struct using_direct **get_local_using_directives ()
262 return &m_local_using_directives;
265 void set_local_using_directives (struct using_direct *new_local)
267 m_local_using_directives = new_local;
270 struct using_direct **get_global_using_directives ()
272 return &m_global_using_directives;
275 bool outermost_context_p () const
277 return m_context_stack.empty ();
280 struct context_stack *get_current_context_stack ()
282 if (m_context_stack.empty ())
283 return nullptr;
284 return &m_context_stack.back ();
287 int get_context_stack_depth () const
289 return m_context_stack.size ();
292 struct subfile *get_current_subfile ()
294 return m_current_subfile;
297 struct pending **get_local_symbols ()
299 return &m_local_symbols;
302 struct pending **get_file_symbols ()
304 return &m_file_symbols;
307 struct pending **get_global_symbols ()
309 return &m_global_symbols;
312 void record_debugformat (const char *format)
314 m_debugformat = format;
317 void record_producer (const char *producer)
319 m_producer = producer;
322 struct context_stack *push_context (int desc, CORE_ADDR valu);
324 struct context_stack pop_context ();
326 struct block *end_compunit_symtab_get_static_block
327 (CORE_ADDR end_addr, int expandable, int required);
329 struct compunit_symtab *end_compunit_symtab_from_static_block
330 (struct block *static_block, int expandable);
332 struct compunit_symtab *end_compunit_symtab (CORE_ADDR end_addr);
334 struct compunit_symtab *end_expandable_symtab (CORE_ADDR end_addr);
336 void augment_type_symtab ();
338 private:
340 void record_pending_block (struct block *block, struct pending_block *opblock);
342 struct block *finish_block_internal (struct symbol *symbol,
343 struct pending **listhead,
344 struct pending_block *old_blocks,
345 const struct dynamic_prop *static_link,
346 CORE_ADDR start, CORE_ADDR end,
347 int is_global, int expandable);
349 struct blockvector *make_blockvector ();
351 void watch_main_source_file_lossage ();
353 struct compunit_symtab *end_compunit_symtab_with_blockvector
354 (struct block *static_block, int expandable);
356 /* The objfile we're reading debug info from. */
357 struct objfile *m_objfile;
359 /* List of subfiles (source files).
360 Files are added to the front of the list.
361 This is important mostly for the language determination hacks we use,
362 which iterate over previously added files. */
363 struct subfile *m_subfiles = nullptr;
365 /* The subfile of the main source file. */
366 struct subfile *m_main_subfile = nullptr;
368 /* Name of source file whose symbol data we are now processing. This
369 comes from a symbol of type N_SO for stabs. For DWARF it comes
370 from the DW_AT_name attribute of a DW_TAG_compile_unit DIE. */
371 gdb::unique_xmalloc_ptr<char> m_last_source_file;
373 /* E.g., DW_AT_comp_dir if DWARF. Space for this is malloc'd. */
374 std::string m_comp_dir;
376 /* Space for this is not malloc'd, and is assumed to have at least
377 the same lifetime as objfile. */
378 const char *m_producer = nullptr;
380 /* Space for this is not malloc'd, and is assumed to have at least
381 the same lifetime as objfile. */
382 const char *m_debugformat = nullptr;
384 /* The compunit we are building. */
385 struct compunit_symtab *m_compunit_symtab = nullptr;
387 /* Language of this compunit_symtab. */
388 enum language m_language;
390 /* The macro table for the compilation unit whose symbols we're
391 currently reading. */
392 struct macro_table *m_pending_macros = nullptr;
394 /* True if symtab has line number info. This prevents an otherwise
395 empty symtab from being tossed. */
396 bool m_have_line_numbers = false;
398 /* Core address of start of text of current source file. This too
399 comes from the N_SO symbol. For Dwarf it typically comes from the
400 DW_AT_low_pc attribute of a DW_TAG_compile_unit DIE. */
401 CORE_ADDR m_last_source_start_addr;
403 /* Stack of subfile names. */
404 std::vector<const char *> m_subfile_stack;
406 /* The "using" directives local to lexical context. */
407 struct using_direct *m_local_using_directives = nullptr;
409 /* Global "using" directives. */
410 struct using_direct *m_global_using_directives = nullptr;
412 /* The stack of contexts that are pushed by push_context and popped
413 by pop_context. */
414 std::vector<struct context_stack> m_context_stack;
416 struct subfile *m_current_subfile = nullptr;
418 /* The mutable address map for the compilation unit whose symbols
419 we're currently reading. The symtabs' shared blockvector will
420 point to a fixed copy of this. */
421 struct addrmap_mutable m_pending_addrmap;
423 /* True if we recorded any ranges in the addrmap that are different
424 from those in the blockvector already. We set this to false when
425 we start processing a symfile, and if it's still false at the
426 end, then we just toss the addrmap. */
427 bool m_pending_addrmap_interesting = false;
429 /* An obstack used for allocating pending blocks. */
430 auto_obstack m_pending_block_obstack;
432 /* Pointer to the head of a linked list of symbol blocks which have
433 already been finalized (lexical contexts already closed) and which
434 are just waiting to be built into a blockvector when finalizing the
435 associated symtab. */
436 struct pending_block *m_pending_blocks = nullptr;
438 /* Pending static symbols and types at the top level. */
439 struct pending *m_file_symbols = nullptr;
441 /* Pending global functions and variables. */
442 struct pending *m_global_symbols = nullptr;
444 /* Pending symbols that are local to the lexical context. */
445 struct pending *m_local_symbols = nullptr;
450 extern void add_symbol_to_list (struct symbol *symbol,
451 struct pending **listhead);
453 extern struct symbol *find_symbol_in_list (struct pending *list,
454 char *name, int length);
456 #endif /* defined (BUILDSYM_H) */