如何更改gdb使用的Python解释器? [英] How to change the Python Interpreter that gdb uses?

查看:267
本文介绍了如何更改gdb使用的Python解释器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是Ubuntu 14.04,其中python3是一个默认的系统包。



我想用gdb调试Python2.7程序,但我似乎遇到了这个问题:

当我在gdb中时,使用 py 命令让我进入解释器,所以我跑这些命令在解释器中:

首先检查解释器版本:

 (gdb)py 
> import sys
> print(sys.version)
> end
3.4.0(默认,2014年4月11日,13:08 :40)
[GCC 4.8.2]

然后我检查解释器可执行文件是使用

 (gdb)py 
> import sys
> print(sys.executable)
> end
/ usr / bin / python
(gdb)

然后在bash中,我检查了解释器:

  12:34] hostname〜$ ls -l / usr / bin / python 
lrwxrwxrwx 1 root root 9 2013年12月21日/ usr / bin / python - > python2.7

所以尽管gdb说它使用我的2.7解释器,但它实际上使用了另一个解释器。我需要一个2.7解释器,可以将它与ubuntu软件包'python2.7-dbg'提供的python特定的扩展名一起使用,因为据我所知,python 3.4还没有这样的软件包,即使存在,我想调试的程序运行python 2.7



我的问题是如何让它使用我想要的解释器?




不要卸载python3 btw。我在ubuntu 14.04上做了它,它破坏了我的系统。无法设法重新启动它。我目前在没有窗口管理器的情况下使用它(这很酷,而且是1337),但你明白了。 解决方案


因此,尽管gdb说它使用我的2.7解释器,但是GDB并没有这样说。它表示它使用的是3.4.0,并且该解释器以 libpython3.4.a 或<$ c $的形式链接到 GDB c> libpython3.4.so 。



由于没有涉及实际的Python二进制文件,因此这里的(小)错误是 sys.executable 返回 / usr / bin / python 。它可能会更好地返回 / usr / bin / gdb


我需要一个2.7解释器


在这种情况下,您必须重建 gdb - with-python 值进行配置之后,从源代码获得c $ c>。

I'm using ubuntu 14.04, where python3 is a default system package.

I want to debug Python2.7 programs with gdb, but I seem to encounter this issue:

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) 

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

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?

[EDIT] 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.

解决方案

So although gdb says it's using my 2.7 interpreter

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.

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.

I need a 2.7 interpreter

In that case, you'll have to rebuild gdb from source, after configuring it with appropriate --with-python value.

这篇关于如何更改gdb使用的Python解释器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