Preserve gdb_std{out, err, log, targ, targerr} across interpreter_exec_cmd
authorPeter Waller <p@pwaller.net>
Mon, 21 Dec 2020 14:38:07 +0000 (09:38 -0500)
committerSimon Marchi <simon.marchi@polymtl.ca>
Mon, 21 Dec 2020 14:38:22 +0000 (09:38 -0500)
commite1ff6226d8e36896edbdd651753a3e1292381ba0
treec30ef5fba5cf64bd5d6ae951132b0b2880643623
parentca01f1bf3d9e5f5bcddf72bd83f574395e859d1c
Preserve gdb_std{out, err, log, targ, targerr} across interpreter_exec_cmd

Calls through interpreter_exec_cmd can cause the output state to be modified in
a way which doesn't get back after the execution.

It looks like the intent is that interp::resume should put things back how they
should be, however, mi_interp::resume modifies gdb_stdout and nothing currently
restores it to the previous state.

To see the broken behaviour:

  gdb -ex starti -ex bt -ex 'interpreter-exec mi echo' -ex bt -ex q echo <<<''

Prior to this patch, on a terminal environment, the first backtrace is
coloured, and the second backtrace is not. The reason is that
stdio_file::can_emit_style_escape becomes false, because the gdb_stdout gets
overwritten in mi_interp::resume and not replaced.

gdb/ChangeLog:

* interps.c (interpreter_exec_cmd): Restore streams pointers.

gdb/testsuite/ChangeLog:

* gdb.base/style-interp-exec-mi.exp: New.
* gdb.base/style-interp-exec-mi.c: New.

Signed-off-by: Peter Waller <p@pwaller.net>
Change-Id: Id87423b262d058857ea9dca5866ca6471741e512
gdb/ChangeLog
gdb/interps.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.base/style-interp-exec-mi.c [new file with mode: 0644]
gdb/testsuite/gdb.base/style-interp-exec-mi.exp [new file with mode: 0644]