From patchwork Thu Jul 24 15:05:33 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 2164 Received: (qmail 24972 invoked by alias); 24 Jul 2014 15:05:49 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 24870 invoked by uid 89); 24 Jul 2014 15:05:38 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Thu, 24 Jul 2014 15:05:36 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s6OF5ZUT015524 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 24 Jul 2014 11:05:35 -0400 Received: from brno.lan (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s6OF5XvW015524 for ; Thu, 24 Jul 2014 11:05:34 -0400 From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PUSHED+7.8] Fix pagination crash when the TUI is active Date: Thu, 24 Jul 2014 16:05:33 +0100 Message-Id: <1406214333-12425-1-git-send-email-palves@redhat.com> The TUI currently crashes when the user types in response to a pagination prompt: $ gdb --tui ... *the TUI is now active* (gdb) set height 2 (gdb) help List of classes of commands: Program received signal SIGSEGV, Segmentation fault. strlen () at ../sysdeps/x86_64/strlen.S:106 106 movdqu (%rax), %xmm12 (top-gdb) bt #0 strlen () at ../sysdeps/x86_64/strlen.S:106 #1 0x000000000086be5f in xstrdup (s=0x0) at ../src/libiberty/xstrdup.c:33 #2 0x00000000005163f9 in tui_prep_terminal (notused1=1) at ../src/gdb/tui/tui-io.c:296 #3 0x000000000077a7ee in _rl_callback_newline () at ../src/readline/callback.c:82 #4 0x000000000077a853 in rl_callback_handler_install (prompt=0x0, linefunc=0x618b60 ) at ../src/readline/callback.c:102 #5 0x0000000000718a5c in gdb_readline_wrapper_cleanup (arg=0xfd14d0) at ../src/gdb/top.c:788 #6 0x0000000000596d08 in do_my_cleanups (pmy_chain=0xcf0b38 , old_chain=0x1043d10) at ../src/gdb/cleanups.c:155 #7 0x0000000000596d75 in do_cleanups (old_chain=0x1043d10) at ../src/gdb/cleanups.c:177 #8 0x0000000000718bd9 in gdb_readline_wrapper (prompt=0x7fffffffcfa0 "---Type to continue, or q to quit---") at ../src/gdb/top.c:835 #9 0x000000000071cf74 in prompt_for_continue () at ../src/gdb/utils.c:1894 #10 0x000000000071d434 in fputs_maybe_filtered (linebuffer=0x1043db0 "List of classes of commands:\n\n", stream=0xf72e20, filter=1) at ../src/gdb/utils.c:2111 #11 0x000000000071da0f in vfprintf_maybe_filtered (stream=0xf72e20, format=0x89aef8 "List of classes of %scommands:\n\n", args=0x7fffffffd118, filter=1) at ../src/gdb/utils.c:2339 #12 0x000000000071da4a in vfprintf_filtered (stream=0xf72e20, format=0x89aef8 "List of classes of %scommands:\n\n", args=0x7fffffffd118) at ../src/gdb/utils.c:2347 #13 0x000000000071dc72 in fprintf_filtered (stream=0xf72e20, format=0x89aef8 "List of classes of %scommands:\n\n") at ../src/gdb/utils.c:2399 #14 0x00000000004f90ab in help_list (list=0xe6d100, cmdtype=0x89ad8c "", class=all_classes, stream=0xf72e20) at ../src/gdb/cli/cli-decode.c:1038 #15 0x00000000004f8dba in help_cmd (arg=0x0, stream=0xf72e20) at ../src/gdb/cli/cli-decode.c:946 Git 0017922 added: @@ -776,6 +777,12 @@ gdb_readline_wrapper_cleanup (void *arg) gdb_assert (input_handler == gdb_readline_wrapper_line); input_handler = cleanup->handler_orig; + + /* Reinstall INPUT_HANDLER in readline, without displaying a + prompt. */ + if (async_command_editing_p) + rl_callback_handler_install (NULL, input_handler); and tui_prep_terminal simply misses handling the case of a NULL rl_prompt. I also checked that readline's sources do similar checks. gdb/ 2014-07-24 Pedro Alves * tui/tui-io.c (tui_prep_terminal): Handle NULL rl_prompt. --- gdb/ChangeLog | 4 ++++ gdb/tui/tui-io.c | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index e239221..1c4ccaf 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,7 @@ +2014-07-24 Pedro Alves + + * tui/tui-io.c (tui_prep_terminal): Handle NULL rl_prompt. + 2014-07-24 Tom Tromey Gary Benson diff --git a/gdb/tui/tui-io.c b/gdb/tui/tui-io.c index dcccb08..75eb4b8 100644 --- a/gdb/tui/tui-io.c +++ b/gdb/tui/tui-io.c @@ -293,7 +293,7 @@ tui_prep_terminal (int notused1) (we can't use gdb_prompt() due to secondary prompts and can't use rl_prompt because it points to an alloca buffer). */ xfree (tui_rl_saved_prompt); - tui_rl_saved_prompt = xstrdup (rl_prompt); + tui_rl_saved_prompt = rl_prompt != NULL ? xstrdup (rl_prompt) : NULL; } /* Readline callback to restore the terminal. It is called once each