]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/buildsym.c
Automatic date update in version.in
[thirdparty/binutils-gdb.git] / gdb / buildsym.c
CommitLineData
c906108c 1/* Support routines for building symbol tables in GDB's internal format.
42a4f53d 2 Copyright (C) 1986-2019 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 18
c906108c 19#include "defs.h"
0baae8db 20#include "buildsym-legacy.h"
c906108c 21#include "bfd.h"
04ea0df1 22#include "gdb_obstack.h"
c906108c 23#include "symtab.h"
72367fb4 24#include "symfile.h"
c906108c
SS
25#include "objfiles.h"
26#include "gdbtypes.h"
27#include "complaints.h"
4a64f543 28#include "expression.h" /* For "enum exp_opcode" used by... */
4a64f543 29#include "filenames.h" /* For DOSish file names. */
99d9066e 30#include "macrotab.h"
261397f8 31#include "demangle.h" /* Needed by SYMBOL_INIT_DEMANGLED_NAME. */
fe898f56 32#include "block.h"
9219021c 33#include "cp-support.h"
de4f826b 34#include "dictionary.h"
801e3a5b 35#include "addrmap.h"
b05628f0 36#include <algorithm>
9219021c 37
0a0edcd5 38/* For cleanup_undefined_stabs_types and finish_global_stabs (somewhat
c906108c
SS
39 questionable--see comment where we call them). */
40
41#include "stabsread.h"
42
93eed41f
TT
43/* List of blocks already made (lexical contexts already closed).
44 This is used at the end to make the blockvector. */
45
46struct pending_block
47 {
48 struct pending_block *next;
49 struct block *block;
50 };
51
c906108c 52static int compare_line_numbers (const void *ln1p, const void *ln2p);
0b49e518 53
c906108c
SS
54/* Initial sizes of data structures. These are realloc'd larger if
55 needed, and realloc'd down to the size actually used, when
56 completed. */
57
c906108c
SS
58#define INITIAL_LINE_VECTOR_LENGTH 1000
59\f
60
ab209f6f
TT
61buildsym_compunit::buildsym_compunit (struct objfile *objfile_,
62 const char *name,
63 const char *comp_dir_,
64 enum language language_,
65 CORE_ADDR last_addr)
cbb09508 66 : m_objfile (objfile_),
ab209f6f 67 m_last_source_file (name == nullptr ? nullptr : xstrdup (name)),
cbb09508
KS
68 m_comp_dir (comp_dir_ == nullptr ? nullptr : xstrdup (comp_dir_)),
69 m_language (language_),
ab209f6f
TT
70 m_last_source_start_addr (last_addr)
71{
72 /* Allocate the compunit symtab now. The caller needs it to allocate
73 non-primary symtabs. It is also needed by get_macro_table. */
cbb09508 74 m_compunit_symtab = allocate_compunit_symtab (m_objfile, name);
ab209f6f
TT
75
76 /* Build the subfile for NAME (the main source file) so that we can record
77 a pointer to it for later.
78 IMPORTANT: Do not allocate a struct symtab for NAME here.
79 It can happen that the debug info provides a different path to NAME than
80 DIRNAME,NAME. We cope with this in watch_main_source_file_lossage but
81 that only works if the main_subfile doesn't have a symtab yet. */
82 start_subfile (name);
83 /* Save this so that we don't have to go looking for it at the end
84 of the subfiles list. */
cbb09508 85 m_main_subfile = m_current_subfile;
ab209f6f
TT
86}
87
88buildsym_compunit::~buildsym_compunit ()
89{
90 struct subfile *subfile, *nextsub;
91
92 if (m_pending_macros != nullptr)
93 free_macro_table (m_pending_macros);
94
cbb09508 95 for (subfile = m_subfiles;
ab209f6f
TT
96 subfile != NULL;
97 subfile = nextsub)
98 {
99 nextsub = subfile->next;
100 xfree (subfile->name);
101 xfree (subfile->line_vector);
102 xfree (subfile);
103 }
104
105 struct pending *next, *next1;
106
107 for (next = m_file_symbols; next != NULL; next = next1)
108 {
109 next1 = next->next;
110 xfree ((void *) next);
111 }
112
113 for (next = m_global_symbols; next != NULL; next = next1)
114 {
115 next1 = next->next;
116 xfree ((void *) next);
117 }
118}
119
120struct macro_table *
121buildsym_compunit::get_macro_table ()
122{
123 if (m_pending_macros == nullptr)
cbb09508 124 m_pending_macros = new_macro_table (&m_objfile->per_bfd->storage_obstack,
25629dfd 125 &m_objfile->per_bfd->macro_cache,
cbb09508 126 m_compunit_symtab);
ab209f6f
TT
127 return m_pending_macros;
128}
129
4a64f543 130/* Maintain the lists of symbols and blocks. */
c906108c 131
93bf33fd 132/* Add a symbol to one of the lists of symbols. */
c906108c
SS
133
134void
135add_symbol_to_list (struct symbol *symbol, struct pending **listhead)
136{
52f0bd74 137 struct pending *link;
c906108c
SS
138
139 /* If this is an alias for another symbol, don't add it. */
140 if (symbol->ginfo.name && symbol->ginfo.name[0] == '#')
141 return;
142
4a64f543 143 /* We keep PENDINGSIZE symbols in each link of the list. If we
c906108c
SS
144 don't have a link with room in it, add a new link. */
145 if (*listhead == NULL || (*listhead)->nsyms == PENDINGSIZE)
146 {
1d376700 147 link = XNEW (struct pending);
c906108c
SS
148 link->next = *listhead;
149 *listhead = link;
150 link->nsyms = 0;
151 }
152
153 (*listhead)->symbol[(*listhead)->nsyms++] = symbol;
154}
155
156/* Find a symbol named NAME on a LIST. NAME need not be
157 '\0'-terminated; LENGTH is the length of the name. */
158
159struct symbol *
160find_symbol_in_list (struct pending *list, char *name, int length)
161{
162 int j;
0d5cff50 163 const char *pp;
c906108c
SS
164
165 while (list != NULL)
166 {
167 for (j = list->nsyms; --j >= 0;)
168 {
3567439c 169 pp = SYMBOL_LINKAGE_NAME (list->symbol[j]);
5aafa1cc
PM
170 if (*pp == *name && strncmp (pp, name, length) == 0
171 && pp[length] == '\0')
c906108c
SS
172 {
173 return (list->symbol[j]);
174 }
175 }
176 list = list->next;
177 }
178 return (NULL);
179}
180
6b213a47
TT
181/* Record BLOCK on the list of all blocks in the file. Put it after
182 OPBLOCK, or at the beginning if opblock is NULL. This puts the
183 block in the list after all its subblocks. */
184
4a2125f5
TT
185void
186buildsym_compunit::record_pending_block (struct block *block,
187 struct pending_block *opblock)
6b213a47
TT
188{
189 struct pending_block *pblock;
190
4a2125f5 191 pblock = XOBNEW (&m_pending_block_obstack, struct pending_block);
6b213a47
TT
192 pblock->block = block;
193 if (opblock)
194 {
195 pblock->next = opblock->next;
196 opblock->next = pblock;
197 }
198 else
199 {
4a2125f5
TT
200 pblock->next = m_pending_blocks;
201 m_pending_blocks = pblock;
6b213a47
TT
202 }
203}
204
c906108c
SS
205/* Take one of the lists of symbols and make a block from it. Keep
206 the order the symbols have in the list (reversed from the input
207 file). Put the block on the list of pending blocks. */
208
4a2125f5
TT
209struct block *
210buildsym_compunit::finish_block_internal
211 (struct symbol *symbol,
212 struct pending **listhead,
213 struct pending_block *old_blocks,
214 const struct dynamic_prop *static_link,
215 CORE_ADDR start, CORE_ADDR end,
216 int is_global, int expandable)
c906108c 217{
cbb09508 218 struct gdbarch *gdbarch = get_objfile_arch (m_objfile);
52f0bd74
AC
219 struct pending *next, *next1;
220 struct block *block;
221 struct pending_block *pblock;
c906108c 222 struct pending_block *opblock;
c906108c 223
84a146c9 224 block = (is_global
cbb09508
KS
225 ? allocate_global_block (&m_objfile->objfile_obstack)
226 : allocate_block (&m_objfile->objfile_obstack));
c906108c 227
261397f8
DJ
228 if (symbol)
229 {
b026f593
KS
230 BLOCK_MULTIDICT (block)
231 = mdict_create_linear (&m_objfile->objfile_obstack, *listhead);
261397f8
DJ
232 }
233 else
c906108c 234 {
6d30eef8
DE
235 if (expandable)
236 {
b026f593
KS
237 BLOCK_MULTIDICT (block) = mdict_create_hashed_expandable (m_language);
238 mdict_add_pending (BLOCK_MULTIDICT (block), *listhead);
6d30eef8
DE
239 }
240 else
241 {
b026f593
KS
242 BLOCK_MULTIDICT (block) =
243 mdict_create_hashed (&m_objfile->objfile_obstack, *listhead);
6d30eef8 244 }
c906108c
SS
245 }
246
247 BLOCK_START (block) = start;
248 BLOCK_END (block) = end;
c906108c 249
c906108c
SS
250 /* Put the block in as the value of the symbol that names it. */
251
252 if (symbol)
253 {
254 struct type *ftype = SYMBOL_TYPE (symbol);
b026f593 255 struct mdict_iterator miter;
c906108c
SS
256 SYMBOL_BLOCK_VALUE (symbol) = block;
257 BLOCK_FUNCTION (block) = symbol;
258
259 if (TYPE_NFIELDS (ftype) <= 0)
260 {
261 /* No parameter type information is recorded with the
262 function's type. Set that from the type of the
4a64f543 263 parameter symbols. */
c906108c
SS
264 int nparams = 0, iparams;
265 struct symbol *sym;
8157b174
TT
266
267 /* Here we want to directly access the dictionary, because
268 we haven't fully initialized the block yet. */
b026f593 269 ALL_DICT_SYMBOLS (BLOCK_MULTIDICT (block), miter, sym)
c906108c 270 {
2a2d4dc3
AS
271 if (SYMBOL_IS_ARGUMENT (sym))
272 nparams++;
c906108c
SS
273 }
274 if (nparams > 0)
275 {
276 TYPE_NFIELDS (ftype) = nparams;
277 TYPE_FIELDS (ftype) = (struct field *)
278 TYPE_ALLOC (ftype, nparams * sizeof (struct field));
279
de4f826b 280 iparams = 0;
8157b174
TT
281 /* Here we want to directly access the dictionary, because
282 we haven't fully initialized the block yet. */
b026f593 283 ALL_DICT_SYMBOLS (BLOCK_MULTIDICT (block), miter, sym)
c906108c 284 {
de4f826b
DC
285 if (iparams == nparams)
286 break;
287
2a2d4dc3 288 if (SYMBOL_IS_ARGUMENT (sym))
c906108c 289 {
c906108c 290 TYPE_FIELD_TYPE (ftype, iparams) = SYMBOL_TYPE (sym);
8176bb6d 291 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0;
c906108c 292 iparams++;
c906108c
SS
293 }
294 }
295 }
296 }
297 }
298 else
299 {
300 BLOCK_FUNCTION (block) = NULL;
301 }
302
63e43d3a 303 if (static_link != NULL)
cbb09508 304 objfile_register_static_link (m_objfile, block, static_link);
63e43d3a 305
1d376700 306 /* Now free the links of the list, and empty the list. */
c906108c
SS
307
308 for (next = *listhead; next; next = next1)
309 {
310 next1 = next->next;
1d376700 311 xfree (next);
c906108c
SS
312 }
313 *listhead = NULL;
314
c906108c 315 /* Check to be sure that the blocks have an end address that is
4a64f543 316 greater than starting address. */
c906108c
SS
317
318 if (BLOCK_END (block) < BLOCK_START (block))
319 {
320 if (symbol)
321 {
b98664d3 322 complaint (_("block end address less than block "
3e43a32a 323 "start address in %s (patched it)"),
de5ad195 324 SYMBOL_PRINT_NAME (symbol));
c906108c
SS
325 }
326 else
327 {
b98664d3 328 complaint (_("block end address %s less than block "
3e43a32a 329 "start address %s (patched it)"),
5af949e3
UW
330 paddress (gdbarch, BLOCK_END (block)),
331 paddress (gdbarch, BLOCK_START (block)));
c906108c 332 }
4a64f543 333 /* Better than nothing. */
c906108c
SS
334 BLOCK_END (block) = BLOCK_START (block);
335 }
c906108c
SS
336
337 /* Install this block as the superblock of all blocks made since the
338 start of this scope that don't have superblocks yet. */
339
340 opblock = NULL;
4a2125f5 341 for (pblock = m_pending_blocks;
c0219d42
MS
342 pblock && pblock != old_blocks;
343 pblock = pblock->next)
c906108c
SS
344 {
345 if (BLOCK_SUPERBLOCK (pblock->block) == NULL)
346 {
c906108c 347 /* Check to be sure the blocks are nested as we receive
4a64f543 348 them. If the compiler/assembler/linker work, this just
14711c82
DJ
349 burns a small amount of time.
350
351 Skip blocks which correspond to a function; they're not
352 physically nested inside this other blocks, only
353 lexically nested. */
354 if (BLOCK_FUNCTION (pblock->block) == NULL
355 && (BLOCK_START (pblock->block) < BLOCK_START (block)
356 || BLOCK_END (pblock->block) > BLOCK_END (block)))
c906108c
SS
357 {
358 if (symbol)
359 {
b98664d3 360 complaint (_("inner block not inside outer block in %s"),
de5ad195 361 SYMBOL_PRINT_NAME (symbol));
c906108c
SS
362 }
363 else
364 {
b98664d3 365 complaint (_("inner block (%s-%s) not "
3e43a32a 366 "inside outer block (%s-%s)"),
5af949e3
UW
367 paddress (gdbarch, BLOCK_START (pblock->block)),
368 paddress (gdbarch, BLOCK_END (pblock->block)),
369 paddress (gdbarch, BLOCK_START (block)),
370 paddress (gdbarch, BLOCK_END (block)));
c906108c
SS
371 }
372 if (BLOCK_START (pblock->block) < BLOCK_START (block))
373 BLOCK_START (pblock->block) = BLOCK_START (block);
374 if (BLOCK_END (pblock->block) > BLOCK_END (block))
375 BLOCK_END (pblock->block) = BLOCK_END (block);
376 }
c906108c
SS
377 BLOCK_SUPERBLOCK (pblock->block) = block;
378 }
379 opblock = pblock;
380 }
381
22cee43f
PMR
382 block_set_using (block,
383 (is_global
4a2125f5
TT
384 ? m_global_using_directives
385 : m_local_using_directives),
cbb09508 386 &m_objfile->objfile_obstack);
22cee43f 387 if (is_global)
4a2125f5 388 m_global_using_directives = NULL;
22cee43f 389 else
4a2125f5 390 m_local_using_directives = NULL;
27aa8d6a 391
6b213a47 392 record_pending_block (block, opblock);
801e3a5b
JB
393
394 return block;
c906108c
SS
395}
396
84a146c9 397struct block *
4a2125f5
TT
398buildsym_compunit::finish_block (struct symbol *symbol,
399 struct pending_block *old_blocks,
400 const struct dynamic_prop *static_link,
401 CORE_ADDR start, CORE_ADDR end)
84a146c9 402{
4a2125f5
TT
403 return finish_block_internal (symbol, &m_local_symbols,
404 old_blocks, static_link, start, end, 0, 0);
84a146c9 405}
de4f826b 406
801e3a5b
JB
407/* Record that the range of addresses from START to END_INCLUSIVE
408 (inclusive, like it says) belongs to BLOCK. BLOCK's start and end
409 addresses must be set already. You must apply this function to all
410 BLOCK's children before applying it to BLOCK.
411
412 If a call to this function complicates the picture beyond that
413 already provided by BLOCK_START and BLOCK_END, then we create an
414 address map for the block. */
415void
4a2125f5
TT
416buildsym_compunit::record_block_range (struct block *block,
417 CORE_ADDR start,
418 CORE_ADDR end_inclusive)
801e3a5b
JB
419{
420 /* If this is any different from the range recorded in the block's
421 own BLOCK_START and BLOCK_END, then note that the address map has
422 become interesting. Note that even if this block doesn't have
423 any "interesting" ranges, some later block might, so we still
424 need to record this block in the addrmap. */
425 if (start != BLOCK_START (block)
426 || end_inclusive + 1 != BLOCK_END (block))
4a2125f5 427 m_pending_addrmap_interesting = true;
801e3a5b 428
4a2125f5
TT
429 if (m_pending_addrmap == nullptr)
430 m_pending_addrmap = addrmap_create_mutable (&m_pending_addrmap_obstack);
801e3a5b 431
4a2125f5 432 addrmap_set_empty (m_pending_addrmap, start, end_inclusive, block);
801e3a5b
JB
433}
434
4a2125f5
TT
435struct blockvector *
436buildsym_compunit::make_blockvector ()
c906108c 437{
52f0bd74
AC
438 struct pending_block *next;
439 struct blockvector *blockvector;
440 int i;
c906108c
SS
441
442 /* Count the length of the list of blocks. */
443
4a2125f5 444 for (next = m_pending_blocks, i = 0; next; next = next->next, i++)
5ac04550 445 {
c906108c
SS
446 }
447
448 blockvector = (struct blockvector *)
cbb09508 449 obstack_alloc (&m_objfile->objfile_obstack,
c906108c
SS
450 (sizeof (struct blockvector)
451 + (i - 1) * sizeof (struct block *)));
452
4a64f543 453 /* Copy the blocks into the blockvector. This is done in reverse
c906108c 454 order, which happens to put the blocks into the proper order
4a64f543 455 (ascending starting address). finish_block has hair to insert
c906108c
SS
456 each block into the list after its subblocks in order to make
457 sure this is true. */
458
459 BLOCKVECTOR_NBLOCKS (blockvector) = i;
4a2125f5 460 for (next = m_pending_blocks; next; next = next->next)
c906108c
SS
461 {
462 BLOCKVECTOR_BLOCK (blockvector, --i) = next->block;
463 }
464
4a2125f5 465 free_pending_blocks ();
c906108c 466
801e3a5b
JB
467 /* If we needed an address map for this symtab, record it in the
468 blockvector. */
4a2125f5 469 if (m_pending_addrmap != nullptr && m_pending_addrmap_interesting)
801e3a5b 470 BLOCKVECTOR_MAP (blockvector)
cbb09508 471 = addrmap_create_fixed (m_pending_addrmap, &m_objfile->objfile_obstack);
801e3a5b
JB
472 else
473 BLOCKVECTOR_MAP (blockvector) = 0;
4aad0dfc 474
c906108c 475 /* Some compilers output blocks in the wrong order, but we depend on
4a64f543 476 their being in the right order so we can binary search. Check the
4aad0dfc
DE
477 order and moan about it.
478 Note: Remember that the first two blocks are the global and static
479 blocks. We could special case that fact and begin checking at block 2.
480 To avoid making that assumption we do not. */
c906108c
SS
481 if (BLOCKVECTOR_NBLOCKS (blockvector) > 1)
482 {
483 for (i = 1; i < BLOCKVECTOR_NBLOCKS (blockvector); i++)
484 {
485 if (BLOCK_START (BLOCKVECTOR_BLOCK (blockvector, i - 1))
486 > BLOCK_START (BLOCKVECTOR_BLOCK (blockvector, i)))
487 {
59527da0
JB
488 CORE_ADDR start
489 = BLOCK_START (BLOCKVECTOR_BLOCK (blockvector, i));
c906108c 490
b98664d3 491 complaint (_("block at %s out of order"),
bb599908 492 hex_string ((LONGEST) start));
c906108c
SS
493 }
494 }
495 }
c906108c
SS
496
497 return (blockvector);
498}
499\f
500/* Start recording information about source code that came from an
501 included (or otherwise merged-in) source file with a different
4d663531 502 name. NAME is the name of the file (cannot be NULL). */
c906108c
SS
503
504void
4a2125f5 505buildsym_compunit::start_subfile (const char *name)
c906108c 506{
43f3e411 507 const char *subfile_dirname;
52f0bd74 508 struct subfile *subfile;
c906108c 509
cbb09508 510 subfile_dirname = m_comp_dir.get ();
c906108c 511
43f3e411
DE
512 /* See if this subfile is already registered. */
513
cbb09508 514 for (subfile = m_subfiles; subfile; subfile = subfile->next)
c906108c 515 {
84ba0adf
DJ
516 char *subfile_name;
517
518 /* If NAME is an absolute path, and this subfile is not, then
519 attempt to create an absolute path to compare. */
520 if (IS_ABSOLUTE_PATH (name)
521 && !IS_ABSOLUTE_PATH (subfile->name)
43f3e411
DE
522 && subfile_dirname != NULL)
523 subfile_name = concat (subfile_dirname, SLASH_STRING,
6eb7ee03 524 subfile->name, (char *) NULL);
84ba0adf
DJ
525 else
526 subfile_name = subfile->name;
527
528 if (FILENAME_CMP (subfile_name, name) == 0)
c906108c 529 {
4a2125f5 530 m_current_subfile = subfile;
84ba0adf
DJ
531 if (subfile_name != subfile->name)
532 xfree (subfile_name);
c906108c
SS
533 return;
534 }
84ba0adf
DJ
535 if (subfile_name != subfile->name)
536 xfree (subfile_name);
c906108c
SS
537 }
538
43f3e411 539 /* This subfile is not known. Add an entry for it. */
c906108c 540
8d749320 541 subfile = XNEW (struct subfile);
43f3e411 542 memset (subfile, 0, sizeof (struct subfile));
4a2125f5 543 subfile->buildsym_compunit = this;
43f3e411 544
cbb09508
KS
545 subfile->next = m_subfiles;
546 m_subfiles = subfile;
43f3e411 547
4a2125f5 548 m_current_subfile = subfile;
c906108c 549
b74db436 550 subfile->name = xstrdup (name);
c906108c
SS
551
552 /* Initialize line-number recording for this subfile. */
553 subfile->line_vector = NULL;
554
555 /* Default the source language to whatever can be deduced from the
556 filename. If nothing can be deduced (such as for a C/C++ include
557 file with a ".h" extension), then inherit whatever language the
558 previous subfile had. This kludgery is necessary because there
559 is no standard way in some object formats to record the source
560 language. Also, when symtabs are allocated we try to deduce a
561 language then as well, but it is too late for us to use that
562 information while reading symbols, since symtabs aren't allocated
563 until after all the symbols have been processed for a given
4a64f543 564 source file. */
c906108c
SS
565
566 subfile->language = deduce_language_from_filename (subfile->name);
5aafa1cc
PM
567 if (subfile->language == language_unknown
568 && subfile->next != NULL)
c906108c
SS
569 {
570 subfile->language = subfile->next->language;
571 }
572
25caa7a8 573 /* If the filename of this subfile ends in .C, then change the
c906108c 574 language of any pending subfiles from C to C++. We also accept
25caa7a8 575 any other C++ suffixes accepted by deduce_language_from_filename. */
c906108c
SS
576 /* Likewise for f2c. */
577
578 if (subfile->name)
579 {
580 struct subfile *s;
581 enum language sublang = deduce_language_from_filename (subfile->name);
582
583 if (sublang == language_cplus || sublang == language_fortran)
cbb09508 584 for (s = m_subfiles; s != NULL; s = s->next)
c906108c
SS
585 if (s->language == language_c)
586 s->language = sublang;
587 }
588
589 /* And patch up this file if necessary. */
590 if (subfile->language == language_c
591 && subfile->next != NULL
592 && (subfile->next->language == language_cplus
593 || subfile->next->language == language_fortran))
594 {
595 subfile->language = subfile->next->language;
596 }
597}
598
599/* For stabs readers, the first N_SO symbol is assumed to be the
600 source file name, and the subfile struct is initialized using that
601 assumption. If another N_SO symbol is later seen, immediately
602 following the first one, then the first one is assumed to be the
603 directory name and the second one is really the source file name.
604
605 So we have to patch up the subfile struct by moving the old name
606 value to dirname and remembering the new name. Some sanity
607 checking is performed to ensure that the state of the subfile
608 struct is reasonable and that the old name we are assuming to be a
4a64f543 609 directory name actually is (by checking for a trailing '/'). */
c906108c
SS
610
611void
4a2125f5
TT
612buildsym_compunit::patch_subfile_names (struct subfile *subfile,
613 const char *name)
c906108c 614{
43f3e411 615 if (subfile != NULL
cbb09508 616 && m_comp_dir == NULL
43f3e411 617 && subfile->name != NULL
0ba1096a 618 && IS_DIR_SEPARATOR (subfile->name[strlen (subfile->name) - 1]))
c906108c 619 {
cbb09508 620 m_comp_dir.reset (subfile->name);
1b36a34b 621 subfile->name = xstrdup (name);
46212e0b 622 set_last_source_file (name);
c906108c
SS
623
624 /* Default the source language to whatever can be deduced from
625 the filename. If nothing can be deduced (such as for a C/C++
626 include file with a ".h" extension), then inherit whatever
627 language the previous subfile had. This kludgery is
628 necessary because there is no standard way in some object
629 formats to record the source language. Also, when symtabs
630 are allocated we try to deduce a language then as well, but
631 it is too late for us to use that information while reading
632 symbols, since symtabs aren't allocated until after all the
4a64f543 633 symbols have been processed for a given source file. */
c906108c
SS
634
635 subfile->language = deduce_language_from_filename (subfile->name);
5aafa1cc
PM
636 if (subfile->language == language_unknown
637 && subfile->next != NULL)
c906108c
SS
638 {
639 subfile->language = subfile->next->language;
640 }
641 }
642}
643\f
644/* Handle the N_BINCL and N_EINCL symbol types that act like N_SOL for
645 switching source files (different subfiles, as we call them) within
646 one object file, but using a stack rather than in an arbitrary
647 order. */
648
649void
4a2125f5 650buildsym_compunit::push_subfile ()
c906108c 651{
4a2125f5
TT
652 gdb_assert (m_current_subfile != NULL);
653 gdb_assert (m_current_subfile->name != NULL);
654 m_subfile_stack.push_back (m_current_subfile->name);
c906108c
SS
655}
656
8419ee53 657const char *
4a2125f5 658buildsym_compunit::pop_subfile ()
c906108c 659{
4a2125f5
TT
660 gdb_assert (!m_subfile_stack.empty ());
661 const char *name = m_subfile_stack.back ();
662 m_subfile_stack.pop_back ();
8419ee53 663 return name;
c906108c
SS
664}
665\f
666/* Add a linetable entry for line number LINE and address PC to the
667 line vector for SUBFILE. */
668
669void
4a2125f5
TT
670buildsym_compunit::record_line (struct subfile *subfile, int line,
671 CORE_ADDR pc)
c906108c
SS
672{
673 struct linetable_entry *e;
c906108c 674
cc59ec59 675 /* Ignore the dummy line number in libg.o */
c906108c
SS
676 if (line == 0xffff)
677 {
678 return;
679 }
680
681 /* Make sure line vector exists and is big enough. */
682 if (!subfile->line_vector)
683 {
684 subfile->line_vector_length = INITIAL_LINE_VECTOR_LENGTH;
685 subfile->line_vector = (struct linetable *)
686 xmalloc (sizeof (struct linetable)
c5aa993b 687 + subfile->line_vector_length * sizeof (struct linetable_entry));
c906108c 688 subfile->line_vector->nitems = 0;
4a2125f5 689 m_have_line_numbers = true;
c906108c
SS
690 }
691
692 if (subfile->line_vector->nitems + 1 >= subfile->line_vector_length)
693 {
694 subfile->line_vector_length *= 2;
695 subfile->line_vector = (struct linetable *)
696 xrealloc ((char *) subfile->line_vector,
697 (sizeof (struct linetable)
698 + (subfile->line_vector_length
699 * sizeof (struct linetable_entry))));
700 }
701
607ae575
DJ
702 /* Normally, we treat lines as unsorted. But the end of sequence
703 marker is special. We sort line markers at the same PC by line
704 number, so end of sequence markers (which have line == 0) appear
705 first. This is right if the marker ends the previous function,
706 and there is no padding before the next function. But it is
707 wrong if the previous line was empty and we are now marking a
708 switch to a different subfile. We must leave the end of sequence
709 marker at the end of this group of lines, not sort the empty line
710 to after the marker. The easiest way to accomplish this is to
711 delete any empty lines from our table, if they are followed by
712 end of sequence markers. All we lose is the ability to set
713 breakpoints at some lines which contain no instructions
714 anyway. */
715 if (line == 0 && subfile->line_vector->nitems > 0)
716 {
717 e = subfile->line_vector->item + subfile->line_vector->nitems - 1;
718 while (subfile->line_vector->nitems > 0 && e->pc == pc)
719 {
720 e--;
721 subfile->line_vector->nitems--;
722 }
723 }
724
c906108c
SS
725 e = subfile->line_vector->item + subfile->line_vector->nitems++;
726 e->line = line;
607ae575 727 e->pc = pc;
c906108c
SS
728}
729
730/* Needed in order to sort line tables from IBM xcoff files. Sigh! */
731
732static int
733compare_line_numbers (const void *ln1p, const void *ln2p)
734{
735 struct linetable_entry *ln1 = (struct linetable_entry *) ln1p;
736 struct linetable_entry *ln2 = (struct linetable_entry *) ln2p;
737
738 /* Note: this code does not assume that CORE_ADDRs can fit in ints.
739 Please keep it that way. */
740 if (ln1->pc < ln2->pc)
741 return -1;
742
743 if (ln1->pc > ln2->pc)
744 return 1;
745
746 /* If pc equal, sort by line. I'm not sure whether this is optimum
747 behavior (see comment at struct linetable in symtab.h). */
748 return ln1->line - ln2->line;
749}
750\f
4a64f543
MS
751/* Subroutine of end_symtab to simplify it. Look for a subfile that
752 matches the main source file's basename. If there is only one, and
753 if the main source file doesn't have any symbol or line number
754 information, then copy this file's symtab and line_vector to the
755 main source file's subfile and discard the other subfile. This can
756 happen because of a compiler bug or from the user playing games
757 with #line or from things like a distributed build system that
43f3e411
DE
758 manipulates the debug info. This can also happen from an innocent
759 symlink in the paths, we don't canonicalize paths here. */
4584e32e 760
4a2125f5
TT
761void
762buildsym_compunit::watch_main_source_file_lossage ()
4584e32e 763{
43f3e411 764 struct subfile *mainsub, *subfile;
4584e32e 765
43f3e411 766 /* Get the main source file. */
cbb09508 767 mainsub = m_main_subfile;
43f3e411 768
4a64f543 769 /* If the main source file doesn't have any line number or symbol
7bab9b58 770 info, look for an alias in another subfile. */
4584e32e 771
43f3e411
DE
772 if (mainsub->line_vector == NULL
773 && mainsub->symtab == NULL)
4584e32e 774 {
43f3e411 775 const char *mainbase = lbasename (mainsub->name);
4584e32e
DE
776 int nr_matches = 0;
777 struct subfile *prevsub;
778 struct subfile *mainsub_alias = NULL;
779 struct subfile *prev_mainsub_alias = NULL;
780
781 prevsub = NULL;
cbb09508 782 for (subfile = m_subfiles;
43f3e411 783 subfile != NULL;
4584e32e
DE
784 subfile = subfile->next)
785 {
43f3e411
DE
786 if (subfile == mainsub)
787 continue;
0ba1096a 788 if (filename_cmp (lbasename (subfile->name), mainbase) == 0)
4584e32e
DE
789 {
790 ++nr_matches;
791 mainsub_alias = subfile;
792 prev_mainsub_alias = prevsub;
793 }
794 prevsub = subfile;
795 }
796
797 if (nr_matches == 1)
798 {
43f3e411 799 gdb_assert (mainsub_alias != NULL && mainsub_alias != mainsub);
4584e32e
DE
800
801 /* Found a match for the main source file.
802 Copy its line_vector and symtab to the main subfile
803 and then discard it. */
804
43f3e411
DE
805 mainsub->line_vector = mainsub_alias->line_vector;
806 mainsub->line_vector_length = mainsub_alias->line_vector_length;
807 mainsub->symtab = mainsub_alias->symtab;
4584e32e
DE
808
809 if (prev_mainsub_alias == NULL)
cbb09508 810 m_subfiles = mainsub_alias->next;
4584e32e
DE
811 else
812 prev_mainsub_alias->next = mainsub_alias->next;
98387a29 813 xfree (mainsub_alias->name);
4584e32e
DE
814 xfree (mainsub_alias);
815 }
816 }
817}
818
4359dff1
JK
819/* Implementation of the first part of end_symtab. It allows modifying
820 STATIC_BLOCK before it gets finalized by end_symtab_from_static_block.
821 If the returned value is NULL there is no blockvector created for
822 this symtab (you still must call end_symtab_from_static_block).
c906108c 823
4359dff1
JK
824 END_ADDR is the same as for end_symtab: the address of the end of the
825 file's text.
c906108c 826
4359dff1 827 If EXPANDABLE is non-zero the STATIC_BLOCK dictionary is made
36586728
TT
828 expandable.
829
830 If REQUIRED is non-zero, then a symtab is created even if it does
831 not contain any symbols. */
6d30eef8 832
4359dff1 833struct block *
4a2125f5
TT
834buildsym_compunit::end_symtab_get_static_block (CORE_ADDR end_addr,
835 int expandable, int required)
c906108c 836{
c906108c
SS
837 /* Finish the lexical context of the last function in the file; pop
838 the context stack. */
839
4a2125f5 840 if (!m_context_stack.empty ())
c906108c 841 {
a60f3166 842 struct context_stack cstk = pop_context ();
4359dff1 843
c906108c 844 /* Make a block for the local symbols within. */
c233e9c6 845 finish_block (cstk.name, cstk.old_blocks, NULL,
a60f3166 846 cstk.start_addr, end_addr);
c906108c 847
4a2125f5 848 if (!m_context_stack.empty ())
c906108c
SS
849 {
850 /* This is said to happen with SCO. The old coffread.c
851 code simply emptied the context stack, so we do the
852 same. FIXME: Find out why it is happening. This is not
853 believed to happen in most cases (even for coffread.c);
854 it used to be an abort(). */
b98664d3 855 complaint (_("Context stack not empty in end_symtab"));
4a2125f5 856 m_context_stack.clear ();
c906108c
SS
857 }
858 }
859
860 /* Reordered executables may have out of order pending blocks; if
861 OBJF_REORDERED is true, then sort the pending blocks. */
6d30eef8 862
cbb09508 863 if ((m_objfile->flags & OBJF_REORDERED) && m_pending_blocks)
c906108c 864 {
07e7f39f 865 struct pending_block *pb;
c906108c 866
b05628f0 867 std::vector<block *> barray;
c906108c 868
4a2125f5 869 for (pb = m_pending_blocks; pb != NULL; pb = pb->next)
b05628f0 870 barray.push_back (pb->block);
07e7f39f 871
5033013f
UW
872 /* Sort blocks by start address in descending order. Blocks with the
873 same start address must remain in the original order to preserve
874 inline function caller/callee relationships. */
875 std::stable_sort (barray.begin (), barray.end (),
876 [] (const block *a, const block *b)
877 {
878 return BLOCK_START (a) > BLOCK_START (b);
879 });
07e7f39f 880
b05628f0 881 int i = 0;
4a2125f5 882 for (pb = m_pending_blocks; pb != NULL; pb = pb->next)
b05628f0 883 pb->block = barray[i++];
c906108c
SS
884 }
885
886 /* Cleanup any undefined types that have been left hanging around
887 (this needs to be done before the finish_blocks so that
888 file_symbols is still good).
c5aa993b 889
0a0edcd5 890 Both cleanup_undefined_stabs_types and finish_global_stabs are stabs
c906108c
SS
891 specific, but harmless for other symbol readers, since on gdb
892 startup or when finished reading stabs, the state is set so these
893 are no-ops. FIXME: Is this handled right in case of QUIT? Can
894 we make this cleaner? */
895
cbb09508
KS
896 cleanup_undefined_stabs_types (m_objfile);
897 finish_global_stabs (m_objfile);
c906108c 898
36586728 899 if (!required
4a2125f5
TT
900 && m_pending_blocks == NULL
901 && m_file_symbols == NULL
902 && m_global_symbols == NULL
903 && !m_have_line_numbers
904 && m_pending_macros == NULL
905 && m_global_using_directives == NULL)
c906108c 906 {
4359dff1
JK
907 /* Ignore symtabs that have no functions with real debugging info. */
908 return NULL;
909 }
910 else
911 {
912 /* Define the STATIC_BLOCK. */
e148f09d 913 return finish_block_internal (NULL, get_file_symbols (), NULL, NULL,
4a2125f5 914 m_last_source_start_addr,
2c99ee5c 915 end_addr, 0, expandable);
4359dff1
JK
916 }
917}
918
7bab9b58
DE
919/* Subroutine of end_symtab_from_static_block to simplify it.
920 Handle the "have blockvector" case.
921 See end_symtab_from_static_block for a description of the arguments. */
922
4a2125f5
TT
923struct compunit_symtab *
924buildsym_compunit::end_symtab_with_blockvector (struct block *static_block,
925 int section, int expandable)
4359dff1 926{
cbb09508 927 struct compunit_symtab *cu = m_compunit_symtab;
4359dff1
JK
928 struct blockvector *blockvector;
929 struct subfile *subfile;
7bab9b58 930 CORE_ADDR end_addr;
4359dff1 931
7bab9b58 932 gdb_assert (static_block != NULL);
cbb09508 933 gdb_assert (m_subfiles != NULL);
7bab9b58
DE
934
935 end_addr = BLOCK_END (static_block);
936
937 /* Create the GLOBAL_BLOCK and build the blockvector. */
e148f09d 938 finish_block_internal (NULL, get_global_symbols (), NULL, NULL,
4a2125f5 939 m_last_source_start_addr, end_addr,
7bab9b58 940 1, expandable);
43f3e411 941 blockvector = make_blockvector ();
c906108c 942
f56ce883
DE
943 /* Read the line table if it has to be read separately.
944 This is only used by xcoffread.c. */
cbb09508
KS
945 if (m_objfile->sf->sym_read_linetable != NULL)
946 m_objfile->sf->sym_read_linetable (m_objfile);
c906108c 947
4584e32e
DE
948 /* Handle the case where the debug info specifies a different path
949 for the main source file. It can cause us to lose track of its
950 line number information. */
951 watch_main_source_file_lossage ();
952
43f3e411
DE
953 /* Now create the symtab objects proper, if not already done,
954 one for each subfile. */
c906108c 955
cbb09508 956 for (subfile = m_subfiles;
43f3e411
DE
957 subfile != NULL;
958 subfile = subfile->next)
c906108c
SS
959 {
960 int linetablesize = 0;
c906108c 961
7bab9b58 962 if (subfile->line_vector)
c906108c 963 {
7bab9b58
DE
964 linetablesize = sizeof (struct linetable) +
965 subfile->line_vector->nitems * sizeof (struct linetable_entry);
966
967 /* Like the pending blocks, the line table may be
968 scrambled in reordered executables. Sort it if
969 OBJF_REORDERED is true. */
cbb09508 970 if (m_objfile->flags & OBJF_REORDERED)
7bab9b58
DE
971 qsort (subfile->line_vector->item,
972 subfile->line_vector->nitems,
973 sizeof (struct linetable_entry), compare_line_numbers);
974 }
9182c5bc 975
7bab9b58
DE
976 /* Allocate a symbol table if necessary. */
977 if (subfile->symtab == NULL)
43f3e411 978 subfile->symtab = allocate_symtab (cu, subfile->name);
5accd1a0 979 struct symtab *symtab = subfile->symtab;
9182c5bc 980
7bab9b58 981 /* Fill in its components. */
43f3e411 982
7bab9b58
DE
983 if (subfile->line_vector)
984 {
985 /* Reallocate the line table on the symbol obstack. */
8435453b 986 SYMTAB_LINETABLE (symtab) = (struct linetable *)
cbb09508 987 obstack_alloc (&m_objfile->objfile_obstack, linetablesize);
8435453b
DE
988 memcpy (SYMTAB_LINETABLE (symtab), subfile->line_vector,
989 linetablesize);
c906108c 990 }
24be086d 991 else
c906108c 992 {
8435453b 993 SYMTAB_LINETABLE (symtab) = NULL;
c906108c 994 }
c906108c 995
7bab9b58
DE
996 /* Use whatever language we have been using for this
997 subfile, not the one that was deduced in allocate_symtab
998 from the filename. We already did our own deducing when
999 we created the subfile, and we may have altered our
1000 opinion of what language it is from things we found in
1001 the symbols. */
1002 symtab->language = subfile->language;
43f3e411 1003 }
c906108c 1004
43f3e411
DE
1005 /* Make sure the symtab of main_subfile is the first in its list. */
1006 {
1007 struct symtab *main_symtab, *prev_symtab;
1008
cbb09508 1009 main_symtab = m_main_subfile->symtab;
43f3e411 1010 prev_symtab = NULL;
5accd1a0 1011 for (symtab *symtab : compunit_filetabs (cu))
43f3e411
DE
1012 {
1013 if (symtab == main_symtab)
1014 {
1015 if (prev_symtab != NULL)
1016 {
1017 prev_symtab->next = main_symtab->next;
1018 main_symtab->next = COMPUNIT_FILETABS (cu);
1019 COMPUNIT_FILETABS (cu) = main_symtab;
1020 }
1021 break;
1022 }
1023 prev_symtab = symtab;
1024 }
1025 gdb_assert (main_symtab == COMPUNIT_FILETABS (cu));
1026 }
84a146c9 1027
0ab9ce85 1028 /* Fill out the compunit symtab. */
84a146c9 1029
cbb09508 1030 if (m_comp_dir != NULL)
43f3e411
DE
1031 {
1032 /* Reallocate the dirname on the symbol obstack. */
cbb09508 1033 const char *comp_dir = m_comp_dir.get ();
43f3e411 1034 COMPUNIT_DIRNAME (cu)
cbb09508 1035 = (const char *) obstack_copy0 (&m_objfile->objfile_obstack,
905eb0e2 1036 comp_dir, strlen (comp_dir));
c906108c
SS
1037 }
1038
43f3e411 1039 /* Save the debug format string (if any) in the symtab. */
cbb09508 1040 COMPUNIT_DEBUGFORMAT (cu) = m_debugformat;
43f3e411
DE
1041
1042 /* Similarly for the producer. */
cbb09508 1043 COMPUNIT_PRODUCER (cu) = m_producer;
43f3e411
DE
1044
1045 COMPUNIT_BLOCKVECTOR (cu) = blockvector;
7bab9b58 1046 {
43f3e411 1047 struct block *b = BLOCKVECTOR_BLOCK (blockvector, GLOBAL_BLOCK);
cb1df416 1048
43f3e411 1049 set_block_compunit_symtab (b, cu);
7bab9b58 1050 }
cb1df416 1051
43f3e411
DE
1052 COMPUNIT_BLOCK_LINE_SECTION (cu) = section;
1053
4a2125f5 1054 COMPUNIT_MACRO_TABLE (cu) = release_macros ();
43f3e411 1055
7bab9b58
DE
1056 /* Default any symbols without a specified symtab to the primary symtab. */
1057 {
1058 int block_i;
1059
43f3e411 1060 /* The main source file's symtab. */
5accd1a0 1061 struct symtab *symtab = COMPUNIT_FILETABS (cu);
43f3e411 1062
7bab9b58
DE
1063 for (block_i = 0; block_i < BLOCKVECTOR_NBLOCKS (blockvector); block_i++)
1064 {
1065 struct block *block = BLOCKVECTOR_BLOCK (blockvector, block_i);
1066 struct symbol *sym;
b026f593 1067 struct mdict_iterator miter;
7bab9b58
DE
1068
1069 /* Inlined functions may have symbols not in the global or
1070 static symbol lists. */
1071 if (BLOCK_FUNCTION (block) != NULL)
08be3fe3
DE
1072 if (symbol_symtab (BLOCK_FUNCTION (block)) == NULL)
1073 symbol_set_symtab (BLOCK_FUNCTION (block), symtab);
7bab9b58
DE
1074
1075 /* Note that we only want to fix up symbols from the local
1076 blocks, not blocks coming from included symtabs. That is why
1077 we use ALL_DICT_SYMBOLS here and not ALL_BLOCK_SYMBOLS. */
b026f593 1078 ALL_DICT_SYMBOLS (BLOCK_MULTIDICT (block), miter, sym)
08be3fe3
DE
1079 if (symbol_symtab (sym) == NULL)
1080 symbol_set_symtab (sym, symtab);
7bab9b58
DE
1081 }
1082 }
edb3359d 1083
43f3e411 1084 add_compunit_symtab_to_objfile (cu);
43f3e411
DE
1085
1086 return cu;
7bab9b58
DE
1087}
1088
1089/* Implementation of the second part of end_symtab. Pass STATIC_BLOCK
1090 as value returned by end_symtab_get_static_block.
1091
1092 SECTION is the same as for end_symtab: the section number
1093 (in objfile->section_offsets) of the blockvector and linetable.
1094
1095 If EXPANDABLE is non-zero the GLOBAL_BLOCK dictionary is made
1096 expandable. */
1097
43f3e411 1098struct compunit_symtab *
4a2125f5
TT
1099buildsym_compunit::end_symtab_from_static_block (struct block *static_block,
1100 int section, int expandable)
7bab9b58 1101{
43f3e411 1102 struct compunit_symtab *cu;
7bab9b58
DE
1103
1104 if (static_block == NULL)
1105 {
0ab9ce85
DE
1106 /* Handle the "no blockvector" case.
1107 When this happens there is nothing to record, so there's nothing
1108 to do: memory will be freed up later.
1109
1110 Note: We won't be adding a compunit to the objfile's list of
1111 compunits, so there's nothing to unchain. However, since each symtab
1112 is added to the objfile's obstack we can't free that space.
1113 We could do better, but this is believed to be a sufficiently rare
1114 event. */
43f3e411 1115 cu = NULL;
7bab9b58
DE
1116 }
1117 else
43f3e411 1118 cu = end_symtab_with_blockvector (static_block, section, expandable);
cb1df416 1119
43f3e411 1120 return cu;
6d30eef8
DE
1121}
1122
4359dff1
JK
1123/* Finish the symbol definitions for one main source file, close off
1124 all the lexical contexts for that file (creating struct block's for
1125 them), then make the struct symtab for that file and put it in the
1126 list of all such.
1127
1128 END_ADDR is the address of the end of the file's text. SECTION is
1129 the section number (in objfile->section_offsets) of the blockvector
1130 and linetable.
1131
1132 Note that it is possible for end_symtab() to return NULL. In
1133 particular, for the DWARF case at least, it will return NULL when
1134 it finds a compilation unit that has exactly one DIE, a
1135 TAG_compile_unit DIE. This can happen when we link in an object
1136 file that was compiled from an empty source file. Returning NULL
1137 is probably not the correct thing to do, because then gdb will
1138 never know about this empty file (FIXME).
1139
1140 If you need to modify STATIC_BLOCK before it is finalized you should
1141 call end_symtab_get_static_block and end_symtab_from_static_block
1142 yourself. */
6d30eef8 1143
43f3e411 1144struct compunit_symtab *
4a2125f5 1145buildsym_compunit::end_symtab (CORE_ADDR end_addr, int section)
6d30eef8 1146{
4359dff1
JK
1147 struct block *static_block;
1148
4d663531
DE
1149 static_block = end_symtab_get_static_block (end_addr, 0, 0);
1150 return end_symtab_from_static_block (static_block, section, 0);
6d30eef8
DE
1151}
1152
4359dff1 1153/* Same as end_symtab except create a symtab that can be later added to. */
6d30eef8 1154
43f3e411 1155struct compunit_symtab *
4a2125f5 1156buildsym_compunit::end_expandable_symtab (CORE_ADDR end_addr, int section)
6d30eef8 1157{
4359dff1
JK
1158 struct block *static_block;
1159
4d663531
DE
1160 static_block = end_symtab_get_static_block (end_addr, 1, 0);
1161 return end_symtab_from_static_block (static_block, section, 1);
6d30eef8
DE
1162}
1163
1164/* Subroutine of augment_type_symtab to simplify it.
43f3e411
DE
1165 Attach the main source file's symtab to all symbols in PENDING_LIST that
1166 don't have one. */
6d30eef8
DE
1167
1168static void
43f3e411
DE
1169set_missing_symtab (struct pending *pending_list,
1170 struct compunit_symtab *cu)
6d30eef8
DE
1171{
1172 struct pending *pending;
1173 int i;
1174
1175 for (pending = pending_list; pending != NULL; pending = pending->next)
801e3a5b 1176 {
6d30eef8
DE
1177 for (i = 0; i < pending->nsyms; ++i)
1178 {
08be3fe3
DE
1179 if (symbol_symtab (pending->symbol[i]) == NULL)
1180 symbol_set_symtab (pending->symbol[i], COMPUNIT_FILETABS (cu));
6d30eef8 1181 }
801e3a5b 1182 }
6d30eef8 1183}
c906108c 1184
6d30eef8
DE
1185/* Same as end_symtab, but for the case where we're adding more symbols
1186 to an existing symtab that is known to contain only type information.
1187 This is the case for DWARF4 Type Units. */
1188
1189void
4a2125f5 1190buildsym_compunit::augment_type_symtab ()
6d30eef8 1191{
cbb09508 1192 struct compunit_symtab *cust = m_compunit_symtab;
43f3e411 1193 const struct blockvector *blockvector = COMPUNIT_BLOCKVECTOR (cust);
6d30eef8 1194
4a2125f5 1195 if (!m_context_stack.empty ())
a60f3166 1196 complaint (_("Context stack not empty in augment_type_symtab"));
4a2125f5 1197 if (m_pending_blocks != NULL)
b98664d3 1198 complaint (_("Blocks in a type symtab"));
4a2125f5 1199 if (m_pending_macros != NULL)
b98664d3 1200 complaint (_("Macro in a type symtab"));
4a2125f5 1201 if (m_have_line_numbers)
b98664d3 1202 complaint (_("Line numbers recorded in a type symtab"));
6d30eef8 1203
4a2125f5 1204 if (m_file_symbols != NULL)
6d30eef8
DE
1205 {
1206 struct block *block = BLOCKVECTOR_BLOCK (blockvector, STATIC_BLOCK);
1207
1208 /* First mark any symbols without a specified symtab as belonging
1209 to the primary symtab. */
4a2125f5 1210 set_missing_symtab (m_file_symbols, cust);
6d30eef8 1211
b026f593 1212 mdict_add_pending (BLOCK_MULTIDICT (block), m_file_symbols);
6d30eef8
DE
1213 }
1214
4a2125f5 1215 if (m_global_symbols != NULL)
6d30eef8
DE
1216 {
1217 struct block *block = BLOCKVECTOR_BLOCK (blockvector, GLOBAL_BLOCK);
1218
1219 /* First mark any symbols without a specified symtab as belonging
1220 to the primary symtab. */
4a2125f5 1221 set_missing_symtab (m_global_symbols, cust);
6d30eef8 1222
b026f593 1223 mdict_add_pending (BLOCK_MULTIDICT (block),
4a2125f5 1224 m_global_symbols);
6d30eef8 1225 }
c906108c
SS
1226}
1227
1228/* Push a context block. Args are an identifying nesting level
1229 (checkable when you pop it), and the starting PC address of this
1230 context. */
1231
1232struct context_stack *
4a2125f5 1233buildsym_compunit::push_context (int desc, CORE_ADDR valu)
c906108c 1234{
4a2125f5
TT
1235 m_context_stack.emplace_back ();
1236 struct context_stack *newobj = &m_context_stack.back ();
c906108c 1237
fe978cb0 1238 newobj->depth = desc;
4a2125f5
TT
1239 newobj->locals = m_local_symbols;
1240 newobj->old_blocks = m_pending_blocks;
fe978cb0 1241 newobj->start_addr = valu;
4a2125f5 1242 newobj->local_using_directives = m_local_using_directives;
fe978cb0 1243 newobj->name = NULL;
c906108c 1244
4a2125f5
TT
1245 m_local_symbols = NULL;
1246 m_local_using_directives = NULL;
c906108c 1247
fe978cb0 1248 return newobj;
c906108c 1249}
0c5e171a 1250
a672ef13 1251/* Pop a context block. Returns the address of the context block just
4a64f543 1252 popped. */
a672ef13 1253
a60f3166 1254struct context_stack
4a2125f5 1255buildsym_compunit::pop_context ()
0c5e171a 1256{
4a2125f5
TT
1257 gdb_assert (!m_context_stack.empty ());
1258 struct context_stack result = m_context_stack.back ();
1259 m_context_stack.pop_back ();
a60f3166 1260 return result;
0c5e171a 1261}