Commit | Line | Data |
---|---|---|
bc5065a7 PA |
1 | /* This testcase is part of GDB, the GNU debugger. |
2 | ||
b811d2c2 | 3 | Copyright 2013-2020 Free Software Foundation, Inc. |
bc5065a7 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 | |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
17 | ||
18 | /* Note: 'volatile' is used to make sure the compiler doesn't fold / | |
19 | optimize out the arithmetic that uses the variables. */ | |
20 | ||
21 | static int | |
22 | func1 (int a, int b) | |
23 | { | |
24 | volatile int r = a * b; | |
25 | ||
26 | r += (a | b); | |
27 | r += (a - b); | |
28 | ||
29 | return r; | |
30 | } | |
31 | ||
32 | int | |
33 | main(void) | |
34 | { | |
35 | volatile int a = 0; | |
36 | volatile int b = 1; | |
37 | volatile int c = 2; | |
38 | volatile int d = 3; | |
39 | volatile int e = 4; | |
40 | volatile double d1 = 1.0; | |
41 | volatile double d2 = 2.0; | |
42 | ||
43 | /* A macro that expands to a single source line that compiles to a | |
44 | number of instructions, with no branches. */ | |
45 | #define LINE_WITH_MULTIPLE_INSTRUCTIONS \ | |
46 | do \ | |
47 | { \ | |
48 | a = b + c + d * e - a; \ | |
49 | } while (0) | |
50 | ||
51 | LINE_WITH_MULTIPLE_INSTRUCTIONS; /* location 1 */ | |
52 | ||
53 | /* A line of source code that compiles to a function call (jump or | |
54 | branch), surrounded by instructions before and after. IOW, this | |
55 | will generate approximately the following pseudo-instructions: | |
56 | ||
57 | addr1: | |
58 | insn1; | |
59 | insn2; | |
60 | ... | |
61 | call func1; | |
62 | ... | |
63 | insn3; | |
64 | addr2: | |
65 | insn4; | |
66 | */ | |
67 | e = 10 + func1 (a + b, c * d); /* location 2 */ | |
68 | ||
69 | e = 10 + func1 (a + b, c * d); | |
70 | ||
71 | /* Generate a single source line that includes a short loop. */ | |
72 | #define LINE_WITH_LOOP \ | |
73 | do \ | |
74 | { \ | |
75 | for (a = 0, e = 0; a < 15; a++) \ | |
76 | e += a; \ | |
77 | } while (0) | |
78 | ||
79 | LINE_WITH_LOOP; | |
80 | ||
81 | LINE_WITH_LOOP; | |
82 | ||
83 | /* Generate a single source line that includes a time-consuming | |
84 | loop. GDB breaks the loop early by clearing variable 'c'. */ | |
85 | #define LINE_WITH_TIME_CONSUMING_LOOP \ | |
86 | do \ | |
87 | { \ | |
88 | for (c = 1, a = 0; a < 65535 && c; a++) \ | |
89 | for (b = 0; b < 65535 && c; b++) \ | |
90 | { \ | |
91 | d1 = d2 * a / b; \ | |
92 | d2 = d1 * a; \ | |
93 | } \ | |
94 | } while (0) | |
95 | ||
96 | LINE_WITH_TIME_CONSUMING_LOOP; | |
97 | ||
98 | /* Some multi-instruction lines for software watchpoint tests. */ | |
99 | LINE_WITH_MULTIPLE_INSTRUCTIONS; | |
100 | LINE_WITH_MULTIPLE_INSTRUCTIONS; /* soft-watch */ | |
101 | LINE_WITH_MULTIPLE_INSTRUCTIONS; | |
102 | ||
103 | return 0; | |
104 | } |