Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[SOLVED] backtrace a segmentation fault using gdb
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
jopeto
Tux's lil' helper
Tux's lil' helper


Joined: 02 Jul 2012
Posts: 106

PostPosted: Sat Aug 25, 2012 2:30 pm    Post subject: [SOLVED] backtrace a segmentation fault using gdb Reply with quote

I'm trying to run a python script on my gentoo machine which I wrote on a different computer running linux mint. It uses numpy, wxpython and matplotlib and runs just fine on the linux mint machine. However when I try to run it on the gentoo machine I get a segmentation fault. The interesting thing is that the program seems to run until the end, since the last line in the script is to save a figure generated by matplotlib. Upon examination, the figure is saved and everything works fine. It's really strange then that the program crashes.

I added the -ggdb flag to my CFLAGS in /etc/make.conf python, wxpython, matplotlib and numpy with these new flags as advised here:
http://www.gentoo.org/proj/en/qa/backtraces.xml?style=printable

I also enabled creating a core dump file using the ulimit command.

After running my program, a file "core" is generated in the directory. Then I run gdb on it, however I don't really get any meaningful backtrace. This is what I get:
Code:
$ gdb
GNU gdb (Gentoo 7.3.1 p2) 7.3.1
Copyright (C) 2011 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-pc-linux-gnu".
For bug reporting instructions, please see:
<http://bugs.gentoo.org/>.
(gdb) core core
[New LWP 13235]
[New LWP 13245]
Core was generated by `python2.7 ./mpl_latex_plot_v2.py'.
Program terminated with signal 11, Segmentation fault.
#0 0x00007f03e4adce4a in ?? ()
(gdb) bt
#0 0x00007f03e4adce4a in ?? ()
#1 0x00007f03e2a20b10 in ?? ()
#2 0x0000000000000000 in ?? ()


Could someone point me out what I am doing wrong and how I could get more meaningful backtrace in order to find out where the segmentation fault is coming from in order to get rid of it.

Thanks a lot.


Last edited by jopeto on Sun Aug 26, 2012 2:09 pm; edited 1 time in total
Back to top
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 21633

PostPosted: Sat Aug 25, 2012 2:54 pm    Post subject: Reply with quote

You linked to the backtrace guide, but you did not specify whether you also changed your FEATURES to prevent stripping. Debug symbols require quite a bit of space, so normally the package manager will strip the file to recover that space. As noted in the guide you referenced, you need FEATURES=splitdebug or FEATURES=nostrip to preserve those symbols.
Back to top
View user's profile Send private message
jopeto
Tux's lil' helper
Tux's lil' helper


Joined: 02 Jul 2012
Posts: 106

PostPosted: Sat Aug 25, 2012 8:39 pm    Post subject: Reply with quote

Sorry, I guess I had not specified the features. Now this is what the relevant bits in my /etc/make.conf files look like:
Code:
CFLAGS="-march=core2 -O2 -pipe -ggdb"
CXXFLAGS="${CFLAGS}"
MAKEOPTS="-j3"
FEATURES="-config-protect-if-modified splitdebug"

I re-emerged python 2.7, wxpython, numpy and matplotlib. However when I run gdb on the core dump file, I get exactly the same output as before. Just ??.

One thing that I noticed is that in /usr/lib/debug, there is folder /usr/lib/debug/usr/bin and in it there is only one file python2.7.debug. There is no numpy, wxpython or matplotlib debug files, even though I re-emerged them after changing the flags and the FEATURES.
Back to top
View user's profile Send private message
toralf
Developer
Developer


Joined: 01 Feb 2004
Posts: 3922
Location: Hamburg

PostPosted: Sat Aug 25, 2012 9:39 pm    Post subject: Reply with quote

Well, beside that I've " -g -ggdb" you can exmine the core file with
Code:
gdb --core=<core file> <path to the executable, eg. python 2.7>
BTW you should consider default package CFLAGS in your make.conf
Code:
$ grep CFLAGS /etc/make.conf
CFLAGS="-O2 -march=native -pipe"
CXXFLAGS="${CFLAGS}"
and then package specific flags like this :
Code:
$ cat /etc/portage/env/splitdebug
CFLAGS="${CFLAGS} -g -ggdb"                                               
CXXFLAGS="${CFLAGS}"                                                                     
FEATURES="splitdebug"
and
Code:
$ grep splitdebug /etc/portage/package.env/misc | head -n 3
app-shells/bash                 splitdebug
<=dev-libs/glib-2.30.3          splitdebug      notest
dev-libs/glib                   splitdebug
Back to top
View user's profile Send private message
jopeto
Tux's lil' helper
Tux's lil' helper


Joined: 02 Jul 2012
Posts: 106

PostPosted: Sun Aug 26, 2012 9:25 am    Post subject: Reply with quote

Thanks a lot for your suggestion. So what I have now is the following:
In my /etc/make.conf file I have:
Code:
CFLAGS="-march=core2 -O2 -pipe"
CXXFLAGS="${CFLAGS}"
MAKEOPTS="-j3"
FEATURES="-config-protect-if-modified"

I also created a /etc/portage/env directory and put a file called debug.conf in it containing
Code:
CFLAGS="${CFLAGS} -g -ggdb"                                               
CXXFLAGS="${CFLAGS}"                                                                     
FEATURES="splitdebug"

Finally I created a /etc/portage/package.env file containing
Code:
dev-lang/python:2.7   debug.conf
dev-python/wxpython   debug.conf
dev-python/numpy   debug.conf
dev-python/matplotlib   debug.conf

Then I re-emerged python 2.7, numpy, wxpython and matplotlib.

I ran my script again and a core dump file called "core" was generated. I ran the following commands
Code:
$ eselect python list
Available Python interpreters:
  [1]   python2.7 *
  [2]   python3.2
$ which python
/usr/bin/python
$ gdb --core=core /usr/bin/python
GNU gdb (Gentoo 7.3.1 p2) 7.3.1
Copyright (C) 2011 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-pc-linux-gnu".
For bug reporting instructions, please see:
<http://bugs.gentoo.org/>...
Reading symbols from /usr/bin/python...(no debugging symbols found)...done.

warning: core file may not match specified executable file.
[New LWP 25122]
[New LWP 25147]
Core was generated by `python2.7 ./mpl_latex_plot_v2.py'.
Program terminated with signal 11, Segmentation fault.
#0  0x00007f15533b5e4a in ?? ()
(gdb) bt
#0  0x00007f15533b5e4a in ?? ()
#1  0x00007f15512f9b10 in ?? ()
#2  0x0000000000000000 in ?? ()


