[Sanitizer] Add the machinery to run the same test under several sanitizers
[blocksruntime.git] / test / sanitizer_common / TestCases / ptrace.cc
blob2c7517551af27157260767d9f051d9e475de1388
1 // RUN: %clangxx -O0 %s -o %t && %run %t
3 #include <assert.h>
4 #include <signal.h>
5 #include <stdio.h>
6 #include <sys/ptrace.h>
7 #include <sys/types.h>
8 #include <sys/user.h>
9 #include <sys/wait.h>
10 #include <unistd.h>
12 int main(void) {
13 pid_t pid;
14 pid = fork();
15 if (pid == 0) { // child
16 ptrace(PTRACE_TRACEME, 0, NULL, NULL);
17 execl("/bin/true", "true", NULL);
18 } else {
19 wait(NULL);
20 user_regs_struct regs;
21 int res;
22 res = ptrace(PTRACE_GETREGS, pid, NULL, &regs);
23 assert(!res);
24 if (regs.rip)
25 printf("%zx\n", regs.rip);
27 user_fpregs_struct fpregs;
28 res = ptrace(PTRACE_GETFPREGS, pid, NULL, &fpregs);
29 assert(!res);
30 if (fpregs.mxcsr)
31 printf("%x\n", fpregs.mxcsr);
33 siginfo_t siginfo;
34 res = ptrace(PTRACE_GETSIGINFO, pid, NULL, &siginfo);
35 assert(!res);
36 assert(siginfo.si_pid == pid);
38 ptrace(PTRACE_CONT, pid, NULL, NULL);
40 wait(NULL);
42 return 0;