Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Support routines for building symbol tables in GDB's internal format. |
e2882c85 | 2 | Copyright (C) 1986-2018 Free Software Foundation, Inc. |
c906108c | 3 | |
c5aa993b | 4 | This file is part of GDB. |
c906108c | 5 | |
c5aa993b JM |
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 | 9 | (at your option) any later version. |
c906108c | 10 | |
c5aa993b JM |
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. | |
c906108c | 15 | |
c5aa993b | 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 | /* This module provides subroutines used for creating and adding to | |
20 | the symbol table. These routines are called from various symbol- | |
21 | file-reading routines. | |
22 | ||
23 | Routines to support specific debugging information formats (stabs, | |
0ab9ce85 DE |
24 | DWARF, etc) belong somewhere else. |
25 | ||
26 | The basic way this module is used is as follows: | |
27 | ||
33c7c59d | 28 | scoped_free_pendings free_pending; |
0ab9ce85 DE |
29 | cust = start_symtab (...); |
30 | ... read debug info ... | |
31 | cust = end_symtab (...); | |
0ab9ce85 DE |
32 | |
33 | The compunit symtab pointer ("cust") is returned from both start_symtab | |
34 | and end_symtab to simplify the debug info readers. | |
35 | ||
36 | There are minor variations on this, e.g., dwarf2read.c splits end_symtab | |
37 | into two calls: end_symtab_get_static_block, end_symtab_from_static_block, | |
38 | but all debug info readers follow this basic flow. | |
39 | ||
40 | Reading DWARF Type Units is another variation: | |
41 | ||
33c7c59d | 42 | scoped_free_pendings free_pending; |
0ab9ce85 DE |
43 | cust = start_symtab (...); |
44 | ... read debug info ... | |
45 | cust = end_expandable_symtab (...); | |
0ab9ce85 DE |
46 | |
47 | And then reading subsequent Type Units within the containing "Comp Unit" | |
48 | will use a second flow: | |
49 | ||
33c7c59d | 50 | scoped_free_pendings free_pending; |
0ab9ce85 DE |
51 | cust = restart_symtab (...); |
52 | ... read debug info ... | |
53 | cust = augment_type_symtab (...); | |
0ab9ce85 DE |
54 | |
55 | dbxread.c and xcoffread.c use another variation: | |
56 | ||
33c7c59d | 57 | scoped_free_pendings free_pending; |
0ab9ce85 DE |
58 | cust = start_symtab (...); |
59 | ... read debug info ... | |
60 | cust = end_symtab (...); | |
61 | ... start_symtab + read + end_symtab repeated ... | |
0ab9ce85 | 62 | */ |
c906108c SS |
63 | |
64 | #include "defs.h" | |
b80a981d | 65 | #include "buildsym.h" |
c906108c | 66 | #include "bfd.h" |
04ea0df1 | 67 | #include "gdb_obstack.h" |
c906108c | 68 | #include "symtab.h" |
72367fb4 | 69 | #include "symfile.h" |
c906108c SS |
70 | #include "objfiles.h" |
71 | #include "gdbtypes.h" | |
72 | #include "complaints.h" | |
4a64f543 | 73 | #include "expression.h" /* For "enum exp_opcode" used by... */ |
4a64f543 | 74 | #include "filenames.h" /* For DOSish file names. */ |
99d9066e | 75 | #include "macrotab.h" |
261397f8 | 76 | #include "demangle.h" /* Needed by SYMBOL_INIT_DEMANGLED_NAME. */ |
fe898f56 | 77 | #include "block.h" |
9219021c | 78 | #include "cp-support.h" |
de4f826b | 79 | #include "dictionary.h" |
801e3a5b | 80 | #include "addrmap.h" |
b05628f0 | 81 | #include <algorithm> |
9219021c | 82 | |
0a0edcd5 | 83 | /* For cleanup_undefined_stabs_types and finish_global_stabs (somewhat |
c906108c SS |
84 | questionable--see comment where we call them). */ |
85 | ||
86 | #include "stabsread.h" | |
87 | ||
43f3e411 DE |
88 | /* The work-in-progress of the compunit we are building. |
89 | This is created first, before any subfiles by start_symtab. */ | |
7bab9b58 | 90 | |
43f3e411 | 91 | static struct buildsym_compunit *buildsym_compunit; |
7bab9b58 | 92 | |
93eed41f TT |
93 | /* List of blocks already made (lexical contexts already closed). |
94 | This is used at the end to make the blockvector. */ | |
95 | ||
96 | struct pending_block | |
97 | { | |
98 | struct pending_block *next; | |
99 | struct block *block; | |
100 | }; | |
101 | ||
0ab9ce85 DE |
102 | static void free_buildsym_compunit (void); |
103 | ||
c906108c | 104 | static int compare_line_numbers (const void *ln1p, const void *ln2p); |
0b49e518 | 105 | |
c906108c SS |
106 | /* Initial sizes of data structures. These are realloc'd larger if |
107 | needed, and realloc'd down to the size actually used, when | |
108 | completed. */ | |
109 | ||
c906108c SS |
110 | #define INITIAL_LINE_VECTOR_LENGTH 1000 |
111 | \f | |
112 | ||
ab209f6f TT |
113 | buildsym_compunit::buildsym_compunit (struct objfile *objfile_, |
114 | const char *name, | |
115 | const char *comp_dir_, | |
116 | enum language language_, | |
117 | CORE_ADDR last_addr) | |
118 | : objfile (objfile_), | |
119 | m_last_source_file (name == nullptr ? nullptr : xstrdup (name)), | |
120 | comp_dir (comp_dir_ == nullptr ? nullptr : xstrdup (comp_dir_)), | |
121 | language (language_), | |
122 | m_last_source_start_addr (last_addr) | |
123 | { | |
124 | /* Allocate the compunit symtab now. The caller needs it to allocate | |
125 | non-primary symtabs. It is also needed by get_macro_table. */ | |
126 | compunit_symtab = allocate_compunit_symtab (objfile, name); | |
127 | ||
128 | /* Build the subfile for NAME (the main source file) so that we can record | |
129 | a pointer to it for later. | |
130 | IMPORTANT: Do not allocate a struct symtab for NAME here. | |
131 | It can happen that the debug info provides a different path to NAME than | |
132 | DIRNAME,NAME. We cope with this in watch_main_source_file_lossage but | |
133 | that only works if the main_subfile doesn't have a symtab yet. */ | |
134 | start_subfile (name); | |
135 | /* Save this so that we don't have to go looking for it at the end | |
136 | of the subfiles list. */ | |
137 | main_subfile = m_current_subfile; | |
138 | } | |
139 | ||
140 | buildsym_compunit::~buildsym_compunit () | |
141 | { | |
142 | struct subfile *subfile, *nextsub; | |
143 | ||
144 | if (m_pending_macros != nullptr) | |
145 | free_macro_table (m_pending_macros); | |
146 | ||
147 | for (subfile = subfiles; | |
148 | subfile != NULL; | |
149 | subfile = nextsub) | |
150 | { | |
151 | nextsub = subfile->next; | |
152 | xfree (subfile->name); | |
153 | xfree (subfile->line_vector); | |
154 | xfree (subfile); | |
155 | } | |
156 | ||
157 | struct pending *next, *next1; | |
158 | ||
159 | for (next = m_file_symbols; next != NULL; next = next1) | |
160 | { | |
161 | next1 = next->next; | |
162 | xfree ((void *) next); | |
163 | } | |
164 | ||
165 | for (next = m_global_symbols; next != NULL; next = next1) | |
166 | { | |
167 | next1 = next->next; | |
168 | xfree ((void *) next); | |
169 | } | |
170 | } | |
171 | ||
172 | struct macro_table * | |
173 | buildsym_compunit::get_macro_table () | |
174 | { | |
175 | if (m_pending_macros == nullptr) | |
176 | m_pending_macros = new_macro_table (&objfile->per_bfd->storage_obstack, | |
177 | objfile->per_bfd->macro_cache, | |
178 | compunit_symtab); | |
179 | return m_pending_macros; | |
180 | } | |
181 | ||
4a64f543 | 182 | /* Maintain the lists of symbols and blocks. */ |
c906108c | 183 | |
93bf33fd | 184 | /* Add a symbol to one of the lists of symbols. */ |
c906108c SS |
185 | |
186 | void | |
187 | add_symbol_to_list (struct symbol *symbol, struct pending **listhead) | |
188 | { | |
52f0bd74 | 189 | struct pending *link; |
c906108c SS |
190 | |
191 | /* If this is an alias for another symbol, don't add it. */ | |
192 | if (symbol->ginfo.name && symbol->ginfo.name[0] == '#') | |
193 | return; | |
194 | ||
4a64f543 | 195 | /* We keep PENDINGSIZE symbols in each link of the list. If we |
c906108c SS |
196 | don't have a link with room in it, add a new link. */ |
197 | if (*listhead == NULL || (*listhead)->nsyms == PENDINGSIZE) | |
198 | { | |
1d376700 | 199 | link = XNEW (struct pending); |
c906108c SS |
200 | link->next = *listhead; |
201 | *listhead = link; | |
202 | link->nsyms = 0; | |
203 | } | |
204 | ||
205 | (*listhead)->symbol[(*listhead)->nsyms++] = symbol; | |
206 | } | |
207 | ||
208 | /* Find a symbol named NAME on a LIST. NAME need not be | |
209 | '\0'-terminated; LENGTH is the length of the name. */ | |
210 | ||
211 | struct symbol * | |
212 | find_symbol_in_list (struct pending *list, char *name, int length) | |
213 | { | |
214 | int j; | |
0d5cff50 | 215 | const char *pp; |
c906108c SS |
216 | |
217 | while (list != NULL) | |
218 | { | |
219 | for (j = list->nsyms; --j >= 0;) | |
220 | { | |
3567439c | 221 | pp = SYMBOL_LINKAGE_NAME (list->symbol[j]); |
5aafa1cc PM |
222 | if (*pp == *name && strncmp (pp, name, length) == 0 |
223 | && pp[length] == '\0') | |
c906108c SS |
224 | { |
225 | return (list->symbol[j]); | |
226 | } | |
227 | } | |
228 | list = list->next; | |
229 | } | |
230 | return (NULL); | |
231 | } | |
232 | ||
33c7c59d TT |
233 | /* At end of reading syms, or in case of quit, ensure everything |
234 | associated with building symtabs is freed. | |
0ab9ce85 DE |
235 | |
236 | N.B. This is *not* intended to be used when building psymtabs. Some debug | |
237 | info readers call this anyway, which is harmless if confusing. */ | |
c906108c | 238 | |
33c7c59d | 239 | scoped_free_pendings::~scoped_free_pendings () |
c906108c | 240 | { |
0ab9ce85 | 241 | free_buildsym_compunit (); |
c906108c SS |
242 | } |
243 | ||
6b213a47 TT |
244 | /* Record BLOCK on the list of all blocks in the file. Put it after |
245 | OPBLOCK, or at the beginning if opblock is NULL. This puts the | |
246 | block in the list after all its subblocks. */ | |
247 | ||
4a2125f5 TT |
248 | void |
249 | buildsym_compunit::record_pending_block (struct block *block, | |
250 | struct pending_block *opblock) | |
6b213a47 TT |
251 | { |
252 | struct pending_block *pblock; | |
253 | ||
4a2125f5 | 254 | pblock = XOBNEW (&m_pending_block_obstack, struct pending_block); |
6b213a47 TT |
255 | pblock->block = block; |
256 | if (opblock) | |
257 | { | |
258 | pblock->next = opblock->next; | |
259 | opblock->next = pblock; | |
260 | } | |
261 | else | |
262 | { | |
4a2125f5 TT |
263 | pblock->next = m_pending_blocks; |
264 | m_pending_blocks = pblock; | |
6b213a47 TT |
265 | } |
266 | } | |
267 | ||
c906108c SS |
268 | /* Take one of the lists of symbols and make a block from it. Keep |
269 | the order the symbols have in the list (reversed from the input | |
270 | file). Put the block on the list of pending blocks. */ | |
271 | ||
4a2125f5 TT |
272 | struct block * |
273 | buildsym_compunit::finish_block_internal | |
274 | (struct symbol *symbol, | |
275 | struct pending **listhead, | |
276 | struct pending_block *old_blocks, | |
277 | const struct dynamic_prop *static_link, | |
278 | CORE_ADDR start, CORE_ADDR end, | |
279 | int is_global, int expandable) | |
c906108c | 280 | { |
5af949e3 | 281 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
52f0bd74 AC |
282 | struct pending *next, *next1; |
283 | struct block *block; | |
284 | struct pending_block *pblock; | |
c906108c | 285 | struct pending_block *opblock; |
c906108c | 286 | |
84a146c9 TT |
287 | block = (is_global |
288 | ? allocate_global_block (&objfile->objfile_obstack) | |
289 | : allocate_block (&objfile->objfile_obstack)); | |
c906108c | 290 | |
261397f8 DJ |
291 | if (symbol) |
292 | { | |
5ffa0793 PA |
293 | BLOCK_DICT (block) |
294 | = dict_create_linear (&objfile->objfile_obstack, | |
4a2125f5 | 295 | language, *listhead); |
261397f8 DJ |
296 | } |
297 | else | |
c906108c | 298 | { |
6d30eef8 DE |
299 | if (expandable) |
300 | { | |
4a2125f5 | 301 | BLOCK_DICT (block) = dict_create_hashed_expandable (language); |
6d30eef8 DE |
302 | dict_add_pending (BLOCK_DICT (block), *listhead); |
303 | } | |
304 | else | |
305 | { | |
306 | BLOCK_DICT (block) = | |
5ffa0793 | 307 | dict_create_hashed (&objfile->objfile_obstack, |
4a2125f5 | 308 | language, *listhead); |
6d30eef8 | 309 | } |
c906108c SS |
310 | } |
311 | ||
312 | BLOCK_START (block) = start; | |
313 | BLOCK_END (block) = end; | |
c906108c | 314 | |
c906108c SS |
315 | /* Put the block in as the value of the symbol that names it. */ |
316 | ||
317 | if (symbol) | |
318 | { | |
319 | struct type *ftype = SYMBOL_TYPE (symbol); | |
de4f826b | 320 | struct dict_iterator iter; |
c906108c SS |
321 | SYMBOL_BLOCK_VALUE (symbol) = block; |
322 | BLOCK_FUNCTION (block) = symbol; | |
323 | ||
324 | if (TYPE_NFIELDS (ftype) <= 0) | |
325 | { | |
326 | /* No parameter type information is recorded with the | |
327 | function's type. Set that from the type of the | |
4a64f543 | 328 | parameter symbols. */ |
c906108c SS |
329 | int nparams = 0, iparams; |
330 | struct symbol *sym; | |
8157b174 TT |
331 | |
332 | /* Here we want to directly access the dictionary, because | |
333 | we haven't fully initialized the block yet. */ | |
334 | ALL_DICT_SYMBOLS (BLOCK_DICT (block), iter, sym) | |
c906108c | 335 | { |
2a2d4dc3 AS |
336 | if (SYMBOL_IS_ARGUMENT (sym)) |
337 | nparams++; | |
c906108c SS |
338 | } |
339 | if (nparams > 0) | |
340 | { | |
341 | TYPE_NFIELDS (ftype) = nparams; | |
342 | TYPE_FIELDS (ftype) = (struct field *) | |
343 | TYPE_ALLOC (ftype, nparams * sizeof (struct field)); | |
344 | ||
de4f826b | 345 | iparams = 0; |
8157b174 TT |
346 | /* Here we want to directly access the dictionary, because |
347 | we haven't fully initialized the block yet. */ | |
348 | ALL_DICT_SYMBOLS (BLOCK_DICT (block), iter, sym) | |
c906108c | 349 | { |
de4f826b DC |
350 | if (iparams == nparams) |
351 | break; | |
352 | ||
2a2d4dc3 | 353 | if (SYMBOL_IS_ARGUMENT (sym)) |
c906108c | 354 | { |
c906108c | 355 | TYPE_FIELD_TYPE (ftype, iparams) = SYMBOL_TYPE (sym); |
8176bb6d | 356 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0; |
c906108c | 357 | iparams++; |
c906108c SS |
358 | } |
359 | } | |
360 | } | |
361 | } | |
362 | } | |
363 | else | |
364 | { | |
365 | BLOCK_FUNCTION (block) = NULL; | |
366 | } | |
367 | ||
63e43d3a PMR |
368 | if (static_link != NULL) |
369 | objfile_register_static_link (objfile, block, static_link); | |
370 | ||
1d376700 | 371 | /* Now free the links of the list, and empty the list. */ |
c906108c SS |
372 | |
373 | for (next = *listhead; next; next = next1) | |
374 | { | |
375 | next1 = next->next; | |
1d376700 | 376 | xfree (next); |
c906108c SS |
377 | } |
378 | *listhead = NULL; | |
379 | ||
c906108c | 380 | /* Check to be sure that the blocks have an end address that is |
4a64f543 | 381 | greater than starting address. */ |
c906108c SS |
382 | |
383 | if (BLOCK_END (block) < BLOCK_START (block)) | |
384 | { | |
385 | if (symbol) | |
386 | { | |
b98664d3 | 387 | complaint (_("block end address less than block " |
3e43a32a | 388 | "start address in %s (patched it)"), |
de5ad195 | 389 | SYMBOL_PRINT_NAME (symbol)); |
c906108c SS |
390 | } |
391 | else | |
392 | { | |
b98664d3 | 393 | complaint (_("block end address %s less than block " |
3e43a32a | 394 | "start address %s (patched it)"), |
5af949e3 UW |
395 | paddress (gdbarch, BLOCK_END (block)), |
396 | paddress (gdbarch, BLOCK_START (block))); | |
c906108c | 397 | } |
4a64f543 | 398 | /* Better than nothing. */ |
c906108c SS |
399 | BLOCK_END (block) = BLOCK_START (block); |
400 | } | |
c906108c SS |
401 | |
402 | /* Install this block as the superblock of all blocks made since the | |
403 | start of this scope that don't have superblocks yet. */ | |
404 | ||
405 | opblock = NULL; | |
4a2125f5 | 406 | for (pblock = m_pending_blocks; |
c0219d42 MS |
407 | pblock && pblock != old_blocks; |
408 | pblock = pblock->next) | |
c906108c SS |
409 | { |
410 | if (BLOCK_SUPERBLOCK (pblock->block) == NULL) | |
411 | { | |
c906108c | 412 | /* Check to be sure the blocks are nested as we receive |
4a64f543 | 413 | them. If the compiler/assembler/linker work, this just |
14711c82 DJ |
414 | burns a small amount of time. |
415 | ||
416 | Skip blocks which correspond to a function; they're not | |
417 | physically nested inside this other blocks, only | |
418 | lexically nested. */ | |
419 | if (BLOCK_FUNCTION (pblock->block) == NULL | |
420 | && (BLOCK_START (pblock->block) < BLOCK_START (block) | |
421 | || BLOCK_END (pblock->block) > BLOCK_END (block))) | |
c906108c SS |
422 | { |
423 | if (symbol) | |
424 | { | |
b98664d3 | 425 | complaint (_("inner block not inside outer block in %s"), |
de5ad195 | 426 | SYMBOL_PRINT_NAME (symbol)); |
c906108c SS |
427 | } |
428 | else | |
429 | { | |
b98664d3 | 430 | complaint (_("inner block (%s-%s) not " |
3e43a32a | 431 | "inside outer block (%s-%s)"), |
5af949e3 UW |
432 | paddress (gdbarch, BLOCK_START (pblock->block)), |
433 | paddress (gdbarch, BLOCK_END (pblock->block)), | |
434 | paddress (gdbarch, BLOCK_START (block)), | |
435 | paddress (gdbarch, BLOCK_END (block))); | |
c906108c SS |
436 | } |
437 | if (BLOCK_START (pblock->block) < BLOCK_START (block)) | |
438 | BLOCK_START (pblock->block) = BLOCK_START (block); | |
439 | if (BLOCK_END (pblock->block) > BLOCK_END (block)) | |
440 | BLOCK_END (pblock->block) = BLOCK_END (block); | |
441 | } | |
c906108c SS |
442 | BLOCK_SUPERBLOCK (pblock->block) = block; |
443 | } | |
444 | opblock = pblock; | |
445 | } | |
446 | ||
22cee43f PMR |
447 | block_set_using (block, |
448 | (is_global | |
4a2125f5 TT |
449 | ? m_global_using_directives |
450 | : m_local_using_directives), | |
22cee43f PMR |
451 | &objfile->objfile_obstack); |
452 | if (is_global) | |
4a2125f5 | 453 | m_global_using_directives = NULL; |
22cee43f | 454 | else |
4a2125f5 | 455 | m_local_using_directives = NULL; |
27aa8d6a | 456 | |
6b213a47 | 457 | record_pending_block (block, opblock); |
801e3a5b JB |
458 | |
459 | return block; | |
c906108c SS |
460 | } |
461 | ||
84a146c9 | 462 | struct block * |
4a2125f5 TT |
463 | buildsym_compunit::finish_block (struct symbol *symbol, |
464 | struct pending_block *old_blocks, | |
465 | const struct dynamic_prop *static_link, | |
466 | CORE_ADDR start, CORE_ADDR end) | |
84a146c9 | 467 | { |
4a2125f5 TT |
468 | return finish_block_internal (symbol, &m_local_symbols, |
469 | old_blocks, static_link, start, end, 0, 0); | |
84a146c9 | 470 | } |
de4f826b | 471 | |
801e3a5b JB |
472 | /* Record that the range of addresses from START to END_INCLUSIVE |
473 | (inclusive, like it says) belongs to BLOCK. BLOCK's start and end | |
474 | addresses must be set already. You must apply this function to all | |
475 | BLOCK's children before applying it to BLOCK. | |
476 | ||
477 | If a call to this function complicates the picture beyond that | |
478 | already provided by BLOCK_START and BLOCK_END, then we create an | |
479 | address map for the block. */ | |
480 | void | |
4a2125f5 TT |
481 | buildsym_compunit::record_block_range (struct block *block, |
482 | CORE_ADDR start, | |
483 | CORE_ADDR end_inclusive) | |
801e3a5b JB |
484 | { |
485 | /* If this is any different from the range recorded in the block's | |
486 | own BLOCK_START and BLOCK_END, then note that the address map has | |
487 | become interesting. Note that even if this block doesn't have | |
488 | any "interesting" ranges, some later block might, so we still | |
489 | need to record this block in the addrmap. */ | |
490 | if (start != BLOCK_START (block) | |
491 | || end_inclusive + 1 != BLOCK_END (block)) | |
4a2125f5 | 492 | m_pending_addrmap_interesting = true; |
801e3a5b | 493 | |
4a2125f5 TT |
494 | if (m_pending_addrmap == nullptr) |
495 | m_pending_addrmap = addrmap_create_mutable (&m_pending_addrmap_obstack); | |
801e3a5b | 496 | |
4a2125f5 | 497 | addrmap_set_empty (m_pending_addrmap, start, end_inclusive, block); |
801e3a5b JB |
498 | } |
499 | ||
4a2125f5 TT |
500 | struct blockvector * |
501 | buildsym_compunit::make_blockvector () | |
c906108c | 502 | { |
52f0bd74 AC |
503 | struct pending_block *next; |
504 | struct blockvector *blockvector; | |
505 | int i; | |
c906108c SS |
506 | |
507 | /* Count the length of the list of blocks. */ | |
508 | ||
4a2125f5 | 509 | for (next = m_pending_blocks, i = 0; next; next = next->next, i++) |
5ac04550 | 510 | { |
c906108c SS |
511 | } |
512 | ||
513 | blockvector = (struct blockvector *) | |
4a146b47 | 514 | obstack_alloc (&objfile->objfile_obstack, |
c906108c SS |
515 | (sizeof (struct blockvector) |
516 | + (i - 1) * sizeof (struct block *))); | |
517 | ||
4a64f543 | 518 | /* Copy the blocks into the blockvector. This is done in reverse |
c906108c | 519 | order, which happens to put the blocks into the proper order |
4a64f543 | 520 | (ascending starting address). finish_block has hair to insert |
c906108c SS |
521 | each block into the list after its subblocks in order to make |
522 | sure this is true. */ | |
523 | ||
524 | BLOCKVECTOR_NBLOCKS (blockvector) = i; | |
4a2125f5 | 525 | for (next = m_pending_blocks; next; next = next->next) |
c906108c SS |
526 | { |
527 | BLOCKVECTOR_BLOCK (blockvector, --i) = next->block; | |
528 | } | |
529 | ||
4a2125f5 | 530 | free_pending_blocks (); |
c906108c | 531 | |
801e3a5b JB |
532 | /* If we needed an address map for this symtab, record it in the |
533 | blockvector. */ | |
4a2125f5 | 534 | if (m_pending_addrmap != nullptr && m_pending_addrmap_interesting) |
801e3a5b | 535 | BLOCKVECTOR_MAP (blockvector) |
4a2125f5 | 536 | = addrmap_create_fixed (m_pending_addrmap, &objfile->objfile_obstack); |
801e3a5b JB |
537 | else |
538 | BLOCKVECTOR_MAP (blockvector) = 0; | |
4aad0dfc | 539 | |
c906108c | 540 | /* Some compilers output blocks in the wrong order, but we depend on |
4a64f543 | 541 | their being in the right order so we can binary search. Check the |
4aad0dfc DE |
542 | order and moan about it. |
543 | Note: Remember that the first two blocks are the global and static | |
544 | blocks. We could special case that fact and begin checking at block 2. | |
545 | To avoid making that assumption we do not. */ | |
c906108c SS |
546 | if (BLOCKVECTOR_NBLOCKS (blockvector) > 1) |
547 | { | |
548 | for (i = 1; i < BLOCKVECTOR_NBLOCKS (blockvector); i++) | |
549 | { | |
550 | if (BLOCK_START (BLOCKVECTOR_BLOCK (blockvector, i - 1)) | |
551 | > BLOCK_START (BLOCKVECTOR_BLOCK (blockvector, i))) | |
552 | { | |
59527da0 JB |
553 | CORE_ADDR start |
554 | = BLOCK_START (BLOCKVECTOR_BLOCK (blockvector, i)); | |
c906108c | 555 | |
b98664d3 | 556 | complaint (_("block at %s out of order"), |
bb599908 | 557 | hex_string ((LONGEST) start)); |
c906108c SS |
558 | } |
559 | } | |
560 | } | |
c906108c SS |
561 | |
562 | return (blockvector); | |
563 | } | |
564 | \f | |
565 | /* Start recording information about source code that came from an | |
566 | included (or otherwise merged-in) source file with a different | |
4d663531 | 567 | name. NAME is the name of the file (cannot be NULL). */ |
c906108c SS |
568 | |
569 | void | |
4a2125f5 | 570 | buildsym_compunit::start_subfile (const char *name) |
c906108c | 571 | { |
43f3e411 | 572 | const char *subfile_dirname; |
52f0bd74 | 573 | struct subfile *subfile; |
c906108c | 574 | |
4a2125f5 | 575 | subfile_dirname = comp_dir.get (); |
c906108c | 576 | |
43f3e411 DE |
577 | /* See if this subfile is already registered. */ |
578 | ||
4a2125f5 | 579 | for (subfile = subfiles; subfile; subfile = subfile->next) |
c906108c | 580 | { |
84ba0adf DJ |
581 | char *subfile_name; |
582 | ||
583 | /* If NAME is an absolute path, and this subfile is not, then | |
584 | attempt to create an absolute path to compare. */ | |
585 | if (IS_ABSOLUTE_PATH (name) | |
586 | && !IS_ABSOLUTE_PATH (subfile->name) | |
43f3e411 DE |
587 | && subfile_dirname != NULL) |
588 | subfile_name = concat (subfile_dirname, SLASH_STRING, | |
6eb7ee03 | 589 | subfile->name, (char *) NULL); |
84ba0adf DJ |
590 | else |
591 | subfile_name = subfile->name; | |
592 | ||
593 | if (FILENAME_CMP (subfile_name, name) == 0) | |
c906108c | 594 | { |
4a2125f5 | 595 | m_current_subfile = subfile; |
84ba0adf DJ |
596 | if (subfile_name != subfile->name) |
597 | xfree (subfile_name); | |
c906108c SS |
598 | return; |
599 | } | |
84ba0adf DJ |
600 | if (subfile_name != subfile->name) |
601 | xfree (subfile_name); | |
c906108c SS |
602 | } |
603 | ||
43f3e411 | 604 | /* This subfile is not known. Add an entry for it. */ |
c906108c | 605 | |
8d749320 | 606 | subfile = XNEW (struct subfile); |
43f3e411 | 607 | memset (subfile, 0, sizeof (struct subfile)); |
4a2125f5 | 608 | subfile->buildsym_compunit = this; |
43f3e411 | 609 | |
4a2125f5 TT |
610 | subfile->next = subfiles; |
611 | subfiles = subfile; | |
43f3e411 | 612 | |
4a2125f5 | 613 | m_current_subfile = subfile; |
c906108c | 614 | |
b74db436 | 615 | subfile->name = xstrdup (name); |
c906108c SS |
616 | |
617 | /* Initialize line-number recording for this subfile. */ | |
618 | subfile->line_vector = NULL; | |
619 | ||
620 | /* Default the source language to whatever can be deduced from the | |
621 | filename. If nothing can be deduced (such as for a C/C++ include | |
622 | file with a ".h" extension), then inherit whatever language the | |
623 | previous subfile had. This kludgery is necessary because there | |
624 | is no standard way in some object formats to record the source | |
625 | language. Also, when symtabs are allocated we try to deduce a | |
626 | language then as well, but it is too late for us to use that | |
627 | information while reading symbols, since symtabs aren't allocated | |
628 | until after all the symbols have been processed for a given | |
4a64f543 | 629 | source file. */ |
c906108c SS |
630 | |
631 | subfile->language = deduce_language_from_filename (subfile->name); | |
5aafa1cc PM |
632 | if (subfile->language == language_unknown |
633 | && subfile->next != NULL) | |
c906108c SS |
634 | { |
635 | subfile->language = subfile->next->language; | |
636 | } | |
637 | ||
25caa7a8 | 638 | /* If the filename of this subfile ends in .C, then change the |
c906108c | 639 | language of any pending subfiles from C to C++. We also accept |
25caa7a8 | 640 | any other C++ suffixes accepted by deduce_language_from_filename. */ |
c906108c SS |
641 | /* Likewise for f2c. */ |
642 | ||
643 | if (subfile->name) | |
644 | { | |
645 | struct subfile *s; | |
646 | enum language sublang = deduce_language_from_filename (subfile->name); | |
647 | ||
648 | if (sublang == language_cplus || sublang == language_fortran) | |
4a2125f5 | 649 | for (s = subfiles; s != NULL; s = s->next) |
c906108c SS |
650 | if (s->language == language_c) |
651 | s->language = sublang; | |
652 | } | |
653 | ||
654 | /* And patch up this file if necessary. */ | |
655 | if (subfile->language == language_c | |
656 | && subfile->next != NULL | |
657 | && (subfile->next->language == language_cplus | |
658 | || subfile->next->language == language_fortran)) | |
659 | { | |
660 | subfile->language = subfile->next->language; | |
661 | } | |
662 | } | |
663 | ||
43f3e411 | 664 | /* Delete the buildsym compunit. */ |
7bab9b58 DE |
665 | |
666 | static void | |
43f3e411 | 667 | free_buildsym_compunit (void) |
7bab9b58 | 668 | { |
43f3e411 DE |
669 | if (buildsym_compunit == NULL) |
670 | return; | |
b248663f | 671 | delete buildsym_compunit; |
43f3e411 | 672 | buildsym_compunit = NULL; |
7bab9b58 DE |
673 | } |
674 | ||
c906108c SS |
675 | /* For stabs readers, the first N_SO symbol is assumed to be the |
676 | source file name, and the subfile struct is initialized using that | |
677 | assumption. If another N_SO symbol is later seen, immediately | |
678 | following the first one, then the first one is assumed to be the | |
679 | directory name and the second one is really the source file name. | |
680 | ||
681 | So we have to patch up the subfile struct by moving the old name | |
682 | value to dirname and remembering the new name. Some sanity | |
683 | checking is performed to ensure that the state of the subfile | |
684 | struct is reasonable and that the old name we are assuming to be a | |
4a64f543 | 685 | directory name actually is (by checking for a trailing '/'). */ |
c906108c SS |
686 | |
687 | void | |
4a2125f5 TT |
688 | buildsym_compunit::patch_subfile_names (struct subfile *subfile, |
689 | const char *name) | |
c906108c | 690 | { |
43f3e411 | 691 | if (subfile != NULL |
4a2125f5 | 692 | && comp_dir == NULL |
43f3e411 | 693 | && subfile->name != NULL |
0ba1096a | 694 | && IS_DIR_SEPARATOR (subfile->name[strlen (subfile->name) - 1])) |
c906108c | 695 | { |
4a2125f5 | 696 | comp_dir.reset (subfile->name); |
1b36a34b | 697 | subfile->name = xstrdup (name); |
46212e0b | 698 | set_last_source_file (name); |
c906108c SS |
699 | |
700 | /* Default the source language to whatever can be deduced from | |
701 | the filename. If nothing can be deduced (such as for a C/C++ | |
702 | include file with a ".h" extension), then inherit whatever | |
703 | language the previous subfile had. This kludgery is | |
704 | necessary because there is no standard way in some object | |
705 | formats to record the source language. Also, when symtabs | |
706 | are allocated we try to deduce a language then as well, but | |
707 | it is too late for us to use that information while reading | |
708 | symbols, since symtabs aren't allocated until after all the | |
4a64f543 | 709 | symbols have been processed for a given source file. */ |
c906108c SS |
710 | |
711 | subfile->language = deduce_language_from_filename (subfile->name); | |
5aafa1cc PM |
712 | if (subfile->language == language_unknown |
713 | && subfile->next != NULL) | |
c906108c SS |
714 | { |
715 | subfile->language = subfile->next->language; | |
716 | } | |
717 | } | |
718 | } | |
719 | \f | |
720 | /* Handle the N_BINCL and N_EINCL symbol types that act like N_SOL for | |
721 | switching source files (different subfiles, as we call them) within | |
722 | one object file, but using a stack rather than in an arbitrary | |
723 | order. */ | |
724 | ||
725 | void | |
4a2125f5 | 726 | buildsym_compunit::push_subfile () |
c906108c | 727 | { |
4a2125f5 TT |
728 | gdb_assert (m_current_subfile != NULL); |
729 | gdb_assert (m_current_subfile->name != NULL); | |
730 | m_subfile_stack.push_back (m_current_subfile->name); | |
c906108c SS |
731 | } |
732 | ||
8419ee53 | 733 | const char * |
4a2125f5 | 734 | buildsym_compunit::pop_subfile () |
c906108c | 735 | { |
4a2125f5 TT |
736 | gdb_assert (!m_subfile_stack.empty ()); |
737 | const char *name = m_subfile_stack.back (); | |
738 | m_subfile_stack.pop_back (); | |
8419ee53 | 739 | return name; |
c906108c SS |
740 | } |
741 | \f | |
742 | /* Add a linetable entry for line number LINE and address PC to the | |
743 | line vector for SUBFILE. */ | |
744 | ||
745 | void | |
4a2125f5 TT |
746 | buildsym_compunit::record_line (struct subfile *subfile, int line, |
747 | CORE_ADDR pc) | |
c906108c SS |
748 | { |
749 | struct linetable_entry *e; | |
c906108c | 750 | |
cc59ec59 | 751 | /* Ignore the dummy line number in libg.o */ |
c906108c SS |
752 | if (line == 0xffff) |
753 | { | |
754 | return; | |
755 | } | |
756 | ||
757 | /* Make sure line vector exists and is big enough. */ | |
758 | if (!subfile->line_vector) | |
759 | { | |
760 | subfile->line_vector_length = INITIAL_LINE_VECTOR_LENGTH; | |
761 | subfile->line_vector = (struct linetable *) | |
762 | xmalloc (sizeof (struct linetable) | |
c5aa993b | 763 | + subfile->line_vector_length * sizeof (struct linetable_entry)); |
c906108c | 764 | subfile->line_vector->nitems = 0; |
4a2125f5 | 765 | m_have_line_numbers = true; |
c906108c SS |
766 | } |
767 | ||
768 | if (subfile->line_vector->nitems + 1 >= subfile->line_vector_length) | |
769 | { | |
770 | subfile->line_vector_length *= 2; | |
771 | subfile->line_vector = (struct linetable *) | |
772 | xrealloc ((char *) subfile->line_vector, | |
773 | (sizeof (struct linetable) | |
774 | + (subfile->line_vector_length | |
775 | * sizeof (struct linetable_entry)))); | |
776 | } | |
777 | ||
607ae575 DJ |
778 | /* Normally, we treat lines as unsorted. But the end of sequence |
779 | marker is special. We sort line markers at the same PC by line | |
780 | number, so end of sequence markers (which have line == 0) appear | |
781 | first. This is right if the marker ends the previous function, | |
782 | and there is no padding before the next function. But it is | |
783 | wrong if the previous line was empty and we are now marking a | |
784 | switch to a different subfile. We must leave the end of sequence | |
785 | marker at the end of this group of lines, not sort the empty line | |
786 | to after the marker. The easiest way to accomplish this is to | |
787 | delete any empty lines from our table, if they are followed by | |
788 | end of sequence markers. All we lose is the ability to set | |
789 | breakpoints at some lines which contain no instructions | |
790 | anyway. */ | |
791 | if (line == 0 && subfile->line_vector->nitems > 0) | |
792 | { | |
793 | e = subfile->line_vector->item + subfile->line_vector->nitems - 1; | |
794 | while (subfile->line_vector->nitems > 0 && e->pc == pc) | |
795 | { | |
796 | e--; | |
797 | subfile->line_vector->nitems--; | |
798 | } | |
799 | } | |
800 | ||
c906108c SS |
801 | e = subfile->line_vector->item + subfile->line_vector->nitems++; |
802 | e->line = line; | |
607ae575 | 803 | e->pc = pc; |
c906108c SS |
804 | } |
805 | ||
806 | /* Needed in order to sort line tables from IBM xcoff files. Sigh! */ | |
807 | ||
808 | static int | |
809 | compare_line_numbers (const void *ln1p, const void *ln2p) | |
810 | { | |
811 | struct linetable_entry *ln1 = (struct linetable_entry *) ln1p; | |
812 | struct linetable_entry *ln2 = (struct linetable_entry *) ln2p; | |
813 | ||
814 | /* Note: this code does not assume that CORE_ADDRs can fit in ints. | |
815 | Please keep it that way. */ | |
816 | if (ln1->pc < ln2->pc) | |
817 | return -1; | |
818 | ||
819 | if (ln1->pc > ln2->pc) | |
820 | return 1; | |
821 | ||
822 | /* If pc equal, sort by line. I'm not sure whether this is optimum | |
823 | behavior (see comment at struct linetable in symtab.h). */ | |
824 | return ln1->line - ln2->line; | |
825 | } | |
826 | \f | |
43f3e411 DE |
827 | /* See buildsym.h. */ |
828 | ||
829 | struct compunit_symtab * | |
830 | buildsym_compunit_symtab (void) | |
831 | { | |
832 | gdb_assert (buildsym_compunit != NULL); | |
833 | ||
4a2125f5 | 834 | return buildsym_compunit->get_compunit_symtab (); |
43f3e411 DE |
835 | } |
836 | ||
837 | /* See buildsym.h. */ | |
fc474241 DE |
838 | |
839 | struct macro_table * | |
43f3e411 | 840 | get_macro_table (void) |
fc474241 | 841 | { |
43f3e411 DE |
842 | struct objfile *objfile; |
843 | ||
844 | gdb_assert (buildsym_compunit != NULL); | |
6a976300 | 845 | return buildsym_compunit->get_macro_table (); |
fc474241 DE |
846 | } |
847 | \f | |
4d663531 | 848 | /* Start a new symtab for a new source file in OBJFILE. Called, for example, |
c906108c SS |
849 | when a stabs symbol of type N_SO is seen, or when a DWARF |
850 | TAG_compile_unit DIE is seen. It indicates the start of data for | |
0b0287a1 DE |
851 | one original source file. |
852 | ||
5ffa0793 PA |
853 | NAME is the name of the file (cannot be NULL). COMP_DIR is the |
854 | directory in which the file was compiled (or NULL if not known). | |
855 | START_ADDR is the lowest address of objects in the file (or 0 if | |
856 | not known). LANGUAGE is the language of the source file, or | |
857 | language_unknown if not known, in which case it'll be deduced from | |
858 | the filename. */ | |
c906108c | 859 | |
43f3e411 | 860 | struct compunit_symtab * |
4d663531 | 861 | start_symtab (struct objfile *objfile, const char *name, const char *comp_dir, |
5ffa0793 | 862 | CORE_ADDR start_addr, enum language language) |
c906108c | 863 | { |
b37dd3bc TT |
864 | /* These should have been reset either by successful completion of building |
865 | a symtab, or by the scoped_free_pendings destructor. */ | |
866 | gdb_assert (buildsym_compunit == nullptr); | |
43f3e411 | 867 | |
c0015d44 | 868 | buildsym_compunit = new struct buildsym_compunit (objfile, name, comp_dir, |
2c99ee5c | 869 | language, start_addr); |
43f3e411 | 870 | |
4a2125f5 | 871 | return buildsym_compunit->get_compunit_symtab (); |
6d30eef8 DE |
872 | } |
873 | ||
874 | /* Restart compilation for a symtab. | |
0ab9ce85 DE |
875 | CUST is the result of end_expandable_symtab. |
876 | NAME, START_ADDR are the source file we are resuming with. | |
877 | ||
6d30eef8 | 878 | This is used when a symtab is built from multiple sources. |
0ab9ce85 DE |
879 | The symtab is first built with start_symtab/end_expandable_symtab |
880 | and then for each additional piece call restart_symtab/augment_*_symtab. | |
881 | Note: At the moment there is only augment_type_symtab. */ | |
6d30eef8 DE |
882 | |
883 | void | |
0ab9ce85 DE |
884 | restart_symtab (struct compunit_symtab *cust, |
885 | const char *name, CORE_ADDR start_addr) | |
6d30eef8 | 886 | { |
b37dd3bc TT |
887 | /* These should have been reset either by successful completion of building |
888 | a symtab, or by the scoped_free_pendings destructor. */ | |
889 | gdb_assert (buildsym_compunit == nullptr); | |
c906108c | 890 | |
b248663f TT |
891 | buildsym_compunit |
892 | = new struct buildsym_compunit (COMPUNIT_OBJFILE (cust), | |
c0015d44 | 893 | name, |
b248663f | 894 | COMPUNIT_DIRNAME (cust), |
2c99ee5c | 895 | compunit_language (cust), |
4a2125f5 TT |
896 | start_addr, |
897 | cust); | |
c906108c SS |
898 | } |
899 | ||
4a64f543 MS |
900 | /* Subroutine of end_symtab to simplify it. Look for a subfile that |
901 | matches the main source file's basename. If there is only one, and | |
902 | if the main source file doesn't have any symbol or line number | |
903 | information, then copy this file's symtab and line_vector to the | |
904 | main source file's subfile and discard the other subfile. This can | |
905 | happen because of a compiler bug or from the user playing games | |
906 | with #line or from things like a distributed build system that | |
43f3e411 DE |
907 | manipulates the debug info. This can also happen from an innocent |
908 | symlink in the paths, we don't canonicalize paths here. */ | |
4584e32e | 909 | |
4a2125f5 TT |
910 | void |
911 | buildsym_compunit::watch_main_source_file_lossage () | |
4584e32e | 912 | { |
43f3e411 | 913 | struct subfile *mainsub, *subfile; |
4584e32e | 914 | |
43f3e411 | 915 | /* Get the main source file. */ |
4a2125f5 | 916 | mainsub = main_subfile; |
43f3e411 | 917 | |
4a64f543 | 918 | /* If the main source file doesn't have any line number or symbol |
7bab9b58 | 919 | info, look for an alias in another subfile. */ |
4584e32e | 920 | |
43f3e411 DE |
921 | if (mainsub->line_vector == NULL |
922 | && mainsub->symtab == NULL) | |
4584e32e | 923 | { |
43f3e411 | 924 | const char *mainbase = lbasename (mainsub->name); |
4584e32e DE |
925 | int nr_matches = 0; |
926 | struct subfile *prevsub; | |
927 | struct subfile *mainsub_alias = NULL; | |
928 | struct subfile *prev_mainsub_alias = NULL; | |
929 | ||
930 | prevsub = NULL; | |
4a2125f5 | 931 | for (subfile = subfiles; |
43f3e411 | 932 | subfile != NULL; |
4584e32e DE |
933 | subfile = subfile->next) |
934 | { | |
43f3e411 DE |
935 | if (subfile == mainsub) |
936 | continue; | |
0ba1096a | 937 | if (filename_cmp (lbasename (subfile->name), mainbase) == 0) |
4584e32e DE |
938 | { |
939 | ++nr_matches; | |
940 | mainsub_alias = subfile; | |
941 | prev_mainsub_alias = prevsub; | |
942 | } | |
943 | prevsub = subfile; | |
944 | } | |
945 | ||
946 | if (nr_matches == 1) | |
947 | { | |
43f3e411 | 948 | gdb_assert (mainsub_alias != NULL && mainsub_alias != mainsub); |
4584e32e DE |
949 | |
950 | /* Found a match for the main source file. | |
951 | Copy its line_vector and symtab to the main subfile | |
952 | and then discard it. */ | |
953 | ||
43f3e411 DE |
954 | mainsub->line_vector = mainsub_alias->line_vector; |
955 | mainsub->line_vector_length = mainsub_alias->line_vector_length; | |
956 | mainsub->symtab = mainsub_alias->symtab; | |
4584e32e DE |
957 | |
958 | if (prev_mainsub_alias == NULL) | |
4a2125f5 | 959 | subfiles = mainsub_alias->next; |
4584e32e DE |
960 | else |
961 | prev_mainsub_alias->next = mainsub_alias->next; | |
98387a29 | 962 | xfree (mainsub_alias->name); |
4584e32e DE |
963 | xfree (mainsub_alias); |
964 | } | |
965 | } | |
966 | } | |
967 | ||
4359dff1 JK |
968 | /* Implementation of the first part of end_symtab. It allows modifying |
969 | STATIC_BLOCK before it gets finalized by end_symtab_from_static_block. | |
970 | If the returned value is NULL there is no blockvector created for | |
971 | this symtab (you still must call end_symtab_from_static_block). | |
c906108c | 972 | |
4359dff1 JK |
973 | END_ADDR is the same as for end_symtab: the address of the end of the |
974 | file's text. | |
c906108c | 975 | |
4359dff1 | 976 | If EXPANDABLE is non-zero the STATIC_BLOCK dictionary is made |
36586728 TT |
977 | expandable. |
978 | ||
979 | If REQUIRED is non-zero, then a symtab is created even if it does | |
980 | not contain any symbols. */ | |
6d30eef8 | 981 | |
4359dff1 | 982 | struct block * |
4a2125f5 TT |
983 | buildsym_compunit::end_symtab_get_static_block (CORE_ADDR end_addr, |
984 | int expandable, int required) | |
c906108c | 985 | { |
c906108c SS |
986 | /* Finish the lexical context of the last function in the file; pop |
987 | the context stack. */ | |
988 | ||
4a2125f5 | 989 | if (!m_context_stack.empty ()) |
c906108c | 990 | { |
a60f3166 | 991 | struct context_stack cstk = pop_context (); |
4359dff1 | 992 | |
c906108c | 993 | /* Make a block for the local symbols within. */ |
c233e9c6 | 994 | finish_block (cstk.name, cstk.old_blocks, NULL, |
a60f3166 | 995 | cstk.start_addr, end_addr); |
c906108c | 996 | |
4a2125f5 | 997 | if (!m_context_stack.empty ()) |
c906108c SS |
998 | { |
999 | /* This is said to happen with SCO. The old coffread.c | |
1000 | code simply emptied the context stack, so we do the | |
1001 | same. FIXME: Find out why it is happening. This is not | |
1002 | believed to happen in most cases (even for coffread.c); | |
1003 | it used to be an abort(). */ | |
b98664d3 | 1004 | complaint (_("Context stack not empty in end_symtab")); |
4a2125f5 | 1005 | m_context_stack.clear (); |
c906108c SS |
1006 | } |
1007 | } | |
1008 | ||
1009 | /* Reordered executables may have out of order pending blocks; if | |
1010 | OBJF_REORDERED is true, then sort the pending blocks. */ | |
6d30eef8 | 1011 | |
4a2125f5 | 1012 | if ((objfile->flags & OBJF_REORDERED) && m_pending_blocks) |
c906108c | 1013 | { |
07e7f39f | 1014 | struct pending_block *pb; |
c906108c | 1015 | |
b05628f0 | 1016 | std::vector<block *> barray; |
c906108c | 1017 | |
4a2125f5 | 1018 | for (pb = m_pending_blocks; pb != NULL; pb = pb->next) |
b05628f0 | 1019 | barray.push_back (pb->block); |
07e7f39f | 1020 | |
5033013f UW |
1021 | /* Sort blocks by start address in descending order. Blocks with the |
1022 | same start address must remain in the original order to preserve | |
1023 | inline function caller/callee relationships. */ | |
1024 | std::stable_sort (barray.begin (), barray.end (), | |
1025 | [] (const block *a, const block *b) | |
1026 | { | |
1027 | return BLOCK_START (a) > BLOCK_START (b); | |
1028 | }); | |
07e7f39f | 1029 | |
b05628f0 | 1030 | int i = 0; |
4a2125f5 | 1031 | for (pb = m_pending_blocks; pb != NULL; pb = pb->next) |
b05628f0 | 1032 | pb->block = barray[i++]; |
c906108c SS |
1033 | } |
1034 | ||
1035 | /* Cleanup any undefined types that have been left hanging around | |
1036 | (this needs to be done before the finish_blocks so that | |
1037 | file_symbols is still good). | |
c5aa993b | 1038 | |
0a0edcd5 | 1039 | Both cleanup_undefined_stabs_types and finish_global_stabs are stabs |
c906108c SS |
1040 | specific, but harmless for other symbol readers, since on gdb |
1041 | startup or when finished reading stabs, the state is set so these | |
1042 | are no-ops. FIXME: Is this handled right in case of QUIT? Can | |
1043 | we make this cleaner? */ | |
1044 | ||
0a0edcd5 | 1045 | cleanup_undefined_stabs_types (objfile); |
c906108c SS |
1046 | finish_global_stabs (objfile); |
1047 | ||
36586728 | 1048 | if (!required |
4a2125f5 TT |
1049 | && m_pending_blocks == NULL |
1050 | && m_file_symbols == NULL | |
1051 | && m_global_symbols == NULL | |
1052 | && !m_have_line_numbers | |
1053 | && m_pending_macros == NULL | |
1054 | && m_global_using_directives == NULL) | |
c906108c | 1055 | { |
4359dff1 JK |
1056 | /* Ignore symtabs that have no functions with real debugging info. */ |
1057 | return NULL; | |
1058 | } | |
1059 | else | |
1060 | { | |
1061 | /* Define the STATIC_BLOCK. */ | |
e148f09d | 1062 | return finish_block_internal (NULL, get_file_symbols (), NULL, NULL, |
4a2125f5 | 1063 | m_last_source_start_addr, |
2c99ee5c | 1064 | end_addr, 0, expandable); |
4359dff1 JK |
1065 | } |
1066 | } | |
1067 | ||
7bab9b58 DE |
1068 | /* Subroutine of end_symtab_from_static_block to simplify it. |
1069 | Handle the "have blockvector" case. | |
1070 | See end_symtab_from_static_block for a description of the arguments. */ | |
1071 | ||
4a2125f5 TT |
1072 | struct compunit_symtab * |
1073 | buildsym_compunit::end_symtab_with_blockvector (struct block *static_block, | |
1074 | int section, int expandable) | |
4359dff1 | 1075 | { |
4a2125f5 | 1076 | struct compunit_symtab *cu = compunit_symtab; |
7bab9b58 | 1077 | struct symtab *symtab; |
4359dff1 JK |
1078 | struct blockvector *blockvector; |
1079 | struct subfile *subfile; | |
7bab9b58 | 1080 | CORE_ADDR end_addr; |
4359dff1 | 1081 | |
7bab9b58 | 1082 | gdb_assert (static_block != NULL); |
4a2125f5 | 1083 | gdb_assert (subfiles != NULL); |
7bab9b58 DE |
1084 | |
1085 | end_addr = BLOCK_END (static_block); | |
1086 | ||
1087 | /* Create the GLOBAL_BLOCK and build the blockvector. */ | |
e148f09d | 1088 | finish_block_internal (NULL, get_global_symbols (), NULL, NULL, |
4a2125f5 | 1089 | m_last_source_start_addr, end_addr, |
7bab9b58 | 1090 | 1, expandable); |
43f3e411 | 1091 | blockvector = make_blockvector (); |
c906108c | 1092 | |
f56ce883 DE |
1093 | /* Read the line table if it has to be read separately. |
1094 | This is only used by xcoffread.c. */ | |
c295b2e5 | 1095 | if (objfile->sf->sym_read_linetable != NULL) |
f56ce883 | 1096 | objfile->sf->sym_read_linetable (objfile); |
c906108c | 1097 | |
4584e32e DE |
1098 | /* Handle the case where the debug info specifies a different path |
1099 | for the main source file. It can cause us to lose track of its | |
1100 | line number information. */ | |
1101 | watch_main_source_file_lossage (); | |
1102 | ||
43f3e411 DE |
1103 | /* Now create the symtab objects proper, if not already done, |
1104 | one for each subfile. */ | |
c906108c | 1105 | |
4a2125f5 | 1106 | for (subfile = subfiles; |
43f3e411 DE |
1107 | subfile != NULL; |
1108 | subfile = subfile->next) | |
c906108c SS |
1109 | { |
1110 | int linetablesize = 0; | |
c906108c | 1111 | |
7bab9b58 | 1112 | if (subfile->line_vector) |
c906108c | 1113 | { |
7bab9b58 DE |
1114 | linetablesize = sizeof (struct linetable) + |
1115 | subfile->line_vector->nitems * sizeof (struct linetable_entry); | |
1116 | ||
1117 | /* Like the pending blocks, the line table may be | |
1118 | scrambled in reordered executables. Sort it if | |
1119 | OBJF_REORDERED is true. */ | |
1120 | if (objfile->flags & OBJF_REORDERED) | |
1121 | qsort (subfile->line_vector->item, | |
1122 | subfile->line_vector->nitems, | |
1123 | sizeof (struct linetable_entry), compare_line_numbers); | |
1124 | } | |
9182c5bc | 1125 | |
7bab9b58 DE |
1126 | /* Allocate a symbol table if necessary. */ |
1127 | if (subfile->symtab == NULL) | |
43f3e411 | 1128 | subfile->symtab = allocate_symtab (cu, subfile->name); |
7bab9b58 | 1129 | symtab = subfile->symtab; |
9182c5bc | 1130 | |
7bab9b58 | 1131 | /* Fill in its components. */ |
43f3e411 | 1132 | |
7bab9b58 DE |
1133 | if (subfile->line_vector) |
1134 | { | |
1135 | /* Reallocate the line table on the symbol obstack. */ | |
8435453b | 1136 | SYMTAB_LINETABLE (symtab) = (struct linetable *) |
7bab9b58 | 1137 | obstack_alloc (&objfile->objfile_obstack, linetablesize); |
8435453b DE |
1138 | memcpy (SYMTAB_LINETABLE (symtab), subfile->line_vector, |
1139 | linetablesize); | |
c906108c | 1140 | } |
24be086d | 1141 | else |
c906108c | 1142 | { |
8435453b | 1143 | SYMTAB_LINETABLE (symtab) = NULL; |
c906108c | 1144 | } |
c906108c | 1145 | |
7bab9b58 DE |
1146 | /* Use whatever language we have been using for this |
1147 | subfile, not the one that was deduced in allocate_symtab | |
1148 | from the filename. We already did our own deducing when | |
1149 | we created the subfile, and we may have altered our | |
1150 | opinion of what language it is from things we found in | |
1151 | the symbols. */ | |
1152 | symtab->language = subfile->language; | |
43f3e411 | 1153 | } |
c906108c | 1154 | |
43f3e411 DE |
1155 | /* Make sure the symtab of main_subfile is the first in its list. */ |
1156 | { | |
1157 | struct symtab *main_symtab, *prev_symtab; | |
1158 | ||
4a2125f5 | 1159 | main_symtab = main_subfile->symtab; |
43f3e411 DE |
1160 | prev_symtab = NULL; |
1161 | ALL_COMPUNIT_FILETABS (cu, symtab) | |
1162 | { | |
1163 | if (symtab == main_symtab) | |
1164 | { | |
1165 | if (prev_symtab != NULL) | |
1166 | { | |
1167 | prev_symtab->next = main_symtab->next; | |
1168 | main_symtab->next = COMPUNIT_FILETABS (cu); | |
1169 | COMPUNIT_FILETABS (cu) = main_symtab; | |
1170 | } | |
1171 | break; | |
1172 | } | |
1173 | prev_symtab = symtab; | |
1174 | } | |
1175 | gdb_assert (main_symtab == COMPUNIT_FILETABS (cu)); | |
1176 | } | |
84a146c9 | 1177 | |
0ab9ce85 | 1178 | /* Fill out the compunit symtab. */ |
84a146c9 | 1179 | |
4a2125f5 | 1180 | if (comp_dir != NULL) |
43f3e411 DE |
1181 | { |
1182 | /* Reallocate the dirname on the symbol obstack. */ | |
4a2125f5 | 1183 | const char *comp_dir = this->comp_dir.get (); |
43f3e411 | 1184 | COMPUNIT_DIRNAME (cu) |
224c3ddb | 1185 | = (const char *) obstack_copy0 (&objfile->objfile_obstack, |
905eb0e2 | 1186 | comp_dir, strlen (comp_dir)); |
c906108c SS |
1187 | } |
1188 | ||
43f3e411 | 1189 | /* Save the debug format string (if any) in the symtab. */ |
4a2125f5 | 1190 | COMPUNIT_DEBUGFORMAT (cu) = debugformat; |
43f3e411 DE |
1191 | |
1192 | /* Similarly for the producer. */ | |
4a2125f5 | 1193 | COMPUNIT_PRODUCER (cu) = producer; |
43f3e411 DE |
1194 | |
1195 | COMPUNIT_BLOCKVECTOR (cu) = blockvector; | |
7bab9b58 | 1196 | { |
43f3e411 | 1197 | struct block *b = BLOCKVECTOR_BLOCK (blockvector, GLOBAL_BLOCK); |
cb1df416 | 1198 | |
43f3e411 | 1199 | set_block_compunit_symtab (b, cu); |
7bab9b58 | 1200 | } |
cb1df416 | 1201 | |
43f3e411 DE |
1202 | COMPUNIT_BLOCK_LINE_SECTION (cu) = section; |
1203 | ||
4a2125f5 | 1204 | COMPUNIT_MACRO_TABLE (cu) = release_macros (); |
43f3e411 | 1205 | |
7bab9b58 DE |
1206 | /* Default any symbols without a specified symtab to the primary symtab. */ |
1207 | { | |
1208 | int block_i; | |
1209 | ||
43f3e411 DE |
1210 | /* The main source file's symtab. */ |
1211 | symtab = COMPUNIT_FILETABS (cu); | |
1212 | ||
7bab9b58 DE |
1213 | for (block_i = 0; block_i < BLOCKVECTOR_NBLOCKS (blockvector); block_i++) |
1214 | { | |
1215 | struct block *block = BLOCKVECTOR_BLOCK (blockvector, block_i); | |
1216 | struct symbol *sym; | |
1217 | struct dict_iterator iter; | |
1218 | ||
1219 | /* Inlined functions may have symbols not in the global or | |
1220 | static symbol lists. */ | |
1221 | if (BLOCK_FUNCTION (block) != NULL) | |
08be3fe3 DE |
1222 | if (symbol_symtab (BLOCK_FUNCTION (block)) == NULL) |
1223 | symbol_set_symtab (BLOCK_FUNCTION (block), symtab); | |
7bab9b58 DE |
1224 | |
1225 | /* Note that we only want to fix up symbols from the local | |
1226 | blocks, not blocks coming from included symtabs. That is why | |
1227 | we use ALL_DICT_SYMBOLS here and not ALL_BLOCK_SYMBOLS. */ | |
1228 | ALL_DICT_SYMBOLS (BLOCK_DICT (block), iter, sym) | |
08be3fe3 DE |
1229 | if (symbol_symtab (sym) == NULL) |
1230 | symbol_set_symtab (sym, symtab); | |
7bab9b58 DE |
1231 | } |
1232 | } | |
edb3359d | 1233 | |
43f3e411 | 1234 | add_compunit_symtab_to_objfile (cu); |
43f3e411 DE |
1235 | |
1236 | return cu; | |
7bab9b58 DE |
1237 | } |
1238 | ||
1239 | /* Implementation of the second part of end_symtab. Pass STATIC_BLOCK | |
1240 | as value returned by end_symtab_get_static_block. | |
1241 | ||
1242 | SECTION is the same as for end_symtab: the section number | |
1243 | (in objfile->section_offsets) of the blockvector and linetable. | |
1244 | ||
1245 | If EXPANDABLE is non-zero the GLOBAL_BLOCK dictionary is made | |
1246 | expandable. */ | |
1247 | ||
43f3e411 | 1248 | struct compunit_symtab * |
4a2125f5 TT |
1249 | buildsym_compunit::end_symtab_from_static_block (struct block *static_block, |
1250 | int section, int expandable) | |
7bab9b58 | 1251 | { |
43f3e411 | 1252 | struct compunit_symtab *cu; |
7bab9b58 DE |
1253 | |
1254 | if (static_block == NULL) | |
1255 | { | |
0ab9ce85 DE |
1256 | /* Handle the "no blockvector" case. |
1257 | When this happens there is nothing to record, so there's nothing | |
1258 | to do: memory will be freed up later. | |
1259 | ||
1260 | Note: We won't be adding a compunit to the objfile's list of | |
1261 | compunits, so there's nothing to unchain. However, since each symtab | |
1262 | is added to the objfile's obstack we can't free that space. | |
1263 | We could do better, but this is believed to be a sufficiently rare | |
1264 | event. */ | |
43f3e411 | 1265 | cu = NULL; |
7bab9b58 DE |
1266 | } |
1267 | else | |
43f3e411 | 1268 | cu = end_symtab_with_blockvector (static_block, section, expandable); |
cb1df416 | 1269 | |
43f3e411 | 1270 | return cu; |
6d30eef8 DE |
1271 | } |
1272 | ||
4359dff1 JK |
1273 | /* Finish the symbol definitions for one main source file, close off |
1274 | all the lexical contexts for that file (creating struct block's for | |
1275 | them), then make the struct symtab for that file and put it in the | |
1276 | list of all such. | |
1277 | ||
1278 | END_ADDR is the address of the end of the file's text. SECTION is | |
1279 | the section number (in objfile->section_offsets) of the blockvector | |
1280 | and linetable. | |
1281 | ||
1282 | Note that it is possible for end_symtab() to return NULL. In | |
1283 | particular, for the DWARF case at least, it will return NULL when | |
1284 | it finds a compilation unit that has exactly one DIE, a | |
1285 | TAG_compile_unit DIE. This can happen when we link in an object | |
1286 | file that was compiled from an empty source file. Returning NULL | |
1287 | is probably not the correct thing to do, because then gdb will | |
1288 | never know about this empty file (FIXME). | |
1289 | ||
1290 | If you need to modify STATIC_BLOCK before it is finalized you should | |
1291 | call end_symtab_get_static_block and end_symtab_from_static_block | |
1292 | yourself. */ | |
6d30eef8 | 1293 | |
43f3e411 | 1294 | struct compunit_symtab * |
4a2125f5 | 1295 | buildsym_compunit::end_symtab (CORE_ADDR end_addr, int section) |
6d30eef8 | 1296 | { |
4359dff1 JK |
1297 | struct block *static_block; |
1298 | ||
4d663531 DE |
1299 | static_block = end_symtab_get_static_block (end_addr, 0, 0); |
1300 | return end_symtab_from_static_block (static_block, section, 0); | |
6d30eef8 DE |
1301 | } |
1302 | ||
4359dff1 | 1303 | /* Same as end_symtab except create a symtab that can be later added to. */ |
6d30eef8 | 1304 | |
43f3e411 | 1305 | struct compunit_symtab * |
4a2125f5 | 1306 | buildsym_compunit::end_expandable_symtab (CORE_ADDR end_addr, int section) |
6d30eef8 | 1307 | { |
4359dff1 JK |
1308 | struct block *static_block; |
1309 | ||
4d663531 DE |
1310 | static_block = end_symtab_get_static_block (end_addr, 1, 0); |
1311 | return end_symtab_from_static_block (static_block, section, 1); | |
6d30eef8 DE |
1312 | } |
1313 | ||
1314 | /* Subroutine of augment_type_symtab to simplify it. | |
43f3e411 DE |
1315 | Attach the main source file's symtab to all symbols in PENDING_LIST that |
1316 | don't have one. */ | |
6d30eef8 DE |
1317 | |
1318 | static void | |
43f3e411 DE |
1319 | set_missing_symtab (struct pending *pending_list, |
1320 | struct compunit_symtab *cu) | |
6d30eef8 DE |
1321 | { |
1322 | struct pending *pending; | |
1323 | int i; | |
1324 | ||
1325 | for (pending = pending_list; pending != NULL; pending = pending->next) | |
801e3a5b | 1326 | { |
6d30eef8 DE |
1327 | for (i = 0; i < pending->nsyms; ++i) |
1328 | { | |
08be3fe3 DE |
1329 | if (symbol_symtab (pending->symbol[i]) == NULL) |
1330 | symbol_set_symtab (pending->symbol[i], COMPUNIT_FILETABS (cu)); | |
6d30eef8 | 1331 | } |
801e3a5b | 1332 | } |
6d30eef8 | 1333 | } |
c906108c | 1334 | |
6d30eef8 DE |
1335 | /* Same as end_symtab, but for the case where we're adding more symbols |
1336 | to an existing symtab that is known to contain only type information. | |
1337 | This is the case for DWARF4 Type Units. */ | |
1338 | ||
1339 | void | |
4a2125f5 | 1340 | buildsym_compunit::augment_type_symtab () |
6d30eef8 | 1341 | { |
4a2125f5 | 1342 | struct compunit_symtab *cust = compunit_symtab; |
43f3e411 | 1343 | const struct blockvector *blockvector = COMPUNIT_BLOCKVECTOR (cust); |
6d30eef8 | 1344 | |
4a2125f5 | 1345 | if (!m_context_stack.empty ()) |
a60f3166 | 1346 | complaint (_("Context stack not empty in augment_type_symtab")); |
4a2125f5 | 1347 | if (m_pending_blocks != NULL) |
b98664d3 | 1348 | complaint (_("Blocks in a type symtab")); |
4a2125f5 | 1349 | if (m_pending_macros != NULL) |
b98664d3 | 1350 | complaint (_("Macro in a type symtab")); |
4a2125f5 | 1351 | if (m_have_line_numbers) |
b98664d3 | 1352 | complaint (_("Line numbers recorded in a type symtab")); |
6d30eef8 | 1353 | |
4a2125f5 | 1354 | if (m_file_symbols != NULL) |
6d30eef8 DE |
1355 | { |
1356 | struct block *block = BLOCKVECTOR_BLOCK (blockvector, STATIC_BLOCK); | |
1357 | ||
1358 | /* First mark any symbols without a specified symtab as belonging | |
1359 | to the primary symtab. */ | |
4a2125f5 | 1360 | set_missing_symtab (m_file_symbols, cust); |
6d30eef8 | 1361 | |
4a2125f5 | 1362 | dict_add_pending (BLOCK_DICT (block), m_file_symbols); |
6d30eef8 DE |
1363 | } |
1364 | ||
4a2125f5 | 1365 | if (m_global_symbols != NULL) |
6d30eef8 DE |
1366 | { |
1367 | struct block *block = BLOCKVECTOR_BLOCK (blockvector, GLOBAL_BLOCK); | |
1368 | ||
1369 | /* First mark any symbols without a specified symtab as belonging | |
1370 | to the primary symtab. */ | |
4a2125f5 | 1371 | set_missing_symtab (m_global_symbols, cust); |
6d30eef8 | 1372 | |
e148f09d | 1373 | dict_add_pending (BLOCK_DICT (block), |
4a2125f5 | 1374 | m_global_symbols); |
6d30eef8 | 1375 | } |
c906108c SS |
1376 | } |
1377 | ||
1378 | /* Push a context block. Args are an identifying nesting level | |
1379 | (checkable when you pop it), and the starting PC address of this | |
1380 | context. */ | |
1381 | ||
1382 | struct context_stack * | |
4a2125f5 | 1383 | buildsym_compunit::push_context (int desc, CORE_ADDR valu) |
c906108c | 1384 | { |
4a2125f5 TT |
1385 | m_context_stack.emplace_back (); |
1386 | struct context_stack *newobj = &m_context_stack.back (); | |
c906108c | 1387 | |
fe978cb0 | 1388 | newobj->depth = desc; |
4a2125f5 TT |
1389 | newobj->locals = m_local_symbols; |
1390 | newobj->old_blocks = m_pending_blocks; | |
fe978cb0 | 1391 | newobj->start_addr = valu; |
4a2125f5 | 1392 | newobj->local_using_directives = m_local_using_directives; |
fe978cb0 | 1393 | newobj->name = NULL; |
c906108c | 1394 | |
4a2125f5 TT |
1395 | m_local_symbols = NULL; |
1396 | m_local_using_directives = NULL; | |
c906108c | 1397 | |
fe978cb0 | 1398 | return newobj; |
c906108c | 1399 | } |
0c5e171a | 1400 | |
a672ef13 | 1401 | /* Pop a context block. Returns the address of the context block just |
4a64f543 | 1402 | popped. */ |
a672ef13 | 1403 | |
a60f3166 | 1404 | struct context_stack |
4a2125f5 | 1405 | buildsym_compunit::pop_context () |
0c5e171a | 1406 | { |
4a2125f5 TT |
1407 | gdb_assert (!m_context_stack.empty ()); |
1408 | struct context_stack result = m_context_stack.back (); | |
1409 | m_context_stack.pop_back (); | |
a60f3166 | 1410 | return result; |
0c5e171a KD |
1411 | } |
1412 | ||
c906108c | 1413 | \f |
357e46e7 | 1414 | |
c906108c | 1415 | void |
554d387d | 1416 | record_debugformat (const char *format) |
c906108c | 1417 | { |
4a2125f5 | 1418 | buildsym_compunit->record_debugformat (format); |
c906108c SS |
1419 | } |
1420 | ||
303b6f5d DJ |
1421 | void |
1422 | record_producer (const char *producer) | |
1423 | { | |
4a2125f5 | 1424 | buildsym_compunit->record_producer (producer); |
303b6f5d DJ |
1425 | } |
1426 | ||
c906108c | 1427 | \f |
46212e0b | 1428 | |
46212e0b TT |
1429 | /* See buildsym.h. */ |
1430 | ||
1431 | void | |
1432 | set_last_source_file (const char *name) | |
1433 | { | |
c0015d44 TT |
1434 | gdb_assert (buildsym_compunit != nullptr || name == nullptr); |
1435 | if (buildsym_compunit != nullptr) | |
1436 | buildsym_compunit->set_last_source_file (name); | |
46212e0b TT |
1437 | } |
1438 | ||
1439 | /* See buildsym.h. */ | |
1440 | ||
1441 | const char * | |
4a2125f5 | 1442 | get_last_source_file () |
46212e0b | 1443 | { |
c0015d44 TT |
1444 | if (buildsym_compunit == nullptr) |
1445 | return nullptr; | |
4a2125f5 | 1446 | return buildsym_compunit->get_last_source_file (); |
46212e0b TT |
1447 | } |
1448 | ||
2c99ee5c TT |
1449 | /* See buildsym.h. */ |
1450 | ||
1451 | void | |
1452 | set_last_source_start_addr (CORE_ADDR addr) | |
1453 | { | |
1454 | gdb_assert (buildsym_compunit != nullptr); | |
4a2125f5 | 1455 | buildsym_compunit->set_last_source_start_addr (addr); |
2c99ee5c TT |
1456 | } |
1457 | ||
1458 | /* See buildsym.h. */ | |
1459 | ||
1460 | CORE_ADDR | |
1461 | get_last_source_start_addr () | |
1462 | { | |
1463 | gdb_assert (buildsym_compunit != nullptr); | |
4a2125f5 | 1464 | return buildsym_compunit->get_last_source_start_addr (); |
2c99ee5c TT |
1465 | } |
1466 | ||
6cccc9a8 TT |
1467 | /* See buildsym.h. */ |
1468 | ||
1469 | struct using_direct ** | |
1470 | get_local_using_directives () | |
1471 | { | |
1472 | gdb_assert (buildsym_compunit != nullptr); | |
4a2125f5 | 1473 | return buildsym_compunit->get_local_using_directives (); |
6cccc9a8 TT |
1474 | } |
1475 | ||
1476 | /* See buildsym.h. */ | |
1477 | ||
1478 | void | |
1479 | set_local_using_directives (struct using_direct *new_local) | |
1480 | { | |
1481 | gdb_assert (buildsym_compunit != nullptr); | |
4a2125f5 | 1482 | buildsym_compunit->set_local_using_directives (new_local); |
6cccc9a8 TT |
1483 | } |
1484 | ||
1485 | /* See buildsym.h. */ | |
1486 | ||
1487 | struct using_direct ** | |
1488 | get_global_using_directives () | |
1489 | { | |
1490 | gdb_assert (buildsym_compunit != nullptr); | |
4a2125f5 | 1491 | return buildsym_compunit->get_global_using_directives (); |
6cccc9a8 TT |
1492 | } |
1493 | ||
a60f3166 TT |
1494 | /* See buildsym.h. */ |
1495 | ||
1496 | bool | |
1497 | outermost_context_p () | |
1498 | { | |
1499 | gdb_assert (buildsym_compunit != nullptr); | |
4a2125f5 | 1500 | return buildsym_compunit->outermost_context_p (); |
a60f3166 TT |
1501 | } |
1502 | ||
1503 | /* See buildsym.h. */ | |
1504 | ||
1505 | struct context_stack * | |
1506 | get_current_context_stack () | |
1507 | { | |
1508 | gdb_assert (buildsym_compunit != nullptr); | |
4a2125f5 | 1509 | return buildsym_compunit->get_current_context_stack (); |
a60f3166 TT |
1510 | } |
1511 | ||
1512 | /* See buildsym.h. */ | |
1513 | ||
1514 | int | |
1515 | get_context_stack_depth () | |
1516 | { | |
1517 | gdb_assert (buildsym_compunit != nullptr); | |
4a2125f5 | 1518 | return buildsym_compunit->get_context_stack_depth (); |
a60f3166 TT |
1519 | } |
1520 | ||
3c65e5b3 TT |
1521 | /* See buildsym.h. */ |
1522 | ||
1523 | struct subfile * | |
1524 | get_current_subfile () | |
1525 | { | |
1526 | gdb_assert (buildsym_compunit != nullptr); | |
4a2125f5 | 1527 | return buildsym_compunit->get_current_subfile (); |
3c65e5b3 TT |
1528 | } |
1529 | ||
e148f09d TT |
1530 | /* See buildsym.h. */ |
1531 | ||
1532 | struct pending ** | |
1533 | get_local_symbols () | |
1534 | { | |
1535 | gdb_assert (buildsym_compunit != nullptr); | |
4a2125f5 | 1536 | return buildsym_compunit->get_local_symbols (); |
e148f09d TT |
1537 | } |
1538 | ||
1539 | /* See buildsym.h. */ | |
1540 | ||
1541 | struct pending ** | |
1542 | get_file_symbols () | |
1543 | { | |
1544 | gdb_assert (buildsym_compunit != nullptr); | |
4a2125f5 | 1545 | return buildsym_compunit->get_file_symbols (); |
e148f09d TT |
1546 | } |
1547 | ||
1548 | /* See buildsym.h. */ | |
1549 | ||
1550 | struct pending ** | |
1551 | get_global_symbols () | |
1552 | { | |
1553 | gdb_assert (buildsym_compunit != nullptr); | |
4a2125f5 TT |
1554 | return buildsym_compunit->get_global_symbols (); |
1555 | } | |
1556 | ||
1557 | void | |
1558 | start_subfile (const char *name) | |
1559 | { | |
1560 | gdb_assert (buildsym_compunit != nullptr); | |
1561 | buildsym_compunit->start_subfile (name); | |
1562 | } | |
1563 | ||
1564 | void | |
1565 | patch_subfile_names (struct subfile *subfile, const char *name) | |
1566 | { | |
1567 | gdb_assert (buildsym_compunit != nullptr); | |
1568 | buildsym_compunit->patch_subfile_names (subfile, name); | |
1569 | } | |
1570 | ||
1571 | void | |
1572 | push_subfile () | |
1573 | { | |
1574 | gdb_assert (buildsym_compunit != nullptr); | |
1575 | buildsym_compunit->push_subfile (); | |
1576 | } | |
1577 | ||
1578 | const char * | |
1579 | pop_subfile () | |
1580 | { | |
1581 | gdb_assert (buildsym_compunit != nullptr); | |
1582 | return buildsym_compunit->pop_subfile (); | |
1583 | } | |
1584 | ||
1585 | struct block * | |
1586 | end_symtab_get_static_block (CORE_ADDR end_addr, int expandable, int required) | |
1587 | { | |
1588 | gdb_assert (buildsym_compunit != nullptr); | |
1589 | return buildsym_compunit->end_symtab_get_static_block (end_addr, expandable, | |
1590 | required); | |
1591 | } | |
1592 | ||
1593 | struct compunit_symtab * | |
1594 | end_symtab_from_static_block (struct block *static_block, | |
1595 | int section, int expandable) | |
1596 | { | |
1597 | gdb_assert (buildsym_compunit != nullptr); | |
1598 | struct compunit_symtab *result | |
1599 | = buildsym_compunit->end_symtab_from_static_block (static_block, | |
1600 | section, expandable); | |
74c72eac | 1601 | free_buildsym_compunit (); |
4a2125f5 TT |
1602 | return result; |
1603 | } | |
1604 | ||
1605 | struct compunit_symtab * | |
1606 | end_symtab (CORE_ADDR end_addr, int section) | |
1607 | { | |
1608 | gdb_assert (buildsym_compunit != nullptr); | |
1609 | struct compunit_symtab *result | |
1610 | = buildsym_compunit->end_symtab (end_addr, section); | |
74c72eac | 1611 | free_buildsym_compunit (); |
4a2125f5 TT |
1612 | return result; |
1613 | } | |
1614 | ||
1615 | struct compunit_symtab * | |
1616 | end_expandable_symtab (CORE_ADDR end_addr, int section) | |
1617 | { | |
1618 | gdb_assert (buildsym_compunit != nullptr); | |
1619 | struct compunit_symtab *result | |
1620 | = buildsym_compunit->end_expandable_symtab (end_addr, section); | |
74c72eac | 1621 | free_buildsym_compunit (); |
4a2125f5 TT |
1622 | return result; |
1623 | } | |
1624 | ||
1625 | void | |
1626 | augment_type_symtab () | |
1627 | { | |
1628 | gdb_assert (buildsym_compunit != nullptr); | |
1629 | buildsym_compunit->augment_type_symtab (); | |
74c72eac | 1630 | free_buildsym_compunit (); |
4a2125f5 TT |
1631 | } |
1632 | ||
1633 | struct context_stack * | |
1634 | push_context (int desc, CORE_ADDR valu) | |
1635 | { | |
1636 | gdb_assert (buildsym_compunit != nullptr); | |
1637 | return buildsym_compunit->push_context (desc, valu); | |
1638 | } | |
1639 | ||
1640 | struct context_stack | |
1641 | pop_context () | |
1642 | { | |
1643 | gdb_assert (buildsym_compunit != nullptr); | |
1644 | return buildsym_compunit->pop_context (); | |
1645 | } | |
1646 | ||
1647 | struct block * | |
1648 | finish_block (struct symbol *symbol, struct pending_block *old_blocks, | |
1649 | const struct dynamic_prop *static_link, | |
1650 | CORE_ADDR start, CORE_ADDR end) | |
1651 | { | |
1652 | gdb_assert (buildsym_compunit != nullptr); | |
1653 | return buildsym_compunit->finish_block (symbol, old_blocks, static_link, | |
1654 | start, end); | |
1655 | } | |
1656 | ||
1657 | void | |
1658 | record_block_range (struct block *block, CORE_ADDR start, | |
1659 | CORE_ADDR end_inclusive) | |
1660 | { | |
1661 | gdb_assert (buildsym_compunit != nullptr); | |
1662 | buildsym_compunit->record_block_range (block, start, end_inclusive); | |
1663 | } | |
1664 | ||
1665 | void | |
1666 | record_line (struct subfile *subfile, int line, CORE_ADDR pc) | |
1667 | { | |
1668 | gdb_assert (buildsym_compunit != nullptr); | |
1669 | buildsym_compunit->record_line (subfile, line, pc); | |
e148f09d | 1670 | } |