Change regcache list to be an hash map
[deliverable/binutils-gdb.git] / gdb / buildsym.h
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.
4
5 This file is part of GDB.
6
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.
11
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.
16
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/>. */
19
20 #if !defined (BUILDSYM_H)
21 #define BUILDSYM_H 1
22
23 #include "gdb_obstack.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 struct subfile *next;
50 /* Space for this is malloc'd. */
51 char *name;
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;
59 };
60
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
63 make it. */
64
65 #define PENDINGSIZE 100
66
67 struct pending
68 {
69 struct pending *next;
70 int nsyms;
71 struct symbol *symbol[PENDINGSIZE];
72 };
73
74 /* Stack representing unclosed lexical contexts (that will become
75 blocks, eventually). */
76
77 struct context_stack
78 {
79 /* Outer locals at the time we entered */
80
81 struct pending *locals;
82
83 /* Pending using directives at the time we entered. */
84
85 struct using_direct *local_using_directives;
86
87 /* Pointer into blocklist as of entry */
88
89 struct pending_block *old_blocks;
90
91 /* Name of function, if any, defining context */
92
93 struct symbol *name;
94
95 /* Expression that computes the frame base of the lexically enclosing
96 function, if any. NULL otherwise. */
97
98 struct dynamic_prop *static_link;
99
100 /* PC where this context starts */
101
102 CORE_ADDR start_addr;
103
104 /* Temp slot for exception handling. */
105
106 CORE_ADDR end_addr;
107
108 /* For error-checking matching push/pop */
109
110 int depth;
111
112 };
113
114 /* Buildsym's counterpart to struct compunit_symtab. */
115
116 struct buildsym_compunit
117 {
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). */
122
123 buildsym_compunit (struct objfile *objfile_, const char *name,
124 const char *comp_dir_, enum language language_,
125 CORE_ADDR last_addr);
126
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. */
130
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)
140 {
141 }
142
143 ~buildsym_compunit ();
144
145 DISABLE_COPY_AND_ASSIGN (buildsym_compunit);
146
147 void set_last_source_file (const char *name)
148 {
149 char *new_name = name == NULL ? NULL : xstrdup (name);
150 m_last_source_file.reset (new_name);
151 }
152
153 const char *get_last_source_file ()
154 {
155 return m_last_source_file.get ();
156 }
157
158 struct macro_table *get_macro_table ();
159
160 struct macro_table *release_macros ()
161 {
162 struct macro_table *result = m_pending_macros;
163 m_pending_macros = nullptr;
164 return result;
165 }
166
167 /* This function is called to discard any pending blocks. */
168
169 void free_pending_blocks ()
170 {
171 m_pending_block_obstack.clear ();
172 m_pending_blocks = nullptr;
173 }
174
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);
179
180 void record_block_range (struct block *block,
181 CORE_ADDR start, CORE_ADDR end_inclusive);
182
183 void start_subfile (const char *name);
184
185 void patch_subfile_names (struct subfile *subfile, const char *name);
186
187 void push_subfile ();
188
189 const char *pop_subfile ();
190
191 void record_line (struct subfile *subfile, int line, CORE_ADDR pc);
192
193 struct compunit_symtab *get_compunit_symtab ()
194 {
195 return m_compunit_symtab;
196 }
197
198 void set_last_source_start_addr (CORE_ADDR addr)
199 {
200 m_last_source_start_addr = addr;
201 }
202
203 CORE_ADDR get_last_source_start_addr ()
204 {
205 return m_last_source_start_addr;
206 }
207
208 struct using_direct **get_local_using_directives ()
209 {
210 return &m_local_using_directives;
211 }
212
213 void set_local_using_directives (struct using_direct *new_local)
214 {
215 m_local_using_directives = new_local;
216 }
217
218 struct using_direct **get_global_using_directives ()
219 {
220 return &m_global_using_directives;
221 }
222
223 bool outermost_context_p () const
224 {
225 return m_context_stack.empty ();
226 }
227
228 struct context_stack *get_current_context_stack ()
229 {
230 if (m_context_stack.empty ())
231 return nullptr;
232 return &m_context_stack.back ();
233 }
234
235 int get_context_stack_depth () const
236 {
237 return m_context_stack.size ();
238 }
239
240 struct subfile *get_current_subfile ()
241 {
242 return m_current_subfile;
243 }
244
245 struct pending **get_local_symbols ()
246 {
247 return &m_local_symbols;
248 }
249
250 struct pending **get_file_symbols ()
251 {
252 return &m_file_symbols;
253 }
254
255 struct pending **get_global_symbols ()
256 {
257 return &m_global_symbols;
258 }
259
260 void record_debugformat (const char *format)
261 {
262 m_debugformat = make_unique_xstrdup (format);
263 }
264
265 void record_producer (const char *producer)
266 {
267 m_producer = producer;
268 }
269
270 struct context_stack *push_context (int desc, CORE_ADDR valu);
271
272 struct context_stack pop_context ();
273
274 struct block *end_symtab_get_static_block (CORE_ADDR end_addr,
275 int expandable, int required);
276
277 struct compunit_symtab *end_symtab_from_static_block
278 (struct block *static_block, int section, int expandable);
279
280 struct compunit_symtab *end_symtab (CORE_ADDR end_addr, int section);
281
282 struct compunit_symtab *end_expandable_symtab (CORE_ADDR end_addr,
283 int section);
284
285 void augment_type_symtab ();
286
287 private:
288
289 void record_pending_block (struct block *block, struct pending_block *opblock);
290
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);
297
298 struct blockvector *make_blockvector ();
299
300 void watch_main_source_file_lossage ();
301
302 struct compunit_symtab *end_symtab_with_blockvector
303 (struct block *static_block, int section, int expandable);
304
305 /* The objfile we're reading debug info from. */
306 struct objfile *m_objfile;
307
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;
313
314 /* The subfile of the main source file. */
315 struct subfile *m_main_subfile = nullptr;
316
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;
321
322 /* E.g., DW_AT_comp_dir if DWARF. Space for this is malloc'd. */
323 gdb::unique_xmalloc_ptr<char> m_comp_dir;
324
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;
328
329 /* Space for this is malloc'd. */
330 gdb::unique_xmalloc_ptr<char> m_debugformat;
331
332 /* The compunit we are building. */
333 struct compunit_symtab *m_compunit_symtab = nullptr;
334
335 /* Language of this compunit_symtab. */
336 enum language m_language;
337
338 /* The macro table for the compilation unit whose symbols we're
339 currently reading. */
340 struct macro_table *m_pending_macros = nullptr;
341
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;
345
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;
350
351 /* Stack of subfile names. */
352 std::vector<const char *> m_subfile_stack;
353
354 /* The "using" directives local to lexical context. */
355 struct using_direct *m_local_using_directives = nullptr;
356
357 /* Global "using" directives. */
358 struct using_direct *m_global_using_directives = nullptr;
359
360 /* The stack of contexts that are pushed by push_context and popped
361 by pop_context. */
362 std::vector<struct context_stack> m_context_stack;
363
364 struct subfile *m_current_subfile = nullptr;
365
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;
370
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;
375
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;
381
382 /* An obstack used for allocating pending blocks. */
383 auto_obstack m_pending_block_obstack;
384
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;
390
391 /* Pending static symbols and types at the top level. */
392 struct pending *m_file_symbols = nullptr;
393
394 /* Pending global functions and variables. */
395 struct pending *m_global_symbols = nullptr;
396
397 /* Pending symbols that are local to the lexical context. */
398 struct pending *m_local_symbols = nullptr;
399 };
400
401 \f
402
403 extern void add_symbol_to_list (struct symbol *symbol,
404 struct pending **listhead);
405
406 extern struct symbol *find_symbol_in_list (struct pending *list,
407 char *name, int length);
408
409 #endif /* defined (BUILDSYM_H) */
This page took 0.038059 seconds and 4 git commands to generate.