]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.multi/attach-no-multi-process.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.multi / attach-no-multi-process.exp
1 # This testcase is part of GDB, the GNU debugger.
2
3 # Copyright 2020-2024 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 process, as a second inferior, through a
19 # gdbserver that does not support multi-process extensions.
20
21 load_lib gdbserver-support.exp
22
23 standard_testfile
24
25 require allow_gdbserver_tests
26
27 require can_spawn_for_attach
28
29 if {[build_executable "build" $testfile $srcfile {debug}] == -1} {
30 return -1
31 }
32
33 proc test {target_non_stop} {
34 global binfile
35 global gdb_prompt
36
37 save_vars { ::GDBFLAGS } {
38 # If GDB and GDBserver are both running locally, set the sysroot to avoid
39 # reading files via the remote protocol.
40 if { ![is_remote host] && ![is_remote target] } {
41 set ::GDBFLAGS "${::GDBFLAGS} -ex \"set sysroot\""
42 }
43 set ::GDBFLAGS \
44 "${::GDBFLAGS} -ex \"set remote multiprocess-feature-packet off\""
45 set ::GDBFLAGS \
46 "${::GDBFLAGS} -ex \"maint set target-non-stop ${target_non_stop}\""
47 clean_restart ${binfile}
48 }
49
50 # Start the first inferior.
51 if {![runto_main]} {
52 return
53 }
54
55 # The second inferior is an extended remote.
56 gdb_test "add-inferior -no-connection" "Added inferior 2.*" \
57 "add the second inferior"
58 gdb_test "inferior 2" ".*Switching to inferior 2.*" \
59 "switch to inferior 2"
60 set res [gdbserver_start "--multi" ""]
61 set gdbserver_gdbport [lindex $res 1]
62 gdb_target_cmd "extended-remote" $gdbserver_gdbport
63
64 # Start a program, then attach to it.
65 set spawn_id_list [spawn_wait_for_attach [list $binfile]]
66 set test_spawn_id [lindex $spawn_id_list 0]
67 set testpid [spawn_id_get_pid $test_spawn_id]
68 gdb_test_multiple "attach $testpid" "attach to the program via remote" {
69 -re "Attaching to Remote target.*\[\r\n\]+$gdb_prompt " {
70 pass $gdb_test_name
71 }
72 }
73
74 # Check that we have two threads. Bad GDB duplicated the
75 # thread coming from the remote when target-non-stop is off;
76 # or hanged during attach when target-non-stop is on.
77 gdb_test "info threads" \
78 [multi_line \
79 " Id\[^\r\n\]+" \
80 " 1\.1\[^\r\n\]+" \
81 ". 2\.1\[^\r\n\]+"
82 ]
83
84 # Clean the spawned process and gdbserver.
85 gdbserver_exit 0
86 kill_wait_spawned_process $test_spawn_id
87 }
88
89 foreach_with_prefix target_non_stop {off on} {
90 test $target_non_stop
91 }