1 // RUN: %clangxx -O0 %s -o %t && %run %t
6 #include <sys/ptrace.h>
13 #if __mips64 || __arm__
14 #include <asm/ptrace.h>
15 #include <sys/procfs.h>
18 // GLIBC 2.20+ sys/user does not include asm/ptrace.h
19 #include <asm/ptrace.h>
25 if (pid
== 0) { // child
26 ptrace(PTRACE_TRACEME
, 0, NULL
, NULL
);
27 execl("/bin/true", "true", NULL
);
33 user_regs_struct regs
;
34 res
= ptrace(PTRACE_GETREGS
, pid
, NULL
, ®s
);
37 printf("%zx\n", regs
.rip
);
39 user_fpregs_struct fpregs
;
40 res
= ptrace(PTRACE_GETFPREGS
, pid
, NULL
, &fpregs
);
43 printf("%x\n", fpregs
.mxcsr
);
46 #if (__powerpc64__ || __mips64 || __arm__)
48 res
= ptrace((enum __ptrace_request
)PTRACE_GETREGS
, pid
, NULL
, ®s
);
52 printf("%lx\n", regs
.nip
);
55 printf("%lx\n", regs
.cp0_epc
);
58 printf("%lx\n", regs
.ARM_pc
);
60 #if (__powerpc64 || __mips64)
61 elf_fpregset_t fpregs
;
62 res
= ptrace((enum __ptrace_request
)PTRACE_GETFPREGS
, pid
, NULL
, &fpregs
);
64 if ((elf_greg_t
)fpregs
[32]) // fpscr
65 printf("%lx\n", (elf_greg_t
)fpregs
[32]);
67 char regbuf
[ARM_VFPREGS_SIZE
];
68 res
= ptrace((enum __ptrace_request
)PTRACE_GETVFPREGS
, pid
, 0, regbuf
);
70 unsigned fpscr
= *(unsigned*)(regbuf
+ (32 * 8));
71 printf ("%x\n", fpscr
);
73 #endif // (__powerpc64__ || __mips64 || __arm__)
76 struct iovec regset_io
;
78 struct user_pt_regs regs
;
79 regset_io
.iov_base
= ®s
;
80 regset_io
.iov_len
= sizeof(regs
);
81 res
= ptrace(PTRACE_GETREGSET
, pid
, (void*)NT_PRSTATUS
, (void*)®set_io
);
84 printf("%llx\n", regs
.pc
);
86 struct user_fpsimd_state fpregs
;
87 regset_io
.iov_base
= &fpregs
;
88 regset_io
.iov_len
= sizeof(fpregs
);
89 res
= ptrace(PTRACE_GETREGSET
, pid
, (void*)NT_FPREGSET
, (void*)®set_io
);
92 printf("%x\n", fpregs
.fpsr
);
93 #endif // (__aarch64__)
96 res
= ptrace(PTRACE_GETSIGINFO
, pid
, NULL
, &siginfo
);
98 assert(siginfo
.si_pid
== pid
);
100 ptrace(PTRACE_CONT
, pid
, NULL
, NULL
);