Visual Studio - How to change the return value of a method in the debugger?
For those who are looking for a solution to this in VB.NET:
It was so simple, I can't believe I did not see it : To look at the value a function will return : just place the pointer over the function's name. The value will be shown in a tool tip.
The change the value : just click on this tool tip, change the value and hit enter.
Visual Studio is very cool !
Note : I tested it in VB.NET on Visual Studio Team System 2008. Just tried using C#, but it does not work... :-(
Return values from functions are usually returned in the EAX register.
If you set a breakpoint just at the end of the function then there's a chance that changing EAX would change the return value. You can change and view any register in visual studio simply by writing its name in the watch window.
This is likely to fail if you have optimization on or even if the function is something simple like return 12
. it's probably also not going to work if you're returning something that doesn't fit in a 32 bit register.
In the least it's worth trying.
Don't think so.
You'd need to have a temp var in the callee or the caller so as to get a handle on the value to modify it in the IDE Debugger/QuickWatch window. So the simplest and fastest way to do it would be to comment existing code and make a temporary change for debug-what-if.
either
private int myMethod_1()
{
var x = 12;
return x;
}
Or
private int myMethod_2()
{
var y = someCall( someValue);
return y;
}
Don't see it worth the aggravation of 'avoiding a code change' to do this. If I FUBAR, I do a checkout and we're gold again.