+/* 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);
+}
+
+static void
+reload_shared_libraries (char *ignored, int from_tty,
+ struct cmd_list_element *e)
+{
+ struct target_so_ops *ops;
+
+ reload_shared_libraries_1 (from_tty);
+
+ ops = solib_ops (target_gdbarch);
+
+ /* Creating inferior hooks here has two purposes. First, if we reload
+ shared libraries then the address of solib breakpoint we've computed
+ previously might be no longer valid. For example, if we forgot to set
+ solib-absolute-prefix and are setting it right now, then the previous
+ breakpoint address is plain wrong. Second, installing solib hooks
+ also implicitly figures were ld.so is and loads symbols for it.
+ Absent this call, if we've just connected to a target and set
+ solib-absolute-prefix or solib-search-path, we'll lose all information
+ about ld.so. */
+ if (target_has_execution)
+ {
+ /* Reset or free private data structures not associated with
+ so_list entries. */
+ ops->clear_solib ();
+
+ /* Remove any previous solib event breakpoint. This is usually
+ done in common code, at breakpoint_init_inferior time, but
+ we're not really starting up the inferior here. */
+ remove_solib_event_breakpoints ();
+
+#ifdef SOLIB_CREATE_INFERIOR_HOOK
+ SOLIB_CREATE_INFERIOR_HOOK (PIDGET (inferior_ptid));
+#else
+ solib_create_inferior_hook (from_tty);
+#endif
+ }
+
+ /* Sometimes the platform-specific hook loads initial shared
+ libraries, and sometimes it doesn't. If it doesn't FROM_TTY will be
+ incorrectly 0 but such solib targets should be fixed anyway. If we
+ made all the inferior hook methods consistent, this call could be
+ removed. Call it only after the solib target has been initialized by
+ solib_create_inferior_hook. */
+
+ solib_add (NULL, 0, NULL, auto_solib_add);
+
+ breakpoint_re_set ();
+
+ /* We may have loaded or unloaded debug info for some (or all)
+ shared libraries. However, frames may still reference them. For
+ example, a frame's unwinder might still point at DWARF FDE
+ structures that are now freed. Also, getting new symbols may
+ change our opinion about what is frameless. */
+ reinit_frame_cache ();
+
+ ops->special_symbol_handling ();
+}
+
+static void
+show_auto_solib_add (struct ui_file *file, int from_tty,
+ struct cmd_list_element *c, const char *value)
+{
+ fprintf_filtered (file, _("Autoloading of shared library symbols is %s.\n"),
+ value);
+}
+
+
+/* Handler for library-specific lookup of global symbol NAME in OBJFILE. Call
+ the library-specific handler if it is installed for the current target. */
+
+struct symbol *
+solib_global_lookup (const struct objfile *objfile,
+ const char *name,
+ const domain_enum domain)
+{
+ struct target_so_ops *ops = solib_ops (target_gdbarch);
+
+ if (ops->lookup_lib_global_symbol != NULL)
+ return ops->lookup_lib_global_symbol (objfile, name, domain);
+ return NULL;
+}
+
+
+extern initialize_file_ftype _initialize_solib; /* -Wmissing-prototypes */
+