]>
Commit | Line | Data |
---|---|---|
cc72b2a2 KP |
1 | /* This testcase is part of GDB, the GNU debugger. |
2 | ||
1d506c26 | 3 | Copyright 2011-2024 Free Software Foundation, Inc. |
cc72b2a2 KP |
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/>. */ |
cc72b2a2 KP |
17 | |
18 | #include <setjmp.h> | |
19 | #include <stdlib.h> | |
a59add0c | 20 | #include <string.h> |
cc72b2a2 KP |
21 | #include <unistd.h> |
22 | ||
23 | /* Defined in py-events-shlib.h. */ | |
24 | extern void do_nothing (void); | |
25 | ||
26 | int increase_1 (int *a) | |
27 | { | |
28 | *a += 1; | |
29 | return -5; | |
30 | } | |
31 | ||
32 | void increase (int *a) | |
33 | { | |
34 | increase_1 (a); | |
35 | } | |
36 | ||
80ffe722 HD |
37 | int increase_2 (int *a) |
38 | { | |
39 | *a += 10; | |
40 | return -8; | |
41 | } | |
42 | ||
43 | inline void __attribute__((always_inline)) | |
44 | increase_inlined (int *a) | |
45 | { | |
46 | increase_2 (a); | |
47 | *a += 5; | |
48 | } | |
49 | ||
cc72b2a2 KP |
50 | int |
51 | test_1 (int i, int j) | |
52 | { | |
53 | return i == j; | |
54 | } | |
55 | ||
56 | int | |
57 | test (int i, int j) | |
58 | { | |
59 | return test_1 (i, j); | |
60 | } | |
61 | ||
62 | int | |
63 | call_longjmp_1 (jmp_buf *buf) | |
64 | { | |
65 | longjmp (*buf, 1); | |
66 | } | |
67 | ||
68 | int | |
69 | call_longjmp (jmp_buf *buf) | |
70 | { | |
71 | call_longjmp_1 (buf); | |
86e4e63d | 72 | return 0; |
cc72b2a2 KP |
73 | } |
74 | ||
75 | void | |
3bc96cfb | 76 | test_exec_exit (const char *self_exec) |
cc72b2a2 | 77 | { |
3bc96cfb | 78 | if (self_exec == NULL) |
cc72b2a2 KP |
79 | exit (0); |
80 | else | |
3bc96cfb | 81 | execl (self_exec, self_exec, "exit", (char *)0); |
cc72b2a2 KP |
82 | } |
83 | ||
84 | int main (int argc, char *argv[]) | |
85 | { | |
86 | jmp_buf env; | |
87 | int foo = 5; | |
88 | int bar = 42; | |
89 | int i, j; | |
90 | ||
3bc96cfb JK |
91 | if (argc == 2 && strcmp (argv[1], "exit") == 0) |
92 | return 0; | |
93 | ||
cc72b2a2 KP |
94 | do_nothing (); |
95 | ||
96 | i = 0; | |
97 | /* Break at increase. */ | |
98 | increase (&i); | |
99 | increase (&i); | |
100 | increase (&i); | |
80ffe722 | 101 | increase_inlined (&i); |
cc72b2a2 KP |
102 | |
103 | for (i = 0; i < 10; i++) | |
104 | { | |
105 | j += 1; /* Condition Break. */ | |
106 | } | |
107 | ||
108 | if (setjmp (env) == 0) /* longjmp caught */ | |
109 | { | |
110 | call_longjmp (&env); | |
111 | } | |
112 | else | |
113 | j += 1; /* after longjmp. */ | |
114 | ||
3bc96cfb | 115 | test_exec_exit (argv[0]); |
cc72b2a2 KP |
116 | |
117 | return j; /* Break at end. */ | |
118 | } |