我正在尝试使用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
我尝试在命令之间添加“打印”语句,并将问题跟踪到此 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)
并且“打印”行打印以下内容,看起来正确:
_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)
我已经读到,段错误可能是由于共享库与使用(或链接到?)另一个库的不同版本构建的库链接引起的,但我如何找出导致问题的原因?谢谢。
更新
如果我用 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运行时为什么没有segfault?
更新 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)