无法使用 Python 支持编译 GDB7.8

j0h*_*j0h 2 python gdb

我正在尝试安装支持 Python 的 GDB7.8。从源文件夹中,我正在运行./configure --with-python 当我从 --with- 执行 tab-complete 时,我没有在列表中看到 Python。但是当我用那个标志运行 configure 时,它​​并没有阻止。

当我运行 make 时,它​​抱怨找不到 Python。

checking for python2.7... no
Run Code Online (Sandbox Code Playgroud)

但是安装了 Python:

 $ which python
python                python2.7             python2.7-dbg-config
python2               python2.7-dbg 

$ which python2.7 
/usr/bin/python2.7
Run Code Online (Sandbox Code Playgroud)

我在没有 --with-python 的情况下编译了 GDB,并且安装的东西没有错误。我的印象是 GDB7.8 无需特殊标志即可支持 Python。但是当我运行时:

$gdb python
(gdb) run test.py
Run Code Online (Sandbox Code Playgroud)

我得到某种无法导入 gdb 导入错误

然后我尝试调用“pi”:

(gdb) pi printf.py
Python scripting is not supported in this copy of GDB.
Run Code Online (Sandbox Code Playgroud)

那么...如何在 GDB7.8 中获得 Python 支持?它实际上不支持吗?或者我不应该叫“pi”?

小智 11

我花了很多时间让 gdb (7.9) 与 Python (2.7) 一起工作。最后一切都运行得很好。然而,有很多事情你必须做对。关键是 gdb configure 脚本试图编译一个看起来像这样的小 C 程序。

#include "Python.h"
int
main ()
{
Py_Initialize ();
  ;
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

如果此程序无法编译,则不会构建 Python 支持。要编译此程序,必须在 .h 中找到 Python.h 包含文件/usr/include/python2.7。此文件仅在python-devel安装了软件包时才存在。在我的系统(redhat)上,安装这个包的命令是sudo yum install python-devel.

但是,这不足以安装 Python。在 configure 脚本尝试编译 C 程序之前,它从python-config.py. 如果这些选项不正确,则 C 程序将无法编译。在我的系统上,python-config.py返回以下选项。

-lpthread -ldl -lutil -lm -lpython2.7 -Xlinker -export-dynamic
Run Code Online (Sandbox Code Playgroud)

这些选项不会在我的环境中引起任何问题。其他人对返回的选项有问题,python-config.py并进行了更改python-config.py以解决这些问题。在我的系统上,完整的编译命令是

gcc -o conftest -g -O2   -I/usr/include/python2.7 -I/usr/include/python2.7 \
    conftest.c -ldl -lncurses -lz -lm -ldl    -lpthread -ldl -lutil -lm \
    -lpython2.7 -Xlinker -export-dynamic
Run Code Online (Sandbox Code Playgroud)

这个编译命令在我安装后立即完成,没有任何错误python-devel。请注意,您不必手动输入gcc命令。我确实gcc多次运行该命令以确保一切正确。通常,配置脚本将为您运行编译器。另请注意,要完成整个 gdb 安装过程,makeinfo还必须安装。安装 makeinfo 的命令是sudo yum install texinfo.

总的来说,正确的步骤集似乎是

  1. 安装 python-devel

  2. 安装 texinfo

  3. 下载 gdb 源代码并对其进行压缩和解压。

  4. cdgdb-7.9包含configure文件的目录。

  5. ./configure --prefix=/usr --with-python
    make 
    sudo make install
    
    Run Code Online (Sandbox Code Playgroud)

应该可以让 gdb 与 Python 3 一起工作。各种 gdb 脚本和安装程序在很多地方都提到了 Python 3。但是,此时我不知道使用 Python 3 安装 gdb 的正确过程。