From dd6c23d79fe745e37bc5e3942e500f3044b52f5e Mon Sep 17 00:00:00 2001 From: Miheev Egor Date: Wed, 30 Oct 2024 22:37:36 +0300 Subject: [PATCH] =?UTF-8?q?feat:=20=D0=BC=D0=B8=D0=BD=D0=B8=D0=BC=D0=B0?= =?UTF-8?q?=D0=BB=D1=8C=D0=BD=D0=BE=D0=B5=20=D1=80=D0=B5=D1=88=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 08-debugging/Makefile | 17 +++++++++++++++++ 08-debugging/test.c | 40 ++++++++++++++++++++++++++++++++++++++++ 08-debugging/testee.asm | 21 +++++++++++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 08-debugging/Makefile create mode 100644 08-debugging/test.c create mode 100644 08-debugging/testee.asm diff --git a/08-debugging/Makefile b/08-debugging/Makefile new file mode 100644 index 0000000..a139d69 --- /dev/null +++ b/08-debugging/Makefile @@ -0,0 +1,17 @@ + +all: test testee + +test: test.o + gcc $^ -o $@ -g + +test.o: test.c + gcc -c $^ -g + +testee: testee.o + ld $^ -o $@ + +testee.o: testee.asm + nasm -felf64 $^ -o $@ -g + +clean: + rm *.o test *.gch diff --git a/08-debugging/test.c b/08-debugging/test.c new file mode 100644 index 0000000..86afea6 --- /dev/null +++ b/08-debugging/test.c @@ -0,0 +1,40 @@ +#include +#include +#include +#include +#include +#include +#include + +#define DONT_CARE 0 + +int stats; +struct user_regs_struct regs; + +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) + { + printf(" -- parrent\n"); + for (int i = 0; i < 4; i++) + { + waitpid(pid, &stats, 0); + printf("____PARENT_STAT: %d____\n", stats); + ptrace(PTRACE_GETREGS, pid, DONT_CARE, ®s); + printf("rax = %llu\n", regs.rax); + ptrace(PTRACE_SINGLESTEP, pid, DONT_CARE, DONT_CARE); + } + printf("____AFTER_TRACE_PARRENT____\n"); + } + return 0; +} diff --git a/08-debugging/testee.asm b/08-debugging/testee.asm new file mode 100644 index 0000000..db63d56 --- /dev/null +++ b/08-debugging/testee.asm @@ -0,0 +1,21 @@ +global _start + +section .data + msg: db "I'm alive", `\n`, 0 + msg_len equ $-msg + +section .text +_start: + xor rax, rax, + add rax, 1 + add rax, 12 + + mov rax, 1 + mov rdi, 1 + mov rsi, msg + mov rdx, msg_len + syscall + + mov rax, 60 + mov rdi, 0 + syscall