1 /* Build symbol tables in GDB's internal format.
2 Copyright (C) 1986-2018 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)
25 struct compunit_symtab;
28 /* This module provides definitions used for creating and adding to
29 the symbol table. These routines are called from various symbol-
30 file-reading routines.
32 They originated in dbxread.c of gdb-4.2, and were split out to
33 make xcoffread.c more maintainable by sharing code. */
40 /* The list of sub-source-files within the current individual
41 compilation. Each file gets its own symtab with its own linetable
42 and associated info, but they all share one blockvector. */
47 /* Space for this is malloc'd. */
49 /* Space for this is malloc'd. */
50 struct linetable *line_vector;
51 int line_vector_length;
52 /* The "containing" compunit. */
53 struct buildsym_compunit *buildsym_compunit;
54 enum language language;
55 struct symtab *symtab;
58 /* Record the symbols defined for each context in a list. We don't
59 create a struct block for the context until we know how long to
62 #define PENDINGSIZE 100
68 struct symbol *symbol[PENDINGSIZE];
71 /* Stack representing unclosed lexical contexts (that will become
72 blocks, eventually). */
76 /* Outer locals at the time we entered */
78 struct pending *locals;
80 /* Pending using directives at the time we entered. */
82 struct using_direct *local_using_directives;
84 /* Pointer into blocklist as of entry */
86 struct pending_block *old_blocks;
88 /* Name of function, if any, defining context */
92 /* Expression that computes the frame base of the lexically enclosing
93 function, if any. NULL otherwise. */
95 struct dynamic_prop *static_link;
97 /* PC where this context starts */
101 /* Temp slot for exception handling. */
105 /* For error-checking matching push/pop */
111 /* Buildsym's counterpart to struct compunit_symtab. */
113 struct buildsym_compunit
115 /* Start recording information about a primary source file (IOW, not an
116 included source file).
117 COMP_DIR is the directory in which the compilation unit was compiled
118 (or NULL if not known). */
120 buildsym_compunit (struct objfile *objfile_, const char *name,
121 const char *comp_dir_, enum language language_,
122 CORE_ADDR last_addr);
124 /* Reopen an existing compunit_symtab so that additional symbols can
125 be added to it. Arguments are as for the main constructor. CUST
126 is the expandable compunit_symtab to be reopened. */
128 buildsym_compunit (struct objfile *objfile_, const char *name,
129 const char *comp_dir_, enum language language_,
130 CORE_ADDR last_addr, struct compunit_symtab *cust)
131 : m_objfile (objfile_),
132 m_last_source_file (name == nullptr ? nullptr : xstrdup (name)),
133 m_comp_dir (comp_dir_ == nullptr ? nullptr : xstrdup (comp_dir_)),
134 m_compunit_symtab (cust),
135 m_language (language_),
136 m_last_source_start_addr (last_addr)
140 ~buildsym_compunit ();
142 DISABLE_COPY_AND_ASSIGN (buildsym_compunit);
144 void set_last_source_file (const char *name)
146 char *new_name = name == NULL ? NULL : xstrdup (name);
147 m_last_source_file.reset (new_name);
150 const char *get_last_source_file ()
152 return m_last_source_file.get ();
155 struct macro_table *get_macro_table ();
157 struct macro_table *release_macros ()
159 struct macro_table *result = m_pending_macros;
160 m_pending_macros = nullptr;
164 /* This function is called to discard any pending blocks. */
166 void free_pending_blocks ()
168 m_pending_block_obstack.clear ();
169 m_pending_blocks = nullptr;
172 struct block *finish_block (struct symbol *symbol,
173 struct pending_block *old_blocks,
174 const struct dynamic_prop *static_link,
175 CORE_ADDR start, CORE_ADDR end);
177 void record_block_range (struct block *block,
178 CORE_ADDR start, CORE_ADDR end_inclusive);
180 void start_subfile (const char *name);
182 void patch_subfile_names (struct subfile *subfile, const char *name);
184 void push_subfile ();
186 const char *pop_subfile ();
188 void record_line (struct subfile *subfile, int line, CORE_ADDR pc);
190 struct compunit_symtab *get_compunit_symtab ()
192 return m_compunit_symtab;
195 void set_last_source_start_addr (CORE_ADDR addr)
197 m_last_source_start_addr = addr;
200 CORE_ADDR get_last_source_start_addr ()
202 return m_last_source_start_addr;
205 struct using_direct **get_local_using_directives ()
207 return &m_local_using_directives;
210 void set_local_using_directives (struct using_direct *new_local)
212 m_local_using_directives = new_local;
215 struct using_direct **get_global_using_directives ()
217 return &m_global_using_directives;
220 bool outermost_context_p () const
222 return m_context_stack.empty ();
225 struct context_stack *get_current_context_stack ()
227 if (m_context_stack.empty ())
229 return &m_context_stack.back ();
232 int get_context_stack_depth () const
234 return m_context_stack.size ();
237 struct subfile *get_current_subfile ()
239 return m_current_subfile;
242 struct pending **get_local_symbols ()
244 return &m_local_symbols;
247 struct pending **get_file_symbols ()
249 return &m_file_symbols;
252 struct pending **get_global_symbols ()
254 return &m_global_symbols;
257 void record_debugformat (const char *format)
259 m_debugformat = format;
262 void record_producer (const char *producer)
264 m_producer = producer;
267 struct context_stack *push_context (int desc, CORE_ADDR valu);
269 struct context_stack pop_context ();
271 struct block *end_symtab_get_static_block (CORE_ADDR end_addr,
272 int expandable, int required);
274 struct compunit_symtab *end_symtab_from_static_block
275 (struct block *static_block, int section, int expandable);
277 struct compunit_symtab *end_symtab (CORE_ADDR end_addr, int section);
279 struct compunit_symtab *end_expandable_symtab (CORE_ADDR end_addr,
282 void augment_type_symtab ();
286 void record_pending_block (struct block *block, struct pending_block *opblock);
288 struct block *finish_block_internal (struct symbol *symbol,
289 struct pending **listhead,
290 struct pending_block *old_blocks,
291 const struct dynamic_prop *static_link,
292 CORE_ADDR start, CORE_ADDR end,
293 int is_global, int expandable);
295 struct blockvector *make_blockvector ();
297 void watch_main_source_file_lossage ();
299 struct compunit_symtab *end_symtab_with_blockvector
300 (struct block *static_block, int section, int expandable);
302 /* The objfile we're reading debug info from. */
303 struct objfile *m_objfile;
305 /* List of subfiles (source files).
306 Files are added to the front of the list.
307 This is important mostly for the language determination hacks we use,
308 which iterate over previously added files. */
309 struct subfile *m_subfiles = nullptr;
311 /* The subfile of the main source file. */
312 struct subfile *m_main_subfile = nullptr;
314 /* Name of source file whose symbol data we are now processing. This
315 comes from a symbol of type N_SO for stabs. For DWARF it comes
316 from the DW_AT_name attribute of a DW_TAG_compile_unit DIE. */
317 gdb::unique_xmalloc_ptr<char> m_last_source_file;
319 /* E.g., DW_AT_comp_dir if DWARF. Space for this is malloc'd. */
320 gdb::unique_xmalloc_ptr<char> m_comp_dir;
322 /* Space for this is not malloc'd, and is assumed to have at least
323 the same lifetime as objfile. */
324 const char *m_producer = nullptr;
326 /* Space for this is not malloc'd, and is assumed to have at least
327 the same lifetime as objfile. */
328 const char *m_debugformat = nullptr;
330 /* The compunit we are building. */
331 struct compunit_symtab *m_compunit_symtab = nullptr;
333 /* Language of this compunit_symtab. */
334 enum language m_language;
336 /* The macro table for the compilation unit whose symbols we're
337 currently reading. */
338 struct macro_table *m_pending_macros = nullptr;
340 /* True if symtab has line number info. This prevents an otherwise
341 empty symtab from being tossed. */
342 bool m_have_line_numbers = false;
344 /* Core address of start of text of current source file. This too
345 comes from the N_SO symbol. For Dwarf it typically comes from the
346 DW_AT_low_pc attribute of a DW_TAG_compile_unit DIE. */
347 CORE_ADDR m_last_source_start_addr;
349 /* Stack of subfile names. */
350 std::vector<const char *> m_subfile_stack;
352 /* The "using" directives local to lexical context. */
353 struct using_direct *m_local_using_directives = nullptr;
355 /* Global "using" directives. */
356 struct using_direct *m_global_using_directives = nullptr;
358 /* The stack of contexts that are pushed by push_context and popped
360 std::vector<struct context_stack> m_context_stack;
362 struct subfile *m_current_subfile = nullptr;
364 /* The mutable address map for the compilation unit whose symbols
365 we're currently reading. The symtabs' shared blockvector will
366 point to a fixed copy of this. */
367 struct addrmap *m_pending_addrmap = nullptr;
369 /* The obstack on which we allocate pending_addrmap.
370 If pending_addrmap is NULL, this is uninitialized; otherwise, it is
371 initialized (and holds pending_addrmap). */
372 auto_obstack m_pending_addrmap_obstack;
374 /* True if we recorded any ranges in the addrmap that are different
375 from those in the blockvector already. We set this to false when
376 we start processing a symfile, and if it's still false at the
377 end, then we just toss the addrmap. */
378 bool m_pending_addrmap_interesting = false;
380 /* An obstack used for allocating pending blocks. */
381 auto_obstack m_pending_block_obstack;
383 /* Pointer to the head of a linked list of symbol blocks which have
384 already been finalized (lexical contexts already closed) and which
385 are just waiting to be built into a blockvector when finalizing the
386 associated symtab. */
387 struct pending_block *m_pending_blocks = nullptr;
389 /* Pending static symbols and types at the top level. */
390 struct pending *m_file_symbols = nullptr;
392 /* Pending global functions and variables. */
393 struct pending *m_global_symbols = nullptr;
395 /* Pending symbols that are local to the lexical context. */
396 struct pending *m_local_symbols = nullptr;
401 extern void add_symbol_to_list (struct symbol *symbol,
402 struct pending **listhead);
404 extern struct symbol *find_symbol_in_list (struct pending *list,
405 char *name, int length);
407 #endif /* defined (BUILDSYM_H) */