- /* Update memory corruption handler function addresses. */
- init_malloc (md);
- objfile -> md = md;
- objfile -> mmfd = fd;
- /* Update pointers to functions to *our* copies */
- obstack_chunkfun (&objfile -> psymbol_obstack, xmmalloc);
- obstack_freefun (&objfile -> psymbol_obstack, mfree);
- obstack_chunkfun (&objfile -> symbol_obstack, xmmalloc);
- obstack_freefun (&objfile -> symbol_obstack, mfree);
- obstack_chunkfun (&objfile -> type_obstack, xmmalloc);
- obstack_freefun (&objfile -> type_obstack, mfree);
- /* If already in objfile list, unlink it. */
- unlink_objfile (objfile);
- /* Forget things specific to a particular gdb, may have changed. */
- objfile -> sf = NULL;
+ PTR md;
+
+ if ((md = map_to_file (fd)) == NULL)
+ {
+ close (fd);
+ }
+ else if ((objfile = (struct objfile *) mmalloc_getkey (md, 0)) != NULL)
+ {
+ /* Update memory corruption handler function addresses. */
+ init_malloc (md);
+ 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);
+ obstack_freefun (&objfile->symbol_obstack, mfree);
+ obstack_chunkfun (&objfile->type_obstack, xmmalloc);
+ obstack_freefun (&objfile->type_obstack, mfree);
+ /* If already in objfile list, unlink it. */
+ unlink_objfile (objfile);
+ /* Forget things specific to a particular gdb, may have changed. */
+ objfile->sf = NULL;
+ }
+ else
+ {
+
+ /* Set up to detect internal memory corruption. MUST be
+ done before the first malloc. See comments in
+ init_malloc() and mmcheck(). */
+
+ init_malloc (md);
+
+ objfile = (struct objfile *)
+ xmmalloc (md, sizeof (struct objfile));
+ memset (objfile, 0, sizeof (struct objfile));
+ objfile->md = md;
+ 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);
+ obstack_specify_allocation_with_arg (&objfile->symbol_obstack,
+ 0, 0, xmmalloc, mfree,
+ objfile->md);
+ obstack_specify_allocation_with_arg (&objfile->type_obstack,
+ 0, 0, xmmalloc, mfree,
+ objfile->md);
+ }