Debugging return values in Visual Studio
Let us suppose that we're debugging an application in Visual Studio .NET 2005. Let us also suppose that we have a method similar to the following:
Let us suppose that we had a breakpoint on the closing curly brace, and that we had reached said breakpoint during normal debugging. Let us assume also that we have no code or .pdb for the assembly containing the staple object's class definition, and thus we cannot step into it.
How would we know what value
[Tags: debugging visualstudio returnvalue hmming and hrring]
// Let us also suppose that this is good code.
public int GetFalseStapleWotsit()
{
return staple.GetWotsit(false);
}
Let us suppose that we had a breakpoint on the closing curly brace, and that we had reached said breakpoint during normal debugging. Let us assume also that we have no code or .pdb for the assembly containing the staple object's class definition, and thus we cannot step into it.
How would we know what value
staple.GetWotsit(false) had returned? There are no variables to show up in the autos, locals or watch windows, and there is nothing to hover over in the code. The only solution I have come up with so far is to put staple.GetWotsit(false) into the immediate window (Ctrl+D+I) and press enter. This calls the function again, and puts the returned value on the next line. Surely this can't be the best way. I'll just wait for a big-brain to leave me a comment to tell me exactly where I'm going wrong.[Tags: debugging visualstudio returnvalue hmming and hrring]
11 Comments:
Good question. I've been searching for an answer to the same question and ran across your post. No one's given you a suggestion in all this time?
No, I haven't had any suggestions, but then I'm hardly an A-lister!
If the value returned is a float it will be in the memory registry ST0, if it is an int, or a pointer it will be in the memory registry EAX.
In VS 2005 these values show up in the Autos when you are right click the source and choose "Go to Disassembly".
While in disassembly view, step over (F10) until just after the instruction "call Staple::GetWotsit". The value of EAX will be a pointer to the returned type, or an int/byte/float (float is in st0). Make sure you are viewing the Value in hexadecimal mode. (Right click the Value box in your watch box and check Hexadecimal display) Open up a quick watch and enter "(Foo *)0xFEDBCA09" Where Foo is the name of the returned class/struct. You can get that from the method signature. FEDBCA09 should be the value of the memory registry EAX immediately after the call assembly statement.
Cheers,
Aldur
There we go. It took nearly two years to find out, but there was a better way. Thanks Aldur.
Is there an easier way than what Aldur described?
Suppose you have the following function:
01 void foo()
02 {
03 return false;
04 }
You want to break when the function returns false. Put a breakpoint on line 04, then right click on it and select 'condition'. Copy and paste the following snippet w/o quotes: '($eax&0x000000FF)==0'. What this basically means is take the value of register eax (your return value is stored there), loose 3 most significant bytes (they are gibberish on x64 platforms) and compare the result against 0 (0=false, 1=true). Enjoy. By the way, there is a better way to do this is VS...might want to pick a book for that.
I'm just wondering why "return value" isn't an entry in the "locals" pane. I can't imagine it would be that hard to implement given everything else they can do. Nobody's found a simple way that doesn't involve peeking at registers? Is there something I can type into a watch definition to grab the return value?
I and my coworker are fairly certain that it used to show up in the "Autos" window or something, in previous versions of VS. Now in 2005 we can't find it.
This has been a known issue since VS 2003, and although it has been reported a few times Microsoft has postponed it release after release, and looks like they are not planning to fixing it in VS 2010 either.
https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=114921
In simple case like this,
you could just type staple.GetWotsit(false)
In immediate window and get the print result of return value.
In VS 2005, the return value from a function call is shown in the top line of the 'Autos' dialog. The entry starts with a bent arrow, includes the function signature and then the string 'returned'. The return value then appears in the next field.
You can 'step in' to the function you are interested in, then 'step out' and the information above will be populated into 'Autos'
Post a Comment