Fix crash when exiting TUI with gdb -tui
authorTom Tromey <tom@tromey.com>
Tue, 16 Jun 2020 23:55:57 +0000 (17:55 -0600)
committerTom Tromey <tom@tromey.com>
Wed, 17 Jun 2020 00:02:20 +0000 (18:02 -0600)
PR tui/25348 points out that, when "gdb -tui" is used, then exiting
the TUI will cause a crash.

This happens because tui_setup_io stashes some readline variables --
but because this happens before readline is initialized, some of these
are NULL.  Then, when exiting the TUI, the NULL values are "restored",
causing a crash in readline.

This patch fixes the problem by ensuring that readline is initialized
first.  Back in commit 11061048d ("Give a name to the TUI SingleKey
keymap"), a call to rl_initialize was removed from
tui_initialize_readline; this patch resurrects the call, but moves it
to the end of the function, so as not to remove the ability to modify
the SingleKey map from .inputrc.

gdb/ChangeLog
2020-06-16  Tom Tromey  <tom@tromey.com>

PR tui/25348:
* tui/tui.c (tui_ensure_readline_initialized): Rename from
tui_initialize_readline.  Only run once.  Call rl_initialize.
* tui/tui.h (tui_ensure_readline_initialized): Rename from
tui_initialize_readline.
* tui/tui-io.c (tui_setup_io): Call
tui_ensure_readline_initialized.
* tui/tui-interp.c (tui_interp::init): Update.

gdb/ChangeLog
gdb/tui/tui-interp.c
gdb/tui/tui-io.c
gdb/tui/tui.c
gdb/tui/tui.h

index 316b3fad288a2538aa94e82664befa8607a094b1..dc269261bebac78243abef7c44a1ccbe407c8b1f 100644 (file)
@@ -1,3 +1,14 @@
+2020-06-16  Tom Tromey  <tom@tromey.com>
+
+       PR tui/25348:
+       * tui/tui.c (tui_ensure_readline_initialized): Rename from
+       tui_initialize_readline.  Only run once.  Call rl_initialize.
+       * tui/tui.h (tui_ensure_readline_initialized): Rename from
+       tui_initialize_readline.
+       * tui/tui-io.c (tui_setup_io): Call
+       tui_ensure_readline_initialized.
+       * tui/tui-interp.c (tui_interp::init): Update.
+
 2020-06-16  Tom Tromey  <tom@tromey.com>
 
        * tui/tui-layout.c (tui_layout_split::remove_windows): Fix logic.
index 10118af27411035593725e9caf89fd75dd22eff1..44a1396432383b4cde11b795880af21f56d165ae 100644 (file)
@@ -244,7 +244,7 @@ tui_interp::init (bool top_level)
   tui_initialize_io ();
   tui_initialize_win ();
   if (gdb_stdout->isatty ())
-    tui_initialize_readline ();
+    tui_ensure_readline_initialized ();
 }
 
 void
index e7a8ac77bce8729a4cdf10e919e45a5b4efa0c86..277b560af4f4cdaa4229a7cd575332b32e004967 100644 (file)
@@ -746,6 +746,10 @@ tui_setup_io (int mode)
 
   if (mode)
     {
+      /* Ensure that readline has been initialized before saving any
+        of its variables.  */
+      tui_ensure_readline_initialized ();
+
       /* Redirect readline to TUI.  */
       tui_old_rl_redisplay_function = rl_redisplay_function;
       tui_old_rl_deprep_terminal = rl_deprep_term_function;
index ac435d16d6cdb510353619df11fdf50c9a87996e..828e42bccf7a263da40648699f967f1aabcbec60 100644 (file)
@@ -268,8 +268,14 @@ tui_set_key_mode (enum tui_key_mode mode)
 /* Initialize readline and configure the keymap for the switching
    key shortcut.  */
 void
-tui_initialize_readline (void)
+tui_ensure_readline_initialized ()
 {
+  static bool initialized;
+
+  if (initialized)
+    return;
+  initialized = true;
+
   int i;
   Keymap tui_ctlx_keymap;
 
@@ -325,6 +331,9 @@ tui_initialize_readline (void)
   rl_bind_key_in_map ('q', tui_rl_next_keymap, tui_keymap);
   rl_bind_key_in_map ('s', tui_rl_next_keymap, emacs_ctlx_keymap);
   rl_bind_key_in_map ('s', tui_rl_next_keymap, tui_ctlx_keymap);
+
+  /* Initialize readline after the above.  */
+  rl_initialize ();
 }
 
 /* Return the TERM variable from the environment, or "<unset>"
index 816b1e92851b3869949fc48b2805b30bc897863a..79525babc9ff6eec07b4c34a117ddbed3b9ce3a4 100644 (file)
@@ -49,9 +49,9 @@ extern bool tui_is_window_visible (enum tui_win_type type);
 extern bool tui_get_command_dimension (unsigned int *width,
                                       unsigned int *height);
 
-/* Initialize readline and configure the keymap for the switching
-   key shortcut.  */
-extern void tui_initialize_readline (void);
+/* Initialize readline and configure the keymap for the switching key
+   shortcut.  May be called more than once without issue.  */
+extern void tui_ensure_readline_initialized ();
 
 /* Enter in the tui mode (curses).  */
 extern void tui_enable (void);
This page took 0.030641 seconds and 4 git commands to generate.