From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 67814 invoked by alias); 8 Mar 2017 12:02:46 -0000 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 Received: (qmail 67796 invoked by uid 89); 8 Mar 2017 12:02:45 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-6.4 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_2,MIME_BASE64_BLANKS,RP_MATCHES_RCVD,SPF_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:1414, H*r:169.254.6, Tel, tel X-HELO: mga01.intel.com Received: from mga01.intel.com (HELO mga01.intel.com) (192.55.52.88) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 08 Mar 2017 12:02:44 +0000 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 08 Mar 2017 04:02:43 -0800 X-ExtLoop1: 1 Received: from irsmsx152.ger.corp.intel.com ([163.33.192.66]) by fmsmga002.fm.intel.com with ESMTP; 08 Mar 2017 04:02:42 -0800 Received: from irsmsx104.ger.corp.intel.com ([169.254.5.142]) by IRSMSX152.ger.corp.intel.com ([169.254.6.125]) with mapi id 14.03.0248.002; Wed, 8 Mar 2017 12:02:42 +0000 From: "Tedeschi, Walfred" To: Jiong Wang , GDB Subject: RE: [PATCH v9] amd64-mpx: initialize BND register before performing inferior calls. Date: Wed, 08 Mar 2017 12:02:00 -0000 Message-ID: References: <1488215745-5625-1-git-send-email-walfred.tedeschi@intel.com> <0f14f1c3-d99f-e83b-9b88-8453eccac66d@foss.arm.com> In-Reply-To: <0f14f1c3-d99f-e83b-9b88-8453eccac66d@foss.arm.com> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 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JvdW5kID0gZmZmZmZmZmZ9IDogc2l6ZSAtMSBAZW5kIHNtYWxsZXhhbXBs ZQ0KDQpUaGlzIGNhdXNlZCAibWFrZSBodG1sIiBmYWlsdXJlLCBhbmQgaXQg bG9va3MgdG8gbWUgaXMgbWlzc2luZyBAIGJlZm9yZSB7Lg0KDQpJIHdpbGwg Y29tbWl0IHRoaXMgcGF0Y2ggYXMgb2J2aW91cy4NCg0KZ2RiLw0KMjAxNy0w My0wOCAgSmlvbmcgV2FuZ2cgIDxqaW9uZy53YW5nQGFybS5jb20+DQoNCiAg ICAgICAgICogZG9jL2dkYi50ZXhpbmZvIChNZW1vcnkgUHJvdGVjdGlvbiBF eHRlbnNpb25zKTogQWRkIG1pc3NpbmcgZXNjYXBlDQogICAgICAgICBjaGFy YWN0ZXIgIkAiLg0KDQpJbnRlbCBEZXV0c2NobGFuZCBHbWJIClJlZ2lzdGVy ZWQgQWRkcmVzczogQW0gQ2FtcGVvbiAxMC0xMiwgODU1NzkgTmV1YmliZXJn LCBHZXJtYW55ClRlbDogKzQ5IDg5IDk5IDg4NTMtMCwgd3d3LmludGVsLmRl Ck1hbmFnaW5nIERpcmVjdG9yczogQ2hyaXN0aW4gRWlzZW5zY2htaWQsIENo cmlzdGlhbiBMYW1wcmVjaHRlcgpDaGFpcnBlcnNvbiBvZiB0aGUgU3VwZXJ2 aXNvcnkgQm9hcmQ6IE5pY29sZSBMYXUKUmVnaXN0ZXJlZCBPZmZpY2U6IE11 bmljaApDb21tZXJjaWFsIFJlZ2lzdGVyOiBBbXRzZ2VyaWNodCBNdWVuY2hl biBIUkIgMTg2OTI4Cg== >From gdb-patches-return-137450-listarch-gdb-patches=sources.redhat.com@sourceware.org Wed Mar 08 12:27:57 2017 Return-Path: Delivered-To: listarch-gdb-patches@sources.redhat.com Received: (qmail 62768 invoked by alias); 8 Mar 2017 12:27:57 -0000 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 Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 62493 invoked by uid 89); 8 Mar 2017 12:27:56 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= 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 ESMTP; Wed, 08 Mar 2017 12:27:54 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1E59180462 for ; Wed, 8 Mar 2017 12:27:53 +0000 (UTC) Received: from cascais.lan (ovpn04.gateway.prod.ext.phx2.redhat.com [10.5.9.4]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v28CRq27024450 for ; Wed, 8 Mar 2017 07:27:52 -0500 From: Pedro Alves To: gdb-patches@sourceware.org Subject: [pushed] Fix PR 21218: GDB dumps core when escaping newline in multi-line command Date: Wed, 08 Mar 2017 12:27:00 -0000 Message-Id: <1488976070-12453-1-git-send-email-palves@redhat.com> X-SW-Source: 2017-03/txt/msg00094.txt.bz2 Content-length: 5859 With commit 3b12939dfc2399 ("Replace the sync_execution global with a new enum prompt_state tristate"), GDB started aborting if you try splitting an input line with a continuation char (backslash) while in a multi-line command: (gdb) commands Type commands for breakpoint(s) 1, one per line. End with a line saying just "end". >print \ (gdb) 1 # note "(gdb)" incorrectly printed here. >end readline: readline_callback_read_char() called with no handler! $ That abort is actually a symptom of an old problem introduced when gdb_readline_wrapper was rewritten to use asynchronous readline, back in 2007. Note how the "(gdb)" prompt is printed above in the "(gdb) 1" line. Clearly it shouldn't be there, but it already was before the commit mentioned above. Fixing that also fixes the readline abort shown above. The problem starts when command_line_input passes a NULL prompt to gdb_readline_wrapper when it finds previous incomplete input due to a backslash, trying to fetch more input without printing another ">" secondary prompt. That itself should not be a problem, because passing NULL to gdb_readline_wrapper has the same meaning as passing a pointer to empty string, since gdb_readline_wrapper exposes the same interface as 'readline(char *)'. However, gdb_readline_wrapper passes the prompt argument directly to display_gdb_prompt, and for the latter, a NULL prompt argument has a different meaning - it requests printing the primary prompt. Before commit 782a7b8ef9c096 (which rewrote gdb_readline_wrapper to use asynchronous readline), GDB behaved like this: (gdb) commands [....] >print \ 1 >end (gdb) The above is what this commit restores GDB back to. New test included. gdb/ChangeLog: 2017-03-08 Pedro Alves PR cli/21218 * top.c (gdb_readline_wrapper): Avoid passing NULL to display_gdb_prompt. (command_line_input): Add comment. gdb/testsuite/ChangeLog: 2017-03-08 Pedro Alves Jan Kratochvil PR cli/21218 * gdb.base/commands.exp (backslash_in_multi_line_command_test): New proc. (top level): Call it. --- gdb/ChangeLog | 7 +++++++ gdb/testsuite/ChangeLog | 8 ++++++++ gdb/testsuite/gdb.base/commands.exp | 29 +++++++++++++++++++++++++++++ gdb/top.c | 10 ++++++++-- 4 files changed, 52 insertions(+), 2 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 432cdcc..92847f7 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,12 @@ 2017-03-08 Pedro Alves + PR cli/21218 + * top.c (gdb_readline_wrapper): Avoid passing NULL to + display_gdb_prompt. + (command_line_input): Add comment. + +2017-03-08 Pedro Alves + PR tui/21216 * tui/tui-file.c (tui_file::write): New. * tui/tui-file.h (tui_file): Override "write". diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 0654bef..d7b603b 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,4 +1,12 @@ 2017-03-08 Pedro Alves + Jan Kratochvil + + PR cli/21218 + * gdb.base/commands.exp (backslash_in_multi_line_command_test): + New proc. + (top level): Call it. + +2017-03-08 Pedro Alves PR tui/21216 * gdb.tui/tui-nl-filtered-output.exp: New file. diff --git a/gdb/testsuite/gdb.base/commands.exp b/gdb/testsuite/gdb.base/commands.exp index 9ad70f5..6d3c398 100644 --- a/gdb/testsuite/gdb.base/commands.exp +++ b/gdb/testsuite/gdb.base/commands.exp @@ -1003,6 +1003,34 @@ proc_with_prefix redefine_backtrace_test {} { gdb_test "bt" "hibob" "execute bt command" } +# Test an input line split with a continuation character (backslash) +# while entering a multi-line command (in a secondary prompt). + +proc_with_prefix backslash_in_multi_line_command_test {} { + gdb_breakpoint "main" + + gdb_test_multiple "commands" "commands" { + -re "End with a line saying just \"end\"\\.\r\n>$" { + pass "commands" + } + } + + set test "input line split with backslash" + send_gdb "print \\\nargc\n" + gdb_test_multiple "" $test { + -re "^print \\\\\r\nargc\r\n>$" { + pass $test + } + } + + gdb_test_no_output "end" + + # Input any command, just to be sure the readline state is sane. + # In PR 21218, this would trigger the infamous: + # readline: readline_callback_read_char() called with no handler! + gdb_test "print 1" "" "run command" +} + gdbvar_simple_if_test gdbvar_simple_while_test gdbvar_complex_if_while_test @@ -1027,5 +1055,6 @@ recursive_source_test if_commands_test error_clears_commands_left redefine_hook_test +backslash_in_multi_line_command_test # This one should come last, as it redefines "backtrace". redefine_backtrace_test diff --git a/gdb/top.c b/gdb/top.c index 6bf9d8c0..295b680 100644 --- a/gdb/top.c +++ b/gdb/top.c @@ -1030,8 +1030,11 @@ gdb_readline_wrapper (const char *prompt) if (cleanup->target_is_async_orig) target_async (0); - /* Display our prompt and prevent double prompt display. */ - display_gdb_prompt (prompt); + /* Display our prompt and prevent double prompt display. Don't pass + down a NULL prompt, since that has special meaning for + display_gdb_prompt -- it indicates a request to print the primary + prompt, while we want a secondary prompt here. */ + display_gdb_prompt (prompt != NULL ? prompt : ""); if (ui->command_editing) rl_already_prompted = 1; @@ -1307,6 +1310,9 @@ command_line_input (const char *prompt_arg, int repeat, char *annotation_suffix) if (cmd != NULL) break; + /* Got partial input. I.e., got a line that ends with a + continuation character (backslash). Suppress printing the + prompt again. */ prompt = NULL; } -- 2.5.5