diff options
author | Patrick Palka <patrick@parcs.ath.cx> | 2015-07-27 11:54:07 -0400 |
---|---|---|
committer | Patrick Palka <patrick@parcs.ath.cx> | 2015-07-29 08:39:41 -0400 |
commit | 18206ca3f9367f1488cdfc1475f8da072e7e9636 (patch) | |
tree | 6939220e0cab7c33bff405eb907c133f9911ebb1 /gdb/testsuite/gdb.base | |
parent | 7afa63c624ae570472381b8e35ce066bf145844a (diff) | |
download | gdb-18206ca3f9367f1488cdfc1475f8da072e7e9636.zip gdb-18206ca3f9367f1488cdfc1475f8da072e7e9636.tar.gz gdb-18206ca3f9367f1488cdfc1475f8da072e7e9636.tar.bz2 |
Make sure terminal settings are restored before exiting
When exiting GDB -- whether it's via the "quit" command, via a SIGTERM,
or otherwise -- we should leave the terminal in the state we acquired
it. To that end, we have to undo any modifications that may have been
made by the TUI (ncurses) or by the CLI (readline).
Tested on x86_64 Debian Stretch.
gdb/ChangeLog:
* top.c: Include "tui/tui.h".
(undo_terminal_modifications_before_exit): New static function.
(quit_force): Use it.
gdb/testsuite/ChangeLog:
* gdb.base/batch-preserve-term-settings.exp
(test_terminal_settings_preserved_after_cli_exit): New test.
Diffstat (limited to 'gdb/testsuite/gdb.base')
-rw-r--r-- | gdb/testsuite/gdb.base/batch-preserve-term-settings.exp | 94 |
1 files changed, 93 insertions, 1 deletions
diff --git a/gdb/testsuite/gdb.base/batch-preserve-term-settings.exp b/gdb/testsuite/gdb.base/batch-preserve-term-settings.exp index 97ffaa4..ca6f173 100644 --- a/gdb/testsuite/gdb.base/batch-preserve-term-settings.exp +++ b/gdb/testsuite/gdb.base/batch-preserve-term-settings.exp @@ -176,4 +176,96 @@ proc test_terminal_settings_preserved {} { exit_shell } -test_terminal_settings_preserved +# Check that quitting from the CLI via the "quit" command does not leave the +# terminal in the wrong state. The GDB commands CMDS are executed before +# quitting. + +proc test_terminal_settings_preserved_after_cli_exit { cmds } { + global file_arg + global GDB INTERNAL_GDBFLAGS GDBFLAGS + global gdb_prompt + global shell_prompt_re + + if ![spawn_shell] { + return + } + + set saved_gdbflags $GDBFLAGS + + set stty_supported [run_stty "stty before" stty_before] + + set test "start gdb" + send_gdb "$GDB $INTERNAL_GDBFLAGS $GDBFLAGS [host_info gdb_opts] --args \"$file_arg\"\n" + gdb_expect { + -re "$gdb_prompt $" { + pass $test + } + timeout { + fail "$test (timeout)" + } + eof { + fail "$test (eof)" + } + } + + foreach cmd $cmds { + set test "run command $cmd" + send_gdb "$cmd\n" + gdb_expect { + -re "$gdb_prompt $" { + pass $test + } + timeout { + fail "$test (timeout)" + } + eof { + fail "$test (eof)" + } + } + } + + set test "quit gdb" + send_gdb "quit\n" + gdb_expect { + -re "(y or n)" { + send_gdb "y\n" + exp_continue + } + -re ".*$shell_prompt_re$" { + pass $test + } + timeout { + fail "$test (timeout)" + } + eof { + fail "$test (eof)" + } + } + + set test "terminal settings preserved" + if $stty_supported { + run_stty "stty after" stty_after + + gdb_assert [string equal $stty_before $stty_after] $test + } else { + unsupported "$test (no stty)" + } + + exit_shell +} + +with_test_prefix "batch run" { + test_terminal_settings_preserved +} + +with_test_prefix "cli exit" { + test_terminal_settings_preserved_after_cli_exit { } +} + +with_test_prefix "cli exit after start cmd" { + test_terminal_settings_preserved_after_cli_exit { "start" } +} + +with_test_prefix "cli exit after run cmd" { + test_terminal_settings_preserved_after_cli_exit { "run" } +} |