1 # This testcase is part of GDB
, the GNU debugger.
3 # Copyright
2021-2022 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 attaching to a multi
-threaded process using gdbserver
's --attach flag.
20 load_lib gdbserver-support.exp
24 if { [skip_gdbserver_tests] } {
28 if {![can_spawn_for_attach]} {
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.
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\""
43 if { [prepare_for_testing
"failed to prepare" $::testfile $::srcfile \
49 # Make sure we
're disconnected, in case we're testing with an
50 # extended
-remote board
, therefore already connected.
51 gdb_test
"disconnect" ".*"
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
]
57 lassign
[gdbserver_start
"" "--attach $testpid"] unused gdbserver_address
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
63 # There should be
11 threads.
64 gdb_test
"thread 11" "Switching to thread 11.*"
66 kill_wait_spawned_process $test_spawn_id
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} {
77 run_one_test $
{non
-stop
} $
{target
-non
-stop
}