Lion Cipher Lab
Compile and debug C with gcc and gdb: build, break, inspect, and read a crash
- Cyber / Security Engineer
- Beginner
- ~50 min
- Free · no account required
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
- installing gcc and gdb on Linux, macOS and Windows
- compiling C with gcc and reading its errors and warnings
- the compiler flags that matter for security work (-g, -O0, -Wall -Wextra, -std=, -fsanitize=address)
- driving gdb: break, run, next/step, print, backtrace, info locals, examining memory
- catching memory bugs with AddressSanitizer
- reading a crash and a core dump to find the faulting line
Steps in this lab
- What a compiler, a linker and a toolchain are, in one paragraph
- First, check whether you already have them (every OS)
- Linux: install the build tools and gdb with your package manager
- macOS: Command Line Tools now, Homebrew gcc/gdb only if you truly need them
- Windows: use WSL (recommended for security work), or MSYS2/MinGW-w64
- Compile your first program and watch the stages
- The flags that matter — and the reason for each
- Read a compiler error, then a warning — they are not the same thing
- Write a program that crashes on purpose (a null dereference)
- Find the crash in gdb: break, run, step, print, backtrace, info locals
- Examine memory directly with gdb's x command
- Catch a subtler bug with AddressSanitizer (a stack buffer overflow)
- When to reach for which: print, gdb, or a sanitizer
- Core dumps: what they are and where they go
- Prove it: build, run, break, and read a fault end to end
- The errors you'll actually hit, and their fixes
- What you just did — and why it matters