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; |
c906108c SS |
33 | char buf[10]; |
34 | struct foo | |
35 | { | |
36 | int val; | |
37 | }; | |
38 | struct foo struct1, struct2, *ptr1, *ptr2; | |
39 | ||
40 | int doread = 0; | |
41 | ||
fa4727a6 DJ |
42 | char *global_ptr; |
43 | ||
c906108c SS |
44 | void marker1 () |
45 | { | |
46 | } | |
47 | ||
48 | void marker2 () | |
49 | { | |
50 | } | |
51 | ||
52 | void marker4 () | |
53 | { | |
54 | } | |
55 | ||
56 | void marker5 () | |
57 | { | |
58 | } | |
59 | ||
085dd6e6 JM |
60 | void marker6 () |
61 | { | |
62 | } | |
63 | ||
64 | #ifdef PROTOTYPES | |
65 | void recurser (int x) | |
66 | #else | |
67 | void recurser (x) int x; | |
68 | #endif | |
69 | { | |
70 | int local_x; | |
71 | ||
72 | if (x > 0) | |
73 | recurser (x-1); | |
74 | local_x = x; | |
75 | } | |
76 | ||
c906108c SS |
77 | void |
78 | func2 () | |
79 | { | |
085dd6e6 JM |
80 | int local_a; |
81 | static int static_b; | |
82 | ||
83 | ival5++; | |
84 | local_a = ival5; | |
85 | static_b = local_a; | |
c906108c SS |
86 | } |
87 | ||
293e9a31 DC |
88 | void |
89 | func3 () | |
90 | { | |
91 | int x; | |
92 | int y; | |
93 | ||
94 | x = 0; | |
95 | x = 1; /* second x assignment */ | |
96 | y = 1; | |
97 | y = 2; | |
98 | } | |
99 | ||
c906108c SS |
100 | int |
101 | func1 () | |
102 | { | |
103 | /* The point of this is that we will set a breakpoint at this call. | |
104 | ||
105 | Then, if DECR_PC_AFTER_BREAK equals the size of a function call | |
106 | instruction (true on a sun3 if this is gcc-compiled--FIXME we | |
107 | should use asm() to make it work for any compiler, present or | |
108 | future), then we will end up branching to the location just after | |
109 | the breakpoint. And we better not confuse that with hitting the | |
110 | breakpoint. */ | |
111 | func2 (); | |
112 | return 73; | |
113 | } | |
114 | ||
fa4727a6 DJ |
115 | void |
116 | func4 () | |
117 | { | |
118 | buf[0] = 3; | |
119 | global_ptr = buf; | |
120 | buf[0] = 7; | |
121 | } | |
122 | ||
c906108c SS |
123 | int main () |
124 | { | |
125 | #ifdef usestubs | |
126 | set_debug_traps(); | |
127 | breakpoint(); | |
128 | #endif | |
129 | struct1.val = 1; | |
130 | struct2.val = 2; | |
131 | ptr1 = &struct1; | |
132 | ptr2 = &struct2; | |
133 | marker1 (); | |
134 | func1 (); | |
135 | for (count = 0; count < 4; count++) { | |
136 | ival1 = count; | |
137 | ival3 = count; ival4 = count; | |
138 | } | |
139 | ival1 = count; /* Outside loop */ | |
140 | ival2 = count; | |
141 | ival3 = count; ival4 = count; | |
142 | marker2 (); | |
143 | if (doread) | |
144 | { | |
145 | static char msg[] = "type stuff for buf now:"; | |
146 | write (1, msg, sizeof (msg) - 1); | |
147 | read (0, &buf[0], 5); | |
148 | } | |
149 | marker4 (); | |
150 | ||
151 | /* We have a watchpoint on ptr1->val. It should be triggered if | |
152 | ptr1's value changes. */ | |
153 | ptr1 = ptr2; | |
154 | ||
155 | /* This should not trigger the watchpoint. If it does, then we | |
156 | used the wrong value chain to re-insert the watchpoints or we | |
157 | are not evaluating the watchpoint expression correctly. */ | |
158 | struct1.val = 5; | |
159 | marker5 (); | |
160 | ||
161 | /* We have a watchpoint on ptr1->val. It should be triggered if | |
162 | ptr1's value changes. */ | |
163 | ptr1 = ptr2; | |
164 | ||
165 | /* This should not trigger the watchpoint. If it does, then we | |
166 | used the wrong value chain to re-insert the watchpoints or we | |
167 | are not evaluating the watchpoint expression correctly. */ | |
168 | struct1.val = 5; | |
169 | marker5 (); | |
085dd6e6 JM |
170 | |
171 | /* We're going to watch locals of func2, to see that out-of-scope | |
172 | watchpoints are detected and properly deleted. | |
173 | */ | |
174 | marker6 (); | |
175 | ||
176 | /* This invocation is used for watches of a single | |
177 | local variable. */ | |
178 | func2 (); | |
179 | ||
180 | /* This invocation is used for watches of an expression | |
181 | involving a local variable. */ | |
182 | func2 (); | |
183 | ||
184 | /* This invocation is used for watches of a static | |
185 | (non-stack-based) local variable. */ | |
186 | func2 (); | |
187 | ||
188 | /* This invocation is used for watches of a local variable | |
189 | when recursion happens. | |
190 | */ | |
191 | marker6 (); | |
192 | recurser (2); | |
193 | ||
194 | marker6 (); | |
293e9a31 DC |
195 | |
196 | func3 (); | |
197 | ||
fa4727a6 DJ |
198 | func4 (); |
199 | ||
c906108c SS |
200 | return 0; |
201 | } |