Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH][gdb] Make INTERP_TUI's default ui_out the INTERP_CONSOLE ui_out
@ 2019-09-05  9:58 Tom de Vries
  2019-09-05 12:50 ` Tom de Vries
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Tom de Vries @ 2019-09-05  9:58 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

Hi,

When calling the bt command using a user-defined command while logging with
redirect (escaping '#' using '\' for git commit message convenience):
...
$ gdb -q a.out
Reading symbols from a.out...
(gdb) define mybt
Type commands for definition of "mybt".
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) start
(gdb) mybt
\#0  main () at hello.c:9
...
we get the bt output (the '#0  main () at hello.c:9' above) in the gdb
output rather than in the log file gdb.txt:
...
$ cat gdb.txt
Temporary breakpoint 1 at 0x40053b: file hello.c, line 9.
Starting program: /data/gdb_versions/devel/a.out

Temporary breakpoint 1, main () at hello.c:9
9         printf ("hello\n");
...

If we do the same using "bt" instead of "mybt", the output does end up in the
log file, and not in the gdb output, as expected.

Also, if we build gdb with --disable-tui, the problem disappears.

The problem is caused by:
- the fact that INTERP_TUI maintains two ui_outs, one for TUI mode disabled
  (called the default ui_out) and one for TUI mode enabled, combined with
- the fact that the user-defined commands are interpreted by INTERP_CONSOLE,
  which has its own ui_out.

With --disable-tui, the main interpreter is INTERP_CONSOLE, so the logging
redirect is setup for INTERP_CONSOLE's ui_out, and the redirect has effect
when interpreting the mybt command.

With --enable-tui, the main interpreter is INTERP_TUI, so the logging
redirect is setup for INTERP_TUI's default ui_out, and the redirect has no
effect when interpreting the mybt command using INTERP_CONSOLE.

Fix this by making INTERP_TUI's default ui_out the console ui_out.

Tested on x86_64-linux.

OK for trunk?

Thanks,
- Tom

[gdb] Make INTERP_TUI's default ui_out the INTERP_CONSOLE ui_out

gdb/ChangeLog:

2019-09-05  Tom de Vries  <tdevries@suse.de>

	PR gdb/24956
	* tui/tui-io.c (tui_initialize_io): Make default ui_out the console
	ui_out.

gdb/testsuite/ChangeLog:

2019-09-05  Tom de Vries  <tdevries@suse.de>

	PR gdb/24956
	* gdb.base/ui-redirect.exp: Test output of user-defined command.

---
 gdb/testsuite/gdb.base/ui-redirect.exp | 21 +++++++++++++++++++++
 gdb/tui/tui-io.c                       |  5 ++++-
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/gdb/testsuite/gdb.base/ui-redirect.exp b/gdb/testsuite/gdb.base/ui-redirect.exp
index 4507ac51a2..a1a81aecac 100644
--- a/gdb/testsuite/gdb.base/ui-redirect.exp
+++ b/gdb/testsuite/gdb.base/ui-redirect.exp
@@ -47,11 +47,30 @@ if ![runto_main] {
 gdb_breakpoint "foo"
 gdb_breakpoint "bar"
 
+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" \
     "Copying output to /dev/null.*Copying debug output to /dev/null\\."
     gdb_test "save breakpoints /dev/null" "Saved to file '/dev/null'\\."
+    gdb_test "userdefined" "#0  main ().*"
     gdb_test "set logging off" "Done logging to /dev/null\\."
     gdb_test "help" "List of classes of commands:.*"
 }
@@ -61,6 +80,7 @@ with_test_prefix "redirect" {
     gdb_test "set logging on" \
     "Redirecting output to /dev/null.*Copying debug output to /dev/null\\."
     gdb_test_no_output "save breakpoints /dev/null"
+    gdb_test_no_output "userdefined"
     gdb_test "set logging off" "Done logging to /dev/null\\."
     gdb_test "help" "List of classes of commands:.*"
 }
@@ -72,6 +92,7 @@ with_test_prefix "redirect while already logging" {
     gdb_test "set logging redirect on" \
     ".*warning: Currently logging .*Turn the logging off and on to make the new setting effective.*"
     gdb_test "save breakpoints /dev/null" "Saved to file '/dev/null'\\."
+    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"
diff --git a/gdb/tui/tui-io.c b/gdb/tui/tui-io.c
index ee581a2ff6..eab894325a 100644
--- a/gdb/tui/tui-io.c
+++ b/gdb/tui/tui-io.c
@@ -43,6 +43,7 @@
 #include "gdbsupport/filestuff.h"
 #include "completer.h"
 #include "gdb_curses.h"
+#include "interps.h"
 #include <map>
 
 /* This redefines CTRL if it is not already defined, so it must come
@@ -870,7 +871,9 @@ tui_initialize_io (void)
   tui_out = tui_out_new (tui_stdout);
 
   /* Create the default UI.  */
-  tui_old_uiout = cli_out_new (gdb_stdout);
+  struct interp *interp = interp_lookup (current_ui, "console");
+  tui_old_uiout = dynamic_cast<cli_ui_out *> (interp->interp_ui_out());
+  gdb_assert (tui_old_uiout != nullptr);
 
 #ifdef TUI_USE_PIPE_FOR_READLINE
   /* Temporary solution for readline writing to stdout: redirect


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

* Re: [PATCH][gdb] Make INTERP_TUI's default ui_out the INTERP_CONSOLE ui_out
  2019-09-05  9:58 [PATCH][gdb] Make INTERP_TUI's default ui_out the INTERP_CONSOLE ui_out Tom de Vries
@ 2019-09-05 12:50 ` Tom de Vries
  2019-09-24 15:24 ` [PING][PATCH][gdb] " Tom de Vries
  2019-09-24 17:31 ` [PATCH][gdb] " Andrew Burgess
  2 siblings, 0 replies; 12+ messages in thread
