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