How to know the return value at the end of a function when debugging in VS2008?

Using C # in Visual Studio 2008 and going through the function in the debugger, I get to the end of the function and with the final brace} and Iโ€™m about to return. Is there any way to know what value the function will return?

This is necessary if the return value is calculated, for example:

return (x.Func() > y.Func()); 
+4
source share
5 answers

This is a bit low, but if you switch to disassembly, you can perform one step through the instructions and see what is set for the return value. It is usually set in the @eax register.

You can put a breakpoint in the ret statement and check the case at that point if you don't want it to go through it.

+4
source

I made a commercial extension for Visual Studio called BugAid (currently in beta) that does exactly what you requested.

In your example, it will show you the following:

Statement visualization

The way this happens is that you control your code while debugging it, allowing us to retrieve the return values โ€‹โ€‹of both calls in "Func" and thus conclude whether the expression is x.Func() > y.Func() true or not.

For more information, see the related blog post .

+3
source

You can put

 (x.Func() > y.Func()) 

in the viewport to rate it and see the result. If no instructions are given

 return ValueChangesAfterEveryCall(); 

everything should be fine.

+2
source

I am still using VS 2003 with C ++, so this may or may not apply. If you use the "auto" tab (next to the "locals" and "watch" tabs), it will return the function return value after returning.

+2
source

I would recommend code refactoring to return individual functions to local variables. Thus, you yourself and others should not jump through hoops while debugging your code to figure out a specific score. Typically, this creates code that is easier to debug and therefore easier for others to understand and maintain.

 int sumOfSomething = x.Func(); int pendingSomethings = y.Func(); return (sumOfSomething > pendingSomethings); 
+1
source

Source: https://habr.com/ru/post/1277423/


All Articles