There are many cases where setting a breakpoint on a line of code does not help much. Cases like data or variables get modified from somewhere. That can be data in a linked list somewhere, and all what I have found out so far that it gets changed or corrupted. But I do not know what piece of code is responsible for it.
The solution for such problems are ‘data breakpoints’ or ‘watchpoints‘. Still, not many developers seem to be aware of watchpoints? They are incredibly helpful. And VS Code has at least some basic support for it.

Embedded Target
Point in case: I had to find a defect in a firmware for the NXP LPC55S16:

It took me a while to find out how to use watchpoints in that project using VS Code.
VS Code Watchpoints
I have to use the context menu on a variable inside the VARIABLES pane: There I can choose between
- Break on Value Read: Break for value read
- Break on Value Change: Break for value write
- Break on Value Access: Break on variable read or write

It only is supported by GDB based debug probes, and is for example working with cortex-debug by marus.
Breakpoint List
After setting a data breakpoint, it shows up in the Breakpoints list with a red hexagon (very hard to distinguish from the normal red circle for breakpoints):

The context menu on that view can be used to delete the breakpoint (or in this case, the watchpoint).
Debug Console
If the watchpoint condition triggers, it halts the debugger and I can see the reason in the Debug Console:

I can use the GDB command-line in the Debug Console to inspect the watchpoints:
info watchpoint

Summary
With this, I can find out who is accessing/reading/writing a memory location or variable. Just keep in mind that the hardware resources for watchpoints are limited, so best if you just use few or only one.
Happy watching 🙂
Links
- Watchpoints: Data Breakpoints
- Tutorial: Catching Rogue Memory Accesses with ARM Watchpoint Comparators and Instruction Trace
- VS Code: Data Breakpoints: https://code.visualstudio.com/Docs/editor/debugging#_data-breakpoints
- Cortex-Debug Extension: https://github.com/Marus/cortex-debug
- GDB: working with watchpoints: https://sourceware.org/gdb/download/onlinedocs/gdb/Set-Watchpoints.html
This blog is called ‘mcuoneclipse’ and I dont care for VS code.
Is it possible to get your update mails without news about VS code?
LikeLike
Hi Florian,
I don’t think WordPress supports such a filtering.
Erich
LikeLike