1# Copyright 2016-2017 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# Regression test for PR 20494 (User input stops being echoed in CLI). 17# Before that bug was fixed, starting an inferior in a non-main UI 18# would result in GDB saving readline's prepped terminal state as 19# gdb's "own" terminal state (i.e., target_terminal_ours state), 20# resulting in subsequent synchronous execution commands in the main 21# UI disabling input echo. 22 23standard_testfile 24 25set compile_options "debug" 26if {[build_executable $testfile.exp $testfile ${srcfile} ${compile_options}] == -1} { 27 untested "failed to compile" 28 return -1 29} 30 31# Start gdb and create an extra console UI. Start the inferior in the 32# DRIVER console (either "main" or "extra"), and then enter a 33# synchronous execution command in the extra console. Before PR 20494 34# was fixed, if DRIVER was a secondary UI, GDB would lose input echo 35# on the main UI after the synchronous execution command. We test 36# with both main and extra UIs as driver consoles for completeness. 37 38proc echo_test {driver} { 39 global srcfile testfile 40 global gdb_prompt 41 global gdb_spawn_id 42 global gdb_main_spawn_id extra_spawn_id 43 global decimal 44 45 clean_restart $testfile 46 47 # Save the main UI's spawn ID. 48 set gdb_main_spawn_id $gdb_spawn_id 49 50 # Create the new PTY for the secondary console UI. 51 spawn -pty 52 set extra_spawn_id $spawn_id 53 set extra_tty_name $spawn_out(slave,name) 54 gdb_test_multiple "new-ui console $extra_tty_name" "new-ui" { 55 -re "New UI allocated\r\n$gdb_prompt $" { 56 } 57 } 58 59 with_spawn_id $extra_spawn_id { 60 set test "initial prompt on extra console" 61 gdb_test_multiple "" $test { 62 -re "$gdb_prompt $" { 63 pass $test 64 } 65 } 66 } 67 68 set main_console [list $gdb_main_spawn_id "main console"] 69 set extra_console [list $extra_spawn_id "extra console"] 70 71 if {$driver == "main"} { 72 set con1 $main_console 73 set con2 $extra_console 74 } else { 75 set con1 $extra_console 76 set con2 $main_console 77 } 78 79 set con1_spawn_id [lindex $con1 0] 80 set con2_spawn_id [lindex $con2 0] 81 set con1_name [lindex $con1 1] 82 set con2_name [lindex $con2 1] 83 84 set bp_lineno [gdb_get_line_number "set break $con1_name here"] 85 86 with_spawn_id $con1_spawn_id { 87 gdb_test "break $srcfile:$bp_lineno" \ 88 "Breakpoint $decimal .*$srcfile, line $bp_lineno\\." \ 89 "set breakpoint using $con1_name" 90 gdb_run_cmd 91 gdb_test "" "set break $con1_name here .*" "run to breakpoint on $con1_name" 92 } 93 94 with_spawn_id $con2_spawn_id { 95 set test "breakpoint hit reported on $con2_name too" 96 gdb_test_multiple "" $test { 97 -re "Breakpoint $decimal, .* set break $con1_name here " { 98 pass $test 99 } 100 } 101 gdb_test "next" "global = 1;" "next on $con2_name" 102 } 103 104 # Ensure echo remains enabled in both consoles. 105 with_spawn_id $con1_spawn_id { 106 gdb_test "print 1" "^print 1\r\n\\\$1 = 1" "print on $con1_name echoes" 107 } 108 with_spawn_id $con2_spawn_id { 109 gdb_test "print 2" "^print 2\r\n\\\$2 = 2" "print on $con2_name echoes" 110 } 111} 112 113# The test driver. 114 115proc test_driver {} { 116 117 with_test_prefix "extra console as driver" { 118 echo_test "extra" 119 } 120 121 with_test_prefix "main console as driver" { 122 echo_test "main" 123 } 124 125} 126 127test_driver 128