[英]Stack Walk on linux using ptrace
以下是我的要求。
进程A正在运行。
我在循环中遇到Start和Resume Process A的问题。 我尝试了kill(pid,SIGSTOP),kill(pid,SIGCONT),PTRACE_CONT的组合。 但没有工作。
还有其他解决方案吗?
提前致谢。 桑迪普
以下代码对我有用,似乎满足您的要求 -
AC
#include<stdio.h>
int main()
{
int i=0;
printf("My PID is - %ld\n",getpid());
while(i>=0)
{
}
return 0;
}
Bc - 追踪过程
int main()
{
int pid;
int status;
struct user_regs_struct regs;
unsigned int eip;
printf("Enter pid to trace : \n");
scanf("%d",&pid);
printf("PID to be traced - %ld\n",pid);
ptrace(PTRACE_ATTACH,pid,0,0);
if(errno)
{
perror("attach");
return -1;
}
waitpid(pid,&status,WUNTRACED);
printf("Process Stopped\n");
while(1)
{
ptrace(PTRACE_GETREGS,pid,0,®s);
eip=ptrace(PTRACE_PEEKTEXT,pid,regs.eip,0);
printf("EIP - 0x%08x, instruction executed - 0x%08x\n",regs.eip,eip);
ptrace(PTRACE_CONT,pid,0,0);
waitpid(pid,&status,WUNTRACED);
}
return 0;
}
信号传递 -
杀死-STOP 17779杀死-STOP 17779
A的输出 -
xxxxx!xxxxx:~/myPer/stack_overflow [135]$ ./A
My PID is - 17779
B的输出 -
XXXXX!xxxxx:~/myPer/stack_overflow [121]$ ./B
Enter pid to trace :
17779
PID to be traced - 17779
Process Stopped
EIP - 0x080483e1, instruction executed - 0x00f87d83
EIP - 0x080483e5, instruction executed - 0x00b8fa79
EIP - 0x080483e5, instruction executed - 0x00b8fa79
我们看到B显示传送给客户端的每个信号的EIP值。 基本上信号没有传递到A而是B唤醒并检查EIP然后继续循环。 如果需要,您可以修改代码以传递信号。
这是我从你的问题中理解的。 如果我理解别的东西请告诉我,我会相应地更新答案
您可以像许多IDE一样尝试使用gdb编写脚本/接口。 另见http://www.redhat.com/docs/manuals/enterprise/RHEL-4-Manual/gdb/gdb-mi.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.