Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS debugging and watching a variable for changes

I have a property inside a class that is getting changed by something. The only place I change the value of this code is a line that looks like this:

pushpin.Position.Altitude = -31;

During visual studio debugging, is there a way to watch .Altitude for any changes made, preferably it breaks at the assignment statement that changes the value.

If this is the correct way to track down this problem, could I have a step-by-step tutorial/instruction on how to do this?

Thanks.

like image 362
Shawn Mclean Avatar asked Mar 27 '10 18:03

Shawn Mclean


People also ask

How can I see the variable value while debugging in Visual Studio?

When stopped in the debugger hover the mouse cursor over the variable you want to look at. The DataTip will appear showing you the value of that variable. If the variable is an object, you can expand the object by clicking on the arrow to see the elements of that object.

Is it possible to change the value of a variable while debugging?

Yes u can if you have the authorization: while debugging do a doubleclick on the variable, the system'll show the name and the value of the variable, change the value and press CHANGE icon.


2 Answers

If this is a property then you can do this by adding a breakpoint to the set method of the property. Putting the cursor in the set statement and hit F9 will create the break point.

If this is a field then there's no way to watch this directly. Breaking when a field changes a value is a supported operation in C++, known as data break points, but is not supported in the CLR. The best work around is to convert the field to a property temporarily and break on the set statement.

EDIT

Updating based on OP saying it's a 3rd party DLL.

In this case you want to use the Break at Function feature of Visual Studio. The first step is to disable Just My Code.

  • Tools -> Options -> Debugger
  • Uncheck "Enable Just My Code"

Next actually set the named break point

  • Open up the break points window (Debugger -> Windows -> Break Points)
  • Click on the new button and select "Break at function"
  • Enter the name of the property. For example: Position.set_Altitude

You may need to fully qualify the name in order to get it to work

like image 83
JaredPar Avatar answered Sep 29 '22 05:09

JaredPar


You can set a conditional breakpoint by setting the bp and then right-click to specify a condition upon which to break at that line.

You can add a 'Watch' to a variable and specify to break anywhere/anytime the value changes.

like image 42
Sky Sanders Avatar answered Sep 29 '22 03:09

Sky Sanders