X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=gdb%2Fobjfiles.c;h=b78f80b23f2e3ab31a6316e7558bf7ac4b654297;hb=deffd638b5941634b3dbfd3f30649c1b37d2d129;hp=891531d3d89c0990ee7c9cbffe6384049c6980a7;hpb=3a47045432484224045297da5e3254941c93b071;p=deliverable%2Fbinutils-gdb.git diff --git a/gdb/objfiles.c b/gdb/objfiles.c index 891531d3d8..b78f80b23f 100644 --- a/gdb/objfiles.c +++ b/gdb/objfiles.c @@ -1,5 +1,5 @@ /* GDB routines for manipulating objfiles. - Copyright 1992 Free Software Foundation, Inc. + Copyright 1992, 1993, 1994, 1995 Free Software Foundation, Inc. Contributed by Cygnus Support, using pieces from other GDB modules. This file is part of GDB. @@ -16,7 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software -Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* This file contains support routines for creating, manipulating, and destroying objfile structures. */ @@ -30,9 +30,10 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "target.h" #include -#include +#include "gdb_stat.h" #include -#include +#include "obstack.h" +#include "gdb_string.h" /* Prototypes for local functions */ @@ -44,14 +45,13 @@ open_existing_mapped_file PARAMS ((char *, long, int)); static int open_mapped_file PARAMS ((char *filename, long mtime, int mapped)); -static CORE_ADDR -map_to_address PARAMS ((void)); +static PTR +map_to_file PARAMS ((int)); #endif /* !defined(NO_MMALLOC) && defined(HAVE_MMAP) */ -/* Message to be printed before the error message, when an error occurs. */ - -extern char *error_pre_print; +static void +add_to_objfile_sections PARAMS ((bfd *, sec_ptr, PTR)); /* Externally visible variables that are owned by this module. See declarations in objfile.h for more info. */ @@ -59,6 +59,7 @@ extern char *error_pre_print; struct objfile *object_files; /* Linked list of all objfiles */ struct objfile *current_objfile; /* For symbol file being read in */ struct objfile *symfile_objfile; /* Main symbol table loaded from */ +struct objfile *rt_common_objfile; /* For runtime common symbols */ int mapped_symbol_files; /* Try to use mapped symbol files */ @@ -86,7 +87,7 @@ add_to_objfile_sections (abfd, asect, objfile_p_char) section.the_bfd_section = asect; section.addr = bfd_section_vma (abfd, asect); section.endaddr = section.addr + bfd_section_size (abfd, asect); - obstack_grow (&objfile->psymbol_obstack, §ion, sizeof(section)); + obstack_grow (&objfile->psymbol_obstack, (char *) §ion, sizeof(section)); objfile->sections_end = (struct obj_section *) (((unsigned long) objfile->sections_end) + 1); } @@ -146,11 +147,9 @@ allocate_objfile (abfd, mapped) mapped); if (fd >= 0) { - CORE_ADDR mapto; PTR md; - if (((mapto = map_to_address ()) == 0) || - ((md = mmalloc_attach (fd, (PTR) mapto)) == NULL)) + if ((md = map_to_file (fd)) == NULL) { close (fd); } @@ -161,6 +160,8 @@ allocate_objfile (abfd, mapped) objfile -> md = md; objfile -> mmfd = fd; /* Update pointers to functions to *our* copies */ + obstack_chunkfun (&objfile -> psymbol_cache.cache, xmmalloc); + obstack_freefun (&objfile -> psymbol_cache.cache, mfree); obstack_chunkfun (&objfile -> psymbol_obstack, xmmalloc); obstack_freefun (&objfile -> psymbol_obstack, mfree); obstack_chunkfun (&objfile -> symbol_obstack, xmmalloc); @@ -188,6 +189,9 @@ allocate_objfile (abfd, mapped) objfile -> mmfd = fd; objfile -> flags |= OBJF_MAPPED; mmalloc_setkey (objfile -> md, 0, objfile); + obstack_specify_allocation_with_arg (&objfile -> psymbol_cache.cache, + 0, 0, xmmalloc, mfree, + objfile -> md); obstack_specify_allocation_with_arg (&objfile -> psymbol_obstack, 0, 0, xmmalloc, mfree, objfile -> md); @@ -210,7 +214,7 @@ allocate_objfile (abfd, mapped) if (mapped) { - warning ("this version of gdb does not support mapped symbol tables."); + warning ("mapped symbol tables are not supported on this machine; missing or broken mmap()."); /* Turn off the global flag so we don't try to do mapped symbol tables any more, which shuts up gdb unless the user specifically gives the @@ -230,6 +234,8 @@ allocate_objfile (abfd, mapped) objfile = (struct objfile *) xmalloc (sizeof (struct objfile)); memset (objfile, 0, sizeof (struct objfile)); objfile -> md = NULL; + obstack_specify_allocation (&objfile -> psymbol_cache.cache, 0, 0, + xmalloc, free); obstack_specify_allocation (&objfile -> psymbol_obstack, 0, 0, xmalloc, free); obstack_specify_allocation (&objfile -> symbol_obstack, 0, 0, xmalloc, @@ -372,6 +378,12 @@ free_objfile (objfile) unlink_objfile (objfile); + /* If we are going to free the runtime common objfile, mark it + as unallocated. */ + + if (objfile == rt_common_objfile) + rt_common_objfile = NULL; + /* Before the symbol table code was redone to make it easier to selectively load and remove information particular to a specific linkage unit, gdb used to do these things whenever the monolithic @@ -429,6 +441,7 @@ free_objfile (objfile) if (objfile->static_psymbols.list) mfree (objfile->md, objfile->static_psymbols.list); /* Free the obstacks for non-reusable objfiles */ + obstack_free (&objfile -> psymbol_cache.cache, 0); obstack_free (&objfile -> psymbol_obstack, 0); obstack_free (&objfile -> symbol_obstack, 0); obstack_free (&objfile -> type_obstack, 0); @@ -530,7 +543,7 @@ objfile_relocate (objfile, new_offsets) if (SYMBOL_CLASS (sym) == LOC_CONST && SYMBOL_NAMESPACE (sym) == LABEL_NAMESPACE && STRCMP (SYMBOL_NAME (sym), MIPS_EFI_SYMBOL_NAME) == 0) - ecoff_relocate_efi (sym, ANOFFSET (delta, s->block_line_section)); + ecoff_relocate_efi (sym, ANOFFSET (delta, s->block_line_section)); #endif } } @@ -542,28 +555,24 @@ objfile_relocate (objfile, new_offsets) ALL_OBJFILE_PSYMTABS (objfile, p) { - /* FIXME: specific to symbol readers which use gdb-stabs.h. - We can only get away with it since objfile_relocate is only - used on XCOFF, which lacks psymtabs, and for gdb-stabs.h - targets. */ p->textlow += ANOFFSET (delta, SECT_OFF_TEXT); p->texthigh += ANOFFSET (delta, SECT_OFF_TEXT); } } { - struct partial_symbol *psym; + struct partial_symbol **psym; for (psym = objfile->global_psymbols.list; psym < objfile->global_psymbols.next; psym++) - if (SYMBOL_SECTION (psym) >= 0) - SYMBOL_VALUE_ADDRESS (psym) += ANOFFSET (delta, SYMBOL_SECTION (psym)); + if (SYMBOL_SECTION (*psym) >= 0) + SYMBOL_VALUE_ADDRESS (*psym) += ANOFFSET (delta, SYMBOL_SECTION (*psym)); for (psym = objfile->static_psymbols.list; psym < objfile->static_psymbols.next; psym++) - if (SYMBOL_SECTION (psym) >= 0) - SYMBOL_VALUE_ADDRESS (psym) += ANOFFSET (delta, SYMBOL_SECTION (psym)); + if (SYMBOL_SECTION (*psym) >= 0) + SYMBOL_VALUE_ADDRESS (*psym) += ANOFFSET (delta, SYMBOL_SECTION (*psym)); } { @@ -816,49 +825,47 @@ open_mapped_file (filename, mtime, mapped) return (fd); } -/* Return the base address at which we would like the next objfile's - mapped data to start. - - For now, we use the kludge that the configuration specifies a base - address to which it is safe to map the first mmalloc heap, and an - increment to add to this address for each successive heap. There are - a lot of issues to deal with here to make this work reasonably, including: - - Avoid memory collisions with existing mapped address spaces - - Reclaim address spaces when their mmalloc heaps are unmapped - - When mmalloc heaps are shared between processes they have to be - mapped at the same addresses in each - - Once created, a mmalloc heap that is to be mapped back in must be - mapped at the original address. I.E. each objfile will expect to - be remapped at it's original address. This becomes a problem if - the desired address is already in use. - - etc, etc, etc. - - */ - - -static CORE_ADDR -map_to_address () +static PTR +map_to_file (fd) + int fd; { + PTR md; + CORE_ADDR mapto; -#if defined(MMAP_BASE_ADDRESS) && defined (MMAP_INCREMENT) - - static CORE_ADDR next = MMAP_BASE_ADDRESS; - CORE_ADDR mapto = next; - - next += MMAP_INCREMENT; - return (mapto); - -#else - - return (0); - -#endif - + md = mmalloc_attach (fd, (PTR) 0); + if (md != NULL) + { + mapto = (CORE_ADDR) mmalloc_getkey (md, 1); + md = mmalloc_detach (md); + if (md != NULL) + { + /* FIXME: should figure out why detach failed */ + md = NULL; + } + else if (mapto != (CORE_ADDR) NULL) + { + /* This mapping file needs to be remapped at "mapto" */ + md = mmalloc_attach (fd, (PTR) mapto); + } + else + { + /* This is a freshly created mapping file. */ + mapto = (CORE_ADDR) mmalloc_findbase (20 * 1024 * 1024); + if (mapto != 0) + { + /* To avoid reusing the freshly created mapping file, at the + address selected by mmap, we must truncate it before trying + to do an attach at the address we want. */ + ftruncate (fd, 0); + md = mmalloc_attach (fd, (PTR) mapto); + if (md != NULL) + { + mmalloc_setkey (md, 1, (PTR) mapto); + } + } + } + } + return (md); } #endif /* !defined(NO_MMALLOC) && defined(HAVE_MMAP) */