2025-04-10 03:19:12 +00:00
|
|
|
From e76eb034e25f53ef2c17eab700e95d07bbbdc7aa Mon Sep 17 00:00:00 2001
|
|
|
|
From: Tom de Vries <tdevries@suse.de>
|
|
|
|
Date: Mon, 7 Apr 2025 15:09:37 +0200
|
|
|
|
Subject: [PATCH] [gdb/tui] Don't try deferred curses initialization twice
|
|
|
|
|
|
|
|
I noticed that if deferred curses initialization fails, for instance when
|
|
|
|
using TERM=dumb, and we try the same again, we run into the same error:
|
|
|
|
...
|
|
|
|
$ TERM=dumb gdb -batch -ex "tui enable" -ex "tui enable"
|
|
|
|
Cannot enable the TUI: terminal doesn't support cursor addressing [TERM=dumb]
|
|
|
|
Cannot enable the TUI: terminal doesn't support cursor addressing [TERM=dumb]
|
|
|
|
...
|
|
|
|
|
|
|
|
I think it's better to try deferred curses initialization only once.
|
|
|
|
|
|
|
|
Fix this by changing bool tui_finish_init into a tribool, and using
|
|
|
|
TRIBOOL_UNKNOWN to represent the "initialization failed" state, such that we
|
|
|
|
get instead:
|
|
|
|
...
|
|
|
|
$ TERM=dumb gdb -batch -ex "tui enable" -ex "tui enable"
|
|
|
|
Cannot enable the TUI: terminal doesn't support cursor addressing [TERM=dumb]
|
|
|
|
Cannot enable the TUI
|
|
|
|
...
|
|
|
|
|
|
|
|
Tested on x86_64-linux.
|
|
|
|
---
|
|
|
|
gdb/tui/tui.c | 20 +++++++++++++++++---
|
|
|
|
1 file changed, 17 insertions(+), 3 deletions(-)
|
|
|
|
|
2025-04-03 13:13:04 +00:00
|
|
|
diff --git a/gdb/tui/tui.c b/gdb/tui/tui.c
|
2025-04-10 03:19:12 +00:00
|
|
|
index 59aa1bc1483..06a899e2418 100644
|
2025-04-03 13:13:04 +00:00
|
|
|
--- a/gdb/tui/tui.c
|
|
|
|
+++ b/gdb/tui/tui.c
|
2025-04-10 03:19:12 +00:00
|
|
|
@@ -67,7 +67,12 @@ show_tui_debug (struct ui_file *file, int from_tty,
|
2025-04-03 13:13:04 +00:00
|
|
|
|
|
|
|
/* Tells whether the TUI is active or not. */
|
|
|
|
bool tui_active = false;
|
|
|
|
-static bool tui_finish_init = true;
|
2025-04-10 03:19:12 +00:00
|
|
|
+
|
|
|
|
+/* Tells whether the TUI should do deferred curses initialization.
|
|
|
|
+ If TRIBOOL_TRUE, then yes. If TRIBOOL_FALSE. then no (because
|
|
|
|
+ initialization is already done). If TRIBOOL_UNKNOWN, then no (because
|
|
|
|
+ initialization failed). */
|
|
|
|
+static tribool tui_finish_init = TRIBOOL_TRUE;
|
2025-04-03 13:13:04 +00:00
|
|
|
|
|
|
|
enum tui_key_mode tui_current_key_mode = TUI_COMMAND_MODE;
|
|
|
|
|
2025-04-10 03:19:12 +00:00
|
|
|
@@ -390,7 +395,13 @@ tui_enable (void)
|
2025-04-03 13:13:04 +00:00
|
|
|
/* To avoid to initialize curses when gdb starts, there is a deferred
|
|
|
|
curses initialization. This initialization is made only once
|
|
|
|
and the first time the curses mode is entered. */
|
|
|
|
- if (tui_finish_init)
|
2025-04-10 03:19:12 +00:00
|
|
|
+ if (tui_finish_init == TRIBOOL_UNKNOWN)
|
2025-04-03 13:13:04 +00:00
|
|
|
+ {
|
2025-04-10 03:19:12 +00:00
|
|
|
+ /* Initialization failed before, just throw a generic error, don't try
|
|
|
|
+ again. */
|
2025-04-03 13:13:04 +00:00
|
|
|
+ error (_("Cannot enable the TUI"));
|
|
|
|
+ }
|
2025-04-10 03:19:12 +00:00
|
|
|
+ else if (tui_finish_init == TRIBOOL_TRUE)
|
2025-04-03 13:13:04 +00:00
|
|
|
{
|
|
|
|
WINDOW *w;
|
|
|
|
SCREEN *s;
|
2025-04-10 03:19:12 +00:00
|
|
|
@@ -410,6 +421,9 @@ tui_enable (void)
|
2025-04-03 13:13:04 +00:00
|
|
|
if (!gdb_stderr->isatty ())
|
|
|
|
error (_("Cannot enable the TUI when output is not a terminal"));
|
|
|
|
|
2025-04-10 03:19:12 +00:00
|
|
|
+ /* Don't try initialization again. */
|
|
|
|
+ tui_finish_init = TRIBOOL_UNKNOWN;
|
2025-04-03 13:13:04 +00:00
|
|
|
+
|
|
|
|
s = newterm (NULL, stdout, stdin);
|
|
|
|
#ifdef __MINGW32__
|
|
|
|
/* The MinGW port of ncurses requires $TERM to be unset in order
|
2025-04-10 03:19:12 +00:00
|
|
|
@@ -468,7 +482,7 @@ tui_enable (void)
|
|
|
|
tui_set_win_focus_to (tui_src_win ());
|
|
|
|
keypad (tui_cmd_win ()->handle.get (), TRUE);
|
|
|
|
wrefresh (tui_cmd_win ()->handle.get ());
|
2025-04-03 13:13:04 +00:00
|
|
|
- tui_finish_init = false;
|
2025-04-10 03:19:12 +00:00
|
|
|
+ tui_finish_init = TRIBOOL_FALSE;
|
2025-04-03 13:13:04 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2025-04-10 03:19:12 +00:00
|
|
|
|
|
|
|
base-commit: eaacf3d48a7f16f56d5a69d5fb03ac3638d7b957
|
|
|
|
--
|
|
|
|
2.43.0
|
|
|
|
|