views:

177

answers:

2

I have this output when trying to debug

Program received signal SIGSEGV, Segmentation fault

0x43989029 in std::string::compare (this=0x88fd430, __str=@0xbfff9060) at /home/devsw/tmp/objdir/i686-pc-linux-gnu/libstdc++-v3/include/bits/char_traits.h:253

253 { return memcmp(__s1, __s2, __n); } Current language: auto; currently c++


Using valgrind I getting this output

==12485== Process terminating with default action of signal 11 (SIGSEGV)

==12485== Bad permissions for mapped region at address 0x0

==12485== at 0x1: (within path_to_my_executable_file/executable_file)

+4  A: 

Just run the app in the debugger. At one point it will die and you will have a stack trace with the information you want.

David Rodríguez - dribeas
Debugging results are shoded above. The problem in std::string::compare
Davit Siradeghyan
The debugger can offer much more information than what you are showing. It can surely show the stack trace, so you know not only that the `string::compare` killed the app, but also who made that call and with what parameters... In linux use gdb: `bt` will dump a backtrace, you can move with `up/down/frame #` to a given frame, and you can use `print var` to dump the contents of a var to screen...
David Rodríguez - dribeas
+5  A: 

You don't need to use Valgrind, in fact you want to use the GNU DeBugger (GDB).

If you run the application via gdb (gdb path_to_my_executable_file/executable_file) and you've compiled the application with debugging enabled (-g or -ggdb for GNU C/C++ compilers), you can start the application (via run command at the gdb prompt) and once you arrive at the SegFault, do a backtrace (bt) to see what part of your program called std::string::compare which died.

Example (C):

mctaylor@mpc:~/stackoverflow$ gcc -ggdb crash.c -o crash
mctaylor@mpc:~/stackoverflow$ gdb -q ./crash 
(gdb) run
Starting program: /home/mctaylor/stackoverflow/crash 

Program received signal SIGSEGV, Segmentation fault.
0x00007f78521bdeb1 in memcpy () from /lib/libc.so.6
(gdb) bt
#0  0x00007f78521bdeb1 in memcpy () from /lib/libc.so.6
#1  0x00000000004004ef in main (argc=1, argv=0x7fff3ef4d848) at crash.c:5
(gdb) 

So the error I'm interested in is located on crash.c line 5.

Good luck.

mctylr