aboutsummaryrefslogtreecommitdiff
path: root/gdb/tui
diff options
context:
space:
mode:
Diffstat (limited to 'gdb/tui')
-rw-r--r--gdb/tui/tui-interp.c17
-rw-r--r--gdb/tui/tui.c53
-rw-r--r--gdb/tui/tui.h4
3 files changed, 49 insertions, 25 deletions
diff --git a/gdb/tui/tui-interp.c b/gdb/tui/tui-interp.c
index 24cb5a3..b377db2 100644
--- a/gdb/tui/tui-interp.c
+++ b/gdb/tui/tui-interp.c
@@ -51,9 +51,6 @@ tui_exit (void)
tui_disable ();
}
-/* True if TUI is the top-level interpreter. */
-static int tui_is_toplevel = 0;
-
/* Observers for several run control events. If the interpreter is
quiet (i.e., another interpreter is being run with
interpreter-exec), print nothing. */
@@ -126,8 +123,6 @@ tui_on_command_error (void)
static void *
tui_init (struct interp *self, int top_level)
{
- tui_is_toplevel = top_level;
-
/* Install exit handler to leave the screen in a good shape. */
atexit (tui_exit);
@@ -150,18 +145,6 @@ tui_init (struct interp *self, int top_level)
return NULL;
}
-/* True if enabling the TUI is allowed. Example, if the top level
- interpreter is MI, enabling curses will certainly lose. */
-
-int
-tui_allowed_p (void)
-{
- /* Only if TUI is the top level interpreter. Also don't try to
- setup curses (and print funny control characters) if we're not
- outputting to a terminal. */
- return tui_is_toplevel && ui_file_isatty (gdb_stdout);
-}
-
static int
tui_resume (void *data)
{
diff --git a/gdb/tui/tui.c b/gdb/tui/tui.c
index a02c855..ca66ccd 100644
--- a/gdb/tui/tui.c
+++ b/gdb/tui/tui.c
@@ -48,6 +48,7 @@
#include <setjmp.h>
#include "gdb_curses.h"
+#include "interps.h"
/* This redefines CTRL if it is not already defined, so it must come
after terminal state releated include files like <term.h> and
@@ -361,6 +362,20 @@ tui_initialize_readline (void)
rl_bind_key_in_map ('s', tui_rl_next_keymap, tui_ctlx_keymap);
}
+/* Return the TERM variable from the environment, or "<unset>"
+ if not set. */
+
+static const char *
+gdb_getenv_term (void)
+{
+ const char *term;
+
+ term = getenv ("TERM");
+ if (term != NULL)
+ return term;
+ return "<unset>";
+}
+
/* 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.
@@ -368,8 +383,7 @@ tui_initialize_readline (void)
void
tui_enable (void)
{
- if (!tui_allowed_p ())
- error (_("TUI mode not allowed"));
+ struct interp *interp;
if (tui_active)
return;
@@ -380,9 +394,40 @@ tui_enable (void)
if (tui_finish_init)
{
WINDOW *w;
+ SCREEN *s;
+ const char *cap;
+ const char *interp;
+
+ /* If the top level interpreter is not the console/tui (e.g.,
+ MI), enabling curses will certainly lose. */
+ interp = interp_name (top_level_interpreter ());
+ if (strcmp (interp, INTERP_TUI) != 0)
+ error (_("Cannot enable the TUI when the interpreter is '%s'"), interp);
+
+ /* Don't try to setup curses (and print funny control
+ characters) if we're not outputting to a terminal. */
+ if (!ui_file_isatty (gdb_stdout))
+ error (_("Cannot enable the TUI when output is not a terminal"));
+
+ s = newterm (NULL, NULL, NULL);
+ if (s == NULL)
+ {
+ error (_("Cannot enable the TUI: error opening terminal [TERM=%s]"),
+ gdb_getenv_term ());
+ }
+ w = stdscr;
+
+ /* Check required terminal capabilities. */
+ cap = tigetstr ("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 ());
+ }
- w = initscr ();
-
cbreak ();
noecho ();
/* timeout (1); */
diff --git a/gdb/tui/tui.h b/gdb/tui/tui.h
index 9afadb2..b1dddc0 100644
--- a/gdb/tui/tui.h
+++ b/gdb/tui/tui.h
@@ -64,10 +64,6 @@ extern int tui_get_command_dimension (unsigned int *width,
key shortcut. */
extern void tui_initialize_readline (void);
-/* True if enabling the TUI is allowed. Example, if the top level
- interpreter is MI, enabling curses will certainly lose. */
-extern int tui_allowed_p (void);
-
/* Enter in the tui mode (curses). */
extern void tui_enable (void);