GDB & LLDB Debugging Cheat Sheet
Quick reference guide for GDB & LLDB: Breakpoints, stepping execution, inspecting memory, watchpoints, and stack traces.
Editors & Tools
gdb
lldb
debugging
GDB (GNU Debugger) and LLDB (LLVM Debugger) are low-level command-line debuggers for C, C++, Rust, and assembly binaries.
Equivalent Commands Syntax Comparison
Table
| Action / Goal | GDB Command | LLDB Command |
|---|---|---|
| Launch Executable | gdb ./app | lldb ./app |
| Set Breakpoint at Line | break main.c:42 | breakpoint set --file main.c --line 42 (or b main.c:42) |
| Set Breakpoint at Function | break my_function | b my_function |
| Start / Run Program | run arg1 arg2 | process launch -- arg1 arg2 (or r) |
| Continue Execution | continue (or c) | continue (or c) |
| Step Into Function | step (or s) | step (or s) |
| Step Over Line | next (or n) | next (or n) |
| Print Variable Value | print var_name (or p var_name) | frame variable var_name (or p var_name) |
| Show Stack Backtrace | backtrace (or bt) | thread backtrace (or bt) |
| Set Memory Watchpoint | watch my_var | watchpoint set variable my_var |
Inspection Commands Example
bash
# GDB: Inspect 16 hex words starting at memory address
(gdb) x/16xw 0x7fffffffe000
# GDB: Print structure field
(gdb) p user->name
# LLDB: Print thread backtrace for all threads
(lldb) thread backtrace all
Common Pitfalls & Tips
[!WARNING] Debugging binaries compiled with release optimizations (
-O2or-O3) can result in missing variables or skipped lines due to inline optimizations!
[!TIP] Always compile source code with debug symbols (
-gflag in gcc/clang ordebug = truein Cargo) to display line numbers and variable names in debuggers.