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 / GoalGDB CommandLLDB Command
Launch Executablegdb ./applldb ./app
Set Breakpoint at Linebreak main.c:42breakpoint set --file main.c --line 42 (or b main.c:42)
Set Breakpoint at Functionbreak my_functionb my_function
Start / Run Programrun arg1 arg2process launch -- arg1 arg2 (or r)
Continue Executioncontinue (or c)continue (or c)
Step Into Functionstep (or s)step (or s)
Step Over Linenext (or n)next (or n)
Print Variable Valueprint var_name (or p var_name)frame variable var_name (or p var_name)
Show Stack Backtracebacktrace (or bt)thread backtrace (or bt)
Set Memory Watchpointwatch my_varwatchpoint 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 (-O2 or -O3) can result in missing variables or skipped lines due to inline optimizations!

[!TIP] Always compile source code with debug symbols (-g flag in gcc/clang or debug = true in Cargo) to display line numbers and variable names in debuggers.