blob: 504708cab81b53526b12ad763f67d2fde00f3ad5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
|
# Copyright 2014-2016 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/>.
# Test "set auto-connect-native-target off" and "target native" on
# native targets.
standard_testfile
if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} {
return -1
}
# Whether this GDB is configured with a "native" target.
set have_native 0
set test "help target native"
gdb_test_multiple $test $test {
-re "Undefined target command.*$gdb_prompt $" {
set have_native 0
}
-re "Native process.*$gdb_prompt $" {
set have_native 1
}
}
if { !$have_native } {
unsupported "no \"target native\" support."
return
}
# Returns the topmost target pushed on the target stack. TEST is used
# as test message.
proc get_topmost_target {test} {
global gdb_prompt
set topmost "unknown"
gdb_test_multiple "maint print target-stack" $test {
-re "The current target stack is:\r\n - (\[^ \]+) .*$gdb_prompt $" {
set topmost $expect_out(1,string)
pass $test
}
}
return $topmost
}
set topmost [get_topmost_target "check whether a target is already connected"]
# Testing against the extended-remote board, for example?
if { $topmost != "exec" } {
unsupported "already connected to target $topmost."
return
}
# Check which target this board connects to. If testing with a native
# target board, this should cause the native target to auto connect.
if ![runto_main] then {
fail "can't run to main"
return 0
}
# Returns true if the native target is pushed on the target stack.
# TEST is used as test message.
proc check_native_target {test} {
global gdb_prompt
gdb_test_multiple "maint print target-stack" $test {
-re " native .*$gdb_prompt $" {
pass $test
return 1
}
-re "$gdb_prompt $" {
pass $test
}
}
return 0
}
# Testing against a remote board, for example?
if { ![check_native_target "check whether board tests the native target"] } {
unsupported "not testing the native target."
return
}
# Kill program. TEST is used as test message.
proc kill_program {test} {
global gdb_prompt
gdb_test_multiple "kill" $test {
-re "Kill the program being debugged\\? .y or n. $" {
send_gdb "y\n"
exp_continue
}
-re "$gdb_prompt $" {
pass $test
}
}
}
# Kill the program. This should pop the target. The "start" test
# below will fail otherwise.
kill_program "kill"
# Now prevent the native target from auto connecting.
gdb_test_no_output "set auto-connect-native-target off"
# Commands that rely on the native target auto-connecting should no longer work.
gdb_test "start" "Don't know how to run.*" "start no longer works"
# Explicitly connect to the native target.
gdb_test "target native" \
"Done. Use the \"run\" command to start a process.*" \
"explicitly connect to the native target"
proc test_native_target_remains_pushed {} {
gdb_test "maint print target-stack" \
"The current target stack is:\r\n .* native .* exec .*" \
"native target remains pushed"
}
# Test a set of "inferior gone" scenarios, making sure the target
# remains pushed.
with_test_prefix "kill" {
gdb_test "start" "main.*" "start"
kill_program "kill"
test_native_target_remains_pushed
}
with_test_prefix "detach" {
gdb_test "start" "main.*"
set test "detach"
gdb_test_multiple $test $test {
-re "Detach the program being debugged\\? .y or n. $" {
send_gdb "y\n"
exp_continue
}
-re "$gdb_prompt $" {
pass $test
}
}
test_native_target_remains_pushed
}
with_test_prefix "run to exit" {
gdb_test "start" "Temporary breakpoint .* main .*"
gdb_test "c" "$inferior_exited_re normally.*"
test_native_target_remains_pushed
}
# Now test disconnecting. Commands that rely on the native target
# auto-connecting should no longer work (again) after this.
with_test_prefix "disconnect" {
gdb_test "start" "Temporary breakpoint .* main .*"
set test "disconnect"
gdb_test_multiple $test $test {
-re "A program is being debugged already.* .y or n. $" {
send_gdb "y\n"
exp_continue
}
-re "$gdb_prompt $" {
pass $test
}
}
set topmost \
[get_topmost_target "check whether the target is no longer connected"]
set test "no longer connected to a target"
if { $topmost == "exec" } {
pass $test
} else {
fail $test
}
gdb_test "start" "Don't know how to run.*" "start no longer works"
}
# Reenable auto-connecting to the native target. Plain "start" should
# start working again.
gdb_test_no_output "set auto-connect-native-target on"
gdb_test "start" "Temporary breakpoint .* main .*" \
"start auto-connects to the native target after reenabling auto-connect"
|