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 ...
66 #include "gdb_obstack.h"
71 #include "complaints.h"
72 #include "expression.h" /* For "enum exp_opcode" used by... */
73 #include "filenames.h" /* For DOSish file names. */
75 #include "demangle.h" /* Needed by SYMBOL_INIT_DEMANGLED_NAME. */
77 #include "cp-support.h"
78 #include "dictionary.h"
82 /* Ask buildsym.h to define the vars it normally declares `extern'. */
85 #include "buildsym.h" /* Our own declarations. */
88 /* For cleanup_undefined_stabs_types and finish_global_stabs (somewhat
89 questionable--see comment where we call them). */
91 #include "stabsread.h"
93 /* Buildsym's counterpart to struct compunit_symtab. */
95 struct buildsym_compunit
97 /* Start recording information about a primary source file (IOW, not an
98 included source file).
99 COMP_DIR is the directory in which the compilation unit was compiled
100 (or NULL if not known). */
102 buildsym_compunit (struct objfile *objfile_, const char *name,
103 const char *comp_dir_, enum language language_,
105 : objfile (objfile_),
106 m_last_source_file (name == nullptr ? nullptr : xstrdup (name)),
107 comp_dir (comp_dir_ == nullptr ? nullptr : xstrdup (comp_dir_)),
108 language (language_),
109 m_last_source_start_addr (last_addr)
113 ~buildsym_compunit ()
115 struct subfile *subfile, *nextsub;
117 if (m_pending_macros != nullptr)
118 free_macro_table (m_pending_macros);
120 for (subfile = subfiles;
124 nextsub = subfile->next;
125 xfree (subfile->name);
126 xfree (subfile->line_vector);
130 struct pending *next, *next1;
132 for (next = m_file_symbols; next != NULL; next = next1)
135 xfree ((void *) next);
138 for (next = m_global_symbols; next != NULL; next = next1)
141 xfree ((void *) next);
145 void set_last_source_file (const char *name)
147 char *new_name = name == NULL ? NULL : xstrdup (name);
148 m_last_source_file.reset (new_name);
151 struct macro_table *get_macro_table ()
153 if (m_pending_macros == nullptr)
154 m_pending_macros = new_macro_table (&objfile->per_bfd->storage_obstack,
155 objfile->per_bfd->macro_cache,
157 return m_pending_macros;
160 struct macro_table *release_macros ()
162 struct macro_table *result = m_pending_macros;
163 m_pending_macros = nullptr;
167 /* This function is called to discard any pending blocks. */
169 void free_pending_blocks ()
171 m_pending_block_obstack.clear ();
172 m_pending_blocks = nullptr;
175 /* The objfile we're reading debug info from. */
176 struct objfile *objfile;
178 /* List of subfiles (source files).
179 Files are added to the front of the list.
180 This is important mostly for the language determination hacks we use,
181 which iterate over previously added files. */
182 struct subfile *subfiles = nullptr;
184 /* The subfile of the main source file. */
185 struct subfile *main_subfile = nullptr;
187 /* Name of source file whose symbol data we are now processing. This
188 comes from a symbol of type N_SO for stabs. For DWARF it comes
189 from the DW_AT_name attribute of a DW_TAG_compile_unit DIE. */
190 gdb::unique_xmalloc_ptr<char> m_last_source_file;
192 /* E.g., DW_AT_comp_dir if DWARF. Space for this is malloc'd. */
193 gdb::unique_xmalloc_ptr<char> comp_dir;
195 /* Space for this is not malloc'd, and is assumed to have at least
196 the same lifetime as objfile. */
197 const char *producer = nullptr;
199 /* Space for this is not malloc'd, and is assumed to have at least
200 the same lifetime as objfile. */
201 const char *debugformat = nullptr;
203 /* The compunit we are building. */
204 struct compunit_symtab *compunit_symtab = nullptr;
206 /* Language of this compunit_symtab. */
207 enum language language;
209 /* The macro table for the compilation unit whose symbols we're
210 currently reading. */
211 struct macro_table *m_pending_macros = nullptr;
213 /* True if symtab has line number info. This prevents an otherwise
214 empty symtab from being tossed. */
215 bool m_have_line_numbers = false;
217 /* Core address of start of text of current source file. This too
218 comes from the N_SO symbol. For Dwarf it typically comes from the
219 DW_AT_low_pc attribute of a DW_TAG_compile_unit DIE. */
220 CORE_ADDR m_last_source_start_addr;
222 /* Stack of subfile names. */
223 std::vector<const char *> m_subfile_stack;
225 /* The "using" directives local to lexical context. */
226 struct using_direct *m_local_using_directives = nullptr;
228 /* Global "using" directives. */
229 struct using_direct *m_global_using_directives = nullptr;
231 /* The stack of contexts that are pushed by push_context and popped
233 std::vector<struct context_stack> m_context_stack;
235 struct subfile *m_current_subfile = nullptr;
237 /* The mutable address map for the compilation unit whose symbols
238 we're currently reading. The symtabs' shared blockvector will
239 point to a fixed copy of this. */
240 struct addrmap *m_pending_addrmap = nullptr;
242 /* The obstack on which we allocate pending_addrmap.
243 If pending_addrmap is NULL, this is uninitialized; otherwise, it is
244 initialized (and holds pending_addrmap). */
245 auto_obstack m_pending_addrmap_obstack;
247 /* True if we recorded any ranges in the addrmap that are different
248 from those in the blockvector already. We set this to false when
249 we start processing a symfile, and if it's still false at the
250 end, then we just toss the addrmap. */
251 bool m_pending_addrmap_interesting = false;
253 /* An obstack used for allocating pending blocks. */
254 auto_obstack m_pending_block_obstack;
256 /* Pointer to the head of a linked list of symbol blocks which have
257 already been finalized (lexical contexts already closed) and which
258 are just waiting to be built into a blockvector when finalizing the
259 associated symtab. */
260 struct pending_block *m_pending_blocks = nullptr;
262 /* Pending static symbols and types at the top level. */
263 struct pending *m_file_symbols = nullptr;
265 /* Pending global functions and variables. */
266 struct pending *m_global_symbols = nullptr;
268 /* Pending symbols that are local to the lexical context. */
269 struct pending *m_local_symbols = nullptr;
272 /* The work-in-progress of the compunit we are building.
273 This is created first, before any subfiles by start_symtab. */
275 static struct buildsym_compunit *buildsym_compunit;
277 /* List of blocks already made (lexical contexts already closed).
278 This is used at the end to make the blockvector. */
282 struct pending_block *next;
286 static void free_buildsym_compunit (void);
288 static int compare_line_numbers (const void *ln1p, const void *ln2p);
290 static void record_pending_block (struct objfile *objfile,
292 struct pending_block *opblock);
294 /* Initial sizes of data structures. These are realloc'd larger if
295 needed, and realloc'd down to the size actually used, when
298 #define INITIAL_LINE_VECTOR_LENGTH 1000
301 /* Maintain the lists of symbols and blocks. */
303 /* Add a symbol to one of the lists of symbols. */
306 add_symbol_to_list (struct symbol *symbol, struct pending **listhead)
308 struct pending *link;
310 /* If this is an alias for another symbol, don't add it. */
311 if (symbol->ginfo.name && symbol->ginfo.name[0] == '#')
314 /* We keep PENDINGSIZE symbols in each link of the list. If we
315 don't have a link with room in it, add a new link. */
316 if (*listhead == NULL || (*listhead)->nsyms == PENDINGSIZE)
318 link = XNEW (struct pending);
319 link->next = *listhead;
324 (*listhead)->symbol[(*listhead)->nsyms++] = symbol;
327 /* Find a symbol named NAME on a LIST. NAME need not be
328 '\0'-terminated; LENGTH is the length of the name. */
331 find_symbol_in_list (struct pending *list, char *name, int length)
338 for (j = list->nsyms; --j >= 0;)
340 pp = SYMBOL_LINKAGE_NAME (list->symbol[j]);
341 if (*pp == *name && strncmp (pp, name, length) == 0
342 && pp[length] == '\0')
344 return (list->symbol[j]);
352 /* At end of reading syms, or in case of quit, ensure everything
353 associated with building symtabs is freed.
355 N.B. This is *not* intended to be used when building psymtabs. Some debug
356 info readers call this anyway, which is harmless if confusing. */
358 scoped_free_pendings::~scoped_free_pendings ()
360 free_buildsym_compunit ();
363 /* Take one of the lists of symbols and make a block from it. Keep
364 the order the symbols have in the list (reversed from the input
365 file). Put the block on the list of pending blocks. */
367 static struct block *
368 finish_block_internal (struct symbol *symbol,
369 struct pending **listhead,
370 struct pending_block *old_blocks,
371 const struct dynamic_prop *static_link,
372 CORE_ADDR start, CORE_ADDR end,
373 int is_global, int expandable)
375 struct objfile *objfile = buildsym_compunit->objfile;
376 struct gdbarch *gdbarch = get_objfile_arch (objfile);
377 struct pending *next, *next1;
379 struct pending_block *pblock;
380 struct pending_block *opblock;
383 ? allocate_global_block (&objfile->objfile_obstack)
384 : allocate_block (&objfile->objfile_obstack));
389 = dict_create_linear (&objfile->objfile_obstack,
390 buildsym_compunit->language, *listhead);
397 = dict_create_hashed_expandable (buildsym_compunit->language);
398 dict_add_pending (BLOCK_DICT (block), *listhead);
403 dict_create_hashed (&objfile->objfile_obstack,
404 buildsym_compunit->language, *listhead);
408 BLOCK_START (block) = start;
409 BLOCK_END (block) = end;
411 /* Put the block in as the value of the symbol that names it. */
415 struct type *ftype = SYMBOL_TYPE (symbol);
416 struct dict_iterator iter;
417 SYMBOL_BLOCK_VALUE (symbol) = block;
418 BLOCK_FUNCTION (block) = symbol;
420 if (TYPE_NFIELDS (ftype) <= 0)
422 /* No parameter type information is recorded with the
423 function's type. Set that from the type of the
424 parameter symbols. */
425 int nparams = 0, iparams;
428 /* Here we want to directly access the dictionary, because
429 we haven't fully initialized the block yet. */
430 ALL_DICT_SYMBOLS (BLOCK_DICT (block), iter, sym)
432 if (SYMBOL_IS_ARGUMENT (sym))
437 TYPE_NFIELDS (ftype) = nparams;
438 TYPE_FIELDS (ftype) = (struct field *)
439 TYPE_ALLOC (ftype, nparams * sizeof (struct field));
442 /* Here we want to directly access the dictionary, because
443 we haven't fully initialized the block yet. */
444 ALL_DICT_SYMBOLS (BLOCK_DICT (block), iter, sym)
446 if (iparams == nparams)
449 if (SYMBOL_IS_ARGUMENT (sym))
451 TYPE_FIELD_TYPE (ftype, iparams) = SYMBOL_TYPE (sym);
452 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0;
461 BLOCK_FUNCTION (block) = NULL;
464 if (static_link != NULL)
465 objfile_register_static_link (objfile, block, static_link);
467 /* Now free the links of the list, and empty the list. */
469 for (next = *listhead; next; next = next1)
476 /* Check to be sure that the blocks have an end address that is
477 greater than starting address. */
479 if (BLOCK_END (block) < BLOCK_START (block))
483 complaint (_("block end address less than block "
484 "start address in %s (patched it)"),
485 SYMBOL_PRINT_NAME (symbol));
489 complaint (_("block end address %s less than block "
490 "start address %s (patched it)"),
491 paddress (gdbarch, BLOCK_END (block)),
492 paddress (gdbarch, BLOCK_START (block)));
494 /* Better than nothing. */
495 BLOCK_END (block) = BLOCK_START (block);
498 /* Install this block as the superblock of all blocks made since the
499 start of this scope that don't have superblocks yet. */
502 for (pblock = buildsym_compunit->m_pending_blocks;
503 pblock && pblock != old_blocks;
504 pblock = pblock->next)
506 if (BLOCK_SUPERBLOCK (pblock->block) == NULL)
508 /* Check to be sure the blocks are nested as we receive
509 them. If the compiler/assembler/linker work, this just
510 burns a small amount of time.
512 Skip blocks which correspond to a function; they're not
513 physically nested inside this other blocks, only
515 if (BLOCK_FUNCTION (pblock->block) == NULL
516 && (BLOCK_START (pblock->block) < BLOCK_START (block)
517 || BLOCK_END (pblock->block) > BLOCK_END (block)))
521 complaint (_("inner block not inside outer block in %s"),
522 SYMBOL_PRINT_NAME (symbol));
526 complaint (_("inner block (%s-%s) not "
527 "inside outer block (%s-%s)"),
528 paddress (gdbarch, BLOCK_START (pblock->block)),
529 paddress (gdbarch, BLOCK_END (pblock->block)),
530 paddress (gdbarch, BLOCK_START (block)),
531 paddress (gdbarch, BLOCK_END (block)));
533 if (BLOCK_START (pblock->block) < BLOCK_START (block))
534 BLOCK_START (pblock->block) = BLOCK_START (block);
535 if (BLOCK_END (pblock->block) > BLOCK_END (block))
536 BLOCK_END (pblock->block) = BLOCK_END (block);
538 BLOCK_SUPERBLOCK (pblock->block) = block;
543 block_set_using (block,
545 ? buildsym_compunit->m_global_using_directives
546 : buildsym_compunit->m_local_using_directives),
547 &objfile->objfile_obstack);
549 buildsym_compunit->m_global_using_directives = NULL;
551 buildsym_compunit->m_local_using_directives = NULL;
553 record_pending_block (objfile, block, opblock);
559 finish_block (struct symbol *symbol,
560 struct pending_block *old_blocks,
561 const struct dynamic_prop *static_link,
562 CORE_ADDR start, CORE_ADDR end)
564 return finish_block_internal (symbol, &buildsym_compunit->m_local_symbols,
565 old_blocks, static_link,
569 /* Record BLOCK on the list of all blocks in the file. Put it after
570 OPBLOCK, or at the beginning if opblock is NULL. This puts the
571 block in the list after all its subblocks.
573 Allocate the pending block struct in the objfile_obstack to save
574 time. This wastes a little space. FIXME: Is it worth it? */
577 record_pending_block (struct objfile *objfile, struct block *block,
578 struct pending_block *opblock)
580 struct pending_block *pblock;
582 pblock = XOBNEW (&buildsym_compunit->m_pending_block_obstack,
583 struct pending_block);
584 pblock->block = block;
587 pblock->next = opblock->next;
588 opblock->next = pblock;
592 pblock->next = buildsym_compunit->m_pending_blocks;
593 buildsym_compunit->m_pending_blocks = pblock;
598 /* Record that the range of addresses from START to END_INCLUSIVE
599 (inclusive, like it says) belongs to BLOCK. BLOCK's start and end
600 addresses must be set already. You must apply this function to all
601 BLOCK's children before applying it to BLOCK.
603 If a call to this function complicates the picture beyond that
604 already provided by BLOCK_START and BLOCK_END, then we create an
605 address map for the block. */
607 record_block_range (struct block *block,
608 CORE_ADDR start, CORE_ADDR end_inclusive)
610 /* If this is any different from the range recorded in the block's
611 own BLOCK_START and BLOCK_END, then note that the address map has
612 become interesting. Note that even if this block doesn't have
613 any "interesting" ranges, some later block might, so we still
614 need to record this block in the addrmap. */
615 if (start != BLOCK_START (block)
616 || end_inclusive + 1 != BLOCK_END (block))
617 buildsym_compunit->m_pending_addrmap_interesting = true;
619 if (buildsym_compunit->m_pending_addrmap == nullptr)
620 buildsym_compunit->m_pending_addrmap
621 = addrmap_create_mutable (&buildsym_compunit->m_pending_addrmap_obstack);
623 addrmap_set_empty (buildsym_compunit->m_pending_addrmap,
624 start, end_inclusive, block);
627 static struct blockvector *
628 make_blockvector (void)
630 struct objfile *objfile = buildsym_compunit->objfile;
631 struct pending_block *next;
632 struct blockvector *blockvector;
635 /* Count the length of the list of blocks. */
637 for (next = buildsym_compunit->m_pending_blocks, i = 0;
639 next = next->next, i++)
643 blockvector = (struct blockvector *)
644 obstack_alloc (&objfile->objfile_obstack,
645 (sizeof (struct blockvector)
646 + (i - 1) * sizeof (struct block *)));
648 /* Copy the blocks into the blockvector. This is done in reverse
649 order, which happens to put the blocks into the proper order
650 (ascending starting address). finish_block has hair to insert
651 each block into the list after its subblocks in order to make
652 sure this is true. */
654 BLOCKVECTOR_NBLOCKS (blockvector) = i;
655 for (next = buildsym_compunit->m_pending_blocks; next; next = next->next)
657 BLOCKVECTOR_BLOCK (blockvector, --i) = next->block;
660 buildsym_compunit->free_pending_blocks ();
662 /* If we needed an address map for this symtab, record it in the
664 if (buildsym_compunit->m_pending_addrmap != nullptr
665 && buildsym_compunit->m_pending_addrmap_interesting)
666 BLOCKVECTOR_MAP (blockvector)
667 = addrmap_create_fixed (buildsym_compunit->m_pending_addrmap,
668 &objfile->objfile_obstack);
670 BLOCKVECTOR_MAP (blockvector) = 0;
672 /* Some compilers output blocks in the wrong order, but we depend on
673 their being in the right order so we can binary search. Check the
674 order and moan about it.
675 Note: Remember that the first two blocks are the global and static
676 blocks. We could special case that fact and begin checking at block 2.
677 To avoid making that assumption we do not. */
678 if (BLOCKVECTOR_NBLOCKS (blockvector) > 1)
680 for (i = 1; i < BLOCKVECTOR_NBLOCKS (blockvector); i++)
682 if (BLOCK_START (BLOCKVECTOR_BLOCK (blockvector, i - 1))
683 > BLOCK_START (BLOCKVECTOR_BLOCK (blockvector, i)))
686 = BLOCK_START (BLOCKVECTOR_BLOCK (blockvector, i));
688 complaint (_("block at %s out of order"),
689 hex_string ((LONGEST) start));
694 return (blockvector);
697 /* Start recording information about source code that came from an
698 included (or otherwise merged-in) source file with a different
699 name. NAME is the name of the file (cannot be NULL). */
702 start_subfile (const char *name)
704 const char *subfile_dirname;
705 struct subfile *subfile;
707 gdb_assert (buildsym_compunit != NULL);
709 subfile_dirname = buildsym_compunit->comp_dir.get ();
711 /* See if this subfile is already registered. */
713 for (subfile = buildsym_compunit->subfiles; subfile; subfile = subfile->next)
717 /* If NAME is an absolute path, and this subfile is not, then
718 attempt to create an absolute path to compare. */
719 if (IS_ABSOLUTE_PATH (name)
720 && !IS_ABSOLUTE_PATH (subfile->name)
721 && subfile_dirname != NULL)
722 subfile_name = concat (subfile_dirname, SLASH_STRING,
723 subfile->name, (char *) NULL);
725 subfile_name = subfile->name;
727 if (FILENAME_CMP (subfile_name, name) == 0)
729 buildsym_compunit->m_current_subfile = subfile;
730 if (subfile_name != subfile->name)
731 xfree (subfile_name);
734 if (subfile_name != subfile->name)
735 xfree (subfile_name);
738 /* This subfile is not known. Add an entry for it. */
740 subfile = XNEW (struct subfile);
741 memset (subfile, 0, sizeof (struct subfile));
742 subfile->buildsym_compunit = buildsym_compunit;
744 subfile->next = buildsym_compunit->subfiles;
745 buildsym_compunit->subfiles = subfile;
747 buildsym_compunit->m_current_subfile = subfile;
749 subfile->name = xstrdup (name);
751 /* Initialize line-number recording for this subfile. */
752 subfile->line_vector = NULL;
754 /* Default the source language to whatever can be deduced from the
755 filename. If nothing can be deduced (such as for a C/C++ include
756 file with a ".h" extension), then inherit whatever language the
757 previous subfile had. This kludgery is necessary because there
758 is no standard way in some object formats to record the source
759 language. Also, when symtabs are allocated we try to deduce a
760 language then as well, but it is too late for us to use that
761 information while reading symbols, since symtabs aren't allocated
762 until after all the symbols have been processed for a given
765 subfile->language = deduce_language_from_filename (subfile->name);
766 if (subfile->language == language_unknown
767 && subfile->next != NULL)
769 subfile->language = subfile->next->language;
772 /* If the filename of this subfile ends in .C, then change the
773 language of any pending subfiles from C to C++. We also accept
774 any other C++ suffixes accepted by deduce_language_from_filename. */
775 /* Likewise for f2c. */
780 enum language sublang = deduce_language_from_filename (subfile->name);
782 if (sublang == language_cplus || sublang == language_fortran)
783 for (s = buildsym_compunit->subfiles; s != NULL; s = s->next)
784 if (s->language == language_c)
785 s->language = sublang;
788 /* And patch up this file if necessary. */
789 if (subfile->language == language_c
790 && subfile->next != NULL
791 && (subfile->next->language == language_cplus
792 || subfile->next->language == language_fortran))
794 subfile->language = subfile->next->language;
798 /* Delete the buildsym compunit. */
801 free_buildsym_compunit (void)
803 if (buildsym_compunit == NULL)
805 delete buildsym_compunit;
806 buildsym_compunit = NULL;
809 /* For stabs readers, the first N_SO symbol is assumed to be the
810 source file name, and the subfile struct is initialized using that
811 assumption. If another N_SO symbol is later seen, immediately
812 following the first one, then the first one is assumed to be the
813 directory name and the second one is really the source file name.
815 So we have to patch up the subfile struct by moving the old name
816 value to dirname and remembering the new name. Some sanity
817 checking is performed to ensure that the state of the subfile
818 struct is reasonable and that the old name we are assuming to be a
819 directory name actually is (by checking for a trailing '/'). */
822 patch_subfile_names (struct subfile *subfile, const char *name)
825 && buildsym_compunit->comp_dir == NULL
826 && subfile->name != NULL
827 && IS_DIR_SEPARATOR (subfile->name[strlen (subfile->name) - 1]))
829 buildsym_compunit->comp_dir.reset (subfile->name);
830 subfile->name = xstrdup (name);
831 set_last_source_file (name);
833 /* Default the source language to whatever can be deduced from
834 the filename. If nothing can be deduced (such as for a C/C++
835 include file with a ".h" extension), then inherit whatever
836 language the previous subfile had. This kludgery is
837 necessary because there is no standard way in some object
838 formats to record the source language. Also, when symtabs
839 are allocated we try to deduce a language then as well, but
840 it is too late for us to use that information while reading
841 symbols, since symtabs aren't allocated until after all the
842 symbols have been processed for a given source file. */
844 subfile->language = deduce_language_from_filename (subfile->name);
845 if (subfile->language == language_unknown
846 && subfile->next != NULL)
848 subfile->language = subfile->next->language;
853 /* Handle the N_BINCL and N_EINCL symbol types that act like N_SOL for
854 switching source files (different subfiles, as we call them) within
855 one object file, but using a stack rather than in an arbitrary
861 gdb_assert (buildsym_compunit != nullptr);
862 gdb_assert (buildsym_compunit->m_current_subfile != NULL);
863 gdb_assert (buildsym_compunit->m_current_subfile->name != NULL);
864 buildsym_compunit->m_subfile_stack.push_back
865 (buildsym_compunit->m_current_subfile->name);
871 gdb_assert (buildsym_compunit != nullptr);
872 gdb_assert (!buildsym_compunit->m_subfile_stack.empty ());
873 const char *name = buildsym_compunit->m_subfile_stack.back ();
874 buildsym_compunit->m_subfile_stack.pop_back ();
878 /* Add a linetable entry for line number LINE and address PC to the
879 line vector for SUBFILE. */
882 record_line (struct subfile *subfile, int line, CORE_ADDR pc)
884 struct linetable_entry *e;
886 /* Ignore the dummy line number in libg.o */
892 /* Make sure line vector exists and is big enough. */
893 if (!subfile->line_vector)
895 subfile->line_vector_length = INITIAL_LINE_VECTOR_LENGTH;
896 subfile->line_vector = (struct linetable *)
897 xmalloc (sizeof (struct linetable)
898 + subfile->line_vector_length * sizeof (struct linetable_entry));
899 subfile->line_vector->nitems = 0;
900 buildsym_compunit->m_have_line_numbers = true;
903 if (subfile->line_vector->nitems + 1 >= subfile->line_vector_length)
905 subfile->line_vector_length *= 2;
906 subfile->line_vector = (struct linetable *)
907 xrealloc ((char *) subfile->line_vector,
908 (sizeof (struct linetable)
909 + (subfile->line_vector_length
910 * sizeof (struct linetable_entry))));
913 /* Normally, we treat lines as unsorted. But the end of sequence
914 marker is special. We sort line markers at the same PC by line
915 number, so end of sequence markers (which have line == 0) appear
916 first. This is right if the marker ends the previous function,
917 and there is no padding before the next function. But it is
918 wrong if the previous line was empty and we are now marking a
919 switch to a different subfile. We must leave the end of sequence
920 marker at the end of this group of lines, not sort the empty line
921 to after the marker. The easiest way to accomplish this is to
922 delete any empty lines from our table, if they are followed by
923 end of sequence markers. All we lose is the ability to set
924 breakpoints at some lines which contain no instructions
926 if (line == 0 && subfile->line_vector->nitems > 0)
928 e = subfile->line_vector->item + subfile->line_vector->nitems - 1;
929 while (subfile->line_vector->nitems > 0 && e->pc == pc)
932 subfile->line_vector->nitems--;
936 e = subfile->line_vector->item + subfile->line_vector->nitems++;
941 /* Needed in order to sort line tables from IBM xcoff files. Sigh! */
944 compare_line_numbers (const void *ln1p, const void *ln2p)
946 struct linetable_entry *ln1 = (struct linetable_entry *) ln1p;
947 struct linetable_entry *ln2 = (struct linetable_entry *) ln2p;
949 /* Note: this code does not assume that CORE_ADDRs can fit in ints.
950 Please keep it that way. */
951 if (ln1->pc < ln2->pc)
954 if (ln1->pc > ln2->pc)
957 /* If pc equal, sort by line. I'm not sure whether this is optimum
958 behavior (see comment at struct linetable in symtab.h). */
959 return ln1->line - ln2->line;
962 /* See buildsym.h. */
964 struct compunit_symtab *
965 buildsym_compunit_symtab (void)
967 gdb_assert (buildsym_compunit != NULL);
969 return buildsym_compunit->compunit_symtab;
972 /* See buildsym.h. */
975 get_macro_table (void)
977 struct objfile *objfile;
979 gdb_assert (buildsym_compunit != NULL);
980 return buildsym_compunit->get_macro_table ();
983 /* Start a new symtab for a new source file in OBJFILE. Called, for example,
984 when a stabs symbol of type N_SO is seen, or when a DWARF
985 TAG_compile_unit DIE is seen. It indicates the start of data for
986 one original source file.
988 NAME is the name of the file (cannot be NULL). COMP_DIR is the
989 directory in which the file was compiled (or NULL if not known).
990 START_ADDR is the lowest address of objects in the file (or 0 if
991 not known). LANGUAGE is the language of the source file, or
992 language_unknown if not known, in which case it'll be deduced from
995 struct compunit_symtab *
996 start_symtab (struct objfile *objfile, const char *name, const char *comp_dir,
997 CORE_ADDR start_addr, enum language language)
999 /* These should have been reset either by successful completion of building
1000 a symtab, or by the scoped_free_pendings destructor. */
1001 gdb_assert (buildsym_compunit == nullptr);
1003 buildsym_compunit = new struct buildsym_compunit (objfile, name, comp_dir,
1004 language, start_addr);
1006 /* Allocate the compunit symtab now. The caller needs it to allocate
1007 non-primary symtabs. It is also needed by get_macro_table. */
1008 buildsym_compunit->compunit_symtab = allocate_compunit_symtab (objfile,
1011 /* Build the subfile for NAME (the main source file) so that we can record
1012 a pointer to it for later.
1013 IMPORTANT: Do not allocate a struct symtab for NAME here.
1014 It can happen that the debug info provides a different path to NAME than
1015 DIRNAME,NAME. We cope with this in watch_main_source_file_lossage but
1016 that only works if the main_subfile doesn't have a symtab yet. */
1017 start_subfile (name);
1018 /* Save this so that we don't have to go looking for it at the end
1019 of the subfiles list. */
1020 buildsym_compunit->main_subfile = buildsym_compunit->m_current_subfile;
1022 return buildsym_compunit->compunit_symtab;
1025 /* Restart compilation for a symtab.
1026 CUST is the result of end_expandable_symtab.
1027 NAME, START_ADDR are the source file we are resuming with.
1029 This is used when a symtab is built from multiple sources.
1030 The symtab is first built with start_symtab/end_expandable_symtab
1031 and then for each additional piece call restart_symtab/augment_*_symtab.
1032 Note: At the moment there is only augment_type_symtab. */
1035 restart_symtab (struct compunit_symtab *cust,
1036 const char *name, CORE_ADDR start_addr)
1038 /* These should have been reset either by successful completion of building
1039 a symtab, or by the scoped_free_pendings destructor. */
1040 gdb_assert (buildsym_compunit == nullptr);
1043 = new struct buildsym_compunit (COMPUNIT_OBJFILE (cust),
1045 COMPUNIT_DIRNAME (cust),
1046 compunit_language (cust),
1048 buildsym_compunit->compunit_symtab = cust;
1051 /* Subroutine of end_symtab to simplify it. Look for a subfile that
1052 matches the main source file's basename. If there is only one, and
1053 if the main source file doesn't have any symbol or line number
1054 information, then copy this file's symtab and line_vector to the
1055 main source file's subfile and discard the other subfile. This can
1056 happen because of a compiler bug or from the user playing games
1057 with #line or from things like a distributed build system that
1058 manipulates the debug info. This can also happen from an innocent
1059 symlink in the paths, we don't canonicalize paths here. */
1062 watch_main_source_file_lossage (void)
1064 struct subfile *mainsub, *subfile;
1066 /* We have to watch for buildsym_compunit == NULL here. It's a quirk of
1067 end_symtab, it can return NULL so there may not be a main subfile. */
1068 if (buildsym_compunit == NULL)
1071 /* Get the main source file. */
1072 mainsub = buildsym_compunit->main_subfile;
1074 /* If the main source file doesn't have any line number or symbol
1075 info, look for an alias in another subfile. */
1077 if (mainsub->line_vector == NULL
1078 && mainsub->symtab == NULL)
1080 const char *mainbase = lbasename (mainsub->name);
1082 struct subfile *prevsub;
1083 struct subfile *mainsub_alias = NULL;
1084 struct subfile *prev_mainsub_alias = NULL;
1087 for (subfile = buildsym_compunit->subfiles;
1089 subfile = subfile->next)
1091 if (subfile == mainsub)
1093 if (filename_cmp (lbasename (subfile->name), mainbase) == 0)
1096 mainsub_alias = subfile;
1097 prev_mainsub_alias = prevsub;
1102 if (nr_matches == 1)
1104 gdb_assert (mainsub_alias != NULL && mainsub_alias != mainsub);
1106 /* Found a match for the main source file.
1107 Copy its line_vector and symtab to the main subfile
1108 and then discard it. */
1110 mainsub->line_vector = mainsub_alias->line_vector;
1111 mainsub->line_vector_length = mainsub_alias->line_vector_length;
1112 mainsub->symtab = mainsub_alias->symtab;
1114 if (prev_mainsub_alias == NULL)
1115 buildsym_compunit->subfiles = mainsub_alias->next;
1117 prev_mainsub_alias->next = mainsub_alias->next;
1118 xfree (mainsub_alias->name);
1119 xfree (mainsub_alias);
1124 /* Reset state after a successful building of a symtab. */
1127 reset_symtab_globals (void)
1129 free_buildsym_compunit ();
1132 /* Implementation of the first part of end_symtab. It allows modifying
1133 STATIC_BLOCK before it gets finalized by end_symtab_from_static_block.
1134 If the returned value is NULL there is no blockvector created for
1135 this symtab (you still must call end_symtab_from_static_block).
1137 END_ADDR is the same as for end_symtab: the address of the end of the
1140 If EXPANDABLE is non-zero the STATIC_BLOCK dictionary is made
1143 If REQUIRED is non-zero, then a symtab is created even if it does
1144 not contain any symbols. */
1147 end_symtab_get_static_block (CORE_ADDR end_addr, int expandable, int required)
1149 struct objfile *objfile = buildsym_compunit->objfile;
1151 /* Finish the lexical context of the last function in the file; pop
1152 the context stack. */
1154 if (!buildsym_compunit->m_context_stack.empty ())
1156 struct context_stack cstk = pop_context ();
1158 /* Make a block for the local symbols within. */
1159 finish_block (cstk.name, cstk.old_blocks, NULL,
1160 cstk.start_addr, end_addr);
1162 if (!buildsym_compunit->m_context_stack.empty ())
1164 /* This is said to happen with SCO. The old coffread.c
1165 code simply emptied the context stack, so we do the
1166 same. FIXME: Find out why it is happening. This is not
1167 believed to happen in most cases (even for coffread.c);
1168 it used to be an abort(). */
1169 complaint (_("Context stack not empty in end_symtab"));
1170 buildsym_compunit->m_context_stack.clear ();
1174 /* Reordered executables may have out of order pending blocks; if
1175 OBJF_REORDERED is true, then sort the pending blocks. */
1177 if ((objfile->flags & OBJF_REORDERED) && buildsym_compunit->m_pending_blocks)
1179 struct pending_block *pb;
1181 std::vector<block *> barray;
1183 for (pb = buildsym_compunit->m_pending_blocks; pb != NULL; pb = pb->next)
1184 barray.push_back (pb->block);
1186 /* Sort blocks by start address in descending order. Blocks with the
1187 same start address must remain in the original order to preserve
1188 inline function caller/callee relationships. */
1189 std::stable_sort (barray.begin (), barray.end (),
1190 [] (const block *a, const block *b)
1192 return BLOCK_START (a) > BLOCK_START (b);
1196 for (pb = buildsym_compunit->m_pending_blocks; pb != NULL; pb = pb->next)
1197 pb->block = barray[i++];
1200 /* Cleanup any undefined types that have been left hanging around
1201 (this needs to be done before the finish_blocks so that
1202 file_symbols is still good).
1204 Both cleanup_undefined_stabs_types and finish_global_stabs are stabs
1205 specific, but harmless for other symbol readers, since on gdb
1206 startup or when finished reading stabs, the state is set so these
1207 are no-ops. FIXME: Is this handled right in case of QUIT? Can
1208 we make this cleaner? */
1210 cleanup_undefined_stabs_types (objfile);
1211 finish_global_stabs (objfile);
1214 && buildsym_compunit->m_pending_blocks == NULL
1215 && buildsym_compunit->m_file_symbols == NULL
1216 && buildsym_compunit->m_global_symbols == NULL
1217 && !buildsym_compunit->m_have_line_numbers
1218 && buildsym_compunit->m_pending_macros == NULL
1219 && buildsym_compunit->m_global_using_directives == NULL)
1221 /* Ignore symtabs that have no functions with real debugging info. */
1226 /* Define the STATIC_BLOCK. */
1227 return finish_block_internal (NULL, get_file_symbols (), NULL, NULL,
1228 buildsym_compunit->m_last_source_start_addr,
1229 end_addr, 0, expandable);
1233 /* Subroutine of end_symtab_from_static_block to simplify it.
1234 Handle the "have blockvector" case.
1235 See end_symtab_from_static_block for a description of the arguments. */
1237 static struct compunit_symtab *
1238 end_symtab_with_blockvector (struct block *static_block,
1239 int section, int expandable)
1241 struct objfile *objfile = buildsym_compunit->objfile;
1242 struct compunit_symtab *cu = buildsym_compunit->compunit_symtab;
1243 struct symtab *symtab;
1244 struct blockvector *blockvector;
1245 struct subfile *subfile;
1248 gdb_assert (static_block != NULL);
1249 gdb_assert (buildsym_compunit != NULL);
1250 gdb_assert (buildsym_compunit->subfiles != NULL);
1252 end_addr = BLOCK_END (static_block);
1254 /* Create the GLOBAL_BLOCK and build the blockvector. */
1255 finish_block_internal (NULL, get_global_symbols (), NULL, NULL,
1256 buildsym_compunit->m_last_source_start_addr, end_addr,
1258 blockvector = make_blockvector ();
1260 /* Read the line table if it has to be read separately.
1261 This is only used by xcoffread.c. */
1262 if (objfile->sf->sym_read_linetable != NULL)
1263 objfile->sf->sym_read_linetable (objfile);
1265 /* Handle the case where the debug info specifies a different path
1266 for the main source file. It can cause us to lose track of its
1267 line number information. */
1268 watch_main_source_file_lossage ();
1270 /* Now create the symtab objects proper, if not already done,
1271 one for each subfile. */
1273 for (subfile = buildsym_compunit->subfiles;
1275 subfile = subfile->next)
1277 int linetablesize = 0;
1279 if (subfile->line_vector)
1281 linetablesize = sizeof (struct linetable) +
1282 subfile->line_vector->nitems * sizeof (struct linetable_entry);
1284 /* Like the pending blocks, the line table may be
1285 scrambled in reordered executables. Sort it if
1286 OBJF_REORDERED is true. */
1287 if (objfile->flags & OBJF_REORDERED)
1288 qsort (subfile->line_vector->item,
1289 subfile->line_vector->nitems,
1290 sizeof (struct linetable_entry), compare_line_numbers);
1293 /* Allocate a symbol table if necessary. */
1294 if (subfile->symtab == NULL)
1295 subfile->symtab = allocate_symtab (cu, subfile->name);
1296 symtab = subfile->symtab;
1298 /* Fill in its components. */
1300 if (subfile->line_vector)
1302 /* Reallocate the line table on the symbol obstack. */
1303 SYMTAB_LINETABLE (symtab) = (struct linetable *)
1304 obstack_alloc (&objfile->objfile_obstack, linetablesize);
1305 memcpy (SYMTAB_LINETABLE (symtab), subfile->line_vector,
1310 SYMTAB_LINETABLE (symtab) = NULL;
1313 /* Use whatever language we have been using for this
1314 subfile, not the one that was deduced in allocate_symtab
1315 from the filename. We already did our own deducing when
1316 we created the subfile, and we may have altered our
1317 opinion of what language it is from things we found in
1319 symtab->language = subfile->language;
1322 /* Make sure the symtab of main_subfile is the first in its list. */
1324 struct symtab *main_symtab, *prev_symtab;
1326 main_symtab = buildsym_compunit->main_subfile->symtab;
1328 ALL_COMPUNIT_FILETABS (cu, symtab)
1330 if (symtab == main_symtab)
1332 if (prev_symtab != NULL)
1334 prev_symtab->next = main_symtab->next;
1335 main_symtab->next = COMPUNIT_FILETABS (cu);
1336 COMPUNIT_FILETABS (cu) = main_symtab;
1340 prev_symtab = symtab;
1342 gdb_assert (main_symtab == COMPUNIT_FILETABS (cu));
1345 /* Fill out the compunit symtab. */
1347 if (buildsym_compunit->comp_dir != NULL)
1349 /* Reallocate the dirname on the symbol obstack. */
1350 const char *comp_dir = buildsym_compunit->comp_dir.get ();
1351 COMPUNIT_DIRNAME (cu)
1352 = (const char *) obstack_copy0 (&objfile->objfile_obstack,
1353 comp_dir, strlen (comp_dir));
1356 /* Save the debug format string (if any) in the symtab. */
1357 COMPUNIT_DEBUGFORMAT (cu) = buildsym_compunit->debugformat;
1359 /* Similarly for the producer. */
1360 COMPUNIT_PRODUCER (cu) = buildsym_compunit->producer;
1362 COMPUNIT_BLOCKVECTOR (cu) = blockvector;
1364 struct block *b = BLOCKVECTOR_BLOCK (blockvector, GLOBAL_BLOCK);
1366 set_block_compunit_symtab (b, cu);
1369 COMPUNIT_BLOCK_LINE_SECTION (cu) = section;
1371 COMPUNIT_MACRO_TABLE (cu) = buildsym_compunit->release_macros ();
1373 /* Default any symbols without a specified symtab to the primary symtab. */
1377 /* The main source file's symtab. */
1378 symtab = COMPUNIT_FILETABS (cu);
1380 for (block_i = 0; block_i < BLOCKVECTOR_NBLOCKS (blockvector); block_i++)
1382 struct block *block = BLOCKVECTOR_BLOCK (blockvector, block_i);
1384 struct dict_iterator iter;
1386 /* Inlined functions may have symbols not in the global or
1387 static symbol lists. */
1388 if (BLOCK_FUNCTION (block) != NULL)
1389 if (symbol_symtab (BLOCK_FUNCTION (block)) == NULL)
1390 symbol_set_symtab (BLOCK_FUNCTION (block), symtab);
1392 /* Note that we only want to fix up symbols from the local
1393 blocks, not blocks coming from included symtabs. That is why
1394 we use ALL_DICT_SYMBOLS here and not ALL_BLOCK_SYMBOLS. */
1395 ALL_DICT_SYMBOLS (BLOCK_DICT (block), iter, sym)
1396 if (symbol_symtab (sym) == NULL)
1397 symbol_set_symtab (sym, symtab);
1401 add_compunit_symtab_to_objfile (cu);
1406 /* Implementation of the second part of end_symtab. Pass STATIC_BLOCK
1407 as value returned by end_symtab_get_static_block.
1409 SECTION is the same as for end_symtab: the section number
1410 (in objfile->section_offsets) of the blockvector and linetable.
1412 If EXPANDABLE is non-zero the GLOBAL_BLOCK dictionary is made
1415 struct compunit_symtab *
1416 end_symtab_from_static_block (struct block *static_block,
1417 int section, int expandable)
1419 struct compunit_symtab *cu;
1421 if (static_block == NULL)
1423 /* Handle the "no blockvector" case.
1424 When this happens there is nothing to record, so there's nothing
1425 to do: memory will be freed up later.
1427 Note: We won't be adding a compunit to the objfile's list of
1428 compunits, so there's nothing to unchain. However, since each symtab
1429 is added to the objfile's obstack we can't free that space.
1430 We could do better, but this is believed to be a sufficiently rare
1435 cu = end_symtab_with_blockvector (static_block, section, expandable);
1437 reset_symtab_globals ();
1442 /* Finish the symbol definitions for one main source file, close off
1443 all the lexical contexts for that file (creating struct block's for
1444 them), then make the struct symtab for that file and put it in the
1447 END_ADDR is the address of the end of the file's text. SECTION is
1448 the section number (in objfile->section_offsets) of the blockvector
1451 Note that it is possible for end_symtab() to return NULL. In
1452 particular, for the DWARF case at least, it will return NULL when
1453 it finds a compilation unit that has exactly one DIE, a
1454 TAG_compile_unit DIE. This can happen when we link in an object
1455 file that was compiled from an empty source file. Returning NULL
1456 is probably not the correct thing to do, because then gdb will
1457 never know about this empty file (FIXME).
1459 If you need to modify STATIC_BLOCK before it is finalized you should
1460 call end_symtab_get_static_block and end_symtab_from_static_block
1463 struct compunit_symtab *
1464 end_symtab (CORE_ADDR end_addr, int section)
1466 struct block *static_block;
1468 static_block = end_symtab_get_static_block (end_addr, 0, 0);
1469 return end_symtab_from_static_block (static_block, section, 0);
1472 /* Same as end_symtab except create a symtab that can be later added to. */
1474 struct compunit_symtab *
1475 end_expandable_symtab (CORE_ADDR end_addr, int section)
1477 struct block *static_block;
1479 static_block = end_symtab_get_static_block (end_addr, 1, 0);
1480 return end_symtab_from_static_block (static_block, section, 1);
1483 /* Subroutine of augment_type_symtab to simplify it.
1484 Attach the main source file's symtab to all symbols in PENDING_LIST that
1488 set_missing_symtab (struct pending *pending_list,
1489 struct compunit_symtab *cu)
1491 struct pending *pending;
1494 for (pending = pending_list; pending != NULL; pending = pending->next)
1496 for (i = 0; i < pending->nsyms; ++i)
1498 if (symbol_symtab (pending->symbol[i]) == NULL)
1499 symbol_set_symtab (pending->symbol[i], COMPUNIT_FILETABS (cu));
1504 /* Same as end_symtab, but for the case where we're adding more symbols
1505 to an existing symtab that is known to contain only type information.
1506 This is the case for DWARF4 Type Units. */
1509 augment_type_symtab (void)
1511 struct compunit_symtab *cust = buildsym_compunit->compunit_symtab;
1512 const struct blockvector *blockvector = COMPUNIT_BLOCKVECTOR (cust);
1514 if (!buildsym_compunit->m_context_stack.empty ())
1515 complaint (_("Context stack not empty in augment_type_symtab"));
1516 if (buildsym_compunit->m_pending_blocks != NULL)
1517 complaint (_("Blocks in a type symtab"));
1518 if (buildsym_compunit->m_pending_macros != NULL)
1519 complaint (_("Macro in a type symtab"));
1520 if (buildsym_compunit->m_have_line_numbers)
1521 complaint (_("Line numbers recorded in a type symtab"));
1523 if (buildsym_compunit->m_file_symbols != NULL)
1525 struct block *block = BLOCKVECTOR_BLOCK (blockvector, STATIC_BLOCK);
1527 /* First mark any symbols without a specified symtab as belonging
1528 to the primary symtab. */
1529 set_missing_symtab (buildsym_compunit->m_file_symbols, cust);
1531 dict_add_pending (BLOCK_DICT (block), buildsym_compunit->m_file_symbols);
1534 if (buildsym_compunit->m_global_symbols != NULL)
1536 struct block *block = BLOCKVECTOR_BLOCK (blockvector, GLOBAL_BLOCK);
1538 /* First mark any symbols without a specified symtab as belonging
1539 to the primary symtab. */
1540 set_missing_symtab (buildsym_compunit->m_global_symbols, cust);
1542 dict_add_pending (BLOCK_DICT (block),
1543 buildsym_compunit->m_global_symbols);
1546 reset_symtab_globals ();
1549 /* Push a context block. Args are an identifying nesting level
1550 (checkable when you pop it), and the starting PC address of this
1553 struct context_stack *
1554 push_context (int desc, CORE_ADDR valu)
1556 gdb_assert (buildsym_compunit != nullptr);
1558 buildsym_compunit->m_context_stack.emplace_back ();
1559 struct context_stack *newobj = &buildsym_compunit->m_context_stack.back ();
1561 newobj->depth = desc;
1562 newobj->locals = buildsym_compunit->m_local_symbols;
1563 newobj->old_blocks = buildsym_compunit->m_pending_blocks;
1564 newobj->start_addr = valu;
1565 newobj->local_using_directives
1566 = buildsym_compunit->m_local_using_directives;
1567 newobj->name = NULL;
1569 buildsym_compunit->m_local_symbols = NULL;
1570 buildsym_compunit->m_local_using_directives = NULL;
1575 /* Pop a context block. Returns the address of the context block just
1578 struct context_stack
1581 gdb_assert (buildsym_compunit != nullptr);
1582 gdb_assert (!buildsym_compunit->m_context_stack.empty ());
1583 struct context_stack result = buildsym_compunit->m_context_stack.back ();
1584 buildsym_compunit->m_context_stack.pop_back ();
1591 record_debugformat (const char *format)
1593 buildsym_compunit->debugformat = format;
1597 record_producer (const char *producer)
1599 buildsym_compunit->producer = producer;
1604 /* See buildsym.h. */
1607 set_last_source_file (const char *name)
1609 gdb_assert (buildsym_compunit != nullptr || name == nullptr);
1610 if (buildsym_compunit != nullptr)
1611 buildsym_compunit->set_last_source_file (name);
1614 /* See buildsym.h. */
1617 get_last_source_file (void)
1619 if (buildsym_compunit == nullptr)
1621 return buildsym_compunit->m_last_source_file.get ();
1624 /* See buildsym.h. */
1627 set_last_source_start_addr (CORE_ADDR addr)
1629 gdb_assert (buildsym_compunit != nullptr);
1630 buildsym_compunit->m_last_source_start_addr = addr;
1633 /* See buildsym.h. */
1636 get_last_source_start_addr ()
1638 gdb_assert (buildsym_compunit != nullptr);
1639 return buildsym_compunit->m_last_source_start_addr;
1642 /* See buildsym.h. */
1644 struct using_direct **
1645 get_local_using_directives ()
1647 gdb_assert (buildsym_compunit != nullptr);
1648 return &buildsym_compunit->m_local_using_directives;
1651 /* See buildsym.h. */
1654 set_local_using_directives (struct using_direct *new_local)
1656 gdb_assert (buildsym_compunit != nullptr);
1657 buildsym_compunit->m_local_using_directives = new_local;
1660 /* See buildsym.h. */
1662 struct using_direct **
1663 get_global_using_directives ()
1665 gdb_assert (buildsym_compunit != nullptr);
1666 return &buildsym_compunit->m_global_using_directives;
1669 /* See buildsym.h. */
1672 outermost_context_p ()
1674 gdb_assert (buildsym_compunit != nullptr);
1675 return buildsym_compunit->m_context_stack.empty ();
1678 /* See buildsym.h. */
1680 struct context_stack *
1681 get_current_context_stack ()
1683 gdb_assert (buildsym_compunit != nullptr);
1684 if (buildsym_compunit->m_context_stack.empty ())
1686 return &buildsym_compunit->m_context_stack.back ();
1689 /* See buildsym.h. */
1692 get_context_stack_depth ()
1694 gdb_assert (buildsym_compunit != nullptr);
1695 return buildsym_compunit->m_context_stack.size ();
1698 /* See buildsym.h. */
1701 get_current_subfile ()
1703 gdb_assert (buildsym_compunit != nullptr);
1704 return buildsym_compunit->m_current_subfile;
1707 /* See buildsym.h. */
1710 get_local_symbols ()
1712 gdb_assert (buildsym_compunit != nullptr);
1713 return &buildsym_compunit->m_local_symbols;
1716 /* See buildsym.h. */
1721 gdb_assert (buildsym_compunit != nullptr);
1722 return &buildsym_compunit->m_file_symbols;
1725 /* See buildsym.h. */
1728 get_global_symbols ()
1730 gdb_assert (buildsym_compunit != nullptr);
1731 return &buildsym_compunit->m_global_symbols;