Welcome to MSDN Blogs Sign in | Join | Help
Data Breakpoints: Another Feature You Didn't Know About

Here’s something I didn’t know about until I saw someone use it here at Microsoft.

Data breakpoints are a nice debugger feature that let you find out when a memory address changes.

Say you have some code like this and you’re trying to figure out why the assert is being hit:

void Function()

{

      int value = 0;

 

      ...

 

      Assert( value == 0 );

}

To use a data breakpoint in Visual Studio, first add a breakpoint to the top of the function and execute the program until it’s hit. Then in the Breakpoints window (Debug -> Windows -> Breakpoints ) hit New and choose New Data Breakpoint.

Now you can add a breakpoint at a given memory address for a certain length of memory. You can either add the memory address in manually, or do like I’ve done and add a statement which executes to a memory address:

Now continue execution. When the data in value changes, the debugger will stop and you can see exactly which piece of code is changing it. This is great because it will work even if the value changes outside of the current function (which is usually the case) or if you’re watching a global variable it will break at any time during the execution of the program!

This feature has saved my butt more than once and illuminated areas of code that I didn’t know existed or would be touching my variable’s data.

Posted: Tuesday, July 24, 2007 9:08 PM by Chris Becker
Filed under:

Comments

No Comments

Leave a Comment

(required) 

(required) 

(optional)

(required) 

  
Enter Code Here: Required

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Page view tracker