drd/tests: Add the "dlopen" test program
[valgrind.git] / gdbserver_tests / watchpoints.c
blob132dadba549e8e828d8d3199136dc39c0b7a2f14
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <string.h>
5 static void breakme(int line)
7 fprintf(stderr, "breakme function called from line %d\n", line);
8 fflush(stderr);
10 static char undefined[10] = "undefined";
11 int main (int argc, char *argv[])
14 /* we will test
15 read watchpoint at 0,
16 read/write watchpoints at 4
17 write watchpoints at 8 */
19 breakme(__LINE__); //break1
21 /* We verify read watchpoints are triggered at 0 and 4, not at 8 */
22 fprintf(stderr, "before reading 0/4/8\n");
23 if (undefined[0] == 'u')
24 fprintf(stderr, "u: Expected value at 0\n");
25 else
26 fprintf(stderr, "u: Unexpected value at 0\n");
28 if (undefined[4] == 'f')
29 fprintf(stderr, "f: Expected value at 4\n");
30 else
31 fprintf(stderr, "f: Unexpected value at 4\n");
33 if (undefined[8] == 'd')
34 fprintf(stderr, "d: Expected value at 8\n");
35 else
36 fprintf(stderr, "d: Unexpected value at 8\n");
39 /* We verify write watchpoints are triggered at 4 and 8, not at 0 */
40 fprintf(stderr, "before writing 0\n");
41 undefined[0] = 'U';
43 fprintf(stderr, "before writing 4\n");
44 undefined[4] = 'F';
46 fprintf(stderr, "before writing 8\n");
47 undefined[8] = 'D';
49 fprintf(stderr, "after writing 8\n");
51 /* after having remove the watchpoints, check we can read and write
52 without break. */
53 fprintf(stderr, "value %s\n", undefined);
55 fprintf(stderr, "before rewriting 0\n");
56 undefined[0] = '0';
58 fprintf(stderr, "before rewriting 4\n");
59 undefined[4] = '4';
61 fprintf(stderr, "before rewriting 8\n");
62 undefined[8] = '8';
64 fprintf(stderr, "value %s\n", undefined);
67 char *k50 = malloc(50000);
68 memset (k50, 'p', 50000);
69 fprintf(stderr, "value of k50[1000] %c\n", k50[1000]);
70 free(k50); //break2
73 exit(0);