1 # This testcase is part of GDB, the GNU debugger.
3 # Copyright 1997-2024 Free Software Foundation, Inc.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 # ending-run.exp -- Expect script to test ending a test run in gdb
28 lappend_include_file flags $srcdir/lib/unbuffer_output.c
30 if { [prepare_for_testing "failed to prepare" $testfile $srcfile $flags] } {
33 remote_exec build "rm -f core"
35 set break1_line [gdb_get_line_number "-break1-"]
36 gdb_test "b ending-run.c:$break1_line" \
37 "Breakpoint 1 at ${::hex}.*" \
38 "b ending-run.c:$break1_line, one"
40 # Set up to go to the next-to-last line of the program
42 set break2_line [gdb_get_line_number "-break2-"]
43 gdb_test "b ending-run.c:$break2_line" ".*Breakpoint 2.*ending-run.c, line $break2_line.*"
45 # Expect to hit the bp at line "1", but symbolize this
46 # as line "13". Then try to clear it--this should work.
49 gdb_test "" ".*Breakpoint.*1.*callee.*$break1_line.*" "run"
51 gdb_test "cle" "Deleted breakpoint 1 " "clear worked"
52 gdb_test_multiple "i b" "cleared bp at stopped line" {
53 -re ".* breakpoint .* breakpoint .*$gdb_prompt $" {
56 -re ".*2.*main.*$break2_line.*$gdb_prompt $" {
61 # Test some other "clear" combinations
63 gdb_test "b ending-run.c:$break1_line" "Breakpoint 3 at ${::hex}.*" "b ending-run.c:$break1_line, two"
64 gdb_test "cle ending-run.c:$break1_line" \
65 "Deleted breakpoint 3 " "Cleared 2 by line"
67 gdb_test_multiple "info line ending-run.c:$break1_line" "" {
68 -re ".*address (0x\[0-9a-fA-F]*).*$gdb_prompt $" {
69 set line_nine $expect_out(1,string)
70 gdb_test "b ending-run.c:$break1_line" ".*Breakpoint 4.*ending-run.c, line $break1_line.*"
71 gdb_test "b *$line_nine" ".*Note.*also.*Breakpoint 5.*" "breakpoint 7 at *ending-run.c:$break1_line"
72 gdb_test "cle" "Deleted breakpoints 4 5 " "clear 2 by default"
74 -re ".*$gdb_prompt $" {
75 fail "need to fix test for new compile outcome"
79 gdb_test_multiple "i b" "all set to continue" {
80 -re ".* breakpoint .* breakpoint .*$gdb_prompt $" {
81 fail "all set to continue (didn't clear bps)"
83 -re ".*2.*main.*$break2_line.*$gdb_prompt $" {
84 pass "all set to continue"
86 -re ".*$gdb_prompt $" {
87 fail "all set to continue (missing bp at end)"
92 # See if we can step out with control. The "1 2 3" stuff
93 # is output from the program.
95 if ![gdb_skip_stdio_test "cont"] {
96 gdb_test_stdio "cont" \
97 "1 2 7 14 23 34 47 62 79" \
98 "Breakpoint.*$break2_line.*"
100 gdb_test "cont" ".*Breakpoint.*$break2_line.*"
103 if ![gdb_skip_stdio_test "Step to return"] {
104 gdb_test_stdio "next" \
106 "[expr {$break2_line + 1}].*" \
109 gdb_test "next" ".*" ""
112 set old_timeout $timeout
117 gdb_test_multiple "next" "step out of main" {
118 -re "[expr {$break2_line + 2}]\[ \t\]+\}.*$gdb_prompt $" {
119 # sometimes we stop at the closing brace, if so, do another next
121 fail "step out of main"
128 -re ".*Unable to find return pc for this frame.*$gdb_prompt $" {
129 fail "step out of main"
132 -re ".*in.*start.*$gdb_prompt $" {
133 pass "step out of main"
135 -re ".*in.*bsp_trap.*$gdb_prompt $" {
136 pass "step out of main"
138 -re ".*in.*init.*$gdb_prompt $" {
139 # This is what happens on sparc64-elf ultra.
140 pass "step out of main"
142 -re ".*in.*dll_crt0_1.*$gdb_prompt $" {
143 # This is what happens on Cygwin.
144 pass "step out of main"
146 -re ".*WinMain.*$gdb_prompt $" {
147 # This is what happens on mingw32ce.
148 pass "step out of main"
150 -re ".*$inferior_exited_re normally.*$gdb_prompt $" {
151 # This is what happens on Linux i86 (and I would expect others)
153 pass "step out of main"
155 -re ".*in .nope ().*$gdb_prompt $" {
156 # This is what happens on Solaris currently -sts 1999-08-25
157 pass "step out of main"
159 -re ".*in _int_reset ().*$gdb_prompt $" {
160 # This is what happens on Sanyo XStormy16
161 pass "step out of main"
163 -re ".*init ().*$gdb_prompt $" {
164 # This is what happens on many Mips targets
165 pass "step out of main"
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"
171 -re ".*__rt_entry.* ().*$gdb_prompt $" {
172 # This is what happens on the ARM RVDS runtime
173 pass "step out of main"
175 -re ".*in.*\\\$START\\\$.*from.*dld.sl.*$gdb_prompt $" {
176 pass "step out of main"
178 -re ".*in __wrap__?main ().*$gdb_prompt $" {
179 pass "step out of main"
181 -re "__setup_argv_for_main (.*).*$gdb_prompt $" {
182 # On sh, another wrapper function (start_l) exists, so
183 # another `next' is necessary.
184 gdb_test "next" ".*in start_l ().*" "step out of main"
186 -re ".*in.*currently asm.*$gdb_prompt $" {
187 pass "step out of main"
189 -re "_*start\[0-9\]* \\(\[^)\]*\\).*$gdb_prompt $" {
190 pass "step out of main"
192 -re ".*Program received signal SIGTRAP.*$gdb_prompt $" {
193 pass "step out of main"
195 -re ".*in.*__uClibc_main.*$gdb_prompt $" {
196 # This is what happens on system using uClibc.
197 pass "step out of main"
199 -re -wrap "$hex in \\?\\? \\(\\) from \[^\r\n\]+" {
200 # This case occurs when gdb steps out of main and the
201 # needed debug info files are not loaded on the system, preventing
202 # GDB to determine which function it reached (__libc_start_call_main).
203 # Ideally, the target system would have the necessary debugging
204 # information, but in its absence, GDB's behavior is as expected.
206 # Another consequence of this missing information is that GDB
207 # can no longer continue to perform "next" operations, as doing
208 # so requires GDB to know the bounds of the current function.
209 # Not know what the current function it, it cannot determine
210 # its bounds. So we also set program_exited to 1 to indicate
211 # that we need to stop this testcase at this stage of the testing.
212 pass "step out of main"
217 # When we're talking to a program running on a real stand-alone board,
218 # every BSP's exit function behaves differently, so there's no single
219 # way to tell whether we've exited gracefully or not. So don't run
220 # these tests when use_gdb_stub is set, or when we're running under Cygmon.
221 set program_exited_normally 0
222 set program_not_exited 0
223 set program_in_exit 0
225 && (! [target_info exists use_cygmon] || ! [target_info use_cygmon])} {
226 global program_exited
227 if {[eval expr $program_exited == 0]} {
228 gdb_test_multiple "n" "step to end of run" {
229 -re "$inferior_exited_re normally.*$gdb_prompt $" {
230 # If we actually have debug info for the start function,
231 # then we won't get the "Single-stepping until function
233 pass "step to end of run"
234 set program_exited_normally 1
236 -re "Single.*EXIT code 0\r\n.*$inferior_exited_re normally.*$gdb_prompt $" {
237 pass "step to end of run (status wrapper)"
238 set program_exited_normally 1
240 -re "Single.*EXIT code 0\r\n.*$gdb_prompt $" {
241 pass "step to end of run (status wrapper)"
243 -re ".*Single.*$inferior_exited_re.*$gdb_prompt $" {
244 pass "step to end of run"
245 set program_exited_normally 1
247 -re ".*Single.*in exit.*from.*dld.sl.*$gdb_prompt $" {
248 pass "step to end of run"
249 set program_in_exit 1
251 -re ".*Single.*_int_reset.*$gdb_prompt $" {
252 pass "step to end of run"
253 if {![istarget "xstormy16-*-*"]} {
254 set program_exited_normally 1
260 if {$program_in_exit} {
261 if {[gdb_test "c" ".*" "continue after exit"] == 0} {
262 set program_exited_normally 1
265 unsupported "continue after exit"
268 if {$program_exited_normally} {
269 gdb_test "n" ".*The program is not being run.*" "don't step after run"
270 } elseif {$program_not_exited} {
271 unresolved "don't step after run"
273 unsupported "don't step after run"
276 set exec_output [remote_exec host "ls core"]
278 if [ regexp "core not found" $exec_output] {
279 pass "no core dumped on quit"
281 if [ regexp "No such file or directory" $exec_output] {
282 pass "ls: core (No core dumped on quit)"
284 remote_exec build "rm -f core"
285 fail "ls: core (Core dumped on quit)"
290 set timeout $old_timeout
292 #remote_exec build "rm -f ${binfile}"