Remove obsolete test from gdb.cp/var-tag.exp
[binutils-gdb.git] / gdb / testsuite / gdb.threads / clone-attach-detach.exp
blobde1f6a445a45592c7960a7c7a3f6a4b729e8232c
1 # This testcase is part of GDB, the GNU debugger.
3 # Copyright 2016-2024 Free Software Foundation, Inc.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 # Test attach / detach from a process that uses raw clone.  We use raw
19 # clone as proxy for when libthread_db is not available.
21 # This only works on targets with the Linux kernel.
22 if ![istarget *-*-linux*] {
23     return
26 require can_spawn_for_attach
28 standard_testfile
30 if [prepare_for_testing "failed to prepare" $testfile $srcfile {debug}] {
31     return -1
34 set test_spawn_id [spawn_wait_for_attach $binfile]
35 set testpid [spawn_id_get_pid $test_spawn_id]
37 # Native/gdbserver.
38 set thread_re "(LWP $decimal|Thread )"
40 # Try attach / detach a few times, in case GDB ends up with stale
41 # state after detaching.
43 set attempts 3
44 for {set attempt 1} {$attempt <= $attempts} {incr attempt} {
45     with_test_prefix "fg attach $attempt" {
47         gdb_test "attach $testpid" \
48             "Attaching to program.*process $testpid.*" \
49             "attach"
51         gdb_test "info threads" \
52             "1.*${thread_re}.*\r\n.*2.*${thread_re}.*" \
53             "info threads shows two LWPs"
55         gdb_test "detach" "Detaching from .*, process $testpid\r\n\\\[Inferior $decimal \\(.*\\) detached\\\]"
56     }
59 # Same, but use async/background attach.
61 # If debugging with target remote, check whether the all-stop variant
62 # of the RSP is being used.  If so, we can't run the background tests.
63 if {[target_info exists gdb_protocol]
64     && ([target_info gdb_protocol] == "remote"
65         || [target_info gdb_protocol] == "extended-remote")} {
67     if {![is_target_non_stop]} {
68         unsupported "bg attach: can't issue info threads while target is running"
69         return 0
70     }
73 set attempts 3
74 for {set attempt 1} {$attempt <= $attempts} {incr attempt} {
75     with_test_prefix "bg attach $attempt" {
77         gdb_test "attach $testpid &" \
78             "Attaching to program.*process $testpid.*" \
79             "attach"
81         gdb_test "info threads" \
82             "1.*${thread_re}.*\\(running\\)\r\n.*2.*${thread_re}.*\\(running\\)" \
83             "info threads shows two LWPs"
85         gdb_test "detach" "Detaching from .*, process $testpid\r\n\\\[Inferior $decimal \\(.*\\) detached\\\]"
86     }
89 kill_wait_spawned_process $test_spawn_id