diff --git a/gdb/testsuite/gdb.base/attach-pie-noexec.exp b/gdb/testsuite/gdb.base/attach-pie-noexec.exp
index f6aa1c8..30a2f4d 100644
--- a/gdb/testsuite/gdb.base/attach-pie-noexec.exp
+++ b/gdb/testsuite/gdb.base/attach-pie-noexec.exp
@@ -13,8 +13,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
-# Manipulation with PID on target is not supported.
-if [is_remote target] then {
+if {![can_spawn_for_attach]} {
return 0
}
@@ -53,8 +52,10 @@ if {$arch == ""} {
return 0
}
-set testpid [eval exec $binfile &]
-exec sleep 2
+# Start the program running and then wait for a bit, to be sure
+# that it can be attached to.
+
+set testpid [spawn_wait_for_attach $binfile]
gdb_start
file delete -- $binfile
diff --git a/gdb/testsuite/gdb.base/attach-twice.exp b/gdb/testsuite/gdb.base/attach-twice.exp
index 654ceca..f6a9eb6 100644
--- a/gdb/testsuite/gdb.base/attach-twice.exp
+++ b/gdb/testsuite/gdb.base/attach-twice.exp
@@ -13,8 +13,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
-# Manipulation with PID on target is not supported.
-if [is_remote target] then {
+if {![can_spawn_for_attach]} {
return 0
}
@@ -25,8 +24,10 @@ if { [prepare_for_testing ${testfile}.exp $executable] } {
return -1
}
-set testpid [eval exec $binfile &]
-exec sleep 2
+# Start the program running and then wait for a bit, to be sure
+# that it can be attached to.
+
+set testpid [spawn_wait_for_attach $binfile]
set parentpid 0