if (((mapto = map_to_address ()) == 0) ||
((md = mmalloc_attach (fd, (void *) mapto)) == NULL))
{
- (void) close (fd);
+ close (fd);
}
else if ((objfile = (struct objfile *) mmalloc_getkey (md, 0)) != NULL)
{
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
{
the first malloc. See comments in init_malloc() and mmcheck(). */
init_malloc (md);
objfile = (struct objfile *) xmmalloc (md, sizeof (struct objfile));
- (void) memset (objfile, 0, 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_full_begin (&objfile -> psymbol_obstack, 0, 0,
- xmmalloc, mfree, objfile -> md,
- OBSTACK_MMALLOC_LIKE);
- obstack_full_begin (&objfile -> symbol_obstack, 0, 0,
- xmmalloc, mfree, objfile -> md,
- OBSTACK_MMALLOC_LIKE);
- obstack_full_begin (&objfile -> type_obstack, 0, 0,
- xmmalloc, mfree, objfile -> md,
- OBSTACK_MMALLOC_LIKE);
+ 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);
}
}
if (objfile == NULL)
{
objfile = (struct objfile *) xmalloc (sizeof (struct objfile));
- (void) memset (objfile, 0, sizeof (struct objfile));
+ memset (objfile, 0, sizeof (struct objfile));
objfile -> md = NULL;
- obstack_full_begin (&objfile -> psymbol_obstack, 0, 0, xmalloc, free,
- (void *) 0, 0);
- obstack_full_begin (&objfile -> symbol_obstack, 0, 0, xmalloc, free,
- (void *) 0, 0);
- obstack_full_begin (&objfile -> type_obstack, 0, 0, xmalloc, free,
- (void *) 0, 0);
-
+ obstack_specify_allocation (&objfile -> psymbol_obstack, 0, 0, xmalloc,
+ free);
+ obstack_specify_allocation (&objfile -> symbol_obstack, 0, 0, xmalloc,
+ free);
+ obstack_specify_allocation (&objfile -> type_obstack, 0, 0, xmalloc,
+ free);
}
/* Update the per-objfile information that comes from the bfd, ensuring
return (objfile);
}
+/* Unlink OBJFILE from the list of known objfiles, if it is found in the
+ list.
+
+ It is not a bug, or error, to call this function if OBJFILE is not known
+ to be in the current list. This is done in the case of mapped objfiles,
+ for example, just to ensure that the mapped objfile doesn't appear twice
+ in the list. Since the list is threaded, linking in a mapped objfile
+ twice would create a circular list.
+
+ If OBJFILE turns out to be in the list, we zap it's NEXT pointer after
+ unlinking it, just to ensure that we have completely severed any linkages
+ between the OBJFILE and the list. */
+
+void
+unlink_objfile (objfile)
+ struct objfile *objfile;
+{
+ struct objfile** objpp;
+
+ for (objpp = &object_files; *objpp != NULL; objpp = &((*objpp) -> next))
+ {
+ if (*objpp == objfile)
+ {
+ *objpp = (*objpp) -> next;
+ objfile -> next = NULL;
+ break;
+ }
+ }
+}
+
/* Destroy an objfile and all the symtabs and psymtabs under it. Note
that as much as possible is allocated on the symbol_obstack and
free_objfile (objfile)
struct objfile *objfile;
{
- struct objfile *ofp;
int mmfd;
/* First do any symbol file specific actions required when we are
if (objfile -> obfd != NULL)
{
+ char *name = bfd_get_filename (objfile->obfd);
bfd_close (objfile -> obfd);
+ free (name);
}
/* Remove it from the chain of all objfiles. */
- if (object_files == objfile)
- {
- object_files = objfile -> next;
- }
- else
- {
- for (ofp = object_files; ofp; ofp = ofp -> next)
- {
- if (ofp -> next == objfile)
- {
- ofp -> next = objfile -> next;
- break;
- }
- }
- }
- objfile -> next = NULL;
-
-#if 0 /* FIXME!! */
+ unlink_objfile (objfile);
/* Before the symbol table code was redone to make it easier to
selectively load and remove information particular to a specific
#endif
clear_pc_function_cache ();
-#endif
-
/* The last thing we do is free the objfile struct itself for the
non-reusable case, or detach from the mapped file for the reusable
case. Note that the mmalloc_detach or the mfree is the last thing
mmfd = objfile -> mmfd;
mmalloc_detach (objfile -> md);
objfile = NULL;
- (void) close (mmfd);
+ close (mmfd);
}
#endif /* !defined(NO_MMALLOC) && defined(HAVE_MMAP) */
{
mfree (objfile -> md, objfile -> name);
}
+ if (objfile->global_psymbols.list)
+ mfree (objfile->md, objfile->global_psymbols.list);
+ if (objfile->static_psymbols.list)
+ mfree (objfile->md, objfile->static_psymbols.list);
/* Free the obstacks for non-reusable objfiles */
obstack_free (&objfile -> psymbol_obstack, 0);
obstack_free (&objfile -> symbol_obstack, 0);
{
if (!mapped)
{
- warning ("mapped symbol file `%s' is out of date", symsfilename);
+ warning ("mapped symbol file `%s' is out of date, ignored it",
+ symsfilename);
}
}
else if ((fd = open (symsfilename, O_RDWR)) < 0)
}
#endif /* !defined(NO_MMALLOC) && defined(HAVE_MMAP) */
-