如何在virtualenv中使用gdb python调试扩展

ita*_*tai 15 python gdb virtualenv

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

$ 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)
Run Code Online (Sandbox Code Playgroud)

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

~$ virtualenv ved -p /usr/bin/python2.7-dbg
Run Code Online (Sandbox Code Playgroud)

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

~$ . 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)
Run Code Online (Sandbox Code Playgroud)

我在virtualenv中遗漏了什么吗?

ita*_*tai 10

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

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

最终解决问题的方法是链接/usr/lib/debug/usr/bin/python2.7-gdb.py到env的bin目录.链接的名称应该是<python binary name>-gdb.py,在我的情况下python2.7-dbg-gdb.py(...).

在那之后,一切似乎都有效.


cra*_*gds 7

@ itai的答案在Ubuntu Trusty(14.04)上仅部分适用于我.我发现其他几件事情做得更好:

sudo apt-get install python2.7-dbg

然后,在virtualenv:

. bin/activate
mkdir bin/.debug
ln -s /usr/lib/debug/usr/bin/python2.7-gdb.py bin/.debug/python-gdb.py
ln -s /usr/lib/debug/usr/bin/python2.7 bin/.debug/

gdb --args bin/python2.7 ...
Run Code Online (Sandbox Code Playgroud)

这有助于gdb找到python调试符号以及py-bt等命令.