如何在imp.load_module上调查python2 segfault

时间:2012-12-19 22:03:04

标签: cmake shared-libraries swig python-2.x archlinux

我正在尝试使用Python 2.7.3在Arch Linux上安装和使用dolfin

找出导致细分的最佳方法是什么? 这些错误?

$ python2 -c "import dolfin; print dolfin.__version__"
[3]    6491 segmentation fault (core dumped)  python2 -c "import dolfin; print 
dolfin.__version__"

我试过通过gdb检查核心文件:

$ sudo systemd-coredumpctl gdb 6491

但它们总是被截断:

Reading symbols from /usr/bin/python2.7...(no debugging symbols
found)...done.
BFD: Warning: /var/tmp/coredump-wSi8DV is truncated: expected
core file size >= 39694336, found: 25165824.
warning: core file may not match specified executable file.
[New LWP 7056]
Cannot access memory at address 0x7fe70be0d148
Cannot access memory at address 0x7fe70be0d140

我尝试在命令之间添加'print'语句并且有 将问题跟踪到此load_module行,该行加载了一个 由swig构建的模块:

fp, pathname, description = imp.find_module('_common', [dirname(__file__)])
print "_mod = imp.load_module('_common', \n\tfp=%s, \n\tpathname=%s, \n\tdescription=%s)" % ( fp, pathname, description)
_mod = imp.load_module('_common', fp, pathname, description)

并且'print'行打印以下内容,看起来是正确的:

_mod = imp.load_module('_common', 
        fp=<open file '_common.so', mode 'rb' at 0x282d150>, 
        pathname=_common.so, 
        description=('.so', 'rb', 3))
[1]    9039 segmentation fault (core dumped)  python2 -c "import dolfin; print dolfin.__version__"

我尝试在模块启动时添加sys.settrace 信息,但这不会发生。

因此,我检查了它正在尝试的共享库的链接 负载:

$ ldd _common.so
    libexpat.so.1 => /lib64/libexpat.so.1 (0x00007f52fe960000)
    libavformat.so.54 => /lib64/libavformat.so.54 (0x00007f52fe61d000)
    libavcodec.so.54 => /lib64/libavcodec.so.54 (0x00007f52fd6bb000)
    libavutil.so.51 => /lib64/libavutil.so.51 (0x00007f52fd48d000)
    libswscale.so.2 => /lib64/libswscale.so.2 (0x00007f52fd240000)
    libvtkImaging.so.5.10 => /usr/lib/vtk-5.10/libvtkImaging.so.5.10 (0x00007f52fcb6e000)
    libvtkftgl.so.5.10 => /usr/lib/vtk-5.10/libvtkftgl.so.5.10 (0x00007f52fc960000)
    libfreetype.so.6 => /lib64/libfreetype.so.6 (0x00007f52fc6c1000)
    libQtGui.so.4 => /lib64/libQtGui.so.4 (0x00007f52fba1d000)
    libQtCore.so.4 => /lib64/libQtCore.so.4 (0x00007f52fb546000)
    libGL.so.1 => /lib64/libGL.so.1 (0x00007f52fb223000)
    libXt.so.6 => /lib64/libXt.so.6 (0x00007f52fafbc000)
    libvtkParallel.so.5.10 => /usr/lib/vtk-5.10/libvtkParallel.so.5.10 (0x00007f52faabd000)
    libvtkexoIIc.so.5.10 => /usr/lib/vtk-5.10/libvtkexoIIc.so.5.10 (0x00007f52fa877000)
    libvtkVolumeRendering.so.5.10 => /usr/lib/vtk-5.10/libvtkVolumeRendering.so.5.10 (0x00007f52f9fdf000)
    libQtWebKit.so.4 => /lib64/libQtWebKit.so.4 (0x00007f52f81f9000)
    libQtSql.so.4 => /lib64/libQtSql.so.4 (0x00007f52f7fb9000)
    libQtNetwork.so.4 => /lib64/libQtNetwork.so.4 (0x00007f52f7c81000)
    libvtkViews.so.5.10 => /usr/lib/vtk-5.10/libvtkViews.so.5.10 (0x00007f52f7993000)
    libvtkInfovis.so.5.10 => /usr/lib/vtk-5.10/libvtkInfovis.so.5.10 (0x00007f52f7357000)
    libpci.so.3 => /usr/lib/libpci.so.3 (0x00007f52f714b000)
    libxcb.so.1 => /usr/lib/libxcb.so.1 (0x00007f52f6f2b000)
    libcblas.so => /usr/lib/libcblas.so (0x00007f52f6d0a000)
    libssl.so.1.0.0 => /lib64/libssl.so.1.0.0 (0x00007f52f6a9f000)
    libcrypto.so.1.0.0 => /lib64/libcrypto.so.1.0.0 (0x00007f52f6696000)
    libhdf5_hl.so.7.4.0 => /lib64/libhdf5_hl.so.7.4.0 (0x00007f52f6465000)
    librtmp.so.0 => /lib64/librtmp.so.0 (0x00007f52f6249000)
    libva.so.1 => /lib64/libva.so.1 (0x00007f52f6031000)
    libxvidcore.so.4 => /lib64/libxvidcore.so.4 (0x00007f52f5d19000)
    libx264.so.128 => /lib64/libx264.so.128 (0x00007f52f59ca000)
    libvpx.so.1 => /lib64/libvpx.so.1 (0x00007f52f5729000)
    libvorbisenc.so.2 => /lib64/libvorbisenc.so.2 (0x00007f52f525a000)
    libvorbis.so.0 => /lib64/libvorbis.so.0 (0x00007f52f502d000)
    libtheoraenc.so.1 => /lib64/libtheoraenc.so.1 (0x00007f52f4def000)
    libtheoradec.so.1 => /lib64/libtheoradec.so.1 (0x00007f52f4bd4000)
    libspeex.so.1 => /lib64/libspeex.so.1 (0x00007f52f49bb000)
    libschroedinger-1.0.so.0 => /lib64/libschroedinger-1.0.so.0 (0x00007f52f46ef000)
    libopenjpeg.so.1 => /lib64/libopenjpeg.so.1 (0x00007f52f44c7000)
    libopencore-amrwb.so.0 => /lib64/libopencore-amrwb.so.0 (0x00007f52f42b3000)
    libopencore-amrnb.so.0 => /lib64/libopencore-amrnb.so.0 (0x00007f52f4088000)
    libmp3lame.so.0 => /lib64/libmp3lame.so.0 (0x00007f52f3e11000)
    libgsm.so.1 => /lib64/libgsm.so.1 (0x00007f52f3c06000)
    libglib-2.0.so.0 => /lib64/libglib-2.0.so.0 (0x00007f52f390f000)
    libgobject-2.0.so.0 => /lib64/libgobject-2.0.so.0 (0x00007f52f36c1000)
    libSM.so.6 => /lib64/libSM.so.6 (0x00007f52f34b9000)
    libICE.so.6 => /lib64/libICE.so.6 (0x00007f52f329c000)
    libXrender.so.1 => /lib64/libXrender.so.1 (0x00007f52f3091000)
    libfontconfig.so.1 => /lib64/libfontconfig.so.1 (0x00007f52f2e57000)
    libXext.so.6 => /lib64/libXext.so.6 (0x00007f52f2c43000)
    libnvidia-tls.so.310.19 => /lib64/libnvidia-tls.so.310.19 (0x00007f52f2a40000)
    libnvidia-glcore.so.310.19 => /lib64/libnvidia-glcore.so.310.19 (0x00007f52f054d000)
    libVPIC.so.5.10 => /usr/lib/vtk-5.10/libVPIC.so.5.10 (0x00007f52f0328000)
    libCosmo.so.5.10 => /usr/lib/vtk-5.10/libCosmo.so.5.10 (0x00007f52f00e0000)
    libsqlite3.so.0 => /lib64/libsqlite3.so.0 (0x00007f52efe33000)
    libgstapp-0.10.so.0 => /lib64/libgstapp-0.10.so.0 (0x00007f52efc27000)
    libgstinterfaces-0.10.so.0 => /lib64/libgstinterfaces-0.10.so.0 (0x00007f52efa14000)
    libgstpbutils-0.10.so.0 => /lib64/libgstpbutils-0.10.so.0 (0x00007f52ef7f0000)
    libgstvideo-0.10.so.0 => /lib64/libgstvideo-0.10.so.0 (0x00007f52ef5d4000)
    libgstbase-0.10.so.0 => /lib64/libgstbase-0.10.so.0 (0x00007f52ef37f000)
    libgstreamer-0.10.so.0 => /lib64/libgstreamer-0.10.so.0 (0x00007f52ef096000)
    libvtkalglib.so.5.10 => /usr/lib/vtk-5.10/libvtkalglib.so.5.10 (0x00007f52eee75000)
    libresolv.so.2 => /usr/lib/libresolv.so.2 (0x00007f52eec5e000)
    libXau.so.6 => /usr/lib/libXau.so.6 (0x00007f52eea5a000)
    libXdmcp.so.6 => /usr/lib/libXdmcp.so.6 (0x00007f52ee853000)
    libogg.so.0 => /lib64/libogg.so.0 (0x00007f52ee64d000)
    liborc-0.4.so.0 => /lib64/liborc-0.4.so.0 (0x00007f52ee3d1000)
    libpcre.so.1 => /lib64/libpcre.so.1 (0x00007f52ee16e000)
    libgthread-2.0.so.0 => /lib64/libgthread-2.0.so.0 (0x00007f52edf6b000)
    libffi.so.6 => /lib64/libffi.so.6 (0x00007f52edd63000)
    libuuid.so.1 => /lib64/libuuid.so.1 (0x00007f52edb5e000)
    libgmodule-2.0.so.0 => /lib64/libgmodule-2.0.so.0 (0x00007f52ed959000)

