我使用的是 ubuntu 14.04,其中 python3 是默认系统包.
I'm using ubuntu 14.04, where python3 is a default system package.
我想用gdb调试Python2.7程序,但是我好像遇到了这个问题:
I want to debug Python2.7 programs with gdb, but I seem to encounter this issue:
当我在 gdb 中时,使用 py
命令会将我置于解释器中,因此我在解释器中运行了这些命令:
When i'm in gdb, using the py
command puts me in an interpreter, so i ran these commands in the interpreter:
首先我检查解释器版本:
First I check the interpreter version:
(gdb) py
>import sys
>print(sys.version)
>end
3.4.0 (default, Apr 11 2014, 13:08:40)
[GCC 4.8.2]
然后我检查正在使用的解释器可执行文件
Then I check what interpreter executable is being used
(gdb) py
>import sys
>print(sys.executable)
>end
/usr/bin/python
(gdb)
然后在 bash 中,我检查解释器:
Then in bash, I check the interpreter:
12:34]hostname ~ $ls -l /usr/bin/python
lrwxrwxrwx 1 root root 9 Dec 21 2013 /usr/bin/python -> python2.7
虽然 gdb 说它使用的是我的 2.7 解释器,但实际上它使用的是另一个解释器.我需要一个 2.7 解释器才能将它与 ubuntu 包python2.7-dbg"提供的 python 特定扩展一起使用,因为据我所知,python 3.4 还没有这样的包,即使有,我要调试的程序运行 python 2.7
So although gdb says it's using my 2.7 interpreter, it's actually using another one. I need a 2.7 interpreter to be able to use it with the python specific extensions that the ubuntu package 'python2.7-dbg' provides, because as far as i know there's no such package for python 3.4 yet, and even if there was, the programs that i want to debug run python 2.7
我的问题是如何让它使用我想要的解释器?
My question is how do i make it use the interpreter I want?
不要卸载 python3 顺便说一句.我在 ubuntu 14.04 上完成了它,它破坏了我的系统.没能重新站起来.我目前正在使用它而没有窗口管理器(它很酷,1337),但你明白了.
Do not uninstall python3 btw. I did it on ubuntu 14.04 and it wrecked my system. Couldn't manage to get it up again. I'm currently using it with no window-manager (it's cool and 1337), but you get the idea.
虽然 gdb 说它使用的是我的 2.7 解释器
So although gdb says it's using my 2.7 interpreter
GDB 没有这么说.它说它使用的是 3.4.0,并且解释器以 libpython3.4.a
或 libpython3.4.so的形式链接到 GDB代码>.
GDB doesn't say that. It says it's using 3.4.0, and that interpreter is linked into GDB, in the form of libpython3.4.a
or libpython3.4.so
.
由于不涉及实际的 Python 二进制文件,这里的(小)错误是 sys.executable
返回 /usr/bin/python
.返回 /usr/bin/gdb
可能会更好.
Since there is no actual Python binary involved, the (minor) bug here is that sys.executable
returns /usr/bin/python
. It would possibly be better for it to return /usr/bin/gdb
instead.
我需要一个 2.7 的解释器
I need a 2.7 interpreter
在这种情况下,您必须在使用适当的 --with-python
值配置之后,从源代码重建 gdb
.
In that case, you'll have to rebuild gdb
from source, after configuring it with appropriate --with-python
value.
这篇关于如何更改 gdb 使用的 Python 解释器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!