]>
Commit | Line | Data |
---|---|---|
026a9174 PA |
1 | # This testcase is part of GDB, the GNU debugger. |
2 | ||
1d506c26 | 3 | # Copyright 2016-2024 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. | |
22 | if ![istarget *-*-linux*] { | |
23 | return | |
24 | } | |
25 | ||
06e93b05 | 26 | require can_spawn_for_attach |
026a9174 PA |
27 | |
28 | standard_testfile | |
29 | ||
30 | if [prepare_for_testing "failed to prepare" $testfile $srcfile {debug}] { | |
31 | return -1 | |
32 | } | |
33 | ||
026a9174 PA |
34 | set test_spawn_id [spawn_wait_for_attach $binfile] |
35 | set testpid [spawn_id_get_pid $test_spawn_id] | |
36 | ||
37 | # Native/gdbserver. | |
38 | set thread_re "(LWP $decimal|Thread )" | |
39 | ||
40 | # Try attach / detach a few times, in case GDB ends up with stale | |
41 | # state after detaching. | |
42 | ||
43 | set attempts 3 | |
44 | for {set attempt 1} {$attempt <= $attempts} {incr attempt} { | |
45 | with_test_prefix "fg attach $attempt" { | |
46 | ||
47 | gdb_test "attach $testpid" \ | |
48 | "Attaching to program.*process $testpid.*" \ | |
49 | "attach" | |
50 | ||
51 | gdb_test "info threads" \ | |
52 | "1.*${thread_re}.*\r\n.*2.*${thread_re}.*" \ | |
53 | "info threads shows two LWPs" | |
54 | ||
f67c0c91 | 55 | gdb_test "detach" "Detaching from .*, process $testpid\r\n\\\[Inferior $decimal \\(.*\\) detached\\\]" |
026a9174 PA |
56 | } |
57 | } | |
58 | ||
59 | # Same, but use async/background attach. | |
60 | ||
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")} { | |
66 | ||
47171eeb AB |
67 | if {![is_target_non_stop]} { |
68 | unsupported "bg attach: can't issue info threads while target is running" | |
69 | return 0 | |
026a9174 PA |
70 | } |
71 | } | |
72 | ||
73 | set attempts 3 | |
74 | for {set attempt 1} {$attempt <= $attempts} {incr attempt} { | |
75 | with_test_prefix "bg attach $attempt" { | |
76 | ||
77 | gdb_test "attach $testpid &" \ | |
78 | "Attaching to program.*process $testpid.*" \ | |
79 | "attach" | |
80 | ||
81 | gdb_test "info threads" \ | |
82 | "1.*${thread_re}.*\\(running\\)\r\n.*2.*${thread_re}.*\\(running\\)" \ | |
83 | "info threads shows two LWPs" | |
84 | ||
f67c0c91 | 85 | gdb_test "detach" "Detaching from .*, process $testpid\r\n\\\[Inferior $decimal \\(.*\\) detached\\\]" |
026a9174 PA |
86 | } |
87 | } | |
88 | ||
89 | kill_wait_spawned_process $test_spawn_id |