diff options
author | Peter Waller <p@pwaller.net> | 2020-12-21 09:38:07 -0500 |
---|---|---|
committer | Simon Marchi <simon.marchi@polymtl.ca> | 2020-12-21 09:38:22 -0500 |
commit | e1ff6226d8e36896edbdd651753a3e1292381ba0 (patch) | |
tree | c30ef5fba5cf64bd5d6ae951132b0b2880643623 /gdb/testsuite | |
parent | ca01f1bf3d9e5f5bcddf72bd83f574395e859d1c (diff) | |
download | gdb-e1ff6226d8e36896edbdd651753a3e1292381ba0.zip gdb-e1ff6226d8e36896edbdd651753a3e1292381ba0.tar.gz gdb-e1ff6226d8e36896edbdd651753a3e1292381ba0.tar.bz2 |
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
Diffstat (limited to 'gdb/testsuite')
-rw-r--r-- | gdb/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gdb/testsuite/gdb.base/style-interp-exec-mi.c | 22 | ||||
-rw-r--r-- | gdb/testsuite/gdb.base/style-interp-exec-mi.exp | 46 |
3 files changed, 73 insertions, 0 deletions
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 3e08608..da1f22d 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2020-12-21 Peter Waller <p@pwaller.net> + + * gdb.base/style-interp-exec-mi.exp: New. + * gdb.base/style-interp-exec-mi.c: New. + 2020-12-21 Simon Marchi <simon.marchi@polymtl.ca> * gdb.base/list.exp: Replace send_gdb + gdb_expect with diff --git a/gdb/testsuite/gdb.base/style-interp-exec-mi.c b/gdb/testsuite/gdb.base/style-interp-exec-mi.c new file mode 100644 index 0000000..9d7b2f1 --- /dev/null +++ b/gdb/testsuite/gdb.base/style-interp-exec-mi.c @@ -0,0 +1,22 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2020 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +int +main (void) +{ + return 0; +} diff --git a/gdb/testsuite/gdb.base/style-interp-exec-mi.exp b/gdb/testsuite/gdb.base/style-interp-exec-mi.exp new file mode 100644 index 0000000..f3f010e --- /dev/null +++ b/gdb/testsuite/gdb.base/style-interp-exec-mi.exp @@ -0,0 +1,46 @@ +# Copyright 2020 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +# It was observed that when doing: +# +# - backtrace +# - an "interpreter-exec mi" command +# - backtrace again +# +# The second backtrace would not be styled. This test tests that. + +standard_testfile + +save_vars { env(TERM) } { + # We need an ANSI-capable terminal to get the output. + setenv TERM ansi + + if { [prepare_for_testing "failed to prepare" \ + ${testfile} ${srcfile}] } { + return + } + + if { ![runto_main] } { + untested "could not run to main" + return + } + + gdb_test_no_output "set style enabled on" + set main_expr [style main function] + gdb_test "backtrace" ".* ${main_expr} .*" "backtrace before" + gdb_test "interpreter-exec mi \"-data-evaluate-expression 1\"" \ + "\\^done,value=\"1\"" + gdb_test "backtrace" ".* ${main_expr} .*" "backtrace after" +} |