Author Topic: Still having seg fault while watching a string....  (Read 4431 times)

Offline sylwa

  • Multiple posting newcomer
  • *
  • Posts: 12
Still having seg fault while watching a string....
« on: March 25, 2013, 11:38:43 am »
Hi !

I get a seg fault when I try to watch a string.

Here my config :
code::block v10.05
gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5)
GNU gdb (Ubuntu/Linaro 7.4-2012.04-0ubuntu2.1) 7.4-2012.04

here my snippet :

Code
#include <memory.h> // for memset
#include <string>

using namespace std;

const unsigned kuiConfigFileNameMaxLength = 128;

int main(int argc, char* argv[])
{
  int iErr = 0;
  char cConfigFileName [kuiConfigFileNameMaxLength];
  memset( (void*)cConfigFileName , 0, kuiConfigFileNameMaxLength );

  // Get input file name
  if ( strlen( (const char *) argv[1] ) > kuiConfigFileNameMaxLength )
  {
    iErr = 1;
  }
  else
  {
    memcpy( (void*)cConfigFileName, (const void*)argv[1], strlen( (const char *) argv[1] ));
  }

  string strConfigFileName( (const char*)(cConfigFileName), strlen( (const char *)cConfigFileName) );

  return iErr;
}


and here the log when I add a string in the watch window :
Code
LD_LIBRARY_PATH=.:/usr/physics/root/pro/lib:
Command-line: /usr/bin/gdb -nx -fullname  -quiet -args Debug/BuildCrocusCfgFile
Working dir : /home/rousseau/DSP/codeBlock/codeBlockTst1/
Reading symbols from /home/rousseau/DSP/codeBlock/codeBlockTst1/Debug/BuildCrocusCfgFile...
done.
(gdb)
> set prompt >>>>>>cb_gdb:
Executing: xterm -T 'Program Console' -e sleep 82690
>>>>>>cb_gdb:
> show version
GNU gdb (Ubuntu/Linaro 7.4-2012.04-0ubuntu2.1) 7.4-2012.04
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://bugs.launchpad.net/gdb-linaro/>.
>>>>>>cb_gdb:
> set confirm off
>>>>>>cb_gdb:
> set width 0
>>>>>>cb_gdb:
> set height 0
>>>>>>cb_gdb:
> set breakpoint pending on
>>>>>>cb_gdb:
> set print asm-demangle on
>>>>>>cb_gdb:
> set unwindonsignal on
>>>>>>cb_gdb:
> set disassembly-flavor intel
>>>>>>cb_gdb:
> catch throw
Function "__cxa_throw" not defined.
Catchpoint 1 (throw)
>>>>>>cb_gdb:
> source /usr/share/codeblocks/scripts/stl-views-1.0.3.gdb
>>>>>>cb_gdb:
> directory /home/rousseau/DSP/codeBlock/codeBlockTst1/
>>>>>>cb_gdb:
> set args S:\svn\ALICE\windows\codeBlockTst1
>>>>>>cb_gdb:
> break "/home/rousseau/DSP/codeBlock/codeBlockTst1/BuildCrocusCfgFile.cpp:16"
Breakpoint 2 at 0x400916: file /home/rousseau/DSP/codeBlock/codeBlockTst1/BuildCrocusCfgFile.cpp, line 16.
>>>>>>cb_gdb:
Executing: ps x -o tty,pid,command
PS result: pts/48    7344 ps x -o tty,pid,command
PS result: pts/6     7343 sleep 82690
TTY is[/dev/pts/6]
GetConsoleTTY[/dev/pts/6]ConsolePid[7341]
> tty /dev/pts/6
Queued:[tty /dev/pts/6]
>>>>>>cb_gdb:
> run
Breakpoint 2, main (argc=2, argv=0x7fffffffea28) at /home/rousseau/DSP/codeBlock/codeBlockTst1/BuildCrocusCfgFile.cpp:16
/home/rousseau/DSP/codeBlock/codeBlockTst1/BuildCrocusCfgFile.cpp:16:351:beg:0x400916
>>>>>>cb_gdb:
> info locals
iErr = 0
cConfigFileName = "\000\000\000\000\000\000\000\000\004\005@\000\000\000\000\000\070\226.", '\000' <se r\377\377\377\377\377\377\377烿\000\377\377\377\377\377\377\377瓿攀 ㄀㌀ 昀漀椀猀㸀Ⰰ ∀堀尀㈀㜀㐀尀㌀㌀㌀尀㌀㘀㜀尀㌀㜀㜀尀㄀㜀㜀∀Ⰰ ✀尀   ✀ 㰀猀攀 爀\000\377\377\377\377\377\377\377烿\000\377\377\377\377\377\377\377瓿攀 ㄀㄀ 昀漀椀猀㸀∀尀㈀㐀 Ⰰ 尀㈀㔀㔀尀㌀㘀㜀尀㌀㜀㜀尀㄀㜀㜀尀   尀   琀尀㈀ 㜀尀㌀㌀㘀尀㌀㘀㜀尀㌀㜀㜀尀㄀㜀㜀尀   尀   尀  ㄀尀   尀   尀   尀㌀㜀㜀尀㄀㜀㜀尀   尀   䀀尀渀䀀∀Ⰰ ✀尀   ✀ 㰀猀攀 爀\000\377\377\377\377\377\377\377烿\000\377\377\377\377\377\377\377瓿攀 ㄀㌀ 昀漀椀猀㸀Ⰰ ∀㬀尀愀䀀尀   尀   尀   尀   尀   尀  ㄀尀   尀   尀   尀㌀㜀㜀尀㄀㜀㜀尀   尀   尀㈀ 㔀尀渀䀀尀   尀   尀   尀   尀   ⠀尀㌀㔀㈀尀㌀㜀㜀尀㌀㜀㜀尀㌀㜀㜀尀㄀㜀㜀尀   尀   䀀尀渀䀀尀   尀   尀   尀   ∀
strConfigFileName = {
  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 = 0x1ffffffff <Address 0x1ffffffff out of bounds>
  }
}
>>>>>>cb_gdb:
> info args
argc = 2
argv = 0x7fffffffea28
>>>>>>cb_gdb:
> whatis argv[1]
type = char *
>>>>>>cb_gdb:
> output argv[1]
0x7fffffffec95 "S:svnALICEwindowscodeBlockTst1">>>>>>cb_gdb:
> whatis cConfigFileName
type = char [128]
>>>>>>cb_gdb:
> output cConfigFileName
"\000\000\000\000\000\000\000\000\004\005@\000\000\000\000\000\070\226.", '\000' <se r\377\377\377\377\377\377\377烿\000\377\377\377\377\377\377\377瓿攀 ㄀㌀ 昀漀椀猀㸀Ⰰ ∀堀尀㈀㜀㐀尀㌀㌀㌀尀㌀㘀㜀尀㌀㜀㜀尀㄀㜀㜀∀Ⰰ ✀尀   ✀ 㰀猀攀 爀\000\377\377\377\377\377\377\377烿\000\377\377\377\377\377\377\377瓿攀 ㄀㄀ 昀漀椀猀㸀∀尀㈀㐀 Ⰰ 尀㈀㔀㔀尀㌀㘀㜀尀㌀㜀㜀尀㄀㜀㜀尀   尀   琀尀㈀ 㜀尀㌀㌀㘀尀㌀㘀㜀尀㌀㜀㜀尀㄀㜀㜀尀   尀   尀  ㄀尀   尀   尀   尀㌀㜀㜀尀㄀㜀㜀尀   尀   䀀尀渀䀀∀Ⰰ ✀尀   ✀ 㰀猀攀 爀\000\377\377\377\377\377\377\377烿\000\377\377\377\377\377\377\377瓿攀 ㄀㌀ 昀漀椀猀㸀Ⰰ ∀㬀尀愀䀀尀   尀   尀   尀   尀   尀  ㄀尀   尀   尀   尀㌀㜀㜀尀㄀㜀㜀尀   尀   尀㈀ 㔀尀渀䀀尀   尀   尀   尀   尀   ⠀尀㌀㔀㈀尀㌀㜀㜀尀㌀㜀㜀尀㌀㜀㜀尀㄀㜀㜀尀   尀   䀀尀渀䀀尀   尀   尀   尀   ∀>>>>>>cb_gdb:
> bt 30
#0  main (argc=2, argv=0x7fffffffea28) at /home/rousseau/DSP/codeBlock/codeBlockTst1/BuildCrocusCfgFile.cpp:16
>>>>>>cb_gdb:
> info locals
iErr = 0
cConfigFileName = "\000\000\000\000\000\000\000\000\004\005@\000\000\000\000\000\070\226.", '\000' <se r\377\377\377\377\377\377\377烿\000\377\377\377\377\377\377\377瓿攀 ㄀㌀ 昀漀椀猀㸀Ⰰ ∀堀尀㈀㜀㐀尀㌀㌀㌀尀㌀㘀㜀尀㌀㜀㜀尀㄀㜀㜀∀Ⰰ ✀尀   ✀ 㰀猀攀 爀\000\377\377\377\377\377\377\377烿\000\377\377\377\377\377\377\377瓿攀 ㄀㄀ 昀漀椀猀㸀∀尀㈀㐀 Ⰰ 尀㈀㔀㔀尀㌀㘀㜀尀㌀㜀㜀尀㄀㜀㜀尀   尀   琀尀㈀ 㜀尀㌀㌀㘀尀㌀㘀㜀尀㌀㜀㜀尀㄀㜀㜀尀   尀   尀  ㄀尀   尀   尀   尀㌀㜀㜀尀㄀㜀㜀尀   尀   䀀尀渀䀀∀Ⰰ ✀尀   ✀ 㰀猀攀 爀\000\377\377\377\377\377\377\377烿\000\377\377\377\377\377\377\377瓿攀 ㄀㌀ 昀漀椀猀㸀Ⰰ ∀㬀尀愀䀀尀   尀   尀   尀   尀   尀  ㄀尀   尀   尀   尀㌀㜀㜀尀㄀㜀㜀尀   尀   尀㈀ 㔀尀渀䀀尀   尀   尀   尀   尀   ⠀尀㌀㔀㈀尀㌀㜀㜀尀㌀㜀㜀尀㌀㜀㜀尀㄀㜀㜀尀   尀   䀀尀渀䀀尀   尀   尀   尀   ∀
strConfigFileName = {
  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 = 0x1ffffffff <Address 0x1ffffffff out of bounds>
  }
}
>>>>>>cb_gdb:
> info args
argc = 2
argv = 0x7fffffffea28
>>>>>>cb_gdb:
> whatis argv[1]
type = char *
>>>>>>cb_gdb:
> output argv[1]
0x7fffffffec95 "S:svnALICEwindowscodeBlockTst1">>>>>>cb_gdb:
> whatis cConfigFileName
type = char [128]
>>>>>>cb_gdb:
> output cConfigFileName
"\000\000\000\000\000\000\000\000\004\005@\000\000\000\000\000\070\226.", '\000' <se r\377\377\377\377\377\377\377烿\000\377\377\377\377\377\377\377瓿攀 ㄀㌀ 昀漀椀猀㸀Ⰰ ∀堀尀㈀㜀㐀尀㌀㌀㌀尀㌀㘀㜀尀㌀㜀㜀尀㄀㜀㜀∀Ⰰ ✀尀   ✀ 㰀猀攀 爀\000\377\377\377\377\377\377\377烿\000\377\377\377\377\377\377\377瓿攀 ㄀㄀ 昀漀椀猀㸀∀尀㈀㐀 Ⰰ 尀㈀㔀㔀尀㌀㘀㜀尀㌀㜀㜀尀㄀㜀㜀尀   尀   琀尀㈀ 㜀尀㌀㌀㘀尀㌀㘀㜀尀㌀㜀㜀尀㄀㜀㜀尀   尀   尀  ㄀尀   尀   尀   尀㌀㜀㜀尀㄀㜀㜀尀   尀   䀀尀渀䀀∀Ⰰ ✀尀   ✀ 㰀猀攀 爀\000\377\377\377\377\377\377\377烿\000\377\377\377\377\377\377\377瓿攀 ㄀㌀ 昀漀椀猀㸀Ⰰ ∀㬀尀愀䀀尀   尀   尀   尀   尀   尀  ㄀尀   尀   尀   尀㌀㜀㜀尀㄀㜀㜀尀   尀   尀㈀ 㔀尀渀䀀尀   尀   尀   尀   尀   ⠀尀㌀㔀㈀尀㌀㜀㜀尀㌀㜀㜀尀㌀㜀㜀尀㄀㜀㜀尀   尀   䀀尀渀䀀尀   尀   尀   尀   ∀>>>>>>cb_gdb:
> whatis strConfigFileName
type = std::string
>>>>>>cb_gdb:
> output strConfigFileName.c_str()[0]@strConfigFileName.size()
The program being debugged was signaled while in a function called from GDB.
GDB has restored the context to what it was before the call.
To change this behavior use "set unwindonsignal off".
Evaluation of the expression containing the function
(std::string::size() const) will be abandoned.
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7b77dd3 in std::string::size() const () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
>>>>>>cb_gdb:
> info locals
iErr = 0
cConfigFileName = "\000\000\000\000\000\000\000\000\004\005@\000\000\000\000\000\070\226.", '\000' <se r\377\377\377\377\377\377\377烿\000\377\377\377\377\377\377\377瓿攀 ㄀㌀ 昀漀椀猀㸀Ⰰ ∀堀尀㈀㜀㐀尀㌀㌀㌀尀㌀㘀㜀尀㌀㜀㜀尀㄀㜀㜀∀Ⰰ ✀尀   ✀ 㰀猀攀 爀\000\377\377\377\377\377\377\377烿\000\377\377\377\377\377\377\377瓿攀 ㄀㄀ 昀漀椀猀㸀∀尀㈀㐀 Ⰰ 尀㈀㔀㔀尀㌀㘀㜀尀㌀㜀㜀尀㄀㜀㜀尀   尀   琀尀㈀ 㜀尀㌀㌀㘀尀㌀㘀㜀尀㌀㜀㜀尀㄀㜀㜀尀   尀   尀  ㄀尀   尀   尀   尀㌀㜀㜀尀㄀㜀㜀尀   尀   䀀尀渀䀀∀Ⰰ ✀尀   ✀ 㰀猀攀 爀\000\377\377\377\377\377\377\377烿\000\377\377\377\377\377\377\377瓿攀 ㄀㌀ 昀漀椀猀㸀Ⰰ ∀㬀尀愀䀀尀   尀   尀   尀   尀   尀  ㄀尀   尀   尀   尀㌀㜀㜀尀㄀㜀㜀尀   尀   尀㈀ 㔀尀渀䀀尀   尀   尀   尀   尀   ⠀尀㌀㔀㈀尀㌀㜀㜀尀㌀㜀㜀尀㌀㜀㜀尀㄀㜀㜀尀   尀   䀀尀渀䀀尀   尀   尀   尀   ∀
strConfigFileName = {
  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 = 0x1ffffffff <Address 0x1ffffffff out of bounds>
  }
}
>>>>>>cb_gdb:
> info args
argc = 2
argv = 0x7fffffffea28
>>>>>>cb_gdb:
> whatis argv[1]
type = char *
>>>>>>cb_gdb:
> output argv[1]
0x7fffffffec95 "S:svnALICEwindowscodeBlockTst1">>>>>>cb_gdb:
> whatis cConfigFileName
type = char [128]
>>>>>>cb_gdb:
> output cConfigFileName
"\000\000\000\000\000\000\000\000\004\005@\000\000\000\000\000\070\226.", '\000' <se r\377\377\377\377\377\377\377烿\000\377\377\377\377\377\377\377瓿攀 ㄀㌀ 昀漀椀猀㸀Ⰰ ∀堀尀㈀㜀㐀尀㌀㌀㌀尀㌀㘀㜀尀㌀㜀㜀尀㄀㜀㜀∀Ⰰ ✀尀   ✀ 㰀猀攀 爀\000\377\377\377\377\377\377\377烿\000\377\377\377\377\377\377\377瓿攀 ㄀㄀ 昀漀椀猀㸀∀尀㈀㐀 Ⰰ 尀㈀㔀㔀尀㌀㘀㜀尀㌀㜀㜀尀㄀㜀㜀尀   尀   琀尀㈀ 㜀尀㌀㌀㘀尀㌀㘀㜀尀㌀㜀㜀尀㄀㜀㜀尀   尀   尀  ㄀尀   尀   尀   尀㌀㜀㜀尀㄀㜀㜀尀   尀   䀀尀渀䀀∀Ⰰ ✀尀   ✀ 㰀猀攀 爀\000\377\377\377\377\377\377\377烿\000\377\377\377\377\377\377\377瓿攀 ㄀㌀ 昀漀椀猀㸀Ⰰ ∀㬀尀愀䀀尀   尀   尀   尀   尀   尀  ㄀尀   尀   尀   尀㌀㜀㜀尀㄀㜀㜀尀   尀   尀㈀ 㔀尀渀䀀尀   尀   尀   尀   尀   ⠀尀㌀㔀㈀尀㌀㜀㜀尀㌀㜀㜀尀㌀㜀㜀尀㄀㜀㜀尀   尀   䀀尀渀䀀尀   尀   尀   尀   ∀>>>>>>cb_gdb:
> whatis strConfigFileName
type = std::string
>>>>>>cb_gdb:
> output strConfigFileName.c_str()[0]@strConfigFileName.size()
The program being debugged was signaled while in a function called from GDB.
GDB has restored the context to what it was before the call.
To change this behavior use "set unwindonsignal off".
Evaluation of the expression containing the function
(std::string::size() const) will be abandoned.
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7b77dd3 in std::string::size() const () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
>>>>>>cb_gdb:
> bt 30
#0  main (argc=2, argv=0x7fffffffea28) at /home/rousseau/DSP/codeBlock/codeBlockTst1/BuildCrocusCfgFile.cpp:16
>>>>>>cb_gdb:


May I ask you some help ?

Cheers !

Sylvain

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Still having seg fault while watching a string....
« Reply #1 on: March 25, 2013, 12:57:09 pm »
Search the forum... it was discussed at length...
(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 Pecan

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 2783
Re: Still having seg fault while watching a string....
« Reply #2 on: March 25, 2013, 03:04:32 pm »
Navigate to the forum home and in the search box type "string size optimize" for a list of messages to this problem.

Offline sylwa

  • Multiple posting newcomer
  • *
  • Posts: 12
Re: Still having seg fault while watching a string....
« Reply #3 on: March 25, 2013, 03:20:38 pm »
Hi !

many thanks for your help.

Actually, I went through this topic : http://forums.codeblocks.org/index.php?topic=17573.0 and wound up without any solution.
Then I read this topic : http://forums.codeblocks.org/index.php/topic,16772.30.html which led me to http://wiki.codeblocks.org/index.php?title=Pretty_Printers which eventually gave me the solution.

Sorry for the disturbance.

Sylvain