Sunday, February 8, 2009

[VC++] Visual Studio Debugger tips for viewing string pointers

If you add a string pointer to debug watch window what you can see is the memory location pointed and not the string itself. In order to view the string data we may need to place format specifier with the variable name in watch window.

Add following with variable name in watch window
,s for an simple null-terminated string
,s8 for a UTF-8 string
,su for a Unicode string

The memory operators can be used to display up to 64 bytes of memory in the preview line, as bytes, words, dwords, quads, or ascii characters
,mb bytes
,mw words
,md dwords
,mq quads
,ma ASCII

Also we can use ,wc ,wm and ,hr to view data as a window class, window message, and HRESULT respectively. See the below snapshot demonstrating how to use these operators in watch window.

For viewing UNICODE string in the watch/quick watch you can either ,su (I specified before) or can check the Display unicode strings check box in the Tools->Options->Debug tab

No comments: