public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* Re: Breakpoint commands in MI mode and "backtrace"
       [not found]               ` <fb95da6b-2390-f486-0806-291d24fbe766@simark.ca>
@ 2017-10-21  8:26                 ` Eli Zaretskii
  2017-10-21 14:13                   ` Simon Marchi
  2017-10-21 18:41                   ` [PATCH] Use console uiout when executing breakpoint commands Simon Marchi
  0 siblings, 2 replies; 6+ messages in thread
From: Eli Zaretskii @ 2017-10-21  8:26 UTC (permalink / raw)
  To: Simon Marchi; +Cc: gdb, gdb-patches

> Cc: gdb@sourceware.org
> From: Simon Marchi <simark@simark.ca>
> Date: Mon, 9 Oct 2017 08:02:24 -0400
> 
> Anyhow, can you try this patch here?  It changes the uiout manually instead of
> going through safe_execute_command.

Since this worked for me, in GDB 8.0, can something similar be put in
the current master, so the next GDB release will have this bug fixed?

Thanks.

> diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c
> index f1db954a69..b08954132b 100644
> --- a/gdb/cli/cli-script.c
> +++ b/gdb/cli/cli-script.c
> @@ -472,6 +472,8 @@ print_command_trace (const char *cmd)
>    printf_filtered ("%s\n", cmd);
>  }
> 
> +static void restore_interp (void *arg);
> +
>  enum command_control_type
>  execute_control_command (struct command_line *cmd)
>  {
> @@ -491,8 +493,17 @@ execute_control_command (struct command_line *cmd)
>        {
>  	/* A simple command, execute it and return.  */
>  	std::string new_line = insert_user_defined_cmd_args (cmd->line);
> +
> +	struct interp *old_interp = interp_set_temp (INTERP_CONSOLE);
> +	struct cleanup *old_chain = make_cleanup (restore_interp, old_interp);
> +	scoped_restore save_uiout
> +	  = make_scoped_restore (&current_uiout,
> +		     current_interpreter ()->interp_ui_out ());
> +
>  	execute_command (&new_line[0], 0);
>  	ret = cmd->control_type;
> +
> +	do_cleanups (old_chain);
>  	break;
>        }
> 
> 
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Breakpoint commands in MI mode and "backtrace"
  2017-10-21  8:26                 ` Breakpoint commands in MI mode and "backtrace" Eli Zaretskii
@ 2017-10-21 14:13                   ` Simon Marchi
  2017-10-21 16:27                     ` Eli Zaretskii
  2017-10-21 18:41                   ` [PATCH] Use console uiout when executing breakpoint commands Simon Marchi
  1 sibling, 1 reply; 6+ messages in thread
From: Simon Marchi @ 2017-10-21 14:13 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: gdb, gdb-patches

On 2017-10-21 04:26 AM, Eli Zaretskii wrote:
>> Cc: gdb@sourceware.org
>> From: Simon Marchi <simark@simark.ca>
>> Date: Mon, 9 Oct 2017 08:02:24 -0400
>>
>> Anyhow, can you try this patch here?  It changes the uiout manually instead of
>> going through safe_execute_command.
> 
> Since this worked for me, in GDB 8.0, can something similar be put in
> the current master, so the next GDB release will have this bug fixed?
> 
> Thanks.

I'll look into it, but I'll try a slightly different patch.  The one I sent
previously sets and restores the interpreter at every executed command, which
is inefficient.  I'll try to set and restore only once at a higher level in
the call stack.

Simon

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Breakpoint commands in MI mode and "backtrace"
  2017-10-21 14:13                   ` Simon Marchi
@ 2017-10-21 16:27                     ` Eli Zaretskii
  0 siblings, 0 replies; 6+ messages in thread
From: Eli Zaretskii @ 2017-10-21 16:27 UTC (permalink / raw)
  To: Simon Marchi; +Cc: gdb, gdb-patches

> Cc: gdb@sourceware.org, gdb-patches@sourceware.org
> From: Simon Marchi <simark@simark.ca>
> Date: Sat, 21 Oct 2017 10:13:20 -0400
> 
> > Since this worked for me, in GDB 8.0, can something similar be put in
> > the current master, so the next GDB release will have this bug fixed?
> > 
> > Thanks.
> 
> I'll look into it, but I'll try a slightly different patch.  The one I sent
> previously sets and restores the interpreter at every executed command, which
> is inefficient.  I'll try to set and restore only once at a higher level in
> the call stack.

Thank you.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH] Use console uiout when executing breakpoint commands
  2017-10-21  8:26                 ` Breakpoint commands in MI mode and "backtrace" Eli Zaretskii
  2017-10-21 14:13                   ` Simon Marchi
@ 2017-10-21 18:41                   ` Simon Marchi
  2017-11-01  1:37                     ` Simon Marchi
  1 sibling, 1 reply; 6+ messages in thread
From: Simon Marchi @ 2017-10-21 18:41 UTC (permalink / raw)
  To: gdb-patches; +Cc: eliz, Simon Marchi

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 (&current_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 {
-- 
2.14.2

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Use console uiout when executing breakpoint commands
  2017-10-21 18:41                   ` [PATCH] Use console uiout when executing breakpoint commands Simon Marchi
@ 2017-11-01  1:37                     ` Simon Marchi
  2017-11-01  3:45                       ` Eli Zaretskii
  0 siblings, 1 reply; 6+ messages in thread
From: Simon Marchi @ 2017-11-01  1:37 UTC (permalink / raw)
  To: gdb-patches; +Cc: eliz

On 2017-10-21 02:41 PM, Simon Marchi wrote:
> 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.

I pushed this patch in.

Simon

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Use console uiout when executing breakpoint commands
  2017-11-01  1:37                     ` Simon Marchi
@ 2017-11-01  3:45                       ` Eli Zaretskii
  0 siblings, 0 replies; 6+ messages in thread
From: Eli Zaretskii @ 2017-11-01  3:45 UTC (permalink / raw)
  To: Simon Marchi; +Cc: gdb-patches

> Cc: eliz@gnu.org
> From: Simon Marchi <simon.marchi@polymtl.ca>
> Date: Tue, 31 Oct 2017 21:37:09 -0400
> 
> I pushed this patch in.

Great, thanks a lot!

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-11-01  3:45 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <8360bqt0im.fsf@gnu.org>
     [not found] ` <8a3d7153-7486-032f-aabc-6c3453f96459@simark.ca>
     [not found]   ` <83shetsdg2.fsf@gnu.org>
     [not found]     ` <e65519d3-37e8-06f0-cd5a-d7e6b7aaf31d@simark.ca>
     [not found]       ` <83o9phs8zw.fsf@gnu.org>
     [not found]         ` <b0ce9014-a231-6d57-8a72-6da1eb80f67b@simark.ca>
     [not found]           ` <83d15wsrvw.fsf@gnu.org>
     [not found]             ` <83bmlgsqpm.fsf@gnu.org>
     [not found]               ` <fb95da6b-2390-f486-0806-291d24fbe766@simark.ca>
2017-10-21  8:26                 ` Breakpoint commands in MI mode and "backtrace" Eli Zaretskii
2017-10-21 14:13                   ` Simon Marchi
2017-10-21 16:27                     ` Eli Zaretskii
2017-10-21 18:41                   ` [PATCH] Use console uiout when executing breakpoint commands Simon Marchi
2017-11-01  1:37                     ` Simon Marchi
2017-11-01  3:45                       ` Eli Zaretskii

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).