VS Code: Data Breakpoints and Watchpoints

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.

Data Breakpoints in VS Code

Embedded Target

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

NXP LPC55S16-EVK

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
Context Menu on Variables to break on date 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):

Data 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:

Watchpoint is hit

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

info watchpoint
info watchpoint GDB command

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

2 thoughts on “VS Code: Data Breakpoints and Watchpoints

  1. 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?

    Like

Leave a reply to Erich Styger Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.