如何调试 Python 分段错误?
我们正在尝试在 SuSE 12.3 上运行我们的 python 代码。我们得到可重现的分段错误。多年来,python 代码一直在其他平台上运行,没有出现分段错误。
我们只编写 Python 代码,没有 C 扩展......
调试此问题的最佳方法是什么?我知道一点ansi c,但那是十年前的事了....
Python 2.7.5
更新
分段错误发生在解释器关闭时。
我可以多次运行脚本:
python -m pdb myscript.py arg1 arg1
continue
run
continue
run
但是如果我用 ctrl-d 离开 pdb,就会发生分段错误。
更新 2
我现在尝试用 gdb 调试它:
gdb
> file python
> run myscript.py arg1 arg2
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fffefbe2700 (LWP 15483)]
0x00007ffff7aef93c in PyEval_EvalFrameEx () from /usr/lib64/libpython2.7.so.1.0
(gdb) bt
#0 0x00007ffff7aef93c in PyEval_EvalFrameEx () from /usr/lib64/libpython2.7.so.1.0
#1 0x00007ffff7af5303 in PyEval_EvalCodeEx () from /usr/lib64/libpython2.7.so.1.0
#2 0x00007ffff7adc858 in ?? () from /usr/lib64/libpython2.7.so.1.0
#3 0x00007ffff7ad840d in PyObject_Call () from /usr/lib64/libpython2.7.so.1.0
#4 0x00007ffff7af1082 in PyEval_EvalFrameEx () from /usr/lib64/libpython2.7.so.1.0
#5 0x00007ffff7af233d in PyEval_EvalFrameEx () from /usr/lib64/libpython2.7.so.1.0
#6 0x00007ffff7af233d in PyEval_EvalFrameEx () from /usr/lib64/libpython2.7.so.1.0
#7 0x00007ffff7af5303 in PyEval_EvalCodeEx () from /usr/lib64/libpython2.7.so.1.0
#8 0x00007ffff7adc5b6 in ?? () from /usr/lib64/libpython2.7.so.1.0
#9 0x00007ffff7ad840d in PyObject_Call () from /usr/lib64/libpython2.7.so.1.0
#10 0x00007ffff7ad9171 in ?? () from /usr/lib64/libpython2.7.so.1.0
#11 0x00007ffff7ad840d in PyObject_Call () from /usr/lib64/libpython2.7.so.1.0
#12 0x00007ffff7aeeb62 in PyEval_CallObjectWithKeywords () from /usr/lib64/libpython2.7.so.1.0
#13 0x00007ffff7acc757 in ?? () from /usr/lib64/libpython2.7.so.1.0
#14 0x00007ffff7828e0f in start_thread () from /lib64/libpthread.so.0
#15 0x00007ffff755c7dd in clone () from /lib64/libc.so.6
更新 3
我从http://hg.python.org/cpython/file/default/Misc/gdbinit安装了 gdbinit,从http://download.opensuse.org/debug/distribution/12.3/repo/oss/suse/安装 了调试符号x86_64/
(gdb) pystack
No symbol "_PyUnicode_AsString" in current context.
现在怎么办?
更新 4 我们安装了新的 RPM (python-2.7.5-3.1.x86_64)。我们得到的段错误更少,但它们仍然会发生。这是存储库的链接:
http://download.opensuse.org/repositories/devel:/languages:/python:/Factory/openSUSE_12.3/x86_64/
更新 5 解决了我最初的问题:
它是http://bugs.python.org/issue1856(关闭(退出)可以挂起或 segfault 与守护线程运行)