1 /* Support routines for building symbol tables in GDB's internal format.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1995, 1996
3 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, 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"
38 /* Ask buildsym.h to define the vars it normally declares `extern'. */
40 #include "buildsym.h" /* Our own declarations */
43 /* For cleanup_undefined_types and finish_global_stabs (somewhat
44 questionable--see comment where we call them). */
45 #include "stabsread.h"
47 /* Pointer to the head of a linked list of symbol blocks which have
48 already been finalized (lexical contexts already closed) and which are
49 just waiting to be built into a blockvector when finalizing the
52 static struct pending_block *pending_blocks = NULL;
54 /* List of free `struct pending' structures for reuse. */
56 static struct pending *free_pendings;
58 /* Non-zero if symtab has line number info. This prevents an otherwise empty
59 symtab from being tossed. */
61 static int have_line_numbers;
64 compare_line_numbers PARAMS ((const void *, const void *));
67 /* Initial sizes of data structures. These are realloc'd larger if needed,
68 and realloc'd down to the size actually used, when completed. */
70 #define INITIAL_CONTEXT_STACK_SIZE 10
71 #define INITIAL_LINE_VECTOR_LENGTH 1000
74 /* Complaints about the symbols we have encountered. */
76 struct complaint block_end_complaint =
77 {"block end address less than block start address in %s (patched it)", 0, 0};
79 struct complaint anon_block_end_complaint =
80 {"block end address 0x%lx less than block start address 0x%lx (patched it)", 0, 0};
82 struct complaint innerblock_complaint =
83 {"inner block not inside outer block in %s", 0, 0};
85 struct complaint innerblock_anon_complaint =
86 {"inner block (0x%lx-0x%lx) not inside outer block (0x%lx-0x%lx)", 0, 0};
88 struct complaint blockvector_complaint =
89 {"block at 0x%lx out of order", 0, 0};
92 /* maintain the lists of symbols and blocks */
94 /* Add a symbol to one of the lists of symbols. */
97 add_symbol_to_list (symbol, listhead)
98 struct symbol *symbol;
99 struct pending **listhead;
101 register struct pending *link;
103 /* If this is a reference to/live alias for another symbol, don't add it.
104 We don't want to be able to look up the live references directly. */
105 if (symbol->ginfo.name && symbol->ginfo.name[0] == '#')
108 /* We keep PENDINGSIZE symbols in each link of the list.
109 If we don't have a link with room in it, add a new link. */
110 if (*listhead == NULL || (*listhead)->nsyms == PENDINGSIZE)
114 link = free_pendings;
115 free_pendings = link->next;
119 link = (struct pending *) xmalloc (sizeof (struct pending));
122 link->next = *listhead;
127 (*listhead)->symbol[(*listhead)->nsyms++] = symbol;
130 /* Find a symbol named NAME on a LIST. NAME need not be '\0'-terminated;
131 LENGTH is the length of the name. */
134 find_symbol_in_list (list, name, length)
135 struct pending *list;
144 for (j = list->nsyms; --j >= 0; )
146 pp = SYMBOL_NAME (list->symbol[j]);
147 if (*pp == *name && strncmp (pp, name, length) == 0 &&
150 return (list->symbol[j]);
158 /* At end of reading syms, or in case of quit,
159 really free as many `struct pending's as we can easily find. */
163 really_free_pendings (foo)
166 struct pending *next, *next1;
168 for (next = free_pendings; next; next = next1)
173 free_pendings = NULL;
175 free_pending_blocks ();
177 for (next = file_symbols; next != NULL; next = next1)
184 for (next = global_symbols; next != NULL; next = next1)
189 global_symbols = NULL;
192 /* This function is called to discard any pending blocks. */
195 free_pending_blocks ()
197 #if 0 /* Now we make the links in the symbol_obstack, so don't free them. */
198 struct pending_block *bnext, *bnext1;
200 for (bnext = pending_blocks; bnext; bnext = bnext1)
202 bnext1 = bnext->next;
206 pending_blocks = NULL;
209 /* Take one of the lists of symbols and make a block from it.
210 Keep the order the symbols have in the list (reversed from the input file).
211 Put the block on the list of pending blocks. */
214 finish_block (symbol, listhead, old_blocks, start, end, objfile)
215 struct symbol *symbol;
216 struct pending **listhead;
217 struct pending_block *old_blocks;
218 CORE_ADDR start, end;
219 struct objfile *objfile;
221 register struct pending *next, *next1;
222 register struct block *block;
223 register struct pending_block *pblock;
224 struct pending_block *opblock;
228 /* Count the length of the list of symbols. */
230 for (next = *listhead, i = 0;
232 i += next->nsyms, next = next->next)
237 block = (struct block *) obstack_alloc (&objfile -> symbol_obstack,
238 (sizeof (struct block) + ((i - 1) * sizeof (struct symbol *))));
240 /* Copy the symbols into the block. */
242 BLOCK_NSYMS (block) = i;
243 for (next = *listhead; next; next = next->next)
245 for (j = next->nsyms - 1; j >= 0; j--)
247 BLOCK_SYM (block, --i) = next->symbol[j];
251 BLOCK_START (block) = start;
252 BLOCK_END (block) = end;
253 /* Superblock filled in when containing block is made */
254 BLOCK_SUPERBLOCK (block) = NULL;
255 BLOCK_GCC_COMPILED (block) = processing_gcc_compilation;
257 /* Put the block in as the value of the symbol that names it. */
261 struct type *ftype = SYMBOL_TYPE (symbol);
262 SYMBOL_BLOCK_VALUE (symbol) = block;
263 BLOCK_FUNCTION (block) = symbol;
265 if (TYPE_NFIELDS (ftype) <= 0)
267 /* No parameter type information is recorded with the function's
268 type. Set that from the type of the parameter symbols. */
269 int nparams = 0, iparams;
271 for (i = 0; i < BLOCK_NSYMS (block); i++)
273 sym = BLOCK_SYM (block, i);
274 switch (SYMBOL_CLASS (sym))
279 case LOC_REGPARM_ADDR:
280 case LOC_BASEREG_ARG:
292 case LOC_CONST_BYTES:
295 case LOC_OPTIMIZED_OUT:
302 TYPE_NFIELDS (ftype) = nparams;
303 TYPE_FIELDS (ftype) = (struct field *)
304 TYPE_ALLOC (ftype, nparams * sizeof (struct field));
306 for (i = iparams = 0; iparams < nparams; i++)
308 sym = BLOCK_SYM (block, i);
309 switch (SYMBOL_CLASS (sym))
314 case LOC_REGPARM_ADDR:
315 case LOC_BASEREG_ARG:
317 TYPE_FIELD_TYPE (ftype, iparams) = SYMBOL_TYPE (sym);
328 case LOC_CONST_BYTES:
331 case LOC_OPTIMIZED_OUT:
341 BLOCK_FUNCTION (block) = NULL;
344 /* Now "free" the links of the list, and empty the list. */
346 for (next = *listhead; next; next = next1)
349 next->next = free_pendings;
350 free_pendings = next;
355 /* Check to be sure that the blocks have an end address that is
356 greater than starting address */
358 if (BLOCK_END (block) < BLOCK_START (block))
362 complain (&block_end_complaint, SYMBOL_SOURCE_NAME (symbol));
366 complain (&anon_block_end_complaint, BLOCK_END (block), BLOCK_START (block));
368 /* Better than nothing */
369 BLOCK_END (block) = BLOCK_START (block);
373 /* Install this block as the superblock
374 of all blocks made since the start of this scope
375 that don't have superblocks yet. */
378 for (pblock = pending_blocks; pblock != old_blocks; pblock = pblock->next)
380 if (BLOCK_SUPERBLOCK (pblock->block) == NULL)
383 /* Check to be sure the blocks are nested as we receive them.
384 If the compiler/assembler/linker work, this just burns a small
386 if (BLOCK_START (pblock->block) < BLOCK_START (block) ||
387 BLOCK_END (pblock->block) > BLOCK_END (block))
391 complain (&innerblock_complaint,
392 SYMBOL_SOURCE_NAME (symbol));
396 complain (&innerblock_anon_complaint, BLOCK_START (pblock->block),
397 BLOCK_END (pblock->block), BLOCK_START (block),
400 if (BLOCK_START (pblock->block) < BLOCK_START (block))
401 BLOCK_START (pblock->block) = BLOCK_START (block);
402 if (BLOCK_END (pblock->block) > BLOCK_END (block))
403 BLOCK_END (pblock->block) = BLOCK_END (block);
406 BLOCK_SUPERBLOCK (pblock->block) = block;
411 record_pending_block (objfile, block, opblock);
414 /* Record BLOCK on the list of all blocks in the file. Put it after
415 OPBLOCK, or at the beginning if opblock is NULL. This puts the block
416 in the list after all its subblocks.
418 Allocate the pending block struct in the symbol_obstack to save
419 time. This wastes a little space. FIXME: Is it worth it? */
422 record_pending_block (objfile, block, opblock)
423 struct objfile* objfile;
425 struct pending_block *opblock;
427 register struct pending_block *pblock;
429 pblock = (struct pending_block *)
430 obstack_alloc (&objfile -> symbol_obstack, sizeof (struct pending_block));
431 pblock -> block = block;
434 pblock -> next = opblock -> next;
435 opblock -> next = pblock;
439 pblock -> next = pending_blocks;
440 pending_blocks = pblock;
444 /* Note that this is only used in this file and in dstread.c, which should be
445 fixed to not need direct access to this function. When that is done, it can
446 be made static again. */
449 make_blockvector (objfile)
450 struct objfile *objfile;
452 register struct pending_block *next;
453 register struct blockvector *blockvector;
456 /* Count the length of the list of blocks. */
458 for (next = pending_blocks, i = 0; next; next = next->next, i++) {;}
460 blockvector = (struct blockvector *)
461 obstack_alloc (&objfile -> symbol_obstack,
462 (sizeof (struct blockvector)
463 + (i - 1) * sizeof (struct block *)));
465 /* Copy the blocks into the blockvector.
466 This is done in reverse order, which happens to put
467 the blocks into the proper order (ascending starting address).
468 finish_block has hair to insert each block into the list
469 after its subblocks in order to make sure this is true. */
471 BLOCKVECTOR_NBLOCKS (blockvector) = i;
472 for (next = pending_blocks; next; next = next->next)
474 BLOCKVECTOR_BLOCK (blockvector, --i) = next->block;
477 #if 0 /* Now we make the links in the obstack, so don't free them. */
478 /* Now free the links of the list, and empty the list. */
480 for (next = pending_blocks; next; next = next1)
486 pending_blocks = NULL;
488 #if 1 /* FIXME, shut this off after a while to speed up symbol reading. */
489 /* Some compilers output blocks in the wrong order, but we depend
490 on their being in the right order so we can binary search.
491 Check the order and moan about it. FIXME. */
492 if (BLOCKVECTOR_NBLOCKS (blockvector) > 1)
494 for (i = 1; i < BLOCKVECTOR_NBLOCKS (blockvector); i++)
496 if (BLOCK_START(BLOCKVECTOR_BLOCK (blockvector, i-1))
497 > BLOCK_START(BLOCKVECTOR_BLOCK (blockvector, i)))
500 /* FIXME-32x64: loses if CORE_ADDR doesn't fit in a
501 long. Possible solutions include a version of
502 complain which takes a callback, a
503 sprintf_address_numeric to match
504 print_address_numeric, or a way to set up a GDB_FILE
505 * which causes sprintf rather than fprintf to be
508 complain (&blockvector_complaint,
509 (unsigned long) BLOCK_START(BLOCKVECTOR_BLOCK (blockvector, i)));
515 return (blockvector);
519 /* Start recording information about source code that came from an included
520 (or otherwise merged-in) source file with a different name. NAME is
521 the name of the file (cannot be NULL), DIRNAME is the directory in which
522 it resides (or NULL if not known). */
525 start_subfile (name, dirname)
529 register struct subfile *subfile;
531 /* See if this subfile is already known as a subfile of the
532 current main source file. */
534 for (subfile = subfiles; subfile; subfile = subfile->next)
536 if (STREQ (subfile->name, name))
538 current_subfile = subfile;
543 /* This subfile is not known. Add an entry for it.
544 Make an entry for this subfile in the list of all subfiles
545 of the current main source file. */
547 subfile = (struct subfile *) xmalloc (sizeof (struct subfile));
548 subfile->next = subfiles;
550 current_subfile = subfile;
552 /* Save its name and compilation directory name */
553 subfile->name = (name == NULL) ? NULL : savestring (name, strlen (name));
555 (dirname == NULL) ? NULL : savestring (dirname, strlen (dirname));
557 /* Initialize line-number recording for this subfile. */
558 subfile->line_vector = NULL;
560 /* Default the source language to whatever can be deduced from
561 the filename. If nothing can be deduced (such as for a C/C++
562 include file with a ".h" extension), then inherit whatever
563 language the previous subfile had. This kludgery is necessary
564 because there is no standard way in some object formats to
565 record the source language. Also, when symtabs are allocated
566 we try to deduce a language then as well, but it is too late
567 for us to use that information while reading symbols, since
568 symtabs aren't allocated until after all the symbols have
569 been processed for a given source file. */
571 subfile->language = deduce_language_from_filename (subfile->name);
572 if (subfile->language == language_unknown &&
573 subfile->next != NULL)
575 subfile->language = subfile->next->language;
578 /* Initialize the debug format string to NULL. We may supply it
579 later via a call to record_debugformat. */
580 subfile->debugformat = NULL;
582 /* cfront output is a C program, so in most ways it looks like a C
583 program. But to demangle we need to set the language to C++. We
584 can distinguish cfront code by the fact that it has #line
585 directives which specify a file name ending in .C.
587 So if the filename of this subfile ends in .C, then change the language
588 of any pending subfiles from C to C++. We also accept any other C++
589 suffixes accepted by deduce_language_from_filename (in particular,
590 some people use .cxx with cfront). */
591 /* Likewise for f2c. */
596 enum language sublang = deduce_language_from_filename (subfile->name);
598 if (sublang == language_cplus || sublang == language_fortran)
599 for (s = subfiles; s != NULL; s = s->next)
600 if (s->language == language_c)
601 s->language = sublang;
604 /* And patch up this file if necessary. */
605 if (subfile->language == language_c
606 && subfile->next != NULL
607 && (subfile->next->language == language_cplus
608 || subfile->next->language == language_fortran))
610 subfile->language = subfile->next->language;
614 /* For stabs readers, the first N_SO symbol is assumed to be the source
615 file name, and the subfile struct is initialized using that assumption.
616 If another N_SO symbol is later seen, immediately following the first
617 one, then the first one is assumed to be the directory name and the
618 second one is really the source file name.
620 So we have to patch up the subfile struct by moving the old name value to
621 dirname and remembering the new name. Some sanity checking is performed
622 to ensure that the state of the subfile struct is reasonable and that the
623 old name we are assuming to be a directory name actually is (by checking
624 for a trailing '/'). */
627 patch_subfile_names (subfile, name)
628 struct subfile *subfile;
631 if (subfile != NULL && subfile->dirname == NULL && subfile->name != NULL
632 && subfile->name[strlen(subfile->name)-1] == '/')
634 subfile->dirname = subfile->name;
635 subfile->name = savestring (name, strlen (name));
636 last_source_file = name;
638 /* Default the source language to whatever can be deduced from
639 the filename. If nothing can be deduced (such as for a C/C++
640 include file with a ".h" extension), then inherit whatever
641 language the previous subfile had. This kludgery is necessary
642 because there is no standard way in some object formats to
643 record the source language. Also, when symtabs are allocated
644 we try to deduce a language then as well, but it is too late
645 for us to use that information while reading symbols, since
646 symtabs aren't allocated until after all the symbols have
647 been processed for a given source file. */
649 subfile->language = deduce_language_from_filename (subfile->name);
650 if (subfile->language == language_unknown &&
651 subfile->next != NULL)
653 subfile->language = subfile->next->language;
659 /* Handle the N_BINCL and N_EINCL symbol types
660 that act like N_SOL for switching source files
661 (different subfiles, as we call them) within one object file,
662 but using a stack rather than in an arbitrary order. */
667 register struct subfile_stack *tem
668 = (struct subfile_stack *) xmalloc (sizeof (struct subfile_stack));
670 tem->next = subfile_stack;
672 if (current_subfile == NULL || current_subfile->name == NULL)
676 tem->name = current_subfile->name;
683 register struct subfile_stack *link = subfile_stack;
690 subfile_stack = link->next;
696 /* Add a linetable entry for line number LINE and address PC to the line
697 vector for SUBFILE. */
700 record_line (subfile, line, pc)
701 register struct subfile *subfile;
705 struct linetable_entry *e;
706 /* Ignore the dummy line number in libg.o */
713 /* Make sure line vector exists and is big enough. */
714 if (!subfile->line_vector)
716 subfile->line_vector_length = INITIAL_LINE_VECTOR_LENGTH;
717 subfile->line_vector = (struct linetable *)
718 xmalloc (sizeof (struct linetable)
719 + subfile->line_vector_length * sizeof (struct linetable_entry));
720 subfile->line_vector->nitems = 0;
721 have_line_numbers = 1;
724 if (subfile->line_vector->nitems + 1 >= subfile->line_vector_length)
726 subfile->line_vector_length *= 2;
727 subfile->line_vector = (struct linetable *)
728 xrealloc ((char *) subfile->line_vector, (sizeof (struct linetable)
729 + subfile->line_vector_length * sizeof (struct linetable_entry)));
732 e = subfile->line_vector->item + subfile->line_vector->nitems++;
733 e->line = line; e->pc = pc;
737 /* Needed in order to sort line tables from IBM xcoff files. Sigh! */
740 compare_line_numbers (ln1p, ln2p)
744 struct linetable_entry *ln1 = (struct linetable_entry *) ln1p;
745 struct linetable_entry *ln2 = (struct linetable_entry *) ln2p;
747 /* Note: this code does not assume that CORE_ADDRs can fit in ints.
748 Please keep it that way. */
749 if (ln1->pc < ln2->pc)
752 if (ln1->pc > ln2->pc)
755 /* If pc equal, sort by line. I'm not sure whether this is optimum
756 behavior (see comment at struct linetable in symtab.h). */
757 return ln1->line - ln2->line;
761 /* Start a new symtab for a new source file.
762 Called, for example, when a stabs symbol of type N_SO is seen, or when
763 a DWARF TAG_compile_unit DIE is seen.
764 It indicates the start of data for one original source file. */
767 start_symtab (name, dirname, start_addr)
770 CORE_ADDR start_addr;
773 last_source_file = name;
774 last_source_start_addr = start_addr;
776 global_symbols = NULL;
778 have_line_numbers = 0;
780 /* Context stack is initially empty. Allocate first one with room for
781 10 levels; reuse it forever afterward. */
782 if (context_stack == NULL)
784 context_stack_size = INITIAL_CONTEXT_STACK_SIZE;
785 context_stack = (struct context_stack *)
786 xmalloc (context_stack_size * sizeof (struct context_stack));
788 context_stack_depth = 0;
790 /* Initialize the list of sub source files with one entry
791 for this file (the top-level source file). */
794 current_subfile = NULL;
795 start_subfile (name, dirname);
798 /* Finish the symbol definitions for one main source file,
799 close off all the lexical contexts for that file
800 (creating struct block's for them), then make the struct symtab
801 for that file and put it in the list of all such.
803 END_ADDR is the address of the end of the file's text.
804 SECTION is the section number (in objfile->section_offsets) of
805 the blockvector and linetable.
807 Note that it is possible for end_symtab() to return NULL. In particular,
808 for the DWARF case at least, it will return NULL when it finds a
809 compilation unit that has exactly one DIE, a TAG_compile_unit DIE. This
810 can happen when we link in an object file that was compiled from an empty
811 source file. Returning NULL is probably not the correct thing to do,
812 because then gdb will never know about this empty file (FIXME). */
815 end_symtab (end_addr, objfile, section)
817 struct objfile *objfile;
820 register struct symtab *symtab = NULL;
821 register struct blockvector *blockvector;
822 register struct subfile *subfile;
823 register struct context_stack *cstk;
824 struct subfile *nextsub;
826 /* Finish the lexical context of the last function in the file;
827 pop the context stack. */
829 if (context_stack_depth > 0)
831 cstk = pop_context();
832 /* Make a block for the local symbols within. */
833 finish_block (cstk->name, &local_symbols, cstk->old_blocks,
834 cstk->start_addr, end_addr, objfile);
836 if (context_stack_depth > 0)
838 /* This is said to happen with SCO. The old coffread.c code
839 simply emptied the context stack, so we do the same. FIXME:
840 Find out why it is happening. This is not believed to happen
841 in most cases (even for coffread.c); it used to be an abort(). */
842 static struct complaint msg =
843 {"Context stack not empty in end_symtab", 0, 0};
845 context_stack_depth = 0;
849 /* Reordered executables may have out of order pending blocks; if
850 OBJF_REORDERED is true, then sort the pending blocks. */
851 if ((objfile->flags & OBJF_REORDERED) && pending_blocks)
853 /* FIXME! Remove this horrid bubble sort and use merge sort!!! */
857 struct pending_block *pb, *pbnext;
865 /* swap blocks if unordered! */
867 if (BLOCK_START(pb->block) < BLOCK_START(pbnext->block))
869 struct block *tmp = pb->block;
870 pb->block = pbnext->block;
875 pbnext = pbnext->next;
880 /* Cleanup any undefined types that have been left hanging around
881 (this needs to be done before the finish_blocks so that
882 file_symbols is still good).
884 Both cleanup_undefined_types and finish_global_stabs are stabs
885 specific, but harmless for other symbol readers, since on gdb
886 startup or when finished reading stabs, the state is set so these
887 are no-ops. FIXME: Is this handled right in case of QUIT? Can
888 we make this cleaner? */
890 cleanup_undefined_types ();
891 finish_global_stabs (objfile);
893 if (pending_blocks == NULL
894 && file_symbols == NULL
895 && global_symbols == NULL
896 && have_line_numbers == 0)
898 /* Ignore symtabs that have no functions with real debugging info */
903 /* Define the STATIC_BLOCK & GLOBAL_BLOCK, and build the blockvector. */
904 finish_block (0, &file_symbols, 0, last_source_start_addr, end_addr,
906 finish_block (0, &global_symbols, 0, last_source_start_addr, end_addr,
908 blockvector = make_blockvector (objfile);
911 #ifdef PROCESS_LINENUMBER_HOOK
912 PROCESS_LINENUMBER_HOOK (); /* Needed for xcoff. */
915 /* Now create the symtab objects proper, one for each subfile. */
916 /* (The main file is the last one on the chain.) */
918 for (subfile = subfiles; subfile; subfile = nextsub)
920 int linetablesize = 0;
921 /* If we have blocks of symbols, make a symtab.
922 Otherwise, just ignore this file and any line number info in it. */
926 if (subfile->line_vector)
928 linetablesize = sizeof (struct linetable) +
929 subfile->line_vector->nitems * sizeof (struct linetable_entry);
931 /* I think this is artifact from before it went on the obstack.
932 I doubt we'll need the memory between now and when we
933 free it later in this function. */
934 /* First, shrink the linetable to make more memory. */
935 subfile->line_vector = (struct linetable *)
936 xrealloc ((char *) subfile->line_vector, linetablesize);
939 /* Like the pending blocks, the line table may be scrambled
940 in reordered executables. Sort it if OBJF_REORDERED is
942 if (objfile->flags & OBJF_REORDERED)
943 qsort (subfile->line_vector->item,
944 subfile->line_vector->nitems,
945 sizeof (struct linetable_entry), compare_line_numbers);
948 /* Now, allocate a symbol table. */
949 symtab = allocate_symtab (subfile->name, objfile);
951 /* Fill in its components. */
952 symtab->blockvector = blockvector;
953 if (subfile->line_vector)
955 /* Reallocate the line table on the symbol obstack */
956 symtab->linetable = (struct linetable *)
957 obstack_alloc (&objfile -> symbol_obstack, linetablesize);
958 memcpy (symtab->linetable, subfile->line_vector, linetablesize);
962 symtab->linetable = NULL;
964 symtab->block_line_section = section;
965 if (subfile->dirname)
967 /* Reallocate the dirname on the symbol obstack */
968 symtab->dirname = (char *)
969 obstack_alloc (&objfile -> symbol_obstack,
970 strlen (subfile -> dirname) + 1);
971 strcpy (symtab->dirname, subfile->dirname);
975 symtab->dirname = NULL;
977 symtab->free_code = free_linetable;
978 symtab->free_ptr = NULL;
980 /* Use whatever language we have been using for this subfile,
981 not the one that was deduced in allocate_symtab from the
982 filename. We already did our own deducing when we created
983 the subfile, and we may have altered our opinion of what
984 language it is from things we found in the symbols. */
985 symtab->language = subfile->language;
987 /* Save the debug format string (if any) in the symtab */
988 if (subfile -> debugformat != NULL)
990 symtab->debugformat = obsavestring (subfile->debugformat,
991 strlen (subfile->debugformat),
992 &objfile -> symbol_obstack);
995 /* All symtabs for the main file and the subfiles share a
996 blockvector, so we need to clear primary for everything but
1001 if (subfile->name != NULL)
1003 free ((PTR) subfile->name);
1005 if (subfile->dirname != NULL)
1007 free ((PTR) subfile->dirname);
1009 if (subfile->line_vector != NULL)
1011 free ((PTR) subfile->line_vector);
1013 if (subfile->debugformat != NULL)
1015 free ((PTR) subfile->debugformat);
1018 nextsub = subfile->next;
1019 free ((PTR)subfile);
1022 /* Set this for the main source file. */
1025 symtab->primary = 1;
1028 last_source_file = NULL;
1029 current_subfile = NULL;
1035 /* Push a context block. Args are an identifying nesting level (checkable
1036 when you pop it), and the starting PC address of this context. */
1038 struct context_stack *
1039 push_context (desc, valu)
1043 register struct context_stack *new;
1045 if (context_stack_depth == context_stack_size)
1047 context_stack_size *= 2;
1048 context_stack = (struct context_stack *)
1049 xrealloc ((char *) context_stack,
1050 (context_stack_size * sizeof (struct context_stack)));
1053 new = &context_stack[context_stack_depth++];
1055 new->locals = local_symbols;
1056 new->old_blocks = pending_blocks;
1057 new->start_addr = valu;
1060 local_symbols = NULL;
1066 /* Compute a small integer hash code for the given name. */
1072 register char *p = name;
1073 register int total = p[0];
1088 /* Ensure result is positive. */
1091 total += (1000 << 6);
1093 return (total % HASHSIZE);
1098 record_debugformat (format)
1101 current_subfile -> debugformat = savestring (format, strlen (format));
1105 /* Initialize anything that needs initializing when starting to read
1106 a fresh piece of a symbol file, e.g. reading in the stuff corresponding
1112 free_pendings = NULL;
1113 file_symbols = NULL;
1114 global_symbols = NULL;
1115 pending_blocks = NULL;
1118 /* Initialize anything that needs initializing when a completely new
1119 symbol file is specified (not just adding some symbols from another
1120 file, e.g. a shared library). */
1123 buildsym_new_init ()
1128 /* Initializer for this module */
1131 _initialize_buildsym ()