Chinaunix

标题: 如何使用ptrace获得arm CPU的寄存器信息 [打印本页]

作者: waiting000    时间: 2011-12-31 16:58
标题: 如何使用ptrace获得arm CPU的寄存器信息
在/usr/include/asm/ptrace.h 中看到以下代码

  1. struct pt_regs {
  2. long uregs[18];
  3. };

  4. #define ARM_cpsr uregs[16]
  5. #define ARM_pc uregs[15]
  6. #define ARM_lr uregs[14]
  7. #define ARM_sp uregs[13]
  8. #define ARM_ip uregs[12]
  9. #define ARM_fp uregs[11]
  10. #define ARM_r10 uregs[10]
  11. #define ARM_r9 uregs[9]
  12. #define ARM_r8 uregs[8]
  13. #define ARM_r7 uregs[7]
  14. #define ARM_r6 uregs[6]
  15. #define ARM_r5 uregs[5]
  16. #define ARM_r4 uregs[4]
  17. #define ARM_r3 uregs[3]
  18. #define ARM_r2 uregs[2]
  19. #define ARM_r1 uregs[1]
  20. #define ARM_r0 uregs[0]
复制代码
然后我希望使用x86上的方式获得CPU寄存器值

  1. int main(int argc, char *argv[])
  2. {
  3.         pid_t traced_process;
  4.         struct pt_regs regs;
  5.         long ins;

  6.         if ( argc != 2 ) {
  7.                 printf("Usage: %s <pid to be traced>", argv[0]);
  8.                 exit(1);
  9.         }

  10.         traced_process = atoi(argv[1]);
  11.         ptrace(PTRACE_ATTACH, traced_process, NULL, NULL);
  12.         wait(NULL);
  13.         ptrace(PTRACE_GETREGS, traced_process, NULL, &regs);
  14.         ins = ptrace(PTRACE_PEEKTEXT, traced_process,
  15.                                 regs.ARM_ip, NULL);
  16.         printf("EIP: %lx Instructions executed: %lx\n", regs.ARM_ip, ins);
  17.         ptrace(PTRACE_DETACH, traced_process, NULL, NULL);

  18.         return 0;
  19. }
复制代码
但是实际执行的时候,输出
EIP: 0 Instructions executed: ffffffff

如何达到我想要的目的。谢谢指教
作者: cjaizss    时间: 2012-01-07 01:14
似乎没看出来有什么大问题,哪天我去试验一下看看.




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2