]>
Commit | Line | Data |
---|---|---|
186c406b TT |
1 | /* This testcase is part of GDB, the GNU debugger. |
2 | ||
0b302171 | 3 | Copyright 2008-2012 Free Software Foundation, Inc. |
186c406b TT |
4 | |
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. | |
9 | ||
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. | |
14 | ||
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/>. | |
17 | */ | |
18 | #include <iostream> | |
19 | ||
20 | using namespace std; | |
21 | ||
5b79abe7 | 22 | int dummy () |
186c406b | 23 | { |
5b79abe7 | 24 | return 0; |
186c406b TT |
25 | } |
26 | ||
27 | class NextOverThrowDerivates | |
28 | { | |
29 | ||
30 | public: | |
31 | ||
32 | ||
33 | // Single throw an exception in this function. | |
34 | void function1 (int val) | |
35 | { | |
36 | throw val; | |
37 | } | |
38 | ||
39 | // Throw an exception in another function. | |
40 | void function2 (int val) | |
41 | { | |
42 | function1 (val); | |
43 | } | |
44 | ||
45 | // Throw an exception in another function, but handle it | |
46 | // locally. | |
47 | void function3 (int val) | |
48 | { | |
49 | { | |
50 | try | |
51 | { | |
52 | function1 (val); | |
53 | } | |
54 | catch (...) | |
55 | { | |
56 | cout << "Caught and handled function1 exception" << endl; | |
57 | } | |
58 | } | |
59 | } | |
60 | ||
61 | void rethrow (int val) | |
62 | { | |
63 | try | |
64 | { | |
65 | function1 (val); | |
66 | } | |
67 | catch (...) | |
68 | { | |
69 | throw; | |
70 | } | |
71 | } | |
72 | ||
73 | void finish (int val) | |
74 | { | |
75 | // We use this to test that a "finish" here does not end up in | |
76 | // this frame, but in the one above. | |
77 | try | |
78 | { | |
79 | function1 (val); | |
80 | } | |
81 | catch (int x) | |
82 | { | |
83 | } | |
84 | function1 (val); // marker for until | |
85 | } | |
86 | ||
87 | void until (int val) | |
88 | { | |
89 | function1 (val); | |
90 | function1 (val); // until here | |
91 | } | |
92 | ||
5b79abe7 TT |
93 | void resumebpt (int val) |
94 | { | |
95 | try | |
96 | { | |
97 | throw val; | |
98 | } | |
99 | catch (int x) | |
100 | { | |
101 | dummy (); | |
102 | } | |
103 | } | |
104 | ||
186c406b TT |
105 | }; |
106 | NextOverThrowDerivates next_cases; | |
107 | ||
108 | ||
5b79abe7 TT |
109 | int |
110 | resumebpt_test (int x) | |
111 | { | |
112 | try | |
113 | { | |
114 | next_cases.resumebpt (x); // Start: resumebpt | |
115 | next_cases.resumebpt (x + 1); // Second: resumebpt | |
116 | } | |
117 | catch (int val) | |
118 | { | |
119 | dummy (); | |
120 | x = val; | |
121 | } | |
122 | ||
123 | return x; | |
124 | } | |
125 | ||
186c406b TT |
126 | int main () |
127 | { | |
128 | int testval = -1; | |
129 | ||
130 | try | |
131 | { | |
132 | next_cases.function1 (0); // Start: first test | |
133 | } | |
134 | catch (int val) | |
135 | { | |
136 | dummy (); | |
137 | testval = val; // End: first test | |
138 | } | |
139 | ||
140 | try | |
141 | { | |
142 | next_cases.function2 (1); // Start: nested throw | |
143 | } | |
144 | catch (int val) | |
145 | { | |
146 | dummy (); | |
147 | testval = val; // End: nested throw | |
148 | } | |
149 | ||
150 | try | |
151 | { | |
152 | // This is duplicated so we can next over one but step into | |
153 | // another. | |
154 | next_cases.function2 (2); // Start: step in test | |
155 | } | |
156 | catch (int val) | |
157 | { | |
158 | dummy (); | |
159 | testval = val; // End: step in test | |
160 | } | |
161 | ||
162 | next_cases.function3 (3); // Start: next past catch | |
163 | dummy (); | |
164 | testval = 3; // End: next past catch | |
165 | ||
166 | try | |
167 | { | |
168 | next_cases.rethrow (4); // Start: rethrow | |
169 | } | |
170 | catch (int val) | |
171 | { | |
172 | dummy (); | |
173 | testval = val; // End: rethrow | |
174 | } | |
175 | ||
176 | try | |
177 | { | |
178 | // Another duplicate so we can test "finish". | |
179 | next_cases.function2 (5); // Start: first finish | |
180 | } | |
181 | catch (int val) | |
182 | { | |
183 | dummy (); | |
184 | testval = val; // End: first finish | |
185 | } | |
186 | ||
187 | // Another test for "finish". | |
188 | try | |
189 | { | |
190 | next_cases.finish (6); // Start: second finish | |
191 | } | |
192 | catch (int val) | |
193 | { | |
194 | dummy (); | |
195 | testval = val; // End: second finish | |
196 | } | |
197 | ||
198 | // Test of "until". | |
199 | try | |
200 | { | |
201 | next_cases.finish (7); // Start: first until | |
202 | } | |
203 | catch (int val) | |
204 | { | |
205 | dummy (); | |
206 | testval = val; // End: first until | |
207 | } | |
208 | ||
209 | // Test of "until" with an argument. | |
210 | try | |
211 | { | |
212 | next_cases.until (8); // Start: second until | |
213 | } | |
214 | catch (int val) | |
215 | { | |
216 | dummy (); | |
217 | testval = val; // End: second until | |
218 | } | |
219 | ||
220 | // Test of "advance". | |
221 | try | |
222 | { | |
223 | next_cases.until (9); // Start: advance | |
224 | } | |
225 | catch (int val) | |
226 | { | |
227 | dummy (); | |
228 | testval = val; // End: advance | |
229 | } | |
230 | ||
5b79abe7 TT |
231 | // Test of "resumebpt". |
232 | testval = resumebpt_test (10); | |
233 | ||
186c406b TT |
234 | testval = 32; // done |
235 | } |