如何在 virtualenv 中使用 gdb python 调试扩展 [英] How to use gdb python debugging extension inside virtualenv

查看:33
本文介绍了如何在 virtualenv 中使用 gdb python 调试扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行 ubuntu,并安装了 python-dbg 包.尝试直接使用已安装的版本时,一切正常:

I'm running ubuntu, and installed the python-dbg package. When trying to use the installed version directly everything works great:

$ gdb python2.7-dbg
GNU gdb (Ubuntu/Linaro 7.4-2012.04-0ubuntu2.1) 7.4-2012.04
---x snipped x---
Reading symbols from /usr/bin/python2.7-dbg...done.
(gdb) r
Starting program: /usr/bin/python2.7-dbg
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Python 2.7.3 (default, Feb 27 2014, 19:39:25)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
Program received signal SIGINT, Interrupt.
0x00007ffff6997743 in __select_nocancel () at ../sysdeps/unix/syscall-template.S:82
82      ../sysdeps/unix/syscall-template.S: No such file or directory.
(gdb) py-bt (<--- works, just has nothing to do)
(gdb)

所以,我一直在使用包的二进制 python2.7-dbg 构建一个 virtualenv(因为某些库需要重新编译),使用这个命令行:

So, I've been building a virtualenv using the package's binary python2.7-dbg (since some libraries need recompiling), using this command line:

~$ virtualenv ved -p /usr/bin/python2.7-dbg

一切正常,但是当我在 virtualenv 中使用 gdb 时,至少 python 漂亮的打印机停止工作:

Its all working fine, but when I'm using gdb inside the virtualenv, atleast the python pretty printers stop working:

~$ . ved/bin/activate
(ved)~$ gdb python
GNU gdb (Ubuntu/Linaro 7.4-2012.04-0ubuntu2.1) 7.4-2012.04
---x snipped x---
Reading symbols from /home/itai/ved/bin/python...done.
(gdb) r
Starting program: /home/itai/ved/bin/python
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Python 2.7.3 (default, Feb 27 2014, 19:39:25)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
Program received signal SIGINT, Interrupt.
0x00007ffff6997743 in __select_nocancel () at ../sysdeps/unix/syscall-template.S:82
82      ../sysdeps/unix/syscall-template.S: No such file or directory.
(gdb) py-bt
Undefined command: "py-bt".  Try "help". (<---- PROBLEM)
(gdb)

我的 virtualenv 中是否缺少某些内容?

Am I missing something within my virtualenv?

推荐答案

我已经通过在 gdb 上使用 strace 解决了这个问题,grepping "open" 系统调用.

I've solved the problem by using strace on gdb, grepping the "open" syscalls.

gdb 似乎在它猜测的几个路径中搜索 python-gdb.py(根据 python 二进制文件),每当找不到该文件时,它就会默默地失败.

It seems that gdb makes a search for python-gdb.py in several paths it guesses (according to the python binary), and whenever the file is not found it just fails silently.

最终解决问题的方法是将 /usr/lib/debug/usr/bin/python2.7-gdb.py 链接到 env 的 bin 目录中.链接的名称应该是 <python 二进制名称>-gdb.py,在我的例子中是 python2.7-dbg-gdb.py (...).

Eventually the way to solve the problem is to link /usr/lib/debug/usr/bin/python2.7-gdb.py into the env's bin directory. The name of the link should be <python binary name>-gdb.py, being in my case python2.7-dbg-gdb.py (...).

在那之后,一切似乎都正常了.

After that, everything seems to work.

这篇关于如何在 virtualenv 中使用 gdb python 调试扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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