]>
Commit | Line | Data |
---|---|---|
abe8cab7 SM |
1 | # This testcase is part of GDB, the GNU debugger. |
2 | ||
1d506c26 | 3 | # Copyright 2021-2024 Free Software Foundation, Inc. |
abe8cab7 SM |
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 attaching to a multi-threaded process using gdbserver's --attach flag. | |
19 | ||
20 | load_lib gdbserver-support.exp | |
21 | ||
22 | standard_testfile | |
23 | ||
cadfc59b | 24 | require allow_gdbserver_tests |
abe8cab7 | 25 | |
06e93b05 | 26 | require can_spawn_for_attach |
abe8cab7 SM |
27 | |
28 | # Start the test program, attach to it using gdbserver's --attach flag, connect | |
29 | # to it with GDB, check that what we see makes sense. | |
30 | ||
31 | proc run_one_test { non-stop target-non-stop } { | |
32 | save_vars { ::GDBFLAGS } { | |
33 | # If GDB and GDBserver are both running locally, set the sysroot to avoid | |
34 | # reading files via the remote protocol. | |
35 | if { ![is_remote host] && ![is_remote target] } { | |
36 | set ::GDBFLAGS "$::GDBFLAGS -ex \"set sysroot\"" | |
37 | } | |
38 | ||
39 | if { [prepare_for_testing "failed to prepare" $::testfile $::srcfile \ | |
618e9847 | 40 | {debug pthreads additional_flags=-std=gnu99}] } { |
abe8cab7 SM |
41 | return -1 |
42 | } | |
43 | } | |
44 | ||
45 | # Make sure we're disconnected, in case we're testing with an | |
46 | # extended-remote board, therefore already connected. | |
47 | gdb_test "disconnect" ".*" | |
48 | ||
49 | set target_exec [gdbserver_download_current_prog] | |
50 | set test_spawn_id [spawn_wait_for_attach $::binfile] | |
51 | set testpid [spawn_id_get_pid $test_spawn_id] | |
52 | ||
53 | lassign [gdbserver_start "" "--attach $testpid"] unused gdbserver_address | |
54 | ||
55 | gdb_test_no_output "set non-stop ${non-stop}" | |
56 | gdb_test_no_output "maint set target-non-stop ${target-non-stop}" | |
57 | gdb_target_cmd "remote" $gdbserver_address | |
58 | ||
59 | # There should be 11 threads. | |
60 | gdb_test "thread 11" "Switching to thread 11.*" | |
61 | ||
62 | kill_wait_spawned_process $test_spawn_id | |
63 | gdbserver_exit 0 | |
64 | } | |
65 | ||
66 | foreach_with_prefix non-stop {0 1} { | |
67 | foreach_with_prefix target-non-stop {0 1} { | |
68 | # This combination does not make sense. | |
69 | if { ${non-stop} == 1 && ${target-non-stop} == 0} { | |
70 | continue | |
71 | } | |
72 | ||
73 | run_one_test ${non-stop} ${target-non-stop} | |
74 | } | |
75 | } |