1# Copyright 2008-2024 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 3 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, see <http://www.gnu.org/licenses/>. 15 16 17require allow_cplus_tests 18 19standard_testfile .cc 20 21if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug c++}]} { 22 return -1 23} 24 25if {![runto_main]} { 26 return 27} 28 29if {![skip_unwinder_tests]} { 30 unsupported "nextoverthrow.exp could not find _Unwind_DebugHook" 31 return -1 32} 33 34# Set a temporary breakpoint and then continue to it. 35# The breakpoint is set according to a marker in the file. 36proc tbreak_and_cont {text} { 37 global testfile 38 39 set line [gdb_get_line_number $text $testfile.cc] 40 gdb_breakpoint "$testfile.cc:$line" temporary 41 gdb_test "continue" "Temporary breakpoint.*" "continuing to $text" 42} 43 44# Verify the value of testval. 45proc verify_testval {name value} { 46 gdb_test "print testval == $value" " = true" $name 47} 48 49# See http://sourceware.org/bugzilla/show_bug.cgi?id=9593 50# Our general approach here is to do some operation, verify 51# that testval has not changed, continue to the location at 52# which the next test starts, and verify testval again. 53# This works around platform differences in debuginfo that 54# make looking at the source line unreliable. 55 56# A simple test of next over a throw. 57tbreak_and_cont "Start: first test" 58gdb_test "next" ".*" "next over a throw 1" 59tbreak_and_cont "End: first test" 60verify_testval "pre-check - next over a throw 1" -1 61 62tbreak_and_cont "Start: nested throw" 63verify_testval "post-check - next over a throw 1" 0 64gdb_test "next" ".*" "next over a throw 2" 65tbreak_and_cont "End: nested throw" 66verify_testval "pre-check - next over a throw 2" 0 67 68tbreak_and_cont "Start: step in test" 69verify_testval "post-check - next over a throw 2" 1 70gdb_test "step" "function1().*" "step into function2 1" 71gdb_test "next" ".*" "next over a throw 3" 72tbreak_and_cont "End: step in test" 73verify_testval "pre-check - next over a throw 3" 1 74 75tbreak_and_cont "Start: next past catch" 76verify_testval "post-check - next over a throw 3" 2 77gdb_test "next" ".*" "next past catch" 78tbreak_and_cont "End: next past catch" 79verify_testval "pre-check - next past catch" 2 80 81tbreak_and_cont "Start: rethrow" 82verify_testval "post-check - next past catch" 3 83gdb_test "next" ".*" "next over a throw 4" 84tbreak_and_cont "End: rethrow" 85verify_testval "pre-check - next over a throw 4" 3 86 87tbreak_and_cont "Start: first finish" 88verify_testval "post-check - next over a throw 4" 4 89gdb_test "step" "function1().*" "step into function2 2" 90gdb_test "finish" ".*" "finish 1" 91tbreak_and_cont "End: first finish" 92verify_testval "pre-check - finish 1" 4 93 94tbreak_and_cont "Start: second finish" 95verify_testval "post-check - finish 1" 5 96gdb_test "step" "function1 ().*" "step into finish method" 97gdb_test "finish" ".*" "finish 2" 98tbreak_and_cont "End: second finish" 99verify_testval "pre-check - finish 2" 5 100 101tbreak_and_cont "Start: first until" 102verify_testval "post-check - finish 2" 6 103gdb_test "step" ".*" "step into finish, for until" 104gdb_test "until" ".*" "until with no argument 1" 105set line [gdb_get_line_number "marker for until" $testfile.cc] 106gdb_test "until $line" "function1 ().*" "next past catch 6" 107gdb_test "until" ".*" "until with no argument 2" 108tbreak_and_cont "End: first until" 109verify_testval "pre-check - until 1" 6 110 111tbreak_and_cont "Start: second until" 112verify_testval "post-check - until 1" 7 113set line [gdb_get_line_number "until here" $testfile.cc] 114gdb_test "step" "function1 ().*" "step into until" 115gdb_test "until $line" ".*" "until-over-throw" 116tbreak_and_cont "End: second until" 117verify_testval "pre-check - until 2" 7 118 119tbreak_and_cont "Start: advance" 120verify_testval "post-check - until 2" 8 121gdb_test "step" "function1 ().*" "step into until, for advance" 122gdb_test "advance $line" ".*" "advance-over-throw" 123tbreak_and_cont "End: advance" 124verify_testval "pre-check - advance" 8 125 126tbreak_and_cont "Start: resumebpt" 127gdb_test "tbreak _Unwind_RaiseException" 128gdb_test "continue" "Temporary breakpoint.*" "continuing to _Unwind_RaiseException" 129gdb_test "finish" "Run till exit .*" 130gdb_test {set $retpc=$pc} 131gdb_test {break *$retpc if dummy ()} 132tbreak_and_cont "Second: resumebpt" 133gdb_test "next" 134 135tbreak_and_cont "done" 136verify_testval "post-check - advance" 10 137