Lion Cipher Lab

Build your own mini-strace from scratch with ptrace()

Why it matters

strace, ltrace, gdb, and every Linux debugger and sandbox you will ever use are built on ONE system call: ptrace(2), 'process trace'. ptrace lets one process (the tracer) observe and control another (the tracee) — stop it, read and write its registers and memory, and single-step or run-to-next-syscall. Building a miniature strace with it yourself is the fastest way to turn 'debuggers are magic' into 'debuggers are a fork, a ptrace request, and a loop'. Here is the whole trick you will implement and see work: you fork a child; the child calls PTRACE_TRACEME ("parent, you may trace me") and…

What you'll learn

Steps in this lab

  1. The one idea: one process can drive another, and the kernel hands you its registers
  2. Get a Linux x86-64 shell and a C compiler
  3. The design: fork, TRACEME in the child, PTRACE_SYSCALL loop in the parent
  4. Write the tracer: minitrace.c
  5. Run it — and see the entry/exit double stop with your own eyes
  6. Level up: reach into the tracee's memory and pull out a string
  7. The named failure modes (read this before you trust your own tracer)
  8. The judgment: when to hand-roll ptrace, and when to just run strace

Open the full interactive lab →