我已经读过,段错误可能是由共享库引起的 与使用(或与?相关联)构建的库链接a 另一个库的不同版本,但我怎样才能找出哪个库 造成麻烦?感谢。

更新

如果我使用ltrace启动Python解释器,那么它可以工作(这可能会导致上面的段错误):

$ ltrace python2
__libc_start_main(0x400710, 1, 0x7fff640c6f38, 0x400810 <unfinished ...>
Py_Main(1, 0x7fff640c6f38, 0x7fff640c6f48, 0x400710Python 2.7.3 (default, Dec 12 2012,07:12:24) 
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from dolfin import *
>>>

为什么ltrace运行时没有段错误?

更新2

通过CMake配置-DCMAKE_BUILD_TYPE = Debug仍然允许优化标志'-O'传递给g ++。我将尝试使用调试符号重新构建(标记'-g')并查看它是如何进行的。

更新3

使用-g标志进行编译没有任何区别。

更新4

直接从gdb运行不会暴露分段错误(可能它使用某种形式的ltrace,如上所述):

$ gdb --args python2 -c "import dolfin; print dolfin.__version__"
GNU gdb (GDB) 7.5.1
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-unknown-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /usr/bin/python2...(no debugging symbols found)...done.
(gdb) run
Starting program: /usr/bin/python2 -c import\ dolfin\;\ print\ dolfin.__version__
warning: Could not load shared library symbols for linux-vdso.so.1.
Do you need "set solib-search-path" or "set sysroot"?
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".
Traceback (most recent call last):
  File "/usr/share/gdb/auto-load/usr/lib/libgobject-2.0.so.0.3400.3-gdb.py", line 9, in <module>
from gobject import register
  File "/usr/share/glib-2.0/gdb/gobject.py", line 3, in <module>
    import gdb.backtrace
ImportError: No module named backtrace
1.0.0+
[Inferior 1 (process 8008) exited normally]
(gdb)

2 个答案:

答案 0 :(得分:2)

  

我尝试通过gdb检查核心文件......但它们总是被截断

改为在实时流程上使用GDB:

gdb --args python2 -c "import dolfin; print dolfin.__version__"
(gdb) run

答案 1 :(得分:0)

我和dolfin有类似的问题。罪魁祸首是nvidia司机。我从最新的东西回来了,事情又恢复了。我不得不通过/ var / log / messages找到核心转储,用gdb运行它。在顶部的地方是nvidia图书馆。