1 # Copyright 2016-2024 Free Software Foundation, Inc.
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.
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.
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/>.
16 # Test that -exec-run works as expected. Exercises various testing
19 # - MI running on main UI vs separate UI.
21 # - inferior tty set to main tty vs separate tty.
23 # - forking the child failing and sending output to the right inferior
24 # terminal, vs the child not failing to start.
26 load_lib mi-support.exp
29 # The purpose of this testcase is to test the -exec-run command. If we
30 # cannot use it, then there is no point in running this testcase.
33 standard_testfile mi-start.c
35 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
36 untested "could not build mi-exec-run"
40 # The test proper. INFTTY_MODE determines whether "set inferior-tty"
41 # is in effect. MI_MODE determines whether MI is run on the main UI,
42 # or as a separate UI. FORCE_FAIL is true when we want -exec-run to
43 # fail and cause inferior output be sent to the inferior tty.
45 proc test {inftty_mode mi_mode force_fail} {
46 global srcdir subdir binfile srcfile
47 global gdb_spawn_id gdb_main_spawn_id mi_spawn_id inferior_spawn_id
53 if {$inftty_mode == "separate"} {
54 lappend start_ops "separate-inferior-tty"
56 if {$mi_mode == "separate"} {
57 lappend start_ops "separate-mi-tty"
60 if [mi_gdb_start $start_ops] {
65 # Disable the shell so that it's the first exec that fails,
66 # instead of the shell starting and then failing with some
68 mi_gdb_test "-gdb-set startup-with-shell off" ".*"
75 mi_gdb_reinitialize_dir $srcdir/$subdir
78 # Useful for debugging:
79 verbose -log "Channels:"
80 verbose -log " inferior_spawn_id=$inferior_spawn_id"
81 verbose -log " gdb_spawn_id=$gdb_spawn_id"
82 verbose -log " gdb_main_spawn_id=$gdb_main_spawn_id"
83 verbose -log " mi_spawn_id=$mi_spawn_id"
89 set test "run failure detected"
90 send_gdb "-exec-run --start\n"
92 # Redirect through SPAWN_LIST global. If the
93 # inferior_spawn_id is not the same as gdb_spawn_id, e.g. when
94 # testing with gdbserver, the gdbserver can exit after
95 # emitting it's error message.
97 # If inferior_spawn_id exits then we may see the eof from that
98 # spawn-id before we see the pattern from the gdb_spawn_id,
99 # which will kick us out of the gdb_expect, and cause us to
102 # Instead we clean SPAWN_LIST once we've seen the expected
103 # pattern from that spawn-id, and after that we no longer care
104 # when gdbserver exits.
106 set spawn_list "$inferior_spawn_id"
110 -re ".*Cannot exec.*Permission denied" {
113 verbose -log "saw perm error"
114 if {!$saw_mi_error} {
119 -re "\\^error,msg=\"(During startup program exited with code 127|Running .* on the remote target failed)" {
121 verbose -log "saw mi error"
122 if {!$saw_perm_error} {
128 fail "$test (timeout)"
130 -i "$gdb_main_spawn_id"
137 if {$saw_perm_error && $saw_mi_error} {
139 } elseif {!$already_failed} {
140 verbose -log "saw_perm_error=$saw_perm_error; saw_mi_error=$saw_mi_error"
145 mi_expect_stop "breakpoint-hit" "main" "" ".*$srcfile" "$decimal" \
146 { "" "disp=\"del\"" } "breakpoint hit reported on mi"
148 if {$mi_mode == "separate"} {
149 # Check that the breakpoint hit is reported on the main
150 # UI/CLI. Note no prompt is expected.
151 switch_gdb_spawn_id $gdb_main_spawn_id
153 set test "breakpoint hit reported on console"
154 gdb_test_multiple "" $test {
155 -re "Temporary breakpoint .*, main \\(\\) at .*$srcfile:$decimal.*return 0;" {
160 # Switch back to the MI UI.
162 switch_gdb_spawn_id $mi_spawn_id
167 # Create a not-executable copy of the program, in order to exercise
168 # vfork->exec failing.
169 gdb_remote_download host $binfile $binfile.nox
170 remote_exec target "chmod \"a-x\" $binfile.nox"
172 foreach_with_prefix inferior-tty {"main" "separate"} {
173 foreach_with_prefix mi {"main" "separate"} {
174 foreach_with_prefix force-fail {0 1} {
175 test ${inferior-tty} ${mi} ${force-fail}