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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [gdb-5.0/] [gdb/] [testsuite/] [gdb.base/] [watchpoint.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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