blob: ba318169ee7d54c32d8d1096270b77d2d10a396d [file] [log] [blame]
Stephen Hines2d1fdb22014-05-28 23:58:16 -07001// RUN: %clangxx -O0 %s -o %t && %run %t
Stephen Hines2d1fdb22014-05-28 23:58:16 -07002
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>
Stephen Hines86277eb2015-03-23 12:06:32 -070011#if __mips64
12 #include <asm/ptrace.h>
13 #include <sys/procfs.h>
14#endif
Stephen Hines2d1fdb22014-05-28 23:58:16 -070015
16int main(void) {
17 pid_t pid;
18 pid = fork();
19 if (pid == 0) { // child
20 ptrace(PTRACE_TRACEME, 0, NULL, NULL);
21 execl("/bin/true", "true", NULL);
22 } else {
23 wait(NULL);
Stephen Hines2d1fdb22014-05-28 23:58:16 -070024 int res;
Stephen Hines6d186232014-11-26 17:56:19 -080025
26#if __x86_64__
27 user_regs_struct regs;
Stephen Hines2d1fdb22014-05-28 23:58:16 -070028 res = ptrace(PTRACE_GETREGS, pid, NULL, &regs);
29 assert(!res);
30 if (regs.rip)
31 printf("%zx\n", regs.rip);
32
33 user_fpregs_struct fpregs;
34 res = ptrace(PTRACE_GETFPREGS, pid, NULL, &fpregs);
35 assert(!res);
36 if (fpregs.mxcsr)
37 printf("%x\n", fpregs.mxcsr);
Stephen Hines6d186232014-11-26 17:56:19 -080038#endif // __x86_64__
39
Stephen Hines86277eb2015-03-23 12:06:32 -070040#if (__powerpc64__ || __mips64)
Stephen Hines6d186232014-11-26 17:56:19 -080041 struct pt_regs regs;
42 res = ptrace((enum __ptrace_request)PTRACE_GETREGS, pid, NULL, &regs);
43 assert(!res);
Stephen Hines86277eb2015-03-23 12:06:32 -070044#if (__powerpc64__)
Stephen Hines6d186232014-11-26 17:56:19 -080045 if (regs.nip)
46 printf("%lx\n", regs.nip);
Stephen Hines86277eb2015-03-23 12:06:32 -070047#else
48 if (regs.cp0_epc)
49 printf("%lx\n", regs.cp0_epc);
50#endif
Stephen Hines6d186232014-11-26 17:56:19 -080051 elf_fpregset_t fpregs;
52 res = ptrace((enum __ptrace_request)PTRACE_GETFPREGS, pid, NULL, &fpregs);
53 assert(!res);
54 if ((elf_greg_t)fpregs[32]) // fpscr
55 printf("%lx\n", (elf_greg_t)fpregs[32]);
Stephen Hines86277eb2015-03-23 12:06:32 -070056#endif // (__powerpc64__ || __mips64)
Stephen Hines2d1fdb22014-05-28 23:58:16 -070057
58 siginfo_t siginfo;
59 res = ptrace(PTRACE_GETSIGINFO, pid, NULL, &siginfo);
60 assert(!res);
61 assert(siginfo.si_pid == pid);
62
63 ptrace(PTRACE_CONT, pid, NULL, NULL);
64
65 wait(NULL);
66 }
67 return 0;
68}