Fix potentially uninitialised variables in the Windows tools
[binutils-gdb.git] / gdb / buildsym.h
1 /* Build symbol tables in GDB's internal format.
2 Copyright (C) 1986-2022 Free Software Foundation, Inc.
3
4 This file is part of GDB.
5
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.
10
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.
15
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/>. */
18
19 #if !defined (BUILDSYM_H)
20 #define BUILDSYM_H 1
21
22 #include "gdbsupport/gdb_obstack.h"
23 #include "symtab.h"
24
25 struct objfile;
26 struct symbol;
27 struct addrmap;
28 struct compunit_symtab;
29 enum language;
30
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.
34
35 They originated in dbxread.c of gdb-4.2, and were split out to
36 make xcoffread.c more maintainable by sharing code. */
37
38 struct block;
39 struct pending_block;
40
41 struct dynamic_prop;
42
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. */
46
47 struct subfile
48 {
49 subfile () = default;
50
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);
54
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;
60 };
61
62 using subfile_up = std::unique_ptr<subfile>;
63
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. */
67
68 #define PENDINGSIZE 100
69
70 struct pending
71 {
72 struct pending *next;
73 int nsyms;
74 struct symbol *symbol[PENDINGSIZE];
75 };
76
77 /* Stack representing unclosed lexical contexts (that will become
78 blocks, eventually). */
79
80 struct context_stack
81 {
82 /* Outer locals at the time we entered */
83
84 struct pending *locals;
85
86 /* Pending using directives at the time we entered. */
87
88 struct using_direct *local_using_directives;
89
90 /* Pointer into blocklist as of entry */
91
92 struct pending_block *old_blocks;
93
94 /* Name of function, if any, defining context */
95
96 struct symbol *name;
97
98 /* Expression that computes the frame base of the lexically enclosing
99 function, if any. NULL otherwise. */
100
101 struct dynamic_prop *static_link;
102
103 /* PC where this context starts */
104
105 CORE_ADDR start_addr;
106
107 /* Temp slot for exception handling. */
108
109 CORE_ADDR end_addr;
110
111 /* For error-checking matching push/pop */
112
113 int depth;
114
115 };
116
117 /* Flags associated with a linetable entry. */
118
119 enum linetable_entry_flag : unsigned
120 {
121 /* Indicates this PC is a good location to place a breakpoint at LINE. */
122 LEF_IS_STMT = 1 << 1,
123
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,
127 };
128 DEF_ENUM_FLAGS_TYPE (enum linetable_entry_flag, linetable_entry_flags);
129
130
131 /* Buildsym's counterpart to struct compunit_symtab. */
132
133 struct buildsym_compunit
134 {
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). */
139
140 buildsym_compunit (struct objfile *objfile_, const char *name,
141 const char *comp_dir_, enum language language_,
142 CORE_ADDR last_addr);
143
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. */
147
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)
157 {
158 }
159
160 ~buildsym_compunit ();
161
162 DISABLE_COPY_AND_ASSIGN (buildsym_compunit);
163
164 void set_last_source_file (const char *name)
165 {
166 char *new_name = name == NULL ? NULL : xstrdup (name);
167 m_last_source_file.reset (new_name);
168 }
169
170 const char *get_last_source_file ()
171 {
172 return m_last_source_file.get ();
173 }
174
175 struct macro_table *get_macro_table ();
176
177 struct macro_table *release_macros ()
178 {
179 struct macro_table *result = m_pending_macros;
180 m_pending_macros = nullptr;
181 return result;
182 }
183
184 /* This function is called to discard any pending blocks. */
185
186 void free_pending_blocks ()
187 {
188 m_pending_block_obstack.clear ();
189 m_pending_blocks = nullptr;
190 }
191
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);
196
197 void record_block_range (struct block *block,
198 CORE_ADDR start, CORE_ADDR end_inclusive);
199
200 void start_subfile (const char *name);
201
202 void patch_subfile_names (struct subfile *subfile, const char *name);
203
204 void push_subfile ();
205
206 const char *pop_subfile ();
207
208 void record_line (struct subfile *subfile, int line, CORE_ADDR pc,
209 linetable_entry_flags flags);
210
211 struct compunit_symtab *get_compunit_symtab ()
212 {
213 return m_compunit_symtab;
214 }
215
216 void set_last_source_start_addr (CORE_ADDR addr)
217 {
218 m_last_source_start_addr = addr;
219 }
220
221 CORE_ADDR get_last_source_start_addr ()
222 {
223 return m_last_source_start_addr;
224 }
225
226 struct using_direct **get_local_using_directives ()
227 {
228 return &m_local_using_directives;
229 }
230
231 void set_local_using_directives (struct using_direct *new_local)
232 {
233 m_local_using_directives = new_local;
234 }
235
236 struct using_direct **get_global_using_directives ()
237 {
238 return &m_global_using_directives;
239 }
240
241 bool outermost_context_p () const
242 {
243 return m_context_stack.empty ();
244 }
245
246 struct context_stack *get_current_context_stack ()
247 {
248 if (m_context_stack.empty ())
249 return nullptr;
250 return &m_context_stack.back ();
251 }
252
253 int get_context_stack_depth () const
254 {
255 return m_context_stack.size ();
256 }
257
258 struct subfile *get_current_subfile ()
259 {
260 return m_current_subfile;
261 }
262
263 struct pending **get_local_symbols ()
264 {
265 return &m_local_symbols;
266 }
267
268 struct pending **get_file_symbols ()
269 {
270 return &m_file_symbols;
271 }
272
273 struct pending **get_global_symbols ()
274 {
275 return &m_global_symbols;
276 }
277
278 void record_debugformat (const char *format)
279 {
280 m_debugformat = format;
281 }
282
283 void record_producer (const char *producer)
284 {
285 m_producer = producer;
286 }
287
288 struct context_stack *push_context (int desc, CORE_ADDR valu);
289
290 struct context_stack pop_context ();
291
292 struct block *end_compunit_symtab_get_static_block
293 (CORE_ADDR end_addr, int expandable, int required);
294
295 struct compunit_symtab *end_compunit_symtab_from_static_block
296 (struct block *static_block, int section, int expandable);
297
298 struct compunit_symtab *end_compunit_symtab (CORE_ADDR end_addr, int section);
299
300 struct compunit_symtab *end_expandable_symtab (CORE_ADDR end_addr,
301 int section);
302
303 void augment_type_symtab ();
304
305 private:
306
307 void record_pending_block (struct block *block, struct pending_block *opblock);
308
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);
315
316 struct blockvector *make_blockvector ();
317
318 void watch_main_source_file_lossage ();
319
320 struct compunit_symtab *end_compunit_symtab_with_blockvector
321 (struct block *static_block, int section, int expandable);
322
323 /* The objfile we're reading debug info from. */
324 struct objfile *m_objfile;
325
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;
331
332 /* The subfile of the main source file. */
333 struct subfile *m_main_subfile = nullptr;
334
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;
339
340 /* E.g., DW_AT_comp_dir if DWARF. Space for this is malloc'd. */
341 std::string m_comp_dir;
342
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;
346
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;
350
351 /* The compunit we are building. */
352 struct compunit_symtab *m_compunit_symtab = nullptr;
353
354 /* Language of this compunit_symtab. */
355 enum language m_language;
356
357 /* The macro table for the compilation unit whose symbols we're
358 currently reading. */
359 struct macro_table *m_pending_macros = nullptr;
360
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;
364
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;
369
370 /* Stack of subfile names. */
371 std::vector<const char *> m_subfile_stack;
372
373 /* The "using" directives local to lexical context. */
374 struct using_direct *m_local_using_directives = nullptr;
375
376 /* Global "using" directives. */
377 struct using_direct *m_global_using_directives = nullptr;
378
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;
382
383 struct subfile *m_current_subfile = nullptr;
384
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;
389
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;
394
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;
400
401 /* An obstack used for allocating pending blocks. */
402 auto_obstack m_pending_block_obstack;
403
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;
409
410 /* Pending static symbols and types at the top level. */
411 struct pending *m_file_symbols = nullptr;
412
413 /* Pending global functions and variables. */
414 struct pending *m_global_symbols = nullptr;
415
416 /* Pending symbols that are local to the lexical context. */
417 struct pending *m_local_symbols = nullptr;
418 };
419
420 \f
421
422 extern void add_symbol_to_list (struct symbol *symbol,
423 struct pending **listhead);
424
425 extern struct symbol *find_symbol_in_list (struct pending *list,
426 char *name, int length);
427
428 #endif /* defined (BUILDSYM_H) */