[gdb/syscalls] Sync with strace v6.13
[binutils-gdb.git] / gdb / testsuite / gdb.base / ending-run.exp
blob90359fd8733d2b25a369e327ecc742a6985d2fcd
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/>.
18 # use this to debug:
20 #log_user 1
22 # ending-run.exp -- Expect script to test ending a test run in gdb
24 standard_testfile
26 set flags {}
27 lappend flags debug
28 lappend_include_file flags $srcdir/lib/unbuffer_output.c
30 if { [prepare_for_testing "failed to prepare" $testfile $srcfile $flags] } {
31     return -1
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.
48 gdb_run_cmd
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 $" {
54         fail $gdb_test_name
55     }
56     -re ".*2.*main.*$break2_line.*$gdb_prompt $" {
57         pass $gdb_test_name
58     }
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"
73     }
74     -re ".*$gdb_prompt $" {
75         fail "need to fix test for new compile outcome"
76     }
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)" 
82     }
83     -re ".*2.*main.*$break2_line.*$gdb_prompt $" {
84         pass "all set to continue"
85     }
86     -re ".*$gdb_prompt $" {
87         fail "all set to continue (missing bp at end)"
88     }
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.*"
99 } else {
100     gdb_test "cont" ".*Breakpoint.*$break2_line.*"
103 if ![gdb_skip_stdio_test "Step to return"] {
104     gdb_test_stdio "next" \
105         "Goodbye!" \
106         "[expr {$break2_line + 1}].*" \
107         "Step to return"
108 } else {
109     gdb_test "next" ".*" ""
112 set old_timeout $timeout
113 set timeout 50
114 set program_exited 0
115 set nexted 0
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
120         if { $nexted } {
121             fail "step out of main"
122         } else {
123             set nexted 1
124             send_gdb "next\n"
125             exp_continue
126         }
127     }
128     -re ".*Unable to find return pc for this frame.*$gdb_prompt $" {
129         fail "step out of main"
130         gdb_test "n" ".*" ""
131     }
132     -re ".*in.*start.*$gdb_prompt $" { 
133         pass "step out of main"
134     }
135     -re ".*in.*bsp_trap.*$gdb_prompt $" { 
136         pass "step out of main"
137     }
138     -re ".*in.*init.*$gdb_prompt $" { 
139         # This is what happens on sparc64-elf ultra.
140         pass "step out of main"
141     }
142     -re ".*in.*dll_crt0_1.*$gdb_prompt $" {
143         # This is what happens on Cygwin.
144         pass "step out of main"
145     }
146     -re ".*WinMain.*$gdb_prompt $" {
147         # This is what happens on mingw32ce.
148         pass "step out of main"
149     }
150     -re ".*$inferior_exited_re normally.*$gdb_prompt $" {
151         # This is what happens on Linux i86 (and I would expect others)
152         set program_exited 1
153         pass "step out of main"
154     }
155     -re ".*in .nope ().*$gdb_prompt $" {
156         # This is what happens on Solaris currently -sts 1999-08-25
157         pass "step out of main"
158     }
159     -re ".*in _int_reset ().*$gdb_prompt $" {
160         # This is what happens on Sanyo XStormy16
161         pass "step out of main"
162     }
163     -re ".*init ().*$gdb_prompt $" {
164         # This is what happens on many Mips targets
165         pass "step out of main"
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"
170     }
171     -re ".*__rt_entry.* ().*$gdb_prompt $" {
172         # This is what happens on the ARM RVDS runtime
173         pass "step out of main"
174     }
175     -re ".*in.*\\\$START\\\$.*from.*dld.sl.*$gdb_prompt $" { 
176         pass "step out of main"
177     }
178     -re ".*in __wrap__?main ().*$gdb_prompt $" {
179         pass "step out of main"
180     }
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"
185     }
186     -re ".*in.*currently asm.*$gdb_prompt $" { 
187         pass "step out of main"
188     }
189     -re "_*start\[0-9\]* \\(\[^)\]*\\).*$gdb_prompt $" {
190         pass "step out of main"
191     }
192     -re ".*Program received signal SIGTRAP.*$gdb_prompt $" {
193         pass "step out of main"
194     }
195     -re ".*in.*__uClibc_main.*$gdb_prompt $" {
196         # This is what happens on system using uClibc.
197         pass "step out of main"
198     }
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.
205         #
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"
213         set program_exited 1
214     }
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
224 if {!$use_gdb_stub
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
232                 # exit" message.
233                 pass "step to end of run"
234                 set program_exited_normally 1
235             }
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
239             }
240             -re "Single.*EXIT code 0\r\n.*$gdb_prompt $" {
241                 pass "step to end of run (status wrapper)"
242             }
243             -re ".*Single.*$inferior_exited_re.*$gdb_prompt $" {
244                 pass "step to end of run"
245                 set program_exited_normally 1
246             }
247             -re ".*Single.*in exit.*from.*dld.sl.*$gdb_prompt $" {
248                 pass "step to end of run" 
249                 set program_in_exit 1
250             }
251             -re ".*Single.*_int_reset.*$gdb_prompt $" {
252                 pass "step to end of run"
253                 if {![istarget "xstormy16-*-*"]} {
254                     set program_exited_normally 1
255                 }
256             }
257         }   
258     }
260     if {$program_in_exit} {
261         if {[gdb_test "c" ".*" "continue after exit"] == 0} {
262             set program_exited_normally 1
263         }
264     } else {
265         unsupported "continue after exit"
266     }
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"
272     } else {
273         unsupported "don't step after run"
274     }
276     set exec_output [remote_exec host "ls core"]
278     if [ regexp "core not found" $exec_output]  {
279         pass "no core dumped on quit"
280     } else {
281         if [ regexp "No such file or directory" $exec_output] {
282             pass "ls: core (No core dumped on quit)"
283         } else {
284             remote_exec build "rm -f core"
285             fail "ls: core (Core dumped on quit)"
286         }
287     }
290 set timeout $old_timeout
292 #remote_exec build "rm -f ${binfile}"