1 # Copyright 2008, 2009, 2010, 2011 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/>.
21 if { [skip_cplus_tests] } { continue }
23 set testfile "nextoverthrow"
24 set srcfile ${testfile}.cc
25 set binfile $objdir/$subdir/$testfile
27 # Create and source the file that provides information about the compiler
28 # used to compile the test case.
29 if [get_compiler_info ${binfile} "c++"] {
30 untested nextoverthrow.exp
34 if {[prepare_for_testing $testfile.exp $testfile $srcfile {debug c++}]} {
38 if ![runto_main] then {
39 perror "couldn't run to main"
43 # See whether we have the needed unwinder hooks.
45 gdb_test_multiple "print _Unwind_DebugHook" "check for unwinder hook" {
46 -re "= .*no debug info.*_Unwind_DebugHook.*\r\n$gdb_prompt $" {
47 # Pass the test so we don't get bogus fails in the results.
48 pass "check for unwinder hook"
51 -re "= .*_Unwind_DebugHook.*\r\n$gdb_prompt $" {
52 pass "check for unwinder hook"
54 -re "No symbol .* in current context.\r\n$gdb_prompt $" {
55 # Pass the test so we don't get bogus fails in the results.
56 pass "check for unwinder hook"
61 unsupported "nextoverthrow.exp could not find _Unwind_DebugHook"
65 # Set a temporary breakpoint and then continue to it.
66 # The breakpoint is set according to a marker in the file.
67 proc tbreak_and_cont {text} {
70 set line [gdb_get_line_number $text $testfile.cc]
71 gdb_breakpoint "$testfile.cc:$line" temporary
72 gdb_test "continue" "Temporary breakpoint.*" "continuing to $text"
75 # Verify the value of testval.
76 proc verify_testval {name value} {
77 gdb_test "print testval == $value" " = true" $name
80 # See http://sourceware.org/bugzilla/show_bug.cgi?id=9593
81 # Our general approach here is to do some operation, verify
82 # that testval has not changed, continue to the location at
83 # which the next test starts, and verify testval again.
84 # This works around platform differences in debuginfo that
85 # make looking at the source line unreliable.
87 # A simple test of next over a throw.
88 tbreak_and_cont "Start: first test"
89 gdb_test "next" ".*" "next over a throw 1"
90 tbreak_and_cont "End: first test"
91 verify_testval "pre-check - next over a throw 1" -1
93 tbreak_and_cont "Start: nested throw"
94 verify_testval "post-check - next over a throw 1" 0
95 gdb_test "next" ".*" "next over a throw 2"
96 tbreak_and_cont "End: nested throw"
97 verify_testval "pre-check - next over a throw 2" 0
99 tbreak_and_cont "Start: step in test"
100 verify_testval "post-check - next over a throw 2" 1
101 gdb_test "step" "function1().*" "step into function2 1"
102 gdb_test "next" ".*" "next over a throw 3"
103 tbreak_and_cont "End: step in test"
104 verify_testval "pre-check - next over a throw 3" 1
106 tbreak_and_cont "Start: next past catch"
107 verify_testval "post-check - next over a throw 3" 2
108 gdb_test "next" ".*" "next past catch"
109 tbreak_and_cont "End: next past catch"
110 verify_testval "pre-check - next past catch" 2
112 tbreak_and_cont "Start: rethrow"
113 verify_testval "post-check - next past catch" 3
114 gdb_test "next" ".*" "next over a throw 4"
115 tbreak_and_cont "End: rethrow"
116 verify_testval "pre-check - next over a throw 4" 3
118 tbreak_and_cont "Start: first finish"
119 verify_testval "post-check - next over a throw 4" 4
120 gdb_test "step" "function1().*" "step into function2 2"
121 gdb_test "finish" ".*" "finish 1"
122 tbreak_and_cont "End: first finish"
123 verify_testval "pre-check - finish 1" 4
125 tbreak_and_cont "Start: second finish"
126 verify_testval "post-check - finish 1" 5
127 gdb_test "step" "function1 ().*" "step into finish method"
128 gdb_test "finish" ".*" "finish 2"
129 tbreak_and_cont "End: second finish"
130 verify_testval "pre-check - finish 2" 5
132 tbreak_and_cont "Start: first until"
133 verify_testval "post-check - finish 2" 6
134 gdb_test "step" ".*" "step into finish, for until"
135 gdb_test "until" ".*" "until with no argument 1"
136 set line [gdb_get_line_number "marker for until" $testfile.cc]
137 gdb_test "until $line" "function1 ().*" "next past catch 6"
138 gdb_test "until" ".*" "until with no argument 2"
139 tbreak_and_cont "End: first until"
140 verify_testval "pre-check - until 1" 6
142 tbreak_and_cont "Start: second until"
143 verify_testval "post-check - until 1" 7
144 set line [gdb_get_line_number "until here" $testfile.cc]
145 gdb_test "step" "function1 ().*" "step into until"
146 gdb_test "until $line" ".*" "until-over-throw"
147 tbreak_and_cont "End: second until"
148 verify_testval "pre-check - until 2" 7
150 tbreak_and_cont "Start: advance"
151 verify_testval "post-check - until 2" 8
152 gdb_test "step" "function1 ().*" "step into until, for advance"
153 gdb_test "advance $line" ".*" "advance-over-throw"
154 tbreak_and_cont "End: advance"
155 verify_testval "pre-check - advance" 8
157 tbreak_and_cont "Start: resumebpt"
158 gdb_test "tbreak _Unwind_RaiseException"
159 gdb_test "continue" "Temporary breakpoint.*" "continuing to _Unwind_RaiseException"
160 gdb_test "finish" "Run till exit .*"
161 gdb_test {set $retpc=$pc}
162 gdb_test {break *$retpc if dummy ()}
163 tbreak_and_cont "Second: resumebpt"
166 tbreak_and_cont "done"
167 verify_testval "post-check - advance" 10