C/C++ Watchpoints with Eclipse Kepler

In “Watchpoints: Data Breakpoints” I used the Eclipse based CodeWarrior to set breakpoints so the debugger stops when my application is writing or reading a certain memory location. That CodeWarrior is based on an earlier Eclipse version, and things are different in Eclipse Kepler and not so easy to find. So here is how I can use watchpoints in Eclipse Kepler:

Watchpoints in Breakpoint View

Watchpoints in Breakpoint View

While you technically *could* set a watchpoint on a local variable, it really only makes sense for a global variable (or to a global memory address). The easiest way in Eclipse Kepler is to use the Outline View and to use the ‘Toggle Watchpoint’ context menu:

Outline View to Set a Watchpoint

Outline View to Set a Watchpoint

💡 If the menu is grayed out, then your variable is not really a global variable?

In the dialog I can configure the watchpoint:

Properties for C C++ Watchpoint

Properties for C/C++ Watchpoint

It is then listed in the Breakpoints view:

Watchpoint in the breakoints view

Watchpoint in the breakoints view

It is possible to set a watchpoint for an address too: instead of using a variable name, use an immediate number for the address:

Using a Watchpoint on an Address

Using a Watchpoint on an Address

Another (hidden) way is to use watchpoints directly in the Breakpoints view using that small triangle menu:

Adding Watchpoints from Breakpoints View

Adding Watchpoints from Breakpoints View

To trigger a stop only if the variable has a certain value, I can add a condition like below:

Watchpoint condition

Watchpoint condition

This will halt the target whenever the value of that global Variable changes to 50.

Summary

Using watchpoints is a very powerful way to debug an application, as I can stop the execution on memory read/write accesses. Watchpoint support is rather hidden in Eclipse Kepler, but knowing that it exists and where watchpoints can be enabled can help :-).

Happy Watching 🙂

3 thoughts on “C/C++ Watchpoints with Eclipse Kepler

    • I don’t have much more tips about this. At least not in Eclipse Kepler, as somehow many watchpoint features seem to be broken (conditions seem not to work properly). Not sure why…

      Like

  1. Pingback: Tutorial: Catching Rogue Memory Accesses with Eclipse and GDB Watchpoints | MCU on Eclipse

What do you think?

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