From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30577 invoked by alias); 30 Mar 2010 20:50:25 -0000 Received: (qmail 30558 invoked by uid 22791); 30 Mar 2010 20:50:23 -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 20:50:18 +0000 Received: (qmail 11730 invoked from network); 30 Mar 2010 20:50:17 -0000 Received: from unknown (HELO orlando.localnet) (pedro@127.0.0.2) by mail.codesourcery.com with ESMTPA; 30 Mar 2010 20:50:17 -0000 From: Pedro Alves To: gdb-patches@sourceware.org Subject: Re: [patch] Fix crash on NULL rl_prompt Date: Tue, 30 Mar 2010 20:50:00 -0000 User-Agent: KMail/1.12.2 (Linux/2.6.31-20-generic; KDE/4.3.2; x86_64; ; ) Cc: Jan Kratochvil , tromey@redhat.com References: <20100329234026.GA23895@host0.dyn.jankratochvil.net> <20100330170457.GA10938@host0.dyn.jankratochvil.net> <201003301825.18754.pedro@codesourcery.com> In-Reply-To: <201003301825.18754.pedro@codesourcery.com> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201003302150.12868.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/msg01085.txt.bz2 On Tuesday 30 March 2010 18:25:18, Pedro Alves wrote: > On Tuesday 30 March 2010 18:04:57, Jan Kratochvil wrote: > > On Tue, 30 Mar 2010 18:41:20 +0200, Pedro Alves wrote: > > > But, how did rl_prompt end up NULL in the first place? > > > > I do not know. I have spent some time trying to reproduce it reading the > > source but gave up after some reasonable time. Bugreport comes from an > > automated crash reporter (ABRT) where the person only sometimes can/gives more > > info. Asked now for a reproducer. > > My guess is, either readline wasn't setup proper at all, or, > the prompts stack got busted (get_prompt/set_prompt/PROMPT), which > I've seen happen before with target-async mode. > Maybe this patch helps your crash as well. Running a TUI command when the top level interpreter isn't TUI, segfaults, though somewhere else. ./gdb -i=mi -ex "layout next" #0 0x000000000046968c in gdb_flush (file=0x0) at ../../src/gdb/ui-file.c:173 #1 0x0000000000586739 in gdb_wait_for_event (block=0) at ../../src/gdb/event-loop.c:831 #2 0x0000000000585e58 in gdb_do_one_event (data=0x0) at ../../src/gdb/event-loop.c:432 #3 0x00000000005803c7 in catch_errors (func=0x585dfd , func_args=0x0, errstring=0x7c48a8 "", mask=6) at ../../src/gdb/exceptions.c:510 #4 0x0000000000585ef2 in start_event_loop () at ../../src/gdb/event-loop.c:482 #5 0x00000000004e340c in mi_command_loop (mi_version=2) at ../../src/gdb/mi/mi-interp.c:292 It doesn't seem useful to be able to run TUI commands while GDB is being controlled by MI. I'm also disabling TUI command if we're not outputting to a tty. It doesn't sound useful, and is broken. Example, try this, and see that foo.txt end up full of term control characters: $ ./gdb -nx --batch -ex "refresh" > foo.txt $ od -c foo.txt | less 0000000 033 [ ? 1 0 4 9 h 033 [ 1 ; 3 1 r 033 0000020 [ m 033 ( B 033 [ 4 l 033 [ ? 7 h 033 [ 0000040 ? 1 h 033 = 033 [ H 033 [ 2 J 033 [ 2 1 0000060 d 033 [ 0 ; 7 m 033 ( B N o n e N 0000100 o p r o c e s s I n : ... Remove --batch, and GDB hangs, no ammount of ctrl-c seems to get it back. -- 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:14:17.000000000 +0100 +++ src/gdb/tui/tui-interp.c 2010-03-30 21:34:23.000000000 +0100 @@ -45,6 +45,8 @@ tui_exit (void) tui_disable (); } +static int tui_is_toplevel = 0; + /* These implement the TUI interpreter. */ static void * @@ -60,9 +62,24 @@ tui_init (int top_level) if (ui_file_isatty (gdb_stdout)) tui_initialize_readline (); + if (top_level) + tui_is_toplevel = 1; + 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:05:07.000000000 +0100 +++ src/gdb/tui/tui.c 2010-03-30 21:38:13.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:14:23.000000000 +0100 +++ src/gdb/tui/tui.h 2010-03-30 21:20:51.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);