Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] Make sure terminal settings are restored before exiting
@ 2015-07-28  3:18 Patrick Palka
  2015-07-28 22:20 ` Patrick Palka
  2015-07-29  0:09 ` Pedro Alves
  0 siblings, 2 replies; 7+ messages in thread
From: Patrick Palka @ 2015-07-28  3:18 UTC (permalink / raw)
  To: gdb-patches; +Cc: Patrick Palka

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).

[ Note that we already take a snapshot of the original tty state and save
  it to inflow.c:initial_gdb_ttystate.  Using this variable we can
  define a new function restore_initial_gdb_ttystate and use it here.
  We can replace the call to rl_deprep_terminal with such a function,
  though it wouldn't hurt to have both around either.  Is this a good
  idea?

  As far as testing goes, I am having trouble figuring out how to
  retrieve the pid of the GDB subprocess in order to kill it via SIGTERM
  with the subshell/stty approach used in
  batch-preserve-term-settings.exp.  Seems non-trivial.  Any ideas?  ]

gdb/ChangeLog:

	* top.c (quit_force): Undo any modifications that may have been
	made the terminal by calling target_terminal_ours, then
	tui_disable, then rl_deprep_terminal.
---
 gdb/top.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/gdb/top.c b/gdb/top.c
index 1e30b1c..55f82ae 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)
+    rl_deprep_terminal ();
+
   /* An optional expression may be used to cause gdb to terminate with the 
      value of that expression.  */
   if (args)
-- 
2.5.0.rc2.22.g69b1679.dirty


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2015-07-29 12:15 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-28  3:18 [PATCH] Make sure terminal settings are restored before exiting Patrick Palka
2015-07-28 22:20 ` Patrick Palka
2015-07-28 23:53   ` Pedro Alves
2015-07-29 11:39     ` Patrick Palka
2015-07-29  0:09 ` Pedro Alves
2015-07-29 11:38   ` Patrick Palka
2015-07-29 12:15     ` Pedro Alves

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox