7.5 — Using a debugger
Read one box at a time. No rush.
What is a debugger?#
A debugger lets you pause your program and look inside it while it runs. It's like a slow-motion replay.
Every IDE has one: Visual Studio, VS Code, CLion, Xcode.
Breakpoints#
A breakpoint is a stop sign on a line. Click in the margin next to a line number (a red dot appears). Then start with debugging (F5 in most IDEs).
The program runs until it reaches that line, then pauses.
Stepping#
While paused, you can move one line at a time:
| Action | Usual key | What it does |
|---|---|---|
| Step over | F10 | Run this line, go to the next one. |
| Step into | F11 | If this line calls a function, go inside it. |
| Step out | Shift + F11 | Finish this function, go back to the caller. |
| Continue | F5 | Run until the next breakpoint. |
Watching values#
While paused, hover your mouse over a variable to see its value. Or use the Watch / Locals window to see all of them at once.
Key idea
The debugger shows you what your program is actually doing, not what you think it's doing. That gap is where the bug lives.
Tip: press ← / → to move between lessons, / to search.