Breakpoints and watchpoints, explained
A debugger is not magic: here is what happens when execution stops or a value changes.
What you will learn
After this tutorial you can explain the difference between stopping on an instruction and stopping on a memory access, and choose the right tool for a question.
Software breakpoints
A software breakpoint replaces the first byte of an instruction with a trap instruction. When execution reaches it, the CPU raises an exception and the debugger gets control. The debugger then restores the original byte so the instruction can run normally when you continue.
Use one when you know where to look: the start of a function, a branch, a line of disassembly.
Hardware breakpoints
Hardware breakpoints use the CPU’s debug registers instead of modifying code. There are only a few of them, but they work on code you cannot easily patch (for example, read-only regions). black_box exposes these through its dbg sub-crate.
Watchpoints
A watchpoint stops when memory at an address is accessed, not when an instruction is executed. A write watchpoint answers “who changed this value?” — a question a normal breakpoint cannot answer unless you already know the code path.
Watchpoints in our debugger auto-resume: after the event is recorded, the target continues instead of sitting paused. That matters when the value changes every frame — you collect an instruction trace instead of freezing the program on the first write.
Step in, step over
Once execution is stopped:
- Step in enters the function being called.
- Step over runs the call without entering it.
Both are ways of controlling granularity. Combined with the register panel and disassembly view in Muramasa, they let you follow one instruction at a time.
Try it
- Use Your first memory scan to find an address that changes.
- Set a write watchpoint on it and let the program run.
- Read the recorded instruction: which code wrote the value?
- Set a software breakpoint at that instruction and step through it once, watching the registers.
Only debug processes you own or have explicit permission to analyse.
Why this belongs in a FOSS toolkit
Nothing above requires a proprietary debugger. The techniques are documented CPU behaviour, and our tools expose them so you can learn by reading both the tutorial and the source. If a step is unclear, that is a bug in the explanation — tell us in an issue.