diff --git a/gdb/testsuite/lib/rocm.exp b/gdb/testsuite/lib/rocm.exp
index 3eb51dbb52f..ca581c4772f 100644
--- a/gdb/testsuite/lib/rocm.exp
+++ b/gdb/testsuite/lib/rocm.exp
@@ -177,21 +177,43 @@ proc hip_devices_support_debug_multi_process {} {
     return 1
 }
 
-# Return true if all the devices on the host support precise memory.
+# Helper function which returns if all ROCm devices in the system have
+# the CAP capabilities.  Capabilities are defined in
+# /usr/include/linux/kfd_sysfs.h.
 
-proc hip_devices_support_precise_memory {} {
-    set unsupported_targets \
-	{gfx900 gfx906 gfx908 gfx1010 gfx1011 gfx1012 gfx1030 gfx1031 gfx1032}
+proc hip_devices_have_cap {cap} {
+    set prop_files \
+	[glob /sys/devices/virtual/kfd/kfd/topology/nodes/*/properties]
 
-    set targets [find_amdgpu_devices]
-    if { [llength $targets] == 0 } {
+    if {[llength $prop_files] == 0} {
 	return 0
     }
 
-    foreach target $targets {
-	if { [lsearch -exact $unsupported_targets $target] != -1 } {
-	    return 0
+    set gpu_with_support 0
+    foreach f $prop_files {
+	set fd [open $f]
+	while { [gets $fd line] >= 0 } {
+	    set x [split $line " "]
+	    set prop_name [lindex $x 0]
+	    set val [lindex $x 1]
+	    if {$prop_name eq "capability"} {
+		if {[expr $val & $cap]} {
+		    incr gpu_with_support
+		}
+	    }
 	}
+	close $fd
     }
-    return 1
+
+    return [expr [llength prop_files] == $gpu_with_support]
+}
+
+# Return true if all the devices on the host support precise memory.
+
+proc hip_devices_support_precise_memory {} {
+    # From /usr/include/linux/kfd_sysfs.h
+    set HSA_CAP_TRAP_DEBUG_PRECISE_MEMORY_OPERATIONS_SUPPORTED 0x00040000
+
+    return [hip_devices_have_cap \
+	    $HSA_CAP_TRAP_DEBUG_PRECISE_MEMORY_OPERATIONS_SUPPORTED]
 }
