summaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.cp/nextoverthrow.cc
blob: e57100ee9f3ef59cf63999e019781c98da726a8a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
/* This testcase is part of GDB, the GNU debugger.

   Copyright 2008-2022 Free Software Foundation, Inc.

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

#include <iostream>

using namespace std;

int dummy ()
{
  return 0;
}

class NextOverThrowDerivates
{

public:


  // Single throw an exception in this function.
  void function1 (int val)
  {
    throw val;
  }

  // Throw an exception in another function.
  void function2 (int val)
  {
    function1 (val);
  }

  // Throw an exception in another function, but handle it
  // locally.
  void function3 (int val)
  {
    {
      try
	{
	  function1 (val);
	}
      catch (...) 
	{
	  cout << "Caught and handled function1 exception" << endl;
	}
    }
  }

  void rethrow (int val)
  {
    try
      {
	function1 (val);
      }
    catch (...)
      {
	throw;
      }
  }

  void finish (int val)
  {
    // We use this to test that a "finish" here does not end up in
    // this frame, but in the one above.
    try
      {
	function1 (val);
      }
    catch (int x)
      {
      }
    function1 (val);		// marker for until
  }

  void until (int val)
  {
    function1 (val);
    function1 (val);		// until here
  }

  void resumebpt (int val)
  {
    try
      {
	throw val;
      }
    catch (int x)
      {
	dummy ();
      }
  }

};
NextOverThrowDerivates next_cases;


int
resumebpt_test (int x)
{
  try
    {
      next_cases.resumebpt (x);	    // Start: resumebpt
      next_cases.resumebpt (x + 1); // Second: resumebpt
    }
  catch (int val)
    {
      dummy ();
      x = val;
    }

  return x;
}

int main () 
{ 
  int testval = -1;

  try
    {
      next_cases.function1 (0);	// Start: first test
    }
  catch (int val)
    {
      dummy ();
      testval = val;		// End: first test
    }

  try
    {
      next_cases.function2 (1);	// Start: nested throw
    }
  catch (int val)
    {
      dummy ();
      testval = val;		// End: nested throw
    }

  try
    {
      // This is duplicated so we can next over one but step into
      // another.
      next_cases.function2 (2);	// Start: step in test
    }
  catch (int val)
    {
      dummy ();
      testval = val;		// End: step in test
    }

  next_cases.function3 (3);	// Start: next past catch
  dummy ();
  testval = 3;			// End: next past catch

  try
    {
      next_cases.rethrow (4);	// Start: rethrow
    }
  catch (int val)
    {
      dummy ();
      testval = val;		// End: rethrow
    }

  try
    {
      // Another duplicate so we can test "finish".
      next_cases.function2 (5);	// Start: first finish
    }
  catch (int val)
    {
      dummy ();
      testval = val;		// End: first finish
    }

  // Another test for "finish".
  try
    {
      next_cases.finish (6);	// Start: second finish
    }
  catch (int val)
    {
      dummy ();
      testval = val;		// End: second finish
    }

  // Test of "until".
  try
    {
      next_cases.finish (7);	// Start: first until
    }
  catch (int val)
    {
      dummy ();
      testval = val;		// End: first until
    }

  // Test of "until" with an argument.
  try
    {
      next_cases.until (8);	// Start: second until
    }
  catch (int val)
    {
      dummy ();
      testval = val;		// End: second until
    }

  // Test of "advance".
  try
    {
      next_cases.until (9);	// Start: advance
    }
  catch (int val)
    {
      dummy ();
      testval = val;		// End: advance
    }

  // Test of "resumebpt".
  testval = resumebpt_test (10);

  testval = 32;			// done
}