OSDN Git Service

Initial revision
[pf3gnuchains/pf3gnuchains3x.git] / gdb / testsuite / gdb.hp / watch-hp.c
1 #include <stdio.h>
2 /*
3  *      Since using watchpoints can be very slow, we have to take some pains to
4  *      ensure that we don't run too long with them enabled or we run the risk
5  *      of having the test timeout.  To help avoid this, we insert some marker
6  *      functions in the execution stream so we can set breakpoints at known
7  *      locations, without worrying about invalidating line numbers by changing
8  *      this file.  We use null bodied functions are markers since gdb does
9  *      not support breakpoints at labeled text points at this time.
10  *
11  *      One place we need is a marker for when we start executing our tests
12  *      instructions rather than any process startup code, so we insert one
13  *      right after entering main().  Another is right before we finish, before
14  *      we start executing any process termination code.
15  *
16  *      Another problem we have to guard against, at least for the test
17  *      suite, is that we need to ensure that the line that causes the
18  *      watchpoint to be hit is still the current line when gdb notices
19  *      the hit.  Depending upon the specific code generated by the compiler,
20  *      the instruction after the one that triggers the hit may be part of
21  *      the same line or part of the next line.  Thus we ensure that there
22  *      are always some instructions to execute on the same line after the
23  *      code that should trigger the hit.
24  */
25
26 int count = -1;
27 int ival1 = -1;
28 int ival2 = -1;
29 int ival3 = -1;
30 int ival4 = -1;
31 int ival5 = -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 marker6 ()
58 {
59 }
60
61 void recurser (x)
62   int  x;
63 {
64   int  local_x;
65
66   if (x > 0)
67     recurser (x-1);
68   local_x = x;
69 }
70
71 void
72 func2 ()
73 {
74   int  local_a;
75   static int  static_b;
76
77   ival5++;
78   local_a = ival5;
79   static_b = local_a;
80 }
81
82 int
83 func1 ()
84 {
85   /* The point of this is that we will set a breakpoint at this call.
86
87      Then, if DECR_PC_AFTER_BREAK equals the size of a function call
88      instruction (true on a sun3 if this is gcc-compiled--FIXME we
89      should use asm() to make it work for any compiler, present or
90      future), then we will end up branching to the location just after
91      the breakpoint.  And we better not confuse that with hitting the
92      breakpoint.  */
93   func2 ();
94   return 73;
95 }
96
97 int main ()
98 {
99   struct1.val = 1;
100   struct2.val = 2;
101   ptr1 = &struct1;
102   ptr2 = &struct2;
103   marker1 ();
104   func1 ();
105   for (count = 0; count < 4; count++) {
106     ival1 = count;
107     ival3 = count; ival4 = count;
108   }
109   ival1 = count; /* Outside loop */
110   ival2 = count;
111   ival3 = count; ival4 = count;
112   marker2 ();
113   if (doread)
114     {
115       static char msg[] = "type stuff for buf now:";
116       write (1, msg, sizeof (msg) - 1);
117       read (0, &buf[0], 5);
118     }
119   marker4 ();
120
121   /* We have a watchpoint on ptr1->val.  It should be triggered if
122      ptr1's value changes.  */
123   ptr1 = ptr2;
124
125   /* This should not trigger the watchpoint.  If it does, then we
126      used the wrong value chain to re-insert the watchpoints or we
127      are not evaluating the watchpoint expression correctly.  */
128   struct1.val = 5;
129   marker5 ();
130
131   /* We have a watchpoint on ptr1->val.  It should be triggered if
132      ptr1's value changes.  */
133   ptr1 = ptr2;
134
135   /* This should not trigger the watchpoint.  If it does, then we
136      used the wrong value chain to re-insert the watchpoints or we
137      are not evaluating the watchpoint expression correctly.  */
138   struct1.val = 5;
139   marker5 ();
140
141   /* We're going to watch locals of func2, to see that out-of-scope
142      watchpoints are detected and properly deleted.
143      */
144   marker6 ();
145
146   /* This invocation is used for watches of a single
147      local variable. */
148   func2 ();
149
150   /* This invocation is used for watches of an expression
151      involving a local variable. */
152   func2 ();
153
154   /* This invocation is used for watches of a static
155      (non-stack-based) local variable. */
156   func2 ();
157
158   /* This invocation is used for watches of a local variable
159      when recursion happens.
160      */
161   marker6 ();
162   recurser (2);
163
164   marker6 ();
165   return 0;
166 }