Skip to content
Learn Netverks

Lesson

Step 33/36 92% through track

debugging-cpp

Debugging C++

Last reviewed May 28, 2026 Content v20260528
Track mode
server_compiled
Means
Compiled runner
Reading
~1 min
Level
intermediate

This lesson

This lesson teaches Debugging C++: the syntax, patterns, and safety habits you need before advancing in C++.

Teams still ship Debugging C++ in C++ codebases—skipping it leaves gaps in debugging and code reviews.

You will apply Debugging C++ in contexts like: Game engines, trading systems, desktop apps, and performance-critical libraries.

Write C++ in main.cpp with int main(), click Run on server—the dev runner compiles with c++/g++ -std=c++17 -Wall and runs the binary; read template errors in stderr (LEARNING_RUNNER_ENABLED=true).

Toward the end of the track—consolidate before capstone-style review lessons.

Debugging native C++ uses compiler warnings, debug symbols, interactive debuggers (gdb/lldb), and sanitizers—essential when memory bugs do not show up as friendly stack traces like in Java.

Development habits

  • Compile with -g -Wall -Wextra
  • Run tests under AddressSanitizer and UBSan
  • Use breakpoints and backtraces in gdb/lldb
  • Reduce bug scope with logging via std::cerr

Important interview questions and answers

  1. Q: Segfault causes?
    A: Null dereference, use-after-free, buffer overflow—sanitizers and gdb pinpoint many cases.
  2. Q: -g flag?
    A: Embeds debug symbols mapping machine code to source lines.

Self-check

  1. What does AddressSanitizer detect?
  2. Why fix warnings before shipping?

Tip: Compile with -g -fsanitize=address,undefined during development—catches many lifetime bugs before production.

Interview prep

AddressSanitizer detects?

Heap buffer overflows, use-after-free, double-free, and many memory errors in test builds.

-g flag?

Embeds debug symbols for gdb/lldb to map machine code to source lines.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • gdb first step?
  • ASan when?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump