diff --git a/08-debugging/Makefile b/08-debugging/Makefile index a139d69..ebce68a 100644 --- a/08-debugging/Makefile +++ b/08-debugging/Makefile @@ -14,4 +14,4 @@ testee.o: testee.asm nasm -felf64 $^ -o $@ -g clean: - rm *.o test *.gch + rm *.o test *.gch testee diff --git a/08-debugging/test.c b/08-debugging/test.c index 86afea6..be8551c 100644 --- a/08-debugging/test.c +++ b/08-debugging/test.c @@ -11,6 +11,28 @@ int stats; struct user_regs_struct regs; +void continue_execution(pid_t pid) +{ + ptrace(PTRACE_CONT, pid, DONT_CARE, DONT_CARE); + int wait_status; + int options = 0; + waitpid(pid, &wait_status, options); + 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); + return; +} + int main() { printf("procces is run "); @@ -25,15 +47,18 @@ int main() } else if(pid > 0) { + char buff; printf(" -- parrent\n"); - for (int i = 0; i < 4; i++) - { + continue_execution(pid); + do { waitpid(pid, &stats, 0); - printf("____PARENT_STAT: %d____\n", stats); - ptrace(PTRACE_GETREGS, pid, DONT_CARE, ®s); - printf("rax = %llu\n", regs.rax); + printf("stats - %d", stats); + print_rax(pid); ptrace(PTRACE_SINGLESTEP, pid, DONT_CARE, DONT_CARE); - } + printf("enter any: "); + read(0, &buff, 1); + printf("\n"); + } while(stats); printf("____AFTER_TRACE_PARRENT____\n"); } return 0; diff --git a/08-debugging/testee.asm b/08-debugging/testee.asm index db63d56..e074aea 100644 --- a/08-debugging/testee.asm +++ b/08-debugging/testee.asm @@ -8,7 +8,11 @@ section .text _start: xor rax, rax, add rax, 1 + int3 add rax, 12 + ;int3 + mov rax, 33 + ;int3 mov rax, 1 mov rdi, 1