#include <stdio.h>
-#include <stdio.h>
+#include <unistd.h>
/*
* Since using watchpoints can be very slow, we have to take some pains to
* ensure that we don't run too long with them enabled or we run the risk
int ival2 = -1;
int ival3 = -1;
int ival4 = -1;
-char buf[10];
+int ival5 = -1;
+char buf[30] = "testtesttesttesttesttesttestte";
struct foo
{
int val;
int doread = 0;
+char *global_ptr;
+char **global_ptr_ptr;
+
+struct foo2
+{
+ int val[2];
+};
+struct foo2 foo2;
+
+struct foo4
+{
+ int val[4];
+};
+struct foo4 foo4;
+
+struct foo5
+{
+ struct { int x; } *p;
+};
+
+struct foo5 *nullptr;
+
void marker1 ()
{
}
{
}
+void marker6 ()
+{
+}
+
+#ifdef PROTOTYPES
+void recurser (int x)
+#else
+void recurser (x) int x;
+#endif
+{
+ int local_x = 0;
+
+ if (x > 0)
+ recurser (x-1);
+ local_x = x;
+}
+
void
func2 ()
{
+ int local_a = 0;
+ static int static_b;
+
+ /* func2 breakpoint here */
+ ival5++;
+ local_a = ival5;
+ static_b = local_a;
+}
+
+void
+func3 ()
+{
+ int x;
+ int y;
+
+ x = 0;
+ x = 1; /* second x assignment */
+ y = 1;
+ y = 2;
+ buf[26] = 3;
}
int
return 73;
}
+void
+func4 ()
+{
+ buf[0] = 3;
+ global_ptr = buf;
+ buf[0] = 7;
+ buf[1] = 5;
+ global_ptr_ptr = &global_ptr;
+ buf[0] = 9;
+ global_ptr++;
+}
+
+void
+func5 ()
+{
+ int val = 0, val2 = 23;
+ int *x = &val;
+
+ /* func5 breakpoint here */
+ x = &val2;
+ val = 27;
+}
+
+void
+func6 (void)
+{
+ /* func6 breakpoint here */
+ foo2.val[1] = 0;
+ foo2.val[1] = 11;
+}
+
+void
+func7 (void)
+{
+ /* func7 breakpoint here */
+ foo4.val[3] = 0;
+ foo4.val[3] = 33;
+}
+
int main ()
{
struct1.val = 1;
ival3 = count; ival4 = count;
marker2 ();
if (doread)
- read (0, &buf[0], 5);
+ {
+ static char msg[] = "type stuff for buf now:";
+ write (1, msg, sizeof (msg) - 1);
+ read (0, &buf[0], 5);
+ }
marker4 ();
/* We have a watchpoint on ptr1->val. It should be triggered if
are not evaluating the watchpoint expression correctly. */
struct1.val = 5;
marker5 ();
- if (doread)
- read (0, &buf[0], 5);
- marker4 ();
/* We have a watchpoint on ptr1->val. It should be triggered if
ptr1's value changes. */
are not evaluating the watchpoint expression correctly. */
struct1.val = 5;
marker5 ();
+
+ /* We're going to watch locals of func2, to see that out-of-scope
+ watchpoints are detected and properly deleted.
+ */
+ marker6 ();
+
+ /* This invocation is used for watches of a single
+ local variable. */
+ func2 ();
+
+ /* This invocation is used for watches of an expression
+ involving a local variable. */
+ func2 ();
+
+ /* This invocation is used for watches of a static
+ (non-stack-based) local variable. */
+ func2 ();
+
+ /* This invocation is used for watches of a local variable
+ when recursion happens.
+ */
+ marker6 ();
+ recurser (2);
+
+ /* This invocation is used for watches of a local variable with explicitly
+ specified scope when recursion happens.
+ */
+ marker6 ();
+ recurser (2);
+
+ marker6 ();
+
+ func3 ();
+
+ func4 ();
+
+ func5 ();
+
+ func6 ();
+
+ func7 ();
+
return 0;
}