1 # Copyright 2014-2019 Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 # Test "set auto-connect-native-target off" and "target native" on
21 if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} {
25 # Whether this GDB is configured with a "native" target.
28 set test "help target native"
29 gdb_test_multiple $test $test {
30 -re "Undefined target command.*$gdb_prompt $" {
33 -re "Native process.*$gdb_prompt $" {
38 if { !$have_native } {
39 unsupported "no \"target native\" support."
43 # Returns the topmost target pushed on the target stack. TEST is used
46 proc get_topmost_target {test} {
51 gdb_test_multiple "maint print target-stack" $test {
52 -re "The current target stack is:\r\n - (\[^ \]+) .*$gdb_prompt $" {
53 set topmost $expect_out(1,string)
61 set topmost [get_topmost_target "check whether a target is already connected"]
63 # Testing against the extended-remote board, for example?
64 if { $topmost != "exec" } {
65 unsupported "already connected to target $topmost."
69 # Check which target this board connects to. If testing with a native
70 # target board, this should cause the native target to auto connect.
71 if ![runto_main] then {
72 fail "can't run to main"
76 # Returns true if the native target is pushed on the target stack.
77 # TEST is used as test message.
79 proc check_native_target {test} {
82 gdb_test_multiple "maint print target-stack" $test {
83 -re " native .*$gdb_prompt $" {
95 # Testing against a remote board, for example?
96 if { ![check_native_target "check whether board tests the native target"] } {
97 unsupported "not testing the native target."
101 # Kill program. TEST is used as test message.
103 proc kill_program {test} {
106 gdb_test_multiple "kill" $test {
107 -re "Kill the program being debugged\\? .y or n. $" {
111 -re "$gdb_prompt $" {
117 # Kill the program. This should pop the target. The "start" test
118 # below will fail otherwise.
121 # Now prevent the native target from auto connecting.
122 gdb_test_no_output "set auto-connect-native-target off"
124 # Commands that rely on the native target auto-connecting should no longer work.
125 gdb_test "start" "Don't know how to run.*" "start no longer works"
127 # Explicitly connect to the native target.
128 gdb_test "target native" \
129 "Done. Use the \"run\" command to start a process.*" \
130 "explicitly connect to the native target"
132 proc test_native_target_remains_pushed {} {
133 gdb_test "maint print target-stack" \
134 "The current target stack is:\r\n .* native .* exec .*" \
135 "native target remains pushed"
138 # Test a set of "inferior gone" scenarios, making sure the target
141 with_test_prefix "kill" {
142 gdb_test "start" "main.*" "start"
146 test_native_target_remains_pushed
149 with_test_prefix "detach" {
150 gdb_test "start" "main.*"
153 gdb_test_multiple $test $test {
154 -re "Detach the program being debugged\\? .y or n. $" {
158 -re "$gdb_prompt $" {
163 test_native_target_remains_pushed
166 with_test_prefix "run to exit" {
167 gdb_test "start" "Temporary breakpoint .* main .*"
169 gdb_test "c" "$inferior_exited_re normally.*"
171 test_native_target_remains_pushed
174 # Now test disconnecting. Commands that rely on the native target
175 # auto-connecting should no longer work (again) after this.
177 with_test_prefix "disconnect" {
178 gdb_test "start" "Temporary breakpoint .* main .*"
180 set test "disconnect"
181 gdb_test_multiple $test $test {
182 -re "A program is being debugged already.* .y or n. $" {
186 -re "$gdb_prompt $" {
192 [get_topmost_target "check whether the target is no longer connected"]
194 set test "no longer connected to a target"
195 if { $topmost == "exec" } {
201 gdb_test "start" "Don't know how to run.*" "start no longer works"
204 # Reenable auto-connecting to the native target. Plain "start" should
205 # start working again.
206 gdb_test_no_output "set auto-connect-native-target on"
208 gdb_test "start" "Temporary breakpoint .* main .*" \
209 "start auto-connects to the native target after reenabling auto-connect"