Debugging & Toolchain · Interview question

What's the difference between a breakpoint and a watchpoint?

A strong answer

A breakpoint stops execution when the program reaches a specific code location, when the program counter hits a given line or function address, so it answers "stop when control flow gets here," which is what you use to inspect state at a particular point in the logic. A watchpoint, also called a data breakpoint, stops when a specific memory location is accessed or changed, when a variable is written (or read, or either), so it answers "stop when this data is touched, regardless of which code does it." The distinction matters because they solve different problems: a breakpoint is for control-flow questions ("what's the state when we enter this function?"), while a watchpoint is for data questions, most powerfully "what code is corrupting this variable?", you set a watchpoint on the variable's address and the debugger halts at the exact instruction that writes it, then a backtrace reveals the culprit even if you had no idea where the bad write lived. So breakpoint = PC-reaches-address, watchpoint = data-address-is-accessed, and the watchpoint is the specialized tool for memory-corruption bugs that a breakpoint can't find because you don't know where to put it.

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

Breakpoints & Watchpoints

Stop on a line vs stop on a data change: software vs hardware breakpoints (and why flash execution forces the limited hardware kind), and watchpoints, the tool for catching memory corruption.

More Breakpoints & Watchpoints questions

Browse all 472 interview questions
What's the difference between a breakpoint and a watchpoint? | EmbeddedPrep.io