1 /* Build symbol tables in GDB's internal format.
2 Copyright (C) 1986-2020 Free Software Foundation, Inc.
3 Copyright (C) 2019-2020 Advanced Micro Devices, Inc. All rights reserved.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #if !defined (BUILDSYM_H)
23 #include "gdb_obstack.h"
28 struct compunit_symtab
;
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. */
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. */
50 /* Space for this is malloc'd. */
52 /* Space for this is malloc'd. */
53 struct linetable
*line_vector
;
54 int line_vector_length
;
55 /* The "containing" compunit. */
56 struct buildsym_compunit
*buildsym_compunit
;
57 enum language language
;
58 struct symtab
*symtab
;
61 /* Record the symbols defined for each context in a list. We don't
62 create a struct block for the context until we know how long to
65 #define PENDINGSIZE 100
71 struct symbol
*symbol
[PENDINGSIZE
];
74 /* Stack representing unclosed lexical contexts (that will become
75 blocks, eventually). */
79 /* Outer locals at the time we entered */
81 struct pending
*locals
;
83 /* Pending using directives at the time we entered. */
85 struct using_direct
*local_using_directives
;
87 /* Pointer into blocklist as of entry */
89 struct pending_block
*old_blocks
;
91 /* Name of function, if any, defining context */
95 /* Expression that computes the frame base of the lexically enclosing
96 function, if any. NULL otherwise. */
98 struct dynamic_prop
*static_link
;
100 /* PC where this context starts */
102 CORE_ADDR start_addr
;
104 /* Temp slot for exception handling. */
108 /* For error-checking matching push/pop */
114 /* Buildsym's counterpart to struct compunit_symtab. */
116 struct buildsym_compunit
118 /* Start recording information about a primary source file (IOW, not an
119 included source file).
120 COMP_DIR is the directory in which the compilation unit was compiled
121 (or NULL if not known). */
123 buildsym_compunit (struct objfile
*objfile_
, const char *name
,
124 const char *comp_dir_
, enum language language_
,
125 CORE_ADDR last_addr
);
127 /* Reopen an existing compunit_symtab so that additional symbols can
128 be added to it. Arguments are as for the main constructor. CUST
129 is the expandable compunit_symtab to be reopened. */
131 buildsym_compunit (struct objfile
*objfile_
, const char *name
,
132 const char *comp_dir_
, enum language language_
,
133 CORE_ADDR last_addr
, struct compunit_symtab
*cust
)
134 : m_objfile (objfile_
),
135 m_last_source_file (name
== nullptr ? nullptr : xstrdup (name
)),
136 m_comp_dir (comp_dir_
== nullptr ? nullptr : xstrdup (comp_dir_
)),
137 m_compunit_symtab (cust
),
138 m_language (language_
),
139 m_last_source_start_addr (last_addr
)
143 ~buildsym_compunit ();
145 DISABLE_COPY_AND_ASSIGN (buildsym_compunit
);
147 void set_last_source_file (const char *name
)
149 char *new_name
= name
== NULL
? NULL
: xstrdup (name
);
150 m_last_source_file
.reset (new_name
);
153 const char *get_last_source_file ()
155 return m_last_source_file
.get ();
158 struct macro_table
*get_macro_table ();
160 struct macro_table
*release_macros ()
162 struct macro_table
*result
= m_pending_macros
;
163 m_pending_macros
= nullptr;
167 /* This function is called to discard any pending blocks. */
169 void free_pending_blocks ()
171 m_pending_block_obstack
.clear ();
172 m_pending_blocks
= nullptr;
175 struct block
*finish_block (struct symbol
*symbol
,
176 struct pending_block
*old_blocks
,
177 const struct dynamic_prop
*static_link
,
178 CORE_ADDR start
, CORE_ADDR end
);
180 void record_block_range (struct block
*block
,
181 CORE_ADDR start
, CORE_ADDR end_inclusive
);
183 void start_subfile (const char *name
);
185 void patch_subfile_names (struct subfile
*subfile
, const char *name
);
187 void push_subfile ();
189 const char *pop_subfile ();
191 void record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
);
193 struct compunit_symtab
*get_compunit_symtab ()
195 return m_compunit_symtab
;
198 void set_last_source_start_addr (CORE_ADDR addr
)
200 m_last_source_start_addr
= addr
;
203 CORE_ADDR
get_last_source_start_addr ()
205 return m_last_source_start_addr
;
208 struct using_direct
**get_local_using_directives ()
210 return &m_local_using_directives
;
213 void set_local_using_directives (struct using_direct
*new_local
)
215 m_local_using_directives
= new_local
;
218 struct using_direct
**get_global_using_directives ()
220 return &m_global_using_directives
;
223 bool outermost_context_p () const
225 return m_context_stack
.empty ();
228 struct context_stack
*get_current_context_stack ()
230 if (m_context_stack
.empty ())
232 return &m_context_stack
.back ();
235 int get_context_stack_depth () const
237 return m_context_stack
.size ();
240 struct subfile
*get_current_subfile ()
242 return m_current_subfile
;
245 struct pending
**get_local_symbols ()
247 return &m_local_symbols
;
250 struct pending
**get_file_symbols ()
252 return &m_file_symbols
;
255 struct pending
**get_global_symbols ()
257 return &m_global_symbols
;
260 void record_debugformat (const char *format
)
262 m_debugformat
= make_unique_xstrdup (format
);
265 void record_producer (const char *producer
)
267 m_producer
= producer
;
270 struct context_stack
*push_context (int desc
, CORE_ADDR valu
);
272 struct context_stack
pop_context ();
274 struct block
*end_symtab_get_static_block (CORE_ADDR end_addr
,
275 int expandable
, int required
);
277 struct compunit_symtab
*end_symtab_from_static_block
278 (struct block
*static_block
, int section
, int expandable
);
280 struct compunit_symtab
*end_symtab (CORE_ADDR end_addr
, int section
);
282 struct compunit_symtab
*end_expandable_symtab (CORE_ADDR end_addr
,
285 void augment_type_symtab ();
289 void record_pending_block (struct block
*block
, struct pending_block
*opblock
);
291 struct block
*finish_block_internal (struct symbol
*symbol
,
292 struct pending
**listhead
,
293 struct pending_block
*old_blocks
,
294 const struct dynamic_prop
*static_link
,
295 CORE_ADDR start
, CORE_ADDR end
,
296 int is_global
, int expandable
);
298 struct blockvector
*make_blockvector ();
300 void watch_main_source_file_lossage ();
302 struct compunit_symtab
*end_symtab_with_blockvector
303 (struct block
*static_block
, int section
, int expandable
);
305 /* The objfile we're reading debug info from. */
306 struct objfile
*m_objfile
;
308 /* List of subfiles (source files).
309 Files are added to the front of the list.
310 This is important mostly for the language determination hacks we use,
311 which iterate over previously added files. */
312 struct subfile
*m_subfiles
= nullptr;
314 /* The subfile of the main source file. */
315 struct subfile
*m_main_subfile
= nullptr;
317 /* Name of source file whose symbol data we are now processing. This
318 comes from a symbol of type N_SO for stabs. For DWARF it comes
319 from the DW_AT_name attribute of a DW_TAG_compile_unit DIE. */
320 gdb::unique_xmalloc_ptr
<char> m_last_source_file
;
322 /* E.g., DW_AT_comp_dir if DWARF. Space for this is malloc'd. */
323 gdb::unique_xmalloc_ptr
<char> m_comp_dir
;
325 /* Space for this is not malloc'd, and is assumed to have at least
326 the same lifetime as objfile. */
327 const char *m_producer
= nullptr;
329 /* Space for this is malloc'd. */
330 gdb::unique_xmalloc_ptr
<char> m_debugformat
;
332 /* The compunit we are building. */
333 struct compunit_symtab
*m_compunit_symtab
= nullptr;
335 /* Language of this compunit_symtab. */
336 enum language m_language
;
338 /* The macro table for the compilation unit whose symbols we're
339 currently reading. */
340 struct macro_table
*m_pending_macros
= nullptr;
342 /* True if symtab has line number info. This prevents an otherwise
343 empty symtab from being tossed. */
344 bool m_have_line_numbers
= false;
346 /* Core address of start of text of current source file. This too
347 comes from the N_SO symbol. For Dwarf it typically comes from the
348 DW_AT_low_pc attribute of a DW_TAG_compile_unit DIE. */
349 CORE_ADDR m_last_source_start_addr
;
351 /* Stack of subfile names. */
352 std::vector
<const char *> m_subfile_stack
;
354 /* The "using" directives local to lexical context. */
355 struct using_direct
*m_local_using_directives
= nullptr;
357 /* Global "using" directives. */
358 struct using_direct
*m_global_using_directives
= nullptr;
360 /* The stack of contexts that are pushed by push_context and popped
362 std::vector
<struct context_stack
> m_context_stack
;
364 struct subfile
*m_current_subfile
= nullptr;
366 /* The mutable address map for the compilation unit whose symbols
367 we're currently reading. The symtabs' shared blockvector will
368 point to a fixed copy of this. */
369 struct addrmap
*m_pending_addrmap
= nullptr;
371 /* The obstack on which we allocate pending_addrmap.
372 If pending_addrmap is NULL, this is uninitialized; otherwise, it is
373 initialized (and holds pending_addrmap). */
374 auto_obstack m_pending_addrmap_obstack
;
376 /* True if we recorded any ranges in the addrmap that are different
377 from those in the blockvector already. We set this to false when
378 we start processing a symfile, and if it's still false at the
379 end, then we just toss the addrmap. */
380 bool m_pending_addrmap_interesting
= false;
382 /* An obstack used for allocating pending blocks. */
383 auto_obstack m_pending_block_obstack
;
385 /* Pointer to the head of a linked list of symbol blocks which have
386 already been finalized (lexical contexts already closed) and which
387 are just waiting to be built into a blockvector when finalizing the
388 associated symtab. */
389 struct pending_block
*m_pending_blocks
= nullptr;
391 /* Pending static symbols and types at the top level. */
392 struct pending
*m_file_symbols
= nullptr;
394 /* Pending global functions and variables. */
395 struct pending
*m_global_symbols
= nullptr;
397 /* Pending symbols that are local to the lexical context. */
398 struct pending
*m_local_symbols
= nullptr;
403 extern void add_symbol_to_list (struct symbol
*symbol
,
404 struct pending
**listhead
);
406 extern struct symbol
*find_symbol_in_list (struct pending
*list
,
407 char *name
, int length
);
409 #endif /* defined (BUILDSYM_H) */