From: Tom de Vries @ 2019-09-05 12:50 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

[-- Attachment #1: Type: text/plain, Size: 173 bytes --]

Reposting version that applies cleanly on current trunk which includes
the commit 30331a6ca0 "[gdb/testsuite] Restore breakpoint command in
ui-redirect.exp"

Thanks,
- Tom


[-- Attachment #2: 0001-gdb-Make-INTERP_TUI-s-default-ui_out-the-INTERP_CONSOLE-ui_out.patch --]
[-- Type: text/x-patch, Size: 5101 bytes --]

[gdb] Make INTERP_TUI's default ui_out the INTERP_CONSOLE ui_out

When calling the bt command using a user-defined command while logging with
redirect (escaping '#' using '\' for git commit message convenience):
...
$ gdb -q a.out
Reading symbols from a.out...
(gdb) define mybt
Type commands for definition of "mybt".
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) start
(gdb) mybt
\#0  main () at hello.c:9
...
we get the bt output (the '#0  main () at hello.c:9' above) in the gdb
output rather than in the log file gdb.txt:
...
$ cat gdb.txt
Temporary breakpoint 1 at 0x40053b: file hello.c, line 9.
Starting program: /data/gdb_versions/devel/a.out

Temporary breakpoint 1, main () at hello.c:9
9         printf ("hello\n");
...

If we do the same using "bt" instead of "mybt", the output does end up in the
log file, and not in the gdb output, as expected.

Also, if we build gdb with --disable-tui, the problem disappears.

The problem is caused by:
- the fact that INTERP_TUI maintains two ui_outs, one for TUI mode disabled
  (called the default ui_out) and one for TUI mode enabled, combined with
- the fact that the user-defined commands are interpreted by INTERP_CONSOLE,
  which has its own ui_out.

With --disable-tui, the main interpreter is INTERP_CONSOLE, so the logging
redirect is setup for INTERP_CONSOLE's ui_out, and the redirect has effect
when interpreting the mybt command.

With --enable-tui, the main interpreter is INTERP_TUI, so the logging
redirect is setup for INTERP_TUI's default ui_out, and the redirect has no
effect when interpreting the mybt command using INTERP_CONSOLE.

Fix this by making INTERP_TUI's default ui_out the console ui_out.

Tested on x86_64-linux.

gdb/ChangeLog:

2019-09-05  Tom de Vries  <tdevries@suse.de>

	PR gdb/24956
	* tui/tui-io.c (tui_initialize_io): Make default ui_out the console
	ui_out.

gdb/testsuite/ChangeLog:

2019-09-05  Tom de Vries  <tdevries@suse.de>

	PR gdb/24956
	* gdb.base/ui-redirect.exp: Test output of user-defined command.

---
 gdb/testsuite/gdb.base/ui-redirect.exp | 21 +++++++++++++++++++++
 gdb/tui/tui-io.c                       |  5 ++++-
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/gdb/testsuite/gdb.base/ui-redirect.exp b/gdb/testsuite/gdb.base/ui-redirect.exp
index efcac14b7c..932c74af4b 100644
--- a/gdb/testsuite/gdb.base/ui-redirect.exp
+++ b/gdb/testsuite/gdb.base/ui-redirect.exp
@@ -57,6 +57,24 @@ set cmds "$cmds\n"
 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 @@ with_test_prefix "logging" {
     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 @@ with_test_prefix "redirect" {
     "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 @@ with_test_prefix "redirect while already logging" {
     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"
diff --git a/gdb/tui/tui-io.c b/gdb/tui/tui-io.c
index ee581a2ff6..eab894325a 100644
--- a/gdb/tui/tui-io.c
+++ b/gdb/tui/tui-io.c
@@ -43,6 +43,7 @@
 #include "gdbsupport/filestuff.h"
 #include "completer.h"
 #include "gdb_curses.h"
+#include "interps.h"
 #include <map>
 
 /* This redefines CTRL if it is not already defined, so it must come
@@ -870,7 +871,9 @@ tui_initialize_io (void)
   tui_out = tui_out_new (tui_stdout);
 
   /* Create the default UI.  */
-  tui_old_uiout = cli_out_new (gdb_stdout);
+  struct interp *interp = interp_lookup (current_ui, "console");
+  tui_old_uiout = dynamic_cast<cli_ui_out *> (interp->interp_ui_out());
+  gdb_assert (tui_old_uiout != nullptr);
 
 #ifdef TUI_USE_PIPE_FOR_READLINE
   /* Temporary solution for readline writing to stdout: redirect

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

* [PING][PATCH][gdb] Make INTERP_TUI's default ui_out the INTERP_CONSOLE ui_out
  2019-09-05  9:58 [PATCH][gdb] Make INTERP_TUI's default ui_out the INTERP_CONSOLE ui_out Tom de Vries
  2019-09-05 12:50 ` Tom de Vries
@ 2019-09-24 15:24 ` Tom de Vries
  2019-09-24 17:31 ` [PATCH][gdb] " Andrew Burgess
  2 siblings, 0 replies; 12+ messages in thread
From: Tom de Vries @ 2019-09-24 15:24 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

On 05-09-19 11:58, Tom de Vries wrote:
> Hi,
> 
> When calling the bt command using a user-defined command while logging with
> redirect (escaping '#' using '\' for git commit message convenience):
> ...
> $ gdb -q a.out
> Reading symbols from a.out...
> (gdb) define mybt
> Type commands for definition of "mybt".
> 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) start
> (gdb) mybt
> \#0  main () at hello.c:9
> ...
> we get the bt output (the '#0  main () at hello.c:9' above) in the gdb
> output rather than in the log file gdb.txt:
> ...
> $ cat gdb.txt
> Temporary breakpoint 1 at 0x40053b: file hello.c, line 9.
> Starting program: /data/gdb_versions/devel/a.out
> 
> Temporary breakpoint 1, main () at hello.c:9
> 9         printf ("hello\n");
> ...
> 
> If we do the same using "bt" instead of "mybt", the output does end up in the
> log file, and not in the gdb output, as expected.
> 
> Also, if we build gdb with --disable-tui, the problem disappears.
> 
> The problem is caused by:
> - the fact that INTERP_TUI maintains two ui_outs, one for TUI mode disabled
>   (called the default ui_out) and one for TUI mode enabled, combined with
> - the fact that the user-defined commands are interpreted by INTERP_CONSOLE,
>   which has its own ui_out.
> 
> With --disable-tui, the main interpreter is INTERP_CONSOLE, so the logging
> redirect is setup for INTERP_CONSOLE's ui_out, and the redirect has effect
> when interpreting the mybt command.
> 
> With --enable-tui, the main interpreter is INTERP_TUI, so the logging
> redirect is setup for INTERP_TUI's default ui_out, and the redirect has no
> effect when interpreting the mybt command using INTERP_CONSOLE.
> 
> Fix this by making INTERP_TUI's default ui_out the console ui_out.
> 
> Tested on x86_64-linux.
> 
> OK for trunk?
> 

Ping.

Thanks,
- Tom

> [gdb] Make INTERP_TUI's default ui_out the INTERP_CONSOLE ui_out
> 
> gdb/ChangeLog:
> 
> 2019-09-05  Tom de Vries  <tdevries@suse.de>
> 
> 	PR gdb/24956
> 	* tui/tui-io.c (tui_initialize_io): Make default ui_out the console
> 	ui_out.
> 
> gdb/testsuite/ChangeLog:
> 
> 2019-09-05  Tom de Vries  <tdevries@suse.de>
> 
> 	PR gdb/24956
> 	* gdb.base/ui-redirect.exp: Test output of user-defined command.
> 
> ---
>  gdb/testsuite/gdb.base/ui-redirect.exp | 21 +++++++++++++++++++++
>  gdb/tui/tui-io.c                       |  5 ++++-
>  2 files changed, 25 insertions(+), 1 deletion(-)
> 
> diff --git a/gdb/testsuite/gdb.base/ui-redirect.exp b/gdb/testsuite/gdb.base/ui-redirect.exp
> index 4507ac51a2..a1a81aecac 100644
> --- a/gdb/testsuite/gdb.base/ui-redirect.exp
> +++ b/gdb/testsuite/gdb.base/ui-redirect.exp
> @@ -47,11 +47,30 @@ if ![runto_main] {
>  gdb_breakpoint "foo"
>  gdb_breakpoint "bar"
>  
> +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" \
>      "Copying output to /dev/null.*Copying debug output to /dev/null\\."
>      gdb_test "save breakpoints /dev/null" "Saved to file '/dev/null'\\."
> +    gdb_test "userdefined" "#0  main ().*"
>      gdb_test "set logging off" "Done logging to /dev/null\\."
>      gdb_test "help" "List of classes of commands:.*"
>  }
> @@ -61,6 +80,7 @@ with_test_prefix "redirect" {
>      gdb_test "set logging on" \
>      "Redirecting output to /dev/null.*Copying debug output to /dev/null\\."
>      gdb_test_no_output "save breakpoints /dev/null"
> +    gdb_test_no_output "userdefined"
>      gdb_test "set logging off" "Done logging to /dev/null\\."
>      gdb_test "help" "List of classes of commands:.*"
>  }
> @@ -72,6 +92,7 @@ with_test_prefix "redirect while already logging" {
>      gdb_test "set logging redirect on" \
>      ".*warning: Currently logging .*Turn the logging off and on to make the new setting effective.*"
>      gdb_test "save breakpoints /dev/null" "Saved to file '/dev/null'\\."
> +    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"
> diff --git a/gdb/tui/tui-io.c b/gdb/tui/tui-io.c
> index ee581a2ff6..eab894325a 100644
> --- a/gdb/tui/tui-io.c
> +++ b/gdb/tui/tui-io.c
> @@ -43,6 +43,7 @@
>  #include "gdbsupport/filestuff.h"
>  #include "completer.h"
>  #include "gdb_curses.h"
> +#include "interps.h"
>  #include <map>
>  
>  /* This redefines CTRL if it is not already defined, so it must come
> @@ -870,7 +871,9 @@ tui_initialize_io (void)
>    tui_out = tui_out_new (tui_stdout);
>  
>    /* Create the default UI.  */
> -  tui_old_uiout = cli_out_new (gdb_stdout);
> +  struct interp *interp = interp_lookup (current_ui, "console");
> +  tui_old_uiout = dynamic_cast<cli_ui_out *> (interp->interp_ui_out());
> +  gdb_assert (tui_old_uiout != nullptr);
>  
>  #ifdef TUI_USE_PIPE_FOR_READLINE
>    /* Temporary solution for readline writing to stdout: redirect
> 


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

* Re: [PATCH][gdb] Make INTERP_TUI's default ui_out the INTERP_CONSOLE ui_out
  2019-09-05  9:58 [PATCH][gdb] Make INTERP_TUI's default ui_out the INTERP_CONSOLE ui_out Tom de Vries
  2019-09-05 12:50 ` Tom de Vries
  2019-09-24 15:24 ` [PING][PATCH][gdb] " Tom de Vries
@ 2019-09-24 17:31 ` Andrew Burgess
  2019-09-24 23:20   ` Tom de Vries
  2 siblings, 1 reply; 12+ messages in thread
From: Andrew Burgess @ 2019-09-24 17:31 UTC (permalink / raw)
  To: Tom de Vries; +Cc: gdb-patches, Tom Tromey

* Tom de Vries <tdevries@suse.de> [2019-09-05 11:58:22 +0200]:

> Hi,
> 
> When calling the bt command using a user-defined command while logging with
> redirect (escaping '#' using '\' for git commit message convenience):
> ...
> $ gdb -q a.out
> Reading symbols from a.out...
> (gdb) define mybt
> Type commands for definition of "mybt".
> 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) start
> (gdb) mybt
> \#0  main () at hello.c:9
> ...
> we get the bt output (the '#0  main () at hello.c:9' above) in the gdb
> output rather than in the log file gdb.txt:
> ...
> $ cat gdb.txt
> Temporary breakpoint 1 at 0x40053b: file hello.c, line 9.
> Starting program: /data/gdb_versions/devel/a.out
> 
> Temporary breakpoint 1, main () at hello.c:9
> 9         printf ("hello\n");
> ...
> 
> If we do the same using "bt" instead of "mybt", the output does end up in the
> log file, and not in the gdb output, as expected.
> 
> Also, if we build gdb with --disable-tui, the problem disappears.
> 
> The problem is caused by:
> - the fact that INTERP_TUI maintains two ui_outs, one for TUI mode disabled
>   (called the default ui_out) and one for TUI mode enabled, combined with
> - the fact that the user-defined commands are interpreted by INTERP_CONSOLE,
>   which has its own ui_out.
> 
> With --disable-tui, the main interpreter is INTERP_CONSOLE, so the logging
> redirect is setup for INTERP_CONSOLE's ui_out, and the redirect has effect
> when interpreting the mybt command.
> 
> With --enable-tui, the main interpreter is INTERP_TUI, so the logging
> redirect is setup for INTERP_TUI's default ui_out, and the redirect has no
> effect when interpreting the mybt command using INTERP_CONSOLE.
> 
> Fix this by making INTERP_TUI's default ui_out the console ui_out.

With this patch applied I see the fixed behaviour you describe at the
CLI, however, if I do:

   (gdb) define mybt
   bt
   end
   (gdb) start
   (gdb) set logging redirect on
   (gdb) tui enable
   (gdb) set logging on
   (gdb) mybt

The I see output appear on both the console and in the log file.  If I
replace mybt with bt then I see the output only go to the log file.
Could this be addressed as part of this patch?

Thanks,
Andrew



> 
> Tested on x86_64-linux.
> 
> OK for trunk?
> 
> Thanks,
> - Tom
> 
> [gdb] Make INTERP_TUI's default ui_out the INTERP_CONSOLE ui_out
> 
> gdb/ChangeLog:
> 
> 2019-09-05  Tom de Vries  <tdevries@suse.de>
> 
> 	PR gdb/24956
> 	* tui/tui-io.c (tui_initialize_io): Make default ui_out the console
> 	ui_out.
> 
> gdb/testsuite/ChangeLog:
> 
> 2019-09-05  Tom de Vries  <tdevries@suse.de>
> 
> 	PR gdb/24956
> 	* gdb.base/ui-redirect.exp: Test output of user-defined command.
> 
> ---
>  gdb/testsuite/gdb.base/ui-redirect.exp | 21 +++++++++++++++++++++
>  gdb/tui/tui-io.c                       |  5 ++++-
>  2 files changed, 25 insertions(+), 1 deletion(-)
> 
> diff --git a/gdb/testsuite/gdb.base/ui-redirect.exp b/gdb/testsuite/gdb.base/ui-redirect.exp
> index 4507ac51a2..a1a81aecac 100644
> --- a/gdb/testsuite/gdb.base/ui-redirect.exp
> +++ b/gdb/testsuite/gdb.base/ui-redirect.exp
> @@ -47,11 +47,30 @@ if ![runto_main] {
>  gdb_breakpoint "foo"
>  gdb_breakpoint "bar"
>  
> +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" \
>      "Copying output to /dev/null.*Copying debug output to /dev/null\\."
>      gdb_test "save breakpoints /dev/null" "Saved to file '/dev/null'\\."
> +    gdb_test "userdefined" "#0  main ().*"
>      gdb_test "set logging off" "Done logging to /dev/null\\."
>      gdb_test "help" "List of classes of commands:.*"
>  }
> @@ -61,6 +80,7 @@ with_test_prefix "redirect" {
>      gdb_test "set logging on" \
>      "Redirecting output to /dev/null.*Copying debug output to /dev/null\\."
>      gdb_test_no_output "save breakpoints /dev/null"
> +    gdb_test_no_output "userdefined"
>      gdb_test "set logging off" "Done logging to /dev/null\\."
>      gdb_test "help" "List of classes of commands:.*"
>  }
> @@ -72,6 +92,7 @@ with_test_prefix "redirect while already logging" {
>      gdb_test "set logging redirect on" \
>      ".*warning: Currently logging .*Turn the logging off and on to make the new setting effective.*"
>      gdb_test "save breakpoints /dev/null" "Saved to file '/dev/null'\\."
> +    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"
> diff --git a/gdb/tui/tui-io.c b/gdb/tui/tui-io.c
> index ee581a2ff6..eab894325a 100644
> --- a/gdb/tui/tui-io.c
> +++ b/gdb/tui/tui-io.c
> @@ -43,6 +43,7 @@
>  #include "gdbsupport/filestuff.h"
>  #include "completer.h"
>  #include "gdb_curses.h"
> +#include "interps.h"
>  #include <map>
>  
>  /* This redefines CTRL if it is not already defined, so it must come
> @@ -870,7 +871,9 @@ tui_initialize_io (void)
>    tui_out = tui_out_new (tui_stdout);
>  
>    /* Create the default UI.  */
> -  tui_old_uiout = cli_out_new (gdb_stdout);
> +  struct interp *interp = interp_lookup (current_ui, "console");
> +  tui_old_uiout = dynamic_cast<cli_ui_out *> (interp->interp_ui_out());
> +  gdb_assert (tui_old_uiout != nullptr);
>  
>  #ifdef TUI_USE_PIPE_FOR_READLINE
>    /* Temporary solution for readline writing to stdout: redirect


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

* Re: [PATCH][gdb] Make INTERP_TUI's default ui_out the INTERP_CONSOLE ui_out
  2019-09-24 17:31 ` [PATCH][gdb] " Andrew Burgess
@ 2019-09-24 23:20   ` Tom de Vries
  2019-09-25  8:36     ` Andrew Burgess
  0 siblings, 1 reply; 12+ messages in thread
From: Tom de Vries @ 2019-09-24 23:20 UTC (permalink / raw)
  To: Andrew Burgess; +Cc: gdb-patches, Tom Tromey

On 24-09-19 19:31, Andrew Burgess wrote:
> With this patch applied I see the fixed behaviour you describe at the
> CLI, however, if I do:
> 
>    (gdb) define mybt
>    bt
>    end
>    (gdb) start
>    (gdb) set logging redirect on
>    (gdb) tui enable
>    (gdb) set logging on
>    (gdb) mybt
> 
> The I see output appear on both the console and in the log file.

I can't reproduce this. Are you sure you removed the gdb.txt file before
starting gdb?

Thanks,
- Tom


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

* Re: [PATCH][gdb] Make INTERP_TUI's default ui_out the INTERP_CONSOLE ui_out
  2019-09-24 23:20   ` Tom de Vries
@ 2019-09-25  8:36     ` Andrew Burgess
  2019-10-01 12:59       ` Tom de Vries
  0 siblings, 1 reply; 12+ messages in thread
From: Andrew Burgess @ 2019-09-25  8:36 UTC (permalink / raw)
  To: Tom de Vries; +Cc: gdb-patches, Tom Tromey

* Tom de Vries <tdevries@suse.de> [2019-09-25 01:20:22 +0200]:

> On 24-09-19 19:31, Andrew Burgess wrote:
> > With this patch applied I see the fixed behaviour you describe at the
> > CLI, however, if I do:
> > 
> >    (gdb) define mybt
> >    bt
> >    end
> >    (gdb) start
> >    (gdb) set logging redirect on
> >    (gdb) tui enable
> >    (gdb) set logging on
> >    (gdb) mybt
> > 
> > The I see output appear on both the console and in the log file.
> 
> I can't reproduce this. Are you sure you removed the gdb.txt file before
> starting gdb?

You're absolutely right, nothing goes to the log for `mybt`, this was
a silly mistake on my side.  Apologies.  However...

With tui enabled and logging on and redirect on, the 'bt' __does__
write to the log, while 'mybt' writes to the screen.  This is the same
bug you're fixing for non-tui mode, correct?  Any solution should
ideally address both cases, or at least be accompanied with an
explanation for why these problems are distinct and should be solved
separately.

Thanks,
Andrew


> 
> Thanks,
> - Tom


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

* Re: [PATCH][gdb] Make INTERP_TUI's default ui_out the INTERP_CONSOLE ui_out
  2019-09-25  8:36     ` Andrew Burgess
@ 2019-10-01 12:59       ` Tom de Vries
  2019-10-03 10:01         ` [PATCH][gdb] Only force INTERP_CONSOLE ui_out for breakpoint commands in MI mode Tom de Vries
  0 siblings, 1 reply; 12+ messages in thread
From: Tom de Vries @ 2019-10-01 12:59 UTC (permalink / raw)
  To: Andrew Burgess; +Cc: gdb-patches, Tom Tromey, Simon Marchi

[-- Attachment #1: Type: text/plain, Size: 1500 bytes --]

On 25-09-19 10:36, Andrew Burgess wrote:
> * Tom de Vries <tdevries@suse.de> [2019-09-25 01:20:22 +0200]:
> 
>> On 24-09-19 19:31, Andrew Burgess wrote:
>>> With this patch applied I see the fixed behaviour you describe at the
>>> CLI, however, if I do:
>>>
>>>    (gdb) define mybt
>>>    bt
>>>    end
>>>    (gdb) start
>>>    (gdb) set logging redirect on
>>>    (gdb) tui enable
>>>    (gdb) set logging on
>>>    (gdb) mybt
>>>
>>> The I see output appear on both the console and in the log file.
>>
>> I can't reproduce this. Are you sure you removed the gdb.txt file before
>> starting gdb?
> 
> You're absolutely right, nothing goes to the log for `mybt`, this was
> a silly mistake on my side.  Apologies.  However...
> 
> With tui enabled and logging on and redirect on, the 'bt' __does__
> write to the log, while 'mybt' writes to the screen.  This is the same
> bug you're fixing for non-tui mode, correct?

From user perspective, yes.

> Any solution should
> ideally address both cases, or at least be accompanied with an
> explanation for why these problems are distinct and should be solved
> separately.
> 

Ideally yes, agreed.

This tentative patch fixes both cases, by limiting the fix of commit
3a87ae656c28 "Use console uiout when executing breakpoint commands" to
the case for which the corresponding problem was reported: INTERP_MI. [
Adding CC simark ]

At this point I don't understand yet why special-casing INTERP_MI would
be the correct thing to do here.

Thanks,
- Tom

[-- Attachment #2: tmp.patch --]
[-- Type: text/x-patch, Size: 892 bytes --]

diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c
index 4fc9c70259c..c8a837bf0f5 100644
--- a/gdb/cli/cli-script.c
+++ b/gdb/cli/cli-script.c
@@ -699,9 +699,14 @@ execute_control_command (struct command_line *cmd, int 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);
-  scoped_restore save_uiout
-    = make_scoped_restore (&current_uiout, console->interp_ui_out ());
+  if (current_interp_named_p (INTERP_MI))
+    {
+      interp *console = interp_lookup (current_ui, INTERP_CONSOLE);
+      scoped_restore save_uiout
+	= make_scoped_restore (&current_uiout, console->interp_ui_out ());
+
+      return execute_control_command_1 (cmd, from_tty);
+    }
 
   return execute_control_command_1 (cmd, from_tty);
 }

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

* [PATCH][gdb] Only force INTERP_CONSOLE ui_out for breakpoint commands in MI mode
  2019-10-01 12:59       ` Tom de Vries
@ 2019-10-03 10:01         ` Tom de Vries
  2019-10-03 12:11           ` Pedro Alves
  0 siblings, 1 reply; 12+ messages in thread
From: Tom de Vries @ 2019-10-03 10:01 UTC (permalink / raw)
  To: Andrew Burgess; +Cc: gdb-patches, Tom Tromey, Simon Marchi

[-- Attachment #1: Type: text/plain, Size: 1823 bytes --]

[ was: Re: [PATCH][gdb] Make INTERP_TUI's default ui_out the
INTERP_CONSOLE ui_out ]

On 01-10-19 14:59, Tom de Vries wrote:
> On 25-09-19 10:36, Andrew Burgess wrote:
>> * Tom de Vries <tdevries@suse.de> [2019-09-25 01:20:22 +0200]:
>>
>>> On 24-09-19 19:31, Andrew Burgess wrote:
>>>> With this patch applied I see the fixed behaviour you describe at the
>>>> CLI, however, if I do:
>>>>
>>>>    (gdb) define mybt
>>>>    bt
>>>>    end
>>>>    (gdb) start
>>>>    (gdb) set logging redirect on
>>>>    (gdb) tui enable
>>>>    (gdb) set logging on
>>>>    (gdb) mybt
>>>>
>>>> The I see output appear on both the console and in the log file.
>>>
>>> I can't reproduce this. Are you sure you removed the gdb.txt file before
>>> starting gdb?
>>
>> You're absolutely right, nothing goes to the log for `mybt`, this was
>> a silly mistake on my side.  Apologies.  However...
>>
>> With tui enabled and logging on and redirect on, the 'bt' __does__
>> write to the log, while 'mybt' writes to the screen.  This is the same
>> bug you're fixing for non-tui mode, correct?
> 
> From user perspective, yes.
> 
>> Any solution should
>> ideally address both cases, or at least be accompanied with an
>> explanation for why these problems are distinct and should be solved
>> separately.
>>
> 
> Ideally yes, agreed.
> 
> This tentative patch fixes both cases, by limiting the fix of commit
> 3a87ae656c28 "Use console uiout when executing breakpoint commands" to
> the case for which the corresponding problem was reported: INTERP_MI. [
> Adding CC simark ]
> 
> At this point I don't understand yet why special-casing INTERP_MI would
> be the correct thing to do here.

I've investigated a bit further the problem that commit 3a87ae656c28
fixes, and constructed a hopefully convincing rationale.

OK for trunk?

Thanks,
- Tom


[-- Attachment #2: 0001-gdb-Only-force-INTERP_CONSOLE-ui_out-for-breakpoint-commands-in-MI-mode.patch --]
[-- Type: text/x-patch, Size: 5455 bytes --]

[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-10-02  Tom de Vries  <tdevries@suse.de>

	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-10-02  Tom de Vries  <tdevries@suse.de>

	PR gdb/24956
	* gdb.base/ui-redirect.exp: Test output of user-defined command.

---
 gdb/cli/cli-script.c                   |  3 +++
 gdb/testsuite/gdb.base/ui-redirect.exp | 21 +++++++++++++++++++++
 2 files changed, 24 insertions(+)

diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c
index 4fc9c70259c..706876a8fee 100644
--- a/gdb/cli/cli-script.c
+++ b/gdb/cli/cli-script.c
@@ -697,6 +697,9 @@ execute_control_command_1 (struct command_line *cmd, int from_tty)
 enum command_control_type
 execute_control_command (struct command_line *cmd, int from_tty)
 {
+  if (!current_interp_named_p (INTERP_MI))
+    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/gdb.base/ui-redirect.exp b/gdb/testsuite/gdb.base/ui-redirect.exp
index efcac14b7cc..932c74af4b5 100644
--- a/gdb/testsuite/gdb.base/ui-redirect.exp
+++ b/gdb/testsuite/gdb.base/ui-redirect.exp
@@ -57,6 +57,24 @@ set cmds "$cmds\n"
 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 @@ with_test_prefix "logging" {
     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 @@ with_test_prefix "redirect" {
     "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 @@ with_test_prefix "redirect while already logging" {
     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"

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

* Re: [PATCH][gdb] Only force INTERP_CONSOLE ui_out for breakpoint commands in MI mode
  2019-10-03 10:01         ` [PATCH][gdb] Only force INTERP_CONSOLE ui_out for breakpoint commands in MI mode Tom de Vries
@ 2019-10-03 12:11           ` Pedro Alves
  2019-10-03 13:51             ` Tom de Vries
  0 siblings, 1 reply; 12+ messages in thread
From: Pedro Alves @ 2019-10-03 12:11 UTC (permalink / raw)
  To: Tom de Vries, Andrew Burgess; +Cc: gdb-patches, Tom Tromey, Simon Marchi

On 10/3/19 11:01 AM, Tom de Vries wrote:
> 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.

> --- a/gdb/cli/cli-script.c
> +++ b/gdb/cli/cli-script.c
> @@ -697,6 +697,9 @@ execute_control_command_1 (struct command_line *cmd, int from_tty)
>  enum command_control_type
>  execute_control_command (struct command_line *cmd, int from_tty)
>  {
> +  if (!current_interp_named_p (INTERP_MI))
> +    return execute_control_command_1 (cmd, from_tty);

Wouldn't we need to handle INTERP_MI1/INTERP_MI2/INTERP_MI3 as well?

Would

 if (current_uiout->is_mi_like_p ())

instead work?

Thanks,
Pedro Alves


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

* Re: [PATCH][gdb] Only force INTERP_CONSOLE ui_out for breakpoint commands in MI mode
  2019-10-03 12:11           ` Pedro Alves
@ 2019-10-03 13:51             ` Tom de Vries
  2019-10-03 14:02               ` Pedro Alves
  0 siblings, 1 reply; 12+ messages in thread
From: Tom de Vries @ 2019-10-03 13:51 UTC (permalink / raw)
  To: Pedro Alves, Andrew Burgess; +Cc: gdb-patches, Tom Tromey, Simon Marchi

[-- Attachment #1: Type: text/plain, Size: 1078 bytes --]

On 03-10-19 14:10, Pedro Alves wrote:
> On 10/3/19 11:01 AM, Tom de Vries wrote:
>> 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.
> 
>> --- a/gdb/cli/cli-script.c
>> +++ b/gdb/cli/cli-script.c
>> @@ -697,6 +697,9 @@ execute_control_command_1 (struct command_line *cmd, int from_tty)
>>  enum command_control_type
>>  execute_control_command (struct command_line *cmd, int from_tty)
>>  {
>> +  if (!current_interp_named_p (INTERP_MI))
>> +    return execute_control_command_1 (cmd, from_tty);
> 
> Wouldn't we need to handle INTERP_MI1/INTERP_MI2/INTERP_MI3 as well?
> 
> Would
> 
>  if (current_uiout->is_mi_like_p ())
> 
> instead work?

Yep, that works as well. Patch updated accordingly and re-tested.

OK for trunk?

Thanks,
- Tom

[-- Attachment #2: 0001-gdb-Only-force-INTERP_CONSOLE-ui_out-for-breakpoint-commands-in-MI-mode.patch --]
[-- Type: text/x-patch, Size: 5451 bytes --]

[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-10-02  Tom de Vries  <tdevries@suse.de>

	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-10-02  Tom de Vries  <tdevries@suse.de>

	PR gdb/24956
	* gdb.base/ui-redirect.exp: Test output of user-defined command.

---
 gdb/cli/cli-script.c                   |  3 +++
 gdb/testsuite/gdb.base/ui-redirect.exp | 21 +++++++++++++++++++++
 2 files changed, 24 insertions(+)

diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c
index 4fc9c70259c..c460792daff 100644
--- a/gdb/cli/cli-script.c
+++ b/gdb/cli/cli-script.c
@@ -697,6 +697,9 @@ execute_control_command_1 (struct command_line *cmd, int from_tty)
 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/gdb.base/ui-redirect.exp b/gdb/testsuite/gdb.base/ui-redirect.exp
index efcac14b7cc..932c74af4b5 100644
--- a/gdb/testsuite/gdb.base/ui-redirect.exp
+++ b/gdb/testsuite/gdb.base/ui-redirect.exp
@@ -57,6 +57,24 @@ set cmds "$cmds\n"
 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 @@ with_test_prefix "logging" {
     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 @@ with_test_prefix "redirect" {
     "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 @@ with_test_prefix "redirect while already logging" {
     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"

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

* Re: [PATCH][gdb] Only force INTERP_CONSOLE ui_out for breakpoint commands in MI mode
  2019-10-03 13:51             ` Tom de Vries
@ 2019-10-03 14:02               ` Pedro Alves
  2019-11-11 16:27                 ` Joel Brobecker
  0 siblings, 1 reply; 12+ messages in thread
From: Pedro Alves @ 2019-10-03 14:02 UTC (permalink / raw)
  To: Tom de Vries, Andrew Burgess; +Cc: gdb-patches, Tom Tromey, Simon Marchi

On 10/3/19 2:51 PM, Tom de Vries wrote:
> On 03-10-19 14:10, Pedro Alves wrote:

>>> --- a/gdb/cli/cli-script.c
>>> +++ b/gdb/cli/cli-script.c
>>> @@ -697,6 +697,9 @@ execute_control_command_1 (struct command_line *cmd, int from_tty)
>>>  enum command_control_type
>>>  execute_control_command (struct command_line *cmd, int from_tty)
>>>  {
>>> +  if (!current_interp_named_p (INTERP_MI))
>>> +    return execute_control_command_1 (cmd, from_tty);
>>
>> Wouldn't we need to handle INTERP_MI1/INTERP_MI2/INTERP_MI3 as well?
>>
>> Would
>>
>>  if (current_uiout->is_mi_like_p ())
>>
>> instead work?
> 
> Yep, that works as well. Patch updated accordingly and re-tested.
> 
> OK for trunk?

Seems good to me, but I think we should hear from Andrew as well.

Thanks,
Pedro Alves


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

* Re: [PATCH][gdb] Only force INTERP_CONSOLE ui_out for breakpoint commands in MI mode
  2019-10-03 14:02               ` Pedro Alves
@ 2019-11-11 16:27                 ` Joel Brobecker
  0 siblings, 0 replies; 12+ messages in thread
From: Joel Brobecker @ 2019-11-11 16:27 UTC (permalink / raw)
  To: Andrew Burgess; +Cc: Tom de Vries, gdb-patches, Tom Tromey, Simon Marchi

Hey Andrew,

> > OK for trunk?
> 
> Seems good to me, but I think we should hear from Andrew as well.

Any chance you could double-check this patch?

As I understand it, the latest version of the patch is available on
Gerrit: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/28

Thank you!
-- 
Joel


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

end of thread, other threads:[~2019-11-11 16:27 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-05  9:58 [PATCH][gdb] Make INTERP_TUI's default ui_out the INTERP_CONSOLE ui_out Tom de Vries
2019-09-05 12:50 ` Tom de Vries
2019-09-24 15:24 ` [PING][PATCH][gdb] " Tom de Vries
2019-09-24 17:31 ` [PATCH][gdb] " Andrew Burgess
2019-09-24 23:20   ` Tom de Vries
2019-09-25  8:36     ` Andrew Burgess
2019-10-01 12:59       ` Tom de Vries
2019-10-03 10:01         ` [PATCH][gdb] Only force INTERP_CONSOLE ui_out for breakpoint commands in MI mode Tom de Vries
2019-10-03 12:11           ` Pedro Alves
2019-10-03 13:51             ` Tom de Vries
2019-10-03 14:02               ` Pedro Alves
2019-11-11 16:27                 ` Joel Brobecker

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox