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