-# Copyright (C) 1988, 1990, 1991, 1992, 1997 Free Software Foundation, Inc.
+# Copyright 1988-2018 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
+# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
-#
+#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
-#
+#
# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
-# Please email any bugs, comments, and/or additions to this file to:
-# bug-gdb@prep.ai.mit.edu
+# Test that GDB saves and restores terminal settings correctly. Also check
+# the output of the "info terminal" command.
-# This file was written by Rob Savoye. (rob@cygnus.com)
+if { [prepare_for_testing "failed to prepare" term term.c] } {
+ return -1
+}
-if $tracelevel then {
- strace $tracelevel
+# Once before running the program.
+gdb_test "info terminal" \
+ "No saved terminal information.*" \
+ "test info terminal pre-execution"
+
+if ![runto break_here] then {
+ fail "can't run to break_here"
+ return 0
}
-# This only works for native, I think.
-if ![isnative] then {
- continue
+# Read the inferior's terminal settings, saved in the T global variable.
+
+proc read_term_settings_from_inferior {} {
+ set termios(c_iflag) [get_hexadecimal_valueof "t.c_iflag" oops]
+ set termios(c_oflag) [get_hexadecimal_valueof "t.c_oflag" oops]
+ set termios(c_cflag) [get_hexadecimal_valueof "t.c_cflag" oops]
+ set termios(c_lflag) [get_hexadecimal_valueof "t.c_lflag" oops]
+
+ return [array get termios]
}
-gdb_start
+# Validate that gdb's notion of the inferior's terminal settings are consistent
+# with the values read from the inferior.
-#
-# test running programs
-#
-set prms_id 0
-set bug_id 0
-
-set testfile "run"
-set srcfile ${testfile}.c
-set binfile ${objdir}/${subdir}/${testfile}
-if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
- gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
+proc compare_gdb_and_inferior_settings { t } {
+ global decimal
+ array set termios $t
+
+ gdb_test "info terminal" \
+ [multi_line "Inferior's terminal status .currently saved by GDB.:" \
+ "File descriptor flags = .*" \
+ "Process group = $decimal" \
+ "c_iflag = ${termios(c_iflag)}, c_oflag = ${termios(c_oflag)}," \
+ "c_cflag = ${termios(c_cflag)}, c_lflag = ${termios(c_lflag)}.*" ]
}
-delete_breakpoints
-gdb_reinitialize_dir $srcdir/$subdir
-gdb_load ${binfile}
-
-gdb_test "set print sevenbit-strings" "" "test set print sevenbit-strings"
-gdb_test "set print address off" "" "test set print address off"
-gdb_test "set width 0" "" "test set width 0"
-gdb_test "info terminal" "No saved terminal information.*" "test info terminal"
-gdb_run_cmd 5
-gdb_expect {
- -re ".*120.*Program exited normally.*$gdb_prompt $" {
- gdb_test "info terminal" "No saved terminal information.*" "test info terminal #2"
+if {[target_info gdb_protocol] == ""} {
+ # Record the initial terminal settings. Verify that GDB's version of the
+ # inferior's terminal settings is right.
+ with_test_prefix "initial" {
+ array set termios1 [read_term_settings_from_inferior]
+ compare_gdb_and_inferior_settings [array get termios1]
}
- default {
- fail "term.exp, factorial didn't run to completion for info terminal"
+
+ # Continue until after the inferior removes ECHO from its terminal settings.
+ gdb_continue_to_breakpoint "continue until after tcsetattr"
+
+ # After the inferior has changed its terminal settings, check that GDB's
+ # saved version reflects the new settings correctly.
+ with_test_prefix "post tcsetattr" {
+ array set termios2 [read_term_settings_from_inferior]
+ compare_gdb_and_inferior_settings [array get termios2]
+
+ # Make sure that the current settings are different than the initial
+ # settings... otherwise this test is meaningless.
+ gdb_assert {${termios1(c_lflag)} != ${termios2(c_lflag)}}
}
-}
-# In mid-execution
-gdb_breakpoint main
-gdb_run_cmd 5
-gdb_expect {
- -re ".*Breakpoint \[0-9\]+,.*main.*if .argc != 2.*$gdb_prompt $" {
- gdb_test "info terminal" "Inferior's terminal status .currently saved by GDB.:.*" "info terminal at breakpoint"
+ # Continue again...
+ gdb_continue_to_breakpoint "continue again"
+
+ # ... and verify again, to validate that when resuming, GDB restored the
+ # inferior's terminal settings correctly.
+ with_test_prefix "after last resume" {
+ array set termios3 [read_term_settings_from_inferior]
+ compare_gdb_and_inferior_settings [array get termios3]
+ gdb_assert {${termios2(c_iflag)} == ${termios3(c_iflag)}}
+ gdb_assert {${termios2(c_oflag)} == ${termios3(c_oflag)}}
+ gdb_assert {${termios2(c_cflag)} == ${termios3(c_cflag)}}
+ gdb_assert {${termios2(c_lflag)} == ${termios3(c_lflag)}}
}
- -re ".*$gdb_prompt $" { fail "info terminal at breakpoint" }
- timeout { fail "(timeout) info terminal at breakpoint" }
+} else {
+ # While only native targets save terminal status, we still test
+ # that the command doesn't misbehave.
+ gdb_test "info terminal" "No saved terminal information\\." "info terminal at breakpoint"
}
+
+delete_breakpoints
+gdb_continue_to_end
+
+# One last time after the program having exited.
+gdb_test "info terminal" \
+ "No saved terminal information.*" \
+ "test info terminal post-execution"