All jobs / Embedded / hardware / Debugging
Embedded / hardware interview question · 3–5 years
A struct field changes value minutes into a run, and nothing in the code writes to it.
How do you find the writer?
The strongest answer
Put a data watchpoint on that address so the debugger halts on the write and names the culprit; where I cannot, I paint the stacks and add canaries either side and see which one is chewed
Why it works
Exactly — a hardware watchpoint hands you the writer’s stack trace, which is the whole answer in one step.
What a good answer covers
- Catch the write, do not chase the symptom.
- Data watchpoint on the address first.
- Paint stacks; read the watermark.
- Canaries show which side overran.
Answers that fall short
- Close, but not the strongest: I would set a watchpoint on the variable and let the debugger catch whoever writes to it
That is the first tool; say your fallback for when the write comes from DMA or an ISR the watchpoint cannot see. - Weak: I would add logging in every function that touches nearby data and read the trace afterwards
Logging changes the layout and the timing, and corruption usually moves the moment you do that. - Red flag: I would move the field into its own struct so nothing lands on it, and close the ticket
Moving the victim hides the symptom and leaves a loose writer to land somewhere worse next time.
Who gets asked this
More Debugging questions
- What do you log in the field when flash is tiny?
- A fleet starts resetting in the wild. First staff hour?
- What is SWD, and how does it differ from JTAG?
- A bug vanishes when you add printf. What did you learn?
- When do you reach for a logic analyser, and when for an oscilloscope?
- HardFault on Cortex-M. What do you capture before you “add a print”?
- What should a field build do on a failed assert?
- Datasheet says 400 kHz I2C; the line looks filthy at 100. What wins?