Sun2 native support (untested).
[deliverable/binutils-gdb.git] / gdb / objfiles.c
index 642026c7cdc8a16e8c2f08061170dfd89c1813b5..278aa4490b8474928570e94794fb2388b82ca526 100644 (file)
@@ -95,7 +95,7 @@ allocate_objfile (abfd, mapped)
       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)
        {
@@ -110,6 +110,10 @@ allocate_objfile (abfd, mapped)
          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
        {
@@ -117,20 +121,20 @@ allocate_objfile (abfd, mapped)
             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);
        }
     }
 
@@ -162,15 +166,14 @@ allocate_objfile (abfd, mapped)
   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
@@ -193,6 +196,36 @@ allocate_objfile (abfd, mapped)
   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
@@ -214,7 +247,6 @@ void
 free_objfile (objfile)
      struct objfile *objfile;
 {
-  struct objfile *ofp;
   int mmfd;
 
   /* First do any symbol file specific actions required when we are
@@ -233,29 +265,14 @@ free_objfile (objfile)
 
   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
@@ -270,8 +287,6 @@ free_objfile (objfile)
 #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
@@ -286,7 +301,7 @@ free_objfile (objfile)
       mmfd = objfile -> mmfd;
       mmalloc_detach (objfile -> md);
       objfile = NULL;
-      (void) close (mmfd);
+      close (mmfd);
     }
 
 #endif /* !defined(NO_MMALLOC) && defined(HAVE_MMAP) */
@@ -300,6 +315,10 @@ free_objfile (objfile)
        {
          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);
@@ -416,7 +435,8 @@ open_existing_mapped_file (symsfilename, mtime, mapped)
        {
          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)
@@ -549,4 +569,3 @@ map_to_address ()
 }
 
 #endif /* !defined(NO_MMALLOC) && defined(HAVE_MMAP) */
-
This page took 0.026507 seconds and 4 git commands to generate.