Skip to content
Learn Netverks

Lesson

Step 26/36 72% through track

debugging-basics

Debugging basics

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 basics: the syntax, patterns, and safety habits you need before advancing in C.

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

You will apply Debugging basics in contexts like: Kernels, drivers, embedded devices, and performance libraries used by other languages.

Write C in main.c with int main(), click Run on server—the dev runner compiles with cc/gcc -std=c11 and runs the binary; read stderr for compile and linker errors (LEARNING_RUNNER_ENABLED=true).

When you can explain the previous lesson's ideas without copying starter code.

C bugs often involve memory and undefined behavior. Combine compiler warnings, printf tracing, and gdb (or lldb) for interactive debugging.

gdb essentials

gcc -g main.c -o main
gdb ./main
(gdb) break main
(gdb) run
(gdb) print variable
(gdb) next

Sanitizers (local)

-fsanitize=address catches many heap overflows and use-after-free issues during development—use alongside Valgrind where available.

Important interview questions and answers

  1. Q: Segmentation fault?
    A: Invalid memory access—null deref, buffer overflow, use-after-free.
  2. Q: Why compile with -g?
    A: Maps machine code back to source lines in the debugger.

Self-check

  1. What gdb command sets a breakpoint?
  2. Name one tool that detects heap corruption.

Tip: Compile with -g -fsanitize=address,undefined during development—catches many pointer bugs before they ship.

Interview prep

Segfault causes?

Null dereference, buffer overflow, use-after-free, stack overflow—use gdb and sanitizers to locate.

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?
  • Valgrind 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