OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gdb-7.2/] [gdb/] [testsuite/] [gdb.base/] [watchpoint.c] - Blame information for rev 394

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.