PRB: Cannot View Unicode Strings in the Watch Window (123465)



The information in this article applies to:

  • The Integrated Debugger, when used with:
    • Microsoft Visual C++, 32-bit Editions 2.0

This article was previously published under Q123465

SYMPTOMS

When trying to watch a Unicode string in the Watch window, you see only the first byte, or it is displayed incorrectly.

CAUSE

Making the debugger "Unicode aware" at the display level involves the complicated task of setting and using locales and fonts properly. This is especially difficult if they are not the ones currently in use. This functionality has not yet been implemented.

RESOLUTION

You can use the 'm' format symbol to see the first eight characters of a string, or you could use the 'ma' format symbol to see the first 32 characters. For example, if you have a declaration in your code like this:
   wchar_t *pStr = L"Some string";
				
Adding the expression pStr,m to the Watch window results in a memory dump of the first 16 bytes, immediately followed by the ASCII equivalent, similar to this:
   S.o.m.e. .s.t.r.
				
The periods are place holders for null bytes, which show up behind their corresponding characters because wchar_t's are defined as two-byte unsigned shorts, whose bytes are thus reversed in memory. (This is why only the first character 'S' would be displayed by default in the example above. The debugger sees the null byte following the 'S' and assumes it is the string terminator.)

This method will obviously work only with short strings. As an alternative, you can open up the memory window and point it to the starting address of your string. Note that dragging or dropping the string's address from the Watch window to the Memory window makes this much easier.

MORE INFORMATION

For future versions, Microsoft is considering ways to allow watching Unicode strings directly using the current locale.

Modification Type:MajorLast Reviewed:10/17/2003
Keywords:kbBug kbDebug kbdisplay kbide kbprb KB123465