[patch] Fix crash on NULL rl_prompt
Pedro Alves
pedro@codesourcery.com
Tue Mar 30 20:50:00 GMT 2010
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 <gdb_do_one_event>, 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 <pedro@codesourcery.com>
* 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);
More information about the Gdb-patches
mailing list