+/* Reload shared libraries, but avoid reloading the same symbol file
+ we already have loaded. */
+
+static void
+reload_shared_libraries_1 (int from_tty)
+{
+ struct so_list *so;
+ struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
+
+ for (so = so_list_head; so != NULL; so = so->next)
+ {
+ char *filename, *found_pathname = NULL;
+ bfd *abfd;
+ int scratch_chan;
+ int was_loaded = so->symbols_loaded;
+ const int flags =
+ SYMFILE_DEFER_BP_RESET | (from_tty ? SYMFILE_VERBOSE : 0);
+
+ filename = tilde_expand (so->so_original_name);
+ abfd = solib_bfd_open (filename);
+ if (abfd != NULL)
+ {
+ found_pathname = xstrdup (bfd_get_filename (abfd));
+ make_cleanup (xfree, found_pathname);
+ gdb_bfd_close_or_warn (abfd);
+ }
+
+ /* If this shared library is no longer associated with its previous
+ symbol file, close that. */
+ if ((found_pathname == NULL && was_loaded)
+ || (found_pathname != NULL
+ && strcmp (found_pathname, so->so_name) != 0))
+ {
+ if (so->objfile && ! (so->objfile->flags & OBJF_USERLOADED))
+ free_objfile (so->objfile);
+ remove_target_sections (so->abfd);
+ free_so_symbols (so);
+ }
+
+ /* If this shared library is now associated with a new symbol
+ file, open it. */
+ if (found_pathname != NULL
+ && (!was_loaded
+ || strcmp (found_pathname, so->so_name) != 0))
+ {
+ volatile struct gdb_exception e;
+
+ TRY_CATCH (e, RETURN_MASK_ERROR)
+ solib_map_sections (so);
+
+ if (e.reason < 0)
+ exception_fprintf (gdb_stderr, e, _("\
+Error while mapping shared library sections:\n"));
+ else if (auto_solib_add || was_loaded || libpthread_solib_p (so))
+ solib_read_symbols (so, flags);
+ }
+ }
+
+ do_cleanups (old_chain);
+}
+