Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting a Method's Return Value in the VS Debugger

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 following code:

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

Since I'm not setting any local variables in Foo, and assuming I'm not setting a break point in whatever's calling Foo, is there a way to see what the return value is if I have a breakpoint inside of Foo (or another way)? I don't have much experience with the Autos or Intermediate windows, so I'm not sure if those are even a valid option or not.

like image 308
Bullines Avatar asked Nov 09 '09 22:11

Bullines


2 Answers

You can set a breakpoint in Foo, open the immediate window and run the following command:

? Foo(valueIn)

This will print the return value in the Immediate Window.

You can also copy the expression and paste it into the Watch window, though I would do this only if I am certain that the call has no side effects (otherwise you can get confusing results).

like image 52
Fredrik Mörk Avatar answered Sep 30 '22 00:09

Fredrik Mörk


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.

like image 34
Rob Walker Avatar answered Sep 29 '22 22:09

Rob Walker