ashish
ashish

Reputation: 319

How to change a variable value on conditional breakpoint in visual studio 2015

Is there any way to change value of variable to on a conditional breakpoint and continue execution.

My code is like this

switch(var){ //conditional breakpoint on this line
    case 1:
    break;
...
}

I put conditional breakpoint like below (var == 0 ) || (var ==1) is true

So when this breakpoint hits, I want to change var = 2, and continue execution.

What I found: I found Action also, but it only log messages. Is there any way to executing a statement like var = 2 as Action taken on this conditional breakpoint.

I don't want to change code because building it takes hell lot of time.

Note: I am working C++ on Visual studio 2015

Upvotes: 7

Views: 4385

Answers (4)

Anton Plakhotnyk
Anton Plakhotnyk

Reputation: 391

In Log a message to Output Window write {my_variable=12345} the side effect of log output is assigning 12345 to my_variable.

Take into account that Log a message can accept and evaluate complex expressions in curly braces.

Upvotes: 11

NeutronCode
NeutronCode

Reputation: 365

This used to work, I can't seem to get it to work now. Worked excellent on loops and also good for altering values without altering the source or the code (and accidently committing it).

Conditional break point, break if true

(url = "http://localhost:1234/") != url

This works thanks to assignment always returns it's assigned value. This will never be true as url becomes localhost

Upvotes: 0

Khalil Khalaf
Khalil Khalaf

Reputation: 9397

Make sure that in Tools / Options / Debugging you have the "Enable Edit and Continue" Enabled/Checked and then you will be able to edit your code while debugging and continue without the need to rebuild or to stop execution.

More information can be found in How to: Enable and Disable Edit and Continue

Upvotes: 0

buld0zzr
buld0zzr

Reputation: 962

You can modify a variable directly in memory to change the execution flow through a quick watch (Shift+F9) or watch window in Visual Studio.

Upvotes: 0

Related Questions