I am using CodeBlocks 13.12 rev 9.501 on windows with MinGW32 GCC 4.8.1 and GDB 4.6.1
Quite often if I try to add a watch for a std::string variable I will get a Segmentation fault. printing the value in GDB works fine.
====
Here is the output of GDB copied from codeblock
Building to ensure sources are up-to-date
Selecting target:
Debug
Adding source dir: C:\Cpp\cocos2d-x-2.2.1\projects\WorldInvasion\
Adding source dir: C:\Cpp\cocos2d-x-2.2.1\projects\WorldInvasion\
Adding file: C:\Cpp\cocos2d-x-2.2.1\projects\WorldInvasion\bin\WorldInvasion.exe
Changing directory to: C:/Cpp/cocos2d-x-2.2.1/projects/WorldInvasion/.
Set variable: PATH=.;C:\MinGW_Lib\lib;C:\MinGW\bin;C:\MinGW;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files (x86)\Intel\iCLS Client;C:\Program Files\Intel\iCLS Client;C:\Windows\System32;C:\Windows;C:\Windows\System32\wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\OpenCL SDK\3.0\bin\x86;C:\Program Files (x86)\Intel\OpenCL SDK\3.0\bin\x64;C:\Program Files\Microsoft SQL Server\110\Tools\Binn;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin;C:\Program Files (x86)\CMake 2.8\bin;C:\Python27;C:\Program Files (x86)\premake;C:\Cpp\android-ndk-r9c;C:\Cpp\adt-bundle-windows-x86_64-20131030\sdk\tools;C:\Cpp\adt-bundle-windows-x86_64-20131030\sdk\platform-tools;.
Starting debugger: C:\MinGW\bin\gdb.exe -nx -fullname -quiet -args C:/Cpp/cocos2d-x-2.2.1/projects/WorldInvasion/bin/WorldInvasion.exe
done
Registered new type: wxString
Registered new type: STL String
Registered new type: STL Vector
Setting breakpoints
Debugger name and version: GNU gdb (GDB) 7.6.1
Child process PID: 6460
At C:\Cpp\cocos2d-x-2.2.1\cocos2dx\tilemap_parallax_nodes\CCTMXXMLParser.cpp:368
> p m_sTMXFileName
$1 = {
static npos = <optimized out>,
_M_dataplus = {
<std::allocator<char>> = {
<__gnu_cxx::new_allocator<char>> = {<No data fields>}, <No data fields>},
members of std::basic_string<char, std::char_traits<char>, std::allocator<char> >::_Alloc_hider:
_M_p = 0x548d84 "C:\\Cpp\\cocos2d-x-2.2.1\\projects\\WorldInvasion\\Resources/Maps/prototypeMap.tmx"
}
}
The moment I add the same parameter
m_sTMXFileName to the list of watches I get notified of a Segmentation fault and the following output in the debugger log:
Program received signal SIGSEGV, Segmentation fault.
In libstdc++-6!_ZNKSs4sizeEv () (C:\MinGW\bin\libstdc++-6.dll)
Program received signal SIGSEGV, Segmentation fault.
Program received signal SIGSEGV, Segmentation fault.
Strangely enough I noticed that if I put the breakpoint in the same method at a different row and put a watch on the same member
m_sTMXFileName I don't get a segmentation fault however I get the wrong output displayed.
You can see in my screenshot here:
http://postimg.org/image/pf98r01r9/ I'm on a breakpoint in line 366. In my watches frame the value of m_sTMXFileName is something completely wrong. And just below in the GDB pane you can see a print of
m_sTMXFileName with the correct value.
The Segmentation fault happens if I put the breakpoint on line 368 in the same example (basically the next statement)
The strange wrong value that the watch is reporting is actually the value of a local string variable on the stack 'externalTilesetFilename' which is defined about two lines above..
Segmentation faults and weird results in the watch frame happen to me all the time when I work with CodeBlocks (GDB always shows correct values) however when I try to build simple example to reproduce this it does not happen
Any help will be appreciated