]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/watchpoint.c
This commit was generated by cvs2svn to track changes on a CVS vendor
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / watchpoint.c
1 #include <stdio.h>
2 #include <stdio.h>
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;
32 char buf[10];
33 struct foo
34 {
35 int val;
36 };
37 struct foo struct1, struct2, *ptr1, *ptr2;
38
39 int doread = 0;
40
41 void marker1 ()
42 {
43 }
44
45 void marker2 ()
46 {
47 }
48
49 void marker4 ()
50 {
51 }
52
53 void marker5 ()
54 {
55 }
56
57 void
58 func2 ()
59 {
60 }
61
62 int
63 func1 ()
64 {
65 /* The point of this is that we will set a breakpoint at this call.
66
67 Then, if DECR_PC_AFTER_BREAK equals the size of a function call
68 instruction (true on a sun3 if this is gcc-compiled--FIXME we
69 should use asm() to make it work for any compiler, present or
70 future), then we will end up branching to the location just after
71 the breakpoint. And we better not confuse that with hitting the
72 breakpoint. */
73 func2 ();
74 return 73;
75 }
76
77 int main ()
78 {
79 struct1.val = 1;
80 struct2.val = 2;
81 ptr1 = &struct1;
82 ptr2 = &struct2;
83 marker1 ();
84 func1 ();
85 for (count = 0; count < 4; count++) {
86 ival1 = count;
87 ival3 = count; ival4 = count;
88 }
89 ival1 = count; /* Outside loop */
90 ival2 = count;
91 ival3 = count; ival4 = count;
92 marker2 ();
93 if (doread)
94 read (0, &buf[0], 5);
95 marker4 ();
96
97 /* We have a watchpoint on ptr1->val. It should be triggered if
98 ptr1's value changes. */
99 ptr1 = ptr2;
100
101 /* This should not trigger the watchpoint. If it does, then we
102 used the wrong value chain to re-insert the watchpoints or we
103 are not evaluating the watchpoint expression correctly. */
104 struct1.val = 5;
105 marker5 ();
106 if (doread)
107 read (0, &buf[0], 5);
108 marker4 ();
109
110 /* We have a watchpoint on ptr1->val. It should be triggered if
111 ptr1's value changes. */
112 ptr1 = ptr2;
113
114 /* This should not trigger the watchpoint. If it does, then we
115 used the wrong value chain to re-insert the watchpoints or we
116 are not evaluating the watchpoint expression correctly. */
117 struct1.val = 5;
118 marker5 ();
119 return 0;
120 }