I'm interested in tips and tricks regarding debugging a C/C++ project in Visual Studio's debugger. I recently found out that if you have a pointer to a certain data type, let's say char* ptr, then you can see it as an array in the watch window using a syntax such as:
ptr,10
This will display the first 10 elements from the ptr address, in the same way as it would be displayed if the definition would be:
char ptr[10];
What other tips and tricks do you know about Visual Studio debugger?
PS: I hope this subject wasn't already discussed. Should you find a similar post, please let me know.
Some debugging / watch related tips:
Use the following in the Watch window to find out what GetLastError() would return:
@ERR,hr
If you use Visual Studio 2003 or earlier, use this watch expression to find out the length of your std::vector v:
v._Mylast-v._Myfirst
You can also list the e.g. first 5 entries with this expression:
v._Myfirst,5
This doesn't work when using STLport, and the method obsoleted in VS >= 2005 with the new expression visualizers.
If you want to see the return value of a function, look at the eax register (just enter eax in the watch window). You can even change the returned value. If it's a pointer to a string or array, you can also enter eax in the Memory window to see the underlying string.