diff --git a/gdb/NEWS b/gdb/NEWS
index dddef6525de8..d36aa0707629 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -145,6 +145,10 @@ set debug infcall on|off
 show debug infcall
   Print additional debug messages about inferior function calls.
 
+set debug solib on|off
+show debug solib
+  Print additional debug messages about shared library handling.
+
 set style tui-current-position [on|off]
   Whether to style the source and assembly code highlighted by the
   TUI's current position indicator.  The default is off.
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index bababf3c7ff8..ce4dae11f0d2 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -27812,6 +27812,12 @@ A value greater than 1 provides more verbose information.
 @item show debug symbol-lookup
 Show the current state of symbol lookup debugging messages.
 
+@item set debug solib
+Turns on or off display of debugging messages related to shared libraries.
+The default is off.
+@item show debug solib
+Show the current state of solib debugging messages.
+
 @item set debug symfile
 @cindex symbol file functions
 Turns on or off display of debugging messages related to symbol file functions.
diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
index 6acaf87960bf..d2c1cfa7851e 100644
--- a/gdb/solib-svr4.c
+++ b/gdb/solib-svr4.c
@@ -34,6 +34,7 @@
 #include "regcache.h"
 #include "gdbthread.h"
 #include "observable.h"
+#include "cli/cli-cmds.h"
 
 #include "solist.h"
 #include "solib.h"
@@ -2168,6 +2169,9 @@ svr4_create_probe_breakpoints (svr4_info *info, struct gdbarch *gdbarch,
 	{
 	  CORE_ADDR address = p->get_relocated_address (objfile);
 
+	  solib_debug_printf ("name=%s, addr=%s", probe_info[i].name,
+			      paddress (gdbarch, address));
+
 	  create_solib_event_breakpoint (gdbarch, address);
 	  register_solib_event_probe (info, objfile, p, address, action);
 	}
@@ -2185,6 +2189,9 @@ svr4_find_and_create_probe_breakpoints (svr4_info *info,
 					struct obj_section *os,
 					bool with_prefix)
 {
+  SOLIB_SCOPED_DEBUG_START_END ("objfile=%s, with_prefix=%d",
+				os->objfile->original_name, with_prefix);
+
   std::vector<probe *> probes[NUM_PROBES];
 
   for (int i = 0; i < NUM_PROBES; i++)
@@ -2204,6 +2211,7 @@ svr4_find_and_create_probe_breakpoints (svr4_info *info,
 	}
 
       probes[i] = find_probes_in_objfile (os->objfile, "rtld", name);
+      solib_debug_printf ("probe=%s, num found=%zu", name, probes[i].size ());
 
       /* The "map_failed" probe did not exist in early
 	 versions of the probes code in which the probes'
@@ -2237,6 +2245,7 @@ svr4_find_and_create_probe_breakpoints (svr4_info *info,
     }
 
   /* All probes found.  Now create them.  */
+  solib_debug_printf ("using probes interface");
   svr4_create_probe_breakpoints (info, gdbarch, probes, os->objfile);
   return true;
 }
@@ -2262,7 +2271,11 @@ svr4_create_solib_event_breakpoints (svr4_info *info, struct gdbarch *gdbarch,
   if (os == nullptr
       || (!svr4_find_and_create_probe_breakpoints (info, gdbarch, os, false)
 	  && !svr4_find_and_create_probe_breakpoints (info, gdbarch, os, true)))
-    create_solib_event_breakpoint (gdbarch, address);
+    {
+      solib_debug_printf ("falling back to r_brk breakpoint: addr=%s",
+			  paddress (gdbarch, address));
+      create_solib_event_breakpoint (gdbarch, address);
+    }
 }
 
 /* Helper function for gdb_bfd_lookup_symbol.  */
@@ -3449,6 +3462,14 @@ void _initialize_svr4_solib ();
 void
 _initialize_svr4_solib ()
 {
+  add_setshow_boolean_cmd ("solib", class_maintenance,
+			   &debug_solib, _("\
+Set solib debugging."), _("\
+Show solib debugging."), _("\
+When true, solib-related debugging output is enabled."),
+			    nullptr, nullptr,
+			    &setdebuglist, &showdebuglist);
+
   gdb::observers::free_objfile.attach (svr4_free_objfile_observer,
 				       "solib-svr4");
 }
diff --git a/gdb/solib.c b/gdb/solib.c
index 7cfdd81114c4..aafdb85db3be 100644
--- a/gdb/solib.c
+++ b/gdb/solib.c
@@ -55,13 +55,9 @@
 #include "cli/cli-style.h"
 #include "solib-target.h"
 
-/* Architecture-specific operations.  */
-
-
-
-/* external data declarations */
+/* See solib.h.  */
 
-/* Local function prototypes */
+bool debug_solib;
 
 /* If non-empty, this is a search path for loading non-absolute shared library
    symbol files.  This takes precedence over the environment variables PATH
diff --git a/gdb/solib.h b/gdb/solib.h
index a7e751ed9b31..74066680ef9c 100644
--- a/gdb/solib.h
+++ b/gdb/solib.h
@@ -29,6 +29,18 @@ struct program_space;
 #include "gdb_bfd.h"
 #include "symfile-add-flags.h"
 
+/* Value of the 'set debug solib' configuration variable.  */
+
+extern bool debug_solib;
+
+/* Print an "solib" debug statement.  */
+
+#define solib_debug_printf(fmt, ...) \
+  debug_prefixed_printf_cond (debug_solib, "solib", fmt, ##__VA_ARGS__)
+
+#define SOLIB_SCOPED_DEBUG_START_END(fmt, ...) \
+  scoped_debug_start_end (debug_solib, "solib", fmt, ##__VA_ARGS__)
+
 /* Called when we free all symtabs, to free the shared library information
    as well.  */
 
