From patchwork Tue Jul 28 22:20:09 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 7905 Received: (qmail 7726 invoked by alias); 28 Jul 2015 22:20:19 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 7716 invoked by uid 89); 28 Jul 2015 22:20:19 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.5 required=5.0 tests=AWL, BAYES_00, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_LOW autolearn=no version=3.3.2 X-HELO: mail-qg0-f41.google.com Received: from mail-qg0-f41.google.com (HELO mail-qg0-f41.google.com) (209.85.192.41) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Tue, 28 Jul 2015 22:20:17 +0000 Received: by qgii95 with SMTP id i95so83404896qgi.2 for ; Tue, 28 Jul 2015 15:20:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=rv8HNVFUKhsw4vczSJA0PwUw8jrJsvyjgKlxSQy5770=; b=ERFBP0zufPndFbzBHKbKkHsJF7b7A72fouCa8y3ARh8JFhUl4GmLxRISqk7AT7oAiP 50fEdh8WW6sDYwLABpx2GVW7lRseU2l+q/wlblSG0aCHD2HXuvYGVF26ujVcJKeNyBOl hHEj80xDIGyw7SYVEeWqcHaNPIQ7w+ksqGHG6bfX1+iMeNZWUUKYZpVhoUuTG1XOfI22 9gnBKCN3Z41X9P50zOEvCLVeUmTRAbfbGbk3pVpIzYYieE6Sz1MamksjyFl/Rei50CaU XtLg62CwFQ0WFpE+8ik3dW+xNY5dDSbTvlNHYRDMkf17sV31pKk0vrieCTkK8Zce/Wdy Gagg== X-Gm-Message-State: ALoCoQmG7RzSsIXmyvW8TIK9B1KMl6oCzy/bZaCtmtK+BEL5GkVAVDZJ3MtjsjzOD22J1vn4RbaG X-Received: by 10.140.83.84 with SMTP id i78mr54406148qgd.14.1438122015499; Tue, 28 Jul 2015 15:20:15 -0700 (PDT) Received: from localhost.localdomain (ool-4353acd8.dyn.optonline.net. [67.83.172.216]) by smtp.gmail.com with ESMTPSA id d30sm12182415qkh.45.2015.07.28.15.20.14 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 28 Jul 2015 15:20:14 -0700 (PDT) From: Patrick Palka To: gdb-patches@sourceware.org Cc: Patrick Palka Subject: [PATCH] Make sure terminal settings are restored before exiting Date: Tue, 28 Jul 2015 18:20:09 -0400 Message-Id: <1438122009-28779-1-git-send-email-patrick@parcs.ath.cx> In-Reply-To: <1438053504-21507-1-git-send-email-patrick@parcs.ath.cx> References: <1438053504-21507-1-git-send-email-patrick@parcs.ath.cx> [ Here is a new version of the patch that uses gdb_disable_readline instead of rl_deprep_terminal or gdb_rl_callback_handler_remove. A test is added to batch-preserve-term-settings.exp. The test depends on the cleanup patch I posted earlier. ] Tested on x86_64 Stretch. gdb/ChangeLog: * top.c (quit_force): Undo any modifications that may have been made to the terminal. gdb/testsuite/ChangeLog: * gdb.base/batch-preserve-term-settings.exp (test_terminal_settings_preserved_after_cli_exit): New test. --- .../gdb.base/batch-preserve-term-settings.exp | 94 +++++++++++++++++++++- gdb/top.c | 9 +++ 2 files changed, 102 insertions(+), 1 deletion(-) 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" } +} diff --git a/gdb/top.c b/gdb/top.c index 1e30b1c..6df987a 100644 --- a/gdb/top.c +++ b/gdb/top.c @@ -66,6 +66,7 @@ #include "cli-out.h" #include "tracepoint.h" #include "inf-loop.h" +#include "tui/tui.h" extern void initialize_all_files (void); @@ -1494,6 +1495,14 @@ quit_force (char *args, int from_tty) int exit_code = 0; struct qt_args qt; + /* Make sure that the terminal is left in the state we acquired it. */ + target_terminal_ours (); +#if defined(TUI) + tui_disable (); +#endif + if (async_command_editing_p) + gdb_disable_readline (); + /* An optional expression may be used to cause gdb to terminate with the value of that expression. */ if (args)