Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual C++ 2010 refuses to show std::string value when debugging. Shows <Bad Ptr>

I have a strange feeling like this is a recent issue and happens on two separate computers.

When I'm debugging and trying to look at the value of an std::string from STL, it shows as the value. It says its size is 15 and capacity is some garbled huge number.

The array values themselves all say CXX0030: Error: expressions cannot be evaluated.

This is extremely frustrating and I can still access the string values while debugging if I call c_str on the string and assign it to a char * or use watch expressions if I need to, but it's very tedious and makes life very hard when debugging complicated problems for 3 days straight.

The contents other STL containers show up just fine.

This happens on multiple projects on two different computers, and I'm pretty sure I have all debugging options set for the project. No optimizations, and generating debugging info for sure.

like image 918
iseletsky Avatar asked Dec 03 '12 09:12

iseletsky


1 Answers

Had the same problem and fixed it by changing the visualizer in autoexp.dat. It's found here: "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Packages\Debugger\autoexp.dat" or somewhere similar depending on your Visual Studio and Windows version.

Changes for "std::basic_string":

replace $e._BUF_SIZE

by sizeof($e._Bx._Buf)/sizeof(char)

or sizeof($e._Bx._Buf)/sizeof(wchar_t)

https://connect.microsoft.com/VisualStudio/feedback/details/677683/std-string-incorrectly-displayed-in-debugger

like image 181
Synck Avatar answered Oct 09 '22 06:10

Synck