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