diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index b663277aeb7..99c216b0271 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -8083,9 +8083,8 @@ disable_breakpoints_in_unloaded_shlib (program_space *pspace, const solib &solib
     {
       bool bp_modified = false;
 
-      if (b.type != bp_breakpoint
-	  && b.type != bp_jit_event
-	  && b.type != bp_hardware_breakpoint
+      if (b.type != bp_jit_event
+	  && !is_breakpoint (&b)
 	  && !is_tracepoint (&b))
 	continue;
 
diff --git a/gdb/testsuite/gdb.base/shlib-unload.exp b/gdb/testsuite/gdb.base/shlib-unload.exp
index 791f9f518e8..7516ee2a292 100644
--- a/gdb/testsuite/gdb.base/shlib-unload.exp
+++ b/gdb/testsuite/gdb.base/shlib-unload.exp
@@ -111,4 +111,33 @@ proc_with_prefix test_bp_modified_events {} {
     }
 }
 
+# Check that GDB disables dprintf breakpoints within a shared library
+# when the shared library is unloaded.
+proc_with_prefix test_dprintf_at_unload {} {
+    clean_restart $::binfile
+
+    if {![runto_main]} {
+	return
+    }
+
+    gdb_breakpoint $::srcfile:$::bp_line
+    gdb_continue_to_breakpoint "stop before dlclose"
+
+    # Setup a dprintf within the shared library.
+    gdb_test "dprintf foo,\"In foo\""
+    set bp_num [get_integer_valueof "\$bpnum" "*UNKNOWN*" \
+		    "get b/p number"]
+
+    # Unload the shared library, GDB should disable our b/p.
+    gdb_test "next" $::stop_after_bp_re
+
+    # Check that our b/p is now showing as disabled.
+    gdb_test "info breakpoints $bp_num" \
+	[multi_line \
+	     "^Num\\s+Type\\s+Disp\\s+Enb\\s+Address\\s+What" \
+	     "$bp_num\\s+dprintf\\s+keep\\s+y\\s+<PENDING>\\s+foo" \
+	     "\\s+printf \"In foo\""]
+}
+
 test_bp_modified_events
+test_dprintf_at_unload
