Debugging & Toolchain · Interview question

When do you use logging versus a debugger like GDB?

A strong answer

They're complementary, suited to different bug classes. A debugger like GDB excels at inspecting deep state at a specific moment, you halt at a breakpoint and examine any variable, memory, register, or the call stack, so it's the tool for "what exactly is wrong here," like a crash you can backtrace or a corrupted structure you can dissect. But halting stops the world and perturbs timing, so it's poor for bugs that are about sequence and timing: races between tasks and interrupts, real-time deadline misses, intermittent protocol issues, or anything that changes when you stop the CPU (the Heisenbug problem). Logging is the opposite: it observes the flow of execution over time without stopping the program (especially with a fast, non-halting transport like RTT), so it's the right tool for timing/concurrency bugs, for capturing what led up to a rare failure, and for field diagnosis where you can't attach a debugger at all, at the cost of only seeing what you chose to log and adding some (ideally small, deferred) overhead. In practice you use both: logging to narrow down when and in what sequence something goes wrong and to monitor real-time behavior, and GDB to stop at the suspect point and examine the exact state. The decision heuristic is: state-at-a-moment → debugger; flow-and-timing-over-time, or no-halting-allowed → logging.

What a weak answer sounds like

You know the answer. Do you know what gets you dinged?

Pro breaks down the answer most candidates actually give to this question — and the specific reason an interviewer marks it down. It’s the difference between sounding correct and sounding senior, on all 472 questions.

From the lesson

printf Debugging & Logging

Where does printf go on a chip with no console, and what does it cost? Retargeting output to UART/SWO/RTT (vs slow halting semihosting), intrusiveness, and leveled, deferred, compile-gated logging.

More printf Debugging & Logging questions

Browse all 472 interview questions
When do you use logging versus a debugger like GDB? | EmbeddedPrep.io