]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.base/ending-run.exp
Copyright updates for 2007.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / ending-run.exp
CommitLineData
1bf404ef
AC
1# This testcase is part of GDB, the GNU debugger.
2
6aba47ca
DJ
3# Copyright 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2007
4# Free Software Foundation, Inc.
c906108c
SS
5
6# This program is free software; you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation; either version 2 of the License, or
9# (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program; if not, write to the Free Software
1bf404ef 18# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
c906108c
SS
19
20# use this to debug:
21#
22#log_user 1
23
24# ending-run.exp -- Expect script to test ending a test run in gdb
25
26if $tracelevel then {
27 strace $tracelevel
28}
29
30set testfile ending-run
31set srcfile ${testfile}.c
32set binfile ${objdir}/${subdir}/${testfile}
33
34remote_exec build "rm -f ${binfile}"
35remote_exec build "rm -f core"
36
37
38if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
b60f0898
JB
39 untested ending-run.exp
40 return -1
c906108c
SS
41}
42
43
44
45gdb_exit
46gdb_start
47gdb_reinitialize_dir $srcdir/$subdir
48gdb_load ${binfile}
49
50# CHFts23469: Test that you can "clear" a bp set at
51# a line _before_ the routine (which will default to the
52# first line in the routine, which turns out to correspond
53# to the prolog--that's another bug...)
54#
b84b7669
MS
55
56gdb_test "b ending-run.c:1" ".*Breakpoint.*ending-run.c, line 1.*" \
57 "bpt at line before routine"
58
59gdb_test "b ending-run.c:13" \
7dbd117d
MC
60 ".*Note.*also.*Breakpoint 2.*ending-run.c, line 13.*" \
61 "b ending-run.c:13, one"
c906108c
SS
62
63# Set up to go to the next-to-last line of the program
64#
b84b7669 65gdb_test "b ending-run.c:31" ".*Breakpoint 3.*ending-run.c, line 31.*"
c906108c
SS
66
67# Expect to hit the bp at line "1", but symbolize this
085dd6e6 68# as line "13". Then try to clear it--this should work.
c906108c 69#
7a292a7a 70if [target_info exists use_gdb_stub] {
a0b3c4fd 71 gdb_test "continue" ".*Breakpoint.*1.*callee.*13.*"
7a292a7a 72} else {
a0b3c4fd 73 gdb_test "r" ".*Breakpoint.*1.*callee.*13.*"
7a292a7a 74}
c906108c
SS
75gdb_test "cle" ".*Deleted breakpoints 2 1.*" "clear worked"
76send_gdb "i b\n"
77gdb_expect {
ed4c619a 78 -re ".* breakpoint .* breakpoint .*$gdb_prompt $" {
cb9a9d3e
MS
79 fail "cleared bp at line before routine"
80 }
81 -re ".*3.*main.*31.*$gdb_prompt $" {
82 pass "cleared bp at line before routine"
83 }
84 -re ".*$gdb_prompt $" {
85 fail "cleared bp at line before routine (info b)"
86 }
c906108c
SS
87}
88
89# Test some other "clear" combinations
90#
b84b7669 91gdb_test "b ending-run.c:1" ".*Breakpoint.*4.*"
7dbd117d 92gdb_test "b ending-run.c:13" ".*Note.*also.*Breakpoint.*5.*" "b ending-run.c:13, two"
b84b7669
MS
93gdb_test "cle ending-run.c:13" \
94 ".*Deleted breakpoint 5.*" "Only cleared 1 by line"
c906108c 95
b84b7669 96send_gdb "inf line ending-run.c:13\n"
c906108c
SS
97gdb_expect {
98 -re ".*address (0x\[0-9a-fA-F]*).*$gdb_prompt $" {
99 set line_eight $expect_out(1,string)
a0b3c4fd 100 gdb_test "b 13" ".*Breakpoint.*6.*"
c906108c
SS
101 gdb_test "cle *$line_eight" ".*Deleted breakpoints 6 4.*" "Clear 2 by address"
102 }
103 -re ".*$gdb_prompt $" {
104 fail "need to fix test for new compile outcome"
105 }
106}
107
b84b7669 108send_gdb "inf line ending-run.c:14\n"
c906108c
SS
109gdb_expect {
110 -re ".*address (0x\[0-9a-fA-F]*).*$gdb_prompt $" {
111 set line_nine $expect_out(1,string)
b84b7669 112 gdb_test "b ending-run.c:14" ".*Breakpoint 7.*ending-run.c, line 14.*"
1bf404ef 113 gdb_test "b *$line_nine" ".*Note.*also.*Breakpoint 8.*" "Breakpoint 7 at *ending-run.c:14"
a0b3c4fd 114 gdb_test "c" ".*Breakpoint.*7.*callee.*14.*"
c906108c
SS
115 gdb_test "cle" ".*Deleted breakpoints 8 7.*" "Clear 2 by default"
116 }
117 -re ".*$gdb_prompt $" {
118 fail "need to fix test for new compile outcome"
119 }
120}
121
122send_gdb "i b\n"
123gdb_expect {
ed4c619a 124 -re ".* breakpoint .* breakpoint .*$gdb_prompt $" {
cb9a9d3e 125 fail "all set to continue (didn't clear bps)"
c906108c 126 }
085dd6e6 127 -re ".*3.*main.*31.*$gdb_prompt $" {
c906108c
SS
128 pass "all set to continue"
129 }
130 -re ".*$gdb_prompt $" {
cb9a9d3e 131 fail "all set to continue (missing bp at end)"
c906108c
SS
132 }
133}
134
135
136# See if we can step out with control. The "1 2 3" stuff
137# is output from the program.
138#
004af6c7
DJ
139if ![gdb_skip_stdio_test "cont"] {
140 gdb_test "cont" ".*1 2 7 14 23 34 47 62 79.*Breakpoint.*31.*"
141} else {
142 gdb_test "cont" ".*Breakpoint.*31.*"
143}
13a5e3b8
MS
144
145if ![gdb_skip_stdio_test "Step to return"] {
808a31f5 146 gdb_test "next" ".*Goodbye!.*32.*" \
13a5e3b8
MS
147 "Step to return"
148} else {
149 gdb_test "next" "" ""
150}
c906108c
SS
151
152set old_timeout $timeout
153set timeout 50
2b1a1355 154set program_exited 0
c906108c 155send_gdb "next\n"
697bc68d 156set nexted 0
c906108c 157gdb_expect {
085dd6e6 158 -re "33.*$gdb_prompt $" {
c906108c 159 # sometimes we stop at the closing brace, if so, do another next
697bc68d
NS
160 if { $nexted } {
161 fail "step out of main"
162 } else {
163 set nexted 1
164 send_gdb "next\n"
165 exp_continue
c906108c
SS
166 }
167 }
168 -re ".*Unable to find return pc for this frame.*$gdb_prompt $" {
697bc68d
NS
169 fail "step out of main"
170 gdb_test "n" ".*" ""
c906108c
SS
171 }
172 -re ".*in.*start.*$gdb_prompt $" {
697bc68d
NS
173 pass "step out of main"
174 }
175 -re ".*in.*bsp_trap.*$gdb_prompt $" {
176 pass "step out of main"
c906108c 177 }
697bc68d
NS
178 -re ".*in.*init.*$gdb_prompt $" {
179 # This is what happens on sparc64-elf ultra.
180 pass "step out of main"
181 }
182 -re ".*in.*dll_crt0_1.*$gdb_prompt $" {
183 # This is what happens on Cygwin.
184 pass "step out of main"
085dd6e6 185 }
2b1a1355
MS
186 -re ".*Program exited normally.*$gdb_prompt $" {
187 # This is what happens on Linux i86 (and I would expect others)
188 set program_exited 1
189 pass "step out of main"
190 }
697bc68d
NS
191 -re ".*in .nope ().*$gdb_prompt $" {
192 # This is what happens on Solaris currently -sts 1999-08-25
193 pass "step out of main"
194 }
195 -re ".*in _int_reset ().*$gdb_prompt $" {
196 # This is what happens on Sanyo XStormy16
197 pass "step out of main"
198 }
199 -re ".*init ().*$gdb_prompt $" {
200 # This is what happens on many Mips targets
201 pass "step out of main"
202 }
203 -re ".*in ..change.mode ().*$gdb_prompt $" {
204 # This is what happens on ARM in thumb mode -fn 2000-02-01
205 pass "step out of main"
206 }
207 -re ".*__rt_entry ().*$gdb_prompt $" {
208 # This is what happens on the ARM RVDS runtime
209 pass "step out of main"
210 }
211 -re ".*in.*\\\$START\\\$.*from.*dld.sl.*$gdb_prompt $" {
212 pass "step out of main"
213 }
214 -re ".*in __wrap__?main ().*$gdb_prompt $" {
215 pass "step out of main"
216 }
217 -re "__setup_argv_for_main (.*).*$gdb_prompt $" {
218 # On sh, another wrapper function (start_l) exists, so
219 # another `next' is necessary.
220 gdb_test "next" ".*in start_l ().*" "step out of main"
221 }
cce74817 222 -re ".*in.*currently asm.*$gdb_prompt $" {
697bc68d
NS
223 pass "step out of main"
224 }
225 -re "_*start\[0-9\]* \\(\[^)\]*\\).*$gdb_prompt $" {
226 pass "step out of main"
cce74817
JM
227 }
228 -re ".*Program received signal SIGTRAP.*$gdb_prompt $" {
697bc68d 229 pass "step out of main"
cce74817 230 }
697bc68d
NS
231 -re ".*$gdb_prompt $" { fail "step out of main" }
232 timeout { fail "step out of main" }
c906108c
SS
233}
234
0f815cdf
JB
235# When we're talking to a program running on a real stand-alone board,
236# every BSP's exit function behaves differently, so there's no single
237# way to tell whether we've exited gracefully or not. So don't run
238# these tests when use_gdb_stub is set, or when we're running under Cygmon.
31e45dee
FN
239set program_exited_normally 0
240set program_not_exited 0
241set program_in_exit 0
0f815cdf
JB
242if {! [target_info exists use_gdb_stub]
243 && (! [target_info exists use_cygmon] || ! [target_info use_cygmon])} {
2b1a1355
MS
244 global program_exited;
245 if {[eval expr $program_exited == 0]} {
246 send_gdb "n\n"
247 gdb_expect {
248 -re "Program exited normally.*$gdb_prompt $" {
249 # If we actually have debug info for the start function,
250 # then we won't get the "Single-stepping until function
251 # exit" message.
36a22261 252 pass "step to end of run"
31e45dee 253 set program_exited_normally 1
2b1a1355 254 }
a283c5a1 255 -re "Single.*EXIT code 0\r\n.*Program exited normally.*$gdb_prompt $" {
cb9a9d3e 256 pass "step to end of run (status wrapper)"
31e45dee 257 set program_exited_normally 1
cb9a9d3e 258 }
afb5c968
CV
259 -re "Single.*EXIT code 0\r\n.*$gdb_prompt $" {
260 pass "step to end of run (status wrapper)"
261 }
2b1a1355 262 -re ".*Single.*Program exited.*$gdb_prompt $" {
36a22261 263 pass "step to end of run"
31e45dee 264 set program_exited_normally 1
2b1a1355
MS
265 }
266 -re ".*Single.*in exit.*from.*dld.sl.*$gdb_prompt $" {
36a22261 267 pass "step to end of run"
31e45dee 268 set program_in_exit 1
2b1a1355 269 }
36a22261
CV
270 -re ".*Single.*_int_reset.*$gdb_prompt $" {
271 pass "step to end of run"
31e45dee
FN
272 if {![istarget "xstormy16-*-*"]} {
273 set program_exited_normally 1
274 }
36a22261 275 }
2b1a1355
MS
276 -re ".*$gdb_prompt $" {
277 fail "step to end of run"
31e45dee 278 set program_not_exited 1
2b1a1355
MS
279 }
280 timeout {
281 fail "(timeout) step to end of run"
31e45dee 282 set program_not_exited 1
2b1a1355
MS
283 }
284 }
285 }
286
31e45dee
FN
287 if {$program_in_exit} {
288 if {[gdb_test "c" ".*" "continue after exit"] == 0} {
289 set program_exited_normally 1
290 }
291 } else {
292 unsupported "continue after exit"
293 }
294
2b1a1355
MS
295 set timeout $old_timeout
296
31e45dee
FN
297 if {$program_exited_normally} {
298 gdb_test "n" ".*The program is not being run.*" "don't step after run"
299 } elseif {$program_not_exited} {
300 unresolved "don't step after run"
301 } else {
302 unsupported "don't step after run"
303 }
2b1a1355
MS
304
305 set exec_output [remote_exec host "ls core"]
306
307 if [ regexp "core not found" $exec_output] {
308 pass "No core dumped on quit"
7a292a7a 309 } else {
2b1a1355 310 if [ regexp "No such file or directory" $exec_output] {
cb9a9d3e 311 pass "ls: core (No core dumped on quit)"
2b1a1355
MS
312 } else {
313 remote_exec build "rm -f core"
cb9a9d3e 314 fail "ls: core (Core dumped on quit)"
2b1a1355 315 }
7a292a7a 316 }
c906108c
SS
317}
318
319#remote_exec build "rm -f ${binfile}"
320return 0
321
322
323
324