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 1/3] [gdb/tui] Factor out require_tui_terminal
Date: Mon, 11 May 2026 12:35:47 +0200	[thread overview]
Message-ID: <20260511103549.2641036-2-tdevries@suse.de> (raw)
In-Reply-To: <20260511103549.2641036-1-tdevries@suse.de>

I noticed this bit of code in tui_enable:
...
      /* Check required terminal capabilities.  The MinGW port of
	 ncurses does have them, but doesn't expose them through "cup".  */
      cap = tigetstr ((char *) "cup");
      if (cap == NULL || cap == (char *) -1 || *cap == '\0')
	{
	  endwin ();
	  delscreen (s);
	  error (_("Cannot enable the TUI: "
		   "terminal doesn't support cursor addressing [TERM=%s]"),
		 gdb_getenv_term ());
	}
...

At this point in tui_enable, we need endwin and delscreen to clean up after
newterm, but the check can be done before newterm.

Fix this by factoring out a new function require_tui_terminal, and moving the
code there.
---
 gdb/tui/tui.c | 45 ++++++++++++++++++++++++---------------------
 1 file changed, 24 insertions(+), 21 deletions(-)

diff --git a/gdb/tui/tui.c b/gdb/tui/tui.c
index de2faa36af7..c1457e148a2 100644
--- a/gdb/tui/tui.c
+++ b/gdb/tui/tui.c
@@ -406,6 +406,28 @@ require_tui_interpreter ()
 	   interp);
 }
 
+/* Error out if the terminal doesn't support TUI.  */
+
+static void
+require_tui_terminal ()
+{
+  /* Don't try to setup curses (and print funny control
+     characters) if we're not outputting to a terminal.  */
+  if (!gdb_stderr->isatty ())
+    error (_("Cannot enable the TUI when output is not a terminal"));
+
+  /* Check required terminal capabilities.  The MinGW port of
+     ncurses does have them, but doesn't expose them through "cup".  */
+#ifndef __MINGW32__
+  const char *cap = tigetstr ((char *) "cup");
+  const char *not_a_string_capability = (char *) -1;
+  if (cap == nullptr || cap == not_a_string_capability || *cap == '\0')
+    error (_("Cannot enable the TUI: "
+	     "terminal doesn't support cursor addressing [TERM=%s]"),
+	   gdb_getenv_term ());
+#endif
+}
+
 /* Enter in the tui mode (curses).
    When in normal mode, it installs the tui hooks in gdb, redirects
    the gdb output, configures the readline to work in tui mode.
@@ -434,18 +456,13 @@ tui_enable (void)
     {
       WINDOW *w;
       SCREEN *s;
-#ifndef __MINGW32__
-       const char *cap;
-#endif
 
       /* If the top level interpreter is not the console/tui (e.g.,
 	 MI), enabling curses will certainly lose.  */
       require_tui_interpreter ();
 
-      /* Don't try to setup curses (and print funny control
-	 characters) if we're not outputting to a terminal.  */
-      if (!gdb_stderr->isatty ())
-	error (_("Cannot enable the TUI when output is not a terminal"));
+      /* Require a terminal that supports TUI.  */
+      require_tui_terminal ();
 
       /* Don't try initialization again.  */
       tui_finish_init = TRIBOOL_UNKNOWN;
@@ -473,20 +490,6 @@ tui_enable (void)
 	  start_color ();
 	}
 
-      /* Check required terminal capabilities.  The MinGW port of
-	 ncurses does have them, but doesn't expose them through "cup".  */
-#ifndef __MINGW32__
-      cap = tigetstr ((char *) "cup");
-      if (cap == NULL || cap == (char *) -1 || *cap == '\0')
-	{
-	  endwin ();
-	  delscreen (s);
-	  error (_("Cannot enable the TUI: "
-		   "terminal doesn't support cursor addressing [TERM=%s]"),
-		 gdb_getenv_term ());
-	}
-#endif
-
       /* We must mark the tui sub-system active before trying to setup the
 	 current layout as tui windows defined by an extension language
 	 rely on this flag being true in order to know that the window
-- 
2.51.0


  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] [gdb/tui] Allow second tui enable if first fails Tom de Vries
2026-05-11 10:35 ` Tom de Vries [this message]
2026-05-11 10:35 ` [PATCH v2 2/3] [gdb/tui] Factor out init_ncurses Tom de Vries
2026-05-11 10:35 ` [PATCH v2 3/3] [gdb/tui] Allow second tui enable if first fails Tom de Vries
2026-05-19 18:52 ` [PATCH v2 0/3] " 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-2-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