Data Breakpoints

Brad Sullivan

This blog post is part of a series on breakpoints in the Visual Studio debugger and has been updated to reflect the experience of using Visual Studio 2015. If you are interested in details about setting data breakpoints using earlier versions of Visual Studio please see the MSDN Documentation.

Data breakpoints are a powerful feature that is currently available to C++ developers. Data breakpoints allow you to stop execution when a particular piece of memory has changed. This can be very useful for solving corruption issues.

To demonstrate this feature, we will use our C++ example.  Looking at our code we’ve noticed that the Result of PrintObject is not correct. It is giving us a result of 27, but we believe that the result should be 32.


To investigate this, we set a breakpoint in the PrintObject function and inspect the values that it is summing.


When we inspect this we can see that the value of pObj1->getMyInt() is 5, but it was 10 when we created the object. When did this change? We can set a data breakpoint to find out.

To do this, first we will set a breakpoint in the constructor of the object to get the location of m_myint.


At this point we can see that the value is still 10. We can also look at the address by entering “&m_myint”. Next in the Breakpoints windows, we click on New-> Data Breakpoint…

Then in the resulting dialog, we enter the address of the m_myint that we see in the Watch window since it is the variable we want to watch. We could also simply enter “&m_myint” like we did in the Watch window to input that address here. We select the Bytes to be 4 since we are looking at a 4-byte integer.

Then you can see the new data breakpoint in the Breakpoints window.


When I continue the execution of the program, I see the following dialog.


And I am taken to the source code so that I can see where m_myint has changed.




Over the past week, we have posted about all the kinds of breakpoints that you can use in Visual Studio and how they are helpful.

We would love to hear your feedback about the breakpoints experience in Visual Studio. How else do you use breakpoints? What other breakpoint functionality would you like to see in the future?  Please tell us more in the comments below, on our MSDN forum, on our User Voice Site, or through Visual Studio’s Send-a-Smile.


Discussion is closed.

Feedback usabilla icon