1 /* Support routines for building symbol tables in GDB's internal format.
2 Copyright 1986-1999 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, Boston, MA 02111-1307, USA. */
20 /* This module provides subroutines used for creating and adding to
21 the symbol table. These routines are called from various symbol-
22 file-reading routines.
24 Routines to support specific debugging information formats (stabs,
25 DWARF, etc) belong somewhere else. */
31 #include "symfile.h" /* Needed for "struct complaint" */
34 #include "complaints.h"
35 #include "gdb_string.h"
37 /* Ask buildsym.h to define the vars it normally declares `extern'. */
39 #include "buildsym.h" /* Our own declarations */
42 /* For cleanup_undefined_types and finish_global_stabs (somewhat
43 questionable--see comment where we call them). */
45 #include "stabsread.h"
47 /* List of free `struct pending' structures for reuse. */
49 static struct pending *free_pendings;
51 /* Non-zero if symtab has line number info. This prevents an
52 otherwise empty symtab from being tossed. */
54 static int have_line_numbers;
56 static int compare_line_numbers (const void *ln1p, const void *ln2p);
59 /* Initial sizes of data structures. These are realloc'd larger if
60 needed, and realloc'd down to the size actually used, when
63 #define INITIAL_CONTEXT_STACK_SIZE 10
64 #define INITIAL_LINE_VECTOR_LENGTH 1000
67 /* Complaints about the symbols we have encountered. */
69 struct complaint block_end_complaint =
70 {"block end address less than block start address in %s (patched it)", 0, 0};
72 struct complaint anon_block_end_complaint =
73 {"block end address 0x%lx less than block start address 0x%lx (patched it)", 0, 0};
75 struct complaint innerblock_complaint =
76 {"inner block not inside outer block in %s", 0, 0};
78 struct complaint innerblock_anon_complaint =
79 {"inner block (0x%lx-0x%lx) not inside outer block (0x%lx-0x%lx)", 0, 0};
81 struct complaint blockvector_complaint =
82 {"block at 0x%lx out of order", 0, 0};
84 /* maintain the lists of symbols and blocks */
86 /* Add a symbol to one of the lists of symbols. */
89 add_symbol_to_list (struct symbol *symbol, struct pending **listhead)
91 register struct pending *link;
93 /* If this is an alias for another symbol, don't add it. */
94 if (symbol->ginfo.name && symbol->ginfo.name[0] == '#')
97 /* We keep PENDINGSIZE symbols in each link of the list. If we
98 don't have a link with room in it, add a new link. */
99 if (*listhead == NULL || (*listhead)->nsyms == PENDINGSIZE)
103 link = free_pendings;
104 free_pendings = link->next;
108 link = (struct pending *) xmalloc (sizeof (struct pending));
111 link->next = *listhead;
116 (*listhead)->symbol[(*listhead)->nsyms++] = symbol;
119 /* Find a symbol named NAME on a LIST. NAME need not be
120 '\0'-terminated; LENGTH is the length of the name. */
123 find_symbol_in_list (struct pending *list, char *name, int length)
130 for (j = list->nsyms; --j >= 0;)
132 pp = SYMBOL_NAME (list->symbol[j]);
133 if (*pp == *name && strncmp (pp, name, length) == 0 &&
136 return (list->symbol[j]);
144 /* At end of reading syms, or in case of quit, really free as many
145 `struct pending's as we can easily find. */
149 really_free_pendings (int foo)
151 struct pending *next, *next1;
153 for (next = free_pendings; next; next = next1)
156 free ((void *) next);
158 free_pendings = NULL;
160 free_pending_blocks ();
162 for (next = file_symbols; next != NULL; next = next1)
165 free ((void *) next);
169 for (next = global_symbols; next != NULL; next = next1)
172 free ((void *) next);
174 global_symbols = NULL;
177 /* This function is called to discard any pending blocks. */
180 free_pending_blocks (void)
182 #if 0 /* Now we make the links in the
183 symbol_obstack, so don't free
185 struct pending_block *bnext, *bnext1;
187 for (bnext = pending_blocks; bnext; bnext = bnext1)
189 bnext1 = bnext->next;
190 free ((void *) bnext);
193 pending_blocks = NULL;
196 /* Take one of the lists of symbols and make a block from it. Keep
197 the order the symbols have in the list (reversed from the input
198 file). Put the block on the list of pending blocks. */
201 finish_block (struct symbol *symbol, struct pending **listhead,
202 struct pending_block *old_blocks,
203 CORE_ADDR start, CORE_ADDR end,
204 struct objfile *objfile)
206 register struct pending *next, *next1;
207 register struct block *block;
208 register struct pending_block *pblock;
209 struct pending_block *opblock;
213 /* Count the length of the list of symbols. */
215 for (next = *listhead, i = 0;
217 i += next->nsyms, next = next->next)
222 block = (struct block *) obstack_alloc (&objfile->symbol_obstack,
223 (sizeof (struct block) + ((i - 1) * sizeof (struct symbol *))));
225 /* Copy the symbols into the block. */
227 BLOCK_NSYMS (block) = i;
228 for (next = *listhead; next; next = next->next)
230 for (j = next->nsyms - 1; j >= 0; j--)
232 BLOCK_SYM (block, --i) = next->symbol[j];
236 BLOCK_START (block) = start;
237 BLOCK_END (block) = end;
238 /* Superblock filled in when containing block is made */
239 BLOCK_SUPERBLOCK (block) = NULL;
241 BLOCK_GCC_COMPILED (block) = processing_gcc_compilation;
243 /* Put the block in as the value of the symbol that names it. */
247 struct type *ftype = SYMBOL_TYPE (symbol);
248 SYMBOL_BLOCK_VALUE (symbol) = block;
249 BLOCK_FUNCTION (block) = symbol;
251 if (TYPE_NFIELDS (ftype) <= 0)
253 /* No parameter type information is recorded with the
254 function's type. Set that from the type of the
255 parameter symbols. */
256 int nparams = 0, iparams;
258 for (i = 0; i < BLOCK_NSYMS (block); i++)
260 sym = BLOCK_SYM (block, i);
261 switch (SYMBOL_CLASS (sym))
266 case LOC_REGPARM_ADDR:
267 case LOC_BASEREG_ARG:
280 case LOC_CONST_BYTES:
283 case LOC_OPTIMIZED_OUT:
290 TYPE_NFIELDS (ftype) = nparams;
291 TYPE_FIELDS (ftype) = (struct field *)
292 TYPE_ALLOC (ftype, nparams * sizeof (struct field));
294 for (i = iparams = 0; iparams < nparams; i++)
296 sym = BLOCK_SYM (block, i);
297 switch (SYMBOL_CLASS (sym))
302 case LOC_REGPARM_ADDR:
303 case LOC_BASEREG_ARG:
305 TYPE_FIELD_TYPE (ftype, iparams) = SYMBOL_TYPE (sym);
317 case LOC_CONST_BYTES:
320 case LOC_OPTIMIZED_OUT:
330 BLOCK_FUNCTION (block) = NULL;
333 /* Now "free" the links of the list, and empty the list. */
335 for (next = *listhead; next; next = next1)
338 next->next = free_pendings;
339 free_pendings = next;
344 /* Check to be sure that the blocks have an end address that is
345 greater than starting address */
347 if (BLOCK_END (block) < BLOCK_START (block))
351 complain (&block_end_complaint, SYMBOL_SOURCE_NAME (symbol));
355 complain (&anon_block_end_complaint, BLOCK_END (block), BLOCK_START (block));
357 /* Better than nothing */
358 BLOCK_END (block) = BLOCK_START (block);
362 /* Install this block as the superblock of all blocks made since the
363 start of this scope that don't have superblocks yet. */
366 for (pblock = pending_blocks; pblock != old_blocks; pblock = pblock->next)
368 if (BLOCK_SUPERBLOCK (pblock->block) == NULL)
371 /* Check to be sure the blocks are nested as we receive
372 them. If the compiler/assembler/linker work, this just
373 burns a small amount of time. */
374 if (BLOCK_START (pblock->block) < BLOCK_START (block) ||
375 BLOCK_END (pblock->block) > BLOCK_END (block))
379 complain (&innerblock_complaint,
380 SYMBOL_SOURCE_NAME (symbol));
384 complain (&innerblock_anon_complaint, BLOCK_START (pblock->block),
385 BLOCK_END (pblock->block), BLOCK_START (block),
388 if (BLOCK_START (pblock->block) < BLOCK_START (block))
389 BLOCK_START (pblock->block) = BLOCK_START (block);
390 if (BLOCK_END (pblock->block) > BLOCK_END (block))
391 BLOCK_END (pblock->block) = BLOCK_END (block);
394 BLOCK_SUPERBLOCK (pblock->block) = block;
399 record_pending_block (objfile, block, opblock);
402 /* Record BLOCK on the list of all blocks in the file. Put it after
403 OPBLOCK, or at the beginning if opblock is NULL. This puts the
404 block in the list after all its subblocks.
406 Allocate the pending block struct in the symbol_obstack to save
407 time. This wastes a little space. FIXME: Is it worth it? */
410 record_pending_block (struct objfile *objfile, struct block *block,
411 struct pending_block *opblock)
413 register struct pending_block *pblock;
415 pblock = (struct pending_block *)
416 obstack_alloc (&objfile->symbol_obstack, sizeof (struct pending_block));
417 pblock->block = block;
420 pblock->next = opblock->next;
421 opblock->next = pblock;
425 pblock->next = pending_blocks;
426 pending_blocks = pblock;
430 /* Note that this is only used in this file and in dstread.c, which
431 should be fixed to not need direct access to this function. When
432 that is done, it can be made static again. */
435 make_blockvector (struct objfile *objfile)
437 register struct pending_block *next;
438 register struct blockvector *blockvector;
441 /* Count the length of the list of blocks. */
443 for (next = pending_blocks, i = 0; next; next = next->next, i++)
447 blockvector = (struct blockvector *)
448 obstack_alloc (&objfile->symbol_obstack,
449 (sizeof (struct blockvector)
450 + (i - 1) * sizeof (struct block *)));
452 /* Copy the blocks into the blockvector. This is done in reverse
453 order, which happens to put the blocks into the proper order
454 (ascending starting address). finish_block has hair to insert
455 each block into the list after its subblocks in order to make
456 sure this is true. */
458 BLOCKVECTOR_NBLOCKS (blockvector) = i;
459 for (next = pending_blocks; next; next = next->next)
461 BLOCKVECTOR_BLOCK (blockvector, --i) = next->block;
464 #if 0 /* Now we make the links in the
465 obstack, so don't free them. */
466 /* Now free the links of the list, and empty the list. */
468 for (next = pending_blocks; next; next = next1)
474 pending_blocks = NULL;
476 #if 1 /* FIXME, shut this off after a while
477 to speed up symbol reading. */
478 /* Some compilers output blocks in the wrong order, but we depend on
479 their being in the right order so we can binary search. Check the
480 order and moan about it. FIXME. */
481 if (BLOCKVECTOR_NBLOCKS (blockvector) > 1)
483 for (i = 1; i < BLOCKVECTOR_NBLOCKS (blockvector); i++)
485 if (BLOCK_START (BLOCKVECTOR_BLOCK (blockvector, i - 1))
486 > BLOCK_START (BLOCKVECTOR_BLOCK (blockvector, i)))
489 /* FIXME-32x64: loses if CORE_ADDR doesn't fit in a
490 long. Possible solutions include a version of
491 complain which takes a callback, a
492 sprintf_address_numeric to match
493 print_address_numeric, or a way to set up a GDB_FILE
494 which causes sprintf rather than fprintf to be
497 complain (&blockvector_complaint,
498 (unsigned long) BLOCK_START (BLOCKVECTOR_BLOCK (blockvector, i)));
504 return (blockvector);
507 /* Start recording information about source code that came from an
508 included (or otherwise merged-in) source file with a different
509 name. NAME is the name of the file (cannot be NULL), DIRNAME is
510 the directory in which it resides (or NULL if not known). */
513 start_subfile (char *name, char *dirname)
515 register struct subfile *subfile;
517 /* See if this subfile is already known as a subfile of the current
520 for (subfile = subfiles; subfile; subfile = subfile->next)
522 if (STREQ (subfile->name, name))
524 current_subfile = subfile;
529 /* This subfile is not known. Add an entry for it. Make an entry
530 for this subfile in the list of all subfiles of the current main
533 subfile = (struct subfile *) xmalloc (sizeof (struct subfile));
534 subfile->next = subfiles;
536 current_subfile = subfile;
538 /* Save its name and compilation directory name */
539 subfile->name = (name == NULL) ? NULL : savestring (name, strlen (name));
541 (dirname == NULL) ? NULL : savestring (dirname, strlen (dirname));
543 /* Initialize line-number recording for this subfile. */
544 subfile->line_vector = NULL;
546 /* Default the source language to whatever can be deduced from the
547 filename. If nothing can be deduced (such as for a C/C++ include
548 file with a ".h" extension), then inherit whatever language the
549 previous subfile had. This kludgery is necessary because there
550 is no standard way in some object formats to record the source
551 language. Also, when symtabs are allocated we try to deduce a
552 language then as well, but it is too late for us to use that
553 information while reading symbols, since symtabs aren't allocated
554 until after all the symbols have been processed for a given
557 subfile->language = deduce_language_from_filename (subfile->name);
558 if (subfile->language == language_unknown &&
559 subfile->next != NULL)
561 subfile->language = subfile->next->language;
564 /* Initialize the debug format string to NULL. We may supply it
565 later via a call to record_debugformat. */
566 subfile->debugformat = NULL;
568 /* cfront output is a C program, so in most ways it looks like a C
569 program. But to demangle we need to set the language to C++. We
570 can distinguish cfront code by the fact that it has #line
571 directives which specify a file name ending in .C.
573 So if the filename of this subfile ends in .C, then change the
574 language of any pending subfiles from C to C++. We also accept
575 any other C++ suffixes accepted by deduce_language_from_filename
576 (in particular, some people use .cxx with cfront). */
577 /* Likewise for f2c. */
582 enum language sublang = deduce_language_from_filename (subfile->name);
584 if (sublang == language_cplus || sublang == language_fortran)
585 for (s = subfiles; s != NULL; s = s->next)
586 if (s->language == language_c)
587 s->language = sublang;
590 /* And patch up this file if necessary. */
591 if (subfile->language == language_c
592 && subfile->next != NULL
593 && (subfile->next->language == language_cplus
594 || subfile->next->language == language_fortran))
596 subfile->language = subfile->next->language;
600 /* For stabs readers, the first N_SO symbol is assumed to be the
601 source file name, and the subfile struct is initialized using that
602 assumption. If another N_SO symbol is later seen, immediately
603 following the first one, then the first one is assumed to be the
604 directory name and the second one is really the source file name.
606 So we have to patch up the subfile struct by moving the old name
607 value to dirname and remembering the new name. Some sanity
608 checking is performed to ensure that the state of the subfile
609 struct is reasonable and that the old name we are assuming to be a
610 directory name actually is (by checking for a trailing '/'). */
613 patch_subfile_names (struct subfile *subfile, char *name)
615 if (subfile != NULL && subfile->dirname == NULL && subfile->name != NULL
616 && subfile->name[strlen (subfile->name) - 1] == '/')
618 subfile->dirname = subfile->name;
619 subfile->name = savestring (name, strlen (name));
620 last_source_file = name;
622 /* Default the source language to whatever can be deduced from
623 the filename. If nothing can be deduced (such as for a C/C++
624 include file with a ".h" extension), then inherit whatever
625 language the previous subfile had. This kludgery is
626 necessary because there is no standard way in some object
627 formats to record the source language. Also, when symtabs
628 are allocated we try to deduce a language then as well, but
629 it is too late for us to use that information while reading
630 symbols, since symtabs aren't allocated until after all the
631 symbols have been processed for a given source file. */
633 subfile->language = deduce_language_from_filename (subfile->name);
634 if (subfile->language == language_unknown &&
635 subfile->next != NULL)
637 subfile->language = subfile->next->language;
642 /* Handle the N_BINCL and N_EINCL symbol types that act like N_SOL for
643 switching source files (different subfiles, as we call them) within
644 one object file, but using a stack rather than in an arbitrary
650 register struct subfile_stack *tem
651 = (struct subfile_stack *) xmalloc (sizeof (struct subfile_stack));
653 tem->next = subfile_stack;
655 if (current_subfile == NULL || current_subfile->name == NULL)
659 tem->name = current_subfile->name;
666 register struct subfile_stack *link = subfile_stack;
673 subfile_stack = link->next;
674 free ((void *) link);
678 /* Add a linetable entry for line number LINE and address PC to the
679 line vector for SUBFILE. */
682 record_line (register struct subfile *subfile, int line, CORE_ADDR pc)
684 struct linetable_entry *e;
685 /* Ignore the dummy line number in libg.o */
692 /* Make sure line vector exists and is big enough. */
693 if (!subfile->line_vector)
695 subfile->line_vector_length = INITIAL_LINE_VECTOR_LENGTH;
696 subfile->line_vector = (struct linetable *)
697 xmalloc (sizeof (struct linetable)
698 + subfile->line_vector_length * sizeof (struct linetable_entry));
699 subfile->line_vector->nitems = 0;
700 have_line_numbers = 1;
703 if (subfile->line_vector->nitems + 1 >= subfile->line_vector_length)
705 subfile->line_vector_length *= 2;
706 subfile->line_vector = (struct linetable *)
707 xrealloc ((char *) subfile->line_vector,
708 (sizeof (struct linetable)
709 + (subfile->line_vector_length
710 * sizeof (struct linetable_entry))));
713 e = subfile->line_vector->item + subfile->line_vector->nitems++;
718 /* Needed in order to sort line tables from IBM xcoff files. Sigh! */
721 compare_line_numbers (const void *ln1p, const void *ln2p)
723 struct linetable_entry *ln1 = (struct linetable_entry *) ln1p;
724 struct linetable_entry *ln2 = (struct linetable_entry *) ln2p;
726 /* Note: this code does not assume that CORE_ADDRs can fit in ints.
727 Please keep it that way. */
728 if (ln1->pc < ln2->pc)
731 if (ln1->pc > ln2->pc)
734 /* If pc equal, sort by line. I'm not sure whether this is optimum
735 behavior (see comment at struct linetable in symtab.h). */
736 return ln1->line - ln2->line;
739 /* Start a new symtab for a new source file. Called, for example,
740 when a stabs symbol of type N_SO is seen, or when a DWARF
741 TAG_compile_unit DIE is seen. It indicates the start of data for
742 one original source file. */
745 start_symtab (char *name, char *dirname, CORE_ADDR start_addr)
748 last_source_file = name;
749 last_source_start_addr = start_addr;
751 global_symbols = NULL;
753 have_line_numbers = 0;
755 /* Context stack is initially empty. Allocate first one with room
756 for 10 levels; reuse it forever afterward. */
757 if (context_stack == NULL)
759 context_stack_size = INITIAL_CONTEXT_STACK_SIZE;
760 context_stack = (struct context_stack *)
761 xmalloc (context_stack_size * sizeof (struct context_stack));
763 context_stack_depth = 0;
765 /* Initialize the list of sub source files with one entry for this
766 file (the top-level source file). */
769 current_subfile = NULL;
770 start_subfile (name, dirname);
773 /* Finish the symbol definitions for one main source file, close off
774 all the lexical contexts for that file (creating struct block's for
775 them), then make the struct symtab for that file and put it in the
778 END_ADDR is the address of the end of the file's text. SECTION is
779 the section number (in objfile->section_offsets) of the blockvector
782 Note that it is possible for end_symtab() to return NULL. In
783 particular, for the DWARF case at least, it will return NULL when
784 it finds a compilation unit that has exactly one DIE, a
785 TAG_compile_unit DIE. This can happen when we link in an object
786 file that was compiled from an empty source file. Returning NULL
787 is probably not the correct thing to do, because then gdb will
788 never know about this empty file (FIXME). */
791 end_symtab (CORE_ADDR end_addr, struct objfile *objfile, int section)
793 register struct symtab *symtab = NULL;
794 register struct blockvector *blockvector;
795 register struct subfile *subfile;
796 register struct context_stack *cstk;
797 struct subfile *nextsub;
799 /* Finish the lexical context of the last function in the file; pop
800 the context stack. */
802 if (context_stack_depth > 0)
804 cstk = pop_context ();
805 /* Make a block for the local symbols within. */
806 finish_block (cstk->name, &local_symbols, cstk->old_blocks,
807 cstk->start_addr, end_addr, objfile);
809 if (context_stack_depth > 0)
811 /* This is said to happen with SCO. The old coffread.c
812 code simply emptied the context stack, so we do the
813 same. FIXME: Find out why it is happening. This is not
814 believed to happen in most cases (even for coffread.c);
815 it used to be an abort(). */
816 static struct complaint msg =
817 {"Context stack not empty in end_symtab", 0, 0};
819 context_stack_depth = 0;
823 /* Reordered executables may have out of order pending blocks; if
824 OBJF_REORDERED is true, then sort the pending blocks. */
825 if ((objfile->flags & OBJF_REORDERED) && pending_blocks)
827 /* FIXME! Remove this horrid bubble sort and use merge sort!!! */
831 struct pending_block *pb, *pbnext;
839 /* swap blocks if unordered! */
841 if (BLOCK_START (pb->block) < BLOCK_START (pbnext->block))
843 struct block *tmp = pb->block;
844 pb->block = pbnext->block;
849 pbnext = pbnext->next;
855 /* Cleanup any undefined types that have been left hanging around
856 (this needs to be done before the finish_blocks so that
857 file_symbols is still good).
859 Both cleanup_undefined_types and finish_global_stabs are stabs
860 specific, but harmless for other symbol readers, since on gdb
861 startup or when finished reading stabs, the state is set so these
862 are no-ops. FIXME: Is this handled right in case of QUIT? Can
863 we make this cleaner? */
865 cleanup_undefined_types ();
866 finish_global_stabs (objfile);
868 if (pending_blocks == NULL
869 && file_symbols == NULL
870 && global_symbols == NULL
871 && have_line_numbers == 0)
873 /* Ignore symtabs that have no functions with real debugging
879 /* Define the STATIC_BLOCK & GLOBAL_BLOCK, and build the
881 finish_block (0, &file_symbols, 0, last_source_start_addr, end_addr,
883 finish_block (0, &global_symbols, 0, last_source_start_addr, end_addr,
885 blockvector = make_blockvector (objfile);
888 #ifndef PROCESS_LINENUMBER_HOOK
889 #define PROCESS_LINENUMBER_HOOK()
891 PROCESS_LINENUMBER_HOOK (); /* Needed for xcoff. */
893 /* Now create the symtab objects proper, one for each subfile. */
894 /* (The main file is the last one on the chain.) */
896 for (subfile = subfiles; subfile; subfile = nextsub)
898 int linetablesize = 0;
901 /* If we have blocks of symbols, make a symtab. Otherwise, just
902 ignore this file and any line number info in it. */
905 if (subfile->line_vector)
907 linetablesize = sizeof (struct linetable) +
908 subfile->line_vector->nitems * sizeof (struct linetable_entry);
910 /* I think this is artifact from before it went on the
911 obstack. I doubt we'll need the memory between now
912 and when we free it later in this function. */
913 /* First, shrink the linetable to make more memory. */
914 subfile->line_vector = (struct linetable *)
915 xrealloc ((char *) subfile->line_vector, linetablesize);
918 /* Like the pending blocks, the line table may be
919 scrambled in reordered executables. Sort it if
920 OBJF_REORDERED is true. */
921 if (objfile->flags & OBJF_REORDERED)
922 qsort (subfile->line_vector->item,
923 subfile->line_vector->nitems,
924 sizeof (struct linetable_entry), compare_line_numbers);
927 /* Now, allocate a symbol table. */
928 symtab = allocate_symtab (subfile->name, objfile);
930 /* Fill in its components. */
931 symtab->blockvector = blockvector;
932 if (subfile->line_vector)
934 /* Reallocate the line table on the symbol obstack */
935 symtab->linetable = (struct linetable *)
936 obstack_alloc (&objfile->symbol_obstack, linetablesize);
937 memcpy (symtab->linetable, subfile->line_vector, linetablesize);
941 symtab->linetable = NULL;
943 symtab->block_line_section = section;
944 if (subfile->dirname)
946 /* Reallocate the dirname on the symbol obstack */
947 symtab->dirname = (char *)
948 obstack_alloc (&objfile->symbol_obstack,
949 strlen (subfile->dirname) + 1);
950 strcpy (symtab->dirname, subfile->dirname);
954 symtab->dirname = NULL;
956 symtab->free_code = free_linetable;
957 symtab->free_ptr = NULL;
959 /* Use whatever language we have been using for this
960 subfile, not the one that was deduced in allocate_symtab
961 from the filename. We already did our own deducing when
962 we created the subfile, and we may have altered our
963 opinion of what language it is from things we found in
965 symtab->language = subfile->language;
967 /* Save the debug format string (if any) in the symtab */
968 if (subfile->debugformat != NULL)
970 symtab->debugformat = obsavestring (subfile->debugformat,
971 strlen (subfile->debugformat),
972 &objfile->symbol_obstack);
975 /* All symtabs for the main file and the subfiles share a
976 blockvector, so we need to clear primary for everything
977 but the main file. */
981 if (subfile->name != NULL)
983 free ((void *) subfile->name);
985 if (subfile->dirname != NULL)
987 free ((void *) subfile->dirname);
989 if (subfile->line_vector != NULL)
991 free ((void *) subfile->line_vector);
993 if (subfile->debugformat != NULL)
995 free ((void *) subfile->debugformat);
998 nextsub = subfile->next;
999 free ((void *) subfile);
1002 /* Set this for the main source file. */
1005 symtab->primary = 1;
1008 last_source_file = NULL;
1009 current_subfile = NULL;
1014 /* Push a context block. Args are an identifying nesting level
1015 (checkable when you pop it), and the starting PC address of this
1018 struct context_stack *
1019 push_context (int desc, CORE_ADDR valu)
1021 register struct context_stack *new;
1023 if (context_stack_depth == context_stack_size)
1025 context_stack_size *= 2;
1026 context_stack = (struct context_stack *)
1027 xrealloc ((char *) context_stack,
1028 (context_stack_size * sizeof (struct context_stack)));
1031 new = &context_stack[context_stack_depth++];
1033 new->locals = local_symbols;
1034 new->params = param_symbols;
1035 new->old_blocks = pending_blocks;
1036 new->start_addr = valu;
1039 local_symbols = NULL;
1040 param_symbols = NULL;
1045 /* Compute a small integer hash code for the given name. */
1048 hashname (char *name)
1050 register char *p = name;
1051 register int total = p[0];
1066 /* Ensure result is positive. */
1069 total += (1000 << 6);
1071 return (total % HASHSIZE);
1076 record_debugformat (char *format)
1078 current_subfile->debugformat = savestring (format, strlen (format));
1081 /* Merge the first symbol list SRCLIST into the second symbol list
1082 TARGETLIST by repeated calls to add_symbol_to_list(). This
1083 procedure "frees" each link of SRCLIST by adding it to the
1084 free_pendings list. Caller must set SRCLIST to a null list after
1085 calling this function.
1090 merge_symbol_lists (struct pending **srclist, struct pending **targetlist)
1094 if (!srclist || !*srclist)
1097 /* Merge in elements from current link. */
1098 for (i = 0; i < (*srclist)->nsyms; i++)
1099 add_symbol_to_list ((*srclist)->symbol[i], targetlist);
1101 /* Recurse on next. */
1102 merge_symbol_lists (&(*srclist)->next, targetlist);
1104 /* "Free" the current link. */
1105 (*srclist)->next = free_pendings;
1106 free_pendings = (*srclist);
1109 /* Initialize anything that needs initializing when starting to read a
1110 fresh piece of a symbol file, e.g. reading in the stuff
1111 corresponding to a psymtab. */
1116 free_pendings = NULL;
1117 file_symbols = NULL;
1118 global_symbols = NULL;
1119 pending_blocks = NULL;
1122 /* Initialize anything that needs initializing when a completely new
1123 symbol file is specified (not just adding some symbols from another
1124 file, e.g. a shared library). */
1127 buildsym_new_init ()