2017-01-01 07:50:51 +01:00
|
|
|
# Copyright 2016-2017 Free Software Foundation, Inc.
|
2016-06-21 02:11:57 +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/>.
|
|
|
|
|
|
|
|
standard_testfile
|
|
|
|
|
|
|
|
set compile_options "debug"
|
|
|
|
if {[build_executable $testfile.exp $testfile ${srcfile} ${compile_options}] == -1} {
|
2016-12-01 21:47:50 +01:00
|
|
|
untested "failed to compile"
|
2016-06-21 02:11:57 +02:00
|
|
|
return -1
|
|
|
|
}
|
|
|
|
|
|
|
|
# Ensure no output has been sent. Use MESSAGE as test message.
|
|
|
|
|
|
|
|
proc ensure_no_output {message} {
|
|
|
|
global decimal
|
|
|
|
|
|
|
|
# Run a command and use an anchor to make sure no output appears
|
|
|
|
# before the command's expected output.
|
|
|
|
gdb_test "print 999" "^print 999\r\n\\\$$decimal = 999" $message
|
|
|
|
}
|
|
|
|
|
|
|
|
# Run a few execution-related commands on CON1, and ensure the proper
|
|
|
|
# output, or none, if appropriate, is sent to CON2. CON1_NAME and
|
|
|
|
# CON2_NAME are the names of the consoles.
|
|
|
|
|
|
|
|
proc do_execution_tests {con1 con1_name con2 con2_name} {
|
|
|
|
global srcfile
|
|
|
|
global decimal
|
|
|
|
|
|
|
|
set bp_lineno [gdb_get_line_number "set break $con1_name here"]
|
|
|
|
|
|
|
|
with_spawn_id $con1 {
|
|
|
|
gdb_test "next" "global = 1;"
|
|
|
|
}
|
|
|
|
with_spawn_id $con2 {
|
|
|
|
ensure_no_output "next causes no spurious output on other console"
|
|
|
|
}
|
|
|
|
|
|
|
|
with_spawn_id $con1 {
|
|
|
|
gdb_test "break $srcfile:$bp_lineno" \
|
|
|
|
"Breakpoint $decimal .*$srcfile, line $bp_lineno\\." \
|
|
|
|
"set breakpoint"
|
|
|
|
}
|
|
|
|
with_spawn_id $con2 {
|
|
|
|
ensure_no_output "break causes no spurious output on other console"
|
|
|
|
}
|
|
|
|
|
|
|
|
with_spawn_id $con1 {
|
|
|
|
gdb_test "continue" "set break $con1_name here .*" "continue to breakpoint"
|
|
|
|
}
|
|
|
|
|
|
|
|
with_spawn_id $con2 {
|
|
|
|
set test "breakpoint hit reported on other console"
|
|
|
|
gdb_test_multiple "" $test {
|
|
|
|
-re "Breakpoint $decimal, .* set break $con1_name here " {
|
|
|
|
pass $test
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# The test proper.
|
|
|
|
|
2017-02-10 22:29:45 +01:00
|
|
|
proc_with_prefix do_test {} {
|
2016-06-21 02:11:57 +02:00
|
|
|
global srcfile testfile
|
|
|
|
global gdb_prompt
|
|
|
|
global gdb_spawn_id
|
|
|
|
global gdb_main_spawn_id extra_spawn_id
|
|
|
|
|
|
|
|
clean_restart $testfile
|
|
|
|
|
|
|
|
if ![runto_main] {
|
|
|
|
untested "could not run to main"
|
|
|
|
return -1
|
|
|
|
}
|
|
|
|
|
|
|
|
gdb_test "new-ui" \
|
|
|
|
"usage: new-ui <interpreter> <tty>" \
|
|
|
|
"new-ui without arguments"
|
|
|
|
|
|
|
|
set test "new-ui does not repeat"
|
|
|
|
send_gdb "\n"
|
|
|
|
gdb_test_multiple "" $test {
|
|
|
|
-re "^\r\n$gdb_prompt $" {
|
|
|
|
pass $test
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# 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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Ensure non-execution commands in one console don't cause output
|
|
|
|
# in the other consoles.
|
|
|
|
with_spawn_id $gdb_main_spawn_id {
|
|
|
|
gdb_test "print 1" "^print 1\r\n\\\$1 = 1" "print on main console"
|
|
|
|
}
|
|
|
|
with_spawn_id $extra_spawn_id {
|
|
|
|
gdb_test "print 2" "^print 2\r\n\\\$2 = 2" "print on extra console"
|
|
|
|
}
|
|
|
|
|
Do not send queries on secondary UIs
This is a follow-up to
https://sourceware.org/ml/gdb-patches/2017-02/msg00261.html
This patch restricts queries to the main UI, which allows to avoid two
different problems.
The first one is that GDB is issuing queries on secondary MI channels
for which a TTY is allocated. The second one is that GDB is not able to
handle queries on two (CLI) UIs simultaneously. Restricting queries to
the main UI allows to bypass these two problems.
More details on how/why these two problems happen:
1. Queries on secondary MI UI
The current criterion to decide if we should query the user is whether
the input stream is a TTY. The original way to start GDB in MI mode
from a front-end was to create a subprocess with pipes to its
stdin/stdout. In this case, the input was considered non-interactive
and queries were auto-answered. Now that front-ends can create the MI
channel as a separate UI connected to a dedicated TTY, GDB now
considers this input stream as interactive and sends queries to it.
By restricting queries to the main UI, we make sure we never query on
the secondary MI UI.
2. Simultaneous queries
As Pedro stated it, when you have two queries on two different CLI UIs
at the same time, you end up with the following pseudo stack:
#0 gdb_readline_wrapper
#1 defaulted_query // for UI #2
#2 handle_command
#3 execute_command ("handle SIGTRAP" ....
#4 stdin_event_handler // input on UI #2
#5 gdb_do_one_event
#7 gdb_readline_wrapper
#8 defaulted_query // for UI #1
#9 handle_command
#10 execute_command ("handle SIGINT" ....
#11 stdin_event_handler // input on UI #1
#12 gdb_do_one_event
#13 gdb_readline_wrapper
trying to answer the query on UI #1 will therefore answer for UI #2.
By restricting the queries to the main UI, we ensure that there will
never be more than one pending query, since you can't have two queries
on a UI at the same time.
I added a snippet to gdb.base/new-ui.exp to verify that we get a query
on the main UI, but that we don't on the secondary one (or, more
precisely, that it gets auto-answered).
gdb/ChangeLog:
* utils.c (defaulted_query): Don't query on secondary UIs.
gdb/testsuite/ChangeLog:
* gdb.base/new-ui.exp (do_test): Test queries behavior on main
and extra UIs.
2017-02-10 22:29:50 +01:00
|
|
|
# Verify that we get proper queries on the main UI, but that they are
|
|
|
|
# auto-answered on secondary UIs.
|
|
|
|
with_spawn_id $gdb_main_spawn_id {
|
|
|
|
gdb_test "delete" "" "delete all breakpoint on main console" \
|
|
|
|
"Delete all breakpoints. .y or n. $" "n"
|
|
|
|
}
|
|
|
|
with_spawn_id $extra_spawn_id {
|
2017-10-25 00:22:56 +02:00
|
|
|
# Check output in two stages in order to override
|
|
|
|
# gdb_test_multiple's internal "got interactive prompt" fail
|
|
|
|
# that would otherwise match if the expect buffer happens to
|
|
|
|
# fill with partial output that ends in "(y or n) ".
|
|
|
|
set test "delete all breakpoints on extra console"
|
|
|
|
gdb_test_multiple "delete" $test {
|
|
|
|
-re "Delete all breakpoints. .y or n. " {
|
|
|
|
gdb_test "" \
|
|
|
|
".answered Y; input not from terminal." \
|
|
|
|
$test
|
|
|
|
}
|
|
|
|
}
|
Do not send queries on secondary UIs
This is a follow-up to
https://sourceware.org/ml/gdb-patches/2017-02/msg00261.html
This patch restricts queries to the main UI, which allows to avoid two
different problems.
The first one is that GDB is issuing queries on secondary MI channels
for which a TTY is allocated. The second one is that GDB is not able to
handle queries on two (CLI) UIs simultaneously. Restricting queries to
the main UI allows to bypass these two problems.
More details on how/why these two problems happen:
1. Queries on secondary MI UI
The current criterion to decide if we should query the user is whether
the input stream is a TTY. The original way to start GDB in MI mode
from a front-end was to create a subprocess with pipes to its
stdin/stdout. In this case, the input was considered non-interactive
and queries were auto-answered. Now that front-ends can create the MI
channel as a separate UI connected to a dedicated TTY, GDB now
considers this input stream as interactive and sends queries to it.
By restricting queries to the main UI, we make sure we never query on
the secondary MI UI.
2. Simultaneous queries
As Pedro stated it, when you have two queries on two different CLI UIs
at the same time, you end up with the following pseudo stack:
#0 gdb_readline_wrapper
#1 defaulted_query // for UI #2
#2 handle_command
#3 execute_command ("handle SIGTRAP" ....
#4 stdin_event_handler // input on UI #2
#5 gdb_do_one_event
#7 gdb_readline_wrapper
#8 defaulted_query // for UI #1
#9 handle_command
#10 execute_command ("handle SIGINT" ....
#11 stdin_event_handler // input on UI #1
#12 gdb_do_one_event
#13 gdb_readline_wrapper
trying to answer the query on UI #1 will therefore answer for UI #2.
By restricting the queries to the main UI, we ensure that there will
never be more than one pending query, since you can't have two queries
on a UI at the same time.
I added a snippet to gdb.base/new-ui.exp to verify that we get a query
on the main UI, but that we don't on the secondary one (or, more
precisely, that it gets auto-answered).
gdb/ChangeLog:
* utils.c (defaulted_query): Don't query on secondary UIs.
gdb/testsuite/ChangeLog:
* gdb.base/new-ui.exp (do_test): Test queries behavior on main
and extra UIs.
2017-02-10 22:29:50 +01:00
|
|
|
}
|
|
|
|
|
2016-06-21 02:11:57 +02:00
|
|
|
# Run a few execution tests with the main console as the driver
|
|
|
|
# console.
|
|
|
|
with_test_prefix "main console" {
|
|
|
|
do_execution_tests \
|
|
|
|
$gdb_main_spawn_id "main console" \
|
|
|
|
$extra_spawn_id "extra console"
|
|
|
|
}
|
|
|
|
# Same, but with the extra console as driver.
|
|
|
|
with_test_prefix "extra console" {
|
|
|
|
do_execution_tests \
|
|
|
|
$extra_spawn_id "extra console" \
|
|
|
|
$gdb_main_spawn_id "main console"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-25 17:01:54 +02:00
|
|
|
# Test missing / invalid arguments.
|
|
|
|
|
2017-02-10 22:29:45 +01:00
|
|
|
proc_with_prefix do_test_invalid_args {} {
|
2016-07-25 17:01:54 +02:00
|
|
|
global testfile
|
|
|
|
|
|
|
|
clean_restart $testfile
|
|
|
|
|
|
|
|
spawn -pty
|
|
|
|
set extra_tty_name $spawn_out(slave,name)
|
|
|
|
|
|
|
|
# Test bad terminal path.
|
|
|
|
gdb_test "new-ui console /non/existent/path" \
|
|
|
|
"opening terminal failed: No such file or directory\." \
|
|
|
|
"new-ui with bad terminal path"
|
|
|
|
|
|
|
|
# Test bad interpreter name.
|
|
|
|
gdb_test "new-ui bloop $extra_tty_name" \
|
|
|
|
"Interpreter `bloop' unrecognized" \
|
|
|
|
"new-ui with bad interpreter name"
|
|
|
|
|
|
|
|
# Test that we can continue working normally.
|
|
|
|
if ![runto_main] {
|
|
|
|
fail "could not run to main"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-10 22:29:45 +01:00
|
|
|
do_test
|
|
|
|
do_test_invalid_args
|