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