1# Copyright 2022-2023 Free Software Foundation, Inc.
2
3# This program is free software; you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation; either version 3 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
16# Test that "start"ing an inferior does not inadvertently stop in another
17# inferior.
18#
19# To achieve this, we start inferior 1 in background, which sleeps for a bit
20# before reaching its main function.  We then "start" inferior 2, which also
21# sleeps before reaching its main function.  The goal is that inferior 1
22# "crosses" inferior 2's start breakpoint (at the time of writing this test, the
23# breakpoint inserted for start is global and has locations in both inferiors).
24# A buggy GDB would report a breakpoint hit in inferior 1.
25
26standard_testfile .c -other.c
27
28if { [use_gdb_stub] } {
29    return
30}
31
32set srcfile_other ${srcfile2}
33set binfile_other ${binfile}-other
34
35if { [build_executable ${testfile}.exp ${binfile} "${srcfile}" {debug}] != 0 } {
36    return -1
37}
38
39if { [build_executable ${testfile}.exp ${binfile_other} "${srcfile_other}" {debug}] != 0 } {
40    return -1
41}
42
43proc do_test {} {
44    # With remote, to be able to start an inferior while another one is
45    # running, we need to use the non-stop variant of the protocol.
46    save_vars { ::GDBFLAGS } {
47	if { [target_info gdb_protocol] == "extended-remote"} {
48	    append ::GDBFLAGS " -ex \"maintenance set target-non-stop on\""
49	}
50
51	clean_restart ${::binfile_other}
52    }
53
54    gdb_test -no-prompt-anchor "run&" "Starting program: .*" "start background inferior"
55    gdb_test "add-inferior" "Added inferior 2.*"
56    gdb_test "inferior 2" "Switching to inferior 2.*"
57    gdb_file_cmd ${::binfile}
58    gdb_test "start" "Thread 2.1 .* hit Temporary breakpoint .*"
59}
60
61do_test
62