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 *comp_dir_
,
109 enum language language_
)
110 : objfile (objfile_
),
111 comp_dir (comp_dir_
== nullptr ? nullptr : xstrdup (comp_dir_
)),
116 ~buildsym_compunit ()
118 struct subfile
*subfile
, *nextsub
;
120 for (subfile
= subfiles
;
124 nextsub
= subfile
->next
;
125 xfree (subfile
->name
);
126 xfree (subfile
->line_vector
);
131 /* The objfile we're reading debug info from. */
132 struct objfile
*objfile
;
134 /* List of subfiles (source files).
135 Files are added to the front of the list.
136 This is important mostly for the language determination hacks we use,
137 which iterate over previously added files. */
138 struct subfile
*subfiles
= nullptr;
140 /* The subfile of the main source file. */
141 struct subfile
*main_subfile
= nullptr;
143 /* E.g., DW_AT_comp_dir if DWARF. Space for this is malloc'd. */
144 gdb::unique_xmalloc_ptr
<char> comp_dir
;
146 /* Space for this is not malloc'd, and is assumed to have at least
147 the same lifetime as objfile. */
148 const char *producer
= nullptr;
150 /* Space for this is not malloc'd, and is assumed to have at least
151 the same lifetime as objfile. */
152 const char *debugformat
= nullptr;
154 /* The compunit we are building. */
155 struct compunit_symtab
*compunit_symtab
= nullptr;
157 /* Language of this compunit_symtab. */
158 enum language language
;
161 /* The work-in-progress of the compunit we are building.
162 This is created first, before any subfiles by start_symtab. */
164 static struct buildsym_compunit
*buildsym_compunit
;
166 /* List of free `struct pending' structures for reuse. */
168 static struct pending
*free_pendings
;
170 /* Non-zero if symtab has line number info. This prevents an
171 otherwise empty symtab from being tossed. */
173 static int have_line_numbers
;
175 /* The mutable address map for the compilation unit whose symbols
176 we're currently reading. The symtabs' shared blockvector will
177 point to a fixed copy of this. */
178 static struct addrmap
*pending_addrmap
;
180 /* The obstack on which we allocate pending_addrmap.
181 If pending_addrmap is NULL, this is uninitialized; otherwise, it is
182 initialized (and holds pending_addrmap). */
183 static struct obstack pending_addrmap_obstack
;
185 /* Non-zero if we recorded any ranges in the addrmap that are
186 different from those in the blockvector already. We set this to
187 zero when we start processing a symfile, and if it's still zero at
188 the end, then we just toss the addrmap. */
189 static int pending_addrmap_interesting
;
191 /* An obstack used for allocating pending blocks. */
193 static struct obstack pending_block_obstack
;
195 /* List of blocks already made (lexical contexts already closed).
196 This is used at the end to make the blockvector. */
200 struct pending_block
*next
;
204 /* Pointer to the head of a linked list of symbol blocks which have
205 already been finalized (lexical contexts already closed) and which
206 are just waiting to be built into a blockvector when finalizing the
207 associated symtab. */
209 static struct pending_block
*pending_blocks
;
213 struct subfile_stack
*next
;
217 static struct subfile_stack
*subfile_stack
;
219 /* The macro table for the compilation unit whose symbols we're
220 currently reading. */
221 static struct macro_table
*pending_macros
;
223 static void free_buildsym_compunit (void);
225 static int compare_line_numbers (const void *ln1p
, const void *ln2p
);
227 static void record_pending_block (struct objfile
*objfile
,
229 struct pending_block
*opblock
);
231 /* Initial sizes of data structures. These are realloc'd larger if
232 needed, and realloc'd down to the size actually used, when
235 #define INITIAL_CONTEXT_STACK_SIZE 10
236 #define INITIAL_LINE_VECTOR_LENGTH 1000
239 /* Maintain the lists of symbols and blocks. */
241 /* Add a symbol to one of the lists of symbols. */
244 add_symbol_to_list (struct symbol
*symbol
, struct pending
**listhead
)
246 struct pending
*link
;
248 /* If this is an alias for another symbol, don't add it. */
249 if (symbol
->ginfo
.name
&& symbol
->ginfo
.name
[0] == '#')
252 /* We keep PENDINGSIZE symbols in each link of the list. If we
253 don't have a link with room in it, add a new link. */
254 if (*listhead
== NULL
|| (*listhead
)->nsyms
== PENDINGSIZE
)
258 link
= free_pendings
;
259 free_pendings
= link
->next
;
263 link
= XNEW (struct pending
);
266 link
->next
= *listhead
;
271 (*listhead
)->symbol
[(*listhead
)->nsyms
++] = symbol
;
274 /* Find a symbol named NAME on a LIST. NAME need not be
275 '\0'-terminated; LENGTH is the length of the name. */
278 find_symbol_in_list (struct pending
*list
, char *name
, int length
)
285 for (j
= list
->nsyms
; --j
>= 0;)
287 pp
= SYMBOL_LINKAGE_NAME (list
->symbol
[j
]);
288 if (*pp
== *name
&& strncmp (pp
, name
, length
) == 0
289 && pp
[length
] == '\0')
291 return (list
->symbol
[j
]);
299 /* At end of reading syms, or in case of quit, ensure everything
300 associated with building symtabs is freed.
302 N.B. This is *not* intended to be used when building psymtabs. Some debug
303 info readers call this anyway, which is harmless if confusing. */
305 scoped_free_pendings::~scoped_free_pendings ()
307 struct pending
*next
, *next1
;
309 for (next
= free_pendings
; next
; next
= next1
)
312 xfree ((void *) next
);
314 free_pendings
= NULL
;
316 free_pending_blocks ();
318 for (next
= file_symbols
; next
!= NULL
; next
= next1
)
321 xfree ((void *) next
);
325 for (next
= global_symbols
; next
!= NULL
; next
= next1
)
328 xfree ((void *) next
);
330 global_symbols
= NULL
;
333 free_macro_table (pending_macros
);
334 pending_macros
= NULL
;
337 obstack_free (&pending_addrmap_obstack
, NULL
);
338 pending_addrmap
= NULL
;
340 free_buildsym_compunit ();
343 /* This function is called to discard any pending blocks. */
346 free_pending_blocks (void)
348 if (pending_blocks
!= NULL
)
350 obstack_free (&pending_block_obstack
, NULL
);
351 pending_blocks
= NULL
;
355 /* Take one of the lists of symbols and make a block from it. Keep
356 the order the symbols have in the list (reversed from the input
357 file). Put the block on the list of pending blocks. */
359 static struct block
*
360 finish_block_internal (struct symbol
*symbol
,
361 struct pending
**listhead
,
362 struct pending_block
*old_blocks
,
363 const struct dynamic_prop
*static_link
,
364 CORE_ADDR start
, CORE_ADDR end
,
365 int is_global
, int expandable
)
367 struct objfile
*objfile
= buildsym_compunit
->objfile
;
368 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
369 struct pending
*next
, *next1
;
371 struct pending_block
*pblock
;
372 struct pending_block
*opblock
;
375 ? allocate_global_block (&objfile
->objfile_obstack
)
376 : allocate_block (&objfile
->objfile_obstack
));
381 = dict_create_linear (&objfile
->objfile_obstack
,
382 buildsym_compunit
->language
, *listhead
);
389 = dict_create_hashed_expandable (buildsym_compunit
->language
);
390 dict_add_pending (BLOCK_DICT (block
), *listhead
);
395 dict_create_hashed (&objfile
->objfile_obstack
,
396 buildsym_compunit
->language
, *listhead
);
400 BLOCK_START (block
) = start
;
401 BLOCK_END (block
) = end
;
403 /* Put the block in as the value of the symbol that names it. */
407 struct type
*ftype
= SYMBOL_TYPE (symbol
);
408 struct dict_iterator iter
;
409 SYMBOL_BLOCK_VALUE (symbol
) = block
;
410 BLOCK_FUNCTION (block
) = symbol
;
412 if (TYPE_NFIELDS (ftype
) <= 0)
414 /* No parameter type information is recorded with the
415 function's type. Set that from the type of the
416 parameter symbols. */
417 int nparams
= 0, iparams
;
420 /* Here we want to directly access the dictionary, because
421 we haven't fully initialized the block yet. */
422 ALL_DICT_SYMBOLS (BLOCK_DICT (block
), iter
, sym
)
424 if (SYMBOL_IS_ARGUMENT (sym
))
429 TYPE_NFIELDS (ftype
) = nparams
;
430 TYPE_FIELDS (ftype
) = (struct field
*)
431 TYPE_ALLOC (ftype
, nparams
* sizeof (struct field
));
434 /* Here we want to directly access the dictionary, because
435 we haven't fully initialized the block yet. */
436 ALL_DICT_SYMBOLS (BLOCK_DICT (block
), iter
, sym
)
438 if (iparams
== nparams
)
441 if (SYMBOL_IS_ARGUMENT (sym
))
443 TYPE_FIELD_TYPE (ftype
, iparams
) = SYMBOL_TYPE (sym
);
444 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
453 BLOCK_FUNCTION (block
) = NULL
;
456 if (static_link
!= NULL
)
457 objfile_register_static_link (objfile
, block
, static_link
);
459 /* Now "free" the links of the list, and empty the list. */
461 for (next
= *listhead
; next
; next
= next1
)
464 next
->next
= free_pendings
;
465 free_pendings
= next
;
469 /* Check to be sure that the blocks have an end address that is
470 greater than starting address. */
472 if (BLOCK_END (block
) < BLOCK_START (block
))
476 complaint (_("block end address less than block "
477 "start address in %s (patched it)"),
478 SYMBOL_PRINT_NAME (symbol
));
482 complaint (_("block end address %s less than block "
483 "start address %s (patched it)"),
484 paddress (gdbarch
, BLOCK_END (block
)),
485 paddress (gdbarch
, BLOCK_START (block
)));
487 /* Better than nothing. */
488 BLOCK_END (block
) = BLOCK_START (block
);
491 /* Install this block as the superblock of all blocks made since the
492 start of this scope that don't have superblocks yet. */
495 for (pblock
= pending_blocks
;
496 pblock
&& pblock
!= old_blocks
;
497 pblock
= pblock
->next
)
499 if (BLOCK_SUPERBLOCK (pblock
->block
) == NULL
)
501 /* Check to be sure the blocks are nested as we receive
502 them. If the compiler/assembler/linker work, this just
503 burns a small amount of time.
505 Skip blocks which correspond to a function; they're not
506 physically nested inside this other blocks, only
508 if (BLOCK_FUNCTION (pblock
->block
) == NULL
509 && (BLOCK_START (pblock
->block
) < BLOCK_START (block
)
510 || BLOCK_END (pblock
->block
) > BLOCK_END (block
)))
514 complaint (_("inner block not inside outer block in %s"),
515 SYMBOL_PRINT_NAME (symbol
));
519 complaint (_("inner block (%s-%s) not "
520 "inside outer block (%s-%s)"),
521 paddress (gdbarch
, BLOCK_START (pblock
->block
)),
522 paddress (gdbarch
, BLOCK_END (pblock
->block
)),
523 paddress (gdbarch
, BLOCK_START (block
)),
524 paddress (gdbarch
, BLOCK_END (block
)));
526 if (BLOCK_START (pblock
->block
) < BLOCK_START (block
))
527 BLOCK_START (pblock
->block
) = BLOCK_START (block
);
528 if (BLOCK_END (pblock
->block
) > BLOCK_END (block
))
529 BLOCK_END (pblock
->block
) = BLOCK_END (block
);
531 BLOCK_SUPERBLOCK (pblock
->block
) = block
;
536 block_set_using (block
,
538 ? global_using_directives
539 : local_using_directives
),
540 &objfile
->objfile_obstack
);
542 global_using_directives
= NULL
;
544 local_using_directives
= NULL
;
546 record_pending_block (objfile
, block
, opblock
);
552 finish_block (struct symbol
*symbol
,
553 struct pending
**listhead
,
554 struct pending_block
*old_blocks
,
555 const struct dynamic_prop
*static_link
,
556 CORE_ADDR start
, CORE_ADDR end
)
558 return finish_block_internal (symbol
, listhead
, old_blocks
, static_link
,
562 /* Record BLOCK on the list of all blocks in the file. Put it after
563 OPBLOCK, or at the beginning if opblock is NULL. This puts the
564 block in the list after all its subblocks.
566 Allocate the pending block struct in the objfile_obstack to save
567 time. This wastes a little space. FIXME: Is it worth it? */
570 record_pending_block (struct objfile
*objfile
, struct block
*block
,
571 struct pending_block
*opblock
)
573 struct pending_block
*pblock
;
575 if (pending_blocks
== NULL
)
576 obstack_init (&pending_block_obstack
);
578 pblock
= XOBNEW (&pending_block_obstack
, struct pending_block
);
579 pblock
->block
= block
;
582 pblock
->next
= opblock
->next
;
583 opblock
->next
= pblock
;
587 pblock
->next
= pending_blocks
;
588 pending_blocks
= pblock
;
593 /* Record that the range of addresses from START to END_INCLUSIVE
594 (inclusive, like it says) belongs to BLOCK. BLOCK's start and end
595 addresses must be set already. You must apply this function to all
596 BLOCK's children before applying it to BLOCK.
598 If a call to this function complicates the picture beyond that
599 already provided by BLOCK_START and BLOCK_END, then we create an
600 address map for the block. */
602 record_block_range (struct block
*block
,
603 CORE_ADDR start
, CORE_ADDR end_inclusive
)
605 /* If this is any different from the range recorded in the block's
606 own BLOCK_START and BLOCK_END, then note that the address map has
607 become interesting. Note that even if this block doesn't have
608 any "interesting" ranges, some later block might, so we still
609 need to record this block in the addrmap. */
610 if (start
!= BLOCK_START (block
)
611 || end_inclusive
+ 1 != BLOCK_END (block
))
612 pending_addrmap_interesting
= 1;
614 if (! pending_addrmap
)
616 obstack_init (&pending_addrmap_obstack
);
617 pending_addrmap
= addrmap_create_mutable (&pending_addrmap_obstack
);
620 addrmap_set_empty (pending_addrmap
, start
, end_inclusive
, block
);
623 static struct blockvector
*
624 make_blockvector (void)
626 struct objfile
*objfile
= buildsym_compunit
->objfile
;
627 struct pending_block
*next
;
628 struct blockvector
*blockvector
;
631 /* Count the length of the list of blocks. */
633 for (next
= pending_blocks
, i
= 0; next
; next
= next
->next
, i
++)
637 blockvector
= (struct blockvector
*)
638 obstack_alloc (&objfile
->objfile_obstack
,
639 (sizeof (struct blockvector
)
640 + (i
- 1) * sizeof (struct block
*)));
642 /* Copy the blocks into the blockvector. This is done in reverse
643 order, which happens to put the blocks into the proper order
644 (ascending starting address). finish_block has hair to insert
645 each block into the list after its subblocks in order to make
646 sure this is true. */
648 BLOCKVECTOR_NBLOCKS (blockvector
) = i
;
649 for (next
= pending_blocks
; next
; next
= next
->next
)
651 BLOCKVECTOR_BLOCK (blockvector
, --i
) = next
->block
;
654 free_pending_blocks ();
656 /* If we needed an address map for this symtab, record it in the
658 if (pending_addrmap
&& pending_addrmap_interesting
)
659 BLOCKVECTOR_MAP (blockvector
)
660 = addrmap_create_fixed (pending_addrmap
, &objfile
->objfile_obstack
);
662 BLOCKVECTOR_MAP (blockvector
) = 0;
664 /* Some compilers output blocks in the wrong order, but we depend on
665 their being in the right order so we can binary search. Check the
666 order and moan about it.
667 Note: Remember that the first two blocks are the global and static
668 blocks. We could special case that fact and begin checking at block 2.
669 To avoid making that assumption we do not. */
670 if (BLOCKVECTOR_NBLOCKS (blockvector
) > 1)
672 for (i
= 1; i
< BLOCKVECTOR_NBLOCKS (blockvector
); i
++)
674 if (BLOCK_START (BLOCKVECTOR_BLOCK (blockvector
, i
- 1))
675 > BLOCK_START (BLOCKVECTOR_BLOCK (blockvector
, i
)))
678 = BLOCK_START (BLOCKVECTOR_BLOCK (blockvector
, i
));
680 complaint (_("block at %s out of order"),
681 hex_string ((LONGEST
) start
));
686 return (blockvector
);
689 /* Start recording information about source code that came from an
690 included (or otherwise merged-in) source file with a different
691 name. NAME is the name of the file (cannot be NULL). */
694 start_subfile (const char *name
)
696 const char *subfile_dirname
;
697 struct subfile
*subfile
;
699 gdb_assert (buildsym_compunit
!= NULL
);
701 subfile_dirname
= buildsym_compunit
->comp_dir
.get ();
703 /* See if this subfile is already registered. */
705 for (subfile
= buildsym_compunit
->subfiles
; subfile
; subfile
= subfile
->next
)
709 /* If NAME is an absolute path, and this subfile is not, then
710 attempt to create an absolute path to compare. */
711 if (IS_ABSOLUTE_PATH (name
)
712 && !IS_ABSOLUTE_PATH (subfile
->name
)
713 && subfile_dirname
!= NULL
)
714 subfile_name
= concat (subfile_dirname
, SLASH_STRING
,
715 subfile
->name
, (char *) NULL
);
717 subfile_name
= subfile
->name
;
719 if (FILENAME_CMP (subfile_name
, name
) == 0)
721 current_subfile
= subfile
;
722 if (subfile_name
!= subfile
->name
)
723 xfree (subfile_name
);
726 if (subfile_name
!= subfile
->name
)
727 xfree (subfile_name
);
730 /* This subfile is not known. Add an entry for it. */
732 subfile
= XNEW (struct subfile
);
733 memset (subfile
, 0, sizeof (struct subfile
));
734 subfile
->buildsym_compunit
= buildsym_compunit
;
736 subfile
->next
= buildsym_compunit
->subfiles
;
737 buildsym_compunit
->subfiles
= subfile
;
739 current_subfile
= subfile
;
741 subfile
->name
= xstrdup (name
);
743 /* Initialize line-number recording for this subfile. */
744 subfile
->line_vector
= NULL
;
746 /* Default the source language to whatever can be deduced from the
747 filename. If nothing can be deduced (such as for a C/C++ include
748 file with a ".h" extension), then inherit whatever language the
749 previous subfile had. This kludgery is necessary because there
750 is no standard way in some object formats to record the source
751 language. Also, when symtabs are allocated we try to deduce a
752 language then as well, but it is too late for us to use that
753 information while reading symbols, since symtabs aren't allocated
754 until after all the symbols have been processed for a given
757 subfile
->language
= deduce_language_from_filename (subfile
->name
);
758 if (subfile
->language
== language_unknown
759 && subfile
->next
!= NULL
)
761 subfile
->language
= subfile
->next
->language
;
764 /* If the filename of this subfile ends in .C, then change the
765 language of any pending subfiles from C to C++. We also accept
766 any other C++ suffixes accepted by deduce_language_from_filename. */
767 /* Likewise for f2c. */
772 enum language sublang
= deduce_language_from_filename (subfile
->name
);
774 if (sublang
== language_cplus
|| sublang
== language_fortran
)
775 for (s
= buildsym_compunit
->subfiles
; s
!= NULL
; s
= s
->next
)
776 if (s
->language
== language_c
)
777 s
->language
= sublang
;
780 /* And patch up this file if necessary. */
781 if (subfile
->language
== language_c
782 && subfile
->next
!= NULL
783 && (subfile
->next
->language
== language_cplus
784 || subfile
->next
->language
== language_fortran
))
786 subfile
->language
= subfile
->next
->language
;
790 /* Delete the buildsym compunit. */
793 free_buildsym_compunit (void)
795 if (buildsym_compunit
== NULL
)
797 delete buildsym_compunit
;
798 buildsym_compunit
= NULL
;
799 current_subfile
= NULL
;
802 /* For stabs readers, the first N_SO symbol is assumed to be the
803 source file name, and the subfile struct is initialized using that
804 assumption. If another N_SO symbol is later seen, immediately
805 following the first one, then the first one is assumed to be the
806 directory name and the second one is really the source file name.
808 So we have to patch up the subfile struct by moving the old name
809 value to dirname and remembering the new name. Some sanity
810 checking is performed to ensure that the state of the subfile
811 struct is reasonable and that the old name we are assuming to be a
812 directory name actually is (by checking for a trailing '/'). */
815 patch_subfile_names (struct subfile
*subfile
, const char *name
)
818 && buildsym_compunit
->comp_dir
== NULL
819 && subfile
->name
!= NULL
820 && IS_DIR_SEPARATOR (subfile
->name
[strlen (subfile
->name
) - 1]))
822 buildsym_compunit
->comp_dir
.reset (subfile
->name
);
823 subfile
->name
= xstrdup (name
);
824 set_last_source_file (name
);
826 /* Default the source language to whatever can be deduced from
827 the filename. If nothing can be deduced (such as for a C/C++
828 include file with a ".h" extension), then inherit whatever
829 language the previous subfile had. This kludgery is
830 necessary because there is no standard way in some object
831 formats to record the source language. Also, when symtabs
832 are allocated we try to deduce a language then as well, but
833 it is too late for us to use that information while reading
834 symbols, since symtabs aren't allocated until after all the
835 symbols have been processed for a given source file. */
837 subfile
->language
= deduce_language_from_filename (subfile
->name
);
838 if (subfile
->language
== language_unknown
839 && subfile
->next
!= NULL
)
841 subfile
->language
= subfile
->next
->language
;
846 /* Handle the N_BINCL and N_EINCL symbol types that act like N_SOL for
847 switching source files (different subfiles, as we call them) within
848 one object file, but using a stack rather than in an arbitrary
854 struct subfile_stack
*tem
= XNEW (struct subfile_stack
);
856 tem
->next
= subfile_stack
;
858 if (current_subfile
== NULL
|| current_subfile
->name
== NULL
)
860 internal_error (__FILE__
, __LINE__
,
861 _("failed internal consistency check"));
863 tem
->name
= current_subfile
->name
;
870 struct subfile_stack
*link
= subfile_stack
;
874 internal_error (__FILE__
, __LINE__
,
875 _("failed internal consistency check"));
878 subfile_stack
= link
->next
;
879 xfree ((void *) link
);
883 /* Add a linetable entry for line number LINE and address PC to the
884 line vector for SUBFILE. */
887 record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
889 struct linetable_entry
*e
;
891 /* Ignore the dummy line number in libg.o */
897 /* Make sure line vector exists and is big enough. */
898 if (!subfile
->line_vector
)
900 subfile
->line_vector_length
= INITIAL_LINE_VECTOR_LENGTH
;
901 subfile
->line_vector
= (struct linetable
*)
902 xmalloc (sizeof (struct linetable
)
903 + subfile
->line_vector_length
* sizeof (struct linetable_entry
));
904 subfile
->line_vector
->nitems
= 0;
905 have_line_numbers
= 1;
908 if (subfile
->line_vector
->nitems
+ 1 >= subfile
->line_vector_length
)
910 subfile
->line_vector_length
*= 2;
911 subfile
->line_vector
= (struct linetable
*)
912 xrealloc ((char *) subfile
->line_vector
,
913 (sizeof (struct linetable
)
914 + (subfile
->line_vector_length
915 * sizeof (struct linetable_entry
))));
918 /* Normally, we treat lines as unsorted. But the end of sequence
919 marker is special. We sort line markers at the same PC by line
920 number, so end of sequence markers (which have line == 0) appear
921 first. This is right if the marker ends the previous function,
922 and there is no padding before the next function. But it is
923 wrong if the previous line was empty and we are now marking a
924 switch to a different subfile. We must leave the end of sequence
925 marker at the end of this group of lines, not sort the empty line
926 to after the marker. The easiest way to accomplish this is to
927 delete any empty lines from our table, if they are followed by
928 end of sequence markers. All we lose is the ability to set
929 breakpoints at some lines which contain no instructions
931 if (line
== 0 && subfile
->line_vector
->nitems
> 0)
933 e
= subfile
->line_vector
->item
+ subfile
->line_vector
->nitems
- 1;
934 while (subfile
->line_vector
->nitems
> 0 && e
->pc
== pc
)
937 subfile
->line_vector
->nitems
--;
941 e
= subfile
->line_vector
->item
+ subfile
->line_vector
->nitems
++;
946 /* Needed in order to sort line tables from IBM xcoff files. Sigh! */
949 compare_line_numbers (const void *ln1p
, const void *ln2p
)
951 struct linetable_entry
*ln1
= (struct linetable_entry
*) ln1p
;
952 struct linetable_entry
*ln2
= (struct linetable_entry
*) ln2p
;
954 /* Note: this code does not assume that CORE_ADDRs can fit in ints.
955 Please keep it that way. */
956 if (ln1
->pc
< ln2
->pc
)
959 if (ln1
->pc
> ln2
->pc
)
962 /* If pc equal, sort by line. I'm not sure whether this is optimum
963 behavior (see comment at struct linetable in symtab.h). */
964 return ln1
->line
- ln2
->line
;
967 /* See buildsym.h. */
969 struct compunit_symtab
*
970 buildsym_compunit_symtab (void)
972 gdb_assert (buildsym_compunit
!= NULL
);
974 return buildsym_compunit
->compunit_symtab
;
977 /* See buildsym.h. */
980 get_macro_table (void)
982 struct objfile
*objfile
;
984 gdb_assert (buildsym_compunit
!= NULL
);
986 objfile
= buildsym_compunit
->objfile
;
988 if (! pending_macros
)
990 pending_macros
= new_macro_table (&objfile
->per_bfd
->storage_obstack
,
991 objfile
->per_bfd
->macro_cache
,
992 buildsym_compunit
->compunit_symtab
);
995 return pending_macros
;
998 /* Init state to prepare for building a symtab.
999 Note: This can't be done in buildsym_init because dbxread.c and xcoffread.c
1000 can call start_symtab+end_symtab multiple times after one call to
1004 prepare_for_building (const char *name
, CORE_ADDR start_addr
)
1006 set_last_source_file (name
);
1007 last_source_start_addr
= start_addr
;
1009 local_symbols
= NULL
;
1010 local_using_directives
= NULL
;
1011 within_function
= 0;
1012 have_line_numbers
= 0;
1014 context_stack_depth
= 0;
1016 /* These should have been reset either by successful completion of building
1017 a symtab, or by the scoped_free_pendings destructor. */
1018 gdb_assert (file_symbols
== NULL
);
1019 gdb_assert (global_symbols
== NULL
);
1020 gdb_assert (global_using_directives
== NULL
);
1021 gdb_assert (pending_macros
== NULL
);
1022 gdb_assert (pending_addrmap
== NULL
);
1023 gdb_assert (current_subfile
== NULL
);
1026 /* Start a new symtab for a new source file in OBJFILE. Called, for example,
1027 when a stabs symbol of type N_SO is seen, or when a DWARF
1028 TAG_compile_unit DIE is seen. It indicates the start of data for
1029 one original source file.
1031 NAME is the name of the file (cannot be NULL). COMP_DIR is the
1032 directory in which the file was compiled (or NULL if not known).
1033 START_ADDR is the lowest address of objects in the file (or 0 if
1034 not known). LANGUAGE is the language of the source file, or
1035 language_unknown if not known, in which case it'll be deduced from
1038 struct compunit_symtab
*
1039 start_symtab (struct objfile
*objfile
, const char *name
, const char *comp_dir
,
1040 CORE_ADDR start_addr
, enum language language
)
1042 prepare_for_building (name
, start_addr
);
1044 buildsym_compunit
= new struct buildsym_compunit (objfile
, comp_dir
,
1047 /* Allocate the compunit symtab now. The caller needs it to allocate
1048 non-primary symtabs. It is also needed by get_macro_table. */
1049 buildsym_compunit
->compunit_symtab
= allocate_compunit_symtab (objfile
,
1052 /* Build the subfile for NAME (the main source file) so that we can record
1053 a pointer to it for later.
1054 IMPORTANT: Do not allocate a struct symtab for NAME here.
1055 It can happen that the debug info provides a different path to NAME than
1056 DIRNAME,NAME. We cope with this in watch_main_source_file_lossage but
1057 that only works if the main_subfile doesn't have a symtab yet. */
1058 start_subfile (name
);
1059 /* Save this so that we don't have to go looking for it at the end
1060 of the subfiles list. */
1061 buildsym_compunit
->main_subfile
= current_subfile
;
1063 return buildsym_compunit
->compunit_symtab
;
1066 /* Restart compilation for a symtab.
1067 CUST is the result of end_expandable_symtab.
1068 NAME, START_ADDR are the source file we are resuming with.
1070 This is used when a symtab is built from multiple sources.
1071 The symtab is first built with start_symtab/end_expandable_symtab
1072 and then for each additional piece call restart_symtab/augment_*_symtab.
1073 Note: At the moment there is only augment_type_symtab. */
1076 restart_symtab (struct compunit_symtab
*cust
,
1077 const char *name
, CORE_ADDR start_addr
)
1079 prepare_for_building (name
, start_addr
);
1082 = new struct buildsym_compunit (COMPUNIT_OBJFILE (cust
),
1083 COMPUNIT_DIRNAME (cust
),
1084 compunit_language (cust
));
1085 buildsym_compunit
->compunit_symtab
= cust
;
1088 /* Subroutine of end_symtab to simplify it. Look for a subfile that
1089 matches the main source file's basename. If there is only one, and
1090 if the main source file doesn't have any symbol or line number
1091 information, then copy this file's symtab and line_vector to the
1092 main source file's subfile and discard the other subfile. This can
1093 happen because of a compiler bug or from the user playing games
1094 with #line or from things like a distributed build system that
1095 manipulates the debug info. This can also happen from an innocent
1096 symlink in the paths, we don't canonicalize paths here. */
1099 watch_main_source_file_lossage (void)
1101 struct subfile
*mainsub
, *subfile
;
1103 /* We have to watch for buildsym_compunit == NULL here. It's a quirk of
1104 end_symtab, it can return NULL so there may not be a main subfile. */
1105 if (buildsym_compunit
== NULL
)
1108 /* Get the main source file. */
1109 mainsub
= buildsym_compunit
->main_subfile
;
1111 /* If the main source file doesn't have any line number or symbol
1112 info, look for an alias in another subfile. */
1114 if (mainsub
->line_vector
== NULL
1115 && mainsub
->symtab
== NULL
)
1117 const char *mainbase
= lbasename (mainsub
->name
);
1119 struct subfile
*prevsub
;
1120 struct subfile
*mainsub_alias
= NULL
;
1121 struct subfile
*prev_mainsub_alias
= NULL
;
1124 for (subfile
= buildsym_compunit
->subfiles
;
1126 subfile
= subfile
->next
)
1128 if (subfile
== mainsub
)
1130 if (filename_cmp (lbasename (subfile
->name
), mainbase
) == 0)
1133 mainsub_alias
= subfile
;
1134 prev_mainsub_alias
= prevsub
;
1139 if (nr_matches
== 1)
1141 gdb_assert (mainsub_alias
!= NULL
&& mainsub_alias
!= mainsub
);
1143 /* Found a match for the main source file.
1144 Copy its line_vector and symtab to the main subfile
1145 and then discard it. */
1147 mainsub
->line_vector
= mainsub_alias
->line_vector
;
1148 mainsub
->line_vector_length
= mainsub_alias
->line_vector_length
;
1149 mainsub
->symtab
= mainsub_alias
->symtab
;
1151 if (prev_mainsub_alias
== NULL
)
1152 buildsym_compunit
->subfiles
= mainsub_alias
->next
;
1154 prev_mainsub_alias
->next
= mainsub_alias
->next
;
1155 xfree (mainsub_alias
->name
);
1156 xfree (mainsub_alias
);
1161 /* Reset state after a successful building of a symtab.
1162 This exists because dbxread.c and xcoffread.c can call
1163 start_symtab+end_symtab multiple times after one call to buildsym_init,
1164 and before the scoped_free_pendings destructor is called.
1165 We keep the free_pendings list around for dbx/xcoff sake. */
1168 reset_symtab_globals (void)
1170 set_last_source_file (NULL
);
1172 local_symbols
= NULL
;
1173 local_using_directives
= NULL
;
1174 file_symbols
= NULL
;
1175 global_symbols
= NULL
;
1176 global_using_directives
= NULL
;
1178 /* We don't free pending_macros here because if the symtab was successfully
1179 built then ownership was transferred to the symtab. */
1180 pending_macros
= NULL
;
1182 if (pending_addrmap
)
1183 obstack_free (&pending_addrmap_obstack
, NULL
);
1184 pending_addrmap
= NULL
;
1186 free_buildsym_compunit ();
1189 /* Implementation of the first part of end_symtab. It allows modifying
1190 STATIC_BLOCK before it gets finalized by end_symtab_from_static_block.
1191 If the returned value is NULL there is no blockvector created for
1192 this symtab (you still must call end_symtab_from_static_block).
1194 END_ADDR is the same as for end_symtab: the address of the end of the
1197 If EXPANDABLE is non-zero the STATIC_BLOCK dictionary is made
1200 If REQUIRED is non-zero, then a symtab is created even if it does
1201 not contain any symbols. */
1204 end_symtab_get_static_block (CORE_ADDR end_addr
, int expandable
, int required
)
1206 struct objfile
*objfile
= buildsym_compunit
->objfile
;
1208 /* Finish the lexical context of the last function in the file; pop
1209 the context stack. */
1211 if (context_stack_depth
> 0)
1213 struct context_stack
*cstk
= pop_context ();
1215 /* Make a block for the local symbols within. */
1216 finish_block (cstk
->name
, &local_symbols
, cstk
->old_blocks
, NULL
,
1217 cstk
->start_addr
, end_addr
);
1219 if (context_stack_depth
> 0)
1221 /* This is said to happen with SCO. The old coffread.c
1222 code simply emptied the context stack, so we do the
1223 same. FIXME: Find out why it is happening. This is not
1224 believed to happen in most cases (even for coffread.c);
1225 it used to be an abort(). */
1226 complaint (_("Context stack not empty in end_symtab"));
1227 context_stack_depth
= 0;
1231 /* Reordered executables may have out of order pending blocks; if
1232 OBJF_REORDERED is true, then sort the pending blocks. */
1234 if ((objfile
->flags
& OBJF_REORDERED
) && pending_blocks
)
1236 struct pending_block
*pb
;
1238 std::vector
<block
*> barray
;
1240 for (pb
= pending_blocks
; pb
!= NULL
; pb
= pb
->next
)
1241 barray
.push_back (pb
->block
);
1243 /* Sort blocks by start address in descending order. Blocks with the
1244 same start address must remain in the original order to preserve
1245 inline function caller/callee relationships. */
1246 std::stable_sort (barray
.begin (), barray
.end (),
1247 [] (const block
*a
, const block
*b
)
1249 return BLOCK_START (a
) > BLOCK_START (b
);
1253 for (pb
= pending_blocks
; pb
!= NULL
; pb
= pb
->next
)
1254 pb
->block
= barray
[i
++];
1257 /* Cleanup any undefined types that have been left hanging around
1258 (this needs to be done before the finish_blocks so that
1259 file_symbols is still good).
1261 Both cleanup_undefined_stabs_types and finish_global_stabs are stabs
1262 specific, but harmless for other symbol readers, since on gdb
1263 startup or when finished reading stabs, the state is set so these
1264 are no-ops. FIXME: Is this handled right in case of QUIT? Can
1265 we make this cleaner? */
1267 cleanup_undefined_stabs_types (objfile
);
1268 finish_global_stabs (objfile
);
1271 && pending_blocks
== NULL
1272 && file_symbols
== NULL
1273 && global_symbols
== NULL
1274 && have_line_numbers
== 0
1275 && pending_macros
== NULL
1276 && global_using_directives
== NULL
)
1278 /* Ignore symtabs that have no functions with real debugging info. */
1283 /* Define the STATIC_BLOCK. */
1284 return finish_block_internal (NULL
, &file_symbols
, NULL
, NULL
,
1285 last_source_start_addr
, end_addr
,
1290 /* Subroutine of end_symtab_from_static_block to simplify it.
1291 Handle the "have blockvector" case.
1292 See end_symtab_from_static_block for a description of the arguments. */
1294 static struct compunit_symtab
*
1295 end_symtab_with_blockvector (struct block
*static_block
,
1296 int section
, int expandable
)
1298 struct objfile
*objfile
= buildsym_compunit
->objfile
;
1299 struct compunit_symtab
*cu
= buildsym_compunit
->compunit_symtab
;
1300 struct symtab
*symtab
;
1301 struct blockvector
*blockvector
;
1302 struct subfile
*subfile
;
1305 gdb_assert (static_block
!= NULL
);
1306 gdb_assert (buildsym_compunit
!= NULL
);
1307 gdb_assert (buildsym_compunit
->subfiles
!= NULL
);
1309 end_addr
= BLOCK_END (static_block
);
1311 /* Create the GLOBAL_BLOCK and build the blockvector. */
1312 finish_block_internal (NULL
, &global_symbols
, NULL
, NULL
,
1313 last_source_start_addr
, end_addr
,
1315 blockvector
= make_blockvector ();
1317 /* Read the line table if it has to be read separately.
1318 This is only used by xcoffread.c. */
1319 if (objfile
->sf
->sym_read_linetable
!= NULL
)
1320 objfile
->sf
->sym_read_linetable (objfile
);
1322 /* Handle the case where the debug info specifies a different path
1323 for the main source file. It can cause us to lose track of its
1324 line number information. */
1325 watch_main_source_file_lossage ();
1327 /* Now create the symtab objects proper, if not already done,
1328 one for each subfile. */
1330 for (subfile
= buildsym_compunit
->subfiles
;
1332 subfile
= subfile
->next
)
1334 int linetablesize
= 0;
1336 if (subfile
->line_vector
)
1338 linetablesize
= sizeof (struct linetable
) +
1339 subfile
->line_vector
->nitems
* sizeof (struct linetable_entry
);
1341 /* Like the pending blocks, the line table may be
1342 scrambled in reordered executables. Sort it if
1343 OBJF_REORDERED is true. */
1344 if (objfile
->flags
& OBJF_REORDERED
)
1345 qsort (subfile
->line_vector
->item
,
1346 subfile
->line_vector
->nitems
,
1347 sizeof (struct linetable_entry
), compare_line_numbers
);
1350 /* Allocate a symbol table if necessary. */
1351 if (subfile
->symtab
== NULL
)
1352 subfile
->symtab
= allocate_symtab (cu
, subfile
->name
);
1353 symtab
= subfile
->symtab
;
1355 /* Fill in its components. */
1357 if (subfile
->line_vector
)
1359 /* Reallocate the line table on the symbol obstack. */
1360 SYMTAB_LINETABLE (symtab
) = (struct linetable
*)
1361 obstack_alloc (&objfile
->objfile_obstack
, linetablesize
);
1362 memcpy (SYMTAB_LINETABLE (symtab
), subfile
->line_vector
,
1367 SYMTAB_LINETABLE (symtab
) = NULL
;
1370 /* Use whatever language we have been using for this
1371 subfile, not the one that was deduced in allocate_symtab
1372 from the filename. We already did our own deducing when
1373 we created the subfile, and we may have altered our
1374 opinion of what language it is from things we found in
1376 symtab
->language
= subfile
->language
;
1379 /* Make sure the symtab of main_subfile is the first in its list. */
1381 struct symtab
*main_symtab
, *prev_symtab
;
1383 main_symtab
= buildsym_compunit
->main_subfile
->symtab
;
1385 ALL_COMPUNIT_FILETABS (cu
, symtab
)
1387 if (symtab
== main_symtab
)
1389 if (prev_symtab
!= NULL
)
1391 prev_symtab
->next
= main_symtab
->next
;
1392 main_symtab
->next
= COMPUNIT_FILETABS (cu
);
1393 COMPUNIT_FILETABS (cu
) = main_symtab
;
1397 prev_symtab
= symtab
;
1399 gdb_assert (main_symtab
== COMPUNIT_FILETABS (cu
));
1402 /* Fill out the compunit symtab. */
1404 if (buildsym_compunit
->comp_dir
!= NULL
)
1406 /* Reallocate the dirname on the symbol obstack. */
1407 const char *comp_dir
= buildsym_compunit
->comp_dir
.get ();
1408 COMPUNIT_DIRNAME (cu
)
1409 = (const char *) obstack_copy0 (&objfile
->objfile_obstack
,
1410 comp_dir
, strlen (comp_dir
));
1413 /* Save the debug format string (if any) in the symtab. */
1414 COMPUNIT_DEBUGFORMAT (cu
) = buildsym_compunit
->debugformat
;
1416 /* Similarly for the producer. */
1417 COMPUNIT_PRODUCER (cu
) = buildsym_compunit
->producer
;
1419 COMPUNIT_BLOCKVECTOR (cu
) = blockvector
;
1421 struct block
*b
= BLOCKVECTOR_BLOCK (blockvector
, GLOBAL_BLOCK
);
1423 set_block_compunit_symtab (b
, cu
);
1426 COMPUNIT_BLOCK_LINE_SECTION (cu
) = section
;
1428 COMPUNIT_MACRO_TABLE (cu
) = pending_macros
;
1430 /* Default any symbols without a specified symtab to the primary symtab. */
1434 /* The main source file's symtab. */
1435 symtab
= COMPUNIT_FILETABS (cu
);
1437 for (block_i
= 0; block_i
< BLOCKVECTOR_NBLOCKS (blockvector
); block_i
++)
1439 struct block
*block
= BLOCKVECTOR_BLOCK (blockvector
, block_i
);
1441 struct dict_iterator iter
;
1443 /* Inlined functions may have symbols not in the global or
1444 static symbol lists. */
1445 if (BLOCK_FUNCTION (block
) != NULL
)
1446 if (symbol_symtab (BLOCK_FUNCTION (block
)) == NULL
)
1447 symbol_set_symtab (BLOCK_FUNCTION (block
), symtab
);
1449 /* Note that we only want to fix up symbols from the local
1450 blocks, not blocks coming from included symtabs. That is why
1451 we use ALL_DICT_SYMBOLS here and not ALL_BLOCK_SYMBOLS. */
1452 ALL_DICT_SYMBOLS (BLOCK_DICT (block
), iter
, sym
)
1453 if (symbol_symtab (sym
) == NULL
)
1454 symbol_set_symtab (sym
, symtab
);
1458 add_compunit_symtab_to_objfile (cu
);
1463 /* Implementation of the second part of end_symtab. Pass STATIC_BLOCK
1464 as value returned by end_symtab_get_static_block.
1466 SECTION is the same as for end_symtab: the section number
1467 (in objfile->section_offsets) of the blockvector and linetable.
1469 If EXPANDABLE is non-zero the GLOBAL_BLOCK dictionary is made
1472 struct compunit_symtab
*
1473 end_symtab_from_static_block (struct block
*static_block
,
1474 int section
, int expandable
)
1476 struct compunit_symtab
*cu
;
1478 if (static_block
== NULL
)
1480 /* Handle the "no blockvector" case.
1481 When this happens there is nothing to record, so there's nothing
1482 to do: memory will be freed up later.
1484 Note: We won't be adding a compunit to the objfile's list of
1485 compunits, so there's nothing to unchain. However, since each symtab
1486 is added to the objfile's obstack we can't free that space.
1487 We could do better, but this is believed to be a sufficiently rare
1492 cu
= end_symtab_with_blockvector (static_block
, section
, expandable
);
1494 reset_symtab_globals ();
1499 /* Finish the symbol definitions for one main source file, close off
1500 all the lexical contexts for that file (creating struct block's for
1501 them), then make the struct symtab for that file and put it in the
1504 END_ADDR is the address of the end of the file's text. SECTION is
1505 the section number (in objfile->section_offsets) of the blockvector
1508 Note that it is possible for end_symtab() to return NULL. In
1509 particular, for the DWARF case at least, it will return NULL when
1510 it finds a compilation unit that has exactly one DIE, a
1511 TAG_compile_unit DIE. This can happen when we link in an object
1512 file that was compiled from an empty source file. Returning NULL
1513 is probably not the correct thing to do, because then gdb will
1514 never know about this empty file (FIXME).
1516 If you need to modify STATIC_BLOCK before it is finalized you should
1517 call end_symtab_get_static_block and end_symtab_from_static_block
1520 struct compunit_symtab
*
1521 end_symtab (CORE_ADDR end_addr
, int section
)
1523 struct block
*static_block
;
1525 static_block
= end_symtab_get_static_block (end_addr
, 0, 0);
1526 return end_symtab_from_static_block (static_block
, section
, 0);
1529 /* Same as end_symtab except create a symtab that can be later added to. */
1531 struct compunit_symtab
*
1532 end_expandable_symtab (CORE_ADDR end_addr
, int section
)
1534 struct block
*static_block
;
1536 static_block
= end_symtab_get_static_block (end_addr
, 1, 0);
1537 return end_symtab_from_static_block (static_block
, section
, 1);
1540 /* Subroutine of augment_type_symtab to simplify it.
1541 Attach the main source file's symtab to all symbols in PENDING_LIST that
1545 set_missing_symtab (struct pending
*pending_list
,
1546 struct compunit_symtab
*cu
)
1548 struct pending
*pending
;
1551 for (pending
= pending_list
; pending
!= NULL
; pending
= pending
->next
)
1553 for (i
= 0; i
< pending
->nsyms
; ++i
)
1555 if (symbol_symtab (pending
->symbol
[i
]) == NULL
)
1556 symbol_set_symtab (pending
->symbol
[i
], COMPUNIT_FILETABS (cu
));
1561 /* Same as end_symtab, but for the case where we're adding more symbols
1562 to an existing symtab that is known to contain only type information.
1563 This is the case for DWARF4 Type Units. */
1566 augment_type_symtab (void)
1568 struct compunit_symtab
*cust
= buildsym_compunit
->compunit_symtab
;
1569 const struct blockvector
*blockvector
= COMPUNIT_BLOCKVECTOR (cust
);
1571 if (context_stack_depth
> 0)
1573 complaint (_("Context stack not empty in augment_type_symtab"));
1574 context_stack_depth
= 0;
1576 if (pending_blocks
!= NULL
)
1577 complaint (_("Blocks in a type symtab"));
1578 if (pending_macros
!= NULL
)
1579 complaint (_("Macro in a type symtab"));
1580 if (have_line_numbers
)
1581 complaint (_("Line numbers recorded in a type symtab"));
1583 if (file_symbols
!= NULL
)
1585 struct block
*block
= BLOCKVECTOR_BLOCK (blockvector
, STATIC_BLOCK
);
1587 /* First mark any symbols without a specified symtab as belonging
1588 to the primary symtab. */
1589 set_missing_symtab (file_symbols
, cust
);
1591 dict_add_pending (BLOCK_DICT (block
), file_symbols
);
1594 if (global_symbols
!= NULL
)
1596 struct block
*block
= BLOCKVECTOR_BLOCK (blockvector
, GLOBAL_BLOCK
);
1598 /* First mark any symbols without a specified symtab as belonging
1599 to the primary symtab. */
1600 set_missing_symtab (global_symbols
, cust
);
1602 dict_add_pending (BLOCK_DICT (block
), global_symbols
);
1605 reset_symtab_globals ();
1608 /* Push a context block. Args are an identifying nesting level
1609 (checkable when you pop it), and the starting PC address of this
1612 struct context_stack
*
1613 push_context (int desc
, CORE_ADDR valu
)
1615 struct context_stack
*newobj
;
1617 if (context_stack_depth
== context_stack_size
)
1619 context_stack_size
*= 2;
1620 context_stack
= (struct context_stack
*)
1621 xrealloc ((char *) context_stack
,
1622 (context_stack_size
* sizeof (struct context_stack
)));
1625 newobj
= &context_stack
[context_stack_depth
++];
1626 newobj
->depth
= desc
;
1627 newobj
->locals
= local_symbols
;
1628 newobj
->old_blocks
= pending_blocks
;
1629 newobj
->start_addr
= valu
;
1630 newobj
->local_using_directives
= local_using_directives
;
1631 newobj
->name
= NULL
;
1633 local_symbols
= NULL
;
1634 local_using_directives
= NULL
;
1639 /* Pop a context block. Returns the address of the context block just
1642 struct context_stack
*
1645 gdb_assert (context_stack_depth
> 0);
1646 return (&context_stack
[--context_stack_depth
]);
1651 /* Compute a small integer hash code for the given name. */
1654 hashname (const char *name
)
1656 return (hash(name
,strlen(name
)) % HASHSIZE
);
1661 record_debugformat (const char *format
)
1663 buildsym_compunit
->debugformat
= format
;
1667 record_producer (const char *producer
)
1669 buildsym_compunit
->producer
= producer
;
1672 /* Merge the first symbol list SRCLIST into the second symbol list
1673 TARGETLIST by repeated calls to add_symbol_to_list(). This
1674 procedure "frees" each link of SRCLIST by adding it to the
1675 free_pendings list. Caller must set SRCLIST to a null list after
1676 calling this function.
1681 merge_symbol_lists (struct pending
**srclist
, struct pending
**targetlist
)
1685 if (!srclist
|| !*srclist
)
1688 /* Merge in elements from current link. */
1689 for (i
= 0; i
< (*srclist
)->nsyms
; i
++)
1690 add_symbol_to_list ((*srclist
)->symbol
[i
], targetlist
);
1692 /* Recurse on next. */
1693 merge_symbol_lists (&(*srclist
)->next
, targetlist
);
1695 /* "Free" the current link. */
1696 (*srclist
)->next
= free_pendings
;
1697 free_pendings
= (*srclist
);
1701 /* Name of source file whose symbol data we are now processing. This
1702 comes from a symbol of type N_SO for stabs. For Dwarf it comes
1703 from the DW_AT_name attribute of a DW_TAG_compile_unit DIE. */
1705 static char *last_source_file
;
1707 /* See buildsym.h. */
1710 set_last_source_file (const char *name
)
1712 xfree (last_source_file
);
1713 last_source_file
= name
== NULL
? NULL
: xstrdup (name
);
1716 /* See buildsym.h. */
1719 get_last_source_file (void)
1721 return last_source_file
;
1726 /* Initialize anything that needs initializing when starting to read a
1727 fresh piece of a symbol file, e.g. reading in the stuff
1728 corresponding to a psymtab. */
1731 buildsym_init (void)
1733 subfile_stack
= NULL
;
1735 pending_addrmap_interesting
= 0;
1737 /* Context stack is initially empty. Allocate first one with room
1738 for a few levels; reuse it forever afterward. */
1739 if (context_stack
== NULL
)
1741 context_stack_size
= INITIAL_CONTEXT_STACK_SIZE
;
1742 context_stack
= XNEWVEC (struct context_stack
, context_stack_size
);
1745 /* Ensure the scoped_free_pendings destructor was called after
1747 gdb_assert (free_pendings
== NULL
);
1748 gdb_assert (pending_blocks
== NULL
);
1749 gdb_assert (file_symbols
== NULL
);
1750 gdb_assert (global_symbols
== NULL
);
1751 gdb_assert (global_using_directives
== NULL
);
1752 gdb_assert (pending_macros
== NULL
);
1753 gdb_assert (pending_addrmap
== NULL
);
1754 gdb_assert (buildsym_compunit
== NULL
);
1757 /* Initialize anything that needs initializing when a completely new
1758 symbol file is specified (not just adding some symbols from another
1759 file, e.g. a shared library). */
1762 buildsym_new_init (void)