Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [PATCH v2 3/3] [gdb/tui] Allow second tui enable if first fails
Date: Mon, 11 May 2026 12:35:49 +0200	[thread overview]
Message-ID: <20260511103549.2641036-4-tdevries@suse.de> (raw)
In-Reply-To: <20260511103549.2641036-1-tdevries@suse.de>

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.
---
 gdb/tui/tui-wingeneral.c | 2 +-
 gdb/tui/tui.c            | 9 +++++++--
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/gdb/tui/tui-wingeneral.c b/gdb/tui/tui-wingeneral.c
index 86f13d275b4..149ca4efc6e 100644
--- a/gdb/tui/tui-wingeneral.c
+++ b/gdb/tui/tui-wingeneral.c
@@ -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 ();
 }
 
diff --git a/gdb/tui/tui.c b/gdb/tui/tui.c
index 11bcba813bc..958fc47b7b6 100644
--- a/gdb/tui/tui.c
+++ b/gdb/tui/tui.c
@@ -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;
 	}
 
-- 
2.51.0


  parent reply	other threads:[~2026-05-11 10:37 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-11 10:35 [PATCH v2 0/3] " Tom de Vries
2026-05-11 10:35 ` [PATCH v2 1/3] [gdb/tui] Factor out require_tui_terminal Tom de Vries
2026-05-11 10:35 ` [PATCH v2 2/3] [gdb/tui] Factor out init_ncurses Tom de Vries
2026-05-11 10:35 ` Tom de Vries [this message]
2026-05-19 18:52 ` [PATCH v2 0/3] [gdb/tui] Allow second tui enable if first fails Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260511103549.2641036-4-tdevries@suse.de \
    --to=tdevries@suse.de \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox