Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Build symbol tables in GDB's internal format. |
e2882c85 | 2 | Copyright (C) 1986-2018 Free Software Foundation, Inc. |
c906108c | 3 | |
c5aa993b JM |
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 | |
a9762ec7 | 8 | the Free Software Foundation; either version 3 of the License, or |
c5aa993b JM |
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 | |
a9762ec7 | 17 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
18 | |
19 | #if !defined (BUILDSYM_H) | |
20 | #define BUILDSYM_H 1 | |
21 | ||
da3331ec AC |
22 | struct objfile; |
23 | struct symbol; | |
801e3a5b | 24 | struct addrmap; |
43f3e411 | 25 | struct compunit_symtab; |
5ffa0793 | 26 | enum language; |
da3331ec | 27 | |
c906108c SS |
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. | |
31 | ||
32 | They originated in dbxread.c of gdb-4.2, and were split out to | |
b80a981d | 33 | make xcoffread.c more maintainable by sharing code. */ |
c906108c | 34 | |
fe898f56 | 35 | struct block; |
93eed41f | 36 | struct pending_block; |
fe898f56 | 37 | |
63e43d3a PMR |
38 | struct dynamic_prop; |
39 | ||
c906108c SS |
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. */ | |
43 | ||
44 | struct subfile | |
43f3e411 DE |
45 | { |
46 | struct subfile *next; | |
47 | /* Space for this is malloc'd. */ | |
48 | char *name; | |
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; | |
56 | }; | |
c906108c | 57 | |
c906108c SS |
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 | |
60 | make it. */ | |
61 | ||
62 | #define PENDINGSIZE 100 | |
63 | ||
64 | struct pending | |
65 | { | |
66 | struct pending *next; | |
67 | int nsyms; | |
68 | struct symbol *symbol[PENDINGSIZE]; | |
69 | }; | |
70 | ||
c906108c SS |
71 | /* Stack representing unclosed lexical contexts (that will become |
72 | blocks, eventually). */ | |
73 | ||
74 | struct context_stack | |
75 | { | |
76 | /* Outer locals at the time we entered */ | |
77 | ||
78 | struct pending *locals; | |
79 | ||
27aa8d6a SW |
80 | /* Pending using directives at the time we entered. */ |
81 | ||
22cee43f | 82 | struct using_direct *local_using_directives; |
27aa8d6a | 83 | |
c906108c SS |
84 | /* Pointer into blocklist as of entry */ |
85 | ||
86 | struct pending_block *old_blocks; | |
87 | ||
88 | /* Name of function, if any, defining context */ | |
89 | ||
90 | struct symbol *name; | |
91 | ||
63e43d3a PMR |
92 | /* Expression that computes the frame base of the lexically enclosing |
93 | function, if any. NULL otherwise. */ | |
94 | ||
95 | struct dynamic_prop *static_link; | |
96 | ||
c906108c SS |
97 | /* PC where this context starts */ |
98 | ||
99 | CORE_ADDR start_addr; | |
100 | ||
0e2de366 | 101 | /* Temp slot for exception handling. */ |
c906108c SS |
102 | |
103 | CORE_ADDR end_addr; | |
104 | ||
105 | /* For error-checking matching push/pop */ | |
106 | ||
107 | int depth; | |
108 | ||
109 | }; | |
110 | ||
ab209f6f TT |
111 | /* Buildsym's counterpart to struct compunit_symtab. */ |
112 | ||
113 | struct buildsym_compunit | |
114 | { | |
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). */ | |
119 | ||
120 | buildsym_compunit (struct objfile *objfile_, const char *name, | |
121 | const char *comp_dir_, enum language language_, | |
122 | CORE_ADDR last_addr); | |
123 | ||
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. */ | |
127 | ||
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 | : objfile (objfile_), | |
132 | m_last_source_file (name == nullptr ? nullptr : xstrdup (name)), | |
133 | comp_dir (comp_dir_ == nullptr ? nullptr : xstrdup (comp_dir_)), | |
134 | compunit_symtab (cust), | |
135 | language (language_), | |
136 | m_last_source_start_addr (last_addr) | |
137 | { | |
138 | } | |
139 | ||
140 | ~buildsym_compunit (); | |
141 | ||
142 | DISABLE_COPY_AND_ASSIGN (buildsym_compunit); | |
143 | ||
144 | void set_last_source_file (const char *name) | |
145 | { | |
146 | char *new_name = name == NULL ? NULL : xstrdup (name); | |
147 | m_last_source_file.reset (new_name); | |
148 | } | |
149 | ||
150 | const char *get_last_source_file () | |
151 | { | |
152 | return m_last_source_file.get (); | |
153 | } | |
154 | ||
155 | struct macro_table *get_macro_table (); | |
156 | ||
157 | struct macro_table *release_macros () | |
158 | { | |
159 | struct macro_table *result = m_pending_macros; | |
160 | m_pending_macros = nullptr; | |
161 | return result; | |
162 | } | |
163 | ||
164 | /* This function is called to discard any pending blocks. */ | |
165 | ||
166 | void free_pending_blocks () | |
167 | { | |
168 | m_pending_block_obstack.clear (); | |
169 | m_pending_blocks = nullptr; | |
170 | } | |
171 | ||
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); | |
176 | ||
177 | void record_block_range (struct block *block, | |
178 | CORE_ADDR start, CORE_ADDR end_inclusive); | |
179 | ||
180 | void start_subfile (const char *name); | |
181 | ||
182 | void patch_subfile_names (struct subfile *subfile, const char *name); | |
183 | ||
184 | void push_subfile (); | |
185 | ||
186 | const char *pop_subfile (); | |
187 | ||
188 | void record_line (struct subfile *subfile, int line, CORE_ADDR pc); | |
189 | ||
190 | struct compunit_symtab *get_compunit_symtab () | |
191 | { | |
192 | return compunit_symtab; | |
193 | } | |
194 | ||
195 | void set_last_source_start_addr (CORE_ADDR addr) | |
196 | { | |
197 | m_last_source_start_addr = addr; | |
198 | } | |
199 | ||
200 | CORE_ADDR get_last_source_start_addr () | |
201 | { | |
202 | return m_last_source_start_addr; | |
203 | } | |
204 | ||
205 | struct using_direct **get_local_using_directives () | |
206 | { | |
207 | return &m_local_using_directives; | |
208 | } | |
209 | ||
210 | void set_local_using_directives (struct using_direct *new_local) | |
211 | { | |
212 | m_local_using_directives = new_local; | |
213 | } | |
214 | ||
215 | struct using_direct **get_global_using_directives () | |
216 | { | |
217 | return &m_global_using_directives; | |
218 | } | |
219 | ||
220 | bool outermost_context_p () const | |
221 | { | |
222 | return m_context_stack.empty (); | |
223 | } | |
224 | ||
225 | struct context_stack *get_current_context_stack () | |
226 | { | |
227 | if (m_context_stack.empty ()) | |
228 | return nullptr; | |
229 | return &m_context_stack.back (); | |
230 | } | |
231 | ||
232 | int get_context_stack_depth () const | |
233 | { | |
234 | return m_context_stack.size (); | |
235 | } | |
236 | ||
237 | struct subfile *get_current_subfile () | |
238 | { | |
239 | return m_current_subfile; | |
240 | } | |
241 | ||
242 | struct pending **get_local_symbols () | |
243 | { | |
244 | return &m_local_symbols; | |
245 | } | |
246 | ||
247 | struct pending **get_file_symbols () | |
248 | { | |
249 | return &m_file_symbols; | |
250 | } | |
251 | ||
252 | struct pending **get_global_symbols () | |
253 | { | |
254 | return &m_global_symbols; | |
255 | } | |
256 | ||
257 | void record_debugformat (const char *format) | |
258 | { | |
259 | debugformat = format; | |
260 | } | |
261 | ||
262 | void record_producer (const char *producer) | |
263 | { | |
264 | this->producer = producer; | |
265 | } | |
266 | ||
267 | struct context_stack *push_context (int desc, CORE_ADDR valu); | |
268 | ||
269 | struct context_stack pop_context (); | |
270 | ||
271 | struct block *end_symtab_get_static_block (CORE_ADDR end_addr, | |
272 | int expandable, int required); | |
273 | ||
274 | struct compunit_symtab *end_symtab_from_static_block | |
275 | (struct block *static_block, int section, int expandable); | |
276 | ||
277 | struct compunit_symtab *end_symtab (CORE_ADDR end_addr, int section); | |
278 | ||
279 | struct compunit_symtab *end_expandable_symtab (CORE_ADDR end_addr, | |
280 | int section); | |
281 | ||
282 | void augment_type_symtab (); | |
283 | ||
284 | private: | |
285 | ||
286 | void record_pending_block (struct block *block, struct pending_block *opblock); | |
287 | ||
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); | |
294 | ||
295 | struct blockvector *make_blockvector (); | |
296 | ||
297 | void watch_main_source_file_lossage (); | |
298 | ||
299 | struct compunit_symtab *end_symtab_with_blockvector | |
300 | (struct block *static_block, int section, int expandable); | |
301 | ||
302 | /* The objfile we're reading debug info from. */ | |
303 | struct objfile *objfile; | |
304 | ||
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 *subfiles = nullptr; | |
310 | ||
311 | /* The subfile of the main source file. */ | |
312 | struct subfile *main_subfile = nullptr; | |
313 | ||
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; | |
318 | ||
319 | /* E.g., DW_AT_comp_dir if DWARF. Space for this is malloc'd. */ | |
320 | gdb::unique_xmalloc_ptr<char> comp_dir; | |
321 | ||
322 | /* Space for this is not malloc'd, and is assumed to have at least | |
323 | the same lifetime as objfile. */ | |
324 | const char *producer = nullptr; | |
325 | ||
326 | /* Space for this is not malloc'd, and is assumed to have at least | |
327 | the same lifetime as objfile. */ | |
328 | const char *debugformat = nullptr; | |
329 | ||
330 | /* The compunit we are building. */ | |
331 | struct compunit_symtab *compunit_symtab = nullptr; | |
332 | ||
333 | /* Language of this compunit_symtab. */ | |
334 | enum language language; | |
335 | ||
336 | /* The macro table for the compilation unit whose symbols we're | |
337 | currently reading. */ | |
338 | struct macro_table *m_pending_macros = nullptr; | |
339 | ||
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; | |
343 | ||
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; | |
348 | ||
349 | /* Stack of subfile names. */ | |
350 | std::vector<const char *> m_subfile_stack; | |
351 | ||
352 | /* The "using" directives local to lexical context. */ | |
353 | struct using_direct *m_local_using_directives = nullptr; | |
354 | ||
355 | /* Global "using" directives. */ | |
356 | struct using_direct *m_global_using_directives = nullptr; | |
357 | ||
358 | /* The stack of contexts that are pushed by push_context and popped | |
359 | by pop_context. */ | |
360 | std::vector<struct context_stack> m_context_stack; | |
361 | ||
362 | struct subfile *m_current_subfile = nullptr; | |
363 | ||
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; | |
368 | ||
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; | |
373 | ||
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; | |
379 | ||
380 | /* An obstack used for allocating pending blocks. */ | |
381 | auto_obstack m_pending_block_obstack; | |
382 | ||
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; | |
388 | ||
389 | /* Pending static symbols and types at the top level. */ | |
390 | struct pending *m_file_symbols = nullptr; | |
391 | ||
392 | /* Pending global functions and variables. */ | |
393 | struct pending *m_global_symbols = nullptr; | |
394 | ||
395 | /* Pending symbols that are local to the lexical context. */ | |
396 | struct pending *m_local_symbols = nullptr; | |
397 | }; | |
398 | ||
252a6764 DE |
399 | /* The type of the record_line function. */ |
400 | typedef void (record_line_ftype) (struct subfile *subfile, int line, | |
401 | CORE_ADDR pc); | |
402 | ||
c906108c SS |
403 | \f |
404 | ||
c906108c SS |
405 | extern void add_symbol_to_list (struct symbol *symbol, |
406 | struct pending **listhead); | |
407 | ||
408 | extern struct symbol *find_symbol_in_list (struct pending *list, | |
409 | char *name, int length); | |
410 | ||
801e3a5b | 411 | extern struct block *finish_block (struct symbol *symbol, |
63e43d3a PMR |
412 | struct pending_block *old_blocks, |
413 | const struct dynamic_prop *static_link, | |
414 | CORE_ADDR start, | |
415 | CORE_ADDR end); | |
801e3a5b JB |
416 | |
417 | extern void record_block_range (struct block *, | |
418 | CORE_ADDR start, CORE_ADDR end_inclusive); | |
c906108c | 419 | |
33c7c59d TT |
420 | class scoped_free_pendings |
421 | { | |
422 | public: | |
423 | ||
5ac04550 | 424 | scoped_free_pendings () = default; |
33c7c59d TT |
425 | ~scoped_free_pendings (); |
426 | ||
427 | DISABLE_COPY_AND_ASSIGN (scoped_free_pendings); | |
428 | }; | |
c906108c | 429 | |
4d663531 | 430 | extern void start_subfile (const char *name); |
c906108c | 431 | |
a121b7c1 | 432 | extern void patch_subfile_names (struct subfile *subfile, const char *name); |
c906108c | 433 | |
8419ee53 | 434 | extern void push_subfile (); |
c906108c | 435 | |
8419ee53 | 436 | extern const char *pop_subfile (); |
c906108c | 437 | |
4359dff1 | 438 | extern struct block *end_symtab_get_static_block (CORE_ADDR end_addr, |
36586728 TT |
439 | int expandable, |
440 | int required); | |
4359dff1 | 441 | |
43f3e411 DE |
442 | extern struct compunit_symtab * |
443 | end_symtab_from_static_block (struct block *static_block, | |
444 | int section, int expandable); | |
4359dff1 | 445 | |
43f3e411 | 446 | extern struct compunit_symtab *end_symtab (CORE_ADDR end_addr, int section); |
c906108c | 447 | |
43f3e411 DE |
448 | extern struct compunit_symtab *end_expandable_symtab (CORE_ADDR end_addr, |
449 | int section); | |
6d30eef8 | 450 | |
0ab9ce85 | 451 | extern void augment_type_symtab (void); |
6d30eef8 | 452 | |
c906108c SS |
453 | extern struct context_stack *push_context (int desc, CORE_ADDR valu); |
454 | ||
a60f3166 | 455 | extern struct context_stack pop_context (); |
0c5e171a | 456 | |
252a6764 | 457 | extern record_line_ftype record_line; |
c906108c | 458 | |
43f3e411 DE |
459 | extern struct compunit_symtab *start_symtab (struct objfile *objfile, |
460 | const char *name, | |
461 | const char *comp_dir, | |
5ffa0793 PA |
462 | CORE_ADDR start_addr, |
463 | enum language language); | |
c906108c | 464 | |
0ab9ce85 DE |
465 | extern void restart_symtab (struct compunit_symtab *cust, |
466 | const char *name, CORE_ADDR start_addr); | |
6d30eef8 | 467 | |
554d387d TT |
468 | /* Record the name of the debug format in the current pending symbol |
469 | table. FORMAT must be a string with a lifetime at least as long as | |
470 | the symtab's objfile. */ | |
471 | ||
472 | extern void record_debugformat (const char *format); | |
473 | ||
474 | /* Record the name of the debuginfo producer (usually the compiler) in | |
475 | the current pending symbol table. PRODUCER must be a string with a | |
476 | lifetime at least as long as the symtab's objfile. */ | |
c906108c | 477 | |
303b6f5d DJ |
478 | extern void record_producer (const char *producer); |
479 | ||
46212e0b TT |
480 | /* Set the name of the last source file. NAME is copied by this |
481 | function. */ | |
482 | ||
483 | extern void set_last_source_file (const char *name); | |
484 | ||
485 | /* Fetch the name of the last source file. */ | |
486 | ||
487 | extern const char *get_last_source_file (void); | |
488 | ||
43f3e411 DE |
489 | /* Return the compunit symtab object. |
490 | It is only valid to call this between calls to start_symtab and the | |
491 | end_symtab* functions. */ | |
492 | ||
493 | extern struct compunit_symtab *buildsym_compunit_symtab (void); | |
494 | ||
495 | /* Return the macro table. | |
496 | Initialize it if this is the first use. | |
497 | It is only valid to call this between calls to start_symtab and the | |
498 | end_symtab* functions. */ | |
fc474241 | 499 | |
43f3e411 | 500 | extern struct macro_table *get_macro_table (void); |
99d9066e | 501 | |
2c99ee5c TT |
502 | /* Set the last source start address. Can only be used between |
503 | start_symtab and end_symtab* calls. */ | |
504 | ||
505 | extern void set_last_source_start_addr (CORE_ADDR addr); | |
506 | ||
507 | /* Get the last source start address. Can only be used between | |
508 | start_symtab and end_symtab* calls. */ | |
509 | ||
510 | extern CORE_ADDR get_last_source_start_addr (); | |
511 | ||
6cccc9a8 TT |
512 | /* Return the local using directives. */ |
513 | ||
514 | extern struct using_direct **get_local_using_directives (); | |
515 | ||
516 | /* Set the list of local using directives. */ | |
517 | ||
518 | extern void set_local_using_directives (struct using_direct *new_local); | |
519 | ||
520 | /* Return the global using directives. */ | |
521 | ||
522 | extern struct using_direct **get_global_using_directives (); | |
523 | ||
a60f3166 TT |
524 | /* True if the context stack is empty. */ |
525 | ||
526 | extern bool outermost_context_p (); | |
527 | ||
528 | /* Return the top of the context stack, or nullptr if there is an | |
529 | entry. */ | |
530 | ||
531 | extern struct context_stack *get_current_context_stack (); | |
532 | ||
533 | /* Return the context stack depth. */ | |
534 | ||
535 | extern int get_context_stack_depth (); | |
536 | ||
3c65e5b3 TT |
537 | /* Return the current subfile. */ |
538 | ||
539 | extern struct subfile *get_current_subfile (); | |
540 | ||
e148f09d TT |
541 | /* Return the local symbol list. */ |
542 | ||
543 | extern struct pending **get_local_symbols (); | |
544 | ||
545 | /* Return the file symbol list. */ | |
546 | ||
547 | extern struct pending **get_file_symbols (); | |
548 | ||
549 | /* Return the global symbol list. */ | |
550 | ||
551 | extern struct pending **get_global_symbols (); | |
552 | ||
c906108c | 553 | #endif /* defined (BUILDSYM_H) */ |