1 # Copyright 1988-2020 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 GDB saves and restores terminal settings correctly. Also check
17 # the output of the "info terminal" command.
19 if { [prepare_for_testing "failed to prepare" term term.c] } {
23 # Once before running the program.
24 gdb_test "info terminal" \
25 "No saved terminal information.*" \
26 "test info terminal pre-execution"
28 if ![runto break_here] then {
29 fail "can't run to break_here"
33 # Read the inferior's terminal settings, saved in the T global variable.
35 proc read_term_settings_from_inferior {} {
36 set termios(c_iflag) [get_hexadecimal_valueof "t.c_iflag" oops]
37 set termios(c_oflag) [get_hexadecimal_valueof "t.c_oflag" oops]
38 set termios(c_cflag) [get_hexadecimal_valueof "t.c_cflag" oops]
39 set termios(c_lflag) [get_hexadecimal_valueof "t.c_lflag" oops]
41 return [array get termios]
44 # Validate that gdb's notion of the inferior's terminal settings are consistent
45 # with the values read from the inferior.
47 proc compare_gdb_and_inferior_settings { t } {
51 gdb_test "info terminal" \
52 [multi_line "Inferior's terminal status .currently saved by GDB.:" \
53 "File descriptor flags = .*" \
54 "Process group = $decimal" \
55 "c_iflag = ${termios(c_iflag)}, c_oflag = ${termios(c_oflag)}," \
56 "c_cflag = ${termios(c_cflag)}, c_lflag = ${termios(c_lflag)}.*" ]
59 if {[target_info gdb_protocol] == ""} {
60 # Record the initial terminal settings. Verify that GDB's version of the
61 # inferior's terminal settings is right.
62 with_test_prefix "initial" {
63 array set termios1 [read_term_settings_from_inferior]
64 compare_gdb_and_inferior_settings [array get termios1]
67 # Continue until after the inferior removes ECHO from its terminal settings.
68 gdb_continue_to_breakpoint "continue until after tcsetattr"
70 # After the inferior has changed its terminal settings, check that GDB's
71 # saved version reflects the new settings correctly.
72 with_test_prefix "post tcsetattr" {
73 array set termios2 [read_term_settings_from_inferior]
74 compare_gdb_and_inferior_settings [array get termios2]
76 # Make sure that the current settings are different than the initial
77 # settings... otherwise this test is meaningless.
78 gdb_assert {${termios1(c_lflag)} != ${termios2(c_lflag)}}
82 gdb_continue_to_breakpoint "continue again"
84 # ... and verify again, to validate that when resuming, GDB restored the
85 # inferior's terminal settings correctly.
86 with_test_prefix "after last resume" {
87 array set termios3 [read_term_settings_from_inferior]
88 compare_gdb_and_inferior_settings [array get termios3]
89 gdb_assert {${termios2(c_iflag)} == ${termios3(c_iflag)}}
90 gdb_assert {${termios2(c_oflag)} == ${termios3(c_oflag)}}
91 gdb_assert {${termios2(c_cflag)} == ${termios3(c_cflag)}}
92 gdb_assert {${termios2(c_lflag)} == ${termios3(c_lflag)}}
95 # While only native targets save terminal status, we still test
96 # that the command doesn't misbehave.
97 gdb_test "info terminal" "No saved terminal information\\." "info terminal at breakpoint"
103 # One last time after the program having exited.
104 gdb_test "info terminal" \
105 "No saved terminal information.*" \
106 "test info terminal post-execution"