1 /* Support routines for building symbol tables in GDB's internal format.
2 Copyright 1986-2000 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 2 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, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 /* This module provides subroutines used for creating and adding to
22 the symbol table. These routines are called from various symbol-
23 file-reading routines.
25 Routines to support specific debugging information formats (stabs,
26 DWARF, etc) belong somewhere else. */
32 #include "symfile.h" /* Needed for "struct complaint" */
35 #include "complaints.h"
36 #include "gdb_string.h"
37 #include "expression.h" /* For "enum exp_opcode" used by... */
38 #include "language.h" /* For "longest_local_hex_string_custom" */
40 /* Ask buildsym.h to define the vars it normally declares `extern'. */
43 #include "buildsym.h" /* Our own declarations */
46 /* For cleanup_undefined_types and finish_global_stabs (somewhat
47 questionable--see comment where we call them). */
49 #include "stabsread.h"
51 /* List of free `struct pending' structures for reuse. */
53 static struct pending *free_pendings;
55 /* Non-zero if symtab has line number info. This prevents an
56 otherwise empty symtab from being tossed. */
58 static int have_line_numbers;
60 static int compare_line_numbers (const void *ln1p, const void *ln2p);
63 /* Initial sizes of data structures. These are realloc'd larger if
64 needed, and realloc'd down to the size actually used, when
67 #define INITIAL_CONTEXT_STACK_SIZE 10
68 #define INITIAL_LINE_VECTOR_LENGTH 1000
71 /* Complaints about the symbols we have encountered. */
73 struct complaint block_end_complaint =
74 {"block end address less than block start address in %s (patched it)", 0, 0};
76 struct complaint anon_block_end_complaint =
77 {"block end address 0x%lx less than block start address 0x%lx (patched it)", 0, 0};
79 struct complaint innerblock_complaint =
80 {"inner block not inside outer block in %s", 0, 0};
82 struct complaint innerblock_anon_complaint =
83 {"inner block (0x%lx-0x%lx) not inside outer block (0x%lx-0x%lx)", 0, 0};
85 struct complaint blockvector_complaint =
86 {"block at %s out of order", 0, 0};
88 /* maintain the lists of symbols and blocks */
90 /* Add a pending list to free_pendings. */
92 add_free_pendings (struct pending *list)
94 register struct pending *link = list;
98 while (link->next) link = link->next;
99 link->next = free_pendings;
100 free_pendings = list;
104 /* Add a symbol to one of the lists of symbols. */
107 add_symbol_to_list (struct symbol *symbol, struct pending **listhead)
109 register struct pending *link;
111 /* If this is an alias for another symbol, don't add it. */
112 if (symbol->ginfo.name && symbol->ginfo.name[0] == '#')
115 /* We keep PENDINGSIZE symbols in each link of the list. If we
116 don't have a link with room in it, add a new link. */
117 if (*listhead == NULL || (*listhead)->nsyms == PENDINGSIZE)
121 link = free_pendings;
122 free_pendings = link->next;
126 link = (struct pending *) xmalloc (sizeof (struct pending));
129 link->next = *listhead;
134 (*listhead)->symbol[(*listhead)->nsyms++] = symbol;
137 /* Find a symbol named NAME on a LIST. NAME need not be
138 '\0'-terminated; LENGTH is the length of the name. */
141 find_symbol_in_list (struct pending *list, char *name, int length)
148 for (j = list->nsyms; --j >= 0;)
150 pp = SYMBOL_NAME (list->symbol[j]);
151 if (*pp == *name && strncmp (pp, name, length) == 0 &&
154 return (list->symbol[j]);
162 /* At end of reading syms, or in case of quit, really free as many
163 `struct pending's as we can easily find. */
167 really_free_pendings (PTR dummy)
169 struct pending *next, *next1;
171 for (next = free_pendings; next; next = next1)
174 free ((void *) next);
176 free_pendings = NULL;
178 free_pending_blocks ();
180 for (next = file_symbols; next != NULL; next = next1)
183 free ((void *) next);
187 for (next = global_symbols; next != NULL; next = next1)
190 free ((void *) next);
192 global_symbols = NULL;
195 /* This function is called to discard any pending blocks. */
198 free_pending_blocks (void)
200 #if 0 /* Now we make the links in the
201 symbol_obstack, so don't free
203 struct pending_block *bnext, *bnext1;
205 for (bnext = pending_blocks; bnext; bnext = bnext1)
207 bnext1 = bnext->next;
208 free ((void *) bnext);
211 pending_blocks = NULL;
214 /* Take one of the lists of symbols and make a block from it. Keep
215 the order the symbols have in the list (reversed from the input
216 file). Put the block on the list of pending blocks. */
219 finish_block (struct symbol *symbol, struct pending **listhead,
220 struct pending_block *old_blocks,
221 CORE_ADDR start, CORE_ADDR end,
222 struct objfile *objfile)
224 register struct pending *next, *next1;
225 register struct block *block;
226 register struct pending_block *pblock;
227 struct pending_block *opblock;
231 /* Count the length of the list of symbols. */
233 for (next = *listhead, i = 0;
235 i += next->nsyms, next = next->next)
240 block = (struct block *) obstack_alloc (&objfile->symbol_obstack,
241 (sizeof (struct block) + ((i - 1) * sizeof (struct symbol *))));
243 /* Copy the symbols into the block. */
245 BLOCK_NSYMS (block) = i;
246 for (next = *listhead; next; next = next->next)
248 for (j = next->nsyms - 1; j >= 0; j--)
250 BLOCK_SYM (block, --i) = next->symbol[j];
254 BLOCK_START (block) = start;
255 BLOCK_END (block) = end;
256 /* Superblock filled in when containing block is made */
257 BLOCK_SUPERBLOCK (block) = NULL;
259 BLOCK_GCC_COMPILED (block) = processing_gcc_compilation;
261 /* Put the block in as the value of the symbol that names it. */
265 struct type *ftype = SYMBOL_TYPE (symbol);
266 SYMBOL_BLOCK_VALUE (symbol) = block;
267 BLOCK_FUNCTION (block) = symbol;
269 if (TYPE_NFIELDS (ftype) <= 0)
271 /* No parameter type information is recorded with the
272 function's type. Set that from the type of the
273 parameter symbols. */
274 int nparams = 0, iparams;
276 for (i = 0; i < BLOCK_NSYMS (block); i++)
278 sym = BLOCK_SYM (block, i);
279 switch (SYMBOL_CLASS (sym))
284 case LOC_REGPARM_ADDR:
285 case LOC_BASEREG_ARG:
298 case LOC_CONST_BYTES:
301 case LOC_OPTIMIZED_OUT:
308 TYPE_NFIELDS (ftype) = nparams;
309 TYPE_FIELDS (ftype) = (struct field *)
310 TYPE_ALLOC (ftype, nparams * sizeof (struct field));
312 for (i = iparams = 0; iparams < nparams; i++)
314 sym = BLOCK_SYM (block, i);
315 switch (SYMBOL_CLASS (sym))
320 case LOC_REGPARM_ADDR:
321 case LOC_BASEREG_ARG:
323 TYPE_FIELD_TYPE (ftype, iparams) = SYMBOL_TYPE (sym);
335 case LOC_CONST_BYTES:
338 case LOC_OPTIMIZED_OUT:
348 BLOCK_FUNCTION (block) = NULL;
351 /* Now "free" the links of the list, and empty the list. */
353 for (next = *listhead; next; next = next1)
356 next->next = free_pendings;
357 free_pendings = next;
362 /* Check to be sure that the blocks have an end address that is
363 greater than starting address */
365 if (BLOCK_END (block) < BLOCK_START (block))
369 complain (&block_end_complaint, SYMBOL_SOURCE_NAME (symbol));
373 complain (&anon_block_end_complaint, BLOCK_END (block), BLOCK_START (block));
375 /* Better than nothing */
376 BLOCK_END (block) = BLOCK_START (block);
380 /* Install this block as the superblock of all blocks made since the
381 start of this scope that don't have superblocks yet. */
384 for (pblock = pending_blocks; pblock != old_blocks; pblock = pblock->next)
386 if (BLOCK_SUPERBLOCK (pblock->block) == NULL)
389 /* Check to be sure the blocks are nested as we receive
390 them. If the compiler/assembler/linker work, this just
391 burns a small amount of time. */
392 if (BLOCK_START (pblock->block) < BLOCK_START (block) ||
393 BLOCK_END (pblock->block) > BLOCK_END (block))
397 complain (&innerblock_complaint,
398 SYMBOL_SOURCE_NAME (symbol));
402 complain (&innerblock_anon_complaint, BLOCK_START (pblock->block),
403 BLOCK_END (pblock->block), BLOCK_START (block),
406 if (BLOCK_START (pblock->block) < BLOCK_START (block))
407 BLOCK_START (pblock->block) = BLOCK_START (block);
408 if (BLOCK_END (pblock->block) > BLOCK_END (block))
409 BLOCK_END (pblock->block) = BLOCK_END (block);
412 BLOCK_SUPERBLOCK (pblock->block) = block;
417 record_pending_block (objfile, block, opblock);
420 /* Record BLOCK on the list of all blocks in the file. Put it after
421 OPBLOCK, or at the beginning if opblock is NULL. This puts the
422 block in the list after all its subblocks.
424 Allocate the pending block struct in the symbol_obstack to save
425 time. This wastes a little space. FIXME: Is it worth it? */
428 record_pending_block (struct objfile *objfile, struct block *block,
429 struct pending_block *opblock)
431 register struct pending_block *pblock;
433 pblock = (struct pending_block *)
434 obstack_alloc (&objfile->symbol_obstack, sizeof (struct pending_block));
435 pblock->block = block;
438 pblock->next = opblock->next;
439 opblock->next = pblock;
443 pblock->next = pending_blocks;
444 pending_blocks = pblock;
448 /* Note that this is only used in this file and in dstread.c, which
449 should be fixed to not need direct access to this function. When
450 that is done, it can be made static again. */
453 make_blockvector (struct objfile *objfile)
455 register struct pending_block *next;
456 register struct blockvector *blockvector;
459 /* Count the length of the list of blocks. */
461 for (next = pending_blocks, i = 0; next; next = next->next, i++)
465 blockvector = (struct blockvector *)
466 obstack_alloc (&objfile->symbol_obstack,
467 (sizeof (struct blockvector)
468 + (i - 1) * sizeof (struct block *)));
470 /* Copy the blocks into the blockvector. This is done in reverse
471 order, which happens to put the blocks into the proper order
472 (ascending starting address). finish_block has hair to insert
473 each block into the list after its subblocks in order to make
474 sure this is true. */
476 BLOCKVECTOR_NBLOCKS (blockvector) = i;
477 for (next = pending_blocks; next; next = next->next)
479 BLOCKVECTOR_BLOCK (blockvector, --i) = next->block;
482 #if 0 /* Now we make the links in the
483 obstack, so don't free them. */
484 /* Now free the links of the list, and empty the list. */
486 for (next = pending_blocks; next; next = next1)
492 pending_blocks = NULL;
494 #if 1 /* FIXME, shut this off after a while
495 to speed up symbol reading. */
496 /* Some compilers output blocks in the wrong order, but we depend on
497 their being in the right order so we can binary search. Check the
498 order and moan about it. FIXME. */
499 if (BLOCKVECTOR_NBLOCKS (blockvector) > 1)
501 for (i = 1; i < BLOCKVECTOR_NBLOCKS (blockvector); i++)
503 if (BLOCK_START (BLOCKVECTOR_BLOCK (blockvector, i - 1))
504 > BLOCK_START (BLOCKVECTOR_BLOCK (blockvector, i)))
507 = BLOCK_START (BLOCKVECTOR_BLOCK (blockvector, i));
509 complain (&blockvector_complaint,
510 longest_local_hex_string ((LONGEST) start));
516 return (blockvector);
519 /* Start recording information about source code that came from an
520 included (or otherwise merged-in) source file with a different
521 name. NAME is the name of the file (cannot be NULL), DIRNAME is
522 the directory in which it resides (or NULL if not known). */
525 start_subfile (char *name, char *dirname)
527 register struct subfile *subfile;
529 /* See if this subfile is already known as a subfile of the current
532 for (subfile = subfiles; subfile; subfile = subfile->next)
534 if (STREQ (subfile->name, name))
536 current_subfile = subfile;
541 /* This subfile is not known. Add an entry for it. Make an entry
542 for this subfile in the list of all subfiles of the current main
545 subfile = (struct subfile *) xmalloc (sizeof (struct subfile));
546 memset ((char *) subfile, 0, sizeof (struct subfile));
547 subfile->next = subfiles;
549 current_subfile = subfile;
551 /* Save its name and compilation directory name */
552 subfile->name = (name == NULL) ? NULL : savestring (name, strlen (name));
554 (dirname == NULL) ? NULL : savestring (dirname, strlen (dirname));
556 /* Initialize line-number recording for this subfile. */
557 subfile->line_vector = NULL;
559 /* Default the source language to whatever can be deduced from the
560 filename. If nothing can be deduced (such as for a C/C++ include
561 file with a ".h" extension), then inherit whatever language the
562 previous subfile had. This kludgery is necessary because there
563 is no standard way in some object formats to record the source
564 language. Also, when symtabs are allocated we try to deduce a
565 language then as well, but it is too late for us to use that
566 information while reading symbols, since symtabs aren't allocated
567 until after all the symbols have been processed for a given
570 subfile->language = deduce_language_from_filename (subfile->name);
571 if (subfile->language == language_unknown &&
572 subfile->next != NULL)
574 subfile->language = subfile->next->language;
577 /* Initialize the debug format string to NULL. We may supply it
578 later via a call to record_debugformat. */
579 subfile->debugformat = NULL;
581 /* cfront output is a C program, so in most ways it looks like a C
582 program. But to demangle we need to set the language to C++. We
583 can distinguish cfront code by the fact that it has #line
584 directives which specify a file name ending in .C.
586 So if the filename of this subfile ends in .C, then change the
587 language of any pending subfiles from C to C++. We also accept
588 any other C++ suffixes accepted by deduce_language_from_filename
589 (in particular, some people use .cxx with cfront). */
590 /* Likewise for f2c. */
595 enum language sublang = deduce_language_from_filename (subfile->name);
597 if (sublang == language_cplus || sublang == language_fortran)
598 for (s = subfiles; s != NULL; s = s->next)
599 if (s->language == language_c)
600 s->language = sublang;
603 /* And patch up this file if necessary. */
604 if (subfile->language == language_c
605 && subfile->next != NULL
606 && (subfile->next->language == language_cplus
607 || subfile->next->language == language_fortran))
609 subfile->language = subfile->next->language;
613 /* For stabs readers, the first N_SO symbol is assumed to be the
614 source file name, and the subfile struct is initialized using that
615 assumption. If another N_SO symbol is later seen, immediately
616 following the first one, then the first one is assumed to be the
617 directory name and the second one is really the source file name.
619 So we have to patch up the subfile struct by moving the old name
620 value to dirname and remembering the new name. Some sanity
621 checking is performed to ensure that the state of the subfile
622 struct is reasonable and that the old name we are assuming to be a
623 directory name actually is (by checking for a trailing '/'). */
626 patch_subfile_names (struct subfile *subfile, char *name)
628 if (subfile != NULL && subfile->dirname == NULL && subfile->name != NULL
629 && subfile->name[strlen (subfile->name) - 1] == '/')
631 subfile->dirname = subfile->name;
632 subfile->name = savestring (name, strlen (name));
633 last_source_file = name;
635 /* Default the source language to whatever can be deduced from
636 the filename. If nothing can be deduced (such as for a C/C++
637 include file with a ".h" extension), then inherit whatever
638 language the previous subfile had. This kludgery is
639 necessary because there is no standard way in some object
640 formats to record the source language. Also, when symtabs
641 are allocated we try to deduce a language then as well, but
642 it is too late for us to use that information while reading
643 symbols, since symtabs aren't allocated until after all the
644 symbols have been processed for a given source file. */
646 subfile->language = deduce_language_from_filename (subfile->name);
647 if (subfile->language == language_unknown &&
648 subfile->next != NULL)
650 subfile->language = subfile->next->language;
655 /* Handle the N_BINCL and N_EINCL symbol types that act like N_SOL for
656 switching source files (different subfiles, as we call them) within
657 one object file, but using a stack rather than in an arbitrary
663 register struct subfile_stack *tem
664 = (struct subfile_stack *) xmalloc (sizeof (struct subfile_stack));
666 tem->next = subfile_stack;
668 if (current_subfile == NULL || current_subfile->name == NULL)
672 tem->name = current_subfile->name;
679 register struct subfile_stack *link = subfile_stack;
686 subfile_stack = link->next;
687 free ((void *) link);
691 /* Add a linetable entry for line number LINE and address PC to the
692 line vector for SUBFILE. */
695 record_line (register struct subfile *subfile, int line, CORE_ADDR pc)
697 struct linetable_entry *e;
698 /* Ignore the dummy line number in libg.o */
705 /* Make sure line vector exists and is big enough. */
706 if (!subfile->line_vector)
708 subfile->line_vector_length = INITIAL_LINE_VECTOR_LENGTH;
709 subfile->line_vector = (struct linetable *)
710 xmalloc (sizeof (struct linetable)
711 + subfile->line_vector_length * sizeof (struct linetable_entry));
712 subfile->line_vector->nitems = 0;
713 have_line_numbers = 1;
716 if (subfile->line_vector->nitems + 1 >= subfile->line_vector_length)
718 subfile->line_vector_length *= 2;
719 subfile->line_vector = (struct linetable *)
720 xrealloc ((char *) subfile->line_vector,
721 (sizeof (struct linetable)
722 + (subfile->line_vector_length
723 * sizeof (struct linetable_entry))));
726 e = subfile->line_vector->item + subfile->line_vector->nitems++;
731 /* Needed in order to sort line tables from IBM xcoff files. Sigh! */
734 compare_line_numbers (const void *ln1p, const void *ln2p)
736 struct linetable_entry *ln1 = (struct linetable_entry *) ln1p;
737 struct linetable_entry *ln2 = (struct linetable_entry *) ln2p;
739 /* Note: this code does not assume that CORE_ADDRs can fit in ints.
740 Please keep it that way. */
741 if (ln1->pc < ln2->pc)
744 if (ln1->pc > ln2->pc)
747 /* If pc equal, sort by line. I'm not sure whether this is optimum
748 behavior (see comment at struct linetable in symtab.h). */
749 return ln1->line - ln2->line;
752 /* Start a new symtab for a new source file. Called, for example,
753 when a stabs symbol of type N_SO is seen, or when a DWARF
754 TAG_compile_unit DIE is seen. It indicates the start of data for
755 one original source file. */
758 start_symtab (char *name, char *dirname, CORE_ADDR start_addr)
761 last_source_file = name;
762 last_source_start_addr = start_addr;
764 global_symbols = NULL;
766 have_line_numbers = 0;
768 /* Context stack is initially empty. Allocate first one with room
769 for 10 levels; reuse it forever afterward. */
770 if (context_stack == NULL)
772 context_stack_size = INITIAL_CONTEXT_STACK_SIZE;
773 context_stack = (struct context_stack *)
774 xmalloc (context_stack_size * sizeof (struct context_stack));
776 context_stack_depth = 0;
778 /* Initialize the list of sub source files with one entry for this
779 file (the top-level source file). */
782 current_subfile = NULL;
783 start_subfile (name, dirname);
786 /* Finish the symbol definitions for one main source file, close off
787 all the lexical contexts for that file (creating struct block's for
788 them), then make the struct symtab for that file and put it in the
791 END_ADDR is the address of the end of the file's text. SECTION is
792 the section number (in objfile->section_offsets) of the blockvector
795 Note that it is possible for end_symtab() to return NULL. In
796 particular, for the DWARF case at least, it will return NULL when
797 it finds a compilation unit that has exactly one DIE, a
798 TAG_compile_unit DIE. This can happen when we link in an object
799 file that was compiled from an empty source file. Returning NULL
800 is probably not the correct thing to do, because then gdb will
801 never know about this empty file (FIXME). */
804 end_symtab (CORE_ADDR end_addr, struct objfile *objfile, int section)
806 register struct symtab *symtab = NULL;
807 register struct blockvector *blockvector;
808 register struct subfile *subfile;
809 register struct context_stack *cstk;
810 struct subfile *nextsub;
812 /* Finish the lexical context of the last function in the file; pop
813 the context stack. */
815 if (context_stack_depth > 0)
817 cstk = pop_context ();
818 /* Make a block for the local symbols within. */
819 finish_block (cstk->name, &local_symbols, cstk->old_blocks,
820 cstk->start_addr, end_addr, objfile);
822 if (context_stack_depth > 0)
824 /* This is said to happen with SCO. The old coffread.c
825 code simply emptied the context stack, so we do the
826 same. FIXME: Find out why it is happening. This is not
827 believed to happen in most cases (even for coffread.c);
828 it used to be an abort(). */
829 static struct complaint msg =
830 {"Context stack not empty in end_symtab", 0, 0};
832 context_stack_depth = 0;
836 /* Reordered executables may have out of order pending blocks; if
837 OBJF_REORDERED is true, then sort the pending blocks. */
838 if ((objfile->flags & OBJF_REORDERED) && pending_blocks)
840 /* FIXME! Remove this horrid bubble sort and use merge sort!!! */
844 struct pending_block *pb, *pbnext;
852 /* swap blocks if unordered! */
854 if (BLOCK_START (pb->block) < BLOCK_START (pbnext->block))
856 struct block *tmp = pb->block;
857 pb->block = pbnext->block;
862 pbnext = pbnext->next;
868 /* Cleanup any undefined types that have been left hanging around
869 (this needs to be done before the finish_blocks so that
870 file_symbols is still good).
872 Both cleanup_undefined_types and finish_global_stabs are stabs
873 specific, but harmless for other symbol readers, since on gdb
874 startup or when finished reading stabs, the state is set so these
875 are no-ops. FIXME: Is this handled right in case of QUIT? Can
876 we make this cleaner? */
878 cleanup_undefined_types ();
879 finish_global_stabs (objfile);
881 if (pending_blocks == NULL
882 && file_symbols == NULL
883 && global_symbols == NULL
884 && have_line_numbers == 0)
886 /* Ignore symtabs that have no functions with real debugging
892 /* Define the STATIC_BLOCK & GLOBAL_BLOCK, and build the
894 finish_block (0, &file_symbols, 0, last_source_start_addr, end_addr,
896 finish_block (0, &global_symbols, 0, last_source_start_addr, end_addr,
898 blockvector = make_blockvector (objfile);
901 #ifndef PROCESS_LINENUMBER_HOOK
902 #define PROCESS_LINENUMBER_HOOK()
904 PROCESS_LINENUMBER_HOOK (); /* Needed for xcoff. */
906 /* Now create the symtab objects proper, one for each subfile. */
907 /* (The main file is the last one on the chain.) */
909 for (subfile = subfiles; subfile; subfile = nextsub)
911 int linetablesize = 0;
914 /* If we have blocks of symbols, make a symtab. Otherwise, just
915 ignore this file and any line number info in it. */
918 if (subfile->line_vector)
920 linetablesize = sizeof (struct linetable) +
921 subfile->line_vector->nitems * sizeof (struct linetable_entry);
923 /* I think this is artifact from before it went on the
924 obstack. I doubt we'll need the memory between now
925 and when we free it later in this function. */
926 /* First, shrink the linetable to make more memory. */
927 subfile->line_vector = (struct linetable *)
928 xrealloc ((char *) subfile->line_vector, linetablesize);
931 /* Like the pending blocks, the line table may be
932 scrambled in reordered executables. Sort it if
933 OBJF_REORDERED is true. */
934 if (objfile->flags & OBJF_REORDERED)
935 qsort (subfile->line_vector->item,
936 subfile->line_vector->nitems,
937 sizeof (struct linetable_entry), compare_line_numbers);
940 /* Now, allocate a symbol table. */
941 symtab = allocate_symtab (subfile->name, objfile);
943 /* Fill in its components. */
944 symtab->blockvector = blockvector;
945 if (subfile->line_vector)
947 /* Reallocate the line table on the symbol obstack */
948 symtab->linetable = (struct linetable *)
949 obstack_alloc (&objfile->symbol_obstack, linetablesize);
950 memcpy (symtab->linetable, subfile->line_vector, linetablesize);
954 symtab->linetable = NULL;
956 symtab->block_line_section = section;
957 if (subfile->dirname)
959 /* Reallocate the dirname on the symbol obstack */
960 symtab->dirname = (char *)
961 obstack_alloc (&objfile->symbol_obstack,
962 strlen (subfile->dirname) + 1);
963 strcpy (symtab->dirname, subfile->dirname);
967 symtab->dirname = NULL;
969 symtab->free_code = free_linetable;
970 symtab->free_ptr = NULL;
972 /* Use whatever language we have been using for this
973 subfile, not the one that was deduced in allocate_symtab
974 from the filename. We already did our own deducing when
975 we created the subfile, and we may have altered our
976 opinion of what language it is from things we found in
978 symtab->language = subfile->language;
980 /* Save the debug format string (if any) in the symtab */
981 if (subfile->debugformat != NULL)
983 symtab->debugformat = obsavestring (subfile->debugformat,
984 strlen (subfile->debugformat),
985 &objfile->symbol_obstack);
988 /* All symtabs for the main file and the subfiles share a
989 blockvector, so we need to clear primary for everything
990 but the main file. */
994 if (subfile->name != NULL)
996 free ((void *) subfile->name);
998 if (subfile->dirname != NULL)
1000 free ((void *) subfile->dirname);
1002 if (subfile->line_vector != NULL)
1004 free ((void *) subfile->line_vector);
1006 if (subfile->debugformat != NULL)
1008 free ((void *) subfile->debugformat);
1011 nextsub = subfile->next;
1012 free ((void *) subfile);
1015 /* Set this for the main source file. */
1018 symtab->primary = 1;
1021 last_source_file = NULL;
1022 current_subfile = NULL;
1027 /* Push a context block. Args are an identifying nesting level
1028 (checkable when you pop it), and the starting PC address of this
1031 struct context_stack *
1032 push_context (int desc, CORE_ADDR valu)
1034 register struct context_stack *new;
1036 if (context_stack_depth == context_stack_size)
1038 context_stack_size *= 2;
1039 context_stack = (struct context_stack *)
1040 xrealloc ((char *) context_stack,
1041 (context_stack_size * sizeof (struct context_stack)));
1044 new = &context_stack[context_stack_depth++];
1046 new->locals = local_symbols;
1047 new->params = param_symbols;
1048 new->old_blocks = pending_blocks;
1049 new->start_addr = valu;
1052 local_symbols = NULL;
1053 param_symbols = NULL;
1059 /* Compute a small integer hash code for the given name. */
1062 hashname (char *name)
1064 return (hash(name,strlen(name)) % HASHSIZE);
1069 record_debugformat (char *format)
1071 current_subfile->debugformat = savestring (format, strlen (format));
1074 /* Merge the first symbol list SRCLIST into the second symbol list
1075 TARGETLIST by repeated calls to add_symbol_to_list(). This
1076 procedure "frees" each link of SRCLIST by adding it to the
1077 free_pendings list. Caller must set SRCLIST to a null list after
1078 calling this function.
1083 merge_symbol_lists (struct pending **srclist, struct pending **targetlist)
1087 if (!srclist || !*srclist)
1090 /* Merge in elements from current link. */
1091 for (i = 0; i < (*srclist)->nsyms; i++)
1092 add_symbol_to_list ((*srclist)->symbol[i], targetlist);
1094 /* Recurse on next. */
1095 merge_symbol_lists (&(*srclist)->next, targetlist);
1097 /* "Free" the current link. */
1098 (*srclist)->next = free_pendings;
1099 free_pendings = (*srclist);
1102 /* Initialize anything that needs initializing when starting to read a
1103 fresh piece of a symbol file, e.g. reading in the stuff
1104 corresponding to a psymtab. */
1107 buildsym_init (void)
1109 free_pendings = NULL;
1110 file_symbols = NULL;
1111 global_symbols = NULL;
1112 pending_blocks = NULL;
1115 /* Initialize anything that needs initializing when a completely new
1116 symbol file is specified (not just adding some symbols from another
1117 file, e.g. a shared library). */
1120 buildsym_new_init (void)