gdb
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.cp / nextoverthrow.exp
1 # Copyright 2008, 2009, 2010 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
17 if $tracelevel then {
18 strace $tracelevel
19 }
20
21 if { [skip_cplus_tests] } { continue }
22
23 set testfile "nextoverthrow"
24 set srcfile ${testfile}.cc
25 set binfile $objdir/$subdir/$testfile
26
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
31 return -1
32 }
33
34 if {[prepare_for_testing $testfile.exp $testfile $srcfile {debug c++}]} {
35 return -1
36 }
37
38 if ![runto_main] then {
39 perror "couldn't run to main"
40 continue
41 }
42
43 # See whether we have the needed unwinder hooks.
44 set ok 1
45 gdb_test_multiple "print _Unwind_DebugHook" "check for unwinder hook" {
46 -re "= .*_Unwind_DebugHook.*\r\n$gdb_prompt $" {
47 pass "check for unwinder hook"
48 }
49 -re "No symbol .* in current context.\r\n$gdb_prompt $" {
50 # Pass the test so we don't get bogus fails in the results.
51 pass "check for unwinder hook"
52 set ok 0
53 }
54 }
55 if {!$ok} {
56 unsupported "nextoverthrow.exp could not find _Unwind_DebugHook"
57 return -1
58 }
59
60 # Set a temporary breakpoint and then continue to it.
61 # The breakpoint is set according to a marker in the file.
62 proc tbreak_and_cont {text} {
63 global testfile
64
65 set line [gdb_get_line_number $text $testfile.cc]
66 gdb_breakpoint "$testfile.cc:$line" temporary
67 gdb_test "continue" "Temporary breakpoint.*" "continuing to $text"
68 }
69
70 # Verify the value of testval.
71 proc verify_testval {name value} {
72 gdb_test "print testval == $value" " = true" $name
73 }
74
75 # See http://sourceware.org/bugzilla/show_bug.cgi?id=9593
76 # Our general approach here is to do some operation, verify
77 # that testval has not changed, continue to the location at
78 # which the next test starts, and verify testval again.
79 # This works around platform differences in debuginfo that
80 # make looking at the source line unreliable.
81
82 # A simple test of next over a throw.
83 tbreak_and_cont "Start: first test"
84 gdb_test "next" ".*" "next over a throw 1"
85 tbreak_and_cont "End: first test"
86 verify_testval "pre-check - next over a throw 1" -1
87
88 tbreak_and_cont "Start: nested throw"
89 verify_testval "post-check - next over a throw 1" 0
90 gdb_test "next" ".*" "next over a throw 2"
91 tbreak_and_cont "End: nested throw"
92 verify_testval "pre-check - next over a throw 2" 0
93
94 tbreak_and_cont "Start: step in test"
95 verify_testval "post-check - next over a throw 2" 1
96 gdb_test "step" "function1().*" "step into function2 1"
97 gdb_test "next" ".*" "next over a throw 3"
98 tbreak_and_cont "End: step in test"
99 verify_testval "pre-check - next over a throw 3" 1
100
101 tbreak_and_cont "Start: next past catch"
102 verify_testval "post-check - next over a throw 3" 2
103 gdb_test "next" ".*" "next past catch"
104 tbreak_and_cont "End: next past catch"
105 verify_testval "pre-check - next past catch" 2
106
107 tbreak_and_cont "Start: rethrow"
108 verify_testval "post-check - next past catch" 3
109 gdb_test "next" ".*" "next over a throw 4"
110 tbreak_and_cont "End: rethrow"
111 verify_testval "pre-check - next over a throw 4" 3
112
113 tbreak_and_cont "Start: first finish"
114 verify_testval "post-check - next over a throw 4" 4
115 gdb_test "step" "function1().*" "step into function2 2"
116 gdb_test "finish" ".*" "finish 1"
117 tbreak_and_cont "End: first finish"
118 verify_testval "pre-check - finish 1" 4
119
120 tbreak_and_cont "Start: second finish"
121 verify_testval "post-check - finish 1" 5
122 gdb_test "step" "function1 ().*" "step into finish method"
123 gdb_test "finish" ".*" "finish 2"
124 tbreak_and_cont "End: second finish"
125 verify_testval "pre-check - finish 2" 5
126
127 tbreak_and_cont "Start: first until"
128 verify_testval "post-check - finish 2" 6
129 gdb_test "step" ".*" "step into finish, for until"
130 gdb_test "until" ".*" "until with no argument 1"
131 set line [gdb_get_line_number "marker for until" $testfile.cc]
132 gdb_test "until $line" "function1 ().*" "next past catch 6"
133 gdb_test "until" ".*" "until with no argument 2"
134 tbreak_and_cont "End: first until"
135 verify_testval "pre-check - until 1" 6
136
137 tbreak_and_cont "Start: second until"
138 verify_testval "post-check - until 1" 7
139 set line [gdb_get_line_number "until here" $testfile.cc]
140 gdb_test "step" "function1 ().*" "step into until"
141 gdb_test "until $line" ".*" "until-over-throw"
142 tbreak_and_cont "End: second until"
143 verify_testval "pre-check - until 2" 7
144
145 tbreak_and_cont "Start: advance"
146 verify_testval "post-check - until 2" 8
147 gdb_test "step" "function1 ().*" "step into until, for advance"
148 gdb_test "advance $line" ".*" "advance-over-throw"
149 tbreak_and_cont "End: advance"
150 verify_testval "pre-check - advance" 8
151
152 tbreak_and_cont "done"
153 verify_testval "post-check - advance" 9
This page took 0.035107 seconds and 5 git commands to generate.