Lion Cipher Lab

Compile and debug C with gcc and gdb: build, break, inspect, and read a crash

Why it matters

C is the language the operating system, the network stack and most of the software you'll attack and defend is written in, and — unlike Python — it can't run until a compiler turns it into machine code and a linker stitches that together into a program. Dozens of labs on this site assume you can already do that: the stack-overflow and format-string labs, the heap-exploitation labs, the ELF-loader and write-your-own-allocator labs, every fuzzing lab, and the reverse-engineering labs all begin "compile this with `gcc -g`" and hand you to gdb. This lab is the rung under all of them. More than…

What you'll learn

Steps in this lab

  1. What a compiler, a linker and a toolchain are, in one paragraph
  2. First, check whether you already have them (every OS)
  3. Linux: install the build tools and gdb with your package manager
  4. macOS: Command Line Tools now, Homebrew gcc/gdb only if you truly need them
  5. Windows: use WSL (recommended for security work), or MSYS2/MinGW-w64
  6. Compile your first program and watch the stages
  7. The flags that matter — and the reason for each
  8. Read a compiler error, then a warning — they are not the same thing
  9. Write a program that crashes on purpose (a null dereference)
  10. Find the crash in gdb: break, run, step, print, backtrace, info locals
  11. Examine memory directly with gdb's x command
  12. Catch a subtler bug with AddressSanitizer (a stack buffer overflow)
  13. When to reach for which: print, gdb, or a sanitizer
  14. Core dumps: what they are and where they go
  15. Prove it: build, run, break, and read a fault end to end
  16. The errors you'll actually hit, and their fixes
  17. What you just did — and why it matters

Open the full interactive lab →