gdb/testsuite: fix gdb.trace/signal.exp on x86
[binutils-gdb/blckswan.git] / gdb / buildsym.h
blobee75e6fd95d355865bbbcb6e910d9057aa124c51
1 /* Build symbol tables in GDB's internal format.
2 Copyright (C) 1986-2022 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"
25 struct objfile;
26 struct symbol;
27 struct addrmap;
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;
57 std::vector<linetable_entry> line_vector_entries;
58 enum language language = language_unknown;
59 struct symtab *symtab = nullptr;
62 using subfile_up = std::unique_ptr<subfile>;
64 /* Record the symbols defined for each context in a list. We don't
65 create a struct block for the context until we know how long to
66 make it. */
68 #define PENDINGSIZE 100
70 struct pending
72 struct pending *next;
73 int nsyms;
74 struct symbol *symbol[PENDINGSIZE];
77 /* Stack representing unclosed lexical contexts (that will become
78 blocks, eventually). */
80 struct context_stack
82 /* Outer locals at the time we entered */
84 struct pending *locals;
86 /* Pending using directives at the time we entered. */
88 struct using_direct *local_using_directives;
90 /* Pointer into blocklist as of entry */
92 struct pending_block *old_blocks;
94 /* Name of function, if any, defining context */
96 struct symbol *name;
98 /* Expression that computes the frame base of the lexically enclosing
99 function, if any. NULL otherwise. */
101 struct dynamic_prop *static_link;
103 /* PC where this context starts */
105 CORE_ADDR start_addr;
107 /* Temp slot for exception handling. */
109 CORE_ADDR end_addr;
111 /* For error-checking matching push/pop */
113 int depth;
117 /* Flags associated with a linetable entry. */
119 enum linetable_entry_flag : unsigned
121 /* Indicates this PC is a good location to place a breakpoint at LINE. */
122 LEF_IS_STMT = 1 << 1,
124 /* Indicates this PC is a good location to place a breakpoint at the first
125 instruction past a function prologue. */
126 LEF_PROLOGUE_END = 1 << 2,
128 DEF_ENUM_FLAGS_TYPE (enum linetable_entry_flag, linetable_entry_flags);
131 /* Buildsym's counterpart to struct compunit_symtab. */
133 struct buildsym_compunit
135 /* Start recording information about a primary source file (IOW, not an
136 included source file).
137 COMP_DIR is the directory in which the compilation unit was compiled
138 (or NULL if not known). */
140 buildsym_compunit (struct objfile *objfile_, const char *name,
141 const char *comp_dir_, enum language language_,
142 CORE_ADDR last_addr);
144 /* Reopen an existing compunit_symtab so that additional symbols can
145 be added to it. Arguments are as for the main constructor. CUST
146 is the expandable compunit_symtab to be reopened. */
148 buildsym_compunit (struct objfile *objfile_, const char *name,
149 const char *comp_dir_, enum language language_,
150 CORE_ADDR last_addr, struct compunit_symtab *cust)
151 : m_objfile (objfile_),
152 m_last_source_file (name == nullptr ? nullptr : xstrdup (name)),
153 m_comp_dir (comp_dir_ == nullptr ? "" : comp_dir_),
154 m_compunit_symtab (cust),
155 m_language (language_),
156 m_last_source_start_addr (last_addr)
160 ~buildsym_compunit ();
162 DISABLE_COPY_AND_ASSIGN (buildsym_compunit);
164 void set_last_source_file (const char *name)
166 char *new_name = name == NULL ? NULL : xstrdup (name);
167 m_last_source_file.reset (new_name);
170 const char *get_last_source_file ()
172 return m_last_source_file.get ();
175 struct macro_table *get_macro_table ();
177 struct macro_table *release_macros ()
179 struct macro_table *result = m_pending_macros;
180 m_pending_macros = nullptr;
181 return result;
184 /* This function is called to discard any pending blocks. */
186 void free_pending_blocks ()
188 m_pending_block_obstack.clear ();
189 m_pending_blocks = nullptr;
192 struct block *finish_block (struct symbol *symbol,
193 struct pending_block *old_blocks,
194 const struct dynamic_prop *static_link,
195 CORE_ADDR start, CORE_ADDR end);
197 void record_block_range (struct block *block,
198 CORE_ADDR start, CORE_ADDR end_inclusive);
200 void start_subfile (const char *name);
202 void patch_subfile_names (struct subfile *subfile, const char *name);
204 void push_subfile ();
206 const char *pop_subfile ();
208 void record_line (struct subfile *subfile, int line, CORE_ADDR pc,
209 linetable_entry_flags flags);
211 struct compunit_symtab *get_compunit_symtab ()
213 return m_compunit_symtab;
216 void set_last_source_start_addr (CORE_ADDR addr)
218 m_last_source_start_addr = addr;
221 CORE_ADDR get_last_source_start_addr ()
223 return m_last_source_start_addr;
226 struct using_direct **get_local_using_directives ()
228 return &m_local_using_directives;
231 void set_local_using_directives (struct using_direct *new_local)
233 m_local_using_directives = new_local;
236 struct using_direct **get_global_using_directives ()
238 return &m_global_using_directives;
241 bool outermost_context_p () const
243 return m_context_stack.empty ();
246 struct context_stack *get_current_context_stack ()
248 if (m_context_stack.empty ())
249 return nullptr;
250 return &m_context_stack.back ();
253 int get_context_stack_depth () const
255 return m_context_stack.size ();
258 struct subfile *get_current_subfile ()
260 return m_current_subfile;
263 struct pending **get_local_symbols ()
265 return &m_local_symbols;
268 struct pending **get_file_symbols ()
270 return &m_file_symbols;
273 struct pending **get_global_symbols ()
275 return &m_global_symbols;
278 void record_debugformat (const char *format)
280 m_debugformat = format;
283 void record_producer (const char *producer)
285 m_producer = producer;
288 struct context_stack *push_context (int desc, CORE_ADDR valu);
290 struct context_stack pop_context ();
292 struct block *end_compunit_symtab_get_static_block
293 (CORE_ADDR end_addr, int expandable, int required);
295 struct compunit_symtab *end_compunit_symtab_from_static_block
296 (struct block *static_block, int section, int expandable);
298 struct compunit_symtab *end_compunit_symtab (CORE_ADDR end_addr, int section);
300 struct compunit_symtab *end_expandable_symtab (CORE_ADDR end_addr,
301 int section);
303 void augment_type_symtab ();
305 private:
307 void record_pending_block (struct block *block, struct pending_block *opblock);
309 struct block *finish_block_internal (struct symbol *symbol,
310 struct pending **listhead,
311 struct pending_block *old_blocks,
312 const struct dynamic_prop *static_link,
313 CORE_ADDR start, CORE_ADDR end,
314 int is_global, int expandable);
316 struct blockvector *make_blockvector ();
318 void watch_main_source_file_lossage ();
320 struct compunit_symtab *end_compunit_symtab_with_blockvector
321 (struct block *static_block, int section, int expandable);
323 /* The objfile we're reading debug info from. */
324 struct objfile *m_objfile;
326 /* List of subfiles (source files).
327 Files are added to the front of the list.
328 This is important mostly for the language determination hacks we use,
329 which iterate over previously added files. */
330 struct subfile *m_subfiles = nullptr;
332 /* The subfile of the main source file. */
333 struct subfile *m_main_subfile = nullptr;
335 /* Name of source file whose symbol data we are now processing. This
336 comes from a symbol of type N_SO for stabs. For DWARF it comes
337 from the DW_AT_name attribute of a DW_TAG_compile_unit DIE. */
338 gdb::unique_xmalloc_ptr<char> m_last_source_file;
340 /* E.g., DW_AT_comp_dir if DWARF. Space for this is malloc'd. */
341 std::string m_comp_dir;
343 /* Space for this is not malloc'd, and is assumed to have at least
344 the same lifetime as objfile. */
345 const char *m_producer = nullptr;
347 /* Space for this is not malloc'd, and is assumed to have at least
348 the same lifetime as objfile. */
349 const char *m_debugformat = nullptr;
351 /* The compunit we are building. */
352 struct compunit_symtab *m_compunit_symtab = nullptr;
354 /* Language of this compunit_symtab. */
355 enum language m_language;
357 /* The macro table for the compilation unit whose symbols we're
358 currently reading. */
359 struct macro_table *m_pending_macros = nullptr;
361 /* True if symtab has line number info. This prevents an otherwise
362 empty symtab from being tossed. */
363 bool m_have_line_numbers = false;
365 /* Core address of start of text of current source file. This too
366 comes from the N_SO symbol. For Dwarf it typically comes from the
367 DW_AT_low_pc attribute of a DW_TAG_compile_unit DIE. */
368 CORE_ADDR m_last_source_start_addr;
370 /* Stack of subfile names. */
371 std::vector<const char *> m_subfile_stack;
373 /* The "using" directives local to lexical context. */
374 struct using_direct *m_local_using_directives = nullptr;
376 /* Global "using" directives. */
377 struct using_direct *m_global_using_directives = nullptr;
379 /* The stack of contexts that are pushed by push_context and popped
380 by pop_context. */
381 std::vector<struct context_stack> m_context_stack;
383 struct subfile *m_current_subfile = nullptr;
385 /* The mutable address map for the compilation unit whose symbols
386 we're currently reading. The symtabs' shared blockvector will
387 point to a fixed copy of this. */
388 struct addrmap *m_pending_addrmap = nullptr;
390 /* The obstack on which we allocate pending_addrmap.
391 If pending_addrmap is NULL, this is uninitialized; otherwise, it is
392 initialized (and holds pending_addrmap). */
393 auto_obstack m_pending_addrmap_obstack;
395 /* True if we recorded any ranges in the addrmap that are different
396 from those in the blockvector already. We set this to false when
397 we start processing a symfile, and if it's still false at the
398 end, then we just toss the addrmap. */
399 bool m_pending_addrmap_interesting = false;
401 /* An obstack used for allocating pending blocks. */
402 auto_obstack m_pending_block_obstack;
404 /* Pointer to the head of a linked list of symbol blocks which have
405 already been finalized (lexical contexts already closed) and which
406 are just waiting to be built into a blockvector when finalizing the
407 associated symtab. */
408 struct pending_block *m_pending_blocks = nullptr;
410 /* Pending static symbols and types at the top level. */
411 struct pending *m_file_symbols = nullptr;
413 /* Pending global functions and variables. */
414 struct pending *m_global_symbols = nullptr;
416 /* Pending symbols that are local to the lexical context. */
417 struct pending *m_local_symbols = nullptr;
422 extern void add_symbol_to_list (struct symbol *symbol,
423 struct pending **listhead);
425 extern struct symbol *find_symbol_in_list (struct pending *list,
426 char *name, int length);
428 #endif /* defined (BUILDSYM_H) */