8sa1-binutils-gdb/gdb/cli
Tom de Vries 65d1cd5f9c [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 3a87ae656c "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  <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-11-21  Tom de Vries  <tdevries@suse.de>

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

Change-Id: Id1771e7fcc9496a7d97ec2b2ea6b1487596f1ef7
2019-11-21 11:02:27 +01:00
..
cli-cmds.c Remove some includes of readline.h 2019-11-06 07:29:43 -07:00
cli-cmds.h Move declaration of max_user_call_depth to header 2019-10-12 14:31:26 -05:00
cli-decode.c [gdb] Fix more typos in comments (2) 2019-10-26 09:55:32 +02:00
cli-decode.h Make first and last lines of 'command help documentation' consistent. 2019-08-07 00:04:33 +02:00
cli-dump.c Remove some includes of readline.h 2019-11-06 07:29:43 -07:00
cli-interp.c Add debug redirect option 2019-05-17 14:21:47 +01:00
cli-interp.h Add debug redirect option 2019-05-17 14:21:47 +01:00
cli-logging.c Use styled_string for "show logging filename" 2019-10-01 15:12:41 -06:00
cli-option.c Make first and last lines of 'command help documentation' consistent. 2019-08-07 00:04:33 +02:00
cli-option.h Change boolean options to bool instead of int 2019-09-18 09:35:12 +09:00
cli-script.c [gdb] Only force INTERP_CONSOLE ui_out for breakpoint commands in MI mode 2019-11-21 11:02:27 +01:00
cli-script.h Don't include gdbarch.h from defs.h 2019-07-10 14:53:53 -06:00
cli-setshow.c Implement convenience functions to examine GDB settings. 2019-10-31 23:31:43 +01:00
cli-setshow.h Implement convenience functions to examine GDB settings. 2019-10-31 23:31:43 +01:00
cli-style.c [gdb] Fix set/show style metadata help text 2019-10-03 10:15:39 +02:00
cli-style.h Remove unused constructor declaration from cli_style_option 2019-11-10 09:48:42 -07:00
cli-utils.c gdb: Add new -n flag to some info commands 2019-08-27 16:21:42 +01:00
cli-utils.h [gdb] Fix more typos in comments (2) 2019-10-26 09:55:32 +02:00