From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [PATCH 3/3] [gdb/tui] Allow second tui enable if first fails
Date: Wed, 29 Apr 2026 13:13:25 +0200 [thread overview]
Message-ID: <20260429111325.1600061-4-tdevries@suse.de> (raw)
In-Reply-To: <20260429111325.1600061-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 shell mode.
Fix this by using reset_shell_mode instead.
---
gdb/tui/tui.c | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/gdb/tui/tui.c b/gdb/tui/tui.c
index ea01448f087..ee967e1e38b 100644
--- a/gdb/tui/tui.c
+++ b/gdb/tui/tui.c
@@ -493,7 +493,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 ())
@@ -530,9 +530,21 @@ tui_enable (void)
}
catch (const gdb_exception &)
{
- endwin ();
- delscreen (s);
+ /* Clean up screen. */
+ clear ();
+ refresh ();
+
+ /* Reset terminal to shell terminal mode. We can't use endwin here,
+ because afterwards the defer destructor might call doupdate,
+ restoring program terminal mode. */
+ reset_shell_mode ();
+
+ /* 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
next prev parent reply other threads:[~2026-04-29 11:14 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-29 11:13 [PATCH 0/3] " Tom de Vries
2026-04-29 11:13 ` [PATCH 1/3] [gdb/tui] Factor out require_tui_terminal Tom de Vries
2026-04-29 11:13 ` [PATCH 2/3] [gdb/tui] Factor out init_ncurses Tom de Vries
2026-04-29 11:13 ` Tom de Vries [this message]
2026-05-01 19:06 ` [PATCH 3/3] [gdb/tui] Allow second tui enable if first fails Tom Tromey
2026-05-11 10:38 ` Tom de Vries
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=20260429111325.1600061-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