In a super simple file, I put a breakpoint at the cout line and then try to add a watch for s. Instant segmentation fault every time. Tried on multiple machines with multiple fresh downloads of codeblocks 12.11 + mingw package.
Here is test file:
#include <iostream>
#include <string>
using namespace std;
int main()
{
string s = "asdfasdf";
cout << "Ouch!" << endl;
return 0;
}
Here is debugger log:
Building to ensure sources are up-to-date
Selecting target:
Debug
Adding source dir: C:\Users\Andrew\Desktop\asdfewrwe\
Adding source dir: C:\Users\Andrew\Desktop\asdfewrwe\
Adding file: C:\Users\Andrew\Desktop\asdfewrwe\asdfewrwe.exe
Changing directory to: C:/Users/Andrew/Desktop/asdfewrwe/.
Set variable: PATH=.;C:\Users\Andrew\Desktop\CodeBlocks\MinGW\bin;C:\Users\Andrew\Desktop\CodeBlocks\MinGW;C:\Program Files (x86)\Google\Chrome\Application;C:\CodeBlocks\MinGW\bin;C:\MinGW\msys\1.0\bin;C:\Program Files (x86)\AMD APP\bin\x86_64;C:\Program Files (x86)\AMD APP\bin\x86;C:\MinGW\bin;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Java\jdk1.7.0_07\bin;C:\Program Files (x86)\Haskell\bin;C:\Program Files (x86)\Haskell Platform\2011.4.0.0\lib\extralibs\bin;C:\Program Files (x86)\Haskell Platform\2011.4.0.0\bin;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Windows\System32;C:\Windows;C:\Windows\System32\wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;c:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn;c:\Program Files\Microsoft SQL Server\100\Tools\Binn;c:\Program Files\Microsoft SQL Server\100\DTS\Binn;C:\Program Files\TIEDUC~1\TI-83P~1\UTILS;c:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE;c:\Program Files (x86)\Microsoft SQL Server\100\DTS\Binn;C:\Program Files\Perforce;C:\Program Files (x86)\Cppcheck;C:\Program Files\doxygen\bin;C:\Program Files (x86)\Google\Google Apps Sync;C:\Program Files (x86)\Google\Google Apps Migration;C:\Program Files\TortoiseHg;C:\Program Files (x86)\Subversion\bin;C:\apache-ant-1.8.4\bin;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files (x86)\QuickTime\QTSystem;C:\Program Files (x86)\AtomicParsley-win32-0.9.0;C:\Program Files (x86)\CodeSourcery\Sourcery_CodeBench_Lite_for_MIPS_ELF\bin;C:\Ruby193\bin;C:\Users\Andrew\AppData\Roaming\cabal\bin
[debug]Command-line: C:\Users\Andrew\Desktop\CodeBlocks\MINGW\bin\gdb.exe -nx -fullname -quiet -args C:/Users/Andrew/Desktop/asdfewrwe/asdfewrwe.exe
[debug]Working dir : C:\Users\Andrew\Desktop\asdfewrwe
Starting debugger: C:\Users\Andrew\Desktop\CodeBlocks\MINGW\bin\gdb.exe -nx -fullname -quiet -args C:/Users/Andrew/Desktop/asdfewrwe/asdfewrwe.exe
done
[debug]> set prompt >>>>>>cb_gdb:
Registered new type: wxString
Registered new type: STL String
Registered new type: STL Vector
Setting breakpoints
[debug]Reading symbols from C:\Users\Andrew\Desktop\asdfewrwe\asdfewrwe.exe...done.
[debug](gdb) >>>>>>cb_gdb:
[debug]> show version
[debug]GNU gdb (GDB) 7.5
[debug]Copyright (C) 2012 Free Software Foundation, Inc.
[debug]License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
[debug]This is free software: you are free to change and redistribute it.
[debug]There is NO WARRANTY, to the extent permitted by law. Type "show copying"
[debug]and "show warranty" for details.
[debug]This GDB was configured as "i686-pc-mingw32".
[debug]For bug reporting instructions, please see:
[debug]<http://www.gnu.org/software/gdb/bugs/>.
[debug]>>>>>>cb_gdb:
[debug]> set confirm off
Debugger name and version: GNU gdb (GDB) 7.5
[debug]>>>>>>cb_gdb:
[debug]> set width 0
[debug]>>>>>>cb_gdb:
[debug]> set height 0
[debug]>>>>>>cb_gdb:
[debug]> set breakpoint pending on
[debug]>>>>>>cb_gdb:
[debug]> set print asm-demangle on
[debug]>>>>>>cb_gdb:
[debug]> set unwindonsignal on
[debug]>>>>>>cb_gdb:
[debug]> set print elements 0
[debug]>>>>>>cb_gdb:
[debug]> set new-console on
[debug]>>>>>>cb_gdb:
[debug]> set disassembly-flavor att
[debug]>>>>>>cb_gdb:
[debug]> source C:\Users\Andrew\Desktop\CodeBlocks\share\codeblocks/scripts/stl-views-1.0.3.gdb
[debug]>>>>>>cb_gdb:
[debug]> directory C:/Users/Andrew/Desktop/asdfewrwe/
[debug]Source directories searched: C:/Users/Andrew/Desktop/asdfewrwe;$cdir;$cwd
[debug]>>>>>>cb_gdb:
[debug]> break "C:/Users/Andrew/Desktop/asdfewrwe/main.cpp:10"
[debug]Breakpoint 1 at 0x4013af: file C:\Users\Andrew\Desktop\asdfewrwe\main.cpp, line 10.
[debug]>>>>>>cb_gdb:
[debug]> run
[debug]Starting program: C:\Users\Andrew\Desktop\asdfewrwe\asdfewrwe.exe
Child process PID: 9860
[debug][New Thread 9860.0x17c4]
[debug]Breakpoint 1, main () at C:\Users\Andrew\Desktop\asdfewrwe\main.cpp:10
[debug]C:\Users\Andrew\Desktop\asdfewrwe\main.cpp:10:111:beg:0x4013af
[debug]>>>>>>cb_gdb:
At C:\Users\Andrew\Desktop\asdfewrwe\main.cpp:10
[debug]> whatis s
[debug]type = std::string
[debug]>>>>>>cb_gdb:
[debug]> output s.c_str()[0]@s.size()
[debug]The program being debugged was signaled while in a function called from GDB.
[debug]GDB has restored the context to what it was before the call.
[debug]To change this behavior use "set unwindonsignal off".
[debug]Evaluation of the expression containing the function
[debug](std::string::size() const) will be abandoned.
[debug]Program received signal SIGSEGV, Segmentation fault.
[debug]0x004228ba in std::string::size() const ()
[debug]>>>>>>cb_gdb:
Program received signal SIGSEGV, Segmentation fault.
In std::string::size() const () ()
[debug]> whatis s
[debug]type = std::string
[debug]>>>>>>cb_gdb:
[debug]> output s.c_str()[0]@s.size()
[debug]The program being debugged was signaled while in a function called from GDB.
[debug]GDB has restored the context to what it was before the call.
[debug]To change this behavior use "set unwindonsignal off".
[debug]Evaluation of the expression containing the function
[debug](std::string::size() const) will be abandoned.
[debug]Program received signal SIGSEGV, Segmentation fault.
[debug]0x004228ba in std::string::size() const ()
[debug]>>>>>>cb_gdb:
[debug]> bt 30
Program received signal SIGSEGV, Segmentation fault.
[debug]> bt 30
[debug]#0 main () at C:\Users\Andrew\Desktop\asdfewrwe\main.cpp:10
[debug]>>>>>>cb_gdb:#0 main () at C:\Users\Andrew\Desktop\asdfewrwe\main.cpp:10
[debug]>>>>>>cb_gdb:
I know I used to be able to watch strings, not sure what is going on. Anyone else noticed this issue? Can anyone replicate it? Any GDB guru's see anything weird in the log? Basically, should I submit a bug or is this user error?
Any idea if there is a way to disable that optimization - any flags I've tried have not seemed to help. Would like to keep using the scripts.
No such GCC option as I can see.
If you stick on using the C::B built-in scripts, you should at least explicitly use some functions of std::string, so that those functions will not be optimized out.
Looks like:
#include <iostream>
#include <string>
using namespace std;
int main()
{
string s = "asdfasdf";
// add those dummy function calls below, so that gcc 4.7.x does not remove them in final executable files.
// as they will be used in C::B debugger scripts.
s.c_str();
s.size();
cout << "Ouch!" << endl;
return 0;
}
I do not tested yet, but please note that all the member functions involved in "s.c_str()[0]@s.size()" should be explicitly called in your source code.
And on windows it also works fine with ollydbg's gdb with pretty printer enabled and TDM's gcc 4.7.1 shipped with C::B 12.11.
Well, I have different result. Today, I tried with my GDB (http://forums.codeblocks.org/index.php/topic,11301.msg77000.html#msg77000) and tdm's gcc 4.7.1sjlj. But I receive the segfault like:
Selecting target:
Debug
Adding source dir: E:\code\cb\test_code\mortenr2012-01-15\
Adding source dir: E:\code\cb\test_code\mortenr2012-01-15\
Adding file: E:\code\cb\test_code\mortenr2012-01-15\bin\Debug\mortenr2012-01-15.exe
Changing directory to: E:/code/cb/test_code/mortenr2012-01-15/.
Set variable: PATH=.;E:\code\gcc\tdm471sjlj\bin;E:\code\gcc\tdm471sjlj;E:\code\gcc\PCXMinGW463\bin;E:\code\gcc\PCXMinGW463;E:\code\common_bin;D:\Program Files\TortoiseSVN\bin;C:\Program Files\SlikSvn\bin;E:\code\opencv\2.4.3\mingw\bin
[debug]Command-line: E:\code\gcc\PCXMinGW463\bin\gdb.exe -nx -fullname -quiet -args E:/code/cb/test_code/mortenr2012-01-15/bin/Debug/mortenr2012-01-15.exe
[debug]Working dir : E:\code\cb\test_code\mortenr2012-01-15
Starting debugger: E:\code\gcc\PCXMinGW463\bin\gdb.exe -nx -fullname -quiet -args E:/code/cb/test_code/mortenr2012-01-15/bin/Debug/mortenr2012-01-15.exe
done
[debug]> set prompt >>>>>>cb_gdb:
Registered new type: wxString
Registered new type: STL String
Registered new type: STL Vector
Setting breakpoints
[debug]Reading symbols from E:\code\cb\test_code\mortenr2012-01-15\bin\Debug\mortenr2012-01-15.exe...
[debug]done.
[debug](gdb)
[debug]>>>>>>cb_gdb:
[debug]> show version
[debug]GNU gdb (GDB) 7.5.50.20130204-cvs
[debug]Copyright (C) 2013 Free Software Foundation, Inc.
[debug]License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
[debug]This is free software: you are free to change and redistribute it.
[debug]There is NO WARRANTY, to the extent permitted by law. Type "show copying"
[debug]and "show warranty" for details.
[debug]This GDB was configured as "mingw32".
[debug]For bug reporting instructions, please see:
[debug]<http://www.gnu.org/software/gdb/bugs/>.
[debug]>>>>>>cb_gdb:
[debug]> set confirm off
Debugger name and version: GNU gdb (GDB) 7.5.50.20130204-cvs
[debug]>>>>>>cb_gdb:
[debug]> set width 0
[debug]>>>>>>cb_gdb:
[debug]> set height 0
[debug]>>>>>>cb_gdb:
[debug]> set breakpoint pending on
[debug]>>>>>>cb_gdb:
[debug]> set print asm-demangle on
[debug]>>>>>>cb_gdb:
[debug]> set unwindonsignal on
[debug]>>>>>>cb_gdb:
[debug]> set print elements 0
[debug]>>>>>>cb_gdb:
[debug]> set new-console on
[debug]>>>>>>cb_gdb:
[debug]> set disassembly-flavor att
[debug]>>>>>>cb_gdb:
[debug]> catch throw
[debug]Catchpoint 1 (throw)
[debug]>>>>>>cb_gdb:
[debug]> source E:\code\cb\CodeBlocksUnofficial\share\codeblocks/scripts/stl-views-1.0.3.gdb
[debug]>>>>>>cb_gdb:
[debug]> source E:\code\gcc\PCXMinGW463\bin\my.gdb
[debug]>>>>>>cb_gdb:
[debug]> directory E:/code/cb/test_code/mortenr2012-01-15/
[debug]Source directories searched: E:/code/cb/test_code/mortenr2012-01-15;$cdir;$cwd
[debug]>>>>>>cb_gdb:
[debug]> break "E:/code/cb/test_code/mortenr2012-01-15/main.cpp:10"
[debug]Breakpoint 2 at 0x4013af: file E:\code\cb\test_code\mortenr2012-01-15\main.cpp, line 10.
[debug]>>>>>>cb_gdb:
[debug]> run
[debug]Starting program: E:\code\cb\test_code\mortenr2012-01-15\bin\Debug\mortenr2012-01-15.exe
Child process PID: 1964
[debug][New Thread 1964.0x94c]
[debug]Breakpoint 2, main () at E:\code\cb\test_code\mortenr2012-01-15\main.cpp:10
[debug]E:\code\cb\test_code\mortenr2012-01-15\main.cpp:10:111:beg:0x4013af
[debug]>>>>>>cb_gdb:
At E:\code\cb\test_code\mortenr2012-01-15\main.cpp:10
[debug]> whatis s
[debug]type = std::string
[debug]>>>>>>cb_gdb:
[debug]> output s.c_str()[0]@s.size()
[debug]The program being debugged was signaled while in a function called from GDB.
[debug]GDB has restored the context to what it was before the call.
[debug]To change this behavior use "set unwindonsignal off".
[debug]Evaluation of the expression containing the function
[debug](std::string::size() const) will be abandoned.
[debug]Program received signal SIGSEGV, Segmentation fault.
[debug]0x004228da in std::string::size() const ()
[debug]>>>>>>cb_gdb:
[debug]> bt 30
Program received signal SIGSEGV, Segmentation fault.
In std::string::size() const () ()
[debug]> bt 30
[debug]#0 main () at E:\code\cb\test_code\mortenr2012-01-15\main.cpp:10
[debug]>>>>>>cb_gdb:#0 main () at E:\code\cb\test_code\mortenr2012-01-15\main.cpp:10
[debug]> whatis s
[debug]>>>>>>cb_gdb:
[debug]> output s
[debug]type = std::string
[debug]>>>>>>cb_gdb:
[debug]> bt 30
[debug]"asdfasdf">>>>>>cb_gdb:#0 main () at E:\code\cb\test_code\mortenr2012-01-15\main.cpp:10
[debug]>>>>>>cb_gdb:
.
I try another newer build on GDB CVS 2013-03-02, but same segfault.