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
;
60 compare_line_numbers
PARAMS ((const void *, const void *));
63 /* Initial sizes of data structures. These are realloc'd larger if needed,
64 and realloc'd down to the size actually used, when completed. */
66 #define INITIAL_CONTEXT_STACK_SIZE 10
67 #define INITIAL_LINE_VECTOR_LENGTH 1000
70 /* Complaints about the symbols we have encountered. */
72 struct complaint block_end_complaint
=
73 {"block end address less than block start address in %s (patched it)", 0, 0};
75 struct complaint anon_block_end_complaint
=
76 {"block end address 0x%lx less than block start address 0x%lx (patched it)", 0, 0};
78 struct complaint innerblock_complaint
=
79 {"inner block not inside outer block in %s", 0, 0};
81 struct complaint innerblock_anon_complaint
=
82 {"inner block (0x%lx-0x%lx) not inside outer block (0x%lx-0x%lx)", 0, 0};
84 struct complaint blockvector_complaint
=
85 {"block at 0x%lx out of order", 0, 0};
88 /* maintain the lists of symbols and blocks */
90 /* Add a symbol to one of the lists of symbols. */
93 add_symbol_to_list (symbol
, listhead
)
94 struct symbol
*symbol
;
95 struct pending
**listhead
;
97 register struct pending
*link
;
99 /* We keep PENDINGSIZE symbols in each link of the list.
100 If we don't have a link with room in it, add a new link. */
101 if (*listhead
== NULL
|| (*listhead
)->nsyms
== PENDINGSIZE
)
105 link
= free_pendings
;
106 free_pendings
= link
->next
;
110 link
= (struct pending
*) xmalloc (sizeof (struct pending
));
113 link
->next
= *listhead
;
118 (*listhead
)->symbol
[(*listhead
)->nsyms
++] = symbol
;
121 /* Find a symbol named NAME on a LIST. NAME need not be '\0'-terminated;
122 LENGTH is the length of the name. */
125 find_symbol_in_list (list
, name
, length
)
126 struct pending
*list
;
135 for (j
= list
->nsyms
; --j
>= 0; )
137 pp
= SYMBOL_NAME (list
->symbol
[j
]);
138 if (*pp
== *name
&& strncmp (pp
, name
, length
) == 0 &&
141 return (list
->symbol
[j
]);
149 /* At end of reading syms, or in case of quit,
150 really free as many `struct pending's as we can easily find. */
154 really_free_pendings (foo
)
157 struct pending
*next
, *next1
;
159 for (next
= free_pendings
; next
; next
= next1
)
164 free_pendings
= NULL
;
166 free_pending_blocks ();
168 for (next
= file_symbols
; next
!= NULL
; next
= next1
)
175 for (next
= global_symbols
; next
!= NULL
; next
= next1
)
180 global_symbols
= NULL
;
183 /* This function is called to discard any pending blocks. */
186 free_pending_blocks ()
188 #if 0 /* Now we make the links in the symbol_obstack, so don't free them. */
189 struct pending_block
*bnext
, *bnext1
;
191 for (bnext
= pending_blocks
; bnext
; bnext
= bnext1
)
193 bnext1
= bnext
->next
;
197 pending_blocks
= NULL
;
200 /* Take one of the lists of symbols and make a block from it.
201 Keep the order the symbols have in the list (reversed from the input file).
202 Put the block on the list of pending blocks. */
205 finish_block (symbol
, listhead
, old_blocks
, start
, end
, objfile
)
206 struct symbol
*symbol
;
207 struct pending
**listhead
;
208 struct pending_block
*old_blocks
;
209 CORE_ADDR start
, end
;
210 struct objfile
*objfile
;
212 register struct pending
*next
, *next1
;
213 register struct block
*block
;
214 register struct pending_block
*pblock
;
215 struct pending_block
*opblock
;
219 /* Count the length of the list of symbols. */
221 for (next
= *listhead
, i
= 0;
223 i
+= next
->nsyms
, next
= next
->next
)
228 block
= (struct block
*) obstack_alloc (&objfile
-> symbol_obstack
,
229 (sizeof (struct block
) + ((i
- 1) * sizeof (struct symbol
*))));
231 /* Copy the symbols into the block. */
233 BLOCK_NSYMS (block
) = i
;
234 for (next
= *listhead
; next
; next
= next
->next
)
236 for (j
= next
->nsyms
- 1; j
>= 0; j
--)
238 BLOCK_SYM (block
, --i
) = next
->symbol
[j
];
242 BLOCK_START (block
) = start
;
243 BLOCK_END (block
) = end
;
244 /* Superblock filled in when containing block is made */
245 BLOCK_SUPERBLOCK (block
) = NULL
;
246 BLOCK_GCC_COMPILED (block
) = processing_gcc_compilation
;
248 /* Put the block in as the value of the symbol that names it. */
252 struct type
*ftype
= SYMBOL_TYPE (symbol
);
253 SYMBOL_BLOCK_VALUE (symbol
) = block
;
254 BLOCK_FUNCTION (block
) = symbol
;
256 if (TYPE_NFIELDS (ftype
) <= 0)
258 /* No parameter type information is recorded with the function's
259 type. Set that from the type of the parameter symbols. */
260 int nparams
= 0, iparams
;
262 for (i
= 0; i
< BLOCK_NSYMS (block
); i
++)
264 sym
= BLOCK_SYM (block
, i
);
265 switch (SYMBOL_CLASS (sym
))
270 case LOC_REGPARM_ADDR
:
281 case LOC_CONST_BYTES
:
284 case LOC_BASEREG_ARG
:
286 case LOC_OPTIMIZED_OUT
:
293 TYPE_NFIELDS (ftype
) = nparams
;
294 TYPE_FIELDS (ftype
) = (struct field
*)
295 TYPE_ALLOC (ftype
, nparams
* sizeof (struct field
));
297 for (i
= iparams
= 0; iparams
< nparams
; i
++)
299 sym
= BLOCK_SYM (block
, i
);
300 switch (SYMBOL_CLASS (sym
))
305 case LOC_REGPARM_ADDR
:
306 TYPE_FIELD_TYPE (ftype
, iparams
) = SYMBOL_TYPE (sym
);
317 case LOC_CONST_BYTES
:
320 case LOC_BASEREG_ARG
:
322 case LOC_OPTIMIZED_OUT
:
332 BLOCK_FUNCTION (block
) = NULL
;
335 /* Now "free" the links of the list, and empty the list. */
337 for (next
= *listhead
; next
; next
= next1
)
340 next
->next
= free_pendings
;
341 free_pendings
= next
;
346 /* Check to be sure that the blocks have an end address that is
347 greater than starting address */
349 if (BLOCK_END (block
) < BLOCK_START (block
))
353 complain (&block_end_complaint
, SYMBOL_SOURCE_NAME (symbol
));
357 complain (&anon_block_end_complaint
, BLOCK_END (block
), BLOCK_START (block
));
359 /* Better than nothing */
360 BLOCK_END (block
) = BLOCK_START (block
);
364 /* Install this block as the superblock
365 of all blocks made since the start of this scope
366 that don't have superblocks yet. */
369 for (pblock
= pending_blocks
; pblock
!= old_blocks
; pblock
= pblock
->next
)
371 if (BLOCK_SUPERBLOCK (pblock
->block
) == NULL
)
374 /* Check to be sure the blocks are nested as we receive them.
375 If the compiler/assembler/linker work, this just burns a small
377 if (BLOCK_START (pblock
->block
) < BLOCK_START (block
) ||
378 BLOCK_END (pblock
->block
) > BLOCK_END (block
))
382 complain (&innerblock_complaint
,
383 SYMBOL_SOURCE_NAME (symbol
));
387 complain (&innerblock_anon_complaint
, BLOCK_START (pblock
->block
),
388 BLOCK_END (pblock
->block
), BLOCK_START (block
),
391 BLOCK_START (pblock
->block
) = BLOCK_START (block
);
392 BLOCK_END (pblock
->block
) = BLOCK_END (block
);
395 BLOCK_SUPERBLOCK (pblock
->block
) = block
;
400 record_pending_block (objfile
, block
, opblock
);
403 /* Record BLOCK on the list of all blocks in the file. Put it after
404 OPBLOCK, or at the beginning if opblock is NULL. This puts the block
405 in the list after all its subblocks.
407 Allocate the pending block struct in the symbol_obstack to save
408 time. This wastes a little space. FIXME: Is it worth it? */
411 record_pending_block (objfile
, block
, opblock
)
412 struct objfile
* objfile
;
414 struct pending_block
*opblock
;
416 register struct pending_block
*pblock
;
418 pblock
= (struct pending_block
*)
419 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct pending_block
));
420 pblock
-> block
= block
;
423 pblock
-> next
= opblock
-> next
;
424 opblock
-> next
= pblock
;
428 pblock
-> next
= pending_blocks
;
429 pending_blocks
= pblock
;
433 /* Note that this is only used in this file and in dstread.c, which should be
434 fixed to not need direct access to this function. When that is done, it can
435 be made static again. */
438 make_blockvector (objfile
)
439 struct objfile
*objfile
;
441 register struct pending_block
*next
;
442 register struct blockvector
*blockvector
;
445 /* Count the length of the list of blocks. */
447 for (next
= pending_blocks
, i
= 0; next
; next
= next
->next
, i
++) {;}
449 blockvector
= (struct blockvector
*)
450 obstack_alloc (&objfile
-> symbol_obstack
,
451 (sizeof (struct blockvector
)
452 + (i
- 1) * sizeof (struct block
*)));
454 /* Copy the blocks into the blockvector.
455 This is done in reverse order, which happens to put
456 the blocks into the proper order (ascending starting address).
457 finish_block has hair to insert each block into the list
458 after its subblocks in order to make sure this is true. */
460 BLOCKVECTOR_NBLOCKS (blockvector
) = i
;
461 for (next
= pending_blocks
; next
; next
= next
->next
)
463 BLOCKVECTOR_BLOCK (blockvector
, --i
) = next
->block
;
466 #if 0 /* Now we make the links in the obstack, so don't free them. */
467 /* Now free the links of the list, and empty the list. */
469 for (next
= pending_blocks
; next
; next
= next1
)
475 pending_blocks
= NULL
;
477 #if 1 /* FIXME, shut this off after a while to speed up symbol reading. */
478 /* Some compilers output blocks in the wrong order, but we depend
479 on their being in the right order so we can binary search.
480 Check the 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
);
508 /* Start recording information about source code that came from an included
509 (or otherwise merged-in) source file with a different name. NAME is
510 the name of the file (cannot be NULL), DIRNAME is the directory in which
511 it resides (or NULL if not known). */
514 start_subfile (name
, dirname
)
518 register struct subfile
*subfile
;
520 /* See if this subfile is already known as a subfile of the
521 current main source file. */
523 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
525 if (STREQ (subfile
->name
, name
))
527 current_subfile
= subfile
;
532 /* This subfile is not known. Add an entry for it.
533 Make an entry for this subfile in the list of all subfiles
534 of the current main source file. */
536 subfile
= (struct subfile
*) xmalloc (sizeof (struct subfile
));
537 subfile
->next
= subfiles
;
539 current_subfile
= subfile
;
541 /* Save its name and compilation directory name */
542 subfile
->name
= (name
== NULL
) ? NULL
: savestring (name
, strlen (name
));
544 (dirname
== NULL
) ? NULL
: savestring (dirname
, strlen (dirname
));
546 /* Initialize line-number recording for this subfile. */
547 subfile
->line_vector
= NULL
;
549 /* Default the source language to whatever can be deduced from
550 the filename. If nothing can be deduced (such as for a C/C++
551 include file with a ".h" extension), then inherit whatever
552 language the previous subfile had. This kludgery is necessary
553 because there is no standard way in some object formats to
554 record the source language. Also, when symtabs are allocated
555 we try to deduce a language then as well, but it is too late
556 for us to use that information while reading symbols, since
557 symtabs aren't allocated until after all the symbols have
558 been processed for a given source file. */
560 subfile
->language
= deduce_language_from_filename (subfile
->name
);
561 if (subfile
->language
== language_unknown
&&
562 subfile
->next
!= NULL
)
564 subfile
->language
= subfile
->next
->language
;
567 /* cfront output is a C program, so in most ways it looks like a C
568 program. But to demangle we need to set the language to C++. We
569 can distinguish cfront code by the fact that it has #line
570 directives which specify a file name ending in .C.
572 So if the filename of this subfile ends in .C, then change the language
573 of any pending subfiles from C to C++. We also accept any other C++
574 suffixes accepted by deduce_language_from_filename (in particular,
575 some people use .cxx with cfront). */
576 /* Likewise for f2c. */
581 enum language sublang
= deduce_language_from_filename (subfile
->name
);
583 if (sublang
== language_cplus
|| sublang
== language_fortran
)
584 for (s
= subfiles
; s
!= NULL
; s
= s
->next
)
585 if (s
->language
== language_c
)
586 s
->language
= sublang
;
589 /* And patch up this file if necessary. */
590 if (subfile
->language
== language_c
591 && subfile
->next
!= NULL
592 && (subfile
->next
->language
== language_cplus
593 || subfile
->next
->language
== language_fortran
))
595 subfile
->language
= subfile
->next
->language
;
599 /* For stabs readers, the first N_SO symbol is assumed to be the source
600 file name, and the subfile struct is initialized using that assumption.
601 If another N_SO symbol is later seen, immediately following the first
602 one, then the first one is assumed to be the directory name and the
603 second one is really the source file name.
605 So we have to patch up the subfile struct by moving the old name value to
606 dirname and remembering the new name. Some sanity checking is performed
607 to ensure that the state of the subfile struct is reasonable and that the
608 old name we are assuming to be a directory name actually is (by checking
609 for a trailing '/'). */
612 patch_subfile_names (subfile
, name
)
613 struct subfile
*subfile
;
616 if (subfile
!= NULL
&& subfile
->dirname
== NULL
&& subfile
->name
!= NULL
617 && subfile
->name
[strlen(subfile
->name
)-1] == '/')
619 subfile
->dirname
= subfile
->name
;
620 subfile
->name
= savestring (name
, strlen (name
));
621 last_source_file
= name
;
623 /* Default the source language to whatever can be deduced from
624 the filename. If nothing can be deduced (such as for a C/C++
625 include file with a ".h" extension), then inherit whatever
626 language the previous subfile had. This kludgery is necessary
627 because there is no standard way in some object formats to
628 record the source language. Also, when symtabs are allocated
629 we try to deduce a language then as well, but it is too late
630 for us to use that information while reading symbols, since
631 symtabs aren't allocated until after all the symbols have
632 been processed for a given source file. */
634 subfile
->language
= deduce_language_from_filename (subfile
->name
);
635 if (subfile
->language
== language_unknown
&&
636 subfile
->next
!= NULL
)
638 subfile
->language
= subfile
->next
->language
;
644 /* Handle the N_BINCL and N_EINCL symbol types
645 that act like N_SOL for switching source files
646 (different subfiles, as we call them) within one object file,
647 but using a stack rather than in an arbitrary order. */
652 register struct subfile_stack
*tem
653 = (struct subfile_stack
*) xmalloc (sizeof (struct subfile_stack
));
655 tem
->next
= subfile_stack
;
657 if (current_subfile
== NULL
|| current_subfile
->name
== NULL
)
661 tem
->name
= current_subfile
->name
;
668 register struct subfile_stack
*link
= subfile_stack
;
675 subfile_stack
= link
->next
;
681 /* Add a linetable entry for line number LINE and address PC to the line
682 vector for SUBFILE. */
685 record_line (subfile
, line
, pc
)
686 register struct subfile
*subfile
;
690 struct linetable_entry
*e
;
691 /* Ignore the dummy line number in libg.o */
698 /* Make sure line vector exists and is big enough. */
699 if (!subfile
->line_vector
)
701 subfile
->line_vector_length
= INITIAL_LINE_VECTOR_LENGTH
;
702 subfile
->line_vector
= (struct linetable
*)
703 xmalloc (sizeof (struct linetable
)
704 + subfile
->line_vector_length
* sizeof (struct linetable_entry
));
705 subfile
->line_vector
->nitems
= 0;
708 if (subfile
->line_vector
->nitems
+ 1 >= subfile
->line_vector_length
)
710 subfile
->line_vector_length
*= 2;
711 subfile
->line_vector
= (struct linetable
*)
712 xrealloc ((char *) subfile
->line_vector
, (sizeof (struct linetable
)
713 + subfile
->line_vector_length
* sizeof (struct linetable_entry
)));
716 e
= subfile
->line_vector
->item
+ subfile
->line_vector
->nitems
++;
717 e
->line
= line
; e
->pc
= pc
;
721 /* Needed in order to sort line tables from IBM xcoff files. Sigh! */
724 compare_line_numbers (ln1p
, ln2p
)
728 struct linetable_entry
*ln1
= (struct linetable_entry
*) ln1p
;
729 struct linetable_entry
*ln2
= (struct linetable_entry
*) ln2p
;
731 /* Note: this code does not assume that CORE_ADDRs can fit in ints.
732 Please keep it that way. */
733 if (ln1
->pc
< ln2
->pc
)
736 if (ln1
->pc
> ln2
->pc
)
739 /* If pc equal, sort by line. I'm not sure whether this is optimum
740 behavior (see comment at struct linetable in symtab.h). */
741 return ln1
->line
- ln2
->line
;
745 /* Start a new symtab for a new source file.
746 Called, for example, when a stabs symbol of type N_SO is seen, or when
747 a DWARF TAG_compile_unit DIE is seen.
748 It indicates the start of data for one original source file. */
751 start_symtab (name
, dirname
, start_addr
)
754 CORE_ADDR start_addr
;
757 last_source_file
= name
;
758 last_source_start_addr
= start_addr
;
760 global_symbols
= NULL
;
763 /* Context stack is initially empty. Allocate first one with room for
764 10 levels; reuse it forever afterward. */
765 if (context_stack
== NULL
)
767 context_stack_size
= INITIAL_CONTEXT_STACK_SIZE
;
768 context_stack
= (struct context_stack
*)
769 xmalloc (context_stack_size
* sizeof (struct context_stack
));
771 context_stack_depth
= 0;
773 /* Initialize the list of sub source files with one entry
774 for this file (the top-level source file). */
777 current_subfile
= NULL
;
778 start_subfile (name
, dirname
);
781 /* Finish the symbol definitions for one main source file,
782 close off all the lexical contexts for that file
783 (creating struct block's for them), then make the struct symtab
784 for that file and put it in the list of all such.
786 END_ADDR is the address of the end of the file's text.
787 SECTION is the section number (in objfile->section_offsets) of
788 the blockvector and linetable.
790 Note that it is possible for end_symtab() to return NULL. In particular,
791 for the DWARF case at least, it will return NULL when it finds a
792 compilation unit that has exactly one DIE, a TAG_compile_unit DIE. This
793 can happen when we link in an object file that was compiled from an empty
794 source file. Returning NULL is probably not the correct thing to do,
795 because then gdb will never know about this empty file (FIXME). */
798 end_symtab (end_addr
, objfile
, section
)
800 struct objfile
*objfile
;
803 register struct symtab
*symtab
= NULL
;
804 register struct blockvector
*blockvector
;
805 register struct subfile
*subfile
;
806 register struct context_stack
*cstk
;
807 struct subfile
*nextsub
;
809 /* Finish the lexical context of the last function in the file;
810 pop the context stack. */
812 if (context_stack_depth
> 0)
814 context_stack_depth
--;
815 cstk
= &context_stack
[context_stack_depth
];
816 /* Make a block for the local symbols within. */
817 finish_block (cstk
->name
, &local_symbols
, cstk
->old_blocks
,
818 cstk
->start_addr
, end_addr
, objfile
);
820 if (context_stack_depth
> 0)
822 /* This is said to happen with SCO. The old coffread.c code
823 simply emptied the context stack, so we do the same. FIXME:
824 Find out why it is happening. This is not believed to happen
825 in most cases (even for coffread.c); it used to be an abort(). */
826 static struct complaint msg
=
827 {"Context stack not empty in end_symtab", 0, 0};
829 context_stack_depth
= 0;
833 /* Reordered executables may have out of order pending blocks; if
834 OBJF_REORDERED is true, then sort the pending blocks. */
835 if ((objfile
->flags
& OBJF_REORDERED
) && pending_blocks
)
837 /* FIXME! Remove this horrid bubble sort and use qsort!!!
838 It'd be a whole lot easier if they weren't in a linked list!!! */
842 struct pending_block
*pb
, *pbnext
;
850 /* swap blocks if unordered! */
852 if (BLOCK_START(pb
->block
) < BLOCK_START(pbnext
->block
))
854 struct block
*tmp
= pb
->block
;
855 pb
->block
= pbnext
->block
;
860 pbnext
= pbnext
->next
;
865 /* Cleanup any undefined types that have been left hanging around
866 (this needs to be done before the finish_blocks so that
867 file_symbols is still good).
869 Both cleanup_undefined_types and finish_global_stabs are stabs
870 specific, but harmless for other symbol readers, since on gdb
871 startup or when finished reading stabs, the state is set so these
872 are no-ops. FIXME: Is this handled right in case of QUIT? Can
873 we make this cleaner? */
875 cleanup_undefined_types ();
876 finish_global_stabs (objfile
);
878 if (pending_blocks
== NULL
879 && file_symbols
== NULL
880 && global_symbols
== NULL
)
882 /* Ignore symtabs that have no functions with real debugging info */
887 /* Define the STATIC_BLOCK & GLOBAL_BLOCK, and build the blockvector. */
888 finish_block (0, &file_symbols
, 0, last_source_start_addr
, end_addr
,
890 finish_block (0, &global_symbols
, 0, last_source_start_addr
, end_addr
,
892 blockvector
= make_blockvector (objfile
);
895 #ifdef PROCESS_LINENUMBER_HOOK
896 PROCESS_LINENUMBER_HOOK (); /* Needed for xcoff. */
899 /* Now create the symtab objects proper, one for each subfile. */
900 /* (The main file is the last one on the chain.) */
902 for (subfile
= subfiles
; subfile
; subfile
= nextsub
)
904 int linetablesize
= 0;
905 /* If we have blocks of symbols, make a symtab.
906 Otherwise, just ignore this file and any line number info in it. */
910 if (subfile
->line_vector
)
912 linetablesize
= sizeof (struct linetable
) +
913 subfile
->line_vector
->nitems
* sizeof (struct linetable_entry
);
915 /* I think this is artifact from before it went on the obstack.
916 I doubt we'll need the memory between now and when we
917 free it later in this function. */
918 /* First, shrink the linetable to make more memory. */
919 subfile
->line_vector
= (struct linetable
*)
920 xrealloc ((char *) subfile
->line_vector
, linetablesize
);
923 /* Like the pending blocks, the line table may be scrambled
924 in reordered executables. Sort it if OBJF_REORDERED is
926 if (objfile
->flags
& OBJF_REORDERED
)
927 qsort (subfile
->line_vector
->item
,
928 subfile
->line_vector
->nitems
,
929 sizeof (struct linetable_entry
), compare_line_numbers
);
932 /* Now, allocate a symbol table. */
933 symtab
= allocate_symtab (subfile
->name
, objfile
);
935 /* Fill in its components. */
936 symtab
->blockvector
= blockvector
;
937 if (subfile
->line_vector
)
939 /* Reallocate the line table on the symbol obstack */
940 symtab
->linetable
= (struct linetable
*)
941 obstack_alloc (&objfile
-> symbol_obstack
, linetablesize
);
942 memcpy (symtab
->linetable
, subfile
->line_vector
, linetablesize
);
946 symtab
->linetable
= NULL
;
948 symtab
->block_line_section
= section
;
949 if (subfile
->dirname
)
951 /* Reallocate the dirname on the symbol obstack */
952 symtab
->dirname
= (char *)
953 obstack_alloc (&objfile
-> symbol_obstack
,
954 strlen (subfile
-> dirname
) + 1);
955 strcpy (symtab
->dirname
, subfile
->dirname
);
959 symtab
->dirname
= NULL
;
961 symtab
->free_code
= free_linetable
;
962 symtab
->free_ptr
= NULL
;
964 /* Use whatever language we have been using for this subfile,
965 not the one that was deduced in allocate_symtab from the
966 filename. We already did our own deducing when we created
967 the subfile, and we may have altered our opinion of what
968 language it is from things we found in the symbols. */
969 symtab
->language
= subfile
->language
;
971 /* All symtabs for the main file and the subfiles share a
972 blockvector, so we need to clear primary for everything but
977 if (subfile
->name
!= NULL
)
979 free ((PTR
) subfile
->name
);
981 if (subfile
->dirname
!= NULL
)
983 free ((PTR
) subfile
->dirname
);
985 if (subfile
->line_vector
!= NULL
)
987 free ((PTR
) subfile
->line_vector
);
990 nextsub
= subfile
->next
;
994 /* Set this for the main source file. */
1000 last_source_file
= NULL
;
1001 current_subfile
= NULL
;
1007 /* Push a context block. Args are an identifying nesting level (checkable
1008 when you pop it), and the starting PC address of this context. */
1010 struct context_stack
*
1011 push_context (desc
, valu
)
1015 register struct context_stack
*new;
1017 if (context_stack_depth
== context_stack_size
)
1019 context_stack_size
*= 2;
1020 context_stack
= (struct context_stack
*)
1021 xrealloc ((char *) context_stack
,
1022 (context_stack_size
* sizeof (struct context_stack
)));
1025 new = &context_stack
[context_stack_depth
++];
1027 new->locals
= local_symbols
;
1028 new->old_blocks
= pending_blocks
;
1029 new->start_addr
= valu
;
1032 local_symbols
= NULL
;
1038 /* Compute a small integer hash code for the given name. */
1044 register char *p
= name
;
1045 register int total
= p
[0];
1060 /* Ensure result is positive. */
1063 total
+= (1000 << 6);
1065 return (total
% HASHSIZE
);
1069 /* Initialize anything that needs initializing when starting to read
1070 a fresh piece of a symbol file, e.g. reading in the stuff corresponding
1076 free_pendings
= NULL
;
1077 file_symbols
= NULL
;
1078 global_symbols
= NULL
;
1079 pending_blocks
= NULL
;
1082 /* Initialize anything that needs initializing when a completely new
1083 symbol file is specified (not just adding some symbols from another
1084 file, e.g. a shared library). */
1087 buildsym_new_init ()
1092 /* Initializer for this module */
1095 _initialize_buildsym ()