Interactive Debugging with GDB & LLDB
🟡 Intermediate
📖 Definition
Command-line debuggers (GDB/LLDB) allow stepping through C++ code line by line, inspecting variable memory values, setting breakpoints, and examining call-stack backtraces (bt) when segmentation faults occur. Compile with -g to embed debug symbols.
💡 Code Example
# Compile with debug symbols (-g)
g++ -g -std=c++17 main.cpp -o main_debug
# Launch GDB session
gdb ./main_debug
(gdb) break main
(gdb) run
(gdb) print variable_name
(gdb) backtrace