1 # Copyright (C) 2015 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 # Check that "gdb -batch -ex run" does not leave the terminal in the
21 if {[build_executable "failed to prepare" $testfile $srcfile debug] == -1} {
27 set file_arg [remote_download host $file_arg]
32 set shell_prompt_re [string_to_regexp $shell_prompt]
34 # Spawn shell. Returns true on success, false otherwise.
37 global shell_prompt_re
39 set res [remote_spawn host "/bin/sh"]
40 if { $res < 0 || $res == "" } {
41 unsupported "Spawning shell failed."
46 set test "spawn shell"
48 -re "$shell_prompt_re$" {
53 fail "$test (timeout)"
66 global shell_prompt_re
72 fail "$test (timeout)"
79 if ![is_remote host] {
84 # Run "stty" and store the output in $result. Returns true on
85 # success, false otherwise.
87 proc run_stty {message result} {
88 global shell_prompt_re
92 send_gdb "stty || echo \"not found\"\n"
95 -re "not found.*not found.*$shell_prompt_re$" {
96 pass "$message (not found)"
98 -re "(.*)$shell_prompt_re$" {
99 set output $expect_out(1,string)
104 fail "$message (timeout)"
107 fail "$message (eof)"
113 # Check that "gdb -batch -ex run" does not leave the terminal in the
116 proc test_terminal_settings_preserved {} {
118 global GDB INTERNAL_GDBFLAGS GDBFLAGS
120 global shell_prompt_re
126 set stty_supported [run_stty "stty before" stty_before]
128 set test "gdb -batch -ex run"
129 append EXTRA_GDBFLAGS "-batch"
130 append EXTRA_GDBFLAGS " -ex \"set height unlimited\""
131 append EXTRA_GDBFLAGS " -ex \"start\""
132 append EXTRA_GDBFLAGS " --args \"$file_arg\""
133 send_gdb "$GDB $INTERNAL_GDBFLAGS $GDBFLAGS $EXTRA_GDBFLAGS [host_info gdb_opts]\n"
135 -re "Don't know how to run.*$shell_prompt_re$" {
138 -re "$gdb_prompt $" {
139 # -batch implies no GDB prompt.
142 -re "Temporary breakpoint .*$shell_prompt_re$" {
146 fail "$test (timeout)"
153 set test "echo test_echo"
154 send_gdb "echo test_echo\n"
156 -re "^echo test_echo\r\ntest_echo\r\n.*$shell_prompt_re$" {
160 fail "$test (timeout)"
167 set test "terminal settings preserved"
169 run_stty "stty after" stty_after
171 gdb_assert [string equal $stty_before $stty_after] $test
173 unsupported "$test (no stty)"
179 test_terminal_settings_preserved