From patchwork Sat Oct 21 18:41:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 23754 Received: (qmail 19179 invoked by alias); 21 Oct 2017 18:41:37 -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 18783 invoked by uid 89); 21 Oct 2017 18:41:36 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_SOFTFAIL autolearn=ham version=3.3.2 spammy=0* X-HELO: barracuda.ebox.ca Received: from barracuda.ebox.ca (HELO barracuda.ebox.ca) (96.127.255.19) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 21 Oct 2017 18:41:34 +0000 X-ASG-Debug-ID: 1508611282-0c856e65d5381b360001-fS2M51 Received: from smtp.electronicbox.net (smtp.electronicbox.net [96.127.255.82]) by barracuda.ebox.ca with ESMTP id gLsYTuVC4uulLXcG (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sat, 21 Oct 2017 14:41:22 -0400 (EDT) X-Barracuda-Envelope-From: simon.marchi@polymtl.ca X-Barracuda-RBL-Trusted-Forwarder: 96.127.255.82 Received: from simark.lan (cable-192.222.251.162.electronicbox.net [192.222.251.162]) by smtp.electronicbox.net (Postfix) with ESMTP id C1F68441B21; Sat, 21 Oct 2017 14:41:22 -0400 (EDT) From: Simon Marchi X-Barracuda-Effective-Source-IP: cable-192.222.251.162.electronicbox.net[192.222.251.162] X-Barracuda-Apparent-Source-IP: 192.222.251.162 X-Barracuda-RBL-IP: 192.222.251.162 To: gdb-patches@sourceware.org Cc: eliz@gnu.org, Simon Marchi Subject: [PATCH] Use console uiout when executing breakpoint commands Date: Sat, 21 Oct 2017 14:41:21 -0400 X-ASG-Orig-Subj: [PATCH] Use console uiout when executing breakpoint commands Message-Id: <20171021184121.694-1-simon.marchi@polymtl.ca> In-Reply-To: <83vaj8c3fj.fsf@gnu.org> References: <83vaj8c3fj.fsf@gnu.org> X-Barracuda-Connect: smtp.electronicbox.net[96.127.255.82] X-Barracuda-Start-Time: 1508611282 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://96.127.255.19:443/cgi-mod/mark.cgi X-Barracuda-Scan-Msg-Size: 4158 X-Barracuda-BRTS-Status: 1 X-Barracuda-Spam-Score: 0.00 X-Barracuda-Spam-Status: No, SCORE=0.00 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=8.0 tests= X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.44091 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- X-IsSubscribed: yes As reported here https://sourceware.org/ml/gdb/2017-10/msg00020.html the output of certain commands, like backtrace, doesn't appear anywhere when it is run as a breakpoint command and when using MI. The reason is that the current_uiout is set to the mi_ui_out while these commands run, whereas we want the output as CLI output. Some commands like "print" work, because they use printf_filtered (gdb_stdout, ...) directly, bypassing the current ui_out. The fix I did is to force setting the cli_uiout as the current_uiout when calling execute_control_command. I am not sure if this is the right way to fix the problem, comments about the approach would be appreciated. I enhanced gdb.mi/mi-break.exp to test the backtrace command. Regtested on the buildbot. gdb/ChangeLog: * cli/cli-script.c (execute_control_command): Rename to ... (execute_control_command_1): ... this. (execute_control_command): New function. gdb/testsuite/ChangeLog: * gdb.mi/mi-break.exp (test_breakpoint_commands): Test backtrace as a breakpoint command. --- gdb/cli/cli-script.c | 23 +++++++++++++++++++---- gdb/testsuite/gdb.mi/mi-break.exp | 4 ++-- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c index 0a93e8b54f..8fbdc83c5c 100644 --- a/gdb/cli/cli-script.c +++ b/gdb/cli/cli-script.c @@ -463,8 +463,10 @@ print_command_trace (const char *cmd) printf_filtered ("%s\n", cmd); } -enum command_control_type -execute_control_command (struct command_line *cmd) +/* Helper for execute_control_command. */ + +static enum command_control_type +execute_control_command_1 (struct command_line *cmd) { struct command_line *current; struct value *val; @@ -541,7 +543,7 @@ execute_control_command (struct command_line *cmd) { scoped_restore save_nesting = make_scoped_restore (&command_nest_depth, command_nest_depth + 1); - ret = execute_control_command (current); + ret = execute_control_command_1 (current); /* If we got an error, or a "break" command, then stop looping. */ @@ -600,7 +602,7 @@ execute_control_command (struct command_line *cmd) { scoped_restore save_nesting = make_scoped_restore (&command_nest_depth, command_nest_depth + 1); - ret = execute_control_command (current); + ret = execute_control_command_1 (current); /* If we got an error, get out. */ if (ret != simple_control) @@ -644,6 +646,19 @@ execute_control_command (struct command_line *cmd) return ret; } +enum command_control_type +execute_control_command (struct command_line *cmd) +{ + /* Make sure we use the console interp and uiout. It's possible + that we are executing breakpoint commands while running the MI + interpreter. */ + interp *console = interp_lookup (current_ui, INTERP_CONSOLE); + scoped_restore save_uiout + = make_scoped_restore (¤t_uiout, interp_ui_out (console)); + + return execute_control_command_1 (cmd); +} + /* Like execute_control_command, but first set suppress_next_print_command_trace. */ diff --git a/gdb/testsuite/gdb.mi/mi-break.exp b/gdb/testsuite/gdb.mi/mi-break.exp index 38670c293b..41a48a1400 100644 --- a/gdb/testsuite/gdb.mi/mi-break.exp +++ b/gdb/testsuite/gdb.mi/mi-break.exp @@ -277,7 +277,7 @@ proc test_breakpoint_commands {} { -number 9 -disp keep -func callee2 -file ".*basics.c" \ -line $line_callee2_body - mi_gdb_test "-break-commands 9 \"set \$i=0\" \"while \$i<10\" \"print \$i\" \"set \$i=\$i+1\" \"end\" \"continue\" " \ + mi_gdb_test "-break-commands 9 \"bt\" \"set \$i=0\" \"while \$i<10\" \"print \$i\" \"set \$i=\$i+1\" \"end\" \"continue\" " \ "\\^done" \ "breakpoint commands: set commands" @@ -291,7 +291,7 @@ proc test_breakpoint_commands {} { set test "intermediate stop and continue, bp commands" gdb_expect { -i $gdb_main_spawn_id - -re ".*\\\$1 = 0.*\\\$10 = 9" { + -re ".*callee2.*callee1.*main.*\\\$1 = 0.*\\\$10 = 9" { pass $test } timeout {