xref: /netbsd-src/external/gpl3/gdb.old/dist/gdb/testsuite/gdb.base/term.exp (revision 70f7362772ba52b749c976fb5e86e39a8b2c9afc)
1#   Copyright 1988-2020 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# Test that GDB saves and restores terminal settings correctly.  Also check
17# the output of the "info terminal" command.
18
19if { [prepare_for_testing "failed to prepare" term term.c] } {
20    return -1
21}
22
23# Once before running the program.
24gdb_test "info terminal" \
25    "No saved terminal information.*" \
26    "test info terminal pre-execution"
27
28if ![runto break_here] then {
29    fail "can't run to break_here"
30    return 0
31}
32
33# Read the inferior's terminal settings, saved in the T global variable.
34
35proc 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]
40
41    return [array get termios]
42}
43
44# Validate that gdb's notion of the inferior's terminal settings are consistent
45# with the values read from the inferior.
46
47proc compare_gdb_and_inferior_settings { t } {
48    global decimal
49    array set termios $t
50
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)}.*" ]
57}
58
59if {[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]
65    }
66
67    # Continue until after the inferior removes ECHO from its terminal settings.
68    gdb_continue_to_breakpoint "continue until after tcsetattr"
69
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]
75
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)}}
79    }
80
81    # Continue again...
82    gdb_continue_to_breakpoint "continue again"
83
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)}}
93    }
94} else {
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"
98}
99
100delete_breakpoints
101gdb_continue_to_end
102
103# One last time after the program having exited.
104gdb_test "info terminal" \
105    "No saved terminal information.*" \
106    "test info terminal post-execution"
107