]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.server/attach-flag.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.server / attach-flag.exp
1 # This testcase is part of GDB, the GNU debugger.
2
3 # Copyright 2021-2023 Free Software Foundation, Inc.
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
24 if { [skip_gdbserver_tests] } {
25 return 0
26 }
27
28 if {![can_spawn_for_attach]} {
29 return 0
30 }
31
32 # Start the test program, attach to it using gdbserver's --attach flag, connect
33 # to it with GDB, check that what we see makes sense.
34
35 proc run_one_test { non-stop target-non-stop } {
36 save_vars { ::GDBFLAGS } {
37 # If GDB and GDBserver are both running locally, set the sysroot to avoid
38 # reading files via the remote protocol.
39 if { ![is_remote host] && ![is_remote target] } {
40 set ::GDBFLAGS "$::GDBFLAGS -ex \"set sysroot\""
41 }
42
43 if { [prepare_for_testing "failed to prepare" $::testfile $::srcfile \
44 {debug pthreads}] } {
45 return -1
46 }
47 }
48
49 # Make sure we're disconnected, in case we're testing with an
50 # extended-remote board, therefore already connected.
51 gdb_test "disconnect" ".*"
52
53 set target_exec [gdbserver_download_current_prog]
54 set test_spawn_id [spawn_wait_for_attach $::binfile]
55 set testpid [spawn_id_get_pid $test_spawn_id]
56
57 lassign [gdbserver_start "" "--attach $testpid"] unused gdbserver_address
58
59 gdb_test_no_output "set non-stop ${non-stop}"
60 gdb_test_no_output "maint set target-non-stop ${target-non-stop}"
61 gdb_target_cmd "remote" $gdbserver_address
62
63 # There should be 11 threads.
64 gdb_test "thread 11" "Switching to thread 11.*"
65
66 kill_wait_spawned_process $test_spawn_id
67 gdbserver_exit 0
68 }
69
70 foreach_with_prefix non-stop {0 1} {
71 foreach_with_prefix target-non-stop {0 1} {
72 # This combination does not make sense.
73 if { ${non-stop} == 1 && ${target-non-stop} == 0} {
74 continue
75 }
76
77 run_one_test ${non-stop} ${target-non-stop}
78 }
79 }