1 /* Support routines for building symbol tables in GDB's internal format.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
3 1996, 1997, 1998, 1999, 2000, 2001 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,
20 Boston, MA 02111-1307, USA. */
22 /* This module provides subroutines used for creating and adding to
23 the symbol table. These routines are called from various symbol-
24 file-reading routines.
26 Routines to support specific debugging information formats (stabs,
27 DWARF, etc) belong somewhere else. */
33 #include "symfile.h" /* Needed for "struct complaint" */
36 #include "complaints.h"
37 #include "gdb_string.h"
38 #include "expression.h" /* For "enum exp_opcode" used by... */
39 #include "language.h" /* For "longest_local_hex_string_custom" */
41 #include "filenames.h" /* For DOSish file names */
42 /* Ask buildsym.h to define the vars it normally declares `extern'. */
45 #include "buildsym.h" /* Our own declarations */
48 /* For cleanup_undefined_types and finish_global_stabs (somewhat
49 questionable--see comment where we call them). */
51 #include "stabsread.h"
53 /* List of free `struct pending' structures for reuse. */
55 static struct pending
*free_pendings
;
57 /* Non-zero if symtab has line number info. This prevents an
58 otherwise empty symtab from being tossed. */
60 static int have_line_numbers
;
62 static int compare_line_numbers (const void *ln1p
, const void *ln2p
);
65 /* Initial sizes of data structures. These are realloc'd larger if
66 needed, and realloc'd down to the size actually used, when
69 #define INITIAL_CONTEXT_STACK_SIZE 10
70 #define INITIAL_LINE_VECTOR_LENGTH 1000
73 /* Complaints about the symbols we have encountered. */
75 struct complaint block_end_complaint
=
76 {"block end address less than block start address in %s (patched it)", 0, 0};
78 struct complaint anon_block_end_complaint
=
79 {"block end address 0x%lx less than block start address 0x%lx (patched it)", 0, 0};
81 struct complaint innerblock_complaint
=
82 {"inner block not inside outer block in %s", 0, 0};
84 struct complaint innerblock_anon_complaint
=
85 {"inner block (0x%lx-0x%lx) not inside outer block (0x%lx-0x%lx)", 0, 0};
87 struct complaint blockvector_complaint
=
88 {"block at %s out of order", 0, 0};
90 /* maintain the lists of symbols and blocks */
92 /* Add a pending list to free_pendings. */
94 add_free_pendings (struct pending
*list
)
96 register struct pending
*link
= list
;
100 while (link
->next
) link
= link
->next
;
101 link
->next
= free_pendings
;
102 free_pendings
= list
;
106 /* Add a symbol to one of the lists of symbols. */
109 add_symbol_to_list (struct symbol
*symbol
, struct pending
**listhead
)
111 register struct pending
*link
;
113 /* If this is an alias for another symbol, don't add it. */
114 if (symbol
->ginfo
.name
&& symbol
->ginfo
.name
[0] == '#')
117 /* We keep PENDINGSIZE symbols in each link of the list. If we
118 don't have a link with room in it, add a new link. */
119 if (*listhead
== NULL
|| (*listhead
)->nsyms
== PENDINGSIZE
)
123 link
= free_pendings
;
124 free_pendings
= link
->next
;
128 link
= (struct pending
*) xmalloc (sizeof (struct pending
));
131 link
->next
= *listhead
;
136 (*listhead
)->symbol
[(*listhead
)->nsyms
++] = symbol
;
139 /* Find a symbol named NAME on a LIST. NAME need not be
140 '\0'-terminated; LENGTH is the length of the name. */
143 find_symbol_in_list (struct pending
*list
, char *name
, int length
)
150 for (j
= list
->nsyms
; --j
>= 0;)
152 pp
= SYMBOL_NAME (list
->symbol
[j
]);
153 if (*pp
== *name
&& strncmp (pp
, name
, length
) == 0 &&
156 return (list
->symbol
[j
]);
164 /* At end of reading syms, or in case of quit, really free as many
165 `struct pending's as we can easily find. */
169 really_free_pendings (PTR dummy
)
171 struct pending
*next
, *next1
;
173 for (next
= free_pendings
; next
; next
= next1
)
176 xfree ((void *) next
);
178 free_pendings
= NULL
;
180 free_pending_blocks ();
182 for (next
= file_symbols
; next
!= NULL
; next
= next1
)
185 xfree ((void *) next
);
189 for (next
= global_symbols
; next
!= NULL
; next
= next1
)
192 xfree ((void *) next
);
194 global_symbols
= NULL
;
197 /* This function is called to discard any pending blocks. */
200 free_pending_blocks (void)
202 #if 0 /* Now we make the links in the
203 symbol_obstack, so don't free
205 struct pending_block
*bnext
, *bnext1
;
207 for (bnext
= pending_blocks
; bnext
; bnext
= bnext1
)
209 bnext1
= bnext
->next
;
210 xfree ((void *) bnext
);
213 pending_blocks
= NULL
;
216 /* Take one of the lists of symbols and make a block from it. Keep
217 the order the symbols have in the list (reversed from the input
218 file). Put the block on the list of pending blocks. */
221 finish_block (struct symbol
*symbol
, struct pending
**listhead
,
222 struct pending_block
*old_blocks
,
223 CORE_ADDR start
, CORE_ADDR end
,
224 struct objfile
*objfile
)
226 register struct pending
*next
, *next1
;
227 register struct block
*block
;
228 register struct pending_block
*pblock
;
229 struct pending_block
*opblock
;
233 /* Count the length of the list of symbols. */
235 for (next
= *listhead
, i
= 0;
237 i
+= next
->nsyms
, next
= next
->next
)
242 block
= (struct block
*) obstack_alloc (&objfile
->symbol_obstack
,
243 (sizeof (struct block
) + ((i
- 1) * sizeof (struct symbol
*))));
245 /* Copy the symbols into the block. */
247 BLOCK_NSYMS (block
) = i
;
248 for (next
= *listhead
; next
; next
= next
->next
)
250 for (j
= next
->nsyms
- 1; j
>= 0; j
--)
252 BLOCK_SYM (block
, --i
) = next
->symbol
[j
];
256 BLOCK_START (block
) = start
;
257 BLOCK_END (block
) = end
;
258 /* Superblock filled in when containing block is made */
259 BLOCK_SUPERBLOCK (block
) = NULL
;
261 BLOCK_GCC_COMPILED (block
) = processing_gcc_compilation
;
263 /* Put the block in as the value of the symbol that names it. */
267 struct type
*ftype
= SYMBOL_TYPE (symbol
);
268 SYMBOL_BLOCK_VALUE (symbol
) = block
;
269 BLOCK_FUNCTION (block
) = symbol
;
271 if (TYPE_NFIELDS (ftype
) <= 0)
273 /* No parameter type information is recorded with the
274 function's type. Set that from the type of the
275 parameter symbols. */
276 int nparams
= 0, iparams
;
278 ALL_BLOCK_SYMBOLS (block
, i
, sym
)
280 switch (SYMBOL_CLASS (sym
))
285 case LOC_REGPARM_ADDR
:
286 case LOC_BASEREG_ARG
:
299 case LOC_CONST_BYTES
:
302 case LOC_OPTIMIZED_OUT
:
309 TYPE_NFIELDS (ftype
) = nparams
;
310 TYPE_FIELDS (ftype
) = (struct field
*)
311 TYPE_ALLOC (ftype
, nparams
* sizeof (struct field
));
313 for (i
= iparams
= 0; iparams
< nparams
; i
++)
315 sym
= BLOCK_SYM (block
, i
);
316 switch (SYMBOL_CLASS (sym
))
321 case LOC_REGPARM_ADDR
:
322 case LOC_BASEREG_ARG
:
324 TYPE_FIELD_TYPE (ftype
, iparams
) = SYMBOL_TYPE (sym
);
336 case LOC_CONST_BYTES
:
339 case LOC_OPTIMIZED_OUT
:
349 BLOCK_FUNCTION (block
) = NULL
;
352 /* Now "free" the links of the list, and empty the list. */
354 for (next
= *listhead
; next
; next
= next1
)
357 next
->next
= free_pendings
;
358 free_pendings
= next
;
363 /* Check to be sure that the blocks have an end address that is
364 greater than starting address */
366 if (BLOCK_END (block
) < BLOCK_START (block
))
370 complain (&block_end_complaint
, SYMBOL_SOURCE_NAME (symbol
));
374 complain (&anon_block_end_complaint
, BLOCK_END (block
), BLOCK_START (block
));
376 /* Better than nothing */
377 BLOCK_END (block
) = BLOCK_START (block
);
381 /* Install this block as the superblock of all blocks made since the
382 start of this scope that don't have superblocks yet. */
385 for (pblock
= pending_blocks
; pblock
!= old_blocks
; pblock
= pblock
->next
)
387 if (BLOCK_SUPERBLOCK (pblock
->block
) == NULL
)
390 /* Check to be sure the blocks are nested as we receive
391 them. If the compiler/assembler/linker work, this just
392 burns a small amount of time. */
393 if (BLOCK_START (pblock
->block
) < BLOCK_START (block
) ||
394 BLOCK_END (pblock
->block
) > BLOCK_END (block
))
398 complain (&innerblock_complaint
,
399 SYMBOL_SOURCE_NAME (symbol
));
403 complain (&innerblock_anon_complaint
, BLOCK_START (pblock
->block
),
404 BLOCK_END (pblock
->block
), BLOCK_START (block
),
407 if (BLOCK_START (pblock
->block
) < BLOCK_START (block
))
408 BLOCK_START (pblock
->block
) = BLOCK_START (block
);
409 if (BLOCK_END (pblock
->block
) > BLOCK_END (block
))
410 BLOCK_END (pblock
->block
) = BLOCK_END (block
);
413 BLOCK_SUPERBLOCK (pblock
->block
) = block
;
418 record_pending_block (objfile
, block
, opblock
);
421 /* Record BLOCK on the list of all blocks in the file. Put it after
422 OPBLOCK, or at the beginning if opblock is NULL. This puts the
423 block in the list after all its subblocks.
425 Allocate the pending block struct in the symbol_obstack to save
426 time. This wastes a little space. FIXME: Is it worth it? */
429 record_pending_block (struct objfile
*objfile
, struct block
*block
,
430 struct pending_block
*opblock
)
432 register struct pending_block
*pblock
;
434 pblock
= (struct pending_block
*)
435 obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct pending_block
));
436 pblock
->block
= block
;
439 pblock
->next
= opblock
->next
;
440 opblock
->next
= pblock
;
444 pblock
->next
= pending_blocks
;
445 pending_blocks
= pblock
;
449 /* Note that this is only used in this file and in dstread.c, which
450 should be fixed to not need direct access to this function. When
451 that is done, it can be made static again. */
454 make_blockvector (struct objfile
*objfile
)
456 register struct pending_block
*next
;
457 register struct blockvector
*blockvector
;
460 /* Count the length of the list of blocks. */
462 for (next
= pending_blocks
, i
= 0; next
; next
= next
->next
, i
++)
466 blockvector
= (struct blockvector
*)
467 obstack_alloc (&objfile
->symbol_obstack
,
468 (sizeof (struct blockvector
)
469 + (i
- 1) * sizeof (struct block
*)));
471 /* Copy the blocks into the blockvector. This is done in reverse
472 order, which happens to put the blocks into the proper order
473 (ascending starting address). finish_block has hair to insert
474 each block into the list after its subblocks in order to make
475 sure this is true. */
477 BLOCKVECTOR_NBLOCKS (blockvector
) = i
;
478 for (next
= pending_blocks
; next
; next
= next
->next
)
480 BLOCKVECTOR_BLOCK (blockvector
, --i
) = next
->block
;
483 #if 0 /* Now we make the links in the
484 obstack, so don't free them. */
485 /* Now free the links of the list, and empty the list. */
487 for (next
= pending_blocks
; next
; next
= next1
)
493 pending_blocks
= NULL
;
495 #if 1 /* FIXME, shut this off after a while
496 to speed up symbol reading. */
497 /* Some compilers output blocks in the wrong order, but we depend on
498 their being in the right order so we can binary search. Check the
499 order and moan about it. FIXME. */
500 if (BLOCKVECTOR_NBLOCKS (blockvector
) > 1)
502 for (i
= 1; i
< BLOCKVECTOR_NBLOCKS (blockvector
); i
++)
504 if (BLOCK_START (BLOCKVECTOR_BLOCK (blockvector
, i
- 1))
505 > BLOCK_START (BLOCKVECTOR_BLOCK (blockvector
, i
)))
508 = BLOCK_START (BLOCKVECTOR_BLOCK (blockvector
, i
));
510 complain (&blockvector_complaint
,
511 longest_local_hex_string ((LONGEST
) start
));
517 return (blockvector
);
520 /* Start recording information about source code that came from an
521 included (or otherwise merged-in) source file with a different
522 name. NAME is the name of the file (cannot be NULL), DIRNAME is
523 the directory in which it resides (or NULL if not known). */
526 start_subfile (char *name
, char *dirname
)
528 register struct subfile
*subfile
;
530 /* See if this subfile is already known as a subfile of the current
533 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
535 if (FILENAME_CMP (subfile
->name
, name
) == 0)
537 current_subfile
= subfile
;
542 /* This subfile is not known. Add an entry for it. Make an entry
543 for this subfile in the list of all subfiles of the current main
546 subfile
= (struct subfile
*) xmalloc (sizeof (struct subfile
));
547 memset ((char *) subfile
, 0, 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 the
561 filename. If nothing can be deduced (such as for a C/C++ include
562 file with a ".h" extension), then inherit whatever language the
563 previous subfile had. This kludgery is necessary because there
564 is no standard way in some object formats to record the source
565 language. Also, when symtabs are allocated we try to deduce a
566 language then as well, but it is too late for us to use that
567 information while reading symbols, since symtabs aren't allocated
568 until after all the symbols have been processed for a given
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
588 language of any pending subfiles from C to C++. We also accept
589 any other C++ suffixes accepted by deduce_language_from_filename
590 (in particular, 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
615 source file name, and the subfile struct is initialized using that
616 assumption. If another N_SO symbol is later seen, immediately
617 following the first one, then the first one is assumed to be the
618 directory name and the second one is really the source file name.
620 So we have to patch up the subfile struct by moving the old name
621 value to dirname and remembering the new name. Some sanity
622 checking is performed to ensure that the state of the subfile
623 struct is reasonable and that the old name we are assuming to be a
624 directory name actually is (by checking for a trailing '/'). */
627 patch_subfile_names (struct subfile
*subfile
, char *name
)
629 if (subfile
!= NULL
&& subfile
->dirname
== NULL
&& subfile
->name
!= NULL
630 && subfile
->name
[strlen (subfile
->name
) - 1] == '/')
632 subfile
->dirname
= subfile
->name
;
633 subfile
->name
= savestring (name
, strlen (name
));
634 last_source_file
= name
;
636 /* Default the source language to whatever can be deduced from
637 the filename. If nothing can be deduced (such as for a C/C++
638 include file with a ".h" extension), then inherit whatever
639 language the previous subfile had. This kludgery is
640 necessary because there is no standard way in some object
641 formats to record the source language. Also, when symtabs
642 are allocated we try to deduce a language then as well, but
643 it is too late for us to use that information while reading
644 symbols, since symtabs aren't allocated until after all the
645 symbols have been processed for a given source file. */
647 subfile
->language
= deduce_language_from_filename (subfile
->name
);
648 if (subfile
->language
== language_unknown
&&
649 subfile
->next
!= NULL
)
651 subfile
->language
= subfile
->next
->language
;
656 /* Handle the N_BINCL and N_EINCL symbol types that act like N_SOL for
657 switching source files (different subfiles, as we call them) within
658 one object file, but using a stack rather than in an arbitrary
664 register struct subfile_stack
*tem
665 = (struct subfile_stack
*) xmalloc (sizeof (struct subfile_stack
));
667 tem
->next
= subfile_stack
;
669 if (current_subfile
== NULL
|| current_subfile
->name
== NULL
)
671 internal_error (__FILE__
, __LINE__
, "failed internal consistency check");
673 tem
->name
= current_subfile
->name
;
680 register struct subfile_stack
*link
= subfile_stack
;
684 internal_error (__FILE__
, __LINE__
, "failed internal consistency check");
687 subfile_stack
= link
->next
;
688 xfree ((void *) link
);
692 /* Add a linetable entry for line number LINE and address PC to the
693 line vector for SUBFILE. */
696 record_line (register struct subfile
*subfile
, int line
, CORE_ADDR pc
)
698 struct linetable_entry
*e
;
699 /* Ignore the dummy line number in libg.o */
706 /* Make sure line vector exists and is big enough. */
707 if (!subfile
->line_vector
)
709 subfile
->line_vector_length
= INITIAL_LINE_VECTOR_LENGTH
;
710 subfile
->line_vector
= (struct linetable
*)
711 xmalloc (sizeof (struct linetable
)
712 + subfile
->line_vector_length
* sizeof (struct linetable_entry
));
713 subfile
->line_vector
->nitems
= 0;
714 have_line_numbers
= 1;
717 if (subfile
->line_vector
->nitems
+ 1 >= subfile
->line_vector_length
)
719 subfile
->line_vector_length
*= 2;
720 subfile
->line_vector
= (struct linetable
*)
721 xrealloc ((char *) subfile
->line_vector
,
722 (sizeof (struct linetable
)
723 + (subfile
->line_vector_length
724 * sizeof (struct linetable_entry
))));
727 e
= subfile
->line_vector
->item
+ subfile
->line_vector
->nitems
++;
729 e
->pc
= ADDR_BITS_REMOVE(pc
);
732 /* Needed in order to sort line tables from IBM xcoff files. Sigh! */
735 compare_line_numbers (const void *ln1p
, const void *ln2p
)
737 struct linetable_entry
*ln1
= (struct linetable_entry
*) ln1p
;
738 struct linetable_entry
*ln2
= (struct linetable_entry
*) ln2p
;
740 /* Note: this code does not assume that CORE_ADDRs can fit in ints.
741 Please keep it that way. */
742 if (ln1
->pc
< ln2
->pc
)
745 if (ln1
->pc
> ln2
->pc
)
748 /* If pc equal, sort by line. I'm not sure whether this is optimum
749 behavior (see comment at struct linetable in symtab.h). */
750 return ln1
->line
- ln2
->line
;
753 /* Start a new symtab for a new source file. Called, for example,
754 when a stabs symbol of type N_SO is seen, or when a DWARF
755 TAG_compile_unit DIE is seen. It indicates the start of data for
756 one original source file. */
759 start_symtab (char *name
, char *dirname
, CORE_ADDR start_addr
)
762 last_source_file
= name
;
763 last_source_start_addr
= start_addr
;
765 global_symbols
= NULL
;
767 have_line_numbers
= 0;
769 /* Context stack is initially empty. Allocate first one with room
770 for 10 levels; reuse it forever afterward. */
771 if (context_stack
== NULL
)
773 context_stack_size
= INITIAL_CONTEXT_STACK_SIZE
;
774 context_stack
= (struct context_stack
*)
775 xmalloc (context_stack_size
* sizeof (struct context_stack
));
777 context_stack_depth
= 0;
779 /* Initialize the list of sub source files with one entry for this
780 file (the top-level source file). */
783 current_subfile
= NULL
;
784 start_subfile (name
, dirname
);
787 /* Finish the symbol definitions for one main source file, close off
788 all the lexical contexts for that file (creating struct block's for
789 them), then make the struct symtab for that file and put it in the
792 END_ADDR is the address of the end of the file's text. SECTION is
793 the section number (in objfile->section_offsets) of the blockvector
796 Note that it is possible for end_symtab() to return NULL. In
797 particular, for the DWARF case at least, it will return NULL when
798 it finds a compilation unit that has exactly one DIE, a
799 TAG_compile_unit DIE. This can happen when we link in an object
800 file that was compiled from an empty source file. Returning NULL
801 is probably not the correct thing to do, because then gdb will
802 never know about this empty file (FIXME). */
805 end_symtab (CORE_ADDR end_addr
, struct objfile
*objfile
, int section
)
807 register struct symtab
*symtab
= NULL
;
808 register struct blockvector
*blockvector
;
809 register struct subfile
*subfile
;
810 register struct context_stack
*cstk
;
811 struct subfile
*nextsub
;
813 /* Finish the lexical context of the last function in the file; pop
814 the context stack. */
816 if (context_stack_depth
> 0)
818 cstk
= pop_context ();
819 /* Make a block for the local symbols within. */
820 finish_block (cstk
->name
, &local_symbols
, cstk
->old_blocks
,
821 cstk
->start_addr
, end_addr
, objfile
);
823 if (context_stack_depth
> 0)
825 /* This is said to happen with SCO. The old coffread.c
826 code simply emptied the context stack, so we do the
827 same. FIXME: Find out why it is happening. This is not
828 believed to happen in most cases (even for coffread.c);
829 it used to be an abort(). */
830 static struct complaint msg
=
831 {"Context stack not empty in end_symtab", 0, 0};
833 context_stack_depth
= 0;
837 /* Reordered executables may have out of order pending blocks; if
838 OBJF_REORDERED is true, then sort the pending blocks. */
839 if ((objfile
->flags
& OBJF_REORDERED
) && pending_blocks
)
841 /* FIXME! Remove this horrid bubble sort and use merge sort!!! */
845 struct pending_block
*pb
, *pbnext
;
853 /* swap blocks if unordered! */
855 if (BLOCK_START (pb
->block
) < BLOCK_START (pbnext
->block
))
857 struct block
*tmp
= pb
->block
;
858 pb
->block
= pbnext
->block
;
863 pbnext
= pbnext
->next
;
869 /* Cleanup any undefined types that have been left hanging around
870 (this needs to be done before the finish_blocks so that
871 file_symbols is still good).
873 Both cleanup_undefined_types and finish_global_stabs are stabs
874 specific, but harmless for other symbol readers, since on gdb
875 startup or when finished reading stabs, the state is set so these
876 are no-ops. FIXME: Is this handled right in case of QUIT? Can
877 we make this cleaner? */
879 cleanup_undefined_types ();
880 finish_global_stabs (objfile
);
882 if (pending_blocks
== NULL
883 && file_symbols
== NULL
884 && global_symbols
== NULL
885 && have_line_numbers
== 0)
887 /* Ignore symtabs that have no functions with real debugging
893 /* Define the STATIC_BLOCK & GLOBAL_BLOCK, and build the
895 finish_block (0, &file_symbols
, 0, last_source_start_addr
, end_addr
,
897 finish_block (0, &global_symbols
, 0, last_source_start_addr
, end_addr
,
899 blockvector
= make_blockvector (objfile
);
902 #ifndef PROCESS_LINENUMBER_HOOK
903 #define PROCESS_LINENUMBER_HOOK()
905 PROCESS_LINENUMBER_HOOK (); /* Needed for xcoff. */
907 /* Now create the symtab objects proper, one for each subfile. */
908 /* (The main file is the last one on the chain.) */
910 for (subfile
= subfiles
; subfile
; subfile
= nextsub
)
912 int linetablesize
= 0;
915 /* If we have blocks of symbols, make a symtab. Otherwise, just
916 ignore this file and any line number info in it. */
919 if (subfile
->line_vector
)
921 linetablesize
= sizeof (struct linetable
) +
922 subfile
->line_vector
->nitems
* sizeof (struct linetable_entry
);
924 /* I think this is artifact from before it went on the
925 obstack. I doubt we'll need the memory between now
926 and when we free it later in this function. */
927 /* First, shrink the linetable to make more memory. */
928 subfile
->line_vector
= (struct linetable
*)
929 xrealloc ((char *) subfile
->line_vector
, linetablesize
);
932 /* Like the pending blocks, the line table may be
933 scrambled in reordered executables. Sort it if
934 OBJF_REORDERED is true. */
935 if (objfile
->flags
& OBJF_REORDERED
)
936 qsort (subfile
->line_vector
->item
,
937 subfile
->line_vector
->nitems
,
938 sizeof (struct linetable_entry
), compare_line_numbers
);
941 /* Now, allocate a symbol table. */
942 symtab
= allocate_symtab (subfile
->name
, objfile
);
944 /* Fill in its components. */
945 symtab
->blockvector
= blockvector
;
946 if (subfile
->line_vector
)
948 /* Reallocate the line table on the symbol obstack */
949 symtab
->linetable
= (struct linetable
*)
950 obstack_alloc (&objfile
->symbol_obstack
, linetablesize
);
951 memcpy (symtab
->linetable
, subfile
->line_vector
, linetablesize
);
955 symtab
->linetable
= NULL
;
957 symtab
->block_line_section
= section
;
958 if (subfile
->dirname
)
960 /* Reallocate the dirname on the symbol obstack */
961 symtab
->dirname
= (char *)
962 obstack_alloc (&objfile
->symbol_obstack
,
963 strlen (subfile
->dirname
) + 1);
964 strcpy (symtab
->dirname
, subfile
->dirname
);
968 symtab
->dirname
= NULL
;
970 symtab
->free_code
= free_linetable
;
971 symtab
->free_ptr
= NULL
;
973 /* Use whatever language we have been using for this
974 subfile, not the one that was deduced in allocate_symtab
975 from the filename. We already did our own deducing when
976 we created the subfile, and we may have altered our
977 opinion of what language it is from things we found in
979 symtab
->language
= subfile
->language
;
981 /* Save the debug format string (if any) in the symtab */
982 if (subfile
->debugformat
!= NULL
)
984 symtab
->debugformat
= obsavestring (subfile
->debugformat
,
985 strlen (subfile
->debugformat
),
986 &objfile
->symbol_obstack
);
989 /* All symtabs for the main file and the subfiles share a
990 blockvector, so we need to clear primary for everything
991 but the main file. */
995 if (subfile
->name
!= NULL
)
997 xfree ((void *) subfile
->name
);
999 if (subfile
->dirname
!= NULL
)
1001 xfree ((void *) subfile
->dirname
);
1003 if (subfile
->line_vector
!= NULL
)
1005 xfree ((void *) subfile
->line_vector
);
1007 if (subfile
->debugformat
!= NULL
)
1009 xfree ((void *) subfile
->debugformat
);
1012 nextsub
= subfile
->next
;
1013 xfree ((void *) subfile
);
1016 /* Set this for the main source file. */
1019 symtab
->primary
= 1;
1022 last_source_file
= NULL
;
1023 current_subfile
= NULL
;
1028 /* Push a context block. Args are an identifying nesting level
1029 (checkable when you pop it), and the starting PC address of this
1032 struct context_stack
*
1033 push_context (int desc
, CORE_ADDR valu
)
1035 register struct context_stack
*new;
1037 if (context_stack_depth
== context_stack_size
)
1039 context_stack_size
*= 2;
1040 context_stack
= (struct context_stack
*)
1041 xrealloc ((char *) context_stack
,
1042 (context_stack_size
* sizeof (struct context_stack
)));
1045 new = &context_stack
[context_stack_depth
++];
1047 new->locals
= local_symbols
;
1048 new->params
= param_symbols
;
1049 new->old_blocks
= pending_blocks
;
1050 new->start_addr
= valu
;
1053 local_symbols
= NULL
;
1054 param_symbols
= NULL
;
1060 /* Compute a small integer hash code for the given name. */
1063 hashname (char *name
)
1065 return (hash(name
,strlen(name
)) % HASHSIZE
);
1070 record_debugformat (char *format
)
1072 current_subfile
->debugformat
= savestring (format
, strlen (format
));
1075 /* Merge the first symbol list SRCLIST into the second symbol list
1076 TARGETLIST by repeated calls to add_symbol_to_list(). This
1077 procedure "frees" each link of SRCLIST by adding it to the
1078 free_pendings list. Caller must set SRCLIST to a null list after
1079 calling this function.
1084 merge_symbol_lists (struct pending
**srclist
, struct pending
**targetlist
)
1088 if (!srclist
|| !*srclist
)
1091 /* Merge in elements from current link. */
1092 for (i
= 0; i
< (*srclist
)->nsyms
; i
++)
1093 add_symbol_to_list ((*srclist
)->symbol
[i
], targetlist
);
1095 /* Recurse on next. */
1096 merge_symbol_lists (&(*srclist
)->next
, targetlist
);
1098 /* "Free" the current link. */
1099 (*srclist
)->next
= free_pendings
;
1100 free_pendings
= (*srclist
);
1103 /* Initialize anything that needs initializing when starting to read a
1104 fresh piece of a symbol file, e.g. reading in the stuff
1105 corresponding to a psymtab. */
1108 buildsym_init (void)
1110 free_pendings
= NULL
;
1111 file_symbols
= NULL
;
1112 global_symbols
= NULL
;
1113 pending_blocks
= NULL
;
1116 /* Initialize anything that needs initializing when a completely new
1117 symbol file is specified (not just adding some symbols from another
1118 file, e.g. a shared library). */
1121 buildsym_new_init (void)