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

Article translations Article translations
Article ID: 326616 - View products that this article applies to.
This article was previously published under Q326616
Notice
Expand all | Collapse all

On This Page

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:
  1. Open Notepad or any other text editor.
  2. Open the Autoexp.dat file from the c:\Program Files\Microsoft Visual Studio .NET\Common7\Packages\Debugger folder.
  3. In the Autoexp.dat file, locate the following lines:
    • std::basic_string<char,std::char_traits<char>,std::allocator<char> >=<_Bx._Buf>
    • std::basic_string<unsigned short,std::char_traits<unsigned short>,std::allocator<unsigned short> >=<_Bx._Ptr>
    • std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> >=<_Bx._Ptr>
  4. Replace the lines that you located in step 3 with the following lines:
    • std::basic_string<char,std::char_traits<char>,std::allocator<char> >=
      _Buf=<_Bx._Buf> _Ptr= <_Bx._Ptr>
    • std::basic_string<unsigned short,std::char_traits<unsigned short>,std::allocator<unsigned short> >=_Buf=<_Bx._Buf> _Ptr= <_Bx._Ptr>
    • std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t> >=<_Bx._Buf> _Ptr= <_Bx._Ptr>

STATUS

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

MORE INFORMATION

Steps to Reproduce the Behavior

  1. Create a new Visual C++ Win32 project:
    1. On the File menu, click New.
    2. 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++.
    3. Name the project LongStringDemo.
    4. In the Win32 Application Wizard, click Application Settings, and then select Application Type as Console Application.
    5. Under Additional Options, click to select the Empty Project check box, and then click Finish.
  2. In Solution Explorer, right-click Source Files, and then click Add a new C++ file.
  3. Name the file LongStringDemo.cpp.
  4. Add the following code to the LongStringDemo.cpp file:
    #include <string>
    using namespace std;
    void main()
    {
    	//Ansi String
    	string szAnsiString;
    	szAnsiString = "c:\\Program Files\\Microsoft Visual Studio .Net";
    
    	//Wide Char String
    	wstring wszWCharString;
    	wszWCharString = L"c:\\Program Files\\Microsoft Visual Studio .Net";
    }
    
  5. On the Build menu, click Build Solution.
  6. On the Debug menu, click Step Into (F11) and start debugging.
  7. On the Debug menu, point to Windows, point to Watch, and then click watch1.
  8. 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.
  9. In the Watch window, verify the value of szAnsiString or wszWCharString variable.

Properties

Article ID: 326616 - Last Review: January 12, 2006 - Revision: 2.0
APPLIES TO
  • Microsoft Visual C++ 2005 Express Edition
  • Microsoft Visual C++ .NET 2002 Standard Edition
Keywords: 
kbdebug kbbug KB326616

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com