1 /* Support routines for building symbol tables in GDB's internal format.
2 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
3 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
4 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
23 /* This module provides subroutines used for creating and adding to
24 the symbol table. These routines are called from various symbol-
25 file-reading routines.
27 Routines to support specific debugging information formats (stabs,
28 DWARF, etc) belong somewhere else. */
32 #include "gdb_obstack.h"
37 #include "gdb_assert.h"
38 #include "complaints.h"
39 #include "gdb_string.h"
40 #include "expression.h" /* For "enum exp_opcode" used by... */
42 #include "filenames.h" /* For DOSish file names */
44 #include "demangle.h" /* Needed by SYMBOL_INIT_DEMANGLED_NAME. */
46 #include "cp-support.h"
47 #include "dictionary.h"
49 /* Ask buildsym.h to define the vars it normally declares `extern'. */
52 #include "buildsym.h" /* Our own declarations */
55 /* For cleanup_undefined_types and finish_global_stabs (somewhat
56 questionable--see comment where we call them). */
58 #include "stabsread.h"
60 /* List of free `struct pending' structures for reuse. */
62 static struct pending
*free_pendings
;
64 /* Non-zero if symtab has line number info. This prevents an
65 otherwise empty symtab from being tossed. */
67 static int have_line_numbers
;
69 static int compare_line_numbers (const void *ln1p
, const void *ln2p
);
72 /* Initial sizes of data structures. These are realloc'd larger if
73 needed, and realloc'd down to the size actually used, when
76 #define INITIAL_CONTEXT_STACK_SIZE 10
77 #define INITIAL_LINE_VECTOR_LENGTH 1000
80 /* maintain the lists of symbols and blocks */
82 /* Add a pending list to free_pendings. */
84 add_free_pendings (struct pending
*list
)
86 struct pending
*link
= list
;
90 while (link
->next
) link
= link
->next
;
91 link
->next
= free_pendings
;
96 /* Add a symbol to one of the lists of symbols. While we're at it, if
97 we're in the C++ case and don't have full namespace debugging info,
98 check to see if it references an anonymous namespace; if so, add an
99 appropriate using directive. */
102 add_symbol_to_list (struct symbol
*symbol
, struct pending
**listhead
)
104 struct pending
*link
;
106 /* If this is an alias for another symbol, don't add it. */
107 if (symbol
->ginfo
.name
&& symbol
->ginfo
.name
[0] == '#')
110 /* We keep PENDINGSIZE symbols in each link of the list. If we
111 don't have a link with room in it, add a new link. */
112 if (*listhead
== NULL
|| (*listhead
)->nsyms
== PENDINGSIZE
)
116 link
= free_pendings
;
117 free_pendings
= link
->next
;
121 link
= (struct pending
*) xmalloc (sizeof (struct pending
));
124 link
->next
= *listhead
;
129 (*listhead
)->symbol
[(*listhead
)->nsyms
++] = symbol
;
131 /* Check to see if we might need to look for a mention of anonymous
134 if (SYMBOL_LANGUAGE (symbol
) == language_cplus
)
135 cp_scan_for_anonymous_namespaces (symbol
);
138 /* Find a symbol named NAME on a LIST. NAME need not be
139 '\0'-terminated; LENGTH is the length of the name. */
142 find_symbol_in_list (struct pending
*list
, char *name
, int length
)
149 for (j
= list
->nsyms
; --j
>= 0;)
151 pp
= DEPRECATED_SYMBOL_NAME (list
->symbol
[j
]);
152 if (*pp
== *name
&& strncmp (pp
, name
, length
) == 0 &&
155 return (list
->symbol
[j
]);
163 /* At end of reading syms, or in case of quit, really free as many
164 `struct pending's as we can easily find. */
167 really_free_pendings (void *dummy
)
169 struct pending
*next
, *next1
;
171 for (next
= free_pendings
; next
; next
= next1
)
174 xfree ((void *) next
);
176 free_pendings
= NULL
;
178 free_pending_blocks ();
180 for (next
= file_symbols
; next
!= NULL
; next
= next1
)
183 xfree ((void *) next
);
187 for (next
= global_symbols
; next
!= NULL
; next
= next1
)
190 xfree ((void *) next
);
192 global_symbols
= NULL
;
195 free_macro_table (pending_macros
);
198 /* This function is called to discard any pending blocks. */
201 free_pending_blocks (void)
203 #if 0 /* Now we make the links in the
204 objfile_obstack, so don't free
206 struct pending_block
*bnext
, *bnext1
;
208 for (bnext
= pending_blocks
; bnext
; bnext
= bnext1
)
210 bnext1
= bnext
->next
;
211 xfree ((void *) bnext
);
214 pending_blocks
= NULL
;
217 /* Take one of the lists of symbols and make a block from it. Keep
218 the order the symbols have in the list (reversed from the input
219 file). Put the block on the list of pending blocks. */
222 finish_block (struct symbol
*symbol
, struct pending
**listhead
,
223 struct pending_block
*old_blocks
,
224 CORE_ADDR start
, CORE_ADDR end
,
225 struct objfile
*objfile
)
227 struct pending
*next
, *next1
;
229 struct pending_block
*pblock
;
230 struct pending_block
*opblock
;
232 block
= allocate_block (&objfile
->objfile_obstack
);
236 BLOCK_DICT (block
) = dict_create_linear (&objfile
->objfile_obstack
,
241 BLOCK_DICT (block
) = dict_create_hashed (&objfile
->objfile_obstack
,
245 BLOCK_START (block
) = start
;
246 BLOCK_END (block
) = end
;
247 /* Superblock filled in when containing block is made */
248 BLOCK_SUPERBLOCK (block
) = NULL
;
249 BLOCK_NAMESPACE (block
) = NULL
;
251 BLOCK_GCC_COMPILED (block
) = processing_gcc_compilation
;
253 /* Put the block in as the value of the symbol that names it. */
257 struct type
*ftype
= SYMBOL_TYPE (symbol
);
258 struct dict_iterator iter
;
259 SYMBOL_BLOCK_VALUE (symbol
) = block
;
260 BLOCK_FUNCTION (block
) = symbol
;
262 if (TYPE_NFIELDS (ftype
) <= 0)
264 /* No parameter type information is recorded with the
265 function's type. Set that from the type of the
266 parameter symbols. */
267 int nparams
= 0, iparams
;
269 ALL_BLOCK_SYMBOLS (block
, iter
, sym
)
271 switch (SYMBOL_CLASS (sym
))
276 case LOC_REGPARM_ADDR
:
277 case LOC_BASEREG_ARG
:
279 case LOC_COMPUTED_ARG
:
291 case LOC_CONST_BYTES
:
294 case LOC_OPTIMIZED_OUT
:
302 TYPE_NFIELDS (ftype
) = nparams
;
303 TYPE_FIELDS (ftype
) = (struct field
*)
304 TYPE_ALLOC (ftype
, nparams
* sizeof (struct field
));
307 ALL_BLOCK_SYMBOLS (block
, iter
, sym
)
309 if (iparams
== nparams
)
312 switch (SYMBOL_CLASS (sym
))
317 case LOC_REGPARM_ADDR
:
318 case LOC_BASEREG_ARG
:
320 case LOC_COMPUTED_ARG
:
321 TYPE_FIELD_TYPE (ftype
, iparams
) = SYMBOL_TYPE (sym
);
322 TYPE_FIELD_ARTIFICIAL (ftype
, iparams
) = 0;
334 case LOC_CONST_BYTES
:
337 case LOC_OPTIMIZED_OUT
:
346 /* If we're in the C++ case, set the block's scope. */
347 if (SYMBOL_LANGUAGE (symbol
) == language_cplus
)
349 cp_set_block_scope (symbol
, block
, &objfile
->objfile_obstack
);
354 BLOCK_FUNCTION (block
) = NULL
;
357 /* Now "free" the links of the list, and empty the list. */
359 for (next
= *listhead
; next
; next
= next1
)
362 next
->next
= free_pendings
;
363 free_pendings
= next
;
368 /* Check to be sure that the blocks have an end address that is
369 greater than starting address */
371 if (BLOCK_END (block
) < BLOCK_START (block
))
375 complaint (&symfile_complaints
,
376 _("block end address less than block start address in %s (patched it)"),
377 SYMBOL_PRINT_NAME (symbol
));
381 complaint (&symfile_complaints
,
382 _("block end address 0x%s less than block start address 0x%s (patched it)"),
383 paddr_nz (BLOCK_END (block
)), paddr_nz (BLOCK_START (block
)));
385 /* Better than nothing */
386 BLOCK_END (block
) = BLOCK_START (block
);
390 /* Install this block as the superblock of all blocks made since the
391 start of this scope that don't have superblocks yet. */
394 for (pblock
= pending_blocks
;
395 pblock
&& pblock
!= old_blocks
;
396 pblock
= pblock
->next
)
398 if (BLOCK_SUPERBLOCK (pblock
->block
) == NULL
)
401 /* Check to be sure the blocks are nested as we receive
402 them. If the compiler/assembler/linker work, this just
403 burns a small amount of time. */
404 if (BLOCK_START (pblock
->block
) < BLOCK_START (block
) ||
405 BLOCK_END (pblock
->block
) > BLOCK_END (block
))
409 complaint (&symfile_complaints
,
410 _("inner block not inside outer block in %s"),
411 SYMBOL_PRINT_NAME (symbol
));
415 complaint (&symfile_complaints
,
416 _("inner block (0x%s-0x%s) not inside outer block (0x%s-0x%s)"),
417 paddr_nz (BLOCK_START (pblock
->block
)),
418 paddr_nz (BLOCK_END (pblock
->block
)),
419 paddr_nz (BLOCK_START (block
)),
420 paddr_nz (BLOCK_END (block
)));
422 if (BLOCK_START (pblock
->block
) < BLOCK_START (block
))
423 BLOCK_START (pblock
->block
) = BLOCK_START (block
);
424 if (BLOCK_END (pblock
->block
) > BLOCK_END (block
))
425 BLOCK_END (pblock
->block
) = BLOCK_END (block
);
428 BLOCK_SUPERBLOCK (pblock
->block
) = block
;
433 record_pending_block (objfile
, block
, opblock
);
437 /* Record BLOCK on the list of all blocks in the file. Put it after
438 OPBLOCK, or at the beginning if opblock is NULL. This puts the
439 block in the list after all its subblocks.
441 Allocate the pending block struct in the objfile_obstack to save
442 time. This wastes a little space. FIXME: Is it worth it? */
445 record_pending_block (struct objfile
*objfile
, struct block
*block
,
446 struct pending_block
*opblock
)
448 struct pending_block
*pblock
;
450 pblock
= (struct pending_block
*)
451 obstack_alloc (&objfile
->objfile_obstack
, sizeof (struct pending_block
));
452 pblock
->block
= block
;
455 pblock
->next
= opblock
->next
;
456 opblock
->next
= pblock
;
460 pblock
->next
= pending_blocks
;
461 pending_blocks
= pblock
;
465 static struct blockvector
*
466 make_blockvector (struct objfile
*objfile
)
468 struct pending_block
*next
;
469 struct blockvector
*blockvector
;
472 /* Count the length of the list of blocks. */
474 for (next
= pending_blocks
, i
= 0; next
; next
= next
->next
, i
++)
478 blockvector
= (struct blockvector
*)
479 obstack_alloc (&objfile
->objfile_obstack
,
480 (sizeof (struct blockvector
)
481 + (i
- 1) * sizeof (struct block
*)));
483 /* Copy the blocks into the blockvector. This is done in reverse
484 order, which happens to put the blocks into the proper order
485 (ascending starting address). finish_block has hair to insert
486 each block into the list after its subblocks in order to make
487 sure this is true. */
489 BLOCKVECTOR_NBLOCKS (blockvector
) = i
;
490 for (next
= pending_blocks
; next
; next
= next
->next
)
492 BLOCKVECTOR_BLOCK (blockvector
, --i
) = next
->block
;
495 #if 0 /* Now we make the links in the
496 obstack, so don't free them. */
497 /* Now free the links of the list, and empty the list. */
499 for (next
= pending_blocks
; next
; next
= next1
)
505 pending_blocks
= NULL
;
507 #if 1 /* FIXME, shut this off after a while
508 to speed up symbol reading. */
509 /* Some compilers output blocks in the wrong order, but we depend on
510 their being in the right order so we can binary search. Check the
511 order and moan about it. FIXME. */
512 if (BLOCKVECTOR_NBLOCKS (blockvector
) > 1)
514 for (i
= 1; i
< BLOCKVECTOR_NBLOCKS (blockvector
); i
++)
516 if (BLOCK_START (BLOCKVECTOR_BLOCK (blockvector
, i
- 1))
517 > BLOCK_START (BLOCKVECTOR_BLOCK (blockvector
, i
)))
520 = BLOCK_START (BLOCKVECTOR_BLOCK (blockvector
, i
));
522 complaint (&symfile_complaints
, _("block at %s out of order"),
523 hex_string ((LONGEST
) start
));
529 return (blockvector
);
532 /* Start recording information about source code that came from an
533 included (or otherwise merged-in) source file with a different
534 name. NAME is the name of the file (cannot be NULL), DIRNAME is
535 the directory in which it resides (or NULL if not known). */
538 start_subfile (char *name
, char *dirname
)
540 struct subfile
*subfile
;
542 /* See if this subfile is already known as a subfile of the current
545 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
547 if (FILENAME_CMP (subfile
->name
, name
) == 0)
549 current_subfile
= subfile
;
554 /* This subfile is not known. Add an entry for it. Make an entry
555 for this subfile in the list of all subfiles of the current main
558 subfile
= (struct subfile
*) xmalloc (sizeof (struct subfile
));
559 memset ((char *) subfile
, 0, sizeof (struct subfile
));
560 subfile
->next
= subfiles
;
562 current_subfile
= subfile
;
564 /* Save its name and compilation directory name */
565 subfile
->name
= (name
== NULL
) ? NULL
: savestring (name
, strlen (name
));
567 (dirname
== NULL
) ? NULL
: savestring (dirname
, strlen (dirname
));
569 /* Initialize line-number recording for this subfile. */
570 subfile
->line_vector
= NULL
;
572 /* Default the source language to whatever can be deduced from the
573 filename. If nothing can be deduced (such as for a C/C++ include
574 file with a ".h" extension), then inherit whatever language the
575 previous subfile had. This kludgery is necessary because there
576 is no standard way in some object formats to record the source
577 language. Also, when symtabs are allocated we try to deduce a
578 language then as well, but it is too late for us to use that
579 information while reading symbols, since symtabs aren't allocated
580 until after all the symbols have been processed for a given
583 subfile
->language
= deduce_language_from_filename (subfile
->name
);
584 if (subfile
->language
== language_unknown
&&
585 subfile
->next
!= NULL
)
587 subfile
->language
= subfile
->next
->language
;
590 /* Initialize the debug format string to NULL. We may supply it
591 later via a call to record_debugformat. */
592 subfile
->debugformat
= NULL
;
594 /* If the filename of this subfile ends in .C, then change the
595 language of any pending subfiles from C to C++. We also accept
596 any other C++ suffixes accepted by deduce_language_from_filename. */
597 /* Likewise for f2c. */
602 enum language sublang
= deduce_language_from_filename (subfile
->name
);
604 if (sublang
== language_cplus
|| sublang
== language_fortran
)
605 for (s
= subfiles
; s
!= NULL
; s
= s
->next
)
606 if (s
->language
== language_c
)
607 s
->language
= sublang
;
610 /* And patch up this file if necessary. */
611 if (subfile
->language
== language_c
612 && subfile
->next
!= NULL
613 && (subfile
->next
->language
== language_cplus
614 || subfile
->next
->language
== language_fortran
))
616 subfile
->language
= subfile
->next
->language
;
620 /* For stabs readers, the first N_SO symbol is assumed to be the
621 source file name, and the subfile struct is initialized using that
622 assumption. If another N_SO symbol is later seen, immediately
623 following the first one, then the first one is assumed to be the
624 directory name and the second one is really the source file name.
626 So we have to patch up the subfile struct by moving the old name
627 value to dirname and remembering the new name. Some sanity
628 checking is performed to ensure that the state of the subfile
629 struct is reasonable and that the old name we are assuming to be a
630 directory name actually is (by checking for a trailing '/'). */
633 patch_subfile_names (struct subfile
*subfile
, char *name
)
635 if (subfile
!= NULL
&& subfile
->dirname
== NULL
&& subfile
->name
!= NULL
636 && subfile
->name
[strlen (subfile
->name
) - 1] == '/')
638 subfile
->dirname
= subfile
->name
;
639 subfile
->name
= savestring (name
, strlen (name
));
640 last_source_file
= name
;
642 /* Default the source language to whatever can be deduced from
643 the filename. If nothing can be deduced (such as for a C/C++
644 include file with a ".h" extension), then inherit whatever
645 language the previous subfile had. This kludgery is
646 necessary because there is no standard way in some object
647 formats to record the source language. Also, when symtabs
648 are allocated we try to deduce a language then as well, but
649 it is too late for us to use that information while reading
650 symbols, since symtabs aren't allocated until after all the
651 symbols have been processed for a given source file. */
653 subfile
->language
= deduce_language_from_filename (subfile
->name
);
654 if (subfile
->language
== language_unknown
&&
655 subfile
->next
!= NULL
)
657 subfile
->language
= subfile
->next
->language
;
662 /* Handle the N_BINCL and N_EINCL symbol types that act like N_SOL for
663 switching source files (different subfiles, as we call them) within
664 one object file, but using a stack rather than in an arbitrary
670 struct subfile_stack
*tem
671 = (struct subfile_stack
*) xmalloc (sizeof (struct subfile_stack
));
673 tem
->next
= subfile_stack
;
675 if (current_subfile
== NULL
|| current_subfile
->name
== NULL
)
677 internal_error (__FILE__
, __LINE__
, _("failed internal consistency check"));
679 tem
->name
= current_subfile
->name
;
686 struct subfile_stack
*link
= subfile_stack
;
690 internal_error (__FILE__
, __LINE__
, _("failed internal consistency check"));
693 subfile_stack
= link
->next
;
694 xfree ((void *) link
);
698 /* Add a linetable entry for line number LINE and address PC to the
699 line vector for SUBFILE. */
702 record_line (struct subfile
*subfile
, int line
, CORE_ADDR pc
)
704 struct linetable_entry
*e
;
705 /* Ignore the dummy line number in libg.o */
712 /* Make sure line vector exists and is big enough. */
713 if (!subfile
->line_vector
)
715 subfile
->line_vector_length
= INITIAL_LINE_VECTOR_LENGTH
;
716 subfile
->line_vector
= (struct linetable
*)
717 xmalloc (sizeof (struct linetable
)
718 + subfile
->line_vector_length
* sizeof (struct linetable_entry
));
719 subfile
->line_vector
->nitems
= 0;
720 have_line_numbers
= 1;
723 if (subfile
->line_vector
->nitems
+ 1 >= subfile
->line_vector_length
)
725 subfile
->line_vector_length
*= 2;
726 subfile
->line_vector
= (struct linetable
*)
727 xrealloc ((char *) subfile
->line_vector
,
728 (sizeof (struct linetable
)
729 + (subfile
->line_vector_length
730 * sizeof (struct linetable_entry
))));
733 e
= subfile
->line_vector
->item
+ subfile
->line_vector
->nitems
++;
735 e
->pc
= ADDR_BITS_REMOVE(pc
);
738 /* Needed in order to sort line tables from IBM xcoff files. Sigh! */
741 compare_line_numbers (const void *ln1p
, const void *ln2p
)
743 struct linetable_entry
*ln1
= (struct linetable_entry
*) ln1p
;
744 struct linetable_entry
*ln2
= (struct linetable_entry
*) ln2p
;
746 /* Note: this code does not assume that CORE_ADDRs can fit in ints.
747 Please keep it that way. */
748 if (ln1
->pc
< ln2
->pc
)
751 if (ln1
->pc
> ln2
->pc
)
754 /* If pc equal, sort by line. I'm not sure whether this is optimum
755 behavior (see comment at struct linetable in symtab.h). */
756 return ln1
->line
- ln2
->line
;
759 /* Start a new symtab for a new source file. Called, for example,
760 when a stabs symbol of type N_SO is seen, or when a DWARF
761 TAG_compile_unit DIE is seen. It indicates the start of data for
762 one original source file. */
765 start_symtab (char *name
, char *dirname
, CORE_ADDR start_addr
)
768 last_source_file
= name
;
769 last_source_start_addr
= start_addr
;
771 global_symbols
= NULL
;
773 have_line_numbers
= 0;
775 /* Context stack is initially empty. Allocate first one with room
776 for 10 levels; reuse it forever afterward. */
777 if (context_stack
== NULL
)
779 context_stack_size
= INITIAL_CONTEXT_STACK_SIZE
;
780 context_stack
= (struct context_stack
*)
781 xmalloc (context_stack_size
* sizeof (struct context_stack
));
783 context_stack_depth
= 0;
785 /* Set up support for C++ namespace support, in case we need it. */
787 cp_initialize_namespace ();
789 /* Initialize the list of sub source files with one entry for this
790 file (the top-level source file). */
793 current_subfile
= NULL
;
794 start_subfile (name
, dirname
);
797 /* Finish the symbol definitions for one main source file, close off
798 all the lexical contexts for that file (creating struct block's for
799 them), then make the struct symtab for that file and put it in the
802 END_ADDR is the address of the end of the file's text. SECTION is
803 the section number (in objfile->section_offsets) of the blockvector
806 Note that it is possible for end_symtab() to return NULL. In
807 particular, for the DWARF case at least, it will return NULL when
808 it finds a compilation unit that has exactly one DIE, a
809 TAG_compile_unit DIE. This can happen when we link in an object
810 file that was compiled from an empty source file. Returning NULL
811 is probably not the correct thing to do, because then gdb will
812 never know about this empty file (FIXME). */
815 end_symtab (CORE_ADDR end_addr
, struct objfile
*objfile
, int section
)
817 struct symtab
*symtab
= NULL
;
818 struct blockvector
*blockvector
;
819 struct subfile
*subfile
;
820 struct context_stack
*cstk
;
821 struct subfile
*nextsub
;
823 /* Finish the lexical context of the last function in the file; pop
824 the context stack. */
826 if (context_stack_depth
> 0)
828 cstk
= pop_context ();
829 /* Make a block for the local symbols within. */
830 finish_block (cstk
->name
, &local_symbols
, cstk
->old_blocks
,
831 cstk
->start_addr
, end_addr
, objfile
);
833 if (context_stack_depth
> 0)
835 /* This is said to happen with SCO. The old coffread.c
836 code simply emptied the context stack, so we do the
837 same. FIXME: Find out why it is happening. This is not
838 believed to happen in most cases (even for coffread.c);
839 it used to be an abort(). */
840 complaint (&symfile_complaints
,
841 _("Context stack not empty in end_symtab"));
842 context_stack_depth
= 0;
846 /* Reordered executables may have out of order pending blocks; if
847 OBJF_REORDERED is true, then sort the pending blocks. */
848 if ((objfile
->flags
& OBJF_REORDERED
) && pending_blocks
)
850 /* FIXME! Remove this horrid bubble sort and use merge sort!!! */
854 struct pending_block
*pb
, *pbnext
;
862 /* swap blocks if unordered! */
864 if (BLOCK_START (pb
->block
) < BLOCK_START (pbnext
->block
))
866 struct block
*tmp
= pb
->block
;
867 pb
->block
= pbnext
->block
;
872 pbnext
= pbnext
->next
;
878 /* Cleanup any undefined types that have been left hanging around
879 (this needs to be done before the finish_blocks so that
880 file_symbols is still good).
882 Both cleanup_undefined_types and finish_global_stabs are stabs
883 specific, but harmless for other symbol readers, since on gdb
884 startup or when finished reading stabs, the state is set so these
885 are no-ops. FIXME: Is this handled right in case of QUIT? Can
886 we make this cleaner? */
888 cleanup_undefined_types ();
889 finish_global_stabs (objfile
);
891 if (pending_blocks
== NULL
892 && file_symbols
== NULL
893 && global_symbols
== NULL
894 && have_line_numbers
== 0
895 && pending_macros
== NULL
)
897 /* Ignore symtabs that have no functions with real debugging
903 /* Define the STATIC_BLOCK & GLOBAL_BLOCK, and build the
905 finish_block (0, &file_symbols
, 0, last_source_start_addr
, end_addr
,
907 finish_block (0, &global_symbols
, 0, last_source_start_addr
, end_addr
,
909 blockvector
= make_blockvector (objfile
);
910 cp_finalize_namespace (BLOCKVECTOR_BLOCK (blockvector
, STATIC_BLOCK
),
911 &objfile
->objfile_obstack
);
914 #ifndef PROCESS_LINENUMBER_HOOK
915 #define PROCESS_LINENUMBER_HOOK()
917 PROCESS_LINENUMBER_HOOK (); /* Needed for xcoff. */
919 /* Now create the symtab objects proper, one for each subfile. */
920 /* (The main file is the last one on the chain.) */
922 for (subfile
= subfiles
; subfile
; subfile
= nextsub
)
924 int linetablesize
= 0;
927 /* If we have blocks of symbols, make a symtab. Otherwise, just
928 ignore this file and any line number info in it. */
931 if (subfile
->line_vector
)
933 linetablesize
= sizeof (struct linetable
) +
934 subfile
->line_vector
->nitems
* sizeof (struct linetable_entry
);
936 /* I think this is artifact from before it went on the
937 obstack. I doubt we'll need the memory between now
938 and when we free it later in this function. */
939 /* First, shrink the linetable to make more memory. */
940 subfile
->line_vector
= (struct linetable
*)
941 xrealloc ((char *) subfile
->line_vector
, linetablesize
);
944 /* Like the pending blocks, the line table may be
945 scrambled in reordered executables. Sort it if
946 OBJF_REORDERED is true. */
947 if (objfile
->flags
& OBJF_REORDERED
)
948 qsort (subfile
->line_vector
->item
,
949 subfile
->line_vector
->nitems
,
950 sizeof (struct linetable_entry
), compare_line_numbers
);
953 /* Now, allocate a symbol table. */
954 symtab
= allocate_symtab (subfile
->name
, objfile
);
956 /* Fill in its components. */
957 symtab
->blockvector
= blockvector
;
958 symtab
->macro_table
= pending_macros
;
959 if (subfile
->line_vector
)
961 /* Reallocate the line table on the symbol obstack */
962 symtab
->linetable
= (struct linetable
*)
963 obstack_alloc (&objfile
->objfile_obstack
, linetablesize
);
964 memcpy (symtab
->linetable
, subfile
->line_vector
, linetablesize
);
968 symtab
->linetable
= NULL
;
970 symtab
->block_line_section
= section
;
971 if (subfile
->dirname
)
973 /* Reallocate the dirname on the symbol obstack */
974 symtab
->dirname
= (char *)
975 obstack_alloc (&objfile
->objfile_obstack
,
976 strlen (subfile
->dirname
) + 1);
977 strcpy (symtab
->dirname
, subfile
->dirname
);
981 symtab
->dirname
= NULL
;
983 symtab
->free_code
= free_linetable
;
984 symtab
->free_func
= NULL
;
986 /* Use whatever language we have been using for this
987 subfile, not the one that was deduced in allocate_symtab
988 from the filename. We already did our own deducing when
989 we created the subfile, and we may have altered our
990 opinion of what language it is from things we found in
992 symtab
->language
= subfile
->language
;
994 /* Save the debug format string (if any) in the symtab */
995 if (subfile
->debugformat
!= NULL
)
997 symtab
->debugformat
= obsavestring (subfile
->debugformat
,
998 strlen (subfile
->debugformat
),
999 &objfile
->objfile_obstack
);
1002 /* All symtabs for the main file and the subfiles share a
1003 blockvector, so we need to clear primary for everything
1004 but the main file. */
1006 symtab
->primary
= 0;
1008 if (subfile
->name
!= NULL
)
1010 xfree ((void *) subfile
->name
);
1012 if (subfile
->dirname
!= NULL
)
1014 xfree ((void *) subfile
->dirname
);
1016 if (subfile
->line_vector
!= NULL
)
1018 xfree ((void *) subfile
->line_vector
);
1020 if (subfile
->debugformat
!= NULL
)
1022 xfree ((void *) subfile
->debugformat
);
1025 nextsub
= subfile
->next
;
1026 xfree ((void *) subfile
);
1029 /* Set this for the main source file. */
1032 symtab
->primary
= 1;
1035 last_source_file
= NULL
;
1036 current_subfile
= NULL
;
1037 pending_macros
= NULL
;
1042 /* Push a context block. Args are an identifying nesting level
1043 (checkable when you pop it), and the starting PC address of this
1046 struct context_stack
*
1047 push_context (int desc
, CORE_ADDR valu
)
1049 struct context_stack
*new;
1051 if (context_stack_depth
== context_stack_size
)
1053 context_stack_size
*= 2;
1054 context_stack
= (struct context_stack
*)
1055 xrealloc ((char *) context_stack
,
1056 (context_stack_size
* sizeof (struct context_stack
)));
1059 new = &context_stack
[context_stack_depth
++];
1061 new->locals
= local_symbols
;
1062 new->params
= param_symbols
;
1063 new->old_blocks
= pending_blocks
;
1064 new->start_addr
= valu
;
1067 local_symbols
= NULL
;
1068 param_symbols
= NULL
;
1073 /* Pop a context block. Returns the address of the context block just
1076 struct context_stack
*
1079 gdb_assert (context_stack_depth
> 0);
1080 return (&context_stack
[--context_stack_depth
]);
1085 /* Compute a small integer hash code for the given name. */
1088 hashname (char *name
)
1090 return (hash(name
,strlen(name
)) % HASHSIZE
);
1095 record_debugformat (char *format
)
1097 current_subfile
->debugformat
= savestring (format
, strlen (format
));
1100 /* Merge the first symbol list SRCLIST into the second symbol list
1101 TARGETLIST by repeated calls to add_symbol_to_list(). This
1102 procedure "frees" each link of SRCLIST by adding it to the
1103 free_pendings list. Caller must set SRCLIST to a null list after
1104 calling this function.
1109 merge_symbol_lists (struct pending
**srclist
, struct pending
**targetlist
)
1113 if (!srclist
|| !*srclist
)
1116 /* Merge in elements from current link. */
1117 for (i
= 0; i
< (*srclist
)->nsyms
; i
++)
1118 add_symbol_to_list ((*srclist
)->symbol
[i
], targetlist
);
1120 /* Recurse on next. */
1121 merge_symbol_lists (&(*srclist
)->next
, targetlist
);
1123 /* "Free" the current link. */
1124 (*srclist
)->next
= free_pendings
;
1125 free_pendings
= (*srclist
);
1128 /* Initialize anything that needs initializing when starting to read a
1129 fresh piece of a symbol file, e.g. reading in the stuff
1130 corresponding to a psymtab. */
1133 buildsym_init (void)
1135 free_pendings
= NULL
;
1136 file_symbols
= NULL
;
1137 global_symbols
= NULL
;
1138 pending_blocks
= NULL
;
1139 pending_macros
= NULL
;
1142 /* Initialize anything that needs initializing when a completely new
1143 symbol file is specified (not just adding some symbols from another
1144 file, e.g. a shared library). */
1147 buildsym_new_init (void)