1 # Copyright 2014-2023 Free Software Foundation, Inc.
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 3 of the License, or
6 # (at your option) any later version.
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.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 set testname func-ptrs
17 set srcfile ${testname}.c
18 if { [prepare_for_testing "failed to prepare" ${testname} ${srcfile}] } {
22 if { ![runto_main] } {
27 # First set our breakpoints.
29 set fp_breakpoint_re \
30 "Breakpoint $decimal at $hex: file .*${srcfile}, line $decimal\\."
31 gdb_test "break sentinel if calc == decr" \
32 "${fp_breakpoint_re}" \
33 "breakpoint at sentinel"
34 gdb_test "break incr" \
35 "${fp_breakpoint_re}" \
37 gdb_test "break decr" \
38 "${fp_breakpoint_re}" \
42 # Check if we run through to the breakpoint in incr.
45 "Breakpoint $decimal, incr \\(i=-1\\)\[ \r\n\]+at .*${srcfile}:$decimal\[\r\n\]+.*" \
46 "continue to incr, first time"
49 # Go back up, make sure the return value is 0.
52 "Run till exit from #0 +incr \\(i=-1\\)\[ \r\n\]+at .*${srcfile}:$decimal\[\r\n\]+($hex in )?main \\(\\)\[ \r\n\]+at .*${srcfile}:$decimal\[\r\n\]+.*Value returned is \\$$decimal = 0" \
53 "go back to main from incr, first time"
56 # Redirect calc and see if we run to the breakpoint in decr instead.
58 gdb_test_no_output "set calc = decr" "set calc to decr"
60 "Breakpoint $decimal, decr \\(i=0\\)\[ \r\n\]+at .*${srcfile}:$decimal\[\r\n\]+.*" \
64 # Go back up, check if we stop in sentinel instead.
67 "Run till exit from #0 +decr \\(i=0\\)\[ \r\n\]+at .*${srcfile}:$decimal\[\r\n\]+Breakpoint $decimal, sentinel \\(\\)\[ \r\n\]+at .*${srcfile}:$decimal\[\r\n\]+.*" \
71 # Go back all the way up to main, make sure the return value is -1.
73 gdb_test_no_output "up-silently" "move up to decr"
75 "Run till exit from #1 +($hex in )?decr \\(i=0\\)\[ \r\n\]+at .*${srcfile}:$decimal\[\r\n\]+($hex in )?main \\(\\)\[ \r\n\]+at .*${srcfile}:$decimal\[\r\n\]+.*Value returned is \\$$decimal = -1" \
76 "go back to main from decr"
79 # Reset calc and see if we run to the breakpoint in incr again.
81 gdb_test_no_output "set calc = incr" "set calc to incr"
83 "Breakpoint $decimal, incr \\(i=-1\\)\[ \r\n\]+at .*${srcfile}:$decimal\[\r\n\]+.*" \
84 "continue to incr, second time"
87 # Go back up again, make sure the return value is 0.
90 "Run till exit from #0 +incr \\(i=-1\\)\[ \r\n\]+at .*${srcfile}:$decimal\[\r\n\]+($hex in )?main \\(\\)\[ \r\n\]+at .*${srcfile}:$decimal\[\r\n\]+.*Value returned is \\$$decimal = 0" \
91 "go back to main from incr, second time"