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.
94 TODO(dje): Move all related global state into here. */
96 struct buildsym_compunit
98 /* Start recording information about a primary source file (IOW, not an
99 included source file).
100 COMP_DIR is the directory in which the compilation unit was compiled
101 (or NULL if not known). */
103 buildsym_compunit (struct objfile
*objfile_
, const char *name
,
104 const char *comp_dir_
, enum language language_
,
106 : objfile (objfile_
),
107 m_last_source_file (name
== nullptr ? nullptr : xstrdup (name
)),
108 comp_dir (comp_dir_
== nullptr ? nullptr : xstrdup (comp_dir_
)),
109 language (language_
),
110 m_last_source_start_addr (last_addr
)
114 ~buildsym_compunit ()
116 struct subfile
*subfile
, *nextsub
;
118 if (m_pending_macros
!= nullptr)
119 free_macro_table (m_pending_macros
);
121 for (subfile
= subfiles
;
125 nextsub
= subfile
->next
;
126 xfree (subfile
->name
);
127 xfree (subfile
->line_vector
);
131 struct pending
*next
, *next1
;
133 for (next
= m_file_symbols
; next
!= NULL
; next
= next1
)
136 xfree ((void *) next
);
139 for (next
= m_global_symbols
; next
!= NULL
; next
= next1
)
142 xfree ((void *) next
);
146 void set_last_source_file (const char *name
)
148 char *new_name
= name
== NULL
? NULL
: xstrdup (name
);
149 m_last_source_file
.reset (new_name
);
152 struct macro_table
*get_macro_table ()
154 if (m_pending_macros
== nullptr)
155 m_pending_macros
= new_macro_table (&objfile
->per_bfd
->storage_obstack
,
156 objfile
->per_bfd
->macro_cache
,
158 return m_pending_macros
;
161 struct macro_table
*release_macros ()
163 struct macro_table
*result
= m_pending_macros
;
164 m_pending_macros
= nullptr;
168 /* This function is called to discard any pending blocks. */
170 void free_pending_blocks ()
172 m_pending_block_obstack
.clear ();
173 m_pending_blocks
= nullptr;
176 /* The objfile we're reading debug info from. */
177 struct objfile
*objfile
;
179 /* List of subfiles (source files).
180 Files are added to the front of the list.
181 This is important mostly for the language determination hacks we use,
182 which iterate over previously added files. */
183 struct subfile
*subfiles
= nullptr;
185 /* The subfile of the main source file. */
186 struct subfile
*main_subfile
= nullptr;
188 /* Name of source file whose symbol data we are now processing. This
189 comes from a symbol of type N_SO for stabs. For DWARF it comes
190 from the DW_AT_name attribute of a DW_TAG_compile_unit DIE. */
191 gdb::unique_xmalloc_ptr
<char> m_last_source_file
;
193 /* E.g., DW_AT_comp_dir if DWARF. Space for this is malloc'd. */
194 gdb::unique_xmalloc_ptr
<char> comp_dir
;
196 /* Space for this is not malloc'd, and is assumed to have at least
197 the same lifetime as objfile. */
198 const char *producer
= nullptr;
200 /* Space for this is not malloc'd, and is assumed to have at least
201 the same lifetime as objfile. */
202 const char *debugformat
= nullptr;
204 /* The compunit we are building. */
205 struct compunit_symtab
*compunit_symtab
= nullptr;
207 /* Language of this compunit_symtab. */
208 enum language language
;
210 /* The macro table for the compilation unit whose symbols we're
211 currently reading. */
212 struct macro_table
*m_pending_macros
= nullptr;
214 /* True if symtab has line number info. This prevents an otherwise
215 empty symtab from being tossed. */
216 bool m_have_line_numbers
= false;
218 /* Core address of start of text of current source file. This too
219 comes from the N_SO symbol. For Dwarf it typically comes from the
220 DW_AT_low_pc attribute of a DW_TAG_compile_unit DIE. */
221 CORE_ADDR m_last_source_start_addr
;
223 /* Stack of subfile names. */
224 std::vector
<const char *> m_subfile_stack
;
226 /* The "using" directives local to lexical context. */
227 struct using_direct
*m_local_using_directives
= nullptr;
229 /* Global "using" directives. */
230 struct using_direct
*m_global_using_directives
= nullptr;
232 /* The stack of contexts that are pushed by push_context and popped
234 std::vector
<struct context_stack
> m_context_stack
;
236 struct subfile
*m_current_subfile
= nullptr;
238 /* The mutable address map for the compilation unit whose symbols
239 we're currently reading. The symtabs' shared blockvector will
240 point to a fixed copy of this. */
241 struct addrmap
*m_pending_addrmap
= nullptr;
243 /* The obstack on which we allocate pending_addrmap.
244 If pending_addrmap is NULL, this is uninitialized; otherwise, it is
245 initialized (and holds pending_addrmap). */
246 auto_obstack m_pending_addrmap_obstack
;
248 /* True if we recorded any ranges in the addrmap that are different
249 from those in the blockvector already. We set this to false when
250 we start processing a symfile, and if it's still false at the
251 end, then we just toss the addrmap. */
252 bool m_pending_addrmap_interesting
= false;
254 /* An obstack used for allocating pending blocks. */
255 auto_obstack m_pending_block_obstack
;
257 /* Pointer to the head of a linked list of symbol blocks which have
258 already been finalized (lexical contexts already closed) and which
259 are just waiting to be built into a blockvector when finalizing the
260 associated symtab. */
261 struct pending_block
*m_pending_blocks
= nullptr;
263 /* Pending static symbols and types at the top level. */
264 struct pending
*m_file_symbols
= nullptr;
266 /* Pending global functions and variables. */
267 struct pending
*m_global_symbols
= nullptr;
269 /* Pending symbols that are local to the lexical context. */
270 struct pending
*m_local_symbols
= nullptr;
273 /* The work-in-progress of the compunit we are building.
274 This is created first, before any subfiles by start_symtab. */
276 static struct buildsym_compunit
*buildsym_compunit
;
278 /* List of blocks already made (lexical contexts already closed).
279 This is used at the end to make the blockvector. */
283 struct pending_block
*next
;
287 static void free_buildsym_compunit (void);
289 static int compare_line_numbers (const void *ln1p
, const void *ln2p
);
291 static void record_pending_block (struct objfile
*objfile
,
293 struct pending_block
*opblock
);
295 /* Initial sizes of data structures. These are realloc'd larger if
296 needed, and realloc'd down to the size actually used, when
299 #define INITIAL_LINE_VECTOR_LENGTH 1000
302 /* Maintain the lists of symbols and blocks. */
304 /* Add a symbol to one of the lists of symbols. */
307 add_symbol_to_list (struct symbol
*symbol
, struct pending
**listhead
)
309 struct pending
*link
;
311 /* If this is an alias for another symbol, don't add it. */
312 if (symbol
->ginfo
.name
&& symbol
->ginfo
.name
[0] == '#')
315 /* We keep PENDINGSIZE symbols in each link of the list. If we
316 don't have a link with room in it, add a new link. */
317 if (*listhead
== NULL
|| (*listhead
)->nsyms
== PENDINGSIZE
)
319 link
= XNEW (struct pending
);
320 link
->next
= *listhead
;
325 (*listhead
)->symbol
[(*listhead
)->nsyms
++] = symbol
;
328 /* Find a symbol named NAME on a LIST. NAME need not be
329 '\0'-terminated; LENGTH is the length of the name. */
332 find_symbol_in_list (struct pending
*list
, char *name
, int length
)
339 for (j
= list
->nsyms
; --j
>= 0;)
341 pp
= SYMBOL_LINKAGE_NAME (list
->symbol
[j
]);
342 if (*pp
== *name
&& strncmp (pp
, name
, length
) == 0
343 && pp
[length
] == '\0')
345 return (list
->symbol
[j
]);
353 /* At end of reading syms, or in case of quit, ensure everything
354 associated with building symtabs is freed.
356 N.B. This is *not* intended to be used when building psymtabs. Some debug
357 info readers call this anyway, which is harmless if confusing. */
359 scoped_free_pendings::~scoped_free_pendings ()
361 free_buildsym_compunit ();
364 /* Take one of the lists of symbols and make a block from it. Keep
365 the order the symbols have in the list (reversed from the input
366 file). Put the block on the list of pending blocks. */
368 static struct block
*
369 finish_block_internal (struct symbol
*symbol
,
370 struct pending
**listhead
,
371 struct pending_block
*old_blocks
,
372 const struct dynamic_prop
*static_link
,
373 CORE_ADDR start
, CORE_ADDR end
,
374 int is_global
, int expandable
)
376 struct objfile
*objfile
= buildsym_compunit
->objfile
;
377 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
378 struct pending
*next
, *next1
;
380 struct pending_block
*pblock
;
381 struct pending_block
*opblock
;
384 ? allocate_global_block (&objfile
->objfile_obstack
)
385 : allocate_block (&objfile
->objfile_obstack
));
390 = dict_create_linear (&objfile
->objfile_obstack
,
391 buildsym_compunit
->language
, *listhead
);
398 = dict_create_hashed_expandable (buildsym_compunit
->language
);
399 dict_add_pending (BLOCK_DICT (block
), *listhead
);
404 dict_create_hashed (&objfile
->objfile_obstack
,
405 buildsym_compunit
->language
, *listhead
);
409 BLOCK_START (block
) = start
;
410 BLOCK_END (block
) = end
;
412 /* Put the block in as the value of the symbol that names it. */
416 struct type
*ftype
= SYMBOL_TYPE (symbol
);
417 struct dict_iterator iter
;
418 SYMBOL_BLOCK_VALUE (symbol
) = block
;
419 BLOCK_FUNCTION (block
) = symbol
;
421 if (TYPE_NFIELDS (ftype
) <= 0)
423 /* No parameter type information is recorded with the
424 function's type. Set that from the type of the
425 parameter symbols. */
426 int nparams
= 0, iparams
;
429 /* Here we want to directly access the dictionary, because
430 we haven't fully initialized the block yet. */
431 ALL_DICT_SYMBOLS (BLOCK_DICT (block
), iter
, sym
)
433 if (SYMBOL_IS_ARGUMENT (sym
))
438 TYPE_NFIELDS (ftype
) = nparams
;
439 TYPE_FIELDS (ftype
) = (struct field
*)
440 TYPE_ALLOC (ftype
, nparams
* sizeof (struct field
));
443 /* Here we want to directly access the dictionary, because
444 we haven't fully initialized the block yet. */
445 ALL_DICT_SYMBOLS (BLOCK_DICT (block
), iter
, sym
)
447 if (iparams
== nparams
)
450 if (SYMBOL_IS_ARGUMENT (sym
))
452 TYPE_FIELD_TYPE (ftype
, iparams
) = SYMBOL_TYPE (sym
);
453 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
462 BLOCK_FUNCTION (block
) = NULL
;
465 if (static_link
!= NULL
)
466 objfile_register_static_link (objfile
, block
, static_link
);
468 /* Now free the links of the list, and empty the list. */
470 for (next
= *listhead
; next
; next
= next1
)
477 /* Check to be sure that the blocks have an end address that is
478 greater than starting address. */
480 if (BLOCK_END (block
) < BLOCK_START (block
))
484 complaint (_("block end address less than block "
485 "start address in %s (patched it)"),
486 SYMBOL_PRINT_NAME (symbol
));
490 complaint (_("block end address %s less than block "
491 "start address %s (patched it)"),
492 paddress (gdbarch
, BLOCK_END (block
)),
493 paddress (gdbarch
, BLOCK_START (block
)));
495 /* Better than nothing. */
496 BLOCK_END (block
) = BLOCK_START (block
);
499 /* Install this block as the superblock of all blocks made since the
500 start of this scope that don't have superblocks yet. */
503 for (pblock
= buildsym_compunit
->m_pending_blocks
;
504 pblock
&& pblock
!= old_blocks
;
505 pblock
= pblock
->next
)
507 if (BLOCK_SUPERBLOCK (pblock
->block
) == NULL
)
509 /* Check to be sure the blocks are nested as we receive
510 them. If the compiler/assembler/linker work, this just
511 burns a small amount of time.
513 Skip blocks which correspond to a function; they're not
514 physically nested inside this other blocks, only
516 if (BLOCK_FUNCTION (pblock
->block
) == NULL
517 && (BLOCK_START (pblock
->block
) < BLOCK_START (block
)
518 || BLOCK_END (pblock
->block
) > BLOCK_END (block
)))
522 complaint (_("inner block not inside outer block in %s"),
523 SYMBOL_PRINT_NAME (symbol
));
527 complaint (_("inner block (%s-%s) not "
528 "inside outer block (%s-%s)"),
529 paddress (gdbarch
, BLOCK_START (pblock
->block
)),
530 paddress (gdbarch
, BLOCK_END (pblock
->block
)),
531 paddress (gdbarch
, BLOCK_START (block
)),
532 paddress (gdbarch
, BLOCK_END (block
)));
534 if (BLOCK_START (pblock
->block
) < BLOCK_START (block
))
535 BLOCK_START (pblock
->block
) = BLOCK_START (block
);
536 if (BLOCK_END (pblock
->block
) > BLOCK_END (block
))
537 BLOCK_END (pblock
->block
) = BLOCK_END (block
);
539 BLOCK_SUPERBLOCK (pblock
->block
) = block
;
544 block_set_using (block
,
546 ? buildsym_compunit
->m_global_using_directives
547 : buildsym_compunit
->m_local_using_directives
),
548 &objfile
->objfile_obstack
);
550 buildsym_compunit
->m_global_using_directives
= NULL
;
552 buildsym_compunit
->m_local_using_directives
= NULL
;
554 record_pending_block (objfile
, block
, opblock
);
560 finish_block (struct symbol
*symbol
,
561 struct pending_block
*old_blocks
,
562 const struct dynamic_prop
*static_link
,
563 CORE_ADDR start
, CORE_ADDR end
)
565 return finish_block_internal (symbol
, &buildsym_compunit
->m_local_symbols
,
566 old_blocks
, static_link
,
570 /* Record BLOCK on the list of all blocks in the file. Put it after
571 OPBLOCK, or at the beginning if opblock is NULL. This puts the
572 block in the list after all its subblocks.
574 Allocate the pending block struct in the objfile_obstack to save
575 time. This wastes a little space. FIXME: Is it worth it? */
578 record_pending_block (struct objfile
*objfile
, struct block
*block
,
579 struct pending_block
*opblock
)
581 struct pending_block
*pblock
;
583 pblock
= XOBNEW (&buildsym_compunit
->m_pending_block_obstack
,
584 struct pending_block
);
585 pblock
->block
= block
;
588 pblock
->next
= opblock
->next
;
589 opblock
->next
= pblock
;
593 pblock
->next
= buildsym_compunit
->m_pending_blocks
;
594 buildsym_compunit
->m_pending_blocks
= pblock
;
599 /* Record that the range of addresses from START to END_INCLUSIVE
600 (inclusive, like it says) belongs to BLOCK. BLOCK's start and end
601 addresses must be set already. You must apply this function to all
602 BLOCK's children before applying it to BLOCK.
604 If a call to this function complicates the picture beyond that
605 already provided by BLOCK_START and BLOCK_END, then we create an
606 address map for the block. */
608 record_block_range (struct block
*block
,
609 CORE_ADDR start
, CORE_ADDR end_inclusive
)
611 /* If this is any different from the range recorded in the block's
612 own BLOCK_START and BLOCK_END, then note that the address map has
613 become interesting. Note that even if this block doesn't have
614 any "interesting" ranges, some later block might, so we still
615 need to record this block in the addrmap. */
616 if (start
!= BLOCK_START (block
)
617 || end_inclusive
+ 1 != BLOCK_END (block
))
618 buildsym_compunit
->m_pending_addrmap_interesting
= true;
620 if (buildsym_compunit
->m_pending_addrmap
== nullptr)
621 buildsym_compunit
->m_pending_addrmap
622 = addrmap_create_mutable (&buildsym_compunit
->m_pending_addrmap_obstack
);
624 addrmap_set_empty (buildsym_compunit
->m_pending_addrmap
,
625 start
, end_inclusive
, block
);
628 static struct blockvector
*
629 make_blockvector (void)
631 struct objfile
*objfile
= buildsym_compunit
->objfile
;
632 struct pending_block
*next
;
633 struct blockvector
*blockvector
;
636 /* Count the length of the list of blocks. */
638 for (next
= buildsym_compunit
->m_pending_blocks
, i
= 0;
640 next
= next
->next
, i
++)
644 blockvector
= (struct blockvector
*)
645 obstack_alloc (&objfile
->objfile_obstack
,
646 (sizeof (struct blockvector
)
647 + (i
- 1) * sizeof (struct block
*)));
649 /* Copy the blocks into the blockvector. This is done in reverse
650 order, which happens to put the blocks into the proper order
651 (ascending starting address). finish_block has hair to insert
652 each block into the list after its subblocks in order to make
653 sure this is true. */
655 BLOCKVECTOR_NBLOCKS (blockvector
) = i
;
656 for (next
= buildsym_compunit
->m_pending_blocks
; next
; next
= next
->next
)
658 BLOCKVECTOR_BLOCK (blockvector
, --i
) = next
->block
;
661 buildsym_compunit
->free_pending_blocks ();
663 /* If we needed an address map for this symtab, record it in the
665 if (buildsym_compunit
->m_pending_addrmap
!= nullptr
666 && buildsym_compunit
->m_pending_addrmap_interesting
)
667 BLOCKVECTOR_MAP (blockvector
)
668 = addrmap_create_fixed (buildsym_compunit
->m_pending_addrmap
,
669 &objfile
->objfile_obstack
);
671 BLOCKVECTOR_MAP (blockvector
) = 0;
673 /* Some compilers output blocks in the wrong order, but we depend on
674 their being in the right order so we can binary search. Check the
675 order and moan about it.
676 Note: Remember that the first two blocks are the global and static
677 blocks. We could special case that fact and begin checking at block 2.
678 To avoid making that assumption we do not. */
679 if (BLOCKVECTOR_NBLOCKS (blockvector
) > 1)
681 for (i
= 1; i
< BLOCKVECTOR_NBLOCKS (blockvector
); i
++)
683 if (BLOCK_START (BLOCKVECTOR_BLOCK (blockvector
, i
- 1))
684 > BLOCK_START (BLOCKVECTOR_BLOCK (blockvector
, i
)))
687 = BLOCK_START (BLOCKVECTOR_BLOCK (blockvector
, i
));
689 complaint (_("block at %s out of order"),
690 hex_string ((LONGEST
) start
));
695 return (blockvector
);
698 /* Start recording information about source code that came from an
699 included (or otherwise merged-in) source file with a different
700 name. NAME is the name of the file (cannot be NULL). */
703 start_subfile (const char *name
)
705 const char *subfile_dirname
;
706 struct subfile
*subfile
;
708 gdb_assert (buildsym_compunit
!= NULL
);
710 subfile_dirname
= buildsym_compunit
->comp_dir
.get ();
712 /* See if this subfile is already registered. */
714 for (subfile
= buildsym_compunit
->subfiles
; subfile
; subfile
= subfile
->next
)
718 /* If NAME is an absolute path, and this subfile is not, then
719 attempt to create an absolute path to compare. */
720 if (IS_ABSOLUTE_PATH (name
)
721 && !IS_ABSOLUTE_PATH (subfile
->name
)
722 && subfile_dirname
!= NULL
)
723 subfile_name
= concat (subfile_dirname
, SLASH_STRING
,
724 subfile
->name
, (char *) NULL
);
726 subfile_name
= subfile
->name
;
728 if (FILENAME_CMP (subfile_name
, name
) == 0)
730 buildsym_compunit
->m_current_subfile
= subfile
;
731 if (subfile_name
!= subfile
->name
)
732 xfree (subfile_name
);
735 if (subfile_name
!= subfile
->name
)
736 xfree (subfile_name
);
739 /* This subfile is not known. Add an entry for it. */
741 subfile
= XNEW (struct subfile
);
742 memset (subfile
, 0, sizeof (struct subfile
));
743 subfile
->buildsym_compunit
= buildsym_compunit
;
745 subfile
->next
= buildsym_compunit
->subfiles
;
746 buildsym_compunit
->subfiles
= subfile
;
748 buildsym_compunit
->m_current_subfile
= subfile
;
750 subfile
->name
= xstrdup (name
);
752 /* Initialize line-number recording for this subfile. */
753 subfile
->line_vector
= NULL
;
755 /* Default the source language to whatever can be deduced from the
756 filename. If nothing can be deduced (such as for a C/C++ include
757 file with a ".h" extension), then inherit whatever language the
758 previous subfile had. This kludgery is necessary because there
759 is no standard way in some object formats to record the source
760 language. Also, when symtabs are allocated we try to deduce a
761 language then as well, but it is too late for us to use that
762 information while reading symbols, since symtabs aren't allocated
763 until after all the symbols have been processed for a given
766 subfile
->language
= deduce_language_from_filename (subfile
->name
);
767 if (subfile
->language
== language_unknown
768 && subfile
->next
!= NULL
)
770 subfile
->language
= subfile
->next
->language
;
773 /* If the filename of this subfile ends in .C, then change the
774 language of any pending subfiles from C to C++. We also accept
775 any other C++ suffixes accepted by deduce_language_from_filename. */
776 /* Likewise for f2c. */
781 enum language sublang
= deduce_language_from_filename (subfile
->name
);
783 if (sublang
== language_cplus
|| sublang
== language_fortran
)
784 for (s
= buildsym_compunit
->subfiles
; s
!= NULL
; s
= s
->next
)
785 if (s
->language
== language_c
)
786 s
->language
= sublang
;
789 /* And patch up this file if necessary. */
790 if (subfile
->language
== language_c
791 && subfile
->next
!= NULL
792 && (subfile
->next
->language
== language_cplus
793 || subfile
->next
->language
== language_fortran
))
795 subfile
->language
= subfile
->next
->language
;
799 /* Delete the buildsym compunit. */
802 free_buildsym_compunit (void)
804 if (buildsym_compunit
== NULL
)
806 delete buildsym_compunit
;
807 buildsym_compunit
= NULL
;
810 /* For stabs readers, the first N_SO symbol is assumed to be the
811 source file name, and the subfile struct is initialized using that
812 assumption. If another N_SO symbol is later seen, immediately
813 following the first one, then the first one is assumed to be the
814 directory name and the second one is really the source file name.
816 So we have to patch up the subfile struct by moving the old name
817 value to dirname and remembering the new name. Some sanity
818 checking is performed to ensure that the state of the subfile
819 struct is reasonable and that the old name we are assuming to be a
820 directory name actually is (by checking for a trailing '/'). */
823 patch_subfile_names (struct subfile
*subfile
, const char *name
)
826 && buildsym_compunit
->comp_dir
== NULL
827 && subfile
->name
!= NULL
828 && IS_DIR_SEPARATOR (subfile
->name
[strlen (subfile
->name
) - 1]))
830 buildsym_compunit
->comp_dir
.reset (subfile
->name
);
831 subfile
->name
= xstrdup (name
);
832 set_last_source_file (name
);
834 /* Default the source language to whatever can be deduced from
835 the filename. If nothing can be deduced (such as for a C/C++
836 include file with a ".h" extension), then inherit whatever
837 language the previous subfile had. This kludgery is
838 necessary because there is no standard way in some object
839 formats to record the source language. Also, when symtabs
840 are allocated we try to deduce a language then as well, but
841 it is too late for us to use that information while reading
842 symbols, since symtabs aren't allocated until after all the
843 symbols have been processed for a given source file. */
845 subfile
->language
= deduce_language_from_filename (subfile
->name
);
846 if (subfile
->language
== language_unknown
847 && subfile
->next
!= NULL
)
849 subfile
->language
= subfile
->next
->language
;
854 /* Handle the N_BINCL and N_EINCL symbol types that act like N_SOL for
855 switching source files (different subfiles, as we call them) within
856 one object file, but using a stack rather than in an arbitrary
862 gdb_assert (buildsym_compunit
!= nullptr);
863 gdb_assert (buildsym_compunit
->m_current_subfile
!= NULL
);
864 gdb_assert (buildsym_compunit
->m_current_subfile
->name
!= NULL
);
865 buildsym_compunit
->m_subfile_stack
.push_back
866 (buildsym_compunit
->m_current_subfile
->name
);
872 gdb_assert (buildsym_compunit
!= nullptr);
873 gdb_assert (!buildsym_compunit
->m_subfile_stack
.empty ());
874 const char *name
= buildsym_compunit
->m_subfile_stack
.back ();
875 buildsym_compunit
->m_subfile_stack
.pop_back ();
879 /* Add a linetable entry for line number LINE and address PC to the
880 line vector for SUBFILE. */
883 record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
885 struct linetable_entry
*e
;
887 /* Ignore the dummy line number in libg.o */
893 /* Make sure line vector exists and is big enough. */
894 if (!subfile
->line_vector
)
896 subfile
->line_vector_length
= INITIAL_LINE_VECTOR_LENGTH
;
897 subfile
->line_vector
= (struct linetable
*)
898 xmalloc (sizeof (struct linetable
)
899 + subfile
->line_vector_length
* sizeof (struct linetable_entry
));
900 subfile
->line_vector
->nitems
= 0;
901 buildsym_compunit
->m_have_line_numbers
= true;
904 if (subfile
->line_vector
->nitems
+ 1 >= subfile
->line_vector_length
)
906 subfile
->line_vector_length
*= 2;
907 subfile
->line_vector
= (struct linetable
*)
908 xrealloc ((char *) subfile
->line_vector
,
909 (sizeof (struct linetable
)
910 + (subfile
->line_vector_length
911 * sizeof (struct linetable_entry
))));
914 /* Normally, we treat lines as unsorted. But the end of sequence
915 marker is special. We sort line markers at the same PC by line
916 number, so end of sequence markers (which have line == 0) appear
917 first. This is right if the marker ends the previous function,
918 and there is no padding before the next function. But it is
919 wrong if the previous line was empty and we are now marking a
920 switch to a different subfile. We must leave the end of sequence
921 marker at the end of this group of lines, not sort the empty line
922 to after the marker. The easiest way to accomplish this is to
923 delete any empty lines from our table, if they are followed by
924 end of sequence markers. All we lose is the ability to set
925 breakpoints at some lines which contain no instructions
927 if (line
== 0 && subfile
->line_vector
->nitems
> 0)
929 e
= subfile
->line_vector
->item
+ subfile
->line_vector
->nitems
- 1;
930 while (subfile
->line_vector
->nitems
> 0 && e
->pc
== pc
)
933 subfile
->line_vector
->nitems
--;
937 e
= subfile
->line_vector
->item
+ subfile
->line_vector
->nitems
++;
942 /* Needed in order to sort line tables from IBM xcoff files. Sigh! */
945 compare_line_numbers (const void *ln1p
, const void *ln2p
)
947 struct linetable_entry
*ln1
= (struct linetable_entry
*) ln1p
;
948 struct linetable_entry
*ln2
= (struct linetable_entry
*) ln2p
;
950 /* Note: this code does not assume that CORE_ADDRs can fit in ints.
951 Please keep it that way. */
952 if (ln1
->pc
< ln2
->pc
)
955 if (ln1
->pc
> ln2
->pc
)
958 /* If pc equal, sort by line. I'm not sure whether this is optimum
959 behavior (see comment at struct linetable in symtab.h). */
960 return ln1
->line
- ln2
->line
;
963 /* See buildsym.h. */
965 struct compunit_symtab
*
966 buildsym_compunit_symtab (void)
968 gdb_assert (buildsym_compunit
!= NULL
);
970 return buildsym_compunit
->compunit_symtab
;
973 /* See buildsym.h. */
976 get_macro_table (void)
978 struct objfile
*objfile
;
980 gdb_assert (buildsym_compunit
!= NULL
);
981 return buildsym_compunit
->get_macro_table ();
984 /* Start a new symtab for a new source file in OBJFILE. Called, for example,
985 when a stabs symbol of type N_SO is seen, or when a DWARF
986 TAG_compile_unit DIE is seen. It indicates the start of data for
987 one original source file.
989 NAME is the name of the file (cannot be NULL). COMP_DIR is the
990 directory in which the file was compiled (or NULL if not known).
991 START_ADDR is the lowest address of objects in the file (or 0 if
992 not known). LANGUAGE is the language of the source file, or
993 language_unknown if not known, in which case it'll be deduced from
996 struct compunit_symtab
*
997 start_symtab (struct objfile
*objfile
, const char *name
, const char *comp_dir
,
998 CORE_ADDR start_addr
, enum language language
)
1000 /* These should have been reset either by successful completion of building
1001 a symtab, or by the scoped_free_pendings destructor. */
1002 gdb_assert (buildsym_compunit
== nullptr);
1004 buildsym_compunit
= new struct buildsym_compunit (objfile
, name
, comp_dir
,
1005 language
, start_addr
);
1007 /* Allocate the compunit symtab now. The caller needs it to allocate
1008 non-primary symtabs. It is also needed by get_macro_table. */
1009 buildsym_compunit
->compunit_symtab
= allocate_compunit_symtab (objfile
,
1012 /* Build the subfile for NAME (the main source file) so that we can record
1013 a pointer to it for later.
1014 IMPORTANT: Do not allocate a struct symtab for NAME here.
1015 It can happen that the debug info provides a different path to NAME than
1016 DIRNAME,NAME. We cope with this in watch_main_source_file_lossage but
1017 that only works if the main_subfile doesn't have a symtab yet. */
1018 start_subfile (name
);
1019 /* Save this so that we don't have to go looking for it at the end
1020 of the subfiles list. */
1021 buildsym_compunit
->main_subfile
= buildsym_compunit
->m_current_subfile
;
1023 return buildsym_compunit
->compunit_symtab
;
1026 /* Restart compilation for a symtab.
1027 CUST is the result of end_expandable_symtab.
1028 NAME, START_ADDR are the source file we are resuming with.
1030 This is used when a symtab is built from multiple sources.
1031 The symtab is first built with start_symtab/end_expandable_symtab
1032 and then for each additional piece call restart_symtab/augment_*_symtab.
1033 Note: At the moment there is only augment_type_symtab. */
1036 restart_symtab (struct compunit_symtab
*cust
,
1037 const char *name
, CORE_ADDR start_addr
)
1039 /* These should have been reset either by successful completion of building
1040 a symtab, or by the scoped_free_pendings destructor. */
1041 gdb_assert (buildsym_compunit
== nullptr);
1044 = new struct buildsym_compunit (COMPUNIT_OBJFILE (cust
),
1046 COMPUNIT_DIRNAME (cust
),
1047 compunit_language (cust
),
1049 buildsym_compunit
->compunit_symtab
= cust
;
1052 /* Subroutine of end_symtab to simplify it. Look for a subfile that
1053 matches the main source file's basename. If there is only one, and
1054 if the main source file doesn't have any symbol or line number
1055 information, then copy this file's symtab and line_vector to the
1056 main source file's subfile and discard the other subfile. This can
1057 happen because of a compiler bug or from the user playing games
1058 with #line or from things like a distributed build system that
1059 manipulates the debug info. This can also happen from an innocent
1060 symlink in the paths, we don't canonicalize paths here. */
1063 watch_main_source_file_lossage (void)
1065 struct subfile
*mainsub
, *subfile
;
1067 /* We have to watch for buildsym_compunit == NULL here. It's a quirk of
1068 end_symtab, it can return NULL so there may not be a main subfile. */
1069 if (buildsym_compunit
== NULL
)
1072 /* Get the main source file. */
1073 mainsub
= buildsym_compunit
->main_subfile
;
1075 /* If the main source file doesn't have any line number or symbol
1076 info, look for an alias in another subfile. */
1078 if (mainsub
->line_vector
== NULL
1079 && mainsub
->symtab
== NULL
)
1081 const char *mainbase
= lbasename (mainsub
->name
);
1083 struct subfile
*prevsub
;
1084 struct subfile
*mainsub_alias
= NULL
;
1085 struct subfile
*prev_mainsub_alias
= NULL
;
1088 for (subfile
= buildsym_compunit
->subfiles
;
1090 subfile
= subfile
->next
)
1092 if (subfile
== mainsub
)
1094 if (filename_cmp (lbasename (subfile
->name
), mainbase
) == 0)
1097 mainsub_alias
= subfile
;
1098 prev_mainsub_alias
= prevsub
;
1103 if (nr_matches
== 1)
1105 gdb_assert (mainsub_alias
!= NULL
&& mainsub_alias
!= mainsub
);
1107 /* Found a match for the main source file.
1108 Copy its line_vector and symtab to the main subfile
1109 and then discard it. */
1111 mainsub
->line_vector
= mainsub_alias
->line_vector
;
1112 mainsub
->line_vector_length
= mainsub_alias
->line_vector_length
;
1113 mainsub
->symtab
= mainsub_alias
->symtab
;
1115 if (prev_mainsub_alias
== NULL
)
1116 buildsym_compunit
->subfiles
= mainsub_alias
->next
;
1118 prev_mainsub_alias
->next
= mainsub_alias
->next
;
1119 xfree (mainsub_alias
->name
);
1120 xfree (mainsub_alias
);
1125 /* Reset state after a successful building of a symtab. */
1128 reset_symtab_globals (void)
1130 free_buildsym_compunit ();
1133 /* Implementation of the first part of end_symtab. It allows modifying
1134 STATIC_BLOCK before it gets finalized by end_symtab_from_static_block.
1135 If the returned value is NULL there is no blockvector created for
1136 this symtab (you still must call end_symtab_from_static_block).
1138 END_ADDR is the same as for end_symtab: the address of the end of the
1141 If EXPANDABLE is non-zero the STATIC_BLOCK dictionary is made
1144 If REQUIRED is non-zero, then a symtab is created even if it does
1145 not contain any symbols. */
1148 end_symtab_get_static_block (CORE_ADDR end_addr
, int expandable
, int required
)
1150 struct objfile
*objfile
= buildsym_compunit
->objfile
;
1152 /* Finish the lexical context of the last function in the file; pop
1153 the context stack. */
1155 if (!buildsym_compunit
->m_context_stack
.empty ())
1157 struct context_stack cstk
= pop_context ();
1159 /* Make a block for the local symbols within. */
1160 finish_block (cstk
.name
, cstk
.old_blocks
, NULL
,
1161 cstk
.start_addr
, end_addr
);
1163 if (!buildsym_compunit
->m_context_stack
.empty ())
1165 /* This is said to happen with SCO. The old coffread.c
1166 code simply emptied the context stack, so we do the
1167 same. FIXME: Find out why it is happening. This is not
1168 believed to happen in most cases (even for coffread.c);
1169 it used to be an abort(). */
1170 complaint (_("Context stack not empty in end_symtab"));
1171 buildsym_compunit
->m_context_stack
.clear ();
1175 /* Reordered executables may have out of order pending blocks; if
1176 OBJF_REORDERED is true, then sort the pending blocks. */
1178 if ((objfile
->flags
& OBJF_REORDERED
) && buildsym_compunit
->m_pending_blocks
)
1180 struct pending_block
*pb
;
1182 std::vector
<block
*> barray
;
1184 for (pb
= buildsym_compunit
->m_pending_blocks
; pb
!= NULL
; pb
= pb
->next
)
1185 barray
.push_back (pb
->block
);
1187 /* Sort blocks by start address in descending order. Blocks with the
1188 same start address must remain in the original order to preserve
1189 inline function caller/callee relationships. */
1190 std::stable_sort (barray
.begin (), barray
.end (),
1191 [] (const block
*a
, const block
*b
)
1193 return BLOCK_START (a
) > BLOCK_START (b
);
1197 for (pb
= buildsym_compunit
->m_pending_blocks
; pb
!= NULL
; pb
= pb
->next
)
1198 pb
->block
= barray
[i
++];
1201 /* Cleanup any undefined types that have been left hanging around
1202 (this needs to be done before the finish_blocks so that
1203 file_symbols is still good).
1205 Both cleanup_undefined_stabs_types and finish_global_stabs are stabs
1206 specific, but harmless for other symbol readers, since on gdb
1207 startup or when finished reading stabs, the state is set so these
1208 are no-ops. FIXME: Is this handled right in case of QUIT? Can
1209 we make this cleaner? */
1211 cleanup_undefined_stabs_types (objfile
);
1212 finish_global_stabs (objfile
);
1215 && buildsym_compunit
->m_pending_blocks
== NULL
1216 && buildsym_compunit
->m_file_symbols
== NULL
1217 && buildsym_compunit
->m_global_symbols
== NULL
1218 && !buildsym_compunit
->m_have_line_numbers
1219 && buildsym_compunit
->m_pending_macros
== NULL
1220 && buildsym_compunit
->m_global_using_directives
== NULL
)
1222 /* Ignore symtabs that have no functions with real debugging info. */
1227 /* Define the STATIC_BLOCK. */
1228 return finish_block_internal (NULL
, get_file_symbols (), NULL
, NULL
,
1229 buildsym_compunit
->m_last_source_start_addr
,
1230 end_addr
, 0, expandable
);
1234 /* Subroutine of end_symtab_from_static_block to simplify it.
1235 Handle the "have blockvector" case.
1236 See end_symtab_from_static_block for a description of the arguments. */
1238 static struct compunit_symtab
*
1239 end_symtab_with_blockvector (struct block
*static_block
,
1240 int section
, int expandable
)
1242 struct objfile
*objfile
= buildsym_compunit
->objfile
;
1243 struct compunit_symtab
*cu
= buildsym_compunit
->compunit_symtab
;
1244 struct symtab
*symtab
;
1245 struct blockvector
*blockvector
;
1246 struct subfile
*subfile
;
1249 gdb_assert (static_block
!= NULL
);
1250 gdb_assert (buildsym_compunit
!= NULL
);
1251 gdb_assert (buildsym_compunit
->subfiles
!= NULL
);
1253 end_addr
= BLOCK_END (static_block
);
1255 /* Create the GLOBAL_BLOCK and build the blockvector. */
1256 finish_block_internal (NULL
, get_global_symbols (), NULL
, NULL
,
1257 buildsym_compunit
->m_last_source_start_addr
, end_addr
,
1259 blockvector
= make_blockvector ();
1261 /* Read the line table if it has to be read separately.
1262 This is only used by xcoffread.c. */
1263 if (objfile
->sf
->sym_read_linetable
!= NULL
)
1264 objfile
->sf
->sym_read_linetable (objfile
);
1266 /* Handle the case where the debug info specifies a different path
1267 for the main source file. It can cause us to lose track of its
1268 line number information. */
1269 watch_main_source_file_lossage ();
1271 /* Now create the symtab objects proper, if not already done,
1272 one for each subfile. */
1274 for (subfile
= buildsym_compunit
->subfiles
;
1276 subfile
= subfile
->next
)
1278 int linetablesize
= 0;
1280 if (subfile
->line_vector
)
1282 linetablesize
= sizeof (struct linetable
) +
1283 subfile
->line_vector
->nitems
* sizeof (struct linetable_entry
);
1285 /* Like the pending blocks, the line table may be
1286 scrambled in reordered executables. Sort it if
1287 OBJF_REORDERED is true. */
1288 if (objfile
->flags
& OBJF_REORDERED
)
1289 qsort (subfile
->line_vector
->item
,
1290 subfile
->line_vector
->nitems
,
1291 sizeof (struct linetable_entry
), compare_line_numbers
);
1294 /* Allocate a symbol table if necessary. */
1295 if (subfile
->symtab
== NULL
)
1296 subfile
->symtab
= allocate_symtab (cu
, subfile
->name
);
1297 symtab
= subfile
->symtab
;
1299 /* Fill in its components. */
1301 if (subfile
->line_vector
)
1303 /* Reallocate the line table on the symbol obstack. */
1304 SYMTAB_LINETABLE (symtab
) = (struct linetable
*)
1305 obstack_alloc (&objfile
->objfile_obstack
, linetablesize
);
1306 memcpy (SYMTAB_LINETABLE (symtab
), subfile
->line_vector
,
1311 SYMTAB_LINETABLE (symtab
) = NULL
;
1314 /* Use whatever language we have been using for this
1315 subfile, not the one that was deduced in allocate_symtab
1316 from the filename. We already did our own deducing when
1317 we created the subfile, and we may have altered our
1318 opinion of what language it is from things we found in
1320 symtab
->language
= subfile
->language
;
1323 /* Make sure the symtab of main_subfile is the first in its list. */
1325 struct symtab
*main_symtab
, *prev_symtab
;
1327 main_symtab
= buildsym_compunit
->main_subfile
->symtab
;
1329 ALL_COMPUNIT_FILETABS (cu
, symtab
)
1331 if (symtab
== main_symtab
)
1333 if (prev_symtab
!= NULL
)
1335 prev_symtab
->next
= main_symtab
->next
;
1336 main_symtab
->next
= COMPUNIT_FILETABS (cu
);
1337 COMPUNIT_FILETABS (cu
) = main_symtab
;
1341 prev_symtab
= symtab
;
1343 gdb_assert (main_symtab
== COMPUNIT_FILETABS (cu
));
1346 /* Fill out the compunit symtab. */
1348 if (buildsym_compunit
->comp_dir
!= NULL
)
1350 /* Reallocate the dirname on the symbol obstack. */
1351 const char *comp_dir
= buildsym_compunit
->comp_dir
.get ();
1352 COMPUNIT_DIRNAME (cu
)
1353 = (const char *) obstack_copy0 (&objfile
->objfile_obstack
,
1354 comp_dir
, strlen (comp_dir
));
1357 /* Save the debug format string (if any) in the symtab. */
1358 COMPUNIT_DEBUGFORMAT (cu
) = buildsym_compunit
->debugformat
;
1360 /* Similarly for the producer. */
1361 COMPUNIT_PRODUCER (cu
) = buildsym_compunit
->producer
;
1363 COMPUNIT_BLOCKVECTOR (cu
) = blockvector
;
1365 struct block
*b
= BLOCKVECTOR_BLOCK (blockvector
, GLOBAL_BLOCK
);
1367 set_block_compunit_symtab (b
, cu
);
1370 COMPUNIT_BLOCK_LINE_SECTION (cu
) = section
;
1372 COMPUNIT_MACRO_TABLE (cu
) = buildsym_compunit
->release_macros ();
1374 /* Default any symbols without a specified symtab to the primary symtab. */
1378 /* The main source file's symtab. */
1379 symtab
= COMPUNIT_FILETABS (cu
);
1381 for (block_i
= 0; block_i
< BLOCKVECTOR_NBLOCKS (blockvector
); block_i
++)
1383 struct block
*block
= BLOCKVECTOR_BLOCK (blockvector
, block_i
);
1385 struct dict_iterator iter
;
1387 /* Inlined functions may have symbols not in the global or
1388 static symbol lists. */
1389 if (BLOCK_FUNCTION (block
) != NULL
)
1390 if (symbol_symtab (BLOCK_FUNCTION (block
)) == NULL
)
1391 symbol_set_symtab (BLOCK_FUNCTION (block
), symtab
);
1393 /* Note that we only want to fix up symbols from the local
1394 blocks, not blocks coming from included symtabs. That is why
1395 we use ALL_DICT_SYMBOLS here and not ALL_BLOCK_SYMBOLS. */
1396 ALL_DICT_SYMBOLS (BLOCK_DICT (block
), iter
, sym
)
1397 if (symbol_symtab (sym
) == NULL
)
1398 symbol_set_symtab (sym
, symtab
);
1402 add_compunit_symtab_to_objfile (cu
);
1407 /* Implementation of the second part of end_symtab. Pass STATIC_BLOCK
1408 as value returned by end_symtab_get_static_block.
1410 SECTION is the same as for end_symtab: the section number
1411 (in objfile->section_offsets) of the blockvector and linetable.
1413 If EXPANDABLE is non-zero the GLOBAL_BLOCK dictionary is made
1416 struct compunit_symtab
*
1417 end_symtab_from_static_block (struct block
*static_block
,
1418 int section
, int expandable
)
1420 struct compunit_symtab
*cu
;
1422 if (static_block
== NULL
)
1424 /* Handle the "no blockvector" case.
1425 When this happens there is nothing to record, so there's nothing
1426 to do: memory will be freed up later.
1428 Note: We won't be adding a compunit to the objfile's list of
1429 compunits, so there's nothing to unchain. However, since each symtab
1430 is added to the objfile's obstack we can't free that space.
1431 We could do better, but this is believed to be a sufficiently rare
1436 cu
= end_symtab_with_blockvector (static_block
, section
, expandable
);
1438 reset_symtab_globals ();
1443 /* Finish the symbol definitions for one main source file, close off
1444 all the lexical contexts for that file (creating struct block's for
1445 them), then make the struct symtab for that file and put it in the
1448 END_ADDR is the address of the end of the file's text. SECTION is
1449 the section number (in objfile->section_offsets) of the blockvector
1452 Note that it is possible for end_symtab() to return NULL. In
1453 particular, for the DWARF case at least, it will return NULL when
1454 it finds a compilation unit that has exactly one DIE, a
1455 TAG_compile_unit DIE. This can happen when we link in an object
1456 file that was compiled from an empty source file. Returning NULL
1457 is probably not the correct thing to do, because then gdb will
1458 never know about this empty file (FIXME).
1460 If you need to modify STATIC_BLOCK before it is finalized you should
1461 call end_symtab_get_static_block and end_symtab_from_static_block
1464 struct compunit_symtab
*
1465 end_symtab (CORE_ADDR end_addr
, int section
)
1467 struct block
*static_block
;
1469 static_block
= end_symtab_get_static_block (end_addr
, 0, 0);
1470 return end_symtab_from_static_block (static_block
, section
, 0);
1473 /* Same as end_symtab except create a symtab that can be later added to. */
1475 struct compunit_symtab
*
1476 end_expandable_symtab (CORE_ADDR end_addr
, int section
)
1478 struct block
*static_block
;
1480 static_block
= end_symtab_get_static_block (end_addr
, 1, 0);
1481 return end_symtab_from_static_block (static_block
, section
, 1);
1484 /* Subroutine of augment_type_symtab to simplify it.
1485 Attach the main source file's symtab to all symbols in PENDING_LIST that
1489 set_missing_symtab (struct pending
*pending_list
,
1490 struct compunit_symtab
*cu
)
1492 struct pending
*pending
;
1495 for (pending
= pending_list
; pending
!= NULL
; pending
= pending
->next
)
1497 for (i
= 0; i
< pending
->nsyms
; ++i
)
1499 if (symbol_symtab (pending
->symbol
[i
]) == NULL
)
1500 symbol_set_symtab (pending
->symbol
[i
], COMPUNIT_FILETABS (cu
));
1505 /* Same as end_symtab, but for the case where we're adding more symbols
1506 to an existing symtab that is known to contain only type information.
1507 This is the case for DWARF4 Type Units. */
1510 augment_type_symtab (void)
1512 struct compunit_symtab
*cust
= buildsym_compunit
->compunit_symtab
;
1513 const struct blockvector
*blockvector
= COMPUNIT_BLOCKVECTOR (cust
);
1515 if (!buildsym_compunit
->m_context_stack
.empty ())
1516 complaint (_("Context stack not empty in augment_type_symtab"));
1517 if (buildsym_compunit
->m_pending_blocks
!= NULL
)
1518 complaint (_("Blocks in a type symtab"));
1519 if (buildsym_compunit
->m_pending_macros
!= NULL
)
1520 complaint (_("Macro in a type symtab"));
1521 if (buildsym_compunit
->m_have_line_numbers
)
1522 complaint (_("Line numbers recorded in a type symtab"));
1524 if (buildsym_compunit
->m_file_symbols
!= NULL
)
1526 struct block
*block
= BLOCKVECTOR_BLOCK (blockvector
, STATIC_BLOCK
);
1528 /* First mark any symbols without a specified symtab as belonging
1529 to the primary symtab. */
1530 set_missing_symtab (buildsym_compunit
->m_file_symbols
, cust
);
1532 dict_add_pending (BLOCK_DICT (block
), buildsym_compunit
->m_file_symbols
);
1535 if (buildsym_compunit
->m_global_symbols
!= NULL
)
1537 struct block
*block
= BLOCKVECTOR_BLOCK (blockvector
, GLOBAL_BLOCK
);
1539 /* First mark any symbols without a specified symtab as belonging
1540 to the primary symtab. */
1541 set_missing_symtab (buildsym_compunit
->m_global_symbols
, cust
);
1543 dict_add_pending (BLOCK_DICT (block
),
1544 buildsym_compunit
->m_global_symbols
);
1547 reset_symtab_globals ();
1550 /* Push a context block. Args are an identifying nesting level
1551 (checkable when you pop it), and the starting PC address of this
1554 struct context_stack
*
1555 push_context (int desc
, CORE_ADDR valu
)
1557 gdb_assert (buildsym_compunit
!= nullptr);
1559 buildsym_compunit
->m_context_stack
.emplace_back ();
1560 struct context_stack
*newobj
= &buildsym_compunit
->m_context_stack
.back ();
1562 newobj
->depth
= desc
;
1563 newobj
->locals
= buildsym_compunit
->m_local_symbols
;
1564 newobj
->old_blocks
= buildsym_compunit
->m_pending_blocks
;
1565 newobj
->start_addr
= valu
;
1566 newobj
->local_using_directives
1567 = buildsym_compunit
->m_local_using_directives
;
1568 newobj
->name
= NULL
;
1570 buildsym_compunit
->m_local_symbols
= NULL
;
1571 buildsym_compunit
->m_local_using_directives
= NULL
;
1576 /* Pop a context block. Returns the address of the context block just
1579 struct context_stack
1582 gdb_assert (buildsym_compunit
!= nullptr);
1583 gdb_assert (!buildsym_compunit
->m_context_stack
.empty ());
1584 struct context_stack result
= buildsym_compunit
->m_context_stack
.back ();
1585 buildsym_compunit
->m_context_stack
.pop_back ();
1592 record_debugformat (const char *format
)
1594 buildsym_compunit
->debugformat
= format
;
1598 record_producer (const char *producer
)
1600 buildsym_compunit
->producer
= producer
;
1605 /* See buildsym.h. */
1608 set_last_source_file (const char *name
)
1610 gdb_assert (buildsym_compunit
!= nullptr || name
== nullptr);
1611 if (buildsym_compunit
!= nullptr)
1612 buildsym_compunit
->set_last_source_file (name
);
1615 /* See buildsym.h. */
1618 get_last_source_file (void)
1620 if (buildsym_compunit
== nullptr)
1622 return buildsym_compunit
->m_last_source_file
.get ();
1625 /* See buildsym.h. */
1628 set_last_source_start_addr (CORE_ADDR addr
)
1630 gdb_assert (buildsym_compunit
!= nullptr);
1631 buildsym_compunit
->m_last_source_start_addr
= addr
;
1634 /* See buildsym.h. */
1637 get_last_source_start_addr ()
1639 gdb_assert (buildsym_compunit
!= nullptr);
1640 return buildsym_compunit
->m_last_source_start_addr
;
1643 /* See buildsym.h. */
1645 struct using_direct
**
1646 get_local_using_directives ()
1648 gdb_assert (buildsym_compunit
!= nullptr);
1649 return &buildsym_compunit
->m_local_using_directives
;
1652 /* See buildsym.h. */
1655 set_local_using_directives (struct using_direct
*new_local
)
1657 gdb_assert (buildsym_compunit
!= nullptr);
1658 buildsym_compunit
->m_local_using_directives
= new_local
;
1661 /* See buildsym.h. */
1663 struct using_direct
**
1664 get_global_using_directives ()
1666 gdb_assert (buildsym_compunit
!= nullptr);
1667 return &buildsym_compunit
->m_global_using_directives
;
1670 /* See buildsym.h. */
1673 outermost_context_p ()
1675 gdb_assert (buildsym_compunit
!= nullptr);
1676 return buildsym_compunit
->m_context_stack
.empty ();
1679 /* See buildsym.h. */
1681 struct context_stack
*
1682 get_current_context_stack ()
1684 gdb_assert (buildsym_compunit
!= nullptr);
1685 if (buildsym_compunit
->m_context_stack
.empty ())
1687 return &buildsym_compunit
->m_context_stack
.back ();
1690 /* See buildsym.h. */
1693 get_context_stack_depth ()
1695 gdb_assert (buildsym_compunit
!= nullptr);
1696 return buildsym_compunit
->m_context_stack
.size ();
1699 /* See buildsym.h. */
1702 get_current_subfile ()
1704 gdb_assert (buildsym_compunit
!= nullptr);
1705 return buildsym_compunit
->m_current_subfile
;
1708 /* See buildsym.h. */
1711 get_local_symbols ()
1713 gdb_assert (buildsym_compunit
!= nullptr);
1714 return &buildsym_compunit
->m_local_symbols
;
1717 /* See buildsym.h. */
1722 gdb_assert (buildsym_compunit
!= nullptr);
1723 return &buildsym_compunit
->m_file_symbols
;
1726 /* See buildsym.h. */
1729 get_global_symbols ()
1731 gdb_assert (buildsym_compunit
!= nullptr);
1732 return &buildsym_compunit
->m_global_symbols
;