As you can see, once again no meaningful debug information was obtained. Any suggestions?
Back to top
View user's profile Send private message
toralf
Developer
Developer


Joined: 01 Feb 2004
Posts: 3922
Location: Hamburg

PostPosted: Sun Aug 26, 2012 9:38 am    Post subject: Reply with quote

Well, specify /usr/bin/python2.7 because /usr/bin/python is only a symlink/wrapper to the actual python executeable.
Back to top
View user's profile Send private message
jopeto
Tux's lil' helper
Tux's lil' helper


Joined: 02 Jul 2012
Posts: 106

PostPosted: Sun Aug 26, 2012 1:14 pm    Post subject: Reply with quote

Thanks a lot, specifying python2.7 did it. Now I got a bit more detailed backtrace and I'll get in touch with the guys at the wxpython mail list. Thanks once again for your help.
Back to top
View user's profile Send private message
toralf
Developer
Developer


Joined: 01 Feb 2004
Posts: 3922
Location: Hamburg

PostPosted: Sun Aug 26, 2012 2:07 pm    Post subject: Reply with quote

jopeto wrote:
Thanks a lot, specifying python2.7 did it. Now I got a bit more detailed backtrace and I'll get in touch with the guys at the wxpython mail list. Thanks once again for your help.
urw
BTW put a "[solved]" in front of the title of this thread - just for convenience.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum