1 /* Support routines for building symbol tables in GDB's internal format.
2 Copyright (C) 1986-2018 Free Software Foundation, Inc.
4 This file is part of GDB.
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
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
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.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 /* This module provides subroutines used for creating and adding to
20 the symbol table. These routines are called from various symbol-
21 file-reading routines.
23 Routines to support specific debugging information formats (stabs,
24 DWARF, etc) belong somewhere else.
26 The basic way this module is used is as follows:
28 scoped_free_pendings free_pending;
29 cust = start_symtab (...);
30 ... read debug info ...
31 cust = end_symtab (...);
33 The compunit symtab pointer ("cust") is returned from both start_symtab
34 and end_symtab to simplify the debug info readers.
36 There are minor variations on this, e.g., dwarf2read.c splits end_symtab
37 into two calls: end_symtab_get_static_block, end_symtab_from_static_block,
38 but all debug info readers follow this basic flow.
40 Reading DWARF Type Units is another variation:
42 scoped_free_pendings free_pending;
43 cust = start_symtab (...);
44 ... read debug info ...
45 cust = end_expandable_symtab (...);
47 And then reading subsequent Type Units within the containing "Comp Unit"
48 will use a second flow:
50 scoped_free_pendings free_pending;
51 cust = restart_symtab (...);
52 ... read debug info ...
53 cust = augment_type_symtab (...);
55 dbxread.c and xcoffread.c use another variation:
57 scoped_free_pendings free_pending;
58 cust = start_symtab (...);
59 ... read debug info ...
60 cust = end_symtab (...);
61 ... start_symtab + read + end_symtab repeated ...
67 #include "gdb_obstack.h"
72 #include "complaints.h"
73 #include "expression.h" /* For "enum exp_opcode" used by... */
74 #include "filenames.h" /* For DOSish file names. */
76 #include "demangle.h" /* Needed by SYMBOL_INIT_DEMANGLED_NAME. */
78 #include "cp-support.h"
79 #include "dictionary.h"
83 /* For cleanup_undefined_stabs_types and finish_global_stabs (somewhat
84 questionable--see comment where we call them). */
86 #include "stabsread.h"
88 /* Buildsym's counterpart to struct compunit_symtab. */
90 struct buildsym_compunit
92 /* Start recording information about a primary source file (IOW, not an
93 included source file).
94 COMP_DIR is the directory in which the compilation unit was compiled
95 (or NULL if not known). */
97 buildsym_compunit (struct objfile *objfile_, const char *name,
98 const char *comp_dir_, enum language language_,
100 : objfile (objfile_),
101 m_last_source_file (name == nullptr ? nullptr : xstrdup (name)),
102 comp_dir (comp_dir_ == nullptr ? nullptr : xstrdup (comp_dir_)),
103 language (language_),
104 m_last_source_start_addr (last_addr)
108 ~buildsym_compunit ()
110 struct subfile *subfile, *nextsub;
112 if (m_pending_macros != nullptr)
113 free_macro_table (m_pending_macros);
115 for (subfile = subfiles;
119 nextsub = subfile->next;
120 xfree (subfile->name);
121 xfree (subfile->line_vector);
125 struct pending *next, *next1;
127 for (next = m_file_symbols; next != NULL; next = next1)
130 xfree ((void *) next);
133 for (next = m_global_symbols; next != NULL; next = next1)
136 xfree ((void *) next);
140 void set_last_source_file (const char *name)
142 char *new_name = name == NULL ? NULL : xstrdup (name);
143 m_last_source_file.reset (new_name);
146 struct macro_table *get_macro_table ()
148 if (m_pending_macros == nullptr)
149 m_pending_macros = new_macro_table (&objfile->per_bfd->storage_obstack,
150 objfile->per_bfd->macro_cache,
152 return m_pending_macros;
155 struct macro_table *release_macros ()
157 struct macro_table *result = m_pending_macros;
158 m_pending_macros = nullptr;
162 /* This function is called to discard any pending blocks. */
164 void free_pending_blocks ()
166 m_pending_block_obstack.clear ();
167 m_pending_blocks = nullptr;
170 /* The objfile we're reading debug info from. */
171 struct objfile *objfile;
173 /* List of subfiles (source files).
174 Files are added to the front of the list.
175 This is important mostly for the language determination hacks we use,
176 which iterate over previously added files. */
177 struct subfile *subfiles = nullptr;
179 /* The subfile of the main source file. */
180 struct subfile *main_subfile = nullptr;
182 /* Name of source file whose symbol data we are now processing. This
183 comes from a symbol of type N_SO for stabs. For DWARF it comes
184 from the DW_AT_name attribute of a DW_TAG_compile_unit DIE. */
185 gdb::unique_xmalloc_ptr<char> m_last_source_file;
187 /* E.g., DW_AT_comp_dir if DWARF. Space for this is malloc'd. */
188 gdb::unique_xmalloc_ptr<char> comp_dir;
190 /* Space for this is not malloc'd, and is assumed to have at least
191 the same lifetime as objfile. */
192 const char *producer = nullptr;
194 /* Space for this is not malloc'd, and is assumed to have at least
195 the same lifetime as objfile. */
196 const char *debugformat = nullptr;
198 /* The compunit we are building. */
199 struct compunit_symtab *compunit_symtab = nullptr;
201 /* Language of this compunit_symtab. */
202 enum language language;
204 /* The macro table for the compilation unit whose symbols we're
205 currently reading. */
206 struct macro_table *m_pending_macros = nullptr;
208 /* True if symtab has line number info. This prevents an otherwise
209 empty symtab from being tossed. */
210 bool m_have_line_numbers = false;
212 /* Core address of start of text of current source file. This too
213 comes from the N_SO symbol. For Dwarf it typically comes from the
214 DW_AT_low_pc attribute of a DW_TAG_compile_unit DIE. */
215 CORE_ADDR m_last_source_start_addr;
217 /* Stack of subfile names. */
218 std::vector<const char *> m_subfile_stack;
220 /* The "using" directives local to lexical context. */
221 struct using_direct *m_local_using_directives = nullptr;
223 /* Global "using" directives. */
224 struct using_direct *m_global_using_directives = nullptr;
226 /* The stack of contexts that are pushed by push_context and popped
228 std::vector<struct context_stack> m_context_stack;
230 struct subfile *m_current_subfile = nullptr;
232 /* The mutable address map for the compilation unit whose symbols
233 we're currently reading. The symtabs' shared blockvector will
234 point to a fixed copy of this. */
235 struct addrmap *m_pending_addrmap = nullptr;
237 /* The obstack on which we allocate pending_addrmap.
238 If pending_addrmap is NULL, this is uninitialized; otherwise, it is
239 initialized (and holds pending_addrmap). */
240 auto_obstack m_pending_addrmap_obstack;
242 /* True if we recorded any ranges in the addrmap that are different
243 from those in the blockvector already. We set this to false when
244 we start processing a symfile, and if it's still false at the
245 end, then we just toss the addrmap. */
246 bool m_pending_addrmap_interesting = false;
248 /* An obstack used for allocating pending blocks. */
249 auto_obstack m_pending_block_obstack;
251 /* Pointer to the head of a linked list of symbol blocks which have
252 already been finalized (lexical contexts already closed) and which
253 are just waiting to be built into a blockvector when finalizing the
254 associated symtab. */
255 struct pending_block *m_pending_blocks = nullptr;
257 /* Pending static symbols and types at the top level. */
258 struct pending *m_file_symbols = nullptr;
260 /* Pending global functions and variables. */
261 struct pending *m_global_symbols = nullptr;
263 /* Pending symbols that are local to the lexical context. */
264 struct pending *m_local_symbols = nullptr;
267 /* The work-in-progress of the compunit we are building.
268 This is created first, before any subfiles by start_symtab. */
270 static struct buildsym_compunit *buildsym_compunit;
272 /* List of blocks already made (lexical contexts already closed).
273 This is used at the end to make the blockvector. */
277 struct pending_block *next;
281 static void free_buildsym_compunit (void);
283 static int compare_line_numbers (const void *ln1p, const void *ln2p);
285 static void record_pending_block (struct objfile *objfile,
287 struct pending_block *opblock);
289 /* Initial sizes of data structures. These are realloc'd larger if
290 needed, and realloc'd down to the size actually used, when
293 #define INITIAL_LINE_VECTOR_LENGTH 1000
296 /* Maintain the lists of symbols and blocks. */
298 /* Add a symbol to one of the lists of symbols. */
301 add_symbol_to_list (struct symbol *symbol, struct pending **listhead)
303 struct pending *link;
305 /* If this is an alias for another symbol, don't add it. */
306 if (symbol->ginfo.name && symbol->ginfo.name[0] == '#')
309 /* We keep PENDINGSIZE symbols in each link of the list. If we
310 don't have a link with room in it, add a new link. */
311 if (*listhead == NULL || (*listhead)->nsyms == PENDINGSIZE)
313 link = XNEW (struct pending);
314 link->next = *listhead;
319 (*listhead)->symbol[(*listhead)->nsyms++] = symbol;
322 /* Find a symbol named NAME on a LIST. NAME need not be
323 '\0'-terminated; LENGTH is the length of the name. */
326 find_symbol_in_list (struct pending *list, char *name, int length)
333 for (j = list->nsyms; --j >= 0;)
335 pp = SYMBOL_LINKAGE_NAME (list->symbol[j]);
336 if (*pp == *name && strncmp (pp, name, length) == 0
337 && pp[length] == '\0')
339 return (list->symbol[j]);
347 /* At end of reading syms, or in case of quit, ensure everything
348 associated with building symtabs is freed.
350 N.B. This is *not* intended to be used when building psymtabs. Some debug
351 info readers call this anyway, which is harmless if confusing. */
353 scoped_free_pendings::~scoped_free_pendings ()
355 free_buildsym_compunit ();
358 /* Take one of the lists of symbols and make a block from it. Keep
359 the order the symbols have in the list (reversed from the input
360 file). Put the block on the list of pending blocks. */
362 static struct block *
363 finish_block_internal (struct symbol *symbol,
364 struct pending **listhead,
365 struct pending_block *old_blocks,
366 const struct dynamic_prop *static_link,
367 CORE_ADDR start, CORE_ADDR end,
368 int is_global, int expandable)
370 struct objfile *objfile = buildsym_compunit->objfile;
371 struct gdbarch *gdbarch = get_objfile_arch (objfile);
372 struct pending *next, *next1;
374 struct pending_block *pblock;
375 struct pending_block *opblock;
378 ? allocate_global_block (&objfile->objfile_obstack)
379 : allocate_block (&objfile->objfile_obstack));
384 = dict_create_linear (&objfile->objfile_obstack,
385 buildsym_compunit->language, *listhead);
392 = dict_create_hashed_expandable (buildsym_compunit->language);
393 dict_add_pending (BLOCK_DICT (block), *listhead);
398 dict_create_hashed (&objfile->objfile_obstack,
399 buildsym_compunit->language, *listhead);
403 BLOCK_START (block) = start;
404 BLOCK_END (block) = end;
406 /* Put the block in as the value of the symbol that names it. */
410 struct type *ftype = SYMBOL_TYPE (symbol);
411 struct dict_iterator iter;
412 SYMBOL_BLOCK_VALUE (symbol) = block;
413 BLOCK_FUNCTION (block) = symbol;
415 if (TYPE_NFIELDS (ftype) <= 0)
417 /* No parameter type information is recorded with the
418 function's type. Set that from the type of the
419 parameter symbols. */
420 int nparams = 0, iparams;
423 /* Here we want to directly access the dictionary, because
424 we haven't fully initialized the block yet. */
425 ALL_DICT_SYMBOLS (BLOCK_DICT (block), iter, sym)
427 if (SYMBOL_IS_ARGUMENT (sym))
432 TYPE_NFIELDS (ftype) = nparams;
433 TYPE_FIELDS (ftype) = (struct field *)
434 TYPE_ALLOC (ftype, nparams * sizeof (struct field));
437 /* Here we want to directly access the dictionary, because
438 we haven't fully initialized the block yet. */
439 ALL_DICT_SYMBOLS (BLOCK_DICT (block), iter, sym)
441 if (iparams == nparams)
444 if (SYMBOL_IS_ARGUMENT (sym))
446 TYPE_FIELD_TYPE (ftype, iparams) = SYMBOL_TYPE (sym);
447 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0;
456 BLOCK_FUNCTION (block) = NULL;
459 if (static_link != NULL)
460 objfile_register_static_link (objfile, block, static_link);
462 /* Now free the links of the list, and empty the list. */
464 for (next = *listhead; next; next = next1)
471 /* Check to be sure that the blocks have an end address that is
472 greater than starting address. */
474 if (BLOCK_END (block) < BLOCK_START (block))
478 complaint (_("block end address less than block "
479 "start address in %s (patched it)"),
480 SYMBOL_PRINT_NAME (symbol));
484 complaint (_("block end address %s less than block "
485 "start address %s (patched it)"),
486 paddress (gdbarch, BLOCK_END (block)),
487 paddress (gdbarch, BLOCK_START (block)));
489 /* Better than nothing. */
490 BLOCK_END (block) = BLOCK_START (block);
493 /* Install this block as the superblock of all blocks made since the
494 start of this scope that don't have superblocks yet. */
497 for (pblock = buildsym_compunit->m_pending_blocks;
498 pblock && pblock != old_blocks;
499 pblock = pblock->next)
501 if (BLOCK_SUPERBLOCK (pblock->block) == NULL)
503 /* Check to be sure the blocks are nested as we receive
504 them. If the compiler/assembler/linker work, this just
505 burns a small amount of time.
507 Skip blocks which correspond to a function; they're not
508 physically nested inside this other blocks, only
510 if (BLOCK_FUNCTION (pblock->block) == NULL
511 && (BLOCK_START (pblock->block) < BLOCK_START (block)
512 || BLOCK_END (pblock->block) > BLOCK_END (block)))
516 complaint (_("inner block not inside outer block in %s"),
517 SYMBOL_PRINT_NAME (symbol));
521 complaint (_("inner block (%s-%s) not "
522 "inside outer block (%s-%s)"),
523 paddress (gdbarch, BLOCK_START (pblock->block)),
524 paddress (gdbarch, BLOCK_END (pblock->block)),
525 paddress (gdbarch, BLOCK_START (block)),
526 paddress (gdbarch, BLOCK_END (block)));
528 if (BLOCK_START (pblock->block) < BLOCK_START (block))
529 BLOCK_START (pblock->block) = BLOCK_START (block);
530 if (BLOCK_END (pblock->block) > BLOCK_END (block))
531 BLOCK_END (pblock->block) = BLOCK_END (block);
533 BLOCK_SUPERBLOCK (pblock->block) = block;
538 block_set_using (block,
540 ? buildsym_compunit->m_global_using_directives
541 : buildsym_compunit->m_local_using_directives),
542 &objfile->objfile_obstack);
544 buildsym_compunit->m_global_using_directives = NULL;
546 buildsym_compunit->m_local_using_directives = NULL;
548 record_pending_block (objfile, block, opblock);
554 finish_block (struct symbol *symbol,
555 struct pending_block *old_blocks,
556 const struct dynamic_prop *static_link,
557 CORE_ADDR start, CORE_ADDR end)
559 return finish_block_internal (symbol, &buildsym_compunit->m_local_symbols,
560 old_blocks, static_link,
564 /* Record BLOCK on the list of all blocks in the file. Put it after
565 OPBLOCK, or at the beginning if opblock is NULL. This puts the
566 block in the list after all its subblocks.
568 Allocate the pending block struct in the objfile_obstack to save
569 time. This wastes a little space. FIXME: Is it worth it? */
572 record_pending_block (struct objfile *objfile, struct block *block,
573 struct pending_block *opblock)
575 struct pending_block *pblock;
577 pblock = XOBNEW (&buildsym_compunit->m_pending_block_obstack,
578 struct pending_block);
579 pblock->block = block;
582 pblock->next = opblock->next;
583 opblock->next = pblock;
587 pblock->next = buildsym_compunit->m_pending_blocks;
588 buildsym_compunit->m_pending_blocks = pblock;
593 /* Record that the range of addresses from START to END_INCLUSIVE
594 (inclusive, like it says) belongs to BLOCK. BLOCK's start and end
595 addresses must be set already. You must apply this function to all
596 BLOCK's children before applying it to BLOCK.
598 If a call to this function complicates the picture beyond that
599 already provided by BLOCK_START and BLOCK_END, then we create an
600 address map for the block. */
602 record_block_range (struct block *block,
603 CORE_ADDR start, CORE_ADDR end_inclusive)
605 /* If this is any different from the range recorded in the block's
606 own BLOCK_START and BLOCK_END, then note that the address map has
607 become interesting. Note that even if this block doesn't have
608 any "interesting" ranges, some later block might, so we still
609 need to record this block in the addrmap. */
610 if (start != BLOCK_START (block)
611 || end_inclusive + 1 != BLOCK_END (block))
612 buildsym_compunit->m_pending_addrmap_interesting = true;
614 if (buildsym_compunit->m_pending_addrmap == nullptr)
615 buildsym_compunit->m_pending_addrmap
616 = addrmap_create_mutable (&buildsym_compunit->m_pending_addrmap_obstack);
618 addrmap_set_empty (buildsym_compunit->m_pending_addrmap,
619 start, end_inclusive, block);
622 static struct blockvector *
623 make_blockvector (void)
625 struct objfile *objfile = buildsym_compunit->objfile;
626 struct pending_block *next;
627 struct blockvector *blockvector;
630 /* Count the length of the list of blocks. */
632 for (next = buildsym_compunit->m_pending_blocks, i = 0;
634 next = next->next, i++)
638 blockvector = (struct blockvector *)
639 obstack_alloc (&objfile->objfile_obstack,
640 (sizeof (struct blockvector)
641 + (i - 1) * sizeof (struct block *)));
643 /* Copy the blocks into the blockvector. This is done in reverse
644 order, which happens to put the blocks into the proper order
645 (ascending starting address). finish_block has hair to insert
646 each block into the list after its subblocks in order to make
647 sure this is true. */
649 BLOCKVECTOR_NBLOCKS (blockvector) = i;
650 for (next = buildsym_compunit->m_pending_blocks; next; next = next->next)
652 BLOCKVECTOR_BLOCK (blockvector, --i) = next->block;
655 buildsym_compunit->free_pending_blocks ();
657 /* If we needed an address map for this symtab, record it in the
659 if (buildsym_compunit->m_pending_addrmap != nullptr
660 && buildsym_compunit->m_pending_addrmap_interesting)
661 BLOCKVECTOR_MAP (blockvector)
662 = addrmap_create_fixed (buildsym_compunit->m_pending_addrmap,
663 &objfile->objfile_obstack);
665 BLOCKVECTOR_MAP (blockvector) = 0;
667 /* Some compilers output blocks in the wrong order, but we depend on
668 their being in the right order so we can binary search. Check the
669 order and moan about it.
670 Note: Remember that the first two blocks are the global and static
671 blocks. We could special case that fact and begin checking at block 2.
672 To avoid making that assumption we do not. */
673 if (BLOCKVECTOR_NBLOCKS (blockvector) > 1)
675 for (i = 1; i < BLOCKVECTOR_NBLOCKS (blockvector); i++)
677 if (BLOCK_START (BLOCKVECTOR_BLOCK (blockvector, i - 1))
678 > BLOCK_START (BLOCKVECTOR_BLOCK (blockvector, i)))
681 = BLOCK_START (BLOCKVECTOR_BLOCK (blockvector, i));
683 complaint (_("block at %s out of order"),
684 hex_string ((LONGEST) start));
689 return (blockvector);
692 /* Start recording information about source code that came from an
693 included (or otherwise merged-in) source file with a different
694 name. NAME is the name of the file (cannot be NULL). */
697 start_subfile (const char *name)
699 const char *subfile_dirname;
700 struct subfile *subfile;
702 gdb_assert (buildsym_compunit != NULL);
704 subfile_dirname = buildsym_compunit->comp_dir.get ();
706 /* See if this subfile is already registered. */
708 for (subfile = buildsym_compunit->subfiles; subfile; subfile = subfile->next)
712 /* If NAME is an absolute path, and this subfile is not, then
713 attempt to create an absolute path to compare. */
714 if (IS_ABSOLUTE_PATH (name)
715 && !IS_ABSOLUTE_PATH (subfile->name)
716 && subfile_dirname != NULL)
717 subfile_name = concat (subfile_dirname, SLASH_STRING,
718 subfile->name, (char *) NULL);
720 subfile_name = subfile->name;
722 if (FILENAME_CMP (subfile_name, name) == 0)
724 buildsym_compunit->m_current_subfile = subfile;
725 if (subfile_name != subfile->name)
726 xfree (subfile_name);
729 if (subfile_name != subfile->name)
730 xfree (subfile_name);
733 /* This subfile is not known. Add an entry for it. */
735 subfile = XNEW (struct subfile);
736 memset (subfile, 0, sizeof (struct subfile));
737 subfile->buildsym_compunit = buildsym_compunit;
739 subfile->next = buildsym_compunit->subfiles;
740 buildsym_compunit->subfiles = subfile;
742 buildsym_compunit->m_current_subfile = subfile;
744 subfile->name = xstrdup (name);
746 /* Initialize line-number recording for this subfile. */
747 subfile->line_vector = NULL;
749 /* Default the source language to whatever can be deduced from the
750 filename. If nothing can be deduced (such as for a C/C++ include
751 file with a ".h" extension), then inherit whatever language the
752 previous subfile had. This kludgery is necessary because there
753 is no standard way in some object formats to record the source
754 language. Also, when symtabs are allocated we try to deduce a
755 language then as well, but it is too late for us to use that
756 information while reading symbols, since symtabs aren't allocated
757 until after all the symbols have been processed for a given
760 subfile->language = deduce_language_from_filename (subfile->name);
761 if (subfile->language == language_unknown
762 && subfile->next != NULL)
764 subfile->language = subfile->next->language;
767 /* If the filename of this subfile ends in .C, then change the
768 language of any pending subfiles from C to C++. We also accept
769 any other C++ suffixes accepted by deduce_language_from_filename. */
770 /* Likewise for f2c. */
775 enum language sublang = deduce_language_from_filename (subfile->name);
777 if (sublang == language_cplus || sublang == language_fortran)
778 for (s = buildsym_compunit->subfiles; s != NULL; s = s->next)
779 if (s->language == language_c)
780 s->language = sublang;
783 /* And patch up this file if necessary. */
784 if (subfile->language == language_c
785 && subfile->next != NULL
786 && (subfile->next->language == language_cplus
787 || subfile->next->language == language_fortran))
789 subfile->language = subfile->next->language;
793 /* Delete the buildsym compunit. */
796 free_buildsym_compunit (void)
798 if (buildsym_compunit == NULL)
800 delete buildsym_compunit;
801 buildsym_compunit = NULL;
804 /* For stabs readers, the first N_SO symbol is assumed to be the
805 source file name, and the subfile struct is initialized using that
806 assumption. If another N_SO symbol is later seen, immediately
807 following the first one, then the first one is assumed to be the
808 directory name and the second one is really the source file name.
810 So we have to patch up the subfile struct by moving the old name
811 value to dirname and remembering the new name. Some sanity
812 checking is performed to ensure that the state of the subfile
813 struct is reasonable and that the old name we are assuming to be a
814 directory name actually is (by checking for a trailing '/'). */
817 patch_subfile_names (struct subfile *subfile, const char *name)
820 && buildsym_compunit->comp_dir == NULL
821 && subfile->name != NULL
822 && IS_DIR_SEPARATOR (subfile->name[strlen (subfile->name) - 1]))
824 buildsym_compunit->comp_dir.reset (subfile->name);
825 subfile->name = xstrdup (name);
826 set_last_source_file (name);
828 /* Default the source language to whatever can be deduced from
829 the filename. If nothing can be deduced (such as for a C/C++
830 include file with a ".h" extension), then inherit whatever
831 language the previous subfile had. This kludgery is
832 necessary because there is no standard way in some object
833 formats to record the source language. Also, when symtabs
834 are allocated we try to deduce a language then as well, but
835 it is too late for us to use that information while reading
836 symbols, since symtabs aren't allocated until after all the
837 symbols have been processed for a given source file. */
839 subfile->language = deduce_language_from_filename (subfile->name);
840 if (subfile->language == language_unknown
841 && subfile->next != NULL)
843 subfile->language = subfile->next->language;
848 /* Handle the N_BINCL and N_EINCL symbol types that act like N_SOL for
849 switching source files (different subfiles, as we call them) within
850 one object file, but using a stack rather than in an arbitrary
856 gdb_assert (buildsym_compunit != nullptr);
857 gdb_assert (buildsym_compunit->m_current_subfile != NULL);
858 gdb_assert (buildsym_compunit->m_current_subfile->name != NULL);
859 buildsym_compunit->m_subfile_stack.push_back
860 (buildsym_compunit->m_current_subfile->name);
866 gdb_assert (buildsym_compunit != nullptr);
867 gdb_assert (!buildsym_compunit->m_subfile_stack.empty ());
868 const char *name = buildsym_compunit->m_subfile_stack.back ();
869 buildsym_compunit->m_subfile_stack.pop_back ();
873 /* Add a linetable entry for line number LINE and address PC to the
874 line vector for SUBFILE. */
877 record_line (struct subfile *subfile, int line, CORE_ADDR pc)
879 struct linetable_entry *e;
881 /* Ignore the dummy line number in libg.o */
887 /* Make sure line vector exists and is big enough. */
888 if (!subfile->line_vector)
890 subfile->line_vector_length = INITIAL_LINE_VECTOR_LENGTH;
891 subfile->line_vector = (struct linetable *)
892 xmalloc (sizeof (struct linetable)
893 + subfile->line_vector_length * sizeof (struct linetable_entry));
894 subfile->line_vector->nitems = 0;
895 buildsym_compunit->m_have_line_numbers = true;
898 if (subfile->line_vector->nitems + 1 >= subfile->line_vector_length)
900 subfile->line_vector_length *= 2;
901 subfile->line_vector = (struct linetable *)
902 xrealloc ((char *) subfile->line_vector,
903 (sizeof (struct linetable)
904 + (subfile->line_vector_length
905 * sizeof (struct linetable_entry))));
908 /* Normally, we treat lines as unsorted. But the end of sequence
909 marker is special. We sort line markers at the same PC by line
910 number, so end of sequence markers (which have line == 0) appear
911 first. This is right if the marker ends the previous function,
912 and there is no padding before the next function. But it is
913 wrong if the previous line was empty and we are now marking a
914 switch to a different subfile. We must leave the end of sequence
915 marker at the end of this group of lines, not sort the empty line
916 to after the marker. The easiest way to accomplish this is to
917 delete any empty lines from our table, if they are followed by
918 end of sequence markers. All we lose is the ability to set
919 breakpoints at some lines which contain no instructions
921 if (line == 0 && subfile->line_vector->nitems > 0)
923 e = subfile->line_vector->item + subfile->line_vector->nitems - 1;
924 while (subfile->line_vector->nitems > 0 && e->pc == pc)
927 subfile->line_vector->nitems--;
931 e = subfile->line_vector->item + subfile->line_vector->nitems++;
936 /* Needed in order to sort line tables from IBM xcoff files. Sigh! */
939 compare_line_numbers (const void *ln1p, const void *ln2p)
941 struct linetable_entry *ln1 = (struct linetable_entry *) ln1p;
942 struct linetable_entry *ln2 = (struct linetable_entry *) ln2p;
944 /* Note: this code does not assume that CORE_ADDRs can fit in ints.
945 Please keep it that way. */
946 if (ln1->pc < ln2->pc)
949 if (ln1->pc > ln2->pc)
952 /* If pc equal, sort by line. I'm not sure whether this is optimum
953 behavior (see comment at struct linetable in symtab.h). */
954 return ln1->line - ln2->line;
957 /* See buildsym.h. */
959 struct compunit_symtab *
960 buildsym_compunit_symtab (void)
962 gdb_assert (buildsym_compunit != NULL);
964 return buildsym_compunit->compunit_symtab;
967 /* See buildsym.h. */
970 get_macro_table (void)
972 struct objfile *objfile;
974 gdb_assert (buildsym_compunit != NULL);
975 return buildsym_compunit->get_macro_table ();
978 /* Start a new symtab for a new source file in OBJFILE. Called, for example,
979 when a stabs symbol of type N_SO is seen, or when a DWARF
980 TAG_compile_unit DIE is seen. It indicates the start of data for
981 one original source file.
983 NAME is the name of the file (cannot be NULL). COMP_DIR is the
984 directory in which the file was compiled (or NULL if not known).
985 START_ADDR is the lowest address of objects in the file (or 0 if
986 not known). LANGUAGE is the language of the source file, or
987 language_unknown if not known, in which case it'll be deduced from
990 struct compunit_symtab *
991 start_symtab (struct objfile *objfile, const char *name, const char *comp_dir,
992 CORE_ADDR start_addr, enum language language)
994 /* These should have been reset either by successful completion of building
995 a symtab, or by the scoped_free_pendings destructor. */
996 gdb_assert (buildsym_compunit == nullptr);
998 buildsym_compunit = new struct buildsym_compunit (objfile, name, comp_dir,
999 language, start_addr);
1001 /* Allocate the compunit symtab now. The caller needs it to allocate
1002 non-primary symtabs. It is also needed by get_macro_table. */
1003 buildsym_compunit->compunit_symtab = allocate_compunit_symtab (objfile,
1006 /* Build the subfile for NAME (the main source file) so that we can record
1007 a pointer to it for later.
1008 IMPORTANT: Do not allocate a struct symtab for NAME here.
1009 It can happen that the debug info provides a different path to NAME than
1010 DIRNAME,NAME. We cope with this in watch_main_source_file_lossage but
1011 that only works if the main_subfile doesn't have a symtab yet. */
1012 start_subfile (name);
1013 /* Save this so that we don't have to go looking for it at the end
1014 of the subfiles list. */
1015 buildsym_compunit->main_subfile = buildsym_compunit->m_current_subfile;
1017 return buildsym_compunit->compunit_symtab;
1020 /* Restart compilation for a symtab.
1021 CUST is the result of end_expandable_symtab.
1022 NAME, START_ADDR are the source file we are resuming with.
1024 This is used when a symtab is built from multiple sources.
1025 The symtab is first built with start_symtab/end_expandable_symtab
1026 and then for each additional piece call restart_symtab/augment_*_symtab.
1027 Note: At the moment there is only augment_type_symtab. */
1030 restart_symtab (struct compunit_symtab *cust,
1031 const char *name, CORE_ADDR start_addr)
1033 /* These should have been reset either by successful completion of building
1034 a symtab, or by the scoped_free_pendings destructor. */
1035 gdb_assert (buildsym_compunit == nullptr);
1038 = new struct buildsym_compunit (COMPUNIT_OBJFILE (cust),
1040 COMPUNIT_DIRNAME (cust),
1041 compunit_language (cust),
1043 buildsym_compunit->compunit_symtab = cust;
1046 /* Subroutine of end_symtab to simplify it. Look for a subfile that
1047 matches the main source file's basename. If there is only one, and
1048 if the main source file doesn't have any symbol or line number
1049 information, then copy this file's symtab and line_vector to the
1050 main source file's subfile and discard the other subfile. This can
1051 happen because of a compiler bug or from the user playing games
1052 with #line or from things like a distributed build system that
1053 manipulates the debug info. This can also happen from an innocent
1054 symlink in the paths, we don't canonicalize paths here. */
1057 watch_main_source_file_lossage (void)
1059 struct subfile *mainsub, *subfile;
1061 /* We have to watch for buildsym_compunit == NULL here. It's a quirk of
1062 end_symtab, it can return NULL so there may not be a main subfile. */
1063 if (buildsym_compunit == NULL)
1066 /* Get the main source file. */
1067 mainsub = buildsym_compunit->main_subfile;
1069 /* If the main source file doesn't have any line number or symbol
1070 info, look for an alias in another subfile. */
1072 if (mainsub->line_vector == NULL
1073 && mainsub->symtab == NULL)
1075 const char *mainbase = lbasename (mainsub->name);
1077 struct subfile *prevsub;
1078 struct subfile *mainsub_alias = NULL;
1079 struct subfile *prev_mainsub_alias = NULL;
1082 for (subfile = buildsym_compunit->subfiles;
1084 subfile = subfile->next)
1086 if (subfile == mainsub)
1088 if (filename_cmp (lbasename (subfile->name), mainbase) == 0)
1091 mainsub_alias = subfile;
1092 prev_mainsub_alias = prevsub;
1097 if (nr_matches == 1)
1099 gdb_assert (mainsub_alias != NULL && mainsub_alias != mainsub);
1101 /* Found a match for the main source file.
1102 Copy its line_vector and symtab to the main subfile
1103 and then discard it. */
1105 mainsub->line_vector = mainsub_alias->line_vector;
1106 mainsub->line_vector_length = mainsub_alias->line_vector_length;
1107 mainsub->symtab = mainsub_alias->symtab;
1109 if (prev_mainsub_alias == NULL)
1110 buildsym_compunit->subfiles = mainsub_alias->next;
1112 prev_mainsub_alias->next = mainsub_alias->next;
1113 xfree (mainsub_alias->name);
1114 xfree (mainsub_alias);
1119 /* Reset state after a successful building of a symtab. */
1122 reset_symtab_globals (void)
1124 free_buildsym_compunit ();
1127 /* Implementation of the first part of end_symtab. It allows modifying
1128 STATIC_BLOCK before it gets finalized by end_symtab_from_static_block.
1129 If the returned value is NULL there is no blockvector created for
1130 this symtab (you still must call end_symtab_from_static_block).
1132 END_ADDR is the same as for end_symtab: the address of the end of the
1135 If EXPANDABLE is non-zero the STATIC_BLOCK dictionary is made
1138 If REQUIRED is non-zero, then a symtab is created even if it does
1139 not contain any symbols. */
1142 end_symtab_get_static_block (CORE_ADDR end_addr, int expandable, int required)
1144 struct objfile *objfile = buildsym_compunit->objfile;
1146 /* Finish the lexical context of the last function in the file; pop
1147 the context stack. */
1149 if (!buildsym_compunit->m_context_stack.empty ())
1151 struct context_stack cstk = pop_context ();
1153 /* Make a block for the local symbols within. */
1154 finish_block (cstk.name, cstk.old_blocks, NULL,
1155 cstk.start_addr, end_addr);
1157 if (!buildsym_compunit->m_context_stack.empty ())
1159 /* This is said to happen with SCO. The old coffread.c
1160 code simply emptied the context stack, so we do the
1161 same. FIXME: Find out why it is happening. This is not
1162 believed to happen in most cases (even for coffread.c);
1163 it used to be an abort(). */
1164 complaint (_("Context stack not empty in end_symtab"));
1165 buildsym_compunit->m_context_stack.clear ();
1169 /* Reordered executables may have out of order pending blocks; if
1170 OBJF_REORDERED is true, then sort the pending blocks. */
1172 if ((objfile->flags & OBJF_REORDERED) && buildsym_compunit->m_pending_blocks)
1174 struct pending_block *pb;
1176 std::vector<block *> barray;
1178 for (pb = buildsym_compunit->m_pending_blocks; pb != NULL; pb = pb->next)
1179 barray.push_back (pb->block);
1181 /* Sort blocks by start address in descending order. Blocks with the
1182 same start address must remain in the original order to preserve
1183 inline function caller/callee relationships. */
1184 std::stable_sort (barray.begin (), barray.end (),
1185 [] (const block *a, const block *b)
1187 return BLOCK_START (a) > BLOCK_START (b);
1191 for (pb = buildsym_compunit->m_pending_blocks; pb != NULL; pb = pb->next)
1192 pb->block = barray[i++];
1195 /* Cleanup any undefined types that have been left hanging around
1196 (this needs to be done before the finish_blocks so that
1197 file_symbols is still good).
1199 Both cleanup_undefined_stabs_types and finish_global_stabs are stabs
1200 specific, but harmless for other symbol readers, since on gdb
1201 startup or when finished reading stabs, the state is set so these
1202 are no-ops. FIXME: Is this handled right in case of QUIT? Can
1203 we make this cleaner? */
1205 cleanup_undefined_stabs_types (objfile);
1206 finish_global_stabs (objfile);
1209 && buildsym_compunit->m_pending_blocks == NULL
1210 && buildsym_compunit->m_file_symbols == NULL
1211 && buildsym_compunit->m_global_symbols == NULL
1212 && !buildsym_compunit->m_have_line_numbers
1213 && buildsym_compunit->m_pending_macros == NULL
1214 && buildsym_compunit->m_global_using_directives == NULL)
1216 /* Ignore symtabs that have no functions with real debugging info. */
1221 /* Define the STATIC_BLOCK. */
1222 return finish_block_internal (NULL, get_file_symbols (), NULL, NULL,
1223 buildsym_compunit->m_last_source_start_addr,
1224 end_addr, 0, expandable);
1228 /* Subroutine of end_symtab_from_static_block to simplify it.
1229 Handle the "have blockvector" case.
1230 See end_symtab_from_static_block for a description of the arguments. */
1232 static struct compunit_symtab *
1233 end_symtab_with_blockvector (struct block *static_block,
1234 int section, int expandable)
1236 struct objfile *objfile = buildsym_compunit->objfile;
1237 struct compunit_symtab *cu = buildsym_compunit->compunit_symtab;
1238 struct symtab *symtab;
1239 struct blockvector *blockvector;
1240 struct subfile *subfile;
1243 gdb_assert (static_block != NULL);
1244 gdb_assert (buildsym_compunit != NULL);
1245 gdb_assert (buildsym_compunit->subfiles != NULL);
1247 end_addr = BLOCK_END (static_block);
1249 /* Create the GLOBAL_BLOCK and build the blockvector. */
1250 finish_block_internal (NULL, get_global_symbols (), NULL, NULL,
1251 buildsym_compunit->m_last_source_start_addr, end_addr,
1253 blockvector = make_blockvector ();
1255 /* Read the line table if it has to be read separately.
1256 This is only used by xcoffread.c. */
1257 if (objfile->sf->sym_read_linetable != NULL)
1258 objfile->sf->sym_read_linetable (objfile);
1260 /* Handle the case where the debug info specifies a different path
1261 for the main source file. It can cause us to lose track of its
1262 line number information. */
1263 watch_main_source_file_lossage ();
1265 /* Now create the symtab objects proper, if not already done,
1266 one for each subfile. */
1268 for (subfile = buildsym_compunit->subfiles;
1270 subfile = subfile->next)
1272 int linetablesize = 0;
1274 if (subfile->line_vector)
1276 linetablesize = sizeof (struct linetable) +
1277 subfile->line_vector->nitems * sizeof (struct linetable_entry);
1279 /* Like the pending blocks, the line table may be
1280 scrambled in reordered executables. Sort it if
1281 OBJF_REORDERED is true. */
1282 if (objfile->flags & OBJF_REORDERED)
1283 qsort (subfile->line_vector->item,
1284 subfile->line_vector->nitems,
1285 sizeof (struct linetable_entry), compare_line_numbers);
1288 /* Allocate a symbol table if necessary. */
1289 if (subfile->symtab == NULL)
1290 subfile->symtab = allocate_symtab (cu, subfile->name);
1291 symtab = subfile->symtab;
1293 /* Fill in its components. */
1295 if (subfile->line_vector)
1297 /* Reallocate the line table on the symbol obstack. */
1298 SYMTAB_LINETABLE (symtab) = (struct linetable *)
1299 obstack_alloc (&objfile->objfile_obstack, linetablesize);
1300 memcpy (SYMTAB_LINETABLE (symtab), subfile->line_vector,
1305 SYMTAB_LINETABLE (symtab) = NULL;
1308 /* Use whatever language we have been using for this
1309 subfile, not the one that was deduced in allocate_symtab
1310 from the filename. We already did our own deducing when
1311 we created the subfile, and we may have altered our
1312 opinion of what language it is from things we found in
1314 symtab->language = subfile->language;
1317 /* Make sure the symtab of main_subfile is the first in its list. */
1319 struct symtab *main_symtab, *prev_symtab;
1321 main_symtab = buildsym_compunit->main_subfile->symtab;
1323 ALL_COMPUNIT_FILETABS (cu, symtab)
1325 if (symtab == main_symtab)
1327 if (prev_symtab != NULL)
1329 prev_symtab->next = main_symtab->next;
1330 main_symtab->next = COMPUNIT_FILETABS (cu);
1331 COMPUNIT_FILETABS (cu) = main_symtab;
1335 prev_symtab = symtab;
1337 gdb_assert (main_symtab == COMPUNIT_FILETABS (cu));
1340 /* Fill out the compunit symtab. */
1342 if (buildsym_compunit->comp_dir != NULL)
1344 /* Reallocate the dirname on the symbol obstack. */
1345 const char *comp_dir = buildsym_compunit->comp_dir.get ();
1346 COMPUNIT_DIRNAME (cu)
1347 = (const char *) obstack_copy0 (&objfile->objfile_obstack,
1348 comp_dir, strlen (comp_dir));
1351 /* Save the debug format string (if any) in the symtab. */
1352 COMPUNIT_DEBUGFORMAT (cu) = buildsym_compunit->debugformat;
1354 /* Similarly for the producer. */
1355 COMPUNIT_PRODUCER (cu) = buildsym_compunit->producer;
1357 COMPUNIT_BLOCKVECTOR (cu) = blockvector;
1359 struct block *b = BLOCKVECTOR_BLOCK (blockvector, GLOBAL_BLOCK);
1361 set_block_compunit_symtab (b, cu);
1364 COMPUNIT_BLOCK_LINE_SECTION (cu) = section;
1366 COMPUNIT_MACRO_TABLE (cu) = buildsym_compunit->release_macros ();
1368 /* Default any symbols without a specified symtab to the primary symtab. */
1372 /* The main source file's symtab. */
1373 symtab = COMPUNIT_FILETABS (cu);
1375 for (block_i = 0; block_i < BLOCKVECTOR_NBLOCKS (blockvector); block_i++)
1377 struct block *block = BLOCKVECTOR_BLOCK (blockvector, block_i);
1379 struct dict_iterator iter;
1381 /* Inlined functions may have symbols not in the global or
1382 static symbol lists. */
1383 if (BLOCK_FUNCTION (block) != NULL)
1384 if (symbol_symtab (BLOCK_FUNCTION (block)) == NULL)
1385 symbol_set_symtab (BLOCK_FUNCTION (block), symtab);
1387 /* Note that we only want to fix up symbols from the local
1388 blocks, not blocks coming from included symtabs. That is why
1389 we use ALL_DICT_SYMBOLS here and not ALL_BLOCK_SYMBOLS. */
1390 ALL_DICT_SYMBOLS (BLOCK_DICT (block), iter, sym)
1391 if (symbol_symtab (sym) == NULL)
1392 symbol_set_symtab (sym, symtab);
1396 add_compunit_symtab_to_objfile (cu);
1401 /* Implementation of the second part of end_symtab. Pass STATIC_BLOCK
1402 as value returned by end_symtab_get_static_block.
1404 SECTION is the same as for end_symtab: the section number
1405 (in objfile->section_offsets) of the blockvector and linetable.
1407 If EXPANDABLE is non-zero the GLOBAL_BLOCK dictionary is made
1410 struct compunit_symtab *
1411 end_symtab_from_static_block (struct block *static_block,
1412 int section, int expandable)
1414 struct compunit_symtab *cu;
1416 if (static_block == NULL)
1418 /* Handle the "no blockvector" case.
1419 When this happens there is nothing to record, so there's nothing
1420 to do: memory will be freed up later.
1422 Note: We won't be adding a compunit to the objfile's list of
1423 compunits, so there's nothing to unchain. However, since each symtab
1424 is added to the objfile's obstack we can't free that space.
1425 We could do better, but this is believed to be a sufficiently rare
1430 cu = end_symtab_with_blockvector (static_block, section, expandable);
1432 reset_symtab_globals ();
1437 /* Finish the symbol definitions for one main source file, close off
1438 all the lexical contexts for that file (creating struct block's for
1439 them), then make the struct symtab for that file and put it in the
1442 END_ADDR is the address of the end of the file's text. SECTION is
1443 the section number (in objfile->section_offsets) of the blockvector
1446 Note that it is possible for end_symtab() to return NULL. In
1447 particular, for the DWARF case at least, it will return NULL when
1448 it finds a compilation unit that has exactly one DIE, a
1449 TAG_compile_unit DIE. This can happen when we link in an object
1450 file that was compiled from an empty source file. Returning NULL
1451 is probably not the correct thing to do, because then gdb will
1452 never know about this empty file (FIXME).
1454 If you need to modify STATIC_BLOCK before it is finalized you should
1455 call end_symtab_get_static_block and end_symtab_from_static_block
1458 struct compunit_symtab *
1459 end_symtab (CORE_ADDR end_addr, int section)
1461 struct block *static_block;
1463 static_block = end_symtab_get_static_block (end_addr, 0, 0);
1464 return end_symtab_from_static_block (static_block, section, 0);
1467 /* Same as end_symtab except create a symtab that can be later added to. */
1469 struct compunit_symtab *
1470 end_expandable_symtab (CORE_ADDR end_addr, int section)
1472 struct block *static_block;
1474 static_block = end_symtab_get_static_block (end_addr, 1, 0);
1475 return end_symtab_from_static_block (static_block, section, 1);
1478 /* Subroutine of augment_type_symtab to simplify it.
1479 Attach the main source file's symtab to all symbols in PENDING_LIST that
1483 set_missing_symtab (struct pending *pending_list,
1484 struct compunit_symtab *cu)
1486 struct pending *pending;
1489 for (pending = pending_list; pending != NULL; pending = pending->next)
1491 for (i = 0; i < pending->nsyms; ++i)
1493 if (symbol_symtab (pending->symbol[i]) == NULL)
1494 symbol_set_symtab (pending->symbol[i], COMPUNIT_FILETABS (cu));
1499 /* Same as end_symtab, but for the case where we're adding more symbols
1500 to an existing symtab that is known to contain only type information.
1501 This is the case for DWARF4 Type Units. */
1504 augment_type_symtab (void)
1506 struct compunit_symtab *cust = buildsym_compunit->compunit_symtab;
1507 const struct blockvector *blockvector = COMPUNIT_BLOCKVECTOR (cust);
1509 if (!buildsym_compunit->m_context_stack.empty ())
1510 complaint (_("Context stack not empty in augment_type_symtab"));
1511 if (buildsym_compunit->m_pending_blocks != NULL)
1512 complaint (_("Blocks in a type symtab"));
1513 if (buildsym_compunit->m_pending_macros != NULL)
1514 complaint (_("Macro in a type symtab"));
1515 if (buildsym_compunit->m_have_line_numbers)
1516 complaint (_("Line numbers recorded in a type symtab"));
1518 if (buildsym_compunit->m_file_symbols != NULL)
1520 struct block *block = BLOCKVECTOR_BLOCK (blockvector, STATIC_BLOCK);
1522 /* First mark any symbols without a specified symtab as belonging
1523 to the primary symtab. */
1524 set_missing_symtab (buildsym_compunit->m_file_symbols, cust);
1526 dict_add_pending (BLOCK_DICT (block), buildsym_compunit->m_file_symbols);
1529 if (buildsym_compunit->m_global_symbols != NULL)
1531 struct block *block = BLOCKVECTOR_BLOCK (blockvector, GLOBAL_BLOCK);
1533 /* First mark any symbols without a specified symtab as belonging
1534 to the primary symtab. */
1535 set_missing_symtab (buildsym_compunit->m_global_symbols, cust);
1537 dict_add_pending (BLOCK_DICT (block),
1538 buildsym_compunit->m_global_symbols);
1541 reset_symtab_globals ();
1544 /* Push a context block. Args are an identifying nesting level
1545 (checkable when you pop it), and the starting PC address of this
1548 struct context_stack *
1549 push_context (int desc, CORE_ADDR valu)
1551 gdb_assert (buildsym_compunit != nullptr);
1553 buildsym_compunit->m_context_stack.emplace_back ();
1554 struct context_stack *newobj = &buildsym_compunit->m_context_stack.back ();
1556 newobj->depth = desc;
1557 newobj->locals = buildsym_compunit->m_local_symbols;
1558 newobj->old_blocks = buildsym_compunit->m_pending_blocks;
1559 newobj->start_addr = valu;
1560 newobj->local_using_directives
1561 = buildsym_compunit->m_local_using_directives;
1562 newobj->name = NULL;
1564 buildsym_compunit->m_local_symbols = NULL;
1565 buildsym_compunit->m_local_using_directives = NULL;
1570 /* Pop a context block. Returns the address of the context block just
1573 struct context_stack
1576 gdb_assert (buildsym_compunit != nullptr);
1577 gdb_assert (!buildsym_compunit->m_context_stack.empty ());
1578 struct context_stack result = buildsym_compunit->m_context_stack.back ();
1579 buildsym_compunit->m_context_stack.pop_back ();
1586 record_debugformat (const char *format)
1588 buildsym_compunit->debugformat = format;
1592 record_producer (const char *producer)
1594 buildsym_compunit->producer = producer;
1599 /* See buildsym.h. */
1602 set_last_source_file (const char *name)
1604 gdb_assert (buildsym_compunit != nullptr || name == nullptr);
1605 if (buildsym_compunit != nullptr)
1606 buildsym_compunit->set_last_source_file (name);
1609 /* See buildsym.h. */
1612 get_last_source_file (void)
1614 if (buildsym_compunit == nullptr)
1616 return buildsym_compunit->m_last_source_file.get ();
1619 /* See buildsym.h. */
1622 set_last_source_start_addr (CORE_ADDR addr)
1624 gdb_assert (buildsym_compunit != nullptr);
1625 buildsym_compunit->m_last_source_start_addr = addr;
1628 /* See buildsym.h. */
1631 get_last_source_start_addr ()
1633 gdb_assert (buildsym_compunit != nullptr);
1634 return buildsym_compunit->m_last_source_start_addr;
1637 /* See buildsym.h. */
1639 struct using_direct **
1640 get_local_using_directives ()
1642 gdb_assert (buildsym_compunit != nullptr);
1643 return &buildsym_compunit->m_local_using_directives;
1646 /* See buildsym.h. */
1649 set_local_using_directives (struct using_direct *new_local)
1651 gdb_assert (buildsym_compunit != nullptr);
1652 buildsym_compunit->m_local_using_directives = new_local;
1655 /* See buildsym.h. */
1657 struct using_direct **
1658 get_global_using_directives ()
1660 gdb_assert (buildsym_compunit != nullptr);
1661 return &buildsym_compunit->m_global_using_directives;
1664 /* See buildsym.h. */
1667 outermost_context_p ()
1669 gdb_assert (buildsym_compunit != nullptr);
1670 return buildsym_compunit->m_context_stack.empty ();
1673 /* See buildsym.h. */
1675 struct context_stack *
1676 get_current_context_stack ()
1678 gdb_assert (buildsym_compunit != nullptr);
1679 if (buildsym_compunit->m_context_stack.empty ())
1681 return &buildsym_compunit->m_context_stack.back ();
1684 /* See buildsym.h. */
1687 get_context_stack_depth ()
1689 gdb_assert (buildsym_compunit != nullptr);
1690 return buildsym_compunit->m_context_stack.size ();
1693 /* See buildsym.h. */
1696 get_current_subfile ()
1698 gdb_assert (buildsym_compunit != nullptr);
1699 return buildsym_compunit->m_current_subfile;
1702 /* See buildsym.h. */
1705 get_local_symbols ()
1707 gdb_assert (buildsym_compunit != nullptr);
1708 return &buildsym_compunit->m_local_symbols;
1711 /* See buildsym.h. */
1716 gdb_assert (buildsym_compunit != nullptr);
1717 return &buildsym_compunit->m_file_symbols;
1720 /* See buildsym.h. */
1723 get_global_symbols ()
1725 gdb_assert (buildsym_compunit != nullptr);
1726 return &buildsym_compunit->m_global_symbols;