Cook Computing

Visual Studio - Function Return Value In Debugger

February 29, 2012 Written by Charles Cook

While preparing for job interviews after I arrived in the US I rehearsed questions such as — how would you improve your favourite programming language — what new features would you like in your favourite IDE — and so on. As it happened I never got asked any of these questions but browsing through the Visual Studio UserVoice site I noticed that one of my desired Visual Studio enhancements is under consideration but won't make it into Visual Studio 11. This is Function return value in debugger. I've never liked having to modify code to be able to see the value being returned from a function, for example changing code like this:

string Foo()
{
    /// ...

    return Bar();
}

So that a local variable can be used to watch the return value from the call to Bar():

string Foo()
{
    /// ...

    string ret = Bar();
    return ret;
}

One of the site admins added a comment:

For those out there who have experience debugging native C++ or VB6 code, you may have used a feature where function return values are provided for you in the Autos window. Unfortunately, this functionality does not exist for managed code. While you can work around this issue by assigning the return values to a local variable, this is not as convenient because it requires modifying your code.

In managed code, it’s a lot trickier to determine what the return value of a function you’ve stepped over. We realized that we couldn’t do the right thing consistently here and so we removed the feature rather than give you incorrect results in the debugger. However, we want to bring this back for you and our CLR and Debugger teams are looking at a number potential solutions to this problem. Unfortunately this is will not be part of Visual Studio 11.

Oh well, back to using local variables for the time being, even if they result in code review comments such as "Remove unnecessary variable".