3

I have a line of code like this

return foo(barIn);

If I place a breakpoint on the line can I inspect the returned value of foo(barIn) without stepping into foo? I can rewrite the code to

var result = foo(barIn);
return result;

but I'd like the convenience of not rewriting and not stepping away from the current code.

========== EDIT ==========

The four initial answers are interesting (thanks) but they do not actually answer my question. Let me try to be clearer.

In this method

public string functionA()
{
    return functionB();
}

is there a way in Visual Studio 2012 to place a break point on the line "return functionB();" and inspect the return value of functionB without stepping into functionB, re-running functionB, or rewriting functionA?

dumbledad
  • 16,305
  • 23
  • 120
  • 273
  • You might want to check [this](http://stackoverflow.com/questions/268048/can-i-find-out-the-return-value-before-returning-while-debugging-in-visual-studi). Visual Studio has new advancement now since VS 2013. – RBT Nov 21 '16 at 06:28

4 Answers4

1

No, you cannot meet this exact behaviour. See Can I find out the return value before returning while debugging in Visual Studio. The closest you can get is:

If foo is idempotent (i.e. it does not have any side-effects), then you can add a watch to foo(barIn).

If it does have side-effects, then put your breakpoint on the return, and then step-out (Shift+F11 by default) of the function and inspect the variable that the result of the function is assigned to.

Community
  • 1
  • 1
RB.
  • 36,301
  • 12
  • 91
  • 131
  • Yep I know I can step back out of the function (and good call on the idempotency, it isn't) but I'm after a way of gleaning the value returned by foo after foo returns before the 'return' statement passes it on. Since all four answers don't cover this case I guess (1) one cannot and (2) my question wasn't clear. I'll edit it. – dumbledad Jul 10 '12 at 16:50
  • The answer to your question is "no". I believe my answer above is the closest you can get to the functionality you are looking for. I've updated my question with an answer to the question as asked for completeness. – RB. Jul 11 '12 at 10:17
  • "no" is definitely an answer. I'll mark it now that the edits make that clear. – dumbledad Jul 12 '12 at 10:10
  • You might want to check [this](http://stackoverflow.com/questions/268048/can-i-find-out-the-return-value-before-returning-while-debugging-in-visual-studi). Visual Studio has new advancement now since VS 2013. – RBT Nov 21 '16 at 06:28
0

You can always use F11 to step into the function and then F10 to go through the function and see what it returns.

Drakkainen
  • 1,142
  • 11
  • 25
  • I know - but I was interested to see if one could do it "without stepping into foo" as I mentioned in the question – dumbledad Jul 10 '12 at 16:39
0

You can add a watch or quick watch of foo(barIn) to see the result. Just highlight it and right click. There are options in the context menu while debugging. Just be careful if running that method twice causes unwanted effects compared to once.

KP.
  • 13,218
  • 3
  • 40
  • 60
0

You can see the return value in the watch window if you write foo(barIn) in there, however this will cause your foo method to be called twice and sometimes it is not what you want to happen, so getting the value to a variable and return it is the best way. You can always step into foo if you have the code.

Amiram Korach
  • 13,056
  • 3
  • 28
  • 30
  • This is what I usually end up doing, it just seems strange that you cannot intercept the result of foo after its call and before the return in the debugger. – dumbledad Jul 10 '12 at 16:41