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