1# Copyright (C) 2015 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# Check that "gdb -batch -ex run" does not leave the terminal in the 17# wrong state. 18 19standard_testfile 20 21if {[build_executable "failed to prepare" $testfile $srcfile debug] == -1} { 22 return -1 23} 24 25set file_arg $binfile 26if [is_remote host] { 27 set file_arg [remote_download host $file_arg] 28} 29 30global GDBFLAGS 31set saved_gdbflags $GDBFLAGS 32 33# The shell's prompt. 34set shell_prompt "$ " 35set shell_prompt_re [string_to_regexp $shell_prompt] 36 37# Spawn shell. Returns true on success, false otherwise. 38 39proc spawn_shell {} { 40 global shell_prompt_re 41 42 set res [remote_spawn host "/bin/sh"] 43 if { $res < 0 || $res == "" } { 44 unsupported "Spawning shell failed." 45 return 0 46 } 47 48 set gotit 0 49 set test "spawn shell" 50 gdb_expect { 51 -re "$shell_prompt_re$" { 52 pass $test 53 set gotit 1 54 } 55 timeout { 56 fail "$test (timeout)" 57 } 58 eof { 59 fail "$test (eof)" 60 } 61 } 62 63 return $gotit 64} 65 66# Exit the shell. 67 68proc exit_shell {} { 69 global shell_prompt_re 70 71 set test "exit shell" 72 send_gdb "exit\n" 73 gdb_expect { 74 timeout { 75 fail "$test (timeout)" 76 return 0 77 } 78 eof { 79 pass "$test" 80 } 81 } 82 if ![is_remote host] { 83 remote_close host 84 } 85} 86 87# Run "stty" and store the output in $result. Returns true on 88# success, false otherwise. 89 90proc run_stty {message result} { 91 global shell_prompt_re 92 93 upvar $result output 94 95 send_gdb "stty || echo \"not found\"\n" 96 set gotit 0 97 gdb_expect { 98 -re "not found.*not found.*$shell_prompt_re$" { 99 pass "$message (not found)" 100 } 101 -re "(.*)$shell_prompt_re$" { 102 set output $expect_out(1,string) 103 set gotit 1 104 pass $message 105 } 106 timeout { 107 fail "$message (timeout)" 108 } 109 eof { 110 fail "$message (eof)" 111 } 112 } 113 return $gotit 114} 115 116# Check that "gdb -batch -ex run" does not leave the terminal in the 117# wrong state. 118 119proc test_terminal_settings_preserved {} { 120 global file_arg 121 global GDB INTERNAL_GDBFLAGS GDBFLAGS 122 global gdb_prompt pagination_prompt 123 global saved_gdbflags 124 global shell_prompt_re 125 126 if ![spawn_shell] { 127 return 128 } 129 130 set stty_supported [run_stty "stty before" stty_before] 131 132 set test "gdb -batch -ex run" 133 set GDBFLAGS $saved_gdbflags 134 append GDBFLAGS " -batch" 135 append GDBFLAGS " -ex \"set height unlimited\"" 136 append GDBFLAGS " -ex \"start\"" 137 append GDBFLAGS " --args \"$file_arg\"" 138 send_gdb "$GDB $INTERNAL_GDBFLAGS $GDBFLAGS [host_info gdb_opts]\n" 139 gdb_expect { 140 -re "Don't know how to run.*$shell_prompt_re$" { 141 unsupported $test 142 } 143 -re "$gdb_prompt $" { 144 # -batch implies no GDB prompt. 145 fail $test 146 } 147 -re "Temporary breakpoint .*$shell_prompt_re$" { 148 pass $test 149 } 150 timeout { 151 fail "$test (timeout)" 152 } 153 eof { 154 fail "$test (eof)" 155 } 156 } 157 158 set test "echo test_echo" 159 send_gdb "echo test_echo\n" 160 gdb_expect { 161 -re "^echo test_echo\r\ntest_echo\r\n.*$shell_prompt_re$" { 162 pass $test 163 } 164 timeout { 165 fail "$test (timeout)" 166 } 167 eof { 168 fail "$test (eof)" 169 } 170 } 171 172 set test "terminal settings preserved" 173 if $stty_supported { 174 run_stty "stty after" stty_after 175 176 gdb_assert [string equal $stty_before $stty_after] $test 177 } else { 178 unsupported "$test (no stty)" 179 } 180 181 exit_shell 182} 183 184test_terminal_settings_preserved 185 186set GDBFLAGS $saved_gdbflags 187