1 /* Support routines for building symbol tables in GDB's internal format.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
3 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
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., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, 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... */
41 #include "language.h" /* For "local_hex_string" */
43 #include "filenames.h" /* For DOSish file names */
45 #include "demangle.h" /* Needed by SYMBOL_INIT_DEMANGLED_NAME. */
47 /* Ask buildsym.h to define the vars it normally declares `extern'. */
50 #include "buildsym.h" /* Our own declarations */
53 /* For cleanup_undefined_types and finish_global_stabs (somewhat
54 questionable--see comment where we call them). */
56 #include "stabsread.h"
58 /* List of free `struct pending' structures for reuse. */
60 static struct pending *free_pendings;
62 /* Non-zero if symtab has line number info. This prevents an
63 otherwise empty symtab from being tossed. */
65 static int have_line_numbers;
67 static int compare_line_numbers (const void *ln1p, const void *ln2p);
70 /* Initial sizes of data structures. These are realloc'd larger if
71 needed, and realloc'd down to the size actually used, when
74 #define INITIAL_CONTEXT_STACK_SIZE 10
75 #define INITIAL_LINE_VECTOR_LENGTH 1000
78 /* maintain the lists of symbols and blocks */
80 /* Add a pending list to free_pendings. */
82 add_free_pendings (struct pending *list)
84 register struct pending *link = list;
88 while (link->next) link = link->next;
89 link->next = free_pendings;
94 /* Add a symbol to one of the lists of symbols. */
97 add_symbol_to_list (struct symbol *symbol, struct pending **listhead)
99 register struct pending *link;
101 /* If this is an alias for another symbol, don't add it. */
102 if (symbol->ginfo.name && symbol->ginfo.name[0] == '#')
105 /* We keep PENDINGSIZE symbols in each link of the list. If we
106 don't have a link with room in it, add a new link. */
107 if (*listhead == NULL || (*listhead)->nsyms == PENDINGSIZE)
111 link = free_pendings;
112 free_pendings = link->next;
116 link = (struct pending *) xmalloc (sizeof (struct pending));
119 link->next = *listhead;
124 (*listhead)->symbol[(*listhead)->nsyms++] = symbol;
127 /* Find a symbol named NAME on a LIST. NAME need not be
128 '\0'-terminated; LENGTH is the length of the name. */
131 find_symbol_in_list (struct pending *list, char *name, int length)
138 for (j = list->nsyms; --j >= 0;)
140 pp = DEPRECATED_SYMBOL_NAME (list->symbol[j]);
141 if (*pp == *name && strncmp (pp, name, length) == 0 &&
144 return (list->symbol[j]);
152 /* At end of reading syms, or in case of quit, really free as many
153 `struct pending's as we can easily find. */
157 really_free_pendings (void *dummy)
159 struct pending *next, *next1;
161 for (next = free_pendings; next; next = next1)
164 xfree ((void *) next);
166 free_pendings = NULL;
168 free_pending_blocks ();
170 for (next = file_symbols; next != NULL; next = next1)
173 xfree ((void *) next);
177 for (next = global_symbols; next != NULL; next = next1)
180 xfree ((void *) next);
182 global_symbols = NULL;
185 free_macro_table (pending_macros);
188 /* This function is called to discard any pending blocks. */
191 free_pending_blocks (void)
193 #if 0 /* Now we make the links in the
194 symbol_obstack, so don't free
196 struct pending_block *bnext, *bnext1;
198 for (bnext = pending_blocks; bnext; bnext = bnext1)
200 bnext1 = bnext->next;
201 xfree ((void *) bnext);
204 pending_blocks = NULL;
207 /* Take one of the lists of symbols and make a block from it. Keep
208 the order the symbols have in the list (reversed from the input
209 file). Put the block on the list of pending blocks. */
212 finish_block (struct symbol *symbol, struct pending **listhead,
213 struct pending_block *old_blocks,
214 CORE_ADDR start, CORE_ADDR end,
215 struct objfile *objfile)
217 register struct pending *next, *next1;
218 register struct block *block;
219 register struct pending_block *pblock;
220 struct pending_block *opblock;
224 /* Count the length of the list of symbols. */
226 for (next = *listhead, i = 0;
228 i += next->nsyms, next = next->next)
233 /* Copy the symbols into the block. */
237 block = (struct block *)
238 obstack_alloc (&objfile->symbol_obstack,
239 (sizeof (struct block) +
240 ((i - 1) * sizeof (struct symbol *))));
241 BLOCK_NSYMS (block) = i;
242 for (next = *listhead; next; next = next->next)
243 for (j = next->nsyms - 1; j >= 0; j--)
245 BLOCK_SYM (block, --i) = next->symbol[j];
250 int htab_size = BLOCK_HASHTABLE_SIZE (i);
252 block = (struct block *)
253 obstack_alloc (&objfile->symbol_obstack,
254 (sizeof (struct block) +
255 ((htab_size - 1) * sizeof (struct symbol *))));
256 for (j = 0; j < htab_size; j++)
258 BLOCK_BUCKET (block, j) = 0;
260 BLOCK_BUCKETS (block) = htab_size;
261 for (next = *listhead; next; next = next->next)
263 for (j = next->nsyms - 1; j >= 0; j--)
266 unsigned int hash_index;
267 const char *name = SYMBOL_DEMANGLED_NAME (next->symbol[j]);
269 name = DEPRECATED_SYMBOL_NAME (next->symbol[j]);
270 hash_index = msymbol_hash_iw (name);
271 hash_index = hash_index % BLOCK_BUCKETS (block);
272 sym = BLOCK_BUCKET (block, hash_index);
273 BLOCK_BUCKET (block, hash_index) = next->symbol[j];
274 next->symbol[j]->hash_next = sym;
279 BLOCK_START (block) = start;
280 BLOCK_END (block) = end;
281 /* Superblock filled in when containing block is made */
282 BLOCK_SUPERBLOCK (block) = NULL;
284 BLOCK_GCC_COMPILED (block) = processing_gcc_compilation;
286 /* Put the block in as the value of the symbol that names it. */
290 struct type *ftype = SYMBOL_TYPE (symbol);
291 SYMBOL_BLOCK_VALUE (symbol) = block;
292 BLOCK_FUNCTION (block) = symbol;
293 BLOCK_HASHTABLE (block) = 0;
295 if (TYPE_NFIELDS (ftype) <= 0)
297 /* No parameter type information is recorded with the
298 function's type. Set that from the type of the
299 parameter symbols. */
300 int nparams = 0, iparams;
302 ALL_BLOCK_SYMBOLS (block, i, sym)
304 switch (SYMBOL_CLASS (sym))
309 case LOC_REGPARM_ADDR:
310 case LOC_BASEREG_ARG:
312 case LOC_COMPUTED_ARG:
324 case LOC_CONST_BYTES:
327 case LOC_OPTIMIZED_OUT:
335 TYPE_NFIELDS (ftype) = nparams;
336 TYPE_FIELDS (ftype) = (struct field *)
337 TYPE_ALLOC (ftype, nparams * sizeof (struct field));
339 for (i = iparams = 0; iparams < nparams; i++)
341 sym = BLOCK_SYM (block, i);
342 switch (SYMBOL_CLASS (sym))
347 case LOC_REGPARM_ADDR:
348 case LOC_BASEREG_ARG:
350 case LOC_COMPUTED_ARG:
351 TYPE_FIELD_TYPE (ftype, iparams) = SYMBOL_TYPE (sym);
352 TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0;
364 case LOC_CONST_BYTES:
367 case LOC_OPTIMIZED_OUT:
378 BLOCK_FUNCTION (block) = NULL;
379 BLOCK_HASHTABLE (block) = 1;
382 /* Now "free" the links of the list, and empty the list. */
384 for (next = *listhead; next; next = next1)
387 next->next = free_pendings;
388 free_pendings = next;
393 /* Check to be sure that the blocks have an end address that is
394 greater than starting address */
396 if (BLOCK_END (block) < BLOCK_START (block))
400 complaint (&symfile_complaints,
401 "block end address less than block start address in %s (patched it)",
402 SYMBOL_PRINT_NAME (symbol));
406 complaint (&symfile_complaints,
407 "block end address 0x%s less than block start address 0x%s (patched it)",
408 paddr_nz (BLOCK_END (block)), paddr_nz (BLOCK_START (block)));
410 /* Better than nothing */
411 BLOCK_END (block) = BLOCK_START (block);
415 /* Install this block as the superblock of all blocks made since the
416 start of this scope that don't have superblocks yet. */
419 for (pblock = pending_blocks;
420 pblock && pblock != old_blocks;
421 pblock = pblock->next)
423 if (BLOCK_SUPERBLOCK (pblock->block) == NULL)
426 /* Check to be sure the blocks are nested as we receive
427 them. If the compiler/assembler/linker work, this just
428 burns a small amount of time. */
429 if (BLOCK_START (pblock->block) < BLOCK_START (block) ||
430 BLOCK_END (pblock->block) > BLOCK_END (block))
434 complaint (&symfile_complaints,
435 "inner block not inside outer block in %s",
436 SYMBOL_PRINT_NAME (symbol));
440 complaint (&symfile_complaints,
441 "inner block (0x%s-0x%s) not inside outer block (0x%s-0x%s)",
442 paddr_nz (BLOCK_START (pblock->block)),
443 paddr_nz (BLOCK_END (pblock->block)),
444 paddr_nz (BLOCK_START (block)),
445 paddr_nz (BLOCK_END (block)));
447 if (BLOCK_START (pblock->block) < BLOCK_START (block))
448 BLOCK_START (pblock->block) = BLOCK_START (block);
449 if (BLOCK_END (pblock->block) > BLOCK_END (block))
450 BLOCK_END (pblock->block) = BLOCK_END (block);
453 BLOCK_SUPERBLOCK (pblock->block) = block;
458 record_pending_block (objfile, block, opblock);
461 /* Record BLOCK on the list of all blocks in the file. Put it after
462 OPBLOCK, or at the beginning if opblock is NULL. This puts the
463 block in the list after all its subblocks.
465 Allocate the pending block struct in the symbol_obstack to save
466 time. This wastes a little space. FIXME: Is it worth it? */
469 record_pending_block (struct objfile *objfile, struct block *block,
470 struct pending_block *opblock)
472 register struct pending_block *pblock;
474 pblock = (struct pending_block *)
475 obstack_alloc (&objfile->symbol_obstack, sizeof (struct pending_block));
476 pblock->block = block;
479 pblock->next = opblock->next;
480 opblock->next = pblock;
484 pblock->next = pending_blocks;
485 pending_blocks = pblock;
489 static struct blockvector *
490 make_blockvector (struct objfile *objfile)
492 register struct pending_block *next;
493 register struct blockvector *blockvector;
496 /* Count the length of the list of blocks. */
498 for (next = pending_blocks, i = 0; next; next = next->next, i++)
502 blockvector = (struct blockvector *)
503 obstack_alloc (&objfile->symbol_obstack,
504 (sizeof (struct blockvector)
505 + (i - 1) * sizeof (struct block *)));
507 /* Copy the blocks into the blockvector. This is done in reverse
508 order, which happens to put the blocks into the proper order
509 (ascending starting address). finish_block has hair to insert
510 each block into the list after its subblocks in order to make
511 sure this is true. */
513 BLOCKVECTOR_NBLOCKS (blockvector) = i;
514 for (next = pending_blocks; next; next = next->next)
516 BLOCKVECTOR_BLOCK (blockvector, --i) = next->block;
519 #if 0 /* Now we make the links in the
520 obstack, so don't free them. */
521 /* Now free the links of the list, and empty the list. */
523 for (next = pending_blocks; next; next = next1)
529 pending_blocks = NULL;
531 #if 1 /* FIXME, shut this off after a while
532 to speed up symbol reading. */
533 /* Some compilers output blocks in the wrong order, but we depend on
534 their being in the right order so we can binary search. Check the
535 order and moan about it. FIXME. */
536 if (BLOCKVECTOR_NBLOCKS (blockvector) > 1)
538 for (i = 1; i < BLOCKVECTOR_NBLOCKS (blockvector); i++)
540 if (BLOCK_START (BLOCKVECTOR_BLOCK (blockvector, i - 1))
541 > BLOCK_START (BLOCKVECTOR_BLOCK (blockvector, i)))
544 = BLOCK_START (BLOCKVECTOR_BLOCK (blockvector, i));
546 complaint (&symfile_complaints, "block at %s out of order",
547 local_hex_string ((LONGEST) start));
553 return (blockvector);
556 /* Start recording information about source code that came from an
557 included (or otherwise merged-in) source file with a different
558 name. NAME is the name of the file (cannot be NULL), DIRNAME is
559 the directory in which it resides (or NULL if not known). */
562 start_subfile (char *name, char *dirname)
564 register struct subfile *subfile;
566 /* See if this subfile is already known as a subfile of the current
569 for (subfile = subfiles; subfile; subfile = subfile->next)
571 if (FILENAME_CMP (subfile->name, name) == 0)
573 current_subfile = subfile;
578 /* This subfile is not known. Add an entry for it. Make an entry
579 for this subfile in the list of all subfiles of the current main
582 subfile = (struct subfile *) xmalloc (sizeof (struct subfile));
583 memset ((char *) subfile, 0, sizeof (struct subfile));
584 subfile->next = subfiles;
586 current_subfile = subfile;
588 /* Save its name and compilation directory name */
589 subfile->name = (name == NULL) ? NULL : savestring (name, strlen (name));
591 (dirname == NULL) ? NULL : savestring (dirname, strlen (dirname));
593 /* Initialize line-number recording for this subfile. */
594 subfile->line_vector = NULL;
596 /* Default the source language to whatever can be deduced from the
597 filename. If nothing can be deduced (such as for a C/C++ include
598 file with a ".h" extension), then inherit whatever language the
599 previous subfile had. This kludgery is necessary because there
600 is no standard way in some object formats to record the source
601 language. Also, when symtabs are allocated we try to deduce a
602 language then as well, but it is too late for us to use that
603 information while reading symbols, since symtabs aren't allocated
604 until after all the symbols have been processed for a given
607 subfile->language = deduce_language_from_filename (subfile->name);
608 if (subfile->language == language_unknown &&
609 subfile->next != NULL)
611 subfile->language = subfile->next->language;
614 /* Initialize the debug format string to NULL. We may supply it
615 later via a call to record_debugformat. */
616 subfile->debugformat = NULL;
618 #if 0 /* OBSOLETE CFront */
619 // OBSOLETE /* cfront output is a C program, so in most ways it looks like a C
620 // OBSOLETE program. But to demangle we need to set the language to C++. We
621 // OBSOLETE can distinguish cfront code by the fact that it has #line
622 // OBSOLETE directives which specify a file name ending in .C. */
623 #endif /* OBSOLETE CFront */
625 /* If the filename of this subfile ends in .C, then change the
626 language of any pending subfiles from C to C++. We also accept
627 any other C++ suffixes accepted by deduce_language_from_filename. */
628 /* OBSOLETE (in particular, some people use .cxx with cfront). */
629 /* Likewise for f2c. */
634 enum language sublang = deduce_language_from_filename (subfile->name);
636 if (sublang == language_cplus || sublang == language_fortran)
637 for (s = subfiles; s != NULL; s = s->next)
638 if (s->language == language_c)
639 s->language = sublang;
642 /* And patch up this file if necessary. */
643 if (subfile->language == language_c
644 && subfile->next != NULL
645 && (subfile->next->language == language_cplus
646 || subfile->next->language == language_fortran))
648 subfile->language = subfile->next->language;
652 /* For stabs readers, the first N_SO symbol is assumed to be the
653 source file name, and the subfile struct is initialized using that
654 assumption. If another N_SO symbol is later seen, immediately
655 following the first one, then the first one is assumed to be the
656 directory name and the second one is really the source file name.
658 So we have to patch up the subfile struct by moving the old name
659 value to dirname and remembering the new name. Some sanity
660 checking is performed to ensure that the state of the subfile
661 struct is reasonable and that the old name we are assuming to be a
662 directory name actually is (by checking for a trailing '/'). */
665 patch_subfile_names (struct subfile *subfile, char *name)
667 if (subfile != NULL && subfile->dirname == NULL && subfile->name != NULL
668 && subfile->name[strlen (subfile->name) - 1] == '/')
670 subfile->dirname = subfile->name;
671 subfile->name = savestring (name, strlen (name));
672 last_source_file = name;
674 /* Default the source language to whatever can be deduced from
675 the filename. If nothing can be deduced (such as for a C/C++
676 include file with a ".h" extension), then inherit whatever
677 language the previous subfile had. This kludgery is
678 necessary because there is no standard way in some object
679 formats to record the source language. Also, when symtabs
680 are allocated we try to deduce a language then as well, but
681 it is too late for us to use that information while reading
682 symbols, since symtabs aren't allocated until after all the
683 symbols have been processed for a given source file. */
685 subfile->language = deduce_language_from_filename (subfile->name);
686 if (subfile->language == language_unknown &&
687 subfile->next != NULL)
689 subfile->language = subfile->next->language;
694 /* Handle the N_BINCL and N_EINCL symbol types that act like N_SOL for
695 switching source files (different subfiles, as we call them) within
696 one object file, but using a stack rather than in an arbitrary
702 register struct subfile_stack *tem
703 = (struct subfile_stack *) xmalloc (sizeof (struct subfile_stack));
705 tem->next = subfile_stack;
707 if (current_subfile == NULL || current_subfile->name == NULL)
709 internal_error (__FILE__, __LINE__, "failed internal consistency check");
711 tem->name = current_subfile->name;
718 register struct subfile_stack *link = subfile_stack;
722 internal_error (__FILE__, __LINE__, "failed internal consistency check");
725 subfile_stack = link->next;
726 xfree ((void *) link);
730 /* Add a linetable entry for line number LINE and address PC to the
731 line vector for SUBFILE. */
734 record_line (register struct subfile *subfile, int line, CORE_ADDR pc)
736 struct linetable_entry *e;
737 /* Ignore the dummy line number in libg.o */
744 /* Make sure line vector exists and is big enough. */
745 if (!subfile->line_vector)
747 subfile->line_vector_length = INITIAL_LINE_VECTOR_LENGTH;
748 subfile->line_vector = (struct linetable *)
749 xmalloc (sizeof (struct linetable)
750 + subfile->line_vector_length * sizeof (struct linetable_entry));
751 subfile->line_vector->nitems = 0;
752 have_line_numbers = 1;
755 if (subfile->line_vector->nitems + 1 >= subfile->line_vector_length)
757 subfile->line_vector_length *= 2;
758 subfile->line_vector = (struct linetable *)
759 xrealloc ((char *) subfile->line_vector,
760 (sizeof (struct linetable)
761 + (subfile->line_vector_length
762 * sizeof (struct linetable_entry))));
765 e = subfile->line_vector->item + subfile->line_vector->nitems++;
767 e->pc = ADDR_BITS_REMOVE(pc);
770 /* Needed in order to sort line tables from IBM xcoff files. Sigh! */
773 compare_line_numbers (const void *ln1p, const void *ln2p)
775 struct linetable_entry *ln1 = (struct linetable_entry *) ln1p;
776 struct linetable_entry *ln2 = (struct linetable_entry *) ln2p;
778 /* Note: this code does not assume that CORE_ADDRs can fit in ints.
779 Please keep it that way. */
780 if (ln1->pc < ln2->pc)
783 if (ln1->pc > ln2->pc)
786 /* If pc equal, sort by line. I'm not sure whether this is optimum
787 behavior (see comment at struct linetable in symtab.h). */
788 return ln1->line - ln2->line;
791 /* Start a new symtab for a new source file. Called, for example,
792 when a stabs symbol of type N_SO is seen, or when a DWARF
793 TAG_compile_unit DIE is seen. It indicates the start of data for
794 one original source file. */
797 start_symtab (char *name, char *dirname, CORE_ADDR start_addr)
800 last_source_file = name;
801 last_source_start_addr = start_addr;
803 global_symbols = NULL;
805 have_line_numbers = 0;
807 /* Context stack is initially empty. Allocate first one with room
808 for 10 levels; reuse it forever afterward. */
809 if (context_stack == NULL)
811 context_stack_size = INITIAL_CONTEXT_STACK_SIZE;
812 context_stack = (struct context_stack *)
813 xmalloc (context_stack_size * sizeof (struct context_stack));
815 context_stack_depth = 0;
817 /* Initialize the list of sub source files with one entry for this
818 file (the top-level source file). */
821 current_subfile = NULL;
822 start_subfile (name, dirname);
825 /* Finish the symbol definitions for one main source file, close off
826 all the lexical contexts for that file (creating struct block's for
827 them), then make the struct symtab for that file and put it in the
830 END_ADDR is the address of the end of the file's text. SECTION is
831 the section number (in objfile->section_offsets) of the blockvector
834 Note that it is possible for end_symtab() to return NULL. In
835 particular, for the DWARF case at least, it will return NULL when
836 it finds a compilation unit that has exactly one DIE, a
837 TAG_compile_unit DIE. This can happen when we link in an object
838 file that was compiled from an empty source file. Returning NULL
839 is probably not the correct thing to do, because then gdb will
840 never know about this empty file (FIXME). */
843 end_symtab (CORE_ADDR end_addr, struct objfile *objfile, int section)
845 register struct symtab *symtab = NULL;
846 register struct blockvector *blockvector;
847 register struct subfile *subfile;
848 register struct context_stack *cstk;
849 struct subfile *nextsub;
851 /* Finish the lexical context of the last function in the file; pop
852 the context stack. */
854 if (context_stack_depth > 0)
856 cstk = pop_context ();
857 /* Make a block for the local symbols within. */
858 finish_block (cstk->name, &local_symbols, cstk->old_blocks,
859 cstk->start_addr, end_addr, objfile);
861 if (context_stack_depth > 0)
863 /* This is said to happen with SCO. The old coffread.c
864 code simply emptied the context stack, so we do the
865 same. FIXME: Find out why it is happening. This is not
866 believed to happen in most cases (even for coffread.c);
867 it used to be an abort(). */
868 complaint (&symfile_complaints,
869 "Context stack not empty in end_symtab");
870 context_stack_depth = 0;
874 /* Reordered executables may have out of order pending blocks; if
875 OBJF_REORDERED is true, then sort the pending blocks. */
876 if ((objfile->flags & OBJF_REORDERED) && pending_blocks)
878 /* FIXME! Remove this horrid bubble sort and use merge sort!!! */
882 struct pending_block *pb, *pbnext;
890 /* swap blocks if unordered! */
892 if (BLOCK_START (pb->block) < BLOCK_START (pbnext->block))
894 struct block *tmp = pb->block;
895 pb->block = pbnext->block;
900 pbnext = pbnext->next;
906 /* Cleanup any undefined types that have been left hanging around
907 (this needs to be done before the finish_blocks so that
908 file_symbols is still good).
910 Both cleanup_undefined_types and finish_global_stabs are stabs
911 specific, but harmless for other symbol readers, since on gdb
912 startup or when finished reading stabs, the state is set so these
913 are no-ops. FIXME: Is this handled right in case of QUIT? Can
914 we make this cleaner? */
916 cleanup_undefined_types ();
917 finish_global_stabs (objfile);
919 if (pending_blocks == NULL
920 && file_symbols == NULL
921 && global_symbols == NULL
922 && have_line_numbers == 0
923 && pending_macros == NULL)
925 /* Ignore symtabs that have no functions with real debugging
931 /* Define the STATIC_BLOCK & GLOBAL_BLOCK, and build the
933 finish_block (0, &file_symbols, 0, last_source_start_addr, end_addr,
935 finish_block (0, &global_symbols, 0, last_source_start_addr, end_addr,
937 blockvector = make_blockvector (objfile);
940 #ifndef PROCESS_LINENUMBER_HOOK
941 #define PROCESS_LINENUMBER_HOOK()
943 PROCESS_LINENUMBER_HOOK (); /* Needed for xcoff. */
945 /* Now create the symtab objects proper, one for each subfile. */
946 /* (The main file is the last one on the chain.) */
948 for (subfile = subfiles; subfile; subfile = nextsub)
950 int linetablesize = 0;
953 /* If we have blocks of symbols, make a symtab. Otherwise, just
954 ignore this file and any line number info in it. */
957 if (subfile->line_vector)
959 linetablesize = sizeof (struct linetable) +
960 subfile->line_vector->nitems * sizeof (struct linetable_entry);
962 /* I think this is artifact from before it went on the
963 obstack. I doubt we'll need the memory between now
964 and when we free it later in this function. */
965 /* First, shrink the linetable to make more memory. */
966 subfile->line_vector = (struct linetable *)
967 xrealloc ((char *) subfile->line_vector, linetablesize);
970 /* Like the pending blocks, the line table may be
971 scrambled in reordered executables. Sort it if
972 OBJF_REORDERED is true. */
973 if (objfile->flags & OBJF_REORDERED)
974 qsort (subfile->line_vector->item,
975 subfile->line_vector->nitems,
976 sizeof (struct linetable_entry), compare_line_numbers);
979 /* Now, allocate a symbol table. */
980 symtab = allocate_symtab (subfile->name, objfile);
982 /* Fill in its components. */
983 symtab->blockvector = blockvector;
984 symtab->macro_table = pending_macros;
985 if (subfile->line_vector)
987 /* Reallocate the line table on the symbol obstack */
988 symtab->linetable = (struct linetable *)
989 obstack_alloc (&objfile->symbol_obstack, linetablesize);
990 memcpy (symtab->linetable, subfile->line_vector, linetablesize);
994 symtab->linetable = NULL;
996 symtab->block_line_section = section;
997 if (subfile->dirname)
999 /* Reallocate the dirname on the symbol obstack */
1000 symtab->dirname = (char *)
1001 obstack_alloc (&objfile->symbol_obstack,
1002 strlen (subfile->dirname) + 1);
1003 strcpy (symtab->dirname, subfile->dirname);
1007 symtab->dirname = NULL;
1009 symtab->free_code = free_linetable;
1010 symtab->free_ptr = NULL;
1012 /* Use whatever language we have been using for this
1013 subfile, not the one that was deduced in allocate_symtab
1014 from the filename. We already did our own deducing when
1015 we created the subfile, and we may have altered our
1016 opinion of what language it is from things we found in
1018 symtab->language = subfile->language;
1020 /* Save the debug format string (if any) in the symtab */
1021 if (subfile->debugformat != NULL)
1023 symtab->debugformat = obsavestring (subfile->debugformat,
1024 strlen (subfile->debugformat),
1025 &objfile->symbol_obstack);
1028 /* All symtabs for the main file and the subfiles share a
1029 blockvector, so we need to clear primary for everything
1030 but the main file. */
1032 symtab->primary = 0;
1034 if (subfile->name != NULL)
1036 xfree ((void *) subfile->name);
1038 if (subfile->dirname != NULL)
1040 xfree ((void *) subfile->dirname);
1042 if (subfile->line_vector != NULL)
1044 xfree ((void *) subfile->line_vector);
1046 if (subfile->debugformat != NULL)
1048 xfree ((void *) subfile->debugformat);
1051 nextsub = subfile->next;
1052 xfree ((void *) subfile);
1055 /* Set this for the main source file. */
1058 symtab->primary = 1;
1061 last_source_file = NULL;
1062 current_subfile = NULL;
1063 pending_macros = NULL;
1068 /* Push a context block. Args are an identifying nesting level
1069 (checkable when you pop it), and the starting PC address of this
1072 struct context_stack *
1073 push_context (int desc, CORE_ADDR valu)
1075 register struct context_stack *new;
1077 if (context_stack_depth == context_stack_size)
1079 context_stack_size *= 2;
1080 context_stack = (struct context_stack *)
1081 xrealloc ((char *) context_stack,
1082 (context_stack_size * sizeof (struct context_stack)));
1085 new = &context_stack[context_stack_depth++];
1087 new->locals = local_symbols;
1088 new->params = param_symbols;
1089 new->old_blocks = pending_blocks;
1090 new->start_addr = valu;
1093 local_symbols = NULL;
1094 param_symbols = NULL;
1099 /* Pop a context block. Returns the address of the context block just
1102 struct context_stack *
1105 gdb_assert (context_stack_depth > 0);
1106 return (&context_stack[--context_stack_depth]);
1111 /* Compute a small integer hash code for the given name. */
1114 hashname (char *name)
1116 return (hash(name,strlen(name)) % HASHSIZE);
1121 record_debugformat (char *format)
1123 current_subfile->debugformat = savestring (format, strlen (format));
1126 /* Merge the first symbol list SRCLIST into the second symbol list
1127 TARGETLIST by repeated calls to add_symbol_to_list(). This
1128 procedure "frees" each link of SRCLIST by adding it to the
1129 free_pendings list. Caller must set SRCLIST to a null list after
1130 calling this function.
1135 merge_symbol_lists (struct pending **srclist, struct pending **targetlist)
1139 if (!srclist || !*srclist)
1142 /* Merge in elements from current link. */
1143 for (i = 0; i < (*srclist)->nsyms; i++)
1144 add_symbol_to_list ((*srclist)->symbol[i], targetlist);
1146 /* Recurse on next. */
1147 merge_symbol_lists (&(*srclist)->next, targetlist);
1149 /* "Free" the current link. */
1150 (*srclist)->next = free_pendings;
1151 free_pendings = (*srclist);
1154 /* Initialize anything that needs initializing when starting to read a
1155 fresh piece of a symbol file, e.g. reading in the stuff
1156 corresponding to a psymtab. */
1159 buildsym_init (void)
1161 free_pendings = NULL;
1162 file_symbols = NULL;
1163 global_symbols = NULL;
1164 pending_blocks = NULL;
1165 pending_macros = NULL;
1168 /* Initialize anything that needs initializing when a completely new
1169 symbol file is specified (not just adding some symbols from another
1170 file, e.g. a shared library). */
1173 buildsym_new_init (void)