]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.threads/clone-attach-detach.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.threads / clone-attach-detach.exp
CommitLineData
026a9174
PA
1# This testcase is part of GDB, the GNU debugger.
2
213516ef 3# Copyright 2016-2023 Free Software Foundation, Inc.
026a9174
PA
4
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.
9#
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.
14#
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/>.
17
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.
20
21# This only works on targets with the Linux kernel.
22if ![istarget *-*-linux*] {
23 return
24}
25
26if {![can_spawn_for_attach]} {
27 return 0
28}
29
30standard_testfile
31
32if [prepare_for_testing "failed to prepare" $testfile $srcfile {debug}] {
33 return -1
34}
35
026a9174
PA
36set test_spawn_id [spawn_wait_for_attach $binfile]
37set testpid [spawn_id_get_pid $test_spawn_id]
38
39# Native/gdbserver.
40set thread_re "(LWP $decimal|Thread )"
41
42# Try attach / detach a few times, in case GDB ends up with stale
43# state after detaching.
44
45set attempts 3
46for {set attempt 1} {$attempt <= $attempts} {incr attempt} {
47 with_test_prefix "fg attach $attempt" {
48
49 gdb_test "attach $testpid" \
50 "Attaching to program.*process $testpid.*" \
51 "attach"
52
53 gdb_test "info threads" \
54 "1.*${thread_re}.*\r\n.*2.*${thread_re}.*" \
55 "info threads shows two LWPs"
56
f67c0c91 57 gdb_test "detach" "Detaching from .*, process $testpid\r\n\\\[Inferior $decimal \\(.*\\) detached\\\]"
026a9174
PA
58 }
59}
60
61# Same, but use async/background attach.
62
63# If debugging with target remote, check whether the all-stop variant
64# of the RSP is being used. If so, we can't run the background tests.
65if {[target_info exists gdb_protocol]
66 && ([target_info gdb_protocol] == "remote"
67 || [target_info gdb_protocol] == "extended-remote")} {
68
69 set test "maint show target-non-stop"
70 gdb_test_multiple "maint show target-non-stop" $test {
71 -re "(is|currently) on.*$gdb_prompt $" {
72 }
73 -re "(is|currently) off.*$gdb_prompt $" {
74 unsupported "bg attach: can't issue info threads while target is running"
75 return 0
76 }
77 }
78}
79
80set attempts 3
81for {set attempt 1} {$attempt <= $attempts} {incr attempt} {
82 with_test_prefix "bg attach $attempt" {
83
84 gdb_test "attach $testpid &" \
85 "Attaching to program.*process $testpid.*" \
86 "attach"
87
88 gdb_test "info threads" \
89 "1.*${thread_re}.*\\(running\\)\r\n.*2.*${thread_re}.*\\(running\\)" \
90 "info threads shows two LWPs"
91
f67c0c91 92 gdb_test "detach" "Detaching from .*, process $testpid\r\n\\\[Inferior $decimal \\(.*\\) detached\\\]"
026a9174
PA
93 }
94}
95
96kill_wait_spawned_process $test_spawn_id