How to Find Out the Return Value Before Returning While Debugging in Visual Studio

Can I find out the return value before returning while debugging in Visual Studio?

Not that I know of. Note that if you do add a variable, it will get removed by the compiler in release builds anyway...

Update:
This functionality has been added to VS2013.
You can see the return values in the autos windows or use $ReturnValue in the watch/immediate window.

The value can only be seen directly after returning from the function, thus the easiest way to access it is by putting a breakpoint on the function call and step over (F10) the call.


Update for VS2015: boo! unfortunately, it doesn't appear to be in VS2015 (devenv v14)

Update for VS2017: it's back. (devenv v15)

How do I get the return value while debugging?

Select the method and right-click. Select Quickwatch from the menu.

Sample Image

I'm assuming you cannot put a breakpoint within GetProcedureReport?

Getting a Method's Return Value in the VS Debugger

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).

watching return-values in Visual Studio Code

Visual Studio Code recently supported this - the returned value can be found under "Local":
Sample Image

Can I find out the return value before returning while debugging in Intellij?

There seems to be a couple ways you can do this. The first one involves setting up the breakpoint on the method signature, in your case you would setup a breakpoint on Object method(){ . This will allow you to watch for the entrance and exit of the method. I believe you have to use this in conjunction with "Watch method return values" like stated above, but I haven't been able to completely test this as it takes too long to compute. Beware, this does dramatically decrease the performance of the debugger and it will take longer to debug.

Also you can do the following manually.

  1. Setup the breakpoint on the return line.
  2. When the return line is hit, click on the return line, specifically put the cursor on the operation that you want to see, then go to Run->Evaluate Expression (or Alt-F8) and it should run the expression at that point and return what it's returning.

Note: If you create a breakpoint, there are a lot of things you can tell IDEA to do with them, such as if you break on a breakpoint, you can tell them to perform an expression and log it. You can look around with what you can do if you right-click on a breakpoint and click properties.

UPDATE:
Try this in conjunction with the first way of doing it. Don't use "Watch method return values" as it seems to slow down or freeze up the debugging session. Instead do the following

  1. Right-click on the return expression you want to see and click "Add to Watches"
  2. Next add a method breakpoint like stated above.
  3. Debug your program and your method will break on the method signature.
  4. Hit the F9 key for continue and it should break again AFTER the return expression has been computed and your return expression should be in the watch column.

Remember that method breakpoints are slower so it might take more time, a tricky way to improve this if you are noticing too much of a performance hit is by just setting the return statement breakpoint (without having a method breakpoint) and then adding the method breakpoint AFTER the return statement breakpoint hits and then continuing.

Hope this helps,

Debug return value

This was added in Visual Studio 2013:

The return value(s) get displayed in the “Autos Windows” (Debug->Windows->Autos) and you can also use the pseudo variable “$ReturnValue” in the Watch and/or Immediate window to fetch the last function’s return value.

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



Related Topics



Leave a reply



Submit