2001-05-19 Michael Chastain <chastain@redhat.com>
[binutils-gdb.git] / gdb / testsuite / gdb.base / ending-run.exp
1 # Copyright 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
2
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 2 of the License, or
6 # (at your option) any later version.
7 #
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.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
16
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gdb@prep.ai.mit.edu
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 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
40 }
41
42
43
44 gdb_exit
45 gdb_start
46 gdb_reinitialize_dir $srcdir/$subdir
47 gdb_load ${binfile}
48
49 # CHFts23469: Test that you can "clear" a bp set at
50 # a line _before_ the routine (which will default to the
51 # first line in the routine, which turns out to correspond
52 # to the prolog--that's another bug...)
53 #
54
55 gdb_test "b ending-run.c:1" ".*Breakpoint.*ending-run.c, line 1.*" \
56 "bpt at line before routine"
57
58 gdb_test "b ending-run.c:13" \
59 ".*Note.*also.*Breakpoint 2.*ending-run.c, line 13.*" \
60 "b ending-run.c:13, one"
61
62 # Set up to go to the next-to-last line of the program
63 #
64 gdb_test "b ending-run.c:31" ".*Breakpoint 3.*ending-run.c, line 31.*"
65
66 # Expect to hit the bp at line "1", but symbolize this
67 # as line "13". Then try to clear it--this should work.
68 #
69 if [target_info exists use_gdb_stub] {
70 gdb_test "continue" ".*Breakpoint.*1.*callee.*13.*"
71 } else {
72 gdb_test "r" ".*Breakpoint.*1.*callee.*13.*"
73 }
74 gdb_test "cle" ".*Deleted breakpoints 2 1.*" "clear worked"
75 send_gdb "i b\n"
76 gdb_expect {
77 -re ".*breakpoint.*breakpoint.*$gdb_prompt $" { fail "clear bp" }
78 -re ".*3.*main.*31.*$gdb_prompt $" { pass "cleared bp at line before routine" }
79 -re ".*$gdb_prompt $" { fail "info b" }
80 }
81
82 # Test some other "clear" combinations
83 #
84 gdb_test "b ending-run.c:1" ".*Breakpoint.*4.*"
85 gdb_test "b ending-run.c:13" ".*Note.*also.*Breakpoint.*5.*" "b ending-run.c:13, two"
86 gdb_test "cle ending-run.c:13" \
87 ".*Deleted breakpoint 5.*" "Only cleared 1 by line"
88
89 send_gdb "inf line ending-run.c:13\n"
90 gdb_expect {
91 -re ".*address (0x\[0-9a-fA-F]*).*$gdb_prompt $" {
92 set line_eight $expect_out(1,string)
93 gdb_test "b 13" ".*Breakpoint.*6.*"
94 gdb_test "cle *$line_eight" ".*Deleted breakpoints 6 4.*" "Clear 2 by address"
95 }
96 -re ".*$gdb_prompt $" {
97 fail "need to fix test for new compile outcome"
98 }
99 }
100
101 send_gdb "inf line ending-run.c:14\n"
102 gdb_expect {
103 -re ".*address (0x\[0-9a-fA-F]*).*$gdb_prompt $" {
104 set line_nine $expect_out(1,string)
105 gdb_test "b ending-run.c:14" ".*Breakpoint 7.*ending-run.c, line 14.*"
106 gdb_test "b *$line_nine" ".*Note.*also.*Breakpoint 8.*"
107 gdb_test "c" ".*Breakpoint.*7.*callee.*14.*"
108 gdb_test "cle" ".*Deleted breakpoints 8 7.*" "Clear 2 by default"
109 }
110 -re ".*$gdb_prompt $" {
111 fail "need to fix test for new compile outcome"
112 }
113 }
114
115 send_gdb "i b\n"
116 gdb_expect {
117 -re ".*breakpoint.*breakpoint.*$gdb_prompt $" {
118 fail "didn't clear bps"
119 }
120 -re ".*3.*main.*31.*$gdb_prompt $" {
121 pass "all set to continue"
122 }
123 -re ".*$gdb_prompt $" {
124 fail "missing bp at end"
125 }
126 }
127
128
129 # See if we can step out with control. The "1 2 3" stuff
130 # is output from the program.
131 #
132 gdb_test "cont" ".*Breakpoint.*31.*"
133
134 if ![gdb_skip_stdio_test "Step to return"] {
135 gdb_test "next" ".*1 2 7 14 23 34 47 62 79 Goodbye!.*32.*" \
136 "Step to return"
137 } else {
138 gdb_test "next" "" ""
139 }
140
141 set old_timeout $timeout
142 set timeout 50
143 send_gdb "next\n"
144 gdb_expect {
145 -re "33.*$gdb_prompt $" {
146 # sometimes we stop at the closing brace, if so, do another next
147 send_gdb "next\n"
148 gdb_expect {
149 -re ".*Unable to find return pc for this frame.*$gdb_prompt $" {
150 fail "Old bug came back!"
151 gdb_test "n" ".*" ""
152 }
153 -re ".*in.*start.*$gdb_prompt $" {
154 pass "step out of main"
155 }
156 -re ".*in.*bsp_trap.*$gdb_prompt $" {
157 pass "step out of main"
158 }
159 -re ".*in.*init.*$gdb_prompt $" {
160 # This is what happens on sparc64-elf ultra.
161 pass "step out of main"
162 }
163 -re ".*in .nope ().*$gdb_prompt $" {
164 # This is what happens on Solaris currently -sts 1999-08-25
165 pass "step out of main on Solaris"
166 }
167 -re ".*in ..change.mode ().*$gdb_prompt $" {
168 # This is what happens on ARM in thumb mode -fn 2000-02-01
169 pass "step out of main on ARM thumb"
170 }
171 -re ".*in.*\\\$START\\\$.*from.*dld.sl.*$gdb_prompt $" {
172 pass "step out of main"
173 }
174 -re ".*$gdb_prompt $" { fail "step at end 2" }
175 timeout { fail "hang or timeout on step at end 2" }
176 }
177 }
178 -re ".*Unable to find return pc for this frame.*$gdb_prompt $" {
179 fail "Old bug came back!"
180 gdb_test "n" ".*" ""
181 }
182 -re ".*in.*start.*$gdb_prompt $" {
183 pass "step out of main"
184 }
185 -re ".*in.*\\\$START\\\$.*from.*dld.sl.*$gdb_prompt $" {
186 pass "step out of main 2"
187 }
188 -re ".*in.*currently asm.*$gdb_prompt $" {
189 pass "step out of main into assembler"
190 }
191 -re ".*Program received signal SIGTRAP.*$gdb_prompt $" {
192 pass "Cygmon stopped in ending trap."
193 }
194 -re ".*$gdb_prompt $" { fail "step at end 1" }
195 timeout { fail "hang or timeout on step at end 1" }
196 }
197
198 if {![target_info exists use_cygmon] || ![target_info use_cygmon]} {
199 send_gdb "n\n"
200 gdb_expect {
201 -re "Program exited normally.*$gdb_prompt $" {
202 # If we actually have debug info for the start function,
203 # then we won't get the "Single-stepping until function
204 # exit" message.
205 pass "step to end of run 1"
206 }
207 -re ".*Single.*Program exited.*$gdb_prompt $" {
208 pass "step to end of run 1"
209 }
210 -re ".*Single.*in exit.*from.*dld.sl.*$gdb_prompt $" {
211 pass "step to end of run 2"
212 gdb_test "c" ".*" "continue after exit"
213 }
214 timeout { fail "(timeout) step to end of run" }
215 }
216
217 set timeout $old_timeout
218
219 gdb_test "n" ".*The program is not being run.*" "don't step after run"
220
221 set exec_output [remote_exec host "ls core"]
222
223
224 if [ regexp "core not found" $exec_output] {
225 pass "No core dumped on quit"
226 } else {
227 if [ regexp "No such file or directory" $exec_output] {
228 pass "ls: core: No core dumped on quit"
229 } else {
230 remote_exec build "rm -f core"
231 fail "Core dumped on quit"
232 }
233 }
234 }
235
236 #remote_exec build "rm -f ${binfile}"
237 return 0
238
239
240
241