1 1.1 christos # This testcase is part of GDB, the GNU debugger. 2 1.1 christos 3 1.1 christos # Copyright 2020-2023 Free Software Foundation, Inc. 4 1.1 christos 5 1.1 christos # This program is free software; you can redistribute it and/or modify 6 1.1 christos # it under the terms of the GNU General Public License as published by 7 1.1 christos # the Free Software Foundation; either version 3 of the License, or 8 1.1 christos # (at your option) any later version. 9 1.1 christos # 10 1.1 christos # This program is distributed in the hope that it will be useful, 11 1.1 christos # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 1.1 christos # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 1.1 christos # GNU General Public License for more details. 14 1.1 christos # 15 1.1 christos # You should have received a copy of the GNU General Public License 16 1.1 christos # along with this program. If not, see <http://www.gnu.org/licenses/>. 17 1.1 christos 18 1.1 christos # Test attaching to a process, as a second inferior, through a 19 1.1 christos # gdbserver that does not support multi-process extensions. 20 1.1 christos 21 1.1 christos load_lib gdbserver-support.exp 22 1.1 christos 23 1.1 christos standard_testfile 24 1.1 christos 25 1.1 christos if { [skip_gdbserver_tests] } { 26 1.1 christos return 0 27 1.1 christos } 28 1.1 christos 29 1.1 christos if {![can_spawn_for_attach]} { 30 1.1 christos return 31 1.1 christos } 32 1.1 christos 33 1.1 christos if {[build_executable "build" $testfile $srcfile {debug}] == -1} { 34 1.1 christos return -1 35 1.1 christos } 36 1.1 christos 37 1.1 christos proc test {target_non_stop} { 38 1.1 christos global binfile 39 1.1 christos global gdb_prompt 40 1.1 christos 41 1.1 christos save_vars { ::GDBFLAGS } { 42 1.1 christos # If GDB and GDBserver are both running locally, set the sysroot to avoid 43 1.1 christos # reading files via the remote protocol. 44 1.1 christos if { ![is_remote host] && ![is_remote target] } { 45 1.1 christos set ::GDBFLAGS "${::GDBFLAGS} -ex \"set sysroot\"" 46 1.1 christos } 47 1.1 christos set ::GDBFLAGS \ 48 1.1 christos "${::GDBFLAGS} -ex \"set remote multiprocess-feature-packet off\"" 49 1.1 christos set ::GDBFLAGS \ 50 1.1 christos "${::GDBFLAGS} -ex \"maint set target-non-stop ${target_non_stop}\"" 51 1.1 christos clean_restart ${binfile} 52 1.1 christos } 53 1.1 christos 54 1.1 christos # Start the first inferior. 55 1.1 christos if {![runto_main]} { 56 1.1 christos return 57 1.1 christos } 58 1.1 christos 59 1.1 christos # The second inferior is an extended remote. 60 1.1 christos gdb_test "add-inferior -no-connection" "Added inferior 2.*" \ 61 1.1 christos "add the second inferior" 62 1.1 christos gdb_test "inferior 2" ".*Switching to inferior 2.*" \ 63 1.1 christos "switch to inferior 2" 64 1.1 christos set res [gdbserver_start "--multi" ""] 65 1.1 christos set gdbserver_gdbport [lindex $res 1] 66 1.1 christos gdb_target_cmd "extended-remote" $gdbserver_gdbport 67 1.1 christos 68 1.1 christos # Start a program, then attach to it. 69 1.1 christos set spawn_id_list [spawn_wait_for_attach [list $binfile]] 70 1.1 christos set test_spawn_id [lindex $spawn_id_list 0] 71 1.1 christos set testpid [spawn_id_get_pid $test_spawn_id] 72 1.1 christos gdb_test_multiple "attach $testpid" "attach to the program via remote" { 73 1.1 christos -re "Attaching to Remote target.*\[\r\n\]+$gdb_prompt " { 74 1.1 christos pass $gdb_test_name 75 1.1 christos } 76 1.1 christos } 77 1.1 christos 78 1.1 christos # Check that we have two threads. Bad GDB duplicated the 79 1.1 christos # thread coming from the remote when target-non-stop is off; 80 1.1 christos # or hanged during attach when target-non-stop is on. 81 1.1 christos gdb_test "info threads" \ 82 1.1 christos [multi_line \ 83 1.1 christos " Id\[^\r\n\]+" \ 84 1.1 christos " 1\.1\[^\r\n\]+" \ 85 1.1 christos ". 2\.1\[^\r\n\]+" 86 1.1 christos ] 87 1.1 christos 88 1.1 christos # Clean the spawned process and gdbserver. 89 1.1 christos gdbserver_exit 0 90 1.1 christos kill_wait_spawned_process $test_spawn_id 91 1.1 christos } 92 1.1 christos 93 1.1 christos foreach_with_prefix target_non_stop {off on} { 94 1.1 christos test $target_non_stop 95 1.1 christos } 96