Automatic date update in version.in
[binutils-gdb.git] / gdb / buildsym.h
blobc1eed247d259e884278f8c60981daeceb0e7b0fb
1 /* Build 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 #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 compunit_symtab;
29 enum language;
31 /* This module provides definitions used for creating and adding to
32 the symbol table. These routines are called from various symbol-
33 file-reading routines.
35 They originated in dbxread.c of gdb-4.2, and were split out to
36 make xcoffread.c more maintainable by sharing code. */
38 struct block;
39 struct pending_block;
41 struct dynamic_prop;
43 /* The list of sub-source-files within the current individual
44 compilation. Each file gets its own symtab with its own linetable
45 and associated info, but they all share one blockvector. */
47 struct subfile
49 subfile () = default;
51 /* There's nothing wrong with copying a subfile, but we don't need to, so use
52 this to avoid copying one by mistake. */
53 DISABLE_COPY_AND_ASSIGN (subfile);
55 struct subfile *next = nullptr;
56 std::string name;
58 /* This field is analoguous in function to symtab::filename_for_id.
60 It is used to look up existing subfiles in calls to start_subfile. */
61 std::string name_for_id;
63 std::vector<linetable_entry> line_vector_entries;
64 enum language language = language_unknown;
65 struct symtab *symtab = nullptr;
68 using subfile_up = std::unique_ptr<subfile>;
70 /* Record the symbols defined for each context in a list. We don't
71 create a struct block for the context until we know how long to
72 make it. */
74 #define PENDINGSIZE 100
76 struct pending
78 struct pending *next;
79 int nsyms;
80 struct symbol *symbol[PENDINGSIZE];
83 /* Stack representing unclosed lexical contexts (that will become
84 blocks, eventually). */
86 struct context_stack
88 /* Outer locals at the time we entered */
90 struct pending *locals;
92 /* Pending using directives at the time we entered. */
94 struct using_direct *local_using_directives;
96 /* Pointer into blocklist as of entry */
98 struct pending_block *old_blocks;
100 /* Name of function, if any, defining context */
102 struct symbol *name;
104 /* Expression that computes the frame base of the lexically enclosing
105 function, if any. NULL otherwise. */
107 struct dynamic_prop *static_link;
109 /* PC where this context starts */
111 CORE_ADDR start_addr;
113 /* Temp slot for exception handling. */
115 CORE_ADDR end_addr;
117 /* For error-checking matching push/pop */
119 int depth;
123 /* Flags associated with a linetable entry. */
125 enum linetable_entry_flag : unsigned
127 /* Indicates this PC is a good location to place a breakpoint at LINE. */
128 LEF_IS_STMT = 1 << 1,
130 /* Indicates this PC is a good location to place a breakpoint at the first
131 instruction past a function prologue. */
132 LEF_PROLOGUE_END = 1 << 2,
134 /* Indicated that this PC is part of the epilogue of a function, making
135 software watchpoints unreliable. */
136 LEF_EPILOGUE_BEGIN = 1 << 3,
138 DEF_ENUM_FLAGS_TYPE (enum linetable_entry_flag, linetable_entry_flags);
141 /* Buildsym's counterpart to struct compunit_symtab. */
143 struct buildsym_compunit
145 /* Start recording information about a primary source file (IOW, not an
146 included source file).
148 COMP_DIR is the directory in which the compilation unit was compiled
149 (or NULL if not known).
151 NAME and NAME_FOR_ID have the same purpose as for the start_subfile
152 method. */
154 buildsym_compunit (struct objfile *objfile_, const char *name,
155 const char *comp_dir_, const char *name_for_id,
156 enum language language_, CORE_ADDR last_addr);
158 /* Same as above, but passes NAME for NAME_FOR_ID. */
160 buildsym_compunit (struct objfile *objfile_, const char *name,
161 const char *comp_dir_, enum language language_,
162 CORE_ADDR last_addr)
163 : buildsym_compunit (objfile_, name, comp_dir_, name, language_, last_addr)
166 /* Reopen an existing compunit_symtab so that additional symbols can
167 be added to it. Arguments are as for the main constructor. CUST
168 is the expandable compunit_symtab to be reopened. */
170 buildsym_compunit (struct objfile *objfile_, const char *name,
171 const char *comp_dir_, enum language language_,
172 CORE_ADDR last_addr, struct compunit_symtab *cust)
173 : m_objfile (objfile_),
174 m_last_source_file (name == nullptr ? nullptr : xstrdup (name)),
175 m_comp_dir (comp_dir_ == nullptr ? "" : comp_dir_),
176 m_compunit_symtab (cust),
177 m_language (language_),
178 m_last_source_start_addr (last_addr)
182 ~buildsym_compunit ();
184 DISABLE_COPY_AND_ASSIGN (buildsym_compunit);
186 void set_last_source_file (const char *name)
188 char *new_name = name == NULL ? NULL : xstrdup (name);
189 m_last_source_file.reset (new_name);
192 const char *get_last_source_file ()
194 return m_last_source_file.get ();
197 struct macro_table *get_macro_table ();
199 struct macro_table *release_macros ()
201 struct macro_table *result = m_pending_macros;
202 m_pending_macros = nullptr;
203 return result;
206 /* This function is called to discard any pending blocks. */
208 void free_pending_blocks ()
210 m_pending_block_obstack.clear ();
211 m_pending_blocks = nullptr;
214 struct block *finish_block (struct symbol *symbol,
215 struct pending_block *old_blocks,
216 const struct dynamic_prop *static_link,
217 CORE_ADDR start, CORE_ADDR end);
219 void record_block_range (struct block *block,
220 CORE_ADDR start, CORE_ADDR end_inclusive);
222 /* Start recording information about source code that comes from a source
223 file. This sets the current subfile, creating it if necessary.
225 NAME is the user-visible name of the subfile.
227 NAME_FOR_ID is a name that must be stable between the different calls to
228 start_subfile referring to the same file (it is used for looking up
229 existing subfiles). It can be equal to NAME if NAME follows that rule. */
230 void start_subfile (const char *name, const char *name_for_id);
232 /* Same as above, but passes NAME for NAME_FOR_ID. */
234 void start_subfile (const char *name)
236 return start_subfile (name, name);
239 void patch_subfile_names (struct subfile *subfile, const char *name);
241 void push_subfile ();
243 const char *pop_subfile ();
245 void record_line (struct subfile *subfile, int line, unrelocated_addr pc,
246 linetable_entry_flags flags);
248 struct compunit_symtab *get_compunit_symtab ()
250 return m_compunit_symtab;
253 void set_last_source_start_addr (CORE_ADDR addr)
255 m_last_source_start_addr = addr;
258 CORE_ADDR get_last_source_start_addr ()
260 return m_last_source_start_addr;
263 struct using_direct **get_local_using_directives ()
265 return &m_local_using_directives;
268 void set_local_using_directives (struct using_direct *new_local)
270 m_local_using_directives = new_local;
273 struct using_direct **get_global_using_directives ()
275 return &m_global_using_directives;
278 bool outermost_context_p () const
280 return m_context_stack.empty ();
283 struct context_stack *get_current_context_stack ()
285 if (m_context_stack.empty ())
286 return nullptr;
287 return &m_context_stack.back ();
290 int get_context_stack_depth () const
292 return m_context_stack.size ();
295 struct subfile *get_current_subfile ()
297 return m_current_subfile;
300 struct pending **get_local_symbols ()
302 return &m_local_symbols;
305 struct pending **get_file_symbols ()
307 return &m_file_symbols;
310 struct pending **get_global_symbols ()
312 return &m_global_symbols;
315 void record_debugformat (const char *format)
317 m_debugformat = format;
320 void record_producer (const char *producer)
322 m_producer = producer;
325 struct context_stack *push_context (int desc, CORE_ADDR valu);
327 struct context_stack pop_context ();
329 struct block *end_compunit_symtab_get_static_block
330 (CORE_ADDR end_addr, int expandable, int required);
332 struct compunit_symtab *end_compunit_symtab_from_static_block
333 (struct block *static_block, int expandable);
335 struct compunit_symtab *end_compunit_symtab (CORE_ADDR end_addr);
337 struct compunit_symtab *end_expandable_symtab (CORE_ADDR end_addr);
339 void augment_type_symtab ();
341 private:
343 void record_pending_block (struct block *block, struct pending_block *opblock);
345 struct block *finish_block_internal (struct symbol *symbol,
346 struct pending **listhead,
347 struct pending_block *old_blocks,
348 const struct dynamic_prop *static_link,
349 CORE_ADDR start, CORE_ADDR end,
350 int is_global, int expandable);
352 struct blockvector *make_blockvector ();
354 void watch_main_source_file_lossage ();
356 struct compunit_symtab *end_compunit_symtab_with_blockvector
357 (struct block *static_block, int expandable);
359 /* The objfile we're reading debug info from. */
360 struct objfile *m_objfile;
362 /* List of subfiles (source files).
363 Files are added to the front of the list.
364 This is important mostly for the language determination hacks we use,
365 which iterate over previously added files. */
366 struct subfile *m_subfiles = nullptr;
368 /* The subfile of the main source file. */
369 struct subfile *m_main_subfile = nullptr;
371 /* Name of source file whose symbol data we are now processing. This
372 comes from a symbol of type N_SO for stabs. For DWARF it comes
373 from the DW_AT_name attribute of a DW_TAG_compile_unit DIE. */
374 gdb::unique_xmalloc_ptr<char> m_last_source_file;
376 /* E.g., DW_AT_comp_dir if DWARF. Space for this is malloc'd. */
377 std::string m_comp_dir;
379 /* Space for this is not malloc'd, and is assumed to have at least
380 the same lifetime as objfile. */
381 const char *m_producer = nullptr;
383 /* Space for this is not malloc'd, and is assumed to have at least
384 the same lifetime as objfile. */
385 const char *m_debugformat = nullptr;
387 /* The compunit we are building. */
388 struct compunit_symtab *m_compunit_symtab = nullptr;
390 /* Language of this compunit_symtab. */
391 enum language m_language;
393 /* The macro table for the compilation unit whose symbols we're
394 currently reading. */
395 struct macro_table *m_pending_macros = nullptr;
397 /* True if symtab has line number info. This prevents an otherwise
398 empty symtab from being tossed. */
399 bool m_have_line_numbers = false;
401 /* Core address of start of text of current source file. This too
402 comes from the N_SO symbol. For Dwarf it typically comes from the
403 DW_AT_low_pc attribute of a DW_TAG_compile_unit DIE. */
404 CORE_ADDR m_last_source_start_addr;
406 /* Stack of subfile names. */
407 std::vector<const char *> m_subfile_stack;
409 /* The "using" directives local to lexical context. */
410 struct using_direct *m_local_using_directives = nullptr;
412 /* Global "using" directives. */
413 struct using_direct *m_global_using_directives = nullptr;
415 /* The stack of contexts that are pushed by push_context and popped
416 by pop_context. */
417 std::vector<struct context_stack> m_context_stack;
419 struct subfile *m_current_subfile = nullptr;
421 /* The mutable address map for the compilation unit whose symbols
422 we're currently reading. The symtabs' shared blockvector will
423 point to a fixed copy of this. */
424 struct addrmap_mutable m_pending_addrmap;
426 /* True if we recorded any ranges in the addrmap that are different
427 from those in the blockvector already. We set this to false when
428 we start processing a symfile, and if it's still false at the
429 end, then we just toss the addrmap. */
430 bool m_pending_addrmap_interesting = false;
432 /* An obstack used for allocating pending blocks. */
433 auto_obstack m_pending_block_obstack;
435 /* Pointer to the head of a linked list of symbol blocks which have
436 already been finalized (lexical contexts already closed) and which
437 are just waiting to be built into a blockvector when finalizing the
438 associated symtab. */
439 struct pending_block *m_pending_blocks = nullptr;
441 /* Pending static symbols and types at the top level. */
442 struct pending *m_file_symbols = nullptr;
444 /* Pending global functions and variables. */
445 struct pending *m_global_symbols = nullptr;
447 /* Pending symbols that are local to the lexical context. */
448 struct pending *m_local_symbols = nullptr;
453 extern void add_symbol_to_list (struct symbol *symbol,
454 struct pending **listhead);
456 extern struct symbol *find_symbol_in_list (struct pending *list,
457 char *name, int length);
459 #endif /* defined (BUILDSYM_H) */