c++visual-studiodebuggingbreakpointsconditional-breakpoint

What are data breakpoints?


I just came to know that there are data breakpoints. I have worked for the last 5 years in C++ using Visual Studio, and I have never used data breakpoints.

Can someone throw some light on what data breakpoints are, when to use them and how to use them with VS?

As per my understanding we can set a data breakpoint when we want to check for changes to a variable's value. In this case, we can set a data breakpoint with a condition on the variable value.

Any other examples?


Solution

  • Definition:

    Data breakpoints allow you to break execution when the value stored at a specified memory location changes.

    From MSDN: How to: Set a Data Breakpoint:

    How to Set a Memory Change Breakpoint

    1. From the Debug Menu, choose New Breakpoint and click New Data Breakpoint

      —or—

      in the Breakpoints window Menu, click the New dropdown and choose New Data Breakpoint.

      The New Breakpoint dialog box appears.

    2. In the Address box, enter a memory address or expression that evaluates to a memory address. For example, &foo to break when the contents of variable foo change.

    3. In the Byte Count box, enter the number of bytes you want the debugger to watch. For example, if you enter 4, the debugger will watch the four bytes starting at &foo and break if any of those bytes change value.

    4. Click OK.