aboutsummaryrefslogtreecommitdiff
path: root/gdb/top.c
diff options
context:
space:
mode:
authorPatrick Palka <patrick@parcs.ath.cx>2015-07-27 11:54:07 -0400
committerPatrick Palka <patrick@parcs.ath.cx>2015-07-29 08:39:41 -0400
commit18206ca3f9367f1488cdfc1475f8da072e7e9636 (patch)
tree6939220e0cab7c33bff405eb907c133f9911ebb1 /gdb/top.c
parent7afa63c624ae570472381b8e35ce066bf145844a (diff)
downloadgdb-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/top.c')
-rw-r--r--gdb/top.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/gdb/top.c b/gdb/top.c
index 1e30b1c..3e88ac6 100644
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -67,6 +67,10 @@
#include "tracepoint.h"
#include "inf-loop.h"
+#if defined(TUI)
+# include "tui/tui.h"
+#endif
+
extern void initialize_all_files (void);
#define PROMPT(X) the_prompts.prompt_stack[the_prompts.top + X].prompt
@@ -1486,6 +1490,21 @@ quit_confirm (void)
return qr;
}
+/* Prepare to exit GDB cleanly by undoing any changes made to the
+ terminal so that we leave the terminal in the state we acquired it. */
+
+static void
+undo_terminal_modifications_before_exit (void)
+{
+ target_terminal_ours ();
+#if defined(TUI)
+ tui_disable ();
+#endif
+ if (async_command_editing_p)
+ gdb_disable_readline ();
+}
+
+
/* Quit without asking for confirmation. */
void
@@ -1494,6 +1513,8 @@ quit_force (char *args, int from_tty)
int exit_code = 0;
struct qt_args qt;
+ undo_terminal_modifications_before_exit ();
+
/* An optional expression may be used to cause gdb to terminate with the
value of that expression. */
if (args)