]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/ending-run.exp
Copyright updates for 2007.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / ending-run.exp
1 # This testcase is part of GDB, the GNU debugger.
2
3 # Copyright 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2007
4 # Free Software Foundation, Inc.
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
18 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
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
26 if $tracelevel then {
27 strace $tracelevel
28 }
29
30 set testfile ending-run
31 set srcfile ${testfile}.c
32 set binfile ${objdir}/${subdir}/${testfile}
33
34 remote_exec build "rm -f ${binfile}"
35 remote_exec build "rm -f core"
36
37
38 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
39 untested ending-run.exp
40 return -1
41 }
42
43
44
45 gdb_exit
46 gdb_start
47 gdb_reinitialize_dir $srcdir/$subdir
48 gdb_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 #
55
56 gdb_test "b ending-run.c:1" ".*Breakpoint.*ending-run.c, line 1.*" \
57 "bpt at line before routine"
58
59 gdb_test "b ending-run.c:13" \
60 ".*Note.*also.*Breakpoint 2.*ending-run.c, line 13.*" \
61 "b ending-run.c:13, one"
62
63 # Set up to go to the next-to-last line of the program
64 #
65 gdb_test "b ending-run.c:31" ".*Breakpoint 3.*ending-run.c, line 31.*"
66
67 # Expect to hit the bp at line "1", but symbolize this
68 # as line "13". Then try to clear it--this should work.
69 #
70 if [target_info exists use_gdb_stub] {
71 gdb_test "continue" ".*Breakpoint.*1.*callee.*13.*"
72 } else {
73 gdb_test "r" ".*Breakpoint.*1.*callee.*13.*"
74 }
75 gdb_test "cle" ".*Deleted breakpoints 2 1.*" "clear worked"
76 send_gdb "i b\n"
77 gdb_expect {
78 -re ".* breakpoint .* breakpoint .*$gdb_prompt $" {
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 }
87 }
88
89 # Test some other "clear" combinations
90 #
91 gdb_test "b ending-run.c:1" ".*Breakpoint.*4.*"
92 gdb_test "b ending-run.c:13" ".*Note.*also.*Breakpoint.*5.*" "b ending-run.c:13, two"
93 gdb_test "cle ending-run.c:13" \
94 ".*Deleted breakpoint 5.*" "Only cleared 1 by line"
95
96 send_gdb "inf line ending-run.c:13\n"
97 gdb_expect {
98 -re ".*address (0x\[0-9a-fA-F]*).*$gdb_prompt $" {
99 set line_eight $expect_out(1,string)
100 gdb_test "b 13" ".*Breakpoint.*6.*"
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
108 send_gdb "inf line ending-run.c:14\n"
109 gdb_expect {
110 -re ".*address (0x\[0-9a-fA-F]*).*$gdb_prompt $" {
111 set line_nine $expect_out(1,string)
112 gdb_test "b ending-run.c:14" ".*Breakpoint 7.*ending-run.c, line 14.*"
113 gdb_test "b *$line_nine" ".*Note.*also.*Breakpoint 8.*" "Breakpoint 7 at *ending-run.c:14"
114 gdb_test "c" ".*Breakpoint.*7.*callee.*14.*"
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
122 send_gdb "i b\n"
123 gdb_expect {
124 -re ".* breakpoint .* breakpoint .*$gdb_prompt $" {
125 fail "all set to continue (didn't clear bps)"
126 }
127 -re ".*3.*main.*31.*$gdb_prompt $" {
128 pass "all set to continue"
129 }
130 -re ".*$gdb_prompt $" {
131 fail "all set to continue (missing bp at end)"
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 #
139 if ![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 }
144
145 if ![gdb_skip_stdio_test "Step to return"] {
146 gdb_test "next" ".*Goodbye!.*32.*" \
147 "Step to return"
148 } else {
149 gdb_test "next" "" ""
150 }
151
152 set old_timeout $timeout
153 set timeout 50
154 set program_exited 0
155 send_gdb "next\n"
156 set nexted 0
157 gdb_expect {
158 -re "33.*$gdb_prompt $" {
159 # sometimes we stop at the closing brace, if so, do another next
160 if { $nexted } {
161 fail "step out of main"
162 } else {
163 set nexted 1
164 send_gdb "next\n"
165 exp_continue
166 }
167 }
168 -re ".*Unable to find return pc for this frame.*$gdb_prompt $" {
169 fail "step out of main"
170 gdb_test "n" ".*" ""
171 }
172 -re ".*in.*start.*$gdb_prompt $" {
173 pass "step out of main"
174 }
175 -re ".*in.*bsp_trap.*$gdb_prompt $" {
176 pass "step out of main"
177 }
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"
185 }
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 }
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 }
222 -re ".*in.*currently asm.*$gdb_prompt $" {
223 pass "step out of main"
224 }
225 -re "_*start\[0-9\]* \\(\[^)\]*\\).*$gdb_prompt $" {
226 pass "step out of main"
227 }
228 -re ".*Program received signal SIGTRAP.*$gdb_prompt $" {
229 pass "step out of main"
230 }
231 -re ".*$gdb_prompt $" { fail "step out of main" }
232 timeout { fail "step out of main" }
233 }
234
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.
239 set program_exited_normally 0
240 set program_not_exited 0
241 set program_in_exit 0
242 if {! [target_info exists use_gdb_stub]
243 && (! [target_info exists use_cygmon] || ! [target_info use_cygmon])} {
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.
252 pass "step to end of run"
253 set program_exited_normally 1
254 }
255 -re "Single.*EXIT code 0\r\n.*Program exited normally.*$gdb_prompt $" {
256 pass "step to end of run (status wrapper)"
257 set program_exited_normally 1
258 }
259 -re "Single.*EXIT code 0\r\n.*$gdb_prompt $" {
260 pass "step to end of run (status wrapper)"
261 }
262 -re ".*Single.*Program exited.*$gdb_prompt $" {
263 pass "step to end of run"
264 set program_exited_normally 1
265 }
266 -re ".*Single.*in exit.*from.*dld.sl.*$gdb_prompt $" {
267 pass "step to end of run"
268 set program_in_exit 1
269 }
270 -re ".*Single.*_int_reset.*$gdb_prompt $" {
271 pass "step to end of run"
272 if {![istarget "xstormy16-*-*"]} {
273 set program_exited_normally 1
274 }
275 }
276 -re ".*$gdb_prompt $" {
277 fail "step to end of run"
278 set program_not_exited 1
279 }
280 timeout {
281 fail "(timeout) step to end of run"
282 set program_not_exited 1
283 }
284 }
285 }
286
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
295 set timeout $old_timeout
296
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 }
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"
309 } else {
310 if [ regexp "No such file or directory" $exec_output] {
311 pass "ls: core (No core dumped on quit)"
312 } else {
313 remote_exec build "rm -f core"
314 fail "ls: core (Core dumped on quit)"
315 }
316 }
317 }
318
319 #remote_exec build "rm -f ${binfile}"
320 return 0
321
322
323
324