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:
29 scoped_free_pendings free_pending;
30 cust = start_symtab (...);
31 ... read debug info ...
32 cust = end_symtab (...);
34 The compunit symtab pointer ("cust") is returned from both start_symtab
35 and end_symtab to simplify the debug info readers.
37 There are minor variations on this, e.g., dwarf2read.c splits end_symtab
38 into two calls: end_symtab_get_static_block, end_symtab_from_static_block,
39 but all debug info readers follow this basic flow.
41 Reading DWARF Type Units is another variation:
44 scoped_free_pendings free_pending;
45 cust = start_symtab (...);
46 ... read debug info ...
47 cust = end_expandable_symtab (...);
49 And then reading subsequent Type Units within the containing "Comp Unit"
50 will use a second flow:
53 scoped_free_pendings free_pending;
54 cust = restart_symtab (...);
55 ... read debug info ...
56 cust = augment_type_symtab (...);
58 dbxread.c and xcoffread.c use another variation:
61 scoped_free_pendings free_pending;
62 cust = start_symtab (...);
63 ... read debug info ...
64 cust = end_symtab (...);
65 ... start_symtab + read + end_symtab repeated ...
70 #include "gdb_obstack.h"
75 #include "complaints.h"
76 #include "expression.h" /* For "enum exp_opcode" used by... */
78 #include "filenames.h" /* For DOSish file names. */
80 #include "demangle.h" /* Needed by SYMBOL_INIT_DEMANGLED_NAME. */
82 #include "cp-support.h"
83 #include "dictionary.h"
87 /* Ask buildsym.h to define the vars it normally declares `extern'. */
90 #include "buildsym.h" /* Our own declarations. */
93 /* For cleanup_undefined_stabs_types and finish_global_stabs (somewhat
94 questionable--see comment where we call them). */
96 #include "stabsread.h"
98 /* Buildsym's counterpart to struct compunit_symtab.
99 TODO(dje): Move all related global state into here. */
101 struct buildsym_compunit
103 /* Start recording information about a primary source file (IOW, not an
104 included source file).
105 COMP_DIR is the directory in which the compilation unit was compiled
106 (or NULL if not known). */
108 buildsym_compunit (struct objfile *objfile_, const char *name,
109 const char *comp_dir_, enum language language_,
111 : objfile (objfile_),
112 m_last_source_file (name == nullptr ? nullptr : xstrdup (name)),
113 comp_dir (comp_dir_ == nullptr ? nullptr : xstrdup (comp_dir_)),
114 language (language_),
115 m_last_source_start_addr (last_addr)
119 ~buildsym_compunit ()
121 struct subfile *subfile, *nextsub;
123 if (m_pending_macros != nullptr)
124 free_macro_table (m_pending_macros);
126 for (subfile = subfiles;
130 nextsub = subfile->next;
131 xfree (subfile->name);
132 xfree (subfile->line_vector);
137 void set_last_source_file (const char *name)
139 char *new_name = name == NULL ? NULL : xstrdup (name);
140 m_last_source_file.reset (new_name);
143 struct macro_table *get_macro_table ()
145 if (m_pending_macros == nullptr)
146 m_pending_macros = new_macro_table (&objfile->per_bfd->storage_obstack,
147 objfile->per_bfd->macro_cache,
149 return m_pending_macros;
152 struct macro_table *release_macros ()
154 struct macro_table *result = m_pending_macros;
155 m_pending_macros = nullptr;
159 /* The objfile we're reading debug info from. */
160 struct objfile *objfile;
162 /* List of subfiles (source files).
163 Files are added to the front of the list.
164 This is important mostly for the language determination hacks we use,
165 which iterate over previously added files. */
166 struct subfile *subfiles = nullptr;
168 /* The subfile of the main source file. */
169 struct subfile *main_subfile = nullptr;
171 /* Name of source file whose symbol data we are now processing. This
172 comes from a symbol of type N_SO for stabs. For DWARF it comes
173 from the DW_AT_name attribute of a DW_TAG_compile_unit DIE. */
174 gdb::unique_xmalloc_ptr<char> m_last_source_file;
176 /* E.g., DW_AT_comp_dir if DWARF. Space for this is malloc'd. */
177 gdb::unique_xmalloc_ptr<char> comp_dir;
179 /* Space for this is not malloc'd, and is assumed to have at least
180 the same lifetime as objfile. */
181 const char *producer = nullptr;
183 /* Space for this is not malloc'd, and is assumed to have at least
184 the same lifetime as objfile. */
185 const char *debugformat = nullptr;
187 /* The compunit we are building. */
188 struct compunit_symtab *compunit_symtab = nullptr;
190 /* Language of this compunit_symtab. */
191 enum language language;
193 /* The macro table for the compilation unit whose symbols we're
194 currently reading. */
195 struct macro_table *m_pending_macros = nullptr;
197 /* True if symtab has line number info. This prevents an otherwise
198 empty symtab from being tossed. */
199 bool m_have_line_numbers = false;
201 /* Core address of start of text of current source file. This too
202 comes from the N_SO symbol. For Dwarf it typically comes from the
203 DW_AT_low_pc attribute of a DW_TAG_compile_unit DIE. */
204 CORE_ADDR m_last_source_start_addr;
207 /* The work-in-progress of the compunit we are building.
208 This is created first, before any subfiles by start_symtab. */
210 static struct buildsym_compunit *buildsym_compunit;
212 /* List of free `struct pending' structures for reuse. */
214 static struct pending *free_pendings;
216 /* The mutable address map for the compilation unit whose symbols
217 we're currently reading. The symtabs' shared blockvector will
218 point to a fixed copy of this. */
219 static struct addrmap *pending_addrmap;
221 /* The obstack on which we allocate pending_addrmap.
222 If pending_addrmap is NULL, this is uninitialized; otherwise, it is
223 initialized (and holds pending_addrmap). */
224 static struct obstack pending_addrmap_obstack;
226 /* Non-zero if we recorded any ranges in the addrmap that are
227 different from those in the blockvector already. We set this to
228 zero when we start processing a symfile, and if it's still zero at
229 the end, then we just toss the addrmap. */
230 static int pending_addrmap_interesting;
232 /* An obstack used for allocating pending blocks. */
234 static struct obstack pending_block_obstack;
236 /* List of blocks already made (lexical contexts already closed).
237 This is used at the end to make the blockvector. */
241 struct pending_block *next;
245 /* Pointer to the head of a linked list of symbol blocks which have
246 already been finalized (lexical contexts already closed) and which
247 are just waiting to be built into a blockvector when finalizing the
248 associated symtab. */
250 static struct pending_block *pending_blocks;
254 struct subfile_stack *next;
258 static struct subfile_stack *subfile_stack;
260 static void free_buildsym_compunit (void);
262 static int compare_line_numbers (const void *ln1p, const void *ln2p);
264 static void record_pending_block (struct objfile *objfile,
266 struct pending_block *opblock);
268 /* Initial sizes of data structures. These are realloc'd larger if
269 needed, and realloc'd down to the size actually used, when
272 #define INITIAL_CONTEXT_STACK_SIZE 10
273 #define INITIAL_LINE_VECTOR_LENGTH 1000
276 /* Maintain the lists of symbols and blocks. */
278 /* Add a symbol to one of the lists of symbols. */
281 add_symbol_to_list (struct symbol *symbol, struct pending **listhead)
283 struct pending *link;
285 /* If this is an alias for another symbol, don't add it. */
286 if (symbol->ginfo.name && symbol->ginfo.name[0] == '#')
289 /* We keep PENDINGSIZE symbols in each link of the list. If we
290 don't have a link with room in it, add a new link. */
291 if (*listhead == NULL || (*listhead)->nsyms == PENDINGSIZE)
295 link = free_pendings;
296 free_pendings = link->next;
300 link = XNEW (struct pending);
303 link->next = *listhead;
308 (*listhead)->symbol[(*listhead)->nsyms++] = symbol;
311 /* Find a symbol named NAME on a LIST. NAME need not be
312 '\0'-terminated; LENGTH is the length of the name. */
315 find_symbol_in_list (struct pending *list, char *name, int length)
322 for (j = list->nsyms; --j >= 0;)
324 pp = SYMBOL_LINKAGE_NAME (list->symbol[j]);
325 if (*pp == *name && strncmp (pp, name, length) == 0
326 && pp[length] == '\0')
328 return (list->symbol[j]);
336 /* At end of reading syms, or in case of quit, ensure everything
337 associated with building symtabs is freed.
339 N.B. This is *not* intended to be used when building psymtabs. Some debug
340 info readers call this anyway, which is harmless if confusing. */
342 scoped_free_pendings::~scoped_free_pendings ()
344 struct pending *next, *next1;
346 for (next = free_pendings; next; next = next1)
349 xfree ((void *) next);
351 free_pendings = NULL;
353 free_pending_blocks ();
355 for (next = file_symbols; next != NULL; next = next1)
358 xfree ((void *) next);
362 for (next = global_symbols; next != NULL; next = next1)
365 xfree ((void *) next);
367 global_symbols = NULL;
370 obstack_free (&pending_addrmap_obstack, NULL);
371 pending_addrmap = NULL;
373 free_buildsym_compunit ();
376 /* This function is called to discard any pending blocks. */
379 free_pending_blocks (void)
381 if (pending_blocks != NULL)
383 obstack_free (&pending_block_obstack, NULL);
384 pending_blocks = NULL;
388 /* Take one of the lists of symbols and make a block from it. Keep
389 the order the symbols have in the list (reversed from the input
390 file). Put the block on the list of pending blocks. */
392 static struct block *
393 finish_block_internal (struct symbol *symbol,
394 struct pending **listhead,
395 struct pending_block *old_blocks,
396 const struct dynamic_prop *static_link,
397 CORE_ADDR start, CORE_ADDR end,
398 int is_global, int expandable)
400 struct objfile *objfile = buildsym_compunit->objfile;
401 struct gdbarch *gdbarch = get_objfile_arch (objfile);
402 struct pending *next, *next1;
404 struct pending_block *pblock;
405 struct pending_block *opblock;
408 ? allocate_global_block (&objfile->objfile_obstack)
409 : allocate_block (&objfile->objfile_obstack));
414 = dict_create_linear (&objfile->objfile_obstack,
415 buildsym_compunit->language, *listhead);
422 = dict_create_hashed_expandable (buildsym_compunit->language);
423 dict_add_pending (BLOCK_DICT (block), *listhead);
428 dict_create_hashed (&objfile->objfile_obstack,
429 buildsym_compunit->language, *listhead);
433 BLOCK_START (block) = start;
434 BLOCK_END (block) = end;
436 /* Put the block in as the value of the symbol that names it. */
440 struct type *ftype = SYMBOL_TYPE (symbol);
441 struct dict_iterator iter;
442 SYMBOL_BLOCK_VALUE (symbol) = block;
443 BLOCK_FUNCTION (block) = symbol;
445 if (TYPE_NFIELDS (ftype) <= 0)
447 /* No parameter type information is recorded with the
448 function's type. Set that from the type of the
449 parameter symbols. */
450 int nparams = 0, iparams;
453 /* Here we want to directly access the dictionary, because
454 we haven't fully initialized the block yet. */
455 ALL_DICT_SYMBOLS (BLOCK_DICT (block), iter, sym)
457 if (SYMBOL_IS_ARGUMENT (sym))
462 TYPE_NFIELDS (ftype) = nparams;
463 TYPE_FIELDS (ftype) = (struct field *)
464 TYPE_ALLOC (ftype, nparams * sizeof (struct field));
467 /* Here we want to directly access the dictionary, because
468 we haven't fully initialized the block yet. */
469 ALL_DICT_SYMBOLS (BLOCK_DICT (block), iter, sym)
471 if (iparams == nparams)
474 if (SYMBOL_IS_ARGUMENT (sym))
476 TYPE_FIELD_TYPE (ftype, iparams) = SYMBOL_TYPE (sym);
477 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0;
486 BLOCK_FUNCTION (block) = NULL;
489 if (static_link != NULL)
490 objfile_register_static_link (objfile, block, static_link);
492 /* Now "free" the links of the list, and empty the list. */
494 for (next = *listhead; next; next = next1)
497 next->next = free_pendings;
498 free_pendings = next;
502 /* Check to be sure that the blocks have an end address that is
503 greater than starting address. */
505 if (BLOCK_END (block) < BLOCK_START (block))
509 complaint (_("block end address less than block "
510 "start address in %s (patched it)"),
511 SYMBOL_PRINT_NAME (symbol));
515 complaint (_("block end address %s less than block "
516 "start address %s (patched it)"),
517 paddress (gdbarch, BLOCK_END (block)),
518 paddress (gdbarch, BLOCK_START (block)));
520 /* Better than nothing. */
521 BLOCK_END (block) = BLOCK_START (block);
524 /* Install this block as the superblock of all blocks made since the
525 start of this scope that don't have superblocks yet. */
528 for (pblock = pending_blocks;
529 pblock && pblock != old_blocks;
530 pblock = pblock->next)
532 if (BLOCK_SUPERBLOCK (pblock->block) == NULL)
534 /* Check to be sure the blocks are nested as we receive
535 them. If the compiler/assembler/linker work, this just
536 burns a small amount of time.
538 Skip blocks which correspond to a function; they're not
539 physically nested inside this other blocks, only
541 if (BLOCK_FUNCTION (pblock->block) == NULL
542 && (BLOCK_START (pblock->block) < BLOCK_START (block)
543 || BLOCK_END (pblock->block) > BLOCK_END (block)))
547 complaint (_("inner block not inside outer block in %s"),
548 SYMBOL_PRINT_NAME (symbol));
552 complaint (_("inner block (%s-%s) not "
553 "inside outer block (%s-%s)"),
554 paddress (gdbarch, BLOCK_START (pblock->block)),
555 paddress (gdbarch, BLOCK_END (pblock->block)),
556 paddress (gdbarch, BLOCK_START (block)),
557 paddress (gdbarch, BLOCK_END (block)));
559 if (BLOCK_START (pblock->block) < BLOCK_START (block))
560 BLOCK_START (pblock->block) = BLOCK_START (block);
561 if (BLOCK_END (pblock->block) > BLOCK_END (block))
562 BLOCK_END (pblock->block) = BLOCK_END (block);
564 BLOCK_SUPERBLOCK (pblock->block) = block;
569 block_set_using (block,
571 ? global_using_directives
572 : local_using_directives),
573 &objfile->objfile_obstack);
575 global_using_directives = NULL;
577 local_using_directives = NULL;
579 record_pending_block (objfile, block, opblock);
585 finish_block (struct symbol *symbol,
586 struct pending **listhead,
587 struct pending_block *old_blocks,
588 const struct dynamic_prop *static_link,
589 CORE_ADDR start, CORE_ADDR end)
591 return finish_block_internal (symbol, listhead, old_blocks, static_link,
595 /* Record BLOCK on the list of all blocks in the file. Put it after
596 OPBLOCK, or at the beginning if opblock is NULL. This puts the
597 block in the list after all its subblocks.
599 Allocate the pending block struct in the objfile_obstack to save
600 time. This wastes a little space. FIXME: Is it worth it? */
603 record_pending_block (struct objfile *objfile, struct block *block,
604 struct pending_block *opblock)
606 struct pending_block *pblock;
608 if (pending_blocks == NULL)
609 obstack_init (&pending_block_obstack);
611 pblock = XOBNEW (&pending_block_obstack, struct pending_block);
612 pblock->block = block;
615 pblock->next = opblock->next;
616 opblock->next = pblock;
620 pblock->next = pending_blocks;
621 pending_blocks = pblock;
626 /* Record that the range of addresses from START to END_INCLUSIVE
627 (inclusive, like it says) belongs to BLOCK. BLOCK's start and end
628 addresses must be set already. You must apply this function to all
629 BLOCK's children before applying it to BLOCK.
631 If a call to this function complicates the picture beyond that
632 already provided by BLOCK_START and BLOCK_END, then we create an
633 address map for the block. */
635 record_block_range (struct block *block,
636 CORE_ADDR start, CORE_ADDR end_inclusive)
638 /* If this is any different from the range recorded in the block's
639 own BLOCK_START and BLOCK_END, then note that the address map has
640 become interesting. Note that even if this block doesn't have
641 any "interesting" ranges, some later block might, so we still
642 need to record this block in the addrmap. */
643 if (start != BLOCK_START (block)
644 || end_inclusive + 1 != BLOCK_END (block))
645 pending_addrmap_interesting = 1;
647 if (! pending_addrmap)
649 obstack_init (&pending_addrmap_obstack);
650 pending_addrmap = addrmap_create_mutable (&pending_addrmap_obstack);
653 addrmap_set_empty (pending_addrmap, start, end_inclusive, block);
656 static struct blockvector *
657 make_blockvector (void)
659 struct objfile *objfile = buildsym_compunit->objfile;
660 struct pending_block *next;
661 struct blockvector *blockvector;
664 /* Count the length of the list of blocks. */
666 for (next = pending_blocks, i = 0; next; next = next->next, i++)
670 blockvector = (struct blockvector *)
671 obstack_alloc (&objfile->objfile_obstack,
672 (sizeof (struct blockvector)
673 + (i - 1) * sizeof (struct block *)));
675 /* Copy the blocks into the blockvector. This is done in reverse
676 order, which happens to put the blocks into the proper order
677 (ascending starting address). finish_block has hair to insert
678 each block into the list after its subblocks in order to make
679 sure this is true. */
681 BLOCKVECTOR_NBLOCKS (blockvector) = i;
682 for (next = pending_blocks; next; next = next->next)
684 BLOCKVECTOR_BLOCK (blockvector, --i) = next->block;
687 free_pending_blocks ();
689 /* If we needed an address map for this symtab, record it in the
691 if (pending_addrmap && pending_addrmap_interesting)
692 BLOCKVECTOR_MAP (blockvector)
693 = addrmap_create_fixed (pending_addrmap, &objfile->objfile_obstack);
695 BLOCKVECTOR_MAP (blockvector) = 0;
697 /* Some compilers output blocks in the wrong order, but we depend on
698 their being in the right order so we can binary search. Check the
699 order and moan about it.
700 Note: Remember that the first two blocks are the global and static
701 blocks. We could special case that fact and begin checking at block 2.
702 To avoid making that assumption we do not. */
703 if (BLOCKVECTOR_NBLOCKS (blockvector) > 1)
705 for (i = 1; i < BLOCKVECTOR_NBLOCKS (blockvector); i++)
707 if (BLOCK_START (BLOCKVECTOR_BLOCK (blockvector, i - 1))
708 > BLOCK_START (BLOCKVECTOR_BLOCK (blockvector, i)))
711 = BLOCK_START (BLOCKVECTOR_BLOCK (blockvector, i));
713 complaint (_("block at %s out of order"),
714 hex_string ((LONGEST) start));
719 return (blockvector);
722 /* Start recording information about source code that came from an
723 included (or otherwise merged-in) source file with a different
724 name. NAME is the name of the file (cannot be NULL). */
727 start_subfile (const char *name)
729 const char *subfile_dirname;
730 struct subfile *subfile;
732 gdb_assert (buildsym_compunit != NULL);
734 subfile_dirname = buildsym_compunit->comp_dir.get ();
736 /* See if this subfile is already registered. */
738 for (subfile = buildsym_compunit->subfiles; subfile; subfile = subfile->next)
742 /* If NAME is an absolute path, and this subfile is not, then
743 attempt to create an absolute path to compare. */
744 if (IS_ABSOLUTE_PATH (name)
745 && !IS_ABSOLUTE_PATH (subfile->name)
746 && subfile_dirname != NULL)
747 subfile_name = concat (subfile_dirname, SLASH_STRING,
748 subfile->name, (char *) NULL);
750 subfile_name = subfile->name;
752 if (FILENAME_CMP (subfile_name, name) == 0)
754 current_subfile = subfile;
755 if (subfile_name != subfile->name)
756 xfree (subfile_name);
759 if (subfile_name != subfile->name)
760 xfree (subfile_name);
763 /* This subfile is not known. Add an entry for it. */
765 subfile = XNEW (struct subfile);
766 memset (subfile, 0, sizeof (struct subfile));
767 subfile->buildsym_compunit = buildsym_compunit;
769 subfile->next = buildsym_compunit->subfiles;
770 buildsym_compunit->subfiles = subfile;
772 current_subfile = subfile;
774 subfile->name = xstrdup (name);
776 /* Initialize line-number recording for this subfile. */
777 subfile->line_vector = NULL;
779 /* Default the source language to whatever can be deduced from the
780 filename. If nothing can be deduced (such as for a C/C++ include
781 file with a ".h" extension), then inherit whatever language the
782 previous subfile had. This kludgery is necessary because there
783 is no standard way in some object formats to record the source
784 language. Also, when symtabs are allocated we try to deduce a
785 language then as well, but it is too late for us to use that
786 information while reading symbols, since symtabs aren't allocated
787 until after all the symbols have been processed for a given
790 subfile->language = deduce_language_from_filename (subfile->name);
791 if (subfile->language == language_unknown
792 && subfile->next != NULL)
794 subfile->language = subfile->next->language;
797 /* If the filename of this subfile ends in .C, then change the
798 language of any pending subfiles from C to C++. We also accept
799 any other C++ suffixes accepted by deduce_language_from_filename. */
800 /* Likewise for f2c. */
805 enum language sublang = deduce_language_from_filename (subfile->name);
807 if (sublang == language_cplus || sublang == language_fortran)
808 for (s = buildsym_compunit->subfiles; s != NULL; s = s->next)
809 if (s->language == language_c)
810 s->language = sublang;
813 /* And patch up this file if necessary. */
814 if (subfile->language == language_c
815 && subfile->next != NULL
816 && (subfile->next->language == language_cplus
817 || subfile->next->language == language_fortran))
819 subfile->language = subfile->next->language;
823 /* Delete the buildsym compunit. */
826 free_buildsym_compunit (void)
828 if (buildsym_compunit == NULL)
830 delete buildsym_compunit;
831 buildsym_compunit = NULL;
832 current_subfile = NULL;
835 /* For stabs readers, the first N_SO symbol is assumed to be the
836 source file name, and the subfile struct is initialized using that
837 assumption. If another N_SO symbol is later seen, immediately
838 following the first one, then the first one is assumed to be the
839 directory name and the second one is really the source file name.
841 So we have to patch up the subfile struct by moving the old name
842 value to dirname and remembering the new name. Some sanity
843 checking is performed to ensure that the state of the subfile
844 struct is reasonable and that the old name we are assuming to be a
845 directory name actually is (by checking for a trailing '/'). */
848 patch_subfile_names (struct subfile *subfile, const char *name)
851 && buildsym_compunit->comp_dir == NULL
852 && subfile->name != NULL
853 && IS_DIR_SEPARATOR (subfile->name[strlen (subfile->name) - 1]))
855 buildsym_compunit->comp_dir.reset (subfile->name);
856 subfile->name = xstrdup (name);
857 set_last_source_file (name);
859 /* Default the source language to whatever can be deduced from
860 the filename. If nothing can be deduced (such as for a C/C++
861 include file with a ".h" extension), then inherit whatever
862 language the previous subfile had. This kludgery is
863 necessary because there is no standard way in some object
864 formats to record the source language. Also, when symtabs
865 are allocated we try to deduce a language then as well, but
866 it is too late for us to use that information while reading
867 symbols, since symtabs aren't allocated until after all the
868 symbols have been processed for a given source file. */
870 subfile->language = deduce_language_from_filename (subfile->name);
871 if (subfile->language == language_unknown
872 && subfile->next != NULL)
874 subfile->language = subfile->next->language;
879 /* Handle the N_BINCL and N_EINCL symbol types that act like N_SOL for
880 switching source files (different subfiles, as we call them) within
881 one object file, but using a stack rather than in an arbitrary
887 struct subfile_stack *tem = XNEW (struct subfile_stack);
889 tem->next = subfile_stack;
891 if (current_subfile == NULL || current_subfile->name == NULL)
893 internal_error (__FILE__, __LINE__,
894 _("failed internal consistency check"));
896 tem->name = current_subfile->name;
903 struct subfile_stack *link = subfile_stack;
907 internal_error (__FILE__, __LINE__,
908 _("failed internal consistency check"));
911 subfile_stack = link->next;
912 xfree ((void *) link);
916 /* Add a linetable entry for line number LINE and address PC to the
917 line vector for SUBFILE. */
920 record_line (struct subfile *subfile, int line, CORE_ADDR pc)
922 struct linetable_entry *e;
924 /* Ignore the dummy line number in libg.o */
930 /* Make sure line vector exists and is big enough. */
931 if (!subfile->line_vector)
933 subfile->line_vector_length = INITIAL_LINE_VECTOR_LENGTH;
934 subfile->line_vector = (struct linetable *)
935 xmalloc (sizeof (struct linetable)
936 + subfile->line_vector_length * sizeof (struct linetable_entry));
937 subfile->line_vector->nitems = 0;
938 buildsym_compunit->m_have_line_numbers = true;
941 if (subfile->line_vector->nitems + 1 >= subfile->line_vector_length)
943 subfile->line_vector_length *= 2;
944 subfile->line_vector = (struct linetable *)
945 xrealloc ((char *) subfile->line_vector,
946 (sizeof (struct linetable)
947 + (subfile->line_vector_length
948 * sizeof (struct linetable_entry))));
951 /* Normally, we treat lines as unsorted. But the end of sequence
952 marker is special. We sort line markers at the same PC by line
953 number, so end of sequence markers (which have line == 0) appear
954 first. This is right if the marker ends the previous function,
955 and there is no padding before the next function. But it is
956 wrong if the previous line was empty and we are now marking a
957 switch to a different subfile. We must leave the end of sequence
958 marker at the end of this group of lines, not sort the empty line
959 to after the marker. The easiest way to accomplish this is to
960 delete any empty lines from our table, if they are followed by
961 end of sequence markers. All we lose is the ability to set
962 breakpoints at some lines which contain no instructions
964 if (line == 0 && subfile->line_vector->nitems > 0)
966 e = subfile->line_vector->item + subfile->line_vector->nitems - 1;
967 while (subfile->line_vector->nitems > 0 && e->pc == pc)
970 subfile->line_vector->nitems--;
974 e = subfile->line_vector->item + subfile->line_vector->nitems++;
979 /* Needed in order to sort line tables from IBM xcoff files. Sigh! */
982 compare_line_numbers (const void *ln1p, const void *ln2p)
984 struct linetable_entry *ln1 = (struct linetable_entry *) ln1p;
985 struct linetable_entry *ln2 = (struct linetable_entry *) ln2p;
987 /* Note: this code does not assume that CORE_ADDRs can fit in ints.
988 Please keep it that way. */
989 if (ln1->pc < ln2->pc)
992 if (ln1->pc > ln2->pc)
995 /* If pc equal, sort by line. I'm not sure whether this is optimum
996 behavior (see comment at struct linetable in symtab.h). */
997 return ln1->line - ln2->line;
1000 /* See buildsym.h. */
1002 struct compunit_symtab *
1003 buildsym_compunit_symtab (void)
1005 gdb_assert (buildsym_compunit != NULL);
1007 return buildsym_compunit->compunit_symtab;
1010 /* See buildsym.h. */
1012 struct macro_table *
1013 get_macro_table (void)
1015 struct objfile *objfile;
1017 gdb_assert (buildsym_compunit != NULL);
1018 return buildsym_compunit->get_macro_table ();
1021 /* Init state to prepare for building a symtab.
1022 Note: This can't be done in buildsym_init because dbxread.c and xcoffread.c
1023 can call start_symtab+end_symtab multiple times after one call to
1027 prepare_for_building ()
1029 local_symbols = NULL;
1030 local_using_directives = NULL;
1031 within_function = 0;
1033 context_stack_depth = 0;
1035 /* These should have been reset either by successful completion of building
1036 a symtab, or by the scoped_free_pendings destructor. */
1037 gdb_assert (file_symbols == NULL);
1038 gdb_assert (global_symbols == NULL);
1039 gdb_assert (global_using_directives == NULL);
1040 gdb_assert (pending_addrmap == NULL);
1041 gdb_assert (current_subfile == NULL);
1042 gdb_assert (buildsym_compunit == nullptr);
1045 /* Start a new symtab for a new source file in OBJFILE. Called, for example,
1046 when a stabs symbol of type N_SO is seen, or when a DWARF
1047 TAG_compile_unit DIE is seen. It indicates the start of data for
1048 one original source file.
1050 NAME is the name of the file (cannot be NULL). COMP_DIR is the
1051 directory in which the file was compiled (or NULL if not known).
1052 START_ADDR is the lowest address of objects in the file (or 0 if
1053 not known). LANGUAGE is the language of the source file, or
1054 language_unknown if not known, in which case it'll be deduced from
1057 struct compunit_symtab *
1058 start_symtab (struct objfile *objfile, const char *name, const char *comp_dir,
1059 CORE_ADDR start_addr, enum language language)
1061 prepare_for_building ();
1063 buildsym_compunit = new struct buildsym_compunit (objfile, name, comp_dir,
1064 language, start_addr);
1066 /* Allocate the compunit symtab now. The caller needs it to allocate
1067 non-primary symtabs. It is also needed by get_macro_table. */
1068 buildsym_compunit->compunit_symtab = allocate_compunit_symtab (objfile,
1071 /* Build the subfile for NAME (the main source file) so that we can record
1072 a pointer to it for later.
1073 IMPORTANT: Do not allocate a struct symtab for NAME here.
1074 It can happen that the debug info provides a different path to NAME than
1075 DIRNAME,NAME. We cope with this in watch_main_source_file_lossage but
1076 that only works if the main_subfile doesn't have a symtab yet. */
1077 start_subfile (name);
1078 /* Save this so that we don't have to go looking for it at the end
1079 of the subfiles list. */
1080 buildsym_compunit->main_subfile = current_subfile;
1082 return buildsym_compunit->compunit_symtab;
1085 /* Restart compilation for a symtab.
1086 CUST is the result of end_expandable_symtab.
1087 NAME, START_ADDR are the source file we are resuming with.
1089 This is used when a symtab is built from multiple sources.
1090 The symtab is first built with start_symtab/end_expandable_symtab
1091 and then for each additional piece call restart_symtab/augment_*_symtab.
1092 Note: At the moment there is only augment_type_symtab. */
1095 restart_symtab (struct compunit_symtab *cust,
1096 const char *name, CORE_ADDR start_addr)
1098 prepare_for_building ();
1101 = new struct buildsym_compunit (COMPUNIT_OBJFILE (cust),
1103 COMPUNIT_DIRNAME (cust),
1104 compunit_language (cust),
1106 buildsym_compunit->compunit_symtab = cust;
1109 /* Subroutine of end_symtab to simplify it. Look for a subfile that
1110 matches the main source file's basename. If there is only one, and
1111 if the main source file doesn't have any symbol or line number
1112 information, then copy this file's symtab and line_vector to the
1113 main source file's subfile and discard the other subfile. This can
1114 happen because of a compiler bug or from the user playing games
1115 with #line or from things like a distributed build system that
1116 manipulates the debug info. This can also happen from an innocent
1117 symlink in the paths, we don't canonicalize paths here. */
1120 watch_main_source_file_lossage (void)
1122 struct subfile *mainsub, *subfile;
1124 /* We have to watch for buildsym_compunit == NULL here. It's a quirk of
1125 end_symtab, it can return NULL so there may not be a main subfile. */
1126 if (buildsym_compunit == NULL)
1129 /* Get the main source file. */
1130 mainsub = buildsym_compunit->main_subfile;
1132 /* If the main source file doesn't have any line number or symbol
1133 info, look for an alias in another subfile. */
1135 if (mainsub->line_vector == NULL
1136 && mainsub->symtab == NULL)
1138 const char *mainbase = lbasename (mainsub->name);
1140 struct subfile *prevsub;
1141 struct subfile *mainsub_alias = NULL;
1142 struct subfile *prev_mainsub_alias = NULL;
1145 for (subfile = buildsym_compunit->subfiles;
1147 subfile = subfile->next)
1149 if (subfile == mainsub)
1151 if (filename_cmp (lbasename (subfile->name), mainbase) == 0)
1154 mainsub_alias = subfile;
1155 prev_mainsub_alias = prevsub;
1160 if (nr_matches == 1)
1162 gdb_assert (mainsub_alias != NULL && mainsub_alias != mainsub);
1164 /* Found a match for the main source file.
1165 Copy its line_vector and symtab to the main subfile
1166 and then discard it. */
1168 mainsub->line_vector = mainsub_alias->line_vector;
1169 mainsub->line_vector_length = mainsub_alias->line_vector_length;
1170 mainsub->symtab = mainsub_alias->symtab;
1172 if (prev_mainsub_alias == NULL)
1173 buildsym_compunit->subfiles = mainsub_alias->next;
1175 prev_mainsub_alias->next = mainsub_alias->next;
1176 xfree (mainsub_alias->name);
1177 xfree (mainsub_alias);
1182 /* Reset state after a successful building of a symtab.
1183 This exists because dbxread.c and xcoffread.c can call
1184 start_symtab+end_symtab multiple times after one call to buildsym_init,
1185 and before the scoped_free_pendings destructor is called.
1186 We keep the free_pendings list around for dbx/xcoff sake. */
1189 reset_symtab_globals (void)
1191 local_symbols = NULL;
1192 local_using_directives = NULL;
1193 file_symbols = NULL;
1194 global_symbols = NULL;
1195 global_using_directives = NULL;
1197 if (pending_addrmap)
1198 obstack_free (&pending_addrmap_obstack, NULL);
1199 pending_addrmap = NULL;
1201 free_buildsym_compunit ();
1204 /* Implementation of the first part of end_symtab. It allows modifying
1205 STATIC_BLOCK before it gets finalized by end_symtab_from_static_block.
1206 If the returned value is NULL there is no blockvector created for
1207 this symtab (you still must call end_symtab_from_static_block).
1209 END_ADDR is the same as for end_symtab: the address of the end of the
1212 If EXPANDABLE is non-zero the STATIC_BLOCK dictionary is made
1215 If REQUIRED is non-zero, then a symtab is created even if it does
1216 not contain any symbols. */
1219 end_symtab_get_static_block (CORE_ADDR end_addr, int expandable, int required)
1221 struct objfile *objfile = buildsym_compunit->objfile;
1223 /* Finish the lexical context of the last function in the file; pop
1224 the context stack. */
1226 if (context_stack_depth > 0)
1228 struct context_stack *cstk = pop_context ();
1230 /* Make a block for the local symbols within. */
1231 finish_block (cstk->name, &local_symbols, cstk->old_blocks, NULL,
1232 cstk->start_addr, end_addr);
1234 if (context_stack_depth > 0)
1236 /* This is said to happen with SCO. The old coffread.c
1237 code simply emptied the context stack, so we do the
1238 same. FIXME: Find out why it is happening. This is not
1239 believed to happen in most cases (even for coffread.c);
1240 it used to be an abort(). */
1241 complaint (_("Context stack not empty in end_symtab"));
1242 context_stack_depth = 0;
1246 /* Reordered executables may have out of order pending blocks; if
1247 OBJF_REORDERED is true, then sort the pending blocks. */
1249 if ((objfile->flags & OBJF_REORDERED) && pending_blocks)
1251 struct pending_block *pb;
1253 std::vector<block *> barray;
1255 for (pb = pending_blocks; pb != NULL; pb = pb->next)
1256 barray.push_back (pb->block);
1258 /* Sort blocks by start address in descending order. Blocks with the
1259 same start address must remain in the original order to preserve
1260 inline function caller/callee relationships. */
1261 std::stable_sort (barray.begin (), barray.end (),
1262 [] (const block *a, const block *b)
1264 return BLOCK_START (a) > BLOCK_START (b);
1268 for (pb = pending_blocks; pb != NULL; pb = pb->next)
1269 pb->block = barray[i++];
1272 /* Cleanup any undefined types that have been left hanging around
1273 (this needs to be done before the finish_blocks so that
1274 file_symbols is still good).
1276 Both cleanup_undefined_stabs_types and finish_global_stabs are stabs
1277 specific, but harmless for other symbol readers, since on gdb
1278 startup or when finished reading stabs, the state is set so these
1279 are no-ops. FIXME: Is this handled right in case of QUIT? Can
1280 we make this cleaner? */
1282 cleanup_undefined_stabs_types (objfile);
1283 finish_global_stabs (objfile);
1286 && pending_blocks == NULL
1287 && file_symbols == NULL
1288 && global_symbols == NULL
1289 && !buildsym_compunit->m_have_line_numbers
1290 && buildsym_compunit->m_pending_macros == NULL
1291 && global_using_directives == NULL)
1293 /* Ignore symtabs that have no functions with real debugging info. */
1298 /* Define the STATIC_BLOCK. */
1299 return finish_block_internal (NULL, &file_symbols, NULL, NULL,
1300 buildsym_compunit->m_last_source_start_addr,
1301 end_addr, 0, expandable);
1305 /* Subroutine of end_symtab_from_static_block to simplify it.
1306 Handle the "have blockvector" case.
1307 See end_symtab_from_static_block for a description of the arguments. */
1309 static struct compunit_symtab *
1310 end_symtab_with_blockvector (struct block *static_block,
1311 int section, int expandable)
1313 struct objfile *objfile = buildsym_compunit->objfile;
1314 struct compunit_symtab *cu = buildsym_compunit->compunit_symtab;
1315 struct symtab *symtab;
1316 struct blockvector *blockvector;
1317 struct subfile *subfile;
1320 gdb_assert (static_block != NULL);
1321 gdb_assert (buildsym_compunit != NULL);
1322 gdb_assert (buildsym_compunit->subfiles != NULL);
1324 end_addr = BLOCK_END (static_block);
1326 /* Create the GLOBAL_BLOCK and build the blockvector. */
1327 finish_block_internal (NULL, &global_symbols, NULL, NULL,
1328 buildsym_compunit->m_last_source_start_addr, end_addr,
1330 blockvector = make_blockvector ();
1332 /* Read the line table if it has to be read separately.
1333 This is only used by xcoffread.c. */
1334 if (objfile->sf->sym_read_linetable != NULL)
1335 objfile->sf->sym_read_linetable (objfile);
1337 /* Handle the case where the debug info specifies a different path
1338 for the main source file. It can cause us to lose track of its
1339 line number information. */
1340 watch_main_source_file_lossage ();
1342 /* Now create the symtab objects proper, if not already done,
1343 one for each subfile. */
1345 for (subfile = buildsym_compunit->subfiles;
1347 subfile = subfile->next)
1349 int linetablesize = 0;
1351 if (subfile->line_vector)
1353 linetablesize = sizeof (struct linetable) +
1354 subfile->line_vector->nitems * sizeof (struct linetable_entry);
1356 /* Like the pending blocks, the line table may be
1357 scrambled in reordered executables. Sort it if
1358 OBJF_REORDERED is true. */
1359 if (objfile->flags & OBJF_REORDERED)
1360 qsort (subfile->line_vector->item,
1361 subfile->line_vector->nitems,
1362 sizeof (struct linetable_entry), compare_line_numbers);
1365 /* Allocate a symbol table if necessary. */
1366 if (subfile->symtab == NULL)
1367 subfile->symtab = allocate_symtab (cu, subfile->name);
1368 symtab = subfile->symtab;
1370 /* Fill in its components. */
1372 if (subfile->line_vector)
1374 /* Reallocate the line table on the symbol obstack. */
1375 SYMTAB_LINETABLE (symtab) = (struct linetable *)
1376 obstack_alloc (&objfile->objfile_obstack, linetablesize);
1377 memcpy (SYMTAB_LINETABLE (symtab), subfile->line_vector,
1382 SYMTAB_LINETABLE (symtab) = NULL;
1385 /* Use whatever language we have been using for this
1386 subfile, not the one that was deduced in allocate_symtab
1387 from the filename. We already did our own deducing when
1388 we created the subfile, and we may have altered our
1389 opinion of what language it is from things we found in
1391 symtab->language = subfile->language;
1394 /* Make sure the symtab of main_subfile is the first in its list. */
1396 struct symtab *main_symtab, *prev_symtab;
1398 main_symtab = buildsym_compunit->main_subfile->symtab;
1400 ALL_COMPUNIT_FILETABS (cu, symtab)
1402 if (symtab == main_symtab)
1404 if (prev_symtab != NULL)
1406 prev_symtab->next = main_symtab->next;
1407 main_symtab->next = COMPUNIT_FILETABS (cu);
1408 COMPUNIT_FILETABS (cu) = main_symtab;
1412 prev_symtab = symtab;
1414 gdb_assert (main_symtab == COMPUNIT_FILETABS (cu));
1417 /* Fill out the compunit symtab. */
1419 if (buildsym_compunit->comp_dir != NULL)
1421 /* Reallocate the dirname on the symbol obstack. */
1422 const char *comp_dir = buildsym_compunit->comp_dir.get ();
1423 COMPUNIT_DIRNAME (cu)
1424 = (const char *) obstack_copy0 (&objfile->objfile_obstack,
1425 comp_dir, strlen (comp_dir));
1428 /* Save the debug format string (if any) in the symtab. */
1429 COMPUNIT_DEBUGFORMAT (cu) = buildsym_compunit->debugformat;
1431 /* Similarly for the producer. */
1432 COMPUNIT_PRODUCER (cu) = buildsym_compunit->producer;
1434 COMPUNIT_BLOCKVECTOR (cu) = blockvector;
1436 struct block *b = BLOCKVECTOR_BLOCK (blockvector, GLOBAL_BLOCK);
1438 set_block_compunit_symtab (b, cu);
1441 COMPUNIT_BLOCK_LINE_SECTION (cu) = section;
1443 COMPUNIT_MACRO_TABLE (cu) = buildsym_compunit->release_macros ();
1445 /* Default any symbols without a specified symtab to the primary symtab. */
1449 /* The main source file's symtab. */
1450 symtab = COMPUNIT_FILETABS (cu);
1452 for (block_i = 0; block_i < BLOCKVECTOR_NBLOCKS (blockvector); block_i++)
1454 struct block *block = BLOCKVECTOR_BLOCK (blockvector, block_i);
1456 struct dict_iterator iter;
1458 /* Inlined functions may have symbols not in the global or
1459 static symbol lists. */
1460 if (BLOCK_FUNCTION (block) != NULL)
1461 if (symbol_symtab (BLOCK_FUNCTION (block)) == NULL)
1462 symbol_set_symtab (BLOCK_FUNCTION (block), symtab);
1464 /* Note that we only want to fix up symbols from the local
1465 blocks, not blocks coming from included symtabs. That is why
1466 we use ALL_DICT_SYMBOLS here and not ALL_BLOCK_SYMBOLS. */
1467 ALL_DICT_SYMBOLS (BLOCK_DICT (block), iter, sym)
1468 if (symbol_symtab (sym) == NULL)
1469 symbol_set_symtab (sym, symtab);
1473 add_compunit_symtab_to_objfile (cu);
1478 /* Implementation of the second part of end_symtab. Pass STATIC_BLOCK
1479 as value returned by end_symtab_get_static_block.
1481 SECTION is the same as for end_symtab: the section number
1482 (in objfile->section_offsets) of the blockvector and linetable.
1484 If EXPANDABLE is non-zero the GLOBAL_BLOCK dictionary is made
1487 struct compunit_symtab *
1488 end_symtab_from_static_block (struct block *static_block,
1489 int section, int expandable)
1491 struct compunit_symtab *cu;
1493 if (static_block == NULL)
1495 /* Handle the "no blockvector" case.
1496 When this happens there is nothing to record, so there's nothing
1497 to do: memory will be freed up later.
1499 Note: We won't be adding a compunit to the objfile's list of
1500 compunits, so there's nothing to unchain. However, since each symtab
1501 is added to the objfile's obstack we can't free that space.
1502 We could do better, but this is believed to be a sufficiently rare
1507 cu = end_symtab_with_blockvector (static_block, section, expandable);
1509 reset_symtab_globals ();
1514 /* Finish the symbol definitions for one main source file, close off
1515 all the lexical contexts for that file (creating struct block's for
1516 them), then make the struct symtab for that file and put it in the
1519 END_ADDR is the address of the end of the file's text. SECTION is
1520 the section number (in objfile->section_offsets) of the blockvector
1523 Note that it is possible for end_symtab() to return NULL. In
1524 particular, for the DWARF case at least, it will return NULL when
1525 it finds a compilation unit that has exactly one DIE, a
1526 TAG_compile_unit DIE. This can happen when we link in an object
1527 file that was compiled from an empty source file. Returning NULL
1528 is probably not the correct thing to do, because then gdb will
1529 never know about this empty file (FIXME).
1531 If you need to modify STATIC_BLOCK before it is finalized you should
1532 call end_symtab_get_static_block and end_symtab_from_static_block
1535 struct compunit_symtab *
1536 end_symtab (CORE_ADDR end_addr, int section)
1538 struct block *static_block;
1540 static_block = end_symtab_get_static_block (end_addr, 0, 0);
1541 return end_symtab_from_static_block (static_block, section, 0);
1544 /* Same as end_symtab except create a symtab that can be later added to. */
1546 struct compunit_symtab *
1547 end_expandable_symtab (CORE_ADDR end_addr, int section)
1549 struct block *static_block;
1551 static_block = end_symtab_get_static_block (end_addr, 1, 0);
1552 return end_symtab_from_static_block (static_block, section, 1);
1555 /* Subroutine of augment_type_symtab to simplify it.
1556 Attach the main source file's symtab to all symbols in PENDING_LIST that
1560 set_missing_symtab (struct pending *pending_list,
1561 struct compunit_symtab *cu)
1563 struct pending *pending;
1566 for (pending = pending_list; pending != NULL; pending = pending->next)
1568 for (i = 0; i < pending->nsyms; ++i)
1570 if (symbol_symtab (pending->symbol[i]) == NULL)
1571 symbol_set_symtab (pending->symbol[i], COMPUNIT_FILETABS (cu));
1576 /* Same as end_symtab, but for the case where we're adding more symbols
1577 to an existing symtab that is known to contain only type information.
1578 This is the case for DWARF4 Type Units. */
1581 augment_type_symtab (void)
1583 struct compunit_symtab *cust = buildsym_compunit->compunit_symtab;
1584 const struct blockvector *blockvector = COMPUNIT_BLOCKVECTOR (cust);
1586 if (context_stack_depth > 0)
1588 complaint (_("Context stack not empty in augment_type_symtab"));
1589 context_stack_depth = 0;
1591 if (pending_blocks != NULL)
1592 complaint (_("Blocks in a type symtab"));
1593 if (buildsym_compunit->m_pending_macros != NULL)
1594 complaint (_("Macro in a type symtab"));
1595 if (buildsym_compunit->m_have_line_numbers)
1596 complaint (_("Line numbers recorded in a type symtab"));
1598 if (file_symbols != NULL)
1600 struct block *block = BLOCKVECTOR_BLOCK (blockvector, STATIC_BLOCK);
1602 /* First mark any symbols without a specified symtab as belonging
1603 to the primary symtab. */
1604 set_missing_symtab (file_symbols, cust);
1606 dict_add_pending (BLOCK_DICT (block), file_symbols);
1609 if (global_symbols != NULL)
1611 struct block *block = BLOCKVECTOR_BLOCK (blockvector, GLOBAL_BLOCK);
1613 /* First mark any symbols without a specified symtab as belonging
1614 to the primary symtab. */
1615 set_missing_symtab (global_symbols, cust);
1617 dict_add_pending (BLOCK_DICT (block), global_symbols);
1620 reset_symtab_globals ();
1623 /* Push a context block. Args are an identifying nesting level
1624 (checkable when you pop it), and the starting PC address of this
1627 struct context_stack *
1628 push_context (int desc, CORE_ADDR valu)
1630 struct context_stack *newobj;
1632 if (context_stack_depth == context_stack_size)
1634 context_stack_size *= 2;
1635 context_stack = (struct context_stack *)
1636 xrealloc ((char *) context_stack,
1637 (context_stack_size * sizeof (struct context_stack)));
1640 newobj = &context_stack[context_stack_depth++];
1641 newobj->depth = desc;
1642 newobj->locals = local_symbols;
1643 newobj->old_blocks = pending_blocks;
1644 newobj->start_addr = valu;
1645 newobj->local_using_directives = local_using_directives;
1646 newobj->name = NULL;
1648 local_symbols = NULL;
1649 local_using_directives = NULL;
1654 /* Pop a context block. Returns the address of the context block just
1657 struct context_stack *
1660 gdb_assert (context_stack_depth > 0);
1661 return (&context_stack[--context_stack_depth]);
1666 /* Compute a small integer hash code for the given name. */
1669 hashname (const char *name)
1671 return (hash(name,strlen(name)) % HASHSIZE);
1676 record_debugformat (const char *format)
1678 buildsym_compunit->debugformat = format;
1682 record_producer (const char *producer)
1684 buildsym_compunit->producer = producer;
1687 /* Merge the first symbol list SRCLIST into the second symbol list
1688 TARGETLIST by repeated calls to add_symbol_to_list(). This
1689 procedure "frees" each link of SRCLIST by adding it to the
1690 free_pendings list. Caller must set SRCLIST to a null list after
1691 calling this function.
1696 merge_symbol_lists (struct pending **srclist, struct pending **targetlist)
1700 if (!srclist || !*srclist)
1703 /* Merge in elements from current link. */
1704 for (i = 0; i < (*srclist)->nsyms; i++)
1705 add_symbol_to_list ((*srclist)->symbol[i], targetlist);
1707 /* Recurse on next. */
1708 merge_symbol_lists (&(*srclist)->next, targetlist);
1710 /* "Free" the current link. */
1711 (*srclist)->next = free_pendings;
1712 free_pendings = (*srclist);
1716 /* See buildsym.h. */
1719 set_last_source_file (const char *name)
1721 gdb_assert (buildsym_compunit != nullptr || name == nullptr);
1722 if (buildsym_compunit != nullptr)
1723 buildsym_compunit->set_last_source_file (name);
1726 /* See buildsym.h. */
1729 get_last_source_file (void)
1731 if (buildsym_compunit == nullptr)
1733 return buildsym_compunit->m_last_source_file.get ();
1736 /* See buildsym.h. */
1739 set_last_source_start_addr (CORE_ADDR addr)
1741 gdb_assert (buildsym_compunit != nullptr);
1742 buildsym_compunit->m_last_source_start_addr = addr;
1745 /* See buildsym.h. */
1748 get_last_source_start_addr ()
1750 gdb_assert (buildsym_compunit != nullptr);
1751 return buildsym_compunit->m_last_source_start_addr;
1756 /* Initialize anything that needs initializing when starting to read a
1757 fresh piece of a symbol file, e.g. reading in the stuff
1758 corresponding to a psymtab. */
1761 buildsym_init (void)
1763 subfile_stack = NULL;
1765 pending_addrmap_interesting = 0;
1767 /* Context stack is initially empty. Allocate first one with room
1768 for a few levels; reuse it forever afterward. */
1769 if (context_stack == NULL)
1771 context_stack_size = INITIAL_CONTEXT_STACK_SIZE;
1772 context_stack = XNEWVEC (struct context_stack, context_stack_size);
1775 /* Ensure the scoped_free_pendings destructor was called after
1777 gdb_assert (free_pendings == NULL);
1778 gdb_assert (pending_blocks == NULL);
1779 gdb_assert (file_symbols == NULL);
1780 gdb_assert (global_symbols == NULL);
1781 gdb_assert (global_using_directives == NULL);
1782 gdb_assert (pending_addrmap == NULL);
1783 gdb_assert (buildsym_compunit == NULL);
1786 /* Initialize anything that needs initializing when a completely new
1787 symbol file is specified (not just adding some symbols from another
1788 file, e.g. a shared library). */
1791 buildsym_new_init (void)