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