Function return values live in VC watch window!
Ever felt the need to watch over return values from functions! Well I did always but unfortunately couldn’t come up with something! I was reading through one of John Robbins’ Bugslayer articles in MSDN and found an interesting tip related to seeing function parameters passed in by adding a watch statement over the ESP stack pointer variable.
So that got me thinking like “why not EAX”, huh that was easy! So this tip happens due to the tip given by one of the readers of John’s article in Bugslayer. I will put a link to that tip once I find it along with the author’s name.
Now let me tell you how the watch statement for our tip should look like…
- To watch string values returned by functions…
- To watch integer values returned by functions…
- To watch objects returned by functions…
Now you may ask why do I need this, I can always use the auto variable debug window. Well don’t forget that we are adding watch to a register (EAX), so this means even raw function call’s return value is shown here.
Let me show you a live case where you may need this. See here I’ve got four function calls which does some strange operations but return values doensn’t matter hence they are not stored. It’s just useless to store return values in temporary var just for the purpose of debugging, so above watches come handy.
DoOperationReturnBool(); // Returns bool, but returned values not stored
DoOperationReturnEnum(); // Cast EAX to appropriate enum type or int
DoOperationReturnCharPtr(); // Cast EAX to char pointer or wide char ptr
DoOperationReturnObject(); // Cast EAX to appropriate object type, I haven’t tested this but should work
I am using this these days, yet to see a drawback, tell me if you find any! Have fun debugging 🙂