0

If stepping through using a debugger and I have a block of code like the following

return int Foo()
{
    return Bar();
}

Is there any way in the debugger to find out the result of Bar before Foo returns with the result?

Scott Chamberlain
  • 124,994
  • 33
  • 282
  • 431
  • Did not see that one, it wont let me delete the question now, so I had to vote to close my own question as duplicate. – Scott Chamberlain Jun 01 '13 at 02:06
  • [There's some feedback here](http://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/2206747-function-return-value-in-debugger) strongly suggesting that the feature you're looking for didn't make it into 2012 either, which unfortunately leaves you with workarounds. – anton.burger Jun 01 '13 at 02:16
  • It looks like this feature is [here in VS2013](http://blogs.msdn.com/b/visualstudioalm/archive/2013/06/27/seeing-function-return-values-in-the-debugger-in-visual-studio-2013.aspx). – anton.burger Jun 28 '13 at 07:41

3 Answers3

2

If Bar() has no side effects, just evaluate (run) it in a quick watch window.

Otherwise, if it does have side effects, if you can rewrite the code, write it as

return int Foo()
{
    var bar = Bar();
    return bar;
}

and put a break point on the return.

Charles Bretana
  • 143,358
  • 22
  • 150
  • 216
0

would consider using Command Window? This can be found on

View => Other Windows => Command Window

and type

? Bar()

you will be able to see the result of Bar() without even stepping Foo()

John Woo
  • 258,903
  • 69
  • 498
  • 492
0

You could call Bar() and store the result in a variable and then simply output it. Otherwise you could add a breakpoint and use visual studio's step over functionality to go through the code and variable values line by line.

Andrew Cumming
  • 965
  • 6
  • 14
  • I know how to solve it with saving it first, and that is what I normally do to correct the code like that. However I don't understand, using step over it goes from `Bar()` not being executed to returned from Foo in one step. – Scott Chamberlain Jun 01 '13 at 02:04