1 # This testcase is part of GDB, the GNU debugger.
3 # Copyright 2016-2018 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 if {![can_spawn_for_attach]} {
32 if [prepare_for_testing "failed to prepare" $testfile $srcfile {debug}] {
36 clean_restart ${binfile}
38 set test_spawn_id [spawn_wait_for_attach $binfile]
39 set testpid [spawn_id_get_pid $test_spawn_id]
42 set thread_re "(LWP $decimal|Thread )"
44 # Try attach / detach a few times, in case GDB ends up with stale
45 # state after detaching.
48 for {set attempt 1} {$attempt <= $attempts} {incr attempt} {
49 with_test_prefix "fg attach $attempt" {
51 gdb_test "attach $testpid" \
52 "Attaching to program.*process $testpid.*" \
55 gdb_test "info threads" \
56 "1.*${thread_re}.*\r\n.*2.*${thread_re}.*" \
57 "info threads shows two LWPs"
59 gdb_test "detach" "Detaching from .*, process $testpid"
63 # Same, but use async/background attach.
65 # If debugging with target remote, check whether the all-stop variant
66 # of the RSP is being used. If so, we can't run the background tests.
67 if {[target_info exists gdb_protocol]
68 && ([target_info gdb_protocol] == "remote"
69 || [target_info gdb_protocol] == "extended-remote")} {
71 set test "maint show target-non-stop"
72 gdb_test_multiple "maint show target-non-stop" $test {
73 -re "(is|currently) on.*$gdb_prompt $" {
75 -re "(is|currently) off.*$gdb_prompt $" {
76 unsupported "bg attach: can't issue info threads while target is running"
83 for {set attempt 1} {$attempt <= $attempts} {incr attempt} {
84 with_test_prefix "bg attach $attempt" {
86 gdb_test "attach $testpid &" \
87 "Attaching to program.*process $testpid.*" \
90 gdb_test "info threads" \
91 "1.*${thread_re}.*\\(running\\)\r\n.*2.*${thread_re}.*\\(running\\)" \
92 "info threads shows two LWPs"
94 gdb_test "detach" "Detaching from .*, process $testpid"
98 kill_wait_spawned_process $test_spawn_id