Code::Blocks Forums

User forums => Help => Topic started by: ericjoe on September 15, 2015, 06:18:04 pm

Title: Trying to solve segfault due to std::string
Post by: ericjoe on September 15, 2015, 06:18:04 pm
Hi, I try to watch a variable type of string in Code Blocks and a pop-out window stating "Problem received signal SIGSEGV, Segmentation Fault" has shown up.

I have searched in the forum. The main search result is http://forums.codeblocks.org/index.php/topic,17573.0/all.html (http://forums.codeblocks.org/index.php/topic,17573.0/all.html), which leads me to http://forums.codeblocks.org/index.php/topic,11301.msg77000.html#msg77000 (http://forums.codeblocks.org/index.php/topic,11301.msg77000.html#msg77000).

From the first post written by ollydbg, I have tried to install Pretty Printers on CodeBlocks from http://wiki.codeblocks.org/index.php?title=Pretty_Printers (http://wiki.codeblocks.org/index.php?title=Pretty_Printers).

Problem happens when I perform the steps in "Test with GDB".

1) I open gdb.exe and run
Code
(gdb) python print sys.version
. It works well. I can see the python version.
2) I create a GDB Command File to enable the printer and save it as pp.gdb. I keep pp.gdb in "C:\Program Files\CodeBlocks\MinGW\mingw32\bin".
3) When I run
Code
(gdb) source C:\Program Files\CodeBlocks\MinGW\mingw32\bin\pp.gdb
, a list of statement is shown. You can refer to the image below:
(http://s10.postimg.org/ccpy3h0uh/python_error.png)
4) I link the Pretty Printers to the Code Blocks. I add the
Code
source C:\Program Files\CodeBlocks\MinGW\mingw32\bin\pp.gdb
in Codeblocks->Settings->Debugger->Default->Debugger initialization commands.
5) I also Disable Codeblocks handling of watch value from the location below: Codeblocks->Settings->Debugger->Default->Enable Watch Scripts = Unchecked.

When I debug and watch a string variable, I still get the pop-out window with the same error message with Enabled Watch Scripts checked and unchecked.

Here is the message from the Debugger:
Code
Building to ensure sources are up-to-date
Selecting target:
Debug
Adding source dir: C:\Working_Place_Joe\MERIT_Black_Box\Latest_Build_09012012\
Adding source dir: C:\Working_Place_Joe\MERIT_Black_Box\Latest_Build_09012012\
Adding file: C:\Working_Place_Joe\MERIT_Black_Box\Latest_Build_09012012\bin\Debug\MERIT.exe
Changing directory to: C:/Working_Place_Joe/MERIT_Black_Box/Latest_Build_09012012/.
Set variable: PATH=.;C:\Program Files\CodeBlocks\lib;C:\boost_1_47_0\libs;C:\Program Files\CodeBlocks\MinGW\bin;C:\Program Files\CodeBlocks\MinGW;C:\Windows\System32;C:\Windows;C:\Windows\System32\wbem;C:\Windows\System32\WindowsPowerShell\v1.0;c:\Program Files\Microsoft SQL Server\90\Tools\Binn;C:\Program Files\Microsoft\Web Platform Installer;C:\Program Files\Microsoft ASP.NET\ASP.NET Web Pages\v1.0;C:\Program Files\Microsoft SQL Server\110\Tools\Binn;c:\Program Files\Microsoft SQL Server\100\Tools\Binn;c:\Program Files\Microsoft SQL Server\100\DTS\Binn;C:\Program Files\Microsoft SQL Server\120\Tools\Binn;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn;C:\Program Files\Microsoft SQL Server\120\DTS\Binn;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\ManagementStudio;C:\Windows\Microsoft.NET\Framework\v4.0.30319;C:\Program Files\Windows Kits\8.1\Windows Performance Toolkit;C:\Program Files\InstallAware X2;C:\Windows\System32\config\systemprofile\.dnx\bin;C:\Program Files\Microsoft DNX\Dnvm;C:\Program Files\Skype\Phone;C:\Program Files\CrSSL\bin;C:\Qt\Qt5.3.2\5.3\mingw482_32\bin;C:\Program Files\CodeBlocks\boost-jam-3.1.18-1-ntx86;C:\boost-jam-3.1.18-1-ntx86
Starting debugger: C:\Program Files\CodeBlocks\MINGW\bin\gdb.exe -nx -fullname  -quiet  -args C:/Working_Place_Joe/MERIT_Black_Box/Latest_Build_09012012/bin/Debug/MERIT.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.5
Child process PID: 33900
At C:\Working_Place_Joe\MERIT_Black_Box\Latest_Build_09012012\QRAModel.cpp:192
Program received signal SIGSEGV, Segmentation fault.
In std::string::size() const () ()
Program received signal SIGSEGV, Segmentation fault.
Program received signal SIGSEGV, Segmentation fault.

Question:
1) What mistakes I have made in setting up Pretty Printer?
2) How do I resolve "Problem received signal SIGSEGV, Segmentation Fault" from http://forums.codeblocks.org/index.php/topic,11301.msg77000.html#msg77000 (http://forums.codeblocks.org/index.php/topic,11301.msg77000.html#msg77000)?
Title: Re: Trying to solve segfault due to std::string
Post by: BlueHazzard on September 15, 2015, 10:45:19 pm
from the steps you have listed your setup should be correct, but we can't tell for sure, because the debugger doesn't come so far...
You get a segfault, this means your program accesses some wrong addresses (probably some null pointer).
To solve this you can try more ways:
1) run your program in the debugger, wait for the segfault and press the run debugger again. You should get a backtrace. With the backtrace you know where you are accessing the nullpointer
2) run your program in the debugger, wait for the segfault, type bt in the gdb console -> you should get a backtrace
3) add a break point at the beginning of your program and step until you get your segfault and backtrace...


greetings

PS. Remember af you are trying to watch a variable in the debugger, and this variable points to a wrong memory location you will also get a segfault...
Title: Re: Trying to solve segfault due to std::string
Post by: scarphin on September 15, 2015, 11:15:23 pm
What compiler are you using? From your log I see you're using a mingw 5.2.0, if you're using the 'mingw-builds' compiler, it loads pretty-printers automatically by a startup script. You can type 'info pretty-printer' in the gdb prompt to see the currently loaded pretty printers. Make sure to disable and/or delete all pretty-printer loading commands before that. Also UNcheck 'disable startup scripts (-nx)' under 'settings->debugger->gdb'.