簡體   English   中英

GDB Python 支持,ImportError 沒有名為 gdb 的模塊

[英]GDB Python support, ImportError no module named gdb

我正在嘗試使用 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了。 在運行“configure”命令之前(編譯之前)設置這些標志

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

CentOS 6 gdb 已經有 Python 支持。 所以你真的不需要構建自己的。

但是,既然您這樣做了,您是否嘗試執行 gdb 在錯誤消息中建議的操作?

另外,你“安裝”了嗎? 您必須這樣做才能使其正常工作。

最后,如果 CentOS 6 還沒有包含 libstdc++ 漂亮打印機,我會感到驚訝。

檢查 /usr/local/share/gdb/python 的權限。 即使在“進行安裝”之后我也有

drwxrwx--- 4 root root 4096 Mar 16 08:46 /usr/local/share/gdb

在將它們設置為 go+rx 遞歸后,警告消失了。

我認為您需要升級您的操作系統版本。 我在單獨更新glibc后遇到了這個問題。 據我所知,在其他情況下,舊版本的操作系統可能會導致此問題,例如 Ubuntu 14.04。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM