binutils-gdb/gdb/testsuite/gdb.base/new-ui-echo.exp

128 lines
3.8 KiB
Plaintext
Raw Normal View History

# Copyright 2016-2018 Free Software Foundation, Inc.
Fix PR20494 - User input stops being echoed in CLI This patch fixes a problem that problem triggers if you start an inferior, e.g., with the "start" command, in a UI created with the new-ui command, and then run a foreground execution command in the main UI. Once the program stops for the latter command, typing in the main UI no longer echoes back to the user. The problem revolves around this: - gdb_has_a_terminal computes its result lazily, on first call. that is what saves gdb's initial main UI terminal state (the UI associated with stdin): our_terminal_info.ttystate = serial_get_tty_state (stdin_serial); This is the state that target_terminal_ours() restores. - In this scenario, the gdb_has_a_terminal function happens to be first ever called from within the target_terminal_init call in startup_inferior: (top-gdb) bt #0 gdb_has_a_terminal () at src/gdb/inflow.c:157 #1 0x000000000079db22 in child_terminal_init_with_pgrp () at src/gdb/inflow.c:217 [...] #4 0x000000000065bacb in target_terminal_init () at src/gdb/target.c:456 #5 0x00000000004676d2 in startup_inferior () at src/gdb/fork-child.c:531 [...] #7 0x000000000046b168 in linux_nat_create_inferior () at src/gdb/linux-nat.c:1112 [...] #9 0x00000000005f20c9 in start_command (args=0x0, from_tty=1) at src/gdb/infcmd.c:657 If the command to start the inferior is issued on the main UI, then readline will have deprepped the terminal when we reach the above, and the problem doesn't appear. If however the command is issued on a non-main UI, then when we reach that gdb_has_a_terminal call, the main UI's terminal state is still set to whatever readline has sets it to in rl_prep_terminal, which happens to have echo disabled. Later, when the following synchronous execution command finishes, we'll call target_terminal_ours to restore gdb's the main UI's terminal settings, and that restores the terminal state with echo disabled... Conceptually, the fix is to move the gdb_has_a_terminal call earlier, to someplace during GDB initialization, before readline/ncurses have had a chance to change terminal settings. Turns out that "set_initial_gdb_ttystate" is exactly such a place. I say conceptually, because the fix actually inlines the gdb_has_a_terminal part that saves the terminal state in set_initial_gdb_ttystate and then simplifies gdb_has_a_terminal, since there's no point in making gdb_has_a_terminal do lazy computation. gdb/ChangeLog: 2016-08-23 Pedro Alves <palves@redhat.com> PR gdb/20494 * inflow.c (our_terminal_info, initial_gdb_ttystate): Update comments. (enum gdb_has_a_terminal_flag_enum, gdb_has_a_terminal_flag): Delete. (set_initial_gdb_ttystate): Record our_terminal_info here too, instead of ... (gdb_has_a_terminal): ... here. Reimplement in terms of initial_gdb_ttystate. Make static. * terminal.h (gdb_has_a_terminal): Delete declaration. (set_initial_gdb_ttystate): Add comment. * top.c (show_interactive_mode): Use input_interactive_p instead of gdb_has_a_terminal. gdb/testsuite/ChangeLog: 2016-08-23 Pedro Alves <palves@redhat.com> PR gdb/20494 * gdb.base/new-ui-echo.c: New file. * gdb.base/new-ui-echo.exp: New file.
2016-08-23 17:03:28 +02:00
# 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/>.
# Regression test for PR 20494 (User input stops being echoed in CLI).
# Before that bug was fixed, starting an inferior in a non-main UI
# would result in GDB saving readline's prepped terminal state as
# gdb's "own" terminal state (i.e., target_terminal_ours state),
# resulting in subsequent synchronous execution commands in the main
# UI disabling input echo.
standard_testfile
set compile_options "debug"
if {[build_executable $testfile.exp $testfile ${srcfile} ${compile_options}] == -1} {
Fixup testcases outputting own name as a test name and standardize failed compilation messages Changes in v3: - Adjusted some testcases where the message "failed to compile" was not unique. Changes in v2: - Addressed comments from reviewers. - Fixed spurious whitespaces. - Changed compilation failure messages that included source/binary paths to ones that are short and deterministic. --- Another bit of cleanup to the testsuite. We have a number of tests that are not honoring the rule of not outputting their own name as a test name. I fixed up all the offenders i could find with the following regular expression: "(xfail|kfail|kpass|fail|pass|unsupported|untested) ([A-Za-z0-9]+|\\\$(.)*testfile(.)*)\.exp$" gdb/testsuite/ChangeLog: 2016-12-01 Luis Machado <lgustavo@codesourcery.com> Fix test names and standardize compilation error messages throughout the following files: * gdb.ada/start.exp * gdb.arch/alpha-step.exp * gdb.arch/e500-prologue.exp * gdb.arch/ftrace-insn-reloc.exp * gdb.arch/gdb1291.exp * gdb.arch/gdb1431.exp * gdb.arch/gdb1558.exp * gdb.arch/i386-dr3-watch.exp * gdb.arch/i386-sse-stack-align.exp * gdb.arch/ia64-breakpoint-shadow.exp * gdb.arch/pa-nullify.exp * gdb.arch/powerpc-aix-prologue.exp * gdb.arch/thumb-bx-pc.exp * gdb.base/annota1.exp * gdb.base/annota3.exp * gdb.base/arrayidx.exp * gdb.base/assign.exp * gdb.base/attach.exp * gdb.base/auxv.exp * gdb.base/bang.exp * gdb.base/bfp-test.exp * gdb.base/bigcore.exp * gdb.base/bitfields2.exp * gdb.base/break-fun-addr.exp * gdb.base/break-probes.exp * gdb.base/call-rt-st.exp * gdb.base/callexit.exp * gdb.base/catch-fork-kill.exp * gdb.base/charset.exp * gdb.base/checkpoint.exp * gdb.base/comprdebug.exp * gdb.base/constvars.exp * gdb.base/coredump-filter.exp * gdb.base/cursal.exp * gdb.base/cvexpr.exp * gdb.base/detach.exp * gdb.base/display.exp * gdb.base/dmsym.exp * gdb.base/dprintf-pending.exp * gdb.base/dso2dso.exp * gdb.base/dtrace-probe.exp * gdb.base/dump.exp * gdb.base/enum_cond.exp * gdb.base/exe-lock.exp * gdb.base/exec-invalid-sysroot.exp * gdb.base/execl-update-breakpoints.exp * gdb.base/exprs.exp * gdb.base/fileio.exp * gdb.base/find.exp * gdb.base/finish.exp * gdb.base/fixsection.exp * gdb.base/foll-vfork.exp * gdb.base/frame-args.exp * gdb.base/gcore.exp * gdb.base/gdb1250.exp * gdb.base/global-var-nested-by-dso.exp * gdb.base/gnu-ifunc.exp * gdb.base/hashline1.exp * gdb.base/hashline2.exp * gdb.base/hashline3.exp * gdb.base/hbreak-in-shr-unsupported.exp * gdb.base/huge.exp * gdb.base/infcall-input.exp * gdb.base/info-fun.exp * gdb.base/info-shared.exp * gdb.base/jit-simple.exp * gdb.base/jit-so.exp * gdb.base/jit.exp * gdb.base/jump.exp * gdb.base/label.exp * gdb.base/lineinc.exp * gdb.base/logical.exp * gdb.base/longjmp.exp * gdb.base/macscp.exp * gdb.base/miscexprs.exp * gdb.base/new-ui-echo.exp * gdb.base/new-ui-pending-input.exp * gdb.base/new-ui.exp * gdb.base/nodebug.exp * gdb.base/nofield.exp * gdb.base/offsets.exp * gdb.base/overlays.exp * gdb.base/pending.exp * gdb.base/pointers.exp * gdb.base/pr11022.exp * gdb.base/printcmds.exp * gdb.base/prologue.exp * gdb.base/ptr-typedef.exp * gdb.base/realname-expand.exp * gdb.base/relativedebug.exp * gdb.base/relocate.exp * gdb.base/remote.exp * gdb.base/reread.exp * gdb.base/return2.exp * gdb.base/savedregs.exp * gdb.base/sep.exp * gdb.base/sepdebug.exp * gdb.base/sepsymtab.exp * gdb.base/set-inferior-tty.exp * gdb.base/setshow.exp * gdb.base/shlib-call.exp * gdb.base/sigaltstack.exp * gdb.base/siginfo-addr.exp * gdb.base/signals.exp * gdb.base/signull.exp * gdb.base/sigrepeat.exp * gdb.base/so-impl-ld.exp * gdb.base/solib-display.exp * gdb.base/solib-overlap.exp * gdb.base/solib-search.exp * gdb.base/solib-symbol.exp * gdb.base/structs.exp * gdb.base/structs2.exp * gdb.base/symtab-search-order.exp * gdb.base/twice.exp * gdb.base/unload.exp * gdb.base/varargs.exp * gdb.base/watchpoint-solib.exp * gdb.base/watchpoint.exp * gdb.base/whatis.exp * gdb.base/wrong_frame_bt_full.exp * gdb.btrace/dlopen.exp * gdb.cell/ea-standalone.exp * gdb.cell/ea-test.exp * gdb.cp/dispcxx.exp * gdb.cp/gdb2384.exp * gdb.cp/method2.exp * gdb.cp/nextoverthrow.exp * gdb.cp/pr10728.exp * gdb.disasm/am33.exp * gdb.disasm/h8300s.exp * gdb.disasm/mn10300.exp * gdb.disasm/sh3.exp * gdb.dwarf2/dw2-dir-file-name.exp * gdb.fortran/complex.exp * gdb.fortran/library-module.exp * gdb.guile/scm-pretty-print.exp * gdb.guile/scm-symbol.exp * gdb.guile/scm-type.exp * gdb.guile/scm-value.exp * gdb.linespec/linespec.exp * gdb.mi/gdb701.exp * gdb.mi/gdb792.exp * gdb.mi/mi-breakpoint-changed.exp * gdb.mi/mi-dprintf-pending.exp * gdb.mi/mi-dprintf.exp * gdb.mi/mi-exit-code.exp * gdb.mi/mi-pending.exp * gdb.mi/mi-solib.exp * gdb.mi/new-ui-mi-sync.exp * gdb.mi/pr11022.exp * gdb.mi/user-selected-context-sync.exp * gdb.opt/solib-intra-step.exp * gdb.python/py-events.exp * gdb.python/py-finish-breakpoint.exp * gdb.python/py-mi.exp * gdb.python/py-prettyprint.exp * gdb.python/py-shared.exp * gdb.python/py-symbol.exp * gdb.python/py-template.exp * gdb.python/py-type.exp * gdb.python/py-value.exp * gdb.reverse/solib-precsave.exp * gdb.reverse/solib-reverse.exp * gdb.server/solib-list.exp * gdb.stabs/weird.exp * gdb.threads/reconnect-signal.exp * gdb.threads/stepi-random-signal.exp * gdb.trace/actions.exp * gdb.trace/ax.exp * gdb.trace/backtrace.exp * gdb.trace/change-loc.exp * gdb.trace/deltrace.exp * gdb.trace/ftrace-lock.exp * gdb.trace/ftrace.exp * gdb.trace/infotrace.exp * gdb.trace/mi-tracepoint-changed.exp * gdb.trace/packetlen.exp * gdb.trace/passcount.exp * gdb.trace/pending.exp * gdb.trace/range-stepping.exp * gdb.trace/report.exp * gdb.trace/stap-trace.exp * gdb.trace/tfind.exp * gdb.trace/trace-break.exp * gdb.trace/trace-condition.exp * gdb.trace/trace-enable-disable.exp * gdb.trace/trace-mt.exp * gdb.trace/tracecmd.exp * gdb.trace/tspeed.exp * gdb.trace/tsv.exp * lib/perftest.exp
2016-12-01 21:47:50 +01:00
untested "failed to compile"
Fix PR20494 - User input stops being echoed in CLI This patch fixes a problem that problem triggers if you start an inferior, e.g., with the "start" command, in a UI created with the new-ui command, and then run a foreground execution command in the main UI. Once the program stops for the latter command, typing in the main UI no longer echoes back to the user. The problem revolves around this: - gdb_has_a_terminal computes its result lazily, on first call. that is what saves gdb's initial main UI terminal state (the UI associated with stdin): our_terminal_info.ttystate = serial_get_tty_state (stdin_serial); This is the state that target_terminal_ours() restores. - In this scenario, the gdb_has_a_terminal function happens to be first ever called from within the target_terminal_init call in startup_inferior: (top-gdb) bt #0 gdb_has_a_terminal () at src/gdb/inflow.c:157 #1 0x000000000079db22 in child_terminal_init_with_pgrp () at src/gdb/inflow.c:217 [...] #4 0x000000000065bacb in target_terminal_init () at src/gdb/target.c:456 #5 0x00000000004676d2 in startup_inferior () at src/gdb/fork-child.c:531 [...] #7 0x000000000046b168 in linux_nat_create_inferior () at src/gdb/linux-nat.c:1112 [...] #9 0x00000000005f20c9 in start_command (args=0x0, from_tty=1) at src/gdb/infcmd.c:657 If the command to start the inferior is issued on the main UI, then readline will have deprepped the terminal when we reach the above, and the problem doesn't appear. If however the command is issued on a non-main UI, then when we reach that gdb_has_a_terminal call, the main UI's terminal state is still set to whatever readline has sets it to in rl_prep_terminal, which happens to have echo disabled. Later, when the following synchronous execution command finishes, we'll call target_terminal_ours to restore gdb's the main UI's terminal settings, and that restores the terminal state with echo disabled... Conceptually, the fix is to move the gdb_has_a_terminal call earlier, to someplace during GDB initialization, before readline/ncurses have had a chance to change terminal settings. Turns out that "set_initial_gdb_ttystate" is exactly such a place. I say conceptually, because the fix actually inlines the gdb_has_a_terminal part that saves the terminal state in set_initial_gdb_ttystate and then simplifies gdb_has_a_terminal, since there's no point in making gdb_has_a_terminal do lazy computation. gdb/ChangeLog: 2016-08-23 Pedro Alves <palves@redhat.com> PR gdb/20494 * inflow.c (our_terminal_info, initial_gdb_ttystate): Update comments. (enum gdb_has_a_terminal_flag_enum, gdb_has_a_terminal_flag): Delete. (set_initial_gdb_ttystate): Record our_terminal_info here too, instead of ... (gdb_has_a_terminal): ... here. Reimplement in terms of initial_gdb_ttystate. Make static. * terminal.h (gdb_has_a_terminal): Delete declaration. (set_initial_gdb_ttystate): Add comment. * top.c (show_interactive_mode): Use input_interactive_p instead of gdb_has_a_terminal. gdb/testsuite/ChangeLog: 2016-08-23 Pedro Alves <palves@redhat.com> PR gdb/20494 * gdb.base/new-ui-echo.c: New file. * gdb.base/new-ui-echo.exp: New file.
2016-08-23 17:03:28 +02:00
return -1
}
# Start gdb and create an extra console UI. Start the inferior in the
# DRIVER console (either "main" or "extra"), and then enter a
# synchronous execution command in the extra console. Before PR 20494
# was fixed, if DRIVER was a secondary UI, GDB would lose input echo
# on the main UI after the synchronous execution command. We test
# with both main and extra UIs as driver consoles for completeness.
proc echo_test {driver} {
global srcfile testfile
global gdb_prompt
global gdb_spawn_id
global gdb_main_spawn_id extra_spawn_id
global decimal
clean_restart $testfile
# Save the main UI's spawn ID.
set gdb_main_spawn_id $gdb_spawn_id
# Create the new PTY for the secondary console UI.
spawn -pty
set extra_spawn_id $spawn_id
set extra_tty_name $spawn_out(slave,name)
gdb_test_multiple "new-ui console $extra_tty_name" "new-ui" {
-re "New UI allocated\r\n$gdb_prompt $" {
}
}
with_spawn_id $extra_spawn_id {
set test "initial prompt on extra console"
gdb_test_multiple "" $test {
-re "$gdb_prompt $" {
pass $test
}
}
}
set main_console [list $gdb_main_spawn_id "main console"]
set extra_console [list $extra_spawn_id "extra console"]
if {$driver == "main"} {
set con1 $main_console
set con2 $extra_console
} else {
set con1 $extra_console
set con2 $main_console
}
set con1_spawn_id [lindex $con1 0]
set con2_spawn_id [lindex $con2 0]
set con1_name [lindex $con1 1]
set con2_name [lindex $con2 1]
set bp_lineno [gdb_get_line_number "set break $con1_name here"]
with_spawn_id $con1_spawn_id {
gdb_test "break $srcfile:$bp_lineno" \
"Breakpoint $decimal .*$srcfile, line $bp_lineno\\." \
"set breakpoint using $con1_name"
gdb_run_cmd
gdb_test "" "set break $con1_name here .*" "run to breakpoint on $con1_name"
}
with_spawn_id $con2_spawn_id {
set test "breakpoint hit reported on $con2_name too"
gdb_test_multiple "" $test {
-re "Breakpoint $decimal, .* set break $con1_name here " {
pass $test
}
}
gdb_test "next" "global = 1;" "next on $con2_name"
}
# Ensure echo remains enabled in both consoles.
with_spawn_id $con1_spawn_id {
gdb_test "print 1" "^print 1\r\n\\\$1 = 1" "print on $con1_name echoes"
}
with_spawn_id $con2_spawn_id {
gdb_test "print 2" "^print 2\r\n\\\$2 = 2" "print on $con2_name echoes"
}
}
# The test driver.
proc test_driver {} {
with_test_prefix "extra console as driver" {
echo_test "extra"
}
with_test_prefix "main console as driver" {
echo_test "main"
}
}
test_driver