* gdb.base/dump.exp: Force the correct endianness for binary
[deliverable/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#
b741e217
DJ
70gdb_run_cmd
71gdb_test "" ".*Breakpoint.*1.*callee.*13.*" "run"
72
c906108c
SS
73gdb_test "cle" ".*Deleted breakpoints 2 1.*" "clear worked"
74send_gdb "i b\n"
75gdb_expect {
ed4c619a 76 -re ".* breakpoint .* breakpoint .*$gdb_prompt $" {
cb9a9d3e
MS
77 fail "cleared bp at line before routine"
78 }
79 -re ".*3.*main.*31.*$gdb_prompt $" {
80 pass "cleared bp at line before routine"
81 }
82 -re ".*$gdb_prompt $" {
83 fail "cleared bp at line before routine (info b)"
84 }
c906108c
SS
85}
86
87# Test some other "clear" combinations
88#
b84b7669 89gdb_test "b ending-run.c:1" ".*Breakpoint.*4.*"
7dbd117d 90gdb_test "b ending-run.c:13" ".*Note.*also.*Breakpoint.*5.*" "b ending-run.c:13, two"
b84b7669
MS
91gdb_test "cle ending-run.c:13" \
92 ".*Deleted breakpoint 5.*" "Only cleared 1 by line"
c906108c 93
b84b7669 94send_gdb "inf line ending-run.c:13\n"
c906108c
SS
95gdb_expect {
96 -re ".*address (0x\[0-9a-fA-F]*).*$gdb_prompt $" {
97 set line_eight $expect_out(1,string)
a0b3c4fd 98 gdb_test "b 13" ".*Breakpoint.*6.*"
c906108c
SS
99 gdb_test "cle *$line_eight" ".*Deleted breakpoints 6 4.*" "Clear 2 by address"
100 }
101 -re ".*$gdb_prompt $" {
102 fail "need to fix test for new compile outcome"
103 }
104}
105
b84b7669 106send_gdb "inf line ending-run.c:14\n"
c906108c
SS
107gdb_expect {
108 -re ".*address (0x\[0-9a-fA-F]*).*$gdb_prompt $" {
109 set line_nine $expect_out(1,string)
b84b7669 110 gdb_test "b ending-run.c:14" ".*Breakpoint 7.*ending-run.c, line 14.*"
1bf404ef 111 gdb_test "b *$line_nine" ".*Note.*also.*Breakpoint 8.*" "Breakpoint 7 at *ending-run.c:14"
a0b3c4fd 112 gdb_test "c" ".*Breakpoint.*7.*callee.*14.*"
c906108c
SS
113 gdb_test "cle" ".*Deleted breakpoints 8 7.*" "Clear 2 by default"
114 }
115 -re ".*$gdb_prompt $" {
116 fail "need to fix test for new compile outcome"
117 }
118}
119
120send_gdb "i b\n"
121gdb_expect {
ed4c619a 122 -re ".* breakpoint .* breakpoint .*$gdb_prompt $" {
cb9a9d3e 123 fail "all set to continue (didn't clear bps)"
c906108c 124 }
085dd6e6 125 -re ".*3.*main.*31.*$gdb_prompt $" {
c906108c
SS
126 pass "all set to continue"
127 }
128 -re ".*$gdb_prompt $" {
cb9a9d3e 129 fail "all set to continue (missing bp at end)"
c906108c
SS
130 }
131}
132
133
134# See if we can step out with control. The "1 2 3" stuff
135# is output from the program.
136#
004af6c7
DJ
137if ![gdb_skip_stdio_test "cont"] {
138 gdb_test "cont" ".*1 2 7 14 23 34 47 62 79.*Breakpoint.*31.*"
139} else {
140 gdb_test "cont" ".*Breakpoint.*31.*"
141}
13a5e3b8
MS
142
143if ![gdb_skip_stdio_test "Step to return"] {
808a31f5 144 gdb_test "next" ".*Goodbye!.*32.*" \
13a5e3b8
MS
145 "Step to return"
146} else {
147 gdb_test "next" "" ""
148}
c906108c
SS
149
150set old_timeout $timeout
151set timeout 50
2b1a1355 152set program_exited 0
c906108c 153send_gdb "next\n"
697bc68d 154set nexted 0
c906108c 155gdb_expect {
085dd6e6 156 -re "33.*$gdb_prompt $" {
c906108c 157 # sometimes we stop at the closing brace, if so, do another next
697bc68d
NS
158 if { $nexted } {
159 fail "step out of main"
160 } else {
161 set nexted 1
162 send_gdb "next\n"
163 exp_continue
c906108c
SS
164 }
165 }
166 -re ".*Unable to find return pc for this frame.*$gdb_prompt $" {
697bc68d
NS
167 fail "step out of main"
168 gdb_test "n" ".*" ""
c906108c
SS
169 }
170 -re ".*in.*start.*$gdb_prompt $" {
697bc68d
NS
171 pass "step out of main"
172 }
173 -re ".*in.*bsp_trap.*$gdb_prompt $" {
174 pass "step out of main"
c906108c 175 }
697bc68d
NS
176 -re ".*in.*init.*$gdb_prompt $" {
177 # This is what happens on sparc64-elf ultra.
178 pass "step out of main"
179 }
180 -re ".*in.*dll_crt0_1.*$gdb_prompt $" {
181 # This is what happens on Cygwin.
182 pass "step out of main"
085dd6e6 183 }
2b1a1355
MS
184 -re ".*Program exited normally.*$gdb_prompt $" {
185 # This is what happens on Linux i86 (and I would expect others)
186 set program_exited 1
187 pass "step out of main"
188 }
697bc68d
NS
189 -re ".*in .nope ().*$gdb_prompt $" {
190 # This is what happens on Solaris currently -sts 1999-08-25
191 pass "step out of main"
192 }
193 -re ".*in _int_reset ().*$gdb_prompt $" {
194 # This is what happens on Sanyo XStormy16
195 pass "step out of main"
196 }
197 -re ".*init ().*$gdb_prompt $" {
198 # This is what happens on many Mips targets
199 pass "step out of main"
200 }
201 -re ".*in ..change.mode ().*$gdb_prompt $" {
202 # This is what happens on ARM in thumb mode -fn 2000-02-01
203 pass "step out of main"
204 }
205 -re ".*__rt_entry ().*$gdb_prompt $" {
206 # This is what happens on the ARM RVDS runtime
207 pass "step out of main"
208 }
209 -re ".*in.*\\\$START\\\$.*from.*dld.sl.*$gdb_prompt $" {
210 pass "step out of main"
211 }
212 -re ".*in __wrap__?main ().*$gdb_prompt $" {
213 pass "step out of main"
214 }
215 -re "__setup_argv_for_main (.*).*$gdb_prompt $" {
216 # On sh, another wrapper function (start_l) exists, so
217 # another `next' is necessary.
218 gdb_test "next" ".*in start_l ().*" "step out of main"
219 }
cce74817 220 -re ".*in.*currently asm.*$gdb_prompt $" {
697bc68d
NS
221 pass "step out of main"
222 }
223 -re "_*start\[0-9\]* \\(\[^)\]*\\).*$gdb_prompt $" {
224 pass "step out of main"
cce74817
JM
225 }
226 -re ".*Program received signal SIGTRAP.*$gdb_prompt $" {
697bc68d 227 pass "step out of main"
cce74817 228 }
697bc68d
NS
229 -re ".*$gdb_prompt $" { fail "step out of main" }
230 timeout { fail "step out of main" }
c906108c
SS
231}
232
0f815cdf
JB
233# When we're talking to a program running on a real stand-alone board,
234# every BSP's exit function behaves differently, so there's no single
235# way to tell whether we've exited gracefully or not. So don't run
236# these tests when use_gdb_stub is set, or when we're running under Cygmon.
31e45dee
FN
237set program_exited_normally 0
238set program_not_exited 0
239set program_in_exit 0
0f815cdf
JB
240if {! [target_info exists use_gdb_stub]
241 && (! [target_info exists use_cygmon] || ! [target_info use_cygmon])} {
2b1a1355
MS
242 global program_exited;
243 if {[eval expr $program_exited == 0]} {
244 send_gdb "n\n"
245 gdb_expect {
246 -re "Program exited normally.*$gdb_prompt $" {
247 # If we actually have debug info for the start function,
248 # then we won't get the "Single-stepping until function
249 # exit" message.
36a22261 250 pass "step to end of run"
31e45dee 251 set program_exited_normally 1
2b1a1355 252 }
a283c5a1 253 -re "Single.*EXIT code 0\r\n.*Program exited normally.*$gdb_prompt $" {
cb9a9d3e 254 pass "step to end of run (status wrapper)"
31e45dee 255 set program_exited_normally 1
cb9a9d3e 256 }
afb5c968
CV
257 -re "Single.*EXIT code 0\r\n.*$gdb_prompt $" {
258 pass "step to end of run (status wrapper)"
259 }
2b1a1355 260 -re ".*Single.*Program exited.*$gdb_prompt $" {
36a22261 261 pass "step to end of run"
31e45dee 262 set program_exited_normally 1
2b1a1355
MS
263 }
264 -re ".*Single.*in exit.*from.*dld.sl.*$gdb_prompt $" {
36a22261 265 pass "step to end of run"
31e45dee 266 set program_in_exit 1
2b1a1355 267 }
36a22261
CV
268 -re ".*Single.*_int_reset.*$gdb_prompt $" {
269 pass "step to end of run"
31e45dee
FN
270 if {![istarget "xstormy16-*-*"]} {
271 set program_exited_normally 1
272 }
36a22261 273 }
2b1a1355
MS
274 -re ".*$gdb_prompt $" {
275 fail "step to end of run"
31e45dee 276 set program_not_exited 1
2b1a1355
MS
277 }
278 timeout {
279 fail "(timeout) step to end of run"
31e45dee 280 set program_not_exited 1
2b1a1355
MS
281 }
282 }
283 }
284
31e45dee
FN
285 if {$program_in_exit} {
286 if {[gdb_test "c" ".*" "continue after exit"] == 0} {
287 set program_exited_normally 1
288 }
289 } else {
290 unsupported "continue after exit"
291 }
292
2b1a1355
MS
293 set timeout $old_timeout
294
31e45dee
FN
295 if {$program_exited_normally} {
296 gdb_test "n" ".*The program is not being run.*" "don't step after run"
297 } elseif {$program_not_exited} {
298 unresolved "don't step after run"
299 } else {
300 unsupported "don't step after run"
301 }
2b1a1355
MS
302
303 set exec_output [remote_exec host "ls core"]
304
305 if [ regexp "core not found" $exec_output] {
306 pass "No core dumped on quit"
7a292a7a 307 } else {
2b1a1355 308 if [ regexp "No such file or directory" $exec_output] {
cb9a9d3e 309 pass "ls: core (No core dumped on quit)"
2b1a1355
MS
310 } else {
311 remote_exec build "rm -f core"
cb9a9d3e 312 fail "ls: core (Core dumped on quit)"
2b1a1355 313 }
7a292a7a 314 }
c906108c
SS
315}
316
317#remote_exec build "rm -f ${binfile}"
318return 0
319
320
321
322
This page took 0.733871 seconds and 4 git commands to generate.