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*] {
26 require can_spawn_for_attach
30 if [prepare_for_testing "failed to prepare" $testfile $srcfile {debug}] {
34 set test_spawn_id [spawn_wait_for_attach $binfile]
35 set testpid [spawn_id_get_pid $test_spawn_id]
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.
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.*" \
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\\\]"
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"
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.*" \
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\\\]"
89 kill_wait_spawned_process $test_spawn_id