Getting a Method's Return Value in the VS Debugger

前端 未结 8 1700
迷失自我
迷失自我 2020-12-15 19:46

Is it possible to get a method\'s return value in the Visual Studio debugger, even if that value isn\'t assigned to a local variable? For example, I\'m debugging the follow

相关标签:
8条回答
  • 2020-12-15 20:06

    You can always switch to disassembler view and step through the individual instructions. The return value will be in @eax (or @rax) just before you execute the 'ret' instruction.

    0 讨论(0)
  • 2020-12-15 20:10

    No, I don't know of a way to do this. I would put a breakpoint in the caller and look at the return value there.

    0 讨论(0)
  • 2020-12-15 20:10

    You can also highlight any expression in the debugger and right-click -> quick watch. That will execute the expression (assuming it's valid) and give you the value.

    0 讨论(0)
  • 2020-12-15 20:12

    The answer of similar question out there: In VS 2013, you can add the variable $ReturnValue to the watch. It contains the actual return value from a function.

    Credit to Jesper Jensen.

    0 讨论(0)
  • 2020-12-15 20:12

    A workaround is to use a Pascal-style result variable:

    public string Foo(int valueIn)
    {
        string result;
        if (valueIn > 100)
            result = Proxy.Bar(valueIn);
        else
            result = "Not enough";
        return result;
    }
    

    This is good style in my opinion for longer functions. For very short ones like the one above it could be considered overkill, but it does get around the debugger problem.

    0 讨论(0)
  • 2020-12-15 20:16

    Visual Studio 2013 now has the ability in the Autos window to display the last value returned by a function, alleviating the need to re-execute it in the Output window or introduce a temporary variable:

    http://blogs.msdn.com/b/visualstudioalm/archive/2013/06/27/seeing-function-return-values-in-the-debugger-in-visual-studio-2013.aspx

    0 讨论(0)
提交回复
热议问题