免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3151 | 回复: 1
打印 上一主题 下一主题

如何使用ptrace获得arm CPU的寄存器信息 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-12-31 16:58 |只看该作者 |倒序浏览
在/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

如何达到我想要的目的。谢谢指教

论坛徽章:
3
2015年迎新春徽章
日期:2015-03-04 09:56:11数据库技术版块每日发帖之星
日期:2016-08-03 06:20:00数据库技术版块每日发帖之星
日期:2016-08-04 06:20:00
2 [报告]
发表于 2012-01-07 01:14 |只看该作者
似乎没看出来有什么大问题,哪天我去试验一下看看.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP