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 /* Initial sizes of data structures. These are realloc'd larger if
286 needed, and realloc'd down to the size actually used, when
289 #define INITIAL_LINE_VECTOR_LENGTH 1000
292 /* Maintain the lists of symbols and blocks. */
294 /* Add a symbol to one of the lists of symbols. */
297 add_symbol_to_list (struct symbol *symbol, struct pending **listhead)
299 struct pending *link;
301 /* If this is an alias for another symbol, don't add it. */
302 if (symbol->ginfo.name && symbol->ginfo.name[0] == '#')
305 /* We keep PENDINGSIZE symbols in each link of the list. If we
306 don't have a link with room in it, add a new link. */
307 if (*listhead == NULL || (*listhead)->nsyms == PENDINGSIZE)
309 link = XNEW (struct pending);
310 link->next = *listhead;
315 (*listhead)->symbol[(*listhead)->nsyms++] = symbol;
318 /* Find a symbol named NAME on a LIST. NAME need not be
319 '\0'-terminated; LENGTH is the length of the name. */
322 find_symbol_in_list (struct pending *list, char *name, int length)
329 for (j = list->nsyms; --j >= 0;)
331 pp = SYMBOL_LINKAGE_NAME (list->symbol[j]);
332 if (*pp == *name && strncmp (pp, name, length) == 0
333 && pp[length] == '\0')
335 return (list->symbol[j]);
343 /* At end of reading syms, or in case of quit, ensure everything
344 associated with building symtabs is freed.
346 N.B. This is *not* intended to be used when building psymtabs. Some debug
347 info readers call this anyway, which is harmless if confusing. */
349 scoped_free_pendings::~scoped_free_pendings ()
351 free_buildsym_compunit ();
354 /* Record BLOCK on the list of all blocks in the file. Put it after
355 OPBLOCK, or at the beginning if opblock is NULL. This puts the
356 block in the list after all its subblocks. */
359 record_pending_block (struct block *block, struct pending_block *opblock)
361 struct pending_block *pblock;
363 pblock = XOBNEW (&buildsym_compunit->m_pending_block_obstack,
364 struct pending_block);
365 pblock->block = block;
368 pblock->next = opblock->next;
369 opblock->next = pblock;
373 pblock->next = buildsym_compunit->m_pending_blocks;
374 buildsym_compunit->m_pending_blocks = pblock;
378 /* Take one of the lists of symbols and make a block from it. Keep
379 the order the symbols have in the list (reversed from the input
380 file). Put the block on the list of pending blocks. */
382 static struct block *
383 finish_block_internal (struct symbol *symbol,
384 struct pending **listhead,
385 struct pending_block *old_blocks,
386 const struct dynamic_prop *static_link,
387 CORE_ADDR start, CORE_ADDR end,
388 int is_global, int expandable)
390 struct objfile *objfile = buildsym_compunit->objfile;
391 struct gdbarch *gdbarch = get_objfile_arch (objfile);
392 struct pending *next, *next1;
394 struct pending_block *pblock;
395 struct pending_block *opblock;
398 ? allocate_global_block (&objfile->objfile_obstack)
399 : allocate_block (&objfile->objfile_obstack));
404 = dict_create_linear (&objfile->objfile_obstack,
405 buildsym_compunit->language, *listhead);
412 = dict_create_hashed_expandable (buildsym_compunit->language);
413 dict_add_pending (BLOCK_DICT (block), *listhead);
418 dict_create_hashed (&objfile->objfile_obstack,
419 buildsym_compunit->language, *listhead);
423 BLOCK_START (block) = start;
424 BLOCK_END (block) = end;
426 /* Put the block in as the value of the symbol that names it. */
430 struct type *ftype = SYMBOL_TYPE (symbol);
431 struct dict_iterator iter;
432 SYMBOL_BLOCK_VALUE (symbol) = block;
433 BLOCK_FUNCTION (block) = symbol;
435 if (TYPE_NFIELDS (ftype) <= 0)
437 /* No parameter type information is recorded with the
438 function's type. Set that from the type of the
439 parameter symbols. */
440 int nparams = 0, iparams;
443 /* Here we want to directly access the dictionary, because
444 we haven't fully initialized the block yet. */
445 ALL_DICT_SYMBOLS (BLOCK_DICT (block), iter, sym)
447 if (SYMBOL_IS_ARGUMENT (sym))
452 TYPE_NFIELDS (ftype) = nparams;
453 TYPE_FIELDS (ftype) = (struct field *)
454 TYPE_ALLOC (ftype, nparams * sizeof (struct field));
457 /* Here we want to directly access the dictionary, because
458 we haven't fully initialized the block yet. */
459 ALL_DICT_SYMBOLS (BLOCK_DICT (block), iter, sym)
461 if (iparams == nparams)
464 if (SYMBOL_IS_ARGUMENT (sym))
466 TYPE_FIELD_TYPE (ftype, iparams) = SYMBOL_TYPE (sym);
467 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0;
476 BLOCK_FUNCTION (block) = NULL;
479 if (static_link != NULL)
480 objfile_register_static_link (objfile, block, static_link);
482 /* Now free the links of the list, and empty the list. */
484 for (next = *listhead; next; next = next1)
491 /* Check to be sure that the blocks have an end address that is
492 greater than starting address. */
494 if (BLOCK_END (block) < BLOCK_START (block))
498 complaint (_("block end address less than block "
499 "start address in %s (patched it)"),
500 SYMBOL_PRINT_NAME (symbol));
504 complaint (_("block end address %s less than block "
505 "start address %s (patched it)"),
506 paddress (gdbarch, BLOCK_END (block)),
507 paddress (gdbarch, BLOCK_START (block)));
509 /* Better than nothing. */
510 BLOCK_END (block) = BLOCK_START (block);
513 /* Install this block as the superblock of all blocks made since the
514 start of this scope that don't have superblocks yet. */
517 for (pblock = buildsym_compunit->m_pending_blocks;
518 pblock && pblock != old_blocks;
519 pblock = pblock->next)
521 if (BLOCK_SUPERBLOCK (pblock->block) == NULL)
523 /* Check to be sure the blocks are nested as we receive
524 them. If the compiler/assembler/linker work, this just
525 burns a small amount of time.
527 Skip blocks which correspond to a function; they're not
528 physically nested inside this other blocks, only
530 if (BLOCK_FUNCTION (pblock->block) == NULL
531 && (BLOCK_START (pblock->block) < BLOCK_START (block)
532 || BLOCK_END (pblock->block) > BLOCK_END (block)))
536 complaint (_("inner block not inside outer block in %s"),
537 SYMBOL_PRINT_NAME (symbol));
541 complaint (_("inner block (%s-%s) not "
542 "inside outer block (%s-%s)"),
543 paddress (gdbarch, BLOCK_START (pblock->block)),
544 paddress (gdbarch, BLOCK_END (pblock->block)),
545 paddress (gdbarch, BLOCK_START (block)),
546 paddress (gdbarch, BLOCK_END (block)));
548 if (BLOCK_START (pblock->block) < BLOCK_START (block))
549 BLOCK_START (pblock->block) = BLOCK_START (block);
550 if (BLOCK_END (pblock->block) > BLOCK_END (block))
551 BLOCK_END (pblock->block) = BLOCK_END (block);
553 BLOCK_SUPERBLOCK (pblock->block) = block;
558 block_set_using (block,
560 ? buildsym_compunit->m_global_using_directives
561 : buildsym_compunit->m_local_using_directives),
562 &objfile->objfile_obstack);
564 buildsym_compunit->m_global_using_directives = NULL;
566 buildsym_compunit->m_local_using_directives = NULL;
568 record_pending_block (block, opblock);
574 finish_block (struct symbol *symbol,
575 struct pending_block *old_blocks,
576 const struct dynamic_prop *static_link,
577 CORE_ADDR start, CORE_ADDR end)
579 return finish_block_internal (symbol, &buildsym_compunit->m_local_symbols,
580 old_blocks, static_link,
584 /* Record that the range of addresses from START to END_INCLUSIVE
585 (inclusive, like it says) belongs to BLOCK. BLOCK's start and end
586 addresses must be set already. You must apply this function to all
587 BLOCK's children before applying it to BLOCK.
589 If a call to this function complicates the picture beyond that
590 already provided by BLOCK_START and BLOCK_END, then we create an
591 address map for the block. */
593 record_block_range (struct block *block,
594 CORE_ADDR start, CORE_ADDR end_inclusive)
596 /* If this is any different from the range recorded in the block's
597 own BLOCK_START and BLOCK_END, then note that the address map has
598 become interesting. Note that even if this block doesn't have
599 any "interesting" ranges, some later block might, so we still
600 need to record this block in the addrmap. */
601 if (start != BLOCK_START (block)
602 || end_inclusive + 1 != BLOCK_END (block))
603 buildsym_compunit->m_pending_addrmap_interesting = true;
605 if (buildsym_compunit->m_pending_addrmap == nullptr)
606 buildsym_compunit->m_pending_addrmap
607 = addrmap_create_mutable (&buildsym_compunit->m_pending_addrmap_obstack);
609 addrmap_set_empty (buildsym_compunit->m_pending_addrmap,
610 start, end_inclusive, block);
613 static struct blockvector *
614 make_blockvector (void)
616 struct objfile *objfile = buildsym_compunit->objfile;
617 struct pending_block *next;
618 struct blockvector *blockvector;
621 /* Count the length of the list of blocks. */
623 for (next = buildsym_compunit->m_pending_blocks, i = 0;
625 next = next->next, i++)
629 blockvector = (struct blockvector *)
630 obstack_alloc (&objfile->objfile_obstack,
631 (sizeof (struct blockvector)
632 + (i - 1) * sizeof (struct block *)));
634 /* Copy the blocks into the blockvector. This is done in reverse
635 order, which happens to put the blocks into the proper order
636 (ascending starting address). finish_block has hair to insert
637 each block into the list after its subblocks in order to make
638 sure this is true. */
640 BLOCKVECTOR_NBLOCKS (blockvector) = i;
641 for (next = buildsym_compunit->m_pending_blocks; next; next = next->next)
643 BLOCKVECTOR_BLOCK (blockvector, --i) = next->block;
646 buildsym_compunit->free_pending_blocks ();
648 /* If we needed an address map for this symtab, record it in the
650 if (buildsym_compunit->m_pending_addrmap != nullptr
651 && buildsym_compunit->m_pending_addrmap_interesting)
652 BLOCKVECTOR_MAP (blockvector)
653 = addrmap_create_fixed (buildsym_compunit->m_pending_addrmap,
654 &objfile->objfile_obstack);
656 BLOCKVECTOR_MAP (blockvector) = 0;
658 /* Some compilers output blocks in the wrong order, but we depend on
659 their being in the right order so we can binary search. Check the
660 order and moan about it.
661 Note: Remember that the first two blocks are the global and static
662 blocks. We could special case that fact and begin checking at block 2.
663 To avoid making that assumption we do not. */
664 if (BLOCKVECTOR_NBLOCKS (blockvector) > 1)
666 for (i = 1; i < BLOCKVECTOR_NBLOCKS (blockvector); i++)
668 if (BLOCK_START (BLOCKVECTOR_BLOCK (blockvector, i - 1))
669 > BLOCK_START (BLOCKVECTOR_BLOCK (blockvector, i)))
672 = BLOCK_START (BLOCKVECTOR_BLOCK (blockvector, i));
674 complaint (_("block at %s out of order"),
675 hex_string ((LONGEST) start));
680 return (blockvector);
683 /* Start recording information about source code that came from an
684 included (or otherwise merged-in) source file with a different
685 name. NAME is the name of the file (cannot be NULL). */
688 start_subfile (const char *name)
690 const char *subfile_dirname;
691 struct subfile *subfile;
693 gdb_assert (buildsym_compunit != NULL);
695 subfile_dirname = buildsym_compunit->comp_dir.get ();
697 /* See if this subfile is already registered. */
699 for (subfile = buildsym_compunit->subfiles; subfile; subfile = subfile->next)
703 /* If NAME is an absolute path, and this subfile is not, then
704 attempt to create an absolute path to compare. */
705 if (IS_ABSOLUTE_PATH (name)
706 && !IS_ABSOLUTE_PATH (subfile->name)
707 && subfile_dirname != NULL)
708 subfile_name = concat (subfile_dirname, SLASH_STRING,
709 subfile->name, (char *) NULL);
711 subfile_name = subfile->name;
713 if (FILENAME_CMP (subfile_name, name) == 0)
715 buildsym_compunit->m_current_subfile = subfile;
716 if (subfile_name != subfile->name)
717 xfree (subfile_name);
720 if (subfile_name != subfile->name)
721 xfree (subfile_name);
724 /* This subfile is not known. Add an entry for it. */
726 subfile = XNEW (struct subfile);
727 memset (subfile, 0, sizeof (struct subfile));
728 subfile->buildsym_compunit = buildsym_compunit;
730 subfile->next = buildsym_compunit->subfiles;
731 buildsym_compunit->subfiles = subfile;
733 buildsym_compunit->m_current_subfile = subfile;
735 subfile->name = xstrdup (name);
737 /* Initialize line-number recording for this subfile. */
738 subfile->line_vector = NULL;
740 /* Default the source language to whatever can be deduced from the
741 filename. If nothing can be deduced (such as for a C/C++ include
742 file with a ".h" extension), then inherit whatever language the
743 previous subfile had. This kludgery is necessary because there
744 is no standard way in some object formats to record the source
745 language. Also, when symtabs are allocated we try to deduce a
746 language then as well, but it is too late for us to use that
747 information while reading symbols, since symtabs aren't allocated
748 until after all the symbols have been processed for a given
751 subfile->language = deduce_language_from_filename (subfile->name);
752 if (subfile->language == language_unknown
753 && subfile->next != NULL)
755 subfile->language = subfile->next->language;
758 /* If the filename of this subfile ends in .C, then change the
759 language of any pending subfiles from C to C++. We also accept
760 any other C++ suffixes accepted by deduce_language_from_filename. */
761 /* Likewise for f2c. */
766 enum language sublang = deduce_language_from_filename (subfile->name);
768 if (sublang == language_cplus || sublang == language_fortran)
769 for (s = buildsym_compunit->subfiles; s != NULL; s = s->next)
770 if (s->language == language_c)
771 s->language = sublang;
774 /* And patch up this file if necessary. */
775 if (subfile->language == language_c
776 && subfile->next != NULL
777 && (subfile->next->language == language_cplus
778 || subfile->next->language == language_fortran))
780 subfile->language = subfile->next->language;
784 /* Delete the buildsym compunit. */
787 free_buildsym_compunit (void)
789 if (buildsym_compunit == NULL)
791 delete buildsym_compunit;
792 buildsym_compunit = NULL;
795 /* For stabs readers, the first N_SO symbol is assumed to be the
796 source file name, and the subfile struct is initialized using that
797 assumption. If another N_SO symbol is later seen, immediately
798 following the first one, then the first one is assumed to be the
799 directory name and the second one is really the source file name.
801 So we have to patch up the subfile struct by moving the old name
802 value to dirname and remembering the new name. Some sanity
803 checking is performed to ensure that the state of the subfile
804 struct is reasonable and that the old name we are assuming to be a
805 directory name actually is (by checking for a trailing '/'). */
808 patch_subfile_names (struct subfile *subfile, const char *name)
811 && buildsym_compunit->comp_dir == NULL
812 && subfile->name != NULL
813 && IS_DIR_SEPARATOR (subfile->name[strlen (subfile->name) - 1]))
815 buildsym_compunit->comp_dir.reset (subfile->name);
816 subfile->name = xstrdup (name);
817 set_last_source_file (name);
819 /* Default the source language to whatever can be deduced from
820 the filename. If nothing can be deduced (such as for a C/C++
821 include file with a ".h" extension), then inherit whatever
822 language the previous subfile had. This kludgery is
823 necessary because there is no standard way in some object
824 formats to record the source language. Also, when symtabs
825 are allocated we try to deduce a language then as well, but
826 it is too late for us to use that information while reading
827 symbols, since symtabs aren't allocated until after all the
828 symbols have been processed for a given source file. */
830 subfile->language = deduce_language_from_filename (subfile->name);
831 if (subfile->language == language_unknown
832 && subfile->next != NULL)
834 subfile->language = subfile->next->language;
839 /* Handle the N_BINCL and N_EINCL symbol types that act like N_SOL for
840 switching source files (different subfiles, as we call them) within
841 one object file, but using a stack rather than in an arbitrary
847 gdb_assert (buildsym_compunit != nullptr);
848 gdb_assert (buildsym_compunit->m_current_subfile != NULL);
849 gdb_assert (buildsym_compunit->m_current_subfile->name != NULL);
850 buildsym_compunit->m_subfile_stack.push_back
851 (buildsym_compunit->m_current_subfile->name);
857 gdb_assert (buildsym_compunit != nullptr);
858 gdb_assert (!buildsym_compunit->m_subfile_stack.empty ());
859 const char *name = buildsym_compunit->m_subfile_stack.back ();
860 buildsym_compunit->m_subfile_stack.pop_back ();
864 /* Add a linetable entry for line number LINE and address PC to the
865 line vector for SUBFILE. */
868 record_line (struct subfile *subfile, int line, CORE_ADDR pc)
870 struct linetable_entry *e;
872 /* Ignore the dummy line number in libg.o */
878 /* Make sure line vector exists and is big enough. */
879 if (!subfile->line_vector)
881 subfile->line_vector_length = INITIAL_LINE_VECTOR_LENGTH;
882 subfile->line_vector = (struct linetable *)
883 xmalloc (sizeof (struct linetable)
884 + subfile->line_vector_length * sizeof (struct linetable_entry));
885 subfile->line_vector->nitems = 0;
886 buildsym_compunit->m_have_line_numbers = true;
889 if (subfile->line_vector->nitems + 1 >= subfile->line_vector_length)
891 subfile->line_vector_length *= 2;
892 subfile->line_vector = (struct linetable *)
893 xrealloc ((char *) subfile->line_vector,
894 (sizeof (struct linetable)
895 + (subfile->line_vector_length
896 * sizeof (struct linetable_entry))));
899 /* Normally, we treat lines as unsorted. But the end of sequence
900 marker is special. We sort line markers at the same PC by line
901 number, so end of sequence markers (which have line == 0) appear
902 first. This is right if the marker ends the previous function,
903 and there is no padding before the next function. But it is
904 wrong if the previous line was empty and we are now marking a
905 switch to a different subfile. We must leave the end of sequence
906 marker at the end of this group of lines, not sort the empty line
907 to after the marker. The easiest way to accomplish this is to
908 delete any empty lines from our table, if they are followed by
909 end of sequence markers. All we lose is the ability to set
910 breakpoints at some lines which contain no instructions
912 if (line == 0 && subfile->line_vector->nitems > 0)
914 e = subfile->line_vector->item + subfile->line_vector->nitems - 1;
915 while (subfile->line_vector->nitems > 0 && e->pc == pc)
918 subfile->line_vector->nitems--;
922 e = subfile->line_vector->item + subfile->line_vector->nitems++;
927 /* Needed in order to sort line tables from IBM xcoff files. Sigh! */
930 compare_line_numbers (const void *ln1p, const void *ln2p)
932 struct linetable_entry *ln1 = (struct linetable_entry *) ln1p;
933 struct linetable_entry *ln2 = (struct linetable_entry *) ln2p;
935 /* Note: this code does not assume that CORE_ADDRs can fit in ints.
936 Please keep it that way. */
937 if (ln1->pc < ln2->pc)
940 if (ln1->pc > ln2->pc)
943 /* If pc equal, sort by line. I'm not sure whether this is optimum
944 behavior (see comment at struct linetable in symtab.h). */
945 return ln1->line - ln2->line;
948 /* See buildsym.h. */
950 struct compunit_symtab *
951 buildsym_compunit_symtab (void)
953 gdb_assert (buildsym_compunit != NULL);
955 return buildsym_compunit->compunit_symtab;
958 /* See buildsym.h. */
961 get_macro_table (void)
963 struct objfile *objfile;
965 gdb_assert (buildsym_compunit != NULL);
966 return buildsym_compunit->get_macro_table ();
969 /* Start a new symtab for a new source file in OBJFILE. Called, for example,
970 when a stabs symbol of type N_SO is seen, or when a DWARF
971 TAG_compile_unit DIE is seen. It indicates the start of data for
972 one original source file.
974 NAME is the name of the file (cannot be NULL). COMP_DIR is the
975 directory in which the file was compiled (or NULL if not known).
976 START_ADDR is the lowest address of objects in the file (or 0 if
977 not known). LANGUAGE is the language of the source file, or
978 language_unknown if not known, in which case it'll be deduced from
981 struct compunit_symtab *
982 start_symtab (struct objfile *objfile, const char *name, const char *comp_dir,
983 CORE_ADDR start_addr, enum language language)
985 /* These should have been reset either by successful completion of building
986 a symtab, or by the scoped_free_pendings destructor. */
987 gdb_assert (buildsym_compunit == nullptr);
989 buildsym_compunit = new struct buildsym_compunit (objfile, name, comp_dir,
990 language, start_addr);
992 /* Allocate the compunit symtab now. The caller needs it to allocate
993 non-primary symtabs. It is also needed by get_macro_table. */
994 buildsym_compunit->compunit_symtab = allocate_compunit_symtab (objfile,
997 /* Build the subfile for NAME (the main source file) so that we can record
998 a pointer to it for later.
999 IMPORTANT: Do not allocate a struct symtab for NAME here.
1000 It can happen that the debug info provides a different path to NAME than
1001 DIRNAME,NAME. We cope with this in watch_main_source_file_lossage but
1002 that only works if the main_subfile doesn't have a symtab yet. */
1003 start_subfile (name);
1004 /* Save this so that we don't have to go looking for it at the end
1005 of the subfiles list. */
1006 buildsym_compunit->main_subfile = buildsym_compunit->m_current_subfile;
1008 return buildsym_compunit->compunit_symtab;
1011 /* Restart compilation for a symtab.
1012 CUST is the result of end_expandable_symtab.
1013 NAME, START_ADDR are the source file we are resuming with.
1015 This is used when a symtab is built from multiple sources.
1016 The symtab is first built with start_symtab/end_expandable_symtab
1017 and then for each additional piece call restart_symtab/augment_*_symtab.
1018 Note: At the moment there is only augment_type_symtab. */
1021 restart_symtab (struct compunit_symtab *cust,
1022 const char *name, CORE_ADDR start_addr)
1024 /* These should have been reset either by successful completion of building
1025 a symtab, or by the scoped_free_pendings destructor. */
1026 gdb_assert (buildsym_compunit == nullptr);
1029 = new struct buildsym_compunit (COMPUNIT_OBJFILE (cust),
1031 COMPUNIT_DIRNAME (cust),
1032 compunit_language (cust),
1034 buildsym_compunit->compunit_symtab = cust;
1037 /* Subroutine of end_symtab to simplify it. Look for a subfile that
1038 matches the main source file's basename. If there is only one, and
1039 if the main source file doesn't have any symbol or line number
1040 information, then copy this file's symtab and line_vector to the
1041 main source file's subfile and discard the other subfile. This can
1042 happen because of a compiler bug or from the user playing games
1043 with #line or from things like a distributed build system that
1044 manipulates the debug info. This can also happen from an innocent
1045 symlink in the paths, we don't canonicalize paths here. */
1048 watch_main_source_file_lossage (void)
1050 struct subfile *mainsub, *subfile;
1052 /* We have to watch for buildsym_compunit == NULL here. It's a quirk of
1053 end_symtab, it can return NULL so there may not be a main subfile. */
1054 if (buildsym_compunit == NULL)
1057 /* Get the main source file. */
1058 mainsub = buildsym_compunit->main_subfile;
1060 /* If the main source file doesn't have any line number or symbol
1061 info, look for an alias in another subfile. */
1063 if (mainsub->line_vector == NULL
1064 && mainsub->symtab == NULL)
1066 const char *mainbase = lbasename (mainsub->name);
1068 struct subfile *prevsub;
1069 struct subfile *mainsub_alias = NULL;
1070 struct subfile *prev_mainsub_alias = NULL;
1073 for (subfile = buildsym_compunit->subfiles;
1075 subfile = subfile->next)
1077 if (subfile == mainsub)
1079 if (filename_cmp (lbasename (subfile->name), mainbase) == 0)
1082 mainsub_alias = subfile;
1083 prev_mainsub_alias = prevsub;
1088 if (nr_matches == 1)
1090 gdb_assert (mainsub_alias != NULL && mainsub_alias != mainsub);
1092 /* Found a match for the main source file.
1093 Copy its line_vector and symtab to the main subfile
1094 and then discard it. */
1096 mainsub->line_vector = mainsub_alias->line_vector;
1097 mainsub->line_vector_length = mainsub_alias->line_vector_length;
1098 mainsub->symtab = mainsub_alias->symtab;
1100 if (prev_mainsub_alias == NULL)
1101 buildsym_compunit->subfiles = mainsub_alias->next;
1103 prev_mainsub_alias->next = mainsub_alias->next;
1104 xfree (mainsub_alias->name);
1105 xfree (mainsub_alias);
1110 /* Reset state after a successful building of a symtab. */
1113 reset_symtab_globals (void)
1115 free_buildsym_compunit ();
1118 /* Implementation of the first part of end_symtab. It allows modifying
1119 STATIC_BLOCK before it gets finalized by end_symtab_from_static_block.
1120 If the returned value is NULL there is no blockvector created for
1121 this symtab (you still must call end_symtab_from_static_block).
1123 END_ADDR is the same as for end_symtab: the address of the end of the
1126 If EXPANDABLE is non-zero the STATIC_BLOCK dictionary is made
1129 If REQUIRED is non-zero, then a symtab is created even if it does
1130 not contain any symbols. */
1133 end_symtab_get_static_block (CORE_ADDR end_addr, int expandable, int required)
1135 struct objfile *objfile = buildsym_compunit->objfile;
1137 /* Finish the lexical context of the last function in the file; pop
1138 the context stack. */
1140 if (!buildsym_compunit->m_context_stack.empty ())
1142 struct context_stack cstk = pop_context ();
1144 /* Make a block for the local symbols within. */
1145 finish_block (cstk.name, cstk.old_blocks, NULL,
1146 cstk.start_addr, end_addr);
1148 if (!buildsym_compunit->m_context_stack.empty ())
1150 /* This is said to happen with SCO. The old coffread.c
1151 code simply emptied the context stack, so we do the
1152 same. FIXME: Find out why it is happening. This is not
1153 believed to happen in most cases (even for coffread.c);
1154 it used to be an abort(). */
1155 complaint (_("Context stack not empty in end_symtab"));
1156 buildsym_compunit->m_context_stack.clear ();
1160 /* Reordered executables may have out of order pending blocks; if
1161 OBJF_REORDERED is true, then sort the pending blocks. */
1163 if ((objfile->flags & OBJF_REORDERED) && buildsym_compunit->m_pending_blocks)
1165 struct pending_block *pb;
1167 std::vector<block *> barray;
1169 for (pb = buildsym_compunit->m_pending_blocks; pb != NULL; pb = pb->next)
1170 barray.push_back (pb->block);
1172 /* Sort blocks by start address in descending order. Blocks with the
1173 same start address must remain in the original order to preserve
1174 inline function caller/callee relationships. */
1175 std::stable_sort (barray.begin (), barray.end (),
1176 [] (const block *a, const block *b)
1178 return BLOCK_START (a) > BLOCK_START (b);
1182 for (pb = buildsym_compunit->m_pending_blocks; pb != NULL; pb = pb->next)
1183 pb->block = barray[i++];
1186 /* Cleanup any undefined types that have been left hanging around
1187 (this needs to be done before the finish_blocks so that
1188 file_symbols is still good).
1190 Both cleanup_undefined_stabs_types and finish_global_stabs are stabs
1191 specific, but harmless for other symbol readers, since on gdb
1192 startup or when finished reading stabs, the state is set so these
1193 are no-ops. FIXME: Is this handled right in case of QUIT? Can
1194 we make this cleaner? */
1196 cleanup_undefined_stabs_types (objfile);
1197 finish_global_stabs (objfile);
1200 && buildsym_compunit->m_pending_blocks == NULL
1201 && buildsym_compunit->m_file_symbols == NULL
1202 && buildsym_compunit->m_global_symbols == NULL
1203 && !buildsym_compunit->m_have_line_numbers
1204 && buildsym_compunit->m_pending_macros == NULL
1205 && buildsym_compunit->m_global_using_directives == NULL)
1207 /* Ignore symtabs that have no functions with real debugging info. */
1212 /* Define the STATIC_BLOCK. */
1213 return finish_block_internal (NULL, get_file_symbols (), NULL, NULL,
1214 buildsym_compunit->m_last_source_start_addr,
1215 end_addr, 0, expandable);
1219 /* Subroutine of end_symtab_from_static_block to simplify it.
1220 Handle the "have blockvector" case.
1221 See end_symtab_from_static_block for a description of the arguments. */
1223 static struct compunit_symtab *
1224 end_symtab_with_blockvector (struct block *static_block,
1225 int section, int expandable)
1227 struct objfile *objfile = buildsym_compunit->objfile;
1228 struct compunit_symtab *cu = buildsym_compunit->compunit_symtab;
1229 struct symtab *symtab;
1230 struct blockvector *blockvector;
1231 struct subfile *subfile;
1234 gdb_assert (static_block != NULL);
1235 gdb_assert (buildsym_compunit != NULL);
1236 gdb_assert (buildsym_compunit->subfiles != NULL);
1238 end_addr = BLOCK_END (static_block);
1240 /* Create the GLOBAL_BLOCK and build the blockvector. */
1241 finish_block_internal (NULL, get_global_symbols (), NULL, NULL,
1242 buildsym_compunit->m_last_source_start_addr, end_addr,
1244 blockvector = make_blockvector ();
1246 /* Read the line table if it has to be read separately.
1247 This is only used by xcoffread.c. */
1248 if (objfile->sf->sym_read_linetable != NULL)
1249 objfile->sf->sym_read_linetable (objfile);
1251 /* Handle the case where the debug info specifies a different path
1252 for the main source file. It can cause us to lose track of its
1253 line number information. */
1254 watch_main_source_file_lossage ();
1256 /* Now create the symtab objects proper, if not already done,
1257 one for each subfile. */
1259 for (subfile = buildsym_compunit->subfiles;
1261 subfile = subfile->next)
1263 int linetablesize = 0;
1265 if (subfile->line_vector)
1267 linetablesize = sizeof (struct linetable) +
1268 subfile->line_vector->nitems * sizeof (struct linetable_entry);
1270 /* Like the pending blocks, the line table may be
1271 scrambled in reordered executables. Sort it if
1272 OBJF_REORDERED is true. */
1273 if (objfile->flags & OBJF_REORDERED)
1274 qsort (subfile->line_vector->item,
1275 subfile->line_vector->nitems,
1276 sizeof (struct linetable_entry), compare_line_numbers);
1279 /* Allocate a symbol table if necessary. */
1280 if (subfile->symtab == NULL)
1281 subfile->symtab = allocate_symtab (cu, subfile->name);
1282 symtab = subfile->symtab;
1284 /* Fill in its components. */
1286 if (subfile->line_vector)
1288 /* Reallocate the line table on the symbol obstack. */
1289 SYMTAB_LINETABLE (symtab) = (struct linetable *)
1290 obstack_alloc (&objfile->objfile_obstack, linetablesize);
1291 memcpy (SYMTAB_LINETABLE (symtab), subfile->line_vector,
1296 SYMTAB_LINETABLE (symtab) = NULL;
1299 /* Use whatever language we have been using for this
1300 subfile, not the one that was deduced in allocate_symtab
1301 from the filename. We already did our own deducing when
1302 we created the subfile, and we may have altered our
1303 opinion of what language it is from things we found in
1305 symtab->language = subfile->language;
1308 /* Make sure the symtab of main_subfile is the first in its list. */
1310 struct symtab *main_symtab, *prev_symtab;
1312 main_symtab = buildsym_compunit->main_subfile->symtab;
1314 ALL_COMPUNIT_FILETABS (cu, symtab)
1316 if (symtab == main_symtab)
1318 if (prev_symtab != NULL)
1320 prev_symtab->next = main_symtab->next;
1321 main_symtab->next = COMPUNIT_FILETABS (cu);
1322 COMPUNIT_FILETABS (cu) = main_symtab;
1326 prev_symtab = symtab;
1328 gdb_assert (main_symtab == COMPUNIT_FILETABS (cu));
1331 /* Fill out the compunit symtab. */
1333 if (buildsym_compunit->comp_dir != NULL)
1335 /* Reallocate the dirname on the symbol obstack. */
1336 const char *comp_dir = buildsym_compunit->comp_dir.get ();
1337 COMPUNIT_DIRNAME (cu)
1338 = (const char *) obstack_copy0 (&objfile->objfile_obstack,
1339 comp_dir, strlen (comp_dir));
1342 /* Save the debug format string (if any) in the symtab. */
1343 COMPUNIT_DEBUGFORMAT (cu) = buildsym_compunit->debugformat;
1345 /* Similarly for the producer. */
1346 COMPUNIT_PRODUCER (cu) = buildsym_compunit->producer;
1348 COMPUNIT_BLOCKVECTOR (cu) = blockvector;
1350 struct block *b = BLOCKVECTOR_BLOCK (blockvector, GLOBAL_BLOCK);
1352 set_block_compunit_symtab (b, cu);
1355 COMPUNIT_BLOCK_LINE_SECTION (cu) = section;
1357 COMPUNIT_MACRO_TABLE (cu) = buildsym_compunit->release_macros ();
1359 /* Default any symbols without a specified symtab to the primary symtab. */
1363 /* The main source file's symtab. */
1364 symtab = COMPUNIT_FILETABS (cu);
1366 for (block_i = 0; block_i < BLOCKVECTOR_NBLOCKS (blockvector); block_i++)
1368 struct block *block = BLOCKVECTOR_BLOCK (blockvector, block_i);
1370 struct dict_iterator iter;
1372 /* Inlined functions may have symbols not in the global or
1373 static symbol lists. */
1374 if (BLOCK_FUNCTION (block) != NULL)
1375 if (symbol_symtab (BLOCK_FUNCTION (block)) == NULL)
1376 symbol_set_symtab (BLOCK_FUNCTION (block), symtab);
1378 /* Note that we only want to fix up symbols from the local
1379 blocks, not blocks coming from included symtabs. That is why
1380 we use ALL_DICT_SYMBOLS here and not ALL_BLOCK_SYMBOLS. */
1381 ALL_DICT_SYMBOLS (BLOCK_DICT (block), iter, sym)
1382 if (symbol_symtab (sym) == NULL)
1383 symbol_set_symtab (sym, symtab);
1387 add_compunit_symtab_to_objfile (cu);
1392 /* Implementation of the second part of end_symtab. Pass STATIC_BLOCK
1393 as value returned by end_symtab_get_static_block.
1395 SECTION is the same as for end_symtab: the section number
1396 (in objfile->section_offsets) of the blockvector and linetable.
1398 If EXPANDABLE is non-zero the GLOBAL_BLOCK dictionary is made
1401 struct compunit_symtab *
1402 end_symtab_from_static_block (struct block *static_block,
1403 int section, int expandable)
1405 struct compunit_symtab *cu;
1407 if (static_block == NULL)
1409 /* Handle the "no blockvector" case.
1410 When this happens there is nothing to record, so there's nothing
1411 to do: memory will be freed up later.
1413 Note: We won't be adding a compunit to the objfile's list of
1414 compunits, so there's nothing to unchain. However, since each symtab
1415 is added to the objfile's obstack we can't free that space.
1416 We could do better, but this is believed to be a sufficiently rare
1421 cu = end_symtab_with_blockvector (static_block, section, expandable);
1423 reset_symtab_globals ();
1428 /* Finish the symbol definitions for one main source file, close off
1429 all the lexical contexts for that file (creating struct block's for
1430 them), then make the struct symtab for that file and put it in the
1433 END_ADDR is the address of the end of the file's text. SECTION is
1434 the section number (in objfile->section_offsets) of the blockvector
1437 Note that it is possible for end_symtab() to return NULL. In
1438 particular, for the DWARF case at least, it will return NULL when
1439 it finds a compilation unit that has exactly one DIE, a
1440 TAG_compile_unit DIE. This can happen when we link in an object
1441 file that was compiled from an empty source file. Returning NULL
1442 is probably not the correct thing to do, because then gdb will
1443 never know about this empty file (FIXME).
1445 If you need to modify STATIC_BLOCK before it is finalized you should
1446 call end_symtab_get_static_block and end_symtab_from_static_block
1449 struct compunit_symtab *
1450 end_symtab (CORE_ADDR end_addr, int section)
1452 struct block *static_block;
1454 static_block = end_symtab_get_static_block (end_addr, 0, 0);
1455 return end_symtab_from_static_block (static_block, section, 0);
1458 /* Same as end_symtab except create a symtab that can be later added to. */
1460 struct compunit_symtab *
1461 end_expandable_symtab (CORE_ADDR end_addr, int section)
1463 struct block *static_block;
1465 static_block = end_symtab_get_static_block (end_addr, 1, 0);
1466 return end_symtab_from_static_block (static_block, section, 1);
1469 /* Subroutine of augment_type_symtab to simplify it.
1470 Attach the main source file's symtab to all symbols in PENDING_LIST that
1474 set_missing_symtab (struct pending *pending_list,
1475 struct compunit_symtab *cu)
1477 struct pending *pending;
1480 for (pending = pending_list; pending != NULL; pending = pending->next)
1482 for (i = 0; i < pending->nsyms; ++i)
1484 if (symbol_symtab (pending->symbol[i]) == NULL)
1485 symbol_set_symtab (pending->symbol[i], COMPUNIT_FILETABS (cu));
1490 /* Same as end_symtab, but for the case where we're adding more symbols
1491 to an existing symtab that is known to contain only type information.
1492 This is the case for DWARF4 Type Units. */
1495 augment_type_symtab (void)
1497 struct compunit_symtab *cust = buildsym_compunit->compunit_symtab;
1498 const struct blockvector *blockvector = COMPUNIT_BLOCKVECTOR (cust);
1500 if (!buildsym_compunit->m_context_stack.empty ())
1501 complaint (_("Context stack not empty in augment_type_symtab"));
1502 if (buildsym_compunit->m_pending_blocks != NULL)
1503 complaint (_("Blocks in a type symtab"));
1504 if (buildsym_compunit->m_pending_macros != NULL)
1505 complaint (_("Macro in a type symtab"));
1506 if (buildsym_compunit->m_have_line_numbers)
1507 complaint (_("Line numbers recorded in a type symtab"));
1509 if (buildsym_compunit->m_file_symbols != NULL)
1511 struct block *block = BLOCKVECTOR_BLOCK (blockvector, STATIC_BLOCK);
1513 /* First mark any symbols without a specified symtab as belonging
1514 to the primary symtab. */
1515 set_missing_symtab (buildsym_compunit->m_file_symbols, cust);
1517 dict_add_pending (BLOCK_DICT (block), buildsym_compunit->m_file_symbols);
1520 if (buildsym_compunit->m_global_symbols != NULL)
1522 struct block *block = BLOCKVECTOR_BLOCK (blockvector, GLOBAL_BLOCK);
1524 /* First mark any symbols without a specified symtab as belonging
1525 to the primary symtab. */
1526 set_missing_symtab (buildsym_compunit->m_global_symbols, cust);
1528 dict_add_pending (BLOCK_DICT (block),
1529 buildsym_compunit->m_global_symbols);
1532 reset_symtab_globals ();
1535 /* Push a context block. Args are an identifying nesting level
1536 (checkable when you pop it), and the starting PC address of this
1539 struct context_stack *
1540 push_context (int desc, CORE_ADDR valu)
1542 gdb_assert (buildsym_compunit != nullptr);
1544 buildsym_compunit->m_context_stack.emplace_back ();
1545 struct context_stack *newobj = &buildsym_compunit->m_context_stack.back ();
1547 newobj->depth = desc;
1548 newobj->locals = buildsym_compunit->m_local_symbols;
1549 newobj->old_blocks = buildsym_compunit->m_pending_blocks;
1550 newobj->start_addr = valu;
1551 newobj->local_using_directives
1552 = buildsym_compunit->m_local_using_directives;
1553 newobj->name = NULL;
1555 buildsym_compunit->m_local_symbols = NULL;
1556 buildsym_compunit->m_local_using_directives = NULL;
1561 /* Pop a context block. Returns the address of the context block just
1564 struct context_stack
1567 gdb_assert (buildsym_compunit != nullptr);
1568 gdb_assert (!buildsym_compunit->m_context_stack.empty ());
1569 struct context_stack result = buildsym_compunit->m_context_stack.back ();
1570 buildsym_compunit->m_context_stack.pop_back ();
1577 record_debugformat (const char *format)
1579 buildsym_compunit->debugformat = format;
1583 record_producer (const char *producer)
1585 buildsym_compunit->producer = producer;
1590 /* See buildsym.h. */
1593 set_last_source_file (const char *name)
1595 gdb_assert (buildsym_compunit != nullptr || name == nullptr);
1596 if (buildsym_compunit != nullptr)
1597 buildsym_compunit->set_last_source_file (name);
1600 /* See buildsym.h. */
1603 get_last_source_file (void)
1605 if (buildsym_compunit == nullptr)
1607 return buildsym_compunit->m_last_source_file.get ();
1610 /* See buildsym.h. */
1613 set_last_source_start_addr (CORE_ADDR addr)
1615 gdb_assert (buildsym_compunit != nullptr);
1616 buildsym_compunit->m_last_source_start_addr = addr;
1619 /* See buildsym.h. */
1622 get_last_source_start_addr ()
1624 gdb_assert (buildsym_compunit != nullptr);
1625 return buildsym_compunit->m_last_source_start_addr;
1628 /* See buildsym.h. */
1630 struct using_direct **
1631 get_local_using_directives ()
1633 gdb_assert (buildsym_compunit != nullptr);
1634 return &buildsym_compunit->m_local_using_directives;
1637 /* See buildsym.h. */
1640 set_local_using_directives (struct using_direct *new_local)
1642 gdb_assert (buildsym_compunit != nullptr);
1643 buildsym_compunit->m_local_using_directives = new_local;
1646 /* See buildsym.h. */
1648 struct using_direct **
1649 get_global_using_directives ()
1651 gdb_assert (buildsym_compunit != nullptr);
1652 return &buildsym_compunit->m_global_using_directives;
1655 /* See buildsym.h. */
1658 outermost_context_p ()
1660 gdb_assert (buildsym_compunit != nullptr);
1661 return buildsym_compunit->m_context_stack.empty ();
1664 /* See buildsym.h. */
1666 struct context_stack *
1667 get_current_context_stack ()
1669 gdb_assert (buildsym_compunit != nullptr);
1670 if (buildsym_compunit->m_context_stack.empty ())
1672 return &buildsym_compunit->m_context_stack.back ();
1675 /* See buildsym.h. */
1678 get_context_stack_depth ()
1680 gdb_assert (buildsym_compunit != nullptr);
1681 return buildsym_compunit->m_context_stack.size ();
1684 /* See buildsym.h. */
1687 get_current_subfile ()
1689 gdb_assert (buildsym_compunit != nullptr);
1690 return buildsym_compunit->m_current_subfile;
1693 /* See buildsym.h. */
1696 get_local_symbols ()
1698 gdb_assert (buildsym_compunit != nullptr);
1699 return &buildsym_compunit->m_local_symbols;
1702 /* See buildsym.h. */
1707 gdb_assert (buildsym_compunit != nullptr);
1708 return &buildsym_compunit->m_file_symbols;
1711 /* See buildsym.h. */
1714 get_global_symbols ()
1716 gdb_assert (buildsym_compunit != nullptr);
1717 return &buildsym_compunit->m_global_symbols;