]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
[gdb/tui] Allow second tui enable if first fails
authorTom de Vries <tdevries@suse.de>
Wed, 20 May 2026 06:31:12 +0000 (08:31 +0200)
committerTom de Vries <tdevries@suse.de>
Wed, 20 May 2026 06:31:12 +0000 (08:31 +0200)
Commit fb23d7ba4a2 ("[gdb/tui] Handle error in tui_enable") handles a
particular error during tui_enable, but doesn't allow trying to enable TUI
again.

I tried to get this to work, but didn't manage because I didn't understand the
interaction between endwin and the "tui_batch_rendering defer" destructor:
- first endwin restores the shell terminal mode
- then the defer destructor calls doupdate, restoring program terminal mode.

Fix this by checking for tui_active in ~tui_batch_rendering.

Approved-By: Tom Tromey <tom@tromey.com>
gdb/tui/tui-wingeneral.c
gdb/tui/tui.c

index 86f13d275b46b4968481eb17b128f3b9ce610da1..149ca4efc6ef7c2ed6000f9ff1fe38476091955e 100644 (file)
@@ -46,7 +46,7 @@ tui_batch_rendering::tui_batch_rendering ()
 tui_batch_rendering::~tui_batch_rendering ()
 {
   suppress_output = m_saved_suppress;
-  if (!suppress_output)
+  if (!suppress_output && tui_active)
     doupdate ();
 }
 
index 11bcba813bcaf2f3003dddd55267dd52b301272a..958fc47b7b6928344c6815d8d0cb1ab3ae24c69b 100644 (file)
@@ -494,7 +494,7 @@ tui_enable (void)
       /* Don't try initialization again.  */
       tui_finish_init = TRIBOOL_UNKNOWN;
 
-      SCREEN *s = init_ncurses ();
+      init_ncurses ();
       w = stdscr;
 
       if (has_colors ())
@@ -532,8 +532,13 @@ tui_enable (void)
       catch (const gdb_exception &)
        {
          endwin ();
-         delscreen (s);
+
+         /* Initialization failed, so TUI is not active.  */
          tui_active = false;
+
+         /* Allow trying to initialize TUI again.  */
+         tui_finish_init = TRIBOOL_TRUE;
+
          throw;
        }