]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.base/longjmp.c
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / longjmp.c
CommitLineData
9dd789d0
PA
1/* This testcase is part of GDB, the GNU debugger.
2
1d506c26 3 Copyright 2008-2024 Free Software Foundation, Inc.
9dd789d0
PA
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
47d48711 16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
9dd789d0
PA
17
18#include <setjmp.h>
19
20jmp_buf env;
21
22volatile int longjmps = 0;
23volatile int resumes = 0;
24
25int
26call_longjmp (jmp_buf *buf)
27{
28 longjmps++;
29 longjmp (*buf, 1);
30}
31
32void
33hidden_longjmp (void)
34{
e81a37f7 35 if (setjmp (env) == 0)
9dd789d0
PA
36 {
37 call_longjmp (&env);
38 }
39 else
40 resumes++;
41}
42
43int
44main ()
45{
46 volatile int i = 0;
47
48 /* Pattern 1 - simple longjmp. */
6e41445b 49 if (setjmp (env) != 0) /* patt1 */
9dd789d0 50 {
6e41445b 51 resumes++;
9dd789d0
PA
52 }
53 else
54 {
6e41445b
TV
55 longjmps++;
56 longjmp (env, 1);
9dd789d0
PA
57 }
58
59 i = 1; /* miss_step_1 */
60
61
62 /* Pattern 2 - longjmp from an inner function. */
63 if (setjmp (env) == 0) /* patt2 */
64 {
65 call_longjmp (&env);
66 }
67 else
68 {
69 resumes++;
70 }
71
72 i = 2; /* miss_step_2 */
73
74 /* Pattern 3 - setjmp/longjmp inside stepped-over function. */
75 hidden_longjmp (); /* patt3 */
76
e81a37f7
TT
77 i = 77; /* longjmp caught */
78
9dd789d0
PA
79 i = 3; /* patt_end3. */
80
81 return 0;
82}