Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio: how do I have the debugger stop when a member variable is modified?

I have program that has a variable that should never change. However, somehow, it is being changed. Is there a way to have the debugger stop when that particular member variable is modified?

like image 446
max Avatar asked May 16 '09 00:05

max


Video Answer


2 Answers

Set a data breakpoint to stop execution whenever some variable changes.

Break on the initialization of your variable, or someplace where your variable is visible - you need to be able get its address in memory. Then, from the menus choose Debug -> New Breakpoint -> New Data Breakpoint. Enter "&var" (with var replaced by the name of your variable.)

This will break into the debugger on the exact line of code that is modifying your variable.

More documentation here:

http://msdn.microsoft.com/en-us/library/350dyxd0.aspx

like image 81
Charlie Avatar answered Oct 30 '22 12:10

Charlie


You can set conditional breakpooint at places where the variable is used.

In Visual Studio set breakpoint by pressing F9 when your cursor at the line where you want to set breakpoint.
Next, right click on the breakpoint and select Condition.
Type your condition like

n != 5

Good luck.

Here's a link from MSDN.

like image 36
Vadim Avatar answered Oct 30 '22 11:10

Vadim