Home | History | Annotate | Download | only in Linux
      1 // RUN: %clangxx -O0 %s -o %t && %run %t
      2 // XFAIL: arm-linux-gnueabi
      3 
      4 #include <assert.h>
      5 #include <signal.h>
      6 #include <stdio.h>
      7 #include <sys/ptrace.h>
      8 #include <sys/types.h>
      9 #include <sys/user.h>
     10 #include <sys/wait.h>
     11 #include <unistd.h>
     12 
     13 int main(void) {
     14   pid_t pid;
     15   pid = fork();
     16   if (pid == 0) { // child
     17     ptrace(PTRACE_TRACEME, 0, NULL, NULL);
     18     execl("/bin/true", "true", NULL);
     19   } else {
     20     wait(NULL);
     21     user_regs_struct regs;
     22     int res;
     23     res = ptrace(PTRACE_GETREGS, pid, NULL, &regs);
     24     assert(!res);
     25     if (regs.rip)
     26       printf("%zx\n", regs.rip);
     27 
     28     user_fpregs_struct fpregs;
     29     res = ptrace(PTRACE_GETFPREGS, pid, NULL, &fpregs);
     30     assert(!res);
     31     if (fpregs.mxcsr)
     32       printf("%x\n", fpregs.mxcsr);
     33 
     34     siginfo_t siginfo;
     35     res = ptrace(PTRACE_GETSIGINFO, pid, NULL, &siginfo);
     36     assert(!res);
     37     assert(siginfo.si_pid == pid);
     38 
     39     ptrace(PTRACE_CONT, pid, NULL, NULL);
     40 
     41     wait(NULL);
     42   }
     43   return 0;
     44 }
     45