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