我正在尝试使用 python 支持编译 gdb,以便我可以使用提供的 PrettyPrinters: http://gcc.gnu.org/svn/gcc/trunk/libstdc++-v3/python
我从 ( http://ftp.gnu.org/gnu/gdb/gdb-7.6.1.tar.gz ) 下载了最新的 gdb 源代码并在我的 Centos 6.4 上编译如下: 1. ./configure --with-python 2.制作
我是否需要为 --with-python 提供路径或其他参数以及 python 库或可执行文件的路径?
编译后运行 gdb,我看到这个警告:
Python Exception <type 'exceptions.ImportError'> No module named gdb:
warning:
Could not load the Python gdb module from `/usr/local/share/gdb/python'.
Limited Python support is available from the _gdb module.
Suggest passing --data-directory=/path/to/gdb/data-directory.
异常在这里很明显,我接下来要做的任何事情都会失败,因为它需要 gdb 模块,但我还是试了一下。所以我在 ~/.gdbinit 中添加了以下几行:
import sys
sys.path.insert(0, '/tmp/pretty/python')
from libstdcxx.v6.printers import register_libstdcxx_printers
register_libstdcxx_printers (None)
现在当我启动 gdb 时,我得到这个错误:
Traceback (most recent call last):
File "<string>", line 3, in <module>
File "/tmp/pretty/python/libstdcxx/v6/printers.py", line 18, in <module>
import gdb
ImportError: No module named gdb
Error while executing Python code.
有人可以帮我解决这个问题吗?
最佳答案
如果有人在试图在 Solus 4.1 中编译 Python 和 GDB 时遇到这篇文章,请阅读我创建的以下设置指南(显然将任何目录名称/树换成你自己的)
像这样设置.profile:
source /usr/share/defaults/etc/profile
# Adding variables to PATH
PATH=$HOME/.local/bin:$PATH;
# Emscripten variables
PATH=$HOME/Applications/emsdk:$PATH;
PATH=$HOME/Applications/emsdk/node/12.18.1_64bit/bin:$PATH;
PATH=$HOME/Applications/emsdk/upstream/emscripten:$PATH;
# GDB variables
# Python variables
PATH=$HOME/Applications/Python-3.9.1/out/bin:$PATH;
LD_LIBRARY_PATH=$HOME/Applications/Python-3.9.1/out/lib:$LD_LIBRARY_PATH;
alias python=/home/jeremi-solus/Applications/Python-3.9.1/out/bin/python3.9
# GDBM variables
# GEF variables
# Various apps variables
PATH=$HOME/Applications:$PATH;
export PATH
export LD_LIBRARY_PATH
# ... remaining .profile
像这样设置.bashrc
#import profile data if exists
if [ -f "$HOME/.profile" ]; then
source "$HOME/.profile"
#else load default profile environment variables
else
source /usr/share/defaults/etc/profile
fi
# ... remaining .bashrc
编译 Python(debug build + dev(--enable-shared
相当于 python3-dev))(首先创建“out”目录 - 然后从中运行两个命令)
../configure --with-pydebug --with-lto --enable-optimizations --prefix=/home/jeremi-solus/Applications/Python-3.9.1/out --exec-prefix=/home/jeremi-solus/Applications/Python-3.9.1/out --enable-shared
make altinstall
编译完Python,就可以开始编译GDB了。在运行“配置”命令之前设置这些标志(在编译之前)
export CFLAGS="-I/home/jeremi-solus/Applications/Python-3.9.1/out/include/python3.9d -I/home/jeremi-solus/Applications/Python-3.9.1/out/include/python3.9d"
export LDFLAGS="-L/home/jeremi-solus/Applications/Python-3.9.1/out/lib -lcrypt -lpthread -ldl -lutil -lm"
export LIBS="-lcrypt -lpthread -ldl -lutil -lm"
记下已编译 Python 二进制文件的路径。您需要将此路径传递给 GDB 配置脚本
/home/jeremi-solus/Applications/Python-3.9.1/out/bin/python3.9
像这样运行配置脚本 - 确保在导出早期设置值后不要关闭 bash shell!!此外,确保通过运行 source ~/.bashrc
.profile
变量
./configure --prefix=/home/jeremi-solus/Applications/gdb-10.1/out --exec-prefix=/home/jeremi-solus/Applications/gdb-10.1/out --enable-lto --with-python=/home/jeremi-solus/Applications/Python-3.9.1/out/bin/python3.9
制作 GDB(从 out 目录运行)
make
用这个命令启动GDB
./gdb -data-directory ./data-directory
关于c++ - GDB Python 支持,ImportError 没有名为 gdb 的模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19045762/