#include #include #include #include #include #include #include #define DONT_CARE 0 int stats; struct user_regs_struct regs; void continue_execution(pid_t pid) { ptrace(PTRACE_CONT, pid, DONT_CARE, DONT_CARE); waitpid(pid, &stats, 0); return; } void print_rax(pid_t pid) { ptrace(PTRACE_GETREGS, pid, DONT_CARE, ®s); printf("rax = %llu\n", regs.rax); return; } void step(pid_t pid) { ptrace(PTRACE_SINGLESTEP, pid, DONT_CARE, DONT_CARE); waitpid(pid, &stats, 0); return; } int main() { printf("procces is run "); pid_t pid; pid = fork(); if (pid==0) { printf(" -- child\n"); ptrace(PTRACE_TRACEME, 0, 0, 0); execl("./testee", "testee", NULL); printf("____AFTER_TRACE_CHILD____\n"); } else if(pid > 0) { char buff; printf(" -- parrent\n"); continue_execution(pid); // to start app continue_execution(pid); if (stats & SIGTRAP) { printf("--BREAKPOINT--\n"); while (stats != 0) { read(0, &buff, 1); print_rax(pid); step(pid); } } printf("____PROCESS_WAS_TERMINATED____\n"); } return 0; }