Support arch-dependent fill
[binutils-gdb.git] / gdb / solib.c
index 6c0a8998e2ee6284bd1abf4c4d66a4a4a3aefa97..84b90190c1347de9deaf4ed418b87d50a9db4b1b 100644 (file)
@@ -1,8 +1,6 @@
 /* Handle shared libraries for GDB, the GNU Debugger.
 
-   Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
-   2000, 2001, 2002, 2003, 2005, 2006, 2007, 2008, 2009, 2010, 2011
-   Free Software Foundation, Inc.
+   Copyright (C) 1990-2003, 2005-2012 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -633,6 +631,20 @@ solib_read_symbols (struct so_list *so, int flags)
   return 0;
 }
 
+/* Return 1 if KNOWN->objfile is used by any other so_list object in the
+   SO_LIST_HEAD list.  Return 0 otherwise.  */
+
+static int
+solib_used (const struct so_list *const known)
+{
+  const struct so_list *pivot;
+
+  for (pivot = so_list_head; pivot != NULL; pivot = pivot->next)
+    if (pivot != known && pivot->objfile == known->objfile)
+      return 1;
+  return 0;
+}
+
 /* Synchronize GDB's shared object list with inferior's.
 
    Extract the list of currently loaded shared objects from the
@@ -746,10 +758,14 @@ update_solib_list (int from_tty, struct target_ops *target)
             unloaded before we remove it from GDB's tables.  */
          observer_notify_solib_unloaded (gdb);
 
+         VEC_safe_push (char_ptr, current_program_space->deleted_solibs,
+                        xstrdup (gdb->so_name));
+
          *gdb_link = gdb->next;
 
          /* Unless the user loaded it explicitly, free SO's objfile.  */
-         if (gdb->objfile && ! (gdb->objfile->flags & OBJF_USERLOADED))
+         if (gdb->objfile && ! (gdb->objfile->flags & OBJF_USERLOADED)
+             && !solib_used (gdb))
            free_objfile (gdb->objfile);
 
          /* Some targets' section tables might be referring to
@@ -780,6 +796,7 @@ update_solib_list (int from_tty, struct target_ops *target)
          volatile struct gdb_exception e;
 
          i->pspace = current_program_space;
+         VEC_safe_push (so_list_ptr, current_program_space->added_solibs, i);
 
          TRY_CATCH (e, RETURN_MASK_ERROR)
            {
@@ -1225,7 +1242,8 @@ reload_shared_libraries_1 (int from_tty)
          || (found_pathname != NULL
              && filename_cmp (found_pathname, so->so_name) != 0))
        {
-         if (so->objfile && ! (so->objfile->flags & OBJF_USERLOADED))
+         if (so->objfile && ! (so->objfile->flags & OBJF_USERLOADED)
+             && !solib_used (so))
            free_objfile (so->objfile);
          remove_target_sections (so->abfd);
          free_so_symbols (so);