From patchwork Thu Nov 21 10:03:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Simon Marchi (Code Review)" X-Patchwork-Id: 36086 Received: (qmail 36476 invoked by alias); 21 Nov 2019 10:03:19 -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 36432 invoked by uid 89); 21 Nov 2019 10:03:19 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-21.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.1 spammy= X-HELO: mx1.osci.io Received: from polly.osci.io (HELO mx1.osci.io) (8.43.85.229) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 21 Nov 2019 10:03:16 +0000 Received: by mx1.osci.io (Postfix, from userid 994) id 51F3820413; Thu, 21 Nov 2019 05:03:13 -0500 (EST) Received: from gnutoolchain-gerrit.osci.io (gnutoolchain-gerrit.osci.io [8.43.85.239]) by mx1.osci.io (Postfix) with ESMTP id 55C882039A; Thu, 21 Nov 2019 05:03:07 -0500 (EST) Received: from localhost (localhost [127.0.0.1]) by gnutoolchain-gerrit.osci.io (Postfix) with ESMTP id 37BD62816F; Thu, 21 Nov 2019 05:03:07 -0500 (EST) X-Gerrit-PatchSet: 2 Date: Thu, 21 Nov 2019 05:03:06 -0500 From: "Sourceware to Gerrit sync (Code Review)" To: Tom de Vries , Andrew Burgess , Simon Marchi , gdb-patches@sourceware.org Auto-Submitted: auto-generated X-Gerrit-MessageType: newpatchset Subject: [pushed] [gdb] Only force INTERP_CONSOLE ui_out for breakpoint commands in MI ... X-Gerrit-Change-Id: Id1771e7fcc9496a7d97ec2b2ea6b1487596f1ef7 X-Gerrit-Change-Number: 28 X-Gerrit-ChangeURL: X-Gerrit-Commit: 65d1cd5f9cbcbb2df0b187cb7623949c1668728f In-Reply-To: References: Reply-To: noreply@gnutoolchain-gerrit.osci.io, simon.marchi@polymtl.ca, tdevries@suse.de, andrew.burgess@embecosm.com, gdb-patches@sourceware.org MIME-Version: 1.0 Content-Disposition: inline User-Agent: Gerrit/3.0.3-79-g83ff7f88f1 Message-Id: <20191121100307.37BD62816F@gnutoolchain-gerrit.osci.io> The original change was created by Tom de Vries. Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/28 ...................................................................... [gdb] Only force INTERP_CONSOLE ui_out for breakpoint commands in MI mode The problem reported in PR mi/25055 is that the output of the backtrace command, when executed as breakpoint command does not show when executing using the MI interpreter: ... $ gdb a.out Reading symbols from a.out... (gdb) break main Breakpoint 1 at 0x4003c0: file test.c, line 19. (gdb) commands Type commands for breakpoint(s) 1, one per line. End with a line saying just "end". >bt >end (gdb) interpreter-exec mi "-exec-run" ^done Breakpoint 1, main () at test.c:19 19 return foo (4); (gdb) ... Interestingly, the function print_frame is called twice during -exec-run: - once during tui_on_normal_stop where the ui_out is temporarily set to tui->interp_ui_out (), resulting in the part after the comma in "Breakpoint 1, main () at test.c:19" - once during execute_control_command, where the ui_out is the default for the current interpreter: mi_ui_out, which ignores calls to output text. The commit 3a87ae656c2 "Use console uiout when executing breakpoint commands" fixes the problem by temporarily switching to the ui_out of INTERP_CONSOLE in execute_control_command. This however caused a regression in redirection (escaping '#' using '\' for git commit message convenience): ... $ rm -f gdb.txt; gdb a.out Reading symbols from a.out... (gdb) break main Breakpoint 1 at 0x4003c0: file test.c, line 19. (gdb) commands Type commands for breakpoint(s) 1, one per line. End with a line saying just "end". >bt >end (gdb) set logging redirect on (gdb) set logging on Redirecting output to gdb.txt. Copying debug output to gdb.txt. (gdb) run \#0 main () at test.c:19 (gdb) q A debugging session is active. Inferior 1 [process 22428] will be killed. Quit anyway? (y or n) y $ cat gdb.txt Starting program: /data/gdb_versions/devel/a.out Breakpoint 1, main () at test.c:19 19 return foo (4); ... The problem is that the '#0 main () at test.c:19' ends up in the gdb output output rather than in gdb.txt. This is due to the fact that the redirect is setup for the current ui_out (which is tui->interp_ui_out ()), while the backtrace output is printed to the INTERP_CONSOLE ui_out. Fix this by limiting switching to INTERP_CONSOLE ui_out to when INTERP_MI is active. Tested on x86_64-linux. gdb/ChangeLog: 2019-11-21 Tom de Vries PR gdb/24956 * cli/cli-script.c (execute_control_command): Only switch to INTERP_CONSOLE's ui_out when INTERP_MI is active. gdb/testsuite/ChangeLog: 2019-11-21 Tom de Vries PR gdb/24956 * gdb.base/ui-redirect.exp: Test output of user-defined command. Change-Id: Id1771e7fcc9496a7d97ec2b2ea6b1487596f1ef7 --- M gdb/ChangeLog M gdb/cli/cli-script.c M gdb/testsuite/ChangeLog M gdb/testsuite/gdb.base/ui-redirect.exp 4 files changed, 35 insertions(+), 0 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index cf65de2..3652685 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,9 @@ +2019-11-21 Tom de Vries + + PR gdb/24956 + * cli/cli-script.c (execute_control_command): Only switch to + INTERP_CONSOLE's ui_out when INTERP_MI is active. + 2019-11-19 Tom Tromey * tui/tui-win.c (tui_partial_win_by_name): Move from tui-data.c. diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c index 316aca0..06cdcd6 100644 --- a/gdb/cli/cli-script.c +++ b/gdb/cli/cli-script.c @@ -696,6 +696,9 @@ enum command_control_type execute_control_command (struct command_line *cmd, int from_tty) { + if (!current_uiout->is_mi_like_p ()) + return execute_control_command_1 (cmd, from_tty); + /* Make sure we use the console uiout. It's possible that we are executing breakpoint commands while running the MI interpreter. */ interp *console = interp_lookup (current_ui, INTERP_CONSOLE); diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index f47ed17..16027e4 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-11-21 Tom de Vries + + PR gdb/24956 + * gdb.base/ui-redirect.exp: Test output of user-defined command. + 2019-11-20 Sergio Durigan Junior * gdb.python/py-progspace.exp: Add missing parentheses on some diff --git a/gdb/testsuite/gdb.base/ui-redirect.exp b/gdb/testsuite/gdb.base/ui-redirect.exp index efcac14..932c74a 100644 --- a/gdb/testsuite/gdb.base/ui-redirect.exp +++ b/gdb/testsuite/gdb.base/ui-redirect.exp @@ -57,6 +57,24 @@ set outdir [standard_output_file {}] set cmds_file "$outdir/cmds.txt" +with_test_prefix "userdefined" { + set test "define userdefined" + gdb_test_multiple $test $test { + -re "End with a line saying just \"end\"\\.\r\n>$" { + pass $test + } + } + + set test "bt" + gdb_test_multiple $test $test { + -re "\r\n>$" { + pass $test + } + } + + gdb_test_no_output "end" +} + with_test_prefix "logging" { gdb_test_no_output "set logging file /dev/null" gdb_test "set logging on" \ @@ -64,6 +82,7 @@ gdb_test "save breakpoints $cmds_file" "Saved to file '$cmds_file'\\." \ "save breakpoints cmds.txt" cmp_file_string "$cmds_file" "$cmds" "cmds.txt" + gdb_test "userdefined" "#0 main ().*" gdb_test "set logging off" "Done logging to /dev/null\\." gdb_test "help" "List of classes of commands:.*" } @@ -74,6 +93,7 @@ "Redirecting output to /dev/null.*Copying debug output to /dev/null\\." gdb_test_no_output "save breakpoints $cmds_file" "save breakpoints cmds.txt" cmp_file_string "$cmds_file" "$cmds" "cmds.txt" + gdb_test_no_output "userdefined" gdb_test "set logging off" "Done logging to /dev/null\\." gdb_test "help" "List of classes of commands:.*" } @@ -87,6 +107,7 @@ gdb_test "save breakpoints $cmds_file" "Saved to file '$cmds_file'\\." \ "save breakpoints cmds.txt" cmp_file_string "$cmds_file" "$cmds" "cmds.txt" + gdb_test "userdefined" "#0 main ().*" gdb_test "set logging off" "Done logging to /dev/null\\." gdb_test "help" "List of classes of commands:.*" gdb_test_no_output "set logging redirect off"