Commit | Line | Data |
---|---|---|
c906108c | 1 | #include <stdio.h> |
085dd6e6 | 2 | #include <unistd.h> |
c906108c SS |
3 | /* |
4 | * Since using watchpoints can be very slow, we have to take some pains to | |
5 | * ensure that we don't run too long with them enabled or we run the risk | |
6 | * of having the test timeout. To help avoid this, we insert some marker | |
7 | * functions in the execution stream so we can set breakpoints at known | |
8 | * locations, without worrying about invalidating line numbers by changing | |
9 | * this file. We use null bodied functions are markers since gdb does | |
10 | * not support breakpoints at labeled text points at this time. | |
11 | * | |
12 | * One place we need is a marker for when we start executing our tests | |
13 | * instructions rather than any process startup code, so we insert one | |
14 | * right after entering main(). Another is right before we finish, before | |
15 | * we start executing any process termination code. | |
16 | * | |
17 | * Another problem we have to guard against, at least for the test | |
18 | * suite, is that we need to ensure that the line that causes the | |
19 | * watchpoint to be hit is still the current line when gdb notices | |
20 | * the hit. Depending upon the specific code generated by the compiler, | |
21 | * the instruction after the one that triggers the hit may be part of | |
22 | * the same line or part of the next line. Thus we ensure that there | |
23 | * are always some instructions to execute on the same line after the | |
24 | * code that should trigger the hit. | |
25 | */ | |
26 | ||
27 | int count = -1; | |
28 | int ival1 = -1; | |
29 | int ival2 = -1; | |
30 | int ival3 = -1; | |
31 | int ival4 = -1; | |
085dd6e6 | 32 | int ival5 = -1; |
218d2fc6 | 33 | char buf[30] = "testtesttesttesttesttesttestte"; |
c906108c SS |
34 | struct foo |
35 | { | |
36 | int val; | |
37 | }; | |
38 | struct foo struct1, struct2, *ptr1, *ptr2; | |
39 | ||
40 | int doread = 0; | |
41 | ||
fa4727a6 | 42 | char *global_ptr; |
65d79d4b | 43 | char **global_ptr_ptr; |
fa4727a6 | 44 | |
fabde485 PA |
45 | struct foo2 |
46 | { | |
47 | int val[2]; | |
48 | }; | |
49 | struct foo2 foo2; | |
50 | ||
51 | struct foo4 | |
52 | { | |
53 | int val[4]; | |
54 | }; | |
55 | struct foo4 foo4; | |
56 | ||
3a1115a0 TT |
57 | struct foo5 |
58 | { | |
59 | struct { int x; } *p; | |
60 | }; | |
61 | ||
62 | struct foo5 *nullptr; | |
63 | ||
c906108c SS |
64 | void marker1 () |
65 | { | |
66 | } | |
67 | ||
68 | void marker2 () | |
69 | { | |
70 | } | |
71 | ||
72 | void marker4 () | |
73 | { | |
74 | } | |
75 | ||
76 | void marker5 () | |
77 | { | |
78 | } | |
79 | ||
085dd6e6 JM |
80 | void marker6 () |
81 | { | |
82 | } | |
83 | ||
84 | #ifdef PROTOTYPES | |
85 | void recurser (int x) | |
86 | #else | |
87 | void recurser (x) int x; | |
88 | #endif | |
89 | { | |
97ddaa9b | 90 | int local_x = 0; |
085dd6e6 JM |
91 | |
92 | if (x > 0) | |
93 | recurser (x-1); | |
94 | local_x = x; | |
95 | } | |
96 | ||
c906108c SS |
97 | void |
98 | func2 () | |
99 | { | |
bdddb4de | 100 | int local_a = 0; |
085dd6e6 JM |
101 | static int static_b; |
102 | ||
bdddb4de | 103 | /* func2 breakpoint here */ |
085dd6e6 JM |
104 | ival5++; |
105 | local_a = ival5; | |
106 | static_b = local_a; | |
c906108c SS |
107 | } |
108 | ||
293e9a31 DC |
109 | void |
110 | func3 () | |
111 | { | |
112 | int x; | |
113 | int y; | |
114 | ||
115 | x = 0; | |
116 | x = 1; /* second x assignment */ | |
117 | y = 1; | |
118 | y = 2; | |
218d2fc6 | 119 | buf[26] = 3; |
293e9a31 DC |
120 | } |
121 | ||
c906108c SS |
122 | int |
123 | func1 () | |
124 | { | |
125 | /* The point of this is that we will set a breakpoint at this call. | |
126 | ||
127 | Then, if DECR_PC_AFTER_BREAK equals the size of a function call | |
128 | instruction (true on a sun3 if this is gcc-compiled--FIXME we | |
129 | should use asm() to make it work for any compiler, present or | |
130 | future), then we will end up branching to the location just after | |
131 | the breakpoint. And we better not confuse that with hitting the | |
132 | breakpoint. */ | |
133 | func2 (); | |
134 | return 73; | |
135 | } | |
136 | ||
fa4727a6 DJ |
137 | void |
138 | func4 () | |
139 | { | |
140 | buf[0] = 3; | |
141 | global_ptr = buf; | |
142 | buf[0] = 7; | |
65d79d4b SDJ |
143 | buf[1] = 5; |
144 | global_ptr_ptr = &global_ptr; | |
145 | buf[0] = 9; | |
146 | global_ptr++; | |
fa4727a6 DJ |
147 | } |
148 | ||
06a64a0b TT |
149 | void |
150 | func5 () | |
151 | { | |
152 | int val = 0, val2 = 23; | |
153 | int *x = &val; | |
154 | ||
155 | /* func5 breakpoint here */ | |
156 | x = &val2; | |
157 | val = 27; | |
158 | } | |
159 | ||
fabde485 PA |
160 | void |
161 | func6 (void) | |
162 | { | |
163 | /* func6 breakpoint here */ | |
164 | foo2.val[1] = 0; | |
165 | foo2.val[1] = 11; | |
166 | } | |
167 | ||
168 | void | |
169 | func7 (void) | |
170 | { | |
171 | /* func7 breakpoint here */ | |
172 | foo4.val[3] = 0; | |
173 | foo4.val[3] = 33; | |
174 | } | |
175 | ||
c906108c SS |
176 | int main () |
177 | { | |
c906108c SS |
178 | struct1.val = 1; |
179 | struct2.val = 2; | |
180 | ptr1 = &struct1; | |
181 | ptr2 = &struct2; | |
182 | marker1 (); | |
183 | func1 (); | |
184 | for (count = 0; count < 4; count++) { | |
185 | ival1 = count; | |
186 | ival3 = count; ival4 = count; | |
187 | } | |
188 | ival1 = count; /* Outside loop */ | |
189 | ival2 = count; | |
190 | ival3 = count; ival4 = count; | |
191 | marker2 (); | |
192 | if (doread) | |
193 | { | |
194 | static char msg[] = "type stuff for buf now:"; | |
195 | write (1, msg, sizeof (msg) - 1); | |
196 | read (0, &buf[0], 5); | |
197 | } | |
198 | marker4 (); | |
199 | ||
200 | /* We have a watchpoint on ptr1->val. It should be triggered if | |
201 | ptr1's value changes. */ | |
202 | ptr1 = ptr2; | |
203 | ||
204 | /* This should not trigger the watchpoint. If it does, then we | |
205 | used the wrong value chain to re-insert the watchpoints or we | |
206 | are not evaluating the watchpoint expression correctly. */ | |
207 | struct1.val = 5; | |
208 | marker5 (); | |
209 | ||
210 | /* We have a watchpoint on ptr1->val. It should be triggered if | |
211 | ptr1's value changes. */ | |
212 | ptr1 = ptr2; | |
213 | ||
214 | /* This should not trigger the watchpoint. If it does, then we | |
215 | used the wrong value chain to re-insert the watchpoints or we | |
216 | are not evaluating the watchpoint expression correctly. */ | |
217 | struct1.val = 5; | |
218 | marker5 (); | |
085dd6e6 JM |
219 | |
220 | /* We're going to watch locals of func2, to see that out-of-scope | |
221 | watchpoints are detected and properly deleted. | |
222 | */ | |
223 | marker6 (); | |
224 | ||
225 | /* This invocation is used for watches of a single | |
226 | local variable. */ | |
227 | func2 (); | |
228 | ||
229 | /* This invocation is used for watches of an expression | |
230 | involving a local variable. */ | |
231 | func2 (); | |
232 | ||
233 | /* This invocation is used for watches of a static | |
234 | (non-stack-based) local variable. */ | |
235 | func2 (); | |
236 | ||
237 | /* This invocation is used for watches of a local variable | |
238 | when recursion happens. | |
239 | */ | |
240 | marker6 (); | |
241 | recurser (2); | |
242 | ||
97ddaa9b PH |
243 | /* This invocation is used for watches of a local variable with explicitly |
244 | specified scope when recursion happens. | |
245 | */ | |
246 | marker6 (); | |
247 | recurser (2); | |
248 | ||
085dd6e6 | 249 | marker6 (); |
293e9a31 DC |
250 | |
251 | func3 (); | |
252 | ||
fa4727a6 DJ |
253 | func4 (); |
254 | ||
06a64a0b TT |
255 | func5 (); |
256 | ||
fabde485 PA |
257 | func6 (); |
258 | ||
259 | func7 (); | |
260 | ||
c906108c SS |
261 | return 0; |
262 | } |