From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7704 invoked by alias); 30 Mar 2010 22:23:50 -0000 Received: (qmail 7695 invoked by uid 22791); 30 Mar 2010 22:23:49 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=BAYES_00,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail.codesourcery.com (HELO mail.codesourcery.com) (38.113.113.100) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 30 Mar 2010 22:23:45 +0000 Received: (qmail 4386 invoked from network); 30 Mar 2010 22:23:43 -0000 Received: from unknown (HELO orlando.localnet) (pedro@127.0.0.2) by mail.codesourcery.com with ESMTPA; 30 Mar 2010 22:23:43 -0000 From: Pedro Alves To: gdb-patches@sourceware.org Subject: Don't allow switching on the TUI in some cases Date: Tue, 30 Mar 2010 22:23:00 -0000 User-Agent: KMail/1.12.2 (Linux/2.6.31-20-generic; KDE/4.3.2; x86_64; ; ) MIME-Version: 1.0 Content-Type: Text/Plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Message-Id: <201003302323.40127.pedro@codesourcery.com> X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2010-03/txt/msg01090.txt.bz2 A slightly updated patch originally posted at: Tested on x86_64-linux and checked in. -- Pedro Alves 2010-03-30 Pedro Alves * tui/tui-interp.c (tui_is_toplevel): New. (tui_init): Set it. (tui_allowed_p): New. * tui/tui.c (tui_enable): Check if the TUI is allowed before enabling it. * tui/tui.h (tui_allowed_p): Declare. --- gdb/tui/tui-interp.c | 17 +++++++++++++++++ gdb/tui/tui.c | 3 +++ gdb/tui/tui.h | 4 ++++ 3 files changed, 24 insertions(+) Index: src/gdb/tui/tui-interp.c =================================================================== --- src.orig/gdb/tui/tui-interp.c 2010-03-30 21:40:50.000000000 +0100 +++ src/gdb/tui/tui-interp.c 2010-03-30 22:44:05.000000000 +0100 @@ -45,11 +45,16 @@ tui_exit (void) tui_disable (); } +/* True if TUI is the top-level interpreter. */ +static int tui_is_toplevel = 0; + /* These implement the TUI interpreter. */ static void * tui_init (int top_level) { + tui_is_toplevel = top_level; + /* Install exit handler to leave the screen in a good shape. */ atexit (tui_exit); @@ -63,6 +68,18 @@ tui_init (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) { Index: src/gdb/tui/tui.c =================================================================== --- src.orig/gdb/tui/tui.c 2010-03-30 21:40:50.000000000 +0100 +++ src/gdb/tui/tui.c 2010-03-30 22:39:28.000000000 +0100 @@ -364,6 +364,9 @@ tui_initialize_readline (void) void tui_enable (void) { + if (!tui_allowed_p ()) + error (_("TUI mode not allowed")); + if (tui_active) return; Index: src/gdb/tui/tui.h =================================================================== --- src.orig/gdb/tui/tui.h 2010-03-30 21:40:50.000000000 +0100 +++ src/gdb/tui/tui.h 2010-03-30 22:39:28.000000000 +0100 @@ -65,6 +65,10 @@ extern int tui_get_command_dimension (un 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);