我正在使用 GDB 调试 Kubuntu 12.04 上我的 python 应用程序中的分段错误。据说 GDB 版本 7 具有用于提取有关 python 堆栈的信息的内置宏 (http://docs.python.org/devguide/gdb.html),但我无法让它工作。我已经安装了 python-dbg。
当我在 GDB 中请求 python 堆栈跟踪时,结果如下所示:
(gdb) py-bt
#5 (unable to read python frame information)
#16 (unable to read python frame information)
#26 (unable to read python frame information)
...
Run Code Online (Sandbox Code Playgroud)
我的 GDB 版本是 7.4-2012.04-0ubuntu2,Python 是 2.7.3-0ubuntu3。
Luk*_*uke 18
问题是:要访问 GDB 中的调试符号,您必须调用不同的二进制文件:“python-dbg”而不是“python”(在 /usr/share/doc/python2.7-dbg/README.debug 中找到) )。
小智 7
在 Ubuntu 16.04 上,我设法通过以下方式在 Python 3.5 中获取 Python 堆栈跟踪:
安装python3-dbg和python3-dev:
$ sudo apt install python3-dbg python3-dev
python3-dbg包附带了如何使用它的简短文档/usr/share/doc/python3-dbg/README.debug,我将在下一步中使用它。
将解压的 GDB 辅助脚本附加/usr/share/doc/python3.5/gdbinit.gz到~/.gdbinit:
zcat /usr/share/doc/python3.5/gdbinit.gz >> ~/.gdbinit
现在 gdb 将能够找到 Python 二进制文件的符号并py-bt用于在 gdb 中显示 Python 堆栈跟踪:
$ gdb -p 4762
GNU gdb (Ubuntu 7.11.1-0ubuntu1~16.04) 7.11.1
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
Attaching to process 4762
[New LWP 4852]
[New LWP 4853]
[New LWP 4854]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
0x00007f38e43deb5d in poll () at ../sysdeps/unix/syscall-template.S:84
84 ../sysdeps/unix/syscall-template.S: No such file or directory.
(gdb) py-bt
Traceback (most recent call first):
File "/usr/bin/indicator-cpufreq", line 80, in <module>
Gtk.main()
(gdb)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15063 次 |
| 最近记录: |