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

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

问题描述

我正在运行ubuntu,并安装了python-dbg软件包。当试图直接使用安装的版本时,一切都很好:

  $ gdb python2.7-dbg 
GNU gdb Ubuntu / Linaro 7.4-2012.04-0ubuntu2.1)7.4-2012.04
--- x剪切x ---
读取/usr/bin/python2.7-dbg...done中的符号。
(gdb)r
启动程序:/usr/bin/python2.7-dbg
[使用libthread_db启用线程调试]
使用主机libthread_db库/ lib / x86_64- Linux的GNU /的libthread_db.so.1\" 。
Python 2.7.3(默认,2014年2月27日,19:39:25)
[gcc 4.6.3] on linux2
键入help,copyright,credits或许可了解更多信息。
>>>
编程接收到的信号SIGINT,中断。
0x00007ffff6997743 in __select_nocancel()at ../sysdeps/unix/syscall-template.S:82
82 ../sysdeps/unix/syscall-template.S:没有这样的文件或目录。
(gdb)py-bt(< --- works,无所事事)
(gdb)



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

 〜$ virtualenv ved -p /usr/bin/python2.7-dbg 
code>

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

 〜$。 ved / bin / activate 
(ved)〜$ gdb python
GNU gdb(Ubuntu / Linaro 7.4-2012.04-0ubuntu2.1)7.4-2012.04
--- x剪裁x ---
阅读/home/itai/ved/bin/python...done中的符号。
(gdb)r
启动程序:/ home / itai / ved / bin / python
[使用libthread_db启用线程调试]
使用主机libthread_db库/ lib / x86_64- Linux的GNU /的libthread_db.so.1\" 。
Python 2.7.3(默认,2014年2月27日,19:39:25)
[gcc 4.6.3] on linux2
键入help,copyright,credits或许可了解更多信息。
>>>
编程接收到的信号SIGINT,中断。
0x00007ffff6997743 in __select_nocancel()at ../sysdeps/unix/syscall-template.S:82
82 ../sysdeps/unix/syscall-template.S:没有这样的文件或目录。
(gdb)py-bt
未定义的命令:py-bt。尝试帮助。 (< ----问题)
(gdb)

我的virtualenv?

解决方案

我已经通过在gdb上使用strace解决了这个问题,并打开了open系统调用。 >

似乎gdb在它猜测的几个路径(根据python二进制文件)中搜索python-gdb.py,并且只要没有找到该文件,它就会失败。

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



之后,一切似乎都奏效。


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)

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

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)

Am I missing something within my virtualenv?

解决方案

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

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.

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天全站免登陆