Home | History | Annotate | Download | only in gdbserver_tests
      1 #include <stdlib.h>
      2 #include <stdio.h>
      3 #include <string.h>
      4 
      5 static void breakme(int line)
      6 {
      7    fprintf(stderr, "breakme function called from line %d\n", line);
      8    fflush(stderr);
      9 }
     10 static char undefined[10] = "undefined";
     11 int main (int argc, char *argv[])
     12 {
     13 
     14    /* we will test
     15       read watchpoint at 0,
     16       read/write watchpoints at 4
     17       write watchpoints at 8 */
     18 
     19    breakme(__LINE__); //break1
     20 
     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");
     27 
     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");
     32 
     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");
     37 
     38 
     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';
     42 
     43    fprintf(stderr, "before writing 4\n");
     44    undefined[4] = 'F';
     45 
     46    fprintf(stderr, "before writing 8\n");
     47    undefined[8] = 'D';
     48 
     49    fprintf(stderr, "after writing 8\n");
     50 
     51    /* after having remove the watchpoints, check we can read and write
     52       without break. */
     53    fprintf(stderr, "value %s\n", undefined);
     54 
     55    fprintf(stderr, "before rewriting 0\n");
     56    undefined[0] = '0';
     57 
     58    fprintf(stderr, "before rewriting 4\n");
     59    undefined[4] = '4';
     60 
     61    fprintf(stderr, "before rewriting 8\n");
     62    undefined[8] = '8';
     63 
     64    fprintf(stderr, "value %s\n", undefined);
     65 
     66    {
     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
     71    }
     72 
     73    exit(0);
     74 }
     75