Author Topic: GDP debugger, string, and segmentation errors  (Read 4556 times)

Offline Forat

  • Single posting newcomer
  • *
  • Posts: 3
GDP debugger, string, and segmentation errors
« on: April 15, 2018, 03:00:05 pm »
Dear Code::Block community,

I using Code::Block 16.02 at my work, and 17.12 at my house.

and I am writing C++ programs, and I am creating a Code Block Project (.cbp) and using the debugger (GDP) to debug the program.

Alot of the times when I am using the string class, I get a segmentation error when debugging, it happens so random and so frequent.

I know the reason for that is because GDP debuggers have a problem with strings, but what is the solution, how can I remove the segmentation error.

Edit1
this is the code that caused Segmentation Error

Code
#include <iostream>

using namespace std;

int main()
{
    cout << "Hello world!" << endl;

    string s1("Hi how are you");

    for(int i = 0;i<s1.size();i++)
        cout<<s1.at(i)<<endl;

    return 0;
}
« Last Edit: April 15, 2018, 03:46:32 pm by Forat »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: GDP debugger, string, and segmentation errors
« Reply #1 on: April 15, 2018, 03:17:58 pm »
First: It is gdb most probably and not gbp, isn't it?
Second: Can you post the full debugger log from one such crash? Full logging must be enabled in the debugger settings.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Forat

  • Single posting newcomer
  • *
  • Posts: 3
Re: GDP debugger, string, and segmentation errors
« Reply #2 on: April 15, 2018, 03:41:55 pm »
First: It is gdb most probably and not gbp, isn't it?
Second: Can you post the full debugger log from one such crash? Full logging must be enabled in the debugger settings.

I am not sure what do you mean by Full debugging must be enabled, but there is the log for the debugging

Code
Active debugger config: GDB/CDB debugger:Default
Building to ensure sources are up-to-date
Selecting target:
Debug
Adding source dir: C:\Users\forat.hatem\Desktop\Code\CPP\SE\
Adding source dir: C:\Users\forat.hatem\Desktop\Code\CPP\SE\
Adding file: C:\Users\forat.hatem\Desktop\Code\CPP\SE\bin\Debug\SE.exe
Changing directory to: C:/Users/forat.hatem/Desktop/Code/CPP/SE/.
Set variable: PATH=.;C:\Program Files\CodeBlocks\MinGW\bin;C:\Program Files\CodeBlocks\MinGW;C:\Program Files\Rockwell Software\RDM;C:\Program Files\Rockwell Software\RSView;C:\Program Files\Rockwell Software\RSCommon;C:\Windows\System32;C:\Windows;C:\Windows\System32\wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Program Files\Rockwell Automation\Common\Components;C:\Program Files\Common Files\Rockwell;C:\Program Files\Windows Kits\8.1\Windows Performance Toolkit
Starting debugger: C:\Program Files\CodeBlocks\MINGW\bin\gdb.exe -nx -fullname -quiet  -args C:/Users/forat.hatem/Desktop/Code/CPP/SE/bin/Debug/SE.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: 7024
At C:\Users\forat.hatem\Desktop\Code\CPP\SE\main.cpp:7
At C:\Users\forat.hatem\Desktop\Code\CPP\SE\main.cpp:9
At C:\Users\forat.hatem\Desktop\Code\CPP\SE\main.cpp:11
Program received signal SIGSEGV, Segmentation fault.
In std::string::size() const () ()
At C:\Users\forat.hatem\Desktop\Code\CPP\SE\main.cpp:12
At C:\Users\forat.hatem\Desktop\Code\CPP\SE\main.cpp:11
At C:\Users\forat.hatem\Desktop\Code\CPP\SE\main.cpp:12
At C:\Users\forat.hatem\Desktop\Code\CPP\SE\main.cpp:11
At C:\Users\forat.hatem\Desktop\Code\CPP\SE\main.cpp:12
At C:\Users\forat.hatem\Desktop\Code\CPP\SE\main.cpp:11
At C:\Users\forat.hatem\Desktop\Code\CPP\SE\main.cpp:12
At C:\Users\forat.hatem\Desktop\Code\CPP\SE\main.cpp:11
At C:\Users\forat.hatem\Desktop\Code\CPP\SE\main.cpp:12
At C:\Users\forat.hatem\Desktop\Code\CPP\SE\main.cpp:11
At C:\Users\forat.hatem\Desktop\Code\CPP\SE\main.cpp:12
At C:\Users\forat.hatem\Desktop\Code\CPP\SE\main.cpp:11
At C:\Users\forat.hatem\Desktop\Code\CPP\SE\main.cpp:12
At C:\Users\forat.hatem\Desktop\Code\CPP\SE\main.cpp:11
At C:\Users\forat.hatem\Desktop\Code\CPP\SE\main.cpp:12
At C:\Users\forat.hatem\Desktop\Code\CPP\SE\main.cpp:11
At C:\Users\forat.hatem\Desktop\Code\CPP\SE\main.cpp:12
At C:\Users\forat.hatem\Desktop\Code\CPP\SE\main.cpp:11
At C:\Users\forat.hatem\Desktop\Code\CPP\SE\main.cpp:12
At C:\Users\forat.hatem\Desktop\Code\CPP\SE\main.cpp:11
At C:\Users\forat.hatem\Desktop\Code\CPP\SE\main.cpp:12
At C:\Users\forat.hatem\Desktop\Code\CPP\SE\main.cpp:11
At C:\Users\forat.hatem\Desktop\Code\CPP\SE\main.cpp:12
At C:\Users\forat.hatem\Desktop\Code\CPP\SE\main.cpp:11
At C:\Users\forat.hatem\Desktop\Code\CPP\SE\main.cpp:12
At C:\Users\forat.hatem\Desktop\Code\CPP\SE\main.cpp:11
At C:\Users\forat.hatem\Desktop\Code\CPP\SE\main.cpp:12
At C:\Users\forat.hatem\Desktop\Code\CPP\SE\main.cpp:11
At C:\Users\forat.hatem\Desktop\Code\CPP\SE\main.cpp:14
Cannot open file: ../../../../../src/gcc-4.9.2/libgcc/unwind-sjlj.c
At ../../../../../src/gcc-4.9.2/libgcc/unwind-sjlj.c:173
Cannot open file: ../../../../../src/gcc-4.9.2/libgcc/unwind-sjlj.c
At ../../../../../src/gcc-4.9.2/libgcc/unwind-sjlj.c:174

and I will edit (edit1) my post, and add the code that caused segmentation fault.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: GDP debugger, string, and segmentation errors
« Reply #3 on: April 15, 2018, 06:04:11 pm »
Settings -> Debugger -> Common -> Full (debug) log
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Forat

  • Single posting newcomer
  • *
  • Posts: 3
Re: GDP debugger, string, and segmentation errors
« Reply #4 on: April 16, 2018, 08:50:27 am »
Settings -> Debugger -> Common -> Full (debug) log

Done that, this is the debugger log now

Code
ctive debugger config: GDB/CDB debugger:Default
Building to ensure sources are up-to-date
Selecting target:
Debug
Adding source dir: C:\Users\forat.hatem\Desktop\Code\CPP\SE\
Adding source dir: C:\Users\forat.hatem\Desktop\Code\CPP\SE\
Adding file: C:\Users\forat.hatem\Desktop\Code\CPP\SE\bin\Debug\SE.exe
Changing directory to: C:/Users/forat.hatem/Desktop/Code/CPP/SE/.
Set variable: PATH=.;C:\Program Files\CodeBlocks\MinGW\bin;C:\Program Files\CodeBlocks\MinGW;C:\Program Files\Rockwell Software\RDM;C:\Program Files\Rockwell Software\RSView;C:\Program Files\Rockwell Software\RSCommon;C:\Windows\System32;C:\Windows;C:\Windows\System32\wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Program Files\Rockwell Automation\Common\Components;C:\Program Files\Common Files\Rockwell;C:\Program Files\Windows Kits\8.1\Windows Performance Toolkit

[debug]Command-line: C:\Program Files\CodeBlocks\MINGW\bin\gdb.exe -nx -fullname -quiet  -args C:/Users/forat.hatem/Desktop/Code/CPP/SE/bin/Debug/SE.exe
[debug]Working dir : C:\Users\forat.hatem\Desktop\Code\CPP\SE

Starting debugger: C:\Program Files\CodeBlocks\MINGW\bin\gdb.exe -nx -fullname -quiet  -args C:/Users/forat.hatem/Desktop/Code/CPP/SE/bin/Debug/SE.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\forat.hatem\Desktop\Code\CPP\SE\bin\Debug\SE.exe...done.
[debug](gdb) >>>>>>cb_gdb:
[debug]> show version
[debug]GNU gdb (GDB) 7.6.1
[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.6.1

[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 C:\Program Files\CodeBlocks\share\codeblocks/scripts/stl-views-1.0.3.gdb
[debug]>>>>>>cb_gdb:
[debug]> directory C:/Users/forat.hatem/Desktop/Code/CPP/SE/
[debug]Source directories searched: C:/Users/forat.hatem/Desktop/Code/CPP/SE;$cdir;$cwd
[debug]>>>>>>cb_gdb:
[debug]> start
[debug]Temporary breakpoint 2 at 0x401385: file C:\Users\forat.hatem\Desktop\Code\CPP\SE\main.cpp, line 7.
[debug]Starting program: C:/Users/forat.hatem/Desktop/Code/CPP/SE/bin/Debug/SE.exe

Child process PID: 8072

[debug][New Thread 8072.0x1074]
[debug]Temporary breakpoint 2, main () at C:\Users\forat.hatem\Desktop\Code\CPP\SE\main.cpp:7
[debug]C:\Users\forat.hatem\Desktop\Code\CPP\SE\main.cpp:7:62:beg:0x401385
[debug]>>>>>>cb_gdb:

At C:\Users\forat.hatem\Desktop\Code\CPP\SE\main.cpp:7

[debug]> info program
[debug] Using the running image of child Thread 8072.0x1074.
[debug]Program stopped at 0x401385.
[debug]It stopped at a breakpoint that has since been deleted.
[debug]>>>>>>cb_gdb:
[debug]> info locals
[debug]s1 = {
[debug]  static npos = <optimized out>,
[debug]  _M_dataplus = {
[debug]    <std::allocator<char>> = {
[debug]      <__gnu_cxx::new_allocator<char>> = {<No data fields>}, <No data fields>},
[debug]    members of std::basic_string<char, std::char_traits<char>, std::allocator<char> >::_Alloc_hider:
[debug]    _M_p = 0xd20e04e8 <Address 0xd20e04e8 out of bounds>
[debug]  }
[debug]}
[debug]>>>>>>cb_gdb:
[debug]> info args
[debug]No arguments.
[debug]>>>>>>cb_gdb:
[debug]> whatis s1
[debug]type = std::string
[debug]>>>>>>cb_gdb:
[debug]> output s1.c_str()[0]@s1.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::c_str() const) will be abandoned.
[debug]Program received signal SIGSEGV, Segmentation fault.
[debug]0x00430880 in std::string::c_str() const ()
[debug]>>>>>>cb_gdb:
[debug]> whatis s1.at(i)

Program received signal SIGSEGV, Segmentation fault.
In std::string::c_str() const () ()

PN: couldn't add the whole log, as it exceeded 20000 characters

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: GDP debugger, string, and segmentation errors
« Reply #5 on: April 16, 2018, 11:08:29 am »
If the log is to long for the forum most it on pastebin and provide the link here.

I dont understand your problem fully, but i would recommend to deactivate the codeblocks internal watch scripts.
settings->debugger->gdb->watch scripts
or something like this. I am not on my pc to test this...

They are replaced by gdb internal scripts. You can search "gdb pretty print codeblocks" for more information