Microsoft KB Archive/326616

= BUG: The Visual C++ .NET or Visual C++ 2005 debugger cannot display std::string and std::wstring variables correctly =

Article ID: 326616

Article Last Modified on 1/12/2006

-

APPLIES TO


 * Microsoft Visual C++ 2005 Express Edition
 * Microsoft Visual C++ .NET 2002 Standard Edition

-



This article was previously published under Q326616



SYMPTOMS
The debugger may not display values appropriately for the following strings:
 * std::string variables, if the length of the string is greater than 15 characters.
 * std::wstring variables, if the length of the string is less than 15 characters.



CAUSE
The std::string or std::wstring variable is stored as static buffer if the length is less than 15 characters. If the length of the string is greater than 15 characters, the string is stored as a pointer to memory.

You can modify the Autoexp.dat file to control the debugger display of std::string variable. The _Bx._Buf member is used to specify the std::string stored as static buffer. The _Bx._Ptr member is used to specify that std::string is stored as a pointer to memory. When the _Bx._Ptr member is not specified for std::string in autoexp.dat file, the debugger does not display the std::string variables that have length greater than 15 characters. When _Bx._Buf member is not specified for std::wstring in autoexp.dat file, the debugger does not display the std::wstring variables that have length less than 15 characters.



RESOLUTION
The Debugger component that displays variable values is known as Expression Evaluator (EE). One instance of EE handles the native code, and the other instance handles the managed code. The Autoexp.dat file provides customization for the native EE, and the Mcee_mc.dat file provides customization of managed EE. To resolve this problem, modify the Autoexp.dat file.

To modify the Autoexp.dat file, follow these steps:  Open Notepad or any other text editor. Open the Autoexp.dat file from the c:\Program Files\Microsoft Visual Studio .NET\Common7\Packages\Debugger folder. In the Autoexp.dat file, locate the following lines:   std::basic_string=<_Bx._Buf>   std::basic_string=<_Bx._Ptr> </li>  std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> >=<_Bx._Ptr> </li></ul> </li> Replace the lines that you located in step 3 with the following lines: <ul>  std::basic_string<char,std::char_traits ,std::allocator >= _Buf=<_Bx._Buf> _Ptr= <_Bx._Ptr> </li>  std::basic_string<unsigned short,std::char_traits ,std::allocator >=_Buf=<_Bx._Buf> _Ptr= <_Bx._Ptr> </li>  std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> >=<_Bx._Buf> _Ptr= <_Bx._Ptr> </li></ul> </li></ol>

<div class="status_section">

STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.

<div class="moreinformation_section">

Steps to Reproduce the Behavior
<ol> Create a new Visual C++ Win32 project: <ol style="list-style-type: lower-alpha;"> On the File menu, click New.</li> Under Project Types, click Visual C++ Projects, and then click Win32 Project in Templates.

Note In Visual Studio 2005, Visual C++ Projects is changed to Visual C++.</li> Name the project LongStringDemo .</li> In the Win32 Application Wizard, click Application Settings, and then select Application Type as Console Application.</li> Under Additional Options, click to select the Empty Project check box, and then click Finish.</li></ol> </li> In Solution Explorer, right-click Source Files, and then click Add a new C++ file.</li> Name the file LongStringDemo.cpp .</li>  Add the following code to the LongStringDemo.cpp file: using namespace std; void main {   //Ansi String string szAnsiString; szAnsiString = &quot;c:\\Program Files\\Microsoft Visual Studio .Net&quot;;
 * 1) include

//Wide Char String wstring wszWCharString; wszWCharString = L&quot;c:\\Program Files\\Microsoft Visual Studio .Net&quot;; } </li> On the Build menu, click Build Solution.</li> On the Debug menu, click Step Into (F11) and start debugging.</li> <li>On the Debug menu, point to Windows, point to Watch, and then click watch1.</li> <li>Add the szAnsiString variable and the wszWCharString variable to the watch window. You can also watch the value by pointing to the szAnsiString or wszWCharString variable.</li> <li>In the Watch window, verify the value of szAnsiString or wszWCharString variable.</li></ol>

<div class="notice_section">

Notice
Keywords: kbdebug kbbug KB326616

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.