C++ - Debugging

Overview

Estimated time: 40–60 minutes

Find and fix issues using debuggers (gdb/lldb), strategic logging, and assertions.

Learning Objectives

  • Run and step through programs in a debugger.
  • Use asserts and logging to isolate issues.

Debuggers

# compile with -g
# gdb ./app  (Linux)
# lldb ./app (macOS)

Common Pitfalls

  • Optimizations (-O2) can reorder code; debug with -O0 when possible.