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 /* 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 otherwise empty
52 symtab from being tossed. */
54 static int have_line_numbers
;
57 compare_line_numbers
PARAMS ((const void *, const void *));
60 /* Initial sizes of data structures. These are realloc'd larger if needed,
61 and realloc'd down to the size actually used, when completed. */
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};
85 /* maintain the lists of symbols and blocks */
87 /* Add a symbol to one of the lists of symbols. */
90 add_symbol_to_list (symbol
, listhead
)
91 struct symbol
*symbol
;
92 struct pending
**listhead
;
94 register struct pending
*link
;
96 /* If this is an alias for another symbol, don't add it. */
97 if (symbol
->ginfo
.name
&& symbol
->ginfo
.name
[0] == '#')
100 /* We keep PENDINGSIZE symbols in each link of the list.
101 If we don't have a link with room in it, add a new link. */
102 if (*listhead
== NULL
|| (*listhead
)->nsyms
== PENDINGSIZE
)
106 link
= free_pendings
;
107 free_pendings
= link
->next
;
111 link
= (struct pending
*) xmalloc (sizeof (struct pending
));
114 link
->next
= *listhead
;
119 (*listhead
)->symbol
[(*listhead
)->nsyms
++] = symbol
;
122 /* Find a symbol named NAME on a LIST. NAME need not be '\0'-terminated;
123 LENGTH is the length of the name. */
126 find_symbol_in_list (list
, name
, length
)
127 struct pending
*list
;
136 for (j
= list
->nsyms
; --j
>= 0; )
138 pp
= SYMBOL_NAME (list
->symbol
[j
]);
139 if (*pp
== *name
&& strncmp (pp
, name
, length
) == 0 &&
142 return (list
->symbol
[j
]);
150 /* At end of reading syms, or in case of quit,
151 really free as many `struct pending's as we can easily find. */
155 really_free_pendings (foo
)
158 struct pending
*next
, *next1
;
160 for (next
= free_pendings
; next
; next
= next1
)
165 free_pendings
= NULL
;
167 free_pending_blocks ();
169 for (next
= file_symbols
; next
!= NULL
; next
= next1
)
176 for (next
= global_symbols
; next
!= NULL
; next
= next1
)
181 global_symbols
= NULL
;
184 /* This function is called to discard any pending blocks. */
187 free_pending_blocks ()
189 #if 0 /* Now we make the links in the symbol_obstack, so don't free them. */
190 struct pending_block
*bnext
, *bnext1
;
192 for (bnext
= pending_blocks
; bnext
; bnext
= bnext1
)
194 bnext1
= bnext
->next
;
198 pending_blocks
= NULL
;
201 /* Take one of the lists of symbols and make a block from it.
202 Keep the order the symbols have in the list (reversed from the input file).
203 Put the block on the list of pending blocks. */
206 finish_block (symbol
, listhead
, old_blocks
, start
, end
, objfile
)
207 struct symbol
*symbol
;
208 struct pending
**listhead
;
209 struct pending_block
*old_blocks
;
210 CORE_ADDR start
, end
;
211 struct objfile
*objfile
;
213 register struct pending
*next
, *next1
;
214 register struct block
*block
;
215 register struct pending_block
*pblock
;
216 struct pending_block
*opblock
;
220 /* Count the length of the list of symbols. */
222 for (next
= *listhead
, i
= 0;
224 i
+= next
->nsyms
, next
= next
->next
)
229 block
= (struct block
*) obstack_alloc (&objfile
-> symbol_obstack
,
230 (sizeof (struct block
) + ((i
- 1) * sizeof (struct symbol
*))));
232 /* Copy the symbols into the block. */
234 BLOCK_NSYMS (block
) = i
;
235 for (next
= *listhead
; next
; next
= next
->next
)
237 for (j
= next
->nsyms
- 1; j
>= 0; j
--)
239 BLOCK_SYM (block
, --i
) = next
->symbol
[j
];
243 BLOCK_START (block
) = start
;
244 BLOCK_END (block
) = end
;
245 /* Superblock filled in when containing block is made */
246 BLOCK_SUPERBLOCK (block
) = NULL
;
248 BLOCK_GCC_COMPILED (block
) = processing_gcc_compilation
;
250 /* Put the block in as the value of the symbol that names it. */
254 struct type
*ftype
= SYMBOL_TYPE (symbol
);
255 SYMBOL_BLOCK_VALUE (symbol
) = block
;
256 BLOCK_FUNCTION (block
) = symbol
;
258 if (TYPE_NFIELDS (ftype
) <= 0)
260 /* No parameter type information is recorded with the function's
261 type. Set that from the type of the parameter symbols. */
262 int nparams
= 0, iparams
;
264 for (i
= 0; i
< BLOCK_NSYMS (block
); i
++)
266 sym
= BLOCK_SYM (block
, i
);
267 switch (SYMBOL_CLASS (sym
))
272 case LOC_REGPARM_ADDR
:
273 case LOC_BASEREG_ARG
:
286 case LOC_CONST_BYTES
:
289 case LOC_OPTIMIZED_OUT
:
296 TYPE_NFIELDS (ftype
) = nparams
;
297 TYPE_FIELDS (ftype
) = (struct field
*)
298 TYPE_ALLOC (ftype
, nparams
* sizeof (struct field
));
300 for (i
= iparams
= 0; iparams
< nparams
; i
++)
302 sym
= BLOCK_SYM (block
, i
);
303 switch (SYMBOL_CLASS (sym
))
308 case LOC_REGPARM_ADDR
:
309 case LOC_BASEREG_ARG
:
311 TYPE_FIELD_TYPE (ftype
, iparams
) = SYMBOL_TYPE (sym
);
323 case LOC_CONST_BYTES
:
326 case LOC_OPTIMIZED_OUT
:
336 BLOCK_FUNCTION (block
) = NULL
;
339 /* Now "free" the links of the list, and empty the list. */
341 for (next
= *listhead
; next
; next
= next1
)
344 next
->next
= free_pendings
;
345 free_pendings
= next
;
350 /* Check to be sure that the blocks have an end address that is
351 greater than starting address */
353 if (BLOCK_END (block
) < BLOCK_START (block
))
357 complain (&block_end_complaint
, SYMBOL_SOURCE_NAME (symbol
));
361 complain (&anon_block_end_complaint
, BLOCK_END (block
), BLOCK_START (block
));
363 /* Better than nothing */
364 BLOCK_END (block
) = BLOCK_START (block
);
368 /* Install this block as the superblock
369 of all blocks made since the start of this scope
370 that don't have superblocks yet. */
373 for (pblock
= pending_blocks
; pblock
!= old_blocks
; pblock
= pblock
->next
)
375 if (BLOCK_SUPERBLOCK (pblock
->block
) == NULL
)
378 /* Check to be sure the blocks are nested as we receive them.
379 If the compiler/assembler/linker work, this just burns a small
381 if (BLOCK_START (pblock
->block
) < BLOCK_START (block
) ||
382 BLOCK_END (pblock
->block
) > BLOCK_END (block
))
386 complain (&innerblock_complaint
,
387 SYMBOL_SOURCE_NAME (symbol
));
391 complain (&innerblock_anon_complaint
, BLOCK_START (pblock
->block
),
392 BLOCK_END (pblock
->block
), BLOCK_START (block
),
395 if (BLOCK_START (pblock
->block
) < BLOCK_START (block
))
396 BLOCK_START (pblock
->block
) = BLOCK_START (block
);
397 if (BLOCK_END (pblock
->block
) > BLOCK_END (block
))
398 BLOCK_END (pblock
->block
) = BLOCK_END (block
);
401 BLOCK_SUPERBLOCK (pblock
->block
) = block
;
406 record_pending_block (objfile
, block
, opblock
);
409 /* Record BLOCK on the list of all blocks in the file. Put it after
410 OPBLOCK, or at the beginning if opblock is NULL. This puts the block
411 in the list after all its subblocks.
413 Allocate the pending block struct in the symbol_obstack to save
414 time. This wastes a little space. FIXME: Is it worth it? */
417 record_pending_block (objfile
, block
, opblock
)
418 struct objfile
* objfile
;
420 struct pending_block
*opblock
;
422 register struct pending_block
*pblock
;
424 pblock
= (struct pending_block
*)
425 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct pending_block
));
426 pblock
-> block
= block
;
429 pblock
-> next
= opblock
-> next
;
430 opblock
-> next
= pblock
;
434 pblock
-> next
= pending_blocks
;
435 pending_blocks
= pblock
;
439 /* Note that this is only used in this file and in dstread.c, which should be
440 fixed to not need direct access to this function. When that is done, it can
441 be made static again. */
444 make_blockvector (objfile
)
445 struct objfile
*objfile
;
447 register struct pending_block
*next
;
448 register struct blockvector
*blockvector
;
451 /* Count the length of the list of blocks. */
453 for (next
= pending_blocks
, i
= 0; next
; next
= next
->next
, i
++) {;}
455 blockvector
= (struct blockvector
*)
456 obstack_alloc (&objfile
-> symbol_obstack
,
457 (sizeof (struct blockvector
)
458 + (i
- 1) * sizeof (struct block
*)));
460 /* Copy the blocks into the blockvector.
461 This is done in reverse order, which happens to put
462 the blocks into the proper order (ascending starting address).
463 finish_block has hair to insert each block into the list
464 after its subblocks in order to make sure this is true. */
466 BLOCKVECTOR_NBLOCKS (blockvector
) = i
;
467 for (next
= pending_blocks
; next
; next
= next
->next
)
469 BLOCKVECTOR_BLOCK (blockvector
, --i
) = next
->block
;
472 #if 0 /* Now we make the links in the obstack, so don't free them. */
473 /* Now free the links of the list, and empty the list. */
475 for (next
= pending_blocks
; next
; next
= next1
)
481 pending_blocks
= NULL
;
483 #if 1 /* FIXME, shut this off after a while to speed up symbol reading. */
484 /* Some compilers output blocks in the wrong order, but we depend
485 on their being in the right order so we can binary search.
486 Check the order and moan about it. FIXME. */
487 if (BLOCKVECTOR_NBLOCKS (blockvector
) > 1)
489 for (i
= 1; i
< BLOCKVECTOR_NBLOCKS (blockvector
); i
++)
491 if (BLOCK_START(BLOCKVECTOR_BLOCK (blockvector
, i
-1))
492 > BLOCK_START(BLOCKVECTOR_BLOCK (blockvector
, i
)))
495 /* FIXME-32x64: loses if CORE_ADDR doesn't fit in a
496 long. Possible solutions include a version of
497 complain which takes a callback, a
498 sprintf_address_numeric to match
499 print_address_numeric, or a way to set up a GDB_FILE
500 * which causes sprintf rather than fprintf to be
503 complain (&blockvector_complaint
,
504 (unsigned long) BLOCK_START(BLOCKVECTOR_BLOCK (blockvector
, i
)));
510 return (blockvector
);
514 /* Start recording information about source code that came from an included
515 (or otherwise merged-in) source file with a different name. NAME is
516 the name of the file (cannot be NULL), DIRNAME is the directory in which
517 it resides (or NULL if not known). */
520 start_subfile (name
, dirname
)
524 register struct subfile
*subfile
;
526 /* See if this subfile is already known as a subfile of the
527 current main source file. */
529 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
531 if (STREQ (subfile
->name
, name
))
533 current_subfile
= subfile
;
538 /* This subfile is not known. Add an entry for it.
539 Make an entry for this subfile in the list of all subfiles
540 of the current main source file. */
542 subfile
= (struct subfile
*) xmalloc (sizeof (struct subfile
));
543 subfile
->next
= subfiles
;
545 current_subfile
= subfile
;
547 /* Save its name and compilation directory name */
548 subfile
->name
= (name
== NULL
) ? NULL
: savestring (name
, strlen (name
));
550 (dirname
== NULL
) ? NULL
: savestring (dirname
, strlen (dirname
));
552 /* Initialize line-number recording for this subfile. */
553 subfile
->line_vector
= NULL
;
555 /* Default the source language to whatever can be deduced from
556 the filename. If nothing can be deduced (such as for a C/C++
557 include file with a ".h" extension), then inherit whatever
558 language the previous subfile had. This kludgery is necessary
559 because there is no standard way in some object formats to
560 record the source language. Also, when symtabs are allocated
561 we try to deduce a language then as well, but it is too late
562 for us to use that information while reading symbols, since
563 symtabs aren't allocated until after all the symbols have
564 been processed for a given source file. */
566 subfile
->language
= deduce_language_from_filename (subfile
->name
);
567 if (subfile
->language
== language_unknown
&&
568 subfile
->next
!= NULL
)
570 subfile
->language
= subfile
->next
->language
;
573 /* Initialize the debug format string to NULL. We may supply it
574 later via a call to record_debugformat. */
575 subfile
->debugformat
= NULL
;
577 /* cfront output is a C program, so in most ways it looks like a C
578 program. But to demangle we need to set the language to C++. We
579 can distinguish cfront code by the fact that it has #line
580 directives which specify a file name ending in .C.
582 So if the filename of this subfile ends in .C, then change the language
583 of any pending subfiles from C to C++. We also accept any other C++
584 suffixes accepted by deduce_language_from_filename (in particular,
585 some people use .cxx with cfront). */
586 /* Likewise for f2c. */
591 enum language sublang
= deduce_language_from_filename (subfile
->name
);
593 if (sublang
== language_cplus
|| sublang
== language_fortran
)
594 for (s
= subfiles
; s
!= NULL
; s
= s
->next
)
595 if (s
->language
== language_c
)
596 s
->language
= sublang
;
599 /* And patch up this file if necessary. */
600 if (subfile
->language
== language_c
601 && subfile
->next
!= NULL
602 && (subfile
->next
->language
== language_cplus
603 || subfile
->next
->language
== language_fortran
))
605 subfile
->language
= subfile
->next
->language
;
609 /* For stabs readers, the first N_SO symbol is assumed to be the source
610 file name, and the subfile struct is initialized using that assumption.
611 If another N_SO symbol is later seen, immediately following the first
612 one, then the first one is assumed to be the directory name and the
613 second one is really the source file name.
615 So we have to patch up the subfile struct by moving the old name value to
616 dirname and remembering the new name. Some sanity checking is performed
617 to ensure that the state of the subfile struct is reasonable and that the
618 old name we are assuming to be a directory name actually is (by checking
619 for a trailing '/'). */
622 patch_subfile_names (subfile
, name
)
623 struct subfile
*subfile
;
626 if (subfile
!= NULL
&& subfile
->dirname
== NULL
&& subfile
->name
!= NULL
627 && subfile
->name
[strlen(subfile
->name
)-1] == '/')
629 subfile
->dirname
= subfile
->name
;
630 subfile
->name
= savestring (name
, strlen (name
));
631 last_source_file
= name
;
633 /* Default the source language to whatever can be deduced from
634 the filename. If nothing can be deduced (such as for a C/C++
635 include file with a ".h" extension), then inherit whatever
636 language the previous subfile had. This kludgery is necessary
637 because there is no standard way in some object formats to
638 record the source language. Also, when symtabs are allocated
639 we try to deduce a language then as well, but it is too late
640 for us to use that information while reading symbols, since
641 symtabs aren't allocated until after all the symbols have
642 been processed for a given source file. */
644 subfile
->language
= deduce_language_from_filename (subfile
->name
);
645 if (subfile
->language
== language_unknown
&&
646 subfile
->next
!= NULL
)
648 subfile
->language
= subfile
->next
->language
;
654 /* Handle the N_BINCL and N_EINCL symbol types
655 that act like N_SOL for switching source files
656 (different subfiles, as we call them) within one object file,
657 but using a stack rather than in an arbitrary order. */
662 register struct subfile_stack
*tem
663 = (struct subfile_stack
*) xmalloc (sizeof (struct subfile_stack
));
665 tem
->next
= subfile_stack
;
667 if (current_subfile
== NULL
|| current_subfile
->name
== NULL
)
671 tem
->name
= current_subfile
->name
;
678 register struct subfile_stack
*link
= subfile_stack
;
685 subfile_stack
= link
->next
;
691 /* Add a linetable entry for line number LINE and address PC to the line
692 vector for SUBFILE. */
695 record_line (subfile
, line
, pc
)
696 register struct subfile
*subfile
;
700 struct linetable_entry
*e
;
701 /* Ignore the dummy line number in libg.o */
708 /* Make sure line vector exists and is big enough. */
709 if (!subfile
->line_vector
)
711 subfile
->line_vector_length
= INITIAL_LINE_VECTOR_LENGTH
;
712 subfile
->line_vector
= (struct linetable
*)
713 xmalloc (sizeof (struct linetable
)
714 + subfile
->line_vector_length
* sizeof (struct linetable_entry
));
715 subfile
->line_vector
->nitems
= 0;
716 have_line_numbers
= 1;
719 if (subfile
->line_vector
->nitems
+ 1 >= subfile
->line_vector_length
)
721 subfile
->line_vector_length
*= 2;
722 subfile
->line_vector
= (struct linetable
*)
723 xrealloc ((char *) subfile
->line_vector
, (sizeof (struct linetable
)
724 + subfile
->line_vector_length
* sizeof (struct linetable_entry
)));
727 e
= subfile
->line_vector
->item
+ subfile
->line_vector
->nitems
++;
728 e
->line
= line
; e
->pc
= pc
;
732 /* Needed in order to sort line tables from IBM xcoff files. Sigh! */
735 compare_line_numbers (ln1p
, ln2p
)
739 struct linetable_entry
*ln1
= (struct linetable_entry
*) ln1p
;
740 struct linetable_entry
*ln2
= (struct linetable_entry
*) ln2p
;
742 /* Note: this code does not assume that CORE_ADDRs can fit in ints.
743 Please keep it that way. */
744 if (ln1
->pc
< ln2
->pc
)
747 if (ln1
->pc
> ln2
->pc
)
750 /* If pc equal, sort by line. I'm not sure whether this is optimum
751 behavior (see comment at struct linetable in symtab.h). */
752 return ln1
->line
- ln2
->line
;
756 /* Start a new symtab for a new source file.
757 Called, for example, when a stabs symbol of type N_SO is seen, or when
758 a DWARF TAG_compile_unit DIE is seen.
759 It indicates the start of data for one original source file. */
762 start_symtab (name
, dirname
, start_addr
)
765 CORE_ADDR start_addr
;
768 last_source_file
= name
;
769 last_source_start_addr
= start_addr
;
771 global_symbols
= NULL
;
773 have_line_numbers
= 0;
775 /* Context stack is initially empty. Allocate first one with room for
776 10 levels; reuse it forever afterward. */
777 if (context_stack
== NULL
)
779 context_stack_size
= INITIAL_CONTEXT_STACK_SIZE
;
780 context_stack
= (struct context_stack
*)
781 xmalloc (context_stack_size
* sizeof (struct context_stack
));
783 context_stack_depth
= 0;
785 /* Initialize the list of sub source files with one entry
786 for this file (the top-level source file). */
789 current_subfile
= NULL
;
790 start_subfile (name
, dirname
);
793 /* Finish the symbol definitions for one main source file,
794 close off all the lexical contexts for that file
795 (creating struct block's for them), then make the struct symtab
796 for that file and put it in the list of all such.
798 END_ADDR is the address of the end of the file's text.
799 SECTION is the section number (in objfile->section_offsets) of
800 the blockvector and linetable.
802 Note that it is possible for end_symtab() to return NULL. In particular,
803 for the DWARF case at least, it will return NULL when it finds a
804 compilation unit that has exactly one DIE, a TAG_compile_unit DIE. This
805 can happen when we link in an object file that was compiled from an empty
806 source file. Returning NULL is probably not the correct thing to do,
807 because then gdb will never know about this empty file (FIXME). */
810 end_symtab (end_addr
, objfile
, section
)
812 struct objfile
*objfile
;
815 register struct symtab
*symtab
= NULL
;
816 register struct blockvector
*blockvector
;
817 register struct subfile
*subfile
;
818 register struct context_stack
*cstk
;
819 struct subfile
*nextsub
;
821 /* Finish the lexical context of the last function in the file;
822 pop the context stack. */
824 if (context_stack_depth
> 0)
826 cstk
= pop_context();
827 /* Make a block for the local symbols within. */
828 finish_block (cstk
->name
, &local_symbols
, cstk
->old_blocks
,
829 cstk
->start_addr
, end_addr
, objfile
);
831 if (context_stack_depth
> 0)
833 /* This is said to happen with SCO. The old coffread.c code
834 simply emptied the context stack, so we do the same. FIXME:
835 Find out why it is happening. This is not believed to happen
836 in most cases (even for coffread.c); it used to be an abort(). */
837 static struct complaint msg
=
838 {"Context stack not empty in end_symtab", 0, 0};
840 context_stack_depth
= 0;
844 /* Reordered executables may have out of order pending blocks; if
845 OBJF_REORDERED is true, then sort the pending blocks. */
846 if ((objfile
->flags
& OBJF_REORDERED
) && pending_blocks
)
848 /* FIXME! Remove this horrid bubble sort and use merge sort!!! */
852 struct pending_block
*pb
, *pbnext
;
860 /* swap blocks if unordered! */
862 if (BLOCK_START(pb
->block
) < BLOCK_START(pbnext
->block
))
864 struct block
*tmp
= pb
->block
;
865 pb
->block
= pbnext
->block
;
870 pbnext
= pbnext
->next
;
875 /* Cleanup any undefined types that have been left hanging around
876 (this needs to be done before the finish_blocks so that
877 file_symbols is still good).
879 Both cleanup_undefined_types and finish_global_stabs are stabs
880 specific, but harmless for other symbol readers, since on gdb
881 startup or when finished reading stabs, the state is set so these
882 are no-ops. FIXME: Is this handled right in case of QUIT? Can
883 we make this cleaner? */
885 cleanup_undefined_types ();
886 finish_global_stabs (objfile
);
888 if (pending_blocks
== NULL
889 && file_symbols
== NULL
890 && global_symbols
== NULL
891 && have_line_numbers
== 0)
893 /* Ignore symtabs that have no functions with real debugging info */
898 /* Define the STATIC_BLOCK & GLOBAL_BLOCK, and build the blockvector. */
899 finish_block (0, &file_symbols
, 0, last_source_start_addr
, end_addr
,
901 finish_block (0, &global_symbols
, 0, last_source_start_addr
, end_addr
,
903 blockvector
= make_blockvector (objfile
);
906 #ifndef PROCESS_LINENUMBER_HOOK
907 #define PROCESS_LINENUMBER_HOOK()
909 PROCESS_LINENUMBER_HOOK (); /* Needed for xcoff. */
911 /* Now create the symtab objects proper, one for each subfile. */
912 /* (The main file is the last one on the chain.) */
914 for (subfile
= subfiles
; subfile
; subfile
= nextsub
)
916 int linetablesize
= 0;
917 /* If we have blocks of symbols, make a symtab.
918 Otherwise, just ignore this file and any line number info in it. */
922 if (subfile
->line_vector
)
924 linetablesize
= sizeof (struct linetable
) +
925 subfile
->line_vector
->nitems
* sizeof (struct linetable_entry
);
927 /* I think this is artifact from before it went on the obstack.
928 I doubt we'll need the memory between now and when we
929 free it later in this function. */
930 /* First, shrink the linetable to make more memory. */
931 subfile
->line_vector
= (struct linetable
*)
932 xrealloc ((char *) subfile
->line_vector
, linetablesize
);
935 /* Like the pending blocks, the line table may be scrambled
936 in reordered executables. Sort it if OBJF_REORDERED is
938 if (objfile
->flags
& OBJF_REORDERED
)
939 qsort (subfile
->line_vector
->item
,
940 subfile
->line_vector
->nitems
,
941 sizeof (struct linetable_entry
), compare_line_numbers
);
944 /* Now, allocate a symbol table. */
945 symtab
= allocate_symtab (subfile
->name
, objfile
);
947 /* Fill in its components. */
948 symtab
->blockvector
= blockvector
;
949 if (subfile
->line_vector
)
951 /* Reallocate the line table on the symbol obstack */
952 symtab
->linetable
= (struct linetable
*)
953 obstack_alloc (&objfile
-> symbol_obstack
, linetablesize
);
954 memcpy (symtab
->linetable
, subfile
->line_vector
, linetablesize
);
958 symtab
->linetable
= NULL
;
960 symtab
->block_line_section
= section
;
961 if (subfile
->dirname
)
963 /* Reallocate the dirname on the symbol obstack */
964 symtab
->dirname
= (char *)
965 obstack_alloc (&objfile
-> symbol_obstack
,
966 strlen (subfile
-> dirname
) + 1);
967 strcpy (symtab
->dirname
, subfile
->dirname
);
971 symtab
->dirname
= NULL
;
973 symtab
->free_code
= free_linetable
;
974 symtab
->free_ptr
= NULL
;
976 /* Use whatever language we have been using for this subfile,
977 not the one that was deduced in allocate_symtab from the
978 filename. We already did our own deducing when we created
979 the subfile, and we may have altered our opinion of what
980 language it is from things we found in the symbols. */
981 symtab
->language
= subfile
->language
;
983 /* Save the debug format string (if any) in the symtab */
984 if (subfile
-> debugformat
!= NULL
)
986 symtab
->debugformat
= obsavestring (subfile
->debugformat
,
987 strlen (subfile
->debugformat
),
988 &objfile
-> symbol_obstack
);
991 /* All symtabs for the main file and the subfiles share a
992 blockvector, so we need to clear primary for everything but
997 if (subfile
->name
!= NULL
)
999 free ((PTR
) subfile
->name
);
1001 if (subfile
->dirname
!= NULL
)
1003 free ((PTR
) subfile
->dirname
);
1005 if (subfile
->line_vector
!= NULL
)
1007 free ((PTR
) subfile
->line_vector
);
1009 if (subfile
->debugformat
!= NULL
)
1011 free ((PTR
) subfile
->debugformat
);
1014 nextsub
= subfile
->next
;
1015 free ((PTR
)subfile
);
1018 /* Set this for the main source file. */
1021 symtab
->primary
= 1;
1024 last_source_file
= NULL
;
1025 current_subfile
= NULL
;
1031 /* Push a context block. Args are an identifying nesting level (checkable
1032 when you pop it), and the starting PC address of this context. */
1034 struct context_stack
*
1035 push_context (desc
, valu
)
1039 register struct context_stack
*new;
1041 if (context_stack_depth
== context_stack_size
)
1043 context_stack_size
*= 2;
1044 context_stack
= (struct context_stack
*)
1045 xrealloc ((char *) context_stack
,
1046 (context_stack_size
* sizeof (struct context_stack
)));
1049 new = &context_stack
[context_stack_depth
++];
1051 new->locals
= local_symbols
;
1052 new->params
= param_symbols
;
1053 new->old_blocks
= pending_blocks
;
1054 new->start_addr
= valu
;
1057 local_symbols
= NULL
;
1058 param_symbols
= NULL
;
1064 /* Compute a small integer hash code for the given name. */
1070 register char *p
= name
;
1071 register int total
= p
[0];
1086 /* Ensure result is positive. */
1089 total
+= (1000 << 6);
1091 return (total
% HASHSIZE
);
1096 record_debugformat (format
)
1099 current_subfile
-> debugformat
= savestring (format
, strlen (format
));
1103 /* Merge the first symbol list SRCLIST into the second symbol list
1104 TARGETLIST by repeated calls to add_symbol_to_list(). This
1105 procedure "frees" each link of SRCLIST by adding it to the
1106 free_pendings list. Caller must set SRCLIST to a null list after
1107 calling this function.
1112 merge_symbol_lists (srclist
, targetlist
)
1113 struct pending
** srclist
;
1114 struct pending
** targetlist
;
1117 register struct pending
* link
;
1119 if (!srclist
|| !*srclist
)
1122 /* Merge in elements from current link */
1123 for (i
=0; i
< (*srclist
)->nsyms
; i
++)
1124 add_symbol_to_list ((*srclist
)->symbol
[i
], targetlist
);
1126 /* Recurse on next */
1127 merge_symbol_lists (&(*srclist
)->next
, targetlist
);
1129 /* "Free" the current link */
1130 (*srclist
)->next
= free_pendings
;
1131 free_pendings
= (*srclist
);
1137 /* Initialize anything that needs initializing when starting to read
1138 a fresh piece of a symbol file, e.g. reading in the stuff corresponding
1144 free_pendings
= NULL
;
1145 file_symbols
= NULL
;
1146 global_symbols
= NULL
;
1147 pending_blocks
= NULL
;
1150 /* Initialize anything that needs initializing when a completely new
1151 symbol file is specified (not just adding some symbols from another
1152 file, e.g. a shared library). */
1155 buildsym_new_init ()
1160 /* Initializer for this module */
1163 _initialize_buildsym ()