Add a 'return' pseudo variable to the Visual Studio debugger for .NET code - by Alex Angas

Status : 

  External<br /><br />
		This item may be valid but belongs to an external system out of the direct control of this product team.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.


119
0
Sign in
to vote
ID 597933 Comments
Status Closed Workarounds
Type Suggestion Repros 0
Opened 9/14/2010 10:21:40 PM
Access Restriction Public

Description

Currently there is nowhere in the debugger to find out the value returned from a method, unless it is assigned to a temporary variable first. A special 'return' pseudo variable is desired to show (and preferably change) this value. This already exists for C/C++ developers as described in point 2 here: http://www.cprogramming.com/tutorial/visual_studio_tips.html

More people requesting this at Stack Overflow: http://stackoverflow.com/questions/268048/can-i-find-out-the-return-value-before-returning-while-debugging-in-visual-studio

Related to this logged issue on Connect: https://connect.microsoft.com/VisualStudio/feedback/details/589359/when-debugging-value-function-is-returning-not-available-by-hovering
Sign in to post a comment.
Posted by Anders on 11/7/2012 at 1:17 AM
The fact that there may be extreme cases where the returned value is not be easy to extract, is no argument for skipping it in all situations.

Just like the previous writer mentions, the fundamental case is about being able to watch the value that is being returned from the method that you are currently debugging.

In the extreme cases, where the return value is uncertain, simply display a "n/a"-message...
Posted by Johan H. Nilsson on 9/21/2012 at 12:40 AM
"In managed code, it’s a lot trickier to determine what the return value of a function you’ve stepped over."

For God's sake, forget about the advanced feature of displaying the return value functions that are stepped over. This issue is about displaying the return value of the function the debugger is within.

int foo(int a)
{
return a+a*2+123;
} <-- when debugger is standing on this row add a 'result' variable to the locals window.

The lack of this feature make programmers change their coding style to:

int foo(int a)
{
int result = a+a*2+123;
return result;
}

or even worse, clean looking code like:

bool IsWithinTolerance(double value)
{
return min <= value && value <= max;
}

is replaced with the horrific:

bool IsWithinTolerance(double value)
{
if (min <= value && value <= max)
     return true;
else
     return false;
}

For Satan's sake, the debugger should not force programmers to code in a certain way.
Posted by Microsoft on 2/15/2012 at 9:23 AM
For those out there who have experience debugging native C++ or VB6 code, you may have used a feature where function return values are provided for you in the Autos window. Unfortunately, this functionality does not exist for managed code. While you can work around this issue by assigning the return values to a local variable, this is not as convenient because it requires modifying your code.
In managed code, it’s a lot trickier to determine what the return value of a function you’ve stepped over. We realized that we couldn’t do the right thing consistently here and so we removed the feature rather than give you incorrect results in the debugger. However, we want to bring this back for you and our CLR and Debugger teams are looking at a number potential solutions to this problem. Unfortunately this is will not be part of Visual Studio 11.
Posted by Shimmy Weitzhandler on 2/11/2012 at 9:01 PM
Very compelling!
Posted by Manitra Andriamitondra on 2/7/2012 at 8:30 AM
Hello,

Just a small comment to emphase the fact that people really needs this feature :)

Manitra.
Posted by Omer Raviv on 12/13/2011 at 12:30 PM
I implemented a feature that lets you see the return value before stepping out of the method part of a commercial extension to Visual Studio called "BugAid", currently in beta. It also seeing the return value of the method calls you stepped over, and it also when you're returning the result of a linq query.

Please see my blog post on the subject: http://www.bugaidsoftware.com/2011/11/tips-for-using-statement-visualization/ and try it out for yourself!
Posted by Brian Seekford on 9/29/2011 at 9:46 AM
This would be nice to have. Since my returns migh have a linq query in them. Would like to know what is being returned without having to add temp vars.
Posted by Steve Westlake on 6/14/2011 at 3:06 AM
This is one of the best features of VS for C++. It becoming especially important in C# with the expansion of techniques like functional programming where less use is made of local variables.
Posted by Alex Angas on 10/15/2010 at 6:02 PM
Hello VS Debugger Team,

Thank you for your response, but with respect it was available for Visual Basic .NET under Visual Studio 2008. See reference: http://stackoverflow.com/questions/3238505/how-to-debug-vb-net-calculated-function-returns-without-a-return-variable "You can set the breakpoint at the End Function line and hover the cursor over the function name." Please also see screenshot linked from that post: http://img682.imageshack.us/img682/7121/debugging.gif.

So it *used* to be possible for .NET code. Could we please have it return for VB.NET and introduced for C# as well?

Thanks and regards.
Posted by Microsoft on 10/15/2010 at 5:48 PM
Hi,

This feature is available in VB 6, VBA, and C++ but unfortunately is not currently possible for .NET code. We will consider this feature for future releases of Visual Studio.

Thanks,
Visual Studio Debugger Team
Posted by Simon Lampen on 10/7/2010 at 3:54 PM
This has also been available in VB (.net, VB and VBA) as the name of the function appears as the variable that stores the return value. It would be great to have this in c# so you have read-write access to the variable before the function completely returns.