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