ptrace에대해서..궁금합니다.

updateing의 이미지

ptrace()를 이용한 backtrace로 자식프로세스에 대한 콜 체인을 얻을수 있나요?

얻을수 있다면 어떤식으로 해야하는지

int main()
{ pid_t child;
const int long_size = sizeof(long);
child = fork();
if(child == 0) {
ptrace(PTRACE_TRACEME, 0, NULL, NULL);
execl("Test_break", "Test_break", NULL);
}
else {
int status;
union u {
long val;
char chars[long_size];
}data;
struct pt_regs regs;
int start = 0;
long ins;
while(1) {

wait(&status);
if(WIFEXITED(status))
break;
ptrace(PTRACE_GETREGS, child, NULL, &regs);
if(start == 1) {
ins = ptrace(PTRACE_PEEKTEXT,child, regs.eip,NULL);
printf("EIP: %#0x Instruction " "executed: %#0x\n",regs.eip, ins);
}
if(regs.orig_eax == SYS_write) {
start = 1;
ptrace(PTRACE_SINGLESTEP, child,NULL, NULL);

}
else

ptrace(PTRACE_SYSCALL, child,NULL, NULL);

}
}
return 0;
}

ptrace()로 regs.ebp regs.esp 로 현재 함수의 주소를 구할수 있나요?

JuEUS-U의 이미지

추측입니다만, 리턴 어드레스를 역참조하면 알아낼 수 있지 않을까요 = ㅅ